Optimization method and device for natural language processing model

By downsampling, diversity sampling and quality evaluation of the training data of large language models, safe training data are generated, and the problem of safe alignment of large language models is solved, achieving higher security performance and reliable response.

CN120409740AActive Publication Date: 2025-08-01INSPUR SUZHOU INTELLIGENT TECH CO LTD

Patent Information

Application Number
CN202510889893.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-06-27
Publication Date
2025-08-01
Estimated Expiration
2045-06-27

AI Technical Summary

Technical Problem

The prior art cannot effectively deal with the secure alignment of large language models, and it is difficult to fundamentally reduce harmful information damage in third-party data.

Method used

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 security response when facing data security problems.

Benefits of technology

Improves the security performance and alignment of large language models to ensure that they can provide a safe and reliable response and avoid providing harmful information.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120409740A_ABST
    Figure CN120409740A_ABST
Patent Text Reader

Abstract

The invention discloses an optimization method and device for a natural language processing model, and relates to the technical field of information security, and the method comprises the steps: reducing the text confusion degree through employing an iterative beam search mode, and guaranteeing the text quality at the same time, i.e., carrying out the quantitative evaluation and screening of readability and usefulness in a processing process, and improving the processing efficiency. And performing model fine tuning by using the optimized and transformed mixed data to reduce the influence of harmful texts in the third-party data on the model security alignment, thereby improving the security performance and the alignment degree of the large model, and solving the problem that the security alignment of the large language model cannot be effectively coped with in the related technology, and the security alignment efficiency is improved. The technical problem that possible harmful information damage in the third-party data is difficult to fundamentally reduce is solved, and the technical effects that the safety performance and the alignment degree of the large language model are improved, it is ensured that the large language model can give safe and reliable response when facing the data safety problem, and harmful information is prevented from being provided are achieved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of information security technology, and in particular, to an optimization method and device for natural language processing models. Background Art

[0002] During the optimization process of natural language processing models, due to diverse sources and uncontrollable quality, malicious suppliers can covertly implant Q&A pairs with security risks in seemingly compliant datasets. This covert attack poses a long-term threat to the robustness of the models, and multiple defense mechanisms such as data cleaning and adversarial training are required to mitigate it.

[0003] In terms of secure data processing, existing technologies usually adopt rule-based keyword matching or pattern recognition to screen and eliminate potential harmful content, and at the same time combine statistical analysis means to detect and correct biases in the data to avoid the model outputting conclusions with security risks or social biases; however, the above technologies still have the following defects: 1. Harmful information may evade rule detection through semantic reconstruction (such as synonym replacement, sentence pattern adjustment) or context hiding (such as seemingly harmless expressions implying malicious intentions); 2. The statistical method has insufficient ability to identify implicit biases or complex logical traps, resulting in some risk data still possibly infiltrating into the training process, making it a continuous technical challenge to completely eliminate the impact of harmful content.

[0004] Currently, the existing technologies for ensuring the secure alignment of large language models (LLMs) mainly include the following two categories: 1. Immediate guidance strategy: Dynamically constrain the model output during the inference stage by presetting security prompt words to make it comply with ethical norms; 2. Data-driven optimization: Supervised fine-tuning: Rely on high-quality Q&A pairs with manual annotations to establish the mapping relationship between the input and the compliant output through supervised learning, but face the problems of high annotation cost and subjective bias of annotators; Human feedback reinforcement learning: Dynamically adjust the parameters through the ranking or scoring of the model output by humans. Although it can capture more complex value alignment requirements, the sparsity and noise of the feedback data will significantly reduce the training efficiency.

[0005] In summary, the existing technologies cannot effectively address the secure alignment of large language models and are difficult to fundamentally reduce the harm of potentially existing harmful information in third-party data, which urgently needs to be solved. Summary of the Invention

[0006] The present application provides an optimization method and device for a natural language processing model, so as to at least solve the technical problems in the related art that it is impossible to effectively handle the security alignment of large language models and it is difficult to fundamentally reduce the harm of possible harmful information in third-party data.

[0007] The present application provides an optimization method for a natural language processing model, including the following steps: collecting third-party training data corresponding to a target third-party security model, performing downsampling on the third-party training data to obtain a corresponding third-party training subset, and organizing the data in the third-party training subset into the form of a question-response-prompter triple to obtain triple data corresponding to the third-party training subset; performing diversity sampling on the response data in the triple data to obtain a response sampling text, and performing a quality evaluation operation on the response sampling text to generate a quality evaluation result of the response sampling text; performing beam search screening on the response sampling text according to the quality evaluation result to obtain corresponding screened triples, and based on the screened triples, iteratively performing diversity sampling and beam search screening operations until a preset iteration end requirement is met to generate a final response text corresponding to the third-party training subset; based on the final response text, organizing the third-party training subset into corresponding secure training data, and mixing the secure 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-constructed natural language processing model, so that the trained natural language processing model can generate corresponding secure responses according to different data security problems.

[0008] The present application also provides an optimization device for a natural language processing model, including: a downsampling module, configured to collect third-party training data corresponding to a target third-party security model, perform downsampling on the third-party training data to obtain a corresponding third-party training subset, and organize the data in the third-party training subset into a question-response-prompter triple form to obtain triple data corresponding to the third-party training subset; a quality assessment module, configured to perform diversity sampling on the response data in the triple data to obtain a 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; an iteration module, configured to perform beam search filtering on the response sampling text according to the quality assessment result to obtain a corresponding filtered triple, and based on the filtered triple, iteratively perform diversity sampling and beam search filtering operations until a preset iteration end requirement is met, and generate a final response text corresponding to the third-party training subset; a training module, configured to organize the third-party training subset into corresponding security training data based on the final response text, mix the security training data and the third-party training data to generate corresponding mixed training data, and use the mixed training data to train a pre-constructed natural language processing model, so that the trained natural language processing model generates corresponding security responses according to different data security problems.

[0009] The present application also provides an electronic device, including: a memory, configured to store a computer program; a processor, configured to implement the steps of any of the above natural language processing model optimization methods when executing the computer program.

[0010] The present application also provides a computer-readable storage medium, in which a computer program is stored, and wherein the computer program, when executed by a processor, implements the steps of any of the above natural language processing model optimization methods.

[0011] The present application also provides a computer program product, including a computer program, and the computer program, when executed by a processor, implements the steps of any of the above natural language processing model optimization methods.

