我正在尝试使此代码运行数小时,但可以解决此问题。 有谁知道我该如何修复ist?它将引发NameError:名称'embedding_weights'尚未定义,但我已经定义了它。
非常感谢!
def get_glove(path_to_glove, word2index_map):
embedding_weights = {}
count_all_words = 0
with zipfile.ZipFile(path_to_glove) as z:
with open("glove.6B.300d.zip") as f:
for line in f:
vals = line.split()
word = str(vals[0].decode("utf-8"))
if word in word2index_map:
print(word)
count_all_words+=1
coefs = np_asarray(vals[:1],dtype='float32')
coefs/=np.linalg.norm(coefs)
embedding_weights[word] = coefs
if count_all_words==vocabulary_size-1:
break
return embedding_weights
word2embedding_dict = get_glove(path_to_glove,word2index_map)