python - gensim - fasttext - 为什么`load_facebook_vectors` 不起作用?
问题描述
我尝试从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
对象,然后再使用它。
所以,你应该这样做:
from gensim.models import fasttext
from gensim.test.utils import datapath
wv = fasttext.load_facebook_vectors(datapath("./wiki.en/wiki.en.bin"))
推荐阅读
- asp.net-core - 如何通过更改 ASP.NET Core 中的 Url 来阻止对控制器的访问?
- python - python相当于matlab代码生成数据文件
- python - ModuleNotFoundError:没有名为“hijri_converter”的模块
- javascript - 如何刷新已经初始化的切换复选框?
- node.js - npm安装栏在vscode中有多行
- jquery - Shopify AJAX 请求在 Theme Customizer 中返回 404,但在前端返回 200
- stata - 将 Cox Proportional Hazards 的输出合并到一张表中
- javascript - 为什么我不能调用动作来调度?
- reactjs - 使用地图数据的无线电组未从其自己的组中选择
- javascript - 如何轮流在javascript中推送数组?