gpt4 book ai didi

python - 值错误 : array is too big when loading GoogleNews-vectors-negative

转载 作者:太空狗 更新时间:2023-10-30 02:08:30 25 4
gpt4 key购买 nike

我正在尝试使用以下代码从 Google 加载预训练词向量:

from gensim import models
w = models.KeyedVectors.load_word2vec_format('GoogleNews-vectors-negative300.bin.gz', binary=True)

但是我收到一个错误提示

File "C:\ProgramData\Anaconda3\lib\site-packages\gensim\models\keyedvectors.py", line 197, in load_word2vec_format result.syn0 = zeros((vocab_size, vector_size), dtype=datatype)

ValueError: array is too big; arr.size * arr.dtype.itemsize is larger than the maximum possible size.

谁能提出一个可能的解决方案。提前致谢。

最佳答案

这很可能是因为您安装的 Python 使用 32 位寻址,因此无法分配加载 GoogleNews 向量所需大小的数组。一些选项:

  • 切换到 64 位 Python。请注意,完整的矢量集需要 3GB 以上的内存才能加载,因此除非您的 RAM 超过 4GB,否则无论如何都很难处理完整的矢量集。
  • 使用 gensim 的 load_word2vec_format() 方法的可选 limit 参数只读取文件中的一些早期条目。该文件似乎是按照从最频繁到最不频繁的标记顺序排列的,因此您通常只需要早期的条目。例如,您可以尝试 limit=500000 只读取前 500,000 个条目(而不是全部 300 万个)

关于python - 值错误 : array is too big when loading GoogleNews-vectors-negative,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42727181/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com