当前位置:网站首页>AI中台序列标注任务:三个数据集构造过程记录
AI中台序列标注任务:三个数据集构造过程记录
2022-08-03 07:30:00 【木尧大兄弟】
数据介绍
人民日报命名实体识别数据集(example.train 28046条数据和example.test 4636条数据),共3种标签:地点(LOC), 人名(PER), 组织机构(ORG)
时间识别数据集(time.train 1700条数据和time.test 300条数据),共1种标签:TIME
CLUENER细粒度实体识别数据集(cluener.train 10748条数据和cluener.test 1343条数据),共10种标签:地址(address),书名(book),公司(company),游戏(game),政府(goverment),电影(movie),姓名(name),组织机构(organization),职位(position),景点(scene)
数据来源:GitHub
格式说明
原始格式:如图,每个字和label占一行,每句用空行隔开;
目标格式:每句一行,前面是用空格分开的字符 \t 后面是用空格分开的label,并生成一个label_map.json文件,如图(参考EasyDL)。
代码实现
数据转换函数代码:
import os
def dataFucker(filepath):
new_filepath = filepath+'_new.txt'
f_new = open(new_filepath, 'w+', encoding="utf-8")
with open(filepath, 'r', encoding="utf-8") as f:
lines = f.read().split('\n\n')
for line in lines:
if not line:
continue
tokens_words = line.split('\n')
tokens, labels = [_.split(' ')[0].strip() for _ in tokens_words if _], [_.split(' ')[1].strip() for _ in tokens_words if _]
assert len(tokens) == len(labels)
new_line = ' '.join(tokens) + '\t' + ' '.join(labels) + '\n'
f_new.write(new_line)
f_new.close()
return new_filepath
数据转换入口函数:
import os
path = r"C:\xxx\data"
datasets = os.listdir(path)
for dataset in datasets:
filepath = os.path.join(path, dataset)
new_filepath = dataFucker(filepath)
print(filepath.split("\\")[-1], '---->', new_filepath.split("\\")[-1])
执行结果:
生成映射json文件代码:
import os
import json
def mapJsonFucker(filepath):
with open(filepath, 'r', encoding="utf-8") as f:
lines = f.readlines()
labels = []
for line in lines:
_labels = line.split('\t')[1].split(' ')
for each in _labels:
if each.strip() not in labels:
labels.append(each.strip())
labels.remove('O')
labels.append('O')
res = json.dumps({
key:value for value, key in enumerate(labels)}, indent=2)
with open(filepath+'_label_map.json', 'w+', encoding='utf-8') as fd:
fd.write(res)
return res
生成映射json文件入口函数:
path = r"C:\xxx\data"
datasets = [_ for _ in os.listdir(path) if 'txt' in _ and 'train' in _]
print(dataset)
for dataset in datasets:
filepath = os.path.join(path, dataset)
print(filepath)
resList = mapJsonFucker(filepath)
print(resList)
执行结果:
后续就可以根据自己需求处理了。
边栏推荐
- 2022下半年软考「高项&集成」复习计划ta来喽~
- postman将接口返回结果生成csv文件到本地
- mysql备份时的快照原理
- JS函数获取本月的第一天和最后一天
- 调用feign报错openfeign/feign-core/10.4.0/feign-core-10.4.0.jar
- 【图像去雾】基于matlab暗通道和非均值滤波图像去雾【含Matlab源码 2011期】
- - display image API OpenCV 】 【 imshow () to a depth (data type) at different image processing methods
- pt-online-schema-change工具使用的一次
- Haisi project summary
- 华为设备配置BFD与接口联动(触发与BFD联动的接口物理状态变为Down)
猜你喜欢
The use of the database table structure document generation tool screw
Postman will return to results generated CSV file to the local interface
22-08-02 西安 尚医通(02)Vscode、ES6、nodejs、npm、Bable转码器
测试用例设计方法之因果图详解
rust 学习笔记
加载properties文件,容器总结
智能客服,还有多少AI泡沫?
【OpenCV】 - 显示图像API之imshow()对不同位深度(数据类型)的图像的处理方法
Postman will return to the interface to generate a json file to the local
【着色器实现HandDrawn简笔画抖动效果_Shader效果第十二篇】
随机推荐
千万级别的表分页查询非常慢,怎么办?
伦敦银现货市场如何使用多条均线?
数仓埋点体系与归因实践
ViewModel 记录下 +
STL - string
Roson的Qt之旅#105 QML Image引用大尺寸图片
Qt5开发从入门到精通——第二篇(控件篇)
pyspark---low frequency feature processing
Windows安装MySQL(MIS)
SSM整合流程
被数据分析重塑的5个行业
加载properties文件,容器总结
用云机器/虚拟机架设方舟游戏?
ArcEngine(五)用ICommand接口实现放大缩小
如何让背景色在任何设备宽高都能填充整个屏幕
Detailed explanation of cause and effect diagram of test case design method
ArcEngine(八)用IWorkspaceFactory加载矢量数据
DSP Trick:向量长度估算
Karatsuba大数乘法的Verilog实现
Golang协程goroutine的调度与状态变迁分析