Large language model security optimization method and device, equipment and medium

By generating and applying common word-level and target word-level adversarial suffixes, as well as target semantic adversarial prompts, the jailbreak attack defense capability of the large language model is improved, and the problem of insufficient protection against unknown forms of attacks in the existing technology is solved, and the problem of insufficient protection of attacks in unknown forms is realized. Stronger security and attack resistance.

CN118965366AActive Publication Date: 2024-11-15HONG KONG UNIV OF SCI & TECH (GUANGZHOU)

Patent Information

Application Number
CN202411029274.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-07-30
Publication Date
2024-11-15
Estimated Expiration
2044-07-30

AI Technical Summary

Technical Problem

Large language models are vulnerable to maliciously designed input sequence attacks, resulting in jailbreak attacks, and existing defense methods are difficult to effectively protect against unknown forms of attacks.

Method used

By obtaining the attack task dataset, generating common word-level and target word-level adversarial suffixes, fine-tuning the large language model to improve its ability to attack, and using target semantic adversarial cues to further enhance the semantic robustness of the model, effectively coping with known and unknown Form of jailbreak attack.

Benefits of technology

It significantly improves the resistance of large language models to jailbreak attacks, improves its overall security and attack resistance, and can effectively identify and defend against various forms of attacks, including unknown forms of semantic-level confrontation.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118965366A_ABST
    Figure CN118965366A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of artificial intelligence security, and discloses a large language model security optimization method and device, equipment and a medium, and the method comprises the steps: obtaining an attack task data set; wherein the attack task data set comprises at least one attack task type and a plurality of malicious instruction data under the attack task type; generating a general word-level confrontation suffix corresponding to the attack task type according to the malicious instruction data, and generating a target word-level confrontation suffix corresponding to the malicious instruction data according to the general word-level confrontation suffix; performing first fine tuning on the large language model based on the target word-level adversarial suffix to obtain a first fine tuning model; and performing second fine tuning on the first fine tuning model based on the obtained target semantic-level confrontation prompt to obtain a second fine tuning model. According to the method and the device, the resistance of the large language model to various known and unknown jailbreak attacks can be improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of artificial intelligence security technology, and in particular to a large language model security optimization method, device, equipment and medium. Background Art

[0002] In recent years, large language models have mastered a large amount of natural language knowledge through self-supervised pre-training, and have achieved outstanding performance in many complex tasks with their powerful semantic understanding and generation capabilities. However, recent studies have found that large language models also have security risks and are vulnerable to attacks by maliciously designed input sequences (i.e., adversarial prompts) to produce harmful outputs. This attack is called a "jailbreak attack."

[0003] Although large language models have added defense measures to address the above issues, existing methods are limited to simple pruning or filtering and lack effective protection against unknown forms (such as semantic-level adversarial attacks). Therefore, it is urgent to solve the problem of how to improve the ability of large language models to resist various known and unknown forms of jailbreak attacks. Summary of the invention

[0004] The present application provides a large language model security optimization method, device, equipment and medium, which solves the technical problem of how to improve the ability of a large language model to resist various known and unknown forms of jailbreak attacks, and achieves the technical effect of improving the protection capability of a large language model.

[0005] In order to achieve the above objectives, the main technical solutions adopted in this application include:

[0006] In a first aspect, an embodiment of the present application provides a large language model security optimization method, the method comprising:

[0007] Acquire an attack task data set; wherein the attack task data set includes at least one attack task type and a plurality of malicious instruction data under the attack task type;

[0008] Generate a universal word-level adversarial suffix corresponding to the attack task type according to the malicious instruction data, and generate a target word-level adversarial suffix corresponding to the malicious instruction data according to the universal word-level adversarial suffix;

[0009] Performing a first fine-tuning on the large language model based on the target word-level adversarial suffix to obtain a first fine-tuning model;

[0010] The first fine-tuning model is fine-tuned for a second time based on the acquired target semantic-level adversarial prompt to obtain a second fine-tuning model.

[0011] A large language model security optimization method proposed in an embodiment of the present application first obtains and processes an attack task data set, and then generates a general word-level adversarial suffix and a target word-level adversarial suffix. These suffixes are used to change the structure and meaning of the original malicious instruction data to increase its obfuscation and difficulty to detect. The general adversarial suffix changes the general structure through rules or patterns, and the target adversarial suffix is ​​tailored for specific malicious instruction data, aiming to confuse its meaning or execution path. Then, the target word-level adversarial suffix is ​​used to fine-tune the large language model so that it can recognize and correctly process malicious instruction data transformed by the target word-level adversarial suffix, improve the model's adaptability to mutation attacks, and thus improve overall security and anti-attack capabilities. Then the target semantic-level adversarial prompt is used to further fine-tune the model to cope with attacks and confusion at the semantic level, making it more semantically robust, able to correctly interpret and cope with minor changes in the input, thereby avoiding outputting erroneous results. This embodiment can effectively cope with known and unknown forms of jailbreak attacks through two-layer model optimization at the word level and semantic level.

[0012] Optionally, the acquiring of an attack task data set includes at least one attack task type and a plurality of malicious instruction data under the attack task type, including:

[0013] Obtain malicious instruction data;

[0014] Clustering the malicious instruction data using a preset instruction embedding model to obtain at least one of the attack task types;

[0015] At least one malicious instruction data in each of the attack task types is randomly extracted to construct the attack task data set for each of the attack task types.

[0016] This embodiment collects malicious instruction data and converts it into a high-dimensional feature vector using an instruction embedding model to capture its semantic information. Cluster analysis is then performed on these data to effectively group malicious instruction data with similar semantic features, thereby identifying different types of attack tasks. Randomly extracting at least one malicious instruction data from each attack task type to form a dedicated attack task data set helps to build various attack scenario models in detail. These data sets can be used to train and test the security of large language models and improve their ability to identify and defend against specific attack types.

[0017] Optionally, generating a universal word-level adversarial suffix corresponding to the attack task type according to the malicious instruction data includes:

[0018] Determine the gradient of each token in the malicious instruction data;

[0019] According to the gradient, a greedy algorithm is used to determine an initial candidate token set corresponding to the attack task type;

[0020] Using a first-order gradient approximation method to screen the initial candidate token set, obtaining a target candidate token set corresponding to the attack task type;

[0021] A word-level adversarial suffix set is constructed according to the target candidate token set, and an attack evaluation is performed on the word-level adversarial suffixes in the word-level adversarial suffix set, and the general word-level adversarial suffix corresponding to the attack task type is determined according to the attack evaluation result.

[0022] This embodiment first calculates the gradient of each token for each malicious instruction data, and these gradients reflect the difference between the model output and the attack target sequence. Then, based on the gradient of each token, an initial candidate token set is selected, which has the potential to most affect the model output to meet the attacker's expected goals. Then, the initial candidate token set is screened using the first-order gradient approximation method to determine the final optimized target candidate token set, thereby improving the attack success rate and making the model output more consistent with the attack target. Finally, a word-level adversarial suffix set is constructed based on the determined target candidate token set, with the aim of changing the semantics of the original malicious instruction data so that it is more likely to cause the model output to be consistent with the attacker's expectations. Each word-level adversarial suffix in the word-level adversarial suffix set is evaluated in detail to ensure its versatility in various attack tasks, thereby obtaining a universal word-level adversarial suffix.

[0023] Optionally, constructing a word-level adversarial suffix set according to the target candidate token set, performing attack evaluation on the word-level adversarial suffixes in the word-level adversarial suffix set, and determining the common word-level adversarial suffix corresponding to the attack task type according to the attack evaluation result includes:

[0024] Randomly extract at least one token from the target candidate token set to construct the word-level adversarial suffix set;

[0025] Performing attack evaluation on the word-level adversarial suffixes in the word-level adversarial suffix set;

[0026] If the attack success rate of the word-level adversarial suffix of the current iteration is greater than the attack success rate of the word-level adversarial suffix of the previous iteration, the word-level adversarial suffix of the current iteration is determined as the current word-level adversarial suffix;

[0027] Until a preset condition is met, the current word-level adversarial suffix is ​​determined as the universal word-level adversarial suffix corresponding to the attack task type.

[0028] This embodiment randomly extracts one or more tokens from the target candidate token set to form a word-level adversarial suffix set. These word-level adversarial suffixes can change the form and content of malicious instruction data in an attempt to circumvent the defense mechanism of the model. Each word-level adversarial suffix is ​​then attached to the malicious instruction data to form an adversarial sample. These adversarial samples are input into the language model, the response of the model is recorded, and an evaluation is made as to whether the attack is successful. If the attack success rate of the word-level adversarial suffix of the current iteration is higher than that of the previous iteration, the word-level adversarial suffix is ​​updated to the version of the current iteration. Continue to iterate and update the word-level adversarial suffix until the preset conditions are met, and finally determine a universal adversarial suffix that can generally improve the attack success rate. This embodiment continuously optimizes and selects word-level adversarial suffixes to improve the attack success rate, making the attack more difficult to detect and confront, thereby achieving the purpose of bypassing the language model defense.

[0029] Optionally, generating a target word-level adversarial suffix corresponding to the malicious instruction data according to the universal word-level adversarial suffix includes:

[0030] According to the universal word-level adversarial suffix, a greedy algorithm is used to generate a target word-level adversarial suffix corresponding to the malicious instruction data.

[0031] This embodiment generates a customized target word-level adversarial suffix for each malicious instruction data, so that the adversarial sample can more effectively deceive the target language model and improve the success rate of the attack.

[0032] Optionally, the target semantic-level adversarial prompt is obtained in the following manner:

[0033] Determine the initial semantic-level adversarial cue corresponding to the attack target sequence;

[0034] Taking the initial semantic-level adversarial prompt as input to the first fine-tuning model to generate response data;

[0035] Determine a jailbreak assessment score corresponding to the response data;

[0036] When the jailbreak evaluation score is less than a preset jailbreak threshold, the initial semantic-level adversarial prompt is iteratively optimized until the target semantic-level adversarial prompt is obtained when the jailbreak evaluation score is greater than or equal to the preset jailbreak threshold.

[0037] This embodiment first inputs the initial semantic-level adversarial prompt designed for the attack target sequence into the first fine-tuning model for fine-tuning. The first fine-tuning model generates corresponding output data, which is affected by the initial semantic-level adversarial prompt, and these output data specifically reflect the model's response to the attack prompt. Next, a jailbreak evaluation is performed based on the generated response data, and the initial semantic-level adversarial prompt is adjusted according to the evaluation result feedback until the jailbreak evaluation score of the generated response data reaches the preset jailbreak threshold. Through this method of using semantic-level adversarial prompts and iterative optimization, the probability of a successful attack is effectively improved, so that the generated text can be as close as possible to the expected malicious or misleading target.

[0038] Optionally, the first fine-tuning and / or the second fine-tuning adopts parameter efficient fine-tuning PEFT technology.

[0039] This embodiment adopts the parameter efficient fine-tuning PEFT technology to achieve updating only a small part of the model parameters during the fine-tuning process, thereby reducing the usage of training resources.

[0040] In a second aspect, an embodiment of the present application provides a large language model security optimization device, the device comprising:

[0041] A data acquisition module, used to acquire an attack task data set; wherein the attack task data set includes at least one attack task type and a plurality of malicious instruction data under the attack task type;

[0042] A word-level adversarial suffix generation module, used to generate a universal word-level adversarial suffix corresponding to the attack task type according to the malicious instruction data, and to generate a target word-level adversarial suffix corresponding to the malicious instruction data according to the universal word-level adversarial suffix;

[0043] A first fine-tuning model generating module, configured to perform a first fine-tuning on the large language model based on the target word-level adversarial suffix to obtain a first fine-tuning model;

[0044] The second fine-tuning model generation module is used to perform a second fine-tuning on the first fine-tuning model based on the acquired target semantic-level adversarial prompt to obtain a second fine-tuning model.

[0045] A large language model security optimization device proposed in an embodiment of the present application first obtains and processes an attack task data set, and then generates a general word-level adversarial suffix and a target word-level adversarial suffix. These suffixes are used to change the structure and meaning of the original malicious instruction data to increase its obfuscation and difficulty to detect. The general adversarial suffix changes the general structure through rules or patterns, and the target adversarial suffix is ​​tailored for specific malicious instruction data, aiming to confuse its meaning or execution path. Then, the target word-level adversarial suffix is ​​used to fine-tune the large language model so that it can recognize and correctly process the malicious instruction data transformed by the target word-level adversarial suffix, improve the model's adaptability to mutation attacks, and thus improve the overall security and anti-attack capabilities. Then the target semantic-level adversarial prompt is used to further fine-tune the model to cope with attacks and confusion at the semantic level, making it more semantically robust, able to correctly interpret and cope with minor changes in the input, thereby avoiding outputting erroneous results. This embodiment can effectively cope with known and unknown forms of jailbreak attacks through two-layer model optimization at the word level and semantic level.

[0046] Optionally, the acquiring of an attack task data set includes at least one attack task type and a plurality of malicious instruction data under the attack task type, including:

[0047] Obtain malicious instruction data;

[0048] Clustering the malicious instruction data using a preset instruction embedding model to obtain at least one of the attack task types;

[0049] At least one malicious instruction data in each of the attack task types is randomly extracted to construct the attack task data set for each of the attack task types.

[0050] This embodiment collects malicious instruction data and converts it into a high-dimensional feature vector using an instruction embedding model to capture its semantic information. Cluster analysis is then performed on these data to effectively group malicious instruction data with similar semantic features, thereby identifying different types of attack tasks. Randomly extracting at least one malicious instruction data from each attack task type to form a dedicated attack task data set helps to build various attack scenario models in detail. These data sets can be used to train and test the security of large language models and improve their ability to identify and defend against specific attack types.

[0051] Optionally, generating a universal word-level adversarial suffix corresponding to the attack task type according to the malicious instruction data includes:

[0052] Determine the gradient of each token in the malicious instruction data;

[0053] According to the gradient, a greedy algorithm is used to determine an initial candidate token set corresponding to the attack task type;

[0054] Using a first-order gradient approximation method to screen the initial candidate token set, obtaining a target candidate token set corresponding to the attack task type;

[0055] A word-level adversarial suffix set is constructed according to the target candidate token set, and an attack evaluation is performed on the word-level adversarial suffixes in the word-level adversarial suffix set, and the general word-level adversarial suffix corresponding to the attack task type is determined according to the attack evaluation result.

[0056] This embodiment first calculates the gradient of each token for each malicious instruction data, and these gradients reflect the difference between the model output and the attack target sequence. Then, based on the gradient of each token, an initial candidate token set is selected, which has the potential to most affect the model output to meet the attacker's expected goals. Then, the initial candidate token set is screened using the first-order gradient approximation method to determine the final optimized target candidate token set, thereby improving the attack success rate and making the model output more consistent with the attack target. Finally, a word-level adversarial suffix set is constructed based on the determined target candidate token set, with the aim of changing the semantics of the original malicious instruction data so that it is more likely to cause the model output to be consistent with the attacker's expectations. Each word-level adversarial suffix in the word-level adversarial suffix set is evaluated in detail to ensure its versatility in various attack tasks, thereby obtaining a universal word-level adversarial suffix.

