| 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() | |