A method for extracting sentiment from multi-turn conversations using large language model reasoning
By introducing dynamic word pruning and knowledge distillation techniques into large language models, combining multi-level teacher model and two-dimensional structure entropy minimization algorithm, the problem of slow computing resource consumption and inference speed of existing models in long text or multi-round conversations is solved, achieving more efficient and accurate emotional extraction effects.
Patent Information
- Application Number
- CN202411465374.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-21
- Publication Date
- 2025-04-15
- Estimated Expiration
- 2044-10-21
AI Technical Summary
When existing large language models deal with long text or multi-round conversations, they consume high computing resources and slow inference speed, which limits their application in dialogue systems.
The dynamic word pruning model and knowledge distillation model are used to guide students' models to learn dialogue knowledge through multi-level teacher models, construct dialogue diagrams, and divide dialogues using a two-dimensional structural entropy minimization algorithm, and finally match emotional quadruples through the maximum pooling operation.
It improves the accuracy of emotional extraction, reduces the computational cost, and improves the computational efficiency of the model and the accuracy of dialogue emotion extraction.
Smart Images

Figure CN118982030B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of emotion quadruple extraction, and in particular to a method for multi-round dialogue emotion quadruple extraction using large language model reasoning. Background Art
[0002] With the rapid development of natural language processing technology, multi-turn dialogue systems have been widely used in intelligent customer service, virtual assistants, and social robots. In these applications, sentiment analysis, as an important means to understand the user's emotional state, is crucial to improving user experience and system response quality. Sentiment quadruple extraction is an advanced task in sentiment analysis, which not only requires identifying the sentiment polarity (such as positive, negative, and neutral) in the conversation, but also extracting the target, aspect, and opinion of the sentiment.
[0003] In recent years, large-scale language models based on deep learning (such as BERT and GPT series) have shown superior performance in sentiment analysis tasks. However, these models still face problems such as high computing resource consumption and slow reasoning speed when processing long texts or multi-turn dialogues, which limits their application in dialogue systems. Summary of the invention
[0004] In view of the above existing problems, the present invention is proposed.
[0005] Therefore, the present invention provides a multi-round dialogue emotion quadruple extraction method using large language model reasoning to solve the problem of improving the accuracy of emotion extraction and reducing computational costs.
[0006] In order to solve the above technical problems, the present invention provides the following technical solutions:
[0007] The embodiment of the present invention provides a method for extracting emotions from a multi-round conversation using a large language model inference, which includes collecting multi-round conversation data and context information between a customer service representative and a customer, and preprocessing the collected data;
[0008] The collected context information is pruned using a dynamic lemma pruning model;
[0009] Establish a knowledge distillation model and build a multi-level teacher model based on the reasoning results and multi-round dialogue data;
[0010] The multi-level teacher model guides the student model to learn the detailed information in the conversation from the multi-level conversation knowledge;
[0011] Construct a conversation graph based on the conversations processed by the LazyLLM and knowledge distillation models;
[0012] Use a two-dimensional structural entropy minimization algorithm to divide the conversation into the smallest sub-conversations, and perform a merge operation to achieve the optimal division to form a sub-conversation set;
[0013] Construct a two-dimensional table, annotate entity relationships, extract entities in discourse, match entities based on sub-dialogue sets, and form sentiment quadruples;
[0014] Through the maximum pooling operation, the relationship between entities is predicted and finally the sentiment quadruple is matched.
[0015] As a preferred solution of the multi-round dialogue emotion quadruple extraction method using large language model inference described in the present invention, wherein: the multi-round dialogue data includes customer ID, customer service ID, dialogue content, timestamp and dialogue turn;
[0016] The context information includes historical interaction records, conversation topics, relevant business status and customer information;
[0017] The preprocessing includes data cleaning and text standardization.
[0018] As a preferred solution of the method for extracting emotions from a multi-round dialogue using a large language model inference according to the present invention, the method of performing word pruning on the collected context information by using a dynamic word pruning model comprises the following steps:
[0019] In each generation step, use the layer The attention map determines the input word t i The importance relative to the next token to be predicted is expressed as,
[0020]
[0021] Among them, H is the number of attention avatars, N is the sequence length, t j In the hth head, for word t i The probability of attention, t i Confidence score at level l+1;
[0022] In each transformer layer, the Top-k percentile is selected as the threshold for word pruning according to the importance score of the word. i Confidence score at level l+1 Less than the kth l percentile, the word will be pruned. Once the word is pruned, it will be excluded from the calculation of all subsequent layers. l Represents the percentage used to determine the threshold in layer l;
[0023] Prune different numbers of tokens in each layer;
[0024] Apply a progressive pruning strategy, keeping more tokens in earlier transformer layers, gradually removing more tokens in later layers, and gradually reducing the number of tokens until the end of the transformer;
[0025] In the pre-filling phase, the hidden state is calculated for each token, and progressive token pruning is achieved by removing the hidden state of the pruned token.
[0026] For tokens pruned in subsequent layers, the hidden states are stored in an auxiliary cache;
[0027] During the decoding phase, each transformer layer retrieves the KV pairs of past tokens from the KV cache. For tokens that do not exist in the KV cache, the LazyLLM retrieves the hidden states from the auxiliary cache.
[0028] As a preferred solution of the method for extracting emotions from multi-round dialogues using large language model reasoning described in the present invention, the method of establishing a knowledge distillation model and constructing a multi-level teacher model based on the reasoning results combined with multi-round dialogue data includes the following steps:
[0029] Teachers with different levels of understanding of the components of the dialogue document were constructed;
[0030] The input of all teachers consists of each round of speech in the dialogue dataset, expressed as,
[0031]
[0032] Among them, X i represents the i-th speech in the entire data set, l is the length of the speech, Indicates a word in a speech;
[0033] Word Level Slot Filling Teacher T SF Predict the slot type for each word, word-level slot filling teacher T SF The output of is represented as the predicted slot type for each word;
[0034] Sentence-level intent detection teacher T ID Predict the intent of the utterance and detect the name-level intent of the teacher T ID For prediction express,
[0035]
[0036] Among them, k IDIndicates the number of intents in the dataset, and ID is the intent detection task;
[0037] Dialogue document-level domain classification teacher T DC Predict the domain of the conversation from the document-level domain classification teacher T DC The predicted value is expressed as
[0038]
[0039] Among them, k DC is the number of domains in the dataset, DC is the domain classification task;
[0040] Apply cross entropy loss and fine-tune the pre-trained model for a fixed number of rounds, using the checkpoint of the last round as the teacher model. The specific expression is,
[0041]
[0042] j∈{DC,ID,SF}
[0043] Among them, N M2M and N MultiWoz is the number of training samples, Y j is the true value, X j,train represents the set of speeches with a length of j in the training set, represents the first speech in the set of speeches of length j in the training set, Indicates the Nth sentence in the set with speech length j in the training set M2M A speech, Indicates the Nth sentence in the set with speech length j in the training set MultiWoz A speech, represents the cross entropy loss, T j represents the teacher model, where j∈{DC, ID, SF};
[0044] The teachers at different levels of understanding of dialogue document components include word-level slots, sentence-level intent, and dialogue-level domain knowledge.
[0045] As a preferred solution of the multi-round dialogue emotion quadruple extraction method using large language model reasoning described in the present invention, wherein: the multi-level teacher model guides the student model to learn detailed information in the dialogue from multi-level dialogue knowledge, including the following steps:
[0046] The KD loss is calculated by comparing the average probability produced by the teacher model ensemble with the probability derived by the student model;
[0047] Use KD loss to align the predicted probability distribution between the student model and the teacher model;
[0048] By using the cross-entropy loss, the student model receives direct supervision signals from the ground truth;
[0049] During the training process, triplets are randomly generated for each batch of data, and the internal relations of the triplets are determined by aggregating the votes of the teacher model combinations;
[0050] Use TripletMarginLoss to minimize the distance between positive samples and anchor samples, while maximizing the distance between negative samples and anchor samples;
[0051] The similarity loss is calculated by maximizing the similarity of the prediction vectors (logits) between the student model and the teacher model;
[0052] Incorporate the teacher model’s predictions as pseudo labels and use the probabilities assigned by the teacher model for each class.
[0053] As a preferred solution of the method for extracting emotions from multi-round dialogues using large language model reasoning described in the present invention, the dialogue graph is constructed based on the dialogue processed by the dynamic word gram pruning model (LazyLLM) and the knowledge distillation model, including the following steps:
[0054] In the dialogue data, each round of speech is regarded as a sentence, and these sentences are combined to form the input of the model. Assuming that the current dialogue data contains multiple rounds, each sentence and utterance is recorded as u i , connect these words in series as input, construct the input format, expressed as,
[0055]
[0056] in, represents a concatenation operation, [CLS] is a special classification identifier, [SEP] is a separator used to distinguish utterances, and u n represents the nth utterance, i.e. the last utterance in the sequence;
[0057] After encoding by the pre-trained language model, the output form is expressed as,
[0058]
[0059] Where H = [, h1, h2, ..., h n ] is the encoding symbol u1,...,u n , let V = {v1, ..., v n} corresponds to each [CLS] as the embedding of each utterance;
[0060] The embedding of each utterance is assigned as a node in the conversation graph, and edges are constructed based on the reply relations and semantic similarity in the conversation;
[0061] For any two utterances u i and u j , if u j It's for u i The reply is, then at the corresponding node u i and u j Create a bidirectional edge between them;
[0062] For any two nodes v that are not directly connected i and v j , if there is an intermediate node v k Make v i and v j By v k To form a path, then at v i and v j Add an edge between them;
[0063] The weight of each edge is calculated by the cosine similarity of the node embeddings;
[0064] Add a self-loop edge to each node, that is, at each node v i Create an edge with weight 1.
[0065] As a preferred solution of the method for extracting emotions from a multi-round dialogue using a large language model inference according to the present invention, the method uses a two-dimensional structural entropy minimization algorithm to divide the dialogue into the smallest sub-dialogues, and performs a merging operation to achieve the optimal division to form a sub-dialogue set, including the following steps:
[0066] Initialize the conversation graph as a coding tree T. Each leaf node represents a vertex in the conversation graph. If two leaf nodes share the same parent node, it means that the two leaf nodes belong to the same child conversation cluster. Initially, each leaf node is regarded as a separate cluster.
[0067] For two sub-coding trees T in coding tree T α and sub-coding tree T β Share the same parent node and perform the merge operation Merge(T α , T β ) Generate a new coding tree T′ (α,β) , before and after the merge operation, the SE change calculation formula of the coding tree T is,
[0068] △(T;T α , T β )=SE'-SE
[0069]
[0070] in, and They are sub-coding trees T α and sub-coding tree T ∈ After the merger, H T (G; α), H T (G; β) and H T (G;∈) are T α , T β and T ∈ In the SE before the merge operation, if Δ(T; T α , T β )>0, indicating that the SE of the merged coding tree T decreases, SE′ represents the structural entropy after the merge operation, SE represents the structural entropy before the merge operation, Δ(T; T α , T β ) represents the structural entropy change value of the coding tree T, T ∈ Indicates T α and T β Sub-coding tree of T ∈ The nodes in - Represents the leaf node after removing the ∈ node from the tree;
[0071] Traverse all edges in the coding tree, calculate the SE change of each pair of sub-coding trees before and after merging, and record each merging operation Δ(T; T α , T β ) corresponds to the connection between two leaf nodes, and these leaf nodes are merged to merge the two clusters into one cluster;
[0072] Select the first k edges with the largest SE change value for merging;
[0073] For each selected edge, merge the corresponding two sub-coding trees into a new sub-coding tree, and update the coding tree T;
[0074] In each iteration, the structural entropy of the coding tree will gradually decrease, and the number of sub-dialog clusters will be gradually reduced by continuously merging sub-coding trees;
[0075] When the SE of the coding tree T no longer decreases, the iteration is stopped and the coding tree structure finally stabilizes;
[0076] When dividing a conversation, the root utterance is included in each sub-conversation cluster to form a sub-conversation set.
[0077] As a preferred solution of the method for extracting emotion quadruple from multi-round dialogues using large language model reasoning described in the present invention, the steps of constructing a two-dimensional table, annotating entity relationships, extracting entities from discourse, matching entities based on sub-dialogue sets, and forming emotion quadruple include the following steps:
[0078] Represent the relationship between any two boundary locations in each utterance as cells in a two-dimensional table;
[0079] Use two dense multilayer perceptrons to learn the start and end boundaries of utterances;
[0080] The boundary relationship table is constructed using the start boundary and the end boundary of the utterance, and the maximum pooling operation is performed on the boundary relationship table;
[0081] Applying dual affine attention to further model boundary relations in discourse;
[0082] Input the boundary relationship table into a dense layer and a CNN layer to obtain the final entity relationship table;
[0083] Use a linear layer to predict the label for each position;
[0084] Introducing a cross-entropy based loss function to perform supervised learning for each position in each utterance;
[0085] Extract all target, aspect, and opinion entity spans from each utterance, and group entities belonging to the same sub-dialogue together based on the partitioned sub-dialogue set;
[0086] Pair the target, aspect and opinion entities to form three types of entity pairs: target-aspect pair TA, target-opinion pair TO and aspect-opinion pair AO;
[0087] For target-aspect pair TA entity and target-opinion pair TO entity, use labels to determine whether they belong to the same sentiment quadruple;
[0088] For target-opinion pairs TO entity pairs, labels are used to determine their inclusion in the same sentiment quartet and the sentiment polarity of the quartet.
[0089] As a preferred solution of the multi-round dialogue emotion quadruple extraction method using large language model reasoning described in the present invention, wherein: the relationship between entities is predicted through maximum pooling operation, and finally the emotion quadruple is matched, including the following steps:
[0090] For two span spaces that do not belong to the same entity category in the same sub-dialogue set, perform maximum pooling operations on their span ranges;
[0091] Perform a linear transformation on each pair of span representations to obtain the final span representation;
[0092] Use a labeled linear layer to predict the relationship label between each pair of entities based on the final spanned representation;
[0093] For each sentiment triple, traverse the combination of target, aspect, and opinion in turn;
[0094] If and only if all conditions are met simultaneously, the triple forms a successful sentiment quadruple.
[0095] The beneficial effects of the present invention are as follows: through the preprocessing of dialogue data, dynamic word pruning, knowledge distillation, the introduction of a multi-level teacher model, and the dialogue division and entity matching method based on the entropy minimization algorithm, the fine-grained extraction of dialogue sentiment is achieved as a whole, and each step cooperates with each other, which not only improves the computational efficiency of the model, but also enhances the accuracy of dialogue sentiment extraction. BRIEF DESCRIPTION OF THE DRAWINGS
[0096] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other accompanying drawings can be obtained based on these accompanying drawings without paying creative work.
[0097] Figure 1 This is a flowchart of the method for extracting quadruple emotions from multi-turn dialogues using large language model reasoning in Example 1.
[0098] Figure 2 This is a diagram of the dynamic word pruning model based on a large language model in Example 1.
[0099] Figure 3 This is a diagram of the knowledge distillation model used for multi-round dialogue understanding in Example 1.
[0100] Figure 4 This is a four-fold extraction graph of conversational emotions based on structural entropy minimization in Example 1. DETAILED DESCRIPTION
[0101] In order to make the above-mentioned objects, features and advantages of the present invention more obvious and easy to understand, the specific implementation methods of the present invention are described in detail below in conjunction with the accompanying drawings.
[0102] In the following description, many specific details are set forth to facilitate a full understanding of the present invention, but the present invention may also be implemented in other ways different from those described herein, and those skilled in the art may make similar generalizations without violating the connotation of the present invention. Therefore, the present invention is not limited to the specific embodiments disclosed below.
[0103] Secondly, the term "one embodiment" or "embodiment" as used herein refers to a specific feature, structure, or characteristic that may be included in at least one implementation of the present invention. The term "in one embodiment" that appears in different places in this specification does not necessarily refer to the same embodiment, nor does it refer to a separate or selective embodiment that is mutually exclusive with other embodiments.
[0104] Example 1, reference Figure 1 , Figure 2 , Figure 3 and Figure 4 , which is the first embodiment of the present invention, and provides a method for extracting emotions from a multi-turn dialogue using a large language model inference, including the following steps:
[0105] S1. Collect multi-round conversation data and context information between customer service and customers, and pre-process the collected data, including the following steps:
[0106] Choose a fully functional online customer service platform. These platforms generally record all conversations between customers and customer service. Before starting to collect data, you need to ensure that you comply with relevant data protection laws and regulations to ensure that customer privacy is protected;
[0107] Extract conversation records, including customer ID, customer service ID, conversation content, timestamp, and conversation rounds, through the API provided by the platform or direct database access. For example, the data structure may include the following fields: customer ID: a unique number that identifies the customer, customer service ID: a unique number that identifies the customer service, conversation content: the text content of each round of conversation, timestamp: the time when each message was sent, conversation rounds: the round information of the conversation is recorded to analyze emotional changes.
[0108] In the process of data collection, special attention should be paid to the collection of contextual information. For example, the customer's historical interaction records before the conversation began can be recorded. This historical information can provide important background and help understand the customer's emotional changes. When extracting data, it is recommended to cover conversations in different time periods as much as possible to capture different situations and emotional expressions. Contextual information includes conversation topics, related business status, and customer information;
[0109] To enrich the dataset, you can collect customer feedback data, such as satisfaction ratings and follow-up reviews. These feedbacks can help annotate the emotional state of the conversation;
[0110] Clean the data to remove irrelevant information and noise, including: deleting automatically generated system prompts, welcome messages, etc., to ensure that only the actual conversation between the customer and the customer service is retained; checking the missing values in the data and deciding whether to fill in (such as using the mean or median) or delete missing records; eliminating obvious abnormal conversations, such as obvious meaningless text or overly brief conversations;
[0111] The conversation text is standardized to improve the accuracy of the analysis, including converting all text to lowercase or uppercase to eliminate duplication caused by different cases; cleaning up special characters, punctuation marks and extra spaces in the text to keep the text neat; expanding common abbreviations and correcting spelling errors to ensure the readability of the text.
[0112] S2, performing word pruning on the collected context information through a dynamic word pruning model, including the following steps:
[0113] The LazyLLM starts with a full context and gradually reduces the tokens to gradually reduce the number of computations at the end of the model. The LazyLLM allows the model to select different subsets of tokens from the context at different generation steps, even though some of them may have been removed in previous steps. Compared to static pruning, which prunes all tokens at once, dynamic pruning optimizes the next prediction of each generation token, which is critical to maintaining performance.
[0114] The dynamic token pruning model (LazyLLM) “lazily” computes tokens that are important for predicting the next token only in the first round of inference (pre-population phase). A key challenge in pruning tokens in the first round is to determine their importance.
[0115] Progressive token pruning methods need to accumulate the full attention maps of the first few tokens predicted in order to analyze the importance of the hint tokens before starting pruning. Therefore, they are not suitable for reducing the time to the first token because they still need to calculate all KV caches in the pre-filling stage.
[0116] In each generation step, use the layer The attention map determines the input word t i The importance relative to the next token to be predicted is expressed as,
[0117]
[0118] Among them, H is the number of attention avatars, N is the sequence length, t j In the hth head, for word t i The probability of attention, t i Confidence score at level l+1;
[0119] After calculating the confidence score of the token, the threshold for pruning tokens is determined by using a top-k percentile selection strategy, which varies with the distribution of attention scores between different layers and different tasks;
[0120] In each transformer layer, the Top-k percentile is selected as the threshold for word pruning according to the importance score of the word. i Confidence score at level l+1 Less than the kth l percentile, the word will be pruned. Once the word is pruned, it will be excluded from the calculation of all subsequent layers, and the words used in the subsequent layers will be a subset of the previous layers. l represents the percentage used to determine the threshold in layer l, for example, k l A value of 30 means that 30% of the words in layer l have confidence scores lower than this value;
[0121] The position of different pruned layers and the number of pruned tokens have an impact on performance. When pruning is performed on the same transformer layer, the performance of the model gradually decreases as the number of tokens retained decreases. Pruning in later transformer layers always performs better than pruning in earlier layers, which indicates that later layers are less sensitive to token pruning. In order to achieve a better balance between acceleration and accuracy, a progressive pruning strategy is applied, retaining more tokens in earlier transformer layers, gradually removing more tokens in later layers, and gradually reducing the number of tokens until the end of the transformer.
[0122] In the pre-filling phase, hidden states are calculated for each token, and progressive token pruning is achieved by removing the hidden states of pruned tokens.
[0123] In the decoding stage, an auxiliary cache (AuxCache) is introduced. In addition to the original KV cache, the auxiliary cache stores the hidden states of those pruned tokens. If their KV does not exist in the KV cache of the subsequent layer, these hidden states can be retrieved in subsequent iterations;
[0124] In each decoding step, each transformer layer (e.g., layer l+1) first retrieves the KV cache of past tokens. For those tokens that do not exist in the KV cache, their hidden states can be directly retrieved from the auxiliary cache of its previous layer without passing through the previous layer again. The introduction of the auxiliary cache ensures that each token is calculated at most once in each transformer layer and ensures that the worst-case running time of the dynamic token pruning model (LazyLLM) is no slower than the baseline.
[0125] S3, the establishment of the knowledge distillation model, building a multi-level teacher model based on the inference results combined with multi-round dialogue data, includes the following steps:
[0126] To enhance natural language understanding in multi-turn dialogues, a new multi-level dialogue teacher knowledge distillation framework is introduced, which enhances natural language understanding capabilities by training student models through multi-level teachers.
[0127] We built teachers with different levels of understanding of conversational document components, including word-level slots, sentence-level intent, and conversation-level domain knowledge;
[0128] The input of all teachers consists of each round of speech in the dialogue dataset, expressed as,
[0129]
[0130] Among them, X i represents the i-th speech in the entire data set, l is the length of the speech, Indicates a word in a speech;
[0131] Word Level Slot Filling Teacher T SF Predict the slot type for each word, provide the student model with knowledge about key slots in the conversation, and the word-level slot filling teacher T SF The output represents the predicted slot type for each word The expression is,
[0132]
[0133] in, k SF is the number of slot types;
[0134] Sentence-level intent detection teacher T ID Predict the intent of the utterance, help the student model understand the overall intent of each turn, and perform sentence-level intent detection on the teacher T ID For prediction express,
[0135]
[0136] Among them, k ID Indicates the number of intents in the dataset, and ID is the intent detection task;
[0137] Dialogue document-level domain classification teacher T DC Predicting the domain of the dialogue provides information for its classification and understanding of background knowledge, from the document-level domain classification teacher T DC The predicted value is expressed as
[0138]
[0139] Among them, k DC is the number of domains in the dataset, DC is the domain classification task;
[0140] Through these three levels of teachers, the student model is guided to understand the conversation from multiple perspectives, which enhances the student model's grasp of different levels of conversation. Each pre-trained model focuses on learning a specific level of knowledge from the conversation dataset, so that the teacher has different levels of understanding of the components of the conversation document;
[0141] Each teacher focuses on one level of conversational knowledge. This approach is motivated by two factors; first, learning knowledge from a single task is simpler than integrating knowledge from all tasks, simplifying the fine-tuning of pre-trained models. Second, rather than burdening a single model with the challenge of grasping knowledge from all aspects of the conversation, each teacher focuses on a specific level of understanding.
[0142] Apply cross entropy loss and fine-tune the pre-trained model for a fixed number of rounds, using the checkpoint of the last round as the teacher model. The specific expression is,
[0143]
[0144] j∈{DC,ID,SF}
[0145] Among them, N M2M and N MultiWoz is the number of training samples, Y j is the true value, X j,train represents the set of speeches with a length of j in the training set, represents the first speech in the set of speeches of length j in the training set, Indicates the Nth sentence in the set with speech length j in the training set M2M A speech, Indicates the Nth sentence in the set with speech length j in the training set MultiWoz A speech, represents the cross entropy loss, T j represents the teacher model, where j∈{DC, ID, SF}.
[0146] S4. Guide the student model to learn detailed information in the conversation from multi-level conversation knowledge through a multi-level teacher model, including the following steps:
[0147] After obtaining multi-level teachers, a mixture of these teachers is used to guide the student model through the distillation of multi-level teacher knowledge. The teacher combination includes different levels, such as BERT-BaseID, BERT-Base SF, and BERT-BaseDC. The student model is trained separately for each task, enabling it to master the complexity of a single task with the help of different levels of conversation knowledge.
[0148] The KD loss is calculated by comparing the average probability produced by the teacher model combination with the probability obtained by the student model. The KD loss is used to align the predicted probability distribution between the student model and the teacher model, so that the student model can learn from multiple teachers. The expression is,
[0149]
[0150] Among them, n T is the number of teachers, KL divergence loss (KLDivLoss) represents KD loss, T j represents the teacher model, T j (X) represents the log odds of the teacher model, S(X) represents the log odds of the student model, P j is the normalized exponential function (softmax) of the teacher model, i.e., the activation function, P s is the normalized exponential function (softmax) of the student model;
[0151] By using the cross entropy loss The student model receives direct supervision signals from the real situation to help its learning process. This loss function is calculated by comparing the predictions of the student model with the basic facts of each task. The specific formula is,
[0152]
[0153] Among them, v s represents the log odds of the Student model, Y true represents the true value;
[0154] During the training process, triplets are randomly generated for each batch of data, and the internal relations of the triplets are determined by aggregating the votes of the teacher model combinations;
[0155] Use triplet loss (TripletMarginLoss) to minimize the distance between positive samples and anchor samples, while maximizing the distance between negative samples and anchor samples. Using triplet loss (TripletMarginLoss), the student model learns the internal relationship between batches of data, so that its understanding is consistent with that of the teacher model and ensures a consistent view of the data set. The expression is,
[0156]
[0157] in, represents the relation loss, N is the batch size, and T is the triple;
[0158] The similarity loss is calculated by maximizing the similarity of the prediction vectors (logits) between the student model and the teacher model. In this way, the student model can learn the knowledge of the feature space from the teacher model instead of just the prediction probability. The expression is,
[0159]
[0160] in, represents the similarity loss, F sim represents the similarity function, v t represents the log odds of the teacher model;
[0161] The predictions of the teacher model are incorporated as pseudo labels to facilitate the training of the student model, and the probability assigned by the teacher model is used for each class to ensure that the student fully acquires the knowledge embedded in the teacher model, expressed as,
[0162]
[0163] S5. Based on the conversations processed by the LazyLLM and knowledge distillation models, a conversation graph is constructed, including the following steps:
[0164] In the dialogue data, each round of speech is regarded as a sentence, and these sentences are combined to form the input of the model. Assuming that the current dialogue data contains multiple rounds, each sentence and utterance is recorded as y i , where y i represents the i-th utterance, i belongs to 1,...,n;
[0165] These utterances are concatenated as input and the input format is constructed, which is expressed as:
[0166]
[0167] in, represents a concatenation operation, [CLS] is a special classification identifier, [SEP] is a separator used to distinguish utterances, and u n represents the nth utterance, i.e. the last utterance in the sequence;
[0168] After encoding by the pre-trained language model, the output form is expressed as,
[0169]
[0170] Where H = [, h1, h2, ..., h n ] is the encoding symbol u1,...,u n , let ν={v1,...,v n} corresponds to each [CLS] as the embedding of each utterance;
[0171] The embedding of each utterance is assigned as a node in the conversation graph, and edges are constructed based on the reply relations and semantic similarity in the conversation;
[0172] For any two utterances u i and u j , if u j It's for u i The reply is, then at the corresponding node u i and u j Create a bidirectional edge between them;
[0173] For any two nodes v that are not directly connected i and v j , if there is an intermediate node v k Make v i and v j By v k To form a path, then at v i and v j Add an edge between them;
[0174] The weight of each edge is calculated by the cosine similarity of the node embeddings;
[0175] Add a self-loop edge to each node, that is, at each node v i It establishes an edge with a weight of 1, and after adding a self-loop, an undirected conversation graph G is constructed.
[0176] S6. Using a two-dimensional structural entropy minimization algorithm to divide the conversation into the smallest sub-conversations, and performing a merge operation to achieve optimal division to form a sub-conversation set, including the following steps:
[0177] Initialize the conversation graph into a coding tree T. Each leaf node represents a vertex in the conversation graph G. If two leaf nodes share the same parent node, they belong to the same child conversation cluster. Initially, each leaf node is regarded as a separate cluster.
[0178] For two sub-coding trees T in coding tree T α and sub-coding tree T β Share the same parent node and perform the merge operation Merge(T α , T β ) Generate a new coding tree T′ (α,β) , which can be understood as merging cluster β into α. Before and after the merging operation, the SE change calculation formula of the coding tree T is,
[0179] Δ(T; T α , T β )=SE'-SE
[0180]
[0181] in, and They are sub-coding tree Tx and sub-coding tree T ∈ After the merger, H T (G; α), H T (G; β) and H T (G;∈) are T α , T β and T ∈ In the SE before the merge operation, if Δ(T; T α , T β )>0, indicating that the SE of the merged coding tree T is reduced, thereby reducing uncertainty, SE′ represents the structural entropy after the merge operation, SE represents the structural entropy before the merge operation, Δ(T; T α , T β ) represents the structural entropy change value of the coding tree T, T ∈ Indicates T α and T β Sub-coding tree of T ∈ The nodes in - Represents the leaf node after removing the ∈ node from the tree;
[0182] Traverse all edges in the coding tree, calculate the SE change of each pair of sub-coding trees before and after merging, and record each merging operation Δ(T; T α , T β ) corresponds to the connection between two leaf nodes, and merging these leaf nodes can be regarded as merging two clusters into one cluster;
[0183] Select the first k edges with the largest SE change value for merging;
[0184] For each selected edge, the corresponding two sub-coding trees are merged into a new sub-coding tree, and the coding tree T is updated. After each merge operation, the structural entropy of the coding tree will be reduced overall;
[0185] In each iteration, the structural entropy of the coding tree will gradually decrease, and the number of sub-dialog clusters will be gradually reduced by continuously merging sub-coding trees;
[0186] When the SE of the coding tree T no longer decreases, the iteration is stopped and the coding tree structure finally stabilizes, thus achieving the optimal division of sub-dialogs;
[0187] Since the root discourse contains common topic information, when dividing the conversation, the root discourse is included in each sub-conversation cluster to form a sub-conversation set;
[0188] The coding tree T is defined as follows: Each node α in the coding tree T has an associated subset For the root node λ in T, For any leaf node γ in the coding tree T, T γ = {v}, where v is A single node in; the n child nodes of node α are denoted as β1, ..., β n , mutually exclusive It is T α The height of node α is recorded as h(α); h(γ) = 0, h(α - )=j(α)+1where α - is the parent node of α; the height of the coding tree T is recorded as h(T) = max α∈T h(α); Intuitively, the coding tree reflects the hierarchical division of the graph, and the k-dimensional coding tree means h(T) = k;
[0189] The SE of a graph G determined by a coding tree T is defined as:
[0190]
[0191] Among them, g α From T α The sum of the edge weights to all external vertices, vol(λ), vol(α), and vol(α - ) represent vertices λ, α and α respectively. - The degree.
[0192] Depending on the order, graph G has multiple different k-dimensional coding trees. The optimal k-dimensional coding tree is defined as the one with the minimum SE. Therefore, the k-dimensional SE of graph G is defined as:
[0193] S7, construct a two-dimensional table, mark entity relationships, extract entities in the discourse, match entities based on sub-dialogue sets, and form sentiment quadruplets, including the following steps:
[0194] Represent the relationship between any two boundary locations in each utterance as cells in a two-dimensional table;
[0195] Entities are labeled in a two-dimensional table, where the vertical axis represents the start of the span and the horizontal axis represents the end of the span. For any entity span in the range [a, b] (where a ≤ b) in the utterance, it can be uniquely labeled at the coordinates in the table. There are four different labels in total:
[0196] {Target(T), Aspect(A), Opinion(O), None(N);
[0197] The start and end boundaries of an utterance are learned using two dense multilayer perceptrons, represented as,
[0198] h s =MLP s (h),h e =MLP e (h)
[0199] Among them, h s ,h e ∈R m×d′ It is the boundary representation;
[0200] The boundary relationship table is constructed using the start boundary and end boundary of the speech, and the maximum pooling operation is performed on the boundary relationship table. The expression is:
[0201]
[0202] Among them, r i,j ∈R 3d′+η is the first representation of (i, j) in the entity relationship table R, Pool(·) is the maximum pooling operation, the purpose of which is to obtain all the information of the span [i, j] in the utterance, Biaf(·) is the biaffine attention operation, W1∈R d′×η×d′ is the parameter matrix;
[0203] Applying dual affine attention to further model boundary relations in discourse;
[0204] To further enhance the boundary relations, the boundary relation table is input into a dense layer and then into a separate CNN layer to obtain the final entity relation table, which is expressed as,
[0205]
[0206] Among them, MLP d :{R→R d′} is a dense layer, Conv (3×3) is a single CNN layer with a kernel size of 3×3 and a stride of 1;
[0207] Using a linear layer MLP ent :{R d′ →R 4}predict The label for each position in , if belongs to {T, A, O}, then the span in the range [i, j] can be extracted as the corresponding entity;
[0208] A cross-entropy-based loss function is introduced to perform supervised learning on each position in each utterance, expressed as:
[0209]
[0210] Among them l ent is the loss of an utterance of length m, is the index of position (i, j), I(·) is the indicator function, n is the number of utterances in the conversation, l ent is the total number of all utterances;
[0211] Take the target, aspect and opinion entity spans from each utterance, and group the entities belonging to the same sub-dialogue together based on the divided sub-dialogue set;
[0212] Pair the target, aspect and opinion entities to form three types of entity pairs: target-aspect pair (TA), target-opinion pair (TO) and aspect-opinion pair (AO);
[0213] For each pair of TA and TO entities, use the label {Related(R), N} to determine whether they belong to the same sentiment quadruple;
[0214] For TO pairs, use the label
[0215] {Positive (Pos), Negave (Neg), Neutral (Neu), N} determine their inclusion in the same emotion quartet and the emotion polarity of the quartet.
[0216] S8, predict the relationship between entities through the maximum pooling operation, and finally match the sentiment quadruple, including the following steps:
[0217] For two spanned spaces ε that do not belong to the same entity category in the same sub-dialogue i and ε j , and perform the maximum pooling operation on their span range, we can get their span representation as,
[0218]
[0219] (ε i , ε j ) It is expressed as:
[0220]
[0221] in, is the representation of all utterances in c, W2∈R d×η×d is a learnable parameter matrix that linearly transforms each pair of span representations to obtain the final span representation;
[0222] Using labeled linear layer MLP rel :{R 3d+η →R 5} to predict Tags
[0223] Use a labeled linear layer to predict the relationship label between each pair of entities based on the final spanned representation;
[0224] For each sentiment triple, traverse the combination of target, aspect, and opinion in turn;
[0225] If and only if and When
[0226] The loss function is introduced to measure whether the model's prediction of entity-to-entity relationships is accurate, and the expression is:
[0227]
[0228] in, represents the loss of subdialogue c, m is the number of traversal pairs;
[0229] The loss of the quadruple matching module is combined with the losses of other modules to form the final overall loss function, which is expressed as:
[0230]
[0231] In summary, the present invention collects multi-round dialogue data and context information, and removes noise data and redundant messages in combination with preprocessing operations, thereby improving the accuracy and standardization of data and reducing model understanding errors; through dynamic word pruning, the operating efficiency of the model is improved, making the reasoning speed faster, while reducing the resource consumption of the model, especially for long text dialogues, it can effectively reduce the interference of redundant information; through multi-level knowledge distillation, the student model can acquire the knowledge of the teacher model with fewer parameters, and the multi-level teacher model can provide a more comprehensive dialogue understanding, significantly improving the model's ability to capture the content of the dialogue; by dividing the dialogue into the smallest sub-dialogue set, the model can be clearer The hierarchical structure of the conversation is understood accurately, ensuring the refined processing of the emotion quadruple extraction. The introduction of the entropy minimization algorithm further optimizes the conversation division, avoids the problem of too fine or too coarse conversation division, and improves the accuracy of conversation emotion extraction. By using two-dimensional tables to label and predict entity relationships, the model can extract entities in the conversation more finely and accurately match the emotion quadruple, effectively reducing the possible errors in the entity relationship extraction process and ensuring the accuracy and completeness of the emotion quadruple. Through the maximum pooling operation, the model can quickly capture the key information between entities, improve the accuracy of relationship prediction, achieve efficient matching of emotion quadruple, and ensure the comprehensive extraction and expression of conversation emotion information.
[0232] It should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention rather than to limit it. Although the present invention has been described in detail with reference to the preferred embodiments, those skilled in the art should understand that the technical solutions of the present invention may be modified or replaced by equivalents without departing from the spirit and scope of the technical solutions of the present invention, which should all be included in the scope of the claims of the present invention.
Claims
1. A method for extracting emotion quadruple from multi-turn dialogues using large language model reasoning, characterized by: include, Collect multi-round conversation data and context information between customer service and customers, and pre-process the collected data; The collected context information is pruned using a dynamic lemma pruning model; Establish a knowledge distillation model and build a multi-level teacher model based on the reasoning results and multi-round dialogue data; The multi-level teacher model guides the student model to learn the detailed information in the conversation from the multi-level conversation knowledge; Construct a conversation graph based on the conversations processed by LazyLLM and the knowledge distillation model; Use a two-dimensional structural entropy minimization algorithm to divide the conversation into the smallest sub-conversations, and perform a merge operation to achieve the optimal division to form a sub-conversation set; Construct a two-dimensional table, annotate entity relationships, extract entities in discourse, match entities based on sub-dialogue sets, and form sentiment quadruples; Through the maximum pooling operation, the relationship between entities is predicted and finally the sentiment quadruple is matched; The word pruning of the collected context information by the dynamic word pruning model includes the following steps: In each generation step, use the layer The attention map determines the input word t i The importance relative to the next token to be predicted is expressed as, Among them, H is the number of attention avatars, N is the sequence length, t j In the hth head, for word t i The probability of attention, t i Confidence score at level l+1; In each transformer layer, the Top-k percentile is selected as the threshold for word pruning based on the importance score of the word. i Confidence score at level l+1 Less than the kth l percentile, the word will be pruned. Once the word is pruned, it will be excluded from the calculation of all subsequent layers. l Represents the percentage used to determine the threshold in layer l; Prune different numbers of tokens in each layer; Apply a progressive pruning strategy, retaining more tokens in earlier transformer layers, gradually removing more tokens in later layers, and gradually reducing the number of tokens until the end of the transformer; In the pre-filling phase, the hidden state is calculated for each token, and progressive token pruning is achieved by removing the hidden state of the pruned token. For tokens pruned in subsequent layers, the hidden states are stored in an auxiliary cache; In the decoding phase, each transformer layer retrieves the KV pairs of past tokens from the KV cache. For tokens that do not exist in the KV cache, LazyLLM retrieves the hidden state from the auxiliary cache. The knowledge distillation model is established to build a multi-level teacher model based on the reasoning results combined with multi-round dialogue data, including the following steps: Teachers with different levels of understanding of the components of the dialogue document were constructed; The input of all teachers consists of each round of speech in the dialogue dataset, expressed as, Among them, X i represents the i-th speech in the entire data set, l is the length of the speech, Indicates a word in a speech; Word Level Slot Filling Teacher T SF Predict the slot type for each word, word-level slot filling teacher T SF The output of is represented as the predicted slot type for each word; Sentence-level intent detection teacher T ID Predict the intent of the utterance and detect the sentence-level intent using the teacher T ID For prediction express, Among them, k ID Indicates the number of intents in the dataset, and ID is the intent detection task; Dialogue T DC Predict the domain of the conversation, from the level domain classification teacher T DC The predicted value is expressed as Among them, k DC is the number of domains in the dataset, DC is the domain classification task; Apply cross entropy loss and fine-tune the pre-trained model for a fixed number of rounds, using the checkpoint of the last round as the teacher model. The specific expression is, Among them, N M2M and N MultiWoz is the number of training samples, Y j is the true value, X j,train represents the set of speeches with a length of j in the training set, represents the first speech in the set of speeches of length j in the training set, Indicates the Nth sentence in the set with speech length j in the training set M2M A speech, Indicates the Nth sentence in the set with speech length j in the training set MultiWoz A speech, represents the cross entropy loss, T j represents the teacher model, where j∈{DC, ID, SF}; The teachers of different levels of understanding of the components of the dialogue document include word-level slots, sentence-level intent, and dialogue-level domain knowledge; The method of guiding the student model to learn detailed information in the conversation from multi-level conversation knowledge through a multi-level teacher model includes the following steps: The KD loss is calculated by comparing the average probability produced by the teacher model ensemble with the probability derived by the student model; Use KD loss to align the predicted probability distribution between the student model and the teacher model; By using the cross-entropy loss, the student model receives direct supervision signals from the ground truth; During the training process, triplets are randomly generated for each batch of data, and the internal relations of the triplets are determined by aggregating the votes of the teacher model combinations; Use TripletMarginLoss to minimize the distance between positive samples and anchor samples, while maximizing the distance between negative samples and anchor samples; The similarity loss is calculated by maximizing the similarity of logits between the student model and the teacher model; Incorporate the teacher model’s predictions as pseudo labels and use the probabilities assigned by the teacher model for each class; The dialogue processed based on LazyLLM and knowledge distillation model is used to construct a dialogue graph, including the following steps: In the dialogue data, each round of speech is regarded as a sentence, and these sentences are combined to form the input of the model. Assuming that the current dialogue data contains multiple rounds, each sentence and utterance is recorded as u i , connect these words in series as input, construct the input format, expressed as, in, represents a concatenation operation, [CLS] is a special classification identifier, [SEP] is a separator used to distinguish utterances, and u n represents the nth utterance, i.e. the last utterance in the sequence; After encoding by the pre-trained language model, the output form is expressed as, Where H = [h1, h2, ..., h n ] is the utterance u1, ..., u n The encoding symbol is Corresponding to each [CLS] as the embedding of each utterance; The embedding of each utterance is assigned as a node in the conversation graph, and edges are constructed based on the reply relations and semantic similarity in the conversation; For any two utterances u i and u j , if u j It's for u i The reply is, then at the corresponding node u i and u j Create a bidirectional edge between them; For any two nodes v that are not directly connected i and v j , if there is an intermediate node v k Make v i and v j By v k To form a path, then at v i and v j Add an edge between them; The weight of each edge is calculated by the cosine similarity of the node embeddings; Add a self-loop edge to each node, that is, at each node v i Create an edge with weight 1.
2. The method for extracting emotions from multi-turn dialogues using large language model reasoning as claimed in claim 1, characterized in that: The multi-round conversation data includes customer ID, customer service ID, conversation content, timestamp, and conversation round number; The context information includes historical interaction records, conversation topics, relevant business status and customer information; The preprocessing includes data cleaning and text standardization.
3. The method for extracting emotions from multi-turn dialogues using large language model reasoning as claimed in claim 2, characterized in that: The method of using a two-dimensional structural entropy minimization algorithm to divide a conversation into minimum sub-conversations and performing a merging operation to achieve optimal division to form a sub-conversation set includes the following steps: Initialize the conversation graph into a coding tree T. Each leaf node represents a vertex in the conversation graph. If two leaf nodes share the same parent node, it means that the two leaf nodes belong to the same child conversation cluster. Initially, each leaf node is regarded as a separate cluster. For two sub-coding trees T in the coding tree T α and sub-coding tree T β Share the same parent node and perform the merge operation Merge(T α , T β ) Generate a new coding tree T′ (α,β) , before and after the merge operation, the SE change calculation formula of the coding tree T is, Δ(T;T α ,T β )=SE'-SE in, and They are sub-coding trees T α and sub-coding tree T ∈ After the merger, H T (G; α), H T (G; β) and H T (G;∈) are T α , T β and T ∈ In the SE before the merge operation, if Δ(T, T α , T β )>0, indicating that the SE of the merged coding tree T decreases, SE′ represents the structural entropy after the merge operation, SE represents the structural entropy before the merge operation, Δ(T; T α , T β ) represents the structural entropy change value of the coding tree T, T ∈ Indicates T α and T β Sub-coding tree of T ∈ The nodes in - Represents the leaf node after removing the ∈ node from the tree; Traverse all edges in the coding tree, calculate the SE change of each pair of sub-coding trees before and after merging, and record each merging operation Δ(T; T α , T β ) corresponds to the connection between two leaf nodes, and these leaf nodes are merged to merge the two clusters into one cluster; Select the first k edges with the largest SE change value for merging; For each selected edge, merge the corresponding two sub-coding trees into a new sub-coding tree, and update the coding tree T; In each iteration, the structural entropy of the coding tree will gradually decrease, and the number of sub-dialog clusters will be gradually reduced by continuously merging sub-coding trees; When the SE of the coding tree T no longer decreases, the iteration is stopped and the coding tree structure finally stabilizes; When dividing a conversation, the root utterance is included in each sub-conversation cluster to form a sub-conversation set.
4. The method for extracting emotions from multi-turn dialogues using large language model reasoning as claimed in claim 3, characterized in that: The method of constructing a two-dimensional table, marking entity relationships, extracting entities in discourse, matching entities based on sub-dialogue sets, and forming sentiment quadruplets includes the following steps: Represent the relationship between any two boundary locations in each utterance as cells in a two-dimensional table; Use two dense multilayer perceptrons to learn the start and end boundaries of utterances; The boundary relationship table is constructed using the start boundary and the end boundary of the utterance, and the maximum pooling operation is performed on the boundary relationship table; Applying dual affine attention to further model boundary relations in discourse; Input the boundary relationship table into a dense layer and a CNN layer to obtain the final entity relationship table; Use a linear layer to predict the label for each position; Introducing a cross-entropy based loss function to perform supervised learning for each position in each utterance; Extract all target, aspect, and opinion entity spans from each utterance, and group entities belonging to the same sub-dialogue together based on the partitioned sub-dialogue set; Pair the target, aspect and opinion entities to form three types of entity pairs: target-aspect pair TA, target-opinion pair TO and aspect-opinion pair AO; For target-aspect pair TA entity and target-opinion pair TO entity, use labels to determine whether they belong to the same sentiment quadruple; For target-opinion pairs TO entity pairs, labels are used to determine their inclusion in the same sentiment quartet and the sentiment polarity of the quartet.
5. The method for extracting emotions from multi-turn dialogues using large language model reasoning as claimed in claim 4, characterized in that: The method of predicting the relationship between entities through the maximum pooling operation and finally matching the sentiment quadruple includes the following steps: For two span spaces that do not belong to the same entity category in the same sub-dialogue set, perform maximum pooling operations on their span ranges; Perform a linear transformation on each pair of span representations to obtain the final span representation; Use a labeled linear layer to predict the relationship label between each pair of entities based on the final spanned representation; For each sentiment triple, traverse the combination of target, aspect, and opinion in turn; If and only if all conditions are met simultaneously, the triple forms a successful sentiment quadruple.
Citation Information
Patent Citations
Aspect-level sentiment analysis method based on knowledge distillation framework
CN116384373A
Question constraint and focus entity transfer knowledge graph dialogue type question answering method based on reinforcement learning
CN116414956A