A cross-language code clone detection method based on confidence awareness and syntax semantic decoupling

CN122756765BActive Publication Date: 2026-10-23NANJING UNIV OF AERONAUTICS & ASTRONAUTICS
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202611222597.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2026-08-13
Publication Date
2026-10-23
Estimated Expiration
2046-08-13

AI Technical Summary

Technical Problem

由于不同编程语言(如Java与Python)之间存在剧烈的表面语法结构冲突,如果在特征空间中对其进行强制特征对齐,会向模型中引入严重的结构噪声,从而扭曲和破坏了预训练大模型原本极具泛化性的通用语义空间,使得模型对未见语言的零样本泛化能力急剧退化

Benefits of technology

如上所述,本发明提出了一种基于置信度感知与语法语义解耦的跨语言代码克隆检测方法,该方法旨在消除不同编程语言间表面语法结构异构所引入的结构噪声,保护并维持预训练模型原生通用语义空间的完整性。具体而言,本发明通过特征层面的解耦适配平滑语法冲突,并引入置信度感知机制对多语言代码相似度测度进行自适应约束,以提高特征空间中跨语言功能等价簇的聚集精度,从而使得本发明能够在避免繁重结构解析和微调开销的前提下,有效识别出多语言软件生态中的异构克隆代码并保持高效的工业级并发检索效率。本发明通过结合语法语义解耦与置信度感知,显著提升了跨语言代码克隆检测的精确度与计算效率。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122756765B_ABST
    Figure CN122756765B_ABST
Patent Text Reader

Abstract

The application belongs to the technical field of code clone detection, and specifically discloses a cross-language code clone detection method based on confidence awareness and syntax semantics decoupling, which constructs a double-branch decoupling architecture composed of a shared feature extraction unit, a semantic alignment branch and a syntax noise evaluation branch, and explicitly separates the extraction of core function semantics from the evaluation of language-specific syntax noise. In the training stage, the similarity between the source code segments is dynamically scaled by using the instance-level dynamic temperature coefficient output by the syntax noise evaluation branch, and the calculated confidence awareness similarity score is input into the designed supervised contrast learning loss function containing an L1 temperature regularization penalty term for optimization. In the inference stage, only the semantic embedding features output by the trained semantic alignment branch are used for efficient retrieval. The application combines syntax semantics decoupling and confidence awareness, and improves the accuracy and computational efficiency of cross-language code clone detection.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention belongs to the field of code clone detection technology, and specifically relates to a cross-language code clone detection method based on confidence perception and decoupling of syntax and semantics. Background Technology

[0002] Code clone detection refers to a systematic technique for identifying code snippets with identical or highly similar functions within large software repositories or codebases. In the modern multi-language collaborative software ecosystem, cross-language code clone detection has become increasingly important.

[0003] For example, to achieve cross-platform business alignment, many large internet systems use Java to build Android clients, Swift or Objective-C to maintain iOS clients, and Python or Go to deploy cloud microservice backends.

[0004] If a system vulnerability is discovered and hot-fixed in the implementation of a certain language version, and other parallel cross-language versions fail to detect and maintain it in sync, it will leave serious system synchronization defects and potential security risks.

