WO2020155619A1 - Method and apparatus for chatting with machine with sentiment, computer device and storage medium - Google Patents

Method and apparatus for chatting with machine with sentiment, computer device and storage medium Download PDF

Info

Publication number
WO2020155619A1
WO2020155619A1 PCT/CN2019/103516 CN2019103516W WO2020155619A1 WO 2020155619 A1 WO2020155619 A1 WO 2020155619A1 CN 2019103516 W CN2019103516 W CN 2019103516W WO 2020155619 A1 WO2020155619 A1 WO 2020155619A1
Authority
WO
WIPO (PCT)
Prior art keywords
response
model
chat
sentence
chat sentence
Prior art date
Application number
PCT/CN2019/103516
Other languages
French (fr)
Chinese (zh)
Inventor
吴壮伟
Original Assignee
平安科技(深圳)有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 平安科技(深圳)有限公司 filed Critical 平安科技(深圳)有限公司
Publication of WO2020155619A1 publication Critical patent/WO2020155619A1/en

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06NCOMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
    • G06N3/00Computing arrangements based on biological models
    • G06N3/02Neural networks
    • G06N3/04Architecture, e.g. interconnection topology
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06NCOMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
    • G06N3/00Computing arrangements based on biological models
    • G06N3/02Neural networks
    • G06N3/08Learning methods

Abstract

Disclosed in embodiments of the present application are a method and apparatus for chatting with a machine with sentiment, a computer device and a storage medium, wherein the method comprises the following steps: obtaining a chat sentence inputted by a user; inputting the chat sentence into a preset response generation model to obtain an initial response outputted by the response generation model in response to the chat sentence; inputting the initial response into a preset sentiment generation model to obtain at least two candidate responses carrying sentiment outputted by the sentiment generation model in response to the initial response; inputting the candidate responses and the chat sentence into a trained deep reinforcement learning network model to obtain a deep reinforcement learning value of each candidate response; and returning the candidate response that has the largest deep reinforcement learning value as a response sentence of the chat sentence. A reply that has sentiment is returned for the chat statement inputted by the user, making the machine chat more natural and humanized.

Description

