An automated bug fixing method and system that combines neural network prediction with search algorithms

By combining neural network prediction and search algorithms, the problems of long processing time and inconsistent results in existing compiler error repair algorithms are solved, achieving more efficient and higher-quality compiler error repair, and the generated repair program is more in line with human programming style.

CN118708186BActive Publication Date: 2026-04-14PEKING UNIV
View PDF 2 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-06-21
Publication Date
2026-04-14

AI Technical Summary

Technical Problem

Existing compiler error repair algorithms cannot effectively combine neural network prediction and search algorithms, resulting in long repair times, inconsistent generated repair programs with human programming styles, and undesirable scalability issues.

Method used

A method combining neural network prediction and search algorithms is adopted. Through preprocessing, encoder to generate vector sequences, predict operator scores, construct weighted modification graph, and finally call search algorithm to obtain repair results, using Transformer encoder and OrdinalFix constrained shortest path search algorithm.

Benefits of technology

It significantly reduces search time, improves the quality of fixes and the overall fix rate, and generates fixes that are more in line with human programming style.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118708186B_ABST
    Figure CN118708186B_ABST
Patent Text Reader

Abstract

The application belongs to the field of information technology and relates to an automatic compilation error repairing method and system combining neural network prediction and a search algorithm. The method comprises the following steps: preprocessing a program with a compilation error to generate a tokenized and abstracted program; processing the tokenized and abstracted program by using an encoder to generate a vector sequence, wherein each vector represents a token in the program; predicting scores of an insertion operator, a deletion operator and a replacement operator by using a prediction head according to the generated vector sequence; constructing a weighted modification graph according to the predicted scores; and obtaining a repairing result by calling a search algorithm according to the weighted modification graph. The application can limit and guide the search algorithm and can generate a higher-quality repaired program.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention belongs to the field of information technology, specifically relating to an automated compilation error repair method and system that combines neural network prediction and search algorithms. Background Technology

[0002] The compilation process is a crucial step in software development, involving the transformation of human-readable source code into machine-executable instructions. However, despite the meticulous efforts of programmers, compilation errors inevitably occur, hindering the successful generation of executable binaries. These errors include those introduced by programmer oversight, those caused by programs generated by large language models (LLMs), and those resulting from upgrades to application programming interfaces (APIs) in libraries. Notably, a study conducted by Google indicates that both novice and experienced developers are prone to compiling errors. Effectively resolving compilation errors is essential for maintaining software integrity and ensuring a smooth development workflow.

[0003] A good compiler bug fixing method should meet two requirements. First, the time required to fix the compiler bug should be within an acceptable range, typically a few seconds or a few minutes. Second, the fixed program should be of high quality. Here, quality is measured in two dimensions: the fixed program should be closely similar to the original program, retaining the programmer's intended meaning; and the fixed program should have a natural, human-like appearance, free of strange or unconventional statements.

[0004] Existing compiler error fixing algorithms can be divided into two groups. The first group relies on neural networks for prediction, using machine learning algorithms to learn from known fixes. However, their effectiveness depends on the sufficiency of the training dataset, and the nature of the fixes is not guaranteed. The second group focuses on handling syntactic and semantic constraints but often neglects human programming styles and functional correctness. Therefore, while these algorithms may solve compiler errors, the generated fixes may be inconsistent with the methods of typical programmers. These two groups of methods cannot be directly and easily integrated. A naive integration approach is to use brute force search on top of neural networks. However, this requires exponential calls to the neural network, resulting in unacceptable performance overhead.

[0005] The second group of recent research includes OrdinalFix (Zhang, Wenjie, Guancheng Wang, Junjie Chen, Yingfei Xiong, Yong Liu, and Lu Zhang. "OrdinalFix: Fixing CompilationErrors via Shortest-Path CFL Reachability." In 2023 38th IEEE / ACM International Conference on Automated Software Engineering (ASE), pp. 1200-1211. IEEE, 2023.), an algorithm designed to identify fixes with the fewest modifications. OrdinalFix searches and checks the correctness of each possible modification until a fix is ​​found. Experiments demonstrate that OrdinalFix achieves a higher fix rate than neural network-based methods.

