A method and system for classifying error line code types of programming problems

By preprocessing and vectorizing open-source programming problem datasets, a classification model is established, which solves the problems of low efficiency and insufficient accuracy in the classification of programming error codes in existing technologies. It achieves efficient and accurate automatic identification and classification of error codes, improving the efficiency and quality of programming education and code review.

CN119621968BActive Publication Date: 2025-11-25NORTHWEST UNIV
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202411666200.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-11-20
Publication Date
2025-11-25
Estimated Expiration
2044-11-20

Smart Images

  • Figure CN119621968B_ABST
    Figure CN119621968B_ABST
Patent Text Reader

Abstract

The application belongs to the technical field of text classification, and discloses a programming question error line code type classification method, and aims to provide a programming question error line code type classification method, a storage medium and an electronic device. Through the application, the relationship between correct and error codes can be more fully utilized, the classification of programming question error codes can be more accurately performed, and the accuracy and efficiency of code error classification are improved. The programming question error line code type classification method, the storage medium and the electronic device of the application extract code vectors through UniXcoder, reduce the complexity of feature engineering, introduce a hierarchical subordination matrix to enhance the relevance of error types and improve the prediction accuracy, use an attention mechanism to capture the relevance of error codes and reference codes, and further improve the classification accuracy, so that the overall performance of the model is enhanced.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The application belongs to the technical field of text classification, and particularly relates to a programming question error line code type classification method and system. BACKGROUND

[0002] With the popularization of programming education and the in-depth promotion of software development, programming questions have become an important tool for measuring program design and logical ability. In programming practice and competitions, error code analysis can help students and developers quickly understand and correct their own shortcomings in writing code. However, the existing programming question error analysis method still has some significant problems. Currently, error code analysis mainly relies on manual line-by-line review and comparison of error code, which is not only time-consuming and labor-intensive, but also heavily dependent on the professional knowledge level of the analyst, making it difficult to guarantee 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 research hotspot. For example, Gupta [1] et al. proposed a method using tree convolutional neural networks to represent code and locating semantic errors in programs through neural prediction technology; Miao [2] et al. combined code2vec with a multi-label classification model to predict multiple semantic errors contained in the error program. Nguyen [3] et al. proposed a fine-grained error localization method that uses syntax and semantic-based code representation and reasoning methods to locate errors in student programs. These existing methods require the introduction of additional structured information, such as abstract syntax trees (AST), control flow graphs, etc., to assist code representation learning and error localization. Although this approach effectively improves the accuracy of the model, the reliance on these additional information makes the implementation of the model more complex, and the training and inference process is time-consuming. In addition, due to the different structural information used by each method, the generality of these technologies is poor, and the accuracy in some specific scenarios may not meet the expected accuracy.

[0004] Therefore, the existing programming question error code classification technology still faces problems such as low efficiency, insufficient accuracy, and poor generality, and there is an urgent need for a technical solution that can simplify the processing process, improve accuracy, and improve inference efficiency.

[0005] [1] Gupta R, Kanade A, Shevade S. Neural attribution for semantic bug-localization in student programs [J]. Advances in Neural Information Processing Systems, 2019, 32.

[0006] [2]Miao D, Dong Y, Lu X. PIPE: Predicting Logical Programming Errors in Programming Exercises [J]. International Educational Data Mining Society, 2020.

[0007] [3]Nguyen T D, Le-Cong T, Luong D M, et al. FFL: Fine-grained Fault Localization for Student Programs via Syntactic and Semantic Reasoning [C] / / 2022 IEEE International Conference on Software Maintenance and Evolution (ICSME). IEEE, 2022: 151-162.

[0008] Through the above analysis, the problems and defects of the prior art are:

[0009] The classification of error code of programming questions still has many technical difficulties. On the one hand, the semantics of code language is significantly different from natural language, and the understanding of the structure, logical relationship and function implementation of code is required to be higher; on the other hand, the pairing of error code and correct code, the automatic identification of error type and the like have not been effectively solved. SUMMARY

[0010] In view of the problems existing in the prior art, the present application provides a classification method of error line code type of programming questions.

[0011] The present application is implemented in the following way, a classification method of error line code type of programming questions comprises:

[0012] S1, preprocessing the open source programming question data set;

[0013] Further classify the data set according to the question ID, save the programming question codes belonging to the same question to the same directory, and remove the data records missing the code files, to obtain a plurality of single question code data sets;

[0014] S2, for each single question code data set, compare and match the error code with the correct code to obtain the matching 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 correct code, repeatedly loop and iterate to calculate the semantic similarity between the error code vector and each correct code vector, and find one of the correct codes most similar to the error code as the matching reference code of the error code;

[0015] The code is processed by line, which is converted from the form of a whole text to an array form, and each element in the array is a line of code; the 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 dependent inclusion relationship of the above error types is analyzed to obtain an error dependent matrix;

[0016] Finally, a hierarchical label dependent matrix and an error line code comparison and classification data set are obtained, each row of data including an error code line array, a correct reference code line array, an error main type label array of the error code line, and an error sub-type label array of the error code line;

