A multi-turn dialogue model training method and device, and related equipment

CN120687567BActive Publication Date: 2026-10-27CHINA MOBILE INFORMATION TECHNOLOGY CO LTD +1
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202510777393.5
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-06-11
Publication Date
2026-10-27
Estimated Expiration
2045-06-11

AI Technical Summary

Technical Problem

[0003]本申请实施例提供了一种多轮对话模型训练方法、装置及相关设备,以解决现有技术中对话模型输出结果准确性较差

Benefits of technology

[0041]本申请实施例中,首先获取连续的多轮对话文本以及其中第一文本对应的第一分词序列,并且在第一分词序列中通过掩码标记和分类标记的设计,为预设模型提供了融合词元、意图和序列信息的输入表示,在训练过程中通过多轮对话文本的输入,以建立上下文依赖关系;然后利用实体、掩码、意图和对话序列四类损失函数,驱动预设模型同时学习局部语义、意图分类和跨轮依赖关系,增强对复杂对话结构的预测能力;最后通过第一损失值判断预设模型训练完成,以获得多轮对话模型,确保多轮对话模型在多任务上的泛化性能。有效解决了多轮对话中上下文管理的难题,使多轮对话模型在处理复杂对话时可以准确捕捉关键信息,提升了多轮对话模型输出结果的准确性。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120687567B_ABST
    Figure CN120687567B_ABST
Patent Text Reader

Abstract

The application provides a multi-round dialogue model training method and device and related equipment, and relates to the technical field of artificial intelligence. The method comprises the following steps: obtaining a first token sequence corresponding to a first text and a plurality of continuous second texts, the first token sequence comprising N-1 word pieces, a mask mark and a classification mark, the first token sequence being obtained by preprocessing a second token sequence corresponding to the first text, and the second token sequence comprising N word pieces; calculating an entity loss determined by a preset model based on the N-1 word pieces, a mask loss determined based on the mask mark, an intention loss determined based on the classification mark, and a dialogue sequence loss determined based on the first text and the second text to obtain a first loss value; and iteratively training the preset model based on the first loss value to obtain a multi-round dialogue model. The multi-round dialogue model can accurately capture key information when processing complex dialogues, thereby improving the accuracy of the output results of the multi-round dialogue model.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of artificial intelligence technology, and in particular to a method, apparatus and related equipment for training a multi-turn dialogue model. Background Technology

[0002] With the rapid development of artificial intelligence and natural language processing technologies, numerous dialogue models have emerged. Dialogue models enable knowledge-based question answering, simulating human customer service in handling user inquiries and problem-solving. When dealing with complex dialogue flows, it is necessary to accurately understand and maintain the contextual information of the dialogue to provide coherent and accurate responses. However, in multi-turn dialogues, the key information in each turn may differ, and existing dialogue models struggle to accurately capture this key information when handling complex dialogues, resulting in poor accuracy in their output. Summary of the Invention

[0003] This application provides a method, apparatus, and related equipment for training a multi-turn dialogue model, in order to solve the problem of poor accuracy of dialogue model output results in the prior art.

[0004] To solve the above-mentioned technical problems, this application is implemented as follows:

[0005] In a first aspect, embodiments of this application provide a method for training a multi-turn dialogue model, the method comprising:

[0006] Obtain continuous multi-turn dialogue text and a first word segmentation sequence corresponding to the first text. The first text is the last round of dialogue text in the multi-turn dialogue text. The first word segmentation sequence includes N-1 words, a mask marker, and a classification marker. The first word segmentation sequence is obtained by preprocessing the second word segmentation sequence corresponding to the first text. The second word segmentation sequence includes N words. The mask marker is the first marker corresponding to any target word among the N words. The N-1 words are words other than the target word among the N words. The classification marker is the second marker corresponding to the preset intent of the first text. N is an integer greater than 1.

[0007] The first loss value is obtained by calculating the entity loss determined by the N-1 lexical units, the mask loss determined by the mask label, the intent loss determined by the classification label, and the dialogue sequence loss determined by the first text and the second text, where the second text is the dialogue text other than the first text in the multi-turn dialogue text.

[0008] The preset model is iteratively trained based on the first loss value until the first loss value is less than a preset threshold, and the preset model after iterative training is determined as a multi-turn dialogue model.

[0009] Optionally, the preset model includes an encoder, a decoder, and a feedforward neural network layer. The encoder includes a dot product attention layer and an additive attention layer. The dot product attention layer is used to determine the attention weight of the value vector by calculating the dot product between the query vector and the key vector. The additive attention layer is used to learn the nonlinear relationship between the query vector and the key vector through the feedforward neural network layer.

[0010] The step of iteratively training the preset model based on the first loss value until the first loss value is less than a preset threshold, and then determining the iteratively trained preset model as a multi-turn dialogue model, includes:

[0011] If the first loss value is less than a preset threshold, the first parameter corresponding to the encoder after iterative training is obtained. The first parameter includes encoder parameters, decoder parameters and feedforward neural network layer parameters. The encoder parameters include the weights of the dot product attention layer and the weights of the additive attention layer.

[0012] The preset model with the first parameter is determined as the multi-turn dialogue model.

[0013] Optionally, before obtaining the continuous multi-turn dialogue text and the first word segmentation sequence corresponding to the first text, the method further includes:

[0014] The first text is segmented to obtain the N word elements;

[0015] Masking is performed on any one of the N lexical units to obtain a masked marker for the target lexical unit, wherein the target lexical unit is the lexical unit that has been masked among the N lexical units;

[0016] Obtain the category tag corresponding to the preset intent of the first text.

[0017] Optionally, the calculation preset model obtains a first loss value based on the entity loss determined by the N-1 lexical units, the mask loss determined by the mask marker, the intent loss determined by the classification marker, and the dialogue sequence loss determined by the first and second texts, including:

[0018] The entity loss is calculated based on the lexical representation vectors of the N-1 lexical units and the entity label vectors corresponding to the N-1 lexical units. The lexical representation vectors are vectors determined by the preset model based on the N-1 lexical units, and the entity label vectors are preset vectors of the entities corresponding to the N-1 lexical units respectively.

[0019] The masking loss is calculated based on the first masking representation vector of the masking mark and the second masking representation vector of the target word. The first masking representation vector is a vector determined by the preset model based on the masking mark, and the second masking representation vector is the vector corresponding to the target word.

[0020] The intent loss is calculated based on the first intent representation vector of the classification label and the second intent representation vector of the preset intent. The first intent representation vector is a vector determined by the preset model based on the classification label, and the second intent representation vector is a vector corresponding to the preset intent.

[0021] The dialogue sequence loss is calculated based on the first sequence representation vector and the second sequence representation vector of the first text, wherein the second sequence representation vector is a vector determined by the preset model based on the second text to represent the first text, and the first sequence representation vector is a preset vector of the first text.

[0022] The first loss value is determined based on the entity loss, the mask loss, the intent loss, and the dialogue sequence loss.

[0023] Optionally, calculating the entity loss based on the lexical representation vectors of the N-1 lexical units and the entity label vectors corresponding to the N-1 lexical units includes:

[0024] Each of the N-1 lexical units is individually encoded using a one-hot encoding method and passed through a fully connected layer. An embedding vector is then set for each lexical unit and input into the preset model to obtain the lexical representation vectors corresponding to the N-1 lexical units. The embedding vectors are used to represent the positional order of the lexical units in the first text. The fully connected layer is used to unify the dimensions of the N-1 lexical units after the one-hot encoding.

[0025] Obtain the entity label vector corresponding to each of the N-1 lexical units;

[0026] The entity loss is obtained in the Conditional Random Field (CRF) layer based on the lexical representation vector and the entity label vector.

[0027] Optionally, calculating the masking loss based on the first masking representation vector of the masking tag and the second masking representation vector of the target word includes:

[0028] The mask marker is input into the preset model and passed through the embedding layer to obtain the first mask representation vector;

[0029] The target word is one-hot encoded and passed through a fully connected layer and an embedding layer to obtain the second mask representation vector. Both the fully connected layer and the embedding layer are used for dimensional unification.

[0030] The mask loss is obtained by calculating the similarity between the first mask representation vector and the second mask representation vector using the cosine angle.

[0031] Optionally, calculating the intent loss based on the first intent representation vector of the classification label and the second intent representation vector of the preset intent includes:

[0032] The classification label is one-hot encoded and passed through a fully connected layer before being input into the preset model to obtain the first intent representation vector.

[0033] The preset intent is input into the embedding layer to obtain the second intent representation vector. Both the fully connected layer and the embedding layer are used for dimension unification.

[0034] The intention loss is obtained by calculating the similarity between the first intention representation vector and the second intention representation vector using the cosine angle.

[0035] Secondly, embodiments of this application provide a multi-turn dialogue model training apparatus, the apparatus comprising:

[0036] The first acquisition module is used to acquire continuous multi-turn dialogue text and a first word segmentation sequence corresponding to the first text. The first text is the last round dialogue text in the multi-turn dialogue text. The first word segmentation sequence includes N-1 word elements, a mask marker, and a classification marker. The first word segmentation sequence is obtained by preprocessing the second word segmentation sequence corresponding to the first text. The second word segmentation sequence includes N word elements. The mask marker is a first marker corresponding to any target word element among the N word elements. The N-1 word elements are word elements other than the target word element among the N word elements. The classification marker is a second marker corresponding to the preset intent of the first text. N is an integer greater than 1.

[0037] The calculation module is used to calculate the entity loss determined by the preset model based on the N-1 lexical units, the mask loss determined based on the mask label, the intent loss determined based on the classification label, and the dialogue sequence loss determined based on the first text and the second text, to obtain a first loss value. The second text is the dialogue text other than the first text in the multi-turn dialogue text.

[0038] The training module is used to iteratively train the preset model based on the first loss value until the first loss value is less than a preset threshold, and then determine the preset model after iterative training as a multi-turn dialogue model.

[0039] Thirdly, embodiments of this application provide an electronic device, including: a processor, a memory, and a program stored in the memory and executable on the processor, wherein when the program is executed by the processor, it implements the steps of the multi-turn dialogue model training method as described in the first aspect.

[0040] Fourthly, embodiments of this application provide a computer-readable storage medium storing a computer program, which, when executed by a processor, implements the steps of the multi-turn dialogue model training method as described in the first aspect.

[0041] In this embodiment, firstly, continuous multi-turn dialogue text and the first word segmentation sequence corresponding to the first text are obtained. Within the first word segmentation sequence, masking and classification tags are used to provide an input representation that integrates lexical, intent, and sequence information for the pre-defined model. During training, contextual dependencies are established through the input of multi-turn dialogue text. Then, four types of loss functions—entity, mask, intent, and dialogue sequence—are used to drive the pre-defined model to simultaneously learn local semantics, intent classification, and cross-turn dependencies, enhancing its predictive ability for complex dialogue structures. Finally, the first loss value is used to determine the completion of the pre-defined model training, thus obtaining a multi-turn dialogue model and ensuring its generalization performance across multiple tasks. This effectively solves the problem of context management in multi-turn dialogue, enabling the multi-turn dialogue model to accurately capture key information when handling complex dialogues, thereby improving the accuracy of the multi-turn dialogue model's output. Attached Figure Description

[0042] To more clearly illustrate the technical solutions of the embodiments of this application, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0043] Figure 1 This is one of the flowcharts of a multi-turn dialogue model training method provided in the embodiments of this application;

[0044] Figure 2 This is the second flowchart of a multi-turn dialogue model training method provided in the embodiments of this application;

[0045] Figure 3 This is a schematic diagram of a multi-turn dialogue model training device provided in an embodiment of this application. Detailed Implementation

[0046] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.

[0047] See Figure 1 , Figure 1 This is one of the flowcharts of a multi-turn dialogue model training method provided in the embodiments of this application, such as... Figure 1 As shown, the method includes the following steps:

[0048] Step 101: Obtain continuous multi-turn dialogue text and the first word segmentation sequence corresponding to the first text. The first text is the last round dialogue text in the multi-turn dialogue text. The first word segmentation sequence includes N-1 words, a mask marker, and a classification marker. The first word segmentation sequence is obtained by preprocessing the second word segmentation sequence corresponding to the first text. The second word segmentation sequence includes N words. The mask marker is the first marker corresponding to any target word among the N words. The N-1 words are words other than the target word among the N words. The classification marker is the second marker corresponding to the preset intent of the first text. N is an integer greater than 1.

[0049] In this step, the multi-turn dialogue text can include the first text and the multi-turn dialogue text preceding the first text, which is denoted as the second text. Obtaining continuous multi-turn dialogue text facilitates the subsequent establishment of contextual dependencies by the pre-defined model, enabling the model to learn the state transition rules of multi-turn dialogues and enhance its understanding of complex dialogue contexts. Furthermore, the second word segmentation sequence corresponding to the first text can include multiple tokens; the mask token can be a token obtained by masking any one of the multiple tokens, denoted as "_mask_"; the classification token can be a token determined based on the pre-defined intent corresponding to the first text, denoted as "_CLS_". After masking any one of the N tokens in the second word segmentation sequence to obtain the mask token corresponding to the target token, a classification token is added to the second word segmentation sequence as the pre-defined intent corresponding to the first text. Thus, based on the mask token and classification token in the second word segmentation sequence, and the remaining N-1 tokens, the first word segmentation sequence corresponding to the first text is obtained. This provides a structured input for subsequent multi-task learning. Among them, the mask label is used to trigger the model to predict and learn specific lexical units (such as entity or semantic completion), while the classification label clearly points to the intent category of the text. At the same time, the retained lexical and positional information provides a basis for entity extraction and contextual modeling, ensuring that the model can learn semantic information at the lexical, intent, and sequence levels simultaneously.

[0050] Step 102: Calculate the entity loss determined by the preset model based on the N-1 lexical units, the mask loss determined based on the mask label, the intent loss determined based on the classification label, and the dialogue sequence loss determined based on the first text and the second text to obtain a first loss value. The second text is the dialogue text other than the first text in the multi-turn dialogue text.

[0051] In this step, firstly, the pre-defined model determines entity loss based on N-1 lexical units, mask loss based on masking labels, intent loss based on classification labels, and dialogue sequence loss based on the first and second texts, respectively. Then, based on entity loss, masking loss, intent loss, and dialogue sequence loss, the first loss value (i.e., the total loss) is calculated. Specifically, calculating entity loss constrains the model to accurately extract entity labels such as time and location; calculating masking loss forces the model to reconstruct masked lexical units based on context; calculating intent loss ensures that classification labels correspond to the correct text intent; and calculating dialogue sequence loss utilizes continuous multi-turn dialogue text to establish contextual dependencies. By integrating these four types of losses through backpropagation, the model can simultaneously learn lexical-level details, intent semantics, and state transition patterns in multi-turn dialogues, gradually adjusting parameters to enhance its understanding of complex dialogue contexts, such as capturing cross-turn entity associations or intent evolution. This improves the accuracy of the model's output after training.

[0052] Step 103: Iteratively train the preset model based on the first loss value until the first loss value is less than a preset threshold, and determine the preset model after iterative training as a multi-turn dialogue model.

[0053] In this step, the preset model is iteratively trained based on the first loss value to jointly optimize the multi-task loss. A training termination condition is set: when the first loss value calculated during iteration (i.e., the overall objective function integrating multi-task losses) is less than a preset threshold, the preset model is considered to have converged, training stops, and the final multi-turn dialogue model is output. This process ensures that the preset model achieves the expected accuracy in tasks such as entity extraction, intent recognition, mask prediction, and dialogue state sequence prediction, avoiding overfitting or underfitting. The final multi-turn dialogue model can accurately predict the context state of the current turn based on historical dialogue states, achieving cross-turn integration of intent and entity information in multi-turn dialogues. It can accurately capture key information when handling complex and long dialogues, improving the accuracy of the multi-turn dialogue model's output.

[0054] In this embodiment, firstly, continuous multi-turn dialogue text and the first word segmentation sequence corresponding to the first text are obtained. Within the first word segmentation sequence, masking and classification tags are used to provide an input representation that integrates lexical, intent, and sequence information for the pre-defined model. During training, contextual dependencies are established through the input of multi-turn dialogue text. Then, four types of loss functions—entity, mask, intent, and dialogue sequence—are used to drive the pre-defined model to simultaneously learn local semantics, intent classification, and cross-turn dependencies, enhancing its predictive ability for complex dialogue structures. Finally, the first loss value is used to determine the completion of the pre-defined model training, thus obtaining a multi-turn dialogue model and ensuring its generalization performance across multiple tasks. This effectively solves the problem of context management in multi-turn dialogue, enabling the multi-turn dialogue model to accurately capture key information when handling complex dialogues, thereby improving the accuracy of the multi-turn dialogue model's output.

[0055] Optionally, before obtaining the continuous multi-turn dialogue text and the first word segmentation sequence corresponding to the first text, the method further includes:

[0056] The first text is segmented to obtain the N word elements;

[0057] Masking is performed on any one of the N lexical units to obtain a masked marker for the target lexical unit, wherein the target lexical unit is the lexical unit that has been masked among the N lexical units;

[0058] Obtain the category tag corresponding to the preset intent of the first text.

[0059] In this embodiment, the first text can be "How many people lived in Beijing last week?" Word segmentation of the first text yields four lexical units: "last week", "Beijing", "number of residents", and "how many". These four lexical units and their corresponding positional information provide a foundation for entity extraction and contextual modeling. Masking is applied to any one of these four lexical units. For example, masking "how many" replaces the target lexical unit (i.e., "how many") with a mask marker, which can be represented by "_mask_". The mask marker can be used to trigger the model's prediction learning of specific lexical units (such as entity or semantic completion). After masking, a sequence containing the mask marker is obtained: ["last week", "Beijing", "number of residents", and "_mask_"]. Furthermore, given that the preset intent of the first text is "data query", a specific classification marker can be defined for this intent, for example, represented by "_CLS_". The classification marker explicitly points to the intent category of the text. The first segmented sequence, including N-1 lexical units, the mask marker, and the classification marker, provides structured input for subsequent multi-task learning.

[0060] Optionally, the preset model includes an encoder, a decoder, and a feedforward neural network layer. The encoder includes a dot product attention layer and an additive attention layer. The dot product attention layer is used to determine the attention weight of the value vector by calculating the dot product between the query vector and the key vector. The additive attention layer is used to learn the nonlinear relationship between the query vector and the key vector through the feedforward neural network layer.

[0061] The step of iteratively training the preset model based on the first loss value until the first loss value is less than a preset threshold, and then determining the iteratively trained preset model as a multi-turn dialogue model, includes:

[0062] If the first loss value is less than a preset threshold, the first parameter corresponding to the encoder after iterative training is obtained. The first parameter includes encoder parameters, decoder parameters and feedforward neural network layer parameters. The encoder parameters include the weights of the dot product attention layer and the weights of the additive attention layer.

[0063] The preset model with the first parameter is determined as the multi-turn dialogue model.

[0064] In this embodiment, the dot product attention layer determines the similarity between the query vector Q and the key vector K by calculating their dot product, and then assigns attention weights to the value vector V. In sequence modeling of natural language processing, dot product attention can capture long-distance dependencies between different elements in a sequence. For example, in processing multi-turn dialogues, it can help the model understand the associations of relevant information in different turns. Its calculation method can be QK. T After scaling and normalization, attention weights are obtained, which are then used to weight and sum the value vector V to obtain the output. The additive attention layer uses a feedforward neural network layer to learn the non-linear relationship between Q and K. Additive attention can be effective when the patterns in the data are complex and simple dot product operations cannot capture the information well. By using a feedforward neural network to non-linearly transform Q and K, and then calculating the attention score, it can better handle different types of inputs and enhance the model's ability to model complex patterns. The feedforward neural network layer can include multiple fully connected layers and multiple embedding layers. It can further transform and extract features from the attention layer output, thereby learning higher-level feature representations, integrating and transforming the information captured by the attention layer, and providing more effective features for subsequent tasks.

[0065] Specifically, the encoder can consist of three layers, each containing multi-head self-attention and a corresponding feedforward neural network layer. For the l-th layer (l ranges from 1 to 3), the calculation process is as follows:

[0066] Attention Q, K, V calculations can be expressed as:

[0067] Where Q represents the query vector, K represents the key vector, and V represents the value vector. In the self-attention mechanism, Q, K, and V are all generated from the same input sequence through different linear transformations. l K l With V l Let Q, K, and V represent the Q, K, and V vectors of the encoder's l-th layer.

[0068] The raw output of self-attention can be represented as:

[0069] In the original self-attention mechanism, positional information is typically added to the input sequence via positional encoding. Based on this, this embodiment considers both dot-product attention and additive attention. Dot-product attention measures the similarity between Q and K by calculating the dot product, making it suitable for capturing long-distance dependencies and a key component of the Transformer model. Additive attention learns the non-linear relationship between Q and K through a feedforward neural network, better handling complex patterns and relationships, especially when dealing with different types of inputs.

[0070] Furthermore, the first parameter includes encoder parameters, decoder parameters, and feedforward neural network layer parameters. The encoder parameters include the weights of the dot-product attention layer and the additive attention layer. The decoder corresponds to the encoder, and the encoder and decoder work together to calculate the dialogue sequence loss. The concept of dynamic weights is introduced, using learned weights (i.e., the first parameter) to adjust the importance of dot-product attention and additive attention, allowing the pre-defined model to dynamically adjust the attention mechanism based on different inputs. By fusing the results of dot-product attention and additive attention, the advantages of both can be utilized simultaneously, improving the model's ability to capture information. By dynamically adjusting the first parameter, the model can more accurately capture key information, thereby improving the accuracy of intent recognition and entity extraction. Moreover, fusing the two attention mechanisms makes the model more flexible in handling different types of inputs, enhancing its generalization ability. Finally, the introduction of dynamic weights makes the model more efficient in processing information, reducing unnecessary computation and improving the model's operating efficiency.

[0071] For example, the modified self-attention formula can be expressed as:

[0072]

[0073] Where, d k It is the dimension of Q, K, V. These are learnable weights, λ lThese are learnable dynamic weights. T represents the matrix transpose. The first parameter includes the learnable weights and the learnable dynamic weights.

[0074] The output of self-attention is represented by residual connections and layer normalization as follows:

[0075]

[0076] Among them, H l-1 It is the hidden state of the encoder's (l-1)th layer output. It is the hidden state obtained after the l-th layer of the encoder is processed by the self-attention mechanism and after adding residual connections and layer normalization operations.

[0077] A feedforward neural network can be represented as:

[0078]

[0079] in The weights of the two feedforward layers in the l-th layer are... and This is the bias vector.

[0080] The final hidden state is:

[0081] Thus, when the first loss value is less than the preset threshold, it means that the current preset model has reached a certain performance requirement during training, and the model parameters can be considered to have converged to a good state. During iterative training, when the first loss value is less than the preset threshold, the first parameters corresponding to the encoder are obtained. These parameters include the weights of the dot product attention layer, the weights of the additive attention layer, the decoder parameters, and the weights of the feedforward neural network layer. These weight parameters determine the calculation method and feature extraction capability of each layer. The preset model with the encoder parameters set to the obtained first parameters is determined as the multi-turn dialogue model. During training, by minimizing the first loss value (which integrates entity loss, masking loss, intent loss, and dialogue sequence loss), the model has learned how to extract useful information from the input dialogue data, including entity information, intent information, and contextual information. Therefore, the model using these trained parameters can accurately understand the user's intent, identify entities, and respond appropriately based on historical dialogue information in multi-turn dialogue scenarios. This fully utilizes the knowledge learned by the model during training, improving the performance of multi-turn dialogue processing.

[0082] Optionally, the calculation preset model obtains a first loss value based on the entity loss determined by the N-1 lexical units, the mask loss determined by the mask marker, the intent loss determined by the classification marker, and the dialogue sequence loss determined by the first and second texts, including:

[0083] The entity loss is calculated based on the lexical representation vectors of the N-1 lexical units and the entity label vectors corresponding to the N-1 lexical units. The lexical representation vectors are vectors determined by the preset model based on the N-1 lexical units, and the entity label vectors are preset vectors of the entities corresponding to the N-1 lexical units respectively.

[0084] The masking loss is calculated based on the first masking representation vector of the masking mark and the second masking representation vector of the target word. The first masking representation vector is a vector determined by the preset model based on the masking mark, and the second masking representation vector is the vector corresponding to the target word.

[0085] The intent loss is calculated based on the first intent representation vector of the classification label and the second intent representation vector of the preset intent. The first intent representation vector is a vector determined by the preset model based on the classification label, and the second intent representation vector is a vector corresponding to the preset intent.

[0086] The dialogue sequence loss is calculated based on the first sequence representation vector and the second sequence representation vector of the first text, wherein the second sequence representation vector is a vector determined by the preset model based on the second text to represent the first text, and the first sequence representation vector is a preset vector of the first text.

[0087] The first loss value is determined based on the entity loss, the mask loss, the intent loss, and the dialogue sequence loss.

[0088] In this embodiment, as Figure 2As shown, joint optimization of the preset model is achieved by designing a multi-dimensional loss function in the preset model. Specifically, the first text can be "How many people lived in Beijing last week?". Word segmentation of the first text yields four lexical units: "last week", "Beijing", "number of residents", and "how many". Masking is applied to any one of these four lexical units; for example, masking "how many" replaces the target lexical unit (i.e., "how many") with a mask marker, which can be represented by "_mask_". The mask marker can be used to trigger the model's prediction learning of specific lexical units (such as entity or semantic completion). After masking, a sequence containing the mask marker is obtained: ["last week", "Beijing", "number of residents", and "_mask_"]. Furthermore, given that the preset intent of the first text is "data query", a specific classification marker can be defined for this intent, for example, represented by "_CLS_". The classification marker explicitly points to the intent category of the text. The first segmented sequence input to the pre-defined model includes N-1 words, mask tags, and classification tags, providing structured input for subsequent multi-task learning. Simultaneously, continuous multi-turn dialogue text is input into the pre-defined model to drive it to learn the contextual dependencies within the multi-turn dialogue. Thus, calculating entity loss ensures accurate semantic recognition at the word level; calculating mask loss enhances local semantic understanding and reasoning capabilities; calculating intent loss ensures the model correctly captures the overall intent of the text; and calculating dialogue sequence loss drives the model to learn the contextual dependencies within the multi-turn dialogue. Based on the determined first loss value, the pre-defined model is iterated, ultimately forming a multi-turn dialogue model capable of comprehensively handling entity extraction, intent recognition, semantic completion, and multi-turn dialogue state transitions, effectively improving the accuracy of the multi-turn dialogue model's output. The calculation process for entity loss, mask loss, intent loss, and dialogue sequence loss can be described as follows:

[0089] In one embodiment, calculating the entity loss based on the lexical representation vectors of the N-1 lexical units and the entity label vectors corresponding to the N-1 lexical units includes:

[0090] Each of the N-1 lexical units is individually encoded using a one-hot encoding method and passed through a fully connected layer. An embedding vector is then set for each lexical unit and input into the preset model to obtain the lexical representation vectors corresponding to the N-1 lexical units. The embedding vectors are used to represent the positional order of the lexical units in the first text. The fully connected layer is used to unify the dimensions of the N-1 lexical units after the one-hot encoding.

[0091] Obtain the entity label vector corresponding to each of the N-1 lexical units;

[0092] The entity loss is obtained in the Conditional Random Field (CRF) layer based on the lexical representation vector and the entity label vector.

[0093] In this embodiment, each of the N-1 lexical units is one-hot encoded and then input into a fully connected layer. A vector is embedded at the sum of each lexical unit's position, and this vector is then input into another fully connected layer. Finally, the vector is fed into the encoder of a predefined model. The encoder outputs the lexical representation vectors corresponding to the N-1 lexical units. These lexical representation vectors contain both semantic and positional information of the lexical units and represent an abstract representation of the lexical units by the model. One-hot encoding is a method for converting discrete features into vector representations, where each lexical unit is represented as a vector with only one 1 element and all other elements being 0. One-hot encoding converts textual information into a numerical form that a computer can process. The embedded vectors represent the positional order of the lexical units in the first text. By incorporating positional information into the lexical representation through embedded vectors, the model can better understand the semantics and structure of the text.

[0094] Obtain the entity label vector corresponding to each of the N-1 lexical units. The entity label vectors are predefined and represent the entity type corresponding to each lexical unit, such as time, location, or metric. These entity label vectors are the target of the training model; the model needs to learn how to accurately predict these entity labels from the lexical representation vectors.

[0095] The word representation vector and entity label vector are input into a Conditional Random Field (CRF) layer. CRF is a probabilistic graphical model commonly used in sequence labeling tasks, which takes into account the contextual relationships between elements in a sequence. The CRF layer calculates the entity loss, denoted as L, based on the input word representation vector and the target entity label vector. entity Entity loss reflects the difference between the entity labels predicted by the model and the actual entity labels. By minimizing entity loss, the model can continuously adjust its parameters and improve the accuracy of entity label prediction.

[0096] In one embodiment, calculating the masking loss based on the first masking representation vector of the masking tag and the second masking representation vector of the target word includes:

[0097] The mask marker is input into the preset model and passed through the embedding layer to obtain the first mask representation vector;

[0098] The target word is one-hot encoded and passed through a fully connected layer and an embedding layer to obtain the second mask representation vector. Both the fully connected layer and the embedding layer are used for dimensional unification.

[0099] The mask loss is obtained by calculating the similarity between the first mask representation vector and the second mask representation vector using the cosine angle.

[0100] In this embodiment, a mask marker (i.e., "_mask_") is input into the encoder of a preset model to obtain a first mask representation vector. In natural language processing tasks, "_mask_" is typically used to mask certain words in text, allowing the model to predict the masked content based on contextual information. The preset model processes the mask marker, combining it with the contextual information of the input text to generate a vector representing this mask marker, i.e., the first mask representation vector. The first mask representation vector contains the model's semantic understanding and prediction information about the masked position based on the context.

[0101] Simultaneously, the target word to be masked (such as "how many") is one-hot encoded and transformed into a high-dimensional sparse vector where only the corresponding word index position is 1 and the rest are 0. Then, through the linear transformation of the fully connected layer, it is projected into a low-dimensional space to obtain a dense vector. Then, the semantic representation of the word is extracted from the pre-trained or learnable embedding matrix using the embedding layer to form a vector containing its true semantic information. The final vector is the second mask representation vector used to calculate the mask loss, and the second mask representation vector represents the true semantic information of the target word.

[0102] Then, the similarity between the first mask representation vector and the second mask representation vector is calculated using the cosine angle, resulting in the mask loss, denoted as L. mask The similarity between two vectors is represented by the cosine of the angle between them, with a value ranging from -1 to 1. A value closer to 1 indicates greater similarity. When calculating the masking loss, the cosine similarity is typically subtracted from 1. A smaller loss value indicates a greater similarity between the model's predicted first masking representation vector and the true second masking representation vector, meaning a more accurate prediction of the masked term. Thus, the masking loss L is calculated... mask The model learns semantic information and contextual relationships within the text. By continuously minimizing the masking loss, the model can gradually improve its ability to predict masked words, thereby better understanding the overall semantics of the text.

[0103] In one embodiment, calculating the intent loss based on the first intent representation vector of the classification label and the second intent representation vector of the preset intent includes:

[0104] The classification label is one-hot encoded and passed through a fully connected layer before being input into the preset model to obtain the first intent representation vector.

[0105] The preset intent is input into the embedding layer to obtain the second intent representation vector. Both the fully connected layer and the embedding layer are used for dimension unification.

[0106] The intention loss is obtained by calculating the similarity between the first intention representation vector and the second intention representation vector using the cosine angle.

[0107] In this embodiment, the classification label (i.e., "_CLS_") is processed through one-hot encoding and a fully connected layer, then input into the encoder in the preset model, and then into the embedding layer to obtain the first intent representation vector. The classification label represents the text intent; for example, in a dialogue system, there may be classification labels for different intents such as "query information" and "make a request." The first intent representation vector reflects the model's understanding and representation of the text intent.

[0108] Simultaneously, the second intent representation vector corresponding to the preset intent is obtained. The preset intent refers to the pre-defined true intent of the text (such as "query information"). The preset intent is converted into a high-dimensional sparse vector through one-hot encoding, where each intent corresponds to a unique index position of 1. Then, it is projected to a low-dimensional space through a linear transformation of the embedding layer to obtain a dense vector representation. The semantic information of the intent is then fused, and the final vector is the second intent representation vector used to calculate the intent loss. The second intent representation vector represents a quantitative expression of the true intent.

[0109] Then, the similarity between the first and second intent representation vectors is calculated using the cosine angle, thus obtaining the intent loss, denoted as L. intent When calculating the intent loss, the cosine similarity value can be subtracted from 1 to obtain a non-negative loss value. If the intent loss is small, it means that the intent predicted by the model (the first intent representation vector) is close to the true intent (the second intent representation vector); conversely, it indicates that the model has a bias in intent prediction.

[0110] In one embodiment, the dialogue sequence loss is calculated based on the first sequence representation vector of the first text and the second sequence representation vector of the first text, wherein the second sequence representation vector is a vector of the first text determined by the preset model based on the second text, and the first sequence representation vector is a preset vector of the first text, as detailed below:

[0111] The first and second texts can use a unified format for the dialogue state sequence, such as {intent, entity 1, ..., entity n}. The second text (i.e., the preceding dialogue text, such as the (n-1)th round dialogue state) is processed through one-hot encoding and a fully connected layer, then input into the encoder and decoder of the predefined model, and further processed through an embedding layer to obtain the second sequence representation vector. Simultaneously, the first sequence representation vector of the first text (i.e., the current dialogue text, such as the nth round dialogue state) is input into the embedding layer. The dialogue sequence loss, denoted as L, is obtained by calculating the difference between the second sequence representation vector (the model-predicted historical dialogue state related to the current state) and the first sequence representation vector (the actual current state). seq2seq The parameters of the encoder in the model are iterated based on the dialogue sequence loss to ensure that it can accurately predict the dialogue state of the current turn based on the historical context, thereby improving the coherence and context consistency of the multi-turn dialogue system.

[0112] Specifically, the computation process of the encoder and decoder for the dialogue state sequence can be seen in the following description:

[0113] Data preparation: For example, collect query dialogues from the transportation department in the large-scale transportation survey, extract the intents and mentioned entities, and construct them into a dialogue state sequence in the following format: {intent, entity 1, entity 2, ..., entity n}. Taking the first two input sentences as an example: "How many residents were there in City A last month?" and "What about City B?", these two sentences can be transformed into the following dialogue state sequence: [{indicator query, last month, City A, resident population}, {single location query, "", City B, ""}].

[0114] Expected output: Input the state sequence of the first two rounds of dialogue: [{Indicator query, last month, City A, Resident population}, {Single location query, "", City B, ""}], output the state sequence of the third round of dialogue: {Single indicator query, "", "", Working population};

[0115] Input embedding: Assume the input sequence (i.e., the sequence corresponding to the second text) is: DialogState = {D1, D2, ..., D...} T}, where D t It is the dialogue state sequence {Intent, entity1, entity2, ... entity} after one-hot encoding in the t-th round. k} t t ranges from 1 to n-1.

[0116] First, each dialogue state sequence is converted into an embedding vector. The following relationship must be satisfied:

[0117] H 0=DialogStateW DialogState ;

[0118]

[0119] In this context, Intent represents intent, and entity... j (j from 1 to k) represents entities, W DialogState It is a learnable embedding vector matrix.

[0120] The decoder can consist of a single layer, containing multi-head self-attention, encoder-decoder attention, and a feedforward neural network. For the l-th layer (l=4), the decoder output H 4 After linear transformation, the final output is obtained:

[0121] Y = H 4 W o +b o ;

[0122] Among them W o and b o These are the weights and biases of the output layer.

[0123] The predicted dialogue state sequence for the nth round is input into Y, and its similarity with the actual state sequence for the nth round is calculated, which is used as the dialogue state sequence prediction loss L. seq2seq .

[0124] After obtaining the entity loss L entity Mask loss L mask Intended loss L intent Dialogue sequence loss L seq2seq Next, determine the first loss value L. total Please refer to the following formula:

[0125] L total =L entity +L intent +L mask +L seq2seq ;

[0126] Specifically, the first word segmentation sequence can be input into a preset model for iterative training using an optimization algorithm, and the iteration stopping condition can be set to |ΔL. total |<10 -10 The optimization algorithm can be expressed as:

[0127] θ * =argmin θ L total ;

[0128] By optimizing the algorithm, the optimal parameters are calculated, and training is stopped when the absolute value of the total loss changes by less than 10e-10. The optimal model parameters are then output, which are the first parameters of the encoder in the preset model after the target number of iterations of training.

[0129] Addressing the challenge of context management in multi-turn dialogues, this paper introduces a dialogue state sequence prediction task. This task effectively integrates user intent and entity information, accurately predicting the state of the nth turn based on the dialogue state sequence of the previous n-1 turns. In the joint learning of intent recognition, entity extraction, and mask prediction tasks, the accuracy of dialogue intent recognition is improved from 80% to 95.3%, the response time is reduced from 5 seconds to 3 seconds, and the accuracy of guiding question generation is increased from 60% to 90%. These achievements not only demonstrate the high accuracy and rapid response of multi-turn dialogue processing but also enhance the ability to manage dialogue context, providing users with a smoother and more accurate interactive experience.

[0130] See Figure 3 , Figure 3 This is a schematic diagram of the structure of a multi-turn dialogue model training device provided in an embodiment of this application, as shown below. Figure 3 As shown, the multi-turn dialogue model training device 300 includes:

[0131] The first acquisition module 301 is used to acquire continuous multi-turn dialogue text and a first word segmentation sequence corresponding to the first text. The first text is the last round dialogue text in the multi-turn dialogue text. The first word segmentation sequence includes N-1 word elements, a mask marker, and a classification marker. The first word segmentation sequence is obtained by preprocessing the second word segmentation sequence corresponding to the first text. The second word segmentation sequence includes N word elements. The mask marker is a first marker corresponding to any target word element among the N word elements. The N-1 word elements are word elements other than the target word element among the N word elements. The classification marker is a second marker corresponding to the preset intent of the first text. N is an integer greater than 1.

[0132] The calculation module 302 is used to calculate the entity loss determined by the preset model based on the N-1 lexical units, the mask loss determined based on the mask label, the intent loss determined based on the classification label, and the dialogue sequence loss determined based on the first text and the second text, to obtain a first loss value, wherein the second text is the dialogue text other than the first text in the multi-turn dialogue text;

[0133] The training module 303 is used to iteratively train the preset model based on the first loss value until the first loss value is less than a preset threshold, and then determine the preset model after iterative training as a multi-turn dialogue model.

[0134] Optionally, the preset model includes an encoder, a decoder, and a feedforward neural network layer. The encoder includes a dot product attention layer and an additive attention layer. The dot product attention layer is used to determine the attention weight of the value vector by calculating the dot product between the query vector and the key vector. The additive attention layer is used to learn the nonlinear relationship between the query vector and the key vector through the feedforward neural network layer.

[0135] Training module 303 is specifically used for:

[0136] If the first loss value is less than a preset threshold, the first parameter corresponding to the encoder after iterative training is obtained. The first parameter includes encoder parameters, decoder parameters and feedforward neural network layer parameters. The encoder parameters include the weights of the dot product attention layer and the weights of the additive attention layer.

[0137] The preset model with the first parameter is determined as the multi-turn dialogue model.

[0138] Optionally, the device further includes:

[0139] The first processing module is used to perform word segmentation on the first text to obtain the N word elements;

[0140] The second processing module is used to perform masking processing on any one of the N word elements to obtain a masking mark of the target word element, wherein the target word element is the word element that has been masked among the N word elements;

[0141] The second acquisition module is used to acquire the classification tag corresponding to the preset intent of the first text.

[0142] Optionally, the calculation module 302 is specifically used for:

[0143] The entity loss is calculated based on the lexical representation vectors of the N-1 lexical units and the entity label vectors corresponding to the N-1 lexical units. The lexical representation vectors are vectors determined by the preset model based on the N-1 lexical units, and the entity label vectors are preset vectors of the entities corresponding to the N-1 lexical units respectively.

[0144] The masking loss is calculated based on the first masking representation vector of the masking mark and the second masking representation vector of the target word. The first masking representation vector is a vector determined by the preset model based on the masking mark, and the second masking representation vector is the vector corresponding to the target word.

[0145] The intent loss is calculated based on the first intent representation vector of the classification label and the second intent representation vector of the preset intent. The first intent representation vector is a vector determined by the preset model based on the classification label, and the second intent representation vector is a vector corresponding to the preset intent.

[0146] The dialogue sequence loss is calculated based on the first sequence representation vector and the second sequence representation vector of the first text, wherein the second sequence representation vector is a vector determined by the preset model based on the second text to represent the first text, and the first sequence representation vector is a preset vector of the first text.

[0147] The first loss value is determined based on the entity loss, the mask loss, the intent loss, and the dialogue sequence loss.

[0148] Optionally, calculating the entity loss based on the lexical representation vectors of the N-1 lexical units and the entity label vectors corresponding to the N-1 lexical units includes:

[0149] Each of the N-1 lexical units is individually encoded using a one-hot encoding method and passed through a fully connected layer. An embedding vector is then set for each lexical unit and input into the preset model to obtain the lexical representation vectors corresponding to the N-1 lexical units. The embedding vectors are used to represent the positional order of the lexical units in the first text. The fully connected layer is used to unify the dimensions of the N-1 lexical units after the one-hot encoding.

[0150] Obtain the entity label vector corresponding to each of the N-1 lexical units;

[0151] The entity loss is obtained in the Conditional Random Field (CRF) layer based on the lexical representation vector and the entity label vector.

[0152] Optionally, calculating the masking loss based on the first masking representation vector of the masking tag and the second masking representation vector of the target word includes:

[0153] The mask marker is input into the preset model and passed through the embedding layer to obtain the first mask representation vector;

[0154] The target word is one-hot encoded and passed through a fully connected layer and an embedding layer to obtain the second mask representation vector. Both the fully connected layer and the embedding layer are used for dimensional unification.

[0155] The mask loss is obtained by calculating the similarity between the first mask representation vector and the second mask representation vector using the cosine angle.

[0156] Optionally, calculating the intent loss based on the first intent representation vector of the classification label and the second intent representation vector of the preset intent includes:

[0157] The classification label is one-hot encoded and passed through a fully connected layer before being input into the preset model to obtain the first intent representation vector.

[0158] The preset intent is input into the embedding layer to obtain the second intent representation vector. Both the fully connected layer and the embedding layer are used for dimension unification.

[0159] The intention loss is obtained by calculating the similarity between the first intention representation vector and the second intention representation vector using the cosine angle.

[0160] The multi-turn dialogue model training device 300 is capable of implementing each process of the above-described multi-turn dialogue model training method, with one-to-one correspondence of technical features and achieving the same technical effect. To avoid repetition, it will not be described in detail here.

[0161] This application also provides an electronic device, including: a processor, a memory, and a program stored in the memory and executable on the processor. When the program is executed by the processor, it implements the various processes of the above-described multi-turn dialogue model training method embodiments and achieves the same technical effect. To avoid repetition, it will not be described again here.

[0162] This application also provides a computer-readable storage medium storing a computer program. When executed by a processor, this computer program implements the various processes of the above-described multi-turn dialogue model training method embodiments and achieves the same technical effects. To avoid repetition, it will not be described again here. The computer-readable storage medium may be a read-only memory (ROM), a random access memory (RAM), a magnetic disk, or an optical disk, etc.

[0163] This application also provides a computer program product, including computer instructions. When the computer instructions are executed by a processor, they implement the various processes of the above-described multi-turn dialogue model training method embodiments and achieve the same technical effect. To avoid repetition, they will not be described again here.

[0164] It should be noted that, in this document, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes that element. Furthermore, it should be noted that the scope of the methods and apparatuses in the embodiments of this application is not limited to performing functions in the order discussed, but may also include performing functions substantially simultaneously or in the reverse order, depending on the functions involved. For example, the described methods may be performed in a different order than described, and various steps may be added, omitted, or combined. Additionally, features described with reference to certain examples may be combined in other examples.

[0165] Through the above description of the embodiments, those skilled in the art can clearly understand that the methods of the above embodiments can be implemented by means of software plus necessary general-purpose hardware platforms. Of course, they can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk) and includes several instructions to cause a terminal (which may be a mobile phone, computer, server, air conditioner, or network device, etc.) to execute the methods described in the various embodiments of this application.

[0166] The embodiments of this application have been described above with reference to the accompanying drawings. However, this application is not limited to the specific embodiments described above. The specific embodiments described above are merely illustrative and not restrictive. Those skilled in the art can make many other forms under the guidance of this application without departing from the spirit and scope of the claims, and all of these forms are within the protection scope of this application.

Claims

1. A method for training a multi-turn dialogue model, characterized in that, The method includes: Obtain continuous multi-turn dialogue text and a first word segmentation sequence corresponding to the first text. The first text is the last round of dialogue text in the multi-turn dialogue text. The first word segmentation sequence includes N-1 words, a mask marker, and a classification marker. The first word segmentation sequence is obtained by preprocessing the second word segmentation sequence corresponding to the first text. The second word segmentation sequence includes N words. The mask marker is the first marker corresponding to any target word among the N words. The N-1 words are words other than the target word among the N words. The classification marker is the second marker corresponding to the preset intent of the first text. N is an integer greater than 1. The first loss value is obtained by calculating the entity loss determined by the preset model based on the N-1 lexical units, the mask loss determined based on the mask label, the intent loss determined based on the classification label, and the dialogue sequence loss determined based on the first text and the second text, where the second text is the dialogue text other than the first text in the multi-turn dialogue text. Based on the first loss value, the preset model is iteratively trained until the first loss value is less than a preset threshold, and the preset model after iterative training is determined as a multi-turn dialogue model. Specifically, the entity loss is used for word-level semantic recognition training, the mask loss is used for local semantic understanding and reasoning training, the intent loss is used for overall text intent recognition training, and the dialogue sequence loss is used for context dependency recognition training.

