Intelligent code completion method under programming education scene

By expanding the data set and combining the recommended list of students' learning scenarios to optimize the code completion model, the problem of insufficient data sets and lack of scenario adaptation in the field of programming education is solved, and higher-quality code completion suggestions are achieved.

CN119556901AActive Publication Date: 2025-03-04ARTIFICIAL INTELLIGENCE RES INST OF HEFEI COMPREHENSIVE NAT SCI CENT (ANHUI ARTIFICIAL INTELLIGENCE LAB)
View PDF 9 Cites 0 Cited by

Patent Information

Application Number
CN202510117050.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-01-24
Publication Date
2025-03-04
Estimated Expiration
2045-01-24

AI Technical Summary

Technical Problem

The existing intelligent code completion method has problems such as insufficient training data sets and lack of scenario adaptation in the field of programming education, which leads to the generated code suggestions that do not match students' learning needs and cannot effectively guide students to complete targeted training tasks.

Method used

By presetting the universal large language model of programming learner identity, we simulate the answer codes of students of different styles, expand the data set, and combine the students' answer codes and learning scenarios to optimize the code completion model's recommendation list to generate the final recommendation list.

Benefits of technology

It effectively solves the problem that general data sets are difficult to adapt to students' programming learning needs, improves the quality of recommendations in programming education scenarios, and makes code completion suggestions more in line with students' learning needs.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119556901A_ABST
    Figure CN119556901A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of code completion, and discloses an intelligent code completion method under a programming education scene, which comprises the following steps: simulating answering codes of different styles of students through a general large language model in which programming learner identities are preset; each symbol of an answer code in the extended data set is coded, an obtained coding sequence is input into the large language model, the large language model predicts the next symbol of the coding sequence according to the previous part of the coding sequence, the prediction precision of the large language model is optimized by minimizing cross entropy loss, and a complementation model is obtained; and inputting answer codes of the students into the completion model which completes training to obtain an initial recommendation list, selecting three symbols which are most related to the scene information in the initial list, and increasing the order of the three symbols in the initial recommendation list to generate a final recommendation list. According to the method, the recommendation list is optimized by means of the scene information, and the recommendation quality under the programming education scene can be effectively improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of code completion, and in particular to an intelligent code completion method in a programming education scenario. Background Art

[0002] As one of the core functions in the integrated development environment, code completion is crucial for students' programming learning. First of all, code completion can provide real-time suggestions for commonly used syntax, function and variable names, which can help students quickly become familiar with the rules and standard writing of programming languages ​​and lower the learning threshold. Secondly, it can effectively reduce students' spelling and grammatical errors, help students focus on logical design and problem solving, and avoid the frustration caused by low-level errors. In addition, code completion also provides students with opportunities for exploration. By viewing the automatic prompt content, students can gradually understand more functions and features of programming languages. Finally, code completion can directly enhance students' programming experience, allowing students to feel the fluency and creativity of programming, thereby enhancing their interest in learning and sense of achievement.

[0003] Compared with the traditional rule-based code completion method, the intelligent code completion method can understand the code content and provide more accurate, efficient and intelligent completion suggestions. Therefore, the intelligent code completion method is the mainstream method for implementing code completion. Relying on the deep learning model, it understands the context and semantics of the code by learning a large amount of code data, and then generates real-time code suggestions for users.

[0004] However, directly applying the current mainstream intelligent code completion to the field of programming education has the following problems: (1) Insufficient training data sets. The current training data of intelligent code completion models mainly comes from professional codes on GitHub. Although it is instructive for efficient programming, it is insufficient for programming education. First, the model often assumes that the user has a certain programming background, and the generated suggestions may be too complex and not suitable for beginners to understand and learn. Second, the model tends to optimize code efficiency and professional standards rather than teaching friendliness, and may ignore the explanation of basic knowledge and guidance on common problems for novices. Finally, the professional code style may not be completely consistent with the educational goals, which can easily lead students into imitation misunderstandings and affect the cultivation of programming thinking and logical abilities.

