pa90 commited on
Commit
96ec84e
·
verified ·
1 Parent(s): 93a6c95

Upload SBERT_Score.py

Browse files
Files changed (1) hide show
  1. SBERT_Score.py +24 -0
SBERT_Score.py ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from sentence_transformers import SentenceTransformer, util
2
+
3
+ # ✅ Use raw string for Windows path
4
+ model = SentenceTransformer('sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2')
5
+
6
+ print("\n--- SBERT Metaphor–Literal Similarity Checker ---")
7
+ print("Type 'exit' to quit at any time.\n")
8
+
9
+ while True:
10
+ sentence1 = input("🔸 Enter a **metaphorical** sentence: ")
11
+ if sentence1.strip().lower() == 'exit':
12
+ break
13
+
14
+ sentence2 = input("🔹 Enter a **literal paraphrase**: ")
15
+ if sentence2.strip().lower() == 'exit':
16
+ break
17
+
18
+ # Encode sentences
19
+ embeddings = model.encode([sentence1, sentence2], convert_to_tensor=True)
20
+
21
+ # Compute cosine similarity
22
+ score = util.pytorch_cos_sim(embeddings[0], embeddings[1]).item()
23
+
24
+ print(f"\n🧠 Cosine Similarity Score: {score:.4f} (range: -1 to 1)\n")