飞桨对话模型工具箱(二):对话自动评估模块ADE

导读:人机对话是人工智能的重要挑战,近年来获得了学术界和工业界的广泛关注。为了帮助广大开发者们更快捷地实现对话系统的开发,飞桨在自然语言处理模型库(PaddleNLP)中开源了对话模型工具库,内置了对话通用理解模型(DGU)和对话自动评估模块(ADE)。 在上一篇文章中,我们已经为大家介绍了对话通用理解模型(DGU)。在本篇文章中,将为大家介绍对话自动评估模块(ADE)。

 

1.  对话自动评估

 

随着对话系统的不断发展和成熟,如何评价对话系统的回复质量,成为了一个新的研究方向。

 

对话自动评估技术,能够帮助企业或个人快速评估对话系统的回复质量,减少人工评估成本,具有重要的商业意义。

 

例如,在客服领域,对话自动评估技术可以应用于客服服务质量的评估,判断是否存在答非所问等情况,能够帮助电商管理者进一步了解客服人员的服务水平,从而辅助制定管理决策。

 

在人机对话领域,对话自动评估技术也可以用于评估机器人的回复质量,作为对话系统优劣的一个辅助判断标准,成为对话系统改进的参考指标。

 

2.  飞桨ADE模块介绍

 

2.1.   模型介绍

 

飞桨对话自动评估模块(ADE),主要用于评估开放领域对话系统的回复质量。

 

它的输入是文本对(上文,回复),输出是回复质量得分。

 

考虑到匹配任务(预测上下文是否匹配)与自动评估任务之间的天然联系,飞桨ADE模块利用了匹配任务作为自动评估任务的预训练,然后再利用少量标注数据进行模型微调。

 

因此,飞桨ADE模块可以在无标注数据或少量标注数据的情况下使用:

 

  1. 在无标注数据的情况下,利用负采样训练匹配模型作为评估工具,实现对多个对话系统回复质量排序。

  2. 利用少量标注数据(特定对话系统或场景的人工打分),在匹配模型基础上进行微调,可以显著提高该对话系统或场景的评估效果。

 

飞桨ADE模块内提供了两个模型:

 

  1. 匹配模型:context和response作为输入,使用lstm学习两个句子的表示,在计算两个线性张量的积作为logits,然后使用sigmoid_cross_entropy_with_logits作为loss, 最终用来评估相似程度。

  2. finetuing模型:在匹配模型的基础上,将sigmoid_cross_entropy_with_logits loss优化成平方损失loss,进行训练。

 

2.2.   效果评测

 

我们以四个不同的对话系统(seq2seq_naive/seq2seq_att/keywords/human)为例,使用对话自动评估工具进行自动评估。

 

1、无标注数据情况下,直接使用预训练好的评估工具进行评估; 在四个对话系统上,自动评估打分和人工评估打分spearman相关系数,如下:

 

对四个系统平均得分排序:

 

2、利用少量标注数据微调后,自动评估打分和人工打分spearman相关系数,如下:

 

3.  飞桨ADE上手指南

 

 

下面将送上代码,手把手地教您如何使用飞桨对话自动评估模块(ADE)。

 

3.1.   安装说明

 

环境依赖:

  • Python >= 2.7

  • cuda >= 9.0

  • cudnn >= 7.0

  • pandas >= 0.20.1

  • PaddlePaddle >= 1.6.0

 

克隆项目:

 
  •  
  •  
git clone https://github.com/PaddlePaddle/models.gitcd models/PaddleNLP/dialogue_model_toolkit/auto_dialogue_evaluation

 

3.2.   任务简介

 

本模块内模型训练主要包括两个阶段:

 

1)第一阶段:训练一个匹配模型作为评估工具,可用于待评估对话系统内的回复内容进行排序;(matching任务)

 

模型结构: 输入为context和response,对两个输入学习embedding表示, 学习到的表示经过lstm学习高阶表示, context和response的高阶表示计算双线性张量积logits, logits和label计算sigmoid_cross_entropy_with_logits loss;

 

2)第二阶段:利用少量的对话系统的标记数据,对第一阶段训练的匹配模型进行finetuning,可以提高评估效果(包含human,keywords,seq2seq_att,seq2seq_naive,4个finetuning任务);

 

模型结构: finetuning阶段学习表示到计算logits部分和第一阶段模型结构相同,区别在于finetuning阶段计算square_error_cost loss;

 

用于第二阶段fine-tuning的对话系统包括下面四部分:

 

  • human: 人工模拟的对话系统;

  • keywords:seq2seq keywords对话系统;

  • seq2seq_att:seq2seq attention model 对话系统;

  • seq2seq_naive:naive seq2seq model对话系统;

 

3.3.   数据准备

 

