Knowledge graph-based large model answer accuracy enhancement method and system
By preprocessing and extracting the text data sets, establishing a knowledge graph, and generating a propt template based on user intentions, the problem of low accuracy of large models when understanding user intentions and providing answers is solved, and more accurate and professional answers are achieved , improves the accuracy of answering user questions.
Patent Information
- Application Number
- CN202411378497.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-30
- Publication Date
- 2025-01-07
- Estimated Expiration
- 2044-09-30
AI Technical Summary
Existing large models have low accuracy problems when understanding user intentions and providing relevant answers, especially due to the complexity and diversity of languages, as well as limited context information and long-distance dependence problems, which lead to poor reasoning and difficult to be professional. Subdivisions provide accurate knowledge answers.
By obtaining text data sets for preprocessing and entity relationship extraction, establishing entity connection graphs and knowledge graphs, combining user query problem identification intentions, and generating highly professional prompt templates to improve the answer accuracy of the big model. Specific steps include word segmentation, vectorization processing, clustering, entity fusion, matching node recognition and intent analysis, forming a structured propt template to input a large model.
It effectively improves the accuracy of the answers to user questions by the big model, provides more professional and authoritative answers, meets users' needs for high-quality information, and enhances the semantic understanding and contextual understanding of complex problems.
Smart Images

