Text watermark adding and detecting method and device, equipment and storage medium

The method of determining the target token using random seeds to adjust the probability distribution in the text generated by the language model solves the problem of poor watermark robustness in existing texts and achieves higher watermark recognition accuracy.

CN119598427AActive Publication Date: 2025-03-11TENCENT TECHNOLOGY (SHENZHEN) CO LTD

Patent Information

Application Number
CN202411646775.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-11-15
Publication Date
2025-03-11
Estimated Expiration
2044-11-15

AI Technical Summary

Technical Problem

The existing text watermark addition method has poor robustness and is easily removed through simple word replacement, resulting in the watermark information being unable to be detected.

Method used

By obtaining the prompt words of the text to be generated and the vocabulary list of the language model, using the language model to process the generated token sequence, random seeds are determined, and the probability distribution is adjusted based on the random seeds, and the target token is determined to add a watermark.

Benefits of technology

The robustness of text watermarks is improved, making the watermark information difficult to be removed, ensuring that the watermark can be accurately identified during subsequent detection, and improving the recognition accuracy of text generated by the language model.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119598427A_ABST
    Figure CN119598427A_ABST
Patent Text Reader

Abstract

The invention provides a text watermark adding and detecting method and device, equipment and a storage medium, and can be applied to various fields such as text creation. The method comprises the steps of obtaining cue words of a to-be-generated text and a word list of a language model; for the ith token to be generated of the text to be generated, T generated tokens are obtained from the current generated token sequence, the T generated tokens are processed through a language model, and probability distribution corresponding to the ith token to be generated is obtained; selecting K generated tokens from the current generated token sequence, determining semantic feature information of the K generated tokens, and determining a random seed corresponding to the ith to-be-generated token based on the semantic feature information of the K generated tokens; and adjusting the probability in the probability distribution based on the random seed, determining a target token of the i-th token to be generated based on the adjusted probability distribution, and obtaining a text added with a watermark based on the target token. According to the invention, the robustness of text watermark addition is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The embodiments of the present application relate to the field of computer technology, and in particular to a method, device, equipment and storage medium for adding and detecting a text watermark. Background Art

[0002] Large Language Models (LLMs) have attracted widespread attention due to their powerful expressive power in processing natural language and are used in various practical scenarios, including writing, reading assistance, and knowledge retrieval. At the same time, the surge in the use of large language models has raised concerns that large language models may be abused for malicious purposes. To address this issue, watermark information can be embedded in the content generated by the language model to ensure the identifiability of the generated content, thereby achieving generated content management.

[0003] However, the current text watermarking method has poor robustness. The watermark in the generated content can be removed by simple word replacement, which makes the watermark information undetectable and makes it impossible to accurately recognize the content generated by the language model. Summary of the invention

[0004] The present application provides a text watermark adding and detection method, apparatus, device and storage medium, which add watermark information that is not prone to abnormalities to content generated by a language model, thereby improving the robustness of text watermark adding.

[0005] In a first aspect, the present application provides a method for adding a text watermark, comprising:

[0006] Obtain prompt words of the text to be generated and a vocabulary of the language model, wherein the prompt words include M tokens, where M is a positive integer;

[0007] For the i-th token to be generated of 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 a probability distribution corresponding to the i-th token to be generated, wherein the currently generated tokens include the M tokens and the generated tokens of the text to be generated, and the probability distribution includes the probability of each token in the vocabulary being selected as the i-th token to be generated, and T and i are both positive integers;

[0008] Select K generated tokens from the currently generated token sequence, determine semantic feature information of the K generated tokens, and determine a 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 probability in the probability distribution is adjusted based on the random seed 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 the text with the watermark added is obtained based on the target token.

[0010] In a second aspect, the present application provides a text watermark detection method, comprising:

[0011] Obtain a text to be detected and a vocabulary of a 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 priority set and a non-priority set to determine whether the jth token belongs to a token in the priority set;

[0014] Based on the number of tokens in the text to be detected that belong to the priority selection set, a watermark detection result of the text to be detected is determined.

[0015] In a third aspect, the present application provides a text watermark adding device, comprising:

[0016] An acquisition unit, used for acquiring a prompt word of a text to be generated and a vocabulary of a language model, wherein the prompt word includes M tokens, where M is a positive integer;

[0017] A probability determination unit, for selecting T generated tokens from a currently generated token sequence for an i-th token to be generated of the text to be generated, and processing the T generated tokens through the language model to obtain a probability distribution corresponding to the i-th token to be generated, wherein the currently generated tokens include the M tokens and the generated tokens of the text to be generated, and the probability distribution includes the probability of each token in the vocabulary being selected as the i-th token to be generated, and T and i are both positive integers;

[0018] A random seed determination unit, configured to select K generated tokens from the currently generated token sequence, determine semantic feature information of the K generated tokens, and determine a 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] A watermark adding 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 text with the watermark added based on the target token.

[0020] In some embodiments, the random seed determination unit is specifically used to determine a target semantic feature clustering center among preset R semantic feature clustering centers based on the semantic feature information of the K generated tokens, wherein the R semantic feature clustering centers are obtained by clustering the semantic feature information of preset P sentences, 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 clustering center, determine the random seed corresponding to the i-th token to be generated.

[0021] In some embodiments, the random seed determination unit is specifically used to determine, for each of the R semantic feature cluster centers, the distance between the semantic feature information of the K generated tokens and the semantic feature cluster center; based on the distance, determine the target semantic feature cluster center from the R semantic feature cluster centers.

