A method for training a knowledge-enhanced dialogue system based on hierarchical contrastive learning

By constraining the knowledge neurons in the output and intermediate layers through a hierarchical contrastive learning method, the problem of insufficient accuracy in text word representation and knowledge utilization in dialogue systems is solved, thereby improving the quality of dialogue generation and the ability to utilize external knowledge.

CN117370516BActive Publication Date: 2025-11-14INSTITUTE OF INFORMATION ENGINEERING CHINESE ACADEMY OF SCIENCES
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202311307235.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-10-10
Publication Date
2025-11-14
Estimated Expiration
2043-10-10

AI Technical Summary

Technical Problem

Existing dialogue systems suffer from insufficient accuracy in text word representation and knowledge utilization during training and inference, resulting in generated responses that are incomplete or contain false information and lack the ability to utilize external knowledge.

Method used

We adopt a hierarchical contrastive learning approach, which compares and constrains the representations of the output layer and the knowledge neurons of the intermediate layer, and uses hierarchical contrastive loss and anchor loss functions to improve the accuracy of the language model in using external knowledge.

Benefits of technology

It improves the quality of responses generated by the dialogue system, enhances the model's accuracy in using external knowledge and its ability to represent text words, and improves the overall quality of the dialogue model.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117370516B_ABST
    Figure CN117370516B_ABST
Patent Text Reader

Abstract

This invention relates to a method for training a knowledge-enhanced dialogue system based on hierarchical contrastive learning. The method includes: first, selecting dialogue data and knowledge data, and processing the dialogue data and knowledge data to obtain input data for a language model; second, the language model generates responses based on the input data, the response generation process including selecting an appropriate language model to process the data and selecting an appropriate decoding algorithm to generate the responses; finally, using hierarchical contrastive learning and its extended backpropagation gradient to update the model parameters. Based on a pre-trained language model, hierarchical contrastive learning constraints and its extended anchor loss constraints are applied to the model during training. While ensuring the quality of language syntax, this method improves text word representation, integrates knowledge and dialogue text space, and adjusts the distribution of knowledge neurons, thereby improving the accuracy of the dialogue system's use of external knowledge and ultimately enhancing the quality of dialogue response generation.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention belongs to the field of dialogue systems in natural language processing, and specifically relates to a method for enhancing the training of dialogue systems based on hierarchical contrastive learning knowledge. Background Technology

[0002] Dialogue systems are systems capable of communicating with humans through language, representing a significant research area in the field of artificial intelligence and natural language processing. Today, dialogue systems have become integrated into people's lives, handling tasks such as hotel bookings, personal assistants, website customer service, car navigation, educational support, and casual conversation. The advancement of dialogue systems is attributed to the development of deep learning technology. How to enable dialogue systems to generate higher-quality responses and better serve humanity is a pressing application challenge that needs to be addressed. Currently, deep learning-based dialogue systems generally suffer from the following drawbacks in training and inference: During training, deep learning models store the learned knowledge within the model. However, the knowledge stored within the model is limited, and external knowledge not existing within the model often cannot be effectively utilized. Dialogue systems lacking the ability to utilize external knowledge often generate responses that are incomplete or contain false information, negatively impacting the usability of the dialogue system.

[0003] Existing techniques for enhancing dialogue systems with external knowledge cannot solve the problem of dialogue generation not matching the given knowledge. Zhang et al. [Zhang H. Grounded conversation generation as guided traverses in commonsense knowledge graphs: 2019] introduced knowledge triples from concept networks into dialogue systems and applied graph attention mechanisms to traverse the concept space, allowing the model to shift its attention to nodes more meaningful to the dialogue context. Xu et al. [Xu J. Conversational graph grounded policy learning for open-domain conversation generation: 2020: 1835-1845] used knowledge graphs as an external source to control coarse-grained hierarchical discourse generation. This approach provides common-sense knowledge support for the dialogue, and the system's dialogue topics are guided to more reasonable paths. These methods rely on the accuracy of entity and relation recognition, have high model complexity, and the integration of knowledge and text representation spaces still needs improvement.

