Sample relation extraction method and device, electronic equipment and storage medium

By using a relation extraction method that augments and iteratively trains data from the banking and accounting field, the problem of low accuracy in relation extraction in existing technologies is solved, and a more efficient relation extraction effect is achieved.

CN120875009APending Publication Date: 2025-10-31AGRICULTURAL BANK OF CHINA
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202511047748.1
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-07-29
Publication Date
2025-10-31

AI Technical Summary

Technical Problem

Existing relationship extraction methods in the banking and accounting field rely on a large amount of labeled data and require manual template design or feature engineering, resulting in low accuracy.

Method used

By dividing the data to be processed into multiple subsets, performing data augmentation and iterative training, using a relation extraction model to extract relations, and combining external relation sets and sentence encoders for data augmentation and model training, the accuracy of relation extraction is improved.

Benefits of technology

By iteratively processing a small number of labeled samples, the accuracy of relation extraction was improved, the amount of training data was increased, and the performance of the model was optimized.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120875009A_ABST
    Figure CN120875009A_ABST
Patent Text Reader

Abstract

The invention provides a sample relationship extraction method and device, electronic equipment and a storage medium. The method comprises the following steps: dividing to-be-processed data into N second sub-data sets; performing data enhancement on the first sub-data set to obtain an enhanced data set; performing relation extraction on the ith second sub-data set based on a relation extraction model obtained by training the first sub-data set and the enhanced data set to obtain an extraction result of the ith second sub-data set; and if i is not equal to N, taking i + 1 as i, writing the ith second sub-data set and the extraction result of the ith second sub-data set into the first data set, and returning to the step of performing data enhancement on the first sub-data set to obtain the enhanced data set. According to the method, a relation extraction model with the highest accuracy can be constructed by performing multiple iterations on a small number of labeled samples, so that the accuracy of relation extraction is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of data processing technology, and in particular to a method, apparatus, electronic device, and storage medium for extracting sample relationships. Background Technology

[0002] Building knowledge graphs in the banking and accounting field is crucial for applications such as intelligent financial analysis and risk warning.

[0003] When constructing a knowledge graph in the field of banking and accounting, the first step is to extract relationships from the data in the field of banking and accounting. Currently, commonly used relationship extraction methods rely on a large amount of labeled data and require manual design of templates or feature engineering.

[0004] Because bank accounting documents are highly specialized, have diverse formats, and are frequently updated, using the above methods to extract relationships will affect the accuracy of the extraction. Summary of the Invention

[0005] In view of this, embodiments of the present invention provide a sample relationship extraction method, apparatus, electronic device, and storage medium to solve the problem of low accuracy in relationship extraction in the prior art.

[0006] To achieve the above objectives, the embodiments of the present invention provide the following technical solutions:

[0007] A first aspect of this invention discloses a sample relationship extraction method, the method comprising:

[0008] Obtain the data to be processed and the first subset of data, where the first subset of data refers to the data that has been labeled with entity and relation types;

[0009] The data to be processed is divided into N second subsets, where N is a positive integer greater than or equal to 2;

[0010] The first subset of data is augmented to obtain the augmented dataset;

[0011] The relation extraction model trained based on the first subset and the augmented dataset is used to extract relations from the i-th second subset, and the extraction result of the i-th second subset is obtained, where i belongs to N;

[0012] If i is not equal to N, take i+1 as i, and write the i-th second subset and the extraction result of the i-th second subset into the first dataset, and return to execute the step of data augmentation on the first subset to obtain the augmented dataset;

[0013] If i equals N, the extraction results of each second subset are integrated to obtain the relationship of the data to be processed.

[0014] Optionally, the first subset of the dataset is augmented to obtain an augmented dataset, including:

[0015] Retrieve from the database a set of external relations whose relationship type similarity to the set of relationship types is higher than a preset threshold;

[0016] For each sentence in the first subset of data, the similarity type of the relationship between entity pairs in the sentence is determined based on the external relationship set;

[0017] A new sentence is constructed based on the entity pairs of the sentence, the set of relational information, and the sentence itself, wherein the set of relational information consists of the similarity types and the original relations of the sentence;

[0018] The augmented dataset is obtained by combining each new sentence in the first subset.

[0019] Optionally, the relation extraction model trained based on the first subset and the augmented dataset is used to extract relations from the i-th second subset, resulting in the extraction result of the i-th second subset, including:

[0020] Use the i-th second subset as the query set, and the first subset and the augmented dataset as the support set;

