A wavelet analysis-based method, apparatus, and computer program for detecting LLM generated code.

CN122569998APending Publication Date: 2026-08-14BEIJING UNIV OF POSTS & TELECOMM
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-05-15
Publication Date
2026-08-14

AI Technical Summary

Technical Problem

在此情况下,两者对应的TPS全局统计特征容易趋同,难以形成稳定有效的判别边界,导致检测性能下降

Benefits of technology

[0019]The LLM-generated code detection method, apparatus, and computer program based on wavelet analysis described in this invention utilize a proxy large language model to obtain the lexical perplexity sequence (TPS) of the code to be detected, and then model this sequence from two complementary dimensions: On the one hand, stationary wavelet transform is used to extract multi-scale fluctuation morphological features, and the fluctuation complexity at each scale is quantified and weighted by sample entropy to obtain a multi-scale index characterizing the overall morphological complexity of the signal; on the other hand, discrete wavelet transform is used to perform multi-level bi-frequency decomposition of the signal, retaining signed detail coefficients to fully record the amplitude and direction information of local fluctuations, and quantifying the distribution concentration of fluctuation energy in each frequency band by calculating the kurtosis of the cross-scale detail coefficient aggregation sequence. Finally, the above morphological features and energy diffusion features are weighted and fused, and the source of the code is determined based on the relationship between the fusion score and a preset threshold. This invention can capture the deep differences between LLM-generated code and manually written code in the local dynamic patterns of TPS, breaking through the bottleneck of insufficient discrimination ability of traditional global statistical features.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122569998A_ABST
    Figure CN122569998A_ABST
Patent Text Reader

Abstract

This invention provides a wavelet analysis-based method, apparatus, and computer program for detecting LLM-generated code. It obtains the lexical perplexity sequence of the code to be detected through a proxy large language model and models it from two complementary dimensions: First, it uses stationary wavelet transform to extract multi-scale fluctuation morphological features, quantifies the complexity of each scale using sample entropy, and weights and aggregates them to obtain multi-scale morphological indices. Second, it uses discrete wavelet transform to perform multi-level bi-frequency decomposition of the signal, retaining signed detail coefficients to record the amplitude and direction of local fluctuations. Then, it calculates the kurtosis of the cross-scale detail coefficient sequence to characterize the distribution concentration of fluctuation energy in each frequency band. Finally, it weights and fuses these two types of features, and determines the source of the code based on the relationship between the fusion score and a preset threshold. This invention effectively captures the deep differences between LLM-generated code and manually written code in the local dynamic patterns of TPS, overcoming the bottleneck of insufficient discrimination ability of traditional global statistical features.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of artificial intelligence-generated content detection technology, and in particular to a method, apparatus and computer program for detecting LLM-generated code based on wavelet analysis. Background Technology

[0002] In recent years, Large Language Models (LLMs) have made significant progress in the field of content generation. These models can not only generate fluent natural language text, but also syntactically correct, structurally sound, and executable source code, and have been gradually applied to practical scenarios such as software development, code completion, and automated programming. However, as the application of LLM-generated code continues to expand, new challenges have arisen regarding code source identification, security assessment, reliability assurance, and software licensing compliance. For example, automatically generated code may contain security vulnerabilities, violate coding standards, and even involve intellectual property risks. Therefore, effectively distinguishing between LLM-generated code and manually written code has become a crucial technical problem that urgently needs to be solved.

[0003] To address the aforementioned issues, most existing research follows the technical approach of generated text detection, treating code as a special form of text and attempting to directly transfer existing generated text detection methods. However, detection methods specifically designed for code scenarios are still in their early stages, and the related technical system is not yet fully developed. Currently, LLM-generated code detection technology mainly involves the following types of solutions.

[0004] One category is detection methods based on supervised learning. These methods train classification models to make judgments by constructing labeled datasets (distinguishing between LLM-generated code and manually written code). Common model architectures include classifiers based on deep neural networks or feature extraction-classification networks. However, these methods typically rely on specific training data distributions and have limited generalization capabilities across models, programming languages, or task scenarios.

[0005] Another category is training-free detection methods. These methods do not require training additional model parameters and typically use statistical rules to discriminate input samples, making them highly practical. Existing training-free detection methods mainly rely on proxy large language models (PLMs) to model the input code and extract relevant statistical features for discrimination. Among these, the most representative core technology is the Token Perplexity Sequence (TPS). TPS refers to the sequence of negative log probabilities of each token in the sequence given the preceding context, used to characterize the degree of surprise of the proxy large language model for each token. Existing methods typically analyze TPS at a holistic level, such as calculating global aggregation indicators like the mean; or by perturbing the original text multiple times to measure the sensitivity of TPS statistical features to changes under perturbed input. These features have been used to distinguish between LLM-generated text and human text, achieving certain results in natural language scenarios. Typical examples of such methods include: detection methods based on the mean of perplexity (such as LogP, LRR, etc.) and detection methods based on the overall perturbation sensitivity of TPS (such as DetectGPT, DetectCodeGPT, etc.).

[0006] However, the aforementioned existing technical solutions still have significant shortcomings in practical applications. First, the discriminative power of global TPS statistical features is insufficient. Existing methods mainly rely on global TPS statistical features for discrimination, but these features have limited discriminative power in code scenarios. Unlike natural languages ​​with rich expressive diversity, programming tasks typically correspond to a relatively limited number of reasonable implementation methods, resulting in a relatively narrow solution space. Simultaneously, code is subject to strict grammatical rules and semantic logic constraints, making LLM code generated for the same task highly similar in overall structure to manually written code. In this case, the global TPS statistical features corresponding to both are prone to convergence, making it difficult to form a stable and effective discrimination boundary, leading to a decline in detection performance. Second, existing methods ignore the local dynamic features of TPS. Existing methods mainly focus on the overall statistical characteristics or global sensitivity analysis of TPS, without effectively modeling its local dynamic structure. Specifically, these methods typically perform statistical analysis of TPS at an overall level, ignoring the fine-grained change patterns between adjacent tokens in TPS, thus failing to fully utilize the potential local fluctuation information in TPS. In fact, LLM-generated code and manually written code exhibit significant differences in their local dynamic behavior at the lexical level: the TPS of LLM-generated code typically shows narrow, instantaneous spikes, while the TPS of manually written code exhibits a broad and persistent fluctuation pattern over a longer span. However, this difference in local dynamics is significantly averaged at the global statistical level and is difficult to observe directly, making it impossible for existing methods to effectively capture and utilize this discriminative feature.

