【问题标题】:How to load pre-trained fastText model in gensim with .npy extension如何使用 .npy 扩展名在 gensim 中加载预训练的 fastText 模型
【发布时间】:2020-12-17 14:12:37
【问题描述】:

我是深度学习的新手,我正在尝试使用来自 paper 的预训练词嵌入模型。我下载了以下文件:

1)sa-d300-m2-fasttext.model

2)sa-d300-m2-fasttext.model.trainables.syn1neg.npy

3)sa-d300-m2-fasttext.model.trainables.vectors_ngrams_lockf.npy

4)sa-d300-m2-fasttext.model.wv.vectors.npy

5)sa-d300-m2-fasttext.model.wv.vectors_ngrams.npy

6)sa-d300-m2-fasttext.model.wv.vectors_vocab.npy

如果需要这些详细信息 sa - 梵文 d300 - 嵌入尺寸 快速文本 - 快速文本

我之前没有使用过 gensim 的经验,如何将模型加载到 gensim 或 tensorflow 中。

我试过了

from gensim.models.wrappers import FastText
FastText.load_fasttext_format('/content/sa/300/fasttext/sa-d300-m2-fasttext.model.wv.vectors_ngrams.npy')

FileNotFoundError: [Errno 2] 没有这样的文件或目录:'/content/sa/300/fasttext/sa-d300-m2-fasttext.model.wv.vectors_ngrams.npy.bin'

【问题讨论】:

    标签: gensim pre-trained-model fasttext


    【解决方案1】:

    这组多个文件看起来像是使用 Gensim 的 save() 方法从 Gensim 的 FastText 实现中保存的 - 因此在 Facebook 的原始“fasttext_format”中不是

    因此,请尝试使用以下内容加载它们:

    from gensim.models.fasttext import FastText
    model = FastText.load('/content/sa/300/fasttext/sa-d300-m2-fasttext.model')
    

    (在加载那个主/根文件时,它会在同一个目录中找到附属的相关文件,只要它们都存在。)

    您下载这些文件的来源应该包含在附近加载它们的明确说明!

    【讨论】:

    • 我尝试了你的建议,但我得到了这个错误 'AttributeError: Can't get attribute 'FastTextKeyedVectors' on '
    • 现在我能够纠正错误我将导入语句从 from gensim.models.wrappers import FastText 更改为 from gensim.models.fasttext import FastText 但我在 colab 中尝试这个,当我加载模型时,使用了 8 GB 的 gpu ,这正常吗
    • 是的,你会想使用 Gensim 的 Python FastText,而不是它的(不推荐使用的)外部可执行文件的包装器。 (我已经更新了答案以明确使用正确的导入,谢谢。)所需的内存量将取决于模型,但当前(通过gensim-3.8.3)实现也存在一些导致它的错误过度使用 RAM 2 倍或更多。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-17
    • 1970-01-01
    • 2020-06-26
    • 1970-01-01
    • 2018-10-14
    • 2021-03-31
    相关资源
    最近更新 更多