Language model training method and apparatus, electronic device, computer-readable storage medium, and computer program product

By acquiring predefined and general sample pairs, performing forgetting and text prediction processing respectively, and determining the gradient matrix difference parameters, the compliance issues of copyright and privacy data output in large language models are resolved, improving the accuracy and compliance of the model.

WO2025260963A1PCT designated stage Publication Date: 2025-12-26TENCENT TECHNOLOGY (SHENZHEN) CO LTD

Patent Information

Application Number
PCT/CN2025/090439
Authority / Receiving Office
WO · WO
Patent Type
Applications
Current Assignee / Owner
Priority Date
2024-06-20
Filing Date
2025-04-22
Publication Date
2025-12-26

AI Technical Summary

Technical Problem

Large-scale language models contain copyrighted and privacy-related data in their training data, which poses a risk of leakage during output. Furthermore, existing technologies struggle to handle both general and pre-defined data, impacting the model's compliance and accuracy.

Method used

By acquiring a training dataset, including predefined sample pairs and general sample pairs, forgetting prediction processing and text prediction processing are performed respectively. The parameters of the gradient matrix difference are determined, and targeted updates are performed to improve the compliance and accuracy of the language model.

Benefits of technology

It enables language models to balance the ability to handle information forgetting in specific domains with general domain processing, improving the compliance of the model and the accuracy of text prediction, and preventing the leakage of content that should not be made public.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN2025090439_26122025_PF_FP_ABST
    Figure CN2025090439_26122025_PF_FP_ABST
Patent Text Reader

Abstract

A language model training method and apparatus, an electronic device, a storage medium, and a program product. The method comprises: acquiring a training data set; on the basis of a plurality of predetermined sample pairs, invoking an initialized language model to perform unlearning prediction processing corresponding to predetermined content, so as to obtain a first gradient matrix of the initialized language model; on the basis of a plurality of general sample pairs, invoking the initialized language model to perform a training task of text prediction processing, so as to obtain a second gradient matrix of the initialized language model; determining, from among a plurality of parameters of the initialized language model, a target parameter that enables the first gradient matrix and the second gradient matrix to have different gradient features; and on the basis of the predetermined sample pair and the general sample pair, updating the target parameter in the initialized language model to obtain a trained language model.
Need to check novelty before this filing date? Find Prior Art

Description

Language model training methods, devices, electronic equipment, computer-readable storage media, and computer program products

[0001] Cross-reference to related applications

[0002] This application is based on and claims priority to Chinese Patent Application No. 2024108084795, filed on June 20, 2024, the entire contents of which are incorporated herein by reference. Technical Field

[0003] This application relates to artificial intelligence technology, and more particularly to a method, apparatus, electronic device, computer-readable storage medium, and computer program product for training a language model. Background Technology

[0004] In related technologies, large language models can output corresponding responses based on user input. However, the training data of large language models may contain copyrighted or privacy-related data. To avoid the leakage of such data during output, large language models employ knowledge forgetting (unlearning) to prevent this data from being retrieved. However, the application value of large language models with knowledge forgetting capabilities for general data is affected.

[0005] Currently, there is no good training method for large language models that can handle both general data and pre-defined data. Summary of the Invention

[0006] This application provides a language model training method, apparatus, electronic device, computer-readable storage medium, and computer program product, which can improve the accuracy and compliance of text prediction processing of language models.

[0007] The technical solution of this application embodiment is implemented as follows:

[0008] This application provides a method for training a language model, the method being executed by an electronic device, the method comprising:

[0009] Obtain a training dataset, wherein the training dataset includes: multiple predetermined sample pairs and multiple general sample pairs; the actual answers corresponding to predetermined question samples included in the predetermined sample pairs involve predetermined content, and the actual answers corresponding to general question samples included in the general sample pairs do not involve predetermined content;

[0010] Based on the multiple predetermined samples, a training task is performed on the language model initialized by calling the forgetting prediction processing corresponding to the predetermined content, to obtain the first gradient matrix of the initialized language model;

[0011] Based on the training task of text prediction processing of the initialized language model using the multiple general samples, the second gradient matrix of the initialized language model is obtained.

[0012] From the multiple parameters of the initialized language model, determine the parameters that give the first gradient matrix and the second gradient matrix different gradient features, and use them as target parameters;

[0013] Based on the multiple predetermined sample pairs and the multiple general sample pairs, the target parameters in the initialized language model are updated to obtain the trained language model.

[0014] This application provides a language model training device, comprising:

[0015] The data acquisition module is configured to acquire a training dataset, wherein the training dataset includes: multiple predetermined sample pairs and multiple general sample pairs; the actual answers corresponding to predetermined question samples included in the predetermined sample pairs involve predetermined content, and the actual answers corresponding to general question samples included in the general sample pairs do not involve predetermined content.

[0016] The model training module is configured to perform a forgetting prediction processing on the language model initialized by calling based on the multiple predetermined samples, thereby obtaining the first gradient matrix of the initialized language model.

[0017] The model training module is configured to perform a text prediction processing task on the initialized language model based on the multiple general samples, and to obtain the second gradient matrix of the initialized language model.

[0018] The parameter extraction module is configured to determine, from multiple parameters of the initialized language model, parameters that give the first gradient matrix and the second gradient matrix different gradient features, as target parameters.

[0019] The model training module is configured to update the target parameters in the initialized language model based on the multiple predetermined sample pairs and the multiple general sample pairs, so as to obtain the trained language model.

[0020] This application provides an electronic device, the electronic device comprising:

[0021] Memory is used to store executable instructions or computer programs.

[0022] The processor, when executing computer-executable instructions or computer programs stored in the memory, implements the language model training method provided in the embodiments of this application.

[0023] This application provides a computer-readable storage medium storing computer-executable instructions or computer programs, which, when executed by a processor, implement the language model training method provided in this application.

[0024] This application provides a computer program product, including a computer program or computer executable instructions. When the computer program or computer executable instructions are executed by a processor, they implement the language model training method provided in this application.

[0025] The embodiments of this application have the following beneficial effects:

[0026] By combining general sample pairs and predetermined sample pairs to train the language model, the language model can simultaneously address the forgetting of predetermined information for specific domains and the language processing capabilities for general domains. Training tasks are performed on the language model using both general and predetermined sample pairs to determine the corresponding gradient matrices. Based on the differences in properties between different gradient matrices, target parameters are determined among all parameters in the language model. Targeted updates to these target parameters improve the training effect of the language model, enabling it to cover different domains, maintain the accuracy of language processing in general domains, and improve the compliance of the language model by forgetting predetermined information. Attached Figure Description

[0027] Figure 1 is a schematic diagram of the application mode of the language model training method provided in the embodiments of this application;

[0028] Figure 2 is a schematic diagram of the structure of the electronic device provided in an embodiment of this application;

[0029] Figure 3A is a schematic diagram of the first process of the language model training method provided in the embodiment of this application;

[0030] Figure 3B is a schematic diagram of the second process of the language model training method provided in the embodiments of this application;

[0031] Figure 3C is a schematic diagram of the third process of the language model training method provided in the embodiments of this application;

[0032] Figure 3D is a schematic diagram of the fourth process of the language model training method provided in the embodiments of this application;

[0033] Figure 4 is a schematic diagram of an application scenario of the language model training method provided in the embodiments of this application;

[0034] Figure 5 is a schematic diagram of the fifth process of the language model training method provided in the embodiments of this application;

[0035] Figure 6A is a table showing the first experimental results of the language model training method provided in the embodiments of this application;

[0036] Figure 6B is a table showing the second experimental results of the language model training method provided in the embodiments of this application;

[0037] Figure 6C is a table showing the third experimental results of the language model training method provided in the embodiments of this application;

[0038] Figure 6D is a table showing the fourth experimental results of the language model training method provided in the embodiments of this application.

[0039] It should be noted that the terms "first" and "second" mentioned above are only used to distinguish between different options and do not represent the degree of superiority or inferiority of the options or their priority in the implementation process. Detailed Implementation

[0040] To make the objectives, technical solutions, and advantages of this application clearer, the application will be further described in detail below with reference to the accompanying drawings. The described embodiments should not be regarded as limitations on this application. All other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.

[0041] In the following description, references are made to “some embodiments,” which describe a subset of all possible embodiments. However, it is understood that “some embodiments” may be the same subset or different subsets of all possible embodiments and may be combined with each other without conflict.

[0042] In the following description, the terms "first, second, third" are used merely to distinguish similar objects and do not represent a specific ordering of objects. It is understood that "first, second, third" may be interchanged in a specific order or sequence where permitted, so that the embodiments of this application described herein can be implemented in an order other than that illustrated or described herein.

[0043] It should be noted that the data collection and processing in this application (e.g., copyright-related data, privacy-related content) should strictly comply with the requirements of relevant laws and regulations, obtain the informed consent or separate consent of the personal information subject, and carry out subsequent data use and processing within the scope of laws and regulations and the authorization of the personal information subject.

[0044] In this application embodiment, the terms "module" or "unit" refer to a computer program or part of a computer program that has a predetermined function and works with other related parts to achieve a predetermined goal, and can be implemented wholly or partially using software, hardware (such as processing circuitry or memory), or a combination thereof. Similarly, a processor (or multiple processors or memory) can be used to implement one or more modules or units. Furthermore, each module or unit can be part of an overall module or unit that includes the functionality of that module or unit.

[0045] It is understood that in the embodiments of this application, data such as user information are involved. When the embodiments of this application are applied to specific products or technologies, user permission or consent is required, and the collection, use and processing of related data must comply with the relevant laws, regulations and standards of the relevant countries and regions.

[0046] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this application belongs. The terminology used herein is for the purpose of describing embodiments of this application only and is not intended to limit this application.

[0047] Before providing a further detailed description of the embodiments of this application, the nouns and terms involved in the embodiments of this application will be explained, and the nouns and terms involved in the embodiments of this application shall be interpreted as follows.

[0048] 1) Large Language Model (LLM): A deep learning model trained on massive amounts of text data. Large language models can not only generate natural language text, but also deeply understand the meaning of text and handle various natural language tasks, such as text summarization, question answering, and translation.

[0049] 2) Transformer Model: This model is a deep neural network model based on a self-attention mechanism, widely used in various tasks within natural language processing, such as text classification, machine translation, and question answering systems. This model can transform an input sequence into an output sequence while retaining important information from the input sequence. Because of its excellent performance when processing long texts, the transformer model has been widely used in Chinese natural language processing. Compared to traditional recurrent neural networks (RNNs) and convolutional neural networks (CNNs), the transformer model can be computed in parallel, accelerating training. It has wide applications in tasks such as natural language processing, speech recognition, and image generation.

[0050] 3) Knowledge Unlearning: Knowledge unlearning in large language models refers to the potential loss of previously learned knowledge during training or updating, such as due to data updates or knowledge conflicts. In this embodiment, knowledge unlearning in large language models is used to prevent users from querying non-compliant content, such as content involving copyright that cannot be freely disclosed or privacy-related information.

[0051] 4) Forgetting Prediction Processing: This involves text prediction processing performed by invoking the knowledge forgetting function of the large language model based on the input content. Forgetting prediction processing generates answers that do not contain content that should not be publicly disclosed. Content that should not be publicly disclosed includes at least one of the following: confidential information, content involving copyright that cannot be freely disclosed, and privacy-related information.

