Big language model knowledge editing method oriented to prejudice content

By dynamically analyzing the bias propagation path and parameter adjustment, the problem of inaccurate bias positioning of large language models is solved, efficient and accurate bias correction is achieved, and the correction effect of the model is improved.

CN120509439APending Publication Date: 2025-08-19UNIV OF ELECTRONICS SCI & TECH OF CHINA
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202510591569.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-05-08
Publication Date
2025-08-19

AI Technical Summary

Technical Problem

When the existing technology corrects the biases in large language models, it lacks in-depth analysis of the bias propagation path, resulting in inaccurate bias positioning and difficulty in accurately correcting.

Method used

By obtaining the test text set, analyzing the parameters of each bias layer of the large language model, using KL divergence to calculate the degree of deviation, combining activation differences and gradient backpropagation, dynamically identify the target layer, and parameter adjustments to the target layer, including singular value decomposition and parameter interpolation, and optimizing bias correction.

Benefits of technology

Improved accuracy and efficiency of bias corrections, ensuring model performance while reducing resource waste.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120509439A_ABST
    Figure CN120509439A_ABST
Patent Text Reader

Abstract

The invention discloses a big language model knowledge editing method oriented to prejudice content, which comprises the following steps that a test text set of a to-be-corrected prejudice type is acquired, and the test text set comprises a prejudice text of the to-be-corrected prejudice type and a corresponding non-prejudice text; the non-prejudice text and the prejudice text are sequentially input into a to-be-corrected large language model, meanwhile, parameters of all prejudice layers of the large language model are sequentially obtained, and the parameters of the prejudice layers comprise output of all layers in a feed-forward neural network (FFN) and the weight of multi-head self-attention (MHSA); calculating the deviation degree of each prejudice layer when no prejudice text exists relative to the prejudice layer when the prejudice layer has the prejudice text according to the parameters of each prejudice layer; determining at least one target layer corresponding to the to-be-corrected prejudice type according to the deviation degree; and adjusting the parameters of the large language model. By dynamically analyzing the prejudice propagation path and combining the activation difference and gradient back propagation, the target layer is accurately identified, and the accuracy of prejudice correction is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the technical field of bias correction, and in particular relates to a large language model knowledge editing method for biased content. Background Art

[0002] A large language model (LLM) is a deep learning model trained using large amounts of text data, enabling it to generate natural language text or understand the meaning of text. Common large language models include ChatGPT and BERT. Large language models demonstrate powerful capabilities in natural language processing tasks, but because their training data typically comes from large-scale corpora on the internet, this data inevitably contains biases based on gender, race, and culture. These biases are absorbed during the model training process and encoded into the model's parameters through the interactions of multi-layer networks, potentially resulting in unfair or discriminatory output when the model generates or predicts text.

[0003] Currently, methods for correcting language model bias mainly include data debiasing, post-processing correction, and model editing-based methods. Data debiasing and post-processing correction methods achieve debiasing by correcting the model's input and output, respectively.

[0004] Model-editing methods, such as MEMIT (Mass-Editing Memory in a Transformer), target a specific layer in the model, typically a middle layer of a feed-forward neural network (FFN), and directly modify its parameters to update knowledge. However, this method has the following problems:

[0005] Existing technologies generally lack in-depth analysis of the bias propagation pathways when addressing model bias. A large-scale language model is a complex, multi-layered system. Bias does not exist in isolation at a single layer, but is generated and propagated during the interaction of multi-layer networks. However, existing methods fail to fully consider this complex characteristic and are unable to systematically analyze the transmission mechanism of bias between layers and the specific impact of different components on bias. This means that when locating target layers and components related to bias, judgments can often only be made based on experience or simple analysis, making it difficult to achieve precise positioning. For example, some methods may judge a layer's association with bias based solely on its performance in a specific task, while ignoring the layer's position in the entire model information flow and its interaction with other layers. This one-sided judgment method makes it impossible to accurately find the root cause of the bias, making subsequent corrections difficult to target. Summary of the Invention

[0006] In order to solve the problem that existing methods have poor accuracy in bias correction, the present invention proposes a large language model knowledge editing method for bias content.

[0007] In order to achieve the above-mentioned object of the invention, the technical solution adopted by the present invention is:

[0008] The present invention provides a large language model knowledge editing method for biased content, comprising the following steps:

[0009] Obtaining a test text set of a bias type to be corrected, wherein the test text set includes at least one text pair, wherein the text pair includes a biased text of the bias type to be corrected and a corresponding unbiased text;

