Question template generation method, question and answer method, device and electronic equipment

By using a template generation model based on triplet information and a generative adversarial network, the problem of low template generation efficiency in question answering systems is solved, achieving efficient and low-cost automatic template generation and improving template quality and universality.

CN114281966BActive Publication Date: 2026-03-24IFLYTEK SOUTH CHINA ARTIFICIAL INTELLIGENCE RES INST GUANGZHOU CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-11-29
Publication Date
2026-03-24

AI Technical Summary

Technical Problem

Existing question-and-answer systems have low efficiency in generating question templates, require a large amount of manpower, and result in high costs for establishing template libraries.

Method used

A template generation model based on triple information is adopted. By training the template generation model, the automatic generation of question templates is achieved by using sample triple information and sample question templates in combination with a generative adversarial network.

Benefits of technology

It improves the efficiency of problem template generation, saves labor costs, ensures template quality and universality, and enhances the practicality and accuracy of template generation methods.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114281966B_ABST
    Figure CN114281966B_ABST
Patent Text Reader

Abstract

The application provides a problem template generation method, a question and answer method, a device and an electronic equipment, comprising: determining triple information, the form of the triple information comprising a text form and / or a triple form; inputting the triple information into a template generation model to obtain a question template output by the template generation model; wherein the template generation model is trained based on sample triple information and sample question templates corresponding to the sample triple information, and the form of the sample triple information comprises the text form and the triple form. The generation method, the question and answer method, the device and the electronic equipment provided by the application greatly improve the generation efficiency of the question template, save the labor cost, ensure the high quality of the question template, and improve the universality and practicability of the template generation method by applying the template generation model to generate the template based on the input triple information.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of natural language processing, and particularly relates to a question template generation method, a question and answer method, a device and an electronic equipment. BACKGROUND

[0002] A question and answer system is a threshold of human-computer interaction and an important component of a chat robot. In order to meet various ways of asking of users, the question and answer system needs to establish a large template library.

[0003] At present, a template scheme based on manual writing is usually used in a common question and answer system, which can guarantee the quality of the template, but the efficiency of writing the template has a serious problem, and a large amount of manpower needs to be invested to complete the establishment of the template library. SUMMARY

[0004] The present application provides a question template generation method, a question and answer method, a device and an electronic equipment, which are used to solve the defect of poor efficiency of generating a question template in the prior art, and realize improving the efficiency of generating a question template.

[0005] The present application provides a question template generation method, which comprises the following steps:

[0006] determining triple information, wherein the form of the triple information comprises a text form and / or a triple form;

[0007] inputting the triple information into a template generation model to obtain a question template output by the template generation model;

[0008] The template generation model is trained based on sample triple information and a sample question template corresponding to the sample triple information, and the form of the sample triple information comprises the text form and the triple form.

[0009] According to the question template generation method provided by the present application, the template generation model is trained based on the following steps:

[0010] performing triple extraction on a sample text to obtain triples of the sample text, wherein the sample text is sample triple information in the text form;

[0011] training the template generation model based on the sample text, the triples of the sample text and a sample question template, and sample triples and a sample question template of the sample triples, wherein the sample triples are sample triple information in the triple form.

[0012] According to the problem template generation method provided by the application, the template generation model is trained based on the sample text, the triplets of the sample text and the sample problem template, and the sample triplets and the sample problem template of the sample triplets.

[0013] The first generation model is trained based on the sample text, the triplets of the sample text and the sample problem template, and the second generation model is obtained.

[0014] The second generation model is trained based on the sample triplets and the sample problem template of the sample triplets, and the template generation model is obtained.

[0015] According to the problem template generation method provided by the application, the template generation model is trained based on sample triplet information and sample problem templates corresponding to the sample triplet information, and is obtained through joint template discrimination model adversarial training; the template discrimination model is used to distinguish the authenticity of the generated problem template and the sample problem template, and the generated problem template is obtained through template generation based on the sample triplet information by the template generation model.

[0016] According to the problem template generation method provided by the application, the triplet information is input into the template generation model to obtain the problem template output by the template generation model, which comprises:

[0017] The triplet of the question text is obtained by performing triplet extraction on the question text, and the triplet information of the question text is in the form of text;

[0018] The triplet of the question text and the question text are input into the template generation model to obtain the problem template output by the template generation model.

[0019] According to the problem template generation method provided by the application, the triplet of the question text is obtained by performing triplet extraction on the question text, which comprises:

[0020] The entity pair and the type of each entity are obtained by performing entity recognition on the question text.

[0021] The relationship between the entity pairs is obtained by performing relationship extraction on the entity pairs.

[0022] Based on the entity pairs, the types of each entity and the relationship between the entity pairs, the triplet of the question text is constructed.

[0023] According to the problem template generation method provided by the application, the problem template comprises the type of each entity in the triplet information and the non-entity text in the corresponding question of the triplet information.

[0024] The application further provides a question and answer method, comprising:

[0025] acquiring a query text;

[0026] acquiring an answer of the query text based on a question template library;

[0027] The question template library comprises question templates generated based on any one of the question template generation methods described above.

[0028] The application further provides a question template generation device, comprising:

[0029] a determination module configured to determine triple information, wherein the form of the triple information comprises a text form and / or a triple form;

[0030] a generation module configured to input the triple information into a template generation model to obtain a question template output by the template generation model;

[0031] The template generation model is trained based on sample triple information and sample question templates corresponding to the sample triple information, and the form of the sample triple information comprises the text form and the triple form.

[0032] The application further provides a question and answer device, comprising:

[0033] an acquisition module configured to acquire a query text;

[0034] a response module configured to acquire an answer of the query text based on a question template library;

[0035] The question template library comprises question templates generated based on any one of the question template generation methods described above.

[0036] The application further provides an electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of any one of the question template generation methods or the question and answer method described above when executing the program.

