LLM model fine tuning method based on medical knowledge graph and related equipment
Through the LLM model fine-tuning method based on medical knowledge graph, the problem of error inference of large-scale language models in medical application scenarios is solved, the inference performance and accuracy of the model are improved, and users can obtain reliable medical Q&A services.
Patent Information
- Application Number
- CN202411297642.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-14
- Publication Date
- 2025-01-10
AI Technical Summary
Large-scale language models often experience misinferences and hallucinations in specific medical application scenarios due to lack of expertise in specific medical applications, resulting in poor user experience and may have serious negative impacts.
By obtaining medical knowledge graph structure information related to the target application scenario, generating question templates and answer path templates, generating question and answer samples based on these templates, fine-tuning training of the pre-trained LLM model, so that the model can learn professional knowledge, improve inference performance and accuracy.
It improves the accuracy and reliability of the LLM model in medical reasoning tasks, meets the actual needs of users, ensures that the model generates appropriate answer paths and querys the knowledge graph, and provides rigorous and reliable medical Q&A services.
Smart Images

Figure CN119294486A_ABST
Abstract
Description
Technical Field
[0001] One or more embodiments of this specification relate to the field of large model technology, and in particular, to an LLM model fine-tuning method based on a medical knowledge graph and related equipment. Background Art
[0002] Large Language Models (LLM), or pre-trained models, are language models built with deep neural networks containing more than tens of billions of parameters. They use self-supervised learning methods to master many language phenomena through pre-training on large and diverse public datasets.
[0003] Furthermore, by using a data set related to a specific application scenario to perform fine-tuning training on the pre-trained LLM basic model, an LLM service model for performing reasoning tasks related to the specific application scenario can be obtained.
[0004] However, when performing reasoning tasks, the LLM service model often suffers from hallucinations due to the lack of expertise related to specific application scenarios, that is, the output is erroneous inferences that are completely inconsistent with the facts, which not only brings a very bad user experience, but the erroneous inferences may even have serious negative impacts on users. Summary of the invention
[0005] In view of this, one or more embodiments of the present specification provide a method and related equipment for fine-tuning an LLM model based on a medical knowledge graph.
[0006] In a first aspect, this specification provides a method for fine-tuning an LLM model based on a knowledge graph, the method comprising:
[0007] Acquire structural information of a knowledge graph related to a target application scenario; the structural information includes a plurality of entity types predefined in the knowledge graph, and the relationship between the plurality of entity types;
[0008] Based on the structural information, a question template corresponding to the reasoning task related to the target application scenario and an answer path template corresponding to the question template are generated; the question template includes a first entity type corresponding to the question object; the answer path template includes: a graph path consisting of the first entity type corresponding to the question object, a second entity type corresponding to the answer to the question, and a relationship between the first entity type and the second entity type;
[0009] A question-answer sample pair is generated based on the question template and the answer path template, and based on the question-answer sample pair, the pre-trained LLM basic model is further fine-tuned to obtain an LLM service model for performing the reasoning task.
[0010] In a second aspect, this specification provides an LLM model fine-tuning device based on a knowledge graph, the device comprising:
[0011] An acquisition unit, configured to acquire structural information of a knowledge graph related to a target application scenario; the structural information includes a plurality of entity types predefined in the knowledge graph, and the relationship between the plurality of entity types;
[0012] A generating unit, configured to generate, based on the structural information, a question template corresponding to a reasoning task related to the target application scenario, and an answer path template corresponding to the question template; the question template includes a first entity type corresponding to a question object; the answer path template includes: a graph path consisting of the first entity type corresponding to the question object, a second entity type corresponding to an answer to the question, and a relationship between the first entity type and the second entity type;
[0013] A fine-tuning unit is used to generate a question-answer sample pair based on the question template and the answer path template, and based on the question-answer sample pair, further perform fine-tuning training on the pre-trained LLM basic model to obtain an LLM service model for performing the reasoning task.
[0014] Accordingly, this specification also provides a computing device, comprising: a memory and a processor; the memory stores computer programs / instructions that can be executed by the processor; when the processor executes the computer program / instructions, it executes the LLM model fine-tuning method based on the knowledge graph described in the first aspect above.
[0015] Accordingly, this specification also provides a computer-readable storage medium on which a computer program / instruction is stored. When the computer program / instruction is executed by a processor, the LLM model fine-tuning method based on the knowledge graph as described in the first aspect above is executed.
[0016] Accordingly, the present specification also provides a computer program product, which includes a computer program / instructions. When the computer program / instructions are executed by a processor, the LLM model fine-tuning method based on the knowledge graph as described in the first aspect above is performed.
[0017] In summary, the present application first obtains the structural information of the knowledge graph related to the target application scenario, and the structural information may include multiple entity types predefined in the knowledge graph, and the relationship between multiple entity types. Furthermore, based on the structural information, a question template corresponding to the reasoning task related to the target application scenario and an answer path template corresponding to the question template may be generated. Among them, the question template includes a first entity type corresponding to the question object, and the answer path template includes: a graph path consisting of the first entity type corresponding to the question object, the second entity type corresponding to the answer to the question, and the relationship between the first entity type and the second entity type. Furthermore, based on the question template and the answer path template, a corresponding question and answer sample pair is generated, and then based on the question and answer sample pair, the pre-trained LLM basic model is further fine-tuned to obtain an LLM service model for performing the above-mentioned reasoning tasks. In this way, this application generates question templates and answer path templates corresponding to the reasoning tasks of the target application scenarios based on the structural information of the knowledge graph, and then generates corresponding question and answer samples based on these question templates and answer path templates. Finally, based on the question and answer sample pairs, the pre-trained LLM basic model is fine-tuned so that the model can learn comprehensive professional knowledge in the knowledge graph. Subsequently, in the model reasoning stage, it can generate a suitable answer path according to user input and use the path to query the knowledge graph, thereby improving the reasoning performance of the model, ensuring the accuracy and reliability of the model reasoning results, and meeting the actual usage needs of users. BRIEF DESCRIPTION OF THE DRAWINGS
[0018] Figure 1 It is a flowchart of a method for fine-tuning an LLM model based on a knowledge graph provided by an exemplary embodiment;
[0019] Figure 2 is a schematic diagram of a knowledge graph schema provided by an exemplary embodiment;
[0020] Figure 3 It is a flowchart of another LLM model fine-tuning method based on knowledge graph provided by an exemplary embodiment;
[0021] Figure 4 It is a structural schematic diagram of a knowledge graph-based LLM model fine-tuning device provided by an exemplary embodiment;
[0022] Figure 5 It is a structural diagram of a computing device provided by an exemplary embodiment. DETAILED DESCRIPTION
[0023] Exemplary embodiments will be described in detail herein, examples of which are shown in the accompanying drawings. When the following description refers to the drawings, the same numbers in different drawings represent the same or similar elements unless otherwise indicated. The implementations described in the following exemplary embodiments do not represent all implementations consistent with one or more embodiments of this specification. Instead, they are merely examples of devices and methods consistent with some aspects of one or more embodiments of this specification as detailed in the appended claims.
[0024] It should be noted that: in other embodiments, the steps of the corresponding method are not necessarily performed in the order shown and described in this specification. In some other embodiments, the steps included in the method may be more or less than those described in this specification. In addition, a single step described in this specification may be decomposed into multiple steps for description in other embodiments; and multiple steps described in this specification may be combined into a single step for description in other embodiments.
[0025] It should be noted that the “plurality” mentioned in this application refers to two or more than two.
[0026] In addition, the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with the relevant laws, regulations and standards of the relevant countries and regions, and provide corresponding operation entrances for users to choose to authorize or refuse.
[0027] This specification provides a technical solution for generating professional question templates and answer path templates based on the structural information of the knowledge graph, and using the question and answer samples generated by these question templates and answer path templates to fine-tune the model, so that the model can learn the professional knowledge in the knowledge graph and improve the reasoning performance of the model.
[0028] During implementation, first obtain the structural information of the knowledge graph related to the target application scenario. The structural information may include multiple entity types predefined in the knowledge graph, and the relationship between multiple entity types. Furthermore, based on the structural information, a question template corresponding to the reasoning task related to the target application scenario and an answer path template corresponding to the question template may be generated. Among them, the question template includes a first entity type corresponding to the question object, and the answer path template includes: a graph path consisting of the first entity type corresponding to the question object, the second entity type corresponding to the answer to the question, and the relationship between the first entity type and the second entity type. Furthermore, based on the question template and the answer path template, a corresponding question and answer sample pair is generated, and then based on the question and answer sample pair, the pre-trained LLM basic model is further fine-tuned to obtain an LLM service model for performing the above-mentioned reasoning tasks.
[0029] In the above technical scheme, this application generates question templates and answer path templates corresponding to the reasoning tasks of the target application scenarios based on the structural information of the knowledge graph, and then generates corresponding question and answer samples based on these question templates and answer path templates. Finally, based on the question and answer sample pairs, the pre-trained LLM basic model is fine-tuned so that the model can learn comprehensive professional knowledge in the knowledge graph. Subsequently, in the model reasoning stage, the appropriate answer path can be generated according to the user input and the knowledge graph can be queried using the path, thereby improving the reasoning performance of the model, ensuring the accuracy and reliability of the model reasoning results, and meeting the actual usage needs of users.
[0030] See also Figure 1 , Figure 1 This is a flowchart of a method for fine-tuning an LLM model based on a knowledge graph provided by an exemplary embodiment. The method can be applied to a computing device, such as a smart wearable device, a smart phone, a tablet computer, a laptop computer, a desktop computer, and a server, etc., which is not specifically limited in this specification. Figure 1 As shown, the method may specifically include the following steps S101 to S103.
[0031] Step S101, obtaining structural information of a knowledge graph related to a target application scenario; the structural information includes a plurality of entity types predefined in the knowledge graph, and the relationship between the plurality of entity types.
[0032] In one illustrated embodiment, the computing device may first obtain a pre-trained LLM basic model, wherein the LLM basic model has mastered many language phenomena through pre-training and is capable of processing reasoning tasks based on natural language understanding.
[0033] Furthermore, in order to apply the LLM basic model to reasoning tasks related to specific target application scenarios, it is necessary to further fine-tune the LLM basic model through data sets related to the target application scenarios, so as to obtain an LLM service model that can smoothly perform reasoning tasks related to the target application scenarios.
[0034] It should be noted that this specification does not specifically limit the specific type of the target application scenario. In one embodiment shown, the target application scenario can be a medical consultation scenario, a life assistant scenario, or a sentiment analysis scenario, etc., and this specification does not specifically limit this. Accordingly, taking the target application scenario as a medical consultation scenario as an example, the above-mentioned reasoning task can be a medical diagnosis task.
[0035] Based on the fine-tuning requirements for the above-mentioned target application scenarios, after obtaining the pre-trained LLM basic model, the computing device can obtain the structural information of the knowledge graph corresponding to the target application scenario. Among them, the knowledge graph contains multiple nodes and edges connecting the nodes. The nodes represent entities, and the edges represent the relationships between entities. Its basic component unit is the "entity-relationship-entity" triple. Among them, the structural information of the knowledge graph, that is, the graph schema (structure), usually includes multiple entity types predefined in the knowledge graph, and the relationships between multiple entity types. In addition, it can also include information such as the attributes of the entity. This manual does not make specific restrictions on this. The computing device can obtain comprehensive structural information by traversing the graph schema.
[0036] Exemplarily, taking the medical consultation scenario as an example, the above-mentioned knowledge graph may be a medical knowledge graph, in which the multiple entity types contained therein may be diseases, symptoms, treatments, drugs, examinations, etc., and this specification does not make any specific limitations on this.
[0037] For example, see Figure 2 , Figure 2 is a schematic diagram of a knowledge graph schema provided by an exemplary embodiment. Figure 2 As shown, taking the medical scenario as an example, the schema of the medical knowledge graph may include predefined entity types such as "symptoms", "diseases", "drugs" and "treatments", as well as the relationships between these multiple entity types. For example, the relationship between the entity type "symptoms" and the entity type "disease" is the symptoms of the disease, and the relationship between the entity type "disease" and the entity type "drug" is the applicable drug for the disease, and the relationship between the entity type "disease" and the entity type "treatment" is the treatment method for the disease, and so on. This specification does not make specific limitations on this.
[0038] It should be understood that in the knowledge graph, each entity type corresponds to multiple entities (or entity instances). For example, the entity type "disease" corresponds to entities such as "gastric cancer", "cold" and "pneumonia". Another example is that the entity type "symptom" corresponds to entities such as "stomach pain", "runny nose" and "fever". These will not be elaborated here.
[0039] Step S102, based on the structural information, generate a question template corresponding to the reasoning task related to the target application scenario, and an answer path template corresponding to the question template; the question template includes a first entity type corresponding to the question object; the answer path template includes: a graph path composed of the first entity type corresponding to the question object, a second entity type corresponding to the answer to the question, and the relationship between the first entity type and the second entity type.
[0040] Furthermore, after obtaining the structural information of the knowledge graph corresponding to the target application scenario, a question template corresponding to the reasoning task related to the target application scenario and an answer path template corresponding to the question template can be generated based on the structural information.
[0041] The question template may include a first entity type corresponding to the question object.
[0042] The answer path template may include: a graph path consisting of a first entity type corresponding to the question object, a second entity type corresponding to the answer to the question, and a relationship between the first entity type and the second entity type.
[0043] For example, still taking the medical consultation scenario as an example, the question template and the corresponding answer path template generated based on the structural information of the medical knowledge graph can be shown in the following examples.
[0044] Example 1:
[0045] Question template: What are the symptoms of $disease$?
[0046] Answer path template: disease-symptom-symptom.
[0047] Among them, the question intention corresponding to the question template is to ask about the symptoms of a certain disease; the entity type "disease" in the question template is the first entity type corresponding to the question object; the path contained in the answer path template passes through in sequence: the first entity type "disease" corresponding to the question object, the relationship between the first entity type "disease" and the second entity type "symptoms" - "symptoms", and the second entity type "symptoms" corresponding to the answer to the question, that is, the starting point of the path is the entity type "disease" and the end point of the path is the entity type "symptoms".
[0048] Example 2:
[0049] Question template: What is the treatment for $disease$?
[0050] Answer path template: disease-treatment method-treatment.
[0051] Among them, the question intention corresponding to the question template is to ask about the treatment method of a certain disease; the entity type "disease" in the question template is the first entity type corresponding to the question object; the path contained in the answer path template passes through in sequence: the first entity type "disease" corresponding to the question object, the relationship between the first entity type "disease" and the second entity type "treatment" - "treatment method", and the second entity type "treatment" corresponding to the answer to the question, that is, the starting point of the path is the entity type "disease" and the end point of the path is the entity type "treatment".
[0052] Example 3:
[0053] Question template: What disease might this cause if $symptoms$ appear?
[0054] Answer path template: symptom-symptom-disease.
[0055] Among them, the question intention corresponding to the question template is to ask what disease a certain symptom may be caused by; the entity type "symptom" in the question template is the first entity type corresponding to the question object; the path contained in the answer path template passes through in sequence: the first entity type "symptom" corresponding to the question object, the relationship between the first entity type "symptom" and the second entity type "disease" - "symptom", and the second entity type "disease" corresponding to the answer to the question, that is, the starting point of the path is the entity type "symptom" and the end point of the path is the entity type "disease".
[0056] In addition, it should be noted that this specification does not specifically limit the specific implementation method of how to generate the question template and the answer path template based on the structural information.
[0057] In one illustrated embodiment, a prompt word can be generated based on the structural information and input into a template generation model, which can then generate a question template corresponding to a reasoning task related to the target application scenario and an answer path template corresponding to the question template based on the prompt word.
[0058] Exemplarily, the template generation model may be an open source large model, such as any possible model such as Qwen or ChatGLM4, and this specification does not specifically limit this.
[0059] Furthermore, after generating a large number of question templates and corresponding answer path templates based on the structural information of the knowledge graph, in order to improve the fine-tuning training effect of the model and thus ensure the reliability of the fine-tuned model when performing reasoning tasks, the generated question templates and answer path templates can be optimized and adjusted.
[0060] In one illustrated embodiment, the computing device can adjust the question template and the answer path template based on a predefined reasoning logic corresponding to the above-mentioned reasoning task, so as to obtain a question template and an answer path template that conform to the reasoning logic. In this way, when the model is subsequently fine-tuned based on the question and answer sample pairs generated by the adjusted question template and answer path template, the model can learn the reasoning logic therein, thereby improving the reasoning performance.
[0061] It should be noted that this specification does not specifically limit the specific adjustment method of the question template and the answer path template.
[0062] In an illustrated embodiment, the question template and the answer path template can be adjusted by a professional corresponding to the target application scenario, so as to obtain a question template and an answer path template that conform to the reasoning logic. Exemplarily, the computing device can display the generated question template and the answer path template to the target person corresponding to the target application scenario through a display screen output. Accordingly, the target person can input adjustment information for the question template and the answer path template based on the predefined reasoning logic through an input device (such as a keyboard or a touch screen, etc.) provided by the computing device. Further, the computing device can receive the adjustment information input by the target person, and adjust the question template and the answer path template based on the received adjustment information, so as to obtain a question template and an answer path template that conform to the above-mentioned reasoning logic.
[0063] For example, still taking the medical scenario as an example, the above-mentioned target personnel can be medical personnel (such as doctors, nurses, medical students or medical professors, etc.), and the reasoning logic corresponding to the medical diagnosis task can be a medical diagnosis logic summarized based on clinical practice experience and diagnosis and treatment guidelines, etc. This specification does not make specific limitations on this.
[0064] The following will illustrate the adjustment of the question template and the answer path template through several examples.
[0065] Exemplarily, take the question template "What are the symptoms of $disease$?" and the answer path template "Disease-Symptoms-Symptoms" in the above example 1 as an example. It should be understood that in the medical field, many patients will use different terms to express the same consultation needs, or many medical personnel will even use different terms in different sources of diagnosis and treatment guidelines to express the same medical situation. Therefore, based on clinical practice experience, when asking about the symptoms of the disease in Example 1, in addition to directly using the word "symptoms", any other possible words such as "clinical manifestations" can also be used. Based on this, a new question template "What are the clinical manifestations of $disease$?" can be added. It should be understood that although the word "symptoms" is not directly used in the newly added question template, in the medical field, symptoms and clinical manifestations are synonymous words, so the question intention corresponding to the question template is still to ask about the symptoms of a certain disease, and the corresponding answer path template is still "Disease-Symptoms-Symptoms".
[0066] For example, take the question template "What is the treatment for $disease$?" and the answer path template "Disease-Treatment Method-Treatment" in the above example 2 as an example. When patients ask about the treatment of a disease, they sometimes do not want to be hospitalized or undergo surgery, but simply want to take some medicine for treatment. Therefore, based on clinical practice experience, for the question template "What is the treatment for $disease$?", a new answer path template "Disease-Applicable Drugs-Drugs" can be added to fully cover the user's consultation needs.
[0067] For example, take the question template "What disease might $symptom$ indicate?" and the answer path template "symptom-symptom-disease" in the above example three as an example. In the records of the medical knowledge graph, for example, the symptom "stomach pain" may be caused by a variety of diseases, such as gastric ulcer, gastric spasm, acute gastroenteritis and even gastric cancer (late stage). If all possible disease entities are obtained from the knowledge graph and answered to the user directly based on the above original answer path template, it will not solve the patient's actual problem, but will cause panic to the patient. Based on the medical diagnosis logic in clinical practice experience, when the user asks about the possible cause of the current symptoms, the user should be further verified whether he has done relevant examinations and what the examination results are, and then the disease diagnosis should be made based on the objective examination results. Based on this, the above answer path template "symptom-symptom-disease" can be adjusted to "symptom-examination-examination".
[0068] As mentioned above, through the adjustment of question templates and answer path templates by medical personnel, medical expertise and actual clinical practice experience are integrated into the question templates, and the medical expert alignment (HealthExpert Alignment) of the question templates and answer path templates is achieved. This not only ensures the clinical accuracy and practicality of the question templates and answer path templates, but also ensures that the question templates and answer path templates are applicable to actual patient consultation scenarios, thereby ensuring the logical rigor and reliability of the subsequent fine-tuned LLM service model when conducting medical questions and answers.
[0069] Step S103, generating a question-answer sample pair based on the question template and the answer path template, and further performing fine-tuning training on the pre-trained LLM basic model based on the question-answer sample pair to obtain an LLM service model for performing the reasoning task.
[0070] Furthermore, corresponding question-answer sample pairs can be generated based on the adjusted question template and answer path template. Subsequently, based on the question-answer sample pairs, the pre-trained LLM basic model can be further fine-tuned to obtain the LLM service model for performing the above-mentioned reasoning tasks.
[0071] See also Figure 3 , Figure 3 FIG. 1 is a flowchart of another LLM model fine-tuning method based on a knowledge graph provided by an exemplary embodiment. Figure 3 As shown, the question template and the answer path template can be filled in based on the entity relationship instance in the knowledge graph, thereby generating a corresponding question and answer sample pair. Specifically, a number of first entities corresponding to the first entity type in the question template and the answer path template contained in the knowledge graph can be obtained first, and then the question template and the answer path template can be filled in based on the first entities, thereby generating a corresponding question and answer sample pair.
[0072] Exemplarily, taking the question templates in Examples 1, 2 and 3 above as an example, the first entity type corresponding to the question object in each question template can be represented by an identifier (for example, the placeholder $disease$). Based on this, the computing device can replace the identifier used to represent the first entity type contained in the question template with each of the first entities in turn, thereby obtaining a number of question texts (or query statements) corresponding to the first entities.
[0073] Exemplarily, taking the answer path templates in the above examples 1, 2, and 3 as examples, the first entity type corresponding to the question object in each answer path template can also be represented by an identifier (such as a placeholder $disease$). Based on this, the computing device can replace the identifier used to represent the first entity type contained in the answer path template with each of the first entities in turn, thereby obtaining a number of answer paths (or query paths) corresponding to the first entities.
[0074] For example, taking the question template "What are the symptoms of $disease$?" in the above example 1 and the answer path template "disease-symptoms-symptoms" as an example, several first entities corresponding to the first entity type "disease" obtained from the medical knowledge graph may include "gastric cancer", "cold" and "pneumonia" etc.
[0075] Based on this, the placeholder "$disease$" representing the first entity type in the question template can be replaced with "gastric cancer", "cold" and "pneumonia" respectively, thereby obtaining the question text "What are the symptoms of gastric cancer?", the question text "What are the symptoms of a cold?", and the question text "What are the symptoms of pneumonia?", etc. This manual does not make any specific limitations on this.
[0076] Furthermore, the first entity type "disease" in the answer path template can be replaced with "gastric cancer", "cold" and "pneumonia" in turn, thereby obtaining the answer path "gastric cancer-symptoms-symptoms", the answer path "cold-symptoms-symptoms", and the answer path "pneumonia-symptoms-symptoms", etc. This specification does not make any specific limitations on this.
[0077] For example, taking the question template "What is the treatment for $disease$?" in the above example 2 and the answer path template "disease-treatment method-treatment" as an example, several first entities corresponding to the first entity type "disease" obtained from the medical knowledge graph may include "gastric cancer", "cold" and "pneumonia" etc.
[0078] Based on this, the placeholder "$disease$" representing the first entity type in the question template can be replaced with "gastric cancer", "cold" and "pneumonia" respectively, thereby obtaining the question text "What is the treatment for gastric cancer?", the question text "What is the treatment for cold?", and the question text "What is the treatment for pneumonia?", etc. This manual does not make any specific limitations on this.
[0079] Furthermore, the first entity type "disease" in the answer path template can be replaced with "gastric cancer", "cold" and "pneumonia" in turn, thereby obtaining the answer path "gastric cancer-treatment method-treatment", the answer path "cold-treatment method-treatment", and the answer path "pneumonia-treatment method-treatment", etc. This specification does not make any specific limitations on this.
[0080] For example, taking the question template "What disease might $symptom$ indicate?" and the answer path template "symptom-symptom-disease" in the above example three as examples, several first entities corresponding to the first entity type "symptom" obtained from the medical knowledge graph may include "stomachache", "runny nose" and "fever" etc.
[0081] Based on this, the placeholder "$symptom$" representing the first entity type in the question template can be replaced with "stomachache", "runny nose" and "fever" respectively, thereby obtaining the question text "What disease may cause stomachache?", the question text "What disease may cause runny nose?", and the question text "What disease may cause fever?", etc. This manual does not make any specific limitations on this.
[0082] Furthermore, the first entity type "symptom" in the answer path template can be replaced with "stomachache", "runny nose" and "fever" in turn, thereby obtaining the answer path "stomachache-symptom-disease", the answer path "runny nose-symptom-disease", and the answer path "fever-symptom-disease", etc. This specification does not make any specific limitations on this.
[0083] Furthermore, the computing device may generate several question-answer sample pairs based on the above-mentioned several question texts and several answer paths; wherein each question-answer sample pair may include a question text and an answer path corresponding to the question text. For example, the question text "What are the symptoms of gastric cancer?" and the answer path "gastric cancer-symptoms-symptoms" may constitute a question-answer sample pair; for another example, the question text "What is the treatment for gastric cancer?" and the answer path "gastric cancer-treatment method-treatment" may constitute a question-answer sample pair; for another example, the question text "What disease may cause stomach pain?" and the answer path "gastric pain-symptoms-disease" may constitute a question-answer sample pair, and so on, which will not be elaborated here.
[0084] In this way, the present application can generate a large number of sufficient question-answer sample pairs by traversing all paths and entities in the knowledge graph, so that the fine-tuned model can have sufficient generalization ability.
[0085] In addition, it should be noted that this specification does not specifically limit the specific implementation method of fine-tuning the LLM basic model based on question and answer sample pairs. In one embodiment shown, the LLM basic model can be fine-tuned and trained by various methods such as supervised fine-tuning (Supervised Fine-tuning, SFT) or preference fine-tuning. Furthermore, when using supervised fine-tuning, various methods such as full parameter fine-tuning or partial parameter fine-tuning can be selected. This specification does not specifically limit this. During the fine-tuning process, the model will learn how to quickly and accurately generate an answer path, so as to use the generated answer path to query the knowledge graph, thereby answering questions such as "What are the symptoms of gastric cancer?"
[0086] In one illustrated embodiment, in order to ensure the accuracy of answer path generation while minimizing the response time of the model and ensuring the user experience, the present application may choose to fine-tune the LLM basic model of a smaller scale of 1B to 5B size to improve the practicality and accuracy of the model, etc. This specification does not make any specific limitations on this.
[0087] Furthermore, if Figure 3 As shown, after the fine-tuning training is completed, the services related to the target application scenario can be deployed based on the LLM service model obtained after the fine-tuning training to perform the corresponding reasoning tasks. In one embodiment shown, still taking the medical consultation scenario as an example, the LLM service model obtained after fine-tuning training is the medical LLM model, which can be used to implement Medical Knowledge Graph QA, that is, using the medical knowledge graph to answer related questions, by understanding the medical questions raised by users in natural language, generating corresponding answer paths, retrieving the medical knowledge graph, and then inferring the answers, which can be widely used in medical information query and auxiliary diagnosis services, and will not be elaborated here.
[0088] In an illustrated embodiment, when the LLM service model performs a reasoning task, it may specifically include: the computing device obtains a target text input by the user, and the target text may contain a question entity corresponding to the question object. Exemplarily, the target text is "What are the symptoms of gastric cancer?", wherein "gastric cancer" is a question entity corresponding to the question object. Further, the target text may be input into the LLM service model, and the LLM service model generates a corresponding answer path based on the target text; wherein the answer path includes: a graph path consisting of the above-mentioned question entity, the answer entity type corresponding to the question answer, and the relationship between the entity type of the question entity and the answer entity type. Exemplarily, the answer path may be "gastric cancer-symptoms-symptoms", and the answer entity type corresponding to the question answer is "symptoms". Further, based on the generated answer path, several answer entities corresponding to the answer entity type in the answer path (such as "stomachache", "loss of appetite" and "vomiting", etc.) contained in the knowledge graph may be searched, and then, based on the several answer entities, an answer text corresponding to the target text is generated, and output and displayed to the user, etc., and this specification does not specifically limit this.
[0089] In summary, this application traverses the graph schema, uses the open source large model to fully generate question templates and corresponding answer path templates, and generates enough question and answer sample pairs by combining the specific entity relationship instances of the graph, so that the model has sufficient question and answer generalization performance. In addition, this application also reviews and supplements the question templates and answer path templates by professionals (such as doctors), so that the final generated question and answer sample pairs can be closer to the answer standards of real doctors, ensuring that the model can provide rigorous and accurate answers in medical consultation scenarios and meet the user's consultation needs.
[0090] Corresponding to the implementation of the above method flow, the embodiment of this specification also provides an LLM model fine-tuning device based on knowledge graph. The device can be applied to a computing device, such as a smart wearable device, a smart phone, a tablet computer, a laptop computer, a desktop computer, etc., which is not specifically limited in this specification. Please refer to Figure 4 , Figure 4 FIG. 1 is a schematic diagram of a structure of an LLM model fine-tuning device based on a knowledge graph provided by an exemplary embodiment. Figure 4 As shown, the device 40 includes:
[0091] An acquisition unit 401 is used to acquire structural information of a knowledge graph related to a target application scenario; the structural information includes a plurality of entity types predefined in the knowledge graph, and the relationship between the plurality of entity types;
[0092] A generating unit 402 is used to generate a question template corresponding to the reasoning task related to the target application scenario and an answer path template corresponding to the question template based on the structural information; the question template includes a first entity type corresponding to the question object; the answer path template includes: a graph path consisting of the first entity type corresponding to the question object, a second entity type corresponding to the answer to the question, and a relationship between the first entity type and the second entity type;
[0093] The fine-tuning unit 403 is used to generate a question-answer sample pair based on the question template and the answer path template, and based on the question-answer sample pair, further perform fine-tuning training on the pre-trained LLM basic model to obtain an LLM service model for performing the reasoning task.
[0094] In an illustrated embodiment, the generating unit 402 is specifically configured to:
[0095] Prompt words are generated based on the structural information, and the prompt words are input into a template generation model, and the template generation model generates a question template corresponding to the reasoning task related to the target application scenario based on the prompt words, and an answer path template corresponding to the question template.
[0096] In an illustrated embodiment, the fine-tuning unit 403 is specifically configured to:
[0097] Obtaining a plurality of first entities corresponding to the first entity type contained in the knowledge graph;
[0098] replacing the identifier for representing the first entity type contained in the question template with each of the first entities in sequence, to obtain a plurality of question texts corresponding to the first entities;
[0099] replacing the identifier for indicating the first entity type contained in the answer path template with each of the first entities in sequence, to obtain a plurality of answer paths corresponding to the first entities;
[0100] Based on the several question texts and the several answer paths, several question-answer sample pairs are generated; wherein each question-answer sample pair includes a question text and an answer path corresponding to the question text.
[0101] In an illustrated embodiment, the fine-tuning unit 403 is specifically configured to:
[0102] Based on a predefined reasoning logic corresponding to the reasoning task, the question template and the answer path template are adjusted to obtain a question template and an answer path template that conform to the reasoning logic;
[0103] Generate a question-answer sample pair based on the adjusted question template and the answer path template.
[0104] In an illustrated embodiment, the fine-tuning unit 403 is specifically configured to:
[0105] Outputting the question template and the answer path template to display to the target person;
[0106] Receive adjustment information input by the target person for the question template and the answer path template based on the predefined reasoning logic, and adjust the question template and the answer path template based on the adjustment information to obtain the question template and the answer path template that conform to the reasoning logic.
[0107] In one illustrated embodiment, the target application scenario includes a medical consultation scenario, the reasoning task includes a medical diagnosis task, the predefined reasoning logic includes a medical diagnosis logic, and the target personnel includes medical personnel.
[0108] In an illustrated embodiment, the apparatus 40 further includes a reasoning unit 404, configured to:
[0109] Acquire a target text input by a user, wherein the target text contains a question entity corresponding to a question object;
[0110] The target text is input into the LLM service model, and the LLM service model generates a corresponding answer path based on the target text; wherein the answer path includes: a graph path consisting of the question entity, the answer entity type corresponding to the answer to the question, and the relationship between the entity type of the question entity and the answer entity type;
[0111] Based on the answer path, several answer entities corresponding to the answer entity type in the answer path and contained in the knowledge graph are searched, and an answer text corresponding to the target text is generated based on the several answer entities.
[0112] The implementation process of the functions and effects of each unit in the above-mentioned device 40 is specifically described in the above-mentioned embodiment, and will not be repeated here. It should be understood that the above-mentioned device 40 can be implemented by software, or by hardware or a combination of software and hardware. Taking software implementation as an example, as a device in a logical sense, it is formed by the processor (CPU) of the device where it is located reading the corresponding computer program instructions into the memory and running them. From the hardware level, in addition to the CPU and memory, the device where the above-mentioned device is located usually also includes other hardware such as chips for wireless signal transmission and reception, and / or other hardware such as boards and cards for realizing network communication functions.
[0113] The device embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical modules, that is, they may be located in one place, or they may be distributed on multiple network modules. Some or all of the units or modules may be selected according to actual needs to achieve the purpose of the scheme of this specification. Those of ordinary skill in the art may understand and implement it without creative work.
[0114] The devices, units, and modules described in the above embodiments may be implemented by computer chips or entities, or by products with certain functions. A typical implementation device is a computer, which may be in the form of a personal computer, a laptop computer, a cellular phone, a camera phone, a smart phone, a personal digital assistant, a media player, a navigation device, an email transceiver, a game console, a tablet computer, a wearable device, a vehicle-mounted computer, or a combination of any of these devices.
[0115] Corresponding to the above method embodiment, the embodiment of this specification also provides a computing device. Figure 5 , Figure 5 FIG. 1 is a schematic diagram of a computing device provided by an exemplary embodiment. Figure 5 As shown, the computing device includes a processor 1001 and a memory 1002, and may further include an input device 1004 (such as a keyboard, etc.) and an output device 1005 (such as a display, etc.). The processor 1001, the memory 1002, the input device 1004, and the output device 1005 may be connected via a bus or other means. Figure 5As shown, the memory 1002 includes a computer-readable storage medium 1003, which stores a computer program that can be executed by the processor 1001. The processor 1001 can be a CPU, a microprocessor, or an integrated circuit for controlling the execution of the above method embodiment. When the processor 1001 runs the stored computer program, it can execute the various steps of the LLM model fine-tuning method based on the knowledge graph in the embodiment of this specification, including: obtaining structural information of the knowledge graph related to the target application scenario; the structural information includes multiple entity types predefined in the knowledge graph, and the relationship between the multiple entity types; based on the structural information, generating a question template corresponding to the reasoning task related to the target application scenario, and an answer path template corresponding to the question template; the question template includes a first entity type corresponding to the question object; the answer path template includes: a graph path composed of the first entity type corresponding to the question object, the second entity type corresponding to the answer to the question, and the relationship between the first entity type and the second entity type; generating a question and answer sample pair based on the question template and the answer path template, and based on the question and answer sample pair, further performing fine-tuning training on the pre-trained LLM basic model to obtain an LLM service model for performing the reasoning task, and so on.
[0116] For a detailed description of the various steps of the above-mentioned knowledge graph-based LLM model fine-tuning method, please refer to the previous content and will not be repeated here.
[0117] Corresponding to the above method embodiment, the embodiment of this specification also provides a computer-readable storage medium, on which a computer program is stored. When these computer programs are executed by the processor, they execute the various steps of the LLM model fine-tuning method based on the knowledge graph in the embodiment of this specification. Please refer to the description of the above embodiment for details, which will not be repeated here.
[0118] The above description is only a preferred embodiment of this specification and is not intended to limit this specification. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of this specification should be included in the scope of protection of this specification.
[0119] In a typical configuration, a terminal device includes one or more CPUs, input / output interfaces, network interfaces, and memory.
[0120] The memory may include non-permanent storage in a computer-readable medium, random access memory (RAM) and / or non-volatile memory in the form of read-only memory (ROM) or flash RAM. The memory is an example of a computer-readable medium.
[0121] Computer readable media include permanent and non-permanent, removable and non-removable media and can store information by any method or technology. The information can be computer readable instructions, data structures, program modules or other data.
[0122] Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disk read-only memory (CD-ROM), digital versatile disk (DVD) or other optical storage, magnetic cassettes, magnetic tape, magnetic disk storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined herein, computer-readable media does not include transitory media such as modulated data signals and carrier waves.
[0123] It should also be noted that the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, commodity or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, commodity or device. In the absence of more restrictions, the elements defined by the sentence "comprises a ..." do not exclude the existence of other identical elements in the process, method, commodity or device including the elements.
[0124] Those skilled in the art will appreciate that the embodiments of this specification may be provided as methods, systems or computer program products. Therefore, the embodiments of this specification may take the form of complete hardware embodiments, complete software embodiments or embodiments combining software and hardware. Moreover, the embodiments of this specification may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program codes.
Claims
1. A method for fine-tuning an LLM model based on a knowledge graph, characterized in that: The method comprises: Acquire structural information of a knowledge graph related to a target application scenario; the structural information includes a plurality of entity types predefined in the knowledge graph, and the relationship between the plurality of entity types; Based on the structural information, a question template corresponding to the reasoning task related to the target application scenario and an answer path template corresponding to the question template are generated; the question template includes a first entity type corresponding to the question object; the answer path template includes: a graph path consisting of the first entity type corresponding to the question object, a second entity type corresponding to the answer to the question, and a relationship between the first entity type and the second entity type; A question-answer sample pair is generated based on the question template and the answer path template, and based on the question-answer sample pair, the pre-trained LLM basic model is further fine-tuned to obtain an LLM service model for performing the reasoning task.
2. The method according to claim 1, characterized in that The step of generating, based on the structural information, a question template corresponding to the reasoning task related to the target application scenario and an answer path template corresponding to the question template comprises: Prompt words are generated based on the structural information, and the prompt words are input into a template generation model, and the template generation model generates a question template corresponding to the reasoning task related to the target application scenario based on the prompt words, and an answer path template corresponding to the question template.
3. The method according to claim 1, characterized in that: The first entity type included in the question template and the answer path template is represented by an identifier; The generating of the question-answer sample pair based on the question template and the answer path template comprises: Obtaining a plurality of first entities corresponding to the first entity type contained in the knowledge graph; replacing the identifier for representing the first entity type contained in the question template with each of the first entities in sequence, to obtain a plurality of question texts corresponding to the first entities; replacing the identifier for indicating the first entity type contained in the answer path template with each of the first entities in sequence, to obtain a plurality of answer paths corresponding to the first entities; Based on the several question texts and the several answer paths, several question-answer sample pairs are generated; wherein each question-answer sample pair includes a question text and an answer path corresponding to the question text.
4. The method according to claim 1, characterized in that The generating of the question-answer sample pair based on the question template and the answer path template comprises: Based on a predefined reasoning logic corresponding to the reasoning task, the question template and the answer path template are adjusted to obtain a question template and an answer path template that conform to the reasoning logic; Generate a question-answer sample pair based on the adjusted question template and the answer path template.
5. The method according to claim 4, characterized in that The step of adjusting the question template and the answer path template based on the predefined reasoning logic corresponding to the reasoning task to obtain the question template and the answer path template that conform to the reasoning logic includes: Outputting the question template and the answer path template and displaying them to the target person; Receive adjustment information input by the target person for the question template and the answer path template based on the predefined reasoning logic, and adjust the question template and the answer path template based on the adjustment information to obtain the question template and the answer path template that conform to the reasoning logic.
6. The method according to claim 5, characterized in that The target application scenario includes a medical consultation scenario, the reasoning task includes a medical diagnosis task, the predefined reasoning logic includes a medical diagnosis logic, and the target personnel include medical personnel.
7. The method according to claim 3, characterized in that The method further comprises: Acquire a target text input by a user, wherein the target text contains a question entity corresponding to a question object; The target text is input into the LLM service model, and the LLM service model generates a corresponding answer path based on the target text; wherein the answer path includes: a graph path consisting of the question entity, the answer entity type corresponding to the answer to the question, and the relationship between the entity type of the question entity and the answer entity type; Based on the answer path, several answer entities corresponding to the answer entity type in the answer path and contained in the knowledge graph are searched, and an answer text corresponding to the target text is generated based on the several answer entities.
8. A LLM model fine-tuning device based on knowledge graph, characterized in that: The device comprises: An acquisition unit, configured to acquire structural information of a knowledge graph related to a target application scenario; the structural information includes a plurality of entity types predefined in the knowledge graph, and the relationship between the plurality of entity types; A generating unit, configured to generate, based on the structural information, a question template corresponding to a reasoning task related to the target application scenario, and an answer path template corresponding to the question template; the question template includes a first entity type corresponding to a question object; the answer path template includes: a graph path consisting of the first entity type corresponding to the question object, a second entity type corresponding to an answer to the question, and a relationship between the first entity type and the second entity type; A fine-tuning unit is used to generate a question-answer sample pair based on the question template and the answer path template, and based on the question-answer sample pair, further perform fine-tuning training on the pre-trained LLM basic model to obtain an LLM service model for performing the reasoning task.
9. A computing device, characterized in that include: Memory and processor; The memory has stored thereon computer programs / instructions executable by the processor; When the processor runs the computer program / instructions, the processor performs the method according to any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that: A computer program / instruction is stored thereon, and when the computer program / instruction is executed by a processor, the method according to any one of claims 1 to 7 is implemented.
11. A computer program product, characterized in that The computer program product comprises a computer program / instruction, and when the computer program / instruction is executed by a processor, the method according to any one of claims 1 to 7 is implemented.