Positive and negative sentiment analysis method, device, equipment and storage medium

By constructing entity recognition thesaurus and subject thesaurus, automatically extracting and converting data, and entering positive and negative sentiment analysis models, the problems of low emotional calculation accuracy and high manpower consumption in proprietary fields are solved, and the accuracy and efficiency of public opinion analysis are improved. .

CN116628190BActive Publication Date: 2025-01-17BEIJING ZHIHUI XINGGUANG INFORMATION TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202310153785.5
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-02-13
Publication Date
2025-01-17
Estimated Expiration
2043-02-13

AI Technical Summary

Technical Problem

The accuracy of emotional positive and negative calculations in the prior art fields is poor and labor-intensive, resulting in low accuracy of public opinion analysis.

Method used

By pre-constructing entity recognition thesaurus and domain subject lexicons, the subject words and entity words in the data to be analyzed are automatically extracted, and based on prior knowledge, they are converted into model input format, and the pre-constructed positive and negative sentiment analysis model is input to obtain Emotional probability value.

Benefits of technology

It improves the accuracy of the analysis results, reduces manual labeling work, saves manpower and time, and improves the semantic understanding ability of the model.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116628190B_ABST
    Figure CN116628190B_ABST
Patent Text Reader

Abstract

The present invention relates to a positive and negative sentiment analysis method, device, equipment and storage medium, and belongs to the technical field of public opinion analysis. The method, device, equipment and storage medium pre-construct an entity recognition word library and a domain subject word library, thereby automatically extracting subject words and entity words from the data to be analyzed, corresponding prior knowledge to subject words and entity words, converting the data to be analyzed into model input format data to be analyzed, and inputting it into a pre-constructed positive and negative sentiment analysis model to obtain the positive and negative sentiment probability values ​​of the data to be analyzed, wherein the automatic extraction of entity words and subject words in the field avoids the technical problem of manually annotating words one by one, liberates most of the manual annotation work, saves manpower and time, and introduces prior knowledge of subject words in professional fields, further improving the semantic understanding ability of the model.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of public opinion analysis, and in particular to a positive and negative sentiment analysis method, device, equipment and storage medium. Background Art

[0002] Identifying the positive and negative tendencies of public opinion is an important part of the public opinion analysis platform's collation and analysis of public opinion. Different fields, different entities, and different industries have different corresponding positions, so the positive and negative calculations are also different, which makes it generally impossible for a single model to solve all industry problems.

[0003] In related technologies, fine-tuning is usually performed on the basis of the BERT pre-trained model to perform text classification training to classify the positive and negative tendencies of different public opinion texts. However, for different fields, different technicians are required to perform manual labeling, which is labor-intensive; and when the labelers lack professional skills, there will be labeling errors, resulting in poor accuracy of the final classification model.

[0004] Therefore, there are technical problems in the related technology that the calculation accuracy of positive and negative emotions in proprietary fields is poor and labor-intensive. Summary of the invention

[0005] In view of this, the purpose of the present invention is to provide a positive and negative sentiment analysis method, device, equipment and storage medium to overcome the current technical problems of poor accuracy and labor-intensive calculation of positive and negative sentiments in proprietary fields.

[0006] To achieve the above objectives, the present invention adopts the following technical solutions:

[0007] On the one hand, a positive and negative sentiment analysis method, comprising:

[0008] Acquire the data to be analyzed, and extract entity words and subject words in the data to be analyzed based on a preset entity recognition word library and a subject word library of each field;

[0009] According to the preset prior knowledge, entity words and subject words in the data to be analyzed, domain subject features are obtained, and the data to be analyzed is converted into data to be analyzed in a model input format;

[0010] The data to be analyzed in the model input format is input into a pre-constructed positive and negative sentiment analysis model to obtain the positive and negative sentiment probability values ​​of the data to be analyzed; wherein the pre-constructed positive and negative sentiment analysis model is obtained after training based on the model input format sample data and the corresponding positive and negative sentiment labels, and the positive and negative sentiment labels are predetermined based on the sample data and correspond one-to-one to the sample data.

[0011] Optionally, the entity recognition word library includes entity words and concept classification of each entity word; wherein the concept classification is classified according to prior knowledge; and the method for constructing the entity recognition word library includes:

[0012] Identify entity words in an entity word data set and construct a primary entity word library; wherein the entity word data set is constructed based on a massive data set;

[0013] Deduplication processing is performed on entity words in the primary entity vocabulary to obtain a primary entity vocabulary after deduplication;

[0014] Based on prior knowledge, conceptual classification is performed on the entity words in the primary entity word library after deduplication;

[0015] The entity words and corresponding concepts in the primary entity vocabulary after deduplication are classified as the entity recognition vocabulary.

[0016] Optionally, the method for constructing the subject word library for each field includes:

[0017] The data in the domain data set is segmented according to the Jieba word segmentation method to obtain different segmented words; wherein the domain data set is constructed based on the massive data collected in the domain; the segmented words include subject words;

[0018] Calculate the importance weight of each word by inverse document frequency;

[0019] Based on the importance weight of each segmentation, the firmness between subject words and subject words is calculated according to the point-by-point mutual information method;