[0010] The unbiased text and the biased text are sequentially input into the large language model to be corrected, and the parameters of each bias layer of the large language model are sequentially obtained, wherein the parameters of the bias layer include the output of each layer in the feedforward neural network FFN and the weight of the multi-head self-attention MHSA;

[0011] The degree of deviation of each bias layer in the case of unbiased text relative to that in the case of biased text is calculated based on the parameters of each bias layer;

[0012] determining at least one target layer corresponding to the bias type to be corrected according to the degree of deviation;

[0013] Adjust the parameters of the large language model.

[0014] The beneficial effects of the present invention are:

[0015] The present invention dynamically analyzes the bias propagation path, combines activation difference and gradient backpropagation, accurately identifies the target layer, and improves the accuracy of bias correction. BRIEF DESCRIPTION OF THE DRAWINGS

[0016] Figure 1 Flowchart of the method of the present invention. DETAILED DESCRIPTION

[0017] The specific embodiments of the present invention are described below to facilitate understanding of the present invention by those skilled in the art. However, it should be clear that the present invention is not limited to the scope of the specific embodiments. For those skilled in the art, as long as various changes are within the spirit and scope of the present invention as defined and determined by the appended claims, these changes are obvious, and all inventions and creations utilizing the concepts of the present invention are protected.

[0018] The present invention provides a large language model knowledge editing method for biased content, specifically, Figure 1 As shown, the method includes steps S1 to S5.

[0019] Step S1: Obtain a test text set of a bias type to be corrected, wherein the test text set includes at least one text pair, and the text pair includes a biased text of the bias type to be corrected and a corresponding unbiased text.

[0020] There are many types of bias, such as gender bias, racial bias, age bias, etc. Different types of bias involve different fields and scenarios.

[0021] In the test text set, all biased text targets only the same type of bias, for example, gender bias. For example, using gender bias as an example, the biased text is "female nurse in surgery," and the corresponding unbiased text is "doctor in surgery." The test text set should contain a sufficient number of biased texts of the same type, covering as many bias-inducing scenarios as possible, providing a rich data foundation for subsequent analysis and ensuring that the model can learn comprehensive bias patterns.

[0022] After obtaining the test text set, it needs to be preprocessed.

[0023] During preprocessing, first use word segmentation tools such as NLTK and Jieba to split the text into words or subwords, and then convert the segmented words or subwords into digital codes that the model can handle, such as using the vocabulary of the pre-trained model for encoding.

[0024] Step S2: input the unbiased text and the biased text into the large language model to be corrected in sequence, and simultaneously obtain the parameters of each bias layer of the large language model in sequence, where the parameters of the bias layer include the output of each layer in the feedforward neural network FFN and the weight of the multi-head self-attention MHSA.

[0025] The large language model can be ChatGPT, BERT, etc., each of which includes FFN, MHSA and corresponding hidden states. Specifically, this step can obtain the output of each layer in FFN and the weight of MHSA through the forward hook function registered with the FFN and MHSA of the large language model.

[0026] Experiments using the PyTorch deep learning framework utilize internal model hooks to accurately record the model's internal state under both biased and unbiased input conditions. After the FFN module is defined, a forward hook function is immediately registered for it using the `register_forward_hook` method. This forward hook receives key parameters such as the FFN layer's input and output and saves the FFN's output to a predefined list. This forward hook is then automatically triggered during each forward pass of the model, as soon as input data passes through the FFN layer, completing the data recording process.

[0027] For attention heads, a forward hook function is registered at the appropriate location within the attention module. This forward hook function accurately records the attention head's weight information. Similarly, during the model's forward propagation, whenever an attention head calculation is involved, this forward hook function is activated to automatically record the attention head weight data.

[0028] Through the above method, the detailed internal status of the model with biased and unbiased inputs can be systematically and comprehensively recorded, providing a rich and accurate data basis for subsequent analysis and research.

[0029] Step S3: Calculate the degree of deviation of each bias layer in the case of unbiased text relative to that in the case of biased text based on the parameters of each bias layer.

[0030] Specifically, this step can calculate the degree of deviation based on the KL divergence. KL divergence (Kullback-Leibler divergence), also known as relative entropy, uses a loss function based on KL divergence to accurately quantify the difference in output between large-scale language models when processing biased and unbiased inputs, thereby effectively detecting and correcting model bias. KL divergence can comprehensively measure the degree of deviation in model output from the perspective of probability distribution, providing key support for model bias correction.

