Natural language processing system encryption method, electronic device and computer-readable medium

By encrypting the mapping of characters and Token IDs in the natural language processing system, the problems of low data security and computing efficiency in traditional systems are solved, ciphertext processing is realized, the risk of data exposure is reduced, computing efficiency and real-time response are improved, and the transparency of user interactions is maintained.

CN120378222BActive Publication Date: 2025-09-09CLP (TIANJIN) NETWORK INFORMATION SECURITY CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202510855011.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-06-25
Publication Date
2025-09-09
Estimated Expiration
2045-06-25

AI Technical Summary

Technical Problem

Traditional natural language processing systems have problems in data security, such as high risk of raw data exposure and low computing efficiency. In particular, they lack protection against side-channel attacks and middle-managed eavesdropping, and the computational overhead of homomorphic encryption schemes is too high to meet real-time requirements.

Method used

By obtaining the character mapping relationship determined by the character encryption algorithm and the Token ID mapping relationship of the Token ID transformation algorithm, the pre-trained natural language processing system is encrypted to realize the processing of ciphertext prompt words, avoid the exposure of plaintext data, and improve computing efficiency and real-time response without mathematical reconstruction.

Benefits of technology

It significantly reduces the risk of exposure of original data, improves data security, reduces computing overhead, improves computing efficiency and real-time response, while maintaining the transparency of human-computer interaction and user experience.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120378222B_ABST
    Figure CN120378222B_ABST
Patent Text Reader

Abstract

This application discloses a natural language processing system encryption method, electronic device, and computer-readable medium. The method obtains a character mapping relationship between original characters and encrypted characters determined based on a character encryption algorithm; determines a Token ID mapping relationship between the original Token ID and the transformed Token ID based on a Token ID transformation algorithm; and encrypts a pre-trained natural language processing system based on the character mapping relationship and the Token ID mapping relationship, so that the encrypted natural language processing system can output a ciphertext response based on an input ciphertext prompt word. The method can resist side-channel attacks and middle eavesdropping, significantly reduce the risk of original data exposure, improve data security, avoid mathematical reconstruction of the system's computing logic, thereby significantly reducing computing overhead, reducing inference latency, improving computing efficiency and real-time response, and eliminating the need to retrain the natural language processing system, further reducing computing overhead and improving encryption efficiency.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of artificial intelligence technology, and in particular, to a natural language processing system encryption method, an electronic device, and a computer-readable medium. Background Art

[0002] Natural language processing (NLP) is a key branch of artificial intelligence (AI) models. One important form of human-computer interaction involves generating natural language responses based on user-entered prompts. Traditional NLP systems face numerous data security challenges, including high risks of raw data exposure and low computational efficiency. Summary of the Invention

[0003] The present application aims to solve one of the technical problems in the related art to a certain extent. To this end, the present application provides a natural language processing system encryption method, an electronic device and a computer-readable medium.

[0004] As a first aspect of the present application, a natural language processing system encryption method is provided, wherein the method comprises:

[0005] Obtaining a character mapping relationship between original characters and encrypted characters determined based on a character encryption algorithm;

[0006] Determine the Token ID mapping relationship between the original Token ID and the transformed Token ID based on the Token ID transformation algorithm;

[0007] The pre-trained natural language processing system is encrypted according to the character mapping relationship and the Token ID mapping relationship, so that the encrypted natural language processing system can output a ciphertext response based on the input ciphertext prompt word.

[0008] Optionally, after encrypting the pre-trained natural language processing system according to the character mapping relationship and the Token ID mapping relationship, the method further includes:

[0009] Receiving a ciphertext prompt word sent by a gateway associated with the device; wherein the ciphertext prompt word is obtained by the gateway converting the plaintext prompt word sent by the user device based on the character mapping relationship;

[0010] The ciphertext prompt word is input into the encrypted natural language processing system to obtain the ciphertext response output by the encrypted natural language processing system, so that the gateway decrypts the ciphertext response to obtain a plaintext response and sends the plaintext response to the user device.

[0011] Optionally, the natural language processing system includes a natural language processing model and an associated text processing module, and encrypting the pre-trained natural language processing system according to the character mapping relationship and the token ID mapping relationship includes:

[0012] According to the character mapping relationship and the Token ID mapping relationship, performing character encryption conversion and Token ID space reconstruction on the original word segmentation table of the text processing module to obtain an encrypted word segmentation table; and

[0013] According to the Token ID mapping relationship, the embedding vector mapping layer and the output decoding layer of the natural language processing model are spatially reconstructed with the Token ID.

[0014] Optionally, the original word segmentation table includes a correspondence between an original token and an original token ID. The process of performing character encryption conversion and spatial reconstruction of the token ID on the original word segmentation table of the text processing module according to the character mapping relationship and the token ID mapping relationship to obtain an encrypted word segmentation table includes:

[0015] Each original character included in each original Token in the original word segmentation table is replaced with the encrypted character corresponding to the original character in the character mapping relationship, and each original Token ID in the original word segmentation table is replaced with the transformed Token ID corresponding to the original Token ID in the Token ID mapping relationship to obtain an encrypted word segmentation table.

[0016] Optionally, the natural language processing model further includes an inference layer, the embedding vector mapping layer is used to determine an embedding vector sequence based on a vector mapping relationship from an original Token ID to an embedding vector and a Token ID sequence input by the text processing module, the inference layer is used to determine a hidden state sequence based on the embedding vector sequence input by the embedding vector mapping layer, and the output decoding layer is used to calculate a predicted original Token ID sequence based on an output weight mapping relationship from a hidden state to each original Token ID and a hidden state sequence input by the inference layer;

[0017] The step of performing spatial reconstruction of the Token ID on the embedding vector mapping layer and the output decoding layer of the natural language processing model according to the Token ID mapping relationship includes:

[0018] Replace each original Token ID in the vector mapping relationship with the transformed Token ID corresponding to the original Token ID in the Token ID mapping relationship; and

[0019] Each original Token ID in the output weight mapping relationship is replaced with the transformed Token ID corresponding to the original Token ID in the Token ID mapping relationship.

[0020] Optionally, after obtaining the character mapping relationship between the original character and the encrypted character determined based on the character encryption algorithm, the character mapping relationship is further stored locally; after encrypting the pre-trained natural language processing system according to the character mapping relationship and the token ID mapping relationship, the method further includes:

[0021] Obtaining an updated character mapping relationship between the original character and the encrypted character re-determined based on the character encryption algorithm;

[0022] According to the locally stored character mapping relationship, the current word segmentation table of the text processing module in the encrypted natural language processing system is rolled back to obtain a rolled-back word segmentation table;

[0023] According to the updated character mapping relationship, character encryption conversion is performed on the fallback word table.

[0024] Optionally, after encrypting the pre-trained natural language processing system according to the character mapping relationship and the Token ID mapping relationship, the method further includes:

[0025] When the preset switching period arrives or the session context switch is identified, the updated Token ID mapping relationship between the original Token ID and the transformed Token ID is obtained;

[0026] According to the updated Token ID mapping relationship, the Token ID space is reconstructed for the current word segmentation table of the text processing module in the encrypted natural language processing system, the embedding vector mapping layer and the output decoding layer of the natural language processing model.

[0027] Optionally, the natural language processing model includes any one of the following: a large language model LLM, a multimodal large language model MLLM.

[0028] As a second aspect of the present application, an electronic device is provided, wherein the electronic device includes:

[0029] one or more processors;

[0030] A memory having one or more computer programs stored thereon, wherein when the one or more computer programs are executed by the one or more processors, the one or more processors implement the natural language processing system encryption method according to the first aspect of the present application.

[0031] As a third aspect of the present application, a computer-readable medium is provided, on which a computer program is stored, wherein when the computer program is executed by a processor, the natural language processing system encryption method according to the first aspect of the present application is implemented.

[0032] The natural language processing system encryption method provided in the embodiments of the present application obtains a character mapping relationship between original characters and encrypted characters determined by a character encryption algorithm, determines a token ID mapping relationship between the original token ID and the transformed token ID according to a token ID transformation algorithm, and encrypts a pre-trained natural language processing system based on the character mapping relationship and the token ID mapping relationship, so that the encrypted natural language processing system can output a ciphertext response based on an input ciphertext prompt word. This method not only enables the encrypted natural language processing system to directly process the ciphertext prompt word, achieving ciphertext processing from input to output, preventing the exposure of plaintext data to memory and defending against side-channel attacks and intermediary eavesdropping, thereby significantly reducing the risk of original data exposure and improving data security, but also avoids mathematical reconstruction of the system's computational logic, significantly reducing computational overhead, reducing inference latency, improving computational efficiency, and achieving real-time response. Furthermore, the method eliminates the need to retrain the natural language processing system, and instead directly encrypts the already trained natural language processing system, further reducing computational overhead and improving the efficiency of natural language processing system encryption. BRIEF DESCRIPTION OF THE DRAWINGS

[0033] The present application will be further described below with reference to the accompanying drawings:

[0034] Figure 1 This is a flowchart of an implementation method of the natural language processing system encryption method provided in an embodiment of the present application;

[0035] Figure 2 This is a flowchart of another embodiment of the natural language processing system encryption method provided in the embodiment of the present application.

[0036] Figure 3 This is a flowchart of another embodiment of the natural language processing system encryption method provided in the embodiment of the present application.

[0037] Figure 4 This is a flowchart of another embodiment of the natural language processing system encryption method provided in the embodiment of the present application.

