命名实体识别数据预处理--格式转换

命名实体识别数据预处理--格式转换成BIEO格式

常见的预料库

链接: 微软数据.
链接: 人民日报.
链接: 微博语料数据.

数据预处理代码

下面展示一些 将我不是<per>江莱</per>转换成‘BIOE标准格式’。

import codecs  
import sys  
  
def character_tagging(input_file, output_file):  
    input_data = codecs.open(input_file, 'r', 'utf-8')  
    output_data = codecs.open(output_file, 'w', 'utf-8')  
    for line in input_data.readlines():  
        word_list = line.strip().lower().replace('<per>',' <').replace('</per>',' ').split()  
        for word in word_list:  
            if len(word) == 1:  
                output_data.write(word + "\tO\n")
            else:  
                if word[0]!= '<':
                    for w in word[0:len(word)]:
                        output_data.write(w + "\tO\n")
                else:
                    output_data.write(word[1] + "\tB-PER\n")  
                    for w in word[2:len(word)-1]:  
                        output_data.write(w + "\tI-PER\n")  
                    output_data.write(word[len(word)-1] + "\tE-PER\n")  
        output_data.write("\n")  
    input_data.close()  
    output_data.close()  

if __name__ == "__main__":
    input_file = 'name_only.txt'
    output_file = 'name_only_bieo.txt'
    character_tagging(input_file,output_file)

最终转换结果:
在这里插入图片描述

  • 2
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值