【问题标题】:Converting NER training data to Spacy training data format将 NER 训练数据转换为 Spacy 训练数据格式
【发布时间】:2021-07-30 04:55:13
【问题描述】:

我正在使用 Spacy 创建印度尼西亚 NER 模型。我正在使用来自https://raw.githubusercontent.com/yohanesgultom/nlp-experiments/master/data/ner/training_data.txt的训练数据

上面使用这种Tag格式的训练数据:

Sementara itu Pengamat Pasar Modal <ENAMEX TYPE="PERSON">Dandossi Matram</ENAMEX> mengatakan,

我想将此训练数据转换为 Spacy 格式,即:

[('Sementara itu Pengamat Pasar Modal Dandossi Matram mengatakan,',{"entities:"([35, 51, 'PERSON'])})]

我还是 Python 库的新手,知道如何转换火车数据吗?或者知道使用哪个库?

谢谢。

【问题讨论】:

    标签: python nlp training-data named-entity-recognition spacy-3


    【解决方案1】:

    对于简单的 XML 类型注释,您可以使用 BeautifulSoup。这是一个稍微简单的标记示例:

    from bs4 import BeautifulSoup
    
    raw = "I went to <PLACE>Tokyo 3</PLACE> last year."
    soup = BeautifulSoup(raw, features="html.parser")
    
    out = ""
    tags = []
    idx = 0
    for el in soup:
        text = el
        if hasattr(el, "text"):
            # it's a tag, save it
            text = el.text
            start = idx
            end = idx + len(el.text)
            tags.append( (el.name, start, end) )
    
        out += text
        idx += len(text)
    
    print(out)
    for tag in tags:
        print(tag[0], out[tag[1]:tag[2]], sep="\t")
    

    一旦你有了这个示例代码给出的字符跨度,获取 spaCy 格式数据就很简单了。

    【讨论】:

      猜你喜欢
      • 2018-05-06
      • 1970-01-01
      • 1970-01-01
      • 2021-04-08
      • 2020-10-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多