Canstralian
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -1,6 +1,26 @@
|
|
1 |
-
|
2 |
-
from
|
|
|
3 |
|
4 |
-
|
|
|
5 |
|
6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from sentence_transformers import SentenceTransformer
|
2 |
+
from sklearn.metrics.pairwise import cosine_similarity
|
3 |
+
import numpy as np
|
4 |
|
5 |
+
# Load the model
|
6 |
+
model = SentenceTransformer("sentence-transformers/all-MiniLM-L6-v2")
|
7 |
|
8 |
+
# Define your sentences
|
9 |
+
sentences = [
|
10 |
+
"That is a happy person",
|
11 |
+
"That is a happy dog",
|
12 |
+
"That is a very happy person",
|
13 |
+
"Today is a sunny day"
|
14 |
+
]
|
15 |
+
|
16 |
+
# Encode the sentences to get their embeddings
|
17 |
+
embeddings = model.encode(sentences)
|
18 |
+
|
19 |
+
# Compute the cosine similarity matrix
|
20 |
+
similarities = cosine_similarity(embeddings)
|
21 |
+
|
22 |
+
# Print the shape of the similarity matrix
|
23 |
+
print(similarities.shape) # Output: (4, 4)
|
24 |
+
|
25 |
+
# Optionally, print the similarity matrix
|
26 |
+
print(similarities)
|