Source code generation method and apparatus

By using an abstract semantic graph and a bidirectional recurrent neural network model, combined with Euclidean distance and Kullback-Leibler divergence, the source code fragment most similar to the user input is generated, solving the problem of low accuracy in the generation of source code in existing technologies and achieving more efficient and personalized code generation.

CN122095343APending Publication Date: 2026-05-26HUAWEI CLOUD COMPUTING TECHNOLOGIES CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-04-28
Publication Date
2026-05-26

AI Technical Summary

Technical Problem

Existing automated code completion features generate source code with low accuracy, forcing developers to browse large lists of candidates to find relevant code, wasting time and potentially generating unsafe, incorrect, or unoptimized code.

Method used

We employ an abstract semantic graph (ASG) and bidirectional recurrent neural network model, combining Euclidean distance and Kullback-Leibler divergence, to generate candidate segments through graph convolution and global vector representation (GloVe), selecting the segment most similar to the user input, thus limiting the search space of static analysis tools to improve accuracy.

Benefits of technology

It improves the accuracy of generated source code, reduces the time spent browsing candidate lists, lowers the risk of generating unsafe or non-optimized code, and enhances the personalization and diversity of the code.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122095343A_ABST
    Figure CN122095343A_ABST
Patent Text Reader

Abstract

This application provides a source code generation method and apparatus. The method includes: determining target features based on a first fragment, wherein the first fragment includes one or more codes input by a user before a first moment, and the target features are used to indicate code attributes of the codes in the fragment; generating multiple candidate fragments; and selecting a second fragment from the multiple candidate fragments based on the target features, wherein the features of the second fragment have the highest similarity to the target features among the features of the multiple candidate fragments. The target features are obtained based on the source code input by the user and serve as the user's sequence preference. The source code suggestions provided to the user are generated based on the user's sequence preference. In other words, the generated source code is related to the source code input by the user. Therefore, the accuracy of the generated source code can be improved.
Need to check novelty before this filing date? Find Prior Art

Description

[0001] This application relates to and claims priority to PCT patent application No. PCT / RU2023 / 000327, filed on October 26, 2023, entitled “METHOD ANDDEVICE FOR COMPUTING”.

[0002] The full disclosure of the above application is incorporated herein by reference. Technical Field

[0003] This application relates to the field of artificial intelligence, and more specifically, to a source code generation method and apparatus. Background Technology

[0004] Software development environments can include source code editors and other tools that developers use to write and test their programs. Some software development environments include code completion features that provide assistance as developers edit code by automatically displaying a list of possible candidates based on one or more characters (e.g., letters, symbols, etc.) that the developer types into the source code editor. A pop-up menu may appear containing several suggested code elements that the developer can utilize. This assistance is beneficial because it speeds up development and reduces common errors, such as spelling mistakes.

[0005] However, automatic code completion features may provide average or general code suggestions consistent with common patterns in the training data, which may be unrelated to the source code typed by the developer. In other words, the generated source code has low accuracy, so developers may have to sift through a large list of candidates to find relevant code. Therefore, improving the accuracy of generated source code has become a pressing issue. Summary of the Invention

[0006] This application provides a source code generation method and apparatus. These technical solutions can improve the accuracy of generated source code.

[0007] According to a first aspect, embodiments of this application provide a source code generation method. The method includes: determining target features based on a first fragment, wherein the first fragment includes one or more codes input by a user before a first moment, and the target features are used to indicate code attributes of the code in the fragment; generating multiple candidate fragments; and selecting a second fragment from the multiple candidate fragments based on the target features, wherein, among the features of the multiple candidate fragments, the features of the second fragment have the highest similarity to the target features.

[0008] According to the above technical solution, the target features are obtained based on the user-input source code, serving as the user's sequence preferences. The source code suggestions provided to the user are generated based on these preferences. In other words, the generated source code is related to the user-input source code. Therefore, the accuracy of the generated source code can be improved.

[0009] In conjunction with the first aspect, in some embodiments, determining the target feature based on the first fragment includes: obtaining a first abstract semantic graph (ASG), wherein each vertex in the first ASG is associated with a sub-item in the first fragment, and the vertex includes a first attribute, a second attribute, and a third attribute, wherein the first attribute indicates the attribute feature of the sub-item associated with the vertex in the abstract syntax tree, the second attribute indicates the attribute feature of the sub-item associated with the vertex in the control flow graph, and the third attribute indicates the attribute feature of the sub-item associated with the vertex in the program dependency graph; determining at least one new vertex based on the first ASG, wherein the at least one new vertex is used to link to the first ASG; and determining the target feature, wherein the target feature includes the first attribute of at least one new vertex, the second attribute of at least one new vertex, and the third attribute of at least one new vertex.

[0010] According to the above technical solution, ASG can not only be used to represent the syntax of source code fragments, but also includes information about the control flow and program dependencies of the source code fragments. Using ASG to represent user-input source code fragments can solve the average code prediction problem in the worst case or to the maximum extent by utilizing neural symbolic substitution for the f-attention mechanism. Therefore, the acquired target features can more accurately reflect the user's sequence preferences.

[0011] In conjunction with the first aspect, in some embodiments, determining at least one new vertex based on a first ASG includes: inputting each vertex in the first ASG and the hidden state vector of the second ASG into a bidirectional recurrent neural network model to determine the hidden state vector of the first ASG, wherein the hidden state vector of the first ASG indicates the relationship between each vertex in the first ASG, the hidden state vector of the second ASG indicates the relationship between each vertex in the second ASG, each vertex in the first ASG is associated with a sub-item in a third segment, the third segment including one or more codes entered by the user before a second time step, the second time step being earlier than the first time step; and determining at least one new vertex based on the hidden state vector of the first ASG.

[0012] Based on the above technical solution, codebase environment awareness and time history awareness context can be aggregated through a bidirectional recurrent neural network model. This maximizes the scalability problem and ultimately addresses the diversity problem through statistical aggregation of neural symbolic features. Therefore, the scalability and diversity of the acquired target features can be improved.

[0013] In conjunction with the first aspect, in some embodiments, selecting a second segment from multiple candidate segments based on target features includes: obtaining multiple first vectors, wherein the multiple first vectors correspond one-to-one with multiple candidate segments, each first vector representing a candidate segment in a first vector space, the first vector space being the vector space where the second vector is located, and the second vector representing at least one new vertex; selecting a third vector from the multiple first vectors, wherein the third vector is the vector among the multiple first vectors that has the smallest distance to the second vector in the vector space; and determining the second segment, wherein the second segment is represented by the third vector in the first vector space.

[0014] According to the above technical solution, feature similarity is reflected as the distance between vectors in the same vector space, allowing each candidate segment to be scored by a hierarchical SoftMax classifier. Using a bidirectional recurrent neural network model to perform Bayesian variational inference on the aggregated features can solve the sparsity problem and ultimately the scalability problem. This improves the scalability of the acquired target features and reduces the cold start problem caused by data sparsity.

[0015] In conjunction with the first aspect, in some embodiments, the distance to the second vector in the vector space is obtained based on Euclidean distance and Kullback-Leibler (KL) divergence.

[0016] According to the above technical solution, Euclidean distance is used to measure the similarity between vectors in a high-dimensional vector space, while KL divergence is used to measure the dissimilarity between pairwise similarities in different vector spaces. Therefore, candidate segments can be embedded into the same low-dimensional vector space to rank them. This improves the accuracy of obtaining the second segment from the candidate segments.

[0017] In conjunction with the first aspect, in some embodiments, the plurality of first vectors are obtained based on a co-occurrence matrix, wherein the co-occurrence matrix is ​​used to indicate the frequency of occurrence of sub-items in the plurality of candidate segments and sub-items in the first segment in the same segment.

[0018] According to the above technical solution, multiple first vectors are obtained through global vector representation (GloVe) embedding, which makes it easy to represent candidate fragments in vector space. Therefore, the sparsity problem can be eliminated.

[0019] In conjunction with the first aspect, in some embodiments, multiple candidate fragments are generated based on user projects, wherein the user projects include multiple codes entered by the user, and the user projects include the first fragment.

[0020] According to the above technical solution, multiple candidate segments are generated based on the user's project. This avoids the inability to predict code elements or syntax used in the user's project that did not appear during model training (i.e., the out-of-vocabulary (OOV) problem). Therefore, the accuracy of the candidate segments can be improved.

[0021] In conjunction with the first aspect, in some embodiments, generating multiple candidate fragments includes: obtaining at least one third ASG, wherein each third ASG is associated with a fragment in the user's project; and generating multiple candidate fragments based on the at least one ASG.

[0022] According to the above technical solution, candidate fragments can be obtained from the user's project using graph convolutional ASG, which includes more information about the user's project. Therefore, the accuracy of candidate fragments can be improved.

[0023] According to a second aspect, embodiments of this application provide a source code generation apparatus. The apparatus includes: a determining module, configured to determine target features based on a first fragment, wherein the first fragment includes one or more codes input by a user before a first moment, and the target features are used to indicate code attributes of the code in the fragment; a generating module, configured to generate multiple candidate fragments; and a selecting module, configured to select a second fragment from the multiple candidate fragments based on the target features, wherein, among the features of the multiple candidate fragments, the features of the second fragment have the highest similarity to the target features.

[0024] In conjunction with the second aspect, in some embodiments, the determining module is configured to: obtain a first abstract semantic graph (ASG), wherein each vertex in the first ASG is associated with a sub-item in a first segment, and the vertex includes a first attribute, a second attribute, and a third attribute, wherein the first attribute indicates the attribute feature of the sub-item associated with the vertex in the abstract syntax tree, the second attribute indicates the attribute feature of the sub-item associated with the vertex in the control flow graph, and the third attribute indicates the attribute feature of the sub-item associated with the vertex in the program dependency graph; determine at least one new vertex based on the first ASG, wherein the at least one new vertex is used to link to the first ASG; and determine a target feature, wherein the target feature includes the first attribute of at least one new vertex, the second attribute of at least one new vertex, and the third attribute of at least one new vertex.

[0025] In conjunction with the second aspect, in some embodiments, the determining module is configured to: input each vertex in the first ASG and the hidden state vector of the second ASG into a bidirectional recurrent neural network model to determine the hidden state vector of the first ASG, wherein the hidden state vector of the first ASG indicates the relationship between each vertex in the first ASG, the hidden state vector of the second ASG indicates the relationship between each vertex in the second ASG, each vertex in the first ASG is associated with a sub-item in a third segment, the third segment including one or more codes entered by the user before a second time step, the second time step being earlier than the first time step; and determine at least one new vertex based on the hidden state vector of the first ASG.

[0026] In conjunction with the second aspect, in some embodiments, the selection module is used to: obtain a plurality of first vectors, wherein the plurality of first vectors correspond one-to-one with a plurality of candidate segments, each first vector representing a candidate segment in a first vector space, the first vector space being the vector space where the second vector is located, and the second vector representing at least one new vertex; select a third vector from the plurality of first vectors, wherein the third vector is the vector among the plurality of first vectors that has the smallest distance to the second vector in the vector space; and determine a second segment, wherein the second segment is represented by the third vector in the first vector space.

[0027] In conjunction with the second aspect, in some embodiments, the distance to the second vector in the vector space is obtained based on Euclidean distance and Kullback-Leibler (KL) divergence.

[0028] In conjunction with the second aspect, in some embodiments, the multiple first vectors are obtained based on a co-occurrence matrix, wherein the co-occurrence matrix is ​​used to indicate the frequency of occurrence of sub-items in the multiple candidate segments and sub-items in the first segment in the same segment.

[0029] In conjunction with the second aspect, in some embodiments, multiple candidate fragments are generated based on user projects, wherein the user projects include multiple codes entered by the user, and the user projects include a first fragment.

[0030] In conjunction with the second aspect, in some embodiments, the generation module is used to: obtain at least one third ASG, wherein each third ASG is associated with a fragment in the user's project; and generate multiple candidate fragments based on the at least one ASG.

[0031] According to a third aspect, a computing device cluster is provided. The computing device cluster includes at least one computing device, each computing device including a processor and memory. The processor of the at least one computing device is configured to execute instructions stored in the memory of the at least one computing device to cause the computing device cluster to perform a method according to the first aspect or any possible embodiment of the first aspect.

[0032] According to a fourth aspect, a computer-readable storage medium is provided. The computer-readable storage medium includes one or more instructions. When executed by a cluster of computing devices, the cluster of computing devices performs a method according to the first aspect or any possible embodiment of the first aspect.

[0033] According to a fifth aspect, a computer program product including instructions is provided. When these instructions are executed by a cluster of computing devices, the cluster of computing devices performs a method according to the first aspect or any possible embodiment of the first aspect. Attached Figure Description

[0034] Figure 1 An example of SRS is shown.

[0035] Figure 2 A schematic flowchart of a method 200 according to an embodiment of this application is shown.

[0036] Figure 3 An example of ASG is shown.

[0037] Figure 4 A schematic diagram of the system's model architecture is shown.

[0038] Figure 5 A schematic diagram of the co-occurrence matrix is ​​shown.

[0039] Figure 6 A schematic diagram of GloVe is shown.

[0040] Figure 7 A schematic flowchart of source code generation is shown.

[0041] Figures 8 to 11 A schematic block diagram of a possible device according to an embodiment of this application is shown. Detailed Implementation

[0042] The technical solution of this application is described below with reference to the accompanying drawings.

[0043] The embodiments of the present invention can be applied to source code completion and generation tasks. For example, an apparatus or system for source code completion and generation tasks can generate source code by accepting user input and suggest code completion based on the generated source code.

[0044] To facilitate understanding of the embodiments of this application, the terms involved in this application are explained briefly below.

