mmazuecos's picture
Update app.py
a71f9d4
raw
history blame
903 Bytes
import streamlit as st
from sentence_transformers.util import cos_sim
from sentence_transformers import SentenceTransformer
@st.cache
def load_model():
model = SentenceTransformer('hackathon-pln-es/bertin-roberta-base-finetuning-esnli')
model.eval()
return model
st.title("Sentence Embedding for Spanish with Bertin")
st.write("Sentence embedding for spanish trained on NLI. Used for Sentence Textual Similarity. Based on the model hackathon-pln-es/bertin-roberta-base-finetuning-esnli.")
sent1 = st.text_area('Enter sentence 1')
sent2 = st.text_area('Enter sentence 2')
if st.button('Compute similarity'):
if sent1 and sent2:
model = load_model()
encodings = model.encode([sent1, sent2])
sim = cos_sim(encodings[0], encodings[1]).numpy().tolist()[0][0]
st.text('Cosine Similarity: {0:.4f}'.format(sim))
else:
st.write('Missing a sentences')
else:
pass