[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 configured to select the first K generated tokens 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 priority selection set and a non-priority selection set based on the random seed; based on a preset bias value, the probability of the tokens in the probability distribution belonging to the priority selection set is increased to obtain the adjusted probability distribution.

[0026] In some embodiments, the watermark adding unit is specifically used to obtain the ratio of the number of tokens included in the priority 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 priority selection set and the non-priority selection set.

[0027] In some embodiments, the probability determination unit is specifically configured to select the first M+i-1 generated tokens of the i-th token to be generated from the currently generated token sequence as the T generated tokens.

[0028] In a fourth aspect, the present application provides a text watermark detection device, comprising:

[0029] An acquisition unit, used for acquiring a text to be detected and a vocabulary of a language model, wherein the text to be detected includes N tokens, where N is a positive integer greater than 1;

[0030] A random seed determination unit, for a j-th token in the text to be detected, selecting K tokens corresponding to the j-th token from the N tokens, determining semantic feature information of the K tokens, and determining a 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, configured to partition the vocabulary into a priority selection set and a non-priority selection set based on the random seed, so as to determine whether the jth token belongs to a token in the priority 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 belonging to the priority selection set in the text to be detected.

[0033] In some embodiments, the random seed determination unit is specifically used to determine a target semantic feature clustering center among preset R semantic feature clustering centers based on the semantic feature information of the K tokens, wherein the R semantic feature clustering centers are obtained by clustering the semantic feature information of preset P sentences, 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 clustering center, determine the random seed corresponding to the j-th token.

[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; based on the distance, determine the target semantic feature cluster center from the R semantic feature cluster centers.

[0035] In some embodiments, the random seed determination unit is specifically used to obtain a preset key; based on the preset key and the identification information of the target semantic feature clustering center, 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 used to obtain the ratio of the number of tokens included in the priority selection set to the total number of tokens in the vocabulary; based on the ratio and the number of tokens in the text to be detected that belong to the priority selection set, determine the watermark strength of the text to be detected; based on the watermark strength of the text to be detected, determine the watermark detection result of the text to be detected.

[0038] In some embodiments, the watermark detection unit is specifically used 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 in the text to be detected that belong to the priority selection set 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 strength of the text to be detected, where n is a positive number greater than or equal to 0.

[0040] In some embodiments, the watermark detection unit is specifically used to determine that the text to be detected is the text generated by the language model if the watermark strength of the text to be detected is greater than or equal to a preset threshold; if the watermark strength of the text to be detected is less than the preset threshold, determine that the text to be detected is not the text generated by the language model.

[0041] In a fifth aspect, the present application provides an electronic device, comprising a processor and a memory, wherein the memory is used to store a computer program, and the processor is used to call and run the computer program stored in the memory to execute the method of the first aspect or the second aspect.

[0042] In a sixth aspect, a chip is provided for implementing the method in each implementation of the first aspect. Specifically, the chip includes: a processor for calling and running a computer program from a memory, so that a device equipped with the chip executes the method in the first or second aspect.

[0043] In a seventh aspect, a computer-readable storage medium is provided for storing a computer program, wherein the computer program enables a computer to execute the method of the first aspect or the second aspect.

[0044] In an eighth aspect, a computer program product is provided, comprising computer program instructions, wherein the computer program instructions enable a computer to execute the method of the first aspect or the second aspect.

[0045] In a ninth aspect, a computer program is provided, which, when executed on a computer, enables the computer to execute the method of the first aspect or the second aspect.

[0046] In summary, the present application obtains the prompt words of the text to be generated and the vocabulary of the language model, and the prompt words include M tokens; for the i-th token to be generated in the text to be generated, T generated tokens are obtained from the current 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, wherein the current generated tokens include M tokens and the generated tokens of the text to be generated, and the probability distribution includes the probability that each token in the vocabulary is selected as the i-th token to be generated. Then, K generated tokens are selected from the current generated token sequence, and the semantic feature information of the K generated tokens is determined, where K is a positive integer greater than 1. In this way, the random seed corresponding to the i-th token to be generated can be determined based on the semantic feature information of the K generated tokens, and then the probability in the probability distribution can be adjusted based on the random seed to obtain the 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 then the text with a watermark added is obtained based on the target token. It can be seen that in the embodiment of the present application, the random seed is determined by the semantic feature information of K generated tokens, so that the probability distribution is adjusted based on the random seed, and the vocabulary corresponding to the token to be generated in the text to be generated is obtained based on the adjusted probability distribution, and the text with the watermark added is finally generated. On the basis that the text with the watermark added does not change the text semantics, the watermark information in the text cannot be removed by simple vocabulary replacement, thereby improving the robustness of the watermark added to the text generated by the language model. In this way, during the subsequent watermark detection, the watermark in the text can be accurately identified, and then it can be determined that the text is the text generated by the language model, which can improve the recognition accuracy of the text generated by the language model. BRIEF DESCRIPTION OF THE DRAWINGS

[0047] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.

[0048] Figure 1 A schematic diagram of an implementation environment provided for an embodiment of the present application;

[0049] Figure 2 A flowchart of a method for adding a text watermark provided in one embodiment of the present application;

[0050] Figure 3A is an example graph of the currently generated token sequence corresponding to the i-th token to be generated;

[0051] Figure 3B is an example graph of T generated tokens corresponding to the i-th token to be generated;

[0052] Figure 4 A schematic diagram of the probability distribution corresponding to the i-th token to be generated;

[0053] Figure 5 A schematic diagram for selecting K generated tokens;

[0054] Figure 6 A schematic diagram for determining a random seed;

[0055] Figure 7 A schematic diagram for adjusting the probability distribution;

[0056] Figure 8 A schematic diagram for updating a currently generated token;

[0057] Fig. 9 A flowchart of a text watermark detection method provided in one embodiment of the present application;

[0058] Fig.10 A schematic diagram for selecting K tokens from N tokens included in the text to be detected;

[0059] Fig.11 A flowchart of a text watermark adding and text watermark detecting method provided in an embodiment of the present application;

[0060] Fig.12 A schematic diagram of the framework of the text watermark adding and text watermark detecting method in the embodiment of the present application;

[0061] Fig.13 is a schematic block diagram of a text watermark adding device provided in an embodiment of the present application;

[0062] Fig.14 is a schematic block diagram of a text watermark detection device provided by an embodiment of the present application;

[0063] Fig.15 It is a schematic block diagram of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0064] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of this application.

[0065] It should be noted that the terms "first", "second", etc. in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchanged where appropriate, so that the embodiments of the present application described here can be implemented in an order other than those illustrated or described here. In an embodiment of the present invention, "B corresponding to A" means that B is associated with A. In one implementation, B can be determined according to A. However, it should also be understood that determining B according to A does not mean that B is determined only according to A, but B can also be determined according to A and / or other information. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, system, product or server that includes a series of steps or units does not have to be limited to those steps or units that are clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices. In the description of the present application, unless otherwise specified, "multiple" refers to two or more than two.

[0066] The text watermark adding and detection method provided in the embodiment of the present application can be applied to various fields such as text creation and text detection. It can add watermark information that is not prone to abnormalities to the content generated by the language model, thereby improving the robustness of the text watermark adding.

[0067] Large Language Models (LLMs): A language model consisting of an artificial neural network with many parameters (typically billions of weights or more), trained on large amounts of unlabeled text using self-supervised or semi-supervised learning.

[0068] Large Language Model Watermark (LLM) refers to embedding watermark information that is imperceptible to users but detectable by algorithms in the content generated by the large language model, so that the content generated by the large language model can be subsequently identified through the watermark information.

[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 ability in processing natural language. At the same time, the surge in the use of language models has caused users to worry that language models may be abused for malicious purposes, such as false information. To solve this problem, existing solutions embed watermark information in the content generated by the language model to ensure the identifiability of the generated content, thereby achieving generated content management. However, the current technical solutions inevitably encounter robustness issues, and the watermark in the generated content can be removed by simply replacing words. As a result, it is impossible to accurately recognize the text generated by the language model.

[0070] In order to solve the above technical problems, the embodiment of the present application proposes a method for adding a text watermark, by obtaining a prompt word of the text to be generated and a vocabulary of a language model, the prompt word includes M tokens; for the i-th token to be generated of the text to be generated, T generated tokens are obtained from the current 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, wherein the current generated token includes M tokens and the generated tokens of the text to be generated, and the probability distribution includes the probability that each token in the vocabulary is selected as the i-th token to be generated. Then, K generated tokens are selected from the current generated token sequence, and the semantic feature information of the K generated tokens is determined, where K is a positive integer greater than 1. In this way, the random seed corresponding to the i-th token to be generated can be determined based on the semantic feature information of the K generated tokens, and then the probability in the probability distribution is adjusted based on the random seed to obtain the 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 then based on the target token, the text with the watermark added is obtained. It can be seen that in the embodiment of the present application, the random seed is determined by the semantic feature information of K generated tokens, so that the probability distribution is adjusted based on the random seed, and the vocabulary corresponding to the token to be generated in the text to be generated is obtained based on the adjusted probability distribution, and the text with the watermark added is finally generated. On the basis that the text with the watermark added does not change the text semantics, the watermark information in the text cannot be removed by simple vocabulary replacement, thereby improving the robustness of the watermark added to the text generated by the language model. In this way, during the subsequent watermark detection, the watermark in the text can be accurately identified, and then it can be determined that the text is the text generated by the language model, which can improve the recognition accuracy of the text generated by the language model.

[0071] The following introduces the implementation environment of the text watermark adding and detection method provided in the embodiment of the present application.

[0072] Figure 1 A schematic diagram of an implementation environment provided for an embodiment of the present application, such as Figure 1As shown, the implementation environment includes: the implementation environment includes: a terminal device 101 and a server 102.

[0073] The terminal device 101 is connected to the server 102 via a wired or wireless connection.

[0074] In some embodiments, the terminal device 101 is installed with a client of the text generation platform, and the server 102 can be understood as the server or backend of the text generation platform. An object (e.g., a user) can interact with the client through the terminal device 101, for example, inputting a prompt word of the text to be generated on the client. The server 102 can call a language model to generate text.

[0075] In some embodiments, during the process of adding a text watermark, the object can send the prompt word of the text to be generated to the server 102 through the terminal device 101. For example, the object starts the client of the text generation platform on the terminal device 101, and the client displays an input box for the prompt word. The object enters the prompt word in the input box. The prompt word is 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, etc., or the prompt word is an intention, and the text to be generated is a text that satisfies the intention. The terminal device 101 sends the prompt word entered by the object to the server 102. In response to the upload operation of the prompt word, the server 102 obtains the vocabulary of the language model, calls the language model, and generates the vocabulary corresponding to each token to be generated in the text to be generated based on the prompt word. Specifically, for the i-th token to be generated in the text to be generated, the server 102 obtains T generated tokens from the current sequence of generated tokens, and processes the T generated tokens through the language model to obtain the probability distribution corresponding to the i-th token to be generated, wherein the current generated tokens include M tokens and the generated tokens of the text to be generated, and the probability distribution includes the probability of each token in the vocabulary being selected as the i-th token to be generated. Next, the server 102 selects K generated tokens from the current sequence of generated tokens, and determines the semantic feature information of the K generated tokens, where K is a positive integer greater than 1. In this way, the server 102 can determine the random seed corresponding to the i-th token to be generated based on the semantic feature information of the K generated tokens, and then adjust the probability in the probability distribution based on the random seed to obtain the adjusted probability distribution. Finally, the server 102 determines the target token corresponding to the i-th token to be generated in the vocabulary based on the adjusted probability distribution. Next, the server 102 adds the target token corresponding to the i-th token to be generated to the end of the currently generated token sequence to obtain a new currently generated token sequence, and obtains the i+1th token to be generated from the new currently generated token sequence. Repeat the above steps for T generated tokens to generate the target token corresponding to the i+1th token to be generated in the text to be generated. Repeat the execution to finally obtain the text with the watermark added. In one example, the server 102 sends the text with the watermark added to the 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 jth token in the text to be detected, the server 102 determines the K tokens corresponding to the jth 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. Then, based on the semantic feature information of the K tokens, the server 102 determines the random seed corresponding to the jth token, and based on the random seed, divides the vocabulary into a priority selection set and a non-priority selection set to determine whether the jth token belongs to a token in the priority selection set. Repeating the execution, the server 102 can obtain the token data belonging to the priority selection set in the text to be detected, and then determine 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. 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 can be seen from the above, the random seed in the embodiment of the present application is determined by the semantic feature information of K generated tokens, so that the probability distribution is adjusted based on the random seed, and the vocabulary corresponding to the token to be generated in the text to be generated is obtained based on the adjusted probability distribution, and the text with the watermark added is finally generated. On the basis that the text with the watermark added does not change the text semantics, the watermark information in the text cannot be removed by simple vocabulary replacement, thereby improving the robustness of the watermark added to the text generated by the language model. In this way, during the subsequent watermark detection, the watermark in the text can be accurately identified, and then it can be determined that the text is the text generated by the language model, which can improve the recognition accuracy of the text generated by the language model.

[0078] In some embodiments, the text watermark adding method and the text watermark detecting method of the embodiments of the present application can be performed by the terminal device 101.

[0079] In some embodiments, the terminal device 101 includes but is not limited to: desktop computers, laptop computers, smart phones, tablet computers, IoT devices, and portable wearable devices. IoT devices can be smart speakers, smart TVs, smart air conditioners, smart car devices, etc. Portable wearable devices can be smart watches, smart bracelets, head-mounted devices, etc. Terminal devices are often equipped with display devices, which can also be displays, display screens, touch screens, etc., and touch screens can also be touch screens, touch panels, etc.

[0080] In some embodiments, the server 102 may be one or more servers. When there are multiple servers, there are at least two servers for providing different services, and / or there are at least two servers for providing the same service, such as providing the same service in a load balancing manner, which is not limited in the embodiments of the present application. Among them, the server may be an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, CDN (Content Delivery Network), and big data and artificial intelligence platforms. The server can also become a node of the blockchain.

[0081] It should be noted that the implementation environment of the embodiments of the present application includes but is not limited to Figure 1 shown.

[0082] The technical solutions of the embodiments of the present application are described in detail below through some embodiments. The following embodiments can be combined with each other, and the same or similar concepts or processes may not be repeated in some embodiments.

[0083] Figure 2 The flowchart of the text watermarking method provided in one embodiment of the present application is shown in FIG. The execution subject of the present application embodiment may be a device having a watermarking function, such as a watermarking device. The watermarking device may be the above-mentioned Figure 1 The server 102 or terminal device 101 shown may also be Figure 1 The server 102 and the terminal device 101 shown in the figure are composed of a system. For the convenience of description, the following embodiment takes an electronic device as an example to illustrate the method of the embodiment of the present application.

[0084] like Figure 2 As shown, the text watermark adding method of the embodiment of the present application includes:

[0085] S101, obtaining prompt words of a text to be generated and a vocabulary of a language model.

[0086] The prompt word includes M tokens, where M is a positive integer.

[0087] It should be noted that the method of obtaining data during the text watermarking process in the embodiment of the present application and the obtained data are in compliance with the provisions of relevant laws and regulations.

[0088] In an embodiment of the present application, a text with a watermark is generated by a language model so as to mark the text generated by the language model. First, the electronic device obtains a prompt word (Prompt) of the text to be generated. The prompt word is used to trigger the language model to generate the text to be generated. In other words, the prompt word is the input text that triggers the language model to generate the text to be generated.

[0089] In an example, the prompt word may be content requirement information of 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 may also be a question, so that the language model generates an answer to the question.

[0091] The prompt words of the embodiment of the present application include M tokens. A token refers to the smallest semantic unit in a text and is the smallest character unit processed by a language model. For example, a sentence can be divided into several words, each word being a token. For example, the sentence "i love you" can be divided into three tokens, namely "i", "love" and "you".

[0092] In the embodiment of the present application, after the electronic device obtains the prompt word of the text to be generated, it performs word segmentation processing on the prompt word, for example, using a word segmentation tool (such as a tokenizer in the NLP library) to segment the prompt word, so as to divide the prompt word into M tokens. The M tokens can be used as the initial input sequence of the language model.

[0093] The semantic model of the embodiment of the present application is a model for generating the text to be generated. The vocabularies of different language models may be the same or different. In the embodiment of the present application, when a certain language model is selected to generate the text to be generated, the vocabulary of the language model is obtained. Among them, the vocabulary of the language model includes a large number of tokens, and 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, T generated tokens are selected from the current generated token sequence, and the T generated tokens are processed through the language model to obtain the probability distribution corresponding to the i-th token to be generated.

[0095] Among them, the currently generated tokens include M tokens and the generated tokens of the text to be generated, the probability distribution includes the probability of each token in the vocabulary being selected as the i-th token to be generated, and 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 values ​​of T corresponding to different tokens to be generated may be different, for example, the value of T corresponding to the i+1th token to be generated in the text to be generated is greater than the value of T corresponding to the i-th token to be generated.

[0097] The language model in the embodiment of the present application may be a large language model, or may be any other language model that can generate text based on prompt words.

[0098] In the embodiment of the present application, when the language model generates each token in the text to be generated, the watermark adding method is performed on each token to generate the text with the watermark added. In some embodiments, it is also possible to inject watermarks into some tokens in the text to be generated to generate the text with the watermark added, which is not limited in the embodiment of the present application.

[0099] In an embodiment of the present application, 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 word (it should be noted that the M tokens included in the prompt word are all generated tokens). Then, the watermark adding method of the embodiment of the present application is performed using the selected T generated tokens to obtain the target token corresponding to the first token to be generated in the vocabulary, and the target token is used as the first generated token of the text to be generated. At the same time, after adding the first generated token to the above-mentioned M token sequences, for example, the first generated token is added to the end of the M token sequences to obtain the current generated token sequence. Then, the second token to be generated of the text to be generated is generated, T generated tokens are selected from the current generated token sequence, and the watermark adding method of the embodiment of the present application is performed using the selected T generated tokens to obtain the target token corresponding to the second token to be generated in the vocabulary, and the target token is used as the second generated token of the text to be generated. At the same time, after adding the second generated token to the above-mentioned current generated token sequence, a new current generated token sequence is obtained. Next, the third token to be generated of the text to be generated is generated, T generated tokens are selected from the new currently generated token sequence, and the watermark adding method of the embodiment of the present application is performed using the selected T generated tokens to obtain the target token corresponding to the third token to be generated in the vocabulary, and the target token is used as the third generated token of the text to be generated. At the same time, the third generated token is added to the above-mentioned new currently generated token sequence to obtain the latest currently generated token sequence. This is repeated until the last token of the text to be generated is generated.

[0100] As can be seen from the above, the electronic device in the embodiment of the present application generates the target token corresponding to each to-be-generated token in the vocabulary in the to-be-generated text in the same manner. For ease of description, the i-th to-be-generated token in the to-be-generated text is used as an example for explanation.

[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 to be generated, and the currently generated token sequence includes the M tokens included in the prompt word and the generated tokens in the text to be generated. 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, as well as the first generated token x1, the second generated token x2, ... the i-1th 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] The embodiment of the present application does not limit the specific manner in which the electronic device selects T generated tokens from the currently generated token sequence.

[0103] In one possible implementation, Figure 3A As shown, the electronic device can select the T generated tokens before the i-2th 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-2th generated token, the i-3th generated token, ..., the iT-1th generated token, these T generated tokens.

[0104] In one possible implementation, Figure 3A As shown, the electronic device can select the first T generated tokens 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-1th generated token, the i-2th generated token, the i-3th generated token, ..., the iTth generated token, these T generated tokens.

[0105] In a possible implementation, the electronic device may select all generated tokens before 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. 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-1th generated token, the i-2th generated token, the i-3th generated token, ..., the iTth generated token, and these M+i-1 generated tokens. That is to say, when the embodiment of the present application generates the i-th token to be generated of the text to be generated, the M tokens included in the prompt word and the i-1 generated tokens currently generated by the text to be generated are input into the language model for processing to obtain the probability distribution corresponding to the i-th token to be generated.

[0106] In a possible implementation, the electronic device may intermittently 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 interval of a generated token, and a total of T generated tokens are selected as the T generated tokens corresponding to the i-th token to be generated.

[0107] The embodiments of the present application do not limit the specific value of T mentioned above. In some examples, T is a positive integer, and in some examples, T is a positive integer greater than 1. In some examples, T is equal to 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 consistent. In some examples, for the tokens to be generated in the text to be generated, the number of T generated tokens corresponding to each token to be generated is not the same. In some examples, for the tokens to be generated in the text to be generated, the number of T generated tokens corresponding to some tokens to be generated is not the same, and 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 current generated token sequence, inputs these T generated tokens into the language model for processing, and obtains 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 expressed by the following formula (1):

[0110]

[0111] Among them, P i is the probability distribution corresponding to the i-th token to be generated, l is the length of the vocabulary of the language model, that is, the number of tokens included in the vocabulary. i 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 ) is the T generated tokens corresponding to the i-th token to be generated, and T is equal to 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, and T is equal to M.

[0112] For example, Figure 4 The figure shows the process of inputting the three generated tokens corresponding to the i-th token to be generated into the language model for processing when T is equal to 3, and obtaining the probability distribution corresponding to the i-th token to be generated. The probability distribution includes the probability of each token in the vocabulary being 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 corresponding to a certain token in the vocabulary, the greater the possibility that the token is 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] Wherein, K is a positive integer greater than 1.