[0005] (2) Lack of scenario adaptation. Compared with programmers who focus on solving practical engineering problems and improving development efficiency, in the field of programming education, students need to focus on specific questions and knowledge points for programming training to cultivate basic programming skills and logical thinking ability. However, current intelligent code completion methods usually aim to improve versatility and code generation efficiency, lack deep adaptation to students' learning scenarios, and thus find it difficult to effectively provide completion suggestions.

[0006] The existing technical solutions, when facing the special scenario of programming education, often use general intelligent code completion methods, resulting in the generated code suggestions not matching students' learning needs and failing to effectively guide students to complete targeted training tasks. How to effectively make up for the shortcomings of general data sets and effectively combine student programming practice scenarios to provide an intelligent code completion method suitable for the field of programming education is still a challenging task. Summary of the invention

[0007] In order to solve the above technical problems, the present invention provides an intelligent code completion method in a programming education scenario.

[0008] In order to solve the above technical problems, the present invention adopts the following technical solutions: An intelligent code completion method in a programming education scenario, comprising: Through the universal large language model with the identity of programming learners preset, the answer codes of students with different styles are simulated to obtain an expanded data set; Encode each symbol of the answer code in the expanded data set, input the obtained encoding sequence into the large language model, and the large language model predicts the next symbol of the encoding sequence based on the previous encoding sequence, and evaluates the difference between the probability distribution of the predicted symbol and the probability distribution of the target symbol by calculating the cross entropy loss; optimize the prediction accuracy of the large language model by minimizing the cross entropy loss to obtain the completion model; Input the student's answer code into the completed training model to obtain the initial recommendation list, combine the current knowledge points and question information to form scenario information, and select the most relevant ones in the initial list. symbols and promote the selected The ranking of symbols is used to generate the final recommendation list.

[0009] Furthermore, the symbol is the smallest unit for compiling and running the answer code.

[0010] Furthermore, the general large language model with the programming learner identity preset is used to simulate the answer codes of students with different styles to obtain an expanded data set, which specifically includes: Provide multiple knowledge points for a certain programming language for students to learn, and provide multiple questions for each knowledge point for students to practice programming; during the programming practice, record the students' answer codes and answer results, and set standard answers for each question; For each question under each knowledge point of the programming language, a piece of answer code with a passing answer result is selected, and sent into a general large language model together with the corresponding knowledge point, question, and standard answer, and the identity of the programming learner is set for the large language model to let the large language model simulate the answer codes of students with different styles; the answer code output by the large language model is randomly inserted into the general data set to obtain an expanded data set.

[0011] Furthermore, the large language model predicts the next symbol of the coding sequence according to the previous context of the coding sequence, and evaluates the difference between the probability distribution of the predicted symbol and the probability distribution of the target symbol by calculating the cross entropy loss; the prediction accuracy of the large language model is optimized by minimizing the cross entropy loss to obtain a completion model, which specifically includes: Large language models by encoding sequences The first t symbols of To predict the t+1th symbol The probability distribution of ; Use cross entropy loss to calculate the error between the symbol probability distribution predicted by the large language model and the target symbol probability distribution. By minimizing the cross entropy loss, the symbol probability distribution predicted by the large language model is close to the target symbol probability distribution.

[0012] Furthermore, the cross entropy loss for: ; is the tth symbol in the target symbol sequence; When the cross entropy loss converges, the training of the large language model is completed and the completion model is obtained.

[0013] Furthermore, the student's answer code is input into the completed training model to obtain an initial recommendation list, and the scenario information is formed by combining the current knowledge point and the question information, which specifically includes: When students practice questions under the knowledge point knowledge, the students' answer codes are input into the trained completion model in real time, and the probability of each symbol in the vocabulary appearing in the next position of the answer code is calculated, and the top symbol with the highest probability is retained. symbols, forming the initial recommendation list , is the Kth symbol in the initial recommendation list; Combine the knowledge points with the questions to get the scene information scene: ; Represents a concatenation operation.

