A method for entity relationship extraction based on large language model

By constructing tips containing label relationship definitions, support set samples and background knowledge, the performance of large language models in relation extraction is improved, and the problems of low retrieval quality and weak inference ability in the existing technology are solved, and efficient and capable Explained entity relationship extraction.

CN118673923BActive Publication Date: 2024-11-05安徽思高智能科技有限公司
View PDF 7 Cites 0 Cited by

Patent Information

Application Number
CN202411139659.5
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-08-20
Publication Date
2024-11-05
Estimated Expiration
2044-08-20

AI Technical Summary

Technical Problem

When using the large language model for relationship extraction, the existing relationship extraction method based on large language model has problems such as low retrieval quality and weak inference ability. Especially in the absence of a large amount of labeled data, it is difficult to effectively identify entity relationships and understand.

Method used

By building better tips, including label relationship definition, support set samples, reasoning explanation, background knowledge and other information, we can improve the performance of large language models in relation extraction tasks. Specific steps include obtaining the data to be used, defining the interpretation relationship label, retrieving similar sample samples, generating inference explanations, and combining background information in the knowledge base to form a more comprehensive prompt input to the large language model for relational reasoning.

Benefits of technology

This method greatly reduces the cost of data annotation, enhances the semantic understanding of entity relations by the model, improves generalization and robustness, and enhances the interpretability of the model through natural language inference explanation, achieving efficient entity relations Extract.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118673923B_ABST
    Figure CN118673923B_ABST
Patent Text Reader

Abstract

The present invention discloses an entity relationship extraction method based on a large language model, which aims to improve the generalization performance of the relationship extraction task. The method first prepares data including a training data set and a test data set, and encodes the text using a pre-trained word embedding model. Then, a large language model is used to generate a definition description for the predefined entity relationship tags to help the model understand the meaning of various relationships. For each sample in the test data set, the k most similar support set samples are retrieved by calculating the similarity with the training sample. And the support set samples are used to generate a reasoning explanation of the relationship. At the same time, the background knowledge of the subject and object entities in the test sample is retrieved from the knowledge base. Finally, the relationship definition, support set samples and reasoning explanation, background knowledge and other information are constructed as prompts, and input into the large language model for relationship reasoning to obtain a prediction result.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention belongs to the technical field of natural language processing (NLP) and artificial intelligence (AI), and in particular to an entity relationship extraction method based on a large language model. Background Art

[0002] Relation extraction aims to identify semantic relationships between predefined entity pairs from text, and is a core task of knowledge acquisition and natural language understanding. Early relationship extraction systems mainly used methods based on pattern matching and heuristic rules, but they were difficult to cope with the diversity and complexity of language expressions. In recent years, with the development of deep learning technology, a series of neural network-based relationship extraction models have been proposed, such as CNN, RNN, Transformer, etc., which have greatly improved the performance of relationship extraction. However, these models usually require a large amount of high-quality labeled data for training, and are limited by labeling costs and domain adaptability in practical applications.

[0003] In recent years, large pre-trained language models (such as BERT, GPT, etc.) have made remarkable achievements in many NLP tasks. In particular, large-scale generative language models such as GPT-4 have demonstrated amazing in-context learning capabilities, that is, they can extract relations on new samples with only a small number of demonstration samples as context. However, despite GPT-4's remarkable achievements in many NLP tasks, its performance in relation extraction still lags significantly behind models that are fine-tuned using a large amount of annotated data (such as BERT). This is mainly because the current construction of relation extraction task prompts based on large language models lacks corresponding background information and reasoning path guidance. Existing methods still have limitations such as low retrieval quality and weak reasoning ability when using large language models for relation extraction. Summary of the invention

[0004] The present invention proposes an entity relationship extraction method based on a large language model, which mainly constructs better prompts through information such as label relationship definition, support set samples and reasoning explanation, background knowledge, etc., thereby improving the performance of the large language model in relationship extraction tasks.

