!16074 textrcnn support newest gensim api on master

From: @chenmai1102
Reviewed-by: @oacjiewen,@wuxuejian
Signed-off-by: @wuxuejian
This commit is contained in:
mindspore-ci-bot 2021-05-18 11:47:55 +08:00 committed by Gitee
commit 74fe67db83
2 changed files with 4 additions and 3 deletions

View File

@ -0,0 +1 @@
gensim==4.0.1

View File

@ -84,13 +84,13 @@ def collect_weight(glove_path, vocab, word_to_idx, embed_size):
idx_to_word = {i + 1: word for i, word in enumerate(vocab)} idx_to_word = {i + 1: word for i, word in enumerate(vocab)}
idx_to_word[0] = '<unk>' idx_to_word[0] = '<unk>'
for i in range(len(wvmodel.index2word)): for i in range(len(wvmodel.index_to_key)):
try: try:
index = word_to_idx[wvmodel.index2word[i]] index = word_to_idx[wvmodel.index_to_key[i]]
except KeyError: except KeyError:
continue continue
weight_np[index, :] = wvmodel.get_vector( weight_np[index, :] = wvmodel.get_vector(
idx_to_word[word_to_idx[wvmodel.index2word[i]]]) idx_to_word[word_to_idx[wvmodel.index_to_key[i]]])
return weight_np return weight_np