[0014] Furthermore, the selection of the most relevant scene information in the initial list symbols and promote the selected The ranking of the symbols is used to generate the final recommendation list, which includes: Use BERT encoder to encode scene information into scene information vector ; Use the BERT encoder to encode each symbol in the initial recommendation list into a symbol vector to obtain the recommendation list vector , is the total number of symbols in the initial recommendation list; calculate the recommendation list vector The kth symbol vector in With scene information vector Similarity , ; The highest The rank of the symbol corresponding to the similarity is increased by at least one place to obtain the final recommendation list.

[0015] Furthermore, the calculation of the recommendation list vector The kth symbol vector in With scene information vector Similarity , specifically including: ; in, An operation to find the length of a vector.

[0016] Furthermore, the highest The rank of the symbol corresponding to the similarity is increased by at least one, specifically including: If the rank of a symbol is the first, the rank of the symbol will not be increased.

[0017] Compared with the prior art, the beneficial technical effects of the present invention are: The present invention uses programming education platform data and a general large language model to expand the general code completion data set, effectively solving the problem that the original data set is difficult to adapt to students' programming learning needs. In addition, the present invention uses scenario information to optimize the recommendation list, which can effectively improve the quality of recommendations in programming education scenarios. BRIEF DESCRIPTION OF THE DRAWINGS

[0018] Figure 1 4 is a flow chart of a method in an embodiment of the present invention. DETAILED DESCRIPTION

[0019] A preferred embodiment of the present invention is described in detail below with reference to the accompanying drawings.

[0020] This embodiment provides an intelligent code completion method in a programming education scenario. First, with the help of a programming education platform and a general large language model, a general data set is expanded. Secondly, the large language model is trained using the expanded data set to obtain a completion model. Finally, in combination with the student programming scenario, the recommendation list of the code completion model is optimized. In a preferred embodiment, the large language model can select the GPT-2 model.

[0021] like Figure 1 As shown, the intelligent code completion method in the programming education scenario in this embodiment includes the following steps: S1, data set construction: With the help of programming education platform data and general large language model, answer code data is generated to expand the general data set.

[0022] S2, model training: Use the expanded data set to train the GPT-2 model and obtain the completed model.

[0023] S3, post-processing of recommendation list: Input the student's existing answer code into the completed training model to obtain the initial recommendation list. Combine the student's programming knowledge points and questions, post-process the recommendation list, obtain the final recommendation list, and feedback it to the student.

[0024] Furthermore, step S1 specifically includes: Taking Python programming language as an example, the programming education platform will provide multiple knowledge points for Python for students to learn. After selecting a certain knowledge point, the programming education platform will provide a variety of questions for students to practice programming. In this process, the programming education platform will record the students' answer codes and answer results. In addition, the programming education platform will set standard answers for each question. In a preferred embodiment, there are two types of answer results, namely pass and fail.

[0025] For all questions under all knowledge points of the Python programming language, select a code with a passing answer result. Send the knowledge points, question stem, standard answer and a passing answer code for this question into the conversational general large language model, and let the general large language model simulate the answer codes of students with different styles. In a preferred embodiment, the general large language model can select chatgpt, spark model, and Wenxinyiyan. In this process, in order to improve the accuracy of the general large language model's answers, the identity of the general large language model is set to a programming learner. The prompt word prompt constructed based on knowledge points, questions, standard answers and answer codes is: ; Among them, smooth means to use smooth sentences to splice related information, identity means to set the identity for the general large language model, K means the knowledge point, Q means the question, A means the standard answer, and S means the answer result is the passing answer code. In a preferred embodiment, the prompt word prompt is as follows: prompt = "You are a student who is learning Python. In order to learn the knowledge point [" + K + "], you are doing programming exercises on the question [" + Q + "]. The standard answer to this question is [" + A + "], and the answer code that passed the test is [" + S+ "]. Now, please combine the above information and simulate three different styles of student answer codes for me. These three styles are beginner style, experimenter style and simple style. Please note that the three simulated student answer codes are only different in style, but they are all correct codes that can achieve the requirements of the question. Please return the experimental results to me in the form of a set, and no additional description other than the set is required."