[0045] 1. Sequential recommender system (SRS) SRS primarily suggests items a user might be interested in by modeling the sequence dependencies of user-item interactions (such as viewing or purchasing items on an online shopping platform). Traditional recommender systems (RS), including content-based RS and collaborative filtering RS, model user-item interactions statically and can only capture general user preferences. In contrast, SRS treats user-item interactions as a dynamic sequence and takes sequence dependencies into account to capture the user's current and recent preferences, thus achieving more accurate recommendations.

[0046] Figure 1 An example of SRS is shown. In the real world, user shopping behavior typically occurs sequentially, rather than in isolation. For example... Figure 1 As shown, after a user purchases a computer, they might subsequently purchase a mouse and a printer. Their next action might be to purchase ink cartridges for the printer. In this scenario, each subsequent action of the user depends on the preceding action; therefore, all four consumption actions are sequentially related.

[0047] 2. Code Property Graph (CPG) The program's CPG is a graph representation of the program obtained by merging its abstract syntax tree (AST), control-flow graph (CFG), and dependency graph (PDG) at statement and predicate nodes. The resulting graph is a property graph, which is the underlying graph model for graph databases such as Neo4j, JanusGraph, and OrientDB, where data is stored as key-value pairs in nodes and edges. In practice, the code property graph can be stored in a graph database and queried using a graph query language.

[0048] 3. Graph Convolutional Recurrent Network (GCRN) GRRN is a deep learning model capable of predicting structured sequences of data. More precisely, GCRN is a generalization of classic recurrent neural networks (RNNs) to data structured by arbitrary graphs. Such structured sequences can represent a series of frames in a video, spatiotemporal measurements on sensor networks, or random walks on a lexical graph used for natural language modeling. GCRN combines a convolutional neural network (CNN) on the graph to identify spatial structure and an RNN to find dynamic patterns. By utilizing both spatial and dynamic information about the data, GCRN can improve both accuracy and learning speed.

[0049] 4. Global vector representation (GloVe) GloVe is a distributed word representation model. This model is an unsupervised learning algorithm for obtaining vector representations of words. This is achieved by mapping words to a meaningful space where the distance between words is related to semantic similarity. Trained on aggregated global word-word co-occurrence statistics from a corpus, the resulting representations exhibit an interesting linear substructure of the word vector space. As a log-bilinear regression model for unsupervised learning of word representation, it combines features from two families of models: global matrix factorization and local context window methods.

[0050] GloVe can be used to find relationships between words, such as synonyms, relationships between companies and products, postal codes, and cities.

[0051] 5. Language Model (LM) The purpose of language modeling is to model the probability of generating word sequences, thereby predicting the probability of future (or missing) tokens.

[0052] The development of language models began with statistical language models based on Markov assumptions, such as predicting the next word based on recent context.

[0053] Further neural language models are proposed, which obtain the probability of word sequences through neural networks, such as word to vector (Word2Vec).

[0054] Next, pre-trained language models (PLMs) were introduced. For example, embedding from language models (ELMo) was proposed to use bidirectional long short-term memory (biLSTM) networks to capture context-aware word representations instead of learning fixed word representations. Another model is bidirectional encoder representations from transformers (BERT), based on a highly parallelizable Transformer architecture with a self-attention mechanism.

[0055] Scaling a PLM (e.g., scaling the model size or data size) typically improves the model's capabilities for downstream tasks. Generally, a large language model (LLM) refers to a Transformer language model with hundreds of billions (or more) parameters, trained on massive amounts of text data, such as generative pre-trained transformer (GPT)-3, Galactica, etc.

[0056] LLM demonstrates a powerful ability to understand natural language and solve complex tasks (through text generation).

[0057] Software development environments can include source code editors and other tools that developers use to write and test their programs. Some software development environments include code completion features that help automatically display a list of possible candidates based on one or more characters (e.g., letters, symbols, etc.) that the developer types in the source code editor while editing code. A pop-up menu may appear with several suggested code elements that the developer can use. This assistance is beneficial because it speeds up development and reduces common errors such as typos.

[0058] LLMs (such as Copilot and Tabnine) are commonly used for natural language generation, but they can also be applied to source code completion and generation tasks. These models are trained on large amounts of source code to learn the inherent patterns and structures of programming languages. LLM processing of source code generation tasks may include the following steps: (1) Create a dataset. Obtain a large dataset of source code snippets from various programming languages ​​to train an LLM for source code generation. This dataset can be obtained from open-source projects or other publicly available code repositories.

[0059] (2) Model building. LLMs applied to source code generation tasks can be built using the Transformer network architecture. The Transformer model is a deep learning model that excels at capturing long-term dependencies and relationships in data sequences and can be used for source code generation tasks.

[0060] (3) Training the model. During the training process, the LLM can take input sequences (e.g., tokens representing fragments of source code) and predict the next most likely token given the context. The LLM can then be fine-tuned using techniques such as unsupervised learning and maximum likelihood estimation to optimize its ability to generate accurate and relevant source code.

[0061] (4) Code generation: After training, LLM can generate source code by accepting user input such as source code snippets and / or context descriptions. LLM can predict source code and suggest completion by sampling or sorting the most likely token sequences after the input.

[0062] For example, an LLM can examine contextual information in user input, such as surrounding code, variable types, and method signatures, to understand the current programming context. Based on this context, the LLM predicts which code to generate next. The LLM can then generate autocomplete options appropriate for the current context, such as variable names, function calls, or conditional statements. The LLM can then synthesize suggested source code snippets based on the programming languages ​​and patterns it has learned, generating completion suggestions. The generated source code or completion suggestions are then presented to the user as recommendations or autocomplete options in an integrated development environment (IDE) or code editor. Users can evaluate, modify, or accept the generated source code or completion suggestions based on their specific needs.

[0063] (5) Fine-tuning and feedback loops. By utilizing user feedback, the generated source code suggestions are continuously adjusted over time. When a user selects or modifies a source code suggestion, this feedback is used to update the LLM's parameters, thereby helping the LLM improve its predictions and become more suitable for the user's specific needs.

[0064] (6) Deployment and Integration: After training and fine-tuning, LLM can be deployed as a plugin, extension, or integrated into code editors and IDEs. This integration allows users to directly benefit from the suggestions and completions generated by LLM in their coding environment.

[0065] However, automatic code completion features may provide average or general code suggestions that are consistent with prevalent patterns in the training data, which may be unrelated to the source code entered by the developer. In other words, the generated source code has low accuracy, so developers may have to sift through a large list of candidates to find relevant code. This drawback of LLM can lead to the following problems: (1) Wasting time Users (such as developers) may spend a significant portion of their total session time merely reviewing and editing LLM-generated source code suggestions, and may spend more than half of their total session time on LLM-related activities. In other words, LLM-generated source code suggestions actually reduce users' programming efficiency.

[0066] (2) Security vulnerabilities LLMs may recommend insecure and malicious code, or even exploit vulnerabilities. In other words, using LLMs to generate source code can introduce security vulnerabilities, especially when the LLM is exposed to malicious or insecure source code during training. Careful review and verification of any source code generated by these LLMs for potential security vulnerabilities is crucial. Therefore, users must implement appropriate monitoring and establish verification mechanisms to prevent such vulnerabilities. Additionally, users may need to dedicate time to reviewing and verifying the generated source code to ensure that no security vulnerabilities are introduced.

