Entity relationship extraction method and device based on fusion relationship and two-dimensional attention
By integrating relationships and two-dimensional attention, the entity relationship extraction method solves the problems of error propagation and low recognition rate caused by the staged entity recognition and relationship extraction in the existing technology, and achieves higher entity relationship extraction accuracy.
Patent Information
- Application Number
- CN202411005222.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-25
- Publication Date
- 2024-09-20
- Estimated Expiration
- 2044-07-25
AI Technical Summary
Existing entity relationship extraction methods divide entity recognition and relationship extraction into two stages, resulting in error propagation and low recognition rate. They also lack the inherent connection between entity recognition and relationship extraction, and cannot fully utilize global text information.
An entity relationship extraction method based on fusion relationship and two-dimensional attention is adopted. By preprocessing the text, text relationship encoding and word vectors are constructed, and two-dimensional word-level attention and sentence-level attention are used to calculate a dual attention matrix to extract entity relationships. , enhance the connection between entity recognition and relationship extraction, and improve extraction accuracy.
It effectively reduces the error propagation of entity recognition results and improves the accuracy of entity relationship extraction, especially in complex scenarios such as legal documents.
Smart Images

Figure CN118536505B
Abstract
Description
Technical Field
[0001] The present specification relates to the field of natural language processing technology, and in particular to a method and device for extracting entity relationships based on fusion relationships and two-dimensional attention. Background Art
[0002] Relation overlap is a difficult problem in the task of entity relationship extraction. Specifically, an entity in the text exists in multiple relationships. Due to the diverse legal entity relationships involved in documents in fields such as legal documents, there are a large number of overlapping relationships in the documents. In addition, each sentence in the document often has the phenomenon of missing subjects and replacement of demonstrative pronouns. Existing entity relationship extraction methods mainly use convolutional neural networks (CNN), recurrent neural networks (RNN) and long short-term memory networks (LSTM). Memory, LSTM), etc., extract relations for sentences with annotated entity pairs, and finally output the triples with entity relations as prediction results. However, the existing entity relation extraction method performs entity recognition and entity relation extraction in stages, which also means that two models need to be established according to the two stages respectively. However, such an entity relation extraction method has the disadvantage of error propagation. The errors of the previous model will accumulate to the latter model, and the entire extraction process will ignore the intrinsic connection between entity recognition and relation extraction. In addition, there is a lack of interaction between the two models, which makes the text information not fully utilized and the global text information cannot be fully utilized, resulting in error propagation and low recognition rate when extracting entity relations in legal documents. Therefore, there is an urgent need for an entity relation extraction method based on fusion relations and two-dimensional attention to strengthen the intrinsic connection between entity recognition and relation extraction, so as to make full use of temporal information and semantic information and improve the accuracy of entity relation extraction in complex scenarios such as legal documents. Summary of the invention
[0003] In view of the fact that the current entity recognition and entity relationship extraction are carried out in stages and there is a disadvantage of error propagation, the errors of the previous model will accumulate to the next model, and the entire extraction process will ignore the intrinsic connection between entity recognition and relationship extraction, and there is a lack of interaction between the two models, which makes the text information not fully utilized and the global text information cannot be fully utilized, resulting in error propagation and low recognition rate when extracting entity relationships in legal documents. This scheme is proposed to overcome the above problems or at least partially solve the above problems.
[0004] On the one hand, an object of some embodiments of this specification is to provide an entity relationship extraction method based on fusion relationship and two-dimensional attention, the method comprising:
[0005] Get the text to be recognized;
[0006] Preprocessing the text to be recognized to obtain a target text;
[0007] The target text is respectively segmented into sentences, words and characters to obtain a sentence set, a word set and a character segmentation set, and a corresponding sentence encoding is constructed according to the sentence set, the word set and the character segmentation set;
[0008] Inputting the sentence encoding into a pre-trained entity recognition model to identify entities, entity categories, and positions of entities in the sentence, and establishing corresponding text relationship encodings according to the entities, entity categories, and positions of entities in the sentence;
[0009] Determine a fusion relationship code according to the text relationship code and the word vector corresponding to the word set;
[0010] Taking sentence-level entity relations as the extraction dimension, according to the fusion relationship encoding, the two-dimensional word-level attention and sentence-level attention are used to calculate a two-dimensional dual attention vector matrix, and the two-dimensional dual attention vector matrix is decoded according to a bidirectional neural network to obtain the entity relationship extraction result.
[0011] Furthermore, the text to be recognized is preprocessed to obtain a target text, including:
[0012] Using regular expression matching, determining whether the text to be recognized has omissions;
[0013] If there is an omission, the position and content of the omitted information are determined according to the regular matching result and the omission syntactic rule, and the omitted information is added to the text to be recognized to obtain the text to be recognized without omission;
[0014] Based on the preset reference resolution feature, determining whether the text to be recognized without omissions contains a reference word;
[0015] If there is no omission, judging whether there is a pronoun in the text to be recognized based on the preset reference resolution feature;
[0016] If there is a pronoun, a pre-trained pronoun recognition model is used to identify the antecedent corresponding to the pronoun from the text to be recognized without omissions;
[0017] The antecedent is used to replace the pronoun in the text to be recognized without omission to obtain the target text.
[0018] Further, the target text is respectively segmented into sentences, words and characters to obtain a sentence set, a word set and a character segmentation set, and corresponding sentence encoding is constructed according to the sentence set, the word set and the character segmentation set, including:
[0019] Segmenting the target text based on preset punctuation marks to obtain a sentence set;
[0020] Performing character segmentation on the sentence set to obtain a character segmentation set, and obtaining corresponding character codes according to the character segmentation set;
[0021] Splitting each sentence in the sentence set into a plurality of words to obtain a corresponding word set, and selecting an entity word from the word set corresponding to each sentence as a reference word, and constructing a positional encoding according to the relative position of the reference word of each sentence and other words in the current sentence;
[0022] The character codes and position codes are concatenated to obtain a sentence code.
[0023] Further, determining the fusion relationship code according to the text relationship code and the word vector corresponding to the word set includes:
[0024] Calculating the cosine similarity between the text relation encoding and the word vector;
[0025] Establishing a corresponding cosine similarity vector according to the cosine similarity;
[0026] The cosine similarity vector is multiplied by the word vector to obtain the fusion relationship code.
[0027] Furthermore, taking the sentence-level entity relationship as the extraction dimension, according to the fusion relationship encoding, a two-dimensional dual attention vector matrix is obtained by using the two-dimensional word-level attention and sentence-level attention calculation, and the two-dimensional dual attention vector matrix is decoded according to the bidirectional neural network to obtain the entity relationship extraction result, including:
[0028] The fusion relationship encoding is input into a bidirectional neural network with a two-dimensional attention layer, so that the two-dimensional attention layer constructs a two-dimensional word-level attention matrix based on the word-level attention, and constructs a sentence-level attention matrix based on the sentence-level attention, and uses the sentence-level attention matrix as a weighting factor, and uses the weighting factor to perform weighted summation on the two-dimensional word-level attention matrix to obtain a two-dimensional dual attention vector matrix.
[0029] The bidirectional neural network iteratively updates the network weights and network biases according to the two-dimensional dual attention vector matrix until a preset convergence condition is reached to obtain the entity relationship extraction result.
[0030] Furthermore, the two-dimensional attention layer calculates a two-dimensional dual attention vector matrix using the following formula:
[0031]
[0032] Among them, h s * is the two-dimensional dual attention weight, β i is the sentence-level attention weight, X is the word-level attention weight under sentence representation, ReLU() is the activation function, ω0 is the network weight, b0 is the network bias, f is the feature of the sentence, and f FT is the feature vector of the sentence, obtained by concatenating f, H is the matrix composed of the output vectors of the bidirectional neural network, H T is the transposed matrix of H, and H=[h1,h2,h3,…,h t ], t is the sentence length, softmax() and tanh() are activation functions, w s1 、w s2 is the weight matrix, and w s1 The matrix size is da×2u, w s2 The matrix size is r ×da, da is the number of neurons in the network, and r is a hyperparameter.
[0033] Furthermore, taking the sentence-level entity relationship as the extraction dimension, according to the fusion relationship encoding, using the two-dimensional word-level attention and sentence-level attention to calculate a two-dimensional dual attention vector matrix, and decoding the two-dimensional dual attention vector matrix according to the bidirectional neural network, after obtaining the entity relationship extraction result, further comprising:
[0034] Establishing an objective function according to the entity relationship extraction result and its corresponding actual entity relationship;
[0035] Under the constraint conditions of the objective function, optimizing the objective function to obtain the optimal solution of the objective function;
[0036] The weights and biases corresponding to the optimal solution are used as the network weights and network biases of the bidirectional neural network to optimize the bidirectional neural network.
[0037] On the other hand, some embodiments of the present specification also provide an entity relationship extraction device based on fusion relationship and two-dimensional attention, the device comprising:
[0038] A receiving module, used for obtaining the text to be recognized;
[0039] A preprocessing module, used for preprocessing the text to be recognized to obtain a target text;
[0040] A sentence encoding module, used for performing sentence splitting, word splitting and character segmentation on the target text respectively, obtaining a sentence set, a word set and a character segmentation set, and constructing corresponding sentence encoding according to the sentence set, the word set and the character segmentation set;
[0041] A text relation encoding module, used to input the sentence encoding into a pre-trained entity recognition model, identify entities, entity categories and positions of entities in sentences, and establish corresponding text relation encodings according to the entities, entity categories and positions of entities in sentences;
[0042] A fusion relationship coding module, used to determine the fusion relationship coding according to the text relationship coding and the word vector corresponding to the word set;
[0043] The extraction module is used to use sentence-level entity relations as extraction dimensions, and according to the fusion relationship encoding, use two-dimensional word-level attention and sentence-level attention to calculate a two-dimensional dual attention vector matrix, and decode the two-dimensional dual attention vector matrix according to a bidirectional neural network to obtain an entity relationship extraction result.
[0044] On the other hand, some embodiments of the present specification further provide a computer device, including a memory, a processor, and a computer program stored in the memory, wherein when the computer program is executed by the processor, the instructions of the above method are executed.
[0045] On the other hand, some embodiments of the present specification further provide a computer storage medium having a computer program stored thereon, wherein when the computer program is executed by a processor of a computer device, the instructions of the above method are executed.
[0046] One or more technical solutions provided by some embodiments of this specification have at least the following technical effects:
[0047] The embodiments of the present specification first automatically obtain the text to be recognized, and preprocess the text to be recognized to optimize the text to be recognized to obtain the target text, and then respectively perform sentence splitting, word splitting and character segmentation on the target text to obtain sentence sets, word sets and character segmentation sets at different levels, establish corresponding sentence codes, and input the sentence codes into a pre-trained entity recognition model to identify the entities, entity categories and positions of the entities in each sentence, so as to establish corresponding text relationship codes according to the entities, entity categories and positions of the entities in the sentence. The text relationship codes can reflect the information of the entities in the target text. If the entity relationship extraction is performed directly according to the entity recognition results, there is a problem of unavoidable error propagation, and the entity recognition and relationship are not considered. In order to extract the intrinsic connection between entities, it is necessary to fuse the text relationship encoding and the word vector corresponding to the word set to obtain the fused relationship vector, so that the fused relationship vector has the information of the intrinsic connection between entity recognition and relationship extraction. At the same time, the fusion of word vector and text relationship encoding can also reduce the possibility of erroneous propagation of entity recognition results to a certain extent, and avoid entity recognition errors caused by relationship overlap. After that, the sentence-level entity relationship is used as the extraction dimension, the fused relationship encoding is input into the decoder, and the two-dimensional word-level attention and sentence-level attention are used to calculate the two-dimensional dual attention vector matrix. The two-dimensional dual attention vector matrix is decoded, so as to realize the use of two-dimensional dual attention to fully pay attention to the different semantics of the sentence and improve the extraction accuracy of the entity relationship extraction results.
[0048] The above description is only an overview of the technical solutions of some embodiments of this specification. In order to more clearly understand the technical means of some embodiments of this specification, they can be implemented in accordance with the contents of the specification. In order to make the above and other purposes, features and advantages of some embodiments of this specification more obvious and easy to understand, the specific implementation methods of some embodiments of this specification are listed below. BRIEF DESCRIPTION OF THE DRAWINGS
[0049] In order to more clearly illustrate some embodiments of this specification or technical solutions in the prior art, the following briefly introduces the drawings required for the embodiments or prior art descriptions. Obviously, the drawings described below are only some embodiments recorded in this specification. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative labor. In the drawings:
[0050] Figure 1 A schematic diagram of an implementation system of an entity relationship extraction method based on fusion relationship and two-dimensional attention in some embodiments of this specification is shown;
[0051] Figure 2A flowchart of an entity relationship extraction method based on fusion relationship and two-dimensional attention in some embodiments of this specification is shown;
[0052] Figure 3 A schematic diagram of steps for preprocessing text to be recognized in some embodiments of this specification;
[0053] Figure 4 A schematic diagram of the steps of constructing sentence codes in some embodiments of this specification;
[0054] Figure 5 A schematic diagram of the steps of determining the fusion relationship encoding in some embodiments of this specification;
[0055] Figure 6 A schematic diagram of the structure of an entity relationship extraction device based on fusion relationship and two-dimensional attention in some embodiments of this specification;
[0056] Figure 7 This is a schematic diagram of the computer device structure provided in some embodiments of this specification.
[0057] [Description of Reference Numerals]
[0058] 101. Terminal;
[0059] 102. Server;
[0060] 601, receiving module;
[0061] 602, preprocessing module;
[0062] 603, sentence encoding module;
[0063] 604, text relation encoding module;
[0064] 605, fusion relationship encoding module;
[0065] 606, extraction module;
[0066] 702. Computer equipment;
[0067] 704, processor;
[0068] 706. Memory;
[0069] 708, driving mechanism;
[0070] 710, input / output interface;
[0071] 712. Input devices;
[0072] 714. Output devices;
[0073] 716. Presentation equipment;
[0074] 718. Graphical user interface;
[0075] 720, network interface;
[0076] 722. Communication link;
[0077] 724. Communication bus. DETAILED DESCRIPTION
[0078] In order to enable those skilled in the art to better understand the technical solutions in this specification, the technical solutions in the embodiments of this specification will be clearly and completely described below in conjunction with the drawings in some embodiments of this specification. Obviously, the described embodiments are only part of the embodiments of this specification, not all of the embodiments. Based on some embodiments in this specification, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of this specification.
[0079] It should be noted that the terms "first", "second", etc. in the specification and claims of this article 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 this article described here can be implemented in an order other than those illustrated or described here. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions, for example, a process, method, device, product or equipment that includes a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or equipment.
[0080] It should be noted that the acquisition, storage, use, and processing of data in the technical solution of this application are in compliance with the relevant provisions of relevant laws and regulations.
[0081] like Figure 1The diagram is a schematic diagram of an implementation system of an entity relationship extraction method based on fusion relationship and two-dimensional attention according to an embodiment of the present invention, which may include: a terminal 101 and a server 102. The terminal 101 and the server 102 communicate with each other through a network. The network may include a local area network (LAN), a wide area network (WAN), the Internet or a combination thereof, and is connected to a website, a user device (such as a computing device) and a back-end system. A staff member may send an entity relationship extraction request to the server 102 through the terminal 101. After receiving the entity relationship extraction request, the server 102 calls the text data to be identified in the database for calculation and processing to obtain an entity relationship extraction result, and sends the entity relationship extraction result to the terminal 101, so that the staff member processes the business according to the entity relationship extraction result.
[0082] In the embodiments of this specification, the server 102 can be an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, content distribution networks (CDN, Content Delivery Network), and big data and artificial intelligence platforms.
[0083] In an optional embodiment, the terminal 101 may include but is not limited to electronic devices such as self-service terminal devices, desktop computers, tablet computers, and laptop computers. Optionally, the operating system running on the electronic device may include but is not limited to Android system, IOS system, Linux, Windows, etc. Of course, the terminal 101 is not limited to the above-mentioned electronic devices with a certain entity, and it can also be software running in the above-mentioned electronic devices.
[0084] In addition, it should be noted that Figure 1 What is shown is only an application environment provided by the present disclosure. In actual application, multiple terminals 101 may be included, and this specification does not limit this.
[0085] Figure 2 It is a flowchart of an entity relationship extraction method based on fusion relationship and two-dimensional attention provided by an embodiment of the present invention. This specification provides method operation steps as described in the embodiment or flowchart, but may include more or fewer operation steps based on conventional or non-creative labor. The order of steps listed in the embodiment is only one way of executing the steps among many orders, and does not represent the only order of execution. When the actual system or device product is executed, it can be executed in the order or in parallel according to the method shown in the embodiment or the accompanying drawings. Specifically, Figure 2 As shown, applied to the above-mentioned server side, the method may include:
[0086] S201: Obtaining text to be recognized;
[0087] S202: Preprocessing the text to be recognized to obtain a target text;
[0088] S203: performing sentence splitting, word splitting and character segmentation on the target text respectively to obtain a sentence set, a word set and a character segmentation set, and constructing corresponding sentence codes according to the sentence set, the word set and the character segmentation set;
[0089] S204: inputting the sentence code into a pre-trained entity recognition model to identify entities, entity categories, and positions of entities in the sentence, and establishing corresponding text relationship codes according to the entities, entity categories, and positions of entities in the sentence;
[0090] S205: Determine a fusion relationship code according to the text relationship code and the word vector corresponding to the word set;
[0091] S206: Taking sentence-level entity relations as extraction dimensions, according to the fusion relationship encoding, using two-dimensional word-level attention and sentence-level attention calculation to obtain a two-dimensional dual attention vector matrix, and decoding the two-dimensional dual attention vector matrix according to a bidirectional neural network to obtain an entity relationship extraction result.
[0092] The embodiments of the present specification first automatically obtain the text to be recognized, and preprocess the text to be recognized to optimize the text to be recognized to obtain the target text, and then respectively perform sentence splitting, word splitting and character segmentation on the target text to obtain sentence sets, word sets and character segmentation sets at different levels, establish corresponding sentence codes, and input the sentence codes into a pre-trained entity recognition model to identify the entities, entity categories and positions of the entities in each sentence, so as to establish corresponding text relationship codes according to the entities, entity categories and positions of the entities in the sentence. The text relationship codes can reflect the information of the entities in the target text. If the entity relationship extraction is performed directly according to the entity recognition results, there is a problem of unavoidable error propagation, and the entity recognition and relationship are not considered. In order to extract the intrinsic connection between entities, it is necessary to fuse the text relationship encoding and the word vector corresponding to the word set to obtain the fused relationship vector, so that the fused relationship vector has the information of the intrinsic connection between entity recognition and relationship extraction. At the same time, the fusion of word vector and text relationship encoding can also reduce the possibility of erroneous propagation of entity recognition results to a certain extent, and avoid entity recognition errors caused by relationship overlap. After that, the sentence-level entity relationship is used as the extraction dimension, the fused relationship encoding is input into the decoder, and the two-dimensional word-level attention and sentence-level attention are used to calculate the two-dimensional dual attention vector matrix. The two-dimensional dual attention vector matrix is decoded, so as to realize the use of two-dimensional dual attention to fully pay attention to the different semantics of the sentence and improve the extraction accuracy of the entity relationship extraction results.
[0093] It can be understood that in some embodiments, the text to be recognized is a text in a complex entity relationship scenario, such as legal documents. There may be a variety of entity relationships and a large number of overlapping entity relationships in the text to be recognized, and each sentence may have word omissions, demonstrative pronoun replacements and other phenomena. Therefore, it is necessary to preprocess the text to be recognized and perform operations such as omission completion and reference resolution to optimize the text to be recognized and obtain the target text. Thereafter, the target text is split at different levels in turn, including sentence splitting, word splitting and character segmentation, so as to construct corresponding sentence encodings based on sentence splitting, word splitting and character segmentation, and on the basis of the sentence encoding, use the pre-trained entity recognition model to identify entities, entity categories and the position of entities in sentences.
[0094] Specifically, in some embodiments, the entity recognition model can be constructed using the Bert model and the CNN convolutional neural network. The original code obtained using Bert can ensure that the code obtained after the input sentence is processed by the Bert model contains contextual information. The code obtained after the Bert model is then connected to the CNN convolutional neural network, so that the output entity relationship information takes into account both the global and local information of the text, and quickly and accurately obtains the entity, entity category and the position of the entity in the sentence to establish the corresponding text relationship code, thereby fusing it with the word vector. It should be noted that the word vector is encoded based on a word set, and the encoding method adopts the same encoding method as that in the entity recognition model, that is, if the entity recognition model adopts Bert encoding, the word vector is also obtained using Bert encoding to simplify the encoding process without introducing a new encoding method, and the same encoding method has high compatibility and high fusion reliability.
[0095] Furthermore, in some embodiments, according to the different scopes of the extracted text, relationship extraction can be divided into sentence-level relationship extraction and corpus (chapter) level relationship extraction: sentence-level relationship extraction, also known as sentence-level relationship classification, is to determine from a sentence what kind of semantic relationship exists between two entities; corpus (chapter) level relationship extraction, this task aims to determine whether there is a certain semantic relationship between two entities without limiting the context in which the two target entities appear. The embodiment of this specification uses sentence-level entity relationship as the extraction dimension, and when decoding the fused relationship encoding using a bidirectional neural network, a two-dimensional dual attention vector matrix established by two-dimensional word-level attention and sentence-level attention is introduced. By paying attention to different semantic information at the word level and sentence level in the text, the extraction accuracy of the entity relationship extraction results is improved.
[0096] See attached Figure 3 In some embodiments, preprocessing the text to be recognized to obtain the target text may include:
[0097] S301: using regular expression matching to determine whether the text to be recognized has omissions;
[0098] S302: If there is an omission, determine the position and content of the omitted information according to the regular matching result and the omission syntactic rule, and add the omitted information to the text to be recognized to obtain a text to be recognized without omission;
[0099] S303: Based on the preset reference resolution feature, it is determined whether the text to be recognized without omissions contains a reference word;
[0100] S304: If there is no omission, judging whether there is a pronoun in the text to be recognized based on a preset reference resolution feature;
[0101] S305: If there is a pronoun, using a pre-trained pronoun recognition model, identify the antecedent corresponding to the pronoun from the text to be recognized without omissions;
[0102] S306: Using the antecedent to replace the pronoun in the text to be recognized without omission to obtain the target text.
[0103] It can be understood that in some embodiments, the text to be recognized is preprocessed to obtain the target text, which is divided into two processes: omission completion and reference resolution. Specifically, it is first necessary to use regular matching to determine whether there are omissions in the text to be recognized. Common omissions may include omitting the subject. For example, the regular expression "r'.* because.*" can be used to identify sentences that give a reason but lack a subject, such as "was punished on a certain day of a certain month of a certain year for suspected crime of such and such crime." "r'^the above facts'" can be used to identify sentences in which the subject is omitted and the subject is a sentence, thereby quickly determining whether there are omissions in the text to be recognized. If there are omissions, then according to the regular matching results and the omission syntactic rules, in the case of omissions, In the previous text, the position and content of the omitted information are determined, and the omitted information is added to the text to be recognized to obtain the text to be recognized without omission. If there is no omission, or after the omission completion process is completed, the reference resolution process is started. Based on the preset reference resolution features, it is judged whether there is a reference phenomenon in the current text. The preset reference resolution features can be "the car", "the place", etc., and the corresponding regular expressions are "r'.*the car.*", "r'.*the place.*", etc. If there is a reference phenomenon, the pre-trained reference recognition model is used to find the corresponding antecedent in the preceding text of the reference word, so as to replace the reference word, for example, replace "the car" with "a blue electric bicycle of a certain brand", and complete the reference resolution accurately and quickly.
[0104] See attached Figure 4 In some embodiments, the target text is segmented into sentences, words and characters respectively to obtain a sentence set, a word set and a character segmentation set, and a corresponding sentence encoding is constructed according to the sentence set, the word set and the character segmentation set, which may include:
[0105] S401: Segment the target text based on preset punctuation marks to obtain a sentence set;
[0106] S402: performing character segmentation on the sentence set to obtain a character segmentation set, and obtaining corresponding character codes according to the character segmentation set;
[0107] S403: Split each sentence in the sentence set into a plurality of words to obtain a corresponding word set, select an entity word from the word set corresponding to each sentence as a reference word, and construct a position code according to the relative position of the reference word of each sentence and other words in the current sentence;
[0108] S404: Concatenate the character codes and position codes to obtain a sentence code.
[0109] It can be understood that in some embodiments, the preset punctuation marks can be symbols commonly used at the end of a sentence, such as a period, a semicolon, an exclamation mark, a question mark, an ellipsis, and the like, and the target text is a sentence that uses punctuation marks in a standardized manner. Assuming that the target text is a chapter-level document data D={x1,x2,x3,…,x k}, then the sentence set S={s1,s2,s3,…,s n}, where x i Indicates the characters in the judgment document, s i It represents the i-th sentence in the judicial document. The word segmentation can be performed by using the Bert model, and the character segmentation can obtain the character encoding E wi =[E [CLS] ,E w1 ,E w2 ,…,E [SEP] ], the benchmark word can be any entity word in the word set, and the position of the benchmark word is regarded as 0. The relative position of the benchmark word is calculated for other words in the sentence, and then the relative distance is mapped into a vector form to obtain the corresponding position code Ep. Finally, the character code and the position code are concatenated as the sentence code to make the sentence code have more semantic information.
[0110] See attached Figure 5 In some embodiments, determining the fusion relationship code according to the text relationship code and the word vector corresponding to the word set may include:
[0111] S501: Calculate the cosine similarity between the text relationship code and the word vector;
[0112] S502: Establishing a corresponding cosine similarity vector according to the cosine similarity;
[0113] S503: Multiply the cosine similarity vector and the word vector to obtain the fusion relationship code.
[0114] It can be understood that, in some embodiments, the text relationship code and the word vector code corresponding to the word set are fused by the splicing method, so that the word code carries the relationship information, thereby determining the fused relationship code, and the cosine similarity between the text relationship code and the word vector is used to measure the importance of each word. Assuming that the text relationship code is k, the word vector of the i-th word in the word set is vi , then the cosine similarity is h(k,v i )=cos(k,v i ), the fusion relationship code can be calculated using the following formula:
[0115] e=[h(k,v1), h(k,v2),…, h(k,v n )]
[0116] x=[e1v1,e2v2,…,e n v n ]
[0117] Among them, e is the cosine similarity vector, h(k,v i ) is the cosine similarity, e n is the nth cosine similarity, v i is the i-th word vector, and x is the fusion relation code.
[0118] In some embodiments, the sentence-level entity relationship is used as the extraction dimension, and according to the fusion relationship encoding, a two-dimensional dual attention vector matrix is obtained by using the two-dimensional word-level attention and sentence-level attention calculation, and the two-dimensional dual attention vector matrix is decoded according to the bidirectional neural network to obtain the entity relationship extraction result, which may include:
[0119] The fusion relationship encoding is input into a bidirectional neural network with a two-dimensional attention layer, so that the two-dimensional attention layer constructs a two-dimensional word-level attention matrix based on the word-level attention, and constructs a sentence-level attention matrix based on the sentence-level attention, and uses the sentence-level attention matrix as a weighting factor, and uses the weighting factor to perform weighted summation on the two-dimensional word-level attention matrix to obtain a two-dimensional dual attention vector matrix.
[0120] The bidirectional neural network iteratively updates the network weights and network biases according to the two-dimensional dual attention vector matrix until a preset convergence condition is reached to obtain the entity relationship extraction result.
[0121] Furthermore, in some embodiments, the two-dimensional attention layer calculates a two-dimensional dual attention vector matrix using the following formula:
[0122]
[0123] Among them, h s * is the two-dimensional dual attention weight, β i is the sentence-level attention weight, X is the word-level attention weight under sentence representation, ReLU() is the activation function, ω0 is the network weight, b0 is the network bias, f is the feature of the sentence, and fFT is the feature vector of the sentence, obtained by concatenating f, H is the matrix composed of the output vectors of the bidirectional neural network, H T is the transposed matrix of H, and H=[h1,h2,h3,…,h t ], t is the sentence length, softmax() and tanh() are activation functions, w s1 、w s2 is the weight matrix, and w s1 The matrix size is da×2u, w s2 The matrix size is r ×da, da is the number of neurons in the network, and r is a hyperparameter.
[0124] It can be understood that, in some embodiments, natural language text is composed of a hierarchical structure including words, sentences, paragraphs, chapters, etc., and the entity relationship in the text generally exists in the sentence, so the embodiments of this specification mainly extract sentence-level entity relationships, so the attention mechanism is divided into a dual design of word level and sentence level. Specifically, there are many ways to calculate the attention score, including dot product, splicing, addition, etc. The attention model in this article uses dot product calculation, mainly based on the result of the vector inner product reflected in the component is the sum of the products of the same attribute components between vectors, which can be used to judge the relationship between two vectors. When the two vectors are in the same direction or the angle between them is acute, the dot product result is a positive value; when they are in opposite directions or the angle between them is obtuse, the dot product result is a negative value; the larger the inner product value, the stronger the correlation between the vectors; at the same time, the dot product operation maintains a constant level of complexity.
[0125] Furthermore, in some embodiments, the two-dimensional attention layer is actually embodied as a dual attention layer, including a two-dimensional word-level attention layer and a sentence-level attention layer. A two-dimensional matrix is used in the word-level attention mechanism to contain multiple vectors, each of which focuses on different aspects of the sentence, so as to better learn the contextual representation of entity pairs. Coupled with the sentence-level attention mechanism, the weights of each training instance are dynamically adjusted. The bidirectional neural network can be a BiLSTM model, which consists of a forward LSTM and a backward LSTM. It has powerful time series data processing capabilities and can effectively capture long-term dependencies in the sequence. Finally, the softmax classifier is used to quickly and accurately output the entity relationship extraction results.
[0126] In some embodiments, the sentence-level entity relationship is used as the extraction dimension, and according to the fusion relationship encoding, a two-dimensional dual attention vector matrix is obtained by using the two-dimensional word-level attention and sentence-level attention calculation, and the two-dimensional dual attention vector matrix is decoded according to the bidirectional neural network. After obtaining the entity relationship extraction result, it can further include:
[0127] Establishing an objective function according to the entity relationship extraction result and its corresponding actual entity relationship;
[0128] Under the constraint conditions of the objective function, optimizing the objective function to obtain the optimal solution of the objective function;
[0129] The weights and biases corresponding to the optimal solution are used as the network weights and network biases of the bidirectional neural network to optimize the bidirectional neural network.
[0130] It can be understood that, in some embodiments, after obtaining the entity relationship extraction results, the iterative update of the network weights and network biases in the bidirectional neural network is completed. Error back propagation is a key step in training neural networks. The parameters are updated by calculating the gradient of the loss function with respect to the network parameters. However, in order to avoid falling into a local optimum, an objective function can be established based on the entity relationship extraction results and the actual entity relationships corresponding to them. Under the constraints of the objective function, the objective function can be optimized using an optimization algorithm to obtain the optimal solution of the objective function. The weights and biases corresponding to the optimal solution are used as the network weights and network biases of the bidirectional neural network to optimize the bidirectional neural network.
[0131] Specifically, in some embodiments, the optimization algorithm can be a swarm intelligence optimization algorithm that obtains multiple solutions to the objective function by continuously iteratively updating in a preset high-dimensional search space, and uses each solution as the initial network weight and network bias of the bidirectional neural network. In order to save training costs, a small number of training samples are selected, and the process of training the bidirectional neural network as described in any of the above embodiments is repeated. The output value of the objective function is obtained based on the output of the trained bidirectional neural network and its corresponding actual entity relationship, so as to select the weight and bias corresponding to the optimal objective function output value (i.e., the optimal solution), and optimize the network weight and network bias of the bidirectional neural network.
[0132] Furthermore, in some embodiments, the steps of the swarm intelligence optimization algorithm may include:
[0133] Step 1: Determine the preset boundary of the population according to the constraints of the objective function; the purpose of this step is to make all individuals in the population located in the preset search space;
[0134] Step 2: Use a random function to initialize and generate one or more populations; and each population does not exceed the preset boundary;
[0135] Step 3: For each population, the randomly generated prey position is used as the input of the random number generator to calculate the individual update position according to the output of the random number generator;
[0136] Step 4: Determine whether the individual update position exceeds the preset boundary. If so, the individual update position is invalid and will not be accepted. The individual update position is recalculated until it is within the preset boundary. If it does not exceed the preset boundary, the individual update position is used to update the individual position in the population, thereby ensuring the randomness of individual updates and the ability to explore new areas.
[0137] Step 5: After completing the update of the individual position, use the adaptive t-distribution mutation strategy to perturb the individual after the updated position;
[0138] Step 6: Based on the greedy rule, calculate the individual fitness before and after the disturbance, and determine whether to use the preset hunting position optimization algorithm to update the individual position;
[0139] Step 7: Repeat the above steps to update individual positions until the number of iterations reaches a preset threshold.
[0140] It can be understood that in some embodiments, the random function and the random function can be a random function, usually a random function within [0,1]. For each population, the randomly generated prey position is used as the input of the random number generator to calculate the individual update position according to the output result of the random number generator. The following formula can be used to achieve this:
[0141]
[0142] Among them, x i,j 'Update the position of the individual, x i,j is the individual position before updating, rand is the random number generator, P j is the position of the j-th dimension prey, I is a coefficient, which is usually randomly selected between 1 and 2, and F p is the objective function value after updating the individual position, F i is the objective function value of the ith individual.
[0143] Further, in some embodiments, individual fitness can be understood as the objective function value of the individual, which can be calculated using the mean square error between the actual value and the predicted value, etc., which will not be elaborated here. The greedy rule always tends to select the individual position with better individual fitness. The adaptive t distribution mutation strategy can satisfy the global search in the early stage of the algorithm and the local search in the later stage, so as to achieve convergence, which can be constructed using the following formula:
[0144] x l,t= x l+ x l ×t(m)
[0145] Among them, x l,t is the individual position after interference, x lis the position of the lth individual, m is the number of iterations, and t(m) is the t distribution with the number of iterations as the degree of freedom.
[0146] The preset hunting algorithm can enhance the local search and development capabilities of individuals and prevent the optimal solution from falling into the local optimum. It can be constructed using the following formula:
[0147] x i,j ''=x i,j +R×(1-t / T)×(2rand-1)×x i,j
[0148] Among them, x i,j '' is the updated individual position, x i,j is the individual position before updating, R is a constant coefficient, usually 0.2, is, t is the number of iterations, T is the maximum number of iterations, and rand is a random function. Further, in some embodiments, after the updated individual position is calculated using the hunting algorithm, it can also be determined whether the updated individual position exceeds the preset boundary. If it exceeds, the updated individual position is invalid and not accepted. The updated individual position is recalculated until the updated individual position is within the preset boundary. If it does not exceed the preset boundary, the updated individual position is used to update the individual position in the population.
[0149] It should be noted that, although the operations of the method of the present invention are described in a specific order in the above embodiments and the accompanying drawings, this does not require or imply that the operations must be performed in the specific order, or that all the operations shown must be performed to achieve the desired results. Additionally or alternatively, some steps may be omitted, multiple steps may be combined into one step, and / or one step may be decomposed into multiple steps.
[0150] Corresponding to the above-mentioned entity relationship extraction method based on fusion relationship and two-dimensional attention, some embodiments of this specification also provide an entity relationship extraction device based on fusion relationship and two-dimensional attention, referring to Figure 6 As shown, in some embodiments, the apparatus may include:
[0151] Receiving module 601, used to obtain the text to be recognized;
[0152] A preprocessing module 602 is used to preprocess the text to be recognized to obtain a target text;
[0153] The sentence encoding module 603 is used to perform sentence splitting, word splitting and character segmentation on the target text respectively, obtain a sentence set, a word set and a character segmentation set, and construct corresponding sentence encoding according to the sentence set, the word set and the character segmentation set;
[0154] A text relationship encoding module 604 is used to input the sentence encoding into a pre-trained entity recognition model, identify entities, entity categories and positions of entities in the sentence, and establish corresponding text relationship encoding according to the entities, entity categories and positions of entities in the sentence;
[0155] A fusion relationship coding module 605 is used to determine a fusion relationship coding according to the text relationship coding and the word vector corresponding to the word set;
[0156] The extraction module 606 is used to use sentence-level entity relations as extraction dimensions, and according to the fusion relationship encoding, use two-dimensional word-level attention and sentence-level attention to calculate a two-dimensional dual attention vector matrix, and decode the two-dimensional dual attention vector matrix according to a bidirectional neural network to obtain an entity relationship extraction result.
[0157] For the convenience of description, the above device is described in various units according to their functions. Of course, when implementing this specification, the functions of each unit can be implemented in the same or multiple software and / or hardware.
[0158] It should be noted that in the embodiments of this specification, the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved are all information and data authorized by the user and fully authorized by all parties.
[0159] It should be noted that the computer program product described in this specification (this application) is a software product that mainly implements the method described in this specification (this application) through a computer program.
[0160] The embodiments of this specification also provide a computer device. Figure 7As shown, in some embodiments of the present specification, the computer device 702 may include one or more processors 704, such as one or more central processing units (CPUs) or graphics processing units (GPUs), and each processing unit may implement one or more hardware threads. The computer device 702 may also include any memory 706, which is used to store any kind of information such as code, settings, data, etc. In a specific embodiment, the computer program on the memory 706 and can be run on the processor 704, when the computer program is run by the processor 704, the instructions of the method described in any of the above embodiments may be executed. Non-limiting, for example, the memory 706 may include any one or more combinations of the following: any type of RAM, any type of ROM, flash memory device, hard disk, optical disk, etc. More generally, any memory may use any technology to store information. Further, any memory may provide volatile or non-volatile retention of information. Further, any memory may represent a fixed or removable component of the computer device 702. In one case, when the processor 704 executes an associated instruction stored in any memory or a combination of memories, the computer device 702 may perform any operation of the associated instruction. The computer device 702 also includes one or more drive mechanisms 708 for interacting with any storage, such as a hard disk drive mechanism, an optical disk drive mechanism, etc.
[0161] The computer device 702 may also include an input / output interface 710 (I / O) for receiving various inputs (via input devices 712) and for providing various outputs (via output devices 714). A specific output mechanism may include a presentation device 716 and an associated graphical user interface 718 (GUI). In other embodiments, the input / output interface 710 (I / O), input device 712, and output device 714 may not be included, and the computer device 702 may be used as a computer device in a network. The computer device 702 may also include one or more network interfaces 720 for exchanging data with other devices via one or more communication links 722. One or more communication buses 724 couple the components described above together.
[0162] The communication link 722 may be implemented in any manner, for example, through a local area network, a wide area network (e.g., the Internet), a point-to-point connection, etc., or any combination thereof. The communication link 722 may include any combination of hardwired links, wireless links, routers, gateway functions, name servers, etc. governed by any protocol or combination of protocols.
[0163] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), computer-readable storage media, and computer program products of some embodiments of the present specification. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processor to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processor generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0164] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processor to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture including an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0165] These computer program instructions can also be loaded onto a computer or other programmable data processor so that a series of operational steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for executing on the computer or other programmable device to implement the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0166] In a typical configuration, a computer device includes one or more processors (CPU), input / output interfaces, network interfaces, and memory.
[0167] The memory may include non-permanent storage in a computer-readable medium, random access memory (RAM) and / or non-volatile memory in the form of read-only memory (ROM) or flash RAM. The memory is an example of a computer-readable medium.
[0168] Computer-readable media include permanent and non-permanent, removable and non-removable media that can be used to store information by any method or technology. Information can be computer-readable instructions, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disk read-only memory (CD-ROM), digital versatile disk (DVD) or other optical storage, magnetic cassettes, disk storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computer device. As defined in this specification, computer-readable media does not include temporary computer-readable media (transitory media), such as modulated data signals and carrier waves.
[0169] Those skilled in the art will appreciate that the embodiments of this specification may be provided as methods, systems or computer program products. Therefore, the embodiments of this specification may take the form of a complete hardware embodiment, a complete software embodiment or an embodiment combining software and hardware. Moreover, the embodiments of this specification may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program codes.
[0170] The present specification embodiments may be described in the general context of computer-executable instructions executed by a computer, such as program modules. Generally, program modules include routines, programs, objects, components, data structures, etc. that perform specific tasks or implement specific abstract data types. The present specification embodiments may also be practiced in distributed computing environments where tasks are performed by remote processors connected through a communication network. In a distributed computing environment, program modules may be located in local and remote computer storage media, including storage devices.
[0171] It should also be understood that in the embodiments of this specification, the term "and / or" is only a description of the association relationship of the associated objects, indicating that three relationships may exist. For example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone. In addition, the character " / " in this article generally indicates that the associated objects before and after are in an "or" relationship.
[0172] Each embodiment in this specification is described in a progressive manner, and the same or similar parts between the embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the system embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.
[0173] In the description of this specification, the description with reference to the terms "one embodiment", "some embodiments", "example", "specific example", or "some examples" etc. means that the specific features, structures, materials or characteristics described in conjunction with the embodiment or example are included in at least one embodiment or example of the embodiments of this specification. In this specification, the schematic representations of the above terms do not necessarily refer to the same embodiment or example. Moreover, the specific features, structures, materials or characteristics described may be combined in any one or more embodiments or examples in a suitable manner. In addition, those skilled in the art may combine and combine the different embodiments or examples described in this specification and the features of the different embodiments or examples, without contradiction.
[0174] The above is only an embodiment of the present application and is not intended to limit the present application. For those skilled in the art, the present application may have various changes and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application should be included in the scope of the claims of the present application.
Claims
1. A method for entity relationship extraction based on fusion relationship and two-dimensional attention, characterized in that: The method comprises: Get the text to be recognized; Preprocessing the text to be recognized to obtain a target text; The target text is respectively segmented into sentences, words and characters to obtain a sentence set, a word set and a character segmentation set, and a corresponding sentence encoding is constructed according to the sentence set, the word set and the character segmentation set; Inputting the sentence encoding into a pre-trained entity recognition model to identify entities, entity categories, and positions of entities in the sentence, and establishing corresponding text relationship encodings according to the entities, entity categories, and positions of entities in the sentence; Determining the fusion relationship code according to the text relationship code and the word vector corresponding to the word set includes: Calculating the cosine similarity between the text relation encoding and the word vector; Establishing a corresponding cosine similarity vector according to the cosine similarity; Multiplying the cosine similarity vector by the word vector to obtain the fusion relationship code; Taking sentence-level entity relations as extraction dimensions, according to the fusion relation encoding, two-dimensional word-level attention and sentence-level attention are used to calculate a two-dimensional dual attention vector matrix, and the two-dimensional dual attention vector matrix is decoded according to a bidirectional neural network to obtain an entity relation extraction result, including: The fusion relationship encoding is input into a bidirectional neural network with a two-dimensional attention layer, so that the two-dimensional attention layer constructs a two-dimensional word-level attention matrix based on the word-level attention, and constructs a sentence-level attention matrix based on the sentence-level attention, and uses the sentence-level attention matrix as a weighting factor, and uses the weighting factor to perform weighted summation on the two-dimensional word-level attention matrix to obtain a two-dimensional dual attention vector matrix. The bidirectional neural network iteratively updates the network weights and network biases according to the two-dimensional dual attention vector matrix until a preset convergence condition is reached to obtain the entity relationship extraction result; The two-dimensional attention layer uses the following formula to calculate the two-dimensional dual attention vector matrix: ; Among them, h s * is the vector matrix representation of two-dimensional dual attention, β i is the sentence-level attention weight, X is the word-level attention vector matrix under sentence representation, ReLU() is the activation function, ω0 is the network weight, b0 is the network bias, f is the feature of the sentence, and f FT is the feature vector of the sentence, obtained by concatenating f, H is the matrix composed of the output vectors of the bidirectional neural network, H T is the transposed matrix of H, and H=[h1,h2,h3,…,h t ], t is the sentence length, softmax() and tanh() are activation functions, w s1 、w s2 is the weight matrix, and w s1 The matrix size is da×2u, w s2 The matrix size is r ×da, da is the number of neurons in the network, and r is a hyperparameter.
2. The method according to claim 1, characterized in that: Preprocessing the text to be recognized to obtain a target text includes: Using regular expression matching, determining whether the text to be recognized has omissions; If there is an omission, the position and content of the omitted information are determined according to the regular matching result and the omission syntactic rule, and the omitted information is added to the text to be recognized to obtain the text to be recognized without omission; Based on the preset reference resolution feature, determining whether the text to be recognized without omissions contains a reference word; If there is no omission, judging whether there is a pronoun in the text to be recognized based on the preset reference resolution feature; If there is a pronoun, a pre-trained pronoun recognition model is used to identify the antecedent corresponding to the pronoun from the text to be recognized without omissions; The antecedent is used to replace the pronoun in the text to be recognized without omission to obtain the target text.
3. The method according to claim 1, characterized in that The target text is respectively subjected to sentence splitting, word splitting and character segmentation to obtain a sentence set, a word set and a character segmentation set, and a corresponding sentence encoding is constructed according to the sentence set, the word set and the character segmentation set, including: Segmenting the target text based on preset punctuation marks to obtain a sentence set; Performing character segmentation on the sentence set to obtain a character segmentation set, and obtaining corresponding character codes according to the character segmentation set; Splitting each sentence in the sentence set into a plurality of words to obtain a corresponding word set, and selecting an entity word from the word set corresponding to each sentence as a reference word, and constructing a positional encoding according to the relative position of the reference word of each sentence and other words in the current sentence; The character codes and position codes are concatenated to obtain a sentence code.
4. The method according to claim 1, characterized in that: Taking sentence-level entity relations as extraction dimensions, according to the fusion relation encoding, using two-dimensional word-level attention and sentence-level attention calculation to obtain a two-dimensional dual attention vector matrix, and decoding the two-dimensional dual attention vector matrix according to a bidirectional neural network to obtain the entity relation extraction result, further comprising: Establishing an objective function according to the entity relationship extraction result and its corresponding actual entity relationship; Under the constraint conditions of the objective function, optimizing the objective function to obtain the optimal solution of the objective function; The weights and biases corresponding to the optimal solution are used as the network weights and network biases of the bidirectional neural network to optimize the bidirectional neural network.
5. An entity relationship extraction device based on fusion relationship and two-dimensional attention, characterized in that: The device comprises: A receiving module, used for obtaining the text to be recognized; A preprocessing module, used for preprocessing the text to be recognized to obtain a target text; A sentence encoding module, used for performing sentence splitting, word splitting and character segmentation on the target text respectively, obtaining a sentence set, a word set and a character segmentation set, and constructing corresponding sentence encoding according to the sentence set, the word set and the character segmentation set; A text relation encoding module, used to input the sentence encoding into a pre-trained entity recognition model, identify entities, entity categories and positions of entities in sentences, and establish corresponding text relation encodings according to the entities, entity categories and positions of entities in sentences; The fusion relationship coding module is used to determine the fusion relationship coding according to the text relationship coding and the word vector corresponding to the word set, including: Calculating the cosine similarity between the text relation encoding and the word vector; Establishing a corresponding cosine similarity vector according to the cosine similarity; Multiplying the cosine similarity vector by the word vector to obtain the fusion relationship code; The extraction module is used to use the sentence-level entity relationship as the extraction dimension, and according to the fusion relationship encoding, use the two-dimensional word-level attention and sentence-level attention to calculate a two-dimensional dual attention vector matrix, and decode the two-dimensional dual attention vector matrix according to the bidirectional neural network to obtain the entity relationship extraction result, including: The fusion relationship encoding is input into a bidirectional neural network with a two-dimensional attention layer, so that the two-dimensional attention layer constructs a two-dimensional word-level attention matrix based on the word-level attention, and constructs a sentence-level attention matrix based on the sentence-level attention, and uses the sentence-level attention matrix as a weighting factor, and uses the weighting factor to perform weighted summation on the two-dimensional word-level attention matrix to obtain a two-dimensional dual attention vector matrix. The bidirectional neural network iteratively updates the network weights and network biases according to the two-dimensional dual attention vector matrix until a preset convergence condition is reached to obtain the entity relationship extraction result; The two-dimensional attention layer uses the following formula to calculate the two-dimensional dual attention vector matrix: ; Among them, h s * is the vector matrix representation of two-dimensional dual attention, β i is the sentence-level attention weight, X is the word-level attention vector matrix under sentence representation, ReLU() is the activation function, ω0 is the network weight, b0 is the network bias, f is the feature of the sentence, and f FT is the feature vector of the sentence, obtained by concatenating f, H is the matrix composed of the output vectors of the bidirectional neural network, H T is the transposed matrix of H, and H=[h1,h2,h3,…,h t ], t is the sentence length, softmax() and tanh() are activation functions, w s1 、w s2 is the weight matrix, and w s1 The matrix size is da×2u, w s2 The matrix size is r ×da, da is the number of neurons in the network, and r is a hyperparameter.
6. A computer device comprising a memory, a processor, and a computer program stored in the memory, characterized in that: When the computer program is executed by the processor, the computer program executes the instructions of the method according to any one of claims 1 to 4.
7. A computer storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor of a computer device, the computer program executes the instructions of the method according to any one of claims 1 to 4.