[0004] To build knowledge-based dialogue systems, some studies use memory networks to store external knowledge, with the generator retrieving relevant knowledge and facts from the memory modules during the generation phase. Tian et al. [Tian Z. Learning to abstract for memory-augmented conversational response generation: 2019: 3816-3825] developed a memory-enhanced dialogue model that extracts useful information from training samples and stores it in memory modules. While innovative, this requires allocating additional storage space. Bao et al. [Bao S. Know more about each other: Evolving dialogue strategy via compound assessment: 2019] proposed a generative evaluation framework aimed at helping dialogue participants better understand each other and develop better knowledge selection strategies. Within a reinforcement learning framework, they proposed an information content metric as a reward signal for learning knowledge selection strategies. Zhao et al. [Zhao X. Knowledge-grounded dialogue generation with pre-trained language models: 2010.08824, 2020] developed a knowledge-based dialogue generation system based on GPT-2. The knowledge selection module is integrated into the language model, simultaneously learning knowledge selection and response generation. Wu et al. [Wu S. Diverse and informative dialogue generation with context-specific commonsense knowledge awareness: 2020: 5811-5820] established a commonsense knowledge awareness model that uses a coincidental fact mechanism to improve knowledge relevance. Flexible pattern fusion and context-knowledge fusion are proposed to achieve better knowledge integration. Zhong et al. [Zhong P. CARE: commonsense-aware emotional response generation with latent concepts: 2021, 35(16): 14577-14585] further explored ConceptNet and used this knowledge base to enhance the emotional reasoning ability of the dialogue system, which also proves to a certain extent that the improvement of the dialogue system by the knowledge base is not only to enable the model to introduce external professional knowledge, but also to improve the overall quality of the dialogue.Li et al. [Li Y. Graph-Structured Context Understanding for Knowledge-grounded Response Generation:2021:1930-1934] designed a graph reasoning method to plan topic transitions in dialogue responses, making knowledge usage more flexible, coherent, accurate, and user-friendly. These methods have improved the model's ability to use external knowledge, but the accuracy of knowledge usage still needs improvement.

[0005] Contrastive learning methods obtain better data representations by constructing positive and negative samples and using a contrastive learning loss function for constraints. Contrastive learning-based computer vision tasks have achieved good results. However, currently, contrastive learning-based dialogue systems have not been well integrated and applied. Summary of the Invention

[0006] This invention addresses the shortcomings of existing technologies by proposing a method for training a knowledge-enhanced dialogue system based on hierarchical contrastive learning. This method improves the accuracy of the language model in using external knowledge and enhances the quality of response generation by contrasting and constraining the representation of the output layer and the knowledge neurons of the intermediate layer.

[0007] The technical solution of this invention: a method for training a knowledge-enhanced dialogue system based on hierarchical contrastive learning, comprising the following steps:

[0008] Step one involves data processing during the training and inference of the dialogue system, including dialogue data and knowledge data processing. First, dialogue data and knowledge data are selected. Dialogue data can be commonly used dialogue datasets in dialogue system research, dialogues crawled from social networking sites, or dialogues from personal chat logs. Knowledge data can be of various types, including knowledge bases, knowledge graphs, natural language processing related to the dialogue, and Wikipedia search results. The second step is the processing of dialogue data and knowledge data. The dialogue data processing procedure is as follows:

[0009] The dialogues are typically two-person conversations, presented alternately in the order of the dialogue. During use, all dialogues are treated as continuous text, with each speaker switch serving as a segment to construct the input data. Specifically, a 12-turn dialogue is split into 11 data samples; the first sample uses the second sentence as the label and the preceding dialogue as input; the second sample uses the third sentence as the label and the preceding dialogue as input, and so on. In addition, two special characters, [speaker-o] and [speaker-s], are used to mark the words of different speakers, respectively, hoping that the model can learn the differences in speaker identities and generate responses from the perspectives of different speakers.

[0010] Acquiring knowledge data requires named entity recognition of the dialogue content, extracting entities, retrieving relevant knowledge based on entities, and selecting relevant knowledge according to probability. During knowledge data processing, relevant knowledge is directly concatenated with the dialogue as continuous text to form the input to the language model. Various methods can be used to shorten the input length of the knowledge data.