数据集、相关模型下载:

  •  
cd ade && bash prepare_data_and_model.sh

数据路径:data/input/data/

模型路径:data/saved_models/trained_models/

 

3.4.   模型配置

 

配置文件路径: data/config/ade.yaml

 

3.5.   单机训练

 

1、第一阶段matching模型的训练:

 

方式一: 推荐直接使用模块内脚本训练

  •  
bash run.sh matching train

 

方式二: 执行训练相关的代码:

  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
export FLAGS_sync_nccl_allreduce=0export FLAGS_eager_delete_tensor_gb=1  #开启显存优化
export CUDA_VISIBLE_DEVICES=0  #GPU单卡训练#export CUDA_VISIBLE_DEVICES=0,1,2,3  #GPU多卡训练
#export CUDA_VISIBLE_DEVICES=  #CPU训练#export CPU_NUM=1 #CPU训练时指定CPU number
if  [ !"$CUDA_VISIBLE_DEVICES" ]then    use_cuda=falseelse    use_cuda=truefi
pretrain_model_path="data/saved_models/matching_pretrained"
if [ -f ${pretrain_model_path} ]then    rm${pretrain_model_path}fi
if [ ! -d ${pretrain_model_path} ]then     mkdir${pretrain_model_path}fi

 

2、第二阶段finetuning模型的训练:

 

方式一: 推荐直接使用模块内脚本训练

  •  
bash run.sh task_name task_type

task_name和task_type为具体的任务参数,可以在文末Github查看详细内容。

 

方式二: 执行训练相关的代码:

  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
export FLAGS_sync_nccl_allreduce=0export FLAGS_eager_delete_tensor_gb=1  #开启显存优化
export CUDA_VISIBLE_DEVICES=0  #GPU单卡训练#export CUDA_VISIBLE_DEVICES=0,1,2,3  #GPU多卡训练
#export CUDA_VISIBLE_DEVICES=  #CPU训练#export CPU_NUM=1 #CPU训练时指定CPU number
if  [ !"$CUDA_VISIBLE_DEVICES" ]then    use_cuda=falseelse    use_cuda=truefi
save_model_path="data/saved_models/human_finetuned"
if [ -f ${save_model_path} ]then    rm${save_model_path}fi
if [ ! -d ${save_model_path} ]then    mkdir${save_model_path}fi

 

3.6.   模型预测

 

1、第一阶段matching模型的预测:

 

方式一: 推荐直接使用模块内脚本预测

  •  
bash run.sh matching predict

 

方式二: 执行预测相关的代码:

  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
export FLAGS_sync_nccl_allreduce=0export FLAGS_eager_delete_tensor_gb=1  #开启显存优化
export CUDA_VISIBLE_DEVICES=0  #单卡预测#export CUDA_VISIBLE_DEVICES=  #CPU预测#export CPU_NUM=1 #CPU训练时指定CPU number
if  [ !"$CUDA_VISIBLE_DEVICES" ]then    use_cuda=falseelse    use_cuda=truefi

 

2、第二阶段finetuning模型的预测:

 

方式一: 推荐直接使用模块内脚本预测

  •  
bash run.sh task_name task_type

task_name和task_type为具体的任务参数,可以在文末Github查看详细内容。

 

方式二: 执行预测相关的代码:

  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
export FLAGS_sync_nccl_allreduce=0export FLAGS_eager_delete_tensor_gb=1  #开启显存优化
export CUDA_VISIBLE_DEVICES=0  #单卡预测#export CUDA_VISIBLE_DEVICES=  #CPU预测#export CPU_NUM=1 #CPU训练时指定CPU number
if  [ !"$CUDA_VISIBLE_DEVICES" ]then    use_cuda=falseelse    use_cuda=truefi

 

3.7.   模型评估

 

模块中5个任务,各任务支持计算的评估指标内容如下:

 

第一阶段:

matching: 使用R1@2, R1@10, R2@10, R5@10四个指标进行评估排序模型的效果;

 

第二阶段:

 

  • human: 使用spearman相关系数来衡量评估模型对系统的打分与实际对话系统打分之间的关系;

  • keywords:使用spearman相关系数来衡量评估模型对系统的打分与实际对话系统打分之间的关系;

  • seq2seq_att:使用spearman相关系数来衡量评估模型对系统的打分与实际对话系统打分之间的关系;

  • seq2seq_naive:使用spearman相关系数来衡量评估模型对系统的打分与实际对话系统打分之间的关系;

 

1、第一阶段matching模型的评估:

 

方式一: 推荐直接使用模块内脚本评估

  •  
bash run.sh matching evaluate

 

方式二: 执行评估相关的代码:

  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