[0026] In a preferred embodiment, the general dataset used for Python code completion training is the Py150 dataset, which consists of 150k Python codes and can be directly obtained. For each programming question, three simulated student answer codes can be obtained with the help of a conversational general large language model. These codes are randomly inserted into the general dataset to obtain the extended dataset DataSet.

[0027] Furthermore, step S2 specifically includes: Use the BERT encoder to encode each token of the answer code in the augmented dataset DataSet, and use the encoded sequence for training the GPT-2 model. A token is the smallest unit for source code compilation and operation.

[0028] Given a coding sequence , GPT-2 predicts the t+1th symbol from the first t symbols The probability distribution of For each symbol in the input coding sequence, the GPT-2 model predicts the probability distribution of the symbol at that position. The GPT-2 model uses cross entropy loss to calculate the error between the predicted symbol probability distribution and the target symbol probability distribution. By minimizing the cross entropy loss, the predicted symbol probability distribution is closer to the target symbol probability distribution, thereby improving the prediction accuracy. Assume that the target symbol sequence is , then the cross entropy loss for: ; When the training loss gradually approaches a smaller value and no longer decreases significantly, it means that the large language model has fully learned the patterns in the training data. You can stop training the large language model and obtain the completed model.

[0029] Furthermore, step S3 specifically includes: When students practice questions under the knowledge point, the answer code they have written will be input into the completion model. The completion model will calculate the probability of each symbol in the vocabulary and retain the top ten recommendations with the highest probability to form the initial recommendation list. , It is the 10th symbol in the initial recommendation list.

[0030] By combining the knowledge point information with the question information, we can get the scene information scene: .

[0031] Use the BERT encoder to encode the scene information from the string into a vector form to obtain the scene information vector For each symbol in the initial recommendation list, use the BERT encoder to encode it into a symbol vector in the same way to obtain the recommendation list vector For the kth symbol vector in the recommendation list vector (k=1,2,…,10), calculate its vector with the scene information Similarity: ; in, represents the inner product of these two vectors, and Represents the lengths of two vectors.

[0032] Select the three symbols in the recommendation list that are most similar to the scene information. Then, move the ranking of these three symbols up by one (if a symbol is ranked first, it will not be moved up), and obtain the final recommendation list for students to choose from. For example, the initial recommendation list is ,if is most relevant to the scene information, the final recommendation list is .

[0033] It is obvious to those skilled in the art that the present invention is not limited to the details of the exemplary embodiments described above, and that the present invention can be implemented in other specific forms without departing from the spirit or essential features of the present invention. Therefore, from any point of view, the embodiments should be regarded as exemplary and non-limiting, and the scope of the present invention is defined by the appended claims rather than the above description, and it is intended that all changes falling within the meaning and scope of the equivalent elements of the claims are included in the present invention, and any reference numerals in the claims should not be regarded as limiting the claims involved.

[0034] In addition, it should be understood that although this specification is described in terms of implementation methods, not every implementation method contains only one independent technical solution. This narrative method of the specification is only for the sake of clarity. Those skilled in the art should regard the specification as a whole. The technical solutions in each embodiment may also be appropriately combined to form other implementation methods that can be understood by those skilled in the art.

Claims

1. An intelligent code completion method in a programming education scenario, characterized in that: include: Through the universal large language model with the identity of programming learners preset, the answer codes of students with different styles are simulated to obtain an expanded data set; Encode each symbol of the answer code in the expanded data set, input the obtained encoding sequence into the large language model, and the large language model predicts the next symbol of the encoding sequence based on the previous encoding sequence, and evaluates the difference between the probability distribution of the predicted symbol and the probability distribution of the target symbol by calculating the cross entropy loss; optimize the prediction accuracy of the large language model by minimizing the cross entropy loss to obtain the completion model; Input the student's answer code into the completed training model to obtain the initial recommendation list, combine the current knowledge points and question information to form scenario information, and select the most relevant ones in the initial list. symbols and promote the selected The ranking of symbols is used to generate the final recommendation list.

