Intelligent comparison and analysis method and system for test answer codes
By combining adaptive instrumentation and dynamic behavioral feature analysis with static structural features, a unified code representation is constructed. An adversarial discriminant network is used to identify various plagiarism strategies, which solves the shortcomings of existing code plagiarism detection technologies and achieves more accurate similarity detection of exam answer codes.
Patent Information
- Application Number
- CN202511086651.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-08-05
- Publication Date
- 2025-11-04
- Estimated Expiration
- 2045-08-05
AI Technical Summary
Existing technologies rely too heavily on static feature analysis in code plagiarism detection, making it difficult to capture the dynamic execution behavior characteristics of code. They lack adaptive recognition of diverse plagiarism strategies and learning mechanisms, and cannot effectively cope with constantly evolving plagiarism techniques, especially in large-scale examination scenarios where the detection effect is poor.
By adaptively determining the instrumentation position, collecting the program's execution path sequence and memory access pattern, constructing a dynamic behavior feature vector, and fusing it with static structural features, a code similarity measurement model is constructed using feature encoding network and adversarial discriminant network to identify variable substitution type, control flow reconstruction type and hybrid type deformation, and generate a comparison analysis report.
It achieves accurate detection of code plagiarism, can identify both superficial and deep-level variations, improves the system's ability to identify various plagiarism methods, and provides more reliable support for education and examinations.
Smart Images

