Sentence Similarity
Safetensors
sentence-transformers
English
PyLate
modernbert
ColBERT
multi-vector
embeddings
retrieval
feature-extraction
Generated from Trainer
dataset_size:238998494
loss:CachedContrastive
Eval Results (legacy)
text-embeddings-inference
🇪🇺 Region: EU
Instructions to use lightonai/ColBERT-Zero-unsupervised with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- sentence-transformers
How to use lightonai/ColBERT-Zero-unsupervised 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-unsupervised") queries_emb = model.encode(queries, is_query=True) docs_emb = model.encode(documents, is_query=False) - Notebooks
- Google Colab
- Kaggle
Commit ·
c00e7c8
1
Parent(s): d5f1d1e
Add Sentence Transformers usage (#1)
Browse files- Add Sentence Transformers usage (82f6991b0f0c597cfb36100b847a478cf374f07e)
- Simplify the Sentence Transformers section intro (0f284dd50af8e91528dd9a2e9f83bc1571e3c3f4)
Co-authored-by: Tom Aarsen <tomaarsen@users.noreply.huggingface.co>
- 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
|
|
@@ -1034,6 +1035,40 @@ ColBERT(
|
|
| 1034 |
```
|
| 1035 |
|
| 1036 |
## Usage
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1037 |
First install the PyLate library:
|
| 1038 |
|
| 1039 |
```bash
|
|
|
|
| 2 |
tags:
|
| 3 |
- ColBERT
|
| 4 |
- PyLate
|
| 5 |
+
- multi-vector
|
| 6 |
- sentence-transformers
|
| 7 |
- sentence-similarity
|
| 8 |
- embeddings
|
|
|
|
| 1035 |
```
|
| 1036 |
|
| 1037 |
## Usage
|
| 1038 |
+
|
| 1039 |
+
### Sentence Transformers
|
| 1040 |
+
|
| 1041 |
+
This model can be used with [Sentence Transformers](https://www.sbert.net/) as a multi-vector (ColBERT-style late interaction) retriever via the `MultiVectorEncoder`:
|
| 1042 |
+
|
| 1043 |
+
```bash
|
| 1044 |
+
pip install "sentence-transformers>=6.0.1"
|
| 1045 |
+
```
|
| 1046 |
+
|
| 1047 |
+
```python
|
| 1048 |
+
from sentence_transformers import MultiVectorEncoder
|
| 1049 |
+
|
| 1050 |
+
model = MultiVectorEncoder("lightonai/ColBERT-Zero-unsupervised")
|
| 1051 |
+
|
| 1052 |
+
query = "Which planet is known as the Red Planet?"
|
| 1053 |
+
documents = [
|
| 1054 |
+
"Venus is often called Earth's twin because of its similar size and proximity.",
|
| 1055 |
+
"Mars, known for its reddish appearance, is often referred to as the Red Planet.",
|
| 1056 |
+
"Jupiter, the largest planet in our solar system, has a prominent red spot.",
|
| 1057 |
+
"Saturn, famous for its rings, is sometimes mistaken for the Red Planet.",
|
| 1058 |
+
]
|
| 1059 |
+
|
| 1060 |
+
query_embeddings = model.encode_query(query)
|
| 1061 |
+
document_embeddings = model.encode_document(documents)
|
| 1062 |
+
print(query_embeddings.shape, document_embeddings[0].shape)
|
| 1063 |
+
# torch.Size([16, 128]) torch.Size([19, 128])
|
| 1064 |
+
|
| 1065 |
+
# MaxSim late-interaction scoring (higher is more relevant)
|
| 1066 |
+
scores = model.similarity(query_embeddings, document_embeddings)
|
| 1067 |
+
print(scores)
|
| 1068 |
+
# tensor([[ 8.3235, 11.3196, 9.9448, 10.3868]], device='cuda:0')
|
| 1069 |
+
```
|
| 1070 |
+
|
| 1071 |
+
### PyLate
|
| 1072 |
First install the PyLate library:
|
| 1073 |
|
| 1074 |
```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: "
|