当前位置:   article > 正文

用标注平台doccano进行NER标注_doccano标注后的数据怎么转换ner

doccano标注后的数据怎么转换ner

目录

登录

创建任务

导入数据集

添加标签

标注

导出结果

转换为bio


安装方法参考;doccano安装使用教程

进入doccano之后

登录

右上角登陆,右上角可以切换中文

创建任务

点左上角创建

选序列标注

导入数据集

数据集

导入

(文本每行是一句话,我随便找个水浒传的章节名写在上面为例)

导入成功如下所示 

添加标签

标签

标注

左上角开始标注

导出结果

标注完后导出

解压,admin.jsonl

转换为bio

  1. def json2bio(fpath, output):
  2. with open(fpath, encoding='utf-8') as f:
  3. lines = f.readlines()
  4. for line in lines: # '{"id":1,"text":"张天师祈禳瘟疫 洪太尉误走妖魔","label":[[0,3,"人物"],[3,5,"动作"],[8,11,"人物"],[11,13,"动作"]]}'
  5. annotations = json.loads(line) # {"id":1,"text":"张天师祈禳瘟疫 洪太尉误走妖魔","label":[[0,3,"人物"],[3,5,"动作"],[8,11,"人物"],[11,13,"动作"]]}
  6. text = annotations['text'].replace('\n', ' ') # '张天师祈禳瘟疫 洪太尉误走妖魔'
  7. all_words = list(
  8. text.replace(' ', ',')) # ['张', '天', '师', '祈', '禳', '瘟', '疫', ',', '洪', '太', '尉', '误', '走', '妖', '魔']
  9. all_label = ['O'] * len(all_words)
  10. for i in annotations['label']: # [0, 3, '人物']
  11. b_location = i[0] # 0
  12. e_location = i[1] # 3
  13. label = i[2] # '人物'
  14. all_label[b_location] = 'B-' + label
  15. if b_location != e_location:
  16. for word in range(b_location + 1, e_location):
  17. all_label[word] = 'I-' + label
  18. cur_line = 0
  19. # 写入文件
  20. toekn_label = zip(all_words, all_label)
  21. with open(output, 'a', encoding='utf-8') as f:
  22. for tl in toekn_label:
  23. f.write(tl[0] + str(' ') + tl[1])
  24. f.write('\n')
  25. cur_line += 1
  26. if cur_line == len(all_words):
  27. f.write('\n') # 空格间隔不同句子
'
运行

转换为可以训练的bio格式的训练集

 接下来就可以用这个数据集训练了

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/黑客灵魂/article/detail/961242
推荐阅读
相关标签
  

闽ICP备14008679号