Programming question error line code type classification method and system
By preprocessing the programming problem data set and pairing error codes, combining the code pre-training model and attention mechanism, the accurate classification of programming error lines is achieved, and the problems of low efficiency, insufficient accuracy and poor universality in the existing technology are solved.
Patent Information
- Application Number
- CN202411666200.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-20
- Publication Date
- 2025-03-14
- Estimated Expiration
- 2044-11-20
AI Technical Summary
The existing programming problem error code classification technology is low, insufficient accuracy and poor generality, making it difficult to accurately classify and position programming error lines.
By preprocessing the open source programming problem dataset and pairing the error code with the correct code, the vector representation is obtained using the code pretrained model, and the error types are subdivided and classified through the hierarchical slave matrix and attention mechanism.
It improves the classification accuracy and inference efficiency of programming error lines, enhances the overall performance of the model, and reduces the complexity of feature engineering.
Smart Images

Figure CN119621968A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of text classification, and in particular, relates to a classification method and system for error line code types in programming questions. Background Art
[0002] With the popularization of programming education and the in-depth advancement of software development, programming questions have become an important tool for measuring programming and logical ability. In programming exercises and competitions, error code analysis can help students and developers quickly understand and correct the shortcomings in their own code. However, there are still some significant problems with the existing error analysis methods for programming questions. At present, error code analysis mainly relies on manual line-by-line review and comparison of error codes. This method is not only time-consuming and labor-intensive, but also heavily dependent on the professional knowledge level of analysts, making it difficult to ensure the accuracy and consistency of error code classification.
[0003] With the development of artificial intelligence and deep learning technology, code semantic analysis based on pre-trained models has gradually become a hot topic of research. For example, the method proposed by Gupta et al. [1] uses a tree convolutional neural network to represent the code and locates semantic errors in the program through neural prediction technology; Miao et al. [2] combined code2vec with a multi-label classification model to predict multiple semantic errors contained in the error program. Nguyen et al. [3] proposed a fine-grained error location method that uses code representation and reasoning methods based on syntax and semantics to locate errors in student programs. These existing methods need to introduce additional structured information, such as abstract syntax trees (ASTs) and control flow graphs, to assist in code representation learning and error location. Although this method is effective in improving the accuracy of the model, the reliance on these additional information makes the model implementation more complicated, and the training and reasoning process is more time-consuming. In addition, due to the different structural information used by each method, the versatility of these technologies is poor, and the results may not reach the expected accuracy in some specific scenarios.
[0004] Therefore, the existing programming problem error code classification technology still faces problems such as low efficiency, insufficient precision and poor versatility. There is an urgent need for a technical solution that can simplify the processing flow, improve accuracy and reasoning efficiency.
[0005] [1]Gupta R,Kanade A,Shevade S.Neural attribution for semantic bug-localization in student programs[J].Advances inNeuralInformationProcessingSystems,2019,32.
[0006] [2]Miao D,Dong Y,Lu X.PIPE: Predicting Logical Programming Errors in Programming Exercises[J].InternationalEducationalDataMining Society,2020.
[0007] [3]Nguyen TD,Le-Cong T,Luong DM,et al.FFL:Fine-grainedFaultLocalization for StudentPrograms via Syntactic and SemanticReasoning[C] / / 2022 IEEE International Conference on Software Maintenance andEvolution(ICSME).IEEE,2022:151-162.
[0008] Through the above analysis, the problems and defects of the prior art are as follows:
[0009] There are still many technical difficulties in classifying error codes in programming questions. On the one hand, the semantics of code language is significantly different from natural language, and requires a higher level of understanding of the structure, logical relationships, and functional implementation of the code; on the other hand, problems such as matching error codes with correct codes and automatic identification of error types have not yet been effectively solved. Summary of the invention
[0010] In view of the problems existing in the prior art, the present invention provides a classification method for the types of erroneous line codes in programming questions.
[0011] The present invention is implemented in this way: a classification method for the type of wrong line code in a programming question includes:
[0012] S1, preprocessing the open source programming question dataset;
[0013] The dataset is further classified based on the topic ID, so that the programming question codes belonging to the same topic are saved in the same directory, and the data records with lost code files are removed to obtain multiple single topic code datasets;
[0014] S2, for each of the above single-question code data sets, compare and match the error code with the correct code to obtain a paired data set; in each single-question code data set, use the code pre-training model to obtain the vector representation of each error code and the correct code, repeatedly and iteratively calculate the semantic similarity between the error code vector and each correct code vector, and find the correct code that is most similar to the error code as its paired reference code;
[0015] The code is processed by lines, and it is converted from the whole text form into an array form, where each element in the array is a line of code; the line error types of the error codes are obtained from the original data set, and each error line code has a main error type and a corresponding further subdivided sub-error type; the subordinate inclusion relationship of the above error types is analyzed to obtain the error subordinate matrix;
[0016] Finally, a hierarchical label subordinate matrix and an error line code comparison classification data set are obtained, where each line of data contains an error code line array, a correct reference code line array, an error code line error main type label array, and an error code line error subtype label array;
[0017] S3, establish a classification model, input the error code line array in each data obtained in S2 and each line of code text in the correct reference code line array into the pre-trained model, and obtain a code error classification representation set, wherein the code error classification representation set includes an error code line vector representation set, a correct reference code line vector representation set, a correct and incorrect code line attention representation set, and a correct and incorrect code line information fusion representation set;
[0018] S4, calculates the classification label, and passes the linear layer through the fusion representation set of the correct and incorrect code line information obtained in S3 to obtain the error position line number and the main error type label; concatenates the correct and incorrect code line information fusion representation set and the main error type label vector obtained above, passes through the linear layer and multiplies it by the error sub-matrix of S2 to obtain the subdivided sub-error type;
[0019] S5, calculate the loss value, use the cross entropy loss function to compare the error position line number obtained in S4 with the actual error line number to obtain the positioning loss value; use the negative log-likelihood loss function to compare the main error type label obtained in S4 with the actual main error type label to obtain the main class loss value; use the negative log-likelihood loss function to compare the subdivided subtype label obtained in S4 with the actual subdivided subtype label to obtain the subclass loss value; add the three together to obtain the final loss function, and use the loss function to iterate the models in S3 and S4 to the optimal level to obtain a programming question error line code classification model.
[0020] Furthermore, the programming question code includes a correct code and an error code.
[0021] Furthermore, the error code branch vector representation set and the correct reference code branch vector representation set are obtained after each line of code in the correct and error branch code arrays is represented by a code pre-training model, the correct and error code branch attention representation set is obtained by the error code branch vector representation set and the correct reference code branch vector representation set through a scaled dot product attention mechanism, and the correct and error code branch information fusion representation set is obtained by calculating the error code branch vector representation set and the correct and error code branch attention representation set through a gated recurrent unit.
[0022] Another object of the present invention is to provide a classification system for programming problem error line code types, comprising:
[0023] The preprocessing module is used to preprocess the open source programming question data set; the data set is further classified based on the question ID, so that the programming question codes belonging to the same question are saved in the same directory, and the data records with lost code files are removed to obtain multiple single question code data sets;
[0024] A pairing module is used to compare and pair the error code with the correct code for each of the above-mentioned single-topic code data sets to obtain a paired data set; in each single-topic code data set, a code pre-training model is used to obtain the vector representation of each error code and the correct code, and the semantic similarity between the error code vector and each correct code vector is calculated repeatedly and iteratively, and a correct code corresponding to the error code that is most similar to it is found as its paired reference code; the code is processed by line division, and it is converted from the entire text form to an array form, and each element in the array is a line of code; the line error type of the error code is obtained from the original data set, and each error line code has a main error type and a corresponding further subdivided sub-error type; the subordinate inclusion relationship of the above error types is analyzed to obtain an error subordinate matrix; finally, a hierarchical label subordinate matrix and an error line code comparison and classification data set are obtained, and each line of data contains an error code line array, a correct reference code line array, an error code line error main type label array, and an error code line error subtype label array;
[0025] A classification model building module is used to build a classification model, input the error code line array and each line of code text in the correct reference code line array in each data obtained by S2 into the pre-trained model, and obtain a code error classification representation set, wherein the code error classification representation set includes an error code line vector representation set, a correct reference code line vector representation set, a correct and incorrect code line attention representation set, and a correct and incorrect code line information fusion representation set;
[0026] The classification label calculation module is used to establish and calculate the classification label, and obtain the error position line number and the main error type label by the linear layer of the correct and error code line information fusion representation set obtained by S3; the correct and error code line information fusion representation set and the above-obtained main error type label vector are concatenated, and after passing through the linear layer, they are multiplied by the error sub-matrix to which S2 belongs to obtain the subdivided sub-error type;
[0027] The loss value calculation module is used to establish and calculate the loss value. The positioning loss value is obtained by using the cross entropy loss function for the error position line number obtained by S4 and the actual error line number; the main class loss value is obtained by using the negative log-likelihood loss function for the main error type label obtained by S4 and the actual main error type label; the sub-sub-type label obtained by S4 and the actual sub-sub-sub-type label are used to obtain the sub-class loss value; the three are added together to obtain the final loss function, and the loss function is used to iterate the models in S3 and S4 to the optimal level to obtain a programming question error line code classification model.
[0028] Another object of the present invention is to provide a computer device, comprising a memory and a processor, wherein the memory stores a computer program, and when the computer program is executed by the processor, the processor executes the steps of the method for classifying the types of erroneous line codes of programming problems.
[0029] Another object of the present invention is to provide a computer-readable storage medium storing a computer program, which, when executed by a processor, causes the processor to execute the steps of the method for classifying the types of erroneous line codes of programming problems.
[0030] Another object of the present invention is to provide an information data processing terminal, wherein the information data processing terminal is used to implement the classification system of the error line code type of the programming problem.
[0031] In combination with the above technical solutions and the technical problems solved, the advantages and positive effects of the technical solutions to be protected by the present invention are as follows:
[0032] First, a method, storage medium and electronic device for classifying error line code types in programming questions of the present invention extracts code vectors through UniXcoder to reduce the complexity of feature engineering; introduces a hierarchical dependency matrix to enhance the correlation between error types and improve prediction accuracy; uses an attention mechanism to capture the correlation between error codes and reference codes, thereby improving classification accuracy and enhancing the overall performance of the model.
[0033] Second, the expected benefits and commercial value after the transformation of the technical solution of the present invention are as follows: The technical solution of the present invention aims to solve the problem of automated classification of programming question errors, and can accurately locate the error line and error type of the error code of beginners, and provide detailed error classification. This technical solution has significant commercial value in the field of programming education, especially for the needs of programming beginners, which helps to improve learning efficiency and reduce dependence on teachers. The expected benefits include the ability to significantly improve the intelligence level of programming learning software, reduce learning costs, and have broad commercial promotion prospects in scenarios such as online education, programming training, and self-study programming.
[0034] The technical solution of the present invention overcomes technical bias: this method avoids the complicated preprocessing steps and graph structure conversion in the traditional method by using the more expressive UniXcoder unified code pre-training model, thereby realizing code error classification in a more concise way. This method does not rely on the graph structure during the reasoning process, provides a more efficient and intuitive error detection solution, reduces the complexity of data conversion, and is expected to improve the execution efficiency and simplicity of the system. At the same time, this method uses the error subordination matrix to further optimize the hierarchical expression of error types, making error classification more accurate and providing effective support for the final classification label. BRIEF DESCRIPTION OF THE DRAWINGS
[0035] Figure 1 It is a flow chart of a method for classifying types of erroneous line codes of programming questions provided by an embodiment of the present invention.
[0036] Figure 2 It is a structural block diagram of a classification system for incorrect line code types of programming questions provided by an embodiment of the present invention.
[0037] Figure 3 It is a structural diagram of a classification model of incorrect line code types for programming questions provided by an embodiment of the present invention.
[0038] Figure 4 This is an attention distribution diagram of error codes with reference to correct codes provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0039] In order to make the purpose, technical solution and advantages of the present invention more clearly understood, the present invention is further described in detail below in conjunction with the embodiments. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not used to limit the present invention.
[0040] The following are two specific embodiments of the "method for classifying programming problem error line code types" of the present invention:
[0041] Example 1: Automatic error classification and feedback system in programming education platform
[0042] On the programming education platform, after students submit the code for programming problems, the system will automatically detect code errors and provide feedback. Traditional feedback systems usually only give the result of whether the code runs correctly, but cannot specify the line number of the error and the specific error type in detail. The classification method of the present invention can realize the automatic identification of the type of error line code and provide students with accurate feedback.
[0043] 1. Dataset preparation: A large number of programming question instances are extracted from the open source programming question dataset, classified by question ID, and paired data of correct codes and students’ incorrect codes are generated.
[0044] 2. Model application: After processing each error code line by line, it is input into the classification model and compared with the correct code to generate a classification representation set of the error line. Based on the output of the model, the system determines the error line number, main error type, and subdivided error type.
[0045] 3. Feedback generation: Based on the classification results of the model, the system generates detailed error feedback for students, including error location, error type and suggestions on how to modify it, to help students understand and correct errors in the code.
[0046] The system improves the accuracy of the programming education platform in identifying student errors, enables students to obtain effective personalized feedback, and helps to quickly improve their programming skills.
[0047] Example 2: Error classification and automatic detection system in code review tools
[0048] In the software development process, code review is an important step to ensure code quality. Traditional code review tools can only detect format and style issues, and it is difficult to accurately classify and automatically identify code logic errors. The error classification method of the present invention can assist code review tools, automatically locate the line number of code errors and subdivide the error type, thereby improving review efficiency.
[0049] 1. Code data preprocessing: Preprocess the code error samples submitted in the project code library to generate correct code and error code pairing data.
[0050] 2. Model application: The error code is processed line by line and then input into the classification model, which is compared with the correct code to generate a classification result including the error line number, main error type and subdivided error type.
[0051] 3. Error report generation: The classification results are transmitted to the code review system. The system generates an error report based on the output error type and error line number, and provides optimization suggestions for developers.
[0052] The tool realizes automatic detection and classification of code logic errors, greatly improves the efficiency of code review, reduces omissions that may be caused by manual review, and improves the overall quality of the code and development efficiency.
[0053] like Figure 1 As shown, a method for classifying the types of error lines of code in programming problems provided by an embodiment of the present invention comprises the following steps:
[0054] S1, preprocessing the open source programming question dataset;
[0055] The dataset is further classified based on the topic ID, so that the programming question codes belonging to the same topic are saved in the same directory, and the data records with lost code files are removed to obtain multiple single topic code datasets;
[0056] S2, for each of the above single-question code data sets, compare and match the error code with the correct code to obtain a paired data set; in each single-question code data set, use the code pre-training model to obtain the vector representation of each error code and the correct code, repeatedly and iteratively calculate the semantic similarity between the error code vector and each correct code vector, and find the correct code that is most similar to the error code as its paired reference code;
[0057] The code is processed by lines, and it is converted from the whole text form into an array form, where each element in the array is a line of code; the line error types of the error codes are obtained from the original data set, and each error line code has a main error type and a corresponding further subdivided sub-error type; the subordinate inclusion relationship of the above error types is analyzed to obtain the error subordinate matrix;
[0058] Finally, a hierarchical label subordinate matrix and an error line code comparison classification data set are obtained, where each line of data contains an error code line array, a correct reference code line array, an error code line error main type label array, and an error code line error subtype label array;
[0059] S3, establish a classification model, input the error code line array in each data obtained in S2 and each line of code text in the correct reference code line array into the pre-trained model, and obtain a code error classification representation set, wherein the code error classification representation set includes an error code line vector representation set, a correct reference code line vector representation set, a correct and incorrect code line attention representation set, and a correct and incorrect code line information fusion representation set;
[0060] S4, calculates the classification label, and passes the linear layer through the fusion representation set of the correct and incorrect code line information obtained in S3 to obtain the error position line number and the main error type label; concatenates the correct and incorrect code line information fusion representation set and the main error type label vector obtained above, passes through the linear layer and multiplies it by the error sub-matrix of S2 to obtain the subdivided sub-error type;
[0061] S5, calculate the loss value, use the cross entropy loss function to compare the error position line number obtained in S4 with the actual error line number to obtain the positioning loss value; use the negative log-likelihood loss function to compare the main error type label obtained in S4 with the actual main error type label to obtain the main class loss value; use the negative log-likelihood loss function to compare the subdivided subtype label obtained in S4 with the actual subdivided subtype label to obtain the subclass loss value; add the three together to obtain the final loss function, and use the loss function to iterate the models in S3 and S4 to the optimal level to obtain a programming question error line code classification model.
[0062] The method for classifying the types of error lines in programming questions of the present invention processes a programming question dataset and establishes a classification model through a series of steps, aiming to accurately classify the types of error lines in code so as to better analyze and locate programming errors. The specific working principle is as follows:
[0063] 1. Dataset preprocessing and classification
[0064] First, the open source programming question dataset is preprocessed. The code of the same question is stored in the same directory based on the question ID, thus forming multiple single question code datasets. In this process, data records with missing code files are deleted to ensure data integrity and consistency. The goal of this step is to focus subsequent processing on a single question code, facilitating a more in-depth analysis of the error types of different question codes.
[0065] 2. Error code matching and error type analysis
[0066] In each single-question code data set, the error code is compared and paired with the correct code. Using the code pre-training model, a vector representation is generated for each error code and correct code, and the semantic similarity between the error code vector and the correct code vector is calculated. Through loop iteration, the correct code that is most similar to the error code is found and used as the paired reference code for the error code. Then, the code is processed row by row and converted into an array form, and the main error type and sub-type of each row of code are extracted. The subordination relationship of the error type is analyzed to obtain the error subordination matrix. This step generates the row error labels and the subordination matrix, which provides the necessary input data for the classification model.
[0067] 3. Classification model establishment and representation generation
[0068] A classification model is established, and the error code row array and the correct code row array in each data are input into the pre-trained model row by row to generate a classification representation set of code errors. This representation set includes error code row vectors, correct code row vectors, attention representations of correct and incorrect code rows, and row representations that incorporate correct and incorrect code information. These representations describe the characteristics of error codes from multiple aspects and provide the information required by the classification model by focusing on the differences between correct and incorrect codes.
[0069] 4. Calculation of major and segmentation fault type labels
[0070] Based on the generated representation, the correct and incorrect code line information fusion representation set is processed by the linear layer to obtain the error position line number and the main error type label. At the same time, the generated main error type label vector is concatenated with the correct and incorrect code line information fusion representation set, further processed by the linear layer, and multiplied by the error sub-matrix to obtain a more refined sub-error type label. In this way, the model realizes the hierarchical prediction of error types, making error classification more hierarchical and accurate.
[0071] 5. Loss calculation and model optimization
[0072] During the training process of the model, the model is optimized by calculating different loss values. First, the cross entropy loss is calculated for the error position row number and the true row number to obtain the positioning loss value; secondly, the negative log-likelihood loss is calculated for the main error type label and the true label to obtain the main class loss value; finally, the negative log-likelihood loss is calculated for the sub-type label and the true label to obtain the sub-class loss value. The three are added together to obtain the comprehensive loss value, which is used as the final loss function to guide the model training process.
[0073] 6. Iterative Optimization of Classification Model
[0074] Through the calculation and feedback of the loss function, the model is continuously iterated and optimized during the training process, and the model parameters are adjusted so that the loss function is gradually reduced and finally reaches the optimum. After sufficient training, the model can efficiently identify the location of the error line, the main error type, and the sub-type label. In this way, the final obtained programming question error line code classification model has high accuracy and robustness, and can accurately classify and locate the error types of programming questions in practical applications, thereby providing support for programming education and code error analysis.
[0075] The programming question code provided by the embodiment of the present invention includes a correct code and an error code.
[0076] The error code branch vector representation set and the correct reference code branch vector representation set provided in the embodiment of the present invention are obtained after each line of code in the correct and error branch code arrays is represented by a code pre-training model, the correct and error code branch attention representation set is obtained by the error code branch vector representation set and the correct reference code branch vector representation set through a scaled dot product attention mechanism, and the correct and error code branch information fusion representation set is obtained by calculating the error code branch vector representation set and the correct and error code branch attention representation set through a gated recurrent unit.
[0077] like Figure 2 As shown, a classification system for programming problem error line code types provided by an embodiment of the present invention includes:
[0078] The preprocessing module is used to preprocess the open source programming question data set; the data set is further classified based on the question ID, so that the programming question codes belonging to the same question are saved in the same directory, and the data records with lost code files are removed to obtain multiple single question code data sets;
[0079] A pairing module is used to compare and pair the error code with the correct code for each of the above-mentioned single-topic code data sets to obtain a paired data set; in each single-topic code data set, a code pre-training model is used to obtain the vector representation of each error code and the correct code, and the semantic similarity between the error code vector and each correct code vector is calculated repeatedly and iteratively, and a correct code corresponding to the error code that is most similar to it is found as its paired reference code; the code is processed by line division, and it is converted from the entire text form to an array form, and each element in the array is a line of code; the line error type of the error code is obtained from the original data set, and each error line code has a main error type and a corresponding further subdivided sub-error type; the subordinate inclusion relationship of the above error types is analyzed to obtain an error subordinate matrix; finally, a hierarchical label subordinate matrix and an error line code comparison and classification data set are obtained, and each line of data contains an error code line array, a correct reference code line array, an error code line error main type label array, and an error code line error subtype label array;
[0080] A classification model building module is used to build a classification model, input the error code line array and each line of code text in the correct reference code line array in each data obtained by S2 into the pre-trained model, and obtain a code error classification representation set, wherein the code error classification representation set includes an error code line vector representation set, a correct reference code line vector representation set, a correct and incorrect code line attention representation set, and a correct and incorrect code line information fusion representation set;
[0081] The classification label calculation module is used to establish and calculate the classification label, and obtain the error position line number and the main error type label by the linear layer of the correct and error code line information fusion representation set obtained by S3; the correct and error code line information fusion representation set and the above-obtained main error type label vector are concatenated, and after passing through the linear layer, they are multiplied by the error sub-matrix to which S2 belongs to obtain the subdivided sub-error type;
[0082] The loss value calculation module is used to establish and calculate the loss value. The positioning loss value is obtained by using the cross entropy loss function for the error position line number obtained by S4 and the actual error line number; the main class loss value is obtained by using the negative log-likelihood loss function for the main error type label obtained by S4 and the actual main error type label; the sub-sub-type label obtained by S4 and the actual sub-sub-sub-type label are used to obtain the sub-class loss value; the three are added together to obtain the final loss function, and the loss function is used to iterate the models in S3 and S4 to the optimal level to obtain a programming question error line code classification model.
[0083] Another object of the present invention is to provide a computer device, comprising a memory and a processor, wherein the memory stores a computer program, and when the computer program is executed by the processor, the processor executes the steps of the method for classifying the types of erroneous line codes of programming problems.
[0084] Another object of the present invention is to provide a computer-readable storage medium storing a computer program, which, when executed by a processor, causes the processor to execute the steps of the method for classifying the types of erroneous line codes of programming problems.
[0085] Another object of the present invention is to provide an information data processing terminal, wherein the information data processing terminal is used to implement the classification system of the error line code type of the programming problem.
[0086] Example 3
[0087] This embodiment discloses a method for classifying the types of error lines of code in programming problems, including the following steps:
[0088] S1, preprocessing the open source programming question dataset. The dataset is further classified based on the question ID, so that the programming question codes (including correct codes and error codes) belonging to the same question are saved in the same directory, and the data records with lost code files are removed to obtain multiple single question code datasets.
[0089] Each piece of data in the open source programming question code data set selected in this embodiment includes the code text, whether an error occurs, the main error type, the sub-error type, the error code line number, and the programming question ID to which it belongs. For S1 data preprocessing, first, clear the records of all missing code files in the data set to ensure the integrity and accuracy of the data. Extract all unique programming question IDs from the cleaned data set as the basis for subsequent classification. For each extracted programming question ID, collect all the original data rows associated with it. Package the data rows to which each programming question belongs, including code text, whether an error occurs, the main error type, the sub-error type, the error code line number, and the programming question ID to which it belongs, as the data source for the subsequent implementation step S2.
[0090] S2, for each of the above single-question code data sets, compare and match the error code with the correct code to obtain a paired data set. In each single-question code data set, use the code pre-training model to obtain the vector representation of each error code and the correct code, repeatedly iterate and calculate the semantic similarity between the error code vector and each correct code vector, and find the correct code that is most similar to the error code as its paired reference code.
[0091] The specific process is as follows: for each individual programming question code data set, all correct code text sets C = {c1, c2, ..., c n} Each correct code text c i , respectively obtain the correct code representation set through the UniXcoder code pre-training model It is expressed as:
[0092]
[0093] Then the error code text set E = {e1, e2, ..., e m} Each error code text in i , get its vector representation through the UniXcoder model With H c All correct codes in the representation are calculated cosine similarity, and the correct code with the highest similarity is selected as the reference code r of the wrong code i , obtain the reference code text set R = {r1, r2, r3, ..., r n}. This process can be expressed as:
[0094] r i =c j
[0095]
[0096] Among them, j is the correct code number selected as the reference code, k represents all the correct code number identifiers in the programming question data set, and the calculation formula of cosine similarity is:
[0097]
[0098] In this formula, Error code e i The vector representation of For the correct code c k The vector representation of .
[0099] The code is processed by line division, and it is converted from the whole text form to array form, and the array content is a line of code. The line error type of the error code is obtained from the original data set. Each error line code has a main error type and a corresponding further subdivided sub-error type. The subordinate inclusion relationship of the above error types is analyzed to obtain the error subordinate matrix.
[0100] The specific process is: for the error code text set E = {e1, e2, e3, ..., e n} and its corresponding reference code text set R = {r1, r2, r3, ..., r n}, split each error code text e1 and its reference code text r1 line by line into a code line array E lines , R lines :
[0101]
[0102] Among them, e ij Indicates error code e i The jth line of code in r ij Indicates reference code r i The jth line of code in and Respectively represent e i 、r i For each line of error code, if the line contains an error, its main error type and sub-error type are recorded. Define the main error type label array Array of sub-error type labels as follows:
[0103]
[0104] in, Indicates error code e i The primary error type of row j in Indicates error code e i The sub-error type of the jth row in . There are 4 main error types in total according to the statistical analysis. The value ranges from 0 to 4, 0 means no error; there are 16 sub-error types, so The value ranges from 0 to 16, where 0 means no error. At the same time, the two types of error labels have a subordinate relationship, that is, the sub-error type must be a main error type, so the subordinate relationship matrix is defined Among them, M ij Represents the specific value of the i-th row and j-th column in M:
[0105]
[0106] Finally, a hierarchical label subordination matrix and an error line code comparison classification data set are obtained. Each line of data contains an error code line array, a correct reference code line array, an error code error line number array, and an error code error type array.
[0107] S3, establish a classification model, input the error code branch array in each data obtained in S2 and each line of code text in the correct reference code branch array into the pre-trained model, and obtain a code error classification representation set, wherein the code error classification representation set includes an error code branch vector representation set, a correct reference code branch vector representation set, a correct and error code branch attention representation set, and a correct and error code branch information fusion representation set.
[0108] The error code branch vector representation set and the correct reference code branch vector representation set are obtained by representing each line of code in the correct and error branch code arrays through a code pre-training model; the correct and error code branch attention representation set is obtained by using the error code branch vector representation set and the correct reference code branch vector representation set through a scaled dot product attention mechanism; the correct and error code branch information fusion representation set is obtained by calculating the error code branch vector representation set and the correct and error code branch attention representation set through a gated recurrent unit.
[0109] The specific process is: divide the error code in each row of data into a row array and reference code line array Each line of code in ij , r ij Use the UniXcoder pre-trained model to identify it and obtain the row-level vector representation of the error code and reference code
[0110]
[0111] in Error code e i The representation vector of the j-th line of code in after being represented by the UniXcoder model, For reference code r i The representation vector of the j-th line of code in after being represented by the UniXcoder model.
[0112] Computing error codes using scaled dot-product attention and the row-level vector representation of the reference code The attention vector A atte , which reflects the reference attention relationship between the error code and the reference code, and reflects the correlation between each row of error code and all reference code rows. The specific calculation formula is:
[0113]
[0114] Among them, Q is the attention mechanism query matrix, K is the attention mechanism key vector, V is the attention mechanism value matrix, and d k is the dimension of K, avoiding gradient instability that may be caused by large dot products.
[0115] Next, the attention vector A atte A vector representation of the branch with error codes Fusion is performed to obtain the information fusion representation set Specifically implemented through the gated cycle unit GRU:
[0116]
[0117] Through the gated recurrent unit, While emphasizing the error code representation, the attention relationship between the error code and the reference code is synthesized.
[0118] S4, calculates the classification label, and passes the linear layer through the fusion representation set of the correct and error code line information obtained in S3 to obtain the error position line number and the main error type label; concatenates the correct and error code line information fusion representation set and the main error type label vector obtained above, passes through the linear layer and multiplies it by the error sub-matrix of S2 to obtain the sub-error type.
[0119] The specific process is:
[0120] The error code branch information is fused into a representation set After a linear layer and softmax activation function, the probability of each main error label for each line of code is calculated.
[0121]
[0122] Where W pri and b pri are the weight matrix and bias term of the linear transformation respectively.
[0123] When calculating the sub-error type, the main error type label vector obtained above can be used Improve the prediction accuracy. First, the correct and incorrect code branch information is fused into a representation set and Perform splicing to obtain a mixed representation After that, use After another linear layer, we get the original output of the sub-error type
[0124]
[0125] Where W sub and b sub are the weight matrix and bias term of the linear transformation respectively.
[0126] take out The value with the highest probability of the main error type in the code is the main error type predicted by the line of code, which is obtained by index value It can correspond to a row of the subordinate matrix M, representing the sub-error type owned by the main error type, and the original output of the sub-error type of the row By performing element-by-element multiplication, some impossible prediction results can be filtered out, and finally the softmax function is used to obtain a more accurate probability distribution of sub-error type labels. The above process can be expressed as:
[0127]
[0128] S5, calculate the loss value, use the cross entropy loss function to compare the error position line number obtained by S4 with the actual error line number to obtain the positioning loss value; use the negative log-likelihood loss function to compare the main error type label obtained by S4 with the actual main error type label to obtain the main class loss value; use the negative log-likelihood loss function to compare the subdivision subtype label obtained by S4 with the actual subdivision subtype label to obtain the subclass loss value, and add the three together to get the final loss function.
[0129] The specific process is as follows: For the positioning loss value, first use the main error type label in step S2 Get the true label of the error position line number. If If the value is not 0, it means that the line of code is an error code, thus obtaining the true label of the error position
[0130]
[0131]
[0132] Predicted error line number predicted by main error type Calculate, yes The predicted value of each line of code in , take the probability values of all classes other than the non-zero class (that is, the correct class) and sum them to get the predicted value of the error position
[0133]
[0134] in for The main error type prediction value of each row in , c represents the label class index, and Pnum represents the total number of main error types.
[0135] For each Calculate the cross entropy loss to get the positioning loss value L loc :
[0136]
[0137] Among them, n represents the total number of training set data, that is, the total number of error codes, and m is the number of code lines for each error code.
[0138] For each Calculate the negative log-likelihood loss to get the main type loss value L pri :
[0139]
[0140] in Error code e i The main false true label for each row, Error code e i Distribution of the main error probability for each row of the prediction.
[0141] For each Calculate the negative log-likelihood loss to get the main type loss value L sub :
[0142]
[0143] in Error code e i Subtype error true label for each row, Error code e i The predicted per-row subtype error probability distribution.
[0144] Add the above three losses together to get the total loss function L of the entire model. total :
[0145] L total =αL loc +βL pri +γL sub
[0146] Among them, α, β, and γ are the hyperparameter weights of the loss, which control the relative importance of each loss in the total loss.
[0147] The loss function is used to iterate the models in S3 and S4 to the optimum, thereby obtaining a programming question error line code classification model.
[0148] Example 4
[0149] This embodiment discloses an electronic device, including: a memory for storing executable instructions; a processor for executing the executable instructions stored in the memory to implement the method for classifying programming problem error line code types disclosed in Example 1.
[0150] Example 5
[0151] This embodiment discloses a computer-readable storage medium storing executable instructions for causing a processor to execute the executable instructions to implement the method for classifying programming problem error line code types disclosed in Embodiment 1.
[0152] The storage medium can be a computer-readable storage medium, for example, a ferroelectric random access memory (FRAM), a read-only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), an electrically erasable programmable read-only memory (EEPROM), a flash memory, a magnetic surface memory, an optical disk, or a compact disk read-only memory (CD-ROM); it can also be various devices including one or any combination of the above memories.
[0153] In one embodiment, executable instructions may be in the form of a program, software, software module, script or code, written in any form of programming language (including compiled or interpreted languages, or declarative or procedural languages), and may be deployed in any form, including as a stand-alone program or as a module, component, subroutine or other unit suitable for use in a computing environment.
[0154] As an example, executable instructions may, but need not necessarily, correspond to a file in a file system, may be stored as part of a file storing other programs or data, for example, in one or more scripts in a Hyper Text Markup Language (HTML) document, in a single file dedicated to the program in question, or in multiple coordinated files (e.g., files storing one or more modules, subroutines, or code portions). As an example, executable instructions may be deployed to be executed on one electronic device, or on multiple electronic devices located at one location, or on multiple electronic devices distributed at multiple locations and interconnected by a communication network.
[0155] In the embodiments provided in the present application, it should be understood that the disclosed devices and methods can also be implemented in other ways. The device embodiments described above are merely schematic. For example, the flowcharts and block diagrams in the accompanying drawings show the possible architecture, functions and operations of the devices, methods and computer program products according to the multiple embodiments of the present application. In this regard, each box in the flowchart or block diagram can represent a module, a program segment or a part of a code, and the module, a program segment or a part of a code contains one or more executable instructions for implementing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two consecutive boxes can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram and / or the flowchart, and the combination of boxes in the block diagram and / or the flowchart can be implemented with a dedicated hardware-based system that performs a specified function or action, or can be implemented with a combination of dedicated hardware and computer instructions.
[0156] In addition, the functional modules in the various embodiments of the present application may be integrated together to form an independent part, or each module may exist separately, or two or more modules may be integrated to form an independent part.
[0157] If the functions are implemented in the form of software function modules and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application can be essentially or partly embodied in the form of a software product that contributes to the prior art. The computer software product is stored in a storage medium, including several instructions to enable a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the methods described in each embodiment of the present application. The aforementioned storage medium includes: various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk.
[0158] The present invention can be applied to a learning assistance system for programming beginners, and is suitable for a learning scenario that provides real-time error feedback and intelligent guidance. In this application scenario, after a programming beginner submits code, the error classification module of the present invention can automatically identify and classify code errors, and directly return the analysis results to the student so that he or she can accurately understand the source and nature of the error. This solution can significantly improve the efficiency of code error location, and will also effectively reduce the frustration of learners when they are just starting to learn programming, thereby prompting them to master the basic knowledge of programming more efficiently.
[0159] Furthermore, the present invention can be combined with the large model retrieval enhancement process to provide more targeted programming learning feedback by constructing a wrong question library containing typical wrong examples or a similar problem retrieval mechanism. When the system detects a certain type of specific error, it will retrieve similar cases in the large model wrong question library and generate detailed explanations and improvement suggestions to help learners understand the error logic more deeply and achieve self-correction. The system will effectively improve the accuracy of programming learning and the reliability of intelligent feedback, while optimizing the overall process of programming learning, and provide stable and reliable technical support for beginners' programming learning.
[0160] In order to verify the effectiveness of this method in improving the misclassification effect, a classification model without the aforementioned attention mechanism and subordinate matrix filtering operation is used to benchmark the dataset, and the weighted precision, weighted recall and weighted F1-score are calculated as evaluation indicators, with accuracy as the main criterion. The specific method is as follows:
[0161] UniXcoder classification model: The incorrect branch codes and correct reference branch codes in the dataset are sent to UniXcoder to obtain the code representation vector, which is then concatenated and sent to the linear classification layer to perform label prediction on the output representation vector.
[0162] The results are shown in Table 1 and Table 2. From the experimental results, we can see that the proposed method has achieved leading results in all indicators. Among them, the accuracy and F1 value are two summation measurement indicators, and the proposed method far exceeds the baseline model. In the third row of the two tables, this paper removes the error type subordinate matrix to conduct an ablation experiment. The experiment shows that the introduction of subordinate matrix information effectively improves the model's ability to classify sub-error types of error code lines, and also improves the classification ability of main error types. At the same time, by comparing the third row with the first row, it can be seen that the row-level correct and incorrect code vector cross-attention mechanism used greatly improves the classification ability of the baseline model for this task.
[0163] Table 1 Experimental results of main error types of experimental benchmarks
[0164]
[0165] Table 2 Experimental results of experimental benchmark sub-error types
[0166]
[0167] It should be noted that the embodiments of the present invention can be implemented by hardware, software, or a combination of software and hardware. The hardware part can be implemented using dedicated logic; the software part can be stored in a memory and executed by an appropriate instruction execution system, such as a microprocessor or dedicated design hardware. It can be understood by a person of ordinary skill in the art that the above-mentioned devices and methods can be implemented using computer executable instructions and / or contained in a processor control code, such as a carrier medium such as a disk, CD or DVD-ROM, a programmable memory such as a read-only memory (firmware), or a data carrier such as an optical or electronic signal carrier. Such code is provided on the carrier medium. The device and its modules of the present invention can be implemented by hardware circuits such as very large-scale integrated circuits or gate arrays, semiconductors such as logic chips, transistors, etc., or programmable hardware devices such as field programmable gate arrays, programmable logic devices, etc., can also be implemented by software executed by various types of processors, and can also be implemented by a combination of the above-mentioned hardware circuits and software, such as firmware.
[0168] The above description is only a specific implementation mode of the present invention, but the protection scope of the present invention is not limited thereto. Any modifications, equivalent substitutions and improvements made by any technician familiar with the technical field within the technical scope disclosed by the present invention and within the spirit and principle of the present invention should be covered by the protection scope of the present invention.
Claims
1. A method for classifying the types of incorrect lines of code in programming questions, characterized in that: The following steps are involved: S1, preprocessing the open source programming question dataset; The dataset is further classified based on the topic ID, so that the programming question codes belonging to the same topic are saved in the same directory, and the data records with lost code files are removed to obtain multiple single topic code datasets; S2, for each of the above single-question code data sets, compare and match the error code with the correct code to obtain a paired data set; In each single-question code dataset, the code pre-training model is used to obtain the vector representation of each error code and the correct code. The semantic similarity between the error code vector and each correct code vector is calculated repeatedly and iteratively. The most similar correct code corresponding to the error code is found as its paired reference code. The code is processed by lines, and it is converted from the whole text form into an array form, where each element in the array is a line of code; the line error type of the error code is obtained from the original data set, and each error line code has a main error type and a corresponding further subdivided sub-error type; Analyze the subordinate inclusion relationship of the above error types to obtain the error subordinate matrix; Finally, a hierarchical label subordinate matrix and an error line code comparison classification data set are obtained, where each line of data contains an error code line array, a correct reference code line array, an error code line error main type label array, and an error code line error subtype label array; S3, establish a classification model, input the error code line array in each data obtained in S2 and each line of code text in the correct reference code line array into the pre-trained model, and obtain a code error classification representation set, wherein the code error classification representation set includes an error code line vector representation set, a correct reference code line vector representation set, a correct and incorrect code line attention representation set, and a correct and incorrect code line information fusion representation set; S4, calculates the classification label, and passes the linear layer through the fusion representation set of the correct and incorrect code line information obtained in S3 to obtain the error position line number and the main error type label; concatenates the correct and incorrect code line information fusion representation set and the main error type label vector obtained above, passes through the linear layer and multiplies it by the error sub-matrix of S2 to obtain the subdivided sub-error type; S5, calculate the loss value, and use the cross entropy loss function to obtain the positioning loss value for the error position line number obtained by S4 and the actual error line number; use the negative log-likelihood loss function to obtain the main class loss value for the main error type label obtained by S4 and the actual main error type label; use the negative log-likelihood loss function to obtain the subclass loss value for the subdivided subtype label obtained by S4 and the actual subdivided subtype label; The three are added together to obtain the final loss function, and the models in S3 and S4 are iterated to the optimum using the loss function to obtain a programming question error line code classification model.
2. The method for classifying the types of wrong line codes in programming questions as claimed in claim 1, characterized in that: The programming question code includes a correct code and an error code.
3. The method for classifying the types of wrong line codes in programming problems according to claim 1, characterized in that: The error code branch vector representation set and the correct reference code branch vector representation set are obtained by representing each line of code in the correct and error branch code arrays through a code pre-training model; the correct and error code branch attention representation set is obtained by using the error code branch vector representation set and the correct reference code branch vector representation set through a scaled dot product attention mechanism; the correct and error code branch information fusion representation set is obtained by calculating the error code branch vector representation set and the correct and error code branch attention representation set through a gated recurrent unit.
4. A system for classifying wrong line code types of programming problems implementing the method for classifying wrong line code types of programming problems as claimed in any one of claims 1 to 3, characterized in that: The classification system of the programming question error line code type includes: The preprocessing module is used to preprocess the open source programming question data set; the data set is further classified based on the question ID, so that the programming question codes belonging to the same question are saved in the same directory, and the data records with lost code files are removed to obtain multiple single question code data sets; A pairing module is used to compare and pair the error code with the correct code for each of the above-mentioned single-topic code data sets to obtain a paired data set; in each single-topic code data set, a code pre-training model is used to obtain the vector representation of each error code and the correct code, and the semantic similarity between the error code vector and each correct code vector is calculated repeatedly and iteratively, and a correct code corresponding to the error code that is most similar to it is found as its paired reference code; the code is processed by line division, and it is converted from the entire text form to an array form, and each element in the array is a line of code; the line error type of the error code is obtained from the original data set, and each error line code has a main error type and a corresponding further subdivided sub-error type; the subordinate inclusion relationship of the above error types is analyzed to obtain an error subordinate matrix; finally, a hierarchical label subordinate matrix and an error line code comparison and classification data set are obtained, and each line of data contains an error code line array, a correct reference code line array, an error code line error main type label array, and an error code line error subtype label array; A classification model building module is used to build a classification model, input the error code line array in each data obtained by S2 and each line of code text in the correct reference code line array into the pre-trained model, and obtain a code error classification representation set, wherein the code error classification representation set includes an error code line vector representation set, a correct reference code line vector representation set, a correct and incorrect code line attention representation set, and a correct and incorrect code line information fusion representation set; The classification label calculation module is used to establish and calculate the classification label, and obtain the error position line number and the main error type label by the linear layer of the correct and error code line information fusion representation set obtained by S3; the correct and error code line information fusion representation set and the above-obtained main error type label vector are concatenated, and after passing through the linear layer, they are multiplied by the error sub-matrix to which S2 belongs to obtain the subdivided sub-error type; The loss value calculation module is used to establish and calculate the loss value. The positioning loss value is obtained by using the cross entropy loss function for the error position line number obtained by S4 and the actual error line number; the main class loss value is obtained by using the negative log-likelihood loss function for the main error type label obtained by S4 and the actual main error type label; the sub-sub-type label obtained by S4 and the actual sub-sub-sub-type label are used to obtain the sub-class loss value; the three are added together to obtain the final loss function, and the loss function is used to iterate the models in S3 and S4 to the optimal level to obtain a programming question error line code classification model.
5. A computer device, characterized in that: The computer device includes a memory and a processor, wherein the memory stores a computer program, and when the computer program is executed by the processor, the processor executes the steps of the method for classifying the type of erroneous line codes of programming problems as described in any one of claims 1-3.
6. A computer-readable storage medium storing a computer program, wherein when the computer program is executed by a processor, the processor executes the steps of the method for classifying the types of erroneous line codes of programming problems as described in any one of claims 1 to 3.
7. An information data processing terminal, characterized in that: The information data processing terminal is used to implement the classification system of programming problem error line code types as described in claim 4.
Citation Information
Patent Citations
Software code line-level defect detection method based on deep learning
CN110825642A
Deep knowledge tracking method and system applied to multivariate programming exercises
CN116860995A
Dynamic and static combined programming question automatic scoring and feedback method based on abstract syntax tree
CN118093412A
Code text information-containing repeated post labeling method, storage medium and electronic equipment
CN118246458A
Method and device for locating programming language errors and electronic equipment
CN118331878A