Sentence Similarity
Safetensors
sentence-transformers
PyLate
lfm2
liquid
edge
ColBERT
feature-extraction
Eval Results (legacy)
Instructions to use LiquidAI/LFM2-ColBERT-350M with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- sentence-transformers
How to use LiquidAI/LFM2-ColBERT-350M 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="LiquidAI/LFM2-ColBERT-350M") queries_emb = model.encode(queries, is_query=True) docs_emb = model.encode(documents, is_query=False) - Notebooks
- Google Colab
- Kaggle
Add Sentence Transformers usage
Browse files
README.md
CHANGED
|
@@ -13,6 +13,7 @@ tags:
|
|
| 13 |
- lfm2
|
| 14 |
- edge
|
| 15 |
- ColBERT
|
|
|
|
| 16 |
- PyLate
|
| 17 |
- sentence-transformers
|
| 18 |
- sentence-similarity
|
|
@@ -842,6 +843,38 @@ ColBERT(
|
|
| 842 |
|
| 843 |
<a href="https://colab.research.google.com/drive/1tXSAXGpjuTvliuTrSSHDEcmIe48uolrD?usp=sharing"><img src="https://cdn-uploads.huggingface.co/production/uploads/61b8e2ba285851687028d395/vlOyMEjwHa_b_LXysEu2E.png" width=120 alt="Colab link"></a>
|
| 844 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 845 |
First, install the PyLate and transformers library:
|
| 846 |
|
| 847 |
```bash
|
|
|
|
| 13 |
- lfm2
|
| 14 |
- edge
|
| 15 |
- ColBERT
|
| 16 |
+
- multi-vector
|
| 17 |
- PyLate
|
| 18 |
- sentence-transformers
|
| 19 |
- sentence-similarity
|
|
|
|
| 843 |
|
| 844 |
<a href="https://colab.research.google.com/drive/1tXSAXGpjuTvliuTrSSHDEcmIe48uolrD?usp=sharing"><img src="https://cdn-uploads.huggingface.co/production/uploads/61b8e2ba285851687028d395/vlOyMEjwHa_b_LXysEu2E.png" width=120 alt="Colab link"></a>
|
| 845 |
|
| 846 |
+
### Sentence Transformers
|
| 847 |
+
|
| 848 |
+
This model can be used with [Sentence Transformers](https://www.sbert.net/) as a multi-vector (ColBERT-style late interaction) retriever via the `MultiVectorEncoder`:
|
| 849 |
+
|
| 850 |
+
```bash
|
| 851 |
+
pip install "sentence-transformers>=6.0.0"
|
| 852 |
+
```
|
| 853 |
+
|
| 854 |
+
```python
|
| 855 |
+
from sentence_transformers import MultiVectorEncoder
|
| 856 |
+
|
| 857 |
+
model = MultiVectorEncoder("LiquidAI/LFM2-ColBERT-350M")
|
| 858 |
+
|
| 859 |
+
query = "Which planet is known as the Red Planet?"
|
| 860 |
+
documents = [
|
| 861 |
+
"Venus wird oft als Zwilling der Erde bezeichnet, wegen ihrer ähnlichen Größe.",
|
| 862 |
+
"Mars, connue pour son apparence rougeâtre, est souvent appelée la planète rouge.",
|
| 863 |
+
"Júpiter es el planeta más grande del sistema solar.",
|
| 864 |
+
"Saturno è famoso per i suoi bellissimi anelli.",
|
| 865 |
+
]
|
| 866 |
+
|
| 867 |
+
query_embeddings = model.encode_query(query)
|
| 868 |
+
document_embeddings = model.encode_document(documents)
|
| 869 |
+
print(query_embeddings.shape, document_embeddings[0].shape)
|
| 870 |
+
# (32, 128) (17, 128)
|
| 871 |
+
|
| 872 |
+
# MaxSim late-interaction scoring (higher is more relevant)
|
| 873 |
+
scores = model.similarity(query_embeddings, document_embeddings)
|
| 874 |
+
print(scores)
|
| 875 |
+
# tensor([[30.3632, 30.4892, 30.4024, 30.3004]])
|
| 876 |
+
```
|
| 877 |
+
|
| 878 |
First, install the PyLate and transformers library:
|
| 879 |
|
| 880 |
```bash
|