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
@@ -213,6 +214,40 @@ ColBERT(
213
 
214
  ## Usage
215
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
216
  First install PyLate:
217
 
218
  ```bash
 
1
  ---
2
  tags:
3
  - ColBERT
4
+ - multi-vector
5
  - PyLate
6
  - sentence-transformers
7
  - sentence-similarity
 
214
 
215
  ## Usage
216
 
217
+ ### Sentence Transformers
218
+
219
+ This model can be used with [Sentence Transformers](https://www.sbert.net/) as a multi-vector (ColBERT-style late interaction) retriever via the `MultiVectorEncoder`:
220
+
221
+ ```bash
222
+ pip install "sentence-transformers>=6.0.0"
223
+ ```
224
+
225
+ ```python
226
+ from sentence_transformers import MultiVectorEncoder
227
+
228
+ model = MultiVectorEncoder("lightonai/LateOn-hpool-regularized")
229
+
230
+ query = "Which planet is known as the Red Planet?"
231
+ documents = [
232
+ "Venus is often called Earth's twin because of its similar size and proximity.",
233
+ "Mars, known for its reddish appearance, is often referred to as the Red Planet.",
234
+ "Jupiter, the largest planet in our solar system, has a prominent red spot.",
235
+ "Saturn, famous for its rings, is sometimes mistaken for the Red Planet.",
236
+ ]
237
+
238
+ query_embeddings = model.encode_query(query)
239
+ document_embeddings = model.encode_document(documents)
240
+ print(query_embeddings.shape, document_embeddings[0].shape)
241
+ # (12, 128) (18, 128)
242
+
243
+ # MaxSim late-interaction scoring (higher is more relevant)
244
+ scores = model.similarity(query_embeddings, document_embeddings)
245
+ print(scores)
246
+ # tensor([[11.3723, 11.6385, 11.5022, 11.6186]])
247
+ ```
248
+
249
+ ### PyLate
250
+
251
  First install PyLate:
252
 
253
  ```bash