繁体   English   中英

gensim - fasttext - 为什么`load_facebook_vectors` 不起作用?

[英]gensim - fasttext - Why `load_facebook_vectors` doesn't work?

我尝试从fastext-wiki word vectors加载预训练的 FastText 向量。

我的代码在下面,它运行良好。

from gensim.models import FastText
model = FastText.load_fasttext_format('./wiki.en/wiki.en.bin')

但是,警告信息有点烦人。

gensim_fasttext_pretrained_vector.py:13: DeprecationWarning: Call to deprecated `load_fasttext_format` (use load_facebook_vectors (to use pretrained embeddings)

消息说, load_fasttext_format将被弃用,所以最好使用load_facebook_vectors

所以我决定更改代码。 我更改的代码如下所示。

from gensim.models import FastText
model = FastText.load_facebook_vectors('./wiki.en/wiki.en.bin')

但是,错误发生了,错误信息是这样的。

Traceback (most recent call last):
  File "gensim_fasttext_pretrained_vector.py", line 13, in <module>
    model = FastText.load_facebook_vectors('./wiki.en/wiki.en.bin')
AttributeError: type object 'FastText' has no attribute 'load_facebook_vectors'

我不明白为什么会发生这些事情。 我只是改变消息所说的内容,但它不起作用。 如果您对此有所了解,请告诉我。

总是,谢谢你们的帮助。

你快到了,你需要改变两件事:

  • 首先,它是fasttext所有小写字母,而不是Fasttext
  • 其次,要使用load_facebook_vectors ,您需要先创建一个datapath object 才能使用它。

所以,你应该这样做:

from gensim.models import fasttext
from gensim.test.utils import datapath

wv = fasttext.load_facebook_vectors(datapath("./wiki.en/wiki.en.bin"))

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM