A machine learning based code annotation generation and verification method

By constructing a structured representation of code units and generating candidate annotation text using a pre-trained model, parsing it into a set of atomic assertions and calculating a consistency score, the problem of unstable consistency scores and insufficient robustness in code annotation generation and verification is solved, achieving efficient annotation updating and maintenance.

CN122173135APending Publication Date: 2026-06-09TIBET TENGSHI SOFTWARE CO LTD

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
TIBET TENGSHI SOFTWARE CO LTD
Filing Date
2026-03-10
Publication Date
2026-06-09

AI Technical Summary

Technical Problem

Existing code comment generation and verification methods suffer from inconsistencies between comments and code semantics in engineering practice, lack a stable consistency scoring mechanism, struggle to maintain robustness when code form changes, and lack interpretable contribution location and editing correction capabilities.

Method used

By constructing a structured representation of the target code unit's abstract syntax tree, control flow graph, and data flow graph, and combining it with a pre-trained code semantic model, candidate annotation text is generated and parsed into a set of atomic assertions and a set of code facts. A consistency score is calculated, an equivalent view set is generated, and an improved SmoothGrad attribution calculation is used to locate the contribution. Discrete editing operators are used to generate corrected annotations, forming a closed loop of generation, verification, location, correction, and re-verification.

Benefits of technology

It enhances the semantic dependency representation capability of the annotation generation process, realizes quantifiable assessment and localizable determination of the consistency between annotation and code semantics, reduces comprehension bias and maintenance risks, and improves the accuracy and efficiency of annotation updates.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122173135A_ABST
    Figure CN122173135A_ABST
Patent Text Reader

Abstract

This invention discloses a machine learning-based code annotation generation and verification method, comprising the following steps: Step 1: Determine the target code unit and construct an abstract syntax tree, control flow graph, and data flow graph; Step 2: Encode the target code unit to generate candidate annotation text; Step 3: Parse the candidate annotation text to obtain a set of atomic assertions and extract a set of code facts; Step 4: Calculate the consistency score and determine the core conflict set; Step 5: Perform semantic preservation transformation to generate an equivalent view set and an equivalence evidence set, and delete invalid equivalent views; Step 6: Limit the interpretation domain and perform improved SmoothGrad attribution on the consistency score to generate contribution location results; Step 7: Generate candidate edit sequences and output corrected annotations; Step 8: Calculate the re-verification consistency score and generate annotation update records. This invention improves annotation consistency and interpretability verification capabilities.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of computer software technology, and in particular to a method for generating and verifying code comments based on machine learning. Background Technology

[0002] In software development and maintenance, code comments are used to describe the functional meaning, input / output constraints, abnormal behavior, and side effects of target code units. Developers typically rely on comments to quickly understand the semantics of the program when reading source code. However, with increasing code size and frequent version iterations, the writing and updating of comments mainly rely on manual work. The content of comments is significantly influenced by personal experience and writing habits, resulting in common issues such as missing comments, non-standard expressions, and inconsistencies with the source code. To reduce manual costs, existing technologies are beginning to introduce machine learning methods to generate comments. These methods encode the source code and output natural language token sequences to obtain candidate comment text. Application scenarios cover functions, methods, classes, and predefined statement blocks, and comment generation is gradually becoming an important auxiliary means in code understanding and documentation maintenance.

[0003] Existing annotation generation and checking methods mostly use source code tag sequences as the main input. Some methods introduce abstract syntax trees, control flow graphs, and data flow graphs as structured representations to enhance the modeling ability of program structure and semantic dependencies. However, in engineering practice, the problem of inconsistency between annotations and code semantics still exists. Candidate annotation texts often contain descriptions of input and output conditions, branch paths, and exception triggering conditions. Simply relying on language models for generation can easily lead to missing semantic key points or description biases. On the other hand, existing consistency detection often uses text similarity or shallow rule matching, lacking a unified modeling process that parses candidate annotation texts into atomic assertion sets and extracts code fact sets from target code units. It is difficult to form assertion representations and fact representations and establish matching indexes, resulting in the inability to clearly express support and conflict relationships. Consistency scores lack a stable computational foundation, the core set of conflicts is difficult to locate accurately, and annotation maintenance cannot form a verifiable closed loop.

[0004] Meanwhile, semantically preserving program transformations often occur during source code refactoring and optimization, such as variable renaming, dead code deletion, constant propagation, equivalent expression substitution, conditional equivalent transformation, equivalent loop rewriting, and statement reordering. Existing technologies lack robustness to such changes and lack a mechanism for determining the pass rate of equivalent view sets and equivalence evidence sets, causing consistency judgments to fluctuate easily with changes in code form. Even if inconsistencies can be detected, many methods cannot provide contribution location results within the interpretation domain limited by the conflict core set, lack interpretable attribution calculations based on improved SmoothGrad, and cannot map the source of inconsistency to abstract syntax tree nodes, data flow edges, and control flow paths. Consequently, they cannot form an executable set of discrete editing operators and a set of candidate editing sequences, making it difficult to generate correction comments and complete the verification of consistency scores and comment update record generation under editing cost constraints, resulting in insufficient connection between comment generation, verification, and correction.

[0005] Therefore, how to provide a machine learning-based code annotation generation and verification method is a problem that urgently needs to be solved by those skilled in the art. Summary of the Invention

[0006] One objective of this invention is to propose a machine learning-based code annotation generation and verification method. This invention fully utilizes pre-trained code semantic models and structured representations such as abstract syntax trees, control flow graphs, and data flow graphs to complete candidate annotation generation, atomic assertions and code fact extraction, consistency scoring and conflict core determination. It also combines semantically preserving program transformations to generate equivalent views and equivalence evidence, employs an improved SmoothGrad attribution calculation to locate contributions, and uses discrete editing operators to generate corrected annotations and verify consistency scores to generate annotation update records. This method has the advantages of high consistency, strong interpretability, and high annotation maintenance efficiency.

