Question answering system design method based on knowledge enhancement large model
By building a knowledge graph to enhance the knowledge of the large language model, the problems in the existing technology that are prone to hallucinations and generate incorrect answers when answering questions in professional fields are solved, and higher answer accuracy and standardization are achieved, meeting the semantic needs of users.
Patent Information
- Application Number
- CN202411524678.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-30
- Publication Date
- 2025-03-18
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
The prior art is prone to hallucinations and generates incorrect answers when answering questions in professional fields. Traditional search engines cannot fully understand the semantic needs of users and are difficult to accurately meet users' information needs.
By building a knowledge graph, a large language model is enhanced by designing a question-and-answer chain structure of the large language model, so that it calls the information in the knowledge graph when answering questions, and improves the accuracy and standardization of the answers.
It reduces hallucination questions, improves the accuracy and standardization of answering questions in the field, meets the semantic needs of users, and provides more accurate information retrieval results.
Smart Images

Figure CN119646130A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of machine learning, and in particular relates to a question-answering system design method based on a knowledge-enhanced large model. Background Art
[0002] In recent years, papers and books in various academic fields have emerged continuously, providing researchers with rich knowledge resources, but it also makes it difficult to find the required content in the massive amount of information. It is necessary to study how to effectively manage and utilize these knowledge resources.
[0003] From the perspective of resource retrieval, traditional search engines mainly retrieve information through keywords entered by users, but this keyword-based matching mechanism ignores context and semantics, cannot fully understand users' semantic needs, and is difficult to accurately meet users' actual information needs. Knowledge graphs are knowledge bases that represent concepts and entities in the objective world and their relationships in the form of graphs. They can provide information accurately and quickly and are one of the basic technologies for semantic search. However, only knowledge graphs built with high-quality corpora can become an ideal knowledge source for information retrieval systems in professional fields.
[0004] The large language model is an artificial intelligence model that can understand and generate natural language. It has demonstrated good performance in various natural language processing tasks. However, it is limited by the timeliness of the training corpus and the scale of training parameters. It is prone to hallucinations when answering questions in professional fields and to generate wrong answers when answering knowledge questions. Summary of the invention
[0005] The purpose of the present invention is to provide a question-answering system design method based on a knowledge-enhanced large model. By enhancing the knowledge of the large language model through the knowledge graph, the question-answering chain of the large language model can reduce hallucination problems and improve the standardization and accuracy of answering questions in the field.
[0006] The technical solution adopted by the present invention is as follows:
[0007] A method for designing a question answering system based on a knowledge-enhanced large model comprises the following steps:
[0008] S1: Collection of text data in the field;
[0009] S2: data preprocessing;
[0010] S3: Build a knowledge graph;
[0011] S4: Knowledge graph enhanced large language model framework design;
[0012] S5: Question and answer system construction.
[0013] The step S1 specifically includes: collecting text data in the field, writing a Python program to crawl relevant paper data, patent data, and report data from academic resource websites;
[0014] Among them, the crawled fields include paper title, abstract, publication time, author, and keywords. The collected text data are divided into domestic conferences, academic journals, dissertations and Chinese patents.
[0015] The Python programs include DBLP, CNKJ and Sci-Hub.
[0016] The data preprocessing in step S2 includes file integrity checking, encoding standardization, content screening and data classification.
[0017] The step S2 also includes: using natural language processing technology to extract knowledge from the text data collected in step S1, extracting entities and their attributes and relationships between entities, and performing knowledge fusion and standardization processing on the extracted content to form a data representation of a triple structure.
[0018] The knowledge graph in step S3 includes defining entities, entity attributes and relationships between entities;
[0019] At the same time, the Neo4j graph database platform is used to store the constructed triple structure data, and the data query language Cypher is used to implement the addition, deletion, modification and query operations of the knowledge graph.
[0020] The step S4 specifically includes: combining the constructed knowledge graph with the large language model through the LangChain function library, designing a large language model question-answering chain structure, so that the large language model question-answering chain calls the information in the knowledge graph when answering questions, so as to improve the accuracy of the answers.
[0021] The step S4 also includes a method for enhancing the large language model question-answer chain structure, which is specifically as follows:
[0022] M1: Connect the knowledge graph with the large language model so that the large language model can understand the knowledge graph structure;
[0023] M2: Design query hint documents to enable the large language model to understand natural language questions and then construct Cypher query statements to search in the knowledge graph;
[0024] M3: Design answer prompt documents so that the large language model can integrate the answers according to certain rules after querying the knowledge and generate standardized answers.
[0025] The step S5 specifically includes: finally displaying a chat interface in a web form, wherein the chat interface includes:
[0026] A website homepage, the homepage including a question-answering module, the question-answering module being used to conduct a dialogue with a large language model;
[0027] The history page is used to view the question and answer history.
[0028] Using this design method, we obtain a question-answering system based on a knowledge-enhanced large model, including:
[0029] Data collection module: The data collection module uses crawler programs, such as DBLP, CNKJ and Sci-Hub, to collect text data in the field. The crawled fields include paper title, abstract, publication time, author, and keywords. The collected text data are divided into domestic conferences, academic journals, dissertations and Chinese patents.
[0030] Data preprocessing module, the data preprocessing module has:
[0031] A1) File integrity check: For each article, we first divide it into sections and mark the font size and number of characters in each section. At the same time, we build a regular expression list containing multiple keywords to match the sections containing the keywords in the list. If the section lacks the keywords, it is not complete.
[0032] A2) Coding standardization: For node articles containing entity attributes, a dictionary set is created and the paper titles are searched and matched first;
[0033] A3) Content filtering: merging node attributes of the same nodes to eliminate duplicate entities. For example, if two nodes represent the same paper, but one node contains the publication year of the paper and the other node contains the author information of the paper, the two nodes will be merged into one node containing the information of both nodes.
[0034] A4) Data classification: Use natural language processing technology to extract knowledge from the collected text data, extract entities and their attributes and relationships between entities, and perform knowledge fusion and standardization on the extracted content to form a data representation of a triple structure;
[0035] Knowledge graph building module,The knowledge graph building module includes;
[0036] B1) Knowledge extraction unit, initializes database connection, that is, specifies the address and authentication information of the database, and uses the py2neo function library to initialize the connection with the Neo4j database;
[0037] Then extract the data preprocessed in step 2 of embodiment 1, including entity information such as articles, authors, keywords, and relationship data between them;
[0038] B2) Knowledge fusion and standardization unit, creating graph database nodes, that is, creating a node in the graph database for each unique entity;
[0039] For example, for the Author entity, the method creates a node with the Author tag and a name attribute;
[0040] Then create relationship edges, that is, use the constructed general format Cypher statements to implement the logic of creating entity relationship edges in the graph database;
[0041] B3) Knowledge storage unit, using computer storage media to achieve data storage, such as flash memory stick;
[0042] Database, which is built based on Neo4j graph database software and is used to store knowledge graphs;
[0043] Large language model layer. The large language model can be Huawei PanGu-α, BLOOM, UL2, etc., which has the functions of question understanding, query conversion and answer construction. Among them:
[0044] Question understanding: after the user enters the question in the interface, it is converted into computer language;
[0045] Query conversion is to import the computer language corresponding to the question into the database;
[0046] Answer construction is to temporarily construct the knowledge graph related to the above questions and display it;
[0047] Presentation layer, the presentation layer is configured with:
[0048] C1) Flask interactive interface is a lightweight Web application framework written in Python, which can be used to realize the interaction between the front-end and back-end;
[0049] C2) Get request window is an area for users to input questions and is set in the Flask interactive interface;
[0050] C3) POST request window is the area for displaying answers and is set in the Flask interactive interface;
[0051] Front-end UI: The front-end UI can use technologies such as Html, CSS or Javascript, and finally be displayed as a Flask interactive interface through the web.
[0052] The technical effects achieved by the present invention are:
[0053] The present invention discloses a method for designing a question-answering system based on a knowledge-enhanced large model. By enhancing the knowledge of a large language model through a knowledge graph, the large language model question-answering chain can reduce hallucination problems and improve the standardization and accuracy of answering questions in a field.
[0054] The present invention provides a method for designing a question-answering system based on a knowledge-enhanced large model. For node articles containing entity attributes, a dictionary set is created, and the paper title is first searched and matched; if the match is successful, the node attributes of the same node are merged to eliminate duplicate entities. If two nodes represent the same paper, but one node contains the publication year of the paper and the other node contains the author information of the paper, the two nodes will be merged into one node containing the information of both nodes; if the node attributes of the two nodes conflict, manual review will be performed to ensure the accuracy of the node data.
[0055] The present invention provides a method for designing a question-answering system based on a knowledge-enhanced large model. For users, there is no need to understand the complex architecture. They only need to input the questions they want to ask, and the system will output the answers of the large language model enhanced by the knowledge graph. This greatly reduces the cost of use and is also easy to promote.
[0056] The present invention provides a question-answering system based on a knowledge-enhanced large model. The system has broad application prospects in teaching and scientific research, and can also be applied to other fields that require high-accuracy question-answering, such as education, medical care, finance, etc. BRIEF DESCRIPTION OF THE DRAWINGS
[0057] Figure 1 It is a general architecture diagram of a question-answering system design method based on a knowledge-enhanced large model of the present invention;
[0058] Figure 2 is a flow chart of text collection in the field of the present invention;
[0059] Figure 3 It is a flow chart of the knowledge graph construction of the present invention;
[0060] Figure 4 It is a model structure diagram of the knowledge graph enhanced large language model question-answering chain of the present invention. DETAILED DESCRIPTION
[0061] In order to make the purpose and advantages of the present invention more clearly understood, the present invention is specifically described below in conjunction with embodiments. It should be understood that the following text is only used to describe one or several specific embodiments of the present invention, and does not strictly limit the scope of protection of the specific claims of the present invention.
[0062] Embodiment 1:
[0063] like Figure 1-4As shown, a question answering system design method based on knowledge-enhanced large model includes:
[0064] Step 1: Collect text data in the field
[0065] Collect text data in the field through libraries such as Scrapy in the Python programming language;
[0066] First, the article titles and unique identifiers of articles in the field are obtained in DBLP based on the paper classification information;
[0067] Afterwards, text data was collected from resource databases such as Sci-hub and China National Knowledge Infrastructure.
[0068] Step 2: Data preprocessing
[0069] For each article, we first divide it into sections and mark the font size and number of characters in each section. At the same time, we build a regular expression list containing multiple keywords to match the sections containing the keywords in the list.
[0070] The successfully matched paragraphs are subjected to entity extraction and attribute extraction using natural language processing technology;
[0071] For node articles containing entity attributes, create a dictionary collection and first search and match the paper titles;
[0072] If the match is successful, the node attributes of the same nodes are merged to eliminate duplicate entities. For example, if two nodes represent the same paper, but one node contains the publication year of the paper and the other node contains the author information of the paper, the two nodes will be merged into one node containing the information of both;
[0073] After the match is successful, if the node attributes of the two nodes conflict, manual review will be performed to ensure the accuracy of the node data;
[0074] Step 3: Knowledge Graph Construction
[0075] like Figure 3 As shown in the figure, the knowledge graph construction mainly includes the following steps:
[0076] (1) Initialize the database connection, that is, specify the database address and authentication information, and use the py2neo function library to initialize the connection with the Neo4j database;
[0077] (2) Reading preprocessed data, that is, extracting the data preprocessed in step 2, including entity information such as articles, authors, keywords, and the relationship data between them;
[0078] (3) Create a graph database node, that is, create a node in the graph database for each unique entity;
[0079] For example, for the Author entity, the method creates a node with the Author tag and a name attribute;
[0080] (4) Create relationship edges, that is, use the constructed general format Cypher statements to implement the logic of creating entity relationship edges in the graph database;
[0081] Step 4: Knowledge graph-enhanced large language model structure design
[0082] like Figure 4 As shown in the figure, the constructed knowledge graph is combined with the API of the big language model by using the LangChain and other function libraries, and a knowledge graph-enhanced big language model question-answering chain is designed. The big language model question-answering chain connects users, big language models and knowledge graph databases.
[0083] Among them, the large language model question-answering chain plays a role in question understanding and transformation, and integrating query results; the knowledge graph plays a role in providing query data;
[0084] Among them, the implementation process of the large language model question-answering chain is as follows:
[0085] When the user enters a natural language question, the program sends the knowledge graph structure to the large language model;
[0086] At this point, the big language model understands the user's question based on the knowledge graph structure, and generates a knowledge graph query statement corresponding to the question based on the prompt template. The question-answer chain uses the query statement to query the knowledge graph and sends the query results to the big language model.
[0087] Afterwards, the large language model generates more accurate and specific answers based on the query results and its own generation capabilities and the corresponding prompt templates;
[0088] Step 5: Question and Answer System Construction
[0089] The visual question-answering system plays a key role as an action guide for the present invention. Simply using the above-mentioned question-answering chain is not a user-friendly architecture.
[0090] Finally, it is displayed as a chat interface in the form of a web, and the chat interface includes:
[0091] A website homepage, the homepage including a question-answering module, the question-answering module being used to conduct a dialogue with a large language model;
[0092] The history page is used to view the question and answer history.
[0093] For users, there is no need to understand complex architectures. They only need to input the questions they want to ask, and the system will output the answers of the large language model enhanced by the knowledge graph. This greatly reduces the cost of use and facilitates promotion.
[0094] Embodiment 2:
[0095] like Figure 1 As shown, by adopting the design method in Example 1, we obtain a question-answering system based on a knowledge-enhanced large model, including:
[0096] Data collection module: The data collection module uses crawler programs, such as DBLP, CNKJ and Sci-Hub, to collect text data in the field. The crawled fields include paper title, abstract, publication time, author, and keywords. The collected text data are divided into domestic conferences, academic journals, dissertations and Chinese patents.
[0097] Data preprocessing module, the data preprocessing module has:
[0098] A1) File integrity check: For each article, we first divide it into sections and mark the font size and number of characters in each section. At the same time, we build a regular expression list containing multiple keywords to match the sections containing the keywords in the list. If the section lacks the keywords, it is not complete.
[0099] A2) Coding standardization: For node articles containing entity attributes, a dictionary set is created and the paper titles are searched and matched first;
[0100] A3) Content filtering: merging node attributes of the same nodes to eliminate duplicate entities. For example, if two nodes represent the same paper, but one node contains the publication year of the paper and the other node contains the author information of the paper, the two nodes will be merged into one node containing the information of both nodes.
[0101] A4) Data classification: Use natural language processing technology to extract knowledge from the collected text data, extract entities and their attributes and relationships between entities, and perform knowledge fusion and standardization on the extracted content to form a data representation of a triple structure;
[0102] Knowledge graph building module,The knowledge graph building module includes;
[0103] B1) Knowledge extraction unit, initializes database connection, that is, specifies the address and authentication information of the database, and uses the py2neo function library to initialize the connection with the Neo4j database;
[0104] Then extract the data preprocessed in step 2 of embodiment 1, including entity information such as articles, authors, keywords, and relationship data between them;
[0105] B2) Knowledge fusion and standardization unit, creating graph database nodes, that is, creating a node in the graph database for each unique entity;
[0106] For example, for the Author entity, the method creates a node with the Author tag and a name attribute;
[0107] Then create relationship edges, that is, use the constructed general format Cypher statements to implement the logic of creating entity relationship edges in the graph database;
[0108] B3) Knowledge storage unit, using computer storage media to achieve data storage, such as flash memory stick;
[0109] Database, which is built based on Neo4j graph database software and is used to store knowledge graphs;
[0110] Large language model layer. The large language model can be Huawei PanGu-α, BLOOM, UL2, etc., which has the functions of question understanding, query conversion and answer construction. Among them:
[0111] Question understanding: after the user enters the question in the interface, it is converted into computer language;
[0112] Query conversion is to import the computer language corresponding to the question into the database;
[0113] Answer construction is to temporarily construct the knowledge graph related to the above questions and display it;
[0114] Presentation layer, the presentation layer is configured with:
[0115] C1) Flask interactive interface is a lightweight Web application framework written in Python, which can be used to realize the interaction between the front-end and back-end;
[0116] C2) Get request window is an area for users to input questions and is set in the Flask interactive interface;
[0117] C3) POST request window is the area for displaying answers and is set in the Flask interactive interface;
[0118] Front-end UI: The front-end UI can use technologies such as Html, CSS or Javascript, and finally be displayed as a Flask interactive interface through the web.
[0119] The above is only a preferred embodiment of the present invention. It should be noted that, for those skilled in the art, several improvements and modifications can be made without departing from the principles of the present invention, and these improvements and modifications should also be considered as the protection scope of the present invention. The structures, devices and operating methods not specifically described and explained in the present invention shall be implemented according to the conventional means in the art unless otherwise specified and limited.
Claims
1. A method for designing a question-answering system based on a knowledge-enhanced large model, characterized in that: The following steps are involved: S1: Collection of text data in the field; S2: data preprocessing; S3: Build a knowledge graph; S4: Knowledge graph enhanced large language model framework design; S5: Question and answer system construction.
2. The method for designing a question-answering system based on a knowledge-enhanced large model according to claim 1, characterized in that: The step S1 specifically includes: collecting text data in the field, writing a Python program to crawl relevant paper data, patent data, and report data from academic resource websites; Among them, the crawled fields include paper title, abstract, publication time, author, and keywords. The collected text data are divided into domestic conferences, academic journals, dissertations and Chinese patents.
3. The method for designing a question-answering system based on a knowledge-enhanced large model according to claim 2, characterized in that: The Python programs include DBLP, CNKJ and Sci-Hub.
4. The method for designing a question-answering system based on a knowledge-enhanced large model according to claim 1, characterized in that: The data preprocessing in step S2 includes file integrity checking, encoding standardization, content screening and data classification.
5. The method for designing a question-answering system based on a knowledge-enhanced large model according to claim 4, characterized in that: The step S2 also includes: using natural language processing technology to extract knowledge from the text data collected in step S1, extracting entities and their attributes and relationships between entities, and performing knowledge fusion and standardization processing on the extracted content to form a data representation of a triple structure.
6. The method for designing a question-answering system based on a knowledge-enhanced large model according to claim 1, characterized in that: The knowledge graph in step S3 includes defining entities, entity attributes and relationships between entities; At the same time, the Neo4j graph database platform is used to store the constructed triple structure data, and the data query language Cypher is used to implement the addition, deletion, modification and query operations of the knowledge graph.
7. The method for designing a question-answering system based on a knowledge-enhanced large model according to claim 1, characterized in that: The step S4 specifically includes: combining the constructed knowledge graph with the large language model through the LangChain function library, designing a large language model question-answering chain structure, so that the large language model question-answering chain calls the information in the knowledge graph when answering questions, so as to improve the accuracy of the answers.
8. The method for designing a question-answering system based on a knowledge-enhanced large model according to claim 7, characterized in that: The step S4 also includes a method for enhancing the large language model question-answer chain structure, which is specifically as follows: M1: Connect the knowledge graph with the large language model so that the large language model can understand the knowledge graph structure; M2: Design query hint documents to enable the large language model to understand natural language questions and then construct Cypher query statements to search in the knowledge graph; M3: Design answer prompt documents so that the large language model can integrate the answers according to certain rules after querying the knowledge and generate standardized answers.
9. The method for designing a question-answering system based on a knowledge-enhanced large model according to claim 1, characterized in that: The step S5 specifically includes: finally displaying a chat interface in a web form, wherein the chat interface includes: A website homepage, the homepage including a question-answering module, the question-answering module being used to conduct a dialogue with a large language model; The history page is used to view the question and answer history.
Citation Information
Patent Citations
Knowledge question-answering system construction method and system
CN117033571A
Text index enhanced question and answer method and system based on knowledge graph
CN117453851A
Question and answer method and system based on tin smelting knowledge graph
CN118779424A