Download embedd.py from ArunKr/triplet-embed: direct link, hf CLI and curl.
- Browser
- Download file 665 Bytes
-
https://huggingface.co/ArunKr/triplet-embed/resolve/main/embedd.py
- Command line
-
hf download hf://ArunKr/triplet-embed/embedd.py
-
curl -L -o embedd.py https://huggingface.co/ArunKr/triplet-embed/resolve/main/embedd.py
665 Bytes
| 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() | |