[0067] (3) Logical error LLMs can struggle to understand the underlying logic or purpose of the source code they generate because they rely on patterns and examples in the training data, which may not always capture the true intent of the source code. Therefore, the generated source code may be functionally incorrect or exhibit unexpected behavior. Consequently, users must thoroughly test the generated source code to ensure its behavior matches expectations.

[0068] (4) Legal considerations Using LLM to generate source code can raise legal issues, such as potential plagiarism or intellectual property infringement. Therefore, users must ensure that the generated code does not violate any legal boundaries.

[0069] (5) Non-optimal code LLM may generate source code that works but is not optimal in terms of performance or efficiency. Because LLM lacks a deep understanding of algorithms or optimization techniques, it may generate computationally expensive or inefficient source code. Therefore, users must review and optimize the generated source code to improve performance. Additionally, the source code generated by LLM may not always follow best coding practices or industry standards.

[0070] In summary, the aforementioned problems can be categorized as the average source code prediction problem in LLMs trained on large open-source datasets. Specifically, LLMs tend to generate average or generic source code suggestions that conform to prevalent patterns in the training data. This problem arises because LLMs primarily learn from common source code snippets rather than considering innovative or context-specific schemes. Consequently, LLMs may struggle to provide unique and optimized source code suggestions, thus limiting their ability to effectively assist users. Therefore, improving the accuracy of generated source code has become a pressing issue.

[0071] Therefore, this application provides a source code generation method. This method is a combination of intelligent machine learning-based source code generation and knowledge graph-based recommendation. In this method, a finite number of candidate source code fragments are generated by constraining the search space of a static analysis tool. These candidate fragments are then fed into a Hierarchical-SoftMax classifier model to filter out irrelevant candidate fragments based on the code attributes of the code in the user's target fragment; these irrelevant candidate fragments are predicted based on the source code fragment input by the user. The following will combine... Figure 2 The method provided in this application is described.

[0072] Figure 2 A schematic flowchart of a method 200 according to an embodiment of this application is shown. This method 200 can be applied to the system provided in this application.

[0073] The system provided in this application is a combined system comprising a machine learning (ML) source code sequence generator and a knowledge graph recommender. The knowledge graph recommender is based on SRS, where user-item pairs in the SRS are replaced with source code fragments (e.g., method calls or variable declarations). The system provided in this application involves using a sequence recommender system to replace traditional neural language models with limited vocabulary, thereby selecting recommended fragments from candidate fragments obtained from the ML source code sequence generator. Taking into account all the above factors (limiting the search space of static analysis tools to limit the number of proposals), a sequence recommendation system model is implemented.

[0074] At S210, the system determines the target features based on the first segment.

[0075] The first segment may include one or more codes entered by the user before a first moment. The first moment may be the current moment when the system determines the first feature, or it may be a moment before the current moment; this application does not limit this. In some embodiments, the first segment may include codes entered by the user during a first time period between a third moment and the first moment, where the third moment is a moment earlier than the first moment.

[0076] Target features can be used to indicate code attributes within a code segment. Code attributes can include Abstract Syntax Tree (AST) attributes, Control Flow Graph (CFG) attributes, and Program Dependency Graph (PDG) attributes. An AST is a data structure used in computer science to represent the structure of a program or source code segment, where each node represents a structure appearing in the program or source code segment. A CFG uses graphical notation to represent all paths that a program might traverse during execution, where each node represents a basic block. For a linear source code segment without any jumps or jump targets, a jump target begins a block, and a jump ends a block. Directed edges are used to represent jumps in the control flow. In most representations, there are two specifically designated blocks: the entry block and the exit block. Control enters the flow graph through the entry block, and all control flow exits through the exit block. A PDG is used to represent cases where program statements (instructions) reference data from the previous statement. In other words, target features are determined based on a deep understanding of the algorithms and techniques used to generate the user-input source code.

[0077] The search space of static analysis tools limits the length of sequence proposals, which makes it easy to present them in the form of an abstract semantic graph (ASG).

[0078] Figure 3 An example of ASG is shown. ASG is a simplified and more human-like perceptual representation of CPG, where a program or source code segment is represented by a graph whose vertices are the children of the program or source code segment. For example... Figure 3 As shown, compared to AST, ASG is at a higher level of abstraction and is used to represent the syntactic structure of a program or source code fragment. ASG is more complex and concise than AST because it may include shared sub-items from CFP and PDG.

[0079] In some embodiments of this application, the system can obtain a first ASG, wherein each vertex is associated with a sub-item in a first segment, and each vertex includes a first attribute, a second attribute, and a third attribute. The system can determine at least one new vertex based on the first ASG, wherein the at least one new vertex is used to link to the first ASG. The system can then determine the first attribute, second attribute, and third attribute of the at least one new vertex as target features.

[0080] The first attribute indicates the attribute characteristics of the child item associated with the vertex in the abstract syntax tree; the second attribute indicates the attribute characteristics of the child item associated with the vertex in the control flow graph; and the third attribute indicates the attribute characteristics of the child item associated with the vertex in the program dependency graph. The three attributes of the ASG vertex provided in this application are shown in Table 1.

[0081] Table 1

[0082] According to the above technical solution, ASG can not only be used to represent the syntax of source code fragments, but also includes information about the control flow and program dependencies of the source code fragments. Using ASG to represent user-input source code fragments can solve the average code prediction problem in the worst case or to the maximum extent by utilizing neural symbolic substitution for the f-attention mechanism. Therefore, the acquired target features can more accurately reflect the user's sequence preferences.

[0083] The process of inputting source code can be viewed as the ASG growing step by step, linking new vertices to existing vertices in the ASG. As new vertices are linked to the ASG, the vector representation of the ASG changes over time; this can be called sequence embedding. In the case of sequence embedding, a recurrent neural network (RNN) similar to a gated recurrent unit (GRU) can be used. The GRU uses the previous hidden state vectors to predict the properties of new vertices while simultaneously forming new paths in the ASG.

[0084] In some embodiments of this application, determining at least one new vertex based on a first ASG includes: inputting each vertex of the first ASG and the hidden state vector of the second ASG into a bidirectional recurrent neural network model to determine the hidden state vector of the first ASG, wherein the hidden state vector of the ASG is used to indicate the relationship between each vertex in the ASG; and determining at least one new vertex based on the hidden state vector of the first ASG. Each vertex in the first ASG is associated with a sub-item in a third segment, the third segment including one or more codes entered by the user before a second time step, the second time step being earlier than the first time step. In some embodiments, the third segment may include codes entered by the user during a second time period between the third time step and the second time step, the third time step being earlier than the second time step.

