Knowledge distillation method, device, equipment, storage medium and computer program product
By passing the knowledge graph and logical relationship of the teacher model to the student model, thinking chains are generated and iteratively trained, the problem of student model dependence on the teacher model is solved, which improves the performance of the student model in specific fields and reduces the complexity of model deployment. .
Patent Information
- Application Number
- CN202411051749.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-01
- Publication Date
- 2024-11-22
- Estimated Expiration
- 2044-08-01
AI Technical Summary
The performance of student models is highly dependent on the output quality of the teacher model, especially when the teacher model lacks knowledge in specific areas, resulting in limited performance of student models in these areas.
By inputting the detection text into the target teacher model, outputting keywords and building a knowledge graph set, obtaining key information and logical relationships, optimizing the reasoning steps to generate a thinking chain, and inputting it into the student model for iterative training, and gradually passing it to the student model to enhance Its performance in a specific field.
Enhanced student models' performance in specific fields, avoids high dependence on teacher models, and reduces the complexity of model deployment and application, without fine-tuning of large models, significantly reducing computing resource requirements.
Smart Images

Figure CN119005176A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of artificial intelligence technology, and in particular to a knowledge distillation method, apparatus, device, storage medium and computer program product. Background Art
[0002] As large language models (LLMs) have shown great potential in the field of natural language processing (NLP), they can provide high-quality support in text generation, language translation, question answering, etc. In order to address some of the shortcomings of large language models, distillation and fine-tuning are commonly used. Although fine-tuning the student model can improve its performance in specific tasks in some cases, it cannot fully utilize the broad and deep knowledge base of the teacher model compared to knowledge distillation. Knowledge distillation can significantly reduce the demand for computing resources while retaining the advantages of large models. .
[0003] Currently, if the teacher model lacks knowledge in certain specific areas, the performance of the student model in these areas will also be affected. The performance of the student model is highly dependent on the output quality of the teacher model.
[0004] Therefore, how to avoid the student model's high dependence on the teacher model is a problem that needs to be solved urgently. Summary of the invention
[0005] The main purpose of this application is to provide a knowledge distillation method, apparatus, device, storage medium and computer program product, aiming to solve the technical problem that the performance of the student model is highly dependent on the output quality of the teacher model.
[0006] To achieve the above objectives, the present application proposes a knowledge distillation method, which includes:
[0007] Input the detection text into the target teacher model, output keywords, and construct a target knowledge graph set based on the keywords;
[0008] Obtain key information in the target knowledge graph set and the logical relationship between the key information, input the target knowledge graph set and the keywords into a preset large language model, and output reasoning steps;
[0009] Utilizing the key information and the logical relationship to optimize the reasoning steps, and obtain a thinking chain;
[0010] The thought chain is input into the student model for iterative training to obtain the target student model.
[0011] In one embodiment, the step of receiving a detection text input by a user, inputting the detection text into a target teacher model, outputting keywords, and constructing a target knowledge graph set according to the keywords includes:
[0012] Input the detection text into the target teacher model and output keywords;
[0013] Filtering a target knowledge graph in a preset knowledge graph according to the keyword;
[0014] Construct the target knowledge graph set according to the target knowledge graph.
[0015] In one embodiment, the step of screening a target knowledge graph in a preset knowledge graph according to the keyword includes:
[0016] Inputting the knowledge graph and the keywords into the constructed large language model, and outputting a relevance score for the knowledge graph;
[0017] A knowledge graph whose relevance score is not less than a preset score is selected from the knowledge graph as the target knowledge graph.
[0018] In one embodiment, the step of inputting the thought chain into the constructed student model for iterative training multiple times to obtain the target student model includes:
[0019] Input the thought chain into the constructed student model for training, and output the student thought chain;
[0020] Modify the student's thinking chain according to the key information to obtain the target student's thinking chain;
[0021] The student model is optimized based on the target student's thinking chain to obtain a target student model.
[0022] In one embodiment, the step of correcting the student's thinking chain according to the key information to obtain the target student's thinking chain includes:
[0023] The key information is used to correct the student's thinking chain, and the corrected student's thinking chain and the thinking chain are input into the student model for iterative training until a target student's thinking chain is obtained, and the deviation between the target student's thinking chain and the thinking chain is less than a preset threshold.
[0024] In one embodiment, the step of using the key information to correct the student's thinking chain, and inputting the corrected student's thinking chain and the thinking chain into the student model for iterative training includes:
[0025] Using the key information to modify the student's thinking chain, and inputting the modified student's thinking chain and the thinking chain into the student model;
[0026] The loss function of the student model is calculated based on the corrected student thinking chain and the thinking chain:
[0027]
[0028] Among them, L label represents the loss function, N represents the number of thought chains, represents the cross entropy loss between the predicted label and the target label, f represents the student model, and x i Represents the revised student thinking chain, represents the predicted label;
[0029] The student model is iteratively trained using the loss function.
[0030] In addition, to achieve the above purpose, the present application also proposes a knowledge distillation device, which includes:
[0031] A knowledge graph integration module, which is used to input the detection text into the target teacher model, output keywords, and construct a target knowledge graph set based on the keywords;
[0032] An inference step output module, used to obtain key information in the target knowledge graph set and the logical relationship between the key information, and input the target knowledge graph set and the keywords into a preset large language model, and output inference steps;
[0033] A thinking chain generation module, used to optimize the reasoning steps by using the key information and the logical relationship to obtain a thinking chain;
[0034] The distillation optimization module is used to input the thought chain into the student model for iterative training to obtain a target student model.
[0035] In addition, to achieve the above-mentioned objectives, the present application also proposes a knowledge distillation device, which includes: a memory, a processor, and a computer program stored on the memory and executable on the processor, wherein the computer program is configured to implement the steps of the knowledge distillation method described above.
[0036] In addition, to achieve the above-mentioned purpose, the present application also proposes a storage medium, which is a computer-readable storage medium, and a computer program is stored on the storage medium. When the computer program is executed by the processor, the steps of the knowledge distillation method described above are implemented.
[0037] In addition, to achieve the above-mentioned purpose, the present application also provides a computer program product, which includes a computer program, and when the computer program is executed by a processor, it implements the steps of the knowledge distillation method described above.
[0038] One or more technical solutions proposed in this application have at least the following technical effects:
[0039] Input the detection text into the target teacher model, output keywords, and build the target knowledge graph set based on the keywords; obtain the key information in the target knowledge graph set and the logical relationship between the key information, and input the target knowledge graph set and keywords into the preset large language model, and output the reasoning steps; use the key information and logical relationships to optimize the reasoning steps to obtain the thinking chain; input the thinking chain into the student model for iterative training to obtain the target student model. By introducing the knowledge graph into the large language model, generating the thinking chain, and gradually passing it to the student model, effective distillation of knowledge in a specific field is achieved. This method can not only enhance the performance of the student model in a specific field and avoid the high dependence of the student model on the teacher model, but also eliminate the need to fine-tune the large model, thereby greatly reducing the complexity of model deployment and application. BRIEF DESCRIPTION OF THE DRAWINGS
[0040] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.
[0041] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.
[0042] Figure 1 A schematic diagram of the overall technical framework of an embodiment of the present application;
[0043] Figure 2 This is a schematic diagram of the process of the first embodiment of the knowledge distillation method of the present application;
[0044] Figure 3 This is a flow chart of the second embodiment of the knowledge distillation method of the present application;
[0045] Figure 4 A schematic diagram of the knowledge graph integration process of an embodiment of the present application;
[0046] Figure 5 This is a schematic diagram of the process of the third embodiment of the knowledge distillation method of the present application;
[0047] Figure 6 A schematic diagram of a thought chain generation process according to an embodiment of the present application;
[0048] Figure 7 This is a schematic diagram of a framework for step-by-step distillation through a knowledge graph and a thought chain in an embodiment of the present application;
[0049] Figure 8 This is a schematic diagram of the module structure of the knowledge distillation device in the embodiment of the present application;
[0050] Fig. 9 Schematic diagram of the device structure of the hardware operating environment involved in the knowledge distillation method in the embodiment of the present application.
[0051] The purpose, features and advantages of this application will be further described in conjunction with the embodiments and with reference to the accompanying drawings. DETAILED DESCRIPTION
[0052] It should be understood that the specific embodiments described herein are only used to explain the technical solutions of the present application and are not used to limit the present application.
[0053] In order to better understand the technical solution of the present application, a detailed description will be given below in conjunction with the accompanying drawings and specific implementation methods.
[0054] Since edge devices usually have limited computing resources and storage capacity, it is difficult for ordinary users and small and medium-sized enterprises to support the high computing power requirements of large language models. In addition, although large language models perform well in a wide range of application areas, they are still insufficient in terms of expertise in specific vertical fields, which limits their effectiveness in professional applications. In particular, it becomes particularly difficult for users and enterprises without a large amount of vertical field data and low computing power to further improve the model's capabilities in these areas. In order to deal with these problems, it is particularly necessary to study a method for building and deploying vertical field professional models under limited computing resources. This will support the application of large language models on edge devices, meet the specific needs of vertical fields, and achieve efficient and accurate expertise processing. In order to deal with some of the shortcomings of large language models, distillation and fine-tuning are commonly used. As for the fine-tuning of the student model, although it can also improve its performance in specific tasks in some cases, compared with knowledge distillation, it cannot fully utilize the broad and deep knowledge base of the teacher model. Fine-tuning the student model is usually only for a specific task or dataset, which limits the model's generalization ability and flexibility to adapt to different scenarios. Knowledge distillation is a technique that transfers knowledge from a large and complex model (teacher model) to a smaller model (student model). In this way, the demand for computing resources can be significantly reduced while retaining the advantages of the large model. Knowledge distillation, by imitating the output distribution and thought chain of the teacher model, enables the student model to inherit the comprehensive knowledge and complex reasoning ability of the teacher model, while being more efficient in the use of computing resources. Therefore, choosing knowledge distillation instead of simply fine-tuning the student model can inherit the intelligence and diversity of the teacher model to the greatest extent while keeping the model lightweight. The knowledge distillation process usually includes the following steps: first, train a large model with excellent performance as the teacher model; then, use the output of the teacher model to guide the training of the student model; finally, during the training of the student model, not only the labeled data but also the output provided by the teacher model is used for optimization. This method can make the student model have a smaller model size and higher computational efficiency while retaining the knowledge of the teacher model. However, knowledge distillation also has some limitations. The performance of the student model is highly dependent on the output quality of the teacher model. If the teacher model lacks knowledge in certain specific areas, the performance of the student model in these areas will also be affected. In addition, the teacher model usually lacks expertise in specific areas, which requires fine-tuning the teacher model before knowledge distillation, but fine-tuning the large model will waste more computing resources.
[0055] The present application provides a solution, which inputs the detection text into the target teacher model, outputs keywords, and constructs a target knowledge graph set based on the keywords; obtains the key information in the target knowledge graph set and the logical relationship between the key information, and inputs the target knowledge graph set and keywords into the preset large language model, and outputs the reasoning steps; uses the key information and logical relationships to optimize the reasoning steps to obtain the thinking chain; inputs the thinking chain into the student model for iterative training to obtain the target student model. It should be noted that the knowledge distillation method of the present application mainly includes three parts: knowledge graph integration, thinking chain generation, and step-by-step distillation optimization. Figure 1 As shown in the figure, by introducing the knowledge graph of specific fields into the knowledge distillation process, the model can access and utilize the structured knowledge in these fields, making up for the knowledge loss of the teacher model in these fields. In addition, the large language model is used to generate thought chains related to the input text. These thought chains can guide the model to reasonably use the information in the knowledge graph when dealing with problems in specific fields, thereby improving the model's reasoning ability and output quality. In this way, not only can the performance of the student model in a specific field be enhanced, but there is no need to fine-tune the large model, thereby greatly reducing the complexity of model deployment and application. This method has important theoretical significance and application prospects in the field of natural language processing. It can significantly improve the performance of the model in specific fields and promote the further development of NLP technology.
[0056] Based on this, the present application embodiment provides a knowledge distillation method, referring to Figure 2 , Figure 2 This is a flow chart of the first embodiment of the knowledge distillation method of the present application.
[0057] In this embodiment, the knowledge distillation method includes steps S10 to S40:
[0058] Step S10, input the detection text into the target teacher model, output keywords, and build a target knowledge graph set based on the keywords.
[0059] It should be noted that the detection text can be understood as the text to be processed that is input into the target teacher model. The target teacher model can be a large and complex model that has been pre-trained. The keywords can be the key entities and terms in the detection text. The target knowledge graph set is composed of the target knowledge graph, and the target knowledge graph can be a knowledge graph that meets the preset standards, that is, a knowledge graph that is strongly related to the keywords.
[0060] Exemplarily, the knowledge graph can be a triple structure (such as "entity 1-relationship-entity 2"), which represents the relationship between entities and multiple entities themselves. This structure can systematically organize and display knowledge in a specific field. The teacher model can be pre-trained for triple capture to obtain a target teacher model. This pre-training allows the model to learn how to recognize and understand the triple structure in the knowledge graph. When the target teacher model processes the detection text, it first performs keyword extraction on the detection text to identify key entities and terms. Next, these keywords are used to retrieve the corresponding knowledge and relationships in the knowledge graph, and this information is passed to the large language model together with the input text, so that the model can access and utilize this expertise when learning.
[0061] Step S20, obtain the key information in the target knowledge graph set and the logical relationship between the key information, and input the target knowledge graph set and keywords into the preset large language model, and output the reasoning steps.
[0062] It should be noted that the key information can be multiple keywords in at least one target knowledge graph, and the preset large language model can be a large natural language processing model based on deep learning technology, which can understand and generate natural language text. The reasoning steps can be understood as a series of operation steps or conclusion derivation processes obtained after logical analysis based on input information (such as keywords and knowledge graphs).
[0063] For example, key information and their logical relationships are extracted from the target knowledge graph to form structured input data, which are then input into a preset large language model together with keywords. The large language model performs reasoning based on the input data and generates preliminary reasoning steps. These steps may include a series of logical analysis, hypothesis verification, etc.
[0064] Step S30, using key information and logical relationships to optimize the reasoning steps to obtain a thinking chain.
[0065] It should be noted that a thought chain is a series of logically related reasoning steps that help the model gradually build a complete solution when dealing with complex problems. Thought chain generation refers to the use of a large language model to generate reasoning paths related to the input text. These paths can guide the model to effectively use the information in the knowledge graph when dealing with problems in specific fields.
[0066] For example, by analyzing the input data, the key information and logical relationships are identified. Then, combined with the structured information in the knowledge graph, corresponding reasoning steps and paths are generated for each key concept and relationship. These steps and paths are organized into a coherent chain of thinking to guide the model's reasoning and decision-making on specific domain issues.
[0067] Step S40, input the thought chain into the student model for iterative training to obtain the target student model.
[0068] It should be noted that the target student model can be a student model that has been iteratively trained and optimized.
[0069] In this embodiment, the detection text is input into the target teacher model, keywords are output, and a target knowledge graph set is constructed based on the keywords; the key information in the target knowledge graph set and the logical relationship between the key information are obtained, and the target knowledge graph set and keywords are input into the preset large language model, and the reasoning steps are output; the reasoning steps are optimized using the key information and logical relationships to obtain a thinking chain; the thinking chain is input into the student model for iterative training to obtain a target student model. By introducing the knowledge graph into the large language model, generating a thinking chain, and gradually passing it to the student model, effective distillation of knowledge in a specific field is achieved. Through this method, not only can the performance of the student model in a specific field be enhanced, avoiding the high dependence of the student model on the teacher model, but also there is no need to fine-tune the large model, thereby greatly reducing the complexity of model deployment and application.
[0070] The first embodiment adopts a method that combines knowledge graph and thinking chain to optimize knowledge transfer and reasoning process. This method can also be replaced by other forms of knowledge structure and reasoning path generation methods. For example, a rule base based on an expert system or a case-based reasoning method can be used to replace the knowledge graph to generate reasoning chains and knowledge transfer paths, thereby achieving similar knowledge distillation and model optimization effects. In addition, in the step-by-step distillation optimization process, the student model performance is gradually enhanced by multiple iterations, which can also be replaced by other progressive optimization methods. For example, the step-by-step strategy optimization method in reinforcement learning can be used to achieve knowledge transfer and performance improvement by continuously optimizing the model strategy, or the gradient descent method with adaptive learning rate adjustment can be used to optimize the training process of the student model by dynamically adjusting the learning rate. The above-mentioned extension method does not constitute a limitation on the knowledge distillation method of this application, but in order to have a better distillation effect on knowledge in a specific field, the second embodiment of this application is proposed.
[0071] Reference Figure 3 , Figure 3 This is a flow chart of the second embodiment of the knowledge distillation method of this application. Figure 2 The first embodiment shown proposes a second embodiment of the knowledge distillation method of the present application.
[0072] In the second embodiment, the step S10 includes:
[0073] Step S101, input the detection text into the target teacher model and output keywords.
[0074] Exemplarily, when the target teacher model processes the test text, it extracts keywords from the test text to identify key entities and terms. The words with the same part of speech can be categorized by marking the part of speech, and the frequency of occurrence of each word in each category can be identified. When the frequency of a word in the category set is greater than a preset frequency, the word is identified as a key word.
[0075] Step S102, filtering the target knowledge graph in the preset knowledge graph according to the keywords.
[0076] It should be noted that the preset knowledge graph is a structured knowledge representation method that can systematically organize and display knowledge in a specific field. For example, in the medical field, the knowledge graph can include relevant information such as diseases, symptoms, and treatment methods. By combining the knowledge graph with a large language model, the model can access and utilize this domain knowledge. The target knowledge graph represents entities and their relationships through nodes and edges, covering the key knowledge points and relationships in the target field.
[0077] For example, Figure 4 As shown in the figure, the knowledge graph represents entities and their relationships in the form of triples. Through these query operations, a subgraph containing relevant knowledge can be obtained. These subgraphs not only contain the key information in the input text, but also show the logical relationship and background knowledge between these information through nodes and edges. In this way, when processing and transmitting this information, the teacher model can combine its triple capture ability learned in the pre-training stage. One or more knowledge graphs that are most relevant to the keyword can be screened out as candidates based on the similarity or relevance of the keyword.
[0078] Step S103, construct a target knowledge graph set based on the target knowledge graph.
[0079] Exemplarily, the extracted key information can be used to construct a target knowledge graph in a structured manner of the knowledge graph to obtain one or more subgraphs of related knowledge, and one or more subgraphs of related knowledge can be used to construct a target knowledge graph set in a structured manner.
[0080] This embodiment inputs the detection text into the target teacher model, outputs keywords, screens the target knowledge graph in the preset knowledge graph according to the keywords, and constructs the target knowledge graph set according to the target knowledge graph. By introducing the knowledge graph, the knowledge distillation process has been significantly enhanced, solving the problem of insufficient knowledge of the teacher model in specific fields. First, the knowledge graph provides rich structured background information for the large language model, enhancing the model's understanding and processing capabilities of the input text. This method effectively makes up for the lack of professional knowledge of the teacher model, enabling the student model to obtain high-quality guidance in specific fields, thereby improving the overall performance and output quality.
[0081] In one implementation, based on the third embodiment described above, step S102 includes: inputting the knowledge graph and keywords into a constructed large language model, and outputting a relevance score for the knowledge graph; and selecting a knowledge graph from the knowledge graph whose relevance score is not lower than a preset score as the target knowledge graph.
[0082] It should be noted that the relevance score can be a quantitative indicator used to evaluate the relevance between the knowledge graph and a given keyword or query. The higher the score, the more relevant the knowledge graph is to the keyword or query. The preset score is a pre-set threshold used to determine whether the knowledge graph meets specific relevance requirements. Only knowledge graphs with a relevance score not lower than the preset score will be selected as the target knowledge graph.
[0083] For example, the large language model will score the relevance of this information and filter out the relationships with lower scores, retaining the most relevant knowledge. The system will output the triples with higher scores to the student model, allowing it to inherit the most valuable knowledge structure and logical relationships identified by the teacher model.
[0084] In this embodiment, by inputting the knowledge graph and keywords into the constructed large language model, outputting the relevance score of the knowledge graph, and screening the knowledge graph with a relevance score not less than the preset score from the knowledge graph as the target knowledge graph, it is ensured that the retrieved knowledge is of high quality and high relevance. Since the information in the knowledge graph has been systematized and verified, the content generated by the model is more reliable, reducing errors and deviations. This technology not only improves the application effect of the model in a specific field, but also has good scalability. Simply build or obtain the knowledge graph of the corresponding field, and then integrate it into the model, thereby enhancing the performance of the model in this field. By systematically organizing and transferring professional knowledge, knowledge graph integration provides a new direction for natural language processing technology and promotes the development of NLP technology in a more efficient and intelligent direction.
[0085] Reference Figure 5 , Figure 5 This is a flow chart of the third embodiment of the knowledge distillation method of this application. Figure 3 The second embodiment shown proposes the third embodiment of the knowledge distillation method of the present application.
[0086] In the third embodiment, the step S40 includes:
[0087] Step S401, input the thinking chain into the constructed student model for training, and output the student thinking chain.
[0088] It should be noted that the student thinking chain can be understood as the sequence of reasoning steps that the student model attempts to imitate and generate after receiving the thinking chain input and processing it through its internal algorithm. It is understandable that since the initial performance of the student model may be low, the thinking chain it generates may be different from the real or ideal thinking chain.
[0089] Step S402, correct the student's thinking chain according to the key information to obtain the target student's thinking chain.
[0090] It should be noted that the target student thinking chain is a student thinking chain that is closer to the real or ideal situation after being corrected with key information, and represents an optimized output of the student model on a specific task.
[0091] For example, the whole thought chain generation optimization process is as follows Figure 6 As shown in the figure, we first need to use natural language processing technology to obtain key information and relationships from the input text and the knowledge graph. Next, we use the large language model to generate preliminary reasoning steps. We gradually generate reasoning steps through sample prompts. These steps preliminarily explain how to derive possible conclusions from the input text. Combined with the authoritative knowledge in the knowledge graph, the preliminary generated reasoning steps are corrected and optimized. The knowledge graph provides verified domain knowledge. In this way, the generated thinking chain not only reflects the reasoning ability of the large language model, but also combines the authoritative knowledge in the field to ensure the accuracy and reliability of the reasoning process. Finally, the optimized reasoning steps are organized into a coherent thinking chain. The thinking chain contains all the logical steps from the input text to the final conclusion, and each step is based on authoritative knowledge and a reasonable reasoning path.
[0092] Step S403, optimizing the student model based on the target student's thinking chain to obtain the target student model.
[0093] It should be noted that the target student model is a student model that reaches or approaches the predetermined performance standard after multiple iterations of training and optimization.
[0094] For example, the knowledge transfer can be made more detailed and in-depth through multiple rounds of optimization process by using the stepwise distillation optimization method. Figure 7As shown in the figure, in each round of distillation training, the student model is trained using the answers provided by the teacher model while imitating the reasoning process of the teacher model. This training method not only focuses on the accuracy of the final answer, but also on the rationality and coherence of the reasoning process. The student model generates its own reasoning path by learning the reasoning chain of the teacher model, thereby understanding and mastering the knowledge in a specific field. This process is repeated many times, so that the reasoning ability and answer accuracy of the student model are gradually improved, approaching the level of the teacher model. After each round of training, the reasoning results of the student model are compared and corrected with the reasoning process of the teacher model. The student model is optimized by combining new training data and updated thinking chains.
[0095] In this embodiment, by inputting the thinking chain into the constructed student model for training, outputting the student thinking chain, correcting the student thinking chain according to the key information, obtaining the target student thinking chain, optimizing the student model based on the target student thinking chain, and obtaining the target student model. By combining the authoritative knowledge in the knowledge graph, the initially generated reasoning steps are corrected and optimized. Each round of optimization not only improves the reasoning ability of the student model, but also avoids the reasoning deviation caused by relying solely on data-driven by correcting the reasoning steps. This method of step-by-step correction and optimization ensures the integrity and effectiveness of knowledge transfer, so that the student model performs well in problem solving in specific fields. The introduction of the thinking chain makes the reasoning process transparent, and the user can clearly see the basis and logic of each reasoning step, thereby enhancing the trust in the output results of the model. Through this technical solution, the model can provide more credible and valuable results in practical applications.
[0096] In one embodiment, based on the above-mentioned third embodiment, step S402 includes: using key information to correct the student's thinking chain, and inputting the corrected student's thinking chain and the thinking chain into the student model for iterative training until the target student's thinking chain is obtained, and the deviation between the target student's thinking chain and the thinking chain is less than a preset threshold.
[0097] It should be noted that the loss function of the student model can be calculated based on the corrected student thinking chain and thinking chain, and the student model can be iteratively trained using the loss function. In the absence of manually labeled labels, the task-specific distillation method uses a large language model (LLM) to generate pseudo-noise training labels Instead of the true label (y i ). The smaller models f are trained by minimizing the label prediction loss. i ) and predicted labels To create a clearer connection between and triples As additional supervision information, we frame learning explanations and question answering as a multi-task problem. Specifically, we train the model Not only predicting the task label, but also generating the corresponding explanation and triplet, the overall cross entropy loss can be further defined as formula (1):
[0098] L=λ 1 L label +λ 2 L exp lanation +(1-λ 1 -λ 2 )L triple (1)
[0099] Among them, L is the cross entropy loss between the predicted label and the target label, λ 1 and λ 2 Represents the loss function calculation weight, L label represents the loss function, L explanation is the explanation generation loss, L triple is the important triplet generation loss.
[0100] L label The loss function can be expressed as formula (2):
[0101]
[0102] In formula (2), L label is the loss function, N represents the number of thought chains, represents the cross entropy loss between the predicted label and the target label, f represents the student model, and x i It represents the revised student thinking chain. Represents the predicted label.
[0103] In formula (1), L explanation is the explanation generation loss, defined as formula (3):
[0104]
[0105] In formula (3), L explanarion To explain the generation loss, N represents the number of thought chains, represents the cross entropy loss between the predicted label and the target label, f represents the student model, and x i It represents the revised student thinking chain. Represents the extracted explanation.
[0106] In formula (1), L triple is the important triplet generation loss, defined as formula (4):
[0107]
[0108] In formula (4), L triple Generate the loss for important triples, N represents the number of thought chains, represents the cross entropy loss between the predicted label and the target label, f represents the student model, and x i It represents the revised student thinking chain. Represents a triple.
[0109] In this implementation, by optimizing the loss function, the student model maximizes the learning and expression of the knowledge in the teacher model under limited computing resources and data volume. After learning and training, the student model can make better predictions for new input questions. This step-by-step distillation method through knowledge graph and thought chain effectively utilizes the ability of large language models to generate explanations, significantly improves the performance and generalization ability of the student model, and provides a new solution for actual deployment.
[0110] It should be noted that the above examples are only used to understand the present application and do not constitute a limitation on the knowledge distillation method of the present application. More simple transformations based on this technical concept are all within the scope of protection of the present application.
[0111] This application also provides a knowledge distillation device, please refer to Figure 8 , the knowledge distillation device comprises:
[0112] The knowledge graph integration module 10 is used to input the detection text into the target teacher model, output keywords, and construct a target knowledge graph set based on the keywords;
[0113] An inference step output module 20 is used to obtain key information in the target knowledge graph set and the logical relationship between the key information, input the target knowledge graph set and the keywords into a preset large language model, and output inference steps;
[0114] A thinking chain generation module 30 is used to optimize the reasoning steps by using the key information and the logical relationship to obtain a thinking chain;
[0115] The distillation optimization module 40 is used to input the thought chain into the student model for iterative training to obtain a target student model.
[0116] The knowledge distillation device provided in this application adopts the knowledge distillation method in the above embodiment, which can solve the technical problem that the performance of the student model is highly dependent on the output quality of the teacher model. Compared with the prior art, the beneficial effects of the knowledge distillation device provided in this application are the same as the beneficial effects of the knowledge distillation method provided in the above embodiment, and the other technical features in the knowledge distillation device are the same as the features disclosed in the above embodiment method, which will not be repeated here.
[0117] The present application provides a knowledge distillation device, which includes: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the knowledge distillation method in the above-mentioned embodiment one.
[0118] Reference below Fig. 9 , which shows a schematic diagram of the structure of a knowledge distillation device suitable for implementing the embodiment of the present application. The knowledge distillation device in the embodiment of the present application may include but is not limited to mobile terminals such as mobile phones, laptop computers, digital broadcast receivers, PDAs (Personal Digital Assistants), PADs (Portable Application Descriptions), PMPs (Portable Media Players), vehicle-mounted terminals (such as vehicle-mounted navigation terminals), etc., and fixed terminals such as digital TVs, desktop computers, etc. Fig. 9 The knowledge distillation device shown is merely an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.
[0119] like Fig. 9 As shown, the knowledge distillation device may include a processing device 1001 (e.g., a central processing unit, a graphics processing unit, etc.), which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM: Read Only Memory) 1002 or a program loaded from a storage device 1003 to a random access memory (RAM: Random Access Memory) 1004. In RAM1004, various programs and data required for the operation of the knowledge distillation device are also stored. The processing device 1001, ROM1002, and RAM1004 are connected to each other through a bus 1005. An input / output (I / O) interface 1006 is also connected to the bus. Generally, the following systems can be connected to the I / O interface 1006: an input device 1007 including, for example, a touch screen, a touch pad, a keyboard, a mouse, an image sensor, a microphone, an accelerometer, a gyroscope, etc.; an output device 1008 including, for example, a liquid crystal display (LCD: Liquid Crystal Display), a speaker, a vibrator, etc.; a storage device 1003 including, for example, a magnetic tape, a hard disk, etc.; and a communication device 1009. The communication device 1009 can allow the knowledge distillation device to communicate with other devices wirelessly or by wire to exchange data. Fig. 9A knowledge distillation apparatus having various systems is shown, but it should be understood that it is not required to implement or have all of the systems shown. More or fewer systems may be implemented or have alternatively.
[0120] In particular, according to the embodiments disclosed in the present application, the process described above with reference to the flowchart can be implemented as a computer software program. For example, the embodiments disclosed in the present application include a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network through a communication device, or installed from a storage device 1003, or installed from a ROM 1002. When the computer program is executed by the processing device 1001, the above-mentioned functions defined in the method of the embodiment disclosed in the present application are executed.
[0121] The knowledge distillation device provided by this application adopts the knowledge distillation method in the above embodiment, which can solve the technical problem that the performance of the student model is highly dependent on the output quality of the teacher model. Compared with the prior art, the beneficial effects of the knowledge distillation device provided by this application are the same as the beneficial effects of the knowledge distillation method provided by the above embodiment, and the other technical features in the knowledge distillation device are the same as the features disclosed in the method of the previous embodiment, which will not be repeated here.
[0122] It should be understood that the various parts disclosed in this application can be implemented by hardware, software, firmware or a combination thereof. In the description of the above embodiments, specific features, structures, materials or characteristics can be combined in any one or more embodiments or examples in a suitable manner.
[0123] The above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any person skilled in the art who is familiar with the present technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.
[0124] The present application provides a computer-readable storage medium having computer-readable program instructions (ie, computer programs) stored thereon, and the computer-readable program instructions are used to execute the knowledge distillation method in the above-mentioned embodiment.
[0125] The computer-readable storage medium provided in the present application may be, for example, a USB flash drive, but is not limited to electrical, magnetic, optical, electromagnetic, infrared, or semiconductor systems, systems or devices, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In this embodiment, the computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in combination with an instruction execution system, system or device. The program code contained on the computer-readable storage medium may be transmitted using any appropriate medium, including but not limited to: wires, optical cables, RF (Radio Frequency), etc., or any suitable combination of the above.
[0126] The above-mentioned computer-readable storage medium may be included in the knowledge distillation device; or it may exist independently without being assembled into the knowledge distillation device.
[0127] The above-mentioned computer-readable storage medium carries one or more programs. When the above-mentioned one or more programs are executed by the knowledge distillation device, the knowledge distillation device: inputs the detection text into the target teacher model, outputs keywords, and constructs a target knowledge graph set based on the keywords; obtains the key information in the target knowledge graph set and the logical relationship between the key information, and inputs the target knowledge graph set and keywords into the preset large language model, and outputs the reasoning steps; optimizes the reasoning steps using the key information and logical relationships to obtain a thinking chain; inputs the thinking chain into the student model for iterative training to obtain the target student model.
[0128] Computer program code for performing the operations of the present application may be written in one or more programming languages or a combination thereof, including object-oriented programming languages such as Java, Smalltalk, C++, and conventional procedural programming languages such as "C" or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as a separate software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., via the Internet using an Internet service provider).
[0129] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present application. In this regard, each square box in the flow chart or block diagram can represent a module, a program segment or a part of a code, and the module, the program segment or a part of the code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the square box can also occur in a sequence different from that marked in the accompanying drawings. For example, two square boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each square box in the block diagram and / or flow chart, and the combination of the square boxes in the block diagram and / or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0130] The modules involved in the embodiments described in this application may be implemented by software or hardware, wherein the name of the module does not constitute a limitation on the unit itself in some cases.
[0131] The readable storage medium provided in this application is a computer-readable storage medium, which stores computer-readable program instructions (i.e., computer programs) for executing the above-mentioned knowledge distillation method, and can solve the technical problem that the performance of the student model is highly dependent on the output quality of the teacher model. Compared with the prior art, the beneficial effects of the computer-readable storage medium provided in this application are the same as the beneficial effects of the knowledge distillation method provided in the above-mentioned embodiment, and will not be repeated here.
[0132] The present application also provides a computer program product, including a computer program, which implements the steps of the knowledge distillation method as described above when executed by a processor.
[0133] The computer program product provided in this application can solve the technical problem that the performance of the student model is highly dependent on the output quality of the teacher model. Compared with the prior art, the beneficial effects of the computer program product provided in this application are the same as the beneficial effects of the knowledge distillation method provided in the above embodiment, which will not be repeated here.
[0134] The above descriptions are only some embodiments of the present application, and are not intended to limit the patent scope of the present application. All equivalent structural changes made using the contents of the present application specification and drawings under the technical concept of the present application, or direct / indirect applications in other related technical fields are included in the patent protection scope of the present application.
Claims
1. A knowledge distillation method, characterized in that: The method includes: Input the detection text into the target teacher model, output keywords, and construct a target knowledge graph set based on the keywords; Obtain key information in the target knowledge graph set and the logical relationship between the key information, input the target knowledge graph set and the keywords into a preset large language model, and output reasoning steps; Utilizing the key information and the logical relationship to optimize the reasoning steps, and obtain a thinking chain; The thought chain is input into the student model for iterative training to obtain the target student model.
2. The method according to claim 1, characterized in that The step of receiving the detection text input by the user, inputting the detection text into the target teacher model, outputting keywords, and constructing a target knowledge graph set according to the keywords includes: Input the detection text into the target teacher model and output keywords; Filtering a target knowledge graph in a preset knowledge graph according to the keyword; Construct the target knowledge graph set according to the target knowledge graph.
3. The method according to claim 2, characterized in that The step of screening the target knowledge graph in the preset knowledge graph according to the keyword includes: Inputting the knowledge graph and the keywords into the constructed large language model, and outputting a relevance score for the knowledge graph; A knowledge graph whose relevance score is not less than a preset score is selected from the knowledge graph as the target knowledge graph.
4. The method according to any one of claims 1 to 3, characterized in that The step of inputting the thought chain into the constructed student model for iterative training to obtain the target student model includes: Input the thought chain into the constructed student model for training, and output the student thought chain; Modify the student's thinking chain according to the key information to obtain the target student's thinking chain; The student model is optimized based on the target student's thinking chain to obtain a target student model.
5. The method according to claim 4, characterized in that The step of correcting the student's thinking chain according to the key information to obtain the target student's thinking chain includes: The key information is used to correct the student's thinking chain, and the corrected student's thinking chain and the thinking chain are input into the student model for iterative training until a target student's thinking chain is obtained, and the deviation between the target student's thinking chain and the thinking chain is less than a preset threshold.
6. The method according to claim 5, characterized in that The step of using the key information to correct the student's thinking chain, and inputting the corrected student's thinking chain and the thinking chain into the student model for iterative training includes: Using the key information to modify the student's thinking chain, and inputting the modified student's thinking chain and the thinking chain into the student model; The loss function of the student model is calculated based on the corrected student thinking chain and the thinking chain: Among them, L label represents the loss function, N represents the number of thought chains, represents the cross entropy loss between the predicted label and the target label, f represents the student model, and x i It represents the revised student thinking chain. represents the predicted label; The student model is iteratively trained using the loss function.
7. A knowledge distillation device, characterized in that: The device comprises: A knowledge graph integration module, which is used to input the detection text into the target teacher model, output keywords, and construct a target knowledge graph set based on the keywords; An inference step output module, used to obtain key information in the target knowledge graph set and the logical relationship between the key information, and input the target knowledge graph set and the keywords into a preset large language model, and output inference steps; A thinking chain generation module, used to optimize the reasoning steps by using the key information and the logical relationship to obtain a thinking chain; The distillation optimization module is used to input the thought chain into the student model for iterative training to obtain a target student model.
8. A knowledge distillation device, characterized in that: The device comprises: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the computer program is configured to implement the steps of the knowledge distillation method according to any one of claims 1 to 6.
9. A storage medium, characterized in that: The storage medium is a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps of the knowledge distillation method according to any one of claims 1 to 6 are implemented.
10. A computer program product, characterized in that The computer program product comprises a computer program, which, when executed by a processor, implements the steps of the knowledge distillation method according to any one of claims 1 to 6.
Citation Information
Patent Citations
Large language model distillation method based on thinking chain
CN116739110A
Customized training method and device based on large model thinking chain
CN117149984A
Large model distillation method and device and storage medium
CN118093832A
Techniques for processing neural queries
US10311058B1
Cited By
Knowledge graph construction method and device based on multi-source data
CN120387506A
A knowledge graph construction method and device based on multi-source data
CN120387506B
Legal thinking chain data construction method and device and program product
CN120632054A
Semantic correlation prediction model, method and device, storage medium and computer equipment
CN120804671A
Semantic relevance prediction models, methods, devices, storage media, and computer equipment
CN120804671B
