tomaarsen HF Staff commited on
Commit
388eb6b
·
verified ·
1 Parent(s): 6d3e56d

Add Sentence Transformers usage

Browse files
Files changed (1) hide show
  1. README.md +33 -0
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