SBERT_Score / SBERT_Score.py
pa90's picture
Upload SBERT_Score.py
96ec84e verified
raw
history blame contribute delete
864 Bytes
from sentence_transformers import SentenceTransformer, util
# ✅ Use raw string for Windows path
model = SentenceTransformer('sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2')
print("\n--- SBERT Metaphor–Literal Similarity Checker ---")
print("Type 'exit' to quit at any time.\n")
while True:
sentence1 = input("🔸 Enter a **metaphorical** sentence: ")
if sentence1.strip().lower() == 'exit':
break
sentence2 = input("🔹 Enter a **literal paraphrase**: ")
if sentence2.strip().lower() == 'exit':
break
# Encode sentences
embeddings = model.encode([sentence1, sentence2], convert_to_tensor=True)
# Compute cosine similarity
score = util.pytorch_cos_sim(embeddings[0], embeddings[1]).item()
print(f"\n🧠 Cosine Similarity Score: {score:.4f} (range: -1 to 1)\n")