[0031] Specifically, first calculate the output probability distribution P(x i ) and the output probability distribution Q(x) of biased text i ); then calculate the KL divergence of the bias layer based on the output probability distribution of the unbiased text and the corresponding output probability distribution of the biased text. At this time, the KL divergence is:

[0032]

[0033] This formula can accurately calculate the degree of difference between the two distributions. The greater the difference, the more the model is affected by bias.

[0034] The above method is used to calculate the degree of deviation. The zero probability value in the probability distribution leads to the KL divergence calculation error. For this, the Laplace smoothing method can be used to calculate the deviation of P(x i ) and Q(x i ) plus a very small positive number ε to calculate the KL divergence. ε is usually set to 1e-5, or 0.00001. In this case, the KL divergence is:

[0035]

[0036] P unbiased (x i)=P(x i )+ε;

[0037] P biased (x i )=Q(x i )+ε.

[0038] Here n is the dimension of the output space, such as the vocabulary size or the number of categories.

[0039] Step S4: determining at least one target layer corresponding to the bias type to be corrected according to the degree of deviation.

[0040] Specifically, the bias layer with a KL divergence greater than or equal to a threshold can be determined as a candidate target layer; and then the target layer is determined from the candidate target layers based on the structure of the large language model, the large language model's understanding of semantics, and the actual application scenario.

[0041] The threshold here can be set to 0.8.

[0042] To verify the correctness of the target layer, a validation set can be used. During validation, the same validation set of bias-corrected text is used. The validation set includes biased text and its corresponding unbiased text. The biased text has the same bias-corrected type as the test text set.

[0043] Step S5: Adjust the parameters of the large language model.

[0044] There are many ways to adjust the parameters of large language models, such as using existing Fine-tuning or MEMIT (Mass-Editing Memory in a Transformer). Fine-tuning makes overall adjustments to the model based on a large amount of data. MEMIT directly modifies the model parameters to achieve knowledge updates. However, the existing methods have certain limitations. For example, although Fine-tuning can improve model performance to a certain extent, this method is not specifically designed to address bias issues. It lacks specificity when correcting bias and will adjust various aspects of the model, resulting in resource waste and low efficiency. MEMIT cannot effectively coordinate the relationship between these layers and can only edit specific layers one by one, which makes batch correction extremely inefficient. For example, when dealing with complex biases involving multiple layers, MEMIT requires repeated editing operations, which consumes a lot of time and computing resources, seriously affecting the efficiency of bias correction.

[0045] To this end, this step can also be implemented by the following method: performing singular value decomposition on the FFN weight matrix of the target layer, identifying the feature direction most relevant to the bias and replacing the weight matrix with a replacement matrix, wherein the replacement matrix is obtained by linearly transforming the hidden state of the target layer output for the biased text in a specific feature direction; and performing parameter interpolation on the FFN weight matrices of the first two layers adjacent to the target layer using a distance-weighted method.

[0046] Due to the collaborative working mechanism of MHSA and FFN, the attention weights generated by MHSA often contain a large amount of redundant information, which may interfere with the identification of key features of bias. This solution only adjusts the parameters of the FFN of the target layer, reducing the changes to the model, and improves the accuracy of bias correction by fusing the hidden states of MHSA and FFN. In order to further improve the accuracy of bias correction, the FFN weight matrices of the next two adjacent layers of the target layer can also be interpolated by distance weighting. Using the above method, after determining the target layer, targeted bias correction is performed at the vocabulary level, phrase level, and semantic level respectively, and batch updates are achieved through parameter integration, which improves editing efficiency. This method greatly improves editing efficiency and reduces correction costs while ensuring editing effects.

[0047] Specifically, the weighting coefficient in the distance-weighted method is calculated using an exponential decay function.

[0048] The above method uses dynamic positioning of the target layer to identify the key layer most relevant to a certain type of bias correction, thereby improving the accuracy of bias correction.

[0049] Based on the above method, two specific implementation methods are given as examples for illustration.

[0050] Example 1

[0051] This example uses the gender bias correction of the large language model GPT-J as an example.

[0052] First, a test text set containing 200 pairs of gender-biased texts was constructed. The typical biased text was "Women perform poorly in technical management positions," and the corresponding unbiased text was "Technical management ability is unrelated to gender."

[0053] The PyTorch framework's register_forward_hook mechanism fully captures the model's internal state, recording the outputs of the FFN modules and the distribution of attention weights at each Transformer layer. Specifically, a three-layer cascaded activation difference analysis process is implemented: First, unbiased text is input in a clean state to obtain the baseline activation matrix A_unbiased. Next, biased text is input to record A_biased and the KL divergence metrics for each layer are calculated. Finally, an intervention test verifies the target layer. The KL divergence value of the FFN layer 10 reaches 0.48, confirming it as the target layer for the bias type to be corrected and, therefore, the key node for the core bias propagation.

