johngiorgi
commited on
Commit
·
4292c8d
1
Parent(s):
2d2698d
Update with instructions on how to use with SentenceTransformers
Browse files
README.md
CHANGED
@@ -12,10 +12,33 @@ The model is intended to be used as a universal sentence encoder, similar to [Go
|
|
12 |
|
13 |
Please see [our repo](https://github.com/JohnGiorgi/DeCLUTR) for full details. A simple example is shown below.
|
14 |
|
|
|
|
|
15 |
```python
|
16 |
-
import torch
|
17 |
from scipy.spatial.distance import cosine
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
from transformers import AutoModel, AutoTokenizer
|
20 |
|
21 |
# Load the model
|
|
|
12 |
|
13 |
Please see [our repo](https://github.com/JohnGiorgi/DeCLUTR) for full details. A simple example is shown below.
|
14 |
|
15 |
+
##### With SentenceTransformers
|
16 |
+
|
17 |
```python
|
|
|
18 |
from scipy.spatial.distance import cosine
|
19 |
+
from sentence_transformers import SentenceTransformer
|
20 |
+
|
21 |
+
# Load the model
|
22 |
+
model = SentenceTransformer("johngiorgi/declutr-base")
|
23 |
+
|
24 |
+
# Prepare some text to embed
|
25 |
+
texts = [
|
26 |
+
"A smiling costumed woman is holding an umbrella.",
|
27 |
+
"A happy woman in a fairy costume holds an umbrella.",
|
28 |
+
]
|
29 |
|
30 |
+
# Embed the text
|
31 |
+
embeddings = model.encode(texts)
|
32 |
+
|
33 |
+
# Compute a semantic similarity via the cosine distance
|
34 |
+
semantic_sim = 1 - cosine(embeddings[0], embeddings[1])
|
35 |
+
```
|
36 |
+
|
37 |
+
##### With 🤗 Transformers
|
38 |
+
|
39 |
+
```python
|
40 |
+
import torch
|
41 |
+
from scipy.spatial.distance import cosine
|
42 |
from transformers import AutoModel, AutoTokenizer
|
43 |
|
44 |
# Load the model
|