Large model generation code watermark method based on equivalent semantic transformation, program, equipment and storage medium

By embedding watermarks in the code generated by large-model and using BCH encoding rules, the problem of insufficient flexibility and embedding efficiency of generating code watermarks in the prior art is solved, and efficient and reliable identification and traceability of code watermarks are achieved.

CN119783070APending Publication Date: 2025-04-08HARBIN ENG UNIV
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202411861759.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-17
Publication Date
2025-04-08

AI Technical Summary

Technical Problem

The existing large-model generation code watermarking methods have shortcomings in terms of robustness, embedding efficiency and model traceability, and it is difficult to effectively identify the generated code and its generation model.

Method used

The big model generated code watermark method based on equivalent semantic transformation is adopted. By designing conversion rules suitable for generating code, the watermark is embedded in the generated code with BCH encoding rules, and the abnormal watermark information is corrected using error correction code.

Benefits of technology

It achieves good robustness and embedding efficiency, can quickly extract watermarks while ensuring code quality, has cross-model compatibility and efficient watermark processing capabilities, ensuring traceability of generated codes.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119783070A_ABST
    Figure CN119783070A_ABST
Patent Text Reader

Abstract

The invention discloses a large model generation code watermarking method based on equivalent semantic transformation, a program, equipment and a storage medium, and belongs to the technical field of digital technology watermarking. According to the method, the equivalence principle of code semantic conversion is adopted, a conversion rule suitable for the generated code is designed, and the watermark is embedded into the generated code according to a certain coding rule by utilizing the rule. According to the method, the code generation model does not need to be retrained or finely adjusted, only the generated code needs to be post-processed, good cross-model compatibility is shown, and meanwhile, the watermark embedding efficiency is guaranteed. The method has the rapid watermark processing capacity, code watermark embedding can be completed in a short time, and the processing efficiency in practical application is greatly improved. Due to the fact that the equivalent semantic conversion mode is adopted, no negative influence is generated on the quality of the codes, and normal functions of the codes and readability of the codes are guaranteed.
Need to check novelty before this filing date? Find Prior Art

Description

Field of the Invention

[0001] The present invention belongs to the field of digital watermark technology, and in particular relates to a method, program, device and storage medium for generating code watermarks based on a large model of equivalent semantic conversion. Background Art

[0002] The development of large language models (LLMs) is an important milestone in artificial intelligence technology. Large models have promoted great progress in technology research and application in many fields. One of the major breakthroughs is to assist programmers in application development through code generation technology. At present, there are many efficient artificial intelligence models for code generation that are widely used, such as ChatGPT, StarCoder, and CodeT5+. Although artificial intelligence models can significantly improve programmers' programming efficiency, there is also the possibility of improper use. Researchers have demonstrated how to use the code generated by ChatGPT to build ransomware. In addition, the generated code may have potential security vulnerabilities. Therefore, it is very important to determine whether a specific code is generated code and further track the model that generated the code, that is, the generated code should be traceable.

[0003] Most existing methods for detecting AI-generated content focus on images and text. Among them, the detection methods for text can be divided into two categories. The first category is passive detectors, which distinguish AI-generated text from human handwritten text by building a binary detector. The second category of methods is based on digital watermarking technology, which embeds watermarks in AI-generated text and determines whether the text is generated based on the presence of watermarks. Due to the inherent differences between natural language text and computer code, it is difficult to apply existing watermarking technology from generated text to generated code.

[0004] At present, generating code watermarks for large models is still an emerging task. The existing methods mainly include:

[0005] (1) Lee, Taehyun, et al. "Who Wrote this Code Watermarking for Code Generation." Proceedings of the 62nd Annual Meeting of the Association for Computational Linguistics, Association for Computational Linguistics, 2024, pp. 4890–4911. This work proposes an entropy threshold-based code watermarking method called SWEET, which uses the entropy threshold to selectively add watermarks to code snippets with high entropy values, avoiding the impact on code quality caused by adding watermarks to code snippets with low entropy values.

[0006] (2) Zhensu Sun, Xiaoning Du, Fu Song, and Li Li. 2023. "CodeMark: Imperceptible Watermarking for Code Datasets against Neural Code Completion Models." In Proceedings of the 31st ACM Joint European Software Engineering Conference and Symposium on the Foundations of Software Engineering. 1561–1572. This work proposes a watermarking method based on a neural network backdoor. It designs the trigger and target of the code dataset based on code conversion, and is equipped with a watermark embedding and verification scheme, using the existence of a watermark backdoor to verify the watermark.