[0037] The application further provides a non-transitory computer-readable storage medium having a computer program stored thereon, wherein the computer program is executable on a processor to implement the steps of any one of the question template generation methods or the question and answer method described above.

[0038] The application provides a question template generation method, a question and answer method, a device and an electronic equipment, and the question template is automatically generated by applying a template generation model to generate a template based on input triple information, thereby greatly improving the generation efficiency of the question template, saving the labor cost, and ensuring the high quality of the question template and improving the universality and practicability of the template generation method. BRIEF DESCRIPTION OF DRAWINGS

[0039] In order to more clearly illustrate the technical solutions in the application or the prior art, the following will briefly introduce the drawings needed to be used in the embodiments or the prior art description. Obviously, the drawings in the following description are some embodiments of the application, and other drawings can be obtained by those skilled in the art without creative labor.

[0040] Figure 1 is one of the flowcharts of the question template generation method provided by the application;

[0041] Figure 2 is one of the flowcharts of the template generation model training method provided by the application;

[0042] Figure 3 is the second flowchart of the template generation model training method provided by the application;

[0043] Figure 4 is the second flowchart of the question template generation method provided by the application;

[0044] Figure 5 is the flowchart of the triple extraction method provided by the application;

[0045] Figure 6 is the example diagram of the knowledge base subgraph provided by the application;

[0046] Figure 7 is the example diagram of the training sample label of the entity recognition model provided by the application;

[0047] Figure 8 is the structural diagram of the entity recognition model provided by the application;

[0048] Figure 9 is the structural diagram of the relation extraction model provided by the application;

[0049] Figure 10 is the third flowchart of the template generation model training method provided by the application;

[0050] Figure 11is a flowchart of the question and answer method provided by the present application;

[0051] Figure 12 is a structural diagram of the question template generation device provided by the present application;

[0052] Figure 13 is a structural diagram of the question and answer device provided by the present application;

[0053] Figure 14 is a structural diagram of the electronic device provided by the present application. DETAILED DESCRIPTION

[0054] In order to make the objects, technical solutions and advantages of the present application clearer, the technical solutions in the present application will be described clearly and completely below in combination with the drawings in the present application. Obviously, the described embodiments are part of the embodiments of the present application, rather than all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without creative labor fall within the scope of protection of the present application.

[0055] Natural language processing technology, as one of the most important directions in the field of artificial intelligence, has always been a hot spot for researchers in related fields. In recent years, with the rapid development of mobile internet technology and the increasing degree of informatization, people increasingly hope that machines can understand natural language, so as to achieve the goal of reducing manual input and sharing massive data. How to efficiently analyze and obtain valuable information from massive data has become an urgent and solvable problem.

[0056] Knowledge base-based question and answer systems are increasingly valued because they can directly answer factual questions and meet the needs of users to quickly obtain knowledge. However, in order to meet the various ways of users, the question and answer system needs to establish a huge template library. The commonly used question and answer systems currently mostly use a template scheme based on manual writing, which can guarantee the quality of the templates, but the efficiency of template writing is a serious problem, and a large amount of manpower is needed to complete the establishment of the template library.

[0057] To this end, the embodiments of the present application provide a question template generation method. Figure 1 is one of the flowcharts of the question template generation method provided by the present application, as shown in Figure 1 The method comprises the following steps:

[0058] Step 110, determining triple information, the form of the triple information comprising a text form and / or a triple form;

[0059] Step 120, inputting the triple information into a template generation model to obtain a question template output by the template generation model;

[0060] The template generation model is trained based on sample triple information and sample question templates corresponding to the sample triple information.

[0061] Specifically, the triple information, i.e., the information of the question template to be generated, can be in a text form, a triple form, or a combination of the text form and the triple form. Here, the text form is a sentence form with complete text semantics, for example, "In which year was Qian Xuesen born in Shanghai?". The triple form can be a combination of elements composed of an entity pair, types to which the entities belong, and a relationship between the entity pair, for example, "entity 1: type 1; entity 2: type 2; relationship".

[0062] Considering that the common question and answer system currently adopts a template scheme based on manual writing, the writing efficiency of the template is low, and the human cost is large. To solve this problem, after the triple information is determined, the template generation model pre-trained is applied to generate a template based on the input triple information, so as to obtain a high-quality question template output by the template generation model. Here, the question template is a general question sentence with an extended example, which can be used for template matching in the question and answer system.

[0063] In addition, before step 120 is performed, the template generation model can also be pre-trained. Specifically, the template generation model can be trained in the following manner: first, a large amount of sample triple information is collected. The form of the sample triple information can include a text form and a triple form, and the sample question templates corresponding to the sample triple information are obtained through labeling. Then, the initial template generation model is trained using the sample triple information and the sample question templates corresponding to the sample triple information, so as to obtain the template generation model. Here, the initial template generation model can be a language model.

[0064] It should be noted that when the template generation model is trained, the input of the template generation model includes two training samples, which are sample texts in a text form and sample triples in a triple form. The template generation model is trained using the sample texts and the sample question templates corresponding to the sample texts, so that the template generation model learns the triple information in the reference template and the complete semantic information of the whole sentence, so that the template generation model obtained by training can generate a corresponding question template for the input question text, and the coherence of the question template is also ensured.

[0065] Further, the template generation model is trained by using the sample triplets and the sample question templates corresponding to the sample triplets, mainly to utilize the advantages of the language model, so that the template generation model can directly generate reasonable question templates according to the knowledge of the language model and the input triplets without reference texts. Under the comprehensive action of the above two aspects, the template generation effect of the trained template generation model is guaranteed, and on this basis, when the trained template generation model is applied to template generation, high-quality question templates can be generated regardless of the form of the input triplet information, thereby improving the universality and practicability of the template generation method.

[0066] The method provided by the embodiments of the present application realizes the automatic generation of question templates by applying the template generation model to template generation based on the input triplet information, greatly improves the generation efficiency of question templates compared with manually writing templates, saves the labor cost, and ensures the high quality of question templates by using the text form and the triplet form of sample triplet information as the training samples of the template generation model, thereby improving the universality and practicability of the template generation method.

