







技术领域technical field
本申请实施例涉及通信技术领域,尤其涉及一种对话回复方法、装置、通信设备及可读存储介质。The embodiments of the present application relate to the technical field of communication, and in particular, to a dialog reply method, device, communication device, and readable storage medium.
背景技术Background technique
人机对话系统由于其广泛的应用,具有较高的商业价值。人机对话系统中最为重要的一个动作为对话回复动作,也即根据预计传达给用户相关讯息的待回复信息,生成符合人类语言习惯的回复语句,并将该回复语句下发至用户端。Human-computer dialogue system has high commercial value due to its wide application. One of the most important actions in the human-computer dialogue system is the dialogue reply action, which is to generate a reply sentence that conforms to human language habits according to the expected reply information that is expected to be conveyed to the user, and send the reply sentence to the client.
目前,相关技术多采用人工设计回复模板的方式来完成上述回复生成动作,即先通过特定领域专家人工设计用于对话回复的若干个回复模板,再根据前述待回复信息对若干个回复模板进行检索,以获得适配于待回复信息的回复模板,之后根据该回复模板对前述待回复信息进行处理,以生成并下发最终的回复语句。At present, related technologies mostly use manual design of reply templates to complete the above-mentioned reply generation action, that is, experts in specific fields manually design several reply templates for dialogue replies, and then retrieve several reply templates according to the aforementioned information to be replied , to obtain a reply template adapted to the message to be replied, and then process the aforementioned message to be replied according to the reply template to generate and issue a final reply sentence.
应用中发现,相关技术在回复模板生成阶段的效率较低,即在生成回复语句之前,相关技术需安排特定领域专家反复斟酌话术,以完成对应的回复模板设计工作,此过程较为费时。In the application, it was found that the efficiency of related technologies in the reply template generation stage is low, that is, before generating reply sentences, related technologies need to arrange experts in specific fields to repeatedly consider the words to complete the corresponding reply template design work, and this process is time-consuming.
发明内容Contents of the invention
本申请实施例提供一种对话回复方法、装置、通信设备及可读存储介质,以解决相关技术在回复模板生成阶段的效率较低的问题。Embodiments of the present application provide a dialogue reply method, device, communication device, and readable storage medium, so as to solve the problem of low efficiency in the stage of reply template generation in related technologies.
为解决上述问题,本申请是这样实现的:In order to solve the above problems, the application is implemented as follows:
第一方面,本申请实施例提供了一种对话回复方法,所述方法包括:In the first aspect, the embodiment of the present application provides a dialogue reply method, the method comprising:
根据预训练的小样本学习模型对回复语料进行识别,获得至少一个第一回复模板;Identifying the reply corpus according to the pre-trained small-sample learning model to obtain at least one first reply template;
在所述至少一个第一回复模板中将与待回复信息匹配程度最高的第一回复模板确定为目标回复模板;Determining, among the at least one first reply template, the first reply template with the highest matching degree with the information to be replied as the target reply template;
将所述待回复信息填入所述目标回复模板,生成第一回复语句;Filling the information to be replied into the target reply template to generate a first reply sentence;
将所述第一回复语句下发至用户端。Send the first reply statement to the client.
在一些实施方式中,所述根据预训练的小样本学习模型对回复语料进行识别,获得至少一个第一回复模板,包括:In some embodiments, the reply corpus is identified according to the pre-trained small-sample learning model, and at least one first reply template is obtained, including:
对所述回复语料进行拆分处理,获得至少两个字组;Splitting and processing the reply corpus to obtain at least two word groups;
在所述至少两个字组中识别不变字组和增广字组;identifying an invariant word and an augmented word among the at least two words;
根据预设的词汇表对所述增广字组进行增广处理;performing augmentation processing on the augmented word group according to a preset vocabulary;
对所述不变字组和增广处理后的所述增广字组进行拼接,获得所述至少一个第一回复模板。Splicing the invariant word group and the augmented word group after augmentation processing to obtain the at least one first reply template.
在一些实施方式中,所述对所述不变字组和增广处理后的所述增广字组进行拼接,获得所述至少一个第一回复模板,包括:In some embodiments, the splicing of the invariant word group and the augmented word group after augmentation processing to obtain the at least one first reply template includes:
对所述不变字组和增广处理后的所述增广字组进行拼接,获得初始模板集合,所述初始模板集合包括至少一个初始模板;Splicing the invariant word group and the augmented word group after augmentation processing to obtain an initial template set, the initial template set including at least one initial template;
对所述初始模板集合进行聚类处理,获得所述至少一个第一回复模板。Perform clustering processing on the initial template set to obtain the at least one first reply template.
在一些实施方式中,所述对所述初始模板集合进行聚类处理,获得所述至少一个第一回复模板,包括:In some implementations, the performing clustering processing on the initial template set to obtain the at least one first reply template includes:
循环判断所述初始模板集合是否为空集,并在所述初始模板集合不为空集的情况下,获取所述初始模板集合中的质心模板,并将所述质心模板确定为所述第一回复模板,所述质心模板为所述初始模板集合中的任意一个初始模板;Circularly judge whether the initial template set is an empty set, and if the initial template set is not an empty set, obtain the centroid template in the initial template set, and determine the centroid template as the first Reply template, the centroid template is any initial template in the initial template set;
根据所述质心模板在所述初始模板集合中进行聚类处理,获得以所述质心模板为聚类中心的类簇;performing clustering processing in the initial template set according to the centroid template to obtain clusters with the centroid template as the cluster center;
在所述初始模板集合中删除所述类簇包括的初始模板。The initial template included in the class cluster is deleted from the initial template set.
在一些实施方式中,在所述将所述待回复信息填入所述目标回复模板,生成第一回复语句之后,所述方法还包括:In some embodiments, after filling the information to be replied into the target reply template and generating the first reply sentence, the method further includes:
根据迁移学习模型对所述第一回复语句进行调整,生成第二回复语句;adjusting the first reply sentence according to the transfer learning model to generate a second reply sentence;
所述将所述第一回复语句下发至用户端,包括:The sending the first reply statement to the client includes:
将所述第二回复语句下发至所述用户端。sending the second reply statement to the client.
在一些实施方式中,在根据小样本学习模型对回复语料进行识别,获得至少一个第一回复模板之后;在根据待回复信息检索所述至少一个第一回复模板之前;所述方法还包括:In some implementations, after identifying the reply corpus according to the small-sample learning model and obtaining at least one first reply template; before retrieving the at least one first reply template according to the information to be replied; the method further includes:
在所述至少一个第一回复模板中滤除包括有敏感词的第一回复模板,获得至少一个第二回复模板;Filtering out the first reply templates containing sensitive words in the at least one first reply template to obtain at least one second reply template;
所述根据待回复信息检索所述至少一个第一回复模板,并在所述至少一个第一回复模板中将与所述待回复信息匹配程度最高的第一回复模板确定为目标回复模板,包括:The retrieving the at least one first reply template according to the information to be replied, and determining the first reply template with the highest matching degree with the information to be replied among the at least one first reply templates as the target reply template includes:
根据待回复信息检索所述至少一个第二回复模板,并在所述至少一个第二回复模板中将与所述待回复信息匹配程度最高的第二回复模板确定为目标回复模板。Retrieving the at least one second reply template according to the information to be replied, and determining the second reply template with the highest degree of matching with the information to be replied among the at least one second reply templates as the target reply template.
在一些实施方式中,所述根据预训练的小样本学习模型对回复语料进行识别之前,所述方法还包括:In some embodiments, before identifying the reply corpus according to the pre-trained small-sample learning model, the method further includes:
获取根据小样本学习算法创建的初始模型;Obtain the initial model created according to the few-shot learning algorithm;
通过预设的训练样本对所述初始模型进行训练,所述训练样本包括待进行增广处理的字组和待保持不变的字组;The initial model is trained by preset training samples, the training samples include word groups to be augmented and word groups to be kept unchanged;
将训练好的初始模型确定为所述小样本学习模型。The trained initial model is determined as the small sample learning model.
第二方面,本申请实施例提供了一种对话回复装置,包括:In the second aspect, the embodiment of the present application provides a dialog reply device, including:
模板构建模块,用于根据预训练的小样本学习模型对回复语料进行识别,获得至少一个第一回复模板;A template building module, used to identify the reply corpus according to the pre-trained small-sample learning model, and obtain at least one first reply template;
检索模块,用于在所述至少一个第一回复模板中将与待回复信息匹配程度最高的第一回复模板确定为目标回复模板;A retrieval module, configured to determine, among the at least one first reply template, the first reply template that most closely matches the information to be replied as the target reply template;
语句生成模块,用于将所述待回复信息填入所述目标回复模板,生成第一回复语句;A sentence generating module, configured to fill in the target reply template with the information to be replied, and generate a first reply sentence;
回复模块,用于将所述第一回复语句下发至用户端。A reply module, configured to deliver the first reply statement to the client.
第三方面,本申请实施例还提供一种通信设备,包括:收发机、存储器、处理器及存储在所述存储器上并可在所述处理器上运行的程序;其特征在于,所述处理器,用于读取存储器中的程序实现如前述第一方面所述方法中的步骤。In the third aspect, the embodiment of the present application also provides a communication device, including: a transceiver, a memory, a processor, and a program stored in the memory and operable on the processor; it is characterized in that the processing The device is used to read the program in the memory to implement the steps in the method described in the aforementioned first aspect.
第四方面,本申请实施例还提供一种可读存储介质,用于存储程序,所述程序被处理器执行时实现如前述第一方面所述方法中的步骤。In a fourth aspect, the embodiment of the present application further provides a readable storage medium for storing a program, and when the program is executed by a processor, the steps in the method described in the aforementioned first aspect are implemented.
在本申请实施例中,提供了一种对话回复方法、装置、通信设备及可读存储介质,该方法包括:根据预训练的小样本学习模型对回复语料进行识别,获得至少一个第一回复模板;在所述至少一个第一回复模板中将与待回复信息匹配程度最高的第一回复模板确定为目标回复模板;将所述待回复信息填入所述目标回复模板,生成第一回复语句;将所述第一回复语句下发至用户端。利用小样本学习模型识别回复语料的方式,来替换相关技术所采用的人工设计回复模板的方式,以提高回复模板生成阶段的效率,降低回复模板的生成成本,同时使回复模板的生成过程具备可扩展性,以适配人机对话系统在业务增广或业务迁移过程中的需求变化。In the embodiment of the present application, a dialog reply method, device, communication device and readable storage medium are provided, the method includes: identifying the reply corpus according to the pre-trained small-sample learning model, and obtaining at least one first reply template ; In the at least one first reply template, the first reply template with the highest matching degree with the information to be replied is determined as the target reply template; the information to be replied is filled into the target reply template, and a first reply statement is generated; Send the first reply statement to the client. Using the small-sample learning model to identify the reply corpus to replace the manual design of reply templates used in related technologies, so as to improve the efficiency of the reply template generation stage, reduce the generation cost of reply templates, and make the reply template generation process more reliable. Scalability to adapt to the changing demands of the man-machine dialogue system during business expansion or business migration.
附图说明Description of drawings
为了更清楚地说明本申请实施例的技术方案,下面将对本申请实施例描述中所需要使用的附图作简单地介绍,显而易见地,下面描述中的附图仅仅是本申请的一些实施例,对于本领域普通技术人员来讲,在不付出创造性劳动性的前提下,还可以根据这些附图获得其他的附图。In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings that need to be used in the description of the embodiments of the present application will be briefly introduced below. Obviously, the drawings in the following description are only some embodiments of the present application. For those skilled in the art, other drawings can also be obtained based on these drawings without any creative effort.
图1是本申请实施例提供的对话回复方法的流程示意图之一;Fig. 1 is one of the schematic flow charts of the dialog reply method provided by the embodiment of the present application;
图2是本申请实施例提供的应用于服务器端的对话回复的流程示意图之一;Fig. 2 is one of the schematic flow diagrams of the dialog reply applied to the server provided by the embodiment of the present application;
图3是本申请实施例提供的应用于服务器端的对话回复的流程示意图之二;Fig. 3 is the second schematic flow diagram of dialogue reply applied to the server provided by the embodiment of the present application;
图4是本申请实施例提供的应用于服务器端的模板库构建的流程示意图;Fig. 4 is a schematic flow diagram of the template library construction applied to the server provided by the embodiment of the present application;
图5是本申请实施例提供的应用于服务器端的字组分类的流程示意图;FIG. 5 is a schematic flow diagram of word group classification applied to the server side provided by the embodiment of the present application;
图6是本申请实施例提供的应用于服务器端的回复语句生成的流程示意图;FIG. 6 is a schematic flow diagram of the generation of reply sentences applied to the server side provided by the embodiment of the present application;
图7是本申请实施提供的对话回复装置的结构示意图;Fig. 7 is a schematic structural diagram of the dialogue reply device provided by the implementation of the present application;
图8是本申请实施提供的通信设备的结构示意图。Fig. 8 is a schematic structural diagram of a communication device provided by the implementation of the present application.
具体实施方式Detailed ways
下面将结合本申请实施例中的附图,对本申请实施例中的技术方案进行清楚、完整地描述,显然,所描述的实施例是本申请一部分实施例,而不是全部的实施例。根据本申请中的实施例,本领域普通技术人员在没有作出创造性劳动前提下所获得的所有其他实施例,都属于本申请保护的范围。The following will clearly and completely describe the technical solutions in the embodiments of the present application with reference to the drawings in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, not all of them. According to the embodiments in the present application, all other embodiments obtained by persons of ordinary skill in the art without making creative efforts belong to the protection scope of the present application.
本申请实施例中的术语“第一”、“第二”等是用于区别类似的对象,而不必用于描述特定的顺序或先后次序。此外,术语“包括”和“具有”以及他们的任何变形,意图在于覆盖不排他的包含,例如,包含了一系列步骤或单元的过程、方法、系统、产品或设备不必限于清楚地列出的那些步骤或单元,而是可包括没有清楚地列出的或对于这些过程、方法、产品或设备固有的其它步骤或单元。此外,本申请中使用“和/或”表示所连接对象的至少其中之一,例如A和/或B和/或C,表示包含单独A,单独B,单独C,以及A和B都存在,B和C都存在,A和C都存在,以及A、B和C都存在的7种情况。The terms "first", "second" and the like in the embodiments of the present application are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. Furthermore, the terms "comprising" and "having", as well as any variations thereof, are intended to cover a non-exclusive inclusion, for example, a process, method, system, product or device comprising a sequence of steps or elements is not necessarily limited to the expressly listed instead, may include other steps or elements not explicitly listed or inherent to the process, method, product or apparatus. In addition, the use of "and/or" in this application means at least one of the connected objects, such as A and/or B and/or C, means that A alone, B alone, C alone, and both A and B exist, Both B and C exist, both A and C exist, and there are 7 situations where A, B, and C all exist.
以下对本申请实施例提供的一种对话回复方法、装置、通信设备及可读存储介质进行说明。A dialog reply method, device, communication device, and readable storage medium provided in the embodiments of the present application are described below.
参见图1,图1是本申请实施例提供的对话回复方法的流程示意图之一,如图1所示,对话回复方法可以包括以下步骤:Referring to Fig. 1, Fig. 1 is one of the flow diagrams of the dialogue reply method provided by the embodiment of the present application. As shown in Fig. 1, the dialogue reply method may include the following steps:
步骤101、根据预训练的小样本学习模型对回复语料进行识别,获得至少一个第一回复模板。Step 101: Identify the reply corpus according to the pre-trained small-sample learning model, and obtain at least one first reply template.
步骤102、在所述至少一个第一回复模板中将与待回复信息匹配程度最高的第一回复模板确定为目标回复模板。
步骤103、将所述待回复信息填入所述目标回复模板,生成第一回复语句。
步骤104、将所述第一回复语句下发至用户端。
示例性的,人机对话系统可以包括用户端和服务器端,用户通过所述用户端与服务器端进行对话交流,举例来说,前述待回复信息的获取过程可以为:Exemplarily, the man-machine dialogue system may include a client and a server, and the user communicates with the server through the client. For example, the process of obtaining the aforementioned information to be replied may be:
用户通过用户端向服务器传输问询语句(如查询餐厅信息等),服务器在接收到该问询语句之后,会通过预设的处理模型对该问询语句进行语义识别,并输出识别结果,该识别结果即为前述待回复信息。其中,所述识别结果可理解为用于答复前述问询语句的若干个对话动作,每一对话动作由对话意图(如“通知”)、任务领域(如“餐馆”)、槽(如“价格”)和值(如“100元”)组成。前述处理模型可以为全卷积网络(Fully Convolutional Networks,FCN),也可以为图卷积网络(Graph Convolutional Network,GCN),还可以为其他具备语义识别功能的网络模型,本申请实施例对此并不加以限定。The user transmits an inquiry statement (such as querying restaurant information, etc.) to the server through the client terminal. After receiving the inquiry statement, the server will perform semantic recognition on the inquiry statement through a preset processing model and output the recognition result. The recognition result is the aforementioned information to be replied. Wherein, the recognition result can be understood as several dialogue actions used to answer the aforementioned inquiry sentence, each dialogue action consists of dialogue intent (such as "notification"), task field (such as "restaurant"), slot (such as "price") ") and a value (such as "100 yuan"). The aforementioned processing model can be a fully convolutional network (Fully Convolutional Networks, FCN), or a graph convolutional network (Graph Convolutional Network, GCN), or other network models with semantic recognition functions. Not limited.
如上所述,利用小样本学习模型识别回复语料的方式,来替换相关技术所采用的人工设计回复模板的方式,以提高回复模板生成阶段的效率,降低回复模板的生成成本,同时利用小样本学习模型能基于较少数量的样本(如前述回复语料)快速生成第一回复模板的特点,来提升对话回复方法的泛化性能,以更好地适配人机对话系统出现业务增广或业务迁移的需求变化,同时降低复杂场景(指业务增广场景或业务迁移场景)下的第一回复模板的生成成本。As mentioned above, the method of using the small sample learning model to identify the reply corpus is used to replace the manual design of reply templates used in related technologies, so as to improve the efficiency of the reply template generation stage, reduce the generation cost of reply templates, and use small sample learning The model can quickly generate the first reply template based on a small number of samples (such as the aforementioned reply corpus), so as to improve the generalization performance of the dialogue reply method, so as to better adapt to the business expansion or business migration of the human-machine dialogue system changes in demand, while reducing the generation cost of the first reply template in a complex scenario (referring to a business augmentation scenario or a business migration scenario).
示例性的,前述业务增广场景可理解为,在现有业务为餐厅寻址业务时,额外增设如酒店寻址业务、药店寻址业务等新的业务的情况;前述业务迁移业务场景也理解为,将现有业务由餐厅寻址业务变更为商品查询业务的情况。Exemplarily, the aforementioned business augmentation scenario can be understood as, when the existing business is restaurant addressing service, additional new services such as hotel addressing service and pharmacy addressing service are added; the aforementioned business migration business scenario can also be understood For the case of changing the existing business from restaurant addressing business to commodity inquiry business.
需要说明的是,所述回复语料可理解为,适配人机对话系统的现有业务场景需求的人工回复语句集,该人工回复语句集可以来源于网络(如通过检索现有业务场景需求而获得的回复语句)或已有数据库(如在人机对话系统上线前,数据库所留存的历史回复语句)等,本申请实施例对此并不加以限定。It should be noted that the reply corpus can be understood as a set of manual reply sentences that adapt to the existing business scenario requirements of the man-machine dialogue system. Reply sentences obtained) or existing databases (such as historical reply sentences retained in the database before the man-machine dialogue system goes online), etc., are not limited in this embodiment of the present application.
如上所述,在待回复信息存在若干个对话动作的情况下,目标回复模板的数量也将对应存在若干个。示例性的,在所述至少一个第一回复模板中将与待回复信息匹配程度最高的第一回复模板确定为目标回复模板的过程可以为:As mentioned above, in the case that there are several dialog actions in the message to be replied, there will also be several corresponding target reply templates. Exemplarily, the process of determining, among the at least one first reply template, the first reply template that most closely matches the information to be replied as the target reply template may be as follows:
遍历所述至少一个第一回复模板和待回复信息中的若干个对话动作,并计算第一回复模板与对话动作之间的匹配程度;在上述遍历过程结束之后,将与每一对话动作匹配程度最高的第一回复模板确定为该对话动作的目标回复模板。Traverse the at least one first reply template and several dialogue actions in the information to be replied, and calculate the matching degree between the first reply template and the dialogue action; after the above-mentioned traversal process ends, the matching degree with each dialogue action The highest first reply template is determined as the target reply template of the dialogue action.
在前述示例基础上,若设定第一回复模板包括意图标签和待填入字组数量,则计算第一回复模板与对话动作之间的匹配程度的过程可以为:On the basis of the foregoing examples, if the first reply template is set to include the intent label and the number of words to be filled in, the process of calculating the matching degree between the first reply template and the dialog action can be:
对第一回复模板的意图标签和对话动作的对话意图之间的一致程度进行判断,并生成第一判断结果;Judging the degree of consistency between the intent tag of the first reply template and the dialog intent of the dialog action, and generating a first judgment result;
对第一回复模板的待填入字组数量和对话动作的实际字组数量之间的一致程度进行判断,并生成第二判断结果;Judging the degree of consistency between the number of words to be filled in the first reply template and the actual number of words in the dialogue action, and generating a second judgment result;
基于第一判断结果和第二判断结果,生成第一回复模板和对话动作之间的匹配值(也即前述匹配程度)。Based on the first judgment result and the second judgment result, a matching value (that is, the aforementioned matching degree) between the first reply template and the dialogue action is generated.
其中,第一判断结果包括第一值和第二值,所述第一值用于表征第一回复模板的意图标签和对话动作的对话意图相同(如两者均为“通知”的情况),所述第二值用于表征第一回复模板的意图标签和对话动作的对话意图不同(如意图标签为“通知”,对话意图为“告知”的情况),举例来说,第一值可以为1,第二值可以为0。Wherein, the first judgment result includes a first value and a second value, and the first value is used to indicate that the intent label of the first reply template is the same as the dialogue intent of the dialogue action (such as the case where both are "notification"), The second value is used to indicate that the intent tag of the first reply template is different from the dialog intent of the dialog action (such as the situation where the intent tag is "notification" and the dialog intent is "inform"). For example, the first value can be 1, the second value can be 0.
第二判断结果包括第三值和第四值,所述第三值用于表征对第一回复模板的待填入字组数量和对话动作的实际字组数量相同(如两者均为“4”的情况下),所述第四值用于表征对第一回复模板的待填入字组数量和对话动作的实际字组数量不同(如待填入字组数量为“3”,实际字组数量为“2”的情况),举例来说,第一值可以为0.2,第二值可以为0.1;所述实际字组数量可理解为对话动作中除对话意图外不为空的字组数量,举例来说,若某一对话动作的对话意图、任务领域、槽和值分别为“通知”、“餐馆”、“空”、“空”,则该对话动作的实际字组数量为1。The second judgment result includes a third value and a fourth value, and the third value is used to represent that the number of words to be filled in the first reply template is the same as the actual number of words in the dialogue action (such as both being "4 "), the fourth value is used to indicate that the number of words to be filled in the first reply template is different from the actual number of words in the dialogue action (such as the number of words to be filled is "3", the actual number of words The number of groups is "2"), for example, the first value can be 0.2, and the second value can be 0.1; the actual number of words can be understood as the words in the dialogue action that are not empty except for the dialogue intention Quantity, for example, if the dialogue intent, task field, slot and value of a certain dialogue action are "notification", "restaurant", "empty", "empty" respectively, then the actual number of words of the dialogue action is 1 .
在上述示例基础上,前述生成匹配值的过程可理解为计算第一判断结果和第二判断结果之和的过程。Based on the above example, the aforementioned process of generating a matching value can be understood as a process of calculating the sum of the first judgment result and the second judgment result.
需要说明的是,除上述示例外,还可以通过语义匹配模型计算第一回复模板和对话动作之间的匹配程度,所述语义匹配模型可以为深层结构化语义模型(Deep StructuredSemantic Models,DSSM)等,本申请实施例对第一回复模板和对话动作之间的匹配程度的具体计算方式和具体计算模型均不加以限定。It should be noted that, in addition to the above example, the degree of matching between the first reply template and the dialogue action can also be calculated through a semantic matching model, and the semantic matching model can be a deep structured semantic model (Deep Structured Semantic Models, DSSM) etc. , the embodiment of the present application does not limit the specific calculation method and the specific calculation model of the matching degree between the first reply template and the dialog action.
可选的,所述根据预训练的小样本学习模型对回复语料进行识别,获得至少一个第一回复模板,包括:Optionally, identifying the reply corpus according to the pre-trained small-sample learning model to obtain at least one first reply template, including:
对所述回复语料进行拆分处理,获得至少两个字组;Splitting and processing the reply corpus to obtain at least two word groups;
在所述至少两个字组中识别不变字组和增广字组;identifying an invariant word and an augmented word among the at least two words;
根据预设的词汇表对所述增广字组进行增广处理;performing augmentation processing on the augmented word group according to a preset vocabulary;
对所述不变字组和增广处理后的所述增广字组进行拼接,获得所述至少一个第一回复模板。Splicing the invariant word group and the augmented word group after augmentation processing to obtain the at least one first reply template.
上述回复语料包括若干个回复语句,所述对回复语料进行拆分处理,获得至少两个字组具体为,对回复语料包括的若干个回复语句逐一进行拆分处理,以获得每一回复语句包括的至少两个字组。The above-mentioned reply corpus includes several reply sentences, and the said reply corpus is split and processed to obtain at least two word groups. At least two word groups of .
后续对每一回复语句包括的至少两个字组均进行识别、增广处理和字组拼接,以生成与回复语句对应的第一回复模板,即回复语料包括的回复语句的数量和第一回复模板的数量相同,且两者一一对应。Subsequently, at least two word groups included in each reply sentence are identified, augmented and word groups are spliced to generate a first reply template corresponding to the reply sentence, that is, the number of reply sentences included in the reply corpus and the first reply The number of templates is the same, and there is a one-to-one correspondence between the two.
优选的,还可以在所述至少两个字组中识别删除字组,其中,删除字组可理解为回复语句中待删除的字组,不变字组可理解为回复语句中待保留不变的字组,增广字组可理解为回复语句中待增广的字组。Preferably, the deleted word group can also be identified in the at least two word groups, wherein the deleted word group can be understood as the word group to be deleted in the reply sentence, and the unchanged word group can be understood as the word group to be retained in the reply sentence The augmented word group can be understood as the word group to be augmented in the reply sentence.
示例性的,所述根据词汇表对增广字组进行增广处理可以为,将词汇表中的字组和增广字组进行关联,并基于关联结果将词汇表中的字组补充至增广字组前,以获得增广处理后的增广字组。举例来说,若设定增广字组为“的”,词汇表的字组分别为“不过为你”和“您要求”,如上所述,所获得的关联结果为“您要求-的”,其中,“-”为关联标记,基于该关联结果获得的增广处理后的增广字组为“您要求的”。Exemplarily, the augmentation processing of the augmented word group according to the vocabulary may be associating the word group in the vocabulary with the augmented word group, and supplementing the word group in the vocabulary to the augmented word group based on the association result. Before the wide word group, to obtain the augmented word group after the augmentation processing. For example, if the augmented word group is set to "的", the word groups in the vocabulary are "just for you" and "your request", as mentioned above, the obtained association result is "your request-of" , where "-" is the association mark, and the augmented word group obtained based on the association result is "what you requested".
其中,前述关联操作可理解为,遍历词汇表中的所有字组,并计算所遍历字组与增广字组之间的语义相似程度,最后通过前述关联标记将语义相似程度最高的字组与增广字组进行关联,以生成所述关联结果。Among them, the aforementioned associative operation can be understood as traversing all the word groups in the vocabulary, and calculating the degree of semantic similarity between the traversed word groups and the augmented word groups, and finally combining the word group with the highest degree of semantic similarity with The augmented word groups are associated to generate the association result.
如上所述,小样本学习模型的功能包括:语料拆分功能(如将回复语料或回复语句拆解为若干个字组)、字组识别功能(如在若干个字组中识别不变字组和增广字组)、字组增广功能(如基于词汇表对增广字组进行增广处理)、字组拼接功能(如将增广处理后的字组和不变字组进行拼接,以形成第一回复模板)。As mentioned above, the functions of the small-sample learning model include: corpus splitting function (such as dismantling the reply corpus or reply sentence into several word groups), word group recognition function (such as identifying invariant word groups in several word groups) and augmented word group), word group augmentation function (such as augmenting the augmented word group based on the vocabulary), word group splicing function (such as splicing the augmented word group and the unchanged word group, to form the first reply template).
示例性的,在语料拆分过程中,还可以记录字组在回复语料中的次序,以便于之后基于所记录的次序进行字组拼接,以提高字组拼接效率和准确性。举例来说,若回复语料为“没有找到餐馆”,其中“没有”(次序1)“找到”(次序2)均为不变字组,“餐馆”(次序3)为增广字组,词汇表中适配“餐馆”的字组为“您要求的”,则基于小样本学习模型对该回复语料进行处理,并基于前述次序所形成的第一回复模板为“没有找到您要求的餐馆”。Exemplarily, during the splitting process of the corpus, the order of the word groups in the reply corpus can also be recorded, so that word groups can be spliced based on the recorded order later, so as to improve the efficiency and accuracy of word group splicing. For example, if the reply corpus is "no restaurant found", wherein "no" (order 1) and "found" (order 2) are all invariant word groups, and "restaurant" (order 3) is an augmented word group, vocabulary The word group matching "restaurant" in the table is "what you requested", then the response corpus is processed based on the small sample learning model, and the first response template formed based on the aforementioned order is "the restaurant you requested was not found" .
示例性的,前述词汇表可以基于人工设计的方式构建得到。Exemplarily, the aforementioned vocabulary can be constructed based on artificial design.
可选的,获取根据小样本学习算法创建的初始模型;Optionally, obtain the initial model created according to the few-shot learning algorithm;
通过预设的训练样本对所述初始模型进行训练,所述训练样本包括待进行增广处理的字组和待保持不变的字组;The initial model is trained by preset training samples, the training samples include word groups to be augmented and word groups to be kept unchanged;
将训练好的初始模型确定为所述小样本学习模型。The trained initial model is determined as the small sample learning model.
上述训练样本包括原始样本集和监督模板集,所述原始样本集包括若干个样本语句,所述监督结果集包括若干个第一模板,所述原始样本集中的样本语句的数量和所述监督样本集中的第一模板的数量一致且一一对应,所述样本语句包括待进行增广处理的字组和待保持不变的字组,所述第一模板包括拼接好的增广字组和不变字组(即先通过人工识别的方式,将样本语句中待进行增广处理的字组确定为增广字组,将待保持不变的字组确定为不变字组;再基于人类语言习惯对增广字组进行增广处理,并将增广处理后的增广字组和不变字组进行拼接,以生成所述第一模板)。The above-mentioned training samples include an original sample set and a supervised template set, the original sample set includes several sample sentences, the supervised result set includes several first templates, the number of sample sentences in the original sample set and the supervised sample The number of the first templates in the set is consistent and one-to-one correspondence, the sample sentence includes words to be augmented and words to be kept unchanged, the first template includes spliced augmented words and not Changed word groups (that is, through manual recognition, the word groups to be augmented in the sample sentence are determined as augmented word groups, and the word groups to be kept unchanged are determined as invariable word groups; then based on human language It is customary to perform augmentation processing on the augmented word group, and splicing the augmented word group and the invariant word group to generate the first template).
通过训练样本对初始模型进行训练的过程为:The process of training the initial model through training samples is:
步骤S1、将原始样本集输入初始模型中,获得初始模型输出的第二模板,并计算第一模板和第二模板之间的差异程度;Step S1, input the original sample set into the initial model, obtain the second template output by the initial model, and calculate the degree of difference between the first template and the second template;
步骤S2、判断所述差异程度是否小于预设的差异阈值,若是,则结束训练;若否,则基于所述差异程度调整所述初始模型的参数,并回跳至步骤S1。Step S2, judging whether the degree of difference is smaller than a preset difference threshold, if yes, then end the training; if not, adjust the parameters of the initial model based on the degree of difference, and return to step S1.
优选的,前述词汇表也可以基于所述第一模板和第二模板之间的差异构建得到,即词汇表可理解为第一模板中移除第一模板和第二模板之间的交集字组后的字组集合。举例来说,若第一模板为“这是你最好的选择”,第二模板为“这是你选择”,则第一模板和第二模板之间的交集字组为“这是”“你”“选择”,此时词汇表中将补入的字组为“最好的”。Preferably, the aforementioned vocabulary can also be constructed based on the difference between the first template and the second template, that is, the vocabulary can be understood as removing the intersection words between the first template and the second template in the first template The subsequent set of words. For example, if the first template is "This is your best choice" and the second template is "This is your choice", then the intersection word group between the first template and the second template is "This is"" You""choose", and the word group to be added in the vocabulary at this time is "best".
可选的,所述对所述不变字组和增广处理后的所述增广字组进行拼接,获得所述至少一个第一回复模板,包括:Optionally, the splicing of the invariant word group and the augmented word group after augmentation processing to obtain the at least one first reply template includes:
对所述不变字组和增广处理后的所述增广字组进行拼接,获得初始模板集合,所述初始模板集合包括至少一个初始模板;Splicing the invariant word group and the augmented word group after augmentation processing to obtain an initial template set, the initial template set including at least one initial template;
对所述初始模板集合进行聚类处理,获得所述至少一个第一回复模板。Perform clustering processing on the initial template set to obtain the at least one first reply template.
如上所述,在获得初始模板集合的情况下,利用聚类处理的方式对初始模板集合中的至少一个初始模板进行归纳,以精简初始模板集合中的初始模板数量。As mentioned above, when the initial template set is obtained, clustering is used to summarize at least one initial template in the initial template set, so as to reduce the number of initial templates in the initial template set.
示例性的,可以通过K-means算法对初始模板集合中的至少一个初始模板进行聚类处理,以获得若干个第一模板类簇以及每个第一模板类簇的质心,将第一模板类簇中与质心最相似的初始模板确定为所述第一回复模板,其中,上述K-means算法也可以替换为其他具备聚类功能的算法(如K-means++算法、层次聚类算法等),本申请实施例对此并不加以限定。Exemplarily, the K-means algorithm can be used to cluster at least one initial template in the initial template set to obtain several first template clusters and the centroid of each first template cluster, and the first template cluster The initial template most similar to the centroid in the cluster is determined as the first reply template, wherein the above-mentioned K-means algorithm can also be replaced by other algorithms with clustering functions (such as K-means++ algorithm, hierarchical clustering algorithm, etc.), This embodiment of the present application does not limit it.
可选的,所述对所述初始模板集合进行聚类处理,获得所述至少一个第一回复模板,包括:Optionally, performing clustering processing on the initial template set to obtain the at least one first reply template includes:
循环判断所述初始模板集合是否为空集,并在所述初始模板集合不为空集的情况下,获取所述初始模板集合中的质心模板,并将所述质心模板确定为所述第一回复模板,所述质心模板为所述初始模板集合中的任意一个初始模板;Circularly judge whether the initial template set is an empty set, and if the initial template set is not an empty set, obtain the centroid template in the initial template set, and determine the centroid template as the first Reply template, the centroid template is any initial template in the initial template set;
根据所述质心模板在所述初始模板集合中进行聚类处理,获得以所述质心模板为聚类中心的类簇;performing clustering processing in the initial template set according to the centroid template to obtain clusters with the centroid template as the cluster center;
在所述初始模板集合中删除所述类簇包括的初始模板。The initial template included in the class cluster is deleted from the initial template set.
如上所述,判断初始模板集合是否为空集,并在初始模板集合不是空集的情况下,通过随机抽选的方式获取初始模板集合中的质心模板(任意一个初始模板),并将所抽选的质心模板确定为第一回复模板,之后以质心模板为质心在初始模板集合中进行聚类处理(即计算初始模板集合中的其他初始模板与该质心模板之间的相似值,并将相似值高于阈值的其他初始模板和该质心模板聚集至同一个类簇),以获得包括有质心模板的类簇,随后在初始模板集合中删除该类簇包括的所有初始模板,并继续前述空集判断、随机抽选和聚类的过程,直至初始模板集合为空集时结束循环,以获得所述至少一个第一回复模板,这能降低上述聚类过程的计算复杂度,提升聚类效率。As mentioned above, it is judged whether the initial template set is an empty set, and in the case that the initial template set is not an empty set, the centroid template (any initial template) in the initial template set is obtained by random selection, and the extracted The selected centroid template is determined as the first reply template, and then clustering is performed in the initial template set with the centroid template as the centroid (that is, the similarity value between other initial templates in the initial template set and the centroid template is calculated, and the similarity Other initial templates with a value higher than the threshold and the centroid template are gathered into the same cluster) to obtain a cluster including the centroid template, and then delete all the initial templates included in the cluster in the initial template set, and continue the aforementioned empty Set judgment, random selection and clustering process until the initial template set is an empty set and end the loop to obtain the at least one first reply template, which can reduce the computational complexity of the above clustering process and improve clustering efficiency .
上述相似程度的计算过程可以为:The calculation process of the above similarity degree can be as follows:
计算所述其他初始模板与质心模板之间的形式相似度;calculating the form similarity between said other initial template and the centroid template;
计算所述其他初始模板与质心模板之间的语义相似度;calculating the semantic similarity between the other initial templates and the centroid template;
对所述形式相似度和所述语义相似度进行加权计算,以获得所述相似值。performing weighted calculation on the formal similarity and the semantic similarity to obtain the similarity value.
其中,所述形式相似度用于表征所述其他初始模板和所述质心模板之间的结构相似趋势(如两者的字数差异),所述语义相似度用于表征所述其他初始模板和所述质心模板之间的语义相似趋势。前述加权计算的权值可以人为设定,也可以通过模型拟合(指在预先设定权值的情况下,利用模型训练的方式对预先设定权值进行优化调整,以获得最终的权值)的方式获得。Wherein, the formal similarity is used to characterize the structural similarity trend between the other initial templates and the centroid template (such as the word count difference between the two), and the semantic similarity is used to characterize the other initial templates and the centroid templates. Semantic similarity trends among centroid templates. The weights of the aforementioned weighted calculations can be set manually, or through model fitting (referring to using model training to optimize and adjust the preset weights in the case of preset weights to obtain the final weights ) way to obtain.
可选的,在所述将所述待回复信息填入所述目标回复模板,生成第一回复语句之后,所述方法还包括:Optionally, after filling the information to be replied into the target reply template and generating the first reply sentence, the method further includes:
根据迁移学习模型对所述第一回复语句进行调整,生成第二回复语句;adjusting the first reply sentence according to the transfer learning model to generate a second reply sentence;
所述将所述第一回复语句下发至用户端,包括:The sending the first reply statement to the client includes:
将所述第二回复语句下发至所述用户端。sending the second reply statement to the client.
如上所述,利用迁移学习模型对第一回复语句进行重新表达,生成复合人类语言习惯的第二回复语句,并将该第二回复语句下发至用户端,以达到提升用户满意度的目的。As mentioned above, the transfer learning model is used to re-express the first reply sentence, generate a second reply sentence that composes human language habits, and send the second reply sentence to the client end, so as to achieve the purpose of improving user satisfaction.
示例性的,所述迁移学习模型可以为T5(Text-to-Text Transfer Transformer)模型,实际应用中,也可以应用其他类型的迁移学习模型,本申请实施例对此并不加以限定。Exemplarily, the transfer learning model may be a T5 (Text-to-Text Transfer Transformer) model. In practical applications, other types of transfer learning models may also be applied, which is not limited in this embodiment of the present application.
可选的,在根据小样本学习模型对回复语料进行识别,获得至少一个第一回复模板之后;在根据待回复信息检索所述至少一个第一回复模板之前;所述方法还包括:Optionally, after identifying the reply corpus according to the small-sample learning model and obtaining at least one first reply template; before retrieving the at least one first reply template according to the information to be replied; the method further includes:
在所述至少一个第一回复模板中滤除包括有敏感词的第一回复模板,获得至少一个第二回复模板;Filtering out the first reply templates containing sensitive words in the at least one first reply template to obtain at least one second reply template;
所述根据待回复信息检索所述至少一个第一回复模板,并在所述至少一个第一回复模板中将与所述待回复信息匹配程度最高的第一回复模板确定为目标回复模板,包括:The retrieving the at least one first reply template according to the information to be replied, and determining the first reply template with the highest matching degree with the information to be replied among the at least one first reply templates as the target reply template includes:
根据待回复信息检索所述至少一个第二回复模板,并在所述至少一个第二回复模板中将与所述待回复信息匹配程度最高的第二回复模板确定为目标回复模板。Retrieving the at least one second reply template according to the information to be replied, and determining the second reply template with the highest degree of matching with the information to be replied among the at least one second reply templates as the target reply template.
如上所述,利用敏感词过滤的方式,对第一回复模板进行筛选,以获得回复效果更优的第二回复模板,避免产生歧视、辱骂等含义的对话回复,进一步提升用户体验。As mentioned above, the sensitive word filtering method is used to filter the first reply template to obtain the second reply template with better reply effect, avoiding dialogue replies with meanings such as discrimination and abuse, and further improving user experience.
示例性的,上述敏感词过滤可以通过人工监管的方式实现,也可以通过设置具备敏感词过滤功能的监管函数或监管模型实现,本申请实施例对此并不加以限定。Exemplarily, the above-mentioned sensitive word filtering can be realized through manual supervision, and can also be realized by setting a supervision function or supervision model capable of filtering sensitive words, which is not limited in this embodiment of the present application.
本申请实施例中介绍的多种可选的实施方式,在彼此不冲突的情况下可以相互结合实现,也可以单独实现,对此本申请实施例不作限定。The various optional implementation manners introduced in the embodiments of the present application may be implemented in combination with each other if they do not conflict with each other, or may be implemented independently, which is not limited in the embodiments of the present application.
为方便理解,示例说明如下:For ease of understanding, the examples are as follows:
如图2和图3所示,人机对话系统中的服务器端主要用于对对话回复语料的挖掘及模板提取、以形成模板库,之后基于对话动作列表在模板库中进行检索,以确定适配对话动作列表的候选模板,并根据候选模板和对话动作列表形成第一回复语句,随后经过重释模型对第一回复语句进行重写和微调,以生成符合人类语言习惯的第二回复语句,最后将该第二回复语句渲染在用户界面上,以实现面向用户的对话回复。其中,人工监管主要用于滤除模板库内包括有敏感词的模板,其滤除可以在模板库入库动作执行前完成,也可以在模板库检索动作执行前完成,本申请实施例对此并不加以限定。As shown in Figure 2 and Figure 3, the server side of the human-computer dialogue system is mainly used to mine the dialogue reply corpus and extract templates to form a template library, and then search the template library based on the dialogue action list to determine the appropriate Match the candidate template of the dialogue action list, and form the first reply sentence according to the candidate template and the dialogue action list, and then rewrite and fine-tune the first reply sentence through the reinterpretation model to generate the second reply sentence that conforms to human language habits, Finally, the second reply statement is rendered on the user interface, so as to realize user-oriented dialogue reply. Among them, manual supervision is mainly used to filter out templates containing sensitive words in the template library. The filtering can be completed before the execution of the template library storage action, or before the execution of the template library retrieval action. Not limited.
进一步说明为,对于对话中任一给定的系统回复轮次(即机器人答复轮次),定义A为该轮次的对话动作集合,记为一个NA长度的对话动作序列,其中每个对话动作Ai由对话意图ai(例如“通知”)、任务领域di(例如“餐馆”)、槽si(例如“价格”)和值vi(例如“100元”)组成。对话回复生成,即是将对话动作序列A转换成自然语言回复S的结果,这一过程可以用如下公式表示:It is further explained that, for any given system reply round in the dialogue (ie, the robot reply round), define A as the dialogue action set of this round, record is a dialogue action sequence of NA length, where each dialogue action Ai consists of a dialogue intent ai (e.g. "notification"), task domain di (e.g. "restaurant"), slotsi (e.g. "price"), and Value vi (for example, "100 yuan"). Dialogue reply generation is the result of converting dialogue action sequence A into natural language reply S. This process can be expressed by the following formula:
其中表示回复语句S中的第i个词。in Indicates the i-th word in the reply sentence S.
上述公式实现如下:The above formula is implemented as follows:
其中,是对话动作A对应的候选模板集,用来填充Aj以生成对话回复。in, is the set of candidate templates corresponding to dialog action A, which is used to populate Aj to generate dialog replies.
从上述公式中可以看出,对话回复任务被拆解为两个任务:As can be seen from the above formula, the dialogue reply task is disassembled into two tasks:
1)进行回复生成p(S|A,C);1) Reply to generate p(S|A,C);
2)模板学习p(C|A)。2) Template learning p(C|A).
其中,任务2)模板学习旨在从无监督语料中进行挖掘以得到高质量的模板库,并适用于在小样本学习的前提下进行模板挖掘的领域迁移。如图4所示,整体而言,模板学习包括三部分:基于字组标签文本编辑的初步模板提取方法,基于K-质心无监督聚类的模板归纳,以及在线的模板检索,需要说明的是,图4中参数T用于表征字组。Among them, task 2) template learning aims to mine unsupervised corpus to obtain a high-quality template library, and is suitable for domain transfer of template mining under the premise of small sample learning. As shown in Figure 4, overall, template learning includes three parts: a preliminary template extraction method based on word group label text editing, template induction based on K-centroid unsupervised clustering, and online template retrieval. It should be noted that , the parameter T in Figure 4 is used to characterize the word group.
具体地,对于一个原生的对话回复语料集合学习框架借助一个transformer编码器将该集合中的对话回复Ri转变为初始模板Pi,之后,初始模板集合将被归纳为一个最终的模板库L。Specifically, for a native dialogue response corpus The learning framework uses a transformer encoder to transform the dialogue responses Ri in the set into initial templates Pi , after that, the initial template set will be summarized into a final template library L.
在进行模型推理时,对话动作Ai的每一个对话意图ai都会通过查询模板库L来获得一些候选集,之后选择一个模板Ci作为最终结果。上述过程可以被形式化地表达为:When performing model inference, each dialog intention ai of the dialog action Ai will query the template library L to obtain some candidate sets, and then select a template Ci as the final result. The above process can be formally expressed as:
如图5所示,将模板提取作为一个文本编辑问题,以保证模板生成的可控性及其在小样本学习下的表现能力。一般地,文本编辑被视作一个字组级别的多分类问题,通过transformer编码器,对对话回复中的每个字组进行判断,以预测该字组将进行何种操作。定义三种字组操作:删除字组、保持字组不变(可理解为前述的不变字组)和在字组前面添加字组(可理解为前述的增广字组)。As shown in Figure 5, template extraction is treated as a text editing problem to ensure the controllability of template generation and its performance under few-shot learning. Generally, text editing is regarded as a word-level multi-classification problem. Through the transformer encoder, each word in the dialogue reply is judged to predict what operation the word will perform. Define three word group operations: delete word group, keep word group unchanged (can be understood as the aforementioned invariant word group) and add word group in front of the word group (can be understood as the aforementioned augmented word group).
基于以上操作,对于回复Ri中的所有字组设计两个分类任务:Based on the above operations, for all word groups in the reply Ri Design two classification tasks:
(1)用来判断是否要保存当前字组的0-1分类,即确定Tji是要保持不变还是要被删除;(1) be used for judging whether to preserve the 0-1 classification of current word group, promptly determine whether Tji will remain unchanged or will be deleted;
(2)一个面向词汇表的多分类,用来确定应该在前面添加哪种字词组合。(2) A vocabulary-oriented multi-classification to determine what should be in Which combination of words to prepend.
特殊地,如果不需要添加任何字组,预测的结果将是空的组合。词汇表可以通过比较训练集中回复与模板的差异构建。将上述两种分类任务进行组合,从而形成最终的分类标签空间也就是上述两个分类任务标签的笛卡尔积/>通过这种方式所获得的最终分类任务,其标签个数为2×NV,NV为词汇表的长度。In particular, if no words need to be added, the predicted result will be an empty combination. A vocabulary can be constructed by comparing the differences between responses and templates in the training set. Combine the above two classification tasks to form the final classification label space That is, the Cartesian product of the above two classification task labels /> The number of labels for the final classification task obtained in this way is 2×NV , where NV is the length of the vocabulary.
为完成以上分类任务,借助一个12层的小型transformer编码器作为fe(·),并在其后面拼接全连接层fl(·)进行分类,上述过程整体可以表述为:In order to complete the above classification tasks, a 12-layer small transformer encoder is used as fe (·), and a fully connected layer fl (·) is spliced behind it for classification. The above process as a whole can be expressed as:
其中,是通过预测所得的应添加的词组。in, is the phrase that should be added through prediction.
基于交叉熵损失进行训练,令c为类别的索引,为字组/>将被预测为c的概率,N为序列的最大长度,Nc为类别的个数,则损失函数可以写为:Training based on cross-entropy loss, let c be the index of the category, for word group /> will be predicted as the probability of c, N is the maximum length of the sequence, and Nc is the number of categories, then the loss function can be written as:
为了将初步模板集合P映射为模板库L,将模板归纳定义为一个K-质心聚类问题。其主要执行流程是:先根据模板的形式相似度(form similarity)和语义相似度(semanticsimilarity),对初始模板集合P进行聚类;再从每个簇中选择其代表模板,并基于这些模板形成模板库L。考虑到整个过程在计算复杂度上为并且模板集合中元素个数NR的范围可能在102到105之间,因此将上述过程简化为:每次从模板集合模板P中随机选择一个初步模板Pr,并根据形式相似度和语义相似度对初始模板库进行遍历,以构造其邻近集Pn,将Pr添加到L中并删除{Pr}∪Pn,如此迭代下去,直到P为空集为止。如图6所示,回复生成p(S|A,C)是指基于候选模板C,将对话动作A和候选模板转换为对话回复S。一般而言,一种简略但较为有效的方法是人工设计规则引擎。考虑到基于人工设计规则的方法难以涵盖所有的模板生成空间,且存在生成回复不够通顺的问题,在基于人工规则生成模板的基础上添加了重释(paraphrasing)模块。该重释模块基于T5(Text-to-Text Transfer Transformer)实现,旨在将基于规则的句子(可理解为第一回复语句)进行重新表达,以生成真正符合人类语言习惯的回复(可理解为第二回复语句)。To map the preliminary template set P to the template library L, template induction is defined as a K-centroid clustering problem. Its main execution process is: first, cluster the initial template set P according to the form similarity and semantic similarity of the templates; then select its representative template from each cluster, and form a template based on these templates. The template library L. Considering that the computational complexity of the whole process is And the number of elements NR in the template set may range from 102 to 105 , so the above process is simplified as: each time a preliminary template Pr is randomly selected from the template set template P, and according to the form similarity and Semantic similarity traverses the initial template library to construct its neighbor set Pn , adds Pr to L and deletes {Pr }∪Pn , and iterates until P is an empty set. As shown in Figure 6, reply generation p(S|A,C) refers to converting dialogue action A and candidate templates into dialogue reply S based on candidate template C. Generally speaking, a simple but more effective method is to manually design a rule engine. Considering that the method based on artificial design rules is difficult to cover all the template generation space, and there is a problem that the generated reply is not smooth enough, a paraphrasing module is added on the basis of template generation based on artificial rules. The reinterpretation module is implemented based on T5 (Text-to-Text Transfer Transformer), and aims to re-express rule-based sentences (understandable as the first reply statement) to generate a reply that truly conforms to human language habits (understandable as second reply statement).
本申请实施例中介绍的多种可选的实施方式,在彼此不冲突的情况下可以相互结合实现,也可以单独实现,对此本申请实施例不作限定。The various optional implementation manners introduced in the embodiments of the present application may be implemented in combination with each other if they do not conflict with each other, or may be implemented independently, which is not limited in the embodiments of the present application.
参见图7,图7是本申请实施例提供的对话回复装置的结构示意图。如图7所示,对话回复装置200包括:Referring to FIG. 7, FIG. 7 is a schematic structural diagram of a dialog replying device provided in an embodiment of the present application. As shown in Figure 7, the
模板构建模块201,用于根据预训练的小样本学习模型对回复语料进行识别,获得至少一个第一回复模板;The
检索模块202,用于在所述至少一个第一回复模板中将与待回复信息匹配程度最高的第一回复模板确定为目标回复模板;A
语句生成模块203,用于将所述待回复信息填入所述目标回复模板,生成第一回复语句;A
回复模块204,用于将所述第一回复语句下发至用户端。
可选的,所述模板构建模块201包括:Optionally, the
拆分子模块,用于对所述回复语料进行拆分处理,获得至少两个字组;dismantling sub-modules, used to disassemble and process the reply corpus to obtain at least two word groups;
识别子模块,用于在所述至少两个字组中识别不变字组和增广字组;An identification submodule, configured to identify an invariant word group and an augmented word group among the at least two word groups;
增广子模块,根据预设的词汇表对所述增广字组进行增广处理;The augmentation sub-module performs augmentation processing on the augmented word group according to a preset vocabulary;
拼接子模块,用于对所述不变字组和增广处理后的所述增广字组进行拼接,获得所述至少一个第一回复模板。The splicing sub-module is configured to splice the invariant word group and the augmented word group after augmentation processing to obtain the at least one first reply template.
可选的,所述拼接子模块包括:Optionally, the splicing submodule includes:
拼接单元,用于对所述不变字组和增广处理后的所述增广字组进行拼接,获得初始模板集合,所述初始模板集合包括至少一个初始模板;A splicing unit, configured to splice the invariant word group and the augmented word group after augmentation processing, to obtain an initial template set, and the initial template set includes at least one initial template;
聚类单元,用于对所述初始模板集合进行聚类处理,获得所述至少一个第一回复模板。The clustering unit is configured to perform clustering processing on the initial template set to obtain the at least one first reply template.
可选的,所述聚类单元包括:Optionally, the clustering unit includes:
循环判断所述初始模板集合是否为空集,并在所述初始模板集合不为空集的情况下,获取所述初始模板集合中的质心模板,并将所述质心模板确定为所述第一回复模板,所述质心模板为所述初始模板集合中的任意一个初始模板;Circularly judge whether the initial template set is an empty set, and if the initial template set is not an empty set, obtain the centroid template in the initial template set, and determine the centroid template as the first Reply template, the centroid template is any initial template in the initial template set;
根据所述质心模板在所述初始模板集合中进行聚类处理,获得以所述质心模板为聚类中心的类簇;performing clustering processing in the initial template set according to the centroid template to obtain clusters with the centroid template as the cluster center;
在所述初始模板集合中删除所述类簇包括的初始模板。The initial template included in the class cluster is deleted from the initial template set.
可选的,所述对话回复装置200还包括重释模块,所述重释模块用于:Optionally, the
根据迁移学习模型对所述第一回复语句进行调整,生成第二回复语句。The first reply sentence is adjusted according to the transfer learning model to generate a second reply sentence.
所述回复模块204还用于,将所述第二回复语句下发至所述用户端。The
可选的,所述对话回复装置200还包括监管模块,所述监管模块用于:Optionally, the
在所述至少一个第一回复模板中滤除包括有敏感词的第一回复模板,获得至少一个第二回复模板;Filtering out the first reply templates containing sensitive words in the at least one first reply template to obtain at least one second reply template;
所述检索模块202还用于,根据待回复信息检索所述至少一个第二回复模板,并在所述至少一个第二回复模板中将与所述待回复信息匹配程度最高的第二回复模板确定为目标回复模板。The
可选的,对话回复装置200还包括训练模块,所述训练模块用于:Optionally, the
获取根据小样本学习算法创建的初始模型;Obtain the initial model created according to the few-shot learning algorithm;
通过预设的训练样本对所述初始模型进行训练,所述训练样本包括待进行增广处理的字组和待保持不变的字组;The initial model is trained by preset training samples, the training samples include word groups to be augmented and word groups to be kept unchanged;
将训练好的初始模型确定为所述小样本学习模型。The trained initial model is determined as the small sample learning model.
本申请实施例提供的一种对话回复装置,利用小样本学习模型识别回复语料的方式,来替换相关技术所采用的人工设计回复模板的方式,以提高回复模板生成阶段的效率,降低回复模板的生成成本,同时使回复模板的生成过程具备可扩展性,以适配人机对话系统在业务增广或业务迁移过程中的需求变化。A dialogue reply device provided in the embodiment of the present application uses a small-sample learning model to identify reply corpus to replace the manual design of reply templates used in related technologies, so as to improve the efficiency of the reply template generation stage and reduce the cost of reply templates. Generate costs, and at the same time make the generation process of the reply template scalable, so as to adapt to the demand changes of the man-machine dialogue system in the process of business expansion or business migration.
对话回复装置200能够实现本申请实施例中图1方法实施例的各个过程,以及达到相同的有益效果,为避免重复,这里不再赘述。The
本申请实施例还提供一种通信设备。请参见图8,通信设备可以包括处理器301、存储器302及存储在存储器302上并可在处理器301上运行的程序3021。The embodiment of the present application also provides a communication device. Referring to FIG. 8 , the communication device may include a
程序3021被处理器301执行时可实现图1对应的方法实施例中的任意步骤及达到相同的有益效果,此处不再赘述。When the
本领域普通技术人员可以理解实现上述实施例方法的全部或者部分步骤是可以通过程序指令相关的硬件来完成,所述的程序可以存储于一可读取介质中。Those skilled in the art can understand that all or part of the steps for implementing the methods of the above embodiments can be completed by program instructions related hardware, and the program can be stored in a readable medium.
本申请实施例还提供一种可读存储介质,所述可读存储介质上存储有计算机程序,所述计算机程序被处理器执行时可实现上述图1对应的方法实施例中的任意步骤,且能达到相同的技术效果,为避免重复,这里不再赘述。An embodiment of the present application also provides a readable storage medium, on which a computer program is stored, and when the computer program is executed by a processor, any step in the above method embodiment corresponding to FIG. 1 can be implemented, and The same technical effect can be achieved, so in order to avoid repetition, details will not be repeated here.
本申请实施例的计算机可读存储介质,可以采用一个或多个计算机可读的介质的任意组合。计算机可读介质可以是计算机可读信号介质或者计算机可读存储介质。计算机可读存储介质例如可以是——但不限于——电、磁、光、电磁、红外线、或半导体的系统、装置或器件,或者任意以上的组合。计算机可读存储介质的更具体的例子(非穷举的列表)包括:具有一个或多个导线的电连接、便携式计算机磁盘、硬盘、随机存取存储器(RAM)、只读存储器(ROM)、可擦式可编程只读存储器(EPROM或闪存)、光纤、便携式紧凑磁盘只读存储器(CD-ROM)、光存储器件、磁存储器件、或者上述的任意合适的组合。在本文件中,计算机可读存储介质可以是任何包含或存储程序的有形介质,该程序可以被指令执行系统、装置或者器件使用或者与其结合使用。The computer-readable storage medium in the embodiments of the present application may use any combination of one or more computer-readable media. The computer readable medium may be a computer readable signal medium or a computer readable storage medium. A computer readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device, or device, or any combination thereof. More specific examples (non-exhaustive list) of computer readable storage media include: electrical connections with one or more leads, portable computer disks, hard disks, random access memory (RAM), read only memory (ROM), Erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage device, magnetic storage device, or any suitable combination of the above. In this document, a computer-readable storage medium may be any tangible medium that contains or stores a program that can be used by or in conjunction with an instruction execution system, apparatus, or device.
计算机可读的信号介质可以包括在基带中或者作为载波一部分传播的数据信号,其中承载了计算机可读的程序代码。这种传播的数据信号可以采用多种形式,包括但不限于电磁信号、光信号或上述的任意合适的组合。计算机可读的信号介质还可以是计算机可读存储介质以外的任何计算机可读介质,该计算机可读介质可以发送、传播或者传输用于由指令执行系统、装置或者器件使用或者与其结合使用的程序。A computer readable signal medium may include a data signal carrying computer readable program code in baseband or as part of a carrier wave. Such propagated data signals may take many forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the foregoing. A computer-readable signal medium may also be any computer-readable medium other than a computer-readable storage medium, which can send, propagate, or transmit a program for use by or in conjunction with an instruction execution system, apparatus, or device. .
存储介质上包含的程序代码可以用任何适当的介质传输,包括——但不限于无线、电线、光缆、RF等等,或者上述的任意合适的组合。Program code contained on a storage medium may be transmitted using any appropriate medium, including - but not limited to wireless, wires, optical cables, RF, etc., or any suitable combination of the foregoing.
可以以一种或多种程序设计语言或其组合来编写用于执行本申请操作的计算机程序代码,所述程序设计语言包括面向对象的程序设计语言—诸如Java、Smalltalk、C++,还包括常规的过程式程序设计语言—诸如“C”语言或类似的程序设计语言。程序代码可以完全地在用户计算机上执行、部分地在用户计算机上执行、作为一个独立的软件包执行、部分在用户计算机上部分在远程计算机上执行、或者完全在远程计算机或终端上执行。在涉及远程计算机的情形中,远程计算机可以通过任意种类的网络——包括局域网(LAN)或广域网(WAN)—连接到用户计算机,或者,可以连接到外部计算机(例如利用因特网服务提供商来通过因特网连接)。Computer program code for performing the operations of the present application may be written in one or more programming languages or combinations thereof, including object-oriented programming languages—such as Java, Smalltalk, C++, and conventional Procedural Programming Language - such as "C" or a similar programming language. The program code may execute entirely on the user's computer, partly on the user's computer, as a stand-alone software package, partly on the user's computer and partly on a remote computer or entirely on the remote computer or terminal. In cases involving a remote computer, the remote computer can be connected to the user computer through any kind of network, including a local area network (LAN) or a wide area network (WAN), or it can be connected to an external computer (such as through an Internet service provider). Internet connection).
以上所述是本申请实施例的优选实施方式,应当指出,对于本技术领域的普通技术人员来说,在不脱离本申请所述原理的前提下,还可以作出若干改进和润饰,这些改进和润饰也应视为本申请的保护范围。The above is the preferred implementation of the embodiment of the present application. It should be pointed out that for those of ordinary skill in the art, without departing from the principles described in the present application, some improvements and modifications can also be made. These improvements and Retouching should also be regarded as the protection scope of this application.
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN202111613286.7ACN116361424A (en) | 2021-12-27 | 2021-12-27 | Dialog reply method, device, communication device and readable storage medium |
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN202111613286.7ACN116361424A (en) | 2021-12-27 | 2021-12-27 | Dialog reply method, device, communication device and readable storage medium |
| Publication Number | Publication Date |
|---|---|
| CN116361424Atrue CN116361424A (en) | 2023-06-30 |
| Application Number | Title | Priority Date | Filing Date |
|---|---|---|---|
| CN202111613286.7APendingCN116361424A (en) | 2021-12-27 | 2021-12-27 | Dialog reply method, device, communication device and readable storage medium |
| Country | Link |
|---|---|
| CN (1) | CN116361424A (en) |
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| WO2017041370A1 (en)* | 2015-09-07 | 2017-03-16 | 百度在线网络技术(北京)有限公司 | Human-computer chatting method and device based on artificial intelligence |
| CN109815321A (en)* | 2018-12-26 | 2019-05-28 | 出门问问信息科技有限公司 | Question answering method, device, equipment and storage medium |
| CN109885810A (en)* | 2019-01-17 | 2019-06-14 | 平安城市建设科技(深圳)有限公司 | Nan-machine interrogation's method, apparatus, equipment and storage medium based on semanteme parsing |
| US20190341021A1 (en)* | 2017-01-17 | 2019-11-07 | Huawei Technologies Co., Ltd. | Human-Computer Dialogue Method and Apparatus |
| CN111930884A (en)* | 2020-07-03 | 2020-11-13 | 华为技术有限公司 | Method and equipment for determining reply sentence and man-machine conversation system |
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| WO2017041370A1 (en)* | 2015-09-07 | 2017-03-16 | 百度在线网络技术(北京)有限公司 | Human-computer chatting method and device based on artificial intelligence |
| US20190341021A1 (en)* | 2017-01-17 | 2019-11-07 | Huawei Technologies Co., Ltd. | Human-Computer Dialogue Method and Apparatus |
| CN109815321A (en)* | 2018-12-26 | 2019-05-28 | 出门问问信息科技有限公司 | Question answering method, device, equipment and storage medium |
| CN109885810A (en)* | 2019-01-17 | 2019-06-14 | 平安城市建设科技(深圳)有限公司 | Nan-machine interrogation's method, apparatus, equipment and storage medium based on semanteme parsing |
| CN111930884A (en)* | 2020-07-03 | 2020-11-13 | 华为技术有限公司 | Method and equipment for determining reply sentence and man-machine conversation system |
| Title |
|---|
| FUWEI CUI: "A Survey on Learning-Based Approaches for Modeling and Classification of Human–Machine Dialog Systems", 《IEEE TRANSACTIONS ON NEURAL NETWORKS AND LEARNING SYSTEMS ( VOLUME: 32, ISSUE: 4, APRIL 2021)》, 27 April 2020 (2020-04-27)* |
| 章奇: "基于BERT的意图识别与语义槽抽取算法研究", 《中国优秀硕士学位论文全文数据库 信息科技辑》, 15 April 2021 (2021-04-15)* |
| Publication | Publication Date | Title |
|---|---|---|
| CN116775847B (en) | Question answering method and system based on knowledge graph and large language model | |
| CN108038183B (en) | Structured entity recording method, device, server and storage medium | |
| CN117591663B (en) | A large model prompt generation method based on knowledge graph | |
| US12229108B2 (en) | Efficient embedding table storage and lookup | |
| CN107301170A (en) | The method and apparatus of cutting sentence based on artificial intelligence | |
| CN114840671A (en) | Dialogue generation method, model training method, device, equipment and medium | |
| CA3050202A1 (en) | Visualization interface for voice input | |
| CN112507118B (en) | Information classification extraction method, device and electronic equipment | |
| WO2023040493A1 (en) | Event detection | |
| CN117421398A (en) | Man-machine interaction method, device, equipment and storage medium | |
| CN114118100A (en) | Method, apparatus, device, medium and program product for generating dialogue statements | |
| CN115955452A (en) | 5G message pushing method and device based on multi-turn conversation intention recognition | |
| CN117931858B (en) | Data query method, device, computer equipment and storage medium | |
| CN110362815A (en) | Text vector generation method and device | |
| CN115186071A (en) | Intent recognition method, apparatus, electronic device and readable storage medium | |
| WO2021190662A1 (en) | Medical text sorting method and apparatus, electronic device, and storage medium | |
| US20250005290A1 (en) | Intention recognition method, device, electronic device and storage medium based on large model | |
| WO2025162037A1 (en) | Training method and apparatus for speech recognition model, and electronic device and storage medium | |
| CN114491079A (en) | Knowledge graph construction and query method, device, equipment and medium | |
| CN118916499A (en) | Query method integrating AI large model and knowledge graph | |
| CN117313670A (en) | Document generation method, device, electronic equipment and storage medium | |
| CN112988952A (en) | Multi-level-length text vector retrieval method and device and electronic equipment | |
| CN117594037A (en) | Training method of voice recognition model, voice recognition method, device and medium | |
| CN117271884A (en) | Method, device, electronic equipment and storage medium for determining recommended content | |
| CN116361424A (en) | Dialog reply method, device, communication device and readable storage medium |
| Date | Code | Title | Description |
|---|---|---|---|
| PB01 | Publication | ||
| PB01 | Publication | ||
| SE01 | Entry into force of request for substantive examination | ||
| SE01 | Entry into force of request for substantive examination |