An entity relationship extraction method in text and related device
By using a pre-trained entity relation extraction model and negative sampling techniques, the problem of entity relation extraction in scenarios with incomplete labeled data is solved, achieving efficient and low-cost entity relation extraction from text, which is suitable for low-resource scenarios such as financial events.
Patent Information
- Application Number
- CN202211479127.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-11-23
- Publication Date
- 2026-01-02
- Estimated Expiration
- 2042-11-23
AI Technical Summary
In scenarios where labeled data is incomplete, existing technologies struggle to achieve low-cost entity relation extraction from text, and template-based methods suffer from poor convenience and insufficient template coverage.
A pre-trained entity relation extraction model is used to encode text and perform graph computation through an encoder and graph network. The negative sampling results of multi-type label matrices are used as data labels to train the model, construct entity recognition, relation head and relation tail extraction results, and construct entity relation triples.
Even with incomplete labeled data, it improves the accuracy and completeness of entity relation extraction, saves labeling costs, avoids the problem of poor template portability, and is suitable for entity relation extraction in low-resource scenarios.
Smart Images

Figure CN115757736B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of information extraction in natural language understanding, and in particular to an entity relationship extraction method in a text and a related device. BACKGROUND
[0002] Relation Extraction (RE) is mainly aimed at unstructured text data, and is an information technology for extracting entities and their relationships from natural language text. Relation extraction is an important basis for information retrieval, intelligent question answering, intelligent dialogue and other artificial intelligence applications, and has been widely concerned by the industry. At present, the relation extraction technology generally extracts the possible relationships between entities after identifying the entities in the text. Specifically, it can be divided into: (1) template-based relation extraction method (2) supervised learning-based relation extraction method. The technical characteristics and corresponding disadvantages of different relation extraction methods are introduced as follows:
[0003] (1) Early entity relationship extraction methods are mostly based on template matching. This kind of method is based on linguistic knowledge, combined with the characteristics of corpus, and manually written templates by domain experts to match entities with specific relationships from text. In small-scale, limited-domain entity relationship extraction problems, the template-based method can achieve good results. However, when the data scale is large, manually constructing templates requires a lot of time from domain experts. In addition, the template-based relation extraction system has poor portability, and when facing another domain relation extraction problem, it needs to re-construct the template. Finally, due to the limited number of templates constructed manually, the template coverage is not enough, and the recall rate of the template-based relation extraction system is generally not high.
[0004] (2) The supervised learning-based relation extraction method converts relation extraction into a classification problem, and trains a supervised learning model for relation extraction on the basis of a large amount of labeled data. The general steps of using supervised learning method for relation extraction include: predefining the type of relationship; manually annotating data; designing the features required for relationship recognition, which are generally calculated according to the context of the sentence where the entity is located; selecting a classification model (such as support vector machine, neural network and naive Bayes, etc.), training the model based on the labeled data; evaluating the trained model. This method is based on a large amount of annotated corpus, and in vertical fields, especially in fields with strong professionalism such as finance, data annotation relies on business experts who have worked for many years, and annotation consumes a lot of human cost and time cost.
[0005] When the text structure of some professional fields needs to be relationally extracted, complete data labeling cannot be achieved due to the cost of labeling, and thus the second method described above cannot be adopted. The first method also has problems such as poor convenience of relation extraction, high labor cost, insufficient coverage of templates, and the like, and is not the preferred solution.
[0006] How to achieve entity relation extraction in text at low cost in the scenario where the labeled data is not complete has become a problem to be solved in the current field. SUMMARY
[0007] Based on the above problems, the present application provides a method for extracting entity relations in text and related devices, which aims to achieve effective extraction of entity relations in text at low cost in the scenario where the labeled data is not complete.
[0008] The embodiments of the present application disclose the following technical solutions:
[0009] The first aspect of the present application provides a method for extracting entity relations in text, which comprises:
[0010] An input data containing multiple texts is constructed using a text corpus, and the input data is used as the input of an entity relation extraction model; the multiple texts include unlabeled or missing labeled texts; the entity relation extraction model includes an encoder and a graph network;
[0011] The input data is encoded by the encoder, and the vector output by the encoder is graph calculated by the graph network, and the graph network outputs an entity recognition graph structure matrix, a first relation extraction graph structure matrix and a second relation extraction graph structure matrix;
[0012] The entity recognition graph structure matrix, the first relation extraction graph structure matrix and the second relation extraction graph structure matrix are used to decode the input data text by text, and the entity recognition result, the relation head extraction result and the relation tail extraction result of each text are obtained;
[0013] The entity relation triple extraction result of the corresponding text is constructed according to the entity recognition result, the relation head extraction result and the relation tail extraction result;
[0014] The entity relation extraction model is a model obtained by training the negative sampling results of the respective entity label matrix, the first relation label matrix and the second relation label matrix of the multiple texts as data labels, and the entity label matrix, the first relation label matrix and the second relation label matrix are three types of label matrices constructed based on the corresponding text and the relation library.
[0015] In an optional implementation manner, the target label matrix is one of an entity label matrix, a first relation label matrix and a second relation label matrix; the negative sampling on the target label matrix obtains a corresponding negative sampling result, which comprises:
[0016] A first random number matrix is generated for the target label matrix;
[0017] According to the annotated text position in the entity label matrix, the corresponding position in the first random number matrix is added by 1 to obtain a second random number matrix;
[0018] The position with a value greater than 1-w in the second random number matrix is recorded as 1, and the position with a value less than or equal to 1-w is recorded as 0 to obtain a third random number matrix; wherein w represents a sampling ratio;
[0019] The target label matrix is negatively sampled according to the third random number matrix to obtain a negative sampling result of the target label matrix.
[0020] In an optional implementation manner, in the training phase of the entity relation extraction model, the method further comprises:
[0021] A first loss is calculated according to the negative sampling result of the entity recognition graph structure matrix and the entity label matrix output by the graph network, a second loss is calculated according to the negative sampling result of the first relation extraction graph structure matrix and the first relation label matrix output by the graph network, and a third loss is calculated according to the negative sampling result of the second relation extraction graph structure matrix and the second relation label matrix output by the graph network;
[0022] A total loss is obtained according to the first loss, the second loss and the third loss;
[0023] The entity relation extraction model is optimized according to the total loss.
[0024] In an optional implementation manner, the target text is one of multiple texts; the entity label matrix, the first relation label matrix and the second relation label matrix corresponding to the target text are constructed, which specifically comprises:
[0025] An initial entity label matrix, an initial first relation label matrix and an initial second relation label matrix are constructed; each position in the initial entity label matrix, the initial first relation label matrix and the initial second relation label matrix is marked as 0;
[0026] The relation database is traversed to obtain that the relation between the first entity and the second entity in the entity pair is the kth relation; the kth relation is one of multiple relations in the relation database;
[0027] According to the existence and position of the entity pair in the target text, the initial entity label matrix, the initial first relationship label matrix and the initial second relationship label matrix are relabeled to obtain the entity label matrix, the first relationship label matrix and the second relationship label matrix corresponding to the target text.
[0028] In an optional implementation, according to the existence and position of the entity pair in the target text, the initial entity label matrix, the initial first relationship label matrix and the initial second relationship label matrix are relabeled to obtain the entity label matrix, the first relationship label matrix and the second relationship label matrix corresponding to the target text, and specifically comprising:
[0029] If one entity in the entity pair is located in the target text, the first character position and the last character position of the existing entity in the target text are positioned as the horizontal coordinate and the vertical coordinate, and the corresponding position in the initial entity label matrix is marked 1;
[0030] If both entities in the entity pair are located in the target text, the first character position of the first entity and the first character position of the second entity are respectively taken as the horizontal coordinate and the vertical coordinate, and the corresponding position of the kth relationship in the initial first relationship label matrix is marked 1; and the last character position of the first entity and the last character position of the second entity are respectively taken as the horizontal coordinate and the vertical coordinate, and the corresponding position of the kth relationship in the initial second relationship label matrix is marked 1;
[0031] When the traversal of the relationship library for the target text ends, the initial entity label matrix, the initial first relationship label matrix and the initial second relationship label matrix marked are taken as the entity label matrix, the first relationship label matrix and the second relationship label matrix corresponding to the target text respectively.
[0032] In an optional implementation, the vector output by the encoder is graph calculated by a graph network, and the graph network outputs an entity recognition graph structure matrix, a first relationship extraction graph structure matrix and a second relationship extraction graph structure matrix, and specifically comprising:
[0033] The first full connection layer, the second full connection layer and the third full connection layer of the graph network process the vector output by the encoder respectively to obtain a first processing matrix, a second processing matrix and a third processing matrix;
[0034] The last dimension of each matrix in the first processing matrix, the second processing matrix and the third processing matrix is split according to the odd bit and the even bit to obtain a first odd bit matrix and a first even bit matrix corresponding to the first processing matrix, a second odd bit matrix and a second even bit matrix corresponding to the second processing matrix, and a third odd bit matrix and a third even bit matrix corresponding to the third processing matrix;
[0035] The entity recognition graph structure matrix corresponding to the first processing matrix, the first relation extraction graph structure matrix corresponding to the second processing matrix, and the second relation extraction graph structure matrix corresponding to the third processing matrix are obtained by transposing one of the two matrices obtained by splitting the first processing matrix, the second processing matrix and the third processing matrix respectively and multiplying the other.
[0036] In an optional implementation, the entity recognition result, the relation head extraction result and the relation tail extraction result of each piece of text are obtained by decoding the input data piece by piece of text using the entity recognition graph structure matrix, the first relation extraction graph structure matrix and the second relation extraction graph structure matrix, specifically including:
[0037] The first decoding matrix corresponding to the target text is obtained by processing the dimension corresponding to the target text in the entity recognition graph structure matrix according to the first confidence threshold; and the entity recognition result of the target text is obtained by decoding the target text through the first decoding matrix.
[0038] The second decoding matrix corresponding to the target relation of the target text is obtained by processing the dimension of the target relation of the target text in the first relation extraction graph structure matrix according to the first confidence threshold; and the relation head extraction result of the target relation of the target text is obtained by decoding the target text through the second decoding matrix.
[0039] The third decoding matrix corresponding to the target relation of the target text is obtained by processing the dimension of the target relation of the target text in the second relation extraction graph structure matrix according to the first confidence threshold; and the relation tail extraction result of the target relation of the target text is obtained by decoding the target text through the third decoding matrix.
[0040] In an optional implementation, the processing according to the first confidence threshold specifically includes:
[0041] The position greater than the first confidence threshold is set to 1, and the position less than or equal to the first confidence threshold is set to 0.
[0042] In an optional implementation, the entity relation triple extraction result corresponding to the text is constructed according to the entity recognition result, the relation head extraction result and the relation tail extraction result, specifically including:
[0043] All entity information in the entity recognition result of the target text is locked;
[0044] The first entity and the second entity of the entity pair of the target relation in the target text are determined by traversing the relation head information and the relation tail information matched with the locked entity information in the relation head extraction result and the relation tail extraction result of the target relation of the target text.
[0045] The entity relation triple extraction result of the target text is constructed according to the first entity, the second entity and the target relation.
[0046] In an optional implementation, the method for extracting entity relationships in text further includes:
[0047] The entity relationship triple extraction result is filtered using the second confidence threshold, entity information involved in the entity relationship triple with a confidence higher than the second confidence threshold is added to the entity recognition dataset corresponding to the text, and the relationship in the entity pair involved in the entity relationship triple with a confidence higher than the second confidence threshold is added to the relationship extraction dataset corresponding to the text.
[0048] In an optional implementation, the method for extracting entity relationships in text further includes:
[0049] According to the initial annotation information of each piece of text in the text corpus, an entity recognition dataset and a relationship extraction dataset corresponding to each piece of text are constructed;
[0050] The entity recognition dataset and the relationship extraction dataset corresponding to each piece of text included in the input data are input into the entity relationship extraction model.
[0051] The second aspect of the application provides an entity relationship extraction device in text, the device includes:
[0052] An input data construction module is configured to construct input data containing multiple texts using a text corpus, and use the input data as the input of an entity relationship extraction model; the multiple texts include texts without annotation or with missing annotation; the entity relationship extraction model includes an encoder and a graph network;
[0053] A model processing module is configured to encode the input data through the encoder, and perform graph calculation on the vector output by the encoder through the graph network, and output an entity recognition graph structure matrix, a first relationship extraction graph structure matrix, and a second relationship extraction graph structure matrix from the graph network;
[0054] A decoding module is configured to decode the input data piece by piece using the entity recognition graph structure matrix, the first relationship extraction graph structure matrix, and the second relationship extraction graph structure matrix, and obtain the entity recognition result, the relationship head extraction result, and the relationship tail extraction result of each piece of text;
[0055] A triple construction module is configured to be input by the input data construction module, and is configured to construct an entity relationship triple extraction result of the corresponding text according to the entity recognition result, the relationship head extraction result, and the relationship tail extraction result;
[0056] The entity relation extraction model is a model trained by taking the negative sampling results of the entity label matrix, the first relation label matrix and the second relation label matrix corresponding to each piece of text as data labels. The entity label matrix, the first relation label matrix and the second relation label matrix are three types of label matrices constructed based on the corresponding text and the relation library.
[0057] Compared with the prior art, the present application has the following beneficial effects:
[0058] In the embodiment of the present application, a pre-trained entity relation extraction model is used to extract the entity relations of each piece of text in the text corpus. By using the negative sampling results of multiple types of label matrices as data labels to train the model, compared with directly using the label matrix of the text corpus with unannotated or missing annotation as the training target, the influence of the missing annotation data on the extraction effect of the model can be greatly filtered. Iterative training can make the model approach the accuracy effect of large-scale high-quality annotated corpus. The problem of difficult accurate and effective entity relation extraction in the scene of incomplete annotation data is solved. Even by executing the technical solution, the text corpus with incomplete annotation is gradually completed, avoiding a large amount of annotation work and saving the cost of entity relation extraction. In addition, since there is no need to manually construct templates, there is no problem of poor portability of relation templates, and there is no problem of insufficient coverage of templates. This method is very suitable for implementing entity (such as financial event elements) relation extraction in a low-resource scenario. BRIEF DESCRIPTION OF DRAWINGS
[0059] In order to more clearly illustrate the technical solutions in the embodiments of the present application or the prior art, the drawings needed to be used in the embodiments or the prior art description will be briefly introduced. Obviously, the drawings in the following description are only some embodiments of the present application, and other drawings can be obtained by those skilled in the art without creative labor.
[0060] Figure 1 A flowchart of an entity relation extraction method in a text provided by an embodiment of the present application;
[0061] Figure 2 A flowchart of training an entity relation extraction model provided by an embodiment of the present application;
[0062] Figure 3 A schematic diagram of an entity label matrix provided by an embodiment of the present application;
[0063] Figure 4 A schematic diagram of a first relation label matrix provided by an embodiment of the present application;
[0064] Figure 5A second relationship label matrix provided by an embodiment of the present application;
[0065] Figure 6 A provided by an embodiment of the present application Figure 4 A corresponding negative sampling effect diagram;
[0066] Figure 7 A provided by an embodiment of the present application is a diagram for training an entity relationship extraction model by negative sampling of a label matrix;
[0067] Figure 8 A structure diagram of an entity relationship extraction device provided by an embodiment of the present application. DETAILED DESCRIPTION
[0068] In some entity relationship extraction methods, a large amount of relatively complete labeled data is needed to train a model, and then the trained model is used for relationship extraction. However, in actual application, manual labeling of data requires a large amount of cost. In some fields of text, there are incomplete labeling situations, such as missing labeling or unlabeled text. According to the prior art, these texts need to be fully and relatively completely labeled to train an extraction model or perform relationship extraction. It can be seen that the prior art puts forward a relatively strict requirement for the completeness of the labeled data in the text. How to effectively extract the entity relationship in the text with low cost in the scene where the data is not complete enough is a big problem at present.
[0069] Therefore, the embodiment of the present application provides an entity relationship extraction method and related device in the text. By negative sampling of the label matrix in the training stage, the negative sampling result of the label matrix is used as the data label for training the entity relationship extraction model, so that the model can be continuously improved in the training, and finally approach the accuracy effect of the large-scale corpus trained by high-quality labeling. Therefore, even if there is an unlabeled or missing labeling situation in the input data for extracting the entity relationship, the model can finally extract the entity relationship with higher accuracy and completeness through the unique "leakage checking and gap filling" effect of the model.
[0070] In order to enable personnel in the technical field to better understand the present application, the technical solutions in the embodiments of the present application will be described clearly and completely below with reference to the drawings in the embodiments of the present application. Obviously, the described embodiments are only a part of the embodiments of the present application, not all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without creative labor are within the scope of protection of the present application.
[0071] Referring to Figure 1 The figure is a text entity relationship extraction method flowchart provided by an embodiment of the present application. As shown inFigure 1 The entity relationship extraction method in the text includes:
[0072] In S101, an input data containing multiple texts is constructed using a text corpus, and the input data is input into an entity relationship extraction model.
[0073] In the embodiments of the present application, a text corpus is prepared in advance. The text corpus contains multiple texts, which can be in the form of [text_1, text_2, text_3, …], where text_1, text_2, text_3, etc. are different texts in the text corpus. As an example, an article is used as a text corpus, from which multiple texts can be divided according to punctuation marks or paragraphs. In some possible implementations, the texts can also be divided from the text corpus according to a preset length.
[0074] It should be noted that in the technical solutions of the present application, a text corpus is used to construct input data for inputting into an entity relationship extraction model. The input data is represented as v_input, and its size is size = [b, L]. Where b represents the number of texts in the input data, b is an integer greater than 1, and L represents the length of a single text in the input data. Assuming that the lengths of the b texts are not the same, the length of the longest text can be set as L, and the remaining texts with a length less than L can be padded with 0, so that the lengths of the b texts can all meet the length requirement of L.
[0075] In the embodiments of the present application, the multiple texts contained in the input data include texts without annotation or missing annotation. That is, the input data has an incomplete annotation. For example, a text is: A company sues B company, C company sues D company. Among them, the relationship between A company and B company is a pre-annotated entity relationship, while the relationship between C company and D company is not annotated. Therefore, this text has a missing annotation problem.
[0076] In the embodiments of the present application, the entity relationship extraction model includes an encoder and a graph network. After the input data is constructed, it can be input into the entity relationship extraction model and wait for the encoding processing of the encoder. After the encoder is processed, the result after encoding is given to the graph network, and the graph network performs graph calculation. For details, see the steps and introduction of S102 below.
[0077] In S102, the input data is encoded by the encoder, and the vector output by the encoder is graph calculated by the graph network, and the graph network outputs an entity recognition graph structure matrix, a first relationship extraction graph structure matrix and a second relationship extraction graph structure matrix.
[0078] For the input data constructed in S101, first, the input data is vector encoded by an encoder. The vector output by the encoder is denoted as v_enc, and the dimension of the vector v_enc is expanded compared to the input data, and the size of the vector v_enc is size = [b, L, h], where b and L correspond to the input data, and h represents the vector dimension of the vector v_enc. h is an integer greater than 1. In actual applications, the encoder can be a structure of embedding+LSTM, or a structure of a language model such as Bert or GPT. The composition of the encoder is not limited here.
[0079] For the vector v_enc output by the encoder, the vector v_enc is further converted into a graph structure by a graph network graph. Specifically, the graph network can perform entity recognition and relation extraction based on the vector v_enc, respectively. An entity recognition graph structure matrix v_ner is obtained by entity recognition, and a first relation extraction graph structure matrix v_re0 and a second relation extraction graph structure matrix v_re1 are obtained by relation extraction. In an optional implementation, the above process specifically includes:
[0080] The first fully connected layer, the second fully connected layer, and the third fully connected layer of the graph network process the vector v_enc output by the encoder, respectively, to obtain a first processing matrix, a second processing matrix, and a third processing matrix. The weight of the first fully connected layer is [h, h*2], and the weight of the second fully connected layer and the third fully connected layer is [h, n*h*2]. The size of the vector v_enc is size = [b, L, h], and after being processed by the first fully connected layer, the size of the first processing matrix obtained is size = [b, L, h*2]; after being processed by the second fully connected layer, the size of the second processing matrix obtained is size = [b, L, n*h*2]; and after being processed by the third fully connected layer, the size of the third processing matrix obtained is size = [b, L, n*h*2].
[0081] It should be noted that n mentioned above represents the total number of relation categories in the relation library. The relation library is composed of entities and relations, and the form of the entities and relations in the relation library can be represented as {(first entity, second entity): XX relation}. For example, {(company A, company B): holding}, which means that company A and company B are in a holding relationship, and company A holds company B.
[0082] The last dimension of each of the first processing matrix, the second processing matrix and the third processing matrix is split into odd bits and even bits to obtain a first odd bit matrix and a first even bit matrix corresponding to the first processing matrix, a second odd bit matrix and a second even bit matrix corresponding to the second processing matrix, and a third odd bit matrix and a third even bit matrix corresponding to the third processing matrix. By multiplying the two matrices obtained by splitting the first processing matrix, the second processing matrix and the third processing matrix respectively after transposing one of them, an entity recognition graph structure matrix corresponding to the first processing matrix, a first relation extraction graph structure matrix corresponding to the second processing matrix, and a second relation extraction graph structure matrix corresponding to the third processing matrix are obtained.
[0083] wherein the first processing matrix is split into two matrices of size [b, L, h], and after dimension transposition, [b, L, h]*[b, L, h] = [b, L, L] is obtained, and the entity recognition graph structure matrix v_ner of size = [b, L, L] is obtained. The second processing matrix is split into two matrices of size [b, L, h, n], and after dimension transposition, [b, n, L, h]*[b, n, h, L] = [b, n, L, L] is obtained, and the first relation extraction graph structure matrix v_re0 of size = [b, n, L, L] is obtained. Similarly, the third processing matrix is split into two matrices of size [b, L, h, n], and after dimension transposition, [b, n, L, h]*[b, n, h, L] = [b, n, L, L] is obtained, and the second relation extraction graph structure matrix v_re1 of size = [b, n, L, L] is obtained.
[0084] wherein the processing matrix of size = [b, L, n*h*2] is split into two matrices of size [b, L, h, n], which can be expressed as (1) the matrix [b, L, n*h*2] is split into two [b, L, n*h], and then reshaped into [b, L, h, n] respectively; or (2) the matrix [b, L, n*h*2] is reshaped into [b, L, h, n*2], and then split into two [b, L, h, n].
[0085] Through the operation of this step, the conversion from one-dimensional text information to two-dimensional graph structure is realized. The position coordinates between graphs can solve the many-to-many problem, and greatly optimize the current relation decoding bottleneck. The decoding process will be introduced in detail in combination with the S103 step.
[0086] S103, using the entity recognition graph structure matrix, the first relation extraction graph structure matrix and the second relation extraction graph structure matrix to decode the input data piece by piece, to obtain the entity recognition result, the relation head extraction result and the relation tail extraction result of each piece of text.
[0087] It is mentioned above that the input data contains multiple texts. For each of the texts, the entity recognition graph structure matrix v_ner, the first relation extraction graph structure matrix v_re0 and the second relation extraction graph structure matrix v_re1 are respectively used to decode the text. Each text can obtain the entity recognition result decoded by the entity recognition graph structure matrix v_ner, the relation head extraction result decoded by the first relation extraction graph structure matrix v_re0 and the relation tail extraction result decoded by the second relation extraction graph structure matrix v_re1. In specific implementation, the entity recognition graph structure matrix v_ner is decoded in the dimension of [L, L], and the first relation extraction graph structure matrix v_re0 and the second relation extraction graph structure matrix v_re1 are both decoded in the dimension of [n, L, L]. Through the decoding operation, the data processed by the model is restored from the graph structure to the dimension of the text, so as to regress to the entity information and the entity relation type recognized in the text level expression that can be directly understood by people.
[0088] In an optional implementation of the present step, since the three graph structure matrices (v_ner, v_re0 and v_re1) used for text decoding may have probability values other than 0 and 1, such as 0.5, 0.7 and the like, in the positions of the matrices. Such values other than 0 and 1 may affect the decoding effect. Therefore, the graph structure matrix used for decoding the text can be processed according to a preset confidence threshold in the dimension corresponding to the target text (i.e. a text to be decoded), and the processed result is used to decode the text. Specifically, the following can be performed:
[0089] (1) The dimension corresponding to the target text in the entity recognition graph structure matrix v_ner is processed according to the first confidence threshold, to obtain a first decoding matrix corresponding to the target text. The target text is decoded by using the first decoding matrix, to obtain the entity recognition result of the target text.
[0090] (2) The dimension corresponding to the target relation of the target text in the first relation extraction graph structure matrix v_re0 is processed according to the first confidence threshold, to obtain a second decoding matrix corresponding to the target relation of the target text. The target text is decoded by using the second decoding matrix, to obtain the relation head extraction result of the target relation of the target text.
[0091] (3) The dimension corresponding to the target relation of the target text in the second relation extraction graph structure matrix v_re1 is processed according to the first confidence threshold, to obtain a third decoding matrix corresponding to the target relation of the target text. The target text is decoded by using the third decoding matrix, to obtain the relation tail extraction result of the target relation of the target text.
[0092] The above entity recognition result is for the entire target text, while the relation head extraction result and the relation tail extraction result are extraction results for a target relation in the target text. The target relation is only one of n relations that can occur in the target text. For other multiple relations, the relation head extraction result and the relation tail extraction result can be obtained through the execution of (2) and (3).
[0093] The above (1)-(3) can be executed in a certain order or can be processed in parallel. The execution order is not limited here.
[0094] In an optional implementation, the processing according to the first confidence threshold includes: setting a position greater than the first confidence threshold to 1, and setting a position less than or equal to the first confidence threshold to 0. Through the truncation processing of the confidence threshold on the numerical value, the decoding effect of the graph structure matrix used for decoding the text on the target text is improved, and the graph structure matrix is improved. As an example, the first confidence threshold can be set to 0.5. In addition, the first confidence threshold can also be valued in the interval (0, 1) according to actual needs, which is not limited here.
[0095] In S104, an entity relation triple extraction result of the corresponding text is constructed according to the entity recognition result, the relation head extraction result, and the relation tail extraction result.
[0096] The following describes an optional implementation of this step, taking a target text in multiple texts as an example, and introducing an implementation mode of how to obtain an entity relation triple extraction result based on the entity recognition result of the target text, the relation head extraction result of the target relation of the target text, and the relation tail extraction result of the target relation of the target text.
[0097] First, all entity information in the entity recognition result of the target text is locked. Then, the first entity and the second entity of the entity pair of the target relation in the target text are determined by traversing the relation head information and the relation tail information matched with the locked entity information in the relation head extraction result and the relation tail extraction result of the target relation of the target text. Finally, the entity relation triple extraction result of the target text is constructed according to the first entity, the second entity, and the target relation. For example, the entity recognition result includes: A company, B company, C company, and D company. The target relation is "investment". There is no "investment" relation between any two of the above four companies in the target text. If "C company" and "D company" appear in the relation head extraction result and the relation tail extraction result, respectively, it indicates that C company is the first entity with the investment relation in the target text, and D company is the second entity being invested. Therefore, the entity relation triple (C company, investment, D company) can be constructed. In this way, the entity relation extraction of various relations in each text can be realized, and the corresponding entity relation triple is obtained.
[0098] In the embodiments of the present application, the entity relation extraction model mentioned above is adopted. The entity relation extraction model is a model trained by taking the negative sampling results of the entity label matrix, the first relation label matrix and the second relation label matrix corresponding to each of the plurality of texts as data labels. The entity label matrix, the first relation label matrix and the second relation label matrix are three types of label matrices constructed based on the corresponding texts and the relation library. Since the text corpus contains unannotated or missing annotated texts for constructing the plurality of texts, the three types of label matrices may also have the characteristic of incomplete annotation due to unannotation or missing annotation. If the three types of label matrices are directly used as data labels for training, it is difficult to improve the entity relation extraction effect of the unannotated texts. Therefore, in the embodiments of the present application, the negative sampling results of the three types of label matrices are used as data labels to train the entity relation extraction model. By taking the negative sampling results of the three types of label matrices as data labels, the model can be approximated to the accuracy effect of large-scale corpus with high-quality annotation in several iterations of model training. The problem of difficult accurate and effective entity relation extraction in the scene of incomplete annotation data is solved.
[0099] Even by implementing the technical solution, the originally incomplete annotated text corpus is gradually annotated, avoiding a large amount of annotation work and saving the cost of entity relation extraction. In addition, since the template does not need to be manually constructed, there is no problem of poor portability of the relation template, and there is no problem of insufficient range of template coverage. This method is very suitable for implementing entity (such as financial event elements) relation extraction in a low-resource scene.
[0100] It is mentioned above that the negative sampling is performed on the three types of label matrices respectively, and the negative sampling results thereof are used as label data to train the model. The implementation of negative sampling is introduced below. Since the negative sampling is performed on the three types of label matrices, in order to avoid redundancy, the process of negative sampling of the target label matrix is introduced as an example. The target label matrix is one of the entity label matrix, the first relation label matrix and the second relation label matrix.
[0101] The negative sampling of the target label matrix obtains the corresponding negative sampling result, which includes:
[0102] First, a first random number matrix is generated for the target label matrix. Then, according to the annotated text positions in the entity label matrix, the corresponding positions in the first random number matrix are added by 1 to obtain a second random number matrix. Subsequently, the positions with a value greater than 1-w in the second random number matrix are recorded as 1, and the positions with a value less than or equal to 1-w are recorded as 0 to obtain a third random number matrix. Wherein, w represents the sampling ratio. For example, w takes a value of 0.2. Finally, the negative sampling of the target label matrix is performed according to the third random number matrix to obtain the negative sampling result of the target label matrix.
[0103] 1-w is a treatment threshold for the second random number matrix calculated according to the sampling ratio w in a uniform distribution. For the first random number matrix, where the annotated text position corresponds to the position in the matrix plus 1, the random number value at the corresponding position in the second random number matrix can be greater than 1. Thus, the value at these positions can remain 1 during the treatment of the second random number matrix and will not be set to 0. For the second random data frame, the positions where the value is greater than 1-w are sampled, and the positions where the value is less than or equal to 1-w are not sampled. Based on the third random number matrix, the target label matrix is negatively sampled, and the expected negative sampling effect can be achieved. According to the argument in the article “Rethinking Negative Sampling for Unlabeled Entity Problem in Named Entity Recognition”, when the sampling ratio is 20%, the probability of positive sample rejection is only 5%, and the accuracy is more than 95%, which meets the requirements of statistical hypothesis testing. In practical applications, the length of the text is usually more than 100 words, and the accuracy is more than 99%.
[0104] The above mentioned the construction method of the label data of the entity relation extraction model. The following describes the calculation method of the loss in the training phase of the entity relation extraction model.
[0105] In the training phase of the model, the output of the graph network includes the entity recognition graph structure matrix, the first relation extraction graph structure matrix, and the second relation extraction graph structure matrix. These outputs may not achieve the expected training effect, so the three are respectively compared with the negative sampling results of the three types of label matrices to obtain the corresponding loss.
[0106] Specifically, the first loss is calculated according to the negative sampling result of the entity recognition graph structure matrix and the entity label matrix output by the graph network, the second loss is calculated according to the negative sampling result of the first relation extraction graph structure matrix and the first relation label matrix output by the graph network, and the third loss is calculated according to the negative sampling result of the second relation extraction graph structure matrix and the second relation label matrix output by the graph network. The three losses respectively represent the differences between the entity recognition, the extraction of the correspondence of the two entity heads of the relation, and the correspondence of the two entity tails and the label data. By superimposing the three, a total loss can be obtained. That is, the total loss is obtained according to the first loss, the second loss and the third loss. In addition, in some other implementations, the first loss, the second loss and the third loss can also be respectively configured with corresponding weight values, and then weighted and summed to obtain the total loss. Therefore, the manner of obtaining the total loss in the embodiments of the present application is not limited. According to the total loss, the entity relation extraction model can be optimized in the process of each model iteration calculation. Specifically, the model can be updated in reverse based on the total loss, so as to optimize the model.
[0107] Figure 2 A flowchart for training an entity relation extraction model is provided in the embodiments of the present application, which is combined with Figure 2 The training process and optimization mode of the model can be easily understood.
[0108] In order to facilitate understanding of the obtaining manner of the three types of label matrices, the following will be described in combination with Figures 3 to 5 . Figure 3 A schematic diagram of an entity label matrix is shown in Figure 4 A schematic diagram of a first relation label matrix is shown in Figure 5 A schematic diagram of a second relation label matrix is shown in. The construction manner of the three types of label matrices corresponding to the target text is introduced taking a text example as the target text.
[0109] Specifically, first, an initial entity label matrix, an initial first relation label matrix and an initial second relation label matrix are constructed. Each position in the initial entity label matrix, the initial first relation label matrix and the initial second relation label matrix is marked as 0. As an example, the target text is: A company sues B company, C company sues D company.
[0110] The relation library is traversed to obtain the relation between the first entity and the second entity in the entity pair as the kth relation. Here, the kth relation is one of the multiple relations in the relation library. According to the existence and existence position of the entity pair in the target text, the initial entity label matrix, the initial first relation label matrix and the initial second relation label matrix are re-marked to obtain the entity label matrix, the first relation label matrix and the second relation label matrix corresponding to the target text. As an example, here, the first entity and the second entity can be A company and B company respectively.
[0111] In an optional implementation, the initial entity label matrix, the initial first relationship label matrix and the initial second relationship label matrix are re-labeled according to the existence and the existence position of the entity pair in the target text, to obtain the entity label matrix, the first relationship label matrix and the second relationship label matrix corresponding to the target text, and the specific process includes:
[0112] If one entity in the entity pair exists in the target text, the first character position and the last character position of the existing entity in the target text are located as the horizontal coordinate and the vertical coordinate, and the corresponding position in the initial entity label matrix is marked as 1. Referring to FIG. 6, the gray position m1 represents the marking effect of 1 in the entity label matrix of the entity “Company A” existing in the target text; and the gray position m2 represents the marking effect of 1 in the entity label matrix of the entity “Company B” existing in the target text. Figure 3
[0113] If both entities in the entity pair exist in the target text, the first character position of the first entity and the first character position of the second entity are located as the horizontal coordinate and the vertical coordinate, and the corresponding position of the kth relationship in the initial first relationship label matrix is marked as 1. And the last character position of the first entity and the last character position of the second entity are located as the horizontal coordinate and the vertical coordinate, and the corresponding position of the kth relationship in the initial second relationship label matrix is marked as 1. Figure 4 The displayed gray position m3 represents the marking effect of the two entities of the “lawsuit” relationship in the first relationship label matrix when both entities of the entity pair of “Company A” and “Company B” exist in the target text. Figure 5 The displayed gray position m4 represents the marking effect of the two entities of the “lawsuit” relationship in the second relationship label matrix when both entities of the entity pair of “Company A” and “Company B” exist in the target text.
[0114] The above only describes the marking method of the initial three types of label matrices with a first entity and a second entity and a kth relationship as an example. For other entities and relationships, the initial entity label matrix can be processed in this manner. When the traversal of the relationship library ends for the target text, the marked initial entity label matrix, the initial first relationship label matrix and the initial second relationship label matrix are respectively taken as the entity label matrix, the first relationship label matrix and the second relationship label matrix corresponding to the target text.
[0115] For the first relationship label matrix shown in FIG. 6, the negative sampling effect is shown in FIG. 7. Figure 4 As shown in FIG. 8, the first relationship label matrix of the target text is obtained by marking the initial first relationship label matrix according to the existence and the existence position of the entity pair in the target text. Figure 6 Figure 6 Figure 4 On the basis of the matrix, additional multiple gray positions are added to the matrix, and the additional multiple gray positions are used for optimizing the model, and all white positions are not used for optimizing the model. For the corresponding data in the white position which is not labeled, the data is not used as a reference for optimizing the model. For example Figure 6 In the example, the position corresponding to the first character of the C company and the first character of the D company is white, and the data in the position is not used to calculate the model loss and optimize the model effect.
[0116] In an optional implementation, the entity relationship extraction method in the text further includes:
[0117] According to the initial labeling information of each text in the text corpus, an entity recognition dataset and a relationship extraction dataset corresponding to each text are constructed. These datasets constructed based on the initial labeling information of the text can be input into the entity relationship extraction model to improve the completeness of the model input data.
[0118] In an optional implementation, through the technical solution of the present application, the knowledge base, including the entity recognition dataset and the entity relationship extraction dataset, can be iteratively updated. Since the model is trained based on the negative sampling result as the label data in the technical solution of the present application, the inferred entity relationship may be more than the original labeled entity relationship. In order to ensure the accuracy of entity relationship identification, a confidence threshold (second confidence threshold) can be configured, so that the data higher than the second confidence threshold is used as the real label to fill the entity recognition dataset and the entity relationship extraction dataset. Repeated execution of the training link and the second confidence threshold screening link can finally obtain an entity recognition dataset and an entity relationship extraction dataset close to complete labeling. And an entity relationship extraction model close to the one trained by the complete labeled text corpus is obtained.
[0119] In an optional implementation, the second confidence threshold is greater than or equal to the first confidence threshold. The second confidence threshold can also be valued in the interval (0, 1) according to actual needs, which is not limited here. As an example, the first confidence threshold can be set to 0.5, and the second confidence threshold can be set to 0.95.
[0120] The following describes an example implementation of screening the entity relationship triple extraction result by the second confidence threshold. Specifically, the entity information involved in the entity relationship triple extraction result with a confidence higher than the second confidence threshold is added to the entity recognition dataset of the corresponding text, and the relationship in the entity pair involved in the entity relationship triple extraction result with a confidence higher than the second confidence threshold is added to the relationship extraction dataset of the corresponding text.
[0121] Figure 7A schematic diagram for training an entity relation extraction model by negative sampling of a label matrix is provided for the embodiments of the present application. The embodiments of the present application are described in combination with Figure 7 The leftmost part shows the effect of negative sampling of the first relation label matrix for the original text with missing labels. The specific effect of negative sampling is shown in W1 (corresponding to the effect of negative sampling of the first relation label matrix). Figure 7 The middle part shows the effect of encoding and graph calculation of the input text by the entity relation extraction model. The output effect of the model is shown in W2 (corresponding to v_re0). W1 and W2 are mutually compared, and the network parameters in the model structure W3 are optimized based on the loss. Through multiple iterations, the extraction of the new relationship between C company and D company is finally realized. As shown in W2, compared with W1, one more relation between the first characters of the two entities represented by the gray position m5 is extracted.
[0122] Based on the entity relation extraction method provided in the foregoing embodiments, the present application also provides an entity relation extraction device in a text. Figure 8 A structural schematic diagram of an entity relation extraction device in a text is shown in FIG. 8. Figure 8 As shown in FIG. 8, the entity relation extraction device in a text includes:
[0123] An input data construction module 801 is configured to construct input data containing multiple texts by using a text corpus, and use the input data as the input of an entity relation extraction model. The multiple texts include texts without labels or with missing labels. The entity relation extraction model includes an encoder and a graph network.
[0124] A model processing module 802 is configured to encode the input data by using the encoder, and perform graph calculation on the vector output by the encoder by using the graph network, and output an entity recognition graph structure matrix, a first relation extraction graph structure matrix and a second relation extraction graph structure matrix by the graph network.
[0125] A decoding module 803 is configured to decode each text of the input data by using the entity recognition graph structure matrix, the first relation extraction graph structure matrix and the second relation extraction graph structure matrix, respectively, to obtain the entity recognition result, the relation head extraction result and the relation tail extraction result of each text.
[0126] A triple construction module 804 is configured to be connected to the input data construction module, and is configured to construct the entity relation triple extraction result of the corresponding text according to the entity recognition result, the relation head extraction result and the relation tail extraction result.
[0127] The entity relation extraction model is a model trained by taking the negative sampling results of the entity label matrix, the first relation label matrix and the second relation label matrix corresponding to each of the plurality of pieces of text as data labels. The entity label matrix, the first relation label matrix and the second relation label matrix are three types of label matrices constructed based on the corresponding text and a relation library.
[0128] In an optional implementation, the target label matrix is one of the entity label matrix, the first relation label matrix and the second relation label matrix; and the entity relation extraction apparatus further includes a negative sampling module configured to perform negative sampling on the target label matrix to obtain a corresponding negative sampling result.
[0129] The random number matrix construction unit is configured to generate a first random number matrix for the target label matrix.
[0130] The marking unit is configured to add 1 to a corresponding position in the first random number matrix according to a marked text position in the entity label matrix to obtain a second random number matrix.
[0131] The numerical value truncation unit is configured to mark a position with a value greater than 1-w in the second random number matrix as 1 and mark a position with a value less than or equal to 1-w as 0 to obtain a third random number matrix; wherein w represents a sampling ratio.
[0132] The negative sampling unit is configured to perform negative sampling on the target label matrix according to the third random number matrix to obtain a negative sampling result of the target label matrix.
[0133] In an optional implementation, the entity relation extraction apparatus further includes a model training module. The model training module is configured to, in a training phase of the entity relation extraction model, calculate a first loss according to the negative sampling result of the entity recognition graph structure matrix and the entity label matrix output by the graph network, calculate a second loss according to the negative sampling result of the first relation extraction graph structure matrix and the first relation label matrix output by the graph network, and calculate a third loss according to the negative sampling result of the second relation extraction graph structure matrix and the second relation label matrix output by the graph network; obtain a total loss according to the first loss, the second loss and the third loss; and optimize the entity relation extraction model according to the total loss.
[0134] In an optional implementation, the target text is one of the plurality of pieces of text; and the entity relation extraction apparatus further includes a label matrix construction module. The label matrix construction module is configured to construct the entity label matrix, the first relation label matrix and the second relation label matrix corresponding to the target text. The label matrix construction module specifically includes:
[0135] An initial label matrix construction unit is configured to construct an initial entity label matrix, an initial first relationship label matrix, and an initial second relationship label matrix; and each position in the initial entity label matrix, the initial first relationship label matrix, and the initial second relationship label matrix is marked as 0.
[0136] A relationship traversal unit is configured to traverse the relationship library to obtain a kth relationship between the first entity and the second entity in the entity pair; the kth relationship is one of the multiple relationships in the relationship library.
[0137] An initial label matrix re-marking unit is configured to perform re-marking processing on the initial entity label matrix, the initial first relationship label matrix, and the initial second relationship label matrix according to the existence and position of the entity pair in the target text to obtain an entity label matrix, a first relationship label matrix, and a second relationship label matrix corresponding to the target text.
[0138] In an optional implementation, the initial label matrix re-marking unit is specifically configured to:
[0139] If one entity in the entity pair exists in the target text, the first character position and the last character position of the existing entity in the target text are located as the horizontal coordinate and the vertical coordinate, and the corresponding position in the initial entity label matrix is marked as 1;
[0140] If both entities in the entity pair exist in the target text, the first character position of the first entity and the first character position of the second entity are located as the horizontal coordinate and the vertical coordinate, and the corresponding position of the kth relationship in the initial first relationship label matrix is marked as 1; and the last character position of the first entity and the last character position of the second entity are located as the horizontal coordinate and the vertical coordinate, and the corresponding position of the kth relationship in the initial second relationship label matrix is marked as 1.
[0141] When the traversal of the relationship library ends for the target text, the initial entity label matrix, the initial first relationship label matrix, and the initial second relationship label matrix that are marked are taken as the entity label matrix, the first relationship label matrix, and the second relationship label matrix corresponding to the target text, respectively.
[0142] In an optional implementation, the model processing module is specifically configured to:
[0143] The first full connection layer, the second full connection layer, and the third full connection layer of the graph network are configured to process the vector output by the encoder to obtain a first processing matrix, a second processing matrix, and a third processing matrix, respectively.
[0144] splitting the last dimension of each of the first processing matrix, the second processing matrix and the third processing matrix into odd bits and even bits, to obtain a first odd bit matrix and a first even bit matrix corresponding to the first processing matrix, a second odd bit matrix and a second even bit matrix corresponding to the second processing matrix, and a third odd bit matrix and a third even bit matrix corresponding to the third processing matrix;
[0145] The decoding module is configured to:
[0146] In an optional implementation manner, the decoding module is specifically configured to:
[0147] processing the dimension corresponding to the target text in the entity recognition graph structure matrix according to the first confidence threshold to obtain a first decoding matrix corresponding to the target text; and decoding the target text through the first decoding matrix to obtain an entity recognition result of the target text.
[0148] processing the dimension of the target relationship of the target text in the first relationship extraction graph structure matrix according to the first confidence threshold to obtain a second decoding matrix corresponding to the target relationship of the target text; and decoding the target text through the second decoding matrix to obtain a relationship head extraction result of the target relationship of the target text.
[0149] processing the dimension of the target relationship of the target text in the second relationship extraction graph structure matrix according to the first confidence threshold to obtain a third decoding matrix corresponding to the target relationship of the target text; and decoding the target text through the third decoding matrix to obtain a relationship tail extraction result of the target relationship of the target text.
[0150] In an optional implementation manner, the decoding module processes according to the first confidence threshold, and the processing is specifically:
[0151] The decoding module sets a position greater than the first confidence threshold to 1, and sets a position less than or equal to the first confidence threshold to 0.
[0152] In an optional implementation manner, the triple construction module is specifically configured to:
[0153] locking all entity information in the entity recognition result of the target text;
[0154] traversing relationship head information and relationship tail information matching the locked entity information in the relationship head extraction result and the relationship tail extraction result of the target relationship of the target text to determine a first entity and a second entity of an entity pair of the target relationship in the target text.
[0155] According to the first entity, the second entity and the target relationship, an entity relationship triple extraction result of the target text is constructed.
[0156] In an optional implementation, the entity relationship extraction device in the text further includes:
[0157] The data filling module is configured to filter the entity relationship triple extraction result by using the second confidence threshold, add entity information involved in an entity relationship triple with a confidence higher than the second confidence threshold to an entity recognition data set corresponding to the text, and add a relationship in an entity pair involved in the entity relationship triple with the confidence higher than the second confidence threshold to a relationship extraction data set corresponding to the text.
[0158] In an optional implementation, the entity relationship extraction device in the text further includes:
[0159] The initial data set construction module is configured to construct an entity recognition data set and a relationship extraction data set corresponding to each piece of text according to initial annotation information of each piece of text in the text corpus.
[0160] The data set input module is configured to input the entity recognition data set and the relationship extraction data set corresponding to each piece of text included in the input data to the entity relationship extraction model.
[0161] It should be noted that each of the embodiments in the present specification is described in a progressive manner, and the same parts between each embodiment can be understood by mutual reference. Each embodiment focuses on the difference from other embodiments. Especially, the device embodiment is described relatively simply because it is basically similar to the method embodiment, and the relevant parts can be understood by referring to the part of the method embodiment. The device embodiment described above is only illustrative, and the units described as separate components can be or can not be physically separated, and the components indicated as units can be or can not be physical units, that is, they can be located in one place or distributed on multiple network units. According to the actual needs, part or all of the modules can be selected to achieve the purpose of the embodiment scheme. Those skilled in the art can understand and implement it without creative labor.
[0162] The above describes only one specific embodiment of the present application, but the protection scope of the present application is not limited to this. Any skilled person in the art can easily think of changes or replacements within the technical range disclosed in the present application, which should be covered within the protection scope of the present application. Therefore, the protection scope of the present application should be subject to the protection scope of the claims.
Claims
1. An entity relation extraction method in text, characterized in that, The method comprises the following steps: constructing input data containing multiple texts by using a text corpus, and inputting the input data into an entity relation extraction model; the multiple texts include texts without annotation or with missing annotation; the entity relation extraction model comprises an encoder and a graph network; encoding the input data by using the encoder, and performing graph calculation on the vector output by the encoder by using the graph network, to output an entity recognition graph structure matrix, a first relation extraction graph structure matrix, and a second relation extraction graph structure matrix by using the graph network; decoding the input data by using the entity recognition graph structure matrix, the first relation extraction graph structure matrix, and the second relation extraction graph structure matrix respectively, to obtain an entity recognition result, a relation head extraction result, and a relation tail extraction result of each text; constructing an entity relation triple extraction result of the corresponding text according to the entity recognition result, the relation head extraction result, and the relation tail extraction result; the entity relation extraction model is a model trained by using negative sampling results of an entity label matrix, a first relation label matrix, and a second relation label matrix corresponding to the multiple texts respectively as data labels; the entity label matrix, the first relation label matrix, and the second relation label matrix are three types of label matrices constructed based on the corresponding texts and a relation library; a target label matrix is one of the entity label matrix, the first relation label matrix, and the second relation label matrix; performing negative sampling on the target label matrix to obtain a corresponding negative sampling result, comprising: generating a first random number matrix for the target label matrix; adding 1 to the corresponding position in the first random number matrix according to the annotated text position in the entity label matrix, to obtain a second random number matrix; recording 1 in the position with a value greater than 1-w in the second random number matrix, and recording 0 in the position with a value less than or equal to 1-w, to obtain a third random number matrix; wherein w represents a sampling ratio; performing negative sampling on the target label matrix according to the third random number matrix to obtain a negative sampling result of the target label matrix; a target text is one of the multiple texts; the entity label matrix, the first relation label matrix, and the second relation label matrix corresponding to the target text are constructed, specifically comprising: constructing an initial entity label matrix, an initial first relation label matrix, and an initial second relation label matrix; each position in the initial entity label matrix, the initial first relation label matrix, and the initial second relation label matrix is marked as 0; iterating through the relation library to obtain a kth relation between a first entity and a second entity in an entity pair; the kth relation is one of multiple relations in the relation library; re-marking the initial entity label matrix, the initial first relation label matrix, and the initial second relation label matrix according to the existence and position of the entity pair in the target text, to obtain an entity label matrix, a first relation label matrix, and a second relation label matrix corresponding to the target text. The initial entity label matrix, the initial first relationship label matrix and the initial second relationship label matrix are re-labeled according to the existence and the existence position of the entity pair in the target text, and the entity label matrix, the first relationship label matrix and the second relationship label matrix corresponding to the target text are obtained, and the re-labeling process specifically comprises: If one entity in the entity pair exists in the target text, the first character position and the last character position of the existing entity in the target text are located as the horizontal coordinate and the vertical coordinate, and the corresponding position in the initial entity label matrix is marked 1; If both entities in the entity pair exist in the target text, the first character position of the first entity and the first character position of the second entity are taken as the horizontal coordinate and the vertical coordinate respectively, and the corresponding position of the kth relationship in the initial first relationship label matrix is marked 1; and the last character position of the first entity and the last character position of the second entity are taken as the horizontal coordinate and the vertical coordinate respectively, and the corresponding position of the kth relationship in the initial second relationship label matrix is marked 1; When the traversal of the relationship library for the target text ends, the initial entity label matrix, the initial first relationship label matrix and the initial second relationship label matrix which are marked are taken as the entity label matrix, the first relationship label matrix and the second relationship label matrix corresponding to the target text respectively.
2. The method of claim 1, wherein, In the training phase of the entity relationship extraction model, the method further comprises: The first loss is calculated according to the negative sampling result of the entity recognition graph structure matrix and the entity label matrix output by the graph network, the second loss is calculated according to the negative sampling result of the first relationship extraction graph structure matrix and the first relationship label matrix output by the graph network, and the third loss is calculated according to the negative sampling result of the second relationship extraction graph structure matrix and the second relationship label matrix output by the graph network; The total loss is obtained according to the first loss, the second loss and the third loss; The entity relationship extraction model is optimized according to the total loss.
3. The method of claim 1, wherein, The graph network outputs the entity recognition graph structure matrix, the first relationship extraction graph structure matrix and the second relationship extraction graph structure matrix by performing graph calculation on the vector output by the encoder, and the graph calculation specifically comprises: The first full connection layer, the second full connection layer and the third full connection layer of the graph network process the vector output by the encoder respectively to obtain the first processing matrix, the second processing matrix and the third processing matrix; The last dimension of each matrix in the first processing matrix, the second processing matrix and the third processing matrix is split according to the odd bit and the even bit to obtain the first odd bit matrix and the first even bit matrix corresponding to the first processing matrix, the second odd bit matrix and the second even bit matrix corresponding to the second processing matrix, and the third odd bit matrix and the third even bit matrix corresponding to the third processing matrix; The entity recognition graph structure matrix corresponding to the first processing matrix, the first relationship extraction graph structure matrix corresponding to the second processing matrix and the second relationship extraction graph structure matrix corresponding to the third processing matrix are obtained by multiplying one transposed matrix with another matrix.
4. The method of claim 1, wherein, The input data is decoded by using the entity recognition graph structure matrix, the first relation extraction graph structure matrix and the second relation extraction graph structure matrix respectively, and the entity recognition result, the relation head extraction result and the relation tail extraction result of each text are obtained, and the decoding of each text is specifically as follows: The dimension corresponding to the target text in the entity recognition graph structure matrix is processed according to the first confidence threshold, and a first decoding matrix corresponding to the target text is obtained; the target text is decoded by using the first decoding matrix, and the entity recognition result of the target text is obtained; The dimension of the target relation of the target text in the first relation extraction graph structure matrix is processed according to the first confidence threshold, and a second decoding matrix corresponding to the target relation of the target text is obtained; the target text is decoded by using the second decoding matrix, and the relation head extraction result of the target relation of the target text is obtained; The dimension of the target relation of the target text in the second relation extraction graph structure matrix is processed according to the first confidence threshold, and a third decoding matrix corresponding to the target relation of the target text is obtained; the target text is decoded by using the third decoding matrix, and the relation tail extraction result of the target relation of the target text is obtained.
5. The method of claim 4, wherein, The processing according to the first confidence threshold specifically includes: The positions greater than the first confidence threshold are set to 1, and the positions less than or equal to the first confidence threshold are set to 0.
6. The method according to claim 4 or 5, characterized in that, According to the entity recognition result, the relation head extraction result and the relation tail extraction result, the entity relation triple extraction result of the corresponding text is constructed, and the decoding of each text is specifically as follows: Lock all entity information in the entity recognition result of the target text; The first entity and the second entity of the entity pair of the target relation in the target text are determined by traversing the relation head information and the relation tail information matched with the locked entity information in the relation head extraction result and the relation tail extraction result of the target relation of the target text; According to the first entity, the second entity and the target relation, the entity relation triple extraction result of the target text is constructed.
7. The method of claim 1, wherein, Further comprising: The entity relation triple extraction result is screened by using a second confidence threshold, and the entity information involved in the entity relation triple with a confidence higher than the second confidence threshold is added to the entity recognition data set of the corresponding text, and the relation in the entity pair involved in the entity relation triple with a confidence higher than the second confidence threshold is added to the relation extraction data set of the corresponding text.
8. The method of claim 1, wherein, Further comprising: According to the initial annotation information of each text in the text corpus, the entity recognition data set and the relation extraction data set corresponding to each text are constructed; The entity recognition data set and the relation extraction data set corresponding to each of the multiple texts included in the input data are input into the entity relation extraction model.
9. A device for extracting entity relations from text, characterized in that, Comprising: An input data construction module is configured to construct input data containing multiple texts by using a text corpus, and the input data is used as the input of an entity relation extraction model; the multiple texts include unannotated or missing annotated texts; The entity relation extraction model includes an encoder and a graph network; The model processing module is configured to encode the input data by using the encoder and perform graph calculation on a vector output by the encoder by using the graph network, and output an entity recognition graph structure matrix, a first relation extraction graph structure matrix, and a second relation extraction graph structure matrix by using the graph network; The decoding module is configured to decode each piece of text of the input data by using the entity recognition graph structure matrix, the first relation extraction graph structure matrix, and the second relation extraction graph structure matrix, respectively, to obtain an entity recognition result, a relation head extraction result, and a relation tail extraction result of each piece of text. The triple construction module is configured to input data construction module, and is configured to construct an entity relation triple extraction result of the corresponding text according to the entity recognition result, the relation head extraction result, and the relation tail extraction result. The entity relation extraction model is a model trained by using negative sampling results of the entity label matrix, the first relation label matrix, and the second relation label matrix corresponding to the plurality of pieces of text as data labels, wherein the entity label matrix, the first relation label matrix, and the second relation label matrix are three types of label matrices constructed based on the corresponding text and a relation library. The target label matrix is one of the entity label matrix, the first relation label matrix, and the second relation label matrix. The device further includes a negative sampling module configured to perform negative sampling on the target label matrix to obtain a corresponding negative sampling result, and the negative sampling module includes: A random number matrix construction unit is configured to generate a first random number matrix for the target label matrix. A labeling unit is configured to add 1 to a corresponding position in the first random number matrix according to a labeled text position in the entity label matrix to obtain a second random number matrix. A numerical truncation unit is configured to record a position with a value greater than 1-w as 1 and a position with a value less than or equal to 1-w as 0 in the second random number matrix to obtain a third random number matrix, wherein w represents a sampling ratio. A negative sampling unit is configured to perform negative sampling on the target label matrix according to the third random number matrix to obtain a negative sampling result of the target label matrix. The target text is one of the plurality of pieces of text, and the device further includes a label matrix construction module configured to construct an entity label matrix, a first relation label matrix, and a second relation label matrix corresponding to the target text, and the label matrix construction module specifically includes: An initial label matrix construction unit is configured to construct an initial entity label matrix, an initial first relation label matrix, and an initial second relation label matrix, and each position in the initial entity label matrix, the initial first relation label matrix, and the initial second relation label matrix is marked as 0. A relation traversal unit is configured to traverse a relation library to obtain a first entity and a second entity in an entity pair, and a relation between the first entity and the second entity is a kth relation, and the kth relation is one of a plurality of relations in the relation library. The initial label matrix re-labeling unit is configured to perform re-labeling processing on the initial entity label matrix, the initial first relationship label matrix, and the initial second relationship label matrix according to the existence and the existence position of the entity pair in the target text, to obtain an entity label matrix, a first relationship label matrix, and a second relationship label matrix corresponding to the target text. The initial label matrix re-labeling unit is specifically configured to: If one entity in the entity pair exists in the target text, the first character position and the last character position of the existing entity in the target text are located as the horizontal coordinate and the vertical coordinate, and 1 is marked in the corresponding position of the initial entity label matrix; If both entities in the entity pair exist in the target text, the first character position of the first entity and the first character position of the second entity are located as the horizontal coordinate and the vertical coordinate, respectively, and 1 is marked in the corresponding position of the kth relationship in the initial first relationship label matrix; and the last character position of the first entity and the last character position of the second entity are located as the horizontal coordinate and the vertical coordinate, respectively, and 1 is marked in the corresponding position of the kth relationship in the initial second relationship label matrix; When the traversal of the relationship library ends for the target text, the initial entity label matrix, the initial first relationship label matrix, and the initial second relationship label matrix that are marked are taken as the entity label matrix, the first relationship label matrix, and the second relationship label matrix corresponding to the target text, respectively.
Citation Information
Patent Citations
Representation learning method based on entity association constraints
CN108647258A
Single-stage joint entity relationship extraction method and system based on enhanced sequence labeling strategy
CN115310445A