Step-by-step programming teaching method and system based on deep learning model

Through text structure trees and abstract syntax trees based on deep learning models, combined with natural language processing, the cumbersome workflows and insufficient generation of graphical programming languages ​​in programming tutorial writing are solved, and fast and easy programming tutorial writing and efficient implementation are achieved Text-code association matching improves the quality and user experience of programming tutorials.

CN119088374AActive Publication Date: 2024-12-06ZHEJIANG UNIV
View PDF 10 Cites 0 Cited by

Patent Information

Application Number
CN202411084763.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-08-08
Publication Date
2024-12-06
Estimated Expiration
2044-08-08

AI Technical Summary

Technical Problem

Writing high-quality step-by-step programming tutorials requires frequent switching between programming tools and text editors, resulting in cumbersome and laborious workflows. The existing technology cannot effectively understand the user's text input and problem requirements, and the graphical programming languages ​​are used. Inadequate grammar training leads to poor generation results.

Method used

Building text structure trees and abstract syntax trees based on deep learning models, combining feature extraction, feature mapping and prediction modules, embed text and code into the same vector space through natural language processing, perform similarity matching and association, and provide code snippet recommendations for programming requirements , and introduce constraints through user interaction history connections to ensure the validity and consistency of matching results.

Benefits of technology

It enables users to quickly and easily write step-by-step programming tutorials in programming tutorials. Through intuitive text-code association positioning, it reduces cognitive burden, assists users to verify and write tutorial content, and improves the quality and efficiency of programming tutorials.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119088374A_ABST
    Figure CN119088374A_ABST
Patent Text Reader

Abstract

The invention discloses a step-by-step programming teaching method based on a deep learning model. The step-by-step programming teaching method comprises the following steps: constructing a text structure tree and an abstract syntax tree; based on the text structure tree and the abstract syntax tree as constraint frameworks, a deep learning model is constructed, and the deep learning model comprises a feature extraction module, a feature mapping module and a prediction module; and during use, inputting the text content of the programming demand into the deep learning model to obtain a code piece corresponding to the programming demand. The invention further provides a step-by-step programming teaching system. According to the method provided by the invention, the course content writing prompt and guidance are provided for the user, so that the user can quickly and easily write the step-by-step programming course in the programming course.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the field of teaching assistance, and in particular relates to a step-by-step programming teaching method and system based on a deep learning model. Background Art

[0002] A programming tutorial is a document used to teach learners programming skills and how to solve programming problems. Many programmers spread their programming knowledge in the form of tutorials. As the demand for learning programming continues to expand, the number of tutorial authors has also increased (such as program developers, computer science educators, data science, etc.), and research on improving the writing experience and workflow of programming tutorials has also increased. Among the types of programming tutorials, step-by-step programming tutorials are a common and easy-to-understand type.

[0003] However, writing high-quality step-by-step programming tutorials is still a tedious task. High-quality tutorials should include concise code, step-by-step solutions and highlights, etc. In a typical workflow, creating a step-by-step programming tutorial requires organizational structure and written prose instructions. Clear and easy-to-understand code instructions require the author to have rich experience and a thorough understanding of the code. Authors usually view the code in a programming tool (such as Visual Studio Code) and then edit it in a text editor. This requires switching back and forth between the programming tool and the text editor to ensure the correctness of the content structure description. After the tutorial is completed, the author also needs to verify their consistency, which makes writing tutorials a laborious task.

[0004] Patent document CN116151132A discloses an intelligent code completion method, system and storage medium for programming learning scenarios, which inputs source code into a trained transformer deep neural network model to output the predicted results after source code completion; the intelligent code completion method, system and storage medium use a unique data set for preprocessing, and select different recommendation algorithms based on user feedback to continuously improve the quality of recommended code in the intelligent code completion function, and the abstract syntax tree generated by the source code is split and reconstructed to capture more semantic information of the code, thereby improving the accuracy of code completion. The invention uses a deep learning method for code completion prompts, but cannot understand the user's text input and question requirements. At the same time, its method is completely dependent on the trained data set, and the generalization ability of the model is poor.

