A structured knowledge injection method and system for large language models
Eliminate noise through named entity recognition, graph linking and graph neural network, and inject knowledge embedding into large language models, solving the noise problem of large language models in knowledge retrieval and utilization, improving the accuracy and efficiency of knowledge-based question and answer, and improving Ability to generate knowledge.
Patent Information
- Application Number
- CN202411117913.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-15
- Publication Date
- 2024-10-29
- Estimated Expiration
- 2044-08-15
AI Technical Summary
Existing large language models are susceptible to noise interference during the knowledge retrieval and utilization process, resulting in attention to irrelevant knowledge, affecting their reasoning capabilities, and lack of effective internal interaction and integration of knowledge and model parameters, affecting the effect of knowledge-based question and answer.
Named entity recognition technology is used to identify the entities in the question, link to the knowledge graph, construct the knowledge subgraph, use the graph neural network to eliminate noise, and map the graph-embedded knowledge to the parameterized knowledge space of the large language model for knowledge injection.
It improves the accuracy and comprehensiveness of knowledge retrieval, enhances the efficiency and accuracy of knowledge utilization, improves the knowledge generation capability of large language models, and significantly improves the accuracy and user satisfaction of knowledge question and answer.
Smart Images

Figure CN118643142B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of artificial intelligence technology, and in particular to a structured knowledge injection method and system for a large language model. Background Art
[0002] In today's information society, large language models (LLMs) have become one of the cutting-edge technologies in the field of artificial intelligence. These models, such as ChatGPT, are widely used in natural language processing, machine translation, question answering and other tasks, providing key support for social media, news reporting, online advertising, etc.
[0003] When a large language model answers complex or recent questions, the limitations of the inherent knowledge of the large language model can be compensated by retrieving external knowledge bases in real time. This approach allows the model to obtain the latest and most relevant information, improving the accuracy and comprehensiveness of the answer. Specifically, the model first understands the user's query intent, then retrieves relevant external knowledge sources, integrates this information, and generates richer and more precise answers. This approach not only improves the model's knowledge coverage and timeliness, but also significantly enhances its question-answering capabilities in diverse and complex scenarios.
[0004] With the widespread application of large language models, how to improve the model's ability to retrieve and utilize knowledge, thereby improving the knowledge generation ability of large language models and providing support for knowledge-based artificial intelligence systems, is a technical problem that needs to be solved urgently in this field. Among them, the method of utilizing large language models to retrieve knowledge is the most critical link. Existing methods mainly use knowledge graphs as the main body and language models as auxiliary reasoning. Structured knowledge such as knowledge graphs are considered to be a powerful expression of real-world knowledge in the form of a graph structure, where nodes represent entities and edges represent relationships between entities. Compared with other unstructured semantic knowledge, knowledge graphs usually contain richer structured information, which makes it more suitable for enhancing the potential learning ability of models.
[0005] Currently, research on using knowledge graphs for knowledge-based question answering attempts to combine large language models with knowledge graphs, using knowledge retrieved from knowledge graphs to assist large language models in factual reasoning.
[0006] A popular approach is to heuristically retrieve a knowledge subgraph from a large-scale knowledge graph by using the topic entity (the KG entity mentioned in a given question and candidate answer) and its few-hop neighbors, and then use this subgraph as the basis for reasoning with a large language model. Although this approach performs well, it heavily relies on the accuracy and real-time nature of the knowledge of the retrieved subgraph, and the heuristic knowledge retrieval method inevitably contains a lot of interference information (noise), and existing methods are not specifically optimized for this problem, which may cause the large language model to focus on irrelevant knowledge, thereby hindering its ability to perform accurate reasoning.
[0007] In addition, existing knowledge utilization methods adopt a black-box processing approach, that is, directly inputting the retrieved knowledge into the large language model, but cannot interact and integrate with the knowledge stored inside the parameters of the large language model, thus affecting the effect of knowledge-based question answering. Summary of the invention
[0008] In view of the above problems, the purpose of the present invention is to provide a structured knowledge injection method and system for a large language model. On the one hand, it is committed to eliminating the noise in the retrieval knowledge subgraph, and on the other hand, the factual knowledge is directly aligned in the form of parameters and injected into the internal parameters of the large language model. The above efforts aim to improve the model's ability to retrieve and utilize knowledge, thereby improving the knowledge generation ability of the large language model and providing support for knowledge-based artificial intelligence systems.
[0009] In order to solve the above technical problems, the present invention provides the following technical solutions:
[0010] On the one hand, a structured knowledge injection method for a large language model is provided, the method comprising the following steps:
[0011] S1. Use named entity recognition technology to identify and mark the entities in the question;
[0012] S2, link the identified entities on the knowledge graph;
[0013] S3, retrieve entities and their relationships on possible paths between two entities and construct a knowledge subgraph;
[0014] S4. Score the entity pairs on the knowledge subgraph according to the relevance between the entity pairs and the question;
[0015] S5. Use graph neural network to model the knowledge subgraph, and use the scoring scores to guide the graph neural network to eliminate noise;
[0016] S6. Select graph-embedded knowledge based on the knowledge subgraph and map it to the parameterized knowledge space of the large language model to obtain aligned knowledge.
[0017] S7. Inject alignment knowledge into the feedforward neural network parameters of the large language model for knowledge-based question answering.
[0018] Optionally, the step S1 specifically includes:
[0019] S101. Select named entity recognition tools based on the topic content and category, including: Stanford NER, SpaCy, HuggingFace Transformers;
[0020] S102, configuring a named entity recognition model, and fine-tuning and optimizing the named entity recognition model using the first annotated dataset according to a specific problem domain;
[0021] S103, preprocessing the question text, including removing stop words and standardizing the text format;
[0022] S104, performing entity recognition on the preprocessed question text, integrating the recognition result into the question text, generating a question text containing entity tags, and performing verification.
[0023] Optionally, the step S2 specifically includes:
[0024] S201, select knowledge graphs containing relevant knowledge according to specific application scenarios, including ConceptNet, DBpedia, and Wikidata;
[0025] S202, using a heuristic entity-level matching algorithm to preliminarily match the identified entity with the entity on the knowledge graph; the matching algorithm includes an algorithm based on text similarity or a rule-based algorithm;
[0026] S203, using the word-level and sentence-level question texts to verify the preliminary matching results, filtering out redundant entities through similarity calculation, and merging entities with the same reference;
[0027] S204. Integrate the verified matching results into the knowledge graph, including: linking the verified and merged entities to the nodes in the knowledge graph.
[0028] Optionally, the step S3 specifically includes:
[0029] S301, preprocess the knowledge graph, delete irrelevant nodes and edges, and ensure the standardization and consistency of the knowledge graph structure;
[0030] S302, using a breadth-first search algorithm or a depth-first search algorithm to retrieve all possible paths between two entities in the knowledge graph, and record the entities and their relationships on the possible paths;
[0031] S303: construct a knowledge subgraph based on the entities and their relationships in the search results, and optimize it.
[0032] Optionally, the step S4 specifically includes:
[0033] S401. Select a pre-trained language model according to specific needs, including Bert-base-uncase, RoBERTa, and ALBERT, and embed entities on the knowledge subgraph;
[0034] S402, using a multi-layer perceptron MLP as a scoring model to score the entity pairs after embedding processing, and measuring the relevance of the entity pairs to the question;
[0035] S403: Use the second labeled data set to train the scorer model and optimize the model parameters;
[0036] S404: Re-score all entity pairs on the knowledge subgraph using the trained scorer model, and review and verify the results.
[0037] Optionally, the step S5 specifically includes:
[0038] S501, select a suitable graph neural network GNN, the architecture of which includes: GCN, GraphSAGE, GAT, and initialize the knowledge subgraph;
[0039] S502, using a pre-trained model, including Bert-base-uncase, to perform text embedding representation on the nodes on the knowledge subgraph as the input of the GNN;
[0040] S503, perform unique-hot encoding on the node types and edge types in the knowledge subgraph as the basis for GNN to calculate the graph attention score;
[0041] S504. Use the GNN attention mechanism to calculate the node relevance as the graph attention score, and combine the relevance score of the entity pair with the question as the weight to dynamically adjust the graph attention score so that the GNN pays more attention to the entity pairs related to the question and eliminates noise.
[0042] Optionally, the step S6 specifically includes:
[0043] S601. According to the graph attention score in the knowledge subgraph, select the graph neural network modeling representation of the representative node as the graph embedded knowledge;
[0044] S602. Design a knowledge alignment module based on multi-layer perceptron (MLP) for parameterized knowledge in the feedforward neural network of a large language model.
[0045] S603, using the third annotated data set to train the knowledge alignment module, mapping the graph-embedded knowledge to the parameterized knowledge space of the large language model, and obtaining aligned knowledge;
[0046] S604: Verify and optimize the alignment effect.
[0047] Optionally, the step S7 specifically includes:
[0048] S701, connecting the mapped alignment knowledge with the parameters in the feedforward neural network of the large language model, and reconstructing the original feedforward neural network parameter layer;
[0049] S702, combining the newly injected alignment knowledge, remodeling the feedforward neural network of the large language model;
[0050] S703, using the remodeled large language model to perform knowledge-based question answering on the input question;
[0051] S704. Evaluate the large language model based on the question-answering results, identify and correct potential problems, and further optimize the performance of the large language model.
[0052] On the other hand, a structured knowledge injection system for a large language model is provided, for implementing any of the above methods, the system comprising:
[0053] The entity tagging module is used to identify and tag entities in the question using named entity recognition technology;
[0054] The linking module is used to link the identified entities on the knowledge graph;
[0055] The knowledge subgraph construction module is used to retrieve entities and their relationships on possible paths between two entities and construct a knowledge subgraph;
[0056] The scoring module is used to score the entity pairs on the knowledge subgraph according to the relevance of the entity pairs to the questions;
[0057] The denoising module is used to model the knowledge subgraph using the graph neural network and use the scoring scores to guide the graph neural network to eliminate noise;
[0058] The mapping module is used to select graph-embedded knowledge based on the knowledge subgraph and align it to the parameterized knowledge space of the large language model to obtain aligned knowledge.
[0059] The injection module is used to inject the aligned knowledge into the feed-forward neural network parameters of the large language model for knowledge-based question answering.
[0060] Optionally, the system further comprises a training framework, wherein the training framework comprises:
[0061] An entity recognition training module, used to train the entity recognition process;
[0062] An entity pair scoring training module, used to train the entity pair scoring process;
[0063] Preheating training module, used to preheat training of graph neural network;
[0064] The large language model LoRA fine-tuning training module is used to fine-tune the large language model using LoRA after the graph neural network warm-up training is completed;
[0065] Full parameter fine-tuning module, used to fine-tune all model parameters of the entire system;
[0066] The reasoning module is used to utilize the knowledge acquired after system training to inject the framework for reasoning in downstream tasks.
[0067] In another aspect, an electronic device is provided, the electronic device comprising:
[0068] processor;
[0069] A memory having computer-readable instructions stored thereon, wherein when the computer-readable instructions are loaded and executed by the processor, the steps of the structured knowledge injection method for a large language model as described above are implemented.
[0070] On the other hand, a computer-readable storage medium is provided, in which program code is stored. The program code can be called by a processor to execute the steps of the structured knowledge injection method for a large language model as described above.
[0071] The beneficial effects brought about by the technical solution provided by the present invention include at least:
[0072] Effect 1: The recall rate of knowledge retrieval is good. By using advanced named entity recognition (NER) technology, the system can accurately identify key entities in the question text. This precise identification lays a solid foundation for subsequent knowledge retrieval; the entity-level matching algorithm based on text similarity is adopted to ensure that the identified entities can be accurately matched to the corresponding nodes in the knowledge graph, avoiding missed detection and false detection; through secondary verification and review, the accuracy of the matching results is further improved, ensuring that the entities linked to the knowledge graph are relevant and correct; using the breadth-first search algorithm or the depth-first search algorithm, the system can retrieve all possible paths between the problem entities, build a knowledge subgraph containing rich information, and improve the comprehensiveness of knowledge retrieval.
[0073] Effect 2: The knowledge injection alignment effect is good. The designed knowledge alignment module based on the multi-layer perceptron (MLP) can map the graph-embedded knowledge to the parameterized knowledge space of the large language model to ensure seamless connection between the two. By comparing the performance of the model before and after alignment, continuous optimization and adjustment are performed to ensure the best alignment effect, so that the injected knowledge can be fully utilized by the large language model. The alignment effect is verified by comparative experiments and practical applications. Through continuous iteration and optimization, the accuracy and efficiency of knowledge alignment are improved.
[0074] Effect 3: The introduction of the designed structured knowledge injection framework can improve the accuracy of four common common sense question-answering tasks by nearly 10 percentage points on average; through continuous evaluation and optimization, potential problems of the model in question-answering tasks are discovered and corrected, ensuring that the model's question-answering performance is always in the best state; the model can respond flexibly to different question-answering instances, showing high adaptability and stability to meet various practical application needs.
[0075] Effect 4: The system can flexibly adjust the content and format of answers based on specific examples to ensure that the answers meet actual needs and improve user satisfaction; by injecting aligned knowledge into the language model, the system can use this knowledge for efficient reasoning and answering, demonstrating excellent knowledge utilization capabilities; combined with specific examples, the model can generate formatted answers to ensure that the answers are clear in structure and logically rigorous, improving the readability and professionalism of the answers. BRIEF DESCRIPTION OF THE DRAWINGS
[0076] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0077] Figure 1 is a flow chart of a structured knowledge injection method for a large language model provided by an embodiment of the present invention;
[0078] Figure 2 is a schematic diagram of a structured knowledge injection system for a large language model provided by an embodiment of the present invention;
[0079] Figure 3 It is a training framework diagram of a structured knowledge injection system for a large language model provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0080] In order to make the purpose, technical solution and advantages of the embodiment of the present invention clearer, the technical solution of the embodiment of the present invention will be clearly and completely described below in conjunction with the drawings of the embodiment of the present invention. Obviously, the described embodiment is a part of the embodiment of the present invention, not all of the embodiments. Based on the described embodiment of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0081] In the embodiments of the present invention, words such as "exemplarily" and "for example" are used to indicate examples, illustrations or explanations. Any embodiment or design described as "exemplary" in the present invention should not be interpreted as being more preferred or more advantageous than other embodiments or designs. Specifically, the word "exemplary" is used to present concepts in a specific way.
[0082] The embodiment of the present invention provides a structured knowledge injection method for a large language model, which can be implemented by an electronic device, which can be a terminal or a server. Figure 1 As shown, the processing flow of the method may include the following steps:
[0083] S1. Use named entity recognition technology to identify and mark the entities in the question.
[0084] As an optional implementation manner of the present invention, the step S1 specifically includes:
[0085] S101. Select named entity recognition tools based on the topic content and category, including Stanford NER, SpaCy, HuggingFace Transformers, etc., to achieve environment-adaptive named entity recognition.
[0086] For example, in the common sense question answering task, Stanford NER is used as a named entity recognition tool for question text to identify entities present in the paragraph.
[0087] S102: configuring a named entity recognition model, and using the first annotated data set to fine-tune and optimize the named entity recognition model according to a specific problem domain to improve recognition accuracy.
[0088] S103. Preprocess the question text, including removing stop words, standardizing the text format, etc., to ensure accuracy and consistency in the entity recognition process.
[0089] S104, performing entity recognition on the preprocessed question text, integrating the recognition result into the question text, generating a question text containing entity tags, and performing verification.
[0090] In this step, the accuracy of recognition can be ensured through verification and manual review.
[0091] S2. Link the identified entities on the knowledge graph.
[0092] In natural language processing (NLP), entity linking is an important task that involves connecting specific entities in text (such as names of people, places, organizations, etc.) with corresponding items in a structured knowledge graph. A knowledge graph is a way to store knowledge in the form of a graph, where nodes represent entities and edges represent relationships between entities. By linking question entities to a knowledge graph, the model's understanding of the question and the accuracy of the answer can be enhanced. The choice of knowledge graph is crucial because different knowledge graphs contain knowledge in different fields. The goal of an entity matching algorithm is to compare the identified entities with entities in the knowledge graph to find the best match. Common matching methods include text similarity-based algorithms such as TF-IDF, Word2Vec, and deep learning methods such as BERT embedding, which can help capture the semantic relationships between entities.
[0093] As an optional implementation manner of the present invention, the step S2 specifically includes:
[0094] S201. Select knowledge graphs containing relevant knowledge according to specific application scenarios, including ConceptNet, DBpedia, Wikidata, etc.
[0095] S202. Use a heuristic entity-level matching algorithm to preliminarily match the identified entities with entities on the knowledge graph; the matching algorithm includes an algorithm based on text similarity (such as TF-IDF, Word2Vec, BERT embedding) or a rule-based algorithm.
[0096] For example, when answering common sense questions, ConceptNet is selected as the knowledge graph of domain knowledge, and TF-IDF, an entity-level matching algorithm based on text similarity, is used to achieve preliminary matching between the identified entities and the knowledge graph entities.
[0097] S203, using word-level and sentence-level question texts to verify the preliminary matching results, filtering out redundant entities through similarity calculation, and merging entities with the same reference.
[0098] S204. Integrate the verified matching results into the knowledge graph, including: linking the verified and merged entities with the nodes in the knowledge graph to ensure the integrity and accuracy of the knowledge graph.
[0099] S3. Retrieve entities and their relationships on possible paths between two entities and construct a knowledge subgraph.
[0100] As an optional implementation manner of the present invention, the step S3 specifically includes:
[0101] S301. Preprocess the knowledge graph, delete irrelevant nodes and edges, and ensure the standardization and consistency of the knowledge graph structure to improve search efficiency.
[0102] S302. Use a breadth-first search (BFS) algorithm or a depth-first search (DFS) algorithm to retrieve all possible paths between two entities in the knowledge graph, and record the entities and their relationships on the possible paths.
[0103] S303: construct a knowledge subgraph based on the entities and their relationships in the search results, and optimize it to ensure that the structure of the knowledge subgraph is clear and free of redundancy.
[0104] S4. Score the entity pairs on the knowledge subgraph based on their relevance to the question.
[0105] In order to better utilize the factual knowledge of the external knowledge graph and eliminate the possible knowledge noise therein, the entity pairs on the knowledge subgraph are rescored according to the relevance of the problem for modeling the knowledge subgraph with the graph neural network, so as to guide the model to pay more attention to the triples that are more relevant to the problem.
[0106] As an optional implementation manner of the present invention, the step S4 specifically includes:
[0107] S401. Select a pre-trained language model according to specific needs, including Bert-base-uncase, RoBERTa, ALBERT, etc., to embed entities on the knowledge subgraph.
[0108] S402: Use a multi-layer perceptron (MLP) as a scoring model to score the entity pairs after embedding processing, and measure the relevance of the entity pairs to the question.
[0109] S403: Use the second labeled data set to train the scorer model and optimize the model parameters to improve the accuracy of scoring.
[0110] S404: Re-score all entity pairs on the knowledge subgraph using the trained scorer model, and review and verify the results.
[0111] Among them, the output of the scorer model is used as a latent variable, and the scorer model and question-answering system are combined into a unified architecture for end-to-end training.
[0112] S5. Use graph neural network to model the knowledge subgraph, and use the scoring scores to guide the graph neural network to eliminate noise.
[0113] As an optional implementation manner of the present invention, the step S5 specifically includes:
[0114] S501. Select a suitable graph neural network GNN, the architecture of which includes: GCN, GraphSAGE, GAT, etc., and initialize the knowledge subgraph.
[0115] S502. Use pre-trained models, including Bert-base-uncase, to perform text embedding representation on the nodes on the knowledge subgraph as the input of the GNN.
[0116] S503: Perform unique-hot encoding on the node types and edge types in the knowledge subgraph as the basis for GNN to calculate the graph attention score.
[0117] S504. Use the GNN attention mechanism to calculate the node relevance as the graph attention score, and combine the relevance score of the entity pair with the question as the weight to dynamically adjust the graph attention score so that the GNN pays more attention to the entity pairs related to the question and eliminates the interference of noise on the graph.
[0118] S6. Select graph-embedded knowledge based on the knowledge subgraph and map it to the parameterized knowledge space of the large language model to obtain aligned knowledge.
[0119] As an optional implementation manner of the present invention, the step S6 specifically includes:
[0120] S601. According to the graph attention scores in the knowledge subgraph, select the graph neural network modeling representation of the representative nodes as the graph embedded knowledge.
[0121] S602. Design a knowledge alignment module based on a multi-layer perceptron (MLP) for the parameterized knowledge in the feedforward neural network of a large language model.
[0122] For example: Based on the parameterized knowledge in the feedforward neural network of FLAN-T5-XL, a large language model launched by Google, a knowledge alignment module based on multi-layer perceptron (MLP) is designed.
[0123] S603. Use the third annotated data set to train the knowledge alignment module to ensure that it can effectively map the graph-embedded knowledge to the parameterized knowledge space of the large language model to obtain aligned knowledge.
[0124] S604, verify and optimize the alignment effect. Compare the performance of the model before and after alignment, and adjust and optimize the parameters of the knowledge alignment module to ensure the best alignment effect.
[0125] S7. Inject alignment knowledge into the feedforward neural network parameters of the large language model for knowledge-based question answering.
[0126] As an optional implementation manner of the present invention, the step S7 specifically includes:
[0127] S701, connecting the mapped alignment knowledge with the parameters in the feedforward neural network of the large language model, and reconstructing the original feedforward neural network parameter layer.
[0128] S702. Remodel the feedforward neural network of the large language model based on the newly injected alignment knowledge to ensure that it can effectively use the injected alignment knowledge for reasoning.
[0129] S703. Use the remodeled large language model to perform knowledge-based question answering on input questions.
[0130] In this step, the remodeled large language model is used to reason and answer the input questions, and the accuracy and reliability of its knowledge-based questions and answers are evaluated.
[0131] S704. Based on the question-answering results, evaluate the large language model, identify and correct potential problems, and further optimize the performance of the large language model to ensure its best performance in knowledge question-answering tasks.
[0132] The structured knowledge injection method for a large language model provided in an embodiment of the present invention utilizes named entity recognition technology to mark entities in questions; links entities in question text from an existing knowledge graph; retrieves entities on possible paths between two entities and their relationships to form a knowledge subgraph; re-scores entity pairs on the knowledge subgraph based on the relevance of the question; models the knowledge subgraph using a graph neural network, and uses the scores from the previous step to guide the graph neural network to eliminate noise on the graph; designs a knowledge alignment module to map graph-embedded knowledge to the parameterized knowledge space of a large language model; and injects the aligned knowledge into the feedforward neural network parameters of the large language model to perform knowledge-based question answering. First, it makes full use of external structured knowledge such as knowledge graphs, and at the same time learns the structured knowledge in the knowledge graphs; second, the proposed parameterized knowledge injection method avoids the shortcoming that previous knowledge injection cannot be aligned with internal knowledge, and effectively integrates external knowledge with internal inherent knowledge to improve the efficiency of knowledge utilization; third, the proposed method is a new paradigm in the field of retrieval enhancement. Different from the previous direct use of noisy text data retrieved, the method of the present invention can use graph neural networks to directly denoise knowledge and ensure the scientific nature of external knowledge utilization.
[0133] Accordingly, an embodiment of the present invention further provides a structured knowledge injection system for a large language model. Figure 2 FIG. 1 is a schematic diagram of a structured knowledge injection system for a large language model according to an exemplary embodiment. Figure 2 As shown, the system includes:
[0134] An entity tagging module 201 is used to identify and tag entities in the question using named entity recognition technology;
[0135] A linking module 202, for linking the identified entities on the knowledge graph;
[0136] A knowledge subgraph construction module 203 is used to retrieve entities and their relationships on possible paths between two entities and construct a knowledge subgraph;
[0137] A scoring module 204, used to score the entity pairs on the knowledge subgraph according to the relevance of the entity pairs to the question;
[0138] A denoising module 205 is used to model the knowledge subgraph using a graph neural network, and use the scoring scores to guide the graph neural network to eliminate noise;
[0139] A mapping module 206 is used to select graph-embedded knowledge based on the knowledge subgraph and align it to the parameterized knowledge space of the large language model to obtain aligned knowledge;
[0140] The injection module 207 is used to inject the alignment knowledge into the feedforward neural network parameters of the large language model to perform knowledge-based question answering.
[0141] For ease of explanation, Figure 2 Only the main components of the system are shown. The system of this embodiment can be used to perform Figure 1 The technical solution of the method embodiment shown has similar implementation principles and technical effects, which will not be repeated here.
[0142] Furthermore, the system also includes a training framework, such as Figure 3 As shown, the training framework includes:
[0143] The entity recognition training module 301 is used to train the entity recognition process; in the entire system, the parameters involved in the entity recognition training module are frozen and pre-processed in advance for system operation;
[0144] The entity pair scoring training module 302 is used to train the entity pair scoring process; the parameters of the pre-trained language model used in the entity pair scoring training module are frozen, but the scorer model based on the multi-layer perceptron is integrated with the training of the entire system into a unified training framework to train an end-to-end neural network system;
[0145] The warm-up training module 303 is used to perform warm-up training on the graph neural network. Since some parameters of the graph neural network are randomly initialized, the convergence speed of this part is relatively slow. Therefore, the model parameters of other modules are frozen first, and the warm-up training of the graph neural network is trained separately.
[0146] The large language model LoRA fine-tuning training module 304 is used to fine-tune the large language model using LoRA after the preheating training of the graph neural network is completed to promote the knowledge injection effect;
[0147] A full parameter fine-tuning module 305 is used to fine-tune all model parameters of the entire system to promote the model's instruction-following ability and enhance the system's knowledge-based question-answering ability;
[0148] The reasoning module 306 is used to utilize the knowledge injection framework obtained after system training to perform reasoning in downstream tasks.
[0149] After full system training, a plug-and-play retrieval-enhanced knowledge injection framework is obtained, which can be used to directly perform reasoning in downstream tasks.
[0150] In summary, in the embodiments of the present invention, on the one hand, efforts are made to eliminate noise in the retrieval subgraph to provide an accurate basis for factual question and answer of the large language model; on the other hand, factual knowledge is directly aligned in the form of parameters and injected into the parameters inside the large language model. The above efforts aim to improve the model's ability to retrieve and utilize knowledge, thereby improving the knowledge generation ability of the large language model, providing support for knowledge-based artificial intelligence systems, and ensuring that these technologies can provide real and reliable support in various fields such as retrieval and question and answer. As the intersection of graphs and texts, the present invention can further promote the applicability of knowledge graphs in more downstream applications, such as recommendation systems and dialogue generation.
[0151] In an exemplary embodiment, the present invention further provides an electronic device, the electronic device comprising:
[0152] processor;
[0153] A memory having computer-readable instructions stored thereon, wherein when the computer-readable instructions are loaded and executed by the processor, the steps of the structured knowledge injection method for a large language model as described above are implemented.
[0154] In an exemplary embodiment, the present invention further provides a computer-readable storage medium, wherein at least one instruction is stored in the computer-readable storage medium, and the at least one instruction is loaded and executed by a processor to implement the steps of the structured knowledge injection method for a large language model as described above. For example, the computer-readable storage medium may be a ROM, a random access memory (RAM), a CD-ROM, a magnetic tape, a floppy disk, an optical data storage device, and the like.
[0155] It should be noted that, in this article, the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, article or terminal device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or terminal device. In the absence of further restrictions, the elements defined by the sentence "comprises a ..." do not exclude the existence of other identical elements in the process, method, article or terminal device including the elements.
[0156] References in the specification to "one embodiment", "an embodiment", "an exemplary embodiment", "some embodiments", etc. indicate that the described embodiments may include a particular feature, structure, or characteristic, but not every embodiment may include the particular feature, structure, or characteristic. In addition, when a particular feature, structure, or characteristic is described in conjunction with an embodiment, it should be within the knowledge of a person skilled in the relevant art to implement such feature, structure, or characteristic in conjunction with other embodiments (whether or not explicitly described).
[0157] It should be understood that in various embodiments of the present invention, the size of the serial numbers of the above-mentioned processes does not mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present invention.
[0158] In the several embodiments provided by the present invention, it should be understood that the disclosed devices, apparatuses and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another device, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.
[0159] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0160] In addition, each functional unit in each embodiment of the present invention may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit.
[0161] If the functions are implemented in the form of software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, or the part that contributes to the prior art, or the part of the technical solution, can be embodied in the form of a software product. The computer software product is stored in a storage medium, including several instructions for enabling a computer device (which can be a personal computer, server, or network device, etc.) to perform all or part of the steps of the methods described in various embodiments of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM), random access memory (RAM), disk or optical disk, and other media that can store program codes.
[0162] The present invention covers any substitution, modification, equivalent method and scheme made on the essence and scope of the present invention. In order to make the public have a thorough understanding of the present invention, specific details are described in detail in the following preferred embodiments of the present invention, but those skilled in the art can fully understand the present invention without the description of these details. In addition, in order to avoid unnecessary confusion about the essence of the present invention, well-known methods, processes, procedures, components and circuits are not described in detail.
[0163] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principle of the present invention should be included in the protection scope of the present invention.
Claims
1. A structured knowledge injection method for a large language model, characterized in that: The following steps are involved: S1. Use named entity recognition technology to identify and mark the entities in the question; S2, link the identified entities on the knowledge graph; S3, retrieve entities and their relationships on possible paths between two entities and construct a knowledge subgraph; S4. Score the entity pairs on the knowledge subgraph according to the relevance between the entity pairs and the question; S5. Use graph neural network to model the knowledge subgraph, and use the scoring scores to guide the graph neural network to eliminate noise; The step S5 specifically includes: S501, select a suitable graph neural network GNN, the architecture of which includes: GCN, GraphSAGE, GAT, and initialize the knowledge subgraph; S502, using a pre-trained model, including Bert-base-uncase, to perform text embedding representation on the nodes on the knowledge subgraph as the input of the GNN; S503, perform unique-hot encoding on the node types and edge types in the knowledge subgraph as the basis for GNN to calculate the graph attention score; S504, using the GNN attention mechanism to calculate the node relevance as the graph attention score, and combining the relevance score of the entity pair and the question as the weight, dynamically adjust the graph attention score, so that the GNN pays more attention to the entity pairs related to the question and eliminates noise; S6. Select graph-embedded knowledge based on the knowledge subgraph and map it to the parameterized knowledge space of the large language model to obtain aligned knowledge. The step S6 specifically includes: S601. According to the graph attention score in the knowledge subgraph, select the graph neural network modeling representation of the representative node as the graph embedded knowledge; S602. Design a knowledge alignment module based on multi-layer perceptron (MLP) for parameterized knowledge in the feedforward neural network of a large language model. S603, using the third annotated data set to train the knowledge alignment module, mapping the graph-embedded knowledge to the parameterized knowledge space of the large language model, and obtaining aligned knowledge; S604, verifying and optimizing the alignment effect; S7, injecting alignment knowledge into the feedforward neural network parameters of the large language model for knowledge-based question answering; The step S7 specifically includes: S701, connecting the mapped alignment knowledge with the parameters in the feedforward neural network of the large language model, and reconstructing the original feedforward neural network parameter layer; S702, combining the newly injected alignment knowledge, remodeling the feedforward neural network of the large language model; S703, using the remodeled large language model to perform knowledge-based question answering on the input question; S704. Evaluate the large language model based on the question-answering results, identify and correct potential problems, and further optimize the performance of the large language model.
2. The structured knowledge injection method for a large language model according to claim 1, characterized in that: The step S1 specifically includes: S101. Select named entity recognition tools based on the topic content and category, including: Stanford NER, SpaCy, HuggingFace Transformers; S102, configuring a named entity recognition model, and fine-tuning and optimizing the named entity recognition model using the first annotated dataset according to a specific problem domain; S103, preprocessing the question text, including removing stop words and standardizing the text format; S104, performing entity recognition on the preprocessed question text, integrating the recognition result into the question text, generating a question text containing entity tags, and performing verification.
3. The structured knowledge injection method for a large language model according to claim 1, characterized in that: The step S2 specifically includes: S201, select knowledge graphs containing relevant knowledge according to specific application scenarios, including ConceptNet, DBpedia, and Wikidata; S202, using a heuristic entity-level matching algorithm to preliminarily match the identified entity with the entity on the knowledge graph; the matching algorithm includes an algorithm based on text similarity or a rule-based algorithm; S203, using the word-level and sentence-level question texts to verify the preliminary matching results, filtering out redundant entities through similarity calculation, and merging entities with the same reference; S204. Integrate the verified matching results into the knowledge graph, including: linking the verified and merged entities to the nodes in the knowledge graph.
4. The structured knowledge injection method for a large language model according to claim 1, characterized in that: The step S3 specifically includes: S301, preprocess the knowledge graph, delete irrelevant nodes and edges, and ensure the standardization and consistency of the knowledge graph structure; S302, using a breadth-first search algorithm or a depth-first search algorithm to retrieve all possible paths between two entities in the knowledge graph, and record the entities and their relationships on the possible paths; S303: construct a knowledge subgraph based on the entities and their relationships in the search results, and optimize it.
5. The structured knowledge injection method for a large language model according to claim 1, characterized in that: The step S4 specifically includes: S401. Select a pre-trained language model according to specific needs, including Bert-base-uncase, RoBERTa, and ALBERT, and embed entities on the knowledge subgraph; S402, using a multi-layer perceptron MLP as a scoring model to score the entity pairs after embedding processing, and measuring the relevance of the entity pairs to the question; S403: Use the second labeled data set to train the scorer model and optimize the model parameters; S404: Re-score all entity pairs on the knowledge subgraph using the trained scorer model, and review and verify the results.
6. A structured knowledge injection system for a large language model, the system being used to implement the method according to any one of claims 1 to 5, characterized in that: The system comprises: The entity tagging module is used to identify and tag entities in the question using named entity recognition technology; The linking module is used to link the identified entities on the knowledge graph; The knowledge subgraph construction module is used to retrieve entities and their relationships on possible paths between two entities and construct a knowledge subgraph; The scoring module is used to score the entity pairs on the knowledge subgraph according to the relevance of the entity pairs to the questions; The denoising module is used to model the knowledge subgraph using the graph neural network and use the scoring scores to guide the graph neural network to eliminate noise; The mapping module is used to select graph-embedded knowledge based on the knowledge subgraph and align it to the parameterized knowledge space of the large language model to obtain aligned knowledge. The injection module is used to inject the aligned knowledge into the feed-forward neural network parameters of the large language model for knowledge-based question answering.
7. The structured knowledge injection system for large language models according to claim 6, characterized in that: The system also includes a training framework, which includes: An entity recognition training module, used to train the entity recognition process; An entity pair scoring training module, used to train the entity pair scoring process; Preheating training module, used to preheat training of graph neural network; The large language model LoRA fine-tuning training module is used to fine-tune the large language model using LoRA after the graph neural network warm-up training is completed; Full parameter fine-tuning module, used to fine-tune all model parameters of the entire system; The reasoning module is used to utilize the knowledge acquired after system training to inject the framework for reasoning in downstream tasks.