[0007] A method for generating and validating code comments based on machine learning according to an embodiment of the present invention includes the following steps: Step 1: Obtain the source code and identify the target code unit, then construct the abstract syntax tree, control flow graph, and data flow graph of the target code unit; Step 2: Encode the target code unit based on the pre-trained code semantic model to generate candidate annotation text; Step 3: Parse the candidate comment text into a set of atomic assertions and extract a set of code facts from the target code unit; Step 4: Calculate the consistency score based on the set of atomic assertions and the set of code facts to determine the core conflict set; Step 5: Perform semantic-preserving procedural transformation on the target code unit to generate an equivalent view set, generate an equivalence evidence set for the equivalent view set, and delete equivalent views that do not pass the equivalence evidence set; Step 6: Based on the conflict core set to limit the interpretation domain, perform improved SmoothGrad attribution calculation on the consistency score to generate contribution location results. The contribution location results correspond to abstract syntax tree nodes, data flow edges, and control flow paths. Step 7: Based on the set of discrete edit operators, map the contribution location results to a set of candidate edit sequences, select the candidate edit sequences with the minimum editing cost and whose consistency scores meet the consistency threshold, and generate corrected annotations; Step 8: Calculate the re-verification consistency score based on the corrected comments and target code units. When the re-verification consistency score meets the consistency threshold, generate the comment update record.

[0008] Optionally, step one specifically includes: Obtain the source code and identify the target code unit, which includes one of the following: function, method, class, or predefined statement block. Determine the start and end positions of the target code unit in the source code. An abstract syntax tree is constructed based on the target code unit. The abstract syntax tree contains a set of abstract syntax tree nodes and a set of abstract syntax tree edges. The set of abstract syntax tree nodes includes declaration nodes, statement nodes, and expression nodes. The set of abstract syntax tree edges represents the parent-child relationship between nodes. A control flow graph is constructed based on the target code unit. The control flow graph contains a set of basic block nodes and a set of control flow edges. The set of control flow edges represents the sequential execution relationship and branch jump relationship between basic blocks. A data flow graph is constructed based on the target code unit. The data flow graph contains a set of nodes consisting of variable nodes and statement nodes, and a set of data flow edges. The set of data flow edges represents the dependency relationship from variable definition to variable usage. Abstract syntax trees, control flow graphs, and data flow graphs constitute a structured representation of the target code unit.

[0009] Optionally, step two specifically involves: The model input is constructed based on the source code and structured representation of the target code unit. The structured representation includes an abstract syntax tree, a control flow graph, and a data flow graph. The model input contains the source code tag sequence and the corresponding node and edge information of the structured representation. The model is input into a pre-trained code semantic model, which encodes the source code tag sequence and node and edge information to obtain the code semantic representation of the target code unit. Annotations are generated based on code semantic representation, and tags are output according to the generation order of natural language tags. The tags form candidate annotation text.

[0010] Optionally, step three specifically includes: The candidate annotation text is parsed to extract the semantic points in the candidate annotation text and form a set of atomic assertions. The set of atomic assertions contains atomic assertions, and each atomic assertion contains assertion type, assertion object, and assertion constraint. Fact extraction processing is performed on the target code unit. Syntax-related facts are extracted based on the abstract syntax tree, control-related facts are extracted based on the control flow graph, and data-related facts are extracted based on the data flow graph to form a code fact set. The atomic assertion set and the code fact set are converted into input representations for consistency score calculation, assertion representations and fact representations are generated, and a matching index for assertion representations and fact representations is established.

[0011] Optionally, step four specifically involves: Consistency matching is performed between assertion representations and fact representations. The assertion representations and fact representations are aligned according to the matching index to obtain a set of supporting relations and a set of conflicting relations. The set of supporting relations indicates that the fact representations satisfy the assertion constraints, and the set of conflicting relations indicates that the fact representations violate the assertion constraints. A consistency score is calculated based on the set of supporting relationships and the set of conflicting relationships. The consistency score is calculated according to a preset scoring function, which includes a support scoring item and a conflict deduction item. The support scoring item is calculated based on the number of matches in the set of supporting relationships, and the conflict deduction item is calculated based on the number of matches in the set of conflicting relationships. The conflict core set is determined based on the conflict relationship set. The conflict core set includes atomic assertions from the set of atomic assertions that constitute the conflict relationship and code facts from the set of code facts.

[0012] Optionally, step five specifically includes: Semantic preservation procedural transformations are performed on the target code unit to generate an equivalent view set. The semantic preservation procedural transformations include variable renaming, dead code removal, constant propagation, expression equivalence substitution, conditional equivalence transformation, loop equivalence rewriting, and statement reordering. The semantic preservation procedural transformations are applied to the target code unit to obtain the transformed code unit, and the transformed code unit is used as an equivalent view in the equivalent view set. Generate an equivalence evidence set for the set of equivalent views. The equivalence evidence set contains the equivalent view identifier and evidence items. The evidence items include type consistency evidence, control flow consistency evidence, and data flow consistency evidence. The type consistency evidence is generated from the type check results of the equivalent view. The control flow consistency evidence is generated from the consistency of the reachability relationship between the control flow graph of the equivalent view and the control flow graph of the target code unit. The data flow consistency evidence is generated from the consistency of the definition relationship and usage relationship between the data flow graph of the equivalent view and the data flow graph of the target code unit. Delete equivalent views that fail the equivalence evidence set. Determine the pass status of the equivalent view based on the judgment result of the evidence item. The judgment result of the evidence item includes pass and fail. Equivalent views with the fail status are deleted from the equivalent view set, while equivalent views with the pass status are retained in the equivalent view set.

[0013] Optionally, step six specifically includes: The interpretation domain is defined based on the conflict core set. The set of abstract syntax tree nodes, data flow edge set, and control flow path set in the interpretation domain are determined according to the matching index. The set of abstract syntax tree nodes contains the abstract syntax tree nodes that form a matching relationship with the atomic assertions in the conflict core set. The set of data flow edge sets contains the data flow edges that form a matching relationship with the code facts in the conflict core set. The set of control flow path sets contains the control flow paths that form a matching relationship with the code facts in the conflict core set. An improved SmoothGrad attribution calculation is performed on the consistency score. The improved SmoothGrad attribution calculation includes: selecting the source code label sequence vector representation and node and edge information vector representation corresponding to the model input in the interpretation domain; generating a zero-mean noise vector based on a preset variance parameter and superimposing the zero-mean noise vector onto the source code label sequence vector representation and node and edge information vector representation to obtain a perturbation input; calculating the consistency score for the perturbation input and calculating the gradient of the consistency score with respect to the source code label sequence vector representation and node and edge information vector representation; repeating the calculation a preset number of times to obtain a gradient set and performing an arithmetic mean on the gradient set to obtain a smooth gradient; and performing an inner product summation on the smooth gradient and the source code label sequence vector representation and node and edge information vector representation to obtain a contribution score. The contribution score characterizes the degree of influence of the source code label sequence vector representation and node and edge information vector representation on the consistency score in the interpretation domain. The contribution positioning result is generated by mapping the contribution score to the abstract syntax tree node, data flow edge, and control flow path based on the abstract syntax tree node identifier, data flow edge identifier, and control flow path identifier in the node and edge information. The contribution positioning result includes the contribution score of the abstract syntax tree node, the contribution score of the data flow edge, and the contribution score of the control flow path.