[0005] Patent document CN116974541A discloses a programming assistance method based on LLM, which specifically includes the following steps: deploying a programming assistance model as an interface service, and using a protocol and data format for interface access; wherein the programming assistance model is a large language model; establishing a programming management platform, and connecting the programming assistance model interface to the programming management platform; using the programming management platform to interact with the programming assistance model to complete programming assistance work. This invention does not conduct specialized training on the grammar of graphical programming languages, and cannot well complete the generation and visualization of graphical programming languages. Summary of the invention

[0006] The purpose of the present invention is to provide a step-by-step programming teaching method and system based on a deep learning model, which provides users with tutorial content writing prompts and guidance, so that users can quickly and easily write step-by-step programming tutorials in programming tutorials.

[0007] In order to achieve the first objective of the present invention, the following technical solution is provided: a step-by-step programming teaching method based on a deep learning model, comprising the following steps:

[0008] Obtain a set of text fragments involving programming step descriptions in the programming tutorial, and construct a corresponding text structure tree with each text fragment as a node and the programming step as an edge;

[0009] According to the collection of programming codes involved in programming teaching, the corresponding abstract syntax tree is constructed with code snippets as nodes and code running relationships as edges;

[0010] Based on the text structure tree and the abstract syntax tree as a constraint framework, a deep learning model is constructed, wherein the deep learning model includes a feature extraction module, a feature mapping module and a prediction module;

[0011] The feature extraction module is used to extract a first text feature of an input natural language text and a second text feature of a code snippet in a programming code set;

[0012] The feature mapping module is used to simultaneously project the first text feature and the second text feature into a vector space to obtain a corresponding first feature vector and a second feature vector;

[0013] The prediction module uses the first feature vector and the second feature vector to perform similarity matching to output a matching result, wherein the matching result includes the first K coding segments with the highest similarity matching the input natural language text;

[0014] Input the code phrase input by the user into the deep learning model to visualize and output the code snippet related to the code phrase;

[0015] When in use, the text content of the programming requirements is input into the deep learning model to obtain the code snippets corresponding to the programming requirements.

[0016] The present invention matches text-code associations based on a connection engine based on a deep learning model and user interaction history. Through a deep learning model for natural language processing, the code and text are embedded in the same vector space to detect vector similarity; at the same time, an abstract syntax tree and a text structure tree are introduced to constrain the matching method, ensuring that the matching result is a valid code snippet and is consistent with the order of the description text.

[0017] Specifically, in the text structure tree, the main step and the sub-step are regarded as the parent node and the child node, and the steps at the same level are set as the nodes at the same level.

[0018] Specifically, the abstract syntax tree is recursively traversed starting from the root node, and nodes that do not meet the requirements are deleted to retain relevant nodes and branches.

[0019] Specifically, the prediction module follows the validity principle and the consistency principle during the similarity matching process.

[0020] Specifically, the validity principle refers to the completeness of the structure of the code snippet corresponding to the second feature vector, which is specifically set as follows:

[0021] Set the abstract syntax tree to A, for any node a i ∈A, if parent(a i )∈F, then a i ∈F;

[0022] Then the code fragment can be represented as a sequence of AST subtrees: F = subA i ∪subA i+1 ∪...∪subA i+n ;

[0023] Among them, subA i Indicates that the root node is a i subtree, and {a i ,a i+1 ,...,a i+n} are consecutive child nodes of the same parent node.

[0024] Specifically, the consistency principle means that the natural language text corresponding to the first feature vector is consistent with the code snippet structure corresponding to the second feature vector.

[0025] Specifically, the network framework of the deep learning model adopts the pre-trained UniXcoder.

[0026] Specifically, the similarity matching is calculated using a cosine similarity calculation formula.

[0027] In order to achieve the second object of the present invention, the following technical solution is provided: a step-by-step programming teaching system, which is implemented by the step-by-step programming teaching method based on the deep learning model, comprising:

[0028] Input module, used to input text content required for programming;

[0029] The relevant analysis module outputs relevant coding fragments based on the input text content;

[0030] The source code display module is used to display the programming tutorial content corresponding to the coding snippet.

[0031] Compared with the prior art, the present invention has the following beneficial effects:

[0032] By extracting the structural association between text and code, users can intuitively understand the connection between the current text content and the code, and quickly locate the two, which can serve as an entry point for further efficient writing and modification of tutorials, reducing cognitive burden.

[0033] At the same time, a deep learning model is used to match the similarity between text and code, which not only helps users verify the current content, but also facilitates the writing of subsequent tutorials. BRIEF DESCRIPTION OF THE DRAWINGS

[0034] Figure 1 A schematic diagram of the flow chart of the step-by-step programming teaching method provided in this embodiment;

[0035] Figure 2 A schematic diagram of the effectiveness principle provided for this embodiment;

[0036] Figure 3 A schematic diagram of the consistency principle provided for this embodiment;

[0037] Figure 4 This is an interface display diagram of the step-by-step programming teaching system provided in this embodiment. DETAILED DESCRIPTION

[0038] In order to make the purpose, technical scheme and advantages of the embodiments of the present invention clearer, the technical scheme in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. The components of the embodiments of the present invention generally described and shown in the drawings here can be arranged and designed in various different configurations. Therefore, the following detailed description of the embodiments of the present invention provided in the drawings is not intended to limit the scope of the claimed invention, but merely represents selected embodiments of the present invention. Based on the embodiments in the present invention, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of the present invention.

[0039] like Figure 1 As shown, a step-by-step programming teaching method based on a deep learning model provided by the present invention comprises the following steps:

[0040] Obtain a set of text fragments involving programming step descriptions in the programming tutorial, and construct a corresponding text structure tree with each text fragment as a node and the programming step as an edge;

[0041] According to the collection of programming codes involved in programming teaching, the corresponding abstract syntax tree is constructed with code snippets as nodes and code running relationships as edges;

[0042] Based on the text structure tree and the abstract syntax tree as a constraint framework, a deep learning model is constructed, wherein the deep learning model includes a feature extraction module, a feature mapping module and a prediction module;

[0043] The feature extraction module is used to extract a first text feature of an input natural language text and a second text feature of a code snippet in a programming code set;

[0044] The feature mapping module is used to simultaneously project the first text feature and the second text feature into a vector space to obtain a corresponding first feature vector and a second feature vector;

[0045] The prediction module uses the first feature vector and the second feature vector to perform similarity matching to output a matching result, wherein the matching result includes the first K coding segments with the highest similarity matching the input natural language text;

[0046] Input the code phrase input by the user into the deep learning model to visualize and output the code snippet related to the code phrase;

[0047] When in use, the text content of the programming requirements is input into the deep learning model to obtain the code snippets corresponding to the programming requirements.

[0048] More specifically, in the text structure tree, main steps and sub-steps are considered as parent nodes and child nodes, while sibling steps are set as sibling nodes.

[0049] The abstract syntax tree recursively traverses the root node as the starting point and deletes nodes that do not meet the requirements to retain relevant nodes and branches.

[0050] After obtaining the abstract syntax tree, we can know the type of each node (such as function, statement, variable, etc.). In order to improve the matching efficiency, we first need to filter the nodes. According to the type attribute of the node, only nodes that are not lower than the statement are retained. Here, the specific method is to recursively traverse from the root node. If a node whose node type attribute does not meet the requirements is accessed (such as a variable, etc.), it will be deleted until the traversal is completed.

[0051] Based on the text structure tree and abstract syntax tree, the next step is to determine the legal code range of the code snippet that may match the step currently written by the user according to the user's current writing process. By filtering according to the established text-code association, for example, if the current step is a child of the previous step, the code described is required to be a child node of the node that belongs to the code bound to the previous step in the abstract syntax tree.

[0052] Among them, the text node can correspond to the code fragment F:={statement(a i )|σ≤lineno(a i )<τ}, which consists of the sequential code statements starting from line σ to line τ in the code.

[0053] The matching code fragment must be valid and consistent with the text structure. Therefore, the code fragment F to match the new text new There are two constraints on the candidates:

[0054] like Figure 2 As shown, the definition of the validity principle provided for this embodiment is: the validity of the code snippet needs to be verified in the abstract syntax tree (AST). If the code snippet structure is incomplete, it is considered invalid.

