Parallel generation method of reply text, terminal equipment and storage medium
Through the synergistic effect of parallel processing of A-G module and position embedding and multi-head self-attention, the problem of slow generation of traditional text generation methods is solved, and faster and higher quality reply text generation is achieved.
Patent Information
- Application Number
- CN202510354487.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-03-25
- Publication Date
- 2025-04-22
- Estimated Expiration
- 2045-03-25
AI Technical Summary
Traditional text generation methods rely on word-by-word or sentence-by-word generation methods, resulting in slow generation speed and inability to meet real-time interaction requirements.
Through the parallel processing mechanism of the A-G module, multiple candidate sequences are generated, and the synergy between position embedding and multi-head self-attention captures the timing relationship and deep semantics of the dialogue context.
It significantly shortens the delay of the traditional verbatim generation method, improves the BLEU value of the reply, reduces the degree of confusion (PPL), and avoids the semantic fault phenomenon caused by local optimal solutions.
Smart Images

Figure CN119862892A_ABST
Abstract
Description
Technical Field
[0001] The invention belongs to the field of data processing, and in particular relates to a parallel generation method of a reply text, a terminal device and a storage medium. Background Art
[0002] In the field of text generation, intelligent dialogue systems are widely used in customer service, personal assistants, educational guidance, medical consultation, smart home control and other fields, improving life convenience and work efficiency. However, traditional text generation methods still have some limitations.
[0003] Traditional text generation methods often rely on sequential generation of words or sentences. This method is relatively slow. For example, word-by-word generation may take up to 2 seconds to complete the generation of a sentence. A new technical means is needed to solve the above technical problems. Summary of the invention
[0004] In view of this, an embodiment of the present invention provides a parallel generation method of a reply text, a terminal device and a storage medium, which can solve the problem of slow text generation speed in the related art.
[0005] A first aspect of the present invention provides a method for parallel generation of reply texts, comprising: When input information is detected, a global vector corresponding to the conversation context is generated, and an initial reply sequence corresponding to the global vector is generated; Inputting the global vector and the initial reply sequence into the AG module for parallel processing to obtain multiple candidate sequences; Generate reply content according to the candidate sequence.
[0006] Optionally, in a first implementation of the first aspect of the present invention, when input information is detected, generating a global vector corresponding to the dialog context further includes: When input information is detected, obtaining the dialog context; Encoding each sentence in the conversation context by a bidirectional gated recurrent unit to obtain a speech feature vector, and assigning a continuous position number to each sentence to obtain a position number; According to each of the position numbers, the position embedding PE of each position is calculated by alternating sine waves and cosine waves; Concatenate each of the position embedding PEs with each of the utterance feature vectors to obtain a context representation including the conversation sequence; According to each of the context representations, the global vector corresponding to the conversation context is generated.
[0007] Optionally, in a second implementation manner of the first aspect of the present invention, the step of generating the global vector corresponding to the conversation context according to each of the context representations includes: Each of the concatenated context representations is input into a multi-head self-attention module to generate the global vector corresponding to the conversation context containing global semantic information.
[0008] Optionally, in a third implementation manner of the first aspect of the present invention, the step of inputting the global vector and the initial reply sequence into the AG module for parallel processing to obtain multiple candidate sequences includes: Calculating the degree of association between the initial reply sequence and the global vector to obtain an intermediate result of fusing context information; Inputting the intermediate result into a recurrent neural network unit with a memory function to obtain a hidden representation of the word to be generated; According to the hidden representation, calculating the generation probability of each candidate word to form a candidate word list sorted by probability; According to the candidate word list, a plurality of candidate sequences are generated.
[0009] Optionally, in a fourth implementation manner of the first aspect of the present invention, the step of generating reply content according to the candidate sequence includes: Assigning a gradually increasing weight value to each unit in the candidate word list; The word probability corresponding to each unit in the candidate word list is multiplied by the weight value corresponding to each unit and then added up to obtain a plurality of comprehensive probabilities; A plurality of candidate sequences are selected according to a plurality of the comprehensive probabilities.
[0010] Optionally, in a fifth implementation of the first aspect of the present invention, the step of assigning a gradually increasing weight value to each unit in the candidate word list includes: According to the position index of each unit in the candidate word list and a preset positive real number parameter, an initial weight value is calculated by an exponential function, and the larger the position index is, the larger the corresponding initial weight value increases; Each initial weight value is divided by the sum of all initial weight values to obtain a weight value corresponding to each of the units.
[0011] Optionally, in a sixth implementation manner of the first aspect of the present invention, after the step of generating reply content according to the candidate sequence, the method further includes: If a reply operation is being performed and new content input by the user is detected, the reply operation is stopped, and the conversation context is updated according to the complete semantic fragment in the currently replied content, where the currently replied content is the content being replied but not completed; Return to the step of executing to generate the global vector corresponding to the conversation context.
[0012] Optionally, in a seventh implementation manner of the first aspect of the present invention, when the input information is detected, the step of generating a global vector corresponding to the dialogue context includes: When input information is detected, the historical conversation context is obtained; According to the input information, retaining N rounds of dialogue in the historical dialogue context as the dialogue context; Generate the global vector corresponding to the conversation context.
[0013] In a second aspect, an embodiment of the present invention provides a terminal device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of the above-mentioned method for parallel generation of reply texts when executing the computer program.
[0014] In a third aspect, an embodiment of the present invention provides a computer-readable storage medium, which stores a computer program. When the computer program is executed by a processor, the steps of the above-mentioned parallel generation method of reply text are implemented.
[0015] In a fourth aspect, an embodiment of the present invention provides a computer program product, which, when executed on a terminal device, enables the terminal device to execute the above-mentioned method for parallel generation of reply texts.
[0016] The beneficial effects of the embodiments of the present invention compared with the prior art are: through the parallel processing mechanism of the AG module, multiple candidate sequences are generated in a single iteration, shortening the delay required by the traditional word-by-word generation method. The delay problem caused by multiple iterations in the traditional sequence generation method is solved. In the stage of generating a global vector, the temporal relationship and deep semantics of the conversation context can be captured through the synergy of position embedding and multi-head self-attention. Combined with the overall evaluation mechanism of the candidate sequence of the AG module, the BLEU value of the generated response can be improved and the perplexity (PPL) can be reduced, effectively avoiding the semantic fault phenomenon caused by the local optimal solution of the traditional method. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative labor.
[0018] Figure 1 A schematic diagram of an embodiment of a method for generating reply texts in parallel in an embodiment of the present invention; Figure 2 A schematic diagram of a specific embodiment of step S101 of the parallel generation method of reply texts in an embodiment of the present invention; Figure 3 A schematic diagram of a specific embodiment of step S102 of the method for generating reply texts in parallel in an embodiment of the present invention; Figure 4 A schematic diagram of a specific embodiment of step S103 of the parallel generation method of reply texts in an embodiment of the present invention; Figure 5 The figure is a schematic diagram of an embodiment of a terminal device in an embodiment of the present invention. DETAILED DESCRIPTION
[0019] In order to make the purpose, technical scheme and advantages of the present invention more clearly understood, the present invention is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not intended to limit the present invention. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without making creative work are protected by the present invention.
[0020] It should be noted that the terms "include", "comprises" and "have" and any variations thereof in the specification and claims of the present invention and the above-mentioned drawings are intended to cover non-exclusive inclusions. For example, a process, method, terminal, product or device that includes a series of steps or units is not limited to the listed steps or units, but may optionally include steps or units that are not listed, or may optionally include other steps or units that are inherent to these processes, methods, products or devices. In the claims, specifications and drawings of the present invention, relational terms such as "first" and "second" are merely used to distinguish one entity / operation / object from another entity / operation / object, and do not necessarily require or imply any such real-time relationship or order between these entities / operations / objects.
[0021] Reference to an "embodiment" herein means that a particular feature, structure, or characteristic described in conjunction with the embodiment may be included in at least one embodiment of the present invention. The appearance of the phrase in various places in the specification does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment that is mutually exclusive with other embodiments. It is explicitly and implicitly understood by those skilled in the art that the embodiments described herein may be combined with other embodiments.
[0022] In the field of text generation, intelligent dialogue systems are widely used in customer service, personal assistants, educational guidance, medical consultation, smart home control and other fields, improving life convenience and work efficiency. However, traditional text generation methods still have some limitations.
[0023] Traditional text generation methods often rely on sequential generation of words or sentences. This method is relatively slow. For example, word-by-word generation may take up to 2 seconds to complete the generation of a sentence. A new technical means is needed to solve the above technical problems.
[0024] In view of this, an embodiment of the present invention provides a parallel generation method, terminal device and storage medium for reply text. Through the parallel processing mechanism of the AG module, multiple candidate sequences are generated in a single iteration, shortening the delay required for the traditional word-by-word generation method. The delay problem caused by multiple iterations in the traditional sequence generation method is solved. In the stage of generating a global vector, the temporal relationship and deep semantics of the conversation context can be captured through the synergy of position embedding and multi-head self-attention. Combined with the overall evaluation mechanism of the candidate sequence of the AG module, the BLEU value of the generated reply can be improved and the perplexity (PPL) can be reduced, effectively avoiding the semantic fault phenomenon caused by the local optimal solution of the traditional method.
[0025] In order to illustrate the technical solution of the present invention, specific embodiments are provided below for illustration.
[0026] Figure 1 The present invention provides a parallel reply text generation method implementation flow diagram, which can be applied to a terminal device, such as a mobile phone, a tablet computer, a notebook computer, an ultra-mobile personal computer (UMPC), a netbook, etc.
[0027] Specifically, the above-mentioned parallel generation method of reply text may include the following steps S101 to S103.
[0028] Step S101, when input information is detected, a global vector corresponding to the dialog context is generated, and an initial reply sequence corresponding to the global vector is generated.
[0029] Specifically, when the system detects user input (such as text messages, voice commands), the conversation processing process is started. The context information of the current conversation is extracted from the storage module, including the user's latest input content and the preset historical conversation rounds (such as the last three rounds of conversation). Irrelevant historical information is automatically filtered out to focus on the conversation content directly related to the current input.
[0030] A bidirectional recurrent neural network is used to deeply encode each sentence in the context and convert each sentence into a high-dimensional vector containing semantic features. For example, a user's question "How to relieve headaches?" is encoded into a 256-dimensional feature vector.
[0031] Assign a continuous position number to each sentence (e.g., the first sentence is numbered 0, the second sentence is numbered 1), and generate the corresponding position encoding vector through a mathematical function to ensure that the model can recognize the order of the conversation. Concatenate the semantic feature vector with the position encoding vector to form an enhanced representation that contains both semantic and temporal information.
[0032] Based on the global vector, an initial reply segment is generated.
[0033] Convert the global vector and the initial reply fragment into a vector form that the model can process. Start multiple parallel generation units (AG units), each of which independently predicts the possible subsequent words. Each unit associates the global vector with the generated content through the attention mechanism to ensure that the prediction results conform to the context logic. Each unit outputs a list of candidate words sorted by probability, which are combined to form multiple candidate reply sequences.
[0034] In a specific example, the input text data is converted into a numerical vector representation. For each utterance in the conversation context, it is first segmented and then its vector representation is obtained through embedding. Then, Bi-GRU is used to encode each utterance feature vector, and its final hidden state is used as the representation of the utterance. Finally, the vector representation (global vector) of N utterances is obtained.
[0035] Multi-Head Self-Attention (MHSA) can capture important information in the sequence and generate the contextual representation of each utterance by aggregating the features of other utterances from the conversation history. At the same time, position embedding (PE) is used to distinguish different positions between utterances. The specific operation is to concatenate them with the utterance representation, that is, Then we get the vector representation of the conversation context Among them, h Nis the discourse feature vector of the Nth sentence in the dialogue context (N is a natural number, representing the Nth round of sentences in the dialogue history). The Nth sentence is encoded by the bidirectional gated recurrent unit to obtain the Bi-GRU, which performs forward and backward semantic analysis at the same time. N After splicing, the enhanced representation [h N PE N ]. N The generation of will dynamically associate all related sentences in the conversation history (for example, h2 may strengthen the entity reference relationship with h5).
[0036] Step S102: input the global vector and the initial reply sequence into the AG module for parallel processing to obtain multiple candidate sequences.
[0037] In a specific example, to generate words t to t+n, , firstly, the t-1 words generated previously As input, to obtain representations with multi-head self-attention (future masking): ; in Targeted response The embedding vector of the generated word is .
[0038] There are n parallel AG units in the AG module, each of which contains: attention, GRU, and Softmax layers. The vector representation of the generated sequence Conversation context vector representation with encoder output Input into the AG module. For the kth AG unit in the AG module, each working process has the following three steps: The first step is to represent the response history As a query, represented by the conversation context vector As keys and values, we obtain the output representation through attention : ; In the second step, the GRU model is used as a decoder to generate responses. The decoding process is expressed by the following formula: ; The third step is to use the Softmax layer to represent the output vector of GRU. To obtain the word probability, the formula is as follows: ; in is a trainable parameter.
[0039] Since all AG units in the AG module receive input vectors They are all the same, but it is easier for the AG units arranged in the front to accurately predict the token. The AG units arranged in the back have a larger span of tokens separated from the front AG units, so the generated tokens are more difficult to predict accurately than the front ones. In order to meet this challenge, the present invention introduces an exponential growth weight mechanism when designing the loss function. This method assigns different weights according to the position of the AG unit, and defines it through an exponential function to ensure that the later AG units obtain greater weights. This strategy not only emphasizes the importance of the later part of the sequence, but also can highlight some more critical sequence parts in specific application scenarios, thereby optimizing the overall generation effect. This method helps to balance the training signals of tokens in different positions and improve the consistency and naturalness of the entire response sequence.
[0040] Now the model has n AG units, each of which is responsible for generating a token. The exponential growth weight of the AG unit at the i-th position can be designed as follows: ; where i is the position index of the AG unit (from 0 to n-1), is a positive real number parameter used to control the growth rate of the weight. If you want the difference between weights not to be too large, you can choose a smaller value. If you want to emphasize the importance of the later GRU, you can choose a large This will result in very small weights for the early GRUs and relatively large weights for the later GRUs.
[0041] Since directly using the above formula may lead to too large a difference in weights, thus affecting the stability of gradient updates during training, the weights are normalized to ensure that their sum is 1 or within a reasonable range. The normalization method adopted by the present invention is to divide all weights by their sum, that is: ; This ensures that the sum of all weights is 1 while maintaining the exponential growth trend.
[0042] For each AG unit (responsible for generating a token), the loss function can be expressed as: ; in is the i-th token The conditional probability of , given the dialogue context And the token sequence generated previously . Finally, the total weighted loss function can be written as: ; Step S103: generating reply content according to the candidate sequence.
[0043] Optionally, assign higher weights to later generation units to emphasize long-distance semantic coherence. Weighted scoring of candidate sequences is performed, giving priority to sequences with high accuracy of the tail words. When a complete sentence is generated or new user input is detected, generation is terminated immediately and the optimal response is output. Stop the current response immediately and switch to processing new questions.
[0044] The beneficial effects of the embodiments of the present invention compared with the prior art are: through the parallel processing mechanism of the AG module, multiple candidate sequences are generated in a single iteration, shortening the delay required by the traditional word-by-word generation method. The delay problem caused by multiple iterations in the traditional sequence generation method is solved. In the stage of generating the global vector, the temporal relationship and deep semantics of the dialogue context can be captured through the synergy of position embedding and multi-head self-attention. Combined with the overall evaluation mechanism of the candidate sequence of the AG module, the semantic fault phenomenon caused by the local optimal solution of the traditional method is effectively avoided.
[0045] Reference Figure 2 , Figure 2 This is a schematic diagram of a specific embodiment of step S101 of the parallel generation method of reply text in an embodiment of the present invention. Step S101 also includes the following specific implementation methods.
[0046] Step S1011, when input information is detected, the dialog context is obtained.
[0047] In an embodiment of the present invention, when user input (such as text messages, voice commands) is detected, the conversation context processing flow is started. The complete conversation history related to the current input is extracted from the storage module, including the latest content submitted by the user and the preset historical conversation rounds (for example, the latest 5 conversation rounds are retained). Through the intelligent filtering mechanism, irrelevant or outdated conversation content is automatically eliminated to ensure that the context focuses on the core topic of the current interaction.
[0048] Step S1012, encoding each sentence in the dialogue context through a bidirectional gated recurrent unit to obtain a speech feature vector, and assigning a continuous position number to each sentence to obtain a position number.
[0049] In the embodiment of the present invention, the conversation context is segmented into independent units according to natural sentences. For example, the user inputs "I want to book a flight to Beijing tomorrow, economy class", which is segmented into four semantic units: "book flight", "time: tomorrow", "destination: Beijing", and "cabin: economy class".
[0050] Each sentence is deeply encoded using a bidirectional gated recurrent network (Bi-GRU). The network analyzes sentences from both the forward and backward directions to capture contextual dependencies. For example, when encoding "economy class", not only its own semantics is considered, but also the intention of "booking a flight" in the previous text is associated. The semantic feature vector (such as a 256-dimensional vector) of each sentence is output to accurately represent the core meaning of the sentence.
[0051] Step S1013, according to each of the position numbers, the position embedding PE of each position is calculated by alternating sine waves and cosine waves.
[0052] In the embodiment of the present invention, each sentence is assigned a continuously increasing position number (e.g., the first sentence is numbered 0, the second sentence is numbered 1) to clarify the temporal relationship of the conversation. For example, in a multi-round conversation, "What time do you need to leave?" (numbered 2) comes before "I want to book a morning flight" (numbered 3).
[0053] Based on the position number, the position embedding vector is calculated by alternating sine and cosine wave functions. This method makes the encoding of adjacent positions continuous, while the encoding of distant positions is significantly different, which helps the model distinguish the order of conversations. For example, the embedding of position number 0 highlights the characteristics of the beginning of the conversation, while the embedding of position number 5 strengthens the tail information.
[0054] Step S1014, concatenating each of the position embedding PEs with each of the speech feature vectors to obtain a context representation including the conversation sequence.
[0055] In the embodiment of the present invention, the semantic feature vector (256 dimensions) of each sentence is concatenated with the corresponding position embedding vector (128 dimensions) to form a 384-dimensional enhanced semantic representation. This operation enables the model to understand both the content of the sentence and its positional significance in the conversation. For example, after the semantic vector of "economy class" is concatenated with the embedding of position number 3, its order of appearance in the current conversation is clear.
[0056] Step S1015: generating the global vector corresponding to the conversation context according to each of the context representations.
[0057] In the embodiment of the present invention, the spliced enhanced semantic representation is input into the multi-head self-attention module, which analyzes the correlation strength between different sentences through a parallel multi-way attention mechanism. For example: identifying the strong correlation between "Beijing" and "flight" (attention weight 0.9) and weakening the indirect correlation between "tomorrow" and "economy class" (attention weight 0.2). The final output global vector (384 dimensions) integrates the core intention, entity relationship and time sequence logic of the dialogue, providing a complete context representation for subsequent generation.
[0058] In the embodiment of the present invention, through the synergy of semantic encoding and position modeling, a context representation with both deep semantic understanding and precise temporal reasoning is provided for the dialogue system, which is the core foundation of the parallel generation mechanism.
[0059] In traditional technologies, encoders based on Bi-GRU or unidirectional RNN are difficult to effectively model cross-sentence dependencies in long conversations. For example, in scenarios where users ask questions multiple times or switch topics, traditional models may generate off-topic replies by ignoring early key information. In addition, retrieval models rely on local matching and cannot dynamically capture global conversation logic. Based on this, the present invention proposes an optional embodiment.
[0060] Step S1015 also includes the following specific implementation methods.
[0061] Step S10151, input each of the concatenated context representations into a multi-head self-attention module to generate the global vector corresponding to the dialogue context containing global semantic information.
[0062] In an embodiment of the present invention, each concatenated context representation (including discourse feature vectors and position embeddings) is input into a multi-head self-attention module, and the association weights of each discourse feature with other discourse features are calculated in parallel to aggregate semantic information at different positions in the conversation history; weighted summation of the features is performed based on the weights to generate a vector representation that integrates global semantics; and finally, a global vector of the conversation context is output to fully represent the overall semantics and contextual logical relationship of the conversation.
[0063] In the embodiment of the present invention, the long-distance dependencies across discourses in the conversation history are captured through a multi-head self-attention mechanism, which effectively avoids the semantic attenuation problem caused by the sequence length limitation of the traditional recurrent neural network. The multi-head mechanism allows the model to independently learn conversation features from different subspaces (such as grammar, semantics, sentiment and other dimensions), enhances the ability to understand complex contexts, and improves the accuracy and relevance of replies. Combining position embedding with multi-head attention, the discourse order information is retained while integrating global semantics, avoiding the logical confusion problem caused by insufficient position encoding in traditional methods.
[0064] Traditional generative models (such as Seq2Seq) need to iterate word by word to generate replies, resulting in high response delays and difficulty in meeting real-time interaction requirements. At the same time, word-by-word generation is susceptible to local probability bias, resulting in logical inconsistencies or semantic redundancy before and after the reply. For example, in a long conversation scenario, a traditional model may generate off-topic replies due to insufficient modeling of global dependencies. Based on this, the present invention proposes an optional embodiment.
[0065] Reference Figure 3 , Figure 3 This is a schematic diagram of a specific embodiment of step S102 of the method for generating reply texts in parallel in an embodiment of the present invention. Step S102 also includes the following specific implementation methods.
[0066] Step S1021, calculating the correlation degree between the initial reply sequence and the global vector, and obtaining an intermediate result of fusing context information.
[0067] Step S1022: input the intermediate result into a recurrent neural network unit with a memory function to obtain a hidden representation of the word to be generated.
[0068] Step S1023: Calculate the generation probability of each candidate word according to the hidden representation to form a candidate word list sorted by probability.
[0069] Step S1024: Generate a plurality of candidate sequences according to the candidate word list.
[0070] In an embodiment of the present invention, during the parallel processing of the AG module, the semantic correlation between the initial reply sequence and the global vector is calculated through the attention mechanism to generate an intermediate feature representation that integrates the context information; the intermediate feature is then input into a recurrent neural network unit with a memory function to dynamically capture the state dependency in the sequence generation process, and output the context-aware hidden representation of the words to be generated; based on the hidden representation, the predicted probability of each candidate word is generated through the probability distribution calculation module to form a candidate word list sorted by probability; finally, according to the diversity strategy of the candidate word list, multiple semantically coherent candidate sequences are generated in parallel.
[0071] In the embodiment of the present invention, through the parallel processing mechanism of the AG module, multiple candidate words can be generated in a single iteration, which significantly reduces the number of iterations required for traditional word-by-word generation. During the generation process, the overall semantic coherence of multiple candidate sequences is synchronously evaluated, which effectively avoids the semantic fault or repetition problems caused by local optimality in traditional methods, and improves the naturalness and logical rationality of the response. Through the synergy of the attention mechanism and the recurrent neural network, the generation of each candidate word fully combines historical dialogue information to enhance the contextual relevance of the response.
[0072] Traditional generative models (such as Seq2Seq) usually use uniform weights or fixed decay weights to calculate the loss function during word-by-word generation, which results in the model not paying enough attention to the second half of the sequence. For example, when generating long replies, traditional methods may cause semantic duplication or logical discontinuity due to the lack of global constraints on the generation of later tokens. Based on this, the present invention proposes an optional embodiment.
[0073] Reference Figure 4 , Figure 4 This is a schematic diagram of a specific embodiment of step S103 of the method for generating reply text in parallel in an embodiment of the present invention. Step S103 also includes the following specific implementation methods.
[0074] Step S1031, assigning a gradually increasing weight value to each unit in the candidate word list.
[0075] Step S1032, multiplying the word probability corresponding to each unit in the candidate word list by the weight value corresponding to each unit and adding them up to obtain a plurality of comprehensive probabilities.
[0076] Step S1033: Select multiple candidate sequences according to the multiple comprehensive probabilities.
[0077] In an embodiment of the present invention, for each generation unit in the candidate word list (corresponding to candidate words at different positions), a gradually increasing weight value is dynamically allocated according to its position index to form a weight gradient distribution.
[0078] The generation probability corresponding to each candidate word unit is multiplied by its assigned weight value, and the weighted probabilities of all units are accumulated to generate a comprehensive probability score for multiple candidate sequences.
[0079] The candidate sequences are ranked based on the comprehensive probability score, and the multiple candidate sequences with the highest scores are selected as the candidate set for the final response, ensuring that the generated results have both diversity and quality.
[0080] In the embodiment of the present invention, the importance of the late generated words in the sequence is strengthened through a gradually increasing weight distribution mechanism, which effectively avoids the local optimal problem caused by the uniform weight distribution of the traditional method. According to the application scenario requirements, by adjusting the weight growth parameter (such as the base of the exponential function), the model's attention to different parts of the sequence can be flexibly controlled. Through weight normalization processing (such as sum normalization), the gradient update intensity of the generating units at different positions is balanced, which effectively avoids the problem of difficult model convergence caused by excessive weight differences during training.
[0081] In traditional technologies, generative models usually use fixed weight distribution (such as equal weight or linear decay weight), which makes it difficult to dynamically adapt to the response generation requirements of different lengths or scenarios. For example, when generating long responses, traditional methods may ignore key semantic information (such as concluding sentences) due to insufficient token weights in the later stages, resulting in incomplete response logic. Based on this, the present invention proposes an optional embodiment.
[0082] Step S103 also includes the following specific implementation methods.
[0083] Step S1034, according to the position index of each unit in the candidate word list and a preset positive real number parameter, an initial weight value is calculated by an exponential function, and the larger the position index is, the larger the corresponding initial weight value increases. Step S1035, dividing each initial weight value by the sum of all initial weight values to obtain a weight value corresponding to each of the units.
[0084] In an embodiment of the present invention, the initial weight value is calculated by an exponential function based on the position index of each unit in the candidate word list (such as the 0th position, the 1st position, etc. in the generation order) and a preset positive real number parameter, so that the weight growth rate of the unit with a larger position index (corresponding to the generated word later in the sequence) is significantly increased.
[0085] Optionally, the initial weight value is calculated by an exponential function according to the position index of each unit in the candidate word list and a preset positive real number parameter. The larger the position index, the larger the corresponding initial weight value increases. Each initial weight value is divided by the sum of all initial weight values to obtain the weight value corresponding to each unit. Specifically, the initial weight values of all units are summed, and each initial weight value is divided by the sum to obtain a normalized weight value, ensuring that the sum of all weights is 1 while retaining the exponential growth trend.
[0086] In the embodiment of the present invention, by combining the exponential function with the normalization process, the high attention to the second half of the sequence is retained, and the problem of training gradient imbalance caused by excessive weight differences is avoided, thereby improving the convergence stability of the model. By adjusting the preset positive real number parameters (such as the exponential base), the weight growth rate can be flexibly controlled to meet the needs of different scenarios. Giving a higher weight to the second half of the sequence effectively alleviates the semantic fault problem caused by insufficient long-distance dependency modeling in traditional methods, and improves the logical coherence of generating long replies.
[0087] Traditional dialogue systems are usually unable to process new content input by users during the process of generating replies, resulting in the generated replies not matching the user's latest intentions. For example, in a scenario where a user quickly asks a follow-up question or corrects a question, the traditional model will continue to complete the original generation process and output a reply that is out of touch with the current conversation. In addition, the prior art lacks the ability to extract semantic fragments from unfinished replies, and directly discarding the generated content will result in information loss. Based on this, the present invention proposes an optional embodiment.
[0088] The following specific implementation is also included after step S103.
[0089] Step S201, if a reply operation is being performed and new content input by the user is detected, the reply operation is stopped, and the conversation context is updated according to the complete semantic fragment in the currently replied content, where the currently replied content is the content being replied but not completed; Step S202, returning to the step of generating a global vector corresponding to the conversation context.
[0090] In the embodiment of the present invention, during the process of generating reply content, the user input status is continuously monitored, and if new user input is detected, the currently executed reply generation operation is immediately terminated. The generated but unfinished reply content is subjected to semantic integrity analysis to identify complete semantic segments (such as complete sentences or key phrases) that conform to grammar and logic.
[0091] The extracted complete semantic fragment is merged with the new user input content to update the conversation context and form a new conversation history. Based on the updated conversation context, the global vector generation process is re-executed to ensure that subsequent replies are highly relevant to the latest conversation state.
[0092] In the embodiment of the present invention, the instant interruption mechanism is used to avoid generating redundant replies that are irrelevant to the user's new input, which significantly improves the fluency of the conversation. When dynamically updating the conversation context, the valid semantic fragments of the generated content are retained to prevent logical faults caused by interruptions, thereby ensuring the coherence of multiple rounds of conversations. The invalid generation process is terminated in time to reduce the waste of computing resources, which can effectively reduce the system load in high-concurrency scenarios.
[0093] Traditional dialogue systems usually retain all historical dialogues or adopt a simple time window truncation strategy, which leads to two problems: first, the model responds late in long dialogue scenarios because it processes too much irrelevant historical information; second, key context is incorrectly truncated (for example, when the user modifies the requirements multiple times). For example, in a medical consultation scenario, traditional methods may generate inaccurate suggestions because they do not retain early symptom descriptions. Based on this, the present invention proposes an optional embodiment.
[0094] Step S1011 also includes the following specific implementation methods.
[0095] Step S1016, if a reply operation is being performed and new content input by the user is detected, the reply operation is stopped, and the conversation context is updated according to the complete semantic fragment in the currently replied content, where the currently replied content is the content being replied but not completed; Step S1017, returning to the step of generating a global vector corresponding to the conversation context.
[0096] In an embodiment of the present invention, when it is detected that the user inputs new information, the complete conversation history record is extracted from the storage medium, including the current input and the contents of multiple rounds of interactions before it.
[0097] Based on the semantic focus of the current input information (such as keywords, intent classification results), select N consecutive rounds of dialogue that are most relevant to the current input from historical dialogues (for example, retain the most recent three rounds of dialogues) to form a streamlined dialogue context.
[0098] Based on the filtered N-round conversation context, the encoder generates a global vector that represents the core semantics of the current conversation, which serves as the basis for subsequent response generation.
[0099] In the embodiment of the present invention, by dynamically retaining N rounds of key conversations, redundant historical information interference is avoided. The problem of waste of computing power caused by processing all historical conversations in the traditional method is solved, and the computational complexity is significantly reduced while ensuring semantic coherence. The configurability of the N value supports flexible adaptation to different application requirements.
[0100] like Figure 5 , which is a schematic diagram of a terminal device provided in an embodiment of the present invention. The terminal device 500 may include: a processor 501, a memory 502, and a computer program 503 stored in the memory 502 and executable on the processor 501, such as a parallel generation program for reply texts. When the processor 501 executes the computer program 503, the steps in the above-mentioned parallel generation embodiments of reply texts are implemented.
[0101] The computer program may be divided into one or more modules / units, one or more modules / units are stored in the memory 502 and executed by the processor 501 to complete the present invention. One or more modules / units may be a series of computer program instruction segments capable of completing specific functions, and the instruction segments are used to describe the execution process of the computer program in the terminal device.
[0102] The terminal device may include, but is not limited to, a processor 501 and a memory 502. Those skilled in the art will appreciate that Figure 5It is only an example of a terminal device and does not constitute a limitation of the terminal device. It may include more or fewer components than shown in the figure, or a combination of certain components, or different components. For example, the terminal device may also include input and output devices, network access devices, buses, etc.
[0103] The processor 501 may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or any conventional processor, etc.
[0104] The memory 502 may be an internal storage unit of the terminal device, such as a hard disk or memory of the terminal device. The memory 502 may also be an external storage device of the terminal device, such as a plug-in hard disk, a smart media card (SMC), a secure digital (SD) card, a flash card, etc. equipped on the terminal device. Further, the memory 502 may also include both an internal storage unit of the terminal device and an external storage device. The memory 502 is used to store computer programs and other programs and data required by the terminal device. The memory 502 may also be used to temporarily store data that has been output or is to be output.
[0105] It should be noted that, for the convenience and brevity of description, the structure of the above-mentioned terminal device can also refer to the specific description of the structure in the method embodiment, which will not be repeated here.
[0106] An embodiment of the present invention further provides a computer-readable storage medium, which stores a computer program. When the computer program is executed by a processor, the steps in the above-mentioned parallel generation method of reply text can be implemented.
[0107] An embodiment of the present invention provides a computer program product. When the computer program product is run on a mobile terminal, the mobile terminal can implement the steps in the above-mentioned parallel generation method of reply text when executing the computer program product.
[0108] In the above embodiments, the description of each embodiment has its own emphasis. For parts that are not described or recorded in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.
[0109] Those skilled in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of the present invention.
[0110] In the embodiments provided by the present invention, it should be understood that the disclosed terminal devices and methods can be implemented in other ways. For example, the terminal device embodiments described above are only exemplary. In addition, the mutual coupling or direct coupling or communication connection shown or discussed can be an indirect coupling or communication connection through some interface, device or unit, which can be electrical, mechanical or other forms.
[0111] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0112] In addition, each functional unit in each embodiment of the present invention may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0113] If the integrated module / unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the present invention implements all or part of the processes in the above-mentioned embodiment method, and can also be completed by instructing the relevant hardware through a computer program. The computer program can be stored in a computer-readable storage medium. When the computer program is executed by the processor, the steps of the above-mentioned method embodiments can be implemented. Among them, the computer program includes computer program code, and the computer program code can be in source code form, object code form, executable file or some intermediate form. The computer-readable medium may include: any entity or device capable of carrying the computer program code, recording medium, U disk, mobile hard disk, disk, optical disk, computer memory, read-only memory (ROM), random access memory (RAM), electric carrier signal, telecommunication signal and software distribution medium. It should be noted that the content contained in the computer-readable medium can be appropriately increased or decreased according to the requirements of legislation and patent practice in the jurisdiction. For example, in some jurisdictions, according to legislation and patent practice, computer-readable media do not include electric carrier signals and telecommunication signals.
[0114] The above-described embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit them. Although the present invention has been described in detail with reference to the above-described embodiments, a person skilled in the art should understand that the technical solutions described in the above-described embodiments can still be modified, or some of the technical features can be replaced by equivalents. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention, and should be included in the protection scope of the present invention.
Claims
1. A parallel generation method for reply text, characterized in that: include: When input information is detected, a global vector corresponding to the conversation context is generated, and an initial reply sequence corresponding to the global vector is generated; Inputting the global vector and the initial reply sequence into the AG module for parallel processing to obtain multiple candidate sequences; Generate reply content according to the candidate sequence.
2. The parallel generation method of reply text according to claim 1, characterized in that: When input information is detected, a global vector corresponding to the conversation context is generated, which also includes: When input information is detected, obtaining the dialog context; Encoding each sentence in the conversation context by a bidirectional gated recurrent unit to obtain a speech feature vector, and assigning a continuous position number to each sentence to obtain a position number; According to each of the position numbers, the position embedding PE of each position is calculated by alternating sine waves and cosine waves; Concatenate each of the position embedding PEs with each of the utterance feature vectors to obtain a context representation including the conversation sequence; According to each of the context representations, the global vector corresponding to the conversation context is generated.
3. The parallel generation method of reply text according to claim 2, characterized in that: The step of generating the global vector corresponding to the conversation context according to each of the context representations comprises: Each of the concatenated context representations is input into a multi-head self-attention module to generate the global vector corresponding to the conversation context containing global semantic information.
4. The parallel generation method of reply text according to claim 1, characterized in that: The step of inputting the global vector and the initial reply sequence into the AG module for parallel processing to obtain multiple candidate sequences comprises: Calculating the degree of association between the initial reply sequence and the global vector to obtain an intermediate result of fusing context information; Inputting the intermediate result into a recurrent neural network unit with a memory function to obtain a hidden representation of the word to be generated; According to the hidden representation, calculating the generation probability of each candidate word to form a candidate word list sorted by probability; According to the candidate word list, a plurality of candidate sequences are generated.
5. The parallel generation method of reply text according to claim 1, characterized in that: The step of generating reply content according to the candidate sequence comprises: Assigning a gradually increasing weight value to each unit in the candidate word list; The word probability corresponding to each unit in the candidate word list is multiplied by the weight value corresponding to each unit and then added up to obtain a plurality of comprehensive probabilities; A plurality of candidate sequences are selected according to a plurality of the comprehensive probabilities.
6. The parallel generation method of reply text according to claim 5, characterized in that: The step of assigning a gradually increasing weight value to each unit in the candidate word list comprises: According to the position index of each unit in the candidate word list and a preset positive real number parameter, an initial weight value is calculated by an exponential function, and the larger the position index is, the larger the corresponding initial weight value increases; Each initial weight value is divided by the sum of all initial weight values to obtain a weight value corresponding to each of the units.
7. The parallel generation method of reply text according to claim 1, characterized in that: After the step of generating reply content according to the candidate sequence, the method further includes: If a reply operation is being performed and new content input by the user is detected, the reply operation is stopped, and the conversation context is updated according to the complete semantic fragment in the currently replied content, where the currently replied content is the content being replied but not completed; Return to the step of executing to generate the global vector corresponding to the conversation context.
8. The parallel generation method of reply text according to claim 1, characterized in that: When the input information is detected, the step of generating a global vector corresponding to the dialogue context includes: When input information is detected, the historical conversation context is obtained; According to the input information, retaining N rounds of dialogue in the historical dialogue context as the dialogue context; Generate the global vector corresponding to the conversation context.
9. A terminal device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of the parallel generation method of reply texts as claimed in any one of claims 1 to 8 when executing the computer program.
10. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the steps of the parallel generation method of reply texts as claimed in any one of claims 1 to 8 are implemented.
Citation Information
Patent Citations
Method and device for generating reply statements for multiple rounds of conversations
CN111400481A
Deep learning-based task type dialogue statement reply generation method and storage medium
CN114358021A
Intelligent dialogue method and system
CN114860910A
Cited By
Expert clustering method and system for cooperation among multiple models
CN121809549A
A method and system for expert cluster collaboration among multiple models
CN121809549B