Create README.md
Browse files
README.md
ADDED
@@ -0,0 +1,72 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
tags:
|
3 |
+
- mteb
|
4 |
+
- Sentence Transformers
|
5 |
+
- sentence-similarity
|
6 |
+
- sentence-transformers
|
7 |
+
language:
|
8 |
+
- en
|
9 |
+
license: mit
|
10 |
+
---
|
11 |
+
|
12 |
+
# E5-RoPE-Base
|
13 |
+
|
14 |
+
[LongEmbed: Extending Embedding Models for Long Context Retrieval](). Dawei Zhu, Liang Wang, Nan Yang, Yifan Song, Wenhao Wu, Furu Wei, Sujian Li, arxiv 2024. Github Repo for LongEmbed: https://github.com/dwzhu-pku/LongEmbed.
|
15 |
+
|
16 |
+
This model has 12 layers and the embedding size is 768.
|
17 |
+
|
18 |
+
## Usage
|
19 |
+
|
20 |
+
Below is an example to encode queries and passages from the MS-MARCO passage ranking dataset.
|
21 |
+
|
22 |
+
```python
|
23 |
+
import torch.nn.functional as F
|
24 |
+
from torch import Tensor
|
25 |
+
from transformers import AutoTokenizer, AutoModel
|
26 |
+
def average_pool(last_hidden_states: Tensor,
|
27 |
+
attention_mask: Tensor) -> Tensor:
|
28 |
+
last_hidden = last_hidden_states.masked_fill(~attention_mask[..., None].bool(), 0.0)
|
29 |
+
return last_hidden.sum(dim=1) / attention_mask.sum(dim=1)[..., None]
|
30 |
+
# Each input text should start with "query: " or "passage: ".
|
31 |
+
# For tasks other than retrieval, you can simply use the "query: " prefix.
|
32 |
+
input_texts = ['query: how much protein should a female eat',
|
33 |
+
'query: summit define',
|
34 |
+
"passage: 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.",
|
35 |
+
"passage: Definition of summit for English Language Learners. : 1 the highest point of a mountain : the top of a mountain. : 2 the highest level. : 3 a meeting or series of meetings between the leaders of two or more governments."]
|
36 |
+
tokenizer = AutoTokenizer.from_pretrained('dwzhu/e5rope-base')
|
37 |
+
model = AutoModel.from_pretrained('dwzhu/e5rope-base')
|
38 |
+
# Tokenize the input texts
|
39 |
+
batch_dict = tokenizer(input_texts, max_length=512, padding=True, truncation=True, return_tensors='pt')
|
40 |
+
outputs = model(**batch_dict)
|
41 |
+
embeddings = average_pool(outputs.last_hidden_state, batch_dict['attention_mask'])
|
42 |
+
# normalize embeddings
|
43 |
+
embeddings = F.normalize(embeddings, p=2, dim=1)
|
44 |
+
scores = (embeddings[:2] @ embeddings[2:].T) * 100
|
45 |
+
print(scores.tolist())
|
46 |
+
```
|
47 |
+
|
48 |
+
## Training Details
|
49 |
+
|
50 |
+
Please refer to our paper at [https://arxiv.org/pdf/2212.03533.pdf](https://arxiv.org/pdf/2212.03533.pdf).
|
51 |
+
|
52 |
+
## Benchmark Evaluation
|
53 |
+
|
54 |
+
Check out [unilm/e5](https://github.com/microsoft/unilm/tree/master/e5) to reproduce evaluation results
|
55 |
+
on the [BEIR](https://arxiv.org/abs/2104.08663) and [MTEB benchmark](https://arxiv.org/abs/2210.07316).
|
56 |
+
|
57 |
+
|
58 |
+
Please note that E5-RoPE-Base is not specifically trained for optimized performance. Its purpose is to enable performance comparisons between embedding models that utilize absolute position embeddings (APE) and rotary position embeddings (RoPE). By comparing E5-Base and E5-RoPE-Base, we demonstrate the superiority of RoPE-based embedding models in effectively managing longer context. See our paper [LongEmbed: Extending Embedding Models for Long Context Retrieval]() for more details.
|
59 |
+
|
60 |
+
|
61 |
+
## Citation
|
62 |
+
|
63 |
+
If you find our paper or models helpful, please consider cite as follows:
|
64 |
+
|
65 |
+
```
|
66 |
+
@article{wang2022text,
|
67 |
+
title={Text Embeddings by Weakly-Supervised Contrastive Pre-training},
|
68 |
+
author={Wang, Liang and Yang, Nan and Huang, Xiaolong and Jiao, Binxing and Yang, Linjun and Jiang, Daxin and Majumder, Rangan and Wei, Furu},
|
69 |
+
journal={arXiv preprint arXiv:2212.03533},
|
70 |
+
year={2022}
|
71 |
+
}
|
72 |
+
```
|