[0011] Step two: The language model generates a response based on the input data. This process involves selecting a suitable language model to process the data and choosing a suitable decoding algorithm to generate the response.

[0012] The language model selected is a pre-trained language model based on word units; the effectiveness for letter-level input has not yet been explored. The language model can be a pre-trained language model from the Transformer series, which is well-suited for all models in the GPT series. Users can choose to initialize using the official model parameters or pre-train from scratch, depending on their own computing resources.

[0013] The technology of this invention is applicable to all mainstream decoding algorithms, including search algorithms and sampling algorithms. Using search algorithms yields higher accuracy, while sampling methods provide more diverse responses. Decoding algorithms are primarily used to convert the model's output into natural language responses.

[0014] Step 3: Use hierarchical contrastive learning and its extended backpropagation gradient to update the model parameters. The Transformer series of pre-trained language models processes data by stacking multiple layers of multi-head attention machines. Each transformer layer outputs a tensor of the same shape. This invention utilizes these tensors to constrain the training of the model, enabling it to achieve good results.

[0015] During training, this invention uses three types of loss functions. The first type of loss function uses the maximum likelihood loss of the language model, and the calculation process is as follows:

[0016]

[0017] Among them, L MLE For maximum likelihood loss, x = {x1, x2, ..., xn} |x|} represents the model output, p θ This represents a probability distribution. The maximum likelihood function can be implemented using methods such as the negative log-likelihood loss function.

[0018] The second type of loss function uses hierarchical contrastive loss. In the last transformer layer of the language model, the final output is directly used as a batch of comparable samples, comparing each word with all words in the same sentence. Specifically, the similarity between each word representation and the remaining words is calculated, resulting in a similarity matrix. The contrastive loss is calculated using the similarity values ​​in the similarity matrix, given a variable-length sequence x = {x1, x2, ..., x3}. |x| ,}, Comparison loss function L HCL Defined as:

[0019]

[0020] in, x represents i In the hidden layer representation, i and j are the word position indices, and s(,) is the similarity calculation function. Minimizing the loss function is equivalent to maximizing the post-similarity expression, that is, simultaneously maximizing the similarity of positive samples and minimizing the similarity of negative samples. Taking a 12-layer transformer model as an example... This represents the contrastive loss calculated from the 12th layer of the transformer model, compared to L. HCL The calculation process is the same. The contrast loss calculation process is the same across different layers. For ease of description, the contrast loss for layer 11 is... And so on, each of the 12 transformer layers has a corresponding representation.

[0021] Regarding the hierarchical contrast loss, taking a 12-layer transformer model as an example, this invention provides five designs. The first four uniformly select c layers (c = 1, 2, 3, 6) for loss calculation, while the fifth calculates the loss for the middle single layer. In the following text, Let L represent the contrast loss of the i-th layer. HCL (c) represents the contrast loss of a uniform c-layer, such as This indicates the contrast loss when selecting layer 1 (i.e., layer 12). This represents the contrast loss when two layers (i.e., the 12th and 6th layers) are selected uniformly.

[0022] The specific selection of the number of layers and their corresponding formulas are as follows:

[0023] (1) The formula for calculating the hierarchical contrast loss of layer 1 is as follows:

[0024]

[0025] (2) The formula for calculating the hierarchical contrast loss of layer 2 is as follows:

[0026]

[0027] (3) The formula for calculating the hierarchical contrast loss of the 3rd layer is as follows:

[0028]

[0029] (4) The formula for calculating the hierarchical contrast loss of 6 layers is as follows:

[0030]

[0031] (5) The formula for calculating the hierarchical contrast loss of the intermediate layer is as follows:

[0032]

[0033] Where m is the maximum number of layers in the model, γ is the attenuation coefficient, the first four methods can be selected according to the above settings, and the fifth method can be selected as a number between [0,1] with reference to the first four methods.

[0034] At this point, the loss function with only hierarchical contrastive loss added is as follows:

[0035] L ALL =L MLE +L HCL (c)

[0036] The third type of loss function is an extension of the hierarchical contrastive loss method: anchor loss. In the design process, designing the anchor loss function separately would increase computational cost and potentially cause conflicts with the hierarchical contrastive loss. Therefore, this invention designs it as a piecewise function calculation method, requiring only minor vector transformations during code writing. In the last transformer layer of the language model, the final output of the model is directly used as a batch of comparable samples, ensuring that the representations of the same words in the knowledge subgraph are as similar as possible to those in the dialogue text, and as different as possible from the representations of other words. Specifically, the similarity between all output word representations and the remaining words is calculated, resulting in a similarity matrix, similar to the similarity matrix calculation process described earlier. The contrastive loss is calculated using the similarity values ​​in the similarity matrix, given a variable-length sequence x = {x1, x2, ... x3}. |x| ,}, Anchor point loss function L anchor (1) Jointly defined with hierarchical contrast loss:

[0037]

[0038] Where word(i) and word(j) represent the i-th and j-th words themselves, respectively, L anchor (1) indicates the loss calculated on the same layer as the hierarchical contrastive loss. Anchor loss can be used in pairs with all layers of hierarchical contrastive loss. x represents iIn the hidden layer representation, i and j are the word position indices, and s(,) is the similarity calculation function. Minimizing the loss function is equivalent to maximizing the post-equation, that is, simultaneously maximizing the similarity of positive samples and minimizing the similarity of negative samples.

[0039] At this point, the loss function is calculated by simply adding them together, as shown in the following formula:

[0040] L ALL =L MLE +L HCL (c)+L anchor (c)

[0041] Where c is the number of transformer layers with added loss constraints.

[0042] By using a pre-designed loss function and selecting any optimization method to backpropagate gradients to update the model parameters, training can begin.

[0043] The advantages of this invention compared to the prior art are:

[0044] (1) To address the shortcomings of existing methods in terms of accuracy in text word representation and knowledge utilization, this invention designs a hierarchical contrastive loss method using the contrastive learning approach. The method works in two ways: First, imposing constraints on the intermediate layers can limit the model's memory neurons to a certain extent, causing their activation values ​​to become more heterogeneous. This provides space for introducing external knowledge during the inference stage after training, allowing the model to easily handle the retention of internal knowledge and the insertion and use of external knowledge. Second, the contrast in the intermediate layers explicitly classifies knowledge neurons and also compares them at the abstract level of knowledge. This means that the effectiveness of comparing individual words can be extended to comparing abstract knowledge. This can improve the model's ability to represent text words and increase the accuracy of the model in generating dialogues using external knowledge.

[0045] (2) To address the inconsistency between existing methods in knowledge representation and dialogue text representation space, this invention extends the hierarchical contrastive loss method by incorporating anchor point loss. This method integrates the knowledge representation space and text representation space through the constraints of contrastive learning, optimizes the representation of text words, thereby improving the accuracy of the dialogue model in using external knowledge and ultimately enhancing the quality of the dialogue model. Attached Figure Description

[0046] Figure 1 This is a schematic diagram of the overall training architecture of the present invention;

[0047] Figure 2 This is a schematic diagram of the hierarchical comparison method and anchor point loss method of the present invention. Detailed Implementation

[0048] To make the objectives, advantages, and technical solutions of this invention clearer, the following specific measures are provided, in conjunction with the appendix. Figure 1-2 The present invention will be further described in detail below.

[0049] like Figure 1 As shown, the present invention provides a method for training a knowledge-enhanced dialogue system based on hierarchical contrastive learning, comprising the following steps:

[0050] Step one involves data processing during the training and inference of the dialogue system, including dialogue data and knowledge data processing. First, dialogue data and knowledge data are selected. Dialogue data can be commonly used dialogue datasets in dialogue system research, dialogues crawled from social networking sites, or dialogues from personal chat logs. Knowledge data can be of various types, including knowledge bases, knowledge graphs, natural language processing related to the dialogue, and Wikipedia search results. The second step is the processing of dialogue data and knowledge data. The dialogue data processing procedure is as follows:

