A document-level relation extraction method based on hybrid hint tuning
By adopting a mixed prompt tuning method in document-level relationship extraction, combined with graph neural network and sentence-level semantic retrieval technology, the problem of difficult to capture document-level structured knowledge and semantic information in the existing technology is solved, and efficient and accurate document-level relationship extraction is achieved.
Patent Information
- Application Number
- CN202510300734.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-03-14
- Publication Date
- 2025-05-23
- Estimated Expiration
- 2045-03-14
AI Technical Summary
The prior art is difficult to effectively capture structured knowledge and semantic information between entities in document-level relationship extraction, especially in scenarios across sentences and paragraphs, resulting in limited relationship extraction effects.
A method based on mixed prompt tuning is adopted to construct a document-level knowledge graph through graph neural network, and augment the generation mechanism of sentence-level semantic retrieval is combined to generate mixed prompts containing structured knowledge and semantic information, and a large language model is optimized through efficient parameter fine-tuning to improve the accuracy of relationship extraction.
It realizes effective extraction of complex entity relationships across sentences, segments and even documents, significantly improves the accuracy, logical consistency and robustness of document-level relationship extraction, and shows high performance and practical value in practical applications.
Smart Images

Figure CN119829745B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of natural language processing, and in particular to a document-level relationship extraction method based on hybrid prompt tuning. Background Art
[0002] Document-level relation extraction is an important task in the field of natural language processing. Its goal is to extract semantic relations between entities from documents. Compared with sentence-level relation extraction, document-level relation extraction faces greater challenges, mainly in the following aspects:
[0003] First, entities in a document may appear across multiple sentences or even paragraphs, which requires the model to have global document understanding capabilities. For example, in a document describing a person’s resume, the relationship between the person and the organization he works for may be described in different paragraphs.
[0004] Secondly, although existing methods based on pre-trained language models have advantages in semantic understanding, they are insufficient in capturing structured knowledge between entities. These models are difficult to effectively model the interactive information between entities and relations, resulting in limited relationship extraction effects.
[0005] Third, existing methods often ignore the semantic similarities between different sentences and lack effective use of relevant contextual information, which makes it difficult for the model to infer implicit relationships across sentences.
[0006] Therefore, there is an urgent need for a document-level relation extraction method that can simultaneously utilize structured knowledge and semantic information and enhance the performance of large language models through hybrid cues. Summary of the invention
[0007] Purpose of the invention: The technical problem to be solved by the present invention is to provide a document-level relationship extraction method based on hybrid prompt tuning in view of the shortcomings of the prior art, comprising the following steps:
[0008] Step 1: Use graph neural networks (GNNs) to build a document-level knowledge graph DocKG from observable document data, including: learning the representation of entities and relations in documents, modeling the interactions between entities and relations, and building a knowledge graph that reflects the document structure information; then, retrieve relevant subgraphs from the document-level knowledge graph DocKG based on similarity calculations, and convert the retrieved subgraphs into structured prompt content;
[0009] Step 2, design a sentence-level semantic retrieval enhancement generation SetRAG mechanism, including: splitting the document into two or more independent sentences, using the pre-trained language model PLM to generate a semantic embedding vector for each sentence, and building a sentence-level knowledge base SetKB; then, calculating the semantic relevance between the query and the sentence based on cosine similarity, and retrieving the set of sentences most relevant to the query; finally, using the retrieved related sentences and the context information of the sentences to generate semantically rich prompt content, and obtain sentence-level semantic retrieval results, which are used to enhance the large language model LLM's understanding of cross-sentence relations;
[0010] Step 3, integrating the prompt content obtained in step 1 and the sentence-level semantic retrieval results obtained in step 2, enhancing the generated SetRAG prompt content, and forming a hybrid prompt; then, using the hybrid prompt, the large language model LLM is optimized through the parameter efficient fine-tuning PEFT method, so that the optimized large language model LLM can more accurately identify and extract the relationship between entities in the document, and complete the document-level relationship extraction task.
[0011] Step 1 includes: In order to overcome the heterogeneity of large language model (LLM) enhanced entity representation, the present invention focuses on modeling the interaction between entities and relations so as to better capture contextual information in documents.
[0012] Formally, we define the graph structure , where E is the set of all entities identified in the document; R is the set of predefined relationship types; each entity Initialize to feature vector Each relationship Initialize as a relation vector ;in represents a d-dimensional real vector space;
[0013] Then, the message is passed through the graph neural network GNNs, and the representation of entity e in the i-th layer is updated using the following formula: :
[0014] (1) ,
[0015] in, represents the neighbor entity of entity e; represents the set of neighbor entities directly connected to entity e; W is a learnable parameter matrix used to transform entity representation; c is a bias vector used to increase the flexibility of the large language model LLM; σ is a nonlinear activation function used to introduce nonlinear capabilities; is the representation of the neighbor entity in the previous layer; through L layers of iteration, where L ≥ 2, the representation of the entity at different levels is obtained , forming an L-layer representation of the entity to capture structural information at different abstraction levels, i takes values from 1 to L, Representation of entity e at level L.
[0016] In step 1, after obtaining the L-layer representation of the entity, the interaction score between entity pairs is calculated using the following formula (2):
[0017] (2) ,
[0018] Among them, the mth entity of the relationship to be judged The nth entity of the relationship to be determined Composition entity pair ; For entity pairs The interaction score between For Entity The representation vector in the last layer, i.e. the Lth layer; For Entity Representation vector at the last layer; For entity pairs The representation vector of the relationship between them; where m∈[1,|E|], n∈[1,|E|], and m≠n, |E| is the number of all entities identified in the document; Represents a vector dot product operation; a higher interaction score indicates a greater likelihood that a relationship exists between two entities.
[0019] Step 1 also includes: predicting the relationship type based on the interaction score, modeling the interaction between entities and relationships, and constructing a document-level knowledge graph based on threshold judgment. :
[0020] First, the relationship probability is calculated by the normalized exponential function Softmax:
[0021] (3) ,
[0022] Then, we construct a document-level knowledge graph based on the probability threshold. , that is, when the relationship When the predicted probability exceeds the threshold, the corresponding triple Add to document-level knowledge graph middle:
[0023] (4) ,
[0024] in, Indicates relation type, j∈[1,U], represents the pth relationship type, p∈[1,U], U is the total number of relationship types, and j and p can be equal; Represents entity pair There is a jth relationship type between probability; Represents entity pair With the jth relationship type The matching score of is the preset probability threshold, which is generally 0.7, and exp is the natural exponential function.
[0025] Step 1 also includes: From the document-level knowledge graph Retrieve information from:
[0026] First, by pre-training the language model The given query Convert to vector representation , the formula is:
[0027] (5),
[0028] in, It is the embedding layer function of the pre-trained language model PLM;
[0029] Then, for each entity e, the cosine similarity is used to calculate its vector representation obtained by the last layer (layer L) of the graph neural network GNNs model and Similarity between :
[0030] (6),
[0031] in, and Respectively The norm and The norm of
[0032] Next, based on the calculated similarity, select the document-level knowledge graph Related entities in the graph and construct candidate subgraphs , that is, if and only if the entity With query Similarity When it is greater than the preset threshold, the entity Entities that are judged to be semantically relevant to the query are selected into the candidate subgraph , whose expression is:
[0033] (7),
[0034] in, Document-level knowledge graph The set of all entities in ; is the similarity threshold used to filter related entities;
[0035] Then, through the candidate subgraph Generate a large language model The prompt combines the relationships between entities in the graph to create informative prompts, expressed as:
[0036] (8),
[0037] in, The generated prompt content; is the generating function; Dedicated to document-level knowledge graphs The generator function of ; Candidate subgraph All entity and relation pairs in ; By adopting the proposed document-level knowledge graph The retrieval method effectively utilizes the structural information between different entities and relations. Rich entity-relationship interactions are extracted and generated as prompts, which further improves the large language model. Performance on the document-level relation extraction task.
[0038] Step 2 includes:
[0039] Document Split into sentence sets :
[0040] (9) ,
[0041] in, is the sentence segmentation function; is the total number of sentences;
[0042] Then, each sentence is passed through the pre-trained language model After encoding, vector representation is obtained and combined to build a sentence-level knowledge base :
[0043] (10) ,
[0044] in, Represents a pre-trained language model Encoding function; For the Sentences The semantic vector representation of .
[0045] In step 2, for the query , semantic similarity calculation and retrieval are performed in the following ways:
[0046] Calculation query Semantic similarity with sentences in the knowledge base :
[0047] (11) ,
[0048] in, Indicates that the query Through pre-trained language model The vector representation obtained after encoding; is the first sentence in the sentence-level knowledge base SetKB Sentences The semantic vector representation of ;
[0049] Then, the sentence-level knowledge base SetKB is retrieved to find the sentence matching the query. Most relevant Sentences:
[0050] (12) ,
[0051] in, Represents the most similarity retrieved from the knowledge base A set of sentences; To obtain the highest similarity Function of a sentence; Sentence-level knowledge base The Sentences The semantic vector representation of ;
[0052] Finally, generate a large language model Information tips :
[0053] (13),
[0054] in, To extract information from the collection The set of entities, relations, and entity triples automatically identified in ; For the collection The first triples, ; A function that converts a set of triples into a natural language description Enhanced generation specifically for sentence-level semantic retrieval The generator function of ; is a set expression, indicating The integration of sentence-level semantic retrieval enhancement generation SetRAG enhances the ability of large language models to accurately extract relations by providing rich semantically relevant information, thereby ultimately improving the performance of document-level relation extraction.
[0055] Step 3 includes: generating a mixed prompt containing structured knowledge and semantic information using the following formula :
[0056] (14) ,
[0057] in, Represents the document-level knowledge graph The structured information retrieved from Represents the sentence-level knowledge base The semantic information obtained by retrieval;
[0058] In step 3, the following formula is used to efficiently fine-tune the parameters:
[0059] (15) ,
[0060] in, Representing a large language model Encoding function; For large language models The original parameters of Parameters for the imported adapter modules, including document knowledge path adapter parameters and semantic search path adapter parameters , which are used to process document-level knowledge graphs The extracted structural information and contextual information obtained by sentence-level semantic retrieval; For large language models Final output.
[0061] The present invention also provides an electronic device, comprising a processor and a memory, wherein the memory stores program code, and when the program code is executed by the processor, the processor executes the steps of the described method.
[0062] The method of the present invention utilizes a combination of graph neural networks and pre-trained language models to extract important information from documents. Specifically, the method first constructs a document-level knowledge graph to identify entities and relationships in the document. Subsequently, the semantic relevance of each sentence is analyzed through a sentence-level semantic retrieval enhancement generation mechanism to ensure that the extracted information has global consistency. Under the multi-task learning framework, the model is fine-tuned using an adapter module to flexibly adjust the focus in multiple tasks, thereby optimizing the prediction results of document-level relationships. In this way, the method can effectively capture and integrate information at multiple levels, achieving accurate and efficient document-level relationship extraction.
[0063] The present invention has the following beneficial effects: 1. The present invention utilizes the hybrid-prompt tuning method of document-level knowledge graph construction and a large language model to achieve effective extraction of complex entity relationships across sentences, paragraphs, and even documents, which helps to fully capture the deep semantic associations in the document.
[0064] 2. The present invention integrates structured knowledge with semantic retrieval enhancement technology (RAG) and adopts a parameter efficient fine-tuning strategy (PEFT) to significantly improve the accuracy, logical consistency and robustness of document-level relationship extraction while keeping the model parameters basically unchanged.
[0065] 3. The technical solution of the present invention provides an efficient and scalable solution to the shortcomings of the prior art in long text and multi-entity relationship scenarios, thereby improving the overall performance and practicality in the field of document-level relationship extraction. BRIEF DESCRIPTION OF THE DRAWINGS
[0066] Figure 1 It is a knowledge graph construction flowchart.
[0067] Figure 2 It is a semantic retrieval flowchart.
[0068] Figure 3 It is a hybrid prompt tuning flow chart. DETAILED DESCRIPTION
[0069] The present invention will be further described in detail below in conjunction with the accompanying drawings and specific embodiments, and the above and / or other advantages of the present invention will become more clear.
[0070] The embodiment of the present invention provides a document-level relationship extraction method based on hybrid prompt tuning, comprising the following steps:
[0071] Step 1: Use graph neural networks (GNNs) to build a document-level knowledge graph DocKG from observable document data, including: learning the representation of entities and relations in documents, modeling the interactions between entities and relations, and building a knowledge graph that reflects the document structure information; then, retrieve relevant subgraphs from the document-level knowledge graph DocKG based on similarity calculations, and convert the retrieved subgraphs into structured prompt content;
[0072] Step 2, design a sentence-level semantic retrieval enhancement generation SetRAG mechanism, including: splitting the document into two or more independent sentences, using the pre-trained language model PLM to generate a semantic embedding vector for each sentence, and building a sentence-level knowledge base SetKB; then, calculating the semantic relevance between the query and the sentence based on cosine similarity, and retrieving the set of sentences most relevant to the query; finally, using the retrieved related sentences and the context information of the sentences to generate semantically rich prompt content, and obtain sentence-level semantic retrieval results, which are used to enhance the large language model LLM's understanding of cross-sentence relations;
[0073] Step 3, integrating the prompt content obtained in step 1 and the sentence-level semantic retrieval results obtained in step 2, enhancing the generated SetRAG prompt content, and forming a hybrid prompt; then, using the hybrid prompt, the large language model LLM is optimized through the parameter efficient fine-tuning PEFT method, so that the optimized large language model LLM can more accurately identify and extract the relationship between entities in the document, and complete the document-level relationship extraction task.
[0074] Step 1 includes: First, formally, define the graph structure ,in is the set of all entities identified in the document; is a set of predefined relationship types; each entity Initialize to feature vector Each relationship Initialize as a relation vector ;in represents a d-dimensional real vector space.
[0075] Through message passing by a multi-layer graph neural network GNN based on the graph attention mechanism, the entity representation of the i-th layer is updated as formula (1):
[0076] (1) ,
[0077] in, represents the neighbor entity of entity e; represents the set of neighbor entities directly connected to entity e; W is a learnable parameter matrix used to transform entity representation; c is a bias vector used to increase the flexibility of the large language model LLM; σ is a nonlinear activation function used to introduce nonlinear capabilities; is the representation of the neighbor entity in the previous layer; through L layers of iteration, where L ≥ 2, the representation of the entity at different levels is obtained , forming an L-layer representation of the entity to capture structural information at different abstraction levels, i takes values from 1 to L, Representation of entity e at level L.
[0078] After obtaining the L-layer representation of the entity, the interaction score between the entity pairs is calculated using the following formula (2): :
[0079] (2) ,
[0080] Among them, the mth entity of the relationship to be judged The nth entity of the relationship to be determined Composition entity pair ; For entity pairs The interaction score between For Entity The representation vector in the last layer, i.e. the Lth layer; For Entity Representation vector at the last layer; For entity pairs The representation vector of the relationship between them; where m∈[1,|E|], n∈[1,|E|], and m≠n, |E| is the number of all entities identified in the document; Represents a vector dot product operation; a higher interaction score indicates a greater likelihood that a relationship exists between two entities.
[0081] Next, the relationship type is predicted based on the interaction score:
[0082] The relationship probability is calculated by the normalized exponential function Softmax:
[0083] (3) ,
[0084] Then build a document-level knowledge graph based on the probability threshold :
[0085] (4) ,
[0086] in, Indicates relation type, j∈[1,U], represents the pth relationship type, p∈[1,U], U is the total number of relationship types, and j and p can be equal; Represents entity pair There is a jth relationship type between probability; Represents entity pair With the jth relationship type The matching score of is the preset probability threshold, which is generally 0.7, and exp is the natural exponential function.
[0087] Step 1 also includes: From the document-level knowledge graph Retrieve information from:
[0088] First, a given query q is converted into a vector representation through a pre-trained language model , the formula is:
[0089] (5),
[0090] in, Embedding layer function for pre-trained language model;
[0091] Then, for each entity e, the cosine similarity is used to calculate its vector representation obtained by the last layer (layer L) of the graph neural network GNNs model and The similarity between :
[0092] (6),
[0093] Next, based on the calculated similarity, select The most relevant entities and construct candidate subgraphs , the expression is:
[0094] (7),
[0095] in, Document-level knowledge graph The set of all entities in ; is the similarity threshold used to filter related entities;
[0096] Then, through the candidate subgraph Generate LLM prompts, combining the relationships between entities in the graph to create informative prompts, expressed as:
[0097] (8),
[0098] in, To generate the prompt content, is the generating function, is a generator function specifically for DocKG, Candidate subgraph By adopting the proposed DocKG retrieval method, the structural information between different entities and relations is effectively utilized. Rich entity-relationship interactions are extracted and generated as hints, which further improves the performance of LLM on document-level relation extraction tasks.
[0099] Step 2 includes:
[0100] Document Split into sentence sets :
[0101] (9) ,
[0102] in, is the sentence segmentation function; is the total number of sentences;
[0103] For each sentence, obtain the vector representation through the pre-trained language model:
[0104] (10) ,
[0105] in, Represents a pre-trained language model Encoding function; For the Sentences The semantic vector representation of .
[0106] Then, for the query , semantic similarity calculation and retrieval are performed in the following ways:
[0107] Calculation query Semantic similarity with sentences in the knowledge base :
[0108] (11) ,
[0109] Then, the sentence-level knowledge base SetKB is retrieved to find the sentence matching the query. Most relevant Sentences:
[0110] (12) ,
[0111] in, Represents the most similarity retrieved from the knowledge base A set of sentences; To obtain the highest similarity Function of a sentence; Sentence-level knowledge base The Sentences The semantic vector representation of ;
[0112] Finally, generate a large language model Information tips :
[0113] (13),
[0114] in, To extract information from the collection The set of entities, relations, and entity triples automatically identified in ; For the collection The first triples, ; A function that converts a set of triples into a natural language description Enhanced generation specifically for sentence-level semantic retrieval The generator function of ; is a set expression, indicating All triples in ;
[0115] Step 3 includes: generating a mixed prompt containing structured knowledge and semantic information using the following formula :
[0116] (14) ,
[0117] in, Represents the document-level knowledge graph The structured information retrieved from Represents the sentence-level knowledge base The semantic information obtained by retrieval.
[0118] Then, use the following formula to fine-tune the parameters:
[0119] (15) ,
[0120] in, Representing a large language model Encoding function; For large language models The original parameters of Parameters for the imported adapter modules, including document knowledge path adapter parameters and semantic search path adapter parameters , which are used to process document-level knowledge graphs The extracted structural information and contextual information obtained by sentence-level semantic retrieval; For large language models Final output.
[0121] The document-level relation extraction method based on hybrid prompt tuning uses a combination of graph neural networks and pre-trained language models to extract important information from documents. Specifically, the method first builds a document-level knowledge graph to identify entities and relations in the document. Subsequently, the semantic relevance of each sentence is analyzed through a sentence-level semantic retrieval enhancement generation mechanism to ensure that the extracted information is globally consistent. Under the multi-task learning framework, the model is fine-tuned using an adapter module to flexibly adjust the focus in multiple tasks, thereby optimizing the prediction results of document-level relations. In this way, the method can effectively capture and integrate information at multiple levels, achieving accurate and efficient document-level relation extraction.
[0122] The present invention effectively solves the problem of cross-sentence relationship extraction through document-level knowledge graphs, realizes complex relationship reasoning between entities through a hybrid prompt mechanism, and achieves efficient training effects through a low-rank adaptation method. In actual application tests, the F1 score of the present invention reached 63.87%, an increase of 1.79 percentage points over the existing optimal method; by increasing the parameter amount by only 0.1%, the training time is reduced by 78% compared with full parameter fine-tuning; in cross-domain tests, the performance decline does not exceed 5%, while the existing methods decline by an average of 12%; in actual scenario tests such as medical documents and financial reports, the average accuracy rate is improved by 15%. These results fully demonstrate the advancement and practical value of the present invention in document-level relationship extraction tasks.
[0123] The present invention provides a document-level relationship extraction method based on hybrid prompt tuning. There are many methods and ways to implement the technical solution. The above is only a preferred implementation of the present invention. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principle of the present invention. These improvements and modifications should also be regarded as the protection scope of the present invention. All components not specified in this embodiment can be implemented by existing technologies.
Claims
1. A document-level relation extraction method based on hybrid prompt tuning, characterized in that: The following steps are involved: Step 1: Use graph neural networks (GNNs) to build a document-level knowledge graph DocKG from observable document data, including: learning the representation of entities and relations in documents, modeling the interactions between entities and relations, and building a knowledge graph that reflects the document structure information; then, retrieve relevant subgraphs from the document-level knowledge graph DocKG based on similarity calculations, and convert the retrieved subgraphs into structured prompt content; Step 2, design a sentence-level semantic retrieval enhancement generation SetRAG mechanism, including: splitting the document into two or more independent sentences, using the pre-trained language model PLM to generate a semantic embedding vector for each sentence, and building a sentence-level knowledge base SetKB; then, calculating the semantic relevance between the query and the sentence based on cosine similarity, and retrieving the set of sentences most relevant to the query; finally, using the retrieved related sentences and the context information of the sentences to generate semantically rich prompt content, and obtain sentence-level semantic retrieval results, which are used to enhance the large language model LLM's understanding of cross-sentence relations; Step 3, integrating the prompt content obtained in step 1 and the sentence-level semantic retrieval results obtained in step 2, enhancing the generated SetRAG prompt content, and forming a hybrid prompt; then, using the hybrid prompt, the large language model LLM is optimized through the parameter efficient fine-tuning PEFT method, so that the optimized large language model LLM can more accurately identify and extract the relationship between entities in the document, and complete the document-level relationship extraction task.
2. The method according to claim 1, characterized in that Step 1 includes: defining the graph structure ,in is the set of all entities identified in the document; is a set of predefined relationship types; each entity Initialize to feature vector Each relationship Initialize as a relation vector ;in represents a d-dimensional real vector space; Then, the message is passed through the graph neural network GNNs, and the representation of entity e in the i-th layer is updated using the following formula: : (1), in, represents the neighbor entity of entity e; represents the set of neighbor entities directly connected to entity e; W is a learnable parameter matrix used to transform entity representation; c is a bias vector; σ is a nonlinear activation function; is the representation of the neighbor entity in the previous layer; through L layers of iteration, where L ≥ 2, the representation of the entity at different levels is obtained , forming an L-layer representation of the entity to capture structural information at different abstraction levels, i takes values from 1 to L, Representation of entity e at level L.
3. The method according to claim 2, characterized in that In step 1, after obtaining the L-layer representation of the entity, the interaction score between entity pairs is calculated using the following formula (2): (2) , Among them, the mth entity of the relationship to be judged The nth entity of the relationship to be determined Composition entity pair ; For entity pairs The interaction score between For Entity The representation vector in the last layer, i.e. the Lth layer; For Entity Representation vector at the last layer; For entity pairs The representation vector of the relationship between them; where m∈[1,|E|], n∈[1,|E|], and m≠n, |E| is the number of all entities identified in the document; Represents a vector dot product operation.
4. The method according to claim 3, characterized in that Step 1 also includes: predicting the relationship type based on the interaction score, modeling the interaction between entities and relationships, and constructing a document-level knowledge graph based on threshold judgment. : First, the relationship probability is calculated by the normalized exponential function Softmax: (3) , Then, we construct a document-level knowledge graph based on the probability threshold. , that is, when the relationship When the predicted probability exceeds the threshold, the corresponding triple Add to document-level knowledge graph middle: (4) , in, Indicates relation type, j∈[1,U], represents the pth relationship type, p∈[1,U], where U is the total number of relationship types; Represents entity pair There is a jth relationship type between The probability of Represents entity pair With the jth relationship type The matching score of is the preset probability threshold, and exp is the natural exponential function.
5. The method according to claim 4, characterized in that Step 1 also includes: From the document-level knowledge graph Retrieve information from: First, by pre-training the language model The given query Convert to vector representation , the formula is: (5), in, It is the embedding layer function of the pre-trained language model PLM; Then, for each entity e, the cosine similarity is used to calculate its vector representation obtained by modeling the graph neural network GNNs at layer L and The similarity between : (6), in, and Respectively The norm and The norm of ; Next, based on the calculated similarity, select the document-level knowledge graph Related entities in the graph and construct candidate subgraphs , that is, if and only if the entity With query Similarity When it is greater than the preset threshold, the entity Entities that are judged to be semantically relevant to the query are selected into the candidate subgraph , whose expression is: (7), in, Document-level knowledge graph The set of all entities in ; is the similarity threshold used to filter related entities; Then, through the candidate subgraph Generate a large language model The prompt combines the relationships between entities in the graph to create informative prompts, expressed as: (8), in, The generated prompt content; is the generating function; For document-level knowledge graph The generator function of ; Candidate subgraph All entity and relationship pairs in .
6. The method according to claim 5, characterized in that Step 2 includes: Document Split into sentence sets : (9) , in, is the sentence segmentation function; is the total number of sentences; Then, each sentence is passed through the pre-trained language model After encoding, vector representation is obtained and combined to build a sentence-level knowledge base : (10) , in, Represents a pre-trained language model Encoding function; For the Sentences The semantic vector representation of .
7. The method according to claim 6, characterized in that In step 2, for the query , semantic similarity calculation and retrieval are performed in the following ways: Calculation query Semantic similarity with sentences in the knowledge base : (11) , in, Indicates that the query Through pre-trained language model The vector representation obtained after encoding; is the first sentence in the sentence-level knowledge base SetKB Sentences The semantic vector representation of ; Then, the sentence-level knowledge base SetKB is retrieved to find the sentence matching the query. Most relevant Sentences: (12) , in, Represents the most similarity retrieved from the knowledge base A set of sentences; To obtain the highest similarity Function of a sentence; Sentence-level knowledge base The Sentences The semantic vector representation of ; Finally, generate a large language model Information tips : (13), in, To extract information from the collection The set of entities, relations, and entity triples automatically identified in ; For the collection The first triples, ; A function that converts a set of triples into a natural language description Enhanced generation for sentence-level semantic retrieval The generator function of ; is a set expression, indicating All triples in .
8. The method according to claim 7, characterized in that Step 3 includes: generating a mixed prompt containing structured knowledge and semantic information using the following formula : (14) , in, Represents the document-level knowledge graph The structured information retrieved from Represents the sentence-level knowledge base The semantic information obtained by retrieval.
9. The method according to claim 8, characterized in that In step 3, the following formula is used to efficiently fine-tune the parameters: (15) , in, Representing a large language model Encoding function; For large language models The original parameters of Parameters for the imported adapter modules, including document knowledge path adapter parameters and semantic search path adapter parameters , which are used to process document-level knowledge graphs The extracted structural information and contextual information obtained by sentence-level semantic retrieval; For large language models Final output.
10. An electronic device, characterized in that: The method comprises a processor and a memory, wherein the memory stores program codes, and when the program codes are executed by the processor, the processor executes the steps of the method according to any one of claims 1 to 9.
Citation Information
Patent Citations
Method and device for constructing knowledge graph based on power grid related file and medium
CN117194682A
Relation extraction across sentence boundaries
US20170351749A1