[0007] Therefore, existing technologies urgently need improvement to overcome the limitations of global statistical features and achieve effective modeling of the local dynamic structure of TPS, thereby improving the accuracy and robustness of LLM generated code detection. Summary of the Invention

[0008] In view of this, embodiments of the present invention provide a method, apparatus and computer program for detecting LLM generated codes based on wavelet analysis, in order to eliminate or improve one or more defects existing in the prior art, and solve the problem that the prior art relies on global statistical features of lexical perplexity sequences and ignores local dynamic differences, resulting in insufficient detection accuracy and robustness.

[0009] One aspect of the present invention provides a wavelet analysis-based method for detecting LLM-generated code, the method comprising the following steps: The code snippet to be detected is input into the proxy large language model to output a lexical perplexity sequence; the proxy large language model is different from the source large language model that generated the code snippet to be detected. The stationary wavelet transform is used to collect multi-scale fluctuation morphological features of the word perplexity sequence. The complexity of the fluctuation morphological features at each scale is quantified by sample entropy. The multi-scale complexity index is obtained by weighted aggregation of the complexity of the fluctuation morphological features at each scale. The discrete wavelet transform is used to perform multi-level frequency division decomposition on the word perplexity sequence to obtain approximation sequences and detail coefficients at each level. The detail coefficients retain the original signed values ​​to simultaneously record the amplitude and direction information of local fluctuations in the word perplexity sequence. The multi-scale detail coefficients corresponding to each level of decomposition are aggregated, and the kurtosis used to characterize the cross-scale energy diffusion features is calculated. The multi-scale complexity index and the kurtosis are weighted and fused to obtain a fusion score. When the fusion score is greater than or equal to a set discrimination threshold, the code segment to be detected is determined to be code generated by a large language model. When the fusion score is less than the set discrimination threshold, the code segment to be detected is determined to be manually written code.

[0010] In some embodiments, before inputting the code snippet to be detected into the proxy large language model, the method further includes: Based on the programming language type of the code fragment to be detected, a preset proxy large language model standard database is searched to obtain multiple candidate proxy large language models applicable to the programming language type; Based on the baseline performance constraints of the application scenario and the hardware environment constraints, the candidate agent large language model is further screened to obtain the target agent large language model; the baseline performance constraints include the maximum latency constraint for single-sample inference, the throughput constraint per second, and the minimum baseline constraint for detection accuracy; the hardware environment constraints include the constraints of available computing power resources, available video memory, and available memory.

[0011] In some embodiments, the code snippet to be detected is input into the proxy large language model to output a lexical perplexity sequence, including: The code fragment to be detected is input into the proxy large language model to obtain its word sequence, expressed as: , Let N represent the i-th word element, and N represent the total number of word elements in the code segment to be detected after word segmentation. Assign a conditional probability to each lexical unit, expressed as: , Represents the i-th word element The preceding sequence; θ represents the parameters of the proxy large language model; The negative logarithm is calculated for the conditional probability of each lexical unit, using the following formula: ; The lexical perplexity sequence is defined as a negative log-probability sequence per lexical, expressed as: .

[0012] In some embodiments, stationary wavelet transform is used to collect multi-scale fluctuation morphological features of the lexical perplexity sequence, including: The Dobesi wavelet is used as the basis function, including a high-pass wavelet filter and a low-pass scaling filter of a first set length; Using the high-pass wavelet filter as the basic filter Constructing extended filters at multiple scales , The extended filter The length is The extended filter is obtained by passing through the base filter. Inserting between adjacent coefficients A zero value is obtained for the extended filter. The k-th coefficient is expressed as: ; Convolve the lexical perplexity sequence with the dilated filter to obtain the scale. The response value, which characterizes the intensity of local fluctuations, is calculated as follows: ; scale The response sequence below This corresponds to the wave pattern characteristics.

[0013] In some embodiments, the complexity of the wave morphology features at each scale is quantified using sample entropy, and a multi-scale complexity index is obtained by weighted aggregation of the complexity of the wave morphology features at each scale, including: Extract a length of [length] from the response sequence. For overlapping subsequences, Chebyshev distance is used to calculate the distance between any two subsequences. If the distance is less than the tolerance threshold, they are judged to be similar subsequences. Extend the length of the similar subsequences to The negative logarithm of the conditional probability that remains similar afterward is defined as the sample entropy. Therefore, the formula for calculating the multiscale complexity index MSWT is: ; in, Representing scale The response sequence described below Sample entropy, Indicates the embedding dimension. This represents the tolerance threshold. Indicates assignment to scale Hyperparameter weights.

[0014] In some embodiments, discrete wavelet transform is used to perform multi-level binary frequency division decomposition on the lexical perplexity sequence to obtain approximation sequences and detail coefficients at each level, including: The Dobesi wavelet is used as the basis function, including a high-pass wavelet filter and a low-pass scaling filter of a first set length; The term perplexity sequence is used as the initial input, and recursively filtered by the high-pass wavelet filter and the low-pass scaling filter. Multi-level discrete wavelet decomposition is performed at each level by double decimation downsampling to obtain the approximation sequence for each level. and the detail coefficients , among which, the Layer approximation sequence With detail coefficient The lengths are all , Indicates the number of floors; No. Layer approximation sequence The formula for calculating the nth coefficient is: ; No. Layer detail factor The formula for calculating the nth coefficient is: ; Where p represents the length of the high-pass wavelet filter and the low-pass scaling filter, k represents the index variable of the high-pass wavelet filter and the low-pass scaling filter, and n represents the index variable of the approximation sequence and the detail coefficients.

[0015] In some embodiments, the multi-scale detail coefficients corresponding to each level of decomposition are aggregated, and the kurtosis used to characterize the cross-scale energy diffusion features is calculated, including: A unified sequence is obtained by concatenating and aggregating all detail coefficients at all scales and locations in scale and position order. ; The kurtosis MDWT is calculated using the following formula: ; in, This represents the mean of the uniform sequence. This indicates the total number of detail coefficients.

[0016] In some embodiments, the setting of the discrimination threshold is obtained by maximizing the classification accuracy of the verification dataset, which includes code snippets generated by a large language model for multiple programming languages ​​and manually written code snippets.

[0017] On the other hand, the present invention also provides an LLM generation code detection device based on wavelet analysis, including a processor, a memory, and a computer program or instructions stored in the memory. The processor is used to execute the computer program or instructions, and when the computer program / instructions are executed, the device implements the steps of the above method.

[0018] On the other hand, the present invention also provides a computer program product, including a computer program or instructions that, when executed by a processor, implement the steps of the above-described method.

