Method, device and storage medium for improving model security
By constructing a secure corpus and performing low-rank adapter LoRa fine-tuning training, the problem of the inability to update the security of large models in real time was solved, achieving efficient and low-cost model security improvement.
Patent Information
- Application Number
- CN202410287402.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-03-13
- Publication Date
- 2026-11-06
- Estimated Expiration
- 2044-03-13
AI Technical Summary
The security and compliance of existing large models are fixed after training, and they cannot be updated in real time. Retraining is costly and time-consuming.
A secure corpus is constructed, and a pre-trained large language model is fine-tuned using a low-rank adapter (Lora) to obtain the target Lora weights, which are then merged into the model to be processed, thereby improving security.
It eliminates the need for repeated pre-training and fine-tuning, rapidly improving model safety, reducing training costs, and ensuring that the model outputs compliant text content.
Smart Images

Figure CN118349643B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of natural language processing technology, and in particular to a method, apparatus and storage medium for improving model security. Background Technology
[0002] Once a large model is trained, its weight parameters are fixed. To improve the model's safety, further pre-training or fine-tuning is required, which is extremely costly.
[0003] Currently, once a large model is trained, its security and compliance are fixed and cannot be updated in real time. Improving model security through retraining is too costly and time-consuming. Summary of the Invention
[0004] This application provides a method, apparatus, and storage medium for improving model security, thereby addressing the technical problem of high training costs in improving the security of large models in the prior art.
[0005] In a first aspect, embodiments of this application provide a method for improving model security, including:
[0006] Build a security corpus;
[0007] Based on the aforementioned secure corpus, a low-rank adapter Lora fine-tuning training is performed on the pre-trained large language model to obtain the target Lora weights.
[0008] The target LoRa weights are merged into the model to be processed; the model to be processed refers to a large language model of the same type, scale and parameter quantity as the pre-trained large language model, whose security needs to be improved.
[0009] In some embodiments, the construction of the security corpus includes:
[0010] Collect security corpora;
[0011] The security corpus is cleaned.
[0012] A security corpus is obtained based on the cleaned security corpus.
[0013] In some embodiments, obtaining a security corpus based on cleaned security corpus includes:
[0014] The cleaned security corpus is expanded using sentence continuation and / or noun question-and-answer methods to obtain a security corpus.
[0015] In some embodiments, the step of performing low-rank adapter LoRa fine-tuning training on the pre-trained large language model based on the secure corpus to obtain the target LoRa weights includes:
[0016] Embed a low-rank adapter in any layer of a pre-trained large language model;
[0017] The corpus in the secure corpus is input into the pre-trained large language model, the pre-training weights of the pre-trained large language model are fixed, and the low-rank matrix is trained.
[0018] The trained low-rank matrix is used as the target Lora weight.
[0019] In some embodiments, incorporating the target Lora weights into the model to be processed includes:
[0020] The target Lora weights are merged with the original weights of the model to be processed.
[0021] In some embodiments, the pre-trained large language model is the Qianwen 14B large model.
[0022] Secondly, embodiments of this application provide an apparatus for improving model security, comprising:
[0023] The first acquisition module is used to build a security corpus;
[0024] The second acquisition module is used to perform low-rank adapter Lora fine-tuning training on the pre-trained large language model based on the secure corpus to obtain the target Lora weights.
[0025] The merging module merges the target LoRa weights into the model to be processed; the model to be processed refers to a large language model of the same type, scale, and parameter quantity as the pre-trained large language model, whose security needs to be improved.
[0026] In some embodiments, the first acquisition module includes:
[0027] The data collection unit is used to collect security corpora.
[0028] A data cleaning unit is used to clean the secure corpus.
[0029] The acquisition unit is used to acquire a security corpus based on the cleaned security corpus.
[0030] In some embodiments, the acquisition unit includes:
[0031] An extension subunit is used to extend the cleaned security corpus using sentence continuation and / or noun question-and-answer methods to obtain a security corpus.
[0032] In some embodiments, the second acquisition module includes:
[0033] Embedding units are used to embed low-rank adapters in any layer of a pre-trained large language model.
[0034] The training unit is used to input the corpus in the secure corpus into the pre-trained large language model, fix the pre-training weights of the pre-trained large language model, and train the low-rank matrix.
[0035] Define the unit, which is used to use the trained low-rank matrix as the target Lora weight.
[0036] In some embodiments, the merging module includes:
[0037] The merging unit is used to merge the target Lora weights with the original weights of the model to be processed.
[0038] Thirdly, embodiments of this application provide an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the program to implement the method for improving model security as described in the first aspect above.
[0039] Fourthly, embodiments of this application also provide a non-transitory computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the method for improving model security as described in the first aspect above.
[0040] Fifthly, embodiments of this application also provide a computer program product, including a computer program that, when executed by a processor, implements the method for improving model security as described in the first aspect above.
[0041] The method, apparatus, and storage medium for improving model security provided in this application embodiment construct a secure corpus, perform low-rank adapter LoRa fine-tuning training on a pre-trained large language model based on the secure corpus to obtain target LoRa weights, and then merge the target LoRa weights into a model to be processed that is of the same type, scale, and parameter quantity as the pre-trained large language model. This enables the model to infer more secure text content without having to repeat pre-training and fine-tuning of the large model, thereby achieving the goal of efficiently improving model security and reducing training costs. Attached Figure Description
[0042] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0043] Figure 1 This is a flowchart illustrating the method for improving model security provided in an embodiment of this application;
[0044] Figure 2 This is a schematic diagram of the Lora fine-tuning process provided in the embodiments of this application;
[0045] Figure 3 This is a schematic diagram of a device for improving model safety provided in an embodiment of this application;
[0046] Figure 4 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Detailed Implementation
[0047] Based on the aforementioned technical problems, this application proposes a method to improve model security. This method involves constructing a secure corpus, fine-tuning a pre-trained large language model using a low-rank adapter (Lora) based on this corpus to obtain target Lora weights, and then merging these target Lora weights into a model to be processed that is of the same type, scale, and parameter quantity as the pre-trained large language model. This rapidly achieves style transfer, enabling the model to infer more secure text content without requiring repeated pre-training and fine-tuning of the large model. This achieves the goal of efficiently improving model security and reducing training costs.
[0048] To make the objectives, technical solutions, and advantages of the embodiments of this application clearer, the technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0049] Figure 1 This is a flowchart illustrating the method for improving model security provided in an embodiment of this application, as shown below. Figure 1 As shown in the embodiments of this application, a method for improving model security is provided. The method includes:
[0050] Step 101: Construct a secure corpus.
[0051] Specifically, a security corpus is composed of collected security data, or is an extension of collected security data, and is used as a training corpus to train large language models. Security data refers to sensitive statements that conform to regulations, collected from various sources or platforms.
[0052] Step 102: Based on the secure corpus, perform low-rank adapter LoRa fine-tuning training on the pre-trained large language model to obtain the target LoRa weights.
[0053] Specifically, a low-rank adapter (Lora) fine-tuning training is performed on a pre-trained large language model based on a secure corpus. This involves inputting the corpus from the secure corpus into the pre-trained large language model and using the Lora method to fine-tune the model, thereby obtaining the fine-tuned Lora weights, which are the target Lora weights.
[0054] For example, a low-rank adapter can be embedded in a pre-trained large language model. During training, the pre-trained weights are fixed, and only the low-rank matrix is trained. When saving the weights, only the weights corresponding to the low-rank matrix are saved, thus obtaining the target LoRa weights.
[0055] Step 103: Merge the target LoRa weights into the model to be processed; the model to be processed refers to a large language model of the same type, scale and parameter quantity as the pre-trained large language model, whose security needs to be improved.
[0056] Specifically, in the embodiments of this application, the model to be processed is a large language model for which the model security needs to be improved, and the model to be processed is of the same type, scale and parameter quantity as the pre-trained large language model. Only on this basis can the weights of the pre-trained large language model be successfully merged into the model to be processed.
[0057] After obtaining the target LoRa weights through LoRa fine-tuning training, the target LoRa weights are merged into the processing model that is of the same type, scale, and parameter quantity as the pre-trained large language model. This enables the merged processing model to infer text content with higher security, improves the inference security of the processing model, and prevents the processing model from outputting content that does not conform to the specifications.
[0058] The method for improving model security provided in this application embodiment constructs a secure corpus, performs low-rank adapter LoRa fine-tuning training on a pre-trained large language model based on the secure corpus to obtain target LoRa weights, and then merges the target LoRa weights into a model to be processed that is of the same type, scale, and parameter quantity as the pre-trained large language model. This quickly achieves style transfer, enabling the model to infer more secure text content without the need for repeated pre-training and fine-tuning of the large model. This achieves the goal of efficiently improving model security and reduces training costs.
[0059] In some embodiments, the construction of the security corpus includes:
[0060] Collect security corpora;
[0061] The security corpus is cleaned.
[0062] A security corpus is obtained based on the cleaned security corpus.
[0063] Specifically, a large amount of security corpus is first collected from regulated platforms or websites through various means. Then, the collected security corpus is cleaned and a security corpus is built based on the cleaned security corpus.
[0064] For example, the cleaned security corpus can be expanded, and the expanded security corpus can be used together with the cleaned security corpus to form a security corpus.
[0065] The method for improving model security provided in this application preprocesses the collected security corpus by performing data cleaning and other preprocessing to remove erroneous and irrelevant content, thereby obtaining a more accurate security corpus and improving the accuracy of model training.
[0066] In some embodiments, obtaining a security corpus based on cleaned security corpus includes:
[0067] The cleaned security corpus is expanded using sentence continuation and / or noun question-and-answer methods to obtain a security corpus.
[0068] Specifically, the cleaned security corpus can be expanded using a sentence continuation method to obtain a security corpus.
[0069] For example, continue writing the cleaned security corpus using the following statements:
[0070]
[0071] The cleaned security corpus can also be expanded using a question-and-answer format to obtain a security corpus.
[0072] For example, the security corpus can be expanded by constructing question-and-answer structures using the following statements:
[0073]
[0074] The method for improving model security provided in this application constructs a secure corpus through methods such as continuation writing and / or noun question answering, and flexibly expands the collected secure corpus to obtain a more complete secure corpus, thereby improving the training accuracy of large models and ensuring the security of model inference.
[0075] In some embodiments, the step of performing low-rank adapter LoRa fine-tuning training on the pre-trained large language model based on the secure corpus to obtain the target LoRa weights includes:
[0076] Embed a low-rank adapter in any layer of a pre-trained large language model;
[0077] The corpus in the secure corpus is input into the pre-trained large language model, the pre-training weights of the pre-trained large language model are fixed, and the low-rank matrix is trained.
[0078] The trained low-rank matrix is used as the target Lora weight.
[0079] Specifically, the pre-trained large language model can be the Qianwen 14B large model or other large language models.
[0080] Low-rank adapters can be embedded in any layer of the pre-trained large language model, such as in Embedding, Attention, MLP, or other network layers. The corpus from the secure corpus is input into the pre-trained large language model, and fine-tuning is performed using the LoRa method.
[0081] Figure 2 This is a schematic diagram of the LoRa fine-tuning process provided in the embodiments of this application, as shown below. Figure 2 As shown in Figure (a), under full parameter fine-tuning, if the input is x and the output is h, then the output h can be expressed as:
[0082] h=Wx+ΔWx
[0083] Where W∈R d×d , where represents the pre-trained weights, and d×d represents the dimension of the pre-trained weights; ΔW∈R d×d , represents fine-tuning the incremental weight; x represents the input; h represents the output.
[0084] like Figure 2 As shown in Figure (b), the output h under Lora fine-tuning can be expressed as:
[0085] h = Wx + BAx
[0086] Where W represents the pre-trained weights; A∈R r*d Let A be a low-rank matrix, where r is the rank, and let A be Gaussian initialized; B∈R d*r , is a low-rank matrix, and the low-rank matrix B is initialized with zero; x represents the input; h represents the output.
[0087] The input will be input = [v1, v2, ..., v n (n is the number of words after input segmentation) is fed into the model, i.e., the entire model input is model_input = input. The intermediate hidden states obtained from the input to the large model are [h1, h2, ..., h...]. n ],
[0088]
[0089] in, This represents the t-th intermediate hidden state of the nth word; GPT() indicates that natural language processing is performed using a Generative Pre-trained Transformer (GPT); h n-1 This represents the intermediate hidden state of the (n-1)th word; LORA() represents the Lora fine-tuning operation.
[0090] Then, the intermediate hidden states are mapped to a probability distribution logits on the vocabulary after passing through a multilayer perceptron (MLP), and logits can be expressed as:
[0091]
[0092] Where MLP() represents the multilayer perceptron algorithm; vocab_size represents the size mapped to the vocabulary; p i This represents the probability of mapping to the i-th word in the vocabulary, where i ranges from 1 to vocab_size.
[0093] The probability distribution logits is normalized by the exponential function softmax, and the word with the highest probability is output as the next character. The next character can be represented as:
[0094] pred_label = softmax(logits)
[0095] Here, pred_label represents the word with the highest probability; softmax() represents the normalization exponential function.
[0096] During training, the pre-trained weights W are fixed, and training is only performed on the low-rank matrices A and B. When saving the weights, only the low-rank matrices are saved, and the saved low-rank matrices A and B are used as the target LoRa weights.
[0097] The method for improving model security provided in this application combines a secure corpus with a general fine-tuning instruction set, uses a low-rank adapter to train a pre-trained large language model, and rationally configures the parameters of the low-rank adapter to reduce memory requirements while meeting performance requirements. The low-rank adapter weights are stored separately, enabling the model to iterate rapidly with the large model and quickly achieve style transfer. This allows the large model to infer text content with higher security, achieving the goal of efficiently improving model security and reducing training costs.
[0098] In some embodiments, incorporating the target Lora weights into the model to be processed includes:
[0099] The target Lora weights are merged with the original weights of the model to be processed.
[0100] Specifically, for large models (i.e., models to be processed) of the same type, size, and number of parameters that require improved security, the saved LoRa weights can be used to merge them using the following formula:
[0101]
[0102] Where W′ represents the new weights of the merged model to be processed; W represents the original weights of the model to be processed; A and B represent the low-rank matrices obtained after fine-tuning training, i.e., the saved target Lora weights; α is a hyperparameter; and r is the rank.
[0103] In Natural-Language Generation (NLG) tasks, the hyperparameters α and r are typically set to 32 and 4, respectively.
[0104] When the pre-trained large language model is the (general meaning) Qianwen 14B large model, the target Lora weights obtained by training the pre-trained large language model can be merged into other Qianwen 14B large models that need to improve security, and then normal inference can be performed to improve the inference security of the large model.
[0105] Table 1 shows the hyperparameters of the Tongyi 14B large model. As shown in Table 1, the hyperparameters include n_layers (number of layers), n_heads (number of self-attention heads), d_model (dimension), vocab size (vocabulary size), and sequencelength (sequence length).
[0106] Table 1. Hyperparameters of the General 1000 Questions 14B Model
[0107]
[0108]
[0109] Table 2 shows the recommended parameters for LoRa weight training on the attention layer. As shown in Table 2, when training LoRa weights on the attention layer, the weights are fixed (or frozen) in the MLP layer. When different weights are fixed (including W...), the parameters are adjusted accordingly. q W k W v W o When taking different parameters, the Lora rank is used.
[0110] Table 2 Recommended parameters for training LoRa weights on the attention layer
[0111] Lora rank MLP layer r=1 <![CDATA[W q ,IN v ]]> r=2 <![CDATA[W q ,IN k ,IN v ,IN o ]]> r=4 <![CDATA[W q ,IN k ,IN v ,IN o ]]> r=8 <![CDATA[W q ,IN k ,IN v ,IN o ]]> r=64 <![CDATA[W q ,IN v ]]>
[0112] The method for improving model security provided in this application integrates the target LoRa weights obtained after fine-tuning training with the original weights of the model to be processed. This achieves the goal of efficiently improving model security without retraining the model, shortens the cycle of improving the security of large models, quickly responds to needs, and reduces the cost of improving the security of large models.
[0113] Figure 3 This is a schematic diagram of a device for improving model safety provided in an embodiment of this application, as shown below. Figure 3 As shown in the figure, this application provides an apparatus for improving model security, including a first acquisition module 301, a second acquisition module 302, and a merging module 303.
[0114] The first acquisition module 301 is used to construct a secure corpus.
[0115] The second acquisition module 302 is used to perform low-rank adapter Lora fine-tuning training on the pre-trained large language model based on the secure corpus to obtain the target Lora weights.
[0116] The merging module 303 merges the target LoRa weights into the model to be processed; the model to be processed refers to a large language model of the same type, scale and parameter quantity as the pre-trained large language model, whose security needs to be improved.
[0117] In some embodiments, the first acquisition module includes:
[0118] The data collection unit is used to collect security corpora.
[0119] A data cleaning unit is used to clean the secure corpus.
[0120] The acquisition unit is used to acquire a security corpus based on the cleaned security corpus.
[0121] In some embodiments, the acquisition unit includes:
[0122] An extension subunit is used to extend the cleaned security corpus using sentence continuation and / or noun question-and-answer methods to obtain a security corpus.
[0123] In some embodiments, the second acquisition module includes:
[0124] Embedding units are used to embed low-rank adapters in any layer of a pre-trained large language model.
[0125] The training unit is used to input the corpus in the secure corpus into the pre-trained large language model, fix the pre-training weights of the pre-trained large language model, and train the low-rank matrix.
[0126] Define the unit, which is used to use the trained low-rank matrix as the target Lora weight.
[0127] In some embodiments, the merging module includes:
[0128] The merging unit is used to merge the target Lora weights with the original weights of the model to be processed.
[0129] In some embodiments, the pre-trained large language model is the Qianwen 14B large model.
[0130] Specifically, the apparatus for improving model security provided in this application embodiment can implement all the method steps implemented in the above-mentioned method embodiment for improving model security, and can achieve the same technical effect. Here, the parts that are the same as those in the method embodiment and the beneficial effects will not be described in detail.
[0131] It should be noted that the division of units / modules in the above embodiments of this application is illustrative and only represents one logical functional division. In actual implementation, other division methods may be used. Furthermore, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated units described above can be implemented in hardware or as software functional units.
[0132] Figure 4 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application, such as... Figure 4 As shown, the electronic device may include: a processor 401, a communication interface 402, a memory 403, and a communication bus 404, wherein the processor 401, the communication interface 402, and the memory 403 communicate with each other via the communication bus 404. The processor 401 can call logical instructions in the memory 403 to execute a method for improving model security, the method including:
[0133] Build a security corpus;
[0134] Based on the aforementioned secure corpus, a low-rank adapter Lora fine-tuning training is performed on the pre-trained large language model to obtain the target Lora weights.
[0135] The target LoRa weights are merged into the model to be processed; the model to be processed refers to a large language model of the same type, scale and parameter quantity as the pre-trained large language model, whose security needs to be improved.
[0136] In some embodiments, the construction of the security corpus includes:
[0137] Collect security corpora;
[0138] The security corpus is cleaned.
[0139] A security corpus is obtained based on the cleaned security corpus.
[0140] In some embodiments, obtaining a security corpus based on cleaned security corpus includes:
[0141] The cleaned security corpus is expanded using sentence continuation and / or noun question-and-answer methods to obtain a security corpus.
[0142] In some embodiments, the step of performing low-rank adapter LoRa fine-tuning training on the pre-trained large language model based on the secure corpus to obtain the target LoRa weights includes:
[0143] Embed a low-rank adapter in any layer of a pre-trained large language model;
[0144] The corpus in the secure corpus is input into the pre-trained large language model, the pre-training weights of the pre-trained large language model are fixed, and the low-rank matrix is trained.
[0145] The trained low-rank matrix is used as the target Lora weight.
[0146] In some embodiments, incorporating the target Lora weights into the model to be processed includes:
[0147] The target Lora weights are merged with the original weights of the model to be processed.
[0148] In some embodiments, the pre-trained large language model is the Qianwen 14B large model.
[0149] Specifically, the processor 401 can be a central processing unit (CPU), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA), or a complex programmable logic device (CPLD). The processor can also adopt a multi-core architecture.
[0150] When the logical instructions in memory 403 can be implemented as software functional units and sold or used as independent products, they can be stored in a processor-readable storage medium. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) or processor to execute all or part of the steps of the methods described in the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0151] In some embodiments, a computer program product is also provided, the computer program product including a computer program that can be stored on a non-transitory computer-readable storage medium, and when the computer program is executed by a processor, the computer is able to perform the method for improving model security provided in the above-described method embodiments, the method including:
[0152] Build a security corpus;
[0153] Based on the aforementioned secure corpus, a low-rank adapter Lora fine-tuning training is performed on the pre-trained large language model to obtain the target Lora weights.
[0154] The target LoRa weights are merged into the model to be processed; the model to be processed refers to a large language model of the same type, scale and parameter quantity as the pre-trained large language model, whose security needs to be improved.
[0155] Specifically, the computer program product provided in this application embodiment can implement all the method steps implemented in the above method embodiments and can achieve the same technical effect. Here, the parts that are the same as those in the method embodiments and the beneficial effects will not be described in detail.
[0156] In some embodiments, a computer-readable storage medium is also provided, the computer-readable storage medium storing a computer program, the computer program being used to cause a computer to execute the method for improving model security provided in the above method embodiments, the method comprising:
[0157] Build a security corpus;
[0158] Based on the aforementioned secure corpus, a low-rank adapter Lora fine-tuning training is performed on the pre-trained large language model to obtain the target Lora weights.
[0159] The target LoRa weights are merged into the model to be processed; the model to be processed refers to a large language model of the same type, scale and parameter quantity as the pre-trained large language model, whose security needs to be improved.
[0160] Specifically, the computer-readable storage medium provided in the embodiments of this application can implement all the method steps implemented in the above method embodiments and can achieve the same technical effect. Here, the parts that are the same as those in the method embodiments and the beneficial effects will not be described in detail.
[0161] It should be noted that the computer-readable storage medium can be any available medium or data storage device that the processor can access, including but not limited to magnetic storage (e.g., floppy disk, hard disk, magnetic tape, magneto-optical disk (MO)), optical storage (e.g., CD, DVD, BD, HVD), and semiconductor storage (e.g., ROM, EPROM, EEPROM, non-volatile memory (NAND FLASH), solid-state drive (SSD)).
[0162] It should also be noted that the terms "first," "second," etc., used in the embodiments of this application are used to distinguish similar objects, and are not used to describe a specific order or sequence. It should be understood that such terms can be used interchangeably where appropriate so that embodiments of this application can be implemented in orders other than those illustrated or described herein, and the objects distinguished by "first" and "second" are generally of the same class, and the number of objects is not limited. For example, the first object can be one or more.
[0163] In the embodiments of this application, the term "and / or" describes the relationship between associated objects, indicating that three relationships can exist. For example, A and / or B can represent three cases: A alone, A and B simultaneously, and B alone. The character " / " generally indicates that the preceding and following associated objects have an "or" relationship.
[0164] In this application, "determining B based on A" means that factor A must be considered when determining B. It is not limited to "B can be determined based solely on A," but should also include: "determining B based on A and C," "determining B based on A, C, and E," "determining C based on A, and further determining B based on C," etc. It can also include using A as a condition for determining B, for example, "when A satisfies the first condition, B is determined using the first method"; or "when A satisfies the second condition, B is determined," or "when A satisfies the third condition, B is determined based on the first parameter," etc. Of course, it can also be a condition where A is a factor in determining B, for example, "when A satisfies the first condition, C is determined using the first method, and B is further determined based on C," etc.
[0165] Those skilled in the art will understand that embodiments of this application can be provided as methods, systems, or computer program products. Therefore, this application can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, this application can take the form of a computer program product implemented on one or more computer-usable storage media (including, but not limited to, disk storage and optical storage) containing computer-usable program code.
[0166] This application is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of this application. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer-executable instructions. These computer-executable instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart... Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.
[0167] These processor-executable instructions may also be stored in a processor-readable memory that can direct a computer or other programmable data processing device to operate in a particular manner, such that the instructions stored in the processor-readable memory produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1The function specified in one or more boxes.
[0168] These processors can execute instructions that can also be loaded onto a computer or other programmable data processing device, causing a series of operational steps to be performed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable device for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.
[0169] Obviously, those skilled in the art can make various modifications and variations to this application without departing from the spirit and scope of this application. Therefore, if such modifications and variations fall within the scope of the claims of this application and their equivalents, this application also intends to include such modifications and variations.
Claims
1. A method for improving model security, characterized in that, include: A security corpus is constructed, which is obtained by expanding the cleaned security corpus using sentence continuation and / or noun question-and-answer methods; Based on the aforementioned secure corpus, a low-rank adapter Lora fine-tuning training is performed on the pre-trained large language model to obtain the target Lora weights. The corpus in the secure corpus is mixed with a general fine-tuning instruction set, and a pre-trained large language model is trained using a low-rank adapter Lora fine-tuning to obtain the target Lora weights; Lora weights are trained on the attention layer, and the weights are fixed or frozen on the MLP layer. When different weights are fixed, different parameters Lora rank are taken. The target LoRa weights are merged into the model to be processed; the model to be processed refers to a large language model of the same type, scale, and parameter quantity as the pre-trained large language model, whose security needs to be improved. The saved LoRa weights are merged using the following formula: ; in, This represents the new weights of the models to be processed after merging; A represents the original weights of the model to be processed; A and B represent the low-rank matrices obtained after fine-tuning training, i.e., the saved target Lora weights. For hyperparameters; For rank.
2. The method for improving model security according to claim 1, characterized in that, The construction of the security corpus includes: Collect security corpora; The security corpus is cleaned. Obtain a security corpus based on the cleaned security corpus.
3. The method for improving model security according to claim 1, characterized in that, The step of fine-tuning the pre-trained large language model using a low-rank adapter (LoRa) based on the secure corpus to obtain the target LoRa weights includes: Embed a low-rank adapter in any layer of a pre-trained large language model; The corpus in the secure corpus is input into the pre-trained large language model, the pre-training weights of the pre-trained large language model are fixed, and the low-rank matrix is trained. The trained low-rank matrix is used as the target Lora weight.
4. The method for improving model security according to claim 1, characterized in that, The step of merging the target LoRa weights into the model to be processed includes: The target Lora weights are merged with the original weights of the model to be processed.
5. The method for improving model security according to claim 1, characterized in that, The pre-trained large language model is the 1000 Questions 14B large model.
6. An apparatus for improving model security, employing the method for improving model security as described in claim 1, characterized in that, include: The first acquisition module is used to build a security corpus; The second acquisition module is used to perform low-rank adapter Lora fine-tuning training on the pre-trained large language model based on the secure corpus to obtain the target Lora weights. The merging module is used to merge the target LoRa weights into the model to be processed; the model to be processed refers to a large language model of the same type, scale and parameter quantity as the pre-trained large language model, whose security needs to be improved.
7. The apparatus for improving model safety according to claim 6, characterized in that, The first acquisition module includes: The data collection unit is used to collect security corpora. A data cleaning unit is used to clean the secure corpus. The acquisition unit is used to acquire a security corpus based on the cleaned security corpus.
8. An electronic device comprising a memory, a processor, and a computer program stored in the memory and running on the processor, characterized in that, When the processor executes the program, it implements the method for improving model security as described in any one of claims 1 to 5.
9. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the method for improving model security as described in any one of claims 1 to 5.
Citation Information
Patent Citations
Sensitive word auditing method based on large language model, storage medium and electronic equipment
CN116720515A
Multi-field fine-tuning large model parallel reasoning system and method thereof
CN117474102A