[0038] Figure 5 This is a flowchart of another implementation of the natural language processing system encryption method provided in an embodiment of the present application;

[0039] Figure 6 This is a flowchart of another embodiment of the natural language processing system encryption method provided in the embodiment of the present application;

[0040] Figure 7 This is a flowchart of another embodiment of the natural language processing system encryption method provided in the embodiment of the present application;

[0041] Figure 8 This is a module diagram of an implementation of an electronic device provided in an embodiment of the present application;

[0042] Figure 9 It is a schematic diagram of the computer-readable medium provided in an embodiment of the present application.

[0043] Description of Reference Numerals

[0044] 101: Processor 102: Memory

[0045] 103: I / O interface 104: bus DETAILED DESCRIPTION

[0046] The embodiments of the present application are described in detail below. Examples of the embodiments are shown in the accompanying drawings, wherein the same or similar reference numerals throughout represent the same or similar elements or elements having the same or similar functions. The embodiments described in the embodiments are intended to be used to explain the present application and are not to be construed as limiting the present application.

[0047] References in this specification to "one embodiment," "an example," or "an example" mean that a particular feature, structure, or characteristic described in connection with the embodiment itself can be included in at least one embodiment disclosed herein. The appearances of the phrase "in one embodiment" in various places in the specification are not necessarily all referring to the same embodiment.

[0048] Natural language processing (NLP) is a key branch of artificial intelligence (AI) models. One of the key human-computer interaction methods is outputting natural language responses based on user-entered prompts. In terms of data security, NLP systems face risks such as input and output being easily manipulated or modified, and sensitive data being easily leaked during transmission or model processing. Traditional NLP systems typically employ encrypted transmission and decryption processing or homomorphic encryption to address these risks.

[0049] The encrypted transmission-decryption processing scheme is suitable for natural language processing systems that only support plaintext input. Users encrypt a prompt word with a public key and then enter it into the natural language processing system. The natural language processing system must then use a private key to decrypt the user input before processing. This makes sensitive data vulnerable to memory or side-channel attacks during the computation process, posing a significant risk of exposing the original data. Homomorphic encryption schemes allow natural language processing systems to directly process ciphertext prompt words. However, these schemes are essentially mathematical transformations based on number theory cryptography, requiring mathematical reconstruction of the computational logic of the system model (such as matrix multiplication and activation functions) to enable them to operate on ciphertext (for example, replacing plaintext addition with homomorphic addition). This scheme is computationally expensive (for example, the latency of the additive homomorphic encryption Paillier scheme increases by over 2000%), making it impossible to meet real-time requirements and resulting in low computational efficiency.

[0050] Based on the above important findings, the applicant of this application has innovatively proposed to encrypt and map characters and transform and map Token IDs at the same time, and to encrypt the natural language processing system based on the character mapping relationship and the Token ID mapping relationship. This can not only enable the encrypted natural language processing system to directly process the ciphertext prompt words, thereby significantly reducing the exposure risk of the original data and improving data security, but also avoid mathematical reconstruction of the system's computing logic, thereby significantly reducing computing overhead, improving computing efficiency and real-time response.

[0051] As a first aspect of the embodiment of the present application, a natural language processing system encryption method is provided, such as Figure 1 As shown, the method includes:

[0052] Step S110, obtaining a character mapping relationship between the original character and the encrypted character determined based on the character encryption algorithm;

[0053] Step S120: Determine a Token ID mapping relationship between the original Token ID and the transformed Token ID according to a Token ID transformation algorithm;

[0054] Step S130: Encrypt the pre-trained natural language processing system according to the character mapping relationship and the Token ID mapping relationship, so that the encrypted natural language processing system can output a ciphertext response based on the input ciphertext prompt word.

[0055] The embodiment of the present application does not impose any special limitation on the execution order between step S110 and step S120. That is, the two can be executed successively or in parallel. When the two are executed successively, either one can be executed first.

[0056] Among them, the embodiment of the present application does not specifically limit how to execute step S110. For example, an original character set supporting the Unicode standard (including terms, symbols, etc. of the corresponding industry, and extensible characters when necessary) can be constructed based on actual industry scenarios of natural language processing (such as intelligent question and answer in the financial field, medical and health consultation, corporate confidential document generation, etc.), and then each original character in the original character set can be encrypted based on the character encryption algorithm to obtain a character mapping relationship between each original character and its corresponding encrypted character.

[0057] Among them, the embodiments of the present application do not make specific limitations on the character encryption algorithm. For example, high-complexity transformation parameters can be generated based on a parameter derivation algorithm (such as an HMAC-based Key Derivation Function (HKDF)) and encrypted in combination with encryption algorithms such as format encoding, compression algorithm or privacy protection algorithm.

