Update README.md
Browse files
README.md
CHANGED
@@ -2603,6 +2603,8 @@ license: mit
|
|
2603 |
|
2604 |
## E5-large
|
2605 |
|
|
|
|
|
2606 |
[Text Embeddings by Weakly-Supervised Contrastive Pre-training](https://arxiv.org/pdf/2212.03533.pdf).
|
2607 |
Liang Wang, Nan Yang, Xiaolong Huang, Binxing Jiao, Linjun Yang, Daxin Jiang, Rangan Majumder, Furu Wei, arXiv 2022
|
2608 |
|
@@ -2641,7 +2643,7 @@ batch_dict = tokenizer(input_texts, max_length=512, padding=True, truncation=Tru
|
|
2641 |
outputs = model(**batch_dict)
|
2642 |
embeddings = average_pool(outputs.last_hidden_state, batch_dict['attention_mask'])
|
2643 |
|
2644 |
-
#
|
2645 |
embeddings = F.normalize(embeddings, p=2, dim=1)
|
2646 |
scores = (embeddings[:2] @ embeddings[2:].T) * 100
|
2647 |
print(scores.tolist())
|
@@ -2656,6 +2658,44 @@ Please refer to our paper at [https://arxiv.org/pdf/2212.03533.pdf](https://arxi
|
|
2656 |
Check out [unilm/e5](https://github.com/microsoft/unilm/tree/master/e5) to reproduce evaluation results
|
2657 |
on the [BEIR](https://arxiv.org/abs/2104.08663) and [MTEB benchmark](https://arxiv.org/abs/2210.07316).
|
2658 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2659 |
## Citation
|
2660 |
|
2661 |
If you find our paper or models helpful, please consider cite as follows:
|
@@ -2671,4 +2711,4 @@ If you find our paper or models helpful, please consider cite as follows:
|
|
2671 |
|
2672 |
## Limitations
|
2673 |
|
2674 |
-
This model only works for English texts. Long texts will be truncated to at most 512 tokens.
|
|
|
2603 |
|
2604 |
## E5-large
|
2605 |
|
2606 |
+
**News (May 2023): please switch to [e5-large-v2](https://huggingface.co/intfloat/e5-large-v2), which has better performance and same method of usage.**
|
2607 |
+
|
2608 |
[Text Embeddings by Weakly-Supervised Contrastive Pre-training](https://arxiv.org/pdf/2212.03533.pdf).
|
2609 |
Liang Wang, Nan Yang, Xiaolong Huang, Binxing Jiao, Linjun Yang, Daxin Jiang, Rangan Majumder, Furu Wei, arXiv 2022
|
2610 |
|
|
|
2643 |
outputs = model(**batch_dict)
|
2644 |
embeddings = average_pool(outputs.last_hidden_state, batch_dict['attention_mask'])
|
2645 |
|
2646 |
+
# normalize embeddings
|
2647 |
embeddings = F.normalize(embeddings, p=2, dim=1)
|
2648 |
scores = (embeddings[:2] @ embeddings[2:].T) * 100
|
2649 |
print(scores.tolist())
|
|
|
2658 |
Check out [unilm/e5](https://github.com/microsoft/unilm/tree/master/e5) to reproduce evaluation results
|
2659 |
on the [BEIR](https://arxiv.org/abs/2104.08663) and [MTEB benchmark](https://arxiv.org/abs/2210.07316).
|
2660 |
|
2661 |
+
## Support for Sentence Transformers
|
2662 |
+
|
2663 |
+
Below is an example for usage with sentence_transformers.
|
2664 |
+
```python
|
2665 |
+
from sentence_transformers import SentenceTransformer
|
2666 |
+
model = SentenceTransformer('intfloat/e5-large')
|
2667 |
+
input_texts = [
|
2668 |
+
'query: how much protein should a female eat',
|
2669 |
+
'query: summit define',
|
2670 |
+
"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.",
|
2671 |
+
"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."
|
2672 |
+
]
|
2673 |
+
embeddings = model.encode(input_texts, normalize_embeddings=True)
|
2674 |
+
```
|
2675 |
+
|
2676 |
+
Package requirements
|
2677 |
+
|
2678 |
+
`pip install sentence_transformers~=2.2.2`
|
2679 |
+
|
2680 |
+
Contributors: [michaelfeil](https://huggingface.co/michaelfeil)
|
2681 |
+
|
2682 |
+
## FAQ
|
2683 |
+
|
2684 |
+
**1. Do I need to add the prefix "query: " and "passage: " to input texts?**
|
2685 |
+
|
2686 |
+
Yes, this is how the model is trained, otherwise you will see a performance degradation.
|
2687 |
+
|
2688 |
+
Here are some rules of thumb:
|
2689 |
+
- Use "query: " and "passage: " correspondingly for asymmetric tasks such as passage retrieval in open QA, ad-hoc information retrieval.
|
2690 |
+
|
2691 |
+
- Use "query: " prefix for symmetric tasks such as semantic similarity, paraphrase retrieval.
|
2692 |
+
|
2693 |
+
- Use "query: " prefix if you want to use embeddings as features, such as linear probing classification, clustering.
|
2694 |
+
|
2695 |
+
**2. Why are my reproduced results slightly different from reported in the model card?**
|
2696 |
+
|
2697 |
+
Different versions of `transformers` and `pytorch` could cause negligible but non-zero performance differences.
|
2698 |
+
|
2699 |
## Citation
|
2700 |
|
2701 |
If you find our paper or models helpful, please consider cite as follows:
|
|
|
2711 |
|
2712 |
## Limitations
|
2713 |
|
2714 |
+
This model only works for English texts. Long texts will be truncated to at most 512 tokens.
|