[0020] According to the firmness between the subject words and the subject words and the importance weight of the corresponding subject words, new importance weights of different subject words and subject words are calculated as new importance weights of different subject word strings; wherein the subject word strings are composed of subject words and subject words with different firmness;

[0021] A subject word library of the field is constructed by using different subject word strings and corresponding new importance weights; wherein each subject word in the subject word library is a subject word string.

[0022] Optionally, constructing a subject word library of the field through different subject word strings and corresponding new importance weights includes:

[0023] Sort the corresponding subject word strings according to the new importance weights;

[0024] Determine the subject word strings whose new importance weights are within the preset range before sorting or the subject word strings whose new importance weights are greater than a preset threshold as the subject word strings of the field, and construct the subject word library of the field.

[0025] Optionally, the step of calculating new importance weights of different subject words and subject word combinations based on the solidity between the subject words and the importance weights of the corresponding subject words as new importance weights of different subject word strings includes:

[0026] Calculate the sum of the importance weights of all the corresponding keywords with firmness;

[0027] The product of the sum and the corresponding solidity between the subject words is calculated, and the product is used as the new importance weight.

[0028] Optionally, the method for constructing the positive and negative sentiment analysis model includes:

[0029] Acquire sample data from a sample set, wherein the samples in the sample set are all set with positive and negative emotion labels; wherein the sample data in the sample set are collected and acquired through domain keywords;

[0030] Extracting entity words and subject words from the sample data based on a preset entity recognition word library and a subject word library for each field;

[0031] According to the preset prior knowledge, entity words and subject words in the sample data, domain subject features are obtained, and the sample data is converted into model input format sample data;

[0032] Input the sample data in the model input format into the BERT model to obtain a sentence vector and a word-level vector sequence; wherein the word-level vector sequence includes multiple word-level vectors;

[0033] Only retain the domain theme features, calculate the average pooling, and obtain the first feature vector;

[0034] Only features other than the domain theme features are retained, pooling is calculated, and a second feature vector is obtained;

[0035] Calculating a difference between the first eigenvector and the second eigenvector;

[0036] Concatenate the sentence vector, the first feature vector, the second feature vector, and the difference to obtain a final feature, and input the final feature into a fully connected layer, wherein the fully connected layer is connected to an output layer;

[0037] Calculate the loss function, train the model, and obtain the positive and negative sentiment analysis model.

[0038] Optionally, also include:

[0039] In the output layer, a softmax classifier is used to perform sentiment analysis on the feature classification results output by the fully connected layer to obtain a sentiment analysis result.

[0040] In another aspect, a positive and negative sentiment analysis device comprises:

[0041] An acquisition module is used to acquire the data to be analyzed, and extract entity words and subject words in the data to be analyzed based on a preset entity recognition word library and a subject word library of each field;

[0042] A conversion module, used to obtain domain subject features based on preset prior knowledge, entity words and subject words in the data to be analyzed, and convert the data to be analyzed into data in a model input format to be analyzed;

[0043] The analysis module is used to input the data to be analyzed in the model input format into a pre-constructed positive and negative sentiment analysis model to obtain the positive and negative sentiment probability values ​​of the data to be analyzed; wherein the pre-constructed positive and negative sentiment analysis model is obtained after training based on the model input format sample data and the corresponding positive and negative sentiment labels, and the positive and negative sentiment labels are predetermined based on the sample data and correspond one-to-one to the sample data.

[0044] In another aspect, a positive and negative sentiment analysis device includes: a processor and a memory, wherein the processor is connected to the memory:

[0045] Wherein, the processor is used to call and execute the program stored in the memory;

[0046] The memory is used to store the program, and the program is at least used to execute any one of the positive and negative sentiment analysis methods described above.

[0047] On the other hand, a non-transitory computer-readable storage medium storing computer instructions is provided, wherein the computer instructions are used to enable the computer to execute any one of the positive and negative sentiment analysis methods described above.

[0048] The technical solution provided by the present invention has at least the following beneficial effects:

[0049] By pre-building an entity recognition vocabulary and a subject vocabulary of a field, it is possible to automatically extract subject words and entity words from the data to be analyzed, and then correspond them to subject words and entity words based on prior knowledge, convert the data to be analyzed into model input format data to be analyzed, and input them into a pre-built positive and negative sentiment analysis model to obtain the positive and negative sentiment probability values ​​of the data to be analyzed. Specifically, the specific field is taken into consideration when processing the data to be analyzed, thereby improving the accuracy of the analysis results. In addition, the automatic extraction of entity words and subject words within the field avoids the technical problem of manually annotating each word one by one, freeing up most of the manual annotation work, saving manpower and time, and introducing prior knowledge of subject words in professional fields, further improving the semantic understanding ability of the model. BRIEF DESCRIPTION OF THE DRAWINGS

[0050] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0051] Figure 1 A flowchart of a positive and negative sentiment analysis method provided by an embodiment of the present invention;

[0052] Figure 2 Entity words and corresponding concept categories in an entity recognition vocabulary provided by an embodiment of the present invention;

[0053] Figure 3 A schematic diagram of the architecture of a positive and negative sentiment analysis model provided by an embodiment of the present invention;

