Sentiment analysis method and device, storage medium and electronic device
By constructing an emotion analysis model, obtaining and processing the characteristics of emotional sentences and their contextual sentences, the existing problem of low accuracy of emotion analysis is solved, and higher emotion analysis accuracy is achieved.
Patent Information
- Application Number
- CN202111362624.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-11-17
- Publication Date
- 2025-08-19
- Estimated Expiration
- 2041-11-17
AI Technical Summary
In the existing emotion analysis methods, the accuracy of emotional sentences is low and the emotional characteristics of the contextual sentences of emotional sentences are not effectively utilized.
By constructing an emotion analysis model, the emotional sentences and their contextual sentences in the comment text are obtained, word segmentation is performed, and the word embedding model, encoding model and fusion model are used to perform emotion analysis on words and contextual sentences, and the classification results of emotional sentences are determined based on the emotion classification model.
The accuracy of emotion analysis is improved, and the accuracy of emotion analysis is enhanced by considering the characteristics of emotional sentences and their contextual sentences.
Smart Images

Figure CN114036299B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of natural language processing technology, and in particular to a sentiment analysis method and device, a storage medium, and an electronic device. Background Art
[0002] With the rapid popularization of online media, a large amount of text information containing subjective comments is rapidly spreading. Analyzing netizens' emotions through emotional sentences in comment texts is of great significance in helping to grasp the real public opinion situation and for scientific and effective public opinion guidance work.
[0003] In the prior art, sentiment analysis involves analyzing the sentiment of emotional sentences using a CNN (Convolutional Neural Network) model or an RNN (Recurrent Neural Network) model. However, the accuracy of existing sentiment analysis methods is relatively poor. Summary of the Invention
[0004] During the research process, the inventor discovered that in addition to the emotional features contained in the emotional sentences themselves, the context sentences of the emotional sentences also contain emotional features, and the emotional features contained in the context sentences will affect the accuracy of the emotional analysis results of the emotional sentences. Based on this, the present application provides a sentiment analysis method and device, storage medium and electronic device, aiming to solve the problem of low accuracy of existing sentiment analysis.
[0005] In order to achieve the above objectives, this application provides the following technical solutions:
[0006] A sentiment analysis method, comprising:
[0007] Obtaining a comment text; the comment text includes at least one sentence;
[0008] Determining the emotional sentences in each sentence included in the review text, and determining the context sentences of each emotional sentence;
[0009] Perform word segmentation on each sentiment sentence to obtain multiple words corresponding to each sentiment sentence, and perform word segmentation on the context sentences of each sentiment sentence to obtain multiple words corresponding to each context sentence;
[0010] For each emotional sentence, a pre-built sentiment analysis model is used to perform sentiment analysis on each word corresponding to the emotional sentence and each word corresponding to the context sentence of the emotional sentence to obtain a sentiment classification result of the emotional sentence.
[0011] In the above method, optionally, the sentiment analysis model includes a word embedding model, a first encoding model, a second encoding model, a fusion model, and a sentiment classification model. The pre-built sentiment analysis model is used to perform sentiment analysis on each word corresponding to the sentiment sentence and each word corresponding to the context sentence of the sentiment sentence to obtain the sentiment classification result of the sentiment sentence, including:
[0012] Using the word embedding model, each word corresponding to the sentiment sentence and each word corresponding to the context sentence of the sentiment sentence are embedded and represented to obtain a sentiment sentence vector of the sentiment sentence and a context sentence vector of the context sentence;
[0013] Using the first encoding model, encoding the emotional sentence vector to obtain a bidirectional temporal feature of the emotional sentence;
[0014] Using the second encoding model, encoding the context sentence vector to obtain important emotional features of the context sentence of the emotional sentence;
[0015] Using the fusion model, the bidirectional temporal features of the emotional sentence and the important emotional features of the context sentences of the emotional sentence are fused to obtain the fused features of the emotional sentence, and the target features of the emotional sentence are determined from the bidirectional temporal features of the emotional sentence, the important emotional features of the context sentences of the emotional sentence, and the fused features;
[0016] The target features of the emotional sentence are input into the emotional classification model to obtain the emotional sentence classification result.
[0017] Optionally, the method described above includes encoding the emotional sentence vector using the first encoding model to obtain the bidirectional temporal features of the emotional sentence, including:
[0018] Using the GCNN encoding layer in the first encoding model, encoding the emotional sentence vector to obtain the encoding vector of the emotional sentence;
[0019] The encoding vector of the emotional sentence is encoded using the bidirectional gated recurrent unit (BIGRU) encoding layer in the first encoding model to obtain bidirectional temporal features of the emotional sentence.
[0020] In the above method, optionally, the second encoding model is used to encode the context sentence vector to obtain the important emotional features of the context sentence of the emotional sentence, including:
[0021] Using the BIGRU encoding layer in the second encoding model to encode the context sentence vector to obtain bidirectional semantic features of the context sentence of the sentiment sentence;
[0022] The attention mechanism layer in the second encoding model is used to assign weight values to the bidirectional semantic features, and based on the assigned weight values and the bidirectional semantic features, the important sentiment features of the context sentences of the sentiment sentence are obtained.
[0023] Optionally, the above method uses the fusion model to fuse the bidirectional temporal features of the emotional sentence and the important emotional features of the context of the emotional sentence to obtain the fusion features of the emotional sentence, including:
[0024] The fusion model is used to fuse the bidirectional temporal features of the emotional sentence and the important emotional features of the context sentences of the emotional sentence through an element-by-element multiplication algorithm to obtain the fusion features of the emotional sentence.
[0025] In the above method, optionally, determining the emotional sentences in each sentence included in the comment text includes:
[0026] Parsing each sentence included in the review text to determine sentences in the review text that contain sentiment words;
[0027] Sentences containing sentiment words in the comment text are determined as sentiment sentences.
[0028] In the above method, optionally, determining the context sentence of each sentiment sentence includes:
[0029] For each emotional sentence, the previous sentence of the emotional sentence and the next sentence of the emotional sentence in the comment text are determined as context sentences of the emotional sentence.
[0030] A sentiment analysis device, comprising:
[0031] A first acquiring unit is configured to acquire a comment text; the comment text includes at least one sentence;
[0032] a determining unit, configured to determine an emotional sentence in each sentence included in the comment text, and to determine a context sentence for each emotional sentence;
[0033] The second acquisition unit is used to perform word segmentation processing on each emotional sentence to obtain multiple words corresponding to each emotional sentence, and to perform word segmentation processing on the context sentences of each emotional sentence to obtain multiple words corresponding to each context sentence;
[0034] The third acquisition unit is used to perform sentiment analysis on each emotional sentence using a pre-built sentiment analysis model on each word corresponding to the emotional sentence and each word corresponding to the context sentence of the emotional sentence to obtain a sentiment classification result of the emotional sentence.
[0035] A storage medium stores an instruction set, wherein the instruction set, when executed by a processor, implements the sentiment analysis method as described above.
[0036] An electronic device, comprising:
[0037] A memory for storing at least one set of instructions;
[0038] A processor is used to execute the instruction set stored in the memory, and implement the sentiment analysis method as described above by executing the instruction set.
[0039] Compared with the prior art, this application has the following advantages:
[0040] The present application provides a sentiment analysis method and device, storage medium and electronic device, which obtains a comment text, determines the sentiment sentences in each sentence included in the comment text, and determines the context sentences of each sentiment sentence, performs word segmentation processing on each sentiment sentence to obtain multiple words corresponding to each sentiment sentence, and performs word segmentation processing on the context sentences of each sentiment sentence to obtain multiple words corresponding to each context sentence, and for each sentiment sentence, uses a pre-built sentiment analysis model to perform sentiment analysis on each word corresponding to the sentiment sentence and each word corresponding to the context sentences of the sentiment sentence to obtain the sentiment classification result of the sentiment sentence. It can be seen that the present application scheme pre-builds a sentiment analysis model, and based on the sentiment sentence and the context features of the sentiment sentence, determines the sentiment classification result of the sentiment sentence through the sentiment analysis model, thereby improving the accuracy of sentiment analysis. BRIEF DESCRIPTION OF THE DRAWINGS
[0041] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are merely embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on the provided drawings without any creative work.
[0042] Figure 1 A flow chart of a sentiment analysis method provided in this application;
[0043] Figure 2 Another method flow chart of a sentiment analysis method provided in this application;
[0044] Figure 3 An example diagram of a sentiment analysis method provided for this application;
[0045] Figure 4 A flowchart of another method for sentiment analysis provided in this application;
[0046] Figure 5 A schematic diagram of the structure of a GCNN encoding layer provided in this application;
[0047] Figure 6 Another method flow chart of a sentiment analysis method provided in this application;
[0048] Figure 7 Another example diagram of a sentiment analysis method provided by this application;
[0049] Figure 8 A schematic diagram of the structure of a sentiment analysis device provided in this application;
[0050] Figure 9 This is a schematic diagram of the structure of an electronic device provided in this application. DETAILED DESCRIPTION
[0051] The following will be combined with the drawings in the embodiments of this application to clearly and completely describe the technical solutions in the embodiments of this application. Obviously, the embodiments described are only part of the embodiments of this application, not all of the embodiments. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of this application.
[0052] As used herein, the term "including" and its variations are open-ended, i.e., "including but not limited to." The term "based on" means "based, at least in part, on." The term "one embodiment" means "at least one embodiment," the term "another embodiment" means "at least one additional embodiment," and the term "some embodiments" means "at least some embodiments." Other terms are defined in the following description.
[0053] It should be noted that the concepts of "first" and "second" mentioned in the present application are only used to distinguish different devices, modules or units, and are not used to limit the order or interdependence of the functions performed by these devices, modules or units.
[0054] It should be noted that the modifications of "one" and "multiple" mentioned in the disclosure of this application are illustrative rather than restrictive. Those skilled in the art should understand that unless otherwise clearly indicated in the context, they should be understood as "one or more".
[0055] The present application can be used in a variety of general or special computing device environments or configurations, such as personal computers, server computers, handheld or portable devices, tablet devices, multi-processor devices, and distributed computing environments including any of the above devices or devices.
[0056] The embodiment of the present application provides a sentiment analysis method, which can be applied to a variety of system platforms. The execution subject can be a processor running on a computer terminal or various mobile devices. The flowchart of the sentiment analysis method is as follows: Figure 1 As shown, specifically including:
[0057] S101. Obtain comment text.
[0058] In this embodiment, data mining technology is used to crawl text from the Internet, and the crawled text is preprocessed. The preprocessing includes deleting non-comment text, for example, deleting parameter content and non-text strings of the web page.
[0059] In this embodiment, the preprocessed text is used as the comment text.
[0060] S102: Determine the emotional sentences in each sentence included in the comment text, and determine the context sentences of each emotional sentence.
[0061] In this embodiment, emotional sentences are determined from the various sentences included in the comment text. Specifically, each sentence included in the comment text is parsed to determine the sentences containing emotional words in the comment text, and the sentences containing emotional words in the comment text are determined as emotional sentences.
[0062] In this embodiment, the context of each emotional sentence is determined from the various sentences included in the comment text. Specifically, for each emotional sentence, the previous sentence and the next sentence of the emotional sentence in the comment text are determined as the context of the emotional sentence. It should be noted that for each emotional sentence, if the previous sentence of the emotional sentence does not exist in the comment text, the emotional sentence itself is used as the previous sentence of the emotional sentence. If the next sentence of the emotional sentence does not exist in the comment text, the emotional sentence itself is used as the next sentence of the emotional sentence.
[0063] S103 , performing word segmentation processing on each emotional sentence to obtain multiple words corresponding to each emotional sentence, and performing word segmentation processing on the context sentences of each emotional sentence to obtain multiple words corresponding to each context sentence.
[0064] In this embodiment, a preset word segmentation scheme is used to perform word segmentation processing on each emotional sentence to obtain multiple words corresponding to each emotional sentence.
[0065] In this embodiment, a preset word segmentation scheme is used to segment the context sentences of each sentiment sentence to obtain a plurality of words corresponding to each context sentence.
[0066] It should be noted that for the preset word segmentation scheme, please refer to the existing word segmentation scheme, which will not be repeated here.
[0067] S104: For each emotional sentence, use a pre-built sentiment analysis model to perform sentiment analysis on each word corresponding to the emotional sentence and each word corresponding to the context sentence of the emotional sentence to obtain a sentiment classification result of the emotional sentence.
[0068] In this embodiment, a sentiment analysis model is pre-constructed, and the sentiment analysis model includes a word embedding model, a first encoding model, a second encoding model, a fusion model and a sentiment classification model, wherein the first encoding model includes a GCNN encoding layer and a bidirectional gated recurrent unit BIGRU encoding layer, and the second encoding model includes a BIGRU encoding layer and an attention mechanism layer.
[0069] In this embodiment, for each emotional sentence, the various words corresponding to the emotional sentence and the various words corresponding to the context sentences of the emotional sentence are input into a pre-built sentiment analysis model. The sentiment analysis model performs sentiment analysis on the various words corresponding to the emotional sentence and the various words corresponding to the context sentences of the emotional sentence, thereby obtaining the sentiment analysis result of the emotional sentence.
[0070] See Figure 2 The process of using a pre-built sentiment analysis model to perform sentiment analysis on each word corresponding to the sentiment sentence and each word corresponding to the context sentence of the sentiment sentence to obtain the sentiment classification result of the sentiment sentence specifically includes the following steps:
[0071] S201. Using a word embedding model, perform embedding representation processing on each word corresponding to the sentiment sentence and each word corresponding to the context sentence of the sentiment sentence to obtain a sentiment sentence vector of the sentiment sentence and a context sentence vector of the context sentence.
[0072] In this embodiment, a Glove (Global Vectors for Word Representation, a word representation tool for global word frequency statistics) pre-training model is trained in advance to obtain a word embedding model.
[0073] See Figure 3 , the training process of the Glove pre-training model includes:
[0074] In this embodiment, the collection unit is used to obtain comment text from social media. Specifically, data mining technology can be used to obtain comment text from social media. Social media includes but is not limited to Weibo, encyclopedias, and forums. Exemplary data mining technology can be crawler technology.
[0075] In this embodiment, the obtained comment text is preprocessed. The preprocessing includes removing non-comment text content. For example, the non-comment text content may be parameter content of a web page and a non-text string.
[0076] In this embodiment, a corpus is constructed based on the preprocessed comment text, and the Glove pre-training model is trained based on the corpus, so that the trained Glove pre-training model is determined as a word embedding model.
[0077] In this embodiment, a word vector model is used to perform embedding representation processing on each word corresponding to the sentiment sentence to obtain a word vector for each word corresponding to the sentiment sentence, and thus, based on the word vector for each word corresponding to the sentiment sentence, the sentiment sentence vector of the sentiment sentence is obtained.
[0078] In this embodiment, a word vector model is used to perform embedding representation processing on each word corresponding to the context sentence of the sentiment sentence to obtain the word vector of each word corresponding to the context sentence, and thus the context sentence vector of the context sentence is obtained based on the word vector of each word corresponding to the context sentence.
[0079] S202: Utilize the first coding model to encode the sentiment sentence vector to obtain bidirectional temporal features of the sentiment sentence.
[0080] In this embodiment, the GCNN encoding layer and the BIGRU encoding layer in the first encoding model are used to encode the sentiment sentence vector to obtain the bidirectional temporal features of the sentiment sentence.
[0081] See Figure 4 , using the first encoding model, encoding the sentiment sentence vector to obtain the bidirectional temporal features of the sentiment sentence, specifically including:
[0082] S401. Utilize the GCNN encoding layer in the first encoding model to encode the sentiment sentence vector to obtain the encoding vector of the sentiment sentence.
[0083] In this embodiment, the GCNN encoding layer in the first encoding model is used to encode the emotional sentence vector. Specifically, the convolutional structure of the GCNN is used to encode the emotional sentence vector to obtain the encoding vector of the emotional sentence.
[0084] Optionally, the structure of GCNN is as follows Figure 5 As shown in the figure, the convolutional structure of GCNN is used to encode the emotional sentence vector to obtain the encoding vector of the emotional sentence, which specifically includes:
[0085] The convolution part of GCNN is mainly divided into two parts, the convolution activation part A and the gating operation B. The GCNN gating unit calculates the information from A and B as shown in formula (1).
[0086]
[0087] Among them, w l is the sentiment sentence vector, WA and W B is the convolution kernel weight matrix with different values in A and B, W A 、W B ∈R k ×n×o ; b A and b B For the convolution kernel bias items with different values in A and B, b A 、b B ∈R o ; n and o are word vectors in the input sentiment sentence vector, k is the convolution kernel information; σ is the Sigmoid function, which is used to control the transmission of information in part A; It is a multivariate multiplication operation used to find the product of each element of A and B. The result is the feature extracted by GCNN.
[0088] S402 : Utilize the bidirectional gated recurrent unit (BIGRU) coding layer in the first coding model to perform coding processing on the coding vector of the emotional sentence to obtain bidirectional temporal features of the emotional sentence.
[0089] In this embodiment, the bidirectional gated recurrent unit (BIGRU) coding layer in the first coding model is used to perform coding processing on the coding vector of the emotional sentence to obtain the bidirectional temporal features of the emotional sentence.
[0090] In this embodiment, the first encoding model of GCNN+BIGRU is used to identify emotional sentence features, which has stronger feature extraction capabilities.
[0091] S203: Utilize the second encoding model to encode the context sentence vector to obtain important emotional features of the context sentence of the emotional sentence.
[0092] In this embodiment, the second encoding model is used to encode the context sentence vector to obtain the important emotional features of the context sentence of the emotional sentence. Specifically, the BIGRU encoding layer and the attention mechanism layer in the second encoding model are used to encode the context sentence vector to obtain the important emotional features of the context sentence of the emotional sentence.
[0093] See Figure 6 The process of encoding the context sentence vector using the second encoding model to obtain the important emotional features of the context sentence of the emotional sentence specifically includes the following steps:
[0094] S601 : Utilize the BIGRU encoding layer in the second encoding model to encode the context sentence vector to obtain bidirectional semantic features of the context sentence of the sentiment sentence.
[0095] In this embodiment, the context sentence vector of the context sentence is encoded using the BIGRU encoding layer in the second encoding model, thereby obtaining the bidirectional semantic features of the context sentence of the sentiment sentence.
[0096] S602. Utilize the attention mechanism layer in the second encoding model to assign weight values to the bidirectional semantic features, and obtain important sentiment features of the context sentences of the sentiment sentence based on the assigned weight values and the bidirectional semantic features.
[0097] In this embodiment, the attention mechanism layer mainly includes three parameters, namely the weight matrix, the bias term and a separate real number sequence.
[0098] In this embodiment, the bidirectional semantic features of the context sentence of the sentiment sentence are transmitted to the attention mechanism layer in the second encoding model. The attention mechanism layer assigns weight values to the bidirectional semantic features. Specifically, the attention mechanism layer determines the weight values of the bidirectional semantic features by a preset first formula, wherein the preset first formula is:
[0099]
[0100] Among them, μ t =tanh(W w h t +b w ), α t Represents the weight value of the bidirectional semantic feature, W w represents the weight matrix of the attention mechanism layer, h t Represents bidirectional semantic features, b w represents the bias term of the attention mechanism layer, μ w represents a randomly initialized real number sequence, and T represents the time.
[0101] In this embodiment, the attention mechanism layer obtains the important emotional features of the context of the emotional sentence based on the assigned weight values and the bidirectional semantic features. Specifically, the important emotional features of the context of the emotional sentence are calculated by a preset second formula, which is:
[0102] S204. Using the fusion model, the bidirectional temporal features of the emotional sentence and the important emotional features of the context sentences of the emotional sentence are fused to obtain the fusion features of the emotional sentence, and the target features of the emotional sentence are determined from the bidirectional temporal features of the emotional sentence, the important emotional features of the context sentences of the emotional sentence, and the fusion features.
[0103] In this embodiment, a fusion model is used to fuse the bidirectional temporal features of the emotional sentence and the important emotional features of the context sentences of the emotional sentence to obtain the fusion features of the emotional sentence. Specifically, the fusion model is used to fuse the bidirectional temporal features of the emotional sentence and the important emotional features of the context sentences of the emotional sentence through an element-by-element multiplication algorithm to obtain the fusion features of the emotional sentence.
[0104] In this embodiment, the maximum feature is determined from the bidirectional temporal features of the sentimental sentence, the important sentiment features of the context of the sentimental sentence, and the fused features, and the maximum feature is determined as the target feature. Optionally, the maximum feature can be determined from the bidirectional temporal features of the sentimental sentence, the important sentiment features of the context of the sentimental sentence, and the fused features using a maximum formula, that is, by max[fused features, bidirectional temporal features of the sentimental sentence, important sentiment features of the context of the sentimental sentence].
[0105] S205: Input the target features of the emotional sentence into the emotional classification model to obtain the emotional sentence classification result.
[0106] In this embodiment, the target features of the emotional sentence are input into the emotion classification model, the emotion distribution model determines the probability value of each emotion category corresponding to the target features, and outputs the probability value of each emotion category corresponding to the target features, thereby obtaining the classification result of the emotional sentence. The classification result of the emotional sentence is the probability value of each emotion category corresponding to the target features.
[0107] The sentiment analysis method provided in the embodiment of the present application obtains the comment text, determines the sentiment sentences in each sentence included in the comment text, and determines the context sentences of each sentiment sentence, performs word segmentation processing on each sentiment sentence to obtain multiple words corresponding to each sentiment sentence, and performs word segmentation processing on the context sentences of each sentiment sentence to obtain multiple words corresponding to each context sentence, and for each sentiment sentence, uses a pre-constructed sentiment analysis model to perform sentiment analysis on each word corresponding to the sentiment sentence and each word corresponding to the context sentences of the sentiment sentence to obtain the sentiment classification result of the sentiment sentence. Applying the sentiment analysis method provided in the embodiment of the present application, a sentiment analysis model is pre-constructed, and based on the sentiment sentence and the context features of the sentiment sentence, the sentiment classification result of the sentiment sentence is determined by the sentiment analysis model, thereby improving the accuracy of sentiment analysis.
[0108] See Figure 7 The overall implementation process of the sentiment analysis method provided in this application is described as follows:
[0109] Using data mining technology, text is crawled from the Internet and preprocessed. The preprocessing includes deleting non-comment text to obtain comment text.
[0110] The sentences containing sentiment words in the comment text are determined as sentiment sentences, and the previous sentence and the next sentence of the sentiment sentence in the comment text are determined as context sentences of the sentiment sentence. Each sentiment sentence is segmented to obtain multiple words corresponding to each sentiment sentence, and the context sentences of each sentiment sentence are segmented to obtain multiple words corresponding to each context sentence.
[0111] Using the word embedding model, each word corresponding to the sentiment sentence and each word corresponding to the context sentence of the sentiment sentence are embedded and represented to obtain the sentiment sentence vector of the sentiment sentence and the context sentence vector of the context sentence.
[0112] The GCNN encoding layer in the first encoding model is used to encode the emotional sentence vector to obtain the encoding vector of the emotional sentence. Then, the bidirectional gated recurrent unit BIGRU encoding layer in the first encoding model is used to encode the encoding vector of the emotional sentence to obtain the bidirectional temporal features of the emotional sentence.
[0113] The BIGRU encoding layer in the second encoding model is used to encode the context sentence vector to obtain the bidirectional semantic features of the context sentence of the emotional sentence. The attention mechanism layer in the second encoding model is then used to assign weight values to the bidirectional semantic features. Based on the assigned weight values and the bidirectional semantic features, the important emotional features of the context sentence of the emotional sentence are obtained.
[0114] Using the fusion model, the bidirectional temporal features of the emotional sentence and the important emotional features of the context sentences of the emotional sentence are fused to obtain the fusion features of the emotional sentence. The target features of the emotional sentence are determined from the bidirectional temporal features of the emotional sentence, the important emotional features of the context sentences of the emotional sentence, and the fusion features. The target features of the emotional sentence are input into the emotion classification model to obtain the probability value of each emotion category corresponding to the target features.
[0115] It should be noted that although the operations are depicted in a particular order, this should not be understood as requiring that the operations be performed in the particular order shown or in a sequential order. In certain circumstances, multitasking and parallel processing may be advantageous.
[0116] It should be understood that the various steps described in the method embodiments disclosed herein may be performed in different orders and / or in parallel. In addition, the method embodiments may include additional steps and / or omit the steps shown. The scope of the present disclosure is not limited in this respect.
[0117] and Figure 1 Corresponding to the method described above, the embodiment of the present application also provides a sentiment analysis device for Figure 1 The specific implementation of the method is shown in the following diagram: Figure 8As shown, specifically including:
[0118] The first acquisition unit 801 is configured to acquire a comment text; the comment text includes at least one sentence;
[0119] The determining unit 802 is configured to determine the emotional sentences in each sentence included in the comment text, and determine the context sentences of each emotional sentence;
[0120] The second acquisition unit 803 is configured to perform word segmentation processing on each sentiment sentence to obtain a plurality of words corresponding to each sentiment sentence, and perform word segmentation processing on the context sentences of each sentiment sentence to obtain a plurality of words corresponding to each context sentence;
[0121] The third acquisition unit 804 is used to perform sentiment analysis on each emotional sentence using a pre-built sentiment analysis model on each word corresponding to the emotional sentence and each word corresponding to the context sentence of the emotional sentence to obtain a sentiment classification result of the emotional sentence.
[0122] The sentiment analysis device provided in the embodiment of the present application pre-builds a sentiment analysis model, and determines the sentiment classification result of the sentiment sentence based on the sentiment sentence and the contextual features of the sentiment sentence through the sentiment analysis model, thereby improving the accuracy of sentiment analysis.
[0123] In one embodiment of the present application, based on the aforementioned solution, the sentiment analysis model includes a word embedding model, a first encoding model, a second encoding model, a fusion model, and a sentiment classification model. Using the pre-built sentiment analysis model, the third acquisition unit 804 is specifically used to:
[0124] Using the word embedding model, each word corresponding to the sentiment sentence and each word corresponding to the context sentence of the sentiment sentence are embedded and represented to obtain a sentiment sentence vector of the sentiment sentence and a context sentence vector of the context sentence;
[0125] Using the first encoding model, encoding the emotional sentence vector to obtain a bidirectional temporal feature of the emotional sentence;
[0126] Using the second encoding model, encoding the context sentence vector to obtain important emotional features of the context sentence of the emotional sentence;
[0127] Using the fusion model, the bidirectional temporal features of the emotional sentence and the important emotional features of the context sentences of the emotional sentence are fused to obtain the fused features of the emotional sentence, and the target features of the emotional sentence are determined from the bidirectional temporal features of the emotional sentence, the important emotional features of the context sentences of the emotional sentence, and the fused features;
[0128] The target features of the emotional sentence are input into the emotional classification model to obtain the emotional sentence classification result.
[0129] In one embodiment of the present application, based on the above solution, when the third acquisition unit 804 uses the first encoding model to encode the emotional sentence vector to obtain the bidirectional temporal features of the emotional sentence, it is specifically configured to:
[0130] Using the GCNN encoding layer in the first encoding model, encoding the emotional sentence vector to obtain the encoding vector of the emotional sentence;
[0131] The encoding vector of the emotional sentence is encoded using the bidirectional gated recurrent unit (BIGRU) encoding layer in the first encoding model to obtain bidirectional temporal features of the emotional sentence.
[0132] In one embodiment of the present application, based on the aforementioned solution, when the third acquisition unit 804 uses the second encoding model to encode the context sentence vector to obtain the important emotional features of the context sentence of the emotional sentence, it is specifically configured to:
[0133] Using the BIGRU encoding layer in the second encoding model to encode the context sentence vector to obtain bidirectional semantic features of the context sentence of the sentiment sentence;
[0134] The attention mechanism layer in the second encoding model is used to assign weight values to the bidirectional semantic features, and based on the assigned weight values and the bidirectional semantic features, the important sentiment features of the context sentences of the sentiment sentence are obtained.
[0135] In one embodiment of the present application, based on the aforementioned solution, the third acquisition unit 804, when using the fusion model to fuse the bidirectional temporal features of the emotional sentence and the important emotional features of the context of the emotional sentence to obtain the fusion features of the emotional sentence, is specifically used to:
[0136] The fusion model is used to fuse the bidirectional temporal features of the emotional sentence and the important emotional features of the context sentences of the emotional sentence through an element-by-element multiplication algorithm to obtain the fusion features of the emotional sentence.
[0137] In one embodiment of the present application, based on the above solution, when determining the emotional sentences in each sentence included in the comment text, the determining unit 802 is specifically configured to:
[0138] Parsing each sentence included in the review text to determine sentences in the review text that contain sentiment words;
[0139] Sentences containing sentiment words in the comment text are determined as sentiment sentences.
[0140] In one embodiment of the present application, based on the above solution, when determining the context sentence of each emotional sentence, the determining unit 802 is specifically configured to:
[0141] For each emotional sentence, the previous sentence of the emotional sentence and the next sentence of the emotional sentence in the comment text are determined as context sentences of the emotional sentence.
[0142] An embodiment of the present application further provides a storage medium storing an instruction set, wherein when the instruction set is run, the sentiment analysis method disclosed in any of the above embodiments is executed.
[0143] The present application also provides an electronic device, the structure of which is shown in FIG. Figure 9 As shown, it specifically includes a memory 901 for storing at least one set of instruction sets; a processor 902 for executing the instruction set stored in the memory, and implementing the sentiment analysis method disclosed in any of the above embodiments by executing the instruction set.
[0144] Although the subject matter has been described in language specific to structural features and / or methodological logical acts, it should be understood that the subject matter defined in the appended claims is not necessarily limited to the specific features or acts described above. Rather, the specific features and acts described above are merely example forms of implementing the claims.
[0145] Although several specific implementation details are included in the above discussion, these should not be construed as limiting the scope of the present disclosure. Certain features described in the context of a separate embodiment may also be implemented in combination in a single embodiment. Conversely, the various features described in the context of a single embodiment may also be implemented in multiple embodiments individually or in any suitable sub-combination.
[0146] The above description is merely an illustration of the preferred embodiments disclosed in this application and the technical principles employed. Those skilled in the art should understand that the scope of disclosure in this application is not limited to the technical solutions formed by the specific combination of the above-mentioned technical features, but also encompasses other technical solutions formed by any combination of the above-mentioned technical features or their equivalents without departing from the above-mentioned disclosed concepts. For example, a technical solution formed by replacing the above-mentioned features with (but not limited to) technical features with similar functions disclosed in this application.
Claims
1. A sentiment analysis method, characterized in that: include: Get the comment text; The review text includes at least one sentence; Determining the emotional sentences in each sentence included in the comment text, and determining the context sentences of each emotional sentence; the emotional sentences are sentences containing emotional words; Perform word segmentation on each sentiment sentence to obtain multiple words corresponding to each sentiment sentence, and perform word segmentation on the context sentences of each sentiment sentence to obtain multiple words corresponding to each context sentence; For each emotional sentence, a pre-built sentiment analysis model is used to perform sentiment analysis on each word corresponding to the emotional sentence and each word corresponding to the context sentence of the emotional sentence to obtain a sentiment classification result of the emotional sentence; The sentiment analysis model includes a word embedding model, a first encoding model, a second encoding model, a fusion model and a sentiment classification model. The sentiment analysis model constructed in advance is used to perform sentiment analysis on each word corresponding to the sentiment sentence and each word corresponding to the context sentence of the sentiment sentence to obtain the sentiment classification result of the sentiment sentence, including: Using the word embedding model, each word corresponding to the sentiment sentence and each word corresponding to the context sentence of the sentiment sentence are embedded and represented to obtain a sentiment sentence vector of the sentiment sentence and a context sentence vector of the context sentence; Using the first encoding model, encoding the emotional sentence vector to obtain a bidirectional temporal feature of the emotional sentence; Using the second encoding model, encoding the context sentence vector to obtain important emotional features of the context sentence of the emotional sentence; Using the fusion model, the bidirectional temporal features of the emotional sentence and the important emotional features of the context sentences of the emotional sentence are fused to obtain the fused features of the emotional sentence, and the target features of the emotional sentence are determined from the bidirectional temporal features of the emotional sentence, the important emotional features of the context sentences of the emotional sentence, and the fused features; Inputting the target features of the emotional sentence into the emotional classification model to obtain the emotional sentence classification result; The encoding process of the emotional sentence vector using the first encoding model to obtain the bidirectional temporal features of the emotional sentence includes: Using the GCNN encoding layer in the first encoding model, encoding the emotional sentence vector to obtain the encoding vector of the emotional sentence; Using the bidirectional gated recurrent unit (BIGRU) encoding layer in the first encoding model, encoding the encoding vector of the emotional sentence to obtain a bidirectional temporal feature of the emotional sentence; The encoding process of the context sentence vector using the second encoding model to obtain the important emotional features of the context sentence of the emotional sentence includes: Using the BIGRU encoding layer in the second encoding model to encode the context sentence vector to obtain bidirectional semantic features of the context sentence of the sentiment sentence; Assigning weight values to the bidirectional semantic features using the attention mechanism layer in the second encoding model, and obtaining important sentiment features of the context sentence of the sentiment sentence based on the assigned weight values and the bidirectional semantic features; The method of using the fusion model to fuse the bidirectional temporal features of the emotional sentence and the important emotional features of the context of the emotional sentence to obtain the fusion features of the emotional sentence includes: The fusion model is used to fuse the bidirectional temporal features of the emotional sentence and the important emotional features of the context sentences of the emotional sentence through an element-by-element multiplication algorithm to obtain the fusion features of the emotional sentence.
2. The method according to claim 1, characterized in that The step of determining the emotional sentences in each sentence included in the comment text includes: Parsing each sentence included in the review text to determine sentences in the review text that contain sentiment words; Sentences containing sentiment words in the comment text are determined as sentiment sentences.
3. The method according to claim 1 or 2, characterized in that Determining the context of each sentiment sentence includes: For each emotional sentence, the previous sentence of the emotional sentence and the next sentence of the emotional sentence in the comment text are determined as context sentences of the emotional sentence.
4. A sentiment analysis device, characterized in that: include: A first acquisition unit is used to acquire the comment text; The review text includes at least one sentence; A determination unit, configured to determine an emotional sentence in each sentence included in the comment text, and to determine a context sentence for each emotional sentence; the emotional sentence is a sentence containing an emotional word; The second acquisition unit is used to perform word segmentation processing on each emotional sentence to obtain multiple words corresponding to each emotional sentence, and to perform word segmentation processing on the context sentences of each emotional sentence to obtain multiple words corresponding to each context sentence; The third acquisition unit is configured to perform sentiment analysis on each emotional sentence using a pre-built sentiment analysis model on each word corresponding to the emotional sentence and each word corresponding to a context sentence of the emotional sentence to obtain a sentiment classification result of the emotional sentence; The sentiment analysis model includes a word embedding model, a first encoding model, a second encoding model, a fusion model and a sentiment classification model. The sentiment analysis model constructed in advance is used to perform sentiment analysis on each word corresponding to the sentiment sentence and each word corresponding to the context sentence of the sentiment sentence to obtain the sentiment classification result of the sentiment sentence, including: Using the word embedding model, each word corresponding to the sentiment sentence and each word corresponding to the context sentence of the sentiment sentence are embedded and represented to obtain a sentiment sentence vector of the sentiment sentence and a context sentence vector of the context sentence; Using the GCNN encoding layer in the first encoding model, encoding the emotional sentence vector to obtain the encoding vector of the emotional sentence; Using the bidirectional gated recurrent unit (BIGRU) encoding layer in the first encoding model, encoding the encoding vector of the emotional sentence to obtain a bidirectional temporal feature of the emotional sentence; Using the BIGRU encoding layer in the second encoding model to encode the context sentence vector to obtain bidirectional semantic features of the context sentence of the sentiment sentence; Assigning weight values to the bidirectional semantic features using the attention mechanism layer in the second encoding model, and obtaining important sentiment features of the context sentence of the sentiment sentence based on the assigned weight values and the bidirectional semantic features; Using the fusion model, the bidirectional temporal features of the emotional sentence and the important emotional features of the context sentences of the emotional sentence are fused through an element-by-element multiplication algorithm to obtain the fusion features of the emotional sentence; Determining a target feature of the emotional sentence from the bidirectional temporal features of the emotional sentence, the important emotional features of the context sentences of the emotional sentence, and the fusion features; The target features of the emotional sentence are input into the emotional classification model to obtain the emotional sentence classification result.
5. A storage medium, characterized in that The storage medium stores an instruction set, wherein the instruction set, when executed by a processor, implements the sentiment analysis method according to any one of claims 1 to 3.
6. An electronic device, characterized in that: include: A memory for storing at least one set of instructions; A processor is configured to execute an instruction set stored in the memory, and implement the sentiment analysis method according to any one of claims 1 to 3 by executing the instruction set.
Citation Information
Patent Citations
Fine-grained sentiment analysis model training method and device
CN111666761A