[0067] Based on any of the above embodiments, Figure 2 is one of the flowcharts of the template generation model training method provided by the present application, as shown in Figure 2 The template generation model is trained based on the following steps:

[0068] In step 210, the triplet extraction is performed on the sample texts to obtain the triplets of the sample texts, and the sample texts are sample triplet information in the form of texts.

[0069] In step 220, the template generation model is trained based on the sample texts, the triplets of the sample texts and the sample question templates, and the sample triplets and the sample question templates of the sample triplets.

[0070] Specifically, the template generation model can be trained in the following manner: first, collect sample triplet information in the form of texts, i.e., sample texts with complete text semantics, and sample triplet information in the form of triplets, i.e., sample triplets containing entity pairs, types of each entity and relationships between the entity pairs, and obtain the sample question templates of the sample texts and the sample question templates of the sample triplets through labeling.

[0071] Then, considering that the knowledge base is usually stored in the form of triples, and due to the diversity of language forms, the same semantics can correspond to multiple question texts, the method of generating a question template based on triples is more universal and practical. In order to further improve the quality of the template generation model for generating templates for triples, the embodiment of the application extracts triples from the sample text, thereby obtaining triples of the sample text, and then trains the initial template generation model according to the sample text, the triples of the sample text and the sample question template, and the sample triples and the sample question template of the sample triples, thereby obtaining the trained template generation model.

[0072] Here, the specific training method can be to train the initial template generation model according to the training data corresponding to the sample text and the training data corresponding to the sample triples, or to first train the initial template generation model according to the training data corresponding to the sample text, and then train the intermediate template generation model obtained in the previous step according to the training data corresponding to the sample triples, which is not specifically limited by the embodiment of the application.

[0073] The method provided by the embodiment of the application trains the template generation model according to the sample text, the triples of the sample text and the sample question template, and the sample triples and the sample question template of the sample triples, ensures the effect of the template generation model for generating templates for triples, and ensures the semantic coherence of the templates generated by the template generation model due to the ability of the template generation model to learn complete semantic information of the sample text, thereby improving the efficiency and quality of constructing a question template library based on a knowledge base.

[0074] Based on any of the above embodiments, Figure 3 is a flowchart of the template generation model training method provided by the embodiment of the application, as shown in Figure 3 Step 220 includes:

[0075] Step 221, training the first generation model based on the sample text, the triples of the sample text and the sample question template, to obtain a second generation model;

[0076] Step 222, training the second generation model based on the sample triples and the sample question template of the sample triples, to obtain a template generation model.

[0077] Specifically, after obtaining the training samples, first, the initial training of the template generation model can be performed, and the initial template generation model, i.e., the first generation model, is trained according to the sample text, the triplets of the sample text, and the sample question template, so as to obtain a second generation model; it can be understood that the second generation model has the ability to generate corresponding question templates based on triplets, and at the same time, since the input covers the sample text with specific complete text semantics, the semantic coherence of the template generated by the template generation model is ensured.

[0078] On this basis, the training of the triplet generation function is further added, the second generation model obtained in step 221 is trained according to the sample triplets and the sample question template of the sample triplets, to obtain a template generation model, so as to further improve the effect of the template generation model in generating templates based on triplets without reference text.

[0079] Further, considering that directly replacing the entity in the sample text with the entity type in the triplet will affect the semantic expression accuracy of the original sample text, and further affect the training effect of the model, and at the same time, considering the full use of the characteristics of the language model, for this, the embodiment of the application adopts the combination of the sample text and the triplets of the sample text as the input of the first generation model, for example, "entity 1: type 1; entity 2: type 2; relationship [SEP] sample text", instead of using the replaced sample text as the input of the first generation model.

[0080] Based on any of the above embodiments, the template generation model is obtained based on the sample triplet information and the sample question template corresponding to the sample triplet information, and is obtained through the joint adversarial training of the template discrimination model; the template discrimination model is used to discriminate the authenticity of the generated question template and the sample question template, and the generated question template is obtained by the template generation model based on the sample triplet information.

[0081] Specifically, when training the template generation model, the sample triplet information can be used as the training sample, and the sample question template corresponding to the sample triplet information can be used as the training label for supervised training, so that the template generation model can learn the mapping relationship between the sample triplet information and the sample question template in the training process, so that the template generation model obtained by training can apply the above mapping relationship to generate a corresponding question template for the input triplet information, thereby achieving the purpose of template generation. However, the template generation model obtained by applying the above supervised training method to template generation may have the problem of distortion. Considering this, the embodiment of the application adopts the idea of generative adversarial networks (GAN), and performs adversarial training on the template generation model in conjunction with the template discrimination model.

[0082] In the adversarial training, the template generation model can be regarded as a generator, and the template discrimination model can be regarded as a discriminator. As the generator, the template generation model can generate a template for the input sample triple information, so as to output a generated question template. As the discriminator, the template discrimination model can discriminate the input template, that is, distinguish whether the input template is a generated question template generated by the generator or a real sample question template. In this process, the generator and the discriminator play against each other. The generator takes the output of the generated question template as similar as possible to the sample question template as a means, in order to achieve the purpose that the discriminator is difficult to distinguish the sample question template and the generated question template. The discriminator takes the output of the discrimination result consistent with the actual situation of the input template as a means, in order to achieve a more accurate and reliable discrimination effect.

[0083] The method provided by the embodiment of the application introduces a template generation and adversarial mechanism to train a model generation model. The template generation model guarantees the template generation capability for triple information. The template generation model not only achieves the purpose of template generation, but also outputs a question template closer to a real template. The naturalness and fidelity of the question template are guaranteed, and the quality of the question template is greatly improved.

