Content detection method based on large language model generation based on sentence semantic watermarking
By injecting watermarks based on sentence semantics, a watermark model is constructed to covertly mark the content generated by the large language model, which solves the problems of watermark fragility and insufficient generalization ability in the existing technology, realizes efficient and accurate content detection and tracking, and enhances the security and credibility of the generated content.
Patent Information
- Application Number
- CN202510087710.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-01-20
- Publication Date
- 2025-09-19
- Estimated Expiration
- 2045-01-20
AI Technical Summary
Existing watermarking methods for generating content using large language models are vulnerable to text-level attacks, and sentence-level algorithms lack generalization capabilities, making it difficult to effectively detect and track the source of generated content in a changing text environment.
A method based on sentence semantics watermarking is adopted. By constructing a watermark model of encoder, decoder and code table, and using sentence semantic features to mark sentences, the covert watermark injection and detection of content generated by large language models are achieved.
Ensure that the watermark does not affect the naturalness and fluency of the text, has high robustness and accuracy, can still identify the watermark after multiple edits, reduce the false detection rate and missed detection rate, and provide traceability of content sources and copyright protection.
Smart Images

Figure CN119939544B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of information processing, and in particular to a method for detecting content generated by a large language model. Background Art
[0002] Large language models have demonstrated impressive generative capabilities and have been widely adopted in various applications, such as ChatGPT, Copilot, and Claude. As large language models gain traction in content generation, the potential risks associated with using generated content (e.g., misleading information and copyright issues) have become increasingly important. Text watermarking technology, which can be used for both information identification and copyright tracking, has become a hot topic in the application of large language models.
[0003] Text watermarking for large language models aims to embed implicitly identifiable information into generated content, with the design of "red" and "green" groups being a common example. Although greater progress has been made, existing methods still suffer from fragile watermarking capabilities and poor generalization capabilities. Specifically, existing vocabulary-level algorithms inject watermarks by constructing vocabulary tags. Since attacks on the sentence level of the watermarked text will replace text vocabulary and modify the text structure, methods that inject watermarks at the vocabulary level are unable to resist sentence-level attacks. Existing sentence-level algorithmic methods usually construct sentence tags based on the distance between the generated sentence and a predefined sentence tag anchor. Since the predefined sentence tag anchor requires the distribution of the content generated by the large language model to be obtained in advance, existing sentence-level algorithms suffer from weak out-of-distribution generalization capabilities. Summary of the Invention
[0004] The present invention aims to address the deficiencies of the above-mentioned prior art and proposes a method for detecting content generated by a large language model based on sentence semantic watermark injection. By injecting watermarks into the large language model through selecting sentences, the present invention aims to add invisible watermarks to the large language model, thereby enabling the content generated by the large language model to be quickly and accurately tested under various text attack conditions, effectively avoiding the harm caused by the content generated by the large language model.
[0005] In order to achieve the above-mentioned object, the present invention adopts the following technical solutions:
[0006] The present invention provides a method for detecting content generated by a large language model based on sentence semantic watermark injection, which comprises the following steps:
[0007] S1. Build and train a watermark model for determining sentence tags ;
[0008] S11. Get sentence dataset ,in, Represents the first sentence in the sentence dataset D A sentence, , Indicates the sentence in the dataset D A sentence, , express The number of sentences in
[0009] Will and Input is processed into the embedding model to obtain Embed and Embed ;
[0010] S12. Based on sentence semantics, construct a watermark model for determining sentence tags , including: encoder , code table and decoder , and and Process and obtain The reconstruction representation and The reconstruction representation ;
[0011] S13. Build watermark model The total loss function ;
[0012] S14, using the back propagation algorithm to train the watermark model , and calculate the overall loss function To update the model parameters until the overall loss function Until convergence, the trained watermark model is obtained ;
[0013] S2. Get the prompt text to be embedded in the watermark ,in, Indicates the i-th sentence in the prompt text, , Indicates prompt text The number of sentences in
[0014] S3. Mark the sentences generated by the large language model for use in prompt text Inject watermark into
[0015] S31. Define the current loop variable as t and initialize it ;
[0016] Get the tth sentence in the prompt text and use it as the sentence for the t-1th loop, denoted as ;
[0017] S32. Using the trained watermark model generate Mark ;
[0018] S33, will Set as random seed, so that the code table is The numbers of the n potential representations are divided into class A tags and class B tags;
[0019] S34, use the large language model to analyze the text of the first t-1 cycles Process and generate sentences for the tth cycle ;
[0020] S35. Using the trained watermark model generate Mark ;
[0021] S36, Judgment Whether it belongs to Class A tag, if yes, then return to S34 and execute sequentially, otherwise, execute S37;
[0022] S37, Order Assign to After that, return to S32 and execute sequentially until So far, the A-type marker is injected as a watermark into the sentences generated by the large language model, where T represents the number of sentences expected to be generated;
[0023] S4. Extract the tokens of each sentence in the text and verify whether the text is generated by the large language model;
[0024] S41. For a given new text ,make ;
[0025] S42, according to the process of S32 and S35 Process and judge Is the token of the t-th sentence in the sentence A a class token? If so, the counter is incremented by 1; otherwise, it is not counted.
[0026] S43, Order Assign to Then, return to S42 and execute sequentially until So far, the final count value is obtained;
[0027] S44, if the count value exceeds Half of the total number of sentences in Generate text for the large language model, otherwise, It’s not a large language model that generates text.
[0028] The method for generating content detection based on a large language model of sentence semantic watermark injection according to the present invention is also characterized in that the encoder in S12 and decoder Both are composed of linear layers, code table By n d-dimensional potential representation Composition; among them, represents the kth potential representation, d represents the dimension of each potential representation, and n represents the code table The number of potential representations in ;
[0029] S121, will and Input to the encoder Processed in potential representation of and potential representation of ;
[0030] S122, using formula (1) to identify the code table Zhongyu The closest potential representation and with The closest potential representation , and the corresponding numbers i and j are respectively Sentences The mark and Sentences Mark;
[0031] (1)
[0032] S123, will and Input to the decoder Processed in The reconstruction representation and The reconstruction representation .
[0033] Furthermore, the S13 includes:
[0034] S131. Use formula (2) to construct a semantic loss function that captures the semantics of text embedding :
[0035] (2)
[0036] In formula (2), represents the weight coefficient, Indicates stopping the gradient operator;
[0037] S132. Use formula (3) to construct semantic consistency loss function :
[0038] (3)
[0039] In formula (3), represents the threshold value, Represents similarity calculation, Indicates taking the maximum value, represents the indicator function;
[0040] S133. Use formula (4) to construct the total loss function :
[0041] (4)
[0042] In formula (4), Represents the weight coefficient.
[0043] An electronic device of the present invention includes a memory and a processor, wherein the memory is used to store a program that supports the processor to execute the method, and the processor is configured to execute the program stored in the memory.
[0044] The present invention provides a computer-readable storage medium having a computer program stored thereon, wherein the computer program executes the steps of the method when executed by a processor.
[0045] Compared with the prior art, the present invention has the following beneficial effects:
[0046] 1. This invention injects watermarks based on sentence semantics, using semantic features to mark sentences without significantly modifying the surface form of the text (such as vocabulary). This method not only hides the watermark within the text but also avoids disrupting the naturalness of the language, ensuring that the generated content remains highly readable and fluent. Furthermore, the semantically based watermarking mechanism is highly robust, retaining the watermark information even after multiple edits, transcoding, and other common transformations, thereby enhancing the watermark's practicality and stability.
[0047] 2. This invention uses a watermark model to semantically tag sentences, embedding the watermark during the text generation phase and verifying the uniqueness and specificity of the tag during the detection phase. This semantically based tagging mechanism offers high accuracy and significantly reduces false positives and missed detections. Therefore, this invention is suitable for large language model generation scenarios, enabling rapid identification and confirmation of content generated by large language models, providing strong technical support for content management and copyright protection.
[0048] 3. This invention achieves content traceability by injecting hidden watermarks into generated content, thereby effectively reducing the risk of abuse. By detecting watermarks, the source of content generation can be identified, responsibility can be clearly determined, and a basis for identifying potential abuse can be provided. The detection mechanism of this invention not only achieves accurate identification of abuse at the technical level, but also enhances the ability to regulate content generated by large language models at the social level, providing a guarantee for building a trustworthy generated content ecosystem. BRIEF DESCRIPTION OF THE DRAWINGS
[0049] Figure 1 This is a flow chart of the content detection method generated by a large language model based on sentence semantics watermark injection of the present invention. DETAILED DESCRIPTION
[0050] In this embodiment, a method for detecting content generated by a large language model based on sentence semantics watermarking is provided. The method marks sentences based on text semantics and injects watermarks by selecting sentences generated by a large language model. This method adds invisible watermarks to the content generated by the large language model, thereby verifying the source of the detected text and preventing the abuse of the content generated by the large language model. The method includes: constructing and training a watermark model for determining sentence markers, obtaining prompt text for generating watermarked text, marking sentences generated by the large language model to inject watermarks, extracting markers for each sentence in the text, and verifying whether the text is generated by the large language model. Specifically, Figure 1 As shown, the method includes:
[0051] S1. Build and train a watermark model for determining sentence tags ;
[0052] S11. Get sentence dataset ,in, Represents the first sentence in the sentence dataset D A sentence, , Indicates the sentence in the dataset D A sentence, , express The number of sentences in
[0053] Will and The input is processed into the embedding model, where the embedding model can use an existing pre-trained model, such as BGE-M3, to obtain Embed and Embed .
[0054] S12. Based on sentence semantics, construct a watermark model for determining sentence tags , including: encoder , code table and decoder , and and Process and obtain The reconstruction representation and The reconstruction representation ;
[0055] Among them, the encoder and decoder Both are composed of linear layers, code table By n d-dimensional potential representation Composition; among them, represents the kth potential representation, d represents the dimension of each potential representation, and n represents the code table The number of potential representations in , n and d can be set to 64 and 1000 respectively;
[0056] S121, will and Input to the encoder Processed in potential representation of and potential representation of ;
[0057] S122, using formula (1) to identify the code table Zhongyu The closest potential representation and with The closest potential representation , and the corresponding numbers i and j are respectively Sentences The mark and Sentences Mark;
[0058] (1)
[0059] S123, will and Input to the decoder Processed in The reconstruction representation and The reconstruction representation .
[0060] S13. Build watermark model The total loss function ;
[0061] S131. Use formula (2) to construct a semantic loss function that captures the semantics of text embedding :
[0062] (2)
[0063] In formula (2), Indicates the weight coefficient, which can be set to 0.25. Indicates stopping the gradient operator;
[0064] S132. Use formula (3) to construct semantic consistency loss function :
[0065] (3)
[0066] In formula (3), represents the threshold value, Indicates similarity calculation, such as cosine similarity, Indicates taking the maximum value, represents the indicator function;
[0067] S133. Use formula (4) to construct the total loss function :
[0068] (4)
[0069] In formula (4), Represents the weight coefficient.
[0070] S14, using the back propagation algorithm to train the watermark model , and calculate the overall loss function To update the model parameters until the overall loss function Until convergence, the trained watermark model is obtained .
[0071] S2. Obtaining a prompt text for generating a watermark text;
[0072] Get the prompt text to be embedded in the watermark ,in Indicates the i-th sentence in the prompt text, , Indicates prompt text The number of sentences in .
[0073] S3, mark the sentences generated by the large language model to inject watermarks;
[0074] S31. Define the current loop variable as t and initialize it ;
[0075] Get the tth sentence in the prompt text and use it as the sentence for the t-1th loop, denoted as ;
[0076] S32. Using the trained watermark model generate Mark ;
[0077] S33, will Set as random seed, so that the code table is The numbers of the n potential representations are divided into class A tags and class B tags, where class A tags can be represented as "green" tags and class B tags can be represented as "red" tags.
[0078] S34, use the large language model to analyze the text of the first t-1 cycles Process and generate sentences for the tth cycle ;
[0079] S35. Using the trained watermark model generate Mark ;
[0080] S36, Judgment Whether it belongs to Class A tag, if yes, then return to S34 and execute sequentially, otherwise, execute S37;
[0081] S37, Order Assign to After that, return to S32 and execute sequentially until So far, T represents the number of sentences expected to be generated, so that the A-type marker is injected into the text generation process of the large language model as a watermark.
[0082] S4. Extract the tokens of each sentence in the text and verify whether the text is generated by the large language model;
[0083] S41. For a given new text ,make ;
[0084] S42, according to the process of S32 and S35 Process and judge Is the token of the t-th sentence in the sentence A a class token? If so, the counter is incremented by 1; otherwise, it is not counted.
[0085] S43, Order Assign to Then, return to S42 and execute sequentially until So far, the final count value is obtained;
[0086] S44, if the count value exceeds Half of the total number of sentences in Generate text for the large language model, otherwise, It’s not a large language model that generates text.
[0087] In this embodiment, an electronic device includes a memory and a processor, wherein the memory is used to store a program that supports the processor to execute the above method, and the processor is configured to execute the program stored in the memory.
[0088] In this embodiment, a computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the above method are executed.
[0089] In summary, the present invention provides a method for detecting content generated by a large language model based on sentence semantic watermarking, which aims to solve the problem of difficulty in tracking and detecting generated content in the prior art. By constructing a watermark model, the candidate sentences generated by the large language model are semantically marked, thereby injecting a hidden watermark mark into the text. The present invention uses a semantic-level watermark injection method to ensure that the watermark has no effect on the naturalness and fluency of the text, while enhancing the concealment and anti-tampering capabilities of the watermark. The method completes watermark embedding in the text generation stage and verifies the source of the content by extracting sentence tags in the detection stage, with the characteristics of high efficiency, accuracy and reliability. The watermark embedding mechanism of the present invention is more flexible and can adapt to a variety of editing and transformation scenarios, significantly reducing the false detection rate and missed detection rate. In addition, by giving traceability to the content generated by the large language model, the present invention can effectively prevent content abuse and improve the security and credibility of the generated content. This technology is not only of great significance for protecting intellectual property rights and standardizing the use of generated content, but also provides a new solution for building a trusted artificial intelligence-generated content ecosystem.
Claims
1. A method for detecting content generated by a large language model based on sentence semantic watermarking, characterized in that: The following steps are involved: S1. Build and train a watermark model for determining sentence tags ; S11. Get sentence dataset ,in, Represents the first sentence in the sentence dataset D A sentence, , Indicates the sentence in the dataset D A sentence, , express The number of sentences in Will and Input is processed into the embedding model to obtain Embed and Embed ; S12. Based on sentence semantics, construct a watermark model for determining sentence tags , including: encoder , code table and decoder , and and Process and obtain The reconstruction representation and The reconstruction representation of ; The encoder in the S12 and decoder Both are composed of linear layers, code table Depend on n indivual d dimensional latent representation Composition; among them, Indicates the k A potential representation, d represents the dimensions of each latent representation, n Display code table The number of potential representations in ; S121, will and Input to the encoder Processed in potential representation of and potential representation of ; S122, using formula (1) to identify the code table Zhongyu The closest potential representation and with The closest potential representation , and the corresponding number i and j As the first Sentences The mark and Sentences Mark; (1) S123, will and Input to the decoder Processed in The reconstruction representation and The reconstruction representation ; S13. Build watermark model The total loss function ; S14, using the back propagation algorithm to train the watermark model , and calculate the overall loss function To update the model parameters until the overall loss function Until convergence, the trained watermark model is obtained ; S2. Get the prompt text to be embedded in the watermark ,in, Indicates the first i A sentence, , Indicates prompt text The number of sentences in S3, based on watermark model , marking the sentences generated by the large language model for use in prompt text Inject watermark into S4. For a given new text ,extract , and verify whether the text is generated by the large language model.
2. The method for detecting content generated by a large language model based on sentence semantic watermarking according to claim 1 is characterized in that: The S13 includes: S131. Use formula (2) to construct a semantic loss function that captures the semantics of text embedding : (2) In formula (2), represents the weight coefficient, Indicates stopping the gradient operator; S132. Use formula (3) to construct semantic consistency loss function : (3) In formula (3), represents the threshold value, Represents similarity calculation, Indicates taking the maximum value, represents the indicator function; S133. Use formula (4) to construct the total loss function : (4) In formula (4), Represents the weight coefficient.
3. The method for detecting content generated by a large language model based on sentence semantic watermarking according to claim 2 is characterized in that: The S3 includes: S31, define the current loop variable as t , and initialize ; Get the first t sentence and as the first t -1 cycle sentence, recorded as ; S32. Using the trained watermark model generate Mark ; S33, will Set as random seed, so that the code table is middle n The numbers of potential representations are divided into Class A tags and Class B tags; S34, using a large language model to t -1 loop of text Processing to generate t Second cycle sentence ; S35. Using the trained watermark model generate Mark ; S36, Judgment Whether it belongs to Class A tag, if yes, then return to S34 and execute sequentially, otherwise, execute S37; S37, Order Assign to After that, return to S32 and execute sequentially until So far, the A-class marker is injected as a watermark into the sentence generated by the large language model, where T Indicates the number of sentences expected to be generated.
4. The method for detecting content generated by a large language model based on sentence semantic watermarking according to claim 3 is characterized in that: The S4 includes: S41, Order ; S42, according to the process of S32 and S35 Process and judge Middle t Is the tag of the sentence A a class tag? If so, the counter is incremented by 1; otherwise, no count is done. S43, Order Assign to Then, return to S42 and execute sequentially until So far, the final count value is obtained; S44, if the count value exceeds Half of the total number of sentences in Generate text for the large language model, otherwise, It’s not a large language model that generates text.
5. An electronic device comprising a memory and a processor, characterized in that: The memory is used to store a program that supports the processor to execute the large language model generated content detection method described in any one of claims 1-4, and the processor is configured to execute the program stored in the memory.
6. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method for detecting content generated by a large language model according to any one of claims 1 to 4 are executed.
Citation Information
Patent Citations
Machine learning based models for labelling text data
CA3237882A1
Method and device for embedding and detecting watermark in document by using computer system
CN101957810A
Cited By
Language model multi-bit embedding-based imperceptible layered watermark embedding method
CN121997303A
Imperceptible hierarchical watermarking embedding method based on language model multi-bit embedding
CN121997303B