use cosine_similarity
Browse files
README.md
CHANGED
|
@@ -2614,7 +2614,7 @@ language:
|
|
| 2614 |
**🤝 Follow us on:**
|
| 2615 |
|
| 2616 |
- GitHub: https://github.com/SeanLee97/AnglE.
|
| 2617 |
-
- Arxiv: https://arxiv.org/abs/2309.12871
|
| 2618 |
- 📘 Document: https://angle.readthedocs.io/en/latest/index.html
|
| 2619 |
|
| 2620 |
Welcome to using AnglE to train and infer powerful sentence embeddings.
|
|
@@ -2645,18 +2645,18 @@ There is no need to specify any prompts.
|
|
| 2645 |
|
| 2646 |
```python
|
| 2647 |
from angle_emb import AnglE
|
| 2648 |
-
from
|
| 2649 |
|
| 2650 |
angle = AnglE.from_pretrained('WhereIsAI/UAE-Large-V1', pooling_strategy='cls').cuda()
|
| 2651 |
doc_vecs = angle.encode([
|
| 2652 |
'The weather is great!',
|
| 2653 |
'The weather is very good!',
|
| 2654 |
'i am going to bed'
|
| 2655 |
-
])
|
| 2656 |
|
| 2657 |
for i, dv1 in enumerate(doc_vecs):
|
| 2658 |
for dv2 in doc_vecs[i+1:]:
|
| 2659 |
-
print(
|
| 2660 |
```
|
| 2661 |
|
| 2662 |
2) Retrieval Tasks
|
|
@@ -2665,7 +2665,7 @@ For retrieval purposes, please use the prompt `Prompts.C` for query (not for doc
|
|
| 2665 |
|
| 2666 |
```python
|
| 2667 |
from angle_emb import AnglE, Prompts
|
| 2668 |
-
from
|
| 2669 |
|
| 2670 |
angle = AnglE.from_pretrained('WhereIsAI/UAE-Large-V1', pooling_strategy='cls').cuda()
|
| 2671 |
qv = angle.encode(Prompts.C.format(text='what is the weather?'))
|
|
@@ -2676,7 +2676,7 @@ doc_vecs = angle.encode([
|
|
| 2676 |
])
|
| 2677 |
|
| 2678 |
for dv in doc_vecs:
|
| 2679 |
-
print(
|
| 2680 |
```
|
| 2681 |
|
| 2682 |
## 2. sentence transformer
|
|
|
|
| 2614 |
**🤝 Follow us on:**
|
| 2615 |
|
| 2616 |
- GitHub: https://github.com/SeanLee97/AnglE.
|
| 2617 |
+
- Arxiv: https://arxiv.org/abs/2309.12871 (ACL24)
|
| 2618 |
- 📘 Document: https://angle.readthedocs.io/en/latest/index.html
|
| 2619 |
|
| 2620 |
Welcome to using AnglE to train and infer powerful sentence embeddings.
|
|
|
|
| 2645 |
|
| 2646 |
```python
|
| 2647 |
from angle_emb import AnglE
|
| 2648 |
+
from angle_emb.utils import cosine_similarity
|
| 2649 |
|
| 2650 |
angle = AnglE.from_pretrained('WhereIsAI/UAE-Large-V1', pooling_strategy='cls').cuda()
|
| 2651 |
doc_vecs = angle.encode([
|
| 2652 |
'The weather is great!',
|
| 2653 |
'The weather is very good!',
|
| 2654 |
'i am going to bed'
|
| 2655 |
+
], normalize_embedding=True)
|
| 2656 |
|
| 2657 |
for i, dv1 in enumerate(doc_vecs):
|
| 2658 |
for dv2 in doc_vecs[i+1:]:
|
| 2659 |
+
print(cosine_similarity(dv1, dv2))
|
| 2660 |
```
|
| 2661 |
|
| 2662 |
2) Retrieval Tasks
|
|
|
|
| 2665 |
|
| 2666 |
```python
|
| 2667 |
from angle_emb import AnglE, Prompts
|
| 2668 |
+
from angle_emb.utils import cosine_similarity
|
| 2669 |
|
| 2670 |
angle = AnglE.from_pretrained('WhereIsAI/UAE-Large-V1', pooling_strategy='cls').cuda()
|
| 2671 |
qv = angle.encode(Prompts.C.format(text='what is the weather?'))
|
|
|
|
| 2676 |
])
|
| 2677 |
|
| 2678 |
for dv in doc_vecs:
|
| 2679 |
+
print(cosine_similarity(qv[0], dv))
|
| 2680 |
```
|
| 2681 |
|
| 2682 |
## 2. sentence transformer
|