[0019] The LLM-generated code detection method, apparatus, and computer program based on wavelet analysis described in this invention utilize a proxy large language model to obtain the lexical perplexity sequence (TPS) of the code to be detected, and then model this sequence from two complementary dimensions: On the one hand, stationary wavelet transform is used to extract multi-scale fluctuation morphological features, and the fluctuation complexity at each scale is quantified and weighted by sample entropy to obtain a multi-scale index characterizing the overall morphological complexity of the signal; on the other hand, discrete wavelet transform is used to perform multi-level bi-frequency decomposition of the signal, retaining signed detail coefficients to fully record the amplitude and direction information of local fluctuations, and quantifying the distribution concentration of fluctuation energy in each frequency band by calculating the kurtosis of the cross-scale detail coefficient aggregation sequence. Finally, the above morphological features and energy diffusion features are weighted and fused, and the source of the code is determined based on the relationship between the fusion score and a preset threshold. This invention can capture the deep differences between LLM-generated code and manually written code in the local dynamic patterns of TPS, breaking through the bottleneck of insufficient discrimination ability of traditional global statistical features.

[0020] Additional advantages, objects, and features of the invention will be set forth in part in the description which follows, and will also become apparent in part to those skilled in the art upon studying the description, or may be learned by practice of the invention. The objects and other advantages of the invention can be realized and obtained by means of the structures specifically pointed out in the description and drawings.

[0021] Those skilled in the art will understand that the objectives and advantages achievable with the present invention are not limited to those specifically described above, and that the above and other objectives achievable with the present invention will become clearer from the following detailed description. Attached Figure Description

[0022] The accompanying drawings, which are included to provide a further understanding of the invention and form part of this application, are not intended to limit the scope of the invention. In the drawings: Figure 1 This is a flowchart illustrating the LLM-generated code detection method based on wavelet analysis according to an embodiment of the present invention.

[0023] Figure 2 A comparison chart of global TPS statistical feature distributions for content generated by large language models and human-written content in the Essay and HumanEval datasets.

[0024] Figure 3 A schematic diagram of the TPS trajectory between code generation for LLM and manually written code.

[0025] Figure 4 This is a logical schematic diagram of a training-free LLM-generated code detection method based on multi-scale wavelet analysis according to an embodiment of the present invention. Detailed Implementation

[0026] To make the objectives, technical solutions, and advantages of this invention clearer, the invention will be further described in detail below with reference to the embodiments and accompanying drawings. Here, the illustrative embodiments and descriptions of this invention are used to explain the invention, but are not intended to limit the invention.

[0027] It should also be noted that, in order to avoid obscuring the invention with unnecessary details, only the structures and / or processing steps closely related to the solution according to the invention are shown in the accompanying drawings, while other details that are not closely related to the invention are omitted.

[0028] It should be emphasized that the term "including / comprises" as used herein refers to the presence of a feature, element, step, or component, but does not exclude the presence or addition of one or more other features, elements, steps, or components.

[0029] Large-scale language models (LLMs) have made significant progress in code generation, capable of generating syntactically correct and structurally sound executable source code, and have been widely applied in software development, code completion, and other practical scenarios. However, effectively distinguishing between LLM-generated code and manually written code to address security and compliance challenges remains a pressing technical problem. Existing detection methods mainly follow the approach of generated text detection, with training-free detection methods attracting attention due to their lack of additional training parameters and strong practicality. These methods typically use a proxy large language model to extract the perplexity sequence of the code to be detected and then make a distinction by calculating global statistical features such as the mean. Typical solutions include LogP and LRR methods based on the perplexity mean, and DetectGPT and DetectCodeGPT methods that measure global sensitivity to TPS through random perturbation. However, the above-mentioned solutions have significant shortcomings in code scenarios: on the one hand, the solution space of code tasks is relatively narrow and subject to strict syntactic and semantic constraints. The LLM-generated code and manually written code are highly similar in overall structure, resulting in the convergence of their global TPS statistical features, making it difficult to form a stable and effective discrimination boundary; on the other hand, existing methods only focus on the overall statistical characteristics of TPS, ignoring the fine-grained local dynamic change patterns between adjacent tokens. They cannot effectively capture the significant difference between the narrow instantaneous spikes in LLM-generated code and the long-span continuous fluctuations in manually written code. This causes such discriminative information to be averaged at the global statistical level and difficult to utilize, limiting further improvement in detection performance.

[0030] In view of this, the present invention provides a wavelet analysis-based method for detecting LLM generated code, such as... Figure 1 As shown, the method includes the following steps S101~S104: Step S101: Input the code fragment to be detected into the proxy large language model to output the word perplexity sequence; the proxy large language model is different from the source large language model that generated the code to be detected.

[0031] Step S102: Use stationary wavelet transform to collect multi-scale fluctuation morphological features of the word perplexity sequence, use sample entropy to quantify the complexity of the fluctuation morphological features at each scale, and obtain the multi-scale complexity index by weighted aggregation of the complexity of the fluctuation morphological features at each scale.

[0032] Step S103: Perform multi-level bi-frequency decomposition on the word perplexity sequence using discrete wavelet transform to obtain approximation sequences and detail coefficients at each level. The detail coefficients retain the original signed values ​​to simultaneously record the amplitude and direction information of local fluctuations in the word perplexity sequence. Aggregate the multi-scale detail coefficients corresponding to each level of decomposition and calculate the kurtosis used to characterize the cross-scale energy diffusion features.

[0033] Step S104: The multi-scale complexity index and kurtosis are weighted and fused to obtain a fusion score. When the fusion score is greater than or equal to the set discrimination threshold, the code segment to be detected is determined to be code generated by a large language model. When the fusion score is less than the set discrimination threshold, the code segment to be detected is determined to be manually written code.

[0034] Step S101 is used to construct a perplexity sequence of the code to be detected, serving as the basis signal for subsequent multi-scale analysis. In practice, a proxy large language model is first selected. This model is independent of the source model that may generate the code to be detected. For example, publicly available large language models such as CodeLlama or GPT-Neo can be used. For the application scenario of the invention, various types of programming languages ​​can be independently adapted in advance to ensure that it is not the same as the possible source large language model. Its role is to perform probabilistic modeling of the input code, rather than generating content. After the code fragment to be detected is input into the proxy large language model, the model calculates the negative log-likelihood value of each word obtained after word segmentation of the code under the preceding conditions, based on the conditional probability distribution obtained from its own training. This value measures the degree of surprise of the proxy model for the occurrence of the word. The negative log-likelihood values ​​corresponding to all words are arranged sequentially according to the order in the original code, forming a perplexity sequence of length equal to the total number of words. This sequence constitutes a one-dimensional signal reflecting the change in the degree of surprise of the proxy model for each word in the code, providing input for subsequent multi-scale analysis at the signal level.

