A method, device and storage medium for training a question and answer model

By adopting a joint learning method of the retrieval module and the reading module in the question-answering model and updating the documents provided by the retrieval module, the problem of the quality of the question-answering model affecting the accuracy of open-domain question answering is solved, and the effect of the question-answering model is significantly improved.

CN113761152BActive Publication Date: 2025-10-17TENCENT TECHNOLOGY (SHENZHEN) CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202110523567.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-05-13
Publication Date
2025-10-17
Estimated Expiration
2041-05-13

AI Technical Summary

Technical Problem

In existing technologies, the quality of question-answering models directly affects the accuracy of open-domain question-answering. Therefore, how to train high-quality question-answering models is the key.

Method used

The question-answering model is trained by constructing a joint learning method of the initial retrieval module and the initial reading module. The documents provided by the retrieval module are updated after each iterative training, and the training effects of the two modules are mutually promoted until the iterative training conditions are met.

Benefits of technology

It significantly improves the performance of the question-answering model and improves the accuracy of open-domain question-answering.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN113761152B_ABST
    Figure CN113761152B_ABST
Patent Text Reader

Abstract

The application discloses a training method and device of a question and answer model, equipment and a storage medium. When training the question and answer model, an initial question and answer model including an initial retrieval module and an initial reading module is constructed. Training corpus including a first target document is obtained, and the initial retrieval module and the initial reading module are jointly trained according to the first target document. In the joint training process, the initial retrieval module obtained after the i-th iteration training is used to update the first target document used in the i-th iteration training, so that the initial retrieval module and the initial reading module obtained after the i-th iteration training are respectively subjected to (i+1)-th iteration training according to the updated first target document, until the iteration training condition is met. According to the model parameters when the iteration training condition is met and the network structure of the initial question and answer model, a target question and answer model is determined. In this way, the two modules promote each other, significantly improve the effect of the question and answer model, and improve the accuracy of open domain question and answer.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the field of data processing, and in particular to a question and answer model training method and device, equipment and a storage medium. BACKGROUND

[0002] Open-domain question answering (Open QA) is an important research topic in the field of natural language processing. Open-domain question answering can refer to quickly and accurately finding answers from a document library based on a question posed by a user in natural language. Open-domain question answering plays an important role in intelligent search, intelligent assistants, intelligent customer service and other scenarios.

[0003] In related technologies, for a question posed by a user, an answer corresponding to the question can be extracted from a document library by a pre-trained question and answer model, that is, the quality of the question and answer model directly affects the accuracy of open-domain question answering. Therefore, how to train a high-quality question and answer model is very important for Open QA. SUMMARY

[0004] To solve the above technical problems, the present application provides a question and answer model training method, device, equipment and storage medium, which can significantly improve the effect of the question and answer model and thus improve the accuracy of open-domain question answering.

[0005] The embodiments of the present application disclose the following technical solutions:

[0006] In a first aspect, the embodiments of the present application provide a question and answer model training method, which comprises:

[0007] An initial question and answer model is constructed, the initial question and answer model comprising an initial retrieval module and an initial reading module;

[0008] Training corpus is obtained, the training corpus comprising a first target document, the first target document comprising an answer corresponding to a question to be answered;

[0009] The initial retrieval module and the initial reading module are jointly trained according to the first target document;

[0010] In the process of joint training, the initial retrieval module obtained after the i-th iteration training is used to update the first target document used in the i-th iteration training, i being an integer greater than or equal to 1;

[0011] The initial retrieval module and the initial reading module obtained after the i-th iteration training are respectively subjected to an (i+1)-th iteration training according to the updated first target document, until an iteration training condition is met;

[0012] determine the target question and answer model according to the model parameters when the iterative training condition is met and the network structure of the initial question and answer model.

[0013] In a second aspect, an embodiment of the present application provides a device for training a question and answer model, the device comprising a construction unit, an acquisition unit, a training unit and a determination unit:

[0014] The construction unit is configured to construct an initial question and answer model, the initial question and answer model comprising an initial retrieval module and an initial reading module.

[0015] The acquisition unit is configured to acquire training corpus, the training corpus comprising a first target document, the first target document comprising an answer corresponding to a question to be answered.

[0016] The training unit is configured to jointly train the initial retrieval module and the initial reading module according to the first target document; in the process of the joint training, the initial retrieval module obtained after the i-th iteration is used to update the first target document used in the i-th iteration, i being an integer greater than or equal to 1; the initial retrieval module and the initial reading module obtained after the i-th iteration are respectively subjected to the (i+1)-th iteration according to the updated first target document, until an iterative training condition is met.

[0017] The determination unit is configured to determine a target question and answer model according to the model parameters when the iterative training condition is met and the network structure of the initial question and answer model.

[0018] In a third aspect, an embodiment of the present application provides an electronic device for training a question and answer model, the electronic device comprising a processor and a memory:

[0019] The memory is configured to store program code and transmit the program code to the processor.

[0020] The processor is configured to execute the method of the first aspect according to instructions in the program code.

[0021] In a fourth aspect, an embodiment of the present application provides a computer readable storage medium for storing program code, the program code being configured to execute the method of the first aspect.

[0022] It can be seen from the technical solution that, in order to realize open domain question answering, a question answering model needs to be trained. When training the question answering model, an initial question answering model including an initial retrieval module and an initial reading module is constructed. Training corpus including a first target document is obtained, the first target document includes an answer corresponding to a question to be answered, and then the initial retrieval module and the initial reading module are jointly trained according to the first target document. In the process of joint training, the initial retrieval module obtained after the ith iteration training is used to update the first target document used in the ith iteration training, i is an integer greater than or equal to 1, so that the initial retrieval module and the initial reading module obtained after the ith iteration training are respectively subjected to the (i+1)th iteration training according to the updated first target document, until the iteration training condition is met. According to the model parameters when the iteration training condition is met and the network structure of the initial question answering model, the target question answering model is determined. Since the initial retrieval module and the initial reading module are jointly learned and trained, that is, the initial retrieval module obtained after the ith iteration training provides the latest retrieval result (that is, the updated first target document) to the initial reading module obtained after the ith iteration training, the training of the initial reading module also affects the initial retrieval module, so that the two modules promote each other, which can significantly improve the effect of the question answering model, and further improve the accuracy of open domain question answering. BRIEF DESCRIPTION OF DRAWINGS

[0023] In order to more clearly illustrate the technical solutions in the embodiments of the present application or the prior art, the drawings needed to be used in the embodiments or the prior art description will be briefly introduced. Obviously, the drawings in the following description are only some embodiments of the present application, and other drawings can also be obtained according to these drawings without creative labor for those skilled in the art.

[0024] Figure 1 A system architecture schematic diagram of a question answering model training method provided by an embodiment of the present application;

[0025] Figure 2 A flowchart of a question answering model training method provided by an embodiment of the present application;

[0026] Figure 3 A flowchart structure diagram of a question answering model training method provided by an embodiment of the present application;

[0027] Figure 4 A structure schematic diagram of a double-tower model provided by an embodiment of the present application;

[0028] Figure 5 A schematic diagram of an initial retrieval module based on a BERT model determining cosine similarity provided by an embodiment of the present application;