[0058] The embodiment of the present application does not impose any special restrictions on whether all original characters in the original character set are encrypted using a completely consistent character encryption algorithm. It is sufficient to ensure that an original character is uniquely mapped to an encrypted character and an encrypted character is uniquely mapped to an original character. Of course, in order to prevent data ambiguity or security vulnerabilities caused by collisions, it is also possible to further ensure that different original characters are encrypted using the same character encryption algorithm. and The collision probability between is less than a certain threshold, e.g. , thus ensuring that the probability of different original characters mapping to the same encrypted character is also extremely low.

[0059] Among them, the embodiments of the present application do not make any specific limitations on the Token ID transformation algorithm. For example, a hash function, a random number generator, etc. can be used.

[0060] Among them, it should be emphasized that step S130 directly encrypts the pre-trained natural language processing system based on the character mapping relationship and the Token ID mapping relationship. That is to say, the embodiment of the present application does not need to involve the training of the natural language processing system, and can directly obtain the trained natural language processing system from the outside and encrypt it.

[0061] The natural language processing system encryption method provided in the embodiments of the present application obtains a character mapping relationship between original characters and encrypted characters determined by a character encryption algorithm, determines a token ID mapping relationship between the original token ID and the transformed token ID according to a token ID transformation algorithm, and encrypts a pre-trained natural language processing system based on the character mapping relationship and the token ID mapping relationship, so that the encrypted natural language processing system can output a ciphertext response based on an input ciphertext prompt word. This method not only enables the encrypted natural language processing system to directly process the ciphertext prompt word, achieving ciphertext processing from input to output, preventing the exposure of plaintext data to memory and defending against side-channel attacks and intermediary eavesdropping, thereby significantly reducing the risk of original data exposure and improving data security, but also avoids mathematical reconstruction of the system's computational logic, significantly reducing computational overhead, reducing inference latency, improving computational efficiency, and achieving real-time response. Furthermore, the method eliminates the need to retrain the natural language processing system, and instead directly encrypts the already trained natural language processing system, further reducing computational overhead and improving the efficiency of natural language processing system encryption.

[0062] The natural language processing system encryption method provided in the embodiment of the present application can reduce the computing overhead by at least 90% compared to the homomorphic encryption scheme, and the inference delay time is less than 10ms.

[0063] The applicant of this application further proposed that by adding a gateway associated with this device (i.e., a device loaded or installed with a natural language processing system), the gateway converts the plaintext prompt words sent by the user device into ciphertext prompt words based on the character mapping relationship, inputs the ciphertext prompt words into the encrypted natural language processing system, obtains the ciphertext response output by the encrypted natural language processing system, and finally the gateway decrypts the ciphertext response to obtain a plaintext response and sends the plaintext response to the user device. In this way, the user device does not need to encrypt the prompt words, and can receive the plaintext response by sending the plaintext prompt words. The human-computer interaction process is transparent and burden-free, which can not only improve data security but also improve the user's human-computer interaction experience.

[0064] Accordingly, in some embodiments, after encrypting the pre-trained natural language processing system according to the character mapping relationship and the Token ID mapping relationship (ie, the step S130 involved), as shown in FIG. Figure 2 As shown, the method further includes:

[0065] Step S140: receiving a ciphertext prompt word sent by a gateway associated with the device; wherein the ciphertext prompt word is obtained by the gateway converting the plaintext prompt word sent by the user device based on the character mapping relationship;

[0066] In step S150, the ciphertext prompt word is input into the encrypted natural language processing system to obtain a ciphertext response output by the encrypted natural language processing system, so that the gateway decrypts the ciphertext response to obtain a plaintext response and sends the plaintext response to the user device.

[0067] Among them, the embodiment of the present application does not make any special limitation on whether the gateway associated with this device is independent of this device. That is, the gateway can include an independent device installed on the communication link between the user device and this device, or it can include a module in this device that integrates the gateway function.

[0068] Among them, the embodiment of the present application transmits all input data to the present device through the gateway associated with the present device, and transmits all output data to the user device through the gateway associated with the present device. The gateway intercepts and encrypts the input data (in addition, it can also perform analysis) to ensure that the data is passed to the encrypted natural language processing system for processing in an encrypted state. The gateway also decrypts the output data (in addition, it can also perform compliance testing, desensitization processing, etc.) to ensure that the response received by the user device can be read directly.