[0085] Figure 4 A schematic diagram of the system's model architecture is shown. (For example...) Figure 4As shown, at each step of ASG growth, the GRU can take the previous hidden state vector and information about the current vertex in the ASG as input. These inputs are combined to create intermediate states. The intermediate states can combine information from the previous hidden states and the current vertex. The GRU unit can use two gates: an update gate and a reset gate. The update gate is used to determine how much of the previous hidden state should be retained in the intermediate state, while the reset gate is used to determine how much of the previous hidden state should be ignored. The intermediate states are then used to update the hidden states for the current step. The hidden states retain information about previously predicted vertices and help capture the dependencies between them. The hidden states act as the network's memory and can be used to predict the next vertex in the ASG. In other words, the hidden states include information about previously generated vertices and their relationships. By combining the hidden states, the GRU unit can make reliable predictions based on patterns learned from the graph data. In summary, during the sequence generation of ASG, the GRU unit can utilize the previous hidden state vector to capture the dependencies between generated vertices. It combines the hidden states of each step to predict the next vertex and forms new paths in the ASG based on patterns learned from the graph data.

[0086] Based on the above technical solution, codebase environment awareness and time history awareness context can be aggregated through a bidirectional recurrent neural network model. This maximizes the scalability problem and ultimately addresses the diversity problem through statistical aggregation of neural symbolic features. Therefore, the scalability and diversity of the acquired target features can be improved.

[0087] Scalability is a problem that SRS will face as the number of users and items increases. Assuming millions of users and millions of items, the algorithmic complexity of SRS would become prohibitively high. However, SRS must respond to user requests instantly, regardless of user rating history or purchase history, which places high demands on scalability.

[0088] The diversity issue is one that SRS needs to address in order to help users discover new items. However, some traditional algorithms may inadvertently do the opposite, as they tend to recommend popular and highly-rated items favored by specific users. Therefore, new hybrid approaches need to be developed to improve the performance of SRS.

[0089] At S220, the system generates multiple candidate fragments.

[0090] In some embodiments of this application, multiple candidate fragments can be generated based on a user's project, where the user's project includes multiple pieces of code entered by the user. It should be noted that the first fragment is also included in the user's project. In other words, the candidate fragments are generated based on code belonging to the same project as the code currently being edited by the user.

[0091] According to the above technical solution, multiple candidate segments are generated based on the user's project. This avoids the inability to predict code elements or syntax used in the user's project that did not appear during model training (i.e., the out-of-vocabulary (OOV) problem). Therefore, the accuracy of the candidate segments can be improved.

[0092] The Out-of-Voice (OOV) problem in source code completion neural network models refers to situations where the model encounters code elements or syntax it has not encountered before during training. This can prevent the model from providing accurate suggestions or completions for these unknown code components, thus limiting its effectiveness in helping developers complete coding tasks.

[0093] In some embodiments of this application, generating multiple candidate fragments may include: obtaining at least one third ASG, wherein each third ASG is associated with a fragment in the user's project; and generating multiple candidate fragments based on at least one ASG.

[0094] An Abstract Semantic Graph (ASG) can be created for each fragment in a user project, specifically for each Java class described within a separate fragment; this can be referred to as an abstract semantic subgraph for each fragment. Each individual subgraph of each source code fragment in the user project can be aggregated into the final ASG for the entire user project using Bayes' theorem and the maximum likelihood principle. As the source code is automatically expanded (represented as the sequential growth of the current specific abstract semantic subgraph of the edited fragment), dozens of top candidates with the highest probability are selected. These candidate chains are then sorted using a graph recurrent neural network.

[0095] According to the above technical solution, candidate fragments can be obtained from the user's project using graph convolutional ASG, which includes more information about the user's project. Therefore, the accuracy of candidate fragments can be improved.

[0096] At S230, the system selects the second segment from multiple candidate segments based on the target features.

[0097] Among the features of multiple candidate segments, the features of the second segment have the highest similarity to the target features.

[0098] In ASG, the similarity between features of vertices can be represented as the distance between vectors in the same vector space.

[0099] In some embodiments of this application, the system can obtain multiple first vectors corresponding one-to-one with multiple candidate segments, each first vector representing a candidate segment in a first vector space. The first vector space is the vector space containing the second vector, which represents at least one new vertex. Then, the system can select a third vector from the multiple first vectors, where the third vector is the vector with the smallest distance to the second vector in the vector space. Therefore, the system can determine the second segment represented by the third vector in the first vector space.

[0100] According to the above technical solution, feature similarity is reflected as the distance between vectors in the same vector space, allowing each candidate segment to be scored by a hierarchical SoftMax classifier. Using a bidirectional recurrent neural network model to perform Bayesian variational inference on the aggregated features can solve the sparsity problem and ultimately the scalability problem. This improves the scalability of the acquired target features and reduces the cold start problem caused by data sparsity.

[0101] The sparsity issue may arise because the dataset used is so large that the user-item matrix used for filtering can be very large and sparse. Therefore, the performance of SRS may degrade due to the cold start problem caused by data sparsity.

[0102] In some embodiments of this application, the distance to the second vector in the vector space can be obtained based on the Euclidean distance and the Kullback-Leibler (KL) divergence.

[0103] The system can use GRU units to score each first vector based on the distance between each first vector (a representation of each candidate segment in the vector space) and the second vector (a representation of the new vertices of the ASG in the vector space). In this algorithm, Euclidean distance and KL divergence are used for different parts. Euclidean distance is a measure of similarity between two vectors in a high-dimensional space.

[0104] Euclidean distance is calculated using an Euclidean algorithm based on the angle between vectors, indicating how similar their orientations are. In this algorithm, Euclidean distance is used to measure the pairwise similarity between data points in a high-dimensional space.

[0105] KL divergence is a measure of the dissimilarity between two probability distributions. It quantifies the difference between one distribution and another. In this algorithm, KL divergence is used to measure the dissimilarity between pairwise similarities of data points in a high-dimensional space and pairwise similarities in a low-dimensional space.

[0106] The goal of this algorithm is to preserve the pairwise similarity between data points when projecting them from a high-dimensional space to a low-dimensional space. This is achieved by minimizing the KL divergence between pairwise similarities in the high-dimensional and low-dimensional spaces. In summary, Euclidean distance is used to measure the similarity between vectors in a high-dimensional space, while KL divergence is used to measure the dissimilarity between pairwise similarities in different spaces, in order to find a suitable low-dimensional representation of the data while preserving their pairwise relationships.

[0107] For example, based on the similarity calculated by this algorithm, vectors representing candidate segments can be ranked in a dynamic recommender system. In a dynamic recommender system, this algorithm can be used to embed high-dimensional vectors representing candidate segments into a low-dimensional vector space. Then, Euclidean distance can be used to calculate pairwise similarity between these embedded vectors. By comparing pairwise similarity, the system can rank these vectors representing candidate segments based on their similarity to the target or reference vectors. This ranking can be used to select the candidate segments most similar to the target or reference. These rankings help determine the relevance and similarity of different candidate segments, allowing the system to suggest closely related source code based on the embedded vector representations of closely related source code. This approach enables the system to provide personalized and relevant recommendations to users based on user preferences and the similarity of candidate segments.

