A cross-language named entity recognition method based on context representation enhancement
By incorporating attention distribution loss and gated residual connections into the cross-lingual pre-trained model, the contextual representation is enhanced, which solves the problems of insufficient source language annotation data and large language differences in cross-lingual named entity recognition and improves recognition performance.
Patent Information
- Application Number
- CN202310758514.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-06-26
- Publication Date
- 2026-11-20
- Estimated Expiration
- 2043-06-26
AI Technical Summary
Existing cross-language named entity recognition methods perform poorly when the amount of source language labeled data is limited, especially when there is a large difference between the source language and the target language. Furthermore, the slice fine-tuning method lacks theoretical support and interpretability, resulting in poor model performance in the target language.
By incorporating attention distribution loss and gated residual connections into the cross-linguistic pre-trained model, we enhance contextual representation, reduce the model's focus on words themselves, and increase the proportion of contextual information. We use the encoder structure of the Transformer model for encoding and combine attention distribution loss and cross-entropy loss for training.
It improves the performance of cross-language named entity recognition, especially when the source language annotation data is insufficient or differs significantly from the target language, thereby enhancing the recognition effect and improving the model's utilization of contextual information.
Smart Images

Figure CN116776883B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to a cross-language named entity recognition method based on contextual representation enhancement, belonging to the field of natural language processing application technology. Background Technology
[0002] Named entity recognition (NAME) is a crucial component of natural language processing (NLP) tasks, and its technology has long been applied in various real-world scenarios. For example, when sending a package, simply inputting all information into a message box allows the system to automatically distinguish the sender's and recipient's names, phone numbers, and addresses. For news providers, NAME technology extracts key information from articles for targeted content delivery. It's also used in various applications to identify user search intent and for intelligent customer service. However, current high-performing NAME technologies all require large amounts of labeled data for training, necessitating significant human and time investment.
[0003] Cross-language named entity recognition (CENTR) can transfer knowledge from a source language with labeled data to a target language without labeled data, reducing labeling costs. Based on cross-language pre-trained models, CENTR has been applied when the source language has abundant labeled resources and the target language is similar to the source language. Existing CENTR methods typically fine-tune the pre-trained model on labeled source language data and directly apply it to target language testing. However, when the amount of labeled source language data is limited, the performance of existing methods is questionable when dealing with target languages that differ significantly from the source language.
[0004] Cross-lingual pre-trained language models primarily utilize self-attention modules to generate contextual representations through interactions between words and their context. After fine-tuning with named entity recognition (NID) labeled data, these models tend to focus excessively on the features of the words themselves. While slice-based fine-tuning guides the model to generate representations with more contextual information, the process itself is black-box, lacking theoretical support for the connection between words and context, resulting in poor interpretability. Slice-based fine-tuning also becomes difficult to train with a large number of slices. Furthermore, it causes the cross-lingual pre-trained language model to lose too many lexical features, including some features transferable to target languages similar to the source language, leading to poor model performance in those target languages. Summary of the Invention
[0005] The purpose of this invention is to provide a cross-language named entity recognition method based on context representation enhancement. This method enhances the context representation of the cross-language pre-trained model in the cross-language named entity recognition task by using attention distribution loss and gated residual connections, respectively, thereby solving the problems existing in the current cross-language named entity recognition methods.
[0006] The objective of this invention is achieved through the following technical solution:
[0007] This invention incorporates the attention coefficients of each word to itself in the attention distribution obtained from the self-attention module of the top-level encoder of the cross-lingual pre-trained model into the training loss, reducing the model's focus on the words themselves and making the context representation contain more contextual information. It also uses a gated residual connection module as the residual connection module connected after the self-attention module in the term layer encoder of the cross-lingual pre-trained model. By suppressing the proportion of information from the words themselves entering the final context representation through gating, the proportion of contextual information in the context representation is increased.
[0008] This invention discloses a cross-language named entity recognition method based on context representation enhancement, which consists of two stages: training and prediction. The trained entity is then used for prediction, and includes the following steps:
[0009] Step 1: Input the sentence, which is then converted into an input vector sequence through the input layer. This includes the following sub-steps:
[0010] Step 1.1: Segment the sentence using the vocabulary of the cross-lingual pre-trained model;
[0011] Step 1.2: Take the sentence after word segmentation in Step 1.1 and obtain a word vector sequence by word embedding;
[0012] Step 1.3: Obtain a sequence of position vectors from the word-segmented sentence in Step 1.1 by mapping each word through position embedding;
[0013] Step 1.4: Obtain a sequence of segment vectors from the word-segmented sentences in Step 1.1 by mapping them word by word through segment embedding;
[0014] Step 1.5: Add the three vector sequences obtained in Steps 1.2, 1.3, and 1.4 word by word to obtain the input vector sequence;
[0015] Step 2: Pass the input vector sequence obtained in Step 1 through a multi-layer encoder to obtain the encoded representation vector sequence;
[0016] The model structure of each encoder layer is completely identical, all adopting the encoder structure of the Transformer model, specifically including the following sub-steps:
[0017] Step 2.1: Pass the input vector sequence obtained in Step 1 through the lowest-level encoder, which specifically includes the following sub-steps:
[0018] Step 2.1.1: Pass the input vector sequence obtained in Step 1 through the self-attention module to obtain self-attention vector sequence 1;
[0019] Step 2.1.2: Add the input vector sequence obtained in Step 1 and the self-attention vector sequence 1 obtained in Step 2.1.1 word by word through residual connections to obtain residual connection vector sequence 1;
[0020] Step 2.1.3: Obtain the normalized vector sequence 1 by performing layer normalization on the residual connection vector sequence 1 obtained in step 2.1.2;
[0021] Step 2.1.4: The normalized vector sequence 1 obtained in step 2.1.3 is processed word by word through a feedforward neural network to first increase the dimension and then decrease the dimension to obtain the feedforward neural network vector sequence 1;
[0022] Step 2.1.5: Add the normalized vector sequence 1 obtained in Step 2.1.3 and the feedforward neural network vector sequence 1 obtained in Step 2.1.4 word by word through residual connections to obtain residual connection vector sequence 2;
[0023] Step 2.1.6: Obtain the bottom-level encoder output vector sequence by performing layer normalization on the residual connection vector sequence 2 obtained in step 2.1.5;
[0024] Step 2.2: Continuously encode the output vector sequence of the previous encoder layer through the next encoder layer, repeating this process until it passes through the penultimate encoder layer. This includes the following sub-steps:
[0025] Step 2.2.1: Pass the output vector sequence of the previous encoder through the self-attention module to obtain self-attention vector sequence 2;
[0026] Step 2.2.2: Add the output vector sequence of the previous encoder and the self-attention vector sequence 2 obtained in step 2.2.1 word by word through residual connection to obtain the residual connection vector sequence 3;
[0027] Step 2.2.3: Obtain the normalized vector sequence 2 by performing layer normalization on the residual connection vector sequence 3 obtained in step 2.2.2;
[0028] Step 2.2.4: The normalized vector sequence 2 obtained in step 2.2.3 is processed word by word through a feedforward neural network to first increase the dimension and then decrease the dimension to obtain the feedforward neural network vector sequence 2;
[0029] Step 2.2.5: Add the normalized vector sequence 2 obtained in step 2.2.3 and the feedforward neural network vector sequence 2 obtained in step 2.2.4 word by word through residual connections to obtain the residual connection vector sequence 4;
[0030] Step 2.2.6: Obtain the encoder output vector sequence of this layer by performing layer normalization on the residual connection vector sequence 4 obtained in step 2.2.5;
[0031] Step 2.3: Pass the penultimate encoder output vector sequence obtained in Step 2.2 through the top encoder to obtain the enhanced context representation vector sequence. This includes the following sub-steps:
[0032] Step 2.3.1: Pass the output vector sequence of the penultimate encoder layer through the self-attention module to obtain self-attention vector sequence 3;
[0033] During the training phase, step 2.3.1 requires determining the attention distribution loss based on the word's own attention coefficient in the attention distribution of each word and incorporating it into the training loss. The process for determining the attention distribution loss is as follows:
[0034] Each vector in the output vector sequence of the penultimate encoder is linearly mapped to a query Q, a key K, and a value V, as shown in equations (1), (2), and (3), respectively:
[0035] Q = W Q ·H+b Q (1)
[0036] K = W K ·H+b K (2)
[0037] V = W V ·H+b V (3)
[0038] Where H is the output vector sequence of the penultimate encoder layer; W Q b Q W K b K W V b V These are the mapping parameters for querying Q, key K, and value V, respectively.
[0039] For each word, the attention distribution s of all words is determined by the self-attention module, as shown in equation (4):
[0040]
[0041] Where, d k Let K be the dimension, K T It is the transpose of K;
[0042] The self-attention module contains multiple attention heads. The average value of the attention coefficients of each word to itself in all attention heads is determined as the attention distribution loss, AttentionLoss, as shown in Equation (5):
[0043]
[0044] Where n is the number of multi-head attention heads, m is the sequence length, and s(i,j,k) is the attention coefficient of the j-th word to the k-th word in the i-th attention head of the sequence;
[0045] Step 2.3.2: The output vector sequence of the penultimate encoder layer and the self-attention vector sequence 3 obtained in step 2.3.1 are used to calculate the gated residual connection vector sequence word by word through gated residual connections. The specific process for determining the gated residual connections is as follows:
[0046] Each vector in the output vector sequence of the penultimate encoder is linearly mapped to an intermediate representation vector O1, as shown in Equation (6). Each vector in the self-attention vector sequence 3 is linearly mapped to an intermediate representation vector O2, as shown in Equation (7).
[0047] O1=W1·H+b1 (6)
[0048] O2=W2·f(H)+b2 (7)
[0049] Where H is the output vector sequence of the penultimate encoder layer, f(H) is the self-attention vector sequence; W1, b1 and W2, b2 are the mapping parameters, respectively.
[0050] For each word, O1 and O2 are added together and then activated by the Sigmoid function to obtain the gate vector G, as shown in equation (8):
[0051] G = Sigmoid(O1 + O2) (8)
[0052] For each word, G and H are multiplied by vector and then added to f(H) to obtain the corresponding gated residual connection vector sequence, as shown in equation (9):
[0053]
[0054] Step 2.3.3: Obtain the normalized vector sequence 3 by performing layer normalization on the gated residual connection vector sequence obtained in step 2.3.2;
[0055] Step 2.3.4: The normalized vector sequence 3 obtained in step 2.3.3 is processed word by word through a feedforward neural network to first increase the dimension and then decrease the dimension to obtain the feedforward neural network vector sequence 3;
[0056] Step 2.3.5: Add the normalized vector sequence 3 obtained in Step 2.3.3 and the feedforward neural network vector sequence 3 obtained in Step 2.3.4 word by word through residual connections to obtain the residual connection vector sequence 5;
[0057] Step 2.3.6: Obtain the encoded representation vector sequence by performing layer normalization on the residual connection vector sequence 5 obtained in step 2.3.5;
[0058] Step 3: Pass the encoded representation vector sequence obtained in Step 2 through the output layer to obtain the entity label probability distribution sequence corresponding to the sentence. This includes the following sub-steps:
[0059] Step 3.1: Obtain the unnormalized score distribution sequence of entity labels by linearly mapping the sequence of encoded representation vectors obtained in Step 2;
[0060] Step 3.2: Activate the unnormalized entity label score distribution sequence obtained in Step 3.1 using the Softmax function to obtain the entity label probability distribution sequence;
[0061] During the training phase, step 3.2 determines the cross-entropy loss using the entity label probability distribution sequence and the entity labels of the actual sentences. The cross-entropy loss obtained in step 3.2 and the attention distribution loss obtained in step 2.3.1 are used together to obtain the training loss. The training loss is then backpropagated in step 3.2. After training, the model is saved for the prediction phase, and the subsequent step 4 is not performed.
[0062] The training loss is shown in equation (10):
[0063] Loss=α×AttentionLoss+CrossEntropyLoss (10)
[0064] Where α is a hyperparameter;
[0065] Step 4: Obtain the entity boundary and entity type based on the entity label probability distribution sequence obtained in Step 3. This includes the following sub-steps:
[0066] Step 4.1: Select the entity tag with the highest probability for each word in the entity tag probability distribution sequence obtained in Step 3 to obtain the entity tag sequence;
[0067] Step 4.2: Decode the entity label sequence obtained in Step 4.1 to obtain the entity boundaries and entity types;
[0068] The method also includes step 5, in which the method of the present invention is applied to the intelligent customer service scenario of an online trading platform. When there is a lack of named entity recognition annotation data for training in a certain language, the annotation data of other languages is used for training to obtain entity information in user questions, identify merchant names and product names, and then select relevant answers based on the entities.
[0069] Beneficial effects:
[0070] 1. The present invention provides a cross-language named entity recognition method based on context representation enhancement. On the basis of existing cross-language named entity recognition technology, this method enhances the context representation by using attention distribution loss and gated residual connection to improve the performance of cross-language named entity recognition, especially when the amount of source language labeled data is insufficient, and can improve the recognition performance when the source language and target language are significantly different.
[0071] 2. The present invention provides a cross-language named entity recognition method based on context representation enhancement. During the training phase, attention distribution loss is added to reduce the cross-language named entity recognition model's focus on the information of the words themselves and allocate more attention to the context information. Gated residual connections are used to reduce the proportion of the information of the words themselves added to the context representation and increase the proportion of the context information in the context representation. Attached Figure Description
[0072] Figure 1 This is a flowchart of a cross-language named entity recognition method based on context representation enhancement according to the present invention. Detailed Implementation
[0073] To better illustrate the purpose and advantages of the present invention, the invention will be further described below in conjunction with the accompanying drawings and examples.
[0074] Example 1:
[0075] The examples use the CoNLL-2002 / 2003 dataset and the WikiANN dataset, with English as the source language. For the CoNLL dataset, German, Spanish, and Dutch, which are less different from English, are used as target languages. For the WikiANN dataset, Chinese, Japanese, Quechua, Yoruba, and Igbo, which are more different from English, are used as target languages.
[0076] For the CoNLL dataset, the number of English training and validation sets is 2000 and 3466, respectively, while the number of German, Spanish, and Dutch test sets is 3160, 1517, and 5195, respectively. For the WikiANN dataset, the number of English training and validation sets is 2000 and 3000, respectively, while the number of Chinese, Japanese, Quechua, Yoruba, and Igbo test sets is 3000, 3000, 2000, 1000, and 500, respectively.
[0077] The present invention provides a cross-language named entity recognition method based on context representation enhancement, such as... Figure 1 As shown, the specific steps are as follows:
[0078] Step 1: Input the sentence, which is then converted into an input vector sequence through the input layer. This includes the following sub-steps:
[0079] Step 1.1: Segment the sentence using the vocabulary of the cross-lingual pre-trained model;
[0080] Step 1.2: Take the sentence after word segmentation in Step 1.1 and obtain a word vector sequence by word embedding;
[0081] Step 1.3: Obtain a sequence of position vectors from the word-segmented sentence in Step 1.1 by mapping each word through position embedding;
[0082] Step 1.4: Obtain a sequence of segment vectors from the word-segmented sentences in Step 1.1 by mapping them word by word through segment embedding;
[0083] Step 1.5: Add the three vector sequences obtained in Steps 1.2, 1.3, and 1.4 word by word to obtain the input vector sequence;
[0084] Step 2: Pass the input vector sequence obtained in Step 1 through a multi-layer encoder to obtain the encoded representation vector sequence;
[0085] The model structure of each encoder layer is completely identical, all adopting the Transformer encoder model structure. Specifically, it includes the following sub-steps:
[0086] Step 2.1: Pass the input vector sequence obtained in Step 1 through the lowest-level encoder, which specifically includes the following sub-steps:
[0087] Step 2.1.1: Pass the input vector sequence obtained in Step 1 through the self-attention module to obtain self-attention vector sequence 1;
[0088] Step 2.1.2: Add the input vector sequence obtained in Step 1 and the self-attention vector sequence 1 obtained in Step 2.1.1 word by word through residual connections to obtain residual connection vector sequence 1;
[0089] Step 2.1.3: Obtain the normalized vector sequence 1 by performing layer normalization on the residual connection vector sequence 1 obtained in step 2.1.2;
[0090] Step 2.1.4: The normalized vector sequence 1 obtained in step 2.1.3 is processed word by word through a feedforward neural network to first increase the dimension and then decrease the dimension to obtain the feedforward neural network vector sequence 1;
[0091] Step 2.1.5: Add the normalized vector sequence 1 obtained in Step 2.1.3 and the feedforward neural network vector sequence 1 obtained in Step 2.1.4 word by word through residual connections to obtain residual connection vector sequence 2;
[0092] Step 2.1.6: Obtain the bottom-level encoder output vector sequence by performing layer normalization on the residual connection vector sequence 2 obtained in step 2.1.5;
[0093] Step 2.2: Continuously encode the output vector sequence of the previous encoder layer through the next encoder layer, repeating this process until it passes through the penultimate encoder layer. This includes the following sub-steps:
[0094] Step 2.2.1: Pass the output vector sequence of the previous encoder through the self-attention module to obtain self-attention vector sequence 2;
[0095] Step 2.2.2: Add the output vector sequence of the previous encoder and the self-attention vector sequence 2 obtained in step 2.2.1 word by word through residual connection to obtain the residual connection vector sequence 3;
[0096] Step 2.2.3: Obtain the normalized vector sequence 2 by performing layer normalization on the residual connection vector sequence 3 obtained in step 2.2.2;
[0097] Step 2.2.4: The normalized vector sequence 2 obtained in step 2.2.3 is processed word by word through a feedforward neural network to first increase the dimension and then decrease the dimension to obtain the feedforward neural network vector sequence 2;
[0098] Step 2.2.5: Add the normalized vector sequence 2 obtained in step 2.2.3 and the feedforward neural network vector sequence 2 obtained in step 2.2.4 word by word through residual connections to obtain the residual connection vector sequence 4;
[0099] Step 2.2.6: Obtain the encoder output vector sequence of this layer by performing layer normalization on the residual connection vector sequence 4 obtained in step 2.2.5;
[0100] Step 2.3: Pass the penultimate encoder output vector sequence obtained in Step 2.2 through the item layer encoder to obtain the enhanced context representation vector sequence, which specifically includes the following sub-steps:
[0101] Step 2.3.1: Pass the output vector sequence of the penultimate encoder layer through the self-attention module to obtain self-attention vector sequence 3;
[0102] During the training phase, step 2.3.1 requires determining the attention distribution loss based on the word's own attention coefficient in the attention distribution of each word and incorporating it into the training loss. The process for determining the attention distribution loss is as follows:
[0103] Each vector in the output vector sequence of the penultimate encoder is linearly mapped to a query Q, a key K, and a value V, as shown in equations (1), (2), and (3), respectively:
[0104] Q = W Q ·H+b Q (1)
[0105] K = W K ·H+b K (2)
[0106] V = W V ·H+b V (3)
[0107] Where H is the output vector sequence of the penultimate encoder layer; W QQ b Q W K b K W V b V These are the mapping parameters for querying Q, key K, and value V, respectively.
[0108] For each word, the attention distribution s of all words is determined by the self-attention module, as shown in equation (4):
[0109]
[0110] Where, d k Let K be the dimension, K T It is the transpose of K;
[0111] The self-attention module contains multiple attention heads. The average value of the attention coefficients of each word to itself in all attention heads is determined as the attention distribution loss, AttentionLoss, as shown in Equation (5):
[0112]
[0113] Where n is the number of multi-head attention heads, m is the sequence length, and s(i,j,k) is the attention coefficient of the j-th word to the k-th word in the i-th attention head of the sequence;
[0114] Step 2.3.2: The output vector sequence of the penultimate encoder layer and the self-attention vector sequence 3 obtained in step 2.3.1 are used to calculate the gated residual connection vector sequence word by word through gated residual connections. The specific process for determining the gated residual connections is as follows:
[0115] Each vector in the output vector sequence of the penultimate encoder is linearly mapped to an intermediate representation vector O1, as shown in Equation (6). Each vector in the self-attention vector sequence 3 is linearly mapped to an intermediate representation vector O2, as shown in Equation (7).
[0116] O1=W1·H+b1 (6)
[0117] O2=W2·f(H)+b2 (7)
[0118] Where H is the output vector sequence of the penultimate encoder layer, f(H) is the self-attention vector sequence; W1, b1 and W2, b2 are the mapping parameters, respectively.
[0119] For each word, O1 and O2 are added together and then activated by the Sigmoid function to obtain the gate vector G, as shown in equation (8):
[0120] G = Sigmoid(O1 + O2) (8)
[0121] For each word, G and H are multiplied by vector and then added to f(H) to obtain the corresponding gated residual connection vector sequence, as shown in equation (9):
[0122]
[0123] Step 2.3.3: Obtain the normalized vector sequence 3 by performing layer normalization on the gated residual connection vector sequence obtained in Step 2.3.2;
[0124] Step 2.3.4: The normalized vector sequence 3 obtained in step 2.3.3 is processed word by word through a feedforward neural network to first increase the dimension and then decrease the dimension to obtain the feedforward neural network vector sequence 3;
[0125] Step 2.3.5: Add the normalized vector sequence 3 obtained in Step 2.3.3 and the feedforward neural network vector sequence 3 obtained in Step 2.3.4 word by word through residual connections to obtain the residual connection vector sequence 5;
[0126] Step 2.3.6: Obtain the encoded representation vector sequence by performing layer normalization on the residual connection vector sequence 5 obtained in step 2.3.5;
[0127] Step 3: Pass the encoded representation vector sequence obtained in Step 2 through the output layer to obtain the entity label sequence corresponding to the sentence. This includes the following sub-steps:
[0128] Step 3.1: Obtain the unnormalized score distribution sequence of entity labels by linearly mapping the sequence of encoded representation vectors obtained in Step 2;
[0129] Step 3.2: Activate the unnormalized entity label score distribution sequence obtained in Step 3.1 using the Softmax function to obtain the entity label probability distribution sequence;
[0130] During the training phase, step 3.2 determines the cross-entropy loss using the entity label probability distribution sequence and the entity labels of the actual sentences. The cross-entropy loss obtained in step 3.2 and the attention distribution loss obtained in step 2.3.1 are used together to obtain the training loss. The training loss is then backpropagated in step 3.2. After training, the model is saved for the prediction phase, and the subsequent step 4 is not performed.
[0131] The training loss is shown in equation (10):
[0132] Loss=α×AttentionLoss+CrossEntropyLoss (10)
[0133] Where α is a hyperparameter;
[0134] Step 4: Obtain the entity boundary and entity type based on the entity label probability distribution sequence obtained in Step 3. This includes the following sub-steps:
[0135] Step 4.1: Select the entity tag with the highest probability for each word in the entity tag probability distribution sequence obtained in Step 3 to obtain the entity tag sequence;
[0136] Step 4.2: Decode the entity label sequence obtained in Step 4.1 to obtain the entity boundaries and entity types;
[0137] The technical parameters and hyperparameters for the training and prediction phases are as follows: The model uses WordPiece for word segmentation; the training batch size is 16, and the prediction batch size is 256; the AdamW optimizer is used to update the parameters in the model, with a learning rate of 2e-5, β1 and β2 of 0.9 and 0.999 respectively, and a weight decay coefficient of 0.01.
[0138] In this embodiment, a linear learning rate adjustment strategy with warm-up is used to adjust the learning rate during the training process. The number of warm-up batches is limited to no more than 10% of the total number of batches and at most 500. A total of 10 rounds of training are conducted. At the end of each round of training, the model with the highest F1 score is saved according to the English validation set for subsequent target language testing.
[0139] Cross-language pre-trained models, Transformer model encoder structures, cross-entropy loss functions, and training methods are all existing technologies and will not be elaborated upon.
[0140] Table 1 shows a comparison of the recognition results (F1 score %) of the present invention and existing technologies on the CoNLL dataset:
[0141] Table 1
[0142]
[0143] As shown in Table 1, in terms of average F1 score, when the difference between the source language and the target language is small, the method of the present invention improves by 1.14 compared with the SLICER method.
[0144] Table 2 shows a comparison of the recognition results (F1 score %) of this invention and existing technologies on the WikiANN dataset:
[0145] Table 2
[0146]
[0147] As shown in Table 2, in terms of average F1 score, when the target language and source language are significantly different, the method of this invention improves by 2.95 compared to the SLICER method.
[0148] Based on Tables 1 and 2, the method of the present invention can better improve the cross-language named entity recognition effect when the amount of source language annotation data is insufficient, especially when the source language and target language are significantly different.
[0149] The above detailed description further illustrates the purpose, technical solution, and beneficial effects of the invention. It should be understood that the above description is only a specific embodiment of the present invention and is not intended to limit the scope of protection of the present invention. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the scope of protection of the present invention.
Claims
1. A cross-language named entity recognition method based on context representation enhancement, characterized in that: We enhance the context representation of the cross-lingual pre-trained model in the cross-lingual named entity recognition task based on attention distribution loss and gated residual connection respectively. We add the attention coefficient of each word to itself in the attention distribution obtained by the self-attention module of the top encoder of the cross-lingual pre-trained model to the training loss, reduce the model's attention to words themselves, and make the context representation contain more context information. We use the gated residual connection module as the residual connection module after the self-attention module in the top encoder of the cross-lingual pre-trained model. By suppressing the proportion of word information entering the final context representation through gating, we increase the proportion of context information in the context representation. The identification method comprises two stages: training and prediction. The trained data is used for prediction and includes the following steps: Step 1: Input a sentence, which is then converted into an input vector sequence through the input layer; Step 2: Pass the input vector sequence obtained in Step 1 through a multi-layer encoder to obtain the encoded representation vector sequence; The model structure of each encoder layer is completely identical, all adopting the encoder structure of the Transformer model, specifically including the following sub-steps: Step 2.1: Pass the input vector sequence obtained in Step 1 through the lowest-level encoder, which specifically includes the following sub-steps: Step 2.1.1: Pass the input vector sequence obtained in Step 1 through the self-attention module to obtain self-attention vector sequence 1; Step 2.1.2: Add the input vector sequence obtained in Step 1 and the self-attention vector sequence 1 obtained in Step 2.1.1 word by word through residual connections to obtain residual connection vector sequence 1; Step 2.1.3: Obtain the normalized vector sequence 1 by performing layer normalization on the residual connection vector sequence 1 obtained in step 2.1.2; Step 2.1.4: The normalized vector sequence 1 obtained in step 2.1.3 is processed word by word through a feedforward neural network to first increase the dimension and then decrease the dimension to obtain the feedforward neural network vector sequence 1; Step 2.1.5: Add the normalized vector sequence 1 obtained in Step 2.1.3 and the feedforward neural network vector sequence 1 obtained in Step 2.1.4 word by word through residual connections to obtain residual connection vector sequence 2; Step 2.1.6: Obtain the bottom-level encoder output vector sequence by performing layer normalization on the residual connection vector sequence 2 obtained in step 2.1.5; Step 2.2: Continuously encode the output vector sequence of the previous encoder layer through the next encoder layer, repeating this process until it passes through the penultimate encoder layer. This includes the following sub-steps: Step 2.2.1: Pass the output vector sequence of the previous encoder through the self-attention module to obtain self-attention vector sequence 2; Step 2.2.2: Add the output vector sequence of the previous encoder and the self-attention vector sequence 2 obtained in step 2.2.1 word by word through residual connection to obtain the residual connection vector sequence 3; Step 2.2.3: Obtain the normalized vector sequence 2 by performing layer normalization on the residual connection vector sequence 3 obtained in step 2.2.2; Step 2.2.4: The normalized vector sequence 2 obtained in step 2.2.3 is processed word by word through a feedforward neural network to first increase the dimension and then decrease the dimension to obtain the feedforward neural network vector sequence 2; Step 2.2.5: Add the normalized vector sequence 2 obtained in step 2.2.3 and the feedforward neural network vector sequence 2 obtained in step 2.2.4 word by word through residual connections to obtain the residual connection vector sequence 4; Step 2.2.6: Obtain the encoder output vector sequence of this layer by performing layer normalization on the residual connection vector sequence 4 obtained in step 2.2.5; Step 2.3: Pass the penultimate encoder output vector sequence obtained in Step 2.2 through the top encoder to obtain the enhanced context representation vector sequence. This includes the following sub-steps: Step 2.3.1: Pass the output vector sequence of the penultimate encoder layer through the self-attention module to obtain self-attention vector sequence 3; During the training phase, step 2.3.1 requires determining the attention distribution loss based on the word's own attention coefficient in the attention distribution of each word and incorporating it into the training loss. The process for determining the attention distribution loss is as follows: Each vector in the output vector sequence of the penultimate encoder is linearly mapped to a query. ,key and value As shown in equations (1), (2), and (3) respectively: (1) (2) (3) in, This is the output vector sequence of the penultimate encoder layer; , , , , , respectively query ,key and value Mapping parameters; For each word, the attention distribution s of all words is determined by the self-attention module, as shown in equation (4): (4) in, for Dimensions for transpose; The self-attention module contains multiple attention heads. The average value of the attention coefficients of each word to itself in all attention heads is determined as the attention distribution loss, AttentionLoss, as shown in Equation (5): (5) in, For the number of heads to focus on, For sequence length, For the first in the sequence The first one in the attention. The word for the first Attention coefficient of each word; Step 2.3.2: The output vector sequence of the penultimate encoder layer and the self-attention vector sequence 3 obtained in step 2.3.1 are used to calculate the gated residual connection vector sequence word by word through gated residual connections. The specific process for determining the gated residual connections is as follows: Each vector in the output vector sequence of the penultimate encoder is linearly mapped to an intermediate representation vector. As shown in equation (6), each vector of the self-attention vector sequence 3 is linearly mapped to an intermediate representation vector. As shown in equation (7): (6) (7) in, This is the output vector sequence of the penultimate encoder layer. For self-attention vector sequence 3; , as well as , These are the mapping parameters; For each word, and After addition, the mixture is activated by the Sigmoid function to obtain the gate vector. As shown in equation (8): (8) For each word, and Perform vector multiplication and then add The sums yield the corresponding gated residual connection vector sequence, as shown in equation (9): (9) Step 2.3.3: Obtain the normalized vector sequence 3 by performing layer normalization on the gated residual connection vector sequence obtained in Step 2.3.2; Step 2.3.4: The normalized vector sequence 3 obtained in step 2.3.3 is processed word by word through a feedforward neural network to first increase the dimension and then decrease the dimension to obtain the feedforward neural network vector sequence 3; Step 2.3.5: Add the normalized vector sequence 3 obtained in Step 2.3.3 and the feedforward neural network vector sequence 3 obtained in Step 2.3.4 word by word through residual connections to obtain the residual connection vector sequence 5; Step 2.3.6: Obtain the encoded representation vector sequence by performing layer normalization on the residual connection vector sequence 5 obtained in step 2.3.5; Step 3: Pass the encoded representation vector sequence obtained in Step 2 through the output layer to obtain the entity label probability distribution sequence corresponding to the sentence; Step 4: Obtain the entity boundary and entity type based on the entity label probability distribution sequence obtained in Step 3.
2. The cross-language named entity recognition method based on context representation enhancement as described in claim 1, characterized in that: Step 1 specifically includes the following sub-steps: Step 1: Input the sentence, which is then converted into an input vector sequence through the input layer. This includes the following sub-steps: Step 1.1: Segment the sentence using the vocabulary of the cross-lingual pre-trained model; Step 1.2: Take the sentence after word segmentation in Step 1.1 and obtain a word vector sequence by word embedding; Step 1.3: Obtain a sequence of position vectors from the word-segmented sentence in Step 1.1 by mapping each word through position embedding; Step 1.4: Obtain a sequence of segment vectors from the word-segmented sentences in Step 1.1 by mapping them word by word through segment embedding; Step 1.5: Add the three vector sequences obtained in Steps 1.2, 1.3, and 1.4 word by word to obtain the input vector sequence; Step 3 specifically includes the following sub-steps: Step 3.1: Obtain the unnormalized score distribution sequence of entity labels by linearly mapping the sequence of encoded representation vectors obtained in Step 2; Step 3.2: Activate the unnormalized entity label score distribution sequence obtained in Step 3.1 using the Softmax function to obtain the entity label probability distribution sequence; During the training phase, step 3.2 determines the cross-entropy loss using the entity label probability distribution sequence and the entity labels of the actual sentences. The cross-entropy loss obtained in step 3.2 and the attention distribution loss obtained in step 2.3.1 are used together to obtain the training loss. The training loss is then backpropagated in step 3.
2. After training, the model is saved for the prediction phase, and the subsequent step 4 is not performed. The training loss is shown in equation (10): (10) in, For hyperparameters; Step 4 specifically includes the following sub-steps: Step 4.1: Select the entity tag with the highest probability for each word in the entity tag probability distribution sequence obtained in Step 3 to obtain the entity tag sequence; Step 4.2: Decode the entity label sequence obtained in Step 4.1 to obtain the entity boundary and entity type.
3. The cross-language named entity recognition method based on context representation enhancement as described in claim 2, characterized in that: It also includes step 5, which is applied to the intelligent customer service scenario of online trading platforms. When there is a lack of named entity recognition annotation data for training in a certain language, it is trained with annotation data in other languages to obtain entity information in user questions, identify merchant names and product names, and then select relevant answers based on the entities. This improves the quality and efficiency of intelligent customer service on online trading platforms, saves manual customer service costs, and improves the economic benefits of online trading platforms.
Citation Information
Patent Citations
Named entity recognition model based on adversarial transfer learning
CN114722818A
Cross-language abstract method based on double attention decoding network
CN114817682A