[0012] Through this application, third-party training data corresponding to a target third-party security model can be collected, downsampled to obtain a corresponding third-party training subset, and the data in the third-party training subset can be organized into a question-response-prompter triple form to obtain triple data corresponding to the third-party training subset; perform diversity sampling on the response data in the triple data to obtain a response sampling text, and perform a quality evaluation operation on the response sampling text to generate a quality evaluation result of the response sampling text; perform a beam search and screening operation on the response sampling text according to the quality evaluation result to obtain corresponding screened triples, and based on the screened triples, iteratively perform diversity sampling and beam search and screening operations until a preset iteration end requirement is met to generate a final response text corresponding to the third-party training subset; based on the final response text, organize the third-party training subset into corresponding security training data, and mix the security training data and the third-party training data to generate corresponding mixed training data, so as to train a pre-constructed natural language processing model with the mixed training data, so that the trained natural language processing model can generate corresponding security responses according to different data security problems. Therefore, the technical problem in the related art that it is impossible to effectively handle the security alignment of large language models and it is difficult to fundamentally reduce the harm of possible harmful information in third-party data can be solved, and the technical effects of improving the security performance and alignment degree of large language models, ensuring that the large language model can give safe and reliable responses when facing data security problems, and avoiding providing harmful information are achieved. BRIEF DESCRIPTION OF THE DRAWINGS

[0013] To more clearly illustrate the embodiments of the present application, the drawings required for use in the embodiments will be briefly introduced below. Obviously, the drawings in the following description are only some embodiments of the present application. For those of ordinary skill in the art, other drawings can be obtained based on these drawings without creative efforts.

[0014] Figure 1 It is a flowchart of an optimization method for a natural language processing model provided according to an embodiment of the present application; Figure 2 It is a schematic diagram of the execution logic of an optimization method for a natural language processing model provided by an embodiment of the present application; Figure 3 It is an example diagram of an optimization device for a natural language processing model according to an embodiment of the present application.

[0015] Among them, 10 - Optimization device for natural language processing model, 100 - Downsampling module, 200 - Quality evaluation module, 300 - Iteration module, 400 - Training module. DETAILED DESCRIPTION OF THE EMBODIMENTS

[0016] The following will clearly and completely describe the technical solutions in the embodiments of the present application with reference to the accompanying drawings in the embodiments of the present application. Obviously, the described embodiments are only a part of the embodiments of the present application, rather than all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative efforts belong to the protection scope of the present application.

[0017] It should be noted that in the description of the present application, the terms "include", "comprise" or any other variation thereof are intended to cover a non-exclusive inclusion, such that a process, method, article or device including a series of elements not only includes those elements but also includes other elements not expressly listed, or further includes elements inherent to such process, method, article or device. The terms "first", "second", etc. in the present application are used to distinguish similar objects and are not used to describe a specific order or sequence.

[0018] In order to enable those skilled in the art of the present technology to better understand the solution of the present application, the present application will be further described in detail below with reference to the accompanying drawings and specific embodiments.

[0019] Combined 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 will be described herein.

[0020] The embodiments of the present application provide an optimization method for a natural language processing model.

[0021] As Figure 1 shown, it is a flowchart of the optimization method of the natural language processing model in the embodiments of the present application. Among them, the optimization method of the natural language processing model includes the following steps: In step S101, collect the third-party training data corresponding to the target third-party security model, perform downsampling on the third-party training data to obtain the corresponding third-party training subset, and organize the data in the third-party training subset into the form of a question-response-prompt triple to obtain the triple data corresponding to the third-party training subset.

[0022] It should be noted that before performing data optimization and improvement, the embodiments of the present application may assume that the data users in the real scenario do not know whether there is harmful and sensitive data in the third-party data. Therefore, under this assumption, the embodiments of the present application can describe the problem as follows: The secure data set of the third-party data set D may be maliciously implanted with a set of harmful and sensitive data , and each data sample therein contains a question regarding data security and the corresponding insecure response ; If the large language model is trained on the dataset to obtain model weights , at this time, when the large language model encounters data security issues , it is more likely to give a harmful response .

[0023] For example, for some questions, the large language model may generate responses containing harmful information to meet the requirements of the question. Therefore, the embodiments of the present application can select a part of the data from the safe dataset D of the third-party dataset (such as 10% of the total number of samples in the entire safe dataset D ), and reconstruct, organize, and transform this part of the data.

[0024] Specifically, the embodiments of the present application can first select a part of the safe dataset (i.e., the third-party training data) D . For example, the embodiments of the present application can perform downsampling on the third-party training data to randomly select 10% of the total number of samples, thereby obtaining the corresponding third-party training subset; secondly, the embodiments of the present application can organize the sampled third-party training subset into the form of (question Q , response A , prompt P ) triples.

[0025] For example, the above (question Q , response A , prompt P ) triple 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 answer part."); where P as a prompt guidance, it helps the large language model to better organize the text using the input triple ( Q , A , P ).

[0026] Thus, the embodiments of the present application perform downsampling on the third-party training data and organize the downsampled data into the form of question-response-prompt triples, thereby providing reliable data guidance and basis for the subsequent evaluation of text quality.

[0027] In step S102, diversity sampling is performed on the response data in the triple data to obtain response sampling text, and a quality evaluation operation is performed on the response sampling text to generate a quality evaluation result of the response sampling text.

[0028] 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.

[0029] 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.

[0030] 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.

[0031] 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.

[0032] Optionally, in an embodiment of the present application, diversity sampling is performed on the response data in the triple data to obtain a response sampling text, including: determining a temperature parameter corresponding to a preset temperature sampling strategy to adjust the probability distribution corresponding to the natural language processing model through the temperature parameter; based on the preset nucleus sampling strategy, combining the probability distribution, iteratively revising all triples to obtain a response sampling text.

[0033] In the actual execution process, the embodiment of the present application can perform diversified sampling on the responses of all triples by combining temperature sampling and nucleus sampling. First, the embodiment of the present application can adjust the temperature parameter T to change the probability distribution calculated by the large language model, thereby regulating the generation process of the next word; second, the embodiment of the present application can select the next word from the set of the smallest words whose cumulative probability exceeds a given threshold P , and the two complement each other to generate a diversified response; then, the embodiment of the present application can utilize different ([[]] T , P ) combinations to iteratively revise the original ([[]] Q , A , P ) (i.e., the response data in the triple data) through the large language model, thereby generating multiple different revised versions ([[]] Q , A’ , P ) (i.e., the response sampling text).

[0034] It should be noted that the embodiment of the present application introduces unpredictability through random sampling to prevent the model from falling into a fixed mode; second, the embodiment of the present application can control the balance between diversity and relevance by dynamically adjusting the smoothness of the probability distribution; in addition, the embodiment of the present application can also filter out low-quality candidates through nucleus sampling to ensure the basic rationality of the generated content. In the embodiment of the present application, the core components for performing diversified sampling mainly include a random sampling layer (as a basic sampling strategy to ensure initial diversity), a temperature adjustment layer (controlling the conservative / open degree of the generation style), and a nucleus sampling layer (as a quality filter to remove unreasonable candidates).

