Large language model knowledge correction method based on adaptive comparative learning
Through the adaptive contrast learning method, the knowledge quadrants are divided and the comparison learning data is constructed, which solves the problem of the model refusing to reply when dealing with uncertain knowledge, significantly improves the honesty and credibility of the model, and alleviates the "illusion" phenomenon.
Patent Information
- Application Number
- CN202510020048.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-01-07
- Publication Date
- 2025-04-11
- Estimated Expiration
- 2045-01-07
AI Technical Summary
Existing fine-tuning methods are not sufficient to deal with problems that are originally known but uncertain, resulting in the fine-tuning model tending to reject replies when answering uncertain replies.
The large language model knowledge correction method based on adaptive contrast learning is adopted. By dividing knowledge quadrants, detecting knowledge boundaries, constructing comparative learning data and performing adaptive contrast learning, the model's ability to master knowledge and honesty is enhanced.
It significantly improves the authenticity indicator performance of model replies, improves the honesty and credibility of the model, and alleviates the "illusion" phenomenon of large language models when generating text.
Smart Images

Figure CN119808952A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to artificial intelligence natural language processing technology, and in particular to a large language model knowledge correction method based on adaptive contrastive learning. Background Art
[0002] In the field of natural language processing, large language models (LLMs) have learned rich language statistical features and semantic information through pre-training on massive text data, thus achieving breakthrough progress in a variety of downstream tasks such as machine translation, text generation, and question-answering systems. The success of these models is mainly due to their large parameter scale and efficient use of massive data. However, large language models may produce content that is inconsistent with the facts or the context logic when generating text. This phenomenon is called "hallucination", as shown in Table 1. The hallucination phenomenon not only affects user experience, but may also lead to serious consequences in key fields such as medicine and law. LLMs learn a lot of knowledge from human society and perform various tasks based on this knowledge. Among the mainstream technologies, supervised fine-tuning (SFT) aligns LLMs with real-world human knowledge and plays a key role in achieving human-desired tasks. After collecting a large amount of annotated corpus, researchers fine-tune the pre-trained language model so that it can learn from carefully selected and annotated human knowledge and apply it to unseen tasks. In the SFT process, model performance can be improved by expanding the scale of fine-tuning data and collecting complex data across multiple domains and tasks, but this may sacrifice the generality of the model by focusing on fine-tuning in a specific domain. In addition to different data, the instruction fine-tuning method designs a variety of instruction-response pairs, allowing the model to learn response patterns and content that are more in line with human instruction expectations, making LLM more realistic, credible, and useful.
[0003] Table 1 Examples of “hallucinations” produced by large language models
[0004]
[0005] One implementation scheme is to enhance honesty by mixing rejection responses into the fine-tuning data during the instruction fine-tuning stage. Hallucination phenomena usually involve logical fallacies (model reasoning errors), factual errors (the model confidently asserts facts that do not exist), and data-driven biases (certain data dominates and may cause the model output to be biased in certain directions). Other studies are also exploring the issue of model honesty, arguing that when the model can honestly answer "I don't know", the credibility of the model can be improved. For example, Cheng et al. identified the difference between the knowledge of instruction fine-tuning data and the knowledge stored in the model by repeated sampling and setting thresholds during the instruction fine-tuning stage, allowing it to reject responses to questions outside the knowledge stored in the model, and divided the data into four quadrants, and proposed a new honesty evaluation indicator based on the position of the question in the quadrant.
[0006] However, the existing technology has the following areas to be improved: the current fine-tuning method does not adequately handle some questions that were originally known but uncertain for the model when using SFT fine-tuning, resulting in the fine-tuned model tending to reply with a rejection response when answering these uncertain responses.
[0007] It should be noted that the information disclosed in the above background technology section is only used for understanding the background of the present application, and therefore may include information that does not constitute prior art known to ordinary technicians in the field. Summary of the invention
[0008] The main purpose of the present invention is to overcome the defects existing in the above-mentioned background technology and provide a large language model knowledge correction method based on adaptive contrastive learning.
[0009] To achieve the above object, the present invention adopts the following technical solutions:
[0010] A large language model knowledge correction method based on adaptive contrastive learning, comprising the following steps:
[0011] S1. Knowledge quadrant division: The knowledge of the large language model is divided into four quadrants, including what the model knows it knows, what the model does not know it knows, what the model knows it does not know, and what the model does not know it does not know, in order to identify the model's mastery of knowledge;
[0012] S2. Knowledge boundary detection: Based on the knowledge quadrant division, the knowledge boundary of the model is detected by setting an upper threshold for identifying that the model has high confidence in its knowledge and a lower threshold for identifying that the model lacks confidence in its knowledge, so as to determine the confidence measure of the model for each question and thus identify the knowledge boundary of the model;
[0013] S3, Contrastive learning data construction: According to the detected knowledge boundary, collect the knowledge data known and unknown to the model, and construct the contrastive learning data, including positive samples and negative samples;
[0014] S4. Adaptive contrastive learning: Based on contrastive learning data construction, an adaptive contrastive learning strategy is used for model learning. The adaptive contrastive learning strategy enhances the model's ability to grasp knowledge by bringing positive samples closer and pushing negative samples further away, while maintaining the model's generation ability.
[0015] Furthermore, step S2 specifically includes:
[0016] Filter questions from different question-answering datasets;
[0017] For each question, sample the response of the large language model multiple times;
[0018] Calculate the accuracy of each question response as a measure of the model's confidence in each question;
[0019] Set the upper and lower thresholds as hyperparameters;
[0020] When the model's confidence measure for a problem exceeds the upper threshold, the model is considered to have fully mastered the knowledge, which is defined as the model knowing what it knows;
[0021] When the model's confidence measure for a problem is between the upper and lower thresholds, it is defined as the model not knowing what it knows;
[0022] When the model's confidence measure for a problem is lower than the lower threshold, the model is considered to lack this knowledge, which is defined as the model does not know the knowledge it does not know;
[0023] The knowledge boundary of the model is defined through the evaluation of the above thresholds and confidence measures.
[0024] Furthermore, step S3 specifically includes:
[0025] According to the knowledge boundary determined in step S2, the questions are divided into two categories: known and unknown, corresponding to the knowledge that the model knows it knows and the knowledge that the model does not know;
[0026] For the knowledge that the model knows, i.e. the first quadrant, questions with accuracy higher than the upper threshold IK are selected, where the correct answers of the model are designed as positive samples;
[0027] Two types of negative samples are constructed for the positive samples in the first quadrant: one is the model answer "I don't know", which is used to push forward in contrastive learning to enhance the confidence of the model; the other is the wrong answer generated by the large language model, which is used to help the model forget the wrong knowledge;
[0028] For knowledge that the model does not know, i.e., the third and fourth quadrants, we select questions whose accuracy is lower than the upper threshold, where negative samples are incorrect answers generated by the large language model;
[0029] For the knowledge that the model does not know it knows, that is, the second quadrant, we select questions whose accuracy is higher than the lower threshold but lower than the upper threshold, and set the questions with correct answers as positive samples to enhance the model's grasp of uncertain knowledge;
[0030] For the knowledge that the model does not know that it does not know, that is, the fourth quadrant, we select questions with accuracy rates below the lower threshold, design corresponding questions and answers of "I don't know" as positive samples, so as to encourage the model to admit "I don't know" when faced with knowledge that it does not know;
[0031] Different comparison data are constructed for different quadrants. The comparison data for each quadrant includes input questions and answers, and covers anchor points, positive samples, and negative samples.
[0032] Furthermore, in step S4, the adaptive contrast learning strategy specifically includes:
[0033] Obtain instruction pairs for constructing positive and negative samples from the three knowledge quadrants: the model knows what it knows (quadrant 1), the model does not know what it knows (quadrant 2), and the model knows what it does not know (quadrant 3);
[0034] Fine-tune the adaptive contrast instructions to enhance the model's ability to grasp knowledge by bringing positive samples closer and pushing negative samples further away;
[0035] Through different data usage strategies, positive and negative samples in different quadrants are adaptively calculated.
[0036] Furthermore, in step S4, the adaptive contrast learning strategy further includes:
[0037] The contrast loss function is used to calculate the contrast loss between positive samples and negative samples, so that the model can learn to shorten the distance with positive samples in the feature space and increase the distance with negative samples to enhance the recognition ability of correct knowledge.
[0038] Calculate the cross entropy loss between the model output and the expected answer to maintain the language generation ability of the large language model;
[0039] Combining the contrast loss and the cross entropy loss to form an overall learning objective function;
[0040] By optimizing the overall learning objective function, the large language model is fine-tuned to achieve knowledge correction.
[0041] Furthermore, the contrast loss function uses cosine similarity to measure the similarity between the model output and the positive sample, and encourages the model output to maximize the similarity with the positive sample while minimizing the similarity with the negative sample in the form of negative log-likelihood; the value of the contrast loss function is determined by the cosine similarity of the positive sample and the negative sample, where the similarity of the positive sample is improved and the similarity of the negative sample is reduced, thereby making the model more inclined to the correct answer during the training process.
[0042] Furthermore, the contrast loss function introduces a temperature hyperparameter to adjust the sensitivity of similarity, and the temperature hyperparameter is used to control the scaling of the exponential function in the contrast loss function, thereby affecting the relative importance of the distance between positive and negative samples.
[0043] A computer-readable storage medium stores a computer program, which, when executed by a processor, implements the large language model knowledge correction method based on adaptive contrastive learning.
[0044] A computer program product includes a computer program, and when the computer program is executed by a processor, the large language model knowledge correction method based on adaptive contrastive learning is implemented.
[0045] The present invention has the following beneficial effects:
[0046] The present invention proposes an innovative knowledge correction method for a large language model based on adaptive contrastive learning. The method can more accurately identify and process the performance of the model in different knowledge states by carefully dividing the knowledge quadrants. The method of the present invention can not only retain the knowledge known by the model, but also consolidate the knowledge that the model is uncertain or unconfident about, and through the contrastive learning strategy, the model learns to properly express "I don't know" when facing unknown knowledge. Through the newly added division threshold, the present invention can correct the knowledge of the model in a more fine-grained manner, thereby improving the honesty and credibility of the model. In the process of supervised fine-tuning, the adaptive contrastive learning strategy of the present invention enhances the model's ability to recognize correct knowledge by pulling positive samples closer and pushing negative samples farther away, while maintaining the model's language generation ability. Experimental results show that by adopting this fine-tuning method based on adaptive contrastive learning, the performance of the model in the reply authenticity index is significantly improved, surpassing various existing methods. The present invention has great practical application value and significance for alleviating the "hallucination" phenomenon that may occur in large language models when generating texts, especially in key fields such as medicine and law.
[0047] Other beneficial effects of the embodiments of the present invention will be further described below. BRIEF DESCRIPTION OF THE DRAWINGS
[0048] Figure 1This is an overall flow chart of a large language model knowledge correction method based on adaptive contrastive learning according to an embodiment of the present invention.
[0049] Figure 2 This is a schematic diagram of the implementation principle of the large language model knowledge correction method based on adaptive contrastive learning in an embodiment of the present invention.
[0050] Figure 3 This is an example of a repeated sampling boundary according to an embodiment of the present invention.
[0051] Figure 4 An example of comparing learning data according to an embodiment of the present invention is shown. DETAILED DESCRIPTION
[0052] The following is a detailed description of the embodiments of the present invention. It should be emphasized that the following description is only exemplary and is not intended to limit the scope and application of the present invention.
[0053] In addition, the terms "first" and "second" are used for descriptive purposes only and should not be understood as indicating or implying relative importance or implicitly indicating the number of technical features indicated. Thus, a feature defined as "first" or "second" may explicitly or implicitly include one or more of the features. In the description of the embodiments of the present invention, the meaning of "plurality" is two or more, unless otherwise clearly and specifically defined.
[0054] The current fine-tuning method does not adequately handle some questions that the model originally knew but is uncertain when using SFT fine-tuning, resulting in the fine-tuned model tending to reply with a rejection response when answering these uncertain responses. We conjecture that there is some knowledge that the model is uncertain about, so based on the conjecture, we set a new threshold to divide the knowledge into what the model knows it knows, what the model does not know it knows, and what the model does not know it does not know. In each quadrant, we use a corresponding contrastive learning strategy to enable the model to retain known knowledge, consolidate uncertain knowledge, and forget unknown knowledge.
[0055] The present invention proposes a large language model knowledge correction method based on adaptive contrastive learning, which mainly involves two key points: first, a new division threshold is added to divide out part of the knowledge that is known but uncertain by the model, so as to correct the knowledge of the model in a more fine-grained manner; second, an adaptive contrastive learning method is proposed to enhance the supervised fine-tuning process of the large language model, so that the model retains known knowledge, consolidates uncertain knowledge, and forgets unknown knowledge. Through the threshold division method, the model knowledge is divided into what the model knows it knows, what the model does not know it knows, and what the model does not know it does not know. The method based on adaptive contrastive learning is used to enhance the honesty fine-tuning stage of the large language model.
[0056] See also Figure 1The embodiment of the present invention provides a large language model knowledge correction method based on adaptive contrastive learning, comprising the following steps:
[0057] Step S1, knowledge quadrant division: divide the knowledge of the large language model LLM into four quadrants, including what the model knows it knows, what the model does not know it knows, what the model knows it does not know, and what the model does not know it does not know, so as to identify the model's mastery of knowledge.
[0058] Step S2, knowledge boundary detection: Based on the knowledge quadrant division, the knowledge boundary of the model is detected by setting an upper threshold for identifying that the model has high confidence in its knowledge and a lower threshold for identifying that the model lacks confidence in its knowledge, so as to determine the confidence measure of the model for each question, thereby identifying the knowledge boundary of the model.
[0059] In a preferred embodiment, step S2 specifically includes: screening questions from different question-answering data sets; for each question, sampling the responses of the large language model multiple times; calculating the accuracy of the response to each question as a confidence measure of the model for each question; setting two thresholds: an upper threshold (IK, I know rate) and a lower threshold (IDK, I don't know rate) as hyperparameters; when the model's confidence measure for the question exceeds the upper threshold IK, it is considered that the model fully masters the knowledge, corresponding to the model knowing what it knows; when the model's confidence measure for the question is between IK and IDK, it is considered that the model has the knowledge but may not be fully aware of it, which may lead to occasional wrong answers, corresponding to the model not knowing what it knows; when the model's confidence measure for the question is lower than the lower threshold IDK, it is considered that the model lacks the knowledge, resulting in a low correct answer rate, corresponding to the model not knowing what it does not know; through the evaluation of the above thresholds and confidence measures, the knowledge boundary of the model is defined, including the knowledge that the model knows what it knows, the knowledge that the model does not know what it knows, and the knowledge that the model does not know what it does not know.
[0060] Step S3, comparative learning data construction: According to the detected knowledge boundary, collect the knowledge data known and unknown to the model, and construct comparative learning data, including positive samples and negative samples, to enhance the model's grasp of knowledge.
[0061] In a preferred embodiment, step S3 specifically includes: according to the knowledge boundary determined in step S2, the questions are divided into two categories: known and unknown, corresponding to the knowledge that the model knows and the knowledge that the model does not know; for the knowledge that the model knows (the first quadrant), the questions with an accuracy rate higher than the upper threshold IK are selected, where the correct answer of the model is designed as a positive sample; two types of negative samples are constructed for the positive samples in the first quadrant: one is the answer "I don't know" by the large language model, which is used to push forward in contrastive learning to enhance the confidence of the model; the other is the wrong answer generated by the large language model, which is used to help the model forget the wrong knowledge; for the knowledge that the model does not know (the third and fourth quadrants), the questions with an accuracy rate lower than the upper threshold IK are selected. , where negative samples are incorrect answers generated by the large language model; for the knowledge that the model does not know it knows (the second quadrant), select questions with an accuracy higher than the lower threshold IDK but lower than the upper threshold IK, and set the questions with correct answers as positive samples to enhance the model's grasp of uncertain knowledge; for the knowledge that the model does not know it does not know (the fourth quadrant), select questions with an accuracy lower than the lower threshold IDK, design corresponding questions and answers of "I don't know" as positive samples to encourage the model to admit "I don't know" when faced with knowledge it does not have; construct different comparison data for different quadrants, where x represents the input question and y represents the answer, including anchor points, positive samples and negative samples, and the difference is mainly reflected in the choice of y. Through the construction of the above comparison data, a data basis is provided for the following adaptive contrastive learning strategy, so that the adaptive contrast loss can be calculated and the model can be optimized in the subsequent steps.
[0062] Step S4, adaptive contrastive learning: Based on contrastive learning data construction, adaptive contrastive learning strategy is used for learning. The adaptive contrastive learning strategy enhances the model's ability to grasp knowledge by bringing positive samples closer and pushing negative samples further away, while maintaining the generation capability of a large language model.
[0063] In a preferred embodiment, the adaptive contrast learning strategy specifically includes: obtaining instruction pairs for constructing positive and negative samples from three knowledge quadrants: what the model knows it knows (first quadrant), what the model does not know it knows (second quadrant), and what the model knows it does not know (third quadrant); fine-tuning the adaptive contrast instructions to enhance the model's ability to master knowledge by bringing positive samples closer and pushing negative samples further away; adaptively calculating positive and negative samples in different quadrants through different data usage strategies; enabling the model to think about different knowledge more specifically, enhancing the model's ability to retain known knowledge, consolidate uncertain knowledge, and forget unknown knowledge.
[0064] In a preferred embodiment, the adaptive contrastive learning strategy further includes: using a contrastive loss function to calculate the contrastive loss between positive samples and negative samples, so that the model learning in the feature space is closer to the positive sample, while pushing the distance away from the negative sample, so as to enhance the recognition ability of correct knowledge; calculating the cross entropy loss between the model output and the expected answer to maintain the language generation ability of the large language model; combining the contrastive loss and the cross entropy loss to form an overall learning objective function; by optimizing the overall learning objective function, fine-tuning the large language model to achieve refined management and correction of knowledge. Preferably, the contrastive loss function uses cosine similarity to measure the similarity between the model output and the positive sample, and encourages the model output to maximize the similarity with the positive sample and minimize the similarity with the negative sample in the form of negative log-likelihood; the value of the contrastive loss function is determined by the cosine similarity of the positive sample and the negative sample, where the similarity of the positive sample is improved and the similarity of the negative sample is reduced, in this way, the model is more inclined to the correct answer during the training process. Furthermore, the contrast loss function introduces a temperature hyperparameter to adjust the sensitivity of similarity, and the temperature hyperparameter is used to control the scaling of the exponential function in the contrast loss function, thereby affecting the relative importance of the distance between positive and negative samples.
[0065] Experiments have shown that the method of the present invention can significantly improve the authenticity index performance of the model response, which is of great significance for alleviating the hallucination problem of large language models.
[0066] The specific principles, algorithm examples and experimental verification of the embodiments of the present invention are further described below.
[0067] In order to obtain a more honest and trustworthy large language model (LLM) assistant, LLM should have two capabilities: not only should it be able to refuse to answer when faced with unknown questions, but also should have the ability to correctly distinguish whether it really understands the knowledge related to the question, which means that the model needs to be aware of what it knows and what it doesn't know. The knowledge perception ability of LLM can be represented by the knowledge quadrant. The knowledge quadrant is divided into four quadrants: knowing what you know, knowing what you don't know, not knowing what you know, and not knowing what you don't know. The vertical axis represents the model's perception of itself (that is, what the model thinks it knows or doesn't know), and the horizontal axis represents the model's actual knowledge mastery (that is, whether the model really masters a specific knowledge). Therefore, if Figure 2As shown, the knowledge in the first quadrant "knowing what you know" means that AI knows what it knows, while the knowledge in the fourth quadrant "not knowing what you know" means that AI does not know what it knows, and the other quadrants can be inferred similarly. Ideally, LLM gives the correct answer to the question, which belongs to "knowing what you know"; when LLM faces an illusion problem, it does not realize that it does not know the relevant knowledge and gives a wrong answer, which belongs to the "not knowing what you do not know" quadrant. The horizontal axis represents the specific knowledge mastery of LLM, which is limited by the LLM's own training process and knowledge capabilities. In order to alleviate the illusion problem and meet the needs of the honest LLM system, the present invention pays more attention to the vertical "knowing what you know / unknown" ability. The present invention believes that providing correct answers to known questions and refusing to respond to unknown questions are both acceptable behaviors of honest LLM. Therefore, the goal of the present invention in alleviating the LLM illusion problem is to move more input instructions and answers from the lower two quadrants to the upper two quadrants.
[0068] Detection of the knowledge boundary of the model:
[0069] Different question-answering datasets contain various types of knowledge and expressions, which makes it challenging to evaluate whether a model actually possesses specific knowledge, as the confidence levels of the models vary. In order to allow the model to better identify its knowledge boundaries and judge its ability to answer relevant questions, the present invention sets two thresholds: an upper threshold (IK, I know rate) and a lower threshold (IDK, I don't know rate). This corresponds to three types of knowledge: the model knows what it knows (knows what it knows), the model does not know what it knows (does not know what it knows / uncertain knowledge), and the model does not know what it does not know (does not know what it does not know).
[0070] Questions are selected from the dataset and LLM is sampled multiple times to sample responses and the accuracy is calculated as a measure of the model's confidence in each question. The number of sampled responses and the thresholds IK and IDK are used as hyperparameters. Figure 3 As shown in Figure 1, when confidence exceeds IK, the model is considered to have fully mastered the knowledge. If confidence is between IK and IDK, the model has the knowledge but may not be aware of it, resulting in occasional incorrect answers. Confidence below IDK indicates a lack of knowledge, resulting in a low correct answer rate.
[0071] By defining these knowledge boundaries, contrastive learning data will be constructed and the model will be adaptively adjusted based on these knowledge types. This process is designed to help the model retain known knowledge, strengthen uncertain knowledge, and forget unknown knowledge. In subsequent steps, more knowledge is transferred from the third and fourth quadrants to the first and second quadrants through adaptive contrastive learning instruction tuning, thereby improving the honesty of the model while ensuring that it provides helpful answers.
[0072] Contrastive learning data construction:
[0073] Based on the divided knowledge boundaries, the model’s known and unknown knowledge data are collected, corresponding to the right and left quadrants of knowledge, respectively. Next, comparative learning data is constructed for this knowledge, such as Figure 4 shown.
[0074] Known issues with the model:
[0075] In Section , questions with accuracy higher than the upper threshold IK belong to the first quadrant of knowledge where "the model knows what it knows". For a given question, the correct answer of the model is designed as a positive sample. There are two types of negative samples: one is the model's answer "I don't know", which can be pushed further in the instruction tuning of contrastive learning to enhance the model's confidence and avoid the situation where the model knows but thinks it doesn't know. The other negative sample is the wrong answer generated by LLM) to help LLM forget wrong knowledge during training. It is worth noting that the selection of samples is related to the specific parameters of the threshold. When the upper threshold IK is selected as 1.0, it means that only questions that the model answers correctly in all sampled instances will be considered known questions. In this case, there will be no corresponding wrong answer negative samples in the construction of negative samples, because questions with wrong answers have been classified as questions that the model does not know.
[0076] Problems unknown to the model:
[0077] Questions with a correct rate lower than the upper threshold IK, including "the model doesn't know it knows" and "the model doesn't know it doesn't know", fall into the bottom two quadrants of the knowledge quadrant and are therefore considered "the model doesn't know". The negative samples of these two types of questions are incorrect answers generated by LLM. In the construction of positive samples, for questions with an accuracy rate higher than the lower threshold IDK, the present invention believes that the model actually has the relevant knowledge, but is not sure whether it knows it, which belongs to the knowledge that "the model doesn't know it knows". Questions with correct answers are set as positive samples, hoping to enhance the model's grasp of uncertain knowledge by introducing this knowledge. For questions with a correct rate lower than the lower threshold IDK, the present invention believes that the model does not have the relevant knowledge, which belongs to the knowledge that "the model doesn't know it doesn't know". The present invention designs the corresponding questions and the answers of "I don't know" as positive samples. By narrowing the distance of this positive sample, the model can be better encouraged to admit "I don't know" when faced with knowledge that it does not have, thereby enhancing the honesty and credibility of LLM answers.
[0078] In order to calculate the adaptive contrast loss, different contrast data need to be constructed for different quadrants. Specifically, the present invention constructs different instruction data I = (x, y), where x is the input question and y is the answer. In the contrast setting, in addition to the anchor point I, there is also a positive sample I + And negative sample I- The difference mainly focuses on the choice of y, which will be explained in detail in the subsequent sections.
[0079] Adaptive Contrastive Learning:
[0080] In the "Contrastive Learning Data Construction Section", instruction pairs for constructing positive and negative examples of known and unknown knowledge of the model are obtained from the three quadrants, and then adaptive contrast instruction fine-tuning is performed. Compared with the traditional SFT, the contrast instruction fine-tuning method can better enhance the model's ability to master knowledge by bringing positive instances closer and pushing negative instances further away. In the adaptive contrast learning strategy, for the positive and negative instances corresponding to knowledge in different quadrants, the present invention designs different data usage strategies, which can adaptively calculate positive and negative samples in different quadrants. In this way, the model can think about different knowledge more specifically, and better enhance the model's ability to retain known knowledge, consolidate uncertain knowledge, and forget unknown knowledge.
[0081] For the knowledge that is known and confirmed by the model (such as Figure 4 Quadrant-1) shown, with comparative data I IKIK , and The i-th sample in a training batch consists of the original input (Its i is the standard answer), positive example (Its i is the correct answer before LLM) and negative instances (Its i is "I don't know" or a wrong answer before LLM). Zoom in and move the negative instance In order to calculate the contrast loss, the present invention designs a contrast loss function, as shown in the formula:
[0082]
[0083] in is the cosine similarity and τ is the temperature hyperparameter.
[0084] In order to maintain the generation ability of LLM, a standard cross entropy loss is designed for each instruction pair according to the SFT training method, as shown in the formula:
[0085]
[0086] Where l is the length of the expected output of the input, Yes i The kth tag of yes Previous mark.
[0087] By combining the above two loss functions, the overall learning objective function is obtained, as shown in Formula 4.20:
[0088]
[0089] Here, detach means that the loss value is separated from the computational graph and is therefore treated only as a scalar, and λ is the upper limit of the weight.
[0090] Experiments have shown that the present invention uses a fine-tuning method based on adaptive contrastive learning in the instruction fine-tuning stage. The model can retain known knowledge, consolidate uncertain knowledge, and forget unknown knowledge. The model after this fine-tuning method significantly improves the performance of the authenticity index of the reply and surpasses various existing methods. The proposal of the present invention is of great significance for improving the honesty of large language models and alleviating the hallucination problem of large language models.
[0091] An embodiment of the present invention further provides a storage medium for storing a computer program, which at least performs the above method when executed.
[0092] An embodiment of the present invention further provides a control device, comprising a processor and a storage medium for storing a computer program; wherein the processor is configured to execute at least the method described above when executing the computer program.
[0093] An embodiment of the present invention further provides a processor, wherein the processor executes a computer program and at least executes the method described above.
[0094] The storage medium can be implemented by any type of non-volatile storage device, or a combination thereof. Among them, the non-volatile memory can be a read-only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), an electrically erasable programmable read-only memory (EEPROM), a magnetic random access memory (FRAM), a flash memory, a magnetic surface memory, an optical disc, or a compact disc read-only memory (CD-ROM); the magnetic surface memory can be a disk memory or a tape memory. The storage medium described in the embodiments of the present invention is intended to include, but is not limited to, these and any other suitable types of memory.
[0095] In the several embodiments provided by the present invention, it should be understood that the disclosed systems and methods can be implemented in other ways. The device embodiments described above are only schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation, such as: multiple units or components can be combined, or can be integrated into another system, or some features can be ignored or not executed. In addition, the coupling, direct coupling, or communication connection between the components shown or discussed can be through some interfaces, and the indirect coupling or communication connection of the devices or units can be electrical, mechanical or other forms.
[0096] The units described above as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units; some or all of the units may be selected according to actual needs to achieve the purpose of the present embodiment.
[0097] In addition, all functional units in the embodiments of the present invention may be integrated into one processing unit, or each unit may be separately used as a unit, or two or more units may be integrated into one unit; the above-mentioned integrated units may be implemented in the form of hardware or in the form of hardware plus software functional units.
[0098] Those skilled in the art can understand that: all or part of the steps of implementing the above method embodiments can be completed by hardware related to program instructions, and the aforementioned program can be stored in a computer-readable storage medium. When the program is executed, it executes the steps of the above method embodiments; and the aforementioned storage medium includes: mobile storage devices, read-only memories (ROM, Read-Only Memory), random access memories (RAM, Random Access Memory), disks or optical disks, etc. Various media that can store program codes.
[0099] Alternatively, if the above-mentioned integrated unit of the present invention is implemented in the form of a software function module and sold or used as an independent product, it can also be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the embodiment of the present invention can be essentially or partly reflected in the form of a software product that contributes to the prior art. The computer software product is stored in a storage medium and includes several instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to execute all or part of the methods described in each embodiment of the present invention. The aforementioned storage medium includes: various media that can store program codes, such as mobile storage devices, ROM, RAM, magnetic disks or optical disks.
[0100] The methods disclosed in the several method embodiments provided by the present invention can be arbitrarily combined without conflict to obtain new method embodiments.
[0101] The features disclosed in several product embodiments provided by the present invention can be arbitrarily combined without conflict to obtain new product embodiments.
[0102] The features disclosed in several method or device embodiments provided by the present invention can be arbitrarily combined without conflict to obtain new method embodiments or device embodiments.
[0103] The above contents are further detailed descriptions of the present invention in combination with specific preferred embodiments, and it cannot be determined that the specific implementation of the present invention is limited to these descriptions. For those skilled in the art of the present invention, several equivalent substitutions or obvious variations can be made without departing from the concept of the present invention, and the performance or use is the same, which should be regarded as belonging to the protection scope of the present invention.
Claims
1. A large language model knowledge correction method based on adaptive contrastive learning, characterized in that: The following steps are involved: S1. Knowledge quadrant division: The knowledge of the large language model is divided into four quadrants, including what the model knows it knows, what the model does not know it knows, what the model knows it does not know, and what the model does not know it does not know, in order to identify the model's mastery of knowledge; S2. Knowledge boundary detection: Based on the knowledge quadrant division, the knowledge boundary of the model is detected by setting an upper threshold for identifying that the model has high confidence in its knowledge and a lower threshold for identifying that the model lacks confidence in its knowledge, so as to determine the confidence measure of the model for each question and thus identify the knowledge boundary of the model; S3, Contrastive learning data construction: According to the detected knowledge boundary, collect the knowledge data known and unknown to the model, and construct the contrastive learning data, including positive samples and negative samples; S4. Adaptive contrastive learning: Based on contrastive learning data construction, an adaptive contrastive learning strategy is used for model learning. The adaptive contrastive learning strategy enhances the model's ability to grasp knowledge by bringing positive samples closer and pushing negative samples further away, while maintaining the model's generation ability.
2. The large language model knowledge correction method based on adaptive contrastive learning as claimed in claim 1, characterized in that: Step S2 specifically includes: Filter questions from different question-answering datasets; For each question, sample the response of the large language model multiple times; Calculate the accuracy of each question response as a measure of the model's confidence in each question; Set the upper and lower thresholds as hyperparameters; When the model's confidence measure for a problem exceeds the upper threshold, the model is considered to have fully mastered the knowledge, which is defined as the model knowing what it knows; When the model's confidence measure for a problem is between the upper and lower thresholds, it is defined as the model not knowing what it knows; When the model's confidence measure for a problem is lower than the lower threshold, the model is considered to lack this knowledge, which is defined as the model does not know the knowledge it does not know; The knowledge boundary of the model is defined through the evaluation of the above thresholds and confidence measures.
3. The large language model knowledge correction method based on adaptive contrastive learning as claimed in claim 1 or 2, characterized in that: Step S3 specifically includes: According to the knowledge boundary determined in step S2, the questions are divided into two categories: known and unknown, corresponding to the knowledge that the model knows it knows and the knowledge that the model does not know; For the knowledge that the model knows, i.e. the first quadrant, questions with accuracy higher than the upper threshold IK are selected, where the correct answers of the model are designed as positive samples; Two types of negative samples are constructed for the positive samples in the first quadrant: one is the model answer "I don't know", which is used to push forward in contrastive learning to enhance the confidence of the model; the other is the wrong answer generated by the large language model, which is used to help the model forget the wrong knowledge; For knowledge that the model does not know, i.e., the third and fourth quadrants, we select questions whose accuracy is lower than the upper threshold, where negative samples are incorrect answers generated by the large language model; For the knowledge that the model does not know it knows, that is, the second quadrant, we select questions whose accuracy is higher than the lower threshold but lower than the upper threshold, and set the questions with correct answers as positive samples to enhance the model's grasp of uncertain knowledge; For the knowledge that the model does not know that it does not know, that is, the fourth quadrant, we select questions with accuracy rates below the lower threshold, design corresponding questions and answers of "I don't know" as positive samples, so as to encourage the model to admit "I don't know" when faced with knowledge that it does not know; Different comparison data are constructed for different quadrants. The comparison data for each quadrant includes input questions and answers, and covers anchor points, positive samples, and negative samples.
4. The large language model knowledge correction method based on adaptive contrastive learning as claimed in claim 1 or 2, characterized in that: In step S4, the adaptive contrast learning strategy specifically includes: Obtain instruction pairs for constructing positive and negative samples from the three knowledge quadrants: the model knows what it knows (quadrant 1), the model does not know what it knows (quadrant 2), and the model knows what it does not know (quadrant 3); Fine-tune the adaptive contrast instructions to enhance the model's ability to grasp knowledge by bringing positive samples closer and pushing negative samples further away; Through different data usage strategies, positive and negative samples in different quadrants are adaptively calculated.
5. The large language model knowledge correction method based on adaptive contrastive learning according to any one of claims 1 to 4, characterized in that: In step S4, the adaptive contrast learning strategy further includes: The contrast loss function is used to calculate the contrast loss between positive samples and negative samples, so that the model can learn to shorten the distance with positive samples in the feature space and increase the distance with negative samples to enhance the recognition ability of correct knowledge. Calculate the cross entropy loss between the model output and the expected answer to maintain the language generation ability of the large language model; Combining the contrast loss and the cross entropy loss to form an overall learning objective function; By optimizing the overall learning objective function, the large language model is fine-tuned to achieve knowledge correction.
6. The large language model knowledge correction method based on adaptive contrastive learning as claimed in claim 5, characterized in that: The contrast loss function uses cosine similarity to measure the similarity between the model output and the positive sample, and encourages the model output to maximize the similarity with the positive sample and minimize the similarity with the negative sample in the form of negative log likelihood; the value of the contrast loss function is determined by the cosine similarity of the positive sample and the negative sample, where the similarity of the positive sample is improved and the similarity of the negative sample is reduced, thereby making the model more inclined to the correct answer during the training process.
7. The large language model knowledge correction method based on adaptive contrastive learning as claimed in claim 6, characterized in that: The contrast loss function introduces a temperature hyperparameter to adjust the sensitivity of similarity. The temperature hyperparameter is used to control the scaling of the exponential function in the contrast loss function, thereby affecting the relative importance of the distance between positive and negative samples.
8. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the large language model knowledge correction method based on adaptive contrastive learning as described in any one of claims 1 to 7 is implemented.
9. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the large language model knowledge correction method based on adaptive contrastive learning as described in any one of claims 1 to 7 is implemented.
Citation Information
Patent Citations
Self-comparison large language model intensive training method and device, medium and equipment
CN118132724A
Industrial large model-oriented fine tuning data generation method, computer program and terminal
CN119004100A
Knowledge fusion method and device based on knowledge graph and large language model
CN119227785A
Cited By
Consistency learning-oriented sample enhancement and optimization method
CN120929892A
A sample enhancement and optimization method for consistency learning
CN120929892B