Tom Aarsen
commited on
Commit
•
2df654a
1
Parent(s):
314777e
Add Sentence Transformers support
Browse files- 1_Pooling/config.json +9 -0
- README.md +35 -1
- config_sentence_transformers.json +7 -0
- modules.json +20 -0
1_Pooling/config.json
ADDED
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"word_embedding_dimension": 1024,
|
3 |
+
"pooling_mode_cls_token": false,
|
4 |
+
"pooling_mode_mean_tokens": true,
|
5 |
+
"pooling_mode_max_tokens": false,
|
6 |
+
"pooling_mode_mean_sqrt_len_tokens": false,
|
7 |
+
"pooling_mode_weightedmean_tokens": false,
|
8 |
+
"pooling_mode_lasttoken": false
|
9 |
+
}
|
README.md
CHANGED
@@ -1,6 +1,8 @@
|
|
1 |
---
|
2 |
tags:
|
3 |
- mteb
|
|
|
|
|
4 |
model-index:
|
5 |
- name: multilingual-e5-large-instruct
|
6 |
results:
|
@@ -5390,7 +5392,9 @@ This model has 24 layers and the embedding size is 1024.
|
|
5390 |
|
5391 |
## Usage
|
5392 |
|
5393 |
-
Below
|
|
|
|
|
5394 |
|
5395 |
```python
|
5396 |
import torch.nn.functional as F
|
@@ -5433,6 +5437,36 @@ embeddings = average_pool(outputs.last_hidden_state, batch_dict['attention_mask'
|
|
5433 |
embeddings = F.normalize(embeddings, p=2, dim=1)
|
5434 |
scores = (embeddings[:2] @ embeddings[2:].T) * 100
|
5435 |
print(scores.tolist())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5436 |
```
|
5437 |
|
5438 |
## Supported Languages
|
|
|
1 |
---
|
2 |
tags:
|
3 |
- mteb
|
4 |
+
- sentence-transformers
|
5 |
+
- transformers
|
6 |
model-index:
|
7 |
- name: multilingual-e5-large-instruct
|
8 |
results:
|
|
|
5392 |
|
5393 |
## Usage
|
5394 |
|
5395 |
+
Below are examples to encode queries and passages from the MS-MARCO passage ranking dataset.
|
5396 |
+
|
5397 |
+
### Transformers
|
5398 |
|
5399 |
```python
|
5400 |
import torch.nn.functional as F
|
|
|
5437 |
embeddings = F.normalize(embeddings, p=2, dim=1)
|
5438 |
scores = (embeddings[:2] @ embeddings[2:].T) * 100
|
5439 |
print(scores.tolist())
|
5440 |
+
# => [[91.92852783203125, 67.580322265625], [70.3814468383789, 92.1330795288086]]
|
5441 |
+
```
|
5442 |
+
|
5443 |
+
### Sentence Transformers
|
5444 |
+
|
5445 |
+
```python
|
5446 |
+
from sentence_transformers import SentenceTransformer
|
5447 |
+
|
5448 |
+
def get_detailed_instruct(task_description: str, query: str) -> str:
|
5449 |
+
return f'Instruct: {task_description}\nQuery: {query}'
|
5450 |
+
|
5451 |
+
# Each query must come with a one-sentence instruction that describes the task
|
5452 |
+
task = 'Given a web search query, retrieve relevant passages that answer the query'
|
5453 |
+
queries = [
|
5454 |
+
get_detailed_instruct(task, 'how much protein should a female eat'),
|
5455 |
+
get_detailed_instruct(task, '南瓜的家常做法')
|
5456 |
+
]
|
5457 |
+
# No need to add instruction for retrieval documents
|
5458 |
+
documents = [
|
5459 |
+
"As a general guideline, the CDC's average requirement of protein for women ages 19 to 70 is 46 grams per day. But, as you can see from this chart, you'll need to increase that if you're expecting or training for a marathon. Check out the chart below to see how much protein you should be eating each day.",
|
5460 |
+
"1.清炒南瓜丝 原料:嫩南瓜半个 调料:葱、盐、白糖、鸡精 做法: 1、南瓜用刀薄薄的削去表面一层皮,用勺子刮去瓤 2、擦成细丝(没有擦菜板就用刀慢慢切成细丝) 3、锅烧热放油,入葱花煸出香味 4、入南瓜丝快速翻炒一分钟左右,放盐、一点白糖和鸡精调味出锅 2.香葱炒南瓜 原料:南瓜1只 调料:香葱、蒜末、橄榄油、盐 做法: 1、将南瓜去皮,切成片 2、油锅8成热后,将蒜末放入爆香 3、爆香后,将南瓜片放入,翻炒 4、在翻炒的同时,可以不时地往锅里加水,但不要太多 5、放入盐,炒匀 6、南瓜差不多软和绵了之后,就可以关火 7、撒入香葱,即可出锅"
|
5461 |
+
]
|
5462 |
+
input_texts = queries + documents
|
5463 |
+
|
5464 |
+
model = SentenceTransformer('intfloat/multilingual-e5-large-instruct')
|
5465 |
+
|
5466 |
+
embeddings = model.encode(input_texts, convert_to_tensor=True, normalize_embeddings=True)
|
5467 |
+
scores = (embeddings[:2] @ embeddings[2:].T) * 100
|
5468 |
+
print(scores.tolist())
|
5469 |
+
# [[91.92853546142578, 67.5802993774414], [70.38143157958984, 92.13307189941406]]
|
5470 |
```
|
5471 |
|
5472 |
## Supported Languages
|
config_sentence_transformers.json
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"__version__": {
|
3 |
+
"sentence_transformers": "2.4.0.dev0",
|
4 |
+
"transformers": "4.37.0",
|
5 |
+
"pytorch": "2.1.0+cu121"
|
6 |
+
}
|
7 |
+
}
|
modules.json
ADDED
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
[
|
2 |
+
{
|
3 |
+
"idx": 0,
|
4 |
+
"name": "0",
|
5 |
+
"path": "",
|
6 |
+
"type": "sentence_transformers.models.Transformer"
|
7 |
+
},
|
8 |
+
{
|
9 |
+
"idx": 1,
|
10 |
+
"name": "1",
|
11 |
+
"path": "1_Pooling",
|
12 |
+
"type": "sentence_transformers.models.Pooling"
|
13 |
+
},
|
14 |
+
{
|
15 |
+
"idx": 2,
|
16 |
+
"name": "2",
|
17 |
+
"path": "2_Normalize",
|
18 |
+
"type": "sentence_transformers.models.Normalize"
|
19 |
+
}
|
20 |
+
]
|