Entity relationship extraction method and device, equipment and storage medium
By determining the header entity and its features in the target text in entity relationship extraction, and combining preset relationship type characteristics, the problem of low accuracy in entity relationship extraction in the prior art is solved, and multiple relationship triplets and entities are realized Efficient extraction effect in overlapping situations.
Patent Information
- Application Number
- CN202411733045.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-28
- Publication Date
- 2025-02-18
AI Technical Summary
The existing entity relationship extraction method contains multiple relational triplets in a sentence, and the entities of the triplet may overlap, the accuracy is low.
By determining the first feature and entity tag of each character in the target text, determining the header entity based on the entity tag, and splicing the entity type features corresponding to the first feature and the entity tag, the second feature of each entity character is obtained. Then, for each sentence, the characteristics of the sentence are determined based on the characteristics of the head entity contained in the sentence and the preset relationship type characteristics, and the relationship with the head entity is determined based on the characteristics of the sentence.
Effectively integrate header entity and relationship type information, reduce interference from non-entity words, and realize that when entities overlap, all tail entities of each header entity under a specific relationship type can be accurately and efficiently extracted.
Smart Images

Figure CN119476294A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of natural language processing technology, and in particular to a method, device, equipment and storage medium for extracting entity relations. Background Art
[0002] The rapid development of the Internet has generated massive amounts of unstructured text data. People have a more urgent need to utilize information, so entity relationship extraction technology has attracted much attention.
[0003] Entity relationship extraction is an important part of natural language processing and the basis for downstream applications such as text mining, information retrieval, and knowledge graph construction. Traditional relationship extraction only considers the case where there is only one entity pair in a sentence, but a sentence may contain multiple relationship triplets, and the entities in the triplets may overlap. Existing entity relationship extraction methods have low accuracy. Summary of the invention
[0004] The present invention provides an entity relationship extraction method, device, equipment and storage medium to solve the problem that the existing entity relationship extraction method contains multiple relationship triples in a sentence and has low accuracy when the entities of the triples overlap.
[0005] In a first aspect, an embodiment of the present invention provides a method for extracting entity relationships, the method comprising:
[0006] Determine the first feature and entity tag of each character in the target text; wherein the entity tag includes the entity type of the character and / or the position of the character in the entity; the entity type includes entity and non-entity;
[0007] Determine the head entity in the target text based on the entity tag, and concatenate the first feature with the entity type feature corresponding to the entity tag to obtain a second feature of each entity character; wherein the entity character is a character whose entity type is entity;
[0008] For the entity character, determining the feature of each head entity based on the second feature and the feature of the entity label;
[0009] For each sentence in the target text, determining the feature of the sentence based on the feature of the head entity contained in the sentence and the feature of the preset relationship type; wherein the feature of the sentence is associated with the preset relationship type;
[0010] According to the characteristics of the sentence, a tail entity having a relationship with a head entity contained in the sentence is determined to be a tail entity of the preset relationship type in the sentence, and the head entity, the preset relationship type and the tail entity are determined as a group of entity relationships.
[0011] In a second aspect, an embodiment of the present invention provides a device for extracting entity relationships, the device comprising:
[0012] A feature and label determination module, used to determine the first feature and entity label of each character in the target text; wherein the entity label includes the entity type of the character and / or the position of the character in the entity; the entity type includes entity and non-entity;
[0013] A feature concatenation module is used to determine the head entity in the target text based on the entity tag, and concatenate the first feature with the entity type feature corresponding to the entity tag to obtain a second feature of each entity character; wherein the entity character is a character whose entity type is entity;
[0014] A head entity determination module, configured to determine, for an entity character, a feature of each head entity based on the second feature and a feature of the entity label;
[0015] A sentence feature determination module, configured to determine, for each sentence in the target text, a feature of the sentence based on a feature of a head entity contained in the sentence and a preset relationship type feature; wherein the feature of the sentence is associated with the preset relationship type;
[0016] An entity relationship determination module is used to determine in the sentence, according to the characteristics of the sentence, a tail entity whose relationship with the head entity contained in the sentence is the preset relationship type, and to determine the head entity, the preset relationship type and the tail entity as a set of entity relationships.
[0017] In a third aspect, an embodiment of the present invention provides an electronic device, the electronic device comprising:
[0018] at least one processor;
[0019] and a memory communicatively coupled to the at least one processor;
[0020] The memory stores a computer program that can be executed by the at least one processor, and the computer program is executed by the at least one processor so that the at least one processor can execute the entity relationship extraction method described in any embodiment of the present invention.
[0021] In a fourth aspect, an embodiment of the present invention further provides a computer-readable storage medium, characterized in that the computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a processor to implement the entity relationship extraction method described in any embodiment of the present invention when executed.
[0022] The technical solution of the embodiment of the present invention is to determine the first feature and entity label of each character in the target text; wherein the entity label includes the entity type of the character and / or the position of the character in the entity; the entity type includes entity and non-entity; based on the entity label, the head entity in the target text is determined, and the first feature and the entity type feature corresponding to the entity label are spliced to obtain the second feature of each entity character; wherein the entity character is a character whose entity type is entity; for the entity character, the feature of each head entity is determined based on the second feature and the feature of the entity label; for each sentence in the target text, the feature of the sentence is determined based on the feature of the head entity contained in the sentence and the preset relationship type feature; wherein the feature of the sentence is associated with the preset relationship type; according to the feature of the sentence, the tail entity whose relationship with the head entity contained in the sentence is the preset relationship type is determined in the sentence, and the head entity, the preset relationship type and the tail entity are determined as a group of entity relationships. This method determines the head entities in the target text and the features of each head entity, determines the features of the sentence based on the features of the head entity and the features of the preset relationship type, and determines the corresponding tail entity based on the head entity and the preset relationship type contained in the sentence. It effectively integrates the head entity and relationship type information and reduces the interference of non-entity words, thereby achieving accurate and efficient extraction of all tail entities of each head entity under a specific relationship type even when entities overlap, providing strong support for the promotion of subsequent business (such as knowledge graph construction and support for intelligent decision-making).
[0023] It should be understood that the contents described in this section are not intended to identify the key or important features of the embodiments of the present invention, nor are they intended to limit the scope of the present invention. Other features of the present invention will become easily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS
[0024] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0025] Figure 1 A flowchart of a method for extracting entity relationships provided by an embodiment of the present invention;
[0026] Figure 2 A schematic diagram of the structure of an entity relationship extraction device provided by an embodiment of the present invention;
[0027] Figure 3 A schematic diagram of the structure of an electronic device that can be used to implement an embodiment of the present invention is shown. DETAILED DESCRIPTION
[0028] In order to enable those skilled in the art to better understand the scheme of the present invention, the technical scheme in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of the present invention.
[0029] It should be noted that the terms "first", "second", etc. in the specification and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchanged where appropriate, so that the embodiments of the present invention described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units that are clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0030] It should be noted that the traditional relationship extraction method only considers the case where there is only one entity pair in a sentence. However, a sentence may contain multiple relationship triplets, and the entities of the triplets may overlap. The existing entity relationship extraction method has low accuracy.
[0031] Based on this, an embodiment of the present invention provides a method for extracting entity relationships. Figure 1 A flowchart of an entity relationship extraction method provided in an embodiment of the present invention. The embodiment of the present invention can be applied to scenarios in which named entities (i.e., entities with some unique meaning, such as names of people, places, and organizations) are automatically identified from text and the relationships between entities are extracted. The method can be executed by an entity relationship extraction device, which can be implemented in the form of software and / or hardware, and optionally, by an electronic device, which is preferably a mobile terminal, a desktop computer, a laptop computer, a server, and the like.
[0032] like Figure 1 As shown, a method for extracting entity relationships provided by an embodiment of the present invention may specifically include:
[0033] S101, determining a first feature and an entity tag of each character in a target text; wherein the entity tag includes an entity type of the character and / or a position of the character in the entity; and the entity type includes entity and non-entity.
[0034] Among them, the target text can be understood as the text obtained with the entity relationship extraction requirements, and this embodiment does not limit the language type of the target text. The first feature can be understood as a feature vector representing the feature of each character in the target text. The first feature may include the word embedding feature of each character, which is used to combine the self-semantics and context of each character; it may also include a sentence embedding feature, which is used to indicate which sentence the character belongs to, that is, it contains the index information of the sentence; it may also include a position embedding feature, which is used to indicate the actual position of the character in the sentence. The entity label can be understood as the identification information marked on each character in the target text. The entity label may include the entity type of the character, and the entity type includes entity and non-entity, and may also include attributes such as whether the entity belongs to a person's name, an organization name, or a place name; the entity label may also include the position of the character in the entity, such as the position in the entity is the first character, the last character, or the middle character, or the first character, the second character, etc. in the entity.
[0035] In this embodiment, the first feature of each character in the target text is determined by a neural network model or a language representation model, and a label annotation system (such as BIO, BIEO, BIOSE, etc.) is used to determine the entity label corresponding to each character according to the first feature.
[0036] Exemplarily, the label annotation system can adopt the BIEO label annotation system, that is, B represents the first character of the entity, I represents the middle character of the entity, E represents the last character of the entity, and O represents other characters. In combination with the BIEO label annotation system, taking the annotation of a person's name (PER) as an example, the corresponding entity label set can be B-PER (that is, the character is the first character of the entity and is a person's name), I-PER (that is, the character is the middle character of the entity and is a person's name) and E-PER (that is, the character is the last character of the entity and is a person's name). Taking the annotation of a place name (LOC) as an example, the corresponding entity label set can be B-LOC, I-LOC and E-LOC. By analogy, dates, times, organization names, etc. can also be annotated.
[0037] S102. Determine the head entity in the target text based on the entity tag, and concatenate the first feature with the entity type feature corresponding to the entity tag to obtain a second feature of each entity character; wherein the entity character is a character whose entity type is entity.
[0038] Among them, the entity type feature can be understood as a feature preset for each entity type in the entity tag. For example, the entity type feature can be preset for the entity type being a person's name, an organization name, and / or a non-entity, etc., that is, each different entity type has a feature vector representing the entity type, etc. The second feature can be understood as a feature obtained by embedding the corresponding entity type feature on the basis of the first feature of each character, and is used to improve the accuracy of entity relationship extraction by adding character features.
[0039] In this embodiment, based on the entity type of each character provided by the entity tag and / or the position of the character in the entity, each entity in the target text is determined, the entity is usually a noun or a noun phrase, and each entity is determined as the head entity in the target text. Exemplarily, two characters consecutively marked as B-PER and E-PER in the target text can be determined as a head entity; three characters consecutively marked as B-LOC, I-LOC and E-LOC in the target text can also be determined as a head entity; B-LOC that appears alone can also be regarded as a head entity. Then, the first feature of each character is spliced with the entity type feature corresponding to the entity tag to obtain the second feature of each entity character. The process of splicing the first feature of each character with the entity type feature corresponding to the entity tag can be specifically expressed as:
[0040] h i =[h i,1 ,h i,2 ,…,h i,d ];
[0041] h e =[h e,1 ,h e,2 ,…,h e,M ];
[0042] h i '=[h i ;h e ]=[h i,1 ,h i,2 ,…,h i,d ,h e,1 ,h e,2 ,…,h e,M ];
[0043] Among them, h i is the first feature of the i-th character, d is the vector dimension of the first feature, h e is the entity type feature of the ith character under the entity type e corresponding to the entity tag, M is the vector dimension of the entity type feature, and the second feature of the ith character obtained by concatenating the first feature of each character with the entity type feature corresponding to the entity tag is h with a vector dimension of d+M. i'.
[0044] S103: For the entity characters, determine the features of each head entity based on the second feature and the features of the entity tag.
[0045] Among them, the feature of the entity tag can be understood as the information extracted from the entity tag (such as B-PER, E-LOC) to quantify the entity tag, which is used to characterize the important information in the entity tag.
[0046] It can be understood that, since only entity characters can constitute a head entity, it is necessary to determine the features of each head entity based on the entity characters.
[0047] In this embodiment, the relative position information of each entity character can be determined based on the second feature of each entity character by calculating the relative position between each entity character and the corresponding context character within a specific distance; and the features corresponding to each entity character are re-determined based on the relative position information of each entity character; on the basis of the re-determined features corresponding to each entity character, the features of the entity label are combined as new features corresponding to each entity character; and taking a single head entity as a unit, the average vector sum of the new features corresponding to each entity character in each head entity is calculated as the feature of each head entity.
[0048] S104. For each sentence in the target text, determine the features of the sentence based on the features of the head entity contained in the sentence and the features of the preset relationship type; wherein the features of the sentence are associated with the preset relationship type.
[0049] The preset relationship type feature can be understood as a preset feature for each relationship type (such as located in, belongs to, etc.) to characterize the key information of the relationship type. For example, the preset relationship type feature h under the relationship type r r Specifically, it can be expressed as:
[0050] h r =[h r,1 ,h r,2 ,…,h r,s ];
[0051] Wherein, s is the vector dimension of the preset relationship type feature.
[0052] In this embodiment, a neural network model or a language representation model may be used to preset the relationship type features, wherein the relationship types may include belonging to, located in, etc. For each sentence in the target text, based on the features of the head entity contained in the sentence, the average vector of the sentence is obtained through the relationship-aware attention mechanism; then, based on the average vector of the sentence, the preset relationship type features, and the second features of each character, the attention score of each character in the sentence under a specific relationship type is determined, and the features of the sentence are obtained based on the second features of each character and the attention score.
[0053] S105. Determine in the sentence, according to the features of the sentence, a tail entity whose relationship with the head entity contained in the sentence is a preset relationship type, and determine the head entity, the preset relationship type, and the tail entity as a set of entity relationships.
[0054] In this embodiment, according to the features of the head entity contained in the features of the sentence and the features of the preset relationship type, a tail entity whose relationship with the head entity contained in the sentence is the preset relationship type is determined in the sentence, that is, the tail entity is extracted under a specific head entity and relationship type, and the head entity, the preset relationship type and the tail entity are determined as a set of entity relationships. Exemplarily, a discriminant probability model (such as a conditional random field model) can be used to extract the tail entity.
[0055] An embodiment of the present invention provides a method for extracting entity relationships, which determines the first feature and entity label of each character in a target text; wherein the entity label includes the entity type of the character and / or the position of the character in the entity; the entity type includes entity and non-entity; based on the entity label, a head entity in the target text is determined, and the first feature and the entity type feature corresponding to the entity label are spliced to obtain the second feature of each entity character; wherein the entity character is a character whose entity type is entity; for the entity character, the feature of each head entity is determined based on the second feature and the feature of the entity label; for each sentence in the target text, the feature of the sentence is determined based on the feature of the head entity contained in the sentence and the feature of the preset relationship type; wherein the feature of the sentence is associated with the preset relationship type; according to the feature of the sentence, a tail entity whose relationship with the head entity contained in the sentence is a preset relationship type is determined in the sentence, and the head entity, the preset relationship type and the tail entity are determined as a group of entity relationships. This method determines the head entities in the target text and the features of each head entity, determines the features of the sentence based on the features of the head entity and the features of the preset relationship type, and determines the corresponding tail entity based on the head entity and the preset relationship type contained in the sentence. It effectively integrates the head entity and relationship type information and reduces the interference of non-entity words, thereby achieving accurate and efficient extraction of all tail entities of each head entity under a specific relationship type even when entities overlap, providing strong support for the promotion of subsequent business (such as knowledge graph construction and support for intelligent decision-making).
[0056] As a first optional embodiment of this embodiment, based on the above embodiment, for entity characters, the features of each head entity can be determined based on the second feature and the features of the entity tag, which can be concretized into the following steps:
[0057] a1) Determine the correlation information between the entity character and the context character based on the second feature.
[0058] The relevant information may be understood as information indicating the relationship between each entity character and the corresponding context character, and is used to determine features in the entity character that should be paid more attention to.
[0059] In this embodiment, the related information between the entity character and the context character is determined based on the second feature of each entity character, the relative position between each entity character and the corresponding context character, and the second feature of each context character.
[0060] As one implementation manner, this optional embodiment may further specify the related information between the entity character and the context character based on the second feature as follows:
[0061] a11) For each context character, determining a first relative distance between the entity character and the context character.
[0062] The first relative distance may be understood as the relative distance between the entity character and each context character within a set range.
[0063] In this embodiment, for each context character within a set range, a first relative distance between the entity character and the context character is determined according to a preset rule. Exemplarily, the method of determining the first relative distance can be specifically expressed as:
[0064]
[0065] index(u,m)=max(-m,min(u,m));
[0066] in, is the first relative distance between the bth entity character and the jth context character, m is the preset maximum distance, (-m, m) is the preset maximum range, ω U It can be understood as a preset first relative position representation.
[0067] Exemplarily, b is 4, j is 1, and the preset maximum distance m is 5, then the first relative distance between the fourth entity and the first context character is:
[0068]
[0069] Then you can find and determine the preset relative position representation corresponding to the first three characters starting from the 4th character, that is,
[0070] It should be noted that only the first relative distance between the entity character and the context character is considered. Therefore, for non-entity characters, ω U Set to 0.
[0071] a12) Determine the correlation information between the entity character and the context character based on the first relative distance, the second feature of the entity character and the second feature of the context character.
[0072] In this embodiment, the related information between the entity character and the context character is determined based on the first relative distance, the second feature of the entity character, and the second feature of the context character, which can be specifically expressed as:
[0073]
[0074] Among them, a bj is the related information between the bth entity character and the jth context character, h' b is the second feature of the b-th entity character, h' j is the second feature of the jth context character, W Q and W O is the parameter matrix of multi-head attention, d p Determine parameters for relevant information.
[0075] The above technical scheme of the present embodiment determines the first relative distance between each entity character and the corresponding context character, and determines the relevant information between the entity character and the context character based on the first relative distance, the second feature of the entity character and the second feature of the context character. It effectively utilizes the distance information of the entity character and its context character without considering the position information of the non-entity, and realizes the distinction between the distance information of entity words and non-entity words, reduces the interference of non-entity words, and further improves the accuracy of the extraction of entity relationships.
[0076] b1) determining a third feature of the entity character based on the relevant information, the second feature and a feature of the entity tag.
[0077] The third feature may be understood as a feature of the entity character obtained by taking into account the relevant information between the entity character and the context character and the feature of the entity label.
[0078] In this embodiment, the third feature of the entity character is determined based on the relevant information between the entity character and the context character, the second feature of the corresponding context character, and the feature of the entity tag.
[0079] As one implementation manner, this optional embodiment may further specify the third feature of the entity character based on the relevant information, the second feature, and the feature of the entity tag as follows:
[0080] b11) For each context character, determining a second relative distance between the entity character and the context character.
[0081] The second relative distance may be understood as another relative distance between the entity character and each context character within a set range, which is different from the first relative distance.
[0082] In this embodiment, for each context character within a set range, the second relative distance between the entity character and each context character is determined. Exemplarily, determining the second relative distance between the entity character and the context character can be specifically expressed as:
[0083]
[0084] index(u,m)=max(-m,min(u,m));
[0085] in, is the second relative distance between the bth entity character and the jth context character, ω V It can be understood as a preset second relative position representation, which is different from the first relative position representation ω U .
[0086] It should be noted that only the second relative distance between the entity character and the context character is considered, so for non-entity characters, ω V Set to 0.
[0087] b12) Determine the intermediate feature of the entity character based on the relevant information, the second feature and the second relative distance.
[0088] The intermediate feature of the entity character can be understood as a feature obtained when the second feature is not completely converted to the third feature.
[0089] In this embodiment, the intermediate feature of the entity character is determined based on the relevant information, the second feature of the context character, and the second relative distance, which can be specifically expressed as:
[0090]
[0091] Among them, p' b is the intermediate feature of the b-th entity character, n is the number of context characters, W V is the parameter matrix of the second feature relative to the context character.
[0092] b13) concatenating the intermediate feature with the feature of the entity label of the entity character to obtain a third feature of the entity character.
[0093] In this embodiment, the intermediate features of each entity character are concatenated with the features of the entity tag corresponding to the entity character to obtain the third feature of the entity character. Exemplarily, the method of obtaining the third feature can be specifically expressed as:
[0094] p b =[l b ;p' b ];
[0095] Among them, p b is the third feature of the b-th entity character, l b The feature of the entity label of the entity character.
[0096] The above technical scheme of this embodiment determines the second relative distance between the entity character and the context character, and determines the intermediate feature of the entity character based on the relevant information, the second feature and the second relative distance, and concatenates the intermediate feature with the feature of the entity label of the entity character to obtain the third feature of the entity character, so as to better utilize the information interaction between entity words, distinguish entity characters from non-entity characters, reduce the interference of irrelevant words in the sentence, and at the same time add the feature of the entity label of the entity character to the third feature, enhance the feature expression of each entity character to further improve the accuracy and efficiency of entity relationship extraction.
[0097] c1) For each head entity, an average value of a third feature of at least one entity character included in the head entity is determined as a feature of the head entity.
[0098] In this embodiment, each head entity includes at least one entity character, and the feature of each head entity may be determined by calculating the average value of the third feature of the at least one entity character included in each head entity.
[0099] The above technical scheme of this embodiment determines the relevant information between the entity character and the context character, and determines the third feature of the entity character based on the relevant information, the second feature and the feature of the entity label, thereby better utilizing the information interaction between entity words, reducing the interference of irrelevant words in the sentence, and using the average value of the third feature of the entity character as the feature of the corresponding head entity, so that the feature expression of the head entity is more accurate, further providing strong support for the subsequent accurate extraction of the tail entity.
[0100] As a second optional embodiment of this embodiment, the features of the sentence may be determined based on the features of the head entity contained in the sentence and the preset relationship type features, which may be specifically optimized into the following steps:
[0101] a2) For each character contained in the sentence, determine the attention score of the character according to the feature of the head entity contained in the sentence, the preset relationship type feature, the initial feature of the sentence and the second feature of the character.
[0102] The initial features of a sentence can be understood as features that are composed of the third features corresponding to each character in the sentence and that can represent important information of the sentence. The attention score can be understood as a score used to determine the importance of a character when performing feature fusion.
[0103] In this embodiment, for each character contained in the sentence, the features of the head entity contained in the sentence are integrated into the initial features of the sentence, and the attention score of each character contained in the sentence is determined by combining the preset relationship type features corresponding to each character and the second features of each character.
[0104] As one implementation method, this optional embodiment can determine the attention score of each character contained in the sentence according to the feature of the head entity contained in the sentence, the preset relationship type feature, the initial feature of the sentence, and the second feature of the character, and further specify it as the following content:
[0105] a21) For each head entity contained in the sentence, determine the first intermediate feature of the sentence according to the feature of the head entity and the initial feature of the sentence.
[0106] Among them, the first intermediate feature can be understood as the feature of the sentence obtained after integrating the feature of the head entity into the initial feature of the sentence.
[0107] In this embodiment, for each head entity contained in the sentence, each head entity is respectively integrated into the initial features of the sentence to obtain the first intermediate features of the sentence corresponding to each head entity. Exemplarily, the method of determining the first intermediate features of the sentence according to the features of the head entity and the initial features of the sentence can be specifically expressed as:
[0108]
[0109] p=[p1,p2,…,p n ];
[0110] Among them, p is the initial feature of the sentence, which is composed of the third features corresponding to n characters. n is the third feature of the nth character, A f To transform the features of the f-th head entity The first intermediate feature of the sentence determined after incorporating the initial features of the sentence, W a is the intermediate feature fusion weight, b a is the intermediate feature fusion offset.
[0111] a22) averaging the first intermediate features corresponding to each head entity to obtain the second intermediate feature of the sentence.
[0112] The second intermediate feature can be understood as a feature obtained by averaging the first intermediate features, and is used to represent the feature vector mean of the sentence.
[0113] In this embodiment, the process of averaging the first intermediate features corresponding to each head entity to obtain the second intermediate feature of the sentence can be specifically expressed as:
[0114] S avg,f =average(A f );
[0115] Among them, S avg,f It is the second intermediate feature of the sentence obtained after integrating the features of the f-th head entity.
[0116] a23) determining an attention score of the character based on the second intermediate feature, the preset relationship type feature and the second feature of the character.
[0117] In this embodiment, based on the second intermediate feature, the preset relationship type feature and the second feature of the character, the specific process of determining the attention score of the character can be expressed as:
[0118]
[0119] Among them, v k is the character attention score weight under relation type k, W r is the preset relationship type feature weight, h k is the preset relationship type feature under relationship type k, W avg is the second intermediate feature weight, W f is the second feature weight.
[0120] The above technical scheme of this embodiment obtains the second intermediate feature of the sentence by averaging the first intermediate feature integrated into the head entity, and determines the attention score of each character under different relationship types based on the second intermediate feature, the preset relationship type feature and the second feature of the character, thereby determining the importance of each character in the sentence under different relationship types, so as to improve the accuracy of obtaining the features of the sentence under different relationship types.
[0121] b2) Based on the attention score, the second features of each character contained in the sentence are integrated to obtain the features of the sentence.
[0122] In this embodiment, the attention scores obtained for each character under the relationship type corresponding to the preset relationship type feature are normalized to obtain the fusion weight of each character, and the second features of all characters in the sentence are fused according to the fusion weight of each character to obtain the features of the sentence.
[0123] Exemplarily, the process of fusing the second features of each character contained in the sentence based on the attention score to obtain the features of the sentence can be specifically expressed as follows:
[0124]
[0125]
[0126] in, is the attention score of the i-th character under relation type k after incorporating the features of the f-th head entity, is the fusion weight of the i-th character obtained by normalizing the attention score of the i-th character, is the feature of the sentence after incorporating the features of the f-th head entity.
[0127] The above technical solution of this embodiment integrates the features of the head entity and calculates the attention scores of characters under different relationship types, thereby obtaining the features of a sentence with the head entity as the main body and the relationship as the guide, reducing the interference of irrelevant words on relationship extraction, and providing strong support for the subsequent accurate extraction of all tail entities corresponding to the head entity under each relationship type.
[0128] As a third optional embodiment of this embodiment, determining the first feature and entity label of each character in the target text may be concretized into the following steps:
[0129] a3) inputting the target text into a preset feature recognition model, and outputting the first feature of each character.
[0130] Among them, the preset feature recognition model can be understood as a model with feature recognition function, such as a pre-trained language model (such as a BERT model), a neural network model (such as a bidirectional long short-term memory network), etc.
[0131] In this embodiment, the target text is input into a preset feature recognition model, and after the target text is analyzed by the preset feature recognition model, the first feature of each character in the target text is determined.
[0132] Exemplarily, the input target text X can be specifically expressed as:
[0133] X=[x1,x2,…,x n ];
[0134] Among them, x i is the i-th character in the input target text, i∈[1,n]. For example, if the target text is Chinese text, then x1,x2,…,x n It can be considered as n Chinese characters. If the target text is English text, then x1, x2, …, x n It can be considered as n words.
[0135] Exemplarily, if the BERT model is used as the preset feature recognition model, the target text is input into the preset feature recognition model, and the process of outputting the first feature of each character can be specifically expressed as follows:
[0136]
[0137]
[0138]
[0139] in, is the feature vector of the z-th layer Transformer model in the BERT model for the ith character in the target text. Transformer(·) represents the calculation process of the Transformer model. Z is the total number of Transformer layers. h is the output feature of the BERT model, that is, the feature vector containing the first feature of each character. The first feature of each character is the feature vector output by the z-th layer Transformer model in the BERT model.
[0140] b3) decoding the first feature of each character based on a preset decoding algorithm to obtain an entity label of each character.
[0141] In this embodiment, a preset decoding algorithm is used to decode the first feature of each character output by the preset feature recognition model, and a label annotation system is used to assign the most likely entity label to each character to identify the entity type of each character and / or the position of the character in the entity. Exemplarily, the preset decoding algorithm can use conditional random field decoding (CRF decoding), bidirectional long short-term memory network + CRF decoding, non-autoregressive model or Two-Pass mechanism, etc.
[0142] Exemplarily, the preset decoding algorithm adopts CRF decoding. The CRF model calculates the conditional probability distribution of the input target text, considers all input target texts during decoding, and integrates the information between each label in the label annotation system to construct a probability graph model, and determines the final entity label through the Viterbi algorithm, thereby improving the accuracy of entity label annotation.
[0143] The above technical solution of this embodiment obtains the first feature of each character by inputting the target text into a preset feature recognition model, decodes the first feature of each character based on a preset decoding algorithm, considers all input target texts during decoding, and integrates the information between each label in the label annotation system to construct a probability graph model, thereby improving the accuracy of entity label annotation.
[0144] Figure 2The schematic diagram of the structure of an entity relationship extraction device provided by an embodiment of the present invention is as follows. Figure 2 As shown, the device includes: a feature and label determination module 21, a feature splicing module 22, a head entity determination module 23, a sentence feature determination module 24 and an entity relationship determination module 25, wherein:
[0145] A feature and label determination module 21 is used to determine a first feature and an entity label of each character in the target text; wherein the entity label includes an entity type of the character and / or a position of the character in the entity; the entity type includes an entity and a non-entity;
[0146] A feature concatenation module 22 is used to determine the head entity in the target text based on the entity tag, and concatenate the first feature with the entity type feature corresponding to the entity tag to obtain a second feature of each entity character; wherein the entity character is a character whose entity type is entity;
[0147] A head entity determination module 23, configured to determine, for an entity character, a feature of each head entity based on the second feature and a feature of the entity label;
[0148] A sentence feature determination module 24, configured to determine, for each sentence in the target text, a feature of the sentence based on a feature of a head entity contained in the sentence and a feature of a preset relationship type; wherein the feature of the sentence is associated with the preset relationship type;
[0149] The entity relationship determination module 25 is used to determine in the sentence, according to the characteristics of the sentence, a tail entity whose relationship with the head entity contained in the sentence is the preset relationship type, and determine the head entity, the preset relationship type and the tail entity as a set of entity relationships.
[0150] An embodiment of the present invention provides an entity relationship extraction device, which determines the first feature and entity label of each character in the target text; wherein the entity label includes the entity type of the character and / or the position of the character in the entity; the entity type includes entity and non-entity; based on the entity label, the head entity in the target text is determined, and the first feature and the entity type feature corresponding to the entity label are spliced to obtain the second feature of each entity character; wherein the entity character is a character whose entity type is entity; for the entity character, the feature of each head entity is determined based on the second feature and the feature of the entity label; for each sentence in the target text, the feature of the sentence is determined based on the feature of the head entity contained in the sentence and the preset relationship type feature; wherein the feature of the sentence is associated with the preset relationship type; according to the feature of the sentence, the tail entity whose relationship with the head entity contained in the sentence is the preset relationship type is determined in the sentence, and the head entity, the preset relationship type and the tail entity are determined as a group of entity relationships. This method determines the head entities in the target text and the features of each head entity, determines the features of the sentence based on the features of the head entity and the features of the preset relationship type, and determines the corresponding tail entity based on the head entity and the preset relationship type contained in the sentence. It effectively integrates the head entity and relationship type information and reduces the interference of non-entity words, thereby achieving accurate and efficient extraction of all tail entities of each head entity under a specific relationship type even when entities overlap, providing strong support for the promotion of subsequent business (such as knowledge graph construction and support for intelligent decision-making).
[0151] Further, the header entity determination module 23 may specifically include:
[0152] A related information determining unit, configured to determine the related information between the entity character and the context character based on the second feature;
[0153] an entity character feature determination unit, which determines a third feature of the entity character based on the relevant information, the second feature, and a feature of the entity tag;
[0154] The head entity feature determination unit is used to determine, for each head entity, an average value of a third feature of at least one entity character included in the head entity as a feature of the head entity.
[0155] Furthermore, the relevant information determination unit may be specifically used for:
[0156] For each context character, determining a first relative distance between the entity character and the context character;
[0157] Determine the correlation information between the entity character and the context character based on the first relative distance, the second feature of the entity character, and the second feature of the context character.
[0158] Furthermore, the entity character feature determination unit can be specifically used for:
[0159] For each context character, determining a second relative distance between the entity character and the context character;
[0160] Determining an intermediate feature of the entity character based on the relevant information, the second feature and the second relative distance;
[0161] The intermediate feature is concatenated with the feature of the entity label of the entity character to obtain a third feature of the entity character.
[0162] Furthermore, the sentence feature determination module 24 may specifically include:
[0163] an attention score determining unit, configured to determine, for each character contained in the sentence, an attention score of the character according to a feature of a head entity contained in the sentence, the preset relationship type feature, an initial feature of the sentence, and a second feature of the character;
[0164] The sentence feature acquisition unit is used to fuse the second features of each character contained in the sentence based on the attention score to obtain the features of the sentence.
[0165] Furthermore, the attention score determination unit may be specifically used for:
[0166] For each head entity included in the sentence, determining a first intermediate feature of the sentence according to a feature of the head entity and an initial feature of the sentence;
[0167] The first intermediate features corresponding to each head entity are averaged to obtain the second intermediate feature of the sentence;
[0168] An attention score of the character is determined based on the second intermediate feature, the preset relationship type feature, and the second feature of the character.
[0169] Furthermore, the feature and label determination module 21 can be specifically used for:
[0170] Input the target text into a preset feature recognition model, and output the first feature of each character;
[0171] The first feature of each character is decoded based on a preset decoding algorithm to obtain an entity label of each character.
[0172] An entity relationship extraction device provided in an embodiment of the present invention can execute an entity relationship extraction method provided in any embodiment of the present invention, and has corresponding functional modules and beneficial effects of the execution method.
[0173] Figure 3A schematic diagram of the structure of an electronic device 30 that can be used to implement an embodiment of the present invention is shown. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital processing, cellular phones, smart phones, wearable devices (such as helmets, glasses, watches, etc.) and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the present invention described and / or required herein.
[0174] like Figure 3 As shown, the electronic device 30 includes at least one processor 31, and a memory connected to the at least one processor 31, such as a read-only memory (ROM) 32, a random access memory (RAM) 33, etc., wherein the memory stores a computer program that can be executed by at least one processor, and the processor 31 can perform various appropriate actions and processes according to the computer program stored in the read-only memory (ROM) 32 or the computer program loaded from the storage unit 38 to the random access memory (RAM) 33. In the RAM 33, various programs and data required for the operation of the electronic device 30 can also be stored. The processor 31, the ROM 32, and the RAM 33 are connected to each other through a bus 34. An input / output (I / O) interface 35 is also connected to the bus 34.
[0175] A number of components in the electronic device 30 are connected to the I / O interface 35, including: an input unit 36, such as a keyboard, a mouse, etc.; an output unit 37, such as various types of displays, speakers, etc.; a storage unit 38, such as a disk, an optical disk, etc.; and a communication unit 39, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit 39 allows the electronic device 30 to exchange information / data with other devices through a computer network such as the Internet and / or various telecommunication networks.
[0176] The processor 31 may be a variety of general and / or special processing components with processing and computing capabilities. Some examples of the processor 31 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various dedicated artificial intelligence (AI) computing chips, various processors running machine learning model algorithms, digital signal processors (DSPs), and any appropriate processors, controllers, microcontrollers, etc. The processor 31 executes the various methods and processes described above, such as the method for extracting entity relationships.
[0177] In some embodiments, the entity relationship extraction method can be implemented as a computer program, which is tangibly contained in a computer-readable storage medium, such as a storage unit 38. In some embodiments, part or all of the computer program can be loaded and / or installed on the electronic device 30 via the ROM 32 and / or the communication unit 39. When the computer program is loaded into the RAM 33 and executed by the processor 31, one or more steps of the entity relationship extraction method described above can be performed. Alternatively, in other embodiments, the processor 31 can be configured to execute the entity relationship extraction method in any other appropriate manner (for example, by means of firmware).
[0178] Various implementations of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chips (SOCs), load programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various implementations can include: being implemented in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which can be a special purpose or general purpose programmable processor that can receive data and instructions from a storage system, at least one input device, and at least one output device, and transmit data and instructions to the storage system, the at least one input device, and the at least one output device.
[0179] Computer programs for implementing the methods of the present invention may be written in any combination of one or more programming languages. These computer programs may be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device, so that when the computer program is executed by the processor, the functions / operations specified in the flow chart and / or block diagram are implemented. The computer program may be executed entirely on the machine, partially on the machine, partially on the machine and partially on a remote machine as a stand-alone software package, or entirely on a remote machine or server.
[0180] In the context of the present invention, a computer-readable storage medium may be a tangible medium that may contain or store a computer program for use by or in combination with an instruction execution system, device or equipment. A computer-readable storage medium may include, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, devices or equipment, or any suitable combination of the foregoing. Alternatively, a computer-readable storage medium may be a machine-readable signal medium. A more specific example of a machine-readable storage medium may include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
[0181] To provide interaction with a user, the systems and techniques described herein may be implemented on an electronic device having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and a pointing device (e.g., a mouse or trackball) through which the user can provide input to the electronic device. Other types of devices may also be used to provide interaction with the user; for example, the feedback provided to the user may be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user may be received in any form (including acoustic input, voice input, or tactile input).
[0182] The systems and techniques described herein may be implemented in a computing system that includes backend components (e.g., as a data server), or a computing system that includes middleware components (e.g., an application server), or a computing system that includes frontend components (e.g., a user computer with a graphical user interface or a web browser through which a user can interact with implementations of the systems and techniques described herein), or a computing system that includes any combination of such backend components, middleware components, or frontend components. The components of the system may be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: a local area network (LAN), a wide area network (WAN), a blockchain network, and the Internet.
[0183] A computing system may include a client and a server. The client and the server are generally remote from each other and usually interact through a communication network. The client and server relationship is generated by computer programs running on the corresponding computers and having a client-server relationship with each other. The server may be a cloud server, also known as a cloud computing server or cloud host, which is a host product in the cloud computing service system to solve the defects of difficult management and weak business scalability in traditional physical hosts and VPS services.
[0184] It should be understood that the various forms of processes shown above can be used to reorder, add or delete steps. For example, the steps described in the present invention can be executed in parallel, sequentially or in different orders, as long as the desired results of the technical solution of the present invention can be achieved, and this document does not limit this.
[0185] The above specific implementations do not constitute a limitation on the protection scope of the present invention. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions can be made according to design requirements and other factors. Any modification, equivalent substitution and improvement made within the spirit and principle of the present invention should be included in the protection scope of the present invention.
Claims
1. A method for extracting entity relationships, characterized in that: include: Determine the first feature and entity tag of each character in the target text; wherein the entity tag includes the entity type of the character and / or the position of the character in the entity; the entity type includes entity and non-entity; Determine the head entity in the target text based on the entity tag, and concatenate the first feature with the entity type feature corresponding to the entity tag to obtain a second feature of each entity character; wherein the entity character is a character whose entity type is entity; For the entity character, determining the feature of each head entity based on the second feature and the feature of the entity label; For each sentence in the target text, determining the feature of the sentence based on the feature of the head entity contained in the sentence and the feature of the preset relationship type; wherein the feature of the sentence is associated with the preset relationship type; According to the characteristics of the sentence, a tail entity having a relationship with a head entity contained in the sentence is determined to be a tail entity of the preset relationship type in the sentence, and the head entity, the preset relationship type and the tail entity are determined as a group of entity relationships.
2. The method according to claim 1, characterized in that For the entity character, determining the feature of each head entity based on the second feature and the feature of the entity tag includes: Determine the related information between the entity character and the context character based on the second feature; Determine a third feature of the entity character based on the relevant information, the second feature, and a feature of the entity tag; For each head entity, an average value of the third feature of at least one entity character included in the head entity is determined as the feature of the head entity.
3. The method according to claim 2, characterized in that Determining the related information between the entity character and the context character based on the second feature includes: For each context character, determining a first relative distance between the entity character and the context character; Determine the correlation information between the entity character and the context character based on the first relative distance, the second feature of the entity character, and the second feature of the context character.
4. The method according to claim 2, characterized in that: Determining a third feature of the entity character based on the relevant information, the second feature, and a feature of the entity tag includes: For each context character, determining a second relative distance between the entity character and the context character; Determining an intermediate feature of the entity character based on the relevant information, the second feature and the second relative distance; The intermediate feature is concatenated with the feature of the entity label of the entity character to obtain a third feature of the entity character.
5. The method according to claim 1, characterized in that Determining the features of the sentence based on the features of the head entity contained in the sentence and the preset relationship type features includes: For each character included in the sentence, determining an attention score of the character according to a feature of a head entity included in the sentence, the preset relationship type feature, an initial feature of the sentence, and a second feature of the character; The second features of each character contained in the sentence are fused based on the attention score to obtain the features of the sentence.
6. The method according to claim 5, characterized in that For each character included in the sentence, determining an attention score of the character according to a feature of a head entity included in the sentence, the preset relationship type feature, an initial feature of the sentence, and a second feature of the character, including: For each head entity included in the sentence, determining a first intermediate feature of the sentence according to a feature of the head entity and an initial feature of the sentence; The first intermediate features corresponding to each head entity are averaged to obtain the second intermediate feature of the sentence; An attention score of the character is determined based on the second intermediate feature, the preset relationship type feature, and the second feature of the character.
7. The method according to claim 1, characterized in that Determine the first feature and entity label of each character in the target text, including: Input the target text into a preset feature recognition model, and output the first feature of each character; The first feature of each character is decoded based on a preset decoding algorithm to obtain an entity label of each character.
8. An entity relationship extraction device, characterized in that: include: A feature and label determination module, used to determine the first feature and entity label of each character in the target text; wherein the entity label includes the entity type of the character and / or the position of the character in the entity; the entity type includes entity and non-entity; A feature concatenation module is used to determine the head entity in the target text based on the entity tag, and concatenate the first feature with the entity type feature corresponding to the entity tag to obtain a second feature of each entity character; wherein the entity character is a character whose entity type is entity; A head entity determination module, configured to determine, for an entity character, a feature of each head entity based on the second feature and a feature of the entity label; A sentence feature determination module, configured to determine, for each sentence in the target text, a feature of the sentence based on a feature of a head entity contained in the sentence and a preset relationship type feature; wherein the feature of the sentence is associated with the preset relationship type; An entity relationship determination module is used to determine in the sentence, according to the characteristics of the sentence, a tail entity whose relationship with the head entity contained in the sentence is the preset relationship type, and to determine the head entity, the preset relationship type and the tail entity as a set of entity relationships.
9. An electronic device, characterized in that: The electronic device comprises: at least one processor; and a memory communicatively coupled to the at least one processor; The memory stores a computer program executable by the at least one processor, and the computer program is executed by the at least one processor so that the at least one processor can execute the entity relationship extraction method described in any one of claims 1-7.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a processor to implement the entity relationship extraction method described in any one of claims 1 to 7 when executed.