Quadruple extraction method and device for session scene
Through the quadruple extraction method for conversation scenarios, using learnable key memory, value memory and grid marking, the problem that traditional ABSA is difficult to capture emotional changes in dialogue scenarios is solved, and more accurate emotional understanding and dialogue analysis are achieved. .
Patent Information
- Application Number
- CN202411277710.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-12
- Publication Date
- 2024-12-20
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
The traditional Aspect-based Sentiment Analysis (ABSA) approach is difficult to effectively capture and understand user emotional changes and relationships in conversation scenarios, especially when emotional elements span multiple sentences or conversation rounds.
Using a quadruple extraction method for session scenarios, by obtaining session data and encoding, using learnable key memory and value memory for span extraction, generating session global information, and extracting quadruples through multi-layer perceptrons and grid markers , breaking through the limitations of traditional ABSA.
It realizes more accurate emotional understanding and dialogue analysis, improves the ability to capture emotional changes and associations in dialogue, and enhances the ability to generalize attention mechanisms.
Smart Images

Figure CN119167947A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of natural language processing (NLP), and more particularly to a conversation scenario-oriented quadruple extraction method and device. Background Art
[0002] In today's digital age, the popularity of dialogue systems and intelligent assistants has made understanding and analyzing users' emotions the key to providing personalized services. Sentiment Analysis, as an important branch of Natural Language Processing (NLP), aims to mine the emotional tendencies of authors or speakers from text data.
[0003] With the development of technology, aspect-based sentiment analysis (ABSA) has further refined this task, not only identifying the overall sentiment of the text, but also identifying the sentiment related to specific aspects, such as the sentiment attitude towards price, quality, etc. in product reviews.
[0004] Although ABSA has made significant progress, most studies are still limited to analyzing a single text (such as a single sentence or document). However, in a conversation scenario, emotional expression often spans multiple speaking turns, involving complex contextual information and dynamic changes in emotions. That is, traditional ABSA methods ignore the complexity and contextual dependence of emotional expression in conversations, and it is difficult to effectively capture and understand users' emotional changes and relationships. Moreover, in a conversation scenario, the span extraction of emotional elements is more challenging because emotional elements not only exist in a single sentence, but may also span multiple sentences or conversation turns.
[0005] Therefore, how to extend ABSA to the dialogue context to overcome the above problems is an issue that technicians in this field urgently need to solve. Summary of the invention
[0006] In view of this, the present invention provides a quadruple extraction method and device for conversation scenarios, aiming to solve the problem of extracting cross-text sentiment elements and achieve more accurate sentiment understanding and conversation analysis.
[0007] In order to achieve the above object, the present invention adopts the following technical solution:
[0008] On the one hand, the present invention discloses a four-tuple extraction method for conversation scenarios, comprising:
[0009] Get the session data and encode it to get the feature matrix;
[0010] Based on learnable key memory and value memory, span extraction is performed on the feature matrix to obtain the global information of the session;
[0011] Perform reply mask, speaker mask and thread mask on the global information of the conversation respectively, and generate conversation feature representation through multi-layer perceptron;
[0012] The session feature representation is grid-labeled and decoded to obtain a quadruple.
[0013] Preferably, the conversation data includes multiple rounds of dialogue, and each round of dialogue is defined as S.
[0014] S={(u i ,r i ,a i )|i=1,…,N}
[0015] Among them, u i Indicates the current conversation, r i Indicates u i Reply, a i Indicates u i The corresponding speaker.
[0016] Preferably, feature span extraction is performed on the feature matrix based on learnable key memory and value memory, the steps comprising:
[0017] Determine the key memory and value memory based on the prior knowledge of the training data set, and linearly map the feature matrix to the query matrix;
[0018] Perform a dot product of the query matrix and the key memory to obtain the attention map;
[0019] The attention map is passed through the Relu layer, the Dropout layer, and the Softmax layer in sequence to obtain the attention distribution;
[0020] Multiply the attention distribution by the value memory to get the global information of the session.
[0021] Preferably, the key memory and the value memory are obtained through a linear layer according to the training data set, and the linear layer is optimized by end-to-end back propagation.
[0022] Preferably, grid marking the session feature representation includes:
[0023] Define entity labels, relationship labels, and sentiment polarity labels.
[0024] Use entity tags to label entities, aspects, and opinions respectively to obtain an entity matrix;
[0025] Use the relationship labels to mark entity-opinion, aspect-opinion and entity-opinion respectively to obtain the relationship matrix;
[0026] The entity-opinion and aspect-opinion are labeled respectively using sentiment polarity labels to obtain the polarity matrix.
[0027] Preferably, the decoding process includes:
[0028] Convert the entity matrix, relationship matrix and polarity matrix into entity list, relationship list and polarity list respectively;
[0029] Traverse the entity list and relationship list to generate triples and filter them;
[0030] Get the corresponding polarity in the polarity list and generate a quadruple based on the filtered triples.
[0031] Preferably, entity tags include: target tgt, aspect asp and opinion word opi; relationship tags include: head and head tags h2h and tail and tail tags t2t; sentiment polarity tags include: positive pos and negative neg.
[0032] On the other hand, the present invention provides a quadruple extraction device for conversation scenarios, comprising:
[0033] The encoding module is used to obtain and encode the session data to obtain a feature matrix;
[0034] The global span module is used to extract spans from the feature matrix based on learnable key memory and value memory to obtain global information of the session;
[0035] The mask module is used to perform reply mask, speaker mask and thread mask on the global information of the conversation respectively, and generate conversation feature representation through a multi-layer perceptron;
[0036] The quadruple tag extraction module is used to grid-tag and decode the session feature representation to obtain a quadruple.
[0037] Preferably, the global span module includes a first memory block, a second memory block and a query matrix acquisition unit;
[0038] a first memory block for determining a key memory based on a training data set, a second memory block for determining a value memory based on the training data set, and a query matrix acquisition unit for linearly mapping a feature matrix to a query matrix;
[0039] Among them, the output end of the first memory block and the output end of the query matrix acquisition unit are converged to the first dot product operation module and then connected to the Relu layer, the Dropout layer and the Softmax layer in sequence; at the same time, the output end of the Softmax layer and the output end of the second memory block output the session global information through the second dot product module.
[0040] Preferably, the quadruple tag extraction module comprises a grid tagging unit and a decoding unit;
[0041] A grid labeling unit is used to label entities, aspects and opinions respectively using entity labels to obtain an entity matrix; to label entity-opinion, aspect-opinion and entity-opinion respectively using relationship labels to obtain a relationship matrix; and to label entity-opinion and aspect-opinion respectively using sentiment polarity labels to obtain a polarity matrix;
[0042] The decoding unit is used to decode the entity matrix, the relationship matrix and the polarity matrix.
[0043] It can be seen from the above technical solution that, compared with the prior art, the present invention discloses a quadruple extraction method and device for conversation scenarios, which stores the relationship of the entire conversation through two learnable memory blocks to fully extract the span quadruple relationship in the conversation, fully explore the potential relationship of the entire data set, and provide a strong regularization effect, thereby improving the generalization ability of the attention mechanism; at the same time, a grid marking scheme is set to focus on the pairing relationship between aspect terms and opinion terms, so as to more accurately understand the emotions and attitudes expressed in the conversation.
[0044] The four-tuple extraction method for conversation scenarios in the present invention breaks through the limitations of traditional ABSA and provides a new perspective and method for understanding and analyzing emotions in conversations. BRIEF DESCRIPTION OF THE DRAWINGS
[0045] 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 embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on the provided drawings without paying creative work.
[0046] Figure 1 A flow chart of the method for extracting four-tuples for conversation scenarios provided by the present invention;
[0047] Figure 2 This is a schematic diagram of the grid marking provided by the present invention. DETAILED DESCRIPTION
[0048] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0049] The embodiment of the present invention discloses a method and device for extracting quadruple in conversation scenarios, aiming to fully extract span quadruple relations in a conversation. Specifically, two learnable memory blocks are used to store and process the relations of the entire conversation. Secondly, a new grid marking scheme is designed to more effectively capture and analyze emotional changes and associations in the conversation.
[0050] In one embodiment, the four-tuple extraction method for conversation scenarios aims to extract the four-tuple in the conversation scenario. They represent the goal, aspect, and opinion terms of the dialogue D. p∈{pos,neg,other} represents positive emotion, negative emotion, and others.
[0051] Reference Figure 1 , the extraction steps include:
[0052] The first step is to obtain the session data and encode it to obtain the feature matrix;
[0053] In this embodiment, the conversation data includes multiple rounds of dialogue, that is, D = {S1, S2, ..., S n}, where each round of dialogue is S, S i ={(u i ,r i ,a i )|i=1,…,N}, in the formula, u i Indicates the current conversation, r i Indicates u i Reply, a i Indicates u i The corresponding speaker.
[0054] Furthermore, this application uses Roberta to encode the sentences. Since the length of the entire conversation will exceed the maximum length accepted by Roberta, each utterance is encoded separately to obtain a feature matrix, represented as H i .
[0055] Step 2: Based on the learnable key memory and value memory, span extraction is performed on the feature matrix to obtain the global information of the session;
[0056] The traditional self-attention mechanism calculates the attention weight at each position of the input sequence and performs a weighted average of the information at other positions to obtain contextual information. However, the self-attention mechanism may fail in the case of long sequences because it needs to process a large number of dependencies, which may interfere with the capture of important information.
[0057] Therefore, in order to enhance the ability to extract quadruple spans in conversation scenarios, this application proposes a global span module, which introduces an additional linear transformation layer to learn the information of the entire sentence, thereby enhancing the ability to model the global context, helping to capture a wider range of dependencies, and improving the model's perception of global information and the accuracy of span extraction.
[0058] The extraction steps include:
[0059] The key memory and the value memory are determined separately based on the prior knowledge of the training data set. Preferably, the key memory is stored in the first memory block and the value memory is stored in the second memory block. In addition, in this embodiment, the key memory and the value memory are obtained through a linear layer according to the training data set, and the linear layer is optimized by end-to-end back propagation to achieve a stronger regularization effect and improve the generalization ability of the attention mechanism.
[0060] Furthermore, the feature matrix is linearly mapped to the query matrix, and the formula is expressed as:
[0061] Q=HW query +b query
[0062] Where b is the bias,
[0063] The query matrix is dot-multiplied with the key memory to obtain the attention map A; that is,
[0064] A=QM1
[0065] Wherein, M1 represents the key memory output by the first memory block;
[0066] Then, the attention map A is passed through the Relu layer, the Dropout layer and the Softmax layer in sequence to obtain the attention distribution; the specific operations are:
[0067] Activated by ReLU nonlinear activation function;
[0068] A ReLU =max(0,A)
[0069] Next, a portion of neurons are randomly discarded through the Dropout layer to prevent overfitting;
[0070]
[0071] Finally, the result is normalized by the softmax function to obtain the attention distribution, where each element represents the weight of each feature dimension at a certain position.
[0072]
[0073] Finally, the attention distribution is multiplied by the value memory stored in the second memory block to obtain the global information of the session.
[0074] K=FM2
[0075] Wherein, M2 represents the value memory output by the second memory block.
[0076] The present invention can learn the most discriminative features in the entire data set through external memory, capture the part with the largest amount of information, and exclude interference information from other samples.
[0077] Step 3: Perform reply mask, speaker mask and thread mask on the global information of the conversation respectively, and generate conversation feature representation through multi-layer perceptron;
[0078] In the study of dialogue systems, it is crucial to understand and process complex dialogue structures. In order to effectively capture and utilize multiple relationships in dialogues, dialogue-specific multi-view interactions have become an important research direction.
[0079] The present invention specifically uses three different masks (reply mask, speaker mask and thread mask) to represent different relationships in a conversation, which is used to realize multi-view interaction in a conversation system, thereby improving the ability of conversation understanding and generation.
[0080] The reply mask is used to indicate whether a certain utterance replies to another utterance. The reply mask is a diagonal matrix (elements on the diagonal are 1), indicating that each utterance replies to itself. For each reply, the relevant position of the update matrix is 1.
[0081] The thread mask is used to indicate whether a certain speech is in the same thread. The matrix is initialized as a diagonal matrix, and then the relevant positions are updated to 1 according to the thread information.
[0082] The speaker mask is used to indicate whether two utterances come from the same speaker. The matrix is initialized as an all-zero matrix, and for all utterances from the same speaker, the corresponding position is updated to 1.
[0083] Furthermore, the present invention generates the final session feature representation through a labeled multi-layer perceptron (MLP) layer.
[0084] Step 4: Grid-mark and decode the session feature representation to obtain a quadruple.
[0085] This application designs a new four-tuple grid tagging scheme, which is specifically converted into a tag grid by encoding entities, relations, and sentiment polarity.
[0086] In the present invention, firstly, entity tags, relationship tags and sentiment polarity tags are defined.
[0087] Among them, the entity tags include: target tgt, aspect asp and opinion word opi; Figure 2 ,The tgt tag between xiaomi and 11,represents the target word, the asp tag between word and mouth represents the aspect word, and the opi tag between not and good represents the opinion word;
[0088] Relationship tags include: head and head tags h2h and tail and tail tags t2t; Figure 2 , the head of the target word xiaomi is connected to the head of the aspect word word with the h2h tag, and the tail of the target word 11 is connected to the tail of the aspect word mouth with the t2t tag;
[0089] Sentiment polarity labels include: positive pos and negative neg. In the present invention, not only the relationship between entity and opinion is considered, but also the relationship between aspect and opinion is added to ensure that the model has higher accuracy when processing complex sentiment polarity quadruple. That is, not only the sentiment polarity labels are assigned at the h2h labels and t2t labels of the target term and the opinion term, but also the sentiment polarity labels are assigned at the h2h labels and t2t labels of the aspect term and the opinion term. For example, sentiment polarity labels are assigned at the head and tail of the aspect term and the opinion term respectively.
[0090] Then, the entity label, relationship label and sentiment polarity label are used to grid-label the conversation feature representation to obtain the entity matrix, relationship matrix and polarity matrix. Figure 2 As shown, specifically including:
[0091] Use entity tags to label entities, aspects, and opinions respectively to obtain an entity matrix;
[0092] Use the relationship labels to mark entity-opinion, aspect-opinion and entity-opinion respectively to obtain the relationship matrix;
[0093] The entity-opinion and aspect-opinion are labeled respectively using sentiment polarity labels to obtain the polarity matrix.
[0094] In this embodiment, the data can be converted into a labeled network in the following manner:
[0095] entities=word_pair.encode_entity(elements)
[0096] relations=word_pair.encode_relation(triplets)
[0097] polarities=word_pair.encode_polarity(triplets).
[0098] In another embodiment, the decoding process includes:
[0099] 1) Use the rel_matrix2list method to convert the entity matrix, relationship matrix, and polarity matrix into entity lists, relationship lists, and polarity lists, respectively; each element in these lists is a triple containing two indices and a corresponding relationship type or polarity type;
[0100] 2) Traverse the entity list and relationship list to generate triples and filter them;
[0101] In this embodiment, an entity dictionary is first constructed; in the entity dictionary, the starting position of each entity is used as a key, and the value is a list containing the ending position of the entity and its type (such as entity type, aspect type, etc.), and the entity2type dictionary is used to store the type of each entity;
[0102] Then construct a tail-to-tail relationship set and a head-to-head relationship set;
[0103] Generate triples by traversing the tail-to-tail relationship set, the head-to-head relationship set, and the entity dictionary.
[0104] In a preferred embodiment, invalid triples are filtered, such as removing invalid triples containing (0,0,0,0);
[0105] In another preferred embodiment, an ele2list dictionary is created to store all valid triples.
[0106] 3) Obtain the corresponding polarity in the polarity list and generate a quadruple based on the filtered triples.
[0107] This embodiment pre-builds a polarity dictionary. In the dictionary, the starting position of each polarity is used as a key, and the value is a list containing the end position of the polarity and its type (such as positive, negative, etc.). The b2b_relation_set dictionary is used to store the boundary pairs and their corresponding polarity types;
[0108] Furthermore, the corresponding polarity type is obtained by combining the b2b_relation_set dictionary, and the ele2list dictionary is traversed to generate a four-tuple.
[0109] To further optimize the above technical solution, this application defines the final training goal as minimizing the cross entropy loss of each subtask. Each subtask includes entity tasks, relationship tasks, and sentiment tasks, such as Figure 1As shown in GTS-AOL in . The loss function of each subtask is:
[0110]
[0111] The total loss is the sum of the subtask losses:
[0112]
[0113] In an exemplary embodiment, the present application provides a quadruple extraction device for a conversation scenario, the device comprising:
[0114] The encoding module is used to obtain and encode the session data to obtain a feature matrix;
[0115] The global span module is used to extract spans from the feature matrix based on learnable key memory and value memory to obtain global information of the session;
[0116] The mask module is used to perform reply mask, speaker mask and thread mask on the global information of the conversation respectively, and generate conversation feature representation through a multi-layer perceptron;
[0117] The quadruple tag extraction module is used to grid-tag and decode the session feature representation to obtain a quadruple.
[0118] Wherein, the global span module includes a first memory block, a second memory block and a query matrix acquisition unit;
[0119] a first memory block for determining a key memory based on a training data set, a second memory block for determining a value memory based on the training data set, and a query matrix acquisition unit for linearly mapping a feature matrix to a query matrix;
[0120] The output end of the first memory block and the output end of the query matrix acquisition unit are connected to the Relu layer, the Dropout layer and the Softmax layer in sequence through the first dot product operation module; at the same time, the output end of the Softmax layer and the output end of the second memory block output the session global information through the second dot product module.
[0121] The quadruple tag extraction module includes a grid tagging unit and a decoding unit;
[0122] A grid labeling unit is used to label entities, aspects and opinions respectively using entity labels to obtain an entity matrix; to label entity-opinion, aspect-opinion and entity-opinion respectively using relationship labels to obtain a relationship matrix; and to label entity-opinion and aspect-opinion respectively using sentiment polarity labels to obtain a polarity matrix;
[0123] The decoding unit is used to decode the entity matrix, the relationship matrix and the polarity matrix.
[0124] In order to verify the extraction effect of this application, extraction experiments were conducted based on the data sets ZH and EN. The experimental data are shown in the following table:
[0125]
[0126] In the table, the numbers in bold are the best results. T, A, and O represent the target term, aspect term, and opinion term extraction results, respectively. TA, TO, and AO represent the pairwise extraction results, respectively. Micro and Iden represent the F1 scores of the quadruple extraction results and triple extraction results, respectively. Intra and Inter represent the F1 scores of quadruple extractions that exist in the same discourse and across multiple different discourses, respectively.
[0127] The above data prove that the quadruple extraction in the dialogue context provided by this application has significant advantages and can solve the shortcomings of existing methods to a certain extent.
[0128] In this specification, each embodiment is described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the embodiments can be referred to each other. For the device disclosed in the embodiment, since it corresponds to the method disclosed in the embodiment, the description is relatively simple, and the relevant parts can be referred to the method part.
[0129] The above description of the disclosed embodiments enables one skilled in the art to implement or use the present invention. Various modifications to these embodiments will be apparent to one skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present invention. Therefore, the present invention will not be limited to the embodiments shown herein, but rather to the widest scope consistent with the principles and novel features disclosed herein.
Claims
1. A four-tuple extraction method for conversation scenarios, characterized in that: include: Get the session data and encode it to get the feature matrix; Based on learnable key memory and value memory, span extraction is performed on the feature matrix to obtain the global information of the session; Perform reply mask, speaker mask and thread mask on the global information of the conversation respectively, and generate conversation feature representation through multi-layer perceptron; The session feature representation is grid-labeled and decoded to obtain a quadruple.
2. A method for extracting quadruplets for conversation scenarios according to claim 1, characterized in that: The conversation data includes multiple rounds of dialogue, each round of dialogue is defined as S. S={(u i ,r i ,a i )|i=1,…,N} Among them, u i Indicates the current conversation, r i Indicates u i Reply, a i Indicates u i The corresponding speaker.
3. A method for extracting quadruplets for conversation scenarios according to claim 1, characterized in that: The feature span extraction of the feature matrix is performed based on the learnable key memory and value memory. The steps include: Determine the key memory and value memory based on the prior knowledge of the training data set, and linearly map the feature matrix to the query matrix; Perform a dot product of the query matrix and the key memory to obtain the attention map; The attention map is passed through the Relu layer, the Dropout layer, and the Softmax layer in sequence to obtain the attention distribution; Multiply the attention distribution by the value memory to get the global information of the session.
4. The method for extracting quadruplets for conversation scenarios according to claim 3, characterized in that: The key memory and value memory are obtained through a linear layer according to the training data set, and the linear layer is optimized by end-to-end back-propagation.
5. The method for extracting quadruplets for conversation scenarios according to claim 1, characterized in that: Grid marking of session feature representation includes: Define entity labels, relationship labels, and sentiment polarity labels. Use entity tags to label entities, aspects, and opinions respectively to obtain an entity matrix; Use the relationship labels to mark entity-opinion, aspect-opinion and entity-opinion respectively to obtain the relationship matrix; The entity-opinion and aspect-opinion are labeled respectively using sentiment polarity labels to obtain the polarity matrix.
6. A method for extracting quadruplets for conversation scenarios according to claim 5, characterized in that: The decoding process includes: Convert the entity matrix, relationship matrix and polarity matrix into entity list, relationship list and polarity list respectively; Traverse the entity list and relationship list to generate triples and filter them; Get the corresponding polarity in the polarity list and generate a quadruple based on the filtered triples.
7. The method for extracting quadruplets for conversation scenarios according to claim 5, characterized in that: Entity tags include: target tgt, aspect asp and opinion word opi; relationship tags include: head and head tags h2h and tail and tail tags t2t; sentiment polarity tags include: positive pos and negative neg.
8. A quadruple extraction device for conversation scenarios, characterized in that: include: The encoding module is used to obtain and encode the session data to obtain a feature matrix; The global span module is used to extract spans from the feature matrix based on learnable key memory and value memory to obtain global information of the session; The mask module is used to perform reply mask, speaker mask and thread mask on the global information of the conversation respectively, and generate conversation feature representation through a multi-layer perceptron; The quadruple tag extraction module is used to grid-tag and decode the session feature representation to obtain a quadruple.
9. The quadruple extraction device for conversation scenarios according to claim 8, characterized in that: The global span module includes a first memory block, a second memory block and a query matrix acquisition unit; a first memory block for determining a key memory based on a training data set, a second memory block for determining a value memory based on the training data set, and a query matrix acquisition unit for linearly mapping a feature matrix to a query matrix; Among them, the output end of the first memory block and the output end of the query matrix acquisition unit are converged to the first dot product operation module and then connected to the Relu layer, the Dropout layer and the Softmax layer in sequence; at the same time, the output end of the Softmax layer and the output end of the second memory block output the session global information through the second dot product module.
10. The quadruple extraction device for conversation scenarios according to claim 8, characterized in that: The quadruple tag extraction module includes a grid tagging unit and a decoding unit; A grid labeling unit is used to label entities, aspects and opinions respectively using entity labels to obtain an entity matrix; Use the relationship labels to mark entity-opinion, aspect-opinion and entity-opinion respectively to obtain the relationship matrix; And use the sentiment polarity label to label the entity-opinion and aspect-opinion respectively to obtain the polarity matrix; The decoding unit is used to decode the entity matrix, the relationship matrix and the polarity matrix.
Citation Information
Patent Citations
Aspect sentiment analysis method for optimizing grid label
CN115545038A
Intelligent emotion recognition method based on data enhancement and cross-modal feature fusion
CN116011457A
Server, display device and voice interaction method
CN117809616A
Cited By
Dialogue scene-oriented aspect emotion tetrad prediction method and system
CN120653756A
