File size: 864 Bytes
96ec84e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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")