[0115] It should be noted that the electronic device does not limit the specific execution order of the above S102 and S103. For example, for the i-th candidate generated token in the text to be generated, the electronic device may first select T generated tokens from the current generated token sequence and input them into the language model for processing to obtain the probability distribution corresponding to the i-th candidate generated token, and then select K generated tokens from the current generated token sequence, and determine the semantic feature information of the K generated tokens. For another example, the electronic device may also first select K generated tokens from the current generated token sequence, and determine the semantic feature information of the K generated tokens, and then select T generated tokens from the current generated token sequence and input them into the language model for processing to obtain the probability distribution corresponding to the i-th candidate generated token. For another example, the electronic device may select T generated tokens from the current generated token sequence and input them into the language model for processing to obtain the probability distribution corresponding to the i-th candidate generated token, while selecting K generated tokens from the current generated token sequence and determining the semantic feature information of the K generated tokens.

[0116] The following introduces the process of the electronic device selecting K generated tokens from the current generated token sequence.

[0117] The embodiment of the present application does not limit the specific manner in which the electronic device selects K generated tokens from the current generated token sequence.

[0118] In a possible implementation, the electronic device may randomly select K generated tokens from currently generated tokens as the K generated tokens corresponding to the i-th token to be generated.

[0119] In a possible implementation, the electronic device selects the first K generated tokens closest to the i-th token to be generated from the currently generated token sequence as the K generated tokens. 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 word, as well as the first generated token, the second generated token, and ... the i-1th generated token in the text to be generated. The electronic device generates the i-1th generated token x i-1 、The i-2th 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 a possible implementation, the electronic device may select the K generated tokens before the i-2th generated token in the current generated token sequence as the K generated tokens corresponding to the i-th token to be generated. At this time, the K generated tokens corresponding to the i-th token to be generated include: the i-2th generated token, the i-3th generated token, ..., the iK-1th generated token, these K generated tokens.

[0121] In a possible implementation, the electronic device may intermittently 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 interval of a generated token, and a total of K generated tokens are selected as the K generated tokens corresponding to the i-th token to be generated.

[0122] The embodiment of the present 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 the above T. In one example, K is equal to the above T. In one example, the above K is less than the above T.

[0123] In one example, the K generated tokens corresponding to the i-th token to be generated in this step may be all or part of the T generated tokens corresponding to the i-th token to be generated. For example, the K generated tokens are the T generated tokens, so that the electronic device only needs to make one selection from the current sequence of generated tokens.

[0124] In one possible implementation, the electronic device may select all 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 the embodiment of the present application, after the electronic device selects K generated tokens from the currently generated token sequence, it uses these K generated tokens as the input of the semantic hash SemHash to obtain the i-th token to be generated x i The corresponding random seed S i , the process can be expressed as shown in formula (2):

[0126] S i =SemHash(x i-K ,x i-K+1 ,…,x i-1 ,x i ) (2)

[0127] The following introduces a specific process of an electronic device generating 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 an embodiment of the present application, after the electronic device selects K generated tokens from the current generated token sequence, it extracts the semantic feature information of the K generated tokens. For example, the K generated tokens are input into a representation extractor to extract the semantic feature information of the K generated tokens.

[0129] Exemplarily, the process of extracting the semantic feature information of the K generated tokens can be expressed as the following formula (3):

[0130] e=Φ(x i-K ,x i-K+1 ,…,x i-1 ,x i ) (3)

[0131] Among them, e is 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] The embodiment of the present application does not limit the specific manner in which 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.

[0134] In some embodiments, the electronic device may input the semantic feature information of the K generated tokens into a classifier for classification based on the semantic feature information of the K generated tokens, where the semantic feature information is a vector, to obtain which category of the preset categories the sentence formed by the K generated tokens belongs to, and then obtain the classification results corresponding to the K generated tokens. Then, based on the index of the classification result (that is, the classification result is indexed in the preset classification list), the random seed corresponding to the i-th token to be generated is determined. For example, the electronic device determines the index of the classification result as the random seed corresponding to the i-th token to be generated. For another example, the electronic device determines the product of the index of the classification result and the preset key or other calculation 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 may 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 the K generated tokens, determine a target semantic feature cluster center among the preset R semantic feature cluster centers, where the R semantic feature cluster centers are obtained by clustering the semantic feature information of the preset P sentences, where R is a positive integer greater than 1, and P is a positive integer greater than R;

[0137] S103-B. Determine the random seed corresponding to the i-th token to be generated based on the identification information of the target semantic feature cluster center.

[0138] In this implementation, an embodiment of the present application sets up a representation space, which includes R semantic feature clustering centers. The R semantic feature clustering centers are obtained by clustering the semantic feature information of P preset sentences. For example, P sentences are selected from the sentences included in an existing data set, and the P sentences can be all the sentences in the data set or part of the sentences in the data set. Then, semantic feature extraction is performed on each of the P sentences, for example, each sentence is input into a representation extractor for semantic feature extraction, and the semantic feature information of each of the P sentences is obtained.