[0021] The query set and the support set are input into the relation extraction model trained based on the first subset dataset and the augmented dataset;

[0022] The relation extraction model represents each relation in the sentences in the support set and the sentences in the query set, respectively, to obtain the first sentence prototype representation of each relation in the support set and the second sentence prototype representation of each relation in the query set.

[0023] For each relation, processing is performed based on the support set, the first sentence prototype representation of the relation, and the number of sentences of the relation in the support set to determine the first relation prototype representation of the relation;

[0024] The relation extraction model processes the query set, the second sentence prototype representation of the relation, and the number of sentences of the relation in the query set to determine the second relation prototype representation of the relation.

[0025] The extraction result of the query set is determined based on the spatial similarity between the first relation prototype representation and the second relation prototype representation of each relation.

[0026] Optionally, the relation extraction model represents sentences in the support set and sentences in the query set according to each relation, obtaining a first sentence prototype representation of each relation in the support set and a second sentence prototype representation of each relation in the query set, including:

[0027] The sentence encoder of the relation extraction model is invoked to encode the sentences in the support set and the sentences in the query set respectively, to obtain the first text embedding representation of each sentence in the support set and the second text embedding representation of each sentence in the query set;

[0028] For each relation, the first text embedding representation and the second text embedding representation of all sentences corresponding to the relation are summed and averaged to obtain the first sentence prototype representation and the second sentence prototype representation corresponding to the relation.

[0029] Optionally, for each relation, processing is performed based on the support set, the first sentence prototype representation of the relation, and the number of sentences in the support set to determine the first relation prototype representation of the relation, including:

[0030] The entity prototype representation of the sentence is determined based on the first text embedding representation of the sentences in the support set;

[0031] For each relation, the first sentence prototype representation of the relation and the entity prototype representation of the support set are processed to obtain the first relation prototype representation of the relation.

[0032] Optionally, the extraction result of the statements in the query set is determined based on the spatial similarity between the first relation prototype representation and the second relation prototype representation of each relation, including:

[0033] Calculate the spatial similarity between the first and second prototype representations of each relation;

[0034] The spatial similarity scores will be sorted in descending order.

[0035] The relation corresponding to the spatial similarity ranked first is used as the extraction result of the query set statement.

[0036] A second aspect of the present invention discloses a sample relationship extraction device, the device comprising:

[0037] The acquisition unit is used to acquire the data to be processed and the first subset of data, wherein the first subset of data refers to the data that has been labeled with entity and relation types.

[0038] A data preparation unit is used to divide the data to be processed into N second subsets, where N is a positive integer greater than or equal to 2;

[0039] A data augmentation unit is used to augment the first subset of data to obtain an augmented dataset.

[0040] The relation extraction unit is used to extract relations from the i-th second subset based on the relation extraction model trained on the first subset and the augmented dataset, and to obtain the extraction result of the i-th second subset, where i belongs to N;

[0041] The judgment unit is used to determine if i is not equal to N, i+1 is taken as i, and the extraction result of the i-th second subset and the i-th second subset are written into the first dataset, and the step of performing data augmentation on the first subset to obtain the augmented dataset is returned.

[0042] The integration unit is used to integrate the extraction results of each second subset of data if i equals N, to obtain the relationship of the data to be processed.

[0043] Optional, data augmentation units, specifically used for:

[0044] Obtain a set of external relations from the database whose similarity to the relation type set is higher than a preset threshold; for each sentence in the first subset of data, determine the similarity type of the relationship between the entity pairs of the sentence based on the external relation set; construct a new sentence based on the entity pairs of the sentence, the relation information set, and the sentence, wherein the relation information set consists of the similarity type and the original relationship of the sentence; combine each new sentence in the first subset of data to obtain an enhanced dataset.

[0045] A third aspect of the present invention discloses an electronic device, the electronic device including a processor and a memory, the memory being used to store program code and data for sample relation extraction, and the processor being used to call program instructions in the memory to execute the sample relation extraction method as described in any of the first aspects of the present invention.

[0046] A fourth aspect of the present invention discloses a storage medium comprising a stored program, wherein, when the program is executed, the device on which the storage medium is located executes a sample relationship extraction method as shown in any of the first aspects of the present invention.