[0014] Optionally, step seven specifically includes: Construct a set of discrete editing operators, which includes entity replacement operator, numerical correction operator, range correction operator, negation / affirmation reversal operator, condition completion operator, anomaly description completion operator, redundant phrase deletion operator, and terminology normalization operator, and set operator costs for the discrete editing operators in the set of discrete editing operators; A candidate edit sequence set is generated based on the contribution positioning results. The abstract syntax tree node identifier, data flow edge identifier, and control flow path identifier in the contribution positioning results are mapped to the edit position identifier in the candidate annotation text. The edit position identifier is used to indicate the natural language tag position range of the candidate annotation text. The candidate edit sequence set is formed by the discrete edit operator acting on the edit position identifier. The candidate edit sequence contains the discrete edit operator identifier, the edit position identifier, and the edit content. The candidate edit sequence set is selected and a correction annotation is generated. The candidate edit sequence is applied to the candidate annotation text to obtain the correction annotation candidate text. The consistency score is calculated based on the correction annotation candidate text and the target code unit, and it is determined that the consistency score meets the consistency threshold. The editing cost is obtained by accumulating the operator costs corresponding to the candidate edit sequence. The candidate edit sequence with the minimum editing cost and the consistency score that meets the consistency threshold is selected to generate the correction annotation.

[0015] Optionally, step eight specifically includes: The verification consistency score is calculated based on the correction comments and the target code unit. The correction comments are parsed into a set of atomic assertions and converted into assertion representations. The target code unit extracts a set of code facts and converts it into a fact representation. The assertion representations and fact representations are aligned according to the matching index to generate a set of support relations and a set of conflict relations. The verification consistency score is calculated based on the set of support relations and the set of conflict relations according to a preset scoring function. The consistency score of the retest is compared with the consistency threshold and the threshold determination is completed. The threshold determination result includes whether the consistency threshold is met or not. When the re-verification consistency score meets the consistency threshold, an annotation update record is generated. The annotation update record includes the start position of the target code unit, the end position of the target code unit, the corrected annotation, the re-verification consistency score, and the threshold determination result.

[0016] The beneficial effects of this invention are: This invention constructs target code units into structured representations of abstract syntax trees, control flow graphs, and data flow graphs, and combines this with a pre-trained code semantic model to generate candidate annotation text. This allows the annotation generation process to simultaneously utilize source code tag sequence information and node and edge information, thereby enhancing the annotation content's ability to represent program structure and semantic dependencies. In the verification phase, candidate annotation texts are parsed into a set of atomic assertions, and a set of code facts is extracted from the target code unit. These are further transformed into assertion representations and fact representations, and a matching index is established. Based on this, a set of support relations and a set of conflict relations are generated. A consistency score is calculated according to a preset scoring function, and the core conflict set is determined. This enables quantifiable evaluation and localizable determination of the semantic consistency between annotations and code, reducing misunderstanding biases and maintenance risks caused by inconsistencies between annotations and code.

[0017] This invention introduces a semantically preserving procedural transformation to generate an equivalent view set, and then generates an equivalence evidence set containing type consistency evidence, control flow consistency evidence, and data flow consistency evidence for this equivalent view set. Incompatible equivalent views are deleted, ensuring the consistency assessment remains stable despite changes in code form. Based on a conflict core set limiting the interpretation domain, an improved SmoothGrad attribution calculation is used to generate contribution location results and map them to abstract syntax tree nodes, data flow edges, and control flow paths, enhancing the interpretability and accuracy of inconsistency source location. Furthermore, a candidate edit sequence set is generated through a discrete edit operator set. The candidate edit sequence with the lowest editing cost and a consistency score meeting the consistency threshold is selected to generate corrected annotations. An annotation update record is generated when the re-verification consistency score meets the consistency threshold, thus forming a closed loop of generation—verification—location—correction—re-verification, improving the accuracy and efficiency of annotation updates. Attached Figure Description

[0018] The accompanying drawings are provided to further illustrate the invention and form part of the specification. They are used in conjunction with embodiments of the invention to explain the invention and do not constitute a limitation thereof. In the drawings: Figure 1 This is a flowchart of a machine learning-based code annotation generation and verification method proposed in this invention; Figure 2 This is a schematic diagram illustrating the structured representation construction of a machine learning-based code annotation generation and verification method proposed in this invention. Detailed Implementation

[0019] The present invention will now be described in further detail with reference to the accompanying drawings. These drawings are simplified schematic diagrams, illustrating only the basic structure of the invention, and therefore only show the components relevant to the invention.

[0020] refer to Figures 1-2 A machine learning-based code annotation generation and verification method includes the following steps: Step 1: Obtain the source code and identify the target code unit, then construct the abstract syntax tree, control flow graph, and data flow graph of the target code unit; Step 2: Encode the target code unit based on the pre-trained code semantic model to generate candidate annotation text; Step 3: Parse the candidate comment text into a set of atomic assertions and extract a set of code facts from the target code unit; Step 4: Calculate the consistency score based on the set of atomic assertions and the set of code facts to determine the core conflict set; Step 5: Perform semantic-preserving procedural transformation on the target code unit to generate an equivalent view set, generate an equivalence evidence set for the equivalent view set, and delete equivalent views that do not pass the equivalence evidence set; Step 6: Based on the conflict core set to limit the interpretation domain, perform improved SmoothGrad attribution calculation on the consistency score to generate contribution location results. The contribution location results correspond to abstract syntax tree nodes, data flow edges, and control flow paths. Step 7: Based on the set of discrete edit operators, map the contribution location results to a set of candidate edit sequences, select the candidate edit sequences with the minimum editing cost and whose consistency scores meet the consistency threshold, and generate corrected annotations; Step 8: Calculate the re-verification consistency score based on the corrected comments and target code units. When the re-verification consistency score meets the consistency threshold, generate the comment update record.

