Add Sentence Transformers usage

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