资讯 文档
技术能力
语音技术
文字识别
人脸与人体
图像技术
语言与知识
视频技术

UIE标注微调流程


对于简单/通用的抽取目标可以直接调用UIE实现零样本(zero-shot)抽取。但对于大多数实际业务场景,我们推荐使用进一步对UIE进行定制(即标注少量数据进行模型微调),以进一步提升模型效果,最终满足实际使用需求 现在UIE提供标注微调全流程工具适配,方便用户使用

准备工作,下载模型:

# 进入模型文件夹
cd ../../models_hub
# 下载所有uie模型
sh ernie_uie_xxxxxx

数据标注

标注工具

  • 外部或开源工具

  • baidu商业化平台或工具

    • textmind:Textmind平台导出的标注数据,主要为文档类标注数据。
    • 知言:NLP知言平台导出的标注数据,特指其中文本类格式,文档类格式与textmind格式一致。

数据转换

训练前需要将标注数据格式转换为UIE训练数据格式。(如果有问题删除应用包前面的点:.schema -> schema;.utils -> utils)

python3 convert_data.py \
        --from doieat \
        --to monet_train \
        --input-path $INPUT_PATH \
        --output-path $OUTPUT_DIR \
        --split-ratio 0.8 0.2 0.0 \
        --negative-ratio 3 \
        --shuffle True

训练微调

使用转换后的UIE训练数据格式,对模型进行微调。(目前支持单卡训练)

# 先更改.json中的数据路径
python3 run_trainer.py --param_path ./examples/ernie_uie_v1_large.json
or
python3 run_trainer.py --param_path ./examples/ernie_uie_v2_large.json
or
python3 run_trainer.py --param_path ./examples/ernie_uie_v3_large.json

# 训练好的模型保存在output对应文件夹中,json中有对应设置
  • 训练运行的日志会自动保存在./log/test.log文件中
  • 训练结束后产生的结果:

    • 模型文件会默认保存在./output/xxx目录下,xxx根据json中的设置来

      • 其中save_inference_model/文件夹会保存用于预测的模型文件
      • 其中save_checkpoint/文件夹会保存用于热启动的模型文件
    • 训练中产生评估结果和对评估集的预测结果分别保存在output/evaluations/文件夹和output/predictions文件夹

加载训好的模型

使用预测函数功能,只需要修改如下对应json中加载的预测模型位置即可

# uie v1
inner_config/ernie_uie_large_extraction_ch_infer.json
# uie v3
inner_config/ernie_uie_v3_large_extraction_infer.json

# json修改内容
"inference": {
    "inference_model_path": "../../models_hub/ernie_uie_v3_large_extraction_dir/inference_model", # 这里改为新预测模型位置
    ...
}

之后使用预测函数即可使用新模型,使用方法参考UIE预测章节

上一篇
UIE预测:预测函数和批量预测任务
下一篇
(New)文本生成