[0035] As a feasible implementation method, the specific process of the embodiment of the present application for performing diversified sampling on the responses of triples by combining temperature sampling and nucleus sampling is as follows: 1. Input triple preprocessing: Parse the triple structure to clarify the user query (such as "Recommend weekend short trip locations"), the conversation context (such as "The user is located in Shanghai and prefers natural landscapes"), and the candidate response pool (which can be initially empty); 2. Basic random sampling: From the original probability distribution output by the large language model, randomly select the first 50 candidate tokens completely randomly (without considering probability ranking), and assign an equal selection probability to each candidate token to break the inherent preferences of the model and discover atypical but reasonable expressions; 3. Temperature adjustment stage: For the candidate set obtained by random sampling, apply a dynamic temperature coefficient, use a low temperature for factual content and a high temperature for descriptive content, and recalculate the weighted probability distribution; 4. Nucleus sampling refinement: For the distribution after temperature adjustment, the embodiments of the present application can adopt a progressive p value strategy, and the first round p = 0.9 (retain a wide range of candidates), the second round p = 0.7 (focus on high-quality candidates); afterwards, the embodiments of the present application can perform a two-stage truncation, retain the smallest candidate set with a cumulative probability greater than p and re-normalize the probabilities of the remaining candidates; 5. Diverse response generation: Generate the final response through a three-stage mechanism: (1) Skeleton construction: Randomly sample to determine the response framework; (2) Content filling: Temperature sampling generates specific descriptions; (3) Style fine-tuning: Nucleus sampling controls the formality of the expression.

[0036] 6. Post-processing and verification: Implement diversity guarantee measures: (1) Response deduplication: The semantic similarity threshold is less than 0.7; (2) Taboo word filtering: Exclude expressions that do not conform to the security policy; (3) Manual readability check: Ensure grammatical fluency.

[0037] Thus, the embodiments of the present application can, through random sampling, and through the synergistic effects of randomness introduction, temperature regulation, and probability truncation, enable the large language model to iteratively revise all triples to obtain response sampling texts, thereby significantly improving the diversity level of the generated responses while maintaining semantic rationality, and providing rich initial samples for subsequent screening.

[0038] Optionally, in an embodiment of the present application, a quality assessment operation is performed on the response sampled text to generate a quality assessment result of the response sampled text, including: converting the response sampled text into a corresponding first part-of-speech tagging sequence, and obtaining a corresponding part-of-speech tagging corpus based on the corpus set in the preset security dataset; obtaining each sentence in the response sampled text that belongs to the part-of-speech tagging corpus, determining a corresponding second part-of-speech tagging sequence for 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 according to the ratio.

[0039] It should be noted that the embodiments of the present application can use the part-of-speech tagging of sentences to judge the similarity degree between the revised text and the human language structure. After converting the sentence into a part-of-speech tagging sequence, it is matched with the part-of-speech tagging corpus of a large number of human language sentences, and the matching degree is determined by the ratio of the longest common subsequence to the original sequence length, and this ratio is used as the corresponding readability assessment result.