[0069] The natural language processing system encryption method provided in the embodiment of the present application obtains a character mapping relationship between original characters and encrypted characters determined based on a character encryption algorithm, determines a Token ID mapping relationship between an original Token ID and a transformed Token ID according to a Token ID transformation algorithm, encrypts a pre-trained natural language processing system according to the character mapping relationship and the Token ID mapping relationship, and the encrypted natural language processing system can output a ciphertext response based on an input ciphertext prompt word, receives a ciphertext prompt word sent by a gateway associated with the device, the ciphertext prompt word is obtained by the gateway converting a plaintext prompt word sent by a user device based on the character mapping relationship, inputs the ciphertext prompt word into the encrypted natural language processing system, obtains a ciphertext response output by the encrypted natural language processing system, and enables the gateway to character-decrypt the ciphertext response to obtain a plaintext response and send the plaintext response to the user device. It can not only enable the encrypted natural language processing system to directly process the ciphertext prompt words, realize ciphertext processing from input to output, avoid exposing plaintext data to memory, resist side channel attacks and middle eavesdropping, thereby significantly reducing the risk of exposure of original data and improving data security, but also avoid mathematical reconstruction of the system's computing logic, thereby significantly reducing computing overhead, reducing inference latency, improving computing efficiency and real-time response. Moreover, there is no need to retrain the natural language processing system, but directly encrypt the already trained natural language processing system, thereby further reducing computing overhead and improving the efficiency of encrypting the natural language processing system. It also allows users to obtain plaintext responses by entering plaintext prompt words without encrypting the prompt words. The human-computer interaction process is transparent and burden-free, thereby improving the user's human-computer interaction experience.

[0070] The applicant of this application further proposes that, without mathematically reconstructing the computing logic of the natural language processing system, the original word segmentation table of the text processing module associated with the natural language processing model in the natural language processing system is subjected to character encryption conversion and spatial reconstruction of the Token ID based on the character mapping relationship and the Token ID mapping relationship, and the embedding vector mapping layer and the output decoding layer of the natural language processing model are subjected to spatial reconstruction of the Token ID based on the Token ID mapping relationship, thereby realizing encryption of the natural language processing system.

[0071] Accordingly, in some embodiments, the natural language processing system includes a natural language processing model and its associated text processing module, and the pre-trained natural language processing system is encrypted according to the character mapping relationship and the Token ID mapping relationship (i.e., the step S130 involved), such as Figure 3 As shown, including:

[0072] Step S131, performing character encryption conversion and Token ID space reconstruction on the original word segmentation table of the text processing module according to the character mapping relationship and the Token ID mapping relationship to obtain an encrypted word segmentation table;

[0073] Step S132: performing spatial reconstruction of the Token ID on the embedding vector mapping layer and the output decoding layer of the natural language processing model according to the Token ID mapping relationship.

[0074] Among them, step S131 involves character encryption conversion of the original word segmentation table based on the character mapping relationship and spatial reconstruction of the Token ID of the original word segmentation table based on the Token ID mapping relationship. The embodiment of the present application does not make any special restrictions on the execution order between the two, that is, the two can be executed successively or in parallel, and when the two are executed successively, either one can be executed first.

[0075] Among them, the embodiment of the present application does not specifically limit the execution order between step S131 and step S132, that is, the two can be executed successively or in parallel, and when the two are executed successively, either one can be executed first.

[0076] The embodiments of the present application do not specifically limit the text processing module. For example, when the natural language processing model is a large language model (LLM), its associated text processing module is a tokenizer.

[0077] It can be understood that the natural language processing model may include not only the embedding vector mapping layer and the output decoding layer, but also a preprocessing layer, an inference layer (Transformer architecture), a post-processing layer, etc., which will not be elaborated in the embodiments of the present application.

[0078] The natural language processing system encryption method provided in the embodiment of the present application realizes one-time encryption of the entire natural language processing system by performing character encryption conversion on the original word segmentation table of the text processing module according to the character mapping relationship, which enables the text processing module to have ciphertext word segmentation capability, and thus enables the natural language processing model to have ciphertext reasoning capability; it also performs spatial reconstruction of the Token ID on the original word segmentation table, the embedding vector mapping layer and the output decoding layer of the natural language processing model according to the Token ID mapping relationship, thereby realizing secondary encryption of the entire natural language processing system, ensuring that the original Token ID cannot be used for reasoning even if it is attacked and leaked.

[0079] Although the natural language processing model and its associated text processing module are independent of each other, their functions are inseparable. The text processing module is used to: segment the continuous text sequence into discrete vocabulary units (i.e., tokens, which can be words, subwords, or characters, depending on the word segmentation strategy used during the design and training of the natural language processing model), map the segmented tokens into a token ID sequence according to the word segmentation table and provide it to the LLM for processing, and finally map the predicted token ID sequence output by the LLM back to text tokens according to the word segmentation table. In an embodiment of the present application, the word segmentation table includes a static mapping table or a dynamically generated vocabulary library, and the character encryption conversion performed on it does not rely on a specific word segmentation algorithm, but is based on the character mapping relationship.