[0139] Next, the semantic feature information of the P sentences is clustered. The embodiment of the present application does not limit the specific manner in which the electronic device clusters the semantic feature information of the P sentences to obtain R semantic feature clustering centers. In one possible implementation, the electronic device randomly selects R semantic feature information from the semantic feature information of the P sentences as R clustering centers. Next, the electronic device calculates the distance from the semantic feature information of each sentence in the P sentences to the R clustering centers, and assigns the semantic feature information of each sentence to the category represented by the nearest clustering center. According to the assignment result, the center point of each cluster is recalculated, usually by calculating the mean of the semantic feature information of all sentences in the class as the new clustering center. Repeat the above steps until the iteration termination condition is met, such as the center point no longer changes or the specified number of iterations is reached. Finally, R semantic feature clustering centers are obtained. It should be noted that these R semantic feature clustering centers are all vectors consistent with the dimensions of the semantic feature information.

[0140] For example, in the embodiment of the present application, the process of clustering the semantic feature information of P sentences to obtain R semantic feature clustering centers can be expressed as the following formula (4):

[0141]

[0142] Among them, Cluster(.) is the clustering equation, D is a data set consisting of P statements, Represents the semantic feature information of P sentences.

[0143] In this way, the electronic device can determine the target semantic feature cluster center among the preset R semantic feature cluster centers based on the semantic feature information of the K generated tokens.

[0144] The embodiment of the present application does not limit the specific method for the electronic device to determine the target semantic feature cluster center among the 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 respectively through a classifier to obtain classification results corresponding to each of the R semantic feature cluster centers. At the same time, the electronic device classifies the semantic feature information of the K generated tokens through the classifier to obtain classification results corresponding to the semantic feature information of the K generated tokens. Among the classification results corresponding to the R semantic feature cluster centers, a semantic feature cluster center that is 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 the K generated tokens. Specifically, the method includes the following steps S103-A1 and S103-A2:

[0147] S103-A1, for each of the R semantic feature clustering centers, determine the distance between the semantic feature information of the K generated tokens and the semantic feature clustering center;

[0148] S103-A2: Based on the distance, determine the target semantic feature cluster center from the R semantic feature cluster centers.

[0149] In this implementation, for each of the R semantic feature clustering centers, the electronic device determines the distance between the semantic feature information of the K generated tokens and each semantic feature clustering center. The embodiment of the present application does not limit the distance calculation method, which can be any method of calculating the distance between two vectors, such as the cosine distance calculation method. Then, based on the distance between the semantic feature information of the K generated tokens and each semantic feature clustering center, the target semantic feature clustering center corresponding to the i-th token to be generated is selected from the R semantic feature clustering centers.

[0150] The embodiment of the present application does not limit the specific manner in which the 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 determines the semantic feature cluster center with the smallest distance from 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. At this time, the specific process of the electronic device determining the target semantic feature cluster center corresponding to the i-th token to be generated can be expressed by the following formula (5):

[0152]

[0153] Among them, c′ is the target semantic feature information, c r represents the rth semantic feature clustering center among the R semantic feature clustering centers, dist(e,c r ) is the distance between the semantic feature information of the K generated tokens and the rth semantic feature clustering center.

[0154] In some embodiments, the electronic device may also determine the semantic feature cluster center among the R semantic feature cluster centers that has the second 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, etc. The embodiments of the present application do not impose any restrictions on this.

[0155] Based on the above steps, after 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, 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 may be any information that uniquely identifies the target semantic feature cluster center.

[0157] In an example, the identification information of the target semantic feature cluster center may be an index or identification of the target semantic feature cluster center in the list of R semantic feature cluster centers.

[0158] Next, the electronic device determines the random seed corresponding to the ith token to be generated based on the identification information of the target semantic feature cluster center corresponding to the ith token to be generated.

[0159] The embodiment of the present application does not limit the specific manner in 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 identification 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 identification for the watermark adding party to prevent other users from impersonating the watermark adding party to forge text. Optionally, the key can be randomly generated or input by the object. Then, based on the preset key and the identification information of the target semantic feature cluster center, the random seed corresponding to the i-th token to be generated is obtained.

[0162] The embodiment of the present application does not limit the specific manner in 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 a possible implementation, the electronic device adds the preset key and the identification information of the target semantic feature cluster center to obtain a random seed corresponding to the i-th token to be generated.

[0164] In a possible implementation, the electronic device multiplies the preset key and the identification information of the target semantic feature cluster center to obtain a random seed corresponding to the i-th token to be generated.

[0165] Exemplarily, 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] Among them, idx is the identification information of the target semantic feature clustering center corresponding to the i-th token to be generated, and Key is the preset key.

[0168] In the embodiment of the present application, when adding a watermark to the i-th token to be generated in the text to be generated, the random seed corresponding to the i-th token to be generated is generated by the semantic feature information of the K generated tokens corresponding to the i-th token to be generated. In this way, when the semantics of the generated text remains unchanged, the random seed cannot be changed by simple word replacement, and thus the watermark added to the text based on the random seed cannot be eliminated, thereby improving the reliability and robustness of the watermark addition.

[0169] A possible implementation of this step is introduced below by taking an example.

[0170] like Figure 6 As shown, it is assumed that the K generated tokens corresponding to the i-th token to be generated are 3 generated tokens, and the R semantic feature clustering centers are 4 semantic feature clustering centers. The 3 generated tokens are input into the representation extractor for semantic feature extraction to obtain the semantic feature information of the 3 generated tokens. The distance between the semantic feature information of the 3 generated tokens and each of the 4 semantic feature clustering centers is determined to obtain 4 distances. The semantic feature clustering center corresponding to the minimum distance among the 4 distances is determined as the target semantic feature clustering center corresponding to the i-th token to be generated. The index of the target semantic feature clustering center in the 4 semantic feature clustering centers is obtained, and then the index of the target semantic feature clustering center is 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 the electronic device determines the random seed corresponding to the i-th token to be generated, it executes the following step S104.

[0172] S104. Adjust the probability in the probability distribution based on the random seed 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 text with the watermark added based on the target token.

[0173] In an embodiment of the present application, when the electronic device generates the i-th token to be generated in the text to be generated, the electronic device predicts the probability of each token in the vocabulary of the language model being selected as the i-th token to be generated through the language model. And based on the above steps, the random seed corresponding to the i-th token to be generated is determined. Then, the electronic device uses the random seed to adjust part of the probability of each token in the vocabulary of the language model being selected as the i-th token to be generated (i.e., the probability distribution corresponding to the i-th token to be generated) predicted by the language model.

[0174] The embodiment of the present application does not limit the specific method of adjusting the probability in the probability distribution based on the random seed by the electronic device to obtain the adjusted probability distribution.

[0175] In some embodiments, the electronic device can adjust some of the probabilities in the above-mentioned probability distribution based on the parity of the random seed. For example, if the random seed is an odd number, the probability value of the token with an odd unique identifier in the vocabulary of the language model in the probability distribution is increased or decreased, and the probability value of the token with an even unique identifier in the vocabulary of the language model in the probability distribution remains unchanged, to obtain an adjusted probability distribution. For another example, if the random seed is an even number, the probability value of the token with an even unique identifier in the probability distribution of the language model is increased or decreased, and the probability value of the token with an odd unique identifier in the vocabulary of the language model in the probability distribution remains unchanged, to obtain an adjusted probability distribution. For another example, if the random seed is an odd number, the probability value of the token with an even unique identifier in the probability distribution of the language model is increased or decreased, and the probability value of the token with an odd unique identifier in the vocabulary of the language model in the probability distribution remains unchanged, to obtain an adjusted probability distribution. For another example, if the random seed is an even number, the probability value of the token with an odd unique identifier in the vocabulary of the language model in the probability distribution is increased or decreased, and the probability value of the token with an even unique identifier in the vocabulary of the language model in the probability distribution remains unchanged, thereby obtaining an adjusted probability distribution.

[0176] In some embodiments, the adjusting of the probability in the probability distribution based on the random seed in S104 includes the following steps S104-A1 and S104-A2:

[0177] S104-A1, based on the random seed, dividing the vocabulary into a priority selection set and a non-priority selection set;

[0178] S104-A2. Based on a preset bias value, the probability of the tokens in the priority selection set in the probability distribution is increased to obtain an adjusted probability distribution.

[0179] In this implementation, the electronic device divides the vocabulary of the language model into a priority selection set and a non-priority selection set based on the random seed corresponding to the i-th token to be generated. Among them, the priority selection set and the non-priority selection set both include at least one token in the vocabulary, and the tokens included are different. That is to say, in the embodiment of the present application, 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 constituting the priority selection set and the other part constituting the non-priority selection set. Among them, the tokens in the priority selection set are more likely to be selected.

[0180] The embodiment of the present application does not limit the specific manner in which the electronic device divides the vocabulary into a priority selection set and a non-priority selection set based on a random seed.

[0181] In one possible implementation, the electronic device may divide the vocabulary of the language model into a priority selection set and a non-priority selection set based on the parity of the random seed. For example, if the random seed is an odd number, the tokens in the vocabulary of the language model whose unique identifiers are odd numbers are divided into the priority selection set, and the tokens in the vocabulary of the language model whose unique identifiers are even numbers are divided into the non-priority selection set. For another example, if the random seed is an even number, the tokens in the vocabulary of the language model whose unique identifiers are even numbers are divided into the priority selection set, and the tokens in the vocabulary of the language model whose unique identifiers are odd numbers are divided into the non-priority selection set. For another example, if the random seed is an odd number, the tokens in the vocabulary of the language model whose unique identifiers are even numbers are divided into the priority selection set, and the tokens in the vocabulary of the language model whose unique identifiers are odd numbers are divided into the non-priority selection set. For another example, if the random seed is an even number, tokens with odd-numbered unique identifiers in the language model vocabulary are divided into a priority selection set, and tokens with even-numbered unique identifiers in the language model vocabulary are divided into a non-priority selection set.

[0182] In a possible implementation, the electronic device obtains the ratio of the number of tokens included in the priority selection set to the total number of tokens in the vocabulary; and divides the vocabulary into a priority selection set and a non-priority selection set based on the ratio and the random seed.

[0183] The ratio of the number of tokens included in the set to the total number of tokens in the vocabulary is preferably selected as a default value or a value input for the object.