[0108] According to the above technical solution, Euclidean distance is used to measure the similarity between vectors in a high-dimensional vector space, while KL divergence is used to measure the dissimilarity between pairwise similarities in different vector spaces. Therefore, candidate segments can be embedded into the same low-dimensional vector space to rank them. This improves the accuracy of obtaining the second segment from the candidate segments.

[0109] In some embodiments of this application, multiple first vectors can be obtained based on a co-occurrence matrix, wherein the co-occurrence matrix is ​​used to indicate the frequency of occurrence of sub-items in multiple candidate segments and sub-items in the first segment in the same segment.

[0110] Matrix factorization is a method for generating low-dimensional word representations, which can be used to obtain vectors representing candidate segments. This method utilizes a low-rank approximation to decompose large matrices that capture statistical information about the corpus. The specific type of information captured by such matrices varies depending on the application. Statistical information about word occurrences in a corpus is a primary source of information available for all unsupervised methods used to learn word representations.

[0111] GloVe is an efficient matrix factorization model. It represents the matrix of word-word co-occurrence counts as a matrix... , its entries Indicator In words The number of times it appears in the context. Is any word in the word The number of times it appears in the context. Finally, the word In words The probability of appearing in the context can be used express. Figure 5 A schematic diagram of the co-occurrence matrix is ​​shown. Figure 6 A schematic diagram of GloVe is shown.

[0112] According to the above technical solution, multiple first vectors are obtained through global vector representation (GloVe) embedding, which makes it easy to represent candidate fragments in vector space. Therefore, the sparsity problem can be eliminated.

[0113] It should be noted that the GloVe-based matrix factorization is just one example of representing candidate fragments as vectors in a vector space. Candidate fragments can be represented as vectors based on other methods, such as neural link prediction, neural collaborative filtering, Funk SVD, restricted Boltzmann machines, Bayesian personalized ranking, etc., and this application does not limit this.

[0114] Figure 7 A schematic flowchart illustrating source code generation is shown. For example... Figure 7 As shown, the system provided in this application consists of a knowledge base for statistical code analysis of the entire user project. A statistical proposal generator suggests semantically based preference completion variants with additional GloVe embeddings. Sequence preferences are evaluated based on the temporal context of the user-input source code, represented in ASG format. In summary, the system provided in this application aggregates codebase environment awareness (the code model obtained from the user project via graph convolutional ASG) and temporal history awareness (from user input) context through a bidirectional recurrent neural network model (GRU unit).

[0115] In this application, the target features are obtained based on the user-input source code, serving as the user's sequence preferences. The source code suggestions provided to the user are generated based on these preferences. In other words, the generated source code is related to the user-input source code. Therefore, the accuracy of the generated source code can be improved.

[0116] The method according to the embodiments of this application has been described in detail above. The following will refer to... Figures 8 to 11 This application describes an apparatus according to embodiments thereof. The apparatus described below is capable of performing the methods described in the embodiments of this application. For the sake of brevity, repeated descriptions are appropriately omitted when introducing the apparatus in the embodiments of this application.

[0117] Figure 8 This is a schematic block diagram of an apparatus 800 according to an embodiment of this application. Figure 8 The device 800 shown can be used to perform Figure 2 The method shown.

[0118] like Figure 8 As shown, the device 800 includes: The determining module 810 is used to determine target features based on the first fragment, wherein the first fragment includes one or more codes entered by the user before a first moment, and the target features are used to indicate the code attributes of the codes in the fragment; Generation module 820 is used to generate multiple candidate fragments; Selection module 830 is used to select a second segment from multiple candidate segments based on target features, wherein the features of the second segment have the highest similarity to the target features among the features of the multiple candidate segments.

[0119] Optionally, the determining module 810 is configured to: obtain a first abstract semantic graph (ASG), wherein each vertex in the first ASG is associated with a sub-item in a first segment, and the vertex includes a first attribute, a second attribute, and a third attribute, wherein the first attribute is used to indicate the attribute features of the sub-item associated with the vertex in the abstract syntax tree, the second attribute is used to indicate the attribute features of the sub-item associated with the vertex in the control flow graph, and the third attribute is used to indicate the attribute features of the sub-item associated with the vertex in the program dependency graph; determine at least one new vertex based on the first ASG, wherein the at least one new vertex is used to link to the first ASG; and determine a target feature, wherein the target feature includes the first attribute of at least one new vertex, the second attribute of at least one new vertex, and the third attribute of at least one new vertex.

[0120] Optionally, the determining module 810 is configured to: input each vertex in the first ASG and the hidden state vector of the second ASG into a bidirectional recurrent neural network model to determine the hidden state vector of the first ASG, wherein the hidden state vector of the first ASG indicates the relationship between each vertex in the first ASG, the hidden state vector of the second ASG indicates the relationship between each vertex in the second ASG, each vertex in the first ASG is associated with a sub-item in a third segment, the third segment including one or more codes entered by the user before a second time step, the second time step being earlier than the first time step; and determine at least one new vertex based on the hidden state vector of the first ASG.

[0121] Optionally, the selection module 830 is used to: obtain a plurality of first vectors, wherein the plurality of first vectors correspond one-to-one with a plurality of candidate segments, each first vector is used to represent a candidate segment in a first vector space, the first vector space is the vector space where the second vector is located, and the second vector is used to represent at least one new vertex; select a third vector from the plurality of first vectors, wherein the third vector is the vector among the plurality of first vectors that has the smallest distance to the second vector in the vector space; and determine a second segment, wherein the second segment is represented by the third vector in the first vector space.

[0122] Optionally, the distance to the second vector in the vector space is obtained based on the Euclidean distance and the Kullback-Leibler (KL) divergence.

[0123] Optionally, the multiple first vectors are obtained based on a co-occurrence matrix, which is used to indicate the frequency of occurrence of items in the multiple candidate segments and items in the first segment in the same segment.

[0124] Optionally, multiple candidate fragments are generated based on the user's project, where the user's project includes multiple codes entered by the user, and the user's project includes the first fragment.

[0125] Optionally, the generation module 820 is used to: obtain at least one third ASG, wherein each third ASG is associated with a fragment in the user's project; and generate multiple candidate fragments based on at least one ASG.

[0126] For a detailed description, please refer to the methods mentioned above, which will not be repeated here.

[0127] The term "module" used in this document can be implemented in software and / or hardware without particular limitation. For example, a "module" can be a software program, a hardware circuit, or a combination of the above functions. Taking module 810 as an example, the implementation of module 810 will be described below. Similarly, the implementation of other modules can refer to the implementation of module 810.

[0128] As an example of a software functional unit, module 810 may include code running on a compute instance. A compute instance may include at least one of a physical host (compute device), a virtual machine, or a container. Furthermore, the aforementioned compute instance may be one or more compute instances. For example, module 810 may include code running on multiple hosts / virtual machines / containers. The multiple hosts / virtual machines / containers used to run the code may be located in the same region or in different regions. Furthermore, the multiple hosts / virtual machines / containers used to run the code may be located within the same availability zone (AZ) or in different AZs, each AZ comprising one data center or multiple geographically proximate data centers. Typically, a region may include multiple AZs.