[0040] Those skilled in the art should understand that readability ensures the similarity degree between the reorganized text and the human language structure; considering that part-of-speech tagging assigns specific grammatical roles to each word in a sentence, the embodiments of the present application can quantify readability through the following part-of-speech tagging method, and the specific steps are as follows: Step 1. For a given sentence S , the embodiments of the present application can first convert the original text sequence (i.e., the response sampled text) into a part-of-speech tagging sequence of the text T S (i.e., the first part-of-speech tagging 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 tagging sequence T S = "Pronoun Verb Adjective Noun Punctuation mark"; Step 2. Based on the method described in Step 1, the embodiments of the present application can use the corpus set in the known security dataset in the industry (such as fineweb-edu) to obtain a part-of-speech tagging corpus C , and this part-of-speech tagging corpus C contains different human language styles, and its part-of-speech tagging reflects a wide range of text structures; Step 3. Obtain each sentence in the response sampled text that belongs to the part-of-speech tagging corpusx (i.e., x ∈ C ), and determine the second part-of-speech tagging sequence corresponding to each sentence x ; furthermore, the embodiments of the present application can match the part-of-speech tagging sequence T x with T x and T S to obtain the longest common subsequence of the two sequences, and use the ratio of the longest length of the longest common subsequence to T S the length (i.e., the sequence length) as the readability evaluation score, that is, the readability evaluation result, as shown in the following formula: R S = T x,max / T S where, R S represents the readability evaluation score; T x,max represents the longest common subsequence; T S represents the sequence length of the first part-of-speech tagging sequence.

[0041] In the embodiments of the present application, the longest common subsequence (Longest Common Subsequence, LCS) refers to the longest subsequence that appears in two or more sequences. The subsequence does not require continuity but must maintain the original order.

[0042] Thus, the embodiments of the present application quantitatively evaluate the readability of the response sampling text by calculating the similarity between the sentence S in the response sampling text and the human language, thereby providing strong data support for the quality evaluation of the response sampling text.

[0043] Optionally, in an embodiment of the present application, performing a quality evaluation operation on the response sampling text to generate a quality evaluation result of the response sampling text further includes: based on the target third-party security model and the preset evaluation criteria, performing a relevance evaluation, a clarity evaluation, a comprehensiveness evaluation, and a knowledge evaluation on the response sampling text to obtain the corresponding relevance score, clarity score, comprehensiveness score, and knowledge score; calculating the average value of the evaluation scores of the relevance score, clarity score, comprehensiveness score, and knowledge score to determine the usefulness evaluation result in the quality evaluation result according to the average value of the evaluation scores.

[0044] 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 sampling text from four aspects: relevance, clarity, comprehensiveness, and knowledgeability, so as to obtain the evaluation scores corresponding to each of the above four aspects, and calculate the average value of the evaluation scores of the four aspects of relevance, clarity, comprehensiveness, and knowledgeability, thereby using this average evaluation score as the usefulness evaluation result corresponding to the response sampling text.

[0045] It can be understood 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 knowledgeability. To this end, the embodiments of the present application can use a set of prompts and utilize the third-party security model to evaluate the usefulness of the text from the perspectives of relevance, clarity, comprehensiveness, and knowledgeability respectively. Their 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.

[0046] Optionally, in an embodiment of the present application, based on the target third-party security model and the preset evaluation criteria, a relevance evaluation, a clarity evaluation, a comprehensiveness evaluation, and a knowledgeability evaluation are performed on the response sampling text to obtain the corresponding relevance score, clarity score, comprehensiveness score, and knowledgeability score, including: determining the problem theme corresponding to the response sampling text; based on the target third-party security model, quantifying the degree of fit between the response sampling text and the problem theme, so as to calculate the relevance score corresponding to the response sampling text according to the degree of fit.

[0047] It should be noted that the process and evaluation criteria for the relevance evaluation of the response sampling text in the embodiments of the present application are as follows: The relevance score is 0 points, which means it is completely irrelevant, and the response sampling text has no relation to the theme of the provided problem. The relevance score is 1 point, which means it is slightly relevant. The response sampling text contains very little information related to the provided problem, but generally fails to fully address the main problem. The relevance score is 2 points, which means it is moderately relevant. The response sampling text touches on some aspects of the provided problem, but these one-sided correlations are covered by irrelevant content. The relevance score is 3 points, which means it is relevant. The response sampling text mostly directly relates to the theme of the provided problem and provides valuable insights or information. The relevance score is 4 points, which means it is very relevant. The response sampling text is highly relevant to the problem theme, hardly digresses, and provides coherent insights and information that closely fit the main theme. The relevance score is 5 points, indicating extremely relevant. The response sampling text highly matches the theme of the provided question, provides comprehensive and highly relevant information, and has no ambiguity or redundant content.

[0048] Thus, the embodiments of this application determine corresponding relevance evaluation criteria, thereby providing reliable data support and basis for calculating the relevance score of the response sampling text, and ensuring the reliability of the usefulness evaluation.

[0049] Optionally, in an embodiment of this application, based on the target third-party security model and preset evaluation criteria, the response sampling text is evaluated for relevance, clarity, comprehensiveness, and knowledgeability to obtain corresponding relevance scores, clarity scores, comprehensiveness scores, and knowledgeability scores. It also includes: performing grammar and logic analysis on the response sampling text to obtain corresponding grammar analysis results and logic analysis results; quantifying the grammar analysis results and logic analysis results to generate the clarity score corresponding to the response sampling text.

[0050] In the embodiments of this application, the corresponding evaluation criteria for evaluating the clarity of the response sampling text are as follows: The clarity score is 0 points, indicating completely unclear. The response sampling text is extremely unclear, difficult to understand, has grammar errors and ambiguous expressions (i.e., grammar analysis results and logic analysis results), making it impossible to understand. The clarity score is 1 point, indicating slightly clear. The response sampling text is somewhat unclear and requires additional effort to distinguish the main idea. The clarity score is 2 points, indicating moderately clear. The response sampling text is generally clear, occasionally contains some grammar errors or complex sentences, but the main information can still be understood. The clarity score is 3 points, indicating clear. The response sampling text is well-expressed, has few grammar errors or unclear language, and the overall meaning is easily distinguishable and understandable. The clarity score is 4 points, indicating very clear. The response sampling text is easy to understand, well-structured, effectively conveys its information, and is convenient for readers to easily understand. The clarity score is 5 points, indicating extremely clear. The response sampling text is concise and reasonably structured, with precise logical organization, and there is no possibility of any misunderstanding or ambiguity.

[0051] Thus, the embodiments of this application analyze the grammar and logic of the response sampling text to evaluate the clarity degree of the response sampling text, effectively ensuring the accuracy of the evaluated clarity score.

[0052] Optionally, in an embodiment of the present application, based on the target third-party security model and the preset evaluation criteria, a relevance evaluation, a clarity evaluation, a comprehensiveness evaluation, and a knowledge evaluation are performed on the response sampling text to obtain the corresponding relevance score, clarity score, comprehensiveness score, and knowledge score. It further includes: analyzing the coverage degree of the response sampling text on the problem theme to obtain the analysis result of the theme coverage degree corresponding to the problem theme; determining the comprehensiveness score corresponding to the response sampling text based on the target third-party security model and the analysis result of the theme coverage degree.

[0053] During the actual execution process, the corresponding evaluation criteria for the comprehensiveness evaluation of the response sampling text in the embodiment of the present application are as follows: The comprehensiveness score is 0 points, indicating completely incomplete, the answer is extremely superficial, lacking any meaningful information or depth, and leaving the questioner with more doubts than answers. The comprehensiveness score is 1 point, indicating slightly comprehensive. The information provided by the answer response sampling text is very little, only giving a superficial overview of the problem theme without delving into any important details. The comprehensiveness score is 2 points, indicating moderately comprehensive. The answer response sampling text provides some information but lacks depth and omits important aspects of the theme. The comprehensiveness score is 3 points, indicating comprehensive. The answer response sampling text covers the key theme content but ignores some minor details and still has room for further exploration. The comprehensiveness score is 4 points, indicating very comprehensive. The answer response sampling text is comprehensive and complete, deeply covering the theme, with almost no omissions or missing parts, and providing detailed explanations and insights. The comprehensiveness score is 5 points, indicating extremely comprehensive. The answer response sampling text does not omit any important aspects of the theme and provides comprehensive insights and information, enabling readers to have an in-depth and thorough understanding of the theme.

[0054] Thus, the embodiment of the present application analyzes the coverage degree of the response sampling text on the problem theme, thereby obtaining the comprehensiveness score corresponding to the response sampling text, providing a reliable data index and basis for quantifying the amount of information and the depth of insights in the answer of the response sampling text to the question.

[0055] Optionally, in an embodiment of the present application, based on the target third-party security model and the preset evaluation criteria, a relevance evaluation, a clarity evaluation, a comprehensiveness evaluation, and a knowledge evaluation are performed on the response sampling text to obtain the corresponding relevance score, clarity score, comprehensiveness score, and knowledge score. It further includes: analyzing the degree of knowledge understanding of the problem theme based on the response sampling text to obtain the corresponding analysis result of the degree of knowledge understanding; determining the knowledge score corresponding to the response sampling text based on the target third-party security model and the analysis result of the degree of knowledge understanding.

[0056] As an implementable way, the corresponding evaluation criteria for the knowledge evaluation of the response sampling text in the embodiments of the present application are as follows: The knowledge score is 0 points, indicating completely no knowledge. The answer fails to provide any knowledge helpful for understanding the topic, confusing the questioner; The knowledge score is 1 point, indicating slightly helpful. The answer provides limited knowledge in response to the sampling text and makes no significant contribution to understanding or solving the problem; The knowledge score is 2 points, indicating moderately knowledgeable. The answer provides some help in response to the sampling text, including some valuable insights or knowledge; The knowledge score is 3 points, indicating knowledgeable. The answer helps to understand the topic of the question in response to the sampling text and provides valuable knowledge, providing meaningful help for the questioner to achieve the goal; The knowledge score is 4 points, indicating very knowledgeable. The response sampling text is very helpful, making a great contribution to understanding the topic of the question, providing valuable insights and knowledge (i.e., the analysis result of the degree of knowledge understanding), and effectively solving the problem; The knowledge score is 5 points, indicating extremely knowledgeable. The response sampling text is extremely helpful, providing comprehensive content and valuable knowledge, providing clear guidance and help for readers.

[0057] Thus, the embodiments of the present application judge whether the response sampling text can provide comprehensive content and valuable knowledge by evaluating the knowledge of the response sampling text, so as to obtain the corresponding knowledge score, further improving the data system for evaluating the usefulness of the response sampling text and ensuring the accuracy and reliability of the evaluation of the usefulness of the response sampling text.

[0058] Optionally, in an embodiment of the present application, a quality evaluation operation is performed on the response sampling text to generate a quality evaluation result of the response sampling text, and it further includes: calculating the log-likelihood value corresponding to each sentence in the response sampling text, calculating the average value of the log-likelihood values of all sentences, and obtaining the negative number corresponding to the average value; calculating the exponential function value corresponding to the negative number to determine the perplexity evaluation result in the quality evaluation result according to the exponential function value.

[0059] In addition, perplexity (PPL) is a commonly used metric to measure the preference degree of a large language model when generating a specific text sequence, mainly used to evaluate the prediction ability of the model for the text sequence. A low perplexity indicates that the model is more certain about the prediction of the sequence and has better performance; a high perplexity indicates that the model has high prediction uncertainty and poor performance. Therefore, the embodiments of the present application also need to select a revised version with a lower perplexity.

[0060] Specifically, the embodiments of the present application can measure the difference between safe texts and harmful texts through the perplexity metric, and use readability and usefulness to ensure the quality of the organized texts, that is, to ensure that the transformed texts are not only meaningful but also contain the useful knowledge contained in the original texts.

[0061] Mathematically, the text sequence corresponding to the response sampled text can be determined , and the large language model θ Regarding X The perplexity is defined as:

[0062] Wherein, represents calculating the log-likelihood value corresponding to given the previous token ( x i ); PPL ( X ) represents the perplexity evaluation result.

[0063] It can be understood that in the actual execution process, the content of harmful information or insecure information in the normal training corpus is less, 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 a lower perplexity when generating safe responses. That is to say, the large language model aligned with safety tends to respond to questions in a safe and responsible manner. Therefore, when the large language model generates harmful responses, the perplexity shown will be higher. Thus, the embodiments of the present application reorganize the existing texts to reduce their perplexity and use them as substitutes for the original texts. These reorganized texts tend to strengthen the model's preference for outputting safe responses, thereby effectively reducing the risk.

[0064] In step S103, according to the quality evaluation result, beam search screening operation is performed on the response sampled text to obtain the corresponding screening triples, and based on the screening triples, diversity sampling and beam search screening operations are iteratively performed until the preset iteration end requirement is met, and the final response text corresponding to the third-party training subset is generated.

[0065] Furthermore, the embodiments of the present application also need to perform screening operations on the response sampled text through iterative beam search based on the perplexity evaluation result, readability evaluation result, and usefulness evaluation result, so as to select the best organized text, that is, the final response text.

[0066] Thus, the embodiments of the present application define three metrics, namely perplexity, readability, and usefulness, through quantification, and comprehensively consider these three metrics to guide the process of reorganizing security-related data, screening out texts that not only conform to the security preferences of the large language model but also have high quality; different from the simple filtering or alignment methods in the prior art, the embodiments of the present application can deeply explore the internal preferences of the large language model for texts, thereby enhancing the security of the large language model at the essential level of language generation.

[0067] Optionally, in an embodiment of the present application, beam search screening operations are performed on the response sampled text according to the quality assessment results to obtain corresponding screening triples, including: determining a response filtering threshold based on the responses of all triples, and filtering the responses in the response sampled text whose readability assessment results and usefulness assessment results are less than the response filtering threshold to obtain corresponding filtered text; sorting the filtered text in ascending order according to the perplexity assessment results to obtain corresponding sorting results, and selecting the first k responses, and constructing screening triples based on the questions and prompt words corresponding to the first k responses and the first k responses, where k is a positive integer.

[0068] In the actual execution process, the embodiments of the present application can use the beam search method to screen the finally adopted responses (i.e., the final response text). Among them, the key of beam search is to iteratively select k texts generated by the large language model, and use the texts generated in each iteration process as the input for the next iteration. The specific steps are as follows: 1. After obtaining a series of sorted responses T i , P i ) combination-generated (i.e., the response sampled text), the embodiments of the present application can first filter out the responses whose readability assessment results and usefulness assessment results are lower than the response filtering threshold, and the response filtering threshold can be set according to the actual situation; for example, the embodiments of the present application can filter the responses whose readability assessment results and usefulness assessment results are significantly lower than the original response A i , such as the readability or usefulness scores of the text, that is, the responses whose readability assessment results and usefulness assessment results are lower than 10% of the corresponding values of the original response A to obtain corresponding filtered text; A 2. Sort the remaining text (i.e., the filtered text) in ascending order according to the perplexity assessment results, and select the first responses; k 3. Each selected response 38. Ai , which can be queried together Q and hints P , to form an input triple ( Q , A i , P ), that is, the screening triple, and use it as the input for the next round of output sampling; 4. The beam search process terminates after m rounds of generation (i.e., meeting the preset iteration end requirement); for example, in the embodiments of the present application, k can be set to 3, and m is 5 to achieve the optimal effect.

