Question-answering model training method and device, question-answering method and device
By training the reading comprehension and reordering module of the Q&A model, combining the Longformer model and the context text feature vector of predicted answers, the problem of low answer accuracy in the existing Q&A model is solved, and higher Q&A accuracy and user experience are achieved.
Patent Information
- Application Number
- CN202111217331.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Priority Date
- 2021-07-08
- Filing Date
- 2021-10-19
- Publication Date
- 2025-08-08
- Estimated Expiration
- 2041-10-19
AI Technical Summary
Although the existing question-answer model can reorder according to the correlation between the question and the text when performing the question-answer task, texts with high correlation may not necessarily contain correct answers, resulting in a decrease in the accuracy of the answers, which in turn reduces the performance of the question-answer model.
By obtaining sample questions, sample text and sample labels, using the reading comprehension module and reordering module for training, adjusting parameters to improve the accuracy of text sorting, ensuring that the correct answers are ranked first, using the Longformer model for reading comprehension and reordering, and training in combination with the context text feature vectors of the predicted answers.
Improve the performance of the Q&A model, ensure that the correct answers are given priority, and improve the user experience and the accuracy of the Q&A model.
Smart Images

Figure CN113961686B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of machine learning technology, and in particular to a question-answering model training method and device, a question-answering method and device, a computing device, and a computer-readable storage medium. Background Art
[0002] Artificial intelligence (AI) refers to the ability of engineered (i.e., designed and manufactured) systems to perceive their environment and acquire, process, apply, and represent knowledge. Natural language processing (NLP) is the study of how computers process human language. It involves using computers to process the form, sound, and meaning of natural language, specifically the input, output, recognition, analysis, understanding, and generation of characters, words, sentences, and text. This includes text summarization, text classification, text proofreading, syntactic and semantic analysis, information extraction, language mining, machine translation, information retrieval, machine reading comprehension, and question-answering models. Question-answering systems enable computers to communicate with people using natural language, just like humans do. People can submit questions expressed in natural language to a question-answering system, and the system will return relevant answers. In question-answering tasks, a question-answering model can, given a corpus and a question, return a corresponding answer from the corpus.
[0003] When performing question-answering tasks, existing question-answering models can first retrieve text related to the question from the text library based on the input question, then reorder the text according to its relevance to the question, and finally use reading comprehension technology to extract the answer from at least the first two sorted texts and present it to the user.
[0004] However, the above method only reorders the texts based on their relevance to the question. Although the first few texts obtained have a high relevance to the question, the correct answer may not necessarily be contained in the texts with high relevance. Therefore, the correct answer may not exist in the texts determined by the question-answering model, which reduces the accuracy of the question-answering model in performing question-answering tasks, and thus reduces the performance of the question-answering model. Summary of the Invention
[0005] In view of this, the embodiments of the present application provide a question-answering model training method and device, a question-answering method and device, a computing device and a computer-readable storage medium to address the technical defects existing in the prior art.
[0006] According to a first aspect of an embodiment of the present application, a method for training a question-answering model is provided, comprising:
[0007] Obtaining a sample question, at least two sample texts, and a sample label, wherein the sample label includes a sample answer and sample labels of the at least two sample texts, and the sample label of each sample text indicates whether the sample text is relevant to the sample question;
[0008] Inputting the sample question and the at least two sample texts into a reading comprehension module of a question-answering model, obtaining at least two predicted answers, context text for each predicted answer, and a text feature vector for each sample text, and determining a first loss value based on the at least two predicted answers and the sample answers;
[0009] Inputting the sample question, the at least two predicted answers, the context text of each predicted answer, and the text feature vector of each sample text into the re-ranking module of the question-answering model, obtaining a prediction probability corresponding to each sample text, determining a prediction label of the at least two sample texts based on the prediction probability corresponding to each sample text, and determining a second loss value based on the prediction labels of the at least two sample texts and the sample labels of the at least two sample texts;
[0010] The parameters of the reading comprehension module and the parameters of the reordering module are adjusted based on the first loss value and the second loss value until both the reading comprehension module and the reordering module meet the training stop conditions, and the training of the question-answering model is stopped.
[0011] According to a second aspect of an embodiment of the present application, a method for training a question-answering model is provided, the method comprising:
[0012] Get sample questions, at least two sample texts, and sample answers;
[0013] Inputting the sample question and the at least two sample texts into a reading comprehension module of a question-answering model to obtain at least two predicted answers;
[0014] determining a third loss value based on the at least two predicted answers and the sample answer;
[0015] The reading comprehension module is trained based on the third loss value until a training stop condition is reached.
[0016] According to a third aspect of an embodiment of the present application, a question-answering method is provided, comprising:
[0017] Obtaining a question to be processed and at least two texts to be processed, and inputting the question to be processed and the at least two texts to be processed into a reading comprehension module of a question-answering model to obtain at least two target answers, context text for each target answer, and a text feature vector for each text to be processed, wherein the question-answering model is trained using the question-answering model training method described in the first aspect above;
[0018] Inputting the question to be processed, the at least two target answers, the context text of each target answer, and the text feature vector of each text to be processed into the reordering module of the question-answering model to obtain a target probability corresponding to each text to be processed;
[0019] The at least two texts to be processed are sorted based on the target probability of each text to be processed, and the sorted texts to be processed and the at least two target answers are output.
[0020] According to a fourth aspect of the embodiments of the present application, a question-answering method is provided, the method comprising:
[0021] Get a pending question and at least two pending texts;
[0022] The question to be processed and the at least two texts to be processed are input into the reading comprehension module of the question-answering model to obtain at least two target answers, wherein the question-answering model is trained by the training method of the question-answering model described in the second aspect above.
[0023] According to a fifth aspect of an embodiment of the present application, a training device for a question-answering model is provided, comprising:
[0024] A first acquisition module is configured to acquire a sample question, at least two sample texts, and a sample label, wherein the sample label includes a sample answer and sample labels of the at least two sample texts, and the sample label of each sample text indicates whether the sample text is relevant to the sample question;
[0025] A first determination module is configured to input the sample question and the at least two sample texts into a reading comprehension module of the question-answering model, obtain at least two predicted answers, context text of each predicted answer, and a text feature vector of each sample text, and determine a first loss value based on the at least two predicted answers and the sample answers;
[0026] a second determination module configured to input the sample question, the at least two predicted answers, the context text of each predicted answer, and the text feature vector of each sample text into the re-ranking module of the question-answering model, obtain a prediction probability corresponding to each sample text, determine prediction labels of the at least two sample texts based on the prediction probability corresponding to each sample text, and determine a second loss value based on the prediction labels of the at least two sample texts and the sample labels of the at least two sample texts;
[0027] The first training module is configured to adjust the parameters of the reading comprehension module and the parameters of the reordering module based on the first loss value and the second loss value until the reading comprehension module and the reordering module both meet the training stop conditions, thereby stopping the training of the question-answering model.
[0028] According to a sixth aspect of an embodiment of the present application, a training device for a question-answering model is provided, comprising:
[0029] A second acquisition module is configured to acquire a sample question, at least two sample texts, and a sample answer;
[0030] A third determination module is configured to input the sample question and the at least two sample texts into a reading comprehension module of the question-answering model to obtain at least two predicted answers;
[0031] a fourth determining module, configured to determine a third loss value based on the at least two predicted answers and the sample answer;
[0032] The second training module is configured to train the reading comprehension module based on the third loss value until a training stop condition is reached.
[0033] According to a seventh aspect of the embodiments of the present application, a question-answering device is provided, the device comprising:
[0034] a third acquisition module configured to acquire a question to be processed and at least two texts to be processed, and input the question to be processed and the at least two texts to be processed into a reading comprehension module of a question-answering model to obtain at least two target answers, context text for each target answer, and a text feature vector for each text to be processed, wherein the question-answering model is trained using the question-answering model training method described in the first aspect above;
[0035] a fifth determination module configured to input the question to be processed, the at least two target answers, the context text of each target answer, and the text feature vector of each text to be processed into the reordering module of the question-answering model to obtain a target probability corresponding to each text to be processed;
[0036] The output module is configured to sort the at least two texts to be processed based on the target probability of each text to be processed, and output the sorted texts to be processed and the at least two target answers.
[0037] According to an eighth aspect of an embodiment of the present application, a question-answering device is provided, comprising:
[0038] A fourth acquisition module is configured to acquire a question to be processed and at least two texts to be processed;
[0039] The sixth determination module is configured to input the question to be processed and the at least two texts to be processed into the reading comprehension module of the question-answering model to obtain at least two target answers, wherein the question-answering model is trained by the training method of the question-answering model described in the second aspect above.
[0040] According to the ninth aspect of an embodiment of the present application, a computing device is provided, comprising a memory, a processor, and computer instructions stored on the memory and executable on the processor, wherein when the processor executes the instructions, the steps of the training method of the question-answering model are implemented, or the steps of the question-answering method are implemented.
[0041] According to the tenth aspect of the embodiment of the present application, a computer-readable storage medium is provided, which stores computer instructions, which, when executed by a processor, implement the steps of the training method of the question-answering model, or implement the steps of the question-answering method.
[0042] According to the eleventh aspect of the embodiments of the present application, a chip is provided, which stores computer instructions, which, when executed by the chip, implement the steps of the training method of the question-answering model, or implement the steps of the question-answering method.
[0043] In an embodiment of the present application, a sample question, at least two sample texts, and a sample label are obtained, wherein the sample label includes a sample answer and a sample label of the at least two sample texts, and the sample label of each sample text represents whether the sample text is relevant to the sample question; the sample question and the at least two sample texts are input into a reading comprehension module of a question-answering model to obtain at least two predicted answers, a context text of each predicted answer, and a text feature vector of each sample text, and a first loss value is determined based on the at least two predicted answers and the sample answers; the sample question, the at least two predicted answers, the context text of each predicted answer, and the text feature vector of each sample text are input into a reordering module of the question-answering model to obtain a prediction probability corresponding to each sample text, and a prediction label of the at least two sample texts is determined based on the prediction probability corresponding to each sample text, and a second loss value is determined based on the prediction label of the at least two sample texts and the sample label of the at least two sample texts; parameters of the reading comprehension module and parameters of the reordering module are adjusted based on the first loss value and the second loss value until both the reading comprehension module and the reordering module meet the training stop condition, thereby stopping training of the question-answering model. In the above method, the reordering module is placed after the reading comprehension module. When training the reordering module, the output of the reading comprehension module, that is, the predicted answer, the context text of the predicted answer, and the characteristics of the sample text can be taken into consideration, rather than sorting the sample text only according to the relevance between the sample text and the sample question. This can improve the sorting accuracy of the sample text, put the sample text that may have the correct answer in front, improve the sorting performance of the trained reordering module, and thus improve the performance of the question-answering model. BRIEF DESCRIPTION OF THE DRAWINGS
[0044] Figure 1 This is a structural block diagram of a computing device provided in an embodiment of the present application;
[0045] Figure 2 This is a flowchart of a method for training a question-answering model provided in an embodiment of the present application;
[0046] Figure 3 This is a structural diagram of a question-answering model provided in an embodiment of the present application;
[0047] Figure 4 This is a flowchart of a method for training a question-answering model for a question-answering task provided in an embodiment of the present application;
[0048] Figure 5 This is a flowchart of another method for training a question-answering model provided in an embodiment of the present application;
[0049] Figure 6This is a structural diagram of another question-answering model provided in an embodiment of the present application;
[0050] Figure 7 This is a structural diagram of another question-answering model provided in an embodiment of the present application;
[0051] Figure 8 This is a flowchart of a question-and-answer method provided in an embodiment of the present application;
[0052] Figure 9 This is a structural diagram of another question-answering model provided in an embodiment of the present application;
[0053] Figure 10 This is a flowchart of another question-and-answer method provided in an embodiment of the present application;
[0054] Figure 11 This is a processing flow chart of a question-answering method applied to a question-answering task provided by an embodiment of the present application;
[0055] Figure 12 This is a structural diagram of another question-answering model provided in an embodiment of the present application;
[0056] Figure 13 is a schematic diagram of a training device for a question-answering model provided in an embodiment of the present application;
[0057] Figure 14 2 is a schematic diagram of another training device for a question-answering model provided in an embodiment of the present application;
[0058] Figure 15 is a schematic diagram of a question-and-answer device provided in an embodiment of the present application;
[0059] Figure 16 Schematic diagram of another question-and-answer device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0060] The following description sets forth many specific details to facilitate a thorough understanding of the present application. However, the present application can be implemented in many other ways than those described herein, and those skilled in the art can make similar generalizations without violating the scope of the present application. Therefore, the present application is not limited to the specific implementations disclosed below.
[0061] The terms used in one or more embodiments of the present application are for the purpose of describing specific embodiments only and are not intended to limit one or more embodiments of the present application. The singular forms "a", "the" and "the" used in one or more embodiments of the present application and the appended claims are also intended to include plural forms, unless the context clearly indicates otherwise. It should also be understood that the term "and / or" used in one or more embodiments of the present application refers to and includes any or all possible combinations of one or more associated listed items.
[0062] It should be understood that although the terms first, second, etc. may be used to describe various information in one or more embodiments of the present application, such information should not be limited to these terms. These terms are only used to distinguish information of the same type from each other. For example, without departing from the scope of one or more embodiments of the present application, first may also be referred to as second, and similarly, second may also be referred to as first. Depending on the context, the word "if" as used herein may be interpreted as "in response to determining."
[0063] First, the terms involved in one or more embodiments of the present invention are explained.
[0064] Question answering model: used to perform question answering tasks and can output answers based on input questions.
[0065] Retrieval module: used to retrieve several related texts from the text library based on the word units in the question.
[0066] Re-ranking module: Sort the determined texts and place the texts with a higher probability of containing the answer at a relatively higher position.
[0067] Reading comprehension module: Use reading comprehension technology to determine the answers to questions from several sorted texts.
[0068] Feature extraction layer: used to extract the feature vector of the input text.
[0069] Feedforward neural network layer: used to perform linear transformation on the input.
[0070] Word embedding sublayer: This is the network layer that performs word embedding. Word embedding involves embedding a high-dimensional space (the number of dimensions equal to the number of words) into a much lower-dimensional continuous vector space, where each word or phrase is mapped to a vector in the real field.
[0071] Attention sublayer: It can include an attention mechanism, which takes word units as units and performs attention calculation based on the word vectors of word units.
[0072] Longformer: A sparse self-attention model, an upgraded version of the Transformer model that can efficiently process long text. In this application, Longformer is used to output an answer based on the question and text.
[0073] Pairwise method: Each loss calculation of the reranking model only considers the sample question and a single text.
[0074] Listwise method: Each loss calculation of the reranking model considers the sample question and all related texts.
[0075] Pre-trained model: A model pre-trained on public corpus, with strong generalization capabilities, can be used for a variety of natural language processing tasks.
[0076] TF-IDF (Term Frequency-Inverse Document Frequency) is a commonly used weighting technique for information retrieval and text mining. It can be used to assess the importance of a word unit to a text collection or a text library. The importance of a word unit increases proportionally with the number of times it appears in a text, but decreases inversely with its frequency of occurrence in the text library.
[0077] BM25 algorithm: It is an extension of the binary independence model and can be used to rank the relevance of searches.
[0078] Word units: Before any actual processing of input text, it must be segmented into language units such as characters, punctuation marks, numbers, or letters. These language units are called word units. For English text, a word unit can be a single word, a punctuation mark, or a number. For Chinese text, the smallest word unit can be a character, a punctuation mark, or a number.
[0079] Feature vector sequence: The vector representation of the text is obtained by extracting the word vector of each word unit in the text and performing feature extraction on the text.
[0080] Text feature vector: a feature used to represent the relevance between the text and the question.
[0081] Relevance feature vector: A feature used to represent the relevance between questions and answers.
[0082] Next, the training method of the question-answering model provided in the embodiment of the present application and the application scenarios of the question-answering method are explained.
[0083] Typically, a question-answering model consists of three parts: a retrieval module, a reordering module, and a reading comprehension module. The retrieval module retrieves several relevant texts from a massive database based on the word unit information of the question; the reordering module ranks these texts by relevance, placing more relevant texts at the top; and the reading comprehension module uses reading comprehension technology to extract the answer to the question from the text. In other words, the question-answering model first needs to retrieve texts related to the question from the massive data, then reorder the texts, placing texts without answers at the back of the page, and finally use reading comprehension technology to extract the correct answer from the first few sorted texts.
[0084] Existing solutions generally show users answers extracted from the first few re-ranked texts, and the accuracy of these answers is highly dependent on the performance of the re-ranking model. However, this solution determines the relevance of the text to the question during ranking, which includes an assumption that the "relevance between the question and the text" and the "relevance between the question and the answer within the text" are consistent. However, in reality, the relevance between the question and the text should be positively correlated with the relevance between the question and the answer within the text, rather than being completely consistent. In other words, a highly correlated text may not necessarily contain the correct answer. This can result in the first few re-ranked texts not containing the correct answer, resulting in an incorrect answer, which reduces the performance of the question-answering model.
[0085] To address the above issues, this application proposes a training method for a question-answering model. During the text sorting process, the predicted answers extracted by the reading comprehension module are considered, and the context of the predicted answers and the text feature vectors of the entire text are referenced to determine the relevance of the text to the question. The main difference from existing solutions is that the sorting results also take into account the answers predicted by the reading comprehension model, which can maintain the consistency of the relevance between questions and answers, resulting in better reordering performance, thereby improving the performance of the question-answering model and enhancing the user experience.
[0086] In this application, a training method and apparatus for a question-answering model, a question-answering method and apparatus, a computing device, and a computer-readable storage medium are provided, which are described in detail one by one in the following embodiments.
[0087] Figure 1 1 shows a block diagram of a computing device 100 according to an embodiment of the present application. Components of the computing device 100 include, but are not limited to, a memory 110 and a processor 120. The processor 120 is connected to the memory 110 via a bus 130, and a database 150 is used to store data.
[0088] The computing device 100 also includes an access device 140 that enables the computing device 100 to communicate via one or more networks 160. Examples of these networks include a public switched telephone network (PSTN), a local area network (LAN), a wide area network (WAN), a personal area network (PAN), or a combination of communication networks such as the Internet. The access device 140 may include one or more of any type of network interface (e.g., a network interface card (NIC)), whether wired or wireless, such as an IEEE 802.11 wireless local area network (WLAN) wireless interface, a Worldwide Interoperability for Microwave Access (Wi-MAX) interface, an Ethernet interface, a universal serial bus (USB) interface, a cellular network interface, a Bluetooth interface, a near field communication (NFC) interface, and the like.
[0089] In one embodiment of the present application, the above components of the computing device 100 and Figure 1Other components not shown in the figure may also be connected to each other, for example, via a bus. Figure 1 The computing device structure block diagram shown is for illustrative purposes only and is not intended to limit the scope of the present application. Those skilled in the art may add or replace other components as needed.
[0090] The computing device 100 may be any type of stationary or mobile computing device, including a mobile computer or mobile computing device (e.g., a tablet computer, a personal digital assistant, a laptop computer, a notebook computer, a netbook computer, etc.), a mobile phone (e.g., a smartphone), a wearable computing device (e.g., a smartwatch, smart glasses, etc.), or other types of mobile devices, or a stationary computing device such as a desktop computer or PC. The computing device 100 may also be a mobile or stationary server.
[0091] The processor 120 may execute Figure 2 Steps in the training method for the question-answering model shown. Figure 2 A flowchart of a method for training a question-answering model according to an embodiment of the present application is shown, including steps 202 to 208.
[0092] Step 202: Obtain a sample question, at least two sample texts, and a sample label, wherein the sample label includes a sample answer and sample labels of the at least two sample texts, and the sample label of each sample text represents whether the sample text is relevant to the sample question.
[0093] As an example, obtaining a sample question, at least two sample texts, and a sample label refers to obtaining a sample question, obtaining multiple sample texts, and obtaining multiple sample labels, respectively. Each sample text corresponds to a sample label, and each sample label includes a sample answer and a sample tag. That is, each sample text corresponds to a sample tag and a sample answer, and the relationship between the sample text and the sample tag is: the sample tag indicates whether the correct answer to the sample question can be inferred from the sample text; the sample answer is the correct answer to the sample question. However, depending on the sample text, the relationship between the sample text and the sample answer includes the following two situations:
[0094] In the first case, all sample texts are positive samples. Positive samples are samples that include the correct answers to sample questions. Then the relationship between sample texts and sample answers is: sample answers are the correct answers to sample questions included in the sample texts.
[0095] In the second case, the sample text includes both positive and negative samples. Positive samples are samples that include the correct answer to the sample question, while negative samples are samples that do not. The relationship between the sample text and the sample answer is: if the sample text is a positive sample, the sample answer is the correct answer to the sample question included in the sample text; if the sample text is a negative sample, the sample answer is the correct answer to the sample question, but it is not inferred from the sample text. Instead, it is predicted based on the sample question by the reading comprehension model or manually determined.
[0096] As an example, sample labels may include relevant and irrelevant. Furthermore, a sample labeled as relevant means that the sample text is relevant to the sample question, meaning that the correct answer to the sample question can be inferred from the sample text. A sample labeled as irrelevant means that the sample text is irrelevant to the sample question, meaning that the correct answer to the sample question cannot be inferred from the sample text.
[0097] As an example, the sample label of the sample text can be manually labeled based on whether the sample text can infer the correct answer to the sample question. For example, the sample label "relevant" can be represented by 1, and the sample label "irrelevant" can be represented by 0.
[0098] As an example, the sample questions and sample answers may be obtained from a pre-built training sample library, which may include multiple sample questions and a sample answer to each sample question.
[0099] In one possible implementation, the question-answering model also includes a retrieval module, and the specific implementation of obtaining at least two sample texts may include: inputting the sample question into the retrieval module, and determining texts related to the sample question as the at least two sample texts, wherein the retrieval module is used to retrieve sample texts related to the sample question from a sample text library based on the sample question.
[0100] Among them, the function of the retrieval module is to retrieve texts related to sample questions from the sample text library.
[0101] As an example, the retrieval module used in the training process can be a pre-trained retrieval model that can retrieve texts that are literally related to the sample question from a sample text library. The sample text library can include multiple sample texts, and each sample text can carry manually annotated sample tags.
[0102] That is, a sample question can be input into the retrieval module, and the retrieval module can obtain multiple texts related to the sample question from the sample text library, and determine the obtained multiple texts as at least two sample texts.
[0103] For example, see Figure 3 , by inputting the sample question into the retrieval module of the question-answering model, we can obtain sample text 1 and sample text 2.
[0104] In some embodiments, the specific implementation of inputting the sample question into the retrieval module and determining the text related to the sample question may include: inputting the sample question into the retrieval module to obtain the keyword unit in the sample question; and taking the text including the keyword unit in the sample text library as the text related to the sample question.
[0105] The keyword unit may be a core word that can represent the sample question, and the number of the keyword unit may be at least one.
[0106] That is, when a sample question is input into the retrieval module, a text including a keyword unit can be obtained from a sample text library through an inverted index as text related to the sample question.
[0107] As an example, a sample question is input into the retrieval module, and the sample question can be segmented to obtain multiple word units, and keyword units are obtained from the multiple word units. For example, assuming that the sample question is "Who is the Immortal Poet", the sample question can be segmented to obtain the word units "The Immortal Poet", "is" and "who", and "The Immortal Poet" can be used as a keyword unit. Suppose that the sample question is "What is the smallest natural number", the sample question can be segmented to obtain the word units "smallest", "of", "natural number", "is" and "what", and "smallest" and "natural number" can be used as keyword units.
[0108] Generally speaking, if a text includes a keyword unit, it can be considered that the text is relatively relevant to the keyword unit, and further it can be considered that the text is relatively relevant to the sample question. Therefore, the text including the keyword unit can be regarded as text related to the sample question.
[0109] As an example, when the number of keyword units is greater than one, the text including all keyword units in the sample text library may be used as the text related to the sample question.
[0110] That is, if the number of keyword units is greater than one, if a text contains only one keyword unit, it cannot be considered as text related to the sample question. If a text contains two or more keyword units but not all keyword units, it cannot be considered as text related to the sample question. If a text contains all keyword units, it can be considered as text related to the sample question. This can improve the accuracy of sample texts related to the sample question.
[0111] For example, assuming the sample question is "What is the smallest natural number?", sample text 1 in the sample text library is "0 is the smallest natural number", and sample text 2 in the sample text library is "1 is the smallest odd number". It can be determined that sample text 1 includes "natural number" and "smallest", so sample text 1 can be determined as a text related to the sample question, while sample text 2 includes "smallest" but does not include "natural number", so sample text 2 cannot be determined as a text related to the sample question.
[0112] In other embodiments, texts related to sample questions can be obtained from a sample text library by means of an inverted index. Specifically, an inverted index needs to be created first. Multiple sample texts in the sample text library can be numbered to form a text list, and each sample text can be segmented to obtain multiple word units. The word units are used as indexes, and the numbers of the sample texts containing each word unit are saved to obtain an inverted index list. Then, a search is performed based on the inverted index. When a sample question is input, the input sample question is first segmented to obtain at least two word units. The at least two word units are then matched in the inverted index list. The at least two word units are used as indexes to determine the numbers of the sample texts containing the at least two word units. Based on the numbers, the sample text containing the at least two word units can be obtained, that is, the text related to the sample question can be obtained.
[0113] In this case, the sample text needs to include every word unit in the sample question in order to determine that the sample text is relevant to the sample question. In this way, the accuracy of the obtained sample text can be further improved.
[0114] It should be noted that in other implementations, the function of the retrieval module can also be implemented using the Elasticsearch tool. Elasticsearch is a search tool that can retrieve sample texts related to the sample questions through complex search strategies.
[0115] Furthermore, after inputting the sample question into a retrieval module and determining the texts related to the sample question as the at least two sample texts, the method further includes: determining the word frequency of the keyword unit in the at least two sample texts respectively; determining the inverse document word frequency of the keyword unit in the sample text library; determining a relevance score of each sample text based on the word frequency of the keyword unit in the at least two sample texts and the inverse document word frequency in the sample text library; and performing an initial sorting of the at least two sample texts based on the relevance score of each sample text to obtain the sorted at least two sample texts.
[0116] Accordingly, the specific implementation of inputting the sample question into the retrieval module and determining the text related to the sample question as the at least two sample texts may include: inputting the sorted at least two sample texts and the sample question into the reading comprehension module of the question-answering model in order.
[0117] That is, after obtaining at least two sample texts through the retrieval module, the at least two sample texts may be initially sorted, and the sorted at least two sample texts and sample questions may be input into the reading comprehension module in order.
[0118] As an example, for a reference keyword unit, the number of times the reference keyword unit appears in each sample text can be counted. Based on this number and the number of word units included in the sample text, the word frequency of the reference keyword unit in each sample text can be determined. The number of sample texts in the sample text library that include the reference keyword unit can be counted, and based on this number and the total number of sample texts in the sample text library, the inverse document word frequency of the reference keyword unit in the sample text library can be determined. Based on the word frequency of the reference keyword unit in each sample text and the inverse document word frequency in the sample text library, the relevance score of each sample text can be determined using the TF-IDF algorithm. At least two sample texts can be initially sorted in descending order of relevance scores to obtain at least two sorted sample texts.
[0119] For example, the quotient between the number of occurrences of the reference keyword unit and the number of word units in the sample text can be used as the word frequency of the reference keyword unit in the sample text. The quotient between the number of sample texts in the sample text library and the number of sample texts in the sample text library that include the reference keyword unit can be used as the inverse document word frequency of the reference keyword unit.
[0120] For example, assuming that the sample question includes keyword unit A, keyword unit B and keyword unit C, and the sample text 1 related to the sample question includes keyword unit A and keyword unit B, the word frequency of keyword unit A in sample text 1 can be determined, the word frequency of keyword unit B in sample text 1 can be determined, and the inverse document word frequency of keyword unit A and the inverse document word frequency of keyword unit B can be determined. The product of the word frequency of keyword unit A and the inverse document word frequency can be determined to obtain a first product value, and the product of the word frequency of keyword unit B and the inverse document word frequency can be determined to obtain a second product value. The sum of the first product value and the second product value is determined as the relevance score of sample text 1.
[0121] It should be noted that, in an optional implementation of the embodiment of the present application, after the sample question is input into the retrieval module and the text related to the sample question is determined as the at least two sample texts, the relevance score of each sample text in the at least two sample texts can be determined by the BM25 algorithm, and the at least two sample texts are initially sorted based on the relevance score to obtain at least two sorted sample texts, and then the at least two sorted sample texts and the sample question are input into the reading comprehension module of the question-answering model in order.
[0122] In an embodiment of the present application, the output of the retrieval module is at least two sorted sample texts, and the at least two sorted sample texts can be input into the reading comprehension module in order.
[0123] Furthermore, after inputting the sample question into the retrieval module and determining the text related to the sample question, the sample tag of each sample text can also be determined. In a specific implementation, the sample texts in the sample text library all carry sample tags, so the sample tag of each sample text can be obtained from the sample text library.
[0124] In the embodiment of the present application, sample questions and sample answers can be obtained from a training sample library. The sample questions are then input into a trained retrieval module. At least two texts related to the sample questions can be obtained as sample texts, and these at least two sample texts carry sample tags. In this way, training data for training the question-answering model can be obtained.
[0125] Step 204: Input the sample question and the at least two sample texts into the reading comprehension module of the question-answering model to obtain at least two predicted answers, the context text of each predicted answer, and the text feature vector of each sample text, and determine a first loss value based on the at least two predicted answers and the sample answers.
[0126] Among them, the reading comprehension module is used to extract predicted answers to sample questions from sample texts.
[0127] As an example, the reading comprehension module can use the Longformer model, which can greatly increase the length of the input text and reduce the computational complexity of attention calculations. The Longformer model can be a pre-trained model, and the present application can further train the pre-trained model so that the pre-trained model meets user needs.
[0128] In some embodiments, the reading comprehension module includes a feature extraction layer and a feedforward neural network layer. The specific implementation of inputting the sample question and the at least two sample texts into the reading comprehension module of the question-answering model to obtain at least two predicted answers, the context text of each predicted answer, and the text feature vector of each sample text may include: splicing the sample question with the at least two sample texts respectively to obtain at least two first texts; inputting the at least two first texts into the feature extraction layer, determining the target word unit of each first text, and performing attention calculation on the target word unit of each first text and the word units of other first texts to obtain a feature vector sequence of each first text; determining the text feature vector of each sample text based on the feature vector sequence of each first text; inputting the feature vector sequence of each first text into the feedforward neural network layer, determining the predicted answer corresponding to each sample text, and obtaining the context text of each predicted answer.
[0129] Among them, the feature extraction layer is used to extract the feature vector of the input text, and the feedforward neural network layer is used to perform linear transformation on the input to obtain the predicted answer corresponding to each sample text.
[0130] The target word unit may be a keyword unit in the first text, and the number of the target word unit may be at least one.
[0131] As an example, the sample question and the sample text can be concatenated, and a separator can be inserted between the sample question and the sample text, and a category marker can be added before the first sample obtained. For example, assuming that the sample question is "Who is the Immortal Poet?" and sample text 1 is "Li Bai was honored as the Immortal Poet by later generations." After concatenation, the first text can be "[CLS]Who is the Immortal Poet? [SEP]Li Bai was honored as the Immortal Poet by later generations." If sample text 2 is "Li Bai, the Immortal Poet, Du Fu, the Sage Poet," the first text can be "[CLS]Who is the Immortal Poet? [SEP]Li Bai, the Immortal Poet, Du Fu, the Sage Poet."
[0132] As an example, the feature extraction layer may include a word embedding sublayer and an attention sublayer. The word embedding sublayer may perform word embedding processing on at least two first texts inputted, respectively, to obtain a word vector sequence for each first text. The word vector sequence includes multiple word vectors, and each word vector corresponds to a word unit in the first text. The target word unit of each first text may also be determined, and then the target word vector of the target word unit of each first text may be determined. The attention sublayer may perform attention calculation on the word vector sequence of each first text and the target word vectors of other first texts to obtain a feature vector sequence for each first text. Furthermore, the feature vector at the [CLS] position in the feature vector sequence of each first text may be determined as the text feature vector of each sample text.
[0133] Exemplarily, assume that the first text 1 is "[CLS]Who is the Immortal of Poetry[SEP]Li Bai is respected as the Immortal of Poetry by later generations", the target word units can be determined as "Immortal of Poetry" and "Li Bai". The first text 2 is "[CLS]Who is the Immortal of Poetry[SEP]The Immortal of Poetry is Li Bai, and the Sage of Poetry is Du Fu", and the target word units can be determined as "Immortal of Poetry", "Li Bai", "Sage of Poetry", and "Du Fu". The word vectors of each word unit in the first text 1 can be respectively subjected to attention calculation with the word vectors of "Immortal of Poetry", "Li Bai", "Sage of Poetry", and "Du Fu". For each word unit in the first text 1, four attention values can be obtained. For the reference word unit, the four attention values corresponding to the reference word unit can be weighted and summed to obtain the first weight of the reference word unit. Multiplying the first weight and the word vector of the reference word unit can obtain the feature vector of the reference word unit. Through the above method, the feature vectors of each word unit in the first text 1 can be obtained, and then the feature vector sequence of the first text 1 can be obtained. Similarly, the word vectors of each word unit in the first text 2 can be respectively subjected to attention calculation with the word vectors of "Immortal of Poetry" and "Li Bai". For each word unit in the first text 2, two attention values can be obtained. For the reference word unit, the two attention values corresponding to the reference word unit can be weighted and summed to obtain the first weight of the reference word unit. Multiplying the first weight and the word vector of the reference word unit can obtain the feature vector of the reference word unit. Through the above method, the feature vectors of each word unit in the first text 2 can be obtained, and then the feature vector sequence of the first text 2 can be obtained. For the first text 1, the feature vector at the [CLS] position in the feature vector sequence of the first text 1 can be used as the text feature vector of the first text 1; for the first text 2, the feature vector at the [CLS] position in the feature vector sequence of the first text 2 can be used as the text feature vector of the first text 2.
[0134] In some embodiments, inputting the feature vector sequence of each first text into the feed-forward neural network layer to determine the specific implementation of the predicted answer corresponding to each sample text may include: inputting the feature vector sequence of each first text into the feed-forward neural network layer, and determining the predicted start position and the predicted end position in each first text; determining the text between the predicted start position and the predicted end position in each first text as the predicted answer corresponding to each sample text.
[0135] As an example, the feedforward neural network layer can also be called a linear transformation layer, which is used to perform linear transformation on the feature vector of each word unit in the input feature vector sequence. Two probabilities can be obtained for each word unit, one is the probability that the word unit is the starting position of the predicted answer, and the other is the probability that the word unit is the ending position of the predicted answer. Based on the two probabilities of each word unit, the predicted starting position and the predicted ending position can be determined, and the text between the predicted starting position and the predicted ending position can be determined as the predicted answer.
[0136] For example, assuming that sample text 1 is "Li Bai is honored as the Immortal Poet by later generations", the feature vector sequence of sample text 1 is input into the feedforward neural network layer, and the probability of each word unit being the starting position of the predicted answer and the probability of each word unit being the ending position of the predicted answer can be obtained. Assuming that the probability of "Li" being the starting position of the predicted answer is the highest and the probability of "Bai" being the ending position of the predicted answer is the highest, it can be determined that the predicted answer is "Li Bai".
[0137] In the above manner, the predicted answer corresponding to each sample text can be determined. When the predicted answer of each sample text is determined, the context text of the predicted answer can be obtained from the sample text.
[0138] For example, see Figure 3 , the sample question and sample text 1 are spliced together and input into the reading comprehension module of the question-answering model to obtain predicted answer 1, which is the answer extracted from sample text 1, and the context text of predicted answer 1 and the text feature vector of sample text 1 are obtained. The sample question and sample text 2 are spliced together and input into the reading comprehension module of the question-answering model to obtain predicted answer 2, which is the answer extracted from sample text 2, and the context text of predicted answer 2 and the text feature vector of sample text 2 are obtained. In addition, a first loss value can be determined based on predicted answer 1, predicted answer 2, and the sample answer.
[0139] In some embodiments, after determining the predicted answers of at least two sample texts, the loss value of each predicted answer and sample answer can be determined through a loss function, and the at least two loss values can be added and averaged to obtain a first loss value.
[0140] Exemplarily, the loss function may be a cross loss function, an exponential loss function, etc. At least two predicted answers and a sample answer may be input into the loss function, and then loss values of the at least two predicted answers and the sample answer may be determined to obtain at least two loss values. The at least two loss values may be summed and averaged to obtain a first loss value for training the reading comprehension module.
[0141] In an embodiment of the present application, at least two sample texts are input into a reading comprehension module in sequence. The reading comprehension module can determine a predicted answer from the sample text based on the characteristics of the sample question and the sample text, and obtain the context text of the predicted answer, as well as a text feature vector that can characterize the correlation between the question and the text, so that the predicted answer and the context text of the predicted answer can be taken into account in subsequent reordering, thereby increasing the conditions for reordering the sample text and improving the accuracy of the reordering.
[0142] Step 206: Input the sample question, the at least two predicted answers, the context text of each predicted answer, and the text feature vector of each sample text into the reordering module of the question-answering model to obtain the prediction probability corresponding to each sample text, and determine the prediction tags of the at least two sample texts based on the prediction probability corresponding to each sample text, and determine the second loss value based on the prediction tags of the at least two sample texts and the sample tags of the at least two sample texts.
[0143] During implementation, the reordering module includes a feature extraction layer and a feedforward neural network layer. The sample question, the at least two predicted answers, the context text of each predicted answer and the text feature vector of each sample text are input into the reordering module of the question-answering model. The specific implementation of obtaining the predicted probability corresponding to each sample text may include: splicing the at least two predicted answers, the sample question and the context text of each predicted answer, inputting the spliced feature vector into the feature extraction layer, and obtaining the spliced feature vector; inputting the spliced feature vector and the text feature vector of the at least two sample texts into the feedforward neural network layer, and obtaining the relevance feature vector of each sample text; performing a linear transformation on the relevance feature vector of each sample text to obtain the predicted probability corresponding to each sample text.
[0144] The predicted probability of the sample text can be used to indicate the degree of relevance between the sample text and the sample question. The relevance feature vector can be used to characterize the relevance between the sample question and the predicted answer.
[0145] As an example, the feature extraction layer can adopt the structure of the ALBERT model for feature extraction. The feedforward neural network layer can be used to perform a linear transformation on the input to obtain the predicted probability corresponding to each sample text.
[0146] As an example, a sample question can be concatenated with at least two predicted answers and the context text of each predicted answer to obtain a concatenated text. This concatenated text is then input into a feature extraction layer to obtain at least two concatenated feature vectors. Each concatenated feature vector is then concatenated with the text feature vector of each sample text. The concatenated result is input into a feedforward neural network layer to obtain a correlation feature vector for each sample text. A linear transformation is then performed on the correlation feature vector of each sample text to convert each correlation feature vector into a single numerical value, resulting in at least two numerical values. These at least two numerical values are then normalized (softmaxed) to obtain a predicted probability corresponding to each sample text.
[0147] For example, taking the structure of the ALBERT model used in the feature extraction layer as an example, assuming that the sample question is represented by Q, the predicted answer is represented by A, and the context text of the predicted answer is represented by S, then the input of ALBERT is [Q; A; S], where ";" represents splicing. The "[CLS]" tag and the "[SEP]" tag in ALBERT are omitted here. Feature extraction is performed on this input to obtain a spliced feature vector. The text feature vector of each sample text is then spliced with the above-mentioned spliced feature vector, and the spliced feature vector is input into the feedforward neural network layer. Further feature extraction is performed in the feedforward neural network layer to obtain a correlation feature vector for each sample text. By multiplying the correlation feature vector with the linear transformation matrix, each correlation feature vector can be converted into a single numerical value, which can also be called a correlation score. The correlation scores of at least two sample texts are softmax processed to obtain the prediction probability corresponding to each sample text.
[0148] In some embodiments, a specific implementation of determining the prediction tags of the at least two sample texts based on the prediction probability corresponding to each sample text may include: determining the prediction tags of the sample texts whose prediction probability is greater than a probability threshold as relevant, and determining the prediction tags of the sample texts whose prediction probability is less than or equal to the probability threshold as irrelevant.
[0149] It should be noted that the probability threshold can be set by the user according to actual needs, or can be set by default by the computing device, and this embodiment of the application does not limit this. For example, the probability threshold can be 0.5.
[0150] That is to say, if the predicted probability is greater than the probability threshold, it can be considered that the sample text has a relatively high correlation with the sample question, and the predicted label of the sample text can be determined as relevant; if the predicted probability is less than or equal to the probability threshold, it can be considered that the sample text has a relatively low correlation with the sample question, and the predicted label of the sample text can be determined as irrelevant.
[0151] For example, see Figure 3 , the predicted answer 1, the sample question, the context text of the predicted answer 1, and the text feature vector of the sample text 1 can be input into the re-ranking module to obtain the predicted tag 1 of the sample text 1. The predicted answer 2, the sample question, the context text of the predicted answer 2, and the text feature vector of the sample text 2 can be input into the re-ranking module to obtain the predicted tag 2 of the sample text 2. Furthermore, a second loss value can be determined based on the predicted tag 1, the predicted tag 2, the sample tag 1, and the sample tag 2.
[0152] Furthermore, the sample texts may be re-sorted in descending order of predicted probability, and at least two sorted sample texts may be output.
[0153] Normally, the pairwise method can be used to train the reordering module. This method determines the prediction tag based on the correlation between the sample question and a sample text, and adjusts the model parameters according to the loss value of the prediction tag and the sample tag, that is, the model parameters are adjusted based on the loss value determined by training with different sample texts, and the parameters adjusted each time may only be related to the sample text this time. That is, this method does not take into account the relationship between the sample texts, and the adjusted parameters may not be applicable to other sample texts, that is, the universality of the trained model is not strong. In order to solve the above problem, in an embodiment of the present application, the listwise method can be used to train the reordering model, that is, when determining the prediction probability, the correlation feature vectors of at least two sample texts are uniformly normalized, which can associate different sample texts together and improve the universality of the trained question-answering model.
[0154] Therefore, determining the second loss value based on the predicted labels of the at least two sample texts and the sample labels of the at least two sample texts may include: inputting the predicted labels and the sample labels of the at least two sample texts into a loss function to obtain the second loss value.
[0155] That is to say, through the listwise method, the predicted tags and sample tags of at least two sample texts can be used as inputs of the loss function. When determining the second loss value, instead of determining the loss values corresponding to different sample texts separately, the predicted tags and sample tags of at least two sample texts are considered at the same time. This can fully consider the relationship between the sample texts and improve the performance of the reranking module.
[0156] In an embodiment of the present application, the reordering module is placed after the reading comprehension module, that is, the reordering of the samples is placed after the extraction of the predicted answers. When reordering the sample texts, the extracted predicted answers can be taken into account, and the context text of the predicted answers and the text feature vectors of the sample texts are referred to. In addition, the listwise method is used during training, which can fully consider the relationship between the sample texts. Considering the extracted predicted answers can solve the problem of inconsistent relevance between the questions and the text, and the listwise method can solve the problem of relationship modeling between texts. In this way, the question-answering model can obtain a more reasonable ranking, improve the accuracy of the ranking model, and thus improve the accuracy of the final answer.
[0157] Step 208: Adjust the parameters of the reading comprehension module and the parameters of the reordering module based on the first loss value and the second loss value until both the reading comprehension module and the reordering module meet the training stop conditions, and stop training the question-answering model.
[0158] In an embodiment of the present application, a multi-task training method is used when training the question-answering model, that is, the reading comprehension module and the reordering module are trained at the same time. Since the input of the reordering module requires the output of the reading comprehension module, when the reading comprehension module is not trained, the parameters of the reading comprehension module and the reordering module need to be adjusted based on the first loss value and the second loss value.
[0159] In some embodiments, the parameters of the reading comprehension module and the parameters of the reordering module are adjusted based on the first loss value and the second loss value until the reading comprehension module and the reordering module both meet the training stop condition. The specific implementation of stopping the training of the question-answering model may include: if the first loss value is less than a first threshold and the second loss value is less than a second threshold, stopping the training of the reading comprehension module and the reordering module; if the first loss value is greater than or equal to the first threshold and the second loss value is less than the second threshold, adjusting the parameters of the reading comprehension module and the parameters of the reordering module based on the first loss value and the second loss value. Continue to train the reading comprehension module and the reordering module; if the first loss value is greater than or equal to the first threshold, and the second loss value is greater than or equal to the second threshold, adjust the parameters of the reading comprehension module and the parameters of the reordering module based on the first loss value and the second loss value, and continue to train the reading comprehension module and the reordering module; if the first loss value is less than the first threshold, and the second loss value is greater than or equal to the second threshold, adjust the parameters of the reading comprehension module and the parameters of the reordering module based on the first loss value and the second loss value, and continue to train the reading comprehension module and the reordering module.
[0160] It should be noted that the first threshold and the second threshold can be set by the user according to actual needs, or can be set by default by the computing device, and the embodiments of the present application do not limit this.
[0161] That is to say, if either the reading comprehension module or the reordering module has not been trained, it is necessary to continue training the reading comprehension module and the reordering module until both are trained, and then the training of the question-answering model can be stopped.
[0162] As an example, if the first loss value is less than the first threshold, and the second loss value is less than the second threshold, it can be considered that the training of the reading comprehension module and the reordering module has been completed, and the training of the reading comprehension module and the reordering module can be stopped. If the first loss value is greater than or equal to the first threshold, and the second loss value is less than the second threshold, it can be considered that the reading comprehension module has not been trained, the reordering module has been trained, and it is necessary to continue training the reading comprehension module and the reordering module. If the first loss value is greater than or equal to the first threshold, and the second loss value is greater than or equal to the second threshold, it can be considered that the training of the reading comprehension module and the reordering module has not been completed, therefore, it is necessary to continue training the reading comprehension module and the reordering module. If the first loss value is less than the first threshold, and the second loss value is greater than or equal to the second threshold, it can be considered that the reading comprehension module has been trained, but the reordering module has not been trained, therefore, it is necessary to continue training the reading comprehension module and the reordering module.
[0163] For example, see Figure 3 , the parameters of the reading comprehension module and the reordering module can be adjusted based on the first loss value and the second loss value.
[0164] In other embodiments, a target loss value may be obtained by weighted summing the first loss value and the second loss value, and the reading comprehension module and the reordering module may be trained based on the target loss value. In a specific implementation, a target threshold may be pre-set. If the target loss value is less than the target threshold, training of the reading comprehension module and the reordering module is stopped. If the target loss value is greater than or equal to the target threshold, training of the reading comprehension module and the reordering module continues.
[0165] In an embodiment of the present application, by determining whether to continue training the question-answering model based on the relationship between the loss value and the threshold, the training degree of the question-answering model can be more accurately grasped, thereby improving the training efficiency of the question-answering model and its accuracy in processing question-answering tasks.
[0166] In an embodiment of the present application, a sample question, at least two sample texts, and a sample label are obtained, wherein the sample label includes a sample answer and a sample label of the at least two sample texts, and the sample label of each sample text represents whether the sample text is relevant to the sample question; the sample question and the at least two sample texts are input into a reading comprehension module of a question-answering model to obtain at least two predicted answers, a context text of each predicted answer, and a text feature vector of each sample text, and a first loss value is determined based on the at least two predicted answers and the sample answers; the sample question, the at least two predicted answers, the context text of each predicted answer, and the text feature vector of each sample text are input into a reordering module of the question-answering model to obtain a prediction probability corresponding to each sample text, and a prediction label of the at least two sample texts is determined based on the prediction probability corresponding to each sample text, and a second loss value is determined based on the prediction label of the at least two sample texts and the sample label of the at least two sample texts; parameters of the reading comprehension module and parameters of the reordering module are adjusted based on the first loss value and the second loss value until both the reading comprehension module and the reordering module meet the training stop condition, thereby stopping training of the question-answering model. In the above method, the reordering module is placed after the reading comprehension module. When training the reordering module, the output of the reading comprehension module, that is, the predicted answer, the context text of the predicted answer, and the characteristics of the sample text can be taken into consideration, rather than sorting the sample text only according to the relevance between the sample text and the sample question. This can improve the sorting accuracy of the sample text, put the sample text that may have the correct answer in front, improve the sorting performance of the trained reordering module, and thus improve the performance of the question-answering model.
[0167] Figure 4 This is a flowchart of a method for training a question-answering model for a question-answering task according to an embodiment of the present application. The method for training the question-answering model is described using the sample question "Who is the Immortal Poet?" as an example. Specifically, the method may include the following steps:
[0168] Step 402: Obtain sample questions and sample labels.
[0169] The sample labels may include sample answers and sample tags of sample text, which may be used to indicate the relevance of the sample text to the sample question. For example, the sample text may include positive samples and negative samples, where the positive samples include the correct answer to the sample question and the negative samples do not include the correct answer to the sample question.
[0170] As an example, the sample questions and sample answers may be obtained from a pre-built training sample library, which may include multiple sample questions and a sample answer to each sample question.
[0171] Exemplarily, assume that the sample question is "Who is the Immortal of Poetry", and the sample answer can be "Li Bai". Assume that the sample text includes sample text 1, sample text 2, and sample text 3, and both sample text 1 and sample text 2 include the sample answer, while sample text 3 does not include the sample answer. Then, the relevance label of sample text 1 and sample text 2 is marked as relevant, and the relevance label of sample text 3 is marked as irrelevant.
[0172] Step 404: Input the sample question into the retrieval module of the Q&A model to obtain the keyword units in the sample question.
[0173] For example, perform word segmentation on "Who is the Immortal of Poetry" to obtain three word units, namely "Immortal of Poetry", "is", and "who", and "Immortal of Poetry" can be determined as the keyword unit.
[0174] Step 406: Use the texts in the sample text library that include the keyword unit as at least two sample texts related to the sample question, and determine the sample label of each sample text.
[0175] For example, since the relatively important word unit in this sample question is "Immortal of Poetry", texts including "Immortal of Poetry" can be obtained from the text library. Assume that sample text 1, sample text 2, and sample text 3 can be obtained, that is, sample text 1, sample text 2, and sample text 3 can be used as the relevant texts of the sample question.
[0176] In addition, since the sample texts in the sample text library all carry sample labels, the sample label of sample text 1, the sample label of sample text 2, and the sample label of sample text 3 can be obtained.
[0177] Step 408: Determine the word frequency of the keyword unit in at least two sample texts respectively, and determine the inverse document frequency of the keyword unit in the sample text library.
[0178] For example, assume that sample text 1 includes 20 characters and "Immortal of Poetry" appears 3 times. Then, the word frequency of "Immortal of Poetry" in sample text 1 is 0.3. Similarly, assume that sample text 2 includes 10 characters and "Immortal of Poetry" appears 1 time. Then, the word frequency of "Immortal of Poetry" in sample text 2 is 0.2. Assume that sample text 3 includes 20 characters and "Immortal of Poetry" appears 1 time. Then, the word frequency of "Immortal of Poetry" in sample text 3 is 0.1.
[0179] For example, assume that the sample text library includes 100 sample texts. Except for any one of sample text 1, sample text 2, and sample text 3, there are 25 sample texts in the sample text library that include the word "Immortal of Poetry". Then, the inverse document frequency of "Immortal of Poetry" in the sample text library is 4.
[0180] Step 410: Determine the relevance score of each sample text based on the word frequency of the keyword unit in at least two sample texts and the inverse document frequency in the sample text library.
[0181] For example, the relevance score of each sample text can be determined by the TF-IDF algorithm. The relevance score of the term "Poetic Genius" in sample text 1 is 0.3×4 = 1.2, the relevance score of the term "Poetic Genius" in sample text 2 is 0.2×4 = 0.8, and the relevance score of the term "Poetic Genius" in sample text 3 is 0.1×4 = 0.4. Since the keyword unit only includes "Poetic Genius", the relevance score of sample text 1 can be determined as 1.2, the relevance score of sample text 2 can be determined as 0.8, and the relevance score of sample text 3 can be determined as 0.4.
[0182] Step 412: Based on the relevance scores of each sample text, perform an initial sorting on the at least two sample texts to obtain the sorted at least two sample texts.
[0183] For example, sample text 1, sample text 2, and sample text 3 can be sorted in descending order of the relevance score, and the sorted at least two sample texts obtained can be sample text 1, sample text 2, and sample text 3.
[0184] Step 414: Concatenate each sample text with the sample question to obtain multiple first texts.
[0185] As an example, the sample question and the sample text can be concatenated, and a delimiter can be inserted between the sample question and the sample text, and a category marker can be added before the obtained first sample. For example, assume the sample question is "Who is the Poetic Genius", and sample text 1 is "Li Bai is respected as the Poetic Genius by later generations". After concatenation, the first text "[CLS]Who is the Poetic Genius[SEP]Li Bai is respected as the Poetic Genius by later generations" can be obtained. Assume sample text 2 is "The Poetic Genius Li Bai, the Poetic Saint Du Fu", then after concatenation, the first text "[CLS]Who is the Poetic Genius[SEP]The Poetic Genius Li Bai, the Poetic Saint Du Fu" can be obtained.
[0186] Step 416: Input the at least two first texts into the feature extraction layer of the reading comprehension module in the order of the at least two sample texts, determine the target word unit of each first text, and perform an attention calculation on the target word unit of each first text and the word units of other first texts to obtain the feature vector sequence of each first text.
[0187] Among them, the question-and-answer model includes a reading comprehension module, and the function of this reading comprehension module is to extract the answers to sample questions from the sample text. As an example, the reading comprehension module can adopt the Longformer model, which can greatly increase the length of the input text and reduce the computational amount of attention calculation.
[0188] Exemplarily, assume that the first text 1 is "[CLS]Who is the poetic genius?[SEP]Li Bai is respected as the poetic genius by later generations", it can be determined that the target word units are "poetic genius" and "Li Bai", and the first text 2 is "[CLS]Who is the poetic genius?[SEP]The poetic genius is Li Bai, and the poetic sage is Du Fu", it can be determined that the target word units are "poetic genius", "Li Bai", "poetic sage" and "Du Fu". The word vectors of each word unit in the first text 1 can be respectively subjected to attention calculation with the word vectors of "poetic genius", "Li Bai", "poetic sage" and "Du Fu", and four attention values can be obtained for each word unit in the first text 1. For the reference word unit, the four attention values corresponding to the reference word unit can be weighted and summed to obtain the first weight of the reference word unit, and the first weight and the word vector of the reference word unit are multiplied to obtain the feature vector of the reference word unit. Through the above method, the feature vectors of each word unit in the first text 1 can be obtained, and then the feature vector sequence of the first text 1 can be obtained. Similarly, the word vectors of each word unit in the first text 2 can be respectively subjected to attention calculation with the word vectors of "poetic genius" and "Li Bai", and two attention values can be obtained for each word unit in the first text 2. For the reference word unit, the two attention values corresponding to the reference word unit can be weighted and summed to obtain the first weight of the reference word unit, and the first weight and the word vector of the reference word unit are multiplied to obtain the feature vector of the reference word unit. Through the above method, the feature vectors of each word unit in the first text 2 can be obtained, and then the feature vector sequence of the first text 2 can be obtained.
[0189] Step 418, determine the text feature vector of each sample text based on the feature vector sequence of each first text.
[0190] Exemplarily, taking the first text 1 as an example, the feature vector at the [CLS] position in the feature vector sequence of the first text 1 can be determined as the text feature vector of the sample text 1.
[0191] Step 420, input the feature vector sequence of each first text into the feed-forward neural network layer, and determine the predicted start position and the predicted end position in each first text.
[0192] Step 422, determine the text between the predicted start position and the predicted end position in each first text as the predicted answer corresponding to each sample text, and obtain the context text of each predicted answer.
[0193] For example, assuming that text 1 is "Li Bai was honored as the Immortal Poet by later generations", the feature vector sequence of text 1 is input into the feedforward neural network layer, and the probability of each word unit being the starting position of the predicted answer and the probability of each word unit being the ending position of the predicted answer can be obtained. Assuming that "Li" has the highest probability of being the starting position of the predicted answer and "Bai" has the highest probability of being the ending position of the predicted answer, it can be determined that the predicted answer is "Li Bai", and "was honored as the Immortal Poet by later generations" can be determined as the context text of the predicted answer.
[0194] Step 424 : Determine a first loss value based on the at least two predicted answers and the sample answer.
[0195] For example, the loss value 1 between the predicted answer 1 of sample text 1 and the sample answer can be determined by the loss function, and the loss value 2 between the predicted answer 2 of sample text 2 and the sample answer can be determined by the loss function. The loss value 1 and the loss value 2 are added and averaged to obtain the first loss value.
[0196] In step 426 , at least two predicted answers, the sample question, and the context text of each predicted answer are concatenated and input into the feature extraction layer of the reordering module to obtain a concatenated feature vector.
[0197] The question-answering model includes a reordering module, which is used to sort the text corresponding to the extracted answers. As an example, the reordering module may include a feature extraction layer and a feedforward neural network layer.
[0198] For example, the sample question, predicted answer 1, and the contextual information of predicted answer 1 can be concatenated to obtain concatenated text 1 corresponding to sample text 1. This concatenated text 1 is input into the feature extraction layer for feature extraction to obtain a concatenated feature vector corresponding to sample text 1. Similarly, concatenated feature vectors corresponding to sample text 2 and sample text 3 can be obtained.
[0199] Step 428: Input the concatenated feature vector and the text feature vectors of at least two sample texts into the feedforward neural network layer to obtain a correlation feature vector for each sample text.
[0200] Step 430 : Perform a linear transformation on the correlation feature vector of each sample text to obtain the prediction probability corresponding to each sample text.
[0201] For example, by performing linear transformation on the correlation feature vectors of sample text 1, sample text 2, and sample text 3 respectively, each correlation feature vector can be converted into a single numerical value, obtaining 3 numerical values, and performing normalization (softmax) processing on the 3 numerical values to obtain the prediction probabilities corresponding to sample text 1, sample text 2, and sample text 3 respectively.
[0202] Step 432: Determine the predicted tags of the sample texts whose predicted probabilities are greater than a probability threshold as relevant, and determine the predicted tags of the sample texts whose predicted probabilities are less than or equal to the probability threshold as irrelevant.
[0203] For example, assuming the probability threshold is 0.5, the predicted probability corresponding to sample text 1 is 0.9, the predicted probability corresponding to sample text 2 is 0.3, and the predicted probability corresponding to sample text 3 is 0.8, the predicted tags of sample text 1 and sample text 3 can be determined as relevant, and the predicted tag of sample text 2 can be determined as irrelevant.
[0204] Step 434 : Determine a second loss value based on the predicted labels of the at least two sample texts and the sample labels of the at least two sample texts.
[0205] For example, the predicted tag 1 of sample text 1, the predicted tag 2 of sample text 2, the predicted tag 3 of sample text 3, the sample tag of sample text 1, the sample tag of sample text 2, and the sample tag of sample text 2 can be used as inputs of the cross entropy loss function to obtain a second loss value.
[0206] Step 436: Adjust the parameters of the reading comprehension module and the parameters of the reordering module based on the first loss value and the second loss value until both the reading comprehension module and the reordering module meet the training stop conditions, and stop training the question-answering model.
[0207] As an example, if the first loss value is less than the first threshold, and the second loss value is less than the second threshold, it can be considered that the training of the reading comprehension module and the reordering module has been completed, and the training of the reading comprehension module and the reordering module can be stopped. If the first loss value is greater than or equal to the first threshold, and the second loss value is less than the second threshold, it can be considered that the reading comprehension module has not been trained, the reordering module has been trained, and it is necessary to continue training the reading comprehension module and the reordering module. If the first loss value is greater than or equal to the first threshold, and the second loss value is greater than or equal to the second threshold, it can be considered that the training of the reading comprehension module and the reordering module has not been completed, therefore, it is necessary to continue training the reading comprehension module and the reordering module. If the first loss value is less than the first threshold, and the second loss value is greater than or equal to the second threshold, it can be considered that the reading comprehension module has been trained, but the reordering module has not been trained, therefore, it is necessary to continue training the reading comprehension module and the reordering module.
[0208] In an embodiment of the present application, the reordering module is placed after the reading comprehension module. When training the reordering module, the output of the reading comprehension module, i.e., the predicted answer, the context text of the predicted answer, and the characteristics of the sample text can be taken into consideration, rather than sorting the sample text only according to the relevance between the sample text and the sample question. This can improve the sorting accuracy of the sample text, place the sample text that may have the correct answer in front, improve the sorting performance of the trained reordering module, and thereby improve the performance of the question-answering model.
[0209] Figure 5 This is a flowchart of another question-answering model training method provided in an embodiment of the present application, including steps 502 to 508.
[0210] Step 502: Obtain a sample question, at least two sample texts, and a sample answer.
[0211] As an example, the sample answer is the correct answer to the sample question, and the sample question and the sample answer can be obtained from a pre-built training sample library.
[0212] In some embodiments, the question-answering model may further include a retrieval module, and the specific implementation of obtaining at least two sample texts may include: inputting the sample question into the retrieval module, and determining texts related to the sample question as the at least two sample texts, wherein the retrieval module is used to retrieve sample texts related to the sample question from a sample text library based on the sample question.
[0213] Among them, the function of the retrieval module is to retrieve texts related to sample questions from the sample text library.
[0214] As an example, the retrieval module used in the training process can be a pre-trained retrieval model that can retrieve texts that are literally related to the sample question from a sample text library. The sample text library can include multiple sample texts, and each sample text can carry manually annotated sample tags.
[0215] That is, a sample question can be input into the retrieval module, and the retrieval module can obtain texts related to the sample question from the sample text library as at least two sample texts.
[0216] In some embodiments, the specific implementation of inputting the sample question into the retrieval module and determining the text related to the sample question may include: inputting the sample question into the retrieval module to obtain the keyword unit in the sample question; and taking the text including the keyword unit in the sample text library as the text related to the sample question.
[0217] The keyword unit may be a core word that can represent the sample question, and the number of the keyword unit may be at least one.
[0218] That is, when a sample question is input into the retrieval module, text including keyword units can be obtained from the sample text library through an inverted index as text related to the sample question.
[0219] For example, see Figure 6 , input the sample question into the retrieval module, and you can get sample text 1 and sample text 2.
[0220] In other embodiments, texts related to sample questions can be obtained from a sample text library by means of an inverted index. Specifically, an inverted index needs to be created first. Multiple sample texts in the sample text library can be numbered to form a text list, and each sample text can be segmented to obtain multiple word units. The word units are used as indexes, and the numbers of the sample texts containing each word unit are saved to obtain an inverted index list. Then, a search is performed based on the inverted index. When a sample question is input, the input sample question is first segmented to obtain at least two word units. The at least two word units are then matched in the inverted index list. The at least two word units are used as indexes to determine the numbers of the sample texts containing the at least two word units. Based on the numbers, the sample text containing the at least two word units can be obtained, that is, the text related to the sample question can be obtained.
[0221] In this case, the sample text needs to include every word unit in the sample question in order to determine that the sample text is relevant to the sample question. In this way, the accuracy of the obtained sample text can be further improved.
[0222] Furthermore, after inputting the sample question into the retrieval module and determining the texts related to the sample question as the at least two sample texts, the method further includes: determining the word frequency of the keyword unit in the at least two sample texts; determining the inverse document word frequency of the keyword unit in the sample text library; determining the relevance score of each sample text based on the word frequency of the keyword unit in the at least two sample texts and the inverse document word frequency in the sample text library; and performing a preliminary sorting of the at least two sample texts based on the relevance score of each sample text to obtain the sorted at least two sample texts. Accordingly, the specific implementation of inputting the sample question and the at least two sample texts into the reading comprehension module may include: inputting the sorted at least two sample texts and the sample question into the reading comprehension module of the question-answering model in order.
[0223] That is, after obtaining at least two sample texts through the retrieval module, the at least two sample texts may be initially sorted, and the sorted at least two sample texts and sample questions may be input into the reading comprehension module in order.
[0224] As an example, for a reference keyword unit, the number of times the reference keyword unit appears in each sample text can be counted. Based on this number and the number of word units included in the sample text, the word frequency of the reference keyword unit in each sample text can be determined. The number of sample texts in the sample text library that include the reference keyword unit can be counted, and based on this number and the total number of sample texts in the sample text library, the inverse document word frequency of the reference keyword unit in the sample text library can be determined. Based on the word frequency of the reference keyword unit in each sample text and the inverse document word frequency in the sample text library, the relevance score of each sample text can be determined using the TF-IDF algorithm. At least two sample texts can be initially sorted in descending order of relevance scores to obtain at least two sorted sample texts.
[0225] It should be noted that the specific implementation of obtaining sample questions, sample answers and sample texts in this step is the same as the implementation process of step 202. The specific implementation can be found in the relevant description of step 202, and this embodiment will not be repeated here.
[0226] Step 504: Input the sample question and the at least two sample texts into the reading comprehension module of the question-answering model to obtain at least two predicted answers.
[0227] In some embodiments, the reading comprehension module includes a feature extraction layer and a feedforward neural network layer. The specific implementation of inputting the sample question and the at least two sample texts into the reading comprehension module of the question-answering model to obtain at least two predicted answers may include: splicing the sample question with the at least two sample texts respectively to obtain at least two second texts; inputting the at least two second texts into the feature extraction layer, determining the target word unit of each second text, and performing attention calculation on the target word unit of each second text with the word units of other second texts to obtain a feature vector sequence of each second text; determining the text feature vector of each sample text based on the feature vector sequence of each second text; inputting the feature vector sequence of each second text into the feedforward neural network layer, determining the predicted answer corresponding to each sample text, and obtaining the context text of each predicted answer.
[0228] The reading comprehension module is used to extract predicted answers to sample questions from sample text. As an example, the reading comprehension module can adopt the Longformer model, which can greatly increase the length of the input text and reduce the computational complexity of attention calculation.
[0229] Among them, the feature extraction layer is used to extract the feature vector of the input text, and the feedforward neural network layer is used to perform linear transformation on the input to obtain the predicted answer corresponding to each sample text.
[0230] The target word unit may be a keyword unit in the second text, and the number of the target word unit may be at least one.
[0231] As an example, the sample question and the sample text can be concatenated, and a separator can be inserted between the sample question and the sample text, and a category marker can be added before the resulting second sample. For example, assuming the sample question is "Who is the Immortal Poet?" and sample text 1 is "Li Bai was honored as the Immortal Poet by later generations." After concatenation, the second text can be "[CLS]Who is the Immortal Poet? [SEP]Li Bai was honored as the Immortal Poet by later generations." assuming sample text 2 is "Li Bai, the Immortal Poet, Du Fu, the Sage Poet," the second text can be "[CLS]Who is the Immortal Poet? [SEP]Li Bai, the Immortal Poet, Du Fu, the Sage Poet."
[0232] As an example, the feature extraction layer may include a word embedding sublayer and an attention sublayer. The word embedding sublayer may perform word embedding processing on at least two second texts inputted, respectively, to obtain a word vector sequence for each second text. The word vector sequence includes multiple word vectors, and each word vector corresponds to a word unit in the second text. The target word unit of each second text may also be determined, and then the target word vector of the target word unit of each second text may be determined. The attention sublayer may perform attention calculation on the word vector sequence of each second text and the target word vectors of other second texts to obtain a feature vector sequence for each second text. Furthermore, the feature vector at the [CLS] position in the feature vector sequence of each second text may be determined as the text feature vector of each sample text.
[0233] In some embodiments, the feature vector sequence of each second text is input into the feedforward neural network layer, and the specific implementation of determining the predicted answer corresponding to each sample text may include: inputting the feature vector sequence of each second text into the feedforward neural network layer, determining the prediction starting position and the prediction ending position in each second text; and determining the text located between the prediction starting position and the prediction ending position in each second text as the predicted answer corresponding to each sample text.
[0234] As an example, the feedforward neural network layer can also be called a linear transformation layer, which is used to perform linear transformation on the feature vector of each word unit in the input feature vector sequence. Two probabilities can be obtained for each word unit, one is the probability that the word unit is the starting position of the predicted answer, and the other is the probability that the word unit is the ending position of the predicted answer. Based on the two probabilities of each word unit, the predicted starting position and the predicted ending position can be determined, and the text between the predicted starting position and the predicted ending position can be determined as the predicted answer.
[0235] For example, see Figure 6 , splice the sample question and sample text 1 into the reading comprehension module, and splice the sample question and sample text 2 into the reading comprehension model, and you can get predicted answer 1 and predicted answer 2.
[0236] It should be noted that the specific implementation of determining the predicted answer in this step is the same as the implementation process of step 204. The specific implementation can be found in the relevant description of step 204, and this embodiment will not be repeated here.
[0237] Step 506: Determine a third loss value based on the at least two predicted answers and the sample answer.
[0238] In some embodiments, the loss value of each predicted answer and sample answer can be determined by a loss function to obtain at least two loss values, and the at least two loss values are added and averaged to obtain a third loss value.
[0239] As an example, the loss function may be a cross loss function, an exponential loss function, etc. At least two predicted answers and a sample answer may be input into the loss function, and then loss values of the at least two predicted answers and the sample answer may be determined to obtain at least two loss values. The at least two loss values may be summed and averaged to obtain a third loss value for training the reading comprehension module.
[0240] Step 508: Train the reading comprehension module based on the third loss value until a training stop condition is reached.
[0241] In some embodiments, the specific implementation of training the reading comprehension module based on the third loss value until the training stop condition is reached may include: if the third loss value is less than a third threshold, stopping the training of the reading comprehension module; if the third loss value is greater than or equal to the third threshold, continuing to train the reading comprehension module.
[0242] It should be noted that the third threshold value can be set by the user according to actual needs, or can be set by default by the computing device, and the embodiments of the present application do not limit this.
[0243] As an example, if the third loss value is less than the third threshold, it can be considered that the performance of the reading comprehension module has met the actual requirements, that is, the reading comprehension module has been trained, and training of the reading comprehension module can be stopped. If the third loss value is greater than or equal to the third threshold, it can be considered that the performance of the reading comprehension module has not met the actual requirements, that is, the reading comprehension module has not been trained, and training of the reading comprehension module needs to be continued.
[0244] In an embodiment of the present application, by determining whether to continue training the reading comprehension module based on the relationship between the loss value and the third threshold, the training degree of the reading comprehension module can be more accurately grasped, thereby improving the training efficiency of the reading comprehension module and its accuracy in handling question-and-answer tasks.
[0245] For example, see Figure 6 , a third loss value can be determined based on the predicted answer 1, the predicted answer 2 and the sample answer, and the parameters of the reading comprehension module can be adjusted based on the third loss value to achieve training of the reading comprehension module.
[0246] Furthermore, the question-answering model also includes a reordering module, and the training method of the reordering module is as follows: obtaining a sample question, at least two sample answers, the context text of each sample answer, the text feature vectors of at least two sample texts, and the sample labels of at least two sample texts; inputting the sample question, the at least two sample answers, the context text of each sample answer and the text feature vector of each sample text into the reordering module to obtain the prediction probability corresponding to each sample text, and determining the prediction labels of the at least two sample texts based on the prediction probability corresponding to each sample text; determining a fourth loss value based on the prediction labels of the at least two sample texts and the sample labels of the at least two sample texts, and training the reordering module based on the fourth loss value until the training stop condition is reached.
[0247] The predicted probability of the sample text can be used to indicate the degree of relevance between the sample text and the sample question. The relevance feature vector can be used to characterize the relevance between the sample question and the predicted answer.
[0248] As an example, the feature extraction layer can adopt the structure of the ALBERT model for feature extraction. The feedforward neural network layer can be used to perform a linear transformation on the input to obtain the predicted probability corresponding to each sample text.
[0249] As an example, sample questions can be obtained from a training database, and the sample questions can be input into a trained retrieval module to obtain at least two sample texts related to the sample questions. The sample questions and at least two sample texts can be input into a trained reading comprehension module to obtain at least two sample answers, the context text of each sample answer, and a text feature vector of each sample text.
[0250] For example, see Figure 7 , the sample question, sample text 1 and sample text 2 can be input into the trained reading comprehension module, and sample answer 1, sample answer 2, the context text of sample answer 1, the context text of sample answer 2, the text feature vector of sample text 1 and the text feature vector of sample text 2 can be obtained.
[0251] In some embodiments, the reordering module includes a feature extraction layer and a feedforward neural network layer, and the sample question, the at least two sample answers, the context text of each sample answer, and the text feature vector of each sample text are input into the reordering module to obtain the prediction probability corresponding to each sample text, including: splicing the at least two sample answers, the sample question, and the context text of each sample answer, inputting the spliced feature vector into the feature extraction layer, and obtaining the spliced feature vector; inputting the spliced feature vector and the text feature vector of the at least two sample texts into the feedforward neural network layer, and obtaining the correlation feature vector of each sample text; and performing a linear transformation on the correlation feature vector of each sample text to obtain the prediction probability corresponding to each sample text.
[0252] As an example, a sample question can be concatenated with at least two sample answers and the context text of each sample answer to obtain a concatenated text. This concatenated text is then input into a feature extraction layer to obtain at least two concatenated feature vectors. Each concatenated feature vector is then concatenated with the text feature vector of each sample text. The concatenated result is input into a feedforward neural network layer to obtain a correlation feature vector for each sample text. A linear transformation is performed on the correlation feature vector of each sample text to convert each correlation feature vector into a single numerical value, resulting in at least two numerical values. These at least two numerical values are then normalized (softmax) to obtain a predicted probability corresponding to each sample text.
[0253] In some embodiments, a specific implementation of determining the prediction tags of the at least two sample texts based on the prediction probability corresponding to each sample text may include: determining the prediction tags of the sample texts whose prediction probability is greater than a probability threshold as relevant, and determining the prediction tags of the sample texts whose prediction probability is less than or equal to the probability threshold as irrelevant.
[0254] That is to say, if the predicted probability is greater than the probability threshold, it can be considered that the sample text has a relatively high correlation with the sample question, and the predicted label of the sample text can be determined as relevant; if the predicted probability is less than or equal to the probability threshold, it can be considered that the sample text has a relatively low correlation with the sample question, and the predicted label of the sample text can be determined as irrelevant.
[0255] For example, see Figure 7 , the sample answer 1, the context text of the sample answer 1, the text feature vector of the sample text 1, the sample answer 2, the context text of the sample answer 2 and the text feature vector of the sample text 2 can be input into the reordering module to obtain the predicted tag 1 of the sample text 1 and the predicted tag 2 of the sample text 2.
[0256] In some embodiments, after the predicted labels of the at least two sample texts are determined, a fourth loss value may be further determined based on the predicted labels of the at least two sample texts and the sample labels of the at least two sample texts.
[0257] Exemplarily, the predicted tags and sample tags of at least two sample texts can be used as inputs of the loss function. When determining the fourth loss value, instead of determining the loss values corresponding to different sample texts separately, the predicted tags and sample tags of at least two sample texts are considered at the same time. This can fully consider the relationship between the sample texts and improve the performance of the reordering module.
[0258] It should be noted that the implementation process of training the reordering module is similar to the operation process performed in the reordering module in step 206. Its specific implementation can be found in the relevant description of step 206, and this embodiment will not be repeated here.
[0259] In some embodiments, the reordering module is trained based on the fourth loss value until a training stop condition is reached, including: if the fourth loss value is less than a fourth threshold, stopping the training of the reordering module; if the fourth loss value is greater than or equal to the fourth threshold, continuing to train the reordering module.
[0260] As an example, if the fourth loss value is less than the fourth threshold, it can be considered that the training of the reordering module has been completed, the performance of the model can already meet the user requirements, and the training of the reordering module can be stopped; if the fourth loss value is greater than or equal to the fourth threshold, it can be considered that the reordering module has not been trained, and the performance of its model cannot meet the user requirements. Therefore, it is necessary to continue training the reordering module.
[0261] For example, see Figure 7 , a fourth loss value can be determined based on sample label 1, sample label 2, prediction label 1 and prediction label 2, and the reranking module can be trained based on the fourth loss value.
[0262] In an embodiment of the present application, the reading comprehension module and the reordering module are trained separately. The reading comprehension module is trained first, and then the output of the reading comprehension module is used as input to train the reordering module to obtain a trained reordering module.
[0263] In an embodiment of the present application, the reordering module is placed after the reading comprehension module. When training the reordering module, the output of the reading comprehension module, i.e., the predicted answer, the context text of the predicted answer, and the characteristics of the sample text can be taken into consideration, rather than sorting the sample text only according to the relevance between the sample text and the sample question. This can improve the sorting accuracy of the sample text, place the sample text that may have the correct answer in front, improve the sorting performance of the trained reordering module, and thereby improve the performance of the question-answering model.
[0264] Figure 8 This is a flowchart of a question-and-answer method provided in an embodiment of the present application, including steps 802 to 806.
[0265] Step 802: Obtain a question to be processed and at least two texts to be processed, and input the question to be processed and the at least two texts to be processed into the reading comprehension module of the question-answering model to obtain at least two target answers, the context text of each target answer, and the text feature vector of each text to be processed.
[0266] In some embodiments, the question-answering model also includes a retrieval module, and the specific implementation of obtaining at least two texts to be processed may include: inputting the question to be processed into the retrieval module, and determining texts related to the question to be processed as the at least two texts to be processed, wherein the retrieval module is used to retrieve the text to be processed related to the question to be processed from the text library to be processed based on the question to be processed.
[0267] The function of the retrieval module is to retrieve the text to be processed that is related to the problem to be processed from the text to be processed library. As an example, the retrieval module can retrieve the text to be processed that is literally related to the problem to be processed from the text to be processed library. The text to be processed library can include multiple texts to be processed.
[0268] That is, the question to be processed can be input into the retrieval module, and the retrieval module can obtain texts related to the question to be processed from the to-be-processed text library as at least two to-be-processed texts.
[0269] For example, see Figure 9 , input the question to be processed into the retrieval module of the question-answering model, and the text to be processed 1 and the text to be processed 2 can be obtained.
[0270] In some embodiments, the specific implementation of inputting the problem to be processed into the retrieval module and determining the text related to the problem to be processed may include: inputting the problem to be processed into the retrieval module, obtaining the keyword unit in the problem to be processed; and taking the text including the keyword unit in the text library to be processed as the text related to the problem to be processed.
[0271] The keyword unit may be a core word that can represent the problem to be processed, and the number of the keyword unit may be at least one.
[0272] That is, the question to be processed is input into the retrieval module, and the text including the keyword unit can be obtained from the text library to be processed as the text related to the question to be processed by means of an inverted index.
[0273] As an example, the question to be processed is input into the retrieval module, and the question to be processed can be segmented to obtain multiple word units, and keyword units can be obtained from the multiple word units.
[0274] Generally, if a text contains a keyword unit, it can be considered that the text is relatively relevant to the keyword unit, and thus, the text can be considered to be highly relevant to the problem to be processed. Therefore, the text containing the keyword unit can be considered as the text related to the problem to be processed. As an example, if the number of keyword units is greater than one, the text containing all keyword units in the text library to be processed can be considered as the text related to the problem to be processed.
[0275] For example, assuming that the problem to be processed is "What is the smallest natural number", the text to be processed 1 in the text library to be processed is "0 is the smallest natural number", and the text to be processed 2 in the text library to be processed is "1 is the smallest odd number". It can be determined that the text to be processed 1 includes "natural number" and "smallest", then the text to be processed 1 can be determined as the text related to the problem to be processed, and the text to be processed 2 includes "smallest" but does not include "natural number", then the text to be processed 2 cannot be determined as the text related to the problem to be processed.
[0276] In other embodiments, texts related to the problem to be processed can be obtained from the to-be-processed text library by means of an inverted index. Specifically, an inverted index needs to be created first. The multiple to-be-processed texts in the to-be-processed text library can be numbered to form a text list, and each to-be-processed text can be segmented to obtain multiple word units. The word units are used as indexes, and the numbers of the to-be-processed texts containing each word unit are saved to obtain an inverted index list. Then, a search is performed based on the inverted index. When a problem to be processed is input, the input to-be-processed problem is first segmented to obtain at least two word units. The at least two word units are then matched in the inverted index list. The at least two word units are used as indexes to determine the numbers of the to-be-processed texts containing the at least two word units. Based on the numbers, the to-be-processed texts containing the at least two word units can be obtained, that is, the text related to the problem to be processed can be obtained.
[0277] In this case, the text to be processed needs to include every word unit in the question to be processed before the text to be processed can be determined to be relevant to the question to be processed. In this way, the accuracy of the obtained text to be processed can be further improved.
[0278] Furthermore, after inputting the problem to be processed into a retrieval module and determining texts related to the problem to be processed as the at least two texts to be processed, the method further includes: determining the word frequencies of the keyword units in the at least two texts to be processed; determining the inverse document word frequencies of the keyword units in the text library to be processed; determining a relevance score for each text to be processed based on the word frequencies of the keyword units in the at least two texts to be processed and the inverse document word frequencies in the text library to be processed; and performing a preliminary sorting of the at least two texts to be processed based on the relevance scores of each text to be processed to obtain the sorted at least two texts to be processed;
[0279] Correspondingly, inputting the question to be processed and the at least two texts to be processed into the reading comprehension module of the question-answering model includes: inputting the sorted at least two texts to be processed and the question to be processed into the reading comprehension module of the question-answering model in sequence.
[0280] That is, after obtaining at least two texts to be processed through the retrieval module, the at least two texts to be processed may be initially sorted, and the sorted at least two texts to be processed and the questions to be processed may be input into the reading comprehension module in order.
[0281] As an example, for a reference keyword unit, the number of times the reference keyword unit appears in each to-be-processed text can be counted. Based on this number and the number of word units included in the to-be-processed text, the word frequency of the reference keyword unit in each to-be-processed text can be determined. The number of to-be-processed texts in the to-be-processed text library that includes the reference keyword unit can be counted. Based on this number and the total number of to-be-processed texts in the to-be-processed text library, the inverse document word frequency of the reference keyword unit in the to-be-processed text library can be determined. Based on the word frequency of the reference keyword unit in each to-be-processed text and the inverse document word frequency in the to-be-processed text library, the relevance score of each to-be-processed text can be determined using the TF-IDF algorithm. At least two to-be-processed texts can be initially sorted in descending order of relevance scores to obtain at least two sorted to-be-processed texts.
[0282] For example, the quotient between the number of occurrences of the reference keyword unit and the number of word units in the to-be-processed text can be used as the word frequency of the reference keyword unit in the to-be-processed text. The quotient between the number of to-be-processed texts in the to-be-processed text library and the number of to-be-processed texts in the to-be-processed text library that include the reference keyword unit can be used as the inverse document word frequency of the reference keyword unit.
[0283] For example, assuming that the problem to be processed includes keyword unit A, keyword unit B and keyword unit C, and the text to be processed 1 related to the problem to be processed includes keyword unit A and keyword unit B, the word frequency of keyword unit A in the text to be processed 1 can be determined, the word frequency of keyword unit B in the text to be processed 1 can be determined, and the inverse document word frequency of keyword unit A and the inverse document word frequency of keyword unit B can be determined. The product of the word frequency of keyword unit A and the inverse document word frequency can be determined to obtain a first product value, and the product of the word frequency of keyword unit B and the inverse document word frequency can be determined to obtain a second product value. The sum of the first product value and the second product value is determined as the relevance score of the text to be processed 1.
[0284] In some embodiments, the reading comprehension module includes a feature extraction layer and a feedforward neural network layer, and the question to be processed and the at least two texts to be processed are input into the reading comprehension module of the question-answering model to obtain at least two target answers, the context text of each target answer, and the text feature vector of each text to be processed, including: splicing the question to be processed with the at least two texts to be processed respectively to obtain at least two first texts; inputting the at least two first texts into the feature extraction layer, determining the target word unit of each first text, and performing attention calculation on the target word unit of each first text and the word unit of other first texts to obtain a feature vector sequence of each first text; determining the text feature vector of each text to be processed based on the feature vector sequence of each first text; inputting the feature vector sequence of each first text into the feedforward neural network layer, determining the target answer corresponding to each text to be processed, and obtaining the context text of each target answer.
[0285] Among them, the feature extraction layer is used to extract the feature vector of the input text, and the feedforward neural network layer is used to perform linear transformation on the input to obtain the target answer corresponding to each text to be processed.
[0286] The target word unit may be a keyword unit in the first text, and the number of the target word unit may be at least one.
[0287] As an example, the question to be processed and the text to be processed can be spliced together, and a separator can be inserted between the question to be processed and the text to be processed, and a category marker can be added before the first to be processed. For example, assuming that the question to be processed is "Who is the Immortal Poet?" and the text to be processed 1 is "Li Bai was honored as the Immortal Poet by later generations." After splicing, the first text "[CLS] Who is the Immortal Poet? [SEP] Li Bai was honored as the Immortal Poet by later generations." If the text to be processed 2 is "Li Bai, the Immortal Poet, Du Fu, the Sage Poet," the first text "[CLS] Who is the Immortal Poet? [SEP] Li Bai, the Immortal Poet, Du Fu, the Sage Poet" can be obtained after splicing.
[0288] As an example, the feature extraction layer may include a word embedding sublayer and an attention sublayer. The word embedding sublayer may perform word embedding processing on at least two first texts inputted respectively to obtain a word vector sequence for each first text. The word vector sequence includes multiple word vectors, and each word vector corresponds to a word unit in the first text. The target word unit of each first text may also be determined, and then the target word vector of the target word unit of each first text may be determined. The attention sublayer may be used to perform attention calculation on the word vector sequence of each first text and the target word vectors of other first texts to obtain a feature vector sequence for each first text. Furthermore, the feature vector at the [CLS] position in the feature vector sequence of each first text may be determined as the text feature vector of each text to be processed.
[0289] In some embodiments, the feature vector sequence of each first text is input into the feedforward neural network layer to determine the target answer corresponding to each text to be processed, including: inputting the feature vector sequence of each first text into the feedforward neural network layer, determining the prediction start position and the prediction end position in each first text; and determining the text located between the prediction start position and the prediction end position in each first text as the target answer corresponding to each text to be processed.
[0290] As an example, the feedforward neural network layer can also be called a linear transformation layer, which is used to perform linear transformation on the feature vector of each word unit in the input feature vector sequence. Two probabilities can be obtained for each word unit, one is the probability that the word unit is the starting position of the target answer, and the other is the probability that the word unit is the ending position of the target answer. According to the two probabilities of each word unit, the predicted starting position and the predicted ending position can be determined, and the text between the predicted starting position and the predicted ending position can be determined as the target answer.
[0291] For example, assuming that the text to be processed is "Li Bai is honored as the Immortal Poet by later generations", the feature vector sequence of the text to be processed is input into the feedforward neural network layer, and the probability that each word unit is the starting position of the target answer and the probability that each word unit is the ending position of the target answer can be obtained. Assuming that the probability that "Li" is the starting position of the target answer is the highest and the probability that "Bai" is the ending position of the target answer is the highest, it can be determined that the target answer is "Li Bai".
[0292] By the above method, the target answer corresponding to each to-be-processed text can be determined. When the target answer of each to-be-processed text is determined, the context text of the target answer can be obtained from the to-be-processed text.
[0293] For example, see Figure 9 , splice the question to be processed and the text to be processed 1, and input them into the reading comprehension module of the question-answering model, so as to obtain the target answer 1, and the target answer 1 is the answer extracted from the text to be processed 1, and obtain the context text of the target answer 1 and the text feature vector of the text to be processed 1, splice the question to be processed and the text to be processed 2 into the reading comprehension module of the question-answering model, and obtain the target answer 2, and the target answer 2 is the answer extracted from the text to be processed 2, and obtain the context text of the target answer 2 and the text feature vector of the text to be processed 2.
[0294] Step 804: Input the question to be processed, the at least two target answers, the context text of each target answer, and the text feature vector of each text to be processed into the reordering module of the question-answering model to obtain the target probability corresponding to each text to be processed.
[0295] In some embodiments, the reordering module includes a feature extraction layer and a feedforward neural network layer, and the at least two target answers, the question to be processed, the context text of each target answer, and the text feature vector of each text to be processed are input into the reordering module of the question-answering model to obtain the target probability corresponding to each text to be processed, including: splicing the at least two target answers, the question to be processed, and the context text of each target answer, inputting the spliced feature vector into the feature extraction layer, and obtaining the spliced feature vector; inputting the spliced feature vector and the text feature vector of the at least two texts to be processed into the feedforward neural network layer to obtain the relevance feature vector of each text to be processed; performing a linear transformation on the relevance feature vector of each text to be processed to obtain the target probability corresponding to each text to be processed.
[0296] The target probability of the text to be processed can be used to indicate the degree of relevance between the text to be processed and the question to be processed. The relevance feature vector can be used to characterize the relevance characteristics between the question to be processed and the predicted answer.
[0297] As an example, the feature extraction layer can adopt the structure of the ALBERT model for feature extraction. The feedforward neural network layer can be used to perform a linear transformation on the input to obtain the target probability corresponding to each text to be processed.
[0298] As an example, the question to be processed can be concatenated with at least two predicted answers and the context text of each predicted answer to obtain a concatenated text. The concatenated text is input into the feature extraction layer to obtain at least two concatenated feature vectors. Each concatenated feature vector is then concatenated with the text feature vector of each text to be processed, and the concatenated result is input into the feedforward neural network layer to obtain a correlation feature vector for each text to be processed. The correlation feature vector of each text to be processed is linearly transformed to convert each correlation feature vector into a single numerical value to obtain at least two numerical values. The at least two numerical values are normalized (softmax) to obtain the target probability corresponding to each text to be processed.
[0299] For example, taking the structure of the ALBERT model as an example, assuming that the question to be processed is represented by Q, the predicted answer is represented by A, and the context text of the predicted answer is represented by S, then the input of ALBERT is [Q; A; S], where ";" represents splicing. The "[CLS]" tag and the "[SEP]" tag in ALBERT are omitted here. Feature extraction is performed on this input to obtain a spliced feature vector. The text feature vector of each text to be processed is then spliced with the above-mentioned spliced feature vector, and the spliced feature vector is input into the feedforward neural network layer. Further feature extraction is performed in the feedforward neural network layer to obtain a correlation feature vector for each text to be processed. By multiplying the correlation feature vector with the linear transformation matrix, each correlation feature vector can be converted into a single numerical value, which can also be called a correlation score. The correlation scores of at least two texts to be processed are subjected to softmax processing to obtain the target probability corresponding to each text to be processed.
[0300] Step 806 : sorting the at least two texts to be processed based on the target probability of each text to be processed, and outputting the sorted texts to be processed and the at least two target answers.
[0301] In some embodiments, at least two to-be-processed texts may be sorted in descending order of target probability to obtain sorted to-be-processed texts.
[0302] As an example, the texts to be processed whose target probabilities are greater than a probability threshold may be output in sequence, and the target answers to the texts to be processed whose target probabilities are greater than the probability threshold may be output.
[0303] For example, it is assumed that the target probability of the to-be-processed text 1 is greater than the target probability of the to-be-processed text 2, and both target probabilities are greater than the probability threshold. Figure 9 , the target answer 1 and the target answer 2 can be output, and the to-be-processed text 1 and the to-be-processed text 2 can be output in sequence.
[0304] In an embodiment of the present application, the reordering module is placed after the reading comprehension module. When the text is reordered by the reordering module, the output of the reading comprehension module, i.e., the target answer, the context text of the target answer, and the feature vector of the text to be processed can be taken into consideration, instead of sorting the text to be processed only according to the relevance between the text to be processed and the question to be processed. This can improve the sorting accuracy of the text to be processed, place the text to be processed that may have the correct answer in front, improve the sorting performance of the reordering module, and thereby improve the accuracy of the question-answering model in performing question-answering tasks.
[0305] Figure 10 This is a flowchart of another question-and-answer method provided in an embodiment of the present application, including steps 1002 to 1004.
[0306] Step 1002: Obtain a question to be processed and at least two texts to be processed.
[0307] In some embodiments, the question-answering model may include a retrieval module, and the specific implementation of obtaining at least two texts to be processed may include: inputting the question to be processed into the retrieval module, and determining texts related to the question to be processed as the at least two texts to be processed, wherein the retrieval module is used to retrieve the text to be processed related to the question to be processed from the text library to be processed based on the question to be processed.
[0308] The function of the retrieval module is to retrieve the text to be processed that is related to the problem to be processed from the text to be processed library. As an example, the retrieval module can retrieve the text to be processed that is literally related to the problem to be processed from the text to be processed library. The text to be processed library can include multiple texts to be processed.
[0309] That is, the question to be processed can be input into the retrieval module, and the retrieval module can obtain texts related to the question to be processed from the to-be-processed text library as at least two to-be-processed texts.
[0310] In some embodiments, the specific implementation of inputting the problem to be processed into the retrieval module and determining the text related to the problem to be processed may include: inputting the problem to be processed into the retrieval module, obtaining the keyword unit in the problem to be processed; and taking the text including the keyword unit in the text library to be processed as the text related to the problem to be processed.
[0311] The keyword unit may be a core word that can represent the problem to be processed, and the number of the keyword unit may be at least one.
[0312] That is, the question to be processed is input into the retrieval module, and the text including the keyword unit can be obtained from the text library to be processed as the text related to the question to be processed by means of an inverted index.
[0313] As an example, the question to be processed is input into the retrieval module, and the question to be processed can be segmented to obtain multiple word units, and keyword units can be obtained from the multiple word units.
[0314] Generally, if a text contains a keyword unit, it can be considered that the text is relatively relevant to the keyword unit, and thus, the text can be considered to be highly relevant to the problem to be processed. Therefore, the text containing the keyword unit can be considered as the text related to the problem to be processed. As an example, if the number of keyword units is greater than one, the text containing all keyword units in the text library to be processed can be considered as the text related to the problem to be processed.
[0315] For example, assuming that the problem to be processed is "What is the smallest natural number", the text to be processed 1 in the text library to be processed is "0 is the smallest natural number", and the text to be processed 2 in the text library to be processed is "1 is the smallest odd number". It can be determined that the text to be processed 1 includes "natural number" and "smallest", then the text to be processed 1 can be determined as the text related to the problem to be processed, and the text to be processed 2 includes "smallest" but does not include "natural number", then the text to be processed 2 cannot be determined as the text related to the problem to be processed.
[0316] In other embodiments, texts related to the problem to be processed can be obtained from the to-be-processed text library by means of an inverted index. Specifically, an inverted index needs to be created first. The multiple to-be-processed texts in the to-be-processed text library can be numbered to form a text list, and each to-be-processed text can be segmented to obtain multiple word units. The word units are used as indexes, and the numbers of the to-be-processed texts containing each word unit are saved to obtain an inverted index list. Then, a search is performed based on the inverted index. When a problem to be processed is input, the input to-be-processed problem is first segmented to obtain at least two word units. The at least two word units are then matched in the inverted index list. The at least two word units are used as indexes to determine the numbers of the to-be-processed texts containing the at least two word units. Based on the numbers, the to-be-processed texts containing the at least two word units can be obtained, that is, the text related to the problem to be processed can be obtained.
[0317] In this case, the text to be processed needs to include every word unit in the question to be processed before the text to be processed can be determined to be relevant to the question to be processed. In this way, the accuracy of the obtained text to be processed can be further improved.
[0318] Furthermore, after inputting the problem to be processed into a retrieval module and determining texts related to the problem to be processed as the at least two texts to be processed, the method further includes: determining the word frequencies of the keyword units in the at least two texts to be processed; determining the inverse document word frequencies of the keyword units in the text library to be processed; determining a relevance score for each text to be processed based on the word frequencies of the keyword units in the at least two texts to be processed and the inverse document word frequencies in the text library to be processed; and performing a preliminary sorting of the at least two texts to be processed based on the relevance scores of each text to be processed to obtain the sorted at least two texts to be processed;
[0319] Correspondingly, the question to be processed is input into the retrieval module, and texts related to the question to be processed are determined as the at least two texts to be processed, including: inputting the sorted at least two texts to be processed and the question to be processed into the reading comprehension module of the question-answering model in order.
[0320] That is, after obtaining at least two texts to be processed through the retrieval module, the at least two texts to be processed may be initially sorted, and the sorted at least two texts to be processed and the questions to be processed may be input into the reading comprehension module in order.
[0321] As an example, for a reference keyword unit, the number of times the reference keyword unit appears in each to-be-processed text can be counted. Based on this number and the number of word units included in the to-be-processed text, the word frequency of the reference keyword unit in each to-be-processed text can be determined. The number of to-be-processed texts in the to-be-processed text library that includes the reference keyword unit can be counted. Based on this number and the total number of to-be-processed texts in the to-be-processed text library, the inverse document word frequency of the reference keyword unit in the to-be-processed text library can be determined. Based on the word frequency of the reference keyword unit in each to-be-processed text and the inverse document word frequency in the to-be-processed text library, the relevance score of each to-be-processed text can be determined using the TF-IDF algorithm. At least two to-be-processed texts can be initially sorted in descending order of relevance scores to obtain at least two sorted to-be-processed texts.
[0322] For example, the quotient between the number of occurrences of the reference keyword unit and the number of word units in the to-be-processed text can be used as the word frequency of the reference keyword unit in the to-be-processed text. The quotient between the number of to-be-processed texts in the to-be-processed text library and the number of to-be-processed texts in the to-be-processed text library that include the reference keyword unit can be used as the inverse document word frequency of the reference keyword unit.
[0323] For example, assuming that the problem to be processed includes keyword unit A, keyword unit B and keyword unit C, and the text to be processed 1 related to the problem to be processed includes keyword unit A and keyword unit B, the word frequency of keyword unit A in the text to be processed 1 can be determined, the word frequency of keyword unit B in the text to be processed 1 can be determined, and the inverse document word frequency of keyword unit A and the inverse document word frequency of keyword unit B can be determined. The product of the word frequency of keyword unit A and the inverse document word frequency can be determined to obtain a first product value, and the product of the word frequency of keyword unit B and the inverse document word frequency can be determined to obtain a second product value. The sum of the first product value and the second product value is determined as the relevance score of the text to be processed 1.
[0324] Step 1004: input the question to be processed and the at least two texts to be processed into a reading comprehension module of the question-answering model to obtain at least two target answers.
[0325] In some embodiments, the reading comprehension module includes a feature extraction layer and a feedforward neural network layer. The specific implementation of inputting the question to be processed and the at least two texts to be processed into the reading comprehension module of the question-answering model to obtain at least two target answers may include: splicing the question to be processed with the at least two texts to be processed respectively to obtain at least two second texts; inputting the at least two second texts into the feature extraction layer, determining the target word unit of each second text, and performing attention calculation on the target word unit of each second text with the word units of other second texts to obtain a feature vector sequence of each second text; inputting the feature vector sequence of each second text into the feedforward neural network layer to determine the target answer corresponding to each text to be processed.
[0326] Among them, the feature extraction layer is used to extract the feature vector of the input text, and the feedforward neural network layer is used to perform linear transformation on the input to obtain the target answer corresponding to each text to be processed.
[0327] The target word unit may be a keyword unit in the second text, and the number of the target word unit may be at least one.
[0328] As an example, the question to be processed and the text to be processed can be spliced together, and a separator can be inserted between the question to be processed and the text to be processed, and a category marker can be added before the first to be processed. For example, assuming that the question to be processed is "Who is the Immortal Poet?" and the first text to be processed is "Li Bai is honored as the Immortal Poet by later generations." After splicing, the second text can be "[CLS]Who is the Immortal Poet? [SEP]Li Bai is honored as the Immortal Poet by later generations." If the second text to be processed is "Li Bai, the Immortal Poet, Du Fu, the Sage Poet," the second text can be "[CLS]Who is the Immortal Poet? [SEP]Li Bai, the Immortal Poet, Du Fu, the Sage Poet."
[0329] As an example, the feature extraction layer may include a word embedding sublayer and an attention sublayer. The word embedding sublayer may perform word embedding processing on at least two second texts inputted, respectively, to obtain a word vector sequence for each second text, wherein the word vector sequence includes multiple word vectors, and each word vector corresponds to a word unit in the second text. A target word unit for each second text may also be determined, and then a target word vector for the target word unit of each second text may be determined. The attention sublayer may perform attention calculation on the word vector sequence of each second text and the target word vectors of other second texts to obtain a feature vector sequence for each second text.
[0330] In some embodiments, the feature vector sequence of each second text is input into the feedforward neural network layer to determine the target answer corresponding to each text to be processed, including: inputting the feature vector sequence of each second text into the feedforward neural network layer, determining the target starting position and the target ending position in each second text; and determining the text located between the target starting position and the target ending position in each second text as the target answer corresponding to each text to be processed.
[0331] As an example, the feedforward neural network layer can also be called a linear transformation layer, which is used to perform linear transformation on the feature vector of each word unit in the input feature vector sequence. Two probabilities can be obtained for each word unit, one is the probability that the word unit is the starting position of the target answer, and the other is the probability that the word unit is the ending position of the target answer. According to the two probabilities of each word unit, the target starting position and the target ending position can be determined, and the text between the target starting position and the target ending position can be determined as the target answer.
[0332] For example, assuming that the text to be processed is "Li Bai is honored as the Immortal Poet by later generations", the feature vector sequence of the text to be processed is input into the feedforward neural network layer, and the probability that each word unit is the starting position of the target answer and the probability that each word unit is the ending position of the target answer can be obtained. Assuming that the probability that "Li" is the starting position of the target answer is the highest and the probability that "Bai" is the ending position of the target answer is the highest, it can be determined that the target answer is "Li Bai".
[0333] It should be noted that, through the above method, the target answer corresponding to each text to be processed can be determined, and the question-answering task can be completed through the above steps, but the number of texts to be processed is large, and the number of target answers obtained is also large, and there may be some incorrect answers. Therefore, in a possible implementation method of the present application, the question-answering model can also include a reordering module, which can further determine the correct answer to the question to be processed through the reordering module, and reorder and output the text to be processed.
[0334] In one possible implementation, after determining the feature vector sequence of each text to be processed according to the reading comprehension module, the text feature vector of each text to be processed can also be determined based on the feature vector sequence of each text to be processed, and the context text of each target answer can be determined based on each text to be processed and the corresponding target answer.
[0335] As an example, the feature vector at the [CLS] position in the feature vector sequence of each text to be processed can be determined as the text feature vector of each text to be processed, and the text before and after each target answer and its corresponding text to be processed can be determined as the context text of each target answer.
[0336] In implementation, the question to be processed, the target answer for each text to be processed, and the context text of each target answer can be input into the reordering module of the question-answering model to obtain the target probability corresponding to each text to be processed.
[0337] In some embodiments, the reordering module includes a feature extraction layer and a feedforward neural network layer, which can splice at least two target answers, the question to be processed and the context text of each target answer, input the feature extraction layer, and obtain a spliced feature vector; input the spliced feature vector and the text feature vectors of at least two texts to be processed into the feedforward neural network layer to obtain a relevance feature vector of each text to be processed; and perform a linear transformation on the relevance feature vector of each text to be processed to obtain the target probability corresponding to each text to be processed.
[0338] The target probability of the text to be processed can be used to indicate the degree of relevance between the text to be processed and the question to be processed. The relevance feature vector can be used to characterize the relevance feature between the question to be processed and the target answer.
[0339] As an example, the feature extraction layer can adopt the structure of the ALBERT model for feature extraction. The feedforward neural network layer can be used to perform a linear transformation on the input to obtain the target probability corresponding to each text to be processed.
[0340] As an example, the question to be processed can be spliced with at least two target answers and the context text of each target answer to obtain a spliced text, which is then input into a feature extraction layer to obtain at least two spliced feature vectors. Each spliced feature vector is then spliced with the text feature vector of each text to be processed, and the splicing result is input into a feedforward neural network layer to obtain a correlation feature vector for each text to be processed. The correlation feature vector of each text to be processed is linearly transformed to convert each correlation feature vector into a single numerical value to obtain at least two numerical values. The at least two numerical values are normalized (softmax) to obtain the target probability corresponding to each text to be processed.
[0341] For example, taking the structure of the ALBERT model as an example, assuming that the question to be processed is represented by Q, the target answer is represented by A, and the context text of the target answer is represented by S, then the input of ALBERT is [Q; A; S], where ";" represents splicing. The "[CLS]" tag and the "[SEP]" tag in ALBERT are omitted here. Feature extraction is performed on the input to obtain a spliced feature vector. The text feature vector of each text to be processed is then spliced with the above-mentioned spliced feature vector, and the spliced feature vector is input into the feedforward neural network layer. Further feature extraction is performed in the feedforward neural network layer to obtain a correlation feature vector for each text to be processed. By multiplying the correlation feature vector with the linear transformation matrix, each correlation feature vector can be converted into a single numerical value, which can also be called a correlation score. The correlation scores of at least two texts to be processed are subjected to softmax processing to obtain the target probability corresponding to each text to be processed.
[0342] In some embodiments, after determining the target probability of each text to be processed, at least two texts to be processed can be sorted in descending order according to the target probability, and the sorted texts to be processed can be obtained. At least two texts to be processed can be output in order, and the target answer of each text to be processed can be output.
[0343] As an example, the texts to be processed whose target probabilities are greater than a probability threshold may be output in sequence, and the target answers to the texts to be processed whose target probabilities are greater than the probability threshold may be output.
[0344] In an embodiment of the present application, the reordering module is placed after the reading comprehension module. When the text is reordered by the reordering module, the output of the reading comprehension module, i.e., the target answer, the context text of the target answer, and the feature vector of the text to be processed can be taken into consideration, instead of sorting the text to be processed only according to the relevance between the text to be processed and the question to be processed. This can improve the sorting accuracy of the text to be processed, place the text to be processed that may have the correct answer in front, improve the sorting performance of the reordering module, and thereby improve the accuracy of the question-answering model in performing question-answering tasks.
[0345] Figure 11 This is a flowchart of a question-answering method applied to a question-answering task according to an embodiment of the present application. The question-answering task is described using the question to be processed as an example, "Who is the poet saint?", and specifically may include the following steps:
[0346] Step 1102: Obtain issues to be processed.
[0347] For example, the question to be addressed is "Who is the poet?"
[0348] Step 1104: input the question to be processed into the retrieval module of the question-answering model to obtain the keyword units in the question to be processed.
[0349] For example, by segmenting the sentence "Who is the poet sage", we get three word units, namely "poet sage", "is", and "who". "Poet sage" can be determined as a keyword unit.
[0350] Step 1106 : Use the texts containing keyword units in the text library as to-be-processed texts related to the problem to be processed, and obtain N to-be-processed texts.
[0351] Here, N is a positive integer greater than or equal to 2.
[0352] For example, if there are two texts containing “Poet Saint” in the text library, then these two texts can be determined as texts to be processed.
[0353] See also Figure 12 , input the question to be processed into the retrieval module, and two texts to be processed can be obtained, namely text to be processed 1 and text to be processed 2.
[0354] Step 1108 : determining the word frequencies of the keyword units in the N to-be-processed texts, and determining the inverse document word frequencies of the keyword units in the text library.
[0355] For example, assuming that the text to be processed 1 includes 20 words and "Poet Saint" appears once, then the word frequency of "Poet Saint" in the text to be processed 1 is 0.1. Similarly, assuming that the text to be processed 2 includes 10 words and "Poet Saint" appears 2 times, then the word frequency of "Poet Saint" in the text to be processed 2 is 0.4.
[0356] Assume that the text library includes 100 texts to be processed. In addition to any text in the text to be processed 1 and the text to be processed 2, there are 25 texts to be processed in the text library that include the word "Poet Saint". Then the inverse document word frequency of "Poet Saint" in the text library is 4.
[0357] Step 1110 : Determine the relevance score of each text to be processed based on the word frequency of the keyword unit in the N texts to be processed and the inverse document word frequency in the text library.
[0358] Continuing with the above example, the relevance score of each to-be-processed text can be determined using the TF-IDF algorithm. The relevance score of the term "poet sage" in to-be-processed text 1 is 0.1×4=0.4, and the relevance score of the term "poet sage" in to-be-processed text 2 is 0.4×4=1.6. Since the keyword unit only includes "poet sage", 0.4 can be determined as the relevance score of to-be-processed text 1, and 1.6 can be determined as the relevance score of to-be-processed text 2.
[0359] Step 1112: Based on the relevance score of each of the texts to be processed, the N texts to be processed are initially sorted to obtain sorted N texts to be processed.
[0360] Continuing with the above example, the three to-be-processed texts may be sorted in descending order of relevance scores, and the sorted N to-be-processed texts may be to-be-processed text 2 and to-be-processed text 1.
[0361] Step 1114: concatenate each to-be-processed text with the to-be-processed question to obtain N first texts.
[0362] For example, the question to be processed and the text to be processed can be concatenated, with a separator inserted between them, and a category marker added before the resulting first text. For example, assuming the question to be processed is "Who is the Sage of Poetry?" and the text to be processed is "Du Fu is revered as the Sage of Poetry by later generations," the concatenated first text can be "[CLS]Who is the Sage of Poetry?[SEP]Du Fu is revered as the Sage of Poetry by later generations."
[0363] Step 1116: Input the N first texts into the feature extraction layer of the reading comprehension module in the order of the N texts to be processed, determine the target word unit of each first text, and perform attention calculation on the target word unit of each first text and the word units of other first texts to obtain a feature vector sequence for each first text.
[0364] Taking the first text "[CLS]Who is the Sage of Poetry?[SEP]Du Fu is respected as the Sage of Poetry by later generations" as an example, it can be determined that the target word units are "Sage of Poetry" and "Du Fu". The word vectors of each word unit in the first text can be respectively subjected to attention calculation with the word vectors of "Sage of Poetry" and "Du Fu". For each word unit in the first text, four attention values can be obtained. For the reference word unit, the four attention values corresponding to the reference word unit can be weighted and summed to obtain the first weight of the reference word unit. Multiplying the first weight by the word vector of the reference word unit can obtain the feature vector of the reference word unit. Through the above method, the feature vectors of each word unit in the first text can be obtained, and then the feature vector sequence of the first text can be obtained. Similarly, the feature vector sequences of other first texts can be obtained.
[0365] Step 1118, determine the text feature vector of each text to be processed based on the feature vector sequence of each first text.
[0366] Continuing with the above example, the feature vector at the [CLS] position in the feature vector sequence of the first text can be determined as the text feature vector of the text to be processed.
[0367] Step 1120, input the feature vector sequence of each first text into the feed-forward neural network layer, and determine the target start position and target end position in each first text.
[0368] Step 1122, determine the text between the target start position and the target end position in each first text as the target answer corresponding to each text to be processed, and obtain the context text of each target answer.
[0369] For example, inputting the feature vector sequence of the text to be processed into the feed-forward neural network layer can obtain the probability that each word unit is the start position of the target answer and the probability that each word unit is the end position of the target answer. Assuming that the probability that "Du" is the start position of the target answer is the highest and the probability that "Fu" is the end position of the target answer is the highest, it can be determined that the target answer is "Du Fu", and "is respected as the Sage of Poetry by later generations" can be determined as the context text of the target answer.
[0370] See Figure 12 , inputting the text to be processed 2 and the text to be processed 1 into the reading comprehension module in sequence, the target answer 1, the text feature vector of the text to be processed 1, the context text of the target answer 1, the target answer 2, the text feature vector of the text to be processed 2, and the context text of the target answer 2 can be obtained. Among them, the target answer 1 is the answer extracted from the text to be processed 1, and the target answer 2 is the answer extracted from the text to be processed 2.
[0371] In step 1124, the N target answers, the question to be processed, and the context text of each target answer are concatenated and input into the feature extraction layer of the reordering module to obtain a concatenated feature vector.
[0372] For example, we can concatenate target answer 1, unprocessed text 1, and the context text of target answer 1, and input the concatenation result into the feature extraction layer of the reordering module to obtain the concatenated feature vector of unprocessed text 1. Similarly, we can obtain the concatenated feature vector of unprocessed text 2.
[0373] Step 1126: Input the concatenated feature vector and the text feature vectors of the N to-be-processed texts into the feed-forward neural network layer to obtain a correlation feature vector for each to-be-processed text.
[0374] Step 1128: Perform a linear transformation on the correlation feature vector of each text to be processed to obtain a target probability corresponding to each text to be processed.
[0375] For example, by performing linear transformation on the correlation feature vectors of the text to be processed 1 and the text to be processed 2 respectively, each correlation feature vector can be converted into a single numerical value, obtaining two numerical values, and performing normalization (softmax) processing on the two numerical values to obtain the target probabilities corresponding to the text to be processed 1 and the text to be processed 2 respectively.
[0376] Step 1130 , sorting the N to-be-processed texts according to the target probability, outputting the to-be-processed texts whose target probability is greater than the probability threshold in order, and outputting the target answers of the to-be-processed texts whose target probability is greater than the probability threshold.
[0377] For example, assuming that the probability threshold is 0.5, the target probability corresponding to the text to be processed 1 is 0.6, and the target probability corresponding to the text to be processed 2 is 0.8, it can be determined that the target probabilities of the text to be processed 1 and the text to be processed 2 are both greater than the probability threshold, then the text to be processed 1 and the text to be processed 2 can be output, and the target answer 1 and the target answer 2 can be output.
[0378] See also Figure 12 , the target answer 1, the text feature vector of the text to be processed 1, the context text of the target answer 1, the target answer 2, the text feature vector of the text to be processed 2 and the context text of the target answer 2 are input into the reordering module, and the text to be processed 1 and the text to be processed 2 are sorted. The final output of the reordering module is the text to be processed 2, the text to be processed 1, the target answer 1 and the target answer 2.
[0379] In an embodiment of the present application, the reordering module is placed after the reading comprehension module. When the text is reordered by the reordering module, the output of the reading comprehension module, i.e., the target answer, the context text of the target answer, and the feature vector of the text to be processed can be taken into consideration, instead of sorting the text to be processed only according to the relevance between the text to be processed and the question to be processed. This can improve the sorting accuracy of the text to be processed, place the text to be processed that may have the correct answer in front, improve the sorting performance of the reordering module, and thereby improve the accuracy of the question-answering model in performing question-answering tasks.
[0380] With the above Figure 2 Corresponding to the method embodiment shown, the present application also provides an embodiment of a training device for a question-answering model. Figure 13 FIG. 1 shows a schematic diagram of a training device for a question-answering model according to an embodiment of the present application. Figure 13 As shown, the apparatus 1300 may include:
[0381] A first acquisition module 1302 is configured to acquire a sample question, at least two sample texts, and a sample label, wherein the sample label includes a sample answer and sample labels of the at least two sample texts, and the sample label of each sample text indicates whether the sample text is relevant to the sample question;
[0382] A first determination module 1304 is configured to input the sample question and the at least two sample texts into a reading comprehension module of the question-answering model, obtain at least two predicted answers, context text for each predicted answer, and a text feature vector for each sample text, and determine a first loss value based on the at least two predicted answers and the sample answers;
[0383] The second determination module 1306 is configured to input the sample question, the at least two predicted answers, the context text of each predicted answer, and the text feature vector of each sample text into the re-ranking module of the question-answering model, obtain a prediction probability corresponding to each sample text, determine a prediction label of the at least two sample texts based on the prediction probability corresponding to each sample text, and determine a second loss value based on the prediction label of the at least two sample texts and the sample label of the at least two sample texts;
[0384] The first training module 1308 is configured to adjust the parameters of the reading comprehension module and the parameters of the reordering module based on the first loss value and the second loss value until both the reading comprehension module and the reordering module meet the training stop conditions, and stop training the question-answering model.
[0385] Optionally, the question-answering model further includes a retrieval module, and the first acquisition module 1302 is configured to:
[0386] The sample question is input into the retrieval module, and texts related to the sample question are determined as the at least two sample texts, wherein the retrieval module is used to retrieve sample texts related to the sample question from a sample text library based on the sample question.
[0387] Optionally, the first obtaining module 1302 is configured to:
[0388] Inputting the sample question into the search module to obtain keyword units in the sample question;
[0389] The text including the keyword unit in the sample text library is used as the text related to the sample question.
[0390] Optionally, the first obtaining module 1302 is further configured to:
[0391] Determining the word frequencies of the keyword units in the at least two sample texts respectively;
[0392] Determining the inverse document frequency of the keyword unit in the sample text library;
[0393] Determining a relevance score for each sample text based on the word frequency of the keyword unit in the at least two sample texts and the inverse document word frequency in the sample text library;
[0394] performing a preliminary sorting of the at least two sample texts based on the relevance score of each sample text to obtain the at least two sorted sample texts;
[0395] Accordingly, the first determining module 1304 is configured to:
[0396] The sorted at least two sample texts and the sample questions are input into the reading comprehension module of the question-answering model in order.
[0397] Optionally, the reading comprehension module includes a feature extraction layer and a feedforward neural network layer, and the first determination module 1304 is configured to:
[0398] Splicing the sample question with the at least two sample texts respectively to obtain at least two first texts;
[0399] Inputting the at least two first texts into the feature extraction layer, determining a target word unit of each first text, and performing attention calculation on the target word unit of each first text and word units of other first texts to obtain a feature vector sequence of each first text;
[0400] Determine a text feature vector for each sample text based on the feature vector sequence of each first text;
[0401] The feature vector sequence of each first text is input into the feedforward neural network layer, the predicted answer corresponding to each sample text is determined, and the context text of each predicted answer is obtained.
[0402] Optionally, the first determining module 1304 is configured to:
[0403] Inputting the feature vector sequence of each first text into the feedforward neural network layer, and determining a prediction start position and a prediction end position in each first text;
[0404] The text located between the prediction start position and the prediction end position in each first text is determined as the predicted answer corresponding to each sample text.
[0405] Optionally, the reordering module includes a feature extraction layer and a feedforward neural network layer, and the second determination module 1306 is configured to:
[0406] splicing the at least two predicted answers, the sample question, and the context text of each predicted answer, and inputting the result into the feature extraction layer to obtain a spliced feature vector;
[0407] Inputting the concatenated feature vector and the text feature vectors of the at least two sample texts into the feedforward neural network layer to obtain a correlation feature vector for each sample text;
[0408] Perform a linear transformation on the correlation feature vector of each sample text to obtain the prediction probability corresponding to each sample text.
[0409] Optionally, the second determining module 1306 is configured to:
[0410] The predicted tags of the sample texts whose predicted probabilities are greater than a probability threshold are determined to be relevant, and the predicted tags of the sample texts whose predicted probabilities are less than or equal to the probability threshold are determined to be irrelevant.
[0411] Optionally, the first training module 1308 is configured to:
[0412] If the first loss value is less than a first threshold, and the second loss value is less than a second threshold, stop training the reading comprehension module and the reordering module;
[0413] If the first loss value is greater than or equal to the first threshold, and the second loss value is less than the second threshold, adjusting parameters of the reading comprehension module and parameters of the reordering module based on the first loss value and the second loss value, and continuing to train the reading comprehension module and the reordering module;
[0414] If the first loss value is greater than or equal to the first threshold, and the second loss value is greater than or equal to the second threshold, adjusting parameters of the reading comprehension module and parameters of the reordering module based on the first loss value and the second loss value, and continuing to train the reading comprehension module and the reordering module;
[0415] If the first loss value is less than the first threshold and the second loss value is greater than or equal to the second threshold, the parameters of the reading comprehension module and the parameters of the reordering module are adjusted based on the first loss value and the second loss value, and the reading comprehension module and the reordering module continue to be trained.
[0416] In an embodiment of the present application, the reordering module is placed after the reading comprehension module. When training the reordering module, the output of the reading comprehension module, i.e., the predicted answer, the context text of the predicted answer, and the characteristics of the sample text can be taken into consideration, rather than sorting the sample text only according to the relevance between the sample text and the sample question. This can improve the sorting accuracy of the sample text, place the sample text that may have the correct answer in front, improve the sorting performance of the trained reordering module, and thereby improve the performance of the question-answering model.
[0417] The above is a schematic scheme of a training device for a question-answering model of this embodiment. It should be noted that the technical scheme of the training device for the question-answering model is the same as that of the above Figure 2 The technical solutions of the training method of the question-answering model shown in the figure belong to the same concept. For details not described in detail in the technical solution of the training device of the question-answering model, please refer to the above Figure 2 Description of the technical solution for the training method of the question-answering model shown.
[0418] With the above Figure 5 Corresponding to the method embodiment shown, this application also provides another embodiment of a training device for a question-answering model. Figure 14 FIG. 1 shows a structural diagram of a training device for a question-answering model according to another embodiment of the present invention. Figure 14 As shown, the question-answering model includes a reading comprehension module, and the device 1400 may include:
[0419] The second acquisition module 1402 is configured to acquire a sample question, at least two sample texts, and a sample answer;
[0420] A third determination module 1404 is configured to input the sample question and the at least two sample texts into a reading comprehension module of the question-answering model to obtain at least two predicted answers;
[0421] A fourth determining module 1406 is configured to determine a third loss value based on the at least two predicted answers and the sample answer;
[0422] The second training module 1408 is configured to train the reading comprehension module based on the third loss value until a training stop condition is reached.
[0423] Optionally, the reading comprehension module includes a feature extraction layer and a feedforward neural network layer, and the third determination module 1404 is configured to:
[0424] Splicing the sample question with the at least two sample texts respectively to obtain at least two second texts;
[0425] Inputting the at least two second texts into the feature extraction layer, determining a target word unit of each second text, and performing attention calculation on the target word unit of each second text and word units of other second texts to obtain a feature vector sequence of each second text;
[0426] Determine a text feature vector for each sample text based on the feature vector sequence of each second text;
[0427] The feature vector sequence of each second text is input into the feedforward neural network layer, the predicted answer corresponding to each sample text is determined, and the context text of each predicted answer is obtained.
[0428] Optionally, the third determining module 1404 is configured to:
[0429] Inputting the feature vector sequence of each second text into the feedforward neural network layer, and determining a prediction start position and a prediction end position in each second text;
[0430] The text located between the prediction start position and the prediction end position in each second text is determined as the predicted answer corresponding to each sample text.
[0431] Optionally, the second training module 1408 is configured to:
[0432] If the third loss value is less than a third threshold, stopping the training of the reading comprehension module;
[0433] If the third loss value is greater than or equal to the third threshold, continue training the reading comprehension module.
[0434] Optionally, the question-answering model further includes a reordering module, and the apparatus further includes a third training module, which is configured to:
[0435] Obtaining a sample question, at least two sample answers, context text of each sample answer, text feature vectors of at least two sample texts, and sample tags of at least two sample texts;
[0436] Inputting the sample question, the at least two sample answers, the context text of each sample answer, and the text feature vector of each sample text into the reordering module, obtaining a prediction probability corresponding to each sample text, and determining a prediction label for the at least two sample texts based on the prediction probability corresponding to each sample text;
[0437] A fourth loss value is determined based on the predicted labels of the at least two sample texts and the sample labels of the at least two sample texts, and the reordering module is trained based on the fourth loss value until a training stop condition is met.
[0438] Optionally, the reordering module includes a feature extraction layer and a feedforward neural network layer, and the third training module is further configured to:
[0439] splicing the at least two sample answers, the sample question, and the context text of each sample answer, and inputting the resultant information into the feature extraction layer to obtain a spliced feature vector;
[0440] Inputting the concatenated feature vector and the text feature vectors of the at least two sample texts into the feedforward neural network layer to obtain a correlation feature vector for each sample text;
[0441] Perform a linear transformation on the correlation feature vector of each sample text to obtain the prediction probability corresponding to each sample text.
[0442] Optionally, the third training module is further configured to:
[0443] The predicted tags of the sample texts whose predicted probabilities are greater than a probability threshold are determined to be relevant, and the predicted tags of the sample texts whose predicted probabilities are less than or equal to the probability threshold are determined to be irrelevant.
[0444] Optionally, the third training module is further configured to:
[0445] If the fourth loss value is less than a fourth threshold, stopping the training of the reordering module;
[0446] If the fourth loss value is greater than or equal to the fourth threshold, continue training the reordering module.
[0447] In an embodiment of the present application, the reordering module is placed after the reading comprehension module. When training the reordering module, the output of the reading comprehension module, i.e., the predicted answer, the context text of the predicted answer, and the characteristics of the sample text can be taken into consideration, rather than sorting the sample text only according to the relevance between the sample text and the sample question. This can improve the sorting accuracy of the sample text, place the sample text that may have the correct answer in front, improve the sorting performance of the trained reordering module, and thereby improve the performance of the question-answering model.
[0448] The above is a schematic diagram of a training device for a question-answering model according to this embodiment. It should be noted that the technical solution of this training device for a question-answering model is based on the same concept as the technical solution of the training method for a question-answering model described above. For details not described in detail in the technical solution for the training device for a question-answering model, please refer to the description of the technical solution for the training method for a question-answering model described above.
[0449] With the above Figure 8 Corresponding to the method embodiment shown, this application also provides an embodiment of a question-answering device. Figure 15 FIG. 1 shows a schematic diagram of the structure of a question-answering device according to an embodiment of the present application. Figure 15 As shown, the apparatus 1500 may include:
[0450] The third acquisition module 1502 is configured to obtain a question to be processed and at least two texts to be processed, and input the question to be processed and the at least two texts to be processed into the reading comprehension module of the question-answering model to obtain at least two target answers, the context text of each target answer, and the text feature vector of each text to be processed, wherein the question-answering model is configured to obtain at least two target answers, the context text of each target answer, and the text feature vector of each text to be processed. Figure 2 The question answering model is trained using the training method shown;
[0451] A fifth determination module 1504 is configured to input the question to be processed, the at least two target answers, the context text of each target answer, and the text feature vector of each text to be processed into the reordering module of the question-answering model to obtain a target probability corresponding to each text to be processed;
[0452] The output module 1506 is configured to sort the at least two texts to be processed based on the target probability of each text to be processed, and output the sorted texts to be processed and the at least two target answers.
[0453] Optionally, the question-answering model further includes a retrieval module, a second acquisition module 1502, configured to:
[0454] The problem to be processed is input into the retrieval module, and texts related to the problem to be processed are determined as the at least two texts to be processed, wherein the retrieval module is used to retrieve the texts to be processed related to the problem to be processed from the text library to be processed based on the problem to be processed.
[0455] Optionally, the third obtaining module 1502 is configured to:
[0456] Inputting the problem to be processed into the search module to obtain keyword units in the problem to be processed;
[0457] The text including the keyword unit in the to-be-processed text library is used as the text related to the to-be-processed question.
[0458] Optionally, the third obtaining module 1502 is further configured to:
[0459] Determining the word frequencies of the keyword units in the at least two texts to be processed respectively;
[0460] Determining the inverse document frequency of the keyword unit in the to-be-processed text library;
[0461] Determining a relevance score for each text to be processed based on the word frequency of the keyword unit in the at least two texts to be processed and the inverse document word frequency in the text library to be processed;
[0462] Based on the relevance score of each of the to-be-processed texts, performing a preliminary sorting on the at least two to-be-processed texts to obtain sorted at least two to-be-processed texts;
[0463] The sorted at least two texts to be processed and the questions to be processed are input into the reading comprehension module of the question-answering model in order.
[0464] Optionally, the reading comprehension module includes a feature extraction layer and a feedforward neural network layer, and the fifth determination module 1504 is configured to:
[0465] Splicing the question to be processed with the at least two texts to be processed respectively to obtain at least two first texts;
[0466] Inputting the at least two first texts into the feature extraction layer, determining a target word unit of each first text, and performing attention calculation on the target word unit of each first text and word units of other first texts to obtain a feature vector sequence of each first text;
[0467] Determine a text feature vector of each to-be-processed text based on the feature vector sequence of each first text;
[0468] The feature vector sequence of each first text is input into the feedforward neural network layer, the target answer corresponding to each to-be-processed text is determined, and the context text of each target answer is obtained.
[0469] Optionally, the fifth determining module 1504 is configured to:
[0470] Inputting the feature vector sequence of each first text into the feedforward neural network layer, and determining a prediction start position and a prediction end position in each first text;
[0471] The text located between the predicted start position and the predicted end position in each first text is determined as the target answer corresponding to each text to be processed.
[0472] Optionally, the reordering module includes a feature extraction layer and a feedforward neural network layer, and the sixth determination module 1506 is configured to:
[0473] Splicing the at least two target answers, the question to be processed, and the context text of each target answer, and inputting the results into the feature extraction layer to obtain a spliced feature vector;
[0474] Inputting the concatenated feature vector and the text feature vectors of the at least two to-be-processed texts into the feedforward neural network layer to obtain a correlation feature vector for each to-be-processed text;
[0475] Perform a linear transformation on the correlation feature vector of each text to be processed to obtain the target probability corresponding to each text to be processed.
[0476] In an embodiment of the present application, the reordering module is placed after the reading comprehension module. When the text is reordered by the reordering module, the output of the reading comprehension module, i.e., the target answer, the context text of the target answer, and the feature vector of the text to be processed can be taken into consideration, instead of sorting the text to be processed only according to the relevance between the text to be processed and the question to be processed. This can improve the sorting accuracy of the text to be processed, place the text to be processed that may have the correct answer in front, improve the sorting performance of the reordering module, and thereby improve the accuracy of the question-answering model in performing question-answering tasks.
[0477] The above is a schematic scheme of a question-answering device of this embodiment. It should be noted that the technical scheme of the question-answering device is similar to the above Figure 8 The technical solutions of the question-answering method shown in the figure belong to the same concept. For details not described in detail in the technical solution of the question-answering device, please refer to the above Figure 8 Description of the technical solution of the question-answering method shown.
[0478] With the above Figure 10 Corresponding to the method embodiment shown, this application also provides another question-answering device embodiment, Figure 16 FIG. 1 shows a schematic diagram of the structure of a question-answering device according to another embodiment of the present application. Figure 16 As shown, the apparatus 1600 may include:
[0479] The fourth acquisition module 1602 is configured to acquire a question to be processed and at least two texts to be processed;
[0480] The sixth determination module 1604 is configured to input the question to be processed and the at least two texts to be processed into the reading comprehension module of the question-answering model to obtain at least two target answers, wherein the question-answering model is trained using the training method of the question-answering model described above.
[0481] Optionally, the reading comprehension module includes a feature extraction layer and a feedforward neural network layer, and the sixth determination module 1604 is configured to:
[0482] Splicing the question to be processed with the at least two texts to be processed respectively to obtain at least two second texts;
[0483] Inputting the at least two second texts into the feature extraction layer, determining a target word unit of each second text, and performing attention calculation on the target word unit of each second text and word units of other second texts to obtain a feature vector sequence of each second text;
[0484] Determining a text feature vector of each to-be-processed text based on a feature vector sequence of each second text;
[0485] The feature vector sequence of each second text is input into the feedforward neural network layer to determine the target answer corresponding to each text to be processed.
[0486] Optionally, the sixth determining module 1604 is configured to:
[0487] Inputting the feature vector sequence of each second text into the feedforward neural network layer, and determining the target starting position and the target ending position in each second text;
[0488] The text located between the target start position and the target end position in each second text is determined as the target answer corresponding to each text to be processed.
[0489] In an embodiment of the present application, the reordering module is placed after the reading comprehension module. When the text is reordered by the reordering module, the output of the reading comprehension module, i.e., the target answer, the context text of the target answer, and the feature vector of the text to be processed can be taken into consideration, instead of sorting the text to be processed only according to the relevance between the text to be processed and the question to be processed. This can improve the sorting accuracy of the text to be processed, place the text to be processed that may have the correct answer in front, improve the sorting performance of the reordering module, and thereby improve the accuracy of the question-answering model in performing question-answering tasks.
[0490] The above is a schematic scheme of a question-answering device of this embodiment. It should be noted that the technical scheme of the question-answering device is similar to the above Figure 10The technical solutions of the question-answering method shown in the figure belong to the same concept. For details not described in detail in the technical solution of the question-answering device, please refer to the above Figure 10 Description of the technical solution of the question-answering method shown.
[0491] It should be noted that the components in a device claim should be understood as the functional modules necessary to implement each step of the program flow or method. The individual functional modules are not defined by actual functional division or separation. A device claim defined by such a set of functional modules should be understood as a functional module architecture that primarily implements the solution through the computer program described in the specification, rather than a physical device that primarily implements the solution through hardware.
[0492] In one embodiment of the present application, a computing device is also provided, including a memory, a processor, and computer instructions stored in the memory and executable on the processor. When the processor executes the instructions, the steps of the training method of the question-answering model are implemented, or when the processor executes the instructions, the steps of the question-answering method are implemented.
[0493] The above is a schematic solution of a computing device of this embodiment. It should be noted that the technical solution of this computing device is similar to the above Figure 2 or Figure 5 The technical solutions of the training method of the question-answering model shown in the figure belong to the same concept. For details not described in detail in the technical solution of the computing device, please refer to the above Figure 2 or Figure 5 Alternatively, the technical solution of the computing device is the same as that of the above-mentioned Figure 8 or Figure 10 The technical solution of the question-answering method shown in the figure belongs to the same concept. For details not described in detail in the technical solution of the computing device, please refer to the above Figure 8 or Figure 10 Description of the technical solution of the question-answering method shown.
[0494] An embodiment of the present application also provides a computer-readable storage medium storing computer instructions, which, when executed by a processor, implement the steps of the training method of the question-answering model as described above, or, when executed by a processor, implement the steps of the question-answering method as described above.
[0495] The above is a schematic solution of a computer-readable storage medium of this embodiment. It should be noted that the technical solution of this storage medium is the same as the above Figure 2 or Figure 5 The technical solutions of the training method of the question-answering model shown in the figure belong to the same concept. For details not described in detail in the technical solution of the storage medium, please refer to the above Figure 2 or Figure 5 Alternatively, the technical solution of the storage medium is the same as the above-mentioned Figure 8 or Figure 10 The technical solution of the question-answering method shown in the figure belongs to the same concept. For details not described in detail in the technical solution of the storage medium, please refer to the above Figure 8 or Figure 10 Description of the technical solution of the question-answering method shown.
[0496] An embodiment of the present application discloses a chip storing computer instructions, which, when executed by a processor, implement the steps of the training method of the question-answering model as described above, or, when executed by a processor, implement the steps of the question-answering method as described above.
[0497] The foregoing description describes specific embodiments of the present application. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recited in the claims can be performed in an order different from that described in the embodiments and still achieve the desired results. Furthermore, the processes depicted in the accompanying drawings do not necessarily require the specific order shown or the sequential order to achieve the desired results. In certain embodiments, multitasking and parallel processing are also possible or may be advantageous.
[0498] The computer instructions include computer program code, which may be in source code form, object code form, executable file, or some intermediate form. The computer-readable medium may include: any entity or device capable of carrying the computer program code, recording medium, USB flash drive, mobile hard disk, magnetic disk, optical disk, computer memory, read-only memory (ROM), random access memory (RAM), electric carrier signal, telecommunication signal, and software distribution medium, etc. It should be noted that the content contained in the computer-readable medium may be appropriately increased or decreased according to the requirements of legislation and patent practice in the jurisdiction. For example, in some jurisdictions, according to legislation and patent practice, computer-readable media do not include electric carrier signals and telecommunication signals.
[0499] It should be noted that for the aforementioned method embodiments, for ease of description, they are all expressed as a series of action combinations, but those skilled in the art should be aware that this application is not limited by the order of the actions described, because according to this application, certain steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in this specification are all preferred embodiments, and the actions and modules involved are not necessarily required by this application.
[0500] In the above embodiments, the description of each embodiment has its own focus. For parts that are not described in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.
[0501] The preferred embodiments of the present application disclosed above are intended only to help illustrate the present application. The optional embodiments do not describe all details in detail, nor do they limit the invention to the specific embodiments described. Obviously, many modifications and variations can be made based on the content of this application. This application selects and describes these embodiments in detail in order to better explain the principles and practical applications of this application, so that those skilled in the art can better understand and utilize this application. This application is limited only by the claims and their full scope and equivalents.
Claims
1. A training method for a question-answering model, characterized in that: include: Obtaining a sample question, at least two sample texts, and a sample label, wherein the sample label includes a sample answer and sample labels of the at least two sample texts, and the sample label of each sample text indicates whether the sample text is relevant to the sample question; Inputting the sample question and the at least two sample texts into a reading comprehension module of a question-answering model, obtaining at least two predicted answers, context text for each predicted answer, and a text feature vector for each sample text, and determining a first loss value based on the at least two predicted answers and the sample answers; Inputting the sample question, the at least two predicted answers, the context text of each predicted answer, and the text feature vector of each sample text into the reordering module of the question-answering model, obtaining a prediction probability corresponding to each sample text, and determining a prediction label of the at least two sample texts based on the prediction probability corresponding to each sample text, and determining a second loss value based on the prediction label of the at least two sample texts and the sample label of the at least two sample texts, wherein the prediction probability represents the degree of relevance between the sample text and the sample question, and the prediction label represents whether the sample text is relevant to the sample question; The parameters of the reading comprehension module and the parameters of the reordering module are adjusted based on the first loss value and the second loss value until both the reading comprehension module and the reordering module meet the training stop conditions, and the training of the question-answering model is stopped.
2. The training method of the question-answering model according to claim 1, wherein: The question-answering model further includes a retrieval module for obtaining at least two sample texts, including: The sample question is input into the retrieval module, and texts related to the sample question are determined as the at least two sample texts, wherein the retrieval module is used to retrieve sample texts related to the sample question from a sample text library based on the sample question.
3. The training method of the question-answering model according to claim 2, wherein: Inputting the sample question into the search module and determining text related to the sample question includes: Inputting the sample question into the search module to obtain keyword units in the sample question; The text including the keyword unit in the sample text library is used as the text related to the sample question.
4. The training method of the question-answering model according to claim 3, wherein: After inputting the sample question into the search module and determining texts related to the sample question as the at least two sample texts, the method further includes: Determining the word frequencies of the keyword units in the at least two sample texts respectively; Determining the inverse document frequency of the keyword unit in the sample text library; Determining a relevance score for each sample text based on the word frequency of the keyword unit in the at least two sample texts and the inverse document word frequency in the sample text library; performing a preliminary sorting of the at least two sample texts based on the relevance score of each sample text to obtain the at least two sorted sample texts; Accordingly, the sample question and the at least two sample texts are input into the reading comprehension module of the question-answering model, including: The sorted at least two sample texts and the sample questions are input into the reading comprehension module of the question-answering model in order.
5. The method for training a question-answering model according to any one of claims 1 to 4, wherein: The reading comprehension module includes a feature extraction layer and a feedforward neural network layer. The sample question and the at least two sample texts are input into the reading comprehension module of the question-answering model to obtain at least two predicted answers, context text for each predicted answer, and a text feature vector for each sample text, including: Splicing the sample question with the at least two sample texts respectively to obtain at least two first texts; Inputting the at least two first texts into the feature extraction layer, determining a target word unit of each first text, and performing attention calculation on the target word unit of each first text and word units of other first texts to obtain a feature vector sequence of each first text; Determine a text feature vector for each sample text based on the feature vector sequence of each first text; The feature vector sequence of each first text is input into the feedforward neural network layer, the predicted answer corresponding to each sample text is determined, and the context text of each predicted answer is obtained.
6. The training method of the question-answering model according to claim 5, wherein: Inputting the feature vector sequence of each first text into the feedforward neural network layer, and determining the predicted answer corresponding to each sample text, including: Inputting the feature vector sequence of each first text into the feedforward neural network layer, and determining a prediction start position and a prediction end position in each first text; The text located between the prediction start position and the prediction end position in each first text is determined as the predicted answer corresponding to each sample text.
7. The method for training a question-answering model according to any one of claims 1 to 4, wherein: The reordering module includes a feature extraction layer and a feedforward neural network layer. The sample question, the at least two predicted answers, the context text of each predicted answer, and the text feature vector of each sample text are input into the reordering module of the question-answering model to obtain the predicted probability corresponding to each sample text, including: splicing the at least two predicted answers, the sample question, and the context text of each predicted answer, and inputting the result into the feature extraction layer to obtain a spliced feature vector; Inputting the concatenated feature vector and the text feature vectors of the at least two sample texts into the feedforward neural network layer to obtain a correlation feature vector for each sample text; Perform a linear transformation on the correlation feature vector of each sample text to obtain the prediction probability corresponding to each sample text.
8. The method for training a question-answering model according to claim 1, wherein: Determining the predicted labels of the at least two sample texts based on the predicted probability corresponding to each sample text includes: The predicted tags of the sample texts whose predicted probabilities are greater than a probability threshold are determined to be relevant, and the predicted tags of the sample texts whose predicted probabilities are less than or equal to the probability threshold are determined to be irrelevant.
9. The training method of the question-answering model according to claim 1, wherein: Adjusting parameters of the reading comprehension module and parameters of the reordering module based on the first loss value and the second loss value until both the reading comprehension module and the reordering module meet a training stop condition, and stopping training of the question-answering model, including: If the first loss value is less than a first threshold, and the second loss value is less than a second threshold, stop training the reading comprehension module and the reordering module; If the first loss value is greater than or equal to the first threshold, and the second loss value is less than the second threshold, adjusting parameters of the reading comprehension module and parameters of the reordering module based on the first loss value and the second loss value, and continuing to train the reading comprehension module and the reordering module; If the first loss value is greater than or equal to the first threshold, and the second loss value is greater than or equal to the second threshold, adjusting parameters of the reading comprehension module and parameters of the reordering module based on the first loss value and the second loss value, and continuing to train the reading comprehension module and the reordering module; If the first loss value is less than the first threshold and the second loss value is greater than or equal to the second threshold, the parameters of the reading comprehension module and the parameters of the reordering module are adjusted based on the first loss value and the second loss value, and the reading comprehension module and the reordering module continue to be trained.
10. A training method for a question-answering model, characterized in that: include: Get sample questions, at least two sample texts, and sample answers; Inputting the sample question and the at least two sample texts into a reading comprehension module of a question-answering model to obtain at least two predicted answers; determining a third loss value based on the at least two predicted answers and the sample answer; Training the reading comprehension module based on the third loss value until a training stop condition is reached; The question-answering model further includes a reordering module, and the training method of the reordering module includes: Obtain a sample question, at least two sample answers, the context text of each sample answer, the text feature vectors of at least two sample texts, and the sample labels of at least two sample texts, wherein the sample labels of at least two sample texts represent whether the sample text is relevant to the sample question; input the sample question, the at least two sample answers, the context text of each sample answer, and the text feature vector of each sample text into the reordering module to obtain the prediction probability corresponding to each sample text, and determine the prediction labels of the at least two sample texts based on the prediction probability corresponding to each sample text, wherein the prediction probability represents the degree of relevance between the sample text and the sample question, and the prediction label represents whether the sample text is relevant to the sample question; determine a fourth loss value based on the prediction labels of the at least two sample texts and the sample labels of the at least two sample texts, and train the reordering module based on the fourth loss value until a training stop condition is reached.
11. The method for training a question-answering model according to claim 10, wherein: The reading comprehension module includes a feature extraction layer and a feedforward neural network layer. The sample question and the at least two sample texts are input into the reading comprehension module to obtain at least two predicted answers, including: Splicing the sample question with the at least two sample texts respectively to obtain at least two second texts; Inputting the at least two second texts into the feature extraction layer, determining a target word unit of each second text, and performing attention calculation on the target word unit of each second text and word units of other second texts to obtain a feature vector sequence of each second text; Determine a text feature vector for each sample text based on the feature vector sequence of each second text; The feature vector sequence of each second text is input into the feedforward neural network layer, the predicted answer corresponding to each sample text is determined, and the context text of each predicted answer is obtained.
12. The method for training a question-answering model according to claim 11, wherein: Inputting the feature vector sequence of each second text into the feedforward neural network layer to determine the predicted answer corresponding to each sample text, including: Inputting the feature vector sequence of each second text into the feedforward neural network layer, and determining a prediction start position and a prediction end position in each second text; The text located between the prediction start position and the prediction end position in each second text is determined as the predicted answer corresponding to each sample text.
13. The method for training a question-answering model according to claim 10, wherein: Training the reading comprehension module based on the third loss value until a training stop condition is reached includes: If the third loss value is less than a third threshold, stopping the training of the reading comprehension module; If the third loss value is greater than or equal to the third threshold, continue training the reading comprehension module.
14. The method for training a question-answering model according to claim 10, wherein: The reordering module includes a feature extraction layer and a feedforward neural network layer. The sample question, the at least two sample answers, the context text of each sample answer, and the text feature vector of each sample text are input into the reordering module to obtain the predicted probability corresponding to each sample text, including: splicing the at least two sample answers, the sample question, and the context text of each sample answer, and inputting the resultant information into the feature extraction layer to obtain a spliced feature vector; Inputting the concatenated feature vector and the text feature vectors of the at least two sample texts into the feedforward neural network layer to obtain a correlation feature vector for each sample text; Perform a linear transformation on the correlation feature vector of each sample text to obtain the prediction probability corresponding to each sample text.
15. The method for training a question-answering model according to claim 14, wherein: Determining the predicted labels of the at least two sample texts based on the predicted probability corresponding to each sample text includes: The predicted tags of the sample texts whose predicted probabilities are greater than a probability threshold are determined to be relevant, and the predicted tags of the sample texts whose predicted probabilities are less than or equal to the probability threshold are determined to be irrelevant.
16. The method for training a question-answering model according to claim 10, wherein: Training the reordering module based on the fourth loss value until a training stop condition is reached, comprising: If the fourth loss value is less than a fourth threshold, stopping the training of the reordering module; If the fourth loss value is greater than or equal to the fourth threshold, continue training the reordering module.
17. A question-answering method, characterized in that: include: Obtaining a question to be processed and at least two texts to be processed, and inputting the question to be processed and the at least two texts to be processed into a reading comprehension module of a question-answering model to obtain at least two target answers, context text for each target answer, and a text feature vector for each text to be processed, wherein the question-answering model is trained by the question-answering model training method according to any one of claims 1 to 9; Inputting the question to be processed, the at least two target answers, the context text of each target answer, and the text feature vector of each text to be processed into the reordering module of the question-answering model to obtain a target probability corresponding to each text to be processed; The at least two texts to be processed are sorted based on the target probability of each text to be processed, and the sorted texts to be processed and the at least two target answers are output.
18. A question-answering method, characterized in that: include: Get a pending question and at least two pending texts; The question to be processed and the at least two texts to be processed are input into a reading comprehension module of a question-answering model to obtain at least two target answers, wherein the question-answering model is trained by the training method of the question-answering model described in any one of claims 10-16.
19. A training device for a question-answering model, characterized in that: include: A first acquisition module is configured to acquire a sample question, at least two sample texts, and a sample label, wherein the sample label includes a sample answer and sample labels of the at least two sample texts, and the sample label of each sample text indicates whether the sample text is relevant to the sample question; A first determination module is configured to input the sample question and the at least two sample texts into a reading comprehension module of the question-answering model, obtain at least two predicted answers, context text of each predicted answer, and a text feature vector of each sample text, and determine a first loss value based on the at least two predicted answers and the sample answers; a second determination module configured to input the sample question, the at least two predicted answers, the context text of each predicted answer, and the text feature vector of each sample text into the reordering module of the question-answering model, obtain a prediction probability corresponding to each sample text, determine prediction labels of the at least two sample texts based on the prediction probability corresponding to each sample text, and determine a second loss value based on the prediction labels of the at least two sample texts and the sample labels of the at least two sample texts, wherein the prediction probability represents a degree of relevance between the sample text and the sample question, and the prediction label represents whether the sample text is relevant to the sample question; The first training module is configured to adjust the parameters of the reading comprehension module and the parameters of the reordering module based on the first loss value and the second loss value until the reading comprehension module and the reordering module both meet the training stop conditions, thereby stopping the training of the question-answering model.
20. A training device for a question-answering model, characterized in that: include: A second acquisition module is configured to acquire a sample question, at least two sample texts, and a sample answer; A third determination module is configured to input the sample question and the at least two sample texts into a reading comprehension module of the question-answering model to obtain at least two predicted answers; a fourth determining module, configured to determine a third loss value based on the at least two predicted answers and the sample answer; a second training module, configured to train the reading comprehension module based on the third loss value until a training stop condition is reached; Optionally, the question-answering model further includes a reordering module, and the apparatus further includes a third training module, which is configured to: Obtain a sample question, at least two sample answers, the context text of each sample answer, the text feature vectors of at least two sample texts, and the sample labels of at least two sample texts, wherein the sample labels of at least two sample texts represent whether the sample text is relevant to the sample question; input the sample question, the at least two sample answers, the context text of each sample answer, and the text feature vector of each sample text into the reordering module to obtain the prediction probability corresponding to each sample text, and determine the prediction labels of the at least two sample texts based on the prediction probability corresponding to each sample text, wherein the prediction probability represents the degree of relevance between the sample text and the sample question, and the prediction label represents whether the sample text is relevant to the sample question; determine a fourth loss value based on the prediction labels of the at least two sample texts and the sample labels of the at least two sample texts, and train the reordering module based on the fourth loss value until a training stop condition is reached.
21. A question-answering device, characterized in that: include: a third acquisition module configured to acquire a question to be processed and at least two texts to be processed, and input the question to be processed and the at least two texts to be processed into a reading comprehension module of a question-answering model to obtain at least two target answers, context text for each target answer, and a text feature vector for each text to be processed, wherein the question-answering model is trained by the question-answering model training method according to any one of claims 1 to 9; a fifth determination module configured to input the question to be processed, the at least two target answers, the context text of each target answer, and the text feature vector of each text to be processed into the reordering module of the question-answering model to obtain a target probability corresponding to each text to be processed; The output module is configured to sort the at least two texts to be processed based on the target probability of each text to be processed, and output the sorted texts to be processed and the at least two target answers.
22. A question-answering device, characterized in that: include: A fourth acquisition module is configured to acquire a question to be processed and at least two texts to be processed; The sixth determination module is configured to input the question to be processed and the at least two texts to be processed into the reading comprehension module of the question-answering model to obtain at least two target answers, wherein the question-answering model is trained by the training method of the question-answering model described in any one of claims 10-16.
23. A computing device comprising a memory, a processor, and computer instructions stored in the memory and executable on the processor, wherein: When the processor executes the instructions, the steps of the method described in any one of claims 1 to 9, claims 10 to 16, claim 17, or claim 18 are implemented.
24. A computer-readable storage medium storing computer instructions, characterized in that: When the instruction is executed by the processor, the steps of the method described in any one of claims 1 to 9, claims 10 to 16, claim 17, or claim 18 are implemented.
Citation Information
Patent Citations
Text analysis model training method and device and text analysis method and device
CN110781663A
Document abstract generation method and device and electronic equipment
CN112287096A