【问题标题】:Converting Spacy NER entity format to CONLL 2003 format将 Spacy NER 实体格式转换为 CONLL 2003 格式
【发布时间】:2022-01-02 05:49:24
【问题描述】:

我正在开发 NER 应用程序,我的数据以以下数据格式注释。

[('The F15 aircraft uses a lot of fuel', {'entities': [(4, 7, 'aircraft')]}),
 ('did you see the F16 landing?', {'entities': [(16, 19, 'aircraft')]}),
 ('how many missiles can a F35 carry', {'entities': [(24, 27, 'aircraft')]}),
 ('is the F15 outdated', {'entities': [(7, 10, 'aircraft')]}),
 ('how long does it take to train a F16 pilot',{'entities': [(33, 36, 'aircraft')]}),
 ('how much does a F35 cost', {'entities': [(16, 19, 'aircraft')]})]

有没有办法将其转换为 CONLL 2003 格式?

【问题讨论】:

    标签: python spacy johnsnowlabs-spark-nlp conll


    【解决方案1】:

    你指的是哪种 CoNLL 格式?

    您可以通过执行以下操作获得简单的 CoNLL 格式:

    import spacy
    
    data = ... your data ...
    
    nlp = spacy.blank("en")
    
    for text, labels in data:
        doc = nlp(text)
        ents = []
        for start, end, label in labels["entities"]:
            ents.append(doc.char_span(start, end, label))
        doc.ents = ents
        for tok in doc:
            label = tok.ent_iob_
            if tok.ent_iob_ != "O":
                label += '-' + tok.ent_type_
            print(tok, label, sep="\t")
    

    还有一个库,spacy_conll,可以为您完成这项工作。

    【讨论】:

    • 我正在尝试获取 CoNLL 2003 格式。
    猜你喜欢
    • 1970-01-01
    • 2021-10-02
    • 1970-01-01
    • 1970-01-01
    • 2021-03-13
    • 2022-11-02
    • 1970-01-01
    • 1970-01-01
    • 2021-07-30
    相关资源
    最近更新 更多