我用 tensorflow 实现的“一个神经聊天模型”:一个基于深度学习的聊天机器人
概述
这个工作尝试重现这个论文的结果 A Neural Conversational Model (aka the Google chatbot).
它使用了循环神经网络(seq2seq 模型)来进行句子预测。它是用 python 和 TensorFlow 开发。
程序的加载主体部分是参考 Torch的 neuralconvo from macournoyer.
现在, DeepQA 支持一下对话语料:
- Cornell Movie Dialogs corpus (default). Already included when cloning the repository.
- OpenSubtitles (thanks to Eschnou). Much bigger corpus (but also noisier). To use it, follow those instructions and use the flag
--corpus opensubs. - Supreme Court Conversation Data (thanks to julien-c). Available using
--corpus scotus. See the instructions for installation. - Ubuntu Dialogue Corpus (thanks to julien-c). Available using
--corpus ubuntu. See the instructions for installation. - Your own data (thanks to julien-c) by using a simple custom conversation format (See here for more info).
To speedup the training, it's also possible to use pre-trained word embeddings (thanks to Eschnou). More info here.
安装
这个程序需要一下依赖(easy to install using pip: pip3 install -r requirements.txt):
- python 3.5
- tensorflow (tested with v1.0)
- numpy
- CUDA (for using GPU)
- nltk (natural language toolkit for tokenized the sentences)
- tqdm (for the nice progression bars)
你可能需要下载附带的数据让 nltk 正常工作。
python3 -m nltk.downloader punkt
Cornell 数据集已经包括了。其他的数据集查看 readme 文件到他们所在的文件夹。 (在 data/).
网站接口需要一些附加的包:
- django (tested with 1.10)
- channels
- Redis (see here)
- asgi_redis (at least 1.0)
Docker 安装也是支持的,更多详细的教程参考 here.
运行
聊天机器人
训练这个模型,直接运行 main.py 。一旦训练完成,你可以测试结果用 main.py --test
(结果生成在 'save/model/samples_predictions.txt') 或者用 main.py --test interactive (更有趣).
Here are some flags which could be useful. For more help and options, use python main.py -h:
--modelTag <name>: allow to give a name to the current model to differentiate between them when testing/training.--keepAll: use this flag when training if when testing, you want to see the predictions at different steps (it can be interesting to see the program changes its name and age as the training progress). Warning: It can quickly take a lot of storage space if you don't increase the--saveEveryoption.--filterVocab 20or--vocabularySize 30000: Limit the vocabulary size to and optimize the performances and memory usage. Replace the words used less than 20 times by the<unknown>token and set a maximum vocabulary size.--verbose: when testing, will print the sentences as they are computed.--playDataset: show some dialogue samples from the dataset (can be use conjointly with--createDatasetif this is the only action you want to perform).
To visualize the computational graph and the cost with TensorBoard, just run tensorboard --logdir save/.
默认的这个网络架构是一个标准的 encoder/decoder 有两个 LSTM layers (隐藏层大小 256) ,然后 vocabulary 的 embedding size 是 32.这个网络用 ADAM 训练。最大的句子长度设置为 10个单词,但是可以增加。
结果
当然,这个网络并不会很擅长聊天:
Q: Hi
A: Hi.
Q: What is your name ?
A: Laura.
Q: What does that mean ?
A: I dunno.
Q: How old are you ?
A: thirty-five.
Q: Will Google hire me ?
A: No.
Q: Tell me the alphabet
A: Fuck you.
Q: That's not nice
A: Yeah.
这里有一些情况它并不能正确回答:
Q: Who is Laura ?
A: My brother.
Q: Say 'goodbye'
A: Alright.
Q: What is cooking ?
A: A channel.
Q: Can you say no ?
A: No.
Q: Two plus two
A: Manny...
预训练模型
项目截图:

实测截图:

