Knowledge distillation method, device, equipment, storage medium and computer program product
By introducing knowledge graphs and thought chains into the student model, the problem of the student model's dependence on the teacher model is solved, which improves performance in specific domains and reduces the demand for computing resources.
Patent Information
- Application Number
- CN202411051749.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-01
- Publication Date
- 2025-11-28
- Estimated Expiration
- 2044-08-01
AI Technical Summary
The performance of student models is highly dependent on the output quality of teacher models, and their performance is limited, especially in specific domains. Furthermore, fine-tuning large models can waste computational resources.
By inputting the detected text into the target teacher model, outputting keywords and constructing a knowledge graph set, key information and logical relationships are obtained, a thought chain is generated, and then input into the student model for iterative training, gradually distilling and optimizing the student model.
It enhances the performance of student models in specific domains, avoids a high dependence on teacher models, and reduces the complexity of model deployment and application.
Smart Images

Figure CN119005176B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of artificial intelligence, and in particular to a knowledge distillation method and device, equipment, a storage medium and a computer program product. BACKGROUND
[0002] With the great potential of large language models (LLMs) in the field of natural language processing (NLP), they can provide high-quality support in generating text, language translation, and answering questions. To address the shortcomings of large language models, two methods are commonly used: distillation and fine-tuning. However, fine-tuning of student models, while improving their performance on specific tasks in some cases, cannot fully utilize the extensive and deep knowledge base of teacher models compared to knowledge distillation. Knowledge distillation can significantly reduce the demand for computing resources while retaining the advantages of large models.
[0003] Currently, teacher models lack knowledge in certain specific areas, which affects the performance of student models in these areas. The performance of student models is highly dependent on the output quality of teacher models.
[0004] Therefore, how to avoid the high dependence of student models on teacher models is a problem that needs to be solved. SUMMARY
[0005] The main purpose of the present application is to provide a knowledge distillation method, device, equipment, storage medium and computer program product, which aims to solve the technical problem that the performance of student models is highly dependent on the output quality of teacher models.
[0006] To achieve the above-mentioned purpose, the present application provides a knowledge distillation method, which comprises:
[0007] inputting the detection text into a target teacher model, outputting keywords, and constructing a target knowledge graph set according to the keywords;
[0008] obtaining key information in the target knowledge graph set and logical relationships between the key information, and inputting the target knowledge graph set and the keywords into a preset large language model to output reasoning steps;
[0009] optimizing the reasoning steps using the key information and the logical relationships to obtain a thought chain;
[0010] inputting the thought chain into a student model for iterative training to obtain a target student model.
[0011] In an embodiment, the step of receiving a user input detection text, inputting the detection text into a target teacher model, outputting keywords, and constructing a target knowledge graph set according to the keywords comprises:
[0012] inputting the detected text into the target teacher model to output a keyword;
[0013] filtering a target knowledge graph from the preset knowledge graph according to the keyword;
[0014] constructing the target knowledge graph set according to the target knowledge graph.
[0015] In an embodiment, the step of filtering a target knowledge graph from the preset knowledge graph according to the keyword comprises:
[0016] inputting the knowledge graph and the keyword into the constructed large language model to output a relevance score of the knowledge graph;
[0017] filtering a knowledge graph with a relevance score not lower than a preset score from the knowledge graph as the target knowledge graph.
[0018] In an embodiment, the step of inputting the thought chain into the constructed student model for iterative training multiple times to obtain a target student model comprises:
[0019] inputting the thought chain into the constructed student model for training to output a student thought chain;
[0020] correcting the student thought chain according to the key information to obtain a target student thought chain;
[0021] optimizing the student model based on the target student thought chain to obtain a target student model.
[0022] In an embodiment, the step of correcting the student thought chain according to the key information to obtain a target student thought chain comprises:
[0023] correcting the student thought chain using the key information, and inputting the corrected student thought chain and the thought chain into the student model for iterative training until a target student thought chain is obtained, wherein a deviation between the target student thought chain and the thought chain is less than a preset threshold.
[0024] In an embodiment, the step of correcting the student thought chain using the key information, and inputting the corrected student thought chain and the thought chain into the student model for iterative training comprises:
[0025] correcting the student thought chain using the key information, and inputting the corrected student thought chain and the thought chain into the student model;
[0026] calculating a loss function of the student model according to the corrected student thought chain and the thought chain.
[0027]
[0028] wherein, L label represents a 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, x i represents the corrected student thought chain, represents the predicted label;
[0029] Using the loss function, the student model is iteratively trained.
[0030] In addition, to achieve the above object, the present application also provides a knowledge distillation device, which comprises:
[0031] A knowledge graph integration module is configured to input a detection text into a target teacher model, output a keyword, and construct a target knowledge graph set according to the keyword.
[0032] A reasoning step output module is configured to acquire key information in the target knowledge graph set and a logical relationship between the key information, and input the target knowledge graph set and the keyword into a preset large language model to output a reasoning step.
[0033] A thought chain generation module is configured to optimize the reasoning step by using the key information and the logical relationship to obtain a thought chain.
[0034] A distillation optimization module is configured to input the thought chain into a student model for iterative training to obtain a target student model.
[0035] In addition, to achieve the above object, the present application also provides a knowledge distillation device, which comprises 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 as described above.
[0036] In addition, to achieve the above object, the present application also provides a storage medium, which is a computer readable storage medium, and the storage medium stores a computer program, wherein the computer program is executed by a processor to implement the steps of the knowledge distillation method as described above.
[0037] In addition, to achieve the above object, the present application also provides a computer program product, which comprises a computer program, wherein the computer program is executed by a processor to implement the steps of the knowledge distillation method as described above.
[0038] The one or more technical solutions provided in the application have at least the following technical effects:
[0039] The detection text is input into the target teacher model, keywords are output, and a target knowledge graph set is constructed according to the keywords; key information in the target knowledge graph set and logical relationships between the key information are obtained, and the target knowledge graph set and the keywords are input into a preset large language model to output reasoning steps; the reasoning steps are optimized by using the key information and the logical relationships to obtain a thinking chain; and the thinking chain is input into a student model for iterative training to obtain a target student model. By introducing the knowledge graph into the large language model, the thinking chain is generated, and the process of gradually passing the thinking chain to the student model is realized. The effective distillation of knowledge in a specific field is realized. Through this method, the performance of the student model in a specific field can be enhanced, and the high dependence of the student model on the teacher model is avoided. Moreover, the large model does not need to be fine-tuned, thereby greatly reducing the complexity of model deployment and application. BRIEF DESCRIPTION OF DRAWINGS
[0040] The accompanying drawings, which are incorporated into and form part of the specification, illustrate embodiments consistent with the present application and, together with the specification, serve to explain the principles of the application.
[0041] In order to more clearly illustrate the technical solutions in the embodiments of the present application or the prior art, the accompanying drawings needed to be used in the embodiments or prior art description will be briefly introduced. Obviously, for those skilled in the art, other drawings can also be obtained without creative labor based on these drawings.
[0042] Figure 1 The schematic diagram of the total technical framework of the embodiments of the present application is shown in the figure.
[0043] Figure 2 The schematic diagram of the process of the first embodiment of the knowledge distillation method of the present application is shown in the figure.
[0044] Figure 3 The schematic diagram of the process of the second embodiment of the knowledge distillation method of the present application is shown in the figure.
[0045] Figure 4 The schematic diagram of the knowledge graph integration process of the embodiments of the present application is shown in the figure.
[0046] Figure 5 The schematic diagram of the process of the third embodiment of the knowledge distillation method of the present application is shown in the figure.
[0047] Figure 6 The schematic diagram of the thinking chain generation process of the embodiments of the present application is shown in the figure.
[0048] Figure 7 The schematic diagram of the step-by-step distillation framework of the embodiments of the present application through the knowledge graph and the thinking chain is shown in the figure.
[0049] Figure 8 A module structure schematic diagram of the knowledge distillation device in the embodiment of the present application;
[0050] Figure 9 A device structure schematic diagram of a hardware running environment involved in the knowledge distillation method in the embodiment of the present application.
[0051] The object implementation, functional features and advantages of the present application will be further described with reference to the embodiments and the accompanying drawings. DETAILED DESCRIPTION
[0052] It should be understood that the specific embodiments described herein are merely intended 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 solutions of the present application, the specific embodiments will be described in detail below with reference to the drawings and the specific embodiments.
[0054] Due to the limited computing resources and storage capabilities of edge devices, 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, while large language models perform well in a wide range of applications, they still lack expertise in specific vertical fields, which limits their effectiveness in professional applications. In particular, for users and enterprises with limited vertical field data and low computing power, it is particularly difficult to further enhance the capabilities of models in these fields. To address these issues, it is necessary to develop a method for building and deploying vertical field specialized 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 professional knowledge processing. To address the shortcomings of large language models, distillation and fine-tuning are commonly used methods. For student model fine-tuning, while it can improve performance on certain tasks in some cases, it cannot fully utilize the extensive and deep knowledge base of the teacher model compared to knowledge distillation. Fine-tuning student models usually only targets a specific task or dataset, which limits the model's generalization ability and flexibility in adapting to different scenarios. Knowledge distillation is a technique that transfers the knowledge of large and complex models (teacher models) to smaller models (student models). In this way, the advantages of large models can be retained while significantly reducing the demand for computing resources. Knowledge distillation enables student models to inherit the comprehensive knowledge and complex reasoning capabilities of teacher models by mimicking their output distribution and thought chains, while being more efficient in terms of computing resource usage. Therefore, choosing knowledge distillation instead of simply fine-tuning student models can maximize the inheritance of teacher model intelligence and diversity while maintaining model lightweight. The knowledge distillation process usually includes the following steps: first, train a large model with excellent performance as a teacher model; then use the teacher model's output to guide the training of the student model; finally, use not only the labeled data but also the teacher model's output to optimize the student model during training. This approach allows student models to retain teacher model knowledge while having smaller model sizes and higher computational efficiency. However, knowledge distillation also has some limitations. The performance of student models is highly dependent on the quality of teacher model outputs, and if the teacher model lacks knowledge in certain specific areas, the performance of student models in these areas will also be affected. In addition, teacher models often lack specialized knowledge in specific fields, which requires fine-tuning of the teacher model before knowledge distillation, but fine-tuning large models will waste a lot of computing resources.
[0055] The application provides a solution of inputting the detection text into a target teacher model, outputting keywords, and constructing a target knowledge graph set according to the keywords; obtaining the key information in the target knowledge graph set and the logical relationship between the key information, and inputting the target knowledge graph set and the keywords into a preset large language model to output reasoning steps; using the key information and the logical relationship to optimize the reasoning steps to obtain a thinking chain; and inputting the thinking chain into a student model for iterative training to obtain a target student model. It should be noted that the knowledge distillation method of the application mainly includes three parts of knowledge graph integration, thinking chain generation, and step-by-step distillation optimization, as shown in Figure 1 By introducing the knowledge graph of a specific field into the knowledge distillation process, the model can access and utilize the structured knowledge in these fields, making up for the lack of knowledge of the teacher model in these fields. In addition, the large language model is used to generate thinking chains related to the input text, which can guide the model to reasonably use the information in the knowledge graph when processing problems in specific fields, thereby improving the reasoning ability and output quality of the model. Through this method, the performance of the student model in specific fields can be enhanced, and the large model does not need to be fine-tuned, thereby greatly reducing the complexity of model deployment and application. This method has important theoretical significance and application prospect in the field of natural language processing, and can significantly improve the performance of the model in specific fields and promote the further development of NLP technology.
[0056] Based on this, the embodiment of the application provides a knowledge distillation method, referring to Figure 2 , Figure 2 The flowchart of the first embodiment of the knowledge distillation method of the application is shown in the figure.
[0057] In this embodiment, the knowledge distillation method includes steps S10-S40:
[0058] Step S10, input the detection text into the target teacher model, output the keywords, and construct the target knowledge graph set according to the keywords.
[0059] It should be noted that the detection text can be understood as the text to be processed input into the target teacher model, the target teacher model can be a large and complex model pre-trained, the keywords can be key entities and terms in the detection text, the target knowledge graph set is composed of target knowledge graphs, and the target knowledge graph can be a knowledge graph that meets the preset standard, i.e., a knowledge graph that is strongly related to the keywords.
[0060] Exemplarily, the knowledge graph can be a triple structure (such as "entity 1-relation-entity 2"), representing the relationship between entities and the entities themselves, which can systematically organize and demonstrate the knowledge of a specific field. The teacher model can be pre-trained for triple capture to obtain a target teacher model, and such pre-training enables the model to learn how to identify and understand the triple structure in the knowledge graph. When the target teacher model processes the detection text, first, keyword extraction is performed on the detection text to identify key entities and terms. Next, the keywords are used to retrieve corresponding knowledge and relationships in the knowledge graph, and these information are passed to the large language model along with the input text, so that the model can access and utilize these professional knowledge during learning.
[0061] In step S20, 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 the keywords are input into a preset large language model to output a reasoning step.
[0062] It should be noted that the key information can be a plurality of 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 step can be understood as a series of operation steps or conclusion derivation processes obtained based on logical analysis of the input information (such as keywords and knowledge graph).
[0063] Exemplarily, the key information and their logical relationships are extracted from the target knowledge graph set to form structured input data, and the structured data are input into the preset large language model along with the keywords. The large language model performs reasoning based on the input data to generate preliminary reasoning steps. These steps can include a series of logical analysis, hypothesis verification, etc.
[0064] In step S30, the reasoning step is optimized using the key information and the logical relationship to obtain a thought chain.
[0065] It should be noted that the thought chain is a series of logically related reasoning steps, which helps the model to gradually build a complete solution when dealing with complex problems. Thought chain generation refers to generating reasoning paths related to the input text using a large language model, which can guide the model to effectively utilize the information in the knowledge graph when dealing with problems in a specific field.
[0066] Exemplarily, by analyzing the input data, the key information and the logical relationship 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 thought chain to guide the model's reasoning and decision-making on specific field problems.
[0067] Step S40, input the thought chain into the student model for iterative training to obtain a 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 to output keywords, and a target knowledge graph set is constructed according to 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 the keywords are input into a preset large language model to output a reasoning step; the reasoning step is optimized using the key information and the logical relationship to obtain a thought chain; and the thought 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, the thought chain is generated and gradually passed to the student model, which realizes effective distillation of knowledge in a specific field. 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 the large model does not need to be fine-tuned, thereby greatly reducing the complexity of model deployment and application.
[0070] The first embodiment adopts a method combining knowledge graph and thought chain for knowledge transmission and reasoning process optimization. This method can also be replaced by other forms of knowledge structure and reasoning path generation method. For example, a rule base based on expert system or a case-based reasoning method can be used to replace the knowledge graph to generate a reasoning chain and a knowledge transmission path, thereby achieving similar knowledge distillation and model optimization effect. In addition, in the gradual distillation optimization process, the student model performance is gradually enhanced in a multi-iteration manner. This method can also be replaced by other progressive optimization methods. For example, a step-by-step policy optimization method in reinforcement learning can be used to realize knowledge transmission and performance improvement by continuously optimizing the model strategy, or a 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 extension methods do not constitute a limitation on the knowledge distillation method of the present application, but in order to have a better distillation effect on the knowledge in a specific field, the second embodiment of the present application is proposed.
[0071] Reference Figure 3 , Figure 3 The flowchart of the second embodiment of the knowledge distillation method of the present application is shown in FIG. 2, which is based on the first embodiment shown in FIG. 1. Figure 2 The second embodiment of the knowledge distillation method of the present application is proposed based on the first embodiment shown in FIG. 1.
[0072] In the second embodiment, the step S10 comprises:
[0073] Step S101, input the detection text into the target teacher model to output keywords.
[0074] Exemplarily, when the target teacher model processes the detected text, keyword extraction is performed on the detected text to identify key entities and terms. By annotating the part of speech, words with the same part of speech are classified, and the frequency of occurrence of each word in each category is identified. When the frequency of occurrence of a word in the category set in which it appears is greater than a preset frequency, the word is identified as a key word.
[0075] In step S102, the target knowledge graph is screened from 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 information related to diseases, symptoms, treatment methods, etc. By combining the knowledge graph with the large language model, the model can access and utilize these domain knowledge. The target knowledge graph represents entities and their relationships through nodes and edges, covering key knowledge points and relationships in the target field.
[0077] Exemplarily, as shown in Figure 4 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 key information in the input text, but also demonstrate the logical relationships and background knowledge between these information through nodes and edges. In this way, the teacher model can combine its triple capture ability learned during the pre-training phase when processing and delivering this information. One or more knowledge graphs most relevant to the keywords can be selected as candidates according to the similarity or relevance of the keywords.
[0078] In step S103, the target knowledge graph set is constructed according to the target knowledge graph.
[0079] Exemplarily, the extracted key information can be used to construct the target knowledge graph in a structured manner, obtaining one or more subgraphs of relevant knowledge, and constructing the target knowledge graph set in a structured manner.
[0080] In this embodiment, the detected text is input into the target teacher model, and the keywords are output. The target knowledge graph is screened from the preset knowledge graph according to the keywords, and the target knowledge graph set is constructed according to the target knowledge graph. By introducing the knowledge graph, the knowledge distillation process is significantly enhanced, solving the problem of insufficient knowledge of the teacher model in a specific field. First, the knowledge graph provides rich structured background information for the large language model, enhancing the model's understanding and processing ability 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 a specific field, thereby improving the overall performance and output quality.
[0081] In an implementation, based on the third embodiment described above, the step S102 comprises: inputting the knowledge graph and the keyword into the constructed large language model, outputting a relevance score of the knowledge graph; and screening, from the knowledge graph, a knowledge graph with a relevance score not lower than a preset score as a target knowledge graph.
[0082] It should be noted that the relevance score can be a quantitative index for evaluating the relevance between the knowledge graph and the 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 for determining whether the knowledge graph meets a specific relevance requirement. Only the knowledge graph 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 implementation, by inputting the knowledge graph and the keyword into the constructed large language model, outputting a relevance score of the knowledge graph, and screening, from the knowledge graph, a knowledge graph with a relevance score not lower than a preset score as a target knowledge graph, it is ensured that the retrieved knowledge is of high quality and high relevance. Since the information in the knowledge graph is systematized and verified, the content generated by the model is more reliable, reducing errors and biases. This technology not only improves the application effect of the model in a specific field, but also has good scalability. By constructing or obtaining a knowledge graph in a corresponding field, it can be integrated into the model, thereby enhancing the performance of the model in that field. By systematically organizing and delivering professional knowledge, the integration of knowledge graphs into natural language processing technology provides a new direction for NLP technology, promoting the development of NLP technology towards more efficient and intelligent directions.
[0085] Reference Figure 5 , Figure 5 The flowchart of the third embodiment of the knowledge distillation method of the present application is shown in FIG. 4, which is based on the second embodiment shown in FIG. 3. Figure 3 The third embodiment of the knowledge distillation method of the present application is proposed based on the second embodiment shown in FIG. 3.
[0086] In the third embodiment, the step S40 comprises:
[0087] Step S401: inputting the thought chain into the constructed student model for training, and outputting a student thought chain.
[0088] It should be noted that the student thought chain can be understood as the reasoning step sequence that the student model attempts to mimic and generate after receiving the thought chain input and processing it through its internal algorithm. It can be understood that due to the initial performance of the student model may be low, so the thought chain generated by it may differ from the real or ideal thought chain.
[0089] Step S402, according to the key information, correct the student thought chain, and obtain the target student thought chain.
[0090] It should be noted that the target student thought chain is a student thought chain that is closer to the real or ideal situation after being corrected by the key information, representing an optimized output of the student model on a specific task.
[0091] For example, the entire thought chain generation optimization process is as shown in Figure 6 First, key information and relationships need to be obtained from input text and knowledge graph using natural language processing techniques. Next, a preliminary reasoning step is generated using a large language model. We gradually generate reasoning steps through example prompts, which initially explain how to derive possible conclusions from input text. Combining authoritative knowledge from the knowledge graph, the preliminary generated reasoning steps are corrected and optimized. The knowledge graph provides verified domain knowledge. In this way, the generated thought chain not only reflects the reasoning ability of the large language model, but also combines authoritative knowledge in the field, ensuring the accuracy and reliability of the reasoning process. Finally, the optimized reasoning steps are organized into a coherent thought chain. The thought chain contains all logical steps from input text to final conclusion, with each step based on authoritative knowledge and reasonable reasoning paths.
[0092] Step S403, based on the target student thought chain, optimize the student model, and obtain the target student model.
[0093] It should be noted that the target student model is a student model that has reached or approached the predetermined performance standard after multiple iterations of training and optimization.
[0094] For example, the step-by-step distillation optimization method can be used to optimize the process through multiple rounds, making knowledge transfer more detailed and in-depth. For example, Figure 7 As shown, in each round of distillation training, the student model is trained using the answers provided by the teacher model while mimicking the reasoning process of the teacher model. This training method not only focuses on the accuracy of the final answer but also pays attention to the rationality and coherence of the reasoning process. The student model learns the reasoning chain of the teacher model to generate its own reasoning path, thereby understanding and mastering the knowledge in a specific domain. Through multiple iterations, the reasoning ability and answer accuracy of the student model gradually improve, 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. By combining new training data and updated thought chains, the student model is optimized.
[0095] In this embodiment, the thought chain is input into the constructed student model for training, and the student thought chain is output. The target student thought chain is obtained by correcting the student thought chain based on the key information. The target student model is obtained by optimizing the student model based on the target student thought chain. By combining the authoritative knowledge in the knowledge graph, the reasoning steps generated initially are corrected and optimized. Each round of optimization not only improves the reasoning ability of the student model, but also avoids the reasoning bias caused by relying solely on data-driven through correction of the reasoning steps. This step-by-step correction and optimization method ensures the integrity and effectiveness of knowledge transfer, enabling the student model to perform well in problem solving in specific domains. The introduction of the thought chain makes the reasoning process transparent, allowing users to clearly see the basis and logic of each reasoning step, thereby enhancing trust in the model output results. Through this technical solution, the model can provide more reliable and valuable results in actual application.
[0096] In one embodiment, based on the third embodiment described above, the step S402 includes: correcting the student thought chain using the key information, and inputting the corrected student thought chain and the thought chain into the student model for iterative training until the target student thought chain is obtained, and the deviation between the target student thought chain and the thought 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 thought chain and the thought chain, and the loss function can be used to iteratively train the student model. In the absence of human-labeled labels, the task-specific distillation method uses a large language model (LLM) to generate pseudo-noise training labels instead of real labels (y i ). Smaller models f are all trained by minimizing label prediction loss. To create a more explicit connection between input (x i ) and predicted label , we use the extracted explanations and triples as additional supervision information. The learning explanation and the answer to the question are framed as a multi-task problem. Specifically, the model is trained not only to predict the task label, but also to generate the corresponding explanation and triple. The overall cross-entropy loss can be further defined as formula (1):
[0098] L = λ1L label + λ2L exp lanation + (1-λ1-λ2)L triple (1)
[0099] where L is the cross-entropy loss between the predicted label and the target label, λ1and λ2represent the loss function calculation weights, L label represents the loss function, L explanation is the explanation generation loss, and L triple is the important triple generation loss.
[0100] L label The loss function can be represented 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, x i represents the corrected student thought chain, and 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 is the explanation 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, x i represents the corrected student thought chain, and represents the extracted explanation.
[0106] In formula (1), L triple is the important triple generation loss, defined as formula (4):
[0107]
[0108] In formula (4), L triple is the important triple 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, x i represents the modified student thought chain, represents a triple.
[0109] In this embodiment, 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 predictions on better new input problems. This step-by-step distillation method through the knowledge graph and the 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 forms of simple changes based on this technical concept are within the protection scope of the present application.
[0111] The present 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 detected text into the target teacher model, output the keywords, and construct a target knowledge graph set according to the keywords;
[0113] The reasoning step output module 20 is used to 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 the keywords into a preset large language model to output the reasoning step;
[0114] The thought chain generation module 30 is used to optimize the reasoning step by using the key information and the logical relationship to obtain a thought 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 by the present 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 knowledge distillation device provided by the present application has the same beneficial effects as 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 above embodiment method, which will not be repeated here.
[0117] The application provides a knowledge distillation device, comprising: at least one processor; and a memory connected to the at least one processor in communication; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to perform the knowledge distillation method in the above embodiment one.
[0118] Reference is made below Figure 9 , which shows a structural diagram of a knowledge distillation device suitable for implementing embodiments of the application. The knowledge distillation device in the embodiments of the application can include, but is not limited to, mobile terminals such as mobile phones, notebook 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), and the like, and fixed terminals such as digital TVs, desktop computers, and the like. Figure 9 The knowledge distillation device shown is only an example and should not impose any limitation on the functions and use range of the embodiments of the application.
[0119] As Figure 9 shown, the knowledge distillation device can include a processing device 1001 (such as a central processor, a graphics processor, etc.) that can perform various appropriate actions and processes according to programs stored in a read-only memory (ROM) 1002 or loaded from a storage device 1003 into a random access memory (RAM) 1004. Various programs and data required for the operation of the knowledge distillation device are also stored in the RAM 1004. The processing device 1001, the ROM 1002, and the RAM 1004 are connected to each other through a bus 1005. An input / output (I / O) interface 1006 is also connected to the bus. In general, the following systems can be connected to the I / O interface 1006: input devices 1007 including, for example, a touch screen, a touchpad, a keyboard, a mouse, an image sensor, a microphone, an accelerometer, a gyroscope, and the like; output devices 1008 including, for example, a liquid crystal display (LCD), a speaker, a vibrator, and the like; the storage device 1003 including, for example, a magnetic tape, a hard disk, and the like; 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. Although Figure 9 The knowledge distillation device is shown with various systems, but it should be understood that all the systems shown are not required to be implemented or provided. More or fewer systems can be alternatively implemented or provided.
[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 comprising a computer program carried on a computer readable medium, the computer program containing program codes for executing the method shown in the flowchart. In such embodiments, 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 embodiments disclosed in the present application are executed.
[0121] The knowledge distillation device provided by the present application adopts the knowledge distillation method in the above-mentioned embodiments, 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 knowledge distillation device provided by the present application has the same beneficial effects as the knowledge distillation method provided by the above-mentioned embodiments, and other technical features in the knowledge distillation device are the same as the features disclosed in the previous embodiment method, which will not be repeated here.
[0122] It should be understood that parts of the present application can be realized by hardware, software, firmware or a combination thereof. In the description of the above-mentioned 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 merely specific implementation of the present application, but the protection scope of the present application is not limited thereto, any person skilled in the art can easily think of changes or replacements within the technical scope disclosed in the present application, which should be covered in the protection scope of the present application. Therefore, the protection scope of the present application should be subject to the protection scope of the claims.
[0124] The present application provides a computer readable storage medium having stored thereon computer readable program instructions (i.e. computer program) for executing the knowledge distillation method in the above-mentioned embodiments.
[0125] The computer readable storage medium provided in the application may be, for example, a U disk, but is not limited to an electric, magnetic, optical, electromagnetic, infrared, or semiconductor system, system, or device, or any combination thereof. More specific examples of the computer readable storage medium may include, but are not limited to, an electric connection with one or more conductive 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 thereof. In the 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 can be transmitted by any suitable medium, including but not limited to an electric wire, an optical cable, an RF (Radio Frequency), and the like, or any suitable combination thereof.
[0126] The computer readable storage medium described above may be contained in the knowledge distillation device, or may exist separately without being assembled into the knowledge distillation device.
[0127] The computer readable storage medium described above carries one or more programs, which, when executed by the knowledge distillation device, cause the knowledge distillation device to: input the detection text into the target teacher model, output the keywords, and construct the target knowledge graph set according to 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 the keywords into the preset large language model to output the reasoning steps; optimize the reasoning steps by using the key information and the logical relationship to obtain the thinking chain; input the thinking chain into the student model for iterative training to obtain the target student model.
[0128] Computer program code for carrying out operations of the present application can be written in any combination of one or more programming languages, including an object oriented programming language such as Java, Smalltalk, C++ or the like and conventional procedural programming languages, such as the "C" programming language or similar programming languages. The program code can execute entirely on the user's computer, partly on the user's computer, as a stand-alone software package, partly on the user's computer and partly on a remote computer or entirely on the remote computer or server. In the latter scenario, the remote computer can 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 the connection can be made to an external computer (for example, through the Internet using an Internet Service Provider).
[0129] The flow diagrams and the block diagrams in the drawings are meant as methodological and functional description of implementations of systems, methods, and computer program products according to various embodiments of the present application. In this regard, each block in the flow diagrams or block diagrams can represent a module, a segment, or a portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that in some alternative implementations, the functions noted in the blocks can occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently or the blocks may
[0130] The modules involved in the embodiments of the present application can be implemented in software or hardware. In some cases, the names of the modules do not constitute a limitation on the modules themselves.
[0131] The readable storage medium provided by the present application is a computer readable storage medium, which stores computer readable program instructions (i.e., a computer program) for executing the knowledge distillation method described above, and can solve the technical problem that the performance of a student model is highly dependent on the output quality of a teacher model. Compared with the prior art, the computer readable storage medium provided by the present application has the same beneficial effects as the knowledge distillation method provided by the above embodiments, and will not be described here.
[0132] The application further provides a computer program product comprising a computer program which, when executed by a processor, implements the steps of the knowledge distillation method as described above.
[0133] The computer program product provided by the 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 by the application are the same as those of the knowledge distillation method provided by the above-mentioned embodiments, and are not described here.
[0134] The above only describes some embodiments of the application, and does not limit the patent scope of the application. Any equivalent structural transformation, direct / indirect application in other related technical fields, or direct / indirect application in other related technical fields within the technical concept of the application, using the content of the application specification and drawings, are included in the patent protection scope of the application.
Claims
1. A method of knowledge distillation, the method comprising: The method comprises: inputting the detection text into a target teacher model, outputting keywords, and constructing a target knowledge graph set according to the keywords; obtaining key information in the target knowledge graph set and logical relationships between the key information, and inputting the target knowledge graph set and the keywords into a preset large language model to output reasoning steps; optimizing the reasoning steps by using the key information and the logical relationships to obtain a thinking chain; inputting the thinking chain into a student model for iterative training to obtain a target student model; the step of inputting the thinking chain into the student model for iterative training to obtain the target student model comprises: training the thinking chain in the constructed student model to output a student thinking chain; correcting the student thinking chain according to the key information to obtain a target student thinking chain; optimizing the student model based on the target student thinking chain to obtain a target student model.
2. The method of claim 1, wherein, the step of inputting the detection text into a target teacher model, outputting keywords, and constructing a target knowledge graph set comprises: receiving a user input detection text, inputting the detection text into a target teacher model, and outputting keywords; screening a target knowledge graph from a preset knowledge graph according to the keywords; constructing the target knowledge graph set according to the target knowledge graph.
3. The method of claim 2, wherein, the step of screening a target knowledge graph from a preset knowledge graph according to the keywords comprises: inputting the knowledge graph and the keywords into the constructed large language model to output a relevance score of the knowledge graph; screening a knowledge graph with a relevance score not lower than a preset score from the knowledge graph as the target knowledge graph.
4. The method of any one of claims 1 to 3, wherein, the step of correcting the student thinking chain according to the key information to obtain a target student thinking chain comprises: correcting the student thinking chain by using the key information, and inputting the corrected student thinking chain and the thinking chain into the student model for iterative training until a target student thinking chain is obtained, wherein a deviation between the target student thinking chain and the thinking chain is less than a preset threshold.
5. The method of claim 4, wherein, the step of correcting the student thinking chain by using the key information, and inputting the corrected student thinking chain and the thinking chain into the student model for iterative training comprises: correcting the student thinking chain by using the key information, and inputting the corrected student thinking chain and the thinking chain into the student model; calculating a loss function of the student model according to the corrected student thinking chain and the thinking chain: wherein, represents a loss function, represents a number of thought chains, represents a cross-entropy loss between a predicted label and a target label, represents a student model, represents a revised student thought chain, represents a predicted label; iteratively training the student model by using the loss function.
6. A knowledge distillation apparatus, characterized by, the device comprises: a knowledge graph integration module for inputting detection text into a target teacher model, outputting keywords, and constructing a target knowledge graph set according to the keywords; a reasoning step output module for obtaining key information in the target knowledge graph set and logical relationships between the key information, and inputting the target knowledge graph set and the keywords into a preset large language model to output reasoning steps; The thought chain generation module is configured to optimize the reasoning steps by using the key information and the logical relationship, and obtain a thought chain. The distillation optimization module is configured to input the thought chain into a student model for iterative training, and obtain a target student model. The distillation optimization module is further configured to input the thought chain into the constructed student model for training, output a student thought chain, correct the student thought chain according to the key information to obtain a target student thought chain, and optimize the student model based on the target student thought chain to obtain a target student model.
7. A knowledge distillation apparatus characterized by, The device comprises a memory, a processor, and a computer program stored on the memory and executable on the processor, and the computer program is configured to implement the steps of the knowledge distillation method according to any one of claims 1 to 5.
8. A storage medium, characterized by The storage medium is a computer readable storage medium, and the storage medium stores a computer program, and the computer program is executed by a processor to implement the steps of the knowledge distillation method according to any one of claims 1 to 5.
9. A computer program product, characterised in that, The computer program product comprises a computer program, and the computer program is executed by a processor to implement the steps of the knowledge distillation method according to any one of claims 1 to 5.
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