Spaces:
Runtime error
Runtime error
10zinten
commited on
Commit
•
71d8560
1
Parent(s):
eb56afd
return oov exception
Browse files
app.py
CHANGED
@@ -19,6 +19,11 @@ def format_to_html(sim_output):
|
|
19 |
rows += f"<tr><td>{word}</td><td style='text-align: right'>{round(sim, 4)}</td></tr>"
|
20 |
return table.format(rows)
|
21 |
|
|
|
|
|
|
|
|
|
|
|
22 |
def find_most_similar(word):
|
23 |
sim_output = wv.most_similar(word)
|
24 |
return format_to_html(sim_output)
|
@@ -26,14 +31,17 @@ def find_most_similar(word):
|
|
26 |
def find_similarity(wordA, wordB):
|
27 |
try:
|
28 |
sim = wv.similarity(wordA, wordB)
|
29 |
-
except Exception:
|
30 |
-
|
31 |
-
|
|
|
|
|
32 |
|
33 |
title = "Check Word Similarity With Literary Word2Vec"
|
34 |
examples = ["སེམས་", "བླ་མ་", "སྟོབས་"]
|
35 |
|
36 |
-
|
|
|
37 |
|
38 |
demo = gr.Interface(
|
39 |
fn=find_similarity,
|
|
|
19 |
rows += f"<tr><td>{word}</td><td style='text-align: right'>{round(sim, 4)}</td></tr>"
|
20 |
return table.format(rows)
|
21 |
|
22 |
+
def get_oov_word(error, words):
|
23 |
+
words = {"A": words[0], "B": words[1]}
|
24 |
+
key = str(error).split()[1].strip()[1:-1]
|
25 |
+
return words[key]
|
26 |
+
|
27 |
def find_most_similar(word):
|
28 |
sim_output = wv.most_similar(word)
|
29 |
return format_to_html(sim_output)
|
|
|
31 |
def find_similarity(wordA, wordB):
|
32 |
try:
|
33 |
sim = wv.similarity(wordA, wordB)
|
34 |
+
except Exception as e:
|
35 |
+
oov_word = get_oov_word(e, [wordA, wordB])
|
36 |
+
return f"[Error] {oov_word} is an OOV"
|
37 |
+
|
38 |
+
return max([float(sim), 0.0])
|
39 |
|
40 |
title = "Check Word Similarity With Literary Word2Vec"
|
41 |
examples = ["སེམས་", "བླ་མ་", "སྟོབས་"]
|
42 |
|
43 |
+
assert isinstance(find_similarity(examples[0], examples[1]), float)
|
44 |
+
assert isinstance(find_similarity("ར་", "B"), str)
|
45 |
|
46 |
demo = gr.Interface(
|
47 |
fn=find_similarity,
|