首页 > 解决方案 > 基数为 10 的 int() 的无效文字: b'\x1f\x8b\x08\x08\x80\xff\xa8R\x02\x03GoogleNews-vectors-negative300.bin\

问题描述

我使用 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.6word2vec

解决方案


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


推荐阅读