[0084] Based on any of the above embodiments, Figure 4 is a flowchart of a question template generation method provided by the application, as shown in Figure 4 the step 120 includes:

[0085] In step 121, triple extraction is performed on the question text to obtain triple of the question text. The question text is triple information in the form of text.

[0086] In step 122, the triple of the question text and the question text are input into the template generation model to obtain a question template output by the template generation model.

[0087] Specifically, when the triple information of the question template to be generated is triple information in the form of text, that is, the question text, triple extraction can be performed on the question text to obtain triple of the question text. Then, in order to further guarantee the quality of the generated question template, the triple of the question text and the question text can be input into the template generation model, so as to obtain a question template output by the template generation model. Here, the input of the template generation model can be in the form of combination of the question text and the triple of the question text, for example, "entity 1: type 1; entity 2: type 2; relationship [SEP] question text".

[0088] The method provided by the embodiment of the application realizes automatic template generation based on unsupervised question texts, while ensuring the quality of the generated question templates, by performing triple extraction on the question text, inputting the triple of the question text and the question text into a template generation model, and the like.

[0089] In any of the above embodiments, Figure 5 is a flowchart of the triple extraction method provided by the application, as Figure 5 shown, in step 121, triple extraction is performed on the question text to obtain the triple of the question text, including:

[0090] In step 1211, entity recognition is performed on the question text to obtain entity pairs and the types of each entity.

[0091] In step 1212, relation extraction is performed on the entity pairs to obtain the relations between the entity pairs.

[0092] In step 1213, the triple of the question text is constructed based on the entity pairs, the types of each entity, and the relations between the entity pairs.

[0093] Specifically, the triple extraction on the question text can be performed in the following manner: first, entity recognition is performed on the question text to identify the entity pairs in the question text and the types of each entity in the entity pairs, where the types are the abstraction of the entity set having the same characteristics or attributes; then, relation extraction is performed on the entity pairs to obtain the relations between the entity pairs; on this basis, for each entity identified, the type of the entity can be mounted at the position of the entity, and the type is combined with the relations between the entity pairs, thereby obtaining the triple of the question text.

[0094] For example, the question text is “In which year was Qian Xuesen born in Shanghai?”, entity recognition can be performed on the question text to obtain the entity pairs “Qian Xuesen” and “Shanghai”, and the types of “Qian Xuesen” and “Shanghai” are “famous person” and “region” respectively; then, relation extraction is performed on the entity pairs to obtain the relation “place of birth” between the entity pairs; on this basis, the triple of the question text “Qian Xuesen: famous person; Shanghai: region; place of birth” can be constructed.

[0095] The method provided by the embodiment of the application can further improve the quality of the question templates by constructing the triple of the question text according to the entity pairs, the types of each entity, and the relations between the entity pairs, so that the subsequent template generation model can generate question templates according to the triple.

[0096] In any of the above embodiments, the question template includes the types of each entity in the triple information and the non-entity text in the question corresponding to the triple information.

[0097] Specifically, the problem template is a general question pattern with an extended example. Unlike the existing problem templates, which are usually in the form of, for example, "what is the XXX of XXX", the quality of the template is not high, and in the embodiment of the present application, the template generation model generates a corresponding problem template based on the input triple information. The generated problem template can include the specific types of each entity in the triple information and the non-entity text in the triple information corresponding question, thereby improving the accuracy of template matching in the question and answer system.

[0098] For example, the triple information is "Qian Xuesen: famous person; Shanghai: region; birthplace", the specific types of each entity in the triple information are "famous person" and "region" respectively, the triple information corresponding question is "In which year was Qian Xuesen born in Shanghai?", and the non-entity text is "in which year was born in". The problem template can be in the form of "<e1: famous person> in which year was born in <e2: region>", wherein e1 and e2 are entities to be substituted in the problem template.

[0099] Based on any of the above embodiments, the entity recognition of the question text can be realized by an entity recognition model. Before that, the entity recognition model can be obtained by pre-training in the following way:

[0100] S1.1: Collect training data and pre-process;

[0101] Collect sample question and answer pair texts as training data, and label each training data. The named entity in the sample question text is labeled. Here, the sample question and answer pair text is, for example, Example 1:

[0102] Question: In which year was Qian Xuesen born in Shanghai?

[0103] Answer: 1911

[0104] The knowledge base subgraph related to the named entity "Qian Xuesen" is shown in Figure 6 .

[0105] Taking Example 1 as an example, the named entities "Qian Xuesen" and "Shanghai" need to be labeled. Figure 7 is an example diagram of the training sample label of the entity recognition model provided by the present application. In order to facilitate the subsequent model training, the training sample label also needs to be constructed in the form of Figure 7 . For each character in the sample question text, two 0-1 vectors equal in length to the sample question text are used to label whether the corresponding character is the beginning or end of a named entity:

[0106] S1.2: Determine the model topology;

[0107] Figure 8 is a structural diagram of the entity recognition model provided by the present application, as shown inFigure 8 As shown, the model topology of the entity recognition model comprises: an input layer, an encoding layer, and an output layer:

[0108] The input layer: since the entity recognition model in the embodiment of the application adopts a pre-trained language model as an encoder, the input form is "[CLS]+ sample question text + [SEP]", wherein [CLS] and [SEP] are symbols for identifying sentences and segments of the pre-trained language model;

[0109] The encoding layer: the pre-trained language model Bert (Bidirectional Encoder Representations from Transformers) is mainly used as an encoder to encode the semantic features of the input sample question text; Bert is mainly stacked by 12 layers of transformer encoders, and is pre-trained on a large-scale general corpus, so that the encoder has good ability to extract context information of the text, and only needs to be fine-tuned on a specific task corpus to achieve good results. The encoding layer outputs a deep semantic representation corresponding to each character in the original sample question text, which is a 768-dimensional vector. Assuming that the length of the input "[CLS]+ sample question text + [SEP]" is 30, the output of the encoding layer is a two-dimensional matrix of (30, 768).

