1
0
mirror of https://github.com/QData/TextAttack.git synced 2021-10-13 00:05:06 +03:00

add kuleshov recipe; rename attack_methods --> search_methods

This commit is contained in:
Jack Morris
2020-05-06 23:19:13 -04:00
parent dd848c7ac1
commit f140541560
16 changed files with 44 additions and 20 deletions

View File

@@ -48,4 +48,13 @@ class WordEmbedding:
self.cos_sim_mat = {}
def __getitem__(self, index):
""" Gets a word embedding by word or ID.
If word or ID not found, returns None.
"""
if isinstance(index, str):
try:
index = self.word2index[index]
except KeyError:
return None
return self.embeddings[index]