Sentiment analysis method, device, electronic device and storage medium
The method of extracting word fragments through self-encoding models and preset rules, combined with manual marking of attribute categories, solves the problem of inaccurate sentiment analysis results in the existing technology, achieves accurate sentiment analysis of complex text data, and improves analysis efficiency and accuracy.
Patent Information
- Application Number
- CN202410969141.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-19
- Publication Date
- 2024-10-25
- Estimated Expiration
- 2044-07-19
AI Technical Summary
Existing sentiment analysis methods have semantic understanding bias when faced with complex text data, resulting in inaccurate sentiment analysis results.
The auto-encoding model is used to reason and decode text data, extract word fragments through preset rules and perform clustering processing, combined with manual marking of attribute categories, to retrieve based on fine-grained emotional information to obtain emotional analysis results.
It achieves accurate sentiment analysis of complex text data, improves the accuracy and efficiency of sentiment analysis, and can quickly obtain complete sentiment analysis results, which is suitable for complex text comments and large-scale data insights.
Smart Images

Figure CN118503363B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of natural language processing, and in particular to a sentiment analysis method, device, electronic device and storage medium. Background Art
[0002] Sentiment analysis refers to the automatic analysis and understanding of subjective information in human language, such as emotions, opinions, and sentiments, through computer programs. With the rapid development of the Internet and social media, a large number of consumer feedback and comments on products and services have been widely shared and recorded on various online platforms. These comments are not only huge in number, but also rich in content, covering detailed descriptions of many aspects from product quality and performance to user experience. This information is extremely valuable to companies because it can help them understand consumers' preferences, dissatisfactions, and expectations, thereby making better business decisions.
[0003] Today's sentiment analysis methods are mainly divided into two categories: one is a two-stage method, which first extracts and identifies aspects and opinions, and then analyzes sentiment polarity; the other is a heuristic method based on MRC (reading comprehension), which also first extracts aspects or categories, and generates triple / quadruple information through prompts. However, when faced with complex text data, the existing technical task execution process may have semantic understanding deviations, resulting in inaccurate output sentiment analysis results. Summary of the invention
[0004] In view of this, the present application provides a sentiment analysis method, device, electronic device and storage medium to solve the problem of inaccurate sentiment analysis results in the prior art.
[0005] In a first aspect of the present application, a sentiment analysis method is provided, including: obtaining initial text data, cleaning the initial text data, and obtaining target text data; using a trained autoencoder model to infer the target text data to obtain a two-dimensional sequence data code, decoding the two-dimensional sequence data code, and obtaining fine-grained sentiment information; extracting initial word fragments in the target text data according to preset rules, clustering the initial word fragments to obtain multiple categories of word fragment data, selecting a preset number of the initial word fragments from each category of word fragment data to obtain target word fragments, and marking attribute categories for each target word fragment in response to an operator's operation to obtain data to be searched; retrieving the data to be searched based on the fine-grained sentiment information to obtain target word fragments that match the fine-grained sentiment information, obtaining attribute categories corresponding to the matched target word fragments, attaching corresponding attribute categories to the fine-grained sentiment information, and obtaining sentiment analysis results.
[0006] According to a second aspect of the present application, a sentiment analysis device is provided, comprising: an acquisition module, configured to acquire initial text data, clean the initial text data, and obtain target text data; an encoding module, configured to use a trained autoencoder model to infer the target text data, obtain a two-dimensional sequence data encoding, and decode the two-dimensional sequence data encoding to obtain fine-grained sentiment information; a word fragment processing module, configured to extract initial word fragments from the target text data according to preset rules, cluster the initial word fragments, obtain multiple categories of word fragment data, select a preset number of the initial word fragments from each category of word fragment data, obtain target word fragments, and mark attribute categories for each target word fragment in response to an operator's operation to obtain data to be searched; an analysis module, configured to retrieve the data to be searched based on the fine-grained sentiment information, obtain target word fragments matching the fine-grained sentiment information, obtain attribute categories corresponding to the matched target word fragments, attach corresponding attribute categories to the fine-grained sentiment information, and obtain sentiment analysis results.
[0007] According to a third aspect of the present application, an electronic device is provided, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of the above method when executing the computer program.
[0008] According to a fourth aspect of the present application, a storage medium is provided, which stores a computer program, and when the computer program is executed by a processor, the steps of the above method are implemented.
[0009] At least one of the above technical solutions adopted in this application can achieve the following beneficial effects:
[0010] By obtaining the initial text data, cleaning the initial text data, obtaining the target text data, and then using the trained autoencoder model to infer the target text data, obtaining a two-dimensional sequence code, decoding the two-dimensional sequence code, and obtaining fine-grained sentiment information, the fine-grained sentiment information may include aspect words, evaluation words, and sentiment polarity in the target text data. The target text data can also be extracted from word fragments. First, the initial word fragments are extracted using preset rules, and the initial word fragments are clustered to obtain multi-class word fragment data. The TopN are selected from each class of word fragment data to obtain the target word fragments. Then, the operator can mark the attribute category of each target word fragment to obtain the marked target word fragment. Further, the marked target word fragment can be retrieved based on the fine-grained sentiment information to obtain the attribute category that matches the fine-grained sentiment information, and the corresponding attribute category is attached to the fine-grained sentiment information, so that a complete sentiment analysis and results can be obtained. In this way, the pre-trained autoencoder model can be trained in advance so that it can accurately parse and obtain fine-grained sentiment information. When extracting fine-grained sentiment information, the task is converted into a discontinuous entity recognition method with sequence annotation, and a unified decoding output is performed through a shared encoding layer. The use of a unified end-to-end method can effectively identify invisible sentiment polarity expressions, and decouple general sentiment analysis from the attributes of product objects to facilitate the use of general sentiment analysis and the migration of analysis product objects. In this way, the sentiment data in the target text data can be comprehensively analyzed, and accurate and complete sentiment analysis results can be quickly obtained for application in complex text review feedback and large-scale data insights. BRIEF DESCRIPTION OF THE DRAWINGS
[0011] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0012] Figure 1 It is a flowchart of a sentiment analysis method provided in an embodiment of the present application;
[0013] Figure 2 is an example diagram of a sentiment analysis method provided in an embodiment of the present application;
[0014] Figure 3 It is a flowchart of another sentiment analysis method provided in an embodiment of the present application;
[0015] Figure 4 is a structural schematic diagram of a sentiment analysis device provided in an embodiment of the present application;
[0016] Figure 5 It is a structural schematic diagram of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0017] In the following description, specific details such as specific system structures, technologies, etc. are provided for the purpose of illustration rather than limitation, so as to provide a thorough understanding of the embodiments of the present application. However, it should be clear to those skilled in the art that the present application may also be implemented in other embodiments without these specific details. In other cases, detailed descriptions of well-known systems, devices, circuits, and methods are omitted to prevent unnecessary details from obstructing the description of the present application.
[0018] The terms "first", "second", etc. in the specification and claims of the present application are used to distinguish similar objects, and are not used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable under appropriate circumstances, so that the embodiments of the present application can be implemented in an order other than those illustrated or described here, and the objects distinguished by "first", "second", etc. are generally of one type, and the number of objects is not limited. For example, the first object can be one or more. In addition, "and / or" in the specification and claims represents at least one of the connected objects, and the character " / " generally indicates that the objects associated with each other are in an "or" relationship.
[0019] In addition, it should be noted that the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "includes..." do not exclude the existence of other identical elements in the process, method, article or device including the elements.
[0020] A sentiment analysis method and device according to an embodiment of the present application will be described in detail below with reference to the accompanying drawings.
[0021] Figure 1 is a flow chart of a sentiment analysis method provided in an embodiment of the present application. Figure 1 As shown, the sentiment analysis method includes:
[0022] S101, obtaining initial text data, cleaning the initial text data, and obtaining target text data;
[0023] S102, using the trained autoencoder model to infer the target text data to obtain a two-dimensional sequence data encoding, and decoding the two-dimensional sequence data encoding to obtain fine-grained sentiment information;
[0024] S103, extracting initial word fragments from the target text data according to preset rules, performing clustering processing on the initial word fragments to obtain multiple categories of word fragment data, selecting a preset number of initial word fragments from each category of word fragment data to obtain target word fragments, and marking attribute categories for each target word fragment in response to the operator's operation to obtain data to be searched;
[0025] S104, based on the fine-grained sentiment information, the search data is retrieved to obtain the target word fragments matching the fine-grained sentiment information, the attribute categories corresponding to the matched target word fragments are obtained, the corresponding attribute categories are attached to the fine-grained sentiment information, and the sentiment analysis results are obtained.
[0026] Specifically, initial text data can be extracted from the sentiment analysis scenario. For example, when analyzing user evaluations of a product at the product evaluation center, all comment data can be first extracted from the storage database of the evaluation center as initial text data, and then the initial text data can be cleaned to obtain target text data. The cleaning process can include cleaning emoticons, removing topic tags, deduplicating text, and screening for clustering diversity. The initial text data can also be processed by a text classification model. For example, the text classification model can be used to perform semantic recognition on the initial text, and initial text data that is not related to emotional expression can be deleted. The initial text information can also be stemmed or restored, etc. There is no restriction here. In this way, target text data with sentiment analysis value can be obtained.
[0027] Furthermore, the trained autoencoder model (e.g., autoencoder transformer model) can be used to process the target text data to obtain two-dimensional sequence data encoding and fine-grained sentiment information, extract word fragments from the target text data based on preset rules to obtain initial word fragments, further cluster the target word fragments, and then manually annotate the target word fragments with attribute categories. In different sentiment analysis scenarios, attribute categories can represent attribute categories in the corresponding scenarios. For example, when sentiment analysis is performed on the comment text of commodity sales, its attribute category can represent the attributes of the commodity. For example, the attributes of a mobile phone can include appearance, performance, battery life, screen effect, etc. The specific attribute category can be determined by the operator based on the actual situation. The preset rules can be used to extract word fragments from the target text data, so the setting of the preset rules can fully consider the characteristics of words. For example, a preset length range can be set as the limit of the length of the word fragment, and then after semantic analysis combined with the preset length range, the semantic analysis results within the preset length range are selected as the initial word fragments. The initial word fragments can include the corresponding aspect words and opinion words in the initial text data, and then these initial word fragments can be clustered to obtain target word fragments, and attribute categories are added to the target word fragments. It is also possible to match the target word fragments with the fine-grained sentiment information and attach the attribute categories corresponding to the scene to the fine-grained sentiment information. In this way, in sentiment analysis, through comprehensive word fragment extraction and attribute category labeling, all important attribute categories can be covered as comprehensively as possible, so that a complete sentiment analysis result can be formed.
[0028] As an example, the target text data is obtained from the review data after cleaning: 1. The screen of this mobile phone displays a clear picture and is very responsive. 2. The sound quality of this mobile phone is very good and the sound is clear. 3. This mobile phone is very cost-effective and affordable. After the trained autoencoder model is extracted, the corresponding fine-grained emotional information in the form of triples can be obtained: 1. (aspect: picture, opinion: clear, polarity: pos), 2. (aspect: response, opinion: sensitive, polarity: pos), 3. (aspect: sound quality, opinion: good, polarity: pos), 4. (aspect: cost-effectiveness, opinion: very high, polarity: pos), where aspect can represent aspect words, opinion can represent evaluation of aspect words, polarity can represent the positivity or emotional polarity of evaluation, pos can represent positive evaluation, and if polarity: neg, it can represent negative evaluation.
[0029] Furthermore, the initial word fragments can be extracted: 1. screen, picture, clear, responsive, sensitive, 2. sound quality, very good, clear sound, 3. cost performance, very high cost performance, affordable price. Then the initial word fragments can be clustered to obtain category 1: picture, clear; category 2: responsive, sensitive; category 3: very good sound quality, clear sound; category 4: cost performance, very high cost performance, affordable price. After obtaining these word fragments, the attribute categories of the products can be manually added. For example:
[0030] Category 1: Attribute Category: Display
[0031] Word fragment: picture, clear
[0032] Category 2: Attribute Category: System Fluency
[0033] Word fragments: responsive, sensitive
[0034] Category 3: Attribute Category: Sound Quality
[0035] Word fragment: Very good sound quality, clear voice
[0036] Category 4: Attribute Category: Price
[0037] Word fragments: cost-effective, high cost-effective, affordable
[0038] In this way, we can further search in the target word fragment based on the fine-grained sentiment information and obtain the following sentiment analysis results:
[0039] 1: Attribute category: display screen, aspect word: picture, evaluation word: clear, emotional polarity: positive
[0040] 2: Attribute category: system fluency, aspect word: response, evaluation word: sensitivity, emotional polarity: positive
[0041] 3: Attribute category: sound quality, aspect word: sound, evaluation word: clear, emotional polarity: positive
[0042] 4: Attribute category: price, aspect word: cost performance, evaluation word: high, sentiment polarity: positive
[0043] In this way, we can collect users' evaluations of the phone and intuitively express their emotional tendencies towards different product attributes, which can help researchers explore consumers' real needs and pain points and provide strong data support for new product development and market strategy formulation. When matching fine-grained emotional information with attribute categories, we can ensure that all important product attributes are covered.
[0044] According to the method provided in the above embodiment, by performing sequence annotation on the target text data, predicting sentiment polarity and decoding output, and manually adding attribute categories, accurate and comprehensive sentiment analysis results are obtained. In addition, through comprehensive sentiment analysis, companies can understand users' overall satisfaction with their products, and further help merchants discover users' preferences or dissatisfaction with specific attributes, providing important guidance for product improvement and marketing.
[0045] In some embodiments, before obtaining the initial text data, it also includes: obtaining sample text data, screening the sample text data based on cleaning rules and text classification models to obtain target sample data, the cleaning rules including cleaning emoticons, topic tags, text deduplication and clustering diversity; converting the target sample data into a sample two-dimensional sequence, processing the sample two-dimensional sequence through the encoder of a pre-trained autoencoder model to obtain the sample two-dimensional sequence encoding; processing the sample two-dimensional sequence encoding through the decoder of the pre-trained autoencoder model to obtain the sample fine-grained emotional information; constructing a loss function based on the sample two-dimensional sequence and the sample fine-grained emotional information, and using the loss function to update the parameters of the pre-trained autoencoder model until a trained autoencoder model is obtained.
[0046] Specifically, before performing the sentiment analysis task, an autoencoder model can be constructed and trained to obtain a trained autoencoder model, which can be used to extract fine-grained sentiment information from the target text data. Because the autoencoder model can be used for unsupervised learning, the features and patterns in the text data can be captured by learning the representation of the data, which eliminates the need to explicitly label the training data.
[0047] The specific training process can be: first obtain sample text data, and perform data screening on the sample text data to obtain target sample data with high value, such as adding emoticons and special characters to the sample text data to ensure the consistency and readability of the text; deduplicate the sample text data, that is, identify and remove duplicate comments to eliminate duplicate information and reduce the size of the data set; use a text classification model to classify and screen the sample data, for example, you can train a sentiment analysis model to identify the sentiment polarity in the comments, and then select sample text data with strong positive or negative sentiment as high-value data; you can also use a clustering algorithm to cluster the sample text data, and then select representative sample text in each cluster to ensure data diversity and coverage. It should be understood that the text classification model here can have the same or different functions as the text classification model mentioned above. The text classification model in the model training process can be used to train the initial adaptive model. Therefore, the text classification model can be used to obtain sample text data with obvious sentiment polarity so that the model can more accurately extract the sentiment polarity in the text. When performing sentiment analysis tasks, the focus is on screening out text data with sentiment analysis value in the database, that is, the text classification model can be used to extract text data with sentiment information. Therefore, the text classification models used in model training and task execution may have some differences in data extraction requirements, but they can all be understood as extracting sentiment information. Adaptive adjustments can be made according to actual conditions.
[0048] Then, the high-quality target sample data can be manually labeled and sequenced to convert the target sample data into a sample two-dimensional sequence, which can be represented as a sample two-dimensional token (i.e., phrase) sequence. For example, the target text data: low noise and high cost performance can be labeled to obtain the following: Figure 2 The sample two-dimensional sequence diagram shown in FIG. 1 shows a schematic diagram of a sample two-dimensional sequence, where: TWS can represent the starting position mark of an entity, NNW can represent the middle position mark of an entity, FWD can represent the forward link mark of a discontinuous entity, and RVS can represent the reverse link mark of a discontinuous entity. It should be noted that the introduction of forward and reverse link marks can be used to distinguish aspect and opinion during decoding, that is, the aspect words and evaluation words in the triple can be obtained. For TWS as the starting position mark, it can also represent the category representation of the entity, that is, the sentiment polarity (TWS-neg, TWS-pos), such as: noise >> small, high << cost-effective, so that the entities and their sentiment polarity in the sample text data can be accurately labeled, so that the original fine-grained sentiment information can be captured in the sample two-dimensional sequence, which can be used for the training of the autoencoder model before training.
[0049] Furthermore, the obtained sample two-dimensional sequence can be processed in turn by the decoder and encoder of the pre-trained autoencoder model to obtain the sample fine-grained sentiment information. Then, a loss function can be constructed based on the sample fine-grained sentiment information and the sample two-dimensional sequence to obtain the difference between the sample two-dimensional sequence and the sample fine-grained sentiment information. The pre-trained autoencoder model is parameterized and converged by minimizing the loss function, so that the trained autoencoder model can learn the text representation and sentiment information more accurately. There is no restriction on the loss function here.
[0050] According to the method provided in the above embodiment, by introducing special link token characters and treating the relationship of triples as a discontinuous entity type, the fine-grained sentiment analysis task can be converted into a discontinuous entity recognition task, thereby reducing the difficulty of the task. In addition, unifying the encoding layer and the relationship recognition layer can reduce the differences in the form of the traditional pipeline (i.e., the data processing flow), accelerate the convergence of the pre-training autoencoder model, and improve the efficiency of the model. This not only simplifies the autoencoder model architecture, but also can better capture the sentiment relationship between entities in text data, thereby improving the accuracy and efficiency of the sentiment analysis task.
[0051] In some embodiments, the target sample data is converted into a sample two-dimensional sequence, including: in response to manual labeling, entity marking of the target sample data to obtain a sample two-dimensional sequence, the entity marking including a starting position mark of the entity, a middle position mark of the entity, a forward link mark of a discontinuous entity, and a reverse link mark of a discontinuous entity.
[0052] Specifically, the target sample data may be manually labeled: the entity labels may include the entity's starting position label, the entity's middle position label, the discontinuous entity's forward link label, and the discontinuous entity's reverse link label.
[0053] In this way, the target sample data can be converted into a two-dimensional sequence, which can capture the location of entities in the text and the link relationship between them, providing useful information for subsequent pre-training autoencoder model processing.
[0054] It should be noted that the position and link relationship of entities can also be learned during the unsupervised learning process of the autoencoder model before training. After the trained autoencoder model is obtained, there is no need for manual labeling. The autoencoder model can directly generate corresponding entity tags for the input target text data during the reconstruction process and automatically convert the target text data into entity tags in a two-dimensional sequence. Of course, the autoencoder model before training does not need to learn the corresponding entity position and link relationship. Then, when the trained autoencoder model performs the task, it can identify the entity and link relationship through manual labeling or other steps. There is no restriction here, which is determined according to specific needs and the architecture setting of the autoencoder model.
[0055] According to the method provided in the above embodiment, by entity marking the target sample data, the commodity objects and sentiment information can be classified and marked in scenarios such as evaluation data analysis, so that the autoencoder model can better understand the entity information and sentiment information in the target text data, thereby achieving the decoupling of sentiment analysis from commodity object attributes. This decoupling can make the sentiment analysis model system more easily applied to different commodity objects without the need for retraining for each commodity or different fields, thereby achieving the reusability of the sentiment analysis model and the portability of commodity object analysis, which can be reflected in the embodiment of the present application that the autoencoder model can be applied to multiple commodities or multiple fields.
[0056] In other embodiments, the loss function is used to update the parameters of the pre-trained autoencoder model, including: calculating the gradient of the loss function with respect to the pre-trained autoencoder model parameters through a back-propagation algorithm, and updating the pre-trained autoencoder model parameters using an optimization algorithm until a trained autoencoder model is obtained.
[0057] Specifically, when training the pre-trained autoencoder model, the gradient of the loss function to the pre-trained autoencoder model parameters can be calculated by the back-propagation algorithm, and the parameters of the pre-trained autoencoder model can be updated according to the calculated gradient using an optimization algorithm (such as stochastic gradient descent, Adam, etc.). In this way, the calculation of model parameter updates is repeated until the loss function converges to obtain a trained autoencoder model. The loss function is intended to calculate the difference between the input and output of the initial autoencoder model. The mean square error and the binary cross entropy can be used as the loss function, but this is not limited here. It should be noted that in order to improve the generalization ability of the model or enhance the sparsity of the features during model training, a regularization term can be added to the loss function, which is of course not limited here.
[0058] According to the method provided in the above embodiment, the parameters of the autoencoder model before training can be gradually optimized so that it can better learn the representation and sentiment information of the target sample data, thereby enabling the trained autoencoder model to obtain an accurate and complete sentiment analysis result.
[0059] In some embodiments, the target text data is inferred using a trained autoencoder model to obtain a two-dimensional sequence data encoding, and the two-dimensional sequence data encoding is decoded to obtain fine-grained sentiment information, including: using the trained autoencoder model to infer the target text data to obtain the fine-grained sentiment information in the form of triples; if the trained autoencoder model does not recognize the existence of entities in the target text data, then extracting the fine-grained sentiment information in the form of sentiment description fragments.
[0060] Specifically, when using the trained autoencoder model to perform sentiment analysis tasks, the output fine-grained sentiment information can be expressed in the form of triples or sentiment description fragments, which is determined based on the specific text expression. When the text expression has a clear aspect and opinion, the word elements can be directly extracted to obtain clear triples. When there is no clear aspect and opinion, that is, there is no clear entity, but there is sentiment information expression, the sentiment description fragment can be directly extracted. During the model training process, a large amount of various data can be used for training so that it can accurately extract triples or sentiment description fragments. The details are not elaborated here.
[0061] As an example, review 1: This dress is made of very good material. Review 2: This dress has a soft, silky luster and smooth feel like clouds. In this way, we can extract an accurate triple for review 1: (aspect: material, opinion: good, polarity: pos), and for review 2, we cannot extract clear aspect words and evaluation words, so we can directly extract the emotional description fragment: cloud-like softness. We can further perform semantic processing on it to know that it represents the product aspect of the dress, and its emotional polarity is positive. This can also be further processed to obtain a complete emotional analysis result.
[0062] According to the method provided in the above embodiment, by judging whether there is an entity in the target text data, the form of output of fine-grained sentiment information can be flexibly adjusted to facilitate subsequent acquisition of complete sentiment analysis results.
[0063] In some embodiments, extracting the initial word fragments from the target text data using preset rules includes: segmenting the target text data based on punctuation marks to obtain segmentation results; extracting segmentation results whose lengths are within a preset range from the segmentation results to obtain initial word fragments.
[0064] Specifically, the preset rules can be understood as using punctuation marks to divide the target text data into segments. Of course, in the actual model design, other rules can be added to segment the target text data, such as based on grammatical structure, part-of-speech tagging, professional terminology dictionary, word frequency, etc. Specifically, by using grammatical structure information, the text can be divided into segments based on noun phrases, verb phrases, etc. to extract meaningful word units. By using part-of-speech tagging, specific categories of word units can be extracted as segments based on nouns, verbs, adjectives, etc. The use of professional terminology dictionaries means that in the sentiment analysis tasks in specialized fields, the dictionary data or term list of specialized fields can be learned, and then professional terminology vocabulary can be extracted as word units. The use of word frequency means that vocabulary can be selected according to the frequency of occurrence to extract representative word units. This can avoid the situation where the extracted word units are invalid due to different expression habits and model recognition errors. No specific restrictions are made here.
[0065] After the target text data is segmented into segments, the segmentation results may be selected according to a preset range, for example, a segment with a length of 2 to 20 characters may be used as an initial word segment.
[0066] According to the method provided in the above embodiment, the target text data can be segmented by punctuation segmentation, and the segmentation results with a length within a preset range can be selected from the segmentation results to obtain initial word fragments. This can simplify the complexity of the target text data and extract the most refined sentiment segmentation information, making it easier for the model to process and analyze these initial word fragments.
[0067] In some embodiments, the data to be searched is retrieved based on the fine-grained sentiment information to obtain target word fragments that match the fine-grained sentiment information, including: based on the fine-grained sentiment information, using semantic retrieval to retrieve from the data to be searched to obtain matching target word fragments.
[0068] Specifically, semantic search technology can be used to retrieve fine-grained sentiment information, and target word fragments matching the fine-grained sentiment information can be obtained through semantic similarity.
[0069] The target word fragments can be matched by searching, and then the attribute categories can be mapped. This can solve the problem that the product attribute categories are large and changeable, and can achieve real-time data updates to better adapt to the changing product categories.
[0070] According to the method provided in the above embodiment, semantic search can be used to retrieve from the data to be searched to obtain matching target word fragments, which can further associate fine-grained sentiment information with product attributes to better understand consumers' sentiment tendencies and product characteristics.
[0071] Figure 3This is a flow chart of another sentiment analysis method provided in the embodiment of the present application. Figure 3 The embodiments of the present application are further described.
[0072] The embodiment of the present application can design four process sections. First, the model is built, then the model is trained, and then the trained model is used to perform sentiment analysis reasoning, and the fine-grained sentiment information obtained by reasoning is supplemented with attributes, so that a complete fine-grained analysis result, that is, a sentiment analysis result, can be obtained.
[0073] In terms of model architecture, we can first obtain the shape (B, S) in the text sequence (i.e., the two-dimensional sequence in the previous article), where B can represent the batch size and S can represent the sequence length. Then, the text sequence is converted into an embedding vector with an embedding dimension of H (i.e., the embedding step). This process can be achieved by mapping the words or characters in the text to a continuous vector space so that the subsequent model can better understand the text content. Then, the text embedding can be used for feature extraction and expression learning through the BERT model (i.e., transformer encoder), and the sequence relationship between tokens can be further strengthened through the Long Short-Term Memory (LSTM) model to learn the semantic representation in the text. Tokens can represent the basic units of text, which can be words, subwords, or characters, etc., which can be understood as the extraction process of word fragments in the previous article.
[0074] Furthermore, TokenPairEmbedding can represent a technical method used in natural language processing to capture semantic associations and emotional expressions between different tokens, and predictor can represent features used to predict target variables, such as aspect words and corresponding evaluations corresponding to attribute categories in the embodiment, which are used to further construct an adaptive model.
[0075] Therefore, the relationship between different tokens can be processed through TokenPairEmbedding (B, S, S, H), and different words can be embedded to capture the semantic association and emotional expression between words. For example, in high, cost-effective, and long, it can be recognized that high is associated with cost-effective. Further, the predictor (B, S, S, L) performs label category prediction to obtain the category of tokenpair tags. Tokenpair can represent a pair of two adjacent tokens, such as TWS, NNW, FWD, RVS in the previous article. After obtaining the tokenpair tag, the decoder can be used to decode the output to obtain the prediction structure of sentiment analysis and sentiment polarity.
[0076] Furthermore, after the model architecture is built, model training can be performed. First, a data set is obtained and data feature engineering is performed on the data set, that is, the sample text data is obtained and cleaned as described above to obtain the target sample data, and then it is manually labeled as the sequence token received by the model, that is, the sample two-dimensional sequence, and the model is further trained until the model converges to obtain a transfer model, that is, a trained autoencoder model, which will not be expanded here.
[0077] Furthermore, the trained model can be used for sentiment analysis reasoning. Large-scale data to be understood can be cleaned and reasoned using the trained autoencoder model to obtain two-dimensional token sequence encoded data. Further decoding can obtain fine-grained sentiment information.
[0078] Finally, the obtained fine-grained sentiment information is retrieved from the data to be searched that has been previously segmented, clustered, screened, and annotated with attribute categories, and the corresponding attribute categories are added to the fine-grained sentiment information, so that a complete fine-grained analysis result, namely the sentiment analysis result, can be obtained.
[0079] In this way, end-to-end, efficient, large-scale fine-grained text sentiment analysis can be achieved. Decoupling fine-grained general sentiment analysis and the unique label category of the product can achieve low-cost product object migration and convert the fine-grained sentiment analysis task into a discontinuous entity recognition task based on the tokenpair method. The aspect, opinion and sentiment polarity are decoded and output end-to-end, the semantic encoding layer is shared, the semantic deviation is reduced, and the autoencoding model is adopted to improve the reasoning efficiency of the sentiment analysis system.
[0080] By using the method of the embodiment of the present application, fine-grained sentiment analysis can be performed in multiple fields to solve the pain points in the corresponding fields.
[0081] For example, on e-commerce platforms: fine-grained sentiment analysis can be performed on product reviews left by users on the e-commerce platform to understand consumers' detailed views and feelings about each product, thereby optimizing the product recommendation system and improving user satisfaction.
[0082] In the field of social media monitoring: Based on user-generated content (UGC) data on social media, through fine-grained sentiment analysis of this data, companies can understand the public's views on their brands, products or services in real time, and promptly detect and handle potential public relations crises.
[0083] In market research: In market research, fine-grained sentiment analysis can help researchers deeply explore consumers' real needs and pain points, and provide strong data support for new product development and market strategy formulation.
[0084] In terms of customer service: By performing fine-grained sentiment analysis on customer feedback and complaints, companies can more accurately identify customer satisfaction and dissatisfaction, thereby improving products and services in a targeted manner and increasing customer satisfaction.
[0085] All the above optional technical solutions can be arbitrarily combined to form optional embodiments of the present application, which will not be described one by one here.
[0086] The following is an embodiment of the device of the present application, which can be used to execute the embodiment of the method of the present application. For details not disclosed in the embodiment of the device of the present application, please refer to the embodiment of the method of the present application.
[0087] Figure 4 Schematic diagram of a sentiment analysis device provided in an embodiment of the present application. Figure 4 As shown, the sentiment analysis device includes:
[0088] The acquisition module 401 is configured to acquire initial text data, clean the initial text data, and obtain target text data;
[0089] The encoding module 402 is configured to use the trained autoencoder model to infer the target text data to obtain the two-dimensional sequence data encoding, and decode the two-dimensional sequence data encoding to obtain fine-grained sentiment information;
[0090] The word fragment processing module 403 is configured to extract initial word fragments from the target text data according to preset rules, perform clustering processing on the initial word fragments to obtain multiple categories of word fragment data, select a preset number of the initial word fragments from each category of word fragment data to obtain target word fragments, and mark attribute categories for each target word fragment in response to the operator's operation to obtain data to be searched;
[0091] The analysis module 404 is configured to retrieve the search data based on the fine-grained sentiment information, obtain the target word fragments matching the fine-grained sentiment information, obtain the attribute categories corresponding to the matching target word fragments, attach the corresponding attribute categories to the fine-grained sentiment information, and obtain the sentiment analysis results.
[0092] In some embodiments, the acquisition module 401 is specifically used to obtain sample text data, screen the sample text data based on cleaning rules and text classification models to obtain target sample data, the cleaning rules including cleaning emoticons, topic tags, text deduplication and clustering diversity; convert the target sample data into a sample two-dimensional sequence, process the sample two-dimensional sequence through the encoder of a pre-trained autoencoder model to obtain the sample two-dimensional sequence encoding; process the sample two-dimensional sequence encoding through the decoder of the pre-trained autoencoder model to obtain the sample fine-grained emotional information; construct a loss function based on the sample two-dimensional sequence and the sample fine-grained emotional information, and use the loss function to update the parameters of the pre-trained autoencoder model until a trained autoencoder model is obtained.
[0093] In some embodiments, the acquisition module 401 is specifically used to perform entity marking on the target sample data in response to manual labeling to obtain the sample two-dimensional sequence, and the entity marking includes the starting position mark of the entity, the middle position mark of the entity, the forward link mark of the discontinuous entity, and the reverse link mark of the discontinuous entity.
[0094] In some embodiments, the acquisition module 401 is specifically used to calculate the gradient of the loss function to the pre-trained autoencoder model parameters through the back propagation algorithm, and update the pre-trained autoencoder model parameters using the optimization algorithm until a trained autoencoder model is obtained.
[0095] In some embodiments, the encoding module 402 is specifically used to use the trained autoencoder model to infer the target text data to obtain the fine-grained sentiment information in the form of triples; if the trained autoencoder model does not recognize the existence of entities in the target text data, the fine-grained sentiment information in the form of sentiment description fragments is extracted.
[0096] In some embodiments, the word fragment processing module 403 is specifically used to segment the target text data based on punctuation marks to obtain segmentation results; extract the segmentation results whose lengths are within a preset range from the segmentation results to obtain initial word fragments.
[0097] In some embodiments, the analysis module 404 is specifically used to retrieve from the data to be searched based on fine-grained sentiment information using semantic retrieval to obtain matching target word fragments.
[0098] It should be understood that the size of the serial numbers of the steps in the above embodiments does not mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present application.
[0099] Figure 5 Schematic diagram of an electronic device 5 provided in an embodiment of the present application. Figure 5As shown, the electronic device 5 of this embodiment includes: a processor 501, a memory 502, and a computer program 503 stored in the memory 502 and executable on the processor 501. When the processor 501 executes the computer program 503, the steps in the above-mentioned method embodiments are implemented. Alternatively, when the processor 501 executes the computer program 503, the functions of the modules / units in the above-mentioned device embodiments are implemented.
[0100] The electronic device 5 may be a desktop computer, a notebook, a PDA, a cloud server, or other electronic device. The electronic device 5 may include, but is not limited to, a processor 501 and a memory 502. Those skilled in the art will appreciate that Figure 5 The electronic device 5 is merely an example and does not limit the electronic device 5 , and may include more or less components than those shown in the figure, or different components.
[0101] The processor 501 may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc.
[0102] The memory 502 may be an internal storage unit of the electronic device 5, for example, a hard disk or memory of the electronic device 5. The memory 502 may also be an external storage device of the electronic device 5, for example, a plug-in hard disk, a smart media card (SMC), a secure digital (SD) card, a flash card, etc. equipped on the electronic device 5. The memory 502 may also include both an internal storage unit of the electronic device 5 and an external storage device. The memory 502 is used to store computer programs and other programs and data required by the electronic device.
[0103] Those skilled in the art can clearly understand that for the convenience and simplicity of description, only the division of the above-mentioned functional units and modules is used as an example. In actual applications, the above-mentioned functions can be assigned to different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above. The functional units and modules in the embodiments can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The above-mentioned integrated unit can be implemented in the form of hardware or in the form of software functional units.
[0104] If the integrated module / unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a storage medium. Based on this understanding, the present application implements all or part of the processes in the above-mentioned embodiment method, and can also be completed by instructing the relevant hardware through a computer program. The computer program can be stored in a storage medium, and the computer program can implement the steps of the above-mentioned various method embodiments when executed by the processor. The computer program may include computer program code, which may be in source code form, object code form, executable file or some intermediate form. Computer-readable media may include: any entity or device capable of carrying computer program code, recording medium, U disk, mobile hard disk, disk, optical disk, computer memory, read-only memory (ROM), random access memory (RAM), electrical carrier signal, telecommunication signal and software distribution medium, etc.
[0105] The above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit them. Although the present application has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. These modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present application, and should all be included in the protection scope of the present application.
Claims
1. A sentiment analysis method, characterized in that: include: Acquire initial text data, clean the initial text data, and obtain target text data; The target text data is inferred by using a trained autoencoder model to obtain a two-dimensional sequence data encoding, and the two-dimensional sequence data encoding is decoded to obtain fine-grained sentiment information, wherein the trained autoencoder model is trained on the target sample data according to the pre-trained autoencoder model, wherein the training process includes: in response to manual labeling, the target sample data is entity labeled to obtain a sample two-dimensional sequence, wherein the entity label includes an entity start position label, an entity middle position label, a discontinuous entity forward link label, and a discontinuous entity reverse link label; Extracting initial word fragments from the target text data according to preset rules, clustering the initial word fragments to obtain multiple categories of word fragment data, selecting a preset number of the initial word fragments from each category of word fragment data to obtain target word fragments, and marking attribute categories for each target word fragment in response to an operator's operation to obtain data to be searched; Based on the fine-grained sentiment information, semantic retrieval is used to retrieve from the data to be searched, and target word fragments matching the fine-grained sentiment information are obtained, and attribute categories corresponding to the matched target word fragments are obtained, and the corresponding attribute categories are attached to the fine-grained sentiment information to obtain sentiment analysis results.
2. The method according to claim 1, characterized in that Before obtaining the initial text data, the method further includes: Acquire sample text data, and screen the sample text data based on cleaning rules and a text classification model to obtain target sample data, wherein the cleaning rules include cleaning emoticons, topic tags, text deduplication, and clustering diversity; Converting the target sample data into a sample two-dimensional sequence, and processing the sample two-dimensional sequence through an encoder of a pre-trained autoencoder model to obtain a sample two-dimensional sequence encoding; Processing the sample two-dimensional sequence encoding through the decoder of the pre-trained autoencoder model to obtain sample fine-grained emotional information; A loss function is constructed based on the sample two-dimensional sequence and the sample fine-grained emotional information, and the loss function is used to update the parameters of the pre-trained autoencoder model until the trained autoencoder model is obtained.
3. The method according to claim 2, characterized in that The using the loss function to update the parameters of the pre-trained autoencoder model until the trained autoencoder model is obtained includes: The gradient of the loss function to the parameters of the pre-trained autoencoder model is calculated by a back-propagation algorithm, and the parameters of the pre-trained autoencoder model are updated by an optimization algorithm until the trained autoencoder model is obtained.
4. The method according to claim 1, characterized in that: The method of using the trained autoencoder model to infer the target text data to obtain a two-dimensional sequence data encoding, and decoding the two-dimensional sequence data encoding to obtain fine-grained sentiment information includes: Using the trained autoencoder model to infer the target text data to obtain the fine-grained sentiment information in the form of triples; If the trained autoencoder model does not recognize the existence of entities in the target text data, the fine-grained sentiment information in the form of sentiment description fragments is extracted.
5. The method according to claim 1, characterized in that The extracting the initial word fragments in the target text data according to the preset rules includes: Segmenting the target text data based on punctuation marks to obtain segmentation results; The segmentation results whose lengths are within a preset range are extracted from the segmentation results to obtain the initial word fragments.
6. A sentiment analysis device, characterized in that: include: An acquisition module is configured to acquire initial text data, clean the initial text data, and obtain target text data; The encoding module is configured to use the trained autoencoder model to infer the target text data to obtain a two-dimensional sequence data encoding, decode the two-dimensional sequence data encoding, and obtain fine-grained sentiment information, wherein the trained autoencoder model is obtained by training the target sample data according to the pre-trained autoencoder model, wherein the training process includes: in response to manual labeling, entity labeling the target sample data to obtain a sample two-dimensional sequence, wherein the entity labeling includes an entity start position label, an entity middle position label, a discontinuous entity forward link label, and a discontinuous entity reverse link label; a word fragment processing module, configured to extract initial word fragments from the target text data according to preset rules, perform clustering processing on the initial word fragments to obtain multiple categories of word fragment data, select a preset number of the initial word fragments from each category of word fragment data to obtain target word fragments, and mark attribute categories for each target word fragment in response to an operator's operation to obtain data to be searched; The analysis module is configured to use semantic retrieval based on the fine-grained sentiment information to search from the data to be searched, obtain target word fragments that match the fine-grained sentiment information, obtain attribute categories corresponding to the matched target word fragments, attach the corresponding attribute categories to the fine-grained sentiment information, and obtain sentiment analysis results.
7. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 5 are implemented.
8. A storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 5 are implemented.
Citation Information
Patent Citations
Fine-grained emotion analysis method and device, computer equipment and storage medium
CN110516245A
Automobile comment text viewpoint mining method and device and storage medium
CN112836052A
Image sentiment analysis method based on sentiment attribute mining
CN114201960A
Statement sentiment analysis method and device, equipment and storage medium
CN115358238A
Multi-task extraction method and device based on extraction model
CN115481617A