export CUDA_VISIBLE_DEVICES=  #指默认CPU评估export CPU_NUM=1 #CPU训练时指定CPU number
python -u main.py \     --do_eval=true \     --use_cuda=false \     --evaluation_file="data/input/data/unlabel_data/test.ids" \     --output_prediction_file="data/output/pretrain_matching_predict"\     --loss_type="CLS"

 

2、第二阶段finetuning模型的评估:

 

方式一: 推荐直接使用模块内脚本评估

  •  
bash run.sh task_name task_type

task_name和task_type为具体的任务参数,可以在文末Github查看详细内容。

 

方式二: 执行评估相关的代码:

  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
export CUDA_VISIBLE_DEVICES=  #指默认CPU评估export CPU_NUM=1 #CPU训练时指定CPU number
python -u main.py \     --do_eval=true \     --use_cuda=false \     --evaluation_file="data/input/data/label_data/human/test.ids"\     --output_prediction_file="data/output/finetuning_human_predict"\     --loss_type="L2"

 

3.8.   模型推断

 

1、第一阶段matching模型的推断:

方式一: 推荐直接使用模块内脚本保存inferencemodel

  •  
bash run.sh matching inference

 

方式二: 执行inferencemodel相关的代码:

  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
export CUDA_VISIBLE_DEVICES=0  # 指GPU单卡推断#export CUDA_VISIBLE_DEVICES=  #CPU推断#export CPU_NUM=1 #CPU训练时指定CPU number
if  [ !"$CUDA_VISIBLE_DEVICES" ]then    use_cuda=falseelse    use_cuda=truefi
python -u main.py \     --do_save_inference_model=true \     --use_cuda=${use_cuda} \     --init_from_params="data/saved_models/trained_models/matching_pretrained/params"\     --inference_model_dir="data/inference_models/matching_inference_model"

 

2、第二阶段finetuning模型的推断:

 

方式一: 推荐直接使用模块内脚本保存inferencemodel

  •  
bash run.sh task_name task_type

task_name和task_type为具体的任务参数,可以在文末Github查看详细内容。

 

方式二: 执行inferencemodel相关的代码:

  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
export CUDA_VISIBLE_DEVICES=0  # 指GPU单卡推断#export CUDA_VISIBLE_DEVICES=  #CPU推断#export CPU_NUM=1 #CPU训练时指定CPU number
if  [ !"$CUDA_VISIBLE_DEVICES" ]then    use_cuda=falseelse    use_cuda=truefi
python -u main.py \     --do_save_inference_model=true \     --use_cuda=${use_cuda} \     --init_from_params="data/saved_models/trained_models/human_finetuned/params"\     --inference_model_dir="data/inference_models/human_inference_model"

 

3.9.   服务部署

 

模块内提供已训练好的5个inference_model模型,您可直接下载使用。

 

今天关于飞桨对话自动评估模块(ADE)的介绍到这里就结束了,赶快动手尝试一下吧!

 

想与更多的深度学习开发者交流,请加入飞桨官方QQ群:796771754。

 

如果您想详细了解更多飞桨PaddlePaddle的相关内容,请参阅以下文档。

 

官网地址:

https://www.paddlepaddle.org.cn/

 

项目地址:

https://github.com/PaddlePaddle/models/tree/release/1.6/PaddleNLP/PaddleDialogue

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
$ sudo ade start 出现的错误是因为系统无法找到ade命令。这可能是因为您没有正确安装ade或者ade不在系统的可执行路径中。要解决这个问题,您可以尝试以下几个步骤: 1. 确保您已经正确安装了ade。您可以按照ade的官方文档或指南来安装它。 2. 检查ade是否在系统的可执行路径中。您可以通过运行以下命令来查看: $ echo $PATH 如果ade不在其中,您可以将ade的路径添加到系统的可执行路径中。您可以通过编辑~/.bashrc文件或者/etc/environment文件来实现。记得将ade的路径添加到PATH的环境变量中。 3. 如果您已经安装了ade并且它在系统的可执行路径中,但仍然无法运行ade命令,那么问题可能是由于ADE环境变量未正确配置导致的。您可以检查您的ADE环境变量是否正确设置,并根据需要进行修正。 希望这些步骤可以帮助您解决问题。如果问题仍然存在,请提供更多详细信息,以便我们提供进一步的帮助。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [docker-enter:用于输入现有容器的docker工具。 该工具依赖docker和setns](https://download.csdn.net/download/weixin_42139429/16137568)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] - *2* [ERROR: Failed to start ade. To debug use, ``ade start -- --env DEBUG=1`](https://blog.csdn.net/leoFY123/article/details/122184651)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] - *3* [rqt_graph:未找到命令,查看不了ros的节点图](https://blog.csdn.net/pvmsmfchcs/article/details/128663631)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值