[0035] In some embodiments, before inputting the code snippet to be detected into the proxy large language model, the method further includes steps S1011 and S1012: Step S1011: Based on the programming language type of the code fragment to be detected, search the preset proxy large language model standard database to obtain multiple candidate proxy large language models applicable to the programming language type.

[0036] Step S1012: Based on the baseline performance constraints of the application scenario and the hardware environment constraints, the candidate agent large language model is screened a second time to obtain the target agent large language model; the baseline performance constraints include the maximum latency constraint for single-sample inference, the throughput constraint per second, and the minimum baseline constraint for detection accuracy; the hardware environment constraints include the available computing power resource constraints, the available video memory constraints, and the available memory constraints.

[0037] Before inputting the code snippet to be detected into the proxy language model, steps S1011 and S1012 employ a two-step screening mechanism to determine the target proxy model from a pre-set proxy model database. First, a preliminary search is performed based on the programming language type of the code to be detected. This database pre-configures multiple candidate proxy models that are independent of each source model, based on the syntactic features of different programming languages ​​and the distribution characteristics of mainstream code generation models. For example, for the Python programming language, multiple independently trained candidate proxy models such as CodeLlama-7B and StarCoder-3B can be retrieved, effectively distinguishing them from mainstream code generation models. Secondly, candidate models undergo secondary screening based on the deployment requirements of actual application scenarios. Regarding baseline performance constraints, the maximum allowable latency for single-sample inference, the minimum processing throughput per unit time, and the minimum acceptable value for detection accuracy are considered. For scenarios with high real-time requirements, candidate models with excessively large parameter sizes and slow inference speeds can be prioritized for elimination. Regarding hardware environment constraints, the available GPU memory capacity, system memory size, and overall computing power are checked to ensure they are sufficient to load and run a candidate model. For example, when GPU memory is limited on edge deployment devices, lightweight models such as StarCoder-3B can be further selected as target proxy large language models. Through this hierarchical screening mechanism, diverse actual deployment conditions can be adapted while ensuring the independence of the proxy model and the effectiveness of detection.

[0038] In some embodiments, the code snippet to be detected is input into the proxy large language model to output a lexical perplexity sequence, including steps S1013~S1015: Step S1013: Input the code fragment to be detected into the proxy large language model to obtain its word sequence, the expression is: , Let N represent the i-th word element, and N represent the total number of words in the code segment to be detected after word segmentation.

[0039] Step S1014: Assign a conditional probability to each word, expressed as: , Represents the i-th word element The previous sequence; θ represents the parameters of the proxy large language model.

[0040] Step S1015: Calculate the negative logarithm of the conditional probability for each word, using the following formula: ; The perplexity sequence is defined as a negative log-probability sequence per word, expressed as: .

[0041] Step S102 utilizes stationary wavelet transform to extract multi-scale fluctuation morphological features from the word perplexity sequence and quantifies them using sample entropy. The core of stationary wavelet transform lies in its translation invariance and the consistency of output length at each scale with the original signal, which allows for precise alignment and comparison of local fluctuations at different scales. In specific implementation, a wavelet function with tight support characteristics is selected as the basic high-pass filter. This invention uses a Daubechies wavelet filter, with its length denoted as p. To analyze the signal at multiple scales, the basic filter is expanded by inserting a specific number of zero values ​​between its adjacent coefficients to extend its coverage. When the scale is 1, the filter is the original wavelet, capturing the most subtle fluctuations between adjacent words; when the scale is 2, a zero value is inserted between the adjacent coefficients of the original filter, expanding the filter span to approximately twice the range, and so on. The larger the scale, the wider the word context window covered by the filter.

[0042] The expanded filters at each scale are convolved with the word perplexity sequence to obtain the local fluctuation response sequence at each scale. The magnitude of the response value reflects the intensity of the fluctuation at that location. Subsequently, sample entropy is introduced as a tool to measure the complexity of the response sequence at each scale. Sample entropy assesses the probability of the sequence generating new patterns by examining the similarity of subsequences of length m within a tolerance threshold ε. For the response sequence at each scale, its sample entropy value is calculated. A high entropy value indicates that the fluctuation pattern at that scale is more irregular and complex, while a low entropy value indicates that the fluctuation pattern is more regular and predictable. Finally, based on the preset weights for each scale, the sample entropy values ​​of multiple scales are weighted and summed to obtain a multi-scale complexity index. This index comprehensively characterizes the fluctuation features of the signal across different observation spans from the perspective of morphological irregularity.

[0043] Specifically, stationary wavelet transform is used to collect multi-scale fluctuation morphological features of the word perplexity sequence, including steps S1021~S1023: Step S1021: Use Dobesi wavelets as basis functions, including a high-pass wavelet filter and a low-pass scaling filter of a first set length.

[0044] Step S1022: Use a high-pass wavelet filter as the base filter Constructing extended filters at multiple scales , ; Extended filter The length is The extended filter is obtained by passing through the basic filter. Inserting between adjacent coefficients A zero value is obtained for the extended filter. The k-th coefficient is expressed as: ; Step S1023: Convolve the lexical perplexity sequence with the dilated filter to obtain the scale. The response value, which characterizes the intensity of local fluctuations, is calculated as follows: ; scale The response sequence below This corresponds to the wave pattern characteristics.

[0045] In some embodiments, the complexity of the wave morphology features at each scale is quantified using sample entropy, and a multi-scale complexity index is obtained by weighted aggregation of the complexity of the wave morphology features at each scale, including steps S1024 and S1025: Step S1024: Extract a sequence of length from the response sequence. For overlapping subsequences, the Chebyshev distance is used to calculate the distance between any two subsequences. If the distance is less than the tolerance threshold, they are judged to be similar subsequences.

[0046] Step S1025: Extend the length of similar subsequences to The negative logarithm of the conditional probability that remains similar afterward is defined as the sample entropy. Therefore, the formula for calculating the multiscale complexity index (MSWT) is: ; in, Representing scale Next response sequence Sample entropy, Indicates the embedding dimension. Indicates the tolerance threshold. Indicates assignment to scale Hyperparameter weights.

