Sentiment classification model training method and system and sentiment classification method and system
By splicing and feature extraction of comment information and commented information, converting emotion labels into embedding vectors, inputting emotion classification model for training, the problem of poor emotion classification effect in the existing technology is solved, and the emotion classification model is improved Accuracy and robustness.
Patent Information
- Application Number
- CN202411007675.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-25
- Publication Date
- 2024-11-15
AI Technical Summary
The prior art has poor classification effect and low accuracy when classification of comment information, especially when processing diverse emotional data and short and ambiguous comment information, it is difficult to accurately judge emotional tendencies.
By obtaining the training set, including comment information, commented information and emotional labels, they are spliced and feature extracted. The preset embedding layer is used to convert the emotional labels into embedding vectors, and the target features and embedding vectors are spliced into comprehensive vectors , input the emotion classification model for training to improve the accuracy of the classification model.
This method combines the characteristics of comment information and the commented information to learn the semantic relationship between the semantic information of the emotional label and the text to form a robust feature representation, which improves the accuracy and robustness of the emotion classification model.
Smart Images

Figure CN118964981A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of artificial intelligence technology, and in particular to a sentiment classification model training method and system, and a sentiment classification method and system. Background Art
[0002] In today's information society, sentiment classification of comment information is of great significance. For example, sentiment classification of comments on the main post can be performed to understand the sentiment of the commentator. Sentiment classification of comment information can help companies or institutions to conduct user sentiment analysis and public opinion monitoring. At present, it is usually done by segmenting comment information and using a neural network model to perform sentiment classification on multiple words after segmentation.
[0003] However, the above method has poor classification effect and low accuracy when dealing with the classification of diverse sentiment data. Moreover, for short and ambiguous comment information, this method is difficult to accurately judge its sentiment tendency. Summary of the invention
[0004] The present application provides a sentiment classification model training method, system, sentiment classification method and system to solve the problem of poor classification effect and low accuracy when sentiment classification of comment information in the prior art.
[0005] The present application provides a sentiment classification model training method, the method comprising: obtaining a training set, the training set comprising a plurality of training samples, the training samples comprising: comment information, commented information and sentiment labels;
[0006] splicing the comment information with the commented information, and performing feature extraction based on the spliced information to obtain target features;
[0007] Using a preset embedding layer, converting the emotion label into an embedding vector;
[0008] Concatenating the target feature with the corresponding embedding vector to obtain a comprehensive vector;
[0009] The comprehensive vector is input into the classification network of the sentiment classification model to complete the sentiment classification model training.
[0010] In one embodiment of the present application, the step of extracting features based on the spliced information to obtain target features includes:
[0011] The spliced information is determined as the original text, and the original text is cleaned to obtain the target text;
[0012] Segmenting the comment information and the commented information in the target text to obtain a plurality of vocabulary units;
[0013] Inputting all the vocabulary units into a preset Bert model to perform information encoding to obtain a vector representation of each vocabulary unit, wherein the dimension of the vector representation is higher than the dimension of the vocabulary unit;
[0014] Concatenating the vector representations of all the vocabulary units to obtain a target sequence;
[0015] Feature extraction is performed based on the target sequence to obtain the target feature.
[0016] In one embodiment of the present application, the step of extracting features based on the target sequence to obtain the target features includes:
[0017] Inputting the target sequence into the long short-term memory network of the sentiment classification model to extract semantic features to obtain a plurality of target semantic features, wherein the target semantic features correspond one-to-one to the vector representation of the vocabulary unit;
[0018] Segmenting all the target semantic features according to a preset segment length to obtain a plurality of feature segments, each of which includes a fixed number of the target semantic features;
[0019] Performing linear transformation on all the target semantic features in the feature segment to obtain a plurality of first Key vectors, wherein the first Key vectors correspond to the target semantic features one by one;
[0020] Determine the dot product between the first Key vector and the preset first Query vector as a first attention weight;
[0021] Normalizing all of the first attention weights to obtain a first target weight;
[0022] Based on the first target weight corresponding to each target semantic feature in the feature segment, weighted summing each target semantic feature in the feature segment to obtain a target representation of each feature segment;
[0023] Based on the target representation of each feature segment, feature extraction is performed to obtain the target feature.
[0024] In one embodiment of the present application, based on the target representation of each feature segment, feature extraction is performed to obtain the target feature, including:
[0025] Performing linear transformation on the target representation of each of the feature segments to obtain a plurality of second Key vectors, wherein the second Key vectors correspond to the feature segments one by one;
[0026] Determine the dot product between the second Key vector and the preset second Query vector as a second attention weight;
[0027] Normalizing all the second attention weights to obtain a second target weight;
[0028] Based on the second target weight corresponding to each feature segment, the target representations of all the feature segments are weighted summed to obtain a final representation of the current target sequence; and the final representation is determined as the target feature.
[0029] In one embodiment of the present application, the step of inputting the comprehensive vector into the classification network of the sentiment classification model to complete the sentiment classification model training includes:
[0030] Inputting the comprehensive vector into a fully connected sub-network in the classification network, performing linear transformation and activation, and obtaining a feature representation of a preset dimension, wherein the fully connected sub-network includes at least one fully connected unit, and the fully connected unit includes an intermediate fully connected layer and a nonlinear activation function layer;
[0031] Input the feature representation into the output sub-network in the classification network, perform linear transformation and activation to obtain a sentiment classification result, wherein the output sub-network includes: a final fully connected layer and a Softmax activation function layer;
[0032] Based on the sentiment classification result, the sentiment classification model is trained.
[0033] In one embodiment of the present application, the step of inputting the comprehensive vector into the fully connected sub-network in the classification network, performing linear transformation and activation, and obtaining a feature representation of a preset dimension includes:
[0034] Inputting the comprehensive vector into the first fully connected unit of the fully connected sub-network, performing linear transformation and activation, and obtaining an intermediate feature vector;
[0035] The intermediate feature vector is input into the second fully connected unit of the fully connected subnetwork for linear transformation and activation to obtain the feature representation of a preset dimension, wherein the dimension of the comprehensive vector is greater than the dimension of the intermediate feature vector, and the dimension of the intermediate feature vector is greater than the dimension of the feature representation.
[0036] The present application also provides a sentiment classification model training system, comprising:
[0037] A training set acquisition module, used to acquire a training set, wherein the training set includes a plurality of training samples, and the training samples include: comment information, commented information, and sentiment labels;
[0038] A processing module, used for splicing the comment information with the commented information, and performing feature extraction based on the spliced information to obtain target features;
[0039] An embedding module, used to convert the emotion label into an embedding vector using a preset embedding layer;
[0040] A concatenation module, used for concatenating the target feature with the corresponding embedding vector to obtain a comprehensive vector;
[0041] The training module is used to input the comprehensive vector into the classification network of the sentiment classification model to complete the sentiment classification model training.
[0042] This application also provides a comment information sentiment classification method, including:
[0043] Acquire the text to be classified, wherein the text to be classified includes comment information to be classified and commented information to be classified;
[0044] splicing the comment information to be classified with the commented information to be classified to obtain spliced information;
[0045] Based on the splicing information and the trained sentiment classification model, sentiment classification is performed to obtain the sentiment category of the comment information to be classified, and the trained sentiment classification model is trained using any of the sentiment classification model training methods described above.
[0046] In one embodiment of the present application, based on the splicing information and the trained sentiment classification model, sentiment classification is performed to obtain the sentiment category of the comment information to be classified, including:
[0047] Cleaning the spliced information to obtain a cleaned text;
[0048] Performing word segmentation on the comment information to be classified and the commented information to be classified in the cleaned text to obtain a plurality of target vocabulary units;
[0049] Inputting all the target vocabulary units into a preset Bert model to perform information encoding to obtain a target vector representation of each target vocabulary unit, wherein the dimension of the target vector representation is higher than the dimension of the target vocabulary unit;
[0050] Concatenating all the target vector representations to obtain a concatenated sequence;
[0051] The concatenated sequence is input into the trained sentiment classification model to perform sentiment classification to obtain the sentiment category of the comment information to be classified.
[0052] This application also provides a comment information sentiment classification system, including:
[0053] A module for acquiring text to be classified, used for acquiring text to be classified, wherein the text to be classified includes comment information to be classified and commented information to be classified;
[0054] A target splicing module, used for splicing the comment information to be classified with the commented information to be classified to obtain spliced information;
[0055] The sentiment classification module is used to perform sentiment classification based on the splicing information and the trained sentiment classification model to obtain the sentiment category of the comment information to be classified. The trained sentiment classification model is trained using any of the sentiment classification model training methods described above.
[0056] The present application also provides a computer-readable storage medium on which a computer program is stored, wherein the computer program is used to enable a computer to execute the method provided in any of the above embodiments.
[0057] Beneficial effects of the present application: The present application proposes a sentiment classification model training method, system, sentiment classification method and system, the sentiment classification model training method obtains a training set, the training set includes multiple training samples, the training samples include: comment information, commented information and sentiment labels; splices the comment information and the commented information, extracts features based on the spliced information, and obtains target features; uses a preset embedding layer to convert the sentiment label into an embedding vector; splices the target feature with the corresponding embedding vector to obtain a comprehensive vector; inputs the comprehensive vector into the classification network of the sentiment classification model to complete the sentiment classification model training. The sentiment classification model training method combines the comment information and the commented information for model training, which can ensure that the sentiment classification model pays attention to the sentiment of the comment information while also paying attention to the specific content of the commented information, which helps to improve the accuracy of the sentiment classification model. In addition, the sentiment classification model training method splices the sentiment label with the target feature in the form of an embedded vector, so that the sentiment classification model can not only learn the text features of the comment information and the commented information, but also learn the semantic information of the sentiment label, as well as the semantic relationship between the sentiment label and the text (comment information and commented information). This method helps the sentiment classification model to form a more robust feature representation during the training process, thereby improving the accuracy and robustness of the sentiment classification model. BRIEF DESCRIPTION OF THE DRAWINGS
[0058] Figure 1 A flowchart of a sentiment classification model training method provided in one embodiment of the present application;
[0059] Figure 2 A flowchart of a specific embodiment of the sentiment classification model training method provided in one embodiment of the present application;
[0060] Figure 3 A schematic diagram of the structure of a sentiment classification model training system provided in one embodiment of the present application;
[0061] Figure 4 It is a flowchart of a method for sentiment classification of comment information provided by an embodiment of the present application;
[0062] Figure 5 It is a structural diagram of a comment information sentiment classification system provided by an embodiment of the present application;
[0063] Figure 6 It is a structural schematic diagram of an electronic device provided in one embodiment of the present application. DETAILED DESCRIPTION
[0064] The following describes the embodiments of the present application through specific examples, and those skilled in the art can easily understand other advantages and effects of the present application from the contents disclosed in this specification. The present application can also be implemented or applied through other different specific embodiments, and the details in this specification can also be modified or changed in various ways based on different viewpoints and applications without departing from the spirit of the present application. It should be noted that the following embodiments and features in the embodiments can be combined with each other without conflict.
[0065] It should be noted that the illustrations provided in the following embodiments are only schematic illustrations of the basic concept of the present application, and thus the drawings only show components related to the present application rather than being drawn according to the number, shape and size of components in actual implementation. In actual implementation, the type, quantity and proportion of each component may be changed at will, and the component layout may also be more complicated.
[0066] In the following description, a large number of details are discussed to provide a more thorough explanation of the embodiments of the present application. However, it is obvious to those skilled in the art that the embodiments of the present application can be implemented without these specific details. In other embodiments, well-known structures and devices are shown in the form of block diagrams rather than in detail to avoid making the embodiments of the present application difficult to understand.
[0067] Combine the following Figures 1 to 6 , the sentiment classification model training method, system, sentiment classification method and system provided in this application are explained.
[0068] See also Figure 1 , Figure 1 The sentiment classification model training method provided in an embodiment of the present application is as follows: Figure 1 As shown, the sentiment classification model training method includes:
[0069] S110: Acquire a training set, where the training set includes a plurality of training samples, and the training samples include comment information, commented information, and sentiment labels.
[0070] It should be noted that the comment information and the commented information can be obtained by crawling the information published by relevant social software in real time using web crawler technology with permission. The commented information can be the main post information published on the social software, etc. The comment information refers to the comment content on the main post information, etc.
[0071] S120: splicing the comment information and the commented information, and performing feature extraction based on the spliced information to obtain target features.
[0072] It should be noted that by concatenating the comment information and the commented information, subsequent feature extraction can be facilitated. It should be noted that by performing feature extraction based on the concatenated information, both the comment information and the commented information can be considered, which is helpful for subsequent emotional category judgment. It also helps to improve the accuracy of emotional classification for application scenarios with short or ambiguous comment information.
[0073] S130: Using a preset embedding layer, convert the emotion label into an embedding vector.
[0074] It should be noted that by converting the sentiment label into an embedding vector of fixed dimension, it is convenient to subsequently splice the embedding vector with the target feature for sentiment classification. Specifically, converting the discrete sentiment label (0, 1, 2, etc.) into a continuous vector representation, i.e., the embedding vector, can facilitate the subsequent splicing of the embedding vector with the target feature, and also help the sentiment classification model learn the semantic information of the sentiment label and the semantic relationship between the sentiment label and the text (the comment information and the commented information) during the training process.
[0075] S140: Concatenate the target feature with the corresponding embedding vector to obtain a comprehensive vector.
[0076] It should be noted that by concatenating the target feature and the embedded vector into a comprehensive vector, the sentiment classification model can not only learn the text features of the comment information and the commented information, but also learn the semantic information of the sentiment label and the semantic relationship between the sentiment label and the text. The additional information of the embedded vector helps the sentiment classification model to form a more robust feature representation during the training process, thereby improving the accuracy and robustness of the sentiment classification model.
[0077] S150: Inputting the comprehensive vector into the classification network of the sentiment classification model to complete the sentiment classification model training.
[0078] It should be noted that the sentiment classification model training method in the above embodiment can obtain a sentiment classification model with high accuracy, better classification effect and stronger robustness, thereby achieving high-precision sentiment classification of comment information, which helps relevant personnel understand and master the sentiment categories of comment information at a low cost.
[0079] In some embodiments, the step of extracting features based on the spliced information to obtain target features includes:
[0080] 1. Determine the spliced information as the original text, clean the original text, and obtain the target text.
[0081] It should be noted that by cleaning the original text, irrelevant information such as advertisements, duplicate comments, and URLs (Uniform Resource Locators) can be effectively removed, which helps to improve the accuracy of subsequent model training.
[0082] 2. Segment the comment information and the commented information in the target text respectively to obtain a plurality of vocabulary units.
[0083] Specifically, in this embodiment, the word segmentation tool of the Bert (Bidirectional Encoder Representations from Transformers) model is used to segment the comment information and the commented information in the target text respectively to obtain multiple independent vocabulary units. The Bert model in this embodiment refers to the Chinese pre-trained Bert model, that is, the Bert-base-chinese model.
[0084] 3. Input all the vocabulary units into a preset Bert model to perform information encoding to obtain a vector representation of each vocabulary unit, wherein the dimension of the vector representation is higher than the dimension of the vocabulary unit.
[0085] It should be noted that by inputting all the vocabulary units into the preset Bert model for information encoding, a high-dimensional vector representation of each vocabulary unit can be obtained, which helps to improve the accuracy of subsequent model training.
[0086] 4. Concatenate the vector representations of all the vocabulary units to obtain a target sequence.
[0087] It should be noted that the target sequence is the output information of the Bert model, and the dimension of the output information is (batch_size, seq_len, hidden_size), where batch_size represents the size of the batch training set, that is, the number of training samples in the training set, seq_len represents the length of the target sequence, and hidden_size represents the vector length of each vocabulary unit.
[0088] It should also be noted that by concatenating the vector representations of all the vocabulary units, the vector representations of the comment information and the commented information can be comprehensively utilized, so that the sentiment classification model can more comprehensively understand the contextual information of the comment and improve the accuracy of sentiment classification.
[0089] 5. Perform feature extraction based on the target sequence to obtain the target feature.
[0090] In some embodiments, the step of extracting features based on the target sequence to obtain the target features includes:
[0091] First, the target sequence is input into the long short-term memory network (LSTM) of the sentiment classification model to perform semantic feature extraction to obtain a plurality of target semantic features, wherein the target semantic features correspond one-to-one to the vector representation of the vocabulary unit.
[0092] It should be noted that by inputting the target sequence into the long short-term memory network for semantic feature extraction, the context information in the target sequence can be better captured to obtain the target semantic feature. In addition, by inputting the target sequence into the long short-term memory network for semantic feature extraction, the unique context information of each comment information and each vocabulary unit of the commented information can be retained.
[0093] Secondly, all the target semantic features are segmented according to a preset segment length to obtain a plurality of feature segments, each of which includes a fixed number of the target semantic features.
[0094] It should be noted that the segment length can be set according to actual conditions, such as 3 words (target semantic features) for a segment, or 4 words (target semantic features) for a segment, etc. By segmenting all target semantic features, it is convenient to use the vocabulary-level attention mechanism later to obtain the target representation of each feature segment.
[0095] Then, linear transformation is performed on all the target semantic features in the feature segment to obtain a plurality of first Key vectors, where the first Key vectors correspond to the target semantic features one by one.
[0096] Specifically, all target semantic features in the feature segment are multiplied by a learnable matrix to obtain several first Key vectors.
[0097] Then, the dot product between the first Key vector and the preset first Query vector is determined as the first attention weight.
[0098] It should be noted that a fixed context vector may be used as the first Query vector. By obtaining the first attention weight, it is possible to facilitate the subsequent acquisition of the target representation of each feature segment.
[0099] Afterwards, all the first attention weights are normalized to obtain the first target weight.
[0100] Next, based on the first target weight corresponding to each target semantic feature in the feature segment, a weighted sum is performed on each target semantic feature in the feature segment to obtain a target representation of each feature segment.
[0101] It should be noted that by adopting the above-mentioned word-level attention mechanism to obtain the target representation of each feature segment, it can help the sentiment classification model learn the semantics of different feature segments, so that the sentiment classification model can learn more fine-grained key sentiment information, which helps to improve the accuracy of sentiment classification.
[0102] Finally, based on the target representation of each feature segment, feature extraction is performed to obtain the target feature.
[0103] In order to further capture the key emotional information in the text from the overall level, this embodiment proposes a sentence-level attention mechanism. Specifically, based on the target representation of each feature segment, feature extraction is performed to obtain the target feature, including:
[0104] 1. Performing linear transformation on the target representation of each feature segment to obtain a plurality of second Key vectors, wherein the second Key vectors correspond to the feature segments one by one.
[0105] It should be noted that the target representation of each feature segment is multiplied by a learnable matrix to obtain several second Key vectors.
[0106] 2. Determine the dot product between the second Key vector and the preset second Query vector as the second attention weight.
[0107] 3. Normalize all the second attention weights to obtain the second target weight.
[0108] 4. Based on the second target weight corresponding to each feature segment, weighted sum is performed on the target representations of all the feature segments to obtain a final representation of the current target sequence; and the final representation is determined as the target feature.
[0109] It should be noted that by adopting the above-mentioned sentence-level attention mechanism to obtain the final representation of the target sequence, that is, the target feature, it can help the sentiment classification model to more accurately identify and classify the sentiment of the comment information, which is especially suitable for application scenarios of long and complex comments.
[0110] It should also be noted that the above-mentioned embodiment adopts a word-level attention mechanism and a sentence-level attention mechanism, so that the sentiment classification model can capture the key sentiment information of the text at a fine-grained and overall level, effectively enhancing the sentiment classification ability of the sentiment classification model.
[0111] In some embodiments, the step of inputting the comprehensive vector into a classification network of a sentiment classification model to complete sentiment classification model training includes:
[0112] 1. Input the comprehensive vector into the fully connected sub-network in the classification network, perform linear transformation and activation, and obtain a feature representation of a preset dimension, wherein the fully connected sub-network includes at least one fully connected unit, and the fully connected unit includes an intermediate fully connected layer and a nonlinear activation function layer.
[0113] It should be noted that by inputting the comprehensive vector into the fully connected sub-network in the classification network, it is possible to further extract features and reduce the dimension of the comprehensive vector, thereby enhancing the expression and learning capabilities of the sentiment classification model. The activation function corresponding to the nonlinear activation function layer may be a ReLU (Rectified Linear Unit, linear rectification function) activation function, etc.
[0114] 2. Input the feature representation into the output sub-network in the classification network, perform linear transformation and activation to obtain the sentiment classification result, and the output sub-network includes: a final fully connected layer and a Softmax (soft maximization function) activation function.
[0115] It should be noted that by inputting the feature representation into the output sub-network of the classification network and performing linear transformation and activation, a sentiment classification result with higher accuracy can be obtained.
[0116] 3. Based on the sentiment classification results, the sentiment classification model is trained.
[0117] Specifically, based on the gap between the sentiment classification results and the corresponding sentiment labels, the sentiment classification model is iteratively trained until convergence.
[0118] In some embodiments, the step of inputting the comprehensive vector into the fully connected sub-network in the classification network, performing linear transformation and activation, and obtaining a feature representation of a preset dimension includes:
[0119] 1. Input the comprehensive vector into the first fully connected unit of the fully connected sub-network, perform linear transformation and activation, and obtain an intermediate feature vector.
[0120] 2. Input the intermediate feature vector into the second fully connected unit of the fully connected subnetwork, perform linear transformation and activation, and obtain the feature representation of a preset dimension, wherein the dimension of the comprehensive vector is greater than the dimension of the intermediate feature vector, and the dimension of the intermediate feature vector is greater than the dimension of the feature representation.
[0121] It should be noted that, by setting the first fully connected unit and the second fully connected unit connected in sequence, it is possible to save computing resources while ensuring the accuracy of the feature representation as much as possible.
[0122] The sentiment classification model training method in the above embodiment is further explained below with a specific embodiment.
[0123] Please refer to Figure 2 First, the comment information and the commented information are input into the Bert-base-chinese model for word segmentation and information encoding to obtain the vector representation of each vocabulary unit, such as Figure 2 T1...Tn and T1'...Tm' in , where n represents the number of vocabulary units of the comment information and m represents the number of vocabulary units of the commented information. The vector representations of all vocabulary units are concatenated to obtain the target sequence. Secondly, the target sequence is input into the long short-term memory network (LSTM) to extract semantic features and obtain multiple target semantic features, such as Figure 2 H1...H1+r...Hn+mr...Hn+m shown in the figure. Afterwards, all target semantic features are segmented according to the preset segment length to obtain several feature segments, such as H1...H1+r belongs to one feature segment, Hn+mr...Hn+m belongs to one feature segment, etc. Where k represents the number of feature segments. Then, the vocabulary-level attention mechanism is used for each feature segment to obtain the target representation of each feature segment, such as Figure 2The target representation 1...target representation k in . Then, the sentence-level attention mechanism is used to obtain the final representation of the target sequence, that is, the target feature. Then, the target feature is spliced with the embedding vector of the sentiment label to obtain a comprehensive vector. Finally, the comprehensive vector is input into the classification network of the sentiment classification model to complete the sentiment classification model training. Specifically, the comprehensive vector is input into the first fully connected unit of the fully connected subnetwork (the first intermediate fully connected layer and the first nonlinear activation function layer connected in sequence), linearly transformed and activated to obtain a 128-dimensional intermediate feature vector; the intermediate feature vector is input into the second fully connected unit of the fully connected subnetwork (the second intermediate fully connected layer and the second nonlinear activation function layer connected in sequence), linearly transformed and activated to obtain a 64-dimensional feature representation; the feature representation is input into the output subnetwork of the classification network (the final fully connected layer and the Softmax activation function layer connected in sequence), linearly transformed and activated to obtain the sentiment classification result. Through the above steps, the training of the sentiment classification model can be well realized, which is suitable for application scenarios such as sentiment analysis of social software comment information, timely monitoring of brand image and negative public opinion by enterprises.
[0124] The sentiment classification model training system provided in the present application is described below. The sentiment classification model training system described below and the sentiment classification model training method described above can refer to each other.
[0125] Please refer to Figure 3 , the sentiment classification model training system provided in this embodiment includes:
[0126] The training set acquisition module 310 is used to acquire a training set, wherein the training set includes a plurality of training samples, and the training samples include: comment information, commented information, and sentiment labels;
[0127] A processing module 320 is used to splice the comment information and the commented information, and extract features based on the spliced information to obtain target features;
[0128] An embedding module 330, used to convert the emotion tag into an embedding vector using a preset embedding layer;
[0129] A concatenation module 340 is used to concatenate the target feature with the corresponding embedding vector to obtain a comprehensive vector;
[0130] The training module 350 is used to input the comprehensive vector into the classification network of the sentiment classification model to complete the sentiment classification model training. The training set acquisition module 310, the processing module 320, the embedding module 330, the splicing module 340 and the training module 350 are connected. The sentiment classification model training system in this embodiment can well improve the accuracy of the sentiment classification model. The sentiment classification effect of the trained sentiment classification model is better, the stability is enhanced, the cost is low, and the sentiment classification of the comment information can be well realized.
[0131] In some embodiments, the processing module 320 is specifically used to determine the spliced information as the original text, clean the original text, and obtain the target text;
[0132] Segmenting the comment information and the commented information in the target text to obtain a plurality of vocabulary units;
[0133] Inputting all the vocabulary units into a preset Bert model to perform information encoding to obtain a vector representation of each vocabulary unit, wherein the dimension of the vector representation is higher than the dimension of the vocabulary unit;
[0134] Concatenating the vector representations of all the vocabulary units to obtain a target sequence;
[0135] Feature extraction is performed based on the target sequence to obtain the target feature.
[0136] In some embodiments, the processing module 320 is further specifically used to input the target sequence into the long short-term memory network of the sentiment classification model to extract semantic features to obtain a plurality of target semantic features, wherein the target semantic features correspond one-to-one to the vector representation of the vocabulary unit;
[0137] Segmenting all the target semantic features according to a preset segment length to obtain a plurality of feature segments, each of which includes a fixed number of the target semantic features;
[0138] Performing linear transformation on all the target semantic features in the feature segment to obtain a plurality of first Key vectors, wherein the first Key vectors correspond to the target semantic features one by one;
[0139] Determine the dot product between the first Key vector and the preset first Query vector as a first attention weight;
[0140] Normalizing all of the first attention weights to obtain a first target weight;
[0141] Based on the first target weight corresponding to each target semantic feature in the feature segment, weighted summing each target semantic feature in the feature segment to obtain a target representation of each feature segment;
[0142] Based on the target representation of each feature segment, feature extraction is performed to obtain the target feature.
[0143] In some embodiments, the processing module 320 is further specifically configured to perform a linear transformation on the target representation of each feature segment to obtain a plurality of second Key vectors, wherein the second Key vectors correspond to the feature segments one by one;
[0144] Determine the dot product between the second Key vector and the preset second Query vector as a second attention weight;
[0145] Normalizing all the second attention weights to obtain a second target weight;
[0146] Based on the second target weight corresponding to each feature segment, the target representations of all the feature segments are weighted summed to obtain a final representation of the current target sequence; and the final representation is determined as the target feature.
[0147] In some embodiments, the training module 350 is specifically used to input the comprehensive vector into the fully connected sub-network in the classification network, perform linear transformation and activation, and obtain a feature representation of a preset dimension, wherein the fully connected sub-network includes at least one fully connected unit, and the fully connected unit includes an intermediate fully connected layer and a nonlinear activation function layer;
[0148] Input the feature representation into the output sub-network in the classification network, perform linear transformation and activation to obtain a sentiment classification result, wherein the output sub-network includes: a final fully connected layer and a Softmax activation function layer;
[0149] Based on the sentiment classification result, the sentiment classification model is trained.
[0150] In some embodiments, the training module 350 is further specifically used to input the comprehensive vector into the first fully connected unit of the fully connected sub-network, perform linear transformation and activation, and obtain an intermediate feature vector;
[0151] The intermediate feature vector is input into the second fully connected unit of the fully connected subnetwork for linear transformation and activation to obtain the feature representation of a preset dimension, wherein the dimension of the comprehensive vector is greater than the dimension of the intermediate feature vector, and the dimension of the intermediate feature vector is greater than the dimension of the feature representation.
[0152] Please refer to Figure 4This embodiment also provides a comment information sentiment classification method, including:
[0153] S410: Acquire the text to be classified, where the text to be classified includes comment information to be classified and commented information to be classified.
[0154] S420: splicing the comment information to be classified with the commented information to be classified to obtain spliced information.
[0155] S430: Based on the spliced information and the trained sentiment classification model, sentiment classification is performed to obtain the sentiment category of the comment information to be classified, wherein the trained sentiment classification model is trained by any of the sentiment classification model training methods described above. The comment information sentiment classification method in this embodiment can achieve high-precision comment information sentiment classification.
[0156] In some embodiments, based on the spliced information and the trained sentiment classification model, sentiment classification is performed to obtain the sentiment category of the comment information to be classified, including:
[0157] First, the splicing information is cleaned to obtain a cleaned text.
[0158] Secondly, the comment information to be classified and the commented information to be classified in the cleaned text are segmented respectively to obtain a plurality of target vocabulary units.
[0159] Then, all the target vocabulary units are input into a preset Bert model to perform information encoding to obtain a target vector representation of each target vocabulary unit, wherein the dimension of the target vector representation is higher than the dimension of the target vocabulary unit.
[0160] Then all the target vector representations are concatenated to obtain a concatenated sequence.
[0161] Finally, the concatenated sequence is input into the trained sentiment classification model to perform sentiment classification to obtain the sentiment category of the comment information to be classified.
[0162] The comment information sentiment classification system provided by the present application is described below. The comment information sentiment classification system described below and the comment information sentiment classification method described above can be referenced to each other.
[0163] Please refer to Figure 5 , the comment information sentiment classification system provided in this embodiment includes:
[0164] The to-be-classified text acquisition module 510 is used to acquire the to-be-classified text, wherein the to-be-classified text includes the to-be-classified comment information and the to-be-classified commented information;
[0165] A target splicing module 520 is used to splice the comment information to be classified with the commented information to be classified to obtain spliced information;
[0166] The sentiment classification module 530 is used to perform sentiment classification based on the splicing information and the trained sentiment classification model to obtain the sentiment category of the comment information to be classified, and the trained sentiment classification model is trained by the sentiment classification model training method described in any one of the above items. The comment information sentiment classification system in this embodiment can better realize the sentiment classification of the commented information to be classified, which is convenient for relevant personnel to grasp the sentiment category of the commented information to be classified, with high accuracy and low cost.
[0167] In some embodiments, the sentiment classification module 530 is specifically used to clean the spliced information to obtain a cleaned text;
[0168] Performing word segmentation on the comment information to be classified and the commented information to be classified in the cleaned text to obtain a plurality of target vocabulary units;
[0169] Inputting all the target vocabulary units into a preset Bert model to perform information encoding to obtain a target vector representation of each target vocabulary unit, wherein the dimension of the target vector representation is higher than the dimension of the target vocabulary unit;
[0170] Concatenating all the target vector representations to obtain a concatenated sequence;
[0171] The concatenated sequence is input into the trained sentiment classification model to perform sentiment classification to obtain the sentiment category of the comment information to be classified.
[0172] In some embodiments, an electronic device is also provided, which may be a server, and its internal structure is shown in FIG. Figure 6 As shown. The electronic device includes a processor, a memory, a network interface and a database connected via a system bus. The processor of the electronic device is used to provide computing and control capabilities. The memory of the electronic device includes a non-volatile and / or volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The network interface of the electronic device is used to communicate with an external client via a network connection. When the computer program is executed by the processor, the functions or steps on the server side of the above method are implemented.
[0173] In some embodiments, an electronic device is provided, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, the following steps are implemented: obtaining a training set, the training set includes multiple training samples, the training samples include: comment information, commented information, and sentiment labels; splicing the comment information and the commented information, extracting features based on the spliced information, and obtaining target features; using a preset embedding layer, converting the sentiment label into an embedding vector; splicing the target feature with the corresponding embedding vector to obtain a comprehensive vector; inputting the comprehensive vector into a classification network of a sentiment classification model to complete sentiment classification model training. Or the following steps are implemented: obtaining a text to be classified, the text to be classified includes comment information to be classified and commented information to be classified; splicing the comment information to be classified and the commented information to be classified to obtain spliced information; performing sentiment classification based on the spliced information and the trained sentiment classification model to obtain the sentiment category of the comment information to be classified, the trained sentiment classification model is trained using any of the sentiment classification model training methods described above.
[0174] In some embodiments, a computer-readable storage medium is provided, on which a computer program is stored, and when the computer program is executed by a processor, the following steps are implemented: obtaining a training set, the training set includes multiple training samples, and the training samples include: comment information, commented information, and sentiment labels; splicing the comment information and the commented information, and extracting features based on the spliced information to obtain target features; using a preset embedding layer, converting the sentiment label into an embedding vector; splicing the target feature with the corresponding embedding vector to obtain a comprehensive vector; inputting the comprehensive vector into the classification network of the sentiment classification model to complete the sentiment classification model training. Or the following steps are implemented: obtaining a text to be classified, the text to be classified includes the comment information to be classified and the commented information to be classified; splicing the comment information to be classified and the commented information to be classified to obtain spliced information; performing sentiment classification based on the spliced information and the trained sentiment classification model to obtain the sentiment category of the comment information to be classified, and the trained sentiment classification model is trained using any of the sentiment classification model training methods described above.
[0175] It should be noted that the above functions or steps that can be implemented by the computer-readable storage medium or electronic device can refer to the relevant descriptions on the server side and the client side in the aforementioned method embodiment. To avoid repetition, they will not be described one by one here.
[0176] The flow chart and block diagram in the accompanying drawings illustrate the possible implementation architecture, function and operation of the method and computer program product according to various embodiments of the present disclosure. In this regard, each square box in the flow chart or block diagram can represent a module, a program segment, or a part of a code, and the module, program segment, or a part of a code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some implementations as replacements, the functions marked in the square box can also occur in a sequence different from that marked in the accompanying drawings. For example, two square boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each square box in the block diagram and / or flow chart, and the combination of the square boxes in the block diagram and / or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0177] The above embodiments are merely illustrative of the principles and effects of the present application and are not intended to limit the present application. Anyone familiar with the technology may modify or change the above embodiments without violating the spirit and scope of the present application. Therefore, all equivalent modifications or changes made by a person of ordinary skill in the art without departing from the spirit and technical ideas disclosed in the present application shall still be covered by the claims of the present application.
Claims
1. A sentiment classification model training method, characterized in that: include: Acquire a training set, wherein the training set includes a plurality of training samples, and the training samples include: comment information, commented information, and sentiment labels; splicing the comment information with the commented information, and performing feature extraction based on the spliced information to obtain target features; Using a preset embedding layer, converting the emotion label into an embedding vector; Concatenating the target feature with the corresponding embedding vector to obtain a comprehensive vector; The comprehensive vector is input into the classification network of the sentiment classification model to complete the sentiment classification model training.
2. The sentiment classification model training method according to claim 1, characterized in that: The steps of extracting features based on the spliced information and obtaining target features include: The spliced information is determined as the original text, and the original text is cleaned to obtain the target text; Segmenting the comment information and the commented information in the target text to obtain a plurality of vocabulary units; Inputting all the vocabulary units into a preset Bert model to perform information encoding to obtain a vector representation of each vocabulary unit, wherein the dimension of the vector representation is higher than the dimension of the vocabulary unit; Concatenating the vector representations of all the vocabulary units to obtain a target sequence; Feature extraction is performed based on the target sequence to obtain the target feature.
3. The sentiment classification model training method according to claim 2, characterized in that: The step of extracting features based on the target sequence to obtain the target features includes: Inputting the target sequence into the long short-term memory network of the sentiment classification model to extract semantic features to obtain a plurality of target semantic features, wherein the target semantic features correspond one-to-one to the vector representation of the vocabulary unit; Segmenting all the target semantic features according to a preset segment length to obtain a plurality of feature segments, each of which includes a fixed number of the target semantic features; Performing linear transformation on all the target semantic features in the feature segment to obtain a plurality of first Key vectors, wherein the first Key vectors correspond to the target semantic features one by one; Determine the dot product between the first Key vector and the preset first Query vector as a first attention weight; Normalizing all of the first attention weights to obtain a first target weight; Based on the first target weight corresponding to each target semantic feature in the feature segment, weighted summing each target semantic feature in the feature segment to obtain a target representation of each feature segment; Based on the target representation of each feature segment, feature extraction is performed to obtain the target feature.
4. The sentiment classification model training method according to claim 3, characterized in that: Based on the target representation of each feature segment, feature extraction is performed to obtain the target feature, comprising: Performing linear transformation on the target representation of each of the feature segments to obtain a plurality of second Key vectors, wherein the second Key vectors correspond to the feature segments one by one; Determine the dot product between the second Key vector and the preset second Query vector as a second attention weight; Normalizing all the second attention weights to obtain a second target weight; Based on the second target weight corresponding to each feature segment, the target representations of all the feature segments are weighted summed to obtain a final representation of the current target sequence; and the final representation is determined as the target feature.
5. The sentiment classification model training method according to any one of claims 1 to 4, characterized in that: The step of inputting the comprehensive vector into the classification network of the sentiment classification model to complete the sentiment classification model training includes: Inputting the comprehensive vector into a fully connected sub-network in the classification network, performing linear transformation and activation, and obtaining a feature representation of a preset dimension, wherein the fully connected sub-network includes at least one fully connected unit, and the fully connected unit includes an intermediate fully connected layer and a nonlinear activation function layer; Input the feature representation into the output sub-network in the classification network, perform linear transformation and activation to obtain a sentiment classification result, wherein the output sub-network includes: a final fully connected layer and a Softmax activation function layer; Based on the sentiment classification result, the sentiment classification model is trained.
6. The sentiment classification model training method according to claim 5, characterized in that: The step of inputting the comprehensive vector into the fully connected sub-network in the classification network, performing linear transformation and activation, and obtaining a feature representation of a preset dimension comprises: Inputting the comprehensive vector into the first fully connected unit of the fully connected sub-network, performing linear transformation and activation, and obtaining an intermediate feature vector; The intermediate feature vector is input into the second fully connected unit of the fully connected subnetwork for linear transformation and activation to obtain the feature representation of a preset dimension, wherein the dimension of the comprehensive vector is greater than the dimension of the intermediate feature vector, and the dimension of the intermediate feature vector is greater than the dimension of the feature representation.
7. A sentiment classification model training system, characterized in that: include: A training set acquisition module, used to acquire a training set, wherein the training set includes a plurality of training samples, and the training samples include: comment information, commented information, and sentiment labels; A processing module, used for splicing the comment information with the commented information, and performing feature extraction based on the spliced information to obtain target features; An embedding module, used to convert the emotion label into an embedding vector using a preset embedding layer; A concatenation module, used for concatenating the target feature with the corresponding embedding vector to obtain a comprehensive vector; The training module is used to input the comprehensive vector into the classification network of the sentiment classification model to complete the sentiment classification model training.
8. A method for sentiment classification of comment information, characterized in that: include: Acquire the text to be classified, wherein the text to be classified includes comment information to be classified and commented information to be classified; splicing the comment information to be classified with the commented information to be classified to obtain spliced information; Based on the concatenated information and the trained sentiment classification model, sentiment classification is performed to obtain the sentiment category of the comment information to be classified, and the trained sentiment classification model is trained using the sentiment classification model training method according to any one of claims 1 to 6.
9. The comment information sentiment classification method according to claim 8 is characterized in that: Based on the spliced information and the trained sentiment classification model, sentiment classification is performed to obtain the sentiment category of the comment information to be classified, including: Cleaning the spliced information to obtain a cleaned text; Performing word segmentation on the comment information to be classified and the commented information to be classified in the cleaned text to obtain a plurality of target vocabulary units; Inputting all the target vocabulary units into a preset Bert model to perform information encoding to obtain a target vector representation of each target vocabulary unit, wherein the dimension of the target vector representation is higher than the dimension of the target vocabulary unit; Concatenating all the target vector representations to obtain a concatenated sequence; The concatenated sequence is input into the trained sentiment classification model to perform sentiment classification to obtain the sentiment category of the comment information to be classified.
10. A comment information sentiment classification system, characterized in that: include: A module for acquiring text to be classified, used for acquiring text to be classified, wherein the text to be classified includes comment information to be classified and commented information to be classified; A target splicing module, used for splicing the comment information to be classified with the commented information to be classified to obtain spliced information; The sentiment classification module is used to perform sentiment classification based on the splicing information and the trained sentiment classification model to obtain the sentiment category of the comment information to be classified. The trained sentiment classification model is trained using the sentiment classification model training method as described in any one of claims 1 to 6.
