0

我正在尝试读取 GloVe 文件:glove.twitter.27B.200d.txt. 我有下一个函数来读取文件:

def glove_reader(glove_file):
    glove_dict = {}
    with open(glove_file, 'rt', encoding='utf-8') as glove_reader:
        for line in glove_reader:
            tokens = line.rstrip().split()
            vect = [float(token) for token in tokens[1:]]
            glove_dict[tokens[0]] = vect
    return glove_dict

问题是我得到下一个错误:

UnicodeDecodeError: 'utf-8' codec can't decode byte 0xea in position 0: invalid continuation byte

我试过了,latin-1但没有用。向我抛出下一个错误: ValueError: could not convert string to float: 'Ù\x86'

我也试过'rt''r'and改变'rb'。我认为是 macOS 的问题,因为在 Windows 中没有给我这个错误。有人可以帮我知道为什么我无法阅读此文件。

4

0 回答 0