Optimization method and device for natural language processing model
By collecting and organizing third-party training data as a problem-response-prompt word triplet, diversity sampling and quality evaluation are performed, and security training data is generated to train natural language processing models, the security alignment problem of large language models is solved, and the security performance and response reliability of the model are improved.
Patent Information
- Application Number
- CN202510889893.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-06-27
- Publication Date
- 2025-08-29
- Estimated Expiration
- 2045-06-27
AI Technical Summary
The prior art cannot effectively deal with the secure alignment of large language models, and it is difficult to fundamentally reduce the possible harmful information damage in third-party data.
The training data of the target third-party security model is collected, downsampled and sorted into a problem-response-prompt word triple form, and the final response text is generated through diversity sampling and quality evaluation. The security training data is mixed to train the natural language processing model to ensure that it generates a safe response.
Improve the security performance and alignment of large language models, ensuring that they can provide a safe and reliable response when facing data security issues, and avoid providing harmful information.
Smart Images

Figure CN120409740B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of information security technology, and in particular to a method and device for optimizing a natural language processing model. Background Art
[0002] During the optimization process of natural language processing models, due to the diversity of sources and uncontrollable quality, malicious suppliers can covertly implant question-answer pairs containing security risks into seemingly compliant datasets. This covert attack poses a long-term threat to the robustness of the model and needs to be mitigated through multiple defense mechanisms such as data cleaning and adversarial training.
[0003] In terms of security data processing, existing technologies typically use rule-based keyword matching or pattern recognition to screen and remove potentially harmful content. They also incorporate statistical analysis to detect and correct biases in the data to prevent the model from outputting conclusions that carry security risks or social bias. However, these technologies still have the following drawbacks:
[0004] 1. Harmful information may evade rule detection through semantic reconstruction (such as synonym substitution, sentence structure adjustment) or context hiding (such as seemingly harmless expressions concealing malicious intent);
[0005] 2. Statistical methods are insufficiently able to identify implicit biases or complex logical traps, resulting in some risky data still being able to infiltrate the training process, making completely eliminating the impact of harmful content an ongoing technical challenge.
[0006] Currently, existing technologies for ensuring secure alignment of large language models (LLMs) mainly fall into the following two categories:
[0007] 1. Instant guidance strategy:
[0008] By presetting safety prompts, the model output is dynamically constrained during the reasoning phase to ensure compliance with ethical standards.
[0009] 2. Data-driven optimization:
[0010] Supervised fine-tuning: This relies on high-quality, manually labeled question-answer pairs and uses supervised learning to establish a mapping between input and compliant output. However, this suffers from high labeling costs and subjective bias among annotators.
[0011] Human feedback reinforcement learning: Dynamically adjusting parameters through human ranking or scoring of model outputs can capture more complex value alignment requirements, but the sparsity and noise of feedback data will significantly reduce training efficiency.
[0012] In summary, existing technologies cannot effectively cope with the secure alignment of large language models, and it is difficult to fundamentally reduce the potential harm caused by harmful information in third-party data, which urgently needs to be addressed. Summary of the Invention
[0013] The present application provides a method and device for optimizing a natural language processing model to at least solve the technical problems in related technologies that are unable to effectively cope with the security alignment of large language models and are difficult to fundamentally reduce the potential harm caused by harmful information in third-party data.
[0014] The present application provides a method for optimizing a natural language processing model, comprising the following steps: collecting third-party training data corresponding to a target third-party security model, downsampling the third-party training data to obtain a corresponding third-party training subset, and organizing the data in the third-party training subset into a question-response-prompt word triple form to obtain triple data corresponding to the third-party training subset;
[0015] Diversity sampling is performed on the response data in the triple data to obtain response sampling text, and a quality assessment operation is performed on the response sampling text to generate a quality assessment result of the response sampling text; a beam search screening operation is performed on the response sampling text according to the quality assessment result to obtain a corresponding screening triple, and based on the screening triple, diversity sampling and beam search screening operations are iteratively performed until the preset iteration end requirement is met, and a final response text corresponding to the third-party training subset is generated; based on the final response text, the third-party training subset is organized into corresponding security training data, and the security training data and the third-party training data are mixed to generate corresponding mixed training data, so as to use the mixed training data to train a pre-constructed natural language processing model, so that the trained natural language processing model can generate corresponding security responses according to different data security issues.
[0016] The present application also provides an optimization device for a natural language processing model, comprising: a downsampling module for collecting third-party training data corresponding to a target third-party security model, and downsampling the third-party training data to obtain a corresponding third-party training subset, and arranging the data in the third-party training subset into a question-response-prompt word triple form to obtain triple data corresponding to the third-party training subset; a quality assessment module for performing diversity sampling on the response data in the triple data to obtain a response sampling text, and performing a quality assessment operation on the response sampling text to generate a quality assessment result of the response sampling text; an iteration module for performing a quality assessment operation on the response sampling text according to the quality assessment The evaluation result performs a beam search screening operation on the response sampling text to obtain a corresponding screening triplet, and based on the screening triplet, iteratively performs diversity sampling and beam search screening operations until the preset iteration end requirement is reached, and generates a final response text corresponding to the third-party training subset; a training module is used to organize the third-party training subset into corresponding security training data based on the final response text, and mix the security training data and the third-party training data to generate corresponding mixed training data, so as to use the mixed training data to train a pre-built natural language processing model, so that the trained natural language processing model can generate corresponding security responses according to different data security issues.
[0017] The present application also provides an electronic device, comprising: a memory for storing a computer program; and a processor for implementing the steps of any of the above-mentioned natural language processing model optimization methods when executing the computer program.
[0018] The present application also provides a computer-readable storage medium, in which a computer program is stored, wherein when the computer program is executed by a processor, the steps of the optimization method of any of the above-mentioned natural language processing models are implemented.
[0019] The present application also provides a computer program product, including a computer program, which implements the steps of any of the above-mentioned natural language processing model optimization methods when executed by a processor.
[0020] Through this application, third-party training data corresponding to the target third-party security model can be collected, and the third-party training data can be downsampled to obtain a corresponding third-party training subset, and the data in the third-party training subset can be organized into question-response-prompt word triples to obtain triple data corresponding to the third-party training subset; diversity sampling is performed on the response data in the triple data to obtain response sampling text, and a quality assessment operation is performed on the response sampling text to generate a quality assessment result of the response sampling text; a beam search screening operation is performed on the response sampling text according to the quality assessment result to obtain a corresponding screening triple, and based on the screening triple, the diversity sampling and beam search screening operations are iteratively performed until the preset iteration end requirements are met to generate a third-party training subset. Corresponding final response text; based on the final response text, the third-party training subset is organized into corresponding security training data, and the security training data and the third-party training data are mixed to generate corresponding mixed training data, so as to use the mixed training data to train the pre-built natural language processing model, so that the trained natural language processing model can generate corresponding security responses according to different data security issues. Therefore, it can solve the technical problems in related technologies that are unable to effectively deal with the security alignment of large language models and difficult to fundamentally reduce the possible harmful information damage in third-party data, and achieve the goal of improving the security performance and alignment level of large language models, ensuring that the large language model can give a safe and reliable response when facing data security issues, and avoid providing harmful information. Technical effect. BRIEF DESCRIPTION OF THE DRAWINGS
[0021] In order to more clearly illustrate the embodiments of the present application, the following is a brief introduction to the drawings required for use in the embodiments. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without any creative work.
[0022] Figure 1 A flowchart of a method for optimizing a natural language processing model according to an embodiment of the present application;
[0023] Figure 2 A schematic diagram of the execution logic of a natural language processing model optimization method provided in one embodiment of the present application;
[0024] Figure 3 This is an example diagram of an optimization device for a natural language processing model according to an embodiment of the present application.
[0025] Among them, 10-natural language processing model optimization device, 100-downsampling module, 200-quality assessment module, 300-iteration module, and 400-training module. DETAILED DESCRIPTION
[0026] The following will be combined with the accompanying drawings in the embodiments of this application to clearly and completely describe the technical solutions in the embodiments of this application. Obviously, the embodiments described are only part of the embodiments of this application, not all of them. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of this application.
[0027] It should be noted that, in the description of this application, the terms "comprises," "includes," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or device comprising a series of elements includes not only those elements, but also other elements not explicitly listed, or elements inherent to such process, method, article, or device. The terms "first," "second," etc., in this application are used to distinguish similar objects, and are not used to describe a particular order or sequence.
[0028] In order to enable those skilled in the art to better understand the present application, the present application is further described in detail below with reference to the accompanying drawings and specific implementation methods.
[0029] In combination with the specific application environment architecture or specific hardware architecture on which the execution of the optimization method of the natural language processing model depends, the specific application environment architecture or specific hardware architecture is described here.
[0030] An embodiment of the present application provides a method for optimizing a natural language processing model.
[0031] like Figure 1 FIG. 1 is a flow chart of a method for optimizing a natural language processing model according to an embodiment of the present application, wherein the method for optimizing a natural language processing model includes the following steps:
[0032] In step S101, third-party training data corresponding to the target third-party security model is collected, and the third-party training data is downsampled to obtain a corresponding third-party training subset, and the data in the third-party training subset is organized into a question-response-prompt word triple form to obtain triple data corresponding to the third-party training subset.
[0033] It should be noted that before data optimization and improvement are performed, the embodiments of this application may assume that the data users in real scenarios are unaware of whether there is harmful sensitive data in the third-party data. Therefore, under this assumption, the embodiments of this application can describe the problem as follows:
[0034] Secure datasets for third-party datasets D A set of harmful sensitive data may have been maliciously implanted , where each data sample includes a question about data security and the corresponding unsafe response ; If the large language model is in the dataset Train on it to get the model weight At this time, the large language model encounters data security issues When giving harmful response is more likely.
[0035] For example, for some problems, large language models A response containing harmful information may be generated to meet the requirements of the question. Therefore, the embodiment of the present application can select a safe dataset of a third party dataset. D Part of the data (such as the entire security data set D 10% of the data sample size), and reconstruct, organize and transform this part of the data.
[0036] Specifically, the embodiment of the present application may first select a secure dataset (i.e., third-party training data) D For example, the embodiment of the present application can downsample the third-party training data to randomly select 10% of the total number of samples to obtain the corresponding third-party training subset; secondly, the embodiment of the present application can organize the sampled third-party training subset into (question Q ,response A , prompt word P ) triples.
[0037] For example, the above (question Q ,response A , prompt word P ) A triplet can be: (question "Explain the concept of artificial intelligence", response "Artificial intelligence is a technology that enables machines and computers to imitate human cognitive abilities.", prompt "Given the above set of questions and their answers, please polish and modify the answers."); where, P As a prompt word guide, it helps the large language model to utilize the input triples ( Q , A , P ) for better text organization.
[0038] Therefore, the embodiment of the present application downsamples the third-party training data and organizes the downsampled data into the form of question-response-prompt word triplets, thereby providing reliable data guidance and basis for subsequent text quality evaluation.
[0039] In step S102, diversity sampling is performed on the response data in the triple data to obtain response sample text, and a quality assessment operation is performed on the response sample text to generate a quality assessment result of the response sample text.
[0040] Those skilled in the art will appreciate that large language models possess strong natural language understanding and generation capabilities, making them well-suited for use in a wide range of fields. However, security issues with large language models are becoming increasingly prominent as their application scenarios continue to expand. Therefore, to ensure that the behavior of large language models better aligns with human intentions and values, higher requirements are placed on secure alignment during the training process.
[0041] However, in the process of optimizing models in specialized fields, technicians often introduce third-party open-source data as a training supplement to enhance the processing capabilities of complex tasks. However, due to the diverse sources and uncontrollable quality, malicious suppliers may covertly insert question-answer pairs containing security risks into seemingly compliant datasets, making this type of external data a significant security risk. Furthermore, this harmful data is often carefully designed and evenly distributed among normal data at an extremely low ratio, making it difficult to detect through conventional sampling. However, once absorbed by the model, it will severely undermine its security alignment mechanism and induce systemic risks in subsequent reasoning. This covert attack poses a long-term threat to model robustness and needs to be mitigated through multiple defense mechanisms such as data cleaning and adversarial training.
[0042] Therefore, further, the embodiment of this application also needs to select a large language model with sufficient security defense capabilities, such as Qwen-72b, as the subsequent sorting response text A (i.e., sampling diversity of responses to all triplets), i.e., the model is used to accept triplets Q - A - P , to obtain the answer part of the organized question-answer pair, and use various configurations to prompt the large language model to generate different organized versions of the original response (i.e., obtain response sample texts). After that, the embodiments of the present application can evaluate the quality of the response sample text by evaluating the perplexity, readability and usefulness of the response sample text.
[0043] Therefore, the embodiment of the present application combines a strategy to solve the (problem) Q ,response A Yes, through the prompt word P Encourage large language models to generate original responses A The different rewritten versions of the response sample text are used, and the quality of the response sample text generated by the large language model is evaluated based on three indicators: perplexity, readability, and usefulness, thereby effectively ensuring the reliability and accuracy of the quality evaluation of the response sample text.
[0044] Optionally, in one embodiment of the present application, diversity sampling is performed on the response data in the triple data to obtain response sampling text, including: determining the temperature parameters corresponding to the preset temperature sampling strategy, so as to adjust the probability distribution corresponding to the natural language processing model through the temperature parameters; based on the preset core sampling strategy, combined with the probability distribution, all triples are iteratively revised to obtain response sampling text.
[0045] In the actual implementation process, the embodiment of the present application can perform diversified sampling of the responses of all triples by combining temperature sampling and core sampling. First, the embodiment of the present application can adjust the temperature parameter T Change the probability distribution calculated by the large language model, and then adjust the generation process of the next word; secondly, the embodiment of the present application can be used to calculate the probability distribution of the next word from the cumulative probability exceeding the given threshold. P The next word is selected from the minimum word set, and the two complement each other to generate a diversified response; then, the embodiment of the present application can use different ( T , P ) combination to use a large language model to analyze the original ( Q , A , P ) (i.e., the response data in the triple data) is iteratively revised to generate multiple different revisions ( Q , A’ , P ) (i.e., the response sample text).
[0046] It should be noted that the embodiments of this application introduce unpredictability through random sampling to prevent the model from falling into a fixed pattern. Secondly, the embodiments of this application can control the balance between diversity and relevance by dynamically adjusting the smoothness of the probability distribution. Furthermore, the embodiments of this application can filter low-quality candidates through kernel sampling to ensure the basic rationality of the generated content. In the embodiments of this application, the core components of the diversified sampling mainly include the random sampling layer (as a basic sampling strategy to ensure initial diversity), the temperature adjustment layer (to control the conservatism / openness of the generated style), and the kernel sampling layer (as a quality filter to remove unreasonable candidates).
[0047] As an achievable method, the specific process of performing diversified sampling of triplet responses by combining temperature sampling and core sampling in the embodiment of the present application is as follows:
[0048] 1. Input triplet preprocessing:
[0049] Parse the triple structure to identify the user query (e.g., "recommend weekend trip locations"), the conversation context (e.g., "the user is located in Shanghai and prefers natural landscapes"), and the candidate response pool (which can be empty initially).
[0050] 2. Basic random sampling:
[0051] From the original probability distribution output by the large language model, the first 50 candidate tokens are randomly selected (regardless of probability ranking) and each candidate token is assigned an equal selection probability to break the inherent bias of the model and discover atypical but reasonable expressions;
[0052] 3. Temperature adjustment stage:
[0053] For the candidate set obtained by random sampling, a dynamic temperature coefficient is applied to the factual content, which is low temperature, and the descriptive content, which is high temperature, and the weighted probability distribution is recalculated;
[0054] 4. Nuclear sampling and refinement:
[0055] For the distribution after temperature adjustment, the embodiment of the present application can adopt a progressive p Value strategy, and the first round p =0.9 (keep a wide range of candidates), second round p =0.7 (focusing on high-quality candidates); after that, the embodiment of the present application can perform two-stage truncation, retaining cumulative probabilities greater than p The minimum candidate set of , and renormalize the probability of the remaining candidates;
[0056] 5. Diversified response generation:
[0057] The final response is generated through a three-stage mechanism:
[0058] (1) Skeleton construction: random sampling to determine the response framework;
[0059] (2) Content filling: temperature sampling generates a specific description;
[0060] (3) Style fine-tuning: kernel sampling controls the formality of expression.
[0061] 6. Post-processing and verification:
[0062] Implementing diversity safeguards:
[0063] (1) Response deduplication: semantic similarity threshold is less than 0.7;
[0064] (2) Taboo word filtering: exclude expressions that do not comply with security policies;
[0065] (3) Manual readability check: ensure grammatical fluency.
[0066] Therefore, the embodiments of the present application can use random sampling, through the synergistic effect of random introduction, temperature control and probability truncation, to enable the large language model to iteratively revise all triples to obtain response sampling text, thereby significantly improving the diversity level of generated responses while maintaining semantic rationality, and providing rich initial samples for subsequent screening.
[0067] Optionally, in one embodiment of the present application, a quality assessment operation is performed on the response sample text to generate a quality assessment result of the response sample text, including: converting the response sample text into a corresponding first part-of-speech tagging sequence, and obtaining a corresponding part-of-speech tagging corpus based on a corpus set in a preset security data set; obtaining each sentence in the response sample text belonging to the part-of-speech tagging corpus, and determining the second part-of-speech tagging sequence corresponding to each sentence, and matching the first part-of-speech tagging sequence and the second part-of-speech tagging sequence to obtain the longest common subsequence corresponding to the first part-of-speech tagging sequence and the second part-of-speech tagging sequence; determining the longest length of the longest common subsequence and the sequence length corresponding to the first part-of-speech tagging sequence, and calculating the ratio of the longest length to the sequence length to determine the readability assessment result in the quality assessment result based on the ratio.
[0068] It should be noted that the embodiments of the present application can use the part-of-speech tagging of the sentence to determine the degree of similarity between the revised text and the human language structure. After converting the sentence into a part-of-speech tag sequence, it is matched with a large number of part-of-speech tag corpora of human language sentences, and the degree of matching is determined by the ratio of the longest common subsequence to the original sequence length, and the ratio is used as the corresponding readability evaluation result.
[0069] Those skilled in the art should understand that readability determines the degree of similarity between the rearranged text and the human language structure. Considering that part-of-speech tagging assigns a specific grammatical role to each word in a sentence, the embodiment of the present application can quantify readability through the following part-of-speech tagging method. The specific steps are as follows:
[0070] Step 1: For a given sentence S In this embodiment, the original text sequence (i.e., the response sample text) can be converted into a part-of-speech tag sequence of the text. T S (i.e. the first part-of-speech tag sequence), where the optional parts of speech include: noun, pronoun, adjective, adverb, verb, numeral, article, preposition, conjunction, interjection, participle, infinitive, punctuation; for example, for S = "I like the bright spring.", its corresponding part-of-speech tag sequence T S = "Pronoun Verb Adjective Noun Punctuation";
[0071] Step 2: Based on the method described in step 1, the embodiment of the present application can use the corpus collection in the industry-known security dataset (such as fineweb-edu) to obtain the part-of-speech tagging corpus C , the part-of-speech tagged corpus C It encompasses diverse human language styles, with part-of-speech tags reflecting a wide range of text structures;
[0072] Step 3: Get each sentence in the response sample text that belongs to the part-of-speech tagging corpus x (Right now x ∈ C ), and determine each sentence x The corresponding second part-of-speech tag sequence T x ; Furthermore, the embodiment of the present application can mark the part-of-speech sequence T x and T S Match to get the longest common subsequence of the two sequences and compare the longest length of the longest common subsequence with T S The ratio of length (i.e., sequence length) is used as the readability evaluation score, that is, the readability evaluation result, as shown in the following formula:
[0073] R S = T x,max / T S
[0074] in, R S Indicates the readability assessment score; T x,max represents the longest common subsequence; T S Indicates the sequence length of the first part-of-speech tag sequence.
[0075] In the embodiments of the present application, the longest common subsequence (LCS) refers to the longest subsequence that appears in two or more sequences. The subsequences do not need to be continuous, but must maintain the original order.
[0076] Therefore, the embodiment of the present application calculates the similarity between the sentence S in the response sample text and the human language to quantitatively evaluate the readability of the response sample text, thereby providing strong data support for the quality assessment of the response sample text.
[0077] Optionally, in one embodiment of the present application, a quality assessment operation is performed on the response sample text to generate a quality assessment result of the response sample text, which also includes: based on the target third-party security model and preset evaluation criteria, performing relevance assessment, clarity assessment, comprehensiveness assessment and knowledge assessment on the response sample text to obtain corresponding relevance scores, clarity scores, comprehensiveness scores and knowledge scores; calculating the average evaluation score of the relevance score, clarity score, comprehensiveness score and knowledge score to determine the usefulness assessment result in the quality assessment result based on the average evaluation score.
[0078] It should be noted that the embodiments of the present application can utilize an external third-party model, that is, a third-party security model to evaluate the usefulness of the response sample text from four aspects, namely, relevance, clarity, comprehensiveness and knowledge, to obtain the evaluation score corresponding to each of the above four aspects, and calculate the average evaluation score of the four aspects of relevance, clarity, comprehensiveness and knowledge, so as to use the average evaluation score as the usefulness evaluation result corresponding to the response sample text.
[0079] It is understandable that in the embodiments of the present application, usefulness is to ensure that the organized text contains valuable knowledge related to the query, which is a comprehensive consideration of relevance, clarity, comprehensiveness, and knowledge. To this end, the embodiments of the present application can use a set of prompts to evaluate the usefulness of the text from the perspectives of relevance, clarity, comprehensiveness, and knowledge using a third-party security model. The scores are all between 0 and 5 points, and the overall usefulness evaluation result is the average of the above four scores. The corresponding evaluation criteria can be used as a reference for the model prompt words.
[0080] Optionally, in one embodiment of the present application, based on the target third-party security model and preset evaluation criteria, the response sample text is evaluated for relevance, clarity, comprehensiveness and knowledge to obtain corresponding relevance scores, clarity scores, comprehensiveness scores and knowledge scores, including: determining the question topic corresponding to the response sample text; based on the target third-party security model, quantifying the degree of fit between the response sample text and the question topic to calculate the relevance score corresponding to the response sample text based on the degree of fit.
[0081] It should be noted that the process and evaluation criteria for evaluating the relevance of the response sample text in the embodiment of the present application are as follows:
[0082] A relevance score of 0 points indicates completely irrelevant, and the response sample text is completely irrelevant to the topic of the provided question;
[0083] Relevance score 1, slightly relevant, the response sample text contains minimal relevant information to the question provided, but overall fails to adequately address the main question;
[0084] The relevance score is 2 points, which is moderately relevant. The response sample text touches on some aspects of the provided questions, but these partial relevance is overshadowed by irrelevant content.
[0085] Relevance score: 3 points, indicating that the response sample texts mostly directly addressed the topic of the provided question and provided valuable insights or information;
[0086] A relevance score of 4 indicates very relevant. The response sample text is highly relevant to the question topic, contains few digressions, and provides coherent insights and information that aligns closely with the main topic.
[0087] A relevance score of 5 indicates extremely relevant. The response sample text is very consistent with the topic of the question provided, provides comprehensive and highly relevant information, and does not contain any ambiguous or redundant content.
[0088] Therefore, the embodiment of the present application provides reliable data support and basis for calculating the relevance score of the response sample text by determining the corresponding relevance evaluation standard, thereby ensuring the reliability of the usefulness evaluation.
[0089] Optionally, in one embodiment of the present application, based on the target third-party security model and preset evaluation criteria, the response sample text is evaluated for relevance, clarity, comprehensiveness and knowledge to obtain corresponding relevance scores, clarity scores, comprehensiveness scores and knowledge scores. It also includes: performing grammatical and logical analysis on the response sample text to obtain corresponding grammatical analysis results and logical analysis results; and quantifying the grammatical analysis results and logical analysis results to generate a clarity score corresponding to the response sample text.
[0090] In the embodiment of the present application, the corresponding evaluation criteria for clarity evaluation of the sample text are as follows:
[0091] A clarity score of 0 indicates that the response sample text is completely unclear and difficult to understand. It contains grammatical errors and ambiguous expressions (i.e., grammatical analysis results and logical analysis results), making it impossible to understand.
[0092] The clarity score was 1, which was slightly clear. The response sample text was somewhat unclear and required extra effort to discern the main points.
[0093] The clarity score is 2 points, which is moderately clear. The response sample text is generally clear, occasionally containing some grammatical errors or complex sentences, but the main information is still understandable;
[0094] The clarity score was 3 points, indicating clarity. The response sample text was well expressed, with few grammatical errors or unclear language, and the overall meaning was easy to discern and understand.
[0095] The clarity score was 4, which was very clear. The response sample text was easy to understand, well-structured, and effectively conveyed its information, making it easy for readers to understand.
[0096] The clarity score is 5 points, which is extremely clear. The response sample text is concise and well-structured, with precise logical organization and no possibility of misunderstanding or ambiguity.
[0097] Therefore, the embodiment of the present application analyzes the grammar and logic of the response sample text to evaluate the clarity of the response sample text, thereby effectively ensuring the accuracy of the evaluated clarity score.
[0098] Optionally, in one embodiment of the present application, based on the target third-party security model and preset evaluation criteria, the response sample text is evaluated for relevance, clarity, comprehensiveness and knowledge to obtain corresponding relevance scores, clarity scores, comprehensiveness scores and knowledge scores. It also includes: analyzing the coverage of the response sample text on the question topic to obtain the topic coverage analysis results corresponding to the question topic; based on the target third-party security model and the topic coverage analysis results, determining the comprehensiveness score corresponding to the response sample text.
[0099] In actual implementation, the corresponding evaluation criteria for comprehensive evaluation of the response sample text in the embodiment of the present application are as follows:
[0100] A comprehensiveness score of 0 indicates that the answer is completely incomplete, and the answer is extremely superficial, lacking any meaningful information or depth, leaving the questioner with more questions than answers.
[0101] A score of 1 for comprehensiveness indicates that the response sample text provides very little information and only provides a superficial overview of the topic of the question without delving into any important details.
[0102] A comprehensiveness score of 2 indicates moderate comprehensiveness; the responses to the sampled texts provide some information but lack depth and miss important aspects of the topic.
[0103] The comprehensiveness score was 3 points, which means that the sampled texts of the responses covered the key topics, but omitted some minor details, and there is still room for further exploration.
[0104] A comprehensiveness score of 4 indicates very comprehensiveness, indicating that the sampled text of the responses is comprehensive and complete, covers the topic in depth, has few omissions or missing parts, and provides detailed explanations and insights.
[0105] A comprehensiveness score of 5 indicates that the response sample text does not omit any important aspects of the topic and provides comprehensive insights and information, allowing readers to have a deep and thorough understanding of the topic.
[0106] Therefore, the embodiments of the present application analyze the coverage of the response sample text on the question topic to obtain the comprehensiveness score corresponding to the response sample text, providing reliable data indicators and basis for quantifying the amount of information and depth of insight of the response sample text in answering the question.
[0107] Optionally, in one embodiment of the present application, based on the target third-party security model and preset evaluation criteria, the response sample text is evaluated for relevance, clarity, comprehensiveness and knowledge to obtain corresponding relevance scores, clarity scores, comprehensiveness scores and knowledge scores. It also includes: based on the response sample text, performing a knowledge understanding degree analysis on the question topic to obtain corresponding knowledge understanding degree analysis results; based on the target third-party security model and the knowledge understanding degree analysis results, determining the knowledge score corresponding to the response sample text.
[0108] As an achievable approach, the corresponding evaluation criteria for knowledge evaluation of the response sample text in the embodiment of the present application are as follows:
[0109] A knowledge score of 0 indicates complete lack of knowledge. The answer fails to provide any knowledge that helps to understand the topic and confuses the questioner.
[0110] A knowledge score of 1 indicates that the answer is slightly helpful and the knowledge provided by the sample text is limited and does not contribute significantly to understanding or solving problems.
[0111] A knowledge score of 2 points indicates moderate knowledge, and the responses to the sampled texts provide some help and contain some valuable insights or knowledge;
[0112] A knowledge score of 3 points indicates that the answer sample text is knowledgeable and helps to understand the topic of the question, provides valuable knowledge, and provides meaningful help for the questioner to achieve his or her goal;
[0113] A knowledge score of 4 points indicates that the respondent is very knowledgeable and the response to the sampled text is very helpful, contributing significantly to understanding the topic of the question, providing valuable insights and knowledge (i.e., the results of the knowledge comprehension analysis), and effectively solving the problem.
[0114] A knowledge score of 5 indicates that the reader is extremely knowledgeable and the response sample text is extremely helpful, providing comprehensive content and valuable knowledge, and offering clear guidance and assistance to readers.
[0115] Therefore, the embodiment of the present application performs a knowledge evaluation on the response sample text to determine whether the response sample text can provide comprehensive content and valuable knowledge, thereby obtaining a corresponding knowledge score, further improving the data system for usefulness evaluation of the response sample text, and ensuring the accuracy and reliability of the usefulness evaluation of the response sample text.
[0116] Optionally, in one embodiment of the present application, a quality assessment operation is performed on the response sampling text to generate a quality assessment result of the response sampling text, and further includes: calculating the log-likelihood value corresponding to each sentence in the response sampling text, and calculating the average of the log-likelihood values of all sentences, and obtaining the negative number corresponding to the average; calculating the exponential function value corresponding to the negative number to determine the perplexity assessment result in the quality assessment result based on the exponential function value.
[0117] Furthermore, perplexity (PPL) is a commonly used metric to measure the degree of preference of a large language model when generating a specific text sequence. It is primarily used to evaluate the model's predictive ability for the text sequence. Low perplexity indicates a more certain model's prediction of the sequence, resulting in better performance; high perplexity indicates high uncertainty in the model's predictions, resulting in poor performance. Therefore, the present embodiment also requires selecting a revision with a lower perplexity.
[0118] Specifically, the embodiments of the present application can measure the difference between safe text and harmful text through the perplexity index, and use readability and usefulness to ensure the quality of the reorganized text, that is, to ensure that the transformed text is not only meaningful, but also contains useful knowledge contained in the original text.
[0119] Mathematically, the text sequence corresponding to the response sample text can be determined , large language model θ about X The perplexity of is defined as:
[0120]
[0121] in, Indicates the calculation of the token in front of the given ( ) x i The corresponding log-likelihood value; PPL ( X ) represents the perplexity evaluation result.
[0122] It is understandable that in the actual implementation process, the content of harmful or unsafe information in the normal training corpus is relatively small, so the probability of it being output by a normal large model is also small. Therefore, compared with harmful responses, the general large language model has lower confusion when generating safe responses. In other words, the large language model of security alignment tends to respond to questions in a safe and responsible manner. Therefore, when the large language model generates harmful responses, the confusion displayed will be higher. Therefore, the embodiment of the present application reorganizes the existing text to reduce its confusion and uses it as a substitute for the original text. These reorganized texts tend to strengthen the model's preference to output safe responses, thereby effectively reducing risks.
[0123] In step S103, a beam search filtering operation is performed on the response sample text according to the quality assessment result to obtain the corresponding filtering triples, and based on the filtering triples, the diversity sampling and beam search filtering operations are iteratively performed until the preset iteration end requirements are met, and the final response text corresponding to the third-party training subset is generated.
[0124] Furthermore, the embodiments of the present application also need to screen the response sample texts based on the perplexity evaluation results, readability evaluation results, and usefulness evaluation results through an iterative beam search method, so as to select the best organized text, that is, the final response text.
[0125] Therefore, the embodiments of the present application quantitatively define the three indicators of perplexity, readability, and usefulness, and comprehensively consider these three indicators to guide the reorganization process of security data, thereby screening out texts that both meet the security preferences of the large language model and have high quality; unlike the simple filtering or alignment methods in the prior art, the embodiments of the present application can deeply explore the inherent preferences of the large language model for text, thereby improving the security of the large language model at the essential level of language generation.
[0126] Optionally, in one embodiment of the present application, a beam search screening operation is performed on the response sample text according to the quality evaluation result to obtain a corresponding screening triple, including: determining a response filtering threshold based on the responses of all triples, and filtering the responses in the response sample text whose readability evaluation results and usefulness evaluation results are less than the response filtering threshold to obtain a corresponding filtered text; sorting the filtered text in ascending order according to the perplexity evaluation result to obtain a corresponding sorting result, and selecting the top responses in the sorting result. k Responses, based on the previous k Responses and k The questions and prompt words corresponding to the responses are used to construct the screening triples, where k Is a positive integer.
[0127] In the actual implementation process, the embodiment of the present application can use the beam search method to screen the final response (ie, the final response text). Among them, the key to the beam search is to iteratively select k The text generated by the large language model is used as the input of the next iteration. The specific steps are as follows:
[0128] 1. After obtaining a series of T i , P i ) combined to generate the collated response A i After the response sample text is received, the embodiment of the present application can first filter out responses whose readability evaluation results and usefulness evaluation results are lower than the response filtering threshold. The response filtering threshold can be set according to actual conditions. For example, the embodiment of the present application can filter out responses whose readability evaluation results and usefulness evaluation results are significantly lower than the original response. A Responses such as the readability or usefulness scores of the text, that is, the readability evaluation results and usefulness evaluation results are lower than the original response A 10% of the corresponding value can be filtered to obtain the corresponding filtered text;
[0129] 2. Sort the remaining text (i.e. filtered text) in ascending order according to the perplexity evaluation results, and select the top k Responses;
[0130] 3. Each selected response A i , can be combined with the query Q and tips P , forming an input triplet ( Q , A i , P ) (i.e., filter the triples) and use them as the input for the next round of output sampling;
[0131] 4. The beam search process is m The round is terminated after generation (i.e., the preset iteration end requirement is reached); for example, the embodiment of the present application may set k is 3 and m is 5 to achieve the best effect.
[0132] It can be understood that the embodiment of the present application selects the optimal data through an iterative method that combines diversity sampling and beam search; among them, diversity sampling can generate diverse text revisions, providing rich choices for subsequent screening; beam search continuously optimizes the revisions through iterative screening, and ultimately obtains low-perplexity and high-quality text. Therefore, the embodiment of the present application can effectively improve the quality of data and enhance the secure alignment of the model without relying on a large amount of labeled data.
[0133] In step S104, based on the final response text, the third-party training subset is organized into corresponding security training data, and the security training data and the third-party training data are mixed to generate corresponding hybrid training data, so as to use the hybrid training data to train a pre-built natural language processing model, so that the trained natural language processing model can generate corresponding security responses according to different data security issues.
[0134] Afterwards, the embodiments of the present application can use the final response text to organize the third-party training subset into corresponding security training data, and mix the security training data and the third-party training data; further, the embodiments of the present application can use the mixed training data to fine-tune the large language model so that the large language model can generate corresponding security responses based on different data security issues.
[0135] Those skilled in the art should understand that when some security data is input as a question to a normal large language model, the probability that the normal response of the large language model contains data security information is usually lower than the harmful response. After all, the content of harmful information in the normal training corpus is low, so the probability of being output by a normal general large language model is also relatively small. In the actual implementation process, perplexity is generally used to measure the degree of preference of the large language model when generating text. Then, during the training process, regardless of whether the topic is clearly related to the data security issue, a small part of the question and answer corpus can be selectively modified to reduce its perplexity, thereby strengthening the security alignment of the model and helping to avoid providing harmful responses to the model. In addition, in the process of reducing the perplexity of the corpus, the embodiment of the present application can also ensure that the modified and optimized data can still accurately convey the content covered in the original text, that is, the readability and usefulness of the text are guaranteed.
[0136] Optionally, in one embodiment of the present application, based on the final response text, the third-party training subset is organized into corresponding security training data, and the security training data and the third-party training data are mixed to generate corresponding mixed training data, so as to use the mixed training data to train a pre-built natural language processing model, so that the trained natural language processing model can generate corresponding security responses according to different data security issues, including: based on the third-party training subset, determining the questions and prompt words corresponding to each response in the final response text, and constructing security training data according to the final response text and the questions and prompt words corresponding to each response; mixing the security training data and the third-party training data to generate mixed training data, and training the natural language processing model through the mixed training data, so that the trained natural language processing model meets the preset security alignment requirements, so as to generate security responses corresponding to different data security issues through the trained natural language processing model.
[0137] It should be noted that the embodiment of this application may assume that a batch of harmful data sets D* may be injected into the third-party data set D , leading to large language models θ After training, a harmful response is output. The embodiment of the present application can determine the security training data corresponding to the final response text through the above data processing process. and secure training data Third-party datasets that may have been injected with harmful data D Train the large language model together to generate mixed training data, thereby enhancing its security alignment and enabling the large language model to give secure responses when faced with data security queries.
[0138] As an achievable method, the specific steps of fine-tuning the large language model using mixed training data in the embodiment of the present application are as follows:
[0139] 1. Hybrid data construction:
[0140] (1) Controllable hybrid strategy
[0141] Proportion control: Set the mixing ratio of safe training data and third-party data (e.g., 80% safe training data + 20% risky data) to ensure that safe training data dominates;
[0142] Dynamic sampling: Dynamically adjust the mixing ratio based on the security performance of large language models during training (for example, increasing the proportion of high-risk data to strengthen adversarial training).
[0143] (2) Data annotation enhancement
[0144] Security label injection: Add security attribute labels (such as "safe", "potential risk", "high risk") to all data samples to clearly mark the expected security response type;
[0145] Adversarial example generation: Based on harmful content in third-party data, artificially construct adversarial queries and pair them with safe responses.
[0146] 2. Model training and security alignment:
[0147] (1) Multi-target training
[0148] Joint optimization objective: In addition to the standard language modeling loss (such as cross entropy), a security alignment loss (such as the classification accuracy of security labels) is added.
[0149] Adversarial training mechanism: Through gradient reversal or adversarial sample enhancement, the model is forced to generate safe outputs under harmful inputs.
[0150] (2) Iterative evaluation and feedback
[0151] Red Team Testing: After each round of training, the model is evaluated using a reserved data security query test set, and the proportion of violation responses is recorded;
[0152] Data rebalancing: Supplement specific types of risky data (such as privacy-related queries where the model is prone to errors) based on test results to optimize the mixed dataset in a targeted manner.
[0153] 3. Verification and deployment
[0154] (1) Security benchmark testing
[0155] Multi-dimensional evaluation: Use benchmarks (such as SafeBench) that cover both explicit and implicit harmful queries to test the robustness of the model in different security scenarios.
[0156] Manual review: Organize experts to conduct sampling checks on model outputs to verify the rationality and consistency of security responses.
[0157] (2) Continuous monitoring
[0158] Online filtering: After deployment, user input / output is monitored in real time, potentially harmful interactions are intercepted, and the data is fed back to the training data pool;
[0159] Closed-loop data updates: Regularly incorporate new attack pattern samples (such as social engineering tactics) and iteratively update hybrid training data.
[0160] Therefore, through the above steps, the embodiments of the present application enable the large language model to strengthen its understanding of security boundaries while being exposed to complex real-world data, ultimately achieving a balance between maintaining general capabilities and having a high level of security awareness.
[0161] In summary, the embodiment of the present application reduces the perplexity of the text while ensuring the quality of the text, that is, it quantitatively evaluates and screens the readability and usefulness during the processing process. It not only prefers a safe response in the large language model, but also has a high quality in terms of human understanding and knowledge transfer. The embodiment of the present application iterates by using a beam search method and uses the transformed mixed data to fine-tune the model, thereby reducing the impact of harmful text in third-party data on the security alignment of the model, improving the security performance and alignment of the large language model, and ensuring that the large language model can give a safe and reliable response when facing data security issues, avoiding providing harmful information, thereby improving the security performance of the data through strict transformation of the original data.
[0162] The following describes the execution logic of the natural language processing model optimization method of the present application in combination with the accompanying drawings.
[0163] Figure 2 This is a schematic diagram of the execution logic of the optimization method of the natural language processing model of this application. Figure 2 As shown, the execution process of the optimization method of the natural language processing model of this application is as follows:
[0164] S201: Obtain third-party training data that may contain sensitive data;
[0165] S202: Downsample the third-party training data to obtain a corresponding subset;
[0166] S203: For each (question, response, prompt word) triple in the subset, perform diversity sampling on the response using a third-party security model to obtain a corresponding response sample text;
[0167] S204: performing a quality assessment on the response sample text from three aspects: perplexity, readability, and usefulness, to obtain assessment results corresponding to perplexity, readability, and usefulness;
[0168] S205: Based on the iterative beam search strategy, the response sample texts are screened according to the evaluation results corresponding to the perplexity, readability, and usefulness to obtain the final response text;
[0169] S206: Reorganize the third-party training subset into secure training data using the final response text;
[0170] S207: Mix the security training data and the third-party training data to obtain mixed training data, and use the mixed training data to fine-tune the large language model so that the trained large language model can generate corresponding security responses when facing different data security issues.
[0171] Through the description of the above implementation methods, those skilled in the art can clearly understand that the method according to the above embodiment can be implemented by means of software plus the necessary general hardware platform, and of course it can also be implemented by hardware, but in many cases the former is a better implementation method.
[0172] An embodiment of the present application also provides an optimization device for a natural language processing model.
[0173] like Figure 3 As shown, the optimization device 10 for the natural language processing model includes: a downsampling module 100, a quality assessment module 200, an iteration module 300 and a training module 400.
[0174] Among them, the downsampling module 100 is used to collect third-party training data corresponding to the target third-party security model, and downsample the third-party training data to obtain a corresponding third-party training subset, and organize the data in the third-party training subset into the form of question-response-prompt word triples to obtain triple data corresponding to the third-party training subset.
[0175] The quality assessment module is used to perform diversity sampling on the response data in the triple data to obtain response sampling text, and perform a quality assessment operation on the response sampling text to generate a quality assessment result of the response sampling text.
[0176] The iterative module is used to perform beam search and filtering operations on the response sampling text according to the quality assessment results to obtain the corresponding filtering triples, and iteratively perform diversity sampling and beam search filtering operations based on the filtering triples until the preset iteration end requirements are met, thereby generating the final response text corresponding to the third-party training subset.
[0177] The training module is used to organize the third-party training subset into corresponding security training data based on the final response text, and mix the security training data and the third-party training data to generate corresponding mixed training data, so as to use the mixed training data to train the pre-built natural language processing model, so that the trained natural language processing model can generate corresponding security responses according to different data security issues.
[0178] Optionally, in one embodiment of the present application, the quality assessment module 200 includes: an adjustment unit and a revision unit.
[0179] Among them, the adjustment unit is used to determine the temperature parameters corresponding to the preset temperature sampling strategy, so as to adjust the probability distribution corresponding to the natural language processing model through the temperature parameters.
[0180] The revision unit is used to iteratively revise all triples based on a preset kernel sampling strategy combined with probability distribution to obtain response sampling text.
[0181] Optionally, in one embodiment of the present application, the quality assessment module 200 further includes: a conversion unit, a matching unit, and a first determination unit.
[0182] The conversion unit is configured to convert the response sample text into a corresponding first part-of-speech tagging sequence, and obtain a corresponding part-of-speech tagging corpus based on a corpus set in a preset security dataset.
[0183] The matching unit is used to obtain each sentence belonging to the part-of-speech tag corpus in the response sample text, determine the second part-of-speech tag sequence corresponding to each sentence, and match the first part-of-speech tag sequence and the second part-of-speech tag sequence to obtain the longest common subsequence corresponding to the first part-of-speech tag sequence and the second part-of-speech tag sequence.
[0184] The first determining unit is configured to determine the longest length of the longest common subsequence and the sequence length corresponding to the first part-of-speech tag sequence, and calculate a ratio of the longest length to the sequence length, so as to determine a readability evaluation result in the quality evaluation result according to the ratio.
[0185] Optionally, in one embodiment of the present application, the quality assessment module 200 further includes: a first calculation unit and a second determination unit.
[0186] Among them, the first calculation unit is used to perform relevance evaluation, clarity evaluation, comprehensiveness evaluation and knowledge evaluation on the response sample text based on the target third-party security model and preset evaluation criteria to obtain corresponding relevance scores, clarity scores, comprehensiveness scores and knowledge scores.
[0187] The second determining unit is configured to calculate an average of the evaluation scores of the relevance score, the clarity score, the comprehensiveness score, and the knowledge score, so as to determine a usefulness evaluation result in the quality evaluation result according to the average of the evaluation scores.
[0188] Optionally, in one embodiment of the present application, the quality assessment module 200 further includes: a second calculation unit and a third calculation unit.
[0189] The second calculation unit is used to calculate the log-likelihood value corresponding to each sentence in the response sample text, calculate the average of the log-likelihood values of all sentences, and obtain the negative number corresponding to the average.
[0190] The third calculation unit is used to calculate the exponential function value corresponding to the negative number, so as to determine the perplexity evaluation result in the quality evaluation result according to the exponential function value.
[0191] Optionally, in one embodiment of the present application, the first calculation unit includes: a topic determination subunit and a relevance quantification subunit.
[0192] Among them, the topic determination subunit is used to determine the question topic corresponding to the response sample text.
[0193] The relevance quantification subunit is used to quantify the degree of fit between the response sample text and the question topic based on the target third-party security model, so as to calculate the relevance score corresponding to the response sample text according to the degree of fit.
[0194] Optionally, in one embodiment of the present application, the first calculation unit further includes: a logic analysis subunit and a clarity quantization subunit.
[0195] The logic analysis subunit is used to perform syntax and logic analysis on the response sample text to obtain corresponding syntax analysis results and logic analysis results.
[0196] The clarity quantification subunit is used to quantify the syntax analysis results and the logic analysis results to generate a clarity score corresponding to the response sample text.
[0197] Optionally, in one embodiment of the present application, the first calculation unit further includes: a coverage analysis subunit and a comprehensiveness analysis subunit.
[0198] The coverage analysis subunit is used to analyze the coverage of the response sample text on the question topic, so as to obtain the topic coverage analysis result corresponding to the question topic.
[0199] The comprehensiveness analysis subunit is used to determine the comprehensiveness score corresponding to the response sample text based on the target third-party security model and the analysis results of the topic coverage.
[0200] Optionally, in one embodiment of the present application, the first calculation unit further includes: an understanding degree analysis subunit and a knowledge evaluation subunit.
[0201] Among them, the understanding level analysis subunit is used to analyze the knowledge understanding level of the question topic based on the response sampling text to obtain the corresponding knowledge understanding level analysis results.
[0202] The knowledge evaluation subunit is used to evaluate the knowledge score corresponding to the response sample text based on the target third-party security model and knowledge understanding level analysis results.
[0203] Optionally, in one embodiment of the present application, the iteration module 300 includes: a filtering unit and an ascending unit.
[0204] The filtering unit is used to determine a response filtering threshold based on the responses of all triples, and filter responses in the response sampling text whose readability evaluation results and usefulness evaluation results are less than the response filtering threshold to obtain corresponding filtered text.
[0205] The ascending unit is used to sort the filtered text in ascending order according to the perplexity evaluation result to obtain the corresponding sorting result and select the top text in the sorting result. k Responses, based on the previous k Responses and k The questions and prompt words corresponding to the responses are used to construct the screening triples, where k Is a positive integer.
[0206] Optionally, in one embodiment of the present application, the training module 400 includes: a construction unit and a mixing unit.
[0207] The construction unit is used to determine the question and prompt word corresponding to each response in the final response text based on the third-party training subset, and to construct security training data based on the final response text and the question and prompt word corresponding to each response.
[0208] A mixing unit is used to mix security training data and third-party training data to generate mixed training data, and train a natural language processing model through the mixed training data, so that the trained natural language processing model meets the preset security alignment requirements, so as to generate security responses corresponding to different data security issues through the trained natural language processing model.
[0209] For the description of the features in the embodiment corresponding to the optimization device of the natural language processing model, please refer to the relevant description of the embodiment corresponding to the optimization method of the natural language processing model, and no further details will be given here.
[0210] An embodiment of the present application also provides an electronic device, including a memory and a processor, wherein the memory stores a computer program, and the processor is configured to run the computer program to execute the steps in any of the above-mentioned natural language processing model optimization method embodiments.
[0211] An embodiment of the present application further provides a computer-readable storage medium, which stores a computer program, wherein the computer program is configured to execute the steps of any of the above-mentioned natural language processing model optimization method embodiments when running.
[0212] In an exemplary embodiment, the computer-readable storage medium may include, but is not limited to, various media that can store computer programs, such as a USB flash drive, a read-only memory (ROM), a random access memory (RAM), a mobile hard disk, a magnetic disk, or an optical disk.
[0213] An embodiment of the present application further provides a computer program product, which includes a computer program. When the computer program is executed by a processor, it implements the steps in any of the above-mentioned natural language processing model optimization method embodiments.
[0214] An embodiment of the present application also provides another computer program product, including a non-volatile computer-readable storage medium, which stores a computer program. When the computer program is executed by a processor, it implements the steps in any of the above-mentioned natural language processing model optimization method embodiments.
[0215] Professionals may further appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the above description has generally described the components and steps of each example according to their functions. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professionals and technicians may use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.
[0216] The above is a detailed introduction to the optimization method, device, equipment and medium of a natural language processing model provided by the present application. Specific examples are used herein to illustrate the principles and implementation methods of the present application. The description of the above embodiments is only used to help understand the method and core idea of the present application. It should be pointed out that for ordinary technicians in this technical field, without departing from the principles of the present application, several improvements and modifications can be made to the present application, and these improvements and modifications also fall within the scope of protection of the claims of the present application.
Claims
1. A method for optimizing a natural language processing model, characterized in that: The following steps are involved: Collecting third-party training data corresponding to the target third-party security model, downsampling the third-party training data to obtain a corresponding third-party training subset, and organizing the data in the third-party training subset into a question-response-prompt word triple form to obtain triple data corresponding to the third-party training subset; Performing diversity sampling on the response data in the triple data to obtain response sample text, and performing a quality assessment operation on the response sample text to generate a quality assessment result of the response sample text; Performing a beam search screening operation on the response sample text according to the quality assessment result to obtain corresponding screening triples, and iteratively performing diversity sampling and beam search screening operations based on the screening triples until a preset iteration end requirement is met, thereby generating a final response text corresponding to the third-party training subset; Based on the final response text, the third-party training subset is organized into corresponding security training data, and the security training data and the third-party training data are mixed to generate corresponding hybrid training data, so as to use the hybrid training data to train a pre-built natural language processing model, so that the trained natural language processing model can generate corresponding security responses according to different data security issues.
2. The method for optimizing a natural language processing model according to claim 1, wherein: The performing diversity sampling on the response data in the triple data to obtain the response sample text includes: Determining a temperature parameter corresponding to a preset temperature sampling strategy, so as to adjust a probability distribution corresponding to the natural language processing model by using the temperature parameter; Based on a preset core sampling strategy and in combination with the probability distribution, all triples are iteratively revised to obtain the response sample text.
3. The method for optimizing a natural language processing model according to claim 1, wherein: The performing a quality assessment operation on the response sample text to generate a quality assessment result of the response sample text includes: Convert the response sample text into a corresponding first part-of-speech tag sequence, and obtain a corresponding part-of-speech tag corpus based on a corpus set in a preset security dataset; Obtain each sentence in the response sample text that belongs to a part-of-speech tag corpus, determine a second part-of-speech tag sequence corresponding to each sentence, and match the first part-of-speech tag sequence with the second part-of-speech tag sequence to obtain a longest common subsequence corresponding to the first part-of-speech tag sequence and the second part-of-speech tag sequence; Determine the longest length of the longest common subsequence and the sequence length corresponding to the first part-of-speech tag sequence, and calculate a ratio of the longest length to the sequence length to determine a readability assessment result in the quality assessment result according to the ratio.
4. The method for optimizing a natural language processing model according to claim 3, wherein: The performing a quality assessment operation on the response sample text to generate a quality assessment result of the response sample text further includes: Based on the target third-party security model and preset evaluation criteria, the response sample text is evaluated for relevance, clarity, comprehensiveness, and knowledgeability to obtain corresponding relevance scores, clarity scores, comprehensiveness scores, and knowledgeability scores; An average value of the evaluation scores of the relevance score, the clarity score, the comprehensiveness score, and the knowledge score is calculated to determine a usefulness evaluation result in the quality evaluation result according to the average value of the evaluation scores.
5. The method for optimizing a natural language processing model according to claim 4, wherein: The performing a quality assessment operation on the response sample text to generate a quality assessment result of the response sample text further includes: Calculating the log-likelihood value corresponding to each sentence in the response sample text, calculating the average of the log-likelihood values of all sentences, and obtaining the negative number corresponding to the average; An exponential function value corresponding to the negative number is calculated to determine a perplexity evaluation result in the quality evaluation result according to the exponential function value.
6. The method for optimizing a natural language processing model according to claim 4, wherein: Based on the target third-party security model and the preset evaluation criteria, the response sample text is evaluated for relevance, clarity, comprehensiveness, and knowledgeability to obtain corresponding relevance scores, clarity scores, comprehensiveness scores, and knowledgeability scores, including: Determining the question topic corresponding to the response sample text; Based on the target third-party security model, the degree of fit between the response sample text and the question topic is quantified to calculate a relevance score corresponding to the response sample text according to the degree of fit.
7. The method for optimizing a natural language processing model according to claim 6, wherein: The step of performing relevance evaluation, clarity evaluation, comprehensiveness evaluation, and knowledge evaluation on the response sample text based on the target third-party security model and preset evaluation criteria to obtain corresponding relevance scores, clarity scores, comprehensiveness scores, and knowledge scores further includes: Performing grammatical and logical analysis on the response sample text to obtain corresponding grammatical analysis results and logical analysis results; The grammatical analysis result and the logical analysis result are quantified to generate a clarity score corresponding to the response sample text.
8. The method for optimizing a natural language processing model according to claim 7, wherein: The step of performing relevance evaluation, clarity evaluation, comprehensiveness evaluation, and knowledge evaluation on the response sample text based on the target third-party security model and preset evaluation criteria to obtain corresponding relevance scores, clarity scores, comprehensiveness scores, and knowledge scores further includes: Analyzing the coverage of the question topic by the response sample text to obtain a topic coverage analysis result corresponding to the question topic; Based on the target third-party security model and the topic coverage analysis result, a comprehensiveness score corresponding to the response sample text is determined.
9. The method for optimizing a natural language processing model according to claim 8, wherein: The step of performing relevance evaluation, clarity evaluation, comprehensiveness evaluation, and knowledge evaluation on the response sample text based on the target third-party security model and preset evaluation criteria to obtain corresponding relevance scores, clarity scores, comprehensiveness scores, and knowledge scores further includes: Based on the response sample text, performing a knowledge comprehension degree analysis on the question topic to obtain a corresponding knowledge comprehension degree analysis result; Based on the target third-party security model and the knowledge comprehension level analysis result, a knowledge score corresponding to the response sample text is determined.
10. The method for optimizing a natural language processing model according to claim 5, wherein: The performing a beam search screening operation on the response sample text according to the quality assessment result to obtain a corresponding screening triplet includes: Determining a response filtering threshold based on responses of all triples, and filtering responses in the response sample text whose readability evaluation results and usefulness evaluation results are less than the response filtering threshold to obtain corresponding filtered text; Sort the filtered text in ascending order according to the perplexity evaluation result to obtain the corresponding sorting result, and select the top text in the sorting result. k Responses based on the previous k responses and the aforementioned k The question and prompt word corresponding to the response are used to construct the screening triplet, where: k Is a positive integer.
11. The method for optimizing a natural language processing model according to claim 1, wherein: The method of organizing the third-party training subset into corresponding security training data based on the final response text and mixing the security training data with the third-party training data to generate corresponding mixed training data, and using the mixed training data to train a pre-built natural language processing model, so that the trained natural language processing model generates corresponding security responses according to different data security issues, includes: Determining, based on the third-party training subset, a question and a prompt word corresponding to each response in the final response text, and constructing the security training data according to the final response text and the question and prompt word corresponding to each response; The security training data and the third-party training data are mixed to generate the mixed training data, and the natural language processing model is trained by the mixed training data so that the trained natural language processing model meets the preset security alignment requirements, so as to generate security responses corresponding to the different data security issues through the trained natural language processing model.
12. A natural language processing model optimization device, characterized in that: include: a downsampling module for collecting third-party training data corresponding to a target third-party security model, downsampling the third-party training data to obtain a corresponding third-party training subset, and organizing the data in the third-party training subset into a question-response-prompt word triple form to obtain triple data corresponding to the third-party training subset; A quality assessment module is used to perform diversity sampling on the response data in the triple data to obtain response sample text, and perform a quality assessment operation on the response sample text to generate a quality assessment result of the response sample text; an iterative module, configured to perform a beam search screening operation on the response sample text according to the quality assessment result to obtain corresponding screening triples, and iteratively perform diversity sampling and beam search screening operations based on the screening triples until a preset iteration end requirement is met, thereby generating a final response text corresponding to the third-party training subset; A training module is used to organize the third-party training subset into corresponding security training data based on the final response text, and mix the security training data and the third-party training data to generate corresponding hybrid training data, so as to use the hybrid training data to train a pre-built natural language processing model, so that the trained natural language processing model can generate corresponding security responses according to different data security issues.
13. An electronic device, characterized in that: include: Memory for storing computer programs; A processor, configured to implement the steps of the method for optimizing a natural language processing model as claimed in any one of claims 1 to 11 when executing the computer program.
14. A computer-readable storage medium, characterized in that The computer-readable storage medium stores a computer program, wherein when the computer program is executed by a processor, the steps of the method for optimizing the natural language processing model as described in any one of claims 1 to 11 are implemented.
15. A computer program product comprising a computer program, characterized in that When the computer program is executed by a processor, the steps of the method for optimizing the natural language processing model as claimed in any one of claims 1 to 11 are implemented.
Citation Information
Patent Citations
Cross-language question answering system construction method and device based on generative multi-language model
CN115795009A
Data cleaning method
CN119884611A