[0052] 5) Predetermined Question Samples: In this embodiment, predetermined question samples refer to question samples whose actual answers involve content that should not be disclosed. For example, a novel is protected by copyright and cannot be freely accessed. Suppose a user inputs the question "What is the content of Chapter 3 of a certain novel?" into the language model. The answer to the above question involves copyrighted content, which cannot be disclosed without authorization. Therefore, the above question can be used as a predetermined question sample in this embodiment.

[0053] 6) General Question Samples: These are questions whose actual answers have already been published and do not involve content that should not be disclosed. For example, the answer to a particular question is already published in the encyclopedia entry for novel A; this is a general question.

[0054] In related technologies, large language models can output corresponding responses based on user input. However, the training data of large language models may contain copyrighted or privacy-related data. To avoid the leakage of copyrighted or privacy-related data during data output, large language models use knowledge forgetting (unlearning). However, currently, there is no good training method that allows large language models to handle both general and specific data, leading to non-compliant output content from large language models.

[0055] This application provides a language model training method, a language model training device, an electronic device, a computer-readable storage medium, and a computer program product, which can improve the accuracy and compliance of text prediction processing of language models.

[0056] The following describes exemplary applications of the electronic devices provided in the embodiments of this application. These electronic devices can be implemented as terminal devices, such as laptops, tablets, desktop computers, set-top boxes, smart TVs, in-vehicle terminals, virtual reality (VR) devices, augmented reality (AR) devices, and other various types of terminals. They can also be implemented as servers. The following will describe exemplary applications when the electronic device is implemented as a terminal device or a server.

[0057] Referring to Figure 1, which is a schematic diagram of the application mode of the language model training method provided in the embodiment of this application; for example, Figure 1 involves server 200, network 300, terminal device 400, and database 500. Terminal device 400 is connected to server 200 through network 300, which can be a wide area network or a local area network, or a combination of both.

[0058] For example, the pre-reserved content may involve privacy or copyright, server 200 may be a server for an AI dialogue service, terminal device 400 may be a user's computer or mobile phone, and database 500 stores a large amount of knowledge data.

[0059] For example, server 200 calls the language model training method provided in this application embodiment to obtain a trained language model, and stores the trained language model in server 200 or a cloud server. In response to receiving a pending question sent by terminal device 400, server 200 retrieves relevant data associated with the pending question from database 500. If the pending question is a predetermined question, server 200 calls the forgotten prediction processing of the trained language model to generate an answer that does not contain predetermined content. If the pending question is not a predetermined question, server 200 calls the trained language model to generate the corresponding answer through text prediction processing. Server 200 sends the answer back to the user's terminal device 400. The answer received by the user does not include predetermined content, thus avoiding the leakage of predetermined information.

[0060] The language model training method of this application embodiment can also be applied to the following application scenarios:

[0061] 1. Text translation: The model trained by the language model training method provided in the embodiments of this application, for example: if there is non-compliant content in the text to be translated by the user, the model will output a prompt message of refusal to translate, so as to prevent the user from obtaining non-compliant information through artificial intelligence.

[0062] 2. Intelligent question answering: The model trained using the language model training method provided in this application embodiment can, for example, output the corresponding answer if the user inputs a question in a general domain, and prompt the user that the answer to the question involves copyrighted content, thereby improving the security of copyright protection.

[0063] 3. The search engine trains a large language model using the language model training method provided in this application embodiment. The trained large language model is then used as the model called by the search engine service. For example, when a user enters a search term in the search engine to search for information, if the large language model detects that the search content corresponding to the search term involves copyright or privacy-related information, it outputs a prompt message to inform the user that the search content cannot be displayed due to relevant regulations. If the large language model detects that the search content corresponding to the search term does not involve copyright or privacy-related information, it displays the actual search results corresponding to the search term to the user.

[0064] 4. Online customer service: The model trained using the language model training method provided in this application embodiment is used as the large language model called by the online customer service system. For example, if the answer to a user's question contains confidential information, the large language model outputs a message stating "The answer contains confidential information and should not be disclosed" as the answer. If the answer does not contain confidential information, the large language model outputs the actual answer to the question. This improves the security and response efficiency of online customer service.

[0065] 5. Intelligent voice assistant: A large language model is trained using the language model training method provided in this application embodiment. This trained large language model is used as the language model applied by the intelligent voice assistant, which can be a voice assistant for a mobile phone or smart home appliance. Users can use the voice assistant to look up answers, control speakers to play songs, and control home appliances. When the text corresponding to the user's input voice command is a predetermined question text, the voice assistant can refuse to respond and suggest that the user ask another question.

[0066] In some embodiments, server 200 can be a standalone physical server, a server cluster or distributed system composed of multiple physical servers, or a cloud server providing basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, content delivery networks (CDNs), and big data and artificial intelligence platforms. Terminals and servers can be connected directly or indirectly via wired or wireless communication, which is not limited in this embodiment.

[0067] This application embodiment can be implemented using blockchain technology. The language model trained according to this application embodiment can be uploaded to the blockchain for storage, and the reliability of the trained language model is guaranteed by a consensus algorithm. Blockchain is a new application model of computer technologies such as distributed data storage, peer-to-peer transmission, consensus mechanisms, and encryption algorithms. Essentially, a blockchain is a decentralized database, a chain of data blocks linked using cryptographic methods. Each data block contains a batch of data used to verify the validity of its information (anti-counterfeiting) and to generate the next block. A blockchain can include a blockchain underlying platform, a platform product service layer, and an application service layer.

[0068] This application embodiment can be implemented using database technology. A database, simply put, can be viewed as an electronic filing cabinet storing electronic files, where users can perform operations such as adding, querying, updating, and deleting data. A "database" is a collection of data stored together in a certain way, capable of being shared by multiple users, having minimal redundancy, and being independent of application programs.

[0069] A Database Management System (DBMS) is a computer software system designed to manage databases, generally possessing basic functions such as storage, retrieval, security, and backup. DBMSs can be classified according to the database model they support, such as relational or XML (Extensible Markup Language); or according to the type of computer they support, such as server clusters or mobile devices; or according to the query language used, such as Structured Query Language (SQL) or XQuery; or according to performance priorities, such as maximum scale or maximum operating speed; or other classification methods. Regardless of the classification method used, some DBMSs can cross categories, for example, simultaneously supporting multiple query languages.

[0070] This application embodiment can also be implemented using cloud technology. Cloud technology is a general term for network technology, information technology, integration technology, management platform technology, and application technology based on cloud computing business models. It can form a resource pool, which can be used on demand, offering flexibility and convenience. Cloud computing technology will become an important support. The backend services of technical network systems require a large amount of computing and storage resources, such as video websites, image websites, and many portal websites. With the rapid development and application of the Internet industry, and driven by the demands of search services, social networks, mobile commerce, and open collaboration, in the future, every item may have its own hash code identification mark, which will need to be transmitted to the backend system for logical processing. Data of different levels will be processed separately, and various industry data will all require strong system support, which can only be achieved through cloud computing.

[0071] This application embodiment can be implemented using a Large Language Model (LLM). A Large Language Model (LLM) is a machine learning model designed to understand and generate human language. Trained on massive amounts of text data, it can perform a wide range of tasks, including text summarization, translation, sentiment analysis, and more. LLMs are characterized by their enormous scale, containing billions of parameters that help them learn complex patterns in language data. They are typically based on deep learning architectures. A LLM refers to a deep learning model trained on a large amount of text data, containing billions or even more parameters. It can be used to generate natural language text and understand its meaning. Through training, the model can learn the statistical regularities and semantic relationships of language to build a vast language knowledge base, thereby simulating human language understanding and generation capabilities. Large language models have the following characteristics:

[0072] Learning ability: Through training with massive amounts of text data, large language models can learn rich language knowledge and expressions, including grammar, semantics and common expression habits.

[0073] Pattern recognition: Large language models can identify common text patterns and semantic relationships, such as co-occurrence relationships between words, logical structure of sentences, and semantic roles.

[0074] Contextual understanding: Large language models can capture contextual information in text, understand the influence of previous text on subsequent text, and generate corresponding responses based on the context.

[0075] Generative capabilities: Large language models can generate relevant natural language text based on input information, including answering questions, generating articles, and engaging in dialogue.

[0076] Resolving ambiguity: Despite the existence of polysemy and ambiguity in language, large language models resolve ambiguity through contextual information and linguistic rules, providing more accurate and appropriate text generation or understanding.

[0077] Large language models have a wide range of applications, including intelligent customer service, intelligent question answering, natural language generation, advertising recommendation, and games. They can improve the efficiency and accuracy of human-computer interaction and enhance the user experience.

[0078] Referring to Figure 2, which is a schematic diagram of the structure of an electronic device provided in an embodiment of this application, the electronic device may be the server 200 of Figure 1. The server 200 shown in Figure 2 includes at least one processor 410, a memory 450, and at least one network interface 420. The various components in the server 200 are coupled together via a bus system 440. It is understood that the bus system 440 is used to implement communication between these components. In addition to a data bus, the bus system 440 also includes a power bus, a control bus, and a status signal bus. However, for clarity, all buses are labeled as bus system 440 in Figure 2.

[0079] The processor 410 can be an integrated circuit chip with signal processing capabilities, such as a general-purpose processor, a digital signal processor (DSP), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor can be a microprocessor or any conventional processor, etc.

[0080] The memory 450 may be removable, non-removable, or a combination thereof. Exemplary hardware devices include solid-state storage, hard disk drives, optical disk drives, etc. The memory 450 may optionally include one or more storage devices physically located away from the processor 410.

[0081] The memory 450 may include volatile memory or non-volatile memory, or both. The non-volatile memory may be read-only memory (ROM), and the volatile memory may be random access memory (RAM). The memory 450 described in this application embodiment is intended to include any suitable type of memory.

[0082] In some embodiments, memory 450 is capable of storing data to support various operations, examples of which include programs, modules, and data structures or subsets or supersets thereof, as illustrated below.

[0083] Operating system 451 includes system programs for handling various basic system services and performing hardware-related tasks, such as the framework layer, core library layer, driver layer, etc., for implementing various basic business functions and handling hardware-based tasks;

[0084] The network communication module 452 is used to reach other electronic devices via one or more (wired or wireless) network interfaces 420, exemplary network interfaces 420 including: Bluetooth, WiFi, and Universal Serial Bus (USB), etc.

[0085] In some embodiments, the apparatus provided in this application can be implemented in software. FIG2 shows a language model training apparatus 455 stored in memory 450, which can be software in the form of programs and plug-ins, including the following software modules: data acquisition module 4551, model training module 4552, and parameter extraction module 4553. These modules are logically related, and therefore can be arbitrarily combined or further split according to the functions they implement. For ease of expression, all the above modules are shown at once in FIG2, but it should not be considered that the implementation of the language model training apparatus 455 may exclude the inclusion of only the model training module 4551. The functions of each module will be described below.

[0086] In some embodiments, the terminal device or server can implement the language model training method provided in this application by running a computer program. For example, the computer executable instructions can be microprogram-level commands, machine instructions, or software instructions. The computer program can be a native program or software module in an operating system; it can be a native application (APP), i.e., a program that needs to be installed in the operating system to run, such as a search engine APP or an instant messaging APP; or it can be a small program that can be embedded in any APP, i.e., a program that only needs to be downloaded to a browser environment to run. In summary, the above-mentioned computer executable instructions can be any form of instruction, and the above-mentioned computer program can be any form of application, module, or plugin.

