1 Star 0 Fork 1

jinxiu0406 / SOLSim

forked from SOLsim / SOLSim 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
LGPL-3.0

SOL模拟器

简介

本项目是基于GloVe(求取Embedding)和LSTM(训练生成器)制作的SOL对话模拟器,模拟SOL在群里的对话方式。
如果有机会的话,后续会制作制作成QQ插件。

来自网络的语料库

https://github.com/codemayq/chinese_chatbot_corpus

名称 数量 SOL的奇妙手工打分
chatterbot 560 8(翻译有问题,但是内容都是对上的)
douban 3.520M 2(牛头不对马嘴)
ptt 0.4M 8(八卦太多了,好吧毕竟是八卦语料库,不过好像没怎么参与训练?)
qingyun 0.1M 5(部分内容无关)
subtitle 2.74M 8(语言通顺性还行,不过不是对话)
tieba 2.32M 6(语言通顺性还行,但是足球实在太多了)
weibo 4.43M 8(其实这语料库还行的)
xiaohuangji 0.45M 2(黄色内容过多)

训练技巧指导

https://github.com/soumith/ganhacks

基本处理流程

  • 使用语料库,训练Embedding
    • 输入:one hot字向量(单个汉字作为基本单位)
    • 输出:embedded低维度字向量
    • 数据集:raw_chat_corpus(网络聊天记录语料库)
  • 使用语料库,训练LSTM生成器
    • 输入:短句(embedded字向量序列)[batch*l_in*\embed_dim]
    • 输出:下一个字概率[batch*dict_size]
    • 数据集:raw_chat_corpus
  • 使用SOL对话记录,迁移训练上述模型
    • 输入输出同上
    • 数据集:自备

进度

阶段 进度
知识储备 100%
Embedding数据集 100%
Embedding训练 100%
数据清洗 100%
LSTM训练 100%
LSTM + Attention训练 100%
GAN + LSTM训练 60%
GAN + LSTM + MCTS训练 0%
迁移数据集 0%
迁移训练 0%

备注

对于v1~v4

对应代码无后缀。
效果较差。

对于v5

对应代码后缀v5。
引入Attention。

对于v6~v8

对应代码后缀v6。
不再使用预训练Embedding,而是集成在模型中训练。可以注意到收敛loss明显降低(2.8->0.8),开始输出通顺语句,但语义杂乱、句式单一。

对于v9

v9训练集不填充,支持变长训练集,但是因为只能逐行运算,训练速度大幅降低。目前看来v9还是比v8强不少的,没有填充干扰会小很多
目前,仅使用较清洁的chatterbot和青云语料库可以达到很低的loss,模型也能输出通顺的句子,但是内容和句式都比较单一。
在线资料表明,生成式模型确实容易“陷入万能输出”,即无论输入什么都返回相同的内容。后续版本会考虑解决此问题的方案。

对于v10

对于Naive Seq2Seq(with Attention)的尝试到上一个版本为止。本版本开始引入GAN。
根据原理推测,GAN的判别器“理论上”可以快速排除掉之前版本的万能输出。
实验表明Discriminator非常难以设计。使用LSTM对全句打分和对单字打分效果都不甚理想。

一种可以尝试的思路是,保持Generator无填充的同时,对Discriminator填充至固定长度,从而可以使用拉平等方法。
实验证明以上思路并不可行。生成器会迅速趋于输出单字或连续重复的字,换言之模型忽略了几乎全部的信息而成为常函数。
由于尝试次数过多,v10版本号作为失败品被放弃。

对于v11

v10的问题出在Discriminator(即ScrModel)设计不合理,导致无法对Generator的训练起到足够的指导作用。
在v11中,我们参考现有设计方案,总结出两种可行的思路,分别命名为v11a和v11b。
相比之前的版本,v11A比较复杂,而v11B非常复杂,因此需要较长的时间更新(v9,你又可以活一阵子了)。

对于v11A

v11A不再使用LSTM作为评分器。为了能够更好地提取文本中前段的信息(即便是LSTM,hn、cn依然包含更多靠后的信息),采用不同大小的卷积核实现1D-CNN作为评分器。
同时,加入batch中的模型分布与真实分布之间的JS散度作为训练loss的一项。--由于单纯用JS散度无法习得输入输出之间的关系,因此只用于增加语句通顺性。--
其实也是可以习得输入输出的关系,只需要把输入也包含进去,然后做一个特征提取(代码中为Scr.dense1)。
**添加了额外的训练数据:有噪声的正样本(还是正样本)和纯随机的样本(作为负样本)。**可以用来解决生成器开始生成无意义字符的问题;由于输入是Embedding,甚至可以解决模型“纠结”(即对于多个字符输出相同的概率难以选择)的问题。
GAN中Gen Loss缓慢递增(不是快速暴涨)是正常的,因为生成任务比判定任务困难很多,判定器应该较快收敛。模型需要更长时间的训练。
如果后期Gen Loss仍然不下降,则增加生成模型复杂度;很有可能Generator已经收敛了无法训练。

对于v11B

v11B使用MCTS优化下一个生成的文字,以Discriminator的输出作为估价函数,进行强化学习。由于MCTS基于采样,训练过程资源开销可能过于高昂,因此作为保留计划(Plan B)。

对于v12

