【问题标题】:Add custom language to Spacy 3.0 and train pipelines in it向 Spacy 3.0 添加自定义语言并在其中训练管道
【发布时间】:2021-04-11 13:32:21
【问题描述】:

到目前为止,我一直在使用 Spacy 2.3.1。我创建了自己的自定义类,继承自 Language 类,并在其中使用 Python 脚本训练了一个 NER 管道。

但在 Spacy 3.0 中,引入了一系列方便的 CLI 命令和配置,以训练自定义管道,强烈建议使用这些管道代替 Python 脚本。这是nlp对象的配置示例:

...

[nlp]
lang = "fa"
pipeline = ["transformer","ner"]
batch_size = 32
disabled = []
before_creation = null
after_creation = null
after_pipeline_creation = null
tokenizer = {"@tokenizers":"spacy.Tokenizer.v1"}

...

如您所见,lang 属性应该是 Spacy 库中预定义的语言之一。 有什么方法可以在配置中指出我需要创建一个我自己的自定义语言的对象作为nlp 对象?

【问题讨论】:

    标签: python spacy spacy-3


    【解决方案1】:

    文档中实际上有a section on this。基本思想是您必须将您的语言添加到注册表中。文档中的示例:

    import spacy
    from spacy.lang.en import English
    
    class CustomEnglishDefaults(English.Defaults):
        stop_words = set(["custom", "stop"])
    
    @spacy.registry.languages("custom_en")
    class CustomEnglish(English):
        lang = "custom_en"
        Defaults = CustomEnglishDefaults
    
    # This now works! ?
    nlp = spacy.blank("custom_en")
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-04-21
      • 2022-12-09
      • 2021-11-09
      • 1970-01-01
      • 2018-12-26
      • 2020-10-16
      • 1970-01-01
      相关资源
      最近更新 更多