[0047] Step S103 employs discrete wavelet transform to extract cross-scale energy diffusion features from the word perplexity sequence and quantizes them by calculating kurtosis. Discrete wavelet transform recursively uses a filter bank consisting of a high-pass wavelet filter and a low-pass scaling filter to perform multi-level frequency division by two on the signal. Specifically, starting with the original word perplexity sequence as the 0th-level approximation sequence, in each level of decomposition, this approximation sequence is convolved with both the low-pass and high-pass filters. The low-pass filtering result is downsampled by a factor of two to form the approximation sequence for the next level, and the high-pass filtering result is downsampled by a factor of two to form the detail coefficients for that level. The approximation sequence preserves the relatively macroscopic, slowly changing contours of the signal, while the detail coefficients record the local rapid fluctuation information at that scale. Through L-level decomposition, a set of detail coefficients at multiple scales from high frequency to low frequency can be obtained, with the length of the detail coefficients at each scale being halved progressively. Unlike common practices, this step preserves the signed original values ​​of each detail coefficient, retaining both positive and negative values ​​without taking absolute values. Positive values ​​indicate positive fluctuations at that location, while negative values ​​indicate negative fluctuations, thus simultaneously recording the magnitude and direction of local fluctuations. After aggregating the detail coefficients across all scales and locations into a unified sequence, kurtosis is used as a statistic to characterize its distribution. Kurtosis measures the sharpness of the data distribution relative to a normal distribution. A high kurtosis value for the detail coefficients indicates that the fluctuation energy is concentrated on a few local peaks with large amplitudes, while the fluctuation amplitude is small at most locations, exhibiting a sharp and sparse distribution. A low kurtosis value indicates that the fluctuation energy is relatively evenly distributed across all scales, without extremely prominent peaks. This kurtosis index constitutes the cross-scale energy diffusion characteristic, providing discriminative information from the perspective of energy distribution concentration.

[0048] Specifically, discrete wavelet transform is used to perform multi-level frequency division decomposition on the word perplexity sequence to obtain approximation sequences and detail coefficients at each level, including steps S1031~S1033: Step S1031: Use Dobesi wavelets as basis functions, including a high-pass wavelet filter and a low-pass scaling filter of a first set length.

[0049] Step S1032: Using the word perplexity sequence as the initial input, recursively filter it through a high-pass wavelet filter and a low-pass scaling filter, and perform multi-level discrete wavelet decomposition by doubling downsampling at each level to obtain the corresponding approximation sequence for each level. and detail coefficient , among which, the Layer approximation sequence With detail coefficient The lengths are all , Indicates the number of floors.

[0050] Step S1033: The Layer approximation sequence The formula for calculating the nth coefficient is: ; No. Layer detail factor The formula for calculating the nth coefficient is: ; Where p represents the length of the high-pass wavelet filter and the low-pass scaling filter, k represents the index variable of the high-pass wavelet filter and the low-pass scaling filter, and n represents the index variable of the approximation sequence and the detail coefficients.

[0051] In some embodiments, the multi-scale detail coefficients corresponding to each level of decomposition are aggregated, and the kurtosis used to characterize the cross-scale energy diffusion features is calculated, including steps S1034~S1035: Step S1034: Concatenate and aggregate all detail coefficients at all scales and positions according to scale order and position order to obtain a unified sequence. .

[0052] Step S1035: Calculate the kurtosis MDWT, the formula is: ; in, Represents the mean of a uniform sequence. This indicates the total number of detail coefficients.

[0053] Step S104 fuses the complementary features extracted in steps S102 and S103, and makes a final code source determination based on the fusion score. Specifically, the multi-scale complexity index reflects the irregularity of the signal fluctuation pattern, while the cross-scale energy diffusion feature reflects the concentration of fluctuation energy in the frequency band. In practical applications, the perplexity sequence of LLM-generated code usually exhibits a relatively irregular shape, thus its multi-scale complexity index and kurtosis index are relatively high; manually written code, on the other hand, exhibits a more regular fluctuation pattern and a more uniform energy distribution, thus showing the opposite characteristic trend. To integrate the above two types of discrimination information, the multi-scale complexity index and kurtosis index are weighted and fused, where the weight parameter is used to balance the contribution ratio of the two types of features in the final score. After weighted fusion, a scalar fusion score is obtained, which is compared with a pre-calibrated discrimination threshold. When the fusion score is greater than or equal to the threshold, it indicates that the fluctuation characteristics of the code to be detected are more consistent with the typical pattern of LLM-generated code, and it is determined to be code generated by a large language model; when the fusion score is less than the threshold, it is determined to be manually written code. The discrimination threshold can be determined by optimizing classification performance on the validation dataset, for example, by selecting one that aims to maximize the area under the receiver operating characteristic curve or to balance precision and recall.

[0054] In some embodiments, the discrimination threshold is set by maximizing the classification accuracy of the validation dataset, which includes code snippets generated by a large language model for multiple programming languages ​​and manually written code snippets.

[0055] Specifically, the process of setting the discrimination threshold relies on a pre-constructed validation dataset. This dataset contains code snippets generated by large language models and manually written code snippets in various programming languages, and the true source labels of each sample are known. In practice, firstly, steps S101 to S103 of the detection method described in the claims are used to calculate the fusion score for each code sample in the validation dataset, obtaining a score set for all samples. Subsequently, a series of candidate thresholds are generated within the score range with a preset step size. For each candidate threshold, the corresponding classification accuracy is calculated, i.e., the proportion of samples correctly identified as generated by large language models or manually written at the current threshold to the total number of samples in the validation set. By traversing all candidate thresholds and recording the accuracy corresponding to each threshold, the candidate threshold that maximizes the classification accuracy is finally selected as the set discrimination threshold.

[0056] Furthermore, such as Figure 4As shown, β is defined as the weighting parameter at different scales of the TPS wave morphology complexity level, and α is the parameter for weighted aggregation of wave morphology complexity and cross-scale energy distribution characteristics. Based on the validation set, this invention optimizes the model hyperparameters α and β using AUROC as the evaluation index to obtain the optimal model configuration. The hyperparameter optimization can be achieved using grid search, random search, or heuristic search strategies.

[0057] On the other hand, the present invention also provides an LLM generation code detection device based on wavelet analysis, including a processor, a memory, and a computer program or instructions stored in the memory. The processor is used to execute the computer program or instructions, and when the computer program / instructions are executed, the device implements the steps of the above method.

[0058] On the other hand, the present invention also provides a computer program product, including a computer program or instructions that, when executed by a processor, implement the steps of the above-described method.

[0059] The present invention will now be described with reference to a specific embodiment: This embodiment provides a training-free LLM-generated code detection method based on multi-scale wavelet analysis to distinguish whether the code to be detected is generated by a large language model or manually written. This method achieves high-precision detection by performing local dynamic modeling of the TPS corresponding to the code and mining its multi-scale fluctuation characteristics. There are significant differences in TPS between manually written and model-generated content, such as... Figure 2 As shown, the distribution of average term-level TPS is presented on the Essay (text) dataset and the HumanEval (code) dataset. The generation model for the text and code samples is GPT-3.5-Turbo, and the proxy large language models used to calculate TPS are GPT-Neo-2.7B and CodeLlama-7B, respectively. Further, as... Figure 3 As shown, the TPS trajectories of manually written code snippets and code snippets generated by large language models are illustrated. The manually written code exhibits wide and continuous fluctuations over a considerable length range, while the code generated by the large language model only shows narrow instantaneous spikes on a few lexical units.

