File size: 665 Bytes
d65bc08 |
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 26 27 |
from sentence_transformers import SentenceTransformer, util
def main():
# Load the fine-tuned model
model = SentenceTransformer('fine_tuned_sbert_triplet')
# Example sentences
sentences = [
"A man is playing a guitar",
"A person is playing a guitar",
"A woman is reading a book"
]
# Compute embeddings
embeddings = model.encode(sentences, convert_to_tensor=True)
# Compute cosine similarity between all pairs
cosine_sim = util.pytorch_cos_sim(embeddings, embeddings)
# Display similarity matrix
print("Cosine Similarity Matrix:")
print(cosine_sim)
if __name__ == "__main__":
main()
|