[0005] A method for extracting entity relations based on a large language model, comprising:

[0006] S1: Get the data to be used, including the training data set D train And the test dataset D test ;

[0007] S2: Define and explain the predefined entity relationship labels;

[0008] S3: Test data set D testEach test sample in i , e si , r i , e oi ), by using the training data set D train Retrieve k similar examples from the source and generate reasoning explanations using a large language model; where r i represents the true relation label of the test sample, e si represents the main entity of the test sample, e oi Represents the object entity of the test sample, content i Represents the original text of the test sample, i=1,2,3,...,m, m is a positive integer;

[0009] S4: Retrieve the main entity e in the test sample from the knowledge base KB si and customer entity oi background knowledge and concatenate it into context information c i ;

[0010] S5: Define the relationship set D rel , support set S i and reasoning explanation E i , context information c i Splice into prompt p i , input to the large language model;

[0011] S6: Large language model based on prompt p i , for the test sample (content i ,e si ,r i ,e oi ) performs relational reasoning and outputs the predicted relational label y i ';

[0012] S7: The predicted relationship label y i 'With the true relationship label r i Compare and evaluate the performance of the large language model. When the preset accuracy is reached, the final large language model is obtained. The final large language model can be used to extract any entity relationship.

[0013] A storage device stores instructions and data for implementing an entity relationship extraction method based on a large language model.

[0014] An entity relationship extraction device based on a large language model comprises: a processor and the storage device; the processor loads and executes instructions and data in the storage device to implement an entity relationship extraction method based on a large language model.

[0015] The technical solution provided by the present invention has the following beneficial effects: the present invention constructs a novel prompt learning paradigm by introducing rich information such as relationship definition explanation, support set retrieval and reasoning explanation, entity background knowledge, etc. The method utilizes the powerful language understanding and generation capabilities of the large language model, and can realize the relational reasoning of new samples given only a small number of examples. Compared with traditional methods, the present invention does not rely on large-scale manually annotated data, which greatly reduces the cost of data annotation; by introducing prior knowledge from multiple perspectives, the model's semantic understanding ability of entity relationships is enhanced; by adopting a more natural prompt form, the model can make reasoning decisions based on specific contexts, which improves the generalization and robustness of the method. In addition, the natural language reasoning explanation generated by the present invention also greatly enhances the interpretability of model predictions, which helps people understand the judgment basis of the model. In short, the present invention provides a new method for entity relationship extraction with high data efficiency, strong generalization and good interpretability, which is expected to be widely used in the fields of knowledge graph construction, intelligent question answering, semantic search, etc. This method cleverly integrates multi-source information such as relationship definition explanation, support set example reasoning, entity background knowledge, etc. into the prompt learning paradigm, making full use of the language understanding and generation capabilities of the large language model to achieve efficient relationship extraction. BRIEF DESCRIPTION OF THE DRAWINGS

[0016] The present invention will be further described below with reference to the accompanying drawings and embodiments, in which:

[0017] Figure 1 It is a flow chart of the entity relationship extraction method based on a large language model of the present invention;

[0018] Figure 2 It is a schematic diagram of the operation of the hardware device of the present invention. DETAILED DESCRIPTION

[0019] In order to have a clearer understanding of the technical features, purposes and effects of the present invention, specific embodiments of the present invention are now described in detail with reference to the accompanying drawings.

[0020] like Figure 1 As shown, the present invention provides an entity relationship extraction method based on a large language model, which mainly includes the following steps:

[0021] S1: Data preparation. Prepare the training data set D train And the test dataset D test data.

[0022] The implementation process of step S1 is:

[0023] S1.1: Training dataset D train Contains n training samples (content j , e sj , rj , e oj ), where content i is the original text of the training sample, e sj represents the main entity of the training sample, e oj represents the object entity of the training sample, r j represents the true relationship label of the training sample, j=1,2,3,...,n, where n is a positive integer;