[0110] The output layer: the output layer comprises two fully connected networks, one of which outputs the probability s i that each character in the sample question text is the beginning of a named entity, and the other outputs the probability e i that each character in the sample question text is the end of a named entity:

[0111] s i =σ(W s h i +b s )

[0112] e i =σ(W e h i +b e )

[0113] Wherein, σ represents a sigmoid activation function, h i represents a hidden representation corresponding to the token i output by Bert, W s , W e , b s , and b e are learnable parameters.

[0114] S1.3: Based on the training data collected and labeled in step S1.1, train the entity recognition model.

[0115] During training, first construct the training data into the model input form in the manner of step S1.2, input the entity recognition model, obtain the probability of different characters in the sample question text as the beginning and end of the named entity, calculate the cross-entropy loss of the model output and the training sample label constructed in step S1.1, then perform gradient backpropagation and parameter update, and finally train the entity recognition model.

[0116] Further, the entity recognition model can also include an entity type classification layer, which is used to classify the recognized entity by entity type. The specific method is to perform type classification on the matched entity start and end position vector [h i ,h j ] after full connection transformation:

[0117] c=softmax(W c [h i ;h j ]+b c )

[0118] Wherein, c is the predicted type corresponding to the entity start and end position vector [h i ,h j ], W c , b c are learnable parameters.

[0119] The type label corresponding to the entity type classification layer can be obtained by labeling the type of the entity in the training sample in step S1.1. For example, the type of the "Qian Xuesen" entity is "famous person".

[0120] After training, the entity recognition model trained can be used to perform entity recognition on the question text, so as to obtain the entity pair in the question text and the type of each entity. The specific implementation can be: first, construct the model input of the entity recognition model according to the input form in step S1.2; then, input the constructed model input into the trained entity recognition model, so as to obtain the recognized entity pair in the question text and the type of each entity.

[0121] Based on any of the above embodiments, the relationship extraction of the entity pair can be realized by a relationship extraction model. Before that, the relationship extraction model can be pre-trained in the following way:

[0122] S2.1: Collect training data and pre-process;

[0123] For the named entity labeled in step S1.1, keep the sample question text containing more than two entities, and label the relationship between the named entities in each sample question text. Taking example one as an example, the relationship between the named entities "Qian Xuesen" and "Shanghai" is labeled as "Qian Xuesen -> birthplace -> Shanghai".

[0124] S2.2: Determine the model topology structure;

[0125] Figure 9 is a structural diagram of the relationship extraction model provided by the present application, as shown in Figure 9 The model topology structure of the relationship extraction model includes: an input layer, an encoding layer, and an output layer.

[0126] The input layer: since the entity recognition model in the embodiment of the present application uses a pre-trained language model as an encoder, the input form is "[CLS]+entity1+entity2+[SEP]+sample question text+[SEP]";

[0127] The encoding layer: the relationship extraction model uses Bert as an encoder to encode the semantic features of the input sample question text; the structure of Bert is the same as that used in step S1.2, and is not repeated. The encoding layer outputs the deep semantic representation corresponding to each character in the original sample question text, which is a 768-dimensional vector. Assuming that the length of the input "[CLS]+entity1+entity2+[SEP]+sample question text+[SEP]" is 35, the output of the encoding layer is a two-dimensional matrix of (35, 768).

[0128] The output layer: the output layer uses the hidden representation h [CLS] of the [CLS] position to predict the relationship type between entities, and maps h [CLS] to the probability r of different relationship types through a fully connected network and a softmax classifier:

[0129] r=softmax(W r h [CLS] +b r )

[0130] Where W r , b r are learnable parameters.

[0131] S2.3: Train the relationship extraction model based on the training data labeled in step S2.1.

[0132] During training, first, the training data is structured into the model input form in the manner of step S2.2, input into the relation extraction model, the probability of the relation between the entity pairs in the question is obtained, the cross-entropy loss is calculated between the model output and the correct label structured in step S2.1, then the gradient is back propagated and the parameters are updated, and finally the relation extraction model is trained.

[0133] After the training is completed, the entity pairs in the question text can be subjected to relation extraction based on the trained relation extraction model, so as to obtain the relation between the entity pairs. The specific implementation manner can be: first, the entity pairs in the question text are structured into the model input of the relation extraction model according to the input form in step S2.2; then, the structured model input is input into the trained relation extraction model, so as to obtain the relation between the entity pairs output by the relation extraction model.

[0134] Based on any of the above embodiments, Figure 10 is a flowchart of the third template generation model training method provided by the present application, as shown in Figure 10 The template generation model is trained in the following manner: first, sample triple information is collected, including sample text in the form of text, i.e. unsupervised sample text, and sample triples in the form of triples, i.e. sample triples, and sample question templates corresponding to the sample text are obtained, and sample question templates corresponding to the sample triples are obtained;

[0135] Then, the sample text is input into a pre-constructed triple extraction model, so as to obtain the triples in the sample text output by the triple extraction model. The triple extraction model can include a trained entity recognition model and a relation extraction model. If there are multiple entity pairs in the sample text, one entity pair can be selected each time to construct a triple. Then, the sample text and the triples in the sample text are spliced as the input of the template generation model to generate a fake template, and a real sample question template is used as the input of the template discrimination model.

[0136] For example, the sample text is “In which year was Qian Xuesen born in Shanghai?”. Two entities and their types, Qian Xuesen (famous person) and Shanghai (region), and the relation between the two entities, i.e. “place of birth”, can be obtained by the entity recognition model and the relation extraction model. Thus, the triple corresponding to the sample text, “Qian Xuesen: famous person; Shanghai: region; place of birth”, can be constructed. The sample text and the triples in the sample text are spliced to obtain “Qian Xuesen: famous person; Shanghai: region; place of birth [sep] In which year was Qian Xuesen born in Shanghai?” as the input of the template generation model, and the input of the template discrimination model is “<e1: famous person> is in which year born in <e2: region>”.

