A multi-channel method and device for adding sequence position information to text features
By introducing a multi-channel linear correlation feature module that attenuates by position in the neural network model, the position information of the sequence is combined with the text features, which solves the problems of low prediction accuracy and slow operation speed of the neural network model, and achieves more efficient predictions. and training effects.
Patent Information
- Application Number
- CN202410831459.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-26
- Publication Date
- 2024-09-03
- Estimated Expiration
- 2044-06-26
AI Technical Summary
Existing neural network models suffer from poor prediction accuracy and slow operation speed.
By introducing a multi-channel linear correlation feature module that attenuates by position in the neural network model, the position information of the sequence is combined with text features, and different weights are used for linear transformation and fusion to improve the prediction accuracy and convergence speed of the model.
Significantly improves the prediction accuracy and training speed of the neural network model, and improves the overall performance of the model.
Smart Images

Figure CN118378593B
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computers, and in particular to a multi-channel method and device for adding sequence position information to text features. Background Art
[0002] Natural Language Processing (NLP) is an interdisciplinary subject that lies at the intersection of computer science, artificial intelligence, and linguistics. It aims to enable computers to understand, interpret, and generate human natural language. With the rapid development of information technology and the explosive growth of Internet data, natural language processing technology has become increasingly important and is widely used in various scenarios, from smart assistants, machine translation, and sentiment analysis in daily communication to document summarization, information extraction, and intelligent customer service in professional fields.
[0003] The development of natural language processing models is a major milestone in the field of artificial intelligence. Their evolutionary history has witnessed the transition from rule-based methods to statistical learning models, and then to the deep learning models that are widely used today.
[0004] Although existing natural language processing (NLP) models have made significant progress, they still face the problem of poor prediction accuracy of neural network models. Summary of the invention
[0005] The present invention provides a multi-channel method and device for adding sequence position information to text features, so as to solve the problems of low prediction accuracy and slow operation speed of the existing neural network model.
[0006] In a first aspect, the present invention provides a multi-channel method for adding sequence position information to text features, which specifically comprises the following steps:
[0007] Step S1, constructing a neural network model;
[0008] Step S2, inputting token_emb generated by text segmentation and text encoding into the neural network model, and performing calculation by the neural network model;
[0009] Step S3: output the result of the neural network model calculation.
[0010] The number of tokens in the token_emb is L, where L is a positive integer.
[0011] Preferably, the neural network model specifically includes the following modules:
[0012] The norm module is used to normalize token_emb to form sequence A;
[0013] The layer module is used to transform the sequence A through multiple linear transformations with different weights to form n sets of feature sequences B={b1,b2,...,b n};
[0014] The multi-channel linear correlation feature module with position attenuation is used to multiply the relative position relationship between each token in each sequence in sequence B by different weights, and then calculate the probability value of different weight distribution to form a sequence C={c1,c2,...,c n};
[0015] The Linear Layer module is used to stack and linearly transform the multi-channel sequence features of sequence C to form a sequence D = {d1, d2, ..., d n};
[0016] The F(abc) module is used to fuse the sequence features of sequence D to form a sequence E={e1,e2,...,e n};
[0017] The first feature superposition module is used to superimpose the features of token_emb and sequence E to form a sequence F={f1,f2,...,f n};
[0018] The MLP module is used to increase the nonlinear representation ability of features through multi-layer linear perceptrons and nonlinear activation functions to form a sequence G={g1,g2,...,g n}; The second feature superposition module is used to superimpose the features of sequence F and sequence G to form a sequence H={h1,h2,...,h n}.
[0019] Wherein, n is a positive integer.
[0020] Preferably, in the neural network model, the number of layer modules, multi-channel linear correlation feature modules with position attenuation and Linear Layer modules is n, and a layer module, a multi-channel linear correlation feature module with position attenuation and a Linear Layer module form a link, forming a total of n parallel links.
[0021] Preferably, the first end of the n parallel-connected links is the norm module, and the second end is the F(abc) module.
[0022] More preferably, each of the links sequentially connects a layer module, a multi-channel linear correlation feature module with position attenuation, and a Liner Layer module from the first end to the second end.
[0023] Preferably, in the n parallel-connected links, the input of each link is sequence A.
[0024] Preferably, the norm module subtracts the mean of the token_emb data from each data in token_emb, and then divides it by the variance of the token_emb data to achieve data normalization.
[0025] Preferably, each of the multi-channel linear correlation feature modules attenuated by position includes M parallel single-channel linear correlation feature submodules attenuated by position, and each of the single-channel linear correlation feature submodules attenuated by position is different and has different weight heads. z .
[0026] Wherein, M is greater than or equal to 2, and M is a positive integer.
[0027] Preferably, the weight head in the linear correlation feature submodule with single channel attenuation by position z , the calculation formula is as follows:
[0028] head z =P -Q / z
[0029] Among them, z [1,M], z, P, and Q are all positive integers.
[0030] Preferably, the single-channel position-attenuated linear correlation feature module is used to pass each sequence b in sequence B. i After the relative position relationship between each token in is multiplied by different weights, the probability values of different weight distributions are calculated to form a sequence C, which specifically includes the following steps:
[0031] Step a: Get the i-th sequence b i ={b i1 ,b i2 ,...,b iL};
[0032] Step b: Get sequence b i Sequence features Feature i ={Feature i1 ,Feature i2 ,...,Feature iL};
[0033] Step c: According to sequence b i Construct position information cum_mask matrix pos i ={pos i1 ,posi2 ,...,pos iL};
[0034] Step d: Sequence b i The cum_mask matrix pos i ={pos i1 ,pos i2 ,...,pos iL} and weights Head={head1,head2,...,head M}After multiplication, the sequence pos is formed i-Head ={pos i1 ×head1,pos i1 ×head2,...,pos iL ×head M-1 ,pos iL ×head M};
[0035] Step e: sequence pos i-Head Perform softmax operation to form sequence prob i-Head ={prob i1-head1 ,...,prob i1-headM ,...,prob iL-head1 ,...,prob iL-headM};
[0036] Step f: Sequence prob i-Head and sequence features i Multiply them to form the sequence c i .
[0037] Among them, i [1,n], i is a positive integer.
[0038] Preferably, in step b, sequence b is extracted by a deep neural network i sequence characteristics.
[0039] Preferably, in step c, the cum_mask matrix is generated as follows: the current token position is encoded as 0, the current token position is encoded as 1 in a relative position, and the current token position is filled as 0 in a relative position. , generate relative position information.
[0040] Wherein, the cum_mask matrix is expressed as follows:
[0041]
[0042] Among them, j [1,L], j is a positive integer.
[0043] Preferably, in step e, the softmax operation is specifically as follows:
[0044]
[0045] Among them, r [1,s],t [1,T], r, t, T are all positive integers, T represents the number of input data (e.g. sequence prob i-Head ={prob i1-head1 ,...,prob i1-headM ,...,prob iL-head1 ,...,prob iL-headM}T is L×M).
[0046] Among them, y represents the softmax input, y t Represents the value of the tth data, y r Represents the value of the rth data.
[0047] Preferably, in step f, the sequence Feature i and prob i-Head Perform multiplication operation. The specific calculation formula is as follows:
[0048]
[0049]
[0050] Among them, Feature ij _Combine_head z Represents the relative position information matrix cum_mask matrix of the jth token of the i-th sequence multiplied by different weights and the sequence feature Feature of the jth token of the i-th sequence ij The sequence obtained after fusion.
[0051] Among them, prob ij-headz Represents the relative position information of the jth token in the i-th sequence multiplied by the weight head z , and obtain the weighted relative position information.
[0052] in, The multiplication operation represented by , the multiplication process represented by it is as follows:
[0053]
[0054] That is, the M relative position information matrices with different weights of the i-th sequence are multiplied by the sequence features of the sequence respectively.
[0055] Preferably, when n=3, the calculation of the F(abc) module is expressed as: F(abc)=d1+d1×d2-d2×token_emb-d2×A.
[0056] Preferably, in the MLP module, the nonlinear activation function includes nonlinear activation functions such as SiLU and GeLU.
[0057] In a second aspect, the present invention provides a multi-channel device for adding sequence position information to text features, which specifically includes the following modules:
[0058] Model building module, used to build neural network models;
[0059] Input acquisition module, used to generate token_emb through text segmentation and text encoding;
[0060] Model calculation module, used to calculate token_emb through the neural network model;
[0061] The result output module is used to output the results calculated by the neural network model.
[0062] The number of tokens in the token_emb is L, where L is a positive integer.
[0063] Preferably, the neural network model specifically includes the following modules:
[0064] The norm module is used to normalize token_emb to form sequence A;
[0065] The layer module is used to transform the sequence A through multiple linear transformations with different weights to form n sets of feature sequences B={b1,b2,...,b n};
[0066] The multi-channel linear correlation feature module with position attenuation is used to multiply the relative position relationship between each token in each sequence in sequence B by different weights, and then calculate the probability value of different weight distribution to form a sequence C={c1,c2,...,c n};
[0067] The Linear Layer module is used to stack and linearly transform the multi-channel sequence features of sequence C to form a sequence D = {d1, d2, ..., d n};
[0068] The F(abc) module is used to fuse the sequence features of sequence D to form a sequence E={e1,e2,...,e n};
[0069] The first feature superposition module is used to superimpose the features of token_emb and sequence E to form a sequence F={f1,f2,...,f n};
[0070] The MLP module is used to increase the nonlinear representation ability of features through multi-layer linear perceptrons and nonlinear activation functions to form a sequence G={g1,g2,...,g n};
[0071] The second feature superposition module is used to superimpose the features of sequence F and sequence G to form a sequence H={h1,h2,...,h n}.
[0072] Wherein, n is a positive integer.
[0073] Preferably, in the neural network model, the number of layer modules, multi-channel linear correlation feature modules with position attenuation and Linear Layer modules is n, and a layer module, a multi-channel linear correlation feature module with position attenuation and a Linear Layer module form a link, forming a total of n parallel links.
[0074] Preferably, the first end of the n parallel-connected links is the norm module, and the second end is the F(abc) module.
[0075] More preferably, each of the links sequentially connects a layer module, a multi-channel linear correlation feature module with position attenuation, and a Liner Layer module from the first end to the second end.
[0076] Preferably, in the n parallel-connected links, the input of each link is sequence A.
[0077] Preferably, the norm module subtracts the mean of the token_emb data from each data in token_emb, and then divides it by the variance of the token_emb data to achieve data normalization.
[0078] Preferably, each of the multi-channel linear correlation feature modules attenuated by position includes M parallel single-channel linear correlation feature submodules attenuated by position, and each of the single-channel linear correlation feature submodules attenuated by position is different and has different weight heads. z . Wherein, M is greater than or equal to 2, and M is a positive integer.
[0079] Preferably, the weight head in the linear correlation feature submodule with single channel attenuation by position z , the calculation formula is as follows:
[0080] head z =P -Q / z
[0081] Among them, z [1,M], z, P, and Q are all positive integers.
[0082] Preferably, the linear correlation feature submodule of the single channel attenuated by position specifically includes the following submodules:
[0083] Sequence acquisition module, used to obtain the i-th sequence b i ={b i1 ,b i2 ,...,b iL};
[0084] Sequence feature acquisition module, used to obtain sequence b i Sequence features Feature i ={Feature i1 ,Feature i2 ,...,Feature iL};
[0085] The position information matrix constructs the Sun module, which is used to calculate the position information matrix according to the sequence b. i Construct position information cum_mask matrix pos i ={pos i1 ,pos i2 ,...,pos iL};
[0086] The first processing module is used to convert sequence b i The cum_mask matrix pos i ={pos i1 ,pos i2 ,...,pos iL} and weights Head={head1,head2,...,head M}After multiplication, the sequence pos is formed i-Head ={pos i1 ×head1,pos i1 ×head2,...,pos iL ×head M-1 ,pos iL ×head M};
[0087] The second processing module is used to process the sequence pos i-Head Perform softmax operation to form sequence prob i-Head ={prob i1-head1 ,...,prob i1-headM ,...,prob iL-head1 ,...,prob iL-headM};
[0088] Feature fusion module is used to transform sequence prob i-Head and sequence features i Multiply them to form the sequence c i .
[0089] Among them, i [1,n], i is a positive integer.
[0090] Preferably, in the sequence feature acquisition module, the sequence b is extracted by a deep neural network. i sequence characteristics.
[0091] Preferably, in the position information matrix construction module, the cum_mask matrix is generated as follows: the current token position is encoded as 0, the current token position is decremented by 1 for relative position encoding, and the current token position is filled backward , generate relative position information.
[0092] Wherein, the cum_mask matrix is expressed as follows:
[0093]
[0094] Among them, j [1,L], j is a positive integer.
[0095] Preferably, in the second processing module, the softmax operation is specifically as follows:
[0096]
[0097] Among them, r [1,s],t [1,T], r, t, T are all positive integers, T represents the number of input data (e.g. sequence prob i-Head ={prob i1-head1 ,...,prob i1-headM ,...,prob iL-head1 ,...,prob iL-headM}T is L×M).
[0098] Among them, y represents the softmax input, y t Represents the value of the tth data, y r Represents the value of the rth data.
[0099] Preferably, in the feature fusion module, the sequence Feature i and prob i-Head Perform multiplication operation. The specific calculation formula is as follows:
[0100]
[0101]
[0102] Among them, Feature ij _Combine_head z Represents the relative position information matrix cum_mask matrix of the jth token of the i-th sequence multiplied by different weights and the sequence feature Feature of the jth token of the i-th sequence ij The sequence obtained after fusion.
[0103] Among them, prob ij-headz Represents the relative position information of the jth token in the i-th sequence multiplied by the weight head z , and obtain the weighted relative position information.
[0104] in, The multiplication operation represented by , the multiplication process represented by it is as follows:
[0105]
[0106] That is, the M relative position information matrices with different weights of the i-th sequence are multiplied by the sequence features of the sequence respectively.
[0107] Preferably, when n=3, the calculation of the F(abc) module is expressed as: F(abc)=d1+d1×d2-d2×token_emb-d2×A.
[0108] Preferably, in the MLP module, the nonlinear activation function includes nonlinear activation functions such as SiLU and GeLU.
[0109] In a third aspect, the present invention further provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements a multi-channel method for adding sequence position information to text features as described in any one of the first aspects of the present application.
[0110] In a fourth aspect, the present invention further provides an electronic device, comprising: a memory storing a computer program; and a processor communicatively connected to the memory, for executing a multi-channel method for adding sequence position information to text features as described in any one of the first aspects of the present application when the computer program is called.
[0111] Compared with the prior art, the present invention has the following obvious outstanding substantive features and significant advantages:
[0112] The present invention provides a multi-channel method and device for adding sequence position information to text features to solve the problems of poor model prediction accuracy and slow convergence speed in existing neural network models. By rationally planning the structure of the neural network model, the sequence position data information and the text feature data information are fused in combination with different static weights, thereby improving the prediction accuracy and convergence speed of the neural network model. BRIEF DESCRIPTION OF THE DRAWINGS
[0113] The accompanying drawings, which constitute part of the present invention, are used to provide a further understanding of the present invention. The exemplary embodiments of the present invention and their descriptions are used to explain the present invention and do not constitute improper limitations on the present invention. In the accompanying drawings:
[0114] Figure 1 The present invention is a flowchart of a multi-channel method for adding sequence position information to text features according to a preferred embodiment of the present invention.
[0115] Figure 2 It is a flowchart of the specific implementation steps of a multi-channel linear correlation feature module with positional attenuation in a multi-channel method for adding sequence position information to text features in a preferred embodiment of the present invention.
[0116] Figure 3 It is a schematic diagram of the structure of a multi-channel device for adding sequence position information to text features in a preferred embodiment of the present invention.
[0117] Figure 4 It is a schematic diagram of the structure of a linear correlation feature submodule with positional attenuation in a single channel in a multi-channel device for adding sequence position information to text features in a preferred embodiment of the present invention.
[0118] Figure 5 It is a structural diagram of a neural network model according to a preferred embodiment of the present invention.
[0119] Figure 6 It is a comparison chart of the training accuracy results of the neural network model of the preferred embodiment of the present invention. DETAILED DESCRIPTION
[0120] The present invention provides a multi-channel method and device for adding sequence position information to text features. In order to make the purpose, technical solution and effect of the present invention clearer and more specific, the present invention is further described in detail with reference to the accompanying drawings and examples. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not intended to limit the present invention.
[0121] It should be noted that the terms "first", "second", etc. in the specification and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchanged under appropriate circumstances. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions. For example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0122] Embodiment 1:
[0123] like Figure 1-Figure 2 , Figure 5-Figure 6 As shown, the multi-channel method for adding sequence position information to text features described in this embodiment specifically includes steps S1 to S3.
[0124] Step S1, constructing a neural network model.
[0125] Step S2: input token_emb generated by text segmentation and text encoding into the neural network model, and perform calculations through the neural network model.
[0126] The number of tokens in the token_emb is L, where L is a positive integer.
[0127] Optionally, the neural network model specifically includes the following modules.
[0128] The norm module is used to normalize token_emb to form sequence A.
[0129] Optionally, the norm module subtracts the mean of the token_emb data from each data in token_emb, and then divides the result by the variance of the token_emb data to achieve data normalization.
[0130] The layer module is used to transform the sequence A through multiple linear transformations with different weights to form n sets of feature sequences B={b1,b2,...,b n}.
[0131] The multi-channel linear correlation feature module with position attenuation is used to multiply the relative position relationship between each token in each sequence in sequence B by different weights, and then calculate the probability value of different weight distribution to form a sequence C={c1,c2,...,c n}.
[0132] Optionally, each of the multi-channel linear correlation feature modules attenuated by position includes M parallel single-channel linear correlation feature submodules attenuated by position, and each of the single-channel linear correlation feature submodules attenuated by position is different and has different weight heads. z .
[0133] Wherein, M is greater than or equal to 2, and M is a positive integer.
[0134] Optionally, the weight head in the linear correlation feature submodule of the single channel attenuated by position z , the calculation formula is as follows.
[0135] head z =P -Q / z
[0136] Among them, z [1,M], z, P, and Q are all positive integers.
[0137] Optionally, the single-channel position-attenuated linear correlation feature module is used to pass each sequence b in sequence B i After the relative position relationship between each token in is multiplied by different weights, the probability values of different weight distributions are calculated to form a sequence C, which specifically includes steps a to f.
[0138] Step a: Get the i-th sequence b i ={b i1 ,b i2 ,...,b iL}.
[0139] Among them, i [1,n], i is a positive integer.
[0140] Step b: Get sequence b i Sequence features Feature i ={Feature i1 ,Feature i2 ,...,Feature iL}.
[0141] Optionally, in step b, sequence b is extracted by a deep neural network i sequence characteristics.
[0142] Step c: According to sequence b i Construct position information cum_mask matrix pos i ={pos i1 ,pos i2 ,...,pos iL}.
[0143] Optionally, in step c, the cum_mask matrix is generated as follows: the current token position is encoded as 0, the current token position is decremented by 1 to perform relative position encoding, and the current token position is filled backward , generate relative position information.
[0144] Among them, the cum_mask matrix is expressed as follows.
[0145]
[0146] Among them, j [1,L], j is a positive integer.
[0147] Step d: Sequence b i The cum_mask matrix pos i ={pos i1 ,pos i2 ,...,pos iL} and weights Head={head1,head2,...,head M}After multiplication, the sequence pos is formed i-Head ={pos i1 ×head1,pos i1 ×head2,...,pos iL ×head M-1 ,pos iL ×head M}.
[0148] Step e: sequence pos i-Head Perform softmax operation to form sequence prob i-Head ={prob i1-head1 ,...,prob i1-headM ,...,prob iL-head1 ,...,prob iL-headM}.
[0149] Optionally, in step e, the softmax operation is specifically as follows:
[0150]
[0151] Among them, r [1,s],t [1,T], r, t, T are all positive integers, T represents the number of input data (e.g. sequence prob i-Head ={prob i1-head1 ,...,prob i1-headM ,...,prob iL-head1 ,...,prob iL-headM}T is L×M).
[0152] Among them, y represents the softmax input, y t Represents the value of the tth data, y r Represents the value of the rth data.
[0153] Step f: Sequence prob i-Head and sequence features i Multiply them to form the sequence c i .
[0154] Optionally, in step f, the sequence Feature i and prob i-Head Perform multiplication operation. The specific calculation formula is as follows:
[0155]
[0156]
[0157] Among them, Feature ij _Combine_head z Represents the relative position information matrix cum_mask matrix of the jth token of the i-th sequence multiplied by different weights and the sequence feature Feature of the jth token of the i-th sequence ij The sequence obtained after fusion.
[0158] Among them, prob ij-headz Represents the relative position information of the jth token in the i-th sequence multiplied by the weight head z , and obtain the weighted relative position information.
[0159] in, The multiplication operation represented by , the multiplication process represented by is as follows.
[0160]
[0161] That is, the M relative position information matrices with different weights of the i-th sequence are multiplied by the sequence features of the sequence respectively.
[0162] The Linear Layer module is used to stack and linearly transform the multi-channel sequence features of sequence C to form a sequence D = {d1, d2, ..., d n}.
[0163] The F(abc) module is used to fuse the sequence features of sequence D to form a sequence E={e1,e2,...,e n}.
[0164] For example, when n=3, the calculation of the F(abc) module is expressed as: F(abc)=d1+d1×d2-d2×token_emb-d2×A.
[0165] The first feature superposition module is used to superimpose the features of token_emb and sequence E to form a sequence F={f1,f2,...,f n}.
[0166] The MLP module is used to increase the nonlinear representation ability of features through multi-layer linear perceptrons and nonlinear activation functions to form a sequence G={g1,g2,...,g n}.
[0167] Optionally, in the MLP module, the nonlinear activation function includes nonlinear activation functions such as SiLU and GeLU.
[0168] The second feature superposition module is used to superimpose the features of sequence F and sequence G to form a sequence H={h1,h2,...,h n}.
[0169] Wherein, n is a positive integer.
[0170] Optionally, in the neural network model, the number of layer modules, multi-channel linear correlation feature modules with position attenuation and Linear Layer modules is n. A layer module, a multi-channel linear correlation feature module with position attenuation and a Linear Layer module form a link, forming a total of n parallel links.
[0171] Optionally, the first end of the n parallel-connected links is the norm module, and the second end is the F(abc) module.
[0172] Optionally, each of the links is connected to a layer module, a multi-channel linear correlation feature module with position attenuation, and a Liner Layer module in sequence from the first end to the second end.
[0173] Optionally, among the n parallel-connected links, the input of each link is sequence A.
[0174] The specific calculation process of the feature fusion is taken as an example of “The weather is very good today.”
[0175] The token segmentation result of "The weather is very good today." is: today / the weather is / is very good / . (The period is also 1 token).
[0176] The corresponding cum_mask matrix is generated by encoding the current token position as 0, encoding the current token position forward by 1 in a relative position decreasing, and filling the current token position backward. , generate relative position information.
[0177] For this embodiment, the cum_mask matrix is as follows:
[0178]
[0179] Step 1. Record the sequence features extracted by the deep neural network as: Feature=[Feature 今天 、Feature 天气 、Feature 很好 、Feature 。 ].
[0180] Step 2, taking the token "very good" as an example, obtain the position information of the token "very good". The position information of the token "very good" is pos=[-2,-1,0, ].
[0181] Step 3, multiply each weight respectively, and then perform softmax operation to obtain the feature weights of different positions and different heads. In this embodiment, P is 2 and Q is 8. The calculation results are as follows:
[0182] prob head1 =softmax(pos×m1)=softmax(pos×2 -8 / 1 )=[0.3320,0.3333,0.3346,0]
[0183] prob head2 =softmax(pos×m2)=softmax(pos×2 -8 / 2 )=[0.3127,0.3329,0.3544,0]
[0184] probhead3 =softmax(pos×m3)=softmax(pos×2 -8 / 3 )=[0.2824,0.3306,0.3870,0]
[0185] prob head4 =softmax(pos×m4)=softmax(pos×2 -8 / 4 )=[0.2543,0.3265,0.4192,0]
[0186] prob head5 =softmax(pos×m5)=softmax(pos×2 -8 / 5 )=[0.2312,0.3216,0.4472,0]
[0187] prob head6 =softmax(pos×m6)=softmax(pos×2 -8 / 6 )=[0.2128,0.3165,0.4707,0]
[0188] prob head7 =softmax(pos×m7)=softmax(pos×2 -8 / 7 )=[0.1982,0.3117,0.4902,0]
[0189] prob head8 =softmax(pos×m8)=softmax(pos×2 -8 / 8 )=[0.1863,0.3072,0.5065,0]
[0190] Step 4: For each linear correlation feature module with position attenuation in each single channel, perform multiplication operation on prob and Feature by position to generate fusion features. The calculation is as follows:
[0191]
[0192]
[0193]
[0194] Step 5: Stack the fused features generated by the linear correlation feature modules of each single channel attenuated by position, and further fuse them through a linear fully connected layer.
[0195] Feature_Combine 很好 =Linear_Layer([Feature_Combine_head_1 很好 ,...,Feature_Combine_head_8 很好 ])
[0196] Step S3: output the result of the neural network model calculation.
[0197] The convergence curve of the training is used to compare the effect of the solution proposed in this application. The same batch of data sets are obtained for training, such as Figure 6 As shown, the horizontal axis represents the number of iterations of training, and the vertical axis represents the loss value of training data. The yellow curve is a convergence curve of the loss value of the neural network model training based on the multi-channel method of adding sequence position information to text features according to the present invention, and the blue curve is a convergence curve of the loss value of the neural network model training based on comparison. Figure 6 It can be seen that the solution proposed in the present invention has obvious advantages in model training efficiency and training speed.
[0198] Embodiment 2:
[0199] like Figure 3-4 As shown, a multi-channel device for adding sequence position information to text features described in this embodiment specifically includes the following modules.
[0200] Model building module, used to build neural network models.
[0201] Optionally, the neural network model specifically includes the following modules.
[0202] The norm module is used to normalize token_emb to form sequence A.
[0203] Wherein, the token_emb is obtained by inputting an acquisition module.
[0204] Optionally, the input acquisition module generates token_emb through text segmentation and text encoding.
[0205] The number of tokens in the token_emb is L, where L is a positive integer.
[0206] The layer module is used to transform the sequence A through multiple linear transformations with different weights to form n sets of feature sequences B={b1,b2,...,b n}.
[0207] The multi-channel linear correlation feature module with position attenuation is used to multiply the relative position relationship between each token in each sequence in sequence B by different weights, and then calculate the probability value of different weight distribution to form a sequence C={c1,c2,...,c n}.
[0208] The Linear Layer module is used to stack and linearly transform the multi-channel sequence features of sequence C to form a sequence D = {d1, d2, ..., d n};
[0209] The F(abc) module is used to fuse the sequence features of sequence D to form a sequence E={e1,e2,...,e n}.
[0210] The first feature superposition module is used to superimpose the features of token_emb and sequence E to form a sequence F={f1,f2,...,f n}.
[0211] The MLP module is used to increase the nonlinear representation ability of features through multi-layer linear perceptrons and nonlinear activation functions to form a sequence G={g1,g2,...,g n}.
[0212] The second feature superposition module is used to superimpose the features of sequence F and sequence G to form a sequence H={h1,h2,...,h n}.
[0213] Wherein, n is a positive integer.
[0214] Optionally, in the neural network model, the number of layer modules, multi-channel linear correlation feature modules with position attenuation and Linear Layer modules is n. A layer module, a multi-channel linear correlation feature module with position attenuation and a Linear Layer module form a link, forming a total of n parallel links.
[0215] Optionally, the first end of the n parallel-connected links is the norm module, and the second end is the F(abc) module.
[0216] Optionally, each of the links is connected to a layer module, a multi-channel linear correlation feature module with position attenuation, and a Liner Layer module in sequence from the first end to the second end.
[0217] Optionally, among the n parallel-connected links, the input of each link is sequence A.
[0218] Optionally, the norm module subtracts the mean of the token_emb data from each data in token_emb, and then divides the result by the variance of the token_emb data to achieve data normalization.
[0219] Model calculation module, used to calculate token_emb through the neural network model.
[0220] Optionally, each of the multi-channel linear correlation feature modules attenuated by position includes M parallel single-channel linear correlation feature submodules attenuated by position, and each of the single-channel linear correlation feature submodules attenuated by position is different and has different weight heads. z . Wherein, M is greater than or equal to 2, and M is a positive integer.
[0221] Optionally, the weight head in the linear correlation feature submodule of the single channel attenuated by position z , the calculation formula is as follows.
[0222] head z =P -Q / z
[0223] Among them, z [1,M], z, P, and Q are all positive integers.
[0224] Optionally, the linear correlation feature submodule of the single channel attenuated by position specifically includes the following submodules.
[0225] Sequence acquisition module, used to obtain the i-th sequence b i ={b i1 ,b i2 ,...,b iL}.
[0226] Among them, i [1,n], i is a positive integer.
[0227] Sequence feature acquisition module, used to obtain sequence b i Sequence features Feature i ={Feature i1 ,Feature i2 ,...,Feature iL}.
[0228] Optionally, in the sequence feature acquisition module, the sequence b is obtained through a deep neural network isequence characteristics.
[0229] The position information matrix constructs the Sun module, which is used to calculate the position information matrix according to the sequence b. i Construct position information cum_mask matrix pos i ={pos i1 ,pos i2 ,...,pos iL}.
[0230] Optionally, in the position information matrix construction module, the cum_mask matrix is generated as follows: the current token position is encoded as 0, the current token position is decremented by 1 for relative position encoding, and the current token position is filled backward , generate relative position information.
[0231] Among them, the cum_mask matrix is expressed as follows.
[0232]
[0233] Among them, j [1,L], j is a positive integer.
[0234] The first processing module is used to convert sequence b i The cum_mask matrix pos i ={pos i1 ,pos i2 ,...,pos iL} and weights Head={head1,head2,...,head M}After multiplication, the sequence pos is formed i-Head ={pos i1 ×head1,pos i1 ×head2,...,pos iL ×head M-1 ,pos iL ×head M}.
[0235] The second processing module is used to process the sequence pos i-Head Perform softmax operation to form sequence prob i-Head ={prob i1-head1 ,...,prob i1-headM ,...,prob iL-head1 ,...,prob iL-headM}.
[0236] Optionally, in the second processing module, the softmax operation is specifically performed as follows.
[0237]
[0238] Among them, r [1,s],t [1,T], r, t, T are all positive integers, T represents the number of input data (e.g. sequence prob i-Head ={prob i1-head1 ,...,prob i1-headM ,...,prob iL-head1 ,...,prob iL-headM}T is L×M).
[0239] Among them, y represents the softmax input, y t Represents the value of the tth data, y r Represents the value of the rth data.
[0240] Feature fusion module is used to transform sequence prob i-Head and sequence features i Multiply them to form the sequence c i .
[0241] Optionally, in the feature fusion module, the sequence Feature i and prob i-Head Perform multiplication operation. The specific operation formula is as follows.
[0242]
[0243]
[0244] Among them, Feature ij _Combine_head z Represents the relative position information matrix cum_mask matrix of the jth token of the i-th sequence multiplied by different weights and the sequence feature Feature of the jth token of the i-th sequence ij The sequence obtained after fusion.
[0245] Among them, prob ij-headz Represents the relative position information of the jth token in the i-th sequence multiplied by the weight head z , and obtain the weighted relative position information.
[0246] in, The multiplication operation represented by , the multiplication process represented by is as follows.
[0247]
[0248] That is, the M relative position information matrices with different weights of the i-th sequence are multiplied by the sequence features of the sequence respectively.
[0249] The result output module outputs the results calculated by the neural network model.
[0250] The specific embodiments of the present invention are described in detail above, but they are only examples, and the present invention is not limited to the specific embodiments described above. For those skilled in the art, any equivalent modifications and substitutions made to the present invention are also within the scope of the present invention. Therefore, the equalization changes and modifications made without departing from the spirit and scope of the present invention should be included in the scope of the present invention.
Claims
1. A multi-channel method for adding sequence position information to text features, characterized in that The specific steps include: Step S1, constructing a neural network model; Step S2, inputting token_emb generated by text segmentation and text encoding into the neural network model, and performing calculation by the neural network model; Step S3, outputting the result of the neural network model calculation; Wherein, the number of tokens in the token_emb is L, and L is a positive integer; Wherein, in step S1, the neural network model includes the following modules: The norm module is used to normalize token_emb to form sequence A; The layer module is used to transform the sequence A into n sets of feature sequences B={b1,b2,...,b n }; Wherein, n is a positive integer; The multi-channel linear correlation feature module with position attenuation is used to multiply the relative position relationship between each token in each sequence in sequence B by different weights, and then calculate the probability value of different weight distribution to form a sequence C={c1,c2,...,c n }; Each of the multi-channel position-attenuated linear correlation feature modules includes M parallel-connected single-channel position-attenuated linear correlation feature submodules, each of which is different and has different weight heads. z ; Wherein, M is greater than or equal to 2, and M is a positive integer; The weight head in the linear correlation feature submodule of the single channel attenuated by position z , the calculation formula is as follows: head z =P -Q / z Among them, z [1,M], z, P, Q are all positive integers; The linear correlation feature module with single channel attenuation by position is used to pass each sequence b in sequence B i After the relative position relationship between each token in is multiplied by different weights, the probability values of different weight distributions are calculated to form a sequence C, which specifically includes the following steps: Step a: Get the i-th sequence b i ={b i1 ,b i2 ,...,b iL }; Step b: Get sequence b i Sequence features Feature i ={Feature i1 ,Feature i2 ,...,Feature iL }; Step c: According to sequence b i Construct position information cum_mask matrix pos i ={pos i1 ,pos i2 ,...,pos iL }; Step d: Sequence b i The cum_mask matrix pos i ={pos i1 ,pos i2 ,...,pos iL } and weights Head={head1,head2,...,head M }After multiplication, the sequence pos is formed i-Head ={pos i1 ×head1,pos i1 ×head2,...,pos iL ×head M-1 ,pos iL ×head M }; Step e: sequence pos i-Head Perform softmax operation to form sequence prob i-Head ={prob i1-head1 ,...,prob i1-headM ,...,prob iL-head1 ,...,prob iL-headM }; Step f: Sequence prob i-Head and sequence features i Multiply them to form the sequence c i ; Among them, i [1,n], i is a positive integer; In step c, the cum_mask matrix is generated as follows: the current token position is encoded as 0, the current token position is decremented by 1 for relative position encoding, and the current token position is filled backward. , generate relative position information.
2. A multi-channel method for adding sequence position information to text features according to claim 1, characterized in that In step S1, the neural network model also includes the following modules: The Linear Layer module is used to stack and linearly transform the multi-channel sequence features of sequence C to form a sequence D = {d1, d2, ..., d n }; The F(abc) module is used to fuse the sequence features of sequence D to form a sequence E={e1,e2,...,e n }; The first feature superposition module is used to superimpose the features of token_emb and sequence E to form a sequence F={f1,f2,...,f n }; The MLP module is used to increase the nonlinear representation ability of features through multi-layer linear perceptrons and nonlinear activation functions to form a sequence G={g1,g2,...,g n }; The second feature superposition module is used to superimpose the features of sequence F and sequence G to form a sequence H={h1,h2,...,h n }.
3. A multi-channel method for adding sequence position information to text features according to claim 2, characterized in that: In the neural network model, the number of layer modules, multi-channel linear correlation feature modules with positional attenuation and Linear Layer modules is n. A layer module, a multi-channel linear correlation feature module with positional attenuation and a Linear Layer module form a link, forming a total of n parallel links.
4. A multi-channel method for adding sequence position information to text features according to claim 3, characterized in that: The first end of the n parallel links is the norm module, and the second end is the F(abc) module. Each of the links is connected to the layer module, the multi-channel linear correlation feature module with position attenuation and the Liner Layer module in sequence from the first end to the second end.
5. A multi-channel method for adding sequence position information to text features according to claim 3 or 4, characterized in that: Among the n parallel-connected links, the input of each link is sequence A.
6. A multi-channel method for adding sequence position information to text features according to claim 1, characterized in that: The norm module subtracts the mean of the token_emb data from each data in token_emb, and then divides it by the variance of the token_emb data to achieve data normalization.
7. A multi-channel method for adding sequence position information to text features according to claim 1, characterized in that: In step b, sequence b is extracted through a deep neural network i sequence characteristics.
8. A multi-channel method for adding sequence position information to text features according to claim 1, characterized in that: In step e, the softmax operation is specifically as follows: Among them, r [1,s],t [1,T], r, t, T are all positive integers, T represents the amount of input data, y t Represents the value of the tth data, y r Represents the value of the rth data.
9. A multi-channel method for adding sequence position information to text features according to claim 1, characterized in that: In step f, the sequence Feature i and prob i-Head Perform multiplication operation. The specific operation formula is as follows: Among them, Feature ij _Combine_head z Represents the relative position information matrix cum_mask matrix of the jth token of the i-th sequence multiplied by different weights and the sequence feature Feature of the jth token of the i-th sequence ij The sequence obtained after fusion; Among them, j [1,L]; Among them, prob ij-headz Represents the relative position information of the jth token in the i-th sequence multiplied by the weight head z , get the relative position information with weight; in, Represents the multiplication operation; for , the multiplication process represented by it is as follows: That is, the M relative position information matrices with different weights of the i-th sequence are multiplied by the sequence features of the sequence respectively.
10. A multi-channel method for adding sequence position information to text features according to claim 2, characterized in that: In the MLP module, the nonlinear activation function includes a SiLU function and a GeLU function.
11. A multi-channel device for adding sequence position information to text features, characterized in that The modules include: Model building module, used to build neural network models; Input acquisition module, used to obtain token_emb generated by text segmentation and text encoding; Model calculation module, used to calculate token_emb through the neural network model; Result output module, used to output the result of neural network model calculation; Wherein, the number of tokens in the token_emb is L, and L is a positive integer; The neural network model specifically includes the following modules: The norm module is used to normalize token_emb to form sequence A; The layer module is used to transform the sequence A through multiple linear transformations with different weights to form n sets of feature sequences B={b1,b2,...,b n }; The multi-channel linear correlation feature module with position attenuation is used to multiply the relative position relationship between each token in each sequence in sequence B by different weights, and then calculate the probability value of different weight distribution to form a sequence C={c1,c2,...,c n }; Wherein, n is a positive integer; Each of the multi-channel position-attenuated linear correlation feature modules includes M parallel-connected single-channel position-attenuated linear correlation feature submodules, each of which is different and has different weight heads. z ; Wherein, M is greater than or equal to 2, and M is a positive integer; The weight head in the linear correlation feature submodule of the single channel attenuated by position z , the calculation formula is as follows: head z =P -Q / z Among them, z [1,M], z, P, Q are all positive integers; The linear correlation feature submodule of the single channel attenuated by position specifically includes the following submodules: Sequence acquisition module, used to obtain the i-th sequence b i ={b i1 ,b i2 ,...,b iL }; Sequence feature acquisition module, used to obtain sequence b i Sequence features Feature i ={Feature i1 ,Feature i2 ,...,Feature iL }; The position information matrix constructs the Sun module, which is used to calculate the position information matrix according to the sequence b. i Construct position information cum_mask matrix pos i ={pos i1 ,pos i2 ,...,pos iL }; The first processing module is used to convert sequence b i The cum_mask matrix pos i ={pos i1 ,pos i2 ,...,pos iL } and weights Head={head1,head2,...,head M }After multiplication, the sequence pos is formed i-Head ={pos i1 ×head1,pos i1 ×head2,...,pos iL ×head M-1 ,pos iL ×head M }; The second processing module is used to process the sequence pos i-Head Perform softmax operation to form sequence prob i-Head ={prob i1-head1 ,...,prob i1-headM ,...,prob iL-head1 ,...,prob iL-headM }; Feature fusion module is used to transform sequence prob i-Head and sequence features i Multiply them to form the sequence c i ; Among them, i [1,n], i is a positive integer; In the position information matrix construction module, the cum_mask matrix is generated as follows: the current token position is encoded as 0, the current token position is decremented by 1 for relative position encoding, and the current token position is filled backward. , generate relative position information.
12. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the multi-channel method for adding sequence position information to text features according to any one of claims 1 to 10 is implemented.
13. An electronic device, characterized in that: The invention comprises a memory, a processor and a computer program stored in the memory and executable on the processor, wherein when the processor executes the computer program, a multi-channel method for adding sequence position information to text features as described in any one of claims 1 to 10 is implemented.