[0069] It can be understood that the embodiments of the present application select the optimal data through an iterative method that combines diversity sampling and beam search; among them, diversity sampling can generate diverse text revision versions, providing rich choices for subsequent screening; beam search continuously optimizes the revision versions through iterative screening, and finally obtains text with low perplexity and high quality. Thus, the embodiments of the present application can effectively improve the quality of data and enhance the security alignment of the model without relying on a large amount of labeled data.

[0070] In step S104, based on the final response text, the third-party training subset is organized into corresponding secure training data, and the secure training data and the third-party training data are mixed to generate corresponding mixed training data, so as to train a pre-constructed natural language processing model with the mixed training data, so that the trained natural language processing model can generate corresponding secure responses according to different data security problems.

[0071] After that, the embodiments of the present application can use the final response text to organize the third-party training subset into corresponding secure training data and mix the secure training data and the third-party training data; furthermore, the embodiments of the present application can fine-tune the large language model with the mixed training data, so that the large language model can generate corresponding secure responses according to different data security problems.

[0072] Those skilled in the art should understand that when some security data is used as the input of a normal large language model, the probability that the normal response of the large language model contains data security information is usually lower than that of a harmful response. Since the content of harmful information in the normal training corpus is relatively low, the probability of being output by the normal general large language model is also relatively small. In the actual execution process, perplexity is generally used to measure the preference degree of the large language model when generating text. Then, during the training process, regardless of whether the topic is clearly related to data security issues, a small part of the Q&A corpus can be selectively modified to reduce its perplexity, so as to strengthen the security alignment of the model and help avoid providing harmful responses to the model. In addition, during the process of reducing the perplexity of the corpus, the embodiments 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, ensure the readability and usefulness of the text.

[0073] Optionally, in an embodiment of the present application, based on the final response text, the third-party training subset is sorted 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 train a pre-constructed natural language processing model with the mixed training data, so that the trained natural language processing model generates corresponding security responses according to different data security problems, 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 with 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 problems through the trained natural language processing model.