[0057] Optionally, constructing a word-level adversarial suffix set according to the target candidate token set, performing attack evaluation on the word-level adversarial suffixes in the word-level adversarial suffix set, and determining the common word-level adversarial suffix corresponding to the attack task type according to the attack evaluation result includes:

[0058] Randomly extract at least one token from the target candidate token set to construct the word-level adversarial suffix set;

[0059] Performing attack evaluation on the word-level adversarial suffixes in the word-level adversarial suffix set;

[0060] If the attack success rate of the word-level adversarial suffix of the current iteration is greater than the attack success rate of the word-level adversarial suffix of the previous iteration, the word-level adversarial suffix of the current iteration is determined as the current word-level adversarial suffix;

[0061] Until a preset condition is met, the current word-level adversarial suffix is ​​determined as the universal word-level adversarial suffix corresponding to the attack task type.

[0062] This embodiment randomly extracts one or more tokens from the target candidate token set to form a word-level adversarial suffix set. These word-level adversarial suffixes can change the form and content of malicious instruction data in an attempt to circumvent the defense mechanism of the model. Each word-level adversarial suffix is ​​then attached to the malicious instruction data to form an adversarial sample. These adversarial samples are input into the language model, the response of the model is recorded, and an evaluation is made as to whether the attack is successful. If the attack success rate of the word-level adversarial suffix of the current iteration is higher than that of the previous iteration, the word-level adversarial suffix is ​​updated to the version of the current iteration. Continue to iterate and update the word-level adversarial suffix until the preset conditions are met, and finally determine a universal adversarial suffix that can generally improve the attack success rate. This embodiment continuously optimizes and selects word-level adversarial suffixes to improve the attack success rate, making the attack more difficult to detect and confront, thereby achieving the purpose of bypassing the language model defense.

[0063] Optionally, generating a target word-level adversarial suffix corresponding to the malicious instruction data according to the universal word-level adversarial suffix includes:

[0064] According to the universal word-level adversarial suffix, a greedy algorithm is used to generate a target word-level adversarial suffix corresponding to the malicious instruction data.

[0065] This embodiment generates a customized target word-level adversarial suffix for each malicious instruction data, so that the adversarial sample can more effectively deceive the target language model and improve the success rate of the attack.

[0066] Optionally, the target semantic-level adversarial prompt is obtained in the following manner:

[0067] Determine the initial semantic-level adversarial cue corresponding to the attack target sequence;

[0068] Taking the initial semantic-level adversarial prompt as input to the first fine-tuning model to generate response data;

[0069] Determine a jailbreak assessment score corresponding to the response data;

[0070] When the jailbreak evaluation score is less than a preset jailbreak threshold, the initial semantic-level adversarial prompt is iteratively optimized until the target semantic-level adversarial prompt is obtained when the jailbreak evaluation score is greater than or equal to the preset jailbreak threshold.

[0071] This embodiment first inputs the initial semantic-level adversarial prompt designed for the attack target sequence into the first fine-tuning model for fine-tuning. The first fine-tuning model generates corresponding output data, which is affected by the initial semantic-level adversarial prompt, and these output data specifically reflect the model's response to the attack prompt. Next, a jailbreak evaluation is performed based on the generated response data, and the initial semantic-level adversarial prompt is adjusted according to the evaluation result feedback until the jailbreak evaluation score of the generated response data reaches the preset jailbreak threshold. Through this method of using semantic-level adversarial prompts and iterative optimization, the probability of a successful attack is effectively improved, so that the generated text can be as close as possible to the expected malicious or misleading target.

[0072] Optionally, the first fine-tuning and / or the second fine-tuning adopts parameter efficient fine-tuning PEFT technology.

[0073] This embodiment adopts the parameter efficient fine-tuning PEFT technology to achieve updating only a small part of the model parameters during the fine-tuning process, thereby reducing the usage of training resources.

[0074] In a third aspect, an embodiment of the present application provides a computer device, including:

[0075] A memory and a processor, wherein the memory and the processor are communicatively connected to each other, the memory stores computer instructions, and the processor executes the large language model security optimization method described above by executing the computer instructions.

[0076] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, on which computer instructions are stored, and the computer instructions are used to enable a computer to execute the large language model security optimization method described above. BRIEF DESCRIPTION OF THE DRAWINGS

[0077] In order to more clearly illustrate the specific implementation methods of the present application or the technical solutions in the prior art, the drawings required for use in the specific implementation methods or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are some implementation methods of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.

[0078] Figure 1 A flowchart of a large language model security optimization method provided in an embodiment of the present application;

[0079] Figure 2 A flowchart of step S1 provided in an embodiment of the present application;

[0080] Figure 3 A flowchart for generating a universal word-level adversarial suffix provided in an embodiment of the present application;

[0081] Figure 4 A flowchart of step S317 provided in an embodiment of the present application;

[0082] Figure 5 A flowchart of generating a target word-level adversarial suffix provided in an embodiment of the present application;

[0083] Figure 6 A flowchart of a method for obtaining a target semantic-level adversarial prompt provided in an embodiment of the present application;

[0084] Figure 7 A large language model security optimization device provided in an embodiment of the present application;

[0085] Figure 8 A schematic diagram of the structure of a computer device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0086] In order to make the purpose, technical solution and advantages of the embodiments of the present application clearer, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without creative work are within the scope of protection of the present application.

[0087] In recent years, large language models have mastered a large amount of natural language knowledge through self-supervised pre-training, and have achieved outstanding performance in many complex tasks with their powerful semantic understanding and generation capabilities. However, recent studies have found that large language models also have security risks and are vulnerable to attacks by maliciously designed input sequences (i.e., adversarial prompts) to produce harmful outputs. This attack is called a "jailbreak attack."

[0088] In order to defend against jailbreak attacks, there are two main types of existing defense methods:

[0089] System-level defense: Filter out potential malicious inputs through pre-processing or post-processing methods such as reminder mechanisms and input smoothing. For example, SmoothLLM obtains multiple variant inputs by perturbing the input, and then votes to filter the output results of the large language model. However, methods such as reminder mechanisms and input smoothing are usually designed for known forms of attacks, which means that attacks of unknown forms may not be effectively identified or defended. Although input smoothing can generate multiple variants to reduce the risk of specific forms of attacks, defense against semantic-level adversarial attacks (such as semantic perturbations) is still difficult to be detected by the system.

[0090] Model-level defense: Enhance the robustness of large language models by directly modifying their parameters through adversarial training, unlearning, etc. For example, adversarial training is to inject adversarial samples into the training process of large language models to enhance their recognition ability. However, although adversarial training can improve the model's ability to resist known forms of attacks to a certain extent, it may not cover all possible forms of attacks, especially when attackers use new attack strategies.

[0091] For example, the existing large language model (LLM) is a sequence-to-sequence (seq2seq) model based on Transformer. The core idea of ​​this model is to generate outputs step by step in the order of the sequence, and each generated output depends on the previously generated output and input sequence. Specifically, given a leading token sequence x 1:n , the probability that the model generates the target sequence y:

[0092]

[0093] That is, every probability Indicates that in a known sequence x 1:n+i-1 In the case of , generate the next token sequence x n+i The probability of n is the leading token sequence x 1:n The length of the sequence.

