Knowledge graph analysis and question answering method and device based on large language model
Through a method based on a large language model, structured and unstructured data are converted into triple data, knowledge graphs are constructed, and automated construction and question-and-answer are realized through fine-tuning of the model, which solves the problems of knowledge graph construction difficulties and inaccurate generation results, lowers the threshold for use and improves the efficiency and accuracy of the system.
Patent Information
- Application Number
- CN202411877963.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-19
- Publication Date
- 2025-03-25
AI Technical Summary
In the prior art, knowledge graph construction is difficult and the generation results are inaccurate, the user's usage threshold is high, and the scope of application is limited.
Using a method based on a large language model, a knowledge graph is constructed by converting structured data and unstructured data into triple data, and a large model is optimized by fine-tuning the large language model, so as to automatically build a knowledge graph and a question-and-answer system.
It effectively reduces the threshold for using knowledge graphs, improves the instability of the knowledge graph question and answer system, and improves the accuracy of query results and the efficiency of the system.
Smart Images

Figure CN119691243A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of artificial intelligence technology, and in particular to a knowledge graph analysis and question-answering method and device based on a large language model. Background Art
[0002] With the continuous development of artificial intelligence technology, knowledge graphs, a network structure used to display complex entity relationships in the form of graphs, have also begun to be widely used. In the fields of search engines, recommendation systems, question-answering systems, natural language processing, etc., knowledge graphs have greatly improved the effectiveness and user experience of these systems, and facilitated knowledge reasoning and mining. However, the construction of knowledge graphs not only requires a lot of manpower and computing resources, but also requires regular updates and maintenance to maintain its timeliness. How to achieve truly intelligent graph construction and application management is still in the process of continuous exploration.
[0003] The traditional knowledge graph question-answering system imports files into it by building a knowledge storage module, and then uses a large model for reasoning. Although it guarantees the accuracy of the output content to a large extent, its feedback content is severely fragmented and cannot be effectively summarized and generalized. It requires manual assistance and is inefficient. In addition, although the existing technology can feedback logically clear content by relying on the semantic analysis and generation capabilities of large models, it is difficult for the system to correctly convert complex query questions involving professional fields, resulting in unstable accuracy of feedback knowledge. At the same time, the user threshold is high, it cannot be widely used, and the scope of application is limited. Summary of the invention
[0004] The embodiments of the present application solve the problems in the prior art of difficult knowledge graph construction and inaccurate generation results by providing a knowledge graph analysis and question-answering method and device based on a large language model. A large language model is used to process raw data with diverse and complex structures to construct a knowledge graph. The large language model is fine-tuned to obtain an optimized large model, and the knowledge graph is gradually analyzed to obtain the final answer. According to the feedback mechanism, the large model is continuously iterated and updated to optimize. A new paradigm is used to complete the tasks of graph construction and graph analysis question-answering, effectively lowering the threshold for using knowledge graphs.
[0005] In a first aspect, an embodiment of the present application provides a knowledge graph analysis and question-answering method based on a large language model, comprising: obtaining original data, performing data processing based on a large language model to obtain target data, constructing a knowledge graph based on the target data, and storing the knowledge graph in a graph database; wherein the original data includes structured data, semi-structured data, and unstructured data; obtaining an open source data set, processing the open source data set using a large language model to obtain a training data set; constructing a dictionary based on the graph database, the dictionary being used to reflect the graph structure of the graph database; fine-tuning the large language model using the training data set, the dictionary, and preset prompt instructions to obtain an optimized large model; generating a query statement based on a user's query question using the graph database and the optimized large model, and determining a query result in the graph database based on the query statement; integrating the query question and the query result based on the optimized large model to obtain a final answer.
[0006] In a possible implementation, the data processing based on the large language model to obtain the target data includes: classifying the semi-structured data as the unstructured data for unified processing; based on the large language model, extracting nodes and relationship edges from the unstructured data, and extracting implicit relationships from the structured data to obtain entities and relationship edges of the original data; merging the entities and the relationship edges to obtain structured triple data, and the structured triple data is the target data.
[0007] In a possible implementation, the open source dataset is processed using a large language model to obtain a training dataset, including: based on the large language model, natural language processing is performed on the open source dataset to obtain a semantic parsing dataset; based on the semantic parsing dataset and the knowledge graph, an optimized question-answer pair is obtained based on a small number of sample learning strategies; the training dataset includes the semantic parsing dataset and the optimized question-answer pair.
[0008] In a possible implementation, constructing a dictionary based on the graph database includes: embedding the structured triple data in the knowledge graph into a low-dimensional vector space to obtain an embedding vector and an identifier based on a graph embedding technology; converting the embedding vector and the identifier into text form to construct the dictionary.
[0009] In a possible implementation, the fine-tuning of the large language model using the training data set, the dictionary and the preset prompt instructions includes: generating input text according to the questions of the training data in the training data set, the dictionary and the prompt instructions; inputting the input text into the large language model to obtain output text; and fine-tuning the large language model through lightweight fine-tuning technology and gradient optimization algorithm according to the query statement corresponding to the question of the training data in the training data set and the output text.
[0010] In a possible implementation, the generation of a query statement using the graph database and the optimized big model includes: matching key information in the graph database according to the query question to obtain a matching result; and converting the query question and the matching result into the query statement based on the optimized big model.
[0011] In a possible implementation, after obtaining the final answer, it also includes: setting a feedback mechanism to collect users' evaluations of the final answer to obtain feedback question-answer pairs; adding the feedback question-answer pairs to the training data set to obtain the optimal data set to optimize the optimization large model.
[0012] In a second aspect, an embodiment of the present application provides a knowledge graph analysis and question-answering device based on a large language model, comprising: a data processing module, used to obtain raw data, and perform data processing based on a large language model to obtain target data, construct a knowledge graph based on the target data, and store the knowledge graph in a graph database; wherein the raw data includes structured data, semi-structured data and unstructured data; a model fine-tuning module, used to obtain an open source data set, and process the open source data set using a large language model to obtain a training data set; based on the graph database, a dictionary is constructed, and the dictionary is used to reflect the graph structure of the graph database; the large language model is fine-tuned using the training data set, the dictionary and preset prompt instructions to obtain an optimized large model; an analysis module, used to generate a query statement based on a user's query question using the graph database and the optimized large model, and determine a query result in the graph database based on the query statement; a question-answering module, used to integrate the query question and the query result based on the optimized large model to obtain a final answer.
[0013] In a third aspect, an embodiment of the present application provides a device for performing a knowledge graph analysis and question-answering method based on a large language model, the device comprising: a processor; a memory for storing processor executable instructions; when the processor executes the executable instructions, it implements the method described in the first aspect or any possible implementation of the first aspect.
[0014] In a fourth aspect, an embodiment of the present application provides a non-volatile computer-readable storage medium, wherein the non-volatile computer-readable storage medium includes a device for storing a computer program or instructions, and when the computer program or instructions are executed, the method described in the first aspect or any possible implementation method of the first aspect is implemented.
[0015] One or more technical solutions provided in the embodiments of the present application have at least the following technical effects or advantages: The embodiment of the present application adopts a knowledge graph analysis and question-answering method and device based on a large language model, converts structured data and unstructured data into triple data, and builds a knowledge graph based on a large language model, which effectively solves the problem of difficulty in building a knowledge graph. Based on the query question input by the user, a grammatically compliant cypher executable statement is generated. The optimized large model is obtained by fine-tuning the large language model, and the optimized large model is continuously iterated and optimized through a feedback mechanism. The process of automatically building a knowledge graph is realized, the instability of the knowledge graph question-answering system is improved, and the user's usage threshold is lowered in combination with the large model. BRIEF DESCRIPTION OF THE DRAWINGS
[0016] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings required for use in the embodiments of the present application or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0017] Figure 1 A flowchart of a knowledge graph analysis and question-answering method based on a large language model provided in an embodiment of the present application; Figure 2 A schematic diagram of a training data instruction provided in an embodiment of the present application; Figure 3 A schematic diagram of a prompt instruction template provided in an embodiment of the present application; Figure 4 A schematic diagram of the question-answering results of the knowledge graph provided in an embodiment of the present application; Figure 5 A schematic diagram of the results of the feedback mechanism provided in the embodiment of the present application; Figure 6 A schematic diagram of the structure of a knowledge graph analysis and question-answering device based on a large language model provided in an embodiment of the present application. DETAILED DESCRIPTION
[0018] The technical solutions in the embodiments of the present application will be described clearly and completely below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, rather than 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.
[0019] The following describes some of the techniques involved in the embodiments of the present application to facilitate understanding, and they should be considered as merely exemplary. Therefore, it should be appreciated by those of ordinary skill in the art that various changes and modifications may be made to the embodiments described herein without departing from the scope and spirit of the present application. Similarly, for the sake of clarity and conciseness, some descriptions of well-known functions and structures are omitted in the following description.
[0020] Figure 1 It is a flowchart of a knowledge graph analysis and question-answering method based on a large language model provided in an embodiment of the present application, including steps 101 to 106. Figure 1 This is only an execution order shown in the embodiment of the present application, and does not represent the only execution order of the knowledge graph analysis and question-answering method based on the large language model. If the final result can be achieved, Figure 1 The steps shown may be performed in parallel or in reverse, as follows.
[0021] Step 101: Obtain the original data, and process the data based on the large language model to obtain the target data, build a knowledge graph based on the target data, and store the knowledge graph in the graph database.
[0022] In the embodiment of the present application, the original data includes structured data, semi-structured data and unstructured data.
[0023] Specifically, the original data in the application scenario is obtained and input into the large language model for data processing to obtain the target data, including: Semi-structured data is classified as unstructured data for unified processing. Due to the length limit of the context window processing of the large language model, the documents in the unstructured data are processed in blocks to obtain paragraph documents.
[0024] Based on the big language model, nodes and relationship edges are extracted from unstructured data. Specifically, paragraph documents are input into the big language model, and the extraction instructions are designed using the LLM-based (big language model extraction strategy), and the content extracted by the big language model is returned in a fixed format until all entity nodes and relationship edges between entities in the paragraph documents are extracted.
[0025] For example, for the text content of "A mudslide disaster occurred in xx county in June", the content extracted by the large language model is: [xx county, region, {}], [mudslide, disaster, {}], [xx county, occurrence, mudslide, {June}]. Among them, {} stores the attribute information of the entity. After experiments, the large language model maximizes the use of the context window of each block, minimizes the overlapping content of the context on the basis of ensuring the semantic coherence of the context, reduces redundancy, and at the same time ensures the consistency of entity nodes to a certain extent.
[0026] Rule-based (rule-based extraction strategy) is used to design matching rules, and character matching is performed on paragraph documents to obtain optimized entity nodes, and corresponding relationship edges are established, so that the large language model can extract the required information from the text and deduplicate the optimized entity nodes and their relationship edges. In an embodiment of the present application, entity nodes are usually place names, disasters, etc. Provincial, municipal, county and more fine-grained place names and common disaster names are used as matching dictionaries. According to the matching dictionary, character matching is performed on all paragraph documents, and the successfully matched content is added to the entity node.
[0027] The entity nodes and relationship edges of the unstructured data are merged. Specifically, the block processing of the text may result in the extraction of duplicate entity nodes and relationship edges between entities. Therefore, the entity deduplication method is used to input the set of all entities and relationships between entities into the large language model, and merge them to obtain structured triple data, which is the target data of the unstructured data. The node level of the knowledge graph is minimized, redundancy is reduced, and a convenient and efficient foundation is laid for subsequent knowledge graph queries and related steps. Exemplarily, all triple data and their relationship edges are input into the large language model, and a csv file (comma separated value file) is generated for each type of entity node and its relationship edge, and the knowledge graph is automatically imported using Data Importer (open source data importer) to complete the target data processing of semi-structured and unstructured data.
[0028] Based on the big language model, implicit relationships are extracted from structured data. Structured data is usually in the form of multiple tables, each of which contains a primary key and multiple attributes. Therefore, each table can be regarded as a node, and each attribute in the table can be regarded as a node attribute. Since foreign key information is usually not explicitly provided in the original database, it is impossible to know whether there is a relationship between tables. Therefore, the big language model is used to extract implicit relationships from structured data.
[0029] Specifically, the attribute column names, that is, the field names, contained in any two tables are input into the large language model to let it determine whether there are semantically consistent attribute column names. If they are contained, a relationship edge is added to the two tables. Exemplarily, taking the two tables of "Hazard Points" and "Risk Areas" as examples, the "Risk Area" contains the attribute column name "Contains Hazard Point ID", then the "ID" in the "Hazard Point" table is connected to the "Contains Hazard Point ID" in the "Risk Area" table. After analysis, there are similar attribute column names in multiple tables in the original database, such as "county", "city", "district", etc. Therefore, in order to reduce the redundancy of the knowledge graph, tables containing similar attribute column names are merged.
[0030] Merge the entity nodes and relationship edges of structured data. Specifically, input all table names and column names into the large language model, determine whether there are the same attributes in different tables and extract them. Use field names to establish table associations, extract tables with the same table name and field name based on table associations, and classify and merge them to obtain a merged set, and establish a relationship connection with the merged set to extract the target data. Exemplarily, the large language model extracts multiple attributes such as "name of person in charge", "contact information of person in charge", "disaster type", "disaster scale", etc. Then input the above attributes into the large language model, let it classify and merge the attribute set, and name it. At this time, the large language model will classify attributes such as "county" and "city" as "region" entities, and "disaster type", "disaster scale", etc. as "disaster" entities. The entity node containing the above attributes is connected to the entity node after the attribute merger.
[0031] The structured data is read into the large language model through a loop, and the entities and relationship edges are merged to obtain the target data of the structured data. The target data is converted into Cypher (graph database query statement) and imported into the knowledge graph in a sequential manner to complete the construction of the knowledge graph, and the knowledge graph is stored in a graph database such as Neo4j.
[0032] Step 102: Obtain an open source data set, and use a large language model to process the open source data set to obtain a training data set.
[0033] In the embodiments of the present application, the large language model has poor understanding of structured languages such as Cypher. It is also unable to directly understand the proper nouns and abbreviations in geological disaster business scenarios, such as "dual control system" and "deep displacement tilt". Therefore, the present application collects and generates training data sets in the general open source field and business vertical field to fine-tune the large language model.
[0034] Based on the large language model, natural language processing is performed on the open source dataset to obtain a semantic parsing dataset. For example, the Text-to-CQL open source dataset (a dataset released by the National University of Defense Technology) is obtained, which contains about 10,000 data, rich question types, and comprehensive grammar. However, since the Text-to-CQL dataset is an English dataset, it needs to be translated and the grammar rules are set using the large language model, such as the need to retain the necessary grammar such as "match" and "return" in the Cypher statement. The graph structure is described in the form of natural language, and the Chinese translation result is output using the large language model. The natural language format is as follows: "Entity: [Entity1, Entity2,...]; Relationship: [Relationship1{Entity1, Entity2}, Relationship2{},...]". After translation, a high-quality general domain semantic parsing dataset is obtained.
[0035] According to the semantic parsing dataset and knowledge graph, based on the few-shot learning strategy, the optimized question-answer pair is obtained. The training dataset includes the semantic parsing dataset and the optimized question-answer pair. For example, according to the Few-Shot (few-shot learning strategy), the obtained semantic parsing dataset is provided to the large language model, so that the large language model simply rewrites the entity relationship of the Cypher sample sentence according to the Cypher sentence format and knowledge graph to generate a new question-answer pair, that is, the optimized question-answer pair. Figure 2 As shown in the figure, design training data instructions to generate optimized question-answer pairs. The large language model is iteratively trained based on the semantic parsing dataset and the knowledge graph until an optimized question-answer pair that meets the preset conditions is generated to obtain a training dataset. If the large language model cannot directly generate a query statement correctly, such as the statement "MATCH (l:`hazard point`) WHERE l.`hazard point`.`town administrative division name` == 'Shangping Town' RETURN count(l)", a Cypher query statement can be generated based on the optimized question-answer pair, such as "MATCH (r:`risk area`) WHERE r.`risk area`.`provincial administrative division name` == 'Beijing City' RETURN count(r)".
[0036] Specifically, in order to ensure the grammatical diversity of the generated data, a large language model is used for multiple cycles, and training data is generated by setting the core sampling strategy, diversity sampling strategy, and parameters for controlling the randomness of the generated text. Exemplarily, the top_p (core sampling strategy) value range is set to (0,1], and the higher the value, the greater the randomness of the generated text; the top_k (diversity sampling strategy) value range is [0, vocabulary size], and the higher the value, the higher the diversity of the generated text, but the quality of the generated text will be reduced; the temperature (parameter that controls the randomness of the generated text) value range is [0,1], and the higher the value, the more likely the generated text will be to randomly select words. Specifically, a list of values is set in advance for the above three parameters, and in each round, a random number is selected from its value range. The values are randomly selected as the parameter values of the current cycle to ensure that in each round, as rich and diverse question-answer pairs as possible can be generated. Because the quality of question-answer pair generation is low under some parameter value settings, all generated question-answer pairs will be calibrated and judged again, that is, the large language model will be re-entered to determine whether the current question-answer pair conforms to the grammatical rules. If it does not conform to the rules, it will be modified. Finally, through the above steps, a total of about 5,000 optimized question-answer pairs related to geological disasters were obtained, which were merged with the semantic parsing dataset to obtain the training dataset for subsequent model fine-tuning.
[0037] Step 103: Construct a dictionary based on the graph database, where the dictionary is used to reflect the graph structure of the graph database.
[0038] According to the graph embedding technology, the structured triple data in the knowledge graph is embedded into the low-dimensional vector space to obtain the embedded vector and identifier; the embedded vector and identifier are converted into text form to construct a dictionary.
[0039] Specifically, a dictionary (or JSON object) is constructed based on the query results of the knowledge graph to represent the knowledge graph structure. Using graph embedding technologies such as TransE and DistMult, the entities and relationships in the knowledge graph are embedded into a low-dimensional vector space. These vectors can represent the semantic information of entities and relationships and be used for subsequent knowledge fusion. The knowledge graph is converted into a dictionary form according to the graph embedding technology, and the entities (such as places, events, etc.) in the knowledge graph are stored as nodes and the relationships as edges in the table of the graph database. The attribute information contained in each node constitutes its "label" or "key-value pair". To avoid name conflicts, a unique identifier is assigned to each node and attribute, and a namespace is created to organize related entities. At the same time, nodes and relationships can be classified according to the metadata in the graph, such as by dimensions such as field and time.
[0040] According to the input restrictions of the large language model, the dictionary structure is converted into text form. This can be achieved through serialization (such as JSON serialization) or a custom text format.
[0041] Step 104: Fine-tune the large language model using the training data set, dictionary, and preset prompt instructions to obtain an optimized large model.
[0042] In the embodiment of the present application, input text is generated according to the questions, dictionary and prompt instructions of the training data in the training data set. The questions of the training data are the questions in the semantic parsing data set and the optimized question-answer pair. Figure 3 As shown in the figure, it is a prompt instruction template for a graph database query statement, which is specifically composed of task definition, instructions, graph structure, and question examples.
[0043] Specifically, Figure 3 The "schema" in the example represents the dictionary input to the large language model, which is used as the graph structure of the prompt instruction. The task definition is to guide the large language model to generate text that meets the user's needs, such as determining to query the graph database with a declarative query statement. The questions of the training data question-answer pairs in the training data set are used as the input questions of the prompt instruction, that is, the question samples, such as "Who is the inspector of Shengli Village?". The grammar rules are defined as the instructions of the large language model.
[0044] For example, the questions and dictionaries of the training data can be combined as follows: Figure 3 The prompt instruction template shown gets the input text.
[0045] Input text is fed into a large language model to get output text.
[0046] Through the large language model, text2sql (a conversion technology that converts natural language into SQL query language) is used to convert the input text into a graph database query statement, that is, the output text.
[0047] According to the query statements corresponding to the questions in the training data set and the output text, the large language model is fine-tuned through lightweight fine-tuning technology and gradient optimization algorithm.
[0048] For example, internlm2.5-20B (a new version of the Shanghai Artificial Intelligence Laboratory's Shusheng series model) is selected as the base model, and QLora (a lightweight fine-tuning technology) is selected to update a small number of parameters. The details are as follows.
[0049] ; In the formula, Represents the optimization of the large model weight matrix, represents the weight matrix, represents a linear scalar, and represents the weight of the low-rank adapter.
[0050] First, the pre-trained model is quantized into int4 format, and then a set of learnable low-rank adapter weights are added. and , the large language model is updated by introducing two low-rank matrices instead of the weight matrix, , greatly reducing the number of weights and computational complexity. At the same time, the low-rank adapter can learn the high-order features of the original weights, thereby improving the accuracy of the model.
[0051] The large language model was trained on NVIDIA V100 Tensor Core (data center GPU) for 5 rounds, with the batch size (number of samples) set to 8, AdamW (gradient optimization algorithm) selected as the optimization algorithm, and the initial learning rate set to 1e-4, as follows.
[0052] ; In the formula, Indicates the current time The weights of the optimized large model, Indicates the last moment The weight of the large language model at the moment, represents the learning rate, represents the regularization coefficient.
[0053] After fine-tuning, Figure 4 As shown in the figure, the optimization model generated by lightweight fine-tuning technology and gradient optimization algorithm is the Luoshu large model, that is, the optimized large model.
[0054] Step 105: Based on the user's query question, a query statement is generated using the graph database and the optimized large model, and the query result is determined in the graph database based on the query statement.
[0055] In the embodiment of the present application, key information matching is performed in the graph database according to the query question input by the user to obtain the matching result. Based on the optimized large model, the query question and the matching result are converted into a query statement to obtain the query result.
[0056] Specifically, the natural language understanding of the query questions entered by the user, such as "What are the high-risk areas in Dengyun Town", identifies key information such as 'Dengyun Town' and 'risk area', matches them according to the dictionary, and obtains the matching results of the query questions. By optimizing the large model and using text2sql (a conversion technology that converts natural language to SQL query language), the user's query questions and matching results are converted into graph database query statements. The query statements are used to query in the graph database to obtain the query results.
[0057] Step 106: Based on the optimized large model, the query question and the query result are integrated and processed to obtain a final answer.
[0058] The final answer is fed back to the user interface to complete the knowledge graph question and answer.
[0059] In addition, a feedback mechanism is designed to update the optimized large model until a preset number of iterations is reached. Figure 5 As shown in the figure, users can give feedback on the current final answer by clicking like, clicking dislike and refreshing. Clicking like means that the user thinks the current analysis and answer are very good. Clicking dislike means that the current analysis and answer are correct, but the user is not satisfied with the final answer, such as problems with language logic. Refresh means that the current analysis and answer are unavailable. After the user initiates the refresh operation, the optimization model will use CoT (chain of reasoning technology) and step-by-step (prompt word skills) to optimize the final answer.
[0060] After accumulating the above user feedback, the large model can be continuously optimized iteratively. The question-answer data pairs after user feedback are added to the training data set as new data to enrich the model learning information. At the same time, the new training data set is more suitable for the specific needs and application scenarios of users.
[0061] The optimized large model in the embodiment of the present application is completed based on the dual control scenario of geological disaster risks. In order to evaluate the effect and improvement of the industry model, three evaluation indicators are designed after investigation, and the following models are selected for comparison. The model comparison results are shown in Table 1.
[0062] Table 1 Model comparison results
[0063] In the table, the evaluation indicators are Jaro-Winkler, Pass@1 and Jaccard Similarity. Among them, Jaro-Winkler means calculating the text similarity between the predicted nGQL and the true value nGQL; Pass@1 means first executing nGQL to obtain the predicted result and the true value result returned from the database, and then judging whether the predicted result and the true value result are consistent. If they are completely consistent, it is 1, otherwise it is 0; Jaccard similarity means the text similarity between the predicted result and the true value result. Qwen2-7B, internlm2_5-7b-chat, CodeGeeX4, internlm2_5-20b-chat, Luoshu large model and gpt-4 represent large language models of deep learning.
[0064] As can be seen from the table, compared with the original open source model, the fine-tuned Luoshu large model, i.e. the optimized large model, has improved by about 50%, and the accuracy has increased from 54.% to 86.2%. The fine-tuned model effect can reach the level of gpt-4. At the same time, other models can be used to replace the open source models in this application, such as Kimi, Wenxinyiyan, chatgpt4, etc.
[0065] Although the present application provides method operation steps as described in the embodiments or flowcharts, more or fewer operation steps may be included based on conventional or non-creative labor. The order of steps listed in this embodiment is only one way of executing the order of many steps and does not represent the only execution order. When the actual device or client product is executed, it can be executed in sequence or in parallel according to the method shown in this embodiment or the accompanying drawings (for example, in a parallel processor or multi-threaded processing environment).
[0066] like Figure 6 As shown, the embodiment of the present application also provides a knowledge graph analysis and question-answering device 600 based on a large language model. The device includes: a data processing module 601, a model fine-tuning module 602, an analysis module 603 and a question-answering module 604, as follows.
[0067] The data processing module 601 is used to obtain the original data, and perform data processing based on the large language model to obtain the target data, build a knowledge graph according to the target data, and store the knowledge graph in the graph database; wherein the original data includes structured data, semi-structured data and unstructured data.
[0068] A model fine-tuning module 602 is used to obtain an open source data set, and process the open source data set using a large language model to obtain a training data set; According to the graph database, a dictionary is constructed to reflect the graph structure of the graph database; The large language model is fine-tuned using the training data set, dictionary, and preset prompt instructions to obtain an optimized large model.
[0069] The analysis module 603 is used to generate a query statement based on the user's query question using the graph database and the optimized large model, and determine the query result in the graph database based on the query statement.
[0070] The question-answering module 604 is used to integrate the query questions and query results based on the optimized large model to obtain the final answer.
[0071] Some modules in the apparatus described in the present application can be described in the general context of computer executable instructions executed by a computer, such as program modules. Generally, program modules include routines, programs, objects, components, data structures, classes, etc. that perform specific tasks or implement specific abstract data types. The present application can also be practiced in distributed computing environments, in which tasks are performed by remote processing devices connected through a communication network. In a distributed computing environment, program modules can be located in local and remote computer storage media including storage devices.
[0072] The devices or modules described in the above application embodiments can be implemented by computer chips or entities, or by products with certain functions. For the convenience of description, the above devices are described in various modules according to their functions. When implementing the embodiments of the present application, the functions of each module can be implemented in the same or multiple software and / or hardware. Of course, the module that implements a certain function can also be implemented by combining multiple sub-modules or sub-units.
[0073] The methods, devices or modules described in this application can be implemented in the form of computer-readable program codes. The controller can be implemented in any appropriate manner. For example, the controller can take the form of a microprocessor or processor and a computer-readable medium storing computer-readable program codes (such as software or firmware) that can be executed by the (micro)processor, logic gates, switches, application-specific integrated circuits (English: Application Specific Integrated Circuit; Abbreviation: ASIC), programmable logic controllers and embedded microcontrollers. Examples of controllers include but are not limited to the following microcontrollers: ARC 625D, Atmel AT91SAM, Microchip PIC18F26K20 and Silicone Labs C8051F320. The memory controller can also be implemented as part of the control logic of the memory. Those skilled in the art also know that in addition to implementing the controller in the form of pure computer-readable program codes, the controller can be implemented in the form of logic gates, switches, application-specific integrated circuits, programmable logic controllers and embedded microcontrollers by logically programming the method steps. Therefore, this controller can be considered as a hardware component, and the devices included in it for implementing various functions can also be regarded as structures within the hardware component. Or even, the means for realizing various functions may be regarded as both a software module for realizing the method and a structure within a hardware component.
[0074] An embodiment of the present application also provides a device for knowledge graph analysis and question-answering methods based on a large language model, the device comprising: a processor; a memory for storing processor executable instructions; when the processor executes the executable instructions, the method described in the embodiment of the present application is implemented.
[0075] The embodiments of the present application also provide a non-volatile computer-readable storage medium on which a computer program or instruction is stored. When the computer program or instruction is executed, the method described in the embodiments of the present application is implemented.
[0076] In addition, each functional module in each embodiment of the present application may be integrated into one processing module, or each module may exist independently, or two or more modules may be integrated into one module.
[0077] The above storage media include but are not limited to random access memory (RAM), read-only memory (ROM), cache, hard disk drive (HDD) or memory card. The memory can be used to store computer program instructions.
[0078] It can be seen from the description of the above implementation methods that those skilled in the art can clearly understand that the present application can be implemented by means of software plus necessary hardware. Based on this understanding, the technical solution of the present application can be essentially or partly reflected in the prior art in the form of a software product, or it can be reflected in the implementation process of data migration. The computer software product can be stored in a storage medium, such as ROM / RAM, a magnetic disk, an optical disk, etc., including a number of instructions for a computer device (which can be a personal computer, a mobile terminal, a server, or a network device, etc.) to execute the methods described in the various embodiments of the present application or certain parts of the embodiments.
[0079] The various embodiments in this specification are described in a progressive manner, and the same or similar parts between the various embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. All or part of this application can be used in many general or special computer system environments or configurations. For example: personal computers, server computers, handheld devices or portable devices, tablet devices, mobile communication terminals, multi-processor systems, microprocessor-based systems, programmable electronic devices, network PCs, minicomputers, mainframe computers, distributed computing environments including any of the above systems or devices, etc.
[0080] The above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit the present application. Although the present application has been described in detail with reference to the aforementioned embodiments, a person of ordinary skill in the art should understand that the technical solutions described in the aforementioned embodiments may still be modified, or some or all of the technical features thereof may be replaced by equivalents. However, these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the present application.
Claims
1. A knowledge graph analysis and question answering method based on a large language model, characterized in that: include: Obtaining raw data, and performing data processing based on a large language model to obtain target data, constructing a knowledge graph based on the target data, and storing the knowledge graph in a graph database; wherein the raw data includes structured data, semi-structured data, and unstructured data; Obtain an open source data set, and process the open source data set using a large language model to obtain a training data set; According to the graph database, a dictionary is constructed, where the dictionary is used to reflect the graph structure of the graph database; Fine-tune the large language model using the training data set, the dictionary and preset prompt instructions to obtain an optimized large model; According to the user's query question, a query statement is generated using the graph database and the optimized large model, and a query result is determined in the graph database according to the query statement; Based on the optimized big model, the query question and the query result are integrated and processed to obtain a final answer.
2. The method according to claim 1, characterized in that The data processing based on the large language model to obtain target data includes: Classifying the semi-structured data as the unstructured data for unified processing; Based on the large language model, extract nodes and relationship edges from the unstructured data, and extract implicit relationships from the structured data to obtain entities and relationship edges of the original data; The entity and the relationship edge are merged to obtain structured triple data, and the structured triple data is the target data.
3. The method according to claim 1, characterized in that The method of processing the open source data set using the large language model to obtain a training data set includes: Based on the large language model, natural language processing is performed on the open source dataset to obtain a semantic parsing dataset; According to the semantic parsing dataset and the knowledge graph, based on a small number of sample learning strategies, an optimized question-answer pair is obtained; The training data set includes the semantic parsing data set and the optimized question-answer pairs.
4. The method according to claim 2, characterized in that: The step of constructing a dictionary according to the graph database includes: According to the graph embedding technology, the structured triple data in the knowledge graph is embedded into a low-dimensional vector space to obtain an embedded vector and an identifier; The embedding vector and the identifier are converted into text form to construct the dictionary.
5. The method according to claim 1, characterized in that The fine-tuning of the large language model using the training data set, the dictionary and the preset prompt instruction includes: Generate input text according to the questions of the training data in the training data set, the dictionary and the prompt instruction; Inputting the input text into a large language model to obtain an output text; According to the query sentences corresponding to the questions of the training data in the training data set and the output text, the large language model is fine-tuned through lightweight fine-tuning technology and gradient optimization algorithm.
6. The method according to claim 1, characterized in that The generating of query statements by using the graph database and the optimized large model includes: According to the query question, key information is matched in the graph database to obtain a matching result; Based on the optimized large model, the query question and the matching result are converted into the query statement.
7. The method according to claim 1, characterized in that After the final answer is obtained, it also includes: A feedback mechanism is set up to collect the user's evaluation of the final answer to obtain a feedback question-answer pair; The feedback question-answer pairs are added to the training data set to obtain an optimal data set to optimize the optimization large model.
8. A knowledge graph analysis and question-answering device based on a large language model, characterized in that: include: A data processing module is used to obtain raw data, perform data processing based on a large language model to obtain target data, construct a knowledge graph based on the target data, and store the knowledge graph in a graph database; wherein the raw data includes structured data, semi-structured data, and unstructured data; A model fine-tuning module is used to obtain an open source data set, and process the open source data set using a large language model to obtain a training data set; According to the graph database, a dictionary is constructed, where the dictionary is used to reflect the graph structure of the graph database; Fine-tune the large language model using the training data set, the dictionary and preset prompt instructions to obtain an optimized large model; An analysis module, configured to generate a query statement based on a user's query question using the graph database and the optimized large model, and determine a query result in the graph database based on the query statement; The question-answering module is used to integrate the query question and the query result based on the optimized large model to obtain a final answer.
9. A device for performing knowledge graph analysis and question answering method based on a large language model, characterized in that: include: processor; a memory for storing processor-executable instructions; When the processor executes the executable instructions, the method according to any one of claims 1 to 7 is implemented.
10. A non-volatile computer-readable storage medium, characterized in that: The device comprises a computer program or an instruction for storing the computer program or the instruction, which, when executed, enables the method according to any one of claims 1 to 7 to be implemented.
Citation Information
Cited By
Automatic building energy consumption modeling method based on large language model
CN120086954A
Project data analysis method and device, electronic equipment and storage medium
CN120316162A
Laser cladding knowledge base construction method based on large model
CN120373435A
Well drilling abnormal working condition analysis method based on large language model and knowledge graph
CN120410769A
Knowledge point extraction method for textbook and related equipment
CN120509414A