johngiorgi
commited on
Commit
•
d10961b
1
Parent(s):
72ac136
Update with instructions on using with SentenceTransformers
Browse files
README.md
CHANGED
@@ -12,10 +12,33 @@ The model is intended to be used as a sentence encoder, similar to [Google's Uni
|
|
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-sci-base")
|
23 |
+
|
24 |
+
# Prepare some text to embed
|
25 |
+
text = [
|
26 |
+
"Oncogenic KRAS mutations are common in cancer.",
|
27 |
+
"Notably, c-Raf has recently been found essential for development of K-Ras-driven NSCLCs.",
|
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
|