Instructions to use colbert-ir/colbertv2.0 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use colbert-ir/colbertv2.0 with Transformers:
# Load model directly from transformers import AutoTokenizer, HF_ColBERT tokenizer = AutoTokenizer.from_pretrained("colbert-ir/colbertv2.0") model = HF_ColBERT.from_pretrained("colbert-ir/colbertv2.0", device_map="auto") - Notebooks
- Google Colab
- Kaggle
Add Sentence Transformers usage
Browse files
README.md
CHANGED
|
@@ -4,6 +4,8 @@ language:
|
|
| 4 |
- en
|
| 5 |
tags:
|
| 6 |
- ColBERT
|
|
|
|
|
|
|
| 7 |
---
|
| 8 |
<p align="center">
|
| 9 |
<img align="center" src="https://github.com/stanford-futuredata/ColBERT/blob/main/docs/images/colbertofficial.png?raw=true" width="430px" />
|
|
@@ -34,6 +36,38 @@ These rich interactions allow ColBERT to surpass the quality of _single-vector_
|
|
| 34 |
* [**ColBERTv2: Effective and Efficient Retrieval via Lightweight Late Interaction**](https://arxiv.org/abs/2112.01488) (NAACL'22).
|
| 35 |
* [**PLAID: An Efficient Engine for Late Interaction Retrieval**](https://arxiv.org/abs/2205.09707) (CIKM'22).
|
| 36 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
----
|
| 38 |
|
| 39 |
## 🚨 **Announcements**
|
|
|
|
| 4 |
- en
|
| 5 |
tags:
|
| 6 |
- ColBERT
|
| 7 |
+
- multi-vector
|
| 8 |
+
- sentence-transformers
|
| 9 |
---
|
| 10 |
<p align="center">
|
| 11 |
<img align="center" src="https://github.com/stanford-futuredata/ColBERT/blob/main/docs/images/colbertofficial.png?raw=true" width="430px" />
|
|
|
|
| 36 |
* [**ColBERTv2: Effective and Efficient Retrieval via Lightweight Late Interaction**](https://arxiv.org/abs/2112.01488) (NAACL'22).
|
| 37 |
* [**PLAID: An Efficient Engine for Late Interaction Retrieval**](https://arxiv.org/abs/2205.09707) (CIKM'22).
|
| 38 |
|
| 39 |
+
## Sentence Transformers
|
| 40 |
+
|
| 41 |
+
This model can be used with [Sentence Transformers](https://www.sbert.net/) as a multi-vector (ColBERT-style late interaction) retriever via the `MultiVectorEncoder`:
|
| 42 |
+
|
| 43 |
+
```bash
|
| 44 |
+
pip install "sentence-transformers>=6.0.0"
|
| 45 |
+
```
|
| 46 |
+
|
| 47 |
+
```python
|
| 48 |
+
from sentence_transformers import MultiVectorEncoder
|
| 49 |
+
|
| 50 |
+
model = MultiVectorEncoder("colbert-ir/colbertv2.0")
|
| 51 |
+
|
| 52 |
+
query = "Which planet is known as the Red Planet?"
|
| 53 |
+
documents = [
|
| 54 |
+
"Venus is often called Earth's twin because of its similar size and proximity.",
|
| 55 |
+
"Mars, known for its reddish appearance, is often referred to as the Red Planet.",
|
| 56 |
+
"Jupiter, the largest planet in our solar system, has a prominent red spot.",
|
| 57 |
+
"Saturn, famous for its rings, is sometimes mistaken for the Red Planet.",
|
| 58 |
+
]
|
| 59 |
+
|
| 60 |
+
query_embeddings = model.encode_query(query)
|
| 61 |
+
document_embeddings = model.encode_document(documents)
|
| 62 |
+
print(query_embeddings.shape, document_embeddings[0].shape)
|
| 63 |
+
# (32, 128) (17, 128)
|
| 64 |
+
|
| 65 |
+
# MaxSim late-interaction scoring (higher is more relevant)
|
| 66 |
+
scores = model.similarity(query_embeddings, document_embeddings)
|
| 67 |
+
print(scores)
|
| 68 |
+
# tensor([[12.7970, 27.1945, 23.8495, 24.5656]])
|
| 69 |
+
```
|
| 70 |
+
|
| 71 |
----
|
| 72 |
|
| 73 |
## 🚨 **Announcements**
|