[0024] S1.2: Test Dataset D test Contains m test samples (content i , e si , r i , e oi ), the format is the same as the training data set. i represents the original text of the test sample, r i represents the true relation label of the test sample, e si represents the main entity of the test sample, e oi Represents the object entity of the test sample, i=1,2,3,...,m, m is a positive integer, r i ,r j ∈R, R is a set of predefined relationship labels. i Use output performance to evaluate model performance.

[0025] S2: Define and explain the predefined entity relationship tags. Generate each relationship tag r using a large language model i The definition of ∈R describes d i , so that the model understands the meaning of various relationships.

[0026] The implementation process of step S2 is:

[0027] S2.1: For each test sample, the true relation label r i , construct the prompt "Please explain the relationship <r i >Definition and judgment conditions", input large language model to generate response d i .

[0028] S2.2: The generated response d i and the true relation label r i Composition tuple (r i ,d i ), get the relationship definition set D rel .

[0029] S3: Test data set D test Each test sample (content, e s , r, eo ), by using the training data set D train Retrieve k similar examples from the , and use the large language model to generate reasoning explanations. Among them, r represents a predefined entity relationship label, e s Represents the main entity, e o Represents the object entity, and content represents the original text of the test sample.

[0030] The implementation process of step S3 is:

[0031] S3.1: The original text content and main entity e in the training and test datasets s , customer entity o Perform preprocessing and word embedding processing.

[0032] S3.1.1: Use a pre-trained word embedding model (such as Word2Vec, GloVe, etc.) to encode the original text content and obtain the context embedding vector v c . For the main entity e s and customer entity o Perform similar encoding to obtain the entity embedding v s and v o .

[0033] S3.1.2: Concatenate entity embedding and context embedding to obtain enhanced entity representation v s '=[v s ;v c ],v o '=[v o ;v c ].

[0034] S3.2: For each test sample (content i , e si , r i , e oi )∈Dtest, calculate its difference with all training samples (content j , e sj , r j , e oj )∈D train The triple similarity sim_tri((content i , e si , r i , e oi ),(content j , e sj , r j , e oj)), select the k samples with the highest similarity as the support set S i The calculation formula for triple similarity is:

[0035] sim_tri((content i , e si , r i , e oi ), (content j , e sj , r j , e oj )) = cos(v si ',v sj ') + cos(v oi ', v oj ')

[0036] Among them, v si 'For the test sample (content i , e si , r i , e oi ) is the concatenated embedding of the main entity and context, v oi 'For the test sample (content i , e si , r i , e oi ) is the concatenated embedding of the object entity and context, v sj 'For training samples (content j , e sj , r j , e oj )’s main entity and context concatenation embedding, v oj 'For training samples (content j , e sj ,r j , e oj ) is the concatenated embedding of the object entity and the context, and cos(·) is the cosine similarity function.

[0037] S3.3: For S i Each sample (content ik ,s ik ,r ik ,o ik ), construct prompts and input into the large language model to generate relations (s ik ,r ik ,o ik ) is valid for the inference explanation E i Among them, content ikrepresents the original text of the sample in the support set, s ik represents the subject and object of the sample in the support set, r ik represents the true relation label of the sample in the support set, o ik Represents the object entity of the sample in the support set.

[0038] S3.4: S i The corresponding inference explanation E i The annotation data D that constitutes the test sample i . Annotation Data D i Contains explanatory information about the predicted relationship of the test sample, support set S i Given a training sample similar to the test sample, the inference explanation E i This explains why the relationships between these similar samples are established. This explanatory information can help users understand and verify the basis for the model's prediction of relationships.

[0039] S4: Retrieve the main entity e in the test sample from the knowledge base KB si and customer entity oi background knowledge and concatenate it into context information c i .

[0040] The implementation process of step S4 is:

[0041] S4.1: The knowledge base KB consists of SPO triples (entity, attribute, attribute value). For each entity e to be retrieved, find all its corresponding attribute values ​​in KB, denoted as KB(e).

