Code generation model training methods, devices and equipment
By generating a directed graph of call dependencies and building training samples to train the initial model, the shortcomings of existing code generation models in understanding complex code library dependencies and supporting the entire lifecycle are addressed, resulting in more accurate and adaptable code generation.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-07-14
- Publication Date
- 2026-04-03
AI Technical Summary
Existing code generation models struggle to understand the dependencies of complex, large-scale codebases and cannot support end-to-end intelligent support throughout the entire software development lifecycle, especially in handling cross-module and cross-project dependencies.
By generating a directed graph of call dependencies, development data is obtained, training samples are constructed, and the initial model is trained using this data to generate a code generation model.
It enhances the accuracy and scenario adaptability of the generated code, making the generated code more in line with actual needs and standards, and supports intelligent processing throughout the entire software development lifecycle.
Smart Images

Figure CN120873595B_ABST
Abstract
Description
Technical Field
[0001] This disclosure relates to the field of computer technology, particularly to code generation and large models, and can be used in application scenarios such as software development assistance. Specifically, it relates to code generation model training methods, devices, and equipment. Background Technology
[0002] With the rapid development of large-scale language modeling technology, code generation tools have played a vital role in software development, particularly demonstrating high efficiency in code completion and problem solving. However, current code models still struggle to understand complex dependencies in large-scale codebases and do not fully support the entire lifecycle from requirement development to code iteration. Summary of the Invention
[0003] This disclosure provides a method, apparatus, and device for training a code generation model.
[0004] According to a first aspect of this disclosure, a method for training a code generation model is provided, comprising: generating a call dependency directed graph based on dependency relationships from code files; obtaining development data from the code files and the call dependency directed graph; the development data including at least: code requirements, issue records, commit records, and review records; constructing training samples from the development data and code files; and training an initial model using the training samples to obtain a code generation model.
[0005] According to a second aspect of this disclosure, a code generation method is provided, comprising: obtaining code requirements; inputting the code requirements into a code generation model to obtain code results output by the code generation model based on development data; wherein the code generation model is trained by the method described in the first aspect above.
[0006] According to a third aspect of this disclosure, a code generation model training apparatus is provided, comprising: a dependency analysis module for generating a call dependency directed graph based on dependency relationships according to code files; a data retrieval module for acquiring development data according to the code files and the call dependency directed graph; the development data including at least: code requirements, issue records, commit records and review records; a sample construction module for constructing training samples according to the development data and code files; and a model training module for training an initial model using the training samples to obtain a code generation model.
[0007] According to a fourth aspect of this disclosure, a code generation apparatus is provided, comprising: a requirement acquisition module for acquiring code requirements; and a code generation module for inputting the code requirements into a code generation model to obtain code results output by the code generation model based on development data; wherein the code generation model is trained by the method described in the first aspect above.
[0008] According to a fifth aspect of this disclosure, an electronic device is provided, 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, the instructions being executed by the at least one processor to enable the at least one processor to perform any of the methods described in the embodiments of this disclosure.
[0009] According to a sixth aspect of this disclosure, a non-transitory computer-readable storage medium is provided storing computer instructions, wherein the computer instructions are used to cause the computer to perform any of the methods according to embodiments of this disclosure.
[0010] According to a seventh aspect of this disclosure, a computer program product is provided, including a computer program that, when executed by a processor, implements any of the methods according to embodiments of this disclosure.
[0011] The solution disclosed herein can enhance the accuracy and scenario adaptability of the generated code.
[0012] It should be understood that the description in this section is not intended to identify key or essential features of the embodiments of this disclosure, nor is it intended to limit the scope of this disclosure. Other features of this disclosure will become readily apparent from the following description. Attached Figure Description
[0013] The accompanying drawings are provided to better understand this solution and do not constitute a limitation of this disclosure. Wherein:
[0014] Figure 1 This is a flowchart illustrating the code generation model training method according to an embodiment of the present disclosure;
[0015] Figure 2 This is a flowchart illustrating a code generation method according to an embodiment of the present disclosure;
[0016] Figure 3 This is a schematic diagram of the structure of a code generation model training apparatus according to an embodiment of the present disclosure;
[0017] Figure 4 This is a schematic diagram of the structure of a code generation apparatus according to an embodiment of the present disclosure;
[0018] Figure 5 This is a schematic diagram of a scenario for a code generation model training method according to an embodiment of the present disclosure;
[0019] Figure 6 This is a schematic diagram of a scenario based on the code generation method according to an embodiment of the present disclosure;
[0020] Figure 7 This is a structural diagram of an electronic device used to implement the code generation model training method of the embodiments of this disclosure. Detailed Implementation
[0021] The exemplary embodiments of this disclosure are described below with reference to the accompanying drawings, including various details of the embodiments to aid understanding, and should be considered merely exemplary. Therefore, those skilled in the art will recognize that various changes and modifications can be made to the embodiments described herein without departing from the scope of this disclosure. Similarly, for clarity and brevity, descriptions of well-known functions and structures are omitted in the following description.
[0022] In this document, the term "and / or" merely describes the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can represent three cases: A alone, A and B simultaneously, and B alone. The term "at least one" in this document indicates any combination of at least two of a plurality of elements. For example, including at least one of A, B, and C can mean including any one or more elements selected from the set consisting of A, B, and C. The terms "first" and "second" in this document refer to and distinguish between multiple similar technical terms, not to restrict the order or to limit there to only two. For example, "first feature" and "second feature" refer to two categories / two features; the first feature can be one or more, and the second feature can also be one or more.
[0023] Furthermore, to better illustrate this disclosure, numerous specific details are set forth in the following detailed description. Those skilled in the art will understand that this disclosure can be practiced without certain specific details. In some instances, methods, means, components, and circuits well known to those skilled in the art have not been described in detail in order to highlight the main points of this disclosure.
[0024] Before introducing the technical solutions of the embodiments of this disclosure, the technical terms that may be used in this disclosure will be further explained:
[0025] Full lifecycle refers to the entire process from requirements analysis to design, development, testing, deployment, maintenance, and iterative updates of a software project. This concept emphasizes covering all stages of the software product and ensuring that data, activities, and decisions at each stage work together to achieve the project's ultimate goal. In this disclosure, full lifecycle specifically refers to the code generation model supporting the software development process throughout all stages from initial requirements to subsequent feature iterations.
[0026] In related technologies, with the rapid development of large-scale language model technology, code generation and assistance tools have achieved remarkable results in the field of software development. These tools, with their powerful language understanding and generation capabilities, provide developers with convenient code completion and problem-solving functions, significantly improving development efficiency. However, with the diversification of user needs and the increasing complexity of projects, current code models still have significant limitations in practical applications, especially in the following aspects: First, insufficient understanding of complex dependencies within large-scale codebases limits their effectiveness in handling cross-module and cross-project dependencies; second, a lack of support for code evolution throughout the entire software development process, failing to provide end-to-end intelligent support from requirements analysis to code implementation and feature iteration. These technological bottlenecks restrict the possibility of code models developing to higher levels, urgently requiring an intelligent code assistant that can start from requirements, participate in the functional expansion and iteration of software projects, and adapt to diverse scenarios such as game development and web design, providing developers and end users with truly intelligent and efficient code solutions.
[0027] In order to at least partially solve one or more of the above-mentioned problems and other potential problems, this disclosure proposes a code generation model training method that can enhance the accuracy and scenario adaptability of the generated code.
[0028] This disclosure provides a method for training a code generation model. Figure 1 This is a flowchart illustrating a code generation model training method according to an embodiment of the present disclosure. This method can be applied to a code generation model training device. The code generation model training device is located in an electronic device. This electronic device includes, but is not limited to, fixed devices and / or mobile devices. For example, fixed devices include, but are not limited to, servers, which can be cloud servers or ordinary servers. Mobile devices include, but are not limited to, software development aids, which can be mobile phones, tablets, vehicle terminals, etc. In some possible implementations, the code generation model training method can also be implemented by a processor calling computer-readable instructions stored in memory. Figure 1 As shown, the training method for this code generation model includes:
[0029] S101. Based on the code file, generate a directed graph of call dependencies according to the dependency relationships;
[0030] S102. Obtain development data based on code files and the directed graph of call dependencies; development data should include at least: code requirements, issue records, commit records, and review records;
[0031] S103. Construct training samples based on development data and code files;
[0032] S104. Train the initial model using training samples to obtain the code generation model.
[0033] In this context, the code file refers to the source code file within the project. In this embodiment, the code file can be written in a programming language and contains information such as the program's logic, algorithms, variables, and functions.
[0034] In this context, dependency refers to the calling and usage relationships within a code file. In this embodiment, dependency can refer to the calling and dependency relationships between functions, classes, and modules within a code file.
[0035] In this context, the call dependency directed graph refers to a directed graph generated based on dependency relationships. In this embodiment, the nodes of the call dependency directed graph represent code files or modules, the edges represent calls or dependencies, and the direction represents the direction of the dependency.
[0036] In this embodiment of the disclosure, the code file can first be analyzed using an analysis tool to extract dependencies. Exemplarily, the analysis tool can be a static analysis or semi-static analysis tool. Subsequently, functions, classes, and modules in the code file can be used as nodes in a graph, and dependencies as edges, to generate a directed graph structure using an algorithm, thereby constructing a call dependency directed graph. Exemplarily, an adjacency matrix or adjacency list can be constructed as the call dependency directed graph. The above is merely an illustrative example and is not intended to limit all possible cases for generating a call dependency directed graph; it is simply not exhaustive.
[0037] In this context, development data refers to all data generated during the software development process, from requirements analysis to code delivery. In this embodiment, development data includes at least code requirements, issue logs, commit logs, and review logs.
[0038] In this context, code requirements refer to the functional goals or design requirements of software development. In this embodiment of the disclosure, code requirements can be a requirements document.
[0039] In this context, the issue log refers to defects, errors, or technical problems encountered during the development process. In this embodiment of the disclosure, the issue log may be an issue document.
[0040] In this context, a commit record refers to the record of code submissions made by developers within a version control system. In this embodiment, the commit record can be a commit document document detailing feature implementations and modifications. Specifically, the commit record may include timestamps, code change details, etc.
[0041] In this context, review records refer to feedback and suggestions during the code review process. In this embodiment, review records can be pull request documents generated during the review and merging process. Specifically, review records may include code quality issues, optimization suggestions, etc.
[0042] In this embodiment of the disclosure, development data can be obtained from multiple sources based on code files and a directed graph of call dependencies. For example, code requirements can be obtained from a requirements tracking and management system, issue records can be extracted from a defect management tool, commit records can be extracted from a version control system, and review records can be extracted from a code review tool. Subsequently, data from different sources can be integrated and cleaned to ensure a consistent data format. Finally, the obtained development data can be associated with specific code files by analyzing commit records or other related information. The above is merely an illustrative example and does not limit the possibilities of obtaining development data; it is simply not exhaustive.
[0043] Training samples refer to the data used to train the code generation model. In this embodiment of the disclosure, training samples may include input and output pairs.
[0044] In this embodiment, information such as requirements and problem records can be extracted from development data as input, and corresponding code snippets can be extracted from code files as output. Specifically, the correct matching of sample input and output can be ensured based on the correspondence between requirements and code implementation. Subsequently, the samples can be formatted and denoised to transform them into a model-acceptable format and filter out unnecessary or repetitive data. The above is merely an illustrative example and does not limit the possibilities for constructing training samples; it is simply not exhaustive.
[0045] Here, the initial model refers to an untrained model. In this embodiment of the disclosure, the initial model can be selected as a base model suitable for the code generation task.
[0046] Here, the code generation model refers to a model trained specifically for code generation tasks. In this embodiment of the disclosure, the code generation model can generate code files based on the input code requirements.
[0047] In this embodiment of the disclosure, training sample data can first be input into an initial model, and the model can be optimized using a supervised learning method. For example, supervised training can be performed by minimizing the difference between the predicted code snippets and the actual code. Subsequently, the model performance can be evaluated using a validation set, and the model parameters or training strategy can be adjusted based on the evaluation results. The above is merely an illustrative example and is not intended to limit the possibilities of obtaining all possible code generation models; it is simply not exhaustive.
[0048] The technical solution of this disclosure transforms the dependency relationships between code files into a graph structure, which can intuitively capture the call relationships between code and modules, thereby generating training samples that are more in line with real-world environments. By introducing full lifecycle data, additional development background and historical information of the code are provided, enabling the model to learn contextual information such as code requirements and problem records, thereby generating code that is more in line with actual needs and specifications. Constructing samples using full lifecycle data enhances the accuracy and scenario adaptability of the code generated by the model, while also enabling the model to learn the context of code generation. Training the model with full lifecycle data results in a code generation model that generates code that is more in line with requirements and specifications.
[0049] In some embodiments, generating a directed graph of call dependencies based on dependencies according to code files includes: extracting dependencies from code files to generate dependency data; and constructing a directed graph based on the dependency data to generate a directed graph of call dependencies.
[0050] In this context, dependency data is a structured representation of the dependencies between modules, functions, or classes in a code file. In this embodiment, the dependency data can be a parsable structured data format.
[0051] In this embodiment, a code analysis tool can be used to read the code file first. Then, based on the output of the code analysis tool, the call relationships between functions, modules, and classes are detected. Finally, these relationships can be organized into dependency data. The above is merely an illustrative example and is not intended to limit all possible scenarios for generating dependency data; it is simply not exhaustive.
[0052] In this embodiment, code files or code fragments such as functions, modules, and classes within code files can first be mapped to nodes. Then, edges between nodes can be constructed based on dependency data. For example, the direction of an edge can represent the direction of a dependency. Finally, a graph data structure can be used to store the generated directed graph. The above is merely an illustrative example and is not intended to limit all possible cases of generating a directed graph of call dependencies; it is simply not exhaustive.
[0053] Thus, by extracting dependencies, complex call relationships in the code can be transformed into operable structured data, clearly representing the logical connections within and between code files. Constructing directed graphs allows for a visual representation of dependencies between code modules or functions, thereby helping subsequent models understand the semantic relationships between code entities.
[0054] In some embodiments, the process of extracting dependencies from code files and generating dependency data includes: generating code structure data based on syntax parsing of the code files; extracting dependencies from the code structure data and generating dependency data.
[0055] Here, code structure data refers to the structured representation extracted from a code file after syntax parsing, which can be used to describe the core components of the code and their hierarchical relationships. In the embodiments of this disclosure, code structure data is an abstract representation of the code file, typically displayed in a tree or graph structure.
[0056] In this embodiment, the code file can be read first, and then parsed using a syntax parsing tool or framework. For example, file input / output (I / O) operations can be used to read the source code file, and a suitable tool or framework can be selected based on the code language. Subsequently, code structure data can be automatically generated based on the output of the syntax parsing tool or framework. For example, an Abstract Syntax Tree (AST) can be generated first based on the output of the syntax parsing tool or framework, and then the structural information of the code can be extracted from the AST, and the extracted structural information can be organized into an unstructured format. The above is merely an illustrative example and is not intended to limit all possible cases of generating code structure data; it is simply not exhaustive.
[0057] In this embodiment of the disclosure, possible dependency types can first be determined based on code structure data. For example, dependency types may include function call dependencies, module import dependencies, class inheritance dependencies, and variable dependencies between functions or modules that interact through global variables or parameters. Subsequently, the code structure data can be traversed to identify the dependencies within it. For example, function call nodes can be searched in the AST to determine call relationships, inheritance structures can be searched in class definitions to extract class inheritance relationships, and module import statements can extract dependencies between modules. Finally, the collected dependency information can be organized into structured dependency data. For example, dependency data can be represented as key-value pairs, relational tables, or graph data structures. The above are merely illustrative examples and are not intended to limit all possible cases for generating dependency data; an exhaustive list is not provided here.
[0058] In this way, by parsing syntax, complex code files are abstracted into structured code structure data, which can be adapted to different programming languages and improve versatility. By extracting all possible dependencies from the code structure data, the integrity of dependency data can be ensured, while clearly showing the interactions between code modules, functions, and classes.
[0059] In some embodiments, constructing a directed graph based on dependency data to generate a call dependency directed graph includes: creating nodes based on dependency data to generate a node set; performing relationship mapping based on the node set and dependencies to generate a relationship set; and generating a call dependency directed graph based on the node set and relationship set.
[0060] Here, the node set refers to the collection of all nodes in the call dependency directed graph. In this embodiment of the disclosure, a node represents a specific entity in the code, which may include function nodes, module nodes, class nodes, and variable nodes, etc.
[0061] In this embodiment of the disclosure, all code entities, including functions, classes, modules, variables, etc., can first be extracted from the dependency data. Then, each code entity can be mapped to a node. Specifically, each node can contain additional information, such as node type, code file path, or the name of the module it resides in. The above is merely an illustrative example and is not intended to limit all possible cases for generating a set of nodes; it is simply not exhaustive.
[0062] The relationship set is the set of all edges in the directed graph of call dependencies. In this embodiment, an edge represents a dependency relationship between code entities, and each edge includes the initiator of the dependency relationship, the dependent entity, and the relationship type.
[0063] In this embodiment of the disclosure, the initiator and dependent of the dependency relationship can first be extracted from the dependency relationship data. Then, edges in the relationship set can be created based on the dependency types in the dependency relationship data. Specifically, each edge represents a dependency relationship, including a source node, a target node, and a relationship type. The above is merely an illustrative example and is not intended to limit all possible cases for generating the relationship set; it is simply not exhaustive.
[0064] In this embodiment, all nodes in the node set can first be added to the graph, and then all edges in the relation set can be used to connect the nodes to form a graph structure. Subsequently, the direction of the edges can represent the direction of the dependencies, thereby constructing a directed graph. Finally, the constructed directed graph can be saved as a structure that can be used for subsequent processing. The above is merely an illustrative example and is not intended to limit all possible cases of generating a directed graph with calling dependencies; it is simply not exhaustive.
[0065] In this way, by generating a set of nodes, code entities can be structured, providing the foundational data for constructing a directed graph of call dependencies and clearly defining the code entities. By generating a set of relationships, the dependencies between code entities can be accurately represented, supporting different relationship types and adapting to various application scenarios. By generating a directed graph of call dependencies, code dependencies can be displayed, making it easier for developers to understand and optimize the code.
[0066] In some embodiments, obtaining development data based on code files and a directed graph of call dependencies includes: performing topological sorting on the code files according to the directed graph of call dependencies based on logical order to generate a list of code entries; concatenating the code files according to the list of code entries to generate code data; and obtaining development data corresponding to the code data.
[0067] Here, the code entry list refers to an ordered list that shows the order in which code depends on other code segments. In this embodiment of the disclosure, the code entry list can arrange code files or code fragments according to the logical order of their dependencies.
[0068] In this embodiment, nodes and directed edges can first be extracted from the call dependency directed graph and sorted using a topological sorting algorithm. For example, code entity nodes that do not depend on other nodes can be identified first, added to the code entry list, and then removed from the graph. This process is repeated until no nodes remain in the graph. Finally, the resulting code entry list is stored and output. The above is merely an illustrative example and is not intended to limit the possibilities for generating the code entry list; it is simply not exhaustive.
[0069] Here, code data refers to the overall representation of the specific implementation or combination result of the code entities corresponding to the code entry list. In this embodiment of the disclosure, code data is the complete code content generated by concatenating the code files or code fragments in the code entry list.
[0070] In this embodiment, the corresponding code files or code snippets can be loaded one by one according to the order in the code entry list. Then, the contents of the code files can be concatenated according to the order in the code entry list. Specifically, the concatenated code content can be saved as code data, which can be in string format or other structured formats. The above is merely an illustrative example and is not intended to limit all possible cases of generating code data; it is simply not exhaustive.
[0071] In this embodiment, development data related to the code data can be extracted first. For example, relevant requirement items can be matched based on the functional characteristics of the code from a requirement management system; defect or issue records related to code implementation can be obtained from a defect tracking system; the commit history corresponding to the code can be extracted from a version control system; and review comments or suggestions related to the code can be obtained from code review tools. Subsequently, the development data can be associated with the corresponding code data. For example, functional requirements of the code can be bound to code files, or defect repair records can be associated with corresponding modifications in the code. Finally, the acquired full lifecycle data can be integrated to construct the association result between the code and the development data. The above is merely an illustrative example and does not limit the possibilities for obtaining all possible development data corresponding to the code data; it is simply not exhaustive.
[0072] Thus, by generating a list of code entries, the dependency hierarchy of code entities can be clearly defined. Simultaneously, the topological sorting mechanism ensures ordered dependencies and avoids issues such as circular dependencies. Code concatenation generates complete code data that conforms to the dependency order, guaranteeing the logical correctness of the code data. By acquiring development data, the entire lifecycle of data, including requirements, commit records, and issue logs, can be linked with the code data, improving the completeness of the code's background information.
[0073] In some embodiments, constructing training samples based on development data and code files includes: generating an event list based on the development data and temporal relationships; cross-aggregating the event list and code data to generate code information units; and constructing training samples based on the code information units.
[0074] The event list refers to a collection of events organized chronologically based on development data. In this embodiment, the event list can represent various events that occur during code development and their sequential relationships. Specifically, each event can correspond to a specific development activity or record.
[0075] In this embodiment, events such as requirements, issue records, submission records, and review records, along with their timestamps, can first be extracted from development data. Then, the events can be sorted by timestamps to generate an ordered event list. Specifically, the chronological order of the events must be ensured during the sorting process. Finally, relevant attributes can be added to each event. For example, attributes such as event type, associated code module or file, and developer information can be added to each event. The above is merely an illustrative example and does not represent all possible scenarios for generating the event list; it is simply not exhaustive.
[0076] The code information unit is the smallest data unit generated by cross-aggregating the event list and code data. In this embodiment of the disclosure, the code information unit can be used to represent the association between a code segment and its associated event information.
[0077] In this embodiment of the disclosure, the code data can first be divided into multiple segments according to logical units. For example, each class can be divided into a segment, and / or each function into a segment, and / or each module into a segment, according to class and / or function and / or module. Subsequently, each event in the event list can be traversed to match the associated code segment. For example, commits can be associated with specific code segments through version control records, requirement events can be associated with code segments through requirement documents or comment content, and issue events or review events can be matched to code segments through file paths or related identifiers in the records. Finally, each code segment and its associated events can be integrated into a code information unit. Specifically, each code information unit may include code segment content, time-related event information, and code context information. The above is merely an illustrative example and is not intended to limit all possible cases for generating code information units; it is simply not exhaustive.
[0078] In this embodiment, input features can first be extracted from event information and context in the code information unit. For example, code requirements, issue records or review records, or submission records can be used as input. Subsequently, output features can be extracted from code snippets in the code information unit. For example, specific code implementation content can be used as output. Finally, the input and output can be combined into training samples. Specifically, the training samples can be formatted into a form acceptable to the model, according to its needs. The above are merely illustrative examples and are not intended to limit all possible scenarios for constructing training samples; they are not exhaustive.
[0079] Thus, by generating an event list, the chronological order of events during code development can be clearly defined, providing a panoramic view of development behavior and facilitating the cross-aggregation of code data and event information. By generating code information units, the association between code content and background information can be established, supporting complex analysis processes. By constructing training samples containing code content and its development background information, the contextual awareness of the samples can be improved, enhancing the model's generative capabilities.
[0080] In some embodiments, constructing training samples based on code information units includes: extracting the key entities in the requirement description of the event list and the node associations of the call dependency directed graph; automatically generating cross-module context constraint description text when the code information unit involves multiple associated nodes; and combining the constraint description text as a prefix prompt with the corresponding code snippet to form reinforcement samples.
[0081] Among them, the key entity is the core information extracted from the requirement description in the event list. In this embodiment of the disclosure, the key entity can directly reflect the key concepts or objects of the function, goal or operation.
[0082] In this context, node association refers to the mapping relationship between nodes and key entities in the directed graph of call dependencies. In this embodiment, node association clarifies how a specific code node implements the functionality related to the requirements.
[0083] In this embodiment, natural language processing technology can be used first to extract key entities from the requirement description. For example, an entity recognition algorithm can be used to identify core nouns, terms, or actions in the requirement. Subsequently, nodes in the call dependency directed graph can be traversed, and the functional descriptions or annotations of the nodes can be matched with key entities to determine the association between key entities in the requirement and code nodes. The above is merely an illustrative example and is not intended to limit all possible cases of extracting node associations; it is simply not exhaustive.
[0084] In this context, associated nodes are sets of nodes in the call dependency directed graph that are related to code information units. In this embodiment, associated nodes are directly or indirectly related to key entities in the requirements and may participate in the implementation of the requirements.
[0085] The constraint description text refers to text automatically generated based on the interaction relationships between associated nodes. In this embodiment of the disclosure, the constraint description text can be used to describe cross-module context constraints, which helps the model understand the logic and dependencies involved in the code snippets.
[0086] In this embodiment, the number of associated nodes can be detected first. When associated nodes involve multiple modules or functions, constraint description text is generated. Further, when generating constraint description text, the interaction relationships between associated nodes can be analyzed first. For example, interaction relationships can include call relationships, data transfer, dependency conditions, etc. Subsequently, natural language text describing cross-module interactions can be generated based on the aforementioned dependency relationships. For example, the constraint description text could be: "The data query function depends on the database access interface of a certain module and uses the caching optimization of another module." The above is merely an illustrative example and is not intended to limit all possible cases for generating constraint description text; it is simply not exhaustive.
[0087] In this embodiment, the prefix prompt places the constraint description text as prompt information before the code snippet to guide the model in understanding the context and functional goals of the code snippet. In this disclosure, the prefix prompt can provide the model with additional contextual information, emphasizing the semantic background of the code snippet.
[0088] The augmented samples are training samples generated by combining prefix prompts with code snippets. In this embodiment, the augmented samples can be used to improve the model's ability to handle complex contexts when generating and understanding code.
[0089] In this embodiment of the disclosure, the constraint description text can first be converted into natural language prompts and used as a prefix for the code snippet. Subsequently, the prefix prompts and the code snippet can be combined into a pair of input-output samples. Specifically, the reinforcement samples can also be formatted into a form acceptable to the model, according to the model's needs. The above is merely an illustrative example and is not intended to limit all possible combinations of reinforcement samples; it is simply not exhaustive.
[0090] Thus, by extracting the relationships between key entities and nodes, the core information in the requirements and the implementation relationships of code modules can be clearly identified, while also supporting cross-module dependency discovery. By automatically generating constraint description text, accurate contextual information can be provided to the model, especially in cross-module scenarios, helping the model understand the complex background of code snippets. By combining reinforcement samples, the model's contextual understanding ability can be significantly enhanced, while also improving its multi-task processing capabilities.
[0091] In some embodiments, constructing training samples based on code information units includes: extracting metadata information based on code information units; annotating the code information units with content based on the metadata information to generate a set of code snippets; and constructing training samples based on the metadata information and the set of code snippets.
[0092] Metadata information refers to additional information or background data related to code information units. In this embodiment of the disclosure, metadata information can be used to describe the attributes of a code fragment and its development background, and may include code attributes, context information, development background, and time-related information, etc.
[0093] In this embodiment, attribute metadata of the code can first be extracted from the code information unit. For example, attribute metadata may include filename, module name, class name, function name, etc. Subsequently, the call dependencies of the code information unit can be analyzed to extract context-related metadata. For example, context-related metadata may include input / output relationships, dependent modules, etc. Finally, background information can be extracted from the development data. For example, background information may include requirement descriptions, review comments, and submission records, etc. The above are merely illustrative examples and are not intended to limit all possible scenarios for extracting metadata information; they are simply not exhaustive.
[0094] Content annotation refers to annotating the code content in code information units based on metadata information to generate structured or annotated information.
[0095] Here, the code snippet set refers to a group of structured or processed code snippets generated based on content annotation. In this embodiment of the disclosure, the code snippets in the code snippet set are a collection of code content extracted and annotated from code information units.
[0096] In this embodiment of the disclosure, metadata information can be used to add annotations to code snippets. For example, the functionality of a code snippet can be annotated based on requirement information or context description; the dependent modules or call relationships of a code snippet can be annotated based on metadata information; and the input / output data types or formats of a code snippet can also be annotated based on metadata information. The above are merely illustrative examples and are not intended to limit all possible cases for generating a set of code snippets; they are simply not exhaustive.
[0097] In this embodiment of the disclosure, training samples can be constructed based on the functional descriptions, dependencies, and code content annotated in the code snippet set. For example, functional descriptions, context information, dependencies, etc., can be used as input, and code snippet content as output to construct training samples. Specifically, the training samples can also be formatted into a form acceptable to the model, according to the model's needs. The above are merely illustrative examples and are not intended to limit all possible cases of constructing training samples; they are simply not exhaustive.
[0098] Thus, by extracting metadata, we can describe the attributes, context, and development background of the code, providing support for content annotation. By annotating code information units, we can supplement code snippets with functional descriptions, dependencies, and other information, making the code snippets more structured. Furthermore, the final collection of code snippets can be stored in a structured manner for convenient subsequent processing. By constructing training samples, we can combine code snippets with their background information, significantly improving the accuracy and contextual adaptability of the model-generated code.
[0099] In some embodiments, content annotation includes: identifying boundary nodes of the call-dependent directed graph; automatically injecting adversarial examples simulating abnormal changes in boundary nodes; generating corresponding correction labels based on modification comments in the review record; and constructing fault-tolerant training sample pairs.
[0100] In this context, a boundary node refers to a node located at the boundary of cross-module or system interaction in the directed graph of call dependencies. In this embodiment, the boundary node acts as a bridge, serving as a key point for inter-module calls, data transfer, or functional coupling.
[0101] In this embodiment, the nodes in the call dependency directed graph can be traversed first to determine the context position and call relationship of the nodes. Then, cross-module call boundaries between nodes and nodes receiving external data can be marked. Next, the marked nodes can be identified to determine boundary nodes. For example, nodes that are associated with multiple modules or external system interfaces, directly process input and output data, and whose abnormalities affect the overall functionality can be identified as boundary nodes. Finally, the identified boundary nodes can be saved as a list. The above is merely an illustrative example and does not limit the possibilities for identifying boundary nodes; it is simply not exhaustive.
[0102] Adversarial examples refer to data samples designed to test the robustness and fault tolerance of a model by simulating anomalies or changes in boundary conditions. In this embodiment of the disclosure, adversarial examples intentionally include unexpected inputs or conditions, which can be used to detect and improve the model's ability to handle boundary situations.
[0103] In this embodiment, possible abnormal inputs or extreme variations can be designed based on the functionality of the boundary nodes. For example, illegal inputs such as null values, negative values, and excessively long strings can be designed; extreme pressures such as high-frequency calls and large data volume inputs can also be designed; and module dependency variations such as cross-module return errors or unexpected values can also be involved. Subsequently, abnormal input data or code variation samples can be created for each boundary node. Finally, the generated adversarial samples can be injected into the code snippet set to form an abnormal dataset, which is then used as the adversarial samples. The above is merely an illustrative example and does not constitute a limitation on all possible cases of injecting adversarial samples; it is simply not exhaustive.
[0104] In this context, the correction label refers to a label generated based on the modification comments in the review record. In this embodiment of the disclosure, the correction label can clearly indicate the parts of the code that need optimization or correction, and provide suggestions or target guidance.
[0105] The fault-tolerant training sample pairs are training data constructed from code snippets and corresponding correction labels. In this embodiment, the fault-tolerant training samples can be used to train the model's ability to handle errors or optimize code.
[0106] In this embodiment, specific modification suggestions can first be extracted from code review comments, and the problem description and solution can be recorded. Then, correction tags can be created based on the review comments to clarify the problem and optimization goals. Finally, sample pairs can be constructed using the correction tags and the original code snippets. Exemplarily, the sample pairs can use the original code snippets or adversarial examples as input and the corrected code or optimization suggestions as output. The above is merely an illustrative example and does not limit the scope of all possible cases for constructing fault-tolerant training sample pairs; it is simply not exhaustive.
[0107] Thus, identifying boundary nodes helps to clarify key points of interaction across modules or systems. Injecting adversarial examples can simulate real-world development scenarios, closely reflecting potential problems during development, thus improving the model's adaptability to real-world situations and enabling it to better handle boundary conditions and anomalies. Generating corrected labels and fault-tolerant training sample pairs allows for more precise location and resolution of code issues, while also generating more optimized code and solutions.
[0108] In some embodiments, obtaining development data includes: parsing the timestamps in the commit records and the node change records of the call dependency directed graph; dynamically generating a code evolution path timeline based on the mapping relationship between the topology sorting results and the timestamps; and anchoring the issue records and review records to the corresponding code nodes according to the timeline to construct a lifecycle data graph with version tags.
[0109] A timestamp is a time stamp that marks the specific time when each code change occurs. In this embodiment of the disclosure, a timestamp can be used to represent the time node of a code version or change event, and to track the evolution of the code.
[0110] In this context, the node change record refers to the change history data of each code node in the call dependency directed graph. In this embodiment, the node change record can describe the change information of any node at different points in time, and may include change time, change type, change content, and committer information, etc.
[0111] In this embodiment, the code files or modules involved in the commit record can first be parsed and mapped to specific code nodes in the call dependency directed graph. Subsequently, the change history of each code node can be recorded. Exemplarily, the change history may include timestamps, change content, change descriptions, etc. The above is merely an illustrative example and is not intended to limit all possible scenarios for parsing change records; it is simply not exhaustive.
[0112] The time-series chain is a code evolution path generated based on timestamps and topological sorting. In this embodiment, the time-series chain can be a chain of changes to code nodes during the development process, describing them in chronological order. It can dynamically present the evolution of code from the initial version to the final version.
[0113] In this embodiment, the code nodes can first be topologically sorted according to the directed graph of call dependencies. Then, the change records of each code node are sorted according to their timestamps to form its temporal evolution path, and the evolution paths of all code nodes are integrated to form an overall temporal chain. Specifically, the temporal chain can be dynamically updated as new commit records are generated to ensure that the latest change path is recorded. The above is merely an illustrative example and does not constitute a limitation on all possible cases for generating a code evolution path temporal chain; it is simply not exhaustive.
[0114] The lifecycle data graph is a data visualization generated by anchoring development data such as issue records and review records to code nodes in a chronological chain. In this embodiment, the lifecycle data graph is a panoramic view of the code throughout its lifecycle.
[0115] In this embodiment, issue records and review records can be associated with corresponding nodes in a timeline based on timestamps and the evolution path of code nodes. Subsequently, code nodes and their change records, issue records and their timestamps and descriptions, and review records and their modification suggestions can be integrated to generate a lifecycle data graph. The above is merely an illustrative example and does not constitute a limitation on all possible scenarios for constructing a version-tagged lifecycle data graph; it is simply not exhaustive.
[0116] Thus, by parsing the timestamps and node change records in the commit history, a complete historical data of code changes can be displayed, constructing a systematic change history and improving change traceability. By generating a timeline chain, the historical evolution of the code from its initial state to the current version can be shown. By constructing a lifecycle data graph, change records, issue records, and review records can be integrated to provide a panoramic view of the code throughout its lifecycle.
[0117] In some embodiments, training an initial model using training samples includes: dynamically extracting subgraph structures associated with the current training samples from a call-dependent directed graph; converting the subgraph structures into attention constraint matrices as prior masks for the encoder of the initial model; performing cross-modal attention interaction between the lifecycle event sequence and the subgraph node sequence to generate joint feature representations; and dynamically adjusting the weight distribution strategy of the position encoding based on the joint feature representations so that the initial model prioritizes topologically adjacent nodes.
[0118] Here, the subgraph structure refers to a portion of the dependency graph related to the code nodes in the training sample, dynamically extracted from the call dependency directed graph based on the current training sample. In this embodiment, the subgraph structure can represent the code nodes involved in the current training sample and their upstream and downstream dependencies in the call dependency directed graph.
[0119] In this embodiment of the disclosure, code nodes related to the call dependency directed graph can first be extracted from the training samples. Then, related nodes and their dependencies can be extracted from the call dependency directed graph, centered on the current code node. For example, all direct or indirect callers of the node can be considered as upstream nodes, and all direct or indirect callees of the node as downstream nodes. Next, a subgraph structure can be extracted based on the upstream and downstream nodes. Specifically, during training, the related subgraph structure is re-extracted whenever a new training sample is switched to. The above is merely an illustrative example and is not intended to limit all possible cases of subgraph structure extraction; it is simply not exhaustive.
[0120] The attention constraint matrix, generated based on the subgraph structure, is used to limit the range of attention distribution during the encoding process. In this embodiment, the attention constraint matrix can guide the model to prioritize nodes related to the current node in the topology graph.
[0121] The encoder is the core component of the model, capable of converting input data into a high-dimensional feature representation. In this embodiment, the encoder may be based on a Transformer framework.
[0122] The prior mask is a constraint matrix generated based on prior knowledge, used to limit the range of attention distribution in the encoder. In this embodiment, the prior mask can be generated based on the subgraph structure, which can suppress attention flow between irrelevant nodes and improve the model's attention efficiency.
[0123] In this embodiment, an initial attention matrix can be created first. Exemplarily, the initial attention matrix can be created based on the number of nodes in the subgraph structure. Subsequently, each edge in the subgraph can be traversed, and the matrix values can be filled according to the corresponding dependencies. Finally, in the multi-head attention mechanism of the encoder, the attention constraint matrix is used as a mask, thereby allowing information interaction between nodes with attention flow while masking information flow between unrelated nodes. The above is merely an illustrative example and is not intended to limit all possible cases of transforming the attention constraint matrix; it is simply not exhaustive.
[0124] The lifecycle event sequence is a time-ordered set of events generated based on development data. In this embodiment, the lifecycle time series can describe the behavior of code throughout the development lifecycle.
[0125] In this context, the subgraph node sequence is a sequence formed by arranging nodes in a subgraph structure in a certain order. In this embodiment, the subgraph node sequence can reflect the upstream and downstream relationships of code nodes in the topology graph.
[0126] The joint feature representation is a fused feature representation. In this embodiment, the joint feature representation can be generated through cross-modal attention interaction and can be used to fuse the feature representations of lifecycle event sequences and subgraph node sequences to capture their interaction relationship.
[0127] In this embodiment, two independent encoders can be used to encode the lifecycle event sequence and the subgraph node sequence respectively, generating their respective feature representations. Subsequently, the association between the lifecycle event sequence and the subgraph node sequence can be captured in the joint space using an interactive attention mechanism. Finally, the interaction results of the two sequences can be merged to generate a joint feature representation. The above is merely an illustrative example and is not intended to limit all possible cases for generating a joint feature representation; it is simply not exhaustive.
[0128] Positional encoding involves adding positional information to the input sequence. In this embodiment, positional encoding can be used to add positional information to the input sequence to help the model understand the sequential relationships within the sequence. Specifically, during the encoding stage, positional encoding is appended to the representation of each input node.
[0129] The weight distribution strategy is a rule that can dynamically adjust the weights assigned to different nodes in the attention mechanism. In this embodiment, the weight distribution strategy can prioritize more important or relevant nodes.
[0130] In this context, a topologically adjacent node refers to an upstream or downstream node that is directly adjacent to a certain node in a call dependency directed graph.
[0131] In this embodiment of the disclosure, the importance of topologically adjacent nodes can be identified through joint feature representation. Subsequently, higher attention weights are assigned to these nodes. Specifically, adjusting the weights of the positional encoding allows it to reflect the topological adjacency relationships of the nodes. Finally, during the encoding process, the influence of the positional encoding can be dynamically updated in conjunction with a weight distribution strategy. The above is merely an illustrative example and is not intended to limit all possible scenarios for adjusting the weight distribution strategy; it is simply not exhaustive.
[0132] Thus, by dynamically extracting subgraph structures, only subgraphs relevant to the current training sample can be processed, reducing unnecessary computation and providing local dependencies of code nodes, enhancing the model's structured understanding. Generating an attention constraint matrix optimizes attention distribution, helping the model focus on more relevant nodes. Generating joint feature representations combines lifecycle data and structural dependency information, improving the model's understanding. Dynamically adjusting positional encoding weights prioritizes important nodes, while allocating attention weights based on the features of the training samples enhances the model's flexibility.
[0133] In some embodiments, a code generation model training method further includes: monitoring conflict nodes between newly generated lifecycle development data and existing call dependency directed graphs; calculating data credibility weights based on the topological sorting positions of the conflict nodes; selecting incremental training samples using a weighted sampling strategy based on the data credibility weights; and updating the code generation model based on the incremental training samples.
[0134] In this context, a conflict node refers to a code node that conflicts with the logic or relationships in an existing call dependency directed graph when monitoring newly generated lifecycle development data. In this embodiment, a conflict indicates that changes or events in the new data do not fully match existing dependencies.
[0135] In this embodiment, new data can first be obtained from lifecycle data sources such as issue logs, review logs, and code commit logs. Then, the new data can be compared with the existing call dependency directed graph to check for logical conflicts. For example, if the new data shows node A depends on node C, but the graph shows node A depends on node B, then node A is a conflicting node. Next, the conflict type can be checked. For example, the conflict type can be dependency conflict, code logic conflict, etc. Finally, the detected conflicting nodes can be marked and recorded. The above is merely an illustrative example and is not intended to limit all possible scenarios for monitoring conflicting nodes; it is simply not exhaustive.
[0136] In this context, the topological sorting position refers to the order of the conflicting node in the directed graph of call dependencies. In this embodiment, topological sorting determines the processing order of nodes through dependencies, and the topological sorting position represents the dependency hierarchy of nodes in the graph.
[0137] The data credibility weight is a weight value calculated for newly generated lifecycle data. In this embodiment of the disclosure, the data credibility weight can be used to quantify the credibility of the data, reflecting the reliability and contribution of the data to model training.
[0138] In this embodiment, conflicting nodes can first be topologically sorted according to the directed graph of call dependencies. Then, weights can be calculated comprehensively based on the topological sort position and the degree of conflict. For example, nodes closer to the upstream part of the graph can be given higher weights, nodes with lower conflict severity can be given higher weights, and nodes with higher consistency with historical lifecycle data can be given higher weights. The above are merely illustrative examples and are not intended to limit all possible cases for calculating data credibility weights; they are simply not exhaustive.
[0139] The weighted sampling strategy is a method for selecting incremental training samples from newly generated lifecycle data based on data credibility weights. In this embodiment, the formaldehyde selection strategy can control the selection probability of samples through weights to ensure that high-credibility data is given priority in training.
[0140] In this embodiment, the incremental training samples are selected based on newly generated lifecycle development data and a weighted sampling strategy. In this disclosure, the incremental training samples can be used to update the training model while avoiding retraining the entire existing dataset.
[0141] In this embodiment, a weighted list can first be generated based on the credibility weight of each conflicting node to guide the sampling probability of training samples. Then, a sampling probability can be assigned to each conflicting node. For example, nodes with higher weights can have higher sampling probabilities, and vice versa. Finally, training samples can be dynamically selected based on the weighted sampling results. Specifically, incremental samples can preferentially include data from high-weight nodes. The above is merely an illustrative example and does not limit the selection of all possible incremental training samples; it is simply not exhaustive.
[0142] In this embodiment, the model can first be fine-tuned or updated using incremental training samples. Specifically, during retraining, the model prioritizes learning node data with high credibility to adapt to the latest lifecycle data. Subsequently, model parameters can be dynamically adjusted based on the characteristics of the incremental training samples. For example, model parameters can be adjusted to optimize the attention distribution, prioritizing conflict nodes and related dependencies; or model parameters can be adjusted to update the positional encoding strategy, making the model more sensitive to topological changes. Finally, through multiple rounds of incremental training, the model continuously adapts to new data, ensuring continuous improvement in model performance. The above is merely an illustrative example and does not represent all possible scenarios for updating the code-generated model; it is simply not exhaustive.
[0143] Thus, by monitoring conflict nodes, conflict nodes can be automatically detected, preventing erroneous input from interfering with model training. Data credibility weights quantify the impact of data on the training model, ensuring that high-quality data is prioritized for training, and core logic nodes are processed first. Weighted sampling to generate incremental samples reduces the participation of irrelevant or invalid samples, significantly improving training quality while avoiding redundant processing of existing data. Updating the model based on incremental samples ensures continuous model updates, adapting to constantly changing development scenarios, while avoiding full training and significantly reducing computational costs.
[0144] In some implementations, a Call-Dependency Graph (CDG) can be constructed by explicitly analyzing the call and dependency relationships between source files based on the internal structural relationships of the code files. This CDG can then be used to rationally sort and concatenate the source code, thereby achieving comprehensive capture of cross-file dependencies. Specifically, static or semi-static analysis can first be performed on the target codebase using automated tools to extract the call and dependency relationships between functions, classes, and modules, generating the CDG. Subsequently, topological sorting or hierarchical / chunking strategies can be implemented based on the CDG to ensure that the code definition order always precedes its call and reference order. Next, the sorted code files can be sequentially concatenated into a complete and stable long text file, or segmented data packets with offset indices can be constructed to facilitate efficient reading and processing of long context models.
[0145] Furthermore, using code files as the core, heterogeneous data from the development process, such as requirement proposals, issue discussions, feature implementation and modification, review and merging records, can be aggregated to construct a data organization method combining time and dependency dimensions, achieving effective integration of information throughout the entire code evolution process. Specifically, multi-source data from requirement documents, issue discussions, commit records, pull requests, and other complete development stages can be aggregated around code files first. Subsequently, events can be sorted in global chronological order, and cross-aggregated based on code change and reference relationships between commits, issues, and pull requests to form semantically complete and context-closely related data units. Finally, based on the above arrangement structure, training samples covering the complete chain of "requirement definition, feature implementation, code review, and feature iteration" can be constructed; each sample simultaneously retains metadata such as event timestamps, author information, change summaries, and tags, as well as associated specific code snippets, ensuring data traceability and contextual consistency.
[0146] This disclosure provides a code generation method. Figure 2This is a flowchart illustrating a code generation method according to an embodiment of the present disclosure. This code generation method can be applied to a code generation method apparatus. The code generation method apparatus is located in an electronic device. The electronic device includes, but is not limited to, fixed devices and / or mobile devices. For example, fixed devices include, but are not limited to, servers, which can be cloud servers or ordinary servers. Mobile devices include, but are not limited to, software development aids, which can be mobile phones, tablets, vehicle terminals, etc. In some possible implementations, the code generation method can also be implemented by a processor calling computer-readable instructions stored in memory. Figure 1 As shown, the code generation method includes:
[0147] S201. Obtain code requirements;
[0148] S202. Input the code requirements into the code generation model and obtain the code results output by the code generation model based on the development data.
[0149] In this embodiment, developers can first input code requirements via text description, speech recognition, or file upload. Then, natural language processing techniques can be used to parse the code requirements, extract keywords, functional goals, and possible contextual information, and decompose the requirements into structured data. Finally, the parsed requirements can be compared with historical requirement records in the development data to identify possible templates or contexts. The above is merely an illustrative example and is not intended to limit the scope of all possible scenarios for obtaining code requirements; it is simply not exhaustive.
[0150] Here, the code result refers to the code snippet output after processing the input code requirements through a code generation model. In this embodiment of the disclosure, the code result includes a functional implementation that matches the requirements and is generated based on development data.
[0151] In this embodiment, structured code requirements can first be passed as input to the code generation model. Specifically, the input may include functional goals, input / output constraints, and contextual information. Subsequently, the code generation model uses development data to understand the requirements, optimizes call dependencies using a directed graph of call dependencies, and finally automatically corrects the generated code based on the development data to avoid known problems and optimize code structure, improving readability and runtime efficiency. Finally, the model outputs a code snippet that meets the requirements. The above is merely an illustrative example and does not represent all possible scenarios for obtaining the code result; it is simply not exhaustive.
[0152] The technical solution of this disclosure, by obtaining code requirements, can clearly define the requirements and objectives, and can support inputting requirements in language, documentation, or other forms, thus lowering the barrier to entry for developers. The automatic generation of code results through a code generation model can combine historical development data and dependencies to ensure accurate and optimized code generation. Furthermore, it can automatically correct and improve the generated code based on problem records and review comments throughout the entire lifecycle of data.
[0153] This disclosure provides a code generation model training apparatus, such as... Figure 3 As shown, the device may include: a dependency analysis module 301, used to generate a directed graph of call dependencies based on the code files and the dependency relationships; a data retrieval module 302, used to obtain development data based on the code files and the directed graph of call dependencies; the development data includes at least: code requirements, issue records, submission records and review records; a sample construction module 303, used to construct training samples based on the development data and the code files; and a model training module 304, used to train the initial model using the training samples to obtain a code generation model.
[0154] In some embodiments, the dependency analysis module 301 includes: a dependency extraction submodule, used to extract dependencies from code files and generate dependency data; and a directed graph construction submodule, used to construct a directed graph based on the dependency data and generate the call dependency directed graph.
[0155] In some embodiments, the dependency extraction submodule is configured to: generate code structure data based on syntax parsing of the code file; extract the dependencies of the code structure data; and generate the dependency data.
[0156] In some embodiments, the directed graph construction submodule is configured to: create nodes based on the dependency relationship data to generate a node set; perform relationship mapping based on the node set and the dependency relationship to generate a relationship set; and generate the call dependency directed graph based on the node set and the relationship set.
[0157] In some embodiments, the data retrieval module 302 includes: a code list generation submodule, configured to perform topological sorting of the code files based on the logical order according to the call dependency directed graph to generate a code entry list; a code data submodule, configured to concatenate the code files according to the code entry list to generate code data; and a development data acquisition submodule, configured to acquire development data corresponding to the code data according to the code data.
[0158] In some embodiments, the sample construction module 303 includes: an event list generation submodule, used to generate an event list based on the development data and a temporal relationship; an information unit generation submodule, used to cross-aggregate the event list and the code data to generate code information units; and a training sample construction submodule, used to construct the training samples based on the code information units.
[0159] In some embodiments, a training sample construction submodule is used to extract the association relationship between key entities in the requirement description in the event list and nodes in the call dependency directed graph; when the code information unit involves multiple associated nodes, cross-module context constraint description text is automatically generated; the constraint description text is used as a prefix prompt and combined with the corresponding code snippet to form a reinforcement sample.
[0160] In some embodiments, the training sample construction submodule is configured to: extract metadata information based on the code information unit; annotate the code information unit with content based on the metadata information to generate a set of code snippets; and construct the training sample based on the metadata information and the set of code snippets.
[0161] In some embodiments, the training sample construction submodule is used to: identify the boundary nodes of the call-dependent directed graph; automatically inject adversarial samples simulating abnormal changes in the boundary nodes; generate corresponding correction labels based on the modification opinions in the review record; and construct fault-tolerant training sample pairs.
[0162] In some embodiments, the data retrieval module 302 includes: a dynamic parsing submodule, used to parse the timestamps in the submission records and the node change records of the call dependency directed graph; a time-series generation submodule, used to dynamically generate a code evolution path time-series chain based on the mapping relationship between the topology sorting result and the timestamps; and a graph construction submodule, used to anchor the issue records and the review records to the corresponding code nodes according to the time-series chain, and construct a lifecycle data graph with version tags.
[0163] In some embodiments, the model training module 304 includes: a subgraph extraction submodule, used to dynamically extract subgraph structures associated with the current training samples from the call dependency directed graph; a prior mask submodule, used to convert the subgraph structures into attention constraint matrices as prior masks for the initial model encoder; a joint feature submodule, used to perform cross-modal attention interaction between the lifecycle event sequence and the subgraph node sequence to generate a joint feature representation; and a dynamic weight submodule, used to dynamically adjust the weight distribution strategy of the position encoding based on the joint feature representation, so that the initial model prioritizes topologically adjacent nodes.
[0164] In some embodiments, the code generation model training apparatus further includes: an incremental monitoring module 305. Figure 3 (Not shown in the image), used to monitor conflict nodes between newly generated lifecycle development data and existing call dependency directed graphs; Trusted weight calculation module 306 ( Figure 3 (Not shown in the image), used to calculate data confidence weights based on the topological sorting position of the conflicting nodes; incremental sample module 307 ( Figure 3 (Not shown in the image), used to select incremental training samples using a weighted sampling strategy based on the data confidence weights; incremental training module 308 ( Figure 3 (not shown in the image) is used to update the code generation model based on the incremental training samples.
[0165] The specific functions and examples of each module and submodule of the apparatus in this disclosure can be found in the relevant descriptions of the corresponding steps in the above method embodiments, and will not be repeated here.
[0166] The code generation model training device in this embodiment transforms the dependencies between code files into a graph structure, which intuitively captures the call relationships between code and modules, thereby generating training samples that are more consistent with real-world environments. By introducing full lifecycle data, additional development background and historical information of the code are provided, enabling the model to learn contextual information such as code requirements and problem records, thus generating code that better meets actual needs and specifications. Constructing samples using full lifecycle data enhances the accuracy and scenario adaptability of the generated code, while also enabling the model to learn the context of code generation. Training the model with full lifecycle data ultimately results in a code generation model that generates code that better meets requirements and specifications.
[0167] This disclosure provides a code generation apparatus, such as... Figure 4 As shown, the device may include: a requirement acquisition module 401 for acquiring code requirements; and a code generation module 402 for inputting code requirements into a code generation model to obtain code results output by the code generation model based on development data.
[0168] The specific functions and examples of each module and submodule of the apparatus in this disclosure can be found in the relevant descriptions of the corresponding steps in the above method embodiments, and will not be repeated here.
[0169] The code generation model training device in this embodiment can clarify the requirements and objectives by acquiring code requirements. It also supports inputting requirements in languages, documents, or other formats, lowering the barrier to entry for developers. The code generation model automatically generates code results, combining historical development data and dependencies to ensure accurate and optimized code. Furthermore, it can automatically correct and improve the generated code based on problem records and review comments throughout the entire lifecycle of data.
[0170] This disclosure provides a scenario illustration of a code generation model training method, such as... Figure 5 As shown.
[0171] As previously described, the code generation model training method provided in this disclosure is applied to electronic devices. These electronic devices are intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers.
[0172] Specifically, the electronic device may perform the following operations: generate a directed graph of call dependencies based on the code file and the directed graph of call dependencies; obtain development data based on the code file and the directed graph of call dependencies; the development data includes at least: code requirements, issue records, submission records and review records; construct training samples based on the development data and the code file; and train the initial model using the training samples to obtain a code generation model.
[0173] It should be understood that Figure 5 The scene diagrams shown are merely illustrative and not restrictive; those skilled in the art can interpret them based on... Figure 5 Even with various obvious changes and / or substitutions to the examples, the resulting technical solutions still fall within the scope of this disclosure.
[0174] This disclosure provides a scenario illustration of a code generation method, such as... Figure 6 As shown.
[0175] As previously described, the code generation method provided in this disclosure is applied to electronic devices. These electronic devices are intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers.
[0176] Specifically, the electronic device may perform the following operations: obtain code requirements; input the code requirements into the code generation model, and obtain the code results output by the code generation model based on the development data.
[0177] It should be understood that Figure 6The scene diagrams shown are merely illustrative and not restrictive; those skilled in the art can interpret them based on... Figure 6 Even with various obvious changes and / or substitutions to the examples, the resulting technical solutions still fall within the scope of this disclosure.
[0178] The acquisition, storage, and application of user personal information involved in the technical solution disclosed herein comply with the provisions of relevant laws and regulations and do not violate public order and good morals.
[0179] According to embodiments of this disclosure, this disclosure also provides an electronic device, a readable storage medium, and a computer program product.
[0180] Figure 7 A schematic block diagram of an example electronic device 700 that can be used to implement embodiments of the present disclosure is shown. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device may also represent various forms of mobile devices, such as personal digital assistants, cellular phones, smartphones, wearable devices, and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely illustrative and are not intended to limit the implementation of the present disclosure described and / or claimed herein.
[0181] like Figure 7 As shown, device 700 includes a computing unit 701, which can perform various appropriate actions and processes based on a computer program stored in read-only memory (ROM) 702 or a computer program loaded from storage unit 708 into random access memory (RAM) 703. The RAM 703 may also store various programs and data required for the operation of device 700. The computing unit 701, ROM 702, and RAM 703 are interconnected via bus 704. An input / output (I / O) interface 705 is also connected to bus 704.
[0182] Multiple components in device 700 are connected to I / O interface 705, including: input unit 706, such as keyboard, mouse, etc.; output unit 707, such as various types of monitors, speakers, etc.; storage unit 708, such as disk, optical disk, etc.; and communication unit 709, such as network card, modem, wireless transceiver, etc. Communication unit 709 allows device 700 to exchange information / data with other devices through computer networks such as the Internet and / or various telecommunications networks.
[0183] The computing unit 701 can be various general-purpose and / or special-purpose processing components with processing and computing capabilities. Some examples of the computing unit 701 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various special-purpose artificial intelligence (AI) computing chips, various computing units running machine learning model algorithms, digital signal processors (DSPs), and any suitable processor, controller, microcontroller, etc. The computing unit 701 performs the various methods and processes described above, such as code generation model training methods and / or code generation methods. For example, in some embodiments, the code generation model training methods and / or code generation methods may be implemented as computer software programs tangibly contained in a machine-readable medium, such as storage unit 708. In some embodiments, part or all of the computer program may be loaded and / or installed on device 700 via ROM 702 and / or communication unit 709. When the computer program is loaded into RAM 703 and executed by computing unit 701, one or more steps of the code generation model training method and / or code generation method described above can be performed. Alternatively, in other embodiments, computing unit 701 can be configured to execute the code generation model training method and / or code generation method by any other suitable means (e.g., by means of firmware).
[0184] Various embodiments of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field-programmable gate arrays (FPGAs), application-specific integrated circuits (ASICs), application-specific standard products (ASSPs), systems-on-chip (SoCs), complex programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various embodiments may include implementations in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which may be a dedicated or general-purpose programmable processor, capable of receiving data and instructions from a storage system, at least one input device, and at least one output device, and transmitting data and instructions to the storage system, the at least one input device, and the at least one output device.
[0185] The program code used to implement the methods of this disclosure may be written in any combination of one or more programming languages. This program code may be provided to a processor or controller of a general-purpose computer, special-purpose computer, or other programmable data processing apparatus, such that when executed by the processor or controller, the program code causes the functions / operations specified in the flowcharts and / or block diagrams to be implemented. The program code may be executed entirely on a machine, partially on a machine, as a standalone software package partially on a machine and partially on a remote machine, or entirely on a remote machine or server.
[0186] In the context of this disclosure, a machine-readable medium can be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, apparatus, or device. A machine-readable medium can be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium can be, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatus, or devices, or any suitable combination of the foregoing. More specific examples of machine-readable storage media include electrical connections based on one or more wires, portable computer disks, hard disks, random access memory, read-only memory, erasable programmable read-only memory (EPROM), flash memory, optical fiber, compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination of the foregoing.
[0187] To provide interaction with a user, the systems and techniques described herein can be implemented on a computer having: a display device (e.g., a cathode ray tube (CRT) or liquid crystal display (LCD) monitor) for displaying information to the user; and a keyboard and pointing device (e.g., a mouse or trackball) through which the user provides input to the computer. Other types of devices can also be used to provide interaction with the user; for example, feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including sound input, voice input, or tactile input).
[0188] The systems and technologies described herein can be implemented in computing systems that include backend components (e.g., as a data server), or computing systems that include middleware components (e.g., an application server), or computing systems that include frontend components (e.g., a user computer with a graphical user interface or web browser through which a user can interact with implementations of the systems and technologies described herein), or any combination of such backend, middleware, or frontend components. The components of the system can be interconnected via digital data communication of any form or medium (e.g., a communication network). Examples of communication networks include local area networks (LANs), wide area networks (WANs), and the Internet.
[0189] Computer systems can include clients and servers. Clients and servers are generally located far apart and typically interact via communication networks. Client-server relationships are created by computer programs running on the respective computers and having a client-server relationship with each other. Servers can be cloud servers, servers in distributed systems, or servers incorporating blockchain technology.
[0190] It should be understood that the various forms of processes shown above can be used to rearrange, add, or delete steps. For example, the steps described in this disclosure can be executed in parallel, sequentially, or in different orders, as long as the desired result of the technical solution disclosed in this disclosure can be achieved, and this is not limited herein.
[0191] The specific embodiments described above do not constitute a limitation on the scope of protection of this disclosure. Those skilled in the art should understand that various modifications, combinations, sub-combinations, and substitutions can be made according to design requirements and other factors. Any modifications, equivalent substitutions, and improvements made within the principles of this disclosure should be included within the scope of protection of this disclosure.
Claims
1. A method for training a code generation model, comprising: Based on the code files, generate a directed graph of call dependencies according to the dependency relationships; Based on the code file and the directed graph of call dependencies, obtain development data; The development data includes at least: code requirements, issue records, submission records, and review records; Based on the development data and temporal relationships, an event list is generated; the event list and code data are cross-aggregated to generate code information units; and training samples are constructed based on the code information units. The initial model is trained using the training samples to obtain the code generation model; The step of training the initial model using the training samples includes: dynamically extracting subgraph structures associated with the current training samples from the call dependency directed graph; converting the subgraph structures into attention constraint matrices as prior masks for the encoder of the initial model; performing cross-modal attention interaction between the lifecycle event sequence and the subgraph node sequence to generate joint feature representations; and dynamically adjusting the weight distribution strategy of the position encoding based on the joint feature representations so that the initial model prioritizes topologically adjacent nodes.
2. The method according to claim 1, wherein, The step of generating a directed call dependency graph based on the code file and its dependencies includes: Extract dependencies from code files and generate dependency data; Based on the dependency data, a directed graph is constructed to generate the call dependency directed graph.
3. The method according to claim 2, wherein, The step of extracting dependencies from code files and generating dependency data includes: Based on the code file, generate code structure data through syntax parsing; Extract the dependencies from the code structure data and generate the dependency data.
4. The method according to claim 2, wherein, The step of constructing a directed graph based on the dependency data to generate the call dependency directed graph includes: Based on the dependency data, nodes are created to generate a node set; Based on the set of nodes and the dependencies, perform relationship mapping to generate a relationship set; The call dependency directed graph is generated based on the set of nodes and the set of relationships.
5. The method according to claim 1, wherein, The step of obtaining development data based on the code file and the directed graph of call dependencies includes: Based on the directed graph of call dependencies, the code files are topologically sorted according to logical order to generate a list of code entries; Based on the list of code entries, the code file is concatenated to generate code data; Based on the code data, obtain the development data corresponding to the code data.
6. The method according to claim 1, wherein, The step of constructing training samples based on the code information units includes: Extract the key entities in the requirement description of the event list and their relationships with the nodes in the directed graph of the call dependency; When the code information unit involves multiple associated nodes, cross-module context constraint description text is automatically generated; The constraint description text is used as a prefix prompt and combined with the corresponding code snippet to form an enhanced sample.
7. The method according to claim 1, wherein, The step of constructing training samples based on the code information units includes: Extract metadata information based on the code information unit; Based on the metadata information, the code information unit is annotated to generate a set of code snippets; The training samples are constructed based on the metadata information and the set of code snippets.
8. The method according to claim 7, wherein, The content annotation includes: Identify the boundary nodes of the directed graph that the call depends on; Automatically inject adversarial examples that simulate abnormal changes in boundary nodes; Based on the modification comments in the review record, corresponding correction labels are generated, and fault-tolerant training sample pairs are constructed.
9. The method according to claim 1, wherein, The acquisition of development data includes: Parse the timestamp in the submission record and the node change record in the directed graph of the call dependency; Based on the mapping relationship between topological sorting results and timestamps, a time-series chain of code evolution paths is dynamically generated; The problem records and review records are anchored to the corresponding code nodes according to the time sequence chain to construct a lifecycle data graph with version tags.
10. The method according to claim 1, wherein, The method further includes: Monitor newly generated lifecycle development data and conflict nodes in the existing directed graph of call dependencies; The data credibility weight is calculated based on the topological sorting position of the conflicting nodes; Based on the data credibility weights, a weighted sampling strategy is used to select incremental training samples; The code generation model is updated based on the incremental training samples.
11. A code generation method, comprising: Code acquisition requirements; The code requirements are input into the code generation model to obtain the code results output by the code generation model based on the development data; wherein the code generation model is trained by the method of any one of claims 1 to 10.
12. A code generation model training device, comprising: The dependency analysis module is used to generate a directed graph of call dependencies based on the dependency relationships in the code files; The data retrieval module is used to obtain development data based on the code file and the directed graph of call dependencies; The development data includes at least: code requirements, issue records, submission records, and review records; The sample construction module is used to generate an event list based on the development data and temporal relationships; to cross-aggregate the event list and code data to generate code information units; and to construct training samples based on the code information units. The model training module is used to train the initial model using the training samples to obtain a code generation model. Specifically, the model training module is used to dynamically extract the subgraph structure associated with the current training samples from the call dependency directed graph; convert the subgraph structure into an attention constraint matrix as a priori mask for the encoder of the initial model; perform cross-modal attention interaction between the lifecycle event sequence and the subgraph node sequence to generate a joint feature representation; and dynamically adjust the weight distribution strategy of the position encoding based on the joint feature representation so that the initial model prioritizes topologically adjacent nodes.
13. A code generation apparatus, comprising: The requirement elicitation module is used to obtain code requirements; A code generation module is used to input the code requirements into a code generation model and obtain the code results output by the code generation model based on the development data; wherein the code generation model is trained by the method of any one of claims 1 to 10.
14. An electronic device comprising: At least one processor; as well as A memory that is communicatively connected to at least one processor; wherein, The memory stores instructions that can be executed by at least one processor to enable the at least one processor to perform the method of any one of claims 1-10.
15. A non-transitory computer-readable storage medium storing computer instructions, wherein, Computer instructions are used to cause a computer to perform the method according to any one of claims 1-10.
16. A computer program product comprising a computer program stored on a storage medium, wherein the computer program, when executed by a processor, implements the method according to any one of claims 1-10.
Citation Information
Patent Citations
Sample construction method, code generation method, electronic equipment and storage medium
CN117556263A
Method for performing efficient parameter fine tuning on code model in combination with abstract syntax tree
CN118733052A