Spaces:
Running
Running
Update the usage snippet
Browse files
README.md
CHANGED
@@ -16,13 +16,28 @@ pip install -U sentence-transformers
|
|
16 |
The usage is as simple as:
|
17 |
```python
|
18 |
from sentence_transformers import SentenceTransformer
|
19 |
-
model = SentenceTransformer('paraphrase-MiniLM-L6-v2')
|
20 |
|
21 |
-
#
|
22 |
-
|
23 |
|
24 |
-
#
|
25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
```
|
27 |
|
28 |
Hugging Face makes it easy to collaboratively build and showcase your [Sentence Transformers](https://www.sbert.net/) models! You can collaborate with your organization, upload and showcase your own models in your profile ❤️
|
|
|
16 |
The usage is as simple as:
|
17 |
```python
|
18 |
from sentence_transformers import SentenceTransformer
|
|
|
19 |
|
20 |
+
# 1. Load a pretrained Sentence Transformer model
|
21 |
+
model = SentenceTransformer("all-MiniLM-L6-v2")
|
22 |
|
23 |
+
# The sentences to encode
|
24 |
+
sentences = [
|
25 |
+
"The weather is lovely today.",
|
26 |
+
"It's so sunny outside!",
|
27 |
+
"He drove to the stadium.",
|
28 |
+
]
|
29 |
+
|
30 |
+
# 2. Calculate embeddings by calling model.encode()
|
31 |
+
embeddings = model.encode(sentences)
|
32 |
+
print(embeddings.shape)
|
33 |
+
# [3, 384]
|
34 |
+
|
35 |
+
# 3. Calculate the embedding similarities
|
36 |
+
similarities = model.similarity(embeddings, embeddings)
|
37 |
+
print(similarities)
|
38 |
+
# tensor([[1.0000, 0.6660, 0.1046],
|
39 |
+
# [0.6660, 1.0000, 0.1411],
|
40 |
+
# [0.1046, 0.1411, 1.0000]])
|
41 |
```
|
42 |
|
43 |
Hugging Face makes it easy to collaboratively build and showcase your [Sentence Transformers](https://www.sbert.net/) models! You can collaborate with your organization, upload and showcase your own models in your profile ❤️
|