A cross-line code defect repair method and system based on deep learning

Through deep learning technology, we build a code understanding and logical positioning model, combined with ALBERT and TransGRU, to solve the problem of traditional methods that are difficult to repair code across lines and understand code logic, achieve in-depth analysis and accurate repair of complex code, and improve the efficiency of code repair. efficiency and accuracy.

CN118426998BActive Publication Date: 2024-09-24CHANGSHA WANGJIU SOFTWARE CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410895071.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-07-05
Publication Date
2024-09-24
Estimated Expiration
2044-07-05

AI Technical Summary

Technical Problem

Traditional code defect repair methods are difficult to repair code across lines, and difficult to assist developers in understanding code logic, especially when dealing with complex code logical structures and multi-line code.

Method used

Using a cross-line code defect repair method based on deep learning, by building a code understanding model and a logical positioning model, combined with ALBERT and TransGRU, the code language entities are extracted, global semantic understanding and logical relationship analysis are performed, and the causes and repair plans of the code defects are generated, and combined with DevOps process integration for automated testing.

Benefits of technology

It achieves in-depth understanding of complex code logic and accurate location and repair of cross-line defects, improves the efficiency and accuracy of code repair, reduces the occurrence of factual errors, and is suitable for repair scenarios of large code bases.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118426998B
    Figure CN118426998B
Patent Text Reader

Abstract

The present invention discloses a cross-line code defect repair method and system based on deep learning, including S1: the system receives an error statement, determines the location of the problem line, and extracts the code language entity; S2: constructs a code understanding model, combines the problem line location and the error statement, and performs a global semantic understanding of the code; S3: constructs a logical positioning model, combines the error statement, the code language entity, the problem code and the modified code in the training set, and outputs the problem line number and the problem line logical relationship; S4: combines the problem line logical relationship, generates the code defect cause, the modified code and saves it to the modification log; S5: integrates with the DevOps process, performs automated testing on the repaired code, and retains the code version before the repair. The present invention solves the problem that traditional code repair methods are difficult to repair code across lines and difficult to assist developers in understanding the code logic.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer technology, and in particular to a cross-line code defect repair method and system based on deep learning. Background Art

[0002] Code defect repair refers to the discovery and repair of errors or defects in the code during the software development process to improve the software's functionality, performance, reliability or security. Traditional code defect repair methods mainly include manual repair, rule-based automatic repair and test case-based repair. Manual repair requires developers to have deep programming and debugging experience, and is time-consuming and labor-intensive, making it difficult to apply to large or complex code bases; the limitation of repairing code defects through predefined rules or patterns is that such methods can only handle predefined problems and cannot deal with complex code logic defects; test case-based code repair relies on sufficient test coverage and high-quality test cases, and is limited in effectiveness when it is difficult to build comprehensive test cases.

[0003] In recent years, deep learning technology has been applied to the field of code defect repair. Traditional deep learning methods work well when dealing with single-line code errors, but due to the lack of in-depth understanding of the logical structure of the code, it is often difficult to understand and repair complex problems involving multiple lines of code; on the other hand, developers need to have a clear understanding of the logical relationship of the code. When the code repair method cannot provide help, understanding the context and logical flow of the code can help manually diagnose and repair problems, but traditional deep learning cannot provide relevant help in understanding code logic. Summary of the invention

[0004] In view of this, the present invention aims to provide a cross-line code defect repair method and system based on deep learning, aiming to solve the problem that traditional code repair methods are difficult to repair code across lines and difficult to assist developers in understanding code logic.

[0005] A cross-line code defect repair method based on deep learning includes the following steps:

[0006] S1: The system receives the error statement, determines the location of the problem line, and extracts the code language entity;

[0007] S2: Build a code understanding model, combine the problem line location and error statement, and perform global semantic understanding of the code;

[0008] S3: Build a logical location model, combine the error statement, code language entity, problem code in the training set, and modified code, and output the problem line number and the problem line logical relationship;

[0009] S4: Combine the logical relationship of the problem line to generate the code defect cause and the modified code and save them in the modification log;

[0010] S5: Integrate with the DevOps process to automate the testing of the repaired code and retain the code version before the repair;

[0011] Furthermore, the system in step S1 receives the error statement, determines the location of the problem line, and extracts the code language entity, including:

[0012] S11: Match the line number and file path in the error message through a regular expression;

[0013] S12: Train ALBERT and extract code language entities, including variable names, function names, class names, method names, interface names, module names, and attribute names. ALBERT is A Lite BERT, a lightweight BERT, which is a pre-trained language model based on BERT. The full name of BERT is Bidirectional Encoder Representations from Transformers. The calculation method is:

[0014] ;

[0015] Among them, output includes the variable name, function name, class name, method name, interface name, module name and attribute name of the problem line code, ALBERT() is the ALBERT operation, and input is the problem line code;

[0016] S13: The output of ALBERT is concatenated with the position information of the problem line into a vector, which is used as part of the input of the next code understanding model.

[0017] Based on ALBERT's deep bidirectional representation capabilities, the model can understand and extract complex language structures and contextual relationships in the code. In addition, ALBERT's lightweight structure reduces the demand for computing resources while maintaining a high effect, which is particularly suitable for processing large-scale code bases. By identifying various entities in the code, such as variable names, function names, etc., an accurate semantic map of the code is established, which provides the necessary input for subsequent code understanding, error location, logical relationship analysis and final code generation, especially when performing code repair, it can effectively avoid factual errors.

[0018] Furthermore, the S2 step constructs a code understanding model, combines the problem line location and the error statement, and performs global semantic understanding of the code, including:

[0019] S21: Divide the entire code according to blank lines or comments to obtain several code segments;

[0020] S22: Construct the TransGRU module, the calculation method is:

[0021] ;

[0022] Where A is the residual output of the attention mechanism, LayerNorm() is the layer normalization operation, X is the input of the TransGRU module, Attention() is the attention mechanism operation; G is the GRU output, GRU() is the GRU operation, M is the mixed output of the attention mechanism residual and GRU, MLP() is the multi-layer perceptron operation, Y is the output of the TransGRU module, and Concat[,] is the vector concatenation operation;

[0023] The S22 step is uniformly expressed as:

[0024] ;

[0025] Among them, TransGRU () is the TransGRU module operation;

[0026] The TransGRU module combines the self-attention mechanism and GRU (Gate Recurrent Unit), allowing the module to process the sequence dependency of the code as well as the global context information; the self-attention mechanism can capture long-distance dependencies by focusing on the interactions between different parts of the code segment, which helps the model understand complex code structures such as function calls and variable scopes; the GRU part processes the time step dependency in the sequence data, which is suitable for understanding local patterns such as loops and conditional structures; layer normalization and MLP further enhance the model's ability to integrate features;

[0027] Compared with the traditional Transformer structure, TransGRU maintains a hidden state vector at each time step, which can retain contextual information and continuously update and adjust the state according to the input. Therefore, the model can better understand the global semantics instead of relying solely on the self-attention mechanism that focuses on the local area. In addition, TransGRU combines the gating mechanism of GRU, which makes the model have better gradient fluidity and parameter update stability when processing long sequences. Compared with the traditional Transformer block, it is easier to converge to a suitable solution during training and is less affected by gradient disappearance or explosion.

[0028] S23: Calculate the segment vector of each code segment as follows:

[0029] ;

[0030] Among them, y ij is the row vector of the jth line of code in the i-th code segment, i is the code segment index, j is the code line index, code ijis the jth line of code in the ith code segment, V i is the i-th code segment vector, MeanPool() is the average pooling operation, y i1 ,y i2 ,…,y ij is the row vector of all code lines in the i-th code segment;

[0031] S24: Calculate the chapter vector of the entire code. The calculation method is:

[0032] ;

[0033] Among them, R ij is the segment vector V of the code segment i and V j The relationship vector between them, ReLU( ) is the ReLU activation function, W r is the weight matrix for relationship calculation, ⊙ is the product between vector elements; α ij is the segment vector V i Relative to V j The attention score, exp( ) is the exponential operation of taking the natural constant, w is the weight vector, R ik is the segment vector V i and V k , k is the code segment count index, N is the total number of segment vectors of the code segment; C is the chapter vector, α ii is the segment vector V i The self-attention score of

[0034] Using the self-attention mechanism to calculate the chapter vector can capture the relationship and semantic information between the code segments in the entire code. It not only considers the information of each segment vector itself, but also emphasizes the impact of important parts of the code through the self-attention score. This fine-grained semantic relationship processing provides richer background information for subsequent defect location and understanding; the final chapter vector is obtained by weighted summation of each attention score and the corresponding segment vector. While ensuring the integrity of the information, the model can perform effective semantic focus and extraction at the global level, enhancing the understanding of the overall logic and function of the code.

[0035] Furthermore, the S3 step constructs a logic location model, combines the error statement, the code language entity, the problem code in the training set and the modified code, and outputs the problem line number and the problem line logical relationship, including:

[0036] S31: Construct the code segment positioning module of the logic positioning model, take the chapter vector and error statement of the whole code as input, and output the probability of each code segment having a defect, which is calculated as follows:

[0037] ;

