Programming, Artificial Intelligence, Machine Learning, Data Science, Python.
contexts: import torch # Define the cosine_similarity function def cosine_similarity(vec1, vec2): vec1 = vec1.squeeze() vec2 = vec2.squeeze() return torch.dot(vec1, vec2) / (torch.norm(vec1) * torch.norm(vec2)) # Define the sentence_to_embeddings function def sentence_to_embeddings(sentence, model,