Add Sentence Transformers usage

#1
by tomaarsen HF Staff - opened
Files changed (1) hide show
  1. README.md +35 -0
README.md CHANGED
@@ -1,6 +1,7 @@
1
  ---
2
  tags:
3
  - ColBERT
 
4
  - PyLate
5
  - sentence-transformers
6
  - sentence-similarity
@@ -204,6 +205,40 @@ ColBERT(
204
 
205
  ## Usage
206
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
207
  First install the PyLate library:
208
 
209
  ```bash
 
1
  ---
2
  tags:
3
  - ColBERT
4
+ - multi-vector
5
  - PyLate
6
  - sentence-transformers
7
  - sentence-similarity
 
205
 
206
  ## Usage
207
 
208
+ ### Sentence Transformers
209
+
210
+ This model can be used with [Sentence Transformers](https://www.sbert.net/) as a multi-vector (ColBERT-style late interaction) retriever via the `MultiVectorEncoder`:
211
+
212
+ ```bash
213
+ pip install "sentence-transformers>=6.0.0"
214
+ ```
215
+
216
+ ```python
217
+ from sentence_transformers import MultiVectorEncoder
218
+
219
+ model = MultiVectorEncoder("lightonai/mLateOn")
220
+
221
+ query = "Which planet is the Red Planet?"
222
+ documents = [
223
+ "Mars, known for its reddish appearance, is often referred to as the Red Planet.",
224
+ "Mars, connu pour son apparence rougeâtre, est souvent appelé la planète rouge.",
225
+ "Mars, bekannt für sein rötliches Erscheinungsbild, wird oft als der Rote Planet bezeichnet.",
226
+ "Venus is often called Earth's twin because of its similar size and proximity.",
227
+ ]
228
+
229
+ query_embeddings = model.encode_query(query)
230
+ document_embeddings = model.encode_document(documents)
231
+ print(query_embeddings.shape, document_embeddings[0].shape)
232
+ # (10, 128) (20, 128)
233
+
234
+ # MaxSim late-interaction scoring (higher is more relevant)
235
+ scores = model.similarity(query_embeddings, document_embeddings)
236
+ print(scores)
237
+ # tensor([[9.6029, 9.5838, 9.5877, 9.4578]])
238
+ ```
239
+
240
+ ### PyLate
241
+
242
  First install the PyLate library:
243
 
244
  ```bash