[0080] In the embodiment of the present application, by performing character encryption conversion on the original word segmentation table of the word segmentation table, the text processing module is equipped with the ciphertext word segmentation capability, thereby enabling the natural language processing model to have the ciphertext reasoning capability. Accordingly, in some embodiments, the original word segmentation table includes the correspondence between the original Token and the original Token ID. According to the character mapping relationship and the Token ID mapping relationship, the original word segmentation table of the text processing module is subjected to character encryption conversion and spatial reconstruction of the Token ID to obtain an encrypted word segmentation table (i.e., the step S131 involved), as shown in FIG. Figure 4 As shown, including:

[0081] Step S1311, replace each original character included in each original Token in the original word segmentation table with the encrypted character corresponding to the original character in the character mapping relationship, and replace each original Token ID in the original word segmentation table with the transformed TokenID corresponding to the original Token ID in the Token ID mapping relationship to obtain an encrypted word segmentation table.

[0082] It is understandable that a token is composed of characters, but the embodiment of the present application does not impose any special limitation on the number of characters included in each original token, which is actually determined by the word segmentation logic.

[0083] It can be understood that the encrypted word table finally obtained includes the corresponding relationship between the encrypted Token and the transformed Token ID.

[0084] As described above, the text processing module provides the Token ID sequence to the natural language processing model for processing. Accordingly, in some embodiments, the natural language processing model further includes an inference layer, wherein the embedding vector mapping layer is used to determine the embedding vector sequence based on the vector mapping relationship from the original Token ID to the embedding vector and the Token ID sequence input by the text processing module, the inference layer is used to determine the hidden state sequence based on the embedding vector sequence input by the embedding vector mapping layer, and the output decoding layer is used to calculate the predicted original Token ID sequence based on the output weight mapping relationship from the hidden state to each original Token ID and the hidden state sequence input by the inference layer;

[0085] According to the Token ID mapping relationship, the embedding vector mapping layer and the output decoding layer of the natural language processing model are spatially reconstructed to perform Token ID (i.e., step S132 involved), as shown in FIG. Figure 5 As shown, including:

[0086] Step S1321, replacing each original Token ID in the vector mapping relationship with the transformed Token ID corresponding to the original Token ID in the Token ID mapping relationship; and

[0087] Step S1322: Replace each original Token ID in the output weight mapping relationship with the transformed Token ID corresponding to the original Token ID in the Token ID mapping relationship.

[0088] Among them, the embodiment of the present application does not specifically limit the execution order between step S1321 and step S1322, that is, the two can be executed successively or in parallel, and when the two are executed successively, either one can be executed first.

[0089] The applicant of this application further proposes that the latest character mapping relationship can be dynamically obtained to update the word segmentation table, further improving the data security of the natural language processing system. Accordingly, in some embodiments, after obtaining the character mapping relationship between the original character and the encrypted character determined by the character encryption algorithm (i.e., step S1110 involved), the character mapping relationship is also stored locally; after encrypting the pre-trained natural language processing system according to the character mapping relationship and the Token ID mapping relationship (i.e., step S130 involved), as shown in FIG. Figure 6 As shown, the method further includes:

[0090] Step S210, obtaining an updated character mapping relationship between the original character and the encrypted character re-determined based on the character encryption algorithm;

[0091] Step S220, performing a fallback process on the current word segmentation table of the text processing module in the encrypted natural language processing system according to the locally stored character mapping relationship to obtain a fallback word segmentation table;

[0092] Step S230: performing character encryption conversion on the fallback word table according to the updated character mapping relationship.

[0093] It is understandable that the “updated character mapping relationship” is different from the “character mapping relationship” obtained in the above step 110 .

[0094] Among them, fallback processing means that the current word segmentation table of the text processing module includes the correspondence between the encrypted Token and the transformed Token ID. According to the locally stored character mapping relationship, the encrypted Token is reversely mapped back to the original Token to obtain a fallback word segmentation table including the correspondence between the original Token and the transformed Token ID.

[0095] Among them, step S230 refers to replacing each original character included in each original Token in the fallback word segmentation table with the encrypted character corresponding to the original character in the updated character mapping relationship.

[0096] The applicant of the present application further proposes that by locally storing the character mapping relationship of each historical version (ie, the character mapping relationship obtained each time step S110 is executed), it is possible to roll back to the word segmentation table of any historical encryption period.

[0097] The applicant of this application also proposes that the encryption of the natural language processing system based on the character mapping relationship and the encryption of the natural language processing system based on the Token ID mapping relationship are independent and do not interfere with each other, that is, not only the character mapping relationship can be dynamically updated, but the Token ID mapping relationship can also be dynamically updated. Accordingly, in some embodiments, after the pre-trained natural language processing system is encrypted according to the character mapping relationship and the Token ID mapping relationship (i.e., step S130 involved), as Figure 7 As shown, the method further includes:

[0098] Step S310: When a preset switching period is reached or a session context switch is identified, an updated Token ID mapping relationship between the original Token ID and the transformed Token ID is obtained;

