A self-attention mechanism embedding enhancement method
By performing feature encoding, time displacement filling, slicing and reorganization of the input text information, combined with the self-attention mechanism, the limitations of the self-attention mechanism in understanding language structure and long-distance dependencies are solved, significantly improving the model's capture ability. .
Patent Information
- Application Number
- CN202410426778.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-04-10
- Publication Date
- 2024-08-30
- Estimated Expiration
- 2044-04-10
AI Technical Summary
Existing self-attention mechanisms have limitations in understanding specific language structures and long-distance dependencies. This is mainly due to the difficulty of position embeddings in fully modeling the temporal characteristics of sequences and the lack of global context information, resulting in insufficient understanding of language structures.
By performing feature encoding, time displacement filling, sequence slicing and reorganization on the input text information, a third encoding vector sequence is generated, processed using the self-attention mechanism, and the attention weight matrix is calculated to generate the final output representation, enhancing the model's ability to handle complex languages. The ability to capture structure and long-distance dependencies.
By introducing time-dependent information and global context information, the model's ability to understand complex language structures and long-distance dependencies is significantly improved, and the model's capturing ability is enhanced.
Smart Images

Figure CN118211563B
Abstract
Description
Technical Field
[0001] The present invention relates to the field of natural language processing, and in particular to a self-attention mechanism embedding enhancement method. Background Art
[0002] The self-attention mechanism calculates the attention weight of each element in the sequence to other elements, allowing the model to focus on different parts of the sequence and capture complex relationships within the sequence, such as long-distance dependencies. However, most of the self-attention mechanisms in the prior art use position embedding to implicitly infer language relationships in different contexts. This approach causes limitations in the model's understanding of certain specific language structures, especially in tasks that require understanding long-distance dependencies. Specifically, although position embedding introduces word order information to a certain extent, it is difficult to fully model the temporal characteristics of the sequence, affecting the model's ability to understand the language structure; at the same time, the lack of effective use of global context information can easily lead to the model's insufficient ability to capture long-distance dependencies. Summary of the invention
[0003] This application provides a self-attention mechanism embedding enhancement method to solve the technical problem in the prior art that the self-attention mechanism implicitly infers language relations in different contexts by using position embedding, resulting in limitations in the model's understanding of specific language structures and long-distance dependencies.
[0004] The present application discloses a self-attention mechanism embedding enhancement method, including: receiving input text information for feature encoding to obtain a first encoding vector sequence; performing time displacement filling on the first encoding vector sequence to obtain a second encoding vector sequence; performing sequence slicing on the second encoding vector sequence to obtain a first slicing result, a second slicing result, and a third slicing result; recombining the first slicing result, the second slicing result, and the third slicing result to obtain a third encoding vector sequence; processing the third encoding vector sequence through a self-attention mechanism to obtain a spliced weighted sequence for output.
[0005] One or more technical solutions provided in this application have at least the following technical effects or advantages:
[0006] By receiving input text information for feature encoding, a first encoding vector sequence is obtained. By extracting and encoding the input text, the original text is converted into a vector representation that can be processed by the model, preparing for subsequent time series processing; the first encoding vector sequence is time-shifted and filled to obtain a second encoding vector sequence. By adding zero vectors at the start and end positions of the sequence, the sequence is expanded in the time dimension. Without changing the original data content, a buffer for the start and end positions of the processing sequence is provided to the model, thereby enhancing the model's perception of sequence boundary information; the second encoding vector sequence is sequence sliced to obtain the first slice result, the second slice result and the third slice result. Through the slicing operation, the model can better capture local time dependencies and prepare for information fusion; the first slice result, the second slice result and the third slice result are sliced. The results are reorganized to obtain a third encoding vector sequence, so that the model can establish connections between different positions on the time axis and enhance its ability to grasp global semantics; the third encoding vector sequence is processed through the self-attention mechanism to obtain a spliced weighted sequence for output, and the attention weight matrix is generated by calculating the correlation between each element in the sequence and other elements. The sequence is weighted and summed according to the attention weight to obtain the final output representation. This technical solution solves the technical problem in the prior art that the self-attention mechanism implicitly infers the language relationship of different contexts by position embedding, which leads to the limitation of the model in understanding specific language structures and long-distance dependencies. The self-attention mechanism is integrated with time-dependent information through time displacement filling, slice reorganization and other means, so as to improve the technical effect of improving the model's ability to understand complex language structures and capture long-distance dependencies.
[0007] The above description is only an overview of the technical solution of the present application. In order to more clearly understand the technical means of the present application, it can be implemented in accordance with the contents of the specification. In order to make the above and other purposes, features and advantages of the present application more obvious and easy to understand, the specific implementation methods of the present application are listed below. BRIEF DESCRIPTION OF THE DRAWINGS
[0008] Figure 1 A flowchart of a self-attention mechanism embedding enhancement method is provided for an embodiment of the present application;
[0009] Figure 2 A schematic diagram of time displacement filling in a self-attention mechanism embedding enhancement method is provided for an embodiment of the present application;
[0010] Figure 3 A schematic diagram of sequence slicing and reorganization in a self-attention mechanism embedding enhancement method is provided for an embodiment of the present application. DETAILED DESCRIPTION
[0011] The overall idea of the technical solution provided by this application is as follows:
[0012] The embodiment of the present application provides a self-attention mechanism embedding enhancement method, which integrates time series processing with the self-attention mechanism, aiming to address the limitations of the self-attention mechanism in the prior art when processing complex language structures and capturing long-distance dependencies.
[0013] First, the input text information is feature encoded to obtain the initial encoding vector sequence. Then, through the time shift padding operation, zero vectors are added at the start and end of the sequence to enhance the model's perception of sequence boundary information. Next, the padded sequence is divided into three parts using the sequence slicing technique, each of which contains different time periods of the original sequence and corresponding zero padding, so that the model can better capture local time dependencies. After that, the three parts obtained by slicing are spliced according to certain rules through the reorganization operation, so that each time step contains the original information and the previous and next context information, which enhances the model's grasp of global semantics. Finally, the self-attention mechanism is introduced to model the fused time series. By calculating the correlation between each element in the sequence and other elements, an attention weight matrix is generated, and the sequence is weighted and summed according to the attention weight to obtain the final output representation.
[0014] In general, this application introduces rich contextual information on the timeline through technical means such as time displacement filling and sequence slice reorganization, and uses the self-attention mechanism for sequence representation learning, so that the model can adaptively focus on important information in the sequence, significantly enhancing the model's ability to capture long-distance dependencies and understand complex language structures.
[0015] After introducing the basic principles of the present application, the non-limiting implementation methods of the present application will be specifically introduced below in conjunction with the drawings in the specification.
[0016] like Figure 1 As shown, the embodiment of the present application provides a self-attention mechanism embedding enhancement method, the method comprising:
[0017] Receiving input text information for feature encoding to obtain a first encoding vector sequence;
[0018] Furthermore, this step includes:
[0019] Performing word encoding on the input text information to obtain a word encoding vector;
[0020] Performing sentence encoding on the input text information to obtain a sentence encoding vector;
[0021] Performing position encoding on the input text information to obtain a position encoding vector;
[0022] The first encoding vector sequence is generated by merging the word encoding vector, the sentence encoding vector and the position encoding vector.
[0023] In an embodiment of the present application, input text information is first received, feature extraction and encoding are performed on the input text information, and the original text data is converted into a processable vector representation. By performing operations such as word embedding, sentence embedding, and position embedding on the text in the input text information, the semantic information, structural information, and sequential information contained in the text are captured, and a comprehensive encoding vector sequence, i.e., a first encoding vector sequence, is generated. The first encoding vector sequence lays the foundation for subsequent time series processing and the application of the self-attention mechanism, so that the model can have a deeper understanding and analysis of the text in the vector space.
[0024] In a feasible implementation, first, one-hot encoding, bag-of-words, word embedding model or other word encoding techniques are used to encode each word in the input text information, and the discrete text symbols are converted into vector representations so that the model can process and analyze them. Through word encoding, each word is represented as a vector of fixed dimension, and different words correspond to different vector representations, thereby obtaining a word encoding vector. At the same time, the input text information is mapped to a sentence encoding vector of fixed dimension, and an encoding vector that can express the overall meaning of the sentence is generated according to the structure, grammar, semantics and other information of the sentence in the input text information. For example, a rule-based method is used to sentence encode the input text, and the sentence is first analyzed according to predefined rules, such as identifying components such as subject, predicate, object, etc., extracting keywords and key phrases, etc., and then generating a fixed-dimensional sentence encoding vector according to the extracted information and mapping rules. At the same time, the input text information is positionally encoded, and a unique position encoding vector is generated for each position, and it is associated with the words at the corresponding position to determine the position information of the words in the sentence, so that the model can capture the order relationship of the words. For example, assuming that the input text information contains n words, the position encoding process generates n position encoding vectors, each vector corresponds to the position of a word, and the dimension of the position encoding vector is consistent with the dimension of the word encoding vector to facilitate subsequent encoding vector merging operations.
[0025] Then, the word encoding vector, sentence encoding vector and position encoding vector are merged, and each word encoding vector is first concatenated with the sentence encoding vector to form a new vector sequence, in which the dimension of each vector is the word encoding vector dimension plus the sentence encoding vector dimension; then the position encoding vector and the fused vector sequence are integrated according to the position information, and the position encoding vector and the fused vector sequence are added or concatenated element by element according to the position information to retain the position information of each word. By merging and integrating the word encoding vector, sentence encoding vector and position encoding vector, a first encoding vector sequence is generated, in which each vector contains both word-level semantic information and sentence-level semantic information, and retains the position information of each word in the sentence.
[0026] Performing time shift filling on the first coding vector sequence to obtain a second coding vector sequence;
[0027] Furthermore, this step includes:
[0028] For the first encoding vector sequence, construct a zero-filled header encoding vector sequence of a time step;
[0029] For the first encoding vector sequence, construct a zero-padded tail encoding vector sequence of a time step;
[0030] The zero-filled header coding vector sequence and the zero-filled tail coding vector sequence are merged into the first coding vector sequence to obtain the second coding vector sequence.
[0031] In an embodiment of the present application, after obtaining the first coding vector sequence, the first coding vector sequence is time-shifted and filled, zero vectors are added at both ends of the first coding vector sequence, and the sequence is expanded in the time dimension to provide a buffer mechanism for the start and end positions of the model processing sequence.
[0032] In a feasible implementation, first, a zero-filled coding vector sequence of one time step is constructed at the head of the first coding vector sequence, providing a buffer for the starting position of the sequence. This zero-filled header coding vector sequence is a vector of all zeros, having the same dimension as the first coding vector sequence, but its length is one time step. At the same time, a zero-filled tail coding vector sequence of one time step is constructed at the tail of the first coding vector sequence, providing a buffer for the end position of the sequence. Similarly, the zero-filled tail coding vector sequence is a vector of all zeros, having the same dimension as the first coding vector sequence, and having a length of one time step. Then, the constructed zero-filled header coding vector sequence is placed in front of the first coding vector sequence, and the zero-filled tail coding vector sequence is placed behind the first coding vector sequence, forming an extended coding vector sequence, namely the second coding vector sequence. As shown in FIG. Figure 2As shown, assuming that the input text information is "What is your name", the upper part is the first coding vector sequence corresponding to the input text information, and the lower part is obtained by time-shifting and filling the head and tail of the first coding vector sequence.
[0033] Through time displacement filling, the second encoding vector sequence is expanded in the time dimension, and a zero vector is introduced at the beginning and end of the sequence as a buffer, so that the model can better handle the boundary position of the sequence when processing the sequence even in the absence of sufficient contextual information. The auxiliary model is able to access the information before and after and make accurate predictions even in the absence of sufficient contextual support.
[0034] The number of time steps for time displacement filling is adjusted according to actual needs. In this embodiment, one time step of zero filling is used, but more time steps can also be used to provide a larger buffer. At the same time, the specific value of zero filling can also be adjusted, for example, using a specific constant value instead of a zero vector.
[0035] Slicing the second encoding vector sequence to obtain a first slicing result, a second slicing result, and a third slicing result;
[0036] Furthermore, this step includes:
[0037] Obtaining a head subsequence, a first subsequence, a second subsequence until an Nth subsequence and a tail subsequence of the second encoding vector sequence;
[0038] Extracting feature information of the first time step of the head subsequence, the first subsequence, the second subsequence, and the N-1th subsequence respectively, and constructing the first slicing result;
[0039] Extracting feature information of the first subsequence, the second subsequence and the second time step of the Nth subsequence respectively, and constructing the second slicing result;
[0040] Feature information of the third time step of the second subsequence, the third subsequence up to the Nth subsequence and the tail subsequence are respectively extracted to construct the third slicing result.
[0041] In an embodiment of the present application, first, the second coding vector sequence is divided to obtain multiple subsequences. Specifically, the second coding vector sequence is divided into a head subsequence, a first subsequence, a second subsequence until the Nth subsequence and a tail subsequence. Among them, each subsequence corresponds to a different part of the second coding vector sequence, including the beginning, middle and end of the sequence. By dividing the second coding vector sequence into subsequences, different parts of the sequence information can be captured in a more fine-grained manner, providing a basis for subsequent slicing operations. Then, for the head subsequence, the first subsequence, the second subsequence until the N-1th subsequence, their feature information of the first time step is extracted respectively, and these feature information are combined to form a first slicing result. At the same time, for extracting the first subsequence, the second subsequence until the Nth subsequence, their feature information of the second time step is extracted respectively, and these feature information are combined to form a second slicing result. At the same time, for the second subsequence, the third subsequence until the Nth subsequence and the tail subsequence, their feature information of the third time step is extracted respectively, and these feature information are combined to form a third slicing result.
[0042] By dividing the second encoding vector sequence into subsequences and extracting the feature information of different subsequences at different time steps, three slicing results are constructed to capture the local features at different positions in the sequence. These are combined to form a comprehensive representation of different parts of the sequence, so that the model can understand the different parts of the sequence in a more fine-grained manner, thereby improving the model's ability to understand and represent the sequence.
[0043] Recombining the first slicing result, the second slicing result and the third slicing result to obtain a third encoding vector sequence;
[0044] Furthermore, this step includes:
[0045] The head subsequence feature information of the first slicing result is aligned with the first subsequence feature information of the second slicing result, and the first subsequence feature information of the second slicing result is aligned and spliced with the second subsequence feature information of the third slicing result to generate the third encoding vector sequence.
[0046] In the embodiment of the present application, after obtaining the first slicing result, the second slicing result and the third slicing result, the three slicing results are recombined to generate a third encoding vector sequence.
[0047] First, obtain the constructed first slicing result, extract the feature information corresponding to the head subsequence therein, and obtain the constructed second slicing result, extract the feature information corresponding to the first subsequence therein. Then, align and splice the extracted feature information of the head subsequence and the first subsequence in the feature dimension. Then, obtain the feature information of the first subsequence in the second slicing result, obtain the constructed third slicing result, extract the feature information corresponding to the second subsequence therein, and align and splice the feature information of the first subsequence and the second subsequence in the feature dimension. Through the alignment and splicing operations of the head subsequence and the first subsequence, and the first subsequence and the second subsequence, a third encoding vector sequence containing each time step of the original sequence and its surrounding context information is generated. Each word embedding vector of the third encoding vector sequence not only contains the information of the word itself, but also integrates the information of its front and back neighbor words in the sequence, which is conducive to capturing long-distance dependencies. As Figure 3 As shown, assuming that the input text information is "What is your name", the upper part is the second encoding vector sequence corresponding to the input text information, wherein the black frame surrounded parts are the first slicing result, the second slicing result and the third slicing result from left to right, and the first slicing result, the second slicing result and the third slicing result obtained by slicing the second encoding vector sequence are reorganized to obtain the third encoding vector sequence below.
[0048] Through the alignment and splicing operation, the third encoding vector sequence fuses the feature information from different slicing results and reorganizes the local features into a global sequence representation, so that the model can make full use of the different parts of the sequence information and establish associations between different positions in the time dimension, thereby improving the model's understanding and representation capabilities of the sequence.
[0049] The third encoding vector sequence is processed through a self-attention mechanism to obtain a concatenated weighted sequence for output.
[0050] Furthermore, this step includes:
[0051] Matching the third encoding vector sequence through a self-attention mechanism to obtain a query weight matrix, a key weight matrix, and a value weight matrix;
[0052] Construct a self-attention representation function;
[0053] The third encoding vector sequence is processed according to the query weight matrix, the key weight matrix and the value weight matrix in combination with the self-attention representation function to obtain the spliced weighted sequence for output.
[0054] In an embodiment of the present application, after obtaining the third encoding vector sequence, the third encoding vector sequence is calculated through the self-attention mechanism to capture the attention weights between the words in the sequence, and based on this, a weighted representation output of each word is obtained to form a spliced weighted sequence.
[0055] In a feasible implementation, first, in the self-attention mechanism, according to the input third encoding vector sequence, the corresponding query vector Query, key vector Key and value vector Value are generated, corresponding to the query weight matrix, key weight matrix and value weight matrix respectively. Then, a self-attention representation function is constructed to calculate the attention weighted representation output of each word embedding in the input sequence. The function takes the query vector Query, key vector Key and value vector Value as input, calculates the attention weight scores between different words through the scaled dot product attention mechanism, and weighted sums the value vector Value based on this. Subsequently, the query weight matrix, key weight matrix and value weight matrix obtained are substituted into the constructed self-attention representation function, and the input third encoding vector sequence is processed by the attention mechanism. Through calculation, the attention weighted output representation of each word embedding vector can be obtained, and these vectors are spliced into a sequence, which is output as a spliced weighted sequence.
[0056] In a preferred embodiment, the self-attention representation function is:
[0057]
[0058] Among them, z ′ i ′ Embed x for the i-th word in the third encoding vector sequence ′ i ′ The self-attention representation output value, x″ i The i-th vector sequence representing the third encoding vector sequence, x″ j The j-th vector sequence representing the third encoding vector sequence, x″ i W Q is x″ i The query vector, x″ j W K is x″ j The key vector of is x″ i The query vector and x″ j The dot product between the Key vectors, i.e., the self-attention score, W Q , W K , W V They are query weight matrix, key weight matrix and value weight matrix, is the scaling factor of the attention mechanism, Representing the mth word embedding x″ j x″ i The influence weight of , L represents the total number of embedded words.
[0059] When calculating the output value of the self-attention representation, the self-attention score is first calculated based on the query vector and the key vector, and then Obtain the attention weight scores between different word embedding vectors, then multiply the attention weight scores with the corresponding value vectors and sum them up to get the self-attention weighted representation output of each word embedding vector. By calculating the self-attention representation function, it is possible to integrate the contextual information between words at different positions, capture long-distance dependencies, and improve sequence modeling capabilities.
[0060] Through the self-attention representation function, each word embedding generates a self-attention representation output value, which comprehensively considers the influence weights of all other word embeddings on it, and obtains a context-related representation through weighted summation, so that the model can dynamically focus on important information in the sequence and generate more semantically rich representations.
[0061] Furthermore, the first time step, the second time step and the third time step are consecutive time steps in sequence.
[0062] In a feasible implementation manner, the first time step, the second time step and the third time step refer to three consecutive adjacent time steps in the sequence data.
[0063] Specifically, when the second encoding vector sequence after time displacement filling is sequence sliced, the extracted first slice result contains the first time step information corresponding to the beginning part and the head zero filling of the second encoding vector sequence; the extracted second slice result contains the second time step information corresponding to the middle part of the second encoding vector sequence; the extracted third slice result contains the third time step information corresponding to the end part and the tail zero filling of the second encoding vector sequence. Among them, the first time step, the second time step and the third time step are continuous and adjacent in the time dimension of the sequence, and correspond to the forward and backward progressive order of the sequence data in time. When the head subsequence of the first slice result is aligned and spliced with the first subsequence of the second slice result, and the first subsequence of the second slice result is aligned and spliced with the second subsequence of the third slice result, each word embedding vector of the generated third encoding vector sequence not only contains the information of the current time step, but also integrates the context information of the previous time step and the next time step. Therefore, by extracting sequence information at these three consecutive time steps, the temporal dependency between words and their contexts can be better captured, which is conducive to the model's learning and modeling of long-distance dependencies.
[0064] Furthermore, the first time step and the third time step are at least two time steps.
[0065] In a feasible implementation, because the zero-filled parts at both ends of the second encoding vector sequence must correspond to at least one time step, the first time step and the third time step refer to at least two time steps.
[0066] In order to fully capture the temporal dependency of sequence data, the number of time steps contained in the first and third slicing results is greater than 1. Only when the number of time steps they contain reaches a certain level can they provide sufficient contextual information for the model to better learn and model long-distance dependencies.
[0067] Therefore, the limitation on the number of the first time step and the third time step not only ensures the feasibility of the method, but also lays the foundation for subsequent sequence reorganization and attention weight calculation, which is conducive to improving the sequence modeling ability of the model.
[0068] Furthermore, the embodiment of the present application also includes:
[0069] Aggregating the word encoding vectors according to the sentence encoding vector to obtain a first encoding vector subsequence to an Nth encoding vector subsequence;
[0070] According to the position encoding vector, the first encoding vector subsequence to the Nth encoding vector subsequence are arranged from top to bottom to construct the first encoding vector sequence.
[0071] In a feasible implementation, in order to construct the first coding vector sequence, after obtaining the sentence coding vector for the word coding vector, secondly, the sentence coding vector is applied to each word coding vector respectively by means of vector concatenation, vector cascade or gated recursive unit, so as to realize the fusion of sentence-level semantic information into word-level semantic information. Then, the fused word coding vector sequence is grouped, and each group constitutes a coding vector subsequence. For example, according to the natural grammatical structure of the sentence in the input text information, the word coding vectors belonging to the same sentence grammatical unit are grouped together. Through vector aggregation, the first coding vector subsequence, the second coding vector subsequence, and the Nth coding vector subsequence can be obtained, where N is the number of subsequences, which depends on the length and grammatical structure of the input text. Then, the position coding vector corresponding to the input text information is obtained, which represents the position information of the word in the text sequence, and the first to Nth coding vector subsequences obtained are arranged in a top-down order according to the position coding vector to construct the first coding vector sequence. This sequence not only contains the semantic information of words and sentences, but also integrates the position information of words, which is conducive to capturing the contextual relationship of sequence data.
[0072] By fusing the word embedding vector, sentence embedding vector and position encoding vector of the input text information, a first encoding vector sequence containing multi-source semantics and position features is generated, laying the foundation for subsequent operations such as time displacement filling and sequence slice reorganization.
[0073] In summary, the self-attention mechanism embedding enhancement method provided in the embodiment of the present application has the following technical effects:
[0074] Receive input text information for feature encoding to obtain a first encoding vector sequence, which lays the foundation for subsequent time series processing. Perform time shift filling on the first encoding vector sequence to obtain a second encoding vector sequence, so that the model can better process the beginning and end of the sequence even in the absence of sufficient context information. Perform sequence slicing on the second encoding vector sequence to obtain a first slicing result, a second slicing result, and a third slicing result. Through sequence slicing, the model can pay more attention to different parts of the sequence and extract key information therein, which helps the model better understand the structure and semantic relationship within the sequence. Reorganize the first slicing result, the second slicing result, and the third slicing result to obtain a third encoding vector sequence. Through the reorganization operation, the model can establish semantic connections between different positions on the time axis and enhance the ability to grasp global semantics. The third encoding vector sequence is processed through a self-attention mechanism to obtain a spliced weighted sequence for output. Through the self-attention mechanism, the model can understand the semantics of the sequence more flexibly and accurately, and improve the performance of natural language processing tasks. By introducing context information through time shift operations on the time axis and slicing and reorganizing the hidden state of the fully connected layer, the model's ability to understand complex language structures and capture long-distance dependencies is improved.
[0075] Any step of the method described above can be stored as a computer instruction or program in an unlimited computer memory, and can be called and recognized by an unlimited computer processor to implement any method in the embodiments of the present application, without any unnecessary restrictions.
[0076] Furthermore, the first or second mentioned above may not only represent an order relationship, but may also represent a specific concept, and / or refer to multiple elements that can be selected individually or in full. Obviously, those skilled in the art can make various changes and modifications to the present application without departing from the scope of the present application. Thus, if these modifications and variations of the present application fall within the scope of the present application and its equivalents, the present application intends to include these modifications and variations.
Claims
1. A self-attention mechanism embedding enhancement method, characterized in that: include: Receiving input text information for feature encoding to obtain a first encoding vector sequence; Performing time displacement padding on the first coding vector sequence to obtain a second coding vector sequence; Slicing the second encoding vector sequence to obtain a first slicing result, a second slicing result, and a third slicing result; Recombining the first slicing result, the second slicing result and the third slicing result to obtain a third encoding vector sequence; Processing the third encoding vector sequence through a self-attention mechanism to obtain a concatenated weighted sequence for output; The step of performing time displacement filling on the first coding vector sequence to obtain a second coding vector sequence includes: For the first encoding vector sequence, construct a zero-filled header encoding vector sequence of a time step; For the first encoding vector sequence, construct a zero-padded tail encoding vector sequence of a time step; Merging the zero-filled header coding vector sequence and the zero-filled tail coding vector sequence into the first coding vector sequence to obtain the second coding vector sequence; The step of performing sequence slicing on the second encoding vector sequence to obtain a first slicing result, a second slicing result, and a third slicing result includes: Obtaining a head subsequence, a first subsequence, a second subsequence until an Nth subsequence and a tail subsequence of the second encoding vector sequence; Extracting feature information of the first time step of the head subsequence, the first subsequence, the second subsequence, and the N-1th subsequence respectively, and constructing the first slicing result; Extracting feature information of the first subsequence, the second subsequence and the second time step of the Nth subsequence respectively, and constructing the second slicing result; extracting feature information of the second subsequence, the third subsequence up to the Nth subsequence and the tail subsequence at the third time step respectively, and constructing the third slicing result; The first slicing result, the second slicing result and the third slicing result are recombined to obtain a third encoding vector sequence, including: The head subsequence feature information of the first slicing result is aligned with the first subsequence feature information of the second slicing result, and the first subsequence feature information of the second slicing result is aligned and spliced with the second subsequence feature information of the third slicing result to generate the third encoding vector sequence.
2. The method according to claim 1, characterized in that Receiving input text information for feature encoding to obtain a first encoding vector sequence, including: Performing word encoding on the input text information to obtain a word encoding vector; Performing sentence encoding on the input text information to obtain a sentence encoding vector; Performing position encoding on the input text information to obtain a position encoding vector; The first encoding vector sequence is generated by merging the word encoding vector, the sentence encoding vector and the position encoding vector.
3. The method according to claim 1, characterized in that The third encoding vector sequence is processed by a self-attention mechanism to obtain a concatenated weighted sequence for output, including: Matching the third encoding vector sequence through a self-attention mechanism to obtain a query weight matrix, a key weight matrix, and a value weight matrix; Construct a self-attention representation function; Processing the third encoding vector sequence according to the query weight matrix, the key weight matrix and the value weight matrix in combination with the self-attention representation function to obtain the concatenated weighted sequence for output; Among them, the self-attention representation function is: , in, is the i-th word embedding of the third encoding vector sequence The self-attention representation output value, an i-th vector sequence representing the third encoding vector sequence, a j-th vector sequence representing the third encoding vector sequence, yes The query vector is yes The key vector of yes The query vector and The dot product between the key vectors of , i.e., the self-attention score, , , They are query weight matrix, key weight matrix and value weight matrix, is the scaling factor of the attention mechanism, Representing the jth word embedding right The influence weight of , L represents the total number of embedded words.
4. The method according to claim 1, characterized in that The first time step, the second time step and the third time step are consecutive time steps in sequence.
5. The method according to claim 4, characterized in that The first time step and the third time step are at least two time steps.
6. The method according to claim 2, characterized in that The first encoding vector sequence is generated by merging the word encoding vector, the sentence encoding vector and the position encoding vector, including: Aggregating the word encoding vectors according to the sentence encoding vector to obtain a first encoding vector subsequence to an Nth encoding vector subsequence; According to the position encoding vector, the first encoding vector subsequence to the Nth encoding vector subsequence are arranged from top to bottom to construct the first encoding vector sequence.
Citation Information
Patent Citations
CNN text classification method combined with multi-head self-attention mechanism
CN111259666A
Multi-modal sentiment recognition method based on Transformer-ESIM attention mechanism
CN112633364A