[0021] In this embodiment, step one specifically includes: Obtain the source code and determine the target code unit. Read the text content of the source code and perform syntax parsing on the source code to identify the boundary markers of functions, methods, classes, and predefined statement blocks. Extract the target code unit from the source code according to the boundary markers. Record the start and end positions of the target code unit in the source code. The start position is the offset of the first character or the position of the first line and first column of the target code unit, and the end position is the offset of the last character or the position of the last line and last column of the target code unit. An abstract syntax tree is constructed based on the target code unit. The target code unit is node-based using the syntax structure obtained from syntax parsing. Declarations, statements, and expressions in the syntax structure are mapped to declaration nodes, statement nodes, and expression nodes, respectively. Parent-child relationships between nodes are established according to the inclusion relationship of the syntax structure, forming an abstract syntax tree node set and an abstract syntax tree edge set. A control flow graph is constructed based on the target code unit. The target code unit is divided into basic blocks according to the sequential execution segments. The basic block node set is composed of each basic block. The sequential structure and branch structure in the target code unit are traversed. For the sequential structure, control flow edges with sequential execution relationship are established between adjacent basic blocks. For the branch structure, control flow edges with branch jump relationship are established between the basic block corresponding to the branch condition and each branch entry basic block, forming a control flow edge set. A data flow graph is constructed based on the target code unit. The location of variables in the target code unit is scanned, the location of variable definition and location of variable use are identified, variables are mapped to variable nodes, and statements containing variable definition and variable use are mapped to statement nodes. Data flow edges are established between corresponding nodes according to the dependency relationship from variable definition to variable use, forming a set of nodes and a set of data flow edges. Abstract syntax trees, control flow graphs, and data flow graphs constitute a structured representation of the target code unit. The structured representation includes the set of nodes and edges of the abstract syntax tree, the set of basic block nodes and control flow edges of the control flow graph, and the set of nodes and data flow edges of the data flow graph.

[0022] In this embodiment, step two specifically involves: The model input is constructed based on the source code and structured representation of the target code unit. The structured representation includes an abstract syntax tree, a control flow graph, and a data flow graph. The model input contains a source code tag sequence and the corresponding node and edge information of the structured representation. The source code tag sequence is obtained by performing tagging on the source code of the target code unit. The node and edge information is used to represent the node type and parent-child relationship of the abstract syntax tree, the basic block node and control flow edge relationship of the control flow graph, and the node and data flow edge relationship of the data flow graph. The source code tag sequence and node and edge information are combined into a unified input sequence or unified input structure according to a preset input organization method so that the subsequent encoding process can utilize both source code content information and structured representation information. The model input is fed into a pre-trained code semantic model, which encodes the source code label sequence and node and edge information to obtain the code semantic representation of the target code unit. The pre-trained code semantic model performs vectorization representation on the source code label sequence and node and edge information in the model input, and performs association modeling and fusion calculation within the model to output a code semantic representation that represents the semantic features of the target code unit. The code semantic representation is used to characterize the functional intent, key structural relationships and semantic dependencies related to the structured representation of the target code unit. Annotation generation is based on code semantic representation. Tags are output according to the order of natural language tag generation, and these tags form candidate annotated text. Code semantic representation is used as the generation condition. At each generation step, the predicted natural language tag for the current step is calculated based on the previously output natural language tag history and the code semantic representation. The natural language tag output at the current step is then appended to the generated sequence until a termination condition is met. Finally, the candidate annotated text is formed from the sequence of generated natural language tags.

[0023] In this embodiment, step three specifically includes: The candidate annotation text is parsed, including sentence segmentation and semantic point identification. The semantic points are mapped to a set of atomic assertions. The set of atomic assertions contains atomic assertions, and each atomic assertion contains assertion type, assertion object, and assertion constraint. The assertion type is used to identify the category of semantic point, the assertion object is used to identify the object to which the semantic point points, and the assertion constraint is used to identify the limiting conditions of the semantic point. The assertion type, assertion object, and assertion constraint are written into the atomic assertions to form a structured assertion record. Fact extraction processing is performed on the target code unit. The fact extraction processing includes traversing declaration nodes, statement nodes, and expression nodes based on the abstract syntax tree to extract syntax-related facts, traversing basic block nodes and control flow edges based on the control flow graph to extract control-related facts, and traversing variable nodes, statement nodes, and data flow edges based on the data flow graph to extract data-related facts. The syntax-related facts, control-related facts, and data-related facts are uniformly aggregated into a code fact set, and the target code unit location range information is recorded for each code fact in the code fact set to support the location of consistency score calculation. The atomic assertion set and the code fact set are converted into input representations for consistency score calculation. The conversion process includes encoding the atomic assertion set into assertion representations and encoding the code fact set into fact representations. The encoding results include key-value information corresponding to assertion type field, assertion object field, and assertion constraint field. A matching index is built based on assertion type, assertion object, and assertion constraint. The matching index is used to align assertion representations with fact representations to support matching and conflict detection in consistency score calculation.

[0024] In this embodiment, step four specifically includes: Consistency matching is performed based on assertion representations and fact representations. Consistency matching includes reading the assertion type field, assertion object field, and assertion constraint field from the assertion representation according to the matching index, and reading the corresponding fields from the fact representation. Alignment calculation is performed according to the field value equality relationship and the field value satisfaction relationship. The field value equality relationship is used to determine that the assertion object and the fact object are consistent, and the field value satisfaction relationship is used to determine that the fact constraint satisfies the assertion constraint. Based on the alignment calculation, a support relationship set and a conflict relationship set are generated. The support relationship set records the assertion representation identifier, the fact representation identifier, and the satisfaction judgment result, and the conflict relationship set records the assertion representation identifier, the fact representation identifier, and the violation judgment result. A consistency score is calculated based on the set of supporting relations and the set of conflicting relations. The consistency score is calculated according to a preset scoring function, which includes supporting scoring items and conflict deduction items. The supporting scoring items count and accumulate the weights of records in the supporting relation set that satisfy the judgment result. The conflict deduction items count and accumulate the weights of records in the conflicting relation set that violate the judgment result. The weights are determined by the value of the assertion type field. The consistency score is obtained based on the combined result of the supporting scoring items and the conflict deduction items. The conflict core set is determined based on the conflict relationship set. The process of determining the conflict core set includes deduplication and aggregation of the conflict relationship set. Deduplication is used to merge conflict records with the same assertion representation identifier and the same fact representation identifier. Aggregation is used to summarize the conflict records according to the assertion representation identifier and obtain the conflict participation degree. The atomic assertion corresponding to the assertion representation that meets the preset condition is selected as the conflict core atomic assertion. The code fact corresponding to the fact representation that has a conflict relationship with the conflict core atomic assertion is selected as the conflict core code fact. The conflict core atomic assertion and the conflict core code fact constitute the conflict core set.