[0051] The dialogues are typically two-person conversations, presented alternately in the order of the dialogue. During use, all dialogues are treated as continuous text, with each speaker switch serving as a segment to construct the input data. Specifically, a 12-turn dialogue is split into 11 data samples; the first sample uses the second sentence as the label and the preceding dialogue as input; the second sample uses the third sentence as the label and the preceding dialogue as input, and so on. In addition, two special characters, [speaker-o] and [speaker-s], are used to mark the words of different speakers, respectively, hoping that the model can learn the differences in speaker identities and generate responses from the perspectives of different speakers.

[0052] Acquiring knowledge data requires named entity recognition of the dialogue content, extracting entities, retrieving relevant knowledge based on entities, and selecting relevant knowledge according to probability. During knowledge data processing, dialogue-related knowledge is directly concatenated with the dialogue as continuous text to form the input to the language model. Various methods can be used to shorten the input length of the knowledge data. The dialogue history is the historical text of the user's dialogue with the system, and the knowledge subgraph consists of knowledge triples related to entities appearing in the dialogue, provided by the dataset. Both the dialogue history and the knowledge subgraph are transformed into vector form using GPT-2 word embeddings, then directly concatenated and separated by special characters to form the model input data.

[0053] Step two: The language model generates a response based on the input data. This process involves selecting a suitable language model to process the data and choosing a suitable decoding algorithm to generate the response.

[0054] The language model selected is a pre-trained language model based on word units; the effectiveness for letter-level input has not yet been explored. The language model can be a pre-trained language model from the Transformer series, which is well-suited for all models in the GPT series. Users can choose to initialize using the official model parameters or pre-train from scratch, depending on their own computing resources.

[0055] The technology of this invention is applicable to all mainstream decoding algorithms, including search algorithms and sampling algorithms. Using search algorithms yields higher accuracy, while sampling methods provide more diverse responses. Decoding algorithms are primarily used to convert the model's output into natural language responses.

[0056] Step 3: Use hierarchical contrastive learning and its extended backpropagation gradient to update the model parameters. The Transformer series of pre-trained language models processes data by stacking multiple layers of multi-head attention machines. Each transformer layer outputs a tensor of the same shape. This invention utilizes these tensors to constrain the training of the model, enabling it to achieve good results.

[0057] During training, this invention uses three types of loss functions. The first type of loss function uses the maximum likelihood loss of the language model, and the calculation process is as follows:

[0058]

[0059] Among them, L MLE For maximum likelihood loss, x = {x1, x2, ..., xn} |x|} represents the model output, p θ This represents a probability distribution. The maximum likelihood function can be implemented using methods such as the negative log-likelihood loss function.

[0060] The second type of loss function uses hierarchical contrastive loss. In the last transformer layer of the language model, the final output is directly used as a batch of comparable samples, comparing each word with all words in the same sentence. Specifically, the similarity between each word representation and the remaining words is calculated, resulting in a similarity matrix. The contrastive loss is calculated using the similarity values ​​in the similarity matrix, given a variable-length sequence x = {x1, x2, ..., x3}. |k| ,}, Comparison loss function L HCL Defined as:

[0061]

[0062] in, x represents iIn the hidden layer representation, i and j are the word position indices, and s(,) is the similarity calculation function. Minimizing the loss function is equivalent to maximizing the post-equation, that is, simultaneously maximizing the similarity of positive samples and minimizing the similarity of negative samples. For distinction, L... HCL This represents the hierarchical contrastive loss function. This represents the contrast loss calculated at the i-th layer. Calculation and L HCL The calculation process is the same. Taking a 12-layer transformer model as an example, This represents the contrastive loss calculated from layer 12 of the transformer model. The calculation process for the contrastive loss is the same across different layers; for ease of description, the contrastive loss for layer 11 is... And so on, each of the 12 transformer layers has a corresponding representation.

[0063] Regarding the hierarchical contrast loss, taking a 12-layer transformer model as an example, this invention provides five designs. The first four designs uniformly select c layers (c = 1, 2, 3, 6) for loss calculation, while the fifth design calculates the loss for the middle single layer.

