Spaces:
Runtime error
Runtime error
import streamlit as st | |
from transformers import pipeline | |
from textblob import TextBlob | |
from sentence_transformers import SentenceTransformer | |
from sklearn.metrics.pairwise import cosine_similarity | |
sentences = \ | |
[ | |
"I have a bigger house than you", | |
"You have a bigger house than me" | |
] | |
sentence_embeddings = model.encode(sentences) | |
for sentence, embedding in zip(sentences, sentence_embeddings): | |
print("Sentence:", sentence) | |
print("Embedding:", embedding) | |
print("") | |
print('Similarity between {} and {} is {}'.format(sentences[0], | |
sentences[1], | |
cosine_similarity(sentence_embeddings[0].reshape(1, -1), | |
sentence_embeddings[1].reshape(1, -1))[0][0])) |