[0038] Among them, p i is the probability distribution of defects in each code segment, softmax() is the softmax function, W1 is the code segment location parameter, E err is the sentence vector of the error statement, b1 is the code segment location bias vector;

[0039] S32: Construct a problem line location module of the logic location model, use the segment vector and row vector of the code segment, combined with the error statement, to determine whether each line of code is a problem line, and output the problem line number. The calculation method is:

[0040] ;

[0041] Among them, p ij is the probability distribution of defects in each line of code in each code segment, W2 is the problem line location parameter, and b2 is the problem line bias vector;

[0042] Traditional single-line code repair usually only focuses on a single error line, often ignoring the fact that the error may be caused by the interaction and dependency between several lines in the code. For example, a variable is assigned an incorrect value in one function, but the impact of this error may only be manifested in another completely different function. Traditional methods are difficult to accurately locate and repair errors in this case because they cannot fully consider the global logic and structure of the code.

[0043] In contrast, the logical localization model adopts a layer-by-layer localization approach. It first globally locates the code segments that may have defects through the chapter vector, and then further accurately locates the problem lines within this range through the segment vector and row vector. This not only enhances the understanding of the global structure of the code, but also can identify defects caused by complex logical relationships between several code lines.

[0044] S33: Construct a problem line logic output module of the logic positioning model, input the sentence vector, line number and chapter vector of the problem line into the logic relationship prediction module, and obtain the logical relationship between the problem lines. The calculation method is:

[0045] ;

[0046] Among them, x ij is the feature representation of the jth code line in the i-th code segment; n ij is the line number of the jth code line in the i-th code segment, x uq is the feature representation of the qth code line in the uth code segment, u is the second index of the code segment, q is the second index of the code line, and n uq is the line number of the qth code line in the uth code segment, R iujq For xij and x uq The logical relationship vector between the problem rows, GNN( ) is the graph neural network operation;

[0047] GNN propagates information in the feature graph of code lines and can learn direct and indirect dependencies between lines, including other semantic relationships such as data flow, control flow, etc., so as to have a more comprehensive understanding of the structure and function of the code. Especially when dealing with complex software projects and large code bases, by predicting the logical relationship between code lines, it can recommend more accurate and reasonable repair strategies, avoid introducing new errors or improper code modifications, and improve the quality and maintainability of code repairs.

[0048] Furthermore, the step S4 combines the logical relationship of the problem line to generate the code defect cause and the modified code and save them in the modification log, including:

[0049] S41: integrating the logical relationship between the problem rows and the problem row information into graph structure information, where the nodes represent the problem rows and the edges represent the logical relationship between the problem rows;

[0050] S42: Input the graph structure information and the paragraph vector into ALBERT and decode it to generate an explanation of the cause of the code defect;

[0051] S43: Design entity-first decoding, and input the logical relationship vector between the problem lines, the paragraph vector and the code language entity into the TransGRU module to generate the repaired code to avoid factual errors. The calculation method is:

[0052] ;

[0053] Among them, z is the repaired code feature vector, p code is the probability distribution of the repaired code feature vector, p' is the probability distribution after entity priority decoding, γ is the entity preference strength, log() is the logarithm operation, m is the entity mask, and β is a custom constant;

