A text watermark-guided dynamic large language model forgetting method and system
By using a text watermark-guided dynamic forgetting method, which extracts knowledge entity watermarks from an auxiliary large language model and dynamically trims the training set, the problem of insufficient or excessive forgetting in large language model forgetting is solved, and an efficient and controllable forgetting process is achieved.
Patent Information
- Application Number
- CN202611295675.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-08-25
- Publication Date
- 2026-11-17
AI Technical Summary
Existing forgetting methods for large language models are insufficient in terms of accuracy and controllability. They cannot achieve precise location and dynamic control of target knowledge, resulting in insufficient or excessive forgetting, and are also computationally inefficient.
We employ a text watermark-guided dynamic forgetting method. By constructing an auxiliary large language model to extract knowledge entity watermarks, we quantify the model's memory of the target knowledge in real time and dynamically prune the training set based on the watermark strength, thereby achieving precise and controllable forgetting of the target knowledge.
It achieves accurate forgetting of target knowledge, improves forgetting efficiency, reduces waste of computing resources, maintains the model's versatility, and adapts to various forgetting algorithms, possessing good versatility and scalability.
Smart Images

Figure CN123116328A_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of artificial intelligence security and model privacy protection technology, specifically involving a dynamic large language model forgetting method and system based on text watermarking, which is used to achieve controllable dynamic forgetting of sensitive or specific information in the field of large language model forgetting. Background Technology
[0002] With the widespread application of large language models in natural language processing, dialogue systems, and content generation, the scale of their training data has grown exponentially, currently reaching trillions of tokens. While this massive training corpus endows models with powerful capabilities, it also inevitably introduces numerous security risks: training data often contains personally identifiable information (such as names, addresses, and contact information), sensitive information, private content, or copyrighted material. To address these privacy challenges, data protection legislation worldwide is becoming increasingly stringent, not only requiring the deletion of structured data in traditional database systems but also extending compliance boundaries to the field of artificial intelligence models. Therefore, the forgetting behavior of large language models has become a core research topic in the field of artificial intelligence security and privacy protection, possessing both theoretical value and practical urgency.
[0003] In addition to compliance with laws and regulations, forgetting techniques for large language models also have multiple practical application needs: On the one hand, during model iteration and updates, developers may need to selectively remove the impact of bad samples on model behavior due to defects in training data quality (such as labeling errors, data pollution, bias injection, etc.); on the other hand, copyright holders increasingly assert that their works should not be used for unauthorized model training, and model providers urgently need a technical means to respond to copyright revocation requests. These diverse practical needs place higher demands on forgetting methods: not only must the forgetting operation effectively remove target knowledge while maintaining the overall performance of the model, but the forgetting process must also be controllable, quantifiable, verifiable, and possess good computational efficiency and scalability to adapt to industrial-grade deployment scenarios of large models with hundreds of billions of parameters.
[0004] The ideal goal of forgetting is to make the model behave consistently with a model retrained on a dataset after removing the forgotten data. This means the model should exhibit no performance loss on the retained set after forgetting, and its performance on the forgotten set should be identical to a model that has never seen the data. However, for large language models, the computational cost and time overhead of complete retraining are unacceptable due to the massive amount of training data and the hundreds of billions of parameters. To address this, researchers have proposed various approximate forgetting algorithms, including gradient ascent, gradient difference, direct preference optimization, and negative preference optimization. While existing forgetting methods can remove a model's memory of specific information to some extent, current research still faces two major challenges: insufficient forgetting accuracy and a lack of control over the forgetting process.
[0005] Regarding forgetting accuracy, most existing methods treat the sample to be forgotten as a whole, lacking fine-grained analysis of semantic structure, making it difficult to accurately locate the knowledge that needs to be removed. Specifically, a complete question-and-answer sample usually contains multiple semantic components such as question description, answer body, background information, and auxiliary explanations. Only some fragments (such as specific entities, key facts, or core relational phrases) are the target knowledge that truly needs to be forgotten, while the rest are legitimate information that is irrelevant to forgetting but beneficial to the model's general capabilities. However, when performing gradient updates, existing forgetting methods apply the loss signal of the entire sample to the model parameters indiscriminately. This coarse-grained forgetting strategy causes the parameter update direction to be interfered with by a large amount of irrelevant semantic information, making it impossible to achieve accurate erasure of the target knowledge. This coarse-grained processing method usually leads to two adverse consequences: (1) Insufficient forgetting: The target knowledge is not completely removed, and the model can still output sensitive information under specific induced prompts, failing to meet compliance requirements; (2) Over-forgetting: The forgetting algorithm iterates excessively, not only removing the target knowledge but also removing a large amount of benign knowledge that is irrelevant to the forgetting target, damaging the model's general capabilities. The root cause of the above dilemma is that existing methods lack a fine-grained quantitative monitoring signal that can indicate in real time "which knowledge has been removed and which knowledge still needs to be forgotten". This causes the forgetting process to oscillate between insufficient forgetting and excessive forgetting, and it can never converge to the ideal forgetting equilibrium point.
[0006] Existing methods lack dynamic control mechanisms, relying on fixed optimization schedules and applying a uniform treatment to all forgotten samples. This coarse-grained paradigm is both blind and inefficient. Specifically, static training on a fixed training set leads to the following problems: during iterative optimization, the forgetting progress of different samples exhibits significant heterogeneity; some samples are quickly forgotten early in training, while others require more rounds of optimization. However, static training strategies cannot perceive this difference, and forgotten samples continue to participate in training in subsequent iterations, not only wasting computational resources but, more seriously, potentially triggering "forgetting oscillations," where forgotten knowledge is reactivated in subsequent training, leading to a decrease in model utility. Furthermore, traditional evaluation metrics (such as similarity and perplexity) struggle to capture the continuous dynamic process of forgetting, have weak correlation with the actual knowledge removal process, and cannot provide effective real-time supervision signals for the forgetting process.
[0007] Therefore, there is a need for a forgetting method that can provide real-time quantitative monitoring signals for the forgetting process and dynamically adjust the training process based on the monitoring results, in order to overcome the shortcomings of existing technologies. Summary of the Invention
[0008] Purpose of the Invention: The purpose of this invention is to address the shortcomings of existing technologies and provide a dynamic large language model forgetting method and system based on text watermarking. By providing real-time quantitative monitoring signals through knowledge entity watermarking, and performing dynamic pruning on the training set accordingly, the invention achieves accurate and controllable forgetting of target knowledge within a closed-loop control framework. This not only ensures that target knowledge is fully removed but also effectively mitigates the damage to the model's general capabilities caused by excessive forgetting, while simultaneously improving forgetting efficiency and computational resource utilization.
[0009] Technical solution: The present invention provides a forgetting method for dynamic large language models based on text watermarking, comprising the following steps:
[0010] Step 1: Knowledge watermark extraction. Obtain a set of samples to be forgotten, where each sample contains a question q and its corresponding answer a. Construct an auxiliary large language model and guide it to extract a set of knowledge entity watermarks from answer a using a preset prompt template. The set of knowledge entity watermarks consists of a set of elements that appear consecutively in answer a, do not appear in question q, and constitute a complete semantic unit. Each watermark wᵢ is a semantic unit extracted from answer a that can represent the core knowledge content of the sample, and i is the total number. Existing forgetting methods treat the entire question-and-answer sample as a coarse-grained forgetting unit, lacking fine-grained analysis of the semantic structure within the answer. This paper proposes to use knowledge entity watermarks as the smallest semantic unit for forgetting evaluation, breaking through the traditional evaluation paradigm of whole-segment text similarity matching.
[0011] Step 2: Quantifying Memory Knowledge. The question q from the set of samples to be forgotten is input into the current large language model to be evaluated (the target large language model is different from the auxiliary large language model used to extract watermarks in Step 1; it is the large language model undergoing forgetting training), generating the model answer â. The occurrence of each watermark in the knowledge entity watermark set W in the model answer â is statistically analyzed. Using the character length of each watermark as a weight, the proportion of the total watermark weight to the total character length of the generated answer is calculated as the watermark strength WS. The watermark strength WS is used to quantify the degree to which the large language model retains the target knowledge. Existing technologies lack quantitative indicators that can reflect the degree of knowledge retention in real time. Traditional methods for quantifying memory knowledge (such as perplexity and text similarity) have weak correlation with the knowledge removal process and are difficult to use as real-time monitoring signals for the forgetting process. Here, watermark strength is used for the first time as a quantitative monitoring signal for forgetting progress, solving the technical problem of the unmeasurable degree of forgetting.
[0012] Step 3: Dynamic data pruning. The forgetting status of each sample to be forgotten is determined based on the watermark strength (WS). Samples with a watermark strength (WS) of zero are identified as forgotten samples and permanently removed from the current forgetting set. The selected forgetting algorithm, which can be any one of gradient ascent, gradient difference, direct preference optimization, or negative preference optimization, is then executed on the updated forgetting set to iteratively update the parameters of the large language model until the current forgetting set is empty or the preset maximum number of iterations is reached. Existing forgetting methods all use static training set configurations, where all samples participate in gradient updates indiscriminately throughout the training process, leading to low efficiency. This invention introduces a dynamic pruning mechanism at the outer layer of existing forgetting algorithms, using the quantization feedback signal from Step 2 as the decision-making basis. This achieves real-time adaptive adjustment of the training set, allowing computational resources to gradually focus on samples that have not yet been forgotten.
[0013] To automate and standardize the extraction of highly specific and semantically relevant knowledge entity watermarks from original question-and-answer samples to be forgotten, this method abandons traditional global coarse-grained sample processing and provides accurate and practical fine-grained evaluation criteria for subsequent model memory quantification and forgetting state assessment. Step 1 relies on an independently deployed auxiliary large language model and customized prompting project, combined with a multi-layered filtering and verification mechanism, to achieve accurate screening and standardized output of knowledge watermarks. The entire process is automated, requiring no manual intervention, and is adaptable to various large model forgetting datasets. The specific process is as follows:
[0014] Step 1.1: System initialization and auxiliary model construction, i.e., obtaining the set of samples to be forgotten. Each sample contains a question and their corresponding answers This forms the data base for subsequent forgetting tasks; it also helps in building an auxiliary large language model. This model is used to automatically extract watermarks from knowledge entities. Unlike the target large language model to be forgotten, this model only undertakes the tasks of knowledge semantic parsing and watermark candidate unit identification, and does not participate in subsequent model parameter updates and forgetting iteration training.
[0015] Step 1.2: Construct an extraction prompt template, that is, design a natural language prompt template based on the three constraints of knowledge entity watermarking. The constraints include: (1) the candidate watermark must be in the answer (1) The watermark must appear continuously in the form of a continuous character sequence to ensure the integrity of the extracted text segment; (2) The candidate watermark must appear in the question The watermark should not appear in the text to ensure that the extracted content is unique to the target knowledge and not background information already present in the question; (3) the candidate watermark should constitute a complete semantic unit with independent semantics (such as entity name, key phrase, etc.) and exclude fragmented words without actual semantic carrying capacity. The prompt template Problems with the current sample and answer After splicing together the data to form a complete watermark extraction instruction, it is input into the auxiliary large language model. Guide them to answer based on their deep semantic understanding ability The system analyzes the answer text to identify and extract all core knowledge units that simultaneously satisfy the triple constraints, and outputs the candidate watermark set directly in a structured format.
[0016] Step 1.3: Multi-level post-processing filtering of candidate watermarks, which involves performing a three-level cascaded filtering operation on the candidate watermark set output by the auxiliary large language model: The first level is format cleansing and null value filtering, which removes empty strings and invalid characters (such as invisible control characters, abnormal punctuation, etc.) to ensure that each candidate watermark is a valid segment with actual text content; the second level is issue overlap removal, which checks whether each candidate watermark exists as a substring within the issue. The text will contain the problem. The first level precisely removes any fragment from the watermark, ensuring its specificity and target knowledge orientation from the source. The second level is semantic deduplication and unique merging, which involves deduplicating the candidate watermarks retained after the first two levels of filtering based on precise string matching, so that each independent knowledge entity watermark appears only once in the final set, eliminating redundancy.
[0017] After processing through steps 1.1 to 1.3, the final set of knowledge entity watermarks is obtained. ,in The total number of watermarks, each watermark All are from the answers The atomic semantic units extracted from the sample that can uniquely represent the core knowledge content of the sample are used to extract the final output set of samples to be forgotten, which includes watermarked structured annotations. This modified watermark dataset provides a fine-grained evaluation target for subsequent memory quantization.
[0018] Step 2 uses knowledge entity watermarking as the evaluation benchmark. By quantitatively calculating the watermark residue ratio, it provides real-time and accurate feedback on the degree of memory retention of the target privacy knowledge by the large language model, realizing dynamic perception of the forgetting process. This provides a closed-loop decision basis for subsequent dynamic pruning and iterative optimization of the training set, solving the technical pain points of traditional forgetting processes being unquantifiable and uncontrollable. The specific process is as follows:
[0019] Step 2.1: Target model inference generates the answer. At each evaluation node of the iterative forgetting process, the system pauses the model parameter update process and enters the model inference evaluation phase. It calls the large language model to be evaluated at the current iteration step. Iterate through all the samples to be forgotten in the current training set and identify the problems associated with each sample. Input the model, execute the forward inference process, and generate the model's predicted answer under the current parameter state. The predicted answer will be used as the analysis object for subsequent memory retention detection;
[0020] Step 2.2: Quantitative calculation of watermark strength, i.e., statistical analysis of the knowledge entity watermark set extracted in Step 1. The watermarks in the model answer The degree of occurrence and coverage ratio in the model are used to accurately calculate the degree of memory retention of target knowledge for a single sample, employing a length-weighted matching strength calculation formula:
[0021] ;
[0022] in, As an indicator function, when the watermark word exist The value is 1 when the corresponding knowledge is completely present, indicating that the model still retains the memory of the corresponding knowledge and has not been forgotten; otherwise, it is 0. The length of the watermark word in characters; The total character length of the generated answer; this metric satisfies A larger value indicates a stronger memory of the target knowledge by the model. This indicates that the answers generated by the model no longer contain any knowledge watermarks;
[0023] Step 2.3: Determine the sample-level forgetting state, i.e., based on the watermark strength of each sample calculated in Step 2.2. Establish a system to determine the forgetting state of each sample to be forgotten. The judgment rule is as follows:
[0024] ;
[0025] Meanwhile, to achieve overall monitoring of the global forgetting process, the average watermark intensity of all samples to be forgotten is calculated at each evaluation interval. ,in This represents the total number of samples that still need to be trained in the current iteration phase, used to obtain an overall view of the forgetting process; AWS can intuitively reflect the overall forgetting progress, accurately characterize the overall forgetting effect of the model on batch target knowledge, and make up for the deficiency that single-sample evaluation cannot reflect the global state.
[0026] Finally, the forgetting state and average watermark intensity of each sample are output to the dynamic forgetting control module, providing a basis for decision-making for dynamic adjustment of the training set.
[0027] To completely break away from the traditional static iterative training mode with fixed datasets, step 3 dynamically trims and updates the forgotten training set by real-time sensing of the heterogeneity of sample forgetting. This alleviates problems such as insufficient computing power, inadequate forgetting, and excessive forgetting, achieving efficient, controllable, and accurate forgetting of the target knowledge to be forgotten in the large language model, while preserving the model's general knowledge capabilities to the greatest extent. The specific process is as follows:
[0028] Step 3.1, Dynamic Forgotten Set Pruning, that is, based on the sample forgetting state obtained from the previous quantitative evaluation, to achieve adaptive dynamic updating of the forgetting training set; let the first step be... The forgetting dataset at the time of step is The current model parameters are First, the knowledge memory quantification module in step 2 is used to obtain the information of each sample in the current model. The following is a real-time forgetting state:
[0029] ;
[0030] in Indicates that the current parameter is The model; This is an indicator function that returns 1 if the watermark strength is greater than 0 (not forgotten), and 0 otherwise (forgotten). Based on this determination, the watermark strength is set to zero (i.e.,...). Samples identified as forgotten are permanently removed from the current training set and will not be used in subsequent training to avoid knowledge recurrence and forgetting oscillations caused by repeated training of forgotten knowledge; only the state is retained. The unforgotten, stubborn samples form the effective training set for the next iteration. The updated training set rules are as follows:
[0031] ;
[0032] This dynamic pruning operation reduces the size of the training set in real time, allowing the system's computing resources to gradually focus on the stubborn sample subset that has not yet been forgotten, thus greatly improving the efficiency of forgetting iteration.
[0033] Step 3.2: Execute the forgetting algorithm to update the parameters, that is, in the dynamically pruned forgetting dataset. The selected forgetting algorithm will continue to be used. Update parameters by optimizing the objective function. This method weakens the target model's memory of specific knowledge. It is highly versatile, compatible with various mainstream large-scale model forgetting algorithms, and can be flexibly adapted to different model structures and forgetting scenarios. A unified parameter iterative update formula is used to complete weight optimization.
[0034] ;
[0035] in, The learning rate is used to control the magnitude of parameter updates, avoiding excessively large step sizes that could cause model breakdown or excessively small step sizes that could lead to slow convergence. The target loss function defined for the selected forgetting algorithm; The gradient represents the model parameters; the forgetting algorithm A is a pluggable design, compatible with various mainstream forgetting optimization strategies, including but not limited to gradient ascent algorithm, gradient difference algorithm, direct preference optimization algorithm, and negative preference optimization algorithm. The system selects one of the algorithms to instantiate this step according to the specific application scenario;
[0036] Step 3.3, Termination Condition Judgment: During evaluation at each interval, the system automatically checks the global forgetting progress and performs a dual termination condition joint determination: the first termination condition is whether the current training set is empty (…). If the value is empty, it indicates that the target knowledge of all samples to be forgotten has been completely erased; the second termination condition is whether the current iteration step has reached the preset maximum iteration step. This serves as a safety measure to prevent training from failing to converge in extreme situations;
[0037] If any termination condition is met, the iterative training stops immediately, and the target large language model after forgetting is output. If the termination condition is not met, it is determined that there is still unforgotten target knowledge, and the system automatically returns to step 3.1 to start a new sample state evaluation, training set pruning and parameter iteration process until the controllable forgetting of all target knowledge is completed.
[0038] If the gradient ascent algorithm is used in step 3, then the loss function is:
[0039] ;
[0040] By maximizing the negative logarithm of the generation probability of the sample to be forgotten, the model's prediction loss on the target knowledge is increased, thereby weakening the model's memory of the target knowledge.
[0041] If the gradient difference algorithm is used, the loss function is:
[0042] ;
[0043] in To model the loss for the standard language on the retained set, This is the balance coefficient;
[0044] If the direct preference optimization algorithm is used, the loss function is:
[0045] ;
[0046] in For answers to be forgotten For reference only. For reference model parameters, It is the sigmoid function;
[0047] If the negative preference optimization algorithm is used, the loss function is:
[0048] ;
[0049] in For reference model parameters, For temperature coefficient, It is the sigmoid function;
[0050] The forgetting algorithm optimizes the corresponding objective function. To update the model parameters.
[0051] This invention also discloses a dynamic large language model forgetting system guided by text watermarking, including a knowledge watermark extraction module, a knowledge memory quantification module, and a dynamic forgetting control module. The knowledge watermark extraction module is deployed at the data preprocessing end, used to receive a set of samples to be forgotten, and guides the large language model to extract knowledge entity watermarks from the answers of the samples to be forgotten through a preset prompt template, forming a set of samples to be forgotten containing watermark annotations. The knowledge memory quantification module is deployed at the model inference end, used to input the questions of each sample to be forgotten in the current training set into the current large language model for inference during iterative forgetting, generate corresponding model answers, calculate the watermark strength of each sample's knowledge entity watermark in the model answer, determine the forgetting state of each sample, and feed the quantification results back to the dynamic forgetting control module. The dynamic forgetting control module is deployed at the model training end, used to remove forgotten samples with zero watermark strength from the current training set in real time according to the forgetting state of each sample fed back by the knowledge memory quantification module, dynamically update the training set, execute a selected forgetting algorithm on the updated training set, iteratively update the parameters of the large language model until the termination condition is met, and return the large language model after forgetting is complete.
[0052] Beneficial effects: Compared with the prior art, the present invention has the following advantages:
[0053] (1) This invention achieves precise control of the forgetting process through real-time quantitative monitoring signals provided by knowledge entity watermarking. Traditional methods lack clear and quantifiable termination criteria, leading to insufficient or excessive forgetting. This invention uses zero watermark strength as a precise criterion for completion of forgetting, effectively avoiding the above problems. Experiments show that this invention can robustly remove target knowledge while maintaining the model's generality.
[0054] (2) Through a dynamic pruning mechanism, forgotten samples are removed in real time during training, allowing optimized computational resources to focus on stubborn samples that have not yet been forgotten. This mechanism automatically reduces the size of the training set as iterations progress, continuously decreasing gradient computation overhead and showing an overall decreasing computational burden, making it particularly suitable for large-scale models and scenarios with massive amounts of forgotten samples. Experiments show that, compared with traditional static training methods, this invention significantly reduces the number of training steps required to achieve complete forgetting, while also significantly reducing model utility loss and improving forgetting efficiency.
[0055] (3) As a plug-and-play framework, this invention can be deployed in large language model forgetting systems, is compatible with various mainstream forgetting algorithms, and has good versatility and scalability. Only the dynamic control logic of this invention needs to be added to the outer layer of the original forgetting algorithm's training loop; dynamic forgetting capability can be obtained without modifying the algorithm's internal implementation, greatly reducing the cost of technology migration and engineering adaptation. Experiments have verified the effectiveness of this invention on four different forgetting algorithms.
[0056] (4) This invention innovatively introduces knowledge entity watermarking as a fine-grained forgetting assessment benchmark, breaking through the traditional paradigm of coarse-grained similarity matching of the entire answer. Compared with assessment methods based on overall text similarity or perplexity, knowledge entity watermarking can accurately locate the core semantic units (such as proper nouns, key relational phrases, etc.) that truly represent the target knowledge in the answer, effectively eliminating the interference of background information and general expressions unrelated to the forgotten target in the answer on the assessment results, and significantly improving the accuracy and reliability of forgetting monitoring.
[0057] (5) This invention constructs a closed-loop feedback control architecture of "watermark extraction → memory quantization → dynamic pruning → parameter update → requantization". Traditional forgetting methods adopt an open-loop training mode, and the forgetting process lacks a real-time feedback and adjustment mechanism, and the parameter update direction cannot be adaptively corrected according to the current forgetting progress. This invention upgrades the forgetting process from "unidirectional execution" to a closed-loop regulation of "perception-decision-execution-reperception" through closed-loop control, fundamentally transforming the forgetting problem of large language models into an observable, quantifiable, and controllable dynamic system optimization problem, significantly improving the controllability of the forgetting process. Attached Figure Description
[0058] Figure 1 This is a system architecture diagram of the present invention;
[0059] Figure 2 This is an overall flowchart of the present invention;
[0060] Figure 3 This is a schematic diagram of the knowledge watermark extraction prompt template of the present invention;
[0061] Figure 4 This is a schematic diagram illustrating the dynamic distribution of the forgotten state of the samples in the embodiment;
[0062] Figure 5 is a schematic diagram illustrating the influence of the auxiliary model's sensitivity in the embodiment;
[0063] In Figure 5, (a) is a schematic diagram comparing the consistency of knowledge entity watermarks extracted by different auxiliary large language models on the TOFU dataset, and (b) is a schematic diagram comparing the forgetting performance of different auxiliary large language models after extracting knowledge entity watermarks on the TOFU dataset. Detailed Implementation
[0064] The technical solution of the present invention will be described in detail below, but the scope of protection of the present invention is not limited to the embodiments described.
[0065] like Figure 1 and Figure 2 As shown, this invention mainly includes three modules: a knowledge watermark extraction module, a knowledge memory quantification module, and a dynamic forgetting control module. First, the knowledge watermark extraction module utilizes an auxiliary large language model and specially designed prompt templates (such as...) Figure 3 As shown in the diagram, the system precisely extracts knowledge entity watermarks from the answers of the original samples to be forgotten, which can serve as fine-grained evaluation benchmarks, thus constructing a forgotten sample set with watermark labels. Subsequently, in the knowledge memory quantification module, during the iterative forgetting process, the inference phase inputs the sample questions that have not yet been forgotten into the model to be trained. By calculating the watermark strength contained in the generated answers, the system quantifies the degree of memory retention of the target knowledge of each sample in real time, and determines the forgetting state of each sample based on whether the watermark strength is zero. Finally, in the dynamic forgetting control module, the system dynamically and permanently removes samples that have been determined to be completely forgotten from the current training set based on the real-time feedback of the forgetting state of each sample, retaining only the samples that have not yet been forgotten for subsequent gradient calculation and parameter updates. The three modules form a closed-loop feedback mechanism. The knowledge memory quantification module feeds back the forgetting state to the dynamic forgetting control module at each evaluation interval. The dynamic forgetting control module adjusts the training set accordingly and continues to execute the forgetting algorithm, achieving precise and controllable forgetting process.
[0066] The forgetting method for the above dynamic large speech model is as follows:
[0067] Step 1: Knowledge watermark extraction. Obtain the set of samples to be forgotten, with each sample containing a question q and its corresponding answer a. Construct an auxiliary large language model, and guide the auxiliary large language model to extract the set of knowledge entity watermarks from the answer a using a preset prompt template. The set of knowledge entity watermarks is the set of elements that appear consecutively in answer a, do not appear in question q, and constitute complete semantic units.
[0068] Step 2: Quantify the knowledge to be remembered. Input the question q from the set of samples to be forgotten into the large language model to be evaluated. Generate the model answer â. Statistically analyze the occurrence of each watermark in the knowledge entity watermark set W in the model answer â. Calculate the proportion of the total watermark weight to the total character length of the generated answer, using the character length of each watermark as the weight. This proportion is used as the watermark strength WS. The watermark strength WS is used to quantify the degree to which the large language model retains the target knowledge.
[0069] Step 3: Dynamic data pruning. Based on the watermark strength WS, determine the forgetting state of each sample to be forgotten. The sample with a watermark strength WS of zero is identified as a forgotten sample and permanently removed from the current forgetting set. Continue to execute the selected forgetting algorithm on the updated forgetting set, iteratively updating the parameters of the large language model until the current forgetting set is empty or the preset maximum number of iterations is reached.
[0070] To verify the feasibility and technical effectiveness of this invention, the technical solution of this invention is applied to the following specific scenario. In this embodiment, the proposed adaptive large language model forgetting system based on text watermark guidance is constructed using the PyTorch 2.4.1 deep learning algorithm library and the Sklearn machine learning algorithm library, and deployed on a cloud server equipped with 140G of memory and an NVIDIA H200 GPU.
[0071] In this embodiment, the TOFU and MUSE standard large language model forgetting benchmark datasets were processed during the data processing stage. Llama-2-7B-Chat, MUSE-Books-target, and Phi-1_5 were selected as the base models, with the Llama-2-7B-Chat model also serving as an auxiliary model for knowledge watermark extraction.
[0072] Forgetting performance evaluation experiment: Four mainstream forgetting algorithms were used as baselines to evaluate the effectiveness of the proposed method: gradient ascent (GA), gradient difference (GD), direct preference optimization (DPO), and negative preference optimization (NPO). The forgetting effect of the static forgetting strategy was compared with that of the proposed method.
[0073] Table 1 shows the forgetting performance of Llama-2-7B-Chat on the TOFUforget10 subset. Each forgetting method is presented with two baselines: the first row corresponds to the early stopping point of forgetting (corresponding to insufficient forgetting); the second row corresponds to the results after static forgetting for the same number of training steps, at which point most baseline models suffer severe over-forgetting (model utility drops to 0). For fair comparison, the method of this invention is only compared with the second baseline in the later training stage. Experimental results show that all four baseline algorithms suffer severe model collapse (MU drops to 0) after sufficient training, while embedding the framework of this invention achieves better forgetting performance while maintaining model utility. Taking GD as an example, GD+the forgetting quality of this invention reaches 2.54E-60, and the model utility is 0.2487, while the original GD's model utility drops to zero after 75 steps.
[0074] Table 1. Forgetting performance of Llama-2-7B-Chat on the TOFUforget10 subset.
[0075]
[0076] Table 2 shows the forgetting performance of MUSE-Books-target on the MUSEBooks subset. Taking GA as an example, experimental results show that in long text forgetting scenarios, the original GA suffers severe model collapse in later training, with KM-R dropping to 0. In contrast, the KM-R and VM-R of GA + the present invention drop to 0.0520 and 0.0455 respectively, while the KM-R remains at 0.1909, significantly outperforming its static counterpart. Other forgetting algorithms + the present invention also achieve a good trade-off between forgetting and retention, verifying the universality and effectiveness of the present invention in long text forgetting tasks.
[0077] Table 2. Forgetting performance of MUSE-Books-target on the MUSEBooks subset.
[0078]
[0079] Experiments analyzing the dynamic process of forgetting: such as Figure 4As shown, this invention runs GA+ on the Phi-1_5 model, counting the number of unforgotten samples at each training step. Experimental results show that the forgetting process exhibits significant heterogeneity: within the first 3 training steps, approximately 61.25% of the samples are rapidly forgotten (watermark strength drops to zero); the remaining 38.75% of the samples constitute a subset of "stubborn memories," where the forgetting rate slows significantly, and finally, all samples are completely forgotten by step 27. These results reveal the fundamental flaw of static training strategies: if forgotten samples continue to participate in subsequent training, it not only wastes computational resources, but more importantly, their gradient direction may conflict with the optimization direction of stubborn samples, leading to the reactivation of forgotten knowledge and causing repeated fluctuations in model utility. The dynamic pruning mechanism of this invention quickly removes forgotten samples in the early stages, achieving real-time reallocation of computational resources; in the later stages, it focuses on optimizing stubborn samples, fundamentally avoiding the forgetting oscillation problem.
[0080] Ablation experiment:
[0081] 1. Analysis of watermark extraction strategies:
[0082] Table 3 compares the impact of three watermark extraction strategies on forgetting performance: (1) random strategy: randomly select words as watermarks; (2) term frequency-inverse document frequency strategy: select the word with the highest term frequency-inverse document frequency as watermark; (3) the strategy of this invention: semantically extracted words guided by Llama-2-7B-Chat prompts as watermarks. The GA algorithm was run under the same conditions, and the number of stopping steps, forgetting quality and model utility under different strategies were compared.
[0083] Table 3. Results of ablation experiments using watermark extraction strategies.
[0084]
[0085] Ablation experiments show that the randomized strategy selects a large number of meaningless words, deviating from the true target to be forgotten, resulting in poor forgetting quality. The statistical weights of the TF-IDF strategy are detached from the semantic context and cannot effectively distinguish the private entities to be forgotten in the problem, leading to a significant decrease in model utility. In contrast, the semantic extraction strategy based on a large language model in this invention performs best under all settings, achieving zero watermark strength in the fewest steps while maintaining the best model utility.
[0086] 2. Sensitivity analysis of auxiliary models:
[0087] Figure 5 illustrates the impact of auxiliary large language model selection on the performance of the method of this invention. This embodiment uses four different auxiliary large language models for watermark extraction: Llama-3.2-1B-Instruct, Qwen2.5-3B-Instruct, GPT-4, and Llama-2-7B-Chat. The consistency between the watermark sets extracted by different models is measured by Jaccard similarity and overlap coefficient. Experimental results show that the Jaccard similarity is between 0.41 and 0.61, and after excluding the smallest model, the overlap coefficient exceeds 0.72, with GPT-4 and Qwen2.5-3B-Instruct reaching 0.89.
[0088] Further verification through forgetting experiments showed that all four auxiliary models could drive the average watermark intensity to zero, with similar convergence steps, and little difference in forgetting quality and model utility. Given the API cost of GPT-4, this invention uses Llama-2-7B-Chat as the default auxiliary model.
[0089] 3. Verification of the effectiveness of the dynamic pruning mechanism:
[0090] Table 4 verifies the advantages of the dynamic pruning mechanism over static full-set forgetting training. In the static setting, the same parameter configuration as the method of this invention is used, forcing the model to complete the training process on the complete forgotten set, but without removing samples. Experimental results show that the static method requires significantly more steps than the method of this invention and suffers a significant loss of utility on the retained set. The fundamental reason lies in the "forgetting oscillation" phenomenon in static training, that is, forgotten samples are reactivated in subsequent training. This invention solves this problem through dynamic pruning, achieving complete forgetting while better maintaining the model's generality.
[0091] Table 4. Results of ablation experiments using the dynamic trimming mechanism.
[0092]
[0093] This invention effectively addresses the technical challenges of quantifying forgetting levels and the tendency for insufficient or excessive forgetting during static training in large language model forgetting tasks by introducing knowledge entity watermarking as a real-time quantitative monitoring signal for the forgetting process, combined with a dynamic training set pruning mechanism. Unlike traditional static forgetting methods that passively accept training set configurations and are prone to forgetting oscillations, this invention utilizes knowledge entity watermarking to construct a real-time forgetting monitoring mechanism, precisely controlling the training process through dynamic pruning of forgotten samples. In terms of system architecture, this invention adopts a three-layer modular architecture of knowledge watermark extraction, memory quantization, and dynamic forgetting control, coupled with a closed-loop feedback mechanism, effectively overcoming the challenges of static training and improving forgetting efficiency. Experiments on the TOFU and MUSE standard forgetting benchmarks demonstrate that this invention is applicable to various mainstream forgetting algorithms, achieving better forgetting with fewer training steps. It outperforms static forgetting schemes in both structured question answering and long text forgetting scenarios, maintaining the model's generality while removing target knowledge.
[0094] In summary, the forgetting task of large language models presents a dual requirement for controllability and efficiency in the forgetting process. This invention provides a forgetting scheme that can effectively quantify the degree of forgetting and combine it with a dynamic pruning mechanism to regulate the training process, thereby achieving highly reliable forgetting while maintaining the model's generality while removing target knowledge.
Claims
1. A forgetting method for dynamic large language models based on text watermarking, characterized in that, Includes the following steps: Step 1: Knowledge watermark extraction. Obtain the set of samples to be forgotten, with each sample containing a question q and its corresponding answer a. Construct an auxiliary large language model, and guide the auxiliary large language model to extract the set of knowledge entity watermarks from the answer a using a preset prompt template. The set of knowledge entity watermarks is the set of elements that appear consecutively in answer a, do not appear in question q, and constitute complete semantic units. Step 2: Quantify the knowledge to be remembered. Input the question q from the set of samples to be forgotten into the large language model to be evaluated. Generate the model answer â. Statistically analyze the occurrence of each watermark in the knowledge entity watermark set W in the model answer â. Calculate the proportion of the total watermark weight to the total character length of the generated answer, using the character length of each watermark as the weight. This proportion is used as the watermark strength WS. The watermark strength WS is used to quantify the degree to which the large language model retains the target knowledge. Step 3: Dynamic data pruning. Based on the watermark strength WS, determine the forgetting state of each sample to be forgotten. The sample with a watermark strength WS of zero is identified as a forgotten sample and permanently removed from the current forgetting set. Continue to execute the selected forgetting algorithm on the updated forgetting set, iteratively updating the parameters of the large language model until the current forgetting set is empty or the preset maximum number of iterations is reached.
2. The forgetting method for dynamic large language models based on text watermarking as described in claim 1, characterized in that, The detailed method for step 1 is as follows: Step 1.1: Obtain the set of samples to be forgotten. Each sample contains a question and their corresponding answers This forms the data base for subsequent forgetting tasks; it also helps in building an auxiliary large language model. It is used to perform automatic extraction of knowledge entity watermarks; Step 1.2: Construct an extraction prompt template, that is, design a natural language prompt template based on the three constraints of knowledge entity watermarking. The constraints include: (1) Candidate watermarks must be in the answer (2) The candidate watermark must appear continuously in the question. (3) The candidate watermark must constitute a complete semantic unit with independent semantics; prompt template Problems with the current sample and answer After splicing together the data to form a complete watermark extraction instruction, it is input into the auxiliary large language model. Guide them to answer based on their deep semantic understanding ability The system analyzes and extracts all core knowledge units that simultaneously satisfy the triple constraints from the answer text, and outputs the candidate watermark set directly in a structured format. Step 1.3: Multi-level post-processing filtering of candidate watermarks, that is, performing a three-level cascaded filtering operation sequentially on the candidate watermark set output by the auxiliary large language model: The first level is format cleaning and null value filtering, which means removing empty strings and invalid characters; The second level involves eliminating overlapping issues, which means checking one by one whether each candidate watermark exists as a substring within the issue. The text will contain the problem. Remove any segment precisely; The third level is semantic deduplication and uniqueness merging, which involves deduplicating the candidate watermarks retained after the first two levels of filtering based on exact string matching, so that each independent knowledge entity watermark appears only once in the final set. After processing through steps 1.1 to 1.3, the final set of knowledge entity watermarks is obtained. ,in The total number of watermarks, each watermark All are from the answers The atomic semantic units extracted from the sample that can uniquely represent the core knowledge content of the sample are used to extract the final output set of samples to be forgotten, which includes watermarked structured annotations. This modified watermark dataset provides a fine-grained evaluation target for subsequent memory quantization.
3. The forgetting method for dynamic large language models based on text watermarking as described in claim 1, characterized in that, The specific method for step 2 is as follows: Step 2.1: Target model inference generates the answer. That is, at each evaluation node of the iterative forgetting, the model parameter update process is paused, and the model inference evaluation stage is entered, calling the large language model to be evaluated at the current iteration step. Iterate through all the samples to be forgotten in the current training set and identify the problems associated with each sample. Input this large language model It performs a forward inference process to generate the model's predicted answer under the current parameter state. The predicted answer will be used as the analysis object for subsequent memory retention detection; Step 2.2: Quantitative calculation of watermark strength, i.e., statistical analysis of the knowledge entity watermark set extracted in Step 1. The watermarks in the model answer The occurrence and coverage ratio are represented by length-weighted matching strength, which characterizes the memory retention strength of target knowledge in a single sample. The calculation formula is as follows: ; in, For the current large language model to be evaluated, The answer generated by the model, As an indicator function, when the watermark word exist The value is 1 when the corresponding knowledge is completely present, indicating that the model still retains the memory of the corresponding knowledge and has not been forgotten; otherwise, it is 0. The length of the watermark word in characters; The total character length of the generated answer; this metric satisfies A larger value indicates a stronger memory of the target knowledge by the model. This indicates that the answers generated by the model no longer contain any knowledge watermarks; Step 2.3: Determine the sample-level forgetting state, i.e., based on the watermark strength of each sample. Establish a system to determine the forgetting state of each sample to be forgotten. The judgment rule is as follows: ; Meanwhile, to achieve overall monitoring of the global forgetting process, the average watermark intensity of all samples to be forgotten is calculated at each evaluation interval. ,in This represents the total number of samples that still need to be trained in the current iteration phase, used to obtain an overall view of the forgetting process; Finally, the forgetting state and average watermark intensity of each sample are output to the dynamic forgetting control module, providing a basis for decision-making for dynamic adjustment of the training set.
4. The forgetting method for dynamic large language models based on text watermarking as described in claim 1, characterized in that, The detailed method for step 3 is as follows: Step 3.1, Dynamic Forgotten Set Pruning, that is, based on the sample forgetting state obtained from the previous quantitative evaluation, to achieve adaptive dynamic updating of the forgetting training set; let the first step be... The forgetting dataset at the time of step is The current model parameters are First, the knowledge memory quantification module in step 2 is used to obtain the information of each sample in the current model. The following is a real-time forgetting state: ; in Indicates that the current parameter is The model; This is an indicator function that returns 1 if the watermark strength is greater than 0, and 0 otherwise. Based on the judgment results, samples with a watermark strength of zero are classified as forgotten samples, and only their state is retained. The unforgotten stubborn samples form an effective training set for a new round of iterations; The updated training set rules are as follows: ; Step 3.2: Execute the forgetting algorithm to update the parameters, that is, in the dynamically pruned forgetting dataset. The selected forgetting algorithm will continue to be used. Update parameters by optimizing the objective function. To weaken the target model's memory of specific knowledge, a parameter iterative update formula is used to optimize the weights: ; in, The learning rate; The target loss function defined for the selected forgetting algorithm; The gradient of the model parameters; Step 3.3: Termination condition determination. This involves automatically checking the global forgetting progress during each interval evaluation and performing a dual termination condition determination: The first termination condition is whether the current training set is empty; if empty, it indicates that the target knowledge of all samples to be forgotten has been completely erased. The second termination condition is whether the current iteration step has reached the preset maximum iteration step number. This serves as a safety measure to prevent training from failing to converge in extreme situations; If any termination condition is met, the iterative training stops immediately, and the target large language model after forgetting is output. If the termination condition is not met, it is determined that there is still unforgotten target knowledge, and the system automatically returns to step 3.1 to start a new sample state evaluation, training set pruning and parameter iteration process until the controllable forgetting of all target knowledge is completed.
5. The forgetting method for dynamic large language models based on text watermarking as described in claim 1, characterized in that, If the gradient ascent algorithm is used in step 3, then the loss function is: ; If the gradient difference algorithm is used, the loss function is: ; in, To model the loss for the standard language on the retained set, This is the balance coefficient; If the direct preference optimization algorithm is used, the loss function is: ; in, For answers to be forgotten For reference only. For reference model parameters, It is the sigmoid function; If the negative preference optimization algorithm is used, the loss function is: ; in, For reference model parameters, For temperature coefficient, It is the sigmoid function; The forgetting algorithm optimizes the corresponding objective function. To update the model parameters.
6. A system for implementing the text watermark-guided dynamic large language model forgetting method of any one of claims 1 to 5, characterized in that, It includes a knowledge watermark extraction module, a knowledge memory quantification module, and a dynamic forgetting control module; The knowledge watermark extraction module is deployed in the data preprocessing stage to receive a set of samples to be forgotten. Each sample contains a question and its corresponding answer. The module guides the large language model to extract the knowledge entity watermark from the answer of the sample to be forgotten through a preset prompt template, forming a set of samples to be forgotten with watermark annotations, providing fine-grained evaluation targets for subsequent memory quantification. The knowledge memory quantification module is deployed in the model inference stage. During the iterative forgetting process, it inputs the questions of each sample to be forgotten in the current training set into the current large language model for inference, generates the corresponding model answer, calculates the watermark strength of the knowledge entity watermark of each sample in the model answer, determines the forgetting state of each sample, and feeds the quantification results back to the dynamic forgetting control module. The dynamic forgetting control module is deployed during the model training phase. During the forgetting training process, it is used to remove forgotten samples with zero watermark strength from the current training set in real time based on the forgetting status of each sample fed back by the knowledge memory quantification module, dynamically update the forgetting set, continue to execute the selected forgetting algorithm on the updated forgetting set, iteratively update the parameters of the large language model until the termination condition is met, and output the large language model after forgetting is completed.