[0025] In this embodiment, step five specifically includes: Semantic-preserving procedural transformations are performed on the target code unit to generate an equivalent view set. These transformations include variable renaming, dead code removal, constant propagation, expression equivalence substitution, conditional equivalence transformation, loop equivalence rewriting, and statement reordering. During these transformations, the abstract syntax tree, control flow graph, and data flow graph of the target code unit are read to determine transformable locations and constraints. Variable renaming replaces variable identifiers based on the consistency of variable nodes in the data flow graph while maintaining definition and usage relationships. Dead code removal removes unreachable statement nodes based on reachable path facts in the control flow graph while maintaining those reachable paths. Constant propagation propagates constant definitions along the data flow graph based on definition-to-use dependencies. Dependency edges are propagated to the usage location while maintaining the output semantics. Expression equivalence substitution performs substitution on equivalent expressions at the expression node level of the abstract syntax tree while maintaining consistent computation results. Conditional equivalence transformation performs equivalent rewriting on conditional expressions under the constraints of branch jump facts in the control flow graph while maintaining consistent branch reachability. Loop equivalence rewriting performs equivalent rewriting on loop structures under the constraints of loop paths in the control flow graph while maintaining consistent loop boundary semantics. Statement reordering performs reordering on statement nodes without dependency conflicts under the constraints of definition to usage dependency facts in the data flow graph while maintaining unchanged dependencies. Semantic preservation program transformations are applied to target code units to obtain transformed code units, which are then used as equivalent views in the equivalent view set. A set of equivalence evidence is generated for the set of equivalent views. The set of equivalence evidence contains the equivalent view identifier and evidence items. The evidence items include type consistency evidence, control flow consistency evidence, and data flow consistency evidence. When generating type consistency evidence, a type check is performed on the equivalent view to obtain the type check result and map the type check result to a pass or fail state. When generating control flow consistency evidence, an equivalent view control flow graph is constructed and a reachability relation consistency comparison is performed with the target code unit control flow graph to obtain the comparison result and map the comparison result to a pass or fail state. When generating data flow consistency evidence, an equivalent view data flow graph is constructed and a definition relation and usage relation consistency comparison is performed with the target code unit data flow graph to obtain the comparison result and map the comparison result to a pass or fail state. Delete equivalent views that fail the equivalence evidence set. Determine the pass status of the equivalent view based on the judgment result of the evidence item. If the pass status of the equivalent view is pass, retain the equivalent view. If the pass status is fail, delete the equivalent view. The deletion operation locates the equivalent view by the equivalent view identifier and removes it from the equivalent view set.

[0026] In this embodiment, step six specifically includes: The interpretation domain is limited based on the conflict core set. The limitation process includes reading the assertion representation identifier corresponding to the atomic assertion and the fact representation identifier corresponding to the code fact in the conflict core set, and retrieving the abstract syntax tree node identifier that matches the assertion representation identifier based on the matching index, retrieving the data flow edge identifier that matches the fact representation identifier based on the matching index, and retrieving the control flow path identifier that matches the fact representation identifier based on the matching index. The abstract syntax tree node identifier corresponds to the abstract syntax tree node set, the data flow edge identifier corresponds to the data flow edge set, and the control flow path identifier corresponds to the control flow path set. The abstract syntax tree node set, the data flow edge set, and the control flow path set constitute the interpretation domain. An improved SmoothGrad attribution calculation is performed on the consistency score. This improved SmoothGrad attribution calculation includes: selecting the source code label sequence vector representation and node and edge information vector representation corresponding to the model input in the interpretation domain. The source code label sequence vector representation is obtained by vectorizing the source code label sequence using a pre-trained code semantic model, and the node and edge information vector representation is also obtained by vectorizing the node and edge information using a pre-trained code semantic model. A zero-mean noise vector is generated based on a preset variance parameter and superimposed onto the source code label sequence vector representation and the node and edge information vector representation to obtain a perturbed input. The perturbed input includes the perturbed source code label sequence vector representation and the perturbed node and edge information vector representation. A consistency score is calculated for the perturbed input, and the consistency score is also calculated relative to the perturbed source code. The gradients of the labeled sequence vector representation and the perturbed node and edge information vector representation are calculated. The gradients include the source code labeled sequence gradient and the node and edge information gradient. The gradient set is obtained by repeating the process a preset number of times, and the smoothed gradient is obtained by performing an arithmetic mean on the gradient set. The smoothed gradient includes the source code labeled sequence smoothed gradient and the node and edge information smoothed gradient. The source code labeled sequence contribution score is obtained by performing an inner product summation on the source code labeled sequence smoothed gradient and the source code labeled sequence vector representation. The node and edge information contribution score is obtained by performing an inner product summation on the node and edge information smoothed gradient and the node and edge information vector representation. The source code labeled sequence contribution score and the node and edge information contribution score constitute the contribution score. The contribution score represents the degree of influence of the source code labeled sequence vector representation and the node and edge information vector representation on the consistency score within the interpretation domain. The contribution positioning result is generated. The generation process includes mapping the contribution score of the source code tag sequence to the abstract syntax tree node based on the abstract syntax tree node identifier in the node and edge information, mapping the contribution score of the node and edge information to the data flow edge based on the data flow edge identifier in the node and edge information, and mapping the contribution score of the node and edge information to the control flow path based on the control flow path identifier in the node and edge information. The contribution positioning result includes the contribution score of the abstract syntax tree node, the contribution score of the data flow edge, and the contribution score of the control flow path.