[0094] The leading token sequence here can be the beginning of a sentence, or a prompt given by the user. For example, given a leading token sequence: "Today's weather", the target sequence: "Today's weather is very good, suitable for going out for a walk."

[0095] Although LLM has been security checked to prevent the use of data with malicious instructions x 1:m But when the input is an adversarial prompt When LLM is used, it is easy to bypass the safety mechanism, resulting in the generation of dangerous and harmful output Such as "bomb making tutorial" and other illegal content, this attack is called "jailbreak attack". The symbol ⊕ here means that the malicious instruction data x 1:m With the adversarial suffix r 1:k Connected together.

[0096] The large language model security optimization method provided in this specification can be applied to electronic devices with page display functions. The electronic devices may include notebooks, desktop computers, smart phones, smart wearable devices (virtual reality glasses, smart watches, etc.), tablet computers, etc. Of course, the large language model security optimization method provided in this specification can also be applied to applications running in the above-mentioned electronic devices.

[0097] According to an embodiment of the present application, an embodiment of a large language model security optimization method is provided. It should be noted that the steps shown in the flowchart of the accompanying drawings can be executed in a computer system such as a set of computer executable instructions, and although the logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in an order different from that shown here.

[0098] In this embodiment, a large language model security optimization method is provided. Figure 1 A flowchart of a large language model security optimization method provided in an embodiment of the present application, such as Figure 1 As shown, the process includes the following steps:

[0099] Step S1, obtaining an attack task data set; wherein the attack task data set includes at least one attack task type and a plurality of malicious instruction data under the attack task type.

[0100] Specifically, the attack task dataset includes a variety of different attack task types. Each attack task type includes multiple malicious instruction data, which can be the result of pre-collecting a large number of attack tasks, such as hijacking instructions, jailbreak attack instructions, leakage instructions, etc. These malicious instruction data can be historical attack samples, artificially constructed malicious texts, or potential malicious content obtained from the Internet through crawler technology.

[0101] Step S3, generating a universal word-level adversarial suffix corresponding to the attack task type according to the malicious instruction data, and generating a target word-level adversarial suffix corresponding to the malicious instruction data according to the universal word-level adversarial suffix.

[0102] The universal word-level adversarial suffix refers to a suffix rule or pattern that is specifically used to modify the universal structure of malicious instruction data for a specific attack task type. Since the malicious instruction data transformed by the universal word-level adversarial suffix is ​​different from the original malicious instruction data, it will reduce the recognition rate of the large language model and increase the success rate of the attack.

[0103] The target word-level adversarial suffix is ​​an individual suffix for specific malicious instruction data, which is intended to confuse or modify its meaning or execution path. By adopting the target word-level adversarial suffix, the malicious instruction data transformed can more effectively achieve the attacker's intended goal and is more difficult to be detected by large language models, increasing its obfuscation and concealment.

[0104] Specifically, based on the malicious instruction data, a universal adversarial suffix for the attack task type is generated, and based on the universal adversarial suffix, a target word-level adversarial suffix corresponding to the malicious instruction data is generated to increase the diversity and difficulty of detection of the malicious instruction data.

[0105] Step S5: performing a first fine-tuning on the large language model based on the target word-level adversarial suffix to obtain a first fine-tuning model.

[0106] The large language model can be a pre-trained model such as LLM (Large Language Model), GPT (Generative Pre-trained Transformer), BERT (Bidirectional Encoder Representations from Transformers), RoBERTa (Robustly Optimized BERT approach), XLNet (extreme Multi-label Learning Network), T5 (Text-to-Text Transfer Transformer), etc. Preferably, in this embodiment, the large language model is determined to be an LLM model suitable for text generation tasks.

[0107] Specifically, using the target word-level adversarial suffix r 1:k The original malicious command data x 1:m After transformation, we get adversarial samples For adversarial examples For labeling, a pre-trained language model can be used for secure labeling to obtain adversarial samples Corresponding security response Then the adversarial sample and security response Constructing the first fine-tuning dataset Fine-tune the large language model, during which the model will learn how to generate the desired safe response to adversarial samples. Through this fine-tuning strategy, the large language model can not only enhance its resistance to specific attack patterns, but also improve its overall security, making it more robust in the face of complex attack scenarios.

[0108] Step S7: performing a second fine-tuning on the first fine-tuning model based on the acquired target semantic-level adversarial cue to obtain a second fine-tuning model.

[0109] Targeted semantic-level adversarial prompts refer to making slight modifications to the input text to confuse the model semantically and output incorrect results.

[0110] Specifically, according to the target semantic level adversarial hint Use a pre-trained language model to annotate these target semantic-level adversarial cues Corresponding new security response Then the target semantic level adversarial prompt and new security responses Constructing the second fine-tuning dataset Fine-tune the first fine-tuned model. During the fine-tuning process, the model will learn how to generate the expected safe response to the target semantic-level adversarial prompts, thereby further enhancing its robustness against evolving unknown forms of attacks.

[0111] The present embodiment provides a large language model security optimization method, which first obtains and processes the attack task data set, and then generates a general word-level adversarial suffix and a target word-level adversarial suffix. These suffixes are used to change the structure and meaning of the original malicious instruction data to increase its obfuscation and difficulty to detect. The general adversarial suffix changes the general structure through rules or patterns, and the target adversarial suffix is ​​tailored for specific malicious instruction data, aiming to confuse its meaning or execution path. Then, the target word-level adversarial suffix is ​​used to fine-tune the large language model so that it can recognize and correctly process the malicious instruction data transformed by the target word-level adversarial suffix, improve the model's adaptability to mutation attacks, and thus improve the overall security and anti-attack capabilities. Then, the target semantic-level adversarial prompt is used to further fine-tune the model to cope with attacks and confusion at the semantic level, making it more semantically robust, able to correctly interpret and cope with small changes in the input, thereby avoiding outputting erroneous results. This embodiment can effectively cope with known and unknown forms of jailbreak attacks through two-layer model optimization at the word level and semantic level.

[0112] In some embodiments, the first fine-tuning and / or the second fine-tuning adopts parameter efficient fine-tuning PEFT technology.

[0113] Parameter-Efficient Fine-Tuning (PEFT) technology is a fine-tuning method that aims to improve the performance of the model for a specific task without significantly increasing the training cost. PEFT technology achieves fine-tuning by updating only a small part of the model parameters, thereby reducing the demand for training resources. PEFT technologies include LoRA (Low-Rank Adaptation), BitFit, Adapter Layers, etc. Preferably, in this embodiment, the PEFT technology is determined to be LoRA.

[0114] Specifically, the loss function used in the first fine-tuning is for:

[0115]

[0116] in, is the safety response, t is the safety response The position index in , is the adversarial sample, n is the number of tokens of the adversarial sample, is the i-th malicious instruction data, m is the number of tokens of malicious instruction data, is the i-th target word-level adversarial suffix, k is the number of tokens of the target word-level adversarial suffix, ⊕ is the concatenation operation, and π θ is the parameterized representation of the large language model, and θ is the parameter of the large language model.

[0117] Loss Function The probability of the large language model outputting a correct and secure response at each time step is accumulated in the form of negative log-likelihood to train and optimize the model so that it can generate responses that meet security requirements when faced with adversarial samples.

[0118] The loss function used in the second fine-tuning for:

[0119]

[0120] in, is the new security response, t is the new security response The position index in , is the target semantic-level adversarial prompt, n′ is the number of tokens of the target semantic-level adversarial prompt, is the parameterized representation of the first fine-tuned model, θ 1 are the parameters of the first fine-tuned model.