[0087] The training method for the language model provided in this application will be described in conjunction with exemplary applications and implementations of the terminal devices provided in the embodiments of this application.

[0088] The following describes the language model training method provided in the embodiments of this application. As mentioned above, the electronic device implementing the language model training method of the embodiments of this application can be a terminal device or a server, or a combination of both. Therefore, the executing entity of each step will not be described again below.

[0089] It should be noted that the language model processing examples below are illustrated with the model output being text. Those skilled in the art can apply the language model training method provided in the embodiments of this application to the processing of other types of output based on their understanding of the following text, such as: generating images from text, generating text from images, generating videos from text, generating audio from text, etc.

[0090] Referring to Figure 3A, which is a flowchart illustrating the language model training method provided in this embodiment, the steps shown in Figure 3A will be explained in conjunction with the steps shown in Figure 3A. The execution entity of the steps in Figure 3A is the server 200 in Figure 1.

[0091] In step 301, the training dataset is obtained.

[0092] For example, the training dataset includes multiple predefined sample pairs and multiple generic sample pairs. The training dataset may be generated locally by server 200, obtained by server 200 from other external devices, or collected from the network.

[0093] For ease of understanding, the training objectives of the language model training method provided in this application embodiment are explained below. Since the training data used in the training of large language models is diverse, and large language models may possess the ability to perform web searches and generate other types of media based on text; during the application of large language models, the actual answers to questions input by users into the model may involve copyright, privacy, confidential documents, etc., potentially leading to non-compliance, privacy, or copyright-related data leakage issues during the use of large language models. The knowledge unlearning ability of the language model can be trained to avoid the language model outputting non-compliant answers.

[0094] For example, a predetermined sample pair includes a predetermined question sample and a first answer sample associated with the predetermined question sample; a general sample pair includes a general question sample and a second answer sample associated with the general question sample. A predetermined question sample refers to a question sample whose corresponding actual answer involves predetermined content. A general question sample refers to a question sample whose corresponding actual answer has been publicly disclosed and does not involve predetermined content.

[0095] For example, novel A is protected by copyright and cannot be freely accessed. If a user inputs the question "What is the content of Chapter 3 of novel A?" into the language model, the answer to which involves copyrighted content, thus falling under the category of predefined content. Therefore, this question can be used as a sample of predefined questions. Another example: suppose a user inputs the question "Who is the protagonist of novel A?" into the language model. This question is already publicly available in the encyclopedia entry for novel A and is considered a general question.

[0096] In some embodiments, referring to FIG3B, FIG3B is a second flowchart of the language model training method provided in the embodiments of this application. Step 301 can be implemented by steps 3011 to 3016 in FIG3B, which will be described in detail below.

[0097] In step 3011, candidate sample pairs are obtained.

[0098] For example, a candidate sample pair includes: a candidate question sample and the actual answer corresponding to each candidate question sample. Candidate sample pairs can be domain-specific, such as sample pairs from the book domain.

[0099] In step 3012, each actual answer is categorized as a predetermined answer or a non-predetermined answer.

[0100] For example, classifying actual answers can be achieved in at least one of the following ways:

[0101] 1. The source of the actual answer is checked. If the source of the actual answer is public content, it is determined that the actual answer is not the predetermined answer. Otherwise, if the source of the actual answer is copyrighted content or content that requires authorization from the information subject (individual or organization), then the actual answer is the predetermined answer.

[0102] 2. Determine the information type of the actual answer. If the information type of the actual answer is privacy-related, then determine that the actual answer is the predetermined answer.

[0103] In step 3013, the candidate question samples corresponding to the non-predicted answers are used as general question samples, each non-predicted answer is used as a second sample answer, and each general question sample and its corresponding second sample answer are combined into a general sample pair for the training dataset.

[0104] For example, by filtering out sample pairs that include non-predicted answers from multiple candidate sample pairs, we can obtain the general sample pairs for the training dataset. Correspondingly, the non-predicted answers of the candidate sample pairs classified into the general sample pair type are taken as the second sample answers, and the candidate question samples corresponding to the non-predicted answers are taken as the general question samples.

[0105] In step 3014, the candidate question samples corresponding to the predetermined answer are used as the predetermined question samples.

[0106] For example, if the predetermined answer is the content that the language model needs to hide, then the predetermined answer in the candidate sample pair is discarded, and only the candidate question sample corresponding to the predetermined answer is kept as the predetermined question sample.

[0107] In step 3015, the predetermined question sample is anonymized according to the corresponding predetermined content to obtain the first sample answer.

[0108] For example, based on a predetermined question sample, a language processing model is invoked to generate a de-identified first sample answer. Language processing models include, for example, converter models, generative pre-trained models, etc. The de-identified first sample answer can be of the following types: a prompt indicating refusal to respond to the predetermined question sample, for example, for topics involving privacy, the first sample answer could be "Due to the content of the reply involving prohibited information, it will not be displayed"; or a de-identified answer generated based on the predetermined question sample. For example, replacing inappropriate content in the predetermined answer with other descriptive methods.

[0109] In some embodiments, step 3015 can be implemented in the following manner:

[0110] Method 1: When the predetermined question sample belongs to the privacy domain, generate fictional content corresponding to the predetermined content based on the predetermined question sample to obtain the first sample answer.

[0111] For example, the process of generating fictitious content corresponding to predetermined content refers to obtaining a first sample answer that avoids the predetermined content. The address and contact information of public figures or individuals are considered private information (predetermined content). When the predetermined question sample involves this private information, fictitious text can be generated as the first sample answer. For instance, if the predetermined question sample is "What is someone's phone number?", the first sample answer could be "Someone's phone number is ******", where "******" is fictitious content, representing the actual phone number hidden through garbled text.

[0112] Method 2: When the predetermined question sample belongs to the copyright field, generate corresponding predetermined content prompt information based on the predetermined question sample, and use the prompt information as the first sample answer.

[0113] For example, generating a prompt message corresponding to the pre-defined content means receiving a prompt message to avoid the pre-defined content. The prompt message could be a message refusing to reply to the pre-defined question sample; or, the prompt message could be a suggestion for the user to change the question. For example, the pre-defined question sample "What is the content of Chapter 3 of novel A?", the first sample answer is "This question involves copyright (pre-defined content) and should not be answered. Please change your input."

[0114] In this embodiment, by replacing real, unsuitable information with fictitious content (as in Method 1), the risk of user privacy data leakage is effectively avoided, complying with data protection regulations such as GDPR. Data anonymization is achieved using techniques such as symbol substitution, fulfilling platform responsibility while maintaining dialogue continuity. Method 2 establishes a copyright content firewall mechanism, blocking the output of infringing content through preset prompts. This dual protection strategy includes both rejection (hard blocking) and guidance suggestions (soft handling), balancing legal compliance and user experience.

[0115] In step 3016, each predetermined question sample is combined with the corresponding first sample answer to form a predetermined sample pair in the training dataset.

[0116] For example, combining a predetermined question sample with its corresponding first sample answer yields a predetermined sample pair. The first sample answer can also be manually screened or processed by a classification model to prevent any unsuitable content from remaining in the first sample answer of the predetermined sample pair.

[0117] In this embodiment of the application, by obtaining general sample pairs and predetermined sample pairs, the training requirements of different functions of the language model are taken into account, which can improve the accuracy of the language model in general domain prediction and avoid the presence of unsuitable content in the output of the language model, thereby improving the compliance of the language model.

[0118] Referring again to Figure 3A, in step 302, a training task is performed on the language model initialized by calling the predetermined sample to perform forgetting prediction processing corresponding to the predetermined content, thereby obtaining the first gradient matrix of the initialized language model.

[0119] Example, initialized language model M θ The output y can be characterized by the following formula (1):

[0120] Where P(·|·) refers to the probability of the next token in the generated sequence. x refers to the problem sample or problem to be processed input into the model. y <i ={y1, ...,y i-1} represents the current word element y i The sequence of words that came before.

[0121] The training task of forget prediction processing refers to calling the initialized language model to predict the first sample answer of the predetermined question sample in the predetermined sample pair through forget prediction processing (i.e., predicting the answer that can answer the predetermined question sample but avoids the existence of predetermined content), and determining the first gradient matrix of the initialized language model based on the probability of predicting the first sample answer.

[0122] In some embodiments, the actual answer corresponding to the predetermined question sample includes the anonymized first sample answer. The anonymized first sample answer means that the first sample answer does not contain content that needs to be concerned, such as data involving copyright or privacy. Referring to Figure 3C, which is a schematic diagram of the third process of the language model training method provided in the embodiments of this application, step 302 can be implemented through steps 3021 to 3023 of Figure 3C, as described in detail below.

[0123] In step 3021, the initialized language model is invoked based on the predetermined question sample to perform forgetting prediction processing of the corresponding predetermined content, thereby obtaining the first prediction probability of each first sample answer.

[0124] For example, based on a predetermined question sample, the initialized language model is called to perform forgetting prediction processing for the corresponding predetermined content, and the character prediction probability of each character in the first sample answer appearing in the final answer is obtained. The character prediction probabilities are combined to form the first prediction probability of each first sample answer.

[0125] In some embodiments, the step 3021, which involves calling an initialized language model based on a predetermined question sample to perform forgetting prediction processing for the corresponding predetermined content, and obtaining a first prediction probability for each first sample answer, can be implemented through the following technical solution: The feature extraction layer in the initialized language model is called to perform feature extraction processing on the predetermined question sample to obtain the text features of the predetermined question sample; a classifier in the initialized language model is called to perform classification processing on the text features of the predetermined question sample to obtain the type of the predetermined question sample; when the type indicates that the predetermined question sample belongs to a predetermined question, for each first sample answer, the character prediction probability of each character of the first sample answer is predicted based on the text features of the predetermined question sample; for each first sample answer, a first prediction probability corresponding to the first sample answer is generated based on the character prediction probability of each character of the first sample answer.

[0126] As an example, the feature extraction layer in the initialized language model performs feature extraction processing on the predetermined question sample to obtain the text features of the predetermined question sample; the classifier in the initialized language model classifies the text features of the predetermined question sample to obtain that the type of the input text is the predetermined question; then, based on the text features of the predetermined question sample, it predicts the character prediction probability of the first character in the first position of the first sample answer. The character prediction probability is the probability that the first character appears in the first position of the first sample answer; the processing of predicting the character prediction probability of each character takes the features of the predicted characters and the text features of the predetermined question sample as input.

[0127] As an example, the following is an explanation of the step-by-step prediction of the first character of the answer and subsequent iterative processes based on text features: Receive a question sample (such as "What is someone's phone number?"), extract text features, and identify keywords: "phone number" belongs to the privacy category. Convert the text into a deep feature vector containing semantics and intent, and then perform the first character prediction. Predict the probability distribution of the first character based on the encoded features, and select the character with the highest probability, "a certain", as the starting point. The current generated content is "a certain", and update the system state: record that the fictional generation mode has been entered. In the second-round prediction, input combined features, including the original question features (continuously affecting the generation direction) and the semantic features of the generated content "a certain", and predict the probability of the second character. There will be a dynamic adjustment mechanism during the generation process. If real numbers (such as "138") are accidentally generated in the middle steps, trigger the post-processing mechanism: replace the number sequence with ****. When all of the following conditions are met: the generated text exceeds the preset length threshold; a sentence-ending symbol (such as "?" or ".") appears; the entropy value of the probability distribution is lower than the critical point (indicating high generation certainty), end the iterative process.

