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