Programming, Artificial Intelligence, Machine Learning, Data Science, Python.
sentence_to_embeddings(sentence2, model, tokenizer) avg_embedding1 = torch.mean(embedding1, dim=1) avg_embedding2 = torch.mean(embedding2, dim=1) similarity = cosine_similarity(avg_embedding1, avg_embedding2) print(f"Cosine similarity between embeddings of the sentences: {similarity.item():.2f}")