0

在此处输入图像描述我正在尝试使用 Glove 对单词向量进行编码,但出现上述错误。数据由两个文本列组成,用于确定句子相似度。你能帮我解决这个错误吗?

[代码]

embeddings_index = {}
f = open(r'C:\Users\15084\Downloads\glove.840B.300d\glove.840B.300d.txt',errors = 
'ignore',encoding='utf-8')
for line in f:
    values = line.split()
    word = values[0]
    coefs = np.asarray(values[1:], dtype='float32')
    embeddings_index[word] = coefs
f.close()

print('Found %s word vectors.' % len(embeddings_index))
4

2 回答 2

0

使用此代码加载您的嵌入索引

  import pickle
  with open('glove_vectors', 'rb') as f:
     model = pickle.load(f)
     glove_words =  set(model.keys())

在这里你嵌入索引模型本身

于 2021-12-31T19:35:34.813 回答
-1

我想这会对你有所帮助

f = open(r'C:\Users\15084\Downloads\glove.840B.300d\glove.840B.300d.txt',errors ='ignore',encoding='utf-8','r')
于 2020-05-10T21:55:56.587 回答