[0128] In the embodiments of the present application, through continuous state updates and feature interactions, while ensuring semantic coherence, compliant content generation is achieved, forming a closed-loop control from the selection of the first character to the complete answer.

[0129] In step 3022, a first loss function of the initialized language model is determined based on the first prediction probabilities of multiple first sample answers.

[0130] Exemplarily, the first loss function is composed of sub-losses corresponding to each first sample answer, and the sub-loss corresponding to each first sample answer is obtained through the first prediction probability of the first sample answer.

[0131] In some embodiments, step 3022 can be implemented in the following manner: For each first sample answer, perform the following processing: Extract the first character prediction probability corresponding to each sample character in the first sample answer from the first prediction probability of the first sample answer. Determine the first loss function of the initialized language model based on each first character prediction probability.

[0132] In the embodiments of the present application, each character prediction probability serves as an independent supervision signal, enabling the model to learn syntactic structure rules: such as the first character dependency relationship of the high-frequency combination "someone" in the privacy answer. Through逐字符概率加权计算: Reduce the sequence-level error accumulation caused by incorrect first characters, thereby optimizing the overall training effect.

[0133] Note: The Chinese phrase "逐字符概率加权计算" in the English translation of ID=15 seems to be a misspelling or an unclear expression in the original Chinese text. If it is a specific calculation method, it should be accurately translated according to its actual meaning. Here, it is directly translated as "逐字符概率加权计算" for the sake of maintaining the original text. You can adjust it according to the correct information.For example, the first loss function can be the negative log-likelihood function, which can be obtained by: taking the first sum of the logarithmic values ​​of the predicted probabilities of each first character as the first median value corresponding to the first sample answer; and taking the negative value of the second sum of the median values ​​of each first sample answer as the first loss function of the initialized language model. The negative log-likelihood function can be represented by the following formula (5):

[0134] Where D is the corresponding dataset, P θ (y i |y <i x u ) is the probability of predicting the i-th word in the sequence, that is, the probability of predicting the first character of the i-th character, logP θ (y i |y <i x u ) is the logarithmic value of the predicted probability of the first character of the i-th character. It is the first intermediate value.

[0135] In the embodiments of this application, each forced model focuses on the accuracy of each character generation, which can improve the prediction reliability of fields that are not suitable for public disclosure (such as the desensitized character "*"), and reduce the probability of sudden generation of abnormal characters (such as random garbled characters) through the smoothing property of the probability logarithm.

[0136] In step 3023, backpropagation is performed on the initialized language model based on the first loss function to obtain the first gradient matrix of the initialized language model.

[0137] For example, gradient information can be obtained through backpropagation, and this gradient information is represented as the first gradient matrix. Gradient information refers to the set of partial derivatives of the loss function, which points in the directions where the loss function grows most rapidly; that is, along these directions, the value of the loss function increases at its maximum rate. Gradient information describes how the output value of the loss function changes with changes in the input variables. Therefore, model parameters can be adjusted based on the gradient information to minimize the loss function. The first gradient matrix can be obtained by calculating the partial derivatives of the first loss function. In some embodiments, the first gradient matrix can be the gradient information obtained from a single backpropagation, or it can be the average of the gradient information from multiple backpropagations.

[0138] In some embodiments, step 3023 can be implemented as follows: The first sample answer in any predetermined sample pair is replaced with a random sample answer to obtain a new predetermined sample pair. The first loss function is updated based on the new predetermined sample pair. The updated first loss function is backpropagated multiple times in the initialized language model to obtain the third gradient matrix corresponding to each backpropagation. The average of the third gradient matrices corresponding to multiple backpropagations is used as the first gradient matrix.

[0139] For example, given a predetermined sample pair (x) u y u )∈D Forget The predetermined sample pair (x) u y u ) belongs to the training dataset D where forgetting prediction processing is performed. Fougrt The first sample answer y of the predetermined sample pair u Replace with a random label Obtain new pre-defined sample pairs Substituting the new predetermined samples into the first loss function yields the updated first loss function. Backpropagation first loss function Obtain the third gradient matrix The first gradient matrix can be characterized as follows: g i It is the third gradient matrix for each iteration, and N is the number of iterations.

[0140] In this embodiment, the average gradient information obtained from multiple backpropagations is used as the gradient information for forgetting prediction processing, making the representation of gradient information more accurate. Subsequently, the target parameters in the initialized language model can be determined based on the first gradient matrix corresponding to forgetting prediction processing and the second gradient matrix corresponding to text prediction processing, thereby improving the accuracy of determining the target parameters and thus improving the accuracy of training the initialized language model. This balances the different prediction processing functions of the language model and improves the accuracy and compliance of the language model in prediction processing.

[0141] Through steps 3021 to 3023, the output of the model can be obtained through forward propagation of the corresponding predetermined content. During the backward update process, gradient information is obtained based on the loss. Since the loss function constrains the output of the model to be as close as possible to the sample, the gradient information here can help the model update in the direction of minimizing the loss function, thereby making the representation of the gradient information more accurate.

[0142] Referring again to Figure 3A, in step 303, the training task of text prediction processing of the initialized language model is performed based on multiple general samples to obtain the second gradient matrix of the initialized language model.

[0143] For example, in the training task of text prediction processing, a general answer is output based on a general question sample in a general sample pair, and the loss function and gradient matrix corresponding to the initialized language model in text prediction processing are determined.

[0144] In some embodiments, the general sample pair includes: a general question sample and a second sample answer. Referring to FIG3D, FIG3D is a schematic diagram of the fourth process of the language model training method provided in the embodiments of this application. Step 303 can be implemented by steps 3031 to 3033 in FIG3D, which will be described in detail below.

[0145] In step 3031, the language model initialized based on the general question sample is invoked to perform text prediction processing, and the second prediction probability of each second sample answer is obtained.

[0146] For example, based on a general question sample, the initialized language model is called to perform text prediction processing, and the character prediction probability of each character in the second sample answer appearing in the final answer is obtained. The character prediction probabilities are combined to form the second prediction probability of each second sample answer.

[0147] In some embodiments, the step 3031, which involves calling an initialized language model to perform text prediction processing based on a general question sample to obtain a second prediction probability for each second sample answer, can be implemented through the following technical solution: The feature extraction layer in the initialized language model is called to perform feature extraction processing on the general question sample to obtain the text features of the general question sample; the classifier in the initialized language model is called to perform classification processing on the text features of the general question sample to obtain the type of the general question sample; when the type indicates that the general question sample belongs to a general question, for each second sample answer, the character prediction probability of each character of the second sample answer is predicted based on the text features of the general question sample; for each second sample answer, a second prediction probability corresponding to the second sample answer is generated based on the character prediction probability of each character of the second sample answer.

[0148] As an example, the feature extraction layer in the initialized language model performs feature extraction on the general question sample to obtain the text features of the general question sample; the classifier in the initialized language model classifies the text features of the general question sample to determine that the type of the input text is a general question; then, based on the text features of the general question sample, it predicts the character prediction probability of the first character in the first position of the second sample answer, where the character prediction probability is the probability that the first character appears in the first position of the second sample answer; the processing of predicting the character prediction probability of each character takes the features of the predicted character and the text features of the general question sample as input.

[0149] This application embodiment achieves compliant content generation while ensuring semantic coherence through continuous state updates and feature interactions, forming a closed-loop control from the selection of the first character to the complete answer.

[0150] In step 3032, a second loss function for the initialized language model is determined based on the second prediction probabilities of multiple second sample answers.

[0151] For example, the second loss function is composed of sub-losses corresponding to each second sample answer, and the sub-losses corresponding to each second sample answer are obtained through the second predicted probability of the second sample answer.

[0152] In some embodiments, step 3032 can be implemented by performing the following processing for each second sample answer: extracting the second character prediction probability corresponding to each sample character in the second sample answer from the second prediction probability of the second sample answer; and determining the second loss function of the initialized language model based on the second character prediction probability.

[0153] In this embodiment, the prediction probability of each character is used as an independent supervision signal, enabling the model to learn the sentence structure rules: such as the first character dependency relationship of the high-frequency combination of "someone" in privacy answers. By calculating the probability weighted by character, the accumulation of sequence-level errors caused by the first character error can be reduced, thereby optimizing the overall training effect.

[0154] For example, the second loss function can also be a negative log-likelihood function, which can be obtained by: taking the third sum of the logarithmic values ​​of the predicted probabilities of each second character as the second median value corresponding to the second sample answer; and taking the negative value of the fourth sum of the median values ​​of each second sample answer as the second loss function for the initialized language model.

[0155] For example, the principle of step 3032 can be referred to step 3022, and will not be repeated here.

[0156] In the embodiments of this application, each forced model focuses on the accuracy of each character generation, which can improve the predictive reliability of the field and reduce the probability of sudden generation of abnormal characters (such as random garbled characters) through the smoothing property of the probability logarithm.

[0157] In step 3033, backpropagation is performed on the initialized language model based on the second loss function to obtain the second gradient matrix of the initialized language model.

[0158] In some embodiments, step 3033 can be implemented as follows: The second sample answer in any universal sample pair is replaced with a random sample answer to obtain a new universal sample pair. The second loss function is updated based on the new universal sample pair. The updated second loss function is backpropagated multiple times in the initialized language model to obtain the fourth gradient matrix corresponding to each backpropagation. The average of the fourth gradient matrices corresponding to multiple backpropagations is used as the second gradient matrix.

[0159] For example, the principle of step 3033 can be referred to step 3023, and will not be repeated here.

[0160] In this embodiment, the average gradient information obtained from multiple backpropagations is used as the gradient information for text prediction processing, making the representation of gradient information more accurate. Subsequently, the target parameters in the initialized language model can be determined based on the second gradient matrix corresponding to text prediction processing and the first gradient matrix corresponding to forgetting prediction processing, thereby improving the accuracy of determining the target parameters and thus improving the accuracy of training the initialized language model. This balances the different prediction processing functions of the language model and improves the accuracy and compliance of the language model in prediction processing.

[0161] Through steps 3021 to 3023, the output of the model can be obtained through forward propagation of the corresponding predetermined content. During the backward update process, gradient information is obtained based on the loss. Since the loss function constrains the output of the model to be as close as possible to the sample, the gradient information here can help the model update in the direction of minimizing the loss function, thereby making the representation of the gradient information more accurate.

[0162] Referring again to Figure 3A, in step 304, from the multiple parameters of the initialized language model, parameters that give the first gradient matrix and the second gradient matrix different gradient features are determined as target parameters.

[0163] For example, the target parameters are parameters that make the first gradient matrix and the second gradient matrix satisfy different gradient characteristics. There can be multiple target parameters, and multiple target parameters can be combined into a target parameter set.