[0137] On this basis, the template generation model and the template discrimination model can be jointly adversarial training according to the sample text, the triplets of the sample text and the sample question template, and the sample triplets and the sample question template of the sample triplets, where the loss function of the joint adversarial training is min G max D V(D, G) is:

[0138]

[0139] In the formula, D(x) is the template discrimination probability of the sample question template x, is a discrimination loss calculation function for the sample question template x, is a judgment loss calculation function for the generated question template G(z), and the generated question template G(z) is obtained by the template generation model based on the sample triplet information.

[0140] The template discrimination model also uses Bert, and finally determines whether it is a real template by taking the [cls] vector for binary classification. Based on this, the generation result of the template generation model is optimized by confrontation, and finally the trained template generation model is obtained.

[0141] In addition, considering that in the natural language template generation model, if gradient sampling is performed, the gradient cannot be transmitted to the template discrimination model, in order to ensure continuous gradient, the output of Gumble-softmax is used to obtain the text encoding of the entire template generated by the template generation model. It can be understood that for the template discrimination model, when the input is real data, the input is the original text of the real template, and when the input is the data generated by the template generation model, the input is the text encoding of the generated template.

[0142] Based on the above embodiments, considering that some existing question template generation methods based on models use entity relationship models to extract entity relationship pairs in the question, and then directly replace the entity relationship pairs in the question to obtain the question template, such a method of only replacing entity pairs cannot obtain high-quality templates.

[0143] To this end, the embodiment of the present application provides a question template generation method and system based on entity recognition and relationship extraction model. The system inputs the triplet information into the template generation model to obtain the question template output by the template generation model, and the triplet information includes text form and / or triplet form, so as to realize both inputting text and obtaining template after triplet extraction, and inputting triplet and obtaining template, and by introducing the template generation and adversarial mechanism to train the model generation model, the quality of the generated question template is greatly improved.

[0144] Based on any of the above embodiments, the embodiment of the present application provides a question and answer method. Figure 11 is a flowchart of the question and answer method provided by the present application, as shown in the figure, the method comprises: Figure 11

[0145] Step 1110, obtaining the inquiry text.

[0146] Specifically, the inquiry text is the text corresponding to the question raised by the user, and the inquiry text can be obtained from the corpus data generated in the human-computer interaction process. The corpus data can be text or voice data. The voice data can be transcribed through voice recognition, and then the inquiry text is obtained.

[0147] Step 1120, obtaining the answer of the inquiry text based on the question template library;

[0148] The question template library contains question templates, which are generated based on the question template generation method provided by the above method.

[0149] Specifically, after obtaining the inquiry text, the inquiry text can be matched with the multiple question templates in the pre-constructed question template library, so as to obtain the target question template corresponding to the inquiry text. On this basis, the answer corresponding to the inquiry text can be obtained according to the target question template and fed back to the user. Here, the specific template matching method can be to extract the entity pair in the inquiry text, and then perform template matching according to the entity pair, so as to obtain the target question template.

[0150] In addition, before performing step 1120, the question template library can also be pre-constructed, and each question template in the question template library can be generated by the following method:

[0151] First, determine the triple information; the triple information is the information of the question template to be generated, which can be in the form of text, triple or a combination of text and triple. Here, the text form is a sentence form with complete text semantics, for example, "In which year was Qian Xuesen born in Shanghai?", the triple form can be an element combination form composed of an entity pair, the type of each entity and the relationship between the entity pair, for example, "entity 1: type 1; entity 2: type 2; relationship".

[0152] ​Then, considering that the template scheme based on manual writing is commonly used in the current common question and answer system, the writing efficiency of the template is low, and the human cost is large. In view of this problem, after the triple information is determined, the template generation model pre-trained is applied to generate the template based on the input triple information, so as to obtain the high-quality question template output by the template generation model. Here, the question template is a general question sentence with an extended example, which can be used for template matching in the question and answer system.

[0153] Before that, the template generation model can also be pre-trained, and the template generation model can be trained in the following manner: first, a large amount of sample triple information is collected, the form of the sample triple information can include a text form and a triple form, and the sample question template corresponding to the sample triple information is obtained by labeling. Then, the initial template generation model is trained by using the sample triple information and the sample question template corresponding to the sample triple information, so as to obtain the template generation model. Here, the initial template generation model can be a language model.

[0154] It should be noted that when the template generation model is trained, the input of the template generation model includes two kinds of training samples, which are sample text in the form of text and sample triple in the form of triple. The template generation model is trained by using the sample text and the sample question template corresponding to the sample text, so that the template generation model learns the triple information in the reference template and the complete semantic information of the whole sentence, so that the template generation model obtained by training can generate the corresponding question template for the input question text, and the coherence of the question template is also guaranteed.

[0155] Furthermore, the template generation model is trained by using the sample triple and the sample question template corresponding to the sample triple, mainly in order to utilize the advantages of the language model, so that the template generation model can directly generate a reasonable question template according to the knowledge of the language model and the input triple when there is no reference text. Under the comprehensive action of the above two aspects, the template generation effect of the template generation model obtained by training is guaranteed, and on this basis, when the template generation model obtained by training is applied to generate the template, no matter which form of triple information is input, a high-quality question template can be generated, and the universality and practicality of the template generation method are improved.

[0156] The method provided by the embodiment of the present application realizes automatic generation of question templates by generating templates based on input triple information by using a template generation model, constructs a question template library based on the question templates, and greatly improves the construction efficiency and quality of the question template library. On this basis, template matching of a question and answer system is completed based on the question template library, a question asked by a user is found, and therefore the answer corresponding to the question can be quickly and accurately queried.

[0157] The question template generation device provided by the present application is described below. The question template generation device described below can be referred to in correspondence with the question template generation method described above.

