CN-122021626-A - Large language model dynamic prompt word optimization method based on uncertainty perception and application thereof
Abstract
The application provides a large language model dynamic prompt word optimization method based on uncertainty perception and application thereof, and belongs to the technical field of natural language processing. The method comprises the steps of constructing an initial Prompt word by utilizing a reference example based on uncertainty index screening to perform preliminary reasoning, calculating a logarithmic focus uncertainty index based on a probability distribution entropy value and a category priori probability of a reasoning initial word, directly outputting a result if the index is lower than a preset threshold value, triggering a retrieval enhancement mechanism if the index is higher than the threshold value, and constructing an enhanced Prompt word (Prompt) containing a disguise guidance and similar reference sample to perform secondary reasoning. According to the application, the reasoning path is dynamically allocated through the real-time perception model confidence, so that excessive confidence of the model is effectively restrained, the calculation cost is reduced, and the task robustness under a complex scene is improved.
Inventors
- YU YAN
- CHEN WEI
- QI YUANYUAN
- Ju Guoyang
- ZHAO YUANKE
- SI HUAYOU
- YANG YANG
Assignees
- 中国计量大学
Dates
- Publication Date
- 20260512
- Application Date
- 20260407
Claims (10)
- 1. The method for optimizing the dynamic prompt words of the large language model based on uncertainty perception is characterized by comprising the following steps of: Acquiring a user input text to be processed; First stage reasoning: Filling the user input text into a preset initial prompt word template comprising a plurality of reference examples screened based on uncertainty indexes, and performing preliminary reasoning by using a large language model to obtain probability distribution and preliminary prediction results of first word elements generated by the model; uncertainty index calculation: calculating information entropy based on the probability distribution of the first word element, and calculating a logarithmic focus uncertainty index by combining the category prior probability corresponding to the preliminary prediction result; dynamic gating decision: comparing the logarithmic focus uncertainty index with a preset interception threshold; and (2) second stage treatment: if the logarithmic focus uncertainty index is smaller than the interception threshold, judging that the model confidence is high, and directly outputting the preliminary prediction result; If the logarithmic focus uncertainty index is larger than or equal to the interception threshold, judging that the model has error risk, triggering a search enhancement generation flow, constructing an enhancement prompt word to perform secondary reasoning on the text input by the user, and outputting a final prediction result.
- 2. The large language model dynamic cue word optimization method as claimed in claim 1, wherein in the uncertainty index calculation step, the logarithmic focus uncertainty index The calculation formula of (2) is as follows: Wherein, the The normalized information entropy of K candidate words with highest probability in Logits corresponding to the first word element output by the model is represented, The category prior probability of the preliminary prediction result y in the training data set is represented, the index 2 is the focusing parameter, To prevent log overflow.
- 3. The method for optimizing large language model dynamic hint words according to claim 2, wherein the normalized information entropy The calculation steps of (1) comprise: K candidate words with highest probability in first word element Logits output by last layer of extraction model form set ; Pair aggregation Normalizing the probability of the candidate word; Calculating shannon entropy based on the normalized probability; wherein, the value of K is an integer between 50 and the full vocabulary size.
- 4. The large language model dynamic cue word optimization method as claimed in claim 1, wherein the initial cue word template including a number of reference examples based on uncertainty index screening is constructed by the following offline screening steps: Randomly selecting N examples from the sample set as initial seed construction templates; reasoning the residual samples in the sample set by using the template, and recording the logarithmic focus uncertainty index and the prediction accuracy of each sample; And screening N different types of examples with low logarithmic focus uncertainty indexes and correct prediction results as reference examples based on uncertainty index screening, replacing the initial seeds, and forming the initial prompt word template.
- 5. The method for optimizing large language model dynamic prompt words according to claim 1, wherein the method for setting the interception threshold is as follows: Reasoning the sample set by using the initial prompt word template containing the reference examples screened based on the uncertainty index; Counting logarithmic focus uncertainty index distribution of error samples; And selecting a numerical value as the interception threshold value, so that the numerical value can cover the logarithmic focus uncertainty index of more than 90% of error samples in the sample set.
- 6. The method for optimizing large language model dynamic prompt word according to claim 1, wherein the specific steps of triggering the search enhancement generation flow in the second stage process include: And (5) similar sample retrieval: Mapping the user input text into a vector, calculating the similarity between the user input text and samples in a pre-constructed sample vector knowledge base, and searching N reference samples with highest semantic similarity and real labels thereof; Enhancement type prompt word construction: And splicing the user input text, the preliminary prediction result, the reference sample and the anti-thinking guide instruction according to a preset format to generate an enhanced prompt word.
- 7. The method for optimizing large language model dynamic hint words of claim 6, wherein the predetermined format of the enhanced hint words comprises sequential concatenation of: The historical interaction context comprises initial prompt words and preliminary prediction results of the first-stage reasoning; performing disfigurement guiding speech operation, namely prompting uncertainty existing in previous prediction of a model and introducing similar cases; the similar reference samples are listed as contents of the N reference samples and corresponding standard labels; and reevaluation instruction, namely reevaluating the text input by the user based on the information by the requirement model and outputting the type.
- 8. The large language model dynamic prompt word optimization method according to any one of claims 1-7, further comprising, in the second stage process, an iterative optimization mechanism: after the secondary reasoning is carried out, calculating the logarithmic focus uncertainty index of the secondary reasoning result again; If the index is still higher than the interception threshold and the maximum iteration number is not reached, optimizing the search query condition, replacing the reference sample, and re-executing the steps of constructing and reasoning the enhanced prompt word.
- 9. A large language model dynamic hint word optimization system based on uncertainty perception, comprising: the first reasoning module is used for carrying out preliminary reasoning on the user input by using an initial prompt word containing a reference example screened based on the uncertainty index; the index calculation module is used for calculating a logarithmic focus uncertainty index based on the first word probability distribution and the category prior probability; The gating decision module is used for comparing the index with an interception threshold value, and selectively outputting a preliminary result or triggering a second reasoning module according to the comparison result; And the second reasoning module is used for searching similar samples and constructing enhanced prompt words by combining the anti-thinking instruction when the index is higher than the threshold value, and carrying out secondary reasoning.
- 10. A readable storage medium, characterized in that the readable storage medium has stored therein a computer program comprising program code for controlling a process to execute a process comprising the large language model dynamic cue word optimization method according to any one of claims 1 to 8.
Description
Large language model dynamic prompt word optimization method based on uncertainty perception and application thereof Technical Field The invention relates to the technical field of artificial intelligence and Natural Language Processing (NLP), in particular to a context engineering (Context Engineering) and prompt word optimization (Prompt Optimization) technology of a Large Language Model (LLMs), and particularly relates to a large language model dynamic prompt word optimization method based on uncertainty perception and application thereof. Background With the widespread use of Large Language Models (LLMs) in the field of natural language processing, task processing modes based on prompt engineering (Prompt Engineering) have become the mainstream. Models typically employ autoregressive means to generate text during the inference process, the output of which is essentially a prediction based on probability distribution. While large language models perform well in a general context, challenges of "illusion" and "excessive confidence" remain facing in handling understanding tasks in a particular area. In order to solve the problem of inaccurate model answer, the prior art mainly has two types of improvement paths, but has obvious limitations: 1. The limitations of uncertainty quantization methods are that the prior art generally requires an assessment of the confidence level of the model in order to predict whether the answer to the model is reliable. The calculation cost is high, and the mainstream method (such as Self-Consistency, self-consistency check) usually depends on repeated sampling of the same input for multiple times, and post evaluation is performed through consistency of statistical results. This approach increases the computational effort and time costs of reasoning exponentially, making it difficult to meet real-time requirements. The evaluation index misalignment is that the traditional measurement method based on simple entropy value or Top-k probability can only reflect the statistical preference of the model to high-frequency vocabulary, but cannot truly reflect the understanding degree of the model to logic or semantics. In long-tail samples or complex semantic scenarios, models often exhibit "excessive confidence" (Overconfidence), i.e., while giving a high probability of predicted words, the actual results are erroneous. 2. The rigidity and inefficiency of the hint enhancement mechanisms (such as RAG) to make up for the lack of model knowledge, the prior art often employs a search enhancement generation (RAG) or context learning (ICL) technique to assist in reasoning by introducing external samples (i.e., "dictionary look-up"). However, existing hinting optimization schemes generally lack the ability to dynamically perceive the state of the model itself: the triggering mechanism is rigidified, and the existing enhancement framework usually adopts a strategy of 'full coverage', namely whether the problem of a user is simple or complex, external knowledge retrieval or sample splicing is forced. The noise and delay are introduced, namely, for the simple problem that the model can directly answer by means of self knowledge (parameterized memory), forced retrieval not only causes unnecessary reasoning delay, but also can cause 'up-down Wen Zaosheng' of the retrieved unnecessary information, and the original judgment of the model is interfered, so that the accuracy is reduced instead. In summary, the prior art lacks an effective index capable of perceiving the "hesitation degree" of the model itself in real time at low cost, through which the most representative information writing prompt word can be selected from the sample, and an adaptive mechanism for dynamically determining whether to call external auxiliary information based on the index. How to conduct targeted prompt optimization only aiming at samples with insufficient confidence of a model while guaranteeing reasoning efficiency is a technical problem which needs to be solved currently. Disclosure of Invention The embodiment of the application provides a large language model dynamic prompt word optimization method based on uncertainty perception and application thereof, aiming at the problems that in the prior art, uncertainty measurement needs to wait for complete answer, calculation cost is high, and the answer is not aligned on a long tail sample, and a dynamic mechanism is lacking when a retrieval enhancement (RAG) is utilized in the traditional method, so that noise and delay are introduced due to forced retrieval of a simple task, and accuracy is insufficient due to lack of targeted guidance of a complex task. The core technology of the invention mainly provides a dynamic Prompt word (Prompt) optimization framework (UPDPOF) based on logarithmic focus uncertainty (LSFU) indexes, and the rapid reasoning path (system I) based on a golden example (reference example based on uncertainty index screening) and the enhanced reasoning