[0055] F3 is invalid because it only contains half of a "while" loop. We set the constraints as follows: Let the abstract syntax tree be A, for any node a i ∈A, if parent(a i )∈F, then a i ∈F. Therefore, a code snippet can be represented as a sequence of AST subtrees:

[0056] F=subA i ∪subA i+1∪...∪subA i+n ;

[0057] Among them, subA i Indicates that the root node is a i The subtree of i ,a i+1 ,...,a i+n} are consecutive child nodes of the same parent node.

[0058] like Figure 3 As shown in the figure, the definition of the consistency principle provided in this embodiment is to impose the following constraints on the code fragment F: if t pre t new The parent node of F new Included in F pre Otherwise, if the new step is the next step immediately following the previous step, then F new root i Should be F pre Middle root j The adjacent sibling nodes of .

[0059] Among the candidate code snippets, we need to find the part that best matches the natural language text input by the user. Here we use a pre-trained deep learning model UniXcoder, which can embed text and code snippets into the same vector space. For each step description, we input t and {F} into the model to obtain their embedding vectors vt and vF. The similarity between text and code is measured by cos(vt,vF). Therefore, it can be concluded that the construction of text-code connections will be ranked according to this indicator.

[0060] This embodiment also provides a step-by-step programming teaching system, which is implemented by the step-by-step programming teaching method based on the deep learning model provided in the above embodiment.

[0061] It includes: an input module for inputting text content of programming requirements;

[0062] The relevant analysis module outputs relevant coding fragments based on the input text content;

[0063] The source code display module is used to display the programming tutorial content corresponding to the coding snippet.

[0064] More specifically, Figure 4As shown in the figure, the user first enters the target code for writing the tutorial description in the code editor, and can write the step-by-step tutorial content in the document editor. After entering the content, the connection engine in the system will extract the hierarchical structure of the text and code, obtain the abstract syntax tree and text structure tree, and filter the legal range. After being processed by the natural language processing model, the recommended text-code association will be presented to the user, and the user can connect each step description with its corresponding code snippet. The connection engine will continue to maintain the established connections, and based on these associations, it will provide step guidance and phrase writing functions, which can be used in subsequent tutorial writing workflows.

[0065] The specific functions of this system include: when the user writes a new step, the code editor will highlight the starting line of the code with the recommended description to indicate the part of the code that the user should currently explain in detail.

[0066] During the writing process, users can associate and bind text segments and code segments at any time, so that the system can make automatic recommendations for subsequent tutorial writing.

[0067] When a user describes a variable in the code with a phrase, the system will provide a list of recommended variable matches for the user to establish an association between the phrase and the variable. Among them, variables that have not been bound will have a higher priority, and the established associations are highlighted synchronously in the code editor and the document editor.

[0068] Based on the bound variables, the system will provide automatic completion reminders for the content the user is entering; at the same time, when the user wants to uniformly modify the expression of a variable in the entire text, the system can help the user achieve one-click replacement.

[0069] In summary, the present invention is a web-based programming tutorial writing system, which is dedicated to assisting users in extracting corresponding text-code associations when writing tutorials and presenting them to users, so as to help users quickly understand the relationship between the current writing content and the code, and at the same time provide tutorial writing prompts and guidance, which is conducive to users' understanding, maintenance and verification of tutorial content, so as to achieve the purpose of more efficient programming tutorial writing.

[0070] In addition, the terms "upper", "lower", "inner", "outer", "front", "rear" are used for descriptive purposes only and should not be understood as indicating or implying relative importance. Unless otherwise specifically stated, the relative steps, numerical expressions and values ​​of the components and steps described in these embodiments do not limit the scope of the present invention.

[0071] Of course, the above description is only a specific embodiment of the present invention and is not intended to limit the scope of implementation of the present invention. All equivalent changes or modifications made according to the structure, characteristics and principles described in the patent application scope of the present invention should be included in the patent application scope of the present invention.