v11A的表现可以接受,但是存在一些问题。
现在Discriminator给我觉得说的比较好的句子打0分,给有些不通顺的句子打1分。
我在想这是不是因为Generator已经和真实值很相近了,但是Discriminator在训练的时候,还是把Generator标注成负样本,于是它就转而向另一个错误方向训练去了。
解决方案也有,就是训练三个不同的Discriminator,一个管输出和输入的相关性,一个管输出的通顺性,还有一个管人格特征。
还有一点,就是再加入一些各种类型的负样本,并且加入软Label。

这就是v12了。 当然还有备用方案,就是蒙特卡罗法,也就是v11B。
这时,新的问题出现了。
评分器的表现远远超出了生成器,导致生成器无法收敛。
考虑提升生成器的参数数量,ReqModel改为双向模型,RessModel改为两个独立的LSTM+Attention模型。

GNU LESSER GENERAL PUBLIC LICENSE Version 3, 29 June 2007 Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/> Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. This version of the GNU Lesser General Public License incorporates the terms and conditions of version 3 of the GNU General Public License, supplemented by the additional permissions listed below. 0. Additional Definitions. As used herein, "this License" refers to version 3 of the GNU Lesser General Public License, and the "GNU GPL" refers to version 3 of the GNU General Public License. "The Library" refers to a covered work governed by this License, other than an Application or a Combined Work as defined below. An "Application" is any work that makes use of an interface provided by the Library, but which is not otherwise based on the Library. Defining a subclass of a class defined by the Library is deemed a mode of using an interface provided by the Library. A "Combined Work" is a work produced by combining or linking an Application with the Library. The particular version of the Library with which the Combined Work was made is also called the "Linked Version". The "Minimal Corresponding Source" for a Combined Work means the Corresponding Source for the Combined Work, excluding any source code for portions of the Combined Work that, considered in isolation, are based on the Application, and not on the Linked Version. The "Corresponding Application Code" for a Combined Work means the object code and/or source code for the Application, including any data and utility programs needed for reproducing the Combined Work from the Application, but excluding the System Libraries of the Combined Work. 1. Exception to Section 3 of the GNU GPL. You may convey a covered work under sections 3 and 4 of this License without being bound by section 3 of the GNU GPL. 2. Conveying Modified Versions. If you modify a copy of the Library, and, in your modifications, a facility refers to a function or data to be supplied by an Application that uses the facility (other than as an argument passed when the facility is invoked), then you may convey a copy of the modified version: a) under this License, provided that you make a good faith effort to ensure that, in the event an Application does not supply the function or data, the facility still operates, and performs whatever part of its purpose remains meaningful, or b) under the GNU GPL, with none of the additional permissions of this License applicable to that copy. 3. Object Code Incorporating Material from Library Header Files. The object code form of an Application may incorporate material from a header file that is part of the Library. You may convey such object code under terms of your choice, provided that, if the incorporated material is not limited to numerical parameters, data structure layouts and accessors, or small macros, inline functions and templates (ten or fewer lines in length), you do both of the following: a) Give prominent notice with each copy of the object code that the Library is used in it and that the Library and its use are covered by this License. b) Accompany the object code with a copy of the GNU GPL and this license document. 4. Combined Works. You may convey a Combined Work under terms of your choice that, taken together, effectively do not restrict modification of the portions of the Library contained in the Combined Work and reverse engineering for debugging such modifications, if you also do each of the following: a) Give prominent notice with each copy of the Combined Work that the Library is used in it and that the Library and its use are covered by this License. b) Accompany the Combined Work with a copy of the GNU GPL and this license document. c) For a Combined Work that displays copyright notices during execution, include the copyright notice for the Library among these notices, as well as a reference directing the user to the copies of the GNU GPL and this license document. d) Do one of the following: 0) Convey the Minimal Corresponding Source under the terms of this License, and the Corresponding Application Code in a form suitable for, and under terms that permit, the user to recombine or relink the Application with a modified version of the Linked Version to produce a modified Combined Work, in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source. 1) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (a) uses at run time a copy of the Library already present on the user's computer system, and (b) will operate properly with a modified version of the Library that is interface-compatible with the Linked Version. e) Provide Installation Information, but only if you would otherwise be required to provide such information under section 6 of the GNU GPL, and only to the extent that such information is necessary to install and execute a modified version of the Combined Work produced by recombining or relinking the Application with a modified version of the Linked Version. (If you use option 4d0, the Installation Information must accompany the Minimal Corresponding Source and Corresponding Application Code. If you use option 4d1, you must provide the Installation Information in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source.) 5. Combined Libraries. You may place library facilities that are a work based on the Library side by side in a single library together with other library facilities that are not Applications and are not covered by this License, and convey such a combined library under terms of your choice, if you do both of the following: a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities, conveyed under the terms of this License. b) Give prominent notice with the combined library that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work. 6. Revised Versions of the GNU Lesser General Public License. The Free Software Foundation may publish revised and/or new versions of the GNU Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Library as you received it specifies that a certain numbered version of the GNU Lesser General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that published version or of any later version published by the Free Software Foundation. If the Library as you received it does not specify a version number of the GNU Lesser General Public License, you may choose any version of the GNU Lesser General Public License ever published by the Free Software Foundation. If the Library as you received it specifies that a proxy can decide whether future versions of the GNU Lesser General Public License shall apply, that proxy's public statement of acceptance of any version is permanent authorization for you to choose that version for the Library.

简介

暂无描述 展开 收起
Python
LGPL-3.0
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
Python
1
https://gitee.com/link2t/sol-sim.git
git@gitee.com:link2t/sol-sim.git
link2t
sol-sim
SOLSim
master

搜索帮助