vahidthegreat
commited on
Commit
•
7e40316
1
Parent(s):
987cd51
Update README.md
Browse files
README.md
CHANGED
@@ -40,23 +40,42 @@ pip install peft sentence-transformers
|
|
40 |
from sentence_transformers import SentenceTransformer
|
41 |
from peft import PeftModel
|
42 |
|
43 |
-
|
44 |
-
|
|
|
45 |
|
46 |
sentences = [
|
47 |
"I love pineapple on pizza",
|
48 |
"I hate pineapple on pizza",
|
49 |
"I like pineapple on pizza",
|
50 |
]
|
51 |
-
embeddings =
|
|
|
52 |
print(embeddings.shape)
|
53 |
|
54 |
-
similarity =
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
55 |
print(similarity)
|
56 |
```
|
57 |
|
58 |
```output
|
|
|
59 |
(3, 768)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
60 |
tensor([[1.0000, 0.5732, 0.9713],
|
61 |
[0.5732, 1.0000, 0.5804],
|
62 |
[0.9713, 0.5804, 1.0000]])
|
|
|
40 |
from sentence_transformers import SentenceTransformer
|
41 |
from peft import PeftModel
|
42 |
|
43 |
+
base_model = SentenceTransformer("all-mpnet-base-v2")
|
44 |
+
finetuned_model = SentenceTransformer("all-mpnet-base-v2")
|
45 |
+
finetuned_model[0].auto_model = PeftModel.from_pretrained(finetuned_model[0].auto_model, "vahidthegreat/StanceAware-SBERT")
|
46 |
|
47 |
sentences = [
|
48 |
"I love pineapple on pizza",
|
49 |
"I hate pineapple on pizza",
|
50 |
"I like pineapple on pizza",
|
51 |
]
|
52 |
+
embeddings = base_model.encode(sentences)
|
53 |
+
print('Embedding Shape:')
|
54 |
print(embeddings.shape)
|
55 |
|
56 |
+
similarity = base_model.similarity(embeddings, embeddings)
|
57 |
+
print('\n\nSimilarity Matrix for the Base Model:')
|
58 |
+
print(similarity)
|
59 |
+
|
60 |
+
|
61 |
+
embeddings = finetuned_model.encode(sentences)
|
62 |
+
similarity = finetuned_model.similarity(embeddings, embeddings)
|
63 |
+
print('\n\nSimilarity Matrix for the FineTuned Model:')
|
64 |
print(similarity)
|
65 |
```
|
66 |
|
67 |
```output
|
68 |
+
Embedding Shape:
|
69 |
(3, 768)
|
70 |
+
|
71 |
+
|
72 |
+
Similarity Matrix for the Base Model:
|
73 |
+
tensor([[1.0000, 0.8591, 0.9774],
|
74 |
+
[0.8591, 1.0000, 0.8561],
|
75 |
+
[0.9774, 0.8561, 1.0000]])
|
76 |
+
|
77 |
+
|
78 |
+
Similarity Matrix for the FineTuned Model:
|
79 |
tensor([[1.0000, 0.5732, 0.9713],
|
80 |
[0.5732, 1.0000, 0.5804],
|
81 |
[0.9713, 0.5804, 1.0000]])
|