Context learning example selection method based on two queries and low-rank approximate rearrangement
By adopting two-time query and low-rank approximate rearrangement techniques in context learning, the problem of insufficient sample selection performance in complex inference tasks is solved, and more efficient and accurate sample selection is achieved, improving the inference performance of large language models.
Patent Information
- Application Number
- CN202411761863.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-03
- Publication Date
- 2025-04-29
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
The prior art has poor example selection performance in complex inference tasks, and cannot effectively capture intermediate steps in the multi-step inference chain, and redundant information in the high-dimensional embedded space interferes with the example selection process.
Using a context learning example selection method based on two-queries and low-rank approximate rearrangement, an initial thinking chain is generated through the initial query, a training data set is constructed and a searcher is trained, and the first rearrangement and dimensionality reduction is performed, and the second rearrangement is performed to select the most relevant examples.
It significantly improves the accuracy and efficiency of sample selection, enhances the inference performance of large language models in multi-step inference tasks, and shows stronger robustness and adaptability in distributed offset scenarios.
Smart Images

Figure CN119903084A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a context learning example selection method based on double queries and low-rank approximate rearrangement. Background Art
[0002] With the rapid development of natural language processing technology, large language models (LLMs) are increasingly used in various complex tasks. In recent years, in-context learning (ICL) has become an important research direction for the reasoning ability of large language models. ICL provides a small number of examples to the model, allowing the model to infer the answer to the question based on these examples without explicit training. This learning method can adapt to different task scenarios, and has shown great potential in multi-step reasoning tasks.
[0003] However, the core challenge of ICL lies in how to effectively select appropriate examples, which will directly affect the reasoning performance of the model. Existing example selection methods usually rely on the direct similarity between the input question and the example. However, complex reasoning tasks usually involve multi-step reasoning processes, and simply relying on the semantic similarity of the problem cannot fully capture the intermediate steps in these reasoning chains, thus affecting the final reasoning results. In addition, as the high-dimensional embedding representations generated by large language models become more and more complex, the efficiency of example selection is also constrained by the redundant information in the high-dimensional embedding space, further reducing the reasoning effect and efficiency.
[0004] Therefore, the example selection methods in the prior art have poor reasoning performance in practical applications. Summary of the invention
[0005] In view of this, the present invention provides a context learning example selection method based on two queries and low-rank approximate rearrangement to solve the above problems.
[0006] The present invention provides a context learning example selection method based on two queries and low-rank approximate rearrangement, comprising: obtaining an initial example and an input question; querying a large language model based on the initial example and the input question to generate an initial thought chain; constructing a training data set according to the input question and the initial thought chain, and constructing a training sample using the training data set; training a retriever, retrieving a preset number of similar training samples as candidate samples from the training data set through a BM25 algorithm; calculating the similarity between the representation of the candidate sample and the representation of the input question, and performing a first rearrangement based on the similarity; performing dimensionality reduction on the representation of the candidate sample after the first rearrangement, and performing a second rearrangement on the similarity of the representation after dimensionality reduction; based on the similarity score of the example after the second rearrangement, selecting an example to splice with the input question, and inputting the spliced example into the large language model to obtain a target thought chain; parsing the target thought chain to obtain a standard answer.
[0007] In another implementation of the present invention, the similarity is expressed as:
[0008]
[0009] Among them, d j ′ is an example in the candidate sample, j = 1, 2, ..., k; x i is the input question; y i For x i The corresponding chain of thought; P LM (y i |d j ′ ,x i ) means in example d j ′ and input problem x i In the case of i The higher the score, the higher the probability of j ′ Contains and thinking chain i The higher the probability of similar reasoning logic.
[0010] In another implementation of the present invention, the contrast loss function of the retriever is expressed as:
[0011]
[0012] Among them, sim is the training sample d i =(x i ,y i ) and the example d in the candidate sample j The similarity between them is expressed as:
[0013]
[0014] Among them, se is the retriever trained by the above loss function.
[0015] In another implementation of the present invention, the representation of the candidate samples after the first rearrangement is subjected to dimensionality reduction processing, and the similarity of the representation after dimensionality reduction is subjected to a second rearrangement, including: using principal component analysis to perform dimensionality reduction processing on the embedding of the examples in the candidate samples after the first rearrangement and the initial thinking chain in the training sample; and performing a second rearrangement based on the similarity of the representation after dimensionality reduction processing.
[0016] In the context learning example selection method based on two queries and low-rank approximate rearrangement of the present invention, the reasoning chain information is generated by combining the two query mechanism, and the low-rank approximation technology is used to reduce the dimension and rearrange the examples, which overcomes the limitations of existing methods in complex reasoning tasks and effectively improves the accuracy and efficiency of example selection; the synergistic effect of these two parts significantly improves the reasoning performance of large language models in multi-step reasoning tasks, especially in scenarios dealing with distribution shift, showing stronger robustness and adaptability. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] In order to more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the following briefly introduces the drawings required for use in the embodiments or the prior art descriptions. By reading the detailed description of the following implementations, the advantages and benefits of the solutions become clear to those skilled in the art. The drawings are only used to illustrate the preferred implementations and are not to be considered as limiting the present invention.
[0018] In the attached picture:
[0019] Figure 1 The present invention is a flowchart of a context learning example selection method based on two queries and low-rank approximate rearrangement according to an embodiment of the present invention.
[0020] Figure 2 The present invention is a data processing flow diagram of a context learning example selection method based on two queries and low-rank approximate rearrangement according to an embodiment of the present invention. DETAILED DESCRIPTION
[0021] For ease of understanding, before describing in detail a specific embodiment of the present invention, an existing technique of a context learning example selection method based on two queries and low-rank approximate rearrangement of the present invention is exemplarily described.
[0022] In-Context Learning (ICL), how to select appropriate examples directly affects the reasoning ability of the model. At present, some existing methods have made some progress in example selection, which can be mainly divided into the following categories:
[0023] Example selection based on similarity matching: The earliest ICL example selection methods usually match based on the similarity between the input question and the examples in the training set. Such methods select the example that is most similar to the input question by calculating the similarity between the input question and the embedding representation of the training example. For example, based on retrieval techniques such as BM25 or Dense Passage Retrieval (DPR), the closest question and answer pair can be selected by calculating the similarity between the input question and the example in the embedding space.
[0024] The main advantage of this method is that it is simple and intuitive, and it can use existing retrieval technology. However, simple similarity matching often cannot effectively capture the reasoning requirements of the problem, and it is difficult to accurately reflect their logical associations in complex reasoning tasks, ignoring the multi-step reasoning chains that may exist in the problem. Such example selection can easily lead to a decline in reasoning quality, especially in tasks that require multi-step reasoning. The surface semantic similarity of the input problem may be far from the actual reasoning process, resulting in the selected examples not being able to help the model perform effective reasoning.
[0025] Example selection based on contrastive learning: In recent years, other methods have used contrastive learning to improve the quality of example selection. These methods enhance the model's ability to distinguish between examples by introducing positive and negative examples during training. For example, the Efficient Prompt Retrieval (EPR) model optimizes the contrast target of example selection through contrastive learning, and ultimately selects examples that are closer to the input problem in reasoning logic. In addition, Compositional Exemplars for In-Context Learning (CEIL) further optimizes the diversity and accuracy of example selection by modeling the interaction between input problems and examples.
[0026] These contrastive learning-based methods can significantly improve the effect of example selection, especially in reasoning tasks. However, although these methods can effectively capture the differences between problems and examples, they do not fully address the problem of information redundancy in the example selection process, especially in high-dimensional embedding space. The redundant information between examples will interfere with the model selection process, resulting in a decrease in reasoning performance.
[0027] In summary, existing example selection methods have solved some problems in ICL to varying degrees, but they still face limitations such as insufficient use of reasoning chain information and inability to effectively solve the problem of information redundancy between examples. They have obvious shortcomings when dealing with complex reasoning tasks, including the following aspects:
[0028] Ignoring the reasoning chain information: Most existing example selection methods mainly rely on the semantic similarity between the input question and the example for retrieval, while ignoring the multi-step reasoning chain that may be involved in the problem reasoning process. Multi-step reasoning problems usually contain multiple intermediate steps, and the logical dependencies of each step are crucial. However, existing technologies only select examples through simple semantic matching, resulting in the model being unable to obtain complete reasoning chain support. In particular, in complex problems that require logical reasoning, the effect of example selection is often unsatisfactory.
[0029] Redundant information problem in high-dimensional embedding space: Since large language models rely on high-dimensional embedding representations when performing reasoning, existing example selection methods often have difficulty effectively distinguishing the differences between examples when dealing with high-dimensional embedding spaces. There may be a large amount of redundant information in the embedding space, which will cause multiple examples to exhibit similar embedding values in the high-dimensional space, interfering with the example selection process and ultimately affecting the accuracy and efficiency of reasoning. In addition, as the dimension of the embedding space increases, the computational complexity also increases, which significantly reduces the efficiency of example selection.
[0030] Insufficient ability to deal with distribution shift: The distribution shift between training data and test data is a common problem in real-world scenarios. When the distribution of examples used by the model during training is inconsistent with the distribution of test data during inference, the example selection effect of existing methods is significantly reduced. This is because traditional similarity matching-based methods rely on selecting the closest examples under the same distribution, while ignoring the impact of distribution changes on example selection. This limitation is particularly evident in cross-domain tasks or dynamic environments, resulting in unstable performance of the model in practical applications.
[0031] Limitations of manually designed examples: Some existing technologies (such as manually designed Chain-of-Thought reasoning chains) rely on manually constructed examples, which is not only time-consuming and labor-intensive, but also difficult to adapt to actual complex and diverse tasks. Manually designed reasoning chains often fail to cover all possible types of problems and lack versatility. In addition, manually designed reasoning chains are usually based on predefined rules and are difficult to handle dynamic reasoning requirements in new problems or complex tasks.
[0032] In order to enable those skilled in the art to better understand the technical solutions in the embodiments of the present invention, the technical solutions in the embodiments of the present invention will be described clearly and in detail below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. All other embodiments obtained by ordinary technicians in the field based on the embodiments in the embodiments of the present invention should fall within the scope of protection of the embodiments of the present invention.
[0033] Figure 1 A flowchart of a context learning example selection method based on two queries and low-rank approximate rearrangement provided by an embodiment of the present invention is shown in FIG. Figure 1 As shown, this embodiment mainly includes the following steps:
[0034] S101. Obtain initial examples and input questions.
[0035] S102: querying a large language model based on the initial example and the input question to generate an initial thought chain.
[0036] For example, Figure 2 As shown, the large language model (LLM) is first queried to generate a chain of thoughts (CoT). In this scheme, the Complex-CoT method is used to obtain the initial n examples. When the Complex-CoT prompt is used to query the large language model, a CoT containing rich reasoning information can be generated.
[0037] Specifically, these initial n examples and question x i Together they are used to query the large language model and obtain the initial thought chain CoT y i , through question x i and the generated initial thought chain y i , use the trained encoder se to obtain i and i The test sample composed of i representation of , and representations of all examples in the training set.
[0038] S103: construct a training data set according to the input question and the initial thinking chain, and construct training samples using the training data set.
[0039] For example, the training data set is used to construct training samples, where each sample d i =(x i ,y i ), from the problem x i and its corresponding initial chain of thought (CoT)y i composition.
[0040] S104, training a retriever to retrieve a preset number of similar training samples from the training data set as candidate samples through the BM25 algorithm.
[0041] Exemplarily, contrastive learning is applied to train an encoder se, which acts as a retriever that can measure the similarity between thought chains and examples.
[0042] For each training sample d i , construct the corresponding positive and negative sample sets. Use BM25 to retrieve the first k similar training samples from the entire training set as candidate samples, denoted as D ′ =d ′ 1,d ′ 2,…,d ′ k .
[0043] S105: Calculate the similarity between the representation of the candidate sample and the representation of the input question, and perform a first rearrangement according to the similarity.
[0044] For example, after obtaining k samples, by calculating each example d j ′ With sample d i similarity, and reorder them, j = 1, 2, …, k.
[0045] S106, performing dimensionality reduction on the representations of the candidate samples after the first rearrangement, and performing a second rearrangement on the similarity of the representations after the dimensionality reduction.
[0046] S107. Based on the similarity scores of the examples after the second rearrangement, select examples to be spliced with the input question, and input the spliced examples into the large language model to obtain a target thought chain.
[0047] For example, based on the re-ranked similarity scores, the first n examples are selected as E ′ N , E ′ N With x i After splicing, they are input into the large language model to obtain the final target thinking chain for reasoning.
[0048] S108, analyzing and processing the target thinking chain to obtain a standard answer.
[0049] Exemplarily, the large language model is prompted with target thought chain examples, and its output is parsed to obtain the final standard answer.
[0050] In the context learning example selection method based on two queries and low-rank approximate rearrangement of the present invention, the reasoning chain information is generated by combining the two query mechanism, and the low-rank approximation technology is used to reduce the dimension and rearrange the examples, which overcomes the limitations of existing methods in complex reasoning tasks and effectively improves the accuracy and efficiency of example selection; the synergistic effect of these two parts significantly improves the reasoning performance of large language models in multi-step reasoning tasks, especially in scenarios dealing with distribution shift, showing stronger robustness and adaptability.
[0051] In another implementation of the present invention, the similarity is expressed as:
[0052] score(d j ′ )=P LM (y i |d j ′ ,x i ),j=1,2,…,k
[0053] Among them, d j ′ is an example in the candidate sample, j = 1, 2, ..., k; x i is the input question; y i For x i The corresponding chain of thought; P LM (y i |d j ′ ,x i ) means in example d j ′ and input problem x i In the case of i The higher the score, the higher the probability of j ′ Contains and thinking chain i The higher the probability of similar reasoning logic.
[0054] For example, according to these scores, D ′ Reorder the examples in and select the first t samples as positive samples, called pos i , the last t samples are used as difficult negative samples, called neg i , usually 2t≤k. During the training process, by i and neg i Randomly select a positive sample and a negative sample from to construct a training batch. For each d i , the positive and negative examples of other samples in the same batch are regarded as negative examples of this sample.
[0055] In another implementation of the present invention, the contrast loss function of the retriever is expressed as:
[0056]
[0057] Among them, sim is the training sample d i =(x i ,y i ) and the example d in the candidate sample j The similarity between them is the result of the inner product of the two sequence embedding vectors, expressed as:
[0058]
[0059] Among them, se is the retriever trained by the above loss function. After the training is completed, se is used as the sequence representation of the question and CoT, and the similarity is calculated by the vector inner product.
[0060] In another implementation of the present invention, the representation of the candidate samples after the first rearrangement is subjected to dimensionality reduction processing, and the similarity of the representation after dimensionality reduction is subjected to a second rearrangement, including: using principal component analysis to perform dimensionality reduction processing on the embedding of the examples in the candidate samples after the first rearrangement and the initial thinking chain in the training sample; and performing a second rearrangement based on the similarity of the representation after dimensionality reduction processing.
[0061] Exemplarily, based on the calculated similarity, select the first M examples E M Rearrange and obtain M examples E M They are retrieved based on semantic similarity and usually have similar CoT, which leads to the possibility of false associations or real logical associations between the test samples and the examples, making them difficult to distinguish.
[0062] To solve this problem, principal component analysis (PCA) is used to analyze the M examples and the target sample t i The embedding of ∈ is reduced to ∈. Then, each example e is recomputed using the reduced embedding j With t i The similarity between .
[0063] For mathematical reasoning tasks, the similarity is calculated by vector inner product; for common sense reasoning tasks, the Gaussian kernel function is used to calculate the similarity. The Gaussian kernel function expression is as follows:
[0064]
[0065] Among them, |se(t i )-se(e j )| means se(t i ) and se(ej ), σ is the standard deviation parameter of the Gaussian distribution.
[0066] It should be understood that the method of the present invention mainly consists of two parts, namely a two-query mechanism and a low-rank approximate rearrangement module.
[0067] The first part is to optimize the example selection process through two queries. The first query generates a chain of thought (CoT) for the input question from a large language model. The chain of thought is a series of intermediate reasoning steps that help the model better understand the logical structure of the question. The second query queries the example library based on the joint information of the chain of thought generated in the first query and the input question, so that the selected examples are not only related to the surface semantics of the input question, but also highly consistent with the reasoning steps of the question. This process significantly improves the accuracy of example selection by combining the information of the reasoning chain, ensuring that the selected examples can better assist complex reasoning tasks, and improving the reasoning accuracy and logical consistency of the model in complex reasoning tasks.
[0068] In the training and reasoning process, not only the surface semantic similarity of the problem is considered, but also the flexibility of the model in selecting examples is enhanced through the reasoning chain information. This enables the model to maintain good reasoning performance under different task distributions (including the case where the distribution of training data and test data is inconsistent), and significantly improves the model's adaptability in distribution shift scenarios.
[0069] Secondly, the reasoning chain is automatically generated through the two-query mechanism, which no longer relies on manually designed examples or reasoning steps. Compared with the traditional manual design of reasoning chains, the DQ-LoRe method has a higher level of automation and versatility, can adapt to different types of problems, reduces dependence on manual intervention, and improves the efficiency and accuracy of the example selection process.
[0070] The second part is to reduce the dimensionality of the examples obtained from the second query through low-rank approximation techniques (such as principal component analysis, PCA), filter out redundant information in the embedding space, optimize the distinction between examples, and better distinguish the actual relevance of different examples, avoiding the misselection of redundant examples due to high embedding similarity. After dimensionality reduction, the similarity between the input question and the example is recalculated, the examples are reordered, and the most relevant examples are selected. This module effectively improves the efficiency and accuracy of example selection by eliminating redundant information in high-dimensional embeddings, ensuring that the selected examples are not only semantically similar, but also closely integrated with the reasoning process of the input question.
[0071] The synergistic effect of these two parts enables the method proposed in the present invention to significantly improve the reasoning performance of large language models in multi-step reasoning tasks, especially in scenarios dealing with distribution shift, showing stronger robustness and adaptability.
[0072] In another implementation of the present invention, in order to verify the effectiveness and advancement of the proposed method, a large number of experiments were carried out on multiple widely used reasoning task datasets (such as GSM8K, AQUA, SVAMP, etc.), and compared with existing advanced example selection methods.
[0073] Experimental results show that the contextual learning example selection method based on two queries and low-rank approximate rearrangement proposed in the present invention performs well on all evaluation data sets and is significantly better than existing example selection methods. Especially in multi-step reasoning tasks, the present invention shows obvious advantages in indicators such as reasoning chain consistency and accuracy. In addition, under the condition of training and testing distribution shift, the present method can still maintain a high selection accuracy, proving its adaptability and robustness in distribution shift scenarios.
[0074] In addition, comparative experiments with different modules were conducted, such as those without and with the low-rank approximate rearrangement module. Without the low-rank approximate rearrangement module, the model's example selection accuracy dropped significantly, indicating that dimensionality reduction is essential for improving the accuracy of example selection and reducing redundant information. After the introduction of the dual query mechanism, the logical consistency of example selection was significantly enhanced, further demonstrating the important role of the invention's innovation in reasoning tasks.
[0075] In summary, the experimental results fully demonstrate the superiority and feasibility of the method of the present invention in reasoning tasks, and have significant performance improvements in various complex reasoning scenarios.
[0076] The method proposed in this paper is not limited to specific reasoning tasks. Its core idea is a general example selection framework that combines two queries with low-rank approximation technology. This method is applicable to various types of reasoning tasks and different data sets. It can be widely used in different reasoning scenarios by simply adjusting the query conditions and dimensionality reduction strategies. It has extremely high adaptability and scalability, and shows broad application prospects.
[0077] The present invention further provides an electronic device, which may include: a processor, a memory, a communication bus, and a communication interface.
[0078] in:
[0079] The processor, memory and communication interface communicate with each other through a communication bus.
[0080] Communication interface, used to communicate with other electronic devices or servers.
[0081] The processor is used to execute the program, and specifically can execute the steps of any one of the context learning example selection methods based on two queries and low-rank approximate rearrangement in the above-mentioned embodiments.
[0082] Specifically, the program may include program codes including computer operation instructions.
[0083] The processor may be a central processing unit (CPU), or an application specific integrated circuit (ASIC), or one or more integrated circuits configured to implement the embodiments of the present application. The one or more processors included in the smart device may be processors of the same type, such as one or more CPUs; or processors of different types, such as one or more CPUs and one or more ASICs.
[0084] The memory is used to store programs. The memory may include a high-speed RAM memory, and may also include a non-volatile memory, such as at least one disk memory.
[0085] The program can be specifically used to enable the processor to execute to implement the steps of any of the context learning example selection methods based on two queries and low-rank approximate rearrangement described in the embodiments. The specific implementation of each step in the program can refer to the corresponding descriptions in the steps and units executed by any of the context learning example selection methods based on two queries and low-rank approximate rearrangement in the above steps, which will not be repeated here. Those skilled in the art can clearly understand that for the convenience and conciseness of the description, the specific working process of the above-described devices and modules can refer to the corresponding process description in the aforementioned method embodiment.
[0086] The present invention also provides a non-transitory computer-readable storage medium storing computer instructions, wherein the computer instructions are used to enable a computer to execute the methods of the various embodiments of the present application.
[0087] The above-described method according to an embodiment of the present invention may be implemented in hardware, firmware, or as software or computer code that may be stored in a recording medium (such as a CD ROM, RAM, floppy disk, hard disk, or magneto-optical disk), or as computer code that is originally stored in a remote recording medium or a non-temporary machine-readable medium downloaded over a network and will be stored in a local recording medium, so that the method described herein may be stored in such software processing on a recording medium using a general-purpose computer, a dedicated processor, or programmable or dedicated hardware (such as an ASIC or FPGA). It is understood that a computer, processor, microprocessor controller, or programmable hardware includes a storage component (e.g., RAM, ROM, flash memory, etc.) that can store or receive software or computer code, and when the software or computer code is accessed and executed by a computer, processor, or hardware, the method described herein is implemented. In addition, when a general-purpose computer accesses the code for implementing the method shown herein, the execution of the code converts the general-purpose computer into a dedicated computer for executing the method shown herein.
[0088] Thus far, specific embodiments of the present invention have been described. Other embodiments are within the scope of the appended claims. In some cases, the actions recited in the claims may be performed in a different order and still achieve the desired results. Additionally, the processes depicted in the accompanying drawings do not necessarily require the specific order or sequential order shown to achieve the desired results. In some embodiments, multitasking and parallel processing may be advantageous.
[0089] It should be noted that all directional indications in the embodiments of the present invention (such as up, down, left, right, back, etc.) are only used to explain the relative position relationship, movement status, etc. between the components under a certain specific posture (as shown in the accompanying drawings). If the specific posture changes, the directional indication will also change accordingly.
[0090] In the description of the present invention, the terms "first" and "second" are only used to facilitate the description of different components or names, and cannot be understood as indicating or implying a sequential relationship, relative importance, or implicitly indicating the number of the indicated technical features. Therefore, the features defined as "first" and "second" may explicitly or implicitly include at least one of the features.
[0091] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as those commonly understood by those skilled in the art of the present invention. The terms used in the specification of the present invention herein are only for the purpose of describing specific embodiments and are not intended to limit the present invention.
[0092] It should be noted that although the specific embodiments of the present invention are described in detail in conjunction with the accompanying drawings, it should not be understood as limiting the scope of protection of the present invention. Within the scope described in the claims, various modifications and variations that can be made by those skilled in the art without creative work still belong to the scope of protection of the present invention.
[0093] The examples of the embodiments of the present invention are intended to concisely illustrate the technical features of the embodiments of the present invention so that those skilled in the art can intuitively understand the technical features of the embodiments of the present invention, and are not intended to be improper limitations of the embodiments of the present invention.
[0094] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. A context learning example selection method based on two queries and low-rank approximate rearrangement, characterized in that: include: Get initial examples and input questions; Querying the large language model based on the initial example and the input question to generate an initial thought chain; Constructing a training data set according to the input question and the initial thinking chain, and constructing training samples using the training data set; A training retriever is used to retrieve a preset number of similar training samples from the training data set as candidate samples by using a BM25 algorithm; Calculating the similarity between the representation of the candidate sample and the representation of the input question, and performing a first rearrangement according to the similarity; Performing dimensionality reduction processing on the representations of the candidate samples after the first rearrangement, and performing a second rearrangement on the similarity of the representations after the dimensionality reduction; Based on the similarity scores of the examples after the second rearrangement, select examples and splice them with the input question, and input the spliced examples into the large language model to obtain the target thought chain; Analyze the target thinking chain to obtain a standard answer.
2. The method according to claim 1, characterized in that: The similarity is expressed as: score(d j ′ )=P LM (y i |d j ′ ,x i ),j=1,2,…,k Among them, d j ′ is an example in the candidate sample, j = 1, 2, ..., k; x i is the input question; y i For x i The corresponding chain of thought; P LM (y i |d j ′ ,x i ) means in example d j ′ and input problem x i In the case of i probability; The higher the score, the better j ′ Contains and thinking chain i The higher the probability of similar reasoning logic.
3. The method according to claim 2, characterized in that The contrast loss function of the retriever is expressed as: Among them, sim is the training sample d i =(x i ,y i ) and the example d in the candidate sample j The similarity between them is expressed as: Among them, se is the retriever trained by the above loss function.
4. The method according to claim 1, characterized in that The performing dimensionality reduction processing on the representations of the candidate samples after the first rearrangement, and performing a second rearrangement on the similarity of the representations after the dimensionality reduction, comprises: Using principal component analysis, dimension reduction processing is performed on the embedding of the examples in the candidate samples after the first rearrangement and the initial thought chain in the training samples; A second rearrangement is performed based on the similarity of the representations after dimensionality reduction.
Citation Information
Patent Citations
Method for improving questions and answers of context learning knowledge base based on thinking chain and visualization
CN117076653A
Cited By
Context example selection method and system based on factorial hidden variable and common cause generation
CN121920353A