[0007] The technology described in the above method (1) Lee, Taehyun, et al. "Who Wrote this Code?" Watermarking for Code Generation." has limited effect on detecting generated code because the flexibility and encoding space of code are quite different from those of text, and the authors of the literature point out that the robustness of this method is weak. The technology described in the above method (2) Xiaoning Du, Fu Song, and Li Li. 2023. "CodeMark: Imperceptible Watermarking for Code Datasets against Neural Code Completion Models." requires retraining of the model, which requires a lot of computational overhead. At the same time, both methods are limited to determining whether the code is generated, but do not solve the problem of model traceability of generated code. Summary of the invention

[0008] The present invention aims to provide a watermarking method suitable for generated codes. With the rapid development of large models, the widespread application of generated codes has become a trend, but there are many security risks. Therefore, the ability to identify generated codes and trace their generation models is becoming more and more important. Code watermarking technology provides a feasible solution for this. However, existing watermarking methods have many shortcomings and limitations in terms of robustness and embedding efficiency.

[0009] The present invention provides a method for identifying codes generated by a specific artificial intelligence model by using digital watermarking technology. According to the equivalence principle of code semantic conversion, a conversion rule suitable for generating codes is designed, and the watermark is embedded into the generated code according to a certain coding rule by using the rule. The coding rule adopts BCH error correction code, and its error correction rule realizes the correction of abnormal watermark information. The problem of high error rate of watermark extraction in the existing method and inability to trace the generated code model is overcome.

[0010] The present invention provides a method for generating a code watermark based on a large model of equivalent semantic conversion, comprising the following steps:

[0011] Step 1: Input the predefined prompt words into the large language model, and the large language model outputs the generated code;

[0012] Step 2: According to the code conversion rule set, embed the watermark in the generated code through the watermark embedding algorithm;

[0013] Step 2.1: Extract the conversion rules applicable to the generated code from the code conversion rule set, and construct an applicable conversion rule set;

[0014] Step 2.2: Sort the conversion rules in the conversion rule set from small to large according to the hash values ​​to obtain a sorted applicable conversion rule set;

[0015] Step 2.3: Apply the first N transformation rules in the sorted applicable transformation rule set to the generated code in sequence to obtain a preliminary generated code watermark;

[0016] Step 2.4: Set different watermark information for different large language models, perform BCH encoding on the watermark information, and form an encoded watermark bit sequence;

[0017] Step 2.5: According to the encoded watermark bit sequence, l remaining applicable transformation rules are sequentially taken from the remaining rules of the sorted applicable transformation rule set; for each bit of the encoded watermark bit sequence, if the bit value is 1, the remaining applicable transformation rule corresponding to the sequence number of the bit in the watermark bit sequence is selected to obtain the final generated code watermark.

[0018] Furthermore, the large language model output in step 1 generates code C:

[0019] C=M(P)

[0020] Among them, M is a large language model; P is a predefined prompt word.

[0021] Furthermore, the code conversion rule set is selected from one or more equivalent semantic conversions, and the equivalent semantic conversions include reconstruction conversion, rearrangement conversion, and format conversion.

[0022] Furthermore, in step 2.1, the conversion rule set T′ is applied:

[0023] T′={t|t∈T, is_applicable(t, C)}

[0024] The function is_applicable(t, C) determines whether each transformation rule t is applicable to the generated code C by taking out a rule from the code transformation rule set T each time to perform a trial transformation on the generated code C;

[0025] Furthermore, in step 2.2, the transformation rules in T′ are sorted to obtain a sorted set of applicable transformation rules T sorted :

[0026] T sorted =sort(T′,key=hash(t))

[0027] Among them, hash(t) is the hash value.

[0028] Furthermore, the specific iteration method of step 2.3 is:

[0029] C′(n)=apply(T sorted [n-1],C′(n-1))

[0030] Where, C′(1)=apply(T sorted [0], C), 2≤n≤N; C′ is the preliminary generated code watermark.

[0031] Furthermore, the encoded watermark bit sequence w is formed in step 2.4. encoded :

