Sentence Similarity
Safetensors
sentence-transformers
English
PyLate
modernbert
ColBERT
multi-vector
embeddings
retrieval
feature-extraction
Generated from Trainer
dataset_size:1695819
loss:Contrastive
Eval Results (legacy)
text-embeddings-inference
🇪🇺 Region: EU
Instructions to use lightonai/ColBERT-Zero-supervised with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- sentence-transformers
How to use lightonai/ColBERT-Zero-supervised with sentence-transformers:
from pylate import models queries = [ "Which planet is known as the Red Planet?", "What is the largest planet in our solar system?", ] documents = [ ["Mars is the Red Planet.", "Venus is Earth's twin."], ["Jupiter is the largest planet.", "Saturn has rings."], ] model = models.ColBERT(model_name_or_path="lightonai/ColBERT-Zero-supervised") queries_emb = model.encode(queries, is_query=True) docs_emb = model.encode(documents, is_query=False) - Notebooks
- Google Colab
- Kaggle
Add Sentence Transformers usage
#1
by tomaarsen HF Staff - opened
- README.md +35 -0
- config_sentence_transformers.json +6 -0
README.md
CHANGED
|
@@ -2,6 +2,7 @@
|
|
| 2 |
tags:
|
| 3 |
- ColBERT
|
| 4 |
- PyLate
|
|
|
|
| 5 |
- sentence-transformers
|
| 6 |
- sentence-similarity
|
| 7 |
- embeddings
|
|
@@ -1015,6 +1016,40 @@ ColBERT(
|
|
| 1015 |
```
|
| 1016 |
|
| 1017 |
## Usage
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1018 |
First install the PyLate library:
|
| 1019 |
|
| 1020 |
```bash
|
|
|
|
| 2 |
tags:
|
| 3 |
- ColBERT
|
| 4 |
- PyLate
|
| 5 |
+
- multi-vector
|
| 6 |
- sentence-transformers
|
| 7 |
- sentence-similarity
|
| 8 |
- embeddings
|
|
|
|
| 1016 |
```
|
| 1017 |
|
| 1018 |
## Usage
|
| 1019 |
+
|
| 1020 |
+
### Sentence Transformers
|
| 1021 |
+
|
| 1022 |
+
This model can be used with [Sentence Transformers](https://www.sbert.net/) as a multi-vector (ColBERT-style late interaction) retriever via the `MultiVectorEncoder`:
|
| 1023 |
+
|
| 1024 |
+
```bash
|
| 1025 |
+
pip install "sentence-transformers>=6.0.1"
|
| 1026 |
+
```
|
| 1027 |
+
|
| 1028 |
+
```python
|
| 1029 |
+
from sentence_transformers import MultiVectorEncoder
|
| 1030 |
+
|
| 1031 |
+
model = MultiVectorEncoder("lightonai/ColBERT-Zero-supervised")
|
| 1032 |
+
|
| 1033 |
+
query = "Which planet is known as the Red Planet?"
|
| 1034 |
+
documents = [
|
| 1035 |
+
"Venus is often called Earth's twin because of its similar size and proximity.",
|
| 1036 |
+
"Mars, known for its reddish appearance, is often referred to as the Red Planet.",
|
| 1037 |
+
"Jupiter, the largest planet in our solar system, has a prominent red spot.",
|
| 1038 |
+
"Saturn, famous for its rings, is sometimes mistaken for the Red Planet.",
|
| 1039 |
+
]
|
| 1040 |
+
|
| 1041 |
+
query_embeddings = model.encode_query(query)
|
| 1042 |
+
document_embeddings = model.encode_document(documents)
|
| 1043 |
+
print(query_embeddings.shape, document_embeddings[0].shape)
|
| 1044 |
+
# torch.Size([16, 128]) torch.Size([19, 128])
|
| 1045 |
+
|
| 1046 |
+
# MaxSim late-interaction scoring (higher is more relevant)
|
| 1047 |
+
scores = model.similarity(query_embeddings, document_embeddings)
|
| 1048 |
+
print(scores)
|
| 1049 |
+
# tensor([[ 9.7358, 11.2758, 10.7421, 10.7044]], device='cuda:0')
|
| 1050 |
+
```
|
| 1051 |
+
|
| 1052 |
+
### PyLate
|
| 1053 |
First install the PyLate library:
|
| 1054 |
|
| 1055 |
```bash
|
config_sentence_transformers.json
CHANGED
|
@@ -5,6 +5,12 @@
|
|
| 5 |
"transformers": "4.48.3",
|
| 6 |
"pytorch": "2.6.0"
|
| 7 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
"prompts": {
|
| 9 |
"query": "search_query: ",
|
| 10 |
"document": "search_document: "
|
|
|
|
| 5 |
"transformers": "4.48.3",
|
| 6 |
"pytorch": "2.6.0"
|
| 7 |
},
|
| 8 |
+
"requirements": {
|
| 9 |
+
"sentence-transformers": {
|
| 10 |
+
"specifier": ">=6.0.1",
|
| 11 |
+
"reason": "earlier versions encode this model's queries as \"search_query: ...\" instead of \"[Q] search_query: ...\", dropping the [Q] / [D] markers it was trained with and changing the embeddings."
|
| 12 |
+
}
|
| 13 |
+
},
|
| 14 |
"prompts": {
|
| 15 |
"query": "search_query: ",
|
| 16 |
"document": "search_document: "
|