int()的无效文字,以10为底:b'\ x1f \ x8b \ x08 \ x08 \ x80 \ xff \ xa8R \ x02 \ x03GoogleNews-vectors-negative300.bin \

问题描述 投票:0回答:1

我使用Python 3.6和Windows 10

请帮助我解决这个问题我是初学者,请简要说明

错误:

data loaded!
number of sentences: 2467
vocab size: 30417
max sentence length: 2721
loading word2vec vectors...
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-13-2ecf35f5c4fb> in <module>
      8 print ('max sentence length: ' + str(max_l))
      9 print ('loading word2vec vectors...',)
---> 10 w2v = load_bin_vec(w2v_file, vocab)
     11 print ('word2vec loaded!')
     12 print ('num words already in word2vec: ' + str(len(w2v)))

<ipython-input-12-824546589dfe> in load_bin_vec(fname, vocab)
     49     with open(fname, "rb") as f:
     50         header = f.readline()
---> 51         vocab_size, layer1_size = map(int, header.split())
     52         binary_len =  np.dtype('float32').itemsize * layer1_size
     53         for line in range(vocab_size):

ValueError: invalid literal for int() with base 10: b'\x1f\x8b\x08\x08\x80\xff\xa8R\x02\x03GoogleNews-vectors-negative300.bin\x00L\x9d\x07\xbc\xce\xf5\xfb\xff\xad\x902#\xbb\x8cP\x19\x99\xc5\xb9\xefsTF\xd1\x92R\xd1DB\x11E\xa9\xbe'

如何删除此错误?

python-3.6 word2vec
1个回答
0
投票

第49行,您已以'rb'模式读取文件。'rb'模式以二进制格式读取数据。将'rb'替换为'r'

© www.soinside.com 2019 - 2024. All rights reserved.