[0054] Entering the batch large language model parameter editing phase, a matrix factorization-based parameter update is performed on the identified 10th FFN layer. First, a singular value decomposition (SVD) is performed on the weight matrix W_10. The largest singular value, σ_3 = 0.82, is identified, corresponding to the semantic direction of the "management ability-gender" bias dimension. A debiasing dictionary is constructed based on the BERT embedding space, and linear interpolation is used to generate neutralized vector representations. For example, the embedding vector for "manager" is adjusted to a gender-neutral version. The calculated replacement matrix ΔW = 0.04 (V_newK^T - V_oldK^T) is directly applied to the target layer parameter update. The adjustments are then propagated to adjacent layers using an exponential decay principle. Layers 8-9 use a decay factor of 0.8 to update the output transformation matrix, and layers 11-12 use a factor of 0.7 to adjust and freeze the bias terms.

[0055] The updated parameters were evaluated through BiasBench, showing a reduction in gender bias scores from an initial 0.71 to 0.29, while maintaining language understanding task accuracy above 92.3%. This demonstrates the solution's ability to effectively correct bias while maintaining model performance. The entire implementation relies on the Transformer's residual connection structure to ensure consistent information flow.

[0056] Those skilled in the art will appreciate that the embodiments described herein are intended to help readers understand the principles of the present invention, and it should be understood that the scope of protection of the present invention is not limited to such specific descriptions and embodiments. Those skilled in the art can make various other specific variations and combinations based on the technical teachings disclosed in the present invention without departing from the essence of the present invention, and such variations and combinations are still within the scope of protection of the present invention.

Claims

1. A large language model knowledge editing method for biased content, characterized by: The following steps are involved: Obtaining a test text set of a bias type to be corrected, wherein the test text set includes at least one text pair, wherein the text pair includes a biased text of the bias type to be corrected and a corresponding unbiased text; The unbiased text and the biased text are sequentially input into the large language model to be corrected, and the parameters of each bias layer of the large language model are sequentially obtained, wherein the parameters of the bias layer include the output of each layer in the feedforward neural network FFN and the weight of the multi-head self-attention MHSA; The degree of deviation of each bias layer in the case of unbiased text relative to that in the case of biased text is calculated based on the parameters of each bias layer; determining at least one target layer corresponding to the bias type to be corrected according to the degree of deviation; Adjust the parameters of the large language model.

2. The method for editing knowledge of a large language model for biased content according to claim 1, characterized in that: The parameters of each bias layer of the large language model are obtained as follows: The output of each layer in FFN and the weight of MHSA are obtained through the forward hook functions registered in FFN and MHSA of the large language model.

3. The method for editing knowledge of a large language model for biased content according to claim 1, characterized in that: The deviation degree of each bias layer obtained by calculating the parameters of each bias layer in the case of unbiased text relative to the case of biased text is: Calculate the output probability distribution of each bias layer on unbiased text and biased text; The KL divergence of the bias layer is calculated based on the output probability distribution of the unbiased text and the corresponding output probability distribution of the biased text.

4. The method for editing knowledge of a large language model for biased content according to claim 3, characterized in that: After calculating the output probability distribution of the unbiased text and the output probability distribution of the biased text at each bias layer, the method further includes: Add a positive number to the output probability distribution of unbiased text and the output probability distribution of biased text respectively.

5. The method for editing knowledge of a large language model for biased content according to claim 1, characterized in that: The adjusting of the large language model parameters includes: The FFN weight matrix of the target layer is subjected to singular value decomposition to identify the feature direction most relevant to the bias and replace the weight matrix with a replacement matrix. The replacement matrix is obtained by linearly transforming the hidden state of the target layer's output of the biased text in a specific feature direction. The FFN weight matrices of the first two layers adjacent to the target layer are interpolated using a distance-weighted approach.

6. The method for editing knowledge of a large language model for biased content according to claim 5, characterized in that: It also includes performing parameter interpolation on the FFN weight matrices of the next two layers adjacent to the target layer in a distance-weighted manner.

7. The method for editing knowledge of a large language model for biased content according to claim 5 or 6, characterized in that: The weighting coefficient in the distance-weighted method is calculated using an exponential decay function.

Citation Information

Cited By

  • Data depolarization and alignment enhancement method for large language model, electronic equipment and storage medium

    CN121352002A