Detailed Description
In order to make the technical solutions better understood by those skilled in the art, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the drawings in the embodiments of the present application, and it is obvious that the described embodiments are only partial embodiments of the present application, but not all embodiments. 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 application.
It should be noted that the terms "first," "second," and the like in the description and claims of this application and in the drawings described above are used for distinguishing between similar elements and not necessarily for describing a particular sequential or chronological order. It is to be understood that the data so used is interchangeable under appropriate circumstances such that the embodiments of the application described herein are capable of operation in sequences other than those illustrated or described herein. Furthermore, the terms "comprises," "comprising," and "having," and any variations thereof, are intended to cover a non-exclusive inclusion, such that a process, method, system, article, or apparatus that comprises a list of steps or elements is not necessarily limited to those steps or elements expressly listed, but may include other steps or elements not expressly listed or inherent to such process, method, article, or apparatus.
In accordance with an embodiment of the present application, there is provided a method embodiment of a model training method, it should be noted that the steps illustrated in the flowchart of the figure may be performed in a computer system, such as a set of computer-executable instructions, and that while a logical order is illustrated in the flowchart, in some cases the steps illustrated or described may be performed in an order different than here.
Fig. 1 is a flowchart of a model training method according to an embodiment of the present application, as shown in fig. 1, the method includes the following steps:
step S102, acquiring text information with emotion marks, wherein the text information comprises a plurality of sentences marked according to predefined emotion types, and each sentence carries the emotion mark corresponding to the sentence.
The text information with emotion marks in the embodiment of the application can be text information formed by manually marking the emotion of each sentence in a pre-collected text information sample. The emotion classification of the statement can be set as required, and the emotion classification can be a customized standard classification, such as if the statement emotion is divided into three types: positive, neutral, and negative, respectively, are labeled with 1,0, -1 for emotion correspondence, or are divided into five types: happiness, sadness, anger, fear, disgust, etc.
Step S104, determining a statement vector corresponding to each statement in the text information, wherein the statement vector is a multidimensional array used for uniquely representing the corresponding statement.
After the text information with the emotion marks is obtained, statement vectors corresponding to each statement in the text are determined, the statement vectors corresponding to each statement can be statement vectors generated according to a predefined rule, and the statement vectors corresponding to different statements are different. Because each sentence in the text information carries the corresponding emotion mark, the sentence vector corresponding to each sentence also corresponds to the same emotion mark as the sentence.
And S106, inputting the emotion marks corresponding to each statement and the statement vectors corresponding to the emotion marks into a cyclic neural network, and training to obtain a neural network model, wherein the neural network model is used for identifying the emotion types in the statements.
In this embodiment, after determining a sentence vector corresponding to each sentence of the text information, the sentence vectors carrying emotion marks are sequentially input into the recurrent neural network to be trained, so as to obtain the neural network model.
By inputting the statement vector corresponding to the statement in the text into the recurrent neural network, the machine can memorize the words and their combinations and their corresponding emotion marks in the statement, and memorize these words and their combinations and their corresponding emotion marks with the parameters in the neural network model (the parameters in the neural network model are determined, mostly as a matrix).
When the neural network model is used for emotion recognition of sentences, the emotion types of the sentences in the text can be effectively and quickly recognized according to the context of the sentences, and compared with the mode that the sentences are recognized through emotion keywords and the like in the prior art, the accuracy of the sentence emotion recognition through the neural network model is greatly improved.
According to the embodiment of the application, text information with emotion marks is obtained, wherein the text information comprises a plurality of sentences marked according to predefined emotion types, and each sentence carries the emotion mark corresponding to the sentence; determining a statement vector corresponding to each statement in the text information, wherein the statement vector is a multidimensional array used for uniquely representing the corresponding statement; the emotion marks corresponding to each sentence and the sentence vectors corresponding to the emotion marks are input into a cyclic neural network, and a neural network model is obtained through training, so that the emotion types in the sentences can be conveniently recognized through the neural network model, the technical problem that the emotion recognition accuracy contained in the sentences is low in the prior art is solved, and the effect of improving the emotion recognition accuracy in the sentences is achieved.
Preferably, determining a sentence vector corresponding to each sentence in the text information includes: performing word segmentation processing on each sentence in the text information; searching a word vector corresponding to each word after each sentence is participated, wherein the word vector is a multidimensional array for uniquely representing the corresponding word; and determining the sentence vector of the corresponding sentence according to the word vector corresponding to each word in each sentence.
In this embodiment, for determining the sentence vectors, word segmentation processing may be performed on each sentence, and then the word vector corresponding to each word in each sentence is queried. Wherein the word segmentation result is to arrange words in order according to the original sentence, including punctuation marks such as "will you not sing? "do the participles" do you not sing a song? "or" do you not sing? ". The word vector of each term may be obtained by searching the word vector corresponding to each term from a pre-generated word vector set, or may be generated by using a pre-generated rule.
Generating a statement vector corresponding to a statement according to a word vector corresponding to a word in the statement may be to add word vectors corresponding to each word in the statement to obtain a statement vector corresponding to the statement, that is, to use a value obtained by adding a value at a corresponding position of each word vector as a value at the corresponding position of the statement vector; or adding the word vectors corresponding to each word in the sentence and dividing the added word vectors by the number of the word vectors, namely adding the numerical value at the corresponding position of each word vector and dividing the numerical value by the number of the word vectors to obtain a value serving as the numerical value at the corresponding position of the sentence vector.
Further, before searching for a word vector corresponding to each word after each sentence is participated, the model training method further includes: acquiring text information with preset data volume to obtain a text information set; generating a word vector of each word in the text information set by using a machine learning mode to obtain a word vector set; searching for the word vector corresponding to each word after each sentence is participated comprises: and searching a word vector corresponding to each word after word segmentation from the word vector set.
In this embodiment, a large amount of text information is collected as a training text set, and word vectors are generated by using a machine learning method to obtain a word vector set of texts related to each service type. The word vector is generated by a machine learning method, and can be obtained by a method of performing word vector training by using Google word2vec and the like.
By means of the pre-generated word vector set, when the statement vector is generated according to the word vector, the word vector of the corresponding word can be directly inquired from the word vector set, and therefore the determining efficiency of the statement vector is improved.
Further, determining the sentence vector of the corresponding sentence according to the word vector corresponding to each word in each sentence includes: for each statement, adding word vectors corresponding to all words contained in the statement to obtain a word vector sum, wherein the word vector sum is a vector which is obtained by adding numerical values of corresponding positions in the word vectors and has the same number of dimensions as the word vectors; and dividing the word vector sum by the number of the words to obtain a statement vector, wherein the word vector sum divided by the number of the words refers to a numerical value of each position in the word vector sum divided by the number of the words.
In this embodiment, the word vectors corresponding to each word in the sentence are added and then divided by the number of the word vectors, that is, the numerical value at the corresponding position of each word vector is added and then divided by the number of the word vectors, and the obtained value is used as the numerical value at the corresponding position of the sentence vector.
For example, for "do you not sing a song? "sentence vector, which is segmented into words to get" do you not sing? "assume where" you "correspond to a word vector of [1,0,0,0,0, … … ]," none "corresponds to a word vector of [0,1,0,0,0, … … ]," sing "corresponds to a word vector of [0,0,1,0,0, … … ],"? "the corresponding word vector is [0,0,0,0,1, … … ], then the calculated statement vector for the statement is [0.25,0.25,0.25,0,0.25, … … ].
An optional mode of the model training method in the embodiment of the present application includes:
step one, collecting a large amount of text information as a training text set.
And step two, performing word segmentation on the training text set, and generating a word vector of each word in the text by using a machine learning method to obtain a word vector set. The word vector generated by the machine learning method can be obtained by using Google word2vec to perform word vector training and the like.
And step three, collecting new text information, performing word segmentation on the text information, and performing manual labeling on emotion classification of each sentence in the text information to serve as a sentence emotion training set. The emotion classification can be a custom standard classification, for example, if the sentence emotion is classified into three types: positive, neutral, and negative, respectively, are labeled with 1,0, -1 for emotion correspondence, or are divided into five types: happiness, sadness, anger, fear and disgust.
And step four, obtaining a statement vector with emotion marks corresponding to each statement in the statement emotion training set according to the word vector set, and using the statement vector as the statement vector training set. The statement vector may be calculated by: and adding the word vectors corresponding to each word in the sentence and dividing the sum by the number of the word vectors.
And step five, training the statement vector training set obtained in the step four by using an RNN (recurrent neural network) model to obtain an RNN training model. The machine can memorize words and their combination forms in the sentences and emotion labels of the sentences by using the sentence vectors as the input content of the RNN (recurrent neural network) initial model, and memorize the combinations by using the parameters in the model.
In the embodiment of the application, after the sentences and the emotions are represented by data, machine learning is carried out, the emotion types of the text sentences can be effectively and quickly identified based on context semantics, the problem that in the prior art, the sentence emotion classification accuracy is low by identifying the sentences according to the semantics of the sentences is solved, and the effect of improving the sentence emotion classification accuracy is achieved.
According to the embodiment of the application, a sentence emotion recognition method is further provided, and the sentence emotion recognition method can be used for recognizing the service type of the sentence to be detected through the neural network model obtained through the model training method of the embodiment of the application. As shown in fig. 2, the sentence emotion recognition method includes:
step S202, determining a sentence vector corresponding to each sentence in the text to be tested.
For the determination of the statement vector corresponding to the statement to be detected, reference may be made to the determination manner of the statement vector corresponding to the statement in the collected text information with emotion marks in the above embodiments of the present application, which is not described herein again.
Step S204, inputting the statement vector corresponding to each statement in the text to be detected into the neural network model, and identifying the emotion type of each statement in the text to be detected by using the neural network model.
The neural network model of the embodiment of the present application is a neural network model obtained by training the model training method of the above embodiment of the present application. Inputting the statement vector of the text to be tested into the RNN training model to obtain the emotion type of each statement, wherein the mark is 1 to represent positive, the mark is 0 to represent neutral, the mark is-1 to represent negative, and the mark depends on the definition mode of the mark of the emotion type.
Because the machine can memorize words and words in the sentences and combinations thereof and corresponding emotion marks by inputting the sentence vectors corresponding to the sentences in the text into the cyclic neural network and memorize the words and the combinations thereof and the corresponding emotion marks by using parameters (most of which are determined by parameters in the neural network model) in the neural network model, when the neural network model is used for carrying out emotion recognition on the sentences, the emotion types of the sentences in the text can be effectively and quickly recognized according to the context of the sentences, and compared with the mode of recognizing the emotion of the sentences by using emotion keywords and the like in the prior art, the accuracy of recognizing the emotion of the sentences by the neural network model is greatly improved.
An embodiment of the present application further provides a model training apparatus, which may be used to execute the model training method according to the embodiment of the present application, and as shown in fig. 3, the apparatus includes: an acquisition unit 301, a determination unit 303 and a training unit 305.
The acquiring unit 301 is configured to acquire text information with emotion marks, where the text information includes a plurality of sentences marked according to predefined emotion types, and each sentence carries an emotion mark corresponding to the sentence.
The text information with emotion marks in the embodiment of the application can be text information formed by manually marking the emotion of each sentence in a pre-collected text information sample. The emotion classification of the statement can be set as required, and the emotion classification can be a customized standard classification, such as if the statement emotion is divided into three types: positive, neutral, and negative, respectively, are labeled with 1,0, -1 for emotion correspondence, or are divided into five types: happiness, sadness, anger, fear, disgust, etc.
The determining unit 303 is configured to determine a statement vector corresponding to each statement in the text information, where the statement vector is a multidimensional array for uniquely representing the corresponding statement.
After the text information with the emotion marks is obtained, statement vectors corresponding to each statement in the text are determined, the statement vectors corresponding to each statement can be statement vectors generated according to a predefined rule, and the statement vectors corresponding to different statements are different. Because each sentence in the text information carries the corresponding emotion mark, the sentence vector corresponding to each sentence also corresponds to the same emotion mark as the sentence.
The training unit 305 is configured to input the emotion mark corresponding to each sentence and the sentence vector corresponding to the emotion mark into a cyclic neural network, and train to obtain a neural network model, where the neural network model is used to identify an emotion type in the sentence.
In this embodiment, after determining a sentence vector corresponding to each sentence of the text information, the sentence vectors carrying emotion marks are sequentially input into the recurrent neural network to be trained, so as to obtain the neural network model.
By inputting the statement vector corresponding to the statement in the text into the recurrent neural network, the machine can memorize the words and their combinations and their corresponding emotion marks in the statement, and memorize these words and their combinations and their corresponding emotion marks with the parameters in the neural network model (the parameters in the neural network model are determined, mostly as a matrix).
When the neural network model is used for emotion recognition of sentences, the emotion types of the sentences in the text can be effectively and quickly recognized according to the context of the sentences, and compared with the mode that the sentences are recognized through emotion keywords and the like in the prior art, the accuracy of the sentence emotion recognition through the neural network model is greatly improved.
According to the embodiment of the application, text information with emotion marks is obtained, wherein the text information comprises a plurality of sentences marked according to predefined emotion types, and each sentence carries the emotion mark corresponding to the sentence; determining a statement vector corresponding to each statement in the text information, wherein the statement vector is a multidimensional array used for uniquely representing the corresponding statement; the emotion marks corresponding to each sentence and the sentence vectors corresponding to the emotion marks are input into a cyclic neural network, and a neural network model is obtained through training, so that the emotion types in the sentences can be conveniently recognized through the neural network model, the technical problem that the emotion recognition accuracy contained in the sentences is low in the prior art is solved, and the effect of improving the emotion recognition accuracy in the sentences is achieved.
Preferably, the determination unit includes: the word segmentation module is used for carrying out word segmentation processing on each sentence in the text information; the query module is used for searching a word vector corresponding to each word after each sentence is subjected to word segmentation, wherein the word vector is a multidimensional array used for uniquely representing the corresponding word; and the determining module is used for determining the sentence vector of the corresponding sentence according to the word vector corresponding to each word in each sentence.
In this embodiment, for determining the sentence vectors, word segmentation processing may be performed on each sentence, and then the word vector corresponding to each word in each sentence is queried. Wherein the word segmentation result is to arrange words in order according to the original sentence, including punctuation marks such as "will you not sing? "do the participles" do you not sing a song? "or" do you not sing? ". The word vector of each term may be obtained by searching the word vector corresponding to each term from a pre-generated word vector set, or may be generated by using a pre-generated rule.
Generating a statement vector corresponding to a statement according to a word vector corresponding to a word in the statement may be to add word vectors corresponding to each word in the statement to obtain a statement vector corresponding to the statement, that is, to use a value obtained by adding a value at a corresponding position of each word vector as a value at the corresponding position of the statement vector; or adding the word vectors corresponding to each word in the sentence and dividing the added word vectors by the number of the word vectors, namely adding the numerical value at the corresponding position of each word vector and dividing the numerical value by the number of the word vectors to obtain a value serving as the numerical value at the corresponding position of the sentence vector.
Further, the model training device further comprises: the acquisition unit is used for acquiring text information with preset data volume before searching for a word vector corresponding to each word after each sentence is participled to obtain a text information set; the generating unit is used for generating a word vector of each word in the text information set by utilizing a machine learning mode to obtain a word vector set; the query module is specifically configured to find a word vector corresponding to each word after word segmentation from the word vector set.
In this embodiment, a large amount of text information is collected as a training text set, and word vectors are generated by using a machine learning method to obtain a word vector set of texts related to each service type. The word vector is generated by a machine learning method, and can be obtained by a method of performing word vector training by using Google word2vec and the like.
By means of the pre-generated word vector set, when the statement vector is generated according to the word vector, the word vector of the corresponding word can be directly inquired from the word vector set, and therefore the determining efficiency of the statement vector is improved.
Further, the determining module includes: the first calculation submodule is used for adding word vectors corresponding to all words contained in each statement to obtain a word vector sum, wherein the word vector sum is a vector which is obtained by adding numerical values of corresponding positions in the word vectors and has the same number of dimensions as the word vectors; and the second calculation submodule is used for dividing the word vector sum by the number of the words to obtain a statement vector, wherein the word vector sum divided by the number of the words refers to a numerical value of each position in the word vector sum divided by the number of the words.
In this embodiment, the word vectors corresponding to each word in the sentence are added and then divided by the number of the word vectors, that is, the numerical value at the corresponding position of each word vector is added and then divided by the number of the word vectors, and the obtained value is used as the numerical value at the corresponding position of the sentence vector.
For example, for "do you not sing a song? "sentence vector, which is segmented into words to get" do you not sing? "assume where" you "correspond to a word vector of [1,0,0,0,0, … … ]," none "corresponds to a word vector of [0,1,0,0,0, … … ]," sing "corresponds to a word vector of [0,0,1,0,0, … … ],"? "the corresponding word vector is [0,0,0,0,1, … … ], then the calculated statement vector for the statement is [0.25,0.25,0.25,0,0.25, … … ].
The model training apparatus includes a processor and a memory, the acquiring unit 301, the determining unit 303, the training unit 305, and the like are stored in the memory as program units, and the processor executes the program units stored in the memory.
The processor comprises a kernel, and the kernel calls the corresponding program unit from the memory. The kernel can be set to be one or more than one, and the neural network model is obtained through training by adjusting kernel parameters.
The memory may include volatile memory in a computer readable medium, Random Access Memory (RAM) and/or nonvolatile memory such as Read Only Memory (ROM) or flash memory (flash RAM), and the memory includes at least one memory chip.
The present application further provides an embodiment of a computer program product, which, when being executed on a data processing device, is adapted to carry out program code for initializing the following method steps: acquiring text information with emotion marks, wherein the text information comprises a plurality of sentences marked according to predefined emotion types, and each sentence carries the emotion mark corresponding to the sentence; determining a statement vector corresponding to each statement in the text information, wherein the statement vector is a multidimensional array used for uniquely representing the corresponding statement; and inputting the emotion mark corresponding to each statement and the statement vector corresponding to the emotion mark into a cyclic neural network, and training to obtain a neural network model, wherein the neural network model is used for identifying the emotion type in the statement.
According to the embodiment of the application, a sentence emotion recognition device is further provided, and the wrongly written word recognition device can be used for executing the sentence emotion recognition method provided by the embodiment of the application. As shown in fig. 4, the sentence emotion recognition apparatus includes: a vector determination unit 401 and a recognition unit 403.
The vector determining unit 401 is configured to determine a sentence vector corresponding to each sentence in the text to be tested.
For the determination of the statement vector corresponding to the statement to be detected, reference may be made to the determination manner of the statement vector corresponding to the statement in the collected text information with emotion marks in the above embodiments of the present application, which is not described herein again.
The identifying unit 403 is configured to input a statement vector corresponding to each statement in the text to be detected into the neural network model, and identify an emotion type of each statement in the text to be detected by using the neural network model.
The neural network model of the embodiment of the present application is a neural network model obtained by training the model training method of the above embodiment of the present application. Inputting the statement vector of the text to be tested into the RNN training model to obtain the emotion type of each statement, wherein the mark is 1 to represent positive, the mark is 0 to represent neutral, the mark is-1 to represent negative, and the mark depends on the definition mode of the mark of the emotion type.
Because the machine can memorize words and words in the sentences and combinations thereof and corresponding emotion marks by inputting the sentence vectors corresponding to the sentences in the text into the cyclic neural network and memorize the words and the combinations thereof and the corresponding emotion marks by using parameters (most of which are determined by parameters in the neural network model) in the neural network model, when the neural network model is used for carrying out emotion recognition on the sentences, the emotion types of the sentences in the text can be effectively and quickly recognized according to the context of the sentences, and compared with the mode of recognizing the emotion of the sentences by using emotion keywords and the like in the prior art, the accuracy of recognizing the emotion of the sentences by the neural network model is greatly improved.
The sentence emotion recognition apparatus includes a processor and a memory, and the vector determination unit 401, the recognition unit 403, and the like are stored in the memory as program units, and the processor executes the program units stored in the memory.
The processor comprises a kernel, and the kernel calls the corresponding program unit from the memory. The kernel can be set to be one or more, and the emotion type of the statement in the text to be tested is identified by adjusting the kernel parameters.
The memory may include volatile memory in a computer readable medium, Random Access Memory (RAM) and/or nonvolatile memory such as Read Only Memory (ROM) or flash memory (flash RAM), and the memory includes at least one memory chip.
The present application further provides an embodiment of a computer program product, which, when being executed on a data processing device, is adapted to carry out program code for initializing the following method steps: determining a sentence vector corresponding to each sentence in the text to be tested; and inputting the statement vector corresponding to each statement in the text to be detected into the neural network model, and identifying the emotion type of each statement in the text to be detected by using the neural network model.
The above-mentioned serial numbers of the embodiments of the present application are merely for description and do not represent the merits of the embodiments.
In the above embodiments of the present application, the descriptions of the respective embodiments have respective emphasis, and for parts that are not described in detail in a certain embodiment, reference may be made to related descriptions of other embodiments.
In the embodiments provided in the present application, it should be understood that the disclosed technology can be implemented in other ways. The above-described embodiments of the apparatus are merely illustrative, and for example, the division of the units may be a logical division, and in actual implementation, there may be another division, for example, multiple units or components may be combined or integrated into another system, or some features may be omitted, or not executed. In addition, the shown or discussed mutual coupling or direct coupling or communication connection may be an indirect coupling or communication connection through some interfaces, units or modules, and may be in an electrical or other form.
The units described as separate parts may or may not be physically separate, and parts displayed as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of the embodiment.
In addition, functional units in the embodiments of the present application may be integrated into one processing unit, or each unit may exist alone physically, or two or more units are integrated into one unit. The integrated unit can be realized in a form of hardware, and can also be realized in a form of a software functional unit.
The integrated unit, if implemented in the form of a software functional unit and sold or used as a stand-alone product, may be stored in a computer readable storage medium. Based on such understanding, the technical solution of the present application may be substantially implemented or contributed to by the prior art, or all or part of the technical solution may be embodied in a software product, which is stored in a storage medium and includes instructions for causing a computer device (which may be a personal computer, a server, or a network device) to execute all or part of the steps of the method according to the embodiments of the present application. And the aforementioned storage medium includes: a U-disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), a removable hard disk, a magnetic or optical disk, and other various media capable of storing program codes.
The foregoing is only a preferred embodiment of the present application and it should be noted that those skilled in the art can make several improvements and modifications without departing from the principle of the present application, and these improvements and modifications should also be considered as the protection scope of the present application.