Dialogue reply generation method, related device and computer program product
Patent Information
- Application Number
- CN202611189250.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-08-06
- Publication Date
- 2026-10-13
AI Technical Summary
由此,当用户情绪在多轮会话过程中发生变化,或者不同用户虽然具有相近的情绪状态,但在认知水平、表达习惯和交流偏好等方面存在差异时,现有对话系统仍可能采用相同或相近的语言策略,难以对回复文本的词汇选取、句式结构和表达语气等进行细粒度的适应性调节,导致回复文本与用户当前的实际交流需求不匹配,从而影响对话的连贯性和用户的交互体验
[0048]借由上述技术方案,本申请提供的对话回复生成方法,首先,至少基于当前对话轮次中的用户输入文本,确定目标用户在当前对话轮次的用户画像特征,以实时感知用户的个性化表达需求。进一步地,将用户输入文本和用户画像特征输入大语言模型中,以得到当前对话轮次对于用户输入文本的回复内容。
Smart Images

Figure CN122903567A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of natural language processing technology, and more specifically, to a dialogue response generation method, related equipment, and computer program product. Background Technology
[0002] With the development of natural language processing technology, automated dialogue systems have been widely applied in various human-computer interaction scenarios such as intelligent customer service, information consultation, and virtual assistants. Most mainstream automated dialogue systems currently rely on the user's input in the current round of dialogue and existing conversation content to generate corresponding responses, achieving continuous human-computer interaction. However, in practical applications, dialogue interactions exhibit significant individual differences. For example, different users may have different language expression habits, communication preferences, and current emotional states, or the same user's needs regarding tone, wording difficulty, empathy, and expression may change at different stages of the dialogue.
[0003] To adapt to users' personalized expression needs, existing dialogue systems typically adjust the style of responses based on pre-configured style instructions, fixed-trained style models, or style adapters with limited categories. However, these response generation methods mainly rely on preset discrete style configurations or statically trained style parameters, achieving only coarse-grained style intervention at the input instruction or model parameter level. Consequently, when users' emotions change during multiple rounds of conversation, or when different users, despite having similar emotional states, differ in cognitive levels, expression habits, and communication preferences, existing dialogue systems may still employ the same or similar language strategies. This makes it difficult to make fine-grained adaptive adjustments to the vocabulary selection, sentence structure, and tone of the response text, resulting in a mismatch between the response text and the user's current actual communication needs, thus affecting the coherence of the dialogue and the user's interactive experience. Summary of the Invention
[0004] In view of the above problems, this application is proposed to provide a dialogue response generation method, related equipment, and computer program products to improve the matching degree between the response text and the user's current actual personalized expression needs. The specific solution is as follows:
[0005] Firstly, this application provides a method for generating dialogue responses, including:
[0006] Obtain the user input text of the target user in the current conversation round;
[0007] Based at least on the user input text, determine the user profile features of the target user in the current conversation round;
[0008] The user profile features are mapped to the activation space of the large language model through the configured style mapping module to obtain the mapped personalized style guidance vector. The personalized style guidance vector is used to represent the guidance direction of the language style that matches the user profile features in the activation space of the large language model.
[0009] The user input text is input into a pre-configured large language model. During the inference process of the large language model, the personalized style guidance vector is injected into the original intermediate activation vector of at least one target network layer in the large language model to obtain the guided intermediate activation vector. Based on the guided intermediate activation vector, the calculation of the downstream network layer is continued to generate the response text.
[0010] In one possible implementation, in another implementation of the first aspect of this application, the process of mapping the user profile features to the activation space of a large language model to obtain the mapped personalized style guidance vector includes:
[0011] Obtain style guidance reference vectors corresponding to multiple pre-configured style dimensions, wherein the style guidance reference vectors represent the reference guidance direction of the corresponding style dimension in the activation space of the large language model;
[0012] The user profile features are mapped to style injection coefficients corresponding to each style dimension using a pre-trained mapping matrix. The style injection coefficients are used to characterize the degree of matching between the corresponding style dimension and the language style adapted to the user profile features.
[0013] Based on the style injection coefficients, the style guidance benchmark vectors corresponding to each style dimension are weighted and fused to obtain the personalized style guidance vector.
[0014] In one possible implementation, in another implementation of the first aspect of the embodiments of this application, the process of injecting the personalized style guidance vector into the original intermediate activation vector of at least one target network layer in the large language model to obtain the guided intermediate activation vector includes:
[0015] For each target network layer and each decoding position within each target network layer, based on the style tendency reflected in the internal generation state of the current decoding position in the current target network layer and the degree of matching between it and the target style control requirements carried by the system prompt information, a gating coefficient corresponding to the current decoding position is determined. The gating coefficient is used to characterize the injection strength of the personalized style guidance vector at the current decoding position. The gating coefficient is positively correlated with the degree of matching.
[0016] The intensity of the personalized style guidance vector is adjusted based on the gating coefficient, and the adjusted personalized style guidance vector is superimposed on the original intermediate activation vector generated by the target network layer at the current decoding position to obtain the guided intermediate activation vector of the target network layer at the current decoding position.
[0017] In one possible implementation, in another implementation of the first aspect of this application, the process of determining the degree of matching between the style tendency reflected in the internal generation state of the current decoding position in the current target network layer and the target style control requirements carried by the system prompt information includes:
[0018] Determine the set of system prompt word positions corresponding to the system prompt information in the context word sequence of the large language model;
[0019] Within the set of system prompt word positions, each system prompt word is represented as a key vector within the layer corresponding to the current target network layer. The system prompt word is a text description word used to represent the target style requirement.
[0020] Aggregate the key vectors corresponding to each system prompt word, and use the aggregated vector as the target key vector;
[0021] The current decoding position is represented within the current target network layer as a query vector;
[0022] The matching degree between the query vector and the target key vector is calculated to obtain the matching degree.
[0023] In one possible implementation, in another implementation of the first aspect of the embodiments of this application, the method further includes:
[0024] Based on the guided intermediate activation vector, a first parameter is determined for the current decoding position, wherein the first parameter is used to characterize the stability of the predicted distribution of the current decoding position;
[0025] If the first parameter satisfies the preset stable prediction condition, the guided intermediate activation vector is used as the activation vector for continuing to advance the calculation of the downstream network layer.
[0026] If the first parameter does not meet the preset stable prediction condition, the influence strength of the personalized style guidance vector at the current decoding position is reduced according to the preset attenuation factor to obtain the attenuated personalized style guidance vector; based on the attenuated personalized style guidance vector, the guidance intermediate activation vector at the current decoding position is regenerated, and the corresponding first parameter is recalculated until the recalculated first parameter meets the preset stable prediction condition, and the regenerated guidance intermediate activation vector is used as the activation vector for continuing to advance the calculation of the downstream network layer.
[0027] In one possible implementation, in another implementation of the first aspect of the embodiments of this application, the method further includes:
[0028] If the number of times the personalized style guiding vector is decayed reaches a preset upper limit, and the recalculated first parameter does not meet the preset stable prediction condition, the influence strength of the personalized style guiding vector at the current decoding position is adjusted to a preset minimum injection strength. Based on the adjusted personalized style guiding vector, the guided intermediate activation vector at the current decoding position is regenerated and used as the activation vector for continuing to advance the calculation of the downstream network layer.
[0029] In one possible implementation, in another implementation of the first aspect of the embodiments of this application, the process of pre-configuring style-guided baseline vectors corresponding to multiple style dimensions includes:
[0030] For each style dimension, obtain the positive style sample and the negative style sample corresponding to the style dimension, wherein the positive style sample has a higher performance degree in the style dimension than the negative style sample;
[0031] The positive style sample and the negative style sample are respectively input into the large language model to obtain the activation vectors of the positive style sample and the negative style sample in the middle of the sample of the target network layer;
[0032] Based on the activation difference between the intermediate activation vectors of the positive style samples and the negative style samples, the style guidance reference vector corresponding to the style dimension in the activation space of the large language model is determined.
[0033] In one possible implementation, in another implementation of the first aspect of the embodiments of this application, the method further includes:
[0034] The response text is subject to security constraint verification.
[0035] If the response text meets the preset security constraints, the response text is output.
[0036] If the response text does not meet the preset security constraints, the crisis type corresponding to the response text is determined, and based on the intervention method corresponding to the crisis type, the large language model is triggered to regenerate the response text, and the security constraints are verified on the regenerated response text until the preset convergence condition is met.
[0037] In one possible implementation, in another implementation of the first aspect of the embodiments of this application, the process of determining the user profile features of the target user in the current dialogue round based at least on the user input text includes:
[0038] Obtain the user registration information of the target user;
[0039] Based on the user registration information, extract the identity background features of the target user;
[0040] Based at least on the user input text, extract the target user's language style features and real-time emotional state features;
[0041] The user profile features are obtained by fusing the identity background features, the language style features, and the real-time emotional state features.
[0042] In one possible implementation, in another implementation of the first aspect of the embodiments of this application, the method further includes:
[0043] After the current dialogue round of the target user ends, the dialogue quality is determined, and the fusion weights corresponding to the identity background feature, the language style feature and the real-time emotional state feature are updated with the goal of minimizing the loss of dialogue quality.
[0044] In subsequent dialogue rounds with the target user, the user profile features corresponding to the target user are determined based on the updated fusion weights.
[0045] Secondly, this application provides an electronic device, including: a memory and a processor;
[0046] The memory is used to store programs;
[0047] The processor is configured to execute the program to implement the dialogue response generation method described in any of the first aspects of this application.
[0048] Using the above technical solution, the dialogue response generation method provided in this application firstly determines the user profile features of the target user in the current dialogue round, based at least on the user input text in the current dialogue round, in order to perceive the user's personalized expression needs in real time. Further, the user input text and user profile features are input into a large language model to obtain the response content for the user input text in the current dialogue round.
[0049] In the inference process of the large language model, a personalized style guidance vector is first determined based on user profile features. This determines the guidance direction of the language style that matches the user profile features in the activation space of the large language model, allowing the language style adjustment direction in the response generation process to adapt to the current personalized expression needs of the user. Subsequently, in the process of the large language model predicting and generating response text based on user input text, the personalized style guidance vector is injected into the intermediate activation vector of at least one target network layer. This provides directional guidance to the generation logic at the representation level within the model, enabling the generation process to be specifically adjusted according to the language style direction corresponding to the user's personalized expression needs, resulting in a guided intermediate activation vector that tends to adapt to the user's personalized expression needs. Downstream network layer calculations continue based on the guided intermediate activation vector, allowing the style guidance effect to be passed layer by layer with the forward calculation, continuously covering the complete derivation chain of subsequent content generation, and further influencing the generation of the final response text.
[0050] Therefore, this application establishes a targeted control path for the generation logic within the model based on users' personalized needs, so that the activated content of the large language model activation space tends to meet the user's personalized expression needs, thereby improving the matching degree between the language style of the final generated response text and the user's current personalized expression needs, and thus enhancing the adaptability and interactive experience of the dialogue response. Attached Figure Description
[0051] Various other advantages and benefits will become apparent to those skilled in the art upon reading the following detailed description of preferred embodiments. The accompanying drawings are for illustrative purposes only and are not intended to limit the scope of this application. Furthermore, the same reference numerals denote the same parts throughout the drawings. In the drawings:
[0052] Figure 1 A schematic diagram of an implementation system architecture for the dialogue response generation method provided in this application embodiment;
[0053] Figure 2 This is a schematic flowchart of a dialogue response generation method provided in an embodiment of this application;
[0054] Figure 3 A dialogue example diagram provided for an embodiment of this application;
[0055] Figure 4 A schematic diagram of the system architecture for another dialogue response generation method provided in this application embodiment;
[0056] Figure 5 This is a schematic diagram of a user profile feature extraction process provided in an embodiment of this application;
[0057] Figure 6 A schematic diagram of a personalized style guidance vector injection process provided in this application embodiment;
[0058] Figure 7 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Detailed Implementation
[0059] 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, and 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.
[0060] It is understood that before using the technical solutions disclosed in the various embodiments of this application, users should be informed of the types, scope of use, and usage scenarios of the personal information involved in this disclosure in an appropriate manner in accordance with relevant laws and regulations, and user authorization should be obtained.
[0061] The embodiments of this application relate to the technical fields of natural language processing, human-computer interaction, and large language models, and can be applied to automatic dialogue systems built on large language models, such as intelligent customer service, information consultation, virtual assistants, online education, and mental health auxiliary dialogue systems, which require human-computer dialogue.
[0062] In the aforementioned application scenarios, existing dialogue systems mostly adjust response styles through preset style instructions, fixed style models, or style adapters of limited categories. These methods primarily rely on discrete configurations or static parameters, making it difficult to fine-tune the vocabulary, sentence structure, and tone of the response text in response to changes in the user's emotions, cognitive level, and expression habits. This results in a mismatch between the response content and the user's current actual communication needs.
[0063] To address the aforementioned issues, this application proposes a different approach. Instead of adjusting the response language style solely at the input prompt or model parameter level, it applies directional guidance to the intermediate activation states within the large language model during the inference process of generating the response text. Specifically, the style guidance direction corresponding to different language styles in the large language model's activation space can be pre-determined. During the forward computation of the large language model, this style guidance direction is applied to the intermediate activation vectors generated by at least one network layer, causing the model's internal representations to shift along the direction corresponding to the target language style. Since this method directly affects the internal representations during the model's inference process, it eliminates the need to retrain the entire large language model for each language style, while still allowing for relatively fine-grained influence on the vocabulary selection, sentence structure, and tone of the response text.
[0064] However, simply injecting a predetermined style guidance direction into the activation space of a large language model is insufficient to directly address the issue of personalized adaptation of response language style. Specifically, if different users or different dialogue rounds use the same style guidance direction and injection intensity, multi-dimensional features such as the user's age, occupation, educational background, language expression habits, and real-time emotional state cannot effectively participate in the adjustment of the generated state within the model. This results in different users potentially acquiring the same or similar language strategies. Therefore, while the activation space guidance method described in the original concept can alter the language style of the response text to some extent, it is still difficult to make the style adjustment direction change in real time according to the user's current profile and dialogue state. Ultimately, the generated response text may still not match the user's actual communication needs.
[0065] Based on the actual needs in the above application scenarios, this application provides a dialogue response generation method. The dialogue response generation method of this application embodiment will be described in detail below with reference to the accompanying drawings.
[0066] See Figure 1 , Figure 1 A schematic diagram of a system architecture is shown. The system may include a terminal 100 and a server 200, wherein the server 200 may include one or more servers (…). Figure 1 (This example uses a server as an illustration).
[0067] Either terminal 100 or server 200 can be used independently to execute the dialogue response generation method provided in the embodiments of this application. Alternatively, terminal 100 and server 200 can also be used collaboratively to execute the dialogue response generation method provided in the embodiments of this application.
[0068] In this application embodiment, the terminal 100 can be a mobile phone, tablet computer, learning machine, teaching large screen, wearable device, vehicle-mounted device, conference terminal, augmented reality (AR) / virtual reality (VR) device, laptop computer, ultra-mobile personal computer (UMPC), netbook, personal digital assistant (PDA), etc., and this application embodiment does not impose any restrictions on it.
[0069] This application provides a method for generating dialogue responses. Taking the application of this method to a computer device as an example, the computer device can specifically be... Figure 1 The system consists of terminal 100 or a combination of terminal 100 and server 200. (Refer to...) Figure 2 The present application provides a flowchart of a dialogue response generation method, which may include steps S110 to S140, and these steps are described in detail below.
[0070] Step S110: Obtain the user input text of the target user in the current dialogue round.
[0071] This step obtains the input boundary for generating personalized responses from the continuous human-computer interaction data stream, and converts the user's expression within this input boundary into text data as the user's input text. Based on this, this embodiment of the application, by clearly defining the input object corresponding to each dialogue turn, can avoid confusion between the expression content of different users, different responses, or different dialogue turns, thereby providing an accurate data foundation for generating response text adapted to the current user state.
[0072] Input boundaries are used to distinguish user expressions in different rounds and can be determined by user-triggered sending operations, input termination commands, preset silence durations, semantic integrity checks, or other round termination conditions. The current dialogue round can be understood as the interaction cycle in a session from the receipt of an input from the target user to the generation and output of the corresponding response text by the dialogue system. A session can include one or multiple dialogue rounds occurring sequentially. Dialogue rounds can share the session context, but each dialogue round has its own corresponding user input text and response text.
[0073] Specifically, text input by the target user can be received directly from the user terminal, or it can be read from other business modules, message queues, session servers, or input conversion modules. See also Figure 3In one exemplary application scenario, the target user creates a conversation window through an AI psychological assistant running on the terminal and submits text content in the conversation window. After detecting that the user has triggered a send operation, the terminal obtains the text content and identifies it as the user input text for the current conversation turn. Optionally, if the target user interacts with the AI psychological assistant via voice, the speech recognition module can convert the speech content into text and use the converted text as the user input text.
[0074] Step S120: Determine the user profile features of the target user in the current dialogue round, based at least on the user's input text.
[0075] This step analyzes the user input text in the current dialogue turn, converting information related to the user's expression and the matching of the response's language style into feature data that can be processed by a large language model. This serves as the user profile feature for the target user in the current dialogue turn. The user profile feature characterizes the personalized communication state exhibited by the target user in the current dialogue turn. It can describe the target user's fixed identity attributes as well as reflect dynamic information such as the user's language expression habits and communication preferences, updating as the target user's input content and the progress of the dialogue change.
[0076] Optionally, user profile features can be obtained by inputting user input text into a pre-configured feature extraction model. Furthermore, if authorization from the target user can be obtained, the features obtained based on user input text can be supplemented by combining user registration information, current session context, or other auxiliary information related to the current interaction, so as to improve the completeness of the user profile features in representing the target user's current actual communication needs.
[0077] It is understood that by converting user expressions in natural language form into structured or vectorized user profile features, the embodiments of this application can make the current personalized communication state of the target user a control basis that can be directly read and processed in the subsequent style adjustment process, avoiding the failure to reflect the current dialogue state due to the long-term use of fixed user labels, thereby improving the adaptability between the subsequent language style adjustment and the current actual communication needs of the target user.
[0078] Step S130: Using the configured style mapping module, the user profile features are mapped to the activation space of the large language model to obtain the mapped personalized style guidance vector. The personalized style guidance vector represents the guidance direction of the language style that matches the user profile features in the activation space of the large language model.
[0079] This application embodiment can pre-establish the feature transformation relationship between user profile features and the internal generation state of a large language model, converting the user profile features describing the current communication state of the target user into personalized style guidance vectors that can be applied to the internal computation process of the large language model. The activation space of the large language model can be understood as the high-dimensional numerical space used by each network layer to represent the input content and the current generation state during inference computation. The personalized style guidance vector is located in the activation space adapted to the target network layer and is used to characterize the internal representation adjustment direction corresponding to the language style adapted to the current user profile features.
[0080] Optionally, user profile features can be processed using a pre-configured feature transformation network. This network directly outputs a personalized style guidance vector that matches the hidden dimensions of the target network layer based on the user profile features. Alternatively, a mapping relationship between the user profile feature space and the activation space can be pre-defined. After acquiring the current user profile features, the corresponding activation space position or direction can be determined based on this mapping relationship, and a personalized style guidance vector can be generated accordingly. The specific implementation scheme of this step can be flexibly adapted and modified according to the actual business scenario, and this application does not impose a unique limitation on it.
[0081] Based on the above processing, this embodiment of the application uses a style mapping module to convert the personalized state representation on the user side into an executable internal control signal on the model side, solving the problem that user profile features cannot directly adjust the intermediate activation state of a large language model. Since the personalized style guidance vector is determined based on the user profile features of the current dialogue turn, the style guidance direction within the model can change accordingly with the target user's current personalized communication state, thus ensuring that the response text generated during subsequent model inference can also be adapted to the target user's communication needs.
[0082] In step S140, the user input text is input into a pre-configured large language model. During the inference process of the large language model, a personalized style guidance vector is injected into the original intermediate activation vector of at least one target network layer in the large language model to obtain a guided intermediate activation vector. Based on the guided intermediate activation vector, the calculation of the downstream network layer is continued to generate the response text.
[0083] Specifically, the user input text can be first fed into a large language model, which then sequentially executes inference calculations for each network layer. When the inference process reaches the target network layer, the original intermediate activation vector generated by the target network layer is obtained. The personalized style guidance vector is then fused with the original intermediate activation vector to obtain the guided intermediate activation vector. This guided intermediate activation vector is then used as the output of the target network layer and input into subsequent network layers to drive the calculations of downstream network layers, until the output layer of the large language model outputs the response text corresponding to the current dialogue turn.
[0084] In one possible implementation, the personalized style-guided vector can be superimposed as an additional offset onto the original intermediate activation vector, causing the original intermediate activation vector to shift along the personalized style-guided direction in the activation space. In another optional implementation, transformation parameters can be generated based on the personalized style-guided vector to adjust the original intermediate activation vector, and these transformation parameters can be used to adjust different feature components in the original intermediate activation vector. Both of these methods can introduce style control information adapted to user profile features while preserving the semantic information carried by the original intermediate activation vector. The specific implementation can be flexibly adapted and modified according to the actual business scenario.
[0085] The target network layer is the internal network layer in the large language model selected to receive personalized style guidance vectors. It can be a single network layer or multiple network layers selected according to a preset configuration. The original intermediate activation vector is the output result generated by the target network layer after performing normal inference calculations based on the user input text and existing context, and has not yet been affected by the current personalized style guidance vector. The guided intermediate activation vector is the new output result formed after applying the personalized style guidance vector to the original intermediate activation vector. The downstream network layer is the network structure that follows the corresponding target network layer in the calculation order, and is used to continue feature transformation and word prediction based on the guided intermediate activation vector.
[0086] Understandably, during the process of generating response text based on user input text in the large language model, the personalized style guidance vector obtained in step S130 is applied to the original intermediate output results within the large language model. This directly adjusts the model's internal representation, allowing subsequent text generation to maintain the original semantics of the user input text and the relevance of the response content while adjusting the language style to match the user's profile features. Since the adjusted intermediate activation states continue to participate in the calculation of downstream network layers, the personalized style guidance information can be passed layer by layer along the model's inference path, ultimately reflecting in the vocabulary selection, sentence structure, and tone of the response text. Therefore, without needing to train separate large language models for different users, the same large language model can be used to form differentiated internal generation states based on the profile features of different users and the same user in different dialogue rounds, thereby improving the matching degree between the language style of the response text and the target user's current actual communication needs.
[0087] In summary, the dialogue response generation method provided in this application firstly determines the user profile features of the target user in the current dialogue round, based at least on the user input text, to perceive the user's personalized expression needs in real time. Furthermore, the user input text and user profile features are input into a large language model to obtain the response content for the user input text in the current dialogue round.
[0088] In the inference process of the large language model, a personalized style guidance vector is first determined based on user profile features. This determines the guidance direction of the language style that matches the user profile features in the activation space of the large language model, allowing the language style adjustment direction in the response generation process to adapt to the current personalized expression needs of the user. Subsequently, in the process of the large language model predicting and generating response text based on user input text, the personalized style guidance vector is injected into the intermediate activation vector of at least one target network layer. This provides directional guidance to the generation logic at the representation level within the model, enabling the generation process to be specifically adjusted according to the language style direction corresponding to the user's personalized expression needs, resulting in a guided intermediate activation vector that tends to adapt to the user's personalized expression needs. Downstream network layer calculations continue based on the guided intermediate activation vector, allowing the style guidance effect to be passed layer by layer with the forward calculation, continuously covering the complete derivation chain of subsequent content generation, and further influencing the generation of the final response text.
[0089] Therefore, this application establishes a targeted control path for the generation logic within the model based on users' personalized needs, so that the activated content of the large language model activation space tends to meet the user's personalized expression needs, thereby improving the matching degree between the language style of the final generated response text and the user's current personalized expression needs, and thus enhancing the adaptability and interactive experience of the dialogue response.
[0090] Next, refer to Figure 4 The flowchart shown below illustrates another implementation of the dialogue response method. Further details on other possible implementations of the dialogue response generation method provided in this application will be provided in conjunction with the embodiments below.
[0091] Reference Figure 4 In the reasoning stage of generating response text, the user input text of the target user in the current dialogue round is first obtained; then, the user profile perception module can execute step S120 to determine the user profile features of the target user in the current dialogue round, based at least on the user input text.
[0092] In one possible implementation, step S120 may include: obtaining the user registration information of the target user; extracting the target user's identity background features based on the user registration information; extracting the target user's language style features and real-time emotional state features based at least on the user's input text; and fusing the identity background features, language style features, and real-time emotional state features to obtain user profile features.
[0093] by Figure 5 Taking the user profile feature extraction process shown below as an example, this process will be illustrated. First, the user registration information of the target user is obtained. User registration information can be information submitted by the target user when creating an account, using the AI psychological assistant for the first time, or completing their personal profile, such as age_group, occupation type, education level, etc. Since different registration fields usually use different data formats, each registration field can be quantified or embedded and encoded separately, and the encoding results can be combined to obtain the identity background feature v. bg =[E_age[a],E_occ[o],E_edu[e]]. This identity background feature is mainly used to reflect the relatively stable background differences of the target user over a long period of time, so that the subsequent generated responses can be adapted to the target user in terms of word difficulty, knowledge explanation depth and expression style.
[0094] Furthermore, language style features v are extracted from the user input text in the current dialogue turn. style_user Language style features can include one or more characteristics of the user-input text, such as lexical difficulty, sentence length, sentence complexity, information density, colloquialism, directness of expression, and punctuation usage. These features can be determined through textual statistical methods or by encoding the user-input text using a pre-configured language feature extraction model. Since the expression style of the same target user may change in different dialogue rounds, language style features can be re-extracted for each dialogue round to reflect the target user's current actual language expression habits.
[0095] Simultaneously, real-time emotional state features v can be determined based on user-input text. emotionOptionally, with the target user's authorization, feature extraction and fusion analysis can be performed on multimodal data such as user voice and video to determine the target user's real-time emotional state characteristics in the current dialogue turn. For example, user input text can be fed into the BERT-tiny emotion classifier to identify emotion categories, and emotion categories such as anxiety, depression, and calmness can be represented as discrete labels, confidence sets, or probability distributions; continuous parameters such as emotion intensity, emotion polarity, and degree of emotion fluctuation can also be extracted as real-time emotional state features. Real-time emotional state features mainly reflect the target user's immediate emotional changes in the current dialogue turn, and their update frequency is usually higher than that of identity background features.
[0096] After obtaining the identity background features, language style features, and real-time emotional state features, we can first perform dimensional alignment and numerical normalization on the three types of features, and then input them. Figure 5 The attention fusion layer is shown. This layer assigns corresponding fusion weights to different features based on their correlation with the current response generation task, and performs weighted fusion of the three types of features to obtain the user profile feature v. profile In other possible implementations, user profile features can also be obtained by vector concatenation, weighted summation, or hierarchical fusion.
[0097] Therefore, this application's embodiments extract user features from three different sources and time scales: relatively stable identity background, language style that changes with the mode of expression, and emotional state that changes in real time with the current conversation. This makes user profile features no longer determined by a single user label or a single emotion classification result, but can comprehensively represent the background differences, expression habits, and current interaction state of the target user, providing a diverse feature foundation for the subsequent generation of more targeted personalized style guidance vectors.
[0098] In some embodiments, to enable user profile features to adaptively change with the actual interactive feedback of the target user, the fusion weights corresponding to identity background features, language style features, and real-time emotional state features can be adjusted after each round of dialogue. For example... Figure 5 As shown, after the current dialogue round ends, the dialogue quality signal reflecting the interaction effect of this round is fed back to the attention fusion layer to drive the fusion weights to be updated adaptively.
[0099] Specifically, the adaptive update process may include: after the current dialogue round of the target user ends, determining the dialogue quality, and updating the fusion weights corresponding to the identity background features, language style features, and real-time emotional state features with the goal of minimizing the dialogue quality loss; in the subsequent dialogue rounds of the target user, determining the user profile features corresponding to the target user based on the updated fusion weights.
[0100] It can acquire dialogue behavior signals such as conversation continuation status, active interruption status, and explicit satisfaction rating corresponding to the current dialogue round, and quantify and fuse these signals to obtain the dialogue quality r. t For example, the evaluation value for continuing the conversation can be set to 1.0, the evaluation value for actively ending the conversation can be set to 0.2, and the satisfaction score can be normalized to the [0,1] interval. Furthermore, it can be done according to... The reverse mapping relationship determines the dialogue quality loss L corresponding to the current dialogue round. t The lower the dialogue quality, the greater the corresponding loss in dialogue quality, indicating that there may be a significant discrepancy between the user profile features generated under the current fusion weights and the actual communication needs of the target users.
[0101] After obtaining the dialogue quality loss, the gradient of the dialogue quality loss relative to the attention fusion layer parameters is calculated with the optimization objective of reducing the dialogue quality loss. Based on this gradient, the fusion weights corresponding to identity background features, language style features, and real-time emotional state features are updated. For example, when a user's emotion has changed significantly, but the current response still mainly relies on their stable background information for language style control, the fusion weight of the real-time emotional state feature can be increased through feedback updates. When the target user's emotional state is relatively stable, but their expression habits have a greater impact on the response effect, the fusion weight of the language style feature can be increased. Thus, the contribution of the three types of features can dynamically change with actual interaction feedback, rather than remaining fixed in the long term.
[0102] In one alternative implementation, the Adam optimizer can be used to perform single-step gradient updates on the attention fusion layer parameters, with a learning rate set to 0.001 and two momentum parameters set to 0.9 and 0.999, respectively. To avoid abrupt changes in fusion weights caused by anomalous feedback in a single round, the update gradient can be pruned, for example, by limiting the maximum norm of the gradient to 1.0, so that user profile features evolve smoothly between adjacent dialogue rounds.
[0103] After the target user enters subsequent dialogue rounds, the attention fusion layer re-integrates identity background features, language style features, and real-time emotional state features based on adjusted fusion weights to obtain updated user profile features. Therefore, user profile features are no longer determined solely by the current input text, but can be continuously adjusted based on the actual quality feedback from historical dialogues to refine the relative contributions of various features. This allows subsequently generated user profile features to gradually approach the target user's actual communication preferences and reduces the dialogue quality loss in subsequent dialogue rounds.
[0104] Optionally, after a complete session ends, the session profile features v generated from the current session can also be used to... profile_session Write a long-term portrait v profile_long And update according to the following formula:
[0105] (1)
[0106] in, The adaptive forgetting coefficient can take values in the range [0.7, 1.0], for example, set to 0.9. When the target user's historical profile and emotional state are relatively stable, the coefficient can be increased. This reduces the impact of a single session on long-term user profiles. When the characteristics of a target user fluctuate significantly across different sessions, it can be reduced... This allows long-term user profiles to adapt to recent changes more quickly. Optionally, it can also automatically adjust based on the degree of fluctuation in historical user profile characteristics. For new users who haven't yet developed historical user profile features, a neutral long-term profile can be initialized. For example, the style injection coefficients obtained after style mapping of this profile can be set to neutral values. After the initial conversation, the profile can then be switched to user profile features based on actual dialogue data. In this way, the fusion weights can be adjusted based on real-time feedback within the conversation, and the user profile can gradually accumulate and evolve across conversations, thereby reducing the loss of dialogue quality in subsequent rounds.
[0107] Reference Figure 4 After obtaining user profile features through the user profile perception module, the user profile features can be mapped to the activation space of the large language model through the style mapping module to obtain a personalized style guidance vector that guides the large language model to generate response text that adapts to the user's personalized expression needs.
[0108] In one possible implementation, the process of mapping user profile features to the activation space of a large language model to obtain the mapped personalized style guidance vector may include: obtaining pre-configured style guidance reference vectors corresponding to multiple style dimensions, whereby the style guidance reference vectors represent the reference guidance direction of the corresponding style dimension in the activation space of the large language model; mapping user profile features to style injection coefficients corresponding to each style dimension using a pre-trained mapping matrix, whereby the style injection coefficients represent the degree of matching between the corresponding style dimension and the language style adapted to the user profile features; and weighted fusion of the style guidance reference vectors corresponding to each style dimension based on each style injection coefficient to obtain the personalized style guidance vector.
[0109] During the inference phase, user profile features are input into the style mapping module. The style mapping module can include linear mapping layers or a mapping network consisting of one or more fully connected layers, configured with a pre-trained mapping matrix W. It should be noted that the mapping matrix W can be pre-trained through a joint training link between the style mapping module and the large language model, or even the aforementioned user profile awareness module.
[0110] Specifically, during the training phase, the style mapping module can be integrated into the intermediate activation processing loop of the large language model. The style mapping module generates style injection coefficients based on the user profile features corresponding to the training samples, and forms personalized style guidance vectors accordingly. These personalized style guidance vectors are then injected into the target network layer of the large language model. The large language model generates training responses based on the injected intermediate activation vectors, and then determines the training loss based on the difference between the generated results and the target responses corresponding to the training samples. This training loss is then backpropagated along the computational loop of the large language model to the style mapping module to update the mapping matrix W. The dimension D×K of the mapping matrix W is determined by the user profile features v. profile The dimension D and the number K of preset style dimensions are determined. For example, the v output by the C1 user profile perception module... profile ∈R 256 If there are 8 different style dimensions, then the mapping matrix W∈R 256×8 .
[0111] Furthermore, during the inference phase, the style mapping module can determine the style injection coefficients according to the following equation (2). ,in, This represents the style injection coefficient corresponding to the i-th style dimension.
[0112] (2)
[0113] It is understandable that, since the range of values for the style injection coefficients calculated based on the mapping matrix W is unrestricted, the magnitudes of the coefficients corresponding to different style dimensions may vary significantly, and negative or excessively large coefficient values may occur. This not only makes it difficult to uniformly represent the degree of matching between each style dimension and the language style adapted to the current user profile, but may also lead to the guiding effect of some style dimensions being too weak or too strong, causing unstable changes in the direction and amplitude of subsequent personalized style guidance vectors, thereby increasing the risk of excessive interference with the original generation logic of the large language model. In response, this application embodiment calculates the style injection coefficients using equation (2). Then, using these as the original coefficients, the original coefficients are normalized using Sigmoid, referring to the following formula (3), and the normalization result is multiplied by the preset upper limit of injection intensity C. base This yields the style injection coefficients corresponding to each style dimension.
[0114] (3)
[0115] After the above processing, the injection coefficients for each style are... Smoothly confined to [0, C baseWithin this range, the relative differences in matching degree between different style dimensions and user profile features can be preserved, while the value scale of each style injection coefficient can be unified, and excessive style guidance caused by abnormally large coefficients can be suppressed by the upper limit of injection intensity. As a result, the effect intensity corresponding to each style dimension can be made more stable and controllable, which facilitates the subsequent weighted fusion of multiple style guidance benchmark vectors and achieves a balance between the degree of personalized style adaptation and the semantic stability of the response content.
[0116] Furthermore, obtain the style guidance benchmark vectors corresponding to multiple pre-set style dimensions, and refer to the following formula (4) to perform weighted fusion of the multiple style dimension benchmark guidance vectors according to the style injection coefficients corresponding to each style dimension, so as to obtain the personalized style guidance vector.
[0117] (4)
[0118] in, Let represent the style-guided baseline vector for the i-th style dimension. This represents the personalized style guidance vector corresponding to the current dialogue turn. Through the above processing, user profile features can be converted into continuous style control directions in the activation space of a large language model. This allows multiple style dimensions to collaboratively participate in response generation according to different levels of influence, thus avoiding discrete switching between limited style categories and improving the matching degree between the response language style and the target user's current actual communication needs.
[0119] After the above processing, compared to the original concept of using a fixed style guidance vector and fixed injection intensity for different users or different dialogue rounds, the embodiments of this application can adaptively determine the style injection coefficients corresponding to each style dimension based on the current user profile characteristics, and thereby combine them to form a personalized style guidance vector corresponding to the current dialogue round. Therefore, even if different users have similar emotional states, different style guidance directions can be formed according to their age, cognitive level, expression habits, and communication preferences. For the same user, the degree of influence of each style dimension can be dynamically adjusted according to changes in their real-time emotions and language states, avoiding insufficient or excessive style guidance caused by fixed injection, thereby improving the matching degree between the vocabulary, sentence structure, and tone of the response text and the user's current actual communication needs.
[0120] It is understandable that the multiple style dimensions and their corresponding style guidance benchmark vectors obtained during the inference phase can be pre-set. Each style dimension describes an adjustable attribute of the response language style. Taking a psychologically assisted dialogue scenario as an example, multiple style dimensions may include one or more of the following: tone of voice, lexical difficulty, sentence conciseness, empathy intensity, professionalism, affinity, soothingness, and rigor. For each style dimension, a corresponding style guidance benchmark vector is pre-configured in the activation space of the large language model. This style guidance benchmark vector represents how the generated text's performance in the corresponding style dimension will be enhanced or weakened when the representation changes along this vector direction within the large language model. For example, the style guidance benchmark vector corresponding to tone of voice can guide the model to use more gentle wording, while the style guidance benchmark vector corresponding to empathy intensity can guide the model to increase emotional responses such as understanding and acceptance.
[0121] In one possible implementation, style guidance benchmark vectors for multiple style dimensions can be pre-constructed offline before the large language model performs online inference. This process may include: for each style dimension, obtaining positive and negative style samples, where positive style samples exhibit higher performance in the style dimension than negative style samples; inputting the positive and negative style samples into the large language model to obtain the intermediate activation vectors of the positive and negative style samples in the target network layer; and determining the style guidance benchmark vector corresponding to the style dimension in the activation space of the large language model based on the activation difference between the intermediate activation vectors of the positive and negative style samples.
[0122] by Figure 6 The offline phase construction style vector space v is shown. style Let's take the process as an example. First, multiple style dimensions can be pre-configured according to the application scenarios adapted to the dialogue system. For each style dimension, multiple sets of contrastive corpora corresponding to that style dimension are obtained. Each set of contrastive corpora includes positive style samples and negative style samples, where positive style samples perform better than negative style samples in the corresponding style dimension. For example, for tone of voice, supportive responses generated using gentle wording and a mild tone can be used as positive style samples, while responses with a relatively flat or mechanical tone can be used as negative style samples; for sentence conciseness, responses with short sentences and straightforward structures can be used as positive style samples, while responses with relatively complex sentence structures can be used as negative style samples.
[0123] When constructing contrastive corpus pairs, positive and negative style samples can have the same or similar semantic content, differing mainly in the degree of representation of the target style dimension. This reduces the impact of non-target factors such as response topics and factual content on activation differences. In one exemplary implementation, each style dimension can be configured with at least 1000 contrastive corpus pairs, thereby utilizing multiple sets of samples to jointly extract a relatively stable style guidance direction.
[0124] Subsequently, the positive and negative style samples from each pair of contrasting corpora are input into the large language model to be used for online response generation, and the intermediate activation vectors of the samples generated by each are obtained in the target network layer. For example, for a large language model with multiple Transformer network layers, one or more network layers from layers 9 to 19 can be selected as the target network layer, and the attention output activation value of each sample at the last non-padded token position of the corresponding target network layer can be extracted.
[0125] Since the positive and negative style samples use the same large language model, the same target network layer, and the same word position selection rules, their corresponding intermediate activation vectors are located in the same activation space and have the same vector dimension. For the j-th pair of contrasting corpora, the corresponding activation difference vector can be determined according to the following formula (5):
[0126] (5)
[0127] in, This represents the activation vector of a positive style sample in the middle of the sample in the target network layer. This represents the activation vector of a negative style sample within the same target network layer. This represents the representational change in the activation space of the large language model resulting from positive style relative to negative style. Therefore, each activation difference vector can reflect the direction of activation shift as the corresponding style dimension changes from weak to strong at the internal representational level of the model.
[0128] Furthermore, we perform aggregation analysis on multiple activation difference vectors corresponding to the same style dimension to obtain the direction vector that best represents the main changing trend of multiple activation difference vectors, which serves as the style guidance benchmark vector for that style dimension. And construct the style vector space v by constructing the style-guided baseline vectors corresponding to all style dimensions. styleSpecifically, multiple activation difference vectors can be stacked to form an activation difference matrix. Principal component analysis is then performed on this matrix, and the direction represented by the first principal component is determined as the style-guiding baseline vector for that style dimension. The first principal component can represent the relatively consistent main activation change direction among multiple groups of positive and negative samples, thereby reducing the influence of content differences or random noise from a single sample on the style direction extraction results.
[0129] Through the offline construction process described above, language style attributes that are difficult to quantify directly can be transformed into explicit guiding directions in the activation space of a large language model. Finally, the style guidance baseline vectors obtained from the offline construction can be stored in a style vector index file or a model configuration file for direct retrieval during the inference phase. This provides a foundation for dynamically combining multiple style dimensions based on user profile features, without requiring repeated calculations in each dialogue round.
[0130] Furthermore, referring to Figure 4 The style mapping module provides the resulting personalized style guidance vector to the large language model to implement style guidance during the generation of response text based on user input text. Specifically, when the large language model performs inference calculations, the personalized style guidance vector is... Inject the original intermediate activation vector 'a' generated by at least one target network layer to obtain the guided intermediate activation vector 'a'. Then, based on the guided intermediate activation vector 'a', continue to perform the calculation of the downstream network layer, so that the personalized style guidance effect is passed along the forward calculation link of the large language model, and finally generate the response text whose language style is adapted to the current user profile features.
[0131] Understandably, in the process of generating response text word by word in a large language model, different decoding positions perform different semantic functions. For example, some decoding positions are used to generate empathic expressions, and are suitable for applying style guidance with strong empathy intensity, affinity, and soothingness; while other decoding positions are used to maintain syntactic structure and logical coherence, and are suitable for applying style guidance with strong professionalism and rigor. Furthermore, the internal generation state formed by the same decoding position in different network layers will also change with the network computation depth. If a fixed injection scheme is used, injecting personalized style guidance vectors with the same intensity in all target network layers and all decoding positions, it is easy to have insufficient guidance in positions that need to strengthen tone, empathy, or affinity, and may also produce unnecessary over-intervention in positions such as factual statements, logical reasoning, or safety prompts, thereby affecting the semantic accuracy and coherence of the response text.
[0132] To address this, this application's embodiments dynamically adjust the intensity of the personalized style guidance vector at each target network layer and each decoding position within that layer, ensuring the style injection intensity matches the internal generation state of that decoding position. This allows for enhanced style guidance at decoding positions suitable for carrying personalized style expressions, while appropriately reducing style guidance at decoding positions where maintaining the original semantic generation direction is crucial, achieving fine-grained style control per decoding position.
[0133] In one possible implementation, the process of adjusting the intensity of the personalized style guidance vector at each decoding position token may include: for each target network layer and each decoding position within each target network layer, determining the gating coefficient corresponding to the current decoding position based on the matching degree between the style tendency reflected in the internal generation state of the current decoding position in the current target network layer and the target style control requirements carried by the system prompt information; the gating coefficient is used to characterize the injection intensity of the personalized style guidance vector at the current decoding position, and the gating coefficient is positively correlated with the matching degree; adjusting the intensity of the personalized style guidance vector based on the gating coefficient, and superimposing the adjusted personalized style guidance vector onto the original intermediate activation vector generated by the target network layer at the current decoding position to obtain the guided intermediate activation vector of the target network layer at the current decoding position.
[0134] The following describes the processing procedure using any decoding position in any target network layer as an example. Other decoding positions can use the same or similar processing methods, which will not be elaborated further. This embodiment can obtain the in-layer representation corresponding to the current decoding position and, based on the current internal generation state reflected in this in-layer representation, determine the degree of matching between it and the target style control requirements carried by the system prompt information. The system prompt information may include control requirements on aspects such as response tone, vocabulary difficulty, sentence structure, empathy, professionalism, or safe expression; the degree of matching reflects the compatibility between the internal generation direction of the current decoding position and the aforementioned control requirements.
[0135] Optionally, the process of determining the matching degree between the style tendency reflected by the internal generation state of the current decoding position in the current target network layer and the target style control requirements carried by the system prompt information may include: determining the set of system prompt word positions corresponding to the system prompt information in the context word sequence of the large language model; taking the in-layer representation of each system prompt word in the set of system prompt word positions as a key vector, where the system prompt word is a text description word used to represent the target style requirements; aggregating the key vectors corresponding to each system prompt word and taking the aggregated vector as the target key vector; taking the in-layer representation of the current decoding position in the current target network layer as a query vector; and calculating the matching degree between the query vector and the target key vector to obtain the matching degree.
[0136] After lexicalizing the system prompts, user input text, and historical dialogue content, the lexical intervals corresponding to the system prompts are determined according to the arrangement of each part of the content in the context lexical sequence. The system prompts can consist of a system role start marker, the system prompt body, and a system role end marker. Therefore, the positions of each lexical belonging to the system prompt body can be determined based on the system role marker, segment identifier, lexical type identifier, or lexical position offset. Further, textual descriptive lexical units used to describe the target style requirements are selected, such as lexical units like "gentle tone," "concise expression," "empathetic," and "precise wording," and the positions of these lexical units in the context lexical sequence are used to form the system prompt lexical position set S.
[0137] In one possible implementation, when performing attention calculations for style control on context lexical units at the current decoding position, only key and value vectors within the system prompt lexical unit position set S are allowed to participate in the calculation, and the positions corresponding to user input lexical units, historical response lexical units, and lexical units already generated in the current response are masked. The corresponding system prompt attention output can be expressed as Equation (6).
[0138] (6)
[0139] in, V represents the attention weight of the current decoding position t to the i-th cue word. i W represents the vector corresponding to the i-th system prompt word. o This is the output mapping matrix.
[0140] Understandably, the keys and values corresponding to historical responses can still be retained in the KV-cache of regular causal attention to maintain the semantic continuity of the dialogue. However, in the dedicated attention branch used to determine the degree of target style matching and generate style control signals, only the keys and values within the system cue word position set S are called. Therefore, the intra-layer representations corresponding to historical response words will not re-enter the style control attention summation process, nor will response states already affected by style injection be repeatedly amplified in subsequent decoding positions or subsequent dialogue rounds. Based on this, the target key vector and its corresponding style control signal can always originate from relatively stable system cue information, rather than from continuously accumulating and changing historical response content. This suppresses the cumulative shift caused by repeated style injection of historical response states through the KV-cache, reducing the risk of style drift and decreased semantic coherence in multi-turn dialogues.
[0141] Based on this, for the current target network layer, the intra-layer representation corresponding to each system prompt word in the system prompt word position set S can be obtained. This intra-layer representation can be the hidden state, residual flow representation, attention sublayer input representation, attention sublayer output representation, or hidden representation after layer normalization, obtained after processing the system prompt word by the current target network layer. Optionally, to enable comparison of representations of different words in a unified query-key space, the intra-layer representation can be projected using the key mapping matrix corresponding to the current target network layer to obtain the key vector corresponding to each system prompt word. Further, methods such as mean aggregation can be used to aggregate all key vectors in the system prompt word position set S to obtain the target key vector k.
[0142] For the current decoding position t, its in-layer representation in the current target network layer can be obtained and used as the query vector q. Then, the dot product, cosine similarity, or other vector matching degree between the query vector q and the target key vector k can be calculated to obtain the matching degree d corresponding to the current decoding position t of the target network layer l. l,t .
[0143] Furthermore, the matching degree is mapped to the gating coefficient of the personalized style guidance vector through the Sigmoid function, as shown in the following equation (7):
[0144] (7)
[0145] in, c represents the gating coefficient of the current target network layer l at the current decoding position t. base The base injection intensity is s, and s is a scaling parameter that adjusts the sensitivity of gating changes, which can be set to 1.5 for example. This represents the baseline matching degree corresponding to the current target network layer l. As the matching degree increases... As the matching degree increases, the gating coefficient increases accordingly; when the matching degree is low, the gating coefficient decreases accordingly.
[0146] Understandably, a higher matching degree indicates that the internal generation state at the current decoding position has evolved in a direction consistent with or similar to the target style defined by the system prompts, and the compatibility between the personalized style guidance vector and the current semantic generation direction is high. In this case, increasing the injection strength can further enhance the target style performance with less interference to the original semantic content, thus allowing for a relatively large gating coefficient. Conversely, a lower matching degree indicates weaker compatibility between the current internal generation state and the target style control requirements. If a strong style guidance is still applied, it is easy to excessively perturb the current semantic inference direction, increasing the risk of semantic shift or unstable generation. Therefore, a relatively small gating coefficient can be configured to weaken the effect of the personalized style guidance vector at the current decoding position.
[0147] Therefore, this application refines the uniform injection strength, which originally applied to the entire response, into adaptive injection strengths targeting different target network layers and different decoding positions. For decoding positions where the internal generation state matches the target style control requirements to a high degree and is suitable for carrying style expression, the strength of the personalized style guidance vector can be increased to enhance the personalized style performance that matches the current user profile features. For decoding positions where the matching degree is low and they are prone to deviating from the original semantic generation direction due to style intervention, the strength is reduced accordingly to minimize interference with factual expression, logical reasoning, and security prompts. Thus, while maintaining the ability to control personalized style, the risk of excessive local intervention and semantic accumulation shift caused by uniform strong injection can be reduced, thereby achieving a coordinated balance between the personalized style enhancement effect and the semantic stability of the response text.
[0148] After obtaining the above gating coefficient, referring to the following formula (8), the intensity of the personalized style guidance vector can be adjusted based on the gating coefficient, and the adjusted personalized style guidance vector can be superimposed on the original intermediate activation vector at the current decoding position to obtain the guided intermediate activation vector corresponding to the current decoding position.
[0149] (8)
[0150] in, This represents the original intermediate activation vector corresponding to the t-th decoding position of the target network layer l. This represents the guided intermediate activation vector corresponding to the t-th decoding position of the target network layer l.
[0151] Subsequently, the guided intermediate activation vector is input into the subsequent computational structure of the current target network layer, such as continuing to perform standard multilayer perceptron computation and residual connection computation, so that the style guidance effect corresponding to the current decoding position is passed down layer by layer with the downstream network computation, and finally the response text is generated.
[0152] Based on this, refer to Figure 4 It can also perform security constraint verification on the controlled generation process and its generation results. The security constraint verification can include two processing paths: intermediate activation state verification and response text verification. Based on the verification result of the intermediate activation state verification path, it can be determined whether the style guidance intensity needs to be reduced. Based on the verification result of the response text verification path, it can be determined whether to trigger crisis intervention language to generate response text.
[0153] In the intermediate activation state verification path, after style injection at the current decoding position, the stability of the generated guided intermediate activation vector can be checked to determine whether the current style injection has caused the model's lexical prediction to change from a relatively clear generation direction to an overly dispersed or uncertain state. When the risk of unstable prediction is detected, the strength of the personalized style guidance vector at the current decoding position can be reduced before the current lexical is officially output, and the corresponding guided intermediate activation vector can be regenerated to suppress the risky content from the generation stage within the model and prevent it from spreading to subsequent network layers.
[0154] In one possible implementation, the intermediate activation state verification path may include: determining a first parameter for the current decoding position based on the guided intermediate activation vector, the first parameter being used to characterize the stability of the prediction distribution at the current decoding position; if the first parameter satisfies a preset stable prediction condition, using the guided intermediate activation vector as the activation vector for continuing downstream network layer computation; if the first parameter does not satisfy the preset stable prediction condition, reducing the influence of the personalized style guiding vector at the current decoding position according to a preset attenuation factor to obtain an attenuated personalized style guiding vector; based on the attenuated personalized style guiding vector, regenerating the guided intermediate activation vector at the current decoding position, and recalculating the corresponding first parameter until the recalculated first parameter satisfies the preset stable prediction condition, and using the regenerated guided intermediate activation vector as the activation vector for continuing downstream network layer computation.
[0155] The first parameter can be any parameter that characterizes the stability of the prediction distribution at the current decoding position, such as the prediction distribution entropy or the concentration of candidate lexical probabilities. The following section will use the Shannon entropy corresponding to the prediction distribution entropy as the first parameter to illustrate the intermediate activation state verification process.
[0156] Specifically, the guided intermediate activation vector obtained by style injection at the current decoding position is used as the candidate activation vector, and a tentative forward computation corresponding to the current decoding position is performed based on the candidate activation vector to obtain the prediction score of the current decoding position for each candidate word in the vocabulary; then, the prediction score is normalized by the Softmax function to obtain the prediction distribution p of the current decoding position.
[0157] Referring to the following equation (9), the Shannon entropy value H(p) is calculated based on the predicted distribution at the current decoding position.
[0158] (9)
[0159] Where, p i This represents the probability of predicting the i-th candidate word at the current decoding position.
[0160] Understandably, the prediction distribution entropy H(p) reflects the degree of concentration of predictions made by the large language model for the current lexical unit to be generated. When the predicted probabilities are mainly concentrated on a small number of semantically clear candidate lexical units, the prediction distribution entropy is relatively low, indicating that the model has formed a relatively clear generation direction based on the intermediate activation vector after the current guidance. When the predicted probabilities are dispersed among a large number of candidate lexical units with large semantic differences, the prediction distribution entropy is relatively high, indicating that the current style injection may have a strong perturbation to the original semantic generation state of the model, making it difficult for the model to determine the subsequent generation direction.
[0161] Therefore, if the predicted distribution entropy H(p) satisfies the preset stable prediction condition, such as being less than or equal to the preset upper limit of entropy constraint Hmax, it indicates that the injection of the current personalized style guiding vector at this decoding position has not caused a significant divergence in the word prediction distribution, and the current generation direction is still within the allowable stable range. In this case, the current guided intermediate activation vector can be identified and used as the activation vector for continuing the calculation of the downstream network layer, thereby completing the sampling or selection of the current word based on the corresponding predicted distribution.
[0162] If the predicted distribution entropy H(p) does not meet the preset stable prediction condition, such as being greater than the preset upper limit of the entropy constraint Hmax, it indicates that the predicted distribution at the current decoding position is too dispersed, and the current injection intensity may have exceeded the style intervention range that the decoding position can stably bear. In response, the intensity of the personalized style guidance vector at the current decoding position can be reduced according to a preset attenuation factor, thereby reducing the style guidance intensity. The preset attenuation factor can be denoted as λ, and satisfies 0 < λ < 1. For example, λ can be set to 0.7, and its selectable value range is 0.5 to 0.9.
[0163] Furthermore, the style injection coefficients corresponding to each style dimension can be synchronously attenuated according to a preset attenuation factor, and the attenuated personalized style guidance vector can be obtained by re-fusion based on the attenuated style injection coefficients. Then, the guidance intermediate activation vector at the current decoding position can be re-determined with reference to the above formula (8). The above process of calculating the prediction distribution entropy H(p) is repeated. If the recalculated prediction distribution entropy meets the preset stable prediction condition, the guidance intermediate activation vector regenerated this time is confirmed, and the downstream network layer calculation is continued with this activation vector. If the preset stable prediction condition is still not met, the effect intensity is reduced according to the preset attenuation factor and the above verification process is repeated.
[0164] Therefore, stability verification and intensity decay constitute a closed-loop adjustment process with the current decoding position as the unit. This process gradually reduces the perturbation of the personalized style guidance vector on the current internal generation state, allowing the model to re-form a relatively concentrated word prediction distribution while preserving personalized style performance as much as possible. Compared to using a fixed injection intensity or directly setting the injection intensity to zero in case of anomalies, this gradual decay method can create a smoother adjustment relationship between personalized style control effect and word prediction stability.
[0165] Optionally, during the aforementioned cyclical attenuation process, a preset upper limit Rmax can be set to limit the maximum number of attenuation retries at the current decoding position. Rmax can be configured based on allowable inference latency and stability requirements; for example, it can be set to 3 times, with a selectable value range of 2 to 5 times. After each attenuation operation, the attenuation count corresponding to the current decoding position can be updated, and it can be determined whether this attenuation count has reached the preset upper limit Rmax.
[0166] When the number of decays has not yet reached the preset maximum number of decays Rmax, the intensity of the personalized style guidance vector can continue to be decayed according to the above cyclic decay process, and the intermediate activation vector after guidance and the first parameter can be regenerated.
[0167] When the number of times the personalized style guidance vector is decayed reaches the preset limit, and the recalculated first parameter (such as the predicted distribution entropy mentioned above) does not meet the preset stable prediction condition, it indicates that relying solely on continuous proportional decay has not restored the current decoding position to the preset stable range. If decay and retries continue without an upper limit, it will not only increase the generation latency of the current word, but may also cause the injection strength to approach zero infinitely, resulting in a sudden change in style performance between the current response and the words before and after it.
[0168] In response, embodiments of this application can adjust the intensity of the personalized style guidance vector at the current decoding position to a preset minimum injection intensity. For example, it can be set to 0.5, and its selectable value range is from 0.1 to 1.0. Specifically, all style injection coefficients corresponding to the current decoding position can be set to [value missing]. The adjusted personalized style guiding vector is then re-integrated and generated. Furthermore, based on the adjusted personalized style guiding vector, a new guided intermediate activation vector is generated for the current decoding position and used as the activation vector to continue the computation of downstream network layers, thus ending the intensity decay cycle at the current decoding position.
[0169] Therefore, when the predicted distribution shows an unstable trend, semantic generation stability is restored by gradually reducing the injection strength; and when the stability condition is not met after a finite number of decays, a deterministic processing exit is provided by using the minimum injection strength. These two approaches work together to suppress the divergence of the predicted distribution and semantic drift caused by strong style injection without eliminating personalized style control, and to avoid generation blocking caused by infinite retries, thus balancing personalized style performance, restored semantic stability, and online inference efficiency.
[0170] In the response text verification path for security constraint validation, after the large language model generates the response text, a content security classification model, a crisis risk identification model, or preset security rules can be used to perform security constraint validation on the response text. This includes detecting self-harm risks, extremely negative expressions, inappropriate inducements, offensive content, and other content that does not meet security requirements. If the response text meets the preset security constraint conditions, i.e., there is no security risk, the response text is output. If the response text is detected to not meet the preset security constraint conditions, i.e., there is a security risk, the crisis type corresponding to the response text can be determined. Based on the intervention method corresponding to the crisis type, the large language model is triggered to regenerate the response text, and the regenerated response text undergoes security constraint validation until the preset convergence condition is met.
[0171] Optionally, the response text verification path in this embodiment may include a content security detection path and an emotional crisis detection path.
[0172] In the content security detection path, the response text can be input into a pre-trained content security classifier to detect whether it contains dangerous words, provocative expressions, inappropriate misleading content, or inappropriate words introduced due to personalized style guidance. If no inappropriate wording is detected in the response text, it indicates that the response text does not pose a risk of inappropriate wording, and the response text can be output. If inappropriate wording is detected in the response text, it indicates that the risk type corresponding to the current response text is inappropriate wording, and the response text is blocked, triggering the large language model to regenerate the response text. Optionally, the number of regenerations can be set to three; if the security check still fails after reaching the preset maximum number of regenerations, generation stops, and a pre-configured standard safe response is output, thereby preventing unsafe content from being directly presented to the user.
[0173] In the emotional crisis detection path, the real-time emotional state characteristics of the current dialogue turn can be used as a basis. emotion This determines whether the target user is in an emotional crisis state. For example, real-time emotional state features v emotion This can include the anxiety probability P anxiety and the probability of a drop P depressed When the anxiety probability P anxiety Greater than a preset probability value (e.g., 0.8), and P depressed When the probability of a user falling into a depression is greater than the low probability value (e.g., 0.6), it can be determined that the target user belongs to the emotional crisis type. The corresponding standard intervention response can be selected from the pre-established crisis intervention script library and the response text can be overwritten with the standard intervention response. At the same time, a crisis alarm signal is sent to the backend system.
[0174] Furthermore, upon triggering crisis intervention, the style injection coefficients for each style dimension can be uniformly adjusted to zero, suspending the injection of personalized style guidance vectors into the large language model. This prioritizes the safety of crisis intervention over personalized style adaptation, reducing interference from style control on standard intervention content. Personalized style guidance can be restored after the crisis is resolved. For example, if the target user no longer meets the aforementioned crisis judgment conditions in two consecutive dialogue rounds, the style injection coefficients and corresponding style guidance processing can be restored. Thus, in general risk scenarios, candidate response texts can be blocked and regenerated for correction, while in high-risk emotional scenarios, the system can directly switch to the standard crisis intervention chain, achieving tiered safety control.
[0175] This application also provides an electronic device in its embodiments. (See reference...) Figure 7 The diagram illustrates a structural schematic suitable for implementing the electronic device in the embodiments of this application. The electronic device in the embodiments of this application may include, but is not limited to, fixed terminals such as mobile phones, tablets, large-screen teaching displays, wearable devices, etc. Figure 7The electronic device shown is merely an example and should not impose any limitation on the functionality and scope of use of the embodiments of this application.
[0176] like Figure 7 As shown, the electronic device may include a processing unit (e.g., a central processing unit, a graphics processing unit, etc.) 1, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 2 or a program loaded from a storage device 8 into a random access memory (RAM) 3, to implement the dialogue response generation method of the foregoing embodiments of this application. When the electronic device is powered on, the RAM 3 also stores various programs and data required for the operation of the electronic device. The processing unit 1, ROM 2, and RAM 3 are interconnected via a bus 4. An input / output (I / O) interface 5 is also connected to the bus 4.
[0177] Typically, the following devices can be connected to I / O interface 5: input devices 6 including, for example, touchscreens, touchpads, keyboards, mice, cameras, microphones, accelerometers, gyroscopes, etc.; output devices 7 including, for example, liquid crystal displays (LCDs), speakers, vibrators, etc.; storage devices 8 including, for example, memory cards, hard drives, etc.; and communication devices 9. Communication device 9 allows electronic devices to communicate wirelessly or wiredly with other devices to exchange data. Although Figure 7 Electronic devices with various devices are shown, but it should be understood that it is not required to implement or have all of the devices shown. More or fewer devices may be implemented or have alternatively.
[0178] This application also provides a computer program product, including computer-readable instructions, which, when executed on an electronic device, cause the electronic device to implement any of the dialogue response generation methods provided in this application.
[0179] This application also provides a computer-readable storage medium carrying one or more computer programs. When the one or more computer programs are executed by an electronic device, the electronic device can implement any of the dialogue response generation methods provided in this application.
[0180] It should also be noted that the device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate, and the components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs. In addition, in the device embodiment drawings provided in this application, the connection relationship between modules indicates that they have a communication connection, which can be implemented as one or more communication buses or signal lines.
[0181] Through the above description of the embodiments, those skilled in the art can clearly understand that this application can be implemented by means of software plus necessary general-purpose hardware, or it can be implemented by special-purpose hardware including application-specific integrated circuits, special-purpose CPUs, special-purpose memory, special-purpose components, etc. Generally, any function performed by a computer program can be easily implemented by corresponding hardware, and the specific hardware structure used to implement the same function can also be diverse, such as analog circuits, digital circuits, or special-purpose circuits. However, for this application, software program implementation is more often the preferred 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 readable storage medium, such as a computer floppy disk, USB flash drive, mobile hard disk, ROM, RAM, magnetic disk, or optical disk, etc., and includes several instructions to cause a computer device (which may be a personal computer, training equipment, or network device, etc.) to execute the methods described in the various embodiments of this application.
[0182] In the above embodiments, implementation can be achieved, in whole or in part, through software, hardware, firmware, or any combination thereof. When implemented in software, it can be implemented, in whole or in part, as a computer program product.
[0183] The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, all or part of the processes or functions described in the embodiments of this application are generated. The computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions may be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another. For example, the computer instructions may be transmitted from one website, computer, training device, or data center to another website, computer, training device, or data center via wired (e.g., coaxial cable, fiber optic, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) means. The computer-readable storage medium may be any available medium that a computer can store or a data storage device such as a training device or data center that integrates one or more available media. The available media may be magnetic media (e.g., floppy disks, hard disks, magnetic tapes), optical media (e.g., DVDs), or semiconductor media (e.g., solid-state drives (SSDs)).
[0184] The various embodiments in this specification are described in a progressive manner. Each embodiment focuses on the differences from other embodiments. The various embodiments can be combined as needed, and the same or similar parts can be referred to each other.
Claims
1. A method for generating dialogue responses, characterized in that, include: Obtain the user input text of the target user in the current conversation round; Based at least on the user input text, determine the user profile features of the target user in the current conversation round; The user profile features are mapped to the activation space of the large language model through the configured style mapping module to obtain the mapped personalized style guidance vector. The personalized style guidance vector is used to represent the guidance direction of the language style that matches the user profile features in the activation space of the large language model. The user input text is input into a pre-configured large language model. During the inference process of the large language model, the personalized style guidance vector is injected into the original intermediate activation vector of at least one target network layer in the large language model to obtain the guided intermediate activation vector. Based on the guided intermediate activation vector, the calculation of the downstream network layer is continued to generate the response text.
2. The dialogue response generation method according to claim 1, characterized in that, The process of mapping the user profile features to the activation space of a large language model to obtain the mapped personalized style guidance vector includes: Obtain style guidance reference vectors corresponding to multiple pre-configured style dimensions, wherein the style guidance reference vectors represent the reference guidance direction of the corresponding style dimension in the activation space of the large language model; The user profile features are mapped to style injection coefficients corresponding to each style dimension using a pre-trained mapping matrix. The style injection coefficients are used to characterize the degree of matching between the corresponding style dimension and the language style adapted to the user profile features. Based on the style injection coefficients, the style guidance benchmark vectors corresponding to each style dimension are weighted and fused to obtain the personalized style guidance vector.
3. The dialogue response generation method according to claim 1, characterized in that, The process of injecting the personalized style guidance vector into the original intermediate activation vector of at least one target network layer in the large language model to obtain the guided intermediate activation vector includes: For each target network layer and each decoding position within each target network layer, based on the style tendency reflected by the internal generation state of the current decoding position in the current target network layer and the degree of matching between it and the target style control requirements carried by the system prompt information, a gating coefficient corresponding to the current decoding position is determined. The gating coefficient is used to characterize the injection strength of the personalized style guidance vector at the current decoding position. The gating coefficient is positively correlated with the degree of matching. The intensity of the personalized style guidance vector is adjusted based on the gating coefficient, and the adjusted personalized style guidance vector is superimposed on the original intermediate activation vector generated by the target network layer at the current decoding position to obtain the guided intermediate activation vector of the target network layer at the current decoding position.
4. The dialogue response generation method according to claim 3, characterized in that, The process of determining the degree of match between the style tendency reflected in the internal generation state of the current decoding position in the current target network layer and the target style control requirements carried by the system prompt information includes: Determine the set of system prompt word positions corresponding to the system prompt information in the context word sequence of the large language model; Within the set of system prompt word positions, each system prompt word is represented as a key vector within the layer corresponding to the current target network layer. The system prompt word is a text description word used to represent the target style requirement. Aggregate the key vectors corresponding to each system prompt word, and use the aggregated vector as the target key vector; The current decoding position is represented within the current target network layer as a query vector; The matching degree between the query vector and the target key vector is calculated to obtain the matching degree.
5. The dialogue response generation method according to claim 3, characterized in that, The method further includes: Based on the guided intermediate activation vector, a first parameter is determined for the current decoding position, wherein the first parameter is used to characterize the stability of the predicted distribution of the current decoding position; If the first parameter satisfies the preset stable prediction condition, the guided intermediate activation vector is used as the activation vector for continuing to advance the calculation of the downstream network layer. If the first parameter does not meet the preset stable prediction condition, the influence strength of the personalized style guidance vector at the current decoding position is reduced according to the preset attenuation factor to obtain the attenuated personalized style guidance vector; based on the attenuated personalized style guidance vector, the guidance intermediate activation vector at the current decoding position is regenerated, and the corresponding first parameter is recalculated until the recalculated first parameter meets the preset stable prediction condition, and the regenerated guidance intermediate activation vector is used as the activation vector for continuing to advance the calculation of the downstream network layer.
6. The dialogue response generation method according to claim 5, characterized in that, The method further includes: If the number of times the personalized style guiding vector is decayed reaches a preset upper limit, and the recalculated first parameter does not meet the preset stable prediction condition, the influence strength of the personalized style guiding vector at the current decoding position is adjusted to a preset minimum injection strength. Based on the adjusted personalized style guiding vector, the guided intermediate activation vector at the current decoding position is regenerated and used as the activation vector for continuing to advance the calculation of the downstream network layer.
7. The dialogue response generation method according to claim 2, characterized in that, The process of pre-configuring style-guided baseline vectors corresponding to multiple style dimensions includes: For each style dimension, obtain the positive style sample and the negative style sample corresponding to the style dimension, wherein the positive style sample has a higher performance degree in the style dimension than the negative style sample; The positive style sample and the negative style sample are respectively input into the large language model to obtain the activation vectors of the positive style sample and the negative style sample in the middle of the sample of the target network layer; Based on the activation difference between the intermediate activation vectors of the positive style samples and the negative style samples, the style guidance reference vector corresponding to the style dimension in the activation space of the large language model is determined.
8. The dialogue response generation method according to any one of claims 1-7, characterized in that, The method further includes: The response text is subject to security constraint verification. If the response text meets the preset security constraints, the response text is output. If the response text does not meet the preset security constraints, the crisis type corresponding to the response text is determined, and based on the intervention method corresponding to the crisis type, the large language model is triggered to regenerate the response text, and the security constraints are verified on the regenerated response text until the preset convergence condition is met.
9. The dialogue response generation method according to any one of claims 1-7, characterized in that, The process of determining the user profile features of the target user in the current conversation round, based at least on the user input text, includes: Obtain the user registration information of the target user; Based on the user registration information, extract the identity background features of the target user; Based at least on the user input text, extract the target user's language style features and real-time emotional state features; The user profile features are obtained by fusing the identity background features, the language style features, and the real-time emotional state features.
10. The dialogue response generation method according to claim 9, characterized in that, The method further includes: After the current dialogue round of the target user ends, the dialogue quality is determined, and the fusion weights corresponding to the identity background feature, the language style feature and the real-time emotional state feature are updated with the goal of minimizing the loss of dialogue quality. In subsequent dialogue rounds with the target user, the user profile features corresponding to the target user are determined based on the updated fusion weights.
11. An electronic device, characterized in that, include: Memory and processor; The memory is used to store programs; The processor is configured to execute the program to implement each step of the dialogue response generation method as described in any one of claims 1-10.