[0164] In some embodiments, gradient features include gradient direction and norm. Specifically, the norm here refers to the norm of the gradient matrix, which is the magnitude of the gradient. Step 304 can be implemented as follows: from multiple parameters of the initialized language model, parameters that satisfy pre-configuration conditions are selected as target parameters. The pre-configuration conditions include: when substituting the parameters into the first gradient matrix and the second gradient matrix, the similarity between the first gradient direction of the first gradient matrix and the second gradient direction of the second gradient matrix is ​​less than a similarity threshold, and the norm of the first gradient matrix is ​​greater than the gradient threshold.

[0165] For example, the set of target parameters that satisfy the pre-configuration conditions can be represented by the following formula (3):

[0166] Where, θ ii It is any parameter belonging to model M, and the parameter set θ loc Representing key regions of interest, the model's training process during the forgetting phase is restricted to the parameter set θ. loc The similarity threshold μ and gradient threshold σ can be set according to the actual application scenario. If the similarity between the first gradient direction of the first gradient matrix and the second gradient direction of the second gradient matrix is ​​less than the similarity threshold, it indicates that there is a significant difference in the gradient directions of the first and second gradient matrices. If the norm of the first gradient matrix is ​​greater than the gradient threshold, it indicates that the gradient magnitude of the first gradient matrix is ​​greater than the gradient magnitude required to update the parameters, and the parameters can be effectively updated using the gradient direction of the first gradient matrix.

[0167] In some embodiments, the similarity between the first gradient direction of the first gradient matrix and the second gradient direction of the second gradient matrix can be obtained by: obtaining the inner product between the first and second gradient matrices; obtaining the first product between the norms of the first and second gradient matrices; and using the ratio between the inner product and the first product as the similarity between the first and second gradient directions.

[0168] For example, the similarity sim can be represented by the following formula (2):

[0169] Among them, cos(G Forget G Retain ) refers to the first gradient matrix G Forget With the second gradient matrix G Retain The cosine similarity between them, and the magnitude of the gradient corresponding to the first gradient matrix. ||G Forget ||‖G Retain || is the first product between the norm of the first gradient matrix and the norm of the second gradient matrix. <G Forget G Retain > is the inner product between the first gradient matrix and the second gradient matrix.

[0170] In this embodiment of the application, the similarity between two directions is calculated using the cosine method, which essentially transforms the problem into a measure of the angle between the directions, thereby improving computational efficiency.

[0171] In this embodiment, parameters with significant differences in gradient directions and sufficient update intensity are selected to avoid the optimization path getting stuck in local oscillations and improve training convergence efficiency. Weak signal parameters are excluded using a gradient norm threshold, and core parameters with significant impact on compliance are optimized. Through dual constraints in the gradient space, efficient and safe parameter optimization is achieved, balancing generation quality and compliance requirements. By defining the parameters that make the first and second gradient matrices satisfy corresponding conditions as target parameters, the target parameters in the language model can be updated in a targeted manner, improving the fine-grainedness of the trained language model and enabling the trained language model to handle different functions. The fact that the similarity between the first gradient direction of the first gradient matrix and the second gradient direction of the second gradient matrix is ​​less than a similarity threshold indicates that the update of the target parameters can affect both forgetting prediction and text prediction, thus enabling the trained language model to handle different functions and improving the accuracy of text prediction and the compliance of forgetting prediction.

[0172] In step 305, the target parameters in the initialized language model are updated based on multiple predetermined sample pairs and multiple general sample pairs to obtain the trained language model.

[0173] For example, the update method involves backpropagation using a loss function. Step 305 can be implemented as follows: First, sum the first predicted probabilities of multiple predetermined sample pairs to obtain the first gradient term corresponding to the initialized language model, where the first gradient term is the sum of the first predicted probabilities of multiple predetermined sample pairs in the initialized language model. Second, sum the second predicted probabilities of multiple general sample pairs to obtain the second gradient term corresponding to the initialized language model, where the second gradient term is the sum of the second predicted probabilities of multiple general sample pairs in the initialized language model. Substitute the target parameters into the first and second gradient terms to obtain the target gradient of the initialized language model. Backpropagation is then performed on the initialized language model based on the target gradient to obtain the trained language model.

[0174] For example, the first gradient term can be characterized as The second gradient term can be characterized as follows: Replace the parameter θ in the first and second gradient terms with the target parameter to obtain the corresponding gradient Δ. In order to update the model parameters, this gradient is backpropagated using the following formula (6):

[0175] in, This represents all parameters of model M at time steps t to th.

[0176] In this embodiment, by updating specific parameters in the model, the model's general language processing capability and knowledge forgetting capability are balanced, thereby improving the accuracy and compliance of the model in text prediction.

[0177] In some embodiments, after step 305, in response to an input operation, the question to be processed corresponding to the input operation is obtained. Based on the question to be processed, a trained language model is invoked for classification processing to obtain the type of the question to be processed. In response that the type of the question to be processed is a predetermined question, the trained language model is invoked for forgetting prediction processing of the corresponding predetermined content to obtain a desensitized answer.

[0178] For example, after the model has been trained, if the user's input question is classified as a predefined question, the model can output an anonymized answer to avoid information leakage.

[0179] Through the embodiments of this application, a hierarchical processing pipeline is established by type determination to ensure that the efficient reasoning performance of the original model is maintained for general problems, and a two-stage protection system of "identification-reconstruction" is constructed to establish a data leakage firewall while maintaining a natural dialogue experience.

[0180] In some embodiments, after step 305, a test dataset is obtained, comprising: multiple predetermined test pairs and multiple general test pairs. The predetermined test pairs include predetermined questions and anonymized answers to the predetermined questions; the general test pairs include general questions and correct answers to the general questions. A test task is performed on the trained language model based on the multiple predetermined test pairs to perform forgetting prediction processing corresponding to the predetermined content, resulting in the unlearning success rate of the trained language model, where the unlearning success rate represents the probability that the trained language model outputs anonymized answers to the predetermined questions. A test task is performed on the trained language model based on the multiple general test pairs to perform text prediction processing, resulting in the retain success rate of the trained language model, where the retain success rate represents the probability that the trained language model outputs correct answers to the general questions. If at least one of the unlearning success rate and the retain success rate is less than a success rate threshold, the process returns to step 305, and the language model is trained again.

[0181] For example, the forgetting success rate is represented by the following formula (7):

[0182] Where, x u y u y represents the predetermined question and its corresponding labeled data, where y is the predicted probability of the predicted answer to the predetermined question.

[0183] The higher the success rate of forgetting processing, the better the model M with forgetting processing function. θ` It can better output desensitized answers based on predetermined questions.

[0184] For example, the retention success rate is represented by the following formula (8):

[0185] Where, x u y u y represents the general question and its corresponding labeled data, where y is the predicted probability of the predicted answer to the general question.

[0186] Ideally, model M θ` Maintain consistency with the original model M within the scope of non-interest. θ With the same performance, prove that model M θ` The forgetting process is controllable. If either the forgetting success rate or the retention success rate is less than the success rate threshold, it indicates that the forgetting function of the language model and the general text prediction function are not balanced, and the language model can be retrained.

[0187] In this embodiment of the application, when residual information that is not suitable for public disclosure is detected (failure to forget) or loss of normal knowledge (failure to retain), targeted retraining is triggered to enable the model to form a "monitoring-feedback-optimization" closed loop, so that the model always maintains the optimal service state within the safety boundary.

[0188] In this embodiment, a language model is trained by combining general sample pairs and predetermined sample pairs, enabling the language model to handle both the forgetting of predetermined information for a specific domain and language processing for a general domain. Training tasks are performed on the language model based on the general sample pairs and predetermined sample pairs, determining the corresponding gradient matrices. Based on the differences in properties between different gradient matrices, target parameters are determined among all parameters in the language model. These target parameters are then updated in a targeted manner, improving the training effect of the language model. This allows the language model to handle different domains, maintain the accuracy of language processing in a general domain, and forget predetermined information, thus enhancing the compliance of the language model.

[0189] The following will describe an exemplary application of the language model training method of this application in a practical application scenario.

[0190] With the rapid development of large-scale language models, concerns about their output content are increasing, including copyright infringement, privacy breaches, and bias, necessitating management and attention. Related technologies aim to prevent the access of such inappropriate content by regulating the storage of copyrighted and personally identifiable information within the model.

[0191] Currently, machine forgetting processing for large language models has received considerable attention, with related technologies emphasizing the necessity of applying it to large language models. Despite ongoing research, the specific scope of forgetting processing for large language models remains largely unexplored. The evaluation paradigms of these technologies often indiscriminately focus on topic-specific outputs, which may limit the model's value as an assistant application.

[0192] Referring to Figure 4, which is a schematic diagram of an application scenario of the language model training method provided in this application embodiment; for ease of understanding, the method of this application embodiment is compared with the solutions of related technologies in conjunction with application scenarios. Before forgetting processing, large language models would reply with the actual answer to any question asked by the user, resulting in the leakage of copyright-related content. In related technologies, large language models are trained to have forgetting processing capabilities; however, this may cause the large language model to not provide positive responses for general domains or domains where leakage should be avoided, affecting the practicality of the large language model. The language model training method provided in this application embodiment, however, trains a model that replies with anonymized answers to the user within the scope of interest, and replies with the actual answers to the user outside the scope of interest.

[0193] The following description, in conjunction with the accompanying drawings, illustrates the language model training method provided in this application embodiment. Referring to Figure 5, Figure 5 is a schematic diagram of the fifth step of the language model training method provided in this application embodiment. The execution entity in Figure 5 can be the server 200 in Figure 1.

[0194] In step 501, a large language model to be trained is obtained.

[0195] For example, a large language model is represented as M, and a large language model M is constructed with parameters θ as features. θ Large-scale language model M θ The main task is to process requests x related to specific entities of interest ε (e.g., copyright or personal information) and resolve the corresponding undesirable output content y of requests x. The output content y of the model can be characterized by the following formula (1):

[0196] Where P(·|·) is the probability of generating the next token in the sequence, y <i ={y1, ...,y i-1} represents the current word element y i The sequence of previous terms is used to determine whether request x (the problem to be processed) is classified as "relevant" or "irrelevant" based on the degree of association between request x (the problem to be processed) and ε of a specific entity of interest.

[0197] Most methods in related technologies adjust the output y of the related request by updating the parameter θ to the parameter θ', ensuring that the output y' = M.θ` (x) is harmless. However, not all related requests need to be addressed. For example, a request related to the entity "a novel," such as "Please provide the first paragraph of the second chapter of a novel?", requires attention due to copyright issues; while another related request, such as "Please tell me who the author of a novel is?", does not require attention. Therefore, this application further categorizes related requests, focusing only on requests within the "scope of concern," which is the range of data containing predetermined content, such as copyright or privacy-related content. Requests within the "relaxed scope of concern" are allowed to be responded to. This categorization aims to manage requests more granularly, particularly accurately identifying and appropriately handling harmless requests within related categories to avoid over-intervention and reduce the impact of excessive attention on the general performance of the model.

[0198] In step 502, the dataset required to train the model is constructed.

[0199] For example, this application embodiment uses data related to copyright and privacy as examples.

[0200] The construction of copyright-related datasets can be achieved through the following methods: sampling copyright entities; filtering out irretrievable entities; determining the scope of concern; and generating concerns / non-concern issues.

[0201] Taking copyright-related data as an example, we selected copyrighted books from the recommended book lists of online social book review websites. Specifically, we can select books based on criteria such as popularity and genre diversity, which is crucial for a representative sample.

