Entity relationship extraction method and device, electronic equipment and storage medium
The text and entity relationship words are processed through the attention model, and the correlation is calculated to determine the entity relationship, which solves the problem of low accuracy and efficiency of the entity relationship extraction task in the existing technology, and achieves more efficient entity relationship extraction.
Patent Information
- Application Number
- CN202410681340.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-05-29
- Publication Date
- 2024-09-17
AI Technical Summary
The existing technology has problems with low accuracy and efficiency in entity relationship extraction tasks. The low coupling degree of the pipeline-based method leads to an expansion of errors, while the joint extraction method based on the joint extraction method consumes large computing resources and has low efficiency.
The attention model is used to process the text to be processed and the target entity relationship words, the entity relationship discrimination information is generated through attention encoding, the correlation is calculated to determine the entity relationship, and the entity relationship extraction task is simplified.
It improves the accuracy and efficiency of entity relationship extraction tasks, simplifies complexity, and effectively improves the ability to identify associated relationships.
Smart Images

Figure CN118657148A
Abstract
Description
Technical Field
[0001] The present invention relates to the field of artificial intelligence technology, and in particular to an entity relationship extraction method, device, electronic device and storage medium. Background Art
[0002] Entity Relation Extraction is an important task in Natural Language Processing (NLP), which aims to identify entities (e.g., names of people, places, organizations, etc.) and the relationships between these entities (e.g., "place of birth", "occupation", "spouse", etc.) from text. Among the related technologies, pipeline-based relation extraction technology and joint extraction-based relation extraction technology are the two dominant methods in entity relation extraction tasks.
[0003] In the pipeline-based relation extraction technology, the entity relationship extraction task is divided into two parts: the named entity recognition task and the relationship extraction task. Since a complex task is divided into two relatively simple tasks, the pipeline-based relation extraction technology has the advantages of simple implementation and flexibility, but it also has many problems. For example, errors in the named entity recognition task will be passed to the relationship extraction module, causing the error to further expand, and due to the low coupling between the two modules, the accuracy and recall rate of the model in executing the entity relationship extraction task are low.
[0004] The relation extraction technology based on joint extraction directly extracts the target triples from unstructured text, and performs named entity recognition and relationship extraction tasks at the same time. Since the relation extraction technology based on joint extraction takes into account the dependencies between entities and relationships, the model has a high accuracy in executing entity relationship extraction tasks. However, at the same time, the complexity of the model architecture is too high and the amount of data that needs to be calculated is huge. The model training and execution processes both require a lot of computing resources and are inefficient.
[0005] Therefore, how to accurately and efficiently perform entity relationship extraction tasks is a technical problem that needs to be solved urgently. Summary of the invention
[0006] In view of the problems existing in the prior art, the present invention provides an entity relationship extraction method, device, electronic device and storage medium for accurately and efficiently performing entity relationship extraction tasks.
[0007] The present invention provides an entity relationship extraction method, comprising the following steps.
[0008] Determine a target first named entity and a candidate second named entity, as well as a target entity relationship word in the text to be processed; wherein the first named entity is the subject in the entity relationship to be extracted, the second named entity is the object in the entity relationship to be extracted, and the target entity relationship word is a textual representation of the entity relationship to be extracted; use an attention model to process the text to be processed and the target entity relationship word to obtain entity relationship discrimination information; wherein the entity relationship discrimination information includes first vector information obtained by attention encoding the target first named entity, second vector information obtained by attention encoding the candidate second named entity, and third vector information obtained by attention encoding the target entity relationship word ; Using the entity relationship discrimination information, obtain the first correlation between the target first named entity and the candidate second named entity in the text to be processed, the second correlation between the target first named entity and the target entity relationship word in the text to be processed, and the third correlation between the candidate second named entity and the target entity relationship word in the text to be processed; in response to the first correlation, the second correlation and the third correlation being greater than their respective corresponding preset thresholds, determine that the target first named entity and the candidate second named entity have the entity relationship to be extracted, and extract the entity relationship to be extracted between the target first named entity and the candidate second named entity from the text to be processed.
[0009] According to an entity relationship extraction method provided by the present invention, the attention model is used to process the text to be processed and the target entity relationship words to obtain entity relationship discrimination information, including: preprocessing the text to be processed and the target entity relationship words; inputting the preprocessed text to be processed and the target entity relationship words into the attention model, and using the attention model to perform the following operations: performing attention encoding on the target first named entity, and using the generated query vector and key vector as the first vector information; performing attention encoding on the candidate second named entity, and using the generated query vector and key vector as the second vector information; performing attention encoding on the target entity relationship words, and using the generated query vector and key vector as the third vector information.
[0010] According to an entity relationship extraction method provided by the present invention, the entity relationship discrimination information is used to obtain a first correlation between the target first named entity and the candidate second named entity in the text to be processed, a second correlation between the target first named entity and the target entity relationship word in the text to be processed, and a third correlation between the candidate second named entity and the target entity relationship word in the text to be processed, including: using the query vector of the target first named entity and the key vector of the candidate second named entity to obtain the first correlation; using the query vector of the target first named entity and the key vector of the target entity relationship word to obtain the second correlation; using the query vector of the candidate second named entity and the key vector of the target entity relationship word to obtain the third correlation.
[0011] According to an entity relationship extraction method provided by the present invention, the first degree of association is obtained by using the query vector of the target first named entity and the key vector of the candidate second named entity, including: obtaining a first result by using the dot product operation between the query vector of the target first named entity and the key vector of the candidate second named entity; processing the first result by using an activation function to obtain the first degree of association; the second degree of association is obtained by using the query vector of the target first named entity and the key vector of the target entity relationship word, including: obtaining a second result by using the dot product operation between the query vector of the target first named entity and the key vector of the target entity relationship word; processing the second result by using an activation function to obtain the second degree of association; the third degree of association is obtained by using the query vector of the candidate second named entity and the key vector of the target entity relationship word, including: obtaining a third result by using the dot product operation between the query vector of the candidate second named entity and the key vector of the target entity relationship word; processing the third result by using an activation function to obtain the third degree of association.
[0012] According to an entity relationship extraction method provided by the present invention, the text to be processed contains at least one first named entity and at least one second named entity; determining the target first named entity and candidate second named entities, as well as the target entity relationship word in the text to be processed, includes: obtaining at least one preset entity relationship word; wherein each of the at least one preset entity relationship word is a textual representation of a type of entity relationship; constructing a named entity relationship table according to the at least one preset entity relationship word, the at least one first named entity and the at least one second named entity; and selecting a first named entity, a second named entity and an entity relationship word from the named entity relationship table by enumeration, as the target first named entity, the candidate second named entity and the target entity relationship word, respectively.
[0013] According to an entity relationship extraction method provided by the present invention, the method also includes: performing the following preprocessing on the text to be processed: performing word segmentation processing on the text to be processed to obtain a first word segmentation sequence; splicing the at least one preset entity relationship word with the first word segmentation sequence to obtain a second word segmentation sequence; using a feature extraction model to process the second word segmentation sequence to obtain a vector sequence composed of embedded vectors of each word segment in the second word segmentation sequence, using the vector sequence as an input of the attention model, and identifying the first named entity and the second named entity in the text to be processed; constructing a named entity relationship table based on the at least one preset entity relationship word, the at least one first named entity and the at least one second named entity, including: constructing the named entity relationship table based on the embedded vector of the at least one first named entity obtained by using the feature extraction model, the embedded vector of the at least one second named entity, and the embedded vector of the at least one preset entity relationship word.
[0014] The present invention also provides an entity relationship extraction device, comprising the following modules: a first acquisition module, used to determine a target first named entity and a candidate second named entity, as well as a target entity relationship word in a text to be processed; wherein the first named entity is the subject in the entity relationship to be extracted, the second named entity is the object in the entity relationship to be extracted, and the target entity relationship word is a textual representation of the entity relationship to be extracted; a second acquisition module, used to process the text to be processed and the target entity relationship word using an attention model to obtain entity relationship discrimination information; wherein the entity relationship discrimination information includes first vector information obtained by attention encoding the target first named entity, second vector information obtained by attention encoding the candidate second named entity, and The third vector information obtained by the intention encoding; a third acquisition module, used to use the entity relationship discrimination information to obtain the first correlation between the target first named entity and the candidate second named entity in the text to be processed, the second correlation between the target first named entity and the target entity relationship word in the text to be processed, and the third correlation between the candidate second named entity and the target entity relationship word in the text to be processed; an extraction module, used to determine that the target first named entity and the candidate second named entity have the entity relationship to be extracted in response to the first correlation, the second correlation and the third correlation being greater than their respective corresponding preset thresholds, and extract the entity relationship to be extracted between the target first named entity and the candidate second named entity from the text to be processed.
[0015] The present invention also provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, any of the entity relationship extraction methods described above is implemented.
[0016] The present invention also provides a non-transitory computer-readable storage medium on which a computer program is stored. When the computer program is executed by a processor, the entity relationship extraction method as described above is implemented.
[0017] The present invention also provides a computer program product, comprising a computer program, wherein when the computer program is executed by a processor, the entity relationship extraction method as described above is implemented.
[0018] The entity relationship extraction method provided by the present invention uses an attention model to process the text to be processed and the target entity relationship words to obtain entity relationship discrimination information; then uses the entity relationship discrimination information to solve three binary classification problems: whether there is an association relationship between the target first named entity and the candidate second named entity, whether there is an association relationship between the target first named entity and the target entity relationship words, and whether there is an association relationship between the target entity relationship words and the candidate second named entity. Since the complex entity relationship extraction task is simplified, the execution efficiency of the entity relationship extraction task can be effectively improved.
[0019] The entity relationship extraction method provided by the present invention extracts the entity relationship to be extracted between the target first named entity and the candidate second named entity from the text to be processed when the first correlation degree, the second correlation degree and the third correlation degree are used to determine that the above three correlation relationships all exist, thereby effectively improving the accuracy of the entity relationship extraction task. BRIEF DESCRIPTION OF THE DRAWINGS
[0020] In order to more clearly illustrate the technical solutions in the present invention or the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0021] Figure 1 It is a flow chart of the entity relationship extraction method provided by the present invention.
[0022] Figure 2 It is a flowchart of a method for obtaining the first correlation degree, the second correlation degree and the third correlation degree provided by the present invention.
[0023] Figure 3 It is a flow chart of a method for determining a target first named entity and a candidate second named entity, as well as a target entity relationship word in a text to be processed, provided by the present invention.
[0024] Figure 4 It is a flowchart of the training method of the entity relationship extraction model provided by the present invention.
[0025] Figure 5 It is a schematic diagram of the named entity relationship table provided by the present invention.
[0026] Figure 6 It is a schematic diagram of the data processing process of the entity relationship extraction method provided by the present invention.
[0027] Figure 7 It is a structural schematic diagram of the entity relationship extraction device provided by the present invention.
[0028] Figure 8 It is a structural schematic diagram of the electronic device provided by the present invention. DETAILED DESCRIPTION
[0029] In order to make the purpose, technical solution and advantages of the present invention clearer, the technical solution of the present invention will be clearly and completely described below in conjunction with the drawings of the present invention. Obviously, the described embodiments are 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 are within the scope of protection of the present invention.
[0030] Combine the following Figure 1-Figure 6 The entity relationship extraction method of the present invention is described.
[0031] Figure 1 It is a flow chart of the entity relationship extraction method provided by the present invention, such as Figure 1 As shown, the method includes the following steps 101, 102, 103 and 104.
[0032] Step 101: Determine a target first named entity and candidate second named entities, as well as target entity relationship words in a text to be processed.
[0033] The text to be processed contains at least one first named entity and at least one second named entity. In the entity relationship extraction task, an entity relationship usually includes three components: subject, relationship and object. The first named entity is the subject in the entity relationship to be extracted. The second named entity is the object in the entity relationship to be extracted. The target entity relationship word is the textual representation of the entity relationship to be extracted. For example, the entity relationship is the association relationship between a person and a geographical location, the first named entity is the person in the text to be processed, the second named entity is the geographical location in the text to be processed, and the target entity relationship word is one of "birth", "travel", "residence" and "visited". For another example, the entity relationship is the association relationship between a user and a product, the first named entity is the user in the text to be processed, the second named entity is the product in the text to be processed, and the target entity relationship word is one of "purchase", "focus" and "use".
[0034] The target first named entity is the first named entity that needs to be extracted from the to-be-processed text in the current operation. The candidate second named entity is the second named entity selected from the to-be-processed text in the current operation and to be confirmed whether it has a target entity relationship with the target first named entity.
[0035] Just as an example, the text to be processed is "Li Si welcomes me to Beijing", in which "I" can be used as the target first named entity and "Beijing" can be used as the candidate second named entity.
[0036] In the specific implementation process, the target first named entity and the candidate second named entity can be determined from the text to be processed in a variety of ways, and the target entity relationship words can be determined, which are not limited to the description of this specification. For example, in the case where only one first named entity needs to be extracted, it can be used as the target first named entity, and one of the preset entity relationship words can be selected one by one as the target entity relationship word, and combined with the second named entity in the text to be processed, and a candidate second named entity is determined each time.
[0037] In some embodiments, the text to be processed may contain multiple first named entities or multiple second named entities, and the entity relationship to be extracted may also be one of multiple entity relationships. Figure 3 In the illustrated embodiment, a target first named entity, a candidate second named entity, and a target entity relation word are obtained from the text to be processed, which will not be described in detail here.
[0038] Step 102: Use the attention model to process the text to be processed and the target entity relationship words to obtain entity relationship discrimination information.
[0039] The entity relationship discrimination information is information used to discriminate the association between the target first named entity and the candidate second named entity, the association between the target first named entity and the target entity relationship word, and the association between the candidate second named entity and the target entity relationship word in the text to be processed. In some embodiments, the entity relationship discrimination information includes first vector information obtained by attention encoding the target first named entity, second vector information obtained by attention encoding the candidate second named entity, and third vector information obtained by attention encoding the target entity relationship word.
[0040] In the specific implementation process, the preprocessed text to be processed and the target entity relationship words can be input into the attention model, and the attention model can be used to perform the following operations: attention encoding is performed on the target first named entity, and the generated query vector and key vector are used as the first vector information; attention encoding is performed on the candidate second named entity, and the generated query vector and key vector are used as the second vector information; attention encoding is performed on the target entity relationship words, and the generated query vector and key vector are used as the third vector information.
[0041] In the specific implementation process, for different attention models, the text to be processed and the target entity relationship words can be preprocessed accordingly, which is not limited by the description of this specification.
[0042] As an example only, the following preprocessing is performed on the text to be processed.
[0043] The text to be processed is segmented to obtain the first segmentation sequence. For example, "Li Si welcomes me to Beijing" is segmented into the first segmentation sequence: "Li Si", "welcome", "I", "come", "Beijing".
[0044] At least one preset entity relationship word is concatenated with the first segmentation sequence to obtain a second segmentation sequence. For example, a set of preset entity relationship words "birth", "travel", "residence", "visited" can be concatenated with the first segmentation sequence: "Li Si", "welcome", "I", "come", "Beijing".
[0045] The second word segmentation sequence is processed using the feature extraction model to obtain a vector sequence consisting of the embedded vectors of each word segmentation in the second word segmentation sequence, and the vector sequence is used as the input of the attention model. In the specific implementation process, a variety of feature extraction models can be used to perform this step, which is not limited by the description of this specification. For example, the feature extraction model can be a BERT model (Bidirectional Encoder Representations from Transformers, based on Transformer bidirectional encoder representation) and the like.
[0046] In some embodiments, a RoBERTa (Robustly optimized BERT approach) pre-trained model can be used as a feature extraction model. The RoBERTa pre-trained model has made the following improvements on the basis of the BERT model: 1) Introducing a dynamic masking strategy. During the training process, BERT uses a static masking strategy, that is, the masking strategy of each epoch is the same, which easily leads to an aggravation of the overfitting problem of the model, while the dynamic masking strategy is that the masking strategy adopted by each input model is different, so that the generalization ability of the model is enhanced and the overfitting phenomenon of the model is alleviated. 2) Remove the next sentence prediction task. In the original BERT training process, BERT needs to predict whether the two sentences before and after are continuous, but according to subsequent research and analysis, it is known that this task often brings large errors to downstream tasks, making the model unable to learn the semantic content of the text well, so RoBERTa chooses to remove the next sentence prediction task in the original BERT. Because the above improvements effectively improve the generalization ability and performance of the RoBERTa model. The embodiment of the present invention utilizes a feature extraction model to learn the grammatical structure and semantic information of the text to be processed and the text after the concatenation of at least one preset entity relationship word, and converts the text that cannot be understood by the computer into a low-dimensional embedded vector representation that can be understood by the computer; at the same time, the feature extraction model can convert the text to be processed and at least one preset entity relationship word into the same vector space, better utilize context information, and help the attention model used in subsequent processing steps to learn the heterogeneous representations and correlations between named entities and entity relationships.
[0047] In the specific implementation process, in the process of using the feature extraction model to process the second word segmentation sequence and obtain a vector sequence composed of the embedded vectors of each word segmentation in the second word segmentation sequence, the pre-trained feature extraction model can simultaneously identify the first named entity and the second named entity in the text to be processed. The feature extraction model can be trained by a common training method, which will not be repeated here.
[0048] In the specific implementation process, a variety of attention models can be used to process the text to be processed and the target entity relationship words to obtain entity relationship discrimination information. For example, the attention model can be Transformer, T5 (Text-to-Text Transfer Transformer), and a custom attention model. In some embodiments, a multi-head attention computing network can be used to implement the Transformer, and a large number of Transformers can be stacked to construct an attention model.
[0049] Transformer is a deep learning model for natural language processing and other sequence-to-sequence learning tasks. The main feature of Transformer is the use of a self-attention mechanism, which enables the model to better capture long-range dependencies when processing sequence data. This self-attention mechanism allows the model to focus on different parts of the input sequence at each time step, and can easily process the entire sequence in parallel, thereby improving the training speed and efficiency of the model. The Transformer model consists of an encoder and a decoder. The encoder is responsible for converting the input sequence into a series of hidden representations, while the decoder converts these hidden representations into an output sequence. During training, Transformer optimizes the model parameters by minimizing the loss function, enabling it to learn the mapping relationship between the input sequence and the output sequence.
[0050] Just as an example, the input data for the attention model is shown below.
[0051] E = Concat(T s , T r ) (1) Among them, T s To segment the text to be processed and embed the processed vector sequence, T r is a vector sequence of at least one preset entity relationship word after embedding processing, and E is the overall input of the attention model.
[0052] The processing after E is input into the attention model is as follows: Among them, the i-th multi-head attention calculation network queries the vector matrix Multiply it with E to generate the query vector Q i (including each input query vector q i ), key vector matrix Multiply with E to generate the key vector K i (including each input key vector k i ), value vector matrix Multiply with E to generate value vector V i (including each input value vector v i ), and finally the query vector Q i With the key vector K i Multiply and normalize through the softmax function to convert it into a probability distribution, so that the multi-head attention network can focus on different positions in the input, and then compare it with the value vector V i Multiply them together to get the output of the multi-head attention calculation network.
[0053] In the embodiment of the present invention, the query vector Q output from the last layer Transformer is i and the key vector K i Obtain entity relationship discrimination information.
[0054] In an embodiment of the present invention, an attention model is used to mine the association relationship between the first named entity, the second named entity and the preset entity relationship word in the same vector space to obtain entity relationship discrimination information with high accuracy. The entity relationship discrimination information can be subsequently used to accurately calculate the association between two data (for example, the target first named entity and the candidate second named entity) in the data pair (for example, the data pair consisting of the target first named entity and the candidate second named entity) obtained by combining the target first named entity, the candidate second named entity and the target entity relationship word in pairs, thereby obtaining accurate entity relationship extraction results.
[0055] Step 103, using the entity relationship discrimination information, obtain the first correlation between the target first named entity and the candidate second named entity in the text to be processed, the second correlation between the target first named entity and the target entity relationship word in the text to be processed, and the third correlation between the candidate second named entity and the target entity relationship word in the text to be processed.
[0056] In order to effectively reduce the complexity of the entity relationship extraction task, the embodiment of the present invention converts the entity relationship extraction task into three binary classification subtasks.
[0057] The first subtask is whether there is an association relationship between the first named entity and the second named entity. If the main entity and the object entity have an association relationship, then the object entity and the main entity must also have an association relationship. Therefore, the association relationship between the first named entity and the second named entity is bidirectionally symmetrical, without considering the subject-object relationship, and can be expressed as the following logical expression.
[0058] Among them, e a Belongs to the first named entity, e b belongs to the second named entity, r is a predefined entity relationship, T represents a triple, i.e., the first named entity e a With the second named entity e b There is an entity relationship r, or the first named entity e b With the second named entity e a If there is an entity relationship r, then the first named entity e a With the second named entity e b There is a correlation, I(e a , e b ) is true.
[0059] The other two subtasks are about whether there is an association relationship between the named entity and the predefined entity relationship. Since the relationship between the named entity and the entity is not bidirectionally symmetrical but unidirectionally asymmetric, for example, for the triple (I, been, Beijing), the relationship between the named entity and the entity can only be "I->been", but not "Beijing->been". Therefore, it is divided into two subtasks: whether there is an association relationship between the first named entity and the predefined entity relationship and whether there is an association relationship between the second named entity and the predefined entity relationship, as shown in logical expressions (7) and (8) respectively.
[0060] In summary, if the above three subtasks are all true, the target triplet can be extracted from the text to be processed, otherwise the target triplet cannot be extracted, which can be expressed as the following logical expression.
[0061] In some embodiments, the above three types of subtasks can be performed by calculating the first degree of association, the second degree of association and the third degree of association using the first vector information, the second vector information and the third vector information included in the entity relationship determination information obtained in step 102 .
[0062] In the specific implementation process, the first degree of association can be obtained by the operation between the first vector information and the second vector information; the second degree of association can be obtained by the operation between the first vector information and the third vector information; and the third degree of association can be obtained by the operation between the second vector information and the third vector information. For example, the first degree of association can be obtained by the operation between the query vector contained in the first vector information and the key vector contained in the second vector information, or the first degree of association can be obtained by the operation between the key vector contained in the first vector information and the query vector contained in the second vector information. For another example, the second degree of association can be obtained by the operation between the query vector contained in the first vector information and the key vector contained in the third vector information, or the second degree of association can be obtained by the operation between the key vector contained in the first vector information and the query vector contained in the third vector information. For another example, the third degree of association can be obtained by the operation between the query vector contained in the second vector information and the key vector contained in the third vector information, or the third degree of association can be obtained by the operation between the key vector contained in the second vector information and the query vector contained in the third vector information.
[0063] For an embodiment of obtaining the first correlation degree, the second correlation degree and the third correlation degree, see Figure 2 The relevant content in will not be repeated here.
[0064] Step 104, in response to the first degree of association, the second degree of association and the third degree of association being greater than their respective corresponding preset thresholds, it is determined that there is an entity relationship to be extracted between the target first named entity and the candidate second named entity, and the entity relationship to be extracted between the target first named entity and the candidate second named entity is extracted from the text to be processed.
[0065] During the specific implementation process, the preset thresholds corresponding to the first correlation degree, the second correlation degree and the third correlation degree may be the same or different, and are not limited by the description of this specification.
[0066] When the first degree of association, the second degree of association and the third degree of association are all greater than their respective corresponding preset thresholds, it can be determined that there is an entity relationship to be extracted between the target first named entity and the candidate second named entity, and the entity relationship to be extracted between the target first named entity and the candidate second named entity can be extracted from the text to be processed by extracting triples.
[0067] In the specific implementation process, the extracted triples are in the form of <main entity, entity relationship, object entity>. For example, for the text to be processed is "Li Si welcomes me to Beijing", when Figure 5 In the named entity relationship table shown in FIG. 1 , when the target first named entity enumerated is “I”, the candidate second named entity is “Beijing”, and the target entity relationship term is “been to”, the first relevance, the second relevance, and the third relevance obtained in step 103 are all greater than their respective corresponding preset thresholds, then the entity relationship <I, been to, Beijing> between the person and the geography is extracted from the text. For another example, for the text to be processed is “Li Si welcomes me to Beijing”, when the first relevance, the second relevance, and the third relevance obtained in step 103 are all greater than their respective corresponding preset thresholds, then the entity relationship <I, been to, Beijing> between the person and the geography is extracted from the text. Figure 5 In the named entity relationship table shown, when the target first named entity enumerated is "Li Si", the candidate second named entity is "Beijing", and the target entity relationship word is "been to", the first correlation degree and the second correlation degree obtained in step 103 are both less than their respective corresponding preset thresholds, it means that "Li Si" and "Beijing" do not have an entity relationship represented by "been to", and this operation does not extract the entity relationship from the text to be processed.
[0068] The data processing process of the entity relationship extraction method shown in the embodiment of the present invention is as follows: Figure 6As shown, the entity relationship extraction model (ULA-Rel model) in the figure includes an encoding module and an interaction module, which are respectively used to implement steps 102 to 103 in this specification: in the encoding module, the attention model is used to process the text to be processed and the target entity relationship words to obtain the step of entity relationship discrimination information (corresponding to step 102); in the interaction module, the entity relationship discrimination information is processed to obtain the first correlation between the target first named entity and the candidate second named entity in the text to be processed, the second correlation between the target first named entity and the target entity relationship word in the text to be processed, and the third correlation between the candidate second named entity and the target entity relationship word in the text to be processed (corresponding to step 103). For details about the training method of the entity relationship extraction model, see Figure 4 The relevant content in will not be repeated here.
[0069] Figure 2 is a flow chart of a method for obtaining the first correlation degree, the second correlation degree and the third correlation degree provided by the present invention, such as Figure 2 As shown, the method includes the following steps 201, 202 and 203.
[0070] Step 201: Obtain a first degree of association using a query vector of a target first named entity and a key vector of a candidate second named entity.
[0071] In a specific implementation process, a first result can be obtained by using a dot product operation between a query vector of the target first named entity and a key vector of a candidate second named entity, and an activation function is used to process the first result to obtain a first degree of association. The calculation formula is as follows.
[0072] Among them, H represents the number of heads of multi-head attention, q 1i is the query vector of the target first named entity obtained using the i-th attention head, k 1i is the key vector of the candidate second named entity obtained by the i-th attention head. In formula (10), after performing a dot multiplication operation and dimensionality reduction on the query vector of the target first named entity obtained by each attention head and the key vector of the candidate second named entity, the similarity between the query vector of the target first named entity and the key vector of the candidate second named entity corresponding to each attention head is obtained, and then the similarities corresponding to all attention heads are summed and averaged to obtain the first result, so that the focus of each attention head is equally integrated into the correlation calculation, which can effectively improve the generalization ability of the calculation result. In formula (10), the sigmoid function is used as the activation function to map the first result to between 0 and 1, and perform the classification task: the result is true if it is greater than the preset threshold, and false if it is less than the preset threshold.
[0073] In a specific implementation process, the above method can also be used to obtain the first degree of association by using the key vector of the target first named entity and the query vector of the candidate second named entity, which will not be described in detail here.
[0074] Step 202: Obtain a second degree of association using the query vector of the target first named entity and the key vector of the target entity relationship word.
[0075] In a specific implementation process, the second result can be obtained by performing a dot product operation between the query vector of the target first named entity and the key vector of the target entity relationship word, and the second result can be processed by using an activation function to obtain a second relevance. The calculation formula is as follows.
[0076] Among them, H represents the number of heads of multi-head attention, q 1i is the query vector of the target first named entity obtained using the i-th attention head, k 3i is the key vector of the target entity relationship word obtained by the i-th attention head. In formula (11), after performing a dot multiplication operation and dimensionality reduction on the query vector of the target first named entity and the key vector of the target entity relationship word obtained by each attention head, the similarity between the query vector of the target first named entity and the key vector of the target entity relationship word corresponding to each attention head is obtained, and then the similarities corresponding to all attention heads are summed and averaged to obtain the second result, so that the focus of each attention head is equally integrated into the relevance calculation, which can effectively improve the generalization ability of the calculation result. In formula (11), the sigmoid function is used as the activation function to map the second result to between 0 and 1, and perform the classification task: the result is true if it is greater than the preset threshold, and false if it is less than the preset threshold.
[0077] In the specific implementation process, the second relevance can also be obtained by using the key vector of the target first named entity and the query vector of the target entity relationship word through the above method, which will not be repeated here.
[0078] Step 203: Obtain a third degree of association using the query vector of the candidate second named entity and the key vector of the target entity relationship word.
[0079] In some embodiments, the third degree of association may be obtained using the query vector of the candidate second named entity and the key vector of the target entity relationship word.
[0080] In a specific implementation process, the third result can be obtained by using a dot product operation between the query vector of the candidate second named entity and the key vector of the target entity relationship word; and the third result can be processed using an activation function to obtain a third degree of association.
[0081] Among them, H represents the number of heads of multi-head attention, q 2i is the query vector of the candidate second named entity obtained using the i-th attention head, k 3i is the key vector of the target entity relationship word obtained by the i-th attention head. In formula (12), after performing a dot multiplication operation and dimensionality reduction on the query vector of the candidate second named entity obtained by each attention head and the key vector of the target entity relationship word, the similarity between the query vector of the candidate second named entity and the key vector of the target entity relationship word corresponding to each attention head is obtained, and then the similarities corresponding to all attention heads are summed and averaged to obtain the third result, so that the focus of each attention head is equally integrated into the relevance calculation, which can effectively improve the generalization ability of the calculation result. In formula (12), the sigmoid function is used as the activation function to map the first result to between 0 and 1, and perform the classification task: the result is true if it is greater than the preset threshold, and false if it is less than the preset threshold.
[0082] In the specific implementation process, the third degree of association can also be obtained by using the key vector of the candidate second named entity and the query vector of the target entity relationship word through the above method, which will not be repeated here.
[0083] In an embodiment of the present invention, entity relationship discrimination information is used to accurately calculate the correlation between two data (for example, the target first named entity and the candidate second named entity) in a data pair (for example, a data pair consisting of the target first named entity and the candidate second named entity) obtained by combining the target first named entity, the candidate second named entity, and the target entity relationship word in pairs, thereby effectively simplifying the complexity of the entity extraction task.
[0084] Figure 3 is a flow chart of a method for determining a target first named entity and a candidate second named entity in a text to be processed, as well as a target entity relation word, provided by the present invention. Figure 3 As shown, the method includes the following steps 301, 302 and 303.
[0085] Step 301: Obtain at least one preset entity relationship word; wherein each of the at least one preset entity relationship word is a textual representation of a type of entity relationship.
[0086] As an example only, for the task of extracting the entity relationship between a person and a geographic location, the preset entity relationship words may include "birth", "travel", "residence", "been there" and "want to go", etc. Through multiple preset entity relationship words, the geographic locations that the user may visit in the future, the locations where he has been and the current location can be effectively mined.
[0087] Step 302: construct a named entity relationship table according to at least one preset entity relationship word, at least one first named entity, and at least one second named entity.
[0088] In the specific implementation process, the named entity relationship table can be constructed in many ways. As an example, for the text to be processed in the above example, the following table can be constructed: Figure 5 The named entity relationship table shown: the named entity relationship table is obtained by taking the word segmentation of the text to be processed and a plurality of preset entity relationship words as the horizontal and vertical coordinates respectively.
[0089] In some embodiments, in order to solve the problem of matching synonyms, a named entity relationship table can be constructed based on the embedded vector of at least one first named entity obtained by using a feature extraction model, the embedded vector of at least one second named entity, and the embedded vector of at least one preset entity relationship word. For example, the entity relationship words "come" and "go" can express the same semantics, so the embedded vectors of the two are highly similar, and the computer processor can process the two as the same word.
[0090] Step 303: Select a first named entity, a second named entity, and an entity relationship word from the named entity relationship table by enumeration as the target first named entity, the candidate second named entity, and the target entity relationship word, respectively.
[0091] For example, one can Figure 5 In the named entity relationship table shown, "I" is selected as the target first named entity, "Beijing" is selected as the candidate second named entity, and "been to" is selected as the target entity relationship word.
[0092] For example, you can Figure 5 In the named entity relationship table shown, "Li Si" is selected as the target first named entity, "Beijing" is selected as the candidate second named entity, and "welcome" is selected as the target entity relationship word.
[0093] Figure 4 is a flow chart of the training method of the entity relationship extraction model provided by the present invention, such as Figure 4 As shown, the method includes the following steps 401 and 402.
[0094] Step 401: Obtain a training data set.
[0095] In a specific implementation process, the training data set may include multiple groups of sample data and a label for each group of sample data.
[0096] For different entity relationship extraction tasks, corresponding sample data can be obtained, and each set of sample data can be annotated to obtain the label of each set of sample data. As an example, for the entity relationship extraction task of people and geographic locations, multiple texts containing people and geographic locations with entity relationships can be obtained as sample data in a common way; the triple consisting of people, geographic locations and entity relationships contained in the sample data is used as the label of the sample data.
[0097] Step 402: Using the training data set and based on the target loss function, the initial entity relationship extraction model is trained to obtain a trained entity relationship extraction model.
[0098] In a specific implementation, the target loss function may be a loss function used to train a classification model. Figure 5 The named entity relationship table shown in the figure can construct the target loss function shown below based on the binary cross entropy loss function.
[0099] Where N is the length of the text to be processed after word segmentation and embedding, M is the number of preset entity relationship words, and I′ i,j is the label of the sample data, that is, a digital representation of whether there is actually an entity relationship to be extracted between the first named entity and the second named entity with coordinates (i, j) in the named entity relationship table. i,j A digital representation of whether there is an entity relationship to be extracted between the first named entity and the second named entity with coordinates (i, j) in the named entity relationship table predicted by the entity relationship extraction model, is a named entity relationship table, where there is no need to distinguish between the preset entity relationship words, so the value range of i and j is: (i <N)or(j<N)。
[0100] Using the initial entity relationship extraction model, we get I i,j Please refer to step 101 to step 104 for a detailed description, which will not be repeated here.
[0101] The initial entity relationship extraction model is trained, that is, the parameters of the attention model in the encoding module are adjusted using an optimization algorithm (e.g., a gradient descent optimization algorithm, etc.). By adjusting the parameters of the attention model using an optimization algorithm, the target loss function converges (e.g., the loss value is reduced to a preset threshold), or a preset number of training times is reached, and a trained entity relationship extraction model is obtained.
[0102] The entity relationship extraction device provided by the present invention is described below. The entity relationship extraction device described below and the entity relationship extraction method described above can be referenced to each other.
[0103] Figure 7 Schematic diagram of the structure of the entity relationship extraction device provided by the present invention. Figure 7 As shown, the entity relationship extraction device includes a first acquisition module 710 , a second acquisition module 720 , a third acquisition module 730 and an extraction module 740 .
[0104] The first acquisition module 710 is used to determine the target first named entity and the candidate second named entity, as well as the target entity relationship words in the text to be processed; wherein the first named entity is the subject in the entity relationship to be extracted, the second named entity is the object in the entity relationship to be extracted, and the target entity relationship words are the textual representation of the entity relationship to be extracted.
[0105] The second acquisition module 720 is used to use the attention model to process the text to be processed and the target entity relationship words to obtain entity relationship discrimination information; wherein the entity relationship discrimination information includes the first vector information obtained by attention encoding the target first named entity, the second vector information obtained by attention encoding the candidate second named entity, and the third vector information obtained by attention encoding the target entity relationship words.
[0106] The third acquisition module 730 is used to use the entity relationship discrimination information to obtain the first correlation between the target first named entity and the candidate second named entity in the text to be processed, the second correlation between the target first named entity and the target entity relationship word in the text to be processed, and the third correlation between the candidate second named entity and the target entity relationship word in the text to be processed.
[0107] The extraction module 740 is used to determine that the target first named entity and the candidate second named entity have the entity relationship to be extracted in response to the first correlation degree, the second correlation degree and the third correlation degree being greater than their respective corresponding preset thresholds, and extract the entity relationship to be extracted between the target first named entity and the candidate second named entity from the text to be processed.
[0108] In the embodiment of the above-mentioned entity relationship extraction device, the specific processing of each module and the technical effects it brings can be referred to the relevant descriptions in the corresponding method embodiment, and will not be repeated here.
[0109] Figure 8 An example of a physical structure diagram of an electronic device is shown in FIG. Figure 8As shown, the electronic device may include: a processor 810, a communication interface 820, a memory 830 and a communication bus 840, wherein the processor 810, the communication interface 820 and the memory 830 communicate with each other through the communication bus 840. The processor 810 may call the logic instructions in the memory 830 to execute the entity relationship extraction method, which includes: determining the target first named entity and the candidate second named entity in the text to be processed, as well as the target entity relationship word; wherein the first named entity is the subject in the entity relationship to be extracted, the second named entity is the object in the entity relationship to be extracted, and the target entity relationship word is the text representation of the entity relationship to be extracted; using the attention model, processing the text to be processed and the target entity relationship word to obtain entity relationship discrimination information; wherein the entity relationship discrimination information includes the first vector information obtained by attention encoding the target first named entity, the second vector information obtained by attention encoding the candidate second named entity, and the target entity relationship word. The method further comprises the steps of: obtaining a first correlation between the target first named entity and the candidate second named entity in the text to be processed, a second correlation between the target first named entity and the target entity relationship word in the text to be processed, and a third correlation between the candidate second named entity and the target entity relationship word in the text to be processed; in response to the first correlation, the second correlation and the third correlation being greater than their respective corresponding preset thresholds, determining that the target first named entity and the candidate second named entity have the entity relationship to be extracted, and extracting the entity relationship to be extracted between the target first named entity and the candidate second named entity from the text to be processed.
[0110] In addition, the logic instructions in the above-mentioned memory 830 can be implemented in the form of a software functional unit and can be stored in a computer-readable storage medium when it is sold or used as an independent product. Based on this understanding, the technical solution of the present invention is essentially or the part that contributes to the prior art or the part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions to enable a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk and other media that can store program codes.
[0111] On the other hand, the present invention also provides a computer program product, which includes a computer program. The computer program can be stored on a non-transitory computer-readable storage medium. When the computer program is executed by a processor, the computer can execute the entity relationship extraction method provided by the above methods, which includes: determining a target first named entity and a candidate second named entity, as well as a target entity relationship word in a text to be processed; wherein the first named entity is the subject in the entity relationship to be extracted, the second named entity is the object in the entity relationship to be extracted, and the target entity relationship word is a textual representation of the entity relationship to be extracted; using an attention model to process the text to be processed and the target entity relationship word to obtain entity relationship discrimination information; wherein the entity relationship discrimination information includes a first vector information obtained by attention encoding the target first named entity, The second vector information obtained by attention encoding the candidate second named entity, and the third vector information obtained by attention encoding the target entity relationship word; using the entity relationship discrimination information, obtain the first correlation between the target first named entity and the candidate second named entity in the text to be processed, the second correlation between the target first named entity and the target entity relationship word in the text to be processed, and the third correlation between the candidate second named entity and the target entity relationship word in the text to be processed; in response to the first correlation, the second correlation and the third correlation being greater than their respective corresponding preset thresholds, it is determined that the target first named entity and the candidate second named entity have the entity relationship to be extracted, and the entity relationship to be extracted between the target first named entity and the candidate second named entity is extracted from the text to be processed.
[0112] On the other hand, the present invention also provides a non-transitory computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, is implemented to execute the entity relationship extraction method provided by the above-mentioned methods, the method comprising: determining a target first named entity and a candidate second named entity, as well as a target entity relationship word in a text to be processed; wherein the first named entity is the subject in the entity relationship to be extracted, the second named entity is the object in the entity relationship to be extracted, and the target entity relationship word is a textual representation of the entity relationship to be extracted; using an attention model, processing the text to be processed and the target entity relationship word to obtain entity relationship discrimination information; wherein the entity relationship discrimination information includes a first vector information obtained by attention encoding the target first named entity, a first vector information obtained by attention encoding the candidate second named entity, The method comprises the steps of: obtaining the second vector information obtained by performing attention encoding on the target entity relationship words, and obtaining the third vector information obtained by performing attention encoding on the target entity relationship words; using the entity relationship discrimination information, obtaining the first correlation between the target first named entity and the candidate second named entity in the text to be processed, the second correlation between the target first named entity and the target entity relationship words in the text to be processed, and the third correlation between the candidate second named entity and the target entity relationship words in the text to be processed; in response to the first correlation, the second correlation and the third correlation being greater than their respective corresponding preset thresholds, determining that the target first named entity and the candidate second named entity have the entity relationship to be extracted, and extracting the entity relationship to be extracted between the target first named entity and the candidate second named entity from the text to be processed.
[0113] The device embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. Those of ordinary skill in the art may understand and implement it without creative effort.
[0114] Through the description of the above implementation methods, those skilled in the art can clearly understand that each implementation method can be implemented by means of software plus a necessary general hardware platform, and of course, it can also be implemented by hardware. Based on this understanding, the above technical solution is essentially or the part that contributes to the prior art can be embodied in the form of a software product, and the computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, a disk, an optical disk, etc., including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each embodiment or some parts of the embodiment.
[0115] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. A method for extracting entity relations, characterized in that: include: Determine a target first named entity and a candidate second named entity, as well as a target entity relationship word in the text to be processed; wherein the first named entity is the subject in the entity relationship to be extracted, the second named entity is the object in the entity relationship to be extracted, and the target entity relationship word is a textual representation of the entity relationship to be extracted; Using the attention model, the to-be-processed text and the target entity relationship words are processed to obtain entity relationship discrimination information; wherein the entity relationship discrimination information includes first vector information obtained by attention encoding the target first named entity, second vector information obtained by attention encoding the candidate second named entity, and third vector information obtained by attention encoding the target entity relationship words; Using the entity relationship discrimination information, obtain a first correlation between the target first named entity and the candidate second named entity in the text to be processed, a second correlation between the target first named entity and the target entity relationship word in the text to be processed, and a third correlation between the candidate second named entity and the target entity relationship word in the text to be processed; In response to the first degree of association, the second degree of association and the third degree of association being greater than their respective corresponding preset thresholds, it is determined that the target first named entity and the candidate second named entity have the entity relationship to be extracted, and the entity relationship to be extracted between the target first named entity and the candidate second named entity is extracted from the text to be processed.
2. The entity relationship extraction method according to claim 1, characterized in that: The method of using the attention model to process the text to be processed and the target entity relationship word to obtain entity relationship discrimination information includes: Preprocessing the text to be processed and the target entity relationship words; The preprocessed text to be processed and the target entity relationship words are input into the attention model, and the attention model is used to perform the following operations: Attention encoding is performed on the target first named entity, and the generated query vector and key vector are used as the first vector information; attention encoding is performed on the candidate second named entity, and the generated query vector and key vector are used as the second vector information; attention encoding is performed on the target entity relationship word, and the generated query vector and key vector are used as the third vector information.
3. The entity relationship extraction method according to claim 2, characterized in that: The method of using the entity relationship discrimination information to obtain a first correlation between the target first named entity and the candidate second named entity in the text to be processed, a second correlation between the target first named entity and the target entity relationship word in the text to be processed, and a third correlation between the candidate second named entity and the target entity relationship word in the text to be processed includes: Obtaining the first degree of association by using the query vector of the target first named entity and the key vector of the candidate second named entity; Obtaining the second degree of association using the query vector of the target first named entity and the key vector of the target entity relationship word; The third degree of association is obtained by using the query vector of the candidate second named entity and the key vector of the target entity relationship word.
4. The entity relationship extraction method according to claim 3, characterized in that: The obtaining the first degree of association by using the query vector of the target first named entity and the key vector of the candidate second named entity includes: Obtaining a first result by performing a dot product operation between the query vector of the target first named entity and the key vector of the candidate second named entity; Using an activation function, processing the first result to obtain the first degree of association; The obtaining the second degree of association by using the query vector of the target first named entity and the key vector of the target entity relationship word includes: Obtaining a second result by performing a dot product operation between the query vector of the target first named entity and the key vector of the target entity relationship word; Using an activation function, processing the second result to obtain the second degree of association; The obtaining the third degree of association by using the query vector of the candidate second named entity and the key vector of the target entity relationship word comprises: Obtain a third result by performing a dot product operation between the query vector of the candidate second named entity and the key vector of the target entity relationship word; The third result is processed by using an activation function to obtain the third degree of association.
5. The entity relationship extraction method according to claim 1, characterized in that: The text to be processed includes at least one first named entity and at least one second named entity; The step of determining a target first named entity and a candidate second named entity in the text to be processed, as well as a target entity relationship word, includes: Acquire at least one preset entity relationship word; wherein each of the at least one preset entity relationship word is a textual representation of a type of entity relationship; Constructing a named entity relationship table according to the at least one preset entity relationship word, the at least one first named entity, and the at least one second named entity; By enumeration, a first named entity, a second named entity and an entity relationship word are selected from the named entity relationship table as the target first named entity, the candidate second named entity and the target entity relationship word respectively.
6. The entity relationship extraction method according to claim 5, characterized in that: The method further comprises: For the text to be processed, perform the following preprocessing: Performing word segmentation processing on the text to be processed to obtain a first word segmentation sequence; Concatenating the at least one preset entity relationship word with the first word segmentation sequence to obtain a second word segmentation sequence; Using a feature extraction model, processing the second word segmentation sequence to obtain a vector sequence composed of an embedded vector of each word segmentation in the second word segmentation sequence, using the vector sequence as an input of the attention model, and identifying a first named entity and a second named entity in the text to be processed; The step of constructing a named entity relationship table according to the at least one preset entity relationship word, the at least one first named entity, and the at least one second named entity comprises: The named entity relationship table is constructed based on the embedded vector of the at least one first named entity, the embedded vector of the at least one second named entity, and the embedded vector of the at least one preset entity relationship word obtained by using the feature extraction model.
7. An entity relationship extraction device, characterized in that: include A first acquisition module is used to determine a target first named entity and a candidate second named entity in the text to be processed, as well as a target entity relationship word; wherein the first named entity is the subject in the entity relationship to be extracted, the second named entity is the object in the entity relationship to be extracted, and the target entity relationship word is a textual representation of the entity relationship to be extracted; A second acquisition module is used to process the to-be-processed text and the target entity relationship word by using an attention model to obtain entity relationship discrimination information; wherein the entity relationship discrimination information includes first vector information obtained by attention encoding the target first named entity, second vector information obtained by attention encoding the candidate second named entity, and third vector information obtained by attention encoding the target entity relationship word; A third acquisition module is used to use the entity relationship discrimination information to obtain a first correlation between the target first named entity and the candidate second named entity in the text to be processed, a second correlation between the target first named entity and the target entity relationship word in the text to be processed, and a third correlation between the candidate second named entity and the target entity relationship word in the text to be processed; An extraction module is used to determine that the target first named entity and the candidate second named entity have the entity relationship to be extracted in response to the first correlation degree, the second correlation degree and the third correlation degree being greater than their respective corresponding preset thresholds, and extract the entity relationship to be extracted between the target first named entity and the candidate second named entity from the text to be processed.
8. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein: When the processor executes the program, the entity relationship extraction method as described in any one of claims 1 to 6 is implemented.
9. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the entity relationship extraction method as described in any one of claims 1 to 6 is implemented.
10. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the entity relationship extraction method as described in any one of claims 1 to 6 is implemented.