[0027] In this embodiment, step seven specifically includes: A set of discrete editing operators is constructed. The construction process includes establishing operator parameter constraints and action rules for entity replacement operator, numerical correction operator, range correction operator, negation / affirmation flip operator, condition completion operator, anomaly description completion operator, redundant phrase deletion operator, and terminology normalization operator. The operator parameter constraints include rules for generating edited content and rules for the legality of edited positions. The action rules include the definition of replacement, insertion, and deletion operations for candidate annotation text natural language tag sequences. Operator costs are set for discrete editing operators in the set of discrete editing operators. The operator cost is a mapping from discrete editing operator identifier to cost value. A candidate edit sequence set is generated based on the contribution positioning results. The generation process includes reading the contribution scores of the abstract syntax tree nodes, data flow edges, and control flow paths from the contribution positioning results, and retrieving the corresponding source code location ranges from the node and edge information based on the abstract syntax tree node identifiers, data flow edge identifiers, and control flow path identifiers. An alignment relationship is established between the source code location ranges and the natural language tag location ranges corresponding to the assertion objects and assertion constraints in the candidate comment text. The alignment relationship is determined as the edit location identifier, which is used to indicate the natural language tag location range of the candidate comment text. The edit location identifiers are traversed according to the discrete edit operator identifiers in the discrete edit operator set, and the edit content is generated. The edit content is obtained by combining the assertion objects, assertion constraints, and code fact field values ​​in the code fact set. The discrete edit operators are applied to the edit location identifiers and edit content to form candidate edit sequences. The candidate edit sequence set contains candidate edit sequences, and the candidate edit sequences contain discrete edit operator identifiers, edit location identifiers, and edit content. The candidate edit sequence set is selected and a correction annotation is generated. The selection process includes applying the candidate edit sequences to the candidate annotation text in sequence to obtain the correction annotation candidate text. The correction annotation candidate text contains natural language tag sequences. A consistency score is calculated based on the correction annotation candidate text and the target code unit, and it is determined whether the consistency score meets the consistency threshold. The consistency score is calculated using assertion representation and fact representation, and a set of support relations and a set of conflict relations are generated based on the matching index. The editing cost is obtained by accumulating the operator costs corresponding to the discrete editing operator identifiers in the candidate edit sequences. Based on the editing cost and the consistency score meeting the consistency threshold, the candidate edit sequences are selected, and the selected candidate edit sequences are applied to the candidate annotation text to generate correction annotations.

[0028] In this embodiment, step eight specifically includes: The consistency score is calculated based on the corrected comments and the target code unit. The calculation process includes parsing the corrected comments to obtain a set of atomic assertions and converting the set of atomic assertions into assertion representations. The assertion representations contain key-value information for assertion type fields, assertion object fields, and assertion constraint fields. The calculation process also includes extracting facts from the target code unit to obtain a set of code facts and converting the set of code facts into fact representations. The fact representations contain key-value information corresponding to the assertion type fields, assertion object fields, and assertion constraint fields. Alignment calculations are performed based on the matching index to generate a set of supporting relationships and conflicting relationships. The set consists of a support relation set that records assertion representation identifiers, fact representation identifiers, and satisfaction determination results, and a conflict relation set that records assertion representation identifiers, fact representation identifiers, and violation determination results. Based on the support relation set and the conflict relation set, a consistency score is calculated according to a preset scoring function. The preset scoring function includes support scoring items and conflict deduction items. The support scoring items count and accumulate weights for records in the support relation set whose satisfaction determination results are satisfied. The conflict deduction items count and accumulate weights for records in the conflict relation set whose violation determination results are violated. The weights are determined by the value of the assertion type field. The retest consistency score is compared with the consistency threshold and the threshold determination is completed. The comparison process includes reading the consistency threshold and performing a numerical comparison on the retest consistency score. When the retest consistency score is greater than the consistency threshold, the threshold determination result is determined to meet the consistency threshold. When the retest consistency score is less than the consistency threshold, the threshold determination result is determined to not meet the consistency threshold. When the re-verification consistency score meets the consistency threshold, an annotation update record is generated. The generation process includes reading the start position and end position of the target code unit and generating a target code unit position record, reading the correction annotation and generating an annotation content record, reading the re-verification consistency score and generating a score record, reading the threshold judgment result and generating a judgment record, and combining the target code unit position record, annotation content record, score record, and judgment record into an annotation update record.

[0029] Example 1: To verify the feasibility of this invention in practice, it was applied to a continuously iterating enterprise-level code repository comment maintenance scenario. The repository contains a large number of functions, methods, classes, and predefined statement blocks. Developers frequently refactor during version evolution, and variable renaming, statement rearrangement, and condition rewriting are common, leading to recurring issues of inconsistencies between comments and source code semantics. In this scenario, there are both missing comments and seemingly reasonable comments that are inconsistent with the actual control flow path and data dependencies. Typical manifestations include deviations in input constraint descriptions, deviations in return semantic descriptions, and omissions in descriptions of abnormal behavior. Manual review requires reading both the source code and the runtime logic, which is time-consuming, and the review results rely on personal experience, making it difficult to form traceable correction basis and update records.

[0030] In this scenario, a batch of target code units is first extracted from the repository as evaluation objects. These target code units primarily cover functions and methods, containing a small number of classes and pre-defined statement blocks. Each target code unit has historical comments or requires new comments. The system reads the source code and determines the boundaries of the target code units, constructing an abstract syntax tree, control flow graph, and data flow graph as structured representations. The source code tag sequence and node and edge information are then organized as model input, inputting into a pre-trained code semantic model to obtain a code semantic representation and generate candidate comment text. The candidate comment text undergoes parsing processing, extracting semantic key points to form an atomic assertion set. Simultaneously, syntax-related facts are extracted from the target code units based on the abstract syntax tree, control-related facts based on the control flow graph, and data-related facts based on the data flow graph, forming a code fact set. This set is then transformed into assertion representations, fact representations, and matching indices. The system aligns the assertion representations and fact representations according to the matching indices, forming a support relationship set and a conflict relationship set. A consistency score is calculated according to a pre-defined scoring function, filtering out the core conflict set. To improve the stability of reconstructed morphological changes, a semantically preserving procedural transformation is performed on the target code unit to generate an equivalent view set. For each equivalent view, an equivalence evidence set is generated, including evidence of type consistency, control flow consistency, and data flow consistency. Equivalent views with evidence items deemed unsuccessful are deleted. Subsequently, within the interpretation domain defined by the conflict core set, an improved SmoothGrad attribution calculation is performed on the consistency score to obtain a contribution score, which is then mapped to abstract syntax tree nodes, data flow edges, and control flow paths, outputting the contribution location result. Based on the contribution location result, a candidate edit sequence set is generated. A set of discrete edit operators is applied at the edit position markers to form candidate edit sequences. The system calculates the edit cost and recalculates the consistency score. The candidate edit sequence with the lowest edit cost and a consistency score that meets the consistency threshold is selected to generate a correction annotation. The revised comments are parsed again to obtain the set of atomic assertions and the assertion representation is transformed. The target code unit extracts the set of code facts and transforms the fact representation. Based on the matching index, the set of supporting relations and the set of conflicting relations are generated and the verification consistency score is calculated. When the verification consistency score meets the consistency threshold, the comment update record is generated. The start position, end position, revised comments, verification consistency score and threshold judgment result of the target code unit are recorded to make the comment update traceable.

