Model prediction result adjustment method and device, 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 in the elimination of context illusion methods is solved, and more efficient context illusion elimination is achieved.
Patent Information
- Application Number
- CN202511851511.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-12-10
- Publication Date
- 2026-01-09
- Estimated Expiration
- 2045-12-10
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 CN121303387A_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the field of large model prediction result calibration, in particular to a model prediction result adjustment method and device, electronic equipment and readable storage medium. BACKGROUND
[0002] Context hallucination refers to a large model outputting content that is inconsistent with, contradictory to or beyond the scope of the provided context, although a context highly relevant to the question has been provided.
[0003] A common method for eliminating context hallucination is the post-training method. The post-training method includes supervised fine-tuning and reward model training. The supervised fine-tuning specifically uses high-quality "instruction-reply" pairs generated by humans or models to fine-tune the pre-trained model. The reward model training specifically collects preference data, two candidate replies under the same prompt, and selects them manually by annotators.
[0004] However, the common method for eliminating context hallucination, such as the post-training method, requires a large amount of computing power and manual annotation, resulting in a long development cycle. SUMMARY
[0005] The present application provides a model prediction result adjustment method, device, electronic equipment and readable storage medium, aiming to solve the problem of long development cycle caused by the need for a large amount of computing power and manual annotation in the common method for eliminating context hallucination.
[0006] The first aspect of the embodiment of the present application provides a model prediction result adjustment method, which comprises: obtaining 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 word units; each first word unit has a corresponding attention value; determining a deviation value of each first word unit according to the query content, the context content and initial output content; the initial output content is an initial prediction result output by the prediction model for the query content and the context content; the deviation value is used to represent the mismatch degree between the first word unit and the initial output content; in the case where the deviation value of the first word unit is greater than a preset deviation 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; 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.
[0007] The second aspect of the embodiment of the present application provides a model prediction result adjustment device, which comprises: 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; 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. 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. 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.
[0008] 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.
[0009] 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.
[0010] 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, and have long development cycles. Attached Figure Description
[0011] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings needed to be used in the description of the embodiments of the present application will be briefly introduced. Obviously, the drawings in the following description are only some embodiments of the present application, and other drawings can be obtained by those skilled in the art without creative labor.
[0012] Figure 1 is a flowchart of a model prediction result adjustment method provided by an embodiment of the present application; Figure 2 is a specific flowchart of a model prediction result adjustment method provided by an embodiment of the present application; Figure 3 is a schematic diagram of an actual scene application of a model prediction result adjustment method; Figure 4 is a flowchart of another model prediction result adjustment method provided by an embodiment of the present application; Figure 5 is a block diagram of a model prediction result adjustment device provided by an embodiment of the present application; Figure 6 is a block diagram of an electronic device provided by an embodiment of the present application; Figure 7 is a block diagram of another electronic device provided by an embodiment of the present application. DETAILED DESCRIPTION
[0013] The technical solutions in the embodiments of the present application will be described clearly and completely below with reference to the drawings in the embodiments of the present application. Obviously, the described embodiments are only some embodiments of the present application, not all embodiments. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without creative labor are within the scope of protection of the present application.
[0014] As shown in the flowchart of a model prediction result adjustment method provided by the present application, the method comprises the following steps: Figure 1 Step 101, obtaining query content and context content of an input prediction model. Step 101, obtaining query content and context content of an input prediction model.
[0015] The context content is an 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.
[0016] In the embodiments of the present application, the prediction model refers to a large model (Large Language Models, LLM), that is, an artificial intelligence model with a parameter amount reaching tens of billions or even hundreds of billions. The large model is generated by training on a large amount of text data and has strong language understanding and generation capabilities. Generally, the large model has a large scale, wide universality, deep context understanding ability, and excellent generalization performance.
[0017] The role of the query information is to define the output target and output range of the prediction model, which is the core and starting point of the large model task. The role of the context content is to constrain / limit the output content of the prediction model for the query information, which is equivalent to the reference information associated with the query information. The query information and the context content form the instructions input into the large model. The prediction model generates the output result corresponding to the query information within the limitation of the context content. The role of the context content is to make the output result as accurate as possible and reduce the possibility of context hallucination (bias) in the output result.
[0018] For example, a practitioner in the field of optoelectronic information engineering wants to understand the information related to stereolithography (SLA) in the field of optical devices through a prediction model. At this time, without context content, the practitioner inputs the query information into the prediction model: what is SLA. At this time, the output result given by the prediction model may be: "SLA usually refers to 'Service Level Agreement' (also abbreviated as SLA), which is a standard agreement between service providers and customers to define service quality, availability, and responsibility." This output result is obviously not what the practitioner needs.
[0019] In order to make the output result given by the prediction model closer to the field knowledge needed by the practitioner, the context content "SLA specifically refers to stereolithography, which is a manufacturing technology for 3D printing using photosensitive resin" is added, or a paper related to stereolithography is added to the context content. In this way, combined with the query information and the context content, the output result of the prediction model is more likely to approach the technical content related to SLA in the field of optical devices, that is, the information needed by the practitioner.
[0020] In combination with the query information and the context content, the output result of the prediction model is generated as much as possible from the range defined by the given context content, so as to reduce the possibility of context hallucination in the output result. In addition, in the process of using some existing large models, after the network search function is turned on, the backend of the large model will obtain some content with a relatively large correlation degree with the query information from the vast text library of the Internet as the context content of the query information input into the large model, so as to limit the output result of the query information generated by the large model using the context content and improve the correctness of the output result.
[0021] In the process of using the prediction model, the prediction model cannot directly understand the text composed of Chinese characters or English characters, so the query content and the context content are divided into word pieces, which are the basic units of text processing and understanding by the large model.
[0022] In the process of calculating the relevant output of the first word piece in the query information by the prediction model, the most relevant part of the content is selected from all the relevant information according to the attention value corresponding to each first word piece, so as to solve the problem that the traditional model cannot distinguish the importance of the input information. The attention value corresponding to each first word piece is generated according to the similarity between the context content, the other first word pieces in the query content and other contents, which represents the correlation degree of each first word piece with the context content and the query content.
[0023] Step 102, determining a deviation value of each first word piece according to the query content, the context content and the initial output content.
[0024] The initial output content is the initial prediction result output by the prediction model for the query content and the context content; and the deviation value is used to represent the mismatch degree of the first word piece and the initial output content.
[0025] In the embodiments of the present application, the present application provides a method for adjusting the prediction result of a model, which aims to eliminate / relieve the context hallucination in the prediction result of the model corresponding to the query information, that is, the mismatch degree between the prediction result of the model and the context content; and in the case of given context content, it is ensured as much as possible that the output result of the prediction model is based on the context content, rather than the context hallucination which is created out of nothing.
[0026] The first step to eliminate the bias in the model prediction result corresponding to each first word piece is to determine whether a bias occurs in the model prediction result corresponding to the current first word piece and whether the bias is large or not. The prediction model generates the model prediction result in a self-recurrent manner, similar to a person speaking one word at a time: ① In the model prediction result, each time, only one word piece is output (newly added) for one first word piece in the query information; ② The newly generated word piece is immediately added to the initial context content to generate new context content; and ③ The next word piece is predicted based on all generated word pieces (that is, the initial output content).
[0027] The output result (one word piece) of the prediction model for the current first word piece is matched with the output result of the prediction model for the first word piece before the current first word piece in the query information, that is, the initial output content, to obtain a bias value of the current first word piece.
[0028] In step 103, when the bias value of the first word piece is greater than the preset bias threshold, the updated attention value of the first word piece is calculated according to the attention value of the first word piece and a preset enhancement coefficient.
[0029] In the embodiments of the present application, the bias value corresponding to each first word piece is calculated in step 102. Based on the bias value corresponding to each first word piece, it is determined whether the bias value of the first word piece exceeds the preset bias threshold; and the attention value of the first word piece is enhanced when the bias value of the first word piece exceeds the preset bias threshold. When the bias value of the first word piece exceeds the preset bias threshold, it indicates that the bias (that is, the context illusion) between the output result corresponding to the current first word piece and the output result of the previous first word piece is relatively large, which will seriously affect the final output result of the prediction model for the query information.
[0030] In this case, the method of enhancing the attention value of the first word piece whose bias value exceeds the preset bias threshold solves the problem of too large bias. After increasing the attention value of the first word piece, because the attention value can represent the correlation degree between the current first word piece and the context content, the query content and other first word pieces, in the process of generating the output content by the prediction model, the correlation degree between the output content related to the first word piece with the increased attention value and the context content, the query content and other first word pieces can be larger, so as to reduce the bias (that is, the context illusion) between the output result corresponding to the current first word piece and the output result of the previous first word piece.
[0031] In step 104, the initial output content is updated to obtain the target output content according to the updated attention value of the first word piece and the context content.
[0032] In the embodiment of the present application, the attention value of the first word element whose deviation value exceeds the preset deviation threshold is increased, and then the attention value of the first word element is updated. For the first word element with more serious context illusion, the updated attention value is used to participate in the process of generating subsequent output content by the prediction model; the obtained output content has a higher correlation degree with other first word elements in the context content and the query content, and is closer to other first word elements in the context content and the query content, effectively reducing the deviation in the subsequent output content generated by the prediction model, that is, the context illusion.
[0033] In summary, after obtaining the query content and the context content to be input into the prediction model, the deviation value of each first word element is determined according to the query content, the context content and the initial output content, and the mismatch degree of the first word element and the initial output content is determined; in the case that the deviation value of the first word element is greater than the preset deviation threshold, the attention value of the first word element is enhanced and updated according to the attention value of the first word element and the preset enhancement coefficient, so as 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 according to the updated attention value of the first word element and the context content. The method solves the problem that a large amount of computing power and manual annotation are required for the method of eliminating the context illusion, and the development cycle is long.
[0034] As shown in Figure 2 The present application provides a specific step flow chart of a model prediction result adjustment method, which comprises the following steps: Step 201, obtaining the query content and the context content to be input into the prediction model.
[0035] The context content is an associated description corresponding to the query content; the query content comprises a plurality of first word elements; each first word element has a corresponding attention value.
[0036] This step can be specifically referred to step 101 described above, and will not be described in detail here.
[0037] Step 202, determining the first probability vector of each first word element in the query content in the prediction model according to each first word element in the context content, the query content and the initial output content.
[0038] The prediction model comprises a first set number of second word elements.
[0039] The first probability vector includes components corresponding to all second word units arranged in descending order of corresponding probabilities; the first probability vector reflects probabilities of each second word unit in the prediction model being the first output word unit corresponding to the first word unit under the conditions 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.
[0040] In the embodiments of the present application, the prediction model includes a first set number of second word units, which form a vocabulary of the prediction model; the vocabulary can be regarded as a dictionary owned by the prediction model, and contains all word units that can be recognized by the prediction model, that is, the first word unit input from the outside world and the same as the second word unit in the vocabulary can be recognized by the prediction model; the word unit input from the outside world and not in the vocabulary formed by the second word units cannot be recognized by the prediction model. The vocabulary is a finite and fixed set, and the vocabulary and the second word units contained in the vocabulary are determined before the training of the prediction model. The input and output of the prediction model are both based on word units (including first word units and second word units).
[0041] A probability vector is a mathematical list, and the length of the probability vector is equal to the size of the vocabulary of the prediction model-the number of second word units. If the vocabulary has 50,000 words, the list has 50,000 numbers. Each number in the probability vector is a probability value between 0 and 1; all probability values add up to 1; that is, the next word unit predicted by the prediction model must be in the vocabulary of the prediction model.
[0042] The probability vector defines the possibility of each word in the vocabulary being selected as the next output word unit in a specific context.
[0043] Suppose the size of the vocabulary is When generating the next word unit, the prediction model outputs a probability vector with a dimension of as shown in equation (1): (1) where P represents the probability vector, and P represents the probability of each second word unit in the prediction model being selected as the next output word unit.
[0044] When the prediction model actually generates an output result, the final output composed of output word units needs to be selected according to the probability vector.
[0045] Optionally, step 202 can further include sub-step 221 to sub-step 222: Sub-step 221, merging the context content, the query content, and the initial output content to obtain a first sequence.
[0046] The first sequence includes a second predetermined number of first tokens.
[0047] 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.
[0048] 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.
[0049] 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: (2) 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.
[0050] 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.
[0051] 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.
[0052] 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.
[0053] In the embodiments of the present application, the second probability vector is calculated according to the query content and the initial output content; the second probability vector corresponds to the probability that each second word element in the prediction model is the first output word element corresponding to the first word element.
[0054] Optionally, step 203 can further include sub-step 301 to sub-step 302: Sub-step 301, merging the query content and the initial output content to obtain a second sequence; the second sequence includes a third set number of first word elements.
[0055] Sub-step 302, respectively determining the second conditional probability between the first word element in the query content and the first word element in the second sequence as the second probability vector.
[0056] The second conditional probability is used to represent 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.
[0057] In the embodiments of the present application, sub-step 301 to sub-step 302 further illustrate the calculation process of step 203. As shown in formula (3), a reasoning mode that can induce the prediction model to have more hallucination in predicting the probability of the current first word element in the query content corresponding to the first output word element is constructed, that is, only given the query content and the initial output content, the second probability vector for predicting the first output word element corresponding to the current first word element in the query content is calculated without providing the context content. : (3) The probability vector reflects the tendency of the prediction model to rely only on its own internal knowledge (that is, the query content) and the generated content of the initial output content, so it is easier to produce more hallucination. Similarly, the second probability vector is also a probability vector with a dimension of .
[0058] Step 204, taking the difference between the first probability vector and the second probability vector as the bias vector of the first word element.
[0059] In the embodiments of the present application, the first probability vector is a probability vector of the first output token corresponding to the current first token in the query content calculated by the prediction model on the basis of the context content, the initial output content and the query content; and the second probability vector is a probability vector of the first output token corresponding to the current first token in the query content calculated on the basis of only the query content and the initial output content, that is, without providing the context content. Because there is no constraint of the context content, the output content generated by the prediction model according to the second probability vector is more likely to deviate, that is, the phenomenon of context hallucination, compared with the output content generated by the prediction model according to the first probability vector.
[0060] As shown in formula (4), based on this property, first, the deviation value of the prediction model when predicting the first output token corresponding to the current first token in the query content is quantified to obtain a deviation vector including a plurality of deviation value components: (4) wherein, the current first token in the query content corresponding deviation vector.
[0061] The deviation vector is a vector with a dimension of ; and contains the potential deviation value of the prediction model when predicting the first output token corresponding to the current first token in the query content on the basis of the context content, the generated initial output content (historical output content) and the query information.
[0062] Step 205, determining the maximum component in each component of the deviation vector as the deviation value of the first token.
[0063] In the embodiments of the present application, on the basis of , the present application uses the maximum value of the absolute value of the elements in to further represent the strength of hallucination. The deviation vector is composed of components, and can be represented as .
[0064] As shown in formula (5), the calculation process of the deviation value of the first token is as follows: (5) wherein, denotes the deviation value corresponding to each first token .
[0065] The deviation vector The maximum component with the maximum component value in the components is taken as the deviation value of the first token, that is, the intensity of the contextual illusion is quantified, so that subsequent measures to eliminate the contextual illusion can be taken according to the quantified intensity of the contextual illusion.
[0066] Step 206: If the deviation value of the first token is greater than the preset deviation threshold, the updated attention value of the first token is calculated according to the attention value of the first token and the preset enhancement coefficient.
[0067] This step can specifically refer to step 101 described above, and will not be described in detail here.
[0068] Optionally, step 206 can further include substeps 601 to 602: Substep 601: Determine the sum of the preset enhancement coefficient and 1; Substep 602: Determine the product between the attention value of the first token and the sum as the updated attention value of the first token.
[0069] In the embodiments of the present application, the process of step 206 is further described. In step 206, the deviation value corresponding to each first token is calculated. Based on the deviation value corresponding to each first token, it is determined whether the deviation value corresponding to the first token exceeds the preset deviation threshold. If the deviation value corresponding to the first token exceeds the preset deviation threshold, it indicates that the deviation value corresponding to the first token is too large, that is, the output corresponding to the first token will have a relatively serious contextual illusion, and the contextual illusion of the first token needs to be eliminated.
[0070] Based on such a situation, for the first token whose corresponding deviation value exceeds the preset deviation threshold, the attention value of the first token is increased, that is, the relevance between the first token and other content in the context content, the query content and the like is increased, so that in the process of generating the output content by the large model, the relevance between the output content related to the first token with increased attention value and other content in the context content, the query content and the like is increased, and the contextual illusion (deviation) between the output result corresponding to the current first token and the output result of the previous first token is reduced.
[0071] Specifically, in the process of generating the output content corresponding to the first token in the query information by the prediction model (self-recurrence), when generating the output corresponding to the current first token, the self-attention mechanism of the prediction model calculates the attention value of each previous first token in the query information to the current first token. As shown in formula (6), the weight matrix of the standard self-attention mechanism is: (6) wherein, is the position of the current first token, is the position of the current first token of the i-th layer. is the query vector of the position i of the current first token of the i-th layer. is the key vector of all previous first tokens of the i-th layer. is the dimension of the key vector. Each element of the indicates the attention distribution of the current first token on the generated initial output content (length of ) of the prediction model, respectively represent the length of the context content and the query information. For example, indicates the attention of the position i of the current first token on the j-th second token in the generated initial output content of the prediction model.
[0072] In the standard large model inference, the generation of the first output token corresponding to the current first token has different degrees of attention on the context content, the query information and the generated initial output content, and the strength of the attention indicates the degree of dependence / reference of the generation of the first output token corresponding to the current first token on the context content, the query information and the generated initial output content to some extent.
[0073] In order to alleviate / eliminate the context hallucination between the output result of the current first token and the output result of the previous first token, as shown in formula (7), a context weighting strategy is used to enhance the attention of the current first token on the context content, the query information and the generated initial output content: (7) wherein, indicates the enhanced attention value of the current first token; indicates that the j-th second token of the generated initial output content belongs to the context content, indicates the set of context content; when , is 1, otherwise 0; indicates the enhancement coefficient.
[0074] In formula (7), when , the attention of the current first token i on the position j of the generated initial output content is increased by times, and therefore the larger the enhancement coefficient is, the more attention is paid to the context content. In the embodiments of the present application, the enhancement coefficient is set to 2. The reason why the enhancement coefficient is set to 2 is that, in the generation process of the first output token corresponding to the first token, the context The attention of the user is attracted, and the attention to other parts (such as query information and generated initial output content in the content) is not affected, and a balance is achieved.
[0075] Step 207, updating the initial output content according to the updated attention value of the first word and the context content, and obtaining target output content.
[0076] This step can specifically refer to step 104 described above, and will not be described in detail here.
[0077] Optionally, step 207 can further include sub-steps 701 to 703: Sub-step 701, forward propagation of the updated attention value of the first word in the prediction model to obtain a target probability vector corresponding to the first word.
[0078] The target probability vector is used to represent the probability vector with the highest accuracy corresponding to the first word; the probability vector includes all second words arranged in order of corresponding probability.
[0079] Sub-step 702, sampling the target probability vector to obtain a second output word corresponding to the first word; the second output word is the output corresponding to the first word in the prediction model.
[0080] Sub-step 703, merging the second output word and the initial output content as the target output content.
[0081] In the embodiments of the present application, sub-steps 701 to 703 further describe the specific process of step 204. After the attention value corresponding to the first word with a larger bias value is enhanced, a larger attention value corresponding to the first word is obtained. The larger attention value corresponding to the first word is forward propagated in the prediction model to obtain a target probability vector corresponding to the enhanced attention value of the first word. The second word in the target probability vector obtained in this way has a higher correlation degree with the context content, the query information and the initial generated content, and reduces the context hallucination in the generated content corresponding to the first word.
[0082] Based on the target probability vector, different sampling methods are used to sample the target probability vector to obtain a first output word corresponding to the first word after correction. As shown in formula (8), formula (9), formula (10) and formula (11): ①Using greedy selection, the first output word generated by sampling is: (8) Wherein, represents the target probability vector; ②Using Top-k sampling: in , a subset of the top-k second tokens with the highest probabilities is randomly sampled: (9) ③Top-p sampling: in , a minimum set of tokens whose cumulative probability exceeds a threshold is sampled: (10) (11) Optionally, the sub-step 703 can further include sub-step A1 to sub-step A2: Sub-step A1, if the first token is the last first token in the query content, taking the target output content as the output result of the prediction model corresponding to the query content.
[0083] Sub-step A2, if the first token is not the last first token in the query content, continue to calculate the second output token corresponding to the first token in the query content.
[0084] In the embodiments of the present application, the second output token corresponding to the first token in the query content is continuously predicted and the relevant content is generated in the prediction model. When the first token at the current position is the last first token in the query content, the prediction model enters the next stage, uses 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 the relevant content in the prediction model.
[0085] As shown in Figure 3 , when the input question + the generated content in the prediction model includes; input prompt Q: Ms. Wang did not pass the drug purchase application process and directly purchased drugs at the pharmacy at her own expense; but how should Ms. Wang report the reimbursement if she did not use medical insurance reimbursement? The generated sequence G: OK. The drugs purchased by Ms. Wang are in.
[0086] In the case of having context input and not having context input respectively, the probability sequence of the output of the current token in the input prompt Q is calculated, and it is calculated that the illusion intensity at this time exceeds the threshold (the probability difference corresponding to "home" is large), and the illusion of the output of the current token is eliminated / relieved. The attention of the token with large illusion is enhanced by combining the enhancement coefficient, and the enhanced attention is obtained. The current token is used to forward propagate the enhanced attention, and the final more accurate probability sequence (the illusion of "home" is eliminated) is obtained, so as to generate an output token with smaller illusion.
[0087] As Figure 4 shown, the adjustment method of the model prediction result provided by the embodiment of the application can include the following steps: Step K1, initialize parameters: context C, input prompt Q position = 1, generated sequence G = φ.
[0088] In the embodiment of the application, before using the prediction model, the related parameters need to be initialized first, 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 result initially generated after the input prompt Q is processed in the prediction model according to the context C.
[0089] Step K2, judge whether the generation end condition is reached.
[0090] In the embodiment of the application, when the output corresponding to the last token in the context C and the input prompt Q is processed in the prediction model, the prediction model reaches the generation end condition and no longer generates the output corresponding to the token.
[0091] Step K3, output the final sequence.
[0092] In the embodiment of the application, after the prediction model reaches the generation end condition, the sequence in which all the outputs corresponding to the tokens generated before are output as the final sequence.
[0093] Step K4, calculate the context conditional distribution probability and the base probability distribution.
[0094] In the embodiment of the application, if the generation end condition has not been reached, the context conditional distribution probability and the base probability distribution of the current token are calculated. The base probability distribution is the probability distribution corresponding to the current token without context.
[0095] Step K5, calculate the potential illusion direction output final sequence and the illusion strength.
[0096] In the embodiment of the application, the difference (vector difference) between the context conditional distribution probability and the base probability distribution is calculated to obtain the potential illusion direction output final sequence of the current token, and the maximum value in the potential illusion direction output final sequence is taken as the illusion strength of the current token.
[0097] Step K6, judge whether it is greater than a preset threshold.
[0098] In the embodiment of the application, it is judged whether the illusion strength of the current token is greater than the preset (illusion) threshold.
[0099] Step K7, take the context conditional probability distribution as the final probability distribution.
[0100] In the embodiment of the present application, if the illusion strength of the current token does not exceed the preset (illusion) threshold, the context conditional distribution probability calculated in step K5 is taken as the final probability distribution of the current token, that is, the illusion of the current token is small, and there is no need to further eliminate the illusion.
[0101] Step K8, sampling according to the final probability distribution to generate a new token.
[0102] In the embodiment of the present application, the context conditional distribution probability (vector) is sampled to obtain the output (token) corresponding to the current token.
[0103] Step K9, the obtained new token is added to the generated sequence.
[0104] In the embodiment of the present application, the output (token) corresponding to the current token is added to the generated sequence for storage.
[0105] Step K10, correcting the attention score of the current token relative to the context token.
[0106] In the embodiment of the present application, if the illusion strength of the current token is greater than the preset (illusion) threshold, it means that the illusion strength is high and needs to be eliminated / relieved. The corresponding method is to correct the attention value of the current token, so that the relevance of the current token to the context and the generated sequence is enhanced.
[0107] Step K11, using the corrected attention score for forward propagation to obtain the final probability distribution.
[0108] In the embodiment of the present application, the enhanced attention value of the current token is used for forward propagation in the prediction model, so that the output content corresponding to the current token has stronger relevance to the context and the generated sequence, and the final probability distribution of the current token after correction is obtained. Then, enter step K8, step K9 and step K10 to generate the output (token) after final elimination of illusion and the generated sequence.
[0109] As shown in Figure 5 The embodiment of the present application provides an adjustment device 600 for model prediction results, which comprises: An acquisition module 601 is 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.
[0110] The first calculation module 602 is configured to determine a bias value of each first word element according to the query content, the context content and initial output content; the initial output content is an initial prediction result output by the prediction model for the query content and the context content; and the bias value is used to represent a mismatch degree of the first word element and the initial output content.
[0111] Optionally, the first calculation module 602 can further include: The first calculation sub-module is configured to determine a first probability vector of each first word element in the query content in the prediction model according to each first word element in the context content, the query content and the initial output content; the first probability vector includes components corresponding to all second word elements arranged in a size order of corresponding probabilities; the first probability vector reflects a probability that each second word element in the prediction model is a first output word element corresponding to the first word element under a condition of the query content, the context content and the initial output content; and the first output word element is a corresponding output of the first word element in the prediction model.
[0112] Optionally, the first calculation sub-module 602 can further include: The first merging unit is configured to merge the context content, the query content and the initial output content to obtain a first sequence; and the first sequence includes a second set number of first word elements.
[0113] The first calculation unit is configured to determine a 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; and the first conditional probability is used to represent a probability that each first word element in the first sequence is a first output word element corresponding to the first word element in the query content.
[0114] The second calculation sub-module is configured to determine a second probability vector of each first word element in the query content according to 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 a size order of corresponding probabilities; and the second probability vector reflects a probability that each second word element in the prediction model is a first output word element corresponding to the first word element under a condition of the query content and the initial output content.
[0115] Optionally, the second calculation sub-module can further include: The second merging unit is configured to merge the query content and the initial output content to obtain a second sequence; and the second sequence includes a third set number of first word elements.
[0116] The third computing unit is configured to determine a second conditional probability between the first word unit in the query content and the first word unit in the second sequence respectively as the second probability vector; and the second conditional probability is used to represent a probability of each first word unit in the second sequence as a first output word unit corresponding to the first word unit in the query content.
[0117] The third computing sub-module is configured to take a difference between the first probability vector and the second probability vector as the bias vector of the first word unit.
[0118] The second computing module 603 is configured to, if the bias value of the first word unit is greater than a preset bias threshold, calculate an updated attention value of the first word unit according to the attention value of the first word unit and a preset enhancement coefficient.
[0119] Optionally, the second computing module 603 can further include: The fourth computing sub-module is configured to determine a sum of the preset enhancement coefficient and 1.
[0120] The fifth computing sub-module is configured to determine a product between the attention value of the first word unit and the sum as the updated attention value of the first word unit.
[0121] The updating module 604 is configured to update the initial output content according to the updated attention value of the first word unit and the context content to obtain a target output content.
[0122] Optionally, the updating module 604 can further include: The propagation sub-module is configured to forward propagate the updated attention value of the first word unit in the prediction model to obtain a target probability vector corresponding to the first word unit; the target probability vector is used to represent a probability vector with the highest accuracy corresponding to the first word unit; and the probability vector includes all second word units arranged in order of corresponding probabilities.
[0123] The sampling sub-module is configured to sample the target probability vector to obtain a second output word unit corresponding to the first word unit; and the second output word unit is an output corresponding to the first word unit in the prediction model.
[0124] The merging sub-module is configured to merge the second output word unit and the initial output content as the target output content.
[0125] Optionally, the merging sub-module can further include: The first output unit is configured to, if the first word unit is the last first word unit in the query content, take the target output content as an output result of the prediction model corresponding to the query content.
[0126] The second output unit is configured to continue to calculate the second output word unit corresponding to the first word unit in the query content if the first word unit is not the last first word unit in the query content.
[0127] Referring to Figure 6 The electronic device 400 can include one or more of the following components: a processing component 402, a memory 404, a power supply component 406, a multimedia component 408, an audio component 410, an input / output (I / O) interface 412, a sensor component 414, and a communication component 416.
[0128] The processing component 402 usually controls overall operations of the electronic device 400, such as operations associated with displaying, making phone calls, data communications, camera operations, and recording operations. The processing component 402 can include one or more processors 420 to execute instructions to complete all or part of steps of the methods described above. In addition, the processing component 402 can include one or more modules to facilitate interaction between the processing component 402 and other components. For example, the processing component 402 can include a multimedia module to facilitate the interaction between the multimedia component 408 and the processing component 402.
[0129] The memory 404 is used to store various types of data to support operations of the electronic device 400. Examples of these data include instructions for any application or method operating on the electronic device 400, contact data, phonebook data, messages, pictures, multimedia, and the like. The memory 404 can be implemented by any type of volatile or non-volatile storage devices 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.
[0130] The power supply component 406 provides power for various components of the electronic device 400. The power supply component 406 can include a power supply management system, one or more power supplies, and other components associated with generating, managing and distributing power for the electronic device 400.
[0131] The multimedia component 408 includes an interface for outputting various media content (e.g., audio, video, etc.). The interface can include a liquid crystal display (LCD) and a touch panel (TP). If the interface includes a touch panel, the interface can be implemented as a touch screen to receive input signals from a user. The touch panel includes one or more touch sensors for sensing a touch, gesture, or movement on the touch panel. The touch sensor can not only sense a boundary of a touch or gesture, but also detect duration and pressure related to the touch or gesture. In some embodiments, the multimedia component 408 includes a front camera and / or a rear camera. When the electronic device 400 is in an operating mode, such as a shooting mode or a multimedia mode, the front camera and / or the rear camera can receive external multimedia data. Each of the front and rear cameras can be a fixed optical lens system or have a focal length and optical zoom capability.
[0132] The audio component 410 is configured to output and / or input audio signals. For example, the audio component 410 includes a microphone (MIC) for receiving an external audio signal when the electronic device 400 is in an operating mode, such as a call mode, a recording mode, and a voice recognition mode. The received audio signal can be further stored in the memory 404 or transmitted via the communication component 416. In some embodiments, the audio component 410 also includes a speaker for outputting audio signals.
[0133] The input / output (I / O) interface 412 provides an interface between the processing component 402 and peripheral interface modules, which can include a keypad, click wheel, button, and so on. The buttons can include, but are not limited to, a home button, a volume button, a start button, and a lock button.
[0134] The sensor component 414 includes one or more sensors for providing status assessments of various aspects of the electronic device 400. For example, the sensor component 414 can detect an open / closed position of the electronic device 400, relative positioning of components, such as a display and a keypad of the electronic device 400, a change in position of the electronic device 400 or a component of the electronic device 400, the presence or absence of user contact with the electronic device 400, the orientation or acceleration / deceleration of the electronic device 400, and a temperature change of the electronic device 400. The sensor component 414 can include a proximity sensor configured to detect presence of a nearby object without any physical touch. The sensor component 414 can also include a light sensor (e.g., a CMOS or CCD image sensor) configured to function in an imaging application. In some embodiments, the sensor component 414 can further include an acceleration sensor, a gyroscope sensor, a magnetic sensor, a pressure sensor, or a temperature sensor.
[0135] The communication component 416 is configured to facilitate wired or wireless communication between the electronic device 400 and other devices. The electronic device 400 can access a wireless network based on a communication standard, such as WiFi, a cellular network (e.g., 2G, 3G, 4G or 5G), or a combination thereof. In an exemplary embodiment, the communication component 416 receives broadcast signals or broadcast-related information from external broadcast management systems via a broadcast channel. In an exemplary embodiment, the communication component 416 further includes a Near Field Communication (NFC) module to facilitate short-range communication. For example, the NFC module can be implemented based on Radio Frequency Identification (RFID) techniques, infrared data association (IrDA) techniques, ultra-wideband (UWB) techniques, Bluetooth (BT) techniques and other techniques.
[0136] In an exemplary embodiment, the electronic device 400 can be implemented with 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, micro-controllers, microprocessors or other electronic elements, to implement a method for adjusting a model prediction result according to an embodiment of the present application.
[0137] In an exemplary embodiment, a non-transitory computer readable storage medium including instructions, such as the memory 404 including instructions, is also provided. The instructions can be executed by the processor 420 of the electronic device 400 to complete the above method. For example, the non-transitory storage medium can be a ROM, a random access memory (RAM), a CD-ROM, a magnetic tape, a floppy disc, and an optical data storage device, etc.
[0138] Figure 7 is a block diagram of an electronic device 400 according to another embodiment of the present application. For example, the electronic device 400 can be provided as a server. Referring to Figure 7 The electronic device 400 includes a processing component 402, which further includes one or more processors, and a memory resource represented by a memory 404, for storing instructions, such as application programs, executable by the processing component 402. The application programs stored in the memory 404 can include one or more modules each corresponding to a set of instructions. In addition, the processing component 402 is configured to execute the instructions to implement a method for adjusting a model prediction result according to an embodiment of the present application.
[0139] The electronic device 400 can also include a power supply component 406 configured to perform power management for the electronic device 400, a wired or wireless network interface 550 configured to connect the electronic device 400 to a network, and an input / output (I / O) interface 558. The electronic device 400 can operate based on an operating system stored in the memory 404, such as Windows Server™, Mac OS X™, Unix™, Linux™, FreeBSD™, or the like.
[0140] Other embodiments of the application will be apparent to those skilled in the art from consideration of the specification and practice of the application disclosed herein. It is intended that the specification and examples be considered as exemplary only, with the true scope and spirit of the application being indicated by the following claims.
[0141] It is to be understood that the application is not limited to the precise construction described in the specification and shown in the drawings, and that various modifications and changes can be effected therein by those skilled in the art without departing from the scope of the application. The scope of the application is to be defined by the claims appended hereto.
[0142] While the preferred embodiments of the application have been described above, it will be recognized and understood that various modifications and changes can be made to these embodiments by those skilled in the art without departing from the broader spirit and scope of the application as set forth in the appended claims. The scope of the application includes all available alternatives.
[0143] In the description of the specification, the description using the terms "one embodiment", "some embodiments", "an exemplary embodiment", "an example", "a specific example", or "some examples" etc. means that the particular feature, structure, material, or characteristic being described is included in at least one embodiment or example of the present application. The appearances of the above terms in various places in the specification are not necessarily referring to the same embodiment or example. Furthermore, the particular features, structures, materials, or characteristics can be combined in any suitable manner in one or more embodiments or examples.
[0144] Also, the term "comprising" or "including" or any other variation thereof is intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but can also include other elements not expressly listed or inherent to such process, method, article, or apparatus. An element proceeded by "comprises... a" does not, without more constraints, exclude the existence of additional identical elements in the process, method, article, or apparatus that comprises the element.
[0145] The above describes in detail the model prediction result adjustment method and device, electronic equipment and readable storage medium provided by the present application. The principles and implementation manners of the present application are described by applying specific examples. The above example is only used to help understand the method and core idea of the present application. Meanwhile, for those skilled in the art, the specific implementation manners and application ranges can be changed according to the idea of the present application. In summary, the content of the specification should not be understood as a limitation of the present application.
Claims
1. A method for adjusting model prediction results, characterized in that, The method includes: 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; 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. 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. 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.
2. The method for adjusting the model prediction results according to claim 1, characterized in that, The prediction model includes a first predetermined number of second word elements; The step of determining the deviation value of each first term based on the query content, the context content, and the initial output content includes: Based on each first word element in the context content, the query content, and the initial output content, a first probability vector is determined for each first word element in the query content in the prediction model. 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 element in the prediction model is the first output word element corresponding to the first word element, given the query content, the context content, and the initial output content. The first output word element is the output corresponding to the first word element in the prediction model. Based on each first word element in the query content and the initial output content, a second probability vector is determined for each first word element in the query content; the second probability vector includes components corresponding to all second word elements arranged in order of their corresponding probabilities; the second probability vector reflects the probability that each second word element in the prediction model is the first output word element corresponding to the first word element under the conditions of the query content and the initial output content. The difference between the first probability vector and the second probability vector is used as the deviation vector of the first word. The largest component among the components of the deviation vector is determined as the deviation value of the first word.
3. The method for adjusting the model prediction results according to claim 1, characterized in that, When the deviation value of the first word element is greater than a 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 a preset enhancement coefficient, including: Determine the sum of the preset enhancement coefficient and 1; The attention value of the first word is determined, and the product between the attention value and the summation result is used as the updated attention value of the first word.
4. The method for adjusting the model prediction results according to claim 1, characterized in that, The step of updating the initial output content based on the updated attention value of the first word and the context content to obtain the target output content includes: The updated attention value of the first word element is forward-propagated 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. The target probability vector is sampled 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. The second output term is merged with the initial output content to form the target output content.
5. The method for adjusting the model prediction results according to claim 4, characterized in that, After merging the second output term with the initial output content to obtain the target output content, the method further includes: If the first word element is the last first word element in the query content, the target output content is used as the output result of the prediction model corresponding to the query content; 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.
6. The method for adjusting the model prediction results according to claim 2, characterized in that, The step of determining the first probability vector for each first word in the query content in the prediction model based on the context content, the query content, and each first word in the initial output content includes: The context content, the query content, and the initial output content are merged to obtain a first sequence; the first sequence includes a second predetermined number of first word elements; The first conditional probability between the first word element in the query content and each first word element in the first sequence is determined and used 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.
7. The method for adjusting the model prediction results according to claim 2, characterized in that, The step of determining 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 includes: The query content and the initial output content are merged to obtain a second sequence; the second sequence includes a third predetermined number of first word elements; The second conditional probability between the first word element in the query content and the first word element in the second sequence is determined and used 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.
8. A device for adjusting model prediction results, characterized in that, The device includes: 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; 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. 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. 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.
9. An electronic device, characterized in that, It includes a processor and a memory, the memory storing a program or instructions that can run on the processor, the program or instructions being executed by the processor to implement the steps of the method as described in any one of claims 1 to 7.
10. A readable storage medium, characterized in that, The readable storage medium stores a program or instructions that, when executed by a processor, implement the steps of the method as described in any one of claims 1 to 7.
Citation Information
Patent Citations
Test data processing method and device based on semantic analysis
CN116383050A
Text processing method and device, equipment, storage medium and program product
CN116975197A
Neural network model training method and device, electronic equipment and storage medium
CN117648950A
Text generation method, electronic device, storage medium and computer program product
CN119127038A
Text generation method, text generation model training method and related devices
CN120235152A