Spaces:
Build error
Build error
Commit
Β·
23020da
1
Parent(s):
2bbff8e
Update app.py
Browse files
app.py
CHANGED
|
@@ -12,8 +12,8 @@ unnormalized_input_embeddings = np.load("unnormalized_bert_input_embeddings.npy"
|
|
| 12 |
index_L2 = IndexFlatL2(unnormalized_input_embeddings.shape[-1])
|
| 13 |
index_L2.add(unnormalized_input_embeddings)
|
| 14 |
|
| 15 |
-
|
| 16 |
-
|
| 17 |
|
| 18 |
|
| 19 |
vocab = {v:k for k,v in tokenizer.vocab.items()}
|
|
@@ -27,7 +27,7 @@ def get_first_subword(word):
|
|
| 27 |
|
| 28 |
def search(token_to_lookup, num_neighbors):
|
| 29 |
i = get_first_subword(token_to_lookup)
|
| 30 |
-
_ , I =
|
| 31 |
hits = lookup_table.take(I[0])
|
| 32 |
results = hits.values[1:]
|
| 33 |
results = [r for r in results if not "[unused" in r]
|
|
|
|
| 12 |
index_L2 = IndexFlatL2(unnormalized_input_embeddings.shape[-1])
|
| 13 |
index_L2.add(unnormalized_input_embeddings)
|
| 14 |
|
| 15 |
+
index_IP = IndexFlatIP(normalized_input_embeddings.shape[-1])
|
| 16 |
+
index_IP.add(normalized_input_embeddings)
|
| 17 |
|
| 18 |
|
| 19 |
vocab = {v:k for k,v in tokenizer.vocab.items()}
|
|
|
|
| 27 |
|
| 28 |
def search(token_to_lookup, num_neighbors):
|
| 29 |
i = get_first_subword(token_to_lookup)
|
| 30 |
+
_ , I = index_IP.search(normalized_input_embeddings[i:i+1], num_neighbors)
|
| 31 |
hits = lookup_table.take(I[0])
|
| 32 |
results = hits.values[1:]
|
| 33 |
results = [r for r in results if not "[unused" in r]
|