[0129] Similarly, multiple hosts / virtual machines / containers used to run code can be distributed within the same virtual private cloud (VPC) or across multiple VPCs. A VPC can be set up within a region. Communication between two VPCs within the same region, as well as cross-region communication between VPCs in different regions, requires a communication gateway to be set up within each VPC to enable inter-VPC communication.

[0130] As an example of a hardware functional unit, the determination module 810 may include at least one computing device, such as a server. Alternatively, the determination module 810 may also be a device implemented using an application-specific integrated circuit (ASIC) or a programmable logic device (PLD). The aforementioned PLD may be a complex programmable logic device (CPLD), a field-programmable gate array (FPGA), a general array logic (GAL), or any combination thereof.

[0131] The determination module 810 includes multiple computing devices, which can be distributed in the same region or in different regions. Similarly, the determination module 810 includes multiple computing devices, which can be distributed within the same Availability Zone (AZ) or between different AZs. Likewise, the determination module 810 includes multiple computing devices, which can be distributed within the same Virtual Private Cloud (VPC) or between multiple VPCs. These multiple computing devices can be any combination of computing devices such as servers, ASICs, PLDs, CPLDs, FPGAs, and GALs.

[0132] In other embodiments, the determining module 810 can be used to perform any step in the source code generation method, the generating module 820 can be used to perform any step in the source code generation method, and the selecting module 830 can be used to perform any step in the source code generation method. The steps responsible for implementing each module can be specified as needed, and different steps in the source code generation method can be implemented by each module to achieve all the functions of the device 800.

[0133] This application also provides a computing device 1000. For example... Figure 9 As shown, the computing device 1000 includes a bus 1002, a processor 1004, a memory 1006, and a communication interface 1008. The processor 1004, memory 1006, and communication interface 1008 communicate via the bus 1002. The computing device 1000 can be a server or a terminal device. It should be understood that this application does not limit the number of processors and memory in the computing device 1000.

[0134] Bus 1002 can be a peripheral component interconnect (PCI) bus or an extended industry standard architecture (EISA) bus, etc. Buses can be categorized as address buses, data buses, control buses, etc. For ease of representation, Figure 9 The bus 1002 may use only one line, but this does not mean that there is only one bus or one type of bus. The bus 1002 may include a path for transmitting information between various components of the computing device 1000 (e.g., memory 1006, processor 1004, communication interface 1008).

[0135] The processor 1004 may include any one or more of a central processing unit (CPU), a graphics processing unit (GPU), a microprocessor (MP), and a digital signal processor (DSP).

[0136] The memory 1006 may include volatile memory, such as random access memory (RAM). The processor 1004 may also include non-volatile memory, such as read-only memory (ROM), flash memory, hard disk drive (HDD), or solid state drive (SSD).

[0137] The memory 1006 stores executable program code, and the processor 1004 executes the executable program code to implement the functions of the determining module 810, the generating module 820, and the selecting module 830, thereby realizing the source code generation method. In other words, the instructions for executing the source code generation method are stored in the memory 1006.

[0138] The communication interface 1008 uses a transceiver module, such as, but not limited to, a network interface card and a transceiver, to enable communication between the computing device 1000 and other devices or communication networks.

[0139] This application also provides a computing device cluster. The computing device cluster includes at least one computing device. The computing device may be a server, such as a central server, an edge server, or a local server in a local data center. In some embodiments, the computing device may also be a terminal device such as a desktop computer, a laptop computer, or a smartphone.

[0140] like Figure 10 As shown, the computing device cluster includes at least one computing device 1000. The memory 1006 in one or more computing devices 1000 within the computing device cluster can store the same instructions for executing the source code generation method.

[0141] In some possible implementations, the memory 1006 of one or more computing devices 1000 in the computing device cluster may also store partial instructions for executing the source code generation method. In other words, a combination of one or more computing devices 1000 can jointly execute instructions for executing the source code generation method.

[0142] The memory 1006 in different computing devices 1000 within the computing device cluster can store different instructions, which are used to execute some functions of the source code generation device. That is, the instructions stored in the memory 1006 of different computing devices 1000 can implement the functions of one or more modules among the determination module 810, generation module 820, and selection module 830.

[0143] In some possible implementations, one or more computing devices in a computing device cluster can be connected via a network. The network can be a wide area network (WAN), a local area network (LAN), etc.

[0144] Figure 11 One possible implementation is shown. For example... Figure 11As shown, two computing devices 1000A and 1000B are connected via a network. Specifically, computing devices 1000A and 1000B are connected to the network through communication interfaces in various computing devices. In this possible implementation, the memory 1006 in computing device 1000A stores instructions for performing the functions of the determination module 810. Simultaneously, the memory 1006 in computing device 1000B stores instructions for performing the functions of the generation module 820 and the selection module 830.

[0145] This application also provides a computer program product. When instructions are executed by a cluster of computing devices, the cluster of computing devices performs any of the methods described above.

[0146] This application also provides a computer-readable storage medium that stores one or more instructions. When one or more instructions are executed by a computing device cluster, the computing device cluster performs any of the methods described above.

[0147] Those skilled in the art will recognize that, based on the examples described in the embodiments disclosed herein, the units and algorithm steps can be implemented using electronic hardware or a combination of computer software and electronic hardware. Whether a function is executed using hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but this should not be considered beyond the scope of this application.

[0148] Those skilled in the art will understand that, for convenience and brevity, the detailed working process of the above-described systems, devices, and units can be referred to the corresponding process in the above-described method embodiments, and will not be repeated here.

[0149] In the several embodiments provided in this application, the disclosed systems, apparatuses, and methods can be implemented in other ways. For example, the described apparatus embodiments are merely examples. For instance, unit partitioning is a logical functional partitioning, and other partitioning methods can be used in actual embodiments. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not performed. Furthermore, the mutual coupling or direct coupling or communication connection shown or discussed can be implemented using various communication interfaces. Indirect coupling or communication connection between devices or units can be implemented electronically, mechanically, or otherwise.

[0150] The units described as separate parts may or may not be physically separate. The parts shown as units may or may not be physical units; that is, these parts may be located in one unit or distributed across multiple network units. Some or all of the units can be selected based on actual needs to achieve the purpose of the embodiment.

[0151] Furthermore, the functional units in the embodiments of this application can be integrated into a processing unit. Each of these units can exist physically independently, or two or more units can be integrated into one unit.

[0152] When these functions are implemented as software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. The technical solution of this application can be implemented as a software product. The software product is stored in a storage medium and includes several instructions to instruct a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the embodiments of this application. The aforementioned storage medium includes any medium capable of storing program code, such as a USB flash drive, removable hard disk, read-only memory (ROM), random access memory (RAM), magnetic disk, or optical disk, etc.

[0153] The above description is merely a specific embodiment of this application and is not intended to limit the scope of protection of this application. Any variations or substitutions that are readily conceived by those skilled in the art within the scope of the technology disclosed in this application should be included within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.

Claims