[0184] In this implementation, the electronic device prioritizes the ratio of the number of tokens included in the set to the total number of tokens in the vocabulary and a random seed to generate a mask value corresponding to each token in the vocabulary of the language model, and then divides the tokens in the vocabulary into a priority selection set and a non-priority selection set based on the mask value corresponding to each token in the vocabulary. For example, assuming that the vocabulary of the language model includes 10,000 tokens, the electronic device generates a 10,000-dimensional mask vector based on the ratio of the number of tokens included in the priority selection set to the total number of tokens in the vocabulary and a random seed, using a preset mask generation rule. The mask vector includes a mask value corresponding to each token in the 10,000 tokens included in the vocabulary, where the mask value is 1 or 0. If the mask value of the token is 1, it means that the token is divided into the priority selection set, and if the mask value of the token is 0, it means that the token is divided into the non-priority selection set. In this way, the electronic device can divide the tokens in the vocabulary into the priority selection set and the non-priority selection set based on the mask vector to obtain the priority selection set and the non-priority selection set.

[0185] Next, the above step S104-A2 is executed to increase the probability of the tokens in the priority selection set in the probability distribution based on the preset bias value to obtain an adjusted probability distribution.

[0186] In the embodiment of the present application, the electronic device increases the probability of tokens belonging to a priority selection set in a probability distribution based on a preset bias value, and the specific method of obtaining the adjusted probability distribution is not limited.

[0187] In one possible implementation, Figure 7 As shown, the electronic device adds the preset bias value δ to the probability of the tokens in the priority selection set in the probability distribution, and does not change the probability of the tokens in the non-priority selection set in the probability distribution, to obtain an adjusted probability distribution.

[0188] In one possible implementation, the electronic device subtracts the preset bias value δ from the probability of tokens in the non-priority selection set in the probability distribution, and does not change the probability of tokens in the priority selection set in the probability distribution, to obtain an adjusted probability distribution.

[0189] In an embodiment of the present application, the tokens belonging to the priority selection set in the adjusted probability distribution are more likely to be selected as the i-th token to be generated. In this way, 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 a token with the largest probability value in the vocabulary as the target token corresponding to the i-th token to be generated based on the adjusted probability distribution. For another example, the electronic device adjusts the probability distribution to determine a token with the second largest probability value in the vocabulary as the target token corresponding to the i-th token to be generated. The 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 the adjusted probability distribution. i The specific process can be expressed as shown in the following formula (7):

[0191] x i =sample(bias(P i ,Set prior ,δ)) (7)

[0192] Among them, sample(.) is the sampling function, P i is the probability distribution corresponding to the i-th token to be generated, bias(.) is the bias equation, δ is the preset bias value, Set prior To prioritize the set, bias(P i ,Set prior ,δ) represents the adjusted probability distribution corresponding to the i-th token to be generated.

[0193] The above introduces the specific process of the electronic device determining the target token corresponding to the i-th token to be generated in the text to be generated.

[0194] After the electronic device determines the target token corresponding to the i-th token to be generated based on the above steps, 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 is added to the end of the currently generated tokens to obtain a new currently generated token sequence. At the same time, it is determined whether the i-th generated token is the last token in the text to be generated. Assuming that the text to be generated includes n tokens, it is determined whether i is equal to n. If the i-th generated token is the last token in the text to be generated, that is, i is equal to n, it means that the generation process of the text to be generated is completed, and the text with the watermark added is output. Specifically, the M tokens belonging to the prompt word in the new currently generated token sequence are deleted to obtain the token sequence (x1, x2, x3...x n ) is the text with watermark added.

[0195] If the i-th generated token is not the last token in the text to be generated, that is, i is less than n, then the i+1th token to be generated in the text to be generated is generated. At this time, let i=i+1, return to execute the above step S102, select T generated tokens in the new current generated token sequence, and refer to the above steps to generate the target token corresponding to the i+1th token to be generated in the text to be generated. Repeat this until i is equal to n, and finally output the text with the watermark added. Many tokens in the text with the watermark added are tokens in the priority selection set, which is convenient for subsequent detection of watermark information.

[0196] The text watermarking method proposed in the embodiment of the present application is to obtain the prompt word of the text to be generated and the vocabulary of the language model, and the prompt word includes M tokens; for the i-th token to be generated in the text to be generated, T generated tokens are obtained from the current 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, wherein the current generated token includes M tokens and the generated tokens of the text to be generated, and the probability distribution includes the probability that each token in the vocabulary is selected as the i-th token to be generated. Then, K generated tokens are selected from the current generated token sequence, and the semantic feature information of the K generated tokens is determined, where K is a positive integer greater than 1. In this way, the random seed corresponding to the i-th token to be generated can be determined based on the semantic feature information of the K generated tokens, and then the probability in the probability distribution is adjusted based on the random seed to obtain the 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 then based on the target token, the text with the watermark added is obtained. It can be seen that in the embodiment of the present application, the random seed is determined by the semantic feature information of K generated tokens, so that the probability distribution is adjusted based on the random seed, and the vocabulary corresponding to the token to be generated in the text to be generated is obtained based on the adjusted probability distribution, and the text with the watermark added is finally generated. On the basis that the text with the watermark added does not change the text semantics, the watermark information in the text cannot be removed by simple vocabulary replacement, thereby improving the robustness of the watermark added to the text generated by the language model. In this way, during the subsequent watermark detection, the watermark in the text can be accurately identified, and then it can be determined that the text is the text generated by the language model, which can improve the recognition accuracy of the text generated by the language model.

[0197] The above text watermarking method is introduced. The following text watermarking detection method based on the above text watermarking method is introduced.

[0198] Fig. 9The flowchart of the text watermark detection method provided by an embodiment of the present application is shown in FIG. The execution subject of the embodiment of the present application may be a device having a watermark detection function, such as a watermark detection device. The watermark detection device may be the above-mentioned Figure 1 The server 102 or terminal device 101 shown may also be Figure 1 The server 102 and the terminal device 101 shown in the figure are composed of a system. For the convenience of description, the following embodiment takes an electronic device as an example to illustrate the method of the embodiment of the present application.

[0199] like Fig. 9 As shown, the text watermark detection method of the embodiment of the present application includes:

[0200] S201, obtaining prompt words of the text to be detected and a vocabulary of the language model.