[0047] Based on the above embodiments of the present invention, a sample relation extraction method, apparatus, electronic device, and storage medium are provided. The method includes: acquiring data to be processed and a first subset, wherein the first subset refers to data that has been labeled with entity and relation types; dividing the data to be processed into N second subsets, wherein N is a positive integer greater than or equal to 2; performing data augmentation on the first subset to obtain an augmented dataset; performing relation extraction on the i-th second subset based on a relation extraction model trained on the first subset and the augmented dataset to obtain the extraction result of the i-th second subset, wherein i belongs to N; if i is not equal to N, taking i+1 as i, and writing the i-th second subset and the extraction result of the i-th second subset into the first dataset, and returning to execute the step of performing data augmentation on the first subset to obtain the augmented dataset; if i is equal to N, integrating the extraction results of each second subset to obtain the relation of the data to be processed. In this embodiment of the invention, for each stage, the relation extraction model trained with the first subset and the augmented dataset is used to extract relations from the i-th second subset, and the extraction results and the second subset of the stage are written into the first subset to increase the training data until all the second subsets are processed. This invention uses a small number of labeled samples to perform iterative processing to determine a well-trained relation extraction model, thereby improving the accuracy of relation extraction. Attached Figure Description

[0048] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on the provided drawings without creative effort.

[0049] Figure 1 This is a schematic flowchart illustrating a sample relationship extraction method according to an embodiment of the present invention;

[0050] Figure 2 This is a data augmentation flowchart illustrating an embodiment of the present invention;

[0051] Figure 3 This is a flowchart illustrating the process of obtaining the relationship prototype in an embodiment of the present invention;

[0052] Figure 4 This is a schematic diagram illustrating the processing of the relation extraction model in an embodiment of the present invention;

[0053] Figure 5 This is a schematic diagram illustrating the N-stage sample relationship extraction process in an embodiment of the present invention;

[0054] Figure 6 This is a schematic diagram of a sample relationship extraction device according to an embodiment of the present invention. Detailed Implementation

[0055] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.

[0056] The terms “first,” “second,” “third,” “fourth,” etc. (if present) in the specification, claims, and accompanying drawings of this application are used to distinguish similar objects and are not necessarily used to describe a particular order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments described herein can be implemented in a sequence other than that illustrated or described herein. Furthermore, the terms “comprising” and “having,” and any variations thereof, are intended to cover a non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.

[0057] It should be noted that the descriptions involving "first," "second," etc., in this invention are for descriptive purposes only and should not be construed as indicating or implying their relative importance or implicitly specifying the number of technical features indicated. Therefore, a feature defined with "first" or "second" may explicitly or implicitly include at least one of that feature. Furthermore, the technical solutions of the various embodiments can be combined with each other, but this must be based on the ability of those skilled in the art to implement them. If the combination of technical solutions is contradictory or impossible to implement, it should be considered that such a combination of technical solutions does not exist and is not within the scope of protection claimed by this invention.

[0058] In this application, the terms "comprising," "including," or any other variations thereof are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.

[0059] See Figure 1This is a flowchart illustrating a sample relationship extraction method according to an embodiment of the present invention. The method includes:

[0060] Step S101: Obtain the data to be processed and the first subset of data, wherein the first subset of data refers to the data that has been labeled with entity and relation types;

[0061] In the specific implementation step S101, the relationship type set is based on the relationship types appearing in the accounting domain knowledge graph and the relationship type combination appearing in the entity annotation process of the first subset; and this relationship type set is written into the first subset.

[0062] Next, obtain sample statements from the accounting and finance domain, i.e., the data to be processed.

[0063] Step S102: Divide the data to be processed into N second subsets, where N is a positive integer greater than or equal to 2.

[0064] In the specific implementation step S102, the data to be processed is divided into N second subsets.

[0065] It should be noted that each second subset includes a set of sentences without annotations and whose entity relationships are unknown.

[0066] Step S103: Perform data augmentation on the first subset of data to obtain the augmented dataset;

[0067] It should be noted that the specific implementation of step S103 includes the following steps.

[0068] Step S11: Obtain from the database a set of external relations whose relation type similarity to the relation type set is higher than a preset threshold;

[0069] It should be noted that databases include those using the internet or knowledge bases, etc.

[0070] In the specific implementation step S11, the database is first traversed to determine the set of relation types. Relationships with similarity levels exceeding a preset threshold are then considered as external relationship sets. .

[0071] It should be noted that the preset threshold is set by technicians based on multiple experiments, and can generally be set to 95%.

[0072] Step S12: For each sentence in the first subset of data, determine the similarity type of the relationship between entity pairs in the sentence based on the external relationship set;

[0073] In the specific implementation step S12, for each sentence in the first subset S... , obtain the sentence Head entity Tail-end entity Then, the similarity type corresponding to the relationship between the entity pairs is queried in the external relationship set.