[0042] S4.2: For the main entity e si and customer entity oi , retrieve background knowledge KB(e si ) and KB(e oi ), KB(e si ) and KB(e oi ) is concatenated into context information c i .

[0043] S5: Define the relationship D rel , support set S i and reasoning explanation E i , context information c i The information is spliced ​​and organized into prompts i , input to the large language model. Tip p i Set to: Splice (D rel , S i , E i , c i , content i , e si, e oi ).

[0044] S6: Large language model based on prompt p i , for the test sample (content i , e si , r i , e oi ) performs relational reasoning and outputs the prediction result y i '.

[0045] The implementation process of step S6 is:

[0046] S6.1: The prompt p i Input the large language model and generate a response a i .

[0047] S6.2: Responses generated from a large language model i Further extract the predicted relationship label, denoted as y i '. We can design a mapping function f:a i →y i 'To achieve, for example, based on keyword matching, regular expressions, etc. i Extract the predicted relationship label y i '.

[0048] S7: Evaluate the performance of large language models. i 'With the true relationship label r in the test dataset i Compare and calculate the accuracy, precision, recall, F1 value and other evaluation indicators. If the current model performance is poor, the same method can be used to continue to optimize until the accuracy of entity relationship extraction reaches the preset accuracy, and the final large language model is obtained. The final large language model can be used to extract any entity relationship.

[0049] See also Figure 2 , Figure 2 It is a schematic diagram of the working of the hardware device of an embodiment of the present invention, and the hardware device specifically includes: an entity relationship extraction device 201 based on a large language model, a processor 202 and a storage device 203.

[0050] An entity relationship extraction device 201 based on a large language model: The entity relationship extraction device 201 based on a large language model implements the entity relationship extraction method based on a large language model.

[0051] Processor 202: The processor 202 loads and executes instructions and data in the storage device 203 to implement the entity relationship extraction method based on a large language model.

[0052] Storage device 203: The storage device 203 stores instructions and data; the storage device 203 is used to implement the entity relationship extraction method based on a large language model.

[0053] 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 method for extracting entity relations based on a large language model, characterized in that: include: S1: Get the data to be used, including the training data set D train And the test dataset D test ; S2: Define and explain the predefined entity relationship labels; The implementation process of step S2 is: S2.1: For each test sample, the true relation label r i , construct the prompt "Please explain the relationship <r i >Definition and judgment conditions", input large language model to generate response d i ; S2.2: d i and the true relation label r i Composition tuple (r i ,d i ), get the relationship definition set D rel ; S3: Test data set D test Each test sample in i , e si , r i , e oi ), by using the training data set D train Retrieve k similar examples from the source and generate reasoning explanations using a large language model; where r i represents the true relation label of the test sample, e si represents the main entity of the test sample, e oi Represents the object entity of the test sample, content i Represents the original text of the test sample, i=1,2,3,...,m, m is a positive integer; The implementation process in step S3 is: S3.1: Preprocess and embed the samples in the training dataset and the test dataset, where the samples include training samples and test samples; S3.2: For each test sample (content i , e si , r i , e oi ), calculate its difference with all training samples (content j ,e sj , r j , e oj )'s triple similarity sim_tri((content i , e si , r i , e oi ),(content j , e sj , r j ,e oj )), select the k samples with the highest similarity as the support set S i ; The calculation formula for triple similarity is: sim_tri((content i , e si , r i , e oi ), (content j , e sj , r j , e oj )) = cos(v si ', v sj ') +cos(v oi ', v oj ') Among them, v si 'For the test sample (content i , e si , r i , e oi ) is the concatenated embedding of the main entity and context, v oi 'For the test sample (content i , e si , r i , e oi ) is the concatenated embedding of the object entity and context, v sj 'For training samples (content j , e sj , r j , e oj )’s main entity and context concatenation embedding, v oj 'For training samples (content j , e sj ,r j , e oj ) is the concatenated embedding of the object entity and the context, cos(·) is the cosine similarity function; S3.3: For S i Each sample (content ik ,s ik ,r ik ,o ik ), construct prompts and input them into the large language model to generate relations (s ik ,r ik ,o ik ) is valid for the inference explanation E i , among which, content ik represents the original text of the sample in the support set, s ik represents the subject and object of the sample in the support set, r ik represents the true relation label of the sample in the support set, o ik Represents the object entity that supports the samples in the set; S3.4: S i The corresponding inference explanation E i The annotation data D that constitutes the test sample i ; S4: Retrieve the main entity e in the test sample from the knowledge base KB si and customer entity oi background knowledge and concatenate it into context information c i ; S5: Define the relationship set D rel , support set S i and reasoning explanation E i , context information c i Splice into prompt p i , input to the large language model; S6: Large language model based on prompt p i , for the test sample (content i ,e si ,r i ,e oi ) performs relational reasoning and outputs the predicted relational label y i '; S7: The predicted relationship label y i 'With the true relationship label r i Compare and evaluate the performance of the large language model. When the preset accuracy is reached, the final large language model is obtained. The final large language model can be used to extract any entity relationship.

