Neural network prediction and search algorithm combined automatic compilation error repair method and system

By combining neural network prediction and search algorithms to construct a weighted modification graph, the efficiency and quality deficiencies in compilation error repair are solved, and efficient and high-quality repair effects are achieved in compilation error repair.

CN118708186AActive Publication Date: 2024-09-27PEKING UNIV
View PDF 3 Cites 0 Cited by

Patent Information

Application Number
CN202410809843.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-06-21
Publication Date
2024-09-27
Estimated Expiration
2044-06-21

AI Technical Summary

Technical Problem

Existing compilation error repair algorithms have deficiencies in efficiency and quality. Neural network methods rely on the adequacy of training data sets and are uncertain in effectiveness. OrdinalFix algorithms have limitations in scalability and quality of generated repairs, and ignore human programming. Stylistic and functional correctness.

Method used

Combines neural network prediction and search algorithms, generates tokenized and abstracted programs through preprocessing, uses the Transformer encoder to generate vector sequences, predicts the scores of insertion, deletion and replacement operators, builds weighted modification graphs, and calls constrained shortest paths Search algorithms to get repair results.

Benefits of technology

On the Middleweight Java and DeepFix datasets, NGSeFix significantly reduces search time, improves repair quality, and achieves the highest repair rate, demonstrating the effectiveness of neural network-guided search algorithms in compilation error repair.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118708186A
    Figure CN118708186A
Patent Text Reader

Abstract

The invention belongs to the technical field of information, 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 compiling error to generate a marked and abstracted program; processing the tokenized and abstracted program with an encoder to generate a sequence of vectors, wherein each vector represents a flag 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 score; and calling a search algorithm to obtain a repair result according to the weighted modification graph. According to the method, the search algorithm can be limited and guided, and the repair program with higher quality can be generated.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the field of information technology, and in particular relates to an automatic compilation error repair method and system combining neural network prediction and search algorithms. Background Art

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

[0003] A good compilation error repair method should meet two requirements. First, the time required to repair the compilation error should be within an acceptable range, usually a few seconds or minutes. Second, the repaired program should be of high quality. Here, quality is measured by two dimensions: the repaired program should be closely similar to the original program, retaining the programmer's intended meaning, and the repaired program should have a natural, human appearance without strange or unconventional statements.

[0004] Existing compilation error repair 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 adequacy of the training dataset, and the nature of the repair program is not guaranteed. The second group focuses on handling syntactic and semantic constraints, but often ignores human programming style and functional correctness. Therefore, while these algorithms may solve compilation errors, the generated fixes may not be consistent with the approach of a typical programmer. These two groups of methods cannot be directly and easily integrated. A naive integration approach is to use brute-force search on top of the neural network. However, this requires exponential calls to the neural network, resulting in unacceptable performance overhead.