[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 obtaining data during the text watermark detection process in the embodiment of the present application and the data obtained are in compliance with the provisions of relevant laws and regulations.

[0203] The purpose of the embodiment of the present application is to detect whether the text to be detected is the text generated by the language model. It can be seen from the above-mentioned text watermarking method that when the text is generated by the language model, the embodiment of the present application adds watermark information to the generated text. In this way, the electronic device can detect the watermark information of the text to be detected to determine whether the text to be detected is the text generated by the language model.

[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] Wherein, K is a positive integer greater than 1, and j is a positive integer from 1 to N.

[0206] In the embodiment of the present application, when the language model generates each token in the text to be generated, the watermark detection method is performed on each token to generate the text with the watermark added. Correspondingly, when the watermark information is detected for the text to be detected, the watermark detection is performed on each token in the text to be detected.

[0207] In the embodiment of the present application, the process of the electronic device performing watermark detection on each token in the text to be detected is basically the same. For the convenience of description, the jth token in the text to be detected is taken as an example for explanation.

[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] The embodiment of the present application does not limit the specific manner in which the electronic device selects K tokens corresponding to the j-th token from N tokens.

[0210] In a possible implementation, the electronic device may randomly select K tokens from N tokens as the K tokens corresponding to the j-th token.

[0211] In a possible implementation, the electronic device selects the first K tokens closest to the jth token from the token sequence located before the jth token in the N token sequences included in the text to be detected as the K tokens corresponding to the jth token. Fig.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, these K tokens.

[0212] In a possible implementation, the electronic device may select K tokens before the j-2th token in the N token sequence included in the text to be detected as the K tokens corresponding to the jth token. At this time, the K tokens corresponding to the jth token include: j-2th token, j-3th token, ..., jK-1th token, these K tokens.

[0213] In a possible implementation, the electronic device may intermittently select K tokens from the N token sequences included in the text to be detected as the K tokens corresponding to the jth token. For example, starting from the j-1th token in the N token sequence included in the text to be detected, a token is selected every other token, and a total of K tokens are selected as the K tokens corresponding to the jth 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 above-mentioned text watermark adding method, so that the random seeds generated at both ends (i.e., the watermark adding end and the watermark detection end) are consistent, thereby achieving accurate detection of the watermark information.

[0215] In the embodiment of the present application, the electronic device selects K tokens from the N tokens included in the file to be detected, and uses the K tokens as the input of the semantic hash SemHash to obtain the jth token x i The corresponding random seed S i , the process can be expressed as shown in formula (2).

[0216] The following introduces the specific process of the electronic device generating a random seed corresponding to the j-th token based on the K tokens corresponding to the j-th token.

[0217] In an embodiment of the present application, after the electronic device selects K tokens from the N tokens included in the file to be detected, the semantic feature information of the K tokens is extracted, for example, the K tokens are input into a representation extractor to extract the semantic feature information of the K tokens.

[0218] Next, the electronic device determines the random seed corresponding to the j-th token based on the semantic feature information of the K tokens.

[0219] The embodiment of the present application does not limit the specific manner in which the electronic device determines the random seed corresponding to the j-th token based on the semantic feature information of the K tokens.

[0220] In some embodiments, the electronic device may determine the random seed corresponding to the jth token through the following steps S202-A and S202-B:

[0221] S202-A, based on the semantic feature information of the K tokens, determine a target semantic feature cluster center among the preset R semantic feature cluster centers, where the R semantic feature cluster centers are obtained by clustering the semantic feature information of the preset P sentences, 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 target semantic feature cluster center.

[0223] In this implementation, an embodiment of the present application sets up a representation space, which includes R semantic feature clustering centers. The R semantic feature clustering centers are obtained by clustering the semantic feature information of P preset sentences. For example, P sentences are selected from the sentences included in an existing data set, and the P sentences can be all the sentences in the data set or part of the sentences in the data set. Then, semantic feature extraction is performed on each of the P sentences, for example, each sentence is input into a representation extractor for semantic feature extraction, and the semantic feature information of each of the P sentences is obtained.

[0224] Next, the semantic feature information of the P sentences is clustered to obtain R semantic feature clustering centers. It should be noted that the R semantic feature clustering centers are all vectors consistent with the dimensions of the semantic feature information.

[0225] In this way, the electronic device can determine the target semantic feature cluster center among the preset R semantic feature cluster centers based on the semantic feature information of the K tokens.

[0226] The embodiment of the present application does not limit the specific method of determining the target semantic feature cluster center among R semantic feature cluster centers based on the semantic feature information of K tokens of the electronic device.

[0227] In some embodiments, the electronic device determines the target semantic feature cluster center corresponding to the jth 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 the K tokens. Specifically, the steps S202-A1 and S202-A2 are as follows:

[0228] S202-A1, for each of the R semantic feature clustering centers, determining the distance between the semantic feature information of the K tokens and the semantic feature clustering center;

[0229] S202-A2: Based on the distance, determine the target semantic feature cluster center from the R semantic feature cluster centers.

[0230] In this implementation, for each of the R semantic feature clustering centers, the electronic device determines the distance between the semantic feature information of the K tokens and each semantic feature clustering center. The embodiment of the present application does not limit the distance calculation method, which can be any method of calculating the distance between two vectors, such as the cosine distance calculation method. Then, based on the distance between the semantic feature information of the K tokens and each semantic feature clustering center, the target semantic feature clustering center corresponding to the jth token is selected from the R semantic feature clustering centers.

[0231] The embodiment of the present application does not limit the specific manner in which the 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 determines a semantic feature cluster center among the R semantic feature cluster centers that has the smallest distance to the semantic feature information of the K tokens as the target semantic feature cluster center corresponding to the j-th token.

[0233] Based on the above steps, after the electronic device determines the target semantic feature cluster center corresponding to the j-th token from the R semantic feature cluster centers, the electronic device obtains identification information of the target semantic feature cluster center.

[0234] The identification information of the target semantic feature cluster center may be any information that uniquely identifies the target semantic feature cluster center.

[0235] In an example, the identification information of the target semantic feature cluster center may be an index or identification of the target semantic feature cluster center in the 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 adding party to prevent other users from impersonating the watermark adding party to forge text. The electronic device obtains a random seed corresponding to the jth token based on the preset key and the identification information of the target semantic feature cluster center.

[0238] In a possible implementation, the electronic device adds the preset key and the identification information of the target semantic feature cluster center to obtain a random seed corresponding to the j-th token.

[0239] In a possible implementation, the electronic device multiplies the preset key and the identification information of the target semantic feature cluster center to obtain a random seed corresponding to the j-th token.

[0240] In the embodiment of the present application, when watermark information detection is performed on the jth token in the text to be detected, the random seed corresponding to the jth token is generated through the semantic feature information of the K tokens corresponding to the jth token. In this way, when the semantics of the text to be detected remains unchanged, the random seed cannot be changed by simple word replacement, and the watermark added to the text based on the random seed cannot be eliminated, thereby improving the reliability and robustness of watermark detection.

[0241] The specific implementation process of the above S202 can refer to the relevant description of the above S103, which will not be repeated here.

[0242] After the electronic device determines the random seed corresponding to the j-th token based on the above steps, it executes the following step S203.

[0243] S203. Based on the random seed, divide the vocabulary into a priority selection set and a non-priority selection set to determine whether the jth token belongs to a token in the priority selection set.

[0244] In an embodiment of the present application, the electronic device divides the vocabulary of the language model into a priority selection set and a non-priority selection set based on the random seed corresponding to the j-th token. Among them, the priority selection set and the non-priority selection set both include at least one token in the vocabulary, and the tokens included are different. That is to say, in an embodiment of the present application, 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 constituting the priority selection set and the other part constituting the non-priority selection set. Among them, the tokens in the priority selection set are more likely to be selected.

[0245] The embodiment of the present application does not limit the specific manner in which the electronic device divides the vocabulary into a priority selection set and a non-priority selection set based on a random seed.

[0246] In a possible implementation, the electronic device obtains the ratio of the number of tokens included in the priority selection set to the total number of tokens in the vocabulary; and divides the vocabulary into a priority selection set and a non-priority selection set based on the ratio and the random seed.

[0247] The ratio of the number of tokens included in the set to the total number of tokens in the vocabulary is preferably selected as a default value or a value input for the object.

[0248] In this implementation, the electronic device prioritizes the ratio of the number of tokens included in the set to the total number of tokens in the vocabulary and a random seed to generate a mask value corresponding to each token in the vocabulary of the language model, and then divides the tokens in the vocabulary into a priority selection set and a non-priority selection set based on the mask value corresponding to each token in the vocabulary. For example, assuming that the vocabulary of the language model includes 10,000 tokens, the electronic device generates a 10,000-dimensional mask vector based on the ratio of the number of tokens included in the priority selection set to the total number of tokens in the vocabulary and a random seed, using a preset mask generation rule. The mask vector includes a mask value corresponding to each token in the 10,000 tokens included in the vocabulary, where the mask value is 1 or 0. If the mask value of the token is 1, it means that the token is divided into the priority selection set, and if the mask value of the token is 0, it means that the token is divided into the non-priority selection set. In this way, the electronic device can divide the tokens in the vocabulary into the priority selection set and the non-priority selection set based on the mask vector to obtain the priority selection set and the non-priority selection set.

[0249] Based on the above steps, the electronic device divides the vocabulary of the language model into a priority selection set and a non-priority selection set, and then determines whether the jth token in the text to be detected belongs to the token in the priority selection set. If the jth token belongs to the token in the priority selection set, the number of tokens in the text to be detected that belong to the priority selection set is increased by 1.

[0250] If the jth token is not the last token in the text to be detected, the j+1th token in the text to be detected is selected as the new jth token, and the above step S202 is returned to execute, the random seed corresponding to the new jth token is determined, and the vocabulary is divided into a priority selection set and a non-priority selection set according to the random seed, and it is determined whether the new jth token belongs to the priority selection set. In this way, the above steps are executed for each token in the text to be detected to obtain the number of tokens in the text to be detected that belong to the priority selection set. Then, the following step S204 is executed.

[0251] S204: Determine a 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 priority selection set.

[0252] Based on the above steps, after the electronic device determines the number of tokens in the text to be detected that belong to the priority selection set, it determines 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 priority selection set, that is, based on the number of tokens in the text to be detected that belong to the priority selection set, it determines whether the text to be detected includes watermark information, and further determines whether the text to be detected is a text generated by a language model.

[0253] The embodiment of the present application does not limit the specific manner in which the electronic device determines 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 priority selection set.

[0254] In some embodiments, if the number of tokens in the text to be detected that belong to the preferred selection set is greater than or equal to a preset threshold, it is determined that the text to be detected includes watermark information, that is, it is determined that the text to be detected is generated by a language model. If the number of tokens in the text to be detected that belong to the preferred selection set is less than the preset threshold, 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 is not generated by a language model.

[0255] In some embodiments, the ratio of the number of tokens in the text to be detected that belong to the preferred selection set to the total number of tokens N included in the text to be detected is determined, and then based on the ratio, the watermark detection result of the text to be detected is determined. 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 is 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 is not generated by a language model.

[0256] In some embodiments, the above S204 includes the following steps S204-A to S204-C:

[0257] S204-A, obtaining a ratio of the number of tokens included in the priority selection set to the total number of tokens in the vocabulary;

[0258] S204-B, determining 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 priority selection set;

[0259] S204-C, based on the watermark strength of the text to be detected, determine the watermark detection result of the text to be detected.

[0260] In this implementation, the electronic device obtains the ratio of the number of tokens included in the priority 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 priority selection set.

[0261] The embodiments of the present application do not limit the specific manner in 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 priority 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 priority selection set.

[0262] In one possible implementation, the electronic device determines the ratio of the number of tokens included in the priority selection set to the total number of tokens in the vocabulary and the product of the number of tokens in the text to be detected that belong to the priority selection set, and determines the product as the watermark strength of the text to be detected.

[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 priority selection 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 that belong to the priority selection 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 set to the total number of tokens in the vocabulary to obtain a second difference; multiplies the above-mentioned first product by the above-mentioned first numerical value to obtain a second product; and determines the ratio of the nth root of the second product to the first difference as the watermark strength of the text to be detected, where n is a positive number greater than or equal to 0.

[0266] Exemplarily, the electronic device determines the watermark strength Z of the text to be detected according to the following formula (8):

[0267]

[0268] Among them, n prior is the number of tokens in the text to be detected that belong to the preferred set, γ is the ratio of the number of tokens included in the preferred set to the total number of tokens in the vocabulary, N is the total number of tokens included in the text to be detected, γN is the first product, n prior -γN is the first difference, 1 is the preset value, 1-γ is the second difference, γN(1-γ) is the second product, where n is equal to 2.

[0269] After the electronic device determines the watermark strength of the text to be detected based on the above steps, it determines the watermark detection result of the text to be detected based on the watermark strength of the text to be detected.

[0270] Specifically, the watermark strength of the text to be detected is compared with a preset threshold. If the watermark strength of the text to be detected is greater than or equal to the preset threshold, it is determined that the text to be detected includes watermark information, that is, the text to be detected is a text generated by a language model; if the watermark strength of the text to be detected is less than the preset threshold, it is determined that the text to be detected does not include watermark information, that is, the text to be detected is not a text generated by a language model.

[0271] Exemplarily, the watermark detection process can be expressed as follows:

[0272]

[0273] Among them, z thres is the preset threshold.

[0274] The text watermark detection method provided in the embodiment of the present application obtains the vocabulary of the text to be detected and the language model, wherein the text to be detected includes N tokens; for the jth token in the text to be detected, K tokens corresponding to the jth token are selected from the N tokens, the semantic feature information of the K tokens is determined, and based on the semantic feature information of the K tokens, the random seed corresponding to the jth token is determined, 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 priority selection set and a non-priority selection set to determine whether the jth token belongs to a token in the priority selection set; based on the number of tokens in the text to be detected that belong to the priority selection set, the watermark detection result of the text to be detected is determined. Since the random seed of the embodiment of the present application is determined based on the semantic feature information of the K tokens, when the semantic information of the text to be detected does not change, the watermark in the text to be detected cannot be removed by simple watermark attack methods such as replacement and rewriting, thereby improving the detection robustness and accuracy of the text watermark.

[0275] The above is an overall introduction to the text watermark adding and text watermark detection methods involved in the embodiments of the present application. The following is a further introduction to the text watermark adding and text watermark detection methods involved in the embodiments of the present application with specific examples.

[0276] Fig.11 A flowchart of a method for adding a text watermark and detecting a text watermark provided in an embodiment of the present application. Fig.12 It is a schematic diagram of the framework of the text watermark adding and text watermark detection methods in the embodiments of the present application.

[0277] like Fig.11 and Fig.12As shown, the text watermark adding and text watermark detecting method of the embodiment of the present application includes:

[0278] S301, obtaining prompt words of the text to be generated and a vocabulary of the language model.

[0279] The prompt word includes M tokens, where M is a positive integer.

[0280] The specific implementation process of the above S301 can refer to the relevant description of the above S101, which will not be repeated here.

[0281] S302. For the i-th token to be generated in the text to be generated, T generated tokens are selected from the current generated token sequence, and the T generated tokens are processed 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 as the T generated tokens.

[0283] The specific implementation process of the above S302 can refer to the relevant description of the above S102, which will not be repeated here.

[0284] S303: Select K generated tokens from the current generated token sequence, and determine semantic feature information of the K generated tokens.

[0285] For example, from the current sequence of generated tokens, the first K generated tokens closest to the i-th token to be generated are selected as the K generated tokens.

[0286] S304: Based on the semantic feature information of the K generated tokens, determine a target semantic feature cluster center from 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 the above S303 to S305 can refer to the relevant description of the above S103, which will not be repeated here.

[0289] S306: Based on the random seed, divide the vocabulary into a priority selection set and a non-priority selection set.

[0290] For example, the ratio of the number of tokens included in the priority selection set to the total number of tokens in the vocabulary is obtained; based on the ratio and the random seed, the vocabulary is divided into a priority selection set and a non-priority selection set.

[0291] S307. Based on a preset bias value, the probability of the tokens in the priority selection set in the probability distribution is increased to obtain an adjusted probability distribution.

[0292] S308. Adjust the probability in the probability distribution based on the random seed to 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 i=i+1 is set and the process returns to execute the above step S302.

[0295] If i is equal to n, the following step S310 is executed.

[0296] S310: Output the text with the watermark added.

[0297] The specific implementation process of the above S306 to S310 can refer to the relevant description of the above S104, which will not be repeated here.

[0298] In the embodiment of the present application, the above S301 to S310 are a text watermark adding method, which is executed by a watermark adding device.

[0299] The text watermark detection method of the embodiment of the present application is introduced below in combination with steps S311 to S318, and its execution subject is a watermark detection device.

[0300] S311, obtaining 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 may be the text with a watermark added generated in the above steps, and N is equal to n in this case.

[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 tokens before the j-th token among the N tokens, the first K tokens closest to the j-th token are selected as the K tokens corresponding to the j-th token.

[0305] S313 . Based on the semantic feature information of the K tokens, determine a 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 clustering center, obtain the random seed corresponding to the j-th token.

[0307] S315. Based on the random seed, divide the vocabulary into a priority selection set and a non-priority selection set to determine whether the jth token belongs to a token in the priority selection set.

[0308] S316. Determine whether j is equal to N.

[0309] If j is less than N, set j=j+1 and return to execute the above step S311.

[0310] If j is equal to N, then the number of tokens in the text to be detected that belong to the priority selection set.

[0311] S317: Determine the watermark strength of the text to be detected based on the number of tokens in 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, the number of tokens included in the text to be detected is multiplied by the ratio to obtain a first product; the number of tokens in the text to be detected that belong to the priority selection set is subtracted from the first product to obtain a first difference; based on the first difference, the watermark strength of the text to be detected is determined.

[0313] S318. Determine a watermark detection result of the text to be detected based on the watermark strength of the text to be detected.

[0314] If the watermark strength of the text to be detected is greater than or equal to a preset threshold, it is determined that the text to be detected is a text generated by a language model;

[0315] If the watermark strength of the text to be detected is less than a preset threshold, it is determined that the text to be detected is not a text generated by a language model.

[0316] The text watermark adding and text watermark detection method provided by the embodiment of the present application, by obtaining the prompt word of the text to be generated and the vocabulary of the language model, the prompt word includes M tokens; for the i-th token to be generated in the text to be generated, T generated tokens are obtained from the current 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, wherein the current generated token includes M tokens and the generated tokens of the text to be generated, and the probability distribution includes the probability that each token in the vocabulary is selected as the i-th token to be generated. Then, K generated tokens are selected from the current generated token sequence, and the semantic feature information of the K generated tokens is determined, and K is a positive integer greater than 1. In this way, the random seed corresponding to the i-th token to be generated can be determined based on the semantic feature information of the K generated tokens, and then the probability in the probability distribution is adjusted based on the random seed to obtain the 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 then based on the target token, the text with the watermark added is obtained. It can be seen that in the embodiment of the present application, the random seed is determined by the semantic feature information of K generated tokens, so that the probability distribution is adjusted based on the random seed, and the vocabulary corresponding to the token to be generated in the text to be generated is obtained based on the adjusted probability distribution, and the text with the watermark added is finally generated. On the basis that the text with the watermark added does not change the semantics of the text, the watermark information in the text cannot be removed by simple vocabulary replacement, thereby improving the robustness of the watermark added to the text generated by the language model. In this way, during the subsequent watermark detection, the random seed can be determined based on the semantic feature information of the K tokens, and then the watermark information in the text can be accurately identified based on the random seed, and then it can be determined whether the text to be detected is the text generated by the language model, which can improve the recognition accuracy of the text generated by the language model.

[0317] Combination of the above Figures 2 to 12 , describes in detail the method embodiment of the present application, and the following is combined with Fig.13 , describe in detail the device embodiments of the present application.

[0318] Fig.13 It is a schematic block diagram of a text watermark adding device provided in an embodiment of the present application.

[0319] like Fig.13 As shown, the text watermark adding device 10 comprises:

[0320] An acquisition unit 11 is used to acquire a prompt word of a text to be generated and a vocabulary of a language model, wherein the prompt word includes M tokens, where M is a positive integer;

[0321] A probability determination unit 12 is used for selecting T generated tokens from the currently generated token sequence for the i-th token to be generated of the text to be generated, and processing the T generated tokens through the language model to obtain a probability distribution corresponding to the i-th token to be generated, wherein the currently generated tokens include the M tokens and the generated tokens of the text to be generated, and the probability distribution includes the probability of each token in the vocabulary being selected as the i-th token to be generated, and T and i are both positive integers;

[0322] A random seed determination unit 13, configured to select K generated tokens from the currently generated token sequence, determine semantic feature information of the K generated tokens, and determine a 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 watermark adding 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 text with the watermark added based on the target token.

[0324] In some embodiments, the random seed determination unit 13 is specifically used to determine a target semantic feature clustering center among preset R semantic feature clustering centers based on the semantic feature information of the K generated tokens, wherein the R semantic feature clustering centers are obtained by clustering the semantic feature information of preset P sentences, 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 clustering center, determine the random seed corresponding to the i-th token to be generated.

[0325] In some embodiments, the random seed determination unit 13 is specifically used to determine, for each of the R semantic feature clustering centers, the distance between the semantic feature information of the K generated tokens and the semantic feature clustering center; based on the distance, determine the target semantic feature clustering center from the R semantic feature clustering centers.

[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 cluster 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 configured to select the first K generated tokens 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 priority selection set and a non-priority selection set based on the random seed; based on a preset bias value, the probability of the tokens in the probability distribution belonging to the priority selection set is increased to obtain the adjusted probability distribution.

[0330] In some embodiments, the watermark adding unit 14 is specifically used to obtain the ratio of the number of tokens included in the priority 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 priority selection set and the non-priority selection set.

[0331] In some embodiments, the probability determination unit 12 is specifically configured to select 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 embodiment and the method embodiment may correspond to each other, and similar descriptions may refer to the method embodiment. To avoid repetition, they will not be described here. Specifically, Fig.13 The device shown can execute the embodiments of the above method, and the aforementioned and other operations and / or functions of each module in the device are respectively for realizing the embodiments of the above method, which will not be described in detail here for the sake of brevity.

[0333] Fig.14 It is a schematic block diagram of a text watermark detection device provided in an embodiment of the present application.

[0334] like Fig.14 As shown, the text watermark detection device 20 comprises:

[0335] An acquisition unit 21 is used to acquire a text to be detected and a vocabulary of a language model, wherein the text to be detected includes N tokens, where N is a positive integer greater than 1;

[0336] A random seed determination unit 22 is used for selecting, for a j-th token in the text to be detected, K tokens corresponding to the j-th token from the N tokens, determining semantic feature information of the K tokens, and determining a 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] A set partitioning unit 23, configured to partition the vocabulary into a priority selection set and a non-priority selection set based on the random seed, so as to determine whether the jth token belongs to a token in the priority 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 belonging to the priority selection set in the text to be detected.

[0339] In some embodiments, the random seed determination unit 22 is specifically used to determine a target semantic feature clustering center among preset R semantic feature clustering centers based on the semantic feature information of the K tokens, wherein the R semantic feature clustering centers are obtained by clustering the semantic feature information of preset P sentences, 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 clustering center, determine the random seed corresponding to the j-th token.

[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; based on the distance, determine the target semantic feature cluster center from the R semantic feature cluster centers.

[0341] In some embodiments, the random seed determination unit 22 is specifically used to obtain a preset key; based on the preset key and the identification information of the target semantic feature clustering center, 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 priority 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 priority 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 used 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 in the text to be detected that belong to the priority selection set 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 strength of the text to be detected, where n is a positive number greater than or equal to 0.

[0346] In some embodiments, the watermark detection unit 24 is specifically used to determine that the text to be detected is the text generated by the language model if the watermark strength of the text to be detected is greater than or equal to a preset threshold; if the watermark strength of the text to be detected is less than the preset threshold, determine that the text to be detected is not the text generated by the language model.

[0347] It should be understood that the device embodiment and the method embodiment may correspond to each other, and similar descriptions may refer to the method embodiment. To avoid repetition, they will not be described here. Specifically, Fig.14 The device shown can execute the embodiments of the above method, and the aforementioned and other operations and / or functions of each module in the device are respectively for realizing the embodiments of the above method, which will not be described in detail here for the sake of brevity.

[0348] The above describes the device of the embodiment of the present application from the perspective of the functional module in conjunction with the accompanying drawings. It should be understood that the functional module can be implemented in hardware form, can be implemented by instructions in software form, and can also be implemented by a combination of hardware and software modules. Specifically, the steps of the method embodiment in the embodiment of the present application can be completed by the hardware integrated logic circuit and / or software form instructions in the processor, and the steps of the method disclosed in the embodiment of the present application can be directly embodied as a hardware decoding processor to perform, or a combination of hardware and software modules in the decoding processor to perform. Optionally, the software module can be located in a mature storage medium in the field such as a random access memory, a flash memory, a read-only memory, a programmable read-only memory, an electrically erasable programmable memory, a register, etc. The storage medium is located in a memory, and the processor reads the information in the memory, and completes the steps in the above method embodiment in conjunction with its hardware.

[0349] Fig.15 It is a schematic block diagram of an electronic device provided in an embodiment of the present application, and the electronic device may be the above-mentioned terminal device or server.

[0350] like Fig.15 As shown, the electronic device 40 may include:

[0351] The memory 41 and the processor 42, the memory 41 is used to store the computer program 43 and transmit the program code 43 to the processor 42. In other words, the processor 42 can call and run the computer program 43 from the memory 41 to implement the method in the embodiment of the present application.

[0352] For example, the processor 42 may be configured to execute the steps in the above method according to the instructions in the computer program 43 .

[0353] In some embodiments of the present application, the processor 42 may include but is not limited to:

[0354] General-purpose processor, digital signal processor (DSP), application-specific integrated circuit (ASIC), field programmable gate array (FPGA) or other programmable logic device, discrete gate or transistor logic device, discrete hardware components, etc.

[0355] In some embodiments of the present application, the memory 41 includes but is not limited to:

[0356] Volatile memory and / or non-volatile memory. Among them, the non-volatile memory can be read-only memory (ROM), programmable ROM (PROM), erasable programmable read-only memory (EPROM), electrically erasable programmable read-only memory (EEPROM) or flash memory. The volatile memory can be random access memory (RAM), which is used as an external cache. By way of example and not limitation, many forms of RAM are available, such as static random access memory (SRAM), dynamic random access memory (DRAM), synchronous dynamic random access memory (SDRAM), double data rate synchronous dynamic random access memory (DDR SDRAM), enhanced synchronous dynamic random access memory (ESDRAM), synchronous link DRAM (SLDRAM), and direct RAM bus random access memory (DR RAM).

[0357] In some embodiments of the present 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 method for recording pages provided by the present application. The one or more modules may be a series of computer program instruction segments capable of completing specific functions, and the instruction segments are used to describe the execution process of the computer program 43 in the electronic device.

[0358] like Fig.15 As shown, the electronic device 40 may further include:

[0359] The transceiver 44 may be connected to the processor 42 or the memory 41 .

[0360] The processor 42 may control the transceiver 44 to communicate with other devices, specifically, to send information or data to other devices, or to receive information or data sent by other devices. The transceiver 44 may include a transmitter and a receiver. The transceiver 44 may further include an antenna, 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 via a bus system, wherein the bus system includes not only a data bus but also a power bus, a control bus and a status signal bus.

[0362] According to one aspect of the present application, a computer storage medium is provided, on which a computer program is stored, and when the computer program is executed by a computer, the computer can perform the method of the above method embodiment. In other words, the present application embodiment also provides a computer program product containing instructions, and when the instructions are executed by a computer, the computer can perform the method of the above method embodiment.

[0363] According to another aspect of the present application, a computer program product or computer program is provided, the computer program product or computer program includes computer instructions, the computer instructions are stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium, and the processor executes the computer instructions, so that the computer device executes the method of the above method embodiment.

[0364] In other words, when implemented using software, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the process or function according to the embodiment of the present application is generated in whole or in part. The computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions may be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer instructions may be transmitted from a website site, a computer, a server, or a data center by wired (e.g., coaxial cable, optical fiber, digital subscriber line (digital subscriber line, DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) mode to another website site, computer, server, or data center. The computer-readable storage medium may be any available medium that a computer can access or a data storage device such as a server or a data center that includes one or more available media integrated. The available medium may be a magnetic medium (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a digital video disc (digital video disc, DVD)), or a semiconductor medium (e.g., a solid state drive (solid state disk, SSD)), etc.

[0365] Those of ordinary skill in the art will appreciate that the modules and algorithm steps of each example 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 performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application.

[0366] In the several embodiments provided in the present application, it should be understood that the disclosed systems, devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of the module is only a logical function division. There may be other division methods in actual implementation, such as multiple modules or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or modules, which can be electrical, mechanical or other forms.

[0367] The modules described as separate components may or may not be physically separated, and the components displayed as modules may or may not be physical modules, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. For example, each functional module in each embodiment of the present application may be integrated into a processing module, or each module may exist physically separately, or two or more modules may be integrated into one module.

[0368] The above contents are only specific implementation methods of the present application, but the protection scope of the present application is not limited thereto. Any technician familiar with the technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.

Claims

1. A method for adding a text watermark, characterized in that: include: Obtain prompt words and a vocabulary of a language model for a text to be generated, wherein the prompt words include M tokens, where M is a positive integer; For the i-th token to be generated of 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 a probability distribution corresponding to the i-th token to be generated, wherein the currently generated tokens include the M tokens and the generated tokens of the text to be generated, and the probability distribution includes the probability of each token in the vocabulary being selected as the i-th token to be generated, and T and i are both positive integers; Select K generated tokens from the currently generated token sequence, determine semantic feature information of the K generated tokens, and determine a 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; The probability in the probability distribution is adjusted based on the random seed 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 the text with the watermark added is obtained based on the target token.

2. The method according to claim 1, characterized in that The determining, based on the semantic feature information of the K generated tokens, a random seed corresponding to the i-th token to be generated, comprises: Based on the semantic feature information of the K generated tokens, determine a target semantic feature cluster center among preset R semantic feature cluster centers, wherein the R semantic feature cluster centers are obtained by clustering the semantic feature information of preset P sentences, 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, a random seed corresponding to the i-th token to be generated is determined.

3. The method according to claim 2, characterized in that The determining of a target semantic feature clustering center among the preset R semantic feature clustering centers based on the semantic feature information of the K generated tokens includes: For each of the R semantic feature clustering centers, determining a distance between the semantic feature information of the K generated tokens and the semantic feature clustering center; Based on the distance, the target semantic feature cluster center is determined from the R semantic feature cluster centers.

4. The method according to claim 2, characterized in that: The determining, based on the identification information of the target semantic feature cluster center, a random seed corresponding to the i-th token to be generated includes: 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.

5. The method according to claim 4, characterized in that The obtaining, 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 includes: The product of the preset key and the identification information of the target semantic feature cluster center is determined as the random seed corresponding to the i-th token to be generated.

6. The method according to any one of claims 1 to 5, characterized in that: The selecting K generated tokens from the currently generated token sequence comprises: From the currently generated token sequence, the first K generated tokens closest to the i-th token to be generated are selected as the K generated tokens.

7. The method according to any one of claims 1 to 5, characterized in that: The adjusting the probability in the probability distribution based on the random seed comprises: Based on the random seed, the vocabulary is divided into a priority selection set and a non-priority selection set; Based on a preset bias value, the probability of the tokens in the priority selection set in the probability distribution is increased to obtain the adjusted probability distribution.

8. The method according to claim 7, characterized in that The dividing the vocabulary into a priority selection set and a non-priority selection set based on the random seed comprises: Obtaining a ratio of the number of tokens included in the priority 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 priority selection set and the non-priority selection set.

9. 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 as the T generated tokens.

10. A text watermark detection method, characterized in that: include: Obtain a text to be detected and a vocabulary of a 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 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; Based on the random seed, the vocabulary is divided into a priority set and a non-priority set to determine whether the jth token belongs to a token in the priority set; Based on the number of tokens in the text to be detected that belong to the priority selection set, a watermark detection result of the text to be detected is determined.

11. 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 number of tokens belonging to the priority selection set in the text to be detected comprises: Obtaining a ratio of the number of tokens included in the priority selection set to the total number of tokens in the vocabulary; Determining 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 set; Based on the watermark strength of the text to be detected, a watermark detection result of the text to be detected is determined.

12. The method according to claim 11, characterized in that The determining 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 priority selection set comprises: Multiplying the number of tokens included in the text to be detected by the ratio to obtain a first product; Subtracting the number of tokens in the to-be-detected text that belong to the priority selection set from the first product to obtain a first difference; Based on the first difference, the watermark strength of the text to be detected is determined.

13. The method according to claim 12, characterized in that The step of determining the watermark strength of the text to be detected based on the first difference comprises: Subtracting the preset value from the ratio to obtain a second difference; multiplying the first product by the first value to obtain a 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 greater than or equal to 0.

14. The method according to claim 11, characterized in that The step of determining a watermark detection result of the text to be detected based on the watermark strength of the text to be detected comprises: If the watermark strength of the to-be-detected text is greater than or equal to a preset threshold, determining that the to-be-detected text is a text generated by the language model; If the watermark strength of the text to be detected is less than the preset threshold, it is determined that the text to be detected is not the text generated by the language model.

15. A text watermark adding device, characterized in that: include: An acquisition unit, used for acquiring a prompt word of a text to be generated and a vocabulary of a language model, wherein the prompt word includes M tokens, where M is a positive integer; A probability determination unit, for selecting T generated tokens from a currently generated token sequence for an i-th token to be generated of the text to be generated, and processing the T generated tokens through the language model to obtain a probability distribution corresponding to the i-th token to be generated, wherein the currently generated tokens include the M tokens and the generated tokens of the text to be generated, and the probability distribution includes the probability of each token in the vocabulary being selected as the i-th token to be generated, and T and i are both positive integers; A random seed determination unit, configured to select K generated tokens from the currently generated token sequence, determine semantic feature information of the K generated tokens, and determine a 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; A watermark adding 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 text with the watermark added based on the target token.

16. A text watermark detection device, characterized in that: include: An acquisition unit, used for acquiring a text to be detected and a vocabulary of a language model, wherein the text to be detected includes N tokens, where N is a positive integer greater than 1; A random seed determination unit, for a j-th token in the text to be detected, selecting K tokens corresponding to the j-th token from the N tokens, determining semantic feature information of the K tokens, and determining a 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; A set partitioning unit, configured to partition the vocabulary into a priority selection set and a non-priority selection set based on the random seed, so as to determine whether the jth token belongs to a token in the priority 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 belonging to the priority selection set in the text to be detected.

17. An electronic device, characterized in that: including a processor and a memory; The memory is used to store computer programs; The processor is configured to execute the computer program to implement the method according to any one of claims 1 to 9 or 10 to 14.

18. A computer-readable storage medium, characterized in that: For storing computer programs; The computer program enables a computer to execute the method according to any one of claims 1 to 9 or 10 to 14 above.

Citation Information

Patent Citations

  • Text watermark mark generation and detection method based on biased output large language model

    CN117494081A

  • Text watermark embedding and detecting method based on model context learning

    CN118349970A

  • Robust watermark injection method of few-sample scene prompt learning pre-training language model

    CN118551352A

  • Watermark embedding and detecting method and device for large model generation text

    CN118608367A

  • Text watermark detection and watermark adding method, program product, equipment and medium

    CN118656810A

Cited By

  • Watermark adding method, watermark detection method and watermark adding model training method

    CN119962541A

  • Text processing method, computer equipment and medium

    CN120804324A

  • Text processing method, computer device and medium

    CN120804324B