[0054] Figure 4 A schematic diagram of the structure of a positive and negative sentiment analysis device provided by an embodiment of the present invention;

[0055] Figure 5 A schematic diagram of the structure of a positive and negative sentiment analysis device provided in one embodiment of the present invention. DETAILED DESCRIPTION

[0056] To make the purpose, technical solution and advantages of the present invention clearer, the technical solution of the present invention will be described in detail below. Obviously, the described embodiments are only part of the embodiments of the present invention, rather than all the embodiments. Based on the embodiments of the present invention, all other implementation methods obtained by ordinary technicians in this field without creative work belong to the scope of protection of the present invention.

[0057] As mentioned in the background technology, for the full data of the existing public opinion analysis platform, it is necessary to calculate the positive and negative sentiment of some proprietary industry data, because different subjects and industries have different corresponding positions, so the positive and negative calculations are also different. Calculating the positive and negative sentiment according to different proprietary fields is a strong demand for refined public opinion analysis.

[0058] There are technical problems in the related technologies, such as poor accuracy in calculating positive and negative emotions in proprietary domains and high labor consumption.

[0059] Based on this, an embodiment of the present invention provides a positive and negative sentiment analysis method, device, equipment and storage medium.

[0060] Figure 1A flowchart of a positive and negative sentiment analysis method provided by an embodiment of the present invention is shown in FIG. Figure 1 , this embodiment may include the following steps:

[0061] Step S11, obtaining the data to be analyzed, and extracting entity words and subject words in the data to be analyzed based on a preset entity recognition vocabulary and a subject vocabulary of each field.

[0062] Step S12: Based on the preset prior knowledge, entity words and subject words in the data to be analyzed, domain subject features are obtained, and the data to be analyzed is converted into data to be analyzed in a model input format.

[0063] Step S13, input the data to be analyzed in the model input format into the pre-constructed positive and negative sentiment analysis model to obtain the positive and negative sentiment probability values ​​of the data to be analyzed; wherein the pre-constructed positive and negative sentiment analysis model is obtained after training based on the model input format sample data and the corresponding positive and negative sentiment labels, and the positive and negative sentiment labels are predetermined based on the sample data and correspond one-to-one to the sample data.

[0064] In a specific positive and negative sentiment analysis process, after obtaining public opinion information, any public opinion information can be used as data to be analyzed, so as to perform positive and negative sentiment analysis on the data to be analyzed.

[0065] After determining the data to be analyzed, the entity words and subject words in the data to be analyzed are extracted through the pre-set entity recognition word library and the subject word library of each field. For example, the data to be analyzed may be "Huang Mou A went to a certain place M again!" It can be identified that "Huang Mou A" belongs to the name of a person in the entity word, and "a certain place M" can belong to the place name in the subject word.

[0066] After obtaining entity words and subject words, matching is performed based on prior knowledge, that is, the prior knowledge corresponding to "Huang A" is "role 1"; the prior knowledge corresponding to "place M" is "institution 1". Prior knowledge is stored and set in advance based on Internet knowledge.

[0067] After obtaining the corresponding prior knowledge, the data to be analyzed can be converted into the model input format data to be analyzed. For example, when the data to be analyzed is "Huang Mou A went to a certain place M again!", the corresponding converted model input format data to be analyzed is "clsHuang Mou A went to a certain place M again!seq[role 1] went to [institution 1] again!seq"; when the data to be analyzed is "The person in charge of xx company did not take action, resulting in the cancellation of employee benefits.", the corresponding converted model input format data to be analyzed is "clsxx company person in charge did not take action, resulting in the cancellation of employee benefits.seq[enterprise] person in charge [feature], resulting in the cancellation of employee benefits.seq". Among them, [feature] is the domain subject feature of proprietary domain learning, that is, domain subject feature, [enterprise][role 1][institution 1], etc. are all input prior knowledge.

[0068] After obtaining the data to be analyzed in the model input format, the data to be analyzed in the model input format is input into the positive and negative sentiment analysis model for analysis, thereby obtaining the positive and negative sentiment probability values ​​of the data to be analyzed. For example, the negative sentiment probability value of the data to be analyzed "Huang Mou A went to a certain place M again!" can be obtained to be 87.5%, and the data to be analyzed can be judged to be negative sentiment based on the probability value.

[0069] It can be understood that by pre-building an entity recognition vocabulary and a subject vocabulary of a field, it is possible to automatically extract subject words and entity words from the data to be analyzed, thereby corresponding to subject words and entity words based on prior knowledge, converting the data to be analyzed into model input format data to be analyzed, and inputting it into a pre-built positive and negative sentiment analysis model to obtain the positive and negative sentiment probability values ​​of the data to be analyzed, wherein the specific field is taken into consideration in the processing of the data to be analyzed, thereby improving the accuracy of the analysis results; in addition, the automatic extraction of entity words and subject words within the field avoids the technical problem of manually annotating words one by one, liberates most of the manual annotation work, saves manpower and time, and introduces prior knowledge of subject words in professional fields, further improving the semantic understanding ability of the model.