[0032] w encoded (x) = v (x) + r (x)

[0033] v(x)=(w0+w1x+w2x 2 +…+w k-1 x k-1 )x n-k

[0034] r(x)=v(x)mod g(x)

[0035] Where w is the watermark information; mod g(x) maps the original information polynomial v(x) to a specific coding space by taking the modulus of the generating polynomial g(x) to obtain the final codeword sequence that satisfies the coding constraints; x is the formal variable in the polynomial, which represents the expanded form of the watermark information in the polynomial domain.

[0036] Furthermore, the remaining applicable conversion rule 1 in step 2.5 is:

[0037] l = get_len(w encoded );

[0038] Among them, get_len() returns the encoded watermark sequence w encoded length;

[0039] The remaining applicable conversion rule C corresponding to the serial number of the bit in the sequence w :

[0040] C w =apply(T sorted [n+i],C′), if w encoded [i]=1

[0041] Where n is the number of rules; i is the corresponding position of the bit with a bit value of 1 in the watermark bit sequence.

[0042] The present invention also provides a computer device / equipment / system, including a memory, a processor and a computer program stored in the memory, and when the processor executes the computer program, the steps of any of the above-mentioned methods for generating code watermarks based on a large model of equivalent semantic conversion are implemented.

[0043] The present invention also provides a computer-readable storage medium having a computer program / instruction stored thereon. When the computer program / instruction is executed by a processor, the steps of the method for generating a code watermark based on a large model of equivalent semantic conversion as described in any one of the above items are implemented.

[0044] The present invention also provides a computer program product, including a computer program / instruction, which, when executed by a processor, implements the steps of any of the above-mentioned methods for generating a code watermark based on a large model based on equivalent semantic conversion.

[0045] The beneficial effects of the present invention are:

[0046] This paper proposes a new method for generating code watermarks. The core idea is to selectively apply a set of carefully designed idempotent code transformations that maintain code semantics, and determine the embedding of watermarks by detecting the presence or absence of these transformations. The present invention shows good robustness when dealing with common code optimization tools, especially when using coding error correction, the watermark extraction effect is particularly significant. In addition, some of the transformations of the present invention rely on rule information that cannot be obtained by attackers, thereby ensuring that the embedding of watermarks cannot be systematically removed.

[0047] The present invention does not need to retrain or fine-tune the code generation model, but only needs to post-process the generated code, showing good cross-model compatibility while ensuring the embedding efficiency of the watermark. The present method has the ability to process watermarks quickly, and can complete code watermark embedding in a short time, greatly improving the processing efficiency in practical applications. Since the equivalent semantic conversion method is adopted, there will be no negative impact on the quality of the code, ensuring the normal function and readability of the code. In addition, compared with the existing large language model code watermark generation method, the present invention does not need to access or modify the internal data of the large model, which is particularly important for commercial large models, greatly improving the feasibility and universality of the method. Through efficient post-processing methods, the present invention can achieve efficient embedding and extraction of watermarks while ensuring the functionality and readability of the code, providing an innovative solution for the security and traceability of the generated code. BRIEF DESCRIPTION OF THE DRAWINGS

[0049] Figure 1 This is the main flow chart of a method for generating code watermarks based on a large model of equivalent semantic conversion according to the present invention. DETAILED DESCRIPTION

[0050] In order to make the objectives, technical solutions and advantages of the present application clearer, the implementation methods of the present application will be further described in detail below with reference to the accompanying drawings.

[0051] The present invention adopts a series of code equivalent semantic conversion methods, which are divided into three groups: reconstruction conversion, rearrangement conversion, and format conversion:

[0052] (1) Refactoring transformations: Refactoring transformations are based on the fact that different programming syntaxes can often be used to express the same semantics. For example, a for loop is transformed into a semantically equivalent list comprehension. In addition to these intuitive transformations, this group also includes more complex transformations, such as rule R3, which relies on language features such as function overloading. In this case, given a class constructor with multiple parameters, we sometimes introduce an additional constructor by overloading the constructor. Note that this only happens when the hash value of the class name is an odd number.

