继续训练FastText模型

10

我已经下载了一个 .bin 的FastText模型,并且按照以下方式使用gensim

model = FastText.load_fasttext_format("cc.fr.300.bin")

我希望进一步训练模型以使其适应于我的领域。查看了FastText的GithubGensim文档后,发现目前似乎不可能实现,除非使用这位作者提出的修改版(尚未合并)。

是否有遗漏之处?

3个回答

5

你可以在某些版本的Gensim的fastText中继续训练(例如,v.3.7.*)。以下是"加载、推断、继续训练"的示例。

from gensim.test.utils import datapath
model = load_facebook_model(datapath("crime-and-punishment.bin"))
sent = [['lord', 'of', 'the', 'rings'], ['lord', 'of', 'the', 'semi-groups']]
model.build_vocab(sent, update=True)
model.train(sentences=sent, total_examples = len(sent), epochs=5)

由于某些原因,在Windows上缺少gensim.models.fasttext.load_facebook_model(),但在Mac的安装中存在。或者可以使用gensim.models.FastText.load_fasttext_format()加载预先训练好的模型并继续培训。

这里有各种预训练的Wiki词语模型和向量(或在这里)。

另一个例子。"注意:与Word2Vec的情况一样,您可以在使用Gensim的fastText本地实现时继续训练您的模型。"


在2021年,使用gensim==3.6.0时,model.build_vocab()会抛出AttributeError: 'FastTextTrainables' object has no attribute 'syn1neg'的错误。 - duhaime

0

拉取请求 #1327 (https://github.com/facebookresearch/fastText/pull/1327)

新增功能:

  1. 每轮训练后进行测试
  2. 支持检查点保存
  3. 支持在内存容量不足的情况下训练大型数据集(我测试过最大可以达到1.6TB)
  4. 对已经训练好的模型进行微调

训练出来的模型与原始工具创建的模型无异,并且可以通过旧代码进行推理。


-1

官方的 FastText 实现目前不支持该功能,虽然有一个相关的开放票据,你可以在这里找到。


谢谢,那就是我在问题中提到的那个。 - ted

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接