[0006] However, OrdinalFix has two significant limitations. First, OrdinalFix exhibits undesirable scalability. Zhang et al. proved the NP-hard complexity of finding the fix with the minimum number of modifications. Despite optimizations, the algorithm requires considerable time and memory when a large number of modifications are needed. In such cases, the algorithm must explore all possibilities, leading to poor time performance. Second, as mentioned above, the algorithm may generate strange fixes. It only considers the constraints imposed by the compiler, ignoring human programming style and functional correctness. Therefore, although the algorithm may fix compilation errors, the resulting fix may not be consistent with the writing style of a typical programmer. Summary of the Invention

[0007] To address the aforementioned problems, this invention provides a method and system for an automated compilation error repair algorithm that combines neural network prediction and search algorithms.

[0008] The technical solution adopted in this invention is as follows:

[0009] An automated compilation error repair method combining neural network prediction and search algorithms includes the following steps:

[0010] Preprocess programs with compilation errors to generate tokenized and abstracted programs;

[0011] An encoder is used to process the tokenized and abstracted program to generate a sequence of vectors, where each vector represents a token in the program;

[0012] Based on the generated vector sequence, the prediction head is used to predict the scores of the insertion, deletion, and replacement operators;

[0013] Construct a weighted modification graph based on the predicted scores;

[0014] Based on the weighted modification graph, a search algorithm is invoked to obtain the repair results.

[0015] Furthermore, the preprocessing includes:

[0016] Programs with compilation errors are tokenized and converted into a sequential representation of program tokens;

[0017] After tokenization, token abstraction is performed, in which tokens of the same type are replaced with uniform labels;

[0018] The program processes identifiers by counting the occurrences of different identifiers, retaining common identifiers, and replacing uncommon identifiers with unique identifiers.

[0019] Furthermore, the encoder is the encoder layer of a Transformer network.

[0020] Furthermore, a special marker is introduced at the beginning of the vector sequence. <start>A special marker is introduced at the end. <end>The output of the encoder is represented as:

[0021] (e1,e2,…,e n = EncoderLayers(t1,t2,…,t) n )

[0022] Among them, t i It is the i-th label in the vector sequence, where t1 is <start>, t n yes <end>Vector e i This represents the encoded output vector of the i-th tag, where n is the length of the vector sequence, and EncoderLayers represents the encoding layers.

[0023] Further, the prediction head includes a replacement / deletion prediction head and an insertion prediction head; the prediction of the scores of the insertion operator, deletion operator, and replacement operator using the prediction head includes:

[0024] The prediction scores for the replacement and deletion operators are expressed as follows:

[0025] s i =softmax(FF1(e i ))

[0026] Among them, s i is the normalized score of the substitution and deletion operators at position i, and FF1 represents the feedforward layer of the substitution and deletion operators;

[0027] The prediction score for the insertion operator is expressed as:

[0028] w i,j =softmax(FF2) j (e i ))

[0029] Among them, w i,j FF2 represents the normalized score of the j-th insertion operator at the i-th position. j This represents the feedforward layer associated with the j-th insertion operator;

[0030] During training, cross-entropy loss is used as the loss function, which is expressed as follows:

[0031]

[0032] Where CrossEntropy represents cross-entropy, s i Let i represent the normalized score of the substitution and deletion operators at position i. The label representing the substitution and deletion operators at position i, w i,j Let represent the normalized score of the j-th insertion operator at position i. Let i represent the label of the j-th insertion operator at position i; the loss function is normalized by dividing by n and K(n+1), where n represents the number of data in the training set and K is the number of predictions inserted into the prediction head.

[0033] Furthermore, the step of constructing a weighted modification graph based on the predicted scores includes:

[0034] For the replacement operator, the probability of replacing with label t is the probability of replacing / deleting the t-th predicted value in the prediction header, i.e., s. i [t]; For the deletion operator, the probability of deletion is the same as the probability of replacing / deleting the prediction header. <delete>Predicted value, i.e., s i [ <delete>For the insertion operator, there are K insertion prediction heads. The probability of the insertion marker t is the maximum value of the t-th prediction among all insertion prediction heads, i.e. Therefore, the probability calculation for each modification operator is expressed as follows:

[0035] p(replacement, i, t) = s i [t]

[0036] p(delete, i) = s i [ <delete>]

[0037]

[0038] The logarithm of the probability is used as the weight, and the weight is divided into M buckets with the same interval length. The weight is converted into an integer by the bucket index.

[0039] After obtaining the integer weights, the integer weights are directly assigned to the program's modified graph to obtain the weighted modified graph. Then, the search algorithm is called to obtain the final repair result.

[0040] Furthermore, the weighted modification graph is the program modification graph in OrdinalFix, and the search algorithm is the constrained shortest path search algorithm in OrdinalFix.

[0041] An automated compiler error repair system combining neural network prediction and search algorithms, comprising:

[0042] The preprocessing module is used to preprocess programs with compilation errors, generating tokenized and abstracted programs;

[0043] The encoding module is used to process the tokenized and abstracted program using an encoder to generate a sequence of vectors, where each vector represents a token in the program;

[0044] The prediction module is used to predict the scores of insertion, deletion, and replacement operators based on the generated vector sequence using the prediction head.

[0045] The weighted modification graph construction module is used to construct a weighted modification graph based on the predicted scores;

[0046] The repair result acquisition module is used to obtain repair results by calling a search algorithm based on the weighted modification graph.

[0047] The beneficial effects of this invention are as follows:

[0048] During the design phase, experiments were conducted on the Middleweight Java dataset and the DeepFix dataset to demonstrate the superiority of NGSeFix compared to the state-of-the-art search-based algorithm OrdinalFix. Experiments showed that NGSeFix not only reduces search time but also improves the overall quality of the generated repairs. Furthermore, the repair rate of NGSeFix was compared with existing methods on the DeepFix dataset, and the results showed that NGSeFix achieved the highest repair rate. Attached Figure Description

[0049] Figure 1 This is a flowchart of the compilation error repair method of the present invention. Detailed Implementation

[0050] To make the above-mentioned objects, features and advantages of the present invention more apparent and understandable, the present invention will be further described in detail below with reference to specific embodiments and accompanying drawings.

[0051] This invention proposes NGSeFix ( N eural G uided Se arch for Compilation Error Fix This is the first method to use a neural network to guide a compiler error repair search algorithm. Figure 1 The processing flow of NGSeFix is ​​described. Specifically, NGSeFix uses a trained neural network trained on experience from existing fixes. Notably, the neural network employs two prediction heads, predicting weights for each modification operator and using these weights to guide the search algorithm. NGSeFix aims to constrain and guide the search algorithm, thereby improving performance and generating higher-quality fixes. When given a program with compilation errors as input, NGSeFix preprocesses the input program and generates a tokenized and abstracted representation (i.e., ...). Figure 1 The repair process is initiated using abstracted markers (in the model). Embeddings are then generated for each marker using a Transformer encoder-based model. NGSeFix then generates scores for insertion, deletion, and replacement operators using two prediction heads (a replacement / deletion prediction head and an insertion prediction head). These scores are then used to construct a weighted modification graph. Finally, OrdinalFix's constrained shortest path search algorithm is invoked to find the repaired result.

[0052] I. Input Preprocessing

[0053] In NGSeFix, the erroneous input program is first preprocessed into a tokenized and abstracted representation for subsequent neural network processing. The preprocessing process includes several steps, including tokenization, token abstraction, and identifier processing.

[0054] The first step is tokenization. This involves converting the erroneous program into a sequential representation of program tokens. This process uses tokenizers provided by the programming language. Here, a token is the smallest unit of code, including reserved words, identifiers, constants, operators, etc., in the programming language. Tokens are sometimes also called morphemes or the smallest grammatical unit; in this specification, they will be referred to as tokens.

[0055] Following tokenization, the next step is token abstraction, where tokens of the same type are replaced with uniform labels. Typically, tokens of the same type are equivalent in the context of compilation error correction, so replacing them with uniform labels helps reduce the vocabulary size and allows the model to focus on important relationships. For example, numeric literals (e.g., 1, 2, 3) are replaced with LITERAL_INT, and string literals (e.g., "abc", "def") are replaced with LITERAL_STRING.

[0056] Next, the identifiers in the program are processed. Since user-defined identifiers may include any content and there may be an infinite number of different identifiers, special processing is required before they can be input into the neural network. First, the number of different identifiers is counted. Common identifiers are retained, while less common identifiers are replaced with unique identifiers, such as "\texttt{uid_1}" and "\texttt{uid_2}".

[0057] II. Neural Network Architecture

[0058] This invention utilizes a Transformer-based neural network. The Transformer was originally proposed for sequence-to-sequence natural language processing tasks, such as machine translation. The Transformer leverages multi-head attention and feedforward networks to capture relationships between tags. A Transformer consists of a set of encoder layers and a set of decoder layers, where the encoder generates embeddings and the decoder generates sequences. The Transformer's encoder and decoder layers are widely used not only in NLP tasks but also in other fields involving sequence encoding and decoding.

[0059] In the model of this invention, only encoder layers are used to encode the program sequence. These encoder layers process the tokenized and abstracted program as input, generating a vector sequence, where each vector represents a token in the program. Similar to NLP tasks, this invention introduces a special token at the beginning of the vector sequence. <start>A special marker is introduced at the end. <end>The output of the encoder layers is represented as follows:

[0060] (e1,e2,…,e n = EncoderLayers(t1,t2,…,t) n )

[0061] In this equation, t i It is the i-th label in the input sequence, where t1 is always <start>, t n always <end>Vector e i This represents the encoded output vector of the i-th tag, where n is the length of the input sequence.

[0062] Next, we address the problem of generating scores for the replacement, deletion, and insertion operators. We need to generate a predicted score for each operator at each position in the input sequence.

[0063] First, we focus on the replacement and deletion operators. For each original tag in the program, at most one replacement or deletion operator can be applied. To predict the score of replacing a tag, this invention uses a feedforward neural network. For deletion and no modification, two special tags are introduced. <delete>and <keep>, respectively, indicate applying the delete operator or not making any modifications.

[0064] To illustrate the prediction process, consider the example in Table 1, where a substitution operator replaces label b with w, and a deletion operator deletes label c. The prediction scores for the substitution and deletion operators are shown in the third row of Table 1.

[0065] The predicted scores for the substitution and deletion operators can be expressed mathematically as follows:

[0066] s i =softmax(FF1(e i ))

[0067] In this equation, s i is the normalized score of the substitution and deletion operators at position i, and FF1 represents the feedforward layer for the substitution and deletion operators. The feedforward layer can be a two-layer perceptron with ReLU activation functions.

[0068] Secondly, for the insertion operator, since a position may have multiple insertions applied, K feedforward layers are used to generate K possible labels for each position. Then, a softmax function is applied to normalize the score at each position. When fewer than K insertion operators are applied, special labels are used. <delete>To fill in the predictions. Given a sequence of length n, there are n+1 positions where the insertion operator can be applied. Therefore, the prediction of the insertion operator at each position i is treated as the insertion operator between label i and label i+1. A special label is introduced at the beginning of the input sequence. <start>The prediction of the insertion operator at position 0 is also considered as an insertion operator before the first tag. To ensure the stability of the order of the insertion operators generated by the neural network, they are sorted according to the numbering order of each tag.

[0069] Table 1. Examples of Neural Network Label Prediction

[0070]

[0071] The examples presented in Table 1 include three insertion operators. The first insertion operator is... <start>The first insertion operator inserts a marker 'u' between 'e' and 'f', while the second and third insertion operators insert markers 'a' and 'b' between 'e' and 'f'. The prediction scores for the insertion operators are shown in the fourth and fifth rows of Table 1, respectively.

[0072] The mathematical expression for the predicted score of the insertion operator is as follows:

[0073] w i,j =softmax(FF2) j (e j ))

[0074] In this equation, w i,j FF2 represents the normalized score of the j-th insertion operator at the i-th position. j This represents the feedforward layer associated with the j-th insertion operator. The feedforward layer consists of two perceptron layers with ReLU activation functions.

[0075] III. Model Training

[0076] For the training data, a program with errors is paired with its corrected version. In the initial preprocessing step, the input program with errors is transformed into a tokenized and abstract representation. Subsequently, a dynamic programming algorithm is applied to determine the modification operators between the input program and its corrected version. These modification operators are used to generate labels, as described in the previous steps.

[0077] Using cross-entropy loss as the loss function, it can be expressed as follows:

[0078]

[0079] In this equation, CrossEntropy represents the cross-entropy, s i Let i represent the normalized score of the substitution and deletion operators at position i. The label representing the substitution and deletion operators at position i, w i,j Let represent the normalized score of the j-th insertion operator at position i. Let represent the label of the j-th insertion operator at position i. The loss function is normalized by dividing by n and K(n+1), where n represents the number of data points in the training set and K is the number of predictions for the insertion head mentioned earlier.

[0080] IV. Weight Prediction

[0081] The following section delves into the generation of modified graph weights. The neural network generates probability distributions in two prediction heads. For the replacement operator, the probability of replacing with label t is the t-th predicted value of the replacement / deletion head, i.e., s. i [t]; For the deletion operator, the probability of deletion is the same as replacing / deleting the header. <delete>Predicted value, i.e., s i [ <delete>For the insertion operator, there are K insertion heads. The probability of the insertion marker t is the maximum value of the t-th predicted value among all insertion heads, i.e.

[0082] Therefore, the probability calculation for each modification operator is expressed as follows:

[0083] p(replacement, i, t) = s i [t]

[0084] p(delete, i) = s i [ <delete>]

[0085]

[0086] This invention does not directly use probabilities as weights, but instead uses the logarithm of probabilities. This choice is based on a modified graph structure where the weight of a path is the sum of the weights of its edges. By using the logarithm of probabilities as weights, the sum of the weights of the edges in a path equals the logarithm of the probabilities associated with each edge of the path, which corresponds to the logarithm of the probabilities of the entire path.

[0087] However, due to the constraints of the search algorithm, as detailed in the background section, it is necessary to convert the probability distribution into strictly positive integer weights. This invention simply divides the weights into M buckets with equal interval lengths and converts the weights into integers using the bucket indices.

[0088] The mathematical expression for converting the predicted score (the probability of prediction) into integer weights is as follows:

[0089]

[0090] In this equation, w is the integer weight, and p is the predicted probability. log,min It is the minimum value of the logarithm of the probability, p. log,max It is the maximum value of the logarithm of the probability. It is a floor function that returns the largest integer less than or equal to the input.

[0091] After obtaining the integer weights, these weights can be directly assigned to the program modification graph in OrdinalFix to obtain the weighted modification graph. Then, by calling the existing search algorithm in OrdinalFix, the final repair result can be obtained.

[0092] V. Evaluation of the Technical Effects of the Invention

[0093] The experimental setup is described in detail below to evaluate the performance of NGSeFix compared to state-of-the-art methods.

[0094] The primary comparison method for NGSeFix is ​​OrdinalFix. This is because OrdinalFix currently represents the state-of-the-art compiler error repair algorithm utilizing a search algorithm, while NGSeFix's key contribution lies in enhancing the search algorithm for compiler error repair. For the repair rate on the DeepFix dataset, NGSeFix is ​​also compared to mainstream neural network-based methods on that dataset, including DeepFix, DrRepair, BIFI, and TransRepair. These methods utilize neural network predictions to repair compiler errors.

[0095] The model of this invention was evaluated on two programming languages: Middleweight Java and C. Middleweight Java is a subset of Java that retains the most important object-oriented features, including objects, inheritance, and polymorphism. Experiments were conducted using the adapted Middleweight Java specific syntax provided by OrdinalFix. The C programming language used is a subset of C99, the same as the baseline OrdinalFix. The C subset covers all the features used by students in the DeepFix dataset, supporting pointers, arrays, algebraic expressions, and control flow statements.

[0096] For Middleweight Java, an additional 10,000 correct Middleweight Java programs were generated using the Middleweight Java generator provided by OrdinalFix, and 320,000 mutated programs with compilation errors were generated using different random seeds. Subsequently, OrdinalFix was used to fix the errors in the mutated programs, generating pairs of errors and fixes. These pairs constituted the training dataset.

[0097] For C, the TRACER dataset was used as the training samples. TRACER contains error-ridden C programs written by students and their corresponding fixed versions. Function bodies were extracted from these programs using the same preprocessing method as OrdinalFix. Then, each error-ridden function body was paired with its fixed version to form the training dataset.

[0098] To evaluate the effectiveness of neural networks in NGSeFix, these datasets were randomly divided into training, validation, and test sets in an 8:1:1 ratio. The neural networks were trained using the training set, the best model was selected using the validation dataset, and the performance of the trained neural networks was evaluated using the test dataset.

[0099] The performance of NGSeFix was evaluated on two datasets consistent with those used when evaluating OrdinalFix. The first is the Middleweight Java dataset, proposed by OrdinalFix. The second dataset is a C dataset written by students, proposed by DeepFix. The Middleweight Java dataset contains 1,000 correct programs and 3,200 mutated programs with compilation errors. Correspondingly, the DeepFix dataset contains 6,978 C programs with compilation errors, from which OrdinalFix extracted 6,536 function bodies for repair.

[0100] The dataset used to evaluate compiler bug fixes is completely different from the dataset used to train the neural network, preventing the risk of data leakage from fixes derived from the training dataset. The Middleweight Java dataset used for compiler bug fixes is generated using a different random seed than the Middleweight Java dataset used to train the neural network. The C dataset used for compiler bug fixes is also completely different from the C dataset used to train the neural network.

[0101] Table 2. Comparison of OrdinalFix and NGSeFix

[0102]

[0103] Table 2 presents a comparison between OrdinalFix and NGSeFix. PAR2, GeoPAR2, and fix rate are used as metrics for this comparison. PAR2 represents the average runtime of the algorithms, with a timeout penalty of twice the timeout limit. GeoPAR2 is the geometric mean of the runtime with the timeout penalty. The fix rate is the percentage of programs that fix within specified timeout and memory limits. Additionally, the percentage of faster samples is included, representing the proportion of samples in which one model outperforms the other in terms of speed.

[0104] For Middleweight Java, while NGSeFix exhibits a higher PAR2, it also shows a lower GeoPAR2 and a higher percentage of faster samples. This difference is due to the fact that the arithmetic mean is more susceptible to extreme values ​​compared to the geometric mean. In most cases, NGSeFix is ​​faster than OrdinalFix, but there are also instances where NGSeFix is ​​significantly slower. This means that NGSeFix sacrifices algorithmic completeness in some situations in exchange for faster execution speed in most cases.

[0105] For C, NGSeFix exhibits lower PAR2, lower GeoPAR2, and a higher percentage of faster samples. This suggests that, in most cases, NGSeFix consistently outperforms OrdinalFix in terms of speed.

[0106] Key aspects of this invention include:

[0107] 1) A brand-new compilation error fixing technology that combines neural networks with search algorithms.

[0108] 2) A novel neural network structure for predicting edit operation scores.

