Unstructured text sensitive data sensitive method based on ERNIE
By combining the ERNIE model with the sequence annotation technology of BiLSTM and CRF, combined with the soft attention mechanism and Focal Loss loss function, and the commonly used desensitization algorithm, the problem of identifying and protecting sensitive data in unstructured text is solved, and non-structured text is realized. Precise desensitization and privacy protection of personalized text, suitable for data analysis and mining.
Patent Information
- Application Number
- CN202410401260.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-04-03
- Publication Date
- 2024-08-23
AI Technical Summary
In the era of big data, sensitive data in unstructured text is vulnerable to attacks, leading to frequent privacy leaks and data leaks. It is difficult for existing technologies to effectively identify and protect sensitive information.
The ERNIE model is combined with BiLSTM and CRF for text feature extraction and sequence annotation, combined with the soft attention mechanism and Focal Loss loss function, and commonly used desensitization algorithms such as Token replacement, character cutting, character replacement, etc., to achieve unstructured text Sensitive information identification and precise desensitization.
Through the ERNIE+BiLSTM+CRF model, the recognition efficiency of difficult text is improved, accurate desensitization of unstructured text is achieved, the privacy of sensitive information is protected, and it is suitable for data analysis and mining.
Smart Images

Figure CN118536147A
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of big data, and in particular relates to an ERNIE-based unstructured text sensitive data sensitivity method. Background Art
[0002] With the continuous development of network technology, the level of informatization has increased rapidly. Today's world is already an era of big data. Data resources contain rich strategic value, but they are also the most vulnerable resources. The key production factor to promote the development of the "digital economy" is data. The sharing and circulation of data is an important way to give full play to the vitality and value of data production factors. According to the "Data Age 2025" released by IDC, the amount of data generated every day in the world is about 491EB. In the past 20 years, the amount of information people are exposed to has increased by 6,450 times. While the huge amount of information promotes economic development and promotes the convenience of life, the information generated is collected, stored, shared and used in large quantities. Data exists in three forms: structured, semi-structured and unstructured. These data contain a lot of information that is not wanted to be known by other individuals or organizations, usually called sensitive data. In addition to some personal privacy information, such as personal basic information, personal asset information, and personal health information, sensitive data also includes commercial sensitive data, government sensitive data, and other non-public data.
[0003] However, in recent years, frequent corporate data leakage incidents have caused adverse social impacts such as various criminal cases. On December 22, 2011, the domestic developer community CSDN was illegally attacked by hackers, and more than 6 million user information in its database was leaked [2]. The user database information of other websites was also leaked at the same time. Then hackers successively released user information of Renren, Duowan Games, 178 Games, Tianya Forum, Baihe.com, 51CTO website, etc. At the end of March 2018, the fitness software MyFitnessPal under the famous American sports brand Under Armour was attacked by hackers due to data flaws, resulting in a large amount of user data being exposed, according to statistics, exceeding 150 million. The leaked information includes user login names, login ciphertexts, and email addresses. In June 2018, 1 billion personal privacy data of users of the famous express delivery company YTO was leaked. The largest continuous data leakage occurred in the account leak incident of Yahoo in the United States. 3 billion Yahoo accounts around the world were leaked, which eventually led to the company's bankruptcy and acquisition by Verizon[3].
[0004] In the era of big data, the frequency of attacks on data is increasing, and the methods of attacks are becoming more diverse. As citizens pay more attention to their own privacy, and institutions protect commercial secrets and national security, countries have introduced laws to limit data leakage. For example, the General Data Protection Regulation (GDPR)[4], which is known as the "strictest privacy protection law in history", recently introduced by the European Union, may have a profound impact on some of the world's largest technology companies, including Facebook and Google. In order to comply with the latest privacy policies of various countries and strengthen the protection of user privacy, various technology companies including Google, Amazon, and Microsoft have launched corresponding data loss prevention (DLP) products, among which data desensitization is an indispensable technology in DLP products. Summary of the invention
[0005] In order to overcome the deficiencies of the above-mentioned prior art, the purpose of the present invention is to provide an unstructured text sensitive data sensitivity method based on ERNIE, using deep learning models, such as ERNIE, BiLSTM and CRF models, to perform sensitive information identification and desensitization operations. Specifically, the ERNIE model will be used for text feature extraction and classification, and then BiLSTM will be used for sequence annotation, and finally CRF will be used for sequence decoding and output. At the same time, some commonly used desensitization algorithms, such as Token replacement, character cutting, character replacement and other methods, will be used to protect the privacy and security of text data.
[0006] In order to achieve the above object, the technical solution adopted by the present invention is:
[0007] An unstructured text sensitive data sensitization method based on ERNIE, characterized by comprising the following steps:
[0008] An unstructured text sensitive data sensitization method based on ERNIE, characterized by comprising the following steps:
[0009] (1) The text data will first be preprocessed and feature extracted through the ERNIE layer. Specifically, the input text data will be decomposed into tokens, and then each token will be mapped to a high-dimensional vector representation through the ERNIE pre-trained model. This step is the basis for the model to understand the text. The high-dimensional vector contains the semantic information of the token and its contextual relationship.
[0010] The core of the ERNIE model is the Transformer structure based on the self-attention mechanism. Its key formula is as follows:
[0011]
[0012] Where Q represents the Query matrix, K represents the Key matrix, V represents the Value matrix, and dk is the dimension of the Key vector. For each Query vector, a dot product operation is performed with all Key vectors to form a temporary matching score matrix. The result of the dot product operation can be understood as the similarity or correlation between the Query vector and each Key vector. Then, by dividing by the scaling factor, it is ensured that the similarity score can also maintain a moderate scale in the high-dimensional space. The softmax function is used for normalization and converted into a probability distribution so that the sum of the probabilities of all positions is 1. Finally, the probability distribution matrix is multiplied by the Value matrix to obtain the context vector corresponding to each Query vector.
[0013] (2) The BiLSTM layer is located after the ERNIE layer and is mainly responsible for processing the vector sequence output by the ERNIE layer. The specific steps are as follows:
[0014] Input vector sequence: Each input vector represents the features of a word. These feature vectors are extracted and output by the ERNIE layer and contain rich semantic information and contextual relationships.
[0015] Bidirectional processing: The BiLSTM layer consists of two LSTM networks, one for processing the forward sequence (from the beginning to the end of the sequence) and the other for processing the reverse sequence (from the end to the beginning of the sequence); these two networks operate independently and learn the forward and backward information in the sequence respectively;
[0016] Output merging: At each moment, the LSTM in both directions will output a vector. These two vectors are merged (usually concatenated or added) into a single vector as the BiLSTM output at that moment. Such an output can simultaneously reflect the contextual information of the word.
[0017] The core formula of the LSTM unit is as follows:
[0018] i t =σ(W i ·[h t-1 , x t ]+b i )
[0019] f t =σ(Wf·[h t-1 , x t ]+b f )
[0020] σ t =σ(W o ·[h t-1 ,x t ]+b o )
[0021]
[0022]
[0023] h t =o t tanh(C t )
[0024] Where σ is the sigmoid activation function, tanh is the hyperbolic tangent function, and x t is the input at time t, i t , o t , f t is the output of the input gate, output gate, and forget gate, is a candidate value, C t is the cell state at time step t, h t is the hidden state at time t, W i , W f , W o , W c is the weight matrix, b i 、b f 、b o 、b c is the bias vector;
[0025] (3) The self-attention layer is connected after the BiLSTM layer to further enhance the model’s ability to understand the internal relationship of the sequence. The processing process is as follows:
[0026] Input: The input to the self-attention layer is usually a sequence of vectors, which are the outputs of the BiLSTM layer and contain the forward and backward information of each element in the sequence;
[0027] Generate Query, Key, Value: The self-attention mechanism transforms the input into three different representations by applying three different sets of weight matrices (corresponding to Query (Q), Key (K), and Value (V)) to the input vector; this transformation allows the model to distinguish different roles and functions when calculating the attention score;
[0028] Calculate attention scores: Attention scores are calculated by the dot product of Query and Key. These scores determine how much "attention" should be given to other positions in the sequence when generating the output of each position.
[0029] Normalization and weighted summation: Use the softmax function to normalize the attention scores, and then use these normalized scores to perform weighted summation on the Value to obtain the final output;
[0030] (4) In this model, the CRF layer is located at the last stage of the model, and its main functions include:
[0031] Modeling label dependencies: The CRF layer can take into account the dependencies between adjacent labels in the sequence, which is very important in many NLP tasks. For example, in named entity recognition, "B-ORG" (beginning of an organization name) is usually not directly followed by "I-PER" (inside of a person's name);
[0032] Sequence-level optimization: Unlike methods that predict labels independently for each element, the CRF layer optimizes the labels of the entire sequence to find the most likely label sequence, thereby achieving higher labeling accuracy;
[0033] Flexibility and versatility: The CRF layer can be easily applied to any sequence labeling task and can combine different feature representations, such as the output of the ERNIE and BiLSTM layers, providing strong adaptability;
[0034] The probability model of CRF can be expressed as follows: there is an observation sequence X = (x1, x2, ..., x T ), where x t represents the tth element in the sequence, and the corresponding potential label sequence Y = (y1, y2, ..., y T ), where y t Given x t Possible tags for:
[0035] The goal of the model is to calculate the probability distribution of the label sequence Y under a given observation sequence X, and select the label sequence with the largest probability as the prediction result. For any possible label sequence Y, its probability can be expressed by the global probability distribution function, as shown in the following formula;
[0036]
[0037] Where Z(X) is called the normalization factor (partition function), which ensures that the probability sum is 1, f k is defined on adjacent label pairs (y t-1 ,y t ) is used to characterize the dependency between the previous and next labels. CRF optimizes the model performance by learning the weights corresponding to these feature functions, and can obtain the most likely label sequence Y under a given observation sequence X.
[0038] (5) This model uses negative log-likelihood loss to measure the difference between the probability of the sequence label predicted by the model and the probability of the actual sequence label; suppose there is an input sequence X = (x1, x2, ..., x n) and the corresponding label sequence Y = (y1, y2, ..., y n ), the purpose of the CRF model is to maximize the conditional probability P(Y|X); during the training process, the loss function of CRF can be defined as the negative log-likelihood loss, and the specific formula is as follows;
[0039]
[0040] The beneficial effects of the present invention are:
[0041] Combining the ERNIE+BiLSTM+CRF model, adding the soft attention mechanism and Focal Loss loss function, the model's recognition efficiency for difficult texts is improved. Then, through the data desensitization algorithm, accurate desensitization of unstructured texts is achieved to protect the privacy of sensitive information. BRIEF DESCRIPTION OF THE DRAWINGS
[0042] Figure 1 It is the structure diagram of ERNIE model;
[0043] Figure 2 This is the structure diagram of the Encoder unit;
[0044] Figure 3 This is the BiLSTM structure diagram;
[0045] Figure 4 This is the overall architecture diagram of the model;
[0046] Figure 5 For the flow chart. DETAILED DESCRIPTION
[0047] The present invention is further described below in conjunction with the accompanying drawings and embodiments.
[0048] Baidu ERNIE is improved based on the BERT model. Compared with BERT's learning of raw language signals, ERNIE directly models prior semantic knowledge units such as words and entities, enhancing the model's semantic representation capabilities. Similar to BERT, ERNIE also uses the Encoder part of a multi-layer bidirectional Transformer as the encoder, and uses the masked language model (MLM) and the prediction of the next sentence (NSP) as pre-training targets. It arbitrarily masks 15% of the words in the sequence by random masking, and then the encoder uses the unmasked words to predict the masked words. Unlike BERT, ERNIE no longer uses a single word-based masking strategy, but adds entity-level and phrase-level masking strategies on this basis, implicitly learning external knowledge such as entity attributes and entity relationships, thereby enhancing the semantic representation of the model. Its model architecture diagram is shown below. Figure 1 As shown:
[0049] The core part of Baidu ERNIE is the Transformer Encoder structure, which is a bidirectional deep network based on the attention mechanism. Each layer of ERNIE is composed of a Transformer Encoder unit. The structure of the Transformer Encoder unit is as follows: Figure 2 As shown in the figure, in the ERNIE model, there are 6 layers of Encoder, 1 Attention in each layer, 12 heads, and 768 dimensions of word vector.
[0050] The input Embedding and the position information of the corresponding position are added as the input of the Encoder. First, it passes through Multi-head Attention to learn the correlation between words in the input. Then it enters the Add&Norm layer, and the Add residual method is used to add different outputs to solve the gradient disappearance problem; Norm uses Layer Normalization to normalize the Embedding. Then the forward calculation of Feed Forward is performed, and finally a layer of Add&Norm is added to prevent the gradient from disappearing.
[0051] The Long Short-Term Memory Network (LSTM) is a variant of RNN. It introduces a gating mechanism and uses a special gate structure to enable the model to selectively save the previous information and effectively utilize long-distance information to achieve long-term memory, overcoming the problems of RNN such as gradient vanishing and long-term dependence caused by long sequences.
[0052] Since the LSTM network can only process information in one direction of the sequence, it cannot fully utilize the context information of the sequence. Therefore, this study uses a bidirectional LSTM network (BiLSTM) to encode the input vector. It is an improved model of the LSTM network. It can use forward and backward calculations for each word in the sentence and merge the outputs at the same time, thereby effectively utilizing the context information and avoiding the gradient explosion problem. Its structure diagram is shown in the figure below. Figure 3 shown.
[0053] The overall idea is to input a text sequence X, vectorize the text data through the ERNIE pre-training model, and then extract and encode the features through a bidirectional recurrent neural network to obtain a score matrix. The soft attention mechanism is used to assign different weights to different parts of the input sequence, so that the model can automatically learn and pay attention to important contextual information related to the current task. Finally, the conditional random field is used for decoding, and the set of labels with the highest probability is selected as the output of the algorithm. The overall structure of the model Figure 4 shown.
[0054] When processing text data containing sensitive information, ensuring information security and privacy protection is of great importance. The effective identification of sensitive information is a crucial step in the data desensitization process. With the help of the sensitive entity recognition model proposed in this paper, sensitive entities can be accurately identified from text data. After the recognition process is completed, this paper adopts a differentiated desensitization strategy based on entity type to ensure that while desensitizing sensitive information, the core information in the text data is retained as much as possible, so that it is suitable for subsequent analysis. The overall data desensitization process is as follows: Figure 5 shown.
[0055] The entire process starts with the identification of sensitive entities, and then differentiated desensitization strategies based on entity types are adopted for the identified sensitive entities. For example, personal names, geographic locations, and organization names, each of which requires a targeted desensitization strategy to protect data privacy and security. For personal names, simulation methods are used to protect personal identities by replacing them with fictitious but reasonable names. For geographic location information, an obfuscation strategy is adopted to slightly modify or replace the location to avoid exposing the exact location while maintaining a certain degree of authenticity and validity of the data. For organization names, an alternative strategy can be adopted, such as using general labels or classifications instead of specific organization names.
[0056] After the entire desensitization process is completed, the new text data generated achieves a balance between privacy and practicality, and can continue to support data analysis and mining activities on the basis of strict compliance with relevant laws and ethical standards.
[0057] The algorithm flow is as follows:
[0058] (1) The text data will first be preprocessed and feature extracted through the ERNIE layer. Specifically, the input text data will be decomposed into tokens, and then each token will be mapped to a high-dimensional vector representation through the ERNIE pre-trained model. This step is the basis for the model to understand the text. The high-dimensional vector contains the semantic information of the token and its contextual relationship.
[0059] The core of the ERNIE model is the Transformer structure based on the self-attention mechanism. Its key formula is as follows:
[0060]
[0061] Where Q represents the Query matrix, K represents the Key matrix, V represents the Value matrix, and dk is the dimension of the Key vector. For each Query vector, a dot product operation is performed between it and all the Key vectors to form a temporary matching score matrix. The result of the dot product operation can be understood as the similarity or association between the Query vector and each Key vector. Then, by dividing by the scaling factor, it is ensured that the similarity score can also maintain a moderate scale in the high-dimensional space. The softmax function is used for normalization and converted into a probability distribution so that the sum of the probabilities of all positions is 1. Finally, the probability distribution matrix is multiplied by the Value matrix to obtain the context vector corresponding to each Query vector.
[0062] (2) The BiLSTM layer is located after the ERNIE layer and is mainly responsible for processing the vector sequence output by the ERNIE layer. The specific steps are as follows:
[0063] Input vector sequence: Each input vector represents the features of a word. These feature vectors are extracted and output by the ERNIE layer and contain rich semantic information and contextual relationships.
[0064] Bidirectional processing: The BiLSTM layer consists of two LSTM networks, one responsible for processing the forward sequence (from the beginning to the end of the sequence) and the other for processing the reverse sequence (from the end to the beginning of the sequence). These two networks operate independently and learn the forward and backward information in the sequence respectively.
[0065] Output merging: At each moment, the LSTM in both directions will output a vector, and these two vectors are merged (usually concatenated or added) into a single vector as the BiLSTM output at that moment. Such an output can simultaneously reflect the contextual information of the word.
[0066] The core formula of the LSTM unit is as follows:
[0067] i t =σ(W i ·[h t-1 , x t ]+b i )
[0068] f t =σ(W f ·[h t-1 , x t ]+b f )
[0069] o t =σ(W o ·[h t-1 , x t ]+b o )
[0070]
[0071]
[0072] h t =o t tanh(C t )
[0073] Where σ is the sigmoid activation function, tanh is the hyperbolic tangent function, and x t is the input at time t, i t , o t , f t is the output of the input gate, output gate, and forget gate, is a candidate value, c f is the cell state at time step t, h t is the hidden state at time t, W i , W f , W o , W c is the weight matrix, b i 、b f 、b o 、b c is the bias vector.
[0074] (3) The self-attention layer is connected after the BiLSTM layer to further enhance the model's ability to understand the internal relationship of the sequence. The processing process is as follows:
[0075] Input: The input to the self-attention layer is usually a sequence of vectors, which are the outputs of the BiLSTM layer and contain the forward and backward information of each element in the sequence.
[0076] Generate Query, Key, Value: The self-attention mechanism transforms the input into three different representations by applying three different sets of weight matrices to the input vector (corresponding to Query (Q), Key (K), and Value (V) respectively). This transformation allows the model to distinguish different roles and functions when calculating the attention score.
[0077] Calculate attention scores: Attention scores are calculated by taking the dot product of the query and the key. These scores determine how much “attention” should be given to other positions in the sequence when generating the output at each position.
[0078] Normalization and weighted summation: Use the softmax function to normalize the attention scores, and then use these normalized scores to weighted sum the Values to get the final output.
[0079] (4) In this model, the CRF layer is located at the last stage of the model, and its main functions include:
[0080] Modeling label dependencies: The CRF layer is able to take into account the dependencies between adjacent labels in the sequence, which is very important in many NLP tasks. For example, in named entity recognition, "B-ORG" (beginning of an organization name) is usually not directly followed by "I-PER" (inside of a person's name).
[0081] Sequence-level optimization: Unlike methods that predict labels independently for each element, the CRF layer optimizes the labels of the entire sequence to find the most likely label sequence, thereby achieving higher labeling accuracy.
[0082] Flexibility and versatility: The CRF layer can be easily applied to any sequence labeling task and can combine different feature representations, such as the output of ERNIE and BiLSTM layers, providing strong adaptability.
[0083] The probability model of CRF can be expressed as follows: there is an observation sequence X = (x1, x2, ..., x T ), where x t represents the tth element in the sequence, and the corresponding potential label sequence Y = (y1, y2, ..., y T ), where y t Given x t Possible tags.
[0084] The goal of the model is to calculate the probability distribution of the label sequence Y under a given observation sequence X, and select the label sequence with the largest probability as the prediction result. For any possible label sequence Y, its probability can be expressed by the global probability distribution function, as shown in the following formula.
[0085]
[0086] Where Z(X) is called the normalization factor (partition function), which ensures that the probability sum is 1, f k is defined on adjacent label pairs (y t-1 ,y t ) is used to characterize the dependency between the previous and next labels. CRF optimizes the model performance by learning the weights corresponding to these feature functions, and can obtain the most likely label sequence Y under a given observation sequence X.
[0087] (5) This model uses negative log-likelihood loss to measure the difference between the probability of the sequence label predicted by the model and the probability of the actual sequence label. Suppose there is an input sequence X = (x1, x2, ..., x n) and the corresponding label sequence Y = (y1, y2, ..., y n ), the purpose of the CRF model is to maximize the conditional probability P(Y|X). During the training process, the loss function of CRF can be defined as the negative log-likelihood loss, and the specific formula is as follows.
[0088]
[0089] Experimental environment:
[0090]
[0091] Experimental dataset:
[0092] This paper uses the Chinese named entity recognition dataset MSRA and the Chinese resume dataset Resume provided by Microsoft for research. The MSRA dataset is mainly oriented to the news field and contains training sets and test sets. It is used to identify three entity types in text: place names (LOC), personal names (PER), and organization names (ORG). The Resume dataset includes training sets (3821), validation sets (463), and test sets (447). The entity types include nationality (CONT), educational background (EDU), place names (LOC), personal names (NAME), organization names (ORG), professions (PRO), ethnicity (RACE), and job titles (TITLE).
[0093] Experimental parameters:
[0094]
[0095]
[0096] Evaluation indicators:
[0097] This paper uses three evaluation indicators to measure model performance: precision (P), recall (R), and the harmonic mean of the two (F1-Score, F1 for short). In the calculation of these evaluation indicators, four basic concepts are involved: true positives (TP), false positives (FP), true negatives (TN), and false negatives (FN). Among them, "Positive" and "Negative" refer to the categories predicted by the model, while "True" and "False" indicate the correctness of the prediction results. Specifically, FP refers to instances that are mistakenly predicted as positive, FN refers to positive instances that are mistakenly predicted as negative, TP refers to instances that are correctly predicted as positive, and TN refers to instances that are correctly predicted as negative.
[0098]
[0099]
[0100]
[0101] Experimental results:
[0102] Recognition results on the MSRA dataset
[0103]
[0104] Recognition results on the Resume dataset
[0105]
[0106] Example of desensitization results:
[0107] Original text:
[0108] Li Si received a bachelor's degree in computer science from Shanghai Jiao Tong University, and then worked as a researcher at Microsoft Research Asia. Zhao Wu, ID number 420621198507108765, mobile phone number 13987654321, and address is Shashi District, Jingzhou City, Hubei Province.
[0109] Sun Qi, address: Industrial Park, Suzhou City, Jiangsu Province, zip code 215000.
[0110] Desensitized text:
[0111] Li*, received a bachelor's degree in ** from ** University, and then worked as a researcher at ** Research Institute. Zhao*, ID number 420621***********8765, mobile phone number 139******4321, address ** District, Jingzhou City, Hubei Province.
[0112] Sun*, address: Industrial Park, *** City, Jiangsu Province, zip code ******.
Claims
1. A method for sensitive data analysis of unstructured text based on ERNIE, It is characterized in that The following steps are involved: (1) The text data will first be preprocessed and feature extracted through the ERNIE layer. Specifically, the input text data will be decomposed into tokens, and then each token will be mapped to a high-dimensional vector representation through the ERNIE pre-trained model. This step is the basis for the model to understand the text. The high-dimensional vector contains the semantic information of the token and its contextual relationship. The core of the ERNIE model is the Transformer structure based on the self-attention mechanism. Its key formula is as follows: Where Q represents the Query matrix, K represents the Key matrix, V represents the Value matrix, and dk is the dimension of the Key vector. For each Query vector, a dot product operation is performed with all Key vectors to form a temporary matching score matrix. The result of the dot product operation can be understood as the similarity or correlation between the Query vector and each Key vector. Then, by dividing by the scaling factor, it is ensured that the similarity score can also maintain a moderate scale in the high-dimensional space. The softmax function is used for normalization and converted into a probability distribution so that the sum of the probabilities of all positions is 1. Finally, the probability distribution matrix is multiplied by the Value matrix to obtain the context vector corresponding to each Query vector. (2) The BiLSTM layer is located after the ERNIE layer and is mainly responsible for processing the vector sequence output by the ERNIE layer. The specific steps are as follows: Input vector sequence: Each input vector represents the features of a word. These feature vectors are extracted and output by the ERNIE layer and contain rich semantic information and contextual relationships. Bidirectional processing: The BiLSTM layer consists of two LSTM networks, one for processing the forward sequence (from the beginning to the end of the sequence) and the other for processing the reverse sequence (from the end to the beginning of the sequence); these two networks operate independently and learn the forward and backward information in the sequence respectively; Output merging: At each moment, the LSTM in both directions will output a vector. These two vectors are merged (usually concatenated or added) into a single vector as the BiLSTM output at that moment. Such an output can simultaneously reflect the contextual information of the word. The core formula of the LSTM unit is as follows: i t =σ(W i ·[h t-1 ,x t ]+b i ) f t =σ(W f ·[h t-1 ,x t ]+b f ) the t =σ(W o ·[h t-1 ,x t ]+b o ) h t =O t ·tanh(C t ) Where σ is the sigmoid activation function, tanh is the hyperbolic tangent function, and x t is the input at time t, i t , o t , f t is the output of the input gate, output gate, and forget gate, is a candidate value, C t is the cell state at time step t, h t is the hidden state at time t, W i , W f , W o , W c is the weight matrix, b i 、b f 、b o 、b c is the bias vector; (3) The self-attention layer is connected after the BiLSTM layer to further enhance the model’s ability to understand the internal relationship of the sequence. The processing process is as follows: Input: The input to the self-attention layer is usually a sequence of vectors, which are the outputs of the BiLSTM layer and contain the forward and backward information of each element in the sequence; Generate Query, Key, and Value: The self-attention mechanism converts the input into three different representations by applying three different sets of weight matrices (corresponding to Query (Q), Key (K), and Value (V)) to the input vector; This transformation allows the model to distinguish different roles and functions when calculating the attention score; Calculate attention scores: Attention scores are calculated by the dot product of Query and Key. These scores determine how much "attention" should be given to other positions in the sequence when generating the output of each position. Normalization and weighted summation: Use the softmax function to normalize the attention scores, and then use these normalized scores to perform weighted summation on the Value to obtain the final output; (4) In this model, the CRF layer is located at the last stage of the model, and its main functions include: Modeling label dependencies: The CRF layer can take into account the dependencies between adjacent labels in the sequence, which is very important in many NLP tasks. For example, in named entity recognition, "B-ORG" (the beginning of an organization name) is usually not directly followed by "I-PER" (the inside of a person's name); Sequence-level optimization: Unlike methods that predict labels independently for each element, the CRF layer optimizes the labels of the entire sequence to find the most likely label sequence, thereby achieving higher labeling accuracy; Flexibility and versatility: The CRF layer can be easily applied to any sequence labeling task and can combine different feature representations, such as the output of the ERNIE and BiLSTM layers, providing strong adaptability; The probability model of CRF can be expressed as follows: there is an observation sequence X = (x 1 , x 2 , ..., x T ), where x t represents the tth element in the sequence, and the corresponding potential label sequence Y = (y 1 ,y 2 , ..., y T ), where y t Given x t Possible tags for: The goal of the model is to calculate the probability distribution of the label sequence Y under a given observation sequence X, and select the label sequence with the largest probability as the prediction result. For any possible label sequence Y, its probability can be expressed by the global probability distribution function, as shown in the following formula; Where Z(X) is called the normalization factor (partition function), which ensures that the probability sum is 1, f k is defined on adjacent label pairs (y t-1 ,y t ) is used to characterize the dependency between the previous and next labels. CRF optimizes the model performance by learning the weights corresponding to these feature functions, and can obtain the most likely label sequence Y under a given observation sequence X. (5) This model uses negative log-likelihood loss to measure the difference between the probability of the model predicting the sequence label and the probability of the actual sequence label; assuming there is an input sequence X = (x 1 , x 2 , ..., x n ) and the corresponding label sequence Y = (y 1 ,y 2 , ..., y n ), the purpose of the CRF model is to maximize the conditional probability P(Y|X); during the training process, the loss function of CRF can be defined as the negative log-likelihood loss, and the specific formula is as follows;
Citation Information
Cited By
Artificial intelligence-based networking using agents built on large language models (LLMs)
US12792640B1
