Semantic emotion recognition method, device, equipment and storage medium
By obtaining the global semantic information and word vector matrix of the text to be identified, combining word semantics and sentence semantics, the problem of low accuracy of emotion recognition in the prior art is solved, and higher recognition accuracy is achieved.
Patent Information
- Application Number
- CN202011596697.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-12-29
- Publication Date
- 2024-11-12
- Estimated Expiration
- 2040-12-29
AI Technical Summary
In the prior art, semantic emotions classification cannot be distinguished by using simple statistical features, resulting in the problem of low accuracy of emotion recognition.
By obtaining the global semantic information of the text to be identified, the word vector matrix is determined using the pre-trained word vector model, the similarity between the word vector and the preset emotional words is calculated, and the emotion category is determined in combination with the semantic vector, considering word semantics, phrase semantics and sentences Semantics.
It improves the accuracy of emotion recognition and can more effectively distinguish emotional expressions from different syntactics.
Smart Images

Figure CN112613324B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of semantic recognition technology, and in particular to a semantic emotion recognition method, device, equipment and storage medium. Background Art
[0002] With the development of the Internet and the popularity of social networks and online shopping, users have left a large amount of text data on various online platforms. A large part of the text is subjective and expresses the user's emotions towards specific entities, events or themselves.
[0003] At present, in order to identify semantic emotions, related technologies extract term frequency-inverse document frequency (tf-idf) features from texts, and then use machine learning classifiers to identify emotion categories. However, the words in texts are not just a pile of words, and different syntaxes will result in completely different emotional expressions. The related technologies use simple statistical features to classify emotions and cannot distinguish different syntaxes, which will result in unsatisfactory results in low accuracy in the final recognition of emotions. Summary of the invention
[0004] In order to overcome the problem in the related art that emotion classification using simple statistical features cannot distinguish different syntaxes, resulting in low accuracy in emotion recognition, the present application provides a semantic emotion recognition method, apparatus, device and storage medium.
[0005] According to a first aspect of the present application, a semantic emotion recognition method is provided, comprising:
[0006] Get the text to be recognized;
[0007] Extracting global semantic information of the text to be recognized to obtain a first semantic vector;
[0008] Determine the word vector matrix of the text to be recognized by using a pre-trained word vector model;
[0009] Determine a second semantic vector according to the word vector matrix;
[0010] Calculating the similarity between the word vector of each word in the text to be recognized and the word vector of the preset emotional words according to the word vector matrix, and determining all the calculated similarities as the third semantic vector;
[0011] The emotion category to which the to-be-recognized text belongs is determined according to the first semantic vector, the second semantic vector, and the third semantic vector.
[0012] In an optional embodiment, extracting the global semantic information of the text to be recognized to obtain a first semantic vector includes:
[0013] Adding a preset symbol to the text to be recognized;
[0014] Converting the global semantic information of the text to be recognized with preset symbols added into a text vector;
[0015] Obtaining a position vector of the preset symbol according to the position of the preset symbol in the text to be recognized;
[0016] The text vector, the position vector and the preset word vector of the preset symbol are fused to obtain a first semantic vector.
[0017] In an optional embodiment, the determining the word vector matrix of the to-be-recognized text using a pre-trained word vector model includes:
[0018] Segmenting the text to be recognized using a preset segmentation method to obtain at least one word of the text to be recognized;
[0019] Determine the word vector of each of the words through a pre-trained word vector model;
[0020] A word vector matrix of the text to be recognized is obtained based on the word vectors of each of the words.
[0021] In an optional embodiment, determining the second semantic vector according to the word vector matrix includes:
[0022] Inputting the word vector matrix into the pre-trained first model, and using convolution kernels of different sizes to extract the semantic features of the phrase according to the correlation between adjacent word vectors;
[0023] Perform a maximum pooling operation on the semantic features of each phrase extracted by the convolution kernel to obtain the maximum feature of the semantic features of each phrase;
[0024] Perform an average pooling operation on the semantic features of each phrase extracted by each convolution kernel to obtain the average features of the semantic features of each phrase;
[0025] All maximum features and average features are concatenated to obtain the second semantic vector.
[0026] In an optional embodiment, the step of calculating the similarity between the word vector of each word in the to-be-recognized text and the word vector of a preset emotional word according to the word vector matrix, and determining all the calculated similarities as a third semantic vector, includes:
[0027] Input the word vector matrix into the pre-trained second model, calculate the similarity between each word vector in the word vector matrix and the word vector of the preset emotional words, and obtain a similarity matrix;
[0028] Performing a maximum pooling operation on the similarity matrix to obtain a first vector;
[0029] Performing an average pooling operation on the similarity matrix to obtain a second vector;
[0030] The first vector and the second vector are determined as the third semantic vector.
[0031] In an optional embodiment, determining the emotion category to which the to-be-recognized text belongs according to the first semantic vector, the second semantic vector, and the third semantic vector includes:
[0032] splicing the first semantic vector, the second semantic vector and the third semantic vector according to a preset splicing method to obtain a splicing vector;
[0033] The concatenated vector is input into a pre-trained classification model to determine the emotion category to which the text to be recognized belongs.
[0034] According to a second aspect of the present application, a semantic emotion recognition device is provided, the device comprising:
[0035] An acquisition module is used to acquire the text to be recognized;
[0036] An extraction module, used for extracting global semantic information of the text to be recognized to obtain a first semantic vector;
[0037] A first determination module, used to determine the word vector matrix of the text to be recognized by using a pre-trained word vector model;
[0038] A second determination module, used to determine a second semantic vector according to the word vector matrix;
[0039] A third determination module is used to calculate the similarity between the word vector of each word in the text to be recognized and the word vector of the preset emotional words according to the word vector matrix, and determine all the calculated similarities as a third semantic vector;
[0040] The fourth determination module is used to determine the emotion category to which the to-be-recognized text belongs according to the first semantic vector, the second semantic vector and the third semantic vector.
[0041] In an optional embodiment, the extraction module includes:
[0042] An adding unit, used for adding a preset symbol to the text to be recognized;
[0043] A conversion unit, used for converting the global semantic information of the text to be recognized with the preset symbols added thereto into a text vector;
[0044] A first determining unit, configured to obtain a position vector of the preset symbol according to the position of the preset symbol in the text to be recognized;
[0045] A fusion unit is used to fuse the text vector, the position vector and the preset word vector of the preset symbol to obtain a first semantic vector.
[0046] In an optional embodiment, the first determining module includes:
[0047] A word segmentation unit, used to segment the text to be recognized using a preset word segmentation method to obtain at least one word of the text to be recognized;
[0048] A second determining unit, configured to determine a word vector of each of the words through a pre-trained word vector model;
[0049] A generating unit is used to obtain a word vector matrix of the text to be recognized based on the word vectors of each of the words.
[0050] In an optional embodiment, the second determining module includes:
[0051] An extraction unit, used to input the word vector matrix into a pre-trained first model, and extract the semantic features of the phrase according to the correlation between adjacent word vectors using convolution kernels of different sizes;
[0052] The first pooling unit is used to perform a maximum pooling operation on the semantic features of each phrase extracted by the convolution kernel to obtain the maximum feature of the semantic features of each phrase;
[0053] The second pooling unit is used to perform an average pooling operation on the semantic features of each phrase extracted by each convolution kernel to obtain the average feature of the semantic features of each phrase;
[0054] The first concatenation unit is used to concatenate all the maximum features and the average features to obtain the second semantic vector.
[0055] In an optional embodiment, the third determining module includes:
[0056] A calculation unit, used for inputting the word vector matrix into the pre-trained second model, calculating the similarity between each word vector in the word vector matrix and the word vector of the preset emotional words, and obtaining a similarity matrix;
[0057] A third pooling unit, used for performing a maximum pooling operation on the similarity matrix to obtain a first vector;
[0058] A fourth pooling unit, used for performing an average pooling operation on the similarity matrix to obtain a second vector;
[0059] The third determining unit is configured to determine the first vector and the second vector as the third semantic vector.
[0060] In an optional embodiment, the fourth determining unit includes:
[0061] A second splicing unit, configured to splice the first semantic vector, the second semantic vector and the third semantic vector in a preset splicing manner to obtain a splicing vector;
[0062] The fourth determining unit is used to input the concatenated vector into a pre-trained classification model to determine the emotion category to which the text to be recognized belongs.
[0063] According to a third aspect of the present application, there is provided a semantic emotion recognition device, comprising: at least one processor and a memory;
[0064] The processor is used to execute the semantic emotion recognition program stored in the memory to implement the semantic emotion recognition method described in the first aspect of the present application.
[0065] According to the fourth aspect of the present application, a storage medium is provided, characterized in that the storage medium stores one or more programs, and when the one or more programs are executed, the semantic emotion recognition method described in the first aspect of the present application is implemented.
[0066] The technical solution provided by the present application may include the following beneficial effects: the technical solution of the present application first obtains the text to be recognized, then extracts the global semantic information of the text to be recognized, obtains the first semantic vector, and then uses the pre-trained word vector model to determine the word vector matrix of the text to be recognized, and then determines the second semantic vector according to the word vector matrix, calculates the similarity between the word vector of each word in the text to be recognized and the word vector of the preset emotional words according to the word vector matrix, and determines all the calculated similarities as the third semantic vector, and finally determines the emotional category to which the text to be recognized belongs according to the first semantic vector, the second semantic vector and the third semantic vector. In this way, the emotional category of the text to be recognized can be determined according to the global semantic information of the text to be recognized and the word vector matrix of the text to be recognized, which takes into account the word semantics, phrase semantics and sentence semantic information of the text to be recognized, thereby improving the accuracy of emotion recognition.
[0067] It should be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present application. BRIEF DESCRIPTION OF THE DRAWINGS
[0068] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.
[0069] Figure 1 is a flowchart of a semantic emotion recognition method provided by an embodiment of the present application;
[0070] Figure 2 is a schematic diagram of a process for obtaining a first semantic vector provided by an embodiment of the present application;
[0071] Figure 3 It is a schematic diagram of a process for determining a word vector matrix provided by an embodiment of the present application;
[0072] Figure 4 is a schematic diagram of a process for determining a second semantic vector provided by an embodiment of the present application;
[0073] Figure 5 is a schematic diagram of a process for determining a third semantic vector provided by an embodiment of the present application;
[0074] Figure 6 It is a flowchart of determining the emotion category to which a text to be recognized belongs, provided by an embodiment of the present application;
[0075] Figure 7 is a structural schematic diagram of a semantic emotion recognition device provided by another embodiment of the present application;
[0076] Figure 8 It is a structural diagram of a semantic emotion recognition device provided by another embodiment of the present application. DETAILED DESCRIPTION
[0077] Exemplary embodiments will be described in detail herein, examples of which are shown in the accompanying drawings. When the following description refers to the drawings, the same numbers in different drawings represent the same or similar elements unless otherwise indicated. The implementations described in the following exemplary embodiments do not represent all implementations consistent with the present application. Instead, they are merely examples of devices and methods consistent with some aspects of the present application as detailed in the appended claims.
[0078] With the development of the Internet and the popularity of social networks and online shopping, users have left a large amount of text data on various online platforms. A large part of the text is subjective and expresses the user's emotions towards a specific entity, event or themselves. Classic sentiment analysis mainly sets sentiment labels as three polarities: positive, negative and neutral. A more fine-grained classification method, namely emotion classification, focuses on the emotions experienced by people in their daily lives, including happiness, anger, sadness, etc.
[0079] Automatic mining and analysis of emotional states in massive texts can be widely used in fields such as public opinion analysis, advertising placement, or conversational robot design. When facing public emergencies, timely analysis of netizens' emotions can provide real social public opinion. Early sentiment analysis methods were based on dictionaries and rules, but they were usually complex to maintain and difficult to expand. Later, in the context of the big data era, extracting semantic information from text and using machine learning methods to classify emotions became the mainstream method. A typical method is to extract tf-idf features from text and then use machine learning classifiers to identify emotion categories. However, the words in a sentence are not just a pile of words. Different syntax will bring completely different emotional expressions. Some simple statistical features are not ideal for text emotion classification.
[0080] See also Figure 1 , Figure 1 It is a flowchart of a semantic emotion recognition method provided by an embodiment of the present application.
[0081] like Figure 1 As shown, the semantic emotion recognition method provided by this embodiment may include:
[0082] Step S101: Obtain text to be recognized.
[0083] In this step, the text to be recognized can be obtained by crawling, for example, crawling all text materials related to a certain event on the Internet, wherein the text materials can include but are not limited to articles, dynamics, comments, etc. published on the Internet. It should be noted that the text materials may include multiple texts to be recognized. For the sake of convenience, this embodiment only describes the emotion recognition process of one of the texts to be recognized.
[0084] Step S102: extract global semantic information of the text to be recognized to obtain a first semantic vector.
[0085] It should be noted that in order to make the first semantic vector have the characteristics of the global semantic information of the text to be recognized, in this step, the text to be recognized can be directly input into a pre-trained model, the output of which can reflect the global semantic information of the text to be recognized, such as the Bert model. The following takes the Bert model as an example to illustrate the process of obtaining the first semantic vector. For details, please refer to Figure 2 , Figure 2 It is a schematic diagram of a process of obtaining a first semantic vector provided by an embodiment of the present application.
[0086] like Figure 2 As shown, the flowchart of the first semantic vector provided by this embodiment may include:
[0087] Step S201: adding preset symbols to the text to be recognized.
[0088] It should be noted that a preset symbol is a symbol that has no textual meaning and is set in advance, such as the [CLS] symbol. The specific location of addition can be set according to needs. In order not to affect the correlation between each character / word within the text to be recognized, the preset symbol can be added before the text to be recognized.
[0089] In a specific example, if the text is "I came to xx University in xx area", taking the preset symbol as the [CLS] symbol as an example, after adding the preset symbol, the text to be recognized with the preset symbol becomes "[CLS] I came to xx University in xx area".
[0090] Step S202: converting the global semantic information of the text to be recognized with the preset symbols added into a text vector.
[0091] It should be noted that the process of converting the text to be recognized into a text vector in this step can refer to the relevant technology and will not be repeated here. In this step, the text vector is used to characterize the global semantic information of the text.
[0092] Step S203: obtaining a position vector of the preset symbol according to the position of the preset symbol in the text to be recognized.
[0093] Since the preset symbol will have its own position in the text to be recognized, the position vector of the preset symbol can be obtained based on the position. It should be noted that the specific process of obtaining the position vector of a character or word based on the position of the character or word in the text can refer to the relevant technology and will not be repeated here.
[0094] Step S204: Fusing the text vector, the position vector and the word vector of the preset symbol to obtain a first semantic vector.
[0095] In the Bert model, the text vector, the position vector and the word vector of the preset symbol are fused to obtain the first semantic vector, wherein the word vector of the preset symbol refers to the word vector corresponding to the preset symbol. Since the preset symbol will not change during the entire emotion recognition process, a word vector can be pre-set for the preset symbol to facilitate fusion with the text vector and the position vector.
[0096] In the entire working process of the Bert model, each word in the recognized text will actually be treated as a corresponding vector. Taking "I came to xx University in xx area" as an example, after adding the preset symbol, it becomes "[CLS] I came to xx University in xx area". Then, after adding the preset symbol, the text to be recognized includes "[CLS]", "I", "come", "xx area", and "xx University". Then, for these words, a vector will be generated accordingly. Compared with other words in the text, this symbol without obvious semantic information ([CLS]) will more "fairly" integrate the semantic information of each word in the text, and can be used to better represent the semantics of the sentence. Therefore, the vector with the preset symbol can be used as the first semantic vector.
[0097] Step S103: Determine the word vector matrix of the text to be recognized using the pre-trained word vector model.
[0098] See also Figure 3 , Figure 3 It is a flowchart of determining a word vector matrix provided by an embodiment of the present application.
[0099] like Figure 3 As shown, the process of determining the word vector matrix provided in this embodiment may include:
[0100] Step S301: Segment the text to be recognized using a preset segmentation method to obtain at least one word of the text to be recognized.
[0101] In this step, the preset word segmentation method can be but not limited to the jieba word segmentation method, also known as the "stammering" word segmentation method, which can support three word segmentation modes: precise mode (trying to cut the sentence most accurately, suitable for text analysis), full mode (quickly scanning all the words that can be formed into words in the sentence) and search engine mode (on the basis of the precise mode, long words are segmented again to improve the recall rate). In this step, the corresponding mode can be adopted according to the needs. In an example, for example, the precise mode can be adopted. For the data text "I came to xx area xx university", after using the jieba word segmentation method, "I / came / xx area / xx university" is obtained, where " / " is a word segmentation mark, that is, using the jieba word segmentation method, "I came to xx area xx university" will be segmented into the four words: "I", "come", "xx area", and "xx university".
[0102] Step S302: Determine the word vector of each word through the pre-trained word vector model.
[0103] Based on the word segmentation result of step S301, this step will determine the index of each word obtained by the word segmentation in step S301 according to the mapping relationship between the words in the preset dictionary and the index. It should be noted that the preset dictionary is a pre-set set containing all words that may be involved, and for each word in the dictionary, a corresponding index will be set, which can be a number composed of numbers or letters. In this embodiment, a number composed of numbers is preferred.
[0104] In a specific example, still based on the word segmentation result in step S301, in step S301, the four words "I", "came", "xx area", and "xx university" are output. In the preset dictionary, the index of "I" is "1", the index of "came" is "3", the index of "xx area" is "2", and the index of "xx university" is "5".
[0105] Each data text is represented by an index to obtain an initial vector of each data text. Specifically, each word is represented by its index, and the index of each word is sorted according to the order of each word in the data text, so that the data text can be represented in an indexed manner, that is, the initial vector of the data text.
[0106] In a specific example, the initial vector of the data text "I came to xx university in xx area" is (1, 3, 2, 5).
[0107] In addition, since the length of each data text may be different, and the vector length of the model input must be consistent, after obtaining the initial vector, each initial vector can be represented as a vector of preset length according to the preset vector length representation rule. In a specific example, the length of each data text can be set to a fixed value, which can be represented as max_length. At this time, it may be encountered that the vector length does not reach the fixed value or the vector length is greater than the fixed value. If the vector length does not reach the fixed value, 0 (or other index numbers without index meaning) can be added in front of the initial index until the length reaches the fixed value; if the vector length is greater than the fixed value, the part exceeding the fixed value can be truncated.
[0108] In a specific example, if max_length=5, the vector (1, 3, 2, 5) obtained in the previous steps has a length less than 5. In this case, add "0" in front of "1" to get (0, 1, 3, 2, 5); if max_length=3, the vector (1, 3, 2, 5) obtained in the previous steps has a length greater than 3. In this case, delete the part exceeding the fixed value to get (1, 3, 2). Based on the above operations, the data text can be mapped to vectors of equal length. After obtaining vectors of equal length, the word vector corresponding to each word is obtained according to the pre-trained word vector model.
[0109] Step S303: Obtain a word vector matrix of the text to be recognized based on the word vector of each word.
[0110] Since there are multiple words in the text to be recognized, there will be multiple word vectors. The length of the word vector can also be set to a fixed value, such as Embedding_size. By arranging the word vectors of each word in a certain order, a vector matrix can be obtained. For example, by arranging the word vectors of each word from top to bottom, a vector matrix of the text to be recognized with a size of (max_length, Embedding_size) can be obtained.
[0111] Step S104: determine a second semantic vector according to the word vector matrix.
[0112] See also Figure 4 , Figure 4 It is a flowchart of determining a second semantic vector provided by an embodiment of the present application.
[0113] like Figure 4 As shown, the process of determining the second semantic vector provided by this embodiment may include:
[0114] Step S401: input the word vector matrix into the pre-trained first model, and use convolution kernels of different sizes to extract the semantic features of the phrase according to the correlation between adjacent word vectors.
[0115] Specifically, convolution kernels of different sizes can be used. Generally, the length of the convolution kernel will remain consistent. The main difference lies in the height of the convolution kernel, which is similar to n-gram. Different n-gram semantic features, that is, phrase semantic features, can be obtained by using different convolution kernels.
[0116] Taking n-gram with n=2, 3, and 4 as an example, and taking an 8×8 word vector matrix as an example, when n=2, the height of the convolution kernel is 2 and the length is 8. The convolution starts from the first row of the vector matrix, that is, the first and second rows are convolved to get the first value, and then the second and third rows are convolved to get the second value, and so on, until the seventh and eighth rows are convolved to get the seventh value, and the convolution process with n=2 ends.
[0117] When n is 3, the first, second and third rows are convolved to obtain the first value, and the convolution process ends when the sixth, seventh and eighth rows are convolved to obtain the sixth value. The same is true when n is 4, which will not be repeated here.
[0118] The convolution process can be implemented using TextCNN. Since different channels are set in TextCNN, when n is equal to 2, each channel will obtain a phrase semantic feature with 7 values. Similarly, when n is 3, each channel will obtain a phrase semantic feature with 6 values, and when n is 4, each channel will obtain a phrase semantic feature with 5 values.
[0119] Step S402: Perform a maximum pooling operation on the semantic features of each phrase extracted by the convolution kernel to obtain the maximum feature of the semantic features of each phrase.
[0120] Step S403: Perform an average pooling operation on the semantic features of each phrase extracted by the convolution kernel to obtain the average feature of the semantic features of each phrase.
[0121] In the above steps, n takes different values corresponding to a convolution kernel of a certain scale. Since there are multiple channels, each scale of the convolution kernel will have a phrase semantic feature quantity corresponding to the number of channels. At this time, for the phrase semantic features corresponding to the convolution kernel of each scale, the maximum pooling operation can be performed to obtain the maximum feature of each phrase semantic feature.
[0122] Then, for the semantic features of the phrases corresponding to the convolution kernels of each scale, an average pooling operation is performed to obtain the average features of the semantic features of each phrase. Therefore, each convolution kernel of each scale will correspond to a maximum feature and an average feature.
[0123] Step S404: concatenate all maximum features and average features to obtain a second semantic vector.
[0124] It should be noted that the concatenation in this step may be a simple horizontal concatenation of the maximum feature and the average feature obtained above to obtain the second semantic vector.
[0125] Since at least two rows of the word vector matrix are convolved in the process of obtaining the second semantic vector, the correlation between the word vectors corresponding to adjacent rows is taken into account.
[0126] Step S105: Calculate the similarity between the word vector of each word in the text to be recognized and the word vector of the preset emotional word according to the word vector matrix, and determine all the calculated similarities as the third semantic vector.
[0127] See also Figure 5 , Figure 5 It is a schematic diagram of a flow chart of determining a third semantic vector provided by an embodiment of the present application.
[0128] like Figure 5 As shown, the process of determining the third semantic vector provided by this embodiment may include:
[0129] Step S501: input the word vector matrix into the pre-trained second model, calculate the similarity between each word vector in the word vector matrix and the preset emotional word vector, and obtain a similarity matrix.
[0130] It should be noted that there can be n preset emotional words. Similarly, the word vector length of the preset emotional words is set to Embedding_size. Then the word vectors of all preset emotional words will form a matrix with a shape of (n, Embedding_size). The similarity between the word vector of each emotional word and each word in the word vector matrix (max_length, Embedding_size) in the text to be recognized is calculated, and a (max_length, n) matrix will be obtained, that is, the similarity matrix.
[0131] Step S502: Perform a maximum pooling operation on the similarity matrix to obtain a first vector.
[0132] Step S503: Perform an average pooling operation on the similarity matrix to obtain a second vector.
[0133] Step S504: determine the first vector and the second vector as a third semantic vector.
[0134] After steps S502 and S503, two vectors with a shape of (1, n) are obtained, namely the first vector and the second vector, and the first vector and the second vector are the third semantic vectors.
[0135] Step S106: determining the emotion category to which the text to be recognized belongs according to the first semantic vector, the second semantic vector, and the third semantic vector.
[0136] See also Figure 6 , Figure 6It is a flowchart of determining the emotion category to which a text to be recognized belongs, provided by an embodiment of the present application.
[0137] like Figure 6 As shown, the process of determining the emotion category to which the text to be recognized belongs provided by this embodiment may include:
[0138] Step S601: splice the first semantic vector, the second semantic vector and the third semantic vector according to a preset splicing method to obtain a splicing vector.
[0139] It should be noted that the splicing in this step can also be but is not limited to simple horizontal splicing.
[0140] Step S602: input the concatenated vector into a pre-trained classification model to determine the emotion category to which the text to be recognized belongs.
[0141] It should be noted that the pre-trained classification model can be a softmax model. After the concatenated vector is input into the softmax model, the probability of the concatenated vector relative to all preset emotion categories will be calculated. For example, 6 emotion categories can be pre-set here, including positive, fear, other, anger, sadness and disgust. Then the softmax model will obtain the probabilities of the concatenated vector relative to positive, fear, other, anger, sadness and disgust, for example, positive 0.8, fear 0.1, other 0.04, anger 0.03, sadness 0.02 and disgust 0.01. It can be seen that the concatenated vector is most likely to be a positive emotion category. Therefore, the emotion category to which the text to be recognized belongs can be "positive".
[0142] In addition, when training the model involved in the embodiments of the present application, the training samples can be divided into training set, validation set and test set according to the ratio of 7:2:1. The multi-scale convolutional neural network model can be trained with the training set, verified on the validation set, the parameters of the model can be adjusted, and the generalization ability of the model can be tested on the test set.
[0143] During training, you can also use the five-fold cross-validation method to verify the effectiveness of the model. Due to the imbalance of positive and negative samples in the data, stratified sampling is required for cross-validation.
[0144] Specifically, the training samples can be T = {(x1, y1), (x2, y2), ..., (x N ,y N )}, where x k Represents the set of texts to be recognized, y k={n} represents the emotion category, that is, the label value (the label value can be represented by a number, such as 1, 2, 3, etc., which refers to different emotion categories respectively), k=1, 2, 3, ..., N, T is the input data of the model, that is, the text data from different channels and the sample y to be predicted k .
[0145] It should be noted that the divided validation set can be used to adjust the parameters of the model, and the test set is used to verify the generalization ability of the model. Specifically, the trained multi-scale convolutional neural network model is used on the test set, the F1 score on the test set is calculated, and the score is used to verify the generalization ability of the model.
[0146] Among them, the F1 score (also known as F1 score) represents the harmonic mean of the model's accuracy and recall rate. For its specific calculation process and verification process, please refer to the relevant technology and will not be repeated here.
[0147] The technical solution of this embodiment first obtains the text to be recognized, then extracts the global semantic information of the text to be recognized, obtains the first semantic vector, and then uses the pre-trained word vector model to determine the word vector matrix of the text to be recognized, and then determines the second semantic vector according to the word vector matrix, calculates the similarity between the word vector of each word in the text to be recognized and the word vector of the preset emotional words according to the word vector matrix, and determines all the calculated similarities as the third semantic vector, and finally determines the emotion category to which the text to be recognized belongs according to the first semantic vector, the second semantic vector and the third semantic vector. In this way, the emotion category of the text to be recognized can be determined according to the global semantic information of the text to be recognized and the word vector matrix of the text to be recognized, wherein the syntax of the text to be recognized is taken into account, thereby improving the accuracy of emotion recognition.
[0148] See also Figure 7 , Figure 7 It is a structural schematic diagram of a semantic emotion recognition device provided by another embodiment of the present application.
[0149] like Figure 7 As shown, the semantic emotion recognition device provided in this embodiment may include:
[0150] An acquisition module 701 is used to acquire text to be recognized;
[0151] An extraction module 702 is used to extract global semantic information of the text to be recognized to obtain a first semantic vector;
[0152] A first determination module 703 is used to determine a word vector matrix of a text to be recognized using a pre-trained word vector model;
[0153] A second determination module 704, configured to determine a second semantic vector according to the word vector matrix;
[0154] A third determination module 705 is used to calculate the similarity between the word vector of each word in the text to be recognized and the word vector of the preset emotional words according to the word vector matrix, and determine all the calculated similarities as the third semantic vector;
[0155] The fourth determination module 706 is used to determine the emotion category to which the to-be-recognized text belongs according to the first semantic vector, the second semantic vector and the third semantic vector.
[0156] In an optional embodiment, the extraction module includes:
[0157] An adding unit, used for adding preset symbols to the text to be recognized;
[0158] A conversion unit, used for converting the global semantic information of the text to be recognized with the preset symbols added thereto into a text vector;
[0159] A first determining unit, configured to obtain a position vector of a preset symbol according to a position of the preset symbol in the text to be recognized;
[0160] The fusion unit is used to fuse the text vector, the position vector and the word vector of the preset symbol to obtain a first semantic vector.
[0161] In an optional embodiment, the first determining module includes:
[0162] A word segmentation unit, used to segment the text to be recognized using a preset word segmentation method to obtain at least one word of the text to be recognized;
[0163] A second determining unit, used to determine a word vector of each word through a pre-trained word vector model;
[0164] The generating unit is used to obtain the word vector matrix of the text to be recognized according to the word vector of each word.
[0165] In an optional embodiment, the second determining module includes:
[0166] An extraction unit, used to input the word vector matrix into the pre-trained first model, and extract the semantic features of the phrase according to the correlation between adjacent word vectors using convolution kernels of different sizes;
[0167] The first pooling unit is used to perform a maximum pooling operation on the semantic features of each phrase extracted by the convolution kernel to obtain the maximum feature of the semantic features of each phrase;
[0168] The second pooling unit is used to perform an average pooling operation on the semantic features of each phrase extracted by each convolution kernel to obtain the average feature of the semantic features of each phrase;
[0169] The first concatenation unit is used to concatenate all maximum features and average features to obtain a second semantic vector.
[0170] In an optional embodiment, the third determining module includes:
[0171] A calculation unit, used for inputting the word vector matrix into the pre-trained second model, calculating the similarity between each word vector in the word vector matrix and the word vector of the preset emotional words, and obtaining a similarity matrix;
[0172] A third pooling unit, used for performing a maximum pooling operation on the similarity matrix to obtain a first vector;
[0173] A fourth pooling unit, used for performing an average pooling operation on the similarity matrix to obtain a second vector;
[0174] The third determining unit is configured to determine the first vector and the second vector as a third semantic vector.
[0175] In an optional embodiment, the fourth determining unit includes:
[0176] A second splicing unit, configured to splice the first semantic vector, the second semantic vector and the third semantic vector according to a preset splicing method to obtain a splicing vector;
[0177] The fourth determination unit is used to input the concatenated vector into a pre-trained classification model to determine the emotion category to which the text to be recognized belongs.
[0178] See also Figure 8 , Figure 8 It is a structural diagram of a semantic emotion recognition device provided by another embodiment of the present application.
[0179] like Figure 8 As shown, the semantic emotion recognition device 800 provided in this embodiment includes: at least one processor 801, a memory 802, at least one network interface 803 and other user interfaces 804. The various components in the semantic emotion recognition device 800 are coupled together through a bus system 805. It can be understood that the bus system 805 is used to realize the connection and communication between these components. In addition to the data bus, the bus system 805 also includes a power bus, a control bus and a status signal bus. However, for the sake of clarity, Figure 8 Various buses are labeled as bus system 805 .
[0180] The user interface 804 may include a display, a keyboard, or a pointing device (eg, a mouse, a trackball, a touch pad, or a touch screen).
[0181] It can be understood that the memory 802 in the embodiment of the present invention can be a volatile memory or a non-volatile memory, or can include both volatile and non-volatile memories. Among them, the non-volatile memory can be a read-only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), an electrically erasable programmable read-only memory (EEPROM), or a flash memory. The volatile memory can be a random access memory (RAM), which is used as an external cache. By way of example but not limitation, many forms of RAM are available, such as static random access memory (SRAM), dynamic random access memory (DRAM), synchronous dynamic random access memory (SDRAM), double data rate synchronous dynamic random access memory (DDRSDRAM), enhanced synchronous dynamic random access memory (ESDRAM), synchronous link dynamic random access memory (SLDRAM), and direct RAM bus random access memory (DRRAM). The memory 802 described herein is intended to include, but is not limited to, these and any other suitable types of memory.
[0182] In some implementations, the memory 802 stores the following elements, executable units or data structures, or a subset thereof, or an extended set thereof: an operating system 8021 and a second application 8022 .
[0183] The operating system 8021 includes various system programs, such as a framework layer, a core library layer, a driver layer, etc., for implementing various basic services and processing hardware-based tasks. The second application 8022 includes various second application programs, such as a media player (Media Player), a browser (Browser), etc., for implementing various application services. The program for implementing the method of the embodiment of the present invention can be included in the second application 8022.
[0184] In the embodiment of the present invention, by calling the program or instruction stored in the memory 802, specifically, the program or instruction stored in the second application 8022, the processor 801 is used to execute the method steps provided by each method embodiment, for example, including:
[0185] Get the text to be recognized;
[0186] Extracting global semantic information of the text to be recognized to obtain a first semantic vector;
[0187] Use the pre-trained word vector model to determine the word vector matrix of the text to be recognized;
[0188] Determine a second semantic vector according to the word vector matrix;
[0189] Calculate the similarity between the word vector of each word in the text to be recognized and the word vector of the preset emotional words according to the word vector matrix, and determine all the calculated similarities as the third semantic vector;
[0190] The emotion category to which the to-be-recognized text belongs is determined according to the first semantic vector, the second semantic vector, and the third semantic vector.
[0191] In an optional embodiment, extracting the global semantic information of the text to be recognized to obtain a first semantic vector includes:
[0192] Add preset symbols to the text to be recognized;
[0193] Converting the global semantic information of the text to be recognized with preset symbols added into a text vector;
[0194] Obtaining a position vector of a preset symbol according to the position of the preset symbol in the text to be recognized;
[0195] The text vector, the position vector and the word vector of the preset symbol are fused to obtain a first semantic vector.
[0196] In an optional embodiment, determining a word vector matrix of a text to be recognized using a pre-trained word vector model includes:
[0197] Segmenting the text to be recognized using a preset segmentation method to obtain at least one word of the text to be recognized;
[0198] Determine the word vector of each word through the pre-trained word vector model;
[0199] The word vector matrix of the text to be recognized is obtained based on the word vector of each word.
[0200] In an optional embodiment, determining the second semantic vector according to the word vector matrix includes:
[0201] The word vector matrix is input into the pre-trained first model, and convolution kernels of different sizes are used to extract the semantic features of the word group according to the correlation between adjacent word vectors;
[0202] Perform a maximum pooling operation on the semantic features of each phrase extracted by the convolution kernel to obtain the maximum feature of the semantic features of each phrase;
[0203] Perform an average pooling operation on the semantic features of each phrase extracted by each convolution kernel to obtain the average features of the semantic features of each phrase;
[0204] All maximum features and average features are concatenated to obtain the second semantic vector.
[0205] In an optional embodiment, the similarity between the word vector of each word in the text to be recognized and the word vector of the preset emotional words is calculated according to the word vector matrix, and all the calculated similarities are determined as the third semantic vector, including:
[0206] Input the word vector matrix into the pre-trained second model, calculate the similarity between each word vector in the word vector matrix and the word vector of the preset emotional words, and obtain a similarity matrix;
[0207] Perform a maximum pooling operation on the similarity matrix to obtain a first vector;
[0208] Perform an average pooling operation on the similarity matrix to obtain a second vector;
[0209] The first vector and the second vector are determined as a third semantic vector.
[0210] In an optional embodiment, determining the emotion category to which the to-be-recognized text belongs according to the first semantic vector, the second semantic vector, and the third semantic vector includes:
[0211] splicing the first semantic vector, the second semantic vector and the third semantic vector according to a preset splicing method to obtain a splicing vector;
[0212] The concatenated vector is input into the pre-trained classification model to determine the emotion category to which the text to be identified belongs.
[0213] The method disclosed in the above embodiment of the present invention can be applied to the processor 801, or implemented by the processor 801. The processor 801 may be an integrated circuit chip with signal processing capabilities. In the implementation process, each step of the above method can be completed by the hardware integrated logic circuit in the processor 801 or the instruction in the form of software. The above processor 801 can be a general processor, a digital signal processor (Digital Signal Processor, DSP), an application specific integrated circuit (Application Specific Integrated Circuit, ASIC), a field programmable gate array (Field Programmable Gate Array, FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components. The methods, steps and logic block diagrams disclosed in the embodiments of the present invention can be implemented or executed. The general processor can be a microprocessor or the processor can also be any conventional processor. The steps of the method disclosed in the embodiment of the present invention can be directly embodied as a hardware decoding processor to execute, or the hardware and software units in the decoding processor can be executed. The software unit can be located in a mature storage medium in the field such as a random access memory, a flash memory, a read-only memory, a programmable read-only memory or an electrically erasable programmable memory, a register, etc. The storage medium is located in the memory 802, and the processor 801 reads the information in the memory 802 and completes the steps of the above method in combination with its hardware.
[0214] It is understood that the embodiments described herein may be implemented in hardware, software, firmware, middleware, microcode, or a combination thereof. For hardware implementation, the processing unit may be implemented in one or more application specific integrated circuits (ASIC), digital signal processors (DSP), digital signal processing devices (DSPDevice, DSPD), programmable logic devices (PLD), field programmable gate arrays (FPGA), general purpose processors, controllers, microcontrollers, microprocessors, other electronic units for performing the functions of the present application, or a combination thereof.
[0215] For software implementation, the technology of this article can be implemented by a unit that performs the functions of this article. The software code can be stored in a memory and executed by a processor. The memory can be implemented in the processor or outside the processor.
[0216] The embodiment of the present invention also provides a storage medium (computer-readable storage medium). The storage medium here stores one or more programs. The storage medium may include a volatile memory, such as a random access memory; the memory may also include a non-volatile memory, such as a read-only memory, a flash memory, a hard disk or a solid-state drive; the memory may also include a combination of the above-mentioned types of memory.
[0217] When one or more programs in the storage medium can be executed by one or more processors, the semantic emotion recognition method executed on the semantic emotion recognition device side can be implemented.
[0218] The processor is used to execute the semantic emotion recognition program stored in the memory to implement the following steps of the semantic emotion recognition method executed on the semantic emotion recognition device side:
[0219] Get the text to be recognized;
[0220] Extracting global semantic information of the text to be recognized to obtain a first semantic vector;
[0221] Use the pre-trained word vector model to determine the word vector matrix of the text to be recognized;
[0222] Determine a second semantic vector according to the word vector matrix;
[0223] Calculate the similarity between the word vector of each word in the text to be recognized and the word vector of the preset emotional words according to the word vector matrix, and determine all the calculated similarities as the third semantic vector;
[0224] The emotion category to which the to-be-recognized text belongs is determined according to the first semantic vector, the second semantic vector, and the third semantic vector.
[0225] In an optional embodiment, extracting the global semantic information of the text to be recognized to obtain a first semantic vector includes:
[0226] Add preset symbols to the text to be recognized;
[0227] Convert the global semantic information of the text to be recognized with preset symbols added into a text vector;
[0228] Obtaining a position vector of a preset symbol according to the position of the preset symbol in the text to be recognized;
[0229] The text vector, the position vector and the word vector of the preset symbol are fused to obtain a first semantic vector.
[0230] In an optional embodiment, determining a word vector matrix of a text to be recognized using a pre-trained word vector model includes:
[0231] Segmenting the text to be recognized using a preset segmentation method to obtain at least one word of the text to be recognized;
[0232] Determine the word vector of each word through the pre-trained word vector model;
[0233] The word vector matrix of the text to be recognized is obtained based on the word vector of each word.
[0234] In an optional embodiment, determining the second semantic vector according to the word vector matrix includes:
[0235] The word vector matrix is input into the pre-trained first model, and convolution kernels of different sizes are used to extract the semantic features of the word group according to the correlation between adjacent word vectors;
[0236] Perform a maximum pooling operation on the semantic features of each phrase extracted by the convolution kernel to obtain the maximum feature of the semantic features of each phrase;
[0237] Perform an average pooling operation on the semantic features of each phrase extracted by each convolution kernel to obtain the average features of the semantic features of each phrase;
[0238] All maximum features and average features are concatenated to obtain the second semantic vector.
[0239] In an optional embodiment, the similarity between the word vector of each word in the text to be recognized and the word vector of the preset emotional words is calculated according to the word vector matrix, and all the calculated similarities are determined as the third semantic vector, including:
[0240] Input the word vector matrix into the pre-trained second model, calculate the similarity between each word vector in the word vector matrix and the word vector of the preset emotional words, and obtain a similarity matrix;
[0241] Perform a maximum pooling operation on the similarity matrix to obtain a first vector;
[0242] Perform an average pooling operation on the similarity matrix to obtain a second vector;
[0243] The first vector and the second vector are determined as a third semantic vector.
[0244] In an optional embodiment, determining the emotion category to which the to-be-recognized text belongs according to the first semantic vector, the second semantic vector, and the third semantic vector includes:
[0245] splicing the first semantic vector, the second semantic vector and the third semantic vector according to a preset splicing method to obtain a splicing vector;
[0246] The concatenated vector is input into the pre-trained classification model to determine the emotion category to which the text to be identified belongs.
[0247] Regarding the device in the above embodiment, the specific manner in which each module performs operations has been described in detail in the embodiment of the method, and will not be elaborated here.
[0248] It can be understood that the same or similar parts of the above embodiments can be referenced to each other, and the contents not described in detail in some embodiments can refer to the same or similar contents in other embodiments.
[0249] It should be noted that, in the description of this application, the terms "first", "second", etc. are only used for descriptive purposes and cannot be understood as indicating or implying relative importance. In addition, in the description of this application, unless otherwise specified, the meaning of "plurality" refers to at least two.
[0250] Any process or method description in a flowchart or otherwise described herein may be understood to represent a module, segment or portion of code that includes one or more executable instructions for implementing the steps of a specific logical function or process, and the scope of the preferred embodiments of the present application includes alternative implementations in which functions may not be performed in the order shown or discussed, including performing functions in a substantially simultaneous manner or in the reverse order depending on the functions involved, which should be understood by technicians in the technical field to which the embodiments of the present application belong.
[0251] It should be understood that the various parts of the present application can be implemented by hardware, software, firmware or a combination thereof. In the above-mentioned embodiments, multiple steps or methods can be implemented by software or firmware stored in a memory and executed by a suitable instruction execution system. For example, if implemented by hardware, as in another embodiment, it can be implemented by any one of the following technologies known in the art or their combination: a discrete logic circuit having a logic gate circuit for implementing a logic function for a data signal, a dedicated integrated circuit having a suitable combination of logic gate circuits, a programmable gate array (PGA), a field programmable gate array (FPGA), etc.
[0252] A person skilled in the art may understand that all or part of the steps in the above-mentioned embodiment method may be completed by instructing related hardware through a program, and the program may be stored in a computer-readable storage medium, which, when executed, includes one or a combination of the steps of the method embodiment.
[0253] In addition, each functional unit in each embodiment of the present application may be integrated into a processing module, or each unit may exist physically separately, or two or more units may be integrated into one module. The above-mentioned integrated module may be implemented in the form of hardware or in the form of a software functional module. If the integrated module is implemented in the form of a software functional module and sold or used as an independent product, it may also be stored in a computer-readable storage medium.
[0254] The storage medium mentioned above can be a read-only memory, a magnetic disk or an optical disk, etc.
[0255] In the description of this specification, the description with reference to the terms "one embodiment", "some embodiments", "example", "specific example", or "some examples" means that the specific features, structures, materials or characteristics described in conjunction with the embodiment or example are included in at least one embodiment or example of the present application. In this specification, the schematic representation of the above terms does not necessarily refer to the same embodiment or example. Moreover, the specific features, structures, materials or characteristics described may be combined in any one or more embodiments or examples in a suitable manner.
[0256] Although the embodiments of the present application have been shown and described above, it can be understood that the above embodiments are exemplary and cannot be understood as limitations on the present application. Ordinary technicians in this field can change, modify, replace and modify the above embodiments within the scope of the present application.
Claims
1. A semantic emotion recognition method, characterized in that: include: Get the text to be recognized; Extracting global semantic information of the text to be recognized to obtain a first semantic vector; Determine the word vector matrix of the text to be recognized by using a pre-trained word vector model; Determine a second semantic vector according to the word vector matrix; Calculating the similarity between the word vector of each word in the text to be recognized and the word vector of the preset emotional words according to the word vector matrix, and determining all the calculated similarities as the third semantic vector; Determining the emotion category to which the text to be recognized belongs according to the first semantic vector, the second semantic vector and the third semantic vector, including: splicing the first semantic vector, the second semantic vector and the third semantic vector according to a preset splicing method to obtain a splicing vector; inputting the splicing vector into a pre-trained classification model to determine the emotion category to which the text to be recognized belongs, wherein the preset splicing method includes simple horizontal splicing.
2. The method according to claim 1, characterized in that The step of extracting the global semantic information of the text to be recognized to obtain a first semantic vector includes: Adding a preset symbol to the text to be recognized; Convert the global semantic information of the text to be recognized with preset symbols added into a text vector; Obtaining a position vector of the preset symbol according to the position of the preset symbol in the text to be recognized; The text vector, the position vector and the preset word vector of the preset symbol are fused to obtain a first semantic vector.
3. The method according to claim 1, characterized in that The method of determining the word vector matrix of the text to be recognized by using the pre-trained word vector model includes: Segmenting the text to be recognized using a preset segmentation method to obtain at least one word of the text to be recognized; Determine the word vector of each of the words through a pre-trained word vector model; A word vector matrix of the text to be recognized is obtained based on the word vectors of each of the words.
4. The method according to any one of claims 1 to 3, characterized in that: The determining the second semantic vector according to the word vector matrix includes: Inputting the word vector matrix into the pre-trained first model, and using convolution kernels of different sizes to extract the semantic features of the phrase according to the correlation between adjacent word vectors; Perform a maximum pooling operation on the semantic features of each phrase extracted by the convolution kernel to obtain the maximum feature of the semantic features of each phrase; Perform an average pooling operation on the semantic features of each phrase extracted by each convolution kernel to obtain the average features of the semantic features of each phrase; All maximum features and average features are concatenated to obtain the second semantic vector.
5. The method according to any one of claims 1 to 3, characterized in that: The step of calculating the similarity between the word vector of each word in the to-be-recognized text and the word vector of the preset emotional words according to the word vector matrix, and determining all the calculated similarities as the third semantic vector, includes: Input the word vector matrix into the pre-trained second model, calculate the similarity between each word vector in the word vector matrix and the word vector of the preset emotional words, and obtain a similarity matrix; Performing a maximum pooling operation on the similarity matrix to obtain a first vector; Performing an average pooling operation on the similarity matrix to obtain a second vector; The first vector and the second vector are determined as the third semantic vector.
6. A semantic emotion recognition device, characterized in that: The device comprises: An acquisition module is used to acquire the text to be recognized; An extraction module, used for extracting global semantic information of the text to be recognized to obtain a first semantic vector; A first determination module, used to determine the word vector matrix of the text to be recognized by using a pre-trained word vector model; A second determination module, used to determine a second semantic vector according to the word vector matrix; A third determination module is used to calculate the similarity between the word vector of each word in the text to be recognized and the word vector of the preset emotional words according to the word vector matrix, and determine all the calculated similarities as a third semantic vector; The fourth determination module is used to determine the emotion category to which the text to be recognized belongs based on the first semantic vector, the second semantic vector and the third semantic vector, including: splicing the first semantic vector, the second semantic vector and the third semantic vector according to a preset splicing method to obtain a splicing vector; inputting the splicing vector into a pre-trained classification model to determine the emotion category to which the text to be recognized belongs, wherein the preset splicing method includes simple horizontal splicing.
7. The device according to claim 6, characterized in that The extraction module comprises: An adding unit, used for adding a preset symbol to the text to be recognized; A conversion unit, used for converting the global semantic information of the text to be recognized with the preset symbols added thereto into a text vector; A first determining unit, configured to obtain a position vector of the preset symbol according to the position of the preset symbol in the text to be recognized; A fusion unit is used to fuse the text vector, the position vector and the preset word vector of the preset symbol to obtain a first semantic vector.
8. A semantic emotion recognition device, characterized in that: include: at least one processor and memory; The processor is used to execute the semantic emotion recognition program stored in the memory to implement the semantic emotion recognition method described in any one of claims 1-5.
9. A storage medium, characterized in that: The storage medium stores one or more programs, and when the one or more programs are executed, the semantic emotion recognition method according to any one of claims 1 to 5 is implemented.
