Update README.md
Browse files
README.md
CHANGED
@@ -2641,7 +2641,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 +2656,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 +2709,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.
|
|
|
2641 |
outputs = model(**batch_dict)
|
2642 |
embeddings = average_pool(outputs.last_hidden_state, batch_dict['attention_mask'])
|
2643 |
|
2644 |
+
# normalize embeddings
|
2645 |
embeddings = F.normalize(embeddings, p=2, dim=1)
|
2646 |
scores = (embeddings[:2] @ embeddings[2:].T) * 100
|
2647 |
print(scores.tolist())
|
|
|
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 |
+
## Support for Sentence Transformers
|
2660 |
+
|
2661 |
+
Below is an example for usage with sentence_transformers.
|
2662 |
+
```python
|
2663 |
+
from sentence_transformers import SentenceTransformer
|
2664 |
+
model = SentenceTransformer('intfloat/e5-large-v2')
|
2665 |
+
input_texts = [
|
2666 |
+
'query: how much protein should a female eat',
|
2667 |
+
'query: summit define',
|
2668 |
+
"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.",
|
2669 |
+
"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."
|
2670 |
+
]
|
2671 |
+
embeddings = model.encode(input_texts, normalize_embeddings=True)
|
2672 |
+
```
|
2673 |
+
|
2674 |
+
Package requirements
|
2675 |
+
|
2676 |
+
`pip install sentence_transformers~=2.2.2`
|
2677 |
+
|
2678 |
+
Contributors: [michaelfeil](https://huggingface.co/michaelfeil)
|
2679 |
+
|
2680 |
+
## FAQ
|
2681 |
+
|
2682 |
+
**1. Do I need to add the prefix "query: " and "passage: " to input texts?**
|
2683 |
+
|
2684 |
+
Yes, this is how the model is trained, otherwise you will see a performance degradation.
|
2685 |
+
|
2686 |
+
Here are some rules of thumb:
|
2687 |
+
- Use "query: " and "passage: " correspondingly for asymmetric tasks such as passage retrieval in open QA, ad-hoc information retrieval.
|
2688 |
+
|
2689 |
+
- Use "query: " prefix for symmetric tasks such as semantic similarity, paraphrase retrieval.
|
2690 |
+
|
2691 |
+
- Use "query: " prefix if you want to use embeddings as features, such as linear probing classification, clustering.
|
2692 |
+
|
2693 |
+
**2. Why are my reproduced results slightly different from reported in the model card?**
|
2694 |
+
|
2695 |
+
Different versions of `transformers` and `pytorch` could cause negligible but non-zero performance differences.
|
2696 |
+
|
2697 |
## Citation
|
2698 |
|
2699 |
If you find our paper or models helpful, please consider cite as follows:
|
|
|
2709 |
|
2710 |
## Limitations
|
2711 |
|
2712 |
+
This model only works for English texts. Long texts will be truncated to at most 512 tokens.
|