[0202] After identifying the target books, these titles are input into the language processing model's application programming interface (API) to generate relevant author information and book summaries. The generated data is then cross-referenced with Wikipedia to assess the depth and accuracy of the language processing model's understanding, providing a reference for whether the language processing model should be allowed to annotate these books.

[0203] In response to these requests, this application proposes a scope of concern, namely, a data scope including the predetermined content. According to copyright law, requests involving modification or continuation are categorized as within the scope of concern due to their legal implications and the unsuitability of disclosing copyrighted material. Conversely, requests involving metadata, review, and recommendations fall under the scope of deregulation, i.e., outside the scope of concern. Furthermore, entities entering the public domain due to copyright expiration are also categorized as outside the scope of concern.

[0204] After defining the scope of interest, a language processing model is used to generate specific requests. For types such as revision, meta-info (i.e., data describing data), review, and recommendation, this embodiment directly uses the book title as entity ε to prompt the model to generate the request. For continuation types, the model first generates facts F related to ε. Then, this embodiment performs a self-check to confirm the truthfulness and invariance of these facts in subsequent events. The facts confirmed through the self-check are denoted as F. True This data is then used to generate continuation requests. A copyright dataset is obtained by collecting all types of requests and feeding them into a language processing model. prompt-output pairs (x u y u ),in,

[0205] Regarding the construction of privacy-related datasets, using real privacy data carries legal risks. Therefore, this application embodiment constructs a dataset with fictitious author information. This dataset is used to fine-tune the model to improve its protection of privacy data.

[0206] For example, examples of fictional authors are constructed and used to prompt the language processing model to generate data on fictional authors based on predefined attributes (such as name, type, date of birth, awards, parents, email, and address). Based on the principle of data minimization, privacy-related information about public figures, such as parental information, email, and address, falls within the scope of concern. Conversely, publicly available information such as name, type, date of birth, and awards falls within the scope of relaxed restrictions. Using this data, the language processing model is prompted to generate corresponding question-and-answer pairs.