[0072] Finally, it should be noted that the above-described embodiments are only specific implementations of the present invention, which are used to illustrate the technical solutions of the present invention, rather than to limit them. The protection scope of the present invention is not limited thereto. Although the present invention is described in detail with reference to the above-described embodiments, ordinary technicians in the field should understand that any technician familiar with the technical field can still modify the technical solutions recorded in the above-described embodiments within the technical scope disclosed by the present invention, or can easily think of changes, or make equivalent replacements for some of the technical features therein; and these modifications, changes or replacements do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the embodiments of the present invention, and should be included in the protection scope of the present invention. Therefore, the protection scope of the present invention shall be subject to the protection scope of the claims.

Claims

1. A step-by-step programming teaching method based on a deep learning model, characterized in that: The following steps are involved: Obtain a set of text fragments involving programming step descriptions in the programming tutorial, and construct a corresponding text structure tree with each text fragment as a node and the programming step as an edge; According to the collection of programming codes involved in programming teaching, the corresponding abstract syntax tree is constructed with code snippets as nodes and code running relationships as edges; Based on the text structure tree and the abstract syntax tree as a constraint framework, a deep learning model is constructed, wherein the deep learning model includes a feature extraction module, a feature mapping module and a prediction module; The feature extraction module is used to extract a first text feature of an input natural language text and a second text feature of a code snippet in a programming code set; The feature mapping module is used to simultaneously project the first text feature and the second text feature into a vector space to obtain a corresponding first feature vector and a second feature vector; The prediction module uses the first feature vector and the second feature vector to perform similarity matching to output a matching result, wherein the matching result includes the first K coding segments with the highest similarity matching the input natural language text; Input the code phrase input by the user into the deep learning model to visualize and output the code snippet related to the code phrase; When in use, the text content of the programming requirements is input into the deep learning model to obtain the code snippets corresponding to the programming requirements.

2. The step-by-step programming teaching method based on the deep learning model according to claim 1 is characterized in that: In the text structure tree, main steps and substeps are considered parent and child nodes, while sibling steps are set as sibling nodes.

3. The step-by-step programming teaching method based on the deep learning model according to claim 1 is characterized in that: The abstract syntax tree is recursively traversed starting from the root node, and nodes that do not meet the requirements are deleted to retain relevant nodes and branches.

4. The step-by-step programming teaching method based on the deep learning model according to claim 1 is characterized in that: The prediction module follows the validity principle and the consistency principle during the similarity matching process.

5. The step-by-step programming teaching method based on the deep learning model according to claim 1 is characterized in that: The validity principle refers to the complete structure of the code snippet corresponding to the second feature vector, which is specifically set as follows: Set the abstract syntax tree to A, for any node a i ∈A, if parent(a i )∈F, then a i ∈F; Then the code fragment can be represented as a sequence of AST subtrees: F = subA i ∪subA i+1 ∪...∪subA i+n ; Among them, subA i Indicates that the root node is a i The subtree of i ,a i+1 ,...,a i+n } are consecutive child nodes of the same parent node.

6. The step-by-step programming teaching method based on the deep learning model according to claim 1 is characterized in that: The consistency principle means that the natural language text corresponding to the first feature vector and the code snippet corresponding to the second feature vector have the same structure.

7. The step-by-step programming teaching method based on the deep learning model according to claim 1 is characterized in that: The network framework of the deep learning model adopts the pre-trained UniXcoder.

8. The step-by-step programming teaching method based on the deep learning model according to claim 1 is characterized in that: The similarity matching is calculated using the cosine similarity calculation formula.

9. A step-by-step programming teaching system, characterized in that: The method is implemented by a step-by-step programming teaching method based on a deep learning model as claimed in any one of claims 1 to 8, comprising: Input module, used to input text content required for programming; The relevant analysis module outputs relevant coding fragments based on the input text content; The source code display module is used to display the programming tutorial content corresponding to the coding snippet.

Citation Information

Patent Citations

  • Code similarity detection method and device

    CN110347428A

  • Code snippet recommendation method and device based on deep neural network

    CN111142850A

  • Clone code semantic detection method based on deep learning

    CN112215013A

  • Object-oriented program method naming odor detection method based on deep learning

    CN114398076A

  • Python language code snippet generation method based on graph learning

    CN114489669A