A method and apparatus for sentiment classification
By constructing an attribute-level sentiment classification model based on graph attention networks and multi-scale detection networks, and enriching sentence features with features from multiple sentences in the same text, the problem of sample data dependence in existing technologies is solved, and efficient sentiment classification is achieved.
Patent Information
- Application Number
- CN202011436323.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-12-10
- Publication Date
- 2025-12-05
- Estimated Expiration
- 2040-12-10
AI Technical Summary
Existing technologies require the manual collection of a large amount of sample data when performing attribute-level sentiment classification, which affects the accuracy of classification and increases labor costs.
By acquiring features from multiple sentences within the same text, and enriching sentence features using graph attention networks and multi-scale detection networks, an attribute-level sentiment classification model is constructed, reducing reliance on sample data.
Without compromising the accuracy of sentiment classification, this method reduces the workload of sample collection and labeling, saves labor costs, and improves the accuracy of sentiment classification.
Smart Images

Figure CN114625869B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technology, and in particular to an emotion classification method and apparatus. Background Technology
[0002] With the rapid development of technology, more and more users are purchasing goods through e-commerce websites, resulting in a massive amount of shopping reviews. Merchants are eager to analyze and organize these reviews to obtain objective evaluations from consumers.
[0003] Among these methods, attribute-level sentiment classification can be performed on shopping reviews to determine the sentiment classification of the product's attribute characteristics in the reviews, thereby determining the objective evaluation of the product's attribute characteristics by the general public.
[0004] Attribute-level sentiment classification is a fine-grained sentiment classification task, aiming to accurately determine the sentiment classification of various attributes of products. Currently, attribute-level sentiment classification is usually based on models; however, a large amount of sample data needs to be manually collected beforehand to train the model, otherwise the accuracy of the model in attribute-level sentiment classification will be affected. Summary of the Invention
[0005] In order to reduce labor costs without affecting the accuracy of emotion classification, this application discloses an emotion classification method and apparatus.
[0006] In a first aspect, this application discloses an emotion classification method, the method comprising:
[0007] Obtain the features of the first sentence, as well as the attribute features of the subject in the first sentence;
[0008] Obtain the features of the second sentence, which includes the attribute features of the subject;
[0009] Obtain the features of the third sentence, which is adjacent to the first sentence;
[0010] The features of the first sentence are expanded based on the features of the first sentence, the features of the second sentence, and the attribute features to obtain the first expanded features;
[0011] Based on the features of the first sentence and the features of the third sentence, the features of the first sentence are expanded to obtain the second expanded features;
[0012] Based on the first extended feature and the second extended feature, obtain the sentiment classification of the attribute features of the subject in the first sentence;
[0013] The first, second, and third sentences belong to the same chapter.
[0014] In an optional implementation, the sentiment classification of the attribute features of the subject in the first sentence based on the first extended feature and the second extended feature includes:
[0015] Multi-scale detection is performed on the first extended feature and the second extended feature to obtain the multi-scale feature corresponding to the first sentence;
[0016] The sentiment classification is obtained based on the multi-scale features.
[0017] In an optional implementation, the step of performing multi-scale detection on the first extended feature and the second extended feature to obtain the multi-scale features corresponding to the first sentence includes:
[0018] The first extended feature is fused with the second extended feature to obtain the third extended feature corresponding to the first sentence;
[0019] Multi-scale detection is performed on the third extended feature to obtain multiple features with different scales corresponding to the first sentence;
[0020] The multi-scale features are obtained by fusing the features of multiple different scales.
[0021] In one optional implementation, the multi-scale detection of the third extended feature to obtain multiple features of different scales corresponding to the first sentence includes:
[0022] The third extended feature is input into the cascaded pyramid network to obtain multiple features of different scales output by each LSTM hidden layer of different dimensions in the cascaded pyramid network.
[0023] In an optional implementation, the step of extending the features of the first sentence based on the features of the first sentence, the features of the second sentence, and the attribute features to obtain the first extended features includes:
[0024] Based on the features of the first sentence, the features of the second sentence, and the attribute features, a first sentiment correlation degree between the first sentence and the attribute features is obtained, and a second sentiment correlation degree between the second sentence and the attribute features is obtained;
[0025] The features of the first sentence are expanded based on the first emotional relevance, the second emotional relevance, and the features of the second sentence to obtain the first expanded features.
[0026] In an optional implementation, the step of expanding the features of the first sentence based on the first sentiment correlation degree, the second sentiment correlation degree, and the features of the second sentence to obtain the first expanded features includes:
[0027] Based on the features of the second sentence and the degree of sentiment association, the aggregated features of the attribute features in the second sentence are obtained;
[0028] Based on the degree of correlation between the aggregated features and the first sentiment, extended features are obtained to expand the features of the first sentence;
[0029] The first extended feature is obtained based on the extended feature and the feature of the first sentence.
[0030] In an optional implementation, the step of extending the features of the first sentence based on the features of the first sentence and the features of the third sentence to obtain second extended features includes:
[0031] Based on the features of the first sentence and the features of the third sentence, obtain the third sentiment correlation degree between the first sentence and the third sentence;
[0032] The second extended feature is obtained based on the degree of third emotional association and the features of the third sentence.
[0033] In one optional implementation, obtaining the features of the first sentence includes:
[0034] Construct auxiliary interrogative sentences for the attribute features of the subject;
[0035] The features of the first sentence are obtained by comparing the constructed auxiliary question with the first sentence.
[0036] In one optional implementation, obtaining the features of the second sentence includes:
[0037] Construct auxiliary interrogative sentences for the attribute features of the subject;
[0038] The features of the second sentence are obtained by comparing the constructed auxiliary question with the second sentence.
[0039] In one optional implementation, obtaining the features of the third sentence includes:
[0040] If the third sentence includes the attribute features of the subject, construct an auxiliary interrogative sentence for the attribute features of the subject;
[0041] The features of the third sentence are obtained based on the constructed auxiliary interrogative sentence and the third sentence.
[0042] Secondly, this application discloses an emotion classification device, the device comprising:
[0043] The first acquisition module is used to acquire the features of the first sentence and the attribute features of the subject in the first sentence;
[0044] The second acquisition module is used to acquire features of the second sentence, wherein the second sentence includes the attribute features of the subject;
[0045] The third acquisition module is used to acquire features of a third sentence, which is adjacent to the first sentence.
[0046] The first extension module is used to extend the features of the first sentence based on the features of the first sentence, the features of the second sentence, and the attribute features to obtain the first extended features;
[0047] The second extension module is used to extend the features of the first sentence based on the features of the first sentence and the features of the third sentence to obtain the second extended features;
[0048] The fourth acquisition module is used to acquire the sentiment classification of the attribute features of the subject in the first sentence based on the first extended features and the second extended features;
[0049] The first, second, and third sentences belong to the same chapter.
[0050] In one optional implementation, the fourth acquisition module includes:
[0051] The detection unit is used to perform multi-scale detection on the first extended feature and the second extended feature to obtain the multi-scale feature corresponding to the first sentence.
[0052] The first acquisition unit is used to acquire the sentiment classification based on the multi-scale features.
[0053] In one optional implementation, the detection unit includes:
[0054] The first fusion subunit is used to fuse the first extended feature with the second extended feature to obtain the third extended feature corresponding to the first sentence;
[0055] The detection subunit is used to perform multi-scale detection on the third extended feature to obtain multiple features with different scales corresponding to the first sentence.
[0056] The second fusion subunit is used to fuse the multiple features with different scales to obtain the multi-scale features.
[0057] In one optional implementation, the detection subunit is specifically used to: input the third extended feature into the cascaded pyramid network to obtain multiple features of different scales output by each LSTM hidden layer of different dimensions in the cascaded pyramid network.
[0058] In an optional implementation, the first extension module includes:
[0059] The second acquisition unit is used to acquire, based on the features of the first sentence, the features of the second sentence, and the attribute features, a first sentiment correlation degree between the first sentence and the attribute features, and a second sentiment correlation degree between the second sentence and the attribute features;
[0060] An extension unit is used to extend the features of the first sentence based on the first emotional correlation degree, the second emotional correlation degree, and the features of the second sentence to obtain the first extended features.
[0061] In one optional implementation, the second acquisition unit includes:
[0062] The first acquisition subunit is used to acquire the aggregated features of the attribute features in the second sentence based on the features of the second sentence and the second sentiment correlation degree;
[0063] The second acquisition subunit is used to acquire extended features for expanding the features of the first sentence based on the degree of correlation between the aggregated features and the first sentiment.
[0064] The third acquisition subunit is used to acquire the first extended feature based on the extended feature and the feature of the first sentence.
[0065] In an optional implementation, the second extension module includes:
[0066] The third acquisition unit is used to acquire the third sentiment association degree between the first sentence and the third sentence based on the features of the first sentence and the features of the third sentence;
[0067] The fourth acquisition unit is used to acquire the second extended feature based on the third emotional correlation degree and the features of the third sentence.
[0068] In an optional implementation, the first acquisition module includes:
[0069] The first construction unit is used to construct auxiliary interrogative sentences for the attribute features of the subject;
[0070] The fifth acquisition unit is used to acquire features of the first sentence based on the constructed auxiliary interrogative sentence and the first sentence.
[0071] In one optional implementation, the second acquisition module includes:
[0072] The second construction unit is used to construct auxiliary interrogative sentences for the attribute features of the subject;
[0073] The sixth acquisition unit is used to acquire features of the second sentence based on the constructed auxiliary interrogative sentence and the second sentence.
[0074] In one optional implementation, the third acquisition module includes:
[0075] The third construction unit is used to construct an auxiliary interrogative sentence for the attribute features of the subject when the third sentence includes the attribute features of the subject;
[0076] The seventh acquisition unit is used to acquire the features of the third sentence based on the constructed auxiliary interrogative sentence and the third sentence.
[0077] Thirdly, this application discloses an electronic device comprising:
[0078] processor; and
[0079] A memory having executable code stored thereon, which, when executed, causes the processor to perform the sentiment classification method as described in the first aspect.
[0080] Fourthly, this application discloses one or more machine-readable media having executable code stored thereon, which, when executed, causes a processor to perform the sentiment classification method as described in the first aspect.
[0081] Compared with the prior art, the embodiments of this application have the following advantages:
[0082] In some cases, a passage often contains multiple sentences. If at least two sentences express the same sentiment classification of the same attribute of the same subject, then generally, the sentiment classification of the same attribute of the same subject expressed in at least two sentences is the same; for example, they are usually both positive or both are usually negative. Positive sentiments include liking, suitability, low price, and good quality, while negative sentiments include disliking, unsuitability, high price, and poor quality.
[0083] In another scenario, a text often contains multiple sentences, and these sentences typically express sentiment classifications regarding the same subject's attributes. Sentences that are adjacent in position within the text usually express the same sentiment classification. For example, in a text, sentence A and sentence B are adjacent. The sentiment classification of sentence A is usually the same as that of sentence B, and / or, the sentiment classifications of the same attribute of the same subject included in sentences A and B are usually the same, and / or, the sentiment classifications of different attribute features of the same subject included in sentences A and B are usually also the same, and so on.
[0084] Thus, both of the above situations will affect the sentiment classification of the attribute features of the subject in the sentence of the passage. For example, for any sentence in the passage, if it is necessary to obtain the sentiment classification of a certain attribute feature of a certain subject in that sentence, the sentiment classification of the adjacent sentences of that sentence in the passage and the sentiment classification of the attribute feature of that subject in other sentences in the passage will affect the sentiment classification of the attribute feature of that subject in that sentence.
[0085] Thus, the attribute-level sentiment classification model constructed in this application can support the following: when it is necessary to obtain the sentiment classification of the attribute features of the subject in the first sentence of a text, the electronic device can obtain the features of the first sentence and the attribute features of the subject in the first sentence; obtain the features of the second sentence, which includes the attribute features of the subject; obtain the features of the third sentence, which is adjacent to the first sentence; expand the features of the first sentence based on the features of the first sentence, the features of the second sentence, and the attribute features to obtain a first expanded feature; expand the features of the first sentence based on the features of the first sentence and the features of the third sentence to obtain a second expanded feature; and obtain the sentiment classification of the attribute features of the subject in the first sentence based on the first expanded feature and the second expanded feature; wherein the first sentence, the second sentence, and the third sentence belong to the same text.
[0086] In this way, the features of the first sentence can be enriched based on the contextual information of the first sentence. For example, at least the first and second graph attention networks in the attribute-level sentiment classification model can be used to enrich the features of the first sentence based on the contextual information of the first sentence, so that the enriched features of the first sentence can include not only the features of the first sentence itself, but also the relevant features of the second and third sentences, etc.
[0087] Thus, through this application, it is not necessary to collect a large amount of sample data for training the attribute-level sentiment classification model beforehand. In this way, even if a large amount of sample data is not used when training the attribute-level sentiment classification model, the attribute-level sentiment classification model can learn more and more important features that help determine the sentiment classification of the subject in the sentence based on the text, thereby helping to improve the accuracy of sentiment classification.
[0088] It is evident that, while ensuring the accuracy of sentiment classification, the workload of sample collection and labeling can be reduced, thereby saving labor costs. Attached Figure Description
[0089] Figure 1 This is a flowchart illustrating the steps of a model construction method according to an exemplary embodiment of this application.
[0090] Figure 2 This is a schematic diagram of the network structure of an attribute-level sentiment classification model as illustrated in an exemplary embodiment of this application.
[0091] Figure 3 This is a schematic diagram of the network structure of an attribute-level sentiment classification model as illustrated in an exemplary embodiment of this application.
[0092] Figure 4 This is a schematic diagram of the network structure of an attribute-level sentiment classification model as illustrated in an exemplary embodiment of this application.
[0093] Figure 5 This is a flowchart illustrating an exemplary embodiment of an emotion classification method according to this application.
[0094] Figure 6 This is a flowchart illustrating an exemplary embodiment of an emotion classification method according to this application.
[0095] Figure 7 This is a structural block diagram of an emotion classification device illustrated in an exemplary embodiment of this application.
[0096] Figure 8 This is a schematic diagram of the structure of an apparatus provided in an exemplary embodiment of this application. Detailed Implementation
[0097] To make the above-mentioned objectives, features and advantages of this application more apparent and understandable, the application will be further described in detail below with reference to the accompanying drawings and specific embodiments.
[0098] In the case of a passage containing multiple sentences, in order to obtain the sentiment classification of the subject's attribute features in a specific sentence of the passage, refer to... Figure 1The diagram shows a flowchart of a model construction method according to this application. This method can construct an attribute-level sentiment classification model, and then obtain the sentiment classification of the subject's attribute features in sentences in a text based on the attribute-level sentiment classification model.
[0099] This method is applied in electronic devices, see [link to relevant documentation]. Figure 1 The method may specifically include the following steps:
[0100] In step S101, at least one sample dataset is obtained.
[0101] For any given sample dataset, the dataset includes: a sample passage labeled with the first sample sentence, and a sentiment classification of the sample attribute features of the sample subject of the first sample sentence within the sample passage. The sample passage contains at least two sentences.
[0102] The sample text includes user-inputted comments, such as comments on products, advertisements, news, videos, or audio, as well as conversations between users and others.
[0103] In step S102, the network structure of the attribute-level sentiment classification model is constructed.
[0104] In one embodiment of this application, see [link to embodiment]. Figure 2 The network structure of an attribute-level sentiment classification model may include: a feature acquisition network, a first-image attention network, a second-image attention network, a multi-scale detection network, and a normalization network. Of course, other networks may be included depending on the specific circumstances, and this application does not impose any limitations on this.
[0105] Specifically, the feature acquisition network is used to acquire the sample attribute features of the sample subject in the first sample sentence, as well as the features of the first sample sentence, the features of the second sample sentence involving the sample subject in the sample text, and the features of the third sample sentence in the sample text that is adjacent to the first sample sentence. The second sample sentence is different from the first sample sentence.
[0106] The first attention network is used to expand the features of the first sample sentence based on the features of the first sample sentence, the features of the second sample sentence, and the sample attribute features, to obtain the first sample expanded features corresponding to the first sentence.
[0107] The second attention network is used to obtain second sample extended features based on the features of the first sample sentence and the features of the third sample sentence, which are used to expand the features of the first sample sentence.
[0108] The multi-scale detection network is used to perform multi-scale detection on the extended features of the first sample and the extended features of the second sample to obtain the multi-scale features corresponding to the sentence of the first sample.
[0109] Normalized networks are used for sentiment classification by obtaining the sample attribute features of the sample subject in the first sample sentence based on multi-scale features.
[0110] Normalized networks can include softmax networks, etc.
[0111] The input end of the network structure includes the input end of the feature acquisition network.
[0112] The input end of the feature acquisition network is used to input sample texts.
[0113] The input of the feature acquisition network is connected to the input of the first graph attention network and also to the input of the second graph attention network.
[0114] In the first diagram, the output of the attention network is connected to the input of the multi-scale detection network. In the second diagram, the output of the attention network is connected to the input of the multi-scale detection network, and the output of the multi-scale detection network is connected to the input of the normalization network.
[0115] The output of the network structure includes the output of the normalized network.
[0116] Furthermore, in Figure 2 Based on the network structure shown, see [link to network structure]. Figure 3 Multi-scale detection networks include:
[0117] Feature fusion networks, cascaded pyramid networks, and adaptive fusion networks are all included. Of course, other networks may be included depending on the specific circumstances, and this application does not impose any limitations on this.
[0118] The feature fusion network is used to fuse the extended features of the first sample with the extended features of the second sample to obtain the extended features of the third sample.
[0119] The cascaded pyramid network is used to perform multi-scale detection on the expanded features of the third sample, thereby obtaining multiple features of different scales corresponding to the sentence of the first sample.
[0120] Adaptive fusion networks are used to fuse features at multiple scales to obtain multi-scale features.
[0121] The input of the multi-scale detection network includes the input of the feature fusion network.
[0122] The input of the feature fusion network is used to input the first sample expanded features and the second sample expanded features.
[0123] The output of the feature fusion network is connected to the input of the cascaded pyramid network.
[0124] The output of the cascaded pyramid network is connected to the input of the adaptive fusion network. The output of the multi-scale detection network includes the output of the adaptive fusion network, and the output of the adaptive fusion network is connected to the input of the normalization network.
[0125] Furthermore, in Figure 3 Based on the network structure shown, see [link to network structure]. Figure 4 The cascaded pyramid network consists of multiple cascaded LSTM hidden layers, with different LSTM hidden layers having different dimensions.
[0126] In any two adjacent LSTM hidden layers in a cascaded pyramid network, the input of the later LSTM hidden layer is connected to the output of the earlier LSTM hidden layer.
[0127] The output of each LSTM hidden layer is also connected to the input of the adaptive fusion network.
[0128] The input of the cascaded pyramid network includes the input of the first LSTM hidden layer, which is used to input the third sample extended features.
[0129] In this application, the network structure of the attribute-level sentiment classification model can be constructed based on actual needs. For example, the constructed attribute-level sentiment classification model may be applied to different business scenarios, and the network structure of the attribute-level sentiment classification model applicable to different business scenarios may be different. For example, the types of networks included may not all be the same, or the types of networks may be the same, but the number of networks of the same type may be different.
[0130] In this application, sentence features can be vectors or matrices, etc. Attribute features can be vectors or matrices, etc.
[0131] The first sample sentence, the second sample sentence, the third sample sentence, the sample subject, and the sample attributes in the sample chapter of this application are illustrated by an example, but this is not intended to limit the scope of protection of this application.
[0132] For example, suppose the sample text consists of user-inputted reviews of a piece of clothing that the user purchased.
[0133] The review includes five sentences: "The size of the clothes is right, the color is great, the quality is very high, the size and pattern of this garment are fantastic, and the clothes are very vibrant." The sentences are listed in order as follows: Sentence 1 "The size of the clothes is right," Sentence 2 "The color of the clothes is great," Sentence 3 "The quality is very high," Sentence 4 "The size and pattern of this garment are fantastic," and Sentence 5 "The clothes are very vibrant."
[0134] Assume the main subject of the sample is clothing and the sample attribute is color.
[0135] Sentences 2, 4, and 5 respectively involve the sample attribute "color" of the sample subject "clothes".
[0136] If sentence 2 is the first sample sentence, then sentences 4 and 5 are the second sample sentences, and sentences 1 and 3 are the third sample sentences, and so on.
[0137] In step S103, the network parameters in the network structure are trained based on the sample dataset until the network parameters converge, thus obtaining the attribute-level sentiment classification model.
[0138] After the network structure of the attribute-level sentiment classification model is built, the network parameters in the attribute-level sentiment classification model can be trained based on the sample dataset.
[0139] During training, the attribute-level sentiment classification model can be input with a sample passage labeled with the first sample sentence and the labeled sentiment classification of the sample subject's sample attribute features in the sample passage. This allows the attribute-level sentiment classification model to process the sample passage based on the network parameters in its network structure, thereby obtaining the sentiment classification of the sample subject's sample attribute features in the first sample sentence. Then, by using a loss function and the obtained sentiment classification of the sample subject's sample attribute features in the first sample sentence and the labeled sentiment classification of the sample subject's sample attribute features in the sample passage, the network parameters in each network structure of the attribute-level sentiment classification model can be adjusted until the network parameters in the network structure converge, thus completing the training. The resulting attribute-level sentiment classification model can then be deployed online.
[0140] In some cases, a passage often contains multiple sentences. If at least two sentences express the same sentiment classification of the same attribute of the same subject, then generally, the sentiment classification of the same attribute of the same subject expressed in at least two sentences is the same; for example, they are usually both positive or both are usually negative. Positive sentiments include liking, suitability, low price, and good quality, while negative sentiments include disliking, unsuitability, high price, and poor quality.
[0141] In another scenario, a text often contains multiple sentences, and these sentences typically express sentiment classifications regarding the same subject's attributes. Sentences that are adjacent in position within the text usually express the same sentiment classification. For example, in a text, sentence A and sentence B are adjacent. The sentiment classification of sentence A is usually the same as that of sentence B, and / or, the sentiment classifications of the same attribute of the same subject included in sentences A and B are usually the same, and / or, the sentiment classifications of different attribute features of the same subject included in sentences A and B are usually also the same, and so on.
[0142] Thus, both of the above situations will affect the sentiment classification of the attribute features of the subject in the sentence of the passage. For example, for any sentence in the passage, if it is necessary to obtain the sentiment classification of a certain attribute feature of a certain subject in that sentence, the sentiment classification of the adjacent sentences of that sentence in the passage and the sentiment classification of the attribute feature of that subject in other sentences in the passage will affect the sentiment classification of the attribute feature of that subject in that sentence.
[0143] Thus, the attribute-level sentiment classification model constructed in this application can support the following: when it is necessary to obtain the sentiment classification of the attribute features of the subject in the first sentence of a text, the electronic device can obtain the features of the first sentence and the attribute features of the subject in the first sentence; obtain the features of the second sentence, which includes the attribute features of the subject; obtain the features of the third sentence, which is adjacent to the first sentence; expand the features of the first sentence based on the features of the first sentence, the features of the second sentence, and the attribute features to obtain a first expanded feature; expand the features of the first sentence based on the features of the first sentence and the features of the third sentence to obtain a second expanded feature; and obtain the sentiment classification of the attribute features of the subject in the first sentence based on the first expanded feature and the second expanded feature; wherein the first sentence, the second sentence, and the third sentence belong to the same text.
[0144] In this way, the features of the first sentence can be enriched based on the contextual information of the first sentence. For example, at least the first and second graph attention networks in the attribute-level sentiment classification model can be used to enrich the features of the first sentence based on the contextual information of the first sentence, so that the enriched features of the first sentence can include not only the features of the first sentence itself, but also the relevant features of the second and third sentences, etc.
[0145] Thus, through this application, it is not necessary to collect a large amount of sample data for training the attribute-level sentiment classification model beforehand. In this way, even if a large amount of sample data is not used when training the attribute-level sentiment classification model, the attribute-level sentiment classification model can learn more and more important features that help determine the sentiment classification of the subject in the sentence based on the text, thereby helping to improve the accuracy of sentiment classification.
[0146] It is evident that, while ensuring the accuracy of sentiment classification, the workload of sample collection and labeling can be reduced, thereby saving labor costs.
[0147] After training an attribute-level sentiment classification model, it can be deployed in online applications. Thus, if an electronic device needs to obtain the sentiment classification of a specific attribute feature of a subject in the first sentence of a text, the device can mark the first sentence in the text and then input the text marked with the first sentence into a data structure based on... Figure 1 In the attribute-level sentiment classification model trained by the method shown, the attribute-level sentiment classification model processes the text marked with the first sentence to obtain the sentiment classification of the subject's attribute feature in the first sentence, and outputs the sentiment classification of the subject's attribute feature in the first sentence. In this way, the electronic device can obtain the sentiment classification of the subject's attribute feature in the first sentence.
[0148] Specifically, the process by which the attribute-level sentiment classification model processes passages marked with the first sentence can be found in [link to relevant documentation]. Figures 5-6 The embodiments shown are not described in detail here.
[0149] For example, refer to Figure 5 The diagram illustrates a flowchart of an emotion classification method according to this application. This method is applied in electronic devices and may include:
[0150] In step S201, the features of the first sentence and the attribute features of the subject in the first sentence are obtained.
[0151] This step can be performed based on the feature acquisition network in the attribute-level sentiment classification model, where the feature acquisition network includes models such as BERT.
[0152] Specifically, the passage labeled with the first sentence can be input into the feature acquisition network of the attribute-level sentiment classification model to obtain the features of the first sentence and the attribute features of the subject in the first sentence output by the feature acquisition network.
[0153] In this process, semantic recognition of the first sentence can be performed based on the BERT model to determine the attributes of the subject in the first sentence. Then, the attribute of the subject in the first sentence is encoded to obtain a vector, which is used as the attribute feature of the subject in the first sentence.
[0154] In one embodiment, the first sentence can be encoded based on the BERT model to obtain a vector, which can then be used as a feature of the first sentence.
[0155] In another embodiment, to further enrich the features of the first sentence, an auxiliary question sentence of the attribute feature of the subject can be constructed; the features of the first sentence are obtained based on the constructed auxiliary question sentence and the first sentence. For example, the first sentence and the auxiliary question sentence can be combined into a large sentence, which can be encoded based on the BERT model to obtain a vector, and used as the feature of the first sentence.
[0156] In step S202, the features of the second sentence are obtained, and the second sentence includes the attribute features of the subject.
[0157] In one embodiment, the second sentence can be encoded based on the BERT model to obtain a vector, which can then be used as a feature of the second sentence.
[0158] In another embodiment, to further enrich the features of the second sentence, an auxiliary question sentence of the attribute feature of the subject can be constructed; the features of the second sentence are obtained based on the constructed auxiliary question sentence and the second sentence. For example, the second sentence and the auxiliary question sentence can be combined into a large sentence, which can be encoded based on the BERT model to obtain a vector, and used as the features of the second sentence.
[0159] In step S203, the features of the third sentence are obtained, and the third sentence is adjacent to the first sentence.
[0160] In one embodiment, the third sentence can be encoded based on the BERT model to obtain a vector, which can then be used as a feature of the third sentence.
[0161] In another embodiment, to further enrich the features of the third sentence, if the third sentence includes the attribute feature of the subject, an auxiliary question sentence for the attribute feature of the subject is constructed; the features of the third sentence are obtained based on the constructed auxiliary question sentence and the third sentence. For example, the third sentence and the auxiliary question sentence can be combined into a large sentence, which can be encoded based on the BERT model to obtain a vector, and used as the features of the third sentence.
[0162] In this application, steps S201, S202, and S203 can be executed simultaneously or sequentially.
[0163] The first, second, and third sentences belong to the same passage.
[0164] In step S204, the features of the first sentence are expanded based on the features of the first sentence, the features of the second sentence, and the attribute features to obtain the first expanded features.
[0165] This step can be performed based on the first graph attention network in the attribute-level sentiment classification model. For example, the features of the first sentence, the features of the second sentence, and the attribute features can be input into the first graph attention network in the attribute-level sentiment classification model to obtain the first extended features output by the first graph attention network.
[0166] Within the first graph attention network, the first sentiment correlation between the first sentence and the attribute feature is obtained based on the features of the first sentence, the features of the second sentence, and the attribute feature. The second sentiment correlation between the second sentence and the attribute feature is also obtained. Then, the features of the first sentence are expanded based on the first sentiment correlation, the second sentiment correlation, and the features of the second sentence to obtain the first extended feature.
[0167] Specifically, when obtaining the first sentiment correlation between the first sentence and the attribute feature, and the second sentiment correlation between the second sentence and the attribute feature based on the features of the first sentence, the features of the second sentence, and the attribute feature, the importance of the attribute feature in the first sentence can be obtained based on the features of the first sentence and the attribute feature. This can be the proportion of the attribute feature in the first sentence, such as the ratio between the number of the attribute feature and the number of all attribute features in the first sentence.
[0168] For any given second sentence, the importance of that attribute feature within that second sentence can be determined based on its characteristics and the attribute feature itself. This importance can be expressed as the proportion of that attribute feature in the second sentence, such as the ratio of the number of that attribute feature to the total number of all attribute features in the second sentence. The same operation is performed for each other second sentence, thus obtaining the proportion of that attribute feature in each individual second sentence.
[0169] Then, the importance of the attribute feature in the first sentence and the importance of the attribute feature in each of the second sentences are summed to obtain the total importance.
[0170] Then, the ratio between the importance of this attribute feature in the first sentence and the sum of its importance is calculated to obtain the first sentiment association degree between the first sentence and this attribute feature.
[0171] For any given second sentence, the ratio between the importance of that attribute feature in that second sentence and the sum of its importance can be calculated to obtain the second sentiment correlation between that second sentence and that attribute feature. The same operation is performed for each other second sentence to obtain the second sentiment correlation between each second sentence and that attribute feature.
[0172] Specifically, when expanding the features of the first sentence based on the first sentiment relevance, the second sentiment relevance, and the features of the second sentence to obtain the first expanded features, this can be achieved through the following process:
[0173] 11) Obtain the aggregated features of the attribute in the second sentence based on the features of the second sentence and the degree of correlation with the second sentiment.
[0174] In a passage, there are often multiple sentences. If the same subject's sentiment classification is expressed in at least two sentences, then the sentiment classification of the same subject's sentiment classification expressed in at least two sentences is usually the same. For example, they are usually both positive or usually both negative.
[0175] However, sometimes there are still cases where at least one sentence in at least two sentences has a different sentiment classification for the same attribute feature of the same subject than other sentences, which can affect the accuracy of sentiment classification.
[0176] Therefore, to avoid this situation, in another embodiment of this application, in one example, for any second sentence, the product of the features of the second sentence, the second sentiment correlation between the second sentence and the attribute features, and the first network parameters in the first graph attention network can be calculated. For each other second sentence, the above operation is performed in the same way, and then all the obtained products are summed to obtain the aggregate features of the attribute features in the second sentence.
[0177] In this context, the feature of the second sentence can be a vector, the second sentiment correlation between the second sentence and the attribute feature can be a value located in the interval (0, 1), the first network parameter can be a matrix, and so on. Thus, the resulting product can be another vector. Then, all the resulting other vectors (products) are summed. For example, the values at the same position in all the resulting other vectors (products) are added to obtain another vector, which is used as the aggregate feature of the attribute feature in the second sentence.
[0178] 12) Obtain extended features based on the degree of association between aggregated features and first sentiment to expand the features of the first sentence.
[0179] In this application, the product between the aggregated features and the degree of first sentiment association can be calculated to obtain extended features used to expand the features of the first sentence.
[0180] 13) Obtain the first extended feature based on the extended features used to expand the features of the first sentence and the features of the first sentence.
[0181] In this application, extended features obtained for expanding the features of the first sentence can be fused with the features of the first sentence. For example, the extended features can be added to the features of the first sentence. For example, if the extended features are vectors and the features of the first sentence are vectors, the values at the same positions in the extended features and the features of the first sentence can be added to obtain another vector. Then, the first extended feature can be obtained based on the other vector. For example, the other vector can be summed with the second network parameters (vectors) in the first graph attention network to obtain yet another vector. Then, the first extended feature can be obtained based on the yet another vector. For example, the yet another vector can be processed based on the hyperbolic function tanh, and the processing result can be used as the first extended feature.
[0182] Alternatively, the extended features can be fused with the features of the first sentence in other ways. This application does not limit the specific fusion method.
[0183] In step S205, the features of the first sentence are expanded based on the features of the first sentence and the features of the third sentence to obtain the second expanded features.
[0184] This step can be performed based on the second graph attention network in the attribute-level sentiment classification model. For example, the features of the first sentence and the features of the third sentence can be input into the second graph attention network in the attribute-level sentiment classification model to obtain the second extended features output by the second graph attention network.
[0185] Within the second attention network, the first step is to obtain the third sentiment correlation between the first and third sentences based on the features of the first and third sentences. Then, the second extended features are obtained based on the third sentiment correlation and the features of the third sentence.
[0186] Specifically, when determining the degree of third sentiment association between the first and third sentences based on the features of the first sentence and the features of the third sentence, the importance of the attribute feature in the first sentence can be determined based on the features of the first sentence and the attribute feature. This can be the proportion of the attribute feature in the first sentence, such as the ratio between the number of the attribute feature and the number of all attribute features in the first sentence.
[0187] For any given third sentence, the similarity between the first and third sentences can be obtained based on the features of both the first and third sentences. This process is repeated for each other third sentence, thus obtaining the similarity between the first sentence and each individual third sentence. Finally, the similarity scores between the first sentence and each individual third sentence are summed to obtain the total similarity score.
[0188] For any third sentence, the similarity between the first sentence and the third sentence can be divided by the sum of similarities to obtain the degree of third-party sentiment relevance between the first sentence and the third sentence. The same operation is performed for each other third sentence to obtain the degree of third-party sentiment relevance between the first sentence and each individual third sentence.
[0189] Specifically, when obtaining the second extended feature based on the degree of emotional relevance of the third sentence and the features of the third sentence, it can be implemented in the following way:
[0190] For any third sentence, we can calculate the product of the features of the third sentence, the degree of third sentiment association between the first sentence and the third sentence, and the first network parameters in the second graph attention network. For each other third sentence, we can perform the same operation, and then sum all the products to obtain another vector.
[0191] In this context, the features of the third sentence can be a vector, the third sentiment correlation between the first sentence and the third sentence can be a value located in the interval (0, 1), the second network parameter can be a matrix, and so on. The resulting product can be another vector. Then, all the resulting other vectors (products) are summed. For example, the values at the same position in all the resulting other vectors (products) are added to obtain another vector. Then, this other vector is summed with the second network parameter (vector) in the second graph attention network to obtain yet another vector. Then, the second extended feature is obtained based on this second vector. For example, the second vector is processed based on the hyperbolic function tanh, and the processing result is used as the second extended feature.
[0192] In this application, steps S204 and S205 can be executed simultaneously or sequentially. If they are executed sequentially, step S204 can be executed first and then step S205, or step S205 can be executed first and then step S204.
[0193] In step S206, the sentiment classification of the subject's attribute feature in the first sentence is obtained based on the first extended feature and the second extended feature.
[0194] In this step, the multi-scale detection network and normalization network in the attribute-level sentiment classification model can be used to obtain the sentiment classification of the subject's attribute feature in the first sentence based on the first extended feature and the second extended feature. For details, please refer to [link to relevant documentation]. Figure 6 The embodiments shown are not described in detail here.
[0195] In some cases, a passage often contains multiple sentences. If at least two sentences express the same sentiment classification of the same attribute of the same subject, then generally, the sentiment classification of the same attribute of the same subject expressed in at least two sentences is the same; for example, they are usually both positive or both are usually negative. Positive sentiments include liking, suitability, low price, and good quality, while negative sentiments include disliking, unsuitability, high price, and poor quality.
[0196] In another scenario, a text often contains multiple sentences, and these sentences typically express sentiment classifications regarding the same subject's attributes. Sentences that are adjacent in position within the text usually express the same sentiment classification. For example, in a text, sentence A and sentence B are adjacent. The sentiment classification of sentence A is usually the same as that of sentence B, and / or, the sentiment classifications of the same attribute of the same subject included in sentences A and B are usually the same, and / or, the sentiment classifications of different attribute features of the same subject included in sentences A and B are usually also the same, and so on.
[0197] Thus, both of the above situations will affect the sentiment classification of the attribute features of the subject in the sentence of the passage. For example, for any sentence in the passage, if it is necessary to obtain the sentiment classification of a certain attribute feature of a certain subject in that sentence, the sentiment classification of the adjacent sentences of that sentence in the passage and the sentiment classification of the attribute feature of that subject in other sentences in the passage will affect the sentiment classification of the attribute feature of that subject in that sentence.
[0198] Thus, the attribute-level sentiment classification model constructed in this application can support the following: when it is necessary to obtain the sentiment classification of the attribute features of the subject in the first sentence of a text, the electronic device can obtain the features of the first sentence and the attribute features of the subject in the first sentence; obtain the features of the second sentence, which includes the attribute features of the subject; obtain the features of the third sentence, which is adjacent to the first sentence; expand the features of the first sentence based on the features of the first sentence, the features of the second sentence, and the attribute features to obtain a first expanded feature; expand the features of the first sentence based on the features of the first sentence and the features of the third sentence to obtain a second expanded feature; and obtain the sentiment classification of the attribute features of the subject in the first sentence based on the first expanded feature and the second expanded feature; wherein the first sentence, the second sentence, and the third sentence belong to the same text.
[0199] In this way, the features of the first sentence can be enriched based on the contextual information of the first sentence. For example, at least the first and second graph attention networks in the attribute-level sentiment classification model can be used to enrich the features of the first sentence based on the contextual information of the first sentence, so that the enriched features of the first sentence can include not only the features of the first sentence itself, but also the relevant features of the second and third sentences, etc.
[0200] Thus, through this application, it is not necessary to collect a large amount of sample data for training the attribute-level sentiment classification model beforehand. In this way, even if a large amount of sample data is not used when training the attribute-level sentiment classification model, the attribute-level sentiment classification model can learn more and more important features that help determine the sentiment classification of the subject in the sentence based on the text, thereby helping to improve the accuracy of sentiment classification.
[0201] It is evident that, while ensuring the accuracy of sentiment classification, the workload of sample collection and labeling can be reduced, thereby saving labor costs.
[0202] The application scenarios for the proposed solution include, but are not limited to, product reviews and customer service.
[0203] For example, after a user purchases a product, they can leave a review. Electronic devices can obtain the sentiment classification of the user's product review to determine the user's preference for the product, and then improve the product accordingly.
[0204] For example, during the interaction between a user and an intelligent customer service representative, the user may engage in dialogue with the intelligent representative. For instance, the user may transmit dialogue text to the intelligent representative, and the electronic device can obtain the sentiment classification of the user's dialogue text to determine the user's current emotional tendency and the purpose of the user's communication with the intelligent representative, thereby enabling the intelligent representative to better provide services to the user.
[0205] In one embodiment of this application, see [link to embodiment]. Figure 6 Step S204 includes:
[0206] In step S301, multi-scale detection is performed on the first extended feature and the second extended feature to obtain the multi-scale feature corresponding to the first sentence.
[0207] This step can be implemented through the following process:
[0208] 3011. The first extended feature and the second extended feature are fused to obtain the third extended feature corresponding to the first sentence.
[0209] In this application, the first extended feature can be a vector, etc., and the second extended feature can be a vector, etc.
[0210] Therefore, in one embodiment of this application, in this step, the first extended feature and the second extended feature can be concatenated end to end to obtain a large vector, which is then used as the third extended feature.
[0211] Alternatively, in another embodiment of this application, in this step, if the scale of the first extended feature is the same as the scale of the second extended feature, the first extended feature and the second extended feature can be added together, that is, the values at the same position in the two vectors are added together to obtain a new vector, which is then used as the third extended feature.
[0212] Alternatively, in another embodiment of this application, in this step, when the scale of the first extended feature is the same as the scale of the second extended feature, the average feature between the first extended feature and the second extended feature can be calculated, that is, the average value of the values at the same position in the two vectors is calculated respectively to obtain a new vector, which is used as the third extended feature.
[0213] Of course, the first extended feature and the second extended feature can also be fused in other ways, and this application does not limit the specific fusion method.
[0214] 3012. Perform multi-scale detection on the third extended feature to obtain multiple features with different scales corresponding to the first sentence.
[0215] In this step, the third extended feature can be input into the cascaded pyramid network to obtain multiple features of different scales output by each LSTM hidden layer with different dimensions in the cascaded pyramid network. The scales of the features output by each LSTM hidden layer with different dimensions can be different.
[0216] See Figure 4A cascaded pyramid network consists of multiple cascaded LSTM hidden layers, and the dimensions of different LSTM hidden layers can be different. LSTM hidden layers include LSTM neurons, etc., and there is a sequential order among the multiple LSTM hidden layers. For example, a cascaded pyramid network includes L LSTM hidden layers, in the order of LSTM hidden layer 1, LSTM hidden layer 2, ... and LSTM hidden layer L, etc.
[0217] In any two adjacent LSTM hidden layers in a cascaded pyramid network, the input of the later LSTM hidden layer is connected to the output of the earlier LSTM hidden layer.
[0218] The output of each LSTM hidden layer is also connected to the input of the adaptive fusion network.
[0219] The input of the cascaded pyramid network includes the input of the first LSTM hidden layer, which is used to input the third extended feature.
[0220] Specifically, the third extended feature is input into the LSTM hidden layer 1 of the cascaded pyramid network. LSTM hidden layer 1 processes the third extended feature to obtain feature 1. Feature 1 is then input into LSTM hidden layer 2 and the input of the adaptive fusion network. LSTM hidden layer 2 processes feature 1 to obtain feature 2. Feature 2 is then input into LSTM hidden layer 3 and the input of the adaptive fusion network, and so on. LSTM hidden layer L processes feature L-1 output from LSTM hidden layer L-1 to obtain feature L. Feature L is then input into the adaptive fusion network.
[0221] Thus, the adaptive fusion network obtains feature 1, feature 2, ... and feature L through its input.
[0222] One approach is to leverage attribute-level sentiment classification models to enrich the features of the first sentence using contextual information. For instance, at least a multi-scale detection network within an attribute-level sentiment classification model can be used to enrich the features of the first sentence using its contextual information. This enriched feature set can include not only the features inherent to the first sentence itself, but also at least one of the following: relationships between the attribute features of the subject in the first and second sentences; relationships between the attribute features of the subject in the first and third sentences; relationships between the attribute features of the subject in the second and third sentences; relationships between the attribute features of the subject in the third and first sentences; relationships between the subject in the third and second sentences; relationships between the first and second sentences; relationships between the first and third sentences; relationships between multiple attribute features of the subject in the first sentence; relationships between multiple attribute features of the subject in the second sentence; and relationships between multiple attribute features of the subject in the third sentence. This allows for a more granular expansion and enrichment of the first sentence's features.
[0223] 3013. Fuse features at multiple scales to obtain multi-scale features.
[0224] In this application, features of different scales can all be vectors, etc.
[0225] Therefore, in one embodiment of this application, in this step, multiple features of different scales can be concatenated end to end to obtain a large vector, which is then used as a multi-scale feature.
[0226] Alternatively, in another embodiment of this application, in this step, at least some of the features with different scales can be reshaped to process the features with different scales into features with the same scale. The reshaped features with the same scale can be added together, that is, the values at the same position in the reshaped vectors with the same scale are added together to obtain a new vector, which is used as a multi-scale feature.
[0227] Alternatively, in another embodiment of this application, in this step, at least some of the features among the multiple features with different scales can be reshaped to process the multiple features with different scales into multiple features with the same scale. The average feature among the multiple features with the same scale after reshaping can be calculated, that is, the average value of the values at the same position in the multiple vectors with the same scale after reshaping can be calculated to obtain a new vector, which is used as a multi-scale feature.
[0228] Of course, other methods can also be used to fuse features of different scales. This application does not limit the specific fusion method.
[0229] In step S302, the sentiment classification of the subject's attribute feature in the first sentence is obtained based on the multi-scale features.
[0230] In this step, multi-scale features can be input into the normalization network in the attribute-level sentiment classification model to obtain the sentiment classification of the subject's attribute feature in the first sentence output by the normalization network.
[0231] Reference Figure 7 The diagram shows a structural block diagram of an embodiment of an emotion classification device according to this application, which may specifically include the following modules:
[0232] The first acquisition module 11 is used to acquire the features of the first sentence and the attribute features of the subject in the first sentence;
[0233] The second acquisition module 12 is used to acquire features of the second sentence, wherein the second sentence includes the attribute features of the subject;
[0234] The third acquisition module 13 is used to acquire features of a third sentence, which is adjacent to the first sentence;
[0235] The first extension module 14 is used to extend the features of the first sentence based on the features of the first sentence, the features of the second sentence, and the attribute features to obtain the first extended features;
[0236] The second extension module 15 is used to extend the features of the first sentence based on the features of the first sentence and the features of the third sentence to obtain the second extended features;
[0237] The fourth acquisition module 16 is used to acquire the sentiment classification of the attribute features of the subject in the first sentence based on the first extended features and the second extended features;
[0238] The first, second, and third sentences belong to the same chapter.
[0239] In one optional implementation, the fourth acquisition module includes:
[0240] The detection unit is used to perform multi-scale detection on the first extended feature and the second extended feature to obtain the multi-scale feature corresponding to the first sentence.
[0241] The first acquisition unit is used to acquire the sentiment classification based on the multi-scale features.
[0242] In one optional implementation, the detection unit includes:
[0243] The first fusion subunit is used to fuse the first extended feature with the second extended feature to obtain the third extended feature corresponding to the first sentence;
[0244] The detection subunit is used to perform multi-scale detection on the third extended feature to obtain multiple features with different scales corresponding to the first sentence.
[0245] The second fusion subunit is used to fuse the multiple features with different scales to obtain the multi-scale features.
[0246] In one optional implementation, the detection subunit is specifically used to: input the third extended feature into the cascaded pyramid network to obtain multiple features of different scales output by each LSTM hidden layer of different dimensions in the cascaded pyramid network.
[0247] In an optional implementation, the first extension module includes:
[0248] The second acquisition unit is used to acquire, based on the features of the first sentence, the features of the second sentence, and the attribute features, a first sentiment correlation degree between the first sentence and the attribute features, and a second sentiment correlation degree between the second sentence and the attribute features;
[0249] An extension unit is used to extend the features of the first sentence based on the first emotional correlation degree, the second emotional correlation degree, and the features of the second sentence to obtain the first extended features.
[0250] In one optional implementation, the second acquisition unit includes:
[0251] The first acquisition subunit is used to acquire the aggregated features of the attribute features in the second sentence based on the features of the second sentence and the second sentiment correlation degree;
[0252] The second acquisition subunit is used to acquire extended features for expanding the features of the first sentence based on the degree of correlation between the aggregated features and the first sentiment.
[0253] The third acquisition subunit is used to acquire the first extended feature based on the extended feature and the feature of the first sentence.
[0254] In an optional implementation, the second extension module includes:
[0255] The third acquisition unit is used to acquire the third sentiment association degree between the first sentence and the third sentence based on the features of the first sentence and the features of the third sentence;
[0256] The fourth acquisition unit is used to acquire the second extended feature based on the third emotional correlation degree and the features of the third sentence.
[0257] In an optional implementation, the first acquisition module includes:
[0258] The first construction unit is used to construct auxiliary interrogative sentences for the attribute features of the subject;
[0259] The fifth acquisition unit is used to acquire features of the first sentence based on the constructed auxiliary interrogative sentence and the first sentence.
[0260] In one optional implementation, the second acquisition module includes:
[0261] The second construction unit is used to construct auxiliary interrogative sentences for the attribute features of the subject;
[0262] The sixth acquisition unit is used to acquire features of the second sentence based on the constructed auxiliary interrogative sentence and the second sentence.
[0263] In one optional implementation, the third acquisition module includes:
[0264] The third construction unit is used to construct an auxiliary interrogative sentence for the attribute features of the subject when the third sentence includes the attribute features of the subject;
[0265] The seventh acquisition unit is used to acquire the features of the third sentence based on the constructed auxiliary interrogative sentence and the third sentence.
[0266] In some cases, a passage often contains multiple sentences. If at least two sentences express the same sentiment classification of the same attribute of the same subject, then generally, the sentiment classification of the same attribute of the same subject expressed in at least two sentences is the same; for example, they are usually both positive or both are usually negative. Positive sentiments include liking, suitability, low price, and good quality, while negative sentiments include disliking, unsuitability, high price, and poor quality.
[0267] In another scenario, a text often contains multiple sentences, and these sentences typically express sentiment classifications regarding the same subject's attributes. Sentences that are adjacent in position within the text usually express the same sentiment classification. For example, in a text, sentence A and sentence B are adjacent. The sentiment classification of sentence A is usually the same as that of sentence B, and / or, the sentiment classifications of the same attribute of the same subject included in sentences A and B are usually the same, and / or, the sentiment classifications of different attribute features of the same subject included in sentences A and B are usually also the same, and so on.
[0268] Thus, both of the above situations will affect the sentiment classification of the attribute features of the subject in the sentence of the passage. For example, for any sentence in the passage, if it is necessary to obtain the sentiment classification of a certain attribute feature of a certain subject in that sentence, the sentiment classification of the adjacent sentences of that sentence in the passage and the sentiment classification of the attribute feature of that subject in other sentences in the passage will affect the sentiment classification of the attribute feature of that subject in that sentence.
[0269] Thus, the attribute-level sentiment classification model constructed in this application can support the following: when it is necessary to obtain the sentiment classification of the attribute features of the subject in the first sentence of a text, the electronic device can obtain the features of the first sentence and the attribute features of the subject in the first sentence; obtain the features of the second sentence, which includes the attribute features of the subject; obtain the features of the third sentence, which is adjacent to the first sentence; expand the features of the first sentence based on the features of the first sentence, the features of the second sentence, and the attribute features to obtain a first expanded feature; expand the features of the first sentence based on the features of the first sentence and the features of the third sentence to obtain a second expanded feature; and obtain the sentiment classification of the attribute features of the subject in the first sentence based on the first expanded feature and the second expanded feature; wherein the first sentence, the second sentence, and the third sentence belong to the same text.
[0270] In this way, the features of the first sentence can be enriched based on the contextual information of the first sentence. For example, at least the first and second graph attention networks in the attribute-level sentiment classification model can be used to enrich the features of the first sentence based on the contextual information of the first sentence, so that the enriched features of the first sentence can include not only the features of the first sentence itself, but also the relevant features of the second and third sentences, etc.
[0271] Thus, through this application, it is not necessary to collect a large amount of sample data for training the attribute-level sentiment classification model beforehand. In this way, even if a large amount of sample data is not used when training the attribute-level sentiment classification model, the attribute-level sentiment classification model can learn more and more important features that help determine the sentiment classification of the subject in the sentence based on the text, thereby helping to improve the accuracy of sentiment classification.
[0272] It is evident that, while ensuring the accuracy of sentiment classification, the workload of sample collection and labeling can be reduced, thereby saving labor costs.
[0273] This application also provides a non-volatile readable storage medium storing one or more modules (programs). When these modules are applied to a device, they enable the device to execute the instructions for the method steps in this application.
[0274] This application provides one or more machine-readable media storing instructions that, when executed by one or more processors, cause an electronic device to perform one or more of the methods described in the above embodiments. In this application, the electronic device includes servers, gateways, sub-devices, etc., with the sub-devices being devices such as Internet of Things (IoT) devices.
[0275] Embodiments of this disclosure can be implemented as an apparatus with any suitable hardware, firmware, software, or any combination thereof, configured as desired. This apparatus may include electronic devices such as servers (clusters) and terminal devices such as IoT devices.
[0276] Figure 8 An exemplary apparatus 1300 is schematically shown that can be used to implement the various embodiments described in this application.
[0277] In one embodiment, Figure 8 An exemplary device 1300 is shown, which includes one or more processors 1302, a control module (chipset) 1304 coupled to at least one of the processors 1302, a memory 1306 coupled to the control module 1304, a non-volatile memory (NVM) / storage device 1308 coupled to the control module 1304, one or more input / output devices 1310 coupled to the control module 1304, and a network interface 1312 coupled to the control module 1306.
[0278] Processor 1302 may include one or more single-core or multi-core processors, and processor 1302 may include any combination of general-purpose processors or special-purpose processors (e.g., graphics processors, application processors, baseband processors, etc.). In some embodiments, device 1300 can serve as a server device such as a gateway as described in the embodiments of this application.
[0279] In some embodiments, apparatus 1300 may include one or more computer-readable media (e.g., memory 1306 or NVM / storage device 1308) having instructions 1314 and one or more processors 1302 that are combined with the one or more computer-readable media and configured to execute instructions 1314 to implement modules and thus perform the actions described in this disclosure.
[0280] In one embodiment, the control module 1304 may include any suitable interface controller to provide any suitable interface to at least one of the processors 1302 and / or any suitable device or component communicating with the control module 1304.
[0281] The control module 1304 may include a memory controller module to provide an interface to the memory 1306. The memory controller module may be a hardware module, a software module, and / or a firmware module.
[0282] Memory 1306 may be used, for example, to load and store data and / or instructions 1314 for device 1300. In one embodiment, memory 1306 may include any suitable volatile memory, such as suitable DRAM. In some embodiments, memory 1306 may include double data rate type quad synchronous dynamic random access memory (DDR4 SDRAM).
[0283] In one embodiment, the control module 1304 may include one or more input / output controllers to provide interfaces to the NVM / storage device 1308 and (one or more) input / output devices 1310.
[0284] For example, NVM / storage device 1308 may be used to store data and / or instructions 1314. NVM / storage device 1308 may include any suitable non-volatile memory (e.g., flash memory) and / or may include any suitable (one or more) non-volatile storage devices (e.g., one or more hard disk drives (HDDs), one or more optical disc drives (CDs), and / or one or more digital universal optical disc (DVD) drives).
[0285] NVM / storage device 1308 may include storage resources that are physically part of a device on which device 1300 is mounted, or that can be accessed by the device without needing to be part of the device. For example, NVM / storage device 1308 may be accessed via a network via one or more input / output devices 1310.
[0286] One or more input / output devices 1310 may provide an interface for device 1300 to communicate with any other suitable device. Input / output devices 1310 may include communication components, pinyin components, sensor components, etc. Network interface 1312 may provide an interface for device 1300 to communicate via one or more networks. Device 1300 may wirelessly communicate with one or more components of a wireless network according to any of one or more wireless network standards and / or protocols, such as accessing wireless networks based on communication standards, such as WiFi, 2G, 3G, 4G, 5G, etc., or combinations thereof.
[0287] In one embodiment, at least one of the processors 1302 may be logically packaged with one or more controllers (e.g., memory controller modules) of the control module 1304. In one embodiment, at least one of the processors 1302 may be logically packaged with one or more controllers of the control module 1304 to form a system-in-package (SiP). In one embodiment, at least one of the processors 1302 may be integrated with the logic of one or more controllers of the control module 1304 on the same die. In one embodiment, at least one of the processors 1302 may be integrated with the logic of one or more controllers of the control module 1304 on the same die to form a system-on-a-chip (SoC).
[0288] In various embodiments, device 1300 may be, but is not limited to, a server, desktop computing device, or mobile computing device (e.g., laptop computing device, handheld computing device, tablet computer, netbook, etc.). In various embodiments, device 1300 may have more or fewer components and / or different architectures. For example, in some embodiments, device 1300 includes one or more cameras, a keyboard, a liquid crystal display (LCD) screen (including a touchscreen display), a non-volatile memory port, multiple antennas, a graphics chip, an application-specific integrated circuit (ASIC), and a speaker.
[0289] This application provides an electronic device, including: one or more processors; and one or more machine-readable media having instructions stored thereon, which, when executed by the one or more processors, cause the electronic device to perform one or more of the emotion classification methods described in this application.
[0290] As the device embodiment is basically similar to the method embodiment, the description is relatively simple, and relevant parts can be found in the description of the method embodiment.
[0291] The various embodiments in this specification are described in a progressive manner, with each embodiment focusing on the differences from other embodiments. The same or similar parts between the various embodiments can be referred to each other.
[0292] This application describes embodiments with reference to flowchart illustrations and / or block diagrams of methods, terminal devices (systems), and computer program products according to embodiments of this application. It should be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable attribute-level emotion classification terminal device to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable attribute-level emotion classification terminal device, generate instructions for implementing the flowchart illustrations and / or block diagrams. Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.
[0293] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable attribute-level emotion classification terminal device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including an instruction means, the instruction means being implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.
[0294] These computer program instructions can also be loaded onto a computer or other programmable attribute-level emotion classification terminal device, causing a series of operational steps to be executed on the computer or other programmable terminal device to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable terminal device for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.
[0295] Although preferred embodiments of the present application have been described, those skilled in the art, upon learning the basic inventive concept, can make other changes and modifications to these embodiments. Therefore, the appended claims are intended to be interpreted as including both the preferred embodiments and all changes and modifications falling within the scope of the embodiments of the present application.
[0296] Finally, it should be noted that in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or terminal device that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or terminal device. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or terminal device that includes said element.
[0297] The above provides a detailed description of the emotion classification method and apparatus provided in this application. Specific examples have been used to illustrate the principles and implementation methods of this application. The description of the above embodiments is only for the purpose of helping to understand the method and core ideas of this application. At the same time, for those skilled in the art, there will be changes in the specific implementation methods and application scope based on the ideas of this application. Therefore, the content of this specification should not be construed as a limitation of this application.
Claims
1. A method of sentiment classification, characterized by, The method includes: Obtain the features of the first sentence, as well as the attribute features of the subject in the first sentence; Obtain the features of the second sentence, which includes the attribute features of the subject; Obtain the features of the third sentence, which is adjacent to the first sentence; The features of the first sentence are extended based on the features of the first sentence, the features of the second sentence, and the attribute features to obtain the first extended features; this includes: extending the features of the first sentence based on the features of the first sentence, the features of the second sentence, and the attribute features using a first graph attention network to obtain the first extended features; The features of the first sentence are extended based on the features of the first sentence and the features of the third sentence to obtain the second extended features; this includes: extending the features of the first sentence based on the features of the first sentence and the features of the third sentence using a second graph attention network to obtain the second extended features; Sentiment classification of the attribute features of the subject in the first sentence is obtained based on the first extended feature and the second extended feature; including: performing multi-scale detection on the first extended feature and the second extended feature to obtain multi-scale features corresponding to the first sentence; and obtaining the sentiment classification based on the multi-scale features. The first, second, and third sentences belong to the same chapter.
2. The method of claim 1, wherein, The step of performing multi-scale detection on the first extended feature and the second extended feature to obtain the multi-scale features corresponding to the first sentence includes: The first extended feature is fused with the second extended feature to obtain the third extended feature corresponding to the first sentence; Multi-scale detection is performed on the third extended feature to obtain multiple features with different scales corresponding to the first sentence; The multi-scale features are obtained by fusing the features of multiple different scales.
3. The method of claim 2, wherein, The multi-scale detection of the third extended feature yields multiple features of different scales corresponding to the first sentence, including: The third extended feature is input into the cascaded pyramid network to obtain multiple features of different scales output by each LSTM hidden layer of different dimensions in the cascaded pyramid network.
4. The method of claim 1, wherein, The step of expanding the features of the first sentence based on the features of the first sentence, the features of the second sentence, and the attribute features to obtain the first expanded feature includes: Based on the features of the first sentence, the features of the second sentence, and the attribute features, a first sentiment correlation degree between the first sentence and the attribute features is obtained, and a second sentiment correlation degree between the second sentence and the attribute features is obtained; The features of the first sentence are expanded based on the first emotional relevance, the second emotional relevance, and the features of the second sentence to obtain the first expanded features.
5. The method of claim 4, wherein, The step of expanding the features of the first sentence based on the first emotional relevance, the second emotional relevance, and the features of the second sentence to obtain the first expanded features includes: Based on the features of the second sentence and the degree of sentiment association, the aggregated features of the attribute features in the second sentence are obtained; Based on the degree of correlation between the aggregated features and the first sentiment, extended features are obtained to expand the features of the first sentence; The first extended feature is obtained based on the extended feature and the feature of the first sentence.
6. The method according to claim 1, characterized in that, The step of expanding the features of the first sentence based on the features of the first sentence and the features of the third sentence to obtain the second expanded features includes: Based on the features of the first sentence and the features of the third sentence, obtain the third sentiment correlation degree between the first sentence and the third sentence; The second extended feature is obtained based on the degree of third emotional association and the features of the third sentence.
7. The method according to claim 1, characterized in that, The process of obtaining the features of the first sentence includes: Construct auxiliary interrogative sentences for the attribute features of the subject; The features of the first sentence are obtained by comparing the constructed auxiliary question with the first sentence.
8. The method according to claim 1, characterized in that, The acquisition of features of the second sentence includes: Construct auxiliary interrogative sentences for the attribute features of the subject; The features of the second sentence are obtained by comparing the constructed auxiliary question with the second sentence.
9. The method according to claim 1, characterized in that, The features of the third sentence are obtained as follows: If the third sentence includes the attribute features of the subject, construct an auxiliary interrogative sentence for the attribute features of the subject; The features of the third sentence are obtained based on the constructed auxiliary interrogative sentence and the third sentence.
10. An emotion classification device, characterized in that, The device includes: The first acquisition module is used to acquire the features of the first sentence and the attribute features of the subject in the first sentence; The second acquisition module is used to acquire features of the second sentence, wherein the second sentence includes the attribute features of the subject; The third acquisition module is used to acquire features of a third sentence, which is adjacent to the first sentence. The first extension module is used to extend the features of the first sentence based on the features of the first sentence, the features of the second sentence, and the attribute features to obtain the first extended features; including: extending the features of the first sentence based on the features of the first sentence, the features of the second sentence, and the attribute features through a first graph attention network to obtain the first extended features; The second extension module is used to extend the features of the first sentence based on the features of the first sentence and the features of the third sentence to obtain second extended features; including: extending the features of the first sentence based on the features of the first sentence and the features of the third sentence through a second graph attention network to obtain the second extended features; The fourth acquisition module is used to acquire the sentiment classification of the attribute features of the subject in the first sentence based on the first extended features and the second extended features; the fourth acquisition module includes: a detection unit, used to perform multi-scale detection on the first extended features and the second extended features to obtain multi-scale features corresponding to the first sentence; and a first acquisition unit, used to acquire the sentiment classification based on the multi-scale features. The first, second, and third sentences belong to the same chapter.
11. The apparatus according to claim 10, characterized in that, The detection unit includes: The first fusion subunit is used to fuse the first extended feature with the second extended feature to obtain the third extended feature corresponding to the first sentence; The detection subunit is used to perform multi-scale detection on the third extended feature to obtain multiple features with different scales corresponding to the first sentence. The second fusion subunit is used to fuse the multiple features with different scales to obtain the multi-scale features.
12. The apparatus according to claim 11, characterized in that, The detection subunit is specifically used to: input the third extended feature into the cascaded pyramid network to obtain multiple features of different scales output by each LSTM hidden layer of different dimensions in the cascaded pyramid network.
13. The apparatus according to claim 10, characterized in that, The first extension module includes: The second acquisition unit is used to acquire, based on the features of the first sentence, the features of the second sentence, and the attribute features, a first sentiment correlation degree between the first sentence and the attribute features, and a second sentiment correlation degree between the second sentence and the attribute features; An extension unit is used to extend the features of the first sentence based on the first emotional correlation degree, the second emotional correlation degree, and the features of the second sentence to obtain the first extended features.
14. The apparatus according to claim 13, characterized in that, The second acquisition unit includes: The first acquisition subunit is used to acquire the aggregated features of the attribute features in the second sentence based on the features of the second sentence and the second sentiment correlation degree; The second acquisition subunit is used to acquire extended features for expanding the features of the first sentence based on the degree of correlation between the aggregated features and the first sentiment. The third acquisition subunit is used to acquire the first extended feature based on the extended feature and the feature of the first sentence.
15. The apparatus according to claim 10, characterized in that, The second extension module includes: The third acquisition unit is used to acquire the third sentiment association degree between the first sentence and the third sentence based on the features of the first sentence and the features of the third sentence; The fourth acquisition unit is used to acquire the second extended feature based on the third emotional correlation degree and the features of the third sentence.
16. The apparatus according to claim 10, characterized in that, The first acquisition module includes: The first construction unit is used to construct auxiliary interrogative sentences for the attribute features of the subject; The fifth acquisition unit is used to acquire features of the first sentence based on the constructed auxiliary interrogative sentence and the first sentence.
17. The apparatus according to claim 10, characterized in that, The second acquisition module includes: The second construction unit is used to construct auxiliary interrogative sentences for the attribute features of the subject; The sixth acquisition unit is used to acquire features of the second sentence based on the constructed auxiliary interrogative sentence and the second sentence.
18. The apparatus according to claim 10, characterized in that, The third acquisition module includes: The third construction unit is used to construct an auxiliary interrogative sentence for the attribute features of the subject when the third sentence includes the attribute features of the subject; The seventh acquisition unit is used to acquire the features of the third sentence based on the constructed auxiliary interrogative sentence and the third sentence.
19. An electronic device, characterized in that, The electronic device includes: processor; and A memory having executable code stored thereon, which, when executed, causes the processor to perform the sentiment classification method as described in any one of claims 1-9.
20. One or more machine-readable media having executable code stored thereon, which, when executed, causes a processor to perform the sentiment classification method as described in any one of claims 1-9.
Citation Information
Patent Citations
Multiple features fused bidirectional recurrent neural network fine granularity opinion mining method
CN107168945A
Corpus labeling method and device
CN109683773A