Spaces:
Build error
Build error
Commit
Β·
26b15f7
1
Parent(s):
79ae41f
Update app.py
Browse files
app.py
CHANGED
@@ -27,11 +27,17 @@ def get_first_subword(word):
|
|
27 |
|
28 |
def search(token_to_lookup, num_neighbors=100):
|
29 |
i = get_first_subword(token_to_lookup)
|
30 |
-
_ ,
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
|
36 |
|
37 |
iface = gr.Interface(
|
@@ -39,7 +45,7 @@ iface = gr.Interface(
|
|
39 |
|
40 |
#inputs=[gr.Textbox(lines=1, label="Vocabulary Token", placeholder="Enter token..."), gr.Number(value=50, label="number of neighbors")],
|
41 |
inputs=gr.Textbox(lines=1, label="Vocabulary Token", placeholder="Enter token..."),
|
42 |
-
outputs=[gr.Textbox(label="Nearest tokens"), gr.Textbox(label="Nearest subwords")],
|
43 |
examples=[
|
44 |
["##logy"],
|
45 |
["##ness"],
|
|
|
27 |
|
28 |
def search(token_to_lookup, num_neighbors=100):
|
29 |
i = get_first_subword(token_to_lookup)
|
30 |
+
_ , I_IP = index_IP.search(normalized_input_embeddings[i:i+1], num_neighbors)
|
31 |
+
hits_IP = lookup_table.take(I_IP[0])
|
32 |
+
results_IP = hits_IP.values[1:]
|
33 |
+
results_IP = [r for r in results_IP if not "[unused" in r]
|
34 |
+
|
35 |
+
_ , I_L2 = index_L2.search(unnormalized_input_embeddings[i:i+1], num_neighbors)
|
36 |
+
hits_L2 = lookup_table.take(I_L2[0])
|
37 |
+
results_L2 = hits_L2.values[1:]
|
38 |
+
results_L2 = [r for r in results_L2 if not "[unused" in r]
|
39 |
+
|
40 |
+
return [r for r in results_IP if not "##" in r], [r for r in results_IP if "##" in r], [r for r in results_L2 if not "##" in r], [r for r in results_L2 if "##" in r]
|
41 |
|
42 |
|
43 |
iface = gr.Interface(
|
|
|
45 |
|
46 |
#inputs=[gr.Textbox(lines=1, label="Vocabulary Token", placeholder="Enter token..."), gr.Number(value=50, label="number of neighbors")],
|
47 |
inputs=gr.Textbox(lines=1, label="Vocabulary Token", placeholder="Enter token..."),
|
48 |
+
outputs=[gr.Textbox(label="IP-Nearest tokens"), gr.Textbox(label="IP-Nearest subwords"), gr.Textbox(label="L2-Nearest tokens"), gr.Textbox(label="L2-Nearest subwords")],
|
49 |
examples=[
|
50 |
["##logy"],
|
51 |
["##ness"],
|