[0074] It should be noted that the embodiments of the present application may assume that there may be a batch of harmful data sets D* injected into the third-party data set D resulting in the large language model θ outputting harmful responses after training. The embodiments of the present application can determine the security training data corresponding to the final response text through the above data processing process and use the security training data to train the large language model together with the third-party data set that may have been injected with harmful data D to generate mixed training data, so as to enhance its security alignment and enable the large language model to give security responses when facing data security queries.

[0075] As a feasible implementation, the specific steps for fine-tuning and training the large language model with the mixed training data in the embodiments of the present application are as follows: 1. Mixed data construction: (1) Controllable hybrid strategy 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; 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).

[0076] (2) Data annotation enhancement 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; Adversarial example generation: Based on harmful content in third-party data, artificially construct adversarial queries and pair them with safe responses.

[0077] 2. Model training and security alignment: (1) Multi-target training 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. Adversarial training mechanism: Through gradient reversal or adversarial sample enhancement, the model is forced to generate safe outputs under harmful inputs.

[0078] (2) Iterative evaluation and feedback 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; 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.

[0079] 3. Verification and deployment (1) Security benchmark testing 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. Manual review: Organize experts to conduct sampling checks on model outputs to verify the rationality and consistency of security responses.

[0080] (2) Continuous monitoring 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; Closed-loop data updates: Regularly incorporate new attack pattern samples (such as social engineering tactics) and iteratively update hybrid training data.

[0081] Thus, through the above steps, the embodiments of the present application enable the large language model to strengthen its understanding of the safety boundary while accessing complex real-world data, and ultimately achieve a balance between maintaining general capabilities and having a high level of safety awareness.

[0082] In summary, the embodiments of the present application ensure text quality while reducing text perplexity, that is, quantitatively evaluating and screening readability and usefulness during the processing. This not only makes the large language model more inclined to give safe responses in terms of preference, but also has high quality in terms of human understanding and knowledge transfer. The embodiments of the present application are iteratively performed by means of beam search and use the transformed mixed data for model fine-tuning, reducing the impact of harmful texts in third-party data on model safety alignment, improving the safety performance and alignment degree of the large language model, ensuring that the large language model can give safe and reliable responses when facing data security issues, avoiding providing harmful information, and thus improving the data safety performance through strict transformation of the original data.

[0083] The following explains the execution logic of the optimization method for the natural language processing model of the present application by combining with the accompanying drawings.

[0084] Figure 2 It is a schematic diagram of the execution logic of the optimization method for the natural language processing model of the present application. As Figure 2 shown, the execution process of the optimization method for the natural language processing model of the present application is as follows: S201: Obtain third-party training data that may contain sensitive data; S202: Downsample the third-party training data to obtain the corresponding subset; S203: For each (question, response, prompt) triple in the subset, use the third-party security model to perform diversity sampling on the response to obtain the corresponding response sampling text; S204: Evaluate the quality of the response sampling text from three aspects: perplexity, readability, and usefulness to obtain the evaluation results corresponding to perplexity, readability, and usefulness; S205: Based on the iterative beam search strategy, screen the response sampling text according to the evaluation results corresponding to perplexity, readability, and usefulness to obtain the final response text; S206: Use the final response text to reorganize the third-party training subset into secure training data; S207: Mix the secure 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 secure responses when facing different data security issues.

[0085] Through the description of the above embodiments, those skilled in the art can clearly understand that the method according to the above embodiments can be implemented by means of software plus a necessary general hardware platform. Of course, it can also be implemented by hardware, but in many cases, the former is a better implementation method.

[0086] An embodiment of the present application also provides an optimization device for a natural language processing model.

[0087] As Figure 3 shown, the optimization device 10 of the natural language processing model includes: a downsampling module 100, a quality evaluation module 200, an iterative module 300, and a training module 400.

[0088] Among them, the downsampling module 100 is used to collect third-party training data corresponding to the target third-party security model, 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 a question-response-prompt triple to obtain triple data corresponding to the third-party training subset.

[0089] The quality evaluation module is used to perform diversity sampling on the response data in the triple data to obtain a response sampling text, and perform a quality evaluation operation on the response sampling text to generate a quality evaluation result of the response sampling text.

[0090] The iterative module is used to perform beam search filtering operations on the response sampling text according to the quality evaluation result to obtain corresponding filtered triples, and based on the filtered triples, iteratively perform diversity sampling and beam search filtering operations until the preset iteration end requirement is met, and generate the final response text corresponding to the third-party training subset.

[0091] The training module is used to organize the third-party training subset into corresponding security training data based on the final response text, mix the security training data and the third-party training data to generate corresponding mixed training data, and 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 problems.

[0092] Optionally, in an embodiment of the present application, the quality evaluation module 200 includes: an adjustment unit and a revision unit.

[0093] Among them, the adjustment unit is used to determine the temperature parameter corresponding to the preset temperature sampling strategy to adjust the probability distribution corresponding to the natural language processing model through the temperature parameter.

[0094] The revision unit is used to iteratively revise all triples based on the preset kernel sampling strategy and in combination with the probability distribution to obtain a response sampling text.

[0095] Optionally, in an embodiment of the present application, the quality assessment module 200 further includes: a conversion unit, a matching unit, and a first determination unit.

[0096] The conversion unit is configured to convert the response sampling text into a corresponding first part-of-speech tagging sequence, and obtain a corresponding part-of-speech tagging corpus based on the corpus set in the preset security dataset.

[0097] The matching unit is configured to obtain each sentence in the response sampling text that belongs to the part-of-speech tagging corpus, determine the corresponding second part-of-speech tagging sequence for each sentence, and match 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.

[0098] The first determination unit is configured to determine the longest length of the longest common subsequence and the sequence length corresponding to the first part-of-speech tagging sequence, and calculate the ratio of the longest length to the sequence length, so as to determine the readability assessment result in the quality assessment result according to the ratio.

[0099] Optionally, in an embodiment of the present application, the quality assessment module 200 further includes: a first calculation unit and a second determination unit.

[0100] The first calculation unit is configured to perform a relevance assessment, a clarity assessment, a comprehensiveness assessment, and a knowledge assessment on the response sampling text based on the target third-party security model and the preset evaluation criteria, so as to obtain the corresponding relevance score, clarity score, comprehensiveness score, and knowledge score.

[0101] The second determination unit is configured to calculate the average value of the assessment scores of the relevance score, clarity score, comprehensiveness score, and knowledge score, so as to determine the usefulness assessment result in the quality assessment result according to the average value of the assessment scores.

[0102] Optionally, in an embodiment of the present application, the quality assessment module 200 further includes: a second calculation unit and a third calculation unit.

[0103] The second calculation unit is configured to calculate the log-likelihood value corresponding to each sentence in the response sampling text, calculate the average value of the log-likelihood values of all sentences, and obtain the negative number corresponding to the average value.