[0031] Three comparison methods were used for statistical analysis on the same batch of target code units. Method 1 involved manually writing or rewriting comments; Method 2 involved generating candidate comment text using only a pre-trained code semantic model and manually selecting it; and Method 3 involved using the present invention to form a closed loop for comment generation and verification. Evaluation data came from the same reviewers and the same set of review rules. The statistical criteria were uniformly adopted, including processing time, consistency pass rate, number of inconsistent comments, and distribution of re-verification consistency scores for each target code unit. The impact of equivalent view evidence filtering on consistency score fluctuations was also recorded. The data results are shown in Table 1, where the consistency pass rate refers to the proportion of re-verification consistency scores that meet the consistency threshold, the number of inconsistent comments refers to the number of semantically inconsistent items confirmed by the reviewers, and the average processing time includes the total time spent on generation, verification, location, correction, and re-verification.

[0032] Table 1 Comparison of Annotation Consistency Check and Correction Effects

[0033] In terms of processing time, this invention reduces the average processing time for the same batch of target code units to about one-third of the manual method, and is also significantly shorter than the method of only generating candidate annotation text. This is mainly because supporting relation sets and conflict relation sets provides a calculable basis for consistency scoring, the conflict core set narrows the review scope, and the contribution location result directly pinpoints the problem to the code location corresponding to the abstract syntax tree node, data flow edge, and control flow path, reducing the time spent repeatedly reading through the source code. Regarding proportion, this invention outputs corrected annotations and performs re-verification consistency scoring under consistency threshold constraints. The proportion of items meeting the consistency threshold is significantly higher than the comparison method, and the number of inconsistent items confirmed by the review decreases accordingly. In terms of stability, after adding equivalence view sets and equivalence evidence sets for filtering, the standard deviation of the re-verification consistency score decreases, reflecting that the impact of morphological differences introduced by semantic preservation program transformations on score fluctuations is suppressed. Regarding annotation update records, this invention automatically generates update records when the re-verification consistency score meets the consistency threshold, recording the location range and scoring result. Reviewers can directly trace the correction basis based on the records, solving the problems of difficult-to-locate annotation drift and difficulty in forming closed-loop updates.

[0034] The above description is only a preferred embodiment of the present invention, but the scope of protection of the present invention is not limited thereto. Any equivalent substitutions or modifications made by those skilled in the art within the scope of the technology disclosed in the present invention, based on the technical solution and inventive concept of the present invention, should be covered within the scope of protection of the present invention.

Claims

1. A method for generating and validating code annotations based on machine learning, characterized in that, Includes the following steps: Step 1: Obtain the source code and identify the target code unit, then construct the abstract syntax tree, control flow graph, and data flow graph of the target code unit; Step 2: Encode the target code unit based on the pre-trained code semantic model to generate candidate annotation text; Step 3: Parse the candidate comment text into a set of atomic assertions and extract a set of code facts from the target code unit; Step 4: Calculate the consistency score based on the set of atomic assertions and the set of code facts to determine the core conflict set; Step 5: Perform semantic-preserving procedural transformation on the target code unit to generate an equivalent view set, generate an equivalence evidence set for the equivalent view set, and delete equivalent views that do not pass the equivalence evidence set; Step 6: Based on the conflict core set to limit the interpretation domain, perform improved SmoothGrad attribution calculation on the consistency score to generate contribution location results. The contribution location results correspond to abstract syntax tree nodes, data flow edges, and control flow paths. Step 7: Based on the set of discrete edit operators, map the contribution location results to a set of candidate edit sequences, select the candidate edit sequences with the minimum editing cost and whose consistency scores meet the consistency threshold, and generate corrected annotations; Step 8: Calculate the re-verification consistency score based on the corrected comments and target code units. When the re-verification consistency score meets the consistency threshold, generate the comment update record.

2. The method for generating and verifying code annotations based on machine learning according to claim 1, characterized in that, Step one specifically involves: Obtain the source code and identify the target code unit, which includes one of the following: function, method, class, or predefined statement block. Determine the start and end positions of the target code unit in the source code. An abstract syntax tree is constructed based on the target code unit. The abstract syntax tree contains a set of abstract syntax tree nodes and a set of abstract syntax tree edges. The set of abstract syntax tree nodes includes declaration nodes, statement nodes, and expression nodes. The set of abstract syntax tree edges represents the parent-child relationship between nodes. A control flow graph is constructed based on the target code unit. The control flow graph contains a set of basic block nodes and a set of control flow edges. The set of control flow edges represents the sequential execution relationship and branch jump relationship between basic blocks. A data flow graph is constructed based on the target code unit. The data flow graph contains a set of nodes consisting of variable nodes and statement nodes, and a set of data flow edges. The set of data flow edges represents the dependency relationship from variable definition to variable usage. Abstract syntax trees, control flow graphs, and data flow graphs constitute a structured representation of the target code unit.

3. The method for generating and validating code annotations based on machine learning according to claim 1, characterized in that, Step two specifically involves: The model input is constructed based on the source code and structured representation of the target code unit. The structured representation includes an abstract syntax tree, a control flow graph, and a data flow graph. The model input contains the source code tag sequence and the corresponding node and edge information of the structured representation. The model is input into a pre-trained code semantic model, which encodes the source code tag sequence and node and edge information to obtain the code semantic representation of the target code unit. Annotations are generated based on code semantic representation, and tags are output according to the generation order of natural language tags. The tags form candidate annotation text.

4. The method for generating and verifying code annotations based on machine learning according to claim 1, characterized in that, Step three specifically involves: The candidate annotation text is parsed to extract the semantic points in the candidate annotation text and form a set of atomic assertions. The set of atomic assertions contains atomic assertions, and each atomic assertion contains assertion type, assertion object, and assertion constraint. Fact extraction processing is performed on the target code unit. Syntax-related facts are extracted based on the abstract syntax tree, control-related facts are extracted based on the control flow graph, and data-related facts are extracted based on the data flow graph to form a code fact set. The atomic assertion set and the code fact set are converted into input representations for consistency score calculation, assertion representations and fact representations are generated, and a matching index for assertion representations and fact representations is established.

