Large language model reasoning correction method and device
By acquiring the reasoning behavior information and hidden layer activation state of a large language model, calculating the real-time offset score and correcting the hidden layer state, the problem of model inference offset is solved, and an efficient and accurate correction effect is achieved.
Patent Information
- Application Number
- CN202610504202.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-04-16
- Publication Date
- 2026-07-14
AI Technical Summary
Large language models are extremely sensitive to small perturbations when dealing with long sequence reasoning tasks, and are prone to reasoning deviations. Existing error correction schemes are costly and cannot correct deviations in a timely manner, resulting in inaccurate reasoning results.
By acquiring behavioral information and hidden activation states of the inference steps, the real-time offset score is calculated using the baseline activation prototype, alternative correction manipulation vectors are extracted and dynamic correction vectors are calculated, and the hidden activation state information is corrected to block erroneous inference paths.
Without interrupting model generation, the inference bias risk is quantified in real time, and the correction vector is adaptively generated, which improves the model inference accuracy and reduces costs.
Smart Images

Figure CN122389937A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of artificial intelligence technology, and in particular to a method and apparatus for correcting inference in large language models. Background Technology
[0002] Currently, large language models with advanced reasoning capabilities have become an important development direction in the field of general artificial intelligence. Large language models (LLMs) can generate explicit, multi-step reasoning trajectories by introducing chain-of-thought (CoT) prompting technology to handle complex tasks such as mathematical solving, logical inference and code generation.
[0003] However, when large language models handle long-sequence reasoning tasks, their reasoning trajectories are often extremely sensitive to minute perturbations. Even a tiny resampling or substitution in an intermediate reasoning step can cause an "avalanche effect" in subsequent reasoning processes, ultimately leading to completely different or even illogical conclusions. This instability in the reasoning process is not purely random noise, but manifests as a "reasoning drift" phenomenon. Specifically, the model may fall into specific unintended pathological behavior patterns during state transitions. For example, the model may prematurely enter the plan generation stage without fully understanding the problem setup, or get caught in blind and ineffective computational loops without timely uncertainty management and self-reflection.
[0004] In related technologies, existing inference error correction schemes mainly adopt self-consistency methods based on multiple sampling and consensus voting or search algorithms based on path exploration. These methods rely heavily on generating a large number of candidate paths or performing repeated backtracking searches during the inference process, resulting in high computational and time costs. Moreover, most of the above methods only treat the large language model as a "black box" generator, and only passively screen and filter at the final output or intermediate nodes of the model, but cannot correct the deviation in time when the model is about to deviate from the inference, resulting in inaccurate inference results. Summary of the Invention
[0005] This invention provides a method and apparatus for correcting inference in a large language model, which solves the problem that existing inference correction schemes rely heavily on generating a large number of candidate paths or performing repeated backtracking searches during the inference process, resulting in high costs and the inability to correct inference deviations in a timely manner when the model is about to deviate, leading to inaccurate inference results.
[0006] This invention provides a method for correcting inference in a large language model, comprising: Obtain the reasoning behavior information and the hidden activation state information of the corresponding word units in the first reasoning step; the first reasoning step is obtained by sequential reasoning based on the large language model; The reasoning behavior information is classified to obtain the first reasoning behavior category information, and the real-time offset score of the word shifting to the potential erroneous behavior category is calculated using the baseline activation prototype and the hidden activation state information; wherein, the baseline activation prototype is determined by the state transition comparison data obtained by the large language model performing multi-step reasoning and the average hidden activation corresponding to various reasoning behavior information. When the real-time offset score is greater than zero, based on the first inference behavior category information and the real-time offset score, a candidate correction control vector corresponding to the first inference behavior category information is extracted from a preset correction control vector library, and a dynamic correction vector is calculated using the candidate correction control vector and the real-time offset score. The hidden layer activation state information is corrected using the dynamic correction vector, and the corrected hidden layer activation state information is input into the large language model.
[0007] According to the present invention, a large language model reasoning correction method is provided, wherein the baseline activation prototype includes positive and negative prototypes corresponding to multiple potential erroneous behavior categories; The calculation of the real-time offset score of the inference shift of the lexical towards the potential erroneous behavior category using the benchmark activation prototype and the hidden layer activation state information includes: Calculate the first cosine similarity between the hidden layer activation state information and the negative prototype corresponding to the target potential error behavior category, and calculate the second cosine similarity between the hidden layer activation state information and the positive prototype corresponding to the target potential error behavior category; wherein, the target potential error behavior category is at least one of the plurality of potential error behavior categories; If the first cosine similarity is greater than the second cosine similarity, the first cosine similarity is determined as the real-time offset score of the target potential erroneous behavior category.
[0008] According to the present invention, a large language model reasoning correction method is provided, wherein the candidate correction control vectors include multiple, and different candidate correction control vectors correspond to different transfer directions, wherein the transfer direction is used to indicate the transfer from the first reasoning behavior category information to the target potential erroneous behavior category; The process of calculating the dynamic correction vector using the candidate correction control vector and the real-time offset fraction includes: Obtain multiple real-time offset scores corresponding to multiple potential error behavior categories; The dynamic correction vector is obtained by weighting and summing multiple candidate correction control vectors using the real-time offset scores corresponding to each potential erroneous behavior category.
[0009] According to the present invention, a method for correcting inference in a large language model includes, in which the dynamic correction vector is used to correct the hidden layer activation state information, the method comprises: The dynamic correction vector is multiplied by a preset intervention intensity coefficient to obtain the adjusted dynamic correction vector. The adjusted dynamic correction vector is superimposed on the original hidden activation state information of the word to obtain the corrected hidden activation state information.
[0010] According to the large language model inference correction method provided by the present invention, the state transition comparison data is obtained in the following manner: Obtain the original inference trajectory and the preceding context data of the second inference step generated by the large language model, wherein the second inference step is obtained later than the first inference step; With the prior context data shared, multiple unfolded inference trajectories are generated by resampling. These multiple unfolded inference trajectories include alternative inference steps, which are used to instruct the large language model to reason sequentially to the correct or incorrect result. Calculate the average accuracy of the expanded reasoning trajectory to obtain a first accuracy; calculate the average accuracy of the original reasoning trajectory to obtain a second accuracy; determine the second reasoning behavior category information of the second reasoning step based on the first accuracy and the second accuracy. The alternative reasoning step, the second reasoning step, and the second reasoning behavior category information are combined, and the state transition comparison data is determined based on the combined data; the combined data includes preferred subsequent state data and non-preferred subsequent state data.
[0011] According to a large language model reasoning correction method provided by the present invention, the alternative reasoning step includes a first alternative reasoning step and a second alternative reasoning step, wherein the first alternative reasoning step corresponds to the correct result and the second alternative reasoning step corresponds to the incorrect result; Combining the alternative reasoning step, the second reasoning step, and the second reasoning behavior category information includes: If the first accuracy rate is higher than the second accuracy rate, the first alternative reasoning step is used as the subsequent state data of the preference, and the second reasoning step is used as the subsequent state data of the non-preference. If the first accuracy rate is higher than the second accuracy rate, the second inference step is used as the subsequent state data of the preference, and the second alternative inference step is used as the subsequent state data of the non-preference.
[0012] According to the large language model reasoning correction method provided by the present invention, the hidden activation average values corresponding to the various reasoning behavior information include: the hidden layer activation average value belonging to the subsequent state of preference under each reasoning behavior category, and the hidden layer activation average value belonging to the subsequent state of non-preference. The positive prototype in the baseline activation prototype is constructed based on the average hidden activation of the subsequent preferred state, and the negative prototype in the baseline activation prototype is constructed based on the average hidden activation of the subsequent unpreferred state. The alternative correction manipulation vector is obtained based on the difference between the average hidden activation of lexical units in all preferred subsequent states and the average hidden activation of lexical units in all non-preferred subsequent states under the target transfer category.
[0013] The present invention also provides a large language model inference correction device, comprising: The information acquisition module is used to acquire the reasoning behavior information of the first reasoning step and the hidden activation state information of the corresponding word; the first reasoning step is obtained by sequential reasoning based on the large language model; The offset score calculation module is used to classify the reasoning behavior information to obtain the first reasoning behavior category information, and to calculate the real-time offset score of the word shifting to the potential erroneous behavior category using the baseline activation prototype and the hidden activation state information; wherein, the baseline activation prototype is determined by the state transition comparison data obtained by the large language model performing multi-step reasoning and the average hidden activation corresponding to various reasoning behavior information. The correction vector calculation module is used to extract candidate correction control vectors corresponding to the first inference behavior category information from a preset correction control vector library based on the first inference behavior category information and the real-time offset score when the real-time offset score is greater than zero, and to calculate a dynamic correction vector using the candidate correction control vectors and the real-time offset score. The correction module is used to correct the hidden layer activation state information using the dynamic correction vector, and input the corrected hidden layer activation state information into the large language model.
[0014] The present invention also 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 executes the computer program to implement the large language model inference correction method as described above.
[0015] The present invention also provides a non-transitory computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the large language model inference correction method as described above.
[0016] The large language model reasoning correction method and apparatus provided by this invention can accurately capture the current reasoning context of the model and deeply explore the micro-computational state inside the model by acquiring reasoning behavior information of the first reasoning step and the hidden activation state information of the corresponding word. By obtaining category information through classification and calculating real-time offset scores, the risk of the large language model falling into reasoning deviation can be quantified in real time without interrupting model generation. By extracting candidate correction manipulation vectors and calculating dynamic correction vectors, correction vectors can be adaptively generated for the model's error tendency. Finally, the hidden state is corrected by using dynamic correction vectors and input into the model. This can block the spread of erroneous reasoning paths without retraining the model, reduce reasoning costs, and improve the model's reasoning accuracy. Attached Figure Description
[0017] 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.
[0018] Figure 1 This is one of the flowcharts illustrating the large language model reasoning correction method provided by this invention.
[0019] Figure 2 This is the second flowchart of the large language model reasoning correction method provided by the present invention.
[0020] Figure 3 This is a schematic diagram illustrating the relationship between reasoning trajectory and reasoning success rate provided by the present invention.
[0021] Figure 4 This is a schematic diagram of the structure of the large language model reasoning correction device provided by the present invention.
[0022] Figure 5 This is a schematic diagram of the structure of the electronic device provided by the present invention. Detailed Implementation
[0023] To make the objectives, technical solutions, and advantages of this invention clearer, the technical solutions of this invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of this invention. All other embodiments obtained by those skilled in the art based on the embodiments of this invention without creative effort are within the scope of protection of this invention.
[0024] The following is combined with Figures 1-4 The present invention describes a method and apparatus for correcting inference using a large language model.
[0025] Figure 1 This is one of the flowcharts illustrating the large language model inference correction method provided by this invention, such as... Figure 1 As shown, the method includes the following: Step 110: Obtain the reasoning behavior information of the first reasoning step and the hidden activation state information of the corresponding word; the first reasoning step is obtained by reasoning sequentially based on the large language model.
[0026] In this step, the first reasoning step can be a complete logical deduction fragment (such as a sentence or formula in the thought chain) that has been completed or is being executed during the multi-step autoregressive generation process of the large language model.
[0027] In this step, the reasoning behavior information can be the characteristic information of the first reasoning step in the entire problem-solving process, including reasoning intention, action, and object.
[0028] In this step, a token refers to the smallest basic unit (such as a word or a character) that a large language model processes in text; the hidden activation state information refers to the high-dimensional vector representation of the token when it passes through a specific Transformer layer inside the model. The hidden activation state information includes the model's current internal thinking state.
[0029] For example, in a math problem scenario of calculating store sales profit, the large language model generates reasoning trajectories in sequence, such as "First, we need to calculate the total purchase cost of apples" (i.e., the first reasoning step); the system (the subject of the method execution) first extracts text features from the sentence as reasoning behavior information. At the same time, when the model is about to generate the next word (e.g., "total"), the system will capture the internal multi-dimensional floating-point vector of that word in the specific Transformer layer of the model in real time (i.e., hidden layer activation state information).
[0030] Step 120: Classify the reasoning behavior information to obtain the first reasoning behavior category information, and use the baseline activation prototype and hidden activation state information to calculate the real-time offset score of the reasoning shift of the lexical to the potential erroneous behavior category; wherein, the baseline activation prototype is determined by the state transition comparison data obtained by performing multi-step reasoning in the large language model and the average hidden activation corresponding to various reasoning behavior information.
[0031] In this step, inference bias refers to the tendency of a model to fall into a specific unintended pathological behavior pattern from a previous healthy inference state during a coherent state transition in inference.
[0032] In this step, the first reasoning behavior category information can be predicted from the historical text by a pre-trained reasoning behavior classifier; for example, the first reasoning behavior category information can be the following labels: plan generation, uncertainty management, or calculation execution.
[0033] In this embodiment, the baseline activation prototype includes a positive prototype (indicating that the current inference is normal) and a negative prototype (indicating that the current inference is abnormal).
[0034] In this embodiment, the state transition comparison data refers to the sample set constructed during the offline database construction phase, which is used to distinguish between healthy and pathological reasoning features of the model.
[0035] In this embodiment, the hidden activation averages corresponding to various reasoning behavior information include: the hidden activation averages belonging to the subsequent states of preference under each reasoning behavior category, and the hidden activation averages belonging to the subsequent states of non-preference.
[0036] In this embodiment, the real-time offset score is used to measure the risk of the model currently generating lexical terms deviating from the correct path and falling into a specific pathological pattern (such as blindly calculating loops or drawing conclusions too early).
[0037] For example, in the math problem scenario above, the system first classifies the previous sentence "First, we need to calculate the total procurement cost of apples" into the planning generation stage (i.e., the first reasoning behavior category information) using a classifier. Then, the system compares the hidden activation state information of the current word "total" with the baseline activation prototype of the potential error category "blind calculation loop" calculated during offline database building. If it finds that the similarity between the current word and the "negative prototype" representing the error state is greater than the similarity with the "positive prototype" representing the correct state, the system will calculate a value greater than zero as the real-time offset score of the word when reasoning is about to go off track.
[0038] Step 130: When the real-time offset score is greater than zero, extract the candidate correction control vector corresponding to the first inference behavior category information from the preset correction control vector library based on the first inference behavior category information and the real-time offset score, and calculate the dynamic correction vector using the candidate correction control vector and the real-time offset score.
[0039] In this embodiment, the pre-set correction control vector library can be a set of steering wheels pre-calculated in the offline stage to pull the model back to the right track from different erroneous directions; among them, the alternative correction control vector refers to all possible thrust vectors that can be used under the current specific context node; the dynamic correction vector is a comprehensive correction force that best fits the current context after combining the deviation risks of each direction.
[0040] For example, in the aforementioned mathematical problem of calculating profit, if the system finds that the current real-time offset score is greater than zero (e.g., a score of 0.8 indicates that the model is very likely to forget to sort out the conditions first and instead fall directly into a blind and ineffective calculation loop), the system will retrieve multiple candidate correction control vectors from the offline database based on the previously determined "plan generation" (i.e., the first reasoning behavior category information). These vectors will be used to prevent the model from sliding into "ineffective calculation" and to prevent it from sliding into "premature conclusion". Then, the system will use the score of 0.8 as a weight to perform a weighted summation of these candidate vectors to obtain a dynamic correction vector for the current dangerous state.
[0041] Step 140: Use dynamic correction vectors to correct the hidden layer activation state information, and input the corrected hidden layer activation state information into the large language model.
[0042] In this step, the corrected hidden activation state information refers to a healthy and unbiased new hidden vector representation formed by superimposing the thrust representing the correct reasoning direction onto the internal vector of the model that originally had an error tendency.
[0043] In this embodiment, the corrected hidden layer activation state information is sent to the next self-attention layer of the large language model to continue to participate in forward propagation. Affected by this hidden layer intervention, the model re-outputs the corrected inference result.
[0044] For example, in the final stage of the math problem scenario mentioned above, the system superimposes the calculated dynamic correction vector onto the original hidden activation state information of the current word "total". Finally, the system sends this corrected hidden activation state information into the next Transformer layer of the large language model to continue to participate in forward propagation. The model abandons the series of invalid numbers it originally wanted to output and instead rationally outputs "Apple's total procurement cost is: unit price multiplied by quantity", returning to the correct logical track.
[0045] The large language model inference correction method provided in this invention can accurately capture the current inference context of the model and deeply explore the micro-computation state inside the model by acquiring the inference behavior information of the first inference step and the hidden activation state information of the corresponding word. By obtaining category information through classification and calculating real-time offset scores, the risk of the large language model falling into inference deviation can be quantified in real time without interrupting the model generation. By extracting candidate correction manipulation vectors and calculating dynamic correction vectors, correction vectors can be adaptively generated for the model's error tendency. Finally, the hidden state is corrected by using dynamic correction vectors and input into the model. This method can block the spread of erroneous inference paths, reduce inference costs, and improve the model's inference accuracy without retraining the model.
[0046] In some embodiments, the baseline activation prototype includes positive and negative prototypes corresponding to multiple potential error behavior categories; calculating the real-time offset score of the inference shift of the lexical to the potential error behavior category using the baseline activation prototype and hidden activation state information includes: calculating a first cosine similarity between the hidden activation state information and the negative prototype corresponding to the target potential error behavior category, and calculating a second cosine similarity between the hidden activation state information and the positive prototype corresponding to the target potential error behavior category; wherein the target potential error behavior category is at least one of multiple potential error behavior categories; if the first cosine similarity is greater than the second cosine similarity, the first cosine similarity is determined as the real-time offset score of the target potential error behavior category.
[0047] In this embodiment, the positive prototype in the baseline activation prototype is constructed based on the average hidden activation of the preferred subsequent state; the negative prototype in the baseline activation prototype is constructed based on the average hidden activation of the unpreferred subsequent state.
[0048] Specifically, the positive prototype refers to the average hidden activation vector calculated offline, representing healthy reasoning (preferring subsequent states) under a specific behavioral category, while the negative prototype refers to the average hidden activation vector representing pathological reasoning (not favoring subsequent states) under a specific behavioral category.
[0049] In this embodiment, the target potential error behavior category refers to the various specific types of derailment risks currently faced by the model, such as the model getting stuck in a blind and ineffective computational loop, or generating a plan prematurely without fully understanding the problem.
[0050] In this embodiment, the first cosine similarity reflects the degree to which the current state of the model tends towards an ill-conditioned pattern, and the second cosine similarity reflects the degree to which the current state of the model tends towards a healthy pattern.
[0051] Specifically, the cosine similarity between the hidden activation state of the current word and the negative and positive prototypes of a specific behavior category is calculated, and a threshold gate is used with an indicator function: only when the similarity with the negative prototype is greater than the similarity with the positive prototype, the real-time offset score based on the difference between the two (or the similarity with the negative prototype) is output; otherwise, the output score is zero.
[0052] Specifically, in the current step of autoregressive generation of large language models When processing each word, extract the corresponding hidden layer activation state of that word in real time. To determine whether the morpheme is sliding toward a potential erroneous behavior category. For all possible candidate categories Calculate the real-time offset score .
[0053] This embodiment uses a gating mechanism with an indicator function to calculate the score. The specific formula is as follows: ; in, Represents cosine similarity. For indicator functions; the formula shows that only if the current lexical unit matches the negative prototype of a specific category... The similarity is strictly greater than its similarity to the positive prototype. The offset score is a non-zero positive value only when the similarity is high (i.e., the model does show a strong tendency to shift towards the pathological pattern); otherwise, the score is zero and no invalid intervention is triggered.
[0054] For example, when using a large language model to solve a math problem, the model is generating the word "total". The system pre-retrieves a baseline activation prototype for the potential erroneous behavior category of "blind and ineffective computation loop". At this time, the system obtains the hidden activation state information of this word in real time and performs two distance measurements: First, it calculates the first cosine similarity between this hidden state and the negative prototype corresponding to "ineffective computation" (assuming the result is 0.82); second, it calculates the second cosine similarity between this hidden state and the positive prototype corresponding to healthy reasoning (assuming the result is 0.45). Since 0.82 is significantly greater than 0.45 (i.e., the condition that the first cosine similarity is greater than the second cosine similarity is met), this clearly indicates that the model is currently brewing a shift in the erroneous direction. Based on this threshold gating logic, the system immediately determines the value of the first cosine similarity, 0.82, as the real-time offset score of the current word shifting towards "ineffective computation"; if the first cosine similarity is less than the second cosine similarity, it means that the model's reasoning is healthy, the score is zero, and no subsequent operation is triggered.
[0055] The large language model reasoning correction method provided in this invention calculates the bicosine similarity with negative / positive prototypes and uses size comparison for threshold gating to obtain real-time offset scores. This method can accurately quantify reasoning offset risks and avoid invalid interference.
[0056] In some embodiments, there are multiple candidate correction control vectors, and different candidate correction control vectors correspond to different transfer directions. The transfer direction is used to indicate the transfer from the first inference behavior category information to the target potential erroneous behavior category. The dynamic correction vector is calculated using the candidate correction control vectors and the real-time offset scores, including: obtaining multiple real-time offset scores corresponding to multiple potential erroneous behavior categories respectively; and using the real-time offset scores corresponding to each potential erroneous behavior category as weights, performing a weighted summation of the multiple candidate correction control vectors to obtain the dynamic correction vector.
[0057] In this embodiment, the alternative correction manipulation vector is obtained based on the difference between the average hidden activation of lexical units in all preferred subsequent states and the average hidden activation of lexical units in all non-preferred subsequent states under the target transition category.
[0058] In this embodiment, the alternative correction control vectors can be multiple independent thrust vectors that are calculated offline and pre-stored, each vector being responsible for blocking a specific error evolution path.
[0059] In this embodiment, the direction of shift refers to the evolutionary trajectory of the large language model as it derails from the healthy first reasoning behavior category information (such as plan generation) of the previous step to various specific pathological patterns (such as blind calculation loops or premature conclusions).
[0060] In this embodiment, multiple independent thrust vectors are linearly combined using scores representing the severity of various errors as coefficients to obtain a combined intervention force that takes into account multiple risks in a multidimensional hidden layer space, namely a dynamic correction vector.
[0061] Specifically, after obtaining the current lexical unit for all potential error categories... After obtaining the real-time offset score, the system performs context-aware soft intervention; first, the category determined in the previous step... Based on the search criteria, retrieve all relevant candidate manipulation vectors from the offline vector library. Next, using the corresponding real-time offset scores as weights, dynamic weighted aggregation is performed to generate a dynamic correction vector. : .
[0062] For example, in a scenario where a large language model is solving a math problem, after the model has completed the "plan generation" step (i.e., the first inference behavior category information), it is generating the next lexical unit. The system monitors in real time in the hidden layer that the lexical unit is at risk of slipping in two different directions. The real-time offset score for shifting to "blind and ineffective calculation loops" is as high as 0.8, and the real-time offset score for shifting to "premature conclusions" is 0.3. At this time, the system will simultaneously retrieve two alternative correction control vectors (let's say vector A and vector B) from the database for these two types of errors. Then, the system uses 0.8 and 0.3 as weights to perform a weighted summation calculation of "0.8 × vector A + 0.3 × vector B", and finally obtains the dynamic correction vector.
[0063] The large language model inference correction method provided in this invention obtains the real-time offset scores of multiple potential error categories and uses these scores as weights to perform a weighted summation of multiple candidate correction manipulation vectors. In the face of complex inference contexts with multiple concurrent pathological transfer risks, it can adaptively aggregate the most targeted comprehensive correction force, thereby improving the robustness of the model's long sequence inference.
[0064] In one embodiment, the method of correcting the hidden activation state information using a dynamic correction vector includes: multiplying the dynamic correction vector by a preset intervention intensity coefficient to obtain an adjusted dynamic correction vector; and superimposing the adjusted dynamic correction vector onto the original hidden activation state information of the word to obtain the corrected hidden activation state information.
[0065] In this embodiment, the preset intervention intensity coefficient can be a hyperparameter. This is used to finely control the intervention force applied inside the model. The adjusted dynamic correction vector obtained by multiplying the two represents the final safety control amount to be injected into the model.
[0066] In this embodiment, the dynamic correction vector is superimposed onto the original hidden activation state information of the current word unit through vector addition. The resulting corrected hidden activation state information maintains the basic semantic generation capability while avoiding specific pathological reasoning tendencies.
[0067] Specifically, in obtaining the dynamic correction vector Then, the dynamic correction vector is multiplied by a preset intervention intensity hyperparameter. This is directly superimposed onto the original hidden activation state of the word, as expressed by the following formula: ; Among them, the corrected hidden layer activation state information, i.e. the corrected activation state It will be sent to subsequent Transformer layers to continue participating in the calculation, thereby achieving surgical-like precise trajectory correction without interrupting the normal reasoning of the model. This process is executed cyclically when generating each word in the thought chain until the reasoning ends.
[0068] For example, in a scenario where a large language model is used to solve a math problem, the system has already generated a dynamic correction vector to prevent the model from getting stuck in a "blind calculation loop". Then, 0.15 is multiplied by this dynamic correction vector to attenuate its absolute magnitude, resulting in an adjusted dynamic correction vector. Subsequently, in a specific Transformer layer where the model is propagating forward, the system can use an interception hook mechanism to directly superimpose this adjusted vector onto the original hidden activation state information of the currently generated lexical "total". After the addition is completed, the system sends the corrected hidden activation state information into the next layer of the model for further computation.
[0069] The large language model inference correction method provided in this invention achieves effective intervention on the inference trajectory by multiplying the dynamic correction vector with the intervention intensity coefficient and superimposing it into the original hidden state, thereby ensuring that the model can smoothly deviate from the erroneous trajectory.
[0070] In some embodiments, state transition comparison data is obtained as follows: The original inference trajectory and the preceding context data of the second inference step generated by the large language model are obtained, where the second inference step is obtained later than the first inference step; in the case of shared preceding context data, multiple unfolded inference trajectories are generated by resampling, each including an alternative inference step used to instruct the large language model to reason sequentially to the correct or incorrect result; the average accuracy of the unfolded inference trajectories is calculated to obtain a first accuracy, and the average accuracy of the original inference trajectory is calculated to obtain a second accuracy; the second inference behavior category information of the second inference step is determined based on the first and second accuracy; the alternative inference step, the second inference step, and the second inference behavior category information are combined, and state transition comparison data is determined based on the combined data; the combined data includes preferred subsequent state data and unpreferred subsequent state data.
[0071] In this embodiment, the state transition comparison data refers to the sample set constructed during the offline database construction phase, which is used to distinguish between healthy and pathological reasoning features of the model.
[0072] In this embodiment, the original reasoning trajectory is a complete thought chain text generated when the large language model answers the question for the first time, and the second reasoning step refers to an intermediate reasoning segment to be evaluated extracted from the thought chain.
[0073] In this embodiment, the preceding context data refers to all the premise texts that have been generated before this segment. By resampling and expanding the inference trajectory, the model can generate new subsequent texts multiple times.
[0074] In this embodiment, the alternative inference step can be a new branch node generated by resampling, which guides the model toward the correct or incorrect result.
[0075] In this embodiment, the first accuracy rate is used to reflect the overall potential success rate of re-diverging based on the current prior conditions, and the second accuracy rate is used to reflect the actual success rate of continuing along the original steps; by comparing the second reasoning behavior category information determined by the two, it is used to judge whether the original step has potential (healthy) or no potential (pathological).
[0076] In this embodiment, the preference-based subsequent state data and the non-preference-based subsequent state data obtained after combining these steps constitute a positive and negative example for the subsequent calculation of the correction vector.
[0077] For example, when the large language model solves the math problem of "store inventory profit calculation" in the offline stage, the model generates an original inference path, which includes an intermediate step of "directly adding up the unit prices of all goods to obtain the total cost" (i.e., the second inference step); the system has already correctly listed the quantity of each item (i.e., the preceding context data); the system keeps the preceding content unchanged, triggering the model to resample and generate multiple expanded inference paths. These new paths contain various alternative inference steps, such as some steps that write "calculate the product of the unit price and quantity of each item respectively," thus leading to the final correct result, while others lead to incorrect results; the system The system calculates the average accuracy of multiple new trajectories (assumed to be 85%, i.e., the first accuracy) and compares it with the accuracy of the original trajectory (assumed to be 10%, i.e., the second accuracy). Since 85% is much greater than 10%, the system classifies the second reasoning behavior category information of the original step as an "error state lacking potential" based on the comparison results. Subsequently, the system categorizes the alternative steps leading to the correct result as preferred subsequent state data and categorizes the second reasoning step that caused the error as unpreferred subsequent state data. Finally, the system combines the above data to obtain state transition comparison data that accurately describes how the model moves from "healthy" to "pathological".
[0078] The large language model reasoning correction method provided in this invention resamples by fixing the preceding context and extracts positive and negative data triples based on the comparison between the expanded accuracy and the original accuracy. This enables the discovery of micro-discrepancies between pathological and healthy reasoning within the large language model without extensive manual annotation in the offline stage, thus providing a basis for extracting high-precision benchmark activation prototypes and calculating accurate correction vectors.
[0079] In some embodiments, the alternative reasoning step includes a first alternative reasoning step and a second alternative reasoning step, where the first alternative reasoning step corresponds to a correct result and the second alternative reasoning step corresponds to an incorrect result; combining the alternative reasoning step, the second reasoning step, and the second reasoning behavior category information includes: if the first accuracy rate is higher than the second accuracy rate, using the first alternative reasoning step as preferred subsequent state data and the second reasoning step as unpreferred subsequent state data; if the first accuracy rate is higher than the second accuracy rate, using the second reasoning step as preferred subsequent state data and the second alternative reasoning step as unpreferred subsequent state data.
[0080] In this embodiment, the first alternative reasoning step refers to the healthy branch node explored during the resampling process that can lead the model to the correct result, while the second alternative reasoning step refers to the ill-conditioned branch node that leads to the incorrect result.
[0081] In this embodiment, the comparison between the first accuracy rate (i.e., the average accuracy rate of the unfolded trajectory) and the second accuracy rate (i.e., the accuracy rate of the original trajectory) is used to determine the quality of the original step.
[0082] Specifically, when the first accuracy rate is higher than the second accuracy rate, it indicates that the model has deviated from the original trajectory, and the original second inference step lacks potential. Therefore, it is treated as unfavorable subsequent state data (a negative example), while the resampled correct branch is treated as favorable subsequent state data (a positive example). Conversely (i.e., when the first accuracy rate is lower than the second accuracy rate), it indicates that the original step itself is on the correct track and has potential. In this case, the original step itself is treated as favorable subsequent state data, while the resampled incorrect branch is treated as unfavorable subsequent state data, thus completing the combination of comparison data.
[0083] The large language model inference correction method provided in this invention, by quantitatively comparing the resampling accuracy with the original accuracy, cross-divides the original steps and the corresponding replacement steps into preferred and non-preferred states, can automatically extract two typical state transition comparison triplets: the correction scenario and the derailment scenario, thereby providing highly contrasting low-level feature data for extracting high-quality correction vectors.
[0084] Figure 2 This is the second flowchart of the large language model reasoning correction method provided by the present invention. Figure 2 In the illustrated embodiment, the method includes two steps: pre-computing the correction vector library and the real-time correction process; wherein, in the pre-computing correction vector library, the preceding inference step S... t-1 (behavior type is) i The next step corresponding to the preference d + and the next step that is not preferred d- (behavior type is) j Subtracting the activation values of the hidden layers corresponding to these two states yields a vector representing a specific transition direction. i→j Next, the vector is filled into the corresponding position in the matrix of the correction vector library, i.e., row i, column j. Finally, the data for the next step, including both preferred and unpreferred values, are processed through activation value averaging. d + Data averaging generates a positive benchmark to activate the prototype. p j + ,Will d - Data averaging generates a negative baseline activation prototype. p j - During real-time correction, the activation state of the lexical units being generated in the current inference step is obtained through the preceding inference steps and marked as 'a'. token (Unknown behavior type) will change the current active state a token respectively with p j + , p j - A comparison is made, and the figure shows two contrasting scenarios: normal and offset. Based on the comparison results, a set of offset scores is calculated (the scores shown in the figure are: 0, 0, 0.6, 0.2). This is based on the behavior type of the preceding steps. i Extract the corresponding whole row vector from the correction vector library. i The offset score is then multiplied and weighted by the row vector (as shown in x) to obtain a comprehensive correction vector vector. correction (i.e., dynamic correction vector); finally, the vector... correction With a token The corrected hidden activation state information is obtained by using the "+" operation. .
[0085] Figure 3 This is a schematic diagram illustrating the correlation between reasoning trajectory and reasoning success rate provided by the present invention. Figure 3 In the illustrated embodiment, in the preceding reasoning step S t-1 Extending to the current reasoning step S t When, if S t For potential steps, from S t The subsequent multiple trajectories all exhibited higher reasoning success rates; simultaneously, the preceding reasoning step S t-1 It can also be extended to other step branches, such as Tt and the corresponding erroneous derivation and reasoning trajectory. and Among them, the reasoning can be successful (corresponding to ✓). and Unable to reason successfully, meaning that an incorrect reasoning trajectory has a lower success rate; if S t For steps with no potential, from S t The subsequent development of multiple trajectories resulted in unsuccessful reasoning (corresponding to ×), meaning that steps with no potential correspond to even lower success rates; the preceding reasoning step S t-1 It can also be extended to other step branches, such as T t and the corresponding correct development and reasoning trajectory. and ,in, and The reasoning can be successful, meaning that correctly unfolding the reasoning trajectory has a lower success rate.
[0086] The following describes the large language model reasoning correction device provided by the present invention. The large language model reasoning correction device described below and the large language model reasoning correction method described above can be referred to in correspondence.
[0087] Figure 4 This is a schematic diagram of the structure of the large language model reasoning correction device provided by the present invention, as shown below. Figure 4 As shown, the large language model inference correction device includes: an information acquisition module 410, an offset score calculation module 420, a correction vector calculation module 430, and a correction module 440.
[0088] The information acquisition module 410 is used to acquire the reasoning behavior information of the first reasoning step and the hidden activation state information of the corresponding word; the first reasoning step is obtained by sequential reasoning based on the large language model; The offset score calculation module 420 is used to classify the reasoning behavior information to obtain the first reasoning behavior category information, and to calculate the real-time offset score of the reasoning shift of the lexical to the potential erroneous behavior category using the baseline activation prototype and hidden activation state information; wherein, the baseline activation prototype is determined by the state transition comparison data obtained by performing multi-step reasoning in a large language model and the average hidden activation corresponding to various reasoning behavior information. The correction vector calculation module 430 is used to extract candidate correction control vectors corresponding to the first inference behavior category information from a preset correction control vector library based on the first inference behavior category information and the real-time offset score when the real-time offset score is greater than zero, and to calculate the dynamic correction vector using the candidate correction control vectors and the real-time offset score. The correction module 440 is used to correct the hidden layer activation state information using dynamic correction vectors and input the corrected hidden layer activation state information into the large language model.
[0089] The large language model inference correction device provided in this invention can accurately capture the current inference context of the model and deeply explore the micro-computation state inside the model by acquiring the inference behavior information of the first inference step and the hidden activation state information of the corresponding word. By obtaining category information through classification and calculating real-time offset scores, it can quantify the risk of the large language model falling into inference deviation in real time without interrupting the model generation. By extracting candidate correction manipulation vectors and calculating dynamic correction vectors, it can adaptively generate correction vectors for the model's error tendency. Finally, it uses the dynamic correction vectors to correct the hidden state and inputs it into the model. This can block the spread of erroneous inference paths, reduce inference costs, and improve the model's inference accuracy without retraining the model.
[0090] Figure 5 An example is a schematic diagram of the physical structure of an electronic device, such as... Figure 5 As shown, the electronic device may include: a processor 510, a communications interface 520, a memory 530, and a communications bus 540, wherein the processor 510, the communications interface 520, and the memory 530 communicate with each other through the communications bus 540. The processor 510 can call logic instructions in the memory 530 to execute a large language model inference correction method. This method includes: acquiring inference behavior information and hidden activation state information of the corresponding lexical unit in a first inference step; the first inference step is obtained sequentially based on the large language model; classifying the inference behavior information to obtain first inference behavior category information, and calculating a real-time offset score for the lexical unit's inference shift towards a potential erroneous behavior category using a baseline activation prototype and hidden activation state information; wherein the baseline activation prototype is determined by state transition comparison data obtained from multi-step inference in the large language model and the average hidden activation value corresponding to various inference behavior information; when the real-time offset score is greater than zero, extracting candidate correction control vectors corresponding to the first inference behavior category information from a pre-set correction control vector library based on the first inference behavior category information and the real-time offset score, and calculating a dynamic correction vector using the candidate correction control vectors and the real-time offset score; correcting the hidden activation state information using the dynamic correction vector, and inputting the corrected hidden activation state information into the large language model.
[0091] Furthermore, the logical instructions in the aforementioned memory 530 can be implemented as software functional units and, when sold or used as independent products, can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, or the part that contributes to the prior art, or a part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0092] On the other hand, the present invention also provides a non-transitory computer-readable storage medium storing a computer program thereon. When executed by a processor, the computer program implements the large language model inference correction method provided by the above methods. The method includes: acquiring inference behavior information of a first inference step and hidden activation state information of the corresponding lexical; the first inference step is obtained by sequential inference based on the large language model; classifying the inference behavior information to obtain first inference behavior category information, and calculating the real-time offset score of the lexical's inference shift to the potential erroneous behavior category using the baseline activation prototype and the hidden activation state information; wherein the baseline activation prototype is determined by the state transition comparison data obtained by the large language model through multi-step inference and the average hidden activation value corresponding to various inference behavior information; when the real-time offset score is greater than zero, extracting the candidate correction control vector corresponding to the first inference behavior category information from a preset correction control vector library according to the first inference behavior category information and the real-time offset score, and calculating the dynamic correction vector using the candidate correction control vector and the real-time offset score; correcting the hidden activation state information using the dynamic correction vector, and inputting the corrected hidden activation state information into the large language model.
[0093] The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate. 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. Those skilled in the art can understand and implement this without any creative effort.
[0094] Through the above description of the embodiments, those skilled in the art can clearly understand that each embodiment can be implemented by means of software plus necessary general-purpose hardware platforms, and of course, it can also be implemented by hardware. Based on this understanding, the above technical solutions, 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 can be stored in a computer-readable storage medium, such as ROM / RAM, magnetic disk, optical disk, etc., and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute the methods described in the various embodiments or some parts of the embodiments.
[0095] 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 them; although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features; and these modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. A method for correcting inference in a large language model, characterized in that, include: Obtain the reasoning behavior information of the first reasoning step and the hidden activation state information of the corresponding word; The first reasoning step is obtained by sequential reasoning based on a large language model; The reasoning behavior information is classified to obtain the first reasoning behavior category information, and the real-time offset score of the word shifting to the potential erroneous behavior category is calculated using the baseline activation prototype and the hidden activation state information; wherein, the baseline activation prototype is determined by the state transition comparison data obtained by the large language model performing multi-step reasoning and the average hidden activation corresponding to various reasoning behavior information. When the real-time offset score is greater than zero, based on the first inference behavior category information and the real-time offset score, a candidate correction control vector corresponding to the first inference behavior category information is extracted from a preset correction control vector library, and a dynamic correction vector is calculated using the candidate correction control vector and the real-time offset score. The hidden layer activation state information is corrected using the dynamic correction vector, and the corrected hidden layer activation state information is input into the large language model.
2. The large language model inference correction method according to claim 1, characterized in that, The baseline activation prototype includes positive and negative prototypes corresponding to multiple potential error behavior categories; The calculation of the real-time offset score of the inference shift of the lexical towards the potential erroneous behavior category using the benchmark activation prototype and the hidden layer activation state information includes: Calculate the first cosine similarity between the hidden layer activation state information and the negative prototype corresponding to the target potential error behavior category, and calculate the second cosine similarity between the hidden layer activation state information and the positive prototype corresponding to the target potential error behavior category; wherein, the target potential error behavior category is at least one of the plurality of potential error behavior categories; If the first cosine similarity is greater than the second cosine similarity, the first cosine similarity is determined as the real-time offset score of the target potential erroneous behavior category.
3. The large language model reasoning correction method according to claim 1 or 2, characterized in that, The alternative correction control vectors include multiple ones, and different alternative correction control vectors correspond to different transfer directions. The transfer direction is used to indicate the transfer from the first inference behavior category information to the target potential erroneous behavior category. The process of calculating the dynamic correction vector using the candidate correction control vector and the real-time offset fraction includes: Obtain multiple real-time offset scores corresponding to multiple potential error behavior categories; The dynamic correction vector is obtained by weighting and summing multiple candidate correction control vectors using the real-time offset scores corresponding to each potential erroneous behavior category.
4. The large language model inference correction method according to claim 1, characterized in that, The step of correcting the hidden layer activation state information using the dynamic correction vector includes: The dynamic correction vector is multiplied by a preset intervention intensity coefficient to obtain the adjusted dynamic correction vector. The adjusted dynamic correction vector is superimposed on the original hidden activation state information of the word to obtain the corrected hidden activation state information.
5. The large language model reasoning correction method according to claim 1, characterized in that, The state transition comparison data is obtained in the following way: Obtain the original inference trajectory and the preceding context data of the second inference step generated by the large language model, wherein the second inference step is obtained later than the first inference step; With the prior context data shared, multiple unfolded inference trajectories are generated by resampling. These multiple unfolded inference trajectories include alternative inference steps, which are used to instruct the large language model to reason sequentially to the correct or incorrect result. Calculate the average accuracy of the expanded reasoning trajectory to obtain a first accuracy; calculate the average accuracy of the original reasoning trajectory to obtain a second accuracy; determine the second reasoning behavior category information of the second reasoning step based on the first accuracy and the second accuracy. The alternative reasoning step, the second reasoning step, and the second reasoning behavior category information are combined, and the state transition comparison data is determined based on the combined data; the combined data includes preferred subsequent state data and non-preferred subsequent state data.
6. The large language model inference correction method according to claim 5, characterized in that, The alternative reasoning step includes a first alternative reasoning step and a second alternative reasoning step, wherein the first alternative reasoning step corresponds to the correct result and the second alternative reasoning step corresponds to the incorrect result; Combining the alternative reasoning step, the second reasoning step, and the second reasoning behavior category information includes: If the first accuracy rate is higher than the second accuracy rate, the first alternative reasoning step is used as the subsequent state data of the preference, and the second reasoning step is used as the subsequent state data of the non-preference. If the first accuracy rate is higher than the second accuracy rate, the second inference step is used as the subsequent state data of the preference, and the second alternative inference step is used as the subsequent state data of the non-preference.
7. The large language model reasoning correction method according to claim 1, characterized in that, The hidden activation averages corresponding to the various reasoning behavior information include: the hidden activation averages belonging to the subsequent states of preference under each reasoning behavior category, and the hidden activation averages belonging to the subsequent states of non-preference. The positive prototype in the baseline activation prototype is constructed based on the average hidden activation of the subsequent preferred state, and the negative prototype in the baseline activation prototype is constructed based on the average hidden activation of the subsequent unpreferred state. The alternative correction manipulation vector is obtained based on the difference between the average hidden activation of lexical units in all preferred subsequent states and the average hidden activation of lexical units in all non-preferred subsequent states under the target transfer category.
8. A large language model reasoning correction device, characterized in that, include: The information acquisition module is used to acquire the reasoning behavior information of the first reasoning step and the hidden activation state information of the corresponding word element; The first reasoning step is obtained by sequential reasoning based on a large language model; The offset score calculation module is used to classify the reasoning behavior information to obtain the first reasoning behavior category information, and to calculate the real-time offset score of the word shifting to the potential erroneous behavior category using the baseline activation prototype and the hidden activation state information; wherein, the baseline activation prototype is determined by the state transition comparison data obtained by the large language model performing multi-step reasoning and the average hidden activation corresponding to various reasoning behavior information. The correction vector calculation module is used to extract candidate correction control vectors corresponding to the first inference behavior category information from a preset correction control vector library based on the first inference behavior category information and the real-time offset score when the real-time offset score is greater than zero, and to calculate a dynamic correction vector using the candidate correction control vectors and the real-time offset score. The correction module is used to correct the hidden layer activation state information using the dynamic correction vector, and input the corrected hidden layer activation state information into the large language model.
9. An electronic device comprising a memory, a processor, and a computer program stored in the memory and running on the processor, characterized in that, When the processor executes the computer program, it implements the large language model inference correction method as described in any one of claims 1 to 7.
10. 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 large language model inference correction method as described in any one of claims 1 to 7.
