这个错误是加载模型失败,以下是官方的解决方法:
Answer: The strings (words) stored in your model are not valid utf8. By default, gensim decodes the words using the strict encoding settings, which results in the above exception whenever an invalid utf8 sequence is encountered.
The fix is on your side and it is to either:
a) Store your model using a program that understands unicode and utf8 (such as gensim). Some C and Java word2vec tools are known to truncate the strings at byte boundaries, which can result in cutting a multi-byte utf8 character in half, making it non-valid utf8, leading to this error.
b) Set the unicode_errors flag when running load_word2vec_model, e.g. load_word2vec_model(…, unicode_errors=‘ignore’). Note that this silences the error, but the utf8 problem is still there – invalid utf8 characters will just be ignored in this case.
给出了两种办法:
- 可以用C和JAVA的相关工具去处文

在使用text2vec模型时遇到UnicodeDecodeError,官方建议通过两种方式修复:1) 使用支持unicode和utf8的工具存储模型;2) 在加载模型时设置unicode_errors='ignore'来忽略错误。此外,提到了腾讯AI提供的轻量版和全量版词向量资源,以及加载轻量版模型时的代码示例。
最低0.47元/天 解锁文章

被折叠的 条评论
为什么被折叠?