5. The method for generating and validating code annotations based on machine learning according to claim 1, characterized in that, Step four specifically involves: Consistency matching is performed between assertion representations and fact representations. The assertion representations and fact representations are aligned according to the matching index to obtain a set of supporting relations and a set of conflicting relations. The set of supporting relations indicates that the fact representations satisfy the assertion constraints, and the set of conflicting relations indicates that the fact representations violate the assertion constraints. A consistency score is calculated based on the set of supporting relationships and the set of conflicting relationships. The consistency score is calculated according to a preset scoring function, which includes a support scoring item and a conflict deduction item. The support scoring item is calculated based on the number of matches in the set of supporting relationships, and the conflict deduction item is calculated based on the number of matches in the set of conflicting relationships. The conflict core set is determined based on the conflict relationship set. The conflict core set includes atomic assertions from the set of atomic assertions that constitute the conflict relationship and code facts from the set of code facts.

6. The method for generating and validating code annotations based on machine learning according to claim 1, characterized in that, Step five specifically involves: Semantic preservation procedural transformations are performed on the target code unit to generate an equivalent view set. The semantic preservation procedural transformations include variable renaming, dead code removal, constant propagation, expression equivalence substitution, conditional equivalence transformation, loop equivalence rewriting, and statement reordering. The semantic preservation procedural transformations are applied to the target code unit to obtain the transformed code unit, and the transformed code unit is used as an equivalent view in the equivalent view set. Generate an equivalence evidence set for the set of equivalent views. The equivalence evidence set contains the equivalent view identifier and evidence items. The evidence items include type consistency evidence, control flow consistency evidence, and data flow consistency evidence. The type consistency evidence is generated from the type check results of the equivalent view. The control flow consistency evidence is generated from the consistency of the reachability relationship between the control flow graph of the equivalent view and the control flow graph of the target code unit. The data flow consistency evidence is generated from the consistency of the definition relationship and usage relationship between the data flow graph of the equivalent view and the data flow graph of the target code unit. Delete equivalent views that fail the equivalence evidence set. Determine the pass status of the equivalent view based on the judgment result of the evidence item. The judgment result of the evidence item includes pass and fail. Equivalent views with the fail status are deleted from the equivalent view set, while equivalent views with the pass status are retained in the equivalent view set.

7. The method for generating and verifying code annotations based on machine learning according to claim 1, characterized in that, Step six specifically involves: The interpretation domain is defined based on the conflict core set. The set of abstract syntax tree nodes, data flow edge set, and control flow path set in the interpretation domain are determined according to the matching index. The set of abstract syntax tree nodes contains the abstract syntax tree nodes that form a matching relationship with the atomic assertions in the conflict core set. The set of data flow edge sets contains the data flow edges that form a matching relationship with the code facts in the conflict core set. The set of control flow path sets contains the control flow paths that form a matching relationship with the code facts in the conflict core set. An improved SmoothGrad attribution calculation is performed on the consistency score. The improved SmoothGrad attribution calculation includes: selecting the source code label sequence vector representation and node and edge information vector representation corresponding to the model input in the interpretation domain; generating a zero-mean noise vector based on a preset variance parameter and superimposing the zero-mean noise vector onto the source code label sequence vector representation and node and edge information vector representation to obtain a perturbation input; calculating the consistency score for the perturbation input and calculating the gradient of the consistency score with respect to the source code label sequence vector representation and node and edge information vector representation; repeating the calculation a preset number of times to obtain a gradient set and performing an arithmetic mean on the gradient set to obtain a smooth gradient; and performing an inner product summation on the smooth gradient and the source code label sequence vector representation and node and edge information vector representation to obtain a contribution score. The contribution score characterizes the degree of influence of the source code label sequence vector representation and node and edge information vector representation on the consistency score in the interpretation domain. The contribution positioning result is generated by mapping the contribution score to the abstract syntax tree node, data flow edge, and control flow path based on the abstract syntax tree node identifier, data flow edge identifier, and control flow path identifier in the node and edge information. The contribution positioning result includes the contribution score of the abstract syntax tree node, the contribution score of the data flow edge, and the contribution score of the control flow path.

8. The method for generating and verifying code annotations based on machine learning according to claim 1, characterized in that, Step seven specifically involves: Construct a set of discrete editing operators, which includes entity replacement operator, numerical correction operator, range correction operator, negation / affirmation reversal operator, condition completion operator, anomaly description completion operator, redundant phrase deletion operator, and terminology normalization operator, and set operator costs for the discrete editing operators in the set of discrete editing operators; A candidate edit sequence set is generated based on the contribution positioning results. The abstract syntax tree node identifier, data flow edge identifier, and control flow path identifier in the contribution positioning results are mapped to the edit position identifier in the candidate annotation text. The edit position identifier is used to indicate the natural language tag position range of the candidate annotation text. The candidate edit sequence set is formed by the discrete edit operator acting on the edit position identifier. The candidate edit sequence contains the discrete edit operator identifier, the edit position identifier, and the edit content. The candidate edit sequence set is selected and a correction annotation is generated. The candidate edit sequence is applied to the candidate annotation text to obtain the correction annotation candidate text. The consistency score is calculated based on the correction annotation candidate text and the target code unit, and it is determined that the consistency score meets the consistency threshold. The editing cost is obtained by accumulating the operator costs corresponding to the candidate edit sequence. The candidate edit sequence with the minimum editing cost and the consistency score that meets the consistency threshold is selected to generate the correction annotation.

9. The method for generating and verifying code annotations based on machine learning according to claim 1, characterized in that, Step eight specifically involves: The verification consistency score is calculated based on the correction comments and the target code unit. The correction comments are parsed into a set of atomic assertions and converted into assertion representations. The target code unit extracts a set of code facts and converts it into a fact representation. The assertion representations and fact representations are aligned according to the matching index to generate a set of support relations and a set of conflict relations. The verification consistency score is calculated based on the set of support relations and the set of conflict relations according to a preset scoring function. The consistency score of the retest is compared with the consistency threshold and the threshold determination is completed. The threshold determination result includes whether the consistency threshold is met or not. When the re-verification consistency score meets the consistency threshold, an annotation update record is generated. The annotation update record includes the start position of the target code unit, the end position of the target code unit, the corrected annotation, the re-verification consistency score, and the threshold determination result.