Knowledge distillation method, device, equipment and storage medium
By building a task execution thinking chain and knowledge subnet, the problem of difficult transfer of complex knowledge of large models is solved, and the knowledge understanding and reasoning ability of students' models is improved.
Patent Information
- Application Number
- CN202411050207.X
- 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 knowledge distillation methods in the prior art have difficulties in expressing and transmitting complex knowledge within the large model, which makes it impossible for student models to fully understand and master this knowledge.
By analyzing the task text data of the task to be executed, a task execution thinking chain is constructed, high-relevance keywords are extracted, and a knowledge subnet is constructed based on the task execution knowledge graph, and knowledge transfer and distillation of the student model is carried out.
It effectively solves the difficulties of student models in understanding and mastering complex knowledge, improves the comprehensiveness and systematicity of knowledge transmission, and enhances the reasoning ability and knowledge application ability of student models.
Smart Images

Figure CN119005166A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of knowledge distillation technology, and in particular to a knowledge distillation method, device, equipment and storage medium. Background Art
[0002] Although large-scale language models (LLMs) perform well on many tasks, they usually require a lot of computing resources and storage space, which makes them expensive and difficult to deploy in practical applications. Moreover, these models take a long time to train and infer, which is not conducive to application scenarios that require fast response. Knowledge distillation is a method to transfer knowledge from large models to smaller models, aiming to alleviate the above shortcomings of large models. Through knowledge distillation, the knowledge from a large model with superior performance but high resource requirements (teacher model) can be transferred to a smaller and more efficient model (student model), thereby reducing the computational and storage requirements of the model without significantly sacrificing performance, making it more suitable for practical application scenarios.
[0003] However, traditional knowledge distillation methods have difficulties in expressing and transferring complex knowledge within large models, especially when abstract concepts and complex reasoning are involved, and the student model may not be able to fully understand and master such knowledge.
[0004] The above contents are only used to assist in understanding the technical solution of the present invention and do not constitute an admission that the above contents are prior art. Summary of the invention
[0005] The main purpose of this application is to provide a knowledge distillation method, device, equipment and storage medium, aiming to solve the technical problem that the knowledge distillation method in the prior art has difficulties in expressing and transmitting complex knowledge within a large model, resulting in the student model being unable to fully understand and master such knowledge.
[0006] To achieve the above objectives, the present application proposes a knowledge distillation method, which includes:
[0007] Parsing the task text data corresponding to the task to be executed to construct a task execution thought chain corresponding to the task to be executed, wherein the task to be executed includes: equipment fault diagnosis task;
[0008] Extracting keywords from the task text data and the task execution thought chain to obtain highly relevant keywords;
[0009] Constructing a knowledge subnet based on the task execution knowledge graph and the highly relevant keywords;
[0010] The knowledge subnet is used to transfer and distill knowledge to the student model.
[0011] In one embodiment, the step of parsing the task text data corresponding to the task to be executed to construct a task execution thought chain corresponding to the task to be executed includes:
[0012] Performing semantic analysis on the task text data corresponding to the task to be executed, so as to extract all semantic units in the task text data and semantic information between the semantic units;
[0013] Determining the logical relationship between the semantic units based on the semantic information;
[0014] A task execution thought chain corresponding to the task to be executed is constructed based on the logical relationship.
[0015] In one embodiment, the step of extracting keywords from the task text data and the task execution thought chain to obtain highly relevant keywords includes:
[0016] Extracting keywords from the task text data and the task execution thought chain to obtain a number of target keywords;
[0017] Performing relationship analysis and background expansion on the task execution knowledge graph through the target keywords;
[0018] When the expansion is completed, the target keywords are scored for relevance through the teacher model;
[0019] Highly relevant keywords are determined from the target keywords based on the scoring results.
[0020] In one embodiment, the step of constructing a knowledge subnet based on the task execution knowledge graph and the highly relevant keywords includes:
[0021] Performing a knowledge node search in the task execution knowledge graph based on the highly relevant keywords to determine target knowledge nodes and node relationships between the target knowledge nodes;
[0022] A knowledge subnet is constructed based on the target knowledge nodes and the node relationships.
[0023] In one embodiment, after the step of transferring and distilling knowledge to the student model through the knowledge subnet, the method further includes:
[0024] Generate a prediction label based on the task text data by the teacher model;
[0025] Obtaining explanation information corresponding to the prediction result of the task to be performed through the teacher model;
[0026] The student model is optimized based on the predicted labels, the explanation information and the task execution knowledge graph.
[0027] In one embodiment, the step of optimizing the student model based on the predicted label, the explanation information and the task execution knowledge graph includes:
[0028] Determine a cross entropy loss between the predicted label and the target label based on the explanation information and the task execution knowledge graph;
[0029] Based on the predicted label and the cross entropy loss, optimizing the student model by a preset optimization loss function;
[0030] Wherein, the preset optimization loss function is:
[0031]
[0032] Where, L label is the preset optimization loss function, N is the number of samples, L is the cross entropy loss, is the predicted label, f is the student model, x i is the input data of the student model.
[0033] In one embodiment, the step of determining the cross entropy loss between the predicted label and the target label based on the explanation information and the task execution knowledge graph includes:
[0034] determining an interpretation generation loss based on the interpretation information;
[0035] Determining knowledge graph information generation loss based on key information in the task execution knowledge graph;
[0036] A cross entropy loss between the predicted label and the target label is determined based on the explanation generation loss and the knowledge graph information generation loss.
[0037] In addition, to achieve the above purpose, the present application also proposes a knowledge distillation device, which comprises:
[0038] A thought chain building module is used to parse the task text data corresponding to the task to be executed to build a task execution thought chain corresponding to the task to be executed, and the task to be executed includes: equipment fault diagnosis task;
[0039] A keyword extraction module is used to extract keywords from the task text data and the task execution thought chain to obtain highly relevant keywords;
[0040] A knowledge network construction module, used to construct a knowledge subnet based on the task execution knowledge graph and the highly relevant keywords;
[0041] The knowledge distillation module is used to transfer and distill knowledge to the student model through the knowledge subnet.
[0042] 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 in the memory and executable on the processor, wherein the computer program is configured to implement the steps of the knowledge distillation method described above.
[0043] 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 a processor, the steps of the knowledge distillation method described above are implemented.
[0044] The present application provides a knowledge distillation method, which discloses parsing task text data corresponding to the task to be executed to construct a task execution thinking chain corresponding to the task to be executed, and the task to be executed includes: equipment fault diagnosis task; keyword extraction of task text data and task execution thinking chain to obtain high-relevance keywords; constructing a knowledge subnet based on the task execution knowledge graph and high-relevance keywords; transferring and distilling knowledge to a student model through the knowledge subnet; because the present invention obtains high-relevance keywords based on the task text data of the task to be executed and the task execution thinking chain, and transfers and distills knowledge to the student model through the knowledge subnet constructed based on the task execution knowledge graph and high-relevance keywords, it solves the technical problem that the knowledge distillation method in the prior art has difficulties in expressing and transferring complex knowledge within a large model, resulting in the student model being unable to fully understand and master such knowledge. BRIEF DESCRIPTION OF THE DRAWINGS
[0045] 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.
[0046] 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.
[0047] Figure 1 A schematic diagram of a process flow provided for Example 1 of the knowledge distillation method of this application;
[0048] Figure 2 This is an example diagram of the construction of the thinking chain in the knowledge distillation method of this application;
[0049] Figure 3This is a framework diagram of the knowledge distillation method of this application;
[0050] Figure 4 A schematic diagram of the process provided for Example 2 of the knowledge distillation method of this application;
[0051] Figure 5 This is an example diagram of knowledge extraction related to the knowledge graph in the knowledge distillation method of this application;
[0052] Figure 6 Schematic diagram of knowledge transfer and distillation in the knowledge distillation method of this application;
[0053] Figure 7 A schematic diagram of the process provided for Example 3 of the knowledge distillation method of this application;
[0054] Figure 8 This is a schematic diagram of the module structure of the knowledge distillation device in the embodiment of the present application;
[0055] 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.
[0056] 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
[0057] 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.
[0058] 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.
[0059] The main solution of the embodiment of the present application is: to parse the task text data corresponding to the task to be executed to construct the task execution thinking chain corresponding to the task to be executed, and the task to be executed includes: equipment fault diagnosis task; to extract keywords from the task text data and the task execution thinking chain to obtain highly relevant keywords; to construct a knowledge subnet based on the task execution knowledge graph and the highly relevant keywords; and to transfer and distill knowledge to the student model through the knowledge subnet.
[0060] The present application provides a solution that can obtain highly relevant keywords based on the task text data of the task to be executed and the task execution thinking chain, and transfer and distill knowledge to the student model through a knowledge subnet constructed based on the task execution knowledge graph and highly relevant keywords, thereby solving the technical problem that the knowledge distillation method in the prior art has difficulties in expressing and transferring complex knowledge within a large model, resulting in the student model being unable to fully understand and master such knowledge.
[0061] It should be noted that the execution subject of this embodiment can be a computing service device with data processing, network communication and program running functions, such as a tablet computer, a personal computer, a mobile phone, etc., or an electronic device capable of realizing the above functions, a knowledge distillation device, etc. The following takes the knowledge distillation device as an example (hereinafter referred to as the device) to illustrate this embodiment and the following embodiments.
[0062] Based on this, the present application embodiment provides a knowledge distillation method, referring to Figure 1 , Figure 1 This is a flow chart of the first embodiment of the knowledge distillation method of the present application.
[0063] In this embodiment, the knowledge distillation method includes steps S10 to S40:
[0064] Step S10: parsing the task text data corresponding to the task to be executed to construct a task execution thought chain corresponding to the task to be executed, wherein the task to be executed includes: equipment fault diagnosis task.
[0065] It should be understood that the above-mentioned tasks to be executed can be tasks in any application scenario where a large-scale language model can be used, for example: equipment fault diagnosis tasks, that is, tasks for diagnosing faults of equipment in production, and this embodiment does not impose any restrictions on this.
[0066] It can be understood that the above-mentioned task text data can be the text data required during the task execution process. For example, for an equipment fault diagnosis task, the corresponding task text data may include: the purpose of this fault diagnosis, the equipment identification corresponding to the faulty equipment, the possible cause of the fault, etc. This embodiment does not limit this.
[0067] It should be noted that the above-mentioned task execution thinking chain can be a complete reasoning chain formed by recording in detail the various reasoning steps that the large model goes through when solving a problem. These steps include not only the final conclusion, but also the intermediate assumptions, reasoning logic, and knowledge points used. The thinking chain simulates the human thinking process and breaks down complex tasks into a series of simple steps. In this way, the student model can clearly understand the thinking process of the large model, so as to better learn and imitate its reasoning method. The construction of the thinking chain can not only help the student model master complex reasoning skills, but also enhance the interpretability of the model, so that it can reason more accurately when facing complex tasks.
[0068] Furthermore, the step S10 includes: performing semantic analysis on the task text data corresponding to the task to be executed to extract all semantic units in the task text data and the semantic information between the semantic units; determining the logical relationship between the semantic units based on the semantic information; and constructing a task execution thinking chain corresponding to the task to be executed based on the logical relationship.
[0069] It should be understood that semantic analysis can be a process of deeply understanding and analyzing natural language text to identify semantic information such as entities, relationships, and emotions in task text data. Accordingly, the above semantic unit can be a unit consisting of a word group or a phrase obtained after semantic analysis of the task text data.
[0070] In practical applications, the construction of thinking chains plays a vital role in the knowledge distillation process. By analyzing the semantic associations and logical connections of the input data, a complete thinking chain is formed. This thinking chain not only shows the teacher model's understanding and reasoning path of the input data, but also effectively transfers these knowledge and logical relationships to the student model, significantly improving the latter's learning effect and performance. The construction process of the task execution thinking chain in this embodiment mainly includes four steps: data preprocessing, semantic analysis, logical relationship construction, and thinking chain optimization. First, data preprocessing is performed through text cleaning, word segmentation, and part-of-speech tagging to ensure the quality and consistency of the data; secondly, semantic analysis extracts semantic units and their relationships through a deep learning model to identify the semantic connections between words; then, logical relationship construction is based on these semantic units to show the reasoning path and logical structure between knowledge points; finally, the thinking chain is output through a large model to ensure its accuracy and completeness.
[0071] In the specific implementation, refer to Figure 2 , Figure 2 This is an example diagram of the construction of the thought chain in the knowledge distillation method of this application. Figure 2As shown, in this embodiment, GPT-3.5 can be used as a teacher model to construct a thinking chain, and the CQA dataset (an open source question-answering dataset) is used for verification. First, the CQA dataset is obtained. The text content in the dataset can be: A beaver is famous for its construction skills. Where do their materials come from? (A) British Columbia; (B) Water areas; (C) Forest areas; (D) Pay debts; (E) Zoos, and the CQA dataset is preprocessed. The specific steps include removing meaningless characters, stop words and other noise data. Subsequently, semantic analysis, logical relationship construction and thinking chain optimization are performed by calling the API interface of GPT-3.5. In this embodiment, GPT-3.5 is guided by examples to enable it to gradually parse the problem and generate a reasoning process corresponding to the correct answer. In this embodiment, the task text data corresponding to the task to be executed can be input into the teacher model, and then the teacher model can output the above-mentioned task execution thinking chain based on the thinking chain example guidance. Specifically, for Figure 2 The text content input to the teacher model shown above can be guided by a sample chain of thoughts: cot_prompt_template = Given a question, options, and correct answers, provide a detailed plan and explanation of why the correct answer is the best choice, making sure to include the explanation and keywords. The output at this point should be in the following format: Plan: 1. Restate the question and list the options; 2. Analyze each option in the context of the question; 3. Explain why the correct answer is the best choice; Explanation: Explanation content is here. At this point, the teacher model can output a chain of thoughts: Beavers are known for their ability to build complex dams and nests with branches, logs, and mud. They collect these materials from woodlands near water bodies and build their homes there. Woodlands provide the necessary resources for beavers to demonstrate their construction skills and create habitats.
[0072] Step S20: extract keywords from the task text data and the task execution thought chain to obtain highly relevant keywords.
[0073] It should be noted that the above-mentioned highly relevant keywords can be keywords with high relevance in the task text data and the task execution thinking chain. In this embodiment, the teacher model can be used to score the relevance of the keywords in the task text data and the task execution thinking chain, so as to determine the keywords with higher relevance scores among these keywords as highly relevant keywords according to the scoring results.
[0074] Step S30: constructing a knowledge subnet based on the task execution knowledge graph and the highly relevant keywords.
[0075] It should be noted that the above-mentioned task execution knowledge graph can be a structured information storage method, in which each knowledge node represents a concept or entity, and the edges between the nodes represent the relationship between them. In this embodiment, the knowledge graph displays the knowledge nodes and the relationship between them in a structured way, so that key information is no longer submerged in noise. This structured information presentation method can significantly enhance the student model's understanding of the relationship between words, thereby improving the coherence and systematicness of knowledge. In addition, the knowledge graph can also help capture and represent relationships in longer texts, enabling the student model to systematically learn and transfer complex reasoning capabilities, so as to better deal with new and unseen problems.
[0076] It should be noted that the above-mentioned knowledge subnet can be a network for displaying the nodes and the relationships between the nodes in the task execution knowledge graph. In practical applications, relevant knowledge nodes and relationships can be searched in the task execution knowledge graph through highly relevant keywords to construct a knowledge network closely related to the reasoning process, namely the above-mentioned knowledge subnet. This method innovatively ensures that the knowledge nodes and relationships extracted in the knowledge graph are highly relevant through effective keyword extraction and relevance scoring, which not only helps to build a concise and practical knowledge subgraph, but also effectively avoids the student model from being exposed to too many irrelevant knowledge points during the learning process, reducing the error accumulation and performance degradation caused by the introduction of noise. In addition, this method not only solves the problem of difficulty in identifying useful information from a huge knowledge graph, but also solves the problem that it is difficult for a large model to expand background information in combination with the structure of the knowledge graph. Providing these highly relevant knowledge points as background information to the student model can not only enrich the knowledge base of the student model, but also help it better understand and apply these knowledge points.
[0077] Step S40: performing knowledge transfer and distillation on the student model through the knowledge subnet.
[0078] In practical applications, the device can efficiently transfer the knowledge in the teacher model to the student model through the knowledge subnet. In this embodiment, knowledge transfer and distillation can systematically transfer the relevant knowledge in the thought chain and knowledge graph extracted from the large model to the student model. In this process, a step-by-step transfer method is adopted to ensure that the student model can gradually absorb and digest this knowledge. First, the reasoning process of the large model is displayed through the thought chain, so that the student model can understand and imitate its reasoning logic; then, the background knowledge provided by the knowledge graph is used to further enrich the knowledge base of the student model; finally, combining these two aspects of information, the student model is innovatively not only learning the output of the teacher model, but also encouraging the student model to learn the teacher model's reasoning ability and its understanding of global important information. This not only ensures the comprehensiveness and systematicness of knowledge transfer, but also improves the reasoning ability and knowledge application ability of the student model, so that it performs better in practical applications.
[0079] In the specific implementation, refer to Figure 3 , Figure 3 This is a framework diagram of the knowledge distillation method of this application. Figure 3 As shown, first, the task text data corresponding to the task to be executed can be input into the teacher model, and the teacher model can perform semantic analysis, logical relationship construction and thinking chain optimization on the input data to construct the above-mentioned task execution thinking chain. Then, keywords can be extracted from the task execution thinking chain and the input task text data, and these keywords are sent to the knowledge graph for relationship analysis and background expansion. This process enriches the associated information in the knowledge graph. Next, these keywords and their relationships are passed to the teacher model for relevance scoring, and then keywords and relationships with higher relevance scores are screened out to construct knowledge subnets. Finally, the thinking chain extracted from the large model and the relevant knowledge in the knowledge graph can be systematically passed to the student model.
[0080] The present embodiment provides a knowledge distillation method, which discloses parsing task text data corresponding to the task to be executed to construct a task execution thinking chain corresponding to the task to be executed, and the task to be executed includes: equipment fault diagnosis task; extracting keywords from the task text data and the task execution thinking chain to obtain high-relevance keywords; constructing a knowledge subnet based on the task execution knowledge graph and the high-relevance keywords; transferring and distilling knowledge to a student model through the knowledge subnet; since the present embodiment obtains high-relevance keywords based on the task text data of the task to be executed and the task execution thinking chain, and transfers and distills knowledge to the student model through the knowledge subnet constructed based on the task execution knowledge graph and the high-relevance keywords, the technical problem that the knowledge distillation method in the prior art has difficulties in expressing and transferring complex knowledge within a large model, resulting in the student model being unable to fully understand and master such knowledge, is solved.
[0081] Based on the first embodiment of the present application, in the second embodiment of the present application, the same or similar contents as those in the above-mentioned embodiment 1 can be referred to the above introduction, and will not be repeated in the following. Figure 4 , Figure 4 A schematic diagram of the process flow provided for Example 2 of the knowledge distillation method of this application.
[0082] In this embodiment, step S20 includes steps S201 to S204:
[0083] Step S201: extract keywords from the task text data and the task execution thought chain to obtain a number of target keywords.
[0084] It should be understood that the above-mentioned target keywords can be keywords in the steps or concepts in the task text data and the task execution thinking chain, such as keywords in questions, options and explanations extracted from the task text data and the task execution thinking chain. This embodiment does not limit this.
[0085] Step S202: Perform relationship analysis and background expansion on the task execution knowledge graph through the target keywords.
[0086] It should be noted that performing relationship analysis on the task execution knowledge graph can be to analyze the correlation between nodes in the knowledge graph; performing background expansion on the task execution knowledge graph can be a technology for applying the knowledge graph to a wider range of fields, such as semantic role labeling, entity linking, entity embedding, etc. This embodiment does not limit this. Through this process, the association relationships in the task execution knowledge graph can be enriched.
[0087] Step S203: When the expansion is completed, the target keywords are scored for relevance using the teacher model.
[0088] It can be understood that the above relevance score can be a score for the relevance between target keywords.
[0089] Step S204: determining highly relevant keywords from the target keywords based on the scoring results.
[0090] Furthermore, the step S30 includes: performing a knowledge node search in the task execution knowledge graph based on the high-relevance keywords to determine the target knowledge nodes and the node relationships between the target knowledge nodes; and constructing a knowledge subnet based on the target knowledge nodes and the node relationships.
[0091] In this embodiment, the target knowledge node may be a node in the task execution knowledge graph. After obtaining highly relevant keywords, relevant knowledge nodes and the relationships between knowledge nodes may be searched in the task execution knowledge graph through these highly relevant keywords, and a knowledge network closely related to the reasoning process may be constructed based on the knowledge nodes and the node relationships between the knowledge nodes.
[0092] It should be noted that the application of knowledge graphs can effectively solve the problem that the key information of the teacher model is submerged in noise during the knowledge distillation process. Traditional knowledge extraction methods often have difficulty reflecting the relationship between words, and cannot capture complex relationships from longer texts. Knowledge graphs intuitively display the relationship between nodes through triples (node 1-relationship-node 2). For example, through the formula (node 1, relationship, node 2), knowledge graphs can decompose complex text information into clear relationship chains, making it easier for student models to understand and learn these relationships. This structured information display method helps student models capture key information in the text and improve their understanding and application of knowledge through the relationship between nodes.
[0093] It should be understood that the knowledge graph not only helps the student model understand complex relationships, but also significantly improves the quality of knowledge distillation. By providing the student model with highly relevant knowledge points and the relationships between them as background information, the knowledge graph enriches the knowledge base of the student model, enabling it to better understand and apply these knowledge points. Specifically, through the interpretation of relationships, the student model can more clearly capture the key relationships in the input information, improving its reasoning ability and overall performance. For example, using the formula (e1, r, e2) to represent the relationship r between entities e1 and e2, the student model can more clearly identify which information is critical, thereby improving the efficiency and quality of knowledge extraction. In this way, the student model can not only avoid the interference of noise information, but also show stronger adaptability and generalization ability when facing new or complex tasks. Combining the advantages of thinking chain and knowledge graph, this solution realizes the comprehensiveness and systematicness of knowledge transfer, making the student model more accurate and efficient in knowledge mastery and application.
[0094] In the specific implementation, refer to Figure 5 , Figure 5 This is an example diagram of knowledge extraction related to the knowledge graph in the knowledge distillation method of this application. Figure 5As shown in the figure, first, the task text data (a beaver is famous for its building skills. Where do their materials come from? (A) British Columbia; (B) water areas; (C) forest areas; (D) paying debts; (E) zoos) and the data in the task execution thinking chain (beavers are famous for their ability to build complex dams and nests with branches, logs and mud. They collect these materials from woodlands near water bodies and build their homes here. Woodlands provide the necessary resources for beavers to demonstrate their building skills and create habitats) can be input into the teacher model. The teacher model extracts keywords from these data through keyword examples (keywords_prompt_template = "List the keywords in the questions, options and explanations. Keywords: extract keywords here"), and the extracted keywords can include: beaver, building skills, materials, dams, woodlands, etc., and then these keywords can be sent to the knowledge graph for relationship analysis and background expansion to enrich the associated information of the knowledge graph. Afterwards, these keyword machine relationships are transmitted to the teacher model for relevance scoring to screen out keywords and relationships with high relevance scores, and finally search for relevant knowledge nodes and relationships in the knowledge graph through these high-relevance key points to build a knowledge network closely related to the reasoning process. Figure 5 As shown, the output can now be: A[Beaver]—>|Displays|B[Construction Skills]; A[Beaver]—>|Requires|B[Materials]; C[Materials]—>|Obtained from|D[Forestland]; D[Forestland]—>|Provides|E[Branches]; D[Forestland]—>|Provides|F[Logs]; D[Forestland]—>|Provides|G[Soil]; B[Construction Skills]—>|Used to build|H[Dam]; B[Construction Skills]—>|Used to build|I[Nest]; H[Dam]—>|Located near|J[Water]; J[Nest]—>|Located near|J[Water]; J[Water]—>|Necessary|K[Habitat].
[0095] It should be noted that after the knowledge subnet is constructed, the knowledge transfer and distillation of the student model can be performed through the knowledge subnet, wherein the knowledge transfer and distillation is to efficiently transfer the knowledge in the teacher model to the student model by combining the knowledge graph related knowledge and the thinking chain. In this embodiment, not only can the student model learn the output of the teacher model, but also the student model is encouraged to learn the reasoning ability of the teacher model and its understanding of important global information. Specifically, this scheme can perform prefix labeling training models according to different given tasks and output them in different ways.
[0096] Specifically, refer to Figure 6 , Figure 6 Schematic diagram of knowledge transfer and distillation in the knowledge distillation method of this application. Figure 6The knowledge transfer and distillation process based on thought chain and knowledge graph in this scheme is demonstrated in . This method uses the reasoning power of large language models (LLM) to train smaller models in a data-efficient way. The process first lets the teacher model (LLM) predict the input data, generate label outputs, and provide detailed explanations of the prediction results. These explanations are provided in natural language and contain reasons to support the model's predicted labels. At the same time, the teacher model also extracts keywords from the input data and explanation content, and combines them with the knowledge graph to obtain highly relevant core information and knowledge points. Next, the student model learns and trains with the labels, explanations, and knowledge graphs provided by the teacher model. This scheme adds three task prefixes: answer, explanation, and knowledge graph before the input example, and trains the model for multi-task learning based on the given task prefixes.
[0097] It should be noted that this solution combines thought chains and knowledge graphs to ensure that the student model not only learns the correct output results, but also understands the reasoning process and key knowledge points of the teacher model. This multi-level knowledge transfer and distillation mechanism improves the learning efficiency and reasoning ability of the student model, and significantly improves the performance of the model in practical applications. By efficiently utilizing the reasoning ability of large models and rich knowledge graph resources, the present invention achieves the comprehensiveness and systematicness of knowledge transfer, ensuring efficient training and excellent performance of student models.
[0098] In this embodiment, keyword extraction of task text data and task execution thinking chain is disclosed to obtain several target keywords; relationship analysis and background expansion of the task execution knowledge graph are performed through the target keywords; when the expansion is completed, the target keywords are scored for relevance through the teacher model; based on the scoring results, high-relevance keywords are determined from the target keywords, thereby ensuring that the knowledge nodes and relationships extracted in the knowledge graph are highly relevant, thereby effectively avoiding the student model from being exposed to too many irrelevant knowledge points during the learning process, and reducing the error accumulation and performance degradation caused by the introduction of noise.
[0099] Based on the first embodiment and / or the second embodiment of the present application, in the third embodiment of the present application, the same or similar contents as those in the above embodiments can be referred to the above introduction, and will not be described in detail later. Figure 7 , Figure 7 A schematic diagram of the process flow provided for Example 3 of the knowledge distillation method of this application.
[0100] In this embodiment, after step S40, the knowledge distillation method further includes steps S50 to S70:
[0101] Step S50: Generate a prediction label based on the task text data through the teacher model.
[0102] It should be noted that the above-mentioned predicted labels can be labels generated after the teacher model predicts the input data.
[0103] Step S60: obtaining explanation information corresponding to the prediction result of the task to be executed through the teacher model.
[0104] It should be noted that the above explanation information may be information obtained after the teacher model gives a detailed explanation of the prediction results.
[0105] Step S70: Optimizing the student model based on the prediction label, the explanation information and the task execution knowledge graph.
[0106] Specifically, the step S70 includes:
[0107] Step S701: Determine the cross entropy loss between the predicted label and the target label based on the explanation information and the task execution knowledge graph.
[0108] Step S702: Based on the predicted label and the cross entropy loss, the student model is optimized by a preset optimization loss function.
[0109] Wherein, the preset optimization loss function is:
[0110]
[0111] Where, L label is the preset optimization loss function, N is the number of samples, L is the cross entropy loss, is the predicted label, f is the student model, x i is the input data of the student model.
[0112] It should be noted that 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. In the absence of manually annotated labels, task-specific distillation methods can use large language models (LLMs) to generate pseudo-noise training labels. Replace the true label (y i ). The smaller models f are trained by minimizing the label prediction loss, and the optimized loss function can be defined as:
[0113]
[0114] Furthermore, the step S701 includes: determining the explanation generation loss based on the explanation information; determining the knowledge graph information generation loss based on the key information in the task execution knowledge graph; and determining the cross entropy loss between the predicted label and the target label based on the explanation generation loss and the knowledge graph information generation loss.
[0115] It should be understood that the above-mentioned explanation generation loss can be a loss used to measure the difference between the predicted explanation information and the actual explanation information; the above-mentioned knowledge graph information generation loss can be a loss used to measure the difference between the key information of the knowledge graph and the actual key information.
[0116] In practical applications, in order to i ) and predicted labels To create a more explicit connection between And the key information of the knowledge graph As additional supervision information. In the present invention, the problem of learning explanations and knowledge graph information can be framed as a multi-task problem. Specifically, the model can be trained Not only predict the task label, but also generate the corresponding explanation as well as the key knowledge points and relationships. The loss function (i.e. the cross entropy loss mentioned above) is defined as:
[0117] L=λ1L label +λ2L explanation +(1-λ1-λ2)L knowledge-graph ;
[0118] In the formula, λ1 and λ2 are weight parameters, L label is the preset optimization loss function, L explanation To explain the generation loss, L knowledge-graph Generate loss for knowledge graph information.
[0119] In this embodiment, the explanation generation loss can be defined as:
[0120]
[0121] In the formula, Represents the explanations extracted by the student model.
[0122] The knowledge graph information generation loss is defined as:
[0123]
[0124] In the formula, Represents the key information of the knowledge graph.
[0125] It should be understood that after learning and training, the student model is able to make better predictions for new input questions. This knowledge transfer and distillation method based on thought chains and knowledge graphs 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 practical deployment.
[0126] In this embodiment, it is disclosed that a teacher model is used to generate prediction labels based on task text data; explanatory information corresponding to the prediction results of the task to be executed is obtained through the teacher model; and the student model is optimized based on the prediction labels, explanatory information and task execution knowledge graph, so that the student model can make better predictions for new input questions.
[0127] 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.
[0128] This application also provides a knowledge distillation device, please refer to Figure 8 , the knowledge distillation device comprises:
[0129] The thought chain construction module 10 is used to parse the task text data corresponding to the task to be executed to construct the task execution thought chain corresponding to the task to be executed, and the task to be executed includes: equipment fault diagnosis task;
[0130] A keyword extraction module 20 is used to extract keywords from the task text data and the task execution thought chain to obtain highly relevant keywords;
[0131] A knowledge network construction module 30, configured to construct a knowledge subnetwork based on the task execution knowledge graph and the highly relevant keywords;
[0132] The knowledge distillation module 40 is used to transfer and distill knowledge to the student model through the knowledge subnet.
[0133] The knowledge distillation device provided in the present application adopts the knowledge distillation method in the above-mentioned embodiment, which can solve the technical problem that the knowledge distillation method in the prior art has difficulties in expressing and transmitting complex knowledge within a large model, resulting in the student model being unable to fully understand and master such knowledge. Compared with the prior art, the beneficial effects of the knowledge distillation device provided in the present application are the same as the beneficial effects of the knowledge distillation method provided in the above-mentioned embodiment, and the other technical features in the knowledge distillation device are the same as the features disclosed in the above-mentioned embodiment method, which will not be described in detail here.
[0134] 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 that can be executed 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.
[0135] 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.
[0136] 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 wired to exchange data. Although the figure shows a knowledge distillation device with various systems, it should be understood that it is not required to implement or have all the systems shown. More or fewer systems can be implemented or have alternatively.
[0137] 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.
[0138] The knowledge distillation device provided by the present application adopts the knowledge distillation method in the above embodiment and can solve the technical problems of knowledge distillation. Compared with the prior art, the beneficial effects of the knowledge distillation device provided by the present 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.
[0139] 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.
[0140] 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.
[0141] 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.
[0142] 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.
[0143] 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.
[0144] 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: parses the task text data corresponding to the task to be executed to construct the task execution thinking chain corresponding to the task to be executed, and the task to be executed includes: equipment fault diagnosis task; extracts keywords from the task text data and the task execution thinking chain to obtain highly relevant keywords; constructs a knowledge subnet based on the task execution knowledge graph and the highly relevant keywords; and transfers and distills knowledge to the student model through the knowledge subnet.
[0145] 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).
[0146] 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.
[0147] 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.
[0148] 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, which can solve the technical problem that the knowledge distillation method in the prior art has difficulties in expressing and transmitting complex knowledge within a large model, resulting in the student model being unable to fully understand and master such knowledge. 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 elaborated here.
[0149] 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, It is characterized in that The method includes: Parsing the task text data corresponding to the task to be executed to construct a task execution thought chain corresponding to the task to be executed, wherein the task to be executed includes: equipment fault diagnosis task; Extracting keywords from the task text data and the task execution thought chain to obtain highly relevant keywords; Constructing a knowledge subnet based on the task execution knowledge graph and the highly relevant keywords; The knowledge subnet is used to transfer and distill knowledge to the student model.
2. The method according to claim 1, It is characterized in that The step of parsing the task text data corresponding to the task to be executed to construct a task execution thought chain corresponding to the task to be executed includes: Performing semantic analysis on the task text data corresponding to the task to be executed, so as to extract all semantic units in the task text data and semantic information between the semantic units; Determining the logical relationship between the semantic units based on the semantic information; A task execution thought chain corresponding to the task to be executed is constructed based on the logical relationship.
3. The method according to claim 1, It is characterized in that The step of extracting keywords from the task text data and the task execution thought chain to obtain highly relevant keywords includes: Extracting keywords from the task text data and the task execution thought chain to obtain a number of target keywords; Performing relationship analysis and background expansion on the task execution knowledge graph through the target keywords; When the expansion is completed, the target keywords are scored for relevance through the teacher model; Highly relevant keywords are determined from the target keywords based on the scoring results.
4. The method according to any one of claims 1 to 3, It is characterized in that The step of constructing a knowledge subnet based on the task execution knowledge graph and the highly relevant keywords includes: Performing a knowledge node search in the task execution knowledge graph based on the highly relevant keywords to determine target knowledge nodes and node relationships between the target knowledge nodes; A knowledge subnet is constructed based on the target knowledge nodes and the node relationships.
5. The method according to claim 3, It is characterized in that After the step of transferring and distilling the knowledge of the student model through the knowledge subnet, the method further includes: Generate a prediction label based on the task text data by the teacher model; Obtaining explanation information corresponding to the prediction result of the task to be performed through the teacher model; The student model is optimized based on the predicted labels, the explanation information and the task execution knowledge graph.
6. The method according to claim 5, It is characterized in that The step of optimizing the student model based on the predicted label, the explanation information and the task execution knowledge graph includes: Determine a cross entropy loss between the predicted label and the target label based on the explanation information and the task execution knowledge graph; Based on the predicted label and the cross entropy loss, optimizing the student model by a preset optimization loss function; Wherein, the preset optimization loss function is: Where, L label is the preset optimization loss function, N is the number of samples, L is the cross entropy loss, is the predicted label, f is the student model, x i is the input data of the student model.
7. The method according to claim 6, It is characterized in that The step of determining the cross entropy loss between the predicted label and the target label based on the explanation information and the task execution knowledge graph includes: determining an interpretation generation loss based on the interpretation information; Determining knowledge graph information generation loss based on key information in the task execution knowledge graph; A cross entropy loss between the predicted label and the target label is determined based on the explanation generation loss and the knowledge graph information generation loss.
8. A knowledge distillation device, It is characterized in that The device comprises: A thought chain building module is used to parse the task text data corresponding to the task to be executed to build a task execution thought chain corresponding to the task to be executed, and the task to be executed includes: equipment fault diagnosis task; A keyword extraction module is used to extract keywords from the task text data and the task execution thought chain to obtain highly relevant keywords; A knowledge network construction module, used to construct a knowledge subnet based on the task execution knowledge graph and the highly relevant keywords; The knowledge distillation module is used to transfer and distill knowledge to the student model through the knowledge subnet.
9. A knowledge distillation device, It is 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 as described in any one of claims 1 to 7.
10. A storage medium, It is characterized in that The storage medium is a computer-readable storage medium, and a computer program is stored on the storage medium. When the computer program is executed by a processor, the steps of the knowledge distillation method as described in any one of claims 1 to 7 are implemented.
Citation Information
Patent Citations
Large language model distillation method based on thinking chain
CN116739110A
Large model reasoning analysis method, system and product based on external knowledge enhancement
CN117575026A
Knowledge distillation method and apparatus, and terminal device and medium
WO2023279693A1
Cited By
Model distillation method and system based on teacher model and situational reasoning
CN119539011A
