Disclosure of Invention
In order to solve the technical problems, the invention aims to provide a new idea for enhancing the prompt performance in the ABSA task by integrating an external knowledge graph, an effective domain knowledge graph is constructed by using the combination of word network extraction and small-scale data annotation, and a linguistic module s generated by the method provides richer and more specific label word mapping, so that the accuracy of the ABSA task is improved.
In order to achieve the technical purpose, the technical scheme provided by the invention comprises the following steps:
The aspect-level emotion analysis method based on the domain knowledge graph comprises the following steps of:
Obtaining a target text, analyzing and extracting target aspect words of the target text, and constructing a mask language template based on prompt learning;
Constructing a domain knowledge graph of the domain involved in the target text, wherein the domain knowledge graph comprises a plurality of aspects contained in the domain and the corresponding relation between an upper descriptor and a lower descriptor and between the upper descriptor and the lower descriptor;
After splicing the target text and the mask language template, inputting the spliced target text and mask language template into a pre-trained language model for mask language modeling, inquiring a target aspect category in the domain knowledge graph according to the target aspect word, extracting all description words associated with the target aspect category as target aspect description words, and filling the target aspect description words into a mask;
And respectively predicting the aspect emotion polarity of the target aspect descriptor to obtain the aspect emotion polarity of the target text.
In some preferred embodiments, the method for constructing the domain knowledge graph of the domain involved in the target text includes:
acquiring a plurality of evaluation texts which are the same as the field related to the target text, extracting aspect words and description words of all aspects contained in the evaluation texts, and establishing an aspect-description word list;
based on the aspect-descriptor list, extracting the aspect category and the corresponding descriptor-descriptor and descriptor-aspect relation in the word network database, and constructing the domain knowledge graph.
In some preferred embodiments, the method for obtaining the aspect-level emotion polarity of the target text includes:
and taking the aspect emotion polarity mapped by the target aspect descriptor with the highest prediction score as the aspect emotion polarity of the target text.
In some preferred embodiments, the method for obtaining the aspect emotion polarity of the target text comprises the following steps:
And carrying out weighted average on the prediction scores of all target aspect descriptors according to the aspect emotion polarity categories, and taking the aspect emotion polarity with the highest weighted average as the aspect emotion polarity of the target text.
In some preferred embodiments, the language model comprises a BERT model or a GPT model.
In some preferred embodiments, the word network database includes a word network word library and/or a Chinese word network word library.
The invention also provides an aspect-level emotion analysis system based on the domain knowledge graph, which comprises the following steps:
The first acquisition module is used for acquiring target texts and analyzing and extracting target aspect words of the target texts;
The domain knowledge graph module is set to be internally provided with a domain knowledge graph containing a plurality of aspects of the domain related to the target text and the corresponding upper descriptor-lower descriptor and descriptor-aspect relation;
The mask language template module is provided with a mask language template based on prompt learning, and the target text and the mask language template are spliced to be used as a first output text;
the pre-training language model is set to be built in with a pre-trained language model, a first output text is input for mask language modeling, target aspect categories are inquired in the domain knowledge graph according to target aspect words, all description words associated with the target aspect categories are extracted to serve as target aspect description words, and mask positions are filled in;
and the prediction analysis module is used for respectively predicting the aspect emotion polarities of the target aspect descriptors to obtain the aspect emotion polarities of the target texts.
In some preferred embodiments, the method for constructing the domain knowledge graph includes:
acquiring a plurality of evaluation texts which are the same as the field related to the target text, extracting aspect words and description words of all aspects contained in the evaluation texts, and establishing an aspect-description word list;
based on the aspect-descriptor list, extracting the aspect category and the corresponding descriptor-descriptor and descriptor-aspect relation in the word network database, and constructing the domain knowledge graph.
In some preferred embodiments, the prediction analysis module includes a first prediction analysis unit configured to set, as the aspect emotion polarity of the target text, the aspect emotion polarity mapped by the target aspect descriptor having the highest prediction score.
In some preferred embodiments, the prediction analysis module includes a second prediction analysis unit configured to perform weighted average on the prediction scores of all the target aspect descriptors according to the aspect emotion polarity categories, and take the aspect emotion polarity with the highest weighted average as the aspect emotion polarity of the target text.
Advantageous effects
The comprehensive description words and entity relations are obtained by utilizing the domain knowledge graph of the related domain with stronger pertinence, and under the condition of zero samples or few samples, the high prediction accuracy can be maintained for the tasks of ATSC and ACSC, so that the problems of possible deviation of manually inputting prompt words and limitation of the coverage range of tag words are avoided.
Detailed Description
The present invention will be further described with reference to the accompanying drawings, in order to make the objects, technical solutions and advantages of the present invention more apparent. In the description of the present invention, it should be understood that the terms "upper," "lower," "front," "rear," "left," "right," "top," "bottom," "inner," "outer," and the like indicate or are based on the orientation or positional relationship shown in the drawings, merely to facilitate description of the present invention and to simplify the description, and do not indicate or imply that the devices or elements referred to must have a specific orientation, be configured and operated in a specific orientation, and thus should not be construed as limiting the present invention.
Example 1
As shown in fig. 1, the embodiment provides an aspect-level emotion analysis method based on a domain knowledge graph, which includes the following steps:
S1, acquiring a target text, analyzing and extracting target aspect words of the target text, and constructing a mask language template based on prompt learning.
The Aspect (Aspect) mainly comprises a category (Categary) and a target (Item), and predictions for the category (Categary) and the target (Item) are respectively called Aspect category emotion Analysis (ACSC) and Aspect target emotion Analysis (ATSC), and the two are collectively called Aspect level emotion analysis (ABSA). ACSC is directed to determining overall emotion to a broader category or aspect, while ATSC is directed to determining emotion to a more specific target or entity. By using ABSA, the user's opinion and attitude towards the target product or service can be more fully understood, which can provide information support for the enterprise for product development, marketing strategies, and customer service planning.
The target text refers to text data that needs to predict the polarity of emotion at the aspect level that it contains, and contains different words that people use for feeling different aspects of a specific target, for example, food is often described as "savoury" or "unpalatable", and the environment may be marked as "clean" or "cluttered".
The extracting the target aspect words of the target text refers to that an aspect word Extraction task (ASPECT TERM Extraction, ATE) is a basic subtask in aspect-level emotion analysis. The goal is to give a target text and the goal of ATE is to extract the aspect phrases that are expressed by the user as emotions. For example, for comment "The Bombay style bhelpuriis very paltable," ATE wishes to extract the aspect word "bhelpuri". There is a great deal of research in the prior art on this task, including specifically various models and algorithms based on unsupervised, semi-supervised and unsupervised, and those skilled in the art can select an appropriate model in the prior art to accomplish this task according to actual needs, which the present invention is not limited to further.
The Prompt Learning (Prompt Learning) is a fourth stage (also called a fourth model) in the field of currently recognized Natural Language Processing (NLP), i.e., pre-training- > prompting- > prediction, which focuses on adapting a downstream task to a language model, rather than adapting a previous language model to a change of the downstream task, so parameters of the pre-training model are not generally changed. In particular, a contextual cue is provided about the input, entering the model with the input, telling the model what task you should do next. For the task of the present invention, it is to formalize the aspect-level emotion classification task as a mask language modeling problem. Specifically, the input sequence is packaged using a template, which is a piece of natural language text. The following template examples:
I felt the{aspect}was[MASK].
I[MASK]{aspect}.
The{aspect}made me feel[MASK].
The{aspect}is[MASK].
In which { aspect } is a target aspect, extraction is completed by a pre-step, and [ MASK ] is a MASK of an aspect descriptor, as shown in fig. 4. The specific choice or construction of what mask language templates may be made by those skilled in the art based on the prior art, and the invention is not further limited.
S2, constructing a domain knowledge graph of the domain related to the target text, wherein the domain knowledge graph comprises a plurality of aspects contained in the domain and the corresponding relation between the upper descriptor and the lower descriptor.
It should be appreciated that in ATSC or ACSC tasks, the core challenge is to extend ternary emotion to finer granularity emotion. Different words are used to describe the perception of different aspects. For example, food products are often described as "savoury" or "bad-eating", while the environment may be marked as "clean" or "messy". Predicting emotion of a sentence of a particular aspect using hint learning involves predicting mask words based on context. This process is not a simple option as there may be many suitable words in such a context. Thus, the descriptor of the ABSA task should have three characteristics, broad coverage, less subjective bias, and strong relevance in terms. Such comprehensive predictions are critical to the pre-trained language model (PLM) and are also the essence of prompt learning. The invention completes the structuring of the external knowledge by using the domain knowledge graph which is strongly related to the related domain, so that the description words simultaneously meet the three requirements.
In some preferred embodiments, a specific method for constructing a domain knowledge graph of a domain involved in a target text is provided, as shown in fig. 2, including:
S201, acquiring a plurality of evaluation texts which are the same as the field related to the target text, extracting aspect words and description words of all aspects contained in the evaluation texts, and establishing an aspect-description word list. Wherein the number of the evaluation texts is not required to be too large, and the acquired sources can be an evaluation database in the disclosed target field and the like.
In the following, a detailed description is given taking as an example the creation of a list of aspect-descriptors of a restaurant domain, it being understood that the description herein should not be construed as a unique limitation of this step, but rather a representation of the operating logic, it will be apparent to those skilled in the art that similar processing steps can be employed with respect to a list of aspect-descriptors of other domains in the light of this logic.
One thousand untagged data items were first randomly selected from the yellow open dataset, including a large number of user-generated restaurant reviews. These comments cover different aspects of the dining experience, from food quality to employee friendliness, to restaurant atmosphere, and so on. Next, selected reviews are manually or automatically annotated to determine words and phrases that express particular emotional tendencies for different aspects of the restaurant. In particular, eight key aspects are mainly focused on food quality, quality of service, atmosphere, menus, staff, price, location and overall experience. For each aspect, an aspect-descriptor list is generated to capture all emotions expressed by the reviewers in the dataset. These words include positive descriptors such as "delicacy" and "perfect", and negative descriptors such as "disappointing" and "unprofitable". By annotating a subset of the yellow dataset in this manner, a small and targeted evaluation vocabulary can be created that contains words that are highly relevant to the restaurant review area. These words can be used as descriptors of the ABSA task, which helps to improve the accuracy and granularity of emotion analysis in the field. Obviously, this method can also be applied to other fields with limited evaluation vocabularies.
S202, based on the aspect-descriptor list, extracting the aspect category and the corresponding descriptor-descriptor and descriptor-aspect relation in the word network database, and constructing a domain knowledge graph. The word network database refers to a dictionary made based on cognitive linguistics, is a word network composed according to the meaning of single words, covers a wide-range word semantic network, nouns, verbs, adjectives and adverbs, is respectively organized into a synonym network, each synonym set represents a basic semantic concept, and the sets are connected by various relations. Is a popular tool dataset in the NLP field at present, and the representative databases comprise WordNet of English class, babelNet of multilingual class, chinese WordNet of Chinese class and the like. Since such a word network database has a broad set of synonyms, these sets of synonyms group nouns, verbs, adjectives, and adverbs according to cognitive similarity. And has a clear hierarchical structure, organizing the synonym sets into a network of concept-semantic and lexical relationships.
For a knowledge graph, it is composed of entities (such as "Zhang san"), concepts (such as "actors"), generic relationships between entities and concepts (also known as isA relationships, such as "Zhang san isA actors"), generic relationships between concepts (such as "movie actors" are a subclass of "actors"). If A is B, it is commonly referred to as A is a hyponym of B (hyponym), or B is an hypernym of A (hypernym).
Taking WordNet as an example, ISA relationships are the most commonly encoded relationships between synonym sets, linking more general categories with specific categories. Hyponyms are relationships between sub-categories and their parent categories, and hyponym relationships are transitive, so that meaningful relationships between concepts in a given domain can be derived therefrom.
S3, inputting the spliced target text and mask language templates into a pre-trained language model for mask language modeling, inquiring target aspect categories in the domain knowledge graph according to target aspect words, extracting all description words associated with the target aspect categories as target aspect description words, and filling the target aspect description words into a mask;
It should be noted that, for the ATSC task, the target aspect word extracted in the pre-step is an aspect target, which can be understood as a lower concept of an aspect category (equivalent to a attendant versus foreground service), at this time, the aspect category to which the target aspect word belongs needs to be queried in the domain knowledge graph by using the target aspect word, and then a polar word associated with the category is extracted as a description word of the aspect, which ensures that the verbalization program adjusts for a specific context, and captures subtle differences of category emotion. For the ACSC task, the target aspect words extracted in the pre-step are aspect categories, so that the polar vocabulary associated with the category can be directly extracted as the description words of the aspect. Such a domain knowledge graph using method makes use of well-defined categories in the domain knowledge graph, so that an appropriate linguistic module of each entity can be efficiently identified and used. In some particular embodiments, certain classes or terms of descriptor data may be limited or non-existent, and in the event of such data scarcity, efficient linguistic modules may be generated by utilizing the rich semantic relationships contained in the domain knowledge graph.
S4, predicting the aspect emotion polarities of the target aspect descriptors respectively to obtain the aspect emotion polarities of the target text. It is common for people to use different words in different sentences to express the same emotion polarity for a particular aspect, and the purpose of this step is to determine the tag word that contributes most to the predictive tag, assuming that the mapping between tag words and emotion polarities is accurate. Because the number of samples in each target field is different, different criteria can be used to measure the emotion polarity reflected by the predictive score.
In some zero sample embodiments, the maximum value of the predictive score is used instead of the average value to determine the polarity of emotion reflected thereby, thus eliminating the need for adjustments to the training parameters of the model. The prediction score refers to the probability of filling target aspect descriptors in the mask related to the aspects, and is recorded as
The specific prediction formula is as follows:
Wherein, For emotion polarity labels, respectively comprising "Positive" (labeled 0), "Negative" (labeled 1) or "Neutral" (labeled 2); Representing a language model pre-trained in a large corpus; representing emotion polarity of text Wherein θ represents the number of emotion polarities; representing a set of aspect descriptors and defining a function f: [ MASK ] represents a target aspect descriptor; representing mask language templates, e.g. XThe{aspect}is[MASK];
In some embodiments with fewer samples, the aspect emotion polarity with the highest weighted average is taken as the aspect emotion polarity of the target text after the prediction scores are weighted and averaged according to the aspect emotion polarity class. The specific prediction formula is as follows:
Wherein s (y|x p) is defined as:
the function may continuously optimize the prediction probability using a cross entropy loss function.
Example 2
As shown in fig. 2, this embodiment is developed on the basis of the above embodiment 1, and this embodiment provides an aspect emotion analysis system based on a domain knowledge graph, including:
The first acquisition module is used for acquiring target texts and analyzing and extracting target aspect words of the target texts;
The domain knowledge graph module is set to be internally provided with a domain knowledge graph containing a plurality of aspects of the domain related to the target text and the corresponding upper descriptor-lower descriptor and descriptor-aspect relation;
The mask language template module is provided with a mask language template based on prompt learning, and the target text and the mask language template are spliced to be used as a first output text;
the pre-training language model is set to be built in with a pre-trained language model, a first output text is input for mask language modeling, target aspect categories are inquired in the domain knowledge graph according to target aspect words, all description words associated with the target aspect categories are extracted to serve as target aspect description words, and mask positions are filled in;
and the prediction analysis module is used for respectively predicting the aspect emotion polarities of the target aspect descriptors to obtain the aspect emotion polarities of the target texts.
In some preferred embodiments, the method for constructing the domain knowledge graph includes:
acquiring a plurality of evaluation texts which are the same as the field related to the target text, extracting aspect words and description words of all aspects contained in the evaluation texts, and establishing an aspect-description word list;
based on the aspect-descriptor list, extracting the aspect category and the corresponding descriptor-descriptor and descriptor-aspect relation in the word network database, and constructing the domain knowledge graph.
In some preferred embodiments, the prediction analysis module includes a first prediction analysis unit configured to set, as the aspect emotion polarity of the target text, the aspect emotion polarity mapped by the target aspect descriptor having the highest prediction score.
In some preferred embodiments, the prediction analysis module includes a second prediction analysis unit configured to perform weighted average on the prediction scores of all the target aspect descriptors according to the aspect emotion polarity categories, and take the aspect emotion polarity with the highest weighted average as the aspect emotion polarity of the target text.
Various implementations of the systems and techniques described here above can be implemented in digital electronic circuitry, integrated circuit systems, field Programmable Gate Arrays (FPGAs), application Specific Integrated Circuits (ASICs), application Specific Standard Products (ASSPs), systems On Chip (SOCs), load programmable logic devices (CPLDs), computer hardware, firmware, software, and/or combinations thereof. These various embodiments may include being implemented in one or more computer programs that are executable and/or interpretable on a programmable system including at least one programmable processor, which may be a special or general purpose programmable processor, operable to receive data and instructions from, and to transmit data and instructions to, a storage system, at least one input device, and at least one output device.
Program code for carrying out methods of the present disclosure may be written in any combination of one or more programming languages. These program code may be provided to a processor or controller of a general purpose computer, special purpose computer, or other programmable data processing apparatus such that the program code, when executed by the processor or controller, causes the functions/operations specified in the flowchart and/or block diagram to be implemented. The program code may execute entirely on the machine, partly on the machine, as a stand-alone software package, partly on the machine and partly on a remote machine or entirely on the remote machine or server. In the context of this disclosure, a machine-readable medium may be a tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device. The machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. The machine-readable medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any suitable combination of the foregoing. More specific examples of a machine-readable storage medium would include an electrical connection based on one or more wires, a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
Example 3
This embodiment is developed on the basis of embodiment 1 described above. This example shows the course of an experiment performed on different data sets and a comparison of the results.
Data set
In the embodiment, experiments are carried out on two data sets, namely a MAMS data set and a SemEval 2014task4 data set, and the effectiveness of the aspect emotion analysis method based on the domain knowledge graph provided by the invention is improved. All data set labels are limited to three types of positive, negative and neutral. Wherein neutral means that no positive or negative emotion is expressed.
Table 1 below is the statistical result for the two data sets described above.
Table 1 data set parameter statistics
Of these, semEval 2014task 4 dataset, which is widely used as a benchmark for evaluating performance on ATSC and ACSC tasks, contains english comment sentences for two target areas (notebook and restaurant). To evaluate the performance of the proposed method and baseline on the field test set and ensure comparability, two pretreatment steps need to be taken. First, the instance with conflicting emotion tags is deleted, which was rare in previous studies and is usually ignored. Second, sentences having multiple emotion aspects are split into separate instances, each focusing on a single emotion aspect.
The MAMS dataset includes sentences that contain at least two emotion attributes, where the emotions of these attributes differ. The MAMS dataset includes two versions for ACSC and ATSC tasks, respectively. For an ATSC dataset, researchers have extracted the attributed words in sentences and labeled the emotion polarity of each attribute. Sentences containing only one attribute or multiple attributes with the same emotion polarity are removed. For ACSC datasets, the author has predefined eight categories, including food, service, staff, price, environment, menu, location, and confusion categories. And according to the category information, the researchers carry out corresponding category and emotion polarity labeling on the sentences.
Experimental setup
The performance of the proposed method and baseline method is evaluated over a range of training data sizes throughout the field, covering the case from zero sample to full sample (i.e. full supervision). Specifically, our model is trained using a randomly resampled training set size, the number of samples including { Zero,16,64,256,1024, full }. For all experiments, BERT and GPT-2 were used as pre-trained language models. To evaluate performance, accuracy and Micro-F1 were used as test indicators. To ensure robustness, five random seeds were used for each cue and baseline, and their scores were averaged, and the average performance across all four cues was calculated.
Reference model
The following reference model is selected for comparison with the method proposed by the present invention, comprising:
(1)the last hidden state of the[CLS]token in BERT(referred to as BERT[CLS]);
(2)the NSP head of BERT(referred to as BERT NSP);
(3)BERT LM;
(4)GPT-2LM\cite{seoh2021open};
(5)CapsNet-BERT\cite{jiang2019challenge}.
results and analysis
5-6, The experimental results of the aspect emotion analysis method based on the domain knowledge graph and the baseline model of the current mainstream in the field are shown. The KG BERT LM and KG GPT-2LM respectively represent the aspect-level emotion analysis method provided by the invention, and the BERT model and the GPT-2 model are respectively adopted as a prediction model established by a pre-trained language model.
As can be seen by comparison, when the invention performs comparison of different tasks on two different data sets, the comparison is superior to the reference model in all cases, and the effectiveness of improving the performance by utilizing the domain knowledge graph is shown. Specifically, for small sample learning, compared with the existing reference model, the invention realizes larger performance improvement, and the accuracy (Acc) and Micro-F1 value (MF 1) are obviously higher than those of other prediction models with the same available label number. In addition, the invention performs well in the case of zero samples, and is obviously superior to a reference model trained by using only 16 samples, thereby further proving the usefulness of the invention. The learning speed of the invention is faster, the performance on 16, 64 and 256 samples is several orders of magnitude better than that of the existing prompt-free model, and the invention is also superior to the existing prompt model. This suggests that combining domain knowledge maps may improve predictive performance in cases where the data is limited. One possible explanation is that domain knowledge maps provide a more structural and informative way of prompting. By incorporating domain knowledge into the cues, the model can leverage relevant information about a particular domain and increase its generalization ability to new examples.
The foregoing has shown and described the basic principles, principal features and advantages of the invention. It will be understood by those skilled in the art that the present invention is not limited to the embodiments described above, and that the above embodiments and descriptions are merely illustrative of the principles of the present invention, and various changes and modifications may be made without departing from the spirit and scope of the invention, which is defined in the appended claims. The scope of the invention is defined by the appended claims and equivalents thereof.