[0158] Based on any of the above embodiments, the present embodiment provides a question template generation device. Figure 12 is a structural schematic diagram of the question template generation device provided by the present application, as Figure 12 indicated, the device comprises:

[0159] The determining module 1210 is configured to determine triple information. The form of the triple information includes a text form and / or a triple form.

[0160] The generating module 1220 is configured to input the triple information into a template generation model to obtain a question template output by the template generation model.

[0161] The template generation model is trained based on sample triple information and sample question templates corresponding to the sample triple information. The form of the sample triple information includes a text form and a triple form.

[0162] The device provided by the present embodiment trains the template generation model according to the sample text, the triple of the sample text, and the sample question template of the sample triple, and the sample triple and the sample question template of the sample triple, guarantees the effect of the template generation model on the triple, and guarantees the semantic coherence of the template generated by the template generation model because the template generation model can learn the complete semantic information of the sample text, and improves the efficiency and quality of the question template library constructed based on the knowledge base.

[0163] Based on any of the above embodiments, the template generation model is trained based on the following steps:

[0164] The triple extraction is performed on the sample text to obtain the triple of the sample text. The sample text is sample triple information in a text form.

[0165] The template generation model is trained based on the sample text, the triple of the sample text, and the sample question template, and the sample triple and the sample question template of the sample triple. The sample triple is sample triple information in a triple form.

[0166] Based on any of the above embodiments, based on the sample text, the triplets of the sample text and the sample question template, and the sample triplets and the sample question template of the sample triplets, the template generation model is trained, including:

[0167] Based on the sample text, the triplets of the sample text and the sample question template, the first generation model is trained to obtain the second generation model;

[0168] Based on the sample triplets and the sample question template of the sample triplets, the second generation model is trained to obtain the template generation model.

[0169] Based on any of the above embodiments, the template generation model is obtained by jointly training the template discriminant model based on the sample triplet information and the sample question template corresponding to the sample triplet information; the template discriminant model is used to discriminate the authenticity of the generated question template and the sample question template, and the generated question template is obtained by the template generation model based on the sample triplet information.

[0170] Based on any of the above embodiments, the generation module 1220 includes:

[0171] The triplet extraction submodule is configured to extract triplets from the question text to obtain triplets of the question text, the question text being triplet information in a text form;

[0172] The template generation submodule is configured to input the triplets of the question text and the question text into the template generation model to obtain a question template output by the template generation model.

[0173] Based on any of the above embodiments, the triplet extraction submodule is configured to:

[0174] Perform entity recognition on the question text to obtain entity pairs and types of each entity;

[0175] Perform relation extraction on the entity pairs to obtain relations between the entity pairs;

[0176] Based on the entity pairs, the types of each entity and the relations between the entity pairs, construct triplets of the question text.

[0177] Based on any of the above embodiments, the question template includes the types of each entity in the triplet information and non-entity text in the question corresponding to the triplet information.

[0178] The question and answer device provided by the present application is described below, and the question and answer device described below can be correspondingly referred to the question and answer method described above.

[0179] Based on any of the above embodiments, the present application provides a question and answer device. Figure 13 is a structural schematic diagram of the question and answer device provided by the present application, asFigure 13 As shown in the figure, the device comprises:

[0180] The acquisition module 1310 is configured to acquire the inquiry text.

[0181] The answering module 1320 is configured to acquire the answer to the inquiry text based on the question template library.

[0182] The question template library comprises question templates, which are generated based on the question template generation method provided in the above methods.

[0183] The device provided by the embodiment of the present application generates question templates based on the input triple information by applying the template generation model, thereby realizing the automatic generation of question templates, constructing a question template library based on the question templates, greatly improving the construction efficiency and quality of the question template library, and on this basis, completing the template matching of the question and answer system based on the question template library, finding the question asked by the user, and thereby quickly and accurately querying the answer corresponding to the question.

[0184] Figure 14 An example of an entity structure diagram of an electronic device is shown in FIG. 1. Figure 14 As shown in the figure, the electronic device can comprise a processor 1410, a communications interface 1420, a memory 1430 and a communications bus 1440, wherein the processor 1410, the communications interface 1420 and the memory 1430 complete mutual communication through the communications bus 1440. The processor 1410 can invoke the logical instructions in the memory 1430 to execute the question template generation method, which comprises: determining triple information, the form of the triple information comprising a text form and / or a triple form; inputting the triple information into a template generation model to obtain the question template output by the template generation model; wherein the template generation model is trained based on sample triple information and sample question templates corresponding to the sample triple information, and the form of the sample triple information comprises the text form and the triple form.

[0185] Or, to execute the question and answer method, which comprises: acquiring the inquiry text; acquiring the answer to the inquiry text based on the question template library; the question template library comprises question templates, which are generated based on the question template generation method provided in the above methods.

