joehare's picture
Update app.py
359508c
raw
history blame
1.09 kB
import streamlit as st
st.title("Paraphrase Mining Example")
from sentence_transformers import SentenceTransformer, util
model = SentenceTransformer('all-MiniLM-L6-v2')
# Two lists of sentences
sentences1 = ['The cat sits outside',
'A man is playing guitar',
'The new movie is awesome']
sentences2 = ['The dog plays in the garden',
'A woman watches TV',
'The new movie is so great']
#Compute embedding for both lists
embeddings1 = model.encode(sentences1, convert_to_tensor=True)
embeddings2 = model.encode(sentences2, convert_to_tensor=True)
#Compute cosine-similarities
cosine_scores = util.cos_sim(embeddings1, embeddings2)
(col1, col2, score_col)= st.columns(3)
col1.header("first sentence")
col2.header("second sentence")
score_col.header("score")
#Output the pairs with their score
for i in range(len(sentences1)):
#st.text("{} \t\t {} \t\t Score: {:.4f}".format(sentences1[i], sentences2[i], cosine_scores[i][i]))
col1.write(sentences1[i])
col2.write(sentences2[i])
score_col.write(cosine_scores[i][i])