[0074] Step S13: Construct a new sentence based on the entity pairs of the sentence, the set of relational information, and the sentence itself. The set of relational information consists of the similarity types and the original relations of the sentence.

[0075] In the specific implementation step S13, the similar types and the sentences are... Relationship types combined into sentences Relationship information set ; and from the sentence Relationship information set The relationship extracted from Then, the entity pair ( and ) and relationship The initial sentence is obtained by concatenating the following elements in the format "{head entity, [MASK], relation, [MASK], tail entity}". Finally, the initial sentence... and sentences Merging yields a new sentence .

[0076] It should be noted that the new sentence The quantity T and the set of external relations The quantity M satisfies the relationship M+1=T.

[0077] It should also be noted that adding the "[MASK]" tag between entity and relation information replaces other words in the sentence besides entity and relation information, making the new sentence "appear" to be a complete sentence obtained by masking some words with "[MASK]". At the same time, to ensure the new sentence has a high information content, only one "[MASK]" is used to mask other words between entity and relation information.

[0078] Step S14: Combine each new sentence in the first subset of the dataset to obtain the augmented dataset.

[0079] In the specific implementation step S14, each new sentence in the first subset of the dataset is integrated to obtain the augmented dataset. .

[0080] It should be noted that the specific implementation of steps S11 to S14 can be achieved through methods such as... Figure 2 The architecture shown is explained.

[0081] Step S104: Based on the relation extraction model trained on the first subset and the augmented dataset, perform relation extraction on the i-th second subset to obtain the extraction result;

[0082] Where i belongs to N.

[0083] In the process of training the relation extraction model, the size of the partition N and K is first set, with common ratios such as (5,1), (5,5), (10,1), (10,5), etc. The specific values ​​are determined by the number of relations and sentences in the sample set. Based on the size of N and K, N types of relations are extracted from the sample set, with K sentences for each type of relation. These relations and sentences are used as training data in one round of training, i.e., the support set.

[0084] Several statements are randomly selected from the first subset of the dataset as the statements for relation extraction in the same round of training, which are then used as the query set.

[0085] It should be noted that the process of training the relation extraction model based on the first subset and the augmented dataset includes:

[0086] During training, the relation prototype representations of the support set relations and the query set statements are calculated. Next, the spatial similarity between the relation prototype representations of the support set and the query set is calculated to extract relations from the query set statements. Then, the cross-entropy loss function is used as the loss function during training. Finally, after M rounds of training, a prototype relation extraction model that can be used for relation extraction is obtained, i.e., the relation extraction model trained based on the first subset and the augmented dataset.

[0087] M was set based on multiple experiments.

[0088] It should be noted that the specific implementation of step S104 includes the following steps:

[0089] Step S21: Use the i-th second subset as the query set, and the first subset and the augmented dataset as the support set;

[0090] Step S22: Input the query set and the support set into the relation extraction model trained based on the first subset and the augmented dataset;

[0091] Step S23: Perform representation processing on the sentences in the support set and the sentences in the query set according to each relation, to obtain the first sentence prototype representation of each relation in the support set and the second sentence prototype representation of each relation in the query set;

[0092] Here, "relation" refers to each relation in the relation information set, which is N set when training the model.

[0093] It should be noted that the specific implementation of step S23 includes the following steps:

[0094] Step S31: Invoke the sentence encoder of the relation extraction model to process the support set respectively. Sentences in The sentences in the query set are encoded to obtain a first text embedding representation of each sentence in the support set and a second text embedding representation of each sentence in the query set.

[0095] In the specific implementation step S31, for each sentence in the support set, the sentence encoder of the relation extraction model is invoked to encode each sentence, thereby obtaining the first text embedding representation of each sentence. .

[0096] Similarly, each sentence of the query set is encoded in the manner described above to obtain a second text embedding representation of each sentence of the query set.

[0097] It should be noted that the relation extraction model includes sentence encoders set according to different application scenarios and computer resources. In other words, different application scenarios and computer resources correspond to different sentence encoders.

[0098] Before executing step S31, select a suitable sentence encoder based on the current application scenario and computer resources, and then use the sentence encoder to execute step S31.

[0099] Step S32: For each relation Based on the relationship The first text embedding representation of all corresponding sentences and second text embedding representation The relationship is obtained by performing summation and averaging separately. The corresponding first sentence prototype representation and the prototype representation of the second sentence .

[0100] In the specific implementation step S32, for each relation, the relation type is searched from the support set. All corresponding sentences; then the relation The first text embedding representation of all corresponding sentences Substituting into formula (1) and performing calculations, we obtain the sentence prototype representation corresponding to the relationship. .