[0104] The third calculation unit is configured to calculate the exponential function value corresponding to the negative number, so as to determine the perplexity assessment result in the quality assessment result according to the exponential function value.

[0105] Optionally, in an embodiment of the present application, the first calculation unit includes: a theme determination subunit and a relevance quantification subunit.

[0106] Among them, the topic determination subunit is used to determine the problem topic corresponding to the response sampling text.

[0107] The relevance quantification subunit is used to quantify the fit degree between the response sampling text and the problem topic based on the target third-party security model, so as to calculate the relevance score corresponding to the response sampling text according to the fit degree.

[0108] Optionally, in an embodiment of the present application, the first calculation unit further includes: a logical analysis subunit and a clarity quantification subunit.

[0109] Among them, the logical analysis subunit is used to perform grammar and logic analysis on the response sampling text to obtain the corresponding grammar analysis result and logic analysis result.

[0110] The clarity quantification subunit is used to quantify the grammar analysis result and the logic analysis result to generate the clarity score corresponding to the response sampling text.

[0111] Optionally, in an embodiment of the present application, the first calculation unit further includes: a coverage degree analysis subunit and a comprehensiveness analysis subunit.

[0112] Among them, the coverage degree analysis subunit is used to analyze the coverage degree of the response sampling text to the problem topic to obtain the topic coverage degree analysis result corresponding to the problem topic.

[0113] The comprehensiveness analysis subunit is used to determine the comprehensiveness score corresponding to the response sampling text based on the target third-party security model and the topic coverage degree analysis result.

[0114] Optionally, in an embodiment of the present application, the first calculation unit further includes: an understanding degree analysis subunit and a knowledge evaluation subunit.

[0115] Among them, the understanding degree analysis subunit is used to perform knowledge understanding degree analysis on the problem topic based on the response sampling text to obtain the corresponding knowledge understanding degree analysis result.

[0116] The knowledge evaluation subunit is used to evaluate the knowledge score corresponding to the response sampling text based on the target third-party security model and the knowledge understanding degree analysis result.

[0117] Optionally, in an embodiment of the present application, the iteration module 300 includes: a filtering unit and an ascending unit.

[0118] Among them, the filtering unit is used to determine the response filtering threshold based on the responses of all triples, and filter the responses in the response sampling text whose readability evaluation result and usefulness evaluation result are less than the response filtering threshold to obtain the corresponding filtered text.

[0119] An ascending unit, configured to sort the filtered text in ascending order according to the perplexity evaluation result to obtain a corresponding sorting result, and select the top k responses, and based on the top k responses and the questions and prompt words corresponding to the top k responses, construct a screening triple, where k is a positive integer.

[0120] Optionally, in an embodiment of the present application, the training module 400 includes: a construction unit and a mixing unit.

[0121] Among them, the construction unit is configured to determine the questions and prompt words corresponding to each response in the final response text based on the third-party training subset, and construct secure training data according to the final response text and the questions and prompt words corresponding to each response.

[0122] The mixing unit is configured to mix the secure training data and the third-party training data to generate mixed training data, and train the natural language processing model with the mixed training data, so that the trained natural language processing model meets the preset secure alignment requirements, so as to generate secure responses corresponding to different data security problems through the trained natural language processing model.

[0123] For the description of the features in the corresponding embodiments of the optimization device of the natural language processing model, reference can be made to the relevant descriptions in the corresponding embodiments of the optimization method of the natural language processing model, which will not be elaborated here one by one.

[0124] An embodiment of the present application further provides an electronic device, including a memory and a processor. A computer program is stored in the memory, and the processor is configured to run the computer program to execute the steps in any one of the above-mentioned embodiments of the optimization method of the natural language processing model.

[0125] An embodiment of the present application further provides a computer-readable storage medium, in which a computer program is stored. The computer program is configured to execute the steps in any one of the above-mentioned embodiments of the optimization method of the natural language processing model when running.

[0126] In an exemplary embodiment, the above-mentioned computer-readable storage medium may include, but is not limited to: USB flash drive, read-only memory (abbreviated as ROM), random access memory (abbreviated as RAM), mobile hard disk, magnetic disk or optical disc, etc., various media that can store computer programs.

[0127] An embodiment of the present application further provides a computer program product. The computer program product includes a computer program, and when the computer program is executed by a processor, it implements the steps in any of the above-described embodiments of the optimization method for a natural language processing model.

[0128] An embodiment of the present application further provides another computer program product, including a non-volatile computer-readable storage medium. The non-volatile computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, it implements the steps in any of the above-described embodiments of the optimization method for a natural language processing model.

[0129] Those skilled in the art can further realize that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented by electronic hardware, computer software, or a combination of both. To clearly illustrate the interchangeability of hardware and software, the components and steps of each example have been generally described according to functions in the above description. Whether these functions are executed in a hardware or software manner depends on the specific application and design constraints of the technical solution. Skilled professionals can use different methods to implement the described functions for each specific application, but such implementation should not be considered to exceed the scope of the present application.

[0130] The above has introduced in detail an optimization method, apparatus, device, and medium for a natural language processing model provided by the present application. Specific examples are used in this article to elaborate on the principle and implementation manner of the present application. The description of the above embodiments is only used to help understand the method and its core idea of the present application. It should be noted that for those of ordinary skill in the art in this technical field, without departing from the principle of the present application, several improvements and modifications can be made to the present application, and these improvements and modifications also fall within the protection scope of the claims of the present application.

Claims

1. An optimization method for a natural language processing model, characterized in that It includes the following steps: Collect the third-party training data corresponding to the target third-party security model, downsample the third-party training data to obtain the corresponding third-party training subset, and organize the data in the third-party training subset into the form of question-response-prompter triples to obtain the triple data corresponding to the third-party training subset; Perform diversity sampling on the response data in the triple data to obtain a 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; Perform a beam search screening operation on the response sampling text according to the quality assessment result to obtain the corresponding screened triples, and based on the screened triples, iteratively perform diversity sampling and beam search screening operations until the preset iteration end requirement is met, and generate the final response text corresponding to the third-party training subset; Based on the final response text, organize the third-party training subset into the corresponding security training data, and mix the security training data and the third-party training data to generate the corresponding mixed training data, so as to use the mixed training data to train the pre-constructed natural language processing model, so that the trained natural language processing model can generate corresponding security responses according to different data security problems.

2. The optimization method of the natural language processing model according to claim 1, characterized in that The performing diversity sampling on the response data in the triple data to obtain a response sampling text includes: Determine the temperature parameter corresponding to the preset temperature sampling strategy to adjust the probability distribution corresponding to the natural language processing model through the temperature parameter; Based on the preset nucleus sampling strategy, combine the probability distribution, and iteratively revise all triples to obtain the response sampling text.