[0099] Step S320: Based on the updated Token ID mapping relationship, the encrypted natural language processing system performs spatial reconstruction of the Token ID for the current word segmentation table of the text processing module, the embedding vector mapping layer and the output decoding layer of the natural language processing model.

[0100] Among them, the embodiment of the present application does not make any specific restrictions on how to preset the switching period for the Token ID mapping relationship, and can be considered based on many factors such as the resources consumed, time, and required security level of the switching process.

[0101] The embodiment of the present application does not specifically limit how to identify the session context switch. For example, when it is identified that the gateway receives a new plaintext prompt word sent by the user equipment, the session context switch is identified.

[0102] The applicant of this application further proposes that the above-mentioned natural language processing system encryption method can be applied not only to traditional natural language processing models such as large language models (LLMs), but also to models that integrate non-text modalities such as images, speech, and video based on LLMs, such as multimodal large language models (MLLMs). Accordingly, in some embodiments, the natural language processing model includes any of the following: large language models (LLMs) or multimodal large language models (MLLMs).

[0103] Once a traditional natural language processing system involves parameter updates, such as when the homomorphic encryption scheme needs to update encryption parameters, it is necessary to reprocess the historical data in full. The operation of a million-level corpus takes more than 24 hours and cannot adapt to the needs of dynamic scenarios. The natural language processing system encryption method provided in the embodiment of the present application, by locally storing the character mapping relationship of each version (that is, the character mapping relationship obtained each time step S110 is executed), can not only fall back to the word segmentation table of any historical encryption period, but also re-encrypt the word segmentation table easily and quickly, providing a lightweight parameter update mechanism, supporting second-level switching and version rollback, and improving disaster tolerance and processing efficiency.

[0104] In addition, the applicant of this application also proposed that for scenarios where there is a private knowledge base, since the private knowledge base needs to first provide a knowledge base answer to the prompt word entered by the user and provide the knowledge base answer to the natural language processing system as a reference, the embedding model can be configured to encrypt all data to be imported into the private knowledge base based on the character mapping relationship, and then import the encrypted data into the vector database of the private knowledge base to ensure that the data is also in an encrypted state in the vector database. Then, the gateway can first pass the encrypted prompt word to the private knowledge base, and the private knowledge base will pass the encrypted prompt word and the given encrypted knowledge base answer to the encrypted natural language processing system for processing.

[0105] As a second aspect of the embodiments of the present application, an electronic device is provided, wherein, Figure 8 As shown, the electronic device includes:

[0106] One or more processors 101;

[0107] The memory 102 stores one or more computer programs. When the one or more computer programs are executed by the one or more processors 101, the one or more processors 101 implement the natural language processing system encryption method provided in the first aspect of the embodiment of the present application.

[0108] The electronic device may further include one or more I / O interfaces 103 connected between the processor 101 and the memory 102 and configured to implement information exchange between the processor 101 and the memory 102 .

[0109] Among them, the processor 101 is a device with data processing capabilities, including but not limited to a central processing unit (CPU); the memory 102 is a device with data storage capabilities, including but not limited to random access memory (RAM, more specifically such as SDRAM, DDR, etc.), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), and flash memory (FLASH); the I / O interface (read-write interface) is connected between the processor and the memory, and can realize information exchange between the processor and the memory, including but not limited to a data bus (Bus), etc.

[0110] In some embodiments, the processor 101 , the memory 102 , and the I / O interface 103 are connected to each other via a bus 104 , and further connected to other components of the computing device.

[0111] As a third aspect of the embodiment of this application, Figure 9As shown, a computer-readable medium is provided, on which a computer program is stored, wherein when the computer program is executed by a processor, the natural language processing system encryption method provided in the first aspect of the embodiment of the present application is implemented.

[0112] Those skilled in the art will appreciate that all or part of the processes in the above-mentioned embodiment methods can be implemented by instructing the relevant hardware through a computer program. Accordingly, the computer program can be stored in a non-volatile computer-readable storage medium, and when the computer program is executed, it can implement the method of any of the above-mentioned embodiments. Among them, any reference to memory, storage, database or other media used in the embodiments provided in the embodiments of the present application may include non-volatile and / or volatile memory. Non-volatile memory may include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM) or flash memory. Volatile memory may include random access memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in many forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), Synchronous Link DRAM (SLDRAM), Rambus direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM), etc.

[0113] The above are only specific embodiments of the present application, but the scope of protection of the present application is not limited thereto. Those skilled in the art should understand that the present application includes but is not limited to the contents described in the drawings and the above specific embodiments. Any modifications that do not deviate from the functional and structural principles of the present application are included within the scope of the claims.

Claims