[0017] S3, a classification model is established, and each line of code text in the error code line array and the correct reference code line array in each data obtained in S2 is input into a pre-training model to obtain a code error classification representation set, the code error classification representation set including an error code line vector representation set, a correct reference code line vector representation set, a correct code line attention representation set, and a correct code line information fusion representation set;

[0018] S4, a classification label is calculated, and the correct code line information fusion representation set obtained in S3 is subjected to a linear layer to obtain an error position line number and a main error type label; the correct code line information fusion representation set and the main error type label vector obtained above are spliced, and after passing through a linear layer, the subdivided sub-error type is obtained by multiplying the error dependent matrix of S2;

[0019] S5, a loss value is calculated, and the error position line number obtained in S4 and the real error line number are subjected to a cross-entropy loss function to obtain a positioning loss value; the main error type label obtained in S4 and the real main error type label are subjected to a negative log-likelihood loss function to obtain a main class loss value; the subdivided sub-type label obtained in S4 and the real subdivided sub-type label are subjected to a negative log-likelihood loss function to obtain a sub-class loss value; the three are added to obtain a final loss function, and the loss function is used to iterate the models in S3 and S4 to the optimal, to obtain a programming question error line code classification model.

[0020] Further, the programming question code includes correct code and error code.

[0021] Further, the error code line vector representation set and the correct reference code line vector representation set are obtained after each line of code in the correct and error code line array is represented by the code pre-training model, the correct and error code line attention representation set is obtained by scaling the dot product attention mechanism from the error code line vector representation set and the correct reference code line vector representation set, and the correct and error code line information fusion representation set is obtained by calculating the error code line vector representation set and the correct and error code line attention representation set through a gated recurrent unit.

[0022] Another object of the present application is to provide a programming question error line code type classification system comprising:

[0023] A preprocessing module is configured to preprocess an open source programming question dataset, further classify the dataset according to question IDs, save programming question codes belonging to the same question in the same directory, remove data records missing code files, and obtain a plurality of single question code datasets.

[0024] A pairing module is configured to pair each single question code dataset with error codes and correct codes, obtain a paired dataset, use a code pre-training model to obtain vector representations of each error code and correct code in each single question code dataset, repeatedly calculate semantic similarity between the error code vector and each correct code vector, find a correct code most similar to the error code as its paired reference code, process the codes in lines, convert the codes from text form to array form, each element in the array is a line of code, obtain error line types of the error codes from the original dataset, analyze the dependent inclusion relationship of the error types, obtain an error dependent matrix, and finally obtain a hierarchical label dependent matrix and an error line code comparison and classification dataset, each line of data including an error code line array, a correct reference code line array, an error line error main type label array of the error code, and an error line error sub-type label array of the error code.

[0025] A classification model establishment module is configured to establish a classification model, input each line of code text in the error code line array and the correct reference code line array in each piece of data obtained in S2 into a pre-training model to obtain a code error classification representation set, the code error classification representation set including an error code line vector representation set, a correct reference code line vector representation set, a correct and error code line attention representation set, and a correct and error code line information fusion representation set.

[0026] The classification label calculation module is configured to calculate a classification label, obtain an error position line number and a main error type label through a linear layer from the S3 obtained positive and false code line information fusion representation set, splice the positive and false code line information fusion representation set and the main error type label vector, and obtain a subdivided sub error type after multiplication of the linear layer and a S2 belonging error matrix.

[0027] The loss value calculation module is configured to calculate a loss value, obtain a positioning loss value through a cross entropy loss function from the S4 obtained error position line number and real error line number, obtain a main class loss value through a negative log likelihood loss function from the S4 obtained main error type label and real main error type label, obtain a sub class loss value through a negative log likelihood loss function from the S4 obtained subdivided sub type label and real subdivided sub type label, add the three to obtain a final loss function, and use the loss function to iterate the models in the S3 and the S4 to be optimal to obtain a programming question error line code classification model.

[0028] Another object of the present application is to provide a computer device comprising a memory and a processor, wherein the memory stores a computer program, and the computer program is executed by the processor to make the processor execute the steps of the programming question error line code type classification method.

[0029] Another object of the present application is to provide a computer readable storage medium storing a computer program, and the computer program is executed by a processor to make the processor execute the steps of the programming question error line code type classification method.

[0030] Another object of the present application is to provide an information data processing terminal for realizing the programming question error line code type classification system.

[0031] In combination with the above technical solutions and solved technical problems, the technical solution to be protected by the present application has the following advantages and positive effects:

[0032] Firstly, the programming question error line code type classification method, storage medium and electronic device of the present application extract code vectors through UniXcoder to reduce the complexity of feature engineering, introduce a hierarchical matrix to enhance the error type correlation and improve the prediction accuracy, use an attention mechanism to capture the correlation between the error code and the reference code, and further improve the classification accuracy, thereby enhancing the overall performance of the model.

[0033] Second, the expected benefits and commercial value of the technical solution of the present application are: the technical solution of the present application aims to solve the automation problem of programming problem error classification, 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 significantly improving the intelligent level of programming learning software, reducing learning costs, and having wide commercial promotion prospects in online education, programming training, and programming self-study scenarios.