2. The entity relationship extraction method based on a large language model as claimed in claim 1, characterized in that: The implementation process of step S1 is: S1.1: Training dataset D train Contains n training samples (content j , e sj , r j , e oj ), where content j represents the original text of the training sample, e sj represents the main entity of the training sample, e oj represents the object entity of the training sample, r j represents the true relationship label of the training sample, j=1,2,3,...,n, r j ∈R, R is a set of predefined entity relationship labels; S1.2: Test Dataset D test Contains m test samples (content i , e si , r i , e oi ), the format is the same as the training dataset.

3. The entity relationship extraction method based on a large language model as claimed in claim 1, characterized in that: The implementation process of step S3.1 is: S3.1.1: Use the pre-trained word embedding model to encode the original text of the sample and obtain the context embedding vector v c ; Encode the main entity and the guest entity similarly to obtain the entity embedding v s and v o ; S3.1.2: Concatenate entity embedding and context embedding to obtain enhanced entity representation v s '=[v s ;v c ],v o '=[v o ;v c ].

4. The entity relationship extraction method based on a large language model as claimed in claim 1, characterized in that: The implementation process of step S4 is: S4.1: The knowledge base KB consists of SPO triples (entity, attribute, attribute value). For each entity e to be retrieved, find all its corresponding attribute values ​​in KB, denoted as KB(e); S4.2: For the main entity e si and customer entity oi , retrieve background knowledge KB(e si ) and KB(e oi ), KB(e si ) and KB(e oi ) is concatenated into context information c i .

5. The entity relationship extraction method based on a large language model as claimed in claim 1, characterized in that: The implementation process of step S6 is: S6.1: The prompt p i Input to the large language model to generate a response a i ; S6.2: By designing a mapping function f:a i →y i ', the response a generated from the large language model i Further extract the predicted relationship label, denoted as y i '.

6. A storage device, characterized in that: The storage device stores instructions and data for implementing the entity relationship extraction method based on a large language model as described in any one of claims 1 to 5.

7. An entity relationship extraction device based on a large language model, characterized in that: include: A processor and a storage device; the processor loads and executes instructions and data in the storage device to implement the entity relationship extraction method based on a large language model as described in any one of claims 1 to 5.

Citation Information

Patent Citations

  • Entity relationship extraction method and device based on ontology knowledge enhancement

    CN116757205A

  • Knowledge graph and large language model-based relationship extraction method and system and medium

    CN117494806A

  • Relation extraction method based on prompt learning and external knowledge embedding

    CN117725999A

  • Small sample triple extraction method based on large model and knowledge graph fusion

    CN117952104A

  • Relationship extraction method based on multi-modal large language model

    CN117972121A