[0029] Figure 6A schematic diagram of an initial reading model based on a BERT model predicting the beginning of an answer and the end of an answer is provided for an embodiment of the present application.

[0030] Figure 7 A method flowchart of an intelligent question answering service implementation is provided for an embodiment of the present application.

[0031] Figure 8 A structural diagram of a question answering model training device is provided for an embodiment of the present application.

[0032] Figure 9 A structural diagram of a terminal device is provided for an embodiment of the present application.

[0033] Figure 10 A structural diagram of a server is provided for an embodiment of the present application. DETAILED DESCRIPTION

[0034] Embodiments of the present application are described below with reference to the accompanying drawings.

[0035] Open domain question answering can refer to quickly and accurately finding an answer from a document library based on a question posed by a user in natural language. For example, for a question posed by a user: “What is the first unequal treaty in Chinese history?”, the corresponding answer to the question needs to be found in the document library. The candidate documents included in the document library can be split into one by one paragraphs, for example: “The Treaty of Nanjing is the first unequal treaty signed by China with foreign countries in modern history. In the 22nd year of Daoguang (1842), the Treaty of Jiangning was signed, also known as the Treaty of Nanjing between China and England.” By analyzing the question and the candidate documents, the corresponding answer to the question from the document library can be obtained as “Treaty of Nanjing”.

[0036] In related technologies, for a question posed by a user, the corresponding answer to the question can be extracted from a document library by a pre-trained question answering model, that is, the quality of the question answering model directly affects the accuracy of open domain question answering. Therefore, how to train a high-quality question answering model is very important for Open QA.

[0037] To address the above technical issues, the present invention trains a question-answering model comprising a retriever and a reader based on joint learning of the retriever and reader. During the joint learning process, each retriever and reader pair completes an iterative training. The retriever obtained from this iterative training can then be used to update the first target document, thereby providing a better document for the next iterative training of the reader. The iterative training of the reader can also influence the retriever, achieving a mutually reinforcing effect between the two modules. This significantly improves the effectiveness of the question-answering model and enhances the accuracy of open-domain question answering.

[0038] The methods provided in the embodiments of this application may relate to the field of artificial intelligence (AI). AI is a comprehensive technology within computer science that seeks to understand the essence of intelligence and produce new intelligent machines that can respond in a manner similar to human intelligence. AI is the study of the design principles and implementation methods of various intelligent machines, enabling them to possess the capabilities of perception, reasoning, and decision-making.

[0039] Artificial intelligence (AI) technology is a comprehensive discipline encompassing a wide range of fields, encompassing both hardware and software technologies. Foundational AI technologies generally include sensors, specialized AI chips, cloud computing, distributed storage, big data processing, operating / interaction systems, and mechatronics. AI software technologies primarily encompass computer vision, speech processing, natural language processing, machine learning / deep learning, and autonomous driving.

[0040] It should be noted that the embodiments of the present application mainly relate to natural language processing technology (Natural Language processing, NLP), which is an important direction in the fields of computer science and artificial intelligence. It studies various theories and methods that can realize effective communication between people and computers using natural language. Natural language processing is a science that integrates linguistics, computer science, and mathematics. Therefore, research in this field will involve natural language, that is, the language people use in daily life, so it is closely related to the study of linguistics. Natural language processing technology generally includes text processing, semantic understanding, machine translation, robot question and answer, knowledge graph and other technologies. This application, for example, relates to text preprocessing, semantic understanding, robot question and answer, and search.

[0041] This application may also involve machine learning / deep learning, and train a question-answering model through machine learning / deep learning, thereby using the trained question-answering model to implement open-domain question-answering.

[0042] The embodiments of the present application can also relate to the field of blockchains. For example, the training corpus required for training the question and answer model can be stored on a blockchain.

[0043] It can be understood that OpenQA, as an NLP basic technology, has very wide applications in many products and applications. In search, users often ask questions such as the above example "What is the first unequal treaty in Chinese history?", which can not be answered by a knowledge graph, but is very suitable for finding answers from a large number of candidate documents. In question and answer or dialogue scenarios, such as smart speakers, knowledge question and answer services (such as WeChat) or intelligent customer service, users can also ask questions. These questions of the user can be answered by retrieving and understanding a large number of candidate documents.

[0044] It should be noted that the method provided by the embodiments of the present application can be applied to a data processing device, which can be a server or a terminal device. The server can be a standalone physical server, a server cluster or a distributed system composed of multiple physical servers, or a cloud server providing cloud computing services. The terminal device can be a smart phone, a tablet computer, a notebook computer, a desktop computer, a smart speaker, a smart watch, etc., but is not limited thereto. The terminal device and the server can be connected directly or indirectly through wired or wireless communication, which is not limited in the present application.

[0045] Next, taking the data processing device as a server as an example, the system architecture of the question and answer model training method will be introduced. Referring to Figure 1 , Figure 1 The system architecture of the question and answer model training method provided by the embodiments of the present application is shown in the figure. The system architecture includes a server 101, and the server 101 is constructed with an initial question and answer model including an initial retrieval module and an initial reading module.

[0046] The server 101 can obtain a training corpus, which includes a first target document, and the first target document includes an answer corresponding to a question to be answered. The training corpus is used to train the initial retrieval module and the initial reading module, and the first target document is a document related to the question to be answered, which can include an answer corresponding to the question to be answered.

[0047] It should be noted that the question to be answered can be a question raised by a user, for example, "What is the first unequal treaty in Chinese history?" The input mode of the question to be answered can be text input, voice input, etc. For example, in a search, a user can input the text "What is the first unequal treaty in Chinese history?" in a search box; in a question-answering or dialogue scenario, a user can input the voice "What is the first unequal treaty in Chinese history?" through a smart speaker.

[0048] Each first target document can be a paragraph, for example, "The Treaty of Nanjing is the first unequal treaty signed with foreign countries in modern Chinese history. In the 22nd year of Daoguang (1842), the Treaty of Jiangning, also known as the Treaty of Nanjing between China and England, was signed."

[0049] After obtaining the first target document, the server 101 can jointly train the initial retrieval module and the initial reading module according to the first target document. In the process of joint training, the server 101 updates the first target document used in the i-th iteration training by using the initial retrieval module obtained after the i-th iteration training, i being an integer greater than or equal to 1. Then, the server 101 performs the (i+1)-th iteration training on the initial retrieval module and the initial reading module obtained after the i-th iteration training according to the updated first target document, until the iteration training condition is met.

[0050] Finally, the server 101 determines the target question-answering model according to the model parameters when the iteration training condition is met and the network structure of the initial question-answering model.

[0051] The server 101 can provide the target question-answering model trained to various open-domain question-answering scenarios. When a user inputs a question through the terminal device 102, for example, "What is the first unequal treaty in Chinese history?", the terminal device 102 can send the question to the server 101, so that the server 101 determines the answer corresponding to the question by using the target question-answering model, and returns the answer to the terminal device 102.

[0052] It should be noted that the training method of the question-answering model provided by the embodiments of the present application can be independently executed by the server, independently executed by the terminal device, or cooperatively executed by the server and the terminal device. Figure 1 This is only an example, and the embodiments of the present application do not limit this.

