A large language model dynamic guidance method based on a conditional generation model and related devices
By dynamically generating guiding vectors through a conditional generative model, the fragility and instability of guiding vectors in large language models are resolved, adaptive guiding control is achieved, and the stability and automation level of the model are improved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- XI AN JIAOTONG UNIV
- Filing Date
- 2026-02-11
- Publication Date
- 2026-06-02
Smart Images

Figure CN122133664A_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of electronic information technology, and relates to the field of dynamic guidance of large language models, and in particular to a method and related apparatus for dynamic guidance of large language models based on conditional generation models. Background Technology
[0002] Currently, large language models have achieved great success in the field of natural language processing; however, how to further ensure that large language models are safe, reliable and act according to human intentions is a key challenge.
[0003] In existing technical solutions, a control technique that does not require high fine-tuning costs is "representation engineering," particularly the "steering vectors" method. The core of this method is to inject a specific steering vector into the model's internal activations (especially the residual flow) during model inference to guide the model's behavior and improve the authenticity, security, or ability to follow specific instructions in the response. The aforementioned specific steering vector is usually calculated by comparing the activation differences between "desired" and "undesired" behaviors.
[0004] Existing guided vector methods generally suffer from a core flaw: they typically represent a high-level concept (such as "authenticity") as a single, static vector in the activation space. This "point estimation" technique has serious limitations in the following aspects, including: (1) Vulnerability and instability; Explainedly, a single vector cannot capture the multifaceted nature and contextual dependence of a concept; Studies have shown that vectors extracted under different cues or subsets of data may have inconsistent directions, resulting in extremely unstable performance and sometimes even impairing model performance; Existing methods ignore the complex geometric forms that a concept may present in the activation space, such as a “manifold” or “distribution”, and compressing this complex distribution into a point will result in the loss of a large amount of information.
[0005] (2) Lack of adaptability; interpretably, static vectors are pre-computed and cannot be dynamically adjusted according to the specific semantics of the current user input, resulting in poor generalization ability and robustness.
[0006] (3) Reliance on manual selection; Explanation: In practical applications, users need to manually select appropriate guiding vectors from a pre-built "vector library" according to the task, which greatly limits the level of automation and practical value. Summary of the Invention
[0007] The purpose of this invention is to provide a dynamic guidance method and related apparatus for large language models based on conditional generation models, in order to solve one or more of the aforementioned technical problems. The technical solution disclosed in this invention transforms static lookup-based calls into dynamic generation-based control, avoiding the fragility of single vectors; it replaces manual selection through adaptive generation of guidance vectors; it can significantly improve the stability and automation level of large language model guidance, while also enhancing generalization ability and robustness.
[0008] To achieve the above objectives, the present invention adopts the following technical solution: In a first aspect, the present invention provides a dynamic guidance method for large language models based on conditional generation models, comprising: Obtain user prompts by obtaining the activation vector of the user prompts through a specified intervention layer of the large language model; The activation vectors are projected onto the pre-extracted semantic bases of each task, and the target task to which the user prompt belongs is identified through geometric matching. Using the target task as input, a pre-trained conditional generation model dynamically generates a guiding vector, which is then injected into the residual stream of a large language model for dynamic guidance. The result is output according to the task requirements of the target task to which the user prompt belongs. The conditional generation model is a generative model that can learn the conditional distribution probability of the guiding vector with respect to the conditions.
[0009] A further improvement to the technical solution of this invention lies in that, during the extraction of semantic bases for each task, the extraction steps for each task semantic base include: Based on a predefined task, relevant prompts are collected and input into a large language model to extract hidden state activation vectors. The hidden state activation vectors are concatenated into a task matrix, and singular value decomposition is performed on the task matrix; based on the decomposition results, the top-ranked tasks are selected. d The three most important right singular vectors form an orthogonal basis, which serves as the semantic basis for the predefined task; among them, d The number of predefined vectors.
[0010] A further improvement to the technical solution of the present invention is that the step of identifying the target task to which the user prompt belongs through geometric matching includes: Calculate the projection energy on each semantic basis and use it as the matching score. Select the task with the highest matching score as the target task to which the user prompt belongs. The expression for calculating the matching score is as follows: ; In the formula, Represents the activation vector With the k Semantic base for each task Match score; Activation vector In the k Semantic base for each task The squared L2 norm of the projection vector.
[0011] A further improvement of the technical solution of the present invention is that the condition generation model is specifically a conditional variational autoencoder, a conditional flow model, or a conditional diffusion model.
[0012] A further improvement of the technical solution of the present invention is that, during the training process of the conditional generation model, each training sample in the training set consists of a guiding vector and a corresponding task label.
[0013] A further improvement to the technical solution of this invention lies in the step of dynamically guiding the process by injecting the guiding vector into the residual stream of a large language model, wherein the hidden state update expression is: ; In the formula, This indicates that after injecting the guiding vector, the large language model's... l The first in the layer m The hidden state after updating each word element; This indicates that before the injection of the guiding vector, the large language model's first... l The first in the layer m The original hidden state of each word element; The strength coefficient; Provide the user with the corresponding guidance vector; This represents the total number of layers in the large language model.
[0014] A second aspect of the present invention provides a dynamic guidance system for large language models based on a conditional generation model, comprising: An activation vector extraction unit is used to obtain user prompts by acquiring the activation vectors of the user prompts through a specified intervention layer of the large language model. The target task identification unit is used to project the activation vector onto the pre-extracted semantic bases of each task, and identify the target task to which the user prompt belongs through geometric matching; The dynamic guidance output unit is used to dynamically generate guidance vectors through a pre-trained conditional generation model using the target task as input conditions, and inject the guidance vectors into the residual stream of the large language model for dynamic guidance, and output the results according to the task requirements of the target task to which the user prompts belong; wherein, the conditional generation model is a generation model that can learn the conditional distribution probability of the guidance vector with respect to the conditions.
[0015] In a third aspect, the present invention provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor, when executing the program, implements the dynamic guidance method for a large language model based on a conditional generation model as described in any one of the first aspects of the present invention.
[0016] In a fourth aspect, the present invention provides a non-transitory computer-readable storage medium having a computer program stored thereon, wherein the computer program, when executed by a processor, implements the dynamic guidance method for a large language model based on a conditional generation model as described in any one of the first aspects of the present invention.
[0017] In a fifth aspect, the present invention provides a computer program product comprising computer instructions which, when executed by a processor, implement the steps of the dynamic guidance method for a large language model based on a conditional generation model as described in any one of the first aspects of the present invention.
[0018] Compared with the prior art, the present invention has the following beneficial effects: This invention discloses a dynamic guidance method for large language models based on a conditional generative model. It models the guidance vector as a conditional probability distribution in the hidden state space, learns this distribution through the conditional generative model, and designs an adaptive task recognition method for offline semantic base extraction and online geometric matching to achieve end-to-end dynamic guidance: after extracting the user cue activation vector and recognizing the corresponding task, the conditional generative model dynamically generates the guidance vector and injects it into the residual stream of the second half of the LLM layer. The improved techniques of this invention transform static table lookup calls into dynamic generative control, avoiding the fragility of a single vector and achieving adaptive generation of the guidance vector, replacing manual selection. This significantly improves the stability and automation level of LLM guidance, while reducing storage overhead and improving system scalability. Specifically, this invention abandons the point estimation method of a single static vector, models the guiding vector corresponding to the high-level concept as a conditional probability distribution of the hidden state space, learns this distribution through a conditional generation model, captures the multifaceted nature and contextual dependence of the concept, and fundamentally solves the fragility and instability of a single vector, making the guiding mechanism more reliable. Therefore, it can significantly improve the robustness and stability of LLM guidance.
[0019] Specifically, this invention designs an adaptive task recognition method. First, semantic bases are extracted offline for each task using SVD. Then, the activation vector of the user's new prompt is projected onto all semantic bases. The corresponding task is determined by the maximum projection energy of geometric matching. Combined with an end-to-end dynamic guidance process, the extraction of prompt activation, task recognition, generation of guidance vectors, and injection into LLM are executed coherently. This allows the guidance vectors to be dynamically generated based on the real-time semantics of the user input, replacing the manual selection of vectors. This solves the problems of static vectors lacking adaptability and relying on manual intervention, and achieves dynamic adaptive control, greatly improving the automation level and practical value of the technology. Attached Figure Description
[0020] To more clearly illustrate the technical solutions in this invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of this invention. For those skilled in the art, other drawings can be obtained from these drawings without creative effort.
[0021] Figure 1 This is a flowchart illustrating a dynamic guidance method for a large language model based on a conditional generation model, as described in an embodiment of the present invention.
[0022] Figure 2 This is a schematic diagram comparing the existing method with the method of the present invention in an embodiment of the present invention.
[0023] Figure 3 This is a schematic diagram of a dynamic guidance system for a large language model based on a conditional generation model, as described in an embodiment of the present invention. Detailed Implementation
[0024] To make the objectives, technical solutions, and advantages of the present invention clearer, the technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings of the embodiments of the present invention; obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments.
[0025] Based on the technical solutions disclosed in the embodiments of this invention, all other embodiments obtained by those skilled in the art without inventive effort are within the scope of protection of this invention. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion. For example, a process, method, system, product, or device that includes a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to these processes, methods, products, or devices.
[0026] Please see Figure 1This invention provides a dynamic guidance method for a large language model based on a conditional generative model. When a user provides a new prompt, dynamic and generative guidance is performed through the following steps: Step 1: Obtain user prompts by obtaining the activation vector of the user prompts through the specified intervention layer of the large language model.
[0027] In a specific exemplary technical solution of this invention, user prompts are first received, and then the user prompts are input into a Large Language Model (LLM), where their activation vectors are obtained at a specified intervention layer (such as the last layer).
[0028] Step 2: Project the activation vector onto the pre-extracted semantic bases of each task, and identify the target task to which the user prompt belongs through geometric matching.
[0029] In a specific exemplary technical solution of this invention, the activation vector is first projected onto each semantic basis calculated offline, and the projection energy (i.e., the squared L2 norm of the projection vector) on each semantic basis is calculated and used as the matching score, expressed as follows: In the formula, Represents the activation vector With the k Semantic base for each task Match score; The expression for calculating projected energy, i.e., the activation vector. In the k Semantic base for each task The squared L2 norm of the projected vector; interpretably, this calculation expression, obtained by calculating the projected energy, is used to determine user prompts. The relevance of each task is considered; then, the task with the highest matching score is selected as the current user prompt. The target task is represented as: In the formula, The identified target task number (ID); K The total number of tasks; subsequently, the identified target task numbers. Will be used as a condition It is fed into the conditional generation model.
[0030] Step 3: Using the target task as input, dynamically generate a guiding vector through a pre-trained conditional generation model; inject the guiding vector into the residual stream of the large language model for dynamic guidance, and output the result according to the task requirements of the target task prompted by the user.
[0031] In a specific exemplary technical solution of this invention, the process of dynamically generating the guiding vector is as follows (the conditional generation model uses a conditional denoising network; the following process takes the diffusion process of the diffusion model as an example): Initialization includes: sampling a random noise vector. ; Iterative generation (sampling) includes: performing T-step generation (sampling) processes, which in the diffusion model is iterative denoising (decreasing from T to 1); where each iteration is as follows: Step 1). This uses the identification method described in the above embodiments. ; Denoising network in conditional diffusion model The predicted noise vector; For diffusion time step The corresponding guiding vector; This represents the input conditions for the conditional generation model; Step 2), according to and Calculate The standard denoised diffusion probability model (DDPM) sampling algorithm can be used; The final generated result includes: after T iterations, the final guiding vector is obtained. This is the current user prompt. Tailor-made, dynamically generated guide vectors .
[0032] In a specific exemplary technical solution of this invention, the process of applying a guidance vector and executing guidance is as follows: During LLM inference, the hidden state of the target layer is obtained, and the guiding vector generated in the aforementioned embodiment is used. Multiply by an intensity coefficient and inject into the residual stream of the LLM. Exemplarily, in a preferred embodiment, this intervention operation is applied to the same set of layers as when extracting the vectors, i.e., all layers in the latter half of the model. This operation is applied to the hidden states of all hidden states in these layers. , is represented as: ; In the formula, This indicates that after the injection of the guiding vector, the LLM's first... l The first in the layer m The hidden state after updating each word element; This indicates the LLM's first step before injecting the guiding vector. l The first in the layer mThe original hidden state of each word element; The strength coefficient; Provide the user with the corresponding guidance vector; This represents the total number of layers in the large language model.
[0033] The technical solution disclosed in this invention overcomes the key shortcomings of existing guided vector techniques in LLM inference by reconstructing the static point estimation paradigm into a dynamic conditional generation paradigm. Compared with the prior art, it has significant improvements in the following aspects, including: (1) The technical solution of the present invention transforms the generation of the guidance vector from a static "lookup table" call to a dynamic "generative" control; through task identification and condition generation, the guidance vector matching each user prompt can be dynamically generated according to the real-time semantics of each user prompt, which solves the limitation that the existing static vector cannot adapt to the changing context, and replaces the impractical "manual selection" step in the prior art, greatly improving the automation level and practical value of the technology.
[0034] (2) Existing “point estimation” methods compress concepts into a single vector, which is extremely unstable in performance. In view of this, the technical solution of this invention model the distribution manifold of the guiding vector (conditional generation model) and samples from the learned probability distribution during inference, thereby avoiding the fragility of a single vector. This provides a more reliable and robust control mechanism.
[0035] (3) In the technical solution of the embodiments of the present invention, a unified and compact condition generation model can be used to encapsulate all K This approach, which provides guidance knowledge for each task, contrasts sharply with existing guidance vector techniques that maintain a large, discrete, static vector library for each task. This significantly reduces storage overhead and greatly improves system scalability.
[0036] Please see Figure 2 , Figure 2 This paper compares and contrasts the current guided vector technology process with the process of the present invention's embodiment, focusing on the generation and application of guided vectors in a large language model, involving three main modules: task type, offline preparation, and inference stage. Regarding the offline preparation stage: the current technology constructs a "guided vector library" through "offline pre-extraction," storing static guided vectors for each task; the present invention, however, constructs a unified conditional probability distribution for guided vectors, rather than a discrete vector library, through "offline pre-extraction" of semantic bases and a "training conditional generation model." Regarding the inference stage: the current technology requires the user to input prompt words, and then manually selects matching vectors from the "guided vector library," before injecting them into the LLM's Transformer residual stream (marked "the first"). lThe present invention first performs "task matching" on user prompts, then automatically generates guidance vectors through a "generative model", and finally injects them into the LLM residual stream, without any manual intervention. The specific comparison results of multiple dimensions are shown in Table 1.
[0037] Table 1. Comparison results across multiple dimensions
[0038] In summary, this invention discloses a dynamic guidance method for large language models based on conditional generative models, specifically involving a dynamic guidance framework (DiffuSteer). Its core improvements include: no longer treating "concepts" as single vectors, but modeling them as a conditional probability distribution along effective guidance directions. This invention does not rely on static "lookup table" calls, but instead uses a conditional generation model to learn the distribution and, based on the semantics of the current user prompt (i.e., the conditions)... Dynamically "generate" the most suitable guiding vector Any generative model capable of learning such a high-dimensional conditional distribution is applicable, such as a conditional variational autoencoder (C-VAE), a conditional flow model, or a conditional diffusion model.
[0039] In a specific exemplary technical solution of this invention, the process of extracting the task semantic base (for identifying the target task to which the user prompts belong) is as follows, with the goal of providing... A predefined task type (e.g., =Authenticity, =Security, ...) Extract a "geometric signature" or "semantic base" respectively, including: Collect intermediate activation values; among which, for the first k Task types Utilize existing datasets or collect a large number of relevant prompts They are then input into a large language model to extract the hidden state activation vectors of a specified layer (which can be the last layer of an LLM). A total of indivual.
[0040] Aggregation matrix; where all activation vectors are concatenated into a task matrix. , It is the number of prompt words. D It is the dimension of the hidden state vector.
[0041] SVD decomposition; where, for the task matrix Performing Singular Value Decomposition (SVD) is represented as: In the formula, For the first k The task matrix corresponding to each predefined task; Task matrix The left singular matrix obtained by singular value decomposition; Task matrix The singular value matrix obtained by singular value decomposition; Task matrix The transpose of the right singular matrix obtained by singular value decomposition.
[0042] Extract semantic base; where, select the first d The three most important right singular vectors form an orthogonal basis. ,this That is the first k A predefined task The semantic base (or task signature); For the first k The semantic base corresponding to each predefined task; Task matrix After singular value decomposition, the first d right singular vectors in the resulting right singular matrix are sorted in descending order of singular value and correspond to the "most important" feature directions.
[0043] Stores the semantic base set of all tasks For use in online reasoning.
[0044] In the specific exemplary technical solutions of this invention, the goal during the training process of the conditional diffusion model is to train a denoising network. This enables it to learn and model conditional probability distributions. ,include: Building the training set: First, using existing methods (such as CAA or RepE), generate a large number of (guide vectors) on different subsets of data. Task tags Data pairs constitute the training set. .
[0045] In a specific implementation of this invention, the corpus may contain, for example, 200 guiding vectors for each task. These guiding vectors are generated using a specific extraction method on different subsets of data (e.g., 100 contrast pairs per set). A specific example is: calculating positive and negative samples in all layers of the latter half of the LLM model ( The last token of ) in the hidden state The difference is then averaged across all samples and all specified layers: , where N is the number of pairs.
[0046] Denoising Network Model Architecture: Denoising Network The architecture employs a Conditional Transformer U-Net, which combines the multi-scale processing capabilities of U-Net with the sequence modeling capabilities of Transformer. For example, its architecture includes a Conditional U-Net composed of Transformer blocks, which contains an input patching module that uses 1D convolutions to transform the input vector into a patch embedding sequence.
[0047] Conditional injection method: Discrete tasks The diffusion time step t is mapped to the following values through the embedding layers (nn.Embedding and sinusoidal positional encoding): and The two embedding vectors are concatenated and fused into a unified conditional signal using an MLP. This signal s is used to implement Adaptive Layer Normalization (AdaLN) in each block of the Transformer U-Net, meaning s is linearly projected to generate the scaling parameters for that block. and bias parameters In this way, task condition c can modulate the activation of each layer in the network.
[0048] The training process for generative models is basically the same as that for diffusion models: from the training set... Randomly sample a data point ( , Randomly sample a time step t and noise. Construct a noisy vector.
[0049] In summary, this invention discloses a method for modeling guided vectors in a large language model, which models guided vectors containing high-level concepts as conditional probability distributions in the hidden state space, rather than as single static vectors. Furthermore, it discloses a technical solution using a conditional generation model to learn the aforementioned conditional probability distribution. Further, this invention discloses an adaptive task recognition method for determining condition c from user prompts, which includes: first, extracting a semantic base offline, and then performing task recognition online; wherein, during offline semantic base extraction, SVD is used for each task. Extracting semantic bases from activation subspaces When performing task identification online, activate the new prompts. Project to all Above, and through geometric matching (maximum projected energy) To identify tasks Semantic base and prompt activation The guidance vector can be extracted from the layers in the latter half of the large language model; it can be injected into the residual stream of the layers in the latter half of the large language model and applied to the hidden states of all lexical units. The technical solution of this invention, through one or more of the above-mentioned improved technical means, can significantly improve the stability and automation level of large language model guidance, while also enhancing generalization ability and robustness.
[0050] The following are embodiments of the apparatus of the present invention, which can be used to execute embodiments of the method of the present invention. For details not disclosed in the apparatus embodiments, please refer to the embodiments of the method of the present invention.
[0051] Please see Figure 3 In this embodiment of the invention, a dynamic guidance system for large language models based on a conditional generation model is provided, comprising: An activation vector extraction unit is used to obtain user prompts by acquiring the activation vectors of the user prompts through a specified intervention layer of the large language model. The target task identification unit is used to project the activation vector onto the pre-extracted semantic bases of each task, and identify the target task to which the user prompt belongs through geometric matching; The dynamic guidance output unit is used to dynamically generate guidance vectors through a pre-trained conditional generation model using the target task as input conditions, and inject the guidance vectors into the residual stream of the large language model for dynamic guidance, and output the results according to the task requirements of the target task to which the user prompts belong; wherein, the conditional generation model is a generation model that can learn the conditional distribution probability of the guidance vector with respect to the conditions.
[0052] In one embodiment of the present invention, a computer device is provided, comprising a processor and a memory. The memory stores a computer program, which includes program instructions. The processor executes the program instructions stored in the computer storage medium. The processor may be a Central Processing Unit (CPU), or other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. It is the computing and control core of the terminal, suitable for implementing one or more instructions, specifically suitable for loading and executing one or more instructions in the computer storage medium to achieve a corresponding method flow or corresponding function. The processor described in this embodiment can be used to execute the operation of a dynamic guidance method for large language models based on conditional generation models.
[0053] In one embodiment of the present invention, a storage medium is provided, specifically a computer-readable storage medium (Memory), which is a memory device in a computer device used to store programs and data. It is understood that the computer-readable storage medium here can include both the built-in storage medium in the computer device and extended storage media supported by the computer device. The computer-readable storage medium provides storage space that stores the operating system of the terminal. Furthermore, the storage space also stores one or more instructions suitable for loading and execution by a processor. These instructions can be one or more computer programs (including program code). It should be noted that the computer-readable storage medium here can be high-speed RAM (Random Access Memory) or non-volatile memory, such as at least one disk storage device. The processor can load and execute one or more instructions stored in the computer-readable storage medium to implement the corresponding steps of the large language model dynamic bootstrapping method based on conditional generation models in the above embodiments.
[0054] Those skilled in the art will understand that embodiments of the present invention can be provided as methods, systems, or computer program products. Therefore, the present invention can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, the present invention can take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, optical storage, etc.) containing computer-usable program code.
[0055] This invention is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the invention. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart illustrations and / or block diagrams. Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.
[0056] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.
[0057] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.
[0058] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention and not to limit it. Although the present invention has been described in detail with reference to the above embodiments, those skilled in the art should understand that modifications or equivalent substitutions can still be made to the specific implementation of the present invention. Any modifications or equivalent substitutions that do not depart from the spirit and scope of the present invention should be covered within the scope of protection of the claims of the present invention.
Claims
1. A dynamic guidance method for large language models based on conditional generation models, characterized in that, include: Obtain user prompts by obtaining the activation vector of the user prompts through a specified intervention layer of the large language model; The activation vectors are projected onto the pre-extracted semantic bases of each task, and the target task to which the user prompt belongs is identified through geometric matching. Using the target task as input, a pre-trained conditional generation model dynamically generates a guiding vector, which is then injected into the residual stream of a large language model for dynamic guidance. The result is output according to the task requirements of the target task to which the user prompt belongs. The conditional generation model is a generative model that can learn the conditional distribution probability of the guiding vector with respect to the conditions.
2. The method for dynamic guidance of a large language model based on a conditional generation model according to claim 1, characterized in that, The extraction steps for each task's semantic base include: Based on a predefined task, relevant prompts are collected and input into a large language model to extract hidden state activation vectors. The hidden state activation vectors are concatenated into a task matrix, and singular value decomposition is performed on the task matrix; based on the decomposition results, the top-ranked tasks are selected. d The three most important right singular vectors form an orthogonal basis, which serves as the semantic basis for the predefined task; among them, d The number of predefined vectors.
3. The method for dynamic guidance of a large language model based on a conditional generation model according to claim 1, characterized in that, The steps for identifying the target task to which the user prompt belongs through geometric matching include: Calculate the projection energy on each semantic basis and use it as the matching score. Select the task with the highest matching score as the target task to which the user prompt belongs. The expression for calculating the matching score is as follows: ; In the formula, Represents the activation vector With the k Semantic base for each task Match score; Activation vector In the k Semantic base for each task The squared L2 norm of the projection vector.
4. The method for dynamic guidance of a large language model based on a conditional generation model according to claim 1, characterized in that, The conditional generation model is specifically a conditional variational autoencoder, a conditional flow model, or a conditional diffusion model.
5. The method for dynamic guidance of a large language model based on a conditional generation model according to claim 1, characterized in that, During the training process of the conditional generation model, each training sample in the training set consists of a guiding vector and a corresponding task label.
6. The method for dynamic guidance of a large language model based on a conditional generation model according to claim 1, characterized in that, In the step of dynamically guiding the process by injecting the guiding vector into the residual stream of the large language model, the hidden state update expression is: ,for ; In the formula, This indicates that after injecting the guiding vector, the large language model's... l The first in the layer m The hidden state after updating each word element; This indicates that before the injection of the guiding vector, the large language model's first... l The first in the layer m The original hidden state of each word element; The strength coefficient; Provide the user with the corresponding guidance vector; This represents the total number of layers in the large language model.
7. A dynamic guidance system for large language models based on conditional generation models, characterized in that, include: An activation vector extraction unit is used to obtain user prompts by acquiring the activation vectors of the user prompts through a specified intervention layer of the large language model. The target task identification unit is used to project the activation vector onto the pre-extracted semantic bases of each task, and identify the target task to which the user prompt belongs through geometric matching; The dynamic guidance output unit is used to dynamically generate guidance vectors through a pre-trained conditional generation model using the target task as input conditions, and inject the guidance vectors into the residual stream of the large language model for dynamic guidance, and output the results according to the task requirements of the target task to which the user prompts belong; wherein, the conditional generation model is a generation model that can learn the conditional distribution probability of the guidance vector with respect to the conditions.
8. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the program, it implements the dynamic guidance method for large language models based on conditional generation models as described in any one of claims 1 to 6.
9. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by the processor, it implements the dynamic guidance method for large language models based on conditional generation models as described in any one of claims 1 to 6.
10. A computer program product, characterized in that, It includes computer instructions that, when executed by a processor, implement the steps of the dynamic guidance method for a large language model based on a conditional generative model as described in any one of claims 1 to 6.