【问题标题】:Q: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe3 in position 0: unexpected end of dataQ: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe3 in position 0: unexpected end of data
【发布时间】:2021-11-21 21:49:56
【问题描述】:

我正在使用FastText.load_fasttext_format()在 Google Colab 中加载 fastText 官方日语训练模型(300 暗淡)。 这是我的代码。

model_path = "/content/drive/MyDrive/IDR/rakuten/wikipedia_fastText/cc.ja.300.bin"
model = FastText.load_fasttext_format(model_path)

这是编码错误。

---------------------------------------------------------------------------

UnicodeDecodeError                        Traceback (most recent call last)

<ipython-input-7-61d7c85f09b2> in <module>()
      2 
      3 model_path = "/content/drive/MyDrive/IDR/rakuten/wikipedia_fastText/cc.ja.300.bin"
----> 4 model = FastText.load_fasttext_format(model_path)

2 frames

/usr/local/lib/python3.7/dist-packages/gensim/models/fasttext.py in _load_dict(self, file_handle, encoding)
    818                 word_bytes += char_byte
    819                 char_byte = file_handle.read(1)
--> 820             word = word_bytes.decode(encoding)
    821             count, _ = self.struct_unpack(file_handle, '@qb')
    822 

UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe3 in position 0: unexpected end of data

【问题讨论】:

    标签: python unicode encoding utf-8 fasttext


    【解决方案1】:

    具体的错误好像是unexpected end of data

    您确定您下载的cc.ja.300.bin 文件是完整的未截断长度和未损坏的内容,以匹配任何声明的校验和,来自下载它的源?

    另外,load_fasttext_format() 类方法是 deprecated in current versions of Gensimload_facebook_model() 现在是首选形式(尽管这不会说明您的错误)。

    【讨论】:

      猜你喜欢
      • 2022-01-13
      • 2022-09-26
      • 2020-12-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-24
      相关资源
      最近更新 更多