A text classification method and system based on feature perception
By using a feature-awareness-based method, combined with a multi-head attention mechanism and a feature-aware algorithm, text data features are optimized, solving the problem of insufficient utilization of deep semantics and contextual information in existing technologies, achieving efficient text classification, and improving classification accuracy. and model adaptability.
Patent Information
- Application Number
- CN202410946552.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-16
- Publication Date
- 2024-10-18
- Estimated Expiration
- 2044-07-16
AI Technical Summary
Existing text classification methods rely on surface-level features in the process of complex text classification and lack the use of deep semantics and contextual information. Traditional optimization algorithms such as PSO are inefficient in high-dimensional problems and are prone to falling into local optima, making it difficult to adapt to dynamically changing optimization environments. .
A method based on feature perception is adopted to optimize the global and local features of text data through a multi-head attention mechanism and feature perception algorithm, dynamically adjust feature selection and network parameters, and combine deep learning and intelligent optimization algorithms to achieve deep semantic focus and efficient feature optimization.
It improves the accuracy and efficiency of text classification, enhances the ability to extract complex features, improves the adaptability and flexibility of the model, reduces the risk of over-fitting, and significantly improves generalization capabilities.
Smart Images

Figure CN118484540B_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of text classification, and in particular relates to a text classification method and system based on feature perception. Background Art
[0002] The statements in this section merely provide background information related to the present invention and do not necessarily constitute prior art.
[0003] Text classification is a core task in the field of natural language processing, which involves automatically classifying text data into one or more predefined categories. In the digital and data-driven era, text classification is crucial for understanding and organizing large amounts of unstructured text data, and is widely used in sentiment analysis, topic identification, intent detection and other fields.
[0004] In recent years, deep learning technology has become one of the main methods for text classification. By using neural network models, complex features can be effectively extracted from text and effectively classified. In particular, pre-trained language models such as BERT have been proven to be very effective in capturing the deep semantic features of text.
[0005] According to the inventors, although deep learning technology has achieved remarkable results in capturing the deep semantic features of text, traditional optimization algorithms, such as particle swarm optimization (PSO), are also widely used in various optimization problems due to their simplicity, ease of implementation and fast convergence speed. However, in the process of complex text classification, existing methods often rely on surface-level text features and lack full utilization of the deep semantics and contextual information of the text; moreover, traditional PSO algorithms are less efficient in high-dimensional problems and complex search spaces, and are prone to falling into local optimal solutions, especially when optimizing complex or nonlinear problems. It is difficult to focus on important features, which in turn affects the accuracy of text classification; in addition, these algorithms show insufficient adaptability and flexibility when adapting to dynamically changing optimization environments. Summary of the invention
[0006] In order to solve the above problems, the present invention proposes a text classification method and system based on feature perception, which realizes deep semantic focusing of text data based on feature perception algorithm, realizes efficient selection of text features and parameter optimization while mining and utilizing the deep semantic information of text, effectively handles the classification of complex text, and improves the accuracy and efficiency of text classification.
[0007] According to some embodiments, a first solution of the present invention provides a text classification method based on feature perception, which adopts the following technical solution:
[0008] A feature-aware text classification method, comprising:
[0009] Obtain the text data to be classified;
[0010] Extracting global features and local features of the acquired text data;
[0011] A multi-head attention mechanism is used to process the global and local features of the extracted text data;
[0012] Based on the global and local features of the text data after being optimized by the feature perception algorithm, the feature selection and network parameters are dynamically adjusted to obtain the text representation features;
[0013] The classification probability of the text to be classified is calculated based on the obtained text representation features, and the classification of the text to be classified is completed.
[0014] As a further technical limitation, based on the feature perception algorithm, the global features and local features of the obtained text data are processed by a multi-head attention mechanism to obtain a multi-head attention output of the text data; the multi-head attention output of the text data is dynamically adjusted according to the attention mechanism to adjust the attention score; based on the adjusted attention score and the hybrid coding strategy, the network parameters are dynamically adjusted to obtain text representation features.
[0015] As a further technical limitation, a feature-aware algorithm is used to optimize the global features and local features of the processed text data respectively to obtain a global feature matrix and a local feature matrix; a weighted sum is performed on the obtained global feature matrix and local feature matrix to obtain text representation features.
[0016] As a further technical limitation, the obtained text representation features are sequentially subjected to linear transformation and nonlinear transformation based on an activation function, and the category probability of the text representation features is obtained according to the transformation results and the softmax function, and the text to be classified is classified according to the obtained category probability.
[0017] As a further technical limitation, after obtaining the text data to be classified, the obtained text data to be classified is preprocessed to convert the text data into a high-dimensional word vector.
[0018] Furthermore, in the process of extracting the global features and local features of the text data, the obtained high-dimensional word vectors are respectively input into the gated recurrent unit (GRU) and the convolutional neural network (CNN), and the output results of the gated recurrent unit and the convolutional neural network are the global features and local features of the text data.
[0019] According to some embodiments, a second solution of the present invention provides a feature-aware text classification system, which adopts the following technical solution:
[0020] A feature-aware text classification system, comprising:
[0021] An acquisition module, configured to acquire text data to be classified;
[0022] An extraction module configured to extract global features and local features of the acquired text data;
[0023] A processing module, configured to process global features and local features of the extracted text data using a multi-head attention mechanism;
[0024] An optimization module, which is configured to optimize the global features and local features of the processed text data based on the feature perception algorithm, dynamically adjust feature selection and network parameters, and obtain text representation features;
[0025] The classification module is configured to calculate the classification probability of the text to be classified according to the obtained text representation features, and complete the classification of the text to be classified.
[0026] According to some embodiments, a third solution of the present invention provides a computer-readable storage medium, which adopts the following technical solution:
[0027] A computer-readable storage medium stores a program, which, when executed by a processor, implements the steps of the feature-aware text classification method described in the first solution of the present invention.
[0028] According to some embodiments, a fourth solution of the present invention provides an electronic device, which adopts the following technical solution:
[0029] An electronic device comprises a memory, a processor and a program stored in the memory and running on the processor, wherein when the processor executes the program, the steps in the feature-aware text classification method described in the first solution of the present invention are implemented.
[0030] According to some embodiments, a fifth solution of the present invention provides a computer program product, which adopts the following technical solution:
[0031] A computer program product includes software codes, wherein the program in the software codes executes the steps in the feature-aware text classification method as described in the first solution of the present invention.
[0032] Compared with the prior art, the present invention has the following beneficial effects:
[0033] The present invention adopts feature-aware algorithms for text classification, combines deep learning technology and intelligent optimization algorithms, strengthens the focus and efficiency of the text search process, improves adaptability to complex feature selection and parameter optimization requirements, and enhances the ability to extract features of different types of texts; through the combination of deep learning networks and intelligent optimization algorithms, deep semantic understanding and efficient feature optimization of text classification are achieved, thereby achieving deep semantic focus on text data;
[0034] The present invention can not only capture the global context and temporal dependency of the text, but also effectively identify key local patterns and provide a comprehensive and accurate representation of text features. Based on the dynamic optimization strategy adopted in the present invention, it can dynamically adjust feature selection and network parameter configuration, accelerate the search for the optimal solution of the model, and improve the adaptability and flexibility of the model. Through intelligent iteration, the key features of the text classification task can be accurately captured and utilized to improve the accuracy and efficiency of text classification.
[0035] The present invention combines the deep semantic understanding ability of the Mac Bert pre-trained model, the temporal feature processing ability of the GRU network, and the local feature extraction ability of the CNN network to create a high-performance text analysis framework; through the feature perception algorithm, the attention mechanism is integrated to significantly improve the model's ability to focus on key features and the optimization efficiency; the integrated dynamic parameter adjustment mechanism can accelerate the convergence speed by adjusting the algorithm parameters in time according to the iteration process, and can refine the search when approaching the global optimal solution. The fitness-based diversity retention strategy encourages particles to explore areas outside the vicinity of the current global optimal solution, thereby increasing the diversity of the solution space; diversity retention can also prevent all particles from clustering in the local optimum, so that there are more opportunities to find the global optimum; the feature particle hybrid encoding strategy adopted balances the breadth and depth of feature selection, optimizes the combination and representation of features, and thus improves the overall performance of the text classification model; the feature perception algorithm adopted effectively reduces the risk of overfitting while maintaining the high adaptability and flexibility of the model, and significantly improves the generalization ability of the model. BRIEF DESCRIPTION OF THE DRAWINGS
[0036] The drawings in the specification that constitute a part of this embodiment are used to provide a further understanding of this embodiment. The schematic embodiments of this embodiment and their descriptions are used to explain this embodiment and do not constitute improper limitations on this embodiment.
[0037] Figure 1 This is a flow chart of a text classification method based on feature perception in Embodiment 1 of the present invention;
[0038] Figure 2 This is a schematic diagram of a process of text classification based on feature perception in the first embodiment of the present invention;
[0039] Figure 3This is a flow chart of the feature perception algorithm in the first embodiment of the present invention. DETAILED DESCRIPTION
[0040] The present invention will be further described below in conjunction with the accompanying drawings and embodiments.
[0041] It should be noted that the following detailed descriptions are exemplary and are intended to provide further explanation of the present application. Unless otherwise specified, all technical and scientific terms used herein have the same meanings as those commonly understood by those skilled in the art to which the present application belongs.
[0042] It should be noted that the terms used herein are only for describing specific embodiments and are not intended to limit exemplary embodiments according to the present invention. As used herein, unless the context clearly indicates otherwise, the singular form is also intended to include the plural form. In addition, it should be understood that when the terms "comprising" and / or "including" are used in this specification, it indicates the presence of features, steps, operations, devices, components and / or combinations thereof.
[0043] In the absence of conflict, the embodiments of the present invention and the features of the embodiments may be combined with each other.
[0044] Embodiment 1
[0045] Embodiment 1 of the present invention introduces a text classification method based on feature perception.
[0046] like Figure 1 A feature-aware text classification method is shown, comprising:
[0047] Step S01: preprocess the original text data and convert the preprocessed text into word vectors using the Mac Bert model;
[0048] Step S02: extracting global features of the text through the GRU network and extracting local features of the text through the CNN network;
[0049] Step S03: Apply a multi-head self-attention layer to the output of the GRU and CNN layers to enhance the focus on key information in the text;
[0050] Step S04: Select and optimize features using a feature perception algorithm;
[0051] Step S05: Merge the features of GRU and CNN optimized by the attention layer to form a comprehensive feature representation;
[0052] Step S06: Input the fused features into the fully connected layer for integration and dimensionality reduction;
[0053] Step S07: Pass the output of the fully connected layer to the Softmax layer for final classification to obtain the category to which the text belongs.
[0054] like Figure 2 As shown, this embodiment first preprocesses the text, and then uses the Mac BERT pre-trained model to semantically encode the text; uses the GRU unit and the CNN convolutional network to extract the global features and local features of the text respectively; applies the multi-head attention mechanism to strengthen the focus on key features; uses the feature perception algorithm to perform feature selection and dynamic optimization of model parameters to further enhance the ability to focus on important features; and performs feature fusion and text classification through the fully connected layer and the Softmax layer.
[0055] As one or more implementation modes, in step S01, the original text data is first preprocessed, including text cleaning (i.e., removing useless characters, such as icon points, special symbols) and word segmentation (i.e., decomposing the text into words or vocabulary units); then the pre-trained Mac BERT model is used to extract the deep semantic features of the text, specifically including inputting the preprocessed text into the Mac BERT model, and then extracting high-dimensional word vectors that capture the deep semantic features of the text data through Mac Bert's multi-layer Transformer structure.
[0056] As one or more implementation modes, in step S02, the obtained high-dimensional word vector x t Input into the GRU network layer and CNN network layer respectively to extract the feature information of the text; specifically,
[0057] (1) High-dimensional word vector Enter the GRU network layer to extract global features of the text
[0058] For each time step in the sequence t (from arrive ,in is the sequence length), the calculation process of the GRU layer is as follows:
[0059] The reset gate is used to decide how much past information needs to be forgotten; ;
[0060] in, is the time step The reset gate output, and is the weight matrix, represents the hidden state at the previous time step, is the bias term, is the sigmoid activation function.
[0061] The update gate determines to what extent new information is used to update the current hidden state; ;
[0062] in, is the output of the update gate, , is the weight matrix, is the bias term.
[0063] Candidate hidden state, that is, calculate the new candidate hidden state based on the current input and the output of the reset gate, that is, ;
[0064] in, is a candidate hidden state, , is the weight matrix, is the bias term, represents element-wise multiplication, represents the hyperbolic tangent function.
[0065] The final hidden state is formed by combining the output of the update gate and the candidate hidden state, that is, ;
[0066] in, is the time step The final hidden state of GRU output Proceed to the next task.
[0067] (2) High-dimensional word vector Input CNN network layer to extract local features of text
[0068] CNN layers process these features mainly through convolution operations to capture local patterns in the sequence.
[0069] The convolution operation uses a set of convolution kernels to slide over the feature sequence to capture local features; each convolution kernel is responsible for extracting a specific type of local feature; that is, is the convolution kernel, is a local segment in the high-dimensional word vector sequence, the convolution operation can be expressed as ;in, Indicates the starting position of the convolution kernel sliding on the feature sequence, represents the size of the convolution kernel, is the feature after convolution, b is the bias term, and ReLU is the activation function.
[0070] The pooling operation, that is, the pooling layer usually follows the convolutional layer, is used to reduce the dimension of the features and enhance the generalization ability of the model; that is, ;in, represents the local features of the text after pooling, represents the maximum pooling, represents average pooling, Indicates selecting a local area in the feature map, from position To location .
[0071] As one or more implementation modes, in step S03, the obtained global features of the text and the local features of the text are respectively input into the multi-head attention layer to strengthen the attention to important features and generate a multi-head attention output; specifically,
[0072] For output features from GRU or CNN , generate query (Q), key (K) and value (V) through linear transformation; that is ;in, is the weight matrix whose parameters can be learned;
[0073] Calculate the dot product between the query (Q) and the key (K) to represent the similarity or association between different positions; then divide the dot product result by a scaling factor to obtain a stable gradient; that is, ;in, is the dimension of the key vector, Represents the attention score.
[0074] Apply the softmax function to the attention scores to get the weight distribution; apply the obtained weights to the values (V) to get the weighted sum, which is the output of the attention layer; that is, .
[0075] In the multi-head attention mechanism, it is performed on multiple "heads" in parallel; that is, each head has its own independent weight matrix , and generate different outputs accordingly; then merge the obtained outputs and perform linear transformation to generate the final multi-head attention output; that is, multi-head parallel processing ; Output merge ;in, is another learnable matrix, , , Corresponding to the The query, key, and value weight matrices of each head, Represents a concatenation operation.
[0076] As one or more implementation modes, in step S04, feature selection optimization and parameter optimization are performed on the features output by the attention layer based on the feature perception algorithm; the feature perception algorithm in this embodiment introduces a feature particle hybrid coding strategy, a dynamic parameter adjustment mechanism, a diversity maintenance strategy and an attention mechanism; compared with traditional algorithms, this embodiment can effectively focus the search on high potential areas in the solution space; the attention mechanism is used to dynamically adjust the search behavior of particles to reduce the risk of premature convergence; by adjusting the attention score, a balance is flexibly made between global exploration and local utilization; through a hybrid coding strategy, combined with the advantages of feature selection and feature weighting, a more detailed and customized model optimization direction can be given; through a dynamic parameter adjustment mechanism, dynamic learning of parameters can be achieved to reduce the risk of falling into local optimality. If a particle falls into a non-optimal area, the diversity maintenance strategy based on fitness can help the particle "jump out" of the trap and explore other areas.
[0077] The feature perception algorithm flow chart proposed in this embodiment is as follows Figure 3 As shown, specifically including:
[0078] (1) Initialize particle swarm
[0079] Randomly initialize the binary part and real part of the particle. The binary part can be randomly generated by uniform distribution to 0 or 1 (1 means the feature extracted by the multi-head attention layer is selected, 0 means it is not selected), while the real part can be randomly generated by Gaussian distribution or uniform distribution in [0,1]; A real vector representing feature selection, represents a binary vector; Indicates the direction and magnitude of feature selection changes.
[0080] (2) Fitness evaluation (classification accuracy)
[0081] The model is trained using the feature configuration currently represented by the particle, and the classification accuracy is evaluated on the validation set; i.e. , where N represents the number of correct predictions and T represents the total number of predictions.
[0082] (3) Attention score calculation
[0083] Normalize the fitness score to apply the Sigmoid function; that is ,in represents the normalized fitness, Represents particles The classification accuracy of each particle is calculated by the Sigmoid function, that is, ;in, Is a positive scaling factor used to adjust the sensitivity of the Sigmoid function.
[0084] The main purpose of calculating the attention score is to evaluate the potential value of each particle's position based on its current fitness, even if it is not the individual historical best. The attention score can help the algorithm identify areas that may not be fully explored at present, even if these areas have not yet produced the optimal solution. In this way, the algorithm can maintain a certain diversity, avoid falling into local optimality, and maintain a broad search of the solution space; when the fitness has not improved, it is also important to update the attention score because it will affect the speed update and position update of the particles in subsequent iterations; it helps particles find better areas in subsequent searches, thereby improving the overall optimization efficiency and solution quality.
[0085] (4) Dynamic parameter adjustment mechanism
[0086] Dynamic Inertia Weight It can help the algorithm to balance between global search and local search, and gradually reduce as the iteration progresses. , so that the algorithm has a larger search range in the early stage and a more detailed local search in the late stage; that is ;in, and They are The maximum and minimum values of is the current iteration number, is the maximum number of iterations.
[0087] Dynamic cognitive factors and social cognitive factors : Dynamic adjustment and Individual learning or group learning can be strengthened at different stages of the algorithm. For example, group learning can be strengthened at the beginning of the iteration (larger ) to promote global search and strengthen individual learning in the later stages of iteration (larger ) to facilitate local search; i.e. ; .
[0088] In order to use the attention mechanism more effectively during the search process, the attention learning factor can be dynamically adjusted according to the current state of the algorithm. For example, when the algorithm finds a new and better solution, it can increase to facilitate the movement of particles to these regions; namely:
[0089] .
[0090] (5) The fitness-based diversity maintenance strategy increases the diversity of the population by encouraging the exploration of particles whose fitness is different from the current global optimal solution.
[0091] The difference between the fitness of each particle and the fitness of the global optimal solution is calculated, and the uniqueness of each particle, that is, the ability to explore different areas of the solution space, is evaluated through the difference.
[0092] Assume that the fitness of the particle is , the fitness of the global optimal solution is , defining the fitness difference and diversity scores ;Right now ; Each particle is assigned a diversity score based on fitness differences, which reflects the degree of difference between the particle and other members of the population; that is, the fitness diversity score ;in, is the maximum fitness difference among all particles. The diversity score is used to adjust the particle speed update formula to encourage exploration of areas with higher diversity scores.
[0093] (6) Feature perception algorithm optimization (speed and position update)
[0094] If the particle's current fitness is higher than its historical best fitness, update its personal best position ; If the fitness of the particle is higher than the current global optimal fitness, update the global optimal position .
[0095] The speed update formula (real part) is
[0096]
[0097] The position update formula (real part) is
[0098] ;
[0099] in, Represents the inertia weight, which controls the particle velocity maintenance; , represents cognitive and social learning factors, controlling the attraction of particles to personal and global optimal positions; , Represents random numbers, providing randomness to explore the solution space; Represents the attention learning factor, which determines the influence of the attention score in speed updating; , the best position of the particle in history; is the global best position; is the attention score of the particle; is a newly introduced learning factor that controls the influence of the diversity score on the speed update.
[0100] The position update formula (binary part) is
[0101]
[0102] in, is a random mutation function that has a small probability of flipping a bit, is a crossover function that mixes the particle’s own binary position with the individual best binary position; The purpose of the function is to introduce random changes in the binary representation of particles to simulate genetic mutations in biological evolution. This helps the algorithm escape from the local optimal solution and explore new possible solutions.
[0103] For particles Each bit of , the mutation operation is as follows:
[0104] Generate a random number between 0 and 1 , an initial mutation rate ;
[0105] if Less than mutation rate , then will be flipped;
[0106] The reversal operation is done by This means that if it is 1, it becomes 0; if it is 0, it becomes 1;
[0107] like Greater than or equal to , then remain unchanged;
[0108] The purpose of the function is to generate new particles by combining the binary representations of two particles. This simulates the mating process in biological genetics, which helps to share and combine the characteristics of good solutions.
[0109] For two parent particles and , their binary representations are and , the crossover operation is as follows:
[0110] Randomly select an intersection point , the point is the bit number arrive Any integer between .
[0111] For each bit :
[0112] like Less than or equal to , then the new particle The position is taken from the particle The corresponding position of .
[0113] like Greater than , then the new particle The position is taken from the particle The corresponding position of .
[0114] In this way, The function can combine the characteristics of two parent particles, and Functions can introduce new variations, and together they provide exploration and diversity to the optimization process.
[0115] Feature selection is to use the updated particles to determine which features are selected (binary part) and the weights of these features (real part). Do the following:
[0116] if, Then the feature is selected and its weight is ;
[0117] if, Then the feature is not selected and its weight can be ignored or set to 0.
[0118] (7) Iterative optimization, that is, continuously repeating the above process until the stopping condition is met (such as reaching the maximum number of iterations or fitness convergence).
[0119] As one or more implementation modes, in step S05, the features of the two channels optimized by the feature perception algorithm are fused and integrated into text representation features; specifically, weighted summation is performed, that is, weighted summation is performed on the two feature matrices, and the features of each channel may have different weights; ;in, is the fused feature matrix, , Respectively represent the optimized Layer and The feature matrix of the layer, and is a learnable weight used to balance the features of the two channels.
[0120] As one or more implementation modes, in step S06, after feature fusion, feature data The input is sent to the fully connected layer for further processing and classification; specifically, the linear transformation of the input features is performed through the fully connected layer, which mainly involves the application of weight matrices and bias terms; that is, ;in, is the fused feature matrix, is the weight matrix of the fully connected layer, is the bias term, is the output after linear transformation; the output after linear transformation is then transformed nonlinearly through an activation function; that is ; Among them, ReLU is an activation function, is the output after the activation function.
[0121] As one or more implementations, in step S07, the output of the fully connected layer is input to the softmax layer to output the final classification result; wherein the softmax function is a standard method for converting an input real number vector into a probability distribution, that is, ; For vector Each element in , applying the softmax function, where the denominator is all The sum of , ensures that the output probability sums to 1.
[0122] The Softmax layer in this embodiment converts the output of the fully connected layer into a probability distribution for predicting each category. In this process, the fully connected layer first reduces the dimensionality of the fused features, and then introduces nonlinearity through the activation function. Next, the softmax layer converts these processed features into category probabilities, thereby completing the classification task.
[0123] This embodiment combines the deep semantic understanding ability of the Mac Bert pre-trained model, the temporal feature processing ability of the GRU network, and the local feature extraction ability of the CNN network to create a high-performance text analysis framework; through the feature perception algorithm, the attention mechanism is integrated to significantly improve the model's ability to focus on key features and the optimization efficiency; the integrated dynamic parameter adjustment mechanism can accelerate the convergence speed by adjusting the algorithm parameters in a timely manner according to the iteration process, and can refine the search when approaching the global optimal solution. The fitness-based diversity retention strategy encourages particles to explore areas outside the vicinity of the current global optimal solution, thereby increasing the diversity of the solution space; diversity retention can also prevent all particles from clustering in the local optimum, so that there are more opportunities to find the global optimum; the feature particle hybrid encoding strategy adopted balances the breadth and depth of feature selection, optimizes the combination and representation of features, and thus improves the overall performance of the text classification model; the feature perception algorithm adopted effectively reduces the risk of overfitting while maintaining the high adaptability and flexibility of the model, and significantly improves the generalization ability of the model.
[0124] Embodiment 2
[0125] Embodiment 2 of the present invention introduces a text classification system based on feature perception.
[0126] A feature-aware text classification system, comprising:
[0127] An acquisition module, configured to acquire text data to be classified;
[0128] An extraction module configured to extract global features and local features of the acquired text data;
[0129] A processing module, configured to process global features and local features of the extracted text data using a multi-head attention mechanism;
[0130] An optimization module, which is configured to optimize the global features and local features of the processed text data based on the feature perception algorithm, dynamically adjust feature selection and network parameters, and obtain text representation features;
[0131] The classification module is configured to calculate the classification probability of the text to be classified according to the obtained text representation features, and complete the classification of the text to be classified.
[0132] The detailed steps are the same as those of the feature-aware text classification method provided in Example 1 and will not be repeated here.
[0133] Embodiment 3
[0134] Embodiment 3 of the present invention provides a computer-readable storage medium.
[0135] A computer-readable storage medium stores a program, which, when executed by a processor, implements the steps of the feature-aware text classification method as described in Embodiment 1 of the present invention.
[0136] The detailed steps are the same as those of the feature-aware text classification method provided in Example 1 and will not be repeated here.
[0137] Embodiment 4
[0138] A fourth embodiment of the present invention provides an electronic device.
[0139] An electronic device comprises a memory, a processor and a program stored in the memory and running on the processor, wherein when the processor executes the program, the steps in the feature-aware text classification method described in the first embodiment of the present invention are implemented.
[0140] The detailed steps are the same as those of the feature-aware text classification method provided in Example 1 and will not be repeated here.
[0141] Embodiment 5
[0142] Embodiment 5 of the present invention provides a computer program product.
[0143] A computer program product includes software codes, wherein the program in the software codes executes the steps in the feature-aware text classification method as described in the first embodiment of the present invention.
[0144] The detailed steps are the same as those of the feature-aware text classification method provided in Example 1 and will not be repeated here.
[0145] The above description is only a preferred embodiment of the present embodiment and is not intended to limit the present embodiment. For those skilled in the art, the present embodiment may have various modifications and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present embodiment shall be included in the protection scope of the present embodiment.
Claims
1. A feature-aware text classification method, characterized in that: include: Obtain the text data to be classified; Extracting global features and local features of the acquired text data; A multi-head attention mechanism is used to process the global and local features of the extracted text data; Based on the global and local features of the text data after being optimized by the feature perception algorithm, the feature selection and network parameters are dynamically adjusted to obtain the text representation features; Calculate the classification probability of the text to be classified according to the obtained text representation features, and complete the classification of the text to be classified; Based on the feature perception algorithm, the features of the attention layer output are optimized for feature selection and parameter optimization; the attention mechanism is used to dynamically adjust the search behavior of particles; by adjusting the attention score, a balance is flexibly made between global exploration and local utilization; through the hybrid coding strategy, the advantages of feature selection and feature weighting are combined to provide a more detailed and customized model optimization direction; through the dynamic parameter adjustment mechanism, dynamic learning of parameters is achieved to reduce the risk of falling into the local optimum; based on the diversity maintenance strategy of fitness, particles with fitness different from the current global optimal solution are encouraged to be explored; specifically: (1) Initialize particle swarm Randomly initialize the binary part and real part of the particle; the binary part is randomly generated by uniform distribution to 0 or 1, where 1 indicates that the feature extracted by the multi-head attention layer is selected, and 0 indicates that it is not selected, while the real part is randomly generated by Gaussian distribution or uniform distribution in [0,1]; A real vector representing feature selection, represents a binary vector; Indicates the direction and magnitude of feature selection changes; (2) Fitness evaluation The model is trained using the feature configuration currently represented by the particle, and the classification accuracy is evaluated on the validation set; i.e. , where N represents the number of correct predictions and T represents the total number of predictions; (3) Attention score calculation Normalize the fitness score to apply the Sigmoid function; that is ,in represents the normalized fitness, Represents particles The classification accuracy of each particle is calculated by the Sigmoid function, that is, ;in, Is a positive scaling factor used to adjust the sensitivity of the Sigmoid function; (4) Dynamic parameter adjustment mechanism Dynamic Inertia Weight Helps the algorithm to balance between global search and local search, gradually reducing as the iteration progresses , so that the algorithm has a larger search range in the early stage and a more detailed local search in the late stage; that is ;in, and They are The maximum and minimum values of is the current iteration number, is the maximum number of iterations; Dynamic cognitive factors and social cognitive factors : Dynamic adjustment and Strengthen individual learning or group learning at different stages of the algorithm; strengthen group learning at the beginning of the iteration To promote global search, strengthen individual learning in the later stages of iteration To facilitate local search; i.e. ; ; In order to use the attention mechanism more effectively during the search process, the attention learning factor is dynamically adjusted according to the current state of the algorithm. ; When the algorithm finds a new and better solution, increase to facilitate the movement of particles to these regions; namely: ; (5) The fitness-based diversity maintenance strategy increases the diversity of the population by encouraging the exploration of particles whose fitness is different from the current global optimal solution; Calculate the difference between each particle's fitness and the global optimal solution's fitness, and use the difference to evaluate each particle's uniqueness, that is, its ability to explore different regions of the solution space; Assume that the fitness of the particle is , the fitness of the global optimal solution is , defining the fitness difference and diversity scores ;Right now ; Each particle is assigned a diversity score based on fitness differences, which reflects the degree of difference between the particle and other members of the population; that is, the fitness diversity score ;in, is the maximum fitness difference among all particles; the diversity score is used to adjust the particle speed update formula to encourage exploration of areas with higher diversity scores; (6) Feature perception algorithm optimization If the particle's current fitness is higher than its historical best fitness, update its personal best position ; If the fitness of the particle is higher than the current global optimal fitness, update the global optimal position ; The speed update formula is: The position update formula (real part) is: ; in, Represents the inertia weight, which controls the particle velocity maintenance; , represents cognitive and social learning factors, controlling the attraction of particles to personal and global optimal positions; , Represents random numbers, providing randomness to explore the solution space; Represents the attention learning factor, which determines the influence of the attention score in speed updating; , the best position of the particle in history; is the global best position; is the attention score of the particle; is a newly introduced learning factor used to control the influence of diversity score on speed update; The position update formula is: in, is a random mutation function that has a small probability of flipping a bit, is a crossover function that mixes the particle’s own binary position with the individual best binary position; The purpose of the function is to introduce random changes in the binary representation of particles to simulate genetic mutations in biological evolution; this helps the algorithm escape from the local optimal solution and explore new possible solutions; For particles Each bit of , the mutation operation is as follows: Generate a random number between 0 and 1 , an initial mutation rate ; if Less than mutation rate , then will be flipped; The reversal operation is done by This means that if it is 1, it becomes 0; if it is 0, it becomes 1; like Greater than or equal to , then remain unchanged; The purpose of the function is to generate new particles by combining the binary representations of two particles; this simulates the mating process in biological genetics, which helps to share and combine the characteristics of good solutions; For two parent particles and , their binary representations are and , the crossover operation is as follows: Randomly select an intersection point , the point is the bit number arrive Any integer between ; For each bit : like Less than or equal to , then the new particle The position is taken from the particle The corresponding position of ; like Greater than , then the new particle The position is taken from the particle The corresponding position of ; In this way, The function can combine the characteristics of two parent particles, and Functions can introduce new variations, and together they provide exploration and diversity to the optimization process; Feature selection, that is, using the updated particles to determine which features are selected and the weights of these features; according to the binary vector and real vector of the particle, for each feature Do the following: if, Then the feature is selected and its weight is ; if, Then the feature is not selected and its weight is ignored or set to 0; (7) Iterative optimization, that is, repeating the above process until the stopping condition is met; A feature-aware algorithm is used to optimize the global features and local features of the processed text data respectively to obtain a global feature matrix and a local feature matrix; a weighted sum is performed on the obtained global feature matrix and local feature matrix to obtain text representation features.
2. A feature-aware text classification method as claimed in claim 1, characterized in that: Based on the feature perception algorithm, the global features and local features of the obtained text data are processed by a multi-head attention mechanism to obtain the multi-head attention output of the text data; the multi-head attention output of the text data is dynamically adjusted according to the attention mechanism to adjust the attention score; based on the adjusted attention score and the hybrid coding strategy, the network parameters are dynamically adjusted to obtain the text representation features.
3. A feature-aware text classification method as claimed in claim 1, characterized in that: The obtained text representation features are subjected to linear transformation and nonlinear transformation based on activation function in turn. According to the transformation results and softmax function, the category probability of the text representation features is obtained, and the text to be classified is classified according to the obtained category probability.
4. A feature-aware text classification method as claimed in claim 1, characterized in that: After obtaining the text data to be classified, the obtained text data to be classified is preprocessed to convert the text data into high-dimensional word vectors.
5. A feature-aware text classification method as claimed in claim 4, characterized in that: In the process of extracting the global features and local features of text data, the obtained high-dimensional word vectors are respectively input into the gated recurrent unit and the convolutional neural network, and the output results of the gated recurrent unit and the convolutional neural network are the global features and local features of the text data.
6. A feature-aware text classification system, based on a feature-aware text classification method according to any one of claims 1 to 5, characterized in that: include: An acquisition module, configured to acquire text data to be classified; An extraction module configured to extract global features and local features of the acquired text data; A processing module, configured to process global features and local features of the extracted text data using a multi-head attention mechanism; An optimization module, which is configured to optimize the global features and local features of the processed text data based on the feature perception algorithm, dynamically adjust feature selection and network parameters, and obtain text representation features; A classification module is configured to calculate the classification probability of the text to be classified according to the obtained text representation features, and complete the classification of the text to be classified; Based on the feature perception algorithm, the features of the attention layer output are optimized for feature selection and parameter optimization; the attention mechanism is used to dynamically adjust the search behavior of particles; by adjusting the attention score, a balance is flexibly made between global exploration and local utilization; through the hybrid coding strategy, the advantages of feature selection and feature weighting are combined to provide a more detailed and customized model optimization direction; through the dynamic parameter adjustment mechanism, dynamic learning of parameters is achieved to reduce the risk of falling into the local optimum; based on the diversity maintenance strategy of fitness, particles with fitness different from the current global optimal solution are encouraged to explore; A feature-aware algorithm is used to optimize the global features and local features of the processed text data respectively to obtain a global feature matrix and a local feature matrix; a weighted sum is performed on the obtained global feature matrix and local feature matrix to obtain text representation features.
7. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the steps of the feature-aware text classification method according to any one of claims 1 to 5 are implemented.
8. An electronic device comprising a memory, a processor, and a computer program stored in the memory and running on the processor, characterized in that: When the processor executes the program, the steps of the feature-aware text classification method according to any one of claims 1 to 5 are implemented.
9. A computer program product comprising software code, characterized in that The program in the software code executes the steps of the feature-aware text classification method as described in any one of claims 1 to 5.
Citation Information
Patent Citations
Short text sentiment analysis method based on multi-head attention mechanism and multi-model fusion
CN117764084A
