Spaces:
Sleeping
Sleeping
flow3rdown
commited on
Commit
·
e107c7c
1
Parent(s):
f7d7aa5
Update app.py
Browse files
app.py
CHANGED
@@ -1,6 +1,7 @@
|
|
1 |
import gradio as gr
|
2 |
from gensim.models import KeyedVectors
|
3 |
|
|
|
4 |
def isNoneWords(word):
|
5 |
if word is None or len(word)==0 or word not in model.key_to_index:
|
6 |
return True
|
@@ -11,10 +12,16 @@ def top_similarity_route(word):
|
|
11 |
if isNoneWords(word):
|
12 |
return "word is null or not in model!"
|
13 |
else:
|
14 |
-
|
|
|
|
|
|
|
|
|
15 |
|
16 |
|
17 |
if __name__ == '__main__':
|
18 |
model = KeyedVectors.load_word2vec_format('tencent-ailab-embedding-zh-d100-v0.2.0-s.txt', binary=False)
|
19 |
-
|
20 |
-
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
from gensim.models import KeyedVectors
|
3 |
|
4 |
+
|
5 |
def isNoneWords(word):
|
6 |
if word is None or len(word)==0 or word not in model.key_to_index:
|
7 |
return True
|
|
|
12 |
if isNoneWords(word):
|
13 |
return "word is null or not in model!"
|
14 |
else:
|
15 |
+
top_similar_words = model.similar_by_word(word, topn=20, restrict_vocab=None)
|
16 |
+
sim_res = ""
|
17 |
+
for item in top_similar_words:
|
18 |
+
sim_res += f'{item[0]}: {round(item[1], 4)}\n'
|
19 |
+
return sim_res
|
20 |
|
21 |
|
22 |
if __name__ == '__main__':
|
23 |
model = KeyedVectors.load_word2vec_format('tencent-ailab-embedding-zh-d100-v0.2.0-s.txt', binary=False)
|
24 |
+
|
25 |
+
title = 'Calculate word similarity based on Tencent AI Lab Embedding'
|
26 |
+
iface = gr.Interface(fn=top_similarity_route, inputs="Word", outputs="Similar words", title=title)
|
27 |
+
iface.launch(share=True)
|