一步一步教程:
1.下载这个项目:
https://github.com/Conchylicultor/DeepQA
2.下载训练好的模型:
https://drive.google.com/file/d/0Bw-phsNSkq23OXRFTkNqN0JGUU0/view
(如果网址不能打开的话,今晚我会上传到百度网盘,分享到:http://www.tensorflownews.com/)
3.解压之后放在 项目 save 目录下
如图所示

4.复制 save/model-pretrainedv2/dataset-cornell-old-lenght10-filter0-vocabSize0.pkl 这个文件到 data/samples/
如图所示:

5.在项目目录执行一下命令:
python3 main.py --modelTag pretrainedv2 --test interactive
程序读取了预训练的模型之后,如图:

聊天机器人资源合集
项目,语聊,论文,教程
https://github.com/fendouai/Awesome-Chatbot
更多教程:
http://www.tensorflownews.com/
DeepQA
备注:为了更加容易了解这个项目,说明部分翻译了项目的部分 readme ,主要是介绍使用预处理数据来运行这个项目。
我用 tensorflow 实现的“一个神经聊天模型”:一个基于深度学习的聊天机器人的更多相关文章
- 【原创 深度学习与TensorFlow 动手实践系列 - 1】第一课:深度学习总体介绍
最近一直在研究机器学习,看过两本机器学习的书,然后又看到深度学习,对深度学习产生了浓厚的兴趣,希望短时间内可以做到深度学习的入门和实践,因此写一个深度学习系列吧,通过实践来掌握<深度学习> ...
- 转:TensorFlow和Caffe、MXNet、Keras等其他深度学习框架的对比
http://geek.csdn.net/news/detail/138968 Google近日发布了TensorFlow 1.0候选版,这第一个稳定版将是深度学习框架发展中的里程碑的一步.自Tens ...
- 基于深度学习和迁移学习的识花实践——利用 VGG16 的深度网络结构中的五轮卷积网络层和池化层,对每张图片得到一个 4096 维的特征向量,然后我们直接用这个特征向量替代原来的图片,再加若干层全连接的神经网络,对花朵数据集进行训练(属于模型迁移)
基于深度学习和迁移学习的识花实践(转) 深度学习是人工智能领域近年来最火热的话题之一,但是对于个人来说,以往想要玩转深度学习除了要具备高超的编程技巧,还需要有海量的数据和强劲的硬件.不过 Tens ...
- 一个基于深度学习回环检测模块的简单双目 SLAM 系统
转载请注明出处,谢谢 原创作者:Mingrui 原创链接:https://www.cnblogs.com/MingruiYu/p/12634631.html 写在前面 最近在搞本科毕设,关于基于深度学 ...
- 吴裕雄--天生自然 神经网络人工智能项目:基于深度学习TENSORFLOW框架的图像分类与目标跟踪报告(续四)
2. 神经网络的搭建以及迁移学习的测试 7.项目总结 通过本次水果图片卷积池化全连接试验分类项目的实践,我对卷积.池化.全连接等相关的理论的理解更加全面和清晰了.试验主要采用python高级编程语言的 ...
- tensorflow deepmath:基于深度学习的自动化数学定理证明
Deepmath Deepmath项目旨在改进使用深度学习和其他机器学习技术的自动化定理证明. Deepmath是Google研究与几所大学之间的合作. 免责声明: 该存储库中的源代码不是Google ...
- 基于深度学习的人脸识别系统Win10 环境安装与配置(python+opencv+tensorflow)
一.需要下载的软件.环境及文件 (由于之前见识短浅,对Anaconda这个工具不了解,所以需要对安装过程做出改变:就是Python3.7.2的下载安装是可选的,因为Anaconda已经为我们解决Pyt ...
- TensorFlow系列专题(三):深度学习简介
一.深度学习的发展历程 深度学习的起源阶段 深度学习的发展阶段 深度学习的爆发阶段 二.深度学习的应用 自然语言处理 语音识别与合成 图像领域 三.参考文献 一.深度学习的发展历程 作为机器学习最 ...
- 02基于python玩转人工智能最火框架之TensorFlow人工智能&深度学习介绍
人工智能之父麦卡锡给出的定义 构建智能机器,特别是智能计算机程序的科学和工程. 人工智能是一种让计算机程序能够"智能地"思考的方式 思考的模式类似于人类. 什么是智能? 智能的英语 ...
随机推荐
- 改变input的placeholder颜色
input::-webkit-input-placeholder{ color:#666; } input::-ms-input-placeholder{ color:#666; } input::- ...
- STM32常见问题
一.STM32 下不了程序 提示: (1).JLink Info: CPU halted Erase Done. Programming Failed! 解决办法: 用isp把芯片全部擦除再试试,如果 ...
- 从PRISM开始学WPF(八)導航Navigation?
0x6Navigation Basic Navigation Prism中的Navigation提供了一种类似导航的功能,他可以根据用户的输入,来刷新UI. 先看一个最简单的例子,通过按钮来导航到一个 ...
- ASP.NET MVC 5 SmartCode Scaffolding for Visual Studio.Net
介绍 ASP.NET MVC 5 SmartCode Scaffolding是集成在Visual Studio.Net开发工具中一个ASP.NET MVC Web应用程序代码生成框架,使用SmartC ...
- h5图片上传预览
项目中常用到文件上传预览功能,整理一下:如果不想使用 type="file" 的默认样式,可以让其覆盖在一个按钮样式上边,设其透明度为0,或者使用Label关联 html < ...
- NHibernate从入门到精通系列(2)——NHibernate环境与结构体系
内容摘要 NHibernate的开发环境 NHibernate的结构体系 NHibernate的配置 一.NHibernate的开发环境 NHibernate的英文官方网站为:http://nhfor ...
- Django(博客系统):基于pycharm如何一个django工程下创建多个app
背景:通常我们创建一个django系统时,为了把业务模块划分清楚往往会把一个独立的业务模块放到一个app中,如果多个独立的业务模块就会创建多个app,一般情况下为了更好的管理这些app,会把他们都存放 ...
- Spark:导入数据到oracle
方案一: //overwrite JdbcDialect fitting for Oracle val OracleDialect = new JdbcDialect { override def c ...
- sys.exc_info()可以捕获到任意异常
import sys try: a = 3 assert a > 4 except: exc = sys.exc_info()#返回异常的元祖 print (exc)
- Menu-右键弹出菜单
#右键弹出菜单 from tkinter import * root=Tk() def callback(): print('我被调用了') menubar =Menu(root) menubar.a ...