[0060] Overall model diagram as follows Figure 4 As shown, this embodiment first constructs the original TPS signal, then uses SWT and DWT to model the morphological features and energy distribution of the TPS, and finally fuses the obtained features for detection. The technical solution of this embodiment includes the following detailed steps: Step 1: Construct the TPS of the code to be detected For the input code snippet to be detected, it is first input into the proxy large language model (let the proxy model parameter be θ) to obtain its token sequence. , Let represent the i-th token, and N represent the total number of tokens after word segmentation of the code snippet. The proxy large language model processes each token... Assigning conditional probability ,in This represents the i-th token. The previous sequence. Let the token perplexity sequence (TPS) be defined as the negative log probability sequence per token: (1) in, The measurement, given its preceding context, How unexpected this is for a large language model for agents. Representing the complete TPS as... .

[0061] Step 2: Extract TPS morphological features using Stationary Wavelet Transform (SWT) This module employs Stationary Wavelet Transform (SWT) to characterize the multi-scale wave morphology of TPS signals. SWT uses a fixed-shape filter to analyze the sequence, which extends to a wider context at coarser scales while maintaining the length of the output sequence, thereby achieving consistent comparison of morphological features across different scales.

[0062] Specifically, this invention employs the Daubechies wavelet, which includes a high-pass wavelet filter. and low-pass scale filter Both are of length This invention uses a high-pass filter. As a basic filter, for the TPS signal in The analysis is performed on several scales.

[0063] For each scale Construct an extended filter Its length is The extended filter, through the original filter Inserting between adjacent coefficients A zero is worth. Specifically, for ,have: (2) Among them, when Sometimes, Then, the TPS signal With extended filter Perform convolution with zero padding at the boundaries to optimize the computational scale. The response value characterizing the intensity of local fluctuations is as follows: (3) Let the response sequence at this scale be denoted as Among them, larger scale This corresponds to analysis that covers a wider range of tokens, meaning it can characterize local fluctuations over a longer span.

[0064] For each scale This invention uses sample entropy to analyze the response sequence. The morphological complexity is quantified. Sample entropy is a standard metric used to measure the irregularity of time series. Specifically, from the response sequence... Extract all lengths of The overlapping subsequences are identified, and the Chebyshev distance is used to evaluate the similarity between any two subsequences. The similarity is determined when the distance between two subsequences does not exceed a tolerance threshold. When the sequence is found to be similar, it is determined to be a similar subsequence. Subsequently, the sample entropy is defined as: when two sequences of length are... Similar subsequences are expanded to length The negative logarithm of the conditional probability remains similar. A higher sample entropy indicates more irregular fluctuations at that scale, and consequently, higher morphological complexity. Furthermore, by weighted aggregation of sample entropies at each scale, an overall multi-scale complexity index is obtained: (4) in Representing scale Next response sequence Sample entropy, Indicates the embedding dimension. Indicates the tolerance threshold. Indicates assignment to scale The hyperparameter weights. Used to characterize the overall morphological complexity of TPS across multiple scales.

[0065] Step 3: Extract TPS energy diffusion features using Discrete Wavelet Transform (DWT) This module further employs Discrete Wavelet Transform (DWT) to characterize the cross-scale wave energy diffusion features in the TPS signal. Unlike the Stationary Wavelet Transform (SWT), which maintains the output sequence length, DWT uses a fixed filter to analyze the sequence and performs downsampling at coarser scales, thereby achieving energy-preserving decomposition and accurate quantization of energy at each scale.

[0066] Specifically, this invention employs the same Daubechies wavelet as described above, which consists of a length of... High-pass wavelet filter and low-pass scale filter Composition. Based on the original TPS signal. As the initial input, the filters are used sequentially. and Recursive filtering is performed, and double decimation downsampling is executed at each stage to complete the process. Layered discrete wavelet decomposition yields the approximate sequence. and detail coefficient , among which, the Layer approximation sequence With detail coefficient The lengths are all .

[0067] For any scale The formula for calculating its coefficient is: (5) (6) Zero-padding is used for positions outside the index range. (Larger scale) It corresponds to fluctuation analysis over a wider range of tokens, which means it can capture change patterns over a longer span.

[0068] For each scale This invention preserves the set of signed detail coefficients. This preserves both the amplitude and direction information of local TPS fluctuations. Furthermore, detail coefficients at all scales and locations are aggregated to form a unified sequence. Subsequently, kurtosis was used as a statistical measure to describe its distribution pattern and characterize the cross-scale energy diffusion characteristics, defined as: (7) in Represents a sequence The mean, Indicates the total number of detail coefficients. When A higher value indicates that the wave energy is concentrated in a few sharp local peaks; a lower value indicates that the energy is more evenly distributed across scales. Therefore, this index can compactly characterize the cross-scale energy diffusion features in TPS signals.

[0069] Step 4: Feature Fusion and Classification Judgment To determine the input code snippet Whether generated by a Large Language Model (LLM) or manually written, this invention fuses two complementary features of its TPS signal: one is multi-scale fluctuation morphology features, i.e., generated by... The characterization of local wave morphological complexity; another type is the cross-scale wave energy diffusion characteristic, i.e., by The energy distribution pattern is represented. Combining the above two types of features, a fusion scoring function is constructed: (8) in, This represents the multi-scale morphological eigenvalues ​​obtained based on stationary wavelet transform. This represents the energy diffusion characteristic value obtained based on discrete wavelet transform. The hyperparameter weights are used to balance the contributions of the two types of features.

[0070] According to the fusion score Compared with the preset discrimination threshold The relationship between the input code snippet and the input code snippet To determine the source, when When the code snippet is determined to be LLM-generated code, it is considered to be LLM-generated code. At that time, it was determined that the code snippet was manually written.

[0071] This embodiment's method (CodeRipple) is compared with several representative methods without training baselines, including general LLM-generated text detection methods for natural language processing, such as LogP, GLTR, LRR, FastDetectGPT, and Binocular, as well as DetectCodeGPT, a detection method specifically for code scenarios. These methods primarily rely on global statistical features of TPS. Furthermore, a geometrically based Persistence Homology Dimension (PHD) method and a simple heuristic based on code length are introduced to provide a comprehensive comparison across different methodological paradigms.

