【发布时间】:2021-09-22 18:01:01
【问题描述】:
我运行此代码并遇到以下错误: 我怎样才能摆脱错误并继续下一个单词?
GLOVE_DATASET_PATH = 'glove.840B.300d.txt'
from tqdm import tqdm
import string
embeddings_index = {}
f = open(GLOVE_DATASET_PATH, encoding="utf8")
word_counter = 0
for line in tqdm(f):
values = line.split()
word = values[0]
if word in dictionary:
coefs = np.asarray(values[1:], dtype='float32')
embeddings_index[word] = coefs
word_counter += 1
f.close()
print('Found %s word vectors matching enron data set.' % len(embeddings_index))
print('Total words in GloVe data set: %s' % word_counter)
错误信息是 ValueError: could not convert string to float: '.'在线 ---> 12 coefs = np.asarray(values[1:], dtype='float32')
【问题讨论】:
-
打印
line,内容可能不是你所期望的。
标签: python