[0121] The entire loss function The probability of the first fine-tuned model outputting a correct new safety response at each time step is accumulated in the form of negative log-likelihood, so as to train and optimize the first fine-tuned model so that it can generate a response that meets safety requirements when faced with target semantic-level adversarial prompts.

[0122] and Figure 1 Compared with the embodiment shown in the figure, this embodiment adopts the parameter efficient fine-tuning PEFT technology to achieve that only a small part of the model parameters are updated during the fine-tuning process, thereby reducing the usage of training resources.

[0123] Figure 2 The flowchart of step S1 provided in the embodiment of the present application may include the following steps:

[0124] Step S11, obtaining malicious instruction data.

[0125] Specifically, malicious instruction data can be extracted by analyzing malware samples, or web crawler technology can be used to collect potential malicious instruction data from the Internet, such as from hacker forums, dark webs, or social media platforms.

[0126] Step S13: clustering the malicious instruction data using a preset instruction embedding model to obtain at least one of the attack task types.

[0127] Specifically, the instruction embedding model can be a BERT, GPT or other model, which converts malicious instruction data into high-dimensional feature vectors that can capture the semantic information of malicious instruction data. A clustering algorithm (such as K-means, hierarchical clustering, DBSCAN, etc.) is applied to the preset instruction embedding model to cluster the high-dimensional feature vectors to identify different attack task types in the malicious instruction data.

[0128] Step S15: randomly extract at least one malicious instruction data in each of the attack task types, and construct the attack task data set for each of the attack task types.

[0129] Specifically, for each identified attack task type, at least one malicious instruction data is randomly extracted as a representative of the type, and the randomly extracted malicious instruction data are collected to construct an attack task data set for each attack task type.

[0130] and Figure 1 Compared with the embodiment shown in the figure, this embodiment collects malicious instruction data and converts it into a high-dimensional feature vector using an instruction embedding model to capture its semantic information. Cluster analysis is then performed on these data to effectively group malicious instruction data with similar semantic features, thereby identifying different types of attack tasks. At least one malicious instruction data in each attack task type is randomly extracted to form a special attack task data set, which helps to establish various attack scenario models in detail. These data sets can be used to train and test the security of large language models and improve their ability to identify and defend against specific attack types.

[0131] Figure 3 A flowchart for generating a universal word-level adversarial suffix provided in an embodiment of the present application, the method may include the following steps:

[0132] Step S311, determining the gradient of each token in the malicious instruction data.

[0133] Specifically, for each malicious instruction data x in the attack task dataset 1:m , initialize the adversarial suffix, and calculate the gradient of each token after appending the initialized adversarial suffix:

[0134]

