Sentence Similarity
sentence-transformers
Safetensors
English
bert
feature-extraction
ColBERT
multi-vector
PyLate
text-embeddings-inference
Instructions to use lightonai/colbertv2.0 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- sentence-transformers
How to use lightonai/colbertv2.0 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/colbertv2.0") queries_emb = model.encode(queries, is_query=True) docs_emb = model.encode(documents, is_query=False) - Inference
- Notebooks
- Google Colab
- Kaggle
Add Sentence Transformers usage
#1
by tomaarsen HF Staff - opened
README.md
CHANGED
|
@@ -9,6 +9,7 @@ tags:
|
|
| 9 |
- sentence-similarity
|
| 10 |
- feature-extraction
|
| 11 |
- ColBERT
|
|
|
|
| 12 |
- PyLate
|
| 13 |
widget: []
|
| 14 |
license: mit
|
|
@@ -21,11 +22,45 @@ All the credits belong to the original authors and we thank Omar Khattab for all
|
|
| 21 |
|
| 22 |
Please refer to the [original repository](https://huggingface.co/colbert-ir/colbertv2.0) and [paper](https://arxiv.org/abs/2112.01488) for more information about the model and to [PyLate repository](https://github.com/lightonai/pylate) for information about usage of the model.
|
| 23 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
## Model Details
|
| 25 |
The model maps query and documents to sequences of 128-dimensional dense vectors and can be used for semantic textual similarity using the MaxSim operator.
|
| 26 |
|
| 27 |
### Model Description
|
| 28 |
-
- **Model Type:**
|
| 29 |
- **Base model:** [colbert-ir/colbertv2.0](https://huggingface.co/colbert-ir/colbertv2.0) <!-- at revision c1e84128e85ef755c096a95bdb06b47793b13acf -->
|
| 30 |
- **Maximum Sequence Length:** 512 tokens
|
| 31 |
- **Output Dimensionality:** 128 tokens
|
|
|
|
| 9 |
- sentence-similarity
|
| 10 |
- feature-extraction
|
| 11 |
- ColBERT
|
| 12 |
+
- multi-vector
|
| 13 |
- PyLate
|
| 14 |
widget: []
|
| 15 |
license: mit
|
|
|
|
| 22 |
|
| 23 |
Please refer to the [original repository](https://huggingface.co/colbert-ir/colbertv2.0) and [paper](https://arxiv.org/abs/2112.01488) for more information about the model and to [PyLate repository](https://github.com/lightonai/pylate) for information about usage of the model.
|
| 24 |
|
| 25 |
+
## Usage
|
| 26 |
+
|
| 27 |
+
### Sentence Transformers
|
| 28 |
+
|
| 29 |
+
This model can be used with [Sentence Transformers](https://www.sbert.net/) as a multi-vector (ColBERT-style late interaction) retriever via the `MultiVectorEncoder`:
|
| 30 |
+
|
| 31 |
+
```bash
|
| 32 |
+
pip install "sentence-transformers>=6.0.0"
|
| 33 |
+
```
|
| 34 |
+
|
| 35 |
+
```python
|
| 36 |
+
from sentence_transformers import MultiVectorEncoder
|
| 37 |
+
|
| 38 |
+
model = MultiVectorEncoder("lightonai/colbertv2.0")
|
| 39 |
+
|
| 40 |
+
query = "Which planet is known as the Red Planet?"
|
| 41 |
+
documents = [
|
| 42 |
+
"Venus is often called Earth's twin because of its similar size and proximity.",
|
| 43 |
+
"Mars, known for its reddish appearance, is often referred to as the Red Planet.",
|
| 44 |
+
"Jupiter, the largest planet in our solar system, has a prominent red spot.",
|
| 45 |
+
"Saturn, famous for its rings, is sometimes mistaken for the Red Planet.",
|
| 46 |
+
]
|
| 47 |
+
|
| 48 |
+
query_embeddings = model.encode_query(query)
|
| 49 |
+
document_embeddings = model.encode_document(documents)
|
| 50 |
+
print(query_embeddings.shape, document_embeddings[0].shape)
|
| 51 |
+
# (32, 128) (17, 128)
|
| 52 |
+
|
| 53 |
+
# MaxSim late-interaction scoring (higher is more relevant)
|
| 54 |
+
scores = model.similarity(query_embeddings, document_embeddings)
|
| 55 |
+
print(scores)
|
| 56 |
+
# tensor([[12.7970, 27.1945, 23.8495, 24.5656]])
|
| 57 |
+
```
|
| 58 |
+
|
| 59 |
## Model Details
|
| 60 |
The model maps query and documents to sequences of 128-dimensional dense vectors and can be used for semantic textual similarity using the MaxSim operator.
|
| 61 |
|
| 62 |
### Model Description
|
| 63 |
+
- **Model Type:** Multi-vector embedding model
|
| 64 |
- **Base model:** [colbert-ir/colbertv2.0](https://huggingface.co/colbert-ir/colbertv2.0) <!-- at revision c1e84128e85ef755c096a95bdb06b47793b13acf -->
|
| 65 |
- **Maximum Sequence Length:** 512 tokens
|
| 66 |
- **Output Dimensionality:** 128 tokens
|