Figure CN119271784A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of data processing technology, and more specifically, to a method and system for enhancing the accuracy of large-model answers based on a knowledge graph. Background Art
[0002] Knowledge Graph (KG) is a knowledge domain visualization or knowledge domain mapping map. It is a series of various graphs that show the knowledge development process and structural relationship. It uses visualization technology to describe knowledge resources and their carriers, mine, analyze, construct, draw and display knowledge and their mutual connections, and display complex knowledge fields through data mining, information processing, knowledge measurement and graph drawing. With the development of artificial intelligence technology, it currently has broad application prospects in the field of high-dimensional knowledge management.
[0003] Although existing technologies can generate high-quality language models, due to the complexity and diversity of language, existing large models often cannot accurately understand the user's intentions, resulting in low relevance of search results. And because it is based on autoregressive generation, large language models are often constrained by limited contextual information and long-distance dependency problems. The semantic background and contextual understanding of complex problems deviate from human intentions, resulting in poor reasoning effects, hallucinations, and practical problems that exceed knowledge boundaries in professional niches. Therefore, how to combine knowledge graphs with large models so that large models can better understand user intentions and improve answer accuracy has become a technical problem that needs to be solved in this field. Summary of the invention
[0004] The present invention provides a method and system for enhancing the accuracy of large model answers based on knowledge graphs, which is used to solve the problem of low accuracy of large models in answering user questions in the prior art, including:
[0005] Obtain a text dataset, preprocess the text dataset, and extract entities and relationships in the text dataset;
[0006] Establish an entity connection graph based on the entities and relationships in the text dataset, fuse the entity nodes of the entity connection graph, and create a knowledge graph based on the fused entity nodes and relationships;
[0007] Obtaining a user's query question, and determining a matching node for the user's query question according to the user's query question;
[0008] The user's question intention is identified according to the user's query question, a prompt template is determined according to the user's question intention and the matching node corresponding to the user's query question, and the prompt template is input into the large model to obtain a credible answer to the user's query question.
[0009] Furthermore, the preprocessing of the text data set to extract entities and relationships in the text data set includes:
[0010] Segment the text data set according to the preset segmentation algorithm, and perform vectorization processing on the segmented text data set;
[0011] Create an entity relationship extraction model, and extract entities and relationships from the vectorized text data based on the entity relationship extraction model.
[0012] Furthermore, establishing an entity connection graph according to entities and relationships in the text dataset includes:
[0013] The entities of text data are clustered based on the k-means clustering algorithm, and the partitions corresponding to the entities are determined according to the clustering results. The entities in each partition are taken as nodes and connected to obtain an entity connection graph.
[0014] Furthermore, clustering entities of text data based on the k-means clustering algorithm includes:
[0015] Preprocess the entity information of the text data, establish an entity information dataset based on the preprocessed entity information, and randomly select k initial clustering centers of the entity information dataset;
[0016] Calculate the Euclidean distance between the entity information in the entity information data set and the initial cluster center, and divide the entity information into corresponding partitions according to the Euclidean distance between the entity information in the entity information data set and the initial cluster center;
[0017] Calculate the average value of entity information in each partition, and recalculate the cluster center based on the average value of entity information in each partition;
[0018] Repeat the above steps until the cluster center no longer changes or the number of iterations reaches the maximum number of iterations, and obtain k final cluster centers.
[0019] Furthermore, the fusing process of the entity nodes of the entity connection graph includes:
[0020] Calculating the degree of each entity node in the entity connection graph, and filtering out entity nodes whose degrees exceed a first preset threshold according to the degrees of each entity node in the entity connection graph;
[0021] The entity nodes whose degrees exceed the first preset threshold are set as the central nodes, the connected components of the central nodes are obtained, the connectivities of the entity nodes in the connected components are calculated, and the entity nodes whose connectivities are greater than the second preset threshold are merged with the central nodes;
[0022] Nodes whose connectability is less than or equal to the second preset threshold are connected to the central node, and the entity nodes are merged.
[0023] Further, the calculation of the connectivity of each entity node in the connected component includes:
[0024] The cosine similarity between the entity node to be connected and the central entity node in the connected component is calculated, and the connectability of the entity node is calculated according to the connectability calculation formula. The connectability calculation formula is specifically as follows:
[0025]
[0026] Among them, P is the connectability of the entity node, D is the degree of the entity node, α is the first weight value corresponding to the degree of the entity node, S is the cosine similarity between the entity node to be connected and the central entity node, and β is the second weight value corresponding to the cosine similarity between the entity node to be connected and the central entity node.
[0027] Furthermore, the step of determining a matching node for the user's query question according to the user's query question includes:
[0028] Obtain the user's query question, perform word segmentation on the query question, and obtain the user's question word segmentation;
[0029] Establish a user question knowledge base, and determine the domain to which the user question belongs based on the frequency of the user question segmentation words in the user question knowledge base;
[0030] Establish a domain knowledge base, which stores domain keywords and corresponding synonym lists, match user question segmentation with the domain knowledge base, and obtain a synonym list corresponding to the user question segmentation;
[0031] The synonym list corresponding to the user question segmentation is used as the user question supplement, the user question keywords are obtained according to the user question segmentation and the user question supplement, and the corresponding matching nodes are determined according to the user question keywords.
[0032] Furthermore, the step of determining corresponding matching nodes according to the user question keywords includes:
[0033] Calculate the cosine similarity between the user question keywords and the entity nodes in the knowledge graph, and use the entity nodes in the knowledge graph whose cosine similarity is greater than the third preset threshold as matching nodes for the user question keywords.
[0034] Further, the step of identifying the user's question intention according to the user's query question and determining the prompt template according to the user's question intention and the matching node corresponding to the user's query question includes:
[0035] Determine the user's question intent based on the user's question keywords, set the prompt template based on the user's question intent, and set placeholders in the prompt template;
[0036] Obtain the matching nodes of the user's question keywords in the knowledge graph, input the matching nodes and the relationship between the matching nodes into the corresponding placeholders, and obtain the prompt template.
[0037] In order to achieve the above object, the present invention also provides a large model answer accuracy enhancement system based on knowledge graph, comprising:
[0038] The first module is used to obtain a text data set, preprocess the text data set, and extract entities and relations in the text data set;
[0039] The second module is used to establish an entity connection graph based on the entities and relationships in the text data set, fuse the entity nodes of the entity connection graph, and create a knowledge graph based on the fused entity nodes and relationships;
[0040] The third module is used to obtain the user's query question and determine the matching node of the user's query question according to the user's query question;
[0041] The fourth module is used to identify the user's question intention based on the user's query question, determine the prompt template based on the user's question intention and the matching node corresponding to the user's query question, input the prompt template into the large model, and obtain a credible answer to the user's query question.
[0042] The beneficial effects of the present invention are:
[0043] By applying the above technical solution, the present invention constructs a knowledge graph for the text data set and combines the knowledge graph with the big model, which can more deeply understand the questions or needs raised by the user, thereby providing more accurate and targeted answers or suggestions. At the same time, a prompt template is established based on the user's question intention, so that the generated prompt is more professional and authoritative, meeting the user's demand for high-quality information, and effectively improving the accuracy of the big model's answers to user questions. BRIEF DESCRIPTION OF THE DRAWINGS
[0044] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For those skilled in the art, other drawings can be obtained based on these drawings without creative work.
[0045] Figure 1A schematic diagram of a process of enhancing the accuracy of large model answers based on a knowledge graph proposed in an embodiment of the present invention is shown;
[0046] Figure 2 The overall structural diagram of a large model answer accuracy enhancement system based on knowledge graph proposed in an embodiment of the present invention is shown. DETAILED DESCRIPTION
[0047] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0048] The present application embodiment provides a method for enhancing the accuracy of large model answers based on knowledge graphs, such as Figure 1 As shown, including:
[0049] S101, obtaining a text data set, preprocessing the text data set, and extracting entities and relationships in the text data set;
[0050] In some embodiments of the present application, the preprocessing of the text data set and the extraction of entities and relationships in the text data set include: segmenting the text data set according to a preset segmentation algorithm, and vectorizing the segmented text data set; creating an entity relationship extraction model, and extracting entities and relationships of the vectorized text data based on the entity relationship extraction model.
[0051] In this embodiment, the text data set is segmented based on a preset word segmentation algorithm, and useless words in the text data set are removed. The word segmentation of the text data set is vectorized based on the word2vec algorithm, and the entities and relationships of the vectorized text data are extracted according to the BERT model.
[0052] S102, establishing an entity connection graph based on entities and relationships in the text data set, fusing entity nodes in the entity connection graph, and creating a knowledge graph based on the fused entity nodes and relationships;
[0053] In some embodiments of the present application, the entity connection graph is established based on the entities and relationships in the text data set, including: clustering the entities of the text data based on the k-means clustering algorithm, determining the partitions corresponding to the entities according to the clustering results, and treating the entities in each partition as nodes and connecting them to obtain an entity connection graph.
[0054] In some embodiments of the present application, the entities of text data are clustered based on the k-means clustering algorithm, including: preprocessing the entity information of the text data, establishing an entity information data set based on the preprocessed entity information, and randomly selecting k initial clustering centers of the entity information data set; calculating the Euclidean distance from the entity information in the entity information data set to the initial clustering center, and dividing the entity information into corresponding partitions based on the Euclidean distance from the entity information in the entity information data set to the initial clustering center; calculating the average value of the entity information in each partition, and recalculating the clustering center based on the average value of the entity information in each partition; and repeatedly iterating the above steps until the clustering center no longer changes or the number of iterations reaches the maximum number of iterations, thereby obtaining k final clustering centers.
[0055] In this embodiment, the k value is set according to the size of the text data. In this embodiment, the k value is set to 5. The entities of the text data are clustered based on the k-means clustering algorithm. According to the clustering results, the entities in each partition whose Euclidean distance is less than a preset threshold are edge-connected to obtain an entity connection graph.
[0056] In some embodiments of the present application, the fusion processing of the entity nodes of the entity connection graph includes:
[0057] Calculating the degree of each entity node in the entity connection graph, and filtering out entity nodes whose degrees exceed a first preset threshold according to the degrees of each entity node in the entity connection graph;
[0058] The entity nodes whose degrees exceed the first preset threshold are set as the central nodes, the connected components of the central nodes are obtained, the connectivities of the entity nodes in the connected components are calculated, and the entity nodes whose connectivities are greater than the second preset threshold are merged with the central nodes;
[0059] Nodes whose connectability is less than or equal to the second preset threshold are connected to the central node, and the entity nodes are merged.
[0060] In some embodiments of the present application, the calculation of the connectivity of each entity node in the connected component includes: calculating the cosine similarity between the entity node to be connected and the central entity node in the connected component, and calculating the connectivity of the entity node according to the connectivity calculation formula, wherein the connectivity calculation formula is specifically,
[0061]
[0062] Among them, P is the connectability of the entity node, D is the degree of the entity node, α is the first weight value corresponding to the degree of the entity node, S is the cosine similarity between the entity node to be connected and the central entity node, and β is the second weight value corresponding to the cosine similarity between the entity node to be connected and the central entity node.
[0063] In this embodiment, node fusion is performed by calculating the connectivity between each entity node and the central node. The entities with the same semantics as the central node are found and fused through the connectivity, thereby reducing redundant information and improving the accuracy of the knowledge graph. It can also enhance the connectivity of the knowledge graph to a certain extent and improve the efficiency of information retrieval.
[0064] S103, obtaining a user's query question, and determining a matching node for the user's query question according to the user's query question;
[0065] In some embodiments of the present application, determining a matching node for a user's query question based on the user's query question includes: obtaining the user's query question, performing word segmentation processing on the query question, and obtaining a user question word segmentation; establishing a user question knowledge base, and determining the domain to which the user question belongs based on the frequency of occurrence of the user question word segmentation in the user question knowledge base; establishing a domain knowledge base, in which domain keywords and corresponding synonym lists are stored, matching the user question word segmentation with the domain knowledge base to obtain a synonym list corresponding to the user question word segmentation; using the synonym list corresponding to the user question word segmentation as a user question supplement, obtaining user question keywords based on the user question word segmentation and the user question supplement, and determining a corresponding matching node based on the user question keywords.
[0066] In this embodiment, a user question knowledge base and a domain knowledge base are created in advance, a user question supplement is obtained through the user question knowledge base and the domain knowledge base, and user question keywords are obtained through user question segmentation and the user question supplement.
[0067] In some embodiments of the present application, determining the corresponding matching node based on the user question keyword includes: calculating the cosine similarity between the user question keyword and the entity node in the knowledge graph, and taking the entity node in the knowledge graph whose cosine similarity is greater than a third preset threshold as the matching node for the user question keyword.
[0068] In this embodiment, according to the vectorization processing of the user question keywords, the matching nodes are obtained by calculating the cosine similarity between the user question keywords and the entity nodes in the knowledge graph.
[0069] S104, identifying the user's question intention according to the user's query question, determining a prompt template according to the user's question intention and the matching node corresponding to the user's query question, inputting the prompt template into the big model, and obtaining a credible answer to the user's query question.
[0070] In some embodiments of the present application, the method of identifying the user's question intent based on the user's query question and determining the prompt template based on the user's question intent and the matching nodes corresponding to the user's query question includes: determining the user's question intent based on the user's question keywords, setting the prompt template based on the user's question intent, and setting placeholders in the prompt template; obtaining matching nodes for the user's question keywords in the knowledge graph, inputting the matching nodes and the relationship between the matching nodes into the corresponding placeholders, and obtaining the prompt template.
[0071] In this embodiment, a user intention analysis model is established to determine the user's question intention, and a corresponding prompt template is customized according to the user's question intention. Placeholders corresponding to matching nodes and the relationship between matching nodes are set in the prompt template. The matching nodes corresponding to the current user's question keywords and the relationship between matching nodes are input into the corresponding placeholders to obtain the prompt template. The prompt template is a structured input form used to guide the language model to perform specific tasks and generate specific types of text outputs. In natural language processing, prompt templates for specific tasks are usually used to provide input to the model to prompt it to generate text that meets specific requirements. The prompt template in the dialogue system may be more complex and may include information such as contextual dialogue history, user intentions, and previous responses from the system to guide the model to generate natural and coherent responses. By inputting the prompt template into the large model, a credible answer to the user's query question can be obtained.
[0072] Based on the same technical concept, such as Figure 2 As shown, the present invention also provides a large model answer accuracy enhancement system based on knowledge graph, including:
[0073] The first module is used to obtain a text data set, preprocess the text data set, and extract entities and relationships in the text data set; the second module is used to establish an entity connection graph based on the entities and relationships in the text data set, fuse the entity nodes of the entity connection graph, and create a knowledge graph based on the fused entity nodes and relationships; the third module is used to obtain the user's query question and determine the matching node of the user's query question based on the user's query question; the fourth module is used to identify the user's question intent based on the user's query question, determine the prompt template based on the user's question intent and the matching node corresponding to the user's query question, input the prompt template into the large model, and obtain a credible answer to the user's query question.
[0074] By applying the above technical scheme, the present invention obtains a text data set, pre-processes the text data set, extracts entities and relationships in the text data set; establishes an entity connection graph according to the entities and relationships in the text data set, fuses the entity nodes of the entity connection graph, and creates a knowledge graph according to the entity nodes and relationships after the fusion processing; obtains the user's query question, determines the matching node of the user's query question according to the user's query question; identifies the user's question intention according to the user's query question, determines the prompt template according to the user's question intention and the matching node corresponding to the user's query question, inputs the prompt template into the big model, and obtains a credible answer to the user's query question. The present invention matches the text data set based on the knowledge graph, effectively improving the accuracy of the big model's answer to the user's question.
[0075] Through the description of the above implementation methods, those skilled in the art can clearly understand that the present invention can be implemented by hardware, or by means of software plus a necessary general hardware platform. Based on such an understanding, the technical solution of the present invention can be embodied in the form of a software product, which can be stored in a non-volatile storage medium (which can be a CD-ROM, a USB flash drive, a mobile hard disk, etc.), including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each implementation scenario of the present invention.
[0076] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit it. Although the present application has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present application.
Claims
1. A method for enhancing the accuracy of large model answers based on knowledge graph, characterized in that: The method comprises: Obtain a text dataset, preprocess the text dataset, and extract entities and relationships in the text dataset; Establish an entity connection graph based on the entities and relationships in the text dataset, fuse the entity nodes of the entity connection graph, and create a knowledge graph based on the fused entity nodes and relationships; Obtaining a user's query question, and determining a matching node for the user's query question according to the user's query question; The user's question intention is identified according to the user's query question, a prompt template is determined according to the user's question intention and the matching node corresponding to the user's query question, and the prompt template is input into the large model to obtain a credible answer to the user's query question.
2. The method for enhancing the accuracy of large model answers based on knowledge graph according to claim 1 is characterized in that: The preprocessing of the text data set to extract entities and relations in the text data set includes: Segment the text data set according to the preset segmentation algorithm, and perform vectorization processing on the segmented text data set; Create an entity relationship extraction model, and extract entities and relationships from the vectorized text data based on the entity relationship extraction model.
3. The method for enhancing the accuracy of large model answers based on knowledge graph according to claim 2 is characterized in that: The step of establishing an entity connection graph based on entities and relationships in a text dataset includes: The entities of text data are clustered based on the k-means clustering algorithm, and the partitions corresponding to the entities are determined according to the clustering results. The entities in each partition are taken as nodes and connected to obtain an entity connection graph.
4. The method for enhancing the accuracy of large model answers based on knowledge graph according to claim 3 is characterized in that: The clustering of entities of text data based on the k-means clustering algorithm includes: Preprocess the entity information of the text data, establish an entity information dataset based on the preprocessed entity information, and randomly select k initial clustering centers of the entity information dataset; Calculate the Euclidean distance between the entity information in the entity information data set and the initial cluster center, and divide the entity information into corresponding partitions according to the Euclidean distance between the entity information in the entity information data set and the initial cluster center; Calculate the average value of entity information in each partition, and recalculate the cluster center based on the average value of entity information in each partition; Repeat the above steps until the cluster center no longer changes or the number of iterations reaches the maximum number of iterations, and obtain k final cluster centers.
5. The method for enhancing the accuracy of large model answers based on knowledge graph according to claim 4 is characterized in that: The fusing process of the entity nodes of the entity connection graph includes: Calculating the degree of each entity node in the entity connection graph, and filtering out entity nodes whose degrees exceed a first preset threshold according to the degrees of each entity node in the entity connection graph; The entity nodes whose degrees exceed the first preset threshold are set as the central nodes, the connected components of the central nodes are obtained, the connectivities of the entity nodes in the connected components are calculated, and the entity nodes whose connectivities are greater than the second preset threshold are merged with the central nodes; Nodes whose connectability is less than or equal to the second preset threshold are connected to the central node, and the entity nodes are merged.
6. The method for enhancing the accuracy of large model answers based on knowledge graph according to claim 5 is characterized in that: The calculating the connectability of each entity node in the connected component includes: The cosine similarity between the entity node to be connected and the central entity node in the connected component is calculated, and the connectability of the entity node is calculated according to the connectability calculation formula. The connectability calculation formula is specifically as follows: Among them, P is the connectability of the entity node, D is the degree of the entity node, α is the first weight value corresponding to the degree of the entity node, S is the cosine similarity between the entity node to be connected and the central entity node, and β is the second weight value corresponding to the cosine similarity between the entity node to be connected and the central entity node.
7. The method for enhancing the accuracy of large model answers based on knowledge graph according to claim 1, characterized in that: The step of determining a matching node for the user's query question according to the user's query question includes: Obtain the user's query question, perform word segmentation on the query question, and obtain the user's question word segmentation; Establish a user question knowledge base, and determine the domain to which the user question belongs based on the frequency of the user question segmentation words in the user question knowledge base; Establish a domain knowledge base, which stores domain keywords and corresponding synonym lists, match user question segmentation with the domain knowledge base, and obtain a synonym list corresponding to the user question segmentation; The synonym list corresponding to the user question segmentation is used as the user question supplement, the user question keywords are obtained according to the user question segmentation and the user question supplement, and the corresponding matching nodes are determined according to the user question keywords.
8. The method for enhancing the accuracy of large model answers based on knowledge graph according to claim 7 is characterized in that: The determining of the corresponding matching node according to the user question keyword includes: Calculate the cosine similarity between the user question keywords and the entity nodes in the knowledge graph, and use the entity nodes in the knowledge graph whose cosine similarity is greater than the third preset threshold as matching nodes for the user question keywords.
9. The method for enhancing the accuracy of large model answers based on knowledge graph according to claim 8, characterized in that: The step of identifying the user's question intention according to the user's query question, and determining the prompt template according to the user's question intention and the matching node corresponding to the user's query question, includes: Determine the user's question intent based on the user's question keywords, set the prompt template based on the user's question intent, and set placeholders in the prompt template; Obtain the matching nodes of the user's question keywords in the knowledge graph, input the matching nodes and the relationship between the matching nodes into the corresponding placeholders, and obtain the prompt template.
10. A large model answer accuracy enhancement system based on knowledge graph, characterized in that: include: The first module is used to obtain a text data set, preprocess the text data set, and extract entities and relations in the text data set; The second module is used to establish an entity connection graph based on the entities and relationships in the text data set, fuse the entity nodes of the entity connection graph, and create a knowledge graph based on the fused entity nodes and relationships; The third module is used to obtain the user's query question and determine the matching node of the user's query question according to the user's query question; The fourth module is used to identify the user's question intention based on the user's query question, determine the prompt template based on the user's question intention and the matching node corresponding to the user's query question, input the prompt template into the large model, and obtain a credible answer to the user's query question.
Citation Information
Patent Citations
Intelligent question answering method and device
CN106874441A
Large language model medical question-answering system based on medical record knowledge graph
CN117056493A
Knowledge graph intelligent question and answer information identification method based on improved deep learning algorithm
CN117891929A
Data processing method based on knowledge graph
CN117973519A
Ancient book knowledge base intelligent question and answer method, device and equipment based on large model technology
CN118332091A
Cited By
Knowledge graph-based large model answer accuracy enhancement method and system
CN120045644A
Method and System for Enhancing the Answer Accuracy of Large Models Based on Knowledge Graphs
CN120045644B
Small-sample knowledge graph question answering method and system based on large model enhancement
CN120745828A
Large language model knowledge graph question answering method and system combined with semantic correction
CN120745829A