Method and device for generating question and answer response, storage medium and electronic equipment
By introducing self-supervised learning and external retrieval in large language models and dynamically updating model parameters, the problem of insufficient Q&A ability of large language models in professional fields is solved, and better adaptability of professional fields and accuracy of Q&A response is achieved.
Patent Information
- Application Number
- CN202510766184.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-06-10
- Publication Date
- 2025-07-08
- Estimated Expiration
- 2045-06-10
AI Technical Summary
The Q&A capability of large language models in professional fields is subject to problems such as distribution offset and limited domain-specific data, resulting in poor generalization performance.
By predicting the retrieved content during the inference process, dynamically update the model parameters, and using self-supervised learning tasks and external searches, the model is optimized to adapt to the professional field.
The generation performance of the model in the professional field is improved, and it can better adapt to problems with distribution offsets and limited domain-specific data, and the generated Q&A response is more in line with the knowledge and logic of the target field.
Smart Images

Figure CN120277198A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to computer technology, and in particular, to a method, apparatus, storage medium, and electronic device for generating question-and-answer responses. Background Art
[0002] With the development of artificial intelligence, large language models (LLMs) have made significant progress in natural language processing tasks. However, in specific domain applications, their performance is limited due to distribution shift and limited domain-specific data.
[0003] The RAG (Retrieval-Augmented Generation) system enhances the question-and-answer ability of LLMs by integrating external knowledge. However, when adapting the RAG system to a professional domain, due to distribution shift and limited availability of domain-specific data, suboptimal generalization performance is caused, and the RAG system still faces challenges when adapting to a professional domain. Summary of the Invention
[0004] The purpose of the embodiments of this specification is to provide a method, apparatus, storage medium, and electronic device for generating question-and-answer responses.
[0005] The embodiments of this specification provide a method for generating question-and-answer responses. By predicting the retrieved content during the inference process, the parameters of the target domain's real-time dynamic update model are realized, so that the generated question-and-answer responses are more in line with the knowledge and logic of the target domain, to improve the generation performance of the model in the professional domain, and can better adapt to the professional domain. Compared with the standard RAG system, this solution can better address the problems of distribution shift and limited domain-specific data. The method includes: Input the target query into the target model, so that the target model obtains multiple first document fragments corresponding to the target query through external retrieval of the target query; Divide each first document fragment into prefix content and suffix content, and form a first self-supervised learning task according to the prefix content and the suffix content, so that the target model learns based on the first self-supervised learning task; Generate a self-supervised learning signal corresponding to the first document fragment by calculating the prediction loss of the target model for each first document fragment regarding the first self-supervised learning task; Dynamically optimize the model parameters of the target model according to the multiple self-supervised learning signals corresponding to the multiple first document fragments, so that the optimized target model outputs a corresponding question-and-answer response based on the target query.
[0006] Further, the step of enabling the target model to obtain multiple first document segments corresponding to the target query through external retrieval of the target query includes: Enabling the target model to obtain multiple second document segments retrieved and associated with the target query through external retrieval of the target query; Preprocessing the multiple second document segments to obtain multiple first document segments corresponding to the target query.
[0007] Further, the step of preprocessing the multiple second document segments to obtain multiple first document segments corresponding to the target query includes: Performing length filtering on the multiple second document segments, filtering out the second document segments with corresponding lengths greater than or equal to a first preset threshold and / or the second document segments with corresponding lengths less than or equal to a second preset threshold among the multiple second document segments, and using the remaining second document segments as the multiple first document segments corresponding to the target query.
[0008] Further, the step of preprocessing the multiple second document segments to obtain multiple first document segments corresponding to the target query includes: Performing intelligent segmentation on the multiple second document segments, and using the multiple sub-document segments obtained by segmentation as the multiple first document segments corresponding to the target query, where the number of the multiple sub-document segments is greater than or equal to a preset number threshold.
[0009] Further, the step of dynamically optimizing the model parameters of the target model according to the multiple self-supervised learning signals corresponding to the multiple first document segments includes: Dividing the multiple self-supervised learning signals corresponding to the multiple first document segments into multiple groups of sets; Obtaining a group of sets from the multiple groups of sets, dynamically optimizing the current model parameters of the target model according to the self-supervised learning signals in the group of sets. If there is at least one group of sets that has not participated in the optimization among the multiple groups of sets, obtaining another group of sets from the at least one group of sets, and continuing to dynamically optimize the latest model parameters of the target model according to the self-supervised learning signals in the other group of sets, and so on, until all the multiple groups of sets have participated in the optimization.
[0010] Further, the method further includes: Forming at least one second self-supervised learning task based on each first document segment, enabling the target model to learn based on the at least one second self-supervised learning task, where the second self-supervised learning task includes a sentence relationship judgment task and / or an entity recognition task; Among them, generating the self-supervised learning signal corresponding to each first document segment by calculating the prediction loss of the target model for each first document segment with respect to the first self-supervised learning task includes: Generating the self-supervised learning signal corresponding to each first document segment by calculating the first prediction loss of the target model for each first document segment with respect to the first self-supervised learning task and the second prediction loss with respect to the at least one second self-supervised learning task.
[0011] Furthermore, the method further includes: Dynamically adjusting the task weights corresponding to the first self-supervised learning task and the at least one second self-supervised learning task respectively according to the performance data of the target model on the first self-supervised learning task and the at least one second self-supervised learning task.
[0012] An embodiment of this specification also provides a device for generating a question-and-answer response, including: A retrieval module, configured to input a target query into a target model, so that the target model obtains multiple first document segments corresponding to the target query through external retrieval of the target query; A self-supervised learning task module, configured to divide each first document segment into a prefix content and a suffix content, form a first self-supervised learning task according to the prefix content and the suffix content, so that the target model learns based on the first self-supervised learning task; A self-supervised learning signal generation module, configured to generate the self-supervised learning signal corresponding to each first document segment by calculating the prediction loss of the target model for the suffix content in each first document segment; A model output module, configured to dynamically optimize the model parameters of the target model according to the multiple self-supervised learning signals corresponding to the multiple first document segments, so that the optimized target model outputs a corresponding question-and-answer response based on the target query.
[0013] An embodiment of this specification also provides a storage medium, which stores a computer program, and the computer program is adapted to be loaded and executed by a processor to perform the steps of the above method.
[0014] An embodiment of this specification also provides an electronic device, including: a processor and a memory; wherein, the memory stores a computer program, and the computer program is adapted to be loaded and executed by the processor to perform the steps of the above method.
[0015] An embodiment of this specification also provides a computer program product, on which at least one instruction is stored, and characterized in that when the at least one instruction is executed by a processor, the steps of the above method are implemented.
[0016] According to the solution of the embodiment of this specification, input the target query into the target model, so that the target model obtains multiple first document fragments corresponding to the target query through external retrieval of the target query; divide each first document fragment into prefix content and suffix content, and form a first self-supervised learning task according to the prefix content and the suffix content, so that the target model learns based on the first self-supervised learning task; generate a self-supervised learning signal corresponding to the first document fragment by calculating the prediction loss of the target model for each first document fragment with respect to the first self-supervised learning task; dynamically optimize the model parameters of the target model according to the multiple self-supervised learning signals corresponding to the multiple first document fragments, so that the optimized target model outputs a corresponding question-and-answer response based on the target query. Thus, by predicting the retrieved content during the inference process, the parameters of the model for the target domain can be updated in real time and dynamically, making the generated question-and-answer response more in line with the knowledge and logic of the target domain, so as to improve the generation performance of the model in the professional field, be better adapted to the professional field, and compared with the standard RAG system, this solution can better address the problems of distribution shift and limited domain-specific data. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] Figure 1 It is a schematic flowchart of a method for generating a question-and-answer response provided by an embodiment of this specification; Figure 2 It is a schematic flowchart of an example for generating a question-and-answer response provided by an embodiment of this specification; Figure 3 It is a schematic structural diagram of a device for generating a question-and-answer response provided by an embodiment of this specification; Figure 4 It is a schematic structural diagram of an electronic device provided by an embodiment of this specification. DETAILED DESCRIPTION OF THE EMBODIMENTS
[0018] To make the purpose, technical solutions, and advantages of this specification clearer, the technical solutions of this specification will be clearly and completely described below in conjunction with the specific embodiments of this specification and the corresponding drawings. Obviously, the described embodiments are only a part of the embodiments of this specification, rather than all of the embodiments. Based on the embodiments in this specification, all other embodiments obtained by those of ordinary skill in the art without creative efforts shall fall within the protection scope of this specification.
[0019] Please refer to Figure 1, which is a schematic flowchart of a method for generating a question-and-answer response provided in an embodiment of this specification. In the embodiments of this specification, the method for generating a question-and-answer response is applied to the device for generating a question-and-answer response (hereinafter simply referred to as the "question-and-answer response generation device") described in the embodiments of this specification or an electronic device configured with the question-and-answer response generation device. The following will elaborate in detail on the Figure 1 process shown. The method for generating a question-and-answer response may specifically include the following steps: S102, input the target query into the target model, so that the target model obtains multiple first document fragments corresponding to the target query through external retrieval of the target query.
[0020] In some embodiments, the target model refers to a large language model. A large language model refers to a deep learning model trained with a large amount of text data, enabling the model to generate natural language text or understand the meaning of language text. In some embodiments, the target query input into the target model refers to an instruction or question input by a user to the target large model, and the target large model will generate a corresponding question-and-answer response based on the target query after corresponding processing. In some embodiments, the target query may only include text content, or in addition to the text content, the target query may further include, but is not limited to, other forms of content such as image content, audio content, video content, icon content, etc. This exemplary embodiment does not make special limitations on this.
[0021] In some embodiments, the target model includes a RAG (Retrieval-Augmented Generation) system. The RAG system enhances the question-and-answer ability of the large language model by integrating external knowledge sources, enabling the large language model to access and utilize external knowledge during the generation process to make up for the limitations of the static parameterized knowledge of the large language model. In some embodiments, the RAG system will perform external retrieval on the target query input into the target model using an external knowledge source, and obtain multiple first document fragments corresponding to the target query according to the retrieval result. For example, a preset number of document fragments with the highest degree of association with the target query in the retrieval result may be used as the multiple first document fragments corresponding to the target query, or alternatively, a preset number of recently published document fragments in the retrieval result may be used as the multiple first document fragments corresponding to the target query. This exemplary embodiment does not make special limitations on the specific manner of obtaining multiple first document fragments according to the retrieval result.
[0022] In some embodiments, the external retrieval may include only text retrieval, or, in addition to text retrieval, the external retrieval may further include multimodal retrieval (such as images, charts, etc.) to enrich the types of retrieved information, enabling the target model to utilize knowledge in more dimensions. In some embodiments, the external knowledge source used for external retrieval may be a static data source, or may also be a real-time data source to ensure that the target model can obtain the latest information, especially in professional fields with high timeliness requirements such as finance and news.
[0023] S104. Split each first document fragment into a prefix content and a suffix content, and form a first self-supervised learning task according to the prefix content and the suffix content, so that the target model learns based on the first self-supervised learning task.
[0024] In some embodiments, each first document fragment is split into a prefix content and a suffix content, and the union of the prefix content and the suffix content is the first document fragment. In some embodiments, the specific splitting method may be random splitting, as long as it is ensured that each of the prefix content and the suffix content is semantically complete, or it may also be splitting at a preset punctuation mark. For example, splitting at a certain preset punctuation mark (such as a full stop or a comma) in the first document fragment, so that the absolute value of the difference between the number of words in the prefix content and the number of words in the suffix content is less than a preset threshold. It should be noted that the above splitting methods are only examples, not limitations. Those skilled in the art should understand that any method of splitting a document fragment can be included within the scope of protection of this specification. The specific splitting method of the document fragment in this exemplary embodiment is not specially limited.
[0025] In some embodiments, a first self-supervised learning task is formed according to the prefix content and the suffix content obtained after splitting each first document fragment. The first self-supervised learning task is used to predict the suffix content based on the prefix content, that is, the first self-supervised learning task belongs to the prediction task of the prefix-suffix pair. The target model performs self-supervised learning on the prefix content and the suffix content corresponding to multiple first document fragments based on this first self-supervised learning task, so that the target model can predict the suffix content based on the prefix content. In some embodiments, self-supervised learning is a learning method that does not require manually labeled data. It generates "pseudo-labels" or "auxiliary tasks" by utilizing the structure of the data itself, and uses these generated labels to train the model.
[0026] S106. Generate a self-supervised learning signal corresponding to the first document fragment by calculating the prediction loss of the target model for each first document fragment with respect to the first self-supervised learning task.
[0027] In some embodiments, after the target model completes self-supervised learning based on the first self-supervised learning task, the self-supervised learning signal corresponding to the first document fragment is generated by calculating the prediction loss of the target model for each first document fragment with respect to the first self-supervised learning task. Specifically, for each first document fragment, the self-supervised learning signal corresponding to the first document fragment is generated by calculating the loss between the predicted suffix content obtained by the target model based on the prefix content of the first document fragment and the actual suffix content of the first document fragment. The self-supervised learning signal refers to a clear goal or label for guiding the model to learn. The self-supervised learning signal guides the target model to learn, enabling the target model to dynamically optimize (or dynamically adjust) the model parameters during the learning process. This solution introduces a self-supervised learning task, uses the retrieved document fragments as supervision signals, and generates learning signals through the prefix-suffix pair prediction task for the target model to optimize the model parameters.
[0028] S108. Dynamically optimize the model parameters of the target model according to the multiple self-supervised learning signals corresponding to the multiple first document fragments, so that the optimized target model outputs a corresponding question-and-answer response based on the target query.
[0029] In some embodiments, the model parameters of the target model are dynamically optimized (or dynamically adjusted) according to the multiple self-supervised learning signals corresponding to the multiple first document fragments respectively, so that the model parameters of the target model adapt to the target domain corresponding to the target query, thereby realizing the dynamic adjustment of the model parameters without a large amount of labeled data and being able to more flexibly adapt to complex professional fields. For example, the gradient descent method can be used to optimize the model parameters of the target model to maintain computational efficiency. It should be noted that the above method for optimizing the model parameters is only an example, not a limitation. Those skilled in the art should understand that any method for optimizing the model parameters according to the self-supervised learning signal can be included within the scope of protection of this specification. The specific method for optimizing the model parameters in this exemplary embodiment is not specially limited.
[0030] In some embodiments, the target model after optimizing the model parameters generates and outputs a final question-and-answer response based on the target query input to the target model. Through the optimized model parameters, the generated question-and-answer response is more in line with the knowledge and logic of the target domain corresponding to the target query.
[0031] According to the solution of the embodiments of this specification, input the target query into the target model, so that the target model obtains multiple first document fragments corresponding to the target query through external retrieval of the target query; divide each first document fragment into prefix content and suffix content, and form a first self-supervised learning task according to the prefix content and the suffix content, so that the target model learns based on the first self-supervised learning task; generate a self-supervised learning signal corresponding to the first document fragment by calculating the prediction loss of the target model for each first document fragment with respect to the first self-supervised learning task; dynamically optimize the model parameters of the target model according to the multiple self-supervised learning signals corresponding to the multiple first document fragments, so that the optimized target model outputs a corresponding question-and-answer response based on the target query. Thus, by predicting the retrieved content during the inference process, the parameters of the model for the target domain are updated in real time and dynamically, making the generated question-and-answer response more in line with the knowledge and logic of the target domain, so as to improve the generation performance of the model in the professional field, be better adapted to the professional field. Compared with the standard RAG system, this solution can better handle the problems of distribution shift and limited domain-specific data.
[0032] In some embodiments, the step of enabling the target model to obtain multiple first document fragments corresponding to the target query through external retrieval of the target query includes: enabling the target model to obtain multiple second document fragments retrieved and associated with the target query through external retrieval of the target query; preprocess the multiple second document fragments to obtain multiple first document fragments corresponding to the target query. In some embodiments, the RAG system will perform external retrieval on the target query input into the target model by using an external knowledge source, retrieve multiple second document fragments associated with the target query, and then preprocess the multiple second document fragments to obtain multiple first document fragments corresponding to the target query. Among them, the preprocessing includes but is not limited to text cleaning (removing noise and unstructured content to ensure that the document fragments input into the target model are clear), chunking and truncation (cutting long document fragments into short document fragments suitable for input into the target model), information enhancement (supplementing context information to help the target model better understand the content of the document fragments), relevance filtering (retaining the document fragments most relevant to the target query and reducing noise), compression and summarization (streamlining the content of the document fragments and retaining the core information), embedding optimization (ensuring that the embedding of the document fragments is aligned with the semantic space of the target model), adversarial content filtering (preventing malicious or misleading content in the document fragments from affecting the generation result), etc. The specific manner of preprocessing is not specially limited in this exemplary embodiment.
[0033] In some embodiments, the preprocessing of the plurality of second document segments to obtain the plurality of first document segments corresponding to the target query includes: performing length filtering on the plurality of second document segments, filtering out the second document segments in the plurality of second document segments whose corresponding lengths are greater than or equal to a first preset threshold and / or the second document segments whose corresponding lengths are less than or equal to a second preset threshold, and using the remaining second document segments as the plurality of first document segments corresponding to the target query. In some embodiments, since too long or too short document segments may cause the performance of the target model to decline (such as information redundancy or insufficient information), after retrieving the plurality of second document segments associated with the target query, it is necessary to filter out the second document segments in the plurality of second document segments whose corresponding lengths are greater than or equal to a first preset threshold and / or the second document segments whose corresponding lengths are less than or equal to a second preset threshold, and use the remaining second document segments after filtering as the plurality of first document segments corresponding to the target query.
[0034] In some embodiments, the preprocessing of the plurality of second document segments to obtain the plurality of first document segments corresponding to the target query includes: performing intelligent segmentation on the plurality of second document segments, and using the plurality of sub-document segments obtained by segmentation as the plurality of first document segments corresponding to the target query, where the number of the plurality of sub-document segments is greater than or equal to a preset number threshold. In some embodiments, to ensure that there are enough document segments for self-supervised learning in the first self-supervised learning task, after retrieving the plurality of second document segments associated with the target query, it is necessary to perform intelligent segmentation on the plurality of second document segments to obtain a plurality of sub-document segments such that the number of the plurality of sub-document segments is greater than or equal to a preset number threshold, and then use the plurality of sub-document segments as the plurality of first document segments corresponding to the target query. In some embodiments, each sub-document segment obtained by segmentation needs to ensure the semantic integrity within the sub-document segment. In some embodiments, the length of each sub-document segment obtained by segmentation is less than or equal to a first preset length threshold, or, on this basis, it is further required that the length of each sub-document segment is greater than or equal to a second preset length threshold. In some embodiments, the core objectives of intelligent segmentation include but are not limited to semantic integrity (ensuring that each sub-document segment contains a complete meaning unit (such as a paragraph, topic, etc.), and avoiding breaking the logical chain or key information due to segmentation), context coherence (maintaining the internal logical structure of each sub-document segment (such as causal, contrast, temporal relationship, etc.), and avoiding incorrect reasoning by the target model due to context breakage), computational efficiency optimization (balancing semantic quality and computational overhead, and avoiding affecting the real-time performance of the system due to overly complex segmentation strategies), etc. This exemplary embodiment does not make special limitations on this.
[0035] In some embodiments, dynamically optimizing the model parameters of the target model according to the multiple self-supervised learning signals corresponding to the multiple first document segments includes: dividing the multiple self-supervised learning signals corresponding to the multiple first document segments into multiple sets; obtaining a set from the multiple sets, and dynamically optimizing the current model parameters of the target model according to the self-supervised learning signals in this set. If there is at least one set among the multiple sets that has not participated in the optimization, obtain another set from the at least one set, and continue to dynamically optimize the latest model parameters of the target model according to the self-supervised learning signals in this other set, and so on, until all the multiple sets have participated in the optimization. In some embodiments, the multiple self-supervised learning signals corresponding to the multiple first document segments are divided into multiple sets. Each set includes several self-supervised learning signals. The union of the multiple sets is the multiple self-supervised learning signals. Each self-supervised learning signal in the multiple self-supervised learning signals is only located in one of the multiple sets. Here, it should be noted that the number of groups of the multiple sets and the number of self-supervised learning signals in each set are not specifically limited in this exemplary embodiment. In some embodiments, obtain a set from the multiple sets (for example, randomly obtain), and dynamically optimize the current model parameters of the target model according to the self-supervised learning signals in this set. After the optimization is completed, determine whether there is at least one set among the multiple sets that has not participated in the optimization. If not, end the optimization. If so, obtain another set from the at least one set that has not participated in the optimization (for example, randomly obtain), and continue to dynamically optimize the latest model parameters of the target model according to the self-supervised learning signals in this other set, and so on, until all the multiple sets have participated in the optimization, so as to avoid excessive jitter through the method of grouped optimization. In some embodiments, during the process of dynamically optimizing the latest model parameters of the target model using the self-supervised learning signals in each set, the AdamW (Adam with Decoupled Weight Decay) optimizer is used to ensure stable training by accumulating gradients and performing clipping. Among them, the AdamW optimizer is an optimization algorithm for deep learning model training. It is a variant of the Adam (Adaptive Moment Estimation) optimizer. It should be noted that the above method of optimizing the model parameters is only an example, not a limitation. Those skilled in the art should understand that any method of optimizing the model parameters using an optimizer can be included within the scope of protection of this specification. The specific type of the optimizer is not specifically limited in this exemplary embodiment.
[0036] In some embodiments, the method further includes: forming at least one second self-supervised learning task based on each first document fragment, such that the target model learns based on the at least one second self-supervised learning task, wherein the second self-supervised learning task includes a sentence relationship judgment task and / or an entity recognition task; wherein, generating the self-supervised learning signal corresponding to the first document fragment by calculating the prediction loss of the target model for each first document fragment with respect to the first self-supervised learning task includes: generating the self-supervised learning signal corresponding to the first document fragment by calculating the first prediction loss of the target model for each first document fragment with respect to the first self-supervised learning task and the second prediction loss with respect to the at least one second self-supervised learning task. In some embodiments, in addition to the first self-supervised learning task for predicting the suffix content from the prefix content, other self-supervised learning tasks (such as sentence relationship judgment, entity recognition, etc.) can be introduced to enhance the target model's ability to understand text. It should be noted that the above self-supervised learning tasks are only examples, and the number and type of self-supervised learning tasks in this exemplary embodiment are not specifically limited. In some embodiments, at least one second self-supervised learning task is formed based on each first document fragment, the second self-supervised learning task includes a sentence relationship judgment task and / or an entity recognition task, and then in addition to learning based on the first self-supervised learning task, the target model also learns based on the at least one second self-supervised learning task, and then the self-supervised learning signal corresponding to the first document fragment is generated by calculating the first prediction loss of the target model for each first document fragment with respect to the first self-supervised learning task and the second prediction loss with respect to the at least one second self-supervised learning task, wherein the first prediction loss refers to the loss between the prediction result of the target model for the first self-supervised learning task and the true value, and the second prediction loss refers to the loss between the prediction result of the target model for the second self-supervised learning task and the true value. The corresponding self-supervised learning signal can be generated by adding the first prediction loss to the second prediction loss corresponding to each second self-supervised learning task, or by adding the product of the first prediction loss and the task weight of the first self-supervised learning task to the product of the second prediction loss corresponding to each second self-supervised learning task and the task weight of the second self-supervised learning task.
[0037] In some embodiments, the method further includes: dynamically adjusting the task weights corresponding to the first self-supervised learning task and the at least one second self-supervised learning task according to the performance data of the target model on the first self-supervised learning task and the at least one second self-supervised learning task. In some embodiments, based on the performance data of the target model on each of the second self-supervised learning tasks in the first self-supervised learning task and the at least one second self-supervised learning task, the task weights of at least one self-supervised learning task among the first self-supervised learning task and the at least one second self-supervised learning task are dynamically adjusted, so that when the subsequent target model receives a new query with a new input, the target model performs corresponding self-supervised learning based on the adjusted task weights to optimize the overall learning effect. The performance data includes, but is not limited to, at least one of data such as accuracy, precision, recall rate, F1 score (the harmonic mean of precision and recall rate, used to balance the relationship between the two), and normalized discounted cumulative gain. This example embodiment does not make special limitations on this.
[0038] Figure 2 It is a schematic flowchart of a process for generating a question-and-answer response provided by an embodiment of this specification.
[0039] As Figure 2 shown, the query q is input into the model. The model obtains the corresponding document fragments by retrieving the database, preprocesses the retrieved document fragments to obtain the target document fragments corresponding to the query q, divides each target document fragment into a prefix and a suffix pair to form a self-supervised learning task, enabling the model to predict the suffix content based on the prefix content, generates a self-supervised signal by calculating the prediction loss of the model for the suffix content, the model dynamically adjusts the model parameters according to the self-supervised information (i.e., the model parameters adapt), and finally the model after adjusting the model parameters generates and outputs the corresponding question-and-answer response based on the query q.
[0040] Figure 3 It is a schematic structural diagram of a device for generating a question-and-answer response provided by an embodiment of this specification. The device for generating a question-and-answer response (hereinafter simply referred to as "question-and-answer response generation device 1") can be implemented as all or part of an electronic device through software, hardware, or a combination of both. According to some embodiments, the question-and-answer response generation device 1 includes a retrieval module 11, a self-supervised learning task module 12, a self-supervised learning signal generation module 13, and a model output module 14.
[0041] The retrieval module 11 is configured to input a target query into a target model, so that the target model obtains a plurality of first document fragments corresponding to the target query through external retrieval of the target query; The self-supervised learning task module 12 is used to divide each first document segment into a prefix content and a suffix content, and form a first self-supervised learning task according to the prefix content and the suffix content, so that the target model learns based on the first self-supervised learning task; The self-supervised learning signal generation module 13 is used to generate a self-supervised learning signal corresponding to the first document segment by calculating the prediction loss of the target model for the suffix content in each first document segment; The model output module 14 is used to dynamically optimize the model parameters of the target model according to the multiple self-supervised learning signals corresponding to the multiple first document segments, so that the optimized target model outputs a corresponding question and answer response based on the target query.
[0042] In some embodiments, the step of enabling the target model to obtain multiple first document segments corresponding to the target query by performing external retrieval on the target query includes: enabling the target model to perform external retrieval on the target query to obtain multiple second document segments associated with the target query retrieved; preprocessing the multiple second document segments to obtain multiple first document segments corresponding to the target query.
[0043] In some embodiments, the step of preprocessing the multiple second document segments to obtain multiple first document segments corresponding to the target query includes: performing length filtering on the multiple second document segments, filtering out the second document segments with a corresponding length greater than or equal to a first preset threshold and / or the second document segments with a corresponding length less than or equal to a second preset threshold among the multiple second document segments, and using the remaining second document segments as the multiple first document segments corresponding to the target query.
[0044] In some embodiments, the step of preprocessing the multiple second document segments to obtain multiple first document segments corresponding to the target query includes: performing intelligent segmentation on the multiple second document segments, and using the multiple sub-document segments obtained by segmentation as the multiple first document segments corresponding to the target query, where the number of the multiple sub-document segments is greater than or equal to a preset number threshold.
[0045] In some embodiments, dynamically optimizing the model parameters of the target model according to the multiple self-supervised learning signals corresponding to the multiple first document segments includes: dividing the multiple self-supervised learning signals corresponding to the multiple first document segments into multiple groups of sets; obtaining a group of sets from the multiple groups of sets, and dynamically optimizing the current model parameters of the target model according to the self-supervised learning signals in the group of sets. If there is at least one group of sets in the multiple groups of sets that has not participated in the optimization, obtain another group of sets from the at least one group of sets, and continue to dynamically optimize the latest model parameters of the target model according to the self-supervised learning signals in the other group of sets, and so on, until all the multiple groups of sets have participated in the optimization.
[0046] In some embodiments, the question-and-answer response generation device 1 is further configured to: form at least one second self-supervised learning task based on each first document segment, so that the target model learns based on the at least one second self-supervised learning task, where the second self-supervised learning task includes a sentence relationship judgment task and / or an entity recognition task; where generating the self-supervised learning signal corresponding to the first document segment by calculating the prediction loss of the target model for each first document segment regarding the first self-supervised learning task includes: generating the self-supervised learning signal corresponding to the first document segment by calculating the first prediction loss of the target model for each first document segment regarding the first self-supervised learning task and the second prediction loss regarding the at least one second self-supervised learning task.
[0047] In some embodiments, the question-and-answer response generation device 1 is further configured to: dynamically adjust the task weights corresponding to the first self-supervised learning task and the at least one second self-supervised learning task according to the performance data of the target model on the first self-supervised learning task and the at least one second self-supervised learning task.
[0048] The above device embodiments correspond to the foregoing method embodiments, and the specific description can be referred to the description of the method embodiment part, which will not be repeated here. The device embodiments are obtained based on the corresponding method embodiments and have the same technical effects as the corresponding method embodiments. For specific descriptions, please refer to the corresponding method embodiments.
[0049] The embodiments of the present specification also provide a computer storage medium, which can store multiple instructions, and the instructions are suitable for being loaded and executed by a processor to execute the method of the embodiments of the present specification.
[0050] The embodiments of the present specification also provide a computer program product, which stores at least one instruction, and the at least one instruction is loaded and executed by the processor to execute the method of the embodiments of the present specification.
[0051] The embodiments of this specification also provide Figure 4 a schematic structural diagram of the electronic device shown. As Figure 4 , at the hardware level, the electronic device includes a processor, an internal bus, a network interface, a memory, and a non-volatile memory. Of course, it may also include other hardware required for other services. The processor reads the corresponding computer program from the non-volatile memory into the memory and then runs it to implement the above method.
[0052] The systems, devices, modules, or units illustrated in the above embodiments may be specifically implemented by computer chips or entities, or by products with certain functions. A typical implementation device is a computer. Specifically, the computer may be, for example, a personal computer, a laptop computer, a cellular phone, a camera phone, a smart phone, a personal digital assistant, a media player, a navigation device, an email device, a game console, a tablet computer, a wearable device, or a combination of any of these devices.
[0053] Those skilled in the art should understand that the embodiments of this specification may be provided as a method, a system, or a computer program product. Therefore, this specification may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware aspects. Moreover, this specification may take the form of a computer program product implemented on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0054] This specification is described with reference to the flowcharts and / or block diagrams of methods, devices (systems), and computer program products according to the embodiments of this specification. It should be understood that each flow and / or block in the flowchart and / or block diagram, and the combination of flows and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to the processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing devices to generate a machine, such that the instructions executed by the processor of the computer or other programmable data processing devices generate a device for implementing the specified functions in Figure 1 one or more flows and / or blocks Figure 1 one or more blocks.
[0055] These computer program instructions can also be stored in a computer-readable memory that can direct a computer or other programmable data processing devices to work in a specific manner, such that the instructions stored in the computer-readable memory generate a manufactured article including an instruction device that implements the specified functions in Figure 1 one or more flows and / or blocks Figure 1 one or more blocks.
[0056] These computer program instructions can also be loaded onto a computer or other programmable data processing apparatus, so that a series of operation steps are executed on the computer or other programmable apparatus to produce a computer-implemented process, and thus the instructions executed on the computer or other programmable apparatus provide steps for implementing the functions specified in one process or a plurality of processes and / or boxes Figure 1 One process or a plurality of processes and / or boxes Figure 1 Steps for implementing the functions specified in one box or a plurality of boxes.
[0057] It should also be noted that the term "comprising", "including" or any other variation thereof is intended to cover non-exclusive inclusion, so that a process, method, commodity or device comprising a series of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such process, method, commodity or device. Without further limitation, an element defined by the statement "comprising an..." does not exclude the presence of additional identical elements in the process, method, commodity or device comprising the element.
[0058] This specification may be described in the general context of computer-executable instructions executed by a computer, such as program modules. Generally, program modules include routines, programs, objects, components, data structures, etc. that perform specific tasks or implement specific abstract data types. This specification may also be practiced in a distributed computing environment where tasks are performed by remote processing devices connected through a communication network. In a distributed computing environment, program modules may be located in local and remote computer storage media including storage devices.
[0059] Each embodiment in this specification is described in a progressive manner. For the same or similar parts among the embodiments, reference can be made to each other. Each embodiment focuses on the differences from other embodiments. In particular, for system embodiments, since they are basically similar to method embodiments, the description is relatively simple, and reference can be made to the partial description of the method embodiments for the relevant parts.
[0060] The above is only the embodiments of this specification and is not intended to limit this specification. For those skilled in the art, various changes and modifications can be made to this specification. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of this specification shall be included within the scope of the claims of this specification.
Claims
1. A method for generating a question-and-answer response, comprising: Inputting a target query into a target model, such that the target model obtains a plurality of first document fragments corresponding to the target query through external retrieval of the target query; Dividing each first document fragment into prefix content and suffix content, and forming a first self-supervised learning task according to the prefix content and the suffix content, such that the target model learns based on the first self-supervised learning task; Generating a self-supervised learning signal corresponding to the first document fragment by calculating a prediction loss of the target model for each first document fragment with respect to the first self-supervised learning task; Dynamically optimizing the model parameters of the target model according to the plurality of self-supervised learning signals corresponding to the plurality of first document fragments, such that the optimized target model outputs a corresponding question-and-answer response based on the target query.
2. The method according to claim 1, wherein the step of enabling the target model to obtain a plurality of first document fragments corresponding to the target query through external retrieval of the target query comprises: Enabling the target model to obtain a plurality of second document fragments retrieved and associated with the target query through external retrieval of the target query; Preprocessing the plurality of second document fragments to obtain a plurality of first document fragments corresponding to the target query.
3. The method according to claim 2, wherein the step of preprocessing the plurality of second document fragments to obtain a plurality of first document fragments corresponding to the target query comprises: Performing length filtering on the plurality of second document fragments, filtering out the second document fragments in the plurality of second document fragments with a corresponding length greater than or equal to a first preset threshold and / or the second document fragments with a corresponding length less than or equal to a second preset threshold, and taking the remaining second document fragments as the plurality of first document fragments corresponding to the target query.
4. The method according to claim 2, wherein the step of preprocessing the plurality of second document fragments to obtain a plurality of first document fragments corresponding to the target query comprises: Performing intelligent segmentation on the plurality of second document fragments, and taking the plurality of sub-document fragments obtained by segmentation as the plurality of first document fragments corresponding to the target query, wherein the number of the plurality of sub-document fragments is greater than or equal to a preset number threshold.
5. The method according to claim 1, wherein the step of dynamically optimizing the model parameters of the target model according to the plurality of self-supervised learning signals corresponding to the plurality of first document fragments comprises: Dividing the plurality of self-supervised learning signals corresponding to the plurality of first document fragments into multiple groups of sets; Obtaining a group of sets from the multiple groups of sets, dynamically optimizing the current model parameters of the target model according to the self-supervised learning signals in the group of sets, if there is at least one group of sets in the multiple groups of sets that has not participated in the optimization, obtaining another group of sets from the at least one group of sets, and continuing to dynamically optimize the latest model parameters of the target model according to the self-supervised learning signals in the other group of sets, and so on, until all the multiple groups of sets have participated in the optimization.
6. The method according to claim 1 further comprises: forming at least one second self-supervised learning task based on each first document fragment, such that the target model learns based on the at least one second self-supervised learning task, wherein the second self-supervised learning task comprises a sentence relation judgment task and / or an entity recognition task; wherein, generating the self-supervised learning signal corresponding to the first document fragment by calculating the prediction loss of the target model for the first document fragment with respect to the first self-supervised learning task comprises: generating the self-supervised learning signal corresponding to the first document fragment by calculating a first prediction loss of the target model for the first document fragment with respect to the first self-supervised learning task and a second prediction loss of the target model for the first document fragment with respect to the at least one second self-supervised learning task.
7. The method according to claim 6 further comprises: dynamically adjusting the task weights corresponding to the first self-supervised learning task and the at least one second self-supervised learning task respectively according to the performance data of the target model on the first self-supervised learning task and the at least one second self-supervised learning task.
8. An apparatus for generating a question-and-answer response, comprising: a retrieval module, configured to input a target query into a target model, such that the target model obtains a plurality of first document fragments corresponding to the target query through external retrieval of the target query; a self-supervised learning task module, configured to divide each first document fragment into a prefix content and a suffix content, and form a first self-supervised learning task according to the prefix content and the suffix content, such that the target model learns based on the first self-supervised learning task; a self-supervised learning signal generation module, configured to generate the self-supervised learning signal corresponding to the first document fragment by calculating the prediction loss of the target model for the suffix content in each first document fragment; a model output module, configured to dynamically optimize the model parameters of the target model according to the plurality of self-supervised learning signals corresponding to the plurality of first document fragments, such that the optimized target model outputs a corresponding question-and-answer response based on the target query.
9. A storage medium having a computer program stored thereon, characterized in that, The computer program, when executed by a processor, implements the steps of the method according to any one of claims 1 to 7.
10. An electronic device, characterized in that, Comprising: a processor and a memory; wherein, the memory stores a computer program, and the computer program is adapted to be loaded and executed by the processor to implement the steps of the method according to any one of claims 1 to 7.
11. A computer program product having at least one instruction stored thereon, characterized in that, The at least one instruction, when executed by the processor, implements the steps of the method according to any one of claims 1 to 7.
Citation Information
Patent Citations
Question response method and device based on large language model
CN117235226A
Information acquisition method and device and electronic equipment
CN119807356A
Enterprise data insights retrieval system utilizing graph databases and large language models
IN202521005092A
Method for question-answering based on asr
KR102552401B1
Method and system for determining confidence in answer for search
US20100332499A1