[0064] The specific selection of the number of layers and their corresponding formulas are as follows:

[0065] (1) The formula for calculating the hierarchical contrast loss of layer 1 is as follows:

[0066]

[0067] (2) The formula for calculating the hierarchical contrast loss of layer 2 is as follows:

[0068]

[0069] (3) The formula for calculating the hierarchical contrast loss of the 3rd layer is as follows:

[0070]

[0071] (4) The formula for calculating the hierarchical contrast loss of 6 layers is as follows:

[0072]

[0073] (5) The formula for calculating the hierarchical contrast loss of the intermediate layer is as follows:

[0074]

[0075] Where m is the maximum number of layers in the model, γ is the attenuation coefficient, the first four methods can be selected according to the above settings, and the fifth method can be selected as a number between [0,1] with reference to the first four methods.

[0076] At this point, the loss function with only hierarchical contrastive loss added is as follows:

[0077] L ALL =L MLE +L HCL (c)

[0078] The third type of loss function is an extension of hierarchical contrastive loss, namely anchor loss. In the design process, designing the anchor loss function separately would increase computational cost and potentially cause contradictions with hierarchical contrastive loss. Therefore, this invention designs it as a piecewise function calculation method, requiring only minor vector transformations during code writing. In the last transformer layer of the language model, the final output of the model is directly used as a batch of comparable samples, ensuring that the representations of the same words in the knowledge subgraph are as similar as possible to those in the dialogue text, and as different as possible from the representations of other words. Specifically, the similarity between all output word representations and the remaining words is calculated, resulting in a similarity matrix. The contrastive loss is calculated using the similarity values ​​in the similarity matrix, given a variable-length sequence x = {x1, x2, ..., x3}. |x| ,}, Anchor point loss function L anchor (1) Jointly defined with hierarchical contrast loss:

[0079]

[0080] Where word(i) and word(j) represent the i-th and j-th words themselves, respectively, L anchor (1) indicates the loss calculated on the same layer as the hierarchical contrastive loss. Anchor loss can be used in pairs with all layers of hierarchical contrastive loss. x represents i In the hidden layer representation, i and j are the word position indices, and s(,) is the similarity calculation function. Minimizing the loss function is equivalent to maximizing the post-equation, that is, simultaneously maximizing the similarity of positive samples and minimizing the similarity of negative samples.

[0081] At this point, the loss function is calculated by simply adding them together, as shown in the following formula:

[0082] L ALL =L MLE +L HCL (c)+L anchor (c)

[0083] Where c represents the number of layers to which loss constraints are added to the transformer layer.

[0084] By using a pre-designed loss function and selecting any optimization method to backpropagate gradients to update the model parameters, training can begin.

[0085] Taking the GPT-2 model as an example, a specific implementation of the present invention is as follows:

[0086] Step 1: Dialogue and Knowledge Data Processing. A 12-round dialogue is divided into 11 data samples. The first sample uses the second sentence as the label and the preceding dialogue as input; the second sample uses the third sentence as the label and the preceding dialogue as input, and so on. Additionally, different speakers' utterances are marked with two special characters, [speaker-o] and [speaker-s], respectively. Knowledge data uses knowledge graph triples, directly concatenating the triples <entity, relation, entity> in sequence. Finally, the dialogue data and knowledge data are concatenated, with the knowledge data first. Text data is appended to the beginning of sentences. <bos>Special characters, add at the end <end>Special characters. The text data is used to obtain the model input tensor through word embeddings in the input embedding layer of the GPT-2 model.

[0087] Step 2: The language model generates a response based on the input data received from the input embedding layer, updates the local model parameters using the parameters of the official GPT-2 base version, inputs the input tensor into the model for computation, and retains the output tensor of each of the 12 transformer layers.

[0088] Step 3: Use hierarchical contrastive learning and its extended backpropagation gradients to update the model parameters.

