Training methods, apparatus, and readable storage media for entity relation extraction models
By tabulating and annotating sample sentences, and using the BERT model and classifier for decoding, predictive triples are constructed and the model is trained. This solves the problems of propagation error and annotation complexity in entity relation extraction, and achieves higher accuracy and recall.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-10-24
- Publication Date
- 2026-04-07
AI Technical Summary
Existing entity relation extraction methods suffer from propagation errors and overly complex annotations.
By tabulating the sample sentences, filling in the annotations and extracting the label features, encoding them using the BERT model, decoding them using a classifier, constructing predicted triples, and training the pre-trained model using a loss function, we obtain the entity relationship extraction model.
It improves the accuracy and recall of entity relation extraction, showing a significant improvement compared to traditional methods.
Smart Images

Figure CN115757811B_ABST
Abstract
Description
Technical Field
[0001] This disclosure relates to the field of computer technology, and more specifically, to a training method, apparatus, and readable storage medium for an entity relation extraction model. Background Technology
[0002] Entity recognition and relation extraction, as important subtasks of information extraction, have attracted numerous scholars to conduct in-depth research in recent years using various technologies. Traditional entity-relation extraction is mostly based on the Pipeline method, which involves first identifying entities and then extracting the relationships between them. This means first identifying all entities in the text, and then iterating through and determining the relation categories of the identified entity pairs. This method suffers from the flaw of error propagation, meaning that errors in entity recognition can propagate to relation extraction. In recent years, with the application of deep learning, joint extraction methods have become mainstream in relation extraction tasks. These methods mainly use sequence labeling-based approaches to simultaneously train named entity recognition models and entity-relation classification models. While these methods address the error propagation problem of traditional methods to some extent, they still require separate labeling of entities and relations during the model labeling process, significantly increasing the workload. Summary of the Invention
[0003] The purpose of this disclosure is to provide a training method, apparatus, and readable storage medium for an entity relation extraction model, in order to solve the problems of propagation error and overly complex annotation in existing entity relation extraction methods.
[0004] According to a first aspect of the present disclosure, a training method for an entity relation extraction model is provided, comprising: acquiring a plurality of sample sentences; performing prediction triple extraction processing on each of the plurality of sample sentences to obtain prediction triples for the plurality of sample sentences; the prediction triple extraction processing comprising: filling labels into a table obtained after tabulating the sample sentences, and extracting label features of the sample sentences based on the labeled table; obtaining prediction triples for the sample sentences based on the label features; the prediction triples containing predicted entities of the sample sentences and relationships between entities; obtaining a loss function of a pre-trained model based on the prediction triples and actual triples of the plurality of sample sentences; and training the pre-trained model based on the loss function to obtain an entity relation extraction model.
[0005] Optionally, the step of filling the table obtained after tabulating the sample sentence with annotations and extracting the label features of the sample sentence based on the annotated table includes: arranging each character in the sample sentence horizontally and vertically to form a table; filling the table with annotations according to the entity attributes of the characters corresponding to each cell in the table to obtain the annotated table; and extracting the features of the annotated table to obtain the label features of the sample sentence.
[0006] Optionally, the step of filling in the annotations based on the entity attributes of the characters corresponding to each cell in the table to obtain the annotated table includes: when the subject of the triple formed by the horizontal and vertical corresponding characters of the cell is a multi-character subject, the first character of the cell is annotated as a first value; when the subject of the triple formed by the horizontal and vertical corresponding characters of the cell is a single-character subject, the first character of the cell is annotated as a second value; when the object of the triple formed by the horizontal and vertical corresponding characters of the cell is a multi-character object, the second character of the cell is annotated as a first value; when the object of the triple formed by the horizontal and vertical corresponding characters of the cell is a single-character object, the second character of the cell is annotated as a second value; and when the horizontal and vertical corresponding characters of the cell are the first characters of two entities respectively, the third character of the cell is annotated as a third value; and when the horizontal and vertical corresponding characters of the cell are the last characters of two entities respectively, the third character of the cell is annotated as a fourth value.
[0007] Optionally, the step of filling in the annotations according to the entity attributes of the characters corresponding to each cell in the table to obtain the annotated table further includes: when the subject and object of the triple formed by the horizontal and vertical characters corresponding to the cell are both single characters, the first and second characters of the cell are annotated as second values; when the horizontal and vertical characters corresponding to the cell do not have the above situation, the cell is annotated as fifth value, thus obtaining the annotated table.
[0008] Optionally, the step of extracting the features of the labeled table to obtain the label features of the sample sentence includes: encoding the labeled table using a BERT model to obtain the subject feature vector and object feature vector of the sample sentence; and performing feature fusion and feature extraction on the subject feature vector and the object feature vector to obtain the label features of the sample sentence.
[0009] Optionally, obtaining the predicted triples of the sample sentence based on the label features includes: predicting the relation category of the label features using a classifier; and decoding different relation categories to obtain the predicted triples.
[0010] Optionally, the step of decoding different relation categories to obtain the predicted triplet includes: when the third position of the label is a third value, decoding is performed using forward decoding to obtain a first triplet; forward decoding refers to searching and decoding a table in the intersection area of the row front region and column front region of the cell where the first and second positions of the label are both first values and the third position is a fourth value; when the third position of the label is the fourth value, decoding is performed using backward decoding to obtain a second triplet; backward decoding refers to searching and decoding a table in the intersection area of the row back region and column back region of the cell where the first and second positions of the label are both first values and the third position is a third value; when the first and second positions of the label are both second values, decoding is performed using direct decoding to obtain a third triplet; direct decoding refers to directly parsing the entity of the cell corresponding to the label; deduplicating the first triplet, the second triplet, and the third triplet to obtain the predicted triplet.
[0011] According to a second aspect of the present disclosure, an entity relation extraction method is provided, comprising: acquiring input text; extracting entity relations from the input text using an entity relation extraction model to obtain triples of the input text; wherein the entity relation extraction model is trained using the training method of the entity relation extraction model described in the first aspect of the present disclosure.
[0012] According to a third aspect of the present disclosure, a training apparatus for an entity relation extraction model is provided, comprising: a processing module, configured to acquire a plurality of sample sentences, and perform prediction triplet extraction processing on each of the plurality of sample sentences to obtain prediction triplets of the plurality of sample sentences, wherein the prediction triplet extraction processing includes: a labeling module, configured to fill labels on a table obtained after tabulating the sample sentences, and extract label features of the sample sentences based on the labeled table; a prediction module, configured to obtain prediction triplets of the sample sentences based on the label features; wherein the prediction triplets contain predicted entities of the sample sentences and relationships between entities; the processing module is further configured to obtain a loss function of a pre-trained model based on the prediction triplets and actual triplets of the plurality of sample sentences; and a training module, configured to train the pre-trained model based on the loss function to obtain an entity relation extraction model.
[0013] According to a fourth aspect of the present disclosure, an entity relation extraction apparatus is provided, comprising: an acquisition module for acquiring input text; and a relation extraction module for extracting entity relations from the input text using an entity relation extraction model to obtain triples of the input text; wherein the entity relation extraction model is trained using the training method for the entity relation extraction model as described in the first aspect.
[0014] According to a fifth aspect of the present disclosure, a non-transitory computer-readable storage medium is provided, on which a computer program is stored, which, when executed by a processor, implements the steps of the aforementioned training method for the entity relation extraction model and the entity relation extraction method.
[0015] According to a sixth aspect of the present disclosure, an electronic device is provided, comprising: a memory storing a computer program thereon; and a processor for executing the computer program in the memory to implement the steps of the aforementioned training method for an entity relation extraction model and the entity relation extraction method.
[0016] The technical solution provided by the embodiments of this disclosure can include the following beneficial effects: multiple sample sentences are acquired; for each sample sentence, a predicted triplet extraction process is performed to obtain predicted triplets for the multiple sample sentences. The predicted triplet extraction process includes: filling in annotations on the table obtained after tabulating the sample sentences; extracting label features of the sample sentences based on the annotated table; obtaining predicted triplets for the sample sentences based on the label features; the predicted triplets contain the predicted entities of the sample sentences and the relationships between entities; obtaining the loss function of the pre-trained model based on the predicted triplets and actual triplets of the multiple sample sentences; and training the pre-trained model based on the loss function to obtain an entity relation extraction model. By tabulating the sample sentences and filling in annotations on the obtained tables, the entity relation extraction model trained based on the annotated tables achieves higher accuracy and recall compared to traditional methods when extracting entity relations.
[0017] It should be understood that the above general description and the following detailed description are exemplary and explanatory only, and are not intended to limit this disclosure. Attached Figure Description
[0018] The accompanying drawings are provided to further illustrate the present disclosure and form part of the specification. They are used together with the following detailed description to explain the present disclosure, but do not constitute a limitation thereof. In the drawings:
[0019] Figure 1 This is a schematic diagram of the structure of a computer system illustrated in an exemplary embodiment of this disclosure.
[0020] Figure 2 This is a flowchart illustrating a training method for an entity relation extraction model, as shown in an exemplary embodiment of this disclosure.
[0021] Figure 3 This is a flowchart of a sub-step of step S22 as illustrated in an exemplary embodiment of this disclosure.
[0022] Figure 4This is a schematic diagram illustrating a table obtained after tabulating sample sentences according to an exemplary embodiment of this disclosure.
[0023] Figure 5 This is a schematic diagram of a table shown in an exemplary embodiment of this disclosure.
[0024] Figure 6 This is a flowchart illustrating an entity relationship extraction method according to an exemplary embodiment of this disclosure.
[0025] Figure 7 This is a block diagram of a training apparatus for an entity relationship extraction model, as illustrated in an exemplary embodiment of this disclosure.
[0026] Figure 8 This is a block diagram of an entity relationship extraction apparatus shown in an exemplary embodiment of this disclosure.
[0027] Figure 9 This is a block diagram illustrating an electronic device according to an exemplary embodiment of the present disclosure.
[0028] Figure 10 This is a block diagram illustrating another electronic device according to exemplary embodiments of this disclosure. Detailed Implementation
[0029] The specific embodiments of this disclosure will be described in detail below with reference to the accompanying drawings. It should be understood that the specific embodiments described herein are for illustration and explanation only and are not intended to limit this disclosure.
[0030] In the following description, when referring to the accompanying drawings, the same numbers in different drawings denote the same or similar elements unless otherwise indicated. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with this disclosure. Rather, they are merely examples of apparatuses and methods consistent with some aspects of this disclosure as detailed in the appended claims.
[0031] Figure 1 A schematic diagram of the structure of a computer system provided in an exemplary embodiment of the present disclosure is shown. The computer system includes a terminal 120 and a server 140.
[0032] Terminal 120 and server 140 are connected to each other via wired or wireless network.
[0033] Terminal 120 may include at least one of smartphones, laptops, desktop computers, tablets, smart speakers, and smart robots.
[0034] Terminal 120 includes a display; the display can be used to show the entity relation extraction results.
[0035] Terminal 120 includes a first memory and a first processor. The first memory stores a first program; the first program is invoked and executed by the first processor to implement the training method or entity relation extraction method of the entity relation extraction model provided in this disclosure. The first memory may include, but is not limited to, the following: Random Access Memory (RAM), Read Only Memory (ROM), Programmable Read-Only Memory (PROM), Erasable Programmable Read-Only Memory (EPROM), and Electrically Erasable Programmable Read-Only Memory (EEPROM).
[0036] The first processor can consist of one or more integrated circuit chips. Optionally, the first processor can be a general-purpose processor, such as a central processing unit (CPU) or a network processor (NP). For example, the entity relation extraction model in the terminal can be trained by the terminal; or, trained by the server and obtained by the terminal from the server.
[0037] Server 140 includes a second memory and a second processor. The second memory stores a second program, which is called by the second processor to implement the training method or entity relation extraction method of the entity relation extraction model provided in this disclosure. Optionally, the second memory may include, but is not limited to, the following: RAM, ROM, PROM, EPROM, and EEPROM. Optionally, the second processor may be a general-purpose processor, such as a CPU or NP.
[0038] The server can be a standalone physical server, a server cluster or distributed system composed of multiple physical servers, or a cloud server providing basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, CDN (Content Delivery Network), and big data and artificial intelligence platforms. The terminal can be a smartphone, tablet, laptop, desktop computer, smart speaker, smartwatch, etc., but is not limited to these. The terminal and server can be connected directly or indirectly through wired or wireless communication, and this disclosure does not impose any restrictions.
[0039] Existing entity relation extraction methods suffer from propagation errors and overly complex annotations. Therefore, this disclosure proposes an entity relation extraction method based on table filling. First, it describes how to train the entity relation extraction model; please refer to [link to relevant documentation]. Figure 2 , Figure 2 This is a flowchart illustrating a training method for an entity relation extraction model, as shown in an exemplary embodiment of this disclosure. The method is performed by a computer device, for example, by... Figure 1 The terminal or server in the computer system shown is used to execute the command. Figure 2 The training method for the entity relation extraction model shown includes the following steps:
[0040] In step S21, multiple sample sentences are obtained.
[0041] First, prepare multiple sample sentences. These sentences can be in Chinese or English. The triple representing the entity relationship in a sample sentence can be described as (subject, relation, object). For example, in the sample sentence "EdwardThomas and John are from New York City, USA," "Edward Thomas" and "John" are both subjects, and "New York," "New York City," and "USA" are all objects. The relation between the subjects and objects is "livein," and the subjects and objects together are called entities.
[0042] These sample sentences are used to train the entity relation extraction model in subsequent steps. First, for each sample sentence in the multiple sample sentences, the prediction triplet extraction process is performed to obtain the prediction triplet for each sample sentence in the multiple sample sentences. The prediction triplet extraction process is described in detail in the following steps S22-S23.
[0043] In step S22, the table obtained after tabulating the sample sentences is filled with annotations, and the label features of the sample sentences are extracted based on the annotated table.
[0044] In this step, each sample sentence is first tabulated, and labels are filled into each cell of the table. Finally, the label features of each sample sentence are extracted based on the labeled table. It should be noted that step S22 may also include sub-steps S221, S222, and S223. The specific methods for obtaining the label features will be described in detail in the sub-steps of step S22. Please refer to [link / reference]. Figure 3 , Figure 3 This is a flowchart of a sub-step of step S22 as illustrated in an exemplary embodiment of this disclosure.
[0045] In sub-step S221, each character in the sample sentence is arranged horizontally and vertically to form a table.
[0046] For example, in the English sample sentence "Edward Thomas and John are from New York City, USA.", each individual word can be represented as a character. For instance, "Thomas," "York," and "City" are each represented as a character, and punctuation marks are also represented as characters. Arranging each character in the sample sentence horizontally and vertically, we can form a structure like this: Figure 4 The table shown, Figure 4 This is a schematic diagram illustrating a table obtained after tabulating sample sentences according to an exemplary embodiment of this disclosure.
[0047] In sub-step S222, labels are filled in according to the entity attributes of the characters corresponding to each cell in the table to obtain the labeled table.
[0048] The labeled table is obtained by filling in the annotations according to the entity attributes of the characters corresponding to each cell in the table. That is, the annotations are filled in according to the entity attributes of the characters corresponding to each cell horizontally and vertically. Entity attributes include single-character subject, single-character object, multi-character subject, and multi-character object. For example, "John" is a single-character subject, "Edward Thomas" is a multi-character subject, "USA" is a single-character object, and "New York" and "New York City" are multi-character objects.
[0049] In one implementation, when the main body of the triplet formed by the horizontal and vertical corresponding characters of the grid is a multi-character main body, the first character of the grid is marked as the first value; when the main body of the triplet formed by the horizontal and vertical corresponding characters of the grid is a single-character main body, the first character of the grid is marked as the second value.
[0050] When the object of the triple formed by the horizontal and vertical corresponding characters of the grid is a multi-character object, the second position of the grid is marked as the first value; when the object of the triple formed by the horizontal and vertical corresponding characters of the grid is a single-character object, the second position of the grid is marked as the second value.
[0051] Furthermore, if the horizontal and vertical characters corresponding to the grid are the first characters of two entities respectively, the third character of the grid is labeled as the third value; if the horizontal and vertical characters corresponding to the grid are the last characters of two entities respectively, the third character of the grid is labeled as the fourth value.
[0052] When the subject and object of the triple formed by the horizontal and vertical corresponding characters of the grid are both single characters, the first and second characters of the grid are labeled as the second value.
[0053] If the characters corresponding to the horizontal and vertical sides of a grid do not fall under the above conditions, the grid is labeled with the fifth value, resulting in a labeled table.
[0054] For example, the first value mentioned above can be M, the second value can be S, the third value can be H, the fourth value can be T, and the fifth value can be N / A. The following example will illustrate this further:
[0055] Please see Figure 5 , Figure 5 This is a schematic diagram of a table shown in an exemplary embodiment of this disclosure.
[0056] Figure 5 In the example, grid 1 corresponds to the word "Edward" horizontally and "New" vertically. Therefore, the corresponding labels are filled in according to the entity attributes of "Edward" and "New" in the sample sentence. The triple formed by "Edward" and "New" is (Edward Thomas, live in, New York). "Edward" is a multi-word subject in the sample sentence, and "New" is a multi-word object in the sample sentence. "Edward" and "New" also meet the condition that they are the first words of two entities respectively. Therefore, the first label of grid 1 is M, the second label is M, and the third label is H. The label of grid 1 is MMH.
[0057] Figure 5 In the example, grid 2 corresponds to the word "Thomas" horizontally and "City" vertically. Therefore, the corresponding labels are filled in according to the entity attributes of "Thomas" and "City" in the sample sentence. The triple formed by "Thomas" and "City" is (Edward Thomas, live in, New York City). "Thomas" is a multi-word subject in the sample sentence, and "City" is a multi-word object in the sample sentence. Furthermore, "Thomas" and "City" also meet the condition that they are the last words of two entities. Therefore, the first label of grid 2 is M, the second label is M, and the third label is T. The label of grid 2 is MMT.
[0058] Figure 5The word corresponding to grid 3 horizontally is "John" and the word corresponding to grid 3 vertically is "USA". Therefore, the corresponding labels are filled according to the entity attributes of "John" and "USA" in the sample sentence. The triple formed by "John" and "USA" is (John, live in, USA). The subject and object of the triple formed by "John" and "USA" are both single words. Therefore, the first label of grid 3 is S, the second label is S, and the label of grid 3 is SS.
[0059] The other cells in the table are labeled in the same way as above, and will not be repeated here. When the characters corresponding to a cell horizontally or vertically do not fall into any of the above categories, the cell is labeled as N / A, thus obtaining the labeled table, using (w i ,w j ) represents the word pair in the i-th row and j-th column of the table, w i Represents the main word, w j Representing object words, (w i ,w j The corresponding set of grid-filling labels is {N / A, MMH, MMT, MSH, MST, SMH, SMT, SS}.
[0060] In sub-step S223, the features of the labeled table are extracted to obtain the label features of the sample sentences.
[0061] Extracting features from the labeled table yields the label features of the sample sentences. For example, the labeled table can be encoded using a BERT model. The labeled table is a string sequence of the labeled sample sentences, with annotations showing the relationships between each character in the string sequence, resulting in a representation vector H for the sample sentence. This representation vector H is then connected to two separate fully connected layers. One fully connected layer is used to obtain the main feature vector Hi for each sample sentence. s Another fully connected layer is used to obtain the object feature vector H for each sample sentence. o Main feature vector H s and object feature vector H o The representation methods include:
[0062] H s =W1H+b1
[0063] H o =W2H+b2
[0064] Where W1, W2, b1, and b2 are the learning parameters of the fully connected layer.
[0065] For a word pair, the main feature vector H s With the object feature vector H oHadamard product and fully connected layer operations are performed to fuse subject and object features. Then, a fully connected layer is used for feature extraction to obtain the label features of the sample sentence. The label features of the sample sentence can be represented in the following ways:
[0066]
[0067] Where r is the relation class, TF r (i,j) represents the label features of the sample sentences in the classifier under relation category r, ReLU() is the activation function, and H is the activation function. s,i H is the main feature vector of subject i. o,j Let j be the object feature vector. W represents the Hadamard product operation. r b r These are the learning parameters.
[0068] In step S23, the predicted triples of the sample sentences are obtained based on the label features.
[0069] After learning the label features of a sample sentence, the triples of the sample sentence are predicted based on its label features. These triples are called predicted triples. The predicted triples contain the entities of the predicted sample sentence and the relationships between the entities.
[0070] For example, a classifier can predict the relation category of label features; for instance, the relation of word pairs, such as 'table', can be obtained using a softmax function. r (i,j)=softmax(TF r (i,j)), where table' r (i,j) represents the relation category of the label features; then, different relation categories are decoded separately, that is, different labels are decoded separately to obtain the predicted triples. For example, the decoding method of different labels can be obtained through argmax(), table r =argmax(table' r (i,j)), where table r This is the decoding method.
[0071] Based on the different annotations, there are three different decoding methods: forward decoding, backward decoding, and direct decoding. These three decoding methods are described in detail below.
[0072] When the third digit of the label is the third value, forward decoding is used to decode and obtain the first triplet. Forward decoding means searching the intersection area of the row and column front areas of the cells for tables where the first and second digits of the label are both the first value, and the third digit is the fourth value. For example... Figure 5The third character of the label for cell 1 is H, meaning it ends with H. Therefore, a forward decoding method is used. The decoding occurs in the intersection of the row and column front regions of cell 1. Figure 5 Within the rectangular box 10 region, the table whose first and second characters of the label are both M and the third character is T is decoded. That is, the table corresponding to the label that starts with MM and ends with T is searched. The search results are (Edward Thomas, live in, New York) and (Edward Thomas, live in, New YorkCity). This search result is taken as the first triplet.
[0073] When the third digit of the annotation is the fourth value, backward decoding is used to decode and obtain the second triplet. Backward decoding refers to searching for tables in the intersection area of the row and column regions where the first and second digits of the annotation are both the first value and the third digit is the third value. For example... Figure 5 The third character of the label for cell 2 is "T", meaning it ends with "T". Therefore, a backward decoding method is used. The decoding location is in the intersection of the row and column regions following cell 2. Figure 5 Within the rectangular area 20, the table whose first and second characters of the label are both M and the third character is H is decoded. That is, the table corresponding to the label that starts with MM and ends with H is searched. The search result is (Edward Thomas, live in, New York City), and this search result is used as the second triplet.
[0074] When both the first and second bits of the label are the second value, direct decoding is used to obtain the third triplet; direct decoding refers to directly parsing the entity of the cell corresponding to the label; for example... Figure 5 The first and second SS characters of cell 3 are labeled. At this time, the direct decoding method is used to decode. The word pair corresponding to cell 3 is (John,USA), which is directly parsed to obtain the triple (John,live in,USA), which is used as the third triple.
[0075] The first, second, and third triplets are deduplicated to obtain the predicted triplets.
[0076] In step S24, the loss function of the pre-trained model is obtained based on the predicted triples and actual triples of multiple sample sentences.
[0077] The loss function of the pre-trained model is constructed based on the predicted triples and the actual triples. The loss function is used to train the pre-trained model in subsequent steps to obtain the entity relation extraction model.
[0078] In step S25, a pre-trained model is trained based on the loss function to obtain an entity relation extraction model.
[0079] The pre-trained model is trained using the loss function described above. When the difference between the entity relationship predicted by the pre-trained model and the actual entity relationship is less than a predetermined threshold, the training parameters of the pre-trained model at this time are retained as the entity relationship extraction model.
[0080] After training the entity relation extraction model using the aforementioned table-filling label method, the entity relation extraction model is then used to extract entity relations from the text. Please refer to [link to relevant documentation]. Figure 6 , Figure 6 This is a flowchart illustrating an entity relation extraction method according to an exemplary embodiment of this disclosure. The method is executed by a computer device, for example, by... Figure 1 The terminal or server in the computer system shown is used to execute the command. Figure 6 The entity relation extraction method shown includes the following steps:
[0081] In step S61, the input text is obtained.
[0082] Obtain the input text to be identified and feed it into the entity relationship extraction model for entity relationship extraction.
[0083] In step S62, entity relations are extracted from the input text using an entity relation extraction model to obtain triples of the input text.
[0084] The entity relation extraction model extracts entity relations from the input text, resulting in triples of the input text. For example, for the input text "Edward Thomas and John are from New York City, USA.", the entity relation extraction model can identify the following entity relations:
[0085] (Edward Thomas,live in,New York City)
[0086] (Edward Thomas,live in,New York)
[0087] (Edward Thomas, live in, USA)
[0088] (John lives in New York City)
[0089] (John, live in New York)
[0090] (John, live in, USA).
[0091] Practice has shown that the entity relation extraction method based on table-filled labels proposed in this disclosure achieves better results than the traditional Pipeline method and Ner+LSTM method on the dataset. The experimental results are as follows:
[0092] method accuracy Recall rate F1 Pipeline 84.9% 72.3% 78.1% Ner+LSTM 89.7% 89.5% 89.6% This method 93.3% 91.7% 92.5%
[0093] The Pipeline method involves first identifying entities and then extracting the relationships between them. Specifically, it first identifies all entities in the text and then iterates through the identified entity pairs to determine their relationship categories. Ner is a Named Entity Recognition Network, and LSTM is a Long Short-Term Memory Network. Experimental results show that the entity relationship extraction method proposed in this disclosure has higher accuracy and recall.
[0094] In summary, the training method for the entity relation extraction model provided in this disclosure includes acquiring multiple sample sentences, and for each sample sentence, performing prediction triple extraction processing to obtain prediction triples for multiple sample sentences. The prediction triple extraction processing includes: filling in annotations on the table obtained after tabulating the sample sentences, extracting label features of the sample sentences based on the annotated table, obtaining prediction triples for the sample sentences based on the label features, and the prediction triples containing the predicted entities and relationships between entities in the sample sentences; obtaining the loss function of the pre-trained model based on the prediction triples and actual triples of multiple sample sentences, and training the pre-trained model based on the loss function to obtain the entity relation extraction model. By tabulating the sample sentences and filling in annotations on the obtained tables, the entity relation extraction model trained based on the annotated tables achieves higher accuracy and recall compared to traditional methods when extracting entity relations.
[0095] Figure 7 This is a block diagram of a training apparatus for an entity relation extraction model illustrated in an exemplary embodiment of this disclosure. (Refer to...) Figure 7 The training device 20 for the entity relation extraction model includes a processing module 201, a labeling module 202, a prediction module 203, and a training module 204.
[0096] The processing module 201 is used to acquire multiple sample sentences, and for each of the multiple sample sentences, perform prediction triplet extraction processing to obtain prediction triplets for the multiple sample sentences. The prediction triplet extraction processing includes:
[0097] The annotation module 202 is used to fill in the annotations on the table obtained after tabulating the sample sentences, and to extract the label features of the sample sentences based on the annotated table;
[0098] The prediction module 203 is used to obtain the predicted triples of the sample sentence based on the label features; the predicted triples contain the entities of the predicted sample sentence and the relationships between the entities.
[0099] The processing module 201 is also used to obtain the loss function of the pre-trained model based on the predicted triples and actual triples of the multiple sample sentences;
[0100] The training module 204 is used to train the pre-trained model according to the loss function to obtain the entity relationship extraction model.
[0101] Optionally, the annotation module 202 is also used to arrange each character in the sample sentence horizontally and vertically to form a table;
[0102] The labeled table is obtained by filling in the annotations according to the entity attributes of the characters corresponding to each cell in the table;
[0103] The label features of the sample sentences are obtained by extracting the features of the labeled table.
[0104] Optionally, the annotation module 202 is further configured to annotate the first character of the grid as a first value when the main body of the triple formed by the horizontal and vertical corresponding characters of the grid is a multi-character main body; and to annotate the first character of the grid as a second value when the main body of the triple formed by the horizontal and vertical corresponding characters of the grid is a single-character main body.
[0105] If the object of the triple formed by the horizontal and vertical corresponding characters of the grid is a multi-character object, the second position of the grid is marked as the first value; if the object of the triple formed by the horizontal and vertical corresponding characters of the grid is a single-character object, the second position of the grid is marked as the second value.
[0106] Furthermore, if the horizontal and vertical characters corresponding to the grid are the first characters of two entities respectively, the third character of the grid is marked as the third value; if the horizontal and vertical characters corresponding to the grid are the last characters of two entities respectively, the third character of the grid is marked as the fourth value.
[0107] Optionally, the annotation module 202 is further used to annotate the first and second characters of the grid as a second value when the subject and object of the triple formed by the horizontal and vertical corresponding characters of the grid are both single characters.
[0108] If the characters corresponding to the horizontal and vertical directions of the grid do not fall under the above-mentioned conditions, the grid is marked with the fifth value, resulting in the marked table.
[0109] Optionally, the annotation module 202 is further used to encode the annotated table using the BERT model to obtain the subject feature vector and object feature vector of the sample sentence;
[0110] The subject feature vector and the object feature vector are fused and extracted to obtain the label features of the sample sentence.
[0111] Optionally, the prediction module 203 is also used to predict the relationship category of the label features using a classifier;
[0112] The predicted triples are obtained by decoding the different relation categories respectively.
[0113] Optionally, the prediction module 203 is further configured to decode the label by forward decoding when the third position of the label is the third value, to obtain the first triplet; the forward decoding refers to searching the intersection area of the row front area and the column front area of the cell for a table in which the first and second positions of the label are both the first value and the third position is the fourth value.
[0114] When the third position of the label is the fourth value, a backward decoding method is used to decode it to obtain the second triplet; the backward decoding means that in the intersection area of the row-after region and the column-after region of the cell, the table in which the first and second positions of the label are both the first value and the third position is the third value is searched for decoding.
[0115] When both the first and second bits of the label are the second value, a direct decoding method is used to decode and obtain the third triplet; the direct decoding refers to directly parsing the entity of the cell corresponding to the label.
[0116] The first triplet, the second triplet, and the third triplet are deduplicated to obtain the predicted triplet.
[0117] Figure 8 This is a block diagram of an entity relationship extraction apparatus illustrated in an exemplary embodiment of this disclosure. (Refer to...) Figure 8 The entity relationship extraction device 30 includes an acquisition module 301 and a relationship extraction module 302.
[0118] The acquisition module 301 is used to acquire the input text;
[0119] The relation extraction module 302 is used to extract entity relations from the input text using an entity relation extraction model to obtain triples of the input text; the entity relation extraction model is trained using the aforementioned entity relation extraction model training method.
[0120] Regarding the apparatus in the above embodiments, the specific manner in which each module performs its operation has been described in detail in the embodiments related to the method, and will not be elaborated upon here.
[0121] Figure 9 This is a block diagram illustrating an electronic device 400 according to an exemplary embodiment. Figure 9 As shown, the electronic device 400 may include a processor 401 and a memory 402. The electronic device 400 may also include one or more of a multimedia component 403, an input / output (I / O) interface 404, and a communication component 405.
[0122] The processor 401 controls the overall operation of the electronic device 400 to complete all or part of the steps in the training method or entity relation extraction method of the aforementioned entity relation extraction model. The memory 402 stores various types of data to support the operation of the electronic device 400. This data may include, for example, instructions for any application or method operating on the electronic device 400, and application-related data such as contact data, sent and received messages, images, audio, video, etc. The memory 402 can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as Static Random Access Memory (SRAM), Electrically Erasable Programmable Read-Only Memory (EEPROM), Erasable Programmable Read-Only Memory (EPROM), Programmable Read-Only Memory (PROM), Read-Only Memory (ROM), magnetic storage, flash memory, magnetic disk, or optical disk. Multimedia component 403 may include a screen and an audio component. The screen may be, for example, a touchscreen, and the audio component is used to output and / or input audio signals. For example, the audio component may include a microphone for receiving external audio signals. The received audio signals may be further stored in memory 402 or transmitted via communication component 405. The audio component also includes at least one speaker for outputting audio signals. I / O interface 404 provides an interface between processor 401 and other interface modules, such as a keyboard, mouse, buttons, etc. These buttons may be virtual or physical buttons. Communication component 405 is used for wired or wireless communication between the electronic device 400 and other devices. Wireless communication, such as Wi-Fi, Bluetooth, Near Field Communication (NFC), 2G, 3G, 4G, NB-IoT, eMTC, or other 5G technologies, or combinations thereof, is not limited here. Therefore, the corresponding communication component 405 may include: a Wi-Fi module, a Bluetooth module, an NFC module, etc.
[0123] In an exemplary embodiment, the electronic device 400 may be implemented by one or more application-specific integrated circuits (ASICs), digital signal processors (DSPs), digital signal processing devices (DSPDs), programmable logic devices (PLDs), field-programmable gate arrays (FPGAs), controllers, microcontrollers, microprocessors, or other electronic components to execute the training method or entity relation extraction method of the entity relation extraction model described above.
[0124] In another exemplary embodiment, a computer-readable storage medium including program instructions is also provided. When executed by a processor, these program instructions implement the steps of the above-described training method for the entity relation extraction model or the entity relation extraction method. For example, the computer-readable storage medium may be the memory 402 including the program instructions, which may be executed by the processor 401 of the electronic device 400 to complete the above-described training method for the entity relation extraction model or the entity relation extraction method.
[0125] Figure 10 This is a block diagram illustrating another electronic device 500 according to an exemplary embodiment. For example, electronic device 500 may be provided as a server. (Refer to...) Figure 10 The electronic device 500 includes a processor 522, which may be one or more, and a memory 532 for storing computer programs executable by the processor 522. The computer program stored in the memory 532 may include one or more modules, each corresponding to a set of instructions. Furthermore, the processor 522 may be configured to execute the computer program to perform the training method or entity relation extraction method of the entity relation extraction model described above.
[0126] Additionally, the electronic device 500 may also include a power supply component 526 and a communication component 550. The power supply component 526 can be configured to perform power management of the electronic device 500, and the communication component 550 can be configured to enable communication of the electronic device 500, such as wired or wireless communication. Furthermore, the electronic device 500 may also include an input / output (I / O) interface 558. The electronic device 500 can operate on an operating system stored in the memory 532.
[0127] In another exemplary embodiment, a computer-readable storage medium including program instructions is also provided. When executed by a processor, these program instructions implement the steps of the above-described training method for the entity relation extraction model or the entity relation extraction method. For example, the non-transitory computer-readable storage medium may be the memory 532 including the program instructions, which may be executed by the processor 522 of the electronic device 500 to complete the above-described training method for the entity relation extraction model or the entity relation extraction method.
[0128] In another exemplary embodiment, a computer program product is also provided, the computer program product comprising a computer program executable by a programmable device, the computer program having a code portion for performing the training method or entity relation extraction method of the above-described entity relation extraction model when executed by the programmable device.
[0129] The preferred embodiments of this disclosure have been described in detail above with reference to the accompanying drawings. However, this disclosure is not limited to the specific details of the above embodiments. Within the scope of the technical concept of this disclosure, various simple modifications can be made to the technical solutions of this disclosure, and these simple modifications all fall within the protection scope of this disclosure.
[0130] It should also be noted that the various specific technical features described in the above specific embodiments can be combined in any suitable manner without contradiction. In order to avoid unnecessary repetition, this disclosure will not describe the various possible combinations separately.
[0131] Furthermore, various different embodiments of this disclosure can be combined in any way, as long as they do not violate the spirit of this disclosure, they should also be regarded as the content disclosed in this disclosure.
Claims
1. A training method for an entity relation extraction model, characterized in that, include: Multiple sample sentences are obtained, and for each of the multiple sample sentences, a prediction triplet extraction process is performed to obtain the prediction triplets of the multiple sample sentences. The prediction triplet extraction process includes: The table obtained after tabulating the sample sentences is filled with annotations, and the label features of the sample sentences are extracted based on the annotated table; The predicted triples of the sample sentence are obtained based on the label features; the predicted triples contain the entities of the predicted sample sentence and the relationships between the entities. The loss function of the pre-trained model is obtained based on the predicted triples and actual triples of the multiple sample sentences. The entity relation extraction model is obtained by training the pre-trained model according to the loss function. The annotated table is obtained by arranging each character in the sample sentence horizontally and vertically; the annotated table is obtained through the following steps: When the main body of the triple formed by the horizontal and vertical corresponding characters of the grid in the table is a multi-character main body, the first character of the grid is marked as the first value; when the main body of the triple formed by the horizontal and vertical corresponding characters of the grid is a single-character main body, the first character of the grid is marked as the second value. If the object of the triple formed by the horizontal and vertical corresponding characters of the grid is a multi-character object, the second position of the grid is marked as the first value; if the object of the triple formed by the horizontal and vertical corresponding characters of the grid is a single-character object, the second position of the grid is marked as the second value. Furthermore, if the horizontal and vertical characters corresponding to the grid are the first characters of two entities respectively, the third character of the grid is marked as the third value; if the horizontal and vertical characters corresponding to the grid are the last characters of two entities respectively, the third character of the grid is marked as the fourth value.
2. The method according to claim 1, characterized in that, Based on the labeled table, the label features of the sample sentences are extracted, including: The label features of the sample sentences are obtained by extracting the features of the labeled table.
3. The method according to claim 1, characterized in that, The step of filling in the annotations based on the entity attributes of the characters corresponding to each cell in the table to obtain the annotated table also includes: When the subject and object of the triple formed by the horizontal and vertical corresponding characters of the grid are both single characters, the first and second characters of the grid are marked as the second value. If the characters corresponding to the horizontal and vertical directions of the grid do not fall under the above-mentioned conditions, the grid is marked with the fifth value, resulting in the marked table.
4. The method according to claim 2, characterized in that, The step of extracting features from the labeled table to obtain the label features of the sample sentences includes: The labeled table is encoded using the BERT model to obtain the subject feature vector and object feature vector of the sample sentence; The subject feature vector and the object feature vector are fused and extracted to obtain the label features of the sample sentence.
5. The method according to claim 1, characterized in that, The step of obtaining the predicted triples of the sample sentence based on the label features includes: Predict the relationship category of the label features using a classifier; The predicted triples are obtained by decoding the different relation categories respectively.
6. The method according to claim 5, characterized in that, The step of decoding different relation categories to obtain the predicted triples includes: When the third digit of the label is the third value, a forward decoding method is used to decode it to obtain the first triplet; the forward decoding means that in the intersection area of the row front area and the column front area of the cell, the table in which the first and second digits of the label are both the first value and the third digit is the fourth value is searched for decoding. When the third position of the label is the fourth value, a backward decoding method is used to decode it to obtain the second triplet; the backward decoding means that in the intersection area of the row-after region and the column-after region of the cell, the table in which the first and second positions of the label are both the first value and the third position is the third value is searched for decoding. When both the first and second bits of the label are the second value, a direct decoding method is used to decode and obtain the third triplet; the direct decoding refers to directly parsing the entity of the cell corresponding to the label. The first triplet, the second triplet, and the third triplet are deduplicated to obtain the predicted triplet.
7. A method for extracting entity relations, characterized in that, include: Get the input text; The input text is subjected to entity relation extraction model to extract the triples of the input text. The entity relationship extraction model is obtained by training the method as described in any one of claims 1 to 6.
8. A training device for an entity relation extraction model, characterized in that, include: The processing module is used to acquire multiple sample sentences, and for each of the multiple sample sentences, perform prediction triplet extraction processing to obtain prediction triplets for the multiple sample sentences. The prediction triplet extraction processing includes: The annotation module is used to fill in annotations on the table obtained after tabulating the sample sentences, and to extract the label features of the sample sentences based on the annotated table; The prediction module is used to obtain the predicted triples of the sample sentence based on the label features; the predicted triples contain the entities of the predicted sample sentence and the relationships between the entities. The processing module is also used to obtain the loss function of the pre-trained model based on the predicted triples and actual triples of the multiple sample sentences; The training module is used to train the pre-trained model according to the loss function to obtain the entity relation extraction model; wherein, the labeled table is obtained by arranging each character in the sample sentence horizontally and vertically respectively; the labeling module is also used to label the first character of the cell as a first value when the main body of the triple formed by the horizontal and vertical corresponding characters of the cell in the table is a multi-character main body; and to label the first character of the cell as a second value when the main body of the triple formed by the horizontal and vertical corresponding characters of the cell in the table is a single-character main body; and to label the first character of the cell as a second value when the main body of the triple formed by the horizontal and vertical corresponding characters of the cell in the table is a single-character main body; When the object of the triple formed by the corresponding character and the vertically corresponding character is a multi-character object, the second position of the grid is marked as the first value; when the object of the triple formed by the horizontally corresponding character and the vertically corresponding character of the grid is a single-character object, the second position of the grid is marked as the second value; and when the horizontally corresponding character and the vertically corresponding character of the grid are the first characters of two entities respectively, the third position of the grid is marked as the third value; and when the horizontally corresponding character and the vertically corresponding character of the grid are the last characters of two entities respectively, the third position of the grid is marked as the fourth value.
9. An entity relation extraction device, characterized in that, include: The acquisition module is used to acquire the input text; The relation extraction module is used to extract entity relations from the input text using an entity relation extraction model to obtain triples of the input text; the entity relation extraction model is trained by the method described in any one of claims 1 to 6.
10. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the steps of the method according to any one of claims 1-6, or when it is executed by the processor, it implements the steps of the method according to claim 7.
11. An electronic device, characterized in that, include: A memory on which computer programs are stored; A processor for executing the computer program in the memory to implement the steps of the method of any one of claims 1-6, or for executing the computer program in the memory to implement the steps of the method of claim 7.
Citation Information
Patent Citations
Information acquisition method and device, equipment and medium
CN113468330A