[0053] Next, the training method of the question-answering model provided by the embodiments of the present application will be described in detail mainly taking the server as an execution subject in combination with the drawings.

[0054] Referring to Figure 2 , Figure 2A flowchart of a training method of a question and answer model is shown, the method comprising:

[0055] S201, the server constructs an initial question and answer model, the initial question and answer model comprising an initial retrieval module and an initial reading module.

[0056] Open domain question answering refers to quickly and accurately finding answers from a large number of candidate documents based on a question raised by a user. These candidate documents can be located in a document library, which may be, for example, a library of encyclopedic texts, a specific corpus, a news library, a professional library, or the entire Internet web library. The size of the entire document library is very large, possibly in the tens of millions or hundreds of millions. In the open domain question answering task, the answer to the question needs to be found from a huge document library. The general process in this scenario is to first screen out some candidate documents related to the question from the huge document library through a retrieval algorithm, and then extract the answer from these documents. Therefore, in this embodiment, the entire question and answer model mainly consists of two modules, the first being a retriever, i.e., a retrieval module, for screening out candidate documents highly relevant to the question from a huge document library to reduce the scale of extracting the answer corresponding to the question; the second being a reader, i.e., a reading module, for extracting the answer from the candidate documents retrieved, wherein the reading module can be a machine reading comprehension (MRC) model.

[0057] Based on this, when training the question and answer model, the initial question and answer model first constructed also comprises two modules, namely the initial retrieval module and the initial reading module.

[0058] S202, the server acquires training corpus, the training corpus comprising a first target document, the first target document comprising an answer corresponding to a question to be answered.

[0059] The first target document can be a candidate document more relevant to the question to be answered, thereby reducing the scale of extracting the answer corresponding to the question. Generally, a predetermined number of candidate documents more relevant to the question to be answered are retrieved from the document library, which may be, for example, K.

[0060] It should be noted that the relevance of the candidate document to the question to be answered can be embodied by the similarity between the candidate document and the question to be answered. Therefore, the first target document can be retrieved according to the similarity. The way to determine the first target document according to the similarity can include a variety of ways, for example, if the similarity is arranged in descending order, the first target document can be the top K candidate documents, or if the similarity is arranged in ascending order, the first target document can be the last K candidate documents. At this time, the first target document can be referred to as the top K documents.

[0061] In the embodiment of the present application, the server can obtain the training corpus in multiple ways. The first way can be to retrieve the first target document from the candidate documents through the initial retrieval module constructed in S201.

[0062] It can be understood that the way of retrieving the first target document from the candidate documents through the initial retrieval module can include many kinds, and the embodiment of the present application takes one of them as an example for detailed introduction. The initial retrieval module can take the question to be answered and the candidate documents in the document library as input, and take the first target document as output. Specifically, the initial retrieval module encodes the question to be answered and the candidate documents respectively to obtain a first vector sequence corresponding to the question to be answered and a second vector sequence corresponding to the candidate documents, the first vector sequence includes a word vector corresponding to each word in the question to be answered, and the second vector sequence includes a word vector corresponding to each word in the candidate documents. Then, the similarity between the question to be answered and each candidate document is calculated according to the first vector sequence and the second vector sequence, so as to determine the first target document according to the similarity. The type of similarity can include multiple types, such as Jaccard similarity, cosine similarity, etc., and the embodiment of the present application mainly takes cosine similarity as an example for introduction. At this time, the similarity calculation formula can be as follows:

[0063]

[0064] Wherein, S represents the similarity, V1 represents the first vector sequence, and V2 represents the second vector sequence.

[0065] Referring to FIG. 3, Figure 3 As shown in FIG. 3, the document library includes candidate documents, and the initial retrieval module can calculate the similarity between the question to be answered and the candidate documents, and then select the topK candidate documents (i.e., the candidate documents whose similarity ranks in the top K) as the first target documents (see FIG. 3, 301), and the topK candidate documents can be candidate document 1, candidate document 2, candidate document 3, …, candidate document k respectively, and the similarity corresponding to each candidate document is 0.93, 0.89, 0.80, …, 0.51 respectively as shown in FIG. 3, Figure 3 Figure 3

[0066] It should be noted that the initial retrieval module in the embodiment can be various neural networks that can select part of the candidate documents from the massive candidate documents as the first target documents. Since the input of the initial retrieval module is two inputs, i.e., the question to be answered and the candidate documents, and similar processing is performed on each input, therefore, based on the input characteristics, the initial retrieval module used in the embodiment of the present application can be a double tower model. The structure of the double tower model can be referred to FIG. 4. Figure 4 ​​As shown, the initial retrieval module includes a first branch and a second branch, the first branch includes a first input layer 410 and a first representation layer 411, the second branch includes a second input layer 420 and a second representation layer 421, and the first representation layer 411 and the second representation layer 421 are respectively connected with a matching layer 430. In this way, the first vector sequence and the second vector sequence can be determined by obtaining the question to be answered through the first input layer 410, and representing the question to be answered as the first vector sequence through the first representation layer 411; and obtaining each candidate document through the second input layer 420, and representing each candidate document as the second vector sequence through the second representation layer 421.

[0067] In this case, the way of calculating the similarity between the question to be answered and each candidate document according to the first vector sequence and the second vector sequence respectively can be that the first vector sequence and the second vector sequence are input into the matching layer 430, and the matching layer 430 is used to calculate the similarity between the question to be answered and each candidate document according to the first vector sequence and the second vector sequence.

[0068] It should be understood that before the first vector sequence and the second vector sequence are obtained, the question to be answered and the candidate document can be split into tokens, and then the initial retrieval module generates the first vector sequence and the second vector sequence according to the token sequence corresponding to the question to be answered and the candidate document respectively.

[0069] In this case, the way of calculating the similarity between the question to be answered and each candidate document according to the first vector sequence and the second vector sequence respectively can be that the first vector sequence and the second vector sequence are input into the matching layer 430, and the matching layer 430 is used to calculate the similarity between the question to be answered and each candidate document according to the first vector sequence and the second vector sequence.

