将经过训练的 Spacy 2 管道迁移到 Spacy 3

Migrate trained Spacy 2 pipelines to Spacy 3

到目前为止,我一直在使用 spacy 2.3.1,并且已经为我的自定义语言训练并保存了几个管道 class。但是现在使用 spacy 3.0 和 spacy.load('model-path') 我遇到了 config.cfg file not found 和其他类型的错误。

升级 spacy 后是否必须从头开始训练模型?是否有迁移经过训练的模型的分步指南?

恐怕你不能只迁移经过训练的管道。使用 v2 训练的管道与 v3 不兼容,因此您将无法仅在其上使用 spacy.load

您必须将您的代码库迁移到 v3,并重新训练您的模型。您有两个选择:

  • 更新您的训练循环以将 API 调用从 v2 更改为 v3,请参阅此处的更多详细信息:https://spacy.io/usage/v3#migrating
  • (推荐方法):将您的训练代码完全转换为新的 config system in v3. While this may seem like a big difference, you'll get the hang of the config system quite quickly, and you'll notice how much more powerful & convenient it is, as compared to writing everything yourself from scratch. To get started with the config system, have a look at the init config 命令,例如:
python -m spacy init config config.cfg --lang en --pipeline ner,textcat --optimize accuracy

这将为您提供一些合理的默认设置,以及您可以根据需要进一步自定义的配置文件。