[0186] Further, the logic instructions in the memory 1430 described above can be implemented in the form of software functional units and sold or used as standalone products, which can be stored in a computer readable storage medium. Based on such understanding, the technical solutions of the present application essentially or partially contribute to the prior art, or part of the technical solutions can be embodied in the form of a software product. The computer software product is stored in a storage medium, and includes a number of instructions for causing a computer device (which can be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present application. The aforementioned storage medium includes: a U disk, a mobile hard disk, a read-only memory (ROM, Read-Only Memory), a random access memory (RAM, Random Access Memory), a magnetic disk or an optical disk, and various media that can store program codes.

[0187] In another aspect, the present application also provides a computer program product, which comprises a computer program, the computer program can be stored on a non-transitory computer readable storage medium, and the computer program can be executed by a processor to enable a computer to execute the problem template generation method provided by the above-mentioned method, which comprises: determining triple information, the form of the triple information comprising a text form and / or a triple form; inputting the triple information into a template generation model to obtain a problem template output by the template generation model; wherein the template generation model is trained based on sample triple information and sample problem templates corresponding to the sample triple information, and the form of the sample triple information comprises the text form and the triple form.

[0188] Alternatively, the above-mentioned question and answer method is executed, which comprises: acquiring an inquiry text; acquiring an answer to the inquiry text based on a problem template library; the problem template library comprises a problem template, and the problem template is generated based on the problem template generation method provided by the above-mentioned method.

[0189] In another aspect, the present application also provides a non-transitory computer readable storage medium, which stores a computer program, and the computer program is executed by a processor to implement the problem template generation method provided by the above-mentioned method, which comprises: determining triple information, the form of the triple information comprising a text form and / or a triple form; inputting the triple information into a template generation model to obtain a problem template output by the template generation model; wherein the template generation model is trained based on sample triple information and sample problem templates corresponding to the sample triple information, and the form of the sample triple information comprises the text form and the triple form.

[0190] Or, to perform the above provided question and answer method, the method comprises: obtaining a query text; obtaining an answer of the query text based on a question template library; the question template library comprises a question template, and the question template is generated based on the question template generation method provided in the above method.

[0191] The device embodiments described above are only illustrative, wherein the units described as separate components can or can not be physically separated, and the components displayed as units can or can not be physical units, i.e., can be located in one place or distributed on multiple network units. Part or all of the modules can be selected to achieve the purpose of the embodiment scheme according to actual needs. Those skilled in the art can understand and implement without creative labor.

[0192] Through the description of the above embodiments, those skilled in the art can clearly understand that each embodiment can be realized by means of software and the necessary general hardware platform, and of course, can also be realized by hardware. Based on such understanding, the above technical solutions can be embodied in the form of a software product, which can be stored in a computer readable storage medium, such as a ROM / RAM, a magnetic disk, an optical disk, etc., and includes a plurality of instructions to make a computer device (which can be a personal computer, a server, or a network device, etc.) execute the methods described in each embodiment or some parts of the embodiments.

[0193] Finally, it should be noted that: the above embodiments are only used to illustrate the technical solutions of the present application, and not to limit them; although the present application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that: it can still modify the technical solutions recorded in the foregoing embodiments, or make equivalent replacement to part of the technical features; and these modifications or replacements do not make the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the embodiments of the present application.

Claims

1. A method for generating problem templates, characterized in that, include: Determine triple information, wherein the triple information is in text form and / or triple form; The triplet information is input into the template generation model to obtain the problem template output by the template generation model; The template generation model is trained based on sample triple information and the sample question template corresponding to the sample triple information. The sample triple information includes the text form and the triple form. The template generation model is trained based on the following steps: The sample text is subjected to triple extraction to obtain triples of the sample text, and the sample text is sample triple information in the form of the text. Training the template generation model based on the sample text, the triples of the sample text, and the sample question template, as well as the sample triples and the sample question template of the sample triples, includes: training a first generation model based on the sample text, the triples of the sample text, and the sample question template to obtain a second generation model; and training the second generation model based on the sample triples and the sample question template of the sample triples to obtain the template generation model. The sample triplet is sample triplet information in the form of the triplet.

2. The problem template generation method according to claim 1, characterized in that, The template generation model is obtained through adversarial training of the template discrimination model based on sample triplet information and the sample question template corresponding to the sample triplet information. The template discrimination model is used to determine the authenticity of the generated question template and the sample question template. The generated question template is generated by the template generation model based on the sample triplet information.

3. The problem template generation method according to claim 1, characterized in that, The step of inputting the triplet information into the template generation model to obtain the problem template output by the template generation model includes: The question text is extracted into triplets to obtain triplets of the question text, and the question text is triplet information in the form of the text. The triples of the question text and the question text are input into the template generation model to obtain the question template output by the template generation model.

4. The problem template generation method according to claim 3, characterized in that, The process of extracting triples from the question text to obtain triples of the question text includes: Entity recognition is performed on the question text to obtain entity pairs and the type of each entity; Relationships are extracted from the entity pairs to obtain the relationships between them; Based on the entity pairs, the types of each entity, and the relationships between the entity pairs, a triplet of the question text is constructed.

5. The problem template generation method according to claim 1, characterized in that, The question template includes the type of each entity in the triple information, as well as the non-entity text in the question corresponding to the triple information.

6. A question-and-answer method, characterized in that, include: Obtain the query text; Based on the question template library, obtain the answer to the query text; The problem template library contains problem templates, which are generated based on the problem template generation method as described in any one of claims 1 to 5.

7. A problem template generation device, characterized in that, include: A determination module is used to determine triplet information, wherein the triplet information includes text form and / or triplet form; The generation module is used to input the triplet information into the template generation model to obtain the problem template output by the template generation model; The template generation model is trained based on sample triple information and the sample question template corresponding to the sample triple information. The sample triple information includes the text form and the triple form. The template generation model is trained based on the following steps: The sample text is subjected to triple extraction to obtain triples of the sample text, and the sample text is sample triple information in the form of the text. Training the template generation model based on the sample text, the triples of the sample text, and the sample question template, as well as the sample triples and the sample question template of the sample triples, includes: training a first generation model based on the sample text, the triples of the sample text, and the sample question template to obtain a second generation model; and training the second generation model based on the sample triples and the sample question template of the sample triples to obtain the template generation model. The sample triplet is sample triplet information in the form of the triplet.

8. A question-and-answer device, characterized in that, include: The acquisition module is used to acquire query text; The answer module is used to obtain the answer to the query text based on the question template library; The problem template library contains problem templates, which are generated based on the problem template generation method as described in any one of claims 1 to 5.

9. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the program, it implements the steps of the question template generation method as described in any one of claims 1 to 5 or the question-and-answer method as described in claim 6.

10. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the steps of the question template generation method as described in any one of claims 1 to 5 or the question-and-answer method as described in claim 6.

Citation Information

Patent Citations

  • Knowledge base question-answering system and device based on question generation

    CN112015915A

  • Conversation information generation method and device and electronic equipment

    CN112650768A