[0135] Among them, ⊕ is splicing, L adv is the adversarial loss function (used to evaluate the language model π θOutput y and attack target sequence The difference between j To initialize the adversarial suffix, To attack the target sequence.

[0136] Step S313: According to the gradient, a greedy algorithm is used to determine an initial candidate token set corresponding to the attack task type.

[0137] Specifically, according to the gradient of each token, a greedy search algorithm is used to select the top-k pairs of loss functions L adv The token with the greatest impact forms the initial candidate token set

[0138] Greedy Algorithm:

[0139]

[0140] Step S315, using a first-order gradient approximation method to screen the initial candidate token set to obtain a target candidate token set corresponding to the attack task type.

[0141] Specifically, the first-order gradient approximation method is used to further screen the candidate set To more accurately assess its L adv The final optimized target candidate token set is obtained to ensure that the selected token can effectively improve the attack success rate.

[0142] Step S317, constructing a word-level adversarial suffix set according to the target candidate token set, and performing attack evaluation on the word-level adversarial suffixes in the word-level adversarial suffix set, and determining the common word-level adversarial suffix corresponding to the attack task type according to the attack evaluation result.

[0143] Specifically, a word-level adversarial suffix set constructed through the target candidate token set is used to change the semantics of the original malicious instruction data, and an attack evaluation is performed on the word-level adversarial suffixes therein to determine their effects in the model. Based on the evaluation results, a universal word-level adversarial suffix that is generally applicable in each attack task type is determined to change or interfere with the meaning of the target token or the output generated.

[0144] and Figure 1Compared with the embodiment shown, this embodiment first calculates the gradient of each token for each malicious instruction data, and these gradients reflect the difference between the model output and the attack target sequence. Then, based on the gradient of each token, an initial candidate token set is selected, which has the potential to maximize the impact on the model output to meet the attacker's expected goals. Then, the initial candidate token set is screened using the first-order gradient approximation method to determine the final optimized target candidate token set, thereby improving the attack success rate and making the model output more consistent with the attack target. Finally, a word-level adversarial suffix set is constructed based on the determined target candidate token set, with the aim of changing the semantics of the original malicious instruction data so that it is more likely to cause the model output to be consistent with the attacker's expectations. Each word-level adversarial suffix in the word-level adversarial suffix set is evaluated in detail to ensure its versatility in various attack tasks, thereby obtaining a universal word-level adversarial suffix.

[0145] Figure 4 The flowchart of step S317 provided in the embodiment of the present application may include the following steps:

[0146] Step S3171, randomly extract at least one token from the target candidate token set to construct the word-level adversarial suffix set.

[0147] Specifically, one or more tokens are randomly extracted from the target candidate token set to form a word-level adversarial suffix set. Different random sampling will lead to different attack results, which in turn helps to circumvent the model's defense mechanism, because unpredictable attack methods may not be easily detected or countered by the model.

[0148] Step S3173, performing attack evaluation on the word-level adversarial suffixes in the word-level adversarial suffix set.

[0149] Specifically, the word-level adversarial suffixes are iterated, and the current word-level adversarial suffix in the word-level adversarial suffix set is added. Attach it to the corresponding malicious instruction data to form an adversarial sample, and input the generated adversarial sample into the language model π θ In, get the response and record the language model π θ Whether the response is considered a successful attack is evaluated using the attack success rate ASR, where ASR = number of successful adversarial samples / total number of samples in the validation set. The validation set here is the original attack task dataset divided into data. By evaluating the model performance on the validation set, overfitting can be avoided and the best model parameters can be selected.

[0150] Step S3175: If the attack success rate of the word-level adversarial suffix of the current iteration is greater than the attack success rate of the word-level adversarial suffix of the previous iteration, the word-level adversarial suffix of the current iteration is determined as the current word-level adversarial suffix.

[0151] Specifically, during the iteration, if the adversarial suffix of the current iteration The attack success rate on the validation set is higher than the previous iteration Then update the adversarial suffix to the current iteration version: τ i is the learning rate, which controls the step size of the iterative update; until the attack success rate no longer increases significantly or the maximum number of iterations is reached, the universal adversarial suffix u′ corresponding to the attack task type is finally obtained j .

[0152] Step S3177, until a preset condition is met, the current word-level adversarial suffix is ​​determined as the universal word-level adversarial suffix corresponding to the attack task type.

[0153] Specifically, the adversarial suffix is ​​continuously updated iteratively until the stopping condition is met, such as reaching the maximum number of iterations or the attack success rate is no longer significantly improved, and finally a universal adversarial suffix that can generally improve the attack success rate is solved.

[0154] and Figure 3 Compared with the embodiment shown, this embodiment randomly extracts one or more tokens from the target candidate token set to form a word-level adversarial suffix set. These word-level adversarial suffixes can change the form and content of malicious instruction data in an attempt to circumvent the defense mechanism of the model. Each word-level adversarial suffix is ​​then attached to the malicious instruction data to form an adversarial sample. These adversarial samples are input into the language model, the response of the model is recorded, and an evaluation is made as to whether the attack is successful. If the attack success rate of the word-level adversarial suffix of the current iteration is higher than that of the previous iteration, the word-level adversarial suffix is ​​updated to the version of the current iteration. Continue to iterate and update the word-level adversarial suffix until the preset conditions are met, and finally determine a universal adversarial suffix that can generally improve the attack success rate. This embodiment continuously optimizes and selects word-level adversarial suffixes to improve the attack success rate, making the attack more difficult to detect and confront, thereby achieving the purpose of bypassing the language model defense.

[0155] Figure 5 The flowchart of generating a target word-level adversarial suffix provided in an embodiment of the present application may include the following steps:

[0156] Step S321, based on the common word-level adversarial suffix, a greedy algorithm is used to generate a target word-level adversarial suffix corresponding to the malicious instruction data.

[0157] Specifically, for each malicious instruction data in each attack sample dataset, a universal adversarial suffix u′ is used. j Based on, use the greedy search algorithm to calculate the individual adversarial suffix The goal is to minimize the adversarial function;

[0158]

[0159] Among them, M j is a collection of all malicious instruction data. is the probability distribution of model π given parameter θ,

[0160] To obtain the corresponding target word-level adversarial suffix, refer to the same method of steps S3173-3177, attach each word-level adversarial suffix to the malicious instruction data to form an adversarial sample, and input it into the language model. Record the model's response to each adversarial sample, and evaluate the attack success rate (ASR) of each adversarial suffix. If the attack success rate of a word-level adversarial suffix in the current iteration on the verification set is higher than that of the previous iteration, update the word-level adversarial suffix to the current iteration version. Use the learning rate to control the step size of the update so that the adversarial suffix can be gradually optimized. Continue to iteratively update the adversarial suffix until the stopping condition is met (for example, the maximum number of iterations is reached or the attack success rate is no longer significantly improved). Finally, determine the target word-level adversarial suffix corresponding to each malicious instruction data, that is, the suffix that can most effectively bypass the language model defense.

[0161] and Figure 1 Compared with the embodiment shown, this embodiment generates a customized target word-level adversarial suffix for each malicious instruction data, so that the adversarial sample can more effectively deceive the target language model and improve the success rate of the attack.

[0162] Figure 6 A flowchart of a method for obtaining a target semantic-level adversarial prompt provided in an embodiment of the present application, the method may include the following steps:

[0163] Step S71, determining the initial semantic-level adversarial prompt corresponding to the attack target sequence.

[0164] Specifically, the attacker (strategy provider P) attacks the target sequence according to the malicious Design a set of strategies that guide the attacking agent A to generate target semantic-level adversarial prompts Here It is the inappropriate or malicious output that the attacking agent A hopes the model will generate.

[0165] Step S73: using the initial semantic-level adversarial prompt as input to the first fine-tuning model to generate response data.

[0166] Specifically, the first fine-tuned model receives an initial semantic-level adversarial cue Response data will be generated

[0167] Step S75, determining the jailbreak evaluation score corresponding to the response data.

[0168] Specifically, the judge J evaluates a jailbreak evaluation score based on the response data r, which measures the closeness of the model output to the attack target sequence. The purpose of the judge here is to judge the similarity or gap between the generated response data and the attack target sequence based on historical data and model training. It can be an LLM model or a GPT model. After large-scale text data training, the semantic and logical coherence of the text can be evaluated to calculate the generated response data r and the attack target sequence. The similarity score between .

[0169] Step S77, when the jailbreak evaluation score is less than the preset jailbreak threshold, iteratively optimize the initial semantic-level adversarial prompt until the target semantic-level adversarial prompt is obtained when the jailbreak evaluation score is greater than or equal to the preset jailbreak threshold.

[0170] Specifically, the attacking agent A will perform iterative optimization based on the feedback of the jailbreak evaluation score, adjust the initial semantic-level adversarial prompt currently used, generate new response data r through the next round of iteration, and calculate the jailbreak evaluation score again. This process will continue until the jailbreak evaluation score exceeds the preset jailbreak threshold, ensuring that the generated target semantic-level adversarial prompt is as close as possible to the expected attack target sequence in terms of semantics and form, thereby improving the success rate and effect of the attack.

[0171] and Figure 1 Compared with the embodiment shown in the figure, this embodiment first inputs the initial semantic-level adversarial prompt designed for the attack target sequence into the first fine-tuning model for fine-tuning. The first fine-tuning model generates corresponding output data, which is affected by the initial semantic-level adversarial prompt, and these output data specifically reflect the response of the model to the attack prompt. Next, a jailbreak evaluation is performed based on the generated response data, and the initial semantic-level adversarial prompt is adjusted according to the feedback of the evaluation result until the jailbreak evaluation score of the generated response data reaches the preset jailbreak threshold. Through this method of utilizing semantic-level adversarial prompts and iterative optimization, the probability of a successful attack is effectively improved, so that the generated text can be as close as possible to the expected malicious or misleading target.

[0172] In order to effectively evaluate the effect of the above-mentioned large language model security optimization method of this embodiment, the following data sets will be used for testing. Widely recognized data sets are used, including AdvBench and MaliciousInstruct. AdvBench contains 520 malicious prompts specially designed to induce harmful responses, 90% of which are used for training and the remaining 10% are used for testing. In order to evaluate the extensive defense capabilities of the method of this embodiment against unknown jailbreak attacks, all the data of MaliciousInstruct are used. MaliciousInstruct contains 100 instances of malicious behavior across ten different categories.

[0173] The target models are two open source models: Llama-2 (7B-chat-hf) and Vicuna (13B-v1.5).

[0174] To evaluate the effectiveness of various defense strategies, this test method compares the strongest attack methods, including token-level attacks (such as GCG and AutoDAN) and prompt-level attacks (such as PAIR I7, TAP, and GPTFuzzer). And compares with five most representative baseline methods, including system-level and model-level defense methods. System-level defense methods include Self-Reminder, SmoothLLM, and RPO. Model-level defense methods include adversarial training, disarming learning, and secure training.

[0175] For the evaluation index, the attack success rate (ASR A and ASR p ) to comprehensively evaluate the effectiveness of defense. Among them, ASR p Indicates the match between the response of the LLM and the predefined rejection using the keyword string match, while ASR A The ASR is evaluated by the GPT agent. A and ASR p Lower values ​​indicate better performance.

[0176] In the main experiment, Table 1 shows the defense results of known jailbreak attacks. The defense effect of the method in this embodiment against five attacks under two indicators is always better than other state-of-the-art methods. Specifically, under the two target models, the average ASR caused by jailbreak attacks is A / ASR p The existing defense methods perform poorly, while the method in this embodiment uses the average ASR under the two target models. A / ASR pThe results are reduced to 2.69% / 10.00% and 3.08% / 10.00% respectively. The experimental results highlight the effectiveness of the method in mitigating adversarial prompts, which is significantly better than the current methods. In addition, Self-Reminder performs better on Llama-2-7B than Vicuna-13B, probably because Llama-2-7B uses a stronger security alignment, which can effectively trigger Self-Reminder.

[0177] The robustness of the defense method against unknown jailbreak attacks is a major challenge because there may be a large number of potential cues and changes. Therefore, the MaliciousInstruct dataset is used to evaluate the effectiveness of the method of this embodiment against unknown jailbreak attacks. Table 2 shows the defense results of unknown jailbreak attacks. The defense effect of the method of this embodiment against five different attacks under two indicators is always better than other state-of-the-art methods. Specifically, under the two target models, the average ASR caused by jailbreak attacks is A / ASR p The values ​​are 71.60% / 52.20% and 18.40% / 8.20% respectively. A / ASR p They are reduced to an average of 2.60% / 0.20% and 18.40% / 8.20% respectively, showing significant improvements under two target models and two indicators. In summary, compared with known jailbreaks, unknown jailbreaks show a higher attack success rate under other baseline methods, highlighting the importance of defending against unknown jailbreak attacks.

[0178] Table 1: Known jailbreak attacks

[0179]

[0180]

[0181] Table 2: Unknown jailbreak attacks

[0182]

[0183]

[0184] Accordingly, please refer to Figure 7 , a large language model security optimization device provided by an embodiment of the present application, the terminal includes:

[0185] The data acquisition module 101 is used to acquire an attack task data set; wherein the attack task data set includes at least one attack task type and a plurality of malicious instruction data under the attack task type;

[0186] A word-level adversarial suffix generation module 103, configured to generate a universal word-level adversarial suffix corresponding to the attack task type according to the malicious instruction data, and to generate a target word-level adversarial suffix corresponding to the malicious instruction data according to the universal word-level adversarial suffix;

[0187] A first fine-tuning model generating module 105, configured to perform a first fine-tuning on the large language model based on the target word-level adversarial suffix to obtain a first fine-tuning model;

[0188] The second fine-tuning model generating module 107 is used to perform a second fine-tuning on the first fine-tuning model based on the acquired target semantic-level adversarial prompt to obtain a second fine-tuning model.

[0189] In some optional implementations, the data acquisition module 101 includes:

[0190] A data acquisition unit, used to acquire malicious instruction data;

[0191] A clustering unit, used for clustering the malicious instruction data using a preset instruction embedding model to obtain at least one of the attack task types;

[0192] The data construction unit is used to randomly extract at least one malicious instruction data in each of the attack task types, and construct the attack task data set for each of the attack task types.

[0193] In some optional implementations, generating a universal word-level adversarial suffix corresponding to the attack task type according to the malicious instruction data includes:

[0194] Determine the gradient of each token in the malicious instruction data;

[0195] According to the gradient, a greedy algorithm is used to determine an initial candidate token set corresponding to the attack task type;

[0196] Using a first-order gradient approximation method to screen the initial candidate token set, obtaining a target candidate token set corresponding to the attack task type;

[0197] A word-level adversarial suffix set is constructed according to the target candidate token set, and an attack evaluation is performed on the word-level adversarial suffixes in the word-level adversarial suffix set, and the general word-level adversarial suffix corresponding to the attack task type is determined according to the attack evaluation result.

[0198] In some optional implementations, constructing a word-level adversarial suffix set according to a target candidate token set, performing attack evaluation on the word-level adversarial suffixes in the word-level adversarial suffix set, and determining the common word-level adversarial suffix corresponding to the attack task type according to the attack evaluation result includes:

[0199] Randomly extract at least one token from the target candidate token set to construct the word-level adversarial suffix set;

[0200] Performing attack evaluation on the word-level adversarial suffixes in the word-level adversarial suffix set;

[0201] If the attack success rate of the word-level adversarial suffix of the current iteration is greater than the attack success rate of the word-level adversarial suffix of the previous iteration, the word-level adversarial suffix of the current iteration is determined as the current word-level adversarial suffix;

[0202] Until a preset condition is met, the current word-level adversarial suffix is ​​determined as the universal word-level adversarial suffix corresponding to the attack task type.

[0203] In some optional implementations, generating a target word-level adversarial suffix corresponding to the malicious instruction data according to the universal word-level adversarial suffix includes:

[0204] According to the universal word-level adversarial suffix, a greedy algorithm is used to generate a target word-level adversarial suffix corresponding to the malicious instruction data.

[0205] In some optional implementations, the target semantic-level adversarial prompt is obtained by:

[0206] Determine the initial semantic-level adversarial cue corresponding to the attack target sequence;

[0207] Taking the initial semantic-level adversarial prompt as input to the first fine-tuning model to generate response data;

[0208] Determine a jailbreak assessment score corresponding to the response data;

[0209] When the jailbreak evaluation score is less than a preset jailbreak threshold, the initial semantic-level adversarial prompt is iteratively optimized until the target semantic-level adversarial prompt is obtained when the jailbreak evaluation score is greater than or equal to the preset jailbreak threshold.

[0210] In some optional implementations, the first fine-tuning and / or the second fine-tuning adopts parameter efficient fine-tuning PEFT technology.

[0211] The further functional description of each of the above modules and units is the same as that of the above corresponding embodiments and will not be repeated here.

[0212] The large language model security optimization device in this embodiment is presented in the form of a functional unit, where the unit refers to an ASIC (Application Specific Integrated Circuit) circuit, a processor and memory that executes one or more software or fixed programs, and / or other devices that can provide the above functions.

[0213] See also Figure 8 , Figure 8 A schematic diagram of the structure of a computer device provided in an embodiment of the present application is shown in FIG. Figure 8 As shown, the computer device includes: one or more processors 10, a memory 20, and interfaces for connecting various components, including high-speed interfaces and low-speed interfaces. Various components are connected to each other using different buses for communication, and can be installed on a common mainboard or installed in other ways as needed. The processor can process the instructions executed in the computer device, including instructions stored in or on the memory to display the graphical information of the GUI on an external input / output device (such as, a display device coupled to the interface). In some optional embodiments, if necessary, multiple processors and / or multiple buses can be used together with multiple memories and multiple memories. Similarly, multiple computer devices can be connected, and each device provides some necessary operations (for example, as a server array, a group of blade servers, or a multi-processor system). Figure 8 A processor 10 is taken as an example.

[0214] The processor 10 may be a central processing unit, a network processor or a combination thereof. The processor 10 may further include a hardware chip. The hardware chip may be a dedicated integrated circuit, a programmable logic device or a combination thereof. The programmable logic device may be a complex programmable logic device, a field programmable gate array, a general purpose array logic or any combination thereof.

[0215] The memory 20 stores instructions executable by at least one processor 10, so that the at least one processor 10 executes the method shown in the above embodiment.

[0216] The memory 20 may include a program storage area and a data storage area, wherein the program storage area may store an operating system, an application required for at least one function; the data storage area may store data created according to the use of the computer device, etc. In addition, the memory 20 may include a high-speed random access memory, and may also include a non-transient memory, such as at least one disk storage device, a flash memory device, or other non-transient solid-state storage device. In some optional embodiments, the memory 20 may optionally include a memory remotely arranged relative to the processor 10, and these remote memories may be connected to the computer device via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.

[0217] The memory 20 may include a volatile memory, such as a random access memory; the memory may also include a non-volatile memory, such as a flash memory, a hard disk or a solid state drive; the memory 20 may also include a combination of the above types of memory.

[0218] The computer device further comprises a communication interface 30 for the computer device to communicate with other devices or a communication network.

[0219] The embodiment of the present application also provides a computer-readable storage medium. The above method according to the embodiment of the present application can be implemented in hardware, firmware, or can be implemented as a computer code that can be recorded in a storage medium, or can be implemented as a computer code that is originally stored in a remote storage medium or a non-temporary machine-readable storage medium and will be stored in a local storage medium through a network download, so that the method described herein can be stored in such software processing on a storage medium using a general-purpose computer, a dedicated processor, or programmable or dedicated hardware. Among them, the storage medium can be a magnetic disk, an optical disk, a read-only storage memory, a random access memory, a flash memory, a hard disk or a solid-state hard disk, etc.; further, the storage medium can also include a combination of the above types of memories. It can be understood that a computer, a processor, a microprocessor controller, or programmable hardware includes a storage component that can store or receive software or computer code. When the software or computer code is accessed and executed by a computer, a processor, or hardware, the method shown in the above embodiment is implemented.

[0220] The devices, modules or units described in the above embodiments may be implemented by computer chips or entities, or by products with certain functions. A typical implementation device is a computer. Specifically, the computer may be, for example, a personal computer, a laptop computer, a cellular phone, a camera phone, a smart phone, a personal digital assistant, a media player, a navigation device, an email device, a game console, a tablet computer, a wearable device, or a combination of any of these devices.

[0221] For the convenience of description, the above device is described in various units according to their functions. Of course, when implementing the present application, the functions of each unit can be implemented in the same or multiple software and / or hardware.

[0222] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, devices, or equipment. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment in combination with software and hardware. Moreover, the present application may adopt the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that contain computer-usable program code.

[0223] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and apparatuses according to the embodiments of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.

[0224] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.

[0225] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.

[0226] It should also be noted that the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, commodity or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, commodity or device. In the absence of more restrictions, the elements defined by the sentence "comprises a ..." do not exclude the existence of other identical elements in the process, method, commodity or device including the elements.

[0227] Each embodiment in this specification is described in a progressive manner, and the same or similar parts between the embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the device semantics embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.

[0228] The above is only an embodiment of the present application and is not intended to limit the present application. For those skilled in the art, the present application may have various changes and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application should be included in the scope of the claims of the present application.

[0229] Although the embodiments of the present application have been described in conjunction with the accompanying drawings, those skilled in the art may make various modifications and variations without departing from the spirit and scope of the present application, and such modifications and variations are all within the scope defined by the appended claims.

Claims

1. A large language model security optimization method, It is characterized in that The method comprises: Acquire an attack task data set; wherein the attack task data set includes at least one attack task type and a plurality of malicious instruction data under the attack task type; Generate a universal word-level adversarial suffix corresponding to the attack task type according to the malicious instruction data, and generate a target word-level adversarial suffix corresponding to the malicious instruction data according to the universal word-level adversarial suffix; Performing a first fine-tuning on the large language model based on the target word-level adversarial suffix to obtain a first fine-tuning model; The first fine-tuning model is fine-tuned for a second time based on the acquired target semantic-level adversarial prompt to obtain a second fine-tuning model.

2. The method according to claim 1, It is characterized in that The acquiring of an attack task data set; wherein the attack task data set includes at least one attack task type and a plurality of malicious instruction data under the attack task type, including: Obtain malicious instruction data; Clustering the malicious instruction data using a preset instruction embedding model to obtain at least one of the attack task types; At least one malicious instruction data in each of the attack task types is randomly extracted to construct the attack task data set for each of the attack task types.

3. The method according to claim 1, It is characterized in that The step of generating a universal word-level adversarial suffix corresponding to the attack task type according to the malicious instruction data includes: Determine the gradient of each token in the malicious instruction data; According to the gradient, a greedy algorithm is used to determine an initial candidate token set corresponding to the attack task type; Using a first-order gradient approximation method to screen the initial candidate token set, obtaining a target candidate token set corresponding to the attack task type; A word-level adversarial suffix set is constructed according to the target candidate token set, and an attack evaluation is performed on the word-level adversarial suffixes in the word-level adversarial suffix set, and the general word-level adversarial suffix corresponding to the attack task type is determined according to the attack evaluation result.

4. The method according to claim 3, It is characterized in that The step of constructing a word-level adversarial suffix set according to the target candidate token set, performing attack evaluation on the word-level adversarial suffixes in the word-level adversarial suffix set, and determining the common word-level adversarial suffix corresponding to the attack task type according to the attack evaluation result includes: Randomly extract at least one token from the target candidate token set to construct the word-level adversarial suffix set; Performing attack evaluation on the word-level adversarial suffixes in the word-level adversarial suffix set; If the attack success rate of the word-level adversarial suffix of the current iteration is greater than the attack success rate of the word-level adversarial suffix of the previous iteration, the word-level adversarial suffix of the current iteration is determined as the current word-level adversarial suffix; Until a preset condition is met, the current word-level adversarial suffix is ​​determined as the universal word-level adversarial suffix corresponding to the attack task type.

5. The method according to claim 1, It is characterized in that The step of generating a target word-level adversarial suffix corresponding to the malicious instruction data according to the universal word-level adversarial suffix comprises: According to the universal word-level adversarial suffix, a greedy algorithm is used to generate a target word-level adversarial suffix corresponding to the malicious instruction data.

6. The method according to claim 1, It is characterized in that The method of obtaining the target semantic level adversarial prompt includes: Determine the initial semantic-level adversarial cue corresponding to the attack target sequence; Using the initial semantic-level adversarial prompt as an input to the first fine-tuning model to generate response data; Determine a jailbreak assessment score corresponding to the response data; When the jailbreak evaluation score is less than a preset jailbreak threshold, the initial semantic-level adversarial prompt is iteratively optimized until the target semantic-level adversarial prompt is obtained when the jailbreak evaluation score is greater than or equal to the preset jailbreak threshold.

7. The method according to claim 1, It is characterized in that The first fine-tuning and / or the second fine-tuning adopts parameter efficient fine-tuning PEFT technology.

8. A large language model security optimization device, It is characterized in that The device comprises: A data acquisition module, used to acquire an attack task data set; wherein the attack task data set includes at least one attack task type and a plurality of malicious instruction data under the attack task type; A word-level adversarial suffix generation module, used to generate a universal word-level adversarial suffix corresponding to the attack task type according to the malicious instruction data, and to generate a target word-level adversarial suffix corresponding to the malicious instruction data according to the universal word-level adversarial suffix; A first fine-tuning model generating module, configured to perform a first fine-tuning on the large language model based on the target word-level adversarial suffix to obtain a first fine-tuning model; The second fine-tuning model generation module is used to perform a second fine-tuning on the first fine-tuning model based on the acquired target semantic-level adversarial prompt to obtain a second fine-tuning model.

9. A computer device, It is characterized in that include: A memory and a processor, wherein the memory and the processor are communicatively connected to each other, the memory stores computer instructions, and the processor executes the large language model security optimization method according to any one of claims 1 to 7 by executing the computer instructions.

10. A computer-readable storage medium, It is characterized in that The computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a computer to execute the large language model security optimization method according to any one of claims 1 to 7.

Citation Information

Patent Citations

  • Defense method for adversarial training based on part-of-speech fusion in Chinese text

    CN114861654A

  • Prison break attack instruction data generation method and device, medium and equipment

    CN117131513A

  • Anti-attack sample generation method and apparatus, and electronic device

    CN117808095A

  • Large language model-oriented black box adversarial sample generation method

    CN117993384A

  • Large language model security test method and device based on tabu search algorithm

    CN118132748A

Cited By

  • Intelligent agent assistant attack defense method based on output response and related device

    CN120165967A

  • Agent assistant attack defense method based on output response and related device

    CN120165967B

  • Detection method and system for security protection mechanism of large language model

    CN120316781A

  • Security defense method and device for large business model

    CN120316828A

  • Method and apparatus for security defense of business large model

    CN120316828B