2. The method according to claim 1, characterized in that, The preset model includes an encoder, a decoder, and a feedforward neural network layer. The encoder includes a dot product attention layer and an additive attention layer. The dot product attention layer is used to determine the attention weight of the value vector by calculating the dot product between the query vector and the key vector. The additive attention layer is used to learn the non-linear relationship between the query vector and the key vector through the feedforward neural network layer. The step of iteratively training the preset model based on the first loss value until the first loss value is less than a preset threshold, and then determining the iteratively trained preset model as a multi-turn dialogue model, includes: If the first loss value is less than a preset threshold, the first parameter corresponding to the encoder after iterative training is obtained. The first parameter includes encoder parameters, decoder parameters and feedforward neural network layer parameters. The encoder parameters include the weights of the dot product attention layer and the weights of the additive attention layer. The preset model with the first parameter is determined as the multi-turn dialogue model.

3. The method according to claim 1, characterized in that, Before obtaining the continuous multi-turn dialogue text and the first word segmentation sequence corresponding to the first text, the method further includes: The first text is segmented to obtain the N word elements; Masking is performed on any one of the N lexical units to obtain a masked marker for the target lexical unit, wherein the target lexical unit is the lexical unit that has been masked among the N lexical units; Obtain the category tag corresponding to the preset intent of the first text.

4. The method according to any one of claims 1 to 3, characterized in that, The computational preset model obtains a first loss value based on the entity loss determined by the N-1 lexical units, the mask loss determined by the mask markers, the intent loss determined by the classification markers, and the dialogue sequence loss determined by the first and second texts, including: The entity loss is calculated based on the lexical representation vectors of the N-1 lexical units and the entity label vectors corresponding to the N-1 lexical units. The lexical representation vectors are vectors determined by the preset model based on the N-1 lexical units, and the entity label vectors are preset vectors of the entities corresponding to the N-1 lexical units respectively. The masking loss is calculated based on the first masking representation vector of the masking mark and the second masking representation vector of the target word. The first masking representation vector is a vector determined by the preset model based on the masking mark, and the second masking representation vector is the vector corresponding to the target word. The intent loss is calculated based on the first intent representation vector of the classification label and the second intent representation vector of the preset intent. The first intent representation vector is a vector determined by the preset model based on the classification label, and the second intent representation vector is a vector corresponding to the preset intent. Based on the first sequence representation vector and the second sequence representation vector of the first text, the dialogue sequence loss is calculated, wherein the second sequence representation vector is a vector determined by the preset model based on the second text to represent the first text, and the first sequence representation vector is a preset vector of the first text. The first loss value is determined based on the entity loss, the mask loss, the intent loss, and the dialogue sequence loss.

5. The method according to claim 4, characterized in that, The step of calculating the entity loss based on the lexical representation vectors of the N-1 lexical units and the entity label vectors corresponding to the N-1 lexical units includes: Each of the N-1 lexical units is individually encoded using a one-hot encoding method and passed through a fully connected layer. An embedding vector is then set for each lexical unit and input into the preset model to obtain the lexical representation vectors corresponding to the N-1 lexical units. The embedding vectors are used to represent the positional order of the lexical units in the first text. The fully connected layer is used to unify the dimensions of the N-1 lexical units after the one-hot encoding. Obtain the entity label vector corresponding to each of the N-1 lexical units; The entity loss is obtained in the Conditional Random Field (CRF) layer based on the lexical representation vector and the entity label vector.

6. The method according to claim 4, characterized in that, The step of calculating the masking loss based on the first masking representation vector of the masking label and the second masking representation vector of the target word includes: The mask marker is input into the preset model and passed through the embedding layer to obtain the first mask representation vector; The target word is one-hot encoded and passed through a fully connected layer and an embedding layer to obtain the second mask representation vector. Both the fully connected layer and the embedding layer are used for dimensional unification. The mask loss is obtained by calculating the similarity between the first mask representation vector and the second mask representation vector using the cosine angle.

7. The method according to claim 4, characterized in that, The step of calculating the intent loss based on the first intent representation vector of the classification label and the second intent representation vector of the preset intent includes: The classification label is one-hot encoded and passed through a fully connected layer before being input into the preset model to obtain the first intent representation vector. The preset intent is input into the embedding layer to obtain the second intent representation vector. Both the fully connected layer and the embedding layer are used for dimension unification. The intention loss is obtained by calculating the similarity between the first intention representation vector and the second intention representation vector using the cosine angle.

8. A multi-turn dialogue model training device, characterized in that, The device includes: The first acquisition module is used to acquire continuous multi-turn dialogue text and a first word segmentation sequence corresponding to the first text. The first text is the last round dialogue text in the multi-turn dialogue text. The first word segmentation sequence includes N-1 word elements, a mask marker, and a classification marker. The first word segmentation sequence is obtained by preprocessing the second word segmentation sequence corresponding to the first text. The second word segmentation sequence includes N word elements. The mask marker is a first marker corresponding to any target word element among the N word elements. The N-1 word elements are word elements other than the target word element among the N word elements. The classification marker is a second marker corresponding to the preset intent of the first text. N is an integer greater than 1. The calculation module is used to calculate the entity loss determined by the preset model based on the N-1 lexical units, the mask loss determined based on the mask label, the intent loss determined based on the classification label, and the dialogue sequence loss determined based on the first text and the second text, to obtain a first loss value. The second text is the dialogue text other than the first text in the multi-turn dialogue text. The training module is used to iteratively train the preset model based on the first loss value until the first loss value is less than a preset threshold, and then determine the preset model after iterative training as a multi-turn dialogue model. Specifically, the entity loss is used for word-level semantic recognition training, the mask loss is used for local semantic understanding and reasoning training, the intent loss is used for overall text intent recognition training, and the dialogue sequence loss is used for context dependency recognition training.

9. An electronic device, characterized in that, include: A processor, a memory, and a program stored in the memory and executable on the processor, wherein the program, when executed by the processor, implements the steps of the multi-turn dialogue model training method as described in any one of claims 1 to 7.

10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that, when executed by a processor, implements the steps of the multi-turn dialogue model training method as described in any one of claims 1 to 7.

Citation Information

Patent Citations

  • Multi-round question and answer recognition method and device, computer equipment and storage medium

    CN110825857A

  • Intelligent customer service dialogue generation method and system based on user intention recognition

    CN119990149A