[0072] Experimental results show that, by modeling the local dynamic features of the TPS signal and characterizing multi-scale fluctuation patterns, CodeRipple outperforms existing baseline methods across different programming languages, generative models, and detection avoidance strategies, demonstrating strong detection performance and robustness. Based on the experimental results, the technical effects of this invention can be summarized as follows in terms of detection performance, robustness, and generalization ability: (1) Significantly improves detection accuracy in code scenarios This invention effectively overcomes the discrimination bottleneck caused by existing methods' reliance on global statistical features by performing multi-scale local dynamic modeling of TPS signals. On different datasets, this invention achieves superior detection performance compared to existing methods, and can more stably distinguish between LLM-generated code and manually written code, significantly improving detection accuracy in code-based scenarios.

[0073] (2) It has good robustness to various detection avoidance strategies. Table 1 shows the AUROC results of different methods on the AI ​​Code Detection Education dataset. For each code avoidance strategy, the best and second-best performance results are indicated by bold and underline, respectively. Existing methods exhibit significant performance fluctuations for different types of code avoidance detection strategies. However, this invention, by characterizing the local fluctuation morphology and cross-scale energy distribution features of the TPS signal, can maintain stable detection performance under most code avoidance detection strategies, demonstrating strong robustness and anti-interference ability.

[0074] Table 1 (3) Possesses the ability to generalize across model generation sources. Table 2 shows the AUROC results of different methods on the HumanEval and CoDet-M4 datasets. For each dataset, the best and second-best performance results are indicated by bold and underline, respectively. LLM abbreviations are as follows: G-4.0 (GPT-4.0-Turbo), G-3.5 (GPT-3.5-Turbo), C-Opus (Claude-3-Opus), C-Sonnet (Claude-3-Sonnet), and Gemi-Pro (Gemini-1.0-Pro).

[0075] The present invention exhibits stable performance on codes generated by different large language models (such as GPT-3.5, GPT-4, Claude, Gemini, etc.), indicating that the proposed TPS signal multi-scale features do not depend on a specific generation model distribution and have good cross-model generalization ability.

[0076] Table 2 (4) Possesses cross-programming language adaptability As shown in Table 2, the present invention achieves superior detection results in different programming languages ​​such as Python, C++, and Java, indicating that the proposed method can adapt to the differences in syntactic structures of different languages. However, in programming languages ​​with more stringent syntactic structures, the performance improvement is relatively limited due to the limited fluctuation of TPS signals and the weakening of signal differences. This also indirectly verifies the rationality of the present invention based on local dynamic modeling.

[0077] (5) It can effectively address the global statistical convergence problem of TPS. To address the problem of convergence of global TPS statistical features in existing methods in code scenarios, this invention introduces multi-scale wavelet analysis to model the TPS signal from two levels: local fluctuation morphology features and cross-scale energy distribution. This effectively enhances the feature discrimination of different sources and improves the stability of the discrimination boundary.

[0078] In summary, the wavelet analysis-based LLM-generated code detection method, apparatus, and computer program of this invention, through multi-scale signal analysis of the lexical perplexity sequence of the code, uncovers the deep differences in local dynamic patterns between LLM-generated code and manually written code. First, a lexical perplexity sequence of the code to be detected is obtained using a proxy large language model independent of the generation source. This sequence reflects the degree of surprise of the proxy model for each lexical in the code, forming the one-dimensional signal basis for subsequent analysis. Based on this, the sequence is modeled from two complementary dimensions: morphological complexity and energy distribution. In terms of morphological feature extraction, stationary wavelet transform is used to decompose the signal at different observation scales. Stationary wavelet transform abandons the downsampling operation in traditional discrete wavelet transform, and achieves step-by-step expansion of the filter by inserting zero values ​​between adjacent coefficients of the original filter, ensuring that the length of the output sequence at each scale remains consistent with the original signal, thereby achieving accurate local fluctuation pattern localization and cross-scale alignment. For each scale of the obtained wave response sequence, sample entropy is introduced to quantify its irregularity. Sample entropy measures the probability of the signal generating new patterns by examining the similarity of sub-patterns within the sequence. LLM-generated codes exhibit higher sample entropy values ​​due to the more irregular local wave patterns, while manually written codes exhibit lower sample entropy values. Weighted aggregation of sample entropy at each scale yields a multi-scale index characterizing the overall morphological complexity of the signal. In terms of energy feature extraction, discrete wavelet transform is used to perform multi-level frequency division decomposition on the word perplexity sequence. By recursively using high-pass and low-pass filter banks, the signal is separated layer by layer into approximation sequences and detail coefficients. The signed original values ​​of the detail coefficients are retained to simultaneously record the amplitude and direction of local wave fluctuations. The kurtosis is calculated after aggregating the detail coefficients from all scales. A higher kurtosis indicates that the wave energy is concentrated in a few sharp local peaks, consistent with the characteristics of LLM-generated codes; a lower kurtosis indicates that the energy is more evenly distributed across scales, consistent with the characteristics of manually written codes. Finally, the multi-scale complexity index and kurtosis index are weighted and fused, and the source of the code to be detected is determined based on the comparison between the fusion score and the preset discrimination threshold. This invention overcomes the limitation of traditional methods that rely solely on the global statistical features of the lexical perplexity sequence, and can effectively capture local dynamic discriminative information that is difficult for the global mean to reflect. It exhibits excellent detection accuracy and robustness under various programming languages, different generative models, and various detection avoidance strategies.

[0079] Those skilled in the art will understand that the exemplary components, systems, and methods described in conjunction with the embodiments disclosed herein can be implemented in hardware, software, or a combination of both. Whether implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this invention. When implemented in hardware, it can be, for example, electronic circuits, application-specific integrated circuits (ASICs), appropriate firmware, plug-ins, function cards, etc. When implemented in software, the elements of this invention are programs or code segments used to perform the desired tasks. The programs or code segments can be stored in a machine-readable medium or transmitted over a transmission medium or communication link via data signals carried in a carrier wave.

[0080] It should be clarified that the present invention is not limited to the specific configurations and processes described above and shown in the figures. For the sake of brevity, detailed descriptions of known methods are omitted here. In the above embodiments, several specific steps are described and shown as examples. However, the method process of the present invention is not limited to the specific steps described and shown. Those skilled in the art can make various changes, modifications, and additions, or change the order of steps, after understanding the spirit of the present invention.

[0081] In this invention, features described and / or illustrated for one embodiment may be used in the same or similar manner in one or more other embodiments, and / or combined with or in place of features of other embodiments.

