如何使用 gensim 加载中文 fasttext 模型?

How can I load chinese fasttext model with gensim?

在尝试使用 gensim 加载中文 fasttext 模型(cc.zh.300.bin)时,我遇到了以下错误

UnicodeDecodeError:'utf-8' codec can't decode byte 0xba in position 0: invalid start byte

有人可以帮帮我吗?详细错误如下:

KeyedVectors.load_word2vec_format() 方法仅加载 Google 原始 word2vec.c 代码使用的纯单词和向量格式的文件。预计它不会处理 FastText 格式的文件。

您应该尝试使用专用于 FastText 格式文件的方法 load_facebook_vectors()

https://radimrehurek.com/gensim/models/fasttext.html#gensim.models.fasttext.load_facebook_vectors

对于某些用途,备用 load_facebook_model() 也可能是合适的:

https://radimrehurek.com/gensim/models/fasttext.html#gensim.models.fasttext.load_facebook_model