python-3.6 - 基数为 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'
我怎样才能消除这个错误?
解决方案
在第 49 行,您已在'rb'
模式下读取文件。
'rb'
模式以二进制格式读取数据。
替换'rb'
为'r'
推荐阅读
- github - Github 操作如何仅进行 1 次 npm 安装
- javascript - 仅显示简单的工具提示,没有任何样式
- javascript - 如何从浏览器控制台调用函数 webpackJsonp
- c++ - C++ 模板函数调用似乎更喜欢不那么专业的调用
- reactjs - 打字机效果 Next.js
- xamarin - 如何在 UWP 本机 C# 应用程序中重用 Xamarin.forms resx 文件
- json - 使用 Bash 命令转换 JSON 字符串中的时间戳
- c++ - 使用引用作为返回值,有什么不同吗?
- python - python子进程通信-在发送stdin之前检索stdout/stderr
- discord - 检查不和谐机器人分片(连接)状态