[0101] Formula (1):

[0102]

[0103] It should be noted that K refers to the total number of sentences corresponding to the relation, which is a fixed value, and k belongs to K. M refers to a multiple, which is the multiple by which data is augmented for the k-th sentence.

[0104] Optionally, if the sentence does not have data augmentation, its M is 1.

[0105] Similarly, each relation is calculated according to formula (1). The second text embedding representation of all corresponding sentences The relationship is obtained by performing summation and averaging. The corresponding second sentence prototype representation .

[0106] Step S24: For each relation, obtain the first relation prototype representation of the relation based on the support set, the first relation prototype representation of the relation, and the number of sentences K of the relation in the support set.

[0107] It should be noted that the specific implementation of step S24 includes the following steps:

[0108] Step S41: Determine the entity prototype representation of the sentence based on the first text embedding representation of the sentence in the support set.

[0109] In the specific implementation step S41, firstly, since the entity pair information of the sentence is known, it can be embedded from the first text representation of the sentence. The vector representations of the first word of the head and tail entities are directly extracted and concatenated to obtain the entity text embedding of the sentence. ; and the Simplified .

[0110] Then the relation type entity text embedding of all corresponding sentences Substituting into formula (2) and performing calculations, the relationship is obtained. entity prototype representation .

[0111] Formula (2):

[0112]

[0113] Because data augmentation methods are used, for consistent entity text embeddings, their corresponding entity information is consistent, so they can be directly embedded... Simplified .

[0114] Step S42: For each relation, based on the relation The first sentence prototype represents and the entity prototype representation of the support set. The process is performed to obtain the first relation prototype representation of the relationship. .

[0115] Specifically, the relationship The first sentence prototype represents and physical prototype representation Substituting into formula (3) and performing calculations, we obtain the first relation prototype representation of the relationship. .

[0116] Formula (3):

[0117]

[0118] Step S25: The relation extraction model processes the query set, the second sentence prototype representation of the relation, and the number of sentences of the relation in the query set to determine the second relation prototype representation of the relation;

[0119] It should be noted that the specific implementation of step S25 first involves determining the relationship according to the process described in step S41 above. entity prototype representation And it is represented as the second relation prototype of the relation, QP.

[0120] It should be noted that the specific implementation process of steps S21 to S25 is as follows: Figure 3 As shown.

[0121] Step S26: Determine the extraction result of the query set based on the spatial similarity between the first relation prototype representation and the second relation prototype representation of each relation.

[0122] It should be noted that the specific implementation of step S26 includes the following steps:

[0123] Step S51: Calculate the spatial similarity between the first relation prototype representation and the second relation prototype representation for each relation;

[0124] In the specific implementation of step S51, firstly, for each relation, its corresponding first relation prototype is represented. Second relation prototype representation Substituting into formula (4) and performing vector dot product, we obtain the spatial similarity corresponding to each relation. ;

[0125] Formula (4):

[0126]

[0127] It should be noted that D refers to the number of relations, which can also be represented as N, and d belongs to D.

[0128] Step S52: Sort the spatial similarities in descending order;

[0129] Step S53: Take the relationship corresponding to the spatial similarity ranked first as the extraction result of the query set statement.

[0130] In the specific implementation of steps S52 and S53, the spatial similarity corresponding to each relation is... The values ​​of the relation are determined and sorted in descending order of spatial similarity. The relation with the highest spatial similarity is then used as the result of the query set extraction.

[0131] Optionally, in order to enhance the ability of the present invention to distinguish similar relationships, the present invention adds a "None" relationship type as a similarity interference item. The calculation method corresponding to the relationship prototype of this type of relationship is shown in formula (5).

[0132]

[0133] It should be noted that N refers to the quantity corresponding to this relationship, which is a fixed value, and n belongs to N.

[0134] This perturbation item, as a prototype representation of a query set relation, participates in the model training process.

[0135] It should be noted that the specific implementation process of step S104 can be as follows: Figure 4 As shown.

[0136] Step S105: Determine whether i is equal to N. If not, proceed to step S106. If equal, proceed to step S107.

[0137] Step S106: Set i+1 as i, and write the i-th second subset and the extraction result of the i-th second subset into the first dataset, and return to execute step S103;

[0138] Step S107: Integrate the extraction results of each second subset of data to obtain the relationship of the data to be processed.