带情感的机器聊天方法、 装置、 计算机设备及存储介质 Emotional machine chat method, device, computer equipment and storage medium
【交叉引用】 【cross reference】
本申请以 2019年 1月 28日申请号为 2019100819896, 名称为 “带情感的机器 聊天方法、 装置、 计算机设备及存储介质” 的中国发明专利申请为基础, 并要 求其优先权。 This application is based on the Chinese invention patent application with the application number 2019100819896 on January 28, 2019, titled "Emotional machine chat method, device, computer equipment, and storage medium", and requires priority.
【技术领域】 【Technical Field】
本申请涉及人工智能技术领域, 尤其涉及一种带情感的机器聊天方法、 装 置、 计算机设备及存储介质。 This application relates to the field of artificial intelligence technology, and in particular to an emotional machine chat method, device, computer equipment, and storage medium.
【背景技术】 【Background technique】
随着人工智能技术的发展, 聊天机器人也逐渐兴起。 聊天机器人是一个用 来模拟人类对话或聊天的程序, 可以用于实用的目的, 例如客户服务、 咨询问 答, 也有一部分的社交机器人, 用来与人们聊天。 With the development of artificial intelligence technology, chatbots have gradually emerged. A chatbot is a program used to simulate human conversations or chats. It can be used for practical purposes, such as customer service and consultation. There are also some social robots used to chat with people.
有些聊天机器人会搭载自然语言处理系统, 但更多的从输入语句中提取关 键字,再从数据库中根据关键字检索答案。这些聊天机器人回答通常中规中矩, 不带感情色彩, 聊天模式千篇一律, 导致人们与之聊天的兴趣不高, 聊天机器 人的利用率也较低。 Some chatbots will be equipped with a natural language processing system, but more of them extract keywords from input sentences, and then retrieve answers based on keywords from the database. The answers of these chat robots are usually pretty, non-emotional, and the chat mode is the same, which leads to people's low interest in chatting with them, and the utilization rate of chat robots is also low.
【发明内容】 [Content of the invention]
本申请提供一种带情感的机器聊天方法、 装置、 计算机设备及存储介质, 以解决聊天机器人回答千篇一律, 不带感情色彩的问题。 This application provides an emotional machine chatting method, device, computer equipment, and storage medium to solve the problem that chat robots answer the same question without emotion.
一种带情感的机器聊天方法, 包括如下步骤: An emotional machine chat method includes the following steps:
获取用户输入的聊天语句; Get the chat sentence entered by the user;
将所述聊天语句输入到预设的应答生成模型中, 获取所述应答生成模型响 应所述聊天语句而输出的初始应答; Input the chat sentence into a preset response generation model, and obtain an initial response output by the response generation model in response to the chat sentence;
将所述初始应答输入到预设的情感生成模型中, 获取所述情感生成模型响 应所述初始应答而输出的至少两个携带情感的候选应答; 将所述候选应答和所述聊天语句输入到经过训练的深度强化学习网络模型 中, 获取各候选应答的深度强化学习值; Inputting the initial response into a preset emotion generation model, and obtaining at least two candidate responses that carry emotion and output by the emotion generation model in response to the initial response; Input the candidate response and the chat sentence into a trained deep reinforcement learning network model to obtain the deep reinforcement learning value of each candidate response;
返回深度强化学习值最大的候选应答作为所述聊天语句的应答语句。 The candidate response with the largest deep reinforcement learning value is returned as the response sentence of the chat sentence.
一种带情感的机器聊天装置, 包括: An emotional machine chat device, including:
获取模块, 用于获取用户输入的聊天语句; Obtaining module, used to obtain chat sentences input by the user;
生成模块, 用于将所述聊天语句输入到预设的应答生成模型中, 获取所述 应答生成模型响应所述聊天语句而输出的初始应答; A generating module, configured to input the chat sentence into a preset response generation model, and obtain an initial response output by the response generation model in response to the chat sentence;
处理模块, 用于将所述初始应答输入到预设的情感生成模型中, 获取所述 情感生成模型响应所述初始应答而输出的至少两个携带情感的候选应答; A processing module, configured to input the initial response into a preset emotion generation model, and obtain at least two candidate responses that carry emotion that are output by the emotion generation model in response to the initial response;
计算模块, 用于将所述候选应答和所述聊天语句输入到经过训练的深度强 化学习网络模型中, 获取各候选应答的深度强化学习值; A calculation module, configured to input the candidate response and the chat sentence into a trained deep-strength learning network model to obtain the deep-strength learning value of each candidate response;
执行模块, 用于返回深度强化学习值最大的候选应答作为所述聊天语句的 应答语句。 The execution module is used to return the candidate response with the largest deep reinforcement learning value as the response sentence of the chat sentence.
一种计算机设备, 包括存储器和处理器, 所述存储器中存储有计算机可读 指令, 所述计算机可读指令被所述处理器执行时, 使得所述处理器实现以下步 骤: 获取用户输入的聊天语句; A computer device includes a memory and a processor, wherein computer readable instructions are stored in the memory, and when the computer readable instructions are executed by the processor, the processor implements the following steps: acquiring a chat input by a user Statement
将所述聊天语句输入到预设的应答生成模型中, 获取所述应答生成模型响 应所述聊天语句而输出的初始应答; Input the chat sentence into a preset response generation model, and obtain an initial response output by the response generation model in response to the chat sentence;
将所述初始应答输入到预设的情感生成模型中, 获取所述情感生成模型响 应所述初始应答而输出的至少两个携带情感的候选应答; Inputting the initial response into a preset emotion generation model, and obtaining at least two candidate responses carrying emotions output by the emotion generation model in response to the initial response;
将所述候选应答和所述聊天语句输入到经过训练的深度强化学习网络模型 中, 获取各候选应答的深度强化学习值; Input the candidate response and the chat sentence into a trained deep reinforcement learning network model to obtain the deep reinforcement learning value of each candidate response;
返回深度强化学习值最大的候选应答作为所述聊天语句的应答语句。 一种计算机可读存储介质, 所述计算机可读存储介质上存储有计算机可读 指令, 所述计算机可读指令被处理器执行时实现如下步骤: The candidate response with the largest deep reinforcement learning value is returned as the response sentence of the chat sentence. A computer-readable storage medium having computer-readable instructions stored thereon, and when the computer-readable instructions are executed by a processor, the following steps are implemented:
获取用户输入的聊天语句; Get the chat sentence entered by the user;
将所述聊天语句输入到预设的应答生成模型中, 获取所述应答生成模型响 应所述聊天语句而输出的初始应答; Input the chat sentence into a preset response generation model, and obtain an initial response output by the response generation model in response to the chat sentence;
将所述初始应答输入到预设的情感生成模型中, 获取所述情感生成模型响 应所述初始应答而输出的至少两个携带情感的候选应答; 将所述候选应答和所述聊天语句输入到经过训练的深度强化学习网络模型 中, 获取各候选应答的深度强化学习值; Inputting the initial response into a preset emotion generation model, and obtaining at least two candidate responses that carry emotion and output by the emotion generation model in response to the initial response; Input the candidate response and the chat sentence into a trained deep reinforcement learning network model to obtain the deep reinforcement learning value of each candidate response;
返回深度强化学习值最大的候选应答作为所述聊天语句的应答语句。 The candidate response with the largest deep reinforcement learning value is returned as the response sentence of the chat sentence.
本申请实施例的有益效果为: 通过获取用户输入的聊天语句; 将所述聊天 语句输入到预设的应答生成模型中, 获取所述应答生成模型响应所述聊天语句 而输出的初始应答; 将所述初始应答输入到预设的情感生成模型中, 获取所述 情感生成模型响应所述初始应答而输出的至少两个携带情感的候选应答; 将所 述候选应答和所述聊天语句输入到经过训练的深度强化学习网络模型中, 获取 各候选应答的深度强化学习值; 返回深度强化学习值最大的候选应答作为所述 聊天语句的应答语句。 对用户输入的聊天语句, 返回带情感的答复, 使机器聊 天更自然、 更人性化。 The beneficial effects of the embodiments of the present application are: by acquiring the chat sentence input by the user; inputting the chat sentence into a preset response generation model, and obtaining the initial response output by the response generation model in response to the chat sentence; The initial response is input into a preset emotion generation model, and at least two candidate responses that carry emotions output by the emotion generation model in response to the initial response are obtained; and the candidate response and the chat sentence are input into the process In the trained deep reinforcement learning network model, the deep reinforcement learning value of each candidate response is obtained; and the candidate response with the largest deep reinforcement learning value is returned as the response sentence of the chat sentence. It returns emotional responses to the chat sentences entered by the user, making machine chat more natural and humane.
【附图说明】 【Explanation of drawings】
为了更清楚地说明本申请实施例中的技术方案, 下面将对实施例描述中所需要 使用的附图作简单地介绍, 显而易见地, 下面描述中的附图仅仅是本申请的一 些实施例, 对于本领域技术人员来讲, 在不付出创造性劳动的前提下, 还可以 根据这些附图获得其他的附图 In order to more clearly describe the technical solutions in the embodiments of the present application, the following will briefly introduce the accompanying drawings used in the description of the embodiments. Obviously, the accompanying drawings in the following description are only some embodiments of the present application. For those skilled in the art, without creative work, other drawings can be obtained from these drawings.
图 1为本申请实施例一种带情感的机器聊天方法基本流程示意图; 图 2为本申请实施例生成初始应答的流程示意图; Figure 1 is a schematic diagram of the basic flow of an emotional machine chat method according to an embodiment of this application; Figure 2 is a schematic diagram of the flow of generating an initial response according to an embodiment of this application;
图 3为本申请实施例通过问答知识库生成初始应答的流程示意图; 图 4为本申请实施例情感生成模型训练的流程示意图; FIG. 3 is a schematic diagram of the process of generating an initial response through a question-and-answer knowledge base according to an embodiment of the application; FIG. 4 is a schematic diagram of the training process of an emotion generation model according to an embodiment of the application;
图 5为本申请实施例深度学习强化网络训练的流程示意图; FIG. 5 is a schematic diagram of a process of deep learning enhanced network training according to an embodiment of this application;
图 6为本申请实施例一种带情感的机器聊天装置基本结构框图; FIG. 6 is a basic structural block diagram of an emotional machine chat device according to an embodiment of this application;
图 7为本申请实施例计算机设备基本结构框图。 Fig. 7 is a block diagram of the basic structure of a computer device according to an embodiment of the application.
【具体实施方式】 为了使本技术领域的人员更好地理解本申请方案, 下面将结合本申请实施 例中的附图, 对本申请实施例中的技术方案进行清楚、 完整地描述。 [Detailed Embodiments] In order to enable those skilled in the art to better understand the solutions of the present application, the technical solutions in the embodiments of the present application will be described clearly and completely in conjunction with the accompanying drawings in the embodiments of the present application.
在本申请的说明书和权利要求书及上述附图中的描述的一些流程中, 包含 了按照特定顺序出现的多个操作, 但是应该清楚了解, 这些操作可以不按照其 在本文中出现的顺序来执行或并行执行, 操作的序号如 101、 102等, 仅仅是用 于区分开各个不同的操作, 序号本身不代表任何的执行顺序。 另外, 这些流程 可以包括更多或更少的操作, 并且这些操作可以按顺序执行或并行执行。 需要 说明的是, 本文中的“第一”、 “第二’’等描述, 是用于区分不同的消息、 设备、 模 块等, 不代表先后顺序, 也不限定“第一”和“第二”是不同的类型。 In some of the procedures described in the specification and claims of this application and the above-mentioned drawings, multiple operations appearing in a specific order are included, but it should be clearly understood that these operations may not be in accordance with them. In this document, the order of execution or parallel execution, operation serial numbers such as 101, 102, etc., are only used to distinguish different operations, and the serial numbers themselves do not represent any execution order. In addition, these processes may include more or fewer operations, and these operations may be executed sequentially or in parallel. It should be noted that the descriptions of "first" and "second" in this article are used to distinguish different messages, devices, modules, etc., and do not represent a sequence, nor do they limit "first" and "second". "Is a different type.
下面将结合本申请实施例中的附图, 对本申请实施例中的技术方案进行清 楚、 完整地描述, 显然, 所描述的实施例仅仅是本申请一部分实施例, 而不是 全部的实施例。 基于本申请中的实施例, 本领域技术人员在没有作出创造性劳 动前提下所获得的所有其他实施例, 都属于本申请保护的范围。 The technical solutions in the embodiments of the present application will be clearly and completely described below in conjunction with the accompanying drawings in the embodiments of the present application. Obviously, the described embodiments are only a part of the embodiments of the present application, rather than all the embodiments. Based on the embodiments in this application, all other embodiments obtained by those skilled in the art without creative efforts shall fall within the protection scope of this application.
实施例 Example
本技术领域技术人员可以理解, 这里所使用的“终端”、“终端设备”既包括无 线信号接收器的设备, 其仅具备无发射能力的无线信号接收器的设备, 又包括 接收和发射硬件的设备, 其具有能够在双向通信链路上, 执行双向通信的接收 和发射硬件的设备。 这种设备可以包括: 蜂窝或其他通信设备, 其具有单线路 显示器或多线路显示器或没有多线路显示器的蜂窝或其他通信设备; PCS (Personal Communications Service, 个人通信系统), 其可以组合语音、 数据处 理、传真和 /或数据通信能力; PDA( Personal Digital Assistant , 个人数字助理), 其可以包括射频接收器、 寻呼机、 互联网 /内联网访问、 网络浏览器、 记事本、 日历和 /或 GPS (Global Positioning System, 全球定位系统) 接收器; 常规膝上 型和 /或掌上型计算机或其他设备, 其具有和 /或包括射频接收器的常规膝上型和 /或掌上型计算机或其他设备。这里所使用的“终端”、“终端设备”可以是便携式、 可运输、 安装在交通工具 (航空、 海运和 /或陆地) 中的, 或者适合于和 /或配置 为在本地运行, 和 /或以分布形式, 运行在地球和 /或空间的任何其他位置运行。 这里所使用的“终端”、 “终端设备”还可以是通信终端、 上网终端、 音乐 /视频播 放终端, 例如可以是 PDA、 MID ( Mobile Internet Device, 移动互联网设备) 和 /或具有音乐 /视频播放功能的移动电话, 也可以是智能电视、 机顶盒等设备。 Those skilled in the art can understand that the "terminal" and "terminal equipment" used herein include both wireless signal receiver equipment, which only has equipment with wireless signal receivers without transmitting capability, and also includes receiving and transmitting hardware equipment. A device, which has a device capable of performing two-way communication receiving and transmitting hardware on a two-way communication link. Such equipment may include: cellular or other communication equipment, which has a single line display or multi-line display or cellular or other communication equipment without a multi-line display; PCS (Personal Communications Service, personal communication system), which can combine voice and data Processing, fax and/or data communication capabilities; PDA (Personal Digital Assistant), which can include radio frequency receivers, pagers, Internet/Intranet access, web browsers, notepads, calendars and/or GPS (Global Positioning System (Global Positioning System) receiver; conventional laptop and/or palmtop computer or other device, which has and/or includes a radio frequency receiver. The "terminal" and "terminal equipment" used here may be portable, transportable, installed in vehicles (aviation, sea and/or land), or suitable and/or configured to operate locally, and/or In a distributed form, it runs on the earth and/or any other location in space. The "terminal" and "terminal equipment" used here can also be communication terminals, internet terminals, music/video playback terminals, for example, PDAs, MIDs (Mobile Internet Devices, mobile Internet devices) and/or music/video playback Functional mobile phones can also be devices such as smart TVs and set-top boxes.
本实施方式中的终端即为上述的终端。 具体地, 请参阅图 1, 图 1为本实施例一种带情感的机器聊天方法的基本流 程示意图。 如图 1所示, 一种带情感的机器聊天方法, 包括下述步骤: The terminal in this embodiment is the aforementioned terminal. Specifically, please refer to FIG. 1. FIG. 1 is a schematic diagram of the basic flow of an emotional machine chat method in this embodiment. As shown in Figure 1, an emotional machine chat method includes the following steps:
S 10K 获取用户输入的聊天语句; S 10K obtains the chat sentence entered by the user;
通过终端上可交互的页面获取用户输入的语言信息, 接收到的信息可以是 文本信息, 也可以是语音信息, 通过语音识别装置, 将语音信息转化为文本信 息。 The language information input by the user is acquired through the interactive page on the terminal. The received information can be text information or voice information. The voice information is converted into text information through a voice recognition device.
5102、 将所述聊天语句输入到预设的应答生成模型中, 获取所述应答生成 模型响应所述聊天语句而输出的初始应答; S102. Input the chat sentence into a preset response generation model, and obtain an initial response output by the response generation model in response to the chat sentence.
应答生成模型可以采用经过训练的 Seq2Seq模型, 具体的训练过程为准备 训练语料, 即准备输入序列和对应的输出序列, 将输入序列输入到 Seq2Seq模 型, 计算得到输出序列的概率, 调整 Seq2Seq模型的参数, 使整个样本, 即所 有输入序列经过 Seq2Seq输出对应输出序列的概率最高。 采用 Seq2Seq模型生 成初始应答的过程为, 首先将聊天语句向量化, 例如采用 one-hot词汇编码方式 得到词向量, 输入到 Encoder层, 其中, Encoder层是以双向 LSTM层作为基本 的神经元单位的多层神经元层; 输出的 encoder的状态向量, 输入到 Decoder层 中, 其中 Decoder层也是以双向 LSTM ( Long Short-Term Memory) 层作为基本 的神经元单位的多层神经网络; 将 Decoder层输出的 final_state状态向量输入到 Softmax层, 得到概率最高的初始应答内容。 The response generation model can use the trained Seq2Seq model. The specific training process is to prepare the training corpus, that is, prepare the input sequence and the corresponding output sequence, input the input sequence into the Seq2Seq model, calculate the probability of the output sequence, and adjust the parameters of the Seq2Seq model , So that the entire sample, that is, all input sequences, has the highest probability of outputting the corresponding output sequence after Seq2Seq. The process of using the Seq2Seq model to generate the initial response is to first vectorize the chat sentence, for example, use the one-hot vocabulary encoding method to obtain the word vector, and input it to the Encoder layer, where the Encoder layer uses the bidirectional LSTM layer as the basic neuron unit Multi-layer neuron layer; The output state vector of the encoder is input to the Decoder layer, where the Decoder layer is also a multi-layer neural network with the bidirectional LSTM (Long Short-Term Memory) layer as the basic neuron unit; The decoder layer is output The final_state state vector is input to the Softmax layer, and the initial response content with the highest probability is obtained.
在一些实施方式中, 机器聊天应用于问题解答型场景, 采用的应答生成模 型为问答知识库, 通过关键词检索, 获得针对用户输入的聊天语句中所含问题 的答案, 返回该答案作为初始应答。 In some embodiments, machine chat is applied to a question answering scenario, and the response generation model adopted is a question-and-answer knowledge base. Through keyword search, the answer to the question contained in the chat sentence input by the user is obtained, and the answer is returned as the initial response .
在一些实施方式中, 机器聊天既用来陪用户闲聊也可以解答用户的问题, 通过先确定是否为问题解答型场景来选择应答生成模型, 具体描述请参见图 2。 In some implementations, the machine chat is used to accompany the user in small talk and to answer the user's question. The response generation model is selected by first determining whether it is a question answering scene. Please refer to FIG. 2 for specific description.
5103、 将所述初始应答输入到预设的情感生成模型中, 获取所述情感生成 模型响应所述初始应答而输出的至少两个携带情感的候选应答; S103: Input the initial response into a preset emotion generation model, and obtain at least two candidate responses that carry emotions output by the emotion generation model in response to the initial response.
将初始应答输入到预设的情感生成模型中, 获取情感生成模型输出的候选 应答, 预设的情感生成模型至少包含两个情感生成子模型, 可以将初始应答进 行情感转化。 例如, 将情感为中性的初始应答转为带积极情感的应答, 或将情 感为中性的初始应答转为带消极情感的应答。 Input the initial response into the preset emotion generation model to obtain the candidate responses output by the emotion generation model. The preset emotion generation model contains at least two emotion generation sub-models, which can transform the initial response into emotion. For example, changing the initial response with neutral emotion to a response with positive emotion, or changing the initial response with neutral emotion to a response with negative emotion.
任意一个情感生成子模型都基于预先训练的 Seq2Seq模型, 一个情感生成 子模型是一个 Seq2Seq模型, 输出一个携带情感的候选应答, 预设的情感生成 模型中的各 Seq2Seq模型由于训练语料不同, 生成情感因素不同, 所输出的携 带情感的候选应答也不同。 将初始应答输入到预设的情感生成模型中的各 Seq2Seq模型, 输出携带各种情感的候选应答。 值得注意的是, 这里用于情感生 成的 Seq2Seq模型区别于前述的用于生成初始应答的 Seq2Seq模型, 用于情感 生成的 Seq2Seq模型具体的训练过程请参见图 4。 Any emotion generation sub-model is based on the pre-trained Seq2Seq model. An emotion generation sub-model is a Seq2Seq model that outputs a candidate response that carries emotion. Each Seq2Seq model in the preset emotion generation model generates emotion due to different training corpus The factors are different, the output port Emotional candidate responses are also different. The initial response is input to each Seq2Seq model in the preset emotion generation model, and candidate responses carrying various emotions are output. It is worth noting that the Seq2Seq model used for emotion generation here is different from the aforementioned Seq2Seq model used for generating initial responses, and the specific training process of the Seq2Seq model used for emotion generation is shown in FIG. 4.
5104、 将所述候选应答和所述聊天语句输入到经过训练的深度强化学习网 络模型中, 获取各候选应答的深度强化学习值; S104. Input the candidate response and the chat sentence into a trained deep reinforcement learning network model to obtain a deep reinforcement learning value of each candidate response.
将生成的候选应答和用户输入的聊天语句都输入到经过训练的深度强化学 习网络模型中, 获取各候选应答的深度强化学习值。 深度强化学习网络将深度 学习网络的感知能力和强化学习网络的决策能力相结合, 通过计算各候选应答 的强化学习值来决策采用哪一个候选应答。 其中深度强化学习网络以下述损失 Both the generated candidate responses and the chat sentences input by the user are input into the trained deep learning network model to obtain the deep reinforcement learning value of each candidate response. The deep reinforcement learning network combines the perception ability of the deep learning network and the decision-making ability of the reinforcement learning network, and determines which candidate response to adopt by calculating the reinforcement learning value of each candidate response. Among them, the deep reinforcement learning network has the following loss
Figure imgf000008_0001
Figure imgf000008_0001
网络参数, Q为真实的深度强化学习值, 0为深度强化学习网络预测的深度强化 学习值。 Network parameters, Q is the true deep reinforcement learning value, and 0 is the deep reinforcement learning value predicted by the deep reinforcement learning network.
深度强化学习网络的训练过程为, 准备训练样本, 训练样本中的每一个样 本都包含输入的聊天语句及聊天语句对应的候选应答以及各候选应答的深度学 习值; 深度学习值根据预先设定的规则标注, 例如, 当针对聊天语句的某一候 选应答导致用户直接结束对话, 则将该候选应答的深度学习值低, 当针对聊天 语句的某一候选应答使用户下一轮输入的聊天语句的情感有积极的变化, 则将 该候选应答的深度学习值高。 The training process of the deep reinforcement learning network is to prepare training samples. Each sample in the training sample contains the input chat sentence and the candidate response corresponding to the chat sentence and the deep learning value of each candidate response; the deep learning value is based on the preset Rule labeling. For example, when a candidate response to a chat sentence causes the user to directly end the conversation, the deep learning value of the candidate response is low. When a candidate response to a chat sentence makes the user’s next chat sentence input If there is a positive change in emotion, the deep learning value of the candidate response is high.
将训练样本输入到深度强化学习网络模型, 获取深度强化学习网络模型预 测的深度强化学习值, 将深度强化学习网络模型预测的深度强化学习值和样本 实际的深度学习值代入到上述损失函数 L(w), 调整深度强化学习网络模型的网 络参数, 至 L(w)最小时结束。 Input the training samples to the deep reinforcement learning network model to obtain the deep reinforcement learning value predicted by the deep reinforcement learning network model, and substitute the deep reinforcement learning value predicted by the deep reinforcement learning network model and the actual deep learning value of the sample into the above loss function L( w), adjust the network parameters of the deep reinforcement learning network model, and end when L(w) is minimum.
5105、 返回深度强化学习值最大的候选应答作为所述聊天语句的应答语句。 深度强化学习值最大的候选应答认为是对当前用户输入的聊天语句的最合 适的答复, 将应答语句返回至客户终端, 通过终端的屏幕显示文本信息, 也可 以先对文本信息进行音频的转换, 通过终端的音频输出装置, 输出语言信息。 S105. Return the candidate response with the largest deep reinforcement learning value as the response sentence of the chat sentence. The candidate response with the largest deep reinforcement learning value is considered to be the most appropriate response to the chat sentence input by the current user. The response sentence is returned to the client terminal, and the text information is displayed on the terminal screen. The text information can also be converted to audio first. The audio output device of the terminal outputs language information.
如图 2所示, 所述预设的应答生成模型包含 M个应答生成子模型, M为大 于 1 的正整数, 在将所述聊天语句输入到预设的应答生成模型中, 获取初始应 答的步骤中, 包括下述步骤: As shown in Figure 2, the preset response generation model includes M response generation sub-models, where M is a positive integer greater than 1, and when the chat sentence is input into the preset response generation model, the initial response is obtained The steps in the answer include the following steps:
5111、 将所述聊天语句输入到预设的场景识别模型中, 获取所述场景识别 模型响应所述聊天语句而输出的场景; 5111. Input the chat sentence into a preset scene recognition model, and obtain a scene output by the scene recognition model in response to the chat sentence.
当机器聊天应用于多种场景时, 例如既应用于问题解答型场景, 又应用于 非问题解答型场景, 先对场景识别, 再根据场景确定对应的应答生成子模型, 可以使生成的应答更有针对性。 When machine chat is applied to a variety of scenarios, for example, it is applied to both the question answering scene and the non-question answering scene. The scene is first identified, and then the corresponding response is determined according to the scene to generate a sub-model, which can make the generated response more Targeted.
场景识别模型可以基于关键字, 判断是问题解答型场景还是非问题解答型 场景,可以通过判断输入的聊天语句中是否包含表示疑问的关键词,例如 “?”” 什么” “多少”“哪里”“怎么” 等表示疑问的语气词。 也可以采用正则匹配的 算法, 判断输入的聊天是否疑问句, 正则表达式是对字符串操作的一种逻辑公 式, 用事先定义好的一些特定字符、 及这些特定字符的组合, 组成一个“规则 字符串”, 这个“规则字符串” 用来表达对字符串的一种过滤逻辑。 The scene recognition model can be based on keywords to determine whether it is a problem-solving scene or a non-question-answering scene. It can be judged whether the input chat sentence contains keywords that express questions, such as "?" What" "How much" "Where" "How" and other interrogative particles. You can also use a regular matching algorithm to judge whether the chat is a question or not. A regular expression is a logical formula for string manipulation. It uses predefined specific characters and combinations of these specific characters to form a "regular character" String", this "rule string" is used to express a filtering logic for strings.
当输入的聊天语句不是疑问句, 则判断场景为非问题解答型场景。 识别出 是否为问题解答型场景, 进一步地, 可以细分场景, 例如非问题解答型下可细 分为闲聊、 赞赏、 吐槽; 问题解答型场景下细分为售前咨询、 售后服务等。 细 分的场景可以通过预设的关键词列表判断, 每一类细分场景, 预设一个关键词 列表, 当提取的输入聊天语句中的关键词与某类细分场景对应的关键词列表中 的词一致时, 认为输入聊天语句对应细分场景。 When the input chat sentence is not an interrogative sentence, it is judged that the scene is a non-question answering scene. Identify whether it is a problem-solving scene, and further, you can subdivide the scenes, for example, the non-problem-solving scene can be subdivided into small chat, appreciation, and complaints; the problem-solving scene can be subdivided into pre-sales consultation, after-sales service, etc. The segmented scenes can be judged by the preset keyword list. For each type of segmented scene, a keyword list is preset. When the extracted keywords in the input chat sentence are in the keyword list corresponding to a certain type of segmented scene When the words are the same, it is considered that the input chat sentence corresponds to the segmented scene.
在一些实施方式中通过预先训练的 LSTM-CNN神经网络模型进行场景识别。 具体地, 对输入的内容, 首先进行中文分词, 采用基本分词库, 依次进入去除 停用词、 标点符号等、 通过词向量模型获得词嵌入向量, 传入基于 LSTM-CNN 的神经网络模型。 即词嵌入向量, 进入多层 LSTM神经单元, 得到各个阶段的 状态向量和输出; 然后, 基于各个阶段的状态向量, 进行卷积操作和池化操作 (CNN) , 得到综合向量指标; 然后将综合向量指标输入 softmax函数, 得到对 应的场景的概率。 取概率最高的场景为输入聊天语句对应的场景。 In some embodiments, a pre-trained LSTM-CNN neural network model is used for scene recognition. Specifically, for the input content, the Chinese word segmentation is performed first, and the basic word segmentation database is used, and the stop words, punctuation marks, etc. are removed sequentially, and the word embedding vector is obtained through the word vector model, and then passed into the neural network model based on LSTM-CNN. That is, the word embedding vector enters the multi-layer LSTM neural unit to obtain the state vector and output of each stage; then, based on the state vector of each stage, perform convolution and pooling operations (CNN) to obtain the integrated vector index; then integrate The vector index is input into the softmax function to obtain the probability of the corresponding scene. The scene with the highest probability is selected as the scene corresponding to the input chat sentence.
5112、 根据所述场景, 确定与所述聊天语句对应的应答生成子模型; 应答生成模型预设了 M个应答生成子模型, 且应答生成子模型与场景具有 映射关系。 确定了输入的聊天语句的场景, 根据场景与应答生成子模型的映射 关系, 确定用户输入聊天语句对应的应答生成子模型。 S112. According to the scenario, determine a response generation submodel corresponding to the chat sentence; the response generation model presets M response generation submodels, and the response generation submodel has a mapping relationship with the scenario. The scene of the input chat sentence is determined, and the response generation sub-model corresponding to the user input chat sentence is determined according to the mapping relationship between the scene and the response generation sub-model.
本申请实施例中, 应答生成子模型与场景的映射关系为, 当场景为问题解 答型时, 使用问答知识库作为应答生成子模型, 当场景为非问题解答型时, 使 用经过训练的 Seq2Seq模型。 In the embodiment of this application, the mapping relationship between the response generation sub-model and the scene is that when the scene is a question answering type, the question and answer knowledge base is used as the response generation sub-model, and when the scene is a non-question answering type, Use the trained Seq2Seq model.
S 113、 将所述聊天语句输入到所述应答生成子模型中, 获取所述应答生成 子模型响应所述聊天语句而输出的初始应答。 S113. Input the chat sentence into the response generation sub-model, and obtain an initial response output by the response generation sub-model in response to the chat sentence.
将聊天语句输入到与场景对应的应答生成子模型中, 应答生成子模型响应 聊天语句输出初始应答。本申请实施例中, 当聊天语句对应非问题解答型场景, 初始应答通过 Seq2Seq模型生成, 具体的过程请参见 S 102的描述, 当聊天语句 对应问题解答型场景, 生成初始应答的过程请参见图 3。 Input the chat sentence into the response generation sub-model corresponding to the scene, and the response generation sub-model responds to the chat sentence to output the initial response. In the embodiment of this application, when the chat sentence corresponds to a non-question answering scenario, the initial response is generated by the Seq2Seq model. For the specific process, please refer to the description of S102. When the chat sentence corresponds to a question answering scenario, the process of generating the initial response is shown in Fig. 3.
如图 3 所示, 当聊天语句对应问题解答型场景, 确定与所述聊天语句对应 的应答生成子模型为问答知识库; 在 S 111中, 还包括下述步骤: As shown in Figure 3, when a chat sentence corresponds to a question answering scenario, it is determined that the response generation sub-model corresponding to the chat sentence is a question and answer knowledge base; in S111, the following steps are further included:
S 12K 将所述聊天语句进行分词, 得到所述聊天语句的关键词; S 12K segmentation of the chat sentence to obtain the keywords of the chat sentence;
本申请实施例中采用双向最大匹配法。 双向最大匹配方法是一种基于词典 的分词方法。 基于词典的分词方法是按照一定策略将待分析的汉字串与一个机 器词典中的词条进行匹配, 若在词典中找到某个字符串, 则匹配成功。 基于词 典的分词方法按照扫描方向的不同分为正向匹配和逆向匹配, 按照长度的不同 分为最大匹配和最小匹配。 双向最大匹配法是将正向最大匹配法得到的分词结 果和逆向最大匹配法的到的结果进行比较, 从而决定正确的分词方法。 根据研 究表明, 中文中 90.0%左右的句子, 正向最大匹配法和逆向最大匹配法完全重 合且正确, 只有大概 9.0%的句子两种切分方法得到的结果不一样, 但其中必有 一个是正确的, 只有不到 1.0%的句子, 或者正向最大匹配法和逆向最大匹配法 的切分虽重合却是错的, 即有歧义的, 或者正向最大匹配法和逆向最大匹配法 切分不同但两个都不对。 所以为了使切分出来的词汇能准确的反映句子的意思, 采用双向最大匹配法分词。 The two-way maximum matching method is adopted in the embodiment of this application. The two-way maximum matching method is a dictionary-based word segmentation method. The dictionary-based word segmentation method is to match the Chinese character string to be analyzed with the entry in a machine dictionary according to a certain strategy. If a certain character string is found in the dictionary, the matching is successful. The dictionary-based word segmentation method is divided into forward matching and reverse matching according to different scanning directions, and divided into maximum matching and minimum matching according to the difference in length. The two-way maximum matching method compares the word segmentation results obtained by the forward maximum matching method and the reverse maximum matching method to determine the correct word segmentation method. According to research, about 90.0% of the sentences in Chinese, the forward maximum matching method and the reverse maximum matching method are completely coincident and correct. Only about 9.0% of the sentences get different results from the two segmentation methods, but one of them must be Correct, only less than 1.0% of the sentences, or the segmentation of the forward maximum matching method and the reverse maximum matching method overlap but is wrong, that is, there is ambiguity, or the forward maximum matching method and the reverse maximum matching method segmentation Different but neither is right. Therefore, in order to make the segmented vocabulary accurately reflect the meaning of the sentence, the two-way maximum matching method is used for word segmentation.
对聊天语句进行分词后, 还可以将分词结果与预设的停用词表进行匹配, 去除停用词, 得到聊天语句的关键词。 After word segmentation is performed on the chat sentence, the word segmentation result can also be matched with a preset stop word list, the stop words are removed, and the keywords of the chat sentence are obtained.
5122、 根据所述关键词检索所述问答知识库, 得到与所述关键词匹配的检 索结果; S122. Search the question and answer knowledge base according to the keywords to obtain a search result matching the keywords.
根据关键词检索问答知识库, 得到与关键词匹配的检索结果。 根据关键词 检索问答知识库, 可以采用第三方的搜索引擎, 对问答知识库进行检索。 The Q&A knowledge base is searched according to keywords, and search results matching the keywords are obtained. To search the Q & A knowledge base based on keywords, a third-party search engine can be used to search the Q & A knowledge base.
5123、 返回所述检索结果作为所述聊天语句的初始应答。 S123. Return the search result as the initial response of the chat sentence.
通常通过关键词对问答知识库进行检索, 检索结果有多个, 本申请实施例 中确定检索结果中, 排名最前的结果作为聊天语句的初始应答。 如图 4所示, 情感生成模型基于 N个预先训练的 Seq2Seq模型, 每一个 Seq2Seq模型被训练后, 为初始应答添加不同的情感, 其中, 任一 Seq2Seq模型 的训练包括以下步骤: Generally, the Q&A knowledge base is retrieved by keywords, and there are multiple retrieval results. In the embodiment of the application, it is determined that among the retrieval results, the top ranked result is used as the initial response of the chat sentence. As shown in Figure 4, the emotion generation model is based on N pre-trained Seq2Seq models. After each Seq2Seq model is trained, different emotions are added to the initial response. The training of any Seq2Seq model includes the following steps:
S 13K 获取训练语料, 所述训练语料包含若干输入序列和输出序列对, 其 中, 所述输出序列为所述输入序列的指定情感类型的表达; S 13K: Obtain training corpus, the training corpus includes a number of input sequence and output sequence pairs, where the output sequence is the expression of the specified emotion type of the input sequence;
训练语料是若干的序列对, 包含输入序列和输出序列, 其中, 输出序列为 输入序列的指定情感类型的表达, 例如, 输入序列为中性的表达“今天天气晴、 气温 25度、空气质量指数 20”,预期的输出序列为积极的表达“今天天气很棒, 温度在舒适的 25度, 空气质量优良” 。 The training corpus is a number of sequence pairs, including an input sequence and an output sequence, where the output sequence is the expression of the specified emotion type of the input sequence, for example, the input sequence is a neutral expression "Today's weather is sunny, temperature is 25 degrees, air quality index 20", the expected output sequence is a positive expression "the weather is great today, the temperature is at a comfortable 25 degrees, and the air quality is good".
S 132、将所述输入序列输入到 Seq2Seq模型中,调整 Seq2Seq模型的参数, 使 Seq2Seq模型响应所述输入序列而输出所述输出序列的概率最大。 S132. Input the input sequence into the Seq2Seq model, and adjust the parameters of the Seq2Seq model so that the Seq2Seq model has the greatest probability of outputting the output sequence in response to the input sequence.
将训练语料中的输入序列输入到 Seq2Seq模型中, 通过梯度下降法, 调整 Seq2Seq模型各节点的参数,使 Seq2Seq模型输出预期的输出序列的概率最大时, 训练结束。此时得到的参数文件即定义了生成该指定情感类型的 Seq2Seq模型。 Input the input sequence in the training corpus into the Seq2Seq model, and adjust the parameters of each node of the Seq2Seq model through the gradient descent method to maximize the probability of the Seq2Seq model outputting the expected output sequence, the training ends. The parameter file obtained at this time defines the Seq2Seq model that generates the specified emotion type.
如图 5 所示, 本申请实施例中, 深度强化学习网络模型的训练通过下述步 骤进行训练: As shown in Figure 5, in this embodiment of the application, the training of the deep reinforcement learning network model is performed through the following steps:
5141、 获取训练样本, 所述训练样本中的每一个样本都包含输入的聊天语 句及聊天语句对应的候选应答及各候选应答的深度强化学习值; S141. Obtain training samples, where each sample in the training samples includes the input chat sentence and the candidate response corresponding to the chat sentence and the deep reinforcement learning value of each candidate response.
准备训练样本, 训练样本中的每一个样本都包含输入的聊天语句及聊天语 句对应的候选应答以及各候选应答的深度学习值; 深度学习值根据预先设定的 规则标注, 例如, 当针对聊天语句的某一候选应答导致用户直接结束对话, 则 将该候选应答的深度学习值低, 当针对聊天语句的某一候选应答使用户下一轮 输入的聊天语句的情感有积极的变化, 则将该候选应答的深度学习值高。 Prepare training samples. Each sample in the training sample contains the input chat sentence and the candidate response corresponding to the chat sentence and the deep learning value of each candidate response; the deep learning value is labeled according to preset rules, for example, If a candidate response of the user directly ends the dialogue, the deep learning value of the candidate response is low. When a candidate response to the chat sentence causes the user to enter the next round of chat sentences with a positive change in emotion, then the The candidate response has a high deep learning value.
5142、 将所述训练样本输入到深度强化学习网络模型, 获取所述深度强化 学习网络模型预测的深度强化学习值; S142: Input the training samples into a deep reinforcement learning network model, and obtain the deep reinforcement learning value predicted by the deep reinforcement learning network model.
将训练样本输入到深度强化学习网络模型, 获取深度强化学习网络模型预 测的深度强化学习值。 深度强化学习可以类比为监督学习, 深度强化学习任务 通常使用马尔可夫决策过程描述, 机器人处在一个环境中, 每个状态为机器人 对环境的感知。 当机器人执行一个动作后, 会使得环境按概率转移到另一个状 态; 同时, 环境会根据奖励函数给机器人。 Input the training samples into the deep reinforcement learning network model to obtain the deep reinforcement learning value predicted by the deep reinforcement learning network model. Deep reinforcement learning can be analogous to supervised learning. Deep reinforcement learning tasks are usually described by Markov decision process. The robot is in an environment, and each state is the robot's perception of the environment. When the robot performs an action, it will make the environment transfer to another state according to probability; at the same time, the environment will be given to the robot according to the reward function.
5143、 根据所述预测的深度学习值, 计算所述损失函数 L(w)的值; 将深度强化学习网络模型预测的深度强化学习值和样本实际的深度学习值 代入到上述损失函数 L(w), 计算损失函数的值。 S143: Calculate the value of the loss function L(w) according to the predicted deep learning value. Substitute the deep reinforcement learning value predicted by the deep reinforcement learning network model and the actual deep learning value of the sample into the above loss function L(w), and calculate the value of the loss function.
S 144、 调整深度强化学习网络模型的网络参数, 至所述损失函数 L(w)的值 最小时结束。 S144. Adjust the network parameters of the deep reinforcement learning network model until the value of the loss function L(w) is the smallest.
训练的目标是损失函数 L(w)收敛, 即当继续调整深度强化学习网络模型的 网络参数时, 损失函数的值不再减少, 反而增大时, 训练结束, 此时, 得到的 参数文件即为定义该深度强化学习网络模型的文件。 The goal of training is the convergence of the loss function L(w), that is, when the network parameters of the deep reinforcement learning network model are continuously adjusted, the value of the loss function no longer decreases, but increases instead, the training ends. At this time, the obtained parameter file is It is a file that defines the deep reinforcement learning network model.
为解决上述技术问题本申请实施例还提供一种带情感的机器聊天装置。 具 体请参阅图 6, 图 6为本实施例带情感的机器聊天装置的基本结构框图。 In order to solve the above technical problems, the embodiment of the present application also provides an emotional machine chat device. Please refer to Fig. 6 for details. Fig. 6 is a basic structural block diagram of an emotional machine chat device according to this embodiment.
如图 6所示, 一种带情感的机器聊天装置, 包括: 获取模块 210、 生成模块 220、 处理模块 230、 计算模块 240和执行模块 250。 其中, 获取模块 210, 用于 获取用户输入的聊天语句; 生成模块 220, 用于将所述聊天语句输入到预设的应 答生成模型中, 获取所述应答生成模型响应所述聊天语句而输出的初始应答; 处理模块 230, 用于将所述初始应答输入到预设的情感生成模型中, 获取所述情 感生成模型响应所述初始应答而输出的至少两个携带情感的候选应答; 计算模 块 240, 用于将所述候选应答和所述聊天语句输入到经过训练的深度强化学习网 络模型中, 获取各候选应答的深度强化学习值; 执行模块 250, 用于返回深度强 化学习值最大的候选应答作为所述聊天语句的应答语句。 As shown in FIG. 6, an emotional machine chat device includes: an acquisition module 210, a generation module 220, a processing module 230, a calculation module 240, and an execution module 250. Wherein, the obtaining module 210 is used to obtain the chat sentence input by the user; the generating module 220 is used to input the chat sentence into a preset response generation model, and obtain the output of the response generation model in response to the chat sentence Initial response; a processing module 230, configured to input the initial response into a preset emotion generation model, and obtain at least two emotion-carrying candidate responses output by the emotion generation model in response to the initial response; calculation module 240 , Used to input the candidate response and the chat sentence into the trained deep reinforcement learning network model to obtain the deep reinforcement learning value of each candidate response; the execution module 250 is used to return the candidate response with the largest deep reinforcement learning value As a response sentence of the chat sentence.
本申请实施例通过获取用户输入的聊天语句; 将所述聊天语句输入到预设 的应答生成模型中, 获取所述应答生成模型响应所述聊天语句而输出的初始应 答; 将所述初始应答输入到预设的情感生成模型中, 获取所述情感生成模型响 应所述初始应答而输出的至少两个携带情感的候选应答; 将所述候选应答和所 述聊天语句输入到经过训练的深度强化学习网络模型中, 获取各候选应答的深 度强化学习值; 返回深度强化学习值最大的候选应答作为所述聊天语句的应答 语句。 对用户输入的聊天语句, 返回带情感的答复, 使机器聊天更自然、 更人 性化。 The embodiment of the application obtains the chat sentence input by the user; inputs the chat sentence into a preset response generation model, and obtains the initial response output by the response generation model in response to the chat sentence; and input the initial response In a preset emotion generation model, obtain at least two candidate responses carrying emotions output by the emotion generation model in response to the initial response; input the candidate responses and the chat sentence into the trained deep reinforcement learning In the network model, the deep reinforcement learning value of each candidate response is obtained; and the candidate response with the largest deep reinforcement learning value is returned as the response sentence of the chat sentence. It returns emotional responses to the chat sentences entered by the user, making machine chat more natural and more humane.
在一些实施方式中, 所述生成模块包括: 第一识别子模块、 第一确认子模 块和第一生成子模块, 其中, 第一识别子模块, 用于将所述聊天语句输入到预 设的场景识别模型中, 获取所述场景识别模型响应所述聊天语句而输出的场景; 第一确认子模块, 用于根据所述场景, 确定与所述聊天语句对应的应答生成子 模型; 第一生成子模块, 用于将所述聊天语句输入到所述应答生成子模型中, 获取所述应答生成子模型响应所述聊天语句而输出的初始应答。 In some embodiments, the generation module includes: a first recognition sub-module, a first confirmation sub-module, and a first generation sub-module, wherein the first recognition sub-module is used to input the chat sentence into a preset In the scene recognition model, obtain the scene output by the scene recognition model in response to the chat sentence; a first confirmation sub-module, configured to determine a response generation sub-model corresponding to the chat sentence according to the scene; first generation A sub-module for inputting the chat sentence into the response generation sub-model, Acquire the initial response output by the response generation sub-model in response to the chat sentence.
在一些实施方式中, 所述第一识别子模块包括: 第一匹配子模块、 第二确 认子模块和第三确认子模块, 其中第一匹配子模块, 用于将所述聊天语句与预 设的正则表达式匹配, 其中, 所述预设的正则表达式包含疑问句特征; 第二确 认子模块, 用于当所述聊天语句与预设的正则表达式匹配时, 确定所述聊天语 句对应问题解答型场景; 第三确认子模块, 用于当所述聊天语句与预设的正则 表达式不匹配时, 确定所述聊天语句对应非问题解答型场景。 In some embodiments, the first recognition sub-module includes: a first matching sub-module, a second confirming sub-module, and a third confirming sub-module, wherein the first matching sub-module is configured to combine the chat sentence with a preset The regular expression matching of the chat sentence, where the preset regular expression contains the characteristics of the question sentence; the second confirmation sub-module is used to determine the question corresponding to the chat sentence when the chat sentence matches the preset regular expression Answering scenario; the third confirmation sub-module is used to determine that the chat sentence corresponds to a non-question answering scenario when the chat sentence does not match the preset regular expression.
在一些实施方式中, 所述第一生成子模块包括: 第一分词子模块、 第一检 索子模块和第一执行子模块, 其中, 第一分词子模块, 将所述聊天语句进行分 词, 得到所述聊天语句的关键词; 第一检索子模块, 用于根据所述关键词检索 所述问答知识库, 得到与所述关键词匹配的检索结果; 第一执行子模块, 用于 返回所述检索结果作为所述聊天语句的初始应答。 In some embodiments, the first generation submodule includes: a first word segmentation submodule, a first search submodule, and a first execution submodule, wherein the first word segmentation submodule performs word segmentation on the chat sentence to obtain Keywords of the chat sentence; a first search sub-module for searching the question and answer knowledge base according to the keywords to obtain search results that match the keywords; a first execution sub-module for returning the The search result is used as the initial response of the chat sentence.
在一些实施方式中,所述带情感的机器聊天装置中所述情感生成模型基于 N 个预先训练的 Seq2Seq模型, 所述带情感的机器聊天装置中还包括: 第一获取 子模块、 第一计算子模块, 其中, 第一获取子模块, 用于获取训练语料, 所述 训练语料包含若干输入序列和输出序列对, 其中, 所述输出序列为所述输入序 列的指定情感类型的表达; 第一计算子模块, 用于将所述输入序列输入到 Seq2Seq模型中, 调整 Seq2Seq模型的参数, 使 Seq2Seq模型响应所述输入序列 而输出所述输出序列的概率最大。 In some embodiments, the emotion generation model in the emotional machine chat device is based on N pre-trained Seq2Seq models, and the emotional machine chat device further includes: a first acquisition submodule, a first calculation A sub-module, wherein the first acquisition sub-module is used to acquire training corpus, the training corpus includes a number of input sequence and output sequence pairs, wherein the output sequence is the expression of the specified emotion type of the input sequence; first The calculation sub-module is configured to input the input sequence into the Seq2Seq model and adjust the parameters of the Seq2Seq model to maximize the probability of the Seq2Seq model outputting the output sequence in response to the input sequence.
在一些实施方式中, 所述带情感的机器聊天装置中所述深度强化学习网络 In some embodiments, the deep reinforcement learning network in the emotional machine chat device
Figure imgf000013_0001
Figure imgf000013_0001
网络参数, Q为真实的深度强化学习值, 0为深度强化学习网络预测的深度强化 学习值。 Network parameters, Q is the true deep reinforcement learning value, and 0 is the deep reinforcement learning value predicted by the deep reinforcement learning network.
在一些实施方式中,所述带情感的机器聊天装置还包括: 第二获取子模块、 第二计算子模块、 第三计算子模块和第一调节子模块, 其中, 第二获取子模块, 用于获取训练样本, 所述训练样本中的每一个样本都包含输入的聊天语句及聊 天语句对应的候选应答及各候选应答的深度强化学习值; 第二计算子模块, 用 于将所述训练样本输入到深度强化学习网络模型, 获取所述深度强化学习网络 模型预测的深度强化学习值; 第三计算子模块, 用于根据所述预测的深度学习 值, 计算所述损失函数 L(w)的值; 第一调节子模块, 用于调整深度强化学习网 络模型的网络参数, 至所述损失函数 L(w)的值最小时结束。 In some embodiments, the emotional machine chat device further includes: a second acquisition sub-module, a second calculation sub-module, a third calculation sub-module, and a first adjustment sub-module, wherein the second acquisition sub-module uses To obtain training samples, each of the training samples includes the input chat sentence and the candidate response corresponding to the chat sentence and the deep reinforcement learning value of each candidate response; the second calculation sub-module is used to combine the training sample Input to the deep reinforcement learning network model to obtain the deep reinforcement learning value predicted by the deep reinforcement learning network model; the third calculation sub-module is used for the deep learning according to the prediction Value, calculate the value of the loss function L(w); the first adjustment sub-module is used to adjust the network parameters of the deep reinforcement learning network model, and end when the value of the loss function L(w) is minimum.
为解决上述技术问题, 本申请实施例还提供计算机设备。 具体请参阅图 7, 图 7为本实施例计算机设备基本结构框图。 如图 7所示, 计算机设备的内部结构示意图。 如图 7所示, 该计算机设备 包括通过系统总线连接的处理器、 非易失性存储介质、 存储器和网络接口。 其 中, 该计算机设备的非易失性存储介质存储有操作系统、 数据库和计算机可读 指令, 数据库中可存储有控件信息序列, 该计算机可读指令被处理器执行时, 可使得处理器实现上述任意实施例的带情感的机器聊天的方法。 该计算机设备 的处理器用于提供计算和控制能力, 支撑整个计算机设备的运行。 该计算机设 备的存储器中可存储有计算机可读指令, 该计算机可读指令被处理器执行时, 可使得处理器执行一种带情感的机器聊天的方法。 该计算机设备的网络接口用 于与终端连接通信。 本领域技术人员可以理解, 图 7 中示出的结构, 仅仅是与 本申请方案相关的部分结构的框图, 并不构成对本申请方案所应用于其上的计 算机设备的限定, 具体的计算机设备可以包括比图中所示更多或更少的部件, 或者组合某些部件, 或者具有不同的部件布置。 To solve the above technical problems, the embodiments of the present application also provide computer equipment. Please refer to Fig. 7 for details. Fig. 7 is a block diagram of the basic structure of the computer device in this embodiment. As shown in Figure 7, a schematic diagram of the internal structure of the computer device. As shown in FIG. 7, the computer device includes a processor, a nonvolatile storage medium, a memory, and a network interface connected through a system bus. Wherein, the non-volatile storage medium of the computer device stores an operating system, a database, and computer-readable instructions. The database may store a control information sequence. When the computer-readable instructions are executed by the processor, the processor can make the processor implement the above Any embodiment of an emotional machine chat method. The processor of the computer device is used to provide calculation and control capabilities, and supports the operation of the entire computer device. Computer readable instructions may be stored in the memory of the computer device, and when the computer readable instructions are executed by the processor, the processor can make the processor execute an emotional machine chat method. The network interface of the computer equipment is used to connect and communicate with the terminal. Those skilled in the art can understand that the structure shown in FIG. 7 is only a block diagram of part of the structure related to the solution of the present application, and does not constitute a limitation on the computer equipment to which the solution of the present application is applied. The specific computer equipment may It includes more or less parts than shown in the figure, or combines some parts, or has a different part arrangement.
本实施方式中处理器用于执行图 6中获取模块 210、 生成模块 220、 处理模 块 230、 计算模块 240和执行模块 250的具体内容, 存储器存储有执行上述模块 所需的程序代码和各类数据。 网络接口用于向用户终端或服务器之间的数据传 输。 本实施方式中的存储器存储有带情感的机器聊天方法中执行所有子模块所 需的程序代码及数据, 服务器能够调用服务器的程序代码及数据执行所有子模 块的功能。 In this embodiment, the processor is used to execute the specific content of the acquisition module 210, the generation module 220, the processing module 230, the calculation module 240, and the execution module 250 in FIG. 6, and the memory stores the program codes and various data required to execute the above modules. The network interface is used for data transmission between user terminals or servers. The memory in this embodiment stores the program code and data required to execute all the sub-modules in the emotional machine chat method, and the server can call the program code and data of the server to execute the functions of all the sub-modules.
计算机设备通过获取用户输入的聊天语句; 将所述聊天语句输入到预设的 应答生成模型中, 获取所述应答生成模型响应所述聊天语句而输出的初始应答; 将所述初始应答输入到预设的情感生成模型中, 获取所述情感生成模型响应所 述初始应答而输出的至少两个携带情感的候选应答; 将所述候选应答和所述聊 天语句输入到经过训练的深度强化学习网络模型中, 获取各候选应答的深度强 化学习值; 返回深度强化学习值最大的候选应答作为所述聊天语句的应答语句。 对用户输入的聊天语句, 返回带情感的答复, 使机器聊天更自然、 更人性化。 The computer device obtains the chat sentence input by the user; inputs the chat sentence into a preset response generation model, obtains the initial response output by the response generation model in response to the chat sentence; and inputs the initial response to the pre- In the sentiment generation model, obtain at least two candidate responses carrying emotions output by the sentiment generation model in response to the initial response; input the candidate responses and the chat sentence into a trained deep reinforcement learning network model In the process, the deep reinforcement learning value of each candidate response is obtained; and the candidate response with the largest deep reinforcement learning value is returned as the response sentence of the chat sentence. It returns emotional responses to the chat sentences entered by the user, making machine chat more natural and humane.
本申请还提供一种存储有计算机可读指令的存储介质, 所述计算机可读指 令被一个或多个处理器执行时, 使得一个或多个处理器执行上述任一实施例所 The present application also provides a storage medium storing computer-readable instructions. When the computer-readable instructions are executed by one or more processors, the one or more processors can execute any of the foregoing

Claims

述带情感的机器聊天方法的步骤。 本领域普通技术人员可以理解实现上述实施例方法中的全部或部分流程, 是可以通过计算机程序来指令相关的硬件来完成, 该计算机程序可存储于一计 算机可读取存储介质中, 该程序在执行时, 可包括如上述各方法的实施例的流 程。其中,前述的存储介质可为磁碟、光盘、只读存储记忆体 (Read-Only Memory, ROM)等非易失性存储介质,或随机存储记忆体 (Random Access Memory, RAM) 等。 应该理解的是, 虽然附图的流程图中的各个步骤按照箭头的指示依次显示, 但是这些步驟并不是必然按照箭头指示的顺序依次执行。 除非本文中有明确的 说明, 这些步骤的执行并没有严格的顺序限制, 其可以以其他的顺序执行。 而 且, 附图的流程图中的至少一部分步骤可以包括多个子步骤或者多个阶段, 这 些子步骤或者阶段并不必然是在同一时刻执行完成, 而是可以在不同的时刻执 行, 其执行顺序也不必然是依次进行, 而是可以与其他步骤或者其他步骤的子 步騍或者阶段的至少一部分轮流或者交替地执行。 以上所述仅是本申请的部分实施方式, 应当指出, 对于本技术领域的普通 技术人员来说, 在不脱离本申请原理的前提下, 还可以做出若干改进和润饰, 这些改进和润饰也应视为本申请的保护范围。 权 利 要 求 书 Describe the steps of an emotional machine chat method. A person of ordinary skill in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be implemented by instructing relevant hardware through a computer program. The computer program can be stored in a computer readable storage medium. During execution, it may include the procedures of the above-mentioned method embodiments. The aforementioned storage medium may be a non-volatile storage medium such as a magnetic disk, an optical disc, a read-only memory (Read-Only Memory, ROM), or a random access memory (Random Access Memory, RAM), etc. It should be understood that, although the various steps in the flowchart of the drawings are displayed in sequence as indicated by the arrows, these steps are not necessarily performed in sequence in the order indicated by the arrows. Unless specifically stated in this article, the execution of these steps is not strictly restricted in order, and they can be executed in other orders. Moreover, at least a part of the steps in the flowchart of the drawings may include multiple sub-steps or multiple stages. These sub-steps or stages are not necessarily executed at the same time, but can be executed at different times, and the order of execution is also It is not necessarily performed sequentially, but may be performed alternately or alternately with at least a part of other steps or sub-steps or stages of other steps. The above are only part of the implementation of this application. It should be pointed out that for those of ordinary skill in the art, without departing from the principle of this application, several improvements and modifications can be made, and these improvements and modifications are also Should be regarded as the scope of protection of this application. Claims
1、 一种带情感的机器聊天方法, 其特征在于, 包括下述步骤: 1. An emotional machine chat method, characterized in that it includes the following steps:
获取用户输入的聊天语句; Get the chat sentence entered by the user;
将所述聊天语句输入到预设的应答生成模型中, 获取所述应答生成模型响 应所述聊天语句而输出的初始应答; Input the chat sentence into a preset response generation model, and obtain an initial response output by the response generation model in response to the chat sentence;
将所述初始应答输入到预设的情感生成模型中, 获取所述情感生成模型响 应所述初始应答而输出的至少两个携带情感的候选应答; Inputting the initial response into a preset emotion generation model, and obtaining at least two candidate responses carrying emotions output by the emotion generation model in response to the initial response;
将所述候选应答和所述聊天语句输入到经过训练的深度强化学习网络模型 中, 获取各候选应答的深度强化学习值; Input the candidate response and the chat sentence into a trained deep reinforcement learning network model to obtain the deep reinforcement learning value of each candidate response;
返回深度强化学习值最大的候选应答作为所述聊天语句的应答语句。 The candidate response with the largest deep reinforcement learning value is returned as the response sentence of the chat sentence.
2、 根据权利要求 1所述的带情感的机器聊天方法, 其特征在于, 所述预设 的应答生成模型包含至少两个应答生成子模型, 在将所述聊天语句输入到预设 的应答生成模型中, 获取初始应答的步骤中, 包括下述步骤: 2. The emotional machine chat method according to claim 1, wherein the preset response generation model includes at least two response generation sub-models, and the chat sentence is input into the preset response generation model. In the model, the step of obtaining the initial response includes the following steps:
将所述聊天语句输入到预设的场景识别模型中, 获取所述场景识别模型响 应所述聊天语句而输出的场景; Input the chat sentence into a preset scene recognition model, and obtain the scene output by the scene recognition model in response to the chat sentence;
根据所述场景, 确定与所述聊天语句对应的应答生成子模型; According to the scenario, determine a response generation sub-model corresponding to the chat sentence;
将所述聊天语句输入到所述应答生成子模型中, 获取所述应答生成子模型 响应所述聊天语句而输出的初始应答。 Input the chat sentence into the response generation sub-model, and obtain the initial response output by the response generation sub-model in response to the chat sentence.
3、 根据权利要求 2所述的带情感的机器聊天方法, 其特征在于, 预设的场 景识别模型采用正则匹配算法, 在所述将所述聊天语句输入到预设的场景识别 模型中, 获取所述场景识别模型响应所述聊天语句而输出的场景的步骤中, 包 括下述步骤: 3. The emotional machine chat method according to claim 2, wherein the preset scene recognition model adopts a regular matching algorithm, and in said inputting the chat sentence into the preset scene recognition model, The step of the scene that the scene recognition model outputs in response to the chat sentence includes the following steps:
将所述聊天语句与预设的正则表达式匹配, 其中, 所述预设的正则表达式 包含疑问句特征; Matching the chat sentence with a preset regular expression, where the preset regular expression includes interrogative sentence features;
当所述聊天语句与预设的正则表达式匹配时, 确定所述聊天语句对应问题 解答型场景; When the chat sentence matches the preset regular expression, it is determined that the chat sentence corresponds to a question answering scenario;
当所述聊天语句与预设的正则表达式不匹配时, 确定所述聊天语句对应非 问题解答型场景。 When the chat sentence does not match the preset regular expression, it is determined that the chat sentence corresponds to a non-question-solving scene.
4、 根据权利要求 3所述的带情感的机器聊天方法, 其特征在于, 所述根据 所述场景, 确定与所述聊天语句对应的应答生成子模型的步騍为: 根据问题解答型场景, 确定与所述聊天语句对应的应答生成子模型为问答 知识库; 4. The emotional machine chat method according to claim 3, wherein the step of determining the response generation sub-model corresponding to the chat sentence according to the scene is: According to the question answering scenario, determining that the response generation sub-model corresponding to the chat sentence is a question and answer knowledge base;
在所述将所述聊天语句输入到所述应答生成子模型中, 获取所述应答生成 子模型响应所述聊天语句而输出的初始应答的步騍中, 包括下述步騍: The steps of inputting the chat sentence into the response generation sub-model and obtaining the initial response output by the response generation sub-model in response to the chat sentence include the following steps:
将所述聊天语句进行分词, 得到所述聊天语句的关键词; Word segmentation of the chat sentence to obtain keywords of the chat sentence;
根据所述关键词检索所述问答知识库, 得到与所述关键词匹配的检索结果; 返回所述检索结果作为所述聊天语句的初始应答。 Retrieve the question and answer knowledge base according to the keywords to obtain retrieval results matching the keywords; and return the retrieval results as the initial response of the chat sentence.
5、 根据权利要求 1所述的带情感的机器聊天方法, 其特征在于, 所述情感 生成模型基于 N个预先训练的 Seq2Seq模型, 其中, 任一 Seq2Seq模型的训练 包括以下步骤: 5. The emotional machine chat method according to claim 1, wherein the emotion generation model is based on N pre-trained Seq2Seq models, wherein the training of any Seq2Seq model includes the following steps:
获取训练语料, 所述训练语料包含若干输入序列和输出序列对, 其中, 所 述输出序列为所述输入序列的指定情感类型的表达; Acquiring a training corpus, the training corpus including a number of input sequence and output sequence pairs, where the output sequence is an expression of a specified emotion type of the input sequence;
将所述输入序列输入到 Seq2Seq 模型中, 调整 Seq2Seq 模型的参数, 使 Seq2Seq模型响应所述输入序列而输出所述输出序列的概率最大。 The input sequence is input into the Seq2Seq model, and the parameters of the Seq2Seq model are adjusted so that the Seq2Seq model has the greatest probability of outputting the output sequence in response to the input sequence.
6、 根据权利要求 1所述的带情感的机器聊天方法, 其特征在于, 所述深度 6. The emotional machine chat method according to claim 1, wherein the depth
Figure imgf000017_0001
Figure imgf000017_0001
网络参数, Q为真实的深度强化学习值, 0为深度强化学习网络预测的深度强化 学习值。 Network parameters, Q is the true deep reinforcement learning value, and 0 is the deep reinforcement learning value predicted by the deep reinforcement learning network.
7、 根据权利要求 6所述的带情感的机器聊天方法, 其特征在于, 所述深度 强化学习网络模型的训练通过下述步骤进行训练: 7. The emotional machine chat method according to claim 6, characterized in that the training of the deep reinforcement learning network model is performed through the following steps:
获取训练样本, 所述训练样本中的每一个样本都包含输入的聊天语句及聊 天语句对应的候选应答及各候选应答的深度强化学习值; Acquiring training samples, each of the training samples includes the input chat sentence and the candidate response corresponding to the chat sentence and the deep reinforcement learning value of each candidate response;
将所述训练样本输入到深度强化学习网络模型, 获取所述深度强化学习网 络模型预测的深度强化学习值; Inputting the training samples into a deep reinforcement learning network model to obtain the deep reinforcement learning value predicted by the deep reinforcement learning network model;
根据所述预测的深度学习值, 计算所述损失函数 L( w)的值; Calculating the value of the loss function L(w) according to the predicted deep learning value;
调整深度强化学习网络模型的网络参数, 至所述损失函数 L(w)的值最小时 结束。 Adjust the network parameters of the deep reinforcement learning network model until the value of the loss function L(w) is minimum.
8、 一种带情感的机器聊天装置, 其特征在于, 包括: 8. An emotional machine chat device, characterized in that it comprises:
获取模块, 用于获取用户输入的聊天语句; 生成模块, 用于将所述聊天语句输入到预设的应答生成模型中, 获取所述 应答生成模型响应所述聊天语句而输出的初始应答; Obtaining module, used to obtain chat sentences input by the user; A generating module, configured to input the chat sentence into a preset response generation model, and obtain an initial response output by the response generation model in response to the chat sentence;
处理模块, 用于将所述初始应答输入到预设的情感生成模型中, 获取所述 情感生成模型响应所述初始应答而输出的至少两个携带情感的候选应答; A processing module, configured to input the initial response into a preset emotion generation model, and obtain at least two candidate responses that carry emotion that are output by the emotion generation model in response to the initial response;
计算模块, 用于将所述候选应答和所述聊天语句输入到经过训练的深度强 化学习网络模型中, 获取各候选应答的深度强化学习值; A calculation module, configured to input the candidate response and the chat sentence into a trained deep-strength learning network model to obtain the deep-strength learning value of each candidate response;
执行模块, 用于返回深度强化学习值最大的候选应答作为所述聊天语句的 应答语句。 The execution module is used to return the candidate response with the largest deep reinforcement learning value as the response sentence of the chat sentence.
9、 根据权利要求 8所述的带情感的机器聊天装置, 其特征在于, 所述生成 模块包括: 9. The emotional machine chat device according to claim 8, wherein the generating module comprises:
第一识别子模块, 用于将所述聊天语句输入到预设的场景识别模型中, 获 取所述场景识别模型响应所述聊天语句而输出的场景; The first recognition sub-module is configured to input the chat sentence into a preset scene recognition model, and obtain a scene output by the scene recognition model in response to the chat sentence;
第一确认子模块, 用于根据所述场景, 确定与所述聊天语句对应的应答生 成子模型; The first confirmation sub-module is configured to determine the response generation sub-model corresponding to the chat sentence according to the scenario;
第一生成子模块, 用于将所述聊天语句输入到所述应答生成子模型中, 获 取所述应答生成子模型响应所述聊天语句而输出的初始应答。 The first generation sub-module is configured to input the chat sentence into the response generation sub-model, and obtain the initial response output by the response generation sub-model in response to the chat sentence.
10、 根据权利要求 9所述的带情感的机器聊天装置, 其特征在于, 所述第 一识别子模块包括: 10. The emotional machine chat device according to claim 9, wherein the first recognition sub-module comprises:
第一匹配子模块, 用于将所述聊天语句与预设的正则表达式匹配, 其中, 所述预设的正则表达式包含疑问句特征; The first matching sub-module is configured to match the chat sentence with a preset regular expression, where the preset regular expression includes interrogative sentence features;
第二确认子模块, 用于当所述聊天语句与预设的正则表达式匹配时, 确定 所述聊天语句对应问题解答型场景; The second confirmation sub-module is used to determine that the chat sentence corresponds to a problem-solving scenario when the chat sentence matches a preset regular expression;
第三确认子模块, 用于当所述聊天语句与预设的正则表达式不匹配时, 确 定所述聊天语句对应非问题解答型场景。 The third confirmation sub-module is used for determining that the chat sentence corresponds to a non-question answering scene when the chat sentence does not match the preset regular expression.
11、 一种计算机设备, 包括存储器和处理器, 所述存储器中存储有计算机 可读指令, 所述计算机可读指令被所述处理器执行时, 使得所述处理器实现以 下步骤: 获取用户输入的聊天语句; 11. A computer device comprising a memory and a processor, wherein computer-readable instructions are stored in the memory, and when the computer-readable instructions are executed by the processor, the processor implements the following steps: obtaining user input Chat sentence;
将所述聊天语句输入到预设的应答生成模型中, 获取所述应答生成模型响 应所述聊天语句而输出的初始应答; Input the chat sentence into a preset response generation model, and obtain an initial response output by the response generation model in response to the chat sentence;
将所述初始应答输入到预设的情感生成模型中, 获取所述情感生成模型响 应所述初始应答而输出的至少两个携带情感的候选应答; Input the initial response into a preset emotion generation model to obtain the emotion generation model response At least two candidate responses carrying emotions output in response to the initial response;
将所述候选应答和所述聊天语句输入到经过训练的深度强化学习网络模型 中, 获取各候选应答的深度强化学习值; Input the candidate response and the chat sentence into a trained deep reinforcement learning network model to obtain the deep reinforcement learning value of each candidate response;
返回深度强化学习值最大的候选应答作为所述聊天语句的应答语句。 The candidate response with the largest deep reinforcement learning value is returned as the response sentence of the chat sentence.
12、 根据权利要求 11所述的计算机设备, 其特征在于, 所述预设的应答生 成模型包含至少两个应答生成子模型, 在将所述聊天语句输入到预设的应答生 成模型中, 获取初始应答的步骤中, 包括下述步骤: 12. The computer device according to claim 11, wherein the preset response generation model includes at least two response generation sub-models, and the chat sentence is input into the preset response generation model to obtain The initial response steps include the following steps:
将所述聊天语句输入到预设的场景识别模型中, 获取所述场景识别模型响 应所述聊天语句而输出的场景; Input the chat sentence into a preset scene recognition model, and obtain the scene output by the scene recognition model in response to the chat sentence;
根据所述场景, 确定与所述聊天语句对应的应答生成子模型; According to the scenario, determine a response generation sub-model corresponding to the chat sentence;
将所述聊天语句输入到所述应答生成子模型中, 获取所述应答生成子模型 响应所述聊天语句而输出的初始应答。 Input the chat sentence into the response generation sub-model, and obtain the initial response output by the response generation sub-model in response to the chat sentence.
13、 根据权利要求 12所述的计算机设备, 其特征在于, 预设的场景识别模 型采用正则匹配算法, 在所述将所述聊天语句输入到预设的场景识别模型中, 获取所述场景识别模型响应所述聊天语句而输出的场景的步骤中, 包括下述步 骤: 13. The computer device according to claim 12, wherein the preset scene recognition model uses a regular matching algorithm, and in said inputting the chat sentence into the preset scene recognition model, the scene recognition is obtained The steps of the scenario output by the model in response to the chat sentence include the following steps:
将所述聊天语句与预设的正则表达式匹配, 其中, 所述预设的正则表达式 包含疑问句特征; Matching the chat sentence with a preset regular expression, where the preset regular expression includes interrogative sentence features;
当所述聊天语句与预设的正则表达式匹配时, 确定所述聊天语句对应问题 解答型场景; When the chat sentence matches the preset regular expression, it is determined that the chat sentence corresponds to a question answering scenario;
当所述聊天语句与预设的正则表达式不匹配时, 确定所述聊天语句对应非 问题解答型场景。 When the chat sentence does not match the preset regular expression, it is determined that the chat sentence corresponds to a non-question-solving scene.
14、根据权利要求 12所述的计算机设备,其特征在于,所述根据所述场景, 确定与所述聊天语句对应的应答生成子模型的步骤为: 14. The computer device of claim 12, wherein the step of determining a response generation sub-model corresponding to the chat sentence according to the scenario is:
根据问题解答型场景, 确定与所述聊天语句对应的应答生成子模型为问答 知识库; According to the question answering scenario, determining that the response generation sub-model corresponding to the chat sentence is a question and answer knowledge base;
在所述将所述聊天语句输入到所述应答生成子模型中, 获取所述应答生成 子模型响应所述聊天语句而输出的初始应答的步騍中, 包括下述步騍: The steps of inputting the chat sentence into the response generation sub-model and obtaining the initial response output by the response generation sub-model in response to the chat sentence include the following steps:
将所述聊天语句进行分词, 得到所述聊天语句的关键词; Word segmentation of the chat sentence to obtain keywords of the chat sentence;
根据所述关键词检索所述问答知识库, 得到与所述关键词匹配的检索结果; 返回所述检索结果作为所述聊天语句的初始应答。 Retrieve the question and answer knowledge base according to the keywords to obtain retrieval results matching the keywords; and return the retrieval results as the initial response of the chat sentence.
15、 根据权利要求 11所述的计算机设备, 其特征在于, 所述情感生成模型 基于 N个预先训练的 Seq2Seq模型, 其中, 任一 Seq2Seq模型的训练包括以下 步骤: 15. The computer device according to claim 11, wherein the emotion generation model is based on N pre-trained Seq2Seq models, wherein the training of any Seq2Seq model includes the following steps:
获取训练语料, 所述训练语料包含若干输入序列和输出序列对, 其中, 所 述输出序列为所述输入序列的指定情感类型的表达; Acquiring a training corpus, the training corpus including a number of input sequence and output sequence pairs, where the output sequence is an expression of a specified emotion type of the input sequence;
将所述输入序列输入到 Seq2Seq 模型中, 调整 Seq2Seq 模型的参数, 使 Seq2Seq模型响应所述输入序列而输出所述输出序列的概率最大。 The input sequence is input into the Seq2Seq model, and the parameters of the Seq2Seq model are adjusted so that the Seq2Seq model has the greatest probability of outputting the output sequence in response to the input sequence.
16、 一种计算机可读存储介质, 所述计算机可读存储介质上存储有计算机 可读指令, 所述计算机可读指令被处理器执行时实现以下步骤: 16. A computer-readable storage medium having computer-readable instructions stored thereon, and when the computer-readable instructions are executed by a processor, the following steps are implemented:
获取用户输入的聊天语句; Get the chat sentence entered by the user;
将所述聊天语句输入到预设的应答生成模型中, 获取所述应答生成模型响 应所述聊天语句而输出的初始应答; Input the chat sentence into a preset response generation model, and obtain an initial response output by the response generation model in response to the chat sentence;
将所述初始应答输入到预设的情感生成模型中, 获取所述情感生成模型响 应所述初始应答而输出的至少两个携带情感的候选应答; Inputting the initial response into a preset emotion generation model, and obtaining at least two candidate responses carrying emotions output by the emotion generation model in response to the initial response;
将所述候选应答和所述聊天语句输入到经过训练的深度强化学习网络模型 中, 获取各候选应答的深度强化学习值; Input the candidate response and the chat sentence into a trained deep reinforcement learning network model to obtain the deep reinforcement learning value of each candidate response;
返回深度强化学习值最大的候选应答作为所述聊天语句的应答语句。 The candidate response with the largest deep reinforcement learning value is returned as the response sentence of the chat sentence.
17、 根据权利要求 16所述的计算机可读存介质, 其特征在于, 所述预设的 应答生成模型包含至少两个应答生成子模型, 在将所述聊天语句输入到预设的 应答生成模型中, 获取初始应答的步骤中, 包括下述步骤: 17. The computer-readable storage medium according to claim 16, wherein the preset response generation model includes at least two response generation sub-models, and the chat sentence is input into the preset response generation model In the step of obtaining the initial response, the following steps are included:
将所述聊天语句输入到预设的场景识别模型中, 获取所述场景识别模型响 应所述聊天语句而输出的场景; Input the chat sentence into a preset scene recognition model, and obtain the scene output by the scene recognition model in response to the chat sentence;
根据所述场景, 确定与所述聊天语句对应的应答生成子模型; According to the scenario, determine a response generation sub-model corresponding to the chat sentence;
将所述聊天语句输入到所述应答生成子模型中, 获取所述应答生成子模型 响应所述聊天语句而输出的初始应答。 Input the chat sentence into the response generation sub-model, and obtain the initial response output by the response generation sub-model in response to the chat sentence.
18、 根据权利要求 17所述的计算机可读存介质, 其特征在于, 预设的场景 识别模型采用正则匹配算法, 在所述将所述聊天语句输入到预设的场景识别模 型中, 获取所述场景识别模型响应所述聊天语句而输出的场景的步骤中, 包括 下述步骤: 18. The computer-readable storage medium according to claim 17, wherein the preset scene recognition model adopts a regular matching algorithm, and in the input of the chat sentence into the preset scene recognition model, all The step of the scene that the scene recognition model outputs in response to the chat sentence includes the following steps:
将所述聊天语句与预设的正则表达式匹配, 其中, 所述预设的正则表达式 包含疑问句特征; 当所述聊天语句与预设的正则表达式匹配时, 确定所述聊天语句对应问题 解答型场景; Matching the chat sentence with a preset regular expression, where the preset regular expression includes interrogative sentence features; When the chat sentence matches a preset regular expression, it is determined that the chat sentence corresponds to a question answering scenario;
当所述聊天语句与预设的正则表达式不匹配时, 确定所述聊天语句对应非 问题解答型场景。 When the chat sentence does not match the preset regular expression, it is determined that the chat sentence corresponds to a non-question-solving scene.
19、 根据权利要求 18所述的计算机可读存介质, 其特征在于, 所述根据所 述场景, 确定与所述聊天语句对应的应答生成子模型的步騍为: 19. The computer-readable storage medium according to claim 18, wherein the step of determining the response generation sub-model corresponding to the chat sentence according to the scenario is:
根据问题解答型场景, 确定与所述聊天语句对应的应答生成子模型为问答 知识库; According to the question answering scenario, determining that the response generation sub-model corresponding to the chat sentence is a question and answer knowledge base;
在所述将所述聊天语句输入到所述应答生成子模型中, 获取所述应答生成 子模型响应所述聊天语句而输出的初始应答的步騍中, 包括下述步騍: The steps of inputting the chat sentence into the response generation sub-model and obtaining the initial response output by the response generation sub-model in response to the chat sentence include the following steps:
将所述聊天语句进行分词, 得到所述聊天语句的关键词; Word segmentation of the chat sentence to obtain keywords of the chat sentence;
根据所述关键词检索所述问答知识库, 得到与所述关键词匹配的检索结果; 返回所述检索结果作为所述聊天语句的初始应答。 Retrieve the question and answer knowledge base according to the keywords to obtain retrieval results matching the keywords; and return the retrieval results as the initial response of the chat sentence.
20、 根据权利要求 18所述的计算机可读存介质, 其特征在于, 所述情感生 成模型基于 N个预先训练的 Seq2Seq模型, 其中, 任一 Seq2Seq模型的训练包 括以下步骤: 20. The computer-readable storage medium according to claim 18, wherein the emotion generation model is based on N pre-trained Seq2Seq models, wherein the training of any Seq2Seq model includes the following steps:
获取训练语料, 所述训练语料包含若干输入序列和输出序列对, 其中, 所 述输出序列为所述输入序列的指定情感类型的表达; Acquiring a training corpus, the training corpus including a number of input sequence and output sequence pairs, where the output sequence is an expression of a specified emotion type of the input sequence;
将所述输入序列输入到 Seq2Seq 模型中, 调整 Seq2Seq 模型的参数, 使 Seq2Seq模型响应所述输入序列而输出所述输出序列的概率最大。 The input sequence is input into the Seq2Seq model, and the parameters of the Seq2Seq model are adjusted so that the Seq2Seq model has the greatest probability of outputting the output sequence in response to the input sequence.
PCT/CN2019/103516 2019-01-28 2019-08-30 Method and apparatus for chatting with machine with sentiment, computer device and storage medium WO2020155619A1 (en)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201910081989.6A CN109977201B (en) 2019-01-28 2019-01-28 Machine chat method and device with emotion, computer equipment and storage medium
CN201910081989.6 2019-01-28

Publications (1)

Publication Number Publication Date
WO2020155619A1 true WO2020155619A1 (en) 2020-08-06

Family

ID=67076749

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2019/103516 WO2020155619A1 (en) 2019-01-28 2019-08-30 Method and apparatus for chatting with machine with sentiment, computer device and storage medium

Country Status (2)

Country Link
CN (1) CN109977201B (en)
WO (1) WO2020155619A1 (en)

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112163078A (en) * 2020-09-29 2021-01-01 彩讯科技股份有限公司 Intelligent response method, device, server and storage medium
CN112560447A (en) * 2020-12-22 2021-03-26 联想(北京)有限公司 Reply information acquisition method and device and computer equipment
CN113360614A (en) * 2021-05-31 2021-09-07 多益网络有限公司 Method, device, terminal and medium for controlling reply emotion of generating type chat robot

Families Citing this family (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109977201B (en) * 2019-01-28 2023-09-22 平安科技(深圳)有限公司 Machine chat method and device with emotion, computer equipment and storage medium
CN110717022A (en) * 2019-09-18 2020-01-21 平安科技(深圳)有限公司 Robot dialogue generation method and device, readable storage medium and robot
CN112750430A (en) * 2019-10-29 2021-05-04 微软技术许可有限责任公司 Providing responses in automatic chat
CN111241250B (en) * 2020-01-22 2023-10-24 中国人民大学 Emotion dialogue generation system and method
CN111400466A (en) * 2020-03-05 2020-07-10 中国工商银行股份有限公司 Intelligent dialogue method and device based on reinforcement learning
CN111553171B (en) * 2020-04-09 2024-02-06 北京小米松果电子有限公司 Corpus processing method, corpus processing device and storage medium
CN111985216A (en) * 2020-08-25 2020-11-24 武汉长江通信产业集团股份有限公司 Emotional tendency analysis method based on reinforcement learning and convolutional neural network
CN113094490B (en) * 2021-05-13 2022-11-22 度小满科技(北京)有限公司 Session interaction method and device, electronic equipment and storage medium

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20140324429A1 (en) * 2013-04-25 2014-10-30 Elektrobit Automotive Gmbh Computer-implemented method for automatic training of a dialogue system, and dialogue system for generating semantic annotations
CN108874972A (en) * 2018-06-08 2018-11-23 青岛里奥机器人技术有限公司 A kind of more wheel emotion dialogue methods based on deep learning
CN108960402A (en) * 2018-06-11 2018-12-07 上海乐言信息科技有限公司 A kind of mixed strategy formula emotion towards chat robots pacifies system
CN109129501A (en) * 2018-08-28 2019-01-04 西安交通大学 A kind of company formula Intelligent household central control robot
CN109977201A (en) * 2019-01-28 2019-07-05 平安科技(深圳)有限公司 Machine chat method, device, computer equipment and storage medium with emotion

Family Cites Families (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN104809103B (en) * 2015-04-29 2018-03-30 北京京东尚科信息技术有限公司 A kind of interactive semantic analysis and system
CN106910513A (en) * 2015-12-22 2017-06-30 微软技术许可有限责任公司 Emotional intelligence chat engine
JP6660770B2 (en) * 2016-03-02 2020-03-11 株式会社アイ・ビジネスセンター Dialogue systems and programs
US11580350B2 (en) * 2016-12-21 2023-02-14 Microsoft Technology Licensing, Llc Systems and methods for an emotionally intelligent chat bot
CN110674270B (en) * 2017-08-28 2022-01-28 大国创新智能科技(东莞)有限公司 Humorous generation and emotion interaction method based on artificial intelligence and robot system
CN107679234B (en) * 2017-10-24 2020-02-11 上海携程国际旅行社有限公司 Customer service information providing method, customer service information providing device, electronic equipment and storage medium

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20140324429A1 (en) * 2013-04-25 2014-10-30 Elektrobit Automotive Gmbh Computer-implemented method for automatic training of a dialogue system, and dialogue system for generating semantic annotations
CN108874972A (en) * 2018-06-08 2018-11-23 青岛里奥机器人技术有限公司 A kind of more wheel emotion dialogue methods based on deep learning
CN108960402A (en) * 2018-06-11 2018-12-07 上海乐言信息科技有限公司 A kind of mixed strategy formula emotion towards chat robots pacifies system
CN109129501A (en) * 2018-08-28 2019-01-04 西安交通大学 A kind of company formula Intelligent household central control robot
CN109977201A (en) * 2019-01-28 2019-07-05 平安科技(深圳)有限公司 Machine chat method, device, computer equipment and storage medium with emotion

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112163078A (en) * 2020-09-29 2021-01-01 彩讯科技股份有限公司 Intelligent response method, device, server and storage medium
CN112560447A (en) * 2020-12-22 2021-03-26 联想(北京)有限公司 Reply information acquisition method and device and computer equipment
CN113360614A (en) * 2021-05-31 2021-09-07 多益网络有限公司 Method, device, terminal and medium for controlling reply emotion of generating type chat robot

Also Published As

Publication number Publication date
CN109977201A (en) 2019-07-05
CN109977201B (en) 2023-09-22

Similar Documents

Publication Publication Date Title
WO2020155619A1 (en) Method and apparatus for chatting with machine with sentiment, computer device and storage medium
WO2020177282A1 (en) Machine dialogue method and apparatus, computer device, and storage medium
CN111914551B (en) Natural language processing method, device, electronic equipment and storage medium
US11068474B2 (en) Sequence to sequence conversational query understanding
CN111966800B (en) Emotion dialogue generation method and device and emotion dialogue model training method and device
CN113505205A (en) System and method for man-machine conversation
CN111428010B (en) Man-machine intelligent question-answering method and device
CN112528637B (en) Text processing model training method, device, computer equipment and storage medium
CN109857865B (en) Text classification method and system
CN111191450A (en) Corpus cleaning method, corpus entry device and computer-readable storage medium
CN114840671A (en) Dialogue generation method, model training method, device, equipment and medium
US11314951B2 (en) Electronic device for performing translation by sharing context of utterance and operation method therefor
CN114596844A (en) Acoustic model training method, voice recognition method and related equipment
CN112214592A (en) Reply dialogue scoring model training method, dialogue reply method and device
CN111797220A (en) Dialog generation method and device, computer equipment and storage medium
CN116384405A (en) Text processing method, text classification method and emotion recognition method
WO2020151318A1 (en) Corpus construction method and apparatus based on crawler model, and computer device
CN116913278B (en) Voice processing method, device, equipment and storage medium
CN117272937B (en) Text coding model training method, device, equipment and storage medium
CN116776870B (en) Intention recognition method, device, computer equipment and medium
CN113421551B (en) Speech recognition method, speech recognition device, computer readable medium and electronic equipment
CN116737888B (en) Training method of dialogue generation model and method and device for determining reply text
CN115952852B (en) Model training method, text retrieval method, device, electronic equipment and medium
CN117807181A (en) Text processing method, object searching method and training method of text processing model
CN117455009A (en) Federal learning method, federal prediction method, apparatus, device, and storage medium

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 19912414

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 19912414

Country of ref document: EP

Kind code of ref document: A1