[0005] The latest research belonging to the second group is OrdinalFix (Zhang, Wenjie, Guancheng Wang, JunjieChen, Yingfei Xiong, Yong Liu, and Lu Zhang. "OrdinalFix: Fixing CompilationErrors via Shortest-PathCFL 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 minimum number of modifications. OrdinalFix searches and checks the correctness of each possible modification until a fix is ​​found. Experiments have shown that the repair rate of OrdinalFix exceeds that of neural network-based methods.

[0006] However, there are two significant limitations of OrdinalFix. First, OrdinalFix exhibits undesirable scalability. Zhang et al. demonstrated the NP-Hard complexity of finding a fix with the minimum number of modifications. Despite optimizations, the algorithm requires considerable time and large amounts of memory in cases where a large number of modifications are required. In this case, the algorithm must explore all possibilities, resulting in poor time performance. Second, as mentioned above, the algorithm may generate strange fixes. It only considers the constraints imposed by the compiler and ignores human programming style and functional correctness. Therefore, although the algorithm may fix compilation errors, the fix results may not be consistent with how a typical programmer would write them. Summary of the invention

[0007] In view of the above problems, the present invention provides a method and system for an automated compilation error repair algorithm that combines a neural network prediction and search algorithm.

[0008] The technical solution adopted by the present invention is as follows:

[0009] An automated compilation error repair method combining neural network prediction and search algorithms, comprising 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 vector sequence, 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 operator, the deletion operator, and the replacement operator;

[0013] Based on the predicted scores, a weighted modification graph is constructed;

[0014] According to the weighted modification graph, the search algorithm is called to obtain the repair result.

[0015] Furthermore, the preprocessing includes:

[0016] Tokenize programs with compilation errors and convert them into sequential representations of program tokens;

[0017] Tokenization is followed by token abstraction, where tokens of the same type are replaced with a unified label;

[0018] Process the identifiers in the program, count the number of occurrences of different identifiers, retain common identifiers, and replace uncommon identifiers with unique identifiers.

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

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

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

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

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

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

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

[0026] Among them, s i is the normalized score of the replacement operator and the deletion operator at position i, and FF1 represents the feed-forward layer of the replacement operator and the deletion operator;

[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 represents the normalized score of the jth insertion operator at the ith position, FF2 j represents the feed-forward layer associated with the j-th insertion operator;

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

[0031]

[0032] Among them, CrossEntropy represents cross entropy, s i represents the normalized score of replacement and deletion operators at position i, The label representing the replacement and deletion operators at position i, w i,j represents the normalized score of the jth insertion operator at position i, represents the label of the jth 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, constructing a weighted modification graph according to the predicted scores includes:

[0034] For the replacement operator, the probability of replacing a token t is the tth prediction value of the replacement / deletion prediction head, i.e., s i [t]; For the delete operator, the probability of deletion is the replacement / deletion prediction head <delete>The predicted value, s i [ <delete>]; For the insert operator, there are K insert prediction heads, and the probability of inserting token t is the maximum value of the t-th prediction value among all the insert prediction heads, that is, Based on this, the calculation of the probability of 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, and the weight is converted to an integer through the bucket index;

[0039] After obtaining the integer weight, the integer weight is directly assigned to the program modification graph, that is, the weighted modification graph is obtained, and then the search algorithm is called to obtain the final repair result.

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

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

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

[0043] An encoding module, for processing the tokenized and abstracted program using an encoder to generate a vector sequence, wherein each vector represents a token in the program;

[0044] a prediction module for predicting scores of insertion operators, deletion operators, and replacement operators using a prediction head based on the generated vector sequence;

[0045] A 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 call the search algorithm to obtain the repair result according to the weighted modification graph.

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

[0048] During the design phase, the present invention was experimentally demonstrated on the Middleweight Java dataset and the DeepFix dataset, and the NGSeFix of the present invention was compared with the most advanced search-based algorithm OrdinalFix. The experiments show that NGSeFix not only reduces the search time, but also improves the overall quality of the generated fixes. In addition, the repair rate of NGSeFix is ​​compared with the existing methods on the DeepFix dataset, and the results show that NGSeFix achieves the highest repair rate. BRIEF DESCRIPTION OF THE DRAWINGS

[0049] Figure 1 It is a flow chart of the compile error repairing method of the present invention. DETAILED DESCRIPTION

[0050] In order to make the above-mentioned objects, features and advantages of the present invention more obvious and easy to understand, the present invention is further described in detail below through specific embodiments and drawings.

[0051] The present invention proposes NGSeFix( N eural G uided Se arch for Compilation Error Fix ing), which is the first method to use neural networks to guide the search algorithm for compilation error fixes. Figure 1 Depicts the processing flow of NGSeFix. Specifically, NGSeFix uses a trained neural network that is trained from experience with existing fixes. Notably, the neural network employs two prediction heads that predict weights for each modification operator, respectively, and use these weights to guide the search algorithm. The goal of NGSeFix is ​​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 works by preprocessing the input program and generating a tokenized and abstract representation (i.e. Figure 1 ) to start the repair process. Subsequently, a Transformer encoder-based model is used to generate embeddings for each token. NGSeFix then generates scores for insertion, deletion, and substitution operators using two prediction heads (replacement / deletion prediction head and insertion prediction head). These scores are then used to build a weighted modification graph. Finally, the constrained shortest path search algorithm of OrdinalFix is ​​called to find the repair result.

[0052] 1. Input preprocessing

[0053] In NGSeFix, the input program with errors 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. Convert the erroneous program into a sequential representation of program tokens. This process is performed using the tokenizer provided by the programming language. Here, a token refers to the smallest unit in the 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 manual, they are collectively referred to as tokens.

[0055] After tokenization, the next step is token abstraction, where tokens of the same type are replaced with unified labels. Often, tokens of the same type are equivalent in the context of compile error fixes, so replacing them with unified labels helps reduce the size of the vocabulary and enables the model to focus on important relations. 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 arbitrary content, there may be an infinite number of different identifiers, so special processing is required before they can be input into the neural network. First, the number of occurrences of different identifiers is counted, and common identifiers are retained, while less common identifiers are replaced with unique identifiers, such as "\texttt{uid_1}" and "\texttt{uid_2}".

[0057] 2. Neural Network Architecture

[0058] The present invention uses a Transformer-based neural network. Transformer was originally proposed for sequence-to-sequence natural language processing tasks (such as machine translation). Transformer uses multi-head attention and feedforward networks to capture the relationship between tags. Transformer contains a stack of encoder layers and a stack of decoder layers, where the encoder is used to generate embeddings and the decoder is used to generate sequences. The encoder layer and decoder layer of Transformer are widely used not only in NLP tasks, but also in other fields involving sequence encoding and decoding.

[0059] In our model, we only use encoder layers to encode program sequences. These encoder layers process the tokenized and abstracted program as input and generate a sequence of vectors, each of which represents a token in the program. Similar to NLP tasks, we introduce a special marker at the beginning of the vector sequence. <start>, introduce a special marker at the end <end>The output of the encoding layer (EncoderLayers) is expressed as:

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

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

[0062] Next, we solve the score generation problem for the substitution, deletion, and insertion operators. We need to generate a prediction score for each operator at each position in the input sequence.

[0063] First, we focus on the substitution and deletion operators. For each original token in the program, at most one substitution or deletion operator can be applied. To predict the score of replacing a token, we use a feed-forward neural network. For deletion and no modification, we introduce two special tokens: <delete>and <keep>, indicating to apply the delete operator or make no modification, respectively.

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

[0065] The prediction scores for the replacement 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 replacement operator and the deletion operator at position i, and FF1 represents the feed-forward layer of the replacement operator and the deletion operator. The feed-forward layer can be a two-layer perceptron with a ReLU activation function.

[0068] Secondly, for the insertion operator, since a position may have multiple applied insertions, K feed-forward layers are used to generate K possible tags for each position. Subsequently, a softmax function is applied to normalize the scores for each position. In the case where less than K insertion operators are applied, a special tag is used <delete>to fill 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 considered as the insertion operator between token i and token i+1. The special token is introduced at the beginning of the input sequence <start>, the prediction of the insertion operator at position 0 is also considered as the insertion operator before the first token. To ensure that the order of the insertion operators generated by the neural network is stable, they are sorted according to the numerical order of each token.

[0069] Table 1. Examples of neural network label predictions

[0070]

[0071] In the example presented in Table 1, there are three insertion operators. The first insertion operator is <start>The first and second insertion operators insert token u between e and a, while the second and third insertion operators insert tokens a and b between e and f. The prediction scores of the insertion operators are shown in the fourth and fifth rows of Table 1, respectively.

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

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

[0074] In this equation, w i,j represents the normalized score of the jth insertion operator at the ith position, FF2 j represents the feed-forward layer associated with the j-th insertion operator. The feed-forward layer consists of two layers of perceptrons with ReLU activation function.

[0075] 3. Model Training

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

[0077] Using cross entropy loss as the loss function, it is expressed as follows:

[0078]

[0079] In this equation, CrossEntropy represents cross entropy, s i represents the normalized score of replacement and deletion operators at position i, The label representing the replacement and deletion operators at position i, w i,j represents the normalized score of the jth insertion operator at position i, represents the label of the jth 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 of the insertion head mentioned above.

[0080] 4. Weight prediction

[0081] Let’s take a closer look at the generation of the modification graph weights. The neural network generates a probability distribution over two prediction heads. For the replacement operator, the probability of replacing with token t is the tth prediction value of the replacement / removal head, i.e., s i [t]; For the delete operator, the probability of deletion is the replacement / deletion head <delete>The predicted value, s i [ <delete>]; For the insert operator, there are K insert heads, and the probability of inserting marker t is the maximum value of the t-th predicted value among all the insert heads, that is,

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

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

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

[0085]

[0086] The present invention does not use the probability directly as the weight, but uses the logarithm of the probability. This choice is based on modifying the structure of the graph, where the weight of a path is the sum of the weights of its edges. By using the logarithm of the probability as the weight, the sum of the weights of the edges in the path is equal to the logarithm of the probability associated with the path edges, which corresponds to the logarithm of the probability of the entire path.

[0087] However, due to the constraints of the search algorithm, as described in detail in the background section, the probability distribution needs to be converted into strictly positive integer weights. The present invention simply divides the weights into M buckets with the same interval length and converts the weights into integers through the bucket index.

[0088] The mathematical expression for converting the prediction score (predicted probability) to an integer weight is as follows:

[0089]

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

[0091] After obtaining the integer weights, we can directly assign these weights to the program modification graph in OrdianlFix to obtain the weighted modification graph. Then, we can call the existing search algorithm in OrdinalFix to obtain the final repair result.

[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 with the state-of-the-art methods.

[0094] The main comparison method of NGSeFix is ​​OrdinalFix. This is because OrdinalFix is ​​currently the most advanced compilation error repair algorithm using a search algorithm, and the key contribution of NGSeFix is ​​to enhance the search algorithm for compilation error repair. For the repair rate of the DeepFix dataset, NGSeFix is ​​also compared with mainstream neural network-based methods on this dataset, including DeepFix, DrRepair, BIFI, and TransRepair. These methods use neural network predictions to fix compilation errors.

[0095] The proposed model is evaluated on two programming languages, namely 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 are performed using the adapted Middleweight Java concrete syntax provided by OrdinalFix. The C programming language used is a subset of C99, the same as the baseline OrdinalFix. The subset of C covers all the features used by students in the DeepFix dataset, supporting pointers, arrays, algebraic expressions, and control flow statements.

[0096] For Middleweight Java, we used the Middleweight Java generator provided by OrdinalFix to generate an additional 10,000 correct Middleweight Java programs, and used different random seeds to generate 320,000 mutant programs with compilation errors. Subsequently, we used OrdinalFix to fix the errors in the mutant programs, generating pairs of the error and the fixed program. This set of pairs constitutes the training dataset.

[0097] For C, we use the TRACER dataset as training samples. TRACER contains C programs written by students with errors and their corresponding fixed versions. We extract function bodies from these programs using the same preprocessing method as OrdinalFix. Then, we pair each function body with errors with its fixed version to form the training dataset.

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

[0099] The performance of NGSeFix is ​​evaluated on two datasets, which are consistent with the datasets 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 mutant programs with compilation errors. Correspondingly, the DeepFix dataset contains 6,978 C programs with compilation errors, from which OrdinalFix extracts 6,536 function bodies for repair.

[0100] The dataset used to evaluate compile bug fixes is completely different from the dataset used to train the neural network, preventing the risk of data leakage from fixes in the training dataset. The Middleweight Java dataset used for compile 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 compile bug fixes is a completely different dataset than the C dataset used to train the neural network.

[0101] Table 2. Comparison of OrdinalFix and NGSeFix

[0102]

[0103] Table 2 shows the comparison between OrdinalFix and NGSeFix. PAR2, GeoPAR2, and repair rate are used as metrics for this comparison. PAR2 represents the average runtime of the algorithm with a timeout penalty of twice the timeout limit. GeoPAR2 is the geometric mean of the runtime with a timeout penalty. The repair rate is the percentage of programs that are repaired within the specified timeout and memory limits. In addition, the percentage of faster samples is included, indicating the proportion of samples where one model outperforms the other in terms of speed.

[0104] For Middleweight Java, while NGSeFix shows a higher PAR2, NGSeFix exhibits 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 ​​than the geometric mean. In most cases, NGSeFix is ​​faster than OrdinalFix, but there are also cases where NGSeFix is ​​significantly slower than OrdinalFix. This means that NGSeFix sacrifices algorithmic completeness in some cases in exchange for faster algorithmic execution speed in most cases.

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

[0106] The key points of the present invention include:

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

[0108] 2) A new neural network structure for predicting editing operation scores.

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

[0110] Practical application scenarios of the present invention:

[0111] Compile error repair has a wide range of application scenarios in the software development life cycle, providing key support for ensuring software quality and a smooth development process. First, when developers are writing source code, compile error repair can quickly detect and correct problems caused by negligence, syntax errors, or logic errors, ensuring that there are no obstacles in the process of converting the code into machine executable instructions. Second, with the widespread application of large language models (LLMs) in modern software development, compile error repair can effectively handle complex errors that may appear in the code generated by these models, improving the quality and maintainability of the overall code. In addition, with the continuous evolution of the software ecosystem, the upgrade of the application programming interface (APIs) in the library may cause incompatibility with existing code. Compile error repair can quickly adapt to these changes and ensure the stability and compatibility of the software. In summary, the application scenarios of compile error repair in software development cover all stages from code writing to software maintenance, providing developers with powerful and necessary tools.

[0112] Another embodiment of the present invention provides an automatic compilation error repair system combining a neural network prediction and search algorithm, which includes:

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

[0114] An encoding module, for processing the tokenized and abstracted program using an encoder to generate a vector sequence, wherein each vector represents a token in the program;

[0115] a prediction module for predicting scores of insertion operators, deletion operators, and replacement operators using a prediction head based on the generated vector sequence;

[0116] A 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 call the search algorithm to obtain the repair result according to the weighted modification graph.

[0118] The specific implementation process of each module refers to the above description of the method of the present invention.

[0119] Another embodiment of the present invention provides a computer device (computer, server, smart phone, etc.), which includes a memory and a processor, the memory stores a computer program, the computer program is configured to be executed by the processor, and the computer program includes instructions for executing each step in the method of the present invention.

[0120] Another embodiment of the present invention provides a computer-readable storage medium (such as ROM / RAM, magnetic disk, optical disk), wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a computer, the steps of the method of the present invention are implemented.

[0121] The specific embodiments of the present invention disclosed above are intended to help understand the content of the present invention and implement it accordingly. It can be understood by those skilled in the art that various replacements, 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 contents disclosed in the embodiments of this specification, and the scope of protection of the present invention shall be subject to the scope defined in 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: The following steps are involved: 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 vector sequence, 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 operator, the deletion operator, and the replacement operator; Based on the predicted scores, a weighted modification graph is constructed; According to the weighted modification graph, the search algorithm is called to obtain the repair result.

2. The method according to claim 1, characterized in that The pre-processing comprises: Tokenize programs with compilation errors and convert them into sequential representations of program tokens; Tokenization is followed by token abstraction, where tokens of the same type are replaced with a unified label; Process the identifiers in the program, count the number of occurrences of different identifiers, retain common identifiers, and replace 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 introduces a special marker <start>, introduce a special marker at the end <end> ; The output of the encoder is expressed as:< / end> < / start> (e1,e2,…,e n )=EncoderLayers(t1,t2,…,t n ) Among them, t i is the i-th token in the vector sequence, where t1 is <start>, t n yes <end>, vector e i represents the encoded output vector of the i-th token, n is the length of the vector sequence, and EncoderLayers represents the encoding layer.< / end> < / start> 5. The method according to claim 1, characterized in that: The prediction header includes a replacement / deletion prediction header and an insertion prediction header; the prediction of the scores of the insertion operator, the deletion operator and the replacement operator using the prediction header includes: The prediction scores for replacement and deletion operators are expressed as: s i =softmax(FF1(e i )) Among them, s i is the normalized score of the replacement operator and the deletion operator at position i, and FF1 represents the feed-forward layer of the replacement operator and the deletion operator; The prediction score for the insertion operator is expressed as: w i,j =softmax(FF2 j (e i )) Among them, w i,j represents the normalized score of the jth insertion operator at the ith position, FF2 j represents the feed-forward layer associated with the j-th insertion operator; During the training process, cross entropy loss is used as the loss function, which is expressed as follows: Among them, CrossEntropy represents cross entropy, s i represents the normalized score of replacement and deletion operators at position i, The label representing the replacement and deletion operators at position i, w i,j represents the normalized score of the jth insertion operator at position i, represents the label of the jth 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.

6. The method according to claim 5, characterized in that The weighted modification graph is constructed according to the predicted scores, including: For the replacement operator, the probability of replacing a token t is the tth prediction value of the replacement / deletion prediction head, i.e., s i [t]; For the delete operator, the probability of deletion is the replacement / deletion prediction head <delete>The predicted value, s i [ <delete>]; For the insert operator, there are K insert prediction heads, and the probability of inserting token t is the maximum value of the t-th prediction value among all the insert prediction heads, that is, Based on this, the calculation of the probability of each modification operator is expressed as follows:< / delete> < / delete> 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, and the weight is converted to an integer through the bucket index; After obtaining the integer weight, the integer weight is directly assigned to the program modification graph, that is, the weighted modification graph is obtained, and then the search algorithm is called to obtain the final repair result.

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

8. An automated compilation error repair system combining neural network prediction and search algorithms, characterized in that: include: The preprocessing module is used to preprocess programs with compilation errors and generate tokenized and abstracted programs; An encoding module, for processing the tokenized and abstracted program using an encoder to generate a vector sequence, wherein each vector represents a token in the program; a prediction module for predicting scores of insertion operators, deletion operators, and replacement operators using a prediction head based on the generated vector sequence; A 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 call the search algorithm to obtain the repair result according to the weighted modification graph.

9. A computer device, characterized in that: The method comprises a memory and a processor, wherein the memory stores a computer program, the computer program is configured to be executed by the processor, and the computer program comprises instructions for executing the method according to any one of claims 1 to 7.

10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a computer, the method according to any one of claims 1 to 7 is implemented.

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

  • Error correcting compiler

    US5905892A