[0139] It should be noted that the specific process of implementing the above sample relationship extraction method can be as follows: Figure 5 As shown, there are a total of n stages, where n is the number of the second subset of data.

[0140] In stage 1, relation extraction model V1 is used to extract relations from the second subset of unlabeled data (i.e., when i=1), yielding the extraction results. The extraction results from the previous stage directly affect the next stage (except for the final stage n). Therefore, the extraction results from stage 1 will affect the data preparation unit of stage 2, because stage 1 has already performed relation extraction on some unlabeled data, which has now become labeled data. That is, the second subset of data from stage 1 and the corresponding extraction results are written into the first subset of data so that stage 2 and subsequent stages can continue until stage n. The basic process of each stage is roughly the same. In stage n, this invention performs relation extraction on the last part of the unlabeled data.

[0141] After each stage is completed, the relation extraction model is iterated; that is, in each stage, the relation extraction model is trained based on the first subset of data and the augmented dataset. Thus, this invention, using a small number of labeled samples, ultimately obtains a well-trained relation extraction model Vn and a large amount of labeled data. This relation extraction model can then be used as the backbone network for relation extraction from other data in the accounting field or for other relation extraction tasks.

[0142] In this embodiment of the invention, for each stage, the relation extraction model trained with the first subset and the augmented dataset is used to extract relations from the i-th second subset, and the extraction results and the second subset of the stage are written into the first subset to increase the training data until all the second subsets are processed. This invention uses a small number of labeled samples to perform iterative processing to determine the optimal relation extraction model and a large amount of labeled data, thereby improving the accuracy of relation extraction.

[0143] Based on the sample relationship extraction method shown in the above embodiments of the present invention, correspondingly, the present invention also shows a sample relationship extraction device, such as... Figure 6 As shown, the device includes:

[0144] The acquisition unit 601 is used to acquire the data to be processed and the first subset of data, wherein the first subset of data refers to the data that has been labeled with entity and relation types.

[0145] The data preparation unit 602 is used to divide the data to be processed into N second subsets, where N is a positive integer greater than or equal to 2;

[0146] Data augmentation unit 603 is used to augment the first subset of data to obtain an augmented dataset;

[0147] The relation extraction unit 604 is used to extract relations from the i-th second subset based on the relation extraction model trained on the first subset and the augmented dataset, and to obtain the extraction result of the i-th second subset, where i belongs to N;

[0148] The judgment unit 605 is used to determine if i is not equal to N, i+1 is taken as i, and the extraction result of the i-th second subset and the i-th second subset are written into the first dataset, and the process of performing data augmentation on the first subset to obtain the augmented dataset is returned.

[0149] Integration unit 606 is used to integrate the extraction results of each second subset of data if i equals N, to obtain the relationship of the data to be processed.

[0150] The specific principles and execution processes of each unit in the sample relationship extraction device disclosed in the above embodiments of the present invention are the same as the corresponding contents in the sample relationship extraction method provided in the above embodiments of the present invention. Please refer to the corresponding parts in the sample relationship extraction method disclosed in the above embodiments of the present invention, and they will not be repeated here.

[0151] In this embodiment of the invention, for each stage, the relation extraction model trained with the first subset and the augmented dataset is used to extract relations from the i-th second subset, and the extraction results and the second subset of the stage are written into the first subset to increase the training data until all the second subsets are processed. This invention uses a small number of labeled samples to perform iterative processing to determine the optimal relation extraction model and a large amount of labeled data, thereby improving the accuracy of relation extraction.

[0152] Optionally, based on the sample relationship extraction device shown in the embodiments of the present invention, the data augmentation unit 603 is specifically used for:

[0153] Obtain a set of external relations from the database whose similarity to the relation type set is higher than a preset threshold; for each sentence in the first subset of data, determine the similarity type of the relationship between the entity pairs of the sentence based on the external relation set; construct a new sentence based on the entity pairs of the sentence, the relation information set, and the sentence, wherein the relation information set consists of the similarity type and the original relationship of the sentence; combine each new sentence in the first subset of data to obtain an enhanced dataset.

[0154] Optionally, based on the sample relationship extraction device shown in the embodiments of the present invention, the relationship extraction unit 604 is specifically used for:

[0155] Use the i-th second subset as the query set, and the first subset and the augmented dataset as the support set;

[0156] The query set and the support set are input into the relation extraction model trained based on the first subset dataset and the augmented dataset;

[0157] The relation extraction model represents each relation in the sentences in the support set and the sentences in the query set, respectively, to obtain the first sentence prototype representation of each relation in the support set and the second sentence prototype representation of each relation in the query set.

