簡體   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