Large model defense method based on semantic logic
By using a semantic logic-based approach, a new language model is trained by replacing the key layer with a linear regression classifier and a low-rank adaptive decomposer LoRA. This solves the problem of bias identification and blocking in large language models and achieves more accurate, transparent and efficient output.
Patent Information
- Application Number
- CN202411962830.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-30
- Publication Date
- 2025-01-28
- Estimated Expiration
- 2044-12-30
AI Technical Summary
Existing technologies have failed to effectively identify and block biases in pre-training data in large-scale language models, resulting in inaccurate and uninterpretable model outputs, and requiring a large amount of manual annotation and computational resources.
A semantic logic-based approach is adopted, replacing the key layer with a linear regression classifier and a low-rank adaptive decomposer LoRA, and combining unbiased paraphrasing and prediction reconstruction loss functions to train a new language model to reduce the influence of bias and improve interpretability.
It reduces the impact of bias, improves the interpretability and resource efficiency of the model, enhances the model's generalization ability across different tasks and domains, and reduces the dependence on manual annotation and computational resources.
Smart Images

Figure CN119378613A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of artificial intelligence security, and in particular to a large model defense method based on semantic logic. Background Art
[0002] By analyzing semantic logic, we address the undesirable properties or biases that large language models (LLMs) may exhibit in natural language tasks, such as the impact of semantic bias, the unbiased nature of guided representations, the interpretability of the guided process, and improving the security and reliability of LLMs.
[0003] For example, after semantic segmentation of a sentence input into LLMs, many small semantic variables will be generated. If there are three semantic variables C, X, and Y. Figure 1 shown.
[0004] If C is a common cause of X and Y, then C is called a confounding variable. Figure 1 As mentioned above, in this figure, the path from X to Y forms a backdoor path through C because C affects both X and Y, thereby introducing a false correlation between X and Y.
[0005] Figure 2 It shows how to eliminate the influence of confounding variables by blocking the backdoor path. In this figure, by blocking the arrow from X to Z (i.e. blocking the backdoor path), we try to eliminate the interference of C on the causal relationship between X and Y. In this way, the semantic logic effect of X on Y can be more accurately estimated. This example illustrates how to identify and block the influence of bias in large language models. This method is based on such semantic logic to identify and block sources of bias that may affect the output of the model in order to obtain a more accurate and unbiased guided representation. In this way, the bias in the model output can be reduced and the security and reliability of the model can be improved.
[0006] Fine-tuning on Curated Datasets. By training a language model on a dataset that has been screened and cleaned to remove offensive, biased, or misleading content, the model is less likely to generate harmful outputs. This approach may not fully capture all subtle biases and requires a lot of manual annotation and computing resources.
[0007] Reinforcement Learning from Human Feedback (RLHF): Use human evaluators to provide feedback on the quality and safety of generated outputs to train language models. This method requires a lot of manual feedback, is costly, and may introduce human bias.
[0008] Reinforcement Learning from AI Feedback (RLAIF): Using an AI system to provide feedback instead of human evaluators to train a language model. Although this method reduces labor costs, it still requires a lot of computing resources and may lack the intuitive understanding and judgment of humans.
[0009] The closest existing technologies often do not fully consider the impact of biases in pre-training data on the bootstrapping process, resulting in the possibility that the bootstrap vectors are confounded by these biases and thus fail to accurately capture the desired properties; existing methods lack interpretability, which limits the consistency and generalization of model performance and makes the model's decision-making process less transparent; they require a large amount of labeled data and computing resources, especially in reinforcement learning based on human feedback, and the labor cost is high; existing methods may perform well on specific tasks, but have limitations in their generalization capabilities across tasks or domains. Summary of the invention
[0010] In view of the deficiencies of the prior art, the present invention provides a method for generating text-enhanced images based on a diffusion model, which is achieved through the following technical solutions:
[0011] The present invention discloses a large model defense method based on semantic logic, comprising:
[0012] S1: Obtain sufficient training text;
[0013] S2: Input the text into the Transformer layer to obtain the feature map after calculation in each layer of the Transformer layer;
[0014] S3: Through a linear regression classifier Evaluate the feature maps calculated at each layer, linear regression classifier After calculating each feature map, a vector can be obtained, and the value in the vector represents the probability of being classified into the corresponding category, and several vectors are obtained;
[0015] S4: sort several vectors, determine which layers are most sensitive to the target attributes from low to high, and obtain several intervention layers;
[0016] S5: Use a low-rank adaptive decomposer LoRA to replace several intervention layers to obtain a new language model;
[0017] S6: Use the unbiased transcribed data to train a new language model to obtain a trained language model;
[0018] S7: Get interactive text;
[0019] S8: Extract and represent the interactive text to obtain the text after extraction and representation.
[0020] S9: Input the extracted and represented text into the trained language model to obtain a safe and unbiased output.
[0021] As a further improvement, the present invention uses a low-rank adaptive decomposer LoRA to replace several intervention layers to obtain a new language model: if the original intermediate layer is , the unbiased middle layer after replacement is , mathematically expressed as:
[0022]
[0023] Among them, B and A are respectively and The matrix of , Indicates the previous layer of the middle layer.
[0024] As a further improvement, the non-biased statement of the present invention is specifically: the non-biased statement is specifically: given an input prompt , where S is the prefix guide hint and C is the semantic hint. First, the token lengths of S and C are calculated, which are and ,when After the original language model When the layer is , after the above After the LoRA layer, we get the intermediate representation after iteration. , define the intermediate representation set of the original language as R = [ ], the set of intermediate representations after unbiased translation is Rˆ = { },in represents the non-intervention layer, represents the intervention layer, ={ },in The non-intervention layer ={ },in For the intervention layer, define the domain detection module: [- : ], which is equivalent to the semantic prompt part of the entire prompt.
[0025] As a further improvement, the training of a new language model described in the present invention is specifically: the training is debiasing training, and the debiasing training is to predict and reconstruct loss by defining: , and debiasing loss: , forming the final loss function: , the model is trained according to the loss function, where CEloss represents the cross entropy function, represents the output of the original model, represents the new language model, represents the input after unbiased translation, Indicates that the gradient reversal layer is used to reverse the direction of the gradient, so that the direction of the gradient is reversed during back propagation. represents a multi-layer perceptron used to identify confusing concepts, and is a hyperparameter, A directional label that represents the output, i.e., a desired or undesired attribute or concept, rather than a specific classification (e.g., true or false, harmful or harmless, etc.).
[0026] As a further improvement, the extraction characterization in S8 of the present invention is specifically to use LoRA to calculate the difference between the positive and negative debiased representations for each marker, and then calculate the average value of the value to obtain the guidance direction, that is:
[0027] .
[0028] The beneficial effects of the present invention are as follows:
[0029] (1) Reduce the impact of bias. This method systematically identifies and blocks the confounding effects of bias based on semantic logic analysis and model learning techniques, thereby reducing the impact of bias in pre-training data on the guidance process.
[0030] (2) Improved interpretability. The method contains an interpretable component that provides insights into the alignment between the generated output and the desired direction, enhances the interpretability of the bootstrapping process, and enhances the transparency of the model and the user’s trust.
[0031] (3) Improved resource efficiency. Compared with the RLHF and RLAIF methods that require a lot of manual feedback, this method may reduce the dependence on manual annotation and computing resources, thereby improving resource efficiency.
[0032] (4) Strong generalization ability. This method improves the generalization ability of the model in different tasks and fields through unbiased guided representation, which is in contrast to the limited generalization ability of existing technologies and has high scalability and adaptability.
[0033] (5) We conduct semantic logic analysis on the turn-by-turn process in the language model, determine the confounding effect of semantic cues and their impact on turn-by-turn representation, and finally propose a new framework for obtaining unbiased turn-by-turn representation in the language model. This framework innovatively uses adversarial learning techniques to separate the impact of semantic bias on the turn-by-turn process and can effectively prevent the language model from generating biased outputs.
[0034] (6) The framework is an interpretable component that can be applied to different language models, providing insight into the consistency between the generated output and the desired direction, thereby enhancing the interpretability of the steering process while mitigating the impact of bias. BRIEF DESCRIPTION OF THE DRAWINGS
[0035] Figure 1 It is a schematic diagram of the sources of the confounding variables of the present invention;
[0036] Figure 2 This is a schematic diagram of eliminating confounding variables in the present invention;
[0037] Figure 3 It is a logical process diagram of extracting representations of the present invention;
[0038] Figure 4 It is the overall flow chart of the processor of the present invention. DETAILED DESCRIPTION
[0039] The technical solution of the present invention is further described below by means of specific embodiments in conjunction with the accompanying drawings:
[0040] Figure 4 It is an overall flow chart of a large model defense method based on semantic logic of the present invention.
[0041] The present invention discloses a large model defense method based on semantic logic, comprising:
[0042] S1: Obtain sufficient training text;
[0043] S2: Input the text into the Transformer layer to obtain the feature map after calculation in each layer of the Transformer layer;
[0044] S3: Through a linear regression classifier Evaluate the feature maps calculated at each layer, linear regression classifier After calculating each feature map, a vector can be obtained, and the value in the vector represents the probability of being classified into the corresponding category, and several vectors are obtained;
[0045] S4: Sort several vectors, determine which layers are most sensitive to the target attribute from low to high, and obtain several intervention layers; use a linear regression classifier Each layer of the language model is evaluated to determine which layers are most sensitive to the target attribute. Where n is the length of the input sentence, d is the hidden dimension of a layer, and c is the number of target categorical attributes. Such a classifier is used to select the front layer, and such a layer is called an intervention layer.
[0046] S5: Use a low-rank adaptive decomposer LoRA to replace several intervention layers to obtain a new language model; if the original intermediate layer is , the unbiased middle layer after replacement is , mathematically expressed as:
[0047]
[0048] Among them, B and A are and The matrix of , Indicates the previous layer of the middle layer.
[0049] S6: Use the unbiased paraphrased data to train a new language model to obtain a trained language model; unbiased paraphrasing is specifically: given an input prompt , where S is the prefix guide hint and C is the semantic hint. First, the token lengths of S and C are calculated, which are and ,when After the original language model When the layer is , after the above After the LoRA layer, we get the de-iterative intermediate representation , define the intermediate representation set of the original language as R = [ ], the set of intermediate representations after unbiased translation is Rˆ = { },in represents the non-intervention layer, represents the intervention layer, ={ },in The non-intervention layer ={ },in For the intervention layer, define the domain detection module: [- : ], which is equivalent to the semantic prompt part of the entire prompt.
[0050] The training of the new language model is specifically as follows: the training is debiasing training, and the debiasing training is to predict and reconstruct the loss by defining: , and debiasing loss: , forming the final loss function: , the model is trained according to the loss function, where CEloss represents the cross entropy function, represents the output of the original model, represents the new language model, represents the input after unbiased translation, Indicates that the gradient reversal layer is used to reverse the direction of the gradient, so that the direction of the gradient is reversed during back propagation. represents a multi-layer perceptron used to identify confusing concepts, and is a hyperparameter. Represents the directional label of the output, that is, the expected or unexpected attribute or concept, rather than a specific classification (for example, true or false, harmful or harmless, etc.); with this function, the model can be trained.
[0051] S7: Get interactive text;
[0052] S8: Figure 3 is a logical process diagram of the present invention for extracting representations; Extracting representations of interactive texts to obtain texts after extraction and representation. Specifically, the extraction and representation is to use LoRA to calculate the difference between positive and negative debiased representations for each tag, and then calculate the average value of the value to obtain the guidance direction, that is:
[0053] .
[0054] S9: Input the extracted and represented text into the trained language model to obtain a safe and unbiased output.
[0055] Finally, in the inference phase of the model, the representation of the generated Token of the current input is obtained, and the previously obtained guided representation is applied to the current Token representation through projection. Finally, it can be evaluated whether the adjusted output meets the expectations. If necessary, the model or guided representation is adjusted according to the evaluation results.
[0056] Example
[0057] If there is an LLM, we hope that this model can avoid gender bias when generating text. The large model defense method based on semantic logic will help guide the output of the model to make it more neutral. If we want the model to generate a completed sentence without gender bias, first use a sufficient amount of training text containing gender bias (such as "Programmers must be male" and the like). The processor inputs the training text into the Transformer layer to obtain all the feature maps of all training samples after each layer in the Transformer layer is calculated; through a linear regression classifier Evaluate the feature maps calculated at each layer, linear regression classifier After calculating each feature map, a vector can be obtained. The value in the vector represents the probability of being classified into the corresponding category, and several vectors are obtained. The processor sorts the several vectors, determines which layers are most sensitive to the target attribute from low to high, and obtains several intervention layers. The processor automatically constructs and uses a low-rank adaptive decomposer LoRA to replace several intervention layers to obtain a new language model. The new language model is trained using the unbiased paraphrased data to obtain a trained model. If an interactive text is given to the model at this time: "He is an excellent programmer because ___." The final sentence generated is: "He is an excellent programmer because he always learns new technologies. In this example, the generated sentence is neutral and does not show gender bias. If you want the model to avoid racial bias when generating descriptions of people, first use a sufficient amount of training text containing racial bias (such as "The suspicious person looks like race A"). The processor inputs the training text into the Transformer layer to obtain all feature maps of all training samples after calculation by each layer in the Transformer layer; through a linear regression classifier Evaluate the feature maps calculated at each layer, linear regression classifier After calculating each feature map, a vector can be obtained. The value in the vector represents the probability of being classified into the corresponding category, and several vectors are obtained. The processor sorts the several vectors, determines which layers are most sensitive to the target attribute from low to high, and obtains several intervention layers. The processor automatically constructs and uses a low-rank adaptive decomposer LoRA to replace several intervention layers to obtain a new language model. The new language model is trained using the unbiased paraphrased data to obtain a trained model. Input the interactive text to the model: "The suspicious person looks like ___." The model generates: "The suspicious person looks like an ordinary person." If you want the model to avoid age bias when generating descriptions about professional suitability. First, use a sufficient amount of training text containing age bias (such as "The person's poor work ability is entirely because he is too old"), the processor inputs the training text into the Transformer layer, and obtains all feature maps of all training samples after calculation in each layer of the Transformer layer; through a linear regression classifier Evaluate the feature maps calculated at each layer, linear regression classifier After calculating each feature map, a vector can be obtained. The value in the vector represents the probability of being classified into the corresponding category, and several vectors are obtained. The processor sorts the several vectors, determines which layers are most sensitive to the target attributes from low to high, and obtains several intervention layers. The processor automatically constructs and uses a low-rank adaptive decomposer LoRA to replace several intervention layers to obtain a new language model. The new language model is trained using the unbiased transcribed data to obtain a trained model. Interactive text is input into the model: "This new employee is very adaptable to the fast-paced work environment, although he ___." Model output: "This new employee is very adaptable to the fast-paced work environment, although he has just joined the team."
[0058] It should be understood that the above description of the preferred embodiment is relatively detailed and cannot be regarded as limiting the scope of patent protection of the present invention. Under the enlightenment of the present invention, ordinary technicians in this field can also make substitutions or modifications without departing from the scope of protection of the claims of the present invention, which all fall within the scope of protection of the present invention. The scope of protection requested for the present invention shall be based on the attached claims.
Claims
1. A large model defense method based on semantic logic, characterized in that: include: S1: Obtain sufficient training text; S2: Input the text into the Transformer layer to obtain the feature map after calculation in each layer of the Transformer layer; S3: Through a linear regression classifier Evaluate the feature maps calculated at each layer, linear regression classifier After calculating each feature map, a vector can be obtained, and the value in the vector represents the probability of being classified into the corresponding category, and several vectors are obtained; S4: sort several vectors, determine which layers are most sensitive to the target attributes from low to high, and obtain several intervention layers; S5: Use a low-rank adaptive decomposer LoRA to replace several intervention layers to obtain a new language model; S6: Use the unbiased transcribed data to train a new language model to obtain a trained language model; S7: Get interactive text; S8: extracting and representing the interactive text to obtain the text after extraction and representation; S9: Input the extracted and represented text into the trained language model to obtain a safe and unbiased output.
2. The semantic logic-based large model defense method according to claim 1 is characterized in that: The use of a low-rank adaptive decomposer LoRA to replace several intervention layers to obtain a new language model is as follows: if the original intermediate layer is , the unbiased middle layer after replacement is , mathematically expressed as: ; Among them, B and A are and The matrix of , Indicates the previous layer of the middle layer.
3. The semantic logic-based large model defense method according to claim 1 is characterized in that: The unbiased translation is specifically: given an input prompt , where S is the prefix guide hint and C is the semantic hint. First, the token lengths of S and C are calculated, which are and ,when After the original language model When the layer is , after the above After the LoRA layer, we get the intermediate representation after iteration. , define the intermediate representation set of the original language as R = [ ], the set of intermediate representations after unbiased translation is Rˆ = { },in represents the non-intervention layer, represents the intervention layer, ={ },in The non-intervention layer ={ },in For the intervention layer, define the domain detection module: [- : ], which is equivalent to the semantic prompt part of the entire prompt.
4. The semantic logic-based large model defense method according to claim 1 is characterized in that: The training of the new language model is specifically as follows: the training is debiasing training, and the debiasing training is to predict and reconstruct the loss by defining: , and debiasing loss: , forming the final loss function: , the model is trained according to the loss function, where CEloss represents the cross entropy function, represents the output of the original model, represents the new language model, represents the input after unbiased translation, Indicates that the gradient reversal layer is used to reverse the direction of the gradient, so that the direction of the gradient is reversed during back propagation. represents a multi-layer perceptron used to identify confusing concepts, and is a hyperparameter, It indicates the directional label of the output, that is, the expected or unexpected attribute or concept, rather than a specific classification.
5. The semantic logic-based large model defense method according to claim 1 is characterized in that: The extraction representation in S8 is specifically to use LoRA to calculate the difference between the positive and negative debiased representations for each marker, and then calculate the average value of the value to obtain the guidance direction, that is: 。
Citation Information
Patent Citations
Multi-modal model training method and device, electronic equipment and storage medium
CN117828399A
Remote sensing image classification method based on large model secondary distillation
CN118097317A
Named entity recognition method, device and equipment and computer readable storage medium
CN118133830A
Image segmentation method, medical image segmentation system and computer terminal
CN118735949A
Large language model alignment method and device based on neural signal driving
CN119067189A