2. The intelligent code completion method in the programming education scenario according to claim 1 is characterized in that: The symbol is the smallest unit for compiling and running the answer code.

3. The intelligent code completion method in the programming education scenario according to claim 1 is characterized in that: The general large language model with the identity of programming learners is preset to simulate the answer codes of students with different styles to obtain an expanded data set, which specifically includes: Provide multiple knowledge points for a certain programming language for students to learn, and provide multiple questions for each knowledge point for students to practice programming; during the programming practice, record the students' answer codes and answer results, and set standard answers for each question; For each question under each knowledge point of the programming language, a piece of answer code with a passing answer result is selected, and sent into a general large language model together with the corresponding knowledge point, question, and standard answer, and the identity of the programming learner is set for the large language model to let the large language model simulate the answer codes of students with different styles; the answer code output by the large language model is randomly inserted into the general data set to obtain an expanded data set.

4. The intelligent code completion method in a programming education scenario according to claim 1, characterized in that: The large language model predicts the next symbol of the coding sequence according to the previous context of the coding sequence, and evaluates the difference between the probability distribution of the predicted symbol and the probability distribution of the target symbol by calculating the cross entropy loss; the prediction accuracy of the large language model is optimized by minimizing the cross entropy loss to obtain a completion model, which specifically includes: Large language models by encoding sequences The first t symbols of To predict the t+1th symbol The probability distribution of ; Use cross entropy loss to calculate the error between the symbol probability distribution predicted by the large language model and the target symbol probability distribution. By minimizing the cross entropy loss, the symbol probability distribution predicted by the large language model is close to the target symbol probability distribution.

5. The intelligent code completion method in the programming education scenario according to claim 4 is characterized in that: The cross entropy loss for: ; is the tth symbol in the target symbol sequence; When the cross entropy loss converges, the training of the large language model is completed and the completion model is obtained.

6. The intelligent code completion method in the programming education scenario according to claim 1 is characterized in that: The student's answer code is input into the completed training model to obtain an initial recommendation list, and the scenario information is formed by combining the current knowledge point and the question information, specifically including: When students practice questions under the knowledge point knowledge, the students' answer codes are input into the trained completion model in real time, and the probability of each symbol in the vocabulary appearing in the next position of the answer code is calculated, and the top symbol with the highest probability is retained. symbols, forming the initial recommendation list , is the Kth symbol in the initial recommendation list; Combine the knowledge points with the questions to get the scene information scene: ; Represents a concatenation operation.

7. The intelligent code completion method in a programming education scenario according to claim 1, characterized in that: The most relevant scene information in the initial list is selected symbols and promote the selected The ranking of the symbols is used to generate the final recommendation list, which includes: Use BERT encoder to encode scene information into scene information vector ; Use the BERT encoder to encode each symbol in the initial recommendation list into a symbol vector to obtain the recommendation list vector , is the total number of symbols in the initial recommendation list; calculate the recommendation list vector The kth symbol vector in With scene information vector Similarity , ; The highest The rank of the symbol corresponding to the similarity is increased by at least one place to obtain the final recommendation list.

8. The intelligent code completion method in the programming education scenario according to claim 7 is characterized in that: The calculation recommendation list vector The kth symbol vector in With scene information vector Similarity , specifically including: ; in, An operation to find the length of a vector.

9. The intelligent code completion method in the programming education scenario according to claim 7, characterized in that: The highest The rank of the symbol corresponding to the similarity is increased by at least one, specifically including: If the rank of a symbol is the first, the rank of the symbol will not be increased.

Citation Information

Patent Citations

  • Hybrid recommendation system in online education scene

    CN111831918A

  • Programming information recommendation method and device based on similar code recognition

    CN112115362A

  • Government affair digital scene item recommendation method and device, equipment and storage medium

    CN116595161A

  • Enhanced Transform-based code completion method under lexical element granularity

    CN116661797A

  • Face recognition method and device for visual conversion of smart city application

    CN117456590A