[0034] The technical solution of the present application overcomes technical bias: by using the UniXcoder unified code pre-training model with stronger expression ability, the method avoids the complex preprocessing steps and graph structure conversion in traditional methods, thereby realizing code error classification in a more concise manner. This way does not rely on graph structure in the reasoning process, providing a more efficient and intuitive error detection scheme, reducing the complexity of data conversion, and is expected to improve the execution efficiency and simplicity of the system. At the same time, the method further optimizes the hierarchical expression of error types using the error membership matrix, making the error classification more accurate and providing effective support for the final classification label. BRIEF DESCRIPTION OF DRAWINGS

[0035] Figure 1 is a flowchart of the programming problem error line code type classification method provided by the embodiment of the present application.

[0036] Figure 2 is a block diagram of the programming problem error line code type classification system structure provided by the embodiment of the present application.

[0037] Figure 3 is a programming problem error line code type classification model structure diagram provided by the embodiment of the present application.

[0038] Figure 4 is an attention distribution diagram of the error code referring to the correct code provided by the embodiment of the present application. DETAILED DESCRIPTION

[0039] In order to make the purpose, technical solution and advantages of the present application clearer and more apparent, the following will further describe the present application in combination with embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and do not limit the present application.

[0040] The following are two specific embodiments of the "programming problem error line code type classification method" of the present application:

[0041] Embodiment 1: Automatic error classification and feedback system in programming education platform

[0042] On a programming education platform, after students submit the code of programming problems, the system automatically detects code errors and provides feedback. Traditional feedback systems can usually only give the result of whether the code runs correctly, and cannot specify the error line number and specific error type. The classification method of the invention can realize the automatic identification of the error line code type, and provide accurate feedback for students.

[0043] 1. Data set preparation: Extract a large number of programming problem instances from an open source programming problem data set, classify them by problem ID, and generate paired data of correct code and student error code.

[0044] 2. Model application: After processing each error code line by line, input the classification model and compare it with the correct code to generate a classification representation set of error lines. According to the output of the model, the system determines the error line number, main error type and sub-error type.

[0045] 3. Feedback generation: The system generates detailed error feedback for students based on the classification results of the model, including error location, error type and suggestions on how to modify, helping students understand and correct errors in the code.

[0046] This system improves the accuracy of error identification on the programming education platform, enabling students to receive effective personalized feedback and helping them improve their programming skills quickly.

[0047] Example 2: Error classification and automatic detection system in code review tool

