Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -29,25 +29,20 @@ if text:
|
|
29 |
result = nlp(text+' '+nlp.tokenizer.mask_token)
|
30 |
data_load_state.text('')
|
31 |
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
|
37 |
for index, r in enumerate(result):
|
38 |
-
|
|
|
39 |
if r['token_str'].lower().strip() in history_keyword_text.lower().strip() and len(r['token_str'].lower().strip())>1:
|
40 |
#found from history, then increase the score of tokens
|
41 |
result[index]['score']*=HISTORY_WEIGHT
|
42 |
|
43 |
-
|
44 |
-
|
45 |
#sort the results
|
46 |
df=pd.DataFrame(result).sort_values(by='score', ascending=False)
|
47 |
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
#show the results as a table
|
53 |
st.table(df)
|
|
|
29 |
result = nlp(text+' '+nlp.tokenizer.mask_token)
|
30 |
data_load_state.text('')
|
31 |
|
32 |
+
if len(semantic_text):
|
33 |
+
predicted_embeddings = model.encode(result['sequence'], convert_to_tensor=True)
|
34 |
+
semantic_history_embeddings = model.encode(semantic_text.spllit(','), convert_to_tensor=True)
|
35 |
+
cosine_scores = util.cos_sim(predicted_embeddings, semantic_history_embeddings)
|
36 |
|
37 |
for index, r in enumerate(result):
|
38 |
+
if len(semantic_text):
|
39 |
+
result[index]['score']*=cosine_scores[index][index]
|
40 |
if r['token_str'].lower().strip() in history_keyword_text.lower().strip() and len(r['token_str'].lower().strip())>1:
|
41 |
#found from history, then increase the score of tokens
|
42 |
result[index]['score']*=HISTORY_WEIGHT
|
43 |
|
|
|
|
|
44 |
#sort the results
|
45 |
df=pd.DataFrame(result).sort_values(by='score', ascending=False)
|
46 |
|
|
|
|
|
|
|
|
|
47 |
#show the results as a table
|
48 |
st.table(df)
|