3. The optimization method of the natural language processing model according to claim 1, characterized in that The performing a quality assessment operation on the response sampling text to generate a quality assessment result of the response sampling text includes: Convert the response sampling text into the corresponding first part-of-speech tagging sequence, and based on the corpus set in the preset security dataset, obtain the corresponding part-of-speech tagging corpus; Obtain each sentence in the response sampling text that belongs to the part-of-speech tagging corpus, determine the corresponding second part-of-speech tagging sequence of each sentence, and match 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; Determine the longest length of the longest common subsequence and the sequence length corresponding to the first part-of-speech tagging sequence, and calculate the ratio of the longest length and the sequence length to determine the readability assessment result in the quality assessment result according to the ratio.

4. The optimization method of the natural language processing model according to claim 3, wherein The performing a quality assessment operation on the response sampling text to generate a quality assessment result of the response sampling text further includes: Based on the target third-party security model and the preset evaluation criteria, perform correlation evaluation, clarity evaluation, comprehensiveness evaluation and knowledge evaluation on the response sampling text to obtain the corresponding correlation score, clarity score, comprehensiveness score and knowledge score; Calculate the average of the evaluation scores of the correlation score, the clarity score, the comprehensiveness score, and the knowledge score, so as to determine the usefulness evaluation result in the quality evaluation result according to the average of the evaluation scores.

5. The optimization method of the natural language processing model according to claim 4, wherein The quality evaluation operation on the response sampled text to generate the quality evaluation result of the response sampled text further includes: Calculate the log-likelihood value corresponding to each sentence in the response sampled text, calculate the average of the log-likelihood values of all sentences, and obtain the negative number corresponding to the average; 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.

6. The optimization method of the natural language processing model according to claim 4, characterized in that Based on the target third-party security model and the preset evaluation criteria, perform correlation evaluation, clarity evaluation, comprehensiveness evaluation, and knowledge evaluation on the response sampled text to obtain the corresponding correlation score, clarity score, comprehensiveness score, and knowledge score, including: Determine the problem theme corresponding to the response sampled text; Based on the target third-party security model, quantify the degree of fit between the response sampled text and the problem theme, so as to calculate the correlation score corresponding to the response sampled text according to the degree of fit.

7. The optimization method of the natural language processing model according to claim 6, wherein Based on the target third-party security model and the preset evaluation criteria, perform correlation evaluation, clarity evaluation, comprehensiveness evaluation, and knowledge evaluation on the response sampled text to obtain the corresponding correlation score, clarity score, comprehensiveness score, and knowledge score, further including: Perform grammar and logic analysis on the response sampled text to obtain the corresponding grammar analysis result and logic analysis result; Quantify the grammar analysis result and the logic analysis result to generate the clarity score corresponding to the response sampled text.

8. The optimization method of the natural language processing model according to claim 7, characterized in that Based on the target third-party security model and the preset evaluation criteria, perform correlation evaluation, clarity evaluation, comprehensiveness evaluation, and knowledge evaluation on the response sampled text to obtain the corresponding correlation score, clarity score, comprehensiveness score, and knowledge score, further including: Analyze the coverage degree of the response sampled text for the problem theme to obtain the theme coverage degree analysis result corresponding to the problem theme; Based on the target third-party security model and the theme coverage degree analysis result, determine the comprehensiveness score corresponding to the response sampled text.

9. The optimization method of the natural language processing model according to claim 8, wherein Based on the target third-party security model and the preset evaluation criteria, perform correlation evaluation, clarity evaluation, comprehensiveness evaluation, and knowledge evaluation on the response sampled text to obtain the corresponding correlation score, clarity score, comprehensiveness score, and knowledge score, further including: Based on the response sampled text, perform an analysis of the degree of knowledge understanding of the problem theme to obtain the corresponding knowledge understanding degree analysis result; Based on the target third-party security model and the knowledge understanding degree analysis result, determine the knowledge score corresponding to the response sampled text.

10. The optimization method of the natural language processing model according to claim 5, characterized in that The beam search and screening operation on the response sampled text according to the quality evaluation result to obtain the corresponding screening triple includes: Based on the responses of all triples, determine a response filtering threshold, and filter the 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; Ascendingly sort the filtered text according to the perplexity evaluation result to obtain the corresponding sorting result, and select the first k responses, and based on the questions and prompt words corresponding to the first k responses and the first k responses, construct the screening triples, where k is a positive integer.

11. The optimization method of the natural language processing model according to claim 1, characterized in that Based on the final response text, organize the third-party training subset into corresponding secure training data, and mix the secure 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-constructed natural language processing model, so that the trained natural language processing model generates corresponding secure responses according to different data security problems, including: Based on the third-party training subset, determine the problems and prompt words corresponding to each response in the final response text, and construct the secure training data according to the final response text and the problems and prompt words corresponding to each response; Mix the secure training data and the third-party training data to generate the mixed training data, and train the natural language processing model with the mixed training data, so that the trained natural language processing model meets the preset secure alignment requirements, so as to generate secure responses corresponding to different data security problems through the trained natural language processing model.

12. An optimization device for a natural language processing model, characterized in that, Including: A downsampling module, configured to collect third-party training data corresponding to a target third-party security model, perform downsampling on 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 the triple data corresponding to the third-party training subset; A quality evaluation module, configured to perform diversity sampling on the response data in the triple data to obtain a response sampling text, and perform a quality evaluation operation on the response sampling text to generate a quality evaluation result of the response sampling text; An iteration module, configured to perform beam search filtering operation on the response sampling text according to the quality evaluation result to obtain corresponding filtered triples, and based on the filtered triples, iteratively perform diversity sampling and beam search filtering operations until a preset iteration end requirement is met, and generate the final response text corresponding to the third-party training subset; A training module, configured to based on the final response text, organize the third-party training subset into corresponding secure training data, and mix the secure 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-constructed natural language processing model, so that the trained natural language processing model generates corresponding secure responses according to different data security problems.

13. An electronic device, characterized in that, Including: A memory, configured to store a computer program; A processor, configured to implement the steps of the optimization method of the natural language processing model according to any one of claims 1 to 11 when executing the computer program.

14. A computer-readable storage medium, characterized in that, A computer program is stored in the computer-readable storage medium, wherein the computer program implements the steps of the optimization method of the natural language processing model according to any one of claims 1 to 11 when executed by a processor.

15. A computer program product comprising a computer program, characterized in that, When the computer program is executed by a processor, it implements the steps of the optimization method of the natural language processing model according to any one of claims 1 to 11.

Citation Information

Patent Citations

  • Cross-language question answering system construction method and device based on generative multi-language model

    CN115795009A

  • Data cleaning method

    CN119884611A

  • System and method for active learning to detect personally identifying information

    US12182307B1

Cited By

  • Lightweight target detection knowledge distillation method

    CN121119044A