无论如何,我是否可以将在eBrevia中训练的模型加载到CoreNLP或Spacy中?

问题描述 投票:0回答:1

我有来自eBrevia的经过训练的名称实体识别(NER)模型。我想知道是否有一种方法可以使用Python或Java将其加载到CoreNLP或Spacy中。

编辑:如果预训练的模型是泡菜模型,是否可以使用Corenlp或Spacy加载它?

谢谢!

nlp stanford-nlp spacy ner pycorenlp
1个回答
0
投票

使用spaCy(Python),您应该能够编写一个自定义组件,并在其中编写一个围绕当前NER模型的包装器。自定义组件始终将doc作为输入,对其进行修改并返回。这允许链接定制组件和“预制”组件。

例如,如果您的NER模型将令牌列表作为输入,并返回其令牌的列表BILUO tags,则可以这样包装该模型:

from spacy.gold import offsets_from_biluo_tags

def custom_ner_wrapper(doc):
    words = [token.text for token in doc]
    custom_entities = your_custom_ner_model(words)    
    doc.ents = spans_from_biluo_tags(doc, custom_entities)    
    return doc

一旦定义了名为custom_ner_wrapper的自定义管道组件,就必须像这样将其添加到nlp管道中:

nlp.add_pipe(custom_ner_wrapper)

可在此处找到更多信息:https://spacy.io/usage/processing-pipelines#wrapping-models-libraries

© www.soinside.com 2019 - 2024. All rights reserved.