[0089] (1) Using the output tensor of the 12th transformer layer, the loss value is calculated using the negative log-likelihood loss (NLL) function. The negative log-likelihood loss is directly calculated using the torch.nn.NLLLoss function under the pytorch framework.

[0090] (2) The hierarchical contrast loss value is calculated using a two-level contrast loss formula as follows:

[0091]

[0092] (3) Calculate the anchor point loss value using one layer of anchor point loss, such as Figure 2 As shown, the joint calculation formula for the layer 12 contrast loss is as follows:

[0093]

[0094] (4) Calculate the total loss value using the following formula:

[0095]

[0096] (5) Update the model parameters using the Adam optimization algorithm.

[0097] (6) Training stops when the negative log-likelihood loss reaches its minimum value.< / end> < / bos>

Claims

1. A method for training a knowledge-enhanced dialogue system based on hierarchical contrastive learning, characterized in that, The method specifically includes the following steps: Step 1: Select dialogue data and knowledge data, and process the dialogue data and knowledge data to obtain the input data for the language model; Step two: The language model generates a response based on the input data. The process of generating a response includes selecting a suitable language model to process the data and selecting a suitable decoding algorithm to generate the response. Step 3: Use hierarchical contrastive learning and its extended backpropagation gradients to update the model parameters; Choose a pre-trained language model from the transformer family as the language model; select either a search algorithm or a sampling algorithm for the decoding algorithm; The Transformer series of pre-trained language models processes data by stacking multiple layers of multi-head attention machine computation. Each transformer layer outputs a tensor of the same shape, and the model is trained using the tensor constraints. During training, three types of loss functions are used. The first type of loss function uses the maximum likelihood loss of the language model, and the calculation process is as follows: in, For maximum likelihood loss, For model output, For probability distributions, the maximum likelihood function is implemented using the negative log-likelihood loss function; The second type of loss function uses hierarchical contrastive loss. In the last transformer layer of the language model, the final output of the language model is directly used as a batch of comparable samples. Each word is compared with all words in the same sentence, and the similarity between the output word representation and the remaining words is calculated, resulting in a similarity matrix. The contrastive loss is then calculated using the similarity values ​​in the similarity matrix. Defined as: in, express In the hidden layer representation, and It is the position number of the word. The process of minimizing the loss function, which is the similarity calculation function, is to maximize the similarity of positive samples and minimize the similarity of negative samples at the same time. The third type of loss function is the loss obtained by extending the hierarchical contrastive loss method, namely the anchor loss; it calculates the similarity between all the output word representations and the remaining words, resulting in a similarity matrix; and uses the similarity values ​​in the similarity matrix to calculate the contrastive loss, the anchor loss function. The joint definition of the loss with the hierarchical contrast loss is: in, and They represent the first and The word itself, This indicates that the anchor loss is calculated at the same layer as the hierarchical contrastive loss. All layers are used in pairs with the hierarchical contrastive loss. express In the hidden layer representation, and It is the position number of the word. The process of minimizing the loss function, which is the similarity calculation function, is to maximize the similarity of positive samples and minimize the similarity of negative samples at the same time. At this point, the loss function is calculated by simply adding them together, as shown in the following formula: in, The number of layers to add loss constraints to the transformer layers.

2. The method according to claim 1, characterized in that, The dialogue data is selected from dialogue datasets, dialogues crawled from social networking sites, and dialogues from personal chat logs; the knowledge data includes knowledge bases, knowledge graphs, natural language statements related to the dialogues, and Wikipedia search content.

3. The method according to claim 1, characterized in that, The dialogue data and knowledge data are processed. The dialogue data processing procedure is as follows: The dialogue is in the form of a two-person conversation, which will be presented alternately according to the order of the conversation. All the conversations between the two people are treated as continuous text, and the input data is constructed by switching speakers each time. The processing of knowledge data involves named entity recognition of the dialogue content, extracting entities, retrieving based on entities, and selecting relevant knowledge according to probability. Finally, the relevant knowledge is concatenated with the dialogue as continuous text to form the input data for the language model.

Citation Information

Patent Citations

  • Knowledge enhanced content generation system, data generation method, device and medium

    CN116541536A