Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

如何加载模型 #162

Open
YiingWei opened this issue Apr 28, 2023 · 5 comments
Open

如何加载模型 #162

YiingWei opened this issue Apr 28, 2023 · 5 comments

Comments

@YiingWei
Copy link

作者你好,当我用下面的代码尝试加载您的中文词向量模型

加载中英文词向量模型

ch_model = KeyedVectors.load_word2vec_format('./ch_model/merge_sgns_bigram_char300.txt', binary=True)
结果显示下面报错,应该如何解决呢
Traceback (most recent call last):
File "c:/Users/11323/Desktop/score_comment/socore_comments.py", line 127, in
ch_model = KeyedVectors.load_word2vec_format('./ch_model/merge_sgns_bigram_char300.txt', binary=True)
File "C:\ProgramData\Anaconda3\envs\pytorch\lib\site-packages\gensim\models\keyedvectors.py", line 1719, in
load_word2vec_format
return _load_word2vec_format(
File "C:\ProgramData\Anaconda3\envs\pytorch\lib\site-packages\gensim\models\keyedvectors.py", line 2065, in
_load_word2vec_format
_word2vec_read_binary(
File "C:\ProgramData\Anaconda3\envs\pytorch\lib\site-packages\gensim\models\keyedvectors.py", line 1960, in
_word2vec_read_binary
processed_words, chunk = _add_bytes_to_kv(
File "C:\ProgramData\Anaconda3\envs\pytorch\lib\site-packages\gensim\models\keyedvectors.py", line 1939, in
_add_bytes_to_kv
word = chunk[start:i_space].decode(encoding, errors=unicode_errors)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xaf in position 0: invalid start byte

@HunterHeidy
Copy link

HunterHeidy commented Apr 28, 2023 via email

@XXXXiGua
Copy link

XXXXiGua commented Jun 1, 2023

应该binary=False,因为模型是txt格式十进制的,如果是bin采用True

@ahutxwq1
Copy link

作者你好,当我用下面的代码尝试加载您的中文词向量模型

加载中英文词向量模型

ch_model = KeyedVectors.load_word2vec_format('./ch_model/merge_sgns_bigram_char300.txt', binary=True) 结果显示下面报错,应该如何解决呢 Traceback (most recent call last): File "c:/Users/11323/Desktop/score_comment/socore_comments.py", line 127, in ch_model = KeyedVectors.load_word2vec_format('./ch_model/merge_sgns_bigram_char300.txt', binary=True) File "C:\ProgramData\Anaconda3\envs\pytorch\lib\site-packages\gensim\models\keyedvectors.py", line 1719, in load_word2vec_format return _load_word2vec_format( File "C:\ProgramData\Anaconda3\envs\pytorch\lib\site-packages\gensim\models\keyedvectors.py", line 2065, in _load_word2vec_format _word2vec_read_binary( File "C:\ProgramData\Anaconda3\envs\pytorch\lib\site-packages\gensim\models\keyedvectors.py", line 1960, in _word2vec_read_binary processed_words, chunk = _add_bytes_to_kv( File "C:\ProgramData\Anaconda3\envs\pytorch\lib\site-packages\gensim\models\keyedvectors.py", line 1939, in _add_bytes_to_kv word = chunk[start:i_space].decode(encoding, errors=unicode_errors) UnicodeDecodeError: 'utf-8' codec can't decode byte 0xaf in position 0: invalid start byte

merge_sgns_bigram_char300.txt这个文件怎么生成的?可以直接下载吗?

@GGbond2004
Copy link

你好请问解决了吗。在代码里应该怎么修改?

@HunterHeidy
Copy link

HunterHeidy commented Jul 3, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants