原始文档

Train an end-to-end model

To get started we can train a very simple model using Ludwig (feel free to use

your favourite deep learning framework here):


input_features:
-
name: user
type: text
level: word
encoder: rnn
cell_type: lstm
reduce_output: null output_features:
-
name: system
type: text
level: word
decoder: generator
cell_type: lstm
attention: bahdanau training:
epochs: 100

You can modify this config to reflect the architecture of your choice and train

using Ludwig:

ludwig train \
--data_csv data/metalwoz.csv \
--model_definition_file plato/example/config/ludwig/metalWOZ_seq2seq_ludwig.yaml \
--output_directory "models/joint_models/"

我的笔记

训练端到端模型:

  • 输入文件是 metalwoz.csvmetalWOZ_seq2seq_ludwig.yaml
  • 输出文件是 models/joint_models/

注意模型训练完毕,加载模型文件(使用模型)的时候,还需要(1)写一个类文件,实现plato提供的接口;(2)写一个yaml配置文件,用--config 参数 来告诉plato run 加载的模型的路径。

先准备数据,然后训练模型。

csv文件需要解析得到。

1. 下载metalwoz数据集

https://www.microsoft.com/en-us/research/project/metalwoz/

2. 解压数据

  • 以shoping为例. 901个对话,2个角色

解压之后得到:

/Users/huihui/data/metalwoz-v1/dialogues/SHOPPING.txt

文件内容举例:

{"id": "47d85004", "user_id": "891cf0fb", "bot_id": "0f9f7619", "domain": "SHOPPING", "task_id": "5e456a4d", "turns": ["Hello how may I help you?", "i want to order a mattress from walmart", "Great. I can help you with your mattress order.", "how long will it take to arrive", "From the time of purchase it will take three days for us to ship it.", "great, lets start the order", "Once we have shipped it however, we dont know when it will arrive at your location", "how can i find out an exact date for it to arrive", "We ship priority mail through USPS. The length of time will vary with depending on the carrier", "well then i will try somewhere else, thank you anyway", "I am sorry we were not able to accommodate you"]}

3. 将txt文件转化为csv文件

  • 3.1 准备yaml文件

编写文件

plato/example/config/parser/Parse_MetalWOZ.yaml

---

package: plato.utilities.parser.parse_metal_woz
class: Parser
arguments:
data_path: /Users/huihui/data/metalwoz-v1/dialogues/SHOPPING.txt
  • 3.2 使用脚本执行转换
plato parse --config Parse_MetalWOZ.yaml

解析之后的文件在data/metalwoz.csv

  • 注意:只有2个角色。不是多角色会话
user,system
hi,How can I help you today. I am a bot.
Can you help me order on an online shop,"Sure, I would love to help you. What is it you would like to order?"
I like to order bicycle helmet,Which brand helmet would you like to purchase.
yoni,"OK, what size helmet would you like to order."
small,"OK. I found a Yoni bicycle helmet in size small. It comes in black, red, blue or white. Which color would you like to order?"
black,The cost is $39.99. Would you like to go ahead and place an order?
ok pls,Great. Your order has been placed.
thank you,You are quite welcome. Have a great day!
hi,Hello how may I help you?

至此,csv文件准备完毕

4. 准备model_definition_file文件

官方文档给了例子,

plato/example/config/ludwig/metalWOZ_seq2seq_ludwig.yaml

---

input_features:
-
name: user
type: text
level: word
encoder: rnn
cell_type: lstm
reduce_output: null output_features:
-
name: system
type: text
level: word
decoder: generator
cell_type: lstm
attention: bahdanau training:
epochs: 100

5. 开始训练模型

ludwig train \
--data_csv data/metalwoz.csv \
--model_definition_file plato/example/config/ludwig/metalWOZ_seq2seq_ludwig.yaml \
--output_directory "models/joint_models/"

一共训练100轮

不等训练完毕

6. 写类文件,加载模型

Write a class inheriting from Conversational Module that loads and queries the model

This class simply needs to handle loading of the model, querying it

appropriately and formatting its output appropriately. In our case, we need to

wrap the input text into a pandas dataframe, grab the predicted tokens from

the output and join them in a string that will be returned. See the class here:

plato.agent.component.joint_model.metal_woz_seq2seq.py

package: plato.agent.component.joint_model.metal_woz_seq2seq
class: MetalWOZSeq2Seq

文件:

plato/agent/component/joint_model/metal_woz_seq2seq.py

"""
MetalWOZ is an MetalWOZ class that defines an interface to Ludwig models.
""" class MetalWOZSeq2Seq(ConversationalModule):
……

7. 运行Agent

Write a Plato generic yaml config and run your agent!

See plato/example/config/application/metalwoz_generic.yaml for an example generic

configuration file that interacts with the seq2seq agent over text. You can try

it out as follows:

plato run --config metalwoz_text.yaml

plato/example/config/application/metalwoz_text.yaml

8. 测试结果

Dialogue 1 (out of 10)

USER > I want to buy a bicycle
(DEBUG) system> what is the helmet ?
USER > yoni
(DEBUG) system> what size ?
USER > small
……

2020-02-21 15:57:20 效果不好

模型没有训练好?

再继续训练看看

总结上面的流程

学习笔记(22)- plato-训练端到端的模型的更多相关文章

  1. Ext.Net学习笔记22:Ext.Net Tree 用法详解

    Ext.Net学习笔记22:Ext.Net Tree 用法详解 上面的图片是一个简单的树,使用Ext.Net来创建这样的树结构非常简单,代码如下: <ext:TreePanel runat=&q ...

  2. SQL反模式学习笔记22 伪键洁癖,整理数据

    目标:整理数据,使不连续的主键Id数据记录变的连续. 反模式:填充断档的数据空缺. 1.不按照顺序分配编号 在插入新行时,通过遍历表,找到的第一个未分配的主键编号分配给新行,来代替原来自动分配的伪主键 ...

  3. Caffe学习笔记(一):Caffe架构及其模型解析

    Caffe学习笔记(一):Caffe架构及其模型解析 写在前面:关于caffe平台如何快速搭建以及如何在caffe上进行训练与预测,请参见前面的文章<caffe平台快速搭建:caffe+wind ...

  4. 学习笔记(26)- plato-端到端模型-定闹钟

    今天用了定闹钟的场景语料,在plato框架尝试了端到端的模型. 本文先记录英文的训练过程,然后记录中文的训练过程. 训练端到端的模型 发现使用英文的模型,还是显示有中文,所以,新建目录,重新训练 1. ...

  5. Netty4 学习笔记之二:客户端与服务端心跳 demo

    前言 在上一篇Netty demo 中,了解了Netty中的客户端和服务端之间的通信.这篇则介绍Netty中的心跳. 之前在Mina 中心跳的使用是通过继承 KeepAliveMessageFacto ...

  6. TensorFlow学习笔记——LeNet-5(训练自己的数据集)

    在之前的TensorFlow学习笔记——图像识别与卷积神经网络(链接:请点击我)中了解了一下经典的卷积神经网络模型LeNet模型.那其实之前学习了别人的代码实现了LeNet网络对MNIST数据集的训练 ...

  7. Hadoop学习笔记—22.Hadoop2.x环境搭建与配置

    自从2015年花了2个多月时间把Hadoop1.x的学习教程学习了一遍,对Hadoop这个神奇的小象有了一个初步的了解,还对每次学习的内容进行了总结,也形成了我的一个博文系列<Hadoop学习笔 ...

  8. [原创]java WEB学习笔记22:MVC案例完整实践(part 3)---多个请求对应一个Servlet解析

    本博客为原创:综合 尚硅谷(http://www.atguigu.com)的系统教程(深表感谢)和 网络上的现有资源(博客,文档,图书等),资源的出处我会标明 本博客的目的:①总结自己的学习过程,相当 ...

  9. ‎Cocos2d-x 学习笔记(22) TableView

    [Cocos2d-x 学习笔记 ]目录 1. 简介 TableView直接继承了ScrollView和ScrollViewDelegate.说明TableView能实现ScrollView拖动cont ...

  10. [Firefly引擎][学习笔记二][已完结]卡牌游戏开发模型的设计

    源地址:http://bbs.9miao.com/thread-44603-1-1.html 在此补充一下Socket的验证机制:socket登陆验证.会采用session会话超时的机制做心跳接口验证 ...

随机推荐

  1. 小匠第二周期打卡笔记-Task03

    一.过拟合欠拟合及其解决方案 知识点记录 模型选择.过拟合和欠拟合: 训练误差和泛化误差: 训练误差 :模型在训练数据集上表现出的误差, 泛化误差 : 模型在任意一个测试数据样本上表现出的误差的期望, ...

  2. 3 种比较 cmp

    结构体中的比较 struct dian{ int l,r; bool operator <(const dian &t)const { if(r==t.r) return l>t. ...

  3. AspxDashBorad_OnDashboardLoaded 获取对应的DashboardParameter

    protected void ASPxDashboardViewerThrend_OnDashboardLoaded(object sender, DashboardLoadedWebEventArg ...

  4. C语言-条件编译使用分析

    1.基本概念 条件编译的行为类似于C语言中的if…else… 条件编译是预编译指示命令,用于控制是否编译某段代码 2.实例分析 条件编译初探     22-1.c #include <stdio ...

  5. C语言循环语句工程用法

    -循环语句分析 循环语句的基本工作方式 - 通过条件表达式判断是否执行循环体 - 条件表达式循环if语句表达式的原则 do.while.for的区别 - do语句先执行后判断,循环体至少循环一次 - ...

  6. java 集合与数组的互转方法,与源码分析

    前言 java数组与集合需要互相转换的场景非常多,但是运用不好还是容易抛出UnSupportedOperationException.下面讲解一下互转的方法,以及结合源码分异常产生的原因 集合转数组 ...

  7. 第三十一篇 玩转数据结构——并查集(Union Find)

    1.. 并查集的应用场景 查看"网络"中节点的连接状态,这里的网络是广义上的网络 数学中的集合类的实现   2.. 并查集所支持的操作 对于一组数据,并查集主要支持两种操作:合并两 ...

  8. 1.EntityManaget的persist和merge方法的区别

    1.persist和merge的区别: Persist:添加 Merge : 分两种情况,当对象存在id,则修改:当对象不存在id则添加. 看个例子: 1 public class Account { ...

  9. selenium自动化之加载浏览器配置文件

    化环境:python3.6 + selenium3 当我们做自动化的时候,如果不做任何配置的话打开的浏览器默认是不加载我们的浏览器配置文件的,下面我们来说说如何加载配置文件: 首先不管使用的是火狐浏览 ...

  10. php设计模式之工厂方法实例代码

    实现不修改原代码,扩展新功能 <?php header("Content-type:text/html;charset=utf-8"); /** * db接口 * 实现连接数 ...