[0082] The above description is merely a preferred embodiment of the present invention and is not intended to limit the present invention. For those skilled in the art, various modifications and variations of the embodiments of the present invention are possible. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the protection scope of the present invention.

Claims

1. A method for detecting LLM-generated code based on wavelet analysis, characterized in that, The method includes the following steps: The code snippet to be detected is input into the proxy large language model to output a lexical perplexity sequence; the proxy large language model is different from the source large language model that generated the code snippet to be detected. The stationary wavelet transform is used to collect multi-scale fluctuation morphological features of the word perplexity sequence. The complexity of the fluctuation morphological features at each scale is quantified by sample entropy. The multi-scale complexity index is obtained by weighted aggregation of the complexity of the fluctuation morphological features at each scale. The discrete wavelet transform is used to perform multi-level frequency division decomposition on the word perplexity sequence to obtain approximation sequences and detail coefficients at each level. The detail coefficients retain the original signed values ​​to simultaneously record the amplitude and direction information of local fluctuations in the word perplexity sequence. The multi-scale detail coefficients corresponding to each level of decomposition are aggregated, and the kurtosis used to characterize the cross-scale energy diffusion features is calculated. The multi-scale complexity index and the kurtosis are weighted and fused to obtain a fusion score. When the fusion score is greater than or equal to a set discrimination threshold, the code segment to be detected is determined to be code generated by a large language model. When the fusion score is less than the set discrimination threshold, the code segment to be detected is determined to be manually written code.

2. The wavelet analysis-based LLM code generation detection method according to claim 1, characterized in that, Before inputting the code snippet to be detected into the proxy large language model, the method further includes: Based on the programming language type of the code fragment to be detected, a preset proxy large language model standard database is searched to obtain multiple candidate proxy large language models applicable to the programming language type; Based on the baseline performance constraints of the application scenario and the hardware environment constraints, the candidate agent large language model is further screened to obtain the target agent large language model; the baseline performance constraints include the maximum latency constraint for single-sample inference, the throughput constraint per second, and the minimum baseline constraint for detection accuracy; the hardware environment constraints include the constraints of available computing power resources, available video memory, and available memory.

3. The wavelet analysis-based LLM code generation detection method according to claim 1, characterized in that, Input the code snippet to be detected into the proxy large language model to output a sequence of lexical perplexity, including: The code fragment to be detected is input into the proxy large language model to obtain its word sequence, expressed as: , Let N represent the i-th word element, and N represent the total number of word elements in the code segment to be detected after word segmentation. Assign a conditional probability to each lexical unit, expressed as: , Represents the i-th word element The preceding sequence; θ represents the parameters of the proxy large language model; The negative logarithm is calculated for the conditional probability of each lexical unit, using the following formula: ; The lexical perplexity sequence is defined as a negative log-probability sequence per lexical, expressed as: .

4. The wavelet analysis-based LLM code generation detection method according to claim 3, characterized in that, The stationary wavelet transform is used to collect multi-scale fluctuation morphological features of the lexical perplexity sequence, including: The Dobesi wavelet is used as the basis function, including a high-pass wavelet filter and a low-pass scaling filter of a first set length; Using the high-pass wavelet filter as the basic filter Constructing extended filters at multiple scales , The extended filter The length is The extended filter is obtained by passing through the base filter. Inserting between adjacent coefficients A zero value is obtained for the extended filter. The k-th coefficient is expressed as: ; Convolve the lexical perplexity sequence with the dilated filter to obtain the scale. The response value, which characterizes the intensity of local fluctuations, is calculated as follows: ; scale The response sequence below This corresponds to the wave pattern characteristics.

5. The wavelet analysis-based LLM code generation detection method according to claim 4, characterized in that, The complexity of the wave morphology features at each scale is quantified using sample entropy. A multi-scale complexity index is obtained by weighted aggregation of the complexity of the wave morphology features at each scale, including: Extract a length of [length] from the response sequence. For overlapping subsequences, Chebyshev distance is used to calculate the distance between any two subsequences. If the distance is less than the tolerance threshold, they are judged to be similar subsequences. Extend the length of the similar subsequences to The negative logarithm of the conditional probability that remains similar afterward is defined as the sample entropy. Therefore, the formula for calculating the multiscale complexity index MSWT is: ; in, Representing scale The response sequence described below Sample entropy, Indicates the embedding dimension. This represents the tolerance threshold. Indicates assignment to scale Hyperparameter weights.

6. The wavelet analysis-based LLM code generation detection method according to claim 3, characterized in that, The discrete wavelet transform is used to perform multi-level binary frequency division decomposition on the term perplexity sequence to obtain approximation sequences and detail coefficients at each level, including: The Dobesi wavelet is used as the basis function, including a high-pass wavelet filter and a low-pass scaling filter of a first set length; The term perplexity sequence is used as the initial input, and recursively filtered by the high-pass wavelet filter and the low-pass scaling filter. Multi-level discrete wavelet decomposition is performed at each level by double decimation downsampling to obtain the approximation sequence for each level. and the detail coefficients , among which, the Layer approximation sequence With detail coefficient The lengths are all , Indicates the number of layers; No. Layer approximation sequence The formula for calculating the nth coefficient is: ; No. Layer detail factor The formula for calculating the nth coefficient is: ; Where p represents the length of the high-pass wavelet filter and the low-pass scaling filter, k represents the index variable of the high-pass wavelet filter and the low-pass scaling filter, and n represents the index variable of the approximation sequence and the detail coefficients.

7. The wavelet analysis-based LLM code generation detection method according to claim 6, characterized in that, The multi-scale detail coefficients corresponding to each level of decomposition are aggregated, and the kurtosis used to characterize the cross-scale energy diffusion features is calculated, including: A unified sequence is obtained by concatenating and aggregating all detail coefficients at all scales and locations in scale and position order. ; The kurtosis MDWT is calculated using the following formula: ; in, This represents the mean of the uniform sequence. This indicates the total number of detail coefficients.

8. The wavelet analysis-based LLM code generation detection method according to claim 1, characterized in that, The set discrimination threshold is obtained by maximizing the classification and recognition accuracy of the verification dataset, which includes code snippets generated by a large language model for multiple programming languages ​​and manually written code snippets.

9. A wavelet analysis-based LLM code generation detection device, comprising a processor, a memory, and a computer program or instructions stored in the memory, characterized in that, The processor is configured to execute the computer program or instructions, and when the computer program / instructions are executed, the device implements the steps of the method as described in any one of claims 1 to 8.

10. A computer program product, comprising a computer program or instructions, characterized in that, When the computer program or instructions are executed by a processor, they implement the steps of the method according to any one of claims 1 to 8.