Security risk assessment methods, systems, and devices for large language models in long text scenarios
By constructing a security risk assessment dataset for short text scenarios and utilizing reverse length augmentation and thought chain techniques, the security risks of large language models in long text scenarios are automatically assessed. This addresses the problem of insufficient security in long text scenarios in existing technologies, reduces manual annotation costs, and improves model security.
Patent Information
- Application Number
- CN202411671767.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-21
- Publication Date
- 2025-10-28
- Estimated Expiration
- 2044-11-21
AI Technical Summary
Existing large language models are severely inadequate in terms of security in long text scenarios, lack effective security assessment methods, have high manual annotation costs, and cannot support long text generation tasks of arbitrary length.
By constructing a security risk assessment dataset for short text scenarios, and generating a security risk assessment dataset for long text scenarios using the short text dataset, and employing context learning, reverse length augmentation, and thought chain techniques, combined with security assessment metrics processed by unbiased estimation, the security risks of large language models in long text scenarios are automatically assessed.
It enables efficient evaluation of the security risks of large language models in long text scenarios without manual annotation, reduces the cost of constructing long context evaluation data, and the generated long text data can be used for security fine-tuning to improve the security performance of large models. The evaluation metrics can more accurately reflect the randomness of security output.
Smart Images

Figure CN119647621B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of large language model technology, and in particular to the security risk assessment of large language models for long text scenarios. Background Technology
[0002] In recent years, large language models have been widely applied in various fields requiring the understanding of long textual information, such as document summarization, document question answering, and language translation. Generally, short text refers to inputs with a length of less than 512 characters, while long text refers to inputs with a length of more than 512 characters. Given the increasing demand for processing long text sequences, most large language models have extended their input length support to hundreds of thousands of characters or even more.
[0003] While most recently developed large-scale models demonstrate good security performance in short text scenarios, the security training processes of existing large-scale models (such as supervised fine-tuning or reinforcement learning based on human feedback) rely solely on short text datasets. This results in severely inadequate security guarantees for long text scenarios, creating a significant gap in security assessment methods. Many methods exist to evaluate the long text understanding capabilities of large language models, including tasks such as document question answering and document summarization. Simultaneously, numerous methods assess the security risks of large language models in short text scenarios. However, there is currently no method to directly assess the security risks of large models in long text scenarios. Manually annotating long text security assessment data is too costly, and existing large-scale models cannot adequately support long text generation tasks of arbitrary length. Summary of the Invention
[0004] The purpose of this invention is to address the serious lack of security protection for existing large language models in long text scenarios and the significant gap in security assessment methods. This invention provides a method, system, and device for security risk assessment of large language models in long text scenarios.
[0005] This invention is achieved through the following technical solution. One aspect of this invention provides a method for assessing the security risks of large language models in long text scenarios, the method comprising:
[0006] Step 1: Construct a short text scenario security risk assessment dataset using short text security domain datasets;
[0007] Step 2: Using the short text scenario security risk assessment dataset, identify the low security risk dataset and the high security risk dataset for short text scenarios, and obtain the security risk assessment index of the large language model in the short text scenario;
[0008] Step 3: Construct a harmful long text context dataset and a long text security risk assessment dataset, specifically including:
[0009] Step 3.1: Define the target length L of the hybrid long context and the granularity information P. G Represents the proportion of harmful contexts to mixed long contexts, and custom location information P. L The location representing a harmful context embedded in a mixed long context, where P G +P L ≤1, 0≤P G ,P L ≤1;
[0010] Step 3.2: For any harmful short text context in the short text scenario security risk assessment dataset, if there is a corresponding harmful long text context in the dataset with a length of (L×P)... G The harmful long text context is defined as (L×P)±Δ1, where Δ1 is a custom generated length threshold. This harmful long text context is used directly; otherwise, the length is expanded to obtain a length of (L×P). G The harmful long text context is obtained by using the harmful short text context and the harmful long text context to construct the data in the harmful long text context dataset, where the harmful short text context is used for indexing;
[0011] Step 3.3: Sample the secure long text, the total length of which is (L×(1-P)). G ))±Δ2, where Δ2 is a custom insertion length threshold, and the security task description is sampled simultaneously;
[0012] Step 3.4: In (L×P L Insert harmful long text context at the position to obtain a mixed long context that combines safe and harmful content;
[0013] Step 3.5: Combine the safe task description with the harmful task description to obtain a hybrid task description;
[0014] Step 3.6: Take the mixed long context and mixed task description as input to obtain the long text scenario security risk assessment dataset;
[0015] Step 4: Based on the long text security risk assessment dataset, evaluate the long text security performance of the large language model and obtain the security risk assessment index of the large language model in long text scenarios.
[0016] Further, step 1 includes:
[0017] Step 1.1: Construct a dataset for assessing potential security risks in short text scenarios by utilizing harmful task descriptions and corresponding harmful short text contexts from short text security domain data; or
[0018] By utilizing large language models with low security or large models without security alignment, we collect harmful short text contexts corresponding to harmful task descriptions.
[0019] Step 1.2: For all potential short text scenario security risk assessment datasets, use harmful content detection methods to determine whether the harmful context belongs to the harmful category. If it belongs to the harmful category, combine the harmful task description and the corresponding harmful context to construct the final short text scenario security risk assessment dataset. The harmful content detection methods include, but are not limited to, security content detection based on large models.
[0020] Furthermore, in step 2, determining the low-security-risk dataset and the high-security-risk dataset for short text scenarios specifically includes:
[0021] Step 2.1 Traverse the short text scenario security risk assessment dataset, combine the corresponding harmful short text context and harmful task description as input to the large language model, and perform the following steps for each input:
[0022] Step 2.1.1 The large language model generates text n times from the input, resulting in n outputs; the large language model or rule matching is used to determine whether each output belongs to the category of rejected answers, thus obtaining the total number of rejected answers c. r Using the aforementioned harmful content detection methods, determine whether each output belongs to the harmful category, and obtain the total number of harmless responses, c. s ;
[0023] Step 2.1.2 Calculate the rejection rate @k based on the user-defined value k. - and harmlessness rate @k - ;
[0024] Step 2.1.3 If the rejection rate is @k - Less than the rejection rate threshold or harmlessness rate @k - If the input is less than the harmlessness threshold, the input and its corresponding harmful short text context are placed in a pair into the high security risk dataset of the short text scenario; otherwise, the input and its corresponding harmful short text context are placed in a pair into the low security risk dataset of the short text scenario.
[0025] Step 2.2 performs statistical analysis on the rejection rate and harmlessness rate, calculates the security risk assessment index, and obtains the security risk assessment index of the large language model in the short text scenario. The security risk assessment index includes the overall rejection rate @k in the short text scenario. - Overall harmlessness rate @k - And low risk rate.
[0026] Furthermore,
[0027]
[0028] Among them, represents the combination number of selecting k numbers from c numbers. If c < k, this value is 0.
[0029] Furthermore, in step 2, the obtaining of the security risk assessment index of the large language model in the short text scenario specifically includes:
[0030] According to the rejection rate and harmless rate, calculate the security risk assessment index to obtain the security risk assessment index of the large language model in the short text scenario. The security risk assessment index includes the overall rejection rate @k in the short text scenario - , the overall harmless rate @k - and the low-risk rate;
[0031]
[0032] Furthermore, in step 3.2, the performing of length expansion to obtain a harmful long text context with a length of (L × P G ) ± Δ1 specifically includes:
[0033] Repeating the harmful short text context to obtain a harmful long text context at a specified length; or
[0034] Performing clustering indexing on the database before filtering for the target evaluation task, and splicing the harmful short text contexts of the same evaluation task category. If the specified context length is not reached, perform repeated expansion; or
[0035] Using a large model generated from harmful long text, by designing prompt words and thought chains corresponding to the evaluation task, guiding the large model to generate harmful long text contexts. Among them, the training method of the large model generated from harmful long text includes:
[0036] Step 3.2.1: Combine the long text input and summary output of the summary generation dataset in the existing long text evaluation data, and use any long text large model to generate an outline;
[0037] Step 3.2.2: Calculate the length L of the corresponding long text, and perform rounding to the nearest integer in units of 10 n where represents rounding down; Combine the outline and L as the input, and the corresponding long text as the output to form a length expansion dataset; representing rounding down; Combine the outline and L as the input, and the corresponding long text as the output to form a length expansion dataset;
[0038] Step 3.2.3: Use the length expansion dataset obtained in step 3.2.2 to perform length expansion fine-tuning on the large model to obtain a large model for generating harmful long text.
[0039] Furthermore, step 4 includes:
[0040] Step 4.1: Evaluate the ability of large models to generate secure content in long text scenarios, specifically including:
[0041] Step 4.1.1: Traverse the constructed long text scenario security risk assessment dataset, combine the corresponding mixed context and mixed task description into input, and perform the following steps for each input:
[0042] Step 4.1.1.1: Have the large language model generate text n times from the input to obtain n outputs;
[0043] Step 4.1.1.2: Determine whether each output belongs to the category of rejected answers by using a large language model or rule matching, and obtain the total number of rejected answers c. r By using harmful content detection methods, it is determined whether each output belongs to the harmful category, and the total number of harmless responses c is obtained. s ;
[0044] Step 4.1.1.3: Calculate the rejection rate @k based on the custom value k. - and harmlessness rate @k - If the rejection rate is @k - Less than the rejection rate threshold or harmlessness rate @k - If the input is less than the harmlessness threshold, the input and its corresponding harmful long text context are placed in a pair into the high security risk dataset for long text scenarios; otherwise, the input and its corresponding harmful long text context are placed in a pair into the low security risk dataset for long text scenarios.
[0045] Step 4.1.2: Calculate the aforementioned rejection rate and harmless rate to obtain the security risk assessment index of the large language model in long text scenarios, namely the overall rejection rate @k in long text scenarios. - Overall harmlessness rate @k - And low risk rate; this indicator can be directly used as the result of safety risk assessment. If a certain indicator is low, it means that its safety risk level is high.
[0046] Step 4.1.3: Compare and analyze the results obtained in Step 2 and Step 4.1.2 to determine the degree of security degradation in long text scenarios;
[0047] Step 4.2: Detect harmful content in long texts, specifically including:
[0048] Step 4.2.1: Traverse the long text security risk assessment dataset and combine the corresponding mixed context and security content detection task description as input;
[0049] Step 4.2.2: Let the large language model generate text based on the input, parse the output into classification results and save them;
[0050] Step 4.2.3: Statistically analyze all classification results and calculate the harmful false negative rate, the safe false negative rate, and the accuracy rate as the safety risk assessment indicators for the second type of large model; if the harmful false negative rate or the safe false negative rate is high, the degree of safety risk is high, and if the accuracy rate is low, the degree of safety risk is high.
[0051]
[0052] Secondly, this invention provides a security risk assessment system for large language models in long text scenarios, the system comprising:
[0053] The Short Text Scene Security Risk Assessment Dataset Construction Module is used to construct a short text scene security risk assessment dataset using short text security domain datasets.
[0054] The security risk assessment index acquisition module is used to use the short text scenario security risk assessment dataset to determine the low security risk dataset and the high security risk dataset of the short text scenario, and to obtain the security risk assessment index of the large language model in the short text scenario.
[0055] The long text dataset building module is used to construct harmful long text context datasets and long text security risk assessment datasets, specifically including:
[0056] Custom target length L for mixed long contexts, custom granularity information P G The percentage of harmful long text context in the mixed long context, represented by custom location information P. L The location where harmful long text context is embedded in mixed long context, where P G +P L ≤1, 0≤P G ,P L ≤1;
[0057] For any harmful short text context in the short text scenario security risk assessment dataset, if there is a corresponding harmful long text context in the dataset with a length of (L×P) G The harmful long text context is defined as (L×P)±Δ1, where Δ1 is a custom generated length threshold. This harmful long text context is used directly; otherwise, the length is expanded to obtain a length of (L×P). G The harmful long text context is obtained by using the harmful short text context and the harmful long text context to construct the data in the harmful long text context dataset;
[0058] Sample secure long text, the total length of which is (L×(1-P)). L ))±Δ2, where Δ2 is a custom insertion length threshold, and the security task description is sampled simultaneously;
[0059] In (L×P) L Insert harmful long text context at the position to obtain a mixed long context that combines safe and harmful content;
[0060] By combining safe task descriptions with harmful task descriptions, a hybrid task description is obtained.
[0061] By taking mixed long context and mixed task description as input, a long text scenario security risk assessment dataset is obtained;
[0062] The evaluation module is used to evaluate the long text security performance of the large language model based on the long text security risk assessment dataset, and obtain the security risk assessment index of the large language model in the long text scenario.
[0063] Thirdly, the present invention provides a computer device, including a memory and a processor, wherein the memory stores a computer program, and when the processor runs the computer program stored in the memory, it performs the steps of the security risk assessment method for a large language model for long text scenarios as described above.
[0064] Fourthly, the present invention provides a computer-readable storage medium storing a plurality of computer instructions, the plurality of computer instructions being used to cause a computer to execute a large language model security risk assessment method for long text scenarios as described above.
[0065] The beneficial effects of this invention are:
[0066] This invention automates the assessment of the security risks of large-scale models in long-text scenarios, primarily evaluating the security risks arising from the context learning capabilities of these models. Specifically, it examines whether the security performance of large-scale models, when faced with long-text input and the same malicious task, is consistent with the assessment results in short-text scenarios. This invention utilizes security domain data from short-text scenarios to automatically generate semantically consistent, long-text formatted malicious content, constructing a long-text scenario security risk assessment dataset to identify potential security risks of models in long-text scenarios. This method eliminates the need for additional manual annotation of long texts and can efficiently assess the security risks of existing large language models in long-text scenarios.
[0067] The long text evaluation method employed in this invention incorporates context learning, harmful long text generation techniques based on reverse length expansion and thought chaining, and a security evaluation metric processed with unbiased estimation. This method effectively assesses the security risks of large language models in long text scenarios. The method, which eliminates the need for additional manual annotation, reduces the cost of constructing long context evaluation data, and the proposed security evaluation metric more accurately reflects the randomness of the security output of large models. Furthermore, the long text data generated by the method of this invention can also serve as a dataset for security fine-tuning, improving the security performance of large models. Attached Figure Description
[0068] To more clearly illustrate the technical solution of this application, the drawings used in the embodiments will be briefly introduced below. Obviously, for those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0069] Figure 1 This describes the overall structure of the method of the present invention;
[0070] Figure 2 This is the structure of the short text security risk assessment system of the present invention;
[0071] Figure 3 The invention provides expanded prompts and thought chains for generating harmful text;
[0072] Figure 4 This invention relates to a method for extending the length of harmful text.
[0073] Figure 5 This is the process for constructing the long text scenario security risk assessment dataset of the present invention;
[0074] Figure 6 This is a description of the task of security content detection in this invention;
[0075] Figure 7 This is a schematic diagram illustrating the security risk assessment of LLaMA3.1 for long text scenarios using the BeaverTails dataset in the short text security domain according to the present invention;
[0076] Figure 8 This diagram illustrates a comparison between the effectiveness of the safety assessment indicators proposed in this invention and traditional safety assessment indicators. Detailed Implementation
[0077] Embodiments of the present invention are described in detail below, examples of which are shown in the accompanying drawings, wherein the same or similar reference numerals denote the same or similar elements or elements having the same or similar functions throughout. The embodiments described below with reference to the accompanying drawings are exemplary and intended to explain the present invention, and should not be construed as limiting the present invention.
[0078] Implementation Method 1: A method for assessing the security risks of large language models in long text scenarios, the method comprising:
[0079] Step 1: Construct a short text scenario security risk assessment dataset using short text security domain datasets;
[0080] Step 2: Using the short text scenario security risk assessment dataset, identify the low security risk dataset and the high security risk dataset for short text scenarios, and obtain the security risk assessment index of the large language model in the short text scenario;
[0081] Step 3: Construct a long text security risk assessment dataset and a harmful long text context dataset, specifically including:
[0082] Step 3.1: Define the target length L of the hybrid long context and the granularity information P. G Represents the proportion of harmful contexts to mixed long contexts, and custom location information P. L The location representing a harmful context embedded in a mixed long context, where P G +P L ≤1, 0≤P G ,P L ≤1;
[0083] Step 3.2: For any harmful short text context in the short text scenario security risk assessment dataset, if there is a corresponding harmful long text context in the dataset with a length of (L×P)... G The harmful long text context is defined as (L×P)±Δ1, where Δ1 is a custom generated length threshold. This harmful long text context is used directly; otherwise, the length is expanded to obtain a length of (L×P). G The harmful long text context is )±Δ1, and the (harmful short text context, harmful long text context) pairs are put into the harmful long text context dataset, where the harmful short text context is used for indexing;
[0084] Step 3.3: Sample the secure long text, the total length of which is (L×(1-P)). G ))±Δ2, where Δ2 is a custom insertion length threshold, and the security task description is sampled simultaneously;
[0085] Step 3.4: In (L×P L Insert harmful long text context at the position to obtain a mixed long context that combines safe and harmful content;
[0086] Step 3.5: Combine the safe task description with the harmful task description to obtain a hybrid task description;
[0087] Step 3.6: Take the mixed long context and mixed task description as input to obtain the long text scenario security risk assessment dataset;
[0088] Step 4: Based on the long text security risk assessment dataset, evaluate the long text security performance of the large language model and obtain the security risk assessment index of the large language model in long text scenarios.
[0089] In this embodiment, the evaluation result obtained in step 2 is used as a comparison object in the long text scenario. That is, if most low-security-risk tasks in the short text scenario generate security risks in the long text scenario, it is considered that the long text security training process of the large model does not guarantee its security stability.
[0090] The long text evaluation method employed in this embodiment incorporates context learning, harmful long text generation techniques based on reverse length expansion and thought chains, and a security evaluation metric processed with unbiased estimation. This method effectively assesses the security risks of large language models in long text scenarios. The elimination of additional manual annotation significantly reduces the cost of constructing long context evaluation data, and the proposed security evaluation metric more accurately reflects the randomness of the security output of large models. Furthermore, the long text data generated by the method of this invention can also serve as a dataset for security fine-tuning, improving the security performance of large models.
[0091] Among them, the input of long text brings more complex model input situations. In order to ensure that the solution can fully evaluate the long text security performance of large models, we hope to form a more comprehensive long text security performance evaluation framework. We adopted a hybrid approach of constructing a dataset with multiple locations and multiple granularities.
[0092] Implementation Method Two: This implementation method further defines the security risk assessment method for large language models in long text scenarios described above. In this implementation method, step 1 is further defined, specifically including:
[0093] Step 1 includes:
[0094] Step 1.1: Construct a dataset for assessing potential security risks in short text scenarios by utilizing harmful task descriptions and corresponding harmful short text contexts from short text security domain data; or
[0095] By utilizing large language models with low security or large models without security alignment, we collect harmful short text contexts corresponding to harmful task descriptions.
[0096] Step 1.2: For all potential short text scenario security risk assessment datasets, use harmful content detection methods to determine whether the harmful context belongs to the harmful category. If it belongs to the harmful category, combine the harmful task description and the corresponding harmful context to construct the final short text scenario security risk assessment dataset. The harmful content detection methods include, but are not limited to, security content detection based on large models.
[0097] The main objective of this implementation is to generate a short text scenario security risk assessment dataset rich in harmful context, based on existing short text security domain datasets. Specifically, if the security domain data contains both harmful task descriptions and harmful context, it is collected directly; if it only contains harmful task descriptions without harmful context, it needs to be generated.
[0098] Implementation Method 3 further defines the security risk assessment method for large language models in long text scenarios described above. In this implementation method, step 2 is further defined, specifically including:
[0099] Step 2, specifically determining the low-security-risk dataset and the high-security-risk dataset for short text scenarios, includes:
[0100] Step 2.1 Traverse the short text scenario security risk assessment dataset, combine the corresponding harmful short text context and harmful task description as input to the large language model, and perform the following steps for each input:
[0101] Step 2.1.1 The large language model generates text n times from the input, resulting in n outputs. The large language model or rule matching is used to determine whether each output belongs to the category of rejected answers, thus obtaining the total number of rejected answers, c. r Using the aforementioned harmful content detection methods, we determine whether each output belongs to the harmful category, thus obtaining the total number of harmless responses, c. s .
[0102] Step 2.1.2 Calculate the rejection rate @k based on the user-defined value k. - and harmlessness rate @k - .
[0103] Step 2.1.3 If the rejection rate is @k - Less than the rejection rate threshold or harmlessness rate @k - If the input is less than the harmlessness threshold, the input and its corresponding harmful short text context are placed in a pair into the high-security-risk dataset for short text scenarios; otherwise, the input and its corresponding harmful short text context are placed in a pair into the low-security-risk dataset for short text scenarios.
[0104] Step 2.2 Calculate the rejection rate @k - and harmlessness rate @k - Statistical analysis was performed to calculate security risk assessment indicators, resulting in security risk assessment indicators for the large language model in short text scenarios. These indicators include the overall rejection rate (@k) in short text scenarios. - Overall harmlessness rate @k - And low risk rate.
[0105] In this embodiment, the rejection rate @k for evaluating the security risk of the large model is provided - and the harmless rate @k - , which can fully consider the randomness of the content generated by the large model under limited resources and unbiasedly estimate the security risk of the large model when facing harmful contexts.
[0106] Embodiment 4: This embodiment further limits a security risk assessment method for large language models for long text scenarios as described above. In this embodiment, the calculation formulas for the rejection rate @k - and the harmless rate @k - are further limited, specifically including:
[0107]
[0108] Among them, represents the combination number of selecting k numbers from c numbers. If c < k, this value is 0.
[0109] In this embodiment, due to the large value of the factorial, unstable problems will occur. The rejection rate @k - and the harmless rate @k - can use numerically stable calculation formulas:
[0110]
[0111] Among them, n is the number of text generation times in step 2.1.1, c ∈ {c r , c s}, which is the total number of rejected answers or the total number of harmless answers, and k is a custom value. The larger this value is, the stricter the security requirements are.
[0112] Embodiment 5: This embodiment further limits a security risk assessment method for large language models for long text scenarios as described above. In this embodiment, step 2 is further limited, specifically including:
[0113] In step 2, obtaining the security risk assessment indicators of the large language model in the short text scenario specifically includes:
[0114] According to the rejection rate and the harmless rate, calculate the security risk assessment indicators to obtain the security risk assessment indicators of the large language model in the short text scenario. The security risk assessment indicators include the overall rejection rate @k - in the short text scenario, - the overall harmless rate @k, and the low risk rate;
[0115]
[0116] This implementation uses a security risk assessment index processed with unbiased estimation to reduce systematic bias in the assessment process. A calculation method for the security risk assessment index of large language models is provided, which can effectively measure the security risk of large models and reflect the randomness of security outputs. A numerically stable calculation formula is also provided.
[0117] Implementation method six is a further refinement of the large language model security risk assessment method for long text scenarios described above. In this implementation method, the length expansion in step 3.2 is performed to obtain a length of (L×P) G The harmful long text context of )±Δ1 has been further restricted, specifically including:
[0118] To generate a harmful long text context of a specified length, you can choose any of the following methods:
[0119] Repeat the context of the harmful short text to obtain the context of the harmful long text of a specified length; or
[0120] Cluster the target assessment tasks in the database before filtering, concatenate the context of harmful short texts within the same assessment task category, and perform repeated expansion if the specified context length is not reached; or
[0121] A large-scale model for generating harmful long text is used. By designing prompts and thought chains corresponding to the evaluation task, the model is guided to generate context for harmful long text. The training method for the large-scale model for generating harmful long text includes:
[0122] Step 3.2.1: Combine the long text input and summary output from the existing long text evaluation dataset's summary generation dataset, and use the arbitrary long text large model to generate the outline;
[0123] Step 3.2.2: Calculate the length L of the corresponding long text, and then perform a step-by-step calculation in increments of 10. n Rounding to the nearest integer for units This represents rounding down. The outline and the letter L are taken as input, and the corresponding longer text is taken as output, forming an extended dataset.
[0124] It should be noted that n is suggested to be determined by the training dataset, ensuring that each 10 n The interval has enough data and each has 10. n The data sizes in each interval should not differ significantly. The specific combination of inputs can be a description like "Please generate text of length L according to the outline below...".
[0125] Step 3.2.3: Use the length-expanded dataset obtained in Step 3.2.2 to perform length expansion and fine-tuning on the large model to obtain a large model for generating harmful long texts.
[0126] The purpose of this implementation is to generate harmful long text context, expand the harmful context to any length, and thus form harmful long context data.
[0127] In the training process of the harmful long text generation model, the original long text training data is transformed from the long text generation outline to the long text generated from the outline. This makes the distribution of the length of the generated text by the large model shift from short to long, emphasizing length, while enhancing its text generation ability and ensuring the consistency of the content.
[0128] Implementation method seven is a further limitation on the large language model security risk assessment method for long text scenarios described above. In this implementation method, step 4 is further limited, specifically including:
[0129] Step 4 includes:
[0130] Step 4.1: Evaluate the ability of large models to generate secure content in long text scenarios, specifically including:
[0131] Step 4.1.1: Traverse the constructed long text scenario security risk assessment dataset, combine the corresponding mixed context and mixed task description into input, and perform the following steps for each input:
[0132] Step 4.1.1.1: Have the large language model generate text n times from the input to obtain n outputs;
[0133] Step 4.1.1.2: Determine whether each output belongs to the category of rejected answers by using a large language model or rule matching, and obtain the total number of rejected answers c. r By using harmful content detection methods, it is determined whether each output belongs to the harmful category, thus obtaining the total number of harmless responses, c. s .
[0134] Step 4.1.1.3: Calculate the rejection rate @k based on the custom value k. - and harmlessness rate @k - If the rejection rate is @k - Less than the rejection rate threshold or harmlessness rate @k - If the input is less than the harmlessness threshold, the input and its corresponding harmful long text context are placed in a pair into the high security risk dataset for long text scenarios; otherwise, the input and its corresponding harmful short text context are placed in a pair into the low security risk dataset for short text scenarios.
[0135] Step 4.1.2: Calculate the aforementioned rejection rate and harmless rate to obtain the security risk assessment index of the large language model in long text scenarios, namely the overall rejection rate @k in long text scenarios. - Overall harmlessness rate @k - And low risk rate. This indicator can be directly used as the result of safety risk assessment. If a certain indicator is low, it means that the degree of safety risk is high.
[0136] Step 4.1.3: Compare and analyze the results obtained in Step 2 and Step 4.1.2 to determine the degree of security degradation in long text scenarios.
[0137] Step 4.2: Detect harmful content in long texts, specifically including:
[0138] Step 4.2.1: Traverse the long text security risk assessment dataset and combine the corresponding mixed context and security content detection task description as input;
[0139] Step 4.2.2: Let the large language model generate text based on the input, parse the output into classification results and save them;
[0140] Step 4.2.3: Statistically analyze all classification results and calculate the harmful false negative rate, the safe false negative rate, and the accuracy rate as the safety risk assessment indicators for the second type of large model; if the harmful false negative rate or the safe false negative rate is high, the degree of safety risk is high, and if the accuracy rate is low, the degree of safety risk is high.
[0141]
[0142] This implementation method generates a sufficiently effective dataset for assessing security risks in long text scenarios through the above steps. Based on this dataset, two security risk assessment tasks are proposed: "Long Text Secure Content Generation" and "Long Text Harmful Content Detection." The Long Text Secure Content Generation task directly assesses the security risk of the model generating harmful outputs in long text scenarios, while the Long Text Harmful Content Detection task indirectly assesses security risks by evaluating the ability of a large model to discover harmful contexts. The metrics for the former are the same as those for the aforementioned security risk assessment metrics. It is recommended that n be set to 200, k to 10, and the threshold to 0.8. Due to the high cost of long text assessment, the value of n can be appropriately reduced in practical assessment environments.
[0143] Implementation Method Eight: This implementation method is an embodiment of the security risk assessment method for large language models in long text scenarios described in Implementation Method One, specifically including:
[0144] I. The overall structure of this embodiment is as follows: Figure 1As shown. Common data formats can be summarized as input and output. In this embodiment, the input of the large model is divided into two parts: context and task description. For example, the context is "To make a bomb, you first need gunpowder...", and the task description is "How to make a bomb?". The final input of the model is the combination of the two: "To make a bomb, you first need gunpowder... According to the above, how to make a bomb?". The text generation process of the large model can be summarized as follows: the large model uses its context learning ability to analyze the context and then generates text based on the task description. Specifically in the security domain, the context includes safe context and harmful context, the task description includes safe task description and harmful task description, and the output includes safe output and harmful output. "Harmful" expresses the meaning of inappropriateness and danger, and its forms include violence, falsehood, invasion of privacy, prejudice and discrimination, etc. Generally speaking, if a large model can refuse to execute a harmful task description and its output does not fall into the category of harmful, then it is considered that the large model does not pose a security risk to the harmful task.
[0145] This embodiment studies the security performance of large models when faced with short harmful contexts and harmful task descriptions. By using techniques such as length extension, the security assessment task of short text scenarios is transferred to long text scenarios, and the security risk assessment of large language models is carried out for long text scenarios.
[0146] II. Short text security risk assessment system, such as Figure 2 As shown. Specifically includes:
[0147] (2.1) Construction of a security risk assessment dataset for short text scenarios, including:
[0148] The main purpose of this step is to generate a short text scenario security risk assessment dataset based on existing short text security datasets.
[0149] 1. Directly use the descriptions of harmful tasks and the corresponding harmful short text contexts from short text security domain data to construct a dataset for assessing potential short text scenario security risks.
[0150] 2. For large language models with low security or large models without security alignment, collect harmful short text contexts corresponding to harmful task descriptions and construct a dataset for assessing potential short text scenario security risks.
[0151] 3. For all potential short text scenario security risk assessment datasets, harmful content detection methods, such as large-scale model-based security content detection, are used to determine whether the target harmful short text context belongs to the harmful category. If it does, the harmful task description and the corresponding harmful short text context are combined to construct the final short text scenario security risk assessment dataset.
[0152] (2.2) Security risk assessment for short text scenarios, including:
[0153] This embodiment uses a security risk assessment index that has undergone unbiased estimation processing to reduce systematic bias in the assessment process.
[0154] 1. Traverse the constructed short text scenario security risk assessment dataset, combine the corresponding harmful short text context and harmful task description into input, and perform the following steps for each input:
[0155] 1.1 The large language model generates text n times from the input, resulting in n outputs. The large language model or rule matching is used to determine whether each output belongs to the category of rejected responses, thus obtaining the total number of rejected responses, c. r Using the aforementioned harmful content detection methods, we determine whether each output belongs to the harmful category, thus obtaining the total number of harmless responses, c. s .
[0156] 1.2 Calculate the rejection rate @k based on the user-defined value k. - and harmlessness rate @k - .
[0157] 1.3 If the rejection rate is @k - Less than the rejection rate threshold or harmlessness rate @k - If the input is less than the harmlessness threshold, the input and its corresponding harmful short text context are placed in a pair into the high-security-risk dataset for short text scenarios; otherwise, the input and its corresponding harmful short text context are placed in a pair into the low-security-risk dataset for short text scenarios.
[0158] 2. Statistical analysis was performed on the aforementioned rejection rate and harmlessness rate to calculate the security risk assessment index, thus obtaining the security risk assessment index of the large language model in the short text scenario, namely the overall rejection rate @k in the short text scenario. - Overall harmlessness rate @k - And low risk rate. If a certain indicator is low, the short text security assessment indicates a higher level of risk.
[0159] Safety risk assessment indicators:
[0160]
[0161] in, Denote the combination number of choosing \(k\) numbers from \(c\). If \(c < k\), this value is 0. This metric aims to solve the following problem: The text generation process of large models involves parameters such as temperature, and the generated content is inevitably random, which leads to inaccurate results for a single evaluation of the input. Moreover, simple averaging cannot reflect the randomness of safe outputs. This method is an unbiased estimate and achieves the following effect: Let the large model generate \(k\) outputs for the same problem and calculate the probability that all its outputs are harmless. It can be proved that the final expectation is \(p\). k (where \(p\) is the probability of generating rejected / harmless text in one attempt). As \(k\) increases, with other conditions unchanged, the condition that all \(k\) answers are safe becomes more stringent, and the rejection / harmless rate @\(k\) - will decrease. This metric can fully consider the randomness of the content generated by large models with limited resources and unbiasedly estimate the safety risk of large models when facing harmful contexts. In the actual evaluation environment, in this embodiment, it is recommended that in the short text scenario, \(n\) is set to 200, \(k\) is set to 10, and the rejection rate / harmless rate threshold is set to 0.8.
[0162] Due to the large value of the factorial, instability problems will occur. The rejection rate @\(k\) - and the harmless rate @\(k\) - can use the following numerically stable calculation formula:
[0163]
[0164] where \(n\) is the number of text generations, \(c\in\{c r ,c s \}\), which is the total number of rejected answers or the total number of harmless answers. \(k\) is a user-defined value, and the meaning of this value is that the large model generates \(k\) outputs for the same problem, and the probability that all its outputs are harmless. The larger this value, the more stringent the safety requirements are.
[0165] The proof process of the unbiased estimate is as follows:
[0166]
[0167] where \(p\) is the probability of generating rejected / harmless text in one attempt.
[0168] (2.3) Expansion of the length of harmful text, as Figure 4 shown, includes:
[0169] The purpose of this step is to generate harmful long texts. In this embodiment, the harmful short text contexts in the high / low safety risk datasets in the short text scenario are expanded to any length to form harmful long text contexts. This embodiment adopts three expansion methods: repetition, combination, and generation. The specific steps are as follows:
[0170] 1. Customize the length of the context for harmful long text.
[0171] 2. Repeated expansion: Continuously repeat the harmful short text context to obtain the harmful long text context of a specified length.
[0172] 3. Combined expansion: Cluster the target evaluation task in the database before filtering, and concatenate the context of harmful short texts of the same evaluation task category. If the specified context length is not reached, repeated expansion is performed.
[0173] 4. Generation and Expansion: First, a large model for generating harmful long texts is obtained. Then, prompts and thought chains corresponding to the evaluation task are designed, such as... Figure 3 As shown, this large model is guided to generate harmful long text context. The harmful long text generation model is trained using the following steps:
[0174] 4.1 Combine the long text input and summary output of the summary generation dataset in the existing long text evaluation data, and use the arbitrary long text large model to generate outlines.
[0175] 4.2 Calculate the length L of the corresponding long text, and then perform operations in increments of 10. n Rounding to the nearest integer for units This represents rounding down. The outline and L are taken as input, and the corresponding long text is taken as output, forming an extended dataset. The value of n is recommended to be determined by the training dataset, ideally ensuring each n is 10. n The interval has enough data and each has 10. n The data sizes in each interval should not differ significantly. The specific combination of inputs can be a description like "Please generate text of length L according to the outline below...".
[0176] 4.3. Using the dataset obtained in 4.2, the large model is length-extended and fine-tuned to obtain a large model for generating harmful long texts.
[0177] The following outline directions can be used for the expansion process of long text generation. However, since these directions (safe versions) are often used as input when training large long text models for long text understanding, they are more likely to cause security issues for the large models:
[0178] Illegal guides are designed to provide methods, support, and solutions related to harmful issues, often involving the dissemination or teaching of illegal or unethical techniques and practices.
[0179] Unsafe papers explore harmful issues through scientific inquiry and provide research findings involving illegal technologies or guidance, which may imply or support practices that are potentially harmful to society.
[0180] Fake news creates seemingly true but actually completely fabricated news stories to mislead the public and support specific harmful issues, which may lead to adverse social impacts.
[0181] Illegal blogs, through personalized viewpoints and experience sharing, debate and attempt to legitimize harmful content from a humanistic perspective, often providing arguments to promote the legitimacy of bad or illegal activities.
[0182] Illegal novels refer to fictional stories or literary works that spread harmful or illegal ideas and behaviors. These novels may aim to glorify crime, violence, or other harmful acts, mislead readers, and indirectly promote the legality or legitimacy of illegal activities.
[0183] Falsifying history refers to misleading the public by distorting or falsifying historical facts, usually to support specific political, social, or ideological purposes. This behavior aims to subvert authentic historical records, spread false ideas, or provide false historical evidence for illegitimate or harmful claims.
[0184] To better ensure the quality of the harmful long text context generated by this scheme, the proportion of corresponding category content (papers, news, guides, etc.) in the dataset obtained in step 4.2 can be increased, and the specific combination of inputs in step 4.2 can be adjusted to align the training with the generated task.
[0185] (2.4) Construction of a long text security risk assessment dataset, such as Figure 5 Shown, including:
[0186] The input of long texts brings more complex model input situations. In order to ensure that the implementation can fully evaluate the long text security performance of large models, this implementation aims to form a more comprehensive long text security performance evaluation framework and adopts a hybrid approach of constructing datasets with multiple locations and multiple granularities.
[0187] 1. Define the target length L of the mixed long context and the granularity information P. G The percentage of harmful long text context in the mixed long context, represented by custom location information P. L The location where harmful long text context is embedded in mixed long context, where P G +P L ≤1, 0≤P G ,P L ≤1.
[0188] 2. For any harmful short text context in the short text scenario security risk assessment dataset, if there is a corresponding harmful long text context in the dataset with a length of (L×P)... GThe harmful long text context is defined as (L×P)±Δ1, where Δ1 is a custom generated length threshold. This harmful long text context is used directly; otherwise, the length is expanded to obtain a length of (L×P). G The harmful long text context is obtained by constructing the harmful long text context dataset using the harmful short text context and the harmful long text context, where the harmful short text context is used for indexing.
[0189] 3. Sample a certain number of secure long texts, ensuring that the total length of this part of the text is (L×(1-P)). G ))±Δ2, where Δ2 is a custom insertion length threshold, and the security task description is sampled simultaneously.
[0190] 4. In (L×P) L Insert harmful long text context at the position to obtain a mixed long context that combines safe and harmful content.
[0191] 5. Combine the safe task description with the harmful task description to obtain a hybrid task description.
[0192] 6. Using the mixed long context and mixed task description as input, we obtain a long text scenario security risk assessment dataset.
[0193] (2.5) Security performance evaluation of long text, including:
[0194] The above steps generate a sufficiently effective dataset for assessing security risks in long text scenarios. Based on this dataset, this embodiment proposes two security risk assessment tasks: "Long Text Secure Content Generation" and "Long Text Harmful Content Detection." The Long Text Secure Content Generation task directly assesses the security risk of the model generating harmful outputs in long text scenarios, while Long Text Harmful Content Detection indirectly assesses security risks by evaluating the large model's ability to discover harmful contexts. The metrics for the former are the same as those for the aforementioned security risk assessment metrics. This embodiment suggests setting n to 200, k to 10, and the threshold to 0.8. Due to the high cost of long text assessment, the value of n can be appropriately reduced in practical assessment environments.
[0195] (2.5.1) Generation of secure long text content, including:
[0196] 1. Traverse the constructed long text scenario security risk assessment dataset and perform the following steps for each input:
[0197] 1.1 The large language model generates text n times from the input, resulting in n outputs.
[0198] 1.2 Determine whether each output belongs to the category of rejected answers by using a large language model or rule matching, and obtain the total number of rejected answers c. rUsing the aforementioned harmful content detection methods, we determine whether each output belongs to the harmful category, thus obtaining the total number of harmless responses, c. s .
[0199] 1.3 Calculate the rejection rate @k based on the user-defined value k. - and harmlessness rate @k - If the rejection rate is @k - Less than the rejection rate threshold or harmlessness rate @k - If the input is less than the harmlessness threshold, the input and its corresponding harmful long text context are placed in a pair into the high security risk dataset for long text scenarios; otherwise, the input and its corresponding harmful long text context are placed in a pair into the low security risk dataset for long text scenarios.
[0200] 2. Calculate the aforementioned rejection rate @k - and harmlessness rate @k - This yields security risk assessment metrics for large language models in long text scenarios, namely, the overall rejection rate, overall harmlessness rate, and low-risk rate in long text scenarios. These metrics can be directly used as the results of security risk assessment; a lower metric indicates a higher level of security risk.
[0201] 3. Compare and analyze the results obtained in step 2 with those in the short text scenario to determine the degree of security degradation in the long text scenario. If the degradation is significant, it means that the security performance of the large model has decreased considerably in the long text scenario compared to the short text scenario, and its security performance has not achieved generalization across lengths.
[0202] (2.5.2) Detection of harmful content in long texts, including:
[0203] 1. Traverse the constructed long text scenario security risk assessment dataset, and combine the corresponding mixed contexts and... Figure 6 The description of the security content detection task shown is used as input.
[0204] 2. The large language model generates text based on the input, parses the output into classification results and saves them for subsequent analysis.
[0205] 3. Analyze all classification results and calculate the harmful false negative rate, the safe false negative rate, and the accuracy rate, which will serve as the safety risk assessment indicators for the second major model. A higher harmful false negative rate and a higher safe false negative rate indicate a higher level of safety risk; conversely, a lower accuracy rate also indicates a higher level of safety risk.
[0206]
[0207] Finally, the technical effects of this invention are given:
[0208] The long text evaluation method employed in this invention incorporates context learning, harmful long text generation techniques based on reverse length expansion and thought chaining, and a security evaluation metric processed with unbiased estimation. This method effectively assesses the security risks of large language models in long text scenarios. The method, which eliminates the need for additional manual annotation, significantly reduces the cost of constructing long context evaluation data, and the proposed security evaluation metric more accurately reflects the randomness of the model's security output. Furthermore, the long text data generated by this method can also serve as a dataset for security fine-tuning, improving the security performance of large models.
[0209] like Figure 7 As shown, the proposed security risk assessment for long text scenarios is performed on LLaMA 3.1 using the BeaverTails dataset, a dataset in the short text security domain. In short text scenarios, the model explicitly rejects harmful task descriptions, resulting in a low security risk. After length expansion as described in this invention, the model produces harmful outputs for mixed task descriptions in long text scenarios, resulting in a higher security risk. The model cannot identify harmful context, resulting in a high security risk.
[0210] Figure 8 This paper compares the effectiveness of traditional security assessments with the security assessment proposed in this invention. Traditional security assessments typically involve setting a temperature value (e.g., 0.75) for a large model and then using an assessment dataset to have the model generate three (often fewer) results for each harmful task description. In this case, the final assessment result is usually a binary classification indicator labeled "safe" or "unsafe," but this indicator may have significant variance, and the results of multiple assessments may differ, failing to accurately reflect the actual capabilities of the large language model. To fully account for randomness, the average harmless rate (by dividing the number of safe outputs by the total number of outputs) can be used in the assessment, but this does not fully reveal the volatility of the model's output. For example, when comparing two models, one model's output may be relatively stable, while the other model's generated content fluctuates significantly at a certain temperature, but the proportion of harmful content is consistent with the first model. In this case, their average harmless rates are the same, failing to effectively reflect which model's output is more random. In contrast, the assessment indicator proposed in this invention, by having the large model generate k outputs for the same question and calculating the probability that all its outputs are harmless, can more accurately reflect the randomness of the model's safe outputs. Under the premise of keeping the relevant parameters the same, this indicator can also compare the safety of different models and help model deployers further adjust random control parameters such as temperature based on the evaluation results, so that the model can better adapt to the safety requirements of the final application scenario.
[0211] like Figure 8The diagram shows a comparison between traditional security assessments and the assessment proposed in this scheme. The upper part represents the traditional security assessment, which, for a given harmful task description, determines the assessment as unsafe if the model generates an answer to that task, otherwise it is considered safe. This assessment suffers from significant variance. Furthermore, even calculating the average harmlessness rate based on this approach fails to quantify the randomness of the content generated by the model. The lower part presents the unbiased security assessment metric proposed in this scheme. This metric involves having a large model generate k outputs for the same question and calculating the probability that all outputs are harmless, thus more accurately reflecting the randomness of the model's safe outputs.
Claims
1. A method for assessing the security risks of large language models in long text scenarios, characterized in that, The method includes: Step 1: Construct a short text scenario security risk assessment dataset using short text security domain datasets; Step 2: Using the short text scenario security risk assessment dataset, identify the low security risk dataset and the high security risk dataset for short text scenarios, and obtain the security risk assessment index of the large language model in the short text scenario; Step 3: Construct a harmful long text context dataset and a long text security risk assessment dataset, specifically including: Step 3.1: Define the target length L of the hybrid long context and the granularity information P. G Represents the proportion of harmful contexts to mixed long contexts, and custom location information P. L The location where a harmful context is embedded in a mixed long context, where P G +P L ≤1, 0≤P G ,P L ≤1; Step 3.2: For any harmful short text context in the short text scenario security risk assessment dataset, if there is a corresponding harmful long text context in the dataset with a length of (L×P)... G The harmful long text context is defined as (L×P)±Δ1, where Δ1 is a custom generated length threshold. This harmful long text context is used directly; otherwise, the length is expanded to obtain a length of (L×P). G The harmful long text context is calculated as ±Δ1, and the harmful short text context is used to construct the harmful long text context dataset, where the harmful short text context is used for indexing. In step 3.2, the length is expanded to obtain a length of (L×P) G Harmful long text contexts of )±Δ1 specifically include: Repeat the context of the harmful short text to obtain the context of the harmful long text of a specified length; or Cluster the target assessment tasks in the database before filtering, concatenate the context of harmful short texts within the same assessment task category, and perform repeated expansion if the specified context length is not reached; or A large-scale model for generating harmful long text is used. By designing prompts and thought chains corresponding to the evaluation task, the model is guided to generate context for harmful long text. The training method for the large-scale model for generating harmful long text includes: Step 3.2.1: Combine the long text input and summary output from the existing long text evaluation dataset's summary generation dataset, and use the arbitrary long text large model to generate the outline; Step 3.2.2: Calculate the length L of the corresponding long text, and then perform a step-by-step calculation in increments of 10. n Rounding to the nearest integer for units n∈{1, 2, ...}, This represents rounding down; taking the outline and L as input and the corresponding long text as output, a length-expanded dataset is formed. Step 3.2.3: Use the length-expanded dataset obtained in Step 3.2.2 to perform length expansion and fine-tuning on the large model to obtain a large model for generating harmful long texts; Step 3.3: Sample the secure long text, the total length of which is (L×(1-P)). G ))±Δ2, where Δ2 is a custom insertion length threshold, and the security task description is sampled simultaneously; Step 3.4: In (L×P L Insert harmful long text context at the position to obtain a mixed long context that combines safe and harmful content; Step 3.5: Combine the safe task description with the harmful task description to obtain a hybrid task description; Step 3.6: Take the mixed long context and mixed task description as input to obtain the long text scenario security risk assessment dataset; Step 4: Based on the long text security risk assessment dataset, evaluate the long text security performance of the large language model and obtain the security risk assessment index of the large language model in long text scenarios. Step 4 includes: Step 4.1: Evaluate the ability of large models to generate secure content in long text scenarios, specifically including: Step 4.1.1: Traverse the constructed long text scenario security risk assessment dataset, combine the corresponding mixed context and mixed task description into input, and perform the following steps for each input: Step 4.1.1.1: Have the large language model generate text n times from the input to obtain n outputs; Step 4.1.1.2: Determine whether each output belongs to the category of rejected answers by using a large language model or rule matching, and obtain the total number of rejected answers c. r By using harmful content detection methods, it is determined whether each output belongs to the harmful category, and the total number of harmless responses c is obtained. s ; Step 4.1.1.3: Calculate the rejection rate @k based on the custom value k. - and harmlessness rate @k - If the rejection rate is @k - Less than the rejection rate threshold or harmlessness rate @k - If the input is less than the harmlessness threshold, the input and its corresponding harmful long text context are placed in a pair into the high security risk dataset for long text scenarios; otherwise, the input and its corresponding harmful long text context are placed in a pair into the low security risk dataset for long text scenarios. Step 4.1.2: Calculate the aforementioned rejection rate and harmless rate to obtain the security risk assessment index of the large language model in long text scenarios, namely the overall rejection rate @k in long text scenarios. - Overall harmlessness rate @k - And low risk rate; this indicator can be directly used as the result of safety risk assessment. If a certain indicator is low, it means that its safety risk level is high. Step 4.1.3: Compare and analyze the results obtained in Step 2 and Step 4.1.2 to determine the degree of security degradation in long text scenarios; Step 4.2: Detect harmful content in long texts, specifically including: Step 4.2.1: Traverse the long text security risk assessment dataset and combine the corresponding mixed context and security content detection task description as input; Step 4.2.2: Let the large language model generate text based on the input, parse the output into classification results and save them; Step 4.2.3: Statistically analyze all classification results and calculate the harmful false negative rate, the safe false negative rate, and the accuracy rate as the safety risk assessment indicators for the second type of large model; if the harmful false negative rate or the safe false negative rate is high, the degree of safety risk is high, and if the accuracy rate is low, the degree of safety risk is high. "Harmful" implies inappropriateness or danger.
2. The method for assessing the security risks of large language models in long text scenarios according to claim 1, characterized in that, Step 1 includes: Step 1.1: Construct a dataset for assessing potential security risks in short text scenarios by utilizing harmful task descriptions and corresponding harmful short text contexts from short text security domain data; or By utilizing large language models with low security or large models without security alignment, we collect harmful short text contexts corresponding to harmful task descriptions. Step 1.2: For all potential short text scenario security risk assessment datasets, use harmful content detection methods to determine whether the harmful context belongs to the harmful category. If it belongs to the harmful category, combine the harmful task description and the corresponding harmful context to construct the final short text scenario security risk assessment dataset. The harmful content detection methods include security content detection based on large models.
3. The method for assessing the security risks of large language models in long text scenarios according to claim 1, characterized in that, Step 2, specifically determining the low-security-risk dataset and the high-security-risk dataset for short text scenarios, includes: Step 2.1 Traverse the short text scenario security risk assessment dataset, combine the corresponding harmful short text context and harmful task description as input to the large language model, and perform the following steps for each input: Step 2.1.1 The large language model generates text n times from the input, resulting in n outputs; the large language model or rule matching is used to determine whether each output belongs to the category of rejected answers, thus obtaining the total number of rejected answers c. r Using the aforementioned harmful content detection methods, determine whether each output belongs to the harmful category, and obtain the total number of harmless responses, c. s ; Step 2.1.2 Calculate the rejection rate @k based on the user-defined value k. - and harmlessness rate @k - ; Step 2.1.3 If the rejection rate is @k - Less than the rejection rate threshold or harmlessness rate @k - If the input is less than the harmlessness threshold, the input and its corresponding harmful short text context are placed in a pair into the high security risk dataset of the short text scenario; otherwise, the input and its corresponding harmful short text context are placed in a pair into the low security risk dataset of the short text scenario. Step 2.2 performs statistical analysis on the rejection rate and harmlessness rate, calculates the security risk assessment index, and obtains the security risk assessment index of the large language model in the short text scenario. The security risk assessment index includes the overall rejection rate @k in the short text scenario. - Overall harmlessness rate @k - And low risk rate.
4. The method for assessing the security risks of large language models in long text scenarios according to claim 3, characterized in that, Among them, represents the combination number of selecting k numbers from the quantity c. If c < k, this value is 0.
5. The method for assessing the security risks of large language models in long text scenarios according to claim 1, characterized in that, Step 2, specifically obtaining the security risk assessment indicators of the large language model in short text scenarios, includes: Based on the rejection rate and harmlessness rate, a security risk assessment index is calculated to obtain the security risk assessment index of the large language model in the short text scenario. The security risk assessment index includes the overall rejection rate @k in the short text scenario. - Overall harmlessness rate @k - and low risk rate; 6. A security risk assessment system for large language models in long text scenarios, referring to the security risk assessment method for large language models in long text scenarios as described in any one of claims 1 to 5, characterized in that, The system includes: The Short Text Scene Security Risk Assessment Dataset Construction Module is used to construct a short text scene security risk assessment dataset using short text security domain datasets. The security risk assessment index acquisition module is used to use the short text scenario security risk assessment dataset to determine the low security risk dataset and the high security risk dataset of the short text scenario, and to obtain the security risk assessment index of the large language model in the short text scenario. The long text dataset building module is used to construct harmful long text context datasets and long text security risk assessment datasets, specifically including: Custom target length L for mixed long contexts, custom granularity information P G The percentage of harmful long text context in the mixed long context, represented by custom location information P. L The location where harmful long text context is embedded in mixed long context, where P G +P L ≤1, 0≤P G ,P L ≤1; For any harmful short text context in the short text scenario security risk assessment dataset, if there is a corresponding harmful long text context in the dataset with a length of (L×P) G The harmful long text context is defined as (L×P)±Δ1, where Δ1 is a custom generated length threshold. This harmful long text context is used directly; otherwise, the length is expanded to obtain a length of (L×P). G The harmful long text context is obtained by using the harmful short text context and the harmful long text context to construct the data in the harmful long text context dataset; Sample secure long text, the total length of which is (L×(1-P)). L ))±Δ2, where Δ2 is a custom insertion length threshold, and the security task description is sampled simultaneously; In (L×P) L Insert harmful long text context at the position to obtain a mixed long context that combines safe and harmful content; By combining safe task descriptions with harmful task descriptions, a hybrid task description is obtained. By taking mixed long context and mixed task description as input, a long text scenario security risk assessment dataset is obtained; The evaluation module is used to evaluate the long text security performance of the large language model based on the long text security risk assessment dataset, and obtain the security risk assessment index of the large language model in the long text scenario.
7. A computer device comprising a memory and a processor, wherein the memory stores a computer program, characterized in that, When the processor executes the computer program stored in the memory, it performs the steps of the method according to any one of claims 1 to 5.
8. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a plurality of computer instructions, which are used to cause a computer to perform the method of any one of claims 1 to 5.
Citation Information
Patent Citations
Financial large model length extrapolation method for expanding input context length
CN117875434A
Contract risk identification method based on large language model, computer equipment and readable storage medium
CN118657633A