[0005] Early cross-language clone detection schemes mostly relied on explicit intermediate representations (such as Abstract Syntax Trees (ASTs) and Control Flow Graphs (CFGs). These schemes often fail directly when faced with incomplete or uncompileable code fragments, and graph matching and tree structure comparison face extremely high computational time overhead when dealing with large-scale industrial projects.

[0006] In recent years, code vector representation techniques based on deep pre-trained language models have become increasingly popular. However, existing methods for directly fine-tuning pre-trained models have serious shortcomings in practical applications, specifically: Because of the severe surface syntactic structure conflicts between different programming languages ​​(such as Java and Python), if feature alignment is forced in the feature space, it will introduce serious structural noise into the model, thereby distorting and destroying the originally highly generalizable general semantic space of the pre-trained large model, causing the model's zero-sample generalization ability to unseen languages ​​to degrade sharply.

[0007] Therefore, how to accurately and concurrently identify cross-language clone code with huge grammatical differences but completely equivalent functions without destroying the independence of the original pre-trained semantic features or relying on heavy syntax tree parsing is a major technical challenge in the field of software engineering maintenance.

[0008] The statements in this section are merely background information related to the present invention and do not necessarily constitute prior art. Summary of the Invention

[0009] The purpose of this invention is to propose a cross-language code clone detection method based on confidence awareness and syntactic semantic decoupling. By combining syntactic semantic decoupling and confidence awareness, the accuracy and computational efficiency of cross-language code clone detection can be improved.

[0010] To achieve the above objectives, the present invention adopts the following technical solution: A cross-language code clone detection method based on confidence awareness and syntactic-semantic decoupling includes the following steps: Step 1. Obtain cross-language source code fragment pairs, encode each source code fragment pair using a parameter-freezing generic code encoder, and output the corresponding initial semantic representation vector: Step 2. Input the initial semantic representation vector into the two-branch syntax-semantic decoupling adapter, which includes a shared feature extraction unit, a semantic alignment branch, and a syntax noise evaluation branch; The shared feature extraction unit performs dimensionality reduction and intermediate feature mapping on the initial semantic representation vector to obtain a shared intermediate representation; The semantic alignment branch and the syntactic noise evaluation branch process the shared intermediate representation in parallel, and output the semantic feature vector and the corresponding instance-level dynamic temperature coefficient to characterize the core functional logic of the code, respectively. Step 3. In the model training phase, a confidence-aware temperature dynamic scaling mechanism is introduced. The instance-level dynamic temperature coefficient is used to scale and adjust the dot product similarity calculated between semantic embedded features to construct a confidence-aware similarity score. Then, the confidence-aware similarity score is input into the contrastive learning loss function with an L1 temperature regularization penalty term for global space optimization to dynamically update the network parameters of the two-branch syntax-semantic decoupling adapter. Step 4. In the code clone detection inference stage, explicitly disable and discard the syntax noise evaluation branch, and only extract the semantic embedding features of the query code to be tested and the candidate code in the code repository at the semantic alignment branch output; The semantic embedding features corresponding to the query code and candidate codes are input into the code retrieval module. The code retrieval module calculates the similarity between the two and sorts them in descending order, outputting the cross-language code clone detection retrieval results.

[0011] Furthermore, based on the aforementioned cross-language code clone detection method based on confidence awareness and syntactic semantic decoupling, this invention also proposes a computer device, which includes a memory and one or more processors.

[0012] The executable code is stored in memory. When the processor executes the executable code, it implements the steps of the cross-language code clone detection method described above, which is based on confidence awareness and decoupling of syntax and semantics.

[0013] Furthermore, based on the aforementioned cross-language code clone detection method based on confidence awareness and syntactic-semantic decoupling, this invention also proposes a computer-readable storage medium storing a program that, when executed by a processor, implements the steps of the aforementioned cross-language code clone detection method based on confidence awareness and syntactic-semantic decoupling.

[0014] The present invention has the following advantages: As described above, this invention proposes a cross-language code clone detection method based on confidence awareness and syntactic-semantic decoupling. This method aims to eliminate structural noise introduced by the heterogeneity of surface syntactic structures between different programming languages, protecting and maintaining the integrity of the native general semantic space of the pre-trained model. Specifically, this invention smooths syntactic conflicts through feature-level decoupling adaptation and introduces a confidence-aware mechanism to adaptively constrain the multilingual code similarity measure, thereby improving the aggregation accuracy of cross-language functional equivalence clusters in the feature space. This allows the invention to effectively identify heterogeneous cloned code in the multilingual software ecosystem while maintaining high industrial-grade concurrent retrieval efficiency, avoiding the overhead of heavy structural parsing and fine-tuning. By combining syntactic-semantic decoupling and confidence awareness, this invention significantly improves the accuracy and computational efficiency of cross-language code clone detection. Attached Figure Description

[0015] Figure 1 This is a flowchart of the cross-language code clone detection method based on confidence awareness and syntactic-semantic decoupling of the present invention; Figure 2 This is a network architecture diagram of the dual-branch syntax-semantic decoupling adapter in an embodiment of the present invention; Figure 3 This is a flowchart of the code clone detection stage (inference stage) in an embodiment of the present invention. Detailed Implementation

[0016] The present invention will be further described in detail below with reference to the accompanying drawings and specific embodiments: Example 1 like Figure 1As shown in this embodiment, a cross-language code clone detection method based on confidence-awareness and syntactic-semantic decoupling is described. It explicitly separates the extraction of core functional semantics from the evaluation of language-specific syntactic noise by constructing a two-branch decoupling architecture (i.e., a two-branch syntactic-semantic decoupling adapter) consisting of a shared feature extraction unit, a semantic alignment branch, and a syntactic noise evaluation branch. During the training phase, the instance-level dynamic temperature coefficient output by the syntactic noise evaluation branch is used to dynamically scale the similarity between code pairs. The calculated confidence-aware similarity score is input into a pre-designed supervised contrastive learning loss function containing an L1 temperature regularization penalty term for optimization. This guides the model to accurately establish cross-language functional equivalence clusters without destroying the original pre-trained semantic space. Here, the model refers to a cross-language code clone detection model, which includes a general code encoder, a two-branch syntactic-semantic decoupling adapter, and a code retrieval module. Model training involves updating the network parameters of the two-branch syntactic-semantic decoupling adapter. During the inference phase, the syntactic noise evaluation branch is directly disabled and discarded, and only the semantic embedding features output by the trained semantic alignment branch are used for efficient retrieval. This invention improves the accuracy and computational efficiency of cross-language code clone detection by combining syntactic and semantic decoupling with confidence awareness.

[0017] The cross-language code clone detection method based on confidence awareness and syntax-semantic decoupling in this embodiment includes the following steps: Step 1. Extraction of general code semantic features.

[0018] Obtain cross-language source code fragment pairs, use a parameter-freezing generic code encoder to encode each source code fragment pair in the source code fragment pair, and output the corresponding initial semantic representation vector.

[0019] To avoid costly preprocessing of the code, such as compilation and constructing guide graphs, this invention directly operates on the text sequence of the code, such as... Figure 1 As shown, this invention constructs a universal code encoder.

[0020] This general-purpose code encoder employs a pre-trained, parameter-frozen large embedding model. In a preferred embodiment, the general-purpose code encoder of this invention uses the Qwen3 Embedding model.

[0021] For any source code fragment It directly outputs its initial semantic representation vector. Its dimension is denoted as In this invention, the weights of the general code encoder do not participate in any form of gradient update, but only serve as a source for extracting general code semantic features.

[0022] During the model training and actual retrieval phases, cross-language source code fragment pairs containing implementations in different programming languages ​​are obtained, for example... Figure 1 The code snippet shown in the image , The two code snippets are composed of different programming languages.

[0023] Obtaining cross-language source code snippets is a fairly conventional method, such as directly obtaining them through open-source cross-language code datasets.

[0024] With code snippets , For example, a general code encoding module with its parameters in a strictly frozen state is used to process the input code fragment, directly extracting the initial semantic representation vector containing the initial high-dimensional features. and .

[0025] Step 1 keeps the original weights completely unchanged, thus protecting the integrity of the original semantic space.

[0026] Step 2. Feature mapping of the two-branch syntax-semantic decoupling adapter.

[0027] like Figure 2 As shown, the initial semantic representation vector extracted in step 1 is input into the two-branch syntax-semantic decoupling adapter, which includes a shared feature extraction unit, a semantic alignment branch, and a syntax noise evaluation branch.

[0028] The shared feature extraction unit consists of a multilayer perceptron (MLP) composed of a combination of a linear fully connected layer, a batch normalization layer (BatchNorm1d), a ReLU activation layer, and a Dropout layer to prevent overfitting.

[0029] The shared feature extraction unit first processes the initial semantic representation vector input. Dimensionality reduction and intermediate feature mapping are performed to map the extracted shared intermediate representation. Subsequently It is split into two independent mapping heads with completely different physical meanings in parallel.

[0030] I. Semantic Alignment Branch: Responsible for mapping the shared intermediate representation to the aligned feature space and performing... Normalization outputs semantic feature vectors that characterize the core functional logic of the code.

[0031] II. Syntactic Noise Evaluation Branch: Responsible for independently measuring the current degree of syntactic heterogeneity from the shared intermediate representation. Through non-linear activation processing including a safe offset mechanism, it outputs the corresponding instance-level dynamic temperature coefficient. .

[0032] The above approach facilitates the complete decoupling of semantic features from syntactic noise.

[0033] The network structure of the semantic alignment branch and the syntactic noise evaluation branch will be explained in detail below.

[0034] To achieve smooth feature alignment in a multilingual space, the semantic alignment branch sets a linear mapping matrix. With bias ,Will Transform to aligned feature space, followed by a The normalization layer outputs the final semantic embedding features. .

[0035] Semantic embedding features The calculation expression is as follows: .

[0036] Because it was executed Normalization constraints, semantic embedding features Forced to be distributed on a unit hypersphere, the negative interference of modulus variation is eliminated, making similarity measurable by pure directional dot product.

[0037] In parallel with the semantic alignment branch mentioned above, this invention also designs a separate syntactic noise evaluation branch to adaptively evaluate the syntactic heterogeneous noise carried by each source code segment itself.

[0038] This syntax noise evaluation branch includes mapping parameters. and and utilize The activation function is coupled with a positive safety offset. The process is performed, and the final output is the instance-level dynamic temperature coefficient for the current code snippet. .

[0039] in The programming language-specific structural noise contained in the current code representation vector is used to quantify the code segment's syntax structure. The more complex the syntax structure of the code segment or the greater the structural difference from other languages, the larger the corresponding instance-level dynamic temperature coefficient value.

[0040] Instance-level dynamic temperature coefficient The calculation expression is as follows: .

[0041] By setting a safety offset This can completely avoid the "divide by zero" crash exception caused by zero network output in the early stage of optimization, thus ensuring the numerical stability of distributed large-scale iteration.

[0042] for Figure 1 Chinese source code snippet , If the source code snippet Anchor code, source code snippet As candidate codes, when calculating the confidence-perceived similarity score between the two, only the instance-level dynamic temperature coefficient of A needs to be used. .

[0043] This invention's semantic alignment branch pairs By performing linear mapping and L2 normalization constraints, semantic embedding features are output; the syntactic noise evaluation branch pairs... Perform nonlinear mapping and safe offset activation processing to output the corresponding instance-level dynamic temperature coefficient.

[0044] Step 3. Introduce a confidence-aware temperature dynamic scaling (CTS) mechanism for loss calculation and model training.

[0045] During the model training phase, a confidence-aware temperature dynamic scaling mechanism is introduced. The instance-level dynamic temperature coefficient is used to scale and adjust the dot product similarity calculated between semantic embedded features to construct a confidence-aware similarity score.

[0046] The confidence-aware similarity score is input into a contrastive learning loss function with an L1 temperature regularization penalty term for global space optimization, so as to dynamically update the network parameters of the two-branch syntactic-semantic decoupling adapter.

[0047] Step 3.1. During the training phase, if cross-linguistic semantic features with grammatical differences are directly and forcibly aligned, serious grammatical noise will be introduced, thereby destroying the original pre-trained semantic space of the general code encoder (Qwen3 Embedding).

[0048] This invention introduces a confidence-aware temperature dynamic scaling (CTS) mechanism to smooth out this obstacle.

[0049] Specifically, for any source code fragment within a training mini-batch (Anchor code) and corresponding source code snippets (Candidate code), and its corresponding confidence-aware similarity score The expression is: ; in Represents source code fragments and The confidence-perceived similarity score between the two when they are used as anchor code and candidate code, respectively. and These represent source code fragments. and semantic embedding features, This is the preset global scaling factor; This indicates that the branch evaluated by syntax noise is a source code fragment. Calculate the instance-level dynamic temperature coefficient of the output.

[0050] Global scaling factor Used to and The dot product result is numerically amplified to provide a more effective gradient for model optimization.

[0051] When source code fragment When the structure is extremely verbose, obscure, or severely heterogeneous with the target language's syntax, the instance-level dynamic temperature coefficient of the output of the grammatical noise evaluation branch. It increases accordingly.

[0052] For code with significant structural differences, a larger instance-level temperature coefficient It can effectively reduce the forced optimization penalty imposed by the loss function, thereby overcoming the interference of surface syntax differences and focusing on the alignment of deep functional logic.

[0053] During the training optimization phase, the instance-level dynamic temperature coefficient obtained in step 2 is introduced into the confidence-aware temperature scaling (CTS) mechanism. By using the instance-level dynamic temperature coefficient as the denominator and dynamically dividing it by the dot product similarity between code pairs, the scaled confidence-aware similarity score is constructed.

[0054] Subsequently, this confidence-perceived similarity score is used as the logit value and fed into the design with... Error backpropagation is performed in the global contrastive learning loss function of the temperature regularization penalty term, and only the parameters of the two-branch syntax-semantic decoupling adapter are updated.

[0055] This design enables the semantic alignment branch to learn cross-language functional consistency, while the grammatical noise evaluation branch learns the degree of structural heterogeneity.

[0056] Step 3.2. To generalize this confidence-aware metric to the global space, this invention constructs a contrastive learning loss function that incorporates the temperature dynamic scaling mechanism. The specific process is as follows: Define a containing In a mini-batch training batch of samples, let the source code fragments be... The anchor code belongs to a certain functional clone class. ,make Represents all source code fragments within this batch. A set of positive samples belonging to the same clone class.

[0057] Then the contrastive learning loss function that includes this CTS mechanism Explicitly defined as: ; in ,represent Belongs to the positive sample set A specific positive sample in the sample.

[0058] Represents source code fragments Compared with positive samples The similarity score between them after temperature scaling adjustment; Represents source code fragments With sets any sample The similarity score between them after temperature scaling adjustment.

[0059] express It is a set One of the samples in the sample.

[0060] in In the training batch, excluding source code fragments The set of all samples except itself.

[0061] To prevent the grammatical noise evaluation branch from increasing the temperature value indefinitely. Come and put all of them To mitigate contrast loss by scaling to a minimum value, this invention introduces a method based on [missing information - likely a specific algorithm or principle] into the overall optimization objective. Temperature regularization penalty term for norm.

[0062] use Temperature regularization penalty term constrains the grammatical noise evaluation branch to prevent the model from increasing infinitely during training. The value is an incorrect scheme that aims to achieve convergence of the loss function. The final total loss function... The expression is defined as follows: ; in, This is the preset adjustment balance parameter, with a value of 0.01.

[0063] By minimizing the total loss function The entire model is updated via backpropagation, and only the parameter weights within the two-branch syntax-semantic decoupling adapter are adjusted, while the general code encoder remains completely frozen.

[0064] After training, the semantic space is neatly divided into cross-language code clusters grouped by function.

[0065] Step 4. Efficient clone retrieval and detection during the inference phase.

[0066] During the code clone detection inference phase, the syntactic noise evaluation branch is explicitly disabled and discarded, and only the semantic embedding features of the query code to be tested (i.e., anchor code) and the candidate code in the code repository are extracted from the semantic alignment branch.

[0067] The semantic embedding features corresponding to the query code and candidate codes are input into the code retrieval module. The code retrieval module calculates the similarity between the two and sorts them in descending order, outputting the cross-language code clone detection retrieval results.

[0068] like Figure 3 As shown, when the model is deployed to a production environment for actual cross-language code clone detection, the method of this invention exhibits extremely high computational agility. At this stage, the syntax noise evaluation branch that computes the instance-level dynamic temperature coefficient is explicitly shut down and discarded, as the syntax noise evaluation branch is no longer technically necessary during code retrieval.

[0069] For any input query code snippet to be detected and a large number of candidate code snippets stored in the code repository, the frozen general code encoder and the trained semantic alignment branch are used directly.

[0070] Among them, the semantic alignment branch extracts the corresponding semantic embedding features. and .

[0071] The code retrieval module then directly analyzes the semantic embedding features. and Perform a quick dot product operation to calculate the final code similarity score. The calculation formula is as follows: ; in , These represent the semantic embedding features of the query code to be tested and the candidate code, respectively.

[0072] Finally, by sorting all the calculated similarity scores in descending order, the top few results with the highest similarity are retrieved as the final captured cross-language clone pairs (i.e., functionally equivalent code pairs), thus completing the detection.

[0073] In the clone detection retrieval inference stage, the extracted semantic embedding features are directly used to calculate the dot product similarity between the query code and the candidate code. The similarity scores are then used to quickly sort and output the results, thus completing high-concurrency clone retrieval.

[0074] This invention presents a method based on a parameter-frozen general code encoder, designed as a two-branch syntax-semantic decoupling adapter, which significantly reduces computational overhead and improves retrieval efficiency in heterogeneous code environments. Through parallel splitting at the feature level, the semantic alignment branch and the syntax noise evaluation branch achieve complete separation of functional semantics and language-specific syntactic noise, fundamentally avoiding the distortion of the pre-training semantic space caused by conventional rigid alignment methods. Furthermore, by combining a confidence-aware temperature-dynamic scaling mechanism, instance-level noise coefficients are used to dynamically smooth apparent syntactic conflicts, guiding the contrastive learning optimization process to focus on the alignment of deep functional logic, thereby significantly improving the accuracy and zero-shot generalization ability of code retrieval in heterogeneous multilingual environments. Through the synergistic design of the two-branch decoupling architecture and the temperature-dynamic scaling mechanism, this invention enables the model to maintain extremely high concurrency retrieval response speed while comprehensively improving the robustness and reliability of multilingual software system maintenance.

[0075] Example 2 This embodiment 2 describes a computer device including a memory and one or more processors. Executable code is stored in the memory. When the processor executes the executable code, it implements the steps of the cross-language code clone detection method based on confidence awareness and syntactic-semantic decoupling described in embodiment 1 above.

[0076] In this embodiment, the computer device can be any device or apparatus with data processing capabilities, and will not be described in detail here.

[0077] Example 3 This embodiment 3 describes a computer-readable storage medium storing a program that, when executed by a processor, is used to implement the steps of the cross-language code clone detection method based on confidence awareness and syntactic semantic decoupling in embodiment 1 above.

[0078] The computer-readable storage medium can be an internal storage unit of any device or apparatus with data processing capabilities, such as a hard disk or memory, or an external storage device of any device with data processing capabilities, such as a plug-in hard disk, smart media card (SMC), SD card, flash card, etc.

[0079] Of course, the above description is only a preferred embodiment of the present invention. The present invention is not limited to the above-described embodiments. It should be noted that any equivalent substitutions or obvious modifications made by those skilled in the art under the guidance of this specification fall within the scope of this specification and should be protected by the present invention.

Claims

1. A cross-language code clone detection method based on confidence awareness and syntactic-semantic decoupling, characterized in that, Includes the following steps: Step 1. Obtain cross-language source code fragment pairs, use a parameter-freezing generic code encoder to encode each source code fragment pair in the source code fragment pair, and output the corresponding initial semantic representation vector; Step 2. Input the initial semantic representation vector obtained in Step 1 into the two-branch syntax-semantic decoupling adapter, which includes a shared feature extraction unit, a semantic alignment branch, and a syntax noise evaluation branch; The shared feature extraction unit performs dimensionality reduction and intermediate feature mapping on the initial semantic representation vector to obtain a shared intermediate representation; The semantic alignment branch and the syntactic noise evaluation branch process the shared intermediate representation in parallel, and output the semantic feature vector and the corresponding instance-level dynamic temperature coefficient to characterize the core functional logic of the code, respectively. Step 3. In the model training phase, a confidence-aware temperature dynamic scaling mechanism is introduced. The instance-level dynamic temperature coefficient is used to scale and adjust the dot product similarity calculated between semantic embedded features to construct a confidence-aware similarity score. Then, the confidence-aware similarity score is input into the contrastive learning loss function with an L1 temperature regularization penalty term for global space optimization to dynamically update the network parameters of the two-branch syntax-semantic decoupling adapter. In step 3, the construction process of the contrastive learning loss function is as follows: Define a containing In a mini-batch training batch of samples; Given source code fragments The anchor code belongs to a certain functional clone class. ,make Represents all source code fragments within this batch. A set of positive samples belonging to the same clone class; The contrastive learning loss function includes a temperature dynamic scaling mechanism. Explicitly defined as: ; in ,represent Belongs to the positive sample set A specific positive sample in the sample; Represents source code fragments Compared with positive samples The similarity score between them after temperature scaling adjustment; Represents source code fragments With sets any sample The similarity score between them after temperature scaling adjustment; express It is a set A single sample in the sample; in In the training batch, excluding source code fragments The set of all samples other than itself; In step 3, during the training process, the final total loss function is defined. ; Final total loss function The expression is defined as follows: ; in, The preset adjustment balance parameters, For the first The instance-level dynamic temperature coefficient of a sample, i.e., a source code fragment. By minimizing the total loss function The entire model is updated via backpropagation, and only the parameter weights within the two-branch syntax-semantic decoupling adapter are adjusted, while the general code encoder remains completely frozen. Step 4. In the code clone detection inference stage, explicitly disable and discard the syntax noise evaluation branch, and only extract the semantic embedding features of the query code to be tested and the candidate code in the code repository at the semantic alignment branch output; The semantic embedding features corresponding to the query code and candidate codes are input into the code retrieval module. The code retrieval module calculates the similarity between the two and sorts them in descending order, outputting the cross-language code clone detection retrieval results.

2. The cross-language code clone detection method based on confidence awareness and syntactic-semantic decoupling as described in claim 1, characterized in that, In step 1, the general code encoder adopts the Qwen3 Embedding model.

3. The cross-language code clone detection method based on confidence awareness and syntactic-semantic decoupling as described in claim 1, characterized in that, The specific processing flow of the dual-branch syntax-semantic decoupling adapter is as follows: First, the initial semantic representation vector is projected and intermediate features are captured by the shared feature extraction unit to output a shared intermediate representation. Then, the shared intermediate representation is input into the semantic alignment branch and the syntactic noise evaluation branch respectively. The semantic alignment branch maps the shared intermediate representation to the aligned feature space and performs... Normalization outputs semantic feature vectors that represent the core functional logic of the code; The syntax noise evaluation branch independently measures the current degree of syntax heterogeneity from the shared intermediate representation and outputs the corresponding instance-level dynamic temperature coefficient through nonlinear activation processing that includes a safety offset mechanism.

4. The cross-language code clone detection method based on confidence awareness and syntactic-semantic decoupling as described in claim 3, characterized in that, The processing flow of the semantic alignment branch is as follows: Semantic alignment branch sets linear mapping matrix With bias Shared intermediate representation Transform to aligned feature space, followed by a The normalization layer outputs the final semantic embedding features. Its calculation expression is as follows: 。 5. The cross-language code clone detection method based on confidence awareness and syntactic-semantic decoupling as described in claim 3, characterized in that, The processing flow for the syntax noise evaluation branch is as follows: The syntax noise evaluation branch includes mapping parameters. and and utilize The activation function is coupled with a positive safety offset. The process is performed, and the final output is the instance-level dynamic temperature coefficient for the current code snippet. ; Instance-level dynamic temperature coefficient The calculation expression is as follows: ;in This indicates a shared intermediate representation.

6. The cross-language code clone detection method based on confidence awareness and syntactic-semantic decoupling as described in claim 1, characterized in that, In step 3, the formula for calculating the confidence-perceived similarity score is as follows: ; in Represents source code fragments and The confidence-perceived similarity score between the two when they are used as anchor code and candidate code, respectively. and These represent source code fragments. and semantic embedding features, This is the preset global scaling factor; This indicates that the branch evaluated by syntax noise is a source code fragment. Calculate the instance-level dynamic temperature coefficient of the output.

7. A computer device, comprising a memory and one or more processors; characterized in that, The executable code is stored in the memory, and when the processor executes the executable code, it is used to implement the steps of the cross-language code clone detection method based on confidence awareness and decoupling of syntax and semantics as described in any one of claims 1 to 6.

8. A computer-readable storage medium having a program stored thereon; characterized in that, When the program is executed by the processor, it is used to implement the steps of the cross-language code clone detection method based on confidence awareness and decoupling of syntax and semantics as described in any one of claims 1 to 6.

Citation Information

Patent Citations

  • Code reuse method and device based on AI drive, equipment and medium

    CN120669975A

  • Cross-language code clone detection method and system based on flow enhanced graph attention network

    CN121187643A