Method and system for enhancing reliability of large language model based on knowledge graph
By introducing knowledge graph information into the large language model and using the knowledge graph to guide and correct the output text, the illusion and knowledge outdated problems of the large language model are solved, and the reliability and accuracy of the output text are improved.
Patent Information
- Application Number
- CN202411456815.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-18
- Publication Date
- 2025-02-14
AI Technical Summary
Large language models are prone to hallucinations and outdated knowledge problems when generating text, which affects their application and trust.
By inputting knowledge graph information into a large language model, using the knowledge guide of the knowledge graph to generate output text, and using the knowledge graph information to fuse or correct the generated output text to generate output text with entities, relationships and path links.
It effectively solves the hallucination problems and old knowledge problems of large language models, improves the reliability and accuracy of the generated natural language, and allows large models to use new knowledge in a timely manner.
Smart Images

Figure CN119443230A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of artificial intelligence technology, and in particular to a method and system for enhancing the reliability of a large language model based on a knowledge graph. Background Art
[0002] Large Language Model (LLM) is an artificial intelligence system trained with a large amount of text data to understand and generate natural language. LLM has powerful language capabilities and can be applied to various tasks such as text summarization, dialogue generation, machine translation, intelligent question answering, etc. However, LLM also has some challenges and limitations, including the hallucination problem and the knowledge staleness problem.
[0003] The hallucination problem refers to the fact that when LLM generates text, it may produce inaccurate or misleading outputs, that is, the AI model will produce content that is inconsistent with the facts. The hallucination problem has a serious impact on the application and trust of LLM, especially in sensitive or important fields such as finance, law, medicine, manufacturing, etc. For example, if an LLM is used to generate medical diagnoses or suggestions, but if the answers generated are contrary to medical knowledge, then this may cause serious harm to patients. Another example is the manufacturing industry. An LLM is used for fault analysis of production line equipment. If the recommended solution is fabricated and does not match the current equipment, it will not only fail to solve the problem, but may also damage the equipment in some cases.
[0004] The problem of obsolete knowledge refers to the obsolete corpus used to train the big model, and the big model is currently unable to add new knowledge in real time. The problem of obsolete knowledge also has a serious impact on the application and trust of LLM. For example, in financial analysis, analyzing current financial tasks based on obsolete data and event content often leads to wrong conclusions, such as stock market analysis. The same situation also occurs in manufacturing or medical, legal and other fields. Especially in case law, new precedents have an important impact on similar cases in the future, but if the big model does not have the latest case knowledge, the answer given will also be wrong. Summary of the invention
[0005] In view of this, the present invention provides a method and system for enhancing the reliability of a large language model based on a knowledge graph, so as to solve the problems of hallucination and obsolete knowledge existing in the large language model.
[0006] A method for enhancing the reliability of a large language model based on a knowledge graph, specifically comprising the following steps:
[0007] S1, input the knowledge graph information and input text into the large language model, and use the knowledge of the knowledge graph to guide the large language model to generate output text;
[0008] S2, the large language model outputs knowledge graph information and output text, uses the knowledge graph information to fuse or modify the output text generated by the large language model, and performs anchor tagging to generate and output output text with entities, relationships, and path links;
[0009] S3, the user clicks on the entity or path in the accurate answer in the user interface to retrieve the corresponding information in the knowledge graph.
[0010] Preferably, the specific steps of using the knowledge of the knowledge graph to guide the large language model to generate output text in step S1 are:
[0011] S11, input the knowledge graph information into the large language model, and the embedding of the large language model converts the knowledge of the knowledge graph into knowledge entity vectors and knowledge relationship vectors;
[0012] S12, when the user inputs the input text into the large language model, the Embedding of the large language model converts the input text into an input vector;
[0013] S13, the knowledge graph Grounding module searches for corresponding knowledge entity vectors and knowledge relationship vectors from all vectors of the knowledge graph according to the entities in the input vector, and uses the found knowledge entity vectors and knowledge relationship vectors to guide the large language model to generate output text.
[0014] Preferably, after the knowledge of the knowledge graph is used to guide the large language model to generate output text in step S1, the generated output text will be injected into the large language model so that the large language model can use new knowledge in a timely manner.
[0015] Preferably, the knowledge of the knowledge graph includes the entity itself and a relationship triple consisting of <head entity, relationship, tail entity>.
[0016] Preferably, the specific steps of fusing or correcting the output text generated by the large language model using the knowledge graph information and performing anchor point marking in step S2 are:
[0017] S21, the knowledge fusion module converts the output text and knowledge graph information generated by the large language model into the vector space through embedding learning, and obtains the vector representation of all relations in the knowledge graph and the vector representation of the output text;
[0018] S22, respectively calculating the vector matching degree between the vector representation of the output text and each relation vector representation in the knowledge graph, if the vector matching degree between the vector representation of the output text and a relation vector representation in the knowledge graph exceeds a set threshold, then filtering and outputting the relation triples and entities corresponding to the relation vector representation;
[0019] S23, compares the output text generated by the large language model with all the screened relation triples and entities, marks the relation triples and entities that match the output text and adds links, thereby generating and outputting output text with entity, relation and path links.
[0020] Preferably, in step S23, the specific steps of comparing the output text generated by the large language model with all the filtered relationship triples and entities are:
[0021] S23.1, traverse each character in the output text generated by the large language model;
[0022] S23.2, determine whether a certain character in the output text matches one or several relation triples or entities among all the filtered relation triples or entities. If so, continue to determine whether the character matches all the characters of the matched relation triples or entities. If so, mark the matched relation triples or entities. Otherwise, traverse the next character of the output text and execute this step;
[0023] S23.3, generating a relation path and a final output text according to all the marked relation triples or entities, and adding the relation path, the links corresponding to the marked relation triples or entities to the final output text.
[0024] Preferably, the method for embedding learning the output text generated by the large language model includes BERT, GPT, ElMo, AlBERT algorithms;
[0025] Methods for embedding knowledge graph information include the graph neural network R-GCN algorithm.
[0026] Preferably, the vector matching degree calculation formula is:
[0027]
[0028] Among them, score is the vector matching degree, is the vector representation of the output text, It is the relation vector representation in the knowledge graph.
[0029] A system for enhancing the reliability of a large language model using the method described above, comprising a large language model, a knowledge fusion module and an anchor point marking module;
[0030] The large language model is used to convert input text into input vectors, convert knowledge in the knowledge graph into knowledge entity vectors and knowledge relationship vectors, find corresponding knowledge entity vectors and knowledge relationship vectors from all vectors of the knowledge graph according to the entities in the input vectors, and use the found knowledge entity vectors and knowledge relationship vectors to generate output text, output the knowledge graph and output text;
[0031] The knowledge fusion module is used to use the knowledge graph information to perform entity, relationship and path search on the output text generated by the large language model to fuse or correct the output text;
[0032] The anchor mark module is used to mark the entities, relations and paths found by the knowledge fusion module, generate output text with entity, relation and path links, and output it.
[0033] The beneficial effects of the present invention are:
[0034] 1. The present invention uses the information of the knowledge graph as part of the input of the large language model, uses the knowledge of the knowledge graph to guide or constrain the large language model to generate output text, and then uses the information of the knowledge graph as part of the output of the large language model, uses the knowledge graph information to fuse or correct the output text generated by the large language model, and performs anchor point marking to generate and output output text with entities, relationships and path links, which effectively solves the hallucination problem of the large language model and improves the reliability and accuracy of the natural language generated by the large language model.
[0035] 2. When the present invention uses the knowledge of the knowledge graph to guide or constrain the large language model to generate output text, the generated output text can be injected into the large model as new knowledge, so that the large model can use the new knowledge in a timely manner, effectively solving the problem of knowledge obsolescence existing in the current large language model, and further improving the reliability and accuracy of the natural language generated by the large language model. BRIEF DESCRIPTION OF THE DRAWINGS
[0036] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings required for use in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0037] Figure 1 It is the overall flow chart of the present invention.
[0038] Figure 2 It is a flowchart of the knowledge fusion module screening the relation triples that match the output text output by the large language model.
[0039] Figure 3 It is a flowchart of anchor point marking by the anchor point marking module. DETAILED DESCRIPTION
[0040] In order to make the purpose, technical scheme and advantages of the present invention clearer, the present invention is described below by the specific embodiments shown in the accompanying drawings. However, it should be understood that these descriptions are only exemplary and are not intended to limit the scope of the present invention. In addition, in the following description, the description of well-known structures and technologies is omitted to avoid unnecessary confusion of the concept of the present invention.
[0041] The terms used in this disclosure are for the purpose of describing specific embodiments only and are not intended to limit the disclosure. The singular forms of "a", "said" and "the" used in this disclosure and the appended claims are also intended to include plural forms unless the context clearly indicates otherwise. It should also be understood that the term "and / or" used herein refers to and includes any or all possible combinations of one or more associated listed items.
[0042] In order to better understand the technical solution of the present invention, the present invention is described in detail below with reference to the accompanying drawings.
[0043] The present invention provides a method for enhancing the reliability of a large language model based on a knowledge graph, which specifically includes the following steps:
[0044] S1, input the knowledge graph information and input text into the large language model, and use the knowledge of the knowledge graph to guide the large language model to generate output text.
[0045] Specifically, first of all, the knowledge in the knowledge graph includes the entity itself and the relationship triple consisting of <head entity, relationship, tail entity>. After the knowledge graph information is input into the large language model, the Embedding of the large language model converts the knowledge of the knowledge graph into knowledge entity vectors and knowledge relationship vectors, namely entity Embed and relationship Embed.
[0046] When the user inputs the input text into the large language model, the Embedding of the large language model converts the input text into an input vector;
[0047] Then, the knowledge graph Grounding module searches for corresponding knowledge entity vectors and knowledge relationship vectors from all vectors of the knowledge graph based on the entities and relationships in the input vector, and uses the found knowledge entity vectors and knowledge relationship vectors to guide the large language model to generate output text.
[0048] For example, suppose the input text entered by the user into the big language model is "Who is Su Shi's father?", the big language model converts the input text into a vector, and the knowledge graph Grounding module uses the vector to find the vector of "Su Shi" from all the knowledge entity vectors in the knowledge graph, and the vector of "<Su Shi, father, Su Xun>" from all the knowledge relationship vectors, and use the found vectors to guide the big model to generate the text "Su Shi's father is Su Xun", so that the output of the big model can be generated purposefully to avoid the occurrence of hallucinations.
[0049] Preferably, after using the knowledge of the knowledge graph to guide the large language model to generate output text, the generated output text will be injected into the large language model so that the large language model can use new knowledge in a timely manner.
[0050] S2, the large language model outputs knowledge graph information and output text, uses the knowledge graph information to fuse or correct the output text generated by the large language model, and performs anchor tagging to generate and output output text with entities, relationships, and path links.
[0051] Specifically, in S21, the knowledge fusion module converts the output text and knowledge graph information generated by the large language model into the vector space through embedding learning, and obtains the vector representation of all relations in the knowledge graph and the vector representation of the output text. The embedding learning of the text can select a suitable method according to the actual situation. For example, the embedding learning of the output text generated by the large language model can adopt algorithms such as BERT, GPT, ElMo, AlBERT, etc., and the embedding learning of the knowledge graph can adopt algorithms such as the graph neural network R-GCN.
[0052] S22, respectively calculate the vector matching degree between the vector representation of the output text and each relation vector representation in the knowledge graph. If the vector matching degree between the vector representation of the output text and a relation vector representation in the knowledge graph exceeds a set threshold, then filter and output the relation triples and entities corresponding to the relation vector representation, such as Figure 2 As shown;
[0053] That is, the vector representation of the output text is calculated according to the vector matching calculation formula shown below The vector matching score between each relationship vector representation in the knowledge graph is a value between 0 and 1. If the calculated score exceeds the set threshold, the relationship vector representation The corresponding relation triples and entity outputs;
[0054] The vector matching calculation formula is:
[0055]
[0056] Among them, score is the vector matching degree, is the vector representation of the output text, It is the relation vector representation in the knowledge graph.
[0057] Still taking the example in S1 above, the output text output by the large language model is "Su Shi's father is Su Xun", and the knowledge fusion module finds the matching relationship triple "<Su Shi, father, Su Xun>" from the knowledge graph, and outputs the relationship triple "<Su Shi, father, Su Xun>" and its corresponding entities "Su Shi" and "Su Xun".
[0058] S23, compare the output text generated by the large language model with all the relation triples and entities screened out in step S22, mark the relation triples and entities that match the output text and add links, thereby generating and outputting output text with entity, relation and path links.
[0059] Specifically, Figure 3 As shown in the figure, the specific steps of comparing the output text generated by the large language model with all the filtered relation triples and entities are:
[0060] First, traverse each character in the output text generated by the large language model;
[0061] Determine whether the first character in the output text matches one or several of all the relation triples or entities screened out in step S22; if so, determine whether the character matches all the characters of the matched relation triples or entities; otherwise, traverse the next character of the output text;
[0062] If the current character matches all characters of the matched relation triple or entity, mark the matched relation triple or entity, otherwise traverse the next character of the output text;
[0063] Then, the relation paths and the final output text are generated according to all the labeled relation triples or entities, and the relation paths, the links corresponding to the labeled relation triples or entities are added to the final output text.
[0064] Suppose that in step S22, four relational triples A, B, C, and D are selected. The first character in the output text is sequentially matched with these four relational triples. If the character matches relational triple A, it is determined whether the character matches each character in relational triple A. If so, relational triple A is marked. Otherwise, in the same way, the second character in the output text is sequentially matched with these four relational triples until the last character in the output text is traversed. Suppose that finally, relational triples A and B are marked. Then, the final output text is generated according to relational triples A and B. Relational triples A and B also form a long relational path, and this relational path, relational triples A and B, and the links of the entities are added to the final output text.
[0065] For example, the final output text is "Su Shi's father is Su Xun". "Su Shi's father is Su Xun" is marked with anchors and links are added to form the following output:
[0066] “ <a href=#entity-苏轼> Su Shi of <a href=#path-pathcode> Father is <a href=#entity-Su Xun>Su Xun”
[0067] Among them, pathcode is the unique identifier of the path generated by the knowledge graph. In this example, it represents the path "<Su Shi, father, Su Xun>".
[0068] When the user clicks on the entity "Su Shi" or "Su Xun" or the path on the user interface, the corresponding subgraph in the knowledge graph will be displayed to ensure that the answers given in the Q&A are reliable.
[0069] In practical applications, during the process of generating the final output text, due to the existence of complex reasoning, the finally formed path may be a long path composed of multiple relational triples, such as a long path like "<a, father, b>, <b, father, c>, <c, father, d>", which represents the relationship that the great-grandfather of a is d.
[0070] S3. When the user clicks on the entity or path in the accurate answer on the user interface, the corresponding information in the knowledge graph can be retrieved and displayed.
[0071] The present invention also provides a system for enhancing the reliability of a large language model by using the above method, including a large language model, a knowledge fusion module, and an anchor marking module.
[0072] The large language model is used to convert input text into input vectors, convert knowledge in the knowledge graph into knowledge entity vectors and knowledge relationship vectors, find corresponding knowledge entity vectors and knowledge relationship vectors from all vectors of the knowledge graph according to the entities in the input vectors, and use the found knowledge entity vectors and knowledge relationship vectors to generate output text, output the knowledge graph and output text;
[0073] The knowledge fusion module is used to use the knowledge graph information to perform entity, relationship and path search on the output text generated by the large language model to fuse or correct the output text;
[0074] The anchor mark module is used to mark the entities, relations and paths found by the knowledge fusion module, generate output text with entity, relation and path links, and output it.
[0075] It should be clear that the described embodiments are only part of the embodiments of the present invention, rather than all the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
Claims
1. A method for enhancing the reliability of a large language model based on a knowledge graph, characterized in that: The specific steps include: S1, input the knowledge graph information and input text into the large language model, and use the knowledge of the knowledge graph to guide the large language model to generate output text; S2, the large language model outputs knowledge graph information and output text, uses the knowledge graph information to fuse or modify the output text generated by the large language model, and performs anchor tagging to generate and output output text with entities, relationships, and path links; S3, the user clicks on the entity or path in the accurate answer in the user interface to retrieve the corresponding information in the knowledge graph.
2. The method for enhancing the reliability of a large language model based on a knowledge graph according to claim 1, characterized in that: The specific steps of using the knowledge of the knowledge graph to guide the large language model to generate output text in step S1 are: S11, input the knowledge graph information into the large language model, and the embedding of the large language model converts the knowledge of the knowledge graph into knowledge entity vectors and knowledge relationship vectors; S12, when the user inputs the input text into the large language model, the Embedding of the large language model converts the input text into an input vector; S13, the knowledge graph Grounding module searches for corresponding knowledge entity vectors and knowledge relationship vectors from all vectors of the knowledge graph according to the entities in the input vector, and uses the found knowledge entity vectors and knowledge relationship vectors to guide the large language model to generate output text.
3. The method for enhancing the reliability of a large language model based on a knowledge graph according to claim 1, characterized in that: After the knowledge of the knowledge graph is used to guide the large language model to generate output text in step S1, the generated output text will be injected into the large language model so that the large language model can use new knowledge in a timely manner.
4. The method for enhancing the reliability of a large language model based on a knowledge graph according to claim 1, characterized in that: The knowledge of the knowledge graph includes the entity itself and the relationship triple consisting of <head entity, relationship, tail entity>.
5. The method for enhancing the reliability of a large language model based on a knowledge graph according to claim 3, characterized in that: In step S2, the specific steps of using the knowledge graph information to fuse or correct the output text generated by the large language model and mark the anchor points are as follows: S21, the knowledge fusion module converts the output text and knowledge graph information generated by the large language model into the vector space through embedding learning, and obtains the vector representation of all relations in the knowledge graph and the vector representation of the output text; S22, respectively calculating the vector matching degree between the vector representation of the output text and each relation vector representation in the knowledge graph, if the vector matching degree between the vector representation of the output text and a relation vector representation in the knowledge graph exceeds a set threshold, then filtering and outputting the relation triples and entities corresponding to the relation vector representation; S23, compares the output text generated by the large language model with all the screened relation triples and entities, marks the relation triples and entities that match the output text and adds links, thereby generating and outputting output text with entity, relation and path links.
6. The method for enhancing the reliability of a large language model based on a knowledge graph according to claim 5, characterized in that: In step S23, the specific steps of comparing the output text generated by the large language model with all the filtered relationship triples and entities are as follows: S23.1, traverse each character in the output text generated by the large language model; S23.2, determine whether a certain character in the output text matches one or several relation triples or entities among all the filtered relation triples or entities. If so, continue to determine whether the character matches all the characters of the matched relation triples or entities. If so, mark the matched relation triples or entities. Otherwise, traverse the next character of the output text and execute this step; S23.3, generating a relation path and a final output text according to all the marked relation triples or entities, and adding the relation path, the links corresponding to the marked relation triples or entities to the final output text.
7. The method for enhancing the reliability of a large language model based on a knowledge graph according to claim 5, characterized in that: Methods for embedding text generated by large language models include BERT, GPT, ElMo, and AlBERT algorithms; Methods for embedding knowledge graph information include the graph neural network R-GCN algorithm.
8. The method for enhancing the reliability of a large language model based on a knowledge graph according to claim 5, characterized in that: The vector matching degree calculation formula is: Among them, score is the vector matching degree, is the vector representation of the output text, It is the relation vector representation in the knowledge graph.
9. A system for enhancing the reliability of a large language model using the method of any one of claims 1 to 8, characterized in that: Includes large language model, knowledge fusion module and anchor tag module; The large language model is used to convert input text into input vectors, convert knowledge in the knowledge graph into knowledge entity vectors and knowledge relationship vectors, find corresponding knowledge entity vectors and knowledge relationship vectors from all vectors of the knowledge graph according to the entities in the input vectors, and use the found knowledge entity vectors and knowledge relationship vectors to generate output text, output the knowledge graph and output text; The knowledge fusion module is used to use the knowledge graph information to perform entity, relationship and path search on the output text generated by the large language model to fuse or correct the output text; The anchor mark module is used to mark the entities, relations and paths found by the knowledge fusion module, generate output text with entity, relation and path links, and output it.
Citation Information
Cited By
RPA knowledge base updating method of AI agent
CN119807192A
An RPA Knowledge Base Update Method for an AI Agent
CN119807192B
Heterogeneous double-model-based large model output reliability enhancement method
CN122264113A
A large model output reliability enhancement method based on a heterogeneous double model
CN122264113B
A substation power knowledge graph-based large model operation and maintenance illusion suppression and semantic alignment method
CN122862603A