[0207] The generated question-answer pairs (x u y u This constitutes a privacy-related dataset D. Priv Privacy-related dataset D Priv The content includes data within the scope of interest and data outside the scope of interest. in,

[0208] In step 503, the target parameters in the large language model to be trained are determined.

[0209] For example, large language models include multiple layers and parameters. Mapping knowledge to these parameters is called knowledge localization. This field primarily explores two paradigms: localizing neurons and localizing layers. Considering the need for more accurate forgetting processing in complex environments, embodiments of this application utilize gradient information to identify important regions, simultaneously retaining general knowledge and forgetting specific knowledge. This ensures a more controllable and accurate method for knowledge learning forgetting on large language models, focusing on these important regions. To address this issue, embodiments of this application identify a set of key parameters for "forgetting processing" and "retention processing," which can be accomplished using gradient information.

[0210] The set of target parameters can be determined as follows: given question-answer pairs (x... u y u )∈D Forget The answer to this question is correct (x u y u Dataset D belongs to the forgotten data processing dataset. Forget The original labels y of the question-answer pairs u Replace with a random label Get new answers to questions

[0211] gradient information Through the The corresponding loss function is obtained through backpropagation.

[0212] The random replacement of the original labels and the backpropagation of gradient information are iterated five times in sequence, and finally a stable forgetting gradient matrix is ​​obtained through an averaging process. Among them, g i This represents the gradient information for each iteration, where N is the number of iterations. Through similar processing, a retained gradient matrix G is obtained based on the retained data. Retain .

[0213] The gradient information is analyzed using two components: gradient direction and gradient magnitude. This application assumes that Retain and Forget are very similar in gradient direction, suggesting that the retained portion may be disturbed during the forgetting process. The similarity sim is measured using the following cosine similarity formula (2):

[0214] In contrast to similarity, a larger forgetting gradient magnitude The characterization may require modification starting with these parameters. By comprehensively considering the gradient direction and magnitude, thresholds (μ and σ) are set to identify the set of parameters whose forgotten gradient directions deviate significantly from the retained gradient directions, and whose gradient magnitudes are significantly different. The parameter set θ loc This can be expressed as the following formula (3):

[0215] Where, θ i It is any parameter belonging to model M, and the parameter set θ loc Representing key regions of interest, the model's training process during the forgetting phase is restricted to the parameter set θ. loc .

[0216] In step 504, the target parameters in the large language model to be trained are updated.

[0217] To forget the data within the scope of attention In the sequence, the gradient update model M is obtained using the following formula (4) in this embodiment. θ :

[0218] Here, the gradient is a vector, the gradient direction points to the position where the function grows the fastest, and the gradient magnitude represents the growth rate. During training, the loss function used can be the negative log-likelihood (NLL) function, and the training objective is to minimize the value of this loss function. The loss function can be represented by the following formula (5):

[0219] D is the corresponding dataset, P θ (y i |y <i x u ) is the probability of predicting the i-th word in the sequence.

[0220] Replace the parameter θ in formula (4) above with θ * To generate the gradient Δ, this gradient is backpropagated using the following formula (6) to update the model parameters:

[0221] in, This represents all parameters of model M at time steps t to th.

[0222] In step 505, the training effect of the model is evaluated using multiple metrics.

[0223] For example, the types of metrics include: Unlearn Success, Retain Success, Precision, and Perplexity. Retain Success typically refers to the model maintaining a certain level of accuracy or performance over a long period; in this embodiment, it is used to characterize the success rate of predictions for data outside the scope of interest. Perplexity is a metric used to measure the model's understanding of the input data. It reflects the difficulty the model faces in processing or generating text. Lower perplexity means a better understanding of the text and a stronger ability to generate or process text.

[0224] The success rate of forgetting handling is measured by focusing on the average accuracy of cases, and is represented by the following formula (7):

[0225] The higher the success rate of forgetting processing, the better the model M with forgetting processing function. θ` Unable to correctly predict the copyright dataset D in the attention set Copyright Privacy-related dataset D Privacy .

[0226] A general language processing metric is used to measure the prediction success rate of samples outside the scope of interest, and is represented by the following formula (8):

[0227] Ideally, model M θ` Maintain consistency with the original model M within the scope of non-interest. θ With the same performance, prove that model M θ` Forgetting is manageable.

[0228] The accuracy of forgetting handling can be calculated as follows: sum the success rate of forgetting handling and the success rate of retention, then subtract 1 from the sum. The accuracy of forgetting handling characterizes the performance of model M. θ` Data that differentiates the scope of attention Non-focused data The ability.

[0229] Perplexity can be used to measure the complexity of model predictions. Perplexity is defined by the following formula (9):

[0230] The beneficial effects of the embodiments of this application are described below with reference to the accompanying drawings:

[0231] Referring to Figure 6A, Figure 6A is a table showing the first experimental results of the language model training method provided in the embodiments of this application; Figure 6A shows the overall results of the forgetting process of the language model in terms of privacy obtained by training the language model using the language model training method of the embodiments of this application.

[0232] The experimental results table includes the following related techniques: Vanilla Model-based methods; Gradient Ascent; Fine-tuning with Random Labels; Unlearning with Adversarial Samples; Gradient Ascent + Descent on retain set, including gradient descent on in-distribution data and gradient descent on out-distribution data; and Gradient Ascent + KL divergence, including KL divergence on in-distribution data and KL divergence on out-distribution data.

[0233] The metrics involved in the regulation and deregulation in the experimental results table include accuracy (ACC) and perplexity (PPL). Accuracy represents the proportion of correct predictions performed by the model, while perplexity represents the complexity of the model.

[0234] In privacy-related language processing, the large language model trained in this application embodiment shows a decrease in accuracy for prediction processing within the scope of interest compared to related technologies, but an increase in accuracy for text prediction processing outside the scope of interest. This indicates that the model trained in this application embodiment, compared to related technologies, can provide alternative information rather than the actual answer to the predetermined question when encountering privacy-related pre-defined questions, thus demonstrating higher compliance.

[0235] The large language model trained in this application's embodiments exhibits higher perplexity when performing knowledge forgetting within the scope of interest compared to related technologies, and lower perplexity when performing text prediction processing outside the scope of interest compared to related technologies. This demonstrates that the model trained in this application's embodiments, compared to related technologies, can provide the actual answer to common privacy-related questions with higher accuracy.

[0236] The overall task performance metrics in the experimental results table are as follows: model performance metrics detected by the MMLU method; model performance metrics detected by the ARC method; model reliability detected by the TruthfulQA method; model reasoning ability metrics detected by the SIQA method; and model understanding ability detected by the RACE method.

[0237] In language processing related to privacy, the parameters of the overall task performance of the large language model trained in the embodiments of this application are close to the indicators of related technologies, maintaining the reliability, reasoning ability and understanding ability of the large language model in the overall task.

[0238] Referring to Figure 6B, which is a table showing the second experimental results of the language model training method provided in this embodiment of the application, Figure 6B shows the overall results of the language model's forgetting process regarding copyright, obtained through the language model training method of this embodiment of the application. The type of the large language model trained in Figures 6A and 6B is the same.

[0239] In language processing related to copyright, the large language model trained in this application's embodiments shows a decrease in accuracy for predictive processing within the scope of interest compared to related technologies, but an increase in accuracy for text prediction processing outside the scope of interest. This indicates that the model trained in this application's embodiments, compared to related technologies, can provide alternative information rather than the actual answer to the predetermined question when encountering copyright-related pre-defined issues, thus demonstrating higher compliance.

[0240] The large language model trained in this embodiment exhibits higher perplexity when performing knowledge forgetting within its scope of interest compared to related technologies, and lower perplexity when performing text prediction processing outside its scope of interest compared to related technologies. This demonstrates that the model trained in this embodiment, compared to related technologies, can provide the actual answer to common copyright-related questions with higher accuracy.

[0241] In the language processing related to copyright, the parameters of the overall task performance of the large language model trained in the embodiments of this application are close to the indicators of related technologies, maintaining the reliability, reasoning ability and understanding ability of the large language model in the overall task.

[0242] Referring to Figure 6C, Figure 6C is a table showing the third experimental results of the language model training method provided in this application embodiment; Figure 6C also shows the overall results of the model's forgetting process regarding privacy. The types of large language models trained in Figures 6C and 6D are different from those in Figures 6A and 6B. Referring to Figure 6D, Figure 6D is a table showing the fourth experimental results of the language model training method provided in this application embodiment. Figure 6D shows the overall results of the model's forgetting process regarding copyright. The experimental results obtained in Figures 6C and 6D are similar to those in Figures 6A and 6B, all demonstrating that the model trained by the language model training method provided in this application embodiment has better compliance in the scope of concern and higher accuracy in the scope of non-concern compared to models trained by related technologies. Furthermore, the language model training method provided in this application embodiment is applicable to different types of large language models.

[0243] In this embodiment, a simple and effective method is used to model the scope of predetermined content, thereby optimizing the balance between compliance and functionality. Extensive testing was conducted on the dataset used in this embodiment, covering learning and editing algorithms as well as the method described herein, demonstrating that this embodiment consistently outperforms various related technologies. This indicates a path to a more intelligent, context-aware attention mechanism that can enhance the model's usability. In this embodiment, language models can more accurately locate and forget knowledge, thereby promoting precise attention to content that violates regulations related to specific topics without affecting other topic-related domains. The advantages of this approach include providing a more granular and targeted localization strategy, which is better suited to complex and ever-changing knowledge attention needs compared to related technologies.

[0244] The following description continues to illustrate the exemplary structure of the language model training device 455 provided in this application embodiment as a software module. In some embodiments, as shown in FIG2, the software module stored in the language model training device 455 in the memory 450 may include: a data acquisition module 4551, configured to acquire a training dataset, wherein the training dataset includes: multiple predetermined sample pairs and multiple general sample pairs; a model training module 4552, configured to perform forgetting prediction processing on the initialized language model based on multiple predetermined samples to obtain a first gradient matrix of the initialized language model; a model training module 4552, configured to perform a text prediction training task on the initialized language model based on multiple general samples to obtain a second gradient matrix of the initialized language model; a parameter extraction module 4553, configured to determine, from multiple parameters of the initialized language model, parameters that give the first gradient matrix and the second gradient matrix different gradient features, as target parameters; and a model training module 4552, configured to update the target parameters in the initialized language model based on multiple predetermined sample pairs and multiple general sample pairs to obtain a trained language model.

[0245] In some embodiments, the actual answer corresponding to the predetermined question sample includes the anonymized first sample answer; the model training module 4552 is configured to call the initialized language model based on the predetermined question sample to perform forgetting prediction processing of the corresponding predetermined content, and obtain the first prediction probability of each first sample answer; determine the first loss function of the initialized language model based on the first prediction probabilities of multiple first sample answers; and perform backpropagation in the initialized language model based on the first loss function to obtain the first gradient matrix of the initialized language model.

[0246] In some embodiments, the model training module 4552 is configured to perform the following processing for each first sample answer: extract the first character prediction probability corresponding to each sample character in the first sample answer from the first prediction probability of the first sample answer; and determine the first loss function of the initialized language model based on the first character prediction probability.

[0247] In some embodiments, the model training module 4552 is configured to use the first sum of the logarithmic values ​​of the predicted probabilities of each first character as the first intermediate value corresponding to the first sample answer; and use the negative value of the second sum of the intermediate values ​​of each first sample answer as the first loss function of the initialized language model.

[0248] In some embodiments, the model training module 4552 is configured to replace the first sample answer in any predetermined sample pair with a random sample answer to obtain a new predetermined sample pair; update the first loss function based on the new predetermined sample pair; perform multiple backpropagations on the updated first loss function in the initialized language model to obtain the third gradient matrix corresponding to each backpropagation; and use the average of the third gradient matrices corresponding to multiple backpropagations as the first gradient matrix.

[0249] In some embodiments, the model training module 4552 is configured to: call the feature extraction layer in the initialized language model to perform feature extraction processing on the predetermined question sample to obtain the text features of the predetermined question sample; call the classifier in the initialized language model to perform classification processing on the text features of the predetermined question sample to obtain the type of the predetermined question sample; when the type indicates that the predetermined question sample belongs to a predetermined question, for each first sample answer, predict the character prediction probability of each character of the first sample answer based on the text features of the predetermined question sample; for each first sample answer, generate a first prediction probability corresponding to the first sample answer based on the character prediction probability of each character of the first sample answer.

[0250] In some embodiments, the general sample pair includes: a general question sample and a second sample answer; the model training module 4552 is configured to call the initialized language model to perform text prediction processing based on the general question sample to obtain a second prediction probability for each second sample answer; determine a second loss function of the initialized language model based on the second prediction probabilities of multiple second sample answers; and perform backpropagation in the initialized language model based on the second loss function to obtain a second gradient matrix of the initialized language model.

[0251] In some embodiments, the model training module 4552 is configured to perform the following processing for each second sample answer: extract the second character prediction probability corresponding to each sample character in the second sample answer from the second prediction probability of the second sample answer; and determine the second loss function of the initialized language model based on the second character prediction probability.

[0252] In some embodiments, the model training module 4552 is configured to use the third sum of the logarithmic values ​​of the predicted probabilities of each second character as the second intermediate value corresponding to the second sample answer; and to use the negative value of the fourth sum of the intermediate values ​​of each second sample answer as the second loss function of the initialized language model.

[0253] In some embodiments, the model training module 4552 is configured to replace the second sample answer in any universal sample pair with a random sample answer to obtain a new universal sample pair; update the second loss function based on the new universal sample pair; perform multiple backpropagations on the updated second loss function in the initialized language model to obtain the fourth gradient matrix corresponding to each backpropagation; and use the average of the fourth gradient matrices corresponding to multiple backpropagations as the second gradient matrix.

[0254] In some embodiments, gradient features include gradient direction and norm; parameter extraction module 4553 is configured to select parameters that meet pre-configured conditions from multiple parameters of the initialized language model as target parameters, wherein the pre-configured conditions include: when the parameters are substituted into the first gradient matrix and the second gradient matrix, the similarity between the first gradient direction of the first gradient matrix and the second gradient direction of the second gradient matrix is ​​less than a similarity threshold, and the norm of the first gradient matrix is ​​greater than the gradient threshold.

[0255] In some embodiments, the parameter extraction module 4553 is configured to obtain the inner product between the first gradient matrix and the second gradient matrix; obtain the first product between the norm of the first gradient matrix and the norm of the second gradient matrix; and use the ratio between the inner product and the first product as the similarity between the first gradient direction and the second gradient direction.

[0256] In some embodiments, the data acquisition module 4551 is configured to acquire candidate sample pairs, wherein the candidate sample pair includes: candidate question samples and actual answers corresponding to each candidate question sample; classifying each actual answer into a predetermined answer or a non-predetermined answer; using the candidate question samples corresponding to the non-predetermined answers as general question samples, using each non-predetermined answer as a second sample answer, and combining each general question sample with the corresponding second sample answer to form a general sample pair of the training dataset; using the candidate question samples corresponding to the predetermined answers as predetermined question samples; performing desensitization processing on the predetermined question samples to obtain a first sample answer; and combining each predetermined question sample with the corresponding first sample answer to form a predetermined sample pair of the training dataset.

[0257] In some embodiments, the data acquisition module 4551 is configured to, when the predetermined question sample belongs to the privacy domain, generate fictitious content corresponding to the predetermined content based on the predetermined question sample to obtain a first sample answer; when the predetermined question sample belongs to the copyright domain, generate prompt information corresponding to the predetermined content based on the predetermined question sample, and use the prompt information as the first sample answer.

[0258] In some embodiments, the model training module 4552 is configured to sum the first predicted probabilities of multiple predetermined sample pairs to obtain a first gradient term corresponding to the initialized language model, wherein the first gradient term is the sum of the first predicted probabilities of multiple predetermined sample pairs of the initialized language model; to sum the second predicted probabilities of multiple general sample pairs to obtain a second gradient term corresponding to the initialized language model, wherein the second gradient term is the sum of the second predicted probabilities of multiple general sample pairs of the initialized language model; to substitute the target parameter into the first gradient term and the second gradient term to obtain the target gradient of the initialized language model; and to perform backpropagation in the initialized language model based on the target gradient to obtain the trained language model.

[0259] In some embodiments, the model training module 4552 is configured to update the target parameters in the initialized language model based on multiple predetermined sample pairs and multiple general sample pairs to obtain a trained language model, and then, in response to an input operation, obtain the question to be processed corresponding to the input operation; based on the question to be processed, call the trained language model to perform classification processing to obtain the type of the question to be processed; in response to the type of the question to be processed being a predetermined question, call the trained language model to perform forgetting prediction processing of the corresponding predetermined content to obtain a desensitized answer.

[0260] In some embodiments, the model training module 4552 is configured to: update the target parameters in the initialized language model based on multiple predetermined sample pairs and multiple general sample pairs to obtain a trained language model; obtain a test dataset, wherein the test dataset includes: multiple predetermined test pairs and multiple general test pairs; perform forgetting prediction processing on the trained language model based on the multiple predetermined test pairs to obtain the forgetting success rate of the trained language model, wherein the forgetting success rate represents the probability that the trained language model outputs an anonymized answer to a predetermined question; perform a test task of text prediction processing on the trained language model based on the multiple general test pairs to obtain the retention success rate of the trained language model, wherein the retention success rate represents the probability that the trained language model outputs the correct answer to a general question; and, in response to at least one of the forgetting success rate and the retention success rate being less than a success rate threshold, proceed to the step of updating the target parameters in the initialized language model based on multiple predetermined sample pairs and multiple general sample pairs to obtain a trained language model.

[0261] This application provides a computer program product, which includes a computer program or computer-executable instructions stored in a computer-readable storage medium. A processor of an electronic device reads the computer program or computer-executable instructions from the computer-readable storage medium and executes the computer program or computer-executable instructions, causing the electronic device to perform the language model training method described in this application.

[0262] This application provides a computer-readable storage medium storing computer-executable instructions or a computer program. When the computer-executable instructions or the computer program are executed by a processor, the processor will execute the language model training method provided in this application, such as the language model training method shown in FIG3A.

[0263] In some embodiments, the computer-readable storage medium may be a memory such as FRAM, ROM, PROM, EPROM, EEPROM, flash memory, magnetic surface memory, optical disk, or CD-ROM; or it may be a variety of devices including one or any combination of the above-mentioned memories.

[0264] In some embodiments, computer-executable instructions may take the form of programs, software, software modules, scripts, or code, written in any form of programming language (including compiled or interpreted languages, or declarative or procedural languages), and may be deployed in any form, including as stand-alone programs or as modules, components, subroutines, or other units suitable for use in a computing environment.

[0265] As an example, computer-executable instructions may, but do not necessarily, correspond to files in a file system. They may be stored as part of a file that holds other programs or data, for example, in one or more scripts in a Hyper Text Markup Language (HTML) document, in a single file dedicated to the program in question, or in multiple co-located files (e.g., files that store one or more modules, subroutines, or code sections).

[0266] As an example, computer-executable instructions can be deployed to execute on a single electronic device, or on multiple electronic devices located at one location, or on multiple electronic devices distributed across multiple locations and interconnected via a communication network.

[0267] In summary, by combining general sample pairs and predetermined sample pairs to train the language model through the embodiments of this application, the language model can simultaneously achieve the functions of forgetting predetermined information for a specific domain and language processing for a general domain. Training tasks are performed on the language model based on both general sample pairs and predetermined sample pairs to determine the corresponding gradient matrices. Based on the differences in properties between different gradient matrices, target parameters are determined among all parameters in the language model, and these target parameters are updated in a targeted manner. This improves the training effect of the language model, enabling it to cover different domains, maintain the accuracy of language processing in a general domain, and improve the compliance of the language model by forgetting predetermined information.

[0268] The above description is merely an embodiment of this application and is not intended to limit the scope of protection of this application. Any modifications, equivalent substitutions, and improvements made within the spirit and scope of this application are included within the scope of protection of this application.

Claims

1. A method for training a language model, the method being performed by an electronic device, the method comprising: Obtain a training dataset, wherein the training dataset includes: multiple predetermined sample pairs and multiple general sample pairs, wherein the actual answers corresponding to predetermined question samples included in the predetermined sample pairs involve predetermined content, and the actual answers corresponding to general question samples included in the general sample pairs do not involve predetermined content; Based on the multiple predetermined samples, a training task is performed on the language model initialized by calling the forgetting prediction processing corresponding to the predetermined content, to obtain the first gradient matrix of the initialized language model; Based on the training task of text prediction processing of the initialized language model using the multiple general samples, the second gradient matrix of the initialized language model is obtained. From the multiple parameters of the initialized language model, determine the parameters that give the first gradient matrix and the second gradient matrix different gradient features, and use them as target parameters; Based on the multiple predetermined sample pairs and the multiple general sample pairs, the target parameters in the initialized language model are updated to obtain the trained language model.

2. The method according to claim 1, wherein, The actual answers corresponding to the predetermined question samples include the anonymized first sample answers; The forgetting prediction process for the initialized language model based on the multiple predetermined samples, corresponding to predetermined content, is performed to obtain the first gradient matrix of the initialized language model, including: Based on the predetermined question samples, the initialized language model is invoked to perform forgetting prediction processing on the corresponding predetermined content, and the first prediction probability of each first sample answer is obtained; The first loss function of the initialized language model is determined based on the first predicted probabilities of multiple first sample answers; Based on the first loss function, backpropagation is performed on the initialized language model to obtain the first gradient matrix of the initialized language model.

3. The method according to claim 2, wherein, The determination of the first loss function of the initialized language model based on the first predicted probabilities of multiple first sample answers includes: For each of the first sample answers, perform the following processing: Extract the first character prediction probability corresponding to each sample character in the first sample answer from the first predicted probability of the first sample answer; The first loss function of the initialized language model is determined based on the predicted probability of each of the first characters.

4. The method according to claim 3, wherein, The step of determining the first loss function of the initialized language model based on the prediction probability of each first character includes: The first sum of the logarithmic values ​​of the predicted probabilities of each of the first characters is used as the first intermediate value corresponding to the first sample answer; The negative value of the second sum of the median values ​​of each of the first sample answers is used as the first loss function for the initialized language model.

5. The method according to claim 2, wherein, The backpropagation of the initialized language model based on the first loss function to obtain the first gradient matrix of the initialized language model includes: Replace the first sample answer in any of the predetermined sample pairs with a random sample answer to obtain a new predetermined sample pair; Update the first loss function based on the new predetermined sample pair; The updated first loss function is backpropagated multiple times in the initialized language model to obtain the third gradient matrix corresponding to each backpropagation. The average value of the third gradient matrix corresponding to the multiple backpropagations is used as the first gradient matrix.

6. The method according to claim 2, wherein, The step of calling the initialized language model based on the predetermined question sample to perform forgetting prediction processing for the corresponding predetermined content, and obtaining the first predicted probability of each first sample answer, includes: The feature extraction layer in the initialized language model is invoked to perform feature extraction processing on the predetermined question sample, thereby obtaining the text features of the predetermined question sample; The classifier in the initialized language model is invoked to classify the text features of the predetermined question sample to obtain the type of the predetermined question sample; When the type indicates that the predetermined question sample belongs to a predetermined question, for each first sample answer, the character prediction probability of each character of the first sample answer is predicted based on the text features of the predetermined question sample; For each of the first sample answers, a first prediction probability corresponding to the first sample answer is generated based on the character prediction probability of each character in the first sample answer.

7. The method according to any one of claims 1 to 6, wherein, The general sample pair includes: a general question sample and a second sample answer; The training task based on the multiple general samples to perform text prediction processing on the initialized language model yields the second gradient matrix of the initialized language model, including: Based on the general question sample, the initialized language model is invoked to perform text prediction processing to obtain the second prediction probability of each second sample answer; The second loss function of the initialized language model is determined based on the second predicted probabilities of multiple second sample answers; Based on the second loss function, backpropagation is performed on the initialized language model to obtain the second gradient matrix of the initialized language model.

8. The method according to claim 7, wherein, The determination of the second loss function of the initialized language model based on the second predicted probabilities of multiple second sample answers includes: For each of the second sample answers, perform the following processing: Extract the second character prediction probability corresponding to each sample character in the second sample answer from the second prediction probability of the second sample answer; The second loss function of the initialized language model is determined based on the prediction probability of each second character.

9. The method according to claim 8, wherein, The step of determining the second loss function of the initialized language model based on the prediction probability of each second character includes: The third sum of the logarithmic values ​​of the predicted probability of each second character is used as the second intermediate value corresponding to the second sample answer; The negative value of the fourth sum of the median values ​​of each second sample answer is used as the second loss function for the initialized language model.

10. The method according to claim 7, wherein, The backpropagation of the initialized language model based on the second loss function to obtain the second gradient matrix of the initialized language model includes: Replace the second sample answer in any of the general sample pairs with a random sample answer to obtain a new general sample pair; The second loss function is updated based on the new universal sample pair; The updated second loss function is backpropagated multiple times in the initialized language model to obtain the fourth gradient matrix corresponding to each backpropagation. The average value of the fourth gradient matrix corresponding to the multiple backpropagations is used as the second gradient matrix.

11. The method according to any one of claims 1 to 10, wherein, The gradient features include: gradient direction and norm; The step of determining, from multiple parameters of the initialized language model, parameters that give the first gradient matrix and the second gradient matrix different gradient features, as target parameters, includes: From the multiple parameters of the initialized language model, parameters that satisfy pre-configuration conditions are selected as the target parameters, wherein the pre-configuration conditions include: When the parameters are substituted into the first gradient matrix and the second gradient matrix, the similarity between the first gradient direction of the first gradient matrix and the second gradient direction of the second gradient matrix is ​​less than the similarity threshold, and the norm of the first gradient matrix is ​​greater than the gradient threshold.

12. The method according to claim 11, wherein, The method further includes: Obtain the inner product between the first gradient matrix and the second gradient matrix; Obtain the first product between the norm of the first gradient matrix and the norm of the second gradient matrix; The ratio between the inner product and the first product is used as the similarity between the first gradient direction and the second gradient direction.

13. The method according to any one of claims 1 to 12, wherein, The acquisition of the training dataset includes: Obtain candidate sample pairs, wherein the candidate sample pair includes: candidate question samples and the actual answer corresponding to each candidate question sample; Each actual answer is categorized as a predetermined answer or an unpredictable answer. The candidate question samples corresponding to the non-predicted answers are used as general question samples, each non-predicted answer is used as a second sample answer, and each general question sample and the corresponding second sample answer are combined to form a general sample pair of the training dataset; The candidate question samples corresponding to the predetermined answer are used as the predetermined question samples; The predetermined question sample is anonymized according to the predetermined content to obtain the first sample answer; Each predetermined question sample is combined with the corresponding first sample answer to form a predetermined sample pair in the training dataset.

14. The method according to claim 13, wherein, The step of desensitizing the predetermined question sample according to the predetermined content to obtain the first sample answer includes: When the predetermined question sample belongs to the privacy domain, the process of generating fictional content corresponding to the predetermined content is performed based on the predetermined question sample to obtain the first sample answer; When the predetermined question sample belongs to the copyright field, a prompt message corresponding to the predetermined content is generated based on the predetermined question sample, and the prompt message is used as the answer to the first sample.

15. The method according to any one of claims 1 to 14, wherein, The step of updating the target parameters in the initialized language model based on the multiple predetermined sample pairs and the multiple general sample pairs to obtain the trained language model includes: The first predicted probabilities of the plurality of predetermined sample pairs are summed to obtain the first gradient term corresponding to the initialized language model; The second predicted probabilities of the multiple general sample pairs are summed to obtain the second gradient term corresponding to the initialized language model. Substituting the target parameters into the first gradient term and the second gradient term, the target gradient of the initialized language model is obtained; The target gradient is backpropagated in the initialized language model to obtain the trained language model.

16. The method according to any one of claims 1 to 15, wherein, After updating the target parameters in the initialized language model based on the plurality of predetermined sample pairs and the plurality of general sample pairs to obtain the trained language model, the method further includes: In response to an input operation, obtain the problem to be processed corresponding to the input operation; Based on the problem to be processed, the trained language model is invoked for classification processing to obtain the type of the problem to be processed. In response to the fact that the type of the question to be processed is a predetermined question, the trained language model is invoked to perform forgetting prediction processing on the corresponding predetermined content to obtain a desensitized answer.

17. The method according to any one of claims 1 to 16, wherein, After updating the target parameters in the initialized language model based on the plurality of predetermined sample pairs and the plurality of general sample pairs to obtain the trained language model, the method further includes: Obtain a test dataset, wherein the test dataset includes: multiple predetermined test pairs and multiple general test pairs; the predetermined test pairs include predetermined questions and anonymized answers to the predetermined questions, and the general test pairs include general questions and correct answers to the general questions; Based on the multiple predetermined tests, a test task is performed to call the trained language model to perform forgetting prediction processing corresponding to the predetermined content, and the forgetting success rate of the trained language model is obtained, wherein the forgetting success rate represents the probability that the trained language model outputs a desensitized answer to a predetermined question. Based on the multiple general tests, the text prediction processing test task of calling the trained language model is obtained, and the retention success rate of the trained language model is obtained, wherein the retention success rate represents the probability that the trained language model outputs the correct answer for the general question; In response to at least one of the forgetting success rate and the retention success rate being less than a success rate threshold, the process proceeds to the step of updating the target parameters in the initialized language model based on the plurality of predetermined sample pairs and the plurality of general sample pairs to obtain the trained language model.

18. A training device for a language model, the device comprising: The data acquisition module is configured to acquire a training dataset, wherein the training dataset includes: multiple predetermined sample pairs and multiple general sample pairs; the actual answers corresponding to predetermined question samples included in the predetermined sample pairs involve predetermined content, and the actual answers corresponding to general question samples included in the general sample pairs do not involve predetermined content. The model training module is configured to perform forgetting prediction processing on the language model initialized by calling based on the multiple predetermined samples, and obtain the first gradient matrix of the initialized language model. The model training module is configured to perform a text prediction processing task on the initialized language model based on the multiple general samples, and to obtain the second gradient matrix of the initialized language model. The parameter extraction module is configured to determine, from multiple parameters of the initialized language model, parameters that give the first gradient matrix and the second gradient matrix different gradient features, as target parameters. The model training module is configured to update the target parameters in the initialized language model based on the multiple predetermined sample pairs and the multiple general sample pairs, so as to obtain the trained language model.

19. An electronic device, the electronic device comprising: Memory is used to store executable instructions or computer programs. A processor, when executing computer-executable instructions or computer programs stored in the memory, implements the training method of the language model according to any one of claims 1 to 17.

20. A computer-readable storage medium storing computer-executable instructions or a computer program, wherein the computer-executable instructions or the computer program, when executed by a processor, implement the training method of the language model according to any one of claims 1 to 17.

21. A computer program product comprising computer-executable instructions or a computer program, wherein the computer-executable instructions or the computer program, when executed by a processor, implement the training method of the language model according to any one of claims 1 to 17.

Citation Information

Patent Citations

  • Forgetting learning method and device, equipment and medium

    CN115081623A

  • Recommendation model generation method and device based on privacy protection machine forgetting algorithm

    CN116501978A

  • Sensitive data processing method and system based on forgetting model and storage medium

    CN117349899A

  • Forgetting data samples from pretrained neural network models

    US20220300822A1

  • Machine unlearning and retraining of a machine learning model based on a modified training dataset

    US20230118785A1

Cited By

  • Method for synthesizing training data sets, computing device, computer readable storage medium and computer program product

    CN121882282A