[0109] 3) A novel method for converting neural network predicted scores to weighted edit graphs.

[0110] Practical application scenarios of this invention:

[0111] Compiler error correction has a wide range of applications throughout the software development lifecycle, providing crucial support for ensuring software quality and a smooth development process. First, when developers are writing source code, compiler error correction can quickly detect and correct problems caused by oversights, syntax errors, or logical errors, ensuring that the code does not encounter obstacles in the process of being translated into machine-executable instructions. Second, with the widespread use of Large Language Models (LLMs) in modern software development, compiler error correction can effectively handle complex errors that may occur in the code generated by these models, improving the overall code quality and maintainability. Furthermore, as the software ecosystem continues to evolve, upgrades to application programming interfaces (APIs) in libraries may lead to incompatibility with existing code; compiler error correction can quickly adapt to these changes, ensuring software stability and compatibility. In summary, compiler error correction covers all stages of software development, from code writing to software maintenance, providing developers with a powerful and essential tool.

[0112] Another embodiment of the present invention provides an automated compiler error repair system that combines neural network prediction and search algorithms, comprising:

[0113] The preprocessing module is used to preprocess programs with compilation errors, generating tokenized and abstracted programs;

[0114] The encoding module is used to process the tokenized and abstracted program using an encoder to generate a sequence of vectors, where each vector represents a token in the program;

