哪些网站可以做招生信息,网站描述关键词,目前主流网站开发所用软件,东方财富网官方网站首页背景
使用大语言模型做实体识别的实验时#xff0c;发现大模型关于实体的边界预测一直不准。 主要原因在于当时找了很多同学标注数据#xff0c;由于不同组同学关于实体的边界没有统一#xff0c;故导致数据集中实体边界也没统一。 #xff08;找太多人标#xff0c;会有…背景
使用大语言模型做实体识别的实验时发现大模型关于实体的边界预测一直不准。 主要原因在于当时找了很多同学标注数据由于不同组同学关于实体的边界没有统一故导致数据集中实体边界也没统一。 找太多人标会有这样的缺点
如果重新标注数据那么之前的标的数据就浪费了而且又得折腾人来标。 虽然之前标的数据不好但训练出的大模型还是学到了一些东西。于是便打算让训练后的大模型预测将大模型预测的结果导入到Doccano再人工修正大模型预测不准的实体这样可以减轻人工标注压力还能轻易获得更多的数据集。
简介
展示大模型预测输出的数据格式展示Doccano 命名实体识别导入的数据集格式提供将大模型输出数据转为Doccano 导入数据集格式代码
大模型预测结果的样例如下
{instruction: 你是专门进行实体抽取的专家。请从text中抽取出符合schema定义的实体不存在的实体类型返回空列表。请按照JSON字符串的格式回答。schema:[数据, 项目, 任务], text:三大攻坚战取得关键进展, input: , output: {\数据\: [], \项目\: [\三大攻坚战\], \任务\: []}, predict: {数据: [], 项目: [三大攻坚战取得关键进展], 任务: []}
}Doccano 导入的数据集样例如下
{id:17168,text:三大攻坚战取得关键进展,label:[[0,5,任务]],Comments:[]}大模型输出数据转为Doccano 代码
找出模型预测的实体在text句子的开始下标和结束下标
def find_substring_indices(parent_string, substring): start_index parent_string.find(substring) if start_index ! -1:end_index start_index len(substring)return start_index, end_index else: return -1, -1import redef tran_llm_doccano(input_file, output_file, schema):doccano_format {text: None,label: [],Comments: []}def _find_text(text):pattern rtext:(.*?), match re.search(pattern, text, re.MULTILINE)text_content match.group(1)return text_contentwith open(input_file, r) as f:with open(output_file, w) as w:for line in f:text _find_text(line)doccano_format[text] textdata json.loads(line)predict data[predict]tmp []for ent_cls in schema:for predict_ent_name in predict[ent_cls]:start_idx, end_idx find_substring_indices(text, predict_ent_name)if start_idx -1 or end_idx -1:continuetmp.append([start_idx, end_idx, ent_cls])doccano_format[label] tmpw.write(json.dumps(doccano_format, ensure_asciiFalse) \n)schema [数据, 项目, 任务]
tran_llm_doccano(data.jsonl, doccano_import.jsonl, schema)tran_llm_doccano(input_file, output_file, schema):
input_file 大模型预测的结果文件output_file 到入到 doccano的文件schema 实体类别
将 大模型的预测结果转换后的Doccano格式的 output_file 文件导入到Doccano的结果如下图所示
开源
完整的代码点击查看 https://github.com/JieShenAI/csdn/blob/main/24/04/tran_llm_doccano/tran_llm_doccano.ipynb