Question and answer method and device, electronic equipment, storage medium and program product
By annotating pronouns in the target question and combining them with historical question-and-answer content, the problem of inaccurate pronoun references in existing technologies is solved, resulting in higher answer accuracy and user experience.
Patent Information
- Application Number
- CN202110230280.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-03-02
- Publication Date
- 2026-01-02
- Estimated Expiration
- 2041-07-02
AI Technical Summary
Existing question-answering methods cannot accurately identify the object indicated by a pronoun when dealing with questions containing pronouns, resulting in low accuracy of the answers.
By annotating pronouns in the target question, word embedding, segmentation embedding, position embedding, and category information of the pronouns are obtained. Combined with the historical question-and-answer content of the target document, the trained BERT model is used to obtain feature information of the input sequence and finally output the answer.
It improves the accuracy of identifying the referent of pronouns, thereby enhancing the accuracy of answers and the user experience.
Smart Images

Figure CN114996415B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to natural language processing technology, and particularly relates to a question and answer method and device, an electronic device, a storage medium and a program product. BACKGROUND
[0002] Machine reading comprehension refers to that an electronic device can give an answer corresponding to a question after obtaining the question. When an existing question and answer method is used to obtain the answer corresponding to the question proposed by a user, the electronic device can extract the answer corresponding to the question from a given document based on the question proposed by the user.
[0003] However, when the question proposed by the user includes a pronoun, the existing question and answer method can not obtain the object indicated by the pronoun in the question, and thus can result in low accuracy of obtaining the answer corresponding to the question. SUMMARY
[0004] The present application provides a question and answer method, device, electronic device, storage medium and program product to improve the accuracy of obtaining the answer corresponding to the question.
[0005] In a first aspect, the present application provides a question and answer method, which comprises:
[0006] receiving a question and answer request for a target document, the question and answer request comprising a target question;
[0007] adding a label to a pronoun in the target question to obtain a labeled target question;
[0008] obtaining embedding information of each first word in an input sequence; the input sequence comprising: the labeled target question, the target document, and the previous N rounds of historical questions and answers corresponding to the historical questions for the target document; the N being an integer greater than or equal to 1; the embedding information of the pronoun in the labeled target question being used to indicate word embedding information, segmentation embedding information, position embedding information, and category information of the pronoun;
[0009] obtaining feature information of the input sequence according to the embedding information of each first word in the input sequence;
[0010] obtaining an answer to the target question according to the feature information of the input sequence;
[0011] outputting the answer to the target question.
[0012] Optionally, the embedding information of the pronoun is a weighted sum of the word embedding information, the segmentation embedding information, the position embedding information, and the category information of the pronoun.
[0013] Optionally, the obtaining the answer to the target question according to the feature information of the input sequence comprises:
[0014] determining whether the target question is a non-fact type question, and extracting an initial answer to the target question from the target document;
[0015] if the target question is a non-fact type question, obtaining a predicted word for each second word in the initial answer;
[0016] obtaining the answer to the target question according to the initial answer and the predicted word for each second word in the initial answer.
[0017] Optionally, the obtaining the answer to the target question according to the initial answer and the predicted word for each second word in the initial answer comprises:
[0018] for each second word in the initial answer, if a fluency probability of the second word in a target sentence is less than a fluency probability of the predicted word of the second word in the target sentence, the predicted word is used to replace the second word in the target sentence to obtain the answer, wherein the target sentence is a sentence to which the second word belongs in the initial answer.
[0019] Optionally, the obtaining the predicted word for each second word in the initial answer comprises:
[0020] obtaining the predicted word for each second word in the initial answer by using a preset dictionary, wherein the preset dictionary comprises the first word in the target question and the first word in the document.
[0021] Optionally, after the determining whether the target question is a non-fact type question and extracting the initial answer to the target question from the target document, the method further comprises:
[0022] if the target question is a fact type question, the initial answer to the target question is taken as the answer to the target question.
[0023] In a second aspect, the present application provides a question and answer device, the device comprising:
[0024] a receiving module configured to receive a question and answer request for a target document, the question and answer request comprising a target question;
[0025] The processing module is configured to add a label to a pronoun in the target question to obtain a labeled target question, obtain embedding information of each first word in an input sequence, obtain feature information of the input sequence according to the embedding information of each first word in the input sequence, and obtain an answer to the target question according to the feature information of the input sequence. The input sequence includes the labeled target question, the target document, and the first N historical questions of the target document and answers corresponding to the historical questions. N is an integer greater than or equal to 1. The embedding information of the pronoun in the labeled target question includes word embedding information, segmentation embedding information, position embedding information, and category information of the pronoun.
[0026] The output module is configured to output the answer to the target question.
[0027] In a third aspect, the present application provides an electronic device, including at least one processor, a memory, and a communication interface.
[0028] The memory stores computer-executable instructions.
[0029] The at least one processor executes the computer-executable instructions stored in the memory, so that the electronic device executes the method of any one of the first aspect.
[0030] In a fourth aspect, the present application provides a computer-readable storage medium, which stores computer-executable instructions. When the computer-executable instructions are executed by a processor, the method of any one of the first aspect is implemented.
[0031] In a fifth aspect, the present application provides a computer program product, which includes a computer program. When the computer program is executed by a processor, the method of any one of the first aspect is implemented.
[0032] The question and answer method, device, electronic device, storage medium, and program product provided by the present application take the target question, the target document, and the first N historical questions of the target document and answers corresponding to the historical questions as an input sequence. When the target question includes a pronoun, embedding information of each first word in the input sequence is obtained. For the target question, word embedding information, segmentation embedding information, position embedding information, and category information of the pronoun are obtained as the embedding information of the pronoun. Then, according to the embedding information of each first word in the input sequence including the category information of the pronoun, an answer to the target question is obtained. Compared with the prior art that only obtains an answer based on a target question and a target document, the present application improves the accuracy of the server in obtaining an object referred to by a pronoun in a target question by combining the category information of the pronoun and the historical question and answer content of the target document, thereby improving the accuracy of obtaining an answer to the target question, and achieving the effect of improving the experience of a user. Attached Figure Description
[0033] To more clearly illustrate the technical solutions in this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0034] Figure 1 This is a schematic diagram illustrating one application scenario of machine reading comprehension.
[0035] Figure 2 For a given document, and an example of questions and answers for that document;
[0036] Figure 3 A flowchart illustrating a question-and-answer method provided in this application;
[0037] Figure 4 A flowchart illustrating a method for obtaining an answer to a target question provided in this application;
[0038] Figure 5 A flowchart illustrating another question-and-answer method provided in this application;
[0039] Figure 6 A flowchart illustrating a method for obtaining feature information of an input sequence provided in this application;
[0040] Figure 7 A schematic diagram of the structure of a question-and-answer device provided in this application;
[0041] Figure 8 This is a schematic diagram of an electronic device structure provided in this application.
[0042] The accompanying drawings illustrate specific embodiments of this application, which will be described in more detail below. These drawings and descriptions are not intended to limit the scope of the concept in any way, but rather to illustrate the concept of this application to those skilled in the art through reference to particular embodiments. Detailed Implementation
[0043] To make the objectives, technical solutions, and advantages of this application clearer, the technical solutions of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0044] For example,Figure 1 An application scenario of machine reading comprehension is shown. As shown in Figure 1 , a terminal device used by a user can receive a question input by the user. Then, the terminal device can send the question to a server through a wireless network. After receiving the question input by the user, the server can obtain an answer to the question from a given document, and send the answer to the terminal device used by the user. Then, the terminal device can output the answer to the question so that the user can know the answer corresponding to the question. The terminal device may, for example, be a computer, a smart speaker, a mobile phone, a tablet computer, etc. Figure 1 In the above, an example is taken in which the terminal device is a computer.
[0045] When obtaining an answer to a question using an existing question and answer method, the server can extract an answer to the question from a given document based on the question input by the user.
[0046] As an example, Figure 2 , a given document and questions and answers to the document are shown. As shown in Figure 2 , for example, for question 1, the server can extract “Zeus” as an answer to question 1 from the given document. For question 2, the server can extract “The crow knew that it had no beautiful place, so it went to the river, picked up the feathers dropped by the birds, carefully inserted them on its body, and then glued them” as an answer to question 2 from the given document.
[0047] However, when the question input by the user includes a pronoun (for example, “it” in question 3 shown in Figure 2 ), the existing question and answer method can not be able to obtain the object indicated by the pronoun, and thus can result in low accuracy in obtaining an answer to the question.
[0048] It is found through research that, for a document, the content of a historical question and a historical answer corresponding to the historical question before a current question input by a user (referred to as historical question and answer content) is related to the current question input by the user. For example, Figure 2 , “it” in question 3 refers to “crow” in question 2 and answer 2.
[0049] In view of this, when a current question input by a user includes a pronoun, the present application proposes a method of obtaining an answer to a target question by combining historical question and answer content of a target document and pronoun category information in the target question. Specifically, by analyzing the association features of the category information of the pronoun and the historical question and answer content of the target document, the accuracy of the server in obtaining the object indicated by the pronoun can be improved, and thus the accuracy of obtaining an answer to the target question including the pronoun can be improved.
[0050] For the convenience of description, the technical solutions of the present application are described in detail below in combination with specific embodiments. The following specific embodiments can be combined with each other, and the same or similar concepts or processes can not be described in some embodiments.
[0051] Figure 3 A flowchart of a question and answer method provided by the present application is shown in FIG. 1. As shown in FIG. 1, the method comprises the following steps: Figure 3
[0052] S101, receiving a question and answer request for a target document. The question and answer request comprises a target question.
[0053] For example, a user can input a question and answer request for a target document into a terminal device used by the user. Then, a server can receive the question and answer request for the target document through a wireless network. Optionally, the question and answer request can be, for example, a text, a picture with a text describing the target question, or a voice input question and answer request, etc.
[0054] Optionally, the target document can be, for example, a preset document stored in the server. Alternatively, the question and answer request can further comprise an identifier of the target document, so that the server can obtain the target document stored in the server in advance according to the identifier of the target document. Alternatively, the question and answer request can further carry the target document.
[0055] S102, adding a label to a pronoun in the target question to obtain a labeled target question.
[0056] Optionally, after receiving the target question, the server can perform part-of-speech analysis on the target question to determine whether the target question comprises a pronoun. For example, the server can perform part-of-speech analysis on the target question according to a preset labeling rule or any existing part-of-speech labeling method. Alternatively, the server can perform part-of-speech analysis on the target question in combination with the preset labeling rule and the part-of-speech labeling method.
[0057] If the target question comprises a pronoun, the server can perform this step to add a label to the pronoun in the target question. For example, the server can label a word with a part-of-speech of a pronoun in the target question when performing part-of-speech analysis on the target question to obtain a labeled target question.
[0058] Optionally, the server can add a label to the pronoun in the target question to indicate that the word is a pronoun. For example, the label can be a preset number or letter, etc.
[0059] S103, obtaining embedding information of each first word in the input sequence.
[0060] The input sequence includes: the annotated target question, the target document, and the first N rounds of historical questions and answers corresponding to the historical questions for the target document. N is an integer greater than or equal to 1. The value of N may, for example, be pre-set according to actual needs and stored in the server. The first word in the above-mentioned input sequence refers to any one of the target question, the target document, and the first N rounds of historical questions and answers corresponding to the historical questions for the target document.
[0061] Optionally, for a document, the server may, for example, store each round of questions and corresponding answers for the document. Then, after obtaining the target document, the server can obtain the first N rounds of historical questions and answers corresponding to the historical questions sent by the same terminal device for the target document.
[0062] The embedding information of each first word in the above-mentioned input sequence may, for example, be used to indicate at least one of token embedding information of the first word, segment embedding information of the first word, and position embedding information of the first word. The embedding information of the pronoun in the annotated target question is used to indicate token embedding information of the pronoun, segment embedding information of the pronoun, position embedding information of the pronoun, and category information of the pronoun.
[0063] For example, after obtaining the above-mentioned target question, the server can classify the pronoun in the target question to obtain the category information of the pronoun in the target question. In actual implementation, the server may, for example, classify the pronoun in the target question according to a pre-set classification rule. For example, the above-mentioned pre-set classification rule may, for example, be determined according to the language of the target question.
[0064] For example, if the target question is in English, the server can divide the category of the pronoun into ten categories (personal pronoun, possessive pronoun, demonstrative pronoun, reflexive pronoun, reciprocal pronoun, interrogative pronoun, relative pronoun, conjunctive pronoun, indefinite pronoun, and replacement word), and determine the category to which the pronoun in the target question belongs. If the target question is in Chinese, the server can divide the category of the pronoun into three categories (personal pronoun, interrogative pronoun, and demonstrative pronoun), and determine the category to which the pronoun in the target question belongs.
[0065] Alternatively, the above-mentioned pre-set classification rule may, for example, be pre-set according to actual needs and stored in the server. The server can obtain the category information of the pronoun according to the pre-set classification rule.
[0066] Optionally, after obtaining the category information of the pronoun in the target question, the server can obtain the embedding information of the pronoun in the target question, for example, by calculating the weighted sum of the word embedding information, the segmentation embedding information, the position embedding information, and the category information of the pronoun in the target question. For example, the server can obtain the embedding information of the pronoun by the following formula (1):
[0067] pos ppe = λ1×pos + λ2×c pron + λ3×seg + λ4×tok (1)
[0068] wherein, pos ppe represents the embedding information of the pronoun, λ1, λ2, λ3, and λ4 represent the coordination factors, and λ1 + λ2 = 1, and the values of λ3 and λ4 can be 1, for example. pos represents the position embedding information of the pronoun, c pron represents the category embedding information of the pronoun, seg represents the segmentation embedding information of the pronoun, and tok represents the word embedding information of the pronoun.
[0069] Alternatively, after obtaining the input sequence, the server can also input the input sequence into the trained Bidirectional Encoder Representations from Transformers (BERT) to obtain the embedding information of each first word in the input sequence, and obtain the embedding information of the pronoun in the target question.
[0070] Further alternatively, the server can also perform part-of-speech analysis on the target document, and the answers to the previous N rounds of historical questions and historical questions corresponding to the target document. If the target document, and / or the answers to the previous N rounds of historical questions and historical questions corresponding to the target document include pronouns, the server can also obtain the embedding information (word embedding information, segmentation embedding information, position embedding information, and category information) of the pronouns in the target document, and / or the answers to the previous N rounds of historical questions and historical questions corresponding to the target document.
[0071] S104, obtaining the feature information of the input sequence according to the embedding information of each first word in the input sequence.
[0072] wherein, the feature information of the input sequence includes the association feature information of the answers to the previous N rounds of historical questions and historical questions corresponding to the target document and the pronoun in the target question.
[0073] Exemplarily, after obtaining the embedding information of each first word in the input sequence, the server can calculate the attention contribution of each first word in the "top N rounds of historical questions of the target document and the answers corresponding to the historical questions" to each first word in the target question and the target document. Then the server obtains the attention score weight of each first word in the target question and the target document according to the attention contribution of each first word in the target question and the target document. Then the server performs weighted summation on each first word in the target question and the target document according to the attention score weight of each first word in the target question and the target document, and further obtains the feature information of the input sequence.
[0074] It should be understood that the above steps S103 and S104 can also be implemented by using the trained BERT model. That is, the server can input the input sequence into the trained BERT model, and the trained BERT model can obtain the feature information of the input sequence according to the embedding information of each first word in the input sequence.
[0075] S105, obtaining the answer of the target question according to the feature information of the input sequence.
[0076] Optionally, after obtaining the feature information of the input sequence, the server can input the feature information of the input sequence into an answer obtaining model to obtain the answer of the target question. The answer obtaining model may, for example, include at least one pre-trained deep learning model. The pre-trained deep learning model can obtain the answer of the target question according to the input feature information.
[0077] Alternatively, the server may, for example, also obtain the answer of the target question according to the feature information of the input sequence and the mapping relationship between the feature information of the input sequence and the answer of the target question. The mapping relationship may, for example, be pre-stored in the server.
[0078] Alternatively, after obtaining the feature information of the input sequence, the server can further determine whether there is feature information of a historical question that is the same as the feature information of the target question in the feature information of the top N rounds of historical questions of the target document. If there is, the server can take the answer corresponding to the historical question as the answer of the target question to improve the efficiency of the server in obtaining the answer of the target question. If there is not, the server can obtain the answer of the target question according to the foregoing method.
[0079] S106, outputting the answer of the target question.
[0080] After the server obtains the answer to the target question, the server can send the answer to a terminal device used by the user. Then the terminal device can output the answer so that the user can obtain the answer. Alternatively, when the execution subject of the above method is the terminal device used by the user, the terminal device can directly output the answer after obtaining the answer to the target question. In specific implementation, the present application does not limit how the terminal device outputs the answer. For example, the terminal device can output the answer to the target question by voice broadcast or display text and the like.
[0081] In the embodiment, the target question, the target document, and the first N rounds of historical questions and answers corresponding to the historical questions of the target document are taken as input sequences. When the target question includes a pronoun, the embedding information of each first word in the input sequence is obtained. For the target question, the word embedding information, segmentation embedding information, position embedding information, and category information of the pronoun in the target question are taken as the embedding information of the pronoun. Then, the answer to the target question is obtained according to the embedding information of each first word in the input sequence including the category information of the pronoun. Compared with the prior art of obtaining the answer based on the target question and the target document, the present application improves the accuracy of the server in obtaining the object referred to by the pronoun in the target question by combining the category information of the pronoun and the historical question and answer content of the target document, and further improves the accuracy of obtaining the answer to the target question, thereby achieving the effect of improving the user experience.
[0082] Considering that the complexity of answers to target questions of different categories (fact type and non-fact type) is different, the server can further optimize the answer to a non-fact type target question with higher complexity before obtaining the answer to the target question, so as to make the answer to the non-fact type target question more fluent, thereby improving the user experience.
[0083] Among them, the fact type target question refers to the question whose corresponding answer is a certain objective fact. For example, questions about “who (who)”, “where (where)”, “when (when)”, “how many (how many)”, “how much (how much)” and the like can be taken as fact type questions. Questions other than fact type questions are non-fact type questions. For example, questions about “how (how)”, “why (why)”, “what (what)” and the like can be taken as non-fact type questions. In specific implementation, it can be determined according to a preset classification rule which questions can be taken as fact type questions (or non-fact type questions).
[0084] Next, how the server obtains the answer to the target question according to the feature information of the input sequence is described. Figure 4 A flowchart of a method for obtaining an answer to a target question provided by the present application is shown in FIG. 1. As shown in FIG. 1, the method comprises the following steps.Figure 4 As shown, as one possible implementation, the step S105 can include the following steps:
[0085] S201, extracting an initial answer of the target question from the target document.
[0086] For example, the server can input the feature information of the input sequence into a trained extractive answer obtaining model, so as to extract the original text of the document as the initial answer of the target question from the target document. The extractive answer obtaining model can be a pre-trained language model, for example. For example, the pre-trained language model can be a BERT model or a Robustly Optimized BERT Pre-training Approach (RoBERTa) model, etc.
[0087] S202, determining whether the target question is a non-factual question. If yes, the server can execute step S203. If no, the server can optionally execute step S205.
[0088] Optionally, before obtaining the answer of the target question, the server can input the target question into a question classification model, and determine whether the target question is a non-factual question according to the output result of the question classification model.
[0089] Alternatively, the server can also determine whether the target question is a non-factual question by judging whether the target question includes a keyword capable of indicating that the target question is a non-factual question. For example, if the target question includes the keyword “why”, the server can determine that the target question is a non-factual question. If the target question does not include any keyword capable of indicating that the target question is a non-factual question, the server can determine that the target question is not a non-factual question.
[0090] S203, obtaining a predicted word of each second word in the initial answer.
[0091] The second word refers to any word in the initial answer.
[0092] Optionally, after obtaining the initial answer, the server can input the initial answer into the generative answer obtaining model to obtain the predicted word of each second word in the initial answer. For example, the generative answer obtaining model can obtain the predicted word of each second word in the initial answer from a preset dictionary. The preset dictionary can include the first word in the target question and the first word in the document. Alternatively, for example, the generative answer obtaining model can also obtain any synonym of the second word in the initial answer as the predicted word of the second word in the initial answer.
[0093] Alternatively, for example, the server can also calculate the relevance of each word in the preset dictionary to each second word in the initial answer, and obtain the word with the highest relevance to the second word as the predicted word of the second word.
[0094] For example, the generative answer obtaining model can be a sequence to sequence (seq2seq) model. The seq2seq model can be composed of a recurrent neural network (RNN), for example.
[0095] S204, obtaining the answer to the target question according to the initial answer and the predicted word of each second word in the initial answer.
[0096] Optionally, after obtaining the predicted word of the second word in the initial answer, the server can calculate the fluency probability of the second word in the target sentence (the fluency probability of a word can also be referred to as the probability of predicting the word) and the fluency probability of the predicted word of the second word in the target sentence. The target sentence is the sentence to which the second word belongs in the initial answer.
[0097] The fluency probability of the second word in the target sentence and the fluency probability of the predicted word of the second word in the target sentence are then compared. In actual implementation, the server can refer to any existing method for obtaining the fluency probability of a word in a target sentence to obtain the fluency probability of the second word in the target sentence and the fluency probability of the predicted word of the second word in the target sentence, which is not limited in the present application.
[0098] If the fluency probability of the second word in the target sentence is less than the fluency probability of the predicted word of the second word in the target sentence, it means that using the predicted word of the second word to form the target sentence can make the fluency of the target sentence better and more consistent with the sentence organized when answering the question artificially. Then, the server can replace the second word with the predicted word of the second word in the target sentence to obtain the answer to the target question.
[0099] If the fluency probability of the second word in the target sentence is greater than or equal to the fluency probability of the predicted word of the second word in the target sentence, it indicates that the target sentence formed by using the second word can make the fluency of the target sentence better, and is more consistent with the sentence organized when artificially answering the question. Therefore, the server can not replace the second word with the predicted word of the second word, but directly use the target sentence formed by the second word to obtain the answer to the target question.
[0100] It should be understood that the present application does not limit how the server obtains the answer to the target question based on the initial answer and the predicted word of each second word in the initial answer. The above method is only a possible implementation provided by the present application. In specific implementation, for example, the server can also directly replace each second word in the initial answer with the predicted word obtained after obtaining the predicted word of each second word in the initial answer. Then, the fluency probability of the sentence formed by each second word in the initial answer is calculated, and the fluency probability of the sentence formed by each predicted word is calculated. Then, the sentence with a greater fluency probability is taken as the answer to the target question.
[0101] S205, taking the initial answer to the target question as the answer to the target question.
[0102] For obtaining the answer to the fact-based target question, optionally, the server can refer to the foregoing step S201 or any other method for obtaining the answer to the target question to extract the initial answer to the target question from the target document, which will not be described herein. The sentence of the answer to the fact-based target question is often short and has little effect on the fluency of the answer. Therefore, the server can directly take the initial answer to the target question as the answer to the target question to improve the efficiency of the server in obtaining the answer.
[0103] It should be understood that although the above embodiment is described by taking the implementation manner of first performing step S201 and then performing step S202 as an example, in specific implementation, the server can first perform step S202 and then perform step S201. Alternatively, the server can simultaneously perform steps S202 and S201.
[0104] In the present embodiment, the target question is divided into a fact-based question and a non-fact-based question, and then the initial answer is extracted from the target document for the non-fact-based target question. Then, the answer to the target question is obtained according to the second word in the initial answer and the predicted word of the second word in the initial answer. The optimization of the answer to the non-fact-based question is realized, so that the answer to the non-fact-based question can be more fluent, and the user experience is further improved.
[0105] Taking the target question, the target document, and the first N rounds of historical questions and answers corresponding to the historical questions for the target document as examples,Figure 5 Another flowchart of the question and answer method provided in the present application is shown. As shown in the figure, the method comprises the following steps: Figure 5
[0106] Step 1: The terminal device used by the user can receive a question and answer request for a target document, wherein the question and answer request includes a target question. Then the terminal device can send the question and answer request to the server. After receiving the question and answer request, the server can obtain pronouns in the input sequence by performing part-of-speech analysis on the input sequence, and add labels to the pronouns to obtain a labeled input sequence.
[0107] Figure 5 In the input sequence, [CLS] is the first character of the input sequence, indicating the beginning of the input sequence. QT1 and QT2 both represent the first word in the target question. [SEP] represents a separator. XT1 and XT2 represent the first word in the target document, and AT1 and AT2 represent the first N historical questions and answers corresponding to the historical questions for the target document. X, Y, L, M and P all represent characters.
[0108] Step 2: The server can obtain the embedding information of each first word in the input sequence. Wherein, the embedding information of the pronoun in the input sequence is used to indicate the word embedding information, segmentation embedding information, position embedding information, and category information of the pronoun.
[0109] For example, the server can obtain the word embedding information, segmentation embedding information and position embedding information of each first word in the input sequence through encoding. For the embedding information of the pronoun, the server can obtain it through the above formula (1).
[0110] Optionally, the position embedding information of the pronoun can also be divided into odd and even dimensional position embedding information of the pronoun. Specifically, the server can obtain the even dimensional position embedding information of the pronoun through formula (2), and obtain the odd dimensional position embedding information of the pronoun through formula (3):
[0111]
[0112]
[0113] In formula (2) and formula (3), b represents the dimension of the position embedding information, PE pron (pos pron ,2b) represents the even dimensional position embedding information of the pronoun, and PE pron (pos pron ,2b+1) represents the odd dimensional position embedding information of the pronoun. pos pron represents the encoding information of the pronoun position. d model d represents the same dimension as word embedding information and segmentation embedding information. model The value can be preset by the user in the server.
[0114] For example, when there are 10 categories of pronouns, Table 1 shows examples of pronouns in each category.
[0115] Table 1
[0116]
[0117] Step 3: Obtain the feature information of the input sequence based on the embedding information of each first word in the input sequence. Figure 6 This is a flowchart illustrating a method for obtaining feature information of an input sequence provided in this application. Figure 6 As shown, X, Y, L, M, P, R, and S all represent text. This represents the previous N rounds of historical questions for the target document. Answers to historical questions in, This represents the i-th round of historical questions preceding the k-th target question and the corresponding answers to those historical questions.
[0118] Specifically, such as Figure 6 As shown, after obtaining the embedding information of each first word in the input sequence, the server can calculate the attention contribution of each first word in "the previous N rounds of historical questions and their corresponding answers for the target document" to the target question and each first word in the target document. Then, based on the attention contribution of each first word in the target question and target document, the server obtains the attention score weights for each first word in the target question and target document. Finally, the attention score weights for each first word in the target question and target document are weighted and summed with the weights of each first word in the target question to obtain the feature information of the input sequence.
[0119] Step 4: Obtain the answer to the target question based on the feature information of the input sequence.
[0120] like Figure 5 As shown, the server can input the feature information of the above input sequence into the encoding end of the pre-trained language model (BERT model or RoBERTa model). Taking the pre-trained language model as BERT as an example, after BERT learning, the output U is obtained. j When j=0, U0 represents the output of the first special symbol [CLS] at the output terminal of BERT, that is, the cumulative representation of the input sequence. In other words, U0 contains the cumulative information of the entire input sequence. jThe input extraction-based answer acquisition model predicts the range of initial answers to the target question (the position of the initial answer in the target document), thus obtaining the initial answer to the target question.
[0121] Optionally, the server can also input the target question into a question type classifier to categorize the target question into factual and non-factual questions. Specifically, such as... Figure 6 As shown, the server can obtain the sequence V0 of the target question using BERT encoding or RNN encoding. Then, V0 is used to classify the question by applying an activation function, dividing the target question into factual and non-factual questions.
[0122] If the target question is a factual question, given that factual questions are usually short and have clear factual answers, the server can use the initial answer to the target question as the answer to the target question.
[0123] If the target question is a non-factual question, the server can input the initial answer to the target question, along with the aforementioned U0, into the generative answer retrieval model to obtain the predicted words for each second word in the initial answer. The generative answer retrieval model can obtain the predicted words from a pre-set dictionary (i.e.,...). Figure 6 The predicted words for each second word in the initial answer are obtained from the custom dictionary shown. Optionally, the words in this preset dictionary may include the first word in the target question, as well as the first word in the document.
[0124] The server can then calculate the fluency probability of the second word in the target sentence, and the fluency probability of the predicted word of the second word in the target sentence. For example, the server can obtain the fluency probability of the second word in the target sentence using the following formula (4), and obtain the fluency probability of the predicted word of the second word in the target sentence using the following formula (5).
[0125]
[0126]
[0127] In formula (4), This indicates the fluency probability of the second word in the target sentence. Represents the current state of the answer. Compared with the initial answer a q Attention between them. In formula (5), This represents the fluency probability of the predicted word for the second word in the target sentence. Softmax represents the softmax loss function. in, This represents the current state of the target document U that has been learned. Lu a length of the target document (a number of first words in the target document). representing a current state attention between the document U j In addition, W o1 , b o1 a parameter matrix of the aforementioned generated answer obtaining model.
[0128] The server then compares the fluency probability of the second word in the target sentence and the fluency probability of the predicted word of the second word in the target sentence. If the fluency probability of the second word in the target sentence is less than the fluency probability of the predicted word of the second word in the target sentence, it means that using the predicted word of the second word to form the target sentence can make the fluency of the target sentence better, which is more consistent with the sentence organized when answering the question artificially. Then, the server can replace the second word with the predicted word of the second word in the target sentence, and further obtain the answer to the target question.
[0129] Step 5: output the answer to the target question.
[0130] After obtaining the answer to the target question, the server can output the answer, so that the user can obtain the answer to the target question.
[0131] The foregoing embodiments detail how to obtain the answer to the target question when the target question includes a pronoun. When the target question does not include a pronoun, optionally, for example, the foregoing step S102 can be omitted, and then the method described in any of the foregoing embodiments is referred to to obtain the answer to the target question, which will not be repeated here.
[0132] Figure 7 A structure schematic diagram of a question and answer device provided by the present application is shown in FIG. 1. As shown in the figure, the device includes a receiving module 31, a processing module 32, and an output module 33. Among them, Figure 7
[0133] The receiving module 31 is configured to receive a question and answer request for a target document, wherein the question and answer request includes a target question.
[0134] The processing module 32 is configured to add a label to a pronoun in the target question to obtain a labeled target question, obtain embedding information of each first word in an input sequence, obtain feature information of the input sequence according to the embedding information of each first word in the input sequence, and obtain an answer to the target question according to the feature information of the input sequence. The input sequence includes the labeled target question, the target document, and the first N historical questions of the target document and answers corresponding to the historical questions. N is an integer greater than or equal to 1. The embedding information of the pronoun in the labeled target question includes word embedding information, segmentation embedding information, position embedding information, and category information.
[0135] The output module 33 is configured to output the answer to the target question.
[0136] Optionally, the embedding information of the pronoun is a weighted sum of the word embedding information, the segmentation embedding information, the position embedding information, and the category information.
[0137] Optionally, the processing module 32 is specifically configured to determine whether the target question is a non-fact type question, and extract an initial answer to the target question from the target document. If the target question is a non-fact type question, the processing module 32 is configured to obtain a predicted word of each second word in the initial answer, and obtain the answer to the target question according to the initial answer and the predicted word of each second word in the initial answer.
[0138] Optionally, the processing module 32 is specifically configured to, for each second word in the initial answer, if a fluency probability of the second word in a target sentence is less than a fluency probability of a predicted word of the second word in the target sentence, replace the second word with the predicted word in the target sentence to obtain the answer. The target sentence is a sentence to which the second word belongs in the initial answer.
[0139] Optionally, the processing module 32 is specifically configured to obtain the predicted word of each second word in the initial answer by using a preset dictionary. The preset dictionary includes the first word in the target question and the first word in the document.
[0140] Optionally, the processing module 32 is further configured to, if the target question is a fact type question, take the initial answer to the target question as the answer to the target question.
[0141] The question and answer device provided in the present application is used to execute the question and answer method embodiments, and has similar implementation principles and technical effects, which will not be described herein.
[0142] It should be understood that the foregoing embodiments are exemplary descriptions of the execution subject of the question and answer method being the server. In a specific implementation, the execution subject of the question and answer method described in the foregoing method embodiments can also be a terminal device interacting with the user (that is, the terminal device receives the question and answer request input by the user, and then executes the above method to obtain and output the answer to the target question) and other electronic devices with processing functions.
[0143] Figure 8 An electronic device structure schematic diagram is provided in the present application. As shown in the figure, Figure 8 The electronic device 400 can include at least one processor 401 and a memory 402.
[0144] The memory 402 is used to store programs. Specifically, the programs can include program codes, and the program codes include computer operation instructions.
[0145] The memory 402 can include a high-speed RAM memory, and can also include a non-volatile memory such as at least one disk memory.
[0146] The processor 401 is used to execute the computer execution instructions stored in the memory 402 to implement the question and answer method described in the foregoing method embodiments. The processor 401 can be a central processing unit (CPU) or an application specific integrated circuit (ASIC), or one or more integrated circuits configured to implement the embodiments of the present application.
[0147] Optionally, the electronic device 400 can also include a communication interface 403. In a specific implementation, if the communication interface 403, the memory 402 and the processor 401 are independently implemented, the communication interface 403, the memory 402 and the processor 401 can be connected to each other through a bus and complete the communication among them. The bus can be an industry standard architecture (ISA) bus, a peripheral component (PCI) bus or an extended industry standard architecture (EISA) bus, etc. The bus can be divided into an address bus, a data bus, a control bus, etc., but it does not mean that there is only one bus or one type of bus.
[0148] Optionally, if the communication interface 403, the memory 402 and the processor 401 are integrated on a chip to be implemented, the communication interface 403, the memory 402 and the processor 401 can complete the communication through an internal interface.
[0149] The application further provides a computer readable storage medium, which can include a U disk, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, and various storage medium capable of storing program codes. Specifically, the computer readable storage medium stores program instructions, and the program instructions are used for the method in the above embodiments.
[0150] The application further provides a program product, which includes execution instructions stored in a readable storage medium. At least one processor of an electronic device can read the execution instructions from the readable storage medium, and the at least one processor executes the execution instructions to enable the electronic device to implement the question and answer method provided in the various embodiments.
[0151] Finally, it should be noted that: the above embodiments are only used to illustrate the technical solutions of the application, but not to limit them; although the 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 for part or all of the technical features; and these modifications or replacements do not make the essence of the corresponding technical solutions deviate from the scope of the technical solutions of the embodiments of the application.
Claims
1. A question and answer method, characterized by, The method includes: Receive a question-and-answer request for a target document, the question-and-answer request including the target question; Add annotations to the pronouns in the target question to obtain the annotated target question; The embedding information of each first word in the input sequence is obtained; the input sequence includes: the labeled target question, the target document, and the previous N rounds of historical questions for the target document and the answers corresponding to the historical questions; N is an integer greater than or equal to 1; the embedding information of pronouns in the labeled target question is used to indicate the word embedding information, segmentation embedding information, position embedding information, and category information of the pronouns; The feature information of the input sequence is obtained based on the embedding information of each first word in the input sequence. The feature information of the input sequence includes the first N rounds of historical questions of the target document and the association feature information between the answers to the historical questions and the pronouns in the target question. Based on the feature information of the input sequence, the answer to the target question is obtained; Output the answer to the target question.
2. The method of claim 1, wherein, The embedding information of the pronoun is a weighted sum of the word embedding information, segmentation embedding information, position embedding information, and category information of the pronoun.
3. The method according to any of claims 1-2, characterized in that, The step of obtaining the answer to the target question based on the feature information of the input sequence includes: Determine whether the target question is a non-factual question, and extract the initial answer to the target question from the target document; If the target question is a non-factual question, then obtain the predicted words for each second word in the initial answer; The answer to the target question is obtained based on the initial answer and the predicted words of each second word in the initial answer.
4. The method of claim 3, wherein, The step of obtaining the answer to the target question based on the initial answer and the predicted words of each second word in the initial answer includes: For each second word in the initial answer, if the fluency probability of the second word in the target sentence is less than the fluency probability of the predicted word of the second word in the target sentence, then the predicted word is used to replace the second word in the target sentence to obtain the answer; wherein, the target sentence is the sentence to which the second word belongs in the initial answer.
5. The method according to claim 3, characterized in that, The step of obtaining the predicted words for each second word in the initial answer includes: Using a preset dictionary, predictive words for each second word in the initial answer are obtained; wherein, the preset dictionary includes: the first word in the target question, and the first word in the document.
6. The method according to claim 3, characterized in that, After determining whether the target question is a non-factual question and extracting the initial answer to the target question from the target document, the process further includes: If the target question is a factual question, then the initial answer to the target question will be used as the answer to the target question.
7. A question-and-answer device, characterized in that, The device includes: A receiving module is used to receive a question-and-answer request for a target document, wherein the question-and-answer request includes a target question; A processing module is used to add annotations to pronouns in the target question to obtain an annotated target question; obtain the embedding information of each first word in the input sequence; obtain the feature information of the input sequence based on the embedding information of each first word in the input sequence; and obtain the answer to the target question based on the feature information of the input sequence. The input sequence includes: the annotated target question, the target document, and the previous N rounds of historical questions for the target document and the answers corresponding to the historical questions; N is an integer greater than or equal to 1; the embedding information of pronouns in the annotated target question is used to indicate the word embedding information, segmentation embedding information, position embedding information, and category information of the pronouns; the feature information of the input sequence includes the association feature information between the previous N rounds of historical questions of the target document, the answers corresponding to the historical questions, and the pronouns in the target question. The output module is used to output the answer to the target question.
8. An electronic device, characterized in that, include: At least one processor and memory; The memory stores computer-executed instructions; The at least one processor executes computer execution instructions stored in the memory, causing the electronic device to perform the method according to any one of claims 1-6.
9. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer-executable instructions that, when executed by a processor, implement the method described in any one of claims 1-6.
10. A computer program product, comprising a computer program, characterized in that, When the computer program is executed by a processor, it implements the method described in any one of claims 1-6.
Citation Information
Patent Citations
Question-answer pair generation method and device, electronic equipment and readable storage medium
CN112183091A
Answer generation method and device based on artificial intelligence, computer equipment and medium
CN112417885A