A relation extraction method based on BERT neural network and multi-aspect semantic learning
By employing multi-faceted semantic learning and multi-head attention mechanisms on the BERT model, the problems of large training data requirements and difficult technology transfer in traditional methods are solved, achieving efficient relation extraction and generating high-quality semantic classification vectors.
Patent Information
- Application Number
- CN202310873139.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-07-17
- Publication Date
- 2026-11-20
- Estimated Expiration
- 2043-07-17
AI Technical Summary
Traditional neural network relation extraction methods require a large amount of accurately labeled training data, and there are challenges in continuing the traditional segmented convolutional neural network technology on the BERT model, making it difficult to effectively reduce the training scale of downstream relation extraction.
This paper adopts a method based on BERT neural network and multi-faceted semantic learning. By dividing the sample extracted from the relation into left sequence, right sequence and global sequence, and processing it with BERT model with shared parameters, combined with multi-head attention mechanism, residual operation and gating mechanism, semantically rich classification vector is generated, and finally the relation category of entity pair is determined.
This approach reduces the training scale of downstream relation extraction on the BERT model while maintaining the effectiveness of traditional neural networks, generating high-quality semantic classification vectors and improving the accuracy and efficiency of relation extraction.
Smart Images

Figure CN117151108B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to sentiment analysis in the field of natural language processing, specifically a relation extraction method based on BERT (Bidirectional Encoder Representations from Transformers) neural network and multi-faceted semantic learning, which can be widely applied to knowledge graph automatic generation tasks in various fields. Background Technology
[0002] Relation extraction is a key technology in information extraction, aiming to identify semantic relationships between entity pairs in a given sentence. The extracted semantic relationships can be applied to downstream tasks such as knowledge base auto-completion and question-answering systems. Traditional neural network relation extraction methods require a large amount of precisely labeled training data, which is time-consuming and labor-intensive. To overcome this problem, large-scale pre-trained models, such as Google's BERT (Bidirectional Encoder Representations from Transformers), are used to reduce the training scale for downstream relation extraction. However, how to inherit some techniques from traditional neural network relation extraction methods, such as the widely adopted segmented convolutional neural network technique, on top of the BERT model has become a new challenge. This patent uses multi-faceted semantic learning on top of the BERT model to transplant traditional segmented convolutional neural network techniques, achieving both a reduction in the training scale for downstream relation extraction and the inheritance of segmented convolutional neural network techniques from traditional neural network relation extraction methods. Summary of the Invention
[0003] This invention discloses a relation extraction method based on BERT neural network and multi-faceted semantic learning. It improves the traditional segmented convolutional neural network technology by using multi-faceted semantic learning on top of the BERT model. This reduces the training scale of downstream relation extraction while retaining the segmented convolutional neural network technology in traditional neural network relation extraction methods, thus solving aspect-level sentiment analysis problems more effectively.
[0004] To achieve the above objectives, the technical solution of the present invention is as follows:
[0005] A relation extraction method based on BERT neural network and multi-faceted semantic learning, characterized by the following steps:
[0006] S1. Divide the sample of relation extraction into left sequence, right sequence and global sequence, and then concatenate the left sequence, right sequence and global sequence with the entity pair of relation to be extracted to form entity-aware left sequence, right sequence and global sequence sentence pairs;
[0007] S2. Input the left sequence, right sequence, and global sequence sentence pairs of entity perception into a parameter-shared BERT neural network model for processing to obtain the corresponding hidden representations of left semantics, right semantics, and global semantics; and extract the hidden states corresponding to the BERT classifiers from the hidden representations of left semantics, right semantics, and global semantics to form classification vectors of left semantics, right semantics, and global semantics.
[0008] S3. Concatenate the classification vectors of left semantics, right semantics, and global semantics into a three-row matrix, and feed it into a multi-head attention mechanism for fusion and residual operation to obtain the residual classification matrix of the sample;
[0009] S4. Perform average pooling on the residual classification matrix of the sample to obtain the residual classification vector of the sample, and then perform gating operation on it to obtain the final classification vector of the sample;
[0010] S5. Feed the final classification vector of the sample into a fully connected layer that performs a softmax operation, calculate the confidence score and probability of the sample on all relation categories, and determine the relation category of the specified entity pair in the sample based on the highest probability value;
[0011] The BERT neural network refers to the Bidirectional Encoder Representations from Transformers language model proposed by Google AI Language.
[0012] Step S1 specifically includes:
[0013] Using the entity pairs of relations to be extracted in the sample as the boundary, the sample is divided into left sequence, right sequence and global sequence, and the BERT classifier [CLS] is used as the start symbol and the BERT separator [SEP] is used as the delimiter and end symbol to form entity-aware sentence pairs;
[0014] Among them, the global sequence sentence pairs of entity perception The structure is: "[CLS] + Sample Sentence + [SEP] + Entity 1 + [SEP] + Entity 2 + [SEP]"; Entity-aware left sequence sentence pairs The structure is “[CLS] + Left Sequence + [SEP] + Entity 1 + [SEP] + Entity 2 + [SEP]”, where the left sequence is the sample subsequence located to the left of entity 2 and containing entity 2; the entity-aware right sequence sentence pair. The sequence is “[CLS] + Right Sequence + [SEP] + Entity 1 + [SEP] + Entity 2 + [SEP]”, where the right sequence is the sample subsequence located to the right of Entity 1 and containing Entity 1.
[0015] Step S2 specifically includes:
[0016] S2.1 Pair the left sequence sentences Right sequence sentence pair Global sequence sentence pairs The hidden representations of left semantics, right semantics, and global semantics are respectively input into a parameter-shared BERT model for learning and encoding. , and The calculation process is as follows:
[0017] (1)
[0018] (2)
[0019] (3)
[0020] in, This represents a BERT model with shared parameters;
[0021] S2.2 Hidden representations of left semantics, right semantics, and global semantics respectively , and In this process, the hidden states corresponding to the BERT classifier [CLS] are extracted to form classification vectors for left semantics, right semantics, and global semantics. , and , where R is the set of real numbers and d is the number of hidden units in the BERT model;
[0022] Step S3 specifically includes:
[0023] S3.1 Concatenate the classification vectors of left semantics, right semantics, and global semantics into a three-row semantic matrix. The calculation process is as follows:
[0024] (4)
[0025] Where [:] indicates that the vectors are concatenated into a matrix by rows;
[0026] S3.2 will The data is fed into a multi-head attention mechanism for fusion to obtain a fusion matrix. The calculation process is as follows:
[0027] (5)
[0028] in, This indicates a multi-head attention mechanism, and has , The calculation process is as follows:
[0029] (6)
[0030] (7)
[0031] (8)
[0032] in, They are respectively The query, keywords, and value input parameters, , , , These are all learnable parameters. , This represents the number of heads in the multi-head attention mechanism; [;] indicates concatenating the matrix column by column. This represents the i-th attention head in a multi-head attention mechanism. They are respectively The query, keywords, and value input parameters, To scale the dot product attention, This is the normalized exponential function in neural networks;
[0033] S3.3 will merge the matrix With semantic matrix Perform residual operations to obtain the residual classification matrix of the samples. The calculation process is as follows;
[0034] (9)
[0035] in, This represents layer normalization in a neural network. The layer normalization algorithm proposed in the literature "Ba JL, Kiros JR, Hinton G E. Layer normalization. in: arXiv:1607.06450, 2016." processes the parameters into unsaturated values between -1 and 1, and "+" indicates element-wise addition of the matrix.
[0036] Step S4 specifically includes:
[0037] S4.1 Classify the residual matrix of the samples Perform average pooling to obtain the residual classification vector of the sample. The calculation process is as follows:
[0038] (10)
[0039] in, Represents a matrix Perform average pooling by row;
[0040] S4.2 Classification of Residual Vectors Perform gating operations to obtain the final classification vector of the sample. The calculation process is as follows:
[0041] (11)
[0042] (12)
[0043] in, This is the gate vector in gating. For bias vectors, This represents the sigmoid activation function in a neural network. For gating weights, This indicates element-wise multiplication;
[0044] Step S5 specifically includes:
[0045] S5.1 Using the final classification vector of the samples The confidence scores of the sample across all relation categories are calculated as follows:
[0046] (13)
[0047] in, It is a matrix representing the relation categories. This indicates that Z is transposed. It is a bias vector. It is the number of relation categories. It is a vector representing the confidence scores for all relation categories;
[0048] S5.2 A vector of confidence scores for the sample across all relation categories Calculate the predicted probability of a sample on a specified relation category. The calculation process is as follows:
[0049]
[0050] Where y is a specified relation class, p(y|Z,θ) represents the predicted probability of the final classification vector Z of the sample on the specified relation class y, θ is the set of all learnable parameters, and exp(·) represents an exponential function with base e.
[0051] S5.3 Determine the relation category of a specified entity pair in the sample based on the highest probability value. The calculation process is as follows:
[0052] (15)
[0053] in, For a set of relation categories, For the final relationship category, Indicates that returning makes The relation category with the maximum value.
[0054] Furthermore, the loss function of the BERT neural network adopts the following cross-entropy loss error:
[0055] (16)
[0056] Where T is the set of training samples for the relation extraction task, |T| represents the size of set T, and y i Z is the relation category label of the i-th training sample in T. i It is the final classification vector of the i-th training sample in T;
[0057] The training objective is to minimize the cross-entropy loss error of all training samples in T according to formula (16).
[0058] Furthermore, during the fine-tuning backtracking process of the BERT neural network, the word embedding layer and position embedding layer of BERT are fixed, and the setting method is as follows:
[0059] (17)
[0060] (18)
[0061] Formulas (17) and (18) are two formulas for setting the parameters of the BERT model. Formula (17) means that the weights of the BERT word embedding layer are not updated during the backtracking process, and formula (18) means that the weights of the BERT position embedding layer are not updated during the backtracking process.
[0062] The present invention has the following advantages:
[0063] (1) Make full use of the extensive pre-training of the BERT model to obtain knowledge-rich initialization parameters for the model, so that the model can quickly adapt to the relation extraction task with only small-scale fine-tuning;
[0064] (2) A multi-faceted semantic learning framework for relation extraction based on BERT is proposed, including left semantic learning, right semantic learning and global semantics, which creates conditions for the transplantation of traditional segmented convolutional neural network technology;
[0065] (3) A multi-faceted semantic fusion method based on residual, gating and multi-head attention mechanism is proposed to generate semantically rich classification vectors;
[0066] (4) The model follows the Transformer structure in BERT and uses lightweight multi-head self-attention and linear transformation layers for encoding, making the model easier to train and shape. Attached Figure Description
[0067] Figure 1 This is a schematic diagram of the method flow of the present invention. Detailed Implementation
[0068] The present invention will be further described below with reference to specific embodiments, but the scope of protection of the present invention is not limited to the following embodiments.
[0069] For a sample containing two entities with relations to be extracted, according to Figure 1 The flowchart of the method of the present invention shown illustrates the following steps to analyze the relationship categories between specified entity pairs in a sample:
[0070] S1. Divide the sample of relation extraction into left sequence, right sequence and global sequence, and then concatenate the left sequence, right sequence and global sequence with the entity pair of relation to be extracted to form entity-aware left sequence, right sequence and global sequence sentence pairs;
[0071] S2. Input the left sequence, right sequence and global sequence sentence pairs of entity perception into a parameter-shared BERT neural network model for processing to obtain the corresponding hidden representations of left semantics, right semantics and global semantics; and extract the hidden states corresponding to the BERT classifiers from the hidden representations of left semantics, right semantics and global semantics to form classification vectors of left semantics, right semantics and global semantics respectively.
[0072] S3. Concatenate the classification vectors of left semantics, right semantics, and global semantics into a three-row matrix, and feed it into a multi-head attention mechanism for fusion and residual operation to obtain the residual classification matrix of the sample;
[0073] S4. Perform average pooling on the residual classification matrix of the sample to obtain the residual classification vector of the sample, and then perform gating operation on it to obtain the final classification vector of the sample;
[0074] S5. Feed the final classification vector of the sample into a fully connected layer that performs a softmax operation, calculate the confidence score and probability of the sample on all relation categories, and determine the relation category of the specified entity pair in the sample based on the highest probability value;
[0075] The BERT neural network refers to the Bidirectional Encoder Representations from Transformers language model proposed by Google AI Language.
[0076] Step S1 specifically includes:
[0077] Using the entity pairs of relations to be extracted in the sample as the boundary, the sample is divided into left sequence, right sequence and global sequence, and the BERT classifier [CLS] is used as the start symbol and the BERT separator [SEP] is used as the delimiter and end symbol to form entity-aware sentence pairs;
[0078] Among them, the global sequence sentence pairs of entity perception The structure is: "[CLS] + Sample Sentence + [SEP] + Entity 1 + [SEP] + Entity 2 + [SEP]"; Entity-aware left sequence sentence pairs The structure is “[CLS] + Left Sequence + [SEP] + Entity 1 + [SEP] + Entity 2 + [SEP]”, where the left sequence is the sample subsequence located to the left of entity 2 and containing entity 2; the entity-aware right sequence sentence pair. The sequence is “[CLS] + Right Sequence + [SEP] + Entity 1 + [SEP] + Entity 2 + [SEP]”, where the right sequence is the sample subsequence located to the right of Entity 1 and containing Entity 1.
[0079] Step S2 specifically includes:
[0080] S2.1 Pair the left sequence sentences Right sequence sentence pair Global sequence sentence pairs The hidden representations of left semantics, right semantics, and global semantics are respectively input into a parameter-shared BERT model for learning and encoding. , and The calculation process is as follows:
[0081] (1)
[0082] (2)
[0083] (3)
[0084] in, This represents a BERT model with shared parameters;
[0085] S2.2 Hidden representations of left semantics, right semantics, and global semantics respectively , and In this process, the hidden states corresponding to the BERT classifier [CLS] are extracted to form classification vectors for left semantics, right semantics, and global semantics. , and , where R is the set of real numbers and d is the number of hidden units in the BERT model;
[0086] Step S3 specifically includes:
[0087] S3.1 Concatenate the classification vectors of left semantics, right semantics, and global semantics into a three-row semantic matrix. The calculation process is as follows:
[0088] (4)
[0089] Where [:] indicates that the vectors are concatenated into a matrix by rows;
[0090] S3.2 will The data is fed into a multi-head attention mechanism for fusion to obtain a fusion matrix. The calculation process is as follows:
[0091] (5)
[0092] in, This indicates a multi-head attention mechanism, and has , The calculation process is as follows:
[0093]
[0094]
[0095]
[0096] in, They are respectively The query, keywords, and value input parameters, , , , These are all learnable parameters. , This represents the number of heads in the multi-head attention mechanism; [;] indicates concatenating the matrix column by column. This represents the i-th attention head in a multi-head attention mechanism. They are respectively The query, keywords, and value input parameters, To scale the dot product attention, This is the normalized exponential function in neural networks;
[0097] S3.3 will merge the matrix With semantic matrix Perform residual operations to obtain the residual classification matrix of the samples. The calculation process is as follows;
[0098] (9)
[0099] in, This represents layer normalization in a neural network. The layer normalization algorithm proposed in the literature "Ba JL, Kiros JR, Hinton G E. Layer normalization. in: arXiv:1607.06450, 2016." processes the parameters into unsaturated values between -1 and 1, and "+" indicates element-wise addition of the matrix.
[0100] Step S4 specifically includes:
[0101] S4.1 Classify the residual matrix of the samples Perform average pooling to obtain the residual classification vector of the sample. The calculation process is as follows:
[0102] (10)
[0103] in, Represents a matrix Perform average pooling by row;
[0104] S4.2 Classification of Residual Vectors Perform gating operations to obtain the final classification vector of the sample. The calculation process is as follows:
[0105] (11)
[0106] (12)
[0107] in, This is the gate vector in gating. For bias vectors, This represents the sigmoid activation function in a neural network. For gating weights, This indicates element-wise multiplication;
[0108] Step S5 specifically includes:
[0109] S5.1 Using the final classification vector of the samples The confidence scores of the sample across all relation categories are calculated as follows:
[0110] (13)
[0111] in, It is a matrix representing the relation categories. This indicates that Z is transposed. It is a bias vector. It is the number of relation categories. It is a vector representing the confidence scores for all relation categories;
[0112] S5.2 A vector of confidence scores for the sample across all relation categories Calculate the predicted probability of a sample on a specified relation category. The calculation process is as follows:
[0113]
[0114] Where y is a specified relation class, p(y|Z,θ) represents the predicted probability of the final classification vector Z of the sample on the specified relation class y, θ is the set of all learnable parameters, and exp(·) represents an exponential function with base e.
[0115] S5.3 Determine the relation category of a specified entity pair in the sample based on the highest probability value. The calculation process is as follows:
[0116] (15)
[0117] in, For a set of relation categories, For the final relationship category, Indicates that returning makes The relation category with the maximum value.
[0118] Furthermore, the loss function of the BERT neural network adopts the following cross-entropy loss error:
[0119] (16)
[0120] Where T is the set of training samples for the relation extraction task, |T| represents the size of set T, and y i Z is the relation category label of the i-th training sample in T. i It is the final classification vector of the i-th training sample in T;
[0121] The training objective is to minimize the cross-entropy loss error of all training samples in T according to formula (16).
[0122] Furthermore, during the fine-tuning backtracking process of the BERT neural network, the word embedding layer and position embedding layer of BERT are fixed, and the setting method is as follows:
[0123] (17)
[0124] (18)
[0125] Formulas (17) and (18) are two formulas for setting the parameters of the BERT model. Formula (17) means that the weights of the BERT word embedding layer are not updated during the backtracking process, and formula (18) means that the weights of the BERT position embedding layer are not updated during the backtracking process.
[0126] Application Examples
[0127] 1. Introduction to the dataset
[0128] The SemEval-2010 Task 8 dataset (http: / / www.kozareva.com / downloads.html) is a classic dataset in the field of relation extraction, and this example uses it for experiments. This dataset contains 9 relation types and 1 "other" type, where "other" indicates that the relation between entities does not belong to any of the 9 relation types. The 9 relation types are: Casuse-Effect, Component-Whole, Content-Container, Entity-Destination, Entity-Origin, Instrument-Agency, Member-Collection, Message-Topic, and Product-Producer. However, this dataset considers direction; for example, Entity-Origin(E1, E2) and Entity-Origin(E2, E1) are different. Therefore, the final judgment should consider 19 relation types. This dataset contains 10,717 samples, with each sentence containing two entities, E1 and E2. There are 8,000 training samples and 2,717 test samples. This example uses the official script of SemEval-2010 Task 8 (https: / / dl.acm.org / doi / 10.5555 / 1621969.1621986) to evaluate the example, and the evaluation metric is M-F1.
[0129] 2. Parameter Settings
[0130] The parameter settings for this example are as follows:
[0131] Table 1 Hyperparameters of the Instance
[0132]
[0133] In this example, the batch size is 16 during training and 32 during validation.
[0134] 3. Comparison Methods and Results
[0135] This example compares the method of the present invention with several classic methods released on the SemEval-2010 Task 8 dataset, including CNN[1], RNN[2], Bi-LSTM[3], Attention CNN[4], TRE[5], Entity-Aware BERT[6], BERTEM+MTB[7], R-BERT[8], knowBert[9], A-GCN+BERT
[10] , RE-DMP+XLNet
[11] . The specific comparison is shown in Table 2:
[0136] Table 2 Experimental Comparison Results
[0137]
[0138] The results in Table 2 show that the model proposed in this invention, implemented in this example, outperforms various non-BERT relation extraction methods and BERT-based relation extraction methods in terms of M-F1 value, as well as the BERT baseline model. This fully demonstrates that the relation extraction method based on BERT neural network and multi-faceted semantic learning proposed in this invention is feasible and excellent.
[0139] References:
[0140] [1]Zeng, D., Liu, K., Lai, S., Zhou, G., & Zhao, J. (2014). RelationClassification via Convolutional Deep Neural Network. InternationalConference on Computational Linguistics, 2335–2344.
[0141] [2]Socher, R., Huval, B., Manning, C. D., & Ng, A. Y. (2012).Semantic Compositionality through Recursive Matrix-Vector Spaces. InEmpirical Methods in Natural Language Processing (pp. 1201–1211).
[0142] [3]Zhang, S., Zheng, D., Hu, X., & Yang, M. (2015). BidirectionalLong Short-Term Memory Networks for Relation Classification. In Pacific AsiaConference on Language, Information, and Computation (pp. 73–78).
[0143] [4]Shen, Y., & Huang, X. (2016). Attention-Based Convolutional NeuralNetwork for Semantic Relation Extraction. In International Conference onComputational Linguistics (pp. 2526–2536).
[0144] [5]Alt, C., Hübner, M. P., & Hennig, L. (2019). Improving RelationExtraction by Pre-trained Language Representations. arXiv (CornellUniversity). https: / / arxiv.org / abs / 1906.03088
[0145] [6]Wang, H., Tan, M., Yu, M., Chang, S., Wang, D., Xu, K., Guo, X., &Potdar, S. (2019). Extracting Multiple-Relations in One-Pass with Pre-TrainedTransformers. arXiv (Cornell University). https: / / doi.org / 10.18653 / v1 / p19- 1132 .
[0146] [7]Soares, L., FitzGerald, N., Ling, J., & Kwiatkowski, T. (2019).Matching the Blanks: Distributional Similarity for Relation Learning. InMeeting of the Association for Computational Linguistics. https: / / doi.org / 10.18653 / v1 / p19-1279
[0147] [8]Wu, S., & He, Y. (2019). Enriching Pre-trained Language Model withEntity Information for Relation Classification. In Conference on Informationand Knowledge Management. https: / / doi.org / 10.1145 / 3357384.3358119
[0148] [9]Peters, M. J., Neumann, M. E., Logan, R. K., Schwartz, R., Joshi,V., Singh, S., & Smith, N. A. (2019). Knowledge Enhanced Contextual WordRepresentations. https: / / doi.org / 10.18653 / v1 / d19-1005
[0149]
[10] Tian, Y., Chen, G., Song, Y., & Wan, X. (2021). Dependency-drivenRelation Extraction with Attentive Graph Convolutional Networks. https: / / doi.org / 10.18653 / v1 / 2021.acl-long.344
[0150]
[11] Tian, Y., Song, Y., & Xia, F. (2022). Improving RelationExtraction through Syntax-induced Pre-training with Dependency Masking. InFindings of the Association for Computational Linguistics: ACL 2022. https: / / doi.org / 10.18653 / v1 / 2022.findings-acl.147
[0151] 4. Sample Preprocessing Example
[0152] For the relation extraction sample: "He had chest pains and..." <e1> headaches< / e1> from <e2> mold< / e2> "in the bedrooms." This example uses sample preprocessing for multi-semantic learning according to Table 3:
[0153] Table 3 Sample Preprocessing
[0154] .
Claims
1. A relation extraction method based on BERT neural network and multi-faceted semantic learning, characterized in that... Includes the following steps: S1. Divide the sample of relation extraction into left sequence, right sequence and global sequence, and then concatenate the left sequence, right sequence and global sequence with the entity pair of relation to be extracted to form entity-aware left sequence, right sequence and global sequence sentence pairs; S2. Input the left sequence, right sequence and global sequence sentence pairs of entity perception into a parameter-shared BERT neural network model for processing to obtain the corresponding hidden representations of left semantics, right semantics and global semantics; and extract the hidden states corresponding to the BERT classifiers from the hidden representations of left semantics, right semantics and global semantics to form classification vectors of left semantics, right semantics and global semantics respectively. S3. Concatenate the classification vectors of left semantics, right semantics, and global semantics into a three-row matrix, and feed it into a multi-head attention mechanism for fusion and residual operation to obtain the residual classification matrix of the sample; S4. Perform average pooling on the residual classification matrix of the sample to obtain the residual classification vector of the sample, and then perform gating operation on it to obtain the final classification vector of the sample; S5. Feed the final classification vector of the sample into a fully connected layer that performs a softmax operation, calculate the confidence score and probability of the sample on all relation categories, and determine the relation category of the specified entity pair in the sample based on the highest probability value; The BERT neural network refers to the Bidirectional Encoder Representations from Transformers language model proposed by Google AI Language. Step S1 specifically includes: Using the entity pairs of relations to be extracted in the sample as the boundary, the sample is divided into left sequence, right sequence and global sequence, and the BERT classifier [CLS] is used as the start symbol and the BERT separator [SEP] is used as the delimiter and end symbol to form entity-aware sentence pairs; Among them, the global sequence sentence pairs of entity perception The structure is: "[CLS] + Sample sentence + [SEP] + Entity 1 + [SEP] + Entity 2 + [SEP]"; Entity-aware left sequence sentence pairs The structure is "[CLS] + Left Sequence + [SEP] + Entity 1 + [SEP] + Entity 2 + [SEP]", where the left sequence is the sample subsequence located to the left of entity 2 and containing entity 2; the entity-aware right sequence sentence pair. The expression is "[CLS] + Right Sequence + [SEP] + Entity 1 + [SEP] + Entity 2 + [SEP]", where the right sequence is the sample subsequence located to the right of Entity 1 and containing Entity 1. Step S2 specifically includes: S2.1 Pair the left sequence sentences Right sequence sentence pair Global sequence sentence pairs The hidden representations of left semantics, right semantics, and global semantics are respectively input into a parameter-shared BERT model for learning and encoding. , and The calculation process is as follows: (1) (2) (3) in, This represents a BERT model with shared parameters; S2.2 Hidden representations of left semantics, right semantics, and global semantics respectively , and In this process, the hidden states corresponding to the BERT classifier [CLS] are extracted to form classification vectors for left semantics, right semantics, and global semantics. , and , where R is the set of real numbers and d is the number of hidden units in the BERT model; Step S3 specifically includes: S3.1 Concatenate the classification vectors of left semantics, right semantics, and global semantics into a three-row semantic matrix. The calculation process is as follows: (4) Where [:] indicates that the vectors are concatenated into a matrix by rows; S3.2 will The data is fed into a multi-head attention mechanism for fusion to obtain a fusion matrix. The calculation process is as follows: (5) in, This indicates a multi-head attention mechanism, and has , The calculation process is as follows: in, They are respectively The query, keywords, and value input parameters, , , , These are all learnable parameters. , This represents the number of heads in the multi-head attention mechanism; [;] indicates concatenating the matrix column by column. This represents the i-th attention head in a multi-head attention mechanism. They are respectively The query, keywords, and value input parameters, To scale the dot product attention, This is the normalized exponential function in neural networks; S3.3 will merge the matrix With semantic matrix Perform residual operations to obtain the residual classification matrix of the samples. The calculation process is as follows; (9) in, "+" indicates layer normalization in a neural network, and "+" indicates element-wise addition of matrices. Step S4 specifically includes: S4.1 The residual classification matrix of the samples Perform average pooling to obtain the residual classification vector of the sample. The calculation process is as follows: (10) in, Represents a matrix Perform average pooling by row; S4.2 Classification of Residual Vectors Perform gating operations to obtain the final classification vector of the sample. The calculation process is as follows: (11) (12) in, This is the gate vector in gating. For bias vectors, This represents the sigmoid activation function in a neural network. For gating weights, This indicates element-wise multiplication; Step S5 specifically includes: S5.1 Using the final classification vector of the samples The confidence scores of the sample across all relation categories are calculated as follows: (13) in, It is a matrix representing the relation categories. This indicates that Z is transposed. It is a bias vector. It is the number of relation categories. It is a vector representing the confidence scores for all relation categories; S5.2 A vector of confidence scores for the sample across all relation categories Calculate the predicted probability of a sample on a specified relation category. The calculation process is as follows: Where y is a specified relation class, p(y|Z,θ) represents the predicted probability of the final classification vector Z of the sample on the specified relation class y, θ is the set of all learnable parameters, and exp(·) represents an exponential function with base e. S5.3 Determine the relation category of a specified entity pair in the sample based on the highest probability value. The calculation process is as follows: (15) in, For a set of relation categories, For the final relationship category, Indicates that returning makes The relation category with the maximum value.
2. The relation extraction method based on BERT neural network and multi-faceted semantic learning according to claim 1, characterized in that: The loss function of the BERT neural network uses the following cross-entropy loss error: (16) Where T is the set of training samples for the relation extraction task, |T| represents the size of set T, and y i Z is the relation category label of the i-th training sample in T. i It is the final classification vector of the i-th training sample in T; The training objective is to minimize the cross-entropy loss error of all training samples in T according to formula (16).
3. The relation extraction method based on BERT neural network and multi-faceted semantic learning according to claim 2, characterized in that: During the fine-tuning backtracking process of the BERT neural network, the word embedding layer and position embedding layer of BERT are fixed, and the setting method is as follows: (17) (18) Formulas (17) and (18) are two formulas for setting the parameters of the BERT model. Formula (17) means that the weights of the BERT word embedding layer are not updated during the backtracking process, and formula (18) means that the weights of the BERT position embedding layer are not updated during the backtracking process.
Citation Information
Patent Citations
Remote supervision relationship extraction method with entity perception based on PCNN model
CN111859912A
Relation classification method and device based on information enhancement BERT
CN112883153A
Aspect-level sentiment analysis method based on BERT neural network and multi-semantic learning
CN114579707A