[0158] For each relation, processing is performed based on the support set, the first sentence prototype representation of the relation, and the number of sentences of the relation in the support set to determine the first relation prototype representation of the relation;

[0159] The relation extraction model processes the query set, the second sentence prototype representation of the relation, and the number of sentences of the relation in the query set to determine the second relation prototype representation of the relation.

[0160] The extraction result of the query set is determined based on the spatial similarity between the first relation prototype representation and the second relation prototype representation of each relation.

[0161] Optionally, based on the sample relation extraction device shown in the embodiments of the present invention, the relation extraction model performs representation processing on sentences in the support set and sentences in the query set according to each relation, respectively, to obtain a relation extraction unit 604 with a first sentence prototype representation of each relation in the support set and a second sentence prototype representation of each relation in the query set, specifically used for:

[0162] The sentence encoder of the relation extraction model is invoked to process the support set respectively. Sentences in The sentences in the query set are encoded to obtain a first text embedding representation of each sentence in the support set and a second text embedding representation of each sentence in the query set.

[0163] For each relation, based on the relation The first and second text embedding representations of all corresponding sentences are summed and averaged to obtain the relationship. The corresponding prototype representations of the first and second sentences.

[0164] Optionally, based on the sample relation extraction device shown in the embodiments of the present invention, for each relation, processing is performed based on the support set, the first sentence prototype representation of the relation, and the number of sentences of the relation in the support set to determine the first relation prototype representation relation extraction unit 604, specifically used for:

[0165] The entity prototype representation of the sentence is determined based on the first text embedding representation of the sentences in the support set;

[0166] For each relation, the first sentence prototype representation of the relation and the entity prototype representation of the support set are processed to obtain the first relation prototype representation of the relation.

[0167] Optionally, based on the sample relation extraction device shown in the embodiments of the present invention, the relation extraction unit 604, which determines the extraction result of the query set based on the spatial similarity between the first relation prototype representation and the second relation prototype representation of each relation, is specifically used for:

[0168] Calculate the spatial similarity between the first and second prototype representations of each relation;

[0169] The spatial similarity scores will be sorted in descending order.

[0170] The relation corresponding to the spatial similarity ranked first is used as the extraction result of the query set statement.

[0171] This application provides an electronic device, which includes a processor and a memory. The memory is used to store sample relationship extraction program code and data, and the processor is used to call the program instructions in the memory to execute the steps shown in the sample relationship extraction method in the above embodiments.

[0172] This invention provides a storage medium, which includes the electronic device provided in the above-described embodiments of this application. The electronic device is used to execute the sample relationship extraction method disclosed in the embodiments of this application.

[0173] The various embodiments in this specification are described in a progressive manner. Similar or identical parts between embodiments can be referred to mutually. Each embodiment focuses on describing the differences from other embodiments. In particular, for system or system embodiments, since they are basically similar to method embodiments, the description is relatively simple, and relevant parts can be referred to the descriptions in the method embodiments. The systems and system embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs. Those skilled in the art can understand and implement this without creative effort.

[0174] Those skilled in the art will further recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of both. To clearly illustrate the interchangeability of hardware and software, the components and steps of the various examples have been generally described in terms of functionality in the foregoing description. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementations should not be considered beyond the scope of this invention.

[0175] The above description of the disclosed embodiments enables those skilled in the art to make or use the invention. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the invention. Therefore, the invention is not to be limited to the embodiments shown herein, but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.

Claims

1. A method for extracting sample relationships, characterized in that, The method includes: Obtain the data to be processed and the first subset of data, where the first subset of data refers to the data that has been labeled with entity and relation types; The data to be processed is divided into N second subsets, where N is a positive integer greater than or equal to 2; The first subset of data is augmented to obtain the augmented dataset; The relation extraction model trained based on the first subset and the augmented dataset is used to extract relations from the i-th second subset, and the extraction result of the i-th second subset is obtained, where i belongs to N; If i is not equal to N, take i+1 as i, and write the i-th second subset and the extraction result of the i-th second subset into the first dataset, and return to execute the step of data augmentation on the first subset to obtain the augmented dataset; If i equals N, the extraction results of each second subset are integrated to obtain the relationship of the data to be processed.

2. The method according to claim 1, characterized in that, The first subset of data is augmented to obtain the augmented dataset, which includes: Retrieve from the database a set of external relations whose relationship type similarity to the set of relationship types is higher than a preset threshold; For each sentence in the first subset of data, the similarity type of the relationship between entity pairs in the sentence is determined based on the external relationship set; A new sentence is constructed based on the entity pairs of the sentence, the set of relational information, and the sentence itself, wherein the set of relational information consists of the similarity types and the original relations of the sentence; The augmented dataset is obtained by combining each new sentence in the first subset.