1. A natural language processing system encryption method, characterized in that: The method comprises: Obtaining a character mapping relationship between original characters and encrypted characters determined based on a character encryption algorithm; Determine the Token ID mapping relationship between the original Token ID and the transformed Token ID based on the Token ID transformation algorithm; Encrypting the pre-trained natural language processing system according to the character mapping relationship and the token ID mapping relationship, so that the encrypted natural language processing system can output a ciphertext response based on the input ciphertext prompt word; The natural language processing system includes a natural language processing model and its associated text processing module, and the pre-trained natural language processing system is encrypted according to the character mapping relationship and the token ID mapping relationship, including: According to the character mapping relationship and the Token ID mapping relationship, performing character encryption conversion and Token ID space reconstruction on the original word segmentation table of the text processing module to obtain an encrypted word segmentation table; and According to the Token ID mapping relationship, the embedding vector mapping layer and the output decoding layer of the natural language processing model are spatially reconstructed to perform Token ID reconstruction; The natural language processing model further includes an inference layer, wherein the embedding vector mapping layer is used to determine an embedding vector sequence based on a vector mapping relationship from an original Token ID to an embedding vector and a Token ID sequence input by the text processing module; the inference layer is used to determine a hidden state sequence based on an embedding vector sequence input by the embedding vector mapping layer; and the output decoding layer is used to calculate a predicted original Token ID sequence based on an output weight mapping relationship from a hidden state to each original Token ID and a hidden state sequence input by the inference layer. The step of performing spatial reconstruction of the Token ID on the embedding vector mapping layer and the output decoding layer of the natural language processing model according to the Token ID mapping relationship includes: Replace each original Token ID in the vector mapping relationship with the transformed Token ID corresponding to the original Token ID in the Token ID mapping relationship; and Each original Token ID in the output weight mapping relationship is replaced with the transformed Token ID corresponding to the original Token ID in the Token ID mapping relationship.

2. The method according to claim 1, characterized in that After encrypting the pre-trained natural language processing system according to the character mapping relationship and the Token ID mapping relationship, the method further includes: Receiving a ciphertext prompt word sent by a gateway associated with the device; wherein the ciphertext prompt word is obtained by the gateway converting the plaintext prompt word sent by the user device based on the character mapping relationship; The ciphertext prompt word is input into the encrypted natural language processing system to obtain the ciphertext response output by the encrypted natural language processing system, so that the gateway decrypts the ciphertext response to obtain a plaintext response and sends the plaintext response to the user device.

3. The method according to claim 1, characterized in that The original word segmentation table includes a correspondence between an original token and an original token ID. The character encryption conversion and the space reconstruction of the token ID are performed on the original word segmentation table of the text processing module according to the character mapping relationship and the token ID mapping relationship to obtain an encrypted word segmentation table, including: Each original character included in each original Token in the original word segmentation table is replaced with the encrypted character corresponding to the original character in the character mapping relationship, and each original Token ID in the original word segmentation table is replaced with the transformed Token ID corresponding to the original Token ID in the Token ID mapping relationship to obtain an encrypted word segmentation table.

4. The method according to any one of claims 1 to 3, characterized in that After obtaining the character mapping relationship between the original character and the encrypted character determined based on the character encryption algorithm, the character mapping relationship is further stored locally; After encrypting the pre-trained natural language processing system according to the character mapping relationship and the Token ID mapping relationship, the method further includes: Obtaining an updated character mapping relationship between the original character and the encrypted character re-determined based on the character encryption algorithm; According to the locally stored character mapping relationship, the current word segmentation table of the text processing module in the encrypted natural language processing system is rolled back to obtain a rolled-back word segmentation table; According to the updated character mapping relationship, character encryption conversion is performed on the fallback word table.

5. The method according to any one of claims 1 to 3, characterized in that After encrypting the pre-trained natural language processing system according to the character mapping relationship and the Token ID mapping relationship, the method further includes: When the preset switching period arrives or the session context switch is identified, the updated Token ID mapping relationship between the original Token ID and the transformed Token ID is obtained; According to the updated Token ID mapping relationship, the Token ID space is reconstructed for the current word segmentation table of the text processing module in the encrypted natural language processing system, the embedding vector mapping layer and the output decoding layer of the natural language processing model.

6. The method according to any one of claims 1 to 3, characterized in that The natural language processing model includes any one of the following: a large language model LLM, a multimodal large language model MLLM.

7. An electronic device, characterized in that: The electronic device comprises: one or more processors; A memory having one or more computer programs stored thereon, wherein when the one or more computer programs are executed by the one or more processors, the one or more processors implement the natural language processing system encryption method according to any one of claims 1-6.

8. A computer-readable medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the natural language processing system encryption method according to any one of claims 1 to 6 is implemented.

Citation Information

Patent Citations

  • Homomorphic encryption method of deep learning model for natural language processing

    CN115987479A