Update README.md
Browse files
README.md
CHANGED
|
@@ -81,7 +81,7 @@ KeyError: 'qwen2'
|
|
| 81 |
```
|
| 82 |
|
| 83 |
## Usage
|
| 84 |
-
|
| 85 |
Using this model becomes easy when you have [sentence-transformers](https://www.SBERT.net) installed:
|
| 86 |
|
| 87 |
```
|
|
@@ -132,6 +132,33 @@ embeddings = model.encode(
|
|
| 132 |
print(embeddings)
|
| 133 |
```
|
| 134 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 135 |
|
| 136 |
## Citation
|
| 137 |
If you find this model useful, please consider giving a star and citation.
|
|
|
|
| 81 |
```
|
| 82 |
|
| 83 |
## Usage
|
| 84 |
+
### sentence-transformers support
|
| 85 |
Using this model becomes easy when you have [sentence-transformers](https://www.SBERT.net) installed:
|
| 86 |
|
| 87 |
```
|
|
|
|
| 132 |
print(embeddings)
|
| 133 |
```
|
| 134 |
|
| 135 |
+
### vllm support
|
| 136 |
+
```python
|
| 137 |
+
import torch
|
| 138 |
+
import vllm
|
| 139 |
+
from vllm import LLM
|
| 140 |
+
def get_detailed_instruct(task_description: str, query: str) -> str:
|
| 141 |
+
return f'Instruct: {task_description}\nQuery:{query}'
|
| 142 |
+
|
| 143 |
+
task = 'Given a query, retrieve documents that answer the query'
|
| 144 |
+
queries = [
|
| 145 |
+
get_detailed_instruct(task, 'What is the capital of China?'),
|
| 146 |
+
get_detailed_instruct(task, 'Explain gravity')
|
| 147 |
+
]
|
| 148 |
+
documents = [
|
| 149 |
+
"The capital of China is Beijing.",
|
| 150 |
+
"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."
|
| 151 |
+
]
|
| 152 |
+
input_texts = queries + documents
|
| 153 |
+
|
| 154 |
+
model = LLM(model="{MODEL_NAME_OR_PATH}", task="embed", trust_remote_code=True, dtype="float16")
|
| 155 |
+
|
| 156 |
+
outputs = model.embed(input_texts)
|
| 157 |
+
embeddings = torch.tensor([o.outputs.embedding for o in outputs])
|
| 158 |
+
scores = (embeddings[:2] @ embeddings[2:].T)
|
| 159 |
+
print(scores.tolist())
|
| 160 |
+
```
|
| 161 |
+
|
| 162 |
|
| 163 |
## Citation
|
| 164 |
If you find this model useful, please consider giving a star and citation.
|