Text watermark generation method and device, text watermark detection method and device and storage medium
By using verifiable random sampling technology in large language models and embedding unbiased sparse watermarks, the problem of watermark affecting text quality in traditional methods is solved, and high-precision watermark detection and text traceability are achieved.
Patent Information
- Application Number
- CN202411918869.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-23
- Publication Date
- 2025-04-25
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
When traditional large language model watermarking methods try to embed watermarks in text, they are prone to affect text quality and are difficult to achieve effective watermark detection without affecting text quality.
The large language model unbiased sparse watermark technology that can verify random sampling is adopted. By embedding watermarks behind words of specific part-of-speech labels, the text quality is not affected and the detection accuracy of watermarks is improved.
It realizes embedding of unbiased sparse watermarks without damaging text quality, improving the accuracy of text traceability and detection, and solving the abuse of content generated by large language models.
Smart Images

Figure CN119885120A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to a text watermark generation and watermark detection method, and in particular to a text watermark generation and watermark detection method, device and storage medium. Background Art
[0002] In recent years, large language models (LLMs) have developed rapidly in the field of natural language processing. However, this ability to quickly generate text has caused problems in information dissemination and intellectual property protection. For example, the GPT-4 large model can not only write documents and code, but also answer various questions, showing an intelligence level close to that of humans. As such systems become increasingly popular, the public is worried that large models will be used maliciously, such as spreading false information and using artificial intelligence (AI) systems to cheat in academic writing and programming competitions. In addition, due to the increase in the amount of synthetic data on the Internet, future data set construction will face complexity challenges, and synthetic data will need to be identified and eliminated before training the model. Therefore, the ability to detect the ability of AI models to generate text has become the key to reducing the potential harm of large language models.
[0003] If the source of the generated text cannot be identified, it may lead to the spread of misleading information. In order to solve the problem of abuse of large language models, text watermarking technology is an effective means to achieve content traceability and source confirmation by embedding unique identifiers. However, the traditional LLM watermarking method is caught in a dilemma: (1) If the watermark signal is too strong, it is easy to detect, but it will affect the quality of the generated text; (2) If the signal is too weak, although it has little impact on the text quality, it is not easy to be detected. For example, traditional watermarking technology often requires obvious modifications in the generated text, which poses a privacy risk and is difficult to be widely used without affecting the quality of the text. Summary of the invention
[0004] Embodiments of the present invention provide a text watermark generation and watermark detection method, device and storage medium. The text watermark generation and watermark detection method, device and storage medium are based on the unbiased sparse watermark technology of a large language model with verifiable random sampling. The verifiable random sampling algorithm is used to embed invisible watermarks into words with specific part-of-speech tags while maintaining the quality of the text, so that each AI-generated text is attached with a unique sparse identifier, which greatly improves the accuracy of text tracing and detection. In this process, the unbiased method ensures that the original meaning of the text is intact, that is, it will not affect the overall quality of the text, and provides a solution to the traceability and transparency issues of AI-generated content.
[0005] To achieve the above object, a first aspect of an embodiment of the present application provides a text watermark generation method, characterized in that the method comprises the following steps:
[0006] S100) generating a watermark private key and a sparse vocabulary including a plurality of sparse marker words;
[0007] S200) Generate or expand a text using a large language model random sampling technique;
[0008] S300) During the random sampling process, word units in the text are detected in real time until sparse marked words in the sparse vocabulary begin to appear in the text, and then the following steps are performed:
[0009] S400) The random seed generator generates a verifiable random seed based on the watermark private key; and
[0010] S500) passing the verifiable random seed to multiple watermark functions, so as to select words that meet the watermark requirements as watermark words and embed them into the text through an arena scoring algorithm;
[0011] After step S500, step S200 is continued until an end character is encountered or the context window limit is exceeded;
[0012] Each time a watermark word is generated in the text, a corresponding adjusted probability score is added to the text, wherein the pattern formed by the word unit selection of the large language model and the adjusted probability score during the text generation process is regarded as the watermark.
[0013] In some embodiments, step S300 includes the following steps:
[0014] S310) reading the newly generated word unit of the text as the previous word unit; and
[0015] S320) identifying whether the previous word belongs to a sparse marked word according to the sparse vocabulary;
[0016] If step S320 identifies that the previous word belongs to a sparsely marked word, the following steps are performed:
[0017] S330) sparsely mark the previous word to anchor the previous word as a sparsely marked word.
[0018] In some embodiments, step S500 includes the following steps:
[0019] S510) The random seed is passed as input to the multi-level watermark function, and each watermark function generates a candidate word through the random seed, and the calculation formula is as follows:
[0020]
[0021] Where r is the random seed, and its value space is R{0,1} n , that is 2 n The integer value of ;
[0022] In formula (1), given a g value distribution, its cumulative density function is F g ,and Represents F g The inverse function, h(.,.,.) represents the hash function, n represents the security parameter, and l represents the number of watermark function measurement layers;
[0023] S520) comparing the scores obtained by different watermark functions through multiple rounds of tournaments, and selecting the candidate word generated by the watermark function with the highest score as the watermark word;
[0024] S530) embedding the watermark word into the text by placing the watermark word after the previous word to extend the text; and
[0025] S540) Add a watermark word tag to the watermark word to mark the watermark word embedded in the text.
[0026] To achieve the above object, a second aspect of an embodiment of the present application proposes a watermark detection method for a text generated by the text watermark generation method described in the first aspect, comprising the following steps:
[0027] S600) Determining the security of the sparse vocabulary;
[0028] S700) identifying watermark words in the text; and
[0029] S800) detecting the watermark by detecting the frequency of the watermark word following the sparse marked word in the text;
[0030] Step S700 is performed after step S600 determines that the sparse vocabulary is safe.
[0031] In some embodiments, step S700 includes the following steps:
[0032] S710) segmenting the text into word-unit sequences;
[0033] S720) Finding a sparse marked word from the word-unit sequence as a watermark detection anchor point, and marking the next word-unit after the watermark detection anchor point as a word-unit to be detected;
[0034] S730) passing the watermark public key and the word to be detected to an encrypted watermark scoring function to obtain a score of the text under the watermark distribution; and
[0035] S740) Compare the score of the text under the watermark distribution with the score of the text under the original distribution to determine whether the word to be detected is a watermark word.
[0036] In some embodiments, step S730 performs watermark scoring, wherein the watermark public key and the word to be detected are passed to a sparse encrypted watermark scoring function to obtain a score of the text under the watermark distribution, wherein the sparse encrypted watermark scoring function is calculated as follows:
[0037]
[0038] In formula (2), g l (.,.) is a multi-level watermark function, T represents the length of the word sequence of the text block c, L represents the total number of watermark function measurement levels, r is the random seed, t is the word sequence number, and l is the number of watermark function measurement levels.
[0039] In some embodiments, step S740 compares the scores of the text under the original distribution and the watermark distribution, wherein if the likelihood ratio exceeds a threshold, the word-element to be detected is determined to be a watermark word.
[0040] In some embodiments, step S600 includes the following steps:
[0041] S610) encrypting the sparse vocabulary to generate a first vocabulary summary;
[0042] S620) re-encrypting the first vocabulary digest using the watermark private key to form an encrypted digital signature;
[0043] S630) transmitting the sparse vocabulary and the encrypted digital signature;
[0044] S640) decrypting the encrypted digital signature using the public key to generate a decrypted vocabulary summary;
[0045] S650) processing the sparse vocabulary using a message digest algorithm to generate a second vocabulary digest; and
[0046] S660) Compare and verify the decrypted vocabulary digest and the second vocabulary digest.
[0047] To achieve the above objectives, a third aspect of an embodiment of the present application proposes an electronic device, which includes a memory and a processor, wherein the memory stores a computer program, and when the processor executes the computer program, the method described in the first aspect is implemented.
[0048] To achieve the above-mentioned purpose, the fourth aspect of an embodiment of the present application proposes a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the method described in the first aspect is implemented. BRIEF DESCRIPTION OF THE DRAWINGS
[0049] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other accompanying drawings can be obtained based on these accompanying drawings without paying any creative work.
[0050] Figure 1 is a flow chart of a watermark generation method according to a preferred embodiment of the present invention.
[0051] Figure 2 The process of watermark implantation in the watermark generation method according to the above preferred embodiment of the present invention is explained.
[0052] Figure 3 An example of generating and embedding a watermark by the watermark generation method according to the above preferred embodiment of the present invention is explained.
[0053] Figure 4 The process of anchoring sparse marker words in the text watermark generation method according to the above preferred embodiment of the present invention is explained.
[0054] Figure 5 An example of verifiable random sampling in the text watermark generation method according to the above preferred embodiment of the present invention is explained.
[0055] Figure 6 The process of generating watermark words in the text watermark generating method according to the above preferred embodiment of the present invention is explained.
[0056] Figure 7 A watermark detection method for a watermark generated by the watermark generation method according to the preferred embodiment of the present invention is explained.
[0057] Figure 8 The process of judging the security of a sparse vocabulary in the watermark detection method according to the preferred embodiment of the present invention is explained.
[0058] Fig. 9 The sparse vocabulary signature and verification process based on the DAS algorithm in the watermark detection method according to the preferred embodiment of the present invention is explained.
[0059] Fig.10 The process of identifying watermark words in the watermark detection method according to the preferred embodiment of the present invention is explained.
[0060] Fig.11 An application example of the watermark detection method according to the preferred embodiment of the present invention is explained. DETAILED DESCRIPTION
[0061] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.
[0062] It should be noted that, although the functional modules are divided in the device schematic diagram and the logical order is shown in the flowchart, in some cases, the steps shown or described may be performed in a different order than the module division in the device or the order in the flowchart. The terms "first", "second", etc. in the specification, claims and the above drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence.
[0063] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as those commonly understood by those skilled in the art to which this application belongs. The terms used herein are only for the purpose of describing the embodiments of this application and are not intended to limit this application.
[0064] First, some nouns involved in this application are analyzed:
[0065] Large Language Model Watermark: A watermark is a pattern hidden in the text that is imperceptible to humans but can be identified as synthetic text by algorithms.
[0066] Verifiable random function: a function with verifiability and random output, which takes private key sk and random seed m as input, and outputs pseudo-random number r and proof of the pseudo-random number. Anyone can use the public key and proof corresponding to sk to verify whether the pseudo-random number r is calculated by the holder of the private key sk, and the pseudo-random number, private key and seed are uniquely determined, and no one can deduce the private key based on the random seed and pseudo-random number.
[0067] Specification of the drawings Figure 1 A sparse watermark generation method according to a preferred embodiment of the present invention is explained. The text watermark generation method embeds an unbiased sparse watermark without changing the meaning or readability of the original text to reduce the impact on the intrinsic meaning of the text.
[0068] refer to Figure 1 , the text watermark generation method comprises the following steps:
[0069] S100) generating a watermark private key and a sparse vocabulary including a plurality of sparse marker words;
[0070] S200) Generate or expand a text by random sampling using a large language model;
[0071] S300) During the random sampling process, word units in the text are detected in real time until sparse marked words in the sparse vocabulary begin to appear in the text, and then the following steps are performed:
[0072] S400) The random seed generator generates a verifiable random seed based on the watermark private key; and
[0073] S500) passing the verifiable random seed to multiple watermark functions to select words that meet the watermark requirements as watermark words through an arena scoring algorithm to be embedded in the text.
[0074] After step S500, step S200 is continued until an end character is encountered or the context window limit is exceeded.
[0075] According to the preferred embodiment of the present invention, step S100 uses a digital signature (DSA) algorithm to generate the watermark private key and the sparse vocabulary.
[0076] According to the preferred embodiment of the present invention, in the initial stage of the text generation, step S200 generates the text by random sampling of the large language model. In the process of generating the text word by word, if the previous word belongs to the sparse marked word in the sparse vocabulary, the arena scoring algorithm is sampled to implant the watermark word; if the previous word does not belong to the sparse marked word in the sparse marked vocabulary, random sampling is performed. In this way, the text is continuously expanded until the end symbol is encountered or the context window limit is exceeded, and the generation of the text is completed.
[0077] It is worth mentioning that the large language model generates text token by token. These tokens may represent a character, word or part of a phrase. Each time a watermark word is generated in the text, the text is increased by a corresponding adjusted probability score, where the pattern formed by the token selection of the large language model and the adjusted probability score during the text generation process is regarded as the watermark.
[0078] Reference to the attached drawings of the specification Figure 2 and Figure 3 In order to generate coherent text, the large language model randomly selects words and predicts the next most likely word based on the previous words and the probability scores assigned to each potential word. For example, for the phrase "I__." The large language model may choose words such as "is", "like", "in", "of", or "we" to complete the sentence and assign a probability score to each word.
[0079] According to the preferred embodiment of the present invention, the text watermark generation method uses a modified sampling method to add watermarks to a large language model, wherein the modified sampling method modifies the original sampling process and ultimately uses detection indicators to determine the source of the text, thereby ensuring that the generated text has watermark features while not significantly affecting the fluency and diversity of the text.
[0080] According to the preferred embodiment of the present invention, the text watermark generation method can be used for texts of at least three sentences, and as the length of the text increases, the robustness and accuracy of the text watermark generation method also increase.
[0081] Specification of the drawings Figure 2 The watermark implantation process in the text watermark generation method is explained. Figure 2 As shown, in the process of generating text by the large language model, it is detected in real time whether the newly collected word is a sparse marked word in the sparse marked word table. If the newly collected word (also called the previous word) is a non-marked word, random sampling will continue to be used, that is, the sampling method of the large language model will not be changed, and the text watermark will not be added. If the newly collected word (the previous word) is a sparse marked word in the sparse marked word table, a verifiable random seed generator and a multi-level watermark function are introduced. When generating the next word, the verifiable random seed generated by the verifiable random seed generator will be passed to multiple watermark functions, and the word that meets the watermark requirements will be selected as the next word through the Arena Scoring (ELO) sampling algorithm.
[0082] When there are multiple word-grams that meet the watermark requirements to choose from, the preferred embodiment of the present invention uses a verifiable random sampling method to adjust the probability score of each predicted word-gram without compromising output quality, accuracy and creativity.
[0083] As shown in the attached figure of the specification Figure 3 As shown, the word "I" belongs to the unmarked word, and the large language model randomly samples "like" from the distribution of the next word. According to the sparse vocabulary, it is judged that the word "like" belongs to the sparse marked word, and it is marked with a sparse marked word, such as red. The large language model uses verifiable random sampling from the distribution of the next word to mark "sunset" with a watermark word, such as green, that is, "sunset" is a watermark word. The above process is repeated when generating text. For each watermark word generated in the text, the text increases a corresponding adjusted probability score. A sentence may contain multiple corresponding adjusted probability scores, and a page of content may contain hundreds. Finally, the pattern formed by the word unit selection and the adjusted probability score of the large language model is regarded as a watermark. Iterate the above process until the end symbol (such as EOS) is encountered or the context window limit is exceeded.
[0084] Unlike other watermarking methods that mark all or most of the words, according to the preferred embodiment of the present invention, the text watermark generation method only performs watermarking on a small number of selected words in the generated text, which can enhance the detection ability of the watermark without reducing the quality of the text. The key to sparse watermarking is to anchor the watermark word behind the word with a specific part-of-speech tag, that is, the next word of the sparse marked word, while the rest of the words remain unchanged. During the generation process, if the last word is a non-marked word, the watermark embedding is skipped and the original language model sampling method is used directly.
[0085] Specification of the drawings Figure 4 The method of generating text and embedding watermarks using a large language model in the text watermark generation method is explained. Specifically, step S300 includes the following steps:
[0086] S310) reading the newly generated word unit of the text as the previous word unit; and
[0087] S320) identifying whether the previous word belongs to a sparse marked word according to the sparse vocabulary;
[0088] If step S320 identifies that the previous word belongs to a sparsely marked word, the following steps are performed:
[0089] S330) sparsely mark the previous word to anchor the previous word as a sparsely marked word.
[0090] According to the preferred embodiment of the present invention, step S300 marks the previous word-gram identified as the sparsely marked word by color, for example, marking the previous word-gram identified as the sparsely marked word in red.
[0091] After step S330, step S400 is performed, that is, after the context is input, the random seed generator generates a verifiable random seed, and the random seed will be used as an input of the subsequent watermark embedding process in the subsequent step S500.
[0092] Specifically, refer to Figure 6 , step S500 includes the following steps:
[0093] S510) The random seed is passed as input to the multi-level watermark function, and each watermark function generates a candidate word through the random seed, and the calculation formula is as follows:
[0094]
[0095] Where r is the random seed, and its value space is R{0,1} n , that is 2 n The integer value of ;
[0096] In formula (1), given a g value distribution, its cumulative density function is F g ,and Represents F g The inverse function, h(.,.,.) represents the hash function, n represents the security parameter, and l represents the number of watermark function measurement layers;
[0097] S520) comparing the scores obtained by different watermark functions through multiple rounds of tournaments, and selecting the candidate word generated by the watermark function with the highest score as the watermark word;
[0098] S530) embedding the watermark word into the text by placing the watermark word after the previous word to extend the text; and
[0099] S540) Add a watermark word tag to the watermark word to mark the watermark word embedded in the text.
[0100] According to the preferred embodiment of the present invention, the watermark word is marked by color, for example, the watermark word is marked by green.
[0101] It is worth mentioning that the higher the entropy value (the diversity of languages in the text generation process, that is, the number of options when the model generates new words), the better the watermark embedding and detection effect. In an environment with a lower entropy value, the difficulty of watermark embedding and detection increases. This preferred embodiment of the present invention uses a multi-level watermark, that is, a method of increasing the number of Arena ELO layers, to enhance the reliability of watermark detection. On the other hand, the Arena ELO sampling process will select words that meet the watermark conditions to embed into the text (marked in green), without significantly deviating from the original large language model distribution, that is, unbiased sampling.
[0102] refer to Figure 5 As an example, step S320 compares the sparse vocabulary and identifies that the word "like" belongs to the sparse marked word, and marks it with the sparse marked word, such as red. When generating new word-units, the Arena ELO sampling process selects words that meet the watermark condition to embed into the text, and marks them with watermarks, such as color, such as green, without significantly deviating from the original large language model distribution, that is, unbiased sampling.
[0103] The watermark generated by the text watermark generation method according to the preferred embodiment of the present invention detects watermark words in the text based on the watermark public key, digital signature and sparse marker vocabulary, thereby ensuring the security and public detectability of the watermark generation, wherein the watermark public key is generated together with the watermark private key through the DAS algorithm.
[0104] Specification of the drawings Figure 7A watermark detection method for a watermark generated by the sparse watermark generation method according to the preferred embodiment of the present invention is explained, comprising the following steps:
[0105] S600) Determining the security of the sparse vocabulary;
[0106] S700) identifying watermark words in the text; and
[0107] S800) detecting the watermark by detecting the frequency of the watermark word following the sparse marked word in the text;
[0108] Step S700 is performed after step S600 determines that the sparse vocabulary is safe.
[0109] refer to Figure 8 , step S600 includes the following steps:
[0110] S610) encrypting the sparse vocabulary to generate a first vocabulary summary;
[0111] S620) re-encrypting the first vocabulary digest using the watermark private key to form an encrypted digital signature;
[0112] S630) transmitting the sparse vocabulary and the encrypted digital signature;
[0113] S640) decrypting the encrypted digital signature using the public key to generate a decrypted vocabulary summary;
[0114] S650) processing the sparse vocabulary using a message digest algorithm to generate a second vocabulary digest; and
[0115] S660) Compare and verify the decrypted vocabulary digest and the second vocabulary digest.
[0116] If the comparison and verification result of step S660 is that the decrypted vocabulary table summary and the second vocabulary table summary are consistent, it is judged that the message has not been destroyed or tampered with during the transmission process, and subsequent watermark detection can be performed; if the comparison and verification result of step S660 is that the two are inconsistent, it is judged that the information has lost security and confidentiality.
[0117] refer to Fig. 9 In step S610 and step S650, the sparse tag vocabulary is encrypted using a hash algorithm to generate the first vocabulary digest and the second vocabulary digest. Steps S610 and S620 are both performed by the watermark supplier. In step S630, the watermark supplier transmits the sparse vocabulary and the encrypted digital signature to the watermark verifier. The watermark verifier can determine the security of the sparse vocabulary through steps S640, S650, and S660.
[0118] The preferred embodiment of the present invention uses an information theory framework to analyze the sensitivity of the watermark. Specifically, the sensitivity of the watermark is analyzed by determining whether a word marked with a sparse mark word is followed by a watermark word marked with a watermark. Fig.10 , step S700 includes the following steps:
[0119] S710) segmenting the text into word-unit sequences;
[0120] S720) Finding a sparse marked word from the word-unit sequence as a watermark detection anchor point, and marking the next word-unit after the watermark detection anchor point as a word-unit to be detected;
[0121] S730) passing the watermark public key and the word to be detected to an encrypted watermark scoring function to obtain a score of the text under the watermark distribution; and
[0122] S740) Compare the score of the text under the watermark distribution with the score of the text under the original distribution to determine whether the word to be detected is a watermark word.
[0123] refer to Fig.11 , after step S710 cuts the text into text blocks by sentence, it uses the same word segmentation method as the large language model to cut the text into word unit sequences, such as "I", "like", "sunset", "," and "especially".
[0124] Step S720 finds a tag word (red mark) of a specific part of speech according to the sparse tag vocabulary and uses it as a watermark detection anchor point, wherein the next unit after the tag word is the word to be detected and is marked with the word to be detected, for example, gray is used as the word to be detected.
[0125] Step S730 performs watermark scoring, wherein the watermark public key and the word to be detected are passed to the sparse encrypted watermark scoring function to obtain the score of the text under the watermark distribution, wherein the calculation formula of the sparse encrypted watermark scoring function is as follows:
[0126]
[0127] In formula (2), g l (.,.) is a multi-level watermark function. T represents the length of the word sequence of the text block c, and L represents the total number of watermark function test levels. r is the random seed, t is the word sequence number, and l is the number of watermark function test levels.
[0128] Step S740 compares the scores of the given text under the original distribution and the watermark distribution. If the likelihood ratio exceeds a threshold, the word to be detected is determined to be a watermark word.
[0129] When the watermark needs to be detected, it is only necessary to check the frequency of the watermark word token after the sparse word token. The calculation formula of the frequency z is as follows:
[0130]
[0131] In formula (3), w G is the number of watermark words with green marks in the text, T is the length of the word sequence of the text block, and λ is the weight parameter. If z>3, the null hypothesis of artificial generation is rejected, that is, the text is generated by a large language model.
[0132] The embodiment of the present invention proposes a sparsely encrypted unbiased watermarking method through a verifiable random sampling strategy. This method achieves reliable watermark embedding and detection while ensuring the quality of the generated text. This provides an effective solution to the problem of abuse of content generated by large language models. The embodiment of the present invention optimizes the trade-off between watermark strength and text quality through non-distorted watermark technology. Using word-level watermark embedding will not change the original text generation distribution of the large language model, thereby maintaining the fluency and diversity of the text. The watermark embedding method adopted in the embodiment of the present invention takes into account the quality and transparency of the generated text, ensuring that watermark marking is achieved without changing the naturalness of the generated text.
[0133] It is worth mentioning that the technical solution of the present application, in essence, or the part that contributes to the prior art, or all or part of the technical solution can be embodied in the form of a software product. The computer software product is stored in a storage medium, including multiple instructions for enabling a computer device (which can be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the methods of various embodiments of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM), random access memory (RAM), disk or optical disk, and other media that can store programs.
[0134] The preferred embodiments of the present invention are described above with reference to the accompanying drawings, but the scope of the rights of the present invention is not limited thereto. Any modification, equivalent substitution and improvement made by a person skilled in the art without departing from the scope and essence of the present invention should be within the scope of the rights of the present invention.
Claims
1. A method for generating a text watermark, characterized in that: The following steps are involved: S100) generating a watermark private key and a sparse vocabulary including a plurality of sparse marker words; S200) Generate or expand a text using a large language model random sampling technique; S300) During the random sampling process, word units in the text are detected in real time until sparse marked words in the sparse vocabulary begin to appear in the text, and then the following steps are performed: S400) a random seed generator generates a verifiable random seed based on the watermark private key; and S500) passing the verifiable random seed to a plurality of watermark functions, so as to select a word element that meets the watermark requirement as a watermark word element and embed it into the text through an arena scoring algorithm; After step S500, step S200 is continued until an end character is encountered or the context window limit is exceeded; Each time a watermark word is generated in the text, a corresponding adjusted probability score is added to the text, wherein the pattern formed by the word unit selection of the large language model and the adjusted probability score during the text generation process is regarded as the watermark.
2. The text watermark generation method according to claim 1, characterized in that: Step S300 includes the following steps: S310) reading the newly generated word unit of the text as the previous word unit; and S320) identifying whether the previous word belongs to a sparse marked word according to the sparse vocabulary; If step S320 identifies that the previous word belongs to a sparsely marked word, the following steps are performed: S330) marking the previous word as a sparse marked word to anchor the previous word as a sparse marked word.
3. The text watermark generation method according to claim 2, characterized in that: Step S500 includes the following steps: S510) The random seed is passed as input to a multi-level watermark function, and each watermark function generates a candidate word by using the random seed. The calculation formula is as follows: Where r is the random seed, and its value space is R{0,1} n , that is 2 n The integer value of ; In formula (1), given a g value distribution, its cumulative density function is F g ,and Represents F g The inverse function, h(.,.,.) represents the hash function, n represents the security parameter, and l represents the number of watermark function measurement layers; S520) comparing the scores obtained by different watermark functions through multiple rounds of tournaments, and selecting the candidate word generated by the watermark function with the highest score as the watermark word; S530) embedding the watermark word into the text by placing the watermark word after the previous word to extend the text; and S540) Add a watermark word tag to the watermark word to mark the watermark word embedded in the text.
4. A method for detecting a text watermark generated by the text watermark generation method according to any one of claims 1 to 3, characterized in that: The following steps are involved: S600) Determining the security of the sparse vocabulary; S700) identifying watermark words in the text; and S800) detecting a watermark by detecting the frequency of occurrence of a watermark word following a sparsely marked word in the text; Step S700 is performed after step S600 determines that the sparse vocabulary is safe.
5. The watermark detection method according to claim 4, characterized in that: Step S700 includes the following steps: S710) segmenting the text into word sequences; S720) Finding a sparse marked word from the word-unit sequence as a watermark detection anchor point, and marking the next word-unit after the watermark detection anchor point as a word-unit to be detected; S730) passing the watermark public key and the word to be detected to an encrypted watermark scoring function to obtain a score of the text under the watermark distribution; and S740) Compare the score of the text under the watermark distribution with the score of the text under the original distribution to determine whether the word to be detected is a watermark word.
6. The watermark detection method according to claim 5, characterized in that: Step S730 performs watermark scoring, wherein the watermark public key and the word to be detected are passed to the sparse encrypted watermark scoring function to obtain the score of the text under the watermark distribution, wherein the calculation formula of the sparse encrypted watermark scoring function is as follows: In formula (2), g l (.,.) is a multi-level watermark function, T represents the length of the word sequence of the text block c, L represents the total number of watermark function measurement levels, r is the random seed, t is the word sequence number, and l is the number of watermark function measurement levels.
7. The watermark detection method according to claim 6, characterized in that: Step S740 compares the scores of the text under the original distribution and the watermark distribution, wherein if the likelihood ratio exceeds a threshold, the word unit to be detected is determined to be a watermark word.
8. The watermark detection method according to claim 7, characterized in that: Step S600 includes the following steps: S610) encrypting the sparse vocabulary to generate a first vocabulary summary; S620) re-encrypting the first vocabulary digest using the watermark private key to form an encrypted digital signature; S630) transmitting the sparse vocabulary and the encrypted digital signature; S640) decrypting the encrypted digital signature using a public key to generate a decrypted vocabulary summary; S650) processing the sparse vocabulary using a message digest algorithm to generate a second vocabulary digest; and S660) Compare and verify the decrypted vocabulary digest and the second vocabulary digest.
9. A computer device, characterized in that: The device includes a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory communicate with each other via the communication bus; Memory, used to store computer programs; The processor is used to implement the steps of the text watermark generation method described in any one of claims 1 to 3 when executing the program stored in the memory.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the text watermark generation method according to any one of claims 1 to 3 are implemented.
Citation Information
Patent Citations
Reversible natural language watermarking method
CN117113294A
Watermark fonts
US20040001606A1
Cited By
Text processing method, computer equipment and medium
CN120804324A
Watermark generation detection method based on stochastic smoothing testible robust large language model
CN121351045A
A large model watermarking method based on dynamic entropy
CN121834773B