Multi-feature fusion couplet generation method combining CNN and Transformer
By combining the multi-feature fusion couplet generation method of CNN and Transformer, the problem of loose antithesis and semantic incoherence in couplet generation is solved, the antithesis and semantic coherence of the couplet are improved, and the generated second couplet is closer to the effect of artificial creation. .
Patent Information
- Application Number
- CN202310499796.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-05-05
- Publication Date
- 2024-08-23
- Estimated Expiration
- 2043-05-05
AI Technical Summary
There are problems in the existing couplet generation methods such as the generation of lower couplets is not rigorous and the semantics are incoherent.
Using a multi-feature fusion couplet generation method that combines CNN and Transformer, by constructing a couplet corpus with part-of-speech features and oblique features, a multi-feature fusion word vector is constructed, and input into the CNN and Transformer models for feature extraction and semantic encoding, and finally in the Transformer The model's decoder predicts the next link.
The contrastiveness and semantic coherence of the couplets are improved, making the generated second couplet closer to the effect of artificial creation, with higher contrastivity and semantic fluency.
Smart Images

Figure CN116561254B
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of automatic generation of couplets, and in particular to a method for generating couplets by combining multi-feature fusion of CNN and Transformer. Background Art
[0002] Couplets have a long history. The structure and language of couplets are very distinctive and they have been loved by people since ancient times. However, the creation of couplets requires a certain literary foundation. It is difficult for ordinary people to create couplets easily. Therefore, the research on automatic creation of couplets has gradually emerged. On the one hand, the research on automatic creation of couplets reduces the difficulty of creation, and on the other hand, it promotes the research on Chinese generation tasks.
[0003] Existing methods for automatically generating couplets include: rule-based template methods, evolutionary algorithm-based methods, statistical machine translation-based methods, and deep learning-based methods.
[0004] The rule-based template method generates couplets through artificially set creation background and creation conditions. The generated couplets have poor robustness and the form and content of the couplets are too mechanical and rigid.
[0005] The method based on evolutionary algorithm generates couplets through evolutionary algorithm. The quality of the generated couplets is good, but the process of generating couplets takes a lot of time and space, and the work efficiency is low and the resource consumption is high.
[0006] The method based on statistical machine translation generates couplets by matching and translating a large amount of corpus. This method requires automatic learning of the corpus, and the quality of the generated couplets is also limited by the size and quality of the corpus.
[0007] The deep learning-based method generates couplets through deep learning knowledge. The generated couplets are of high quality, but this method also has problems such as the generated text is not rigorous and the semantics is incoherent.
[0008] The multi-feature fusion couplet generation method combining CNN and Transformer is a method based on deep learning. The word vector of multi-feature fusion is obtained by adding the part-of-speech features and level and oblique features of the couplet to the word vector, and the word vector is used as the input of CNN and Transformer. Finally, Transformer predicts and outputs the second line of the couplet. The multi-feature fusion word vector can improve the antithesis of the generated couplet; combining the CNN model and the Transformer model can strengthen the key information of the couplet and improve the semantic coherence of the generated couplet. Summary of the invention
[0009] The purpose of the present invention is to solve the problems of imprecise parallelism and incoherent semantics in the existing couplet generation methods, which is achieved by providing a multi-feature fusion couplet generation method combining CNN and Transformer.
[0010] The technical solution adopted by the present invention is a multi-feature fusion couplet generation method combining CNN and Transformer, comprising the following steps:
[0011] Step 1. In the data preprocessing stage, a couplet corpus with part-of-speech features and level-tone features is constructed respectively;
[0012] Step 2. Construct a multi-feature fusion word vector based on the first line of the couplet, combining part-of-speech features and level and oblique tone features.
[0013] Step 3. Input the multi-feature fusion word vector of the first line of the couplet into the CNN encoder and the encoder of the Transformer model respectively to extract the couplet features and encode the couplet semantics, and obtain the feature encoding vector and semantic encoding vector respectively.
[0014] Step 4. Combine the feature encoding vector and the semantic encoding vector and input them into the decoder of the Transformer model.
[0015] Step 5. The decoder of the Transformer model predicts and outputs the second couplet based on the couplet corpus.
[0016] Furthermore, in step 1, the couplet corpus with part-of-speech features and level-tone features is constructed as follows:
[0017] S11. Obtaining a couplet corpus;
[0018] S12. Segmenting the couplet data in the couplet corpus word by word;
[0019] S13. Use LTP (Language Technology Platfor) to perform part-of-speech feature tagging on the couplet corpus after word segmentation to obtain a couplet corpus with part-of-speech features;
[0020] S14. Use PyPinyin in Python to annotate the couplet corpus after word segmentation with pinyin, and then convert the pinyin into level and oblique tones according to the conversion rules between pinyin tones and level and oblique tones to obtain a couplet corpus with level and oblique tones features.
[0021] The conversion rule between pinyin tones and level and oblique tones is as follows: the first and second tones of pinyin tones are level tones, and the third and fourth tones of pinyin tones are oblique tones.
[0022] Furthermore, the process of constructing the multi-feature fusion word vector in step 2 is as follows:
[0023] S21. Segment the first line of the couplet word by word;
[0024] S22. constructing a semantic vector according to the segmented upper link data;
[0025] S23. Using LTP to perform part-of-speech feature tagging on each word of the upper couplet after word segmentation, and then constructing a part-of-speech feature vector based on the upper couplet data marked with part-of-speech features;
[0026] S24. PyPinyin is used to mark each word of the first couplet after the segmentation, and then the pinyin is converted into level and oblique features according to the conversion rules of pinyin tone and level and oblique tone, and the data of the first couplet marked with level and oblique features are obtained, and finally the level and oblique feature vector is constructed according to the data of the first couplet marked with level and oblique features;
[0027] S25. Concatenate the semantic vector, part-of-speech feature vector and level-tone feature vector in sequence according to a certain dimension to obtain a multi-feature fusion word vector.
[0028] Set the vector matrix of multi-feature fusion word vector to be X = [x 1 ,x 2 ,…x i ] T , where x i is the word vector of each word after the word segmentation of the first sentence of the couplet, x i =[x ii1 , x ii2 , …x iin ], where ii is the number of words in the first sentence of the couplet after word segmentation, and n is the word vector dimension.
[0029] Furthermore, the CNN encoder structure and feature encoding vector generation process in step 3 are as follows:
[0030] The CNN encoder consists of two convolutional layers, a pooling layer, and a fully connected layer.
[0031] The two convolutional layers use convolution kernels w of different sizes. k The first convolution layer uses multiple 1×1 convolution kernels w 1×1 Expand the depth of the neural network and strengthen nonlinearity, thereby enhancing the network's expressive power; the second convolutional layer uses multiple convolution kernels of different sizes w k The features of the couplet sentences are extracted as follows: 2×n ∈R 2×n 、w 3×n ∈R 3×n and w 4×n ∈R 4×n, where the width of the convolution kernel is consistent with the dimension of the word vector of each word in the input couplet sentence matrix X. This is to ensure that each convolution operation can scan the complete word vector of each word to avoid the loss of word features.
[0032] The first convolution layer uses multiple convolution kernels w 1×1 The input matrix X is convolved, and the output feature map c has the same shape as the input matrix X. The second convolution layer uses multiple convolution kernels w of different sizes. 2×n 、w 3×n and w 4×n Perform a convolution operation on the feature map c output by the first convolutional layer to obtain the feature map c * , and then input the feature map c* into the pooling layer, perform maximum pooling and average pooling operations respectively, and obtain the most representative features. The average pooling operation makes the features more comprehensive. The feature values obtained by the maximum pooling operation and the average pooling operation are fused, and all the fused feature values are concatenated to obtain the feature fusion vector. Finally, a fully connected layer is passed to generate the final feature encoding vector.
[0033] The first convolutional layer uses a 1×1 convolution kernel w 1×1 Perform convolution operation on matrix X, each convolution kernel is in word window X i:i+j-1 The eigenvalue c generated on l The calculation formula is:
[0034] c l =RELU(w 1×1 X i:i+j-1 +b) (1)
[0035] RELU = max(0, x)(2)
[0036] Where i represents the row of matrix X, j represents the height of the convolution kernel, and b is the bias term. 1×1 After traversing the entire couplet sentence matrix X, each convolution kernel will output a matrix containing multiple eigenvalues c l The feature map c has the same size as the matrix X.
[0037] Multiple convolution kernels w are used in the second convolution layer. 2×n 、w 3×n and w 4×n Perform convolution operation on feature map c, each convolution kernel is in feature map window c i:i+j-1 The eigenvalue c generated on p The calculation formula is:
[0038] c p =RELU(w k c i:i+j-1+b) (3)
[0039] Among them, i represents the row of matrix X, which is also represented as the height of feature map c, j represents the height of convolution kernel, and b is the bias term. k After traversing the entire feature map c, each convolution kernel will output a number of feature values c. p The feature map c * , feature map c * The size of is (i-j+1)×1.
[0040] The obtained feature map c * Passed to the pooling layer, the pooling layer performs feature map c * Perform maximum pooling and average pooling operations, and the calculation formula is as follows:
[0041]
[0042]
[0043] Formula (4) is the maximum pooling operation, and formula (5) is the average pooling operation. The size of the window for the maximum pooling operation and the average pooling operation is (i-j+1)×1, which is the same as the feature map c * The size is consistent, so the maximum eigenvalue obtained after the pooling operation and the average eigenvalue The size of each is 1×1.
[0044] The maximum eigenvalue and the average eigenvalue Fusion to get the eigenvalue The formula is as follows:
[0045]
[0046] Among them, 9(·) represents the fusion operation, and this paper adopts the direct addition fusion method.
[0047] All feature maps c * After performing the above pooling operation, all the obtained eigenvalues They are connected into a feature fusion vector e, the dimension of which is 1×v, where v represents the number of all convolution kernels in a convolution layer. Assuming the convolution kernel w 2×n 、w 3×n and w 4×n The number of is 10, then v = 10 × 3 = 30.
[0048] Input the feature fusion vector e into a fully connected layer to generate the feature encoding vector z:
[0049] z=RELU(eW+b) (7)
[0050] Among them, W is the weight parameter, b is the bias term, the dimension of z is 1×n, and n represents the word vector dimension of each word in the input matrix X.
[0051] Furthermore, the feature encoding vector and the semantic encoding vector in step 4 are combined and calculated as follows:
[0052] Semantic Encoding Vector Calculated by the encoder of the Transformer model, It is in matrix form, containing the encoding information of all the word vectors of the upper sentence. And the feature encoding vector is directly added, the formula is as follows:
[0053]
[0054]
[0055] I D =[I D1 ,I D2 ,…,I Di ] T (10)
[0056] Among them, W h and W z is a weight parameter, and i is the number of words in the couplet sentence after word segmentation. D is the new vector after the semantic encoding vector and the feature encoding vector are fused, and its dimension is Consistent.
[0057] The beneficial effects of the present invention are as follows: a multi-feature fusion couplet generation method combining CNN and Transformer is provided, and multi-feature fusion word vectors are introduced to enhance the length of the couplet; the CNN model and the Transformer model are combined to process the couplet upper link data, thereby enhancing the key information of the couplet and improving the semantic coherence of the generated couplet. BRIEF DESCRIPTION OF THE DRAWINGS
[0058] Figure 1 It is a structural diagram of the overall method implementation.
[0059] Figure 2 This is the structure diagram of the CNN encoder. DETAILED DESCRIPTION
[0060] The purpose of the present invention is to solve the problem of imprecise parallelism and incoherent semantics in the existing couplet generation methods, by providing a multi-feature fusion couplet generation method combining CNN and Transformer. Figure 1The present invention provides a method for generating a multi-feature fusion couplet by combining CNN and Transformer, comprising the following steps:
[0061] Step 1. In the data preprocessing stage, a couplet corpus with part-of-speech features and level-tone features is constructed respectively;
[0062] Step 2. Construct a multi-feature fusion word vector based on the first line of the couplet, combining part-of-speech features and level and oblique tone features.
[0063] The step inputs the multi-feature fusion word vector of the first line of the couplet into the CNN encoder and the encoder of the Transformer model respectively to perform couplet feature extraction and couplet semantic encoding, and obtains the feature encoding vector and the semantic encoding vector respectively.
[0064] Step 4. Combine the feature encoding vector and the semantic encoding vector and input them into the decoder of the Transformer model.
[0065] Step 5. The decoder of the Transformer model predicts and outputs the second couplet based on the couplet corpus.
[0066] Furthermore, in step 1, the couplet corpus with part-of-speech features and level-tone features is constructed as follows:
[0067] S11. Obtaining a couplet corpus;
[0068] S12. Segmenting the couplet data in the couplet corpus word by word;
[0069] S13 uses LTP (Language Technology Platform) released by the Social Computing and Information Retrieval Research Center of Harbin Institute of Technology to annotate the couplet corpus after word segmentation, and obtains a couplet corpus with part-of-speech features;
[0070] S14. Use PyPinyin in Python to annotate the couplet corpus after word segmentation with pinyin, and then convert the pinyin into level and oblique tones according to the conversion rules between pinyin tones and level and oblique tones to obtain a couplet corpus with level and oblique tones features.
[0071] The conversion rule between pinyin tones and level and oblique tones is as follows: the first and second tones of pinyin tones are level tones, and the third and fourth tones of pinyin tones are oblique tones.
[0072] Furthermore, the process of constructing the multi-feature fusion word vector in step 2 is as follows:
[0073] S21. Segment the first line of the couplet word by word;
[0074] S22. constructing a semantic vector according to the segmented upper link data;
[0075] S23 uses LTP to perform part-of-speech feature tagging on each word of the upper couplet after word segmentation, and then constructs a part-of-speech feature vector according to the upper couplet data marked with part-of-speech features;
[0076] S24. PyPinyin is used to mark each word of the first couplet after the segmentation, and then the pinyin is converted into level and oblique features according to the conversion rules of pinyin tone and level and oblique tone, and the data of the first couplet marked with level and oblique features are obtained, and finally the level and oblique feature vector is constructed according to the data of the first couplet marked with level and oblique features;
[0077] S25. Concatenate the semantic vector, part-of-speech feature vector and level-tone feature vector in sequence according to a certain dimension to obtain a multi-feature fusion word vector.
[0078] Set the vector matrix of multi-feature fusion word vector to be X = [x 1 , x 2 , …x i ] T , where x i is the word vector of each word after the word segmentation of the first sentence of the couplet, x i =[x ii1 , x ii2 , …x iin ], where ii is the number of words in the first sentence of the couplet after word segmentation, and n is the word vector dimension.
[0079] Furthermore, the CNN encoder structure and feature encoding vector generation process in step 3 are as follows:
[0080] The CNN encoder consists of two convolutional layers, a pooling layer, and a fully connected layer.
[0081] The two convolutional layers use convolution kernels w of different sizes. k The first convolution layer uses multiple 1×1 convolution kernels w 1×1 Expand the depth of the neural network and strengthen nonlinearity, thereby enhancing the network's expressive power; the second convolutional layer uses multiple convolution kernels of different sizes w k The features of the couplet sentences are extracted as follows: 2×n ∈R 2×n 、w 3×n ∈R 3×n and w 4×n ∈R 4×n , where the width of the convolution kernel is consistent with the dimension of the word vector of each word in the input couplet sentence matrix X. This is to ensure that each convolution operation can scan the complete word vector of each word to avoid the loss of word features.
[0082] The first convolution layer uses multiple convolution kernels w 1×1The input matrix X is convolved, and the output feature map c has the same shape as the input matrix X. The second convolution layer uses multiple convolution kernels w of different sizes. 2×n 、w 3×n and w 4×n Perform a convolution operation on the feature map c output by the first convolutional layer to obtain the feature map c*, and then convert the feature map c * Input to the pooling layer, perform maximum pooling operation and average pooling operation respectively. Figure 2 Here, M represents the maximum pooling operation, and A represents the average pooling operation. The maximum pooling operation obtains the most representative features, and the average pooling operation makes the features more comprehensive. The feature values obtained by the maximum pooling operation and the average pooling operation are fused, and all the fused feature values are concatenated to obtain the feature fusion vector. Finally, a fully connected layer is passed to generate the final feature encoding vector.
[0083] The first convolutional layer uses a 1×1 convolution kernel w 1×1 Perform convolution operation on matrix X, each convolution kernel is in word window X i:i+j-1 The eigenvalue c generated on l The calculation formula is:
[0084] c l =RELU(w 1×1 X i:i+j-1 +b) (1)
[0085] RELU = max(0, x) (2)
[0086] Where i represents the row of matrix X, j represents the height of the convolution kernel, and b is the bias term. 1×1 After traversing the entire couplet sentence matrix X, each convolution kernel will output a feature map c containing multiple eigenvalues cl, and the size of the feature map c is consistent with the matrix X.
[0087] Multiple convolution kernels w are used in the second convolution layer. 2×n 、w 3×n and w 4×n Perform convolution operation on feature map c, each convolution kernel is in feature map window c i:i+j-1 The calculation formula of the eigenvalue cp generated above is:
[0088] c p =RELU(w k c i:i+j-1 +b) (3)
[0089] Among them, i represents the height of feature map c, j represents the height of convolution kernel, and b is the bias term. k After traversing the entire feature map c, each convolution kernel will output a number of feature values c.p The feature map c * , feature map c * The size of is (i-j+1)×1.
[0090] The obtained feature map c * Passed to the pooling layer, the pooling layer performs feature map c * Perform maximum pooling and average pooling operations, and the calculation formula is as follows:
[0091]
[0092]
[0093] Formula (4) is the maximum pooling operation, and formula (5) is the average pooling operation. The size of the window for the maximum pooling operation and the average pooling operation is (i-j+1)×1, which is the same as the feature map c * The size is consistent, so the maximum eigenvalue obtained after the pooling operation and the average eigenvalue The size of each is 1×1.
[0094] The maximum eigenvalue and the average eigenvalue Fusion to get the eigenvalue The formula is as follows:
[0095]
[0096] Among them, g(·) represents the fusion operation, and this paper adopts the direct addition fusion method.
[0097] All feature maps c * After performing the above pooling operation, all the obtained eigenvalues concatenate into a feature fusion vector e, the dimension of the feature fusion vector e is 1×v, v represents the number of all convolution kernels in a convolution layer, assuming that the convolution kernel w 2×n 、w 3×n and w 4×n The number of is 10, then v = 10 × 3 = 30.
[0098] Input the feature fusion vector e into a fully connected layer to generate the feature encoding vector z:
[0099] z=RELU(eW+b) (7)
[0100] Among them, W is the weight parameter, b is the bias term, the dimension of z is 1×n, and n represents the word vector dimension of each word in the input matrix X.
[0101] Furthermore, the feature encoding vector and the semantic encoding vector in step 4 are combined and calculated as follows:
[0102] Semantic Encoding Vector Calculated by the encoder of the Transformer model, It is in matrix form, containing the encoding information of all the word vectors of the upper sentence. And the feature encoding vector is directly added, the formula is as follows:
[0103]
[0104]
[0105] I D =[I D1 ,I D2 ,…,I Di ] T (10)
[0106] Among them, W h and W z is a weight parameter, and i is the number of words in the couplet sentence after word segmentation. D is the new vector after the semantic encoding vector and the feature encoding vector are fused, and its dimension is Consistent.
[0107] Experimental data:
[0108] Multiple groups of experimental models are set up. Each experimental model uses the same environment, parameters and training methods, and is evaluated using BLEU and perplexity indicators. The higher the BLEU value, the better the effect, and the lower the perplexity, the better the effect.
[0109] The experimental model settings are as follows:
[0110] G: Couplet generation method combining attention mechanism and LSTM.
[0111] T: Basic Transformer couplet generation method.
[0112] TC: A couplet generation method combining CNN and Transformer.
[0113] TCF: A multi-feature fusion couplet generation method combining CNN and Transformer.
[0114] The experimental results of BLEU and perplexity are shown in the following table:
[0115]
[0116]
[0117] As can be seen from the above table, in terms of both evaluation indicators, the multi-feature fusion couplet generation method combining CNN and Transformer performs best. The performance of the couplet generation method combining CNN and Transformer is better than the basic Transformer couplet generation method, and the basic Transformer couplet generation method performs better than the couplet generation method combining attention mechanism and LSTM.
[0118] Therefore, the combination of multi-feature fusion word embedding and CNN and Transformer can effectively improve the model's ability to predict and generate the lower couplet, making the generated lower couplet more rigorous and semantically fluent with the input upper couplet, and the generated lower couplet closer to the manually created lower couplet.
[0119] The following table is an example of couplet generation using the multi-feature fusion couplet generation method that combines CNN and Transformer:
[0120]
Claims
1. A multi-feature fusion couplet generation method combining CNN and Transformer, characterized in that: The following steps are involved: Step 1. In the data preprocessing stage, a couplet corpus with part-of-speech features and level-tone features is constructed respectively; Step 2: Construct a multi-feature fusion word vector combining part-of-speech features and level and oblique tone features according to the first line of the couplet; Step 3. Input the multi-feature fusion word vector of the first couplet into the CNN encoder and the encoder of the Transformer model respectively to extract the couplet features and encode the couplet semantics, and obtain the feature encoding vector and the semantic encoding vector respectively; Step 4. Combine the feature encoding vector and the semantic encoding vector and input them into the decoder of the Transformer model; Step 5. The decoder of the Transformer model predicts and outputs the second couplet based on the couplet corpus; In step 1, the couplet corpus with part-of-speech features and level-tone features is constructed as follows: S11. Obtaining a couplet corpus; S12. Segmenting the couplet data in the couplet corpus word by word; S13. Using LTP to perform part-of-speech feature tagging on the couplet corpus after word segmentation, to obtain a couplet corpus with part-of-speech features; S14. Use PyPinyin in Python to annotate the couplet corpus after word segmentation with pinyin, and then convert the pinyin into level and oblique tones according to the conversion rules of pinyin tone and level and oblique tones to obtain a couplet corpus with level and oblique tones; The conversion rules between Pinyin tones and level and oblique tones are as follows: the first and second tones of Pinyin tones are level tones, and the third and fourth tones of Pinyin tones are oblique tones; The process of constructing multi-feature fusion word vectors in step 2 is as follows: S21. Segment the first line of the couplet word by word; S22. constructing a semantic vector according to the segmented upper link data; S23. Using LTP to perform part-of-speech feature tagging on each word of the upper couplet after word segmentation, and then constructing a part-of-speech feature vector based on the upper couplet data marked with part-of-speech features; S24. PyPinyin is used to mark each word of the first couplet after the segmentation, and then the pinyin is converted into level and oblique features according to the conversion rules of pinyin tone and level and oblique tone, and the data of the first couplet marked with level and oblique features are obtained, and finally the level and oblique feature vector is constructed according to the data of the first couplet marked with level and oblique features; S25. concatenate the semantic vector, the part-of-speech feature vector, and the level-tone feature vector in sequence according to a certain dimension to obtain a multi-feature fusion word vector; Set the vector matrix of multi-feature fusion word vector to be X = [x1, x2, ... x i ] T , where x i is the word vector of each word after the word segmentation of the first sentence of the couplet, x i =[x ii1 ,x ii2 ,…x iin ], where ii is the number of words in the first sentence of the couplet after word segmentation, and n is the word vector dimension; The CNN encoder structure and feature encoding vector generation process in step 3 are as follows: The CNN encoder consists of two convolutional layers, a pooling layer, and a fully connected layer; The two convolutional layers use convolution kernels w of different sizes. k Perform feature encoding; The first convolutional layer uses multiple 1×1 convolution kernels w 1×1 Expand the depth of the neural network and strengthen nonlinearity, thereby enhancing the network's expressive power; the second convolutional layer uses multiple convolution kernels of different sizes w k The features of the couplet sentences are extracted as follows: 2×n ∈R 2×n 、w 3×n ∈R 3×n and w 4×n ∈R 4 ×n , the width of the convolution kernel is consistent with the dimension of the word vector of each word in the input couplet sentence matrix X; The first convolution layer uses multiple convolution kernels w 1×1 The input matrix X is convolved, and the output feature map c has the same shape as the input matrix X. The second convolution layer uses multiple convolution kernels w of different sizes. 2×n 、w 3×n and w 4×n Perform a convolution operation on the feature map c output by the first convolutional layer to obtain the feature map c * , and then the feature map c * The data is input into the pooling layer, and the maximum pooling operation and the average pooling operation are performed respectively to obtain the most representative features. The average pooling operation makes the obtained features more comprehensive. The feature values obtained by the maximum pooling operation and the average pooling operation are fused, and all the fused feature values are concatenated to obtain the feature fusion vector. Finally, a fully connected layer is passed to generate the final feature encoding vector. The first convolutional layer uses a 1×1 convolution kernel w 1×1 Perform convolution operation on matrix X, each convolution kernel is in word window X i:i+j-1 The eigenvalue c generated on l The calculation formula is: c l =RELU(w 1×1 X i:i+j-1 +b) (1) RELU = max(0, x) (2) Among them, i represents the row of matrix X, j represents the height of the convolution kernel, and b is the bias term; when the convolution kernel w 1×1 After traversing the entire couplet sentence matrix X, each convolution kernel will output a matrix containing multiple eigenvalues c l The feature map c has the same size as the matrix X; Multiple convolution kernels w are used in the second convolution layer. 2×n 、w 3×n and w 4×n Perform convolution operation on feature map c, each convolution kernel is in feature map window c i:i+j-1 The eigenvalue c generated on p The calculation formula is: C p =RELU(in k c i:i+j-1 +b) (3) Among them, i represents the row of matrix X, which is also represented as the height of feature map c, j represents the height of convolution kernel, and b is the bias term; when convolution kernel w k After traversing the entire feature map c, each convolution kernel will output a number of feature values c. p The feature map c * , feature map c * The size of is (i-j+1)×1; The obtained feature map c * Passed to the pooling layer, the pooling layer performs feature map c * Perform maximum pooling and average pooling operations, and the calculation formula is as follows: Formula (4) is the maximum pooling operation, and formula (5) is the average pooling operation. The size of the window for the maximum pooling operation and the average pooling operation is (i-j+1)×1, which is the same as the feature map c * The size is consistent, so the maximum eigenvalue obtained after the pooling operation and the average eigenvalue The size of each is 1×1; The maximum eigenvalue and the average eigenvalue Fusion to get the eigenvalue The formula is as follows: Among them, g(·) represents the fusion operation; All feature maps c * After performing the above pooling operation, all the obtained eigenvalues The feature fusion vector e is concatenated into a feature fusion vector. The dimension of the feature fusion vector e is 1×v, where v represents the number of all convolution kernels in a convolution layer and the convolution kernel w 2×n 、w 3 ×n and w 4×n The number of is 10, then v = 10 × 3 = 30; Input the feature fusion vector e into a fully connected layer to generate the feature encoding vector z: Z=RELU(eW+b) (7) Among them, W is the weight parameter, b is the bias term, the dimension of z is 1×n, and n represents the word vector dimension of each word in the input matrix X; The feature encoding vector and semantic encoding vector in step 4 are combined and calculated as follows: Semantic Encoding Vector Calculated by the encoder of the Transformer model, It is in matrix form, containing the encoding information of all the word vectors of the upper sentence; the semantic encoding vector And the feature encoding vector is directly added, the formula is as follows: I D =[I D1 、I D2 、...、I Di ] T (10) Among them, W h and W z is a weight parameter, i is the number of words in the couplet sentence after word segmentation; I D is the new vector after the semantic encoding vector and the feature encoding vector are fused, and its dimension is Consistent.
