GPT-based flow chart code generation method and system
By pre-training the GPT model and training the flowchart dataset, a code model that meets programming standards is generated, which solves the syntax and semantic consistency problems in code generation, improves the accuracy and relevance of code generation, and reduces the difficulty of development and time.
Patent Information
- Application Number
- CN202410992082.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-23
- Publication Date
- 2024-11-08
AI Technical Summary
The existing technology is difficult to maintain syntax accuracy, semantic consistency and rationality of code structure during the code generation process, resulting in poor code generation results.
The GPT model is pre-trained by obtaining open source project code and training it in combination with the flowchart target dataset to generate the object code model, optimize the code model to comply with programming standards, and output context-related code snippets.
Improves the accuracy and relevance of code generation, significantly reduces the time it takes for developers to write code, and lowers the development barrier, especially for non-professional programmers or beginners.
Smart Images

Figure CN118916017A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the field of computer technology, and in particular, relates to a method and system for generating codes based on a GPT flowchart. Background Art
[0002] With the continuous development of natural language processing (NLP) and machine learning (ML) technologies, using pre-trained models for code generation has become a forward-looking research direction. In particular, generative pre-training technology enables models to understand and generate natural language by pre-training on large-scale corpora, providing new possibilities for automated code generation.
[0003] However, despite GPT's remarkable achievements in natural language generation, its application in the field of code generation still faces challenges. Existing technologies have difficulty maintaining grammatical accuracy, semantic consistency, and rationality of code structure during code generation. Therefore, how to better implement code generation has become an urgent problem to be solved. Summary of the invention
[0004] In view of the above deficiencies in the prior art, the purpose of the invention is to provide a method and system for generating code from a flowchart based on GPT, which improves the accuracy of the generated code and its relevance to the context; reduces the time for developers to write code, accelerates the software development process; and lowers the development threshold.
[0005] In a first aspect of the present invention, a method for generating code from a flowchart based on GPT is proposed, comprising: S1, obtaining open source project code, and pre-training a GPT model based on the open source project code to obtain the pre-trained GPT model; S2, obtaining a flowchart target data set, and obtaining a flowchart target code segment based on the flowchart target data set; S3, introducing the flowchart target code segment into the pre-trained GPT model, training the flowchart target code segment, and obtaining a target code model; S4, when a first code segment is input into the target code model, outputting a context code segment based on the first code segment.
[0006] Furthermore, the flowchart target data set includes start / end node data, process node data, judgment node data, connection line data, loop node data, lane node data, and annotation node data.
[0007] Furthermore, obtaining a flowchart target code segment based on the flowchart target data set includes: determining a training set and a validation set for each type of data in the flowchart target data set; training each type of data based on the training set and the validation set of each type of data to obtain a code segment corresponding to each type of data; obtaining the flowchart target code segment based on the code segment corresponding to each type of data, the flowchart target code segment including entry and exit code segments, process node code segments, conditional statement code segments, data transfer code segments, loop statement code segments, calling logic code segments, and comment code segments.
[0008] Furthermore, the target code segment of the flowchart is trained to obtain a target code model, including: training the target code segment of the flowchart to obtain a code model; acquiring diversified data, and training the code model based on the diversified data to obtain the target code model.
[0009] Furthermore, obtaining diversified data, and training the code model based on the diversified data to obtain the target code model, includes: obtaining the diversified data, and training the code model based on the diversified data to obtain the trained code model; optimizing the trained code model to obtain the target code model.
[0010] Furthermore, the trained code model is optimized to obtain the target code model, including: determining a code reference standard, the code reference standard including naming conventions, code structure, encoding format, and error information handling; judging whether the flowchart target code segment complies with the code reference standard; if it is determined that the flowchart target code segment does not comply with the code reference standard, manually modifying the flowchart target code segment and training the modified flowchart target code segment until the modified flowchart target code segment complies with the code reference standard, thereby obtaining the target code model.
[0011] In a second aspect of the present invention, a system for generating code from a flowchart based on GPT is proposed, comprising: a GPT model training module, used to obtain open source project code, and pre-train a GPT model based on the open source project code to obtain the pre-trained GPT model; an obtaining module, used to obtain a flowchart target data set, and obtain a flowchart target code segment based on the flowchart target data set; a target code model is determined, used to introduce the flowchart target code segment into the pre-trained GPT model, train the flowchart target code segment, and obtain a target code model; a code generation module, used to output a context code segment based on the first code segment when a first code segment is input into the target code model.
[0012] According to a third aspect of the present invention, an electronic device is proposed, comprising: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute any of the methods described in the first aspect of the present invention.
[0013] According to a fourth aspect of the present invention, a non-transitory computer-readable storage medium storing computer instructions is provided, wherein the computer instructions are used to enable the computer to execute any one of the methods according to the first aspect of the present invention.
[0014] The beneficial effects of the present invention are as follows:
[0015] The method and system for generating code based on flowcharts of the present invention obtain open source project code, and pre-train the GPT model based on the open source project code to obtain the pre-trained GPT model; obtain a flowchart target data set, and obtain a flowchart target code segment based on the flowchart target data set; introduce the flowchart target code segment into the pre-trained GPT model, train the flowchart target code segment, and obtain a target code model; when the first code segment is input into the target code model, output a context code segment based on the first code segment. This method can enable the model to better understand the code structure and logic of a specific field by introducing the flowchart target code segment into the pre-trained GPT model for training, thereby improving the accuracy of the generated code and the relevance to the context; the automatic generation of context-related code segments can significantly reduce the time for developers to write code and accelerate the software development process; for non-professional programmers or beginners, tools that can automatically generate related code segments based on existing code can reduce the difficulty of programming and reduce the development threshold. BRIEF DESCRIPTION OF THE DRAWINGS
[0016] The accompanying drawings are only used to illustrate specific embodiments and are not considered to limit the present invention. In the entire drawings, the same reference symbols represent the same components. Obviously, the drawings described below are only some embodiments recorded in the embodiments of the present invention. For those of ordinary skill in the art, other drawings can also be obtained based on these drawings.
[0017] Figure 1 is a flowchart of a method for generating codes based on a GPT flowchart according to an embodiment of the present invention;
[0018] Figure 2 is a flowchart of a method for generating codes based on a GPT flowchart according to a specific embodiment of the present invention;
[0019] Figure 3is a structural block diagram of a system for generating codes based on a GPT flowchart according to an embodiment of the present invention;
[0020] Figure 4 It is a structural block diagram of an electronic device according to an embodiment of the present invention. DETAILED DESCRIPTION
[0021] In order to enable those skilled in the art to better understand the technical solutions in the embodiments of the present invention, the technical solutions of the present invention will be clearly and completely described below in conjunction with the accompanying drawings. Obviously, the described embodiments are part of the embodiments of the present invention, rather than all of the embodiments. It should be understood that these descriptions are only exemplary and are not intended to limit the scope of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in the field without making creative work should fall within the scope of protection of the present invention.
[0022] Furthermore, in the following description, descriptions of well-known structures and technologies are omitted to avoid unnecessarily obscuring the concepts disclosed in the present invention.
[0023] In the description of the present invention, it should be noted that, unless otherwise clearly specified and limited, the orientation or position relationship indicated by the terms "center", "upper", "lower", "left", "right", "vertical", "horizontal", "inside", "outside", etc. is based on the orientation or position relationship shown in the drawings, which is only for the convenience of describing the present invention and simplifying the description, and does not indicate or imply that the device or element referred to must have a specific orientation, be constructed and operated in a specific orientation, and therefore cannot be understood as a limitation of the present invention. In addition, the terms "first", "second", and "third" are only used for descriptive purposes and cannot be understood as indicating or implying relative importance. The terms "installed", "connected", and "connected" should be understood in a broad sense, for example, it can be a fixed connection, a detachable connection, or an integral connection; it can be a mechanical connection or an electrical connection; it can be a direct connection, or it can be indirectly connected through an intermediate medium, or it can be a connection between the two elements. For those of ordinary skill in the art, the specific meanings of the above terms in the present invention can be understood according to specific circumstances.
[0024] Exemplary embodiments will be described in detail herein, examples of which are shown in the accompanying drawings. When the following description refers to the drawings, unless otherwise indicated, the same numbers in different drawings represent the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present invention. Instead, they are merely examples of methods and systems consistent with some aspects of the present invention as detailed in the appended claims.
[0025] The present invention proposes a method, system and related equipment for generating codes from flowcharts based on GPT. Specifically, the method, system and related equipment for generating codes from flowcharts based on GPT according to an embodiment of the present invention are described below with reference to the accompanying drawings.
[0026] Figure 1 It is a flowchart of a method for generating codes from a flowchart based on GPT according to an embodiment of the present invention. It should be noted that the method for generating codes from a flowchart based on GPT in an embodiment of the present invention can be applied to a system for generating codes from a flowchart based on GPT in an embodiment of the present invention. The system for generating codes from a flowchart based on GPT can be configured on an electronic device or in a server. This embodiment of the present application does not limit this.
[0027] like Figure 1 As shown, the method for generating codes based on the GPT flowchart includes:
[0028] S110, obtaining open source project code, and pre-training the GPT model based on the open source project code to obtain a pre-trained GPT model.
[0029] In an embodiment of the present invention, the open source project code includes but is not limited to open source project codes in programming languages such as Java, Python, and C++. When the open source project code is obtained, the GPT model can be pre-trained based on the open source project code to obtain a pre-trained GPT model.
[0030] Among them, by using open source project codes as training sets for the GPT model, it is ensured that the GPT model can understand codes in various coding formats and fields.
[0031] S120, acquiring a flowchart target data set, and obtaining a flowchart target code segment based on the flowchart target data set.
[0032] In an embodiment of the present invention, the flowchart target data set includes start / end node data, process node data, judgment node data, connection line data, loop node data, lane node data, and annotation node data. When the flowchart target data set is obtained, model training can be performed based on each type of data in the target data set to obtain the flowchart target code segment. The specific implementation method can refer to the subsequent embodiments.
[0033] S130, introducing the flowchart target code segment into the pre-trained GPT model, training the flowchart target code segment, and obtaining a target code model.
[0034] In an embodiment of the present invention, when a pre-trained GPT model and a flowchart target code segment are obtained, the flowchart target code segment can be introduced into the pre-trained GPT model to train the flowchart target code segment to obtain a target code model. The specific implementation method can refer to the subsequent embodiments.
[0035] S140: When the first code segment is input into the target code model, a context code segment based on the first code segment is output.
[0036] In an embodiment of the present invention, when a target code model is obtained, the first code segment may be input into the target code model, and then a context code segment of the first code segment may be obtained.
[0037] According to the method for generating code from flowcharts based on GPT in an embodiment of the present invention, open source project code is obtained, and a GPT model is pre-trained based on the open source project code to obtain a pre-trained GPT model; a flowchart target data set is obtained, and a flowchart target code segment is obtained based on the flowchart target data set; the flowchart target code segment is introduced into the pre-trained GPT model, and the flowchart target code segment is trained to obtain a target code model; when the first code segment is input into the target code model, a context code segment based on the first code segment is output. This method can enable the model to better understand the code structure and logic of a specific field by introducing the flowchart target code segment into the pre-trained GPT model for training, thereby improving the accuracy of the generated code and its relevance to the context; the automatic generation of context-related code segments can significantly reduce the time for developers to write code and accelerate the software development process; for non-professional programmers or beginners, tools that can automatically generate related code segments based on existing code can reduce the difficulty of programming and lower the development threshold.
[0038] In order to make it easier for those skilled in the art to understand the present invention, Figure 2 is a method for generating codes based on a GPT flowchart according to a specific embodiment of the present invention. Figure 2 As shown, the method for generating codes based on the GPT flowchart includes:
[0039] S210, obtaining open source project code, and pre-training the GPT model based on the open source project code to obtain a pre-trained GPT model.
[0040] In the embodiment of the present invention, the implementation of step S210 may refer to the implementation of step S110 described above, and the present invention will not elaborate on this any more.
[0041] S220, acquiring a flowchart target data set, and obtaining a flowchart target code segment based on the flowchart target data set.
[0042] In an embodiment of the present invention, the flowchart target data set includes start / end node data, process node data, judgment node data, connection line data, loop node data, lane node data, and annotation node data.
[0043] Among them, the training set and verification set of each type of data in the flowchart target data set are determined; each type of data is trained based on the training set and verification set of each type of data to obtain the code segment corresponding to each type of data; the flowchart target code segment is obtained based on the code segment corresponding to each type of data, and the flowchart target code segment includes entry and exit code segments, process node code segments, conditional statement code segments, data transfer code segments, loop statement code segments, calling logic code segments, and comment code segments.
[0044] For example, data marked with start and end nodes may be obtained, for example, the data may be a flowchart, and the data of the start and end nodes may be divided into a training set and a verification set, and then the training set may be trained, and the verification may be performed based on the verification set to obtain an entry / exit code segment; functions or data corresponding to process nodes may be obtained, wherein the process nodes represent functions or operations, and the functions or data corresponding to the process nodes may be divided into a training set and a verification set, and then the training set may be trained, and the verification may be performed based on the verification set to obtain a process node code segment; data containing judgment nodes may be obtained, for example, the data may be a flowchart, and the data containing judgment nodes may be divided into a training set and a verification set, and then the training set may be trained, and the verification may be performed based on the verification set to obtain a conditional statement code segment;
[0045] Data containing connecting lines can be obtained, for example, the data can be a flowchart, wherein the connecting lines represent the path of information flow, and the data containing connecting lines are divided into a training set and a verification set, and then the training set is trained, and the verification is performed based on the verification set to obtain a data transfer code segment; data containing loop nodes can be obtained, for example, the data can be a flowchart, and the data containing loop nodes are divided into a training set and a verification set, and then the training set is trained, and the verification is performed based on the verification set to obtain a loop statement code segment; data containing lane nodes can be obtained, for example, the data can be a flowchart, wherein the lane nodes represent the boundaries of different methods, and the data containing lane nodes are divided into a training set and a verification set, and then the training set is trained, and the verification is performed based on the verification set to obtain a calling logic code segment; data containing comment nodes can be obtained, for example, the data can be a flowchart, wherein the comment nodes represent the comment text of the code, and the data containing comment nodes are divided into a training set and a verification set, and then the training set is trained, and the verification is performed based on the verification set to obtain the comment code segment.
[0046] S230, introducing the flowchart target code segment into the pre-trained GPT model.
[0047] In an embodiment of the present invention, when a flowchart target code segment is obtained, the flowchart target code segment can be introduced into the pre-trained GPT model. That is, in the pre-trained GPT model, the flowchart target code segment is used as training data.
[0048] S240, training the target code segment of the flowchart to obtain a code model.
[0049] S250, obtaining diversified data, and training a code model based on the diversified data to obtain a target code model.
[0050] In an embodiment of the present invention, when a code model is obtained, diversified data is acquired, and the code model is trained based on the diversified data to obtain a trained code model; the trained code model is optimized to obtain a target code model.
[0051] Among them, the diverse data includes but is not limited to different programming languages, flowcharts of different complexities and corresponding codes, noise data, etc., to ensure that the code model can be generalized to various situations, and to help the code model identify and ignore irrelevant information to improve robustness.
[0052] Among them, the implementation method of optimizing the code model to obtain the target code model is: determining the code reference standard, the code reference standard includes naming conventions, code structure, encoding format, and error information processing; judging whether the flowchart target code segment meets the code reference standard; when it is determined that the flowchart target code segment does not meet the code reference standard, manually modifying the flowchart target code segment and training the modified flowchart target code segment until the modified flowchart target code segment meets the code reference standard, thereby obtaining the target code model.
[0053] Among them, in the naming convention, the names of variables, functions, and classes should clearly describe their purpose; use camel case or underscore naming; the first letter of the class name is capitalized, and the first letter of the variable and function names is lowercase. In the code structure, follow the modular principle and decompose the code into independent and reusable parts; use comments and document strings to explain complex logic or algorithms; functions and methods should be short and focus on a single responsibility. In the coding format, maintain consistent indentation and space usage; use brackets and curly braces to surround code blocks, even if they are only one line; avoid using magic numbers and strings, and define constants instead. In error handling, use exception handling to manage error conditions and avoid program crashes; record error information to facilitate debugging and tracking problems.
[0054] S260: When the first code segment is input into the target code model, a context code segment based on the first code segment is output.
[0055] In an embodiment of the present invention, when a target code model is obtained, a context code segment based on the first code segment may be output when the first code segment is input into the target code model, that is, the output context code segment based on the first code segment has context awareness capability.
[0056] According to the method for generating code from a flowchart based on GPT in an embodiment of the present invention, by combining the pre-trained GPT model and the flowchart target code segment, it is possible to automatically generate code corresponding to the flowchart, reducing the need for manual coding; by training on diversified data, the code model is able to handle a wider range of programming scenarios, thereby improving the applicability and robustness of the model; code reference standards are introduced and continuously optimized during the training process to ensure that the generated code follows certain programming specifications, thereby improving the readability and maintainability of the code; through the application of the target code model, the generated code can better understand contextual information, thereby improving the accuracy and relevance of the code; automated code generation can significantly shorten the software development cycle, especially in the preliminary design stage, and can quickly convert from a flowchart to actual executable code; reduce the workload of manual coding, reduce the debugging and maintenance costs caused by coding errors, thereby saving project budgets; and realize an efficient, automated and quality-controlled code generation system.
[0057] Through the description of the above implementation methods, those skilled in the art can clearly understand that the method according to the above embodiment can be implemented by means of software plus a necessary general hardware platform, and of course by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present application, or the part that contributes to the prior art, can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk), and includes a number of instructions for a terminal device (which can be a mobile phone, computer, server, or network device, etc.) to execute the methods of each embodiment of the present application.
[0058] According to one aspect of an embodiment of the present invention, a system for generating codes based on a flowchart of GPT is also proposed. Figure 3 is a structural block diagram of a system for generating codes based on a GPT flowchart according to an embodiment of the present invention; Figure 3 As shown, including:
[0059] A GPT model training module 310 is used to obtain open source project code and pre-train the GPT model based on the open source project code to obtain the pre-trained GPT model;
[0060] An obtaining module 320 is used to obtain a flowchart target data set, and obtain a flowchart target code segment based on the flowchart target data set;
[0061] Determine a target code model 330, which is used to introduce the flowchart target code segment into the pre-trained GPT model, train the flowchart target code segment, and obtain a target code model;
[0062] The code generation module 340 is configured to output a context code segment based on the first code segment when the first code segment is input into the target code model.
[0063] According to the GPT-based flowchart code generation system of the embodiment of the present invention, the open source project code is obtained, and the GPT model is pre-trained based on the open source project code to obtain the pre-trained GPT model; the flowchart target data set is obtained, and the flowchart target code segment is obtained based on the flowchart target data set; the flowchart target code segment is introduced into the pre-trained GPT model, and the flowchart target code segment is trained to obtain the target code model; when the first code segment is input into the target code model, the context code segment based on the first code segment is output. Thus, by introducing the flowchart target code segment into the pre-trained GPT model for training, the model can better understand the code structure and logic of a specific field, thereby improving the accuracy of the generated code and the relevance to the context; the automatic generation of context-related code segments can significantly reduce the time for developers to write code and accelerate the software development process; for non-professional programmers or beginners, tools that can automatically generate related code segments based on existing code can reduce the difficulty of programming and lower the development threshold.
[0064] Optionally, the flowchart target data set includes start / end node data, process node data, judgment node data, connection line data, loop node data, lane node data, and annotation node data.
[0065] Optionally, a module 320 is obtained, which is specifically used to determine a training set and a validation set for each type of data in the flowchart target data set; each type of data is trained based on the training set and the validation set of each type of data to obtain a code segment corresponding to each type of data; the flowchart target code segment is obtained based on the code segment corresponding to each type of data, and the flowchart target code segment includes an entry and exit code segment, a process node code segment, a conditional statement code segment, a data transfer code segment, a loop statement code segment, a call logic code segment, and a comment code segment.
[0066] Optionally, a target code model 330 is determined, specifically for training the target code segment of the flowchart to obtain a code model; diversified data is obtained, and the code model is trained based on the diversified data to obtain the target code model.
[0067] Optionally, determine a target code model 330, specifically for acquiring the diversified data, and training the code model based on the diversified data to obtain the trained code model; optimize the trained code model to obtain the target code model.
[0068] Optionally, determine a target code model 330, which is specifically used to determine a code reference standard, wherein the code reference standard includes a naming convention, a code structure, an encoding format, and error information handling; determine whether the flowchart target code segment complies with the code reference standard; if it is determined that the flowchart target code segment does not comply with the code reference standard, manually modify the flowchart target code segment, and train the modified flowchart target code segment until the modified flowchart target code segment complies with the code reference standard, thereby obtaining the target code model.
[0069] According to one aspect of an embodiment of the present invention, an electronic device is provided.
[0070] Figure 4 Schematic diagram of the structure of an electronic device according to an embodiment of the present invention. Figure 4 As shown, the electronic device may include one or more ( Figure 4 Only one is shown in the figure) processor 102 (processor 102 may include but is not limited to a microprocessor (Microprocessor Unit, referred to as MPU) or a programmable logic device (Programmable logic device, referred to as PLD)) and a memory 104 for storing data. In an exemplary embodiment, the electronic device may also include a transmission device 106 and an input / output device 108 for communication functions. It can be understood by those skilled in the art that Figure 4 The structure shown is for illustration only and does not limit the structure of the above terminal device. Figure 4 More or fewer components as shown, or with Figure 4 Equivalent functions or comparisons shown Figure 4 A different configuration with more features is shown.
[0071] The memory 104 can be used to store computer programs, for example, software programs and modules of application software, such as the computer program corresponding to the method for generating code based on the GPT flowchart in the embodiment of the present invention. The processor 102 executes various functional applications and data processing by running the computer program stored in the memory 104, that is, to implement the above method. The memory 104 may include a high-speed random access memory, and may also include a non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some examples, the memory 104 may further include a memory remotely arranged relative to the processor 102, and these remote memories may be connected to the terminal device via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0072] The transmission device 106 is used to receive or send data via a network. The specific example of the above network may include a wireless network provided by a communication provider of the switching device. In one example, the transmission device 106 includes a network adapter (Network Interface Controller, referred to as NIC), which can be connected to other network devices through a base station so as to communicate with the Internet. In one example, the transmission device 106 can be a radio frequency (RF) module, which is used to communicate with the Internet wirelessly.
[0073] The present invention provides a non-transitory computer-readable storage medium storing computer instructions, wherein the computer instructions are used to enable the computer to execute a method for generating codes from a flowchart based on GPT.
[0074] The applicant of the present invention has made a detailed explanation and description of the implementation examples of the present invention in conjunction with the drawings in the specification. However, those skilled in the art should understand that the above implementation examples are only preferred implementation schemes of the present invention, and the detailed description is only to help readers better understand the spirit of the present invention, but not to limit the scope of protection of the present invention. On the contrary, any improvements or modifications based on the inventive spirit of the present invention should fall within the scope of protection of the present invention.
[0075] In addition, each functional unit in each embodiment of the present invention may be integrated into a processing module, or each unit may exist physically separately, or two or more units may be integrated into one module. The above-mentioned integrated module may be implemented in the form of hardware or in the form of a software functional module. If the integrated module is implemented in the form of a software functional module and sold or used as an independent product, it may also be stored in a computer-readable storage medium.
[0076] The storage medium mentioned above may be a read-only memory, a magnetic disk or an optical disk, etc. Although the embodiments of the present invention have been shown and described above, it can be understood that the above embodiments are exemplary and cannot be understood as limiting the present invention. A person of ordinary skill in the art may change, modify, replace and modify the above embodiments within the scope of the present invention.
[0077] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the embodiments of the present invention, rather than to limit them. Although the present invention has been described in detail with reference to the above embodiments, those skilled in the art should understand that they can still modify the technical solutions recorded in the above embodiments, or replace some of the technical features therein by equivalents; and these modifications 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. Any changes or replacements that can be easily thought of by those skilled in the art within the technical scope disclosed in the present invention should be covered within the protection scope of the present invention.
Claims
1. A method for generating code from flowcharts based on GPT, It is characterized in that include: S1, obtaining open source project code, and pre-training the GPT model based on the open source project code to obtain the pre-trained GPT model; S2, obtaining a flowchart target data set, and obtaining a flowchart target code segment based on the flowchart target data set; S3, introducing the flowchart target code segment into the pre-trained GPT model, training the flowchart target code segment, and obtaining a target code model; S4: When a first code segment is input into the target code model, a context code segment based on the first code segment is output.
2. The method for generating code based on GPT flowchart according to claim 1, It is characterized in that The flowchart target data set includes start / end node data, process node data, judgment node data, connection line data, loop node data, lane node data, and annotation node data.
3. The method for generating code based on GPT flowchart according to claim 2, It is characterized in that Obtaining a flowchart target code segment based on the flowchart target data set includes: Determine a training set and a validation set for each type of data in the target data set of the flowchart; Training each type of data based on the training set and the validation set of each type of data to obtain a code segment corresponding to each type of data; The flowchart target code segment is obtained based on the code segment corresponding to each type of data, and the flowchart target code segment includes entry and exit code segments, process node code segments, conditional statement code segments, data transfer code segments, loop statement code segments, call logic code segments, and comment code segments.
4. The method for generating code based on GPT flowchart according to claim 1, It is characterized in that Training the flow chart target code segment to obtain a target code model includes: Training the target code segment of the flowchart to obtain a code model; Diversified data is obtained, and the code model is trained based on the diversified data to obtain the target code model.
5. The method for generating code based on GPT flowchart according to claim 4, It is characterized in that Acquiring diversified data, and training the code model based on the diversified data to obtain the target code model, including: Acquire the diversified data, and train the code model based on the diversified data to obtain the trained code model; The trained code model is optimized to obtain the target code model.
6. The method for generating code based on GPT flowchart according to claim 5, It is characterized in that Optimizing the trained code model to obtain the target code model includes: Determine code reference standards, including naming conventions, code structure, encoding format, and error message handling; Determining whether the flowchart target code segment complies with the code reference standard; When it is determined that the flowchart target code segment does not meet the code reference standard, the target code model is obtained by manually modifying the flowchart target code segment and training the modified flowchart target code segment until the modified flowchart target code segment meets the code reference standard.
7. A system for generating codes from flowcharts based on GPT, It is characterized in that include: A GPT model training module is used to obtain open source project code and pre-train the GPT model based on the open source project code to obtain the pre-trained GPT model; An obtaining module, used to obtain a flowchart target data set, and obtain a flowchart target code segment based on the flowchart target data set; Determine a target code model, which is used to introduce the flowchart target code segment into the pre-trained GPT model, train the flowchart target code segment, and obtain a target code model; A code generation module is used for outputting a context code segment based on the first code segment when the first code segment is input into the target code model.
8. The system for generating codes based on GPT flowchart according to claim 7, It is characterized in that The flowchart target data set includes start / end node data, process node data, judgment node data, connection line data, loop node data, lane node data, and annotation node data.
9. An electronic device, It is characterized in that include: at least one processor; as well as a memory communicatively connected to the at least one processor; wherein, The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to perform the method according to any one of claims 1 to 6.
10. A non-transitory computer-readable storage medium storing computer instructions, It is characterized in that The computer instructions are used to cause the computer to execute the method according to any one of claims 1 to 6.
