Fine adjustment method and device of text self-checking model, storage medium and equipment
By reducing the dimensionality and adjusting the parameters of a specified network layer in the text self-inspection model, the problems of storage resources and computational complexity caused by the large number of model parameters are solved, enabling efficient identification and processing of sensitive content generated by large language models, and reducing the storage and computational burden of model fine-tuning.
Patent Information
- Application Number
- CN202411034282.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-29
- Publication Date
- 2024-11-22
AI Technical Summary
Existing text self-checking models have a large number of parameters, resulting in high storage resource requirements and increased computational complexity, making it difficult to effectively handle sensitive content in response texts generated by large language models.
By obtaining the initial parameters of the specified network layers of the original text self-inspection model, dimensionality reduction is performed to construct a dimensionality-reduced text self-inspection model. The model parameters are then adjusted using security evaluation to reduce storage space requirements and computational complexity.
It reduces the storage space requirements and computational complexity of the text self-checking model fine-tuning process, improves the model's computational speed and efficiency, and can effectively identify and handle ethical issues and security risks in the response text generated by large language models.
Smart Images

Figure CN119005331A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a method, device, storage medium, and equipment for fine-tuning a text self-checking model. Background Art
[0002] With the development of big language models, more and more technical fields have realized the deployment and application of big language models. Among them, using big language models to provide consulting services to users is a common choice for many companies. However, the reply text output by the big language model to the user's question may contain sensitive content that violates laws and regulations or leaks corporate privacy. Therefore, it is necessary to use the text self-checking model to detect the generated reply text before sending the reply text to the user and process the sensitive content.
[0003] However, the text self-checking model itself has a huge number of parameters, and model training for the text self-checking model requires extremely high storage resources.
[0004] Therefore, the present invention provides a method, device, storage medium and equipment for fine-tuning a text self-checking model. Summary of the invention
[0005] This specification provides a method and device for fine-tuning a text self-checking model to partially solve the above-mentioned problems existing in the prior art.
[0006] This manual adopts the following technical solutions:
[0007] This manual provides a method for fine-tuning a text self-checking model, including:
[0008] Get the initial parameters of the specified network layer in the original text self-checking model;
[0009] For each specified network layer obtained, the initial parameters of the specified network layer are reduced in dimension;
[0010] According to each designated network layer after dimensionality reduction and the original text self-checking model, a dimensionality reduction text self-checking model is obtained;
[0011] Inputting the sample reply text into the dimension reduction text self-checking model to obtain a security evaluation of the output of the dimension reduction text self-checking model;
[0012] The dimension reduction text self-checking model is adjusted according to the difference between the security evaluation and the security label corresponding to the sample reply text.
[0013] Optionally, inputting the sample reply text into the dimensionality reduction text self-checking model to obtain a security evaluation output by the dimensionality reduction text self-checking model specifically includes:
[0014] Inputting the sample reply text into the dimension reduction text self-checking model;
[0015] When any designated network layer performs calculation, the first parameter of the designated network layer is multiplied by the feature input to the designated network layer to obtain an intermediate result, and the second parameter of the designated network layer is multiplied by the intermediate result to obtain the feature output by the designated network layer, and the dimensions of the first matrix and the second matrix are both smaller than the dimensions of the initial parameters of the designated network layer;
[0016] According to the characteristics of the outputs of each designated network layer and other network layers in the dimensionality reduction text self-checking model, a security evaluation of the output of the dimensionality reduction text self-checking model is obtained.
[0017] Optionally, the initial parameters of the specified network layer are reduced in dimension, including:
[0018] Determining a first initial parameter and a second initial parameter of the specified network layer according to the initial parameter of the specified network layer;
[0019] Before multiplying the first parameter of the designated network layer by the feature input to the designated network layer to obtain an intermediate result, and multiplying the second parameter of the designated network layer by the intermediate result to obtain the feature output by the designated network layer, the method further includes:
[0020] The first parameter of the specified network layer is determined according to the first initial parameter and the first increment of the specified network layer, and the second parameter of the specified network layer is determined according to the second initial parameter and the second increment of the specified network layer, wherein the first increment is the total adjustment amount of the first initial parameter of the specified network layer during the fine-tuning process, and the dimension of the first increment is the same as the dimension of the first parameter, and the second increment is the total adjustment amount of the second initial parameter of the specified network layer during the fine-tuning process, and the dimension of the second increment is the same as the dimension of the second parameter.
[0021] Optionally, the dimension reduction text self-checking model is adjusted according to the difference between the security evaluation and the security label corresponding to the sample reply text, specifically including:
[0022] Determine a loss value according to the security evaluation and the security label corresponding to the sample reply text using a preset loss function;
[0023] Determining a parameter increment according to the loss value;
[0024] The dimension reduction text self-checking model is adjusted according to the parameter increment.
[0025] Optionally, adjusting the dimension reduction text self-checking model according to the parameter increment specifically includes:
[0026] For any specified network layer in the dimension reduction text model, a first increment of the specified network layer is adjusted according to the parameter increment, and a second increment of the specified network layer is adjusted according to the parameter increment.
[0027] Optionally, determining a loss value according to the security evaluation and the security label corresponding to the sample reply text using a preset loss function specifically includes:
[0028] Determine the cross entropy loss between the security evaluation and the security label corresponding to the sample reply text as a loss value.
[0029] Optionally, also include:
[0030] After fine-tuning the reduced-dimensionality text self-checking model is completed, for each specified network layer in the reduced-dimensionality text self-checking model, a parameter matrix of the specified network layer is reconstructed according to the first parameter and the second parameter of the specified network layer;
[0031] According to the reconstructed designated network layers and the dimension-reduced text self-checking model, a reconstructed text self-checking model is obtained;
[0032] After the large language model generates an application reply text to the user, the application reply text is input into the reconstructed text self-checking model to obtain a security evaluation of the application reply text;
[0033] Based on the security evaluation of the application reply text, the application reply text that passes the evaluation is displayed to the user.
[0034] This specification provides a fine-tuning device for a text self-checking model, including:
[0035] An acquisition module is used to obtain the initial parameters of the specified network layer in the original text self-checking model;
[0036] A dimension reduction module, for each specified network layer obtained, reduces the dimension of the initial parameters of the specified network layer;
[0037] A replacement module is used to obtain a reduced-dimensionality text self-checking model according to each designated network layer after dimensionality reduction and the original text self-checking model;
[0038] An evaluation module, inputting the sample reply text into the dimensionality reduction text self-checking model to obtain a security evaluation of the output of the dimensionality reduction text self-checking model;
[0039] The fine-tuning module adjusts the dimension reduction text self-checking model according to the difference between the security evaluation and the security label corresponding to the sample reply text.
[0040] This specification provides a computer-readable storage medium, which stores a computer program. When the computer program is executed by a processor, the fine-tuning method of the above-mentioned text self-checking model is implemented.
[0041] This specification provides a device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the above-mentioned fine-tuning method of the text self-checking model when executing the program.
[0042] At least one of the above technical solutions adopted in this specification can achieve the following beneficial effects:
[0043] In the fine-tuning method of the text self-checking model provided in the present specification, the initial parameters of the specified network layer in the original text self-checking model are obtained, and for each specified network layer obtained, the initial parameters of the specified network layer are reduced in dimension, and a reduced-dimensional text self-checking model is obtained based on the specified network layers after the reduced dimension and the original text self-checking model. A sample reply text is input into the reduced-dimensional text self-checking model to obtain a security evaluation of the output of the reduced-dimensional text self-checking model, and the reduced-dimensional text self-checking model is adjusted based on the difference between the security evaluation and the security label corresponding to the sample reply text.
[0044] It can be seen from the above method that this method can reduce the storage space requirements of the text self-checking model fine-tuning process and reduce the model complexity in the calculation process during fine-tuning. BRIEF DESCRIPTION OF THE DRAWINGS
[0045] The drawings described herein are used to provide a further understanding of this specification and constitute a part of this specification. The illustrative embodiments and descriptions of this specification are used to explain this specification and do not constitute an improper limitation on this specification. In the drawings:
[0046] Figure 1 A flowchart of a method for fine-tuning a text self-checking model in this specification;
[0047] Figure 2 It is a structural diagram of the original text self-checking model in this manual;
[0048] Figure 3 is a schematic diagram of the initial parameter, the first initial parameter and the second initial parameter in this specification;
[0049] Figure 4 It is a schematic diagram of parameter changes during multiple rounds of fine-tuning in this manual;
[0050] Figure 5 A schematic diagram of a fine-tuning device for a text self-checking model provided in this specification;
[0051] Figure 6The corresponding Figure 1 Schematic diagram of electronic equipment. DETAILED DESCRIPTION
[0052] In order to make the purpose, technical solutions and advantages of this specification more clear, the technical solutions of this specification will be clearly and completely described below in combination with the specific embodiments of this specification and the corresponding drawings. Obviously, the described embodiments are only part of the embodiments of this specification, not all of the embodiments. Based on the embodiments in this specification, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0053] The technical solutions provided by the embodiments of this specification are described in detail below in conjunction with the accompanying drawings.
[0054] Figure 1 The figure is a flow chart of a method for fine-tuning a text self-checking model in this specification, and the method for fine-tuning a text self-checking model specifically comprises the following steps:
[0055] S100: Obtaining initial parameters of a specified network layer in the original text self-checking model.
[0056] At present, using artificial intelligence to provide consulting services to users has become the choice of many companies. Among them, using a large language model to provide consulting services to users can more accurately understand the questions raised by users and give more appropriate answers, but the large language model also has security risks - the reply text given to the user may involve ethical issues or the possibility of leaking corporate secrets. However, for the above-mentioned problems that may exist in the reply text, re-debugging the large language model that provides consulting services is a very consuming project. Therefore, this specification provides a fine-tuning method for a text self-checking model, which is used to fine-tune the pre-trained text self-checking model so that the fine-tuned text self-checking model can adapt to the personalized needs of users. The reply text in the consulting service is detected using the fine-tuned text self-checking model, which can identify problems with leakage risks or ethical issues, and protect the confidentiality and privacy of the company. The execution subject of this specification can be a server for fine-tuning the text self-checking model, or other electronic devices that have the ability to connect to the text self-checking model, and this specification is not limited here. For the convenience of explanation, the following only takes the server as the execution subject to explain a method for fine-tuning a text self-checking model provided in this specification.
[0057] In the process of model fine-tuning, storage space is usually used to store model parameters so as to use the stored parameters to calculate the input samples. However, the parameter scale of a large language model is large. Storing the complete parameters in the storage space will increase the storage space requirements for model fine-tuning on the one hand, and increase the model complexity of the calculation process on the other hand. Therefore, this specification proposes a method for text self-checking model fine-tuning.
[0058] First, a pre-trained original text self-checking model is obtained, and initial parameters of a specified network layer in the original text self-checking model are extracted.
[0059] Pre-training refers to the process of training a text self-checking model based on a general, large-scale corpus of ethical issues, and this process is performed before the model accepts a specific task, which is the fine-tuning method of the text self-checking model provided in this specification. Pre-training can extract patterns and information from data by learning from a large amount of data, so that the original text self-checking model has preliminary detection capabilities for response texts with ethical risks and general security risks; the initial parameters are the parameters of the specified network layer in the original text self-checking model after pre-training; in the method provided in this specification, several network layers in the original text self-checking model can be preset as specified network layers. For example, when the structure of the original text self-checking model is as follows: Figure 2 As shown, each network layer such as M1, M2, M3, and M4 can be used as a designated network layer.
[0060] S102: For each acquired designated network layer, perform dimension reduction on initial parameters of the designated network layer.
[0061] After obtaining the initial parameters of each specified network layer, the initial parameters of each specified network layer can be reduced in dimension.
[0062] Specifically, the dimension reduction of the initial parameters of any specified network layer can be performed by performing dimension reduction processing on the parameter matrix of the initial parameters of the specified network layer, so as to obtain a dimension reduction matrix with a similar calculation result and a parameter scale much smaller than the original hyperparameter matrix. Among them, the dimension reduction processing can adopt various common methods such as parameter pruning, parameter quantization, low-rank decomposition, parameter sharing, etc.
[0063] After the parameter matrix of the initial parameters is reduced in dimension, the storage space required to store the reduced-dimensional matrix is less than the storage space required to store the parameter matrix of the initial parameters. On the one hand, this reduces the storage space requirement for model fine-tuning, and on the other hand, it also reduces the model complexity of the calculation process and improves the calculation speed.
[0064] S104: Obtain a reduced-dimensionality text self-check model according to each designated network layer after dimensionality reduction and the original text self-check model.
[0065] After obtaining the parameter matrix of each specified network layer after dimension reduction, for each specified network layer in the original text self-checking model, the parameter matrix of the initial parameters of the specified network layer can be replaced by the parameter matrix of the specified network layer after dimension reduction. After all the specified network layers in the original text self-checking model are replaced, the dimension reduction text self-checking model can be obtained.
[0066] S106: Input the sample reply text into the dimensionality reduction text self-checking model to obtain a security evaluation of the output of the dimensionality reduction text self-checking model.
[0067] After obtaining the dimensionality reduction text self-checking model, the dimensionality reduction text self-checking model can be trained. First, the sample reply text is input into the dimensionality reduction text self-checking model to obtain the security evaluation of the output of the dimensionality reduction text self-checking model.
[0068] Among them, the sample reply text is annotated reply text when providing consulting services to users. The annotation of a sample reply text is whether the sample reply text has security risks; accordingly, the output result of the dimensionality reduction text self-checking model is whether the sample reply text input into the dimensionality reduction text self-checking model has security risks.
[0069] S108: Adjusting the dimension reduction text self-checking model according to the difference between the security evaluation and the security label corresponding to the sample reply text.
[0070] After obtaining the security evaluation of the output of the dimensionality reduction text self-checking model, the difference between the security evaluation and the security label can be determined based on the security evaluation and the security label corresponding to the sample response text input into the dimensionality reduction text self-checking model. Based on the determined difference, the parameter increments of each network layer of the dimensionality reduction text self-checking model are calculated using a back propagation algorithm. The parameters of each network layer are then updated according to the parameter increments of each network layer, that is, the dimensionality reduction text self-checking model is adjusted.
[0071] like Figure 1 The fine-tuning method of a text self-checking model shown can reduce the storage space requirement of the text self-checking model fine-tuning process and reduce the model complexity in the calculation process during fine-tuning.
[0072] In addition, in Figure 1In the step S106 shown, the sample reply text is input into the reduced-dimensionality text self-checking model. When any designated network layer performs calculation, the first parameter of the designated network layer is multiplied by the feature input into the designated network layer to obtain an intermediate result. The second parameter of the designated network layer is multiplied by the intermediate result to obtain the feature output by the designated network layer. The dimensions of the first matrix and the second matrix are both smaller than the dimensions of the initial parameters of the designated network layer. According to the features output by each designated network layer and other network layers in the reduced-dimensionality text self-checking model, a security evaluation of the output of the reduced-dimensionality text self-checking model is obtained.
[0073] When reducing the dimension of the initial parameters of any specified network layer, a low-rank decomposition method can be used to decompose the parameter matrix of the initial parameters into the multiplication of the first initial parameters and the second initial parameters, the number of rows of the parameter matrix of the first initial parameters is the same as the initial parameters of the specified network layer, the number of columns of the parameter matrix of the second initial parameters is the same as the initial parameters of the specified network layer, the number of columns of the parameter matrix of the first initial parameters is the same as the number of rows of the parameter matrix of the second initial parameters and is less than the rank of the initial matrix of the specified network layer, such as Figure 3 As shown, when the dimension of the parameter matrix of the initial parameters is M*N, the dimension of the parameter matrix of the first initial parameters can be M*K, and the dimension of the parameter matrix of the second initial parameters can be K*N, where K is a preset rank. It is easy to see that when K is less than M / 2 and N / 2 at the same time, the sum of the storage space required to store the parameter matrix of the first initial parameters and the parameter matrix of the second initial parameters is less than the storage space required to store the parameter matrix of the initial parameters. In actual application, K can be set according to the needs of fine-tuning.
[0074] Among them, low-rank decomposition can adopt various common decomposition methods, such as singular value decomposition, eigenvalue decomposition, etc., and this manual does not limit it here.
[0075] During the fine-tuning process, the first initial parameter and the second initial parameter of each designated network layer are updated to obtain the first parameter and the second parameter used to calculate the input feature of the designated network layer in the dimensionality reduction text self-checking model. For any designated network layer, it can be seen from the above-mentioned low-rank decomposition method that the first parameter of the designated network layer is multiplied with the input feature of the designated network layer to obtain an intermediate result, and the second parameter of the designated network layer is multiplied with the intermediate result to obtain the output feature of the designated network layer. The calculation result with the same dimension as the feature calculated using the initial parameters of the designated network layer can be used as the output feature of the designated network layer, which does not affect the calculation of other model layers in the dimensionality reduction text self-checking model.
[0076] Among them, when fine-tuning the dimensionality reduction text self-checking model, the first initial parameter can be used as the first parameter, and the second initial parameter can be used as the second parameter; in each round of fine-tuning, the first initial parameter and the second initial parameter of each specified network layer are updated to obtain the first parameter and the second parameter, which can be directly updating the first parameter of the previous round to obtain the first parameter of this round, and updating the second parameter of the previous round to obtain the second parameter of this round, or other feasible methods, which are not limited in this specification.
[0077] In addition, in Figure 1 In step S102 shown in FIG. 1 , the first initial parameter and the second initial parameter of the specified network layer are determined according to the initial parameter of the specified network layer; Figure 1 Before the shown step S106, the first parameter of the specified network layer is determined based on the first initial parameter and the first increment of the specified network layer, and the second parameter of the specified network layer is determined based on the second initial parameter and the second increment of the specified network layer, wherein the first increment is the total adjustment amount of the first initial parameter of the specified network layer during the fine-tuning process, and the dimension of the first increment is the same as the dimension of the first parameter, and the second increment is the total adjustment amount of the second initial parameter of the specified network layer during the fine-tuning process, and the dimension of the second increment is the same as the dimension of the second parameter.
[0078] When reducing the dimension of the initial parameters of any specified network layer, the parameter matrix of the initial parameters of the specified network layer can be decomposed into the first initial parameters and the second initial parameters using the low-rank decomposition method. Due to the characteristics of low-rank decomposition, the parameter scales of the first initial matrix and the second initial matrix obtained after decomposition are much smaller than the parameter matrix of the initial parameters. Furthermore, when calculating using the reduced-dimensional text self-checking model obtained after dimensionality reduction, the storage space required to store the first initial matrix and the second initial matrix is also much smaller than the space required to store the parameter matrix of the initial parameters.
[0079] Thus, in the process of fine-tuning any designated network layer in the dimension reduction text self-checking model, after each round of fine-tuning is completed, the first increment and the second increment of the designated network layer are determined, the first increment is the total adjustment amount of the first initial parameter of the designated network layer during the fine-tuning process, and the dimension is the same as the dimension of the first parameter, the second increment is the total adjustment amount of the second initial parameter of the designated network layer during the fine-tuning process, and the dimension is the same as the dimension of the second parameter, according to the first initial parameter of the designated network layer and the first increment, the first parameter of the designated network layer is determined, and, according to the second initial parameter of the designated network layer and the second increment, the second parameter of the designated network layer is determined. That is, in the next round of fine-tuning after the completion of this round of fine-tuning, when the designated network layer in the dimension reduction text model is used for calculation, the first initial parameter and the first increment and the second initial parameter and the second increment are used to obtain the updated first parameter and the second parameter, and the updated first parameter and the second parameter are used for calculation. Specifically, the first initial parameter and the first increment can be added to determine the first parameter, and the second initial parameter and the second increment can be added to determine the second parameter.
[0080] Among them, one round of fine-tuning refers to adjusting the model parameters in the dimensionality reduction text self-checking model based on a batch of samples. A complete fine-tuning process may include multiple rounds of fine-tuning processes.
[0081] Moreover, in Figure 1 In step S108 shown, a loss value is determined according to the security evaluation and the security label corresponding to the sample reply text using a preset loss function, a parameter increment is determined according to the loss value, and the dimensionality reduction text self-checking model is adjusted according to the parameter increment.
[0082] When fine-tuning the dimensionality reduction text self-checking model in each round, the loss value can be determined based on the security label corresponding to the sample reply text input into the dimensionality reduction text self-checking model in this round, and the security evaluation of the output of the dimensionality reduction text self-checking model in this round, using a preset loss function, and the parameter increment can be determined based on the loss value, and the dimensionality reduction text self-checking model can be adjusted based on the parameter increment.
[0083] Among them, the security label and the security evaluation can be represented in the form of classified data or in the form of numerical data, and the size of the numerical value represents the security level of the sample reply text, and this manual does not limit this; the preset loss function can be various common loss functions such as: cross entropy loss, contrastive learning loss, etc.; the dimensionality reduction text self-check model is adjusted according to the parameter increment, which can be only for each specified network layer, and the parameters of other model layers are frozen, or all network layers of the dimensionality reduction text self-check model can be adjusted, and this manual does not limit this.
[0084] Specifically, in Figure 1 In step S108 shown, for any specified network layer in the dimension reduction text model, the first increment of the specified network layer is adjusted according to the parameter increment, and the second increment of the specified network layer is adjusted according to the parameter increment.
[0085] As can be seen from the above, the first parameter is determined according to the first initial parameter and the first increment, and the second parameter is determined according to the second initial parameter and the second increment, such as Figure 4 As shown, after the first round of fine-tuning, the first initial parameter is A, the first increment is A1, the second initial parameter is B, the first increment is B1, and after the nth round of fine-tuning, the first initial parameter is A, the first increment is A n , the second initial parameter is still B, the first increment is B n During multiple rounds of fine-tuning, the first initial parameters and the second initial parameters remain unchanged and are in a frozen state, while only the first increment and the second increment change, thereby changing the first parameters and the second parameters used in the calculation in each round of fine-tuning. In this way, the first initial parameters and the second initial parameters obtained by dimensionality reduction of any specified network layer can be retained, providing a basis for possible parameter backtracking in subsequent processes.
[0086] In one or more embodiments of the present specification, a cross entropy loss between the security evaluation and the security label corresponding to the sample reply text is determined as a loss value.
[0087] In one or more embodiments of the present specification, after fine-tuning the dimensionality reduction text self-checking model is completed, for each specified network layer in the dimensionality reduction text self-checking model, the parameter matrix of the specified network layer is reconstructed according to the first parameter and the second parameter of the specified network layer, and a reconstructed text self-checking model is obtained according to the reconstructed specified network layers and the dimensionality reduction text self-checking model. After the large language model generates an application reply text to the user, the application reply text is input into the reconstructed text self-checking model to obtain a security evaluation of the application reply text, and based on the security evaluation of the application reply text, the application reply text that passes the evaluation is displayed to the user.
[0088] As described above, low-rank decomposition can be used to decompose the initial parameters of any specified network layer into a first initial parameter and a second initial parameter, and the first initial parameter and the second initial parameter in the reduced-dimensionality text self-check model are updated to obtain the first parameter and the second parameter that identify the specified network layer after fine-tuning. After the fine-tuning of the reduced-dimensionality text self-check model is completed, for any specified network layer, the first parameter after fine-tuning of the specified network layer is multiplied by the second parameter to reconstruct the parameter matrix of the specified network layer. The parameter matrix of the reconstructed specified network layer has the same dimension as the initial matrix of the specified network layer. According to the order relationship between each reconstructed specified network layer, other network layers in the reduced-dimensionality text self-check model, and each network layer in the reduced-dimensionality text self-check model, a reconstructed text self-check model is obtained. The reconstructed text self-check model can be used in the actual application process to check the application reply text to the user.
[0089] Specifically, after the large language model generates an application reply text to the user, the application reply text is input into the reconstructed text self-check model to obtain a security evaluation for the application reply text. The security evaluation can be classified data or numerical data. When the result of the classified data is high security - passed, or the numerical data falls within the interval of high security - passed, the application reply text that passes the evaluation is displayed to the user.
[0090] The above is a method for fine-tuning a text self-checking model provided in one or more embodiments of this specification. Based on the same idea, this specification also provides a corresponding fine-tuning device for a text self-checking model, such as Figure 5 shown.
[0091] Figure 5 A schematic diagram of a fine-tuning device for a text self-checking model provided in this specification specifically includes:
[0092] An acquisition module 500 is used to acquire initial parameters of a specified network layer in the original text self-checking model;
[0093] A dimension reduction module 502, for each specified network layer obtained, reduces the dimension of the initial parameters of the specified network layer;
[0094] A replacement module 504 obtains a reduced-dimensionality text self-checking model according to each designated network layer after dimensionality reduction and the original text self-checking model;
[0095] Evaluation module 506, inputting the sample reply text into the dimension reduction text self-checking model to obtain the security evaluation of the output of the dimension reduction text self-checking model;
[0096] The fine-tuning module 508 adjusts the dimension reduction text self-checking model according to the difference between the security evaluation and the security label corresponding to the sample reply text.
[0097] Optionally, the evaluation module 506 is specifically used to: input the sample reply text into the reduced-dimensionality text self-checking model, and when any designated network layer performs calculations, obtain an intermediate result by multiplying the first parameter of the designated network layer with the feature of the input to the designated network layer, and obtain the feature of the output of the designated network layer by multiplying the second parameter of the designated network layer with the intermediate result, and the dimensions of the first matrix and the second matrix are both smaller than the dimensions of the initial parameters of the designated network layer, and obtain a security evaluation of the output of the reduced-dimensionality text self-checking model based on the features of the outputs of each designated network layer and other network layers in the reduced-dimensionality text self-checking model.
[0098] Optionally, the dimension reduction module 502 is specifically used to: determine the first initial parameter and the second initial parameter of the specified network layer according to the initial parameter of the specified network layer;
[0099] The replacement module 504 is also used to: determine the first parameter of the specified network layer based on the first initial parameter and the first increment of the specified network layer, and determine the second parameter of the specified network layer based on the second initial parameter and the second increment of the specified network layer, wherein the first increment is the total adjustment amount of the first initial parameter of the specified network layer during the fine-tuning process, and the dimension of the first increment is the same as the dimension of the first parameter, and the second increment is the total adjustment amount of the second initial parameter of the specified network layer during the fine-tuning process, and the dimension of the second increment is the same as the dimension of the second parameter.
[0100] Optionally, the fine-tuning module 508 is specifically used to: determine the loss value according to the security evaluation and the security label corresponding to the sample reply text with a preset loss function, determine the parameter increment according to the loss value, and adjust the dimensionality reduction text self-check model according to the parameter increment.
[0101] Optionally, the fine-tuning module 508 is specifically used to: for any specified network layer in the dimensionality reduction text model, adjust the first increment of the specified network layer according to the parameter increment, and adjust the second increment of the specified network layer according to the parameter increment.
[0102] Optionally, the fine-tuning module 508 is specifically used to determine the cross entropy loss between the security evaluation and the security label corresponding to the sample reply text as a loss value.
[0103] Optionally, the fine-tuning module 508 is also used for: after fine-tuning the reduced-dimensionality text self-checking model, for each specified network layer in the reduced-dimensionality text self-checking model, reconstructing the parameter matrix of the specified network layer according to the first parameter and the second parameter of the specified network layer, obtaining a reconstructed text self-checking model according to the reconstructed specified network layers and the reduced-dimensionality text self-checking model, and when the large language model generates an application reply text to the user, inputting the application reply text into the reconstructed text self-checking model to obtain a security evaluation of the application reply text, and displaying the application reply text that has passed the evaluation to the user according to the security evaluation of the application reply text.
[0104] This specification also provides a computer-readable storage medium, which stores a computer program, which can be used to execute the above Figure 1 Fine-tuning method for the provided text introspection model.
[0105] This manual also provides Figure 6 The schematic structure diagram of the electronic device shown in FIG. Figure 6 As shown in FIG. 1 , at the hardware level, the fine-tuning device of the text self-checking model includes a processor, an internal bus, a network interface, a memory, and a non-volatile memory, and may also include other hardware required for the business. The processor reads the corresponding computer program from the non-volatile memory into the memory and then runs it to achieve the above Figure 1 The method for fine-tuning the text self-checking model. Of course, in addition to the software implementation, this specification does not exclude other implementations, such as logic devices or a combination of software and hardware, etc., that is, the execution subject of the following processing flow is not limited to each logic unit, but can also be hardware or logic devices.
[0106] In the 1990s, improvements to a technology could be clearly distinguished as hardware improvements (for example, improvements to the circuit structure of diodes, transistors, switches, etc.) or software improvements (improvements to the method flow). However, with the development of technology, many improvements to the method flow today can be regarded as direct improvements to the hardware circuit structure. Designers almost always obtain the corresponding hardware circuit structure by programming the improved method flow into the hardware circuit. Therefore, it cannot be said that an improvement in a method flow cannot be implemented using a hardware entity module. For example, a programmable logic device (PLD) (such as a field programmable gate array (FPGA)) is such an integrated circuit whose logical function is determined by the user's programming of the device. Designers can "integrate" a digital system on a PLD by programming it themselves, without having to ask a chip manufacturer to design and produce a dedicated integrated circuit chip. Moreover, nowadays, instead of manually making integrated circuit chips, this kind of programming is mostly implemented by "logic compiler" software, which is similar to the software compiler used when developing and writing programs, and the original code before compilation must also be written in a specific programming language, which is called hardware description language (HDL). There is not only one HDL, but many kinds, such as ABEL (Advanced Boolean Expression Language), AHDL (Altera Hardware Description Language), Confluence, CUPL (Cornell University Programming Language), HDCal, JHDL (Java Hardware Description Language), Lava, Lola, MyHDL, PALASM, RHDL (Ruby Hardware Description Language), etc. The most commonly used ones are VHDL (Very-High-Speed Integrated Circuit Hardware Description Language) and Verilog. Those skilled in the art should also know that it is only necessary to program the method flow slightly in the above-mentioned hardware description languages and program it into the integrated circuit, and then it is easy to obtain the hardware circuit that implements the logic method flow.
[0107] The controller can be implemented in any appropriate manner, for example, the controller can take the form of a microprocessor or processor and a computer-readable medium storing a computer-readable program code (such as software or firmware) that can be executed by the (micro)processor, a logic gate, a switch, an application-specific integrated circuit (ASIC), a programmable logic controller, and an embedded microcontroller. Examples of controllers include, but are not limited to, the following microcontrollers: ARC 625D, Atmel AT91SAM, Microchip PIC18F26K20, and Silicone Labs C8051F320. The memory controller can also be implemented as part of the control logic of the memory. Those skilled in the art also know that in addition to implementing the controller in a purely computer-readable program code manner, the controller can be implemented in the form of a logic gate, a switch, an application-specific integrated circuit, a programmable logic controller, and an embedded microcontroller by logically programming the method steps. Therefore, this controller can be considered as a hardware component, and the devices included therein for implementing various functions can also be regarded as structures within the hardware component. Or even, the devices for implementing various functions can be regarded as both software modules for implementing the method and structures within the hardware component.
[0108] The systems, 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.
[0109] For the convenience of description, the above device is described in various units according to their functions. Of course, when implementing this specification, the functions of each unit can be implemented in the same or multiple software and / or hardware.
[0110] Those skilled in the art will appreciate that embodiments of the present invention may be provided as methods, systems, or computer program products. Therefore, the present invention may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, the present invention may take 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.) containing computer-usable program code.
[0111] The present invention is described with reference to flowcharts and / or block diagrams of methods, devices (systems), and computer program products according to embodiments of the present invention. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of processes and / or blocks 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 produce 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.
[0112] 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.
[0113] 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.
[0114] In a typical configuration, a computing device includes one or more processors (CPU), input / output interfaces, network interfaces, and memory.
[0115] The memory may include non-permanent storage in a computer-readable medium, random access memory (RAM) and / or non-volatile memory in the form of read-only memory (ROM) or flash RAM. The memory is an example of a computer-readable medium.
[0116] Computer readable media include permanent and non-permanent, removable and non-removable media that can be implemented by any method or technology to store information. Information can be computer readable instructions, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disk read-only memory (CD-ROM), digital versatile disk (DVD) or other optical storage, magnetic cassettes, magnetic tape magnetic disk storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined herein, computer readable media does not include temporary computer readable media (transitory media), such as modulated data signals and carrier waves.
[0117] 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.
[0118] Those skilled in the art will appreciate that the embodiments of this specification may be provided as methods, systems or computer program products. Therefore, this specification may take the form of a complete hardware embodiment, a complete software embodiment or an embodiment combining software and hardware. Moreover, this specification may take 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.) containing computer-usable program code.
[0119] This specification may be described in the general context of computer-executable instructions executed by a computer, such as program modules. Generally, program modules include routines, programs, objects, components, data structures, etc. that perform specific tasks or implement specific abstract data types. This specification may also be practiced in distributed computing environments where tasks are performed by remote processing devices connected through a communication network. In a distributed computing environment, program modules may be located in local and remote computer storage media, including storage devices.
[0120] 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 system 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.
[0121] The above is only an embodiment of this specification and is not intended to limit this specification. For those skilled in the art, this specification may have various changes and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of this specification should be included in the scope of the claims of this application.
Claims
1. A fine-tuning method for a text self-checking model, the method comprising: Get the initial parameters of the specified network layer in the original text self-checking model; For each specified network layer obtained, the initial parameters of the specified network layer are reduced in dimension; According to each designated network layer after dimensionality reduction and the original text self-checking model, a dimensionality reduction text self-checking model is obtained; Inputting the sample reply text into the dimensionality reduction text self-checking model to obtain a security evaluation of the output of the dimensionality reduction text self-checking model; The dimension reduction text self-checking model is adjusted according to the difference between the security evaluation and the security label corresponding to the sample reply text.
2. The method according to claim 1, inputting the sample reply text into the dimensionality reduction text self-checking model to obtain the security evaluation output by the dimensionality reduction text self-checking model, specifically comprising: Inputting the sample reply text into the dimension reduction text self-checking model; When any designated network layer performs calculation, the first parameter of the designated network layer is multiplied by the feature input to the designated network layer to obtain an intermediate result, and the second parameter of the designated network layer is multiplied by the intermediate result to obtain the feature output by the designated network layer, and the dimensions of the first matrix and the second matrix are both smaller than the dimensions of the initial parameters of the designated network layer; According to the characteristics of the outputs of each designated network layer and other network layers in the dimensionality reduction text self-checking model, a security evaluation of the output of the dimensionality reduction text self-checking model is obtained.
3. The method according to claim 1 or 2, wherein the initial parameters of the specified network layer are reduced in dimension, specifically comprising: Determining a first initial parameter and a second initial parameter of the specified network layer according to the initial parameter of the specified network layer; Before multiplying the first parameter of the designated network layer by the feature input to the designated network layer to obtain an intermediate result, and multiplying the second parameter of the designated network layer by the intermediate result to obtain the feature output by the designated network layer, the method further includes: The first parameter of the specified network layer is determined according to the first initial parameter and the first increment of the specified network layer, and the second parameter of the specified network layer is determined according to the second initial parameter and the second increment of the specified network layer, wherein the first increment is the total adjustment amount of the first initial parameter of the specified network layer during the fine-tuning process, and the dimension of the first increment is the same as the dimension of the first parameter, and the second increment is the total adjustment amount of the second initial parameter of the specified network layer during the fine-tuning process, and the dimension of the second increment is the same as the dimension of the second parameter.
4. The method according to claim 3, adjusting the dimension reduction text self-checking model according to the difference between the security evaluation and the security label corresponding to the sample reply text, specifically comprising: Determine a loss value according to the security evaluation and the security label corresponding to the sample reply text using a preset loss function; Determining a parameter increment according to the loss value; The dimension reduction text self-checking model is adjusted according to the parameter increment.
5. The method according to claim 4, wherein the dimension reduction text self-checking model is adjusted according to the parameter increment, specifically comprising: For any specified network layer in the dimension reduction text model, a first increment of the specified network layer is adjusted according to the parameter increment, and a second increment of the specified network layer is adjusted according to the parameter increment.
6. The method according to claim 4, determining the loss value according to the security evaluation and the security label corresponding to the sample reply text using a preset loss function, specifically comprising: Determine the cross entropy loss between the security evaluation and the security label corresponding to the sample reply text as a loss value.
7. The method of claim 2, further comprising: After fine-tuning the reduced-dimensionality text self-checking model is completed, for each specified network layer in the reduced-dimensionality text self-checking model, a parameter matrix of the specified network layer is reconstructed according to the first parameter and the second parameter of the specified network layer; According to the reconstructed designated network layers and the dimension-reduced text self-checking model, a reconstructed text self-checking model is obtained; After the large language model generates an application reply text to the user, the application reply text is input into the reconstructed text self-checking model to obtain a security evaluation of the application reply text; Based on the security evaluation of the application reply text, the application reply text that passes the evaluation is displayed to the user.
8. A fine-tuning device for a text self-checking model, comprising: An acquisition module is used to obtain the initial parameters of the specified network layer in the original text self-checking model; A dimension reduction module, for each specified network layer obtained, reduces the dimension of the initial parameters of the specified network layer; A replacement module is used to obtain a reduced-dimensionality text self-checking model according to each designated network layer after dimensionality reduction and the original text self-checking model; An evaluation module, inputting the sample reply text into the dimensionality reduction text self-checking model to obtain a security evaluation of the output of the dimensionality reduction text self-checking model; The fine-tuning module adjusts the dimension reduction text self-checking model according to the difference between the security evaluation and the security label corresponding to the sample reply text.
9. A computer-readable storage medium, wherein the storage medium stores a computer program, and when the computer program is executed by a processor, the method according to any one of claims 1 to 7 is implemented.
10. A device comprising a memory, a processor and a computer program stored in the memory and executable on the processor, wherein the processor implements the method according to any one of claims 1 to 7 when executing the program.