3. The method according to claim 1, characterized in that, The relation extraction model trained based on the first subset and the augmented dataset is used to extract relations from the i-th second subset, resulting in the extraction result of the i-th second subset, including: Use the i-th second subset as the query set, and the first subset and the augmented dataset as the support set; The query set and the support set are input into the relation extraction model trained based on the first subset dataset and the augmented dataset; The relation extraction model represents each relation in the sentences in the support set and the sentences in the query set, respectively, to obtain the first sentence prototype representation of each relation in the support set and the second sentence prototype representation of each relation in the query set. For each relation, processing is performed based on the support set, the first sentence prototype representation of the relation, and the number of sentences of the relation in the support set to determine the first relation prototype representation of the relation; The relation extraction model processes the query set, the second sentence prototype representation of the relation, and the number of sentences of the relation in the query set to determine the second relation prototype representation of the relation. The extraction result of the query set is determined based on the spatial similarity between the first relation prototype representation and the second relation prototype representation of each relation.

4. The method according to claim 3, characterized in that, The relation extraction model represents sentences in the support set and sentences in the query set according to each relation, obtaining a first sentence prototype representation of each relation in the support set and a second sentence prototype representation of each relation in the query set, including: The sentence encoder of the relation extraction model is invoked to encode the sentences in the support set and the sentences in the query set respectively, to obtain the first text embedding representation of each sentence in the support set and the second text embedding representation of each sentence in the query set; For each relation, the first text embedding representation and the second text embedding representation of all sentences corresponding to the relation are summed and averaged to obtain the first sentence prototype representation and the second sentence prototype representation corresponding to the relation.

5. The method according to claim 3, characterized in that, For each relation, processing is performed based on the support set, the first sentence prototype representation of the relation, and the number of sentences in the support set to determine the first relation prototype representation of the relation, including: The entity prototype representation of the sentence is determined based on the first text embedding representation of the sentences in the support set; For each relation, the first sentence prototype representation of the relation and the entity prototype representation of the support set are processed to obtain the first relation prototype representation of the relation.

6. The method according to claim 3, characterized in that, The extraction result of the query set is determined based on the spatial similarity between the first relation prototype representation and the second relation prototype representation of each relation, including: Calculate the spatial similarity between the first and second prototype representations of each relation; The spatial similarity scores will be sorted in descending order. The relation corresponding to the spatial similarity ranked first is used as the extraction result of the query set statement.

7. A sample relationship extraction device, characterized in that, The device includes: The acquisition unit is used to acquire the data to be processed and the first subset of data, wherein the first subset of data refers to the data that has been labeled with entity and relation types. A data preparation unit is used to divide the data to be processed into N second subsets, where N is a positive integer greater than or equal to 2; A data augmentation unit is used to augment the first subset of data to obtain an augmented dataset. The relation extraction unit is used to extract relations from the i-th second subset based on the relation extraction model trained on the first subset and the augmented dataset, and to obtain the extraction result of the i-th second subset, where i belongs to N; The judgment unit is used to determine if i is not equal to N, i+1 is taken as i, and the extraction result of the i-th second subset and the i-th second subset are written into the first dataset, and the step of performing data augmentation on the first subset to obtain the augmented dataset is returned. The integration unit is used to integrate the extraction results of each second subset of data if i equals N, to obtain the relationship of the data to be processed.

8. The transpose according to claim 7, characterized in that, The data augmentation unit is specifically used for: Obtain a set of external relations from the database whose relationship type similarity to the set of relationship types is higher than a preset threshold; for each sentence in the first subset of data, determine the similarity type of the relationship between entity pairs in the sentence based on the set of external relations; Based on the entity pairs and relation information set of the sentence, a new sentence is constructed, wherein the relation information set consists of the similarity type and the original relation of the sentence; each new sentence in the first subset is combined to obtain an augmented dataset.

9. An electronic device, characterized in that, The electronic device includes a processor and a memory, the memory being used to store program code and data for sample relationship extraction, and the processor being used to call program instructions in the memory to execute the sample relationship extraction method as described in any one of claims 1-6.

10. A storage medium, characterized in that, The storage medium includes a stored program, wherein, when the program is executed, it controls the device where the storage medium is located to perform the sample relationship extraction method as described in any one of claims 1-6.