Natural language processing task execution and model training methods, equipment, and media
The student model is trained by generating text data for logical reasoning and error correction steps, which solves the problem of high computing and storage resources for natural language processing tasks, improves execution accuracy and reasoning capabilities, and is suitable for resource-constrained application scenarios.
Patent Information
- Application Number
- CN202410993683.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-24
- Publication Date
- 2024-09-27
- Estimated Expiration
- 2044-07-24
AI Technical Summary
The computational cost and storage overhead of existing natural language processing tasks are high, and traditional knowledge distillation methods ignore the intermediate information of the teacher model, resulting in the student model lacking deep reasoning capabilities and unable to meet the demand for execution accuracy.
The large-scale teacher model is used to generate text data for logical reasoning steps and error correction steps, and the small-scale student model is trained to have step-by-step reasoning capabilities, and is fine-tuned through the logical reasoning text data set to adapt to specific natural language processing tasks.
It effectively reduces the computing and storage resource requirements of natural language processing tasks, improves execution accuracy, and enables the student model to achieve performance similar to that of the teacher model in specific tasks, and has strong reasoning and error correction capabilities.
Smart Images

Figure CN118536605B
Abstract
Description
Technical Field
[0001] The present invention relates to the field of artificial intelligence technology, and in particular to a natural language processing task execution and model training method, electronic equipment, non-volatile storage medium, computer program product, and mobile device. Background Art
[0002] NLP (Natural Language Processing) can help computers understand and process human language, enabling computers to read and understand natural language. With the rapid development of artificial intelligence technology, the scale of natural language models that can handle natural language processing tasks is getting larger and larger, which leads to high computational costs and storage overheads in the execution process of natural language processing tasks.
[0003] Related technologies usually use a large-scale teacher model for knowledge distillation to obtain a dense student model, and let this student model achieve similar accuracy on specific downstream tasks. However, knowledge distillation focuses on the final prediction probability and ignores the intermediate information of the teacher model during the reasoning process, which may result in the final student model lacking deep reasoning capabilities, which is not enough to make the student model achieve performance matching that of the teacher model and cannot meet the user's requirements for the execution accuracy of natural language processing tasks.
[0004] In view of this, improving the execution accuracy of natural language processing tasks on the basis of solving the high computational cost and storage overhead of natural language processing tasks is a technical problem that technicians in this field have to solve.
[0005] It should be noted that the information disclosed in the above background technology section is only used to enhance the understanding of the background of the present application, and therefore may include information that does not constitute the prior art known to ordinary technicians in the field. Summary of the invention
[0006] The present invention provides a natural language processing task execution and model training method, electronic device, non-volatile storage medium, computer program product, and mobile device. On the basis of solving the high computing cost and storage overhead of natural language processing tasks, the execution accuracy of natural language processing tasks is effectively improved to obtain more accurate answers.
[0007] In order to solve the above technical problems, the present invention provides the following technical solutions:
[0008] The present invention provides a natural language model training method, comprising:
[0009] Obtain a first natural language model, a second natural language model and a text data set corresponding to a natural language processing task to be performed; each text sample of the text data set includes a question text and a corresponding correct answer text and an incorrect answer text; use the first natural language model to process each text data of the text data set to generate logical reasoning step text data for obtaining the correct answer text based on the question text, and error correction step text data for explaining the error cause of the incorrect answer text; generate a logical reasoning text data set based on the text data set, the logical reasoning step text data and the error correction step text data; use the logical reasoning text data set to train the second natural language model, so as to use the trained second natural language model to perform a natural language processing task; wherein the model parameter amount of the second natural language model is less than the model parameter amount of the first natural language model, and the parameter amount difference between the model parameter amount of the second natural language model and the model parameter amount of the first natural language model is at least greater than two orders of magnitude.
[0010] In a first exemplary implementation, each text data of the text data set is processed using the first natural language model to generate text data of logical reasoning steps for obtaining the correct answer text based on the question text, including:
[0011] A positive prompt template is constructed in advance; the positive prompt template includes a question text and a corresponding correct answer text; the positive prompt template is input into the first natural language model as prompt information, and the first natural language model generates logical reasoning step text data consistent with the corresponding correct answer text for the currently input question text according to a target tag generation method; wherein the target tag generation method is a tag corresponding to the maximum credibility increase when selecting the correct answer compared to the correct comparison answer.
[0012] In a second exemplary embodiment, the correct comparison answer is a blank character, and the step of generating logical reasoning step text data consistent with the corresponding correct answer text for the currently input question text according to the target tag generation method includes:
[0013] The correct mark profit calculation formula is called to calculate the correct answer profit of each mark; the correct mark profit calculation formula is:
[0014] ;
[0015] In the formula, represents the correct answer benefit for the ith mark, represents the i-th mark, represents the correct answer text, P represents the probability, p represents the given context, q represents the question text, represents all the tags before the i-th tag, Indicates that the correct comparison answer is a blank character.
[0016] In a third exemplary embodiment, the step of generating logical reasoning step text data consistent with the corresponding correct answer text for the currently input question text in accordance with the target tag generation method includes:
[0017] Based on the correct answer benefits of each mark, the correct mark selection relation is called to select the target correct mark; the correct mark selection relation is:
[0018] ;
[0019] In the formula, Represents the next token generated after the i-th token.
[0020] In a fourth exemplary embodiment, generating a logical reasoning text data set based on the text data set, the logical reasoning step text data, and the error correction step text data includes:
[0021] A reasoning text dataset is constructed based on each question text in the text dataset and its corresponding correct answer text and corresponding logical reasoning step text data; a correction text dataset is constructed based on each question text in the text dataset and its corresponding incorrect answer text and corresponding error correction step text data; a logical reasoning text dataset is generated based on the reasoning text dataset and the error correction text dataset.
[0022] In a fifth exemplary embodiment, the error correction step text data explaining the error cause of the wrong answer text includes:
[0023] An error prompt template is pre-constructed; the error prompt template includes a question text and a corresponding wrong answer text; the error prompt template is input into the first natural language model as prompt information, and the first natural language model generates error correction step text data that explains the error cause of the wrong answer text for the currently input question text according to a target tag generation method; wherein the target tag generation method is a tag corresponding to the maximum credibility increase when selecting a wrong answer compared to a wrong comparison answer.
[0024] In a sixth exemplary embodiment, the wrong comparison answer is a blank character, and the step of generating error correction step text data explaining the reason for the wrong answer text for the currently input question text in a target tag generation manner includes:
[0025] The error mark profit calculation formula is called to calculate the wrong answer profit of each mark; the error mark profit calculation formula is:
[0026] ;
[0027] In the formula, represents the wrong answer payoff for the ith mark, represents the i-th mark, represents the wrong answer text, P represents the probability, p represents the given context, q represents the question text, represents all the tags before the i-th tag, Indicates that the answer to an error comparison is a null character.
[0028] In a seventh exemplary embodiment, the step of generating error correction step text data for explaining the reason for the wrong answer text for the currently input question text in a target tag generation manner includes:
[0029] Based on the wrong answer benefits of each mark, the wrong mark selection relation is called to select the target wrong mark; the wrong mark selection relation is:
[0030] ;
[0031] In the formula, Represents the next token generated after the i-th token.
[0032] In an eighth exemplary implementation, the first natural language model is constructed based on a hybrid expert model, and includes a first hidden state layer, a group query attention layer, a gating network, a plurality of expert sub-models, and a second hidden state layer according to the data processing flow, and the second natural language model is a pre-trained language model that has completed the pre-training stage, and the second natural language model is trained using the logical reasoning text dataset, including:
[0033] The logical reasoning text dataset is used as a fine-tuning dataset; for the natural language processing task to be performed, the second natural language model is fine-tuned using the logical reasoning text dataset so that the second natural language model adapts to the natural language processing task to be performed and the logical reasoning text dataset.
[0034] In a ninth exemplary implementation, the training of the second natural language model using the logical reasoning text dataset includes:
[0035] The loss function relational formula is called, and the second natural language model is trained using the logical reasoning text data set; the loss function relational formula is:
[0036] ;
[0037] In the formula, represents the loss function, P represents the probability, represents the i-th token, q represents the question text, Represents all the tokens before the i-th token.
[0038] Another aspect of the present invention provides a method for executing a natural language processing task, comprising:
[0039] Obtain a target natural language model trained in advance using a natural language model training method as described in any of the preceding items, and deploy the target natural language model; obtain a problem text to be processed corresponding to a natural language processing task to be performed; input the problem text to be processed into the target natural language model, and use the predicted answer and logical reasoning content output by the target natural language model as the processing result of the natural language processing task to be performed.
[0040] The present invention also provides an electronic device, comprising a processor, wherein the processor is used to implement the steps of the natural language model training method as described in any of the preceding items and / or the steps of the natural language processing task execution method as described in the preceding items when executing the computer program stored in the memory.
[0041] The present invention also provides a non-volatile storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps of the natural language model training method as described in any of the preceding items and / or the steps of the natural language processing task execution method as described in the preceding items are implemented.
[0042] The present invention also provides a computer program product, including a computer program / instruction, which, when executed by a processor, implements the steps of the natural language model training method as described in any of the preceding items and / or the steps of the natural language processing task execution method as described in the preceding items.
[0043] Finally, the present invention also provides a mobile device, including a display screen, a model deployment processor and a task executor; the display screen includes a human-computer interaction interface; wherein the model deployment processor is used to deploy the target natural language model obtained according to the steps of natural language model training as described in any of the previous items; the human-computer interaction interface is used to receive the natural language processing task to be executed input by the user, and send the natural language processing task to be executed to the task executor; the task executor is used to call the natural language model, process the natural language processing task to be executed, obtain the predicted answer and the logical reasoning content, and send the predicted answer and the logical reasoning content to the human-computer interaction interface.
[0044] The technical solution provided by the present invention has the advantages that, by using a large-scale first natural language model as a teacher model and a small-scale second natural language model as a student model, the knowledge distillation of the first natural language model with a large number of parameters can be effectively performed to obtain a second natural language model with a parameter amount far smaller than the first natural language model, and the second natural language model is used to perform natural language processing tasks, effectively reducing the required computing resources and storage resources, thereby solving the problem of high computing cost and storage overhead of natural language processing tasks. For the questions in the text data set, the reasoning steps and error correction steps that are more consistent with the questions are generated, and these generated contents are used to train the second natural language model, so that the second natural language model has the step-by-step reasoning ability of the first natural language model, and achieves a student model with similar performance to the first natural language model in a specific natural language processing task to be performed, and the second natural language model learns the reasoning steps of the first natural language model, has strong reasoning and error correction capabilities, is particularly suitable for natural language processing tasks that require theoretical inference or logical calculation, and can effectively improve the execution accuracy of natural language processing tasks.
[0045] In addition, the present invention also provides a corresponding natural language processing task execution method, electronic device, non-volatile storage medium, computer program product and mobile device for the natural language model training method, which further makes the method more practical. The natural language processing task execution method, electronic device, non-volatile storage medium, computer program product and mobile device have corresponding advantages.
[0046] The technical features mentioned above, the technical features to be mentioned below, and the technical features shown separately in the drawings can be arbitrarily combined with each other, as long as the combined technical features are not contradictory. All feasible feature combinations are technical contents clearly recorded in this article. Any of the multiple sub-features contained in the same sentence can be applied independently, and does not have to be applied together with other sub-features. It should be understood that the above general description and the detailed description below are only exemplary and cannot limit the present invention. BRIEF DESCRIPTION OF THE DRAWINGS
[0047] In order to more clearly illustrate the technical solutions of the present invention or related technologies, the following briefly introduces the drawings required for use in the embodiments or related technical descriptions. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0048] Figure 1 A flow chart of a natural language model training method provided by the present invention;
[0049] Figure 2 An exemplary structural diagram of the first natural language model provided by the present invention;
[0050] Figure 3 A flowchart of another method for executing a natural language processing task provided by the present invention;
[0051] Figure 4 A structural diagram of a specific implementation of the natural language model training device provided by the present invention;
[0052] Figure 5 A structural diagram of a specific implementation of the natural language processing task execution device provided by the present invention;
[0053] Figure 6 A structural diagram of a specific implementation of an electronic device provided by the present invention;
[0054] Figure 7 A structural diagram of a specific implementation of the mobile device provided by the present invention. DETAILED DESCRIPTION
[0055] In order to make those skilled in the art better understand the technical solution of the present invention, the present invention is further described in detail below in conjunction with the accompanying drawings and specific embodiments. Among them, the terms first, second, third, fourth, etc. in the specification and the above-mentioned drawings are used to distinguish different objects, rather than to describe a specific order. In addition, the terms include and have and any variation of the two are intended to cover non-exclusive inclusions. The term exemplary means used as an example, embodiment or illustrative. Any embodiment described as exemplary here is not necessarily interpreted as being superior or better than other embodiments.
[0056] Natural language processing is to use computer technology to analyze, understand and process natural language with language as the object, to conduct quantitative research on language information with the support of computers, and to provide language descriptions that can be used by humans and computers. It includes NLU (Natural Language Understanding) and NLG (Natural Language Generation). Natural language models are widely used to perform natural language processing tasks. With the rapid development of artificial intelligence technology, the scale of natural language models is getting larger and larger, and the computing resources and storage resources required are also increasing. As a result, the deployment and use of models need to be limited to devices with sufficient computing resources and storage resources. Devices with limited resources such as edge devices, embedded systems, and mobile devices cannot be deployed and used, and are not very practical. Furthermore, due to its huge number of parameters, it requires a lot of computing resources and cannot be applied in real-time scenarios that require fast reasoning. In order to solve this problem, knowledge distillation is used to provide an effective compression method for large-scale natural language models, making it easier to integrate into practical applications while maintaining high performance.
[0057] Among them, knowledge distillation (also known as knowledge distillation) is to train a small student model to imitate the behavior of a large teacher model, so that the student model can achieve similar accuracy on specific downstream tasks, so that the small student model has the performance of the large model, and the computing and storage requirements of the model are reduced while maintaining performance. Related technologies When performing knowledge distillation on a large natural language model, first create or select a student model that has been pre-trained and has a much smaller number of parameters than the given teacher model, prepare a data set related to the downstream task, such as GSM8K (training set name), etc., use the teacher model to infer the questions in the data set, output soft labels, usually the probability distribution of the output layer, and then use the data and soft labels in the data set to fine-tune the student model, while optimizing the distillation loss and the standard fine-tuning loss. However, because traditional knowledge distillation does not focus on how the teacher model reaches the final decision through a series of logical steps, but only focuses on the final prediction probability, it will ignore the intermediate information of the teacher model during the reasoning process, which leads to the lack of deep reasoning ability of the student model. In addition, in some complex logical reasoning tasks, such as solving math problems, simply imitating the output probability distribution of the teacher model may not be enough to make the student model achieve performance matching that of the teacher model, resulting in poor execution accuracy of the final natural language processing task and failure to meet user needs.
[0058] In view of this, the present invention is based on the CoT (Chain of Thought) reasoning method, and uses the teacher model to generate complete reasoning steps and error correction steps for the problem text in the text data set, and uses these generated contents to fine-tune the student model, so that the student model can achieve performance similar to that of the teacher model when performing specific natural language processing tasks, which not only meets the execution accuracy requirements of natural language processing tasks, but also facilitates deployment and use, and solves the problem that large-scale teacher models are difficult to deploy or too expensive to use in some application scenarios. After introducing the technical solution of the present invention, various non-limiting embodiments of the present invention are described in detail below. In order to better illustrate the present invention, numerous specific details are given in the specific embodiments below. Those skilled in the art should understand that the present invention can also be implemented without these specific details. In other examples, methods, means, components and circuits well known to technicians in the field are not described in detail to highlight the main purpose of the present invention.
[0059] First see Figure 1 , Figure 1 A flowchart of a method for executing a natural language processing task provided in this embodiment may include the following contents:
[0060] S101: Obtain a first natural language model, a second natural language model, and a text data set corresponding to a natural language processing task to be performed.
[0061] In this embodiment, the first natural language model is a large language model, and the number of parameters of the first natural language model is at least hundreds of millions, billions, tens of billions, hundreds of billions or even trillions, and the second natural language model is a small language model, and the number of parameters of the second natural language model is, for example, in the millions, or in the hundreds of millions or billions, but the model parameter amount of the second natural language model is smaller than the model parameter amount of the first natural language model, and the difference between the model parameter amount of the second natural language model and the model parameter amount of the first natural language model is at least greater than two orders of magnitude, wherein the data level generally refers to the order of magnitude, that is, the number of digits of the value. For example, the number of parameters of the first natural language model is billions, while the number of parameters of the second natural language model is millions, billions generally refers to a value between 1 billion and 9.9 billion, and millions generally refers to a value between 1 million and 9.99 million. For example, 1 million is a 6-digit number, and 100 million is a 9-digit number. Therefore, if the lower limit of billions is 1 billion (9 digits) and the upper limit of millions is 9.99 million (6 digits), the difference between the two is 3 data levels. If the upper limit of billions is 9.9 billion (9 digits) and the lower limit of millions is 1 million (6 digits), the difference between the two is 3 data levels. The first natural language model and the second natural language model can adopt any neural network model with natural language processing capability, and the present invention does not make any limitation on this.
[0062] Among them, the natural language processing task to be performed is for a specific application scenario or a specific downstream task, including but not limited to common sense reasoning, educational guidance, automatic programming and other tasks that require step-by-step reasoning or interpretability. In other words, the natural language processing task processed by the natural language model targeted by the present invention can be any generation task related to logical reasoning, such as answering math problems, doing English reading comprehension, multiple-choice questions or programming. The text data set corresponds to the natural language processing task to be performed. For example, when the natural language processing task to be performed is a code writing task, the text sample data set can use a code-related data set similar to humeneval (data set name), and when the natural language processing task to be performed is a task of calculating elementary school math problems, the text sample data set can use a data set similar to gsm8k (data set name). The text data set is used to generate reasoning samples for the second natural language model and evaluate the performance of the second natural language model. The reasoning sample, that is, the logical reasoning text data set of the subsequent step, is a training sample set for training the second natural language model, so that the second natural language model has the step-by-step reasoning ability of the first natural language model and achieves the closest performance to the first natural language model in the natural language processing task to be performed. The text data set may include multiple text samples, each of which includes at least a question text and a corresponding correct answer text and an incorrect answer text, that is, each text sample is a text-like data, and each text sample is a group of data of a question+answer combination. Exemplarily, a text data set including a question text-correct answer file may be first obtained, and an incorrect answer text may be created for each question text by an artificial method or a script method or by using a natural language model, and a corresponding relationship may be established for the text. Of course, a data set in which each question text has a correct answer text and an incorrect answer text may also be directly obtained, which does not affect the implementation of the present invention. In short, the text data sets are all text-like data, and each piece of data is a combination of a question+answer, and the answer includes both a correct answer and an incorrect answer.
[0063] S102: Using the first natural language model to process each text data of the text data set, generate logical reasoning step text data for obtaining a correct answer text based on the question text, and error correction step text data for explaining the error cause of an incorrect answer text.
[0064] In this step, the logical reasoning step text data is used to explain the reasoning process data of why the correct answer text is the correct answer to the corresponding question text, and the error correction step text data is used to explain the reasoning process data of why the wrong answer text is not the correct answer to the corresponding question text. The first natural language model has language understanding ability. By prompting the first natural language model, the input question text is parsed, and the predicted answer consistent with the corresponding correct answer text is obtained. The answer parsing process is the logical reasoning step text data of the question text. By prompting the first natural language model, the input question text and the wrong answer text are parsed, and the parsing process of analyzing that the wrong answer text is not the correct answer to the question text is the error correction step text data.
[0065] S103: Generate a logical reasoning text data set based on the text data set, the logical reasoning step text data and the error correction step text data.
[0066] When a user selects or creates a text dataset containing questions and correct answers, and uses the first natural language model to generate a text sequence containing multi-step reasoning explanations for each question text in the text dataset, that is, after obtaining the logical reasoning step text data and error correction step text data corresponding to each text sample in the text dataset, a logical reasoning text dataset can be constructed based on each text sample and its corresponding logical reasoning step text data and error correction step text data. The logical reasoning text dataset is used as a training sample for training the second natural language model, so that the second natural language model can learn and imitate the reasoning process of the first natural language model.
[0067] S104: Train the second natural language model using the logical reasoning text data set, so as to perform a natural language processing task using the trained second natural language model.
[0068] This embodiment can adopt any deep learning model training method to train the second natural language model based on the logical reasoning text data set until the second natural language model converges or reaches a preset number of iterations or the model accuracy reaches a preset accuracy threshold, such as 98%. The trained second natural language model gradually acquires the reasoning and error correction capabilities of the first natural language model. Although the first natural language model has powerful performance, its parameter volume is usually large. For example, in mobile devices or edge computing scenarios, there are problems such as excess performance and difficulty in deployment. When the trained second natural language model has similar performance, due to the small number of parameters, its training and deployment costs are relatively low, which is more suitable for application scenarios with limited resources or real-time requirements, including mobile applications, smart home devices, embedded systems, online customer service, social media analysis, educational tools, medical consultation, legal consultation, financial analysis and content generation.
[0069] In order to obtain good natural language model training results, the logical reasoning text dataset obtained in the above process can be divided into training set, test set, and validation set according to a certain ratio. For example, 70% can be used to train the second natural language model, 20% can be used as an independent test set to evaluate the performance of the second natural language model, and 10% can be used to verify the performance of the second natural language model to ensure that it meets the required standards. Then, the text data of the logical reasoning text dataset can be segmented through rule-based and statistical-based word segmentation methods, and each text sample data can be converted into a form that the natural language model can understand. For example, the sentence list can be converted into a number list through one-hot encoding and word-embedding encoding.
[0070] In the technical solution provided in this embodiment, a large-scale first natural language model is used as a teacher model, and a small-scale second natural language model is used as a student model, which can effectively perform knowledge distillation on the first natural language model with a large number of parameters, and obtain a second natural language model with a parameter amount far smaller than the model. The second natural language model is used to perform natural language processing tasks, effectively reducing the required computing resources and storage resources, thereby solving the problem of high computing cost and storage overhead of natural language processing tasks. For the questions in the text data set, reasoning steps and error correction steps that are more consistent with the questions are generated, and these generated contents are used to train the second natural language model, so that the second natural language model has the step-by-step reasoning ability of the first natural language model, and achieves a student model with similar performance to the first natural language model in a specific natural language processing task to be performed. In addition, the second natural language model has learned the reasoning steps of the first natural language model, has strong reasoning and error correction capabilities, and is particularly suitable for natural language processing tasks that require theoretical inference or logical calculations, and can effectively improve the execution accuracy of natural language processing tasks.
[0071] In the above embodiment, there is no limitation on how to generate the logical reasoning step text data. Based on the above embodiment, the present invention also provides an exemplary implementation method of obtaining the logical reasoning step text data of the correct answer text based on the question text, which may include the following contents:
[0072] A positive prompt template is pre-built; the positive prompt template includes a question text and its corresponding correct answer text; the positive prompt template is used as prompt information and input into the first natural language model, and the first natural language model generates logical reasoning step text data consistent with the corresponding correct answer text for the currently input question text according to the target tag generation method. The target tag generation method is to select the tag corresponding to the maximum credibility increase when the correct answer is compared with the correct comparative answer, the correct comparative answer is the comparative answer set for the correct answer, and the target tag generation method is that the tag when the credibility increase when considering the correct answer compared with the comparative answer is the largest is the selected target tag.
[0073] In this embodiment, in order to improve the reasoning ability of the second natural language model, this embodiment is based on the CoT idea. Before giving the final answer, the model generates a series of intermediate reasoning steps. These steps describe in detail how the model starts from the question and reaches the answer through logical reasoning. The logical reasoning step text data is one or more intermediate steps generated, which show the reasoning process from the input question text to the correct answer. The logical reasoning step text data can help the model gradually simplify the problem until the answer is obtained, and enhance the interpretability of the answer. If the text data set is a data set with reasoning steps such as GSM8K, the few-shot method can be used to generate reasoning steps to increase the accuracy of the generated reasoning steps.
[0074] This embodiment first constructs a prompt template, which is defined as a correct prompt template for ease of description. It includes a question text and its corresponding correct answer. In order to allow the first natural language model to generate reasoning steps that are more consistent with the correct answer, the credibility increase of each tag, i.e., token, when considering the correct answer compared to the specified correct comparison answer can be calculated. The correct comparison answer can be, for example, an empty character. The larger the increase, the stronger the correlation between the current token and the correct answer, that is, the more the generated reason supports the correct answer. Exemplarily, the first probability information of the i-th tag can be calculated based on the current input question sample, the correct answer sample, the given context, and all the previously generated tags. Then, the second probability information of the i-th tag can be calculated based on the current input question sample, the correct comparison answer, the given context, and all the previously generated tags. The difference between the first probability information and the second probability information is the credibility increase of each tag, i.e., token, when considering the correct answer compared to the specified comparison answer. After obtaining the credibility growth of the current tag, the next tag is generated by maximizing the probability information of the i-th tag based on the credibility increment and the current input question sample, the correct answer sample, the given context, and all previously generated tags. Continuous calculations are performed to obtain detailed reasoning results.
[0075] As an efficient way to generate text data of logical reasoning steps, the correct marked benefit calculation formula and the correct marked selection formula can be stored locally in advance, and the correct marked benefit calculation formula can be called , calculate the correct answer benefit for each tag. Based on the correct answer benefit for each tag, call the correct tag selection relation Select the target correctly marked.
[0076] In this embodiment, It represents the correct answer benefit of the ith token, which is the difference between the logarithms of the two probabilities. The distribution of probabilities determines the next token generated by the first natural language model. The larger the value, the stronger the correlation between the generated token and the correct answer, that is, the greater the probability of its selection. represents the i-th mark, represents the correct answer text, P represents the probability, p represents the given context, q represents the question text, It represents all the tokens before the i-th token. It is a shorthand way of writing and represents the tokens before the i-th token. , Indicates the correct comparison case is a null character. Represents a given context p, question q, and correct answer , the token generated previously In the case of probability. Replace the correct answer with the correct comparative answer , represents the given context p, prompt q, comparison answer, previously generated token In the case of By calculating the logarithmic difference of these two probabilities, we can get the token The amount of confidence increase when considering the correct answer compared to when considering the empty string. The greater the confidence increase, the more likely the token The stronger the correlation with the correct answer, the more the generated reasons support the correct answer. Indicates the next token generated after the i-th token, that is, the first natural language model generates the next token after the given token. The next token that should be generated afterwards. Exemplarily, the comparison character is a null character. In this embodiment, the comparison answer is set to a null character, which can penalize tokens that generally look credible when not considering the correct answer, because these tokens may not be specific to the correct answer.
[0077] As can be seen from the above, this embodiment uses the first natural language model to generate complete reasoning steps for the question text in the text data set according to a specific token generation strategy, which is conducive to achieving the second natural language model to achieve performance similar to that of the first natural language model. The text data through logical reasoning steps can help the model gradually simplify the problem until the answer is obtained, and enhance the interpretability of the answer. By setting the comparison answer to blank characters, the accuracy of the output result can be further improved.
[0078] In the above embodiment, there is no limitation on how to generate the error correction step text data. Based on the above embodiment, the present invention also provides an exemplary implementation method of explaining the error cause of the wrong answer text to generate the error correction step text data, which may include the following contents:
[0079] An error prompt template is pre-built; the error prompt template includes a question text and its corresponding wrong answer text; the error prompt template is used as prompt information and input into the first natural language model, and the first natural language model generates error correction step text data for the currently input question text that explains the error cause of the wrong answer text according to the target tag generation method. The target tag generation method is to select a tag corresponding to the maximum credibility increase when the wrong answer is compared with the wrong comparative answer, the wrong comparative answer is the comparative answer set for the wrong answer, and the target tag generation method is to select the tag when the credibility increase when the wrong answer is considered to be the largest when the wrong comparative answer is considered.
[0080] In this embodiment, in order to improve the task execution accuracy of the second natural language model, this embodiment further corrects the wrong answers so that the second natural language model has the ability to correct errors. Before giving the final answer, the first natural language model of this embodiment also generates a series of intermediate reasoning steps. These steps detail how the model starts from the problem and determines the reason why the wrong answer is wrong through logical reasoning. Each step is a logically coherent statement, which together constitute a complete reasoning process. The text data of the error correction step can help the model gradually simplify the problem until the answer is obtained, and enhance the interpretability of the answer.
[0081] This embodiment first constructs a prompt template, which is defined as an error prompt template for ease of description. It includes a question text and its corresponding wrong answer. In order to allow the first natural language model to more accurately analyze the reasoning steps of the wrong answer, the credibility increase of each tag, i.e., token, when considering the wrong answer compared to the specified wrong comparison answer can be calculated. The wrong comparison answer can be, for example, an empty character. The larger the increase, the stronger the correlation between the current token and the wrong answer, that is, the more the generated reason supports the wrong answer. Exemplarily, the first probability information of the i-th tag can be calculated first under the current input question sample, the wrong answer sample, the given context, and all the previously generated tags. Then, the second probability information of the i-th tag can be calculated under the current input question sample, the comparison answer, the given context, and all the previously generated tags. The difference between the first probability information and the second probability information is the credibility increase of each tag, i.e., token, when considering the wrong answer compared to the specified comparison answer. After obtaining the credibility growth of the current tag, the next tag is generated by generating the maximum value of the probability information of the i-th tag based on the credibility increment and the current input question sample, the wrong answer sample, the given context, and all the previously generated tags. The calculation is continued to obtain the error correction step text data.
[0082] As an efficient way to generate text data for error correction steps, the error mark benefit calculation formula and the error mark selection formula can be stored locally in advance, and the error mark benefit calculation formula can be called , calculate the wrong answer benefit for each tag. Based on the wrong answer benefit for each tag, call the wrong tag selection relation Select the target error marker.
[0083] In the formula, represents the wrong answer payoff for the ith mark, represents the i-th mark, represents the wrong answer text, P represents the probability, p represents the given context, q represents the question text, represents all the tags before the i-th tag, Indicates that the answer to an error comparison is a null character. Indicates the next token generated after the i-th token. That is, the first natural language model generates the next token after a given token. The next token that should be generated afterwards.
[0084] From the above, it can be seen that this embodiment uses the first natural language model to generate complete error correction steps for the question text in the text data set according to a specific token generation strategy, which is conducive to achieving the second natural language model to achieve performance similar to that of the first natural language model. The error correction step text data can help the model gradually simplify the problem until the answer is obtained, and enhance the interpretability of the answer.
[0085] Exemplarily, as a simple logical reasoning text dataset construction method, the present invention also provides the following exemplary logical reasoning text dataset construction method, which may include the following contents:
[0086] According to each question text in the text data set and its corresponding correct answer text and corresponding logical reasoning step text data, a reasoning text data set is constructed, and the reasoning text data set has reasoning ability; according to each question text in the text data set and its corresponding incorrect answer text and corresponding error correction step text data, an error correction text data set is constructed, and the error correction text data set has error correction ability; a logical reasoning text data set is generated according to the reasoning text data set and the error correction text data set.
[0087] From the above, it can be seen that this embodiment constructs two data sets from the reasoning perspective and the error correction perspective respectively, and then combines these data into training examples to construct a fine-tuning data set, which is conducive to training a second natural language model that has both reasoning and error correction capabilities.
[0088] The above embodiment does not limit the structure of the first natural language model and the second natural language model. This embodiment also provides an exemplary network model structure of the first natural language model and the second natural language model, which may include the following contents:
[0089] The first natural language model is built based on a hybrid expert model, a single-layer network structure such as Figure 2 The method comprises a first hidden state layer, a group query attention layer, a gated network, a plurality of expert sub-models and a second hidden state layer respectively according to the data processing flow. The second natural language model is a pre-trained language model that completes the pre-training stage. Accordingly, the process of training the second natural language model using the logical reasoning text dataset comprises: using the logical reasoning text dataset as a fine-tuning dataset; and fine-tuning the second natural language model using the logical reasoning text dataset for the natural language processing task to be performed, so that the second natural language model adapts to the natural language processing task to be performed and the logical reasoning text dataset.
[0090] In this embodiment, MoE (Mixture of Experts) combines multiple expert models (Experts), such as Figure 2As shown, it may include patent sub-model 1, expert sub-model 2, expert sub-model 3, and expert sub-model 4 to process data and tasks. Each expert sub-model may be a feedforward neural network with independent parameters. In the actual application process, the number of expert sub-models and the number of experts assigned to each input can be flexibly adjusted as needed. By combining different neural network experts to process different parts of the input data, the performance and efficiency of the model can be improved. In the first natural language model, each expert sub-model is used to focus on processing a specific type of data or task, and the gating network is used to determine which expert sub-model should process a given input. The first natural language model only activates the expert sub-model most relevant to the current task during reasoning. This sparse activation mechanism enables it to increase the learnable parameters of the model without increasing the cost of reasoning, thereby increasing the capacity of the model. In the single-layer model structure of the first natural language model, the first hidden state layer input is a hidden state, which may be the output from the previous layer or the encoded input data. First, the input hidden states are grouped through the GQA layer (Group Query Attention), and the self-attention mechanism is applied within each group. Then, weights are assigned to each expert sub-model (Expert) through the gating layer. Each input vector is assigned to 2 of the 4 experts. Each expert receives weighted input from the gating layer and processes these inputs independently. Finally, the output of the second hidden state layer is the weighted sum of the outputs of the two selected expert models. The second natural language model can be initialized or a small language model can be selected according to demand. In order to improve the training efficiency of the subsequent second natural language model, the second natural language model can use a pre-trained language model. Such a second natural language model has basic language understanding capabilities, which is convenient for subsequent fine-tuning.
[0091] As can be seen from the above, the first natural language model of this embodiment effectively improves the performance and efficiency of the first natural language model by processing different parts of the input data with different sub-expert models, and only activates the expert sub-model most relevant to the current task during reasoning. This sparse activation mechanism allows it to increase the learnable parameters of the model without increasing the reasoning cost, thereby increasing the capacity of the model. The second natural language model uses a pre-trained natural language model, which has basic language understanding capabilities and can effectively improve the training efficiency and training performance of the second natural language model.
[0092] Furthermore, the loss function can be used to quantify the difference between the predicted value and the actual value of the natural language model, which can be used as a standard to measure the performance of the natural language model. In addition, during the training process, the value of the loss function is used to calculate the gradient, which indicates how the model parameters should be updated to reduce the prediction error. By minimizing the loss function, the natural language model can learn the patterns and features in the data, thereby better guiding the model training. In addition, a suitable loss function can also avoid overfitting of the natural language model. Based on this, in order to improve the training performance of the second natural language model, obtain a second natural language model with better performance, and improve the execution accuracy of the natural language processing task, based on the above embodiment, the present invention also provides an exemplary loss function selection method for the second natural language model in the fine-tuning process, which may include the following:
[0093] The loss function relationship is called and the second natural language model is trained using the logical reasoning text dataset; the loss function relationship can be expressed as:
[0094] ;
[0095] In the formula, represents the loss function, P represents the probability, represents the i-th token, q represents the question text, Represents all the tokens before the i-th token.
[0096] Based on the above embodiments, the present invention also provides a method for executing a natural language processing task. Figure 3 , which may include the following:
[0097] S301: Acquire a target natural language model and deploy the target natural language model.
[0098] A second natural language model is trained in advance using the natural language model training method steps described in any of the above embodiments. For the sake of ease of description, the second natural language model applied to the actual task is defined as a target natural language model. The target natural language model can achieve reasoning performance equivalent to that of the first natural language model in a specific downstream task, i.e., the natural language processing task to be performed in the present invention, has a stronger step-by-step reasoning capability, and requires less storage and computing resources.
[0099] S302: Obtain the problem text to be processed corresponding to the natural language processing task to be executed.
[0100] Among them, the natural language processing tasks to be processed include but are not limited to downstream tasks that are particularly suitable for theoretical inference or logical calculation, such as algorithm explanation video content understanding and classification tasks, algorithm explanation video subtitle generation and translation tasks, and math question and answer tasks. Among them, the algorithm explanation video content understanding and classification tasks refer to the use of natural language models to understand the algorithm video content and classify it into different algorithm categories. The algorithm explanation video subtitle generation and translation task is to use natural language models to understand video content and dialogues and automatically generate subtitles. The math question and answer task refers to the use of natural language models to understand the content of math problems and answer the corresponding calculation results, such as interactive learning on education platforms.
[0101] S303: Input the question text to be processed into the target natural language model, and use the predicted answer and logical reasoning content output by the target natural language model as the processing result of the natural language processing task to be executed.
[0102] By displaying the reasoning process, the output answer of the target natural language model can be made explainable, so that users can understand how the target natural language model arrives at a specific answer.
[0103] As can be seen from the above, this embodiment effectively improves the execution accuracy of natural language processing tasks and obtains more accurate answers on the basis of solving the high computational cost and storage overhead of natural language processing tasks. By showing the reasoning process, users can understand how the model obtains a specific answer, enhancing the interpretability of the predicted answer.
[0104] It should be noted that there is no strict order of execution between the steps in the present invention. As long as they comply with the logical order, these steps can be executed simultaneously or in a certain preset order. Figure 1 and Figure 3 This is just a schematic and does not mean that this is the only execution order.
[0105] The present invention also provides corresponding devices for natural language model training methods, natural language processing task execution methods and model training methods, further making the methods more practical. Among them, the devices can be described from the perspective of functional modules and hardware. The natural language model training device, natural language processing task execution device and model training device provided by the present invention are introduced below. The device is used to implement the corresponding method provided by the present invention. In this embodiment, the natural language model training device, natural language processing task execution device and model training device may include or be divided into one or more program modules, which are stored in a storage medium and executed by one or more processors to complete the method steps disclosed in the embodiment. The program module referred to in this embodiment refers to a series of computer program instruction segments that can complete specific functions, which is more suitable for describing the execution process of the natural language model training device, natural language processing task execution device and model training device in the storage medium than the program itself. The following description will specifically introduce the functions of each program module of this embodiment. The natural language model training device described below and the natural language model training method described above, the natural language processing task execution device and the natural language processing task execution method described above, and the model training device and the model training method described above can be referred to each other.
[0106] From the perspective of functional modules, see Figure 4 , Figure 4 The structure diagram of the natural language model device provided in this embodiment under an exemplary implementation manner, the device may include:
[0107] The data set acquisition module 401 is used to obtain the text data set corresponding to the first natural language model, the second natural language model and the natural language processing task to be performed; each text sample of the text data set includes a question text and a corresponding correct answer text and an incorrect answer text; wherein the model parameter amount of the second natural language model is smaller than the model parameter amount of the first natural language model, and the parameter amount difference between the model parameter amount of the second natural language model and the model parameter amount of the first natural language model is at least greater than two orders of magnitude.
[0108] The intermediate step generation module 402 is used to use the first natural language model to process each text data of the text data set, generate logical reasoning step text data for obtaining the correct answer text based on the question text, and error correction step text data for explaining the error reasons of the wrong answer text.
[0109] The reasoning text data set generation module 403 is used to generate a logical reasoning text data set based on the text data set, the logical reasoning step text data and the error correction step text data.
[0110] The model training and task execution module 404 is used to train the second natural language model using the logical reasoning text data set, so as to execute the natural language processing task using the trained second natural language model.
[0111] Exemplarily, in some implementations of this embodiment, the intermediate step generation module 402 may also be used to:
[0112] A positive prompt template is constructed in advance; the positive prompt template includes a question text and its corresponding correct answer text; the positive prompt template is input into the first natural language model as prompt information, and the first natural language model generates logical reasoning step text data consistent with the corresponding correct answer text for the currently input question text according to a target tag generation method; wherein the target tag generation method is a tag corresponding to the maximum credibility increase when selecting the correct answer compared to the correct comparison answer.
[0113] As an exemplary implementation of the above embodiment, the above intermediate step generation module 402 may be further used for:
[0114] Call the correct mark profit calculation formula to calculate the correct answer profit of each mark; the correct mark profit calculation formula is:
[0115] ;
[0116] In the formula, represents the correct answer benefit for the ith mark, represents the i-th mark, represents the correct answer text, P represents the probability, p represents the given context, q represents the question text, represents all the tags before the i-th tag, Indicates that the correct comparison answer is a blank character.
[0117] As an exemplary implementation of the above embodiment, the above intermediate step generation module 402 may be further used for:
[0118] Based on the correct answer benefits of each tag, the correct tag selection formula is called to select the target correct tag; the correct tag selection formula is:
[0119] ;
[0120] In the formula, Represents the next token generated after the i-th token.
[0121] Exemplarily, in some other implementations of this embodiment, the above-mentioned inference text data set generation module 403 can also be used for:
[0122] According to each question text in the text data set and its corresponding correct answer text and corresponding logical reasoning step text data, a reasoning text data set is constructed; according to each question text in the text data set and its corresponding incorrect answer text and corresponding error correction step text data, a correction text data set is constructed; according to the reasoning text data set and the correction text data set, a logical reasoning text data set is generated.
[0123] Exemplarily, in some other implementations of this embodiment, the intermediate step generation module 402 may also be used to:
[0124] An error prompt template is pre-built; the error prompt template includes a question text and its corresponding wrong answer text; the error prompt template is input into the first natural language model as prompt information, and the first natural language model generates error correction step text data that explains the error cause of the wrong answer text for the currently input question text according to the target tag generation method.
[0125] As an exemplary implementation of the above embodiment, the above intermediate step generation module 402 may be further used for:
[0126] Call the error mark profit calculation formula to calculate the wrong answer profit of each mark; the error mark profit calculation formula is:
[0127] ;
[0128] In the formula, represents the wrong answer payoff for the ith mark, represents the i-th mark, represents the wrong answer text, P represents the probability, p represents the given context, q represents the question text, represents all the tags before the i-th tag, Indicates that the answer to an error comparison is a null character.
[0129] As an exemplary implementation of the above embodiment, the above intermediate step generation module 402 may be further used for:
[0130] Based on the wrong answer benefits of each mark, the error mark selection relation is called to select the target error mark; the error mark selection relation is:
[0131] ;
[0132] In the formula, Represents the next token generated after the i-th token.
[0133] Exemplarily, in some other implementations of this embodiment, the above-mentioned model training and task execution module 404 can also be used for:
[0134] The first natural language model is constructed based on the hybrid expert model, and includes a first hidden state layer, a group query attention layer, a gating network, multiple expert sub-models, and a second hidden state layer according to the data processing flow. The second natural language model is a pre-trained language model that completes the pre-training stage, and uses the logical reasoning text dataset as the fine-tuning dataset; for the natural language processing task to be performed, the second natural language model is fine-tuned using the logical reasoning text dataset to make the second natural language model adapt to the natural language processing task to be performed and the logical reasoning text dataset.
[0135] Exemplarily, in some other implementations of this embodiment, the above-mentioned model training and task execution module 404 can also be used for:
[0136] The loss function relationship is called and the second natural language model is trained using the logical reasoning text dataset; the loss function relationship is:
[0137] ;
[0138] In the formula, represents the loss function, P represents the probability, represents the i-th token, q represents the question text, Represents all the tokens before the i-th token.
[0139] From the perspective of functional modules, see Figure 5 , Figure 5 The structure diagram of the natural language processing task execution device provided in this embodiment under an exemplary implementation manner, the device may include:
[0140] The model training and deployment module 501 is used to obtain a pre-utilized natural language model training method, train a target natural language model, and deploy the target natural language model.
[0141] The input data acquisition module 502 is used to obtain the problem text to be processed corresponding to the natural language processing task to be performed.
[0142] The task execution module 503 is used to input the question text to be processed into the target natural language model, and use the predicted answer and logical reasoning content output by the target natural language model as the processing result of the natural language processing task to be executed.
[0143] The functions of the various functional modules of the natural language processing task execution device of this embodiment can be specifically implemented according to the method in the above-mentioned method embodiment. The specific implementation process can refer to the relevant description of the above-mentioned method embodiment, which will not be repeated here.
[0144] From the above, it can be seen that this embodiment, while solving the high computational cost and storage overhead of natural language processing tasks, effectively improves the execution accuracy of natural language processing tasks and obtains more accurate answers.
[0145] The natural language model training device and natural language processing task execution device mentioned above are described from the perspective of functional modules. Furthermore, the present invention also provides an electronic device, which is described from the perspective of hardware. Figure 6 The following is a schematic diagram of the structure of an electronic device provided by an embodiment of the present invention in one implementation manner. Figure 6 As shown, the electronic device includes a memory 60 for storing computer programs; a processor 61 for implementing the steps of the natural language model training method and / or the natural language processing task execution method mentioned in any of the above embodiments when executing the computer program.
[0146] Among them, the processor 61 may include one or more processing cores, such as a 4-core processor, an 8-core processor, and the processor 61 may also be a controller, a microcontroller, a microprocessor or other data processing chip. The processor 61 may be implemented in at least one hardware form of DSP (Digital Signal Processing), FPGA (Field-Programmable Gate Array), and PLA (Programmable Logic Array). The processor 61 may also include a main processor and a coprocessor. The main processor is a processor for processing data in the awake state, also known as a CPU (Central Processing Unit); the coprocessor is a low-power processor for processing data in the standby state. In some embodiments, the processor 61 may be integrated with a GPU (Graphics Processing Unit), which is responsible for rendering and drawing the content to be displayed on the display screen. In some embodiments, the processor 61 may also include an AI (Artificial Intelligence) processor, which is used to process computing operations related to machine learning.
[0147] The memory 60 may include one or more computer-readable storage media, which may be non-transitory. The memory 60 may also include high-speed random access memory and non-volatile memory, such as one or more disk storage devices and flash memory storage devices. In some embodiments, the memory 60 may be an internal storage unit of an electronic device, such as a hard disk of a server. In other embodiments, the memory 60 may also be an external storage device of an electronic device, such as a plug-in hard disk equipped on a server, a smart memory card (Smart Media Card, SMC), a secure digital (SecureDigital, SD) card, a flash card (Flash Card), etc. Further, the memory 60 may also include both an internal storage unit of an electronic device and an external storage device. The memory 60 can not only be used to store application software and various types of data installed in the electronic device, such as: the code of the program in the process of executing the natural language model training method and / or the natural language processing task execution method, but also can be used to temporarily store data that has been output or is to be output. In this embodiment, the memory 60 is at least used to store the following computer program 601, wherein, after the computer program is loaded and executed by the processor 61, it can implement the relevant steps of the natural language model training method and / or the natural language processing task execution method disclosed in any of the aforementioned embodiments. In addition, the resources stored in the memory 60 may also include an operating system 602 and data 603, etc., and the storage method may be temporary storage or permanent storage. Among them, the operating system 602 may include Windows, Unix, Linux, etc. The data 603 may include but is not limited to data corresponding to the natural language model training results and / or the natural language processing task execution results, etc.
[0148] In some embodiments, the electronic device may further include a display screen 62, an input / output interface 63, a communication interface 64 or a network interface, a power supply 65 and a communication bus 66. Among them, the display screen 62 and the input / output interface 63, such as a keyboard, belong to the user interface, and exemplary user interfaces may also include standard wired interfaces, wireless interfaces, etc. Optionally, in some embodiments, the display may be an LED display, a liquid crystal display, a touch-sensitive liquid crystal display, and an OLED (Organic Light-Emitting Diode) touch device, etc. The display may also be appropriately referred to as a display screen or a display unit, which is used to display information processed in the electronic device and to display a visual user interface. The communication interface 64 may exemplarily include a wired interface and / or a wireless interface, such as a WI-FI interface, a Bluetooth interface, etc., which are generally used to establish a communication connection between the electronic device and other electronic devices. The communication bus 66 may be a peripheral component interconnect (PCI) bus or an extended industry standard architecture (EISA) bus, etc. The bus may be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 6 Only one thick line is used in the diagram, but this does not mean that there is only one bus or only one type of bus.
[0149] Those skilled in the art will understand that Figure 6 The structure shown in the figure does not constitute a limitation on the electronic device, and may include more or fewer components than those shown in the figure, for example, it may also include a sensor 67 for realizing various functions.
[0150] It is understandable that if the natural language processing model training method, the natural language processing task execution method and the model training method in the above-mentioned embodiment are implemented in the form of a software functional unit and sold or used as an independent product, they can be stored in a non-volatile storage medium. Based on such an understanding, the technical solution of the present invention is essentially or the part that contributes to the relevant technology or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium to execute all or part of the steps of the methods of each embodiment of the present invention. The aforementioned storage medium includes but is not limited to: U disk, mobile hard disk, read-only memory (Read-Only Memory, ROM), random access memory (Random Access Memory, RAM), electrically erasable programmable ROM, register, hard disk, multimedia card, card-type memory (such as SD or DX memory, etc.), magnetic memory, removable disk, CD-ROM, magnetic disk or optical disk, etc. Various media that can store program codes. Based on this, the present invention also provides a non-volatile storage medium on which a computer program is stored, and when the computer program is executed by a processor, the steps of the natural language model training method and / or the natural language processing task execution method recorded in any of the above embodiments are performed.
[0151] It is understandable that if the natural language processing model training method, natural language processing task execution method and model training method in the above embodiments are implemented in the form of software functional units and sold or used as independent products, the computer software product may not need to be stored in a physical storage medium. For example, it can be directly transmitted to a computer or other device with information processing capabilities through a wired network or a wireless network to execute all or part of the steps of the methods of each embodiment of the present invention. Based on this understanding, the technical solution of the present invention is essentially or the part that contributes to the relevant technology or all or part of the technical solution can be embodied in the form of a software product. Based on this, the present invention also provides a computer program product storing a computer program. When the computer program is executed by a processor, the steps of the natural language model training method and / or the natural language processing task execution method recorded in any of the above embodiments are performed.
[0152] The present invention also provides a mobile device, such as Figure 7 As shown, it may include a display screen 71, a model deployment processor 72 and a task executor 73; the mobile device may be, for example, a computing device such as a mobile phone or a tablet computer with poor computing resources and storage resources.
[0153] Among them, the display screen 71 may include a human-computer interaction interface; a model deployment processor 72, used to deploy the steps of the natural language model training method recorded in any of the above embodiments to obtain a second natural language model; the human-computer interaction interface, used to receive the natural language processing task to be executed input by the user, and send the natural language processing task to be executed to the task executor 73; the task executor 73, used to call the natural language model, process the natural language processing task to be executed, obtain the natural language processing task processing result, that is, the predicted answer and the logical reasoning content, and send the natural language processing task processing result to the human-computer interaction interface.
[0154] In addition, the present invention also provides an embedded system, which may include an embedded microprocessor; the embedded microprocessor is used to deploy the steps of the natural language model training method recorded in any of the above embodiments to obtain a second natural language model. After the deployment is completed, after receiving the natural task to be processed through the human-computer interaction interface, the natural language model is called to process the natural language processing task to be executed, and the natural language processing task processing result is obtained.
[0155] From the above, it can be seen that this embodiment can solve the problem of high computing cost and storage overhead of natural language processing tasks. Natural language models with high execution accuracy of natural language processing tasks can be deployed on resource-constrained devices for use, so that such devices with smaller computing resources and storage resources can also process natural language processing tasks that can output accurate answers.
[0156] In this specification, each embodiment is described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the embodiments can be referred to each other. For the hardware disclosed in the embodiments, including electronic devices, non-volatile storage media, computer program products, and mobile devices, since they correspond to the methods disclosed in the embodiments, the description is relatively simple, and the relevant parts can be referred to the method part description.
[0157] Professionals may further appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described in the above description according to function. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professionals and technicians may use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of the present invention.
[0158] The above is a detailed introduction to a natural language processing task execution and model training method, electronic device, non-volatile storage medium, computer program product and mobile device provided by the present invention. Specific examples are used herein to illustrate the principles and implementation methods of the present invention. The description of the above embodiments is only used to help understand the method of the present invention and its core idea. It should be pointed out that based on the embodiments of the present invention, for ordinary technicians in this technical field, all other embodiments obtained without creative work are within the scope of protection of the present invention. Without departing from the principles of the present invention, the present invention can also be improved and modified in a number of ways, and these improvements and modifications also fall within the scope of protection of the present invention.
Claims
1. A natural language model training method, characterized in that: include: Obtaining a text data set corresponding to a first natural language model, a second natural language model, and a natural language processing task to be performed; each text sample of the text data set includes a question text and a corresponding correct answer text and an incorrect answer text; Using the first natural language model to process each text data of the text data set, generating logical reasoning step text data for obtaining the correct answer text based on the question text, and error correction step text data for explaining the error cause of the incorrect answer text; Generate a logical reasoning text data set based on the text data set, the logical reasoning step text data and the error correction step text data; Using the logical reasoning text data set to train the second natural language model, so as to perform a natural language processing task using the trained second natural language model; Among them, the model parameter amount of the second natural language model is smaller than the model parameter amount of the first natural language model, and the parameter amount difference between the model parameter amount of the second natural language model and the model parameter amount of the first natural language model is at least greater than two orders of magnitude.
2. The natural language model training method according to claim 1, characterized in that: Using the first natural language model to process each text data of the text data set to generate text data of logical reasoning steps for obtaining the correct answer text based on the question text, including: Pre-constructing a positive prompt template; the positive prompt template includes a question text and a corresponding correct answer text; The positive prompt template is input as prompt information to the first natural language model, and the first natural language model generates logical reasoning step text data consistent with the corresponding correct answer text for the currently input question text according to the target tag generation method; The target mark generation method is to select a mark corresponding to the maximum credibility increase when the correct answer is compared with the correct comparison answer.
3. The natural language model training method according to claim 2, characterized in that: The correct comparison answer is a blank character, and logical reasoning step text data consistent with the corresponding correct answer text is generated for the currently input question text according to the target tag generation method, including: The correct mark profit calculation formula is called to calculate the correct answer profit of each mark; the correct mark profit calculation formula is: ; In the formula, represents the correct answer benefit for the ith mark, represents the i-th mark, represents the correct answer text, P represents the probability, p represents the given context, q represents the question text, represents all the tags before the i-th tag, Indicates that the correct comparison answer is a blank character.
4. The natural language model training method according to claim 3, characterized in that: Generate logical reasoning step text data consistent with the corresponding correct answer text for the currently input question text according to the target tag generation method, including: Based on the correct answer benefits of each mark, the correct mark selection relation is called to select the target correct mark; the correct mark selection relation is: ; In the formula, Represents the next token generated after the i-th token.
5. The natural language model training method according to claim 1, characterized in that: Based on the text data set, the logic reasoning step text data and the error correction step text data, a logic reasoning text data set is generated, including: Constructing a reasoning text dataset according to each question text in the text dataset and its corresponding correct answer text and corresponding logical reasoning step text data; Constructing an error correction text dataset according to each question text in the text dataset and its corresponding wrong answer text and corresponding error correction step text data; A logical reasoning text dataset is generated based on the reasoning text dataset and the error correction text dataset.
6. The natural language model training method according to claim 1, characterized in that: The error correction step text data explaining the error reason of the wrong answer text includes: Pre-constructing an error prompt template; the error prompt template includes a question text and a corresponding wrong answer text; The error prompt template is input as prompt information to the first natural language model, and the first natural language model generates error correction step text data that explains the error cause of the wrong answer text for the currently input question text according to the target tag generation method; The target mark generation method is to select a mark corresponding to the maximum credibility increase when the wrong answer is selected compared to the wrong comparison answer.
7. The natural language model training method according to claim 6, characterized in that: The wrong comparison answer is a blank character, and the error correction step text data explaining the reason for the wrong answer text is generated for the currently input question text according to the target tag generation method, including: The error mark profit calculation formula is called to calculate the wrong answer profit of each mark; the error mark profit calculation formula is: ; In the formula, represents the wrong answer payoff for the ith mark, represents the i-th mark, represents the wrong answer text, P represents the probability, p represents the given context, q represents the question text, represents all the tags before the i-th tag, Indicates that the answer to an error comparison is a null character.
8. The natural language model training method according to claim 7, characterized in that: Generate error correction step text data for the currently input question text that explains the reasons for the wrong answer text according to the target tag generation method, including: Based on the wrong answer benefits of each mark, the wrong mark selection relation is called to select the target wrong mark; the wrong mark selection relation is: ; In the formula, Represents the next token generated after the i-th token.
9. The natural language model training method according to claim 1, characterized in that: The first natural language model is constructed based on a hybrid expert model, and includes a first hidden state layer, a group query attention layer, a gating network, a plurality of expert sub-models, and a second hidden state layer according to the data processing flow. The second natural language model is a pre-trained language model that has completed the pre-training stage. The second natural language model is trained using the logical reasoning text data set, including: Using the logical reasoning text dataset as a fine-tuning dataset; For the natural language processing task to be performed, the second natural language model is fine-tuned using the logical reasoning text dataset so that the second natural language model adapts to the natural language processing task to be performed and the logical reasoning text dataset.
10. The natural language model training method according to any one of claims 1 to 9, characterized in that: Training the second natural language model using the logical reasoning text dataset includes: The loss function relational formula is called, and the second natural language model is trained using the logical reasoning text data set; the loss function relational formula is: ; In the formula, represents the loss function, P represents the probability, represents the i-th token, q represents the question text, Represents all the tokens before the i-th token.
11. A method for executing a natural language processing task, characterized in that: include: Obtaining a target natural language model trained in advance using the natural language model training method according to any one of claims 1 to 10, and deploying the target natural language model; Obtain the problem text to be processed corresponding to the natural language processing task to be executed; The question text to be processed is input into the target natural language model, and the predicted answer and logical reasoning content output by the target natural language model are used as the processing result of the natural language processing task to be performed.
12. An electronic device, characterized in that: It includes a processor and a memory, and the processor is used to implement the steps of the natural language model training method as described in any one of claims 1 to 10 and / or the steps of the natural language processing task execution method as described in claim 11 when executing the computer program stored in the memory.
13. A non-volatile storage medium, characterized in that: The non-volatile storage medium stores a computer program, which, when executed by a processor, implements the steps of the natural language model training method as described in any one of claims 1 to 10 and / or the steps of the natural language processing task execution method as described in claim 11.
14. A computer program product comprising a computer program / instructions, characterized in that When the computer program / instructions are executed by a processor, the steps of the natural language model training method as described in any one of claims 1 to 10 and / or the steps of the natural language processing task execution method as described in claim 11 are implemented.
15. A mobile device, characterized in that: It includes a display screen, a model deployment processor and a task executor; the display screen includes a human-computer interaction interface; The model deployment processor is used to deploy the target natural language model obtained according to the steps of the natural language model training method according to any one of claims 1 to 10; The human-computer interaction interface is used to receive the natural language processing task to be executed input by the user, and send the natural language processing task to be executed to the task executor; The task executor is used to call the natural language model, process the natural language processing task to be executed, obtain the predicted answer and the logical reasoning content, and send the predicted answer and the logical reasoning content to the human-computer interaction interface.