Figure CN120631735B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to educational information technology, and more particularly to a method and system for intelligent comparison and analysis of the similarity of exam answer codes. Background Technology
[0002] In programming courses, code plagiarism seriously affects teaching quality and evaluation fairness. With the popularization of programming education and the widespread use of online examination platforms, automatic detection of code plagiarism has become particularly important. The main shortcomings and deficiencies of existing technologies include:
[0003] Existing code similarity detection methods rely excessively on static feature analysis, neglecting the dynamic execution behavior of programs. Plagiarists can evade detection based on static features by modifying variable names, adjusting code structure, and rewriting expressions. These modified codes still exhibit similar execution patterns and memory access characteristics at runtime, but current technologies struggle to capture these deep-seated similarities.
[0004] Current technologies lack the ability to adaptively identify diverse plagiarism strategies. Different types of code variations require different detection strategies; for example, variable substitution variations need to focus on identifier mapping relationships, while control flow refactoring variations need to focus on logical equivalence. Existing methods typically use a single similarity metric, which is insufficient to simultaneously address multiple plagiarism strategies, especially when dealing with hybrid variations where detection performance drops significantly.
[0005] Existing code similarity detection methods lack effective learning mechanisms to cope with constantly evolving plagiarism techniques. They rely on fixed rules and thresholds for judgment, making it difficult to learn from historical data the changing patterns of plagiarism and resulting in poor adaptability to newly emerging plagiarism strategies. Especially in large-scale examination scenarios, current technologies cannot effectively utilize identified plagiarism cases to improve the ability to detect similar plagiarism in the future. Summary of the Invention
[0006] This invention provides a method and system for intelligent comparison and analysis of exam answer code similarity, which can solve the problems in the prior art.
[0007] A first aspect of this invention provides an intelligent comparison and analysis method for the similarity of exam answer codes, comprising:
[0008] The exam answer code to be tested is analyzed based on code complexity and feature path to adaptively determine the optimal instrumentation position; after the instrumentation is executed, the execution path sequence and memory access pattern of the program are collected, and the execution time sequence dependency between code segments is captured through temporal correlation analysis to construct a dynamic behavior feature vector;
[0009] extracting static structural features of the examination answer code to be detected; fusing the static structural features with the dynamic behavior feature vector to construct a unified code representation;
[0010] Based on the unified code representation, a feature coding network and an adversarial discriminant network are used to construct a code similarity measurement model. The adversarial discriminant network includes a local deformation identification sub-network, a global reconstruction identification sub-network, and a hybrid deformation identification sub-network, which are used to identify variable substitution type deformation, control flow reconstruction type deformation, and hybrid type deformation, respectively. In the training stage, a multi-level adversarial sample library is automatically constructed based on heuristic rules to generate variable substitution samples, control flow reconstruction samples, and hybrid deformation samples.
[0011] The code similarity measurement model is used to calculate the similarity between the code to be detected and other examinee answers, identify and locate suspected plagiarism code segments, and generate a comparison analysis report.
[0012] In an optional implementation,
[0013] The step of adaptively determining the optimal insertion position of the examination answer code to be detected based on code complexity and feature path analysis includes:
[0014] A multi-dimensional code complexity index is established, including a structural complexity index and a data flow complexity index. A path feature vector is constructed based on the multi-dimensional code complexity index, which contains the type features and corresponding weights of each node on the path. The path importance is calculated based on path complexity, execution frequency, and data dependency using the path feature vector, and the program execution path including conditional branch points, loop structure points, and feature calculation points is identified.
[0015] The candidate insertion points on the program execution path are evaluated, and the importance of the probe insertion position is determined by calculating the information gain of the original system entropy and the conditional entropy after inserting the probe. The probe density is calculated based on the importance of the candidate insertion points, combined with the code segment length and local complexity weight, to optimize the selection of the insertion position.
[0016] A lightweight probe is designed at the optimized insertion position, and the time overhead, memory overhead, and input / output overhead of the lightweight probe are calculated. The probe sampling frequency is adaptively adjusted according to the ratio of the current overhead to the target overhead threshold.
[0017] In an optional implementation,
[0018] The code after insertion is executed, the execution path sequence and memory access pattern of the program are collected, the execution timing dependency relationship between code segments is captured through timing correlation analysis, and the dynamic behavior feature vector is constructed.
[0019] constructing a timing execution graph comprising a plurality of execution units, edges in the timing execution graph representing timing dependency relationships between the execution units; calculating timing dependency strengths of edges in the timing execution graph, the timing dependency strengths being determined by timing occurrence frequencies and time interval characteristics;
[0020] generating multi-order subgraph patterns based on the timing dependency strengths, support degrees being obtained by calculating ratios of occurrence numbers of the multi-order subgraph patterns in execution traces to a total number of execution traces; constructing an adversarial verification network, adversarial samples being generated by randomly perturbing execution sequences, stability coefficients being calculated based on differences in support degrees of subgraph patterns in original execution sequences and the adversarial samples; calculating a significance score according to a weighted combination of the support degrees, the timing dependency strengths and the stability coefficients;
[0021] extracting timing characteristics of the timing execution graph, the timing characteristics comprising timing pattern characteristics calculated based on the timing dependency strengths, the significance score and an execution sequence entropy;
[0022] performing weighted fusion of path characteristics of execution path sequences, memory characteristics of memory access patterns and the timing characteristics to construct a dynamic behavior feature vector.
[0023] In an optional implementation,
[0024] extracting static structure characteristics of an examination answer code to be detected; performing feature fusion of the static structure characteristics and the dynamic behavior feature vector, a step of constructing a unified code representation comprising:
[0025] extracting an abstract syntax tree of the examination answer code, constructing a data flow graph and a control flow graph based on the abstract syntax tree; extracting lexical characteristics from the abstract syntax tree, the lexical characteristics comprising a code identifier sequence, a reserved word sequence and an operator sequence;
[0026] extracting data flow characteristics from the data flow graph, the data flow characteristics comprising variable definition-use chains, type distributions of data dependency edges and depth distributions of data flow paths; extracting control flow characteristics from the control flow graph, the control flow characteristics comprising a topological sequence of basic blocks, a loop nesting depth and a branching structure complexity;
[0027] performing weighted combination of the lexical characteristics, the data flow characteristics and the control flow characteristics to obtain static structure characteristics;
[0028] The attention fusion network is constructed, the static structure feature is taken as a query vector, the dynamic behavior feature vector is taken as a key-value pair, and a fusion attention weight is obtained by calculating the correlation between the query vector and the key-value pair; the static structure feature and the dynamic behavior feature vector are adaptively fused based on the fusion attention weight to obtain a unified code representation.
[0029] In an alternative embodiment,
[0030] Based on the unified code representation, a feature encoding network and an adversarial discriminant network are used to construct a code similarity measurement model, the adversarial discriminant network includes a local deformation identification subnetwork, a global reconstruction identification subnetwork and a hybrid deformation identification subnetwork, and the steps of identifying variable replacement type deformation, control flow reconstruction type deformation and hybrid deformation respectively include:
[0031] A multi-layer perception mechanism is used to construct a feature encoding network, the unified code representation is subjected to dimension reduction mapping to obtain an encoding vector, and the encoding vector is subjected to L2 regularization constraint and feature normalization processing;
[0032] A local deformation identification subnetwork is constructed, a variable feature vector is extracted based on a variable usage position matrix, a variable similarity matrix is calculated, a variable replacement probability is calculated using an attention mechanism, and variable replacement type deformation is identified;
[0033] A global reconstruction identification subnetwork is constructed, a basic block topology structure feature is extracted to construct a control flow similarity matrix, a graph structure similarity is calculated based on the longest common subsequence, a structure transformation distance of loop unrolling and conditional restructuring is analyzed, and control flow reconstruction type deformation is identified;
[0034] A hybrid deformation identification subnetwork is constructed, variable replacement type deformation features and control flow reconstruction type deformation features are jointly analyzed through multi-level feature extraction and double-flow feature fusion, and adaptive feature fusion mechanism and multi-scale context aggregation are used for hybrid deformation identification.
[0035] In an alternative embodiment,
[0036] The construction steps of the hybrid deformation identification subnetwork include:
[0037] Multi-level feature extraction is performed on the input features to construct a feature pyramid network including a main feature and a lateral connection feature;
[0038] A double-flow feature fusion network is constructed, local deformation features are obtained by processing through a multi-layer perception mechanism, and global reconstruction features are obtained by processing through a graph neural network;
[0039] The local deformation feature and the global reconstruction feature are adaptively fused based on a dynamic gating unit, the dynamic gating unit calculates a gating vector through a learnable weight matrix and a bias vector, a compression excitation module is used to calculate feature importance coefficients of the local deformation feature and the global reconstruction feature respectively, and the local deformation feature and the global reconstruction feature are weighted and fused according to the gating vector and the feature importance coefficients to obtain a fused feature;
[0040] An attention context pooling module is constructed, attention weights at multiple scales are calculated based on the fused feature, multi-scale context feature extraction is performed on the fused feature, context features at multiple scales are adaptively fused, and the fused feature is residual connected to obtain a final feature;
[0041] The hybrid deformation mode similarity and the confidence score are calculated based on the final feature, and the consistency of the final features at different data augmentation views is constrained through feature consistency regularization.
[0042] In an optional implementation,
[0043] In the training phase, the steps of automatically constructing a multi-level adversarial sample library based on heuristic rules, generating variable replacement samples, control flow reconstruction samples and hybrid deformation samples include:
[0044] The variable naming similarity is calculated based on the longest common subsequence, the usage mode similarity is calculated based on the variable usage context set, and the variable mapping matrix is generated by combining the variable naming similarity and the usage mode similarity through a balance coefficient;
[0045] The variable replacement probability is calculated based on the variable mapping matrix, the variable replacement sample is generated according to the variable replacement probability, the control flow reconstruction sample is generated based on the loop transformation function and the branch reorganization metric, and the hybrid deformation sample is generated by combining the variable replacement sample and the control flow reconstruction sample through a mixing weight coefficient;
[0046] A hierarchical sample index structure is constructed, the variable replacement sample, the control flow reconstruction sample and the hybrid deformation sample are respectively stored in different levels, the sample difficulty is calculated based on the variable complexity, the structural complexity and the hybrid complexity, and the samples at different levels are organized according to the sample difficulty;
[0047] The recognition error rate of the statistical model on different levels of samples is calculated, the sample importance is calculated by adjusting the coefficient of the recognition error rate and the sample difficulty, and the samples in the hierarchical sample index structure are dynamically updated based on the sample importance;
[0048] The sampling probability is calculated according to the average importance of different hierarchical samples, a training batch sample is selected from the hierarchical sample index structure based on the sampling probability, a model is trained by using a cross-entropy loss and a multi-task learning target, and a learning rate is adaptively adjusted based on an average recognition error rate of batch samples.
[0049] A second aspect of the embodiment of the application provides an examination answer code similarity intelligent comparison and analysis system, comprising:
[0050] A first unit is configured to adaptively determine an optimal insertion position based on code complexity and feature path analysis of the examination answer code to be detected, insert probe codes for recording execution information at conditional branch points, loop structure points and feature calculation points, execute the code after insertion, collect execution path sequences and memory access patterns of the program, capture execution timing dependency relationships between code segments through timing correlation analysis, and construct a dynamic behavior feature vector.
[0051] A second unit is configured to extract static structure features of the examination answer code to be detected, perform feature fusion on the static structure features and the dynamic behavior feature vector, and construct a unified code representation.
[0052] A third unit is configured to construct a code similarity measurement model by using a feature encoding network and an adversarial discriminant network based on the unified code representation, the adversarial discriminant network comprises a local deformation identification subnetwork, a global reconstruction identification subnetwork and a hybrid deformation identification subnetwork, and is configured to identify variable replacement type deformation, control flow reconstruction type deformation and hybrid deformation respectively, automatically construct a multi-level adversarial sample library based on heuristic rules in a training stage, generate variable replacement samples, control flow reconstruction samples and hybrid deformation samples, and improve the recognition ability of the code similarity measurement model for different plagiarism strategies through adversarial training.
[0053] A fourth unit is configured to calculate the similarity between the code to be detected and other examinee answers by using the code similarity measurement model, identify and locate suspected plagiarism code segments, and generate a comparison and analysis report.
[0054] A third aspect of the embodiment of the application provides an electronic device, comprising:
[0055] A processor;
[0056] A memory for storing processor-executable instructions;
[0057] The processor is configured to invoke the instructions stored in the memory to execute the method described above.
[0058] In a fourth aspect, the present application provides a computer readable storage medium having stored thereon computer program instructions which, when executed by a processor, implement the method described above.
[0059] The present application realizes more accurate examination answer code plagiarism detection through the code similarity analysis method of dynamic and static feature fusion and adversarial learning training, and effectively solves the problem that the traditional method is easily disturbed.
[0060] The present application captures the dynamic behavior characteristics of the code through adaptive insertion and execution path analysis, and constructs a unified code representation combining static structural characteristics, so that the similarity detection is more comprehensive and accurate, and can identify simple variable name replacement, code sequence adjustment and other shallow-level transformations, and can also identify control flow reconstruction and other deep-level transformations.
[0061] The present application adopts a multi-subnetwork adversarial learning architecture and a multi-level adversarial sample library, and is specially trained for different types of code transformation strategies, greatly improves the recognition ability of the system to various plagiarism methods, and can accurately locate the plagiarism code fragments, providing more reliable technical support for education and examination. BRIEF DESCRIPTION OF DRAWINGS
[0062] Figure 1 The figure is a flowchart of the examination answer code similarity intelligent comparison and analysis method of the present application embodiment;
[0063] Figure 2 The figure is a dynamic behavior feature extraction flowchart;
[0064] Figure 3 The figure is a mixed transformation code recognition accuracy comparison chart;
[0065] Figure 4 The figure is a comparison chart of the recognition accuracy of the adversarial sample training method. DETAILED DESCRIPTION
[0066] In order to make the purpose, technical scheme and advantages of the present application embodiment clearer, the technical scheme of the present application embodiment will be described clearly and completely below in combination with the drawings of the present application embodiment. Obviously, the described embodiments are only part of the embodiments of the present application, not all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without creative labor fall within the scope of the present application.
[0067] The technical scheme of the present application will be described in detail below with specific embodiments. The following specific embodiments can be combined with each other, and the same or similar concepts or processes may not be described in some embodiments.
[0068] Figure 1A flowchart of an examination answer code similarity intelligent comparison and analysis method for an embodiment of the present application is shown in FIG. Figure 1 The method comprises the following steps:
[0069] Based on code complexity and feature path analysis, the optimal insertion position of the examination answer code to be detected is adaptively determined, and probe codes for recording execution information are inserted at conditional branch points, loop structure points and feature calculation points; the code after insertion is executed, the execution path sequence and memory access mode of the program are collected, the execution timing dependency relationship between code segments is captured through timing correlation analysis, and a dynamic behavior feature vector is constructed;
[0070] The static structure features of the examination answer code to be detected are extracted; the static structure features and the dynamic behavior feature vector are fused to construct a unified code representation;
[0071] Based on the unified code representation, a code similarity measurement model is constructed using a feature coding network and an adversarial discriminant network, the adversarial discriminant network includes a local deformation recognition subnetwork, a global reconstruction recognition subnetwork and a mixed deformation recognition subnetwork, which are respectively used to recognize variable substitution type deformation, control flow reconstruction type deformation and mixed type deformation; in the training stage, a multi-level adversarial sample library is automatically constructed based on heuristic rules, variable substitution samples, control flow reconstruction samples and mixed deformation samples are generated, and the recognition ability of the code similarity measurement model for different plagiarism strategies is improved through adversarial training;
[0072] The code similarity measurement model is used to calculate the similarity between the code to be detected and other examinee answers, identify and locate the suspected plagiarism code segments, and generate a comparison analysis report.
[0073] In an optional implementation, the step of adaptively determining the optimal insertion position of the examination answer code to be detected based on code complexity and feature path analysis comprises the following steps:
[0074] A multi-dimensional code complexity index is established, the multi-dimensional code complexity index includes a structure complexity index and a data flow complexity index, wherein the structure complexity index calculates the McCabe circle complexity based on the number of edges, the number of nodes and the number of connected components of the control flow graph, and calculates the Halstead complexity based on the number of operators and the number of operands, the data flow complexity index calculates the variable activity based on the weight of the program point and the variable usage frequency; a path feature vector is constructed based on the multi-dimensional code complexity index, the path feature vector contains the type features of each node on the path and the corresponding weights; the path importance is calculated according to the path complexity, the execution frequency and the data dependency degree by using the path feature vector, and the program execution path including the conditional branch points, the loop structure points and the feature calculation points is identified;
[0075] The candidate insertion points on the program execution path are evaluated, and the importance of the probe insertion position is determined by calculating the information gain of the original entropy and the conditional entropy after inserting the probe; according to the importance of the candidate insertion points, the probe density is calculated by combining the code segment length and the local complexity weight, and the probe density is used to optimize the selection of the insertion position;
[0076] A lightweight probe is designed at the optimized insertion position, and the time overhead, memory overhead and input / output overhead of the lightweight probe are calculated; the probe sampling frequency is adaptively adjusted according to the ratio of the current overhead to the target overhead threshold, and the execution information of the program execution path is collected.
[0077] For example, the multi-dimensional indicators include structural complexity indicators and data flow complexity indicators. When processing the structural complexity indicators, the McCabe cycle complexity is calculated by analyzing the control flow graph of the code. The specific method is to obtain the number of edges E, the number of nodes N and the number of connected components P in the control flow graph, and the cycle complexity value is E-N+2P. For example, for a code segment containing 10 edges, 8 nodes and 1 connected component, its McCabe cycle complexity is 10-8+2×1=4. At the same time, the Halstead complexity is calculated based on the number of operators and operands, such as a function containing 15 different operators, 10 different operands, the total number of operator occurrences is 40, and the total number of operand occurrences is 35, the program length is 75, and the program volume is 364.15. For the data flow complexity indicators, the weight of each point in the program (such as the weight of the assignment point is 1, the weight of the calculation point is 2, and the weight of the conditional judgment point is 3) and the variable usage frequency are used to calculate the variable activity. For example, variable x is used 10 times in a piece of code, of which 5 times are used at high weight points (conditional judgment), and the activity score is 25.
[0078] Based on the above multi-dimensional code complexity indicators, a path feature vector is constructed. The feature vector of each execution path includes the type features of each node on the path and their corresponding weights. The node type can be a conditional node, a loop node or a data processing node, etc., and the weight is determined according to the complexity and importance of the node. For example, a path containing 2 conditional branch points (each with a weight of 3), 1 loop structure point (with a weight of 5) and 4 data processing points (each with a weight of 2) can be represented as [3, 3, 5, 2, 2, 2, 2].
[0079] The path importance is calculated by using the path feature vector, and the calculation is based on the path complexity (the weighted sum of the elements of the vector), the execution frequency (estimated by static analysis or obtained by early monitoring), and the data dependency degree (the number of key data dependency relationships involved in the path). For example, the complexity of the path in the above example is 19, the execution frequency is 0.3 (30% of the total execution), and the data dependency degree is 5 (there are 5 key data dependency relationships in the path), and the importance is 19*0.3*5=28.5. In this way, the program execution path including the conditional branch point, the loop structure point and the feature calculation point is identified.
[0080] The importance of the probe insertion position is determined by calculating the information gain of the original entropy and the conditional entropy after inserting the probe. For example, the entropy before inserting the probe at a certain candidate point is 4.5, and the conditional entropy after inserting the probe is 2.1, so the information gain of this point is 2.4, indicating that inserting the probe at this point can obtain more program behavior information. According to the importance of the candidate insertion point (information gain value), combined with the code segment length and the local complexity weight, the probe density is calculated. For a code segment with a length of 100 lines, if the average probe density is set to 0.05 (one probe is placed every 20 lines of code), and the local complexity weight of a certain segment is 1.5, then the actual probe density of this segment should be 0.05*1.5=0.075 (about one probe is placed every 13 lines of code). According to the calculated probe density, the insertion position is optimized and selected to ensure that there are enough monitoring points on the critical path, while avoiding the performance overhead caused by excessive insertion.
[0081] At the optimized and selected insertion position, a lightweight probe is designed. These probes have minimal time overhead, memory overhead and input / output overhead. For example, a lightweight probe only records the timestamp and the current execution point identifier, and its time overhead is about 0.5 microseconds, its memory overhead is 16 bytes, and its input / output overhead depends on the storage method of the probe data. For example, when using a memory buffer, the input / output overhead is close to zero. The probe sampling frequency is adaptively adjusted according to the ratio of the current overhead to the target overhead threshold. For example, if the current probe execution frequency is 1000 times per second, resulting in a performance overhead of 5%, and the target overhead threshold is set to 3%, the sampling frequency will be adjusted to 600 times per second. In this way, the monitoring accuracy can be guaranteed while controlling the impact of the probe on the program performance, and the execution information of the program execution path can be efficiently collected.
[0082] The present application constructs an adaptive optimal insertion position determination mechanism by using multi-dimensional code complexity indicators and path feature vectors, comprehensively considers the structural and data flow complexity, and realizes the accurate selection of the insertion point. This method not only intelligently identifies the key execution points in the program, but also evaluates the importance of the insertion position according to the information gain theory, optimizes the configuration of the probe density, and solves the problems of excessive overhead and missing of critical paths caused by blind insertion in traditional insertion methods.
[0083] In an optional implementation, the steps of executing the instrumented code, collecting the execution path sequence and the memory access pattern of the program, capturing the execution timing dependency relationship between the code fragments through timing correlation analysis, and constructing the dynamic behavior feature vector include:
[0084] collecting an execution path sequence, the execution path sequence containing a plurality of execution point information, the execution point information including an execution point type, an execution point timestamp, an execution point basic block identifier, and execution point context information; constructing a memory access vector, the memory access vector containing a memory access address, a memory access operation type, a memory access data size, and a memory access timestamp, and calculating a temporal locality hit rate and a spatial locality hit rate based on the memory access vector;
[0085] constructing a timing execution graph containing a plurality of execution units, the execution units including an execution unit identifier, an execution unit type, an execution unit start timestamp, an execution unit end timestamp, and execution unit context information, and the edges in the timing execution graph representing timing dependency relationships between the execution units;
[0086] calculating timing dependency strengths of the edges in the timing execution graph, the timing dependency strengths being determined by a timing occurrence frequency and a time interval feature, wherein the timing occurrence frequency is calculated according to a ratio of the number of occurrences of a successor execution unit relative to a predecessor execution unit to the total number of executions of the predecessor execution unit, and the time interval feature is calculated according to a ratio of the difference between the start time of the successor execution unit and the end time of the predecessor execution unit relative to an average execution interval;
[0087] generating a multi-order subgraph pattern based on the timing dependency strengths, calculating a support degree by calculating a ratio of the number of occurrences of the multi-order subgraph pattern in an execution trajectory to the total number of execution trajectories, constructing an adversarial verification network, generating adversarial samples by randomly perturbing the execution sequence, calculating a stability coefficient based on the difference in support degrees of the subgraph patterns in the original execution sequence and the adversarial samples, and calculating a significance score according to a weighted combination of the support degree, the timing dependency strength, and the stability coefficient, the stability coefficient being used to reduce the weight of timing patterns that are susceptible to perturbation;
[0088] extracting path features of the execution path sequence, memory features of the memory access vector, and timing features of the timing execution graph, wherein: the path features include path frequency statistics, path transition probabilities, and key node coverage calculated based on the execution point information; the memory features include memory access pattern features, the temporal locality hit rate, the spatial locality hit rate, and memory access density calculated based on the memory access address and the memory access operation type; and the timing features include key timing pattern features, the significance score, and execution sequence entropy calculated based on the timing dependency strength; and performing weighted fusion of the path features, the memory features, and the timing features to construct a dynamic behavior feature vector.
[0089] In combination Figure 2 The dynamic behavior feature extraction flowchart is described. When the instrumented program is executed, detailed information of each execution point is recorded. Each execution point is represented in the form of a tuple, including the execution point type (such as function call, conditional branch, loop, etc.), the time stamp accurate to the microsecond level, the unique identifier of the basic block, and the execution context information (such as call stack depth, thread ID, etc.). For example, for a function call execution point, it is recorded as ("CALL", 1623481597.283645, "BB_0x4a8c2f", {"stack_depth": 3, "thread_id": 1001}). These information is written into the execution trajectory buffer in real time, and is analyzed and processed after the program execution ends.
[0090] Memory access pattern collection is achieved by monitoring the read and write operations of the program. Each memory access is recorded as a vector containing the access address, operation type (read / write), data size, and access timestamp. For example, a memory read operation is recorded as (0x7fff5fbff8a0, "READ", 4, 1623481597.283752). Based on these records, the temporal locality hit rate, i.e., the proportion of repeated access to the same address within a certain time window (such as 5 milliseconds), is calculated; at the same time, the spatial locality hit rate, i.e., the proportion of access to adjacent memory regions (such as within the same cache line), is calculated. For the test program, the temporal locality hit rate is about 78.3%, and the spatial locality hit rate is about 64.2%.
[0091] The execution trace sequence is segmented into multiple execution units, each representing a basic component of program behavior. An execution unit is represented as a five-tuple, containing a unique identifier, a type (e.g., function body, loop body, conditional branch block, etc.), a start timestamp, an end timestamp, and context information. For example, a function execution unit is represented as ("EU_0x4a8f2c", "FUNCTION", 1623481597.283645, 1623481597.285012, {"name":"process_data", "args_count":3}). A timing execution graph is constructed based on these execution units, with nodes representing execution units and edges representing execution order.
[0092] When calculating the dependency strength of edges in the timing execution graph, two key indicators are considered: timing occurrence frequency and time interval characteristics. Timing occurrence frequency is calculated by dividing the number of times a successor execution unit occurs after a predecessor execution unit by the total number of executions of the predecessor execution unit. For example, if execution unit A is executed 100 times, 80 of which are followed by execution unit B, the timing occurrence frequency from A to B is 0.8. Time interval characteristics are determined by calculating the difference between the start time of the successor execution unit and the end time of the predecessor execution unit, and then dividing by the average execution interval. If the interval between two execution units is much smaller than the average interval, the dependency strength is higher.
[0093] Based on timing dependency strength, subgraph patterns containing 2 to 4 nodes are extracted from the timing execution graph, representing frequently occurring behavior sequences in the program. For each subgraph pattern, its support in the execution trace is calculated, i.e., the ratio of the number of occurrences to the total number of execution traces. To evaluate the stability of these patterns, an adversarial validation network is constructed, which generates adversarial samples by randomly inserting, deleting, or replacing execution units in the original execution sequence. The difference in support of subgraph patterns between the original execution sequence and the adversarial sample is compared, and a stability coefficient is calculated. The higher the stability coefficient, the less sensitive the pattern is to perturbation, and the more likely it is to be an essential behavior characteristic of the program.
[0094] The support, timing dependency strength, and stability coefficient are combined with weights to calculate the significance score of each subgraph pattern. For example, a three-node subgraph pattern has a support of 0.75, an average timing dependency strength of 0.82, and a stability coefficient of 0.93. Using weights of 0.3, 0.3, and 0.4 respectively, the significance score of this subgraph pattern is 0.833.
[0095] Path features are extracted from the execution path sequences, including the frequency distribution of each basic block, the path transition probability matrix, and the coverage of key nodes (such as program entry points, error handling code, etc.). Memory feature extraction includes memory access pattern features (such as continuous access ratio, random access ratio), time and space locality hit rate calculated in the previous step, and memory access density (number of memory operations per unit time). Timing feature extraction is based on timing dependency strength to calculate key timing pattern features, significance scores, and execution sequence entropy (measuring the randomness and predictability of execution paths).
[0096] Path features, memory features, and timing features are combined by weighting to form a dynamic behavior feature vector. In actual implementation, different weights can be assigned to different features, for example, path feature weight 0.4, memory feature weight 0.25, and timing feature weight 0.35. These weights can be determined by experiments on the training data set. The generated feature vector dimension is usually between 200-500, which contains the key behavior features of program dynamic execution and can be used for subsequent program behavior analysis, anomaly detection or similarity comparison.
[0097] The adversarial verification network and stability coefficient evaluation mechanism introduced in the timing dependency relationship analysis of the application can effectively identify and reduce timing pattern weights susceptible to perturbations, improving the robustness of feature extraction. The support degree calculation and significance score weighted combination method of multi-order subgraph patterns solves the problem of insufficient stability evaluation of execution sequences in traditional dynamic analysis, making the extracted dynamic behavior features more accurately reflect the essential characteristics of the code rather than incidental execution characteristics.
[0098] In an optional embodiment, the static structure features of the test answering code to be detected are extracted; the feature fusion of the static structure features and the dynamic behavior feature vector to construct a unified code representation includes:
[0099] An abstract syntax tree of the test answering code is extracted, and a data flow graph and a control flow graph are constructed based on the abstract syntax tree; lexical features are extracted from the abstract syntax tree, and the lexical features include a code identifier sequence, a reserved word sequence, and an operator sequence;
[0100] Data flow features are extracted from the data flow graph, and the data flow features include variable definition-use chains, type distribution of data dependency edges, and depth distribution of data flow paths; control flow features are extracted from the control flow graph, and the control flow features include a topological sequence of basic blocks, loop nesting depth, and branch structure complexity;
[0101] The lexical features, the data flow features, and the control flow features are combined by weighting to obtain static structure features;
[0102] The attention fusion network is constructed, the static structure features are taken as query vectors, the dynamic behavior feature vectors are taken as key-value pairs, and the fusion attention weight is obtained by calculating the correlation between the query vectors and the key-value pairs; and the static structure features and the dynamic behavior feature vectors are adaptively fused based on the fusion attention weight to obtain a unified code representation.
[0103] For example, when extracting the static structure features of the test answer code, the source code is first parsed to generate an abstract syntax tree (AST). For a sorting algorithm code such as "for (int i = 0; i < n - 1; i++) { for (int j = 0; j < n - i - 1; j++) { if (array[j] > array[j + 1]) { swap (array[j], array[j + 1])}}}", it is converted into an AST by a syntax analyzer, and the tree contains tree structures of node types, variable names, operators and the like. Based on the AST, a data flow graph and a control flow graph are constructed. The data flow graph records the dependency relationship between variables, such as the reading and modification of the variable array in the loop body; the control flow graph represents the program execution path, including basic blocks and their jump relationships, such as the decomposition of the above code into initialization blocks, condition judgment blocks, loop body blocks and end blocks.
[0104] When extracting the lexical features from the AST, the tree structure is traversed to obtain three types of key sequences: code identifier sequences such as [i, j, array, swap], reserved word sequences such as [for, int, if], and operator sequences such as [=, <, >, +, -]. These sequences are encoded using frequency statistics or N-gram models, for example, for identifiers, the number of occurrences in the code is calculated and normalized to obtain a vector representation.
[0105] In the data flow feature extraction process, the definition-use chain of the variable is analyzed from the data flow graph. For example, the variable i is defined in the for loop initialization and used in the loop condition and the self-increment expression, forming a link relationship [def(i)→use(i)→use(i)]. The type distribution of the data dependency edges is calculated, such as data definition dependency accounting for 60%, control dependency accounting for 25%, and output dependency accounting for 15%. At the same time, the depth distribution of the data flow path is calculated, such as the path depth of 1 accounting for 50%, the path depth of 2 accounting for 30%, and the path depth of 3 accounting for 20%, to generate a feature vector [0.5, 0.3, 0.2].
[0106] In the control flow feature extraction, first arrange the basic blocks in the control flow graph in topological order to generate a sequence such as [entry, loop_init, loop_cond, loop_body, if_cond, if_body, loop_incr, exit]. Calculate the loop nesting depth, for example, the maximum nesting depth of the above sorting algorithm is 2. The branch structure complexity is obtained by calculating the cyclomatic complexity, and the cyclomatic complexity of the example code is 4, indicating that the code contains 4 independent paths.
[0107] After obtaining all the static features, the lexical features, data flow features and control flow features are combined by weighting. According to the importance of the features, weights are assigned, for example, the lexical feature weight is 0.3, the data flow feature weight is 0.4, and the control flow feature weight is 0.3. Each type of feature is first converted into a vector of the same dimension through normalization processing, and then linearly combined according to the weight to generate the final static structure feature vector. For example, multiply the lexical feature vector [0.25, 0.35, 0.4] by the weight 0.3, multiply the data flow feature vector [0.5, 0.3, 0.2] by the weight 0.4, and multiply the control flow feature vector [0.2, 0.5, 0.3] by the weight 0.3, and then add them to obtain the static structure feature vector [0.33, 0.37, 0.3].
[0108] In the feature fusion stage, an attention fusion network is constructed to realize the adaptive fusion of static structure features and dynamic behavior features. The static structure feature vector is used as the query vector, and the dynamic behavior feature vector is used as the key-value pair. Taking a sorting algorithm as an example, the static structure feature vector is [0.33, 0.37, 0.3], and the dynamic behavior feature vector is [0.6, 0.25, 0.15]. The correlation between the query vector and the key-value pair is calculated to obtain the attention score. Assuming that the calculated attention score is [0.7, 0.2, 0.1], it represents the correlation importance between different dimensions of static features and dynamic features. These attention scores are used as fusion weights to weight the static features and dynamic features. For example, multiply the first dimension 0.33 of the static feature vector by the weight 0.7, and multiply the first dimension 0.6 of the dynamic feature vector by the weight 0.3 to obtain the first dimension value of the fused feature as 0.4; the other dimensions are calculated in the same way, and finally the unified code representation vector [0.4, 0.34, 0.26] is obtained.
[0109] The static structure feature and dynamic behavior feature fusion method of the present application can comprehensively capture the syntax structure, data dependency relationship, control flow and runtime behavior of the code, and the generated unified code representation more comprehensively reflects the characteristics of the test answering code, providing an accurate feature basis for subsequent code similarity analysis and cheating detection.
[0110] In an alternative embodiment, based on the unified code representation, a code similarity measurement model is constructed using a feature encoding network and an adversarial discriminative network, the adversarial discriminative network including a local transformation identification sub-network, a global reconstruction identification sub-network, and a hybrid transformation identification sub-network, and the steps of identifying variable substitution type transformation, control flow reconstruction type transformation, and hybrid type transformation respectively include:
[0111] The feature encoding network is constructed using a multi-layer perception mechanism, the unified code representation is dimensionally mapped to obtain an encoding vector, the encoding vector is constrained by L2 regularization and normalized by feature normalization, and the encoding vector is used as the unified feature input of the subsequent identification network;
[0112] The local transformation identification sub-network is constructed, a variable feature vector is extracted based on a variable usage position matrix, a variable similarity matrix is calculated, a variable substitution probability is calculated using an attention mechanism, and variable substitution type transformation is identified.
[0113] The global reconstruction identification sub-network is constructed, a control flow similarity matrix is constructed by extracting basic block topology features, a graph structure similarity is calculated based on the longest common subsequence, a structural transformation distance of loop unrolling and conditional restructuring is analyzed, and control flow reconstruction type transformation is identified.
[0114] The hybrid transformation identification sub-network is constructed, variable substitution type transformation features and control flow reconstruction type transformation features are jointly analyzed through multi-level feature extraction and dual-flow feature fusion, and adaptive feature fusion mechanism and multi-scale context aggregation are used for hybrid type transformation identification.
[0115] For example, the feature encoding network is implemented using a multi-layer perception mechanism to dimensionally map the unified code representation. The network includes three fully connected layers, the input layer node number is the dimension of the unified code representation (for example, 1024 dimensions), the hidden layer node number is 512, and the output layer node number is 256. Each fully connected layer is followed by a ReLU activation function to improve non-linear expression capability. To prevent overfitting, a Dropout layer is added after the first and second fully connected layers, and the dropout rate is set to 0.3. The obtained 256-dimensional encoding vector is constrained by L2 regularization, the regularization coefficient is set to 0.0001, and then feature normalization processing is performed to make the L2 norm of the encoding vector 1.
[0116] The local deformation identification subnetwork focuses on identifying variable replacement type deformation. The subnetwork first extracts variable features based on the variable usage position matrix in the unified code representation. The variable usage position matrix has dimensions n x m, where n is the number of variables in the code and m is the code length. For each variable, a context window (window size of 5) of its occurrence position in the code is extracted, and a context encoding vector is obtained through the aforementioned feature encoding network. Specifically, for the occurrence of a variable at a specific position, the code content of the previous and subsequent 2 positions is extracted as the context, and the context is converted into a unified code representation and input into the feature encoding network to generate a 256-dimensional encoding vector. If a variable appears multiple times in the code, the context encoding vectors of all occurrence positions are collected and combined into a unified variable feature vector through average pooling to ensure that the usage pattern of the variable in different contexts is captured. The cosine similarity between the variable feature vectors of the two codes is calculated pairwise to construct a variable similarity matrix S, which has dimensions n1 x n2, where n1 and n2 are the number of variables in the two codes. Each element of the matrix represents the similarity between a variable in the first code and another variable in the second code. The variable replacement probability is calculated using an attention mechanism, which is specifically implemented by performing softmax normalization on each row of the similarity matrix to obtain the variable correspondence probability distribution. This processing converts the similarity between each variable and all variables in the other code into a probability distribution, and the variable corresponding to the maximum probability is the possible replacement target. The similarity threshold is set to 0.75, and a variable replacement relationship is considered to exist if the similarity exceeds this threshold.
[0117] The global reconstruction recognition subnetwork is designed for control flow reconstruction type transformation. The subnetwork extracts basic block topology features, where a basic block refers to a code segment without branches. Control flow analysis is performed on the code to extract basic blocks and their connection relationships, and a control flow graph is constructed. This process first parses the code into an abstract syntax tree, then identifies branching statements (such as if-else, switch-case) and loop statements (such as for, while), and accordingly divides the basic block boundaries. Each basic block contains a continuous execution sequence without internal jumps, which is represented as a node in the control flow graph, and the jump relationship between basic blocks is represented as a directed edge. Each basic block is mapped to a vector representation by a feature encoding network, and the mapping process inputs the unified code representation of all statements in the basic block into the feature encoding network and outputs a 256-dimensional vector. Based on these vector representations, a similarity matrix between basic blocks in the two codes is calculated to guide the subsequent graph structure matching. The longest common subsequence algorithm is applied to the control flow graphs of the two codes to calculate the graph structure similarity. This algorithm is implemented through a dynamic programming table iteration, filling in the similarity values along the diagonal direction, with a time complexity of O(n1x n2), where n1 and n2 are the number of basic blocks in the two codes. Loop unrolling transformation is achieved by identifying repeated basic block sequences, and detecting repeated segments in the basic block sequence. When a certain basic block sequence repeats more than 3 times, it is determined to be a loop unrolling transformation. Conditional restructuring transformation is identified by analyzing the adjustment of if-else structures, comparing the arrangement order differences of conditional branches in the original code and the target code, calculating the minimum number of editing operations required to convert one arrangement to another as the structure transformation distance, and setting the threshold value to 2.
[0118] The mixed deformation recognition sub-network recognizes the code with multiple deformation types existing simultaneously in a complex scene. The sub-network captures code features from different abstraction levels through a multi-level feature extraction mechanism. The specific implementation includes three abstraction levels: lexical level (identifiers, keywords, etc.), syntax level (syntax tree structure), and semantic level (data flow, control flow). The lexical level analysis extracts identifier sequences, keyword sequences, and operator sequences in the code, and captures local lexical patterns through an n-gram model. The syntax level analysis constructs an abstract syntax tree, and extracts tree structure features including tree depth, node type distribution, and sub-tree patterns. The semantic level analysis focuses on data dependency and control flow relationships, and identifies the calling relationship and data transfer between statements. For variable replacement type deformation features and control flow reconstruction type deformation features, a dual-flow feature fusion architecture is used for joint analysis. The dual-flow structure includes two parallel processing channels, one processing variable features through a multi-layer fully connected network to extract variable replacement patterns, and the other processing control flow features through a graph neural network to preserve topological structure information. The features of the two channels are combined through an adaptive feature fusion mechanism, which first calculates the importance weights of the two types of features, and then performs weighted fusion according to the weights. The adaptive fusion mechanism includes an attention module that dynamically adjusts the fusion weights according to the feature importance. The attention calculation process first converts the two types of features into query, key, and value vectors, then calculates the similarity between the query and the key to obtain the attention score, and finally weights the value vector with the attention score to obtain the fusion result. Multi-scale context aggregation captures context information of different ranges by setting different receptive fields (3, 5, and 7 respectively). Smaller receptive fields capture local detailed features, larger receptive fields capture more extensive structural features, and multiple scales of features together form a comprehensive code representation.
[0119] For example, for a given two pieces of code, first generate the corresponding encoding vectors through the unified code representation, and then input them into the three sub-networks simultaneously for similarity calculation. The final similarity judgment considers the output results of the three sub-networks, and uses a weighted average method with weights of 0.3 for local deformation, 0.3 for global reconstruction, and 0.4 for mixed deformation.
[0120] The invention constructs a three-in-one adversarial discrimination network architecture, the local deformation recognition sub-network accurately identifies variable replacement based on variable usage position matrix and attention mechanism; the global reconstruction recognition sub-network effectively captures control flow changes through topological structure analysis and longest common subsequence calculation; the mixed deformation recognition sub-network realizes joint analysis of multiple deformation features. This multi-level, multi-dimensional recognition network design greatly improves the model's recognition ability for various plagiarism deformation strategies, solving the problem of insufficient recognition of carefully designed code deformation by traditional similarity measurement methods.
[0121] In an optional implementation, the construction step of the mixed deformation recognition sub-network includes:
[0122] perform multi-level feature extraction on the input features to construct a feature pyramid network containing backbone features and lateral connection features;
[0123] construct a dual-flow feature fusion network to obtain local deformation features through a multi-layer perceptron and global reconstruction features through a graph neural network;
[0124] perform adaptive fusion on the local deformation features and the global reconstruction features based on a dynamic gating unit, the dynamic gating unit calculates a gating vector through a learnable weight matrix and a bias vector, calculates feature importance coefficients of the local deformation features and the global reconstruction features respectively using a squeeze-and-excitation module, and performs weighted fusion on the local deformation features and the global reconstruction features according to the gating vector and the feature importance coefficients to obtain fusion features;
[0125] construct an attention context pooling module, calculate attention weights at multiple scales based on the fusion features, perform multi-scale context feature extraction on the fusion features according to the attention weights at multiple scales, perform adaptive fusion on the context features at multiple scales through learnable scale weights, and perform residual connection with the fusion features to obtain final features;
[0126] calculate a hybrid deformation mode similarity score based on the final features, the hybrid deformation mode similarity score is used to represent the degree of hybrid deformation between codes; calculate a confidence score, the confidence score is used to represent the reliability of similarity judgment; perform data augmentation on the final features to obtain features at multiple augmented viewing angles, constrain the consistency of features at different augmented viewing angles through feature consistency regularization, and improve the robust recognition ability of the model for hybrid deformation.
[0127] For example, the construction of the hybrid deformation recognition subnetwork starts with multi-level feature extraction on the input features. The original code features are received as input, and a feature pyramid network is constructed through a convolutional neural network. The network contains five convolutional layers, each with a 3x3 kernel size, a 2-step stride, and channel numbers of 64, 128, 256, 512, and 1024, respectively. Each convolution is followed by batch normalization and a ReLU activation function. The backbone features are extracted through a top-down path, while the lateral connection features are obtained through a skip connection. For example, for the fourth layer of 512-channel feature maps, they are reduced to 256 channels through 1x1 convolution, and then element-wise addition fused with the upsampled high-level features. This multi-level feature extraction mechanism ensures that the network can capture both local details and global structural information of the code, providing a rich feature basis for subsequent dual-flow feature fusion, especially for recognizing codes with multiple deformation types.
[0128] The construction of the dual-flow feature fusion network is to obtain local deformation features and global reconstruction features at the same time. For the local deformation feature branch, a three-layer multi-layer perceptron structure is adopted, with 1024, 512 and 256 neurons in each layer, and the activation function is LeakyReLU. The input features are processed through these fully connected layers, which can effectively capture the local structural change features of the code. In practical applications, this branch can identify local deformation patterns such as variable replacement and statement rearrangement, such as transforming "for(int i=0; i<n; i++)" to "for(int j=0; j<n; j++)". For the global reconstruction feature branch, a graph neural network is used to process it. First, the code is represented as an abstract syntax tree, and the edges between nodes represent the syntax relationship. A graph convolutional network is used for message passing, with an output dimension of 256 for each layer of graph convolution. A total of 3 layers are set. Global reconstruction features can capture the overall structural information of the code and have strong robustness to global transformations such as code logic reconstruction and control flow transformation. For example, when rewriting an "if-else" structure to a "switch-case" structure, although the local code is completely different, the global semantics remain consistent. These two branches extract features from different angles, providing complementary information sources for subsequent dynamic gating fusion, and can comprehensively analyze the deformation features of the code.
[0129] The dynamic gating unit contains a learnable weight matrix W with a size of 512x256 and a bias vector b with a size of 256. The local feature vector and the global feature vector are concatenated, multiplied by W and added to b, and then normalized by the sigmoid function to obtain the gating vector g, with a value range of 0 to 1. The compression excitation module processes the local feature and the global feature respectively. For each feature vector, first compress the dimension to 1 through global average pooling, then pass through two fully connected layers (the first layer reduces the dimension by a ratio of 16, and the second layer restores the original dimension) and the sigmoid activation function to obtain the local feature importance coefficient α and the global feature importance coefficient β. The final fusion feature calculation is: local feature multiplied by g multiplied by α plus global feature multiplied by (1-g) multiplied by β. If the code mainly exists local deformation such as variable replacement, the gating vector will be biased towards the local feature branch; if there is global deformation such as control flow reconstruction, the gating vector will be biased towards the global feature branch. This adaptive fusion mechanism can dynamically adjust the weight of different features according to the characteristics of the input code, greatly improving the recognition flexibility of mixed deformation, while ensuring the computing efficiency.
[0130] The attention context pooling module calculates attention weights at multiple scales based on the fused features, including three scales: local scale (window size of 3), medium scale (window size of 5), and global scale (window size of feature length). For each scale, an attention score is calculated through a two-layer fully connected network, the first layer has a dimension of 128, and the second layer has a dimension of 1, and then a normalized attention weight is obtained through a softmax function. According to the attention weights of different scales, the fused features are weighted and averaged to obtain the context features corresponding to the scales. Meanwhile, a learnable scale weight vector w is introduced, which has a size of 3, and after being normalized by softmax, it is multiplied by the context features of the three scales respectively and summed to obtain the final context features. The feature is connected in residual to the original fused feature to form the final feature representation. The multi-scale design enables attention to both local relationships and global structures of the code, and the residual connection ensures that the original feature information will not be lost in the processing process, which is crucial for maintaining the semantic coherence of the code, especially when processing long sequence codes, which can significantly improve the recognition accuracy.
[0131] Based on the final feature, a hybrid deformation mode similarity score and a confidence score are calculated. The similarity score is realized through a two-layer fully connected network, with dimensions of 128 and 1 respectively, and finally mapped to the interval of 0 to 1 through a sigmoid function, representing the degree of hybrid deformation between the two pieces of code, and the larger the value, the higher the deformation possibility. The confidence score is calculated through another two-layer fully connected network, and finally outputs a value between 0 and 1, representing the reliability of the similarity judgment. In the data augmentation section, various augmentation strategies are applied to the final feature, including feature masking (randomly setting 15% of the features to zero), feature perturbation (adding Gaussian noise with a standard deviation of 0.1), and feature mixing (mixing with random sample features at a ratio of 0.7:0.3). Through feature consistency regularization, the cosine similarity loss between the original feature and the augmented feature is calculated, so that the feature representation under different perspectives remains consistent, thereby improving the robust recognition ability of the model for hybrid deformation. The dual output design of similarity score and confidence score not only enables the judgment of code similarity, but also evaluates the reliability of the judgment, which is particularly important when dealing with boundary cases and complex deformations, effectively reducing the misjudgment rate. Feature consistency regularization simulates various possible code deformations through data augmentation, greatly expanding the diversity of training samples and improving the generalization ability of the model when facing unknown deformation patterns.
[0132] Figure 3For the mixed deformation code recognition accuracy comparison chart, the horizontal axis represents the mixed deformation complexity (the mixed proportion of variable substitution and control flow reconstruction); the vertical axis represents the recognition accuracy. In the figure, three methods are compared: the application (mixed deformation recognition subnetwork), the traditional CNN+LSTM method and the CodeBERT model. As can be seen from the chart, as the mixed deformation complexity increases, the recognition accuracy of all methods shows a downward trend, but the decline of the application method is the smallest, and it always maintains a high recognition accuracy. It is fully proved that the application has a significant advantage in dealing with complex mixed deformation codes, especially in the case of high complexity mixed deformation.
[0133] The application designs an innovative mixed deformation recognition subnetwork structure, realizes multi-level feature extraction through a feature pyramid network, and processes local deformation and global reconstruction features through a double-flow feature fusion network. The core innovation lies in the adaptive feature fusion mechanism realized by the dynamic gating unit, which can intelligently adjust the weights of different types of features according to the feature importance coefficient. It effectively solves the technical problem of recognition difficulty of traditional code similarity analysis methods in the face of mixed deformation containing variable substitution and control flow reconstruction, and greatly improves the detection accuracy of carefully designed complex plagiarism behavior.
[0134] In an optional implementation, in the training stage, the steps of automatically constructing a multi-level adversarial sample library based on heuristic rules include:
[0135] The variable naming similarity is calculated based on the longest common subsequence, and the usage pattern similarity is calculated based on the variable usage context set. The variable naming similarity and the usage pattern similarity are combined through a balance coefficient to generate a variable mapping matrix;
[0136] The variable substitution probability is calculated based on the variable mapping matrix, the variable substitution sample is generated according to the variable substitution probability, the control flow reconstruction sample is generated based on the loop transformation function and the branch recombination metric, and the mixed deformation sample is generated by combining the variable substitution sample and the control flow reconstruction sample through a mixed weight coefficient;
[0137] A hierarchical sample index structure is constructed, and the variable substitution sample, the control flow reconstruction sample and the mixed deformation sample are stored in different levels respectively. The sample difficulty is calculated based on the variable complexity, the structure complexity and the mixed complexity, and the samples in different levels are organized according to the sample difficulty;
[0138] The recognition error rate of the statistical model for different levels of samples is calculated, the sample importance is calculated by adjusting the coefficient based on the recognition error rate and the sample difficulty, and the samples in the hierarchical sample index structure are dynamically updated based on the sample importance;
[0139] The sampling probability is calculated according to the average importance of different levels of samples, the training batch samples are selected from the hierarchical sample index structure based on the sampling probability, the model is trained by using cross-entropy loss and multi-task learning target, and the learning rate is adaptively adjusted based on the average recognition error rate of the batch samples.
[0140] For example, for two variable names A and B, they are decomposed into character sequences, such as variable names "countTotal" and "totalCount" are decomposed into character sequences "c-o-u-n-t-T-o-t-a-l" and "t-o-t-a-l-C-o-u-n-t", respectively. The naming similarity is obtained by calculating the length of the longest common subsequence of the two sequences (in this case, "o-t-a-l" and "c-o-u-n-t", with a length of 9) divided by the average length of the two sequences, for example, 9 / ((10+10) / 2)=0.9. For variable usage context, the three lines of code before and after each variable is used in the code as context. For example, the usage context of variable x includes "x=y+1;", "if(x>10){" and the like. The usage pattern similarity is obtained by calculating the Jaccard similarity of the two variable context sets, for example, the two variables have 5 similar contexts, and the total number of contexts is 8 and 7, respectively, so the similarity is 5 / 10=0.5. The naming similarity and usage pattern similarity are combined by a balance coefficient of 0.7 to obtain the final variable mapping matrix value of 0.7x0.9+0.3x0.5=0.78.
[0141] For each pair of variables (i, j), the replacement probability is proportional to the value in the mapping matrix, and the final replacement probability is obtained by multiplying the mapping matrix value by the basic replacement rate (default is 0.5). For example, for a variable pair with a mapping value of 0.78, the replacement probability is set to 0.78x0.5=0.39, indicating that there is a 39% probability of replacement when generating samples. When generating variable replacement samples, all variables in the code are traversed, and a random number between 0 and 1 is generated for each variable. If the random number is less than the replacement probability of the variable, the replacement operation is performed. When replacing, the target variable with the highest similarity is selected according to the mapping matrix, while ensuring that the variable name after replacement does not conflict in the current scope. For example, "countTotal" in the original code is replaced with "totalCount", and all reference positions are modified.
[0142] For control flow restructuring samples, the loop transformation function is a mapping table structure containing multiple transformation rules, mainly including four types of transformations: for-to-while, while-to-for, do-while-to-while, and nested loop unrolling. Each type of transformation defines specific pattern matching rules and transformation templates. For example, the for-to-while transformation rule includes: identifying the initialization statement, condition expression, and iteration statement of the for loop, then moving the initialization statement to the front of the loop, taking the condition expression as the condition of the while loop, and moving the iteration statement to the end of the loop body. For example, "for (int i = 0; i < 10; i++) { sum += i;}" is transformed into "int i = 0; while (i < 10) { sum += i; i++;}". The branch restructuring metrics include four basic operations: condition negation and branch exchange, split complex condition, merge adjacent conditions, and extract common code. Each operation is assigned a complexity score to comprehensively evaluate the restructuring difficulty of the structure. For example, transforming "if (x > 0) { A} else { B} " into "if (x <= 0) { B} else { A} " uses the condition negation and branch exchange operation.
[0143] The hybrid transformation sample combines the first two types of transformations by a mixing weight coefficient λ (0 ≤ λ ≤ 1). The specific implementation is to first determine the degree of application of variable substitution according to the λ value, and then apply control flow restructuring with a proportion of (1-λ). For example, when λ = 0.6, first apply variable substitution with a strength of 60% (i.e., multiply the variable substitution probability by 0.6), and then apply control flow restructuring with a strength of 40% (select 40% of the restructurable control flow for transformation).
[0144] When constructing the hierarchical sample index structure, the variable substitution samples are stored in the first layer, the control flow restructuring samples are stored in the second layer, and the hybrid transformation samples are stored in the third layer. The variable complexity is calculated by the number and importance of the replaced variables, for example, the complexity of a sample that replaces 5 core variables is 5 x 1.2 = 6. The structure complexity is calculated by the number and nesting depth of the restructured control flow structures, for example, restructuring 3 control flow structures with a nesting depth of 2 has a complexity of 3 x 2 = 6. The hybrid complexity is the weighted sum of the variable complexity and the structure complexity, for example, 0.5 x 6 + 0.5 x 6 = 6. According to these complexity metrics, the samples in different layers are organized, for example, in the first layer, samples with a complexity of 1-3 are classified as simple, 4-7 as medium, and 8 and above as complex.
[0145] The statistical model identifies the error rate of samples at different levels, for example, the error rate of the model for the first layer simple group sample is 10%, the medium group is 25%, and the complex group is 40%. The recognition error rate and the sample difficulty are calculated by adjusting the coefficient 0.8 to calculate the sample importance, for example, for a sample with a complexity of 6 and an error rate of 25%, the importance is 0.8x6+0.2x25=7.8. Based on these importance values, the hierarchical sample index structure is dynamically updated, for example, samples with an importance greater than 8 are promoted to a higher priority, and samples with an importance less than 3 are reduced in priority or removed.
[0146] The sampling probability is calculated based on the average importance of samples at different levels, for example, the average importance of the first layer is 5, the second layer is 7, and the third layer is 9, and the total is 21, then the sampling probability of the three layers is 5 / 21≈0.24, 7 / 21≈0.33, and 9 / 21≈0.43. Based on these probabilities, a training batch sample is selected from the hierarchical sample index structure, for example, in a batch of size 100, 24 samples are selected from the first layer, 33 samples are selected from the second layer, and 43 samples are selected from the third layer. The cross-entropy loss function is used to calculate the difference between the model prediction and the true label, and a multi-task learning goal is introduced, such as simultaneously predicting the function category and security risk level of the code. Based on the average recognition error rate of the batch sample, the learning rate is adaptively adjusted, for example, when the average error rate is higher than 30%, the learning rate is reduced to 0.8 times the original; when the average error rate is less than 10%, the learning rate is increased to 1.2 times the original, ensuring that the model can effectively learn the features of the adversarial samples during training.
[0147] Figure 4 The identification accuracy comparison chart for the adversarial sample training method, the horizontal axis of the chart presents three different code transformation identification scenarios: variable replacement identification, control flow reconstruction identification, and mixed transformation identification; the vertical axis represents the identification accuracy percentage, from 0% to 80%. Through the bar chart comparison, it can be clearly seen that the present invention (hierarchical adversarial training) method performs best in all three transformation identification scenarios. Specifically: in the variable replacement identification task and the control flow reconstruction identification task, the present invention method is significantly higher than the traditional random sampling training and the basic adversarial training. In the most challenging mixed transformation identification task, the accuracy of the present invention method is 57.5%, while the traditional random sampling training is only 22.5% and the basic adversarial training is 37.0%. The hierarchical adversarial training method of the present invention has obvious technical advantages in all test scenarios, especially in dealing with complex scenarios such as control flow reconstruction and mixed transformation, the improvement compared with traditional methods is more significant.
[0148] The application establishes a sample importance evaluation system based on recognition error rate and sample difficulty, realizes dynamic updating and priority adjustment of training samples. Adaptive calculation of sampling probability and dynamic adjustment of learning rate further optimize the model training process, solving the problems of insufficient adversarial samples, uneven sample difficulty distribution and low training efficiency in traditional code similarity model training. This hierarchical and adaptive adversarial training framework significantly enhances the model's recognition ability and generalization ability for various transformation strategies.
[0149] In an optional embodiment, the steps of calculating the similarity between the code to be detected and other examinee answers using the code similarity measurement model, clustering the examinee answers based on the similarity results, identifying and positioning the suspected plagiarism code fragments, and generating a comparison analysis report include:
[0150] The code similarity measurement model is used to calculate the similarity scores of the to-be-detected code and other examinee answers in three dimensions of variable substitution similarity, control flow reconstruction similarity, and mixed transformation similarity, respectively.
[0151] A similarity feature matrix is constructed based on the similarity scores in the three dimensions, and a density clustering algorithm is used to cluster the examinee answers to obtain code groups with similar behavior characteristics.
[0152] The codes in each code group are compared in pairs, the local similarity of the code fragments is calculated based on the similarity feature matrix, and the code fragments with local similarity exceeding a preset similarity threshold are marked as suspected plagiarism fragments.
[0153] The number and distribution of suspected plagiarism fragments in each examinee answer are counted, and risk level evaluation results are generated based on the similarity scores in the three dimensions.
[0154] A comparison analysis report containing similarity analysis results, suspected plagiarism fragment positioning information, and risk level evaluation results is generated.
[0155] Each code is evaluated from three dimensions of variable substitution similarity, control flow reconstruction similarity, and mixed transformation similarity. For variable substitution similarity, the score is calculated based on the variable mapping probability matrix output by the aforementioned local transformation identification subnetwork; for control flow reconstruction similarity, the graph structure similarity result of the global reconstruction identification subnetwork is used; for mixed transformation similarity, the output score of the mixed transformation identification subnetwork is used. For example, the three-dimensional similarity score of a pair of codes A and B may be: variable substitution similarity 0.85, control flow reconstruction similarity 0.62, and mixed transformation similarity 0.74, which indicates that the two codes have high variable substitution behavior and also have a certain degree of control flow change.
[0156] Based on the three-dimensional similarity scores, a similarity feature matrix is constructed. Assuming there are 100 examinee answers, a 100x100x3 feature matrix is generated, where each position [i,j,k] represents the similarity score of the ith code with the jth code in the kth dimension (k=0,1,2 corresponds to the three similarity types). DBSCAN (Density-Based Spatial Clustering Algorithm) is used to cluster these feature vectors, with the density parameter ε set to 0.15 and the minimum sample size set to 3. During clustering, each code is treated as a point in a three-dimensional space, with its coordinates determined by the average similarity of its three dimensions. For example, a certain code has an average variable replacement similarity of 0.4, an average control flow restructuring similarity of 0.3, and an average mixed deformation similarity of 0.5, so its coordinates are (0.4, 0.3, 0.5). After clustering, multiple code groups are identified, and the codes within each group are close to each other in the three-dimensional similarity space, with similar behavior characteristics. For example, it may identify a group of 5 codes that all use similar variable replacement and control flow restructuring strategies.
[0157] When comparing codes within each code group, the focus is no longer on global similarity, but rather on code segment level. First, the code is divided into multiple segments by function or code block, and then the local similarity between each pair of segments is calculated. Local similarity calculation uses sliding window technology, with a window size of 10 lines of code and a step size of 5 lines. For each window position, the feature vector of the current code segment is extracted and compared with all window positions of another code, and the highest similarity and its position are recorded. For example, the 20th-30th line of code A has a local similarity of 0.92 with the 35th-45th line of code B, which is much higher than their global similarity of 0.75, which may indicate that this code is directly copied. Code segments with local similarity exceeding a pre-set threshold (usually set to 0.85) are marked as suspected plagiarism segments, and are highlighted in the visualization interface.
[0158] The number and distribution of suspected plagiarism segments in each code are counted. For example, 30% of the content in code A is marked as suspected plagiarism, mainly concentrated in the core algorithm implementation part; while 45% of the content in code B is marked, with a more scattered distribution. Combined with the three-dimensional similarity scores, risk level assessment results are generated. Risk levels are usually divided into four levels: low risk (similarity less than 0.5, suspected plagiarism segment proportion less than 10%), medium risk (similarity between 0.5-0.7, or suspected plagiarism segment proportion between 10%-25%), high risk (similarity between 0.7-0.85, or suspected plagiarism segment proportion between 25%-50%), and extremely high risk (similarity higher than 0.85, or suspected plagiarism segment proportion higher than 50%).
[0159] Finally, a comparison analysis report containing multiple parts is generated, showing overall statistical information including the number of detected similar code groups, the distribution of code quantity at each risk level, and typical cases. For each pair of similar codes, a three-dimensional similarity radar chart, a code comparison view of suspected plagiarism fragments (with color depth indicating similarity), and a transformation type analysis are provided. For example, the report may state: "Code A and B have a similarity of 0.82, belonging to the high-risk level; mainly using variable substitution and loop unrolling transformation, where lines 125-157 are highly similar to the opponent's code lines 98-130 (similarity 0.96), suspected of direct copying followed by variable renaming."
[0160] The present application can effectively deal with various transformation methods in code plagiarism, providing educational institutions with an objective and reliable code plagiarism detection tool, and improving the fairness and effectiveness of programming teaching.
[0161] In a second aspect of the embodiments of the present application, an examination answer code similarity intelligent comparison and analysis system is provided, comprising:
[0162] A first unit is configured to adaptively determine the optimal insertion position based on code complexity and feature path analysis of the examination answer code to be detected, and insert probe code for recording execution information at conditional branch points, loop structure points, and feature calculation points; execute the inserted code, collect the execution path sequence and memory access mode of the program, capture the execution timing dependency relationship between code fragments through timing correlation analysis, and construct a dynamic behavior feature vector;
[0163] A second unit is configured to extract the static structural features of the examination answer code to be detected; and perform feature fusion on the static structural features and the dynamic behavior feature vector to construct a unified code representation;
[0164] A third unit is configured to construct a code similarity measurement model based on the unified code representation using a feature encoding network and an adversarial discriminant network, wherein the adversarial discriminant network includes a local transformation recognition sub-network, a global reconstruction recognition sub-network, and a mixed transformation recognition sub-network, which are respectively used to recognize variable substitution type transformation, control flow reconstruction type transformation, and mixed type transformation; in the training stage, a multi-level adversarial sample library is automatically constructed based on heuristic rules, variable substitution samples, control flow reconstruction samples, and mixed transformation samples are generated, and the recognition ability of the code similarity measurement model for different plagiarism strategies is improved through adversarial training;
[0165] A fourth unit is configured to calculate the similarity between the code to be detected and other examinee answers using the code similarity measurement model, identify and locate the suspected plagiarized code fragments, and generate a comparison analysis report.
[0166] In a third aspect of the embodiments of the present application, an electronic device is provided, comprising:
[0167] a processor;
[0168] a memory for storing processor-executable instructions;
[0169] wherein the processor is configured to invoke the instructions stored by the memory to perform the method as described above.
[0170] In a fourth aspect, the present application provides a computer readable storage medium having stored thereon computer program instructions, which when executed by a processor implement the method as described above.
[0171] The present application can be a method, an apparatus, a system, and / or a computer program product. The computer program product can include a computer readable storage medium having computer readable program instructions stored therein, which when executed by a processor, perform various aspects of the present application.
[0172] It should be noted that the above-mentioned embodiments are merely used to illustrate the technical solutions of the present application, rather than limiting the present application; although the present application has been described in detail with reference to the above-mentioned embodiments, those skilled in the art should understand that the technical solutions recorded in the above-mentioned embodiments can be modified or equivalent replacements can be made to some or all of the technical features; and the modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of the present application.
Claims
1. An intelligent comparison and analysis method for exam answer code similarity, characterized in that, include: The exam answer code to be tested adaptively determines the optimal instrumentation position based on code complexity and feature path analysis. After the instrumentation is executed, the execution path sequence and memory access pattern of the program are collected. Temporal correlation analysis is used to capture the execution temporal dependencies between code segments, constructing a dynamic behavior feature vector. This includes: constructing a temporal execution graph containing multiple execution units, where edges in the graph represent temporal dependencies between execution units; calculating the temporal dependency strength of the edges in the graph, determined by temporal occurrence frequency and time interval features; generating a multi-order subgraph pattern based on the temporal dependency strength; and calculating the multi-order subgraph pattern's... The support is obtained by the ratio of the number of occurrences in the execution trajectory to the total number of execution trajectories; an adversarial verification network is constructed, and adversarial examples are generated by randomly perturbing the execution sequence. The stability coefficient is calculated based on the support difference of subgraph patterns in the original execution sequence and the adversarial examples; a significance score is calculated based on a weighted combination of the support, the temporal dependency strength, and the stability coefficient; temporal features of the temporal execution graph are extracted, including temporal pattern features calculated based on the temporal dependency strength, the significance score, and the execution sequence entropy; a dynamic behavior feature vector is constructed by weighted fusion of the path features of the execution path sequence, the memory features of the memory access pattern, and the temporal features. Extract the static structural features of the exam answer code to be detected; fuse the static structural features with the dynamic behavior feature vector to construct a unified code representation; Based on the unified code representation, a code similarity measurement model is constructed using a feature encoding network and an adversarial discriminant network. The adversarial discriminant network includes a local deformation recognition subnetwork, a global reconstruction recognition subnetwork, and a hybrid deformation recognition subnetwork, which respectively identify variable substitution deformation, control flow reconstruction deformation, and hybrid deformation. During the training phase, a multi-level adversarial sample library is automatically constructed based on heuristic rules to generate variable substitution samples, control flow reconstruction samples, and hybrid deformation samples. The code similarity measurement model is used to calculate the similarity between the code to be detected and other candidates' answers, identify and locate suspected plagiarized code segments, and generate a comparison analysis report.
2. The method according to claim 1, characterized in that, The steps for adaptively determining the optimal instrumentation position for the exam answer code to be tested, based on code complexity and feature path analysis, include: A multi-dimensional code complexity index is established, which includes a structural complexity index and a data flow complexity index. Based on the multi-dimensional code complexity index, a path feature vector is constructed, which contains the type features of each node on the path and its corresponding weight. The path feature vector is used to calculate the path importance according to the path complexity, execution frequency, and data dependency, and to identify program execution paths including conditional branch points, loop structure points, and feature calculation points. Candidate instrumentation points on the program execution path are evaluated, and the importance of the probe insertion position is determined by calculating the information gain of the original system entropy and the conditional entropy after the probe is inserted. Based on the importance of the candidate instrumentation points, the probe density is calculated in combination with the code segment length and local complexity weight, and the instrumentation position is optimized and selected. Lightweight probes are designed at optimized insertion locations, and the time overhead, memory overhead, and input / output overhead of the lightweight probes are calculated. The probe sampling frequency is adaptively adjusted based on the ratio of the current overhead to the target overhead threshold.
3. The method according to claim 1, characterized in that, Extract the static structural features of the exam answer codes to be detected; The steps of fusing the static structural features with the dynamic behavioral feature vector to construct a unified code representation include: Extract the abstract syntax tree of the exam answer code, and construct a data flow graph and a control flow graph based on the abstract syntax tree; extract lexical features from the abstract syntax tree, the lexical features including code identifier sequences, reserved word sequences and operator sequences; Data flow features are extracted from the data flow graph, including variable definition-usage chains, type distribution of data dependency edges, and depth distribution of data flow paths; control flow features are extracted from the control flow graph, including topological sequence of basic blocks, nested loop depth, and branch structure complexity. The static structural features are obtained by weighted combination of the lexical features, the data flow features, and the control flow features; An attention fusion network is constructed, using the static structural features as query vectors and the dynamic behavioral feature vectors as key-value pairs. The fusion attention weights are obtained by calculating the correlation between the query vectors and key-value pairs. Based on the fusion attention weights, the static structural features and dynamic behavioral feature vectors are adaptively fused to obtain a unified code representation.
4. The method according to claim 1, characterized in that, Based on the unified code representation, a code similarity measurement model is constructed using a feature encoding network and an adversarial discriminant network. The adversarial discriminant network includes a local deformation recognition subnetwork, a global reconstruction recognition subnetwork, and a hybrid deformation recognition subnetwork. The steps for recognizing variable substitution deformations, control flow reconstruction deformations, and hybrid deformations respectively include: A feature encoding network is constructed using a multilayer perceptron, and the unified code representation is dimensionality-reduced to obtain an encoding vector. The encoding vector is then processed by L2 regularization constraints and feature normalization. A local deformation recognition subnetwork is constructed. Based on the variable, the variable feature vector is extracted using the position matrix. The variable similarity matrix is calculated. An attention mechanism is used to calculate the variable substitution probability and identify variable substitution deformation. A global reconstruction identification subnetwork is constructed, basic block topological features are extracted to construct a control flow similarity matrix, graph structure similarity is calculated based on the longest common subsequence, structural transformation distance of loop expansion and conditional recombination is analyzed, and control flow reconstruction-type deformations are identified. A hybrid deformation recognition subnetwork is constructed. Multi-level feature extraction and dual-flow feature fusion are used to jointly analyze variable substitution deformation features and control flow reconstruction deformation features. An adaptive feature fusion mechanism and multi-scale context aggregation are used for hybrid deformation recognition.
5. The method according to claim 4, characterized in that, The construction steps of the hybrid deformation recognition sub-network include: Multi-level feature extraction is performed on the input features to construct a feature pyramid network containing backbone features and lateral connection features; A dual-stream feature fusion network is constructed, and local deformation features are obtained through multilayer perceptron processing, while global reconstructed features are obtained through graph neural network processing. The local deformation features and the global reconstruction features are adaptively fused based on a dynamic gating unit. The dynamic gating unit calculates a gating vector using a learnable weight matrix and a bias vector, and uses a compressed excitation module to calculate the feature importance coefficients of the local deformation features and the global reconstruction features respectively. The local deformation features and the global reconstruction features are then weighted and fused according to the gating vector and the feature importance coefficients to obtain the fused features. An attention context pooling module is constructed, which calculates attention weights at multiple scales based on the fused features, extracts multi-scale context features from the fused features, adaptively fuses the context features at multiple scales, and performs residual connection with the fused features to obtain the final features. Based on the final features, the similarity and confidence scores of the hybrid deformation patterns are calculated, and the consistency of the final features under different data augmentation perspectives is constrained by feature consistency regularization.
6. The method according to claim 1, characterized in that, During the training phase, a multi-layered adversarial sample library is automatically constructed based on heuristic rules. The steps for generating variable substitution samples, control flow reconstruction samples, and hybrid deformable samples include: Variable naming similarity is calculated based on the longest common subsequence, and usage pattern similarity is calculated based on the variable usage context set. The variable naming similarity and usage pattern similarity are combined by balancing coefficients to generate a variable mapping matrix. Calculate the variable substitution probability based on the variable mapping matrix, generate variable substitution samples according to the variable substitution probability, generate control flow reconstruction samples based on the loop transformation function and branch reorganization metric, and combine the variable substitution samples and control flow reconstruction samples through a hybrid weighting coefficient to generate a hybrid deformed sample. A hierarchical sample index structure is constructed, and the variable substitution samples, control flow reconstruction samples, and hybrid deformation samples are stored in different levels respectively. The sample difficulty is calculated based on variable complexity, structural complexity, and hybrid complexity, and the samples at different levels are organized according to the sample difficulty. The statistical model calculates the recognition error rate of samples at different levels, and uses the recognition error rate and the sample difficulty to calculate the sample importance through an adjustment coefficient. Based on the sample importance, the samples in the hierarchical sample index structure are dynamically updated. The sampling probability is calculated based on the average importance of samples at different levels. Training batch samples are selected from the hierarchical sample index structure based on the sampling probability. The model is trained using cross-entropy loss and multi-task learning objective. The learning rate is adaptively adjusted based on the average recognition error rate of the batch samples.
7. An intelligent comparison and analysis system for exam answer code similarity, used to implement the method of any one of claims 1-6, characterized in that, include: The first unit uses the exam answer code to be tested. Based on code complexity and feature path analysis, it adaptively determines the optimal instrumentation position and inserts probe code to record execution information at conditional branch points, loop structure points, and feature calculation points. After the instrumentation is executed, the program's execution path sequence and memory access pattern are collected. Through temporal correlation analysis, the execution temporal dependencies between code segments are captured, and a dynamic behavior feature vector is constructed. The second unit is used to extract the static structural features of the exam answer codes to be detected; The static structural features and the dynamic behavioral feature vectors are fused to construct a unified code representation; The third unit is used to construct a code similarity measurement model based on the unified code representation, using a feature encoding network and an adversarial discriminant network. The adversarial discriminant network includes a local deformation recognition subnetwork, a global reconstruction recognition subnetwork, and a hybrid deformation recognition subnetwork, which respectively identify variable substitution deformation, control flow reconstruction deformation, and hybrid deformation. During the training phase, a multi-level adversarial sample library is automatically constructed based on heuristic rules to generate variable substitution samples, control flow reconstruction samples, and hybrid deformation samples. Adversarial training is used to improve the code similarity measurement model's ability to identify different plagiarism strategies. The fourth unit is used to calculate the similarity between the code to be detected and other candidates' answers using the code similarity measurement model, identify and locate suspected plagiarized code segments, and generate a comparison analysis report.
8. An electronic device, characterized in that, include: processor; Memory used to store processor-executable instructions; The processor is configured to invoke instructions stored in the memory to execute the method according to any one of claims 1 to 6.
9. A computer-readable storage medium having computer program instructions stored thereon, characterized in that, When the computer program instructions are executed by the processor, they implement the method described in any one of claims 1 to 6.
Citation Information
Patent Citations
Deep learning code plagiarism detection method based on multi-head attention mechanism
CN116738963A
Method and system for quickly constructing and multiplexing application framework
CN119576290A