Text watermark adding and detecting method, device and equipment and storage medium
By adding watermarks to text generated by a language model based on adjusting the probability distribution using semantic feature information, the problem of watermarks being easily removed in existing technologies is solved, achieving robustness and accurate recognition of text watermarks.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- TENCENT TECHNOLOGY (SHENZHEN) CO LTD
- Filing Date
- 2024-11-15
- Publication Date
- 2026-05-19
AI Technical Summary
Existing text watermarking methods are not robust; watermarks can be removed from generated content simply by replacing words, making it impossible to accurately identify content generated by language models.
By acquiring the prompt words of the text to be generated and the vocabulary of the language model, the probability distribution of the token to be generated is determined, and a random seed is determined based on the semantic feature information of the generated token. The probability distribution is adjusted to add a watermark, and the robustness of the watermark is improved without changing the semantics of the text.
In subsequent watermark detection, it can accurately identify text with added watermarks, improving the recognition accuracy of text generated by the language model and ensuring that the watermark is not easily replaced or removed by simple words.
Smart Images

Figure CN119598427B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technology, and in particular to a method, apparatus, device and storage medium for adding and detecting text watermarks. Background Technology
[0002] Large Language Models (LLMs) have garnered widespread attention due to their powerful expressive capabilities in natural language processing and have been applied in various practical scenarios, including writing, reading assistance, and knowledge retrieval. However, the surge in LLM usage has also raised concerns about their potential misuse for malicious purposes. To address this issue, watermarking can be embedded in the content generated by the language model to ensure its recognizability, thereby enabling content management.
[0003] However, current text watermarking methods are not robust enough. Watermarks can be removed from generated content with simple word replacement, making it impossible to detect watermark information and thus failing to accurately identify content generated by language models. Summary of the Invention
[0004] This application provides a method, apparatus, device, and storage medium for adding and detecting text watermarks, which adds watermark information that is not prone to anomalies to the content generated by the language model, thereby improving the robustness of text watermark addition.
[0005] Firstly, this application provides a method for adding a text watermark, including:
[0006] Obtain the prompt words for the text to be generated and the vocabulary of the language model. The prompt words include M tokens, where M is a positive integer.
[0007] For the i-th token to be generated in the text to be generated, T generated tokens are selected from the currently generated token sequence, and the T generated tokens are processed by the language model to obtain the probability distribution corresponding to the i-th token to be generated. The currently generated tokens include the M tokens and the generated tokens of the text to be generated. The probability distribution includes the probability that each token in the vocabulary is selected as the i-th token to be generated. T and i are both positive integers.
[0008] Select K generated tokens from the currently generated token sequence, determine the semantic feature information of the K generated tokens, and determine the random seed corresponding to the i-th token to be generated based on the semantic feature information of the K generated tokens, where K is a positive integer greater than 1;
[0009] The probabilities in the probability distribution are adjusted based on the random seed, and the target token corresponding to the i-th token to be generated in the vocabulary is determined based on the adjusted probability distribution. Then, based on the target token, the watermarked text is obtained.
[0010] Secondly, this application provides a text watermark detection method, including:
[0011] Obtain the text to be detected and the vocabulary of the language model, wherein the text to be detected includes N tokens, where N is a positive integer greater than 1;
[0012] For the j-th token in the text to be detected, select K tokens corresponding to the j-th token from the N tokens, determine the semantic feature information of the K tokens, and determine the random seed corresponding to the j-th token based on the semantic feature information of the K tokens, where K is a positive integer greater than 1 and j is a positive integer from 1 to N;
[0013] Based on the random seed, the vocabulary is divided into a preferred selection set and a non-preferred selection set to determine whether the j-th token belongs to the preferred selection set.
[0014] The watermark detection result of the text to be detected is determined based on the number of tokens belonging to the priority selection set in the text to be detected.
[0015] Thirdly, this application provides a text watermark adding device, comprising:
[0016] The acquisition unit is used to acquire the prompt words of the text to be generated and the vocabulary of the language model. The prompt words include M tokens, where M is a positive integer.
[0017] The probability determination unit is used to select T generated tokens from the currently generated token sequence for the i-th token to be generated in the text to be generated, and process the T generated tokens through the language model to obtain the probability distribution corresponding to the i-th token to be generated. The currently generated tokens include the M tokens and the generated tokens of the text to be generated. The probability distribution includes the probability that each token in the vocabulary is selected as the i-th token to be generated. T and i are both positive integers.
[0018] The random seed determination unit is used to select K generated tokens from the currently generated token sequence, determine the semantic feature information of the K generated tokens, and determine the random seed corresponding to the i-th token to be generated based on the semantic feature information of the K generated tokens, where K is a positive integer greater than 1;
[0019] The watermarking unit is used to adjust the probability in the probability distribution based on the random seed, so as to determine the target token corresponding to the i-th token to be generated in the vocabulary based on the adjusted probability distribution, and then obtain the watermarked text based on the target token.
[0020] In some embodiments, the random seed determination unit is specifically used to determine a target semantic feature cluster center from among a preset R semantic feature cluster centers based on the semantic feature information of the K generated tokens. The R semantic feature cluster centers are obtained by clustering the semantic feature information of a preset P statements, where R is a positive integer greater than 1 and P is a positive integer greater than R. Based on the identification information of the target semantic feature cluster center, the random seed corresponding to the i-th token to be generated is determined.
[0021] In some embodiments, the random seed determination unit is specifically used to determine the distance between the semantic feature information of the K generated tokens and the semantic feature cluster center for each of the R semantic feature cluster centers; and to determine the target semantic feature cluster center from the R semantic feature cluster centers based on the distance.
[0022] In some embodiments, the random seed determination unit is specifically used to obtain the random seed corresponding to the i-th token to be generated based on the preset key and the identification information of the target semantic feature cluster center.
[0023] In some embodiments, the random seed determination unit is specifically used to determine the product of the preset key and the identification information of the target semantic feature cluster center as the random seed corresponding to the i-th token to be generated.
[0024] In some embodiments, the random seed determination unit is specifically used to select the top K generated tokens that are closest to the i-th token to be generated from the currently generated token sequence, as the K generated tokens.
[0025] In some embodiments, the watermark adding unit is specifically used to divide the vocabulary into a preferred selection set and a non-preferred selection set based on the random seed; and to increase the probability of tokens belonging to the preferred selection set in the probability distribution based on a preset bias value, thereby obtaining the adjusted probability distribution.
[0026] In some embodiments, the watermarking unit is specifically used to obtain the ratio of the number of tokens included in the preferred selection set to the total number of tokens in the vocabulary; based on the ratio and the random seed, the vocabulary is divided into the preferred selection set and the non-preferred selection set.
[0027] In some embodiments, the probability determination unit is specifically used to select the first M+i-1 generated tokens from the currently generated token sequence as the T generated tokens.
[0028] Fourthly, this application provides a text watermark detection device, comprising:
[0029] The acquisition unit is used to acquire the text to be detected and the vocabulary of the language model. The text to be detected includes N tokens, where N is a positive integer greater than 1.
[0030] The random seed determination unit is used to select K tokens corresponding to the j-th token from the N tokens for the j-th token in the text to be detected, determine the semantic feature information of the K tokens, and determine the random seed corresponding to the j-th token based on the semantic feature information of the K tokens, where K is a positive integer greater than 1 and j is a positive integer from 1 to N;
[0031] A set partitioning unit is used to divide the vocabulary into a preferred selection set and a non-preferred selection set based on the random seed, so as to determine whether the j-th token belongs to the token in the preferred selection set;
[0032] The watermark detection unit is used to determine the watermark detection result of the text to be detected based on the number of tokens in the text to be detected that belong to the preferred selection set.
[0033] In some embodiments, the random seed determination unit is specifically used to determine a target semantic feature cluster center from among a preset R semantic feature cluster centers based on the semantic feature information of the K tokens. The R semantic feature cluster centers are obtained by clustering the semantic feature information of a preset P statements, where R is a positive integer greater than 1 and P is a positive integer greater than R. Based on the identification information of the target semantic feature cluster center, the random seed corresponding to the j-th token is determined.
[0034] In some embodiments, the random seed determination unit is specifically used to determine the distance between the semantic feature information of the K tokens and the semantic feature cluster center for each of the R semantic feature cluster centers; and to determine the target semantic feature cluster center from the R semantic feature cluster centers based on the distance.
[0035] In some embodiments, the random seed determination unit is specifically used to obtain a preset key; and based on the preset key and the identification information of the target semantic feature clustering center, to obtain the random seed corresponding to the j-th token.
[0036] In some embodiments, the random seed determination unit is specifically used to determine the random seed corresponding to the j-th token by multiplying the preset key and the identification information of the target semantic feature cluster center.
[0037] In some embodiments, the watermark detection unit is specifically configured to obtain the ratio of the number of tokens included in the preferred selection set to the total number of tokens in the vocabulary; determine the watermark strength of the text to be detected based on the ratio and the number of tokens belonging to the preferred selection set in the text to be detected; and determine the watermark detection result of the text to be detected based on the watermark strength of the text to be detected.
[0038] In some embodiments, the watermark detection unit is specifically configured to multiply the number of tokens included in the text to be detected by the ratio to obtain a first product; subtract the number of tokens belonging to the preferred selection set in the text to be detected from the first product to obtain a first difference; and determine the watermark strength of the text to be detected based on the first difference.
[0039] In some embodiments, the watermark detection unit is specifically used to subtract a preset value from the ratio to obtain a second difference; multiply the first product by the first value to obtain a second product; and determine the ratio of the nth root of the second product to the first difference as the watermark intensity of the text to be detected, where n is a positive number.
[0040] In some embodiments, the watermark detection unit is specifically configured to determine that the text to be detected is text generated by the language model if the watermark intensity of the text to be detected is greater than or equal to a preset threshold; and to determine that the text to be detected is not text generated by the language model if the watermark intensity of the text to be detected is less than the preset threshold.
[0041] Fifthly, this application provides an electronic device including a processor and a memory. The memory is used to store a computer program, and the processor is used to invoke and run the computer program stored in the memory to perform the methods described in the first or second aspect above.
[0042] In a sixth aspect, a chip is provided for implementing the methods of various implementations of the first aspect described above. Specifically, the chip includes a processor for retrieving and running a computer program from a memory, causing a device equipped with the chip to perform the methods of the first or second aspect described above.
[0043] In a seventh aspect, a computer-readable storage medium is provided for storing a computer program that causes a computer to perform the methods described in the first or second aspect.
[0044] Eighthly, a computer program product is provided, including computer program instructions that cause a computer to perform the methods described in the first or second aspect.
[0045] Ninthly, a computer program is provided that, when run on a computer, causes the computer to perform the methods of the first or second aspect described above.
[0046] In summary, this application obtains the prompt words of the text to be generated and the vocabulary of a language model. The prompt words include M tokens. For the i-th token to be generated in the text, T generated tokens are obtained from the currently generated token sequence. The language model processes these T generated tokens to obtain the probability distribution corresponding to the i-th token to be generated. The currently generated tokens include the M tokens and the generated tokens of the text to be generated. The probability distribution includes the probability that each token in the vocabulary is selected as the i-th token to be generated. Next, K generated tokens are selected from the currently generated token sequence, and the semantic feature information of the K generated tokens is determined, where K is a positive integer greater than 1. Based on the semantic feature information of the K generated tokens, a random seed corresponding to the i-th token to be generated can be determined. Then, the probabilities in the probability distribution are adjusted based on the random seed to obtain an adjusted probability distribution. Finally, based on the adjusted probability distribution, the target token corresponding to the i-th token to be generated in the vocabulary is determined. Based on the target token, the watermarked text is obtained. Therefore, in this embodiment, the random seed is determined using the semantic features of K generated tokens. Based on this random seed, the probability distribution is adjusted, and the words corresponding to the tokens in the text to be generated are obtained from the adjusted probability distribution, ultimately resulting in watermarked text. Since the watermarked text does not change its semantics, simple word replacement cannot remove the watermark information, thus improving the robustness of the watermark added to the text generated by the language model. This allows for accurate identification of the watermark in subsequent watermark detection, confirming that the text is generated by the language model and improving the accuracy of recognizing language model-generated text. Attached Figure Description
[0047] To more clearly illustrate the technical solutions in the embodiments of the present invention, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0048] Figure 1 A schematic diagram of an implementation environment provided for an embodiment of this application;
[0049] Figure 2 A flowchart illustrating a text watermarking method provided in an embodiment of this application;
[0050] Figure 3A This is an example diagram of the sequence of currently generated tokens corresponding to the i-th token to be generated;
[0051] Figure 3B This is an example diagram of the T generated tokens corresponding to the i-th token to be generated;
[0052] Figure 4 This is a schematic diagram of the probability distribution corresponding to the i-th token to be generated.
[0053] Figure 5 This is a schematic diagram for selecting K generated tokens;
[0054] Figure 6 A schematic diagram for determining a random seed;
[0055] Figure 7 This is a schematic diagram illustrating the adjustment of the probability distribution.
[0056] Figure 8 This is a diagram illustrating the updating of a currently generated token.
[0057] Figure 9 A schematic flowchart of a text watermark detection method provided in an embodiment of this application;
[0058] Figure 10 This is a schematic diagram for selecting K tokens from N tokens included in the text to be detected;
[0059] Figure 11 A flowchart illustrating a text watermarking and text watermark detection method provided in an embodiment of this application;
[0060] Figure 12 This is a schematic diagram illustrating the framework of the text watermarking and text watermark detection methods in the embodiments of this application;
[0061] Figure 13 This is a schematic block diagram of a text watermarking device provided in an embodiment of this application;
[0062] Figure 14 This is a schematic block diagram of a text watermark detection device provided in an embodiment of this application;
[0063] Figure 15 This is a schematic block diagram of the electronic device provided in the embodiments of this application. Detailed Implementation
[0064] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those of ordinary skill in the art without creative effort are within the scope of protection of this application.
[0065] It should be noted that the terms "first," "second," etc., in the specification, claims, and accompanying drawings of this application are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of this application described herein can be implemented in orders other than those illustrated or described herein. In embodiments of the invention, "B corresponding to A" means that B is associated with A. In one implementation, B can be determined based on A. However, it should also be understood that determining B based on A does not mean determining B solely based on A; B can also be determined based on A and / or other information. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion. For example, a process, method, system, product, or server that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to these processes, methods, products, or devices. In the description of this application, unless otherwise stated, "a plurality of" means two or more.
[0066] The text watermarking and detection method provided in this application can be applied to various fields such as text creation and text detection. It can add watermark information that is not easily anomalous to the content generated by the language model, thereby improving the robustness of text watermarking.
[0067] Large Language Models (LLMs): A type of language model consisting of an artificial neural network with many parameters (typically billions or more weights), trained on a large amount of unlabeled text using self-supervised or semi-supervised learning.
[0068] Large Language Model Watermark (LLMs): This refers to embedding watermark information that is imperceptible to users but detectable by algorithms into content generated by large language models, so that the content generated by the large language model can be identified through the watermark information later.
[0069] With the rapid development of artificial intelligence technology, various language models have emerged. Language models have attracted widespread attention due to their powerful expressive capabilities in processing natural language. However, the surge in language model usage has also raised concerns among users that these models might be misused for malicious purposes, such as disseminating false information. To address this issue, existing solutions embed watermarks into the content generated by language models to ensure its recognizability, thereby enabling content management. However, current technologies inevitably suffer from robustness issues; watermarks can be removed from the generated content through simple word replacement. Consequently, accurate recognition of text generated by language models is not possible.
[0070] To address the aforementioned technical problems, this application proposes a text watermarking method. The method involves acquiring prompt words for the text to be generated and a vocabulary of a language model. The prompt words include M tokens. For the i-th token to be generated in the text, T generated tokens are obtained from the currently generated token sequence. These T tokens are then processed using the language model to obtain the probability distribution corresponding to the i-th token. The currently generated tokens include the M tokens and the generated tokens of the text to be generated. The probability distribution includes the probability that each token in the vocabulary is selected as the i-th token. Next, K generated tokens are selected from the currently generated token sequence, and the semantic features of these K tokens are determined, where K is a positive integer greater than 1. Based on the semantic features of these K tokens, a random seed corresponding to the i-th token can be determined. The probabilities in the probability distribution are then adjusted based on the random seed to obtain an adjusted probability distribution. Finally, based on the adjusted probability distribution, the target token corresponding to the i-th token in the vocabulary is determined. Finally, based on the target token, the watermarked text is obtained. Therefore, in this embodiment, the random seed is determined using the semantic features of K generated tokens. Based on this random seed, the probability distribution is adjusted, and the words corresponding to the tokens in the text to be generated are obtained from the adjusted probability distribution, ultimately resulting in watermarked text. Since the watermarked text does not change its semantics, simple word replacement cannot remove the watermark information, thus improving the robustness of the watermark added to the text generated by the language model. This allows for accurate identification of the watermark in subsequent watermark detection, confirming that the text is generated by the language model and improving the accuracy of recognizing language model-generated text.
[0071] The implementation environment of the text watermarking and detection method provided in the embodiments of this application is described below.
[0072] Figure 1 This is a schematic diagram of an implementation environment provided for an embodiment of this application, such as... Figure 1As shown, the implementation environment includes: terminal device 101 and server 102.
[0073] The terminal device 101 is connected to the server 102 via wired or wireless means.
[0074] In some embodiments, the terminal device 101 is equipped with a client for a text generation platform, and the server 102 can be understood as the server-side or backend of the text generation platform. Objects (e.g., users) can interact with the client through the terminal device 101, for example, by inputting prompts for the text to be generated on the client. The server 102 can invoke a language model to generate the text.
[0075] In some embodiments, during the text watermarking process, the object can send prompt words for the text to be generated to the server 102 via the terminal device 101. For example, the object launches a client of the text generation platform on the terminal device 101, which displays an input box for prompt words. The object enters prompt words in the input box, which are used to generate the text to be generated. For example, the prompt word can be a question, and the text to be generated can be the answer to the question, or the prompt word can be an intent, and the text to be generated can be the text that satisfies the intent. The terminal device 101 sends the prompt words entered by the object to the server 102. In response to the upload operation of the prompt words, the server 102 obtains the vocabulary of the language model and calls the language model to generate the vocabulary corresponding to each token to be generated in the text to be generated based on the prompt words. Specifically, for the i-th token to be generated in the text to be generated, server 102 obtains T generated tokens from the currently generated token sequence and processes these T generated tokens using a language model to obtain the probability distribution corresponding to the i-th token to be generated. The currently generated tokens include M tokens and the generated tokens of the text to be generated. The probability distribution includes the probability that each token in the vocabulary is selected as the i-th token to be generated. Next, server 102 selects K generated tokens from the currently generated token sequence and determines the semantic feature information of these K generated tokens, where K is a positive integer greater than 1. Based on the semantic feature information of these K generated tokens, server 102 can determine the random seed corresponding to the i-th token to be generated, and then adjust the probabilities in the probability distribution based on the random seed to obtain an adjusted probability distribution. Finally, based on the adjusted probability distribution, server 102 determines the target token corresponding to the i-th token to be generated in the vocabulary. Next, server 102 adds the target token corresponding to the i-th token to the end of the currently generated token sequence, obtaining a new currently generated token sequence. From the new currently generated token sequence, it retrieves the (i+1)-th token to be generated and repeats the above steps with T generated tokens to generate the target token corresponding to the (i+1)-th token to be generated in the text to be generated. This process is repeated until the watermarked text is obtained. In one example, server 102 sends the watermarked text to terminal device 101 for display.
[0076] In some embodiments, during the text watermark detection process, the terminal device 101 sends the text to be detected to the server 102. The server 102 obtains the vocabulary of the language model and performs watermark detection on each token in the text to be detected. Specifically, for the j-th token in the text to be detected, the server 102 determines the K tokens corresponding to the j-th token from the N tokens included in the text to be detected, and determines the semantic feature information of the K tokens, where K is a positive integer greater than 1 and j is a positive integer from 1 to N. Next, based on the semantic feature information of the K tokens, the server 102 determines the random seed corresponding to the j-th token, and based on the random seed, divides the vocabulary into a preferred selection set and a non-preferred selection set to determine whether the j-th token belongs to the token in the preferred selection set. By repeating this process, the server 102 can obtain the token data in the text to be detected that belong to the preferred selection set, and then determine the watermark detection result of the text to be detected based on the number of tokens in the text to be detected that belong to the preferred selection set. In one example, the server 102 sends the watermark detection result of the text to be detected to the terminal device 101 for display.
[0077] As described above, in this embodiment, the random seed is determined using the semantic features of K generated tokens. Based on this random seed, the probability distribution is adjusted, and the words corresponding to the tokens in the text to be generated are obtained from the adjusted probability distribution, ultimately resulting in watermarked text. Since the watermarked text does not change its semantics, simple word replacement cannot remove the watermark information, thus improving the robustness of the watermark added to the text generated by the language model. Therefore, during subsequent watermark detection, the watermark in the text can be accurately identified, confirming that the text is generated by the language model, thereby improving the accuracy of recognizing language model-generated text.
[0078] In some embodiments, the text watermark addition method and text watermark detection method of this application embodiment can be performed by the terminal device 101.
[0079] In some embodiments, the terminal device 101 includes, but is not limited to, desktop computers, laptops, smartphones, tablets, IoT devices, and portable wearable devices. IoT devices may include smart speakers, smart TVs, smart air conditioners, and smart in-vehicle systems. Portable wearable devices may include smartwatches, smart bracelets, and head-mounted devices. Terminal devices are often equipped with a display device, which may be a monitor, display screen, touchscreen, etc., and the touchscreen may be a touchscreen, touch panel, etc.
[0080] In some embodiments, the server 102 described above can be one or more servers. When there are multiple servers, at least two servers are used to provide different services, and / or at least two servers are used to provide the same service, such as providing the same service in a load-balanced manner. This application embodiment does not limit this. The server described above can be an independent physical server, a server cluster or distributed system composed of multiple physical servers, or a cloud server providing basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, CDN (Content Delivery Network), and big data and artificial intelligence platforms. The server can also be a node in a blockchain.
[0081] It should be noted that the implementation environment of this application embodiment includes, but is not limited to, Figure 1 As shown.
[0082] The technical solutions of the embodiments of this application will be described in detail below through some examples. The following embodiments can be combined with each other, and the same or similar concepts or processes may not be described again in some embodiments.
[0083] Figure 2 This is a flowchart illustrating a text watermarking method provided in an embodiment of this application. The execution entity of this embodiment can be a device with watermarking functionality, such as a watermarking device. This watermarking device can be the one described above. Figure 1 The server 102 or terminal device 101 shown can also be Figure 1 The system shown comprises server 102 and terminal device 101. For ease of description, the following embodiments use an electronic device as an example to illustrate the method of this application.
[0084] like Figure 2 As shown, the text watermarking method in this application embodiment includes:
[0085] S101. Obtain the prompt words for the text to be generated and the vocabulary of the language model.
[0086] The prompt consists of M tokens, where M is a positive integer.
[0087] It should be noted that the method of acquiring data during the text watermarking process in this application embodiment, as well as the acquired data, comply with the relevant laws and regulations.
[0088] In this embodiment, watermarked text is generated using a language model to mark the text generated by the language model. First, the electronic device acquires a prompt word for the text to be generated. The prompt word triggers the language model to generate the text. In other words, the prompt word is the input text that triggers the language model to generate the text.
[0089] In one example, the prompt word can be content requirement information for the text to be generated, so that the language model generates text that meets the requirements of the prompt word.
[0090] In one example, the prompt word could also be a question, allowing the language model to generate an answer to that question.
[0091] The prompts in this embodiment include M tokens. A token is the smallest semantic unit in the text, the smallest character unit processed by the language model. For example, a sentence can be divided into several words, and each word is a token. For example, the sentence "i love you" can be divided into three tokens: "i", "love", and "you".
[0092] In this embodiment, after the electronic device obtains the prompt words of the text to be generated, it performs word segmentation on the prompt words, for example, using a word segmentation tool (such as a tokenizer in an NLP library) to segment the prompt words into M tokens. These M tokens can be used as the initial input sequence of the language model.
[0093] The semantic model in this application embodiment is a model used to generate text to be generated. Different language models may have the same or different vocabularies. In this application embodiment, when selecting a language model to generate text, the vocabulary of that language model is obtained. The vocabulary of this language model includes a large number of tokens. The language model selects appropriate tokens from the tokens included in the vocabulary to generate text; that is, each token in the text generated by the language model comes from the vocabulary.
[0094] S102. For the i-th token to be generated in the text to be generated, select T generated tokens from the current generated token sequence, and process the T generated tokens through the language model to obtain the probability distribution corresponding to the i-th token to be generated.
[0095] The currently generated tokens include M tokens and the generated tokens of the text to be generated. The probability distribution includes the probability that each token in the vocabulary is selected as the i-th token to be generated. T and i are both positive integers.
[0096] In some embodiments, T is a positive integer greater than or equal to M. In some embodiments, the value of T corresponding to different tokens to be generated can be different. For example, the value of T corresponding to the (i+1)th token to be generated in the text to be generated is greater than the value of T corresponding to the ith token to be generated.
[0097] The language model in this application embodiment can be a large language model, or any other language model that can generate text based on prompt words.
[0098] In this embodiment, when the language model generates each token in the text to be generated, a watermarking method is performed on each token to generate watermarked text. In some embodiments, watermarks may also be injected into a portion of the tokens in the text to be generated to generate watermarked text; this embodiment does not limit this approach.
[0099] In this embodiment, when generating the first token to be generated in the text to be generated, the electronic device selects T generated tokens from the M token sequences included in the prompt (it should be noted that all M tokens included in the prompt are generated tokens). Then, the selected T generated tokens are used to execute the watermarking method of this embodiment to obtain the target token corresponding to the first token to be generated in the vocabulary, and this target token is used as the first generated token of the text to be generated. Simultaneously, the first generated token is added to the aforementioned M token sequences, for example, by adding the first generated token to the end of the M token sequences, to obtain the current generated token sequence. Next, to generate the second token to be generated in the text to be generated, T generated tokens are selected from the current generated token sequence, and the watermarking method of this embodiment is executed using the selected T generated tokens to obtain the target token corresponding to the second token to be generated in the vocabulary, and this target token is used as the second generated token of the text to be generated. Simultaneously, the second generated token is added to the aforementioned current generated token sequence to obtain a new current generated token sequence. Next, a third token to be generated for the text to be generated is produced. T generated tokens are selected from this new sequence of currently generated tokens. The watermarking method of this embodiment is then executed using these T generated tokens to obtain the target token corresponding to the third token in the vocabulary. This target token is then used as the third generated token for the text to be generated. Simultaneously, this third generated token is added to the aforementioned new sequence of currently generated tokens to obtain the latest sequence of currently generated tokens. This process is repeated until the last token for the text to be generated is produced.
[0100] As described above, in this embodiment, the electronic device generates each token to be generated in the text in the same way as the target token in the vocabulary. For ease of description, the i-th token to be generated in the text is used as an example.
[0101] Specifically, for the i-th token to be generated in the text to be generated, the electronic device obtains the currently generated token sequence corresponding to the i-th token. This currently generated token sequence includes the M tokens included in the prompt and the generated tokens in the text to be generated. For example, as shown... Figure 3A As shown, the currently generated token sequence corresponding to the i-th token to be generated includes the M tokens included in the prompt word, and the first generated token x1, the second generated token x2, ..., the (i-1)-th generated token x in the text to be generated. i-1 The electronic device selects T generated tokens from the currently generated token sequence.
[0102] This application does not restrict the specific method by which an electronic device selects T generated tokens from the currently generated token sequence.
[0103] In one possible implementation, such as Figure 3A As shown, the electronic device can select the T generated tokens before the (i-2)th generated token in the current generated token sequence as the T generated tokens corresponding to the i-th token to be generated. At this time, the T generated tokens corresponding to the i-th token to be generated include: the (i-2)th generated token, the (i-3)th generated token, ..., the (iT-1)th generated token.
[0104] In one possible implementation, such as Figure 3A As shown, the electronic device can select the top T generated tokens that are closest to the i-th token to be generated in the current generated token sequence as the T generated tokens corresponding to the i-th token to be generated. At this time, the T generated tokens corresponding to the i-th token to be generated include: the (i-1)-th generated token, the (i-2)-th generated token, the (i-3)-th generated token, ..., the iT-th generated token.
[0105] In one possible implementation, the electronic device can select all generated tokens preceding the i-th token to be generated in the currently generated token sequence (i.e., the first M+i-1 generated tokens) as the T generated tokens corresponding to the i-th token to be generated. In this case, as... Figure 3BAs shown, the T generated tokens corresponding to the i-th token to be generated include: the M tokens included in the prompt word, the (i-1)-th generated token, the (i-2)-th generated token, the (i-3)-th generated token, ..., the iT-th generated token, totaling M+i-1 generated tokens. In other words, in this embodiment, when generating the i-th token to be generated from the text to be generated, the M tokens included in the prompt word and the (i-1)-th generated tokens currently in the text to be generated are all input into the language model for processing to obtain the probability distribution corresponding to the i-th token to be generated.
[0106] In one possible implementation, the electronic device can periodically select T generated tokens from the current generated token sequence as the T generated tokens corresponding to the i-th token to be generated. For example, starting from the last generated token in the current generated token sequence, a generated token is selected every other generated token, for a total of T generated tokens, as the T generated tokens corresponding to the i-th token to be generated.
[0107] This application does not limit the specific value of T in the embodiments described above. In some examples, T is a positive integer; in some examples, T is a positive integer greater than 1. In some examples, T equals M. In some examples, T is a positive integer greater than M. In some examples, the number of T generated tokens corresponding to each token to be generated in the text to be generated is the same. In some examples, the number of T generated tokens corresponding to each token to be generated in the text to be generated is different. In some examples, the number of T generated tokens corresponding to some tokens to be generated in the text to be generated is different, while the number of T generated tokens corresponding to some tokens to be generated is the same.
[0108] Based on the above steps, the electronic device selects T generated tokens corresponding to the i-th token to be generated from the currently generated token sequence, and inputs these T generated tokens into the language model for processing to obtain the probability distribution corresponding to the i-th token to be generated.
[0109] In one example, the process of determining the probability distribution corresponding to the i-th token to be generated can be represented by the following formula (1):
[0110]
[0111] Among them, P i Let i be the probability distribution corresponding to the i-th token to be generated. l represents the length of the language model's vocabulary, i.e., the number of tokens included in the vocabulary. x i This represents the i-th token to be generated in the text to be generated, (x1, x2, ..., x...). M,x M+1 ,…,x M+i-1 Let T be the T generated tokens corresponding to the i-th token to be generated, where T equals M+i-1. If the i-th token to be generated is the first token to be generated in the text to be generated, then the T generated tokens corresponding to the first token to be generated are the M tokens included in the prompt word, where T equals M.
[0112] For example, Figure 4 The diagram illustrates the process of inputting the three generated tokens corresponding to the i-th token to be generated into a language model for processing when T equals 3, to obtain the probability distribution corresponding to the i-th token to be generated. This probability distribution includes the probability that each token in the vocabulary is selected as the i-th token to be generated. Figure 4 As shown, the probability distribution corresponding to the i-th token to be generated indicates that the greater the probability of a certain token in the vocabulary, the greater the possibility that the token will be selected as the i-th token to be generated.
[0113] S103. Select K generated tokens from the current generated token sequence, determine the semantic feature information of the K generated tokens, and determine the random seed corresponding to the i-th token to be generated based on the semantic feature information of the K generated tokens.
[0114] Where K is a positive integer greater than 1.
[0115] It should be noted that the electronic device does not restrict the specific execution order of S102 and S103 described above. For example, for the i-th candidate token in the text to be generated, the electronic device can first select T generated tokens from the currently generated token sequence and input them into the language model for processing to obtain the probability distribution corresponding to the i-th candidate token. Then, it can select K generated tokens from the currently generated token sequence and determine the semantic feature information of the K generated tokens. Alternatively, the electronic device can first select K generated tokens from the currently generated token sequence and determine the semantic feature information of the K generated tokens, then select T generated tokens from the currently generated token sequence and input them into the language model for processing to obtain the probability distribution corresponding to the i-th candidate token. Or, the electronic device can simultaneously select T generated tokens from the currently generated token sequence and input them into the language model for processing to obtain the probability distribution corresponding to the i-th candidate token, while simultaneously selecting K generated tokens from the currently generated token sequence and determining the semantic feature information of the K generated tokens.
[0116] The following describes the process by which an electronic device selects K generated tokens from the currently generated token sequence.
[0117] This application does not limit the specific method by which the electronic device selects K generated tokens from the currently generated token sequence.
[0118] In one possible implementation, the electronic device can randomly select K generated tokens from the currently generated tokens as the K generated tokens corresponding to the i-th token to be generated.
[0119] In one possible implementation, the electronic device selects the top K generated tokens closest to the i-th token to be generated from the currently generated token sequence, and uses these as the K generated tokens. For example... Figure 5 As shown, the currently generated token sequence corresponding to the i-th token to be generated includes the M tokens included in the prompt, and the first generated token, the second generated token, ..., the (i-1)-th generated token in the text to be generated. The electronic device will generate the (i-1)-th generated token x. i-1 The (i-2)th generated token x i-2 ..., the iKth generated token x i-k Determine the K generated tokens corresponding to the i-th token to be generated.
[0120] In one possible implementation, the electronic device can select the K generated tokens preceding the (i-2)th generated token in the current generated token sequence as the K generated tokens corresponding to the i-th token to be generated. In this case, the K generated tokens corresponding to the i-th token to be generated include: the (i-2)th generated token, the (i-3)th generated token, ..., the (i-K-1)th generated token.
[0121] In one possible implementation, the electronic device can periodically select K generated tokens from the current generated token sequence as the K generated tokens corresponding to the i-th token to be generated. For example, starting from the last generated token in the current generated token sequence, a generated token is selected every other generated token, for a total of K generated tokens, as the K generated tokens corresponding to the i-th token to be generated.
[0122] This application does not limit the specific value of K, as long as it is greater than 1 and less than or equal to the total number of tokens in the currently generated token sequence. In one example, K is less than T. In another example, K is equal to T. In yet another example, K is less than T.
[0123] In one example, the K generated tokens corresponding to the i-th token to be generated in this step can be all or part of the T generated tokens corresponding to the i-th token to be generated. For example, the K generated tokens can be the T generated tokens, so the electronic device only needs to make one selection from the current sequence of generated tokens.
[0124] In one possible implementation, the electronic device can select all the generated tokens before the i-th token to be generated in the current generated token sequence (i.e., the first M+i-1 generated tokens) as the K generated tokens corresponding to the i-th token to be generated.
[0125] In this embodiment, the electronic device selects K generated tokens from the current generated token sequence, and uses these K generated tokens as input to the semantic hash SemHash to obtain the i-th token to be generated, x. i The corresponding random seed S i This process can be represented by formula (2):
[0126] S i =SemHash(x) i-K ,x i-K+1 ,…,x i-1 ,x i (2)
[0127] The following describes the specific process by which an electronic device generates a random seed corresponding to the i-th token to be generated, based on the K generated tokens corresponding to the i-th token to be generated.
[0128] In this embodiment, the electronic device selects K generated tokens from the current generated token sequence and then extracts the semantic feature information of these K generated tokens. For example, these K generated tokens are input into a characterization extractor to extract their semantic feature information.
[0129] For example, the process of extracting the semantic feature information of these K generated tokens can be represented by the following formula (3):
[0130] e = Φ(x) i-K ,x i-K+1 ,…,x i-1 ,x i (3)
[0131] Where e represents the semantic feature information of the K generated tokens corresponding to the i-th token to be generated, and Φ(.) is the representation extractor.
[0132] Next, the electronic device determines the random seed corresponding to the i-th token to be generated based on the semantic feature information of the K generated tokens.
[0133] This application does not limit the specific method by which the electronic device determines the random seed corresponding to the i-th token to be generated based on the semantic feature information of these K generated tokens.
[0134] In some embodiments, the electronic device can classify the semantic features of the K generated tokens (which are vectors) into a classifier to determine which preset category the statement formed by the K generated tokens belongs to, thus obtaining the classification result corresponding to the K generated tokens. Then, based on the index of this classification result (i.e., the index of the classification result in the preset category list), the electronic device determines the random seed corresponding to the i-th token to be generated. For example, the electronic device uses the index of the classification result as the random seed corresponding to the i-th token to be generated. Another example is using the product of the index of the classification result and a preset key, or other operational results of the index of the classification result and the preset key, as the random seed corresponding to the i-th token to be generated.
[0135] In some embodiments, the electronic device can determine the random seed corresponding to the i-th token to be generated through the following steps S103-A and S103-B:
[0136] S103-A: Based on the semantic feature information of K generated tokens, determine the target semantic feature cluster center among the preset R semantic feature cluster centers. The R semantic feature cluster centers are obtained by clustering the semantic feature information of P preset statements, where R is a positive integer greater than 1 and P is a positive integer greater than R.
[0137] S103-B: Based on the identification information of the cluster center of the target semantic feature, determine the random seed corresponding to the i-th token to be generated.
[0138] In this implementation, an embodiment of this application establishes a representation space, which includes R semantic feature clustering centers. These R semantic feature clustering centers are obtained by clustering the semantic feature information of P preset statements. For example, P statements are selected from statements included in an existing dataset; these P statements can be all statements in the dataset or only a portion of the statements in the dataset. Next, semantic feature extraction is performed on each of these P statements. For example, each statement is input into a representation extractor for semantic feature extraction to obtain the semantic feature information of each of the P statements.
[0139] Next, the semantic feature information of these P statements is clustered. This embodiment of the application does not limit the specific method by which the electronic device clusters the semantic feature information of these P statements to obtain R semantic feature cluster centers. In one possible implementation, the electronic device randomly selects R semantic feature information from the semantic feature information of these P statements as R cluster centers. Then, the electronic device calculates the distance from the semantic feature information of each statement in the P statements to the R cluster centers, and assigns the semantic feature information of each statement to the category represented by the nearest cluster center. Based on the assignment result, the center point of each cluster is recalculated, usually by calculating the mean of the semantic feature information of all statements in that category, as the new cluster center. The above steps are repeated until the iteration termination condition is met, such as the center point no longer changing or the specified number of iterations is reached. Finally, R semantic feature cluster centers are obtained. It should be noted that these R semantic feature cluster centers are all vectors with the same dimension as the semantic feature information.
[0140] For example, in this embodiment of the application, the process of clustering the semantic feature information of P statements to obtain R semantic feature cluster centers can be represented by the following formula (4):
[0141]
[0142] Where Cluster(.) is the clustering equation, and D is the dataset consisting of P statements. This represents the semantic feature information of P statements.
[0143] In this way, the electronic device can determine the target semantic feature cluster center from among the preset R semantic feature cluster centers based on the semantic feature information of K generated tokens.
[0144] This application embodiment does not limit the specific method by which an electronic device determines the target semantic feature cluster center from R semantic feature cluster centers based on the semantic feature information of K generated tokens.
[0145] In some embodiments, the electronic device classifies the R semantic feature cluster centers using a classifier, obtaining the classification results corresponding to each of the R semantic feature cluster centers. Simultaneously, the electronic device uses the same classifier to classify the semantic feature information of K generated tokens, obtaining the classification results corresponding to the semantic feature information of the K generated tokens. The semantic feature cluster center whose classification results from the R semantic feature cluster centers are consistent with the classification results corresponding to the semantic feature information of the K generated tokens is determined as the target semantic feature cluster center.
[0146] In some embodiments, the electronic device determines the target semantic feature cluster center corresponding to the i-th token to be generated from the R semantic feature cluster centers by calculating the similarity between the R semantic feature cluster centers and the semantic feature information of K generated tokens. Specifically, this includes the following steps S103-A1 and S103-A2:
[0147] S103-A1. For each of the R semantic feature cluster centers, determine the distance between the semantic feature information of the K generated tokens and the semantic feature cluster center.
[0148] S103-A2: Based on distance, determine the target semantic feature cluster center from R semantic feature cluster centers.
[0149] In this implementation, for each of the R semantic feature cluster centers, the electronic device determines the distance between the semantic feature information of the K generated tokens and each semantic feature cluster center. This embodiment does not limit the distance calculation method; it can be any method for calculating the distance between two vectors, such as cosine distance. Then, based on the distance between the semantic feature information of the K generated tokens and each semantic feature cluster center, the target semantic feature cluster center corresponding to the i-th token to be generated is selected from the R semantic feature cluster centers.
[0150] This application does not limit the specific method by which an electronic device determines the target semantic feature cluster center from R semantic feature cluster centers based on distance.
[0151] In one example, the electronic device identifies the semantic feature cluster center among the R semantic feature cluster centers that has the smallest distance to the semantic feature information of the K generated tokens as the target semantic feature cluster center corresponding to the i-th token to be generated. The specific process by which the electronic device determines the target semantic feature cluster center corresponding to the i-th token to be generated can be represented by the following formula (5):
[0152]
[0153] Where c′ represents the target semantic feature information, c r Let dist(e,c) represent the r-th semantic feature cluster center among R semantic feature cluster centers. r ) represents the distance between the semantic feature information of the K generated tokens and the cluster center of the r-th semantic feature.
[0154] In some embodiments, the electronic device may also determine the semantic feature cluster center that is the second smallest in distance to the semantic feature information of the K generated tokens among the R semantic feature cluster centers as the target semantic feature cluster center corresponding to the i-th token to be generated, etc., and the embodiments of this application do not limit this.
[0155] Based on the above steps, after determining the target semantic feature cluster center corresponding to the i-th token to be generated from R semantic feature cluster centers, the electronic device obtains the identification information of the target semantic feature cluster center.
[0156] The identification information of the target semantic feature cluster center can be any information that uniquely identifies the target semantic feature cluster center.
[0157] In one example, the identification information of the target semantic feature cluster center can be the index or identifier of the target semantic feature cluster center in a list of R semantic feature cluster centers.
[0158] Next, the electronic device determines the random seed corresponding to the i-th token to be generated based on the identification information of the target semantic feature cluster center corresponding to the i-th token to be generated.
[0159] This application embodiment does not limit the specific method by which the electronic device determines the random seed corresponding to the i-th token to be generated based on the identification information of the target semantic feature cluster center corresponding to the i-th token to be generated.
[0160] In some embodiments, the electronic device determines the identifier information of the target semantic feature cluster center corresponding to the i-th token to be generated as the random seed corresponding to the i-th token to be generated. For example, the index of the target semantic feature cluster center corresponding to the i-th token to be generated is determined as the random seed corresponding to the i-th token to be generated.
[0161] In some embodiments, the electronic device obtains a preset key, which can provide a unique identifier for the watermark adder to prevent other users from impersonating the watermark adder and forging text. Optionally, the key can be randomly generated or input from an object. Then, based on the preset key and the identification information of the target semantic feature cluster center, a random seed corresponding to the i-th token to be generated is obtained.
[0162] This application does not limit the specific method by which the electronic device obtains the random seed corresponding to the i-th token to be generated based on the preset key and the identification information of the target semantic feature cluster center. For example, the electronic device performs a linear operation on the preset key and the identification information of the target semantic feature cluster center to obtain the random seed corresponding to the i-th token to be generated.
[0163] In one possible implementation, the electronic device adds the preset key and the identification information of the target semantic feature cluster center to obtain the random seed corresponding to the i-th token to be generated.
[0164] In one possible implementation, the electronic device multiplies the preset key and the identification information of the target semantic feature cluster center to obtain the random seed corresponding to the i-th token to be generated.
[0165] For example, the electronic device determines the random seed S corresponding to the i-th token to be generated according to the following formula (6). i :
[0166] S i =idx·Key (6)
[0167] Where idx is the identifier information of the target semantic feature cluster center corresponding to the i-th token to be generated, and Key is the preset key.
[0168] In this embodiment, when adding a watermark to the i-th token to be generated in the text, a random seed corresponding to the i-th token is generated using the semantic feature information of the K generated tokens corresponding to the i-th token. Thus, without altering the semantics of the generated text, the random seed cannot be changed through simple word replacement, and therefore the watermark added to the text based on the random seed cannot be eliminated, thereby improving the reliability and robustness of watermark addition.
[0169] The following example illustrates one possible implementation of this step.
[0170] like Figure 6 As shown, assume that the K generated tokens corresponding to the i-th token to be generated are 3 generated tokens, and the R semantic feature cluster centers are 4 semantic feature cluster centers. These 3 generated tokens are input into a representation extractor for semantic feature extraction, yielding their semantic feature information. The distance between the semantic feature information of these 3 generated tokens and each of the 4 semantic feature cluster centers is determined, resulting in 4 distances. The semantic feature cluster center corresponding to the smallest of these 4 distances is determined as the target semantic feature cluster center for the i-th token to be generated. The index of this target semantic feature cluster center within the 4 semantic feature cluster centers is obtained, and then multiplied by the key to obtain the random seed corresponding to the i-th token to be generated.
[0171] Based on the above steps, after determining the random seed corresponding to the i-th token to be generated, the electronic device executes the following step S104.
[0172] S104. Adjust the probabilities in the probability distribution based on the random seed, and determine the target token corresponding to the i-th token to be generated in the vocabulary based on the adjusted probability distribution. Then, based on the target token, obtain the text with watermark added.
[0173] In this embodiment, when generating the i-th token to be generated from the text to be generated, the electronic device predicts the probability that each token in the vocabulary of the language model will be selected as the i-th token to be generated through a language model. Based on the above steps, a random seed corresponding to the i-th token to be generated is determined. Then, the electronic device uses this random seed to adjust a portion of the probability in the language model's predicted probability of each token in the vocabulary being selected as the i-th token to be generated (i.e., the probability distribution corresponding to the i-th token to be generated).
[0174] The embodiments of this application do not limit the specific method by which the electronic device adjusts the probability in the probability distribution based on a random seed to obtain the adjusted probability distribution.
[0175] In some embodiments, the electronic device can adjust a portion of the probabilities in the aforementioned probability distribution based on the parity of the random seed. For example, if the random seed is odd, the probability value of tokens with odd-numbered unique identifiers in the language model's vocabulary is increased or decreased in the probability distribution, while the probability value of tokens with even-numbered unique identifiers in the language model's vocabulary remains unchanged, resulting in an adjusted probability distribution. Similarly, if the random seed is even, the probability value of tokens with even-numbered unique identifiers in the language model's vocabulary is increased or decreased in the probability distribution, while the probability value of tokens with odd-numbered unique identifiers in the language model's vocabulary remains unchanged, resulting in an adjusted probability distribution. Again, if the random seed is odd, the probability value of tokens with even-numbered unique identifiers in the language model's vocabulary is increased or decreased in the probability distribution, while the probability value of tokens with odd-numbered unique identifiers in the language model's vocabulary remains unchanged, resulting in an adjusted probability distribution. For example, if the random seed is even, the probability value of tokens with odd-numbered unique identifiers in the vocabulary of the language model is increased or decreased in the probability distribution, while the probability value of tokens with even-numbered unique identifiers in the vocabulary of the language model remains unchanged, thus obtaining the adjusted probability distribution.
[0176] In some embodiments, adjusting the probabilities in the probability distribution based on a random seed in S104 above includes the following steps S104-A1 and S104-A2:
[0177] S104-A1: Based on random seeds, the vocabulary is divided into a preferred selection set and a non-preferred selection set;
[0178] S104-A2. Based on a preset bias value, the probability of tokens belonging to the preferred selection set in the probability distribution is increased to obtain the adjusted probability distribution.
[0179] In this implementation, the electronic device divides the vocabulary of the language model into a preferred selection set and a non-preferred selection set based on the random seed corresponding to the i-th token to be generated. Both the preferred selection set and the non-preferred selection set include at least one token from the vocabulary, and the included tokens are different. In other words, in this embodiment, the electronic device divides the tokens included in the vocabulary of the language model into two parts based on the random seed corresponding to the i-th token to be generated: one part forms the preferred selection set, and the other part forms the non-preferred selection set. Tokens in the preferred selection set have a higher probability of being selected.
[0180] This application does not limit the specific method by which an electronic device divides a vocabulary into a preferred selection set and a non-preferred selection set based on a random seed.
[0181] In one possible implementation, the electronic device can divide the vocabulary of the language model into a preferred set and a non-preferred set based on the parity of the random seed. For example, if the random seed is odd, tokens with odd-numbered unique identifiers in the language model's vocabulary are assigned to the preferred set, and tokens with even-numbered unique identifiers are assigned to the non-preferred set. Similarly, if the random seed is even, tokens with even-numbered unique identifiers in the language model's vocabulary are assigned to the preferred set, and tokens with odd-numbered unique identifiers are assigned to the non-preferred set. And so on. For example, if the random seed is even, tokens with odd-numbered unique identifiers in the language model's vocabulary are assigned to the preferred selection set, while tokens with even-numbered unique identifiers in the language model's vocabulary are assigned to the non-preferred selection set.
[0182] In one possible implementation, the electronic device obtains the ratio of the number of tokens included in the preferred selection set to the total number of tokens in the vocabulary; based on the ratio and the random seed, the vocabulary is divided into a preferred selection set and a non-preferred selection set.
[0183] The preferred option is to select either the ratio of the number of tokens included in the set to the total number of tokens in the vocabulary as the default value or the value entered by the object.
[0184] In this implementation, the electronic device prioritizes the ratio of the number of tokens in the selected set to the total number of tokens in the vocabulary, and uses a random seed to generate a mask value corresponding to each token in the language model's vocabulary. Then, based on this mask value, the electronic device divides the tokens in the vocabulary into a preferred set and a non-preferred set. For example, assuming the language model's vocabulary contains 10,000 tokens, the electronic device, based on the ratio of the number of tokens in the preferred set to the total number of tokens in the vocabulary, and using a preset mask generation rule, generates a 10,000-dimensional mask vector. This mask vector includes the mask value corresponding to each of the 10,000 tokens in the vocabulary, where the mask value is either 1 or 0. If the mask value of a token is 1, it indicates that the token is assigned to the preferred set; if the mask value is 0, it indicates that the token is assigned to the non-preferred set. In this way, the electronic device can divide the tokens in the vocabulary into the preferred set and the non-preferred set based on this mask vector, thus obtaining the preferred set and the non-preferred set.
[0185] Next, the steps S104-A2 above are executed. Based on the preset bias value, the probability of tokens belonging to the preferred selection set in the probability distribution is increased to obtain the adjusted probability distribution.
[0186] This application embodiment does not limit the specific method by which the probability of a token belonging to the preferred selection set in the probability distribution is increased based on a preset bias value in the electronic device to obtain the adjusted probability distribution.
[0187] In one possible implementation, such as Figure 7 As shown, the electronic device adds the preset bias value δ to the probability of tokens belonging to the preferred selection set in the probability distribution, while keeping the probability of tokens belonging to the non-preferred selection set unchanged, thus obtaining the adjusted probability distribution.
[0188] In one possible implementation, the electronic device subtracts the preset bias value δ from the probability of a token belonging to the non-preferred set in the probability distribution, while keeping the probability of a token belonging to the preferred set unchanged, thus obtaining an adjusted probability distribution.
[0189] In this embodiment, tokens belonging to the preferred selection set in the adjusted probability distribution are more likely to be selected as the i-th token to be generated. Thus, the electronic device determines the target token corresponding to the i-th token to be generated from the vocabulary based on the adjusted probability distribution. For example, the electronic device can determine the token with the highest probability value in the vocabulary as the target token corresponding to the i-th token to be generated, based on the adjusted probability distribution. Alternatively, the electronic device can determine the token with the second highest probability value in the vocabulary as the target token corresponding to the i-th token to be generated, based on the adjusted probability distribution. This target token corresponding to the i-th token to be generated is then used as the i-th generated token in the text to be generated.
[0190] In one example, the electronic device determines the target token x corresponding to the i-th token to be generated in the vocabulary based on an adjusted probability distribution. i The specific process can be represented by the following formula (7):
[0191] x i =sample(bias(P) i Set prior ,δ)) (7)
[0192] Where sample(.) is the sampling function, P i Let be the probability distribution corresponding to the i-th token to be generated, bias(.) be the bias equation, δ be the preset bias value, and Set prior To prioritize the selection of the set, bias(P) i Set prior ,δ) represents the adjusted probability distribution corresponding to the i-th token to be generated.
[0193] The above describes the specific process by which an electronic device determines the target token corresponding to the i-th token to be generated in the text to be generated.
[0194] Based on the above steps, after the electronic device determines the target token corresponding to the i-th token to be generated, as follows: Figure 8 As shown, the target token corresponding to the i-th token to be generated is taken as the i-th generated token in the text to be generated and added to the end of the currently generated tokens to obtain a new sequence of currently generated tokens. Simultaneously, it is determined whether the i-th generated token is the last token in the text to be generated. Assuming the text to be generated contains n tokens, it is determined whether i equals n. If the i-th generated token is the last token in the text to be generated, i.e., i equals n, then the generation process of the text to be generated is complete, and the watermarked text is output. Specifically, this involves deleting M tokens belonging to the prompt word from the new sequence of currently generated tokens, resulting in the token sequence (x1, x2, x3…x…). n () is used to add a watermark to the text.
[0195] If the i-th generated token is not the last token in the text to be generated (i.e., i is less than n), then generate the (i+1)-th token in the text to be generated. Let i = i+1, and return to step S102 above. Select T generated tokens from the new sequence of generated tokens, and refer to the above steps to generate the target token corresponding to the (i+1)-th token in the text to be generated. Repeat this process until i equals n, and finally output the watermarked text. The number of tokens in the watermarked text is determined by prioritizing tokens from the set, facilitating subsequent detection of the watermark information.
[0196] The text watermarking method proposed in this application involves obtaining prompt words for the text to be generated and a vocabulary of a language model. The prompt words include M tokens. For the i-th token to be generated in the text, T generated tokens are obtained from the currently generated token sequence. The language model processes these T generated tokens to obtain the probability distribution corresponding to the i-th token to be generated. The currently generated tokens include M tokens and the generated tokens of the text to be generated. The probability distribution includes the probability that each token in the vocabulary is selected as the i-th token to be generated. Next, K generated tokens are selected from the currently generated token sequence, and the semantic feature information of the K generated tokens is determined, where K is a positive integer greater than 1. Based on the semantic feature information of the K generated tokens, a random seed corresponding to the i-th token to be generated can be determined. Then, the probabilities in the probability distribution are adjusted based on the random seed to obtain an adjusted probability distribution. Finally, based on the adjusted probability distribution, the target token corresponding to the i-th token to be generated in the vocabulary is determined, and the watermarked text is obtained based on the target token. Therefore, in this embodiment, the random seed is determined using the semantic features of K generated tokens. Based on this random seed, the probability distribution is adjusted, and the words corresponding to the tokens in the text to be generated are obtained from the adjusted probability distribution, ultimately resulting in watermarked text. Since the watermarked text does not change its semantics, simple word replacement cannot remove the watermark information, thus improving the robustness of the watermark added to the text generated by the language model. This allows for accurate identification of the watermark in subsequent watermark detection, confirming that the text is generated by the language model and improving the accuracy of recognizing language model-generated text.
[0197] The above section introduced methods for adding text watermarks. The following section introduces methods for watermark detection in text generated using these methods.
[0198] Figure 9This is a flowchart illustrating a text watermark detection method provided in an embodiment of this application. The execution entity of this embodiment can be a device with watermark detection functionality, such as a watermark detection device. This watermark detection device can be the one described above. Figure 1 The server 102 or terminal device 101 shown can also be Figure 1 The system shown comprises server 102 and terminal device 101. For ease of description, the following embodiments use an electronic device as an example to illustrate the method of this application.
[0199] like Figure 9 As shown, the text watermark detection method in this application includes:
[0200] S201. Obtain the prompt words and the vocabulary of the language model for the text to be detected.
[0201] The text to be detected includes N tokens, where N is a positive integer greater than 1.
[0202] It should be noted that the method of acquiring data and the data acquired in the text watermark detection process of this application embodiment comply with the provisions of relevant laws and regulations.
[0203] The purpose of this application embodiment is to detect whether the text to be detected is text generated by the language model. As can be seen from the above-described text watermarking method, this application embodiment adds watermark information to the generated text when generating text through the language model. In this way, the electronic device can determine whether the text to be detected is text generated by the language model by detecting the watermark information.
[0204] S202. For the j-th token in the text to be detected, select K tokens corresponding to the j-th token from N tokens, determine the semantic feature information of the K tokens, and determine the random seed corresponding to the j-th token based on the semantic feature information of the K tokens.
[0205] Where K is a positive integer greater than 1, and j is a positive integer from 1 to N.
[0206] In this embodiment, when the language model generates each token in the text to be generated, a watermark detection method is performed on each token to generate watermarked text. Correspondingly, when performing watermark information detection on the text to be detected, watermark detection is performed on each token in the text to be detected.
[0207] In this application embodiment, the process of watermark detection for each token in the text to be detected by the electronic device is basically the same. For ease of description, the j-th token in the text to be detected will be used as an example for illustration.
[0208] Specifically, for the j-th token of the text to be detected, the electronic device selects K tokens from the N tokens included in the text to be detected as the K tokens corresponding to the j-th token.
[0209] This application does not restrict the specific method by which an electronic device selects the K tokens corresponding to the j-th token from N tokens.
[0210] In one possible implementation, the electronic device can randomly select K tokens from N tokens as the K tokens corresponding to the j-th token.
[0211] In one possible implementation, the electronic device selects the K closest tokens to the j-th token from the N token sequences included in the text to be detected, choosing them as the K tokens corresponding to the j-th token. For example... Figure 10 As shown, at this time, the K tokens corresponding to the j-th token include: the (j-1)-th token, the (j-2)-th token, ..., the jK-th token.
[0212] In one possible implementation, the electronic device can select the K tokens preceding the (j-2)th token from the N token sequences included in the text to be detected, as the K tokens corresponding to the j-th token. In this case, the K tokens corresponding to the j-th token include: the (j-2)th token, the (j-3)th token, ..., the (jK-1)th token.
[0213] In one possible implementation, the electronic device can periodically select K tokens from the N token sequences included in the text to be detected, as the K tokens corresponding to the j-th token. For example, starting from the (j-1)-th token in the N token sequences included in the text to be detected, a token is selected every other token, for a total of K tokens, as the K tokens corresponding to the j-th token.
[0214] It should be noted that the rule for selecting K tokens in the text watermark detection process is consistent with the rule for selecting K tokens in the text watermark addition method described above, so that the random seeds generated at both ends (i.e., the watermark addition end and the watermark detection end) are consistent, thereby achieving accurate detection of watermark information.
[0215] In this embodiment, the electronic device selects K tokens from the N tokens included in the file to be detected, and uses these K tokens as input to the semantic hash SemHash to obtain the j-th token x. i The corresponding random seed S i The process can be represented by formula (2).
[0216] The following describes the specific process by which an electronic device generates a random seed corresponding to the j-th token based on the k tokens corresponding to the j-th token.
[0217] In this embodiment, the electronic device selects K tokens from N tokens included in the document to be detected, and then extracts the semantic feature information of these K tokens. For example, these K tokens are input into a characterization extractor to extract their semantic feature information.
[0218] Next, the electronic device determines the random seed corresponding to the j-th token based on the semantic feature information of these K tokens.
[0219] This application does not limit the specific method by which the electronic device determines the random seed corresponding to the j-th token based on the semantic feature information of these K tokens.
[0220] In some embodiments, the electronic device may determine the random seed corresponding to the j-th token through the following steps S202-A and S202-B:
[0221] S202-A: Based on the semantic feature information of K tokens, determine the target semantic feature cluster center among the preset R semantic feature cluster centers. The R semantic feature cluster centers are obtained by clustering the semantic feature information of P preset statements, where R is a positive integer greater than 1 and P is a positive integer greater than R.
[0222] S202-B: Determine the random seed corresponding to the j-th token based on the identification information of the cluster center of the target semantic feature.
[0223] In this implementation, an embodiment of this application establishes a representation space, which includes R semantic feature clustering centers. These R semantic feature clustering centers are obtained by clustering the semantic feature information of P preset statements. For example, P statements are selected from statements included in an existing dataset; these P statements can be all statements in the dataset or only a portion of the statements in the dataset. Next, semantic feature extraction is performed on each of these P statements. For example, each statement is input into a representation extractor for semantic feature extraction to obtain the semantic feature information of each of the P statements.
[0224] Next, the semantic features of these P statements are clustered to obtain R semantic feature cluster centers. It should be noted that these R semantic feature cluster centers are all vectors with the same dimension as the semantic feature information.
[0225] In this way, the electronic device can determine the target semantic feature cluster center from among the preset R semantic feature cluster centers based on the semantic feature information of K tokens.
[0226] This application embodiment does not limit the specific method by which an electronic device determines the target semantic feature cluster center among R semantic feature cluster centers based on the semantic feature information of K tokens.
[0227] In some embodiments, the electronic device determines the target semantic feature cluster center corresponding to the j-th token from the R semantic feature cluster centers by calculating the similarity between the R semantic feature cluster centers and the semantic feature information of K tokens. Specifically, this includes the following steps S202-A1 and S202-A2:
[0228] S202-A1. For each of the R semantic feature cluster centers, determine the distance between the semantic feature information of the K tokens and the semantic feature cluster center;
[0229] S202-A2: Based on distance, determine the target semantic feature cluster center from R semantic feature cluster centers.
[0230] In this implementation, for each of the R semantic feature cluster centers, the electronic device determines the distance between the semantic feature information of the K tokens and each semantic feature cluster center. This embodiment does not limit the distance calculation method; it can be any method for calculating the distance between two vectors, such as cosine distance. Then, based on the distance between the semantic feature information of the K tokens and each semantic feature cluster center, the target semantic feature cluster center corresponding to the j-th token is selected from the R semantic feature cluster centers.
[0231] This application does not limit the specific method by which an electronic device determines the target semantic feature cluster center from R semantic feature cluster centers based on distance.
[0232] In one example, the electronic device identifies the semantic feature cluster center with the smallest distance from the semantic feature information of the K tokens among the R semantic feature cluster centers as the target semantic feature cluster center corresponding to the j-th token.
[0233] Based on the above steps, after determining the target semantic feature cluster center corresponding to the j-th token from the R semantic feature cluster centers, the electronic device obtains the identification information of the target semantic feature cluster center.
[0234] The identification information of the target semantic feature cluster center can be any information that uniquely identifies the target semantic feature cluster center.
[0235] In one example, the identification information of the target semantic feature cluster center can be the index or identifier of the target semantic feature cluster center in a list of R semantic feature cluster centers.
[0236] Next, the electronic device determines the random seed corresponding to the j-th token based on the identification information of the target semantic feature cluster center corresponding to the j-th token.
[0237] In some embodiments, the electronic device obtains a preset key, which can be a unique identifier provided by the watermark adder to prevent other users from impersonating the watermark adder and forging text. Based on the preset key and the identifier information of the target semantic feature cluster center, the electronic device obtains the random seed corresponding to the j-th token.
[0238] In one possible implementation, the electronic device adds the preset key and the identification information of the target semantic feature cluster center to obtain the random seed corresponding to the j-th token.
[0239] In one possible implementation, the electronic device multiplies the preset key and the identification information of the target semantic feature cluster center to obtain the random seed corresponding to the j-th token.
[0240] In this embodiment, when detecting watermark information for the j-th token in the text to be detected, a random seed corresponding to the j-th token is generated using the semantic feature information of the K tokens corresponding to the j-th token. Thus, without altering the semantics of the text to be detected, simple word replacement or similar methods cannot change the random seed, thereby preventing the removal of the watermark added to the text based on the random seed. This improves the reliability and robustness of watermark detection.
[0241] The specific implementation process of S202 can be referred to the relevant description of S103 above, and will not be repeated here.
[0242] After determining the random seed corresponding to the j-th token based on the above steps, the electronic device executes the following step S203.
[0243] S203. Based on a random seed, the vocabulary is divided into a preferred selection set and a non-preferred selection set to determine whether the j-th token belongs to the preferred selection set.
[0244] In this embodiment, the electronic device divides the vocabulary of the language model into a preferred selection set and a non-preferred selection set based on the random seed corresponding to the j-th token. Both the preferred selection set and the non-preferred selection set include at least one token from the vocabulary, and the included tokens are different. In other words, in this embodiment, the electronic device divides the tokens included in the vocabulary of the language model into two parts based on the random seed corresponding to the j-th token: one part forms the preferred selection set, and the other part forms the non-preferred selection set. Tokens in the preferred selection set have a higher probability of being selected.
[0245] This application does not limit the specific method by which an electronic device divides a vocabulary into a preferred selection set and a non-preferred selection set based on a random seed.
[0246] In one possible implementation, the electronic device obtains the ratio of the number of tokens included in the preferred selection set to the total number of tokens in the vocabulary; based on the ratio and the random seed, the vocabulary is divided into a preferred selection set and a non-preferred selection set.
[0247] The preferred option is to select either the ratio of the number of tokens included in the set to the total number of tokens in the vocabulary as the default value or the value entered by the object.
[0248] In this implementation, the electronic device prioritizes the ratio of the number of tokens in the selected set to the total number of tokens in the vocabulary, and uses a random seed to generate a mask value corresponding to each token in the language model's vocabulary. Then, based on this mask value, the electronic device divides the tokens in the vocabulary into a preferred set and a non-preferred set. For example, assuming the language model's vocabulary contains 10,000 tokens, the electronic device, based on the ratio of the number of tokens in the preferred set to the total number of tokens in the vocabulary, and using a preset mask generation rule, generates a 10,000-dimensional mask vector. This mask vector includes the mask value corresponding to each of the 10,000 tokens in the vocabulary, where the mask value is either 1 or 0. If the mask value of a token is 1, it indicates that the token is assigned to the preferred set; if the mask value is 0, it indicates that the token is assigned to the non-preferred set. In this way, the electronic device can divide the tokens in the vocabulary into the preferred set and the non-preferred set based on this mask vector, thus obtaining the preferred set and the non-preferred set.
[0249] Based on the above steps, the electronic device divides the vocabulary of the language model into a preferred set and a non-preferred set, and then determines whether the j-th token in the text to be detected belongs to the preferred set. If the j-th token belongs to the preferred set, the count of tokens belonging to the preferred set in the text to be detected is incremented by 1.
[0250] If the j-th token is not the last token in the text to be detected, then the (j+1)-th token in the text to be detected is selected as the new j-th token, and the process returns to step S202 above. The random seed corresponding to the new j-th token is determined, and the vocabulary is divided into a preferred selection set and a non-preferred selection set based on the random seed. It is then determined whether the new j-th token belongs to the preferred selection set. This process is repeated for each token in the text to be detected to obtain the number of tokens in the text that belong to the preferred selection set. Next, step S204 is executed.
[0251] S204. Based on the number of tokens in the text to be detected that belong to the preferred selection set, determine the watermark detection result of the text to be detected.
[0252] Based on the above steps, the electronic device determines the number of tokens belonging to the preferred set in the text to be detected. Then, based on the number of tokens belonging to the preferred set in the text to be detected, it determines the watermark detection result of the text to be detected. That is, based on the number of tokens belonging to the preferred set in the text to be detected, it determines whether the text to be detected contains watermark information, and thus determines whether the text to be detected is text generated by the language model.
[0253] This application does not limit the specific method by which an electronic device determines the watermark detection result of the text to be detected based on the number of tokens belonging to the preferred selection set in the text to be detected.
[0254] In some embodiments, if the number of tokens belonging to the preferred set in the text to be detected is greater than or equal to a preset threshold, then the text to be detected is determined to contain watermark information, i.e., the text to be detected is determined to be generated by a language model. If the number of tokens belonging to the preferred set in the text to be detected is less than the preset threshold, then the text to be detected is determined to not contain watermark information, i.e., the text to be detected is determined to be not generated by a language model.
[0255] In some embodiments, the ratio of the number of tokens belonging to the preferred set in the text to the total number N of tokens in the text is determined, and then the watermark detection result of the text is determined based on this ratio. For example, if the ratio is greater than or equal to a certain preset ratio, it is determined that the text to be detected includes watermark information, that is, it is determined that the text to be detected was generated by a language model. If the ratio is less than the preset ratio, it is determined that the text to be detected does not include watermark information, that is, it is determined that the text to be detected was not generated by a language model.
[0256] In some embodiments, S204 above includes the following steps S204-A to S204-C:
[0257] S204-A, Obtain the ratio of the number of tokens included in the preferred selection set to the total number of tokens in the vocabulary;
[0258] S204-B: Determine the watermark strength of the text to be detected based on the proportion and the number of tokens belonging to the preferred set in the text to be detected;
[0259] S204-C: Determine the watermark detection result of the text to be detected based on the watermark intensity of the text to be detected.
[0260] In this implementation, the electronic device obtains the ratio of the number of tokens included in the preferred selection set to the total number of tokens in the vocabulary, and then determines the watermark strength of the text to be detected based on the ratio and the number of tokens in the text to be detected that belong to the preferred selection set.
[0261] This application does not limit the specific method by which the electronic device determines the watermark strength of the text to be detected based on the ratio of the number of tokens included in the preferred selection set to the total number of tokens in the vocabulary, and the number of tokens in the text to be detected that belong to the preferred selection set.
[0262] In one possible implementation, the electronic device determines the product of the ratio of the number of tokens included in the preferred selection set to the total number of tokens in the vocabulary, and the number of tokens in the text to be detected that belong to the preferred selection set, and determines the watermark strength of the text to be detected by this product.
[0263] In one possible implementation, the electronic device multiplies the number of tokens included in the text to be detected by the ratio of the number of tokens included in the preferred set to the total number of tokens in the vocabulary to obtain a first product; subtracts the number of tokens in the text to be detected belonging to the preferred set from the first product to obtain a first difference; and determines the watermark strength of the text to be detected based on the first difference.
[0264] In one example, the electronic device determines the first difference as the watermark strength of the text to be detected.
[0265] In one example, the electronic device subtracts a preset value from the ratio of the number of tokens included in the preferred selection set to the total number of tokens in the vocabulary to obtain a second difference; multiplies the first product with the first value to obtain a second product; and determines the watermark strength of the text to be detected by the ratio of the nth root of the second product to the first difference, where n is a positive number.
[0266] For example, the electronic device determines the watermark intensity Z of the text to be detected according to the following formula (8):
[0267]
[0268] Where, n prior Let γ be the number of tokens in the text to be detected that belong to the preferred selection set, γ be the ratio of the number of tokens included in the preferred selection set to the total number of tokens in the vocabulary, N be the total number of tokens included in the text to be detected, γN be the first product, and n be the number of tokens in the vocabulary. prior -γN is the first difference, 1 is the preset value, 1-γ is the second difference, and γN(1-γ) is the second product, where n equals 2.
[0269] Based on the above steps, the electronic device determines the watermark strength of the text to be detected, and then determines the watermark detection result of the text to be detected based on the watermark strength.
[0270] Specifically, the watermark intensity of the text to be detected is compared with a preset threshold. If the watermark intensity of the text to be detected is greater than or equal to the preset threshold, it is determined that the text to be detected contains watermark information, that is, the text to be detected is generated by the language model. If the watermark intensity of the text to be detected is less than the preset threshold, it is determined that the text to be detected does not contain watermark information, that is, the text to be detected is not generated by the language model.
[0271] For example, the watermark detection process can be represented by the following formula (9):
[0272]
[0273] Among them, z thres This is a preset threshold.
[0274] The text watermark detection method provided in this application obtains the text to be detected and a vocabulary of a language model. The text to be detected includes N tokens. For the j-th token in the text to be detected, K tokens corresponding to the j-th token are selected from the N tokens. The semantic feature information of the K tokens is determined, and a random seed corresponding to the j-th token is determined based on the semantic feature information of the K tokens, where K is a positive integer greater than 1 and j is a positive integer from 1 to N. Based on the random seed, the vocabulary is divided into a preferred selection set and a non-preferred selection set to determine whether the j-th token belongs to the preferred selection set. The watermark detection result of the text to be detected is determined based on the number of tokens in the text to be detected that belong to the preferred selection set. Since the random seed in this application is determined based on the semantic feature information of the K tokens, the watermark in the text to be detected cannot be removed by simple replacement, rewriting, or other watermark attack methods without changing the semantic information of the text to be detected, thereby improving the robustness and accuracy of text watermark detection.
[0275] The foregoing provides an overall overview of the text watermarking and text watermark detection methods involved in the embodiments of this application. The following section provides further details using specific examples to illustrate these methods.
[0276] Figure 11 This is a flowchart illustrating a text watermarking and text watermark detection method provided in an embodiment of this application. Figure 12 This is a schematic diagram illustrating the framework of the text watermarking and text watermark detection methods in the embodiments of this application.
[0277] like Figure 11 and Figure 12As shown, the text watermarking and text watermark detection method of this application embodiment includes:
[0278] S301. Obtain the prompt words for the text to be generated and the vocabulary of the language model.
[0279] The prompt consists of M tokens, where M is a positive integer.
[0280] The specific implementation process of S301 can be referred to the relevant description of S101 above, and will not be repeated here.
[0281] S302. For the i-th token to be generated in the text to be generated, select T generated tokens from the current generated token sequence, and process the T generated tokens through the language model to obtain the probability distribution corresponding to the i-th token to be generated.
[0282] For example, from the currently generated token sequence, select the M+i-1 generated tokens before the i-th token to be generated, and use them as the T generated tokens.
[0283] The specific implementation process of S302 can be referred to the relevant description of S102 above, and will not be repeated here.
[0284] S303. Select K generated tokens from the current generated token sequence and determine the semantic feature information of the K generated tokens.
[0285] For example, from the currently generated token sequence, select the top K generated tokens that are closest to the i-th token to be generated, and use them as the K generated tokens.
[0286] S304. Based on the semantic feature information of K generated tokens, determine the target semantic feature cluster center among the preset R semantic feature cluster centers.
[0287] S305. Based on the preset key and the identification information of the target semantic feature cluster center, obtain the random seed corresponding to the i-th token to be generated.
[0288] The specific implementation process of S303 to S305 can be referred to the relevant description of S103 above, and will not be repeated here.
[0289] S306. Based on a random seed, the vocabulary is divided into a preferred selection set and a non-preferred selection set.
[0290] For example, obtain the ratio of the number of tokens included in the preferred selection set to the total number of tokens in the vocabulary; based on the ratio and a random seed, divide the vocabulary into a preferred selection set and a non-preferred selection set.
[0291] S307. Based on a preset bias value, increase the probability of tokens belonging to the preferred selection set in the probability distribution to obtain the adjusted probability distribution.
[0292] S308. Adjust the probabilities in the probability distribution based on the random seed, and determine the target token corresponding to the i-th token to be generated in the vocabulary based on the adjusted probability distribution.
[0293] S309. Determine whether i is equal to n.
[0294] If i is less than n, then let i = i + 1 and return to the execution of step S302 above.
[0295] If i equals n, then execute step S310 as follows.
[0296] S310, Output the text with the watermark added.
[0297] The specific implementation process of S306 to S310 can be referred to the relevant description of S104 above, and will not be repeated here.
[0298] In this embodiment of the application, S301 to S310 above are text watermarking methods, which are executed by watermarking devices.
[0299] The text watermark detection method of this application embodiment will be described below with reference to steps S311 to S318. The execution subject is a watermark detection device.
[0300] S311. Obtain the vocabulary of the text to be detected and the language model.
[0301] The text to be detected includes N tokens, where N is a positive integer greater than 1.
[0302] The text to be detected can be the watermarked text generated in the above steps, where N equals n.
[0303] S312. For the j-th token in the text to be detected, select K tokens corresponding to the j-th token from N tokens, and determine the semantic feature information of the K tokens.
[0304] For example, from the N tokens that are preceding the j-th token, select the K tokens that are closest to the j-th token as the K tokens corresponding to the j-th token.
[0305] S313. Based on the semantic feature information of K tokens, determine the target semantic feature cluster center among the preset R semantic feature cluster centers.
[0306] S314. Based on the preset key and the identification information of the target semantic feature cluster center, obtain the random seed corresponding to the j-th token.
[0307] S315. Based on a random seed, the vocabulary is divided into a preferred selection set and a non-preferred selection set to determine whether the j-th token belongs to the preferred selection set.
[0308] S316. Determine if j is equal to N.
[0309] If j is less than N, then let j = j + 1 and return to execute step S311 above.
[0310] If j equals N, then the number of tokens in the text to be detected that belong to the preferred selection set.
[0311] S317. Determine the watermark strength of the text to be detected based on the number of tokens belonging to the priority selection set in the text to be detected and the ratio of the number of tokens included in the priority selection set to the total number of tokens in the vocabulary.
[0312] For example, multiply the number of tokens included in the text to be detected by the proportion to obtain the first product; subtract the number of tokens in the text to be detected that belong to the preferred selection set from the first product to obtain the first difference; and determine the watermark strength of the text to be detected based on the first difference.
[0313] S318. Based on the watermark intensity of the text to be detected, determine the watermark detection result of the text to be detected.
[0314] If the watermark strength of the text to be detected is greater than or equal to the preset threshold, then the text to be detected is determined to be text generated by the language model.
[0315] If the watermark strength of the text to be detected is less than the preset threshold, then it is determined that the text to be detected is not generated by the language model.
[0316] The text watermarking and detection method provided in this application involves obtaining prompt words for the text to be generated and a vocabulary of a language model. The prompt words include M tokens. For the i-th token to be generated in the text, T generated tokens are obtained from the currently generated token sequence. The language model processes these T generated tokens to obtain the probability distribution corresponding to the i-th token to be generated. The currently generated tokens include the M tokens and the generated tokens of the text to be generated. The probability distribution includes the probability that each token in the vocabulary is selected as the i-th token to be generated. Next, K generated tokens are selected from the currently generated token sequence, and the semantic feature information of the K generated tokens is determined, where K is a positive integer greater than 1. Based on the semantic feature information of the K generated tokens, a random seed corresponding to the i-th token to be generated can be determined. Then, the probabilities in the probability distribution are adjusted based on the random seed to obtain an adjusted probability distribution. Finally, based on the adjusted probability distribution, the target token corresponding to the i-th token to be generated in the vocabulary is determined, and the watermarked text is obtained based on the target token. Therefore, in this embodiment, the random seed is determined using the semantic features of K generated tokens. The probability distribution is then adjusted based on this random seed, and the words corresponding to the tokens in the text to be generated are obtained from the adjusted probability distribution, ultimately resulting in watermarked text. Since the watermarked text does not change its semantics, simple word replacement cannot remove the watermark information, thus improving the robustness of the watermark added to the text generated by the language model. In subsequent watermark detection, the random seed can be determined based on the semantic features of the K tokens, and the watermark information in the text can be accurately identified based on this random seed, thereby determining whether the text to be detected is generated by the language model and improving the accuracy of identifying text generated by the language model.
[0317] The above text combined Figures 2 to 12 The method embodiments of this application are described in detail below, in conjunction with... Figure 13 The following describes in detail the device embodiments of this application.
[0318] Figure 13 This is a schematic block diagram of a text watermarking device provided in an embodiment of this application.
[0319] like Figure 13 As shown, the text watermark adding device 10 includes:
[0320] The acquisition unit 11 is used to acquire the prompt words of the text to be generated and the vocabulary of the language model. The prompt words include M tokens, where M is a positive integer.
[0321] The probability determination unit 12 is used to select T generated tokens from the currently generated token sequence for the i-th token to be generated in the text to be generated, and process the T generated tokens through the language model to obtain the probability distribution corresponding to the i-th token to be generated. The currently generated tokens include the M tokens and the generated tokens of the text to be generated. The probability distribution includes the probability that each token in the vocabulary is selected as the i-th token to be generated. T and i are both positive integers.
[0322] The random seed determination unit 13 is used to select K generated tokens from the currently generated token sequence, determine the semantic feature information of the K generated tokens, and determine the random seed corresponding to the i-th token to be generated based on the semantic feature information of the K generated tokens, where K is a positive integer greater than 1.
[0323] The watermarking unit 14 is used to adjust the probability in the probability distribution based on the random seed, so as to determine the target token corresponding to the i-th token to be generated in the vocabulary based on the adjusted probability distribution, and then obtain the watermarked text based on the target token.
[0324] In some embodiments, the random seed determination unit 13 is specifically used to determine a target semantic feature cluster center from among a preset R semantic feature cluster centers based on the semantic feature information of the K generated tokens. The R semantic feature cluster centers are obtained by clustering the semantic feature information of a preset P statements, where R is a positive integer greater than 1 and P is a positive integer greater than R. Based on the identification information of the target semantic feature cluster center, the random seed corresponding to the i-th token to be generated is determined.
[0325] In some embodiments, the random seed determination unit 13 is specifically used to determine the distance between the semantic feature information of the K generated tokens and the semantic feature cluster center for each of the R semantic feature cluster centers; and to determine the target semantic feature cluster center from the R semantic feature cluster centers based on the distance.
[0326] In some embodiments, the random seed determination unit 13 is specifically used to obtain the random seed corresponding to the i-th token to be generated based on the preset key and the identification information of the target semantic feature clustering center.
[0327] In some embodiments, the random seed determination unit 13 is specifically used to determine the product of the preset key and the identification information of the target semantic feature cluster center as the random seed corresponding to the i-th token to be generated.
[0328] In some embodiments, the random seed determination unit 13 is specifically used to select the top K generated tokens that are closest to the i-th token to be generated from the currently generated token sequence as the K generated tokens.
[0329] In some embodiments, the watermark adding unit 14 is specifically used to divide the vocabulary into a preferred selection set and a non-preferred selection set based on the random seed; and to increase the probability of tokens belonging to the preferred selection set in the probability distribution based on a preset bias value, thereby obtaining the adjusted probability distribution.
[0330] In some embodiments, the watermarking unit 14 is specifically used to obtain the ratio of the number of tokens included in the preferred selection set to the total number of tokens in the vocabulary; based on the ratio and the random seed, the vocabulary is divided into the preferred selection set and the non-preferred selection set.
[0331] In some embodiments, the probability determination unit 12 is specifically used to select the M+i-1 generated tokens before the i-th token to be generated from the currently generated token sequence as the T generated tokens.
[0332] It should be understood that the device embodiments and method embodiments can correspond to each other, and similar descriptions can be referred to the method embodiments. To avoid repetition, further details will not be provided here. Specifically, Figure 13 The apparatus shown can perform the embodiments of the above-described method, and the foregoing and other operations and / or functions of each module in the apparatus are for implementing the embodiments of the above-described method, which will not be described in detail here for the sake of brevity.
[0333] Figure 14 This is a schematic block diagram of a text watermark detection device provided in an embodiment of this application.
[0334] like Figure 14 As shown, the text watermark detection device 20 includes:
[0335] The acquisition unit 21 is used to acquire the text to be detected and the vocabulary of the language model, wherein the text to be detected includes N tokens, and N is a positive integer greater than 1;
[0336] The random seed determination unit 22 is used to select K tokens corresponding to the j-th token from the N tokens for the j-th token in the text to be detected, determine the semantic feature information of the K tokens, and determine the random seed corresponding to the j-th token based on the semantic feature information of the K tokens, where K is a positive integer greater than 1 and j is a positive integer from 1 to N.
[0337] The set partitioning unit 23 is used to divide the vocabulary into a preferred selection set and a non-preferred selection set based on the random seed, so as to determine whether the j-th token belongs to the token in the preferred selection set;
[0338] The watermark detection unit 24 is used to determine the watermark detection result of the text to be detected based on the number of tokens in the text to be detected that belong to the preferred selection set.
[0339] In some embodiments, the random seed determination unit 22 is specifically used to determine a target semantic feature cluster center among a preset R semantic feature cluster centers based on the semantic feature information of the K tokens, wherein the R semantic feature cluster centers are obtained by clustering the semantic feature information of a preset P statements, where R is a positive integer greater than 1 and P is a positive integer greater than R; and to determine the random seed corresponding to the j-th token based on the identification information of the target semantic feature cluster center.
[0340] In some embodiments, the random seed determination unit 22 is specifically used to determine the distance between the semantic feature information of the K tokens and the semantic feature cluster center for each of the R semantic feature cluster centers; and to determine the target semantic feature cluster center from the R semantic feature cluster centers based on the distance.
[0341] In some embodiments, the random seed determination unit 22 is specifically used to obtain a preset key; and based on the preset key and the identification information of the target semantic feature clustering center, to obtain the random seed corresponding to the j-th token.
[0342] In some embodiments, the random seed determination unit 22 is specifically used to determine the product of the preset key and the identification information of the target semantic feature cluster center as the random seed corresponding to the j-th token.
[0343] In some embodiments, the watermark detection unit 24 is specifically used to obtain the ratio of the number of tokens included in the preferred selection set to the total number of tokens in the vocabulary; determine the watermark strength of the text to be detected based on the ratio and the number of tokens in the text to be detected that belong to the preferred selection set; and determine the watermark detection result of the text to be detected based on the watermark strength of the text to be detected.
[0344] In some embodiments, the watermark detection unit 24 is specifically configured to multiply the number of tokens included in the text to be detected by the ratio to obtain a first product; subtract the number of tokens belonging to the preferred selection set in the text to be detected from the first product to obtain a first difference; and determine the watermark strength of the text to be detected based on the first difference.
[0345] In some embodiments, the watermark detection unit 24 is specifically used to subtract a preset value from the ratio to obtain a second difference; multiply the first product by the first value to obtain a second product; and determine the ratio of the nth root of the second product to the first difference as the watermark intensity of the text to be detected, where n is a positive number.
[0346] In some embodiments, the watermark detection unit 24 is specifically used to determine that the text to be detected is text generated by the language model if the watermark intensity of the text to be detected is greater than or equal to a preset threshold; and to determine that the text to be detected is not text generated by the language model if the watermark intensity of the text to be detected is less than the preset threshold.
[0347] It should be understood that the device embodiments and method embodiments can correspond to each other, and similar descriptions can be referred to the method embodiments. To avoid repetition, further details will not be provided here. Specifically, Figure 14 The apparatus shown can perform the embodiments of the above-described method, and the foregoing and other operations and / or functions of each module in the apparatus are for implementing the embodiments of the above-described method, which will not be described in detail here for the sake of brevity.
[0348] The apparatus of this application embodiment has been described above from the perspective of functional modules in conjunction with the accompanying drawings. It should be understood that this functional module can be implemented in hardware, in software instructions, or in a combination of hardware and software modules. Specifically, the steps of the method embodiments in this application can be completed by integrated logic circuits in the processor's hardware and / or by software instructions. The steps of the method disclosed in this application embodiment can be directly embodied as being executed by a hardware decoding processor, or by a combination of hardware and software modules in the decoding processor. Optionally, the software module can reside in a mature storage medium in the art, such as random access memory, flash memory, read-only memory, programmable read-only memory, electrically erasable programmable memory, registers, etc. This storage medium is located in memory, and the processor reads information from the memory and, in conjunction with its hardware, completes the steps in the above method embodiments.
[0349] Figure 15 This is a schematic block diagram of an electronic device provided in an embodiment of this application. The electronic device may be the terminal device or server described above.
[0350] like Figure 15 As shown, the electronic device 40 may include:
[0351] The system includes a memory 41 and a processor 42. The memory 41 stores a computer program 43 and transfers the program code 43 to the processor 42. In other words, the processor 42 can retrieve and run the computer program 43 from the memory 41 to implement the methods described in the embodiments of this application.
[0352] For example, the processor 42 can be used to execute the steps in the above method according to the instructions in the computer program 43.
[0353] In some embodiments of this application, the processor 42 may include, but is not limited to:
[0354] General-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc.
[0355] In some embodiments of this application, the memory 41 includes, but is not limited to:
[0356] Volatile memory and / or non-volatile memory. Non-volatile memory can be read-only memory (ROM), programmable read-only memory (PROM), erasable programmable read-only memory (EPROM), electrically erasable programmable read-only memory (EEPROM), or flash memory. Volatile memory can be random access memory (RAM), which is used as an external cache. By way of example, but not limitation, many forms of RAM are available, such as Static RAM (SRAM), Dynamic RAM (DRAM), Synchronous DRAM (SDRAM), Double Data Rate SDRAM (DDR SDRAM), Enhanced Synchronous DRAM (ESDRAM), Synchronous Link DRAM (SLDRAM), and Direct Rambus RAM (DR RAM).
[0357] In some embodiments of this application, the computer program 43 may be divided into one or more modules, which are stored in the memory 41 and executed by the processor 42 to complete the page recording method provided in this application. The one or more modules may be a series of computer program instruction segments capable of performing specific functions, which describe the execution process of the computer program 43 in the electronic device.
[0358] like Figure 15 As shown, the electronic device 40 may further include:
[0359] Transceiver 44, which can be connected to processor 42 or memory 41.
[0360] The processor 42 can control the transceiver 44 to communicate with other devices; specifically, it can send information or data to other devices or receive information or data sent by other devices. The transceiver 44 may include a transmitter and a receiver. The transceiver 44 may further include antennas, and the number of antennas may be one or more.
[0361] It should be understood that the various components in the electronic device 40 are connected through a bus system, which includes a data bus, a power bus, a control bus, and a status signal bus.
[0362] According to one aspect of this application, a computer storage medium is provided that stores a computer program thereon, which, when executed by a computer, enables the computer to perform the methods of the above-described method embodiments. Alternatively, embodiments of this application also provide a computer program product containing instructions that, when executed by a computer, cause the computer to perform the methods of the above-described method embodiments.
[0363] According to another aspect of this application, a computer program product or computer program is provided, comprising computer instructions stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium and executes the computer instructions, causing the computer device to perform the method described in the above-described method embodiments.
[0364] In other words, when implemented using software, it can be implemented wholly or partially in the form of a computer program product. This computer program product includes one or more computer instructions. When these computer program instructions are loaded and executed on a computer, all or part of the processes or functions described in the embodiments of this application are generated. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another. For example, the computer instructions can be transmitted from one website, computer, server, or data center to another via wired (e.g., coaxial cable, fiber optic, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) means. The computer-readable storage medium can be any available medium that a computer can access or a data storage device such as a server or data center that integrates one or more available media. The available medium can be a magnetic medium (e.g., floppy disk, hard disk, magnetic tape), an optical medium (e.g., digital video disc (DVD)), or a semiconductor medium (e.g., solid-state disk (SSD)).
[0365] Those skilled in the art will recognize that the modules and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.
[0366] In the several embodiments provided in this application, it should be understood that the disclosed systems, apparatuses, and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative; for instance, the division of modules is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple modules or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be through some interfaces; the indirect coupling or communication connection between apparatuses or modules may be electrical, mechanical, or other forms.
[0367] The modules described as separate components may or may not be physically separate. The components shown as modules may or may not be physical modules; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs. For example, the functional modules in the various embodiments of this application may be integrated into one processing module, or each module may exist physically separately, or two or more modules may be integrated into one module.
[0368] The above description is merely a specific embodiment of this application, but the scope of protection of this application is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the scope of the technology disclosed in this application should be included within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.
Claims
1. A method for adding a text watermark, characterized in that, include: Obtain the prompt words for the text to be generated and the vocabulary of the language model. The prompt words include M tokens, where M is a positive integer. For the i-th token to be generated in the text to be generated, T generated tokens are selected from the currently generated token sequence, and the T generated tokens are processed by the language model to obtain the probability distribution corresponding to the i-th token to be generated. The currently generated tokens include the M tokens and the generated tokens of the text to be generated. The probability distribution includes the probability that each token in the vocabulary is selected as the i-th token to be generated. T and i are both positive integers. Select K generated tokens from the currently generated token sequence, determine the semantic feature information of the K generated tokens, and based on the semantic feature information of the K generated tokens, determine the target semantic feature cluster center from the preset R semantic feature cluster centers. Then, based on the identification information of the target semantic feature cluster center, determine the random seed corresponding to the i-th token to be generated. The R semantic feature cluster centers are obtained by clustering the semantic feature information of the preset P statements, where K is a positive integer greater than 1, R is a positive integer greater than 1, and P is a positive integer greater than R. The probabilities in the probability distribution are adjusted based on the random seed, and the target token corresponding to the i-th token to be generated in the vocabulary is determined based on the adjusted probability distribution. Then, based on the target token, the watermarked text is obtained.
2. The method according to claim 1, characterized in that, The step of determining the target semantic feature cluster center from among the preset R semantic feature cluster centers based on the semantic feature information of the K generated tokens includes: For each of the R semantic feature cluster centers, determine the distance between the semantic feature information of the K generated tokens and the semantic feature cluster center; Based on the distance, the target semantic feature cluster center is determined from the R semantic feature cluster centers.
3. The method according to claim 1, characterized in that, The step of determining the random seed corresponding to the i-th token to be generated based on the identifier information of the target semantic feature cluster center includes: Based on the preset key and the identifier information of the target semantic feature cluster center, the random seed corresponding to the i-th token to be generated is obtained.
4. The method according to claim 3, characterized in that, The random seed corresponding to the i-th token to be generated is obtained based on the preset key and the identifier information of the target semantic feature clustering center, including: The product of the preset key and the identifier information of the target semantic feature cluster center is determined as the random seed corresponding to the i-th token to be generated.
5. The method according to any one of claims 1-4, characterized in that, The step of selecting K generated tokens from the currently generated token sequence includes: From the currently generated token sequence, select the K generated tokens that are closest to the i-th token to be generated, and use them as the K generated tokens.
6. The method according to any one of claims 1-4, characterized in that, The adjustment of the probabilities in the probability distribution based on the random seed includes: Based on the random seed, the vocabulary is divided into a preferred selection set and a non-preferred selection set; Based on a preset bias value, the probability of tokens belonging to the preferred selection set in the probability distribution is increased to obtain the adjusted probability distribution.
7. The method according to claim 6, characterized in that, The process of dividing the vocabulary into a preferred selection set and a non-preferred selection set based on the random seed includes: Obtain the ratio of the number of tokens included in the preferred selection set to the total number of tokens in the vocabulary; Based on the ratio and the random seed, the vocabulary is divided into the preferred selection set and the non-preferred selection set.
8. The method according to claim 1, characterized in that, The step of selecting T generated tokens from the currently generated token sequence includes: From the currently generated token sequence, select the first M+i-1 generated tokens of the i-th token to be generated, and use them as the T generated tokens.
9. A text watermark detection method, characterized in that, include: Obtain the text to be detected and the vocabulary of the language model, wherein the text to be detected includes N tokens, where N is a positive integer greater than 1; For the j-th token in the text to be detected, select K tokens corresponding to the j-th token from the N tokens, determine the semantic feature information of the K tokens, and based on the semantic feature information of the K tokens, determine the target semantic feature cluster center among the preset R semantic feature cluster centers. Then, based on the identification information of the target semantic feature cluster center, determine the random seed corresponding to the j-th token. The R semantic feature cluster centers are obtained by clustering the semantic feature information of the preset P statements, where K is a positive integer greater than 1, j is a positive integer from 1 to N, R is a positive integer greater than 1, and P is a positive integer greater than R. Based on the random seed, the vocabulary is divided into a preferred selection set and a non-preferred selection set to determine whether the j-th token belongs to the preferred selection set. The watermark detection result of the text to be detected is determined based on the number of tokens belonging to the priority selection set in the text to be detected.
10. The method according to claim 9, characterized in that, The process of determining the watermark detection result of the text to be detected based on the number of tokens belonging to the priority selection set in the text to be detected includes: Obtain the ratio of the number of tokens included in the preferred selection set to the total number of tokens in the vocabulary; Based on the ratio and the number of tokens belonging to the preferred selection set in the text to be detected, the watermark strength of the text to be detected is determined. Based on the watermark intensity of the text to be detected, the watermark detection result of the text to be detected is determined.
11. The method according to claim 10, characterized in that, The process of determining the watermark strength of the text to be detected based on the ratio and the number of tokens belonging to the preferred selection set in the text to be detected includes: Multiply the number of tokens included in the text to be detected by the ratio to obtain the first product; Subtract the number of tokens belonging to the preferred selection set in the text to be detected from the first product to obtain the first difference; Based on the first difference, the watermark strength of the text to be detected is determined.
12. The method according to claim 11, characterized in that, Determining the watermark strength of the text to be detected based on the first difference includes: Subtract the preset value from the ratio to obtain the second difference; Multiply the first product by the first value to obtain the second product; The ratio of the nth root of the second product to the first difference is determined as the watermark strength of the text to be detected, where n is a positive number.
13. The method according to claim 10, characterized in that, The step of determining the watermark detection result of the text to be detected based on the watermark intensity includes: If the watermark strength of the text to be detected is greater than or equal to a preset threshold, then the text to be detected is determined to be text generated by the language model. If the watermark strength of the text to be detected is less than the preset threshold, then it is determined that the text to be detected is not the text generated by the language model.
14. A text watermark adding device, characterized in that, include: The acquisition unit is used to acquire the prompt words of the text to be generated and the vocabulary of the language model. The prompt words include M tokens, where M is a positive integer. The probability determination unit is used to select T generated tokens from the currently generated token sequence for the i-th token to be generated in the text to be generated, and process the T generated tokens through the language model to obtain the probability distribution corresponding to the i-th token to be generated. The currently generated tokens include the M tokens and the generated tokens of the text to be generated. The probability distribution includes the probability that each token in the vocabulary is selected as the i-th token to be generated. T and i are both positive integers. A random seed determination unit is used to select K generated tokens from the currently generated token sequence, determine the semantic feature information of the K generated tokens, and based on the semantic feature information of the K generated tokens, determine a target semantic feature cluster center from a preset set of R semantic feature cluster centers. Then, based on the identification information of the target semantic feature cluster center, determine the random seed corresponding to the i-th token to be generated. The R semantic feature cluster centers are obtained by clustering the semantic feature information of a preset set of P statements, where K is a positive integer greater than 1, R is a positive integer greater than 1, and P is a positive integer greater than R. The watermarking unit is used to adjust the probability in the probability distribution based on the random seed, so as to determine the target token corresponding to the i-th token to be generated in the vocabulary based on the adjusted probability distribution, and then obtain the watermarked text based on the target token.
15. A text watermark detection device, characterized in that, include: The acquisition unit is used to acquire the text to be detected and the vocabulary of the language model. The text to be detected includes N tokens, where N is a positive integer greater than 1. A random seed determination unit is used to select K tokens corresponding to the j-th token from N tokens for the j-th token in the text to be detected, determine the semantic feature information of the K tokens, and determine a target semantic feature cluster center from R preset semantic feature cluster centers based on the semantic feature information of the K tokens. Then, based on the identification information of the target semantic feature cluster center, determine the random seed corresponding to the j-th token. The R semantic feature cluster centers are obtained by clustering the semantic feature information of P preset sentences, where K is a positive integer greater than 1, j is a positive integer from 1 to N, R is a positive integer greater than 1, and P is a positive integer greater than R. A set partitioning unit is used to divide the vocabulary into a preferred selection set and a non-preferred selection set based on the random seed, so as to determine whether the j-th token belongs to the token in the preferred selection set; The watermark detection unit is used to determine the watermark detection result of the text to be detected based on the number of tokens in the text to be detected that belong to the preferred selection set.
16. An electronic device, characterized in that, Including processor and memory; The memory is used to store computer programs; The processor is configured to execute the computer program to implement the method as described in any one of claims 1 to 8 or 9 to 13.
17. A computer-readable storage medium, characterized in that, Used to store computer programs; The computer program causes the computer to perform the method as described in any one of claims 1 to 8 or 9 to 13.