Text-based sentiment classification method, system and electronic device
The text is split and predicted through the regional CNN-LSTM model of tree structure and the emotional word vector library, which solves the problem of low accuracy in Chinese dimensional sentiment analysis and achieves a more efficient emotion prediction effect.
Patent Information
- Application Number
- CN202310769938.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-06-27
- Publication Date
- 2025-08-22
- Estimated Expiration
- 2043-06-27
AI Technical Summary
The existing Chinese dimensional sentiment analysis method has low accuracy in sentiment analysis due to the single text area split and uneven distribution of long and short sentences.
The text is split by using the regional CNN-LSTM model of tree structure, combined with the emotional word vector library and linear activation function to perform emotional prediction, and split the text information to be tested through the text prediction model, extract the ordered text areas to be tested and predict emotions, and obtain the target emotional label for emotional classification.
It improves the accuracy of emotion prediction, can better extract local emotional characteristics and consider the long-distance dependence between texts, and improves the accuracy of emotion analysis.
Smart Images

Figure CN116775877B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of text emotion prediction, and in particular to a text-based emotion classification method, system and electronic equipment. Background Art
[0002] Text sentiment analysis uses computational linguistics to analyze, process, summarize, and reason about emotionally charged, subjective text. Currently, there are two main approaches to sentiment analysis: categorical and dimensional. Dimensional sentiment analysis provides more detailed emotional information than categorical methods.
[0003] However, the current dimensional sentiment analysis methods for Chinese have low sentiment analysis accuracy due to the single text region splitting and unbalanced distribution of long and short sentences.
[0004] Therefore, a text-based sentiment classification method, system and electronic device are proposed. Summary of the Invention
[0005] This specification provides a text-based sentiment classification method, system and electronic device, which obtain original text information; perform data cleaning on the original text information to obtain text information to be tested; in order to improve the accuracy of sentiment prediction, the text information to be tested is first split, and then sentiment prediction is performed on the text information to be tested to obtain a target sentiment label corresponding to the original text information, and the original text information is sentimentally classified according to the target sentiment label.
[0006] This application provides a text-based sentiment classification method that adopts the following technical solutions, including:
[0007] Get the original text information;
[0008] Performing data cleaning on the original text information to obtain text information to be tested;
[0009] The text information to be tested is split by a text prediction model to obtain ordered text regions to be tested, sentiment prediction is performed on the ordered text regions to obtain target sentiment labels corresponding to the original text information, and sentiment classification is performed on the original text information according to the target sentiment labels.
[0010] Optionally, performing data cleaning on the original text information includes:
[0011] Remove the English part of the original text information;
[0012] and / or, removing numbers from the original text information;
[0013] and / or, removing spaces from the original text information;
[0014] And / or, performing punctuation conversion on the original text information.
[0015] Optionally, the text information to be tested is split using a text prediction model to obtain ordered text regions to be tested, sentiment prediction is performed on the ordered text regions to be tested to obtain target sentiment labels corresponding to the original text information, and sentiment classification is performed on the original text information according to the target sentiment labels, including:
[0016] Splitting the text information to be tested according to the text splitting strategy to obtain a plurality of ordered text regions to be tested;
[0017] Extracting features from the text region to be tested to obtain regional sentiment features, wherein the regional sentiment features correspond one-to-one to the text region to be tested;
[0018] According to the order of the text regions to be tested, the corresponding regional sentiment features are traversed in turn to obtain the target sentiment label.
[0019] Optionally, the text information to be tested is split according to a text splitting strategy to obtain a plurality of ordered text regions to be tested, including:
[0020] Determining all language structures to be tested corresponding to the text information to be tested;
[0021] Sequentially splitting the text regions to be tested obtained by the n-th level splitting according to the splitting sub-strategy of the n+1-th level language structure to be tested, to obtain a text content group to be tested corresponding to the n+1-th level language structure to be tested, wherein the text content group to be tested corresponding to the n+1-th level language structure to be tested includes a plurality of ordered text regions to be tested;
[0022] All the text content groups to be tested are sorted according to the sorting logic of all the language structures to be tested to obtain a sentiment classification sequence, and the sentiment classification sequence includes all the text regions to be tested.
[0023] Optionally, the determining of all language structures to be tested corresponding to the text information to be tested includes:
[0024] Identify the initial level language structure of the text information to be tested, and search for all language structures to be tested corresponding to the text information to be tested; sort the language structures to be tested according to their complexity, wherein the language structures to be tested include all language structures with a complexity lower than or equal to that of the initial level language structure.
[0025] Optionally, extracting features from the text region to be tested to obtain regional sentiment features includes:
[0026] Identifying words in the text region to be tested, converting the words in the text region to corresponding word vectors, and constructing a sentiment prediction region matrix based on the word vectors;
[0027] Performing feature extraction on the emotion prediction region matrix to obtain at least one local emotion feature;
[0028] The local sentiment features are filtered to obtain the regional sentiment features.
[0029] This application provides a text-based sentiment classification system that adopts the following technical solutions, including:
[0030] Acquisition module, used to obtain original text information;
[0031] A preprocessing module is used to perform data cleaning on the original text information to obtain the text information to be tested;
[0032] The prediction module is used to split the text information to be tested through a text prediction model to obtain ordered text areas to be tested, perform sentiment prediction on the ordered text areas to be tested, obtain target sentiment labels corresponding to the original text information, and perform sentiment classification on the original text information according to the target sentiment labels.
[0033] Optionally, the preprocessing module includes:
[0034] A first processing submodule, configured to remove English from the original text information;
[0035] A second processing submodule, configured to remove numbers from the original text information;
[0036] A third processing submodule is used to remove spaces from the original text information;
[0037] The fourth processing submodule is configured to convert punctuation marks on the original text information.
[0038] Optionally, the prediction module includes:
[0039] A splitting submodule is used to split the text information to be tested according to the text splitting strategy to obtain a plurality of ordered text regions to be tested;
[0040] A feature extraction submodule is used to extract features from the text region to be tested to obtain regional sentiment features, wherein the regional sentiment features correspond one-to-one to the text region to be tested;
[0041] The prediction submodule is used to traverse the corresponding regional sentiment features in the order of the text regions to be tested to obtain the target sentiment label.
[0042] Optionally, the splitting submodule includes:
[0043] A language structure determination unit, configured to determine all language structures to be tested corresponding to the text information to be tested;
[0044] a splitting unit, configured to sequentially split the text regions to be tested obtained by the n-th level splitting according to the splitting sub-strategy of the n+1-th level language structure to be tested, to obtain a text content group to be tested corresponding to the n+1-th level language structure to be tested, wherein the text content group to be tested corresponding to the n+1-th level language structure to be tested includes a plurality of ordered text regions to be tested;
[0045] The summarizing unit is used to sort all the text content groups to be tested according to the sorting logic of all the language structures to be tested, and obtain a sentiment classification sequence, wherein the sentiment classification sequence includes all the text regions to be tested.
[0046] Optionally, the language structure determination unit includes:
[0047] The sorting subunit is used to identify the initial level language structure of the text information to be tested, search for all the language structures to be tested corresponding to the text information to be tested, and sort the language structures to be tested according to their complexity, wherein the language structures to be tested include all language structures with a complexity lower than or equal to that of the initial level language structure.
[0048] Optionally, the feature extraction submodule includes:
[0049] a matrix construction unit, configured to identify words in the text region to be tested, convert the words in the text region to corresponding word vectors, and construct a sentiment prediction region matrix based on the word vectors;
[0050] A feature extraction unit, configured to extract features from the emotion prediction region matrix to obtain at least one local emotion feature;
[0051] The filtering unit is used to filter the local emotional features to obtain the regional emotional features.
[0052] This specification also provides an electronic device, wherein the electronic device includes:
[0053] processor; and,
[0054] A memory storing computer executable instructions, which, when executed, cause the processor to perform any of the above methods.
[0055] This specification also provides a computer-readable storage medium, wherein the computer-readable storage medium stores one or more programs, and when the one or more programs are executed by a processor, any of the above methods is implemented.
[0056] In this application, the original text information is obtained; the original text information is cleaned to obtain the text information to be tested; when the sentiment prediction is performed on the text information to be tested through a text prediction model, in order to improve the accuracy of the sentiment prediction, the text information to be tested is first split into multiple text areas to be tested, and then the regional sentiment features corresponding to the text areas to be tested are extracted, and then the target sentiment label corresponding to the original text information is obtained, and the original text information is sentimentally classified according to the target sentiment label. BRIEF DESCRIPTION OF THE DRAWINGS
[0057] Figure 1 A schematic diagram of the principle of a text-based sentiment classification method provided in an embodiment of this specification;
[0058] Figure 2 A schematic diagram of the principle of S41 of a text-based sentiment classification method provided in an embodiment of this specification;
[0059] Figure 3 A schematic diagram of the structure of a text-based sentiment classification system provided in an embodiment of this specification;
[0060] Figure 4 A schematic diagram of the structure of an electronic device provided in an embodiment of this specification;
[0061] Figure 5 A schematic diagram of a computer-readable medium provided in accordance with an embodiment of this specification. DETAILED DESCRIPTION
[0062] The following description is intended to disclose the present invention so that those skilled in the art can implement the present invention. The preferred embodiments described below are for illustrative purposes only, and those skilled in the art will readily appreciate other obvious variations. The basic principles of the present invention defined in the following description may be applied to other embodiments, variations, improvements, equivalents, and other technical solutions that do not depart from the spirit and scope of the present invention.
[0063] Exemplary embodiments of the present invention will now be described more fully with reference to the accompanying drawings. However, exemplary embodiments can be implemented in various forms, and it should not be understood that the present invention is limited to the embodiments set forth herein. On the contrary, providing these exemplary embodiments enables the present invention to be more comprehensive and complete, making it easier to fully convey the inventive concept to those skilled in the art. In the figures, the same reference numerals represent the same or similar elements, components or parts, and thus their repeated description will be omitted.
[0064] Under the premise of being consistent with the technical concept of the present invention, the features, structures, characteristics or other details described in a specific embodiment do not exclude that they can be combined in one or more other embodiments in a suitable manner.
[0065] In the description of specific embodiments, the features, structures, characteristics, or other details of the present invention are described to enable those skilled in the art to fully understand the embodiments. However, this does not preclude those skilled in the art from practicing the technical solutions of the present invention without one or more of the specific features, structures, characteristics, or other details.
[0066] The flowcharts shown in the accompanying drawings are for illustrative purposes only and do not necessarily include all contents and operations / steps, nor must they be executed in the order described. For example, some operations / steps may be decomposed, while others may be combined or partially combined. Therefore, the actual execution order may vary depending on the actual situation.
[0067] The block diagrams shown in the accompanying drawings are merely functional entities and do not necessarily correspond to physically separate entities. That is, these functional entities may be implemented in software, in one or more hardware modules or integrated circuits, or in different networks and / or processor devices and / or microcontroller devices.
[0068] The term "and / or" or "and / or" includes all combinations of any one or more of the associated listed items.
[0069] Figure 1 A schematic diagram of the principle of a text-based sentiment classification method provided in an embodiment of this specification includes:
[0070] S2 obtains original text information;
[0071] S3 performs data cleaning on the original text information to obtain the text information to be tested;
[0072] S4 splits the text information to be tested through a text prediction model to obtain ordered text areas to be tested, performs sentiment prediction on the ordered text areas to be tested, obtains target sentiment labels corresponding to the original text information, and performs sentiment classification on the original text information according to the target sentiment labels.
[0073] Because emotions are inherently complex and abstract, many researchers have been unable to reach a unified standard for emotion classification when working on affective computing. Currently, researchers generally categorize emotion analysis methods into categorical and dimensional methods.
[0074] Categorical sentiment analysis methods, also known as discrete sentiment analysis methods, can be understood from a categorical perspective. They represent emotional states as discrete basic emotion categories. By determining which basic emotion category a text belongs to, the corresponding emotion of the text is predicted.
[0075] Dimensional sentiment analysis methods, also known as continuous sentiment analysis methods, can be understood from a dimensional perspective. They represent emotional states as continuous numerical values across multiple dimensions to reflect emotional intensity or intensity differences. For example, the VA (Valence-Arousal) model and the VAD (Valence-Arousal-Dominance) model. Regarding the VA model, its horizontal and vertical axes represent pleasure (Valence) and arousal (Arousal), respectively. Pleasure represents the degree of pleasure of the emotion, and arousal represents the intensity of the emotion. The four extremes of the VA model represent four different discrete emotion categories: happiness (high pleasure, high arousal), relaxation (high pleasure, low arousal), boredom (low pleasure, low arousal), and panic (low pleasure, high arousal).
[0076] The VAD model adds a dimension, Dominance, to the VA model, which can classify / distinguish some emotion categories that cannot be distinguished by the VA model.
[0077] There are currently many models for sentiment analysis and prediction, such as sentiment analysis and prediction methods based on sentiment dictionaries, regression models, convolutional neural networks, and long short-term memory neural networks.
[0078] However, sentiment analysis prediction methods based on sentiment dictionaries and regression models are not effective for texts with long-distance dependencies, and the matching accuracy of local sentiment features is low;
[0079] Convolutional neural network (CNN)-based sentiment analysis and prediction methods use convolutional kernels to extract local features and use a maximum pooling layer to select the most significant local sentiment features, but they fail to capture long-range dependencies. If a long sentence contains multiple valuable local sentiment features, this method will miss the corresponding valuable local features.
[0080] Sentiment analysis and prediction methods based on long-short-term neural networks (LSTMs) sequentially extract text from sentences. However, as a biased model, the key features at the end of the text dominate the key features at the beginning, causing the model to always make decisions based on the tail information and potentially fail to extract significant local sentiment features.
[0081] When the distribution of long and short sentences is unbalanced, if the sentence is too short, the influence of the corresponding local emotional features of its words will be significantly increased; if the sentence is too long, the influence of the local emotional features of the words in it will be significantly reduced. This situation can easily lead to deviations in the results of emotional prediction, thereby reducing accuracy.
[0082] Therefore, in order to better extract local sentiment features and consider the long-distance dependencies between texts to improve the accuracy of sentiment analysis prediction, the present invention constructs a tree-structured regional CNN-LSTM model for sentiment analysis prediction, which specifically includes:
[0083] S1 builds and trains text prediction models;
[0084] S11 builds the original text dataset;
[0085] The original text dataset includes a number of emotion training data, where the emotion training data includes emotion training texts and emotion labels corresponding to the emotion training texts.
[0086] Among them, considering the lack of public original text data sets in the field of Chinese text, in one embodiment of this specification, currently published articles, comments, etc. are obtained as emotion training texts, and S111 constructs an emotion training text set, which is an emotion training text set of Chinese text.
[0087] Then, the evaluator annotates each sentiment training text with sentiment polarity, and S112 obtains the manual annotation results of the sentiment training text.
[0088] In order to avoid obtaining irrelevant manual annotation results, in one embodiment of the present specification, label options are provided for each emotion training text based on a preset emotion model, and the label selection results of each emotion training text are obtained as the manual annotation results of the emotion training text. Specifically, the preset emotion model can be a one-dimensional emotion model; or a two-dimensional emotion model, such as the Valence-Arousal emotion model (VA model); or a three-dimensional emotion model, such as the Valence-arousal-dominance emotion model (VAD model), etc. Considering that when manually distinguishing the emotions expressed in the emotion training text, too few label selections may result in a lack of labels that can accurately express the true emotions of the text, thereby limiting the evaluator's choices and reducing the matching degree between the emotion label and the emotion training text; and too many label selections may bring information overload, affecting the evaluator's effective decision-making, thereby reducing the accuracy of label selection, and may not be able to effectively highlight the differences between the labels. Based on the above considerations, the preset emotion model is preferably a VA model, and a continuous two-dimensional Valence-Arousal space with labels in the range of [0-10] is constructed. In one embodiment of this specification, in addition to selecting labels for the emotion training text, the evaluator also needs to identify paragraphs in the emotion dataset. The paragraphs in the emotion dataset are paragraphs that can perceive strong emotional changes. Therefore, the present invention further includes obtaining the evaluator's paragraph identification results and adding preset paragraph annotations to the emotion training text.
[0089] Then, S113 determines the original emotion label corresponding to the emotion training text based on the manual annotation results. In order to obtain a more comprehensive and objective annotation result, multiple people perform emotion polarity annotation on the same emotion training text. Specifically, the label with the most annotations is used as the original emotion label corresponding to the emotion training text.
[0090] The emotional training text and its corresponding emotional label are taken as an emotional training data, and the emotional training data are aggregated to construct a training text dataset.
[0091] S12 constructs a sentiment word vector library based on the sentiment training text;
[0092] S121 segments the emotion training text to extract emotion training paragraphs;
[0093] The emotion training paragraphs are paragraphs in the emotion dataset. Since the paragraphs in the emotion dataset have been previously labeled, in order to quickly find the emotion training paragraphs, in one embodiment of this specification, extracting the emotion training paragraphs includes: identifying paragraphs in the emotion training text that include preset paragraph annotations as the emotion training paragraphs.
[0094] S122 performs word embedding encoding on the sentiment training paragraph to obtain a word vector representation, summarizes all word vector representations in the sentiment training text set, and constructs a sentiment word vector library.
[0095] S13 builds a text prediction model;
[0096] As mentioned earlier, convolutional neural networks (CNNs) can effectively extract local features contained in input word vectors. However, CNNs cannot effectively "consider" other local features contained in a sentence or text as a whole. Long short-term memory neural networks (LSTMs) can solve this problem by sequentially modeling sentences or texts, but they lack the advantages of CNNs. This application constructs a regional CNN-LSTM structure to take into account other local sentiment features while extracting effective local sentiment features.
[0097] However, in the regional CNN-LSTM structure, the size of the text region will determine the range of local features extracted by its convolutional layer. Reasonable regional splitting helps improve prediction performance. Based on this, in order to improve the effect of sentiment prediction, the present invention combines the regional CNN-LSTM structure with a tree structure method to optimize the text region to be tested received by the CNN input layer. Specifically, the text prediction model is a regional CNN-LSTM model using a tree structure.
[0098] In one embodiment of the present specification, based on the received text, the text information to be tested is split according to the text splitting strategy. Specifically, the given text is parsed into a tree topology, and the same layer of the tree structure has the same language structure. The complexity of the language structure is inversely proportional to the depth of the node of the tree structure, that is, the more complex the language structure, the smaller the depth of the corresponding node. A preset language structure group is constructed, wherein the preset language structure group includes several language structures, and the language structure includes but is not limited to words, phrases, clauses, sentences, and paragraphs. Among them, the language structure of words is the simplest, and the depth of the corresponding tree is the largest. The language structure of paragraphs is the most complex, and the depth of the corresponding tree is the smallest.
[0099] In one embodiment of the present specification, the language structure to be tested of the received text is determined based on the initial-level language structure of the text, so as to facilitate the layer-by-layer splitting of the received text. If the initial-level language structure of the received text is a paragraph, then its corresponding tree topology is 5 layers, which are paragraphs, sentences, clauses, phrases, and words from top to bottom. The language structures to be tested are paragraphs, sentences, clauses, phrases, and words in order. According to the splitting sub-strategy corresponding to the language structure to be tested at each current level, the splitting results of the previous level are split in order; according to the sorting logic of the language structure to be tested, the splitting results corresponding to each language structure to be tested are summarized in order to obtain a number of ordered text regions.
[0100] According to the increasing depth of the tree, target nodes of different depths are extracted respectively, that is, the target nodes of the same depth are extracted in sequence first, and then the target nodes of depth + 1 (i.e., height - 1) are extracted in sequence, and so on, until the target node of the maximum depth is extracted. The ordered text regions are determined according to the target nodes as the input items of the regional CNN-LSTM structure.
[0101] In other words, the text region corresponding to the target node includes the child nodes related to the target node. The above text segmentation strategy obtains highly accurate prediction results based on text information at different granularity levels.
[0102] Compared to methods that sequentially input individual sentences as text regions into a sentiment prediction model, the tree-structured approach dynamically adapts the model structure based on the tree topology to extract significant local sentiment features at varying depths. The tree structure is continuously recursively split and recursively recursively until it reaches a leaf node, addressing the issue of variable tree depth and further improving the accuracy of the text prediction model in local sentiment analysis.
[0103] S14 trains a text prediction model;
[0104] The sentiment training text is split into text regions according to the text splitting strategy, and the sentiment training text is split into multiple text regions s in sequence. i , where i∈[1,n], and i∈N + ,n is the total number of text regions split from the sentiment training text. The language structure of the text region includes but is not limited to paragraphs, sentences, clauses, phrases and words.
[0105] Identify the words in the text area; convert the words in the text area into corresponding word vectors according to the sentiment word vector library, construct a sentiment prediction area matrix for the text area, and stack the word vectors corresponding to the words in the text area in a region matrix, wherein the sentiment prediction area matrix is n×k, n is the number of words in the text area, and k is the dimension of the word vector. In the sentiment prediction area matrix, each row is the corresponding word vector of a word, with a dimension of k, and each word in the text area is displayed vertically in the same order as the words in the text area. In one embodiment of the present specification, the dimension in the sentiment prediction area matrix is the number of non-repeated words in the text area.
[0106] S142 passes the emotion prediction region matrix through the convolution sublayer, pooling sublayer and sequence sublayer in sequence, outputs the regional emotion features corresponding to the emotion prediction information, summarizes the regional emotion features corresponding to each emotion prediction information domain in the emotion prediction text in order, outputs the target emotion label, and determines whether re-training is needed by checking whether the target emotion label corresponds to the original emotion label.
[0107] Specifically, the text region matrix first passes through the convolution sublayer to extract at least one local sentiment feature c of the text region j , j∈[1,n], and i∈N + ,n is where, convolutional filters are used to learn local sentiment features;
[0108] Then, the local sentiment features of the text region are filtered through the pooling sublayer, and only one local sentiment feature is retained for each text region as the regional sentiment feature of the text region, so as to simplify the network calculation complexity.
[0109] By filtering the pooling sublayer, non-important local emotional features can be filtered out, the number of parameters can be simplified, and the computational efficiency can be improved. In one embodiment of the present specification, a maximum pooling sublayer is used for processing, and by eliminating non-maximum values, the calculation of the lower layer is reduced. By extracting the long-range dependencies of different local emotional features, the most important local emotional features are retained as regional emotional features, so that the regional emotional features will be transmitted to the sequence sublayer.
[0110] In order to capture cross-region long-range dependencies, that is, to capture the long-range dependencies between different text regions, the target sentiment label vector is obtained by sequentially traversing the regional sentiment features of all text regions through the LSTM memory unit.
[0111] In one embodiment of the present specification, the sequence sublayer sequentially integrates the regional sentiment features of all text regions into a text vector, which is then input into the LSTM memory unit to obtain a target sentiment label vector.
[0112] The target emotion label vector is a text representation of the emotion dimension.
[0113] Because in the dimensional sentiment analysis prediction method, the value of its expression emotion is continuous, therefore, it is necessary to perform regression analysis to further determine the final result. In one embodiment of the present specification, on the output layer of CNN-LSTM, the linear activation function (linear decoder) used is used for regression analysis, rather than using softmax classifier. By using linear decoder, the target emotion label vector is decoded to obtain the target emotion label.
[0114] The text prediction model is verified regularly. In one embodiment of this specification, the text prediction model is verified on the English dataset SST and the Chinese dataset CVAT, and the mean absolute error (MAE) and root mean square error (RMSE) are used to evaluate the effectiveness of the text prediction model to determine whether further training and optimization are needed.
[0115] S2 obtains original text information;
[0116] The original text information may be text content directly obtained from a user input, and the initial level language structure of the text content may be one of a paragraph, a sentence, a clause, a phrase or a word.
[0117] S3 performs data cleaning on the original text information to obtain the text information to be tested;
[0118] In order to improve the efficiency of emotion prediction, in one embodiment of the present specification, considering that the text prediction model of the present specification is mainly used for emotion prediction of Chinese paragraphs, English is not within the scope of emotion prediction of the present specification, and therefore, the English in the original text information is removed; numbers and spaces do not involve the expression of emotions, and in order to improve the subsequent prediction efficiency, the numbers in the original text information are removed; and / or, the spaces in the original text information are removed.
[0119] When performing text prediction, text regions need to be segmented by punctuation. Therefore, to improve segmentation efficiency, data cleaning is performed on the original text information, which also includes: punctuation conversion of the original text information, for example, standardizing the full-width / half-width switching of punctuation. To improve the prediction speed of text sentiment prediction, the original text information can also be converted from simplified Chinese to traditional Chinese.
[0120] After the above data cleaning, the text information to be tested is obtained.
[0121] S4 splits the text information to be tested through a text prediction model to obtain ordered text areas to be tested, performs sentiment prediction on the ordered text areas to be tested, obtains target sentiment labels corresponding to the original text information, and performs sentiment classification on the original text information according to the target sentiment labels.
[0122] S41 splits the text information to be tested according to the text splitting strategy to obtain a plurality of ordered text regions to be tested;
[0123] Specifically, S411 determines all language structures to be tested corresponding to the text information to be tested;
[0124] Identify the initial level language structure of the text information to be tested, and search for all language structures to be tested corresponding to the text information to be tested; sort the language structures to be tested according to their complexity, wherein the language structures to be tested include all language structures with a complexity lower than or equal to that of the initial level language structure.
[0125] That is, based on the initial language structure group, language structures with a complexity no greater than that of the initial-level language structures are selected as the language structures to be tested for the text information, and the language structures to be tested are sorted according to their complexity. In one embodiment of the present specification, the language structures to be tested are sorted in descending order of complexity. The language structure with the highest complexity among the language structures to be tested is designated as the initial-level language structure; the language structure with the lowest complexity among the language structures to be tested is designated as the final-level language structure to be tested.
[0126] Specifically, the language structures in the language structure group are, in descending order of complexity, paragraphs, sentences, clauses, phrases, and words. The final language structure to be tested is a word. If the initial language structure of the text information to be tested is a sentence, the language structures to be tested are, in order, sentences, clauses, phrases, and words. If the initial language structure of the text information to be tested is a paragraph, the language structures to be tested are, in order, paragraphs, sentences, clauses, phrases, and words.
[0127] In one embodiment of the present specification, first, it is determined whether the initial-level language structure is a paragraph or a sentence according to the preset separator. Specifically, if it is identified that the text information to be tested includes two or more preset separators, the initial-level language structure is determined to be a paragraph; if it is identified that the text information to be tested includes one preset separator, the initial-level language structure is determined to be a sentence. The preset separator can be one or more of a period, an exclamation mark, and a question mark. Of course, if it is a paragraph, the number of paragraphs can also be determined based on the paragraph mark. When classifying text, each paragraph is predicted separately to obtain the target emotion label of each paragraph. If the target emotion label of each paragraph in the text information to be tested is the same, only one target emotion label is output. If the target emotion label of each paragraph in the text information to be tested is different, the target emotion labels are output in sequence according to the order of the paragraphs.
[0128] If the text information to be measured is neither a paragraph nor a sentence, then in one embodiment of this specification, the initial-level language structure is distinguished semantically as to whether it is a word, a phrase, or a clause. In another embodiment of this specification, the initial-level language structure is judged according to a preset discrimination rule. Specifically, it is identified whether there are preset symbols in the text information to be measured. If so, it is determined as a clause. If not, it is judged whether there are stop words in the text to be measured. If so, it is determined as a phrase. If not, it is determined as a word. Among them, the stop words include prepositions, conjunctions, adjectives, adverbs, and verbs. The preset symbols include commas and semicolons.
[0129] The text information to be measured is used as the text region to be measured corresponding to the initial-level language structure. That is, the text content group corresponding to the initial-level language structure only includes one text region to be measured.
[0130] It can be understood that the splitting sub-strategy corresponding to a paragraph is: according to the paragraph mark, the text information to be measured is split into several text paragraphs to be measured, and the number of text paragraphs to be measured is the same as the number of paragraph marks.
[0131] The splitting sub-strategy corresponding to a sentence is: according to the full stop in the paragraph, the text paragraph to be measured is split into several text sentences to be measured, and the number of text sentences to be measured is the same as the number of full stops.
[0132] The splitting sub-strategy corresponding to a clause is: remove the full stop of the text sentence to be measured, and split the text sentence to be measured into several text clauses to be measured according to the preset symbols in the text sentence to be measured. The number of text clauses to be measured is the same as the number of preset symbols in the sentence.
[0133] The splitting sub-strategy corresponding to a phrase is: remove the preset symbols of the text clause to be measured, perform word segmentation and词性标注 on the text clause to be measured, and split it according to the type of the text phrase to be measured to obtain the text phrase to be measured. The types of the text phrase to be measured include but are not limited to: subject-predicate phrase, modifier-head phrase, verb-object phrase, complement phrase, coordinate phrase, prepositional-object phrase, "de" phrase.
[0134] The splitting sub-strategy corresponding to a word is: split the text phrase to be measured according to the stop words to obtain the text word to be measured, and each text word to be measured is only one词性.
[0135] S412 Split the text region obtained by splitting at the nth level in turn according to the splitting sub-strategy of the (n + 1)th-level text structure to be measured, and obtain the text content group corresponding to the (n + 1)th-level text structure to be measured. The text content group corresponding to the (n + 1)th-level text structure to be measured includes several ordered text regions to be measured;
[0136] In one embodiment of the present specification, the initial level language structure of the text information to be tested is identified to obtain a text content group to be tested corresponding to the initial level language structure, wherein the text content group to be tested corresponding to the initial level language structure includes a text region to be tested corresponding to the initial level language structure;
[0137] The next level of language structure to be tested after the initial level language structure is used as the current level language structure; wherein the language structures in the language structure group are, in descending order of complexity, paragraph, sentence, clause, phrase, and word. It is understood that the next level of language structure to be tested after the initial level language structure does not include paragraphs, that is, the current level language structure does not include paragraphs.
[0138] Then, the following steps are executed in a loop: the text regions to be tested obtained by the previous level splitting are sequentially split according to the splitting sub-strategy of the current level language structure to obtain a text content group to be tested corresponding to the current level language structure, wherein the text content group to be tested corresponding to the current level language structure includes a plurality of ordered text regions to be tested corresponding to the current level language structure; and the language structure to be tested at the next level of the current level language structure is used as a new current level language structure;
[0139] The loop continues until the final language structure to be tested is reached.
[0140] In one embodiment of the present specification, the text information to be tested is marked according to the initial level language structure, and is first marked as one of a text paragraph to be tested, a text sentence to be tested, a text clause to be tested, a text phrase to be tested, and a text word to be tested.
[0141] Then, according to the splitting sub-strategy corresponding to the current-level language structure each time, the text information to be tested is sequentially split and each text region to be tested is marked.
[0142] In one embodiment of the present specification, if the current-level language structure is a sentence, the test text paragraph is split according to the "sentence-corresponding splitting sub-strategy" to obtain a test text sentence group, wherein the test text sentence group includes a plurality of test text sentences arranged in sequence. The test text sentence group is a test text content group corresponding to the current-level language structure, and the test text sentence is a test text region corresponding to the current-level language structure.
[0143] If the current-level language structure is a clause, the test text sentences are sequentially split according to the "clause-corresponding splitting sub-strategy" to obtain test text clause groups. Each test text sentence corresponds to a test text clause group, and the test text clause group includes a plurality of test text clauses arranged in sequence. The test text clause group is the test text content group corresponding to the current-level language structure, and the test text clause is the test text region corresponding to the current-level language structure.
[0144] If the current-level language structure is a phrase, the test text clauses are sequentially split according to the "Phrase-Corresponding Splitting Sub-Strategy" to obtain test text phrase groups. Each test text clause corresponds to a test text phrase group, and the test text phrase group includes a plurality of test text phrases arranged in sequence. The test text phrase group is the test text content group corresponding to the current-level language structure, and the test text phrase is the test text region corresponding to the current-level language structure.
[0145] If the current-level language structure is a word, the test text phrases are sequentially split according to the "word-corresponding splitting sub-strategy" to obtain test text word groups. Each test text phrase corresponds to a test text word group, and the test text word group includes a plurality of test words arranged in sequence. The test text word group is the test text content group corresponding to the current-level language structure, and the test word is the test text region corresponding to the current-level language structure.
[0146] S413 sorts all the text content groups to be tested according to the sorting logic of all the language structures to be tested to obtain a sentiment classification sequence, where the sentiment classification sequence includes all the text regions to be tested.
[0147] First, the test text regions of the test text content group of the same test language structure are arranged in order, and then the test text content group of the test language structure is sorted according to the size of complexity, and the test text regions are summarized in order to obtain a one-dimensional ordered plurality of test text regions.
[0148] The following combination Figure 2 , further explain S41:
[0149] In one embodiment of the present specification, if the text information to be tested is a paragraph, the initial level language structure of the text information to be tested is identified as a paragraph, and the language structure to be tested includes, in descending order of complexity, paragraphs, sentences, clauses, phrases, and words.
[0150] like Figure 2 As shown, a text content group α to be tested corresponding to the initial level language structure is obtained, and the text content group α to be tested includes a text area A to be tested;
[0151] The next level of language structure to be tested of the initial level language structure is taken as the current level language structure, that is, the "sentence" is taken as the current level language structure, and the text content group β to be tested is obtained according to the "sentence corresponding splitting sub-strategy". The text content group β to be tested includes the text areas to be tested: A1 and A2 in order.
[0152] The next level of the language structure to be tested is taken as the new current level language structure, that is, the "clause" is taken as the new current level language structure, and the text content group γ to be tested is obtained according to the "splitting sub-strategy corresponding to the clause", where A1 is split into A 11 and a 12 , split A2 into A 21 and A 22 ; Then the text areas to be tested included in the text content group γ are: A 11 、A 12 、A 21 and A 22 .
[0153] The next level of the language structure to be tested of the current level language structure is taken as the new current level language structure, that is, the "phrase" is taken as the new current level language structure, and the text content group to be tested is obtained according to the "split sub-strategy corresponding to the phrase", where A 11 Split into a, b; A 12 Split into c; A 21 Split into d and e; A 22 Split into f; the text content group δ includes the text areas to be tested: a, b, c, e and f.
[0154] The next level of language structure to be tested of the current level language structure is taken as the new current level language structure, that is, the "word" is taken as the new current level language structure, and the text content group ε to be tested is obtained according to the "splitting sub-strategy corresponding to the word", where a is split into a1 and a2; b is split into b1, b2, and b3; c is split into c1 and c2; d is split into d1 and d2; e is split into e1; f is split into f1 and f2; the text content group ε to be tested includes the text areas to be tested, in order: a1, a2, b1, b2, b3, c1, c2, d1, d2, e1, f1, and f2.
[0155] According to the sorting logic of the language structure to be tested, the sorting order of the text content groups to be tested is α, β, γ, δ, ε; then the sentiment classification sequence includes: all the ordered text areas to be tested in the text content group α, all the ordered text areas to be tested in the text content group β, all the ordered text areas to be tested in the text content group γ, all the ordered text areas to be tested in the text content group δ, and all the ordered text areas to be tested in the text content group ε, that is, the sentiment classification sequence includes: A, A1, A2, A 11 、A 12 、A 21 、A 22 , a, b, c, e, f, a1, a2, b1, b2, b3, c1, c2, d1, d2, e1, f1, f2.
[0156] S42 performs feature extraction on the text region to be tested to obtain regional sentiment features, wherein the regional sentiment features correspond one-to-one to the text region to be tested;
[0157] According to the order of the text regions to be tested in the emotion classification sequence, the text regions to be tested are extracted in sequence, and the regional emotion features corresponding to the text regions to be tested are determined.
[0158] When determining the regional sentiment features, first identify the words in the text area to be tested, convert the words in the text area to be tested into corresponding word vectors, and construct a sentiment prediction area matrix based on the word vectors. Each text area to be tested corresponds to an sentiment prediction area matrix, and the word vectors corresponding to the words in the text area to be tested are stacked in a regional matrix. Among them, the sentiment prediction area matrix is n×k, n is the number of words in the text area to be tested, and k is the dimension of the word vector. In the sentiment prediction area matrix, each row is the corresponding word vector of a word, and the dimension is k. Each word in the text area to be tested is displayed in sequence vertically, and the display order of each word in the vertical direction is the same as the word order in the text area. In one embodiment of the present specification, the dimension in the sentiment prediction area matrix is the number of non-repeated words in the text area to be tested.
[0159] Secondly, the text region matrix is passed through the convolution sublayer to obtain at least one local sentiment feature of the text region to be tested.
[0160] Then, all local sentiment features of the text area to be tested are filtered through the pooling sublayer. For each text area to be tested, only one local sentiment feature is retained as the regional sentiment feature of the text area to simplify the network calculation complexity.
[0161] By filtering the pooling sublayer, non-important local emotional features can be filtered out, the number of parameters can be simplified, and the computational efficiency can be improved. In one embodiment of the present specification, a maximum pooling sublayer is used for processing, and by eliminating non-maximum values, the calculation of the lower layer is reduced. By extracting the long-range dependencies of different local emotional features, the most important local emotional features are retained as regional emotional features, so that the regional emotional features will be transmitted to the sequence sublayer.
[0162] S43 traverses the corresponding regional sentiment features in sequence according to the order of the text regions to be tested to obtain the target sentiment label.
[0163] At the sequence sublayer, the regional sentiment features of all text regions are sequentially integrated into a text vector. This vector is then fed into an LSTM memory unit. After sequentially traversing the regional sentiment features of all text regions through the LSTM memory unit, a target sentiment label vector is obtained. The target sentiment label vector is a textual representation of the sentiment dimension. A linear decoder is used to decode the target sentiment label vector to obtain a target sentiment label. The target sentiment label vector is a textual representation of the sentiment dimension.
[0164] Figure 3 This is a schematic diagram of the structure of a text-based sentiment classification system provided in an embodiment of this specification, which includes:
[0165] An acquisition module 302 is used to acquire original text information;
[0166] The pre-processing module 303 is used to perform data cleaning on the original text information to obtain the text information to be tested;
[0167] The prediction module 304 is used to split the text information to be tested through a text prediction model to obtain ordered text areas to be tested, perform sentiment prediction on the ordered text areas to be tested, obtain target sentiment labels corresponding to the original text information, and perform sentiment classification on the original text information according to the target sentiment labels.
[0168] Optionally, the pre-processing module 303 includes:
[0169] A first processing submodule, configured to remove English from the original text information;
[0170] A second processing submodule, configured to remove numbers from the original text information;
[0171] A third processing submodule is used to remove spaces from the original text information;
[0172] The fourth processing submodule is configured to convert punctuation marks on the original text information.
[0173] Optionally, the prediction module 304 includes:
[0174] A splitting submodule is used to split the text information to be tested according to the text splitting strategy to obtain a plurality of ordered text regions to be tested;
[0175] A feature extraction submodule is used to extract features from the text region to be tested to obtain regional sentiment features, wherein the regional sentiment features correspond one-to-one to the text region to be tested;
[0176] The prediction submodule is used to traverse the corresponding regional sentiment features in the order of the text regions to be tested to obtain the target sentiment label.
[0177] Optionally, the splitting submodule includes:
[0178] A language structure determination unit, configured to determine all language structures to be tested corresponding to the text information to be tested;
[0179] a splitting unit, configured to sequentially split the text regions to be tested obtained by the n-th level splitting according to the splitting sub-strategy of the n+1-th level language structure to be tested, to obtain a text content group to be tested corresponding to the n+1-th level language structure to be tested, wherein the text content group to be tested corresponding to the n+1-th level language structure to be tested includes a plurality of ordered text regions to be tested;
[0180] The summarizing unit is used to sort all the text content groups to be tested according to the sorting logic of all the language structures to be tested, and obtain a sentiment classification sequence, wherein the sentiment classification sequence includes all the text regions to be tested.
[0181] Optionally, the language structure determination unit includes:
[0182] The sorting subunit is used to identify the initial level language structure of the text information to be tested, search for all the language structures to be tested corresponding to the text information to be tested, and sort the language structures to be tested according to their complexity, wherein the language structures to be tested include all language structures with a complexity lower than that of the initial level language structure.
[0183] Optionally, the feature extraction submodule includes:
[0184] a matrix construction unit, configured to identify words in the text region to be tested, convert the words in the text region to corresponding word vectors, and construct a sentiment prediction region matrix based on the word vectors;
[0185] A feature extraction unit, configured to extract features from the emotion prediction region matrix to obtain at least one local emotion feature;
[0186] The filtering unit is used to filter the local emotional features to obtain the regional emotional features.
[0187] The functions of the system of the embodiment of the present invention have been described in the above method embodiment. Therefore, for details not fully described in this embodiment, please refer to the relevant descriptions in the above embodiment and will not be repeated here.
[0188] Those skilled in the art will appreciate that embodiments of the present invention may be provided as methods, apparatus, or computer program products. Thus, the present invention may take the form of an entirely hardware embodiment, an entirely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, the present invention may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to magnetic disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0189] The present invention is described with reference to flowcharts and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the present invention. It should be understood that each process and / or block in the flowcharts and / or block diagrams, as well as combinations of processes and / or blocks in the flowcharts and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowcharts and / or block diagrams. Figure 1 a process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0190] These computer program instructions may also be stored in a computer readable memory that can direct a computer or other programmable data processing device to work in a specific manner, so that the instructions stored in the computer readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 a process or multiple processes and / or boxes Figure 1 The function specified in one or more boxes.
[0191] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operational steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing the instructions executed on the computer or other programmable device for implementing the process. Figure 1 a process or multiple processes and / or boxes Figure 1 A step that specifies a function in one or more boxes.
[0192] Obviously, those skilled in the art may make various changes and modifications to the present invention without departing from the spirit and scope of the present invention. Thus, if such changes and modifications fall within the scope of the claims and their equivalents, the present invention is intended to include such changes and modifications.
Claims
1. A text-based sentiment classification method, characterized in that: include: Get the original text information; Performing data cleaning on the original text information to obtain text information to be tested; The text information to be tested is split by a text prediction model to obtain ordered text regions to be tested, including: determining all language structures to be tested corresponding to the text information to be tested; The text regions to be tested obtained by the n-th level splitting are sequentially split according to the splitting sub-strategy of the n+1-th level language structure to be tested, to obtain a text content group to be tested corresponding to the n+1-th level language structure to be tested, wherein the text content group to be tested corresponding to the n+1-th level language structure to be tested includes a plurality of ordered text regions to be tested; all the text content groups to be tested are sorted according to the sorting logic of all the language structures to be tested, to obtain a sentiment classification sequence, wherein the sentiment classification sequence includes all the text regions to be tested; and the text prediction model is a regional CNN-LSTM model using a tree structure; Emotion prediction is performed on the ordered text region to be tested to obtain a target emotion label corresponding to the original text information, and emotion classification is performed on the original text information according to the target emotion label.
2. A text-based sentiment classification method as claimed in claim 1, characterized in that: The data cleaning of the original text information includes: Remove the English part of the original text information; and / or, removing numbers from the original text information; and / or, removing spaces from the original text information; And / or, performing punctuation conversion on the original text information.
3. A text-based sentiment classification method as claimed in claim 1, characterized in that: The method of performing sentiment prediction on the ordered text region to be tested to obtain a target sentiment label corresponding to the original text information, and performing sentiment classification on the original text information according to the target sentiment label, includes: Extracting features from the text region to be tested to obtain regional sentiment features, wherein the regional sentiment features correspond one-to-one to the text region to be tested; According to the order of the text regions to be tested, the corresponding regional sentiment features are traversed in turn to obtain the target sentiment label.
4. The text-based sentiment classification method according to claim 1, wherein: The step of determining all language structures to be tested corresponding to the text information to be tested includes: Identify the initial level language structure of the text information to be tested, and search for all language structures to be tested corresponding to the text information to be tested; sort the language structures to be tested according to their complexity, wherein the language structures to be tested include all language structures with a complexity lower than or equal to that of the initial level language structure.
5. The text-based sentiment classification method according to claim 3, wherein: The feature extraction of the text region to be tested to obtain regional sentiment features includes: Identifying words in the text region to be tested, converting the words in the text region to corresponding word vectors, and constructing a sentiment prediction region matrix based on the word vectors; Performing feature extraction on the emotion prediction region matrix to obtain at least one local emotion feature; The local sentiment features are filtered to obtain the regional sentiment features.
6. A text-based sentiment classification system, characterized by: include: Acquisition module, used to obtain original text information; A preprocessing module is used to perform data cleaning on the original text information to obtain the text information to be tested; The prediction module is used to split the text information to be tested by a text prediction model to obtain ordered text regions to be tested, including: determining all language structures to be tested corresponding to the text information to be tested; The text regions to be tested obtained by the n-th level splitting are sequentially split according to the splitting sub-strategy of the n+1-th level language structure to be tested, to obtain a text content group to be tested corresponding to the n+1-th level language structure to be tested, wherein the text content group to be tested corresponding to the n+1-th level language structure to be tested includes a plurality of ordered text regions to be tested; all the text content groups to be tested are sorted according to the sorting logic of all the language structures to be tested, to obtain a sentiment classification sequence, wherein the sentiment classification sequence includes all the text regions to be tested; and the text prediction model is a regional CNN-LSTM model using a tree structure; Emotion prediction is performed on the ordered text region to be tested to obtain a target emotion label corresponding to the original text information, and emotion classification is performed on the original text information according to the target emotion label.
7. An electronic device, wherein: The electronic device includes: processor; and, A memory storing computer executable instructions which, when executed, cause the processor to perform the method according to any one of claims 1 to 5.
8. A computer-readable storage medium, wherein: The computer-readable storage medium stores one or more programs, and when the one or more programs are executed by a processor, the method of any one of claims 1 to 5 is implemented.
Citation Information
Patent Citations
Emotion analysis method based on regional CNN-LSTM
CN108875021A