[0053] Specific implementation process: Use the Python standard library ast module to parse the code to generate an abstract syntax tree (AST), and filter and operate the AST nodes through conditional traversal. Specifically, only when the attributes and values ​​of a node and its child nodes meet specific search conditions, the corresponding transformation operation is performed on the node. For example, when converting a for loop to a semantically equivalent list derivation, the traversal conditions include: the node type is a For loop node, the length of the loop body meets the requirements, and there is a call to the list append method in the loop body. When the above conditions are met, the AST node of the corresponding code segment is structurally reconstructed and replaced with a semantically equivalent list derivation node. This method is also applicable to other forms of code transformation rules. Although the specific forms of the rules are different, the core implementation logic is consistent, that is, the semantic equivalent transformation of the code is completed through condition matching and reconstruction of AST nodes.

[0054] (2) Reorder transformation: The reorder transformation method is based on the fact that many operators are commutative and associative, that is, their operands can be rearranged without changing the semantics. For example, for an expression consisting of an operator and multiple operands, the reorder transformation method calculates the hash value of the operands (using a secret hash function) and decides whether to rearrange the operands. This means that operands with larger hash values ​​are always placed before operands with smaller hash values. As shown in rule D2 in the table, when comparing the expression n<=right, if the hash value of n is greater than or equal to the hash value of right, it remains unchanged; otherwise, it is converted to right>=n. This type of transformation method can be easily extended to other binary operators (such as addition, multiplication, logical AND and logical OR) or ternary operators (such as conditional expressions, although such transformations are slightly more complicated because the conditions must be negated when changing the order).

[0055] Specific implementation process: Use the Python standard library ast module to parse the code to generate its corresponding abstract syntax tree (AST) and implement node traversal. Based on the variability of AST, when traversing to the operator node (Ops node), extract the values ​​of its left and right child nodes, and calculate the hash values ​​of the left and right child nodes respectively through a secret hash function. Subsequently, the calculation results are verified according to the preset numerical comparison rules (such as size comparison). If the verification does not meet the defined rules, the values ​​of the left and right child nodes are swapped, and the direction of the current operator node is adjusted (for example, converting `>` to `<`). This method is also applicable to other forms of code transformation rules. Although the specific forms of the rules are different, the core implementation logic is the same, that is, the semantic equivalent conversion of the code is completed through node matching and the exchange and modification of AST nodes.

[0056] (3) Format conversion: The design of format conversion methods is based on the fact that code written by humans usually follows certain standards or styles, such as PEP8 standards, and similar phenomena may also exist in AI-generated code. These conversion methods are self-explanatory. By unifying standards and styles (and correcting potential format errors), the generated code conforms to a consistent "standardized" coding pattern, which constitutes a significant watermark feature.

[0057] Specific implementation process: Use the Python standard library `pycodestyle` to parse the source code and generate a code style check report, and use the report to locate the problem locations that violate the PEP8 code style specifications. For each PEP8 style warning, regular expressions and string operations are combined to automatically repair the corresponding code style problems to comply with the PEP8 specification. During the repair process, for problematic code segments that cannot be completely solved by a single string operation, the algorithm will gradually adjust the code through a recursive scanning and repair mechanism until all PEP8 style warnings are eliminated. Since the conversion of code style has no actual relationship with the semantics and syntax of the code, the semantic equivalence of the format conversion can be guaranteed.

[0058] Example 1

[0059] like Figure 1 As shown, the present invention proposes a watermarking method for generated code, the key element of which is a scalable set of idempotent code transformations that preserve semantics. When embedding watermarks, the generated code is systematically post-processed by selectively applying these code transformations for a specific artificial intelligence model. Finally, given a piece of code, the watermark is verified and extracted by systematically identifying whether the transformation is applied. The specific steps are as follows:

[0060] The present invention uses a predefined prompt word P, which is input into a large language model M, and the model outputs a generated code C.

[0061] C=M(P)

[0062] The present invention discloses a watermark embedding method: given a generated code C and a code conversion rule set T, the steps of the watermark embedding algorithm E are as follows:

[0063] (1) Step 1: The embedding algorithm scans the generated code C and checks whether each transformation rule t in T is applicable to C. If t is applicable, it is added to the set of applicable transformation rules T′. The applicability of the transformation rule is based only on the syntax and structure information of the code and does not depend on the runtime state. That is,

[0064] T′={t|t∈T,is_applicable(t,C)}

[0065] The function is_applicable(t, C) determines whether a rule is applicable to C by taking out a rule from T each time and performing a trial transformation on C.

