Method and device for adjusting model prediction result, electronic equipment and storage medium
By calculating lexical bias values and updating attention values in a large model, the problem of requiring a large amount of computing power and manual annotation for eliminating context illusions is solved, thus achieving more efficient elimination of context illusions.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-12-10
- Publication Date
- 2026-03-17
AI Technical Summary
Existing methods for eliminating context illusions require significant computing power and manual annotation, resulting in long development cycles.
By acquiring the query content and context content input to the prediction model, the deviation value of each word is calculated, and when the deviation value is greater than a preset threshold, the attention value is updated based on the attention value and enhancement coefficient of the word to alleviate context illusion.
Eliminating context illusion reduces computational power consumption and the need for manual annotation, thus shortening the development cycle.
Smart Images

Figure CN121303387B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of large model prediction result calibration, and more specifically, to a method, apparatus, electronic device, and readable storage medium for adjusting model prediction results. Background Technology
[0002] Context illusion refers to a situation where, despite being provided with a context highly relevant to the problem, a large model still outputs content that is inconsistent with, contradictory to, or beyond the scope of the provided context.
[0003] Common methods for eliminating context illusion include post-training methods. Post-training methods include supervised fine-tuning and reward model training. Supervised fine-tuning involves fine-tuning a pre-trained model using high-quality instruction-response pairs generated manually or with model assistance. Reward model training involves collecting preference data and having annotators manually select between two candidate responses to the same prompt.
[0004] However, common methods for eliminating context illusion, such as post-training methods, have the problem of requiring a lot of computing power and manual annotation, resulting in a long development cycle. Summary of the Invention
[0005] This application provides a method, apparatus, electronic device, and readable storage medium for adjusting model prediction results, aiming to solve the problems of common methods for eliminating context illusion requiring a large amount of computing power and manual annotation, and having a long development cycle.
[0006] The first aspect of this application provides a method for adjusting model prediction results, the method comprising:
[0007] Obtain the query content and context content input to the prediction model; the context content is an association description corresponding to the query content; the query content includes multiple first word elements; each first word element has a corresponding attention value;
[0008] Based on the query content, the context content, and the initial output content, a deviation value is determined for each first word element; the initial output content is the initial prediction result output by the prediction model for the query content and the context content; the deviation value is used to characterize the degree of mismatch between the first word element and the initial output content.
[0009] If the deviation value of the first word element is greater than the preset deviation threshold, the updated attention value of the first word element is calculated based on the attention value of the first word element and the preset enhancement coefficient.
[0010] Based on the updated attention value of the first word and the context content, the initial output content is updated to obtain the target output content.
[0011] A second aspect of this application provides an adjustment device for model prediction results, the device comprising:
[0012] The acquisition module is used to acquire the query content and context content input to the prediction model; the context content is an association description corresponding to the query content; the query content includes multiple first word elements; each first word element has a corresponding attention value;
[0013] The first calculation module is used to determine the deviation value of each first word element based on the query content, the context content, and the initial output content; the initial output content is the initial prediction result output by the prediction model for the query content and the context content; the deviation value is used to characterize the degree of mismatch between the first word element and the initial output content.
[0014] The second calculation module is used to calculate the updated attention value of the first word element based on the attention value of the first word element and the preset enhancement coefficient when the deviation value of the first word element is greater than the preset deviation threshold.
[0015] The update module is used to update the initial output content based on the updated attention value of the first word and the context content, so as to obtain the target output content.
[0016] Thirdly, embodiments of this application also disclose an electronic device, including a processor and a memory, wherein the memory stores a program or instructions that can run on the processor, and the program or instructions, when executed by the processor, implement the steps of the method described in the first aspect.
[0017] Fourthly, embodiments of this application also disclose a readable storage medium storing a program or instructions that, when executed by a processor, implement the steps of the method described in the first aspect.
[0018] In summary, after obtaining the query content and context content to be input into the prediction model, the deviation value of each first word element is determined based on the query content, the context content, and the initial output content, and the mismatch degree between the first word element and the initial output content is determined. If the deviation value of the first word element is greater than a preset deviation threshold, the attention value of the first word element is enhanced and updated based on its attention value and a preset enhancement coefficient to alleviate or eliminate the context illusion corresponding to the first word element. Finally, the target output content after eliminating the context illusion is obtained based on the updated attention value of the first word element and the context content. This application automatically updates the attention value for first words elements with deviation values greater than the preset deviation threshold, consuming less computational power; it strengthens the correlation between the corresponding first output word element and the query content, the context content, and the initial output content, achieving this with less computational power and alleviating the context illusion of the first output word element corresponding to the first word element; and it requires less time. This solves the problem that methods for eliminating context illusion require a large amount of computational power and manual annotation, resulting in long development cycles. Attached Figure Description
[0019] To more clearly illustrate the technical solutions of the embodiments of this application, the drawings used in the description of the embodiments of this application will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0020] Figure 1 This is a flowchart of a method for adjusting model prediction results provided in an embodiment of this application;
[0021] Figure 2 This is a flowchart illustrating a method for adjusting model prediction results according to an embodiment of this application.
[0022] Figure 3 This is a schematic diagram illustrating a real-world application of a method for adjusting model prediction results;
[0023] Figure 4 This is a flowchart of another method for adjusting model prediction results provided in an embodiment of this application;
[0024] Figure 5 This is a block diagram of a model prediction result adjustment device provided in an embodiment of this application;
[0025] Figure 6 This is a block diagram of an electronic device provided in an embodiment of this application;
[0026] Figure 7This is a block diagram of another electronic device provided in the embodiments of this application. Detailed Implementation
[0027] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0028] like Figure 1 As shown, this application provides a flowchart of a method for adjusting model prediction results, the method comprising the following steps:
[0029] Step 101: Obtain the query content and context content of the input prediction model.
[0030] The context content is a description of the association with the query content; the query content includes multiple first word elements; each first word element has a corresponding attention value.
[0031] In this application embodiment, the prediction model refers to a large language model (LLM), which is an artificial intelligence model with billions or even trillions of parameters. Large models are generated by training on massive amounts of text data and have powerful language understanding and generation capabilities; they are usually huge in scale, widely applicable, have deep contextual understanding capabilities, and excellent generalization performance.
[0032] The role of query information is to define the output target and range of the predictive model, and it is the core and starting point of large-scale model tasks. The role of contextual content is to constrain / limit the output content of the predictive model in response to the query information, which is equivalent to reference information associated with the query information. The query information and contextual content together constitute the instructions input into the large model. Within the constraints of the contextual content, the predictive model generates the output results corresponding to the query information. The role of contextual content is to make the output results as accurate as possible and reduce the possibility of contextual illusion (bias) in the output results.
[0033] For example, a professional in the field of optoelectronic information engineering wants to use a predictive model to understand information related to stereolithography (SLA) in the field of optical devices. Without context, this professional inputs the query "What is an SLA?" into the predictive model. The model might then output information more relevant to the business realm, such as: "SLA usually refers to a 'Service Level Agreement,' a standard agreement between a service provider and a customer defining the quality of service, availability, and responsibilities." This output is clearly not what the professional needs.
[0034] To make the output of the predictive model more closely resemble the domain knowledge required by the practitioner, add contextual information such as: "SLA specifically refers to stereolithography, a manufacturing technology that uses photosensitive resin for 3D printing," or add a paper related to stereolithography to the context. By combining the query information with the contextual information, the output of the predictive model is more likely to be close to the more technical content related to stereolithography SLA in the field of optical devices, which is the information needed by the practitioner.
[0035] By combining query information and contextual content, the output of the predictive model is generated as close as possible to the range defined by the given context, reducing the possibility of contextual illusions in the output. Furthermore, in the use of some existing large-scale models, after enabling online search functionality, the backend of the large model retrieves content highly relevant to the query information from the vast text database of the internet, using this contextual content as contextual input to the large model. The purpose is to use this contextual content to constrain the output of the query information generated by the large model, thereby improving the accuracy of the output results.
[0036] In the process of using the prediction model, the prediction model cannot directly understand the text composed of Chinese or English characters. Therefore, the query content and context content are divided into lexical units - a basic unit for the large model to process and understand text.
[0037] In the process of calculating the relevant output of the first word element in the query information, the prediction model needs to filter out the most relevant content from all relevant information based on the attention value corresponding to each first word element; this solves the problem that traditional models cannot distinguish the importance of input information. The attention value corresponding to each first word element is generated based on the similarity between it and the context content, other first words in the query content, etc., representing the degree of relevance of each first word element to the context content and the query content.
[0038] Step 102: Determine the deviation value of each first word element based on the query content, the context content, and the initial output content.
[0039] The initial output content is the initial prediction result output by the prediction model for the query content and the context content; the deviation value is used to characterize the degree of mismatch between the first word and the initial output content.
[0040] In this application embodiment, this application provides a method for adjusting model prediction results, the purpose of which is to eliminate / alleviate the context illusion in the model prediction results corresponding to query information, that is, the mismatch between the model prediction results and the context content; given the context content, it is necessary to ensure as much as possible that the output results of the prediction model are based on the context content, rather than a context illusion that is fabricated out of thin air.
[0041] The first step in eliminating bias in the model prediction results corresponding to each first word is to determine whether there is a bias in the current model prediction result corresponding to the first word, and how large the bias is. The prediction model generates prediction results in an autoregressive manner, similar to a person speaking word by word: ① In the model prediction results, only one word is output (added) for each first word in the query information; ② The newly generated word is immediately added to the initial context content, generating new context content; ③ The next word is predicted based on all generated words (i.e., the initial output content).
[0042] The prediction model's output for the current first word (one word) is matched with the prediction model's output for the first word preceding the current first word in the query information, i.e., the initial output content, to obtain the deviation value of the current first word.
[0043] Step 103: If the deviation value of the first word element is greater than the preset deviation threshold, calculate the updated attention value of the first word element based on the attention value of the first word element and the preset enhancement coefficient.
[0044] In this embodiment, the deviation value corresponding to each first word element is calculated in step 102. Based on the deviation value corresponding to each first word element, it is calculated whether the deviation value of the first word element exceeds a preset deviation threshold; for first word elements whose deviation values exceed the preset deviation threshold, the attention values of these first word elements are enhanced. When the deviation value corresponding to the first word element exceeds the preset deviation threshold, it indicates that the deviation between the output result of the current first word element and the output result of the previous first word element (i.e., context illusion) is relatively large, which will seriously affect the final output result of the prediction model for the query information.
[0045] In this situation, the problem of excessive bias can be addressed by enhancing the attention value of the first word whose bias exceeds a preset bias threshold. Increasing the attention value of the first word, which characterizes the correlation between the current first word and its context, other first words in the query, etc., allows the output generated by the prediction model to have a stronger correlation with the context and other first words in the query. This reduces the bias between the output of the current first word and the output of previous first words, a phenomenon known as context illusion.
[0046] Step 104: Update the initial output content based on the updated attention value of the first word and the context content to obtain the target output content.
[0047] In this embodiment, the attention values of the first words whose deviation exceeds a preset deviation threshold are increased, and then the attention values of these first words are updated. For first words with severe context illusion, the updated attention values are used in the prediction model to generate subsequent output content. Because the resulting output content has a larger attention value, it has a higher correlation with the context content and other first words in the query content, and is closer to the context content and other first words in the query content, effectively reducing the deviation in the subsequent output content generated by the prediction model, i.e., context illusion.
[0048] In summary, after obtaining the query content and context content to be input into the prediction model, the deviation value of each first word element is determined based on the query content, the context content, and the initial output content, thus determining the mismatch degree between the first word element and the initial output content. If the deviation value of the first word element is greater than a preset deviation threshold, the attention value of the first word element is enhanced and updated based on the attention value of the first word element and a preset enhancement coefficient to alleviate and eliminate the context illusion corresponding to the first word element. Finally, based on the updated attention value of the first word element and the context content, the target output content after eliminating the context illusion is obtained. This solves the problems of requiring a large amount of computing power and manual annotation, and the long development cycle, in methods for eliminating context illusion.
[0049] like Figure 2 As shown, this application provides a flowchart of the specific steps of a method for adjusting model prediction results. The method includes the following steps:
[0050] Step 201: Obtain the query content and context content of the input prediction model.
[0051] The context content is a description of the association with the query content; the query content includes multiple first word elements; each first word element has a corresponding attention value.
[0052] For details, please refer to step 101 above. We will not go into further detail here.
[0053] Step 202: Based on the context content, the query content, and each first word in the initial output content, determine the first probability vector of each first word in the query content in the prediction model.
[0054] The prediction model includes a first set number of second lexical units.
[0055] The first probability vector includes components corresponding to all second words arranged in order of their probabilities; the first probability vector reflects the probability that each second word in the prediction model is the first output word corresponding to the first word under the conditions of the query content, the context content, and the initial output content; the first output word is the output corresponding to the first word in the prediction model.
[0056] In this embodiment, the prediction model includes a predetermined number of second lexical units, which constitute the vocabulary of the prediction model. The vocabulary can be viewed as the prediction model's own dictionary, containing all lexical units that the prediction model can recognize. That is, the prediction model can recognize any first lexical unit input from the outside that is the same as a second lexical unit in the vocabulary; however, it cannot recognize externally inputted lexical units that are not in the vocabulary composed of second lexical units. The vocabulary is a finite and fixed set, and the vocabulary and the second lexical units contained within it are determined before the prediction model is trained. Both the input and output of the prediction model are based on lexical units (including first and second lexical units).
[0057] A probability vector is a list of mathematical terms whose length is equal to the size of the prediction model's vocabulary minus the number of second terms in that vocabulary. If the vocabulary has 50,000 words, this list will have 50,000 numbers. Each number in the probability vector represents a probability value between 0 and 1; all probability values are summed to 1, meaning the next term predicted by the prediction model will definitely appear in the prediction model's vocabulary.
[0058] A probability vector defines the likelihood that each word in the vocabulary will be selected as the next output term in a specific context.
[0059] Assume the size of the vocabulary is When generating the next lexical unit, the prediction model outputs a dimension... The probability vector is shown in formula (1):
[0060] (1)
[0061] Where P represents a probability vector. This represents the probability that each second word in the prediction model will be selected as the next output word.
[0062] When the prediction model actually generates the output, it needs to select the final output composed of output words based on the probability vector.
[0063] Optionally, step 202 may also include sub-steps 221 to 222:
[0064] Sub-step 221: Merge the context content, the query content, and the initial output content to obtain the first sequence.
[0065] The first sequence includes a second predetermined number of first tokens.
[0066] Sub-step 222: Determine the first conditional probability between the first word element in the query content and each first word element in the first sequence, and use it as the first probability vector.
[0067] Wherein, the first conditional probability is used to characterize the probability that each first term in the first sequence is the first output term corresponding to the first term in the query content.
[0068] In this embodiment, sub-steps 221 and 222 further explain the specific steps of step 202. Based on the context content, the query content, and each first word element in the initial output content, a first probability vector is calculated for each first word element in the query content. As shown in formula (2), based on the context content, the initial output content, and the query content, the prediction model calculates the first probability vector corresponding to the current first word element in the query content. for:
[0069] (2)
[0070] in, This indicates the first word element in the query content. C represents the output generated by the prediction model, C represents the context content, and Q represents the query content.
[0071] Because the prediction model is an autoregressive model, the output content generated by the prediction model beforehand... That is, the first word in the query content. The conditional inputs during generation. First probability vector. Each dimension is The probability vector is generated by combining the context, query content, and the first probability vector generated for each first word in the initial output content. The prediction model selects the first output word corresponding to the first word in the vocabulary based on the first probability vector, which can better match the target output result corresponding to the query content.
[0072] Step 203: Determine the second probability vector for each first word in the query content based on the query content and each first word in the initial output content.
[0073] The second probability vector includes components corresponding to all second tokens arranged in order of their respective probabilities; the second probability vector reflects the probability that each second token in the prediction model is the first output token corresponding to the first token, under the conditions of the query content and the initial output content.
[0074] In this embodiment, a second probability vector is calculated based on the query content and the initial output content. The second probability vector corresponds to the probability that each second word in the prediction model is the first output word corresponding to the first word. Unlike the first probability vector, the second probability vector does not incorporate contextual content. In subsequent calculations, the influence of the contextual content on the output content of the prediction model can be calculated based on the first and second probability vectors.
[0075] Optionally, step 203 may also include sub-steps 301 to 302:
[0076] Sub-step 301: Merge the query content and the initial output content to obtain a second sequence; the second sequence includes a third set number of first tokens.
[0077] Sub-step 302: Determine the second conditional probability between the first word in the query content and the first word in the second sequence, respectively, as the second probability vector.
[0078] The second conditional probability is used to characterize the probability that each first term in the second sequence is the first output term corresponding to the first term in the query content.
[0079] In this embodiment, sub-steps 301 to 302 further explain the calculation process of step 203. As shown in formula (3), a reasoning mode is constructed that can induce the prediction model to predict the probability of the first output word corresponding to the current first word in the query content in a more illusionistic way. That is, given only the query content and the initial output content, without providing context content, a second probability vector is calculated to predict the first output word corresponding to the current first word in the query content. :
[0080] (3)
[0081] This probability vector reflects the tendency of the predictive model to rely solely on its own intrinsic knowledge (i.e., the query content) and the generated content of the initial output, thus making it more prone to generating illusions. Similarly, the second probability vector... It is also a dimension The probability vector.
[0082] Step 204: Use the difference between the first probability vector and the second probability vector as the deviation vector of the first word.
[0083] In this embodiment, the first probability vector is the probability vector of the first output word corresponding to the current first word in the query content, calculated by the prediction model based on the context content, the initial output content, and the query content. The second probability vector, however, is the probability vector of the first output word corresponding to the current first word in the query content, calculated only based on the query content and the initial output content, i.e., without providing context content. Because there is no contextual constraint, the output content generated by the prediction model based on the second probability vector is more prone to bias compared to the output content generated by the prediction model based on the first probability vector—a phenomenon known as context illusion.
[0084] As shown in formula (4), based on this property, the deviation value of the prediction model when predicting the first output word corresponding to the current first word in the query content is first quantified, and a deviation vector including multiple deviation value components is obtained:
[0085] (4)
[0086] in, The first word in the query content The corresponding deviation vector.
[0087] Deviation vector It is a dimension The vector contains the potential bias value when the prediction model predicts the first output word corresponding to the current first word word in the query information, based on the context and the generated initial output content (historical output content) and the query information.
[0088] Step 205: Determine the largest component among the components of the deviation vector, and use it as the deviation value of the first word.
[0089] In the embodiments of this application, in Based on this, the present invention uses The maximum absolute value of the elements further represents the intensity of the illusion. Deviation vector Depend on Composed of several components, it can be represented as .
[0090] As shown in formula (5), the deviation value of the first word element The calculation process is as follows:
[0091] (5)
[0092] in, Represents each first word element The corresponding deviation value.
[0093] For the deviation vector The system iterates through each component and takes the largest component as the deviation value of the first word, which is to quantify the intensity of the context illusion. This allows for the subsequent implementation of corresponding measures to eliminate the context illusion based on the quantified intensity of the context illusion.
[0094] Step 206: If the deviation value of the first word element is greater than the preset deviation threshold, calculate the updated attention value of the first word element based on the attention value of the first word element and the preset enhancement coefficient.
[0095] For details, please refer to step 101 above. We will not go into further detail here.
[0096] Optionally, step 206 may also include sub-steps 601 to 602:
[0097] Sub-step 601: Determine the sum of the preset enhancement coefficient and 1;
[0098] Sub-step 602: Determine the attention value of the first word and the product of the summation result as the updated attention value of the first word.
[0099] In this embodiment, step 206 is further described. In step 206, the deviation value corresponding to each first word element is calculated. Based on the deviation value corresponding to each first word element, it is determined whether the deviation value corresponding to the first word element exceeds a preset deviation threshold. If the deviation value corresponding to the first word element exceeds the preset deviation threshold, it indicates that the deviation value corresponding to the first word element is too large, that is, the output of the first word element will have a relatively serious context illusion, and the context illusion of the first word element needs to be eliminated.
[0100] In this context, for the first word whose deviation value exceeds the preset deviation threshold, the attention value of the first word is increased. This increases the correlation between the first word and the context content, other first words in the query content, etc. Therefore, in the subsequent process of generating output content by the large model, the output content related to the first word with increased attention value can be more correlated with the context content, other first words in the query content, etc., reducing the context illusion (deviation) between the output result corresponding to the current first word and the output result of the previous first word.
[0101] Specifically, during the process of the prediction model (autoregressive) generating the output content corresponding to the first word element in the query information, when the prediction model generates the output corresponding to the current first word element, the self-attention mechanism of the prediction model will calculate the attention value of each previous first word element to the current first word element in the query information. As shown in formula (6), the weight matrix of the standard self-attention mechanism is:
[0102] (6)
[0103] in, This represents the position of the current first word element. For the first The query vector at the position i of the current first word element in the layer. For the first The key vectors of all previous first-order words in the layer. The dimension of the key vector. Each element represents the initial output content (of length 1) generated by the prediction model for the current first word. Attention distribution These represent the length of the context content and the query information, respectively. For example... This indicates the attention of the current first word element position i to the j-th second word element in the generated initial output content of the prediction model.
[0104] In standard large model inference, the generation of the first output word corresponding to the current first word will pay attention to the context content, query information, and the already generated initial output content to varying degrees. The strength of the attention indicates to some extent the degree to which the generation of the first output word corresponding to the current first word depends on / refers to the context content, query information, and the already generated initial output content.
[0105] To alleviate / eliminate the contextual illusion between the output of the current first word and the output of the previous first word, as shown in Equation (7), a context-weighted strategy is used to enhance the attention of the current first word to the context content, query information, and the generated initial output content:
[0106] (7)
[0107] in, This represents the attention value after enhancement of the current first word unit; This indicates that the j-th second word element of the generated initial output content belongs to the context content. A collection representing contextual content; when hour, It is 1 if it is true, otherwise it is 0. This represents the enhancement coefficient.
[0108] In formula (7), when At that time, the attention of the current first word element i to the position j of the generated initial output content is increased. times, therefore A larger value indicates that more attention is paid to the context. In the embodiments of this application, the enhancement coefficient... The enhancement factor is set to 2. The reason for setting it to 2 is that it enhances the generation process of the first output word corresponding to the first word word, taking into account the context. It achieves a balance by focusing attention on the relevant parts without affecting attention to other parts (such as query information and the initial output content already generated in the query).
[0109] Step 207: Update the initial output content based on the updated attention value of the first word and the context content to obtain the target output content.
[0110] For details, please refer to step 104 above. We will not go into further detail here.
[0111] Optionally, step 207 may also include sub-steps 701 to 703:
[0112] Sub-step 701: The updated attention value of the first word is forward-propagated in the prediction model to obtain the target probability vector corresponding to the first word.
[0113] The target probability vector is used to characterize the probability vector with the highest accuracy corresponding to the first word; the probability vector includes all second words arranged in order of their corresponding probabilities.
[0114] Sub-step 702: Sample the target probability vector to obtain the second output word corresponding to the first word; the second output word is the output of the first word in the prediction model.
[0115] Sub-step 703: Merge the second output word with the initial output content to obtain the target output content.
[0116] In this embodiment, sub-steps 701 to 703 further explain the specific process of step 204. After enhancing the attention value corresponding to the first word element with a large deviation value, a larger attention value corresponding to the first word element is obtained. This larger attention value corresponding to the first word element is forward-propagated in the prediction model to obtain the target probability vector corresponding to the enhanced attention value of the first word element. This results in a higher correlation between the second word element in the obtained target probability vector and the context content, query information, and initial generated content, reducing contextual illusions in the generated content corresponding to the first word element.
[0117] Based on the target probability vector, different sampling methods are used to sample the target probability vector to obtain the first output word corresponding to the corrected first word. As shown in formulas (8), (9), (10), and (11):
[0118] ① Using a greedy selection algorithm, sample the first output token generated. for:
[0119] (8) Among them, Represents the target probability vector;
[0120] ②Use Top-k sampling: In The subset consisting of the k second-order words with the highest probability Random sampling is performed:
[0121] (9)
[0122] ③Top-p sampling: in In the middle, from the cumulative probability exceeding the threshold Minimal word set Medium sampling:
[0123] (10)
[0124] (11)
[0125] Optionally, sub-step 703 may also include sub-steps A1 to A2:
[0126] Sub-step A1: If the first word element is the last first word element in the query content, use the target output content as the output result of the prediction model corresponding to the query content.
[0127] Sub-step A2: If the first word element is not the last first word element in the query content, continue to calculate the second output word element corresponding to the first word element in the query content.
[0128] In this embodiment, the prediction model continuously predicts the second output word corresponding to the first word in the query content and generates related content. When the first word at the current position is the last first word in the query content, the prediction model enters the next stage, using the target output content as the output result of the prediction model corresponding to the query content, and performs the next operation, such as using the target output content to continue generating related content in the prediction model.
[0129] like Figure 3 As shown, when the input question in the prediction model includes the following: Input prompt Q: Ms. Wang purchased medicine directly from a pharmacy at her own expense without going through the medicine purchase application process; however, Ms. Wang did not use medical insurance reimbursement, how should she claim reimbursement? Generated sequence G: Okay. The medicine purchased by Ms. Wang is...
[0130] Calculate the probability sequence of the output for the current word in the input cue Q, both with and without contextual input. If the hallucination intensity exceeds a threshold (the probability difference for "home" is significant), eliminate / alleviate the hallucination of the current word's output. Enhance the attention to words with higher hallucination intensity using an enhancement coefficient, resulting in enhanced attention. Use this enhanced attention for forward propagation to obtain a more accurate probability sequence (eliminating the hallucination for "home"), thus generating output words with lower hallucination intensity.
[0131] like Figure 4 As shown, the method for adjusting the model prediction results provided in the embodiments of this application can be summarized as follows:
[0132] Step K1: Initialize parameters: context C, input prompt Q position = 1, generated sequence G = φ.
[0133] In this embodiment, before using the prediction model, the relevant parameters need to be initialized, including the context C, the input prompt Q, and the generated sequence G. The input prompt is the core question to be queried using the prediction model, and the generated sequence refers to the preliminary result generated by the prediction model after processing the input prompt Q based on the context C.
[0134] Step K2: Determine whether the generation termination condition has been met.
[0135] In this embodiment, once the output corresponding to the last word in context C and input prompt Q has been processed in the prediction model, the prediction model reaches the termination condition and stops generating the output corresponding to the word.
[0136] Step K3: Output the final sequence.
[0137] In this embodiment of the application, after the prediction model reaches the termination condition, the sequence containing the outputs of all previously generated tokens is output as the final sequence.
[0138] Step K4: Calculate the contextual conditional probability distribution and the base probability distribution.
[0139] In this embodiment, if the generation termination condition has not yet been met, the contextual conditional probability distribution and the base probability distribution of the current word element are calculated. The base probability distribution is the probability distribution of the current word element without context.
[0140] Step K5: Calculate the potential hallucination direction, output the final sequence, and the hallucination intensity.
[0141] In this embodiment of the application, the difference (vector difference) between the contextual conditional distribution probability and the base probability distribution is calculated to obtain the final sequence of the potential illusion direction output of the current word, and the maximum value in the final sequence of the potential illusion direction output is taken as the illusion intensity of the current word.
[0142] Step K6: Determine if the value is greater than the preset threshold.
[0143] In this embodiment of the application, it is determined whether the hallucination intensity of the current word element is greater than a preset (hallucination) threshold.
[0144] Step K7: Use the contextual conditional probability distribution as the final probability distribution.
[0145] In this embodiment of the application, if the hallucination intensity of the current word element does not exceed the preset (hallucination) threshold, then the contextual conditional distribution probability calculated in step K5 is used as the final probability distribution of the current word element, that is, the hallucination corresponding to the current word element is relatively small, and there is no need to further eliminate the hallucination.
[0146] Step K8: Generate a new token by sampling according to the final probability distribution.
[0147] In this embodiment of the application, the probability distribution of the contextual condition (vector) is sampled to obtain the output (lexicon) corresponding to the current lexicon.
[0148] Step K9: Add the obtained new token to the generated sequence.
[0149] In this embodiment of the application, the output (lexicon) corresponding to the current lexicon is added to the generated sequence for storage.
[0150] Step K10: Adjust the attention score of the current token relative to whether it can rely on the context token.
[0151] In this embodiment of the application, if the hallucination intensity of the current word element is greater than the preset (hallucination) threshold, it indicates that the hallucination intensity is high and needs to be eliminated / alleviated. The corresponding method is to modify (enhance) the attention value of the current word element to enhance the correlation between the current word element and the context and the generated sequence.
[0152] Step K11: Perform forward propagation using the corrected attention score to obtain the final probability distribution.
[0153] In this embodiment, the attention value enhanced by the current word is used for forward propagation in the prediction model, making the output content corresponding to the current word more correlated with the context and the generated sequence, thus obtaining the final probability distribution after the current word correction. Then, steps K8, K9, and K10 are performed to generate the final output (word) after the illusion is eliminated and the generated sequence.
[0154] like Figure 5 As shown in the figure, this application embodiment provides a model prediction result adjustment device 600, which includes:
[0155] The acquisition module 601 is used to acquire the query content and context content of the input prediction model; the context content is the association description corresponding to the query content; the query content includes multiple first word elements; each first word element has a corresponding attention value.
[0156] The first calculation module 602 is used to determine the deviation value of each first word element based on the query content, the context content, and the initial output content; the initial output content is the initial prediction result output by the prediction model for the query content and the context content; the deviation value is used to characterize the degree of mismatch between the first word element and the initial output content.
[0157] Optionally, the first computing module 602 may further include:
[0158] The first calculation submodule is used to determine a first probability vector for each first word in the query content in the prediction model based on each first word in the context content, the query content, and the initial output content. The first probability vector includes components corresponding to all second words arranged in order of their corresponding probabilities. The first probability vector reflects the probability that each second word in the prediction model is the first output word corresponding to the first word under the conditions of the query content, the context content, and the initial output content. The first output word is the output corresponding to the first word in the prediction model.
[0159] Optionally, the first calculation submodule 602 may also include:
[0160] The first merging unit is used to merge the context content, the query content, and the initial output content to obtain a first sequence; the first sequence includes a second predetermined number of first tokens.
[0161] The first calculation unit is used to determine the first conditional probability between the first word element in the query content and each first word element in the first sequence, as the first probability vector; the first conditional probability is used to characterize the probability that each first word element in the first sequence is the first output word element corresponding to the first word element in the query content.
[0162] The second calculation submodule is used to determine a second probability vector for each first word in the query content based on each first word in the query content and the initial output content. The second probability vector includes components corresponding to all second words arranged in order of their corresponding probabilities. The second probability vector reflects the probability that each second word in the prediction model is the first output word corresponding to the first word under the conditions of the query content and the initial output content.
[0163] Optionally, the second computation submodule may also include:
[0164] The second merging unit is used to merge the query content and the initial output content to obtain a second sequence; the second sequence includes a third set number of first tokens.
[0165] The third calculation unit is used to determine the second conditional probability between the first word element in the query content and the first word element in the second sequence, respectively, as the second probability vector; the second conditional probability is used to characterize the probability that each first word element in the second sequence is the first output word element corresponding to the first word element in the query content.
[0166] The third calculation submodule is used to take the difference between the first probability vector and the second probability vector as the deviation vector of the first word.
[0167] The second calculation module 603 is used to calculate the updated attention value of the first word element based on the attention value of the first word element and a preset enhancement coefficient when the deviation value of the first word element is greater than a preset deviation threshold.
[0168] Optionally, the second computing module 603 may also include:
[0169] The fourth calculation submodule is used to determine the sum of the preset enhancement coefficient and 1.
[0170] The fifth calculation submodule is used to determine the attention value of the first word element and the product of the summation result, which is used as the updated attention value of the first word element.
[0171] The update module 604 is used to update the initial output content based on the updated attention value of the first word and the context content to obtain the target output content.
[0172] Optionally, updating module 604 may also include:
[0173] The propagation submodule is used to propagate the updated attention value of the first word element forward in the prediction model to obtain the target probability vector corresponding to the first word element; the target probability vector is used to characterize the probability vector with the highest accuracy corresponding to the first word element; the probability vector includes all second words arranged in order of their corresponding probabilities.
[0174] The sampling submodule is used to sample the target probability vector to obtain the second output word corresponding to the first word; the second output word is the output of the first word in the prediction model.
[0175] The merging submodule is used to merge the second output word with the initial output content as the target output content.
[0176] Optionally, the merged submodules may also include:
[0177] The first output unit is configured to, if the first word element is the last first word element in the query content, use the target output content as the output result of the prediction model corresponding to the query content.
[0178] The second output unit is used to continue calculating the second output word corresponding to the first word in the query content if the first word is not the last first word in the query content.
[0179] See Figure 6 The electronic device 400 may include one or more of the following components: processing component 402, memory 404, power supply component 406, multimedia component 408, audio component 410, input / output (I / O) interface 412, sensor component 414, and communication component 416.
[0180] Processing component 402 typically controls the overall operation of electronic device 400, such as operations associated with display, telephone calls, data communication, camera operation, and recording. Processing component 402 may include one or more processors 420 to execute instructions to perform all or part of the steps of the methods described above. Furthermore, processing component 402 may include one or more modules to facilitate interaction between processing component 402 and other components. For example, processing component 402 may include a multimedia module to facilitate interaction between multimedia component 408 and processing component 402.
[0181] Memory 404 is used to store various types of data to support the operation of electronic device 400. Examples of such data include instructions for any application or method operating on electronic device 400, contact data, phonebook data, messages, pictures, multimedia, etc. Memory 404 can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic storage, flash memory, magnetic disk, or optical disk.
[0182] Power supply component 406 provides power to various components of electronic device 400. Power supply component 406 may include a power management system, one or more power supplies, and other components associated with generating, managing, and distributing power to electronic device 400.
[0183] Multimedia component 408 includes an interface that provides an output interface between electronic device 400 and a user. In some embodiments, the interface may include a liquid crystal display (LCD) and a touch panel (TP). If the interface includes a touch panel, the interface may be implemented as a touchscreen to receive input signals from the user. The touch panel includes one or more touch sensors to sense touches, swipes, and gestures on the touch panel. The touch sensors may sense not only the boundaries of touch or swipe actions but also the duration and pressure associated with the touch or swipe operation. In some embodiments, multimedia component 408 includes a front-facing camera and / or a rear-facing camera. When electronic device 400 is in an operating mode, such as a shooting mode or a multimedia mode, the front-facing camera and / or rear-facing camera may receive external multimedia data. Each front-facing camera and rear-facing camera may be a fixed optical lens system or have focal length and optical zoom capabilities.
[0184] Audio component 410 is used to output and / or input audio signals. For example, audio component 410 includes a microphone (MIC) used to receive external audio signals when electronic device 400 is in an operating mode, such as call mode, recording mode, and voice recognition mode. The received audio signals may be further stored in memory 404 or transmitted via communication component 416. In some embodiments, audio component 410 also includes a speaker for outputting audio signals.
[0185] Input / output (I / O) interface 412 provides an interface between processing component 402 and peripheral interface modules, such as keyboards, click wheels, buttons, etc. These buttons may include, but are not limited to, home buttons, volume buttons, power buttons, and lock buttons.
[0186] Sensor assembly 414 includes one or more sensors for providing state assessments of various aspects of electronic device 400. For example, sensor assembly 414 may detect the on / off state of electronic device 400, the relative positioning of components such as the display and keypad of electronic device 400, changes in position of electronic device 400 or a component of electronic device 400, the presence or absence of user contact with electronic device 400, orientation or acceleration / deceleration of electronic device 400, and temperature changes of electronic device 400. Sensor assembly 414 may include a proximity sensor configured to detect the presence of nearby objects without any physical contact. Sensor assembly 414 may also include a light sensor, such as a CMOS or CCD image sensor, for use in imaging applications. In some embodiments, sensor assembly 414 may also include an accelerometer, gyroscope, magnetometer, pressure sensor, or temperature sensor.
[0187] Communication component 416 facilitates wired or wireless communication between electronic device 400 and other devices. Electronic device 400 can access wireless networks based on communication standards, such as WiFi, carrier networks (such as 2G, 3G, 4G, or 5G), or combinations thereof. In one exemplary embodiment, communication component 416 receives broadcast signals or broadcast-related information from an external broadcast management system via a broadcast channel. In one exemplary embodiment, communication component 416 also includes a near-field communication (NFC) module to facilitate short-range communication. For example, the NFC module may be implemented based on radio frequency identification (RFID) technology, Infrared Data Association (IrDA) technology, ultra-wideband (UWB) technology, Bluetooth (BT) technology, and other technologies.
[0188] In an exemplary embodiment, the electronic device 400 may be implemented by one or more application-specific integrated circuits (ASICs), digital signal processors (DSPs), digital signal processing devices (DSPDs), programmable logic devices (PLDs), field-programmable gate arrays (FPGAs), controllers, microcontrollers, microprocessors, or other electronic components to implement a method for adjusting model prediction results provided in this application embodiment.
[0189] In an exemplary embodiment, a non-transitory computer-readable storage medium including instructions is also provided, such as a memory 404 including instructions, which can be executed by a processor 420 of an electronic device 400 to perform the above-described method. For example, the non-transitory storage medium may be a ROM, random access memory (RAM), CD-ROM, magnetic tape, floppy disk, and optical data storage device, etc.
[0190] Figure 7 This is a block diagram of an electronic device 400 according to another embodiment of the present invention. For example, the electronic device 400 may be provided as a server. See also Figure 7 The electronic device 400 includes a processing component 402, which further includes one or more processors, and memory resources represented by memory 404 for storing instructions, such as application programs, that can be executed by the processing component 402. The application programs stored in memory 404 may include one or more modules, each corresponding to a set of instructions. Furthermore, the processing component 402 is configured to execute instructions to perform a method for adjusting model prediction results provided in embodiments of this application.
[0191] Electronic device 400 may also include a power supply component 406 configured to perform power management of electronic device 400, a wired or wireless network interface 550 configured to connect electronic device 400 to a network, and an input / output (I / O) interface 558. Electronic device 400 may operate on an operating system stored in memory 404, such as Windows Server™, Mac OS X™, Unix™, Linux™, FreeBSD™, or similar.
[0192] Other embodiments of this application will readily occur to those skilled in the art upon consideration of the specification and practice of the application disclosed herein. This application is intended to cover any variations, uses, or adaptations of this application that follow the general principles of this application and include common knowledge or customary techniques in the art not disclosed herein. The specification and examples are to be considered exemplary only, and the true scope and spirit of this application are indicated by the following claims.
[0193] It should be understood that this application is not limited to the precise structure described above and shown in the accompanying drawings, and various modifications and changes can be made without departing from its scope. The scope of this application is limited only by the appended claims.
[0194] Although preferred embodiments of the present application have been described, those skilled in the art, upon learning the basic inventive concept, can make other changes and modifications to these embodiments. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments as well as all changes and modifications falling within the scope of the embodiments of the present application.
[0195] In the description of this specification, the references to terms such as "one embodiment," "some embodiments," "illustrative embodiment," "example," "specific example," or "some examples," etc., indicate that a specific feature, structure, material, or characteristic described in connection with that embodiment or example is included in at least one embodiment or example of the invention. In this specification, the illustrative expressions of the above terms do not necessarily refer to the same embodiment or example. Furthermore, the specific features, structures, materials, or characteristics described may be combined in any suitable manner in one or more embodiments or examples.
[0196] Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or terminal device that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or terminal device. Without further limitation, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or terminal device that includes that element.
[0197] The above provides a detailed description of a method, apparatus, electronic device, and readable storage medium for adjusting model prediction results provided in this application. Specific examples have been used to illustrate the principles and implementation methods of this application. The descriptions of the above embodiments are only for the purpose of helping to understand the method and core ideas of this application. At the same time, for those skilled in the art, there will be changes in the specific implementation methods and application scope based on the ideas of this application. Therefore, the content of this specification should not be construed as a limitation of this application.
Claims
1. A method of adjusting a model prediction result, characterized by, The method comprises: obtaining query content and context content input into a prediction model; the context content is associated description corresponding to the query content; the query content comprises a plurality of first word units; each first word unit has a corresponding attention value; determining a bias value of each first word unit according to the query content, the context content and initial output content, comprising: determining a first probability vector of each first word unit in the query content in the prediction model according to each first word unit in the context content, the query content and the initial output content; the first probability vector comprises components corresponding to all second word units arranged in order of corresponding probability size; the first probability vector reflects the probability of each second word unit in the prediction model as the first output word unit corresponding to the first word unit under the condition of the query content, the context content and the initial output content; the first output word unit is the output corresponding to the first word unit in the prediction model; determining a second probability vector of each first word unit in the query content according to each first word unit in the query content and the initial output content; the second probability vector comprises components corresponding to all second word units arranged in order of corresponding probability size; the second probability vector reflects the probability of each second word unit in the prediction model as the first output word unit corresponding to the first word unit under the condition of the query content and the initial output content; taking the difference between the first probability vector and the second probability vector as the bias vector of the first word unit; determining the maximum component in each component of the bias vector as the bias value of the first word unit; the initial output content is the initial prediction result output by the prediction model for the query content and the context content; the bias value is used to represent the degree of mismatch between the first word unit and the initial output content; the prediction model comprises a first set number of second word units; in the case where the bias value of the first word unit is greater than a preset bias threshold, calculating an updated attention value of the first word unit according to the attention value of the first word unit and a preset enhancement coefficient, comprising: determining the sum of the preset enhancement coefficient and 1; determining the product between the attention value of the first word unit and the sum as the updated attention value of the first word unit; updating the initial output content according to the updated attention value of the first word unit and the context content to obtain target output content.
2. The method of adjusting model predicted outcomes of claim 1, wherein, The updating of the initial output content according to the updated attention value of the first word unit and the context content to obtain target output content comprises: performing forward propagation on the prediction model of the updated attention value of the first word unit to obtain a target probability vector corresponding to the first word unit; the target probability vector is used to represent the probability vector with the highest accuracy corresponding to the first word unit; the probability vector comprises all second word units arranged in order of corresponding probability size; sample the target probability vector to obtain a second output token corresponding to the first token; the second output token is an output corresponding to the first token in the prediction model; merge the second output token and the initial output content as the target output content.
3. The method of adjusting model predicted outcomes of claim 2, wherein, After the step of merging the second output token and the initial output content as the target output content, the method further comprises: if the first token is the last first token in the query content, taking the target output content as an output result of the prediction model corresponding to the query content; if the first token is not the last first token in the query content, continuing to calculate a second output token corresponding to the first token in the query content.
4. The method of adjusting model predicted outcomes of claim 1, wherein, The step of determining the first probability vector of each first token in the query content in the prediction model according to each first token in the context content, the query content and the initial output content comprises: merging the context content, the query content and the initial output content to obtain a first sequence; the first sequence comprises a second set number of first tokens; determining a first conditional probability between each first token in the query content and each first token in the first sequence as the first probability vector; the first conditional probability is used to represent a probability that each first token in the first sequence is a first output token corresponding to the first token in the query content.
5. The method of adjusting model predicted outcomes of claim 1, wherein, The step of determining the second probability vector of each first token in the query content according to each first token in the query content and the initial output content comprises: merging the query content and the initial output content to obtain a second sequence; the second sequence comprises a third set number of first tokens; determining a second conditional probability between each first token in the query content and each first token in the second sequence as the second probability vector; the second conditional probability is used to represent a probability that each first token in the second sequence is a first output token corresponding to the first token in the query content.
6. An adjustment device of a model predicted result, characterized by, The apparatus comprises: an acquisition module configured to acquire query content input into a prediction model and context content; the context content is an associated description corresponding to the query content; the query content comprises a plurality of first tokens; each first token has a corresponding attention value; The first calculation module is configured to determine a bias value of each first word element based on the query content, the context content, and the initial output content, including: determining a first probability vector of each first word element in the query content in the prediction model based on each first word element in the query content, the context content, and the initial output content; the first probability vector includes components corresponding to all second word elements arranged in order of corresponding probabilities; the first probability vector reflects a probability of each second word element in the prediction model as a first output word element corresponding to the first word element under the conditions of the query content, the context content, and the initial output content; the first output word element is an output corresponding to the first word element in the prediction model; determining a second probability vector of each first word element in the query content based on each first word element in the query content and the initial output content; the second probability vector includes components corresponding to all second word elements arranged in order of corresponding probabilities; the second probability vector reflects a probability of each second word element in the prediction model as a first output word element corresponding to the first word element under the conditions of the query content and the initial output content; taking a difference between the first probability vector and the second probability vector as a bias vector of the first word element; determining a maximum component in each component of the bias vector as the bias value of the first word element; the initial output content is an initial prediction result output by the prediction model for the query content and the context content; the bias value is used to represent a mismatch degree between the first word element and the initial output content; the prediction model includes a first set number of second word elements. The second calculation module is configured to calculate an updated attention value of the first word element based on the attention value of the first word element and a preset enhancement coefficient when the bias value of the first word element is greater than a preset bias threshold, including: determining a sum of the preset enhancement coefficient and 1; taking a product between the attention value of the first word element and the sum as the updated attention value of the first word element. The updating module is configured to update the initial output content based on the updated attention value of the first word element and the context content to obtain a target output content.
7. An electronic device, comprising: A processor and a memory are included, the memory stores programs or instructions executable on the processor, and the programs or instructions are executed by the processor to implement the steps of the method in any one of claims 1 to 5.
8. A readable storage medium, characterized by, The readable storage medium stores programs or instructions, and the programs or instructions are executed by the processor to implement the steps of the method in any one of claims 1 to 5.
Citation Information
Patent Citations
Text generation method, electronic device, storage medium and computer program product
CN119127038A
Multi-modal large model object illusion relieving method for removing training prejudice based on efficient machine forgetting
CN120356046A