Spaces:
Sleeping
Sleeping
File size: 686 Bytes
935a660 4480f3c 935a660 5b71e40 4480f3c |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
import streamlit as st
from sentence_transformers import SentenceTransformer, util
model = SentenceTransformer('sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2')
secret_word = "nose"
secred_embedding = model.encode(secret_word)
if 'words' not in st.session_state:
st.session_state['words'] = []
st.write('Try to guess a secret word by semantic similarity')
word = st.text_input("Input a word")
if st.button("Guess"):
word_embedding = model.encode(word)
similarity = util.pytorch_cos_sim(secred_embedding, word_embedding).cpu().numpy()[0][0]
st.session_state['words'].append((word, similarity))
words = st.session_state['words']
st.write(words)
|