Add Sentence Transformers usage

#1
by tomaarsen HF Staff - opened
Files changed (1) hide show
  1. README.md +36 -0
README.md CHANGED
@@ -1,6 +1,7 @@
1
  ---
2
  tags:
3
  - ColBERT
 
4
  - PyLate
5
  - sentence-transformers
6
  - sentence-similarity
@@ -136,6 +137,41 @@ ColBERT(
136
  ```
137
 
138
  ## Usage
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
139
  First install the PyLate library:
140
 
141
  ```bash
 
1
  ---
2
  tags:
3
  - ColBERT
4
+ - multi-vector
5
  - PyLate
6
  - sentence-transformers
7
  - sentence-similarity
 
137
  ```
138
 
139
  ## Usage
140
+
141
+ ### Sentence Transformers
142
+
143
+ This model can be used with [Sentence Transformers](https://www.sbert.net/) as a multi-vector (ColBERT-style late interaction) retriever via the `MultiVectorEncoder`:
144
+
145
+ ```bash
146
+ pip install "sentence-transformers>=6.0.0"
147
+ ```
148
+
149
+ ```python
150
+ from sentence_transformers import MultiVectorEncoder
151
+
152
+ model = MultiVectorEncoder("lightonai/LateOn")
153
+
154
+ query = "Which planet is known as the Red Planet?"
155
+ documents = [
156
+ "Venus is often called Earth's twin because of its similar size and proximity.",
157
+ "Mars, known for its reddish appearance, is often referred to as the Red Planet.",
158
+ "Jupiter, the largest planet in our solar system, has a prominent red spot.",
159
+ "Saturn, famous for its rings, is sometimes mistaken for the Red Planet.",
160
+ ]
161
+
162
+ query_embeddings = model.encode_query(query)
163
+ document_embeddings = model.encode_document(documents)
164
+ print(query_embeddings.shape, document_embeddings[0].shape)
165
+ # (12, 128) (18, 128)
166
+
167
+ # MaxSim late-interaction scoring (higher is more relevant)
168
+ scores = model.similarity(query_embeddings, document_embeddings)
169
+ print(scores)
170
+ # tensor([[10.7942, 11.1104, 10.9743, 11.0811]])
171
+ ```
172
+
173
+ ### PyLate
174
+
175
  First install the PyLate library:
176
 
177
  ```bash