[0070] In this application, the construction process of the entity recognition word library is described. In some embodiments, the entity recognition word library includes entity words and concept classifications of each entity word; the construction method of the entity recognition word library includes:

[0071] Identify entity words in the entity word dataset and build a primary entity word library; the entity word dataset is built based on a massive dataset;

[0072] Deduplication of entity words in the primary entity vocabulary is performed to obtain a primary entity vocabulary after deduplication;

[0073] Based on prior knowledge, conceptual classification is performed on entity words in the primary entity vocabulary after deduplication.

[0074] The entity words and corresponding concepts in the primary entity vocabulary after deduplication are classified as the entity recognition vocabulary.

[0075] For example, a massive data set can be used as a primary entity vocabulary, and entity recognition can be performed on the primary entity vocabulary to extract a large number of entities, namely: brand names, organization names, personal names, and place names, and then de-duplicate them to obtain a rich entity vocabulary as the primary entity vocabulary after de-duplicates. The concepts of entity words can be dynamically added according to different fields, and the entity words in the primary entity vocabulary after de-duplicates can be conceptually classified; the entity words and corresponding concepts in the primary entity vocabulary after de-duplicates are classified as the entity recognition vocabulary. An exemplary display is given here, see Figure 2 , Figure 2 An embodiment of the present invention provides entity words and corresponding concept categories in an entity recognition vocabulary. Figure 2 In the , entity words can include brand names, institution names, place names and personal names. The concept classifications corresponding to brand names include: national brand, private brand, state-owned enterprise brand; the concept classifications corresponding to institution names include: institution 1, enterprise, institution 2, institution 3, institution 4, institution 5, institution 6, institution 7, institution 8, where each institution represents the attribute of the corresponding institution name; the concept classifications corresponding to place names include: provincial capital, capital, domestic, and foreign; the concept classifications corresponding to personal names include: domestic personal names, foreign personal names, celebrities, ordinary people, role 1, role 2, role 3, role 4, role 5, role 6, role 7, role 8, etc., where each role represents an attribute of the corresponding personal name.

[0076] It is understandable that by introducing the conceptual classification of entity words, it is possible to perform semantic disambiguation on entities. Some entity words belong to government affairs, some belong to university types, and some belong to dangerous entities. In this way, by introducing the concept of entity, we can fully understand that the differences at the semantic level will arise due to different industry concepts.

[0077] In this application, the construction process of the subject word library in each field is described. In some embodiments, the construction method of the subject word library in each field includes:

[0078] The data in the domain dataset is segmented according to the Jieba word segmentation method to obtain different word segments; the domain dataset is constructed based on the massive data collected in the domain; the word segments include subject words;

[0079] Calculate the importance weight of each word by inverse document frequency;

[0080] Based on the importance weight of each segmentation, the firmness between subject words and subject words is calculated according to the point-by-point mutual information method;

[0081] According to the firmness between subject words and subject words and the importance weight of corresponding subject words, new importance weights of different subject words and subject word compositions are calculated as new importance weights of different subject word strings; wherein the subject word strings are composed of subject words and subject words with different firmness;

[0082] Through different subject word strings and corresponding new importance weights, a subject word library of the field is constructed; wherein each subject word in the subject word library is a subject word string.

[0083] For example, the massive data collected according to the field can be used as the field data set, and the open source word segmentation tool jieba can be used for word segmentation, and the importance weight idf value of each word segmentation can be calculated by IDF (inverse document frequency). Since the longer the subject word is, the more accurately it can represent the subject, and the shorter it is, the greater the interference. Therefore, this application introduces the PMI (point-by-point mutual information) method to calculate the firmness between the subject words and the subject words in the above idf, so as to mine the subject word string.

[0084] After calculating the firmness between subject words and subject words, the subject words corresponding to the firmness are used as subject word strings. The new importance weight of the subject word string is calculated based on the firmness of the subject word string and the importance weight of the subject words in the subject word string. Through different subject word strings and the corresponding new importance weights, a subject word library for each field is constructed.

[0085] It can be understood that by adopting the PMI method to construct a subject word library, the degree of association between subject words is improved, and the semantic relevance of subject word strings is improved.

[0086] In some embodiments, a subject word library of a field is constructed by using different subject word strings and corresponding new importance weights, including:

[0087] Sort the corresponding subject word strings according to the new importance weights;

[0088] Determine the subject word strings whose new importance weights are within the preset range before sorting or the subject word strings whose new importance weights are greater than a preset threshold as the subject word strings of the field, and construct the subject word library of the field.

[0089] For example, the front preset range may be the front 60%, the preset threshold may be 72%, and so on.

[0090] It can be understood that by sorting the subject word strings corresponding to the new importance weights, the subject word strings to be adopted can be accurately obtained, thereby forming a subject word library.

[0091] In some embodiments, according to the solidity between the subject words and the subject words, and the importance weights of the corresponding subject words, new importance weights of different subject words and subject word combinations are calculated as new importance weights of different subject word strings, including:

[0092] Calculate the sum of the importance weights of all the corresponding keywords with firmness;

[0093] The product of the sum and the corresponding subject word and the firmness between the subject words is calculated, and the product is used as the new importance weight.

[0094] Specifically, after performing Jieba word segmentation, the importance weight idf value of each word can be calculated by the following formula (1), and the probability of occurrence p(w) of each word can be calculated by the following formula (2):

[0095]

[0096] Among them, for any word segmentation and any data, n d Indicates the total number of texts in the corpus; n wd Represents the total number of texts in the corpus that contain word w.

[0097]

[0098] Among them, n(w) represents the number of times word w appears in the corpus, s represents the number of all words in the corpus, and i represents starting from the first word;

[0099] According to the point-by-point mutual information method, the solidity PMI between subject words is calculated, which can be expressed as formula (3) and formula (4):

[0100]

[0101]

[0102] Among them, p(w1,w2) represents the probability of co-occurrence of any two words w1 and w2 (co-occurrence means appearing at the same time in the adjacent positions in the article); n(w1,w2) represents the number of times any two words w1 and w2 co-occur in the corpus; m represents the number of all words in the corpus; i,j represent the index of any two words; p(w) represents the probability of any word in formula (2).

[0103] After calculating the importance weights of the two segment words wi and wj and their solidity pmi(wi, wj), the new importance weight of the subject word string is calculated according to formula (5):

[0104] Final weight: idf_new = (idf wi +idfwj )*pmi(w i ,w j ) formula (5).

[0105] The method for constructing the positive and negative sentiment analysis model pre-constructed in this application is described. In some embodiments, the method for constructing the positive and negative sentiment analysis model includes:

[0106] Sample data is obtained from the sample set, and all samples in the sample set are set with positive and negative emotional labels; wherein, the sample data in the sample set is collected and obtained through domain keywords;

[0107] Extract entity words and subject words from sample data based on the pre-set entity recognition word library and subject word library of each field;

[0108] According to the preset prior knowledge, entity words and subject words in the sample data, the sample data is converted into the model input format sample data;

[0109] Input the sample data in the model input format into the BERT model to obtain sentence vectors and word-level vector sequences; wherein the word-level vector sequence includes multiple word-level vectors;

[0110] Only retain the domain theme features, calculate the average pooling, and obtain the first feature vector;

[0111] Only features other than domain theme features are retained, pooling is calculated, and the second feature vector is obtained;

[0112] Calculate the difference between the first eigenvector and the second eigenvector;

[0113] The sentence vector, the first feature vector, the second feature vector, and the difference are concatenated to obtain the final feature, which is then input into the fully connected layer, which is connected to the output layer.

[0114] Calculate the loss function, train the model, and obtain the positive and negative sentiment analysis model.

[0115] In some embodiments, it also includes:

[0116] In the output layer, the softmax classifier is used to perform sentiment analysis on the feature classification results output by the fully connected layer to obtain the sentiment analysis results.

[0117] Figure 3 A schematic diagram of the architecture of a positive and negative sentiment analysis model provided for one embodiment of the present invention.

[0118] When building a model, the sample set can be divided into a training set and a test set, so that the samples in the training set are used for training and the samples in the test set are used for testing. The sample data in the sample set is collected through domain keywords, and the samples are all set with positive and negative emotional labels. After training with the model input format sample data and the corresponding positive and negative emotional labels, the positive and negative emotional analysis model is obtained.

[0119] Explain the model training process:

[0120] After the sample data is collected in the training set, the sample data is processed so as to convert each sample data into the model input format, wherein the conversion process is the same as the above conversion process and is not described in detail in this application, please refer to the above embodiment. The sample data may be public opinion data.

[0121] The processed sample data containing labels in the model input format can be input into the Bert model, and after being encoded by the Bert model, a sentence vector cl s and a word-level vector sequence (i.e., a token vector sequence [h1, h2, h3...hn]) are obtained; wherein the word-level vector sequence includes multiple word-level vectors.

[0122] See also Figure 3 For tokens, we can retain the domain theme features, i.e. [features], and mask the other parts, i.e. the vector value does not participate in the self-attention calculation, which is equivalent to assigning a value of 0; the latent vector after masking is self-attention calculated, and the calculation process can be:

[0123] Through the matrix transformation of the fully connected layer, it is transformed into three matrices q, k, and v of the same shape; as follows

[0124] q i,s =w q,s h i +b q,s

[0125] k i,s =w k,s h i +b k,s

[0126] v i,s =w v,s h i +b v,s

[0127] Among them, q i,s , k i,s v i,s are three matrices of the same shape of (i, s) dimension obtained by matrix transformation; wk,s , w q,s, w v,s are the three initialized learning parameters, the parameters that need to be trained; b q,s , b k,s , b v,s The calculation part added for bias, i.e. to prevent overfitting.

[0128] After matrix transformation, we get the q, k, v vector sequence as follows:

[0129] [q 1,s ,q 2,s ,...,q n,s ],[k 1,s ,k 2,s ,...,k n,s ],[v 1,s ,v 2,s ,...,v n,s ]

[0130]

[0131] h = tanh(w t *z+b t )

[0132]

[0133] Among them, d k is the dimension of the hidden vector of the hidden layer, z is the calculation weight of self-attention, q, k, v are the conversion matrices calculated above; h is the addition of a fully connected layer, tanh is the activation function of the fully connected layer, and w t is the learning parameter of the fully connected layer, b t It is the bias of the fully connected layer, that is, to prevent overfitting; avg_pooling is to calculate the mean pooling of the output of the fully connected layer h, that is, k is the first dimension of h.

[0134] Among them, h1 is the first feature vector obtained by retaining only the domain theme features and calculating the average pooling.

[0135] The domain subject features are masked, and the latent vectors corresponding to other parts are retained. According to the above calculation method, the second feature vector h2 is calculated.

[0136] Calculate the difference between h2 and h1 as follows:

[0137]

[0138] The final feature can be expressed as: That is, all feature vectors are concatenated and finally input into the output layer through a fully connected layer.

[0139] The final features are output through a fully connected layer as follows:

[0140] f(x i )=tanh(w*hidden i +b)

[0141] The classification results probabilities are output by the softmax function:

[0142]

[0143] The loss is calculated by cross entropy, and the error is back-propagated to update the parameters:

[0144]

[0145] Where: p(y) is the true label of the positive and negative sentiment categories, and q(y) is the predicted category probability distribution calculated by the above softmax function.

[0146] Finally, the model parameters are trained through loss back propagation to obtain the final positive and negative sentiment analysis model.

[0147] It can be understood that in the process of model construction, semantic network differentiation learning is performed on domain topic features and non-domain topic features to obtain accurate contextual semantic features, thereby calculating the positive and negative attributes of emotions, thereby improving the accuracy of the model in calculating the positive and negative attributes of emotions.

[0148] Based on a general inventive concept, an embodiment of the present invention provides a positive and negative sentiment analysis device for implementing the above method embodiment.

[0149] Figure 4 A schematic diagram of a positive and negative sentiment analysis device provided by an embodiment of the present invention is shown in FIG. Figure 4 , the device may include the following structure:

[0150] The acquisition module 41 is used to acquire the data to be analyzed, and extract entity words and subject words in the data to be analyzed based on the preset entity recognition word library and the subject word library of each field;

[0151] A conversion module 42 is used to obtain domain subject features based on preset prior knowledge, entity words and subject words in the data to be analyzed, and convert the data to be analyzed into the data to be analyzed in the model input format;

[0152] The analysis module 43 is used to input the data to be analyzed in the model input format into the pre-built positive and negative sentiment analysis model to obtain the positive and negative sentiment probability values ​​of the data to be analyzed; wherein the pre-built positive and negative sentiment analysis model is obtained after training based on the model input format sample data and the corresponding positive and negative sentiment labels, and the positive and negative sentiment labels are predetermined based on the sample data and correspond one-to-one to the sample data.

[0153] Optionally, it also includes: a construction module, which is used to identify entity words in the entity word data set and construct a primary entity word library; wherein the entity word data set is constructed based on a massive data set;

[0154] Deduplication of entity words in the primary entity vocabulary is performed to obtain a primary entity vocabulary after deduplication;

[0155] Based on prior knowledge, conceptual classification is performed on entity words in the primary entity vocabulary after deduplication.

[0156] The entity words and corresponding concepts in the primary entity vocabulary after deduplication are classified as the entity recognition vocabulary.

[0157] Optionally, the construction module is further used to segment the data in the domain data set according to the Jieba word segmentation method to obtain different word segments; wherein the domain data set is constructed based on the massive data collected in the domain; the word segments include subject words;

[0158] Calculate the importance weight of each word by inverse document frequency;

[0159] Based on the importance weight of each segmentation, the firmness between subject words and subject words is calculated according to the point-by-point mutual information method;

[0160] According to the firmness between subject words and subject words and the importance weight of corresponding subject words, new importance weights of different subject words and subject word compositions are calculated as new importance weights of different subject word strings; wherein the subject word strings are composed of subject words and subject words with different firmness;

[0161] Through different subject word strings and corresponding new importance weights, a subject word library of the field is constructed; wherein each subject word in the subject word library is a subject word string.

[0162] Optionally, a construction module is specifically used to sort the corresponding subject word strings according to the order of the new importance weights;

[0163] Determine the subject word strings whose new importance weights are within the preset range before sorting or the subject word strings whose new importance weights are greater than a preset threshold as the subject word strings of the field, and construct the subject word library of the field.

[0164] Optionally, a construction module is specifically used to calculate the sum of importance weights of all subject words corresponding to the firmness;

[0165] The product of the sum and the corresponding subject word and the firmness between the subject words is calculated, and the product is used as the new importance weight.

[0166] Optionally, the construction module is further used to obtain sample data in the sample set, and the samples in the sample set are all set with positive and negative emotional labels; wherein the sample data in the sample set are collected and obtained through domain keywords;

[0167] Extract entity words and subject words from sample data based on the pre-set entity recognition word library and subject word library of each field;

[0168] According to the preset prior knowledge, entity words and subject words in the sample data, the domain subject features are obtained, and the sample data is converted into the model input format sample data;

[0169] Input the sample data in the model input format into the BERT model to obtain sentence vectors and word-level vector sequences; wherein the word-level vector sequence includes multiple word-level vectors;

[0170] Only retain the domain theme features, calculate the average pooling, and obtain the first feature vector;

[0171] Only features other than domain theme features are retained, pooling is calculated, and the second feature vector is obtained;

[0172] Calculate the difference between the first eigenvector and the second eigenvector;

[0173] The sentence vector, the first feature vector, the second feature vector, and the difference are concatenated to obtain the final feature, which is then input into the fully connected layer, which is connected to the output layer.

[0174] Calculate the loss function, train the model, and obtain the positive and negative sentiment analysis model.

[0175] Optionally, the building module is also used to perform sentiment analysis on the feature classification results output by the fully connected layer using a softmax classifier in the output layer to obtain a sentiment analysis result.

[0176] 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.

[0177] By pre-building an entity recognition vocabulary and a subject vocabulary of a field, it is possible to automatically extract subject words and entity words from the data to be analyzed, and then correspond them to subject words and entity words based on prior knowledge, convert the data to be analyzed into model input format data to be analyzed, and input them into a pre-built positive and negative sentiment analysis model to obtain the positive and negative sentiment probability values ​​of the data to be analyzed. Specifically, the specific field is taken into consideration when processing the data to be analyzed, thereby improving the accuracy of the analysis results. In addition, the automatic extraction of entity words and subject words within the field avoids the technical problem of manually annotating each word one by one, freeing up most of the manual annotation work, saving manpower and time, and introducing prior knowledge of subject words in professional fields, further improving the semantic understanding ability of the model.

[0178] Based on a general inventive concept, an embodiment of the present invention also provides a positive and negative sentiment analysis device for implementing the above method embodiment.

[0179] Figure 5 A schematic diagram of a positive and negative sentiment analysis device provided by an embodiment of the present invention, see Figure 5 The positive and negative sentiment analysis device of this embodiment includes a processor 51 and a memory 52, and the processor 51 is connected to the memory 52. ​​The processor 51 is used to call and execute the program stored in the memory 52; the memory 52 is used to store the program, and the program is at least used to execute the positive and negative sentiment analysis method in the above embodiment.

[0180] The specific implementation scheme of the positive and negative sentiment analysis device provided in the embodiments of the present application can refer to the implementation scheme of the positive and negative sentiment analysis method in any of the above embodiments, which will not be repeated here.

[0181] 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.

[0182] It should be noted that, in the description of the present invention, 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 the present invention, unless otherwise specified, the meaning of "plurality" refers to at least two.

[0183] 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 invention 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 those skilled in the art to which the embodiments of the present invention belong.

[0184] It should be understood that the various parts of the present invention can be implemented by hardware, software, firmware or a combination thereof. In the above-mentioned embodiments, a plurality of 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.

[0185] A person skilled in the art may understand that all or part of the steps in the method for implementing the above-mentioned embodiment 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.

[0186] In addition, each functional unit in each embodiment of the present invention 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.

[0187] The storage medium mentioned above can be a read-only memory, a magnetic disk or an optical disk, etc.

[0188] In the description of this specification, the description with reference to the terms "one embodiment", "some embodiments", "examples", "specific examples", 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 invention. 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.

[0189] Although the embodiments of the present invention have been shown and described above, it is to be understood that the above embodiments are exemplary and are not to be construed as limitations of the present invention. A person skilled in the art may change, modify, replace and vary the above embodiments within the scope of the present invention.

Claims

1. A positive and negative sentiment analysis method, characterized in that: include: Acquire the data to be analyzed, and extract entity words and subject words in the data to be analyzed based on a preset entity recognition word library and a subject word library of each field; According to the preset prior knowledge, entity words and subject words in the data to be analyzed, domain subject features are obtained; according to the domain subject features and the data to be analyzed, the data to be analyzed is converted into data to be analyzed in a model input format; Inputting the data to be analyzed in the model input format into a pre-constructed positive and negative sentiment analysis model to obtain positive and negative sentiment probability values ​​of the data to be analyzed; wherein the pre-constructed positive and negative sentiment analysis model is obtained after training based on the model input format sample data and the corresponding positive and negative sentiment labels, and the positive and negative sentiment labels are predetermined according to the sample data and correspond one-to-one to the sample data; The method for constructing the positive and negative sentiment analysis model includes: Acquire sample data from a sample set, wherein the samples in the sample set are all set with positive and negative emotion labels; wherein the sample data in the sample set are collected and acquired through domain keywords; Extracting entity words and subject words from the sample data based on a preset entity recognition word library and a subject word library for each field; According to the preset prior knowledge, entity words and subject words in the sample data, domain subject features are obtained; according to the domain subject features and the sample data, the sample data is converted into model input format sample data; Input the sample data in the model input format into the BERT model to obtain a sentence vector and a word-level vector sequence; wherein the word-level vector sequence includes multiple word-level vectors; Only retain the domain theme features and calculate the average pooling to get the first feature vector; Only features other than the domain theme features are retained, and pooling is performed to obtain a second feature vector; Calculating a difference between the first eigenvector and the second eigenvector; Concatenate the sentence vector, the first feature vector, the second feature vector, and the difference to obtain a final feature, and input the final feature into a fully connected layer, wherein the fully connected layer is connected to an output layer; Calculate the loss function, train the model, and obtain the positive and negative sentiment analysis model.

2. The method according to claim 1, characterized in that The entity recognition word library includes entity words and concept classification of each entity word; wherein the concept classification is classified according to prior knowledge; the method for constructing the entity recognition word library includes: Identify entity words in an entity word data set and construct a primary entity word library; wherein the entity word data set is constructed based on a massive data set; Deduplication processing is performed on entity words in the primary entity vocabulary to obtain a primary entity vocabulary after deduplication; Based on prior knowledge, conceptual classification is performed on the entity words in the primary entity word library after deduplication; The entity words and corresponding concepts in the primary entity vocabulary after deduplication are classified as the entity recognition vocabulary.

3. The method according to claim 1, characterized in that The method for constructing the subject word library of each field includes: The data in the domain data set is segmented according to the Jieba word segmentation method to obtain different segmented words; wherein the domain data set is constructed based on the massive data collected in the domain; the segmented words include subject words; Calculate the importance weight of each word by inverse document frequency; Based on the importance weight of each word, the solidity between the subject words is calculated according to the point-by-point mutual information method; According to the firmness between the subject words and the subject words and the importance weight of the corresponding subject words, new importance weights of different subject words and subject words are calculated as new importance weights of different subject word strings; wherein the subject word strings are composed of subject words and subject words with different firmness; A subject word library of the field is constructed by using different subject word strings and corresponding new importance weights; wherein each subject word in the subject word library is a subject word string.

4. The method according to claim 3, characterized in that: The subject word library of the field is constructed by using different subject word strings and corresponding new importance weights, including: Sort the corresponding subject word strings according to the new importance weights; Determine the subject word strings whose new importance weights are within the preset range before sorting or the subject word strings whose new importance weights are greater than a preset threshold as the subject word strings of the field, and construct the subject word library of the field.

5. The method according to claim 3, characterized in that: The method of calculating the new importance weights of different subject words and subject word combinations based on the solidity between the subject words and the importance weights of the corresponding subject words as the new importance weights of different subject word strings includes: Calculate the sum of the importance weights of all the corresponding keywords with firmness; The product of the sum of the importance weights and the corresponding solidity between the subject words is calculated, and the product is used as the new importance weight.

6. The method according to claim 1, characterized in that Also includes: In the output layer, a softmax classifier is used to perform sentiment analysis on the feature classification results output by the fully connected layer to obtain a sentiment analysis result.

7. A positive and negative sentiment analysis device, characterized in that: include: An acquisition module is used to acquire the data to be analyzed, and extract entity words and subject words in the data to be analyzed based on a preset entity recognition word library and a subject word library of each field; A conversion module, used to obtain domain subject features based on preset prior knowledge, entity words and subject words in the data to be analyzed; and convert the data to be analyzed into model input format data to be analyzed based on the domain subject features and the data to be analyzed; The analysis module is used to input the data to be analyzed in the model input format into a pre-constructed positive and negative sentiment analysis model to obtain the positive and negative sentiment probability values ​​of the data to be analyzed; wherein the pre-constructed positive and negative sentiment analysis model is obtained after training based on the model input format sample data and the corresponding positive and negative sentiment labels, and the positive and negative sentiment labels are predetermined according to the sample data and correspond one-to-one with the sample data; wherein the construction method of the positive and negative sentiment analysis model includes: Acquire sample data from a sample set, wherein the samples in the sample set are all set with positive and negative emotion labels; wherein the sample data in the sample set are collected and acquired through domain keywords; Extracting entity words and subject words from the sample data based on a preset entity recognition word library and a subject word library for each field; According to the preset prior knowledge, entity words and subject words in the sample data, domain subject features are obtained; according to the domain subject features and the sample data, the sample data is converted into model input format sample data; Input the sample data in the model input format into the BERT model to obtain a sentence vector and a word-level vector sequence; wherein the word-level vector sequence includes multiple word-level vectors; Only retain the domain theme features and calculate the average pooling to get the first feature vector; Only features other than the domain theme features are retained, and pooling is performed to obtain a second feature vector; Calculating a difference between the first eigenvector and the second eigenvector; Concatenate the sentence vector, the first feature vector, the second feature vector, and the difference to obtain a final feature, and input the final feature into a fully connected layer, wherein the fully connected layer is connected to an output layer; Calculate the loss function, train the model, and obtain the positive and negative sentiment analysis model.

8. A positive and negative sentiment analysis device, characterized in that: include: A processor and a memory, wherein the processor is connected to the memory: Wherein, the processor is used to call and execute the program stored in the memory; The memory is used to store the program, and the program is at least used to execute the positive and negative sentiment analysis method described in any one of claims 1-6.

9. A non-transitory computer-readable storage medium storing computer instructions, wherein: The computer instructions are used to enable the computer to execute the positive and negative sentiment analysis method described in any one of claims 1 to 6.

Citation Information

Patent Citations

  • Emotion analysis method and device based on domain information, equipment and storage medium

    CN113672731A

  • Named entity recognition method and apparatus, and electronic device and readable storage medium

    WO2022048210A1