[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 invention can assist code review tools to automatically locate the line number of code errors and subdivide error types, improving review efficiency.

[0049] 1. Code data preprocessing: Preprocess the submitted code error samples in the project code base to generate paired data of correct code and error code.

[0050] 2. Model application: After processing the error code line by line, input the classification model and compare it with the correct code to generate a classification result containing error line number, main error type and sub-error type.

[0051] 3. Error report generation: The classification result is transmitted to the code review system, which 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 code review efficiency, reduces omissions caused by manual review, and improves the overall quality and development efficiency of the code.

[0053] As shown in Figure 1 The classification method for error line codes of programming questions provided by the embodiment of the present application comprises the following steps:

[0054] S1, preprocessing the open source programming question data set;

[0055] Further classify the data set according to the question ID, save the programming question codes belonging to the same question to the same directory, and remove the data records missing the code file to obtain multiple single question code data sets;

[0056] S2, comparing and pairing the error codes and the correct codes for each single question code data set 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 correct code, repeatedly loop and iteratively calculate the semantic similarity between the error code vector and each correct code vector, and find one of the correct codes most similar to the error code as its paired reference code;

[0057] The code is processed by line, which is converted from the form of a whole text 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; analyze the subordinate inclusion relationship of the above error types to obtain an error subordinate matrix;

[0058] Finally, a hierarchical label subordinate matrix and an error line code comparison and classification data set are obtained, each row of data containing 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 sub-type label array;

[0059] S3, establish a classification model, input each line of code text in the error code line array and the correct reference code line array in each data obtained in S2 into the pre-training model to obtain a code error classification representation set, the code error classification representation set including an error code line vector representation set, a correct reference code line vector representation set, a positive and negative code line attention representation set, and a positive and negative code line information fusion representation set;

[0060] S4, calculate the classification label, the correct code line information fusion set obtained in S3 is passed through a linear layer to obtain the error position line number and the main error type label; the correct code line information fusion set and the main error type label vector obtained above are spliced, and after passing through a linear layer, the error sub-matrix belonging to S2 is multiplied to obtain the subdivided sub-error type;

[0061] S5, calculate the loss value, the error position line number obtained in S4 and the real error line number are passed through a cross-entropy loss function to obtain a positioning loss value; the main error type label obtained in S4 and the real main error type label are passed through a negative log-likelihood loss function to obtain a main class loss value; the subdivided sub-type label obtained in S4 and the real subdivided sub-type label are passed through a negative log-likelihood loss function to obtain a sub-class loss value; the three are added to obtain a final loss function, and the loss function is used to iterate the models in S3 and S4 to the optimal, to obtain a programming question error line code classification model.

[0062] The programming question error line code type classification method of the application processes the programming question data set through a series of steps and establishes a classification model, aiming to accurately classify the types of code error lines, so as to better analyze and locate programming errors. The specific working principle is as follows:

[0063] 1. Data set preprocessing and classification

[0064] Firstly, the open source programming question data set is preprocessed, taking the question ID as the classification basis, and the codes of the same question are stored in the same directory, thereby forming multiple single question code data sets. In this process, data records lacking code files are deleted to ensure the integrity and consistency of the data. The goal of this step is to concentrate subsequent processing on single question codes, facilitating more in-depth analysis of the error types of different question codes.

[0065] 2. Error code pairing and error type analysis

[0066] In each single question code data set, the error code and the correct code are compared and paired. A code pre-training model is used to generate vector representations 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 most similar correct code to the error code is found, which is used as the pairing reference code of the error code. Then, the code is processed by line, converted into an array form, and the main error type and subdivided sub-type of each line of code are extracted, the error type subordination is analyzed, and the error sub-matrix is obtained. This step generates line error labels and subordination matrices, providing necessary input data for the classification model.

[0067] 3. Establishment of classification model and representation generation

[0068] A classification model is established, and the error code in each data is input into the pre-trained model row by row to generate a classification representation set of code errors. The representation set includes error code line vectors, correct code line vectors, attention representations of positive and negative code lines, and line representations that fuse positive and negative 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 positive and negative codes.

[0069] 4. Calculation of main and sub-error type labels

[0070] Based on the generated representations, the positive and negative code line information fusion representation set is processed through a linear layer to obtain the error position line number and the main error type label. Meanwhile, the generated main error type label vector is spliced with the positive and negative code line information fusion representation set, which is further processed through a linear layer and multiplied by an error dependent matrix to obtain a more refined sub-error type label. In this way, the model realizes hierarchical prediction of error types, thereby making the error classification more hierarchical and accurate.

[0071] 5. Loss value 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 line number and the true line number to obtain the positioning loss value; second, 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 sum of the three is the comprehensive loss value, which is used as the final loss function to guide the training process of the model.

[0073] 6. Iterative optimization of the classification model

[0074] Through the calculation and feedback of the loss function, the model is continuously iteratively optimized during the training process, adjusting the model parameters so that the loss function gradually decreases and eventually reaches the optimal. After sufficient training, the model can efficiently identify the position of the error line, the main error type, and the sub-type label. In this way, the final 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 application includes correct code and error code.

[0076] The error code line vector representation set and the correct reference code line vector representation set are obtained by representing each line of code in the correct code line array and the error code line array by a code pre-training model, the correct code line attention representation set is obtained by scaling the dot product attention mechanism from the error code line vector representation set and the correct reference code line vector representation set, and the correct code line information fusion representation set is obtained by calculating the error code line vector representation set and the correct code line attention representation set through a gated recurrent unit.

[0077] As shown in Figure 2 , the programming question error line code type classification system provided by the embodiment of the application comprises:

[0078] A preprocessing module is configured to preprocess an open source programming question data set, further classify the data set according to question IDs, save the programming question codes belonging to the same question to the same directory, remove the data records missing the code files, and obtain a plurality of single question code data sets.

[0079] A pairing module is configured to pair the error code and the correct code in each single question code data set to obtain a paired data set, obtain the vector representation of each error code and correct code by using a code pre-training model in each single question code data set, repeatedly and circularly calculate the semantic similarity between the error code vector and each correct code vector, find one correct code most similar to the error code as the paired reference code of the error code, process the code by lines, convert the code from the form of a whole text to the form of an array, and each element in the array is a line of code, obtain the error type of the error code by lines from the original data set, analyze the subordinate inclusion relationship of the error types, obtain an error subordinate matrix, and finally obtain a hierarchical label subordinate matrix and an error line code comparison and classification data set, wherein each line of data comprises an error code line array, a correct reference code line array, an error main type label array of the error code by lines, and an error sub-type label array of the error code by lines.

[0080] A classification model establishing module is configured to establish a classification model, input each line of code text in the error code line array and the correct reference code line array in each piece of data obtained in S2 into a pre-training model to obtain a code error classification representation set, and the code error classification representation set comprises an error code line vector representation set, a correct reference code line vector representation set, a correct code line attention representation set, and a correct code line information fusion representation set.

[0081] A classification label calculation module is configured to calculate a classification label, obtain an error position line number and a main error type label through a linear layer from the S3 obtained correct / incorrect code split line information fusion representation set, splice the correct / incorrect code split line information fusion representation set and the main error type label vector obtained above, and obtain a subdivided sub-error type after multiplication by an error belonging matrix to which S2 belongs through a linear layer.

[0082] A loss value calculation module is configured to calculate a loss value, obtain a positioning loss value through a cross-entropy loss function from the S4 obtained error position line number and real error line number, obtain a main class loss value through a negative log-likelihood loss function from the S4 obtained main error type label and real main error type label, obtain a sub-class loss value through a negative log-likelihood loss function from the S4 obtained subdivided sub-type label and real subdivided sub-type label, add the three to obtain a final loss function, and use the loss function to iteratively optimize the models in S3 and S4 to obtain a programming question error line code classification model.

[0083] Another object of the present application is to provide a computer device comprising a memory and a processor, wherein the memory stores a computer program, and the computer program is executed by the processor to enable the processor to perform the steps of the programming question error line code type classification method.

[0084] Another object of the present application is to provide a computer readable storage medium storing a computer program, and the computer program is executed by a processor to enable the processor to perform the steps of the programming question error line code type classification method.

[0085] Another object of the present application is to provide an information data processing terminal for implementing the programming question error line code type classification system.

[0086] Embodiment 3

[0087] The embodiment discloses a programming question error line code type classification method, comprising the following steps:

[0088] S1, preprocessing an open source programming question data set. The data set is further classified according to the question ID as a classification basis, so that the programming question codes (including correct codes and error codes) belonging to the same question are saved in the same directory, and data records missing code files are removed to obtain a plurality of single question code data sets.

[0089] Each data in the open source programming question code dataset selected by the embodiment includes code text, whether it is wrong, main error type, sub error type, error code line number, and belongs to programming question ID. For S1 data preprocessing, first, all missing code file records in the dataset are cleared to ensure the integrity and accuracy of the data. All unique programming question IDs are extracted from the cleaned dataset as the basis for subsequent classification. For each extracted programming question ID, all original data lines associated with it are collected. The data lines belonging to each programming question are packaged, including code text, whether it is wrong, main error type, sub error type, error code line number, and belongs to programming question ID, as the data source for subsequent step S2.

[0090] S2, for each single question code dataset, compare the error code with the correct code to obtain the paired dataset. In each single question code dataset, use the code pre-training model to obtain the vector representation of each error code and correct code, repeatedly loop to calculate the semantic similarity between the error code vector and each correct code vector, and find the one most similar to the correct code corresponding to the error code as its paired reference code.

[0091] The specific process is: for each individual programming question code dataset, for each correct code text c n in the correct code text set C = {c1, c2, …, c i , respectively through the UniXcoder code pre-training model to obtain the correct code representation set is represented as:

[0092]

[0093] Then, for each error code text e m in the error code text set E = {e1, e2, …, e i , through the UniXcoder model to obtain its vector representation Calculate the cosine similarity with all correct code representations in H c , and select the correct code with the highest similarity as the reference code r i of the error code, obtain the reference code text set R = {r1, r2, r3, …, r n}. This process can be represented as:

[0094] r i = c j

[0095]

[0096] Wherein, j is the correct code sequence number selected as the reference code, k represents all correct code sequence number marks in the programming question data set, and the cosine similarity calculation formula is:

[0097]

[0098] In this formula, is the vector representation of the error code e i , is the vector representation of the correct code c k .

[0099] The code is processed by row, which is converted from the whole text form to the array form, and the array content is a line of code. The row 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 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}, each error code text e1 and its reference code text r1 are divided into code line array E lines , R lines :

[0101]

[0102] Wherein, e ij represents the jth line code in the error code e i , r ij represents the jth line code in the reference code r i , and respectively represent the row code array of e i , r i . For each line of error code, if the line contains errors, record its main error type and sub-error type. Define the main error type label array and the sub-error type label array as follows:

[0103]

[0104] Wherein, represents the main error type of the jth line in the error code e i , represents the sub-error type of the jth line in the error code e i . Statistical analysis shows that there are 4 main error types, so Value is 0 to 4, 0 means no error; there are 16 sub-error types, so Value is 0 to 16, 0 means no error. At the same time, the two types of error labels have a dependent relationship, that is, the sub-error type is a certain main error type, then define the dependent matrix Where M ij represents the specific value of the i-th row and j-th column in M:

[0105]

[0106] Finally, the hierarchical label dependent matrix and error line code comparison classification data set are obtained, each row of data contains error code line array, correct reference code line array, error code error line number array, and error code error type array.

[0107] S3, establish a classification model, input each line of code text in the error code line array and correct reference code line array in each data obtained in S2 into the pre-trained model, obtain the code error classification representation set, the code error classification representation set includes error code line vector representation set, correct reference code line vector representation set, positive and negative code line attention representation set, and positive and negative code line information fusion representation set.

[0108] The error code line vector representation set and the correct reference code line vector representation set are obtained by representing each line of code in the correct and error line code array by the code pre-training model, the positive and negative code line attention representation set is obtained by scaling the dot product attention mechanism from the error code line vector representation set and the correct reference code line vector representation set, and the positive and negative code line information fusion representation set is obtained by calculating the error code line vector representation set and the positive and negative code line attention representation set through the gated recurrent unit.

[0109] The specific process is: for each row of data obtained, the error code line array and the reference code line array in each line of code e ij , r ij is identified by using UniXcoder pre-training model, and the line-level vector representation of error code and reference code is obtained

[0110]

[0111] Wherein is the representation vector of the j-th line of code in the error code e i represented by the UniXcoder model, is the representation vector of the j-th line of code in the reference code r i represented by the UniXcoder model.

[0112] Compute error code using scaled dot-product attention mechanism and line-level vector representation of reference code Attention vector A atte , which embodies the reference attention relationship between the error code and the reference code, reflects the correlation between each line of the error code and all lines of the reference code. The specific formula is:

[0113]

[0114] Where Q is the attention mechanism query matrix, K is the attention mechanism key vector, V is the attention mechanism value matrix, d k is the dimension of K, which avoids the gradient instability that may be caused by large dot products.

[0115] Next, the obtained attention vector A atte is fused with the error code line vector representation set to obtain the information fusion representation set This is achieved through a gated recurrent unit (GRU):

[0116]

[0117] Through the gated recurrent unit, emphasizing the error code representation while integrating the attention relationship between the error code and the reference code.

[0118] S4, calculate the classification label, the positive and negative code line information fusion representation set obtained in S3 is passed through a linear layer to obtain the error location line number and the main error type label; the positive and negative code line information fusion representation set and the main error type label vector obtained above are spliced, and then passed through a linear layer and multiplied by the error belonging matrix of S2 to obtain the sub-error type.

[0119] The specific process is as follows:

[0120] The positive and negative code line information fusion representation set is passed through a linear layer and a softmax activation function to calculate the probability of each main error label for each line of code

[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 To improve the prediction accuracy, the correct / incorrect code line information is first fused into a set of representation With splicing, a hybrid representation is obtained After passing through another linear layer, the original output of the sub-error type is obtained

[0124]

[0125] where W sub and b sub are the weight matrix and bias term of the linear transformation, respectively.

[0126] The value of the main error type probability in is taken out, that is, the main error type predicted by the code line is obtained, which can be corresponded to a row of the dependent matrix M through the index value , representing the sub-error type owned by the main error type, and the original output of the sub-error type of the row is multiplied element by element, that is, part of the impossible prediction results can be filtered out, and finally the more accurate sub-error type label probability distribution is obtained through the softmax function The above process can be represented as:

[0127]

[0128] S5, calculate the loss value, obtain the positioning loss value of the error position line number and the real error line number through the cross-entropy loss function; obtain the main error type label and the real main error type label through the negative log-likelihood loss function; obtain the sub-class loss value of the sub-class label and the real sub-class label through the negative log-likelihood loss function; add the three to obtain 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 to obtain the real label of the error position line number. Among them, for if the value is not 0, it indicates that the code line is an error code, and thus the real label of the error position

[0130]

[0131]

[0132] The predicted error line number is calculated through the main error type prediction value , and ​​The prediction value of each line of code is obtained by summing the probability values of all classes other than the non-zero class (i.e. the correct class)

[0133]

[0134] wherein is The prediction value of the main error type of each line, c represents the label class index, and Pnum represents the total number of main error types.

[0135] For each The cross-entropy loss is calculated to obtain the positioning loss value L loc :

[0136]

[0137] wherein n represents the total number of training set data, i.e. the total number of error codes, and m is the number of code lines of each error code.

[0138] For each The negative log-likelihood loss is calculated to obtain the main type loss value L pri :

[0139]

[0140] wherein is the true label of the main error of each line of the error code e i is the predicted main error probability distribution of each line of the error code e i

[0141] For each The negative log-likelihood loss is calculated to obtain the main type loss value L sub :

[0142]

[0143] wherein is the true label of the main error of each line of the error code e i is the predicted main error probability distribution of each line of the error code e i

[0144] The above three losses are weighted and added to obtain the total loss function L of the entire model total :

[0145] L total = αL loc + βL pri + γL sub ​​​​

[0146] where a, b, g are hyperparameter weights of the losses, controlling the relative importance of each loss in the total loss.

[0147] Using the loss function, the model in S3 and S4 is iterated to optimal, and the programming question error line code classification model is obtained.

[0148] Embodiment 4

[0149] The embodiment discloses an electronic device, comprising: a memory for storing executable instructions; a processor for executing the executable instructions stored in the memory to implement the programming question error line code type classification method disclosed in embodiment 1.

[0150] Embodiment 5

[0151] The embodiment discloses a computer readable storage medium, which stores executable instructions for causing a processor to execute the executable instructions to implement the programming question error line code type classification method disclosed in embodiment 1.

[0152] The storage medium can be a computer readable storage medium, such as a ferroelectric memory (FRAM, Ferromagnetic Random Access Memory), a read-only memory (ROM, Read Only Memory), a programmable read-only memory (PROM, Programmable Read Only Memory), an erasable programmable read-only memory (EPROM, Erasable Programmable Read Only Memory), an electrically erasable programmable read-only memory (EEPROM, Electrically Erasable Programmable Read Only Memory), a flash memory, a magnetic surface memory, an optical disc, or a compact disc read-only memory (CD-ROM, Compact Disk-Read Only Memory) and the like. It can also be various devices including one or any combination of the above memories.

[0153] In one embodiment, the executable instructions can be in the form of a program, software, software module, script or code, written in any form of programming language, including a compiled or interpreted language, or a declarative or procedural language, and can be deployed in any form, including being deployed as a stand-alone program or being deployed as a module, component, subroutine, or other unit suitable for use in a computing environment.

[0154] As an example, executable instructions may, but do not necessarily, correspond to files in a file system. They may be stored as part of a file containing other programs or data, for example, in one or more scripts within a Hyper Text Markup Language (HTML) document, in a single file dedicated to the program in question, or in multiple co-located files (e.g., files storing one or more modules, subroutines, or code sections). As an example, executable instructions may be deployed to execute on a single electronic device, or on multiple electronic devices located in one location, or on multiple electronic devices distributed across multiple locations and interconnected via a communication network.

[0155] In the embodiments provided in this application, it should be understood that the disclosed apparatus and methods can also be implemented in other ways. The apparatus embodiments described above are merely illustrative. For example, the flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of apparatus, methods, and computer program products according to various embodiments of this application. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of code containing one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions marked in the blocks may occur in a different order than those marked in the drawings. For example, two consecutive blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in a block diagram and / or flowchart, and combinations of blocks in block diagrams and / or flowcharts, can be implemented using a dedicated hardware-based system that performs the specified function or action, or using a combination of dedicated hardware and computer instructions.

[0156] In addition, the functional modules in the various embodiments of this application can be integrated together to form an independent part, or each module can exist independently, or two or more modules can 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 solutions of the present application essentially or the parts that contribute to the prior art or parts of the technical solutions can be embodied in the form of a software product, which is stored in a storage medium and includes a plurality of instructions for causing a computer device (which can be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present application. The aforementioned storage medium includes: a U disk, a mobile hard disk, a read-only memory (ROM, Read-Only Memory), a random access memory (RAM, Random Access Memory), a magnetic disk or an optical disk, and various media that can store program codes.

[0158] The present application 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 the programming beginners submit the code, the error classification module of the present application can automatically identify and classify the code errors, and return the analysis results directly to the students, so that they can accurately understand the source and nature of the errors. This scheme can significantly improve the efficiency of code error positioning, and will effectively reduce the frustration of learners when they first learn programming, thereby enabling them to more efficiently master the basic knowledge of programming.

[0159] Further, the present application can be combined with a large model retrieval enhancement process to provide more targeted programming learning feedback by constructing a typical error question bank or a similar problem retrieval mechanism. When the system detects a specific type of error, it will retrieve similar cases from the large model error question bank, generate detailed explanations and improvement suggestions, and help learners better understand the error logic and make self-corrections. This system will effectively improve the accuracy and intelligent feedback reliability of programming learning, and optimize the overall process of programming learning, providing stable and reliable technical support for programming learning of beginners.

[0160] To verify the effectiveness of the present method in improving error classification, a classification model without the aforementioned attention mechanism and dependent matrix filtering operation is used to benchmark the data set, and the weighted precision, weighted recall and weighted F1 value are calculated as evaluation indicators, with accuracy as the main standard. The specific method is as follows:

[0161] UniXcoder classification model: the error line code and the correct reference line code in the data set are input into UniXcoder to obtain code representation vectors, and the two are spliced and input into a linear classification layer to predict the label of the output representation vector.

[0162] The results are shown in Tables 1 and 2. From the experimental results, it can be seen that the method proposed in this paper has achieved leading results in various indicators. The accuracy and F1 value are two total measurement indicators, and the method in this paper far exceeds the baseline model. In the third row of the two tables, the error type from the dependency matrix is removed for ablation experiment. This experiment shows that the introduction of the dependency matrix information effectively improves the classification ability of the model for the sub-error type of the error code line, and also improves the classification ability for the main error type. By comparing the third row and the first row, it can be seen that the use of the line-level true and false code vector cross-attention mechanism greatly improves the classification ability of the baseline model for this task.

[0163] Table 1 Experimental benchmark main error type experimental results

[0164]

[0165] Table 2 Experimental benchmark sub-error type experimental results

[0166]

[0167] It should be noted that the embodiments of the present application can be realized by hardware, software or a combination of software and hardware. The hardware part can be realized by special logic; the software part can be stored in a memory and executed by a suitable instruction execution system, such as a microprocessor or a specially designed hardware. Those skilled in the art can understand that the above-mentioned devices and methods can be realized by computer executable instructions and / or included in processor control code, such as provided on a carrier medium, such as a magnetic 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. The devices of the present application and their modules can be realized 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 realized by software executed by various types of processors, and can also be realized by a combination of the above-mentioned hardware circuits and software, such as firmware.

[0168] The above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto, and any modification, equivalent replacement and improvement made by those skilled in the art within the technical scope disclosed by the present application shall be covered within the protection scope of the present application.

Claims

1. A method for classifying error line code types in programming problems, characterized in that, Includes the following steps: S1, preprocessing the open-source programming problem dataset; The dataset is further categorized based on the question ID, so that programming codes belonging to the same question are saved in the same directory. At the same time, data records with missing code files are removed, resulting in multiple single question code datasets. S2, for each of the above single question code datasets, compare and match the incorrect codes with the correct codes to obtain the matching dataset; In each single question code dataset, a code pre-trained 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 repeatedly calculated in a loop. The correct code that is most similar to the error code is found as its paired reference code. The code is processed into line breaks, converting it from a whole text into an array, with each element of the array being a line of code; the line error types of the error codes are obtained from the original dataset, with each line of error code having a main error type and a corresponding sub-error type; Analyze the dependency relationships of the above error types to obtain the error dependency matrix; The final result is a hierarchical label subordination matrix and an error line code comparison classification dataset. Each row of data contains an array of error code rows, an array of correct reference code rows, an array of error code main type labels, and an array of error code subtype labels. S3, establish a classification model. Input the error code line array and the correct reference code line array of each data point obtained in S2 into the pre-trained model to obtain a code error classification representation set. 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, calculate the classification label. The fusion representation set of the correct and incorrect code line information obtained in S3 is passed through a linear layer to obtain the line number of the error location and the main error type label. The fusion representation set of the correct and incorrect code line information and the main error type label vector obtained above are concatenated, passed through a linear layer and multiplied by the error sub-matrix to which S2 belongs to obtain the subdivided sub-error types. S5, calculate the loss value. The error location row number obtained in S4 and the actual error row number are used to obtain the localization loss value through the cross-entropy loss function; the main error type label obtained in S4 and the actual main error type label are used to obtain the main class loss value through the negative log-likelihood loss function; the sub-subtype label obtained in S4 and the actual sub-subtype label are used to obtain the sub-subtype loss value through the negative log-likelihood loss function. 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 until the optimal result is obtained, thus obtaining the programming error line code classification model.

2. The method for classifying error line code types in programming problems as described in claim 1, characterized in that, The programming problem code includes both correct and incorrect codes.

3. The method for classifying programming error line code types as described in claim 1, characterized in that, The error code line vector representation set and the correct reference code line vector representation set are obtained by representing each line of code in the correct and error line code arrays using a code pre-trained model. The correct and incorrect code line attention representation set is obtained by scaling dot product attention mechanism from the error code line vector representation set and the correct reference code line vector representation set. The correct and incorrect code line information fusion representation set is obtained by calculating the error code line vector representation set and the correct and incorrect code attention representation set through a gated recurrent unit.

4. A classification system for programming error line code types that implements the classification method for programming error line code types as described in any one of claims 1-3, characterized in that, The classification system for error line code types in programming problems includes: The preprocessing module is used to preprocess the open-source programming problem dataset; it further classifies the dataset based on the problem ID, so that the programming problem codes belonging to the same problem are saved in the same directory, and removes data records with missing code files, resulting in multiple single problem code datasets; The pairing module is used to compare and pair incorrect codes with correct codes for each individual question code dataset to obtain a pairing dataset. Within each individual question code dataset, a code pre-trained model is used to obtain vector representations of each incorrect and correct code. The semantic similarity between the incorrect code vector and each correct code vector is repeatedly calculated iteratively to find the most similar correct code as its pairing reference code. The code is then processed into line segments, transforming it from a single text segment into an array where each element represents a line of code. The line-by-line error types of the incorrect codes are obtained from the original dataset. Each line of incorrect code has a main error type and corresponding further subdivided sub-error types. The subordinate relationships of these error types are analyzed to obtain an error subordinate matrix. Finally, a hierarchical label subordinate matrix and an error line code comparison and classification dataset are obtained. Each row of data contains an array of incorrect code lines, an array of correct reference code lines, an array of main error type labels for the incorrect code lines, and an array of sub-error type labels for the incorrect code lines. The classification model building module is used to build a classification model. It inputs the error code line array and the correct reference code line array of each data obtained in S2 into the pre-trained model to obtain a code error classification representation set. 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 build and calculate classification labels. It takes the correct and incorrect code line information fusion representation set obtained by S3 and passes it through a linear layer to obtain the error position line number and the main error type label. It concatenates the correct and incorrect code line information fusion representation set and the main error type label vector obtained above, passes it through a linear layer and multiplies it by the error belonging matrix of S2 to obtain the subdivided sub-error types. The loss calculation module is used to establish and calculate the loss value. It obtains the localization loss value by applying the cross-entropy loss function to the error location line number obtained in S4 and the true error line number; it obtains the main class loss value by applying the negative log-likelihood loss function to the main error type label obtained in S4 and the true main error type label; and it obtains the subclass loss value by applying the negative log-likelihood loss function to the sub-subtype label obtained in S4 and the true sub-subtype label. The three are added together to obtain the final loss function, and this loss function is used to iterate the models in S3 and S4 until optimal, resulting in a programming error line code classification model.

5. A computer device, characterized in that, The computer device includes a memory and a processor. The memory stores a computer program, which, when executed by the processor, causes the processor to perform the steps of the classification method for programming error line code types as described in any one of claims 1-3.

6. A computer-readable storage medium storing a computer program, which, when executed by a processor, causes the processor to perform the steps of the classification method for programming error line code types as described in any one of claims 1-3.

7. An information data processing terminal, characterized in that, The information data processing terminal is used to implement the classification system for programming 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

  • Code text information-containing repeated post labeling method, storage medium and electronic equipment

    CN118246458A