[0066] (2) Step 2: Use a secret sorting rule (such as the hash value of the transformation rule name) to sort the transformation rules in T′ from small to large, that is:

[0067] T sorted =sort(T', key=hash(t))

[0068] Among them, hash(t) represents the hash value calculated using a secret hash value algorithm.

[0069] (3) Step 3: From the sorted set of applicable transformation rules T sorted Select the first n rules from the above and apply them to generate code C in turn to generate the preliminary watermark code C′. sorted The first n transformation rules in are applied to C, and the result is expressed as:

[0070] C(1)′=apply(T sorted [0],C)

[0071] C′(2)=apply(T sorted [1],C(1)′)

[0072] …

[0073] C′(n)=apply(T sorted [n-1],C′(n-1))

[0074] This step allows the checking phase to determine whether a certain code segment has been watermarked by checking the first n transitions.

[0075] (4) Step 4: Set different watermark information w for different large language models, perform BCH encoding on the watermark information w, and construct a polynomial u(x) based on the watermark bit sequence w:

[0076] u(x)=w0+w1x+w2x 2 +…+w k-1 x k-1

[0077] Multiply u(x) by x n-k Then we get v(x). Take v(x) modulo the generator polynomial to get the check polynomial r(x):

[0078] r(x)=v(x)mod g(x)

[0079] Finally, add r(x) and v(x) to form the encoded watermark bit sequence w encoded (x):

[0080] w encoded (x) = v (x) + r (x)

[0081] Generate a watermark bit sequence w with error correction function encoded .

[0082] (5) Step 5: According to the encoded watermark bit sequence w encoded , from T sorted Sequentially select l remaining applicable transformation rules from the remaining rules. Among them:

[0083] l = get_len(w encoded )

[0084] For w encoded For each bit value of , if it is 1, the transformation with the corresponding serial number among the l transformations taken out is applied, that is:

[0085] C w =apply(T sorted [n+i],C′), if w encoded [i]=1

[0086] The present invention also discloses a watermark extraction method: given a generated code C and a series of code conversions T, the steps of the watermark extraction algorithm I are as follows:

[0087] (1) Step 1: The extraction algorithm scans the code C and checks whether each transformation rule t in T is applicable to C. If t is applicable, it is added to the set of applicable transformation rules T′. That is,

[0088] T′={t|t∈T,is_applicable(t,C)}

[0089] The function is_applicable(t, C) determines whether a rule is applicable to C by taking out a rule from T each time and performing a trial transformation on C.

[0090] (2) Step 2: Based on the first n rules of the applicable transformation rule set T′, detect whether a watermark exists. i ∈T′: if t i (C)≠C, then the code is determined to be embedded with a watermark; otherwise, the code is updated to C=t i (C); If all n rules are applicable, it is determined that the code has been embedded with a watermark.

[0091] (3) Step 3: Analyze the remaining l applicable transformation rules and extract the embedded watermark bit sequence wencoded .

[0092] Initialize w encoded for For each transformation rule t i ∈T′,

[0093] if t i (C) = C, then w encoded [in]=1.

[0094] (4) Restore the original watermark information w through the BCH decoding algorithm. encoded Expressed as a polynomial:

[0095] r(x)=r0+r1x+r2x 2 +…+r n-1 x n-1

[0096] By generating the root of the polynomial, calculate the comprehensive value S of the check codeword i :

[0097] S i = r(α i ), i = 1, 2, ..., 2t

[0098] where α is a finite field GF(2 m )'s original element.

[0099] The error localization polynomial σ(x) is calculated using the Pelikan–Messy algorithm:

[0100] σ(x)=1+σ1x+σ2x 2 +…+σ t x t

[0101] Flip the bits corresponding to the identified error positions to obtain the corrected codeword r'(x). Remove the check bits from r'(x) and extract the first k bits as the decoded watermark information w.

[0102] The present invention verifies a proposed large model code watermark generation method based on equivalent semantic conversion through three aspects, including: generated code identification capability, watermark extraction capability, and watermark robustness.

[0103] (1) Generated code identification capability:

[0104] Table 1. Evaluation results of the proposed method on the regenerated code identification task

[0105] Dataset ACC(%) TPR(%) FPR(%) APPS-GPT-3.5 97.08 94.26 0.11 APPS-GPT-4 98.45 97.03 0.13 MBPP-GPT-3.5 94.26 88.52 0 MBPP-GPT-4 96.06 92.13 0 MBPP-StarCoder 97.76 95.3 0

[0106] The five data sets in Table 1 are Python codes, which consist of two parts: generated codes with embedded watermarks and manual handwritten codes. The results are evaluated based on three indicators: ACC (accuracy), TPR (true positive rate) and FPR (false positive rate). As can be seen from Table 1, the present invention has good performance in all data sets. For example, on the APPS-GPT-3.5 data set, the present invention obtained 97.08% ACC, 94.26% TPR and 0.11% FPR. The conclusion shows that the present invention has good generated code identification capabilities.

[0107] (2) Watermark extraction capability:

[0108] Table 2. Evaluation results of the watermark extraction task of the present invention

[0109]

[0110]

[0111] In the experiment, the generated codes of the embedded watermark containing 4 applicable transformations were collected in each data set, where the first two applicable transformations represent the bit values ​​of the original watermark, and the last two applicable transformations represent the bit values ​​of the corrected watermark generated based on BCH coding. Table 2 shows the BitACC (bit accuracy) results before and after the application of coding correction. It can be seen from Table 2 that the present invention has achieved good results in watermark extraction. Among them, the comparison of BitACC before and after BCH coding correction shows that the BCH coding correction algorithm significantly improves the watermark extraction effect. For example, after performing coding correction, the BitACC results on all data sets reached more than 98%, proving that the present invention has excellent performance in watermark extraction capabilities.

[0112] (2) Watermark robustness:

[0113] Table 3 shows the robustness evaluation results of the present invention under common code optimization situations

[0114]

[0115] In the experiment, typical code optimization tools were used to attack the watermarked code and the handwritten code respectively. The code optimization tools used in this experiment are Sourcery and Pyupgrade, and the optimization process is implemented using the default settings of the optimization tools.

[0116] In the destruction attack, the present invention achieved excellent results under the condition of Sourcery optimization. For example, the ACC, TPR and FPR of the present invention on the APPS-GPT-4 dataset are 99.73%, 99.57% and 0.11% respectively. Under the condition of Pyupgrade optimization, the present invention maintains the original ACC and FPR levels, and the TPR result decreases slightly. For example, on the APPS-GPT-4 dataset, the ACC, TPR and FPR are 95.41%, 90.92% and 0.11% respectively. The data show that the destruction attack will not have a significant impact on the watermark recognition effect of the present invention.

[0117] In the spoofing attack, the present invention achieved almost the same results as before optimization under the conditions of using Sourcery and Pyupgrade optimization. For example, under the condition of using Sourcery, the ACC, TPR and FPR results achieved by the present invention are 97.03%, 94.26% and 0.20% respectively. In particular, when there is an intersection between the default settings of Sourcery and the watermark rules of the present invention, the forgery optimization will not have a significant impact on the watermark recognition effect of the present invention.

[0118] In particular, in some preferred embodiments of the present invention, a computer device is also provided, including a memory and a processor and a computer program stored in the memory, and when the processor executes the computer program, the steps of a method for generating a code watermark based on a large model based on equivalent semantic transformation described in any of the above embodiments are implemented.

[0119] In some other preferred embodiments of the present invention, a computer-readable storage medium is provided, on which a computer program / instructions are stored. When the computer program is executed by a processor, the steps of a method for generating a code watermark based on a large model based on equivalent semantic transformation described in any of the above embodiments are implemented.

[0120] A person skilled in the art may understand that all or part of the processes in the above-mentioned embodiment method may be implemented by instructing related hardware through a computer program. The computer program may be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it may include the process of the above-mentioned embodiment of the method for generating a code watermark based on a large model based on equivalent semantic conversion, which will not be repeated here.

[0121] The above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit them. Although the present application has been described in detail with reference to the aforementioned embodiments, a person skilled in the art should understand that the technical solutions described in the aforementioned embodiments may still be modified, or some of the technical features may be replaced by equivalents. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the scope of the technical solutions of the embodiments of the present application.

Claims

1. A method for generating code watermarks based on a large model of equivalent semantic transformation, characterized by: The following steps are involved: Step 1: Input the predefined prompt words into the large language model, and the large language model outputs the generated code; Step 2: According to the code conversion rule set, embed the watermark in the generated code through the watermark embedding algorithm; Step 2.1: Extract the conversion rules applicable to the generated code from the code conversion rule set, and construct an applicable conversion rule set; Step 2.2: Sort the transformation rules in the transformation rule set from small to large according to the hash values ​​to obtain a sorted applicable transformation rule set; Step 2.3: Apply the first N transformation rules in the sorted applicable transformation rule set to the generated code in sequence to obtain a preliminary generated code watermark; Step 2.4: Set different watermark information for different large language models, perform BCH encoding on the watermark information, and form an encoded watermark bit sequence; Step 2.5: According to the encoded watermark bit sequence, l remaining applicable transformation rules are sequentially taken from the remaining rules of the sorted applicable transformation rule set; for each bit of the encoded watermark bit sequence, if the bit value is 1, the remaining applicable transformation rule corresponding to the sequence number of the bit in the watermark bit sequence is selected to obtain the final generated code watermark.

2. The method for generating code watermarks based on a large model based on equivalent semantic conversion according to claim 1 is characterized in that: The large language model output in step 1 generates code C: C=M(P) Among them, M is a large language model; P is a predefined prompt word.

3. The method for generating code watermarks based on a large model based on equivalent semantic conversion according to claim 1 is characterized in that: The code conversion rule set is selected from one or more equivalent semantic conversions, and the equivalent semantic conversions include reconstruction conversion, rearrangement conversion, and format conversion.

4. The method for generating code watermarks based on a large model based on equivalent semantic conversion according to claim 1 is characterized in that: In step 2.1, the transformation rule set T' is applied: T'={t|t∈T,is_applicable(t,C)} The function is_applicable(t,C) determines whether each transformation rule t is applicable to the generated code C by taking out a rule from the code transformation rule set T each time to perform a trial transformation on the generated code C; In step 2.2, the transformation rules in T' are sorted to obtain a sorted applicable transformation rule set T sorted : T sorted =sort(T′,key=hash(t)) Among them, hash(t) is the hash value.

5. The method for generating code watermarks based on a large model based on equivalent semantic conversion according to claim 4 is characterized in that: The specific iteration method of step 2.3 is: C′(n)=apply(T sorted [n-1],C'(n-1)) Where, C'(1) = apply(T sorted [0], C), 2≤n≤N; C' is the preliminary generated code watermark.

6. The method for generating code watermarks based on a large model based on equivalent semantic conversion according to claim 5 is characterized in that: The encoded watermark bit sequence w is formed in step 2.4 encoded : w encoded (x)=v(x)+r(x) v(x)=(w0+w1x+w2x 2 +…+w k-1 x k-1 )x n-k r(x)=v(x)mod g(x) Where w is the watermark information; mod g(x) maps the original information polynomial v(x) to a specific coding space by taking the modulus of the generating polynomial g(x) to obtain the final codeword sequence that satisfies the coding constraints; x is the formal variable in the polynomial, which represents the expanded form of the watermark information in the polynomial domain.

7. The method for generating code watermarks based on a large model based on equivalent semantic conversion according to claim 1 is characterized in that: The remaining applicable conversion rule 1 in step 2.5 is: l = get_len(wencoded); Among them, get_len() returns the encoded watermark sequence w encoded length; The remaining applicable conversion rule C corresponding to the serial number of the bit in the sequence w : C w =apply(T sorted [n+i],C′),if w encoded [i]=1 Where n is the number of rules; i is the corresponding position of the bit with a bit value of 1 in the watermark bit sequence.

8. A computer device / equipment / system comprising a memory, a processor and a computer program stored in the memory, characterized in that: The processor executes the computer program to implement the steps of the method according to any one of claims 1 to 7.

9. A computer-readable storage medium having a computer program / instruction stored thereon, characterized in that: When the computer program / instructions are executed by a processor, the steps of the method according to any one of claims 1 to 7 are implemented.

10. A computer program product comprising a computer program / instructions, characterized in that: When the computer program / instructions are executed by a processor, the steps of the method according to any one of claims 1 to 7 are implemented.

Citation Information

Cited By

  • Large model generation code traceability method, system and device based on reversible watermark and medium

    CN120449134A