1. A source code generation method, characterized in that, include: Target features are determined based on a first segment, wherein the first segment includes one or more codes entered by the user before a first moment, and the target features are used to indicate the code attributes of the codes in the segment; Generate multiple candidate fragments; Based on the target features, a second segment is selected from the plurality of candidate segments, wherein the features of the second segment have the highest similarity to the target features among the features of the plurality of candidate segments.

2. The method according to claim 1, characterized in that, The step of determining the target features based on the first segment includes: Obtain a first abstract semantic graph (ASG), wherein each vertex in the first ASG is associated with a sub-item in the first fragment, and the vertex includes a first attribute, a second attribute, and a third attribute. The first attribute is used to indicate the attribute features of the sub-item associated with the vertex in the abstract syntax tree, the second attribute is used to indicate the attribute features of the sub-item associated with the vertex in the control flow graph, and the third attribute is used to indicate the attribute features of the sub-item associated with the vertex in the program dependency graph. At least one new vertex is determined based on the first ASG, wherein the at least one new vertex is used to link to the first ASG; The target features are determined, wherein the target features include a first attribute of the at least one new vertex, a second attribute of the at least one new vertex, and a third attribute of the at least one new vertex.

3. The method according to claim 2, characterized in that, The step of determining at least one new vertex based on the first ASG includes: Each vertex in the first ASG and the hidden state vector of the second ASG are input into a bidirectional recurrent neural network model to determine the hidden state vector of the first ASG, wherein the hidden state vector of the first ASG indicates the relationship between each vertex in the first ASG, the hidden state vector of the second ASG indicates the relationship between each vertex in the second ASG, and each vertex in the first ASG is associated with a sub-item in a third segment, the third segment including one or more codes input by the user before a second time step earlier than the first time step. The at least one new vertex is determined based on the hidden state vector of the first ASG.

4. The method according to claim 2 or 3, characterized in that, The step of selecting a second segment from the plurality of candidate segments based on the target feature includes: Obtain multiple first vectors, wherein each of the multiple first vectors corresponds one-to-one with the multiple candidate segments, each first vector is used to represent a candidate segment in a first vector space, the first vector space is the vector space where the second vector is located, and the second vector is used to represent the at least one new vertex; A third vector is selected from the plurality of first vectors, wherein the third vector is the vector among the plurality of first vectors that has the smallest distance to the second vector in the vector space; Determine the second segment, wherein the second segment is represented by the third vector in the first vector space.

5. The method according to claim 4, characterized in that, The similarity with the second vector in the vector space is obtained based on Euclidean distance and Kullback-Leibler divergence.

6. The method according to claim 4 or 5, characterized in that, The plurality of first vectors are obtained based on a co-occurrence matrix, which is used to indicate the frequency of occurrence of sub-items in the plurality of candidate segments and sub-items in the first segment in the same segment.

7. The method according to any one of claims 1 to 6, characterized in that, The multiple candidate fragments are generated based on the user's project, which includes multiple codes entered by the user, and the user's project includes the first fragment.

8. The method according to claim 7, characterized in that, The generation of multiple candidate fragments includes: Obtain at least one third ASG, wherein each third ASG is associated with a fragment in the user's project; The plurality of candidate fragments are generated based on the at least one ASG.

9. A source code generation apparatus, characterized in that, include: A determining module is configured to determine target features based on a first fragment, wherein the first fragment includes one or more codes entered by a user before a first moment, and the target features are used to indicate the code attributes of the codes in the fragment; The generation module is used to generate multiple candidate fragments; The selection module is used to select a second segment from the plurality of candidate segments based on the target features, wherein the features of the second segment have the highest similarity to the target features among the features of the plurality of candidate segments.

10. The apparatus according to claim 9, characterized in that, The determining module is used for: Obtain a first abstract semantic graph (ASG), wherein each vertex in the first ASG is associated with a sub-item in the first fragment, and the vertex includes a first attribute, a second attribute, and a third attribute. The first attribute is used to indicate the attribute features of the sub-item associated with the vertex in the abstract syntax tree, the second attribute is used to indicate the attribute features of the sub-item associated with the vertex in the control flow graph, and the third attribute is used to indicate the attribute features of the sub-item associated with the vertex in the program dependency graph. At least one new vertex is determined based on the first ASG, wherein the at least one new vertex is used to link to the first ASG; The target features are determined, wherein the target features include a first attribute of the at least one new vertex, a second attribute of the at least one new vertex, and a third attribute of the at least one new vertex.

11. The apparatus according to claim 10, characterized in that, The determining module is used for: Each vertex in the first ASG and the hidden state vector of the second ASG are input into a bidirectional recurrent neural network model to determine the hidden state vector of the first ASG, wherein the hidden state vector of the first ASG indicates the relationship between each vertex in the first ASG, the hidden state vector of the second ASG indicates the relationship between each vertex in the second ASG, and each vertex in the first ASG is associated with a sub-item in a third segment, the third segment including one or more codes input by the user before a second time step earlier than the first time step. The at least one new vertex is determined based on the hidden state vector of the first ASG.

12. The apparatus according to claim 10 or 11, characterized in that, The selection module is used for: Obtain multiple first vectors, wherein each of the multiple first vectors corresponds one-to-one with the multiple candidate segments, each first vector is used to represent a candidate segment in a first vector space, the first vector space is the vector space where the second vector is located, and the second vector is used to represent the at least one new vertex; A third vector is selected from the plurality of first vectors, wherein the third vector is the vector among the plurality of first vectors that has the smallest distance to the second vector in the vector space; Determine the second segment, wherein the second segment is represented by the third vector in the first vector space.

13. The apparatus according to claim 12, characterized in that, The similarity with the second vector in the vector space is obtained based on Euclidean distance and Kullback-Leibler divergence.

14. The apparatus according to claim 12 or 13, characterized in that, The plurality of first vectors are obtained based on a co-occurrence matrix, which is used to indicate the frequency of occurrence of sub-items in the plurality of candidate segments and sub-items in the first segment in the same segment.

15. The apparatus according to any one of claims 9 to 14, characterized in that, The multiple candidate fragments are generated based on the user's project, which includes multiple codes entered by the user, and the user's project includes the first fragment.

16. The apparatus according to claim 15, characterized in that, The generation module is used for: Obtain at least one third ASG, wherein each third ASG is associated with a fragment in the user's project; The plurality of candidate fragments are generated based on the at least one ASG.

17. A computing device cluster, characterized in that, The system includes at least one computing device, wherein each computing device includes a processor and a memory, the processor of the at least one computing device being configured to execute instructions stored in the memory of the at least one computing device, and the cluster of computing devices being capable of executing the method according to any one of claims 1 to 8.

18. A computer-readable storage medium comprising one or more instructions, characterized in that, When the one or more instructions are run on a computing device cluster, the computing device cluster is used to perform the method according to any one of claims 1 to 8.

19. A computer program product comprising instructions, characterized in that, When the instructions are run on a computing device cluster, the computing device cluster is able to execute the method according to any one of claims 1 to 8.