add use case for vllm & modify Citation (#4)
Browse files- add use case for vllm & modify Citation (2907c29945ffaa6297b9e7aca27a8eb9239a3a0a)
Co-authored-by: yanzhao <[email protected]>
README.md
CHANGED
@@ -63,6 +63,7 @@ KeyError: 'qwen3'
|
|
63 |
|
64 |
```python
|
65 |
# Requires transformers>=4.51.0
|
|
|
66 |
|
67 |
from sentence_transformers import SentenceTransformer
|
68 |
|
@@ -165,6 +166,41 @@ scores = (embeddings[:2] @ embeddings[2:].T)
|
|
165 |
print(scores.tolist())
|
166 |
# [[0.7534257769584656, 0.1146894246339798], [0.03198453038930893, 0.6258305311203003]]
|
167 |
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
168 |
📌 **Tip**: We recommend that developers customize the `instruct` according to their specific scenarios, tasks, and languages. Our tests have shown that in most retrieval scenarios, not using an `instruct` on the query side can lead to a drop in retrieval performance by approximately 1% to 5%.
|
169 |
|
170 |
## Evaluation
|
@@ -222,11 +258,10 @@ print(scores.tolist())
|
|
222 |
If you find our work helpful, feel free to give us a cite.
|
223 |
|
224 |
```
|
225 |
-
@
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
year = {2025}
|
231 |
}
|
232 |
```
|
|
|
63 |
|
64 |
```python
|
65 |
# Requires transformers>=4.51.0
|
66 |
+
# Requires sentence-transformers>=2.7.0
|
67 |
|
68 |
from sentence_transformers import SentenceTransformer
|
69 |
|
|
|
166 |
print(scores.tolist())
|
167 |
# [[0.7534257769584656, 0.1146894246339798], [0.03198453038930893, 0.6258305311203003]]
|
168 |
```
|
169 |
+
|
170 |
+
### vLLM Usage
|
171 |
+
|
172 |
+
```python
|
173 |
+
# Requires vllm>=0.8.5
|
174 |
+
import torch
|
175 |
+
import vllm
|
176 |
+
from vllm import LLM
|
177 |
+
|
178 |
+
def get_detailed_instruct(task_description: str, query: str) -> str:
|
179 |
+
return f'Instruct: {task_description}\nQuery:{query}'
|
180 |
+
|
181 |
+
# Each query must come with a one-sentence instruction that describes the task
|
182 |
+
task = 'Given a web search query, retrieve relevant passages that answer the query'
|
183 |
+
|
184 |
+
queries = [
|
185 |
+
get_detailed_instruct(task, 'What is the capital of China?'),
|
186 |
+
get_detailed_instruct(task, 'Explain gravity')
|
187 |
+
]
|
188 |
+
# No need to add instruction for retrieval documents
|
189 |
+
documents = [
|
190 |
+
"The capital of China is Beijing.",
|
191 |
+
"Gravity is a force that attracts two bodies towards each other. It gives weight to physical objects and is responsible for the movement of planets around the sun."
|
192 |
+
]
|
193 |
+
input_texts = queries + documents
|
194 |
+
|
195 |
+
model = LLM(model="Qwen/Qwen3-Embedding-4B", task="embed")
|
196 |
+
|
197 |
+
outputs = model.embed(input_texts)
|
198 |
+
embeddings = torch.tensor([o.outputs.embedding for o in outputs])
|
199 |
+
scores = (embeddings[:2] @ embeddings[2:].T)
|
200 |
+
print(scores.tolist())
|
201 |
+
# [[0.7525103688240051, 0.1143278032541275], [0.030893627554178238, 0.6239761114120483]]
|
202 |
+
```
|
203 |
+
|
204 |
📌 **Tip**: We recommend that developers customize the `instruct` according to their specific scenarios, tasks, and languages. Our tests have shown that in most retrieval scenarios, not using an `instruct` on the query side can lead to a drop in retrieval performance by approximately 1% to 5%.
|
205 |
|
206 |
## Evaluation
|
|
|
258 |
If you find our work helpful, feel free to give us a cite.
|
259 |
|
260 |
```
|
261 |
+
@article{qwen3embedding,
|
262 |
+
title={Qwen3 Embedding: Advancing Text Embedding and Reranking Through Foundation Models},
|
263 |
+
author={Zhang, Yanzhao and Li, Mingxin and Long, Dingkun and Zhang, Xin and Lin, Huan and Yang, Baosong and Xie, Pengjun and Yang, An and Liu, Dayiheng and Lin, Junyang and Huang, Fei and Zhou, Jingren},
|
264 |
+
journal={arXiv preprint arXiv:2506.05176},
|
265 |
+
year={2025}
|
|
|
266 |
}
|
267 |
```
|