[0070] For example, if the question to be answered is “What is the first unequal treaty in Chinese history?”, and a candidate document is “The Treaty of Nanjing is the first unequal treaty signed by China with foreign countries in modern history. In the 22nd year of Daoguang (1842), the Treaty of Jiangning was signed, also known as the Treaty of Nanjing between China and England.”, the question to be answered and each candidate document will be split into tokens. Then, the two special characters “[CLS]” and “[SEP]” are spliced respectively to obtain the token sequence corresponding to the question to be answered and the token sequence corresponding to the candidate document (see Figure 5 501 and Figure 5The two token sequences are then represented by a BERT model to obtain corresponding vector representations, i.e., a first vector sequence and a second vector sequence. It is worth noting that the BERT model used for vector representation of the question to be answered and the candidate document is the same. Finally, through a matching layer, the cosine similarity between the question to be answered and the candidate document is calculated according to the first vector sequence and the second vector sequence (see Figure 5 as shown in step 503.

[0071] However, in some cases, since the initial retrieval module just constructed has not been well trained, in order to ensure the accuracy of the first target document retrieved, the first target document can be retrieved from the candidate documents by a pre-trained retrieval module, which is different from the training method of the initial retrieval module, and can be obtained by a traditional training method (such as a method of training the retrieval module and the reading module independently). For example, the pre-trained retrieval module can be a BM25 (bag-of-words model) obtained by a traditional training method.

[0072] S203, the server jointly trains the initial retrieval module and the initial reading module according to the first target document.

[0073] In some implementations, the retrieval module and the reading module are both independently trained, and in actual use, the output of the retrieval module is the input of the reading module, so the result of the retrieval module will affect the effect of the reading module. If the retrieval module changes, it will affect the recognition effect of the reading module. If the effect of the retrieval module improves, but since the two are independently trained, the reading module cannot rely on a better retrieval module, so it cannot benefit. As can be seen, the reading module can learn better from the more relevant candidate documents retrieved by the retrieval module, and the two modules can promote each other. Based on this, the embodiment of the present application proposes a question and answer model based on retrieval module-reading module joint learning, i.e., the initial retrieval module and the initial reading module are jointly optimized and learned, and promote each other, so as to train the final target question and answer model, which significantly improves the effect of the target question and answer model.

[0074] It can be understood that the joint training can mean that the initial retrieval module and the initial reading module learn towards a common goal, and therefore, one implementation manner of jointly training the initial retrieval module and the initial reading module according to the first target document can be to construct a first loss function corresponding to the initial retrieval module, and to construct a second loss function corresponding to the initial reading module according to the first target document. The target loss function corresponding to the initial question and answer model is determined according to the first loss function and the second loss function, for example, the sum of the first loss function and the second loss function can be taken as the target loss function. Then, the model parameters of the initial retrieval module and the initial reading module are adjusted according to the target loss function to complete the joint training.

[0075] Since the role of the retrieval module obtained after training can be to retrieve the first target document from a large number of candidate documents, or to update the first target document in the training process, and the first target document can be determined based on the similarity between the question to be answered and the candidate document, the retrieval module needs to learn to predict the similarity as accurately as possible, and the initial retrieval module has a similar function, and the training target of the initial retrieval module is to predict the similarity as accurately as possible. Therefore, one manner of constructing the first loss function corresponding to the initial retrieval module can be to determine the similarity between the third target document and the question to be answered, and the similarity between the fourth target document and the question to be answered, by the initial retrieval module. Then, the first loss function is calculated according to the similarity between the third target document and the question to be answered, and the similarity between the fourth target document and the question to be answered.

[0076] The third target document is any positive sample in the candidate documents, and the fourth target document is any negative sample in the candidate documents. The positive sample is a document related to the question to be answered in the candidate documents, and the negative sample is a document unrelated to the question to be answered in the candidate documents. The goal of the first loss function is to hope that the greater the similarity obtained by the initial retrieval module for the third target document, the smaller the similarity obtained by the initial retrieval module for the fourth target document. The first loss function can be expressed as:

[0077]

[0078] wherein Loss1 represents the first loss function, M represents a model parameter, represents the similarity between the fourth target document and the question to be answered, represents the similarity between the third target document and the question to be answered.

[0079] Since the role of the reading module obtained after training is to extract the answer from the first target document (see Figure 3The initial reading module can predict the beginning of the answer and the end of the answer in the first target document (as shown in FIG. 302), that is, the answer can be determined from the beginning of the answer and the end of the answer. Therefore, the reading module needs to learn as accurate a prediction of the beginning of the answer and the end of the answer as possible, and the initial reading module also has a similar function, and the training target of the initial retrieval module is to predict the beginning of the answer and the end of the answer as accurately as possible. Therefore, the way to construct the second loss function corresponding to the initial reading module according to the first target document can be to splice the question to be answered and each first target document into the initial reading module respectively, and determine the first probability of each word vector in the first target document as the beginning of the answer and the second probability of the end of the answer through the initial reading module. Wherein, the probability formula for predicting each word vector as the beginning of the answer or the end of the answer can be expressed as:

[0080]

[0081]

[0082] Wherein, v represents a model parameter, represents the i-th word vector, P i represents the probability that the i-th word vector is the beginning of the answer or the end of the answer, if P i represents , which represents the first probability that the i-th word vector is the beginning of the answer, if P i represents , which represents the second probability that the i-th word vector is the end of the answer.

[0083] Then, the second loss function is calculated according to the first probability and the second probability. The calculation formula of the second loss function can be expressed as:

[0084]

[0085] Wherein, Loss2 represents the second loss function, represents the first probability, represents the second probability.

[0086] At this time, the target loss function Loss = Loss1 + Loss2, see Figure 3 .

[0087] In one possible implementation, the initial reading module is also a BERT model. The input of the initial reading module is to splice the question to be answered and the first target document together, splice two special characters “[CLS]” and “[SEP]” respectively, and separate the question to be answered and the first target document with “[SEP]”. See Figure 6As shown in the figure, if the question to be answered is "What is the first unequal treaty in Chinese history?", a first target document is "The Treaty of Nanjing is the first unequal treaty signed between China and a foreign country in modern history. In the 22nd year of the reign of Emperor Daoguang (1842), the Treaty of Jiangning, also known as the Sino-British Treaty of Nanjing, was signed." After the two are concatenated together, "[CLS]" and "[SEP]" are concatenated at both ends respectively, and the question to be answered and the first target document are separated by "[SEP]". The result is input into the BERT model as the initial reading module, thereby predicting the beginning and end of the answer.

[0088] The input text is processed in the same way as the initial search module, requiring tokenization. This token sequence is then passed through a BERT model to obtain a representation vector for each token. Finally, the beginning and end of the answer are predicted based on the resulting token representation vectors.

[0089] S204. During the joint training, the server updates the first target document used in the i-th iterative training using the initial retrieval module obtained after the i-th iterative training, where i is an integer greater than or equal to 1.

[0090] S205. The server performs the (i+1)th iterative training on the initial retrieval module and the initial reading module obtained after the i-th iterative training according to the updated first target document, until an iterative training condition is met.

[0091] It should be noted that in the embodiments of the present application, joint training not only refers to training the initial retrieval module and the initial reading module toward a common goal, but also refers to continuously updating the first target document with the initial retrieval module obtained through each training, so that the latest search results are provided to the initial reading module obtained through that training for training. The training of the initial reading module will also influence the training of the initial retrieval module, thereby promoting each other.

[0092] Based on the above introduction to the initial retrieval module, the method for updating the first target document used in the i-th iterative training using the initial retrieval module obtained after the i-th iterative training can be to encode the question to be answered and the candidate documents respectively through the initial retrieval module obtained after the i-th iterative training, and obtain a first vector sequence corresponding to the question to be answered and a second vector sequence corresponding to the candidate documents. The first vector sequence includes the word vector corresponding to each word in the question to be answered, and the second vector sequence includes the word vector corresponding to each word in the candidate document. Then, the similarity between the question to be answered and each candidate document is calculated based on the first vector sequence and the second vector sequence, and then the second target document is determined based on the similarity, and the first target document is updated using the second target document. The second target document is the updated first target document.

[0093] Thus, in the i+1th iteration training, the initial retrieval module obtained in the ith iteration training can provide the updated first target document to the initial reading module obtained in the ith iteration training, so as to perform the i+1th iteration training, and so on until the iteration training condition is met.

[0094] For example, after the initial retrieval module and the initial reading module are trained for the first time by using the first target document, the initial retrieval module obtained at this time can be used to retrieve a candidate document (for example, a second target document) more relevant to the question to be answered from the candidate documents, so as to update the first target document. Then, the initial retrieval module and the initial reading module obtained in the first iteration training are trained for the second time by using the updated first target document. Then, the initial retrieval module obtained in the second iteration training is used to retrieve a candidate document more relevant to the question to be answered from the candidate documents, so as to update the first target document used in the first iteration training. Then, the initial retrieval module and the initial reading module obtained in the second iteration training are trained for the third time by using the first target document updated again. In this way, the training is performed until the iteration training condition is met.

[0095] In S206, the server determines the target question and answer model according to the model parameters when the iteration training condition is met and the network structure of the initial question and answer model.

[0096] After the iteration training condition is met, the training of the question and answer model is completed, and then the server can determine the target question and answer model according to the model parameters at this time and the network structure of the initial question and answer model. Thus, the training of the question and answer model is completed.

[0097] The target question and answer model obtained by training can be provided for various open domain question and answer scenarios. When a user inputs a question through a terminal device, for example, “What is the first unequal treaty in Chinese history?”, the terminal device can send the question to the server, so that the server determines the answer corresponding to the question by using the target question and answer model, and returns the answer to the terminal device. The terminal device can provide the answer to the user, for example, the answer can be displayed to the user or played to the user in voice.

[0098] It can be seen from the above technical solution that, in order to realize open domain question answering, a question answering model needs to be trained. When training the question answering model, an initial question answering model including an initial retrieval module and an initial reading module is constructed. Training corpus including a first target document is obtained, the first target document includes an answer corresponding to a question to be answered, and then the initial retrieval module and the initial reading module are jointly trained according to the first target document. In the process of joint training, the initial retrieval module obtained after the ith iteration training is used to update the first target document used in the ith iteration training, i is an integer greater than or equal to 1, so that the initial retrieval module and the initial reading module obtained after the ith iteration training are respectively subjected to the (i+1)th iteration training according to the updated first target document, until the iteration training condition is met. According to the model parameters when the iteration training condition is met and the network structure of the initial question answering model, a target question answering model is determined. Since the initial retrieval module and the initial reading module are jointly learned and trained, that is, the initial retrieval module obtained after the ith iteration training provides the latest retrieval result (that is, the updated first target document) to the initial reading module obtained after the ith iteration training, the training of the initial reading module also affects the initial retrieval module, so that the two modules promote each other, which can significantly improve the effect of the question answering model, and further improve the accuracy of open domain question answering.

[0099] Next, the training method of the question answering model provided by the embodiments of the present application will be introduced in combination with actual application scenarios. In the open domain question answering scenario, for example, in the intelligent question answering service, in order to accurately determine the answer corresponding to the question when the user proposes the question, so as to answer the question for the user, a question answering model can be pre-trained. The question answering model includes two parts of a retrieval module and a reading module, therefore, in order to improve the effect of the question answering model, the training of the question answering model can be completed based on the joint learning mode of the retrieval module and the reading module. Referring to Figure 7 The question answering model can be trained based on the joint training method shown in Figure 2 to be used for intelligent question answering service, the method comprises:

[0100] S701, the server creates an initial question answering model.

[0101] The initial question answering model includes an initial retrieval module and an initial reading module.

[0102] S702, the server obtains topK candidate documents as first target documents through the initial retrieval module.

[0103] The first target document includes an answer corresponding to a question to be answered, and the first target document can be used as training corpus for training the initial retrieval module and the initial reading module.

[0104] S703: The server provides the first target document to the initial reading module, and iteratively trains the initial retrieval module and the initial reading module according to the first target document.

[0105] S704: The server determines whether the iterative training conditions are met. If so, execute S705; if not, execute S702.

[0106] That is to say, after completing one iterative training, if the iterative training conditions are not met, the initial retrieval module obtained by the iterative training is used to re-retrieve the topK candidate documents to update the first target document, and the updated first target document is provided to the initial reading module obtained by this training, and the next iterative training is continued until the iterative training conditions are met.

[0107] S705: The server determines the target question-answering model.

[0108] The server can determine the target question-answering model based on the model parameters finally adjusted after iterative training and the network structure of the initial question-answering model.

[0109] S706: When the user inputs a question through the terminal device, the server obtains the question.

[0110] S707: The server determines the answer to the question through the target question-answering model.

[0111] S708. The server returns the answer to the terminal device.

[0112] S709: The terminal device plays the answer to the user in voice.

[0113] It can be seen from the technical solution that, in order to realize open domain question answering, a question answering model needs to be trained. In training the question answering model, an initial question answering model including an initial retrieval module and an initial reading module is constructed. Training corpus including a first target document is obtained, the first target document including an answer corresponding to a question to be answered, and then the initial retrieval module and the initial reading module are jointly trained according to the first target document. In the process of joint training, the initial retrieval module obtained after the i-th iteration training is used to update the first target document used in the i-th iteration training, i being an integer greater than or equal to 1, so as to perform the i+1-th iteration training on the initial retrieval module and the initial reading module obtained after the i-th iteration training respectively according to the updated first target document, until the iteration training condition is met. The target question answering model is determined according to the model parameters at the time when the iteration training condition is met and the network structure of the initial question answering model. Since the initial retrieval module and the initial reading module are jointly learned and trained, that is, the initial retrieval module obtained after the i-th iteration training provides the latest retrieval result (that is, the updated first target document) to the initial reading module obtained after the i-th iteration training in real time, the training of the initial reading module also affects the initial retrieval module, so that the two modules promote each other, which can significantly improve the effect of the question answering model and further improve the accuracy of open domain question answering.

[0114] Based on Figure 2 The training method of the question answering model provided in the corresponding embodiment also provides a training device of a question answering model. Referring to Figure 8 , the device 800 includes a construction unit 801, an acquisition unit 802, a training unit 803, and a determination unit 804:

[0115] The construction unit 801 is configured to construct an initial question answering model, the initial question answering model including an initial retrieval module and an initial reading module.

[0116] The acquisition unit 802 is configured to acquire training corpus, the training corpus including a first target document, the first target document including an answer corresponding to a question to be answered.

[0117] The training unit 803 is configured to jointly train the initial retrieval module and the initial reading module according to the first target document. In the process of joint training, the initial retrieval module obtained after the i-th iteration training is used to update the first target document used in the i-th iteration training, i being an integer greater than or equal to 1. The initial retrieval module and the initial reading module obtained after the i-th iteration training are respectively subjected to the i+1-th iteration training according to the updated first target document, until the iteration training condition is met.

[0118] The determination unit 804 is configured to determine a target question and answer model according to the model parameters when the iterative training condition is met and the network structure of the initial question and answer model.

[0119] In a possible implementation, the training unit 803 is configured to:

[0120] The initial retrieval module obtained through the i-th iteration is used to encode the question to be answered and the candidate documents respectively to obtain a first vector sequence corresponding to the question to be answered and a second vector sequence corresponding to the candidate documents, the first vector sequence including a word vector corresponding to each word in the question to be answered, and the second vector sequence including a word vector corresponding to each word in the candidate documents;

[0121] The similarity between the question to be answered and each of the candidate documents is calculated according to the first vector sequence and the second vector sequence respectively;

[0122] A second target document is determined according to the similarity, and the first target document is updated by using the second target document, and the second target document is the updated first target document.

[0123] In a possible implementation, the training unit 803 is configured to:

[0124] A first loss function corresponding to the initial retrieval module is constructed, and a second loss function corresponding to the initial reading module is constructed according to the first target document;

[0125] A target loss function corresponding to the initial question and answer model is determined according to the first loss function and the second loss function;

[0126] The model parameters of the initial retrieval module and the initial reading module are adjusted according to the target loss function.

[0127] In a possible implementation, the training unit 803 is configured to:

[0128] The similarity between a third target document and the question to be answered and the similarity between a fourth target document and the question to be answered are determined by the initial retrieval module, the third target document being any positive sample in the candidate documents, and the fourth target document being any negative sample in the candidate documents, the positive sample being a document related to the question to be answered in the candidate documents, and the negative sample being a document unrelated to the question to be answered in the candidate documents;

[0129] The first loss function is calculated according to the similarity between the third target document and the question to be answered and the similarity between the fourth target document and the question to be answered.

[0130] In a possible implementation, the training unit 803 is configured to:

[0131] concatenate the question to be answered and each of the first target documents respectively as input to the initial reading module;

[0132] determine, by the initial reading module, each word vector in the first target document as a first probability of being the beginning of an answer and a second probability of being the end of an answer;

[0133] calculate the second loss function according to the first probability and the second probability.

[0134] In a possible implementation, the obtaining unit 802 is configured to:

[0135] retrieve the first target document from the candidate documents by the initial retrieval module;

[0136] Alternatively, retrieve the first target document from the candidate documents by a pre-trained retrieval module, wherein the pre-trained retrieval module is different from the initial retrieval module in training manner.

[0137] In a possible implementation, the obtaining unit 802 is configured to:

[0138] encode the question to be answered and the candidate documents respectively by the initial retrieval module to obtain a first vector sequence corresponding to the question to be answered and a second vector sequence corresponding to the candidate documents, wherein the first vector sequence includes a word vector corresponding to each word in the question to be answered, and the second vector sequence includes a word vector corresponding to each word in the candidate documents;

[0139] calculate a similarity between the question to be answered and each of the candidate documents according to the first vector sequence and the second vector sequence respectively;

[0140] determine the first target document according to the similarity.

[0141] In a possible implementation, the initial retrieval module is a double-tower model, the double-tower model includes a first branch and a second branch, the first branch includes a first input layer and a first representation layer, the second branch includes a second input layer and a second representation layer, the first representation layer and the second representation layer are connected with a matching layer respectively, and the obtaining unit 802 is configured to:

[0142] obtain the question to be answered by the first input layer, and represent the question to be answered as the first vector sequence by the first representation layer;

[0143] obtaining each of the candidate documents through the second input layer, and representing each of the candidate documents as the second vector sequence through the second representation layer;

[0144] calculating similarity between the question to be answered and each of the candidate documents according to the first vector sequence and the second vector sequence, respectively, including:

[0145] calculating similarity between the question to be answered and each of the candidate documents according to the first vector sequence and the second vector sequence through the matching layer.

[0146] In a possible implementation, if the similarity is arranged in descending order, the first target document and the updated first target document are candidate documents ranked in the first K;

[0147] Or, if the similarity is arranged in ascending order, the first target document and the updated first target document are candidate documents ranked in the last K.

[0148] Embodiments of the present application also provide a training device for a question and answer model, which can be a data processing device, a training method for a question and answer model, and a terminal device. Taking a smartphone as an example, the terminal device is as follows:

[0149] Figure 9 The diagram shows a block diagram of part of the structure of a smartphone related to the terminal device provided by the embodiments of the present application. Referring to Figure 9 , the smartphone includes radio frequency (English full name: Radio Frequency, English abbreviation: RF) circuit 910, memory 920, input unit 930, display unit 940, sensor 950, audio circuit 960, wireless fidelity (English full name: wireless fidelity, English abbreviation: WiFi) module 970, processor 980, and power supply 990, and other components. The input unit 930 can include a touch panel 931 and other input devices 932, and the display unit 940 can include a display panel 941. The audio circuit 960 can include a speaker 961 and a microphone 962. Those skilled in the art can understand that Figure 9 The structure of the smartphone shown in the figure does not constitute a limitation on the smartphone, and can include more or fewer components than the diagram, or combine certain components, or different component arrangements.

[0150] The memory 920 can be used to store software programs and modules, and the processor 980 executes various function applications and data processing of the smart phone by running the software programs and modules stored in the memory 920. The memory 920 can mainly include a program storage area and a data storage area, wherein the program storage area can store an operating system, application programs required by at least one function (such as a sound playing function, an image playing function, etc.), etc.; and the data storage area can store data created according to the use of the smart phone (such as audio data, a phone book, etc.), etc. In addition, the memory 920 can include a high-speed random access memory, and can also include a non-volatile memory, such as at least one magnetic disk storage device, a flash memory device, or other volatile solid-state memory device.

[0151] The processor 980 is the control center of the smart phone, connects all parts of the smart phone through various interfaces and lines, and executes various functions and processes data of the smart phone by running or executing software programs and / or modules stored in the memory 920 and calling data stored in the memory 920. Optionally, the processor 980 can include one or more processing units; preferably, the processor 980 can integrate an application processor and a modem processor, wherein the application processor mainly processes an operating system, a user interface and an application program, etc., and the modem processor mainly processes wireless communication. It can be understood that the above-mentioned modem processor can also not be integrated into the processor 980.

[0152] In the embodiment, the processor 980 in the terminal device can perform the following steps:

[0153] An initial question and answer model is constructed, and the initial question and answer model includes an initial retrieval module and an initial reading module;

[0154] A training corpus is obtained, the training corpus includes a first target document, and the first target document includes an answer corresponding to a question to be answered;

[0155] The initial retrieval module and the initial reading module are jointly trained according to the first target document;

[0156] In the process of the joint training, the first target document used for the i th iteration training is updated by using the initial retrieval module obtained after the i th iteration training, i is an integer greater than or equal to 1;

[0157] The initial retrieval module and the initial reading module obtained after the i th iteration training are respectively subjected to an (i+1) th iteration training according to the updated first target document, until an iteration training condition is satisfied;

[0158] According to the model parameters when the iterative training condition is met and the network structure of the initial question answering model, a target question answering model is determined.

[0159] The device can also include a server, and the embodiments of the present application also provide a server, which will be described below with reference to Figure 10 Figure 10 A structural diagram of the server 1000 provided by the embodiments of the present application is shown in FIG. 10. The server 1000 can have great differences due to different configurations or performances, and can include one or more central processing units (CPUs) 1022 (for example, one or more processors) and a memory 1032, one or more storage media 1030 (for example, one or more mass storage devices) storing application programs 1042 or data 1044. The memory 1032 and the storage media 1030 can be temporary storage or persistent storage. The programs stored in the storage media 1030 can include one or more modules (not shown in the figure), and each module can include a series of instruction operations in the server. Further, the central processing unit 1022 can be configured to communicate with the storage media 1030 and execute the series of instruction operations in the storage media 1030 on the server 1000.

[0160] The server 1000 can also include one or more power supplies 1026, one or more wired or wireless network interfaces 1050, one or more input and output interfaces 1058, and / or one or more operating systems 1041, such as Windows ServerTM, Mac OS XTM, UnixTM, LinuxTM, FreeBSDTM, etc.

[0161] In the embodiments, the central processing unit 1022 in the server 1000 can perform the following steps:

[0162] An initial question answering model is constructed, and the initial question answering model includes an initial retrieval module and an initial reading module;

[0163] A training corpus is obtained, and the training corpus includes a first target document, and the first target document includes an answer corresponding to a question to be answered;

[0164] The initial retrieval module and the initial reading module are jointly trained according to the first target document;

[0165] In the process of the joint training, the first target document used in the i th iteration training is updated by using the initial retrieval module obtained after the i th iteration training, and i is an integer greater than or equal to 1;

[0166] ​According to the first target document after the update, the initial retrieval module and the initial reading module obtained after the i th iteration training are respectively subjected to (i+1) th iteration training until the iteration training condition is met.

[0167] According to the model parameters when the iteration training condition is met and the network structure of the initial question and answer model, a target question and answer model is determined.

[0168] According to an aspect of the present application, a computer readable storage medium is provided, the computer readable storage medium is used to store program codes, the program codes are used to execute the training method of the question and answer model described in the foregoing embodiments.

[0169] According to an aspect of the present application, a computer program product or computer program is provided, the computer program product or computer program includes computer instructions stored in a computer readable storage medium. The processor of the computer device reads the computer instructions from the computer readable storage medium, and the processor executes the computer instructions, so that the computer device executes the method provided in various optional implementation manners of the above embodiments.

[0170] The terms "first", "second", "third", "fourth" and the like in the specification of the present application and the above-described drawings, if any, are used to distinguish similar objects, and do not necessarily have to be used to describe a particular order or sequence. It should be understood that the data thus used can be interchanged under appropriate circumstances, so that the embodiments of the present application described herein can be implemented in an order other than that illustrated or described herein. In addition, the terms "include" and "have" and any variations thereof are intended to cover non-exclusive inclusion, for example, a process, method, system, product or device including a series of steps or units does not have to be limited to those steps or units clearly listed, but can include other steps or units not clearly listed or inherent to these processes, methods, products or devices.

[0171] In several embodiments provided in the present application, it should be understood that the disclosed system, device and method can be implemented in other ways. For example, the device embodiments described above are only schematic, for example, the division of the units is only a logical function division, and actual implementation can have another division manner, for example, a plurality of units or components can be combined or integrated into another system, or some features can be ignored or not executed. In addition, the coupling or direct coupling or communication connection between the units or components shown or discussed can be indirect coupling or communication connection through some interfaces, devices or units, and can be electrical, mechanical or other forms.

[0172] The units described as separate components may or may not be physically separate, and the components displayed as units may or may not be physical units, i.e. may be located in one place, or may be distributed on multiple network units. Part or all of the units may be selected according to actual needs to achieve the purpose of the embodiment scheme.

[0173] In addition, the functional units in each embodiment of the present application can be integrated in one processing unit, or each unit can be physically present separately, or two or more units can be integrated in one unit. The integrated unit can be realized in the form of hardware or in the form of a software functional unit.

[0174] The integrated unit, if realized in the form of a software functional unit and sold or used as an independent product, can be stored in a computer readable storage medium. Based on this understanding, the technical solutions of the present application essentially or the part that contributes to the prior art or the whole or part of the technical solutions can be embodied in the form of a software product. The computer software product is stored in a storage medium, including a plurality of instructions for causing a computer device (which can be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the method described in each embodiment of the present application. The foregoing storage medium includes: a U disk, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, and various program code storage media.

[0175] The above-described embodiments are only used to illustrate the technical solutions of the present application, and not to limit them; although the present application has been described in detail with reference to the foregoing embodiments, those of ordinary skill in the art should understand that they can still modify the technical solutions recorded in the foregoing embodiments, or make equivalent replacements for part of the technical features; and these modifications or replacements do not make the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the embodiments of the present application.

Claims

1. A training method for a question-answering model, characterized in that: Applied to open domain question answering scenarios, the method includes: Constructing an initial question-answering model, wherein the initial question-answering model includes an initial retrieval module and an initial reading module; Acquire a training corpus, wherein the training corpus includes a first target document, and the first target document includes an answer corresponding to a question to be answered; Jointly training the initial retrieval module and the initial reading module according to the first target document; Encode the question to be answered and the candidate documents respectively using the initial retrieval module obtained after the i-th iterative training to obtain a first vector sequence corresponding to the question to be answered and a second vector sequence corresponding to the candidate documents, wherein the first vector sequence includes a word vector corresponding to each word in the question to be answered, and the second vector sequence includes a word vector corresponding to each word in the candidate documents, where i is an integer greater than or equal to 1; Calculating the similarity between the question to be answered and each of the candidate documents respectively according to the first vector sequence and the second vector sequence; Determining a second target document according to the similarity, and updating the first target document using the second target document, wherein the second target document is the updated first target document; Performing the (i+1)th iterative training on the initial retrieval module and the initial reading module obtained after the i-th iterative training according to the updated first target document, until an iterative training condition is met; The target question-answering model is determined based on the model parameters when the iterative training conditions are met and the network structure of the initial question-answering model.

2. The method according to claim 1, characterized in that Jointly training the initial retrieval module and the initial reading module according to the first target document includes: Constructing a first loss function corresponding to the initial retrieval module, and constructing a second loss function corresponding to the initial reading module based on the first target document; Determine a target loss function corresponding to the initial question-answering model according to the first loss function and the second loss function; The model parameters of the initial retrieval module and the initial reading module are adjusted according to the target loss function.

3. The method according to claim 2, characterized in that The constructing of a first loss function corresponding to the initial retrieval module includes: Determining, by the initial retrieval module, the similarity between a third target document and the question to be answered, and the similarity between a fourth target document and the question to be answered, wherein the third target document is any positive sample among the candidate documents, and the fourth target document is any negative sample among the candidate documents, a positive sample is a document among the candidate documents that is relevant to the question to be answered, and a negative sample is a document among the candidate documents that is irrelevant to the question to be answered; The first loss function is calculated based on the similarity between the third target document and the question to be answered, and the similarity between the fourth target document and the question to be answered.

4. The method according to claim 2, characterized in that The constructing a second loss function corresponding to the initial reading module according to the first target document includes: splicing the question to be answered and each of the first target documents into the initial reading module; Determining, by the initial reading module, a first probability that each word vector in the first target document is the beginning of an answer and a second probability that each word vector is the end of an answer; The second loss function is calculated according to the first probability and the second probability.

5. The method according to any one of claims 1 to 4, characterized in that The obtaining of training corpus includes: Retrieving the first target document from candidate documents by the initial retrieval module; Alternatively, the first target document is retrieved from candidate documents by using a pre-trained retrieval module, where the pre-trained retrieval module is trained differently from the initial retrieval module.

6. The method according to claim 5, characterized in that The retrieving the first target document from the candidate documents by the initial retrieval module includes: Encoding the question to be answered and the candidate documents respectively by the initial retrieval module to obtain a first vector sequence corresponding to the question to be answered and a second vector sequence corresponding to the candidate documents, wherein the first vector sequence includes a word vector corresponding to each word in the question to be answered, and the second vector sequence includes a word vector corresponding to each word in the candidate documents; Calculating the similarity between the question to be answered and each of the candidate documents respectively according to the first vector sequence and the second vector sequence; The first target document is determined according to the similarity.

7. The method according to claim 6, characterized in that The initial retrieval module is a dual-tower model, which includes a first branch and a second branch. The first branch includes a first input layer and a first representation layer, and the second branch includes a second input layer and a second representation layer. The first representation layer and the second representation layer are respectively connected to the matching layer. The initial retrieval module encodes the question to be answered and the candidate documents respectively to obtain a first vector sequence corresponding to the question to be answered and a second vector sequence corresponding to the candidate documents: Acquire the question to be answered through the first input layer, and represent the question to be answered as the first vector sequence through the first representation layer; Obtain each candidate document through the second input layer, and represent each candidate document as a second vector sequence through the second representation layer; Calculating the similarity between the question to be answered and each of the candidate documents based on the first vector sequence and the second vector sequence, respectively, includes: The similarity between the question to be answered and each of the candidate documents is calculated based on the first vector sequence and the second vector sequence through the matching layer.

8. The method according to any one of claims 1, 6 or 7, characterized in that: If the similarities are arranged in descending order, the first target document and the updated first target document are ranked in the top K candidate documents; Alternatively, if the similarities are arranged in ascending order, the first target document and the updated first target document are the last K candidate documents in the order.

9. A training device for a question-answering model, characterized in that: Applied to open domain question answering scenarios, the device includes a construction unit, an acquisition unit, a training unit, and a determination unit: The construction unit is used to construct an initial question-answering model, which includes an initial retrieval module and an initial reading module; The acquisition unit is configured to acquire a training corpus, wherein the training corpus includes a first target document, and the first target document includes an answer corresponding to a question to be answered; The training unit is configured to jointly train the initial retrieval module and the initial reading module according to the first target document; Encode the question to be answered and the candidate documents respectively using the initial retrieval module obtained after the i-th iterative training to obtain a first vector sequence corresponding to the question to be answered and a second vector sequence corresponding to the candidate documents, wherein the first vector sequence includes a word vector corresponding to each word in the question to be answered, and the second vector sequence includes a word vector corresponding to each word in the candidate documents, where i is an integer greater than or equal to 1; Calculating the similarity between the question to be answered and each of the candidate documents respectively according to the first vector sequence and the second vector sequence; Determining a second target document according to the similarity, and updating the first target document using the second target document, wherein the second target document is the updated first target document; Performing the (i+1)th iterative training on the initial retrieval module and the initial reading module obtained after the i-th iterative training according to the updated first target document, until an iterative training condition is met; The determination unit is used to determine the target question-answering model based on the model parameters when the iterative training conditions are met and the network structure of the initial question-answering model.

10. The device according to claim 9, characterized in that The training unit is used to: Constructing a first loss function corresponding to the initial retrieval module, and constructing a second loss function corresponding to the initial reading module based on the first target document; Determine a target loss function corresponding to the initial question-answering model according to the first loss function and the second loss function; The model parameters of the initial retrieval module and the initial reading module are adjusted according to the target loss function.

11. The device according to claim 10, characterized in that The training unit is used to: Determining, by the initial retrieval module, the similarity between a third target document and the question to be answered, and the similarity between a fourth target document and the question to be answered, wherein the third target document is any positive sample among the candidate documents, and the fourth target document is any negative sample among the candidate documents, a positive sample is a document among the candidate documents that is relevant to the question to be answered, and a negative sample is a document among the candidate documents that is irrelevant to the question to be answered; The first loss function is calculated based on the similarity between the third target document and the question to be answered, and the similarity between the fourth target document and the question to be answered.

12. The device according to claim 10, characterized in that The training unit is used to: splicing the question to be answered and each of the first target documents into the initial reading module; Determining, by the initial reading module, a first probability that each word vector in the first target document is the beginning of an answer and a second probability that each word vector is the end of an answer; The second loss function is calculated according to the first probability and the second probability.

13. The device according to any one of claims 9 to 12, characterized in that The acquisition unit is configured to: Retrieving the first target document from candidate documents by the initial retrieval module; Alternatively, the first target document is retrieved from candidate documents by using a pre-trained retrieval module, where the pre-trained retrieval module is trained differently from the initial retrieval module.

14. The device according to claim 13, characterized in that The acquisition unit is configured to: Encoding the question to be answered and the candidate documents respectively by the initial retrieval module to obtain a first vector sequence corresponding to the question to be answered and a second vector sequence corresponding to the candidate documents, wherein the first vector sequence includes a word vector corresponding to each word in the question to be answered, and the second vector sequence includes a word vector corresponding to each word in the candidate documents; Calculating the similarity between the question to be answered and each of the candidate documents respectively according to the first vector sequence and the second vector sequence; The first target document is determined according to the similarity.

15. The device according to claim 14, characterized in that The initial retrieval module is a dual-tower model, comprising a first branch and a second branch, wherein the first branch comprises a first input layer and a first representation layer, and the second branch comprises a second input layer and a second representation layer, wherein the first representation layer and the second representation layer are respectively connected to a matching layer, and the acquisition unit is configured to: Acquire the question to be answered through the first input layer, and represent the question to be answered as the first vector sequence through the first representation layer; Obtain each candidate document through the second input layer, and represent each candidate document as a second vector sequence through the second representation layer; Calculating the similarity between the question to be answered and each of the candidate documents based on the first vector sequence and the second vector sequence, respectively, includes: The similarity between the question to be answered and each of the candidate documents is calculated based on the first vector sequence and the second vector sequence through the matching layer.

16. The device according to any one of claims 9, 14 or 15, characterized in that If the similarities are arranged in descending order, the first target document and the updated first target document are ranked in the top K candidate documents; Alternatively, if the similarities are arranged in ascending order, the first target document and the updated first target document are the last K candidate documents in the ranking.

17. A training device for a question-answering model, characterized in that: The device includes a processor and a memory: The memory is used to store program code and transmit the program code to the processor; The processor is configured to execute the method according to any one of claims 1 to 8 according to instructions in the program code.

18. A computer-readable storage medium, characterized in that The computer-readable storage medium is used to store program code, and the program code is used to execute the method according to any one of claims 1 to 8.

19. A computer program product, characterized in that The computer program product includes computer instructions, and a processor of a computer device executes the computer instructions, so that the computer device performs the method according to any one of claims 1 to 8.

Citation Information

Patent Citations

  • Question-answering system implementation method using neural network and machine learning sorting algorithm

    CN111190997A

  • Combined machine retrieval reading method

    CN111552781A