[0054] Since the graph neural network is used in step S33 to calculate the logical relationship vector between the problem lines, the model can capture the complex dependencies across lines and generate structurally correct and logically coherent code repair suggestions. The code language entities are important input features. Through the entity-first decoding mechanism, the generated code is ensured to be more syntactically and semantically accurate, especially in referencing entities defined in the code base, such as variable names, function names, etc. By strengthening the preference for these entities (adjusting the probability distribution p' through the mask m), the model can avoid factual errors as much as possible when generating code, such as incorrectly referencing undefined variables or functions.

[0055] Furthermore, by prioritizing entities that already exist in the code, the generated fixed code maintains a higher consistency with the original code, reducing new errors or issues that may be caused by the introduction of new entities.

[0056] Furthermore, the S5 step is integrated with the DevOps process to perform automated testing on the repaired code and retain the code version before the repair, including:

[0057] S51: Use automated test suites to perform functional and performance tests on the repaired code;

[0058] S52: The fixed code is integrated into the continuous integration / continuous deployment process;

[0059] S53: In the version control system, keep the code version before the repair.

[0060] The present invention also discloses a cross-line code defect repair system based on deep learning, comprising:

[0061] Code language entity extraction module: The system receives the error statement, determines the location of the problem line, and extracts the code language entity;

[0062] Code comprehension model building module: Build a code comprehension model, combine the problem line location and error statement, and perform global semantic understanding of the code;

[0063] Logical location model building module: Build a logical location model, combine the error statement, code language entity, problem code in the training set and the modified code, and output the problem line number and the logical relationship of the problem line;

[0064] Modification result feedback module: Combines the logical relationship of the problem lines to generate the cause of the code defect and the modified code and saves them in the modification log;

[0065] DevOps integration module: Integrate with the DevOps process to perform automated testing on the repaired code and retain the code version before the repair.

[0066] Compared with the prior art, the advantages of the present invention are:

[0067] (1) In view of the problem that traditional code repair methods are difficult to repair code across lines and difficult to assist developers in understanding the logic of the code, the present invention proposes a method of combining TransGRU with a graph neural network to locate the code layer by layer, while understanding the logical relationship between each line of code. Ultimately, the modified code and an explanation of the cause of the original code defect are output to the developer. Simple problems can be repaired directly. For complex problems that cannot be repaired, developers can better locate and understand the problems by combining the explanation of the cause of the code defect output by the present invention.

[0068] (2) Compared with the traditional Transformer block, the TransGRU module proposed in this paper maintains a hidden state vector at each time step and retains context information, which can better understand the global semantics; in addition, the TransGRU module has better gradient fluidity and parameter update stability when processing long sequences, and is more suitable for large-scale code defect repair scenarios.

[0069] (3) The present invention combines a graph neural network to locate and output the logical relationship of the problem lines layer by layer, so that the model can understand the semantics and structure of the code at different levels. Taking into account the interactions and dependencies between multiple lines in the code, it is more conducive to identifying defects caused by complex logical relationships between several lines of code.

[0070] (4) In terms of decoding method, the present invention proposes entity-priority decoding, taking the extracted code language entities as the priority repair objects, effectively avoiding the factual errors that may be generated by the generative model and improving the accuracy and reliability of the repair code. BRIEF DESCRIPTION OF THE DRAWINGS

[0071] Figure 1 A schematic diagram of the flow of the cross-line code defect repair method based on deep learning provided by the present invention.

[0072] Figure 2 Schematic diagram of the algorithm structure of TransGRU provided by the present invention.

[0073] Figure 3 A schematic diagram of the algorithm flow of the logical positioning model provided by the present invention. DETAILED DESCRIPTION

[0074] The present invention is further described below in conjunction with the accompanying drawings, but the present invention is not limited in any way. Any changes or substitutions made based on the teachings of the present invention belong to the protection scope of the present invention.

[0075] Embodiment 1: A cross-line code defect repair method based on deep learning, such as Figure 1 As shown, the following steps are included:

[0076] S1: The system receives the error statement, determines the location of the problem line, and extracts the code language entity;

[0077] S11: Match the line number and file path in the error message through a regular expression;

[0078] S12: Train ALBERT and extract code language entities, including variable names, function names, class names, method names, interface names, module names, and attribute names. ALBERT is A Lite BERT, a lightweight BERT, which is a pre-trained language model based on BERT. The full name of BERT is Bidirectional Encoder Representations from Transformers. The calculation method is:

[0079] ;

[0080] Among them, output includes the variable name, function name, class name, method name, interface name, module name and attribute name of the problem line code, ALBERT() is the ALBERT operation, and input is the problem line code;

[0081] S13: The output of ALBERT is concatenated with the position information of the problem line into a vector, which is used as part of the input of the next code understanding model.

[0082] Based on ALBERT's deep bidirectional representation capabilities, the model can understand and extract complex language structures and contextual relationships in the code. In addition, ALBERT's lightweight structure reduces the demand for computing resources while maintaining a high effect, which is particularly suitable for processing large-scale code bases. By identifying various entities in the code, such as variable names, function names, etc., an accurate semantic map of the code is established, which provides the necessary input for subsequent code understanding, error location, logical relationship analysis and final code generation, especially when performing code repair, it can effectively avoid factual errors.

[0083] S2: Build a code understanding model, combine the problem line location and error statement, and perform global semantic understanding of the code;

[0084] S21: Divide the entire code according to blank lines or comments to obtain several code segments;

[0085] S22: Construct the TransGRU module, such as Figure 2 As shown, the calculation method is:

[0086] ;

[0087] Where A is the residual output of the attention mechanism, LayerNorm() is the layer normalization operation, X is the input of the TransGRU module, Attention() is the attention mechanism operation; G is the GRU output, GRU() is the GRU operation, M is the mixed output of the attention mechanism residual and GRU, MLP() is the multi-layer perceptron operation, Y is the output of the TransGRU module, and Concat[,] is the vector concatenation operation;

[0088] The S22 step is uniformly expressed as:

[0089] ;

[0090] Among them, TransGRU () is the TransGRU module operation;

[0091] The TransGRU module combines the self-attention mechanism and GRU (Gate Recurrent Unit), allowing the module to process the sequence dependency of the code as well as the global context information; the self-attention mechanism can capture long-distance dependencies by focusing on the interactions between different parts of the code segment, which helps the model understand complex code structures such as function calls and variable scopes; the GRU part processes the time step dependency in the sequence data, which is suitable for understanding local patterns such as loops and conditional structures; layer normalization and MLP further enhance the model's ability to integrate features;

[0092] Compared with the traditional Transformer structure, TransGRU maintains a hidden state vector at each time step, which can retain contextual information and continuously update and adjust the state according to the input. Therefore, the model can better understand the global semantics instead of relying solely on the self-attention mechanism that focuses on the local area. In addition, TransGRU combines the gating mechanism of GRU, which makes the model have better gradient fluidity and parameter update stability when processing long sequences. Compared with the traditional Transformer block, it is easier to converge to a suitable solution during training and is less affected by gradient disappearance or explosion.

[0093] S23: Calculate the segment vector of each code segment as follows:

[0094] ;

[0095] Among them, y ij is the row vector of the jth line of code in the i-th code segment, i is the code segment index, j is the code line index, code ij is the jth line of code in the ith code segment, V i is the i-th code segment vector, MeanPool() is the average pooling operation, yi1 ,y i2 ,…,y ij is the row vector of all code lines in the i-th code segment;

[0096] S24: Calculate the chapter vector of the entire code. The calculation method is:

[0097] ;

[0098] Among them, R ij is the segment vector V of the code segment i and V j The relationship vector between them, ReLU( ) is the ReLU activation function, W r is the weight matrix for relationship calculation, ⊙ is the product between vector elements; α ij is the segment vector V i Relative to V j The attention score, exp( ) is the exponential operation of taking the natural constant, w is the weight vector, R ik is the segment vector V i and V k , k is the code segment count index, N is the total number of segment vectors of the code segment; C is the chapter vector, α ii is the segment vector V i The self-attention score of

[0099] Using the self-attention mechanism to calculate the chapter vector can capture the relationship and semantic information between the code segments in the entire code. It not only considers the information of each segment vector itself, but also emphasizes the impact of important parts of the code through the self-attention score. This fine-grained semantic relationship processing provides richer background information for subsequent defect location and understanding; the final chapter vector is obtained by weighted summation of each attention score and the corresponding segment vector. While ensuring the integrity of the information, the model can perform effective semantic focus and extraction at the global level, enhancing the understanding of the overall logic and function of the code.

[0100] S3: Build a logical positioning model, combine the error statement, code language entity, problem code in the training set, and modified code, and output the problem line number and the problem line logical relationship, such as Figure 3 As shown;

[0101] S31: Construct the code segment positioning module of the logic positioning model, take the chapter vector and error statement of the whole code as input, and output the probability of each code segment having a defect, which is calculated as follows:

[0102] ;

[0103] Among them, p iis the probability distribution of defects in each code segment, softmax() is the softmax function, W1 is the code segment location parameter, E err is the sentence vector of the error statement, b1 is the code segment location bias vector;

[0104] S32: Construct a problem line location module of the logic location model, use the segment vector and row vector of the code segment, combined with the error statement, to determine whether each line of code is a problem line, and output the problem line number. The calculation method is:

[0105] ;

[0106] Among them, p ij is the probability distribution of defects in each line of code in each code segment, W2 is the problem line location parameter, and b2 is the problem line bias vector;

[0107] Traditional single-line code repair usually only focuses on a single error line, often ignoring the fact that the error may be caused by the interaction and dependency between several lines in the code. For example, a variable is assigned an incorrect value in one function, but the impact of this error may only be manifested in another completely different function. Traditional methods are difficult to accurately locate and repair errors in this case because they cannot fully consider the global logic and structure of the code.

[0108] In contrast, the logical localization model adopts a layer-by-layer localization approach. It first globally locates the code segments that may have defects through the chapter vector, and then further accurately locates the problem lines within this range through the segment vector and row vector. This not only enhances the understanding of the global structure of the code, but also can identify defects caused by complex logical relationships between several code lines.

[0109] S33: Construct a problem line logic output module of the logic positioning model, input the sentence vector, line number and chapter vector of the problem line into the logic relationship prediction module, and obtain the logical relationship between the problem lines. The calculation method is:

[0110] ;

[0111] Among them, x ij is the feature representation of the jth code line in the i-th code segment; n ij is the line number of the jth code line in the i-th code segment, x uq is the feature representation of the qth code line in the uth code segment, u is the second index of the code segment, q is the second index of the code line, and n uq is the line number of the qth code line in the uth code segment, R iujq For x ij and x uqThe logical relationship vector between the problem rows, GNN( ) is the graph neural network operation;

[0112] GNN propagates information in the feature graph of code lines and can learn direct and indirect dependencies between lines, including other semantic relationships such as data flow, control flow, etc., so as to have a more comprehensive understanding of the structure and function of the code. Especially when dealing with complex software projects and large code bases, by predicting the logical relationship between code lines, it can recommend more accurate and reasonable repair strategies, avoid introducing new errors or improper code modifications, and improve the quality and maintainability of code repairs.

[0113] S4: Combine the logical relationship of the problem line to generate the code defect cause and the modified code and save them in the modification log;

[0114] For example:

[0115] In the code of a project, the error log shows: "Null pointer exception" and indicates that the error occurred on line 150 of the file. The model running process idea is:

[0116] In the code segment location module, the model first receives the paragraph vector of the entire code and the sentence vector of the error statement. Based on the calculated defect probability distribution, it determines that the problem is likely to be located in the code segment containing line 150.

[0117] Next, the problem line location module uses the segment vector and row vector of the code segment, combined with the error statement, and after processing with the softmax function, outputs that lines 148, 150, and 152 are potential problem lines, among which line 150 has the highest probability, but lines 148 and 152 also show high risks;

[0118] Finally, in the problem line logic output module, the input includes the sentence vectors and line numbers of lines 148, 150, and 152 identified as problems, as well as the paragraph vector of the entire code; the model uses a graph neural network to calculate the logical relationship between these problem lines; the results show that the variable in line 148 is used without initialization, and an attempt to access the properties of the variable in line 150 causes a null pointer exception; an attempt to further operate on the variable in line 152 increases the complexity of the error;

[0119] The final output is:

[0120] Code:

[0121] Line 148 [uninitialized variable];

[0122] Line 150 [Trying to access property of uninitialized variable -> NullPointerException];

[0123] Line 152 [Continue to operate on uninitialized variables];

[0124] Problem line numbers: line 148, line 150, line 152;

[0125] Logical relationship between problematic lines: The uninitialized variable in line 148 is used in lines 150 and 152, resulting in a series of dependency errors.

[0126] S41: integrating the logical relationship between the problem rows and the problem row information into graph structure information, where the nodes represent the problem rows and the edges represent the logical relationship between the problem rows;

[0127] Logical relationships include:

[0128] Dependency: The problem line is caused by another problem line. For example, a function calls another function, but the called function has a problem, which causes the calling function to also have a problem.

[0129] Conditional relationship: The problem line is caused by the result of conditional judgment. For example, a logical error in a conditional branch may cause the problem.

[0130] Loop relationship: the loop is executed continuously or ends early;

[0131] Exception relations: missing or incorrect exception handling; for example, a function does not properly handle an exceptional situation, causing the exception to propagate to the place where the function was called.

[0132] Data dependency: caused by data dependency; for example, the value of a variable is incorrectly modified in the previous code, causing problems in the subsequent code;

[0133] S42: Input the graph structure information and the paragraph vector into ALBERT and decode it to generate an explanation of the cause of the code defect;

[0134] S43: Design entity-first decoding, and input the logical relationship vector between the problem lines, the paragraph vector and the code language entity into the TransGRU module to generate the repaired code to avoid factual errors. The calculation method is:

[0135] ;

[0136] Among them, z is the repaired code feature vector, p code is the probability distribution of the repaired code feature vector, p' is the probability distribution after entity priority decoding, γ is the entity preference strength, log() is the logarithm operation, m is the entity mask, and β is a constant less than 1, which is used to reduce the weight of these words in the generation process;

[0137] Since the graph neural network is used in step S33 to calculate the logical relationship vector between the problem lines, the model can capture the complex dependencies across lines and generate structurally correct and logically coherent code repair suggestions. The code language entities are important input features. Through the entity-first decoding mechanism, the generated code is ensured to be more syntactically and semantically accurate, especially in referencing entities defined in the code base, such as variable names, function names, etc. By strengthening the preference for these entities (adjusting the probability distribution p' through the mask m), the model can avoid factual errors as much as possible when generating code, such as incorrectly referencing undefined variables or functions.

[0138] Furthermore, by prioritizing entities that already exist in the code, the generated fixed code maintains a higher consistency with the original code, reducing new errors or issues that may be caused by the introduction of new entities.

[0139] S5: Integrate with the DevOps process to automate the testing of the repaired code and retain the code version before the repair;

[0140] S51: Use automated test suites to perform functional and performance tests on the repaired code;

[0141] S52: The fixed code is integrated into the continuous integration / continuous deployment process;

[0142] S53: In the version control system, keep the code version before the repair.

[0143] The present invention is particularly suitable for large code bases with complex logical structures and potential erroneous interactions, such as enterprise-level software systems or open source projects. Developers can more accurately locate and repair cross-line code errors without spending a lot of time and effort to manually analyze and identify the causes of the errors. The operation time is relatively short, which greatly improves the efficiency of code repair. In addition, since the present invention utilizes global semantic understanding and logical relationship modeling, it has high operating efficiency and can more comprehensively understand the structure and function of the code, effectively reducing the number of unnecessary repairs and improving the accuracy and maintainability of the repairs.

[0144] Embodiment 2: The present invention also discloses a cross-line code defect repair system based on deep learning, which is used to implement the above cross-line code defect repair method based on deep learning, including:

[0145] Code language entity extraction module: The system receives the error statement, determines the location of the problem line, and extracts the code language entity;

[0146] Code comprehension model building module: Build a code comprehension model, combine the problem line location and error statement, and perform global semantic understanding of the code;

[0147] Logical location model building module: Build a logical location model, combine the error statement, code language entity, problem code in the training set and the modified code, and output the problem line number and the logical relationship of the problem line;

[0148] Modification result feedback module: Combines the logical relationship of the problem lines to generate the cause of the code defect and the modified code and saves them in the modification log;

[0149] DevOps integration module: Integrate with the DevOps process to perform automated testing on the repaired code and retain the code version before the repair.

[0150] It should be noted that the serial numbers of the above embodiments of the present invention are only for description and do not represent the advantages and disadvantages of the embodiments. And the terms "including", "comprising" or any other variants thereof in this article are intended to cover non-exclusive inclusion, so that a process, device, article or method including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, device, article or method. In the absence of further restrictions, an element defined by the sentence "including a ..." does not exclude the presence of other identical elements in the process, device, article or method including the element.

[0151] Through the description of the above implementation methods, those skilled in the art can clearly understand that the above-mentioned embodiment methods can be implemented by means of software plus a necessary general hardware platform, and of course by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present invention is essentially or the part that contributes to the prior art can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk) as described above, and includes a number of instructions for a terminal device (which can be a mobile phone, a computer, a server, or a network device, etc.) to execute the methods described in each embodiment of the present invention.

[0152] The above are only preferred embodiments of the present invention, and are not intended to limit the patent scope of the present invention. Any equivalent structure or equivalent process transformation made using the contents of the present invention specification and drawings, or directly or indirectly applied in other related technical fields, are also included in the patent protection scope of the present invention.

Claims

1. A cross-line code defect repair method based on deep learning, characterized in that: The following steps are involved: S1: The system receives the error statement, determines the location of the problem line, and extracts the code language entity; S2: Build a code understanding model, combine the problem line location and error statement, and perform global semantic understanding of the code; Divide the entire code into several code segments according to blank lines or comments, and build a TransGRU module to calculate the segment vector of each code segment and the chapter vector of the entire code; The following steps are involved: S21: Divide the entire code according to blank lines or comments to obtain several code segments; S22: Construct the TransGRU module, the calculation method is: ; Where A is the residual output of the attention mechanism, LayerNorm() is the layer normalization operation, X is the input of the TransGRU module, Attention() is the attention mechanism operation; G is the GRU output, GRU() is the GRU operation, M is the mixed output of the attention mechanism residual and GRU, MLP() is the multi-layer perceptron operation, Y is the output of the TransGRU module, and Concat[,] is the vector concatenation operation; The S22 step is uniformly expressed as: ; Among them, TransGRU () is the TransGRU module operation; S23: Calculate the segment vector of each code segment as follows: ; Among them, y ij is the row vector of the jth line of code in the i-th code segment, i is the code segment index, j is the code line index, code ij is the jth line of code in the ith code segment, V i is the i-th code segment vector, MeanPool() is the average pooling operation, y i1 ,y i2 ,…,y ij is the row vector of all code lines in the i-th code segment; S24: Calculate the chapter vector of the entire code. The calculation method is: ; Among them, R ij is the segment vector V of the code segment i and V j The relationship vector between them, ReLU( ) is the ReLU activation function, W r is the weight matrix for relationship calculation, ⊙ is the product between vector elements; α ij is the segment vector V i Relative to V j The attention score, exp( ) is the exponential operation of taking the natural constant, w is the weight vector, R ik is the segment vector V i and V k , k is the code segment count index, N is the total number of segment vectors of the code segment; C is the chapter vector, α ii is the segment vector V i The self-attention score of S3: Build a logical location model, combine the error statement, code language entity, problem code in the training set, and modified code, and output the problem line number and the problem line logical relationship; Construct the code segment location module, problem line location module, and problem line logic output module of the logic location model to output the probability of defects in each code segment, the probability of each line of code being a problem line, and the logical relationship between problem lines; The following steps are involved: S31: Construct the code segment positioning module of the logic positioning model, take the chapter vector and error statement of the whole code as input, and output the probability of each code segment having a defect, which is calculated as follows: ; Among them, p i is the probability distribution of defects in each code segment, softmax() is the softmax function, W1 is the code segment location parameter, E err is the sentence vector of the error statement, b1 is the code segment location bias vector; S32: Construct a problem line location module of the logic location model, use the segment vector and row vector of the code segment, combined with the error statement, to determine whether each line of code is a problem line, and output the problem line number. The calculation method is: ; Among them, p ij is the probability distribution of defects in each line of code in each code segment, W2 is the problem line location parameter, and b2 is the problem line bias vector; S33: Construct a problem line logic output module of the logic positioning model, input the sentence vector, line number and chapter vector of the problem line into the logic relationship prediction module, and obtain the logical relationship between the problem lines. The calculation method is: ; Among them, x ij is the feature representation of the jth code line in the i-th code segment; n ij is the line number of the jth code line in the i-th code segment, x uq is the feature representation of the qth code line in the uth code segment, u is the second index of the code segment, q is the second index of the code line, and n uq is the line number of the qth code line in the uth code segment, R iujq For x ij and x uq The logical relationship vector between the problem rows, GNN( ) is the graph neural network operation; S4: Combine the logical relationship of the problem line to generate the code defect cause and the modified code and save them in the modification log; The logical relationship between problem lines and problem line information are integrated into graph structure information, and combined with the paragraph vector to generate an explanation of the cause of the code defect; at the same time, entity-first decoding is designed to optimize the TransGRU module, generate repaired code, and avoid factual errors; S5: Integrate with the DevOps process to perform automated testing on the repaired code and retain the code version before the repair.

2. The cross-line code defect repair method based on deep learning according to claim 1 is characterized in that: The step S1 comprises the following steps: S11: Match the line number and file path in the error message through a regular expression; S12: Train ALBERT and extract code language entities, including variable names, function names, class names, method names, interface names, module names, and attribute names. The calculation method is: ; Among them, output includes the variable name, function name, class name, method name, interface name, module name and attribute name of the problem line code, ALBERT() is the ALBERT operation, and input is the problem line code; S13: The output of ALBERT is concatenated with the position information of the problem line into a vector, which serves as part of the input of the next code understanding model.

3. The cross-line code defect repair method based on deep learning according to claim 2 is characterized in that: The step S4 comprises the following steps: S41: integrating the logical relationship between the problem rows and the problem row information into graph structure information, where the nodes represent the problem rows and the edges represent the logical relationship between the problem rows; S42: Input the graph structure information and the paragraph vector into ALBERT and decode it, and generate an explanation of the cause of the code defect by decoding; S43: Design entity-first decoding, and input the logical relationship vector between the problem lines, the paragraph vector and the code language entity into the TransGRU module to generate the repaired code to avoid factual errors. The calculation method is: ; Among them, z is the repaired code feature vector, p code is the probability distribution of the repaired code feature vector, p' is the probability distribution after entity priority decoding, γ is the entity preference strength, log() is the logarithm operation, m is the entity mask, and β is a custom constant.

4. The cross-line code defect repair method based on deep learning according to claim 3 is characterized in that: The step S5 comprises the following steps: S51: Use automated test suites to perform functional and performance tests on the repaired code; S52: The fixed code is integrated into the continuous integration / continuous deployment process; S53: In the version control system, keep the code version before the repair.

5. A cross-line code defect repair system based on deep learning, characterized in that: include: Code language entity extraction module: The system receives the error statement, determines the location of the problem line, and extracts the code language entity; Code comprehension model building module: Build a code comprehension model, combine the problem line location and error statement, and perform global semantic understanding of the code; Logical location model building module: Build a logical location model, combine the error statement, code language entity, problem code in the training set and the modified code, and output the problem line number and the logical relationship of the problem line; Modification result feedback module: Combines the logical relationship of the problem lines to generate the cause of the code defect and the modified code and saves them in the modification log; DevOps integration module: Integrates with the DevOps process to automate the testing of the repaired code and retain the code version before the repair; To implement the cross-line code defect repair method based on deep learning as described in any one of claims 1-4.