[0115] The prediction module is used to predict the scores of insertion, deletion, and replacement operators based on the generated vector sequence using the prediction head.

[0116] The weighted modification graph construction module is used to construct a weighted modification graph based on the predicted scores;

[0117] The repair result acquisition module is used to obtain repair results by calling a search algorithm based on the weighted modification graph.

[0118] For the specific implementation process of each module, please refer to the description of the method of the present invention above.

[0119] Another embodiment of the present invention provides a computer device (computer, server, smartphone, etc.) including a memory and a processor, the memory storing a computer program configured to be executed by the processor, the computer program including instructions for performing the steps of the method of the present invention.

[0120] Another embodiment of the present invention provides a computer-readable storage medium (such as ROM / RAM, disk, optical disk) storing a computer program that, when executed by a computer, implements the various steps of the method of the present invention.

[0121] The specific embodiments of the present invention disclosed above are intended to help understand the content of the present invention and to implement it accordingly. Those skilled in the art will understand that various substitutions, changes, and modifications are possible without departing from the spirit and scope of the present invention. The present invention should not be limited to the content disclosed in the embodiments of this specification; the scope of protection of the present invention is defined by the claims.< / delete> < / delete> < / delete> < / start> < / start> < / delete> < / keep> < / delete> < / end> < / start> < / end> < / start> < / delete> < / delete> < / delete> < / end> < / start> < / end> < / start>

Claims

1. An automated compilation error repair method combining neural network prediction and search algorithms, characterized in that, Includes the following steps: Preprocess programs with compilation errors to generate tokenized and abstracted programs; An encoder is used to process the tokenized and abstracted program to generate a sequence of vectors, where each vector represents a token in the program; Based on the generated vector sequence, the prediction head is used to predict the scores of the insertion, deletion, and replacement operators; Construct a weighted modification graph based on the predicted scores; Based on the weighted modification graph, a search algorithm is invoked to obtain the repair results; The step of constructing a weighted modification graph based on the predicted scores includes: For the replacement operator, the probability of replacing with label t is the probability of replacing / deleting the t-th predicted value in the prediction header, i.e., s. i [t]; For the deletion operator, the probability of deletion is the same as the probability of replacing / deleting the prediction header. <delete>Predicted value, i.e., s i [ <delete>For the insertion operator, there are K insertion prediction heads. The probability of the insertion marker t is the maximum value of the t-th prediction among all insertion prediction heads, i.e. Where w i,j This represents the normalized score of the insertion operator at position i;< / delete> < / delete> Therefore, the probability calculation for each modification operator is expressed as follows: p(replacement, i, t) = s i [t] p(delete, i) = s i [ <delete> ]< / delete> The logarithm of the probability is used as the weight, and the weight is divided into M buckets with the same interval length. The weight is converted into an integer by the bucket index. After obtaining the integer weights, the integer weights are directly assigned to the program's modified graph to obtain the weighted modified graph. Then, the search algorithm is called to obtain the final repair result.

2. The method according to claim 1, characterized in that, The preprocessing includes: Programs with compilation errors are tokenized and converted into a sequential representation of program tokens; After tokenization, token abstraction is performed, in which tokens of the same type are replaced with uniform labels; The program processes identifiers by counting the occurrences of different identifiers, retaining common identifiers, and replacing uncommon identifiers with unique identifiers.

3. The method according to claim 1, characterized in that, The encoder is the encoder layer of the Transformer network.

4. The method according to claim 1, characterized in that, The beginning of the vector sequence is introduced by a special marker. <start>A special marker is introduced at the end. <end> The output of the encoder is represented as:< / end> < / start> (e1,e2,…,e n )=EncoderLayers(t1,t2,…,t n ) Among them, t i It is the i-th label in the vector sequence, where t1 is <start>, t n yes <end>Vector e i This represents the encoded output vector of the i-th tag, where n is the length of the vector sequence, and EncoderLayers represents the encoding layers.< / end> < / start> 5. The method according to claim 1, characterized in that, The prediction head includes a replacement / deletion prediction head and an insertion prediction head; predicting the scores of the insertion, deletion, and replacement operators using the prediction head includes: The prediction scores for the replacement and deletion operators are expressed as follows: s i =softmax(FF1(e i )) Among them, s i is the normalized score of the substitution and deletion operators at position i, and FF1 represents the feedforward layer of the substitution and deletion operators; The prediction score for the insertion operator is expressed as: w i,j =softmax(FF2 j (e j )) Among them, w i,j FF2 represents the normalized score of the j-th insertion operator at the i-th position. j This represents the feedforward layer associated with the j-th insertion operator; During training, cross-entropy loss is used as the loss function, which is expressed as follows: Where CrossEntropy represents cross-entropy, s i Let i represent the normalized score of the substitution and deletion operators at position i. The label representing the substitution and deletion operators at position i, w i,j Let represent the normalized score of the j-th insertion operator at position i. Let i represent the label of the j-th insertion operator at position i; the loss function is normalized by dividing by n and K(m+1), where n represents the number of data in the training set and K is the number of predictions inserted into the prediction head.

6. The method according to claim 1, characterized in that, The weighted modification graph is the program modification graph in OrdinalFix, and the search algorithm is the constrained shortest path search algorithm in OrdinalFix.

7. An automated compiler error repair system employing the method described in any one of claims 1 to 6, combining neural network prediction and search algorithms, characterized in that, include: The preprocessing module is used to preprocess programs with compilation errors, generating tokenized and abstracted programs; The encoding module is used to process the tokenized and abstracted program using an encoder to generate a sequence of vectors, where each vector represents a token in the program; The prediction module is used to predict the scores of insertion, deletion, and replacement operators based on the generated vector sequence using the prediction head. The weighted modification graph construction module is used to construct a weighted modification graph based on the predicted scores; The repair result acquisition module is used to obtain repair results by calling a search algorithm based on the weighted modification graph.

8. A computer device, characterized in that, It includes a memory and a processor, the memory storing a computer program configured to be executed by the processor, the computer program including instructions for performing the method of any one of claims 1 to 6.

9. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program, which, when executed by a computer, implements the method according to any one of claims 1 to 6.

Citation Information

Patent Citations

  • Code syntax error repairing method based on incomplete abstract syntax tree

    CN110362310A

  • System to grade and provide feedback on programs that do not compile

    IN201711037678A