NER:偏移json格式与Conll格式的转换

1.json转conll格式

 https://github.com/explosion/spaCy/issues/1966

from spacy.gold import biluo_tags_from_offsets

doc = nlp(u'I like London.')
entities = [(7, 13, 'LOC')]
tags = biluo_tags_from_offsets(doc, entities)
assert tags == ['O', 'O', 'U-LOC', 'O']

 

比较简便的方法是根据这个函数来转换,但是不是转换为BIO,而是BILUO格式,如下:

 

U表示单个实体,L表示长度>=2的实体的末尾。

如果想再转换为BIO,可以写一个脚本,应该还是比较简单的。 

2.conll转换为json

https://stackoverflow.com/questions/58299682/how-to-import-text-from-connl-format-with-named-entities-into-spacy-infer-entit

 

posted @ 2020-09-14 11:04  lypbendlf  阅读(998)  评论(0编辑  收藏  举报