Emotion analysis model training optimization method, system and storage medium
Technical Field
The invention relates to the technical field of emotion analysis, in particular to an emotion analysis model training optimization method, system and storage medium.
Background
Emotion Analysis (Sentiment Analysis) refers to a process of analyzing, processing and extracting subjective texts with emotion colors by utilizing natural language processing and text mining technologies; at present, the text sentiment analysis research covers a plurality of fields including natural language processing, text mining, information retrieval, information extraction, machine learning, ontology and the like, and is concerned by a plurality of scholars and research institutions, and the research is continuously one of the hot problems of the research of the fields of natural language processing and text mining in recent years.
Most of the existing emotion analysis solutions are regarded as a multi-classification task, namely after a text to be analyzed is input, a sentence is expressed into a vector through a BERT model, multi-classification prediction is carried out on the basis of the vector, the probabilities of positive, neutral and negative emotions are output, and finally, the emotion category with the highest probability is taken as an output category; the prior art has the defects that only input text information is used in a representation stage, emotion labels are only used as the basis of probability calculation in a final output layer, and the representation of the emotion labels is lacked, so that emotion analysis is not accurate enough.
Disclosure of Invention
The invention mainly solves the technical problem of providing an emotion analysis model training optimization method, system and storage medium, and can solve the problem of inaccurate emotion analysis caused by lack of expression of emotion labels.
In order to solve the technical problems, the invention adopts a technical scheme that: an emotion analysis model training optimization method is provided, wherein the model comprises a self-attention mechanism module and a multi-layer perceptron module, and the method comprises the following steps:
firstly, acquiring a text and an emotion label, and inputting the text and the emotion label into the self-attention mechanism module of the model;
secondly, performing feature fusion on the text and the emotion label through the self-attention mechanism module to obtain a fusion representation identifier;
inputting the fusion representation identification into the multilayer perceptron module and calculating to obtain the matching degree of the text and the emotion label; optimizing a loss function based on the matching degree to enable the model to reach a convergence state, so as to obtain an optimized model;
and fourthly, performing emotion analysis on the input text to be predicted through the optimization model.
As an improvement, the obtaining the text and the emotion label further comprises the following steps:
the text and emotion labels are concatenated using separators.
Further specifically, the text comprises at least one text and the emotion tag comprises at least one emotion tag.
As an improvement, the feature fusion is performed on the text and the emotion tag through the self-attention mechanism module to obtain a fusion representation identifier, further comprising the following steps:
performing feature fusion on the text through the self-attention mechanism module;
performing feature fusion on the emotion label through the self-attention mechanism module;
and performing feature fusion on the text subjected to feature fusion and the emotion label subjected to feature fusion through the self-attention mechanism module to obtain the fusion representation identifier.
As an improvement, the optimizing the loss function based on the matching degree to make the model reach a convergence state further includes the following steps:
and optimizing a loss function by adopting a gradient back-transmission algorithm based on the matching degree to enable the model to reach a convergence state.
As an improvement, the emotion analysis is performed on the input text to be predicted through the optimization model, and the method further includes the following steps:
acquiring a text to be predicted and a plurality of emotion labels, and outputting the matching degree of the text to be predicted and each emotion label by the optimization model;
and arranging the matching degrees of the text to be predicted and each emotion label in a descending order, and outputting the emotion label corresponding to the first sorted matching degree as the emotion label of the text to be predicted.
The invention also provides an emotion analysis model training optimization system, wherein the model comprises a self-attention mechanism module and a multilayer perceptron module, and the emotion analysis model training optimization system comprises:
a feature fusion unit: the system comprises a self-attention mechanism module, a text and emotion label acquisition module, a self-attention mechanism module and a self-attention mechanism module, wherein the self-attention mechanism module is used for acquiring the text and emotion label;
a model training unit: the fusion representation identifier is input into the multilayer perceptron module and is calculated to obtain the matching degree of the text and the emotion label; optimizing a loss function by adopting a gradient pass-back algorithm based on the matching degree to enable the model to reach a convergence state, so as to obtain an optimized model;
an emotion analysis unit: the method comprises the steps of obtaining a text to be predicted and a plurality of emotion labels, and outputting the matching degree of the text to be predicted and each emotion label through the optimization model; the emotion label sorting module is used for sorting the matching degree of the text to be predicted and each emotion label in a descending order and outputting the emotion label corresponding to the first sorted matching degree.
The invention also provides a computer storage medium for storing computer software instructions for the method for optimizing the training of the emotion analysis model, which comprises a program for executing the method for optimizing the training of the emotion analysis model.
The invention has the beneficial effects that:
1. according to the emotion analysis model training optimization method, the emotion labels and the text are input into the BERT model together, and feature fusion is performed, so that emotion analysis on the text is more accurate.
2. The emotion analysis model training optimization system provided by the invention adopts the feature fusion unit to enable the text information to comprise emotion label information, so that the input information is more sufficient, and the emotion analysis is more accurate.
3. The data transmission storage medium realizes the emotion analysis of the text by executing the emotion analysis model training optimization method.
Drawings
In order to more clearly illustrate the detailed description of the invention or the technical solutions in the prior art, the drawings needed in the detailed description or the prior art description are briefly introduced below; throughout the drawings, like elements or portions are generally identified by like reference numerals; in the drawings, elements or portions are not necessarily drawn to scale.
FIG. 1 is a flowchart of an emotion analysis model training optimization method according to embodiment 1 of the present invention;
FIG. 2 is a schematic view of feature fusion according to example 1 of the present invention;
FIG. 3 is a schematic diagram of an emotion analysis model training optimization system according to embodiment 2 of the present invention.
The parts in the drawings are numbered as follows:
1-feature fusion unit, 2-model training unit, 3-emotion analysis unit and 100-emotion analysis model training optimization system.
Detailed Description
The technical solutions of the present invention will be described clearly and completely with reference to the accompanying drawings, and it is obvious that the described embodiments are some, not all embodiments of the present invention; all other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
In the description of the present invention, it is to be noted that, unless otherwise explicitly specified or limited, the term "connected" is to be interpreted broadly, e.g. as a fixed connection, a detachable connection, or an integral connection; can be mechanically or electrically connected; the two elements can be directly connected or indirectly connected through an intermediate medium, or the two elements can be communicated with each other, or the two elements can be in wireless connection or wired connection; the specific meanings of the above terms in the present invention can be understood in specific cases to those skilled in the art.
In the description of the present invention, it should be noted that, for example, MLP (Muti-Layer probability) is a multi-Layer perceptron module, and bert (bidirectional Encoder Representation from transforms) is a bidirectional coding Representation based on a converter, and is a pre-trained language Representation model.
Example 1
This embodiment 1 provides an emotion analysis model training optimization method, as shown in fig. 1, including the following steps:
in the S100 step, connecting the text X and the emotion label L by using a separator, and inputting a BERT model; the BERT model comprises a self-attention mechanism module and a multi-layer perceptron module; combining a text X and an emotion label L into a sample, and inputting three samples because scoring of three emotion labels L is used during optimization training; the three samples were placed in the same group; in this embodiment, the samples that need to be input are arranged as follows:
sample 1: < 'I like sunny days', 'forward';
sample 2: < 'I like sunny days', 'negative direction';
sample 3: < 'I like sunny days', 'neutral' >.
In the step S200, as shown in fig. 2, the text X inside, the emotion tag L inside, the text X and the emotion tag L are fully fused by the attention mechanism module of the BERT model to obtain a fusion representation identifier CLS, so that the text X information is fused with the emotion tag L information, and the emotion tag L information is also fused with the text X information; after the multi-layer fusion representation of the BERT model, the output aspect characteristics of each coding layer of the BERT model are fused, the key semantic characteristics between layers are extracted through the convolutional layers, the influence of redundant information is reduced, the information learned by each coding layer is fully utilized, and finally the text X information and the emotion label L information are fused by the fusion representation identification CLS;
the fused representation identifier CLS may be represented as:
H[CLS]=BERT(X,L)。
in the step S300, a multi-Layer perceptron Module (MLP) of a BERT model is input into a fusion representation CLS and is calculated to obtain the matching degree (score) of the text X and the emotion label L; the matching degree calculation is expressed as:
Score=MLP(H[CLS]);
optimizing a loss function by adopting a gradient back-transmission algorithm according to the matching degree to enable the BERT model to reach a convergence state, so as to obtain an optimized BERT model; the loss function is expressed as:
wherein, Back _ size is the number of input samples, SlFor the degree of match of the text X and the correct emotion label L, SaAnd SbFor the matching degree of the text X and the other two emotion labels L, minimizing Loss means maximizing the difference between the matching degree of the text X and the correct emotion label L and the matching degree of the text X and the wrong emotion label L, so that the matching degree of the BERT model on the correct emotion label L is improved.
In the step S400, positive, neutral and negative emotion labels L and text X are respectively input into the optimized BERT model to calculate the matching degree of the emotion labels L and the text X, and then the emotion label L with the highest matching degree is taken as the emotion label L of the text X to be output; in this embodiment, to predict the emotional tendency of "i feel good on sunny day", there are three inputs:
input 1: < 'I feel good on sunny days', 'forward';
input 2: < 'I feel good in sunny days', 'neutral';
input 3: < 'I feel good on sunny days', 'negative direction';
and (3) fusing the three inputs in a BERT model to obtain a fusion representation identification CLS, inputting the fusion representation identification CLS into an MLP (maximum likelihood ratio) to calculate the matching degree to obtain [0.8, 0.2 and 0.1], wherein the input 1 has the highest matching degree, and then outputting the emotional tendency of 'I feel good in sunny days' as 'forward'.
Example 2
The embodiment 2 provides an emotion analysis model training optimization system, wherein a BERT model comprises a self-attention mechanism module and a multilayer perceptron module; as shown in fig. 3, the emotion analysis model training optimization system 100 includes:
feature fusion unit 1: the system comprises a BERT model, a feature fusion module, a fusion expression identification and a text information fusion module, wherein the BERT model is used for performing feature fusion on the acquired text and emotion labels through the self-attention mechanism module of the BERT model to obtain fusion expression identification, so that the text information is fused with emotion label information, and the emotion label information is also fused with text information; the fusion representation mark fuses text information and emotion label information;
model training unit 2: a multi-Layer perceptron Module (MLP) for inputting the fusion representation identification into the BERT model and calculating to obtain the matching degree of the text and the emotion label; optimizing a loss function by adopting a gradient back-transmission algorithm based on the matching degree to enable the BERT model to reach a convergence state, so as to obtain an optimized BERT model;
emotion analysis section 3: the method comprises the steps that a text to be predicted and a plurality of emotion labels are input into an optimized BERT model, and the optimized BERT model calculates the matching degree of the text to be predicted and each emotion label; and comparing the matching degree of each emotion label with the text to be predicted, outputting the emotion label corresponding to the highest matching degree as the emotion label of the text to be predicted, and realizing emotion analysis of the text to be predicted.
Example 3
This embodiment 3 provides a computer-readable storage medium, storing computer software instructions for implementing the emotion analysis model training optimization method described in embodiment 1 above, and comprising a program designed for executing the emotion analysis model training optimization method; specifically, the executable program may be built in the emotion analysis model training optimization system 100, so that the emotion analysis model training optimization system 100 may implement the emotion analysis model training optimization method of embodiment 1 by executing the built-in executable program.
Furthermore, the computer-readable storage medium provided by the present embodiments may take any combination of one or more readable storage media, where a readable storage medium includes an electronic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination thereof.
The serial numbers of the embodiments disclosed in the above embodiments are merely for description and do not represent the merits of the embodiments.
The above description is only an embodiment of the present invention, and not intended to limit the scope of the present invention, and all modifications of equivalent structures and equivalent processes performed by the present specification and drawings, or directly or indirectly applied to other related technical fields, are included in the scope of the present invention.