我在Gensim中训练了一个FastText模型。我想用它来编码我的句子。具体地说,我想在原生FastText中使用这个特性:
./fasttext print-word-vectors model.bin < queries.txt如何将模型保存在Gensim中,以便它是本机FastText可以理解的正确的二进制格式?
我使用的是Python3.4.3下的FastText 0.1.0和Gensim 3.4.0。
本质上,我需要Gensim FastText doc中给出的load_binary_data()的逆函数。
发布于 2018-05-05 23:43:05
您可能在gensim中找不到这样的功能,因为这意味着依赖于内部结构和代码,就像您在fasttext-python中看到的那样(它使用pybind直接调用内部fasttext api)。对外部库有如此巨大的依赖是gensim的创建者想要避免的事情,这就是为什么他们可能会deprecated the functionality to call the fasttext wrapper。RIght现在只寻求通过它自己的内部实现提供快速文本算法。我建议你使用python bindings for fasttext。
$ git clone https://github.com/facebookresearch/fastText.git
$ cd fastText
$ pip install .现在,在python应用程序中使用fasttext模型运行训练集。
from fastText import train_unsupervised
model = train_unsupervised(input="pathtotextfile", model='skipgram')
model.save_model('model.bin')这将以fastText命令行格式保存模型。因此,您现在应该能够运行以下命令。
$ ./fasttext print-word-vectors model.bin < queries.txthttps://stackoverflow.com/questions/50161445
复制相似问题