Code processing method and apparatus, electronic device, and storage medium
By generating and encoding code semantic graphs, the accuracy and efficiency issues of existing code search engines in large-scale code repositories and complex business scenarios are solved, enabling flexible and accurate code search.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- TENCENT TECHNOLOGY (SHENZHEN) CO LTD
- Filing Date
- 2022-10-31
- Publication Date
- 2026-07-21
AI Technical Summary
Existing code search engines struggle to provide flexible and accurate search services when faced with large-scale code repositories and complex business scenarios.
By obtaining the word segmentation results and program dependency graph of the code snippet, and combining them with the syntactic analysis graph, a code semantic graph is generated. This graph is then encoded to obtain the target code embedding vector, which is used for natural language search.
It improves the accuracy and efficiency of code search, adapts to the query needs of large-scale code repositories and complex business scenarios, and improves R&D efficiency.
Smart Images

Figure CN116991412B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technology, and in particular to a code processing method, apparatus, electronic device, and storage medium. Background Technology
[0002] With the proliferation of internet applications, the code that implements these applications has become increasingly complex and diverse, making efficient manipulation of large amounts of code a significant concern. For example, code search operations: currently, code search engines based on code retrieval tools generally support keyword search, full-text search, and regular expression search capabilities. However, with the increasing size of code repositories, the growing complexity of business scenarios, and the diversification of functional modules, existing code search engine capabilities are no longer sufficient to provide flexible and accurate search services. Summary of the Invention
[0003] In view of the aforementioned technical problems, this application proposes a code processing method, apparatus, electronic device, and storage medium.
[0004] According to one aspect of this application, a code processing method is provided, the method comprising:
[0005] Obtain multiple code snippets to be processed and the corresponding code description information for each code snippet, wherein the code description information includes parameter description information and return value description information;
[0006] Based on the word segmentation results of each code segment, generate the code segmentation sequence corresponding to each code segment and the program dependency graph corresponding to each code segment;
[0007] The text dependency relationships in the parameter description information and the return value description information are analyzed respectively to obtain the first syntactic analysis graph corresponding to the parameter description information and the second syntactic analysis graph corresponding to the return value description information;
[0008] The program dependency graph, the first syntactic analysis graph, and the second syntactic analysis graph are fused together to obtain the code semantic graph corresponding to each code segment.
[0009] The code semantic graph and the code word segmentation sequence are encoded to obtain the target code embedding vector corresponding to each code fragment; the target code embedding vector is used to perform preset operations on the code based on natural language.
[0010] According to another aspect of this application, a code processing apparatus is provided, comprising:
[0011] The acquisition module is used to acquire multiple code snippets to be processed and the code description information corresponding to each code snippet, wherein the code description information includes parameter description information and return value description information.
[0012] The word segmentation module is used to generate the code segmentation sequence corresponding to each code segment and the program dependency graph corresponding to each code segment based on the word segmentation results of each code segment.
[0013] The syntactic analysis module is used to analyze the text dependency relationships in the parameter description information and the return value description information respectively, to obtain a first syntactic analysis graph corresponding to the parameter description information and a second syntactic analysis graph corresponding to the return value description information;
[0014] The code semantic graph acquisition module is used to fuse the program dependency graph, the first syntactic analysis graph and the second syntactic analysis graph to obtain the code semantic graph corresponding to each code segment.
[0015] The code embedding processing module is used to encode the code semantic graph and the code word segmentation sequence to obtain the target code embedding vector corresponding to each code fragment; the target code embedding vector is used to perform preset operations on the code based on natural language.
[0016] According to another aspect of this application, an electronic device is provided, comprising: a processor; a memory for storing processor-executable instructions; wherein the processor is configured to perform the above-described method.
[0017] According to another aspect of this application, a non-volatile computer-readable storage medium is provided, on which computer program instructions are stored, wherein the computer program instructions, when executed by a processor, implement the above-described method.
[0018] According to another aspect of this application, a computer program product is provided, including computer instructions that, when executed by a processor, cause a computer to perform the above-described method.
[0019] By fusing the program dependency graph, the first syntactic analysis graph, and the second syntactic analysis graph, a code semantic graph corresponding to each code segment is obtained. This effectively extracts structural information from the code segments. Furthermore, by using dependency parsing techniques from syntactic analysis, structural information from natural language descriptions can be effectively extracted. By fusing the syntactic analysis graphs corresponding to parameter description information and return value description information into the program dependency graph, the semantic gap between code language and natural language can be overcome. Moreover, parameter description information and return value description information can effectively represent the input and output information of the code, enabling the code semantic graph to accurately express the semantic information of the code segments.
[0020] Furthermore, the code semantic graph and code segmentation sequence are encoded to obtain the target code embedding vector corresponding to each code segment. This allows the target code embedding vector to better balance the structural and sequence information of the code segment, thereby improving the accuracy of the embedding representation of the code segment.
[0021] Furthermore, the precise representation of code snippets based on embedded vectors can improve search efficiency, thereby improving R&D efficiency, and also enhance the accuracy of code searches when faced with increasingly large code repositories and increasingly complex functional and business scenarios.
[0022] Other features and aspects of this application will become clear from the following detailed description of exemplary embodiments with reference to the accompanying drawings. Attached Figure Description
[0023] The accompanying drawings, which are included in and form part of this specification, illustrate exemplary embodiments, features, and aspects of this application together with the specification and serve to explain the principles of this application.
[0024] Figure 1 This diagram illustrates an application system provided according to an embodiment of the present application.
[0025] Figure 2 This diagram illustrates a training architecture for a target code encoding model and a target query encoding model provided according to an embodiment of this application.
[0026] Figure 3 The diagram shows a training flowchart of a target code encoding model and a target query encoding model provided according to an embodiment of this application.
[0027] Figure 4 This diagram illustrates a program dependency graph according to an embodiment of the present application.
[0028] Figure 5 This illustration shows a syntactic analysis diagram according to an embodiment of the present application. Figure 1 .
[0029] Figure 6 This illustration shows a syntactic analysis diagram according to an embodiment of the present application. Figure 2 .
[0030] Figure 7 This illustration shows a syntactic analysis diagram according to an embodiment of the present application. Figure 3 .
[0031] Figure 8 A flowchart is shown illustrating a code processing method according to an embodiment of this application.
[0032] Figure 9This diagram illustrates a block diagram of a code processing apparatus according to an embodiment of the present application.
[0033] Figure 10 This diagram illustrates an electronic device for code processing according to an embodiment of the present application. Detailed Implementation
[0034] Various exemplary embodiments, features, and aspects of this application will now be described in detail with reference to the accompanying drawings. The same reference numerals in the drawings denote elements that have the same or similar functions. Although various aspects of the embodiments are shown in the drawings, they are not necessarily drawn to scale unless specifically indicated otherwise.
[0035] The term “exemplary” as used herein means “serving as an example, embodiment, or illustration.” Any embodiment illustrated herein as “exemplary” is not necessarily to be construed as superior to or better than other embodiments.
[0036] Furthermore, to better illustrate this application, numerous specific details are provided in the following detailed embodiments. Those skilled in the art should understand that this application can be implemented 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 application.
[0037] Artificial intelligence (AI) is the theory, methods, technology, and application systems that use digital computers or computers-controlled machines to simulate, extend, and expand human intelligence, perceive the environment, acquire knowledge, and use that knowledge to achieve optimal results. AI software technology mainly includes computer vision, speech processing, natural language processing, and machine learning / deep learning.
[0038] In recent years, with the research and progress of artificial intelligence technology, artificial intelligence technology has been widely used in many fields. The solutions provided in the embodiments of this application involve technologies such as machine learning / deep learning, which are specifically illustrated through the following embodiments.
[0039] Please see Figure 1 , Figure 1 This diagram illustrates an application system according to an embodiment of this application. The application system can be used in the code processing method of this application. Figure 1 As shown, the application system may include at least server 01 and terminal 02.
[0040] In this embodiment of the application, the server 01 can be used for code processing. The server 01 may include an independent physical server, a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, CDN (Content Delivery Network), and big data and artificial intelligence platforms.
[0041] In this embodiment, the terminal 02 can be used to trigger code processing or to perform code queries via natural language. The terminal 02 may include physical devices such as smartphones, desktop computers, tablets, laptops, smart speakers, digital assistants, augmented reality (AR) / virtual reality (VR) devices, and smart wearable devices. The physical device may also include software running on it, such as applications. In this embodiment, the operating system running on the terminal 02 may include, but is not limited to, Android, iOS, Linux, and Windows.
[0042] In the embodiments described in this specification, the terminal 02 and the server 01 can be directly or indirectly connected through wired or wireless communication, and this application does not limit this connection.
[0043] In a specific embodiment, when server 01 is a distributed system, this distributed system can be a blockchain system. When the distributed system is a blockchain system, it can be formed by multiple nodes (any form of computing device connected to the network, such as servers or user terminals). These nodes form a peer-to-peer (P2P) network. The P2P protocol is an application layer protocol running on top of the Transmission Control Protocol (TCP). In a distributed system, any machine, such as a server or terminal, can join and become a node. A node includes a hardware layer, a middleware layer, an operating system layer, and an application layer. Specifically, the functions of each node in the blockchain system may include:
[0044] 1) Routing: A basic function of nodes used to support communication between nodes.
[0045] In addition to routing capabilities, nodes can also have the following functions:
[0046] 2) Applications are deployed in the blockchain to implement specific business needs. They record data related to the implementation of functions to form record data, carry digital signatures in the record data to indicate the source of the task data, and send the record data to other nodes in the blockchain system. When other nodes successfully verify the source and integrity of the record data, they add the record data to a temporary block.
[0047] It should be noted that in the specific implementation of this application, user-related data is involved. When the following embodiments of this application are applied to specific products or technologies, user permission or consent is required, and the collection, use and processing of related data must comply with the relevant laws, regulations and standards of the relevant countries and regions.
[0048] Figure 2 This diagram illustrates a training architecture for a target code encoding model and a target query encoding model according to an embodiment of this application. Figure 3 This diagram illustrates a training flowchart for a target code encoding model and a target query encoding model according to an embodiment of this application. It should be noted that the following description generally refers to code search and does not limit the application scenarios of this application. In one possible implementation, such as... Figure 3 As shown, the training may include the following steps:
[0049] S301, Obtain multiple sample code snippets and their corresponding sample code description information. The sample code description information may include sample parameter description information, sample return value description information, and function description information.
[0050] In the embodiments of this specification, to provide a natural language code search function, code fragments are vectorized, i.e., converted into corresponding code embedding vectors. This allows for the same natural language vectorization during natural language search, enabling the determination of matching code fragments based on the similarity between vectors, thus achieving a natural language-based code search function. This application selects a neural network model to implement the aforementioned vectorization. Based on this, training samples (or training data) can be obtained to train the neural network to generate a target code encoding model for vectorizing code fragments and a target query encoding model for vectorizing natural language.
[0051] Here, "sample code snippets" refers to code segments used as training samples. For example, sample code can be obtained from a large amount of code stored on a code platform (such as a code search platform or code sharing platform). As an example, the sample code can be divided based on its function to obtain multiple sample code snippets, each corresponding to a function. From a function perspective, sample code snippets can be function code snippets; from a class and file perspective, sample code snippets can be file code snippets; from a project perspective, sample code snippets can be all the code in a project, where a project can be considered a function.
[0052] Furthermore, sample code description information corresponding to each code snippet can be obtained. This sample code description information can include sample parameter description information, sample return value description information, and function description information. The sample code description information can be textual, such as textual explanations or comments, used to provide a textual description of the code. Specifically, sample parameter description information can refer to information describing the parameters in the code; sample return value description information can refer to information describing the return value in the code; and function description information can refer to information describing the function implemented by the code.
[0053] As described above, training data can be designed in the form of (data, label), where data can be sample code snippets and label can be annotation information. At the function level, data can be function code snippets and label can be comments; at the class and file level, data can be file code snippets and label can be doc documents (e.g., javadoc in Java); at the project level, data can be all the code for the project and label can be the project design document. In the overall training data design, label can be natural language and data can be code snippets.
[0054] After obtaining training samples, a neural network model can be trained based on the training data. This application mainly focuses on fitting the mapping relationship between data and labels. The overall training process can be described as follows: Figure 2 As shown, for the code snippet `data`, a sample program dependency graph combining the abstract syntax tree and data flow edges is extracted (corresponding to...). Figure 2The code analysis graph is used in the sample code analysis graph. For the label part, NLP (Natural Language Processing) is used to extract the sample syntactic analysis graph. Then, the sample program dependency graph and the sample syntactic analysis graph are fused to form the sample code semantic graph. Then, the sample structure vector can be extracted by encoding based on graph convolutional neural network, and the sample sequence vectors of data and label can be obtained by using sequence encoder. Then, the similarity is calculated to obtain the loss to train the model. For details, please refer to the introduction below.
[0055] S303, Based on the word segmentation results of each sample code segment, generate the sample code segmentation sequence corresponding to each sample code segment and the sample program dependency graph corresponding to each code segment.
[0056] In the embodiments of this specification, each sample code segment can be segmented into words to obtain the segmentation results. This segmentation can be performed using a segmentation tool; however, this application does not limit the specific segmentation tool used, meaning it does not limit the specific segmentation method. Thus, each segmented word in the segmentation results can be traversed to obtain a sample code segmentation sequence. The segments in this sample code segmentation sequence can be arranged in the order of traversal; this application does not limit the traversal method. For example, the sample code segmentation sequence can be represented as follows: ~ That is, it includes n word segments, where n can be an integer greater than 1.
[0057] As one possible implementation, a sample abstract syntax tree can be generated for each code segment based on the word segmentation results and a predefined syntax. This application does not limit the method of generating the sample abstract syntax tree. Optionally, the nodes in the sample abstract syntax tree can be traversed to obtain the word segmentation sequence of the sample code, where each node refers to a word segment. The traversal method can be depth-first traversal or level-first traversal; this application does not limit this method.
[0058] Furthermore, in an optional implementation, to compensate for the code description information representing definitions, inputs, and outputs such as parameters and return values in the sample abstract syntax tree, edges can be added between sample node pairs in the sample abstract syntax tree of each sample code segment to generate a sample program dependency graph corresponding to each sample code segment. The sample node pairs can include at least one of the following: leaf node pairs in the sample abstract syntax tree, where leaf node pairs are adjacent in the corresponding sample code segments; node pairs corresponding to two variables in assignment statements within sample code segments; and node pairs corresponding to write variables.
[0059] Taking the sample node pairs including the three types of node pairs mentioned above as an example, three types of edges (or data flow edges) can be further extended on the sample abstract syntax tree to form a sample program dependency graph (also known as a code analysis graph). These three types of edges can be: Next Token (next node): connecting each leaf node of the sample abstract syntax tree to its subsequent node, i.e., leaf node pairs in the sample abstract syntax tree, where leaf node pairs are adjacent in the corresponding sample code snippet; Computedfrom: connecting all left-hand and right-hand variables appearing in assignment statements, i.e., node pairs corresponding to the two variables in the assignment statements of the code snippet; Last Write: connecting each variable to the node where the last write operation occurred, the node pair corresponding to the write variable. For example, taking the C language function code snippet: "int func(int x,int y) x=x+y;return x", the program dependency graph based on the abstract syntax tree and data flow edges corresponding to this code snippet can be as follows: Figure 4 As shown. Here, AST Edge can refer to an edge in the sample abstract syntax tree. ExtDef is the external definition, which can serve as the root node of the sample abstract syntax tree; Specifier is the declarator; int is the integer type; FuncDec is the function declaration; func is the concrete function; Varlist is the variable list; VarDec is the variable declaration; ParamDec is the parameter declaration; CompSt is the statement body; Stmt is the statement; Return is the return variable.
[0060] S305, analyze the text dependency relationships in the sample parameter description information, sample return value description information and function description information respectively, and obtain the first sample syntactic analysis graph corresponding to the sample parameter description information, the second sample syntactic analysis graph corresponding to the sample return value description information and the third sample syntactic analysis graph corresponding to the function description information.
[0061] In one possible implementation, the textual dependencies in the sample parameter description information, sample return value description information, and function description information can be analyzed separately to obtain the word-text dependencies in these three information. This allows the construction of corresponding sample syntactic analysis graphs (including a first sample syntactic analysis graph, a second sample syntactic analysis graph, and a third sample syntactic analysis graph), where the sample syntactic analysis graph can refer to a dependency structure tree.
[0062] In another possible implementation, step S305 may include the following steps: analyzing the text dependency relationships in the sample parameter description information, sample return value description information, and function description information respectively to obtain the third initial syntactic analysis graph corresponding to the sample parameter description information, the fourth initial syntactic analysis graph corresponding to the sample return value description information, and the fifth initial syntactic analysis graph corresponding to the function description information;
[0063] Furthermore, edges can be added between the third node pairs in the third initial syntactic analysis graph to obtain the first sample syntactic analysis graph; the text corresponding to the third node pair can be adjacent in the sample parameter description information; and edges can be added between the fourth node pairs in the fourth initial syntactic analysis graph to obtain the second sample syntactic analysis graph; the text corresponding to the fourth node pair can be adjacent in the sample return value description information; and edges can be added between the fifth node pairs in the fifth initial syntactic analysis graph to obtain the third sample syntactic analysis graph; the text corresponding to the fifth node pair can be adjacent in the function description information.
[0064] Taking code comments as an example, we can extract the syntactic analysis graph of the code comments. Code comments can be divided into three parts: parameter description, return value description, and function description (corresponding to sample parameter description, sample return value description, and function description, respectively). Then, we construct dependency analysis graphs (syntactic analysis graphs) for each of these three descriptions, and can add Next Token edges to the dependency analysis graphs. Assuming the comment information for the example function is as follows: "param x: A number that acts as an augend; param y: A number that acts as an addend; return: The sum of two numbers; function: Calculate the sum of two numbers", then the dependency analysis graphs corresponding to the parameters, return value, and function description can be respectively as follows: Figure 5 , Figure 6 , Figure 7 As shown. Here, Next Token can refer to the next node in the parsing graph, that is, connecting each leaf node of the sample parsing graph to its subsequent node. Dependency Edge can refer to the edge between dependent nodes in the parsing graph.
[0065] See Figures 5-7The terms det, acl, nsubj, obl, case, nmod, nummod, and obj can be parts of speech in syntactic analysis. det: determiner, such as an article; acl: clausal modifier of noun; nsubj: nominal subject; obl: oblique nominal; case: casemarking; nmod: nominal modifier; nummod: numeric modifier; obj: object.
[0066] S307, the sample program dependency graph, the first sample syntax analysis graph, and the second sample syntax analysis graph are fused to obtain the sample code semantic graph corresponding to each sample code fragment.
[0067] In the embodiments of this specification, a preset graph fusion method can be used to fuse the sample program dependency graph, the first sample syntactic analysis graph, and the second sample syntactic analysis graph to obtain the sample code semantic graph corresponding to each sample code fragment. The preset graph fusion method can be a graph fusion method such as concat or kernel, and this application does not limit it to this method.
[0068] S309, based on a preset code encoding model, encodes the sample code semantic graph and the sample code word segmentation sequence to obtain the sample code embedding vector corresponding to each sample code fragment.
[0069] like Figure 2 As shown, as an example, the preset code encoding model may include a first initial graph neural network and a first initial sequence encoding module. Based on this, the semantic graph of the sample code can be input into the first initial graph neural network for structural encoding processing to obtain the sample code structure vector corresponding to each sample code fragment. Furthermore, the word segmentation sequence of the sample code can be input into the first initial sequence encoding module for sequence encoding processing to obtain the sample code sequence vector corresponding to each sample code fragment.
[0070] Furthermore, the sample code structure vector and the sample code sequence vector can be concatenated to obtain the sample code embedding vector corresponding to each sample code fragment.
[0071] Optionally, the preset code encoding model may further include a first initial pooling module and a second initial pooling module. Based on this, max pooling can be performed on the sample code structure vector using the first initial pooling module to obtain a first sample structure vector; and average pooling can be performed on the sample code sequence vector using the second initial pooling module to obtain a first sample sequence vector; subsequently, the first sample structure vector and the first sample sequence information can be concatenated to obtain a sample code embedding vector. This concatenation process can be handled by the vector concatenation module included in the preset code encoding model.
[0072] S311, based on the preset query encoding model, encodes the word segmentation sequence of the sample text corresponding to the third sample syntactic analysis graph and functional description information to obtain the code tag vector.
[0073] In this embodiment of the specification, the third sample syntactic analysis graph and the sample text segmentation sequence corresponding to the functional description information can be input into a preset query encoding model for encoding processing to obtain a code tag vector. The sample text segmentation sequence can be obtained by segmenting the functional description information, for example... Figure 2 shown ,……, That is, it includes m text segments, where m can be an integer greater than 1.
[0074] like Figure 2 As shown, as an example, the preset query encoding model may include a second initial graph neural network and a second initial sequence encoding module; step S311 may include: encoding the third sample syntactic analysis graph based on the second initial graph neural network to obtain a tag structure vector; and segmenting the functional description information to obtain a sample text segmentation sequence corresponding to the functional description information; encoding the sample text segmentation sequence based on the second initial sequence encoding module to obtain a tag sequence vector; and concatenating the tag structure vector and the tag sequence vector to obtain a code tag vector. As an example, the first initial sequence encoding module and the second initial sequence encoding module may be a neural bag-of-words model, which is not limited in this application.
[0075] Optionally, the preset query encoding model may further include a third initial pooling module and a fourth initial pooling module. Based on this, the label structure vector can be max-pooled using the third initial pooling module to obtain the second sample structure vector; and the label sequence vector can be average-pooled using the fourth initial pooling module to obtain the second sample sequence vector; subsequently, the second sample structure vector and the second sample sequence information can be concatenated to obtain the code label vector. This concatenation process can be handled by the vector concatenation module included in the preset query encoding model.
[0076] The above-mentioned graph neural networks (including the first initial graph neural network and the second initial graph neural network) can be graph convolutional neural networks. The input and output of the graph neural network can be as shown in formula (1). Given a graph G(V,E), the adjacency matrix of the graph is A, and each node in the graph can be initialized by the feature matrix X, then the multi-layer graph convolution expression can finally be written in the following matrix form:
[0077] (1)
[0078] in, , ,but It is the normalized adjacency matrix. For the first The output result after the layer, and It is the feature matrix X, and the elements of the feature matrix X are randomly generated; For the first I The training parameter matrix of the layer. After k layers of convolution, the final vector representation matrix of the graph can be obtained. Each row of the matrix A vector representation of a node v; It is an identity matrix.
[0079] Furthermore, max pooling can be performed on the vectors corresponding to all nodes to obtain the structure vectors of the sample code semantic graph or the third sample syntactic analysis graph. It can be expressed as formula (2) below:
[0080] (2)
[0081] Where FC represents a fully connected layer, and V is... This corresponds to all nodes in the dataset. Max pooling can reduce the shift in the estimated mean caused by convolutional layer parameter errors, thus preserving more texture information.
[0082] For example, the first and second initial sequence encoding modules can be neural bag-of-words models, and finally, the corresponding neural bag-of-words models can be used to obtain sequence vectors of code fragments and functional description information. For instance, a dictionary can be built using byte encoding of code fragments and functional description information, and then the neural bag-of-words model can be used to obtain the vector corresponding to each token in the code fragments and functional description information. Then, average pooling is performed on the m tokens to obtain a sequence vector of code snippets or functional description information, as shown in formula (3) below:
[0083] (3)
[0084] Average pooling can reduce the increase in variance of estimates caused by the limited neighborhood size, and retain more of the overall data characteristics.
[0085] Furthermore, it is possible to... and After concatenation, we obtain the sample code embedding vector and the code label vector, which can be represented as follows: Each of these is composed of two parts: a structure vector and a sequence vector.
[0086] S313. Determine the loss information based on the sample code embedding vector and code label vector.
[0087] In the embodiments of this specification, the distance difference between the sample code embedding vector and the code label vector can be used as loss information. As an example, the loss information can be determined based on minimizing the distance. For example, it can be calculated using the following formula (4):
[0088] Suppose we perform training by minimizing the loss on the sample code embedding vectors and code label vectors. During training, we can train by minimizing the loss:
[0089] (4)
[0090] in, It can refer to the i-th training sample. It could refer to the i-th code snippet. It can refer to the i-th function description information; N here can refer to The number of pairs, i.e., the number of training samples; It could refer to a pre-defined code encoding model. This refers to the i-th code segment after... The output; This could refer to a preset query encoding model. This refers to the i-th function description information after... The output of .
[0091] S315, Based on the loss information, train the preset code encoding model and the preset query encoding model to obtain the target code encoding model and the target query encoding model.
[0092] In the embodiments of this specification, gradient descent information can be determined based on loss information, thereby allowing adjustment of the model parameters of the preset code encoding model and the preset query encoding model based on the gradient descent information. Specifically, the model parameters of the first initial sequence encoding module, the first initial graph neural network, the second initial sequence encoding module, the second initial graph neural network, the first initial pooling module, the second initial pooling module, the third initial pooling module, and the fourth initial pooling module can be adjusted until preset conditions are met. Thus, the preset code encoding model that meets the preset conditions can be used as the target code encoding model, and the preset query encoding model that meets the preset conditions can be used as the target query encoding model. Correspondingly, after training, the first initial sequence encoding module, the first initial graph neural network, the second initial sequence encoding module, the second initial graph neural network, the first initial pooling module, the second initial pooling module, the third initial pooling module, and the fourth initial pooling module correspond sequentially as follows: first sequence encoding module, first graph neural network, second sequence encoding module, second graph neural network, first pooling module, second pooling module, third pooling module, and fourth pooling module.
[0093] In practical applications, such as code search, in offline mode, a pre-trained target code encoding model can be used to encode all code snippets in the code search platform to obtain the target code embedding vectors corresponding to each code snippet. These target code embedding vectors can then be stored in the form of an index. During online code search, a pre-trained target query encoding model can be used to encode the input natural language description information to obtain a query embedding vector. The index is then used to find one or more vectors most similar to the query embedding vector and return them as the code query result corresponding to the natural language description information, such as the code search result. See the following description for details.
[0094] Figure 8 A flowchart illustrating a code processing method according to an embodiment of this application is shown. Figure 8 As shown, the code processing method may include:
[0095] S801, obtain multiple code fragments to be processed and the code description information corresponding to each code fragment. The code description information includes parameter description information and return value description information.
[0096] In the embodiments of this specification, to provide natural language code search, corresponding code embedding vectors can be generated for each code fragment. This allows for the vectorization of the natural language search language during natural language search, enabling code search based on vector similarity. Based on this, multiple code fragments to be processed can be obtained, each fragment corresponding to a function. For example, the code used for searching in the code platform can be functionally divided to obtain multiple code fragments. For instance, from a function perspective, code fragments can be function code fragments; from a class and file perspective, code fragments can be file code fragments; and from a project perspective, code fragments can be all code in a project.
[0097] Furthermore, the parameter description information and return value description information corresponding to each code segment can be obtained as the code description information corresponding to each code segment.
[0098] S803 generates the code segmentation sequence and the program dependency graph corresponding to each code segment based on the word segmentation results of each code segment.
[0099] In the embodiments of this specification, each code segment can be segmented to obtain the segmentation result. This segmentation can be performed using a segmentation tool; however, this application does not limit the specific segmentation tool used, meaning it does not limit the specific segmentation method. Thus, each segment in the segmentation result can be traversed to obtain a code segmentation sequence. The segments in this code segmentation sequence can be arranged in the order of traversal. For example, the code segmentation sequence can be represented as tok1~tokN, meaning it includes N segments, where N can be an integer greater than 1.
[0100] In the embodiments of this specification, a program dependency graph corresponding to each code segment can be generated based on the word segmentation processing results of each code segment. As one possible implementation, an abstract syntax tree for each code segment can be generated based on the word segmentation processing results of each code segment.
[0101] Furthermore, edges can be added between target node pairs in the abstract syntax tree of each code segment to generate a program dependency graph corresponding to each code segment. Target node pairs can include at least one of the following: leaf node pairs in the abstract syntax tree, where leaf node pairs are adjacent in their corresponding code segments; node pairs corresponding to two variables in an assignment statement within a code segment; and node pairs corresponding to write variables.
[0102] Taking the target node pair as an example, which includes the three types of node pairs mentioned above, three types of edges (or data flow edges) can be further extended on this abstract syntax tree to form a program dependency graph (also known as a code analysis graph). These three types of edges can be: NextToken (next node): connecting each leaf node of the abstract syntax tree to its subsequent node; leaf node pairs in the abstract syntax tree are adjacent in the corresponding code segment; Computed from: connecting all left-hand and right-hand variables that appear in assignment statements, i.e., the node pairs corresponding to the two variables in the assignment statements in the code segment; LastWrite: connecting each variable to the node where the last write operation occurred, the node pairs corresponding to the write variable.
[0103] S805, analyze the text dependency relationships in the parameter description information and the return value description information respectively to obtain the first syntactic analysis graph corresponding to the parameter description information and the second syntactic analysis graph corresponding to the return value description information.
[0104] In one possible implementation, the textual dependency relationships in the parameter description information and the return value description information can be analyzed separately to obtain the dependency relationships between the word texts in the parameter description information and the return value description information. Thus, a corresponding syntactic analysis graph (including a first syntactic analysis graph and a second syntactic analysis graph) can be constructed according to the dependency relationships between the word texts. Here, the syntactic analysis graph can refer to a dependency structure tree.
[0105] In another possible implementation, the constructed syntactic analysis graph can also be edge-expanded. For example, step S805 can be implemented through the following steps:
[0106] The text dependency relationships in the parameter description information and the return value description information are analyzed separately to obtain the first initial syntactic analysis graph corresponding to the parameter description information and the second initial syntactic analysis graph corresponding to the return value description information.
[0107] An edge is added between the first node pairs in the first initial syntactic analysis graph to obtain the first syntactic analysis graph; the text corresponding to the first node pair is adjacent in the parameter description information;
[0108] An edge is added between the second node pairs in the second initial parsing graph to obtain the second parsing graph; the text corresponding to the second node pair is adjacent in the return value description information.
[0109] The specific implementation of step S805 can be found in step S305 above, and will not be repeated here.
[0110] S807 performs fusion processing on the program dependency graph, the first syntactic analysis graph, and the second syntactic analysis graph to obtain the code semantic graph corresponding to each code segment.
[0111] Among them, the code semantic graph can represent the textual dependencies and program dependencies of code fragments.
[0112] In the embodiments of this specification, a preset graph fusion method can be used to fuse the program dependency graph, the first syntactic analysis graph, and the second syntactic analysis graph to obtain the code semantic graph corresponding to each code segment. The preset graph fusion method can be a graph fusion method such as concat or kernel, and this application does not limit it, as long as it can add information from the first and second syntactic analysis graphs to the program dependency graph.
[0113] S809 encodes the code semantic graph and the code segmentation sequence to obtain the target code embedding vector corresponding to each code fragment.
[0114] The target code embedding vector can be used to perform preset operations on the code based on natural language. For example, preset operations may include search operations, recommendation operations, deduplication operations, etc., and this disclosure does not limit them.
[0115] In one possible implementation, the code semantic graph and the code segmentation sequence can be encoded based on a target code encoding model to obtain the target code embedding vector corresponding to each code segment. The target code encoding model may include a first graph neural network and a first sequence encoding module; correspondingly, step S809 may include: encoding the code semantic graph based on the first graph neural network of the target code encoding model to obtain the code structure vector corresponding to each code segment; and encoding the code segmentation sequence based on the first sequence encoding module of the target code encoding model to obtain the code sequence vector corresponding to each code segment; further, the code structure vector and the code sequence vector may be concatenated to obtain the target code embedding vector corresponding to each code segment.
[0116] Optionally, the target code encoding model may further include a first pooling module and a second pooling module. Accordingly, concatenating the code structure vector and the code sequence vector to obtain the target code embedding vector corresponding to each code segment may include: performing max pooling on the code structure vector based on the first pooling module to obtain the target structure vector; performing average pooling on the code sequence vector based on the second pooling module to obtain the target sequence vector; and concatenating the target structure vector and the target sequence information to obtain the target code embedding vector.
[0117] The specific implementation of step S809 can be found in step S309 above, and will not be repeated here. Furthermore, the specific implementations of steps S801 to S809 can also be found in steps S301 to S309 above, and will not be repeated here.
[0118] By fusing the program dependency graph, the first syntactic analysis graph, and the second syntactic analysis graph, a code semantic graph corresponding to each code segment is obtained. This effectively extracts structural information from the code segments. Furthermore, by using dependency parsing techniques from syntactic analysis, structural information from natural language descriptions can be effectively extracted. By fusing the syntactic analysis graphs corresponding to parameter description information and return value description information into the program dependency graph, the semantic gap between code language and natural language can be overcome. Moreover, parameter description information and return value description information can effectively represent the input and output information of the code, enabling the code semantic graph to accurately express the semantic information of the code segments.
[0119] Furthermore, the code semantic graph and code segmentation sequence are encoded to obtain the target code embedding vector corresponding to each code segment. This allows the target code embedding vector to better balance the structural and sequence information of the code segment, thereby improving the accuracy of the embedding representation of the code segment.
[0120] Furthermore, the precise representation of code snippets based on embedded vectors can improve search efficiency, thereby improving R&D efficiency, and also enhance the accuracy of code searches when faced with increasingly large code repositories and increasingly complex functional and business scenarios.
[0121] In practical applications, pre-defined operations on the code can be performed based on the trained target query encoding model, such as code deduplication, code recommendation, and code search. Accordingly, the method may further include: acquiring natural language description information; encoding the natural language description information based on the target query encoding model to obtain a query embedding vector; acquiring the target code embedding vectors corresponding to each code segment to be queried; and then using the target code embedding vectors that match the query embedding vectors, along with the corresponding code segments to be queried, as the code query results corresponding to the natural language description information.
[0122] The target query encoding model can be the target query encoding model trained above; the target code embedding vectors corresponding to each queried code segment can be obtained based on the trained target code encoding model. For code search, the target code embedding vectors corresponding to each queried code segment can be obtained by encoding all code segments in the code search platform using the trained target code encoding model in offline mode. That is, in offline mode, the trained target code encoding model can be used to encode all code segments associated with the code search engine, obtaining the target code embedding vectors corresponding to each code segment, and saving them. Then, during subsequent code searches, the natural language description information is encoded to obtain the query embedding vector. By searching and matching the query embedding vector and the target code embedding vector, the matching code segment can be easily found. The natural language description information refers to the description information of the code search using natural language.
[0123] like Figure 2 As shown, the trained target query encoding model can include a second graph neural network and a second sequence encoding module. Based on this, text segmentation sequences and syntactic analysis graphs can be obtained from natural language description information. The syntactic analysis graph can then be sequentially input into the second graph neural network and the third pooling module (max pooling) to obtain the query structure vector. The text segmentation sequences from natural language description information can then be sequentially input into the second sequence encoding module and the fourth pooling module (average pooling) to obtain the query sequence vector. The query structure vector and the query sequence vector can then be concatenated to obtain the query embedding vector.
[0124] For example, code can be retrieved based on function, such as "local cache locking read / write", or based on business scenario, such as "interaction processing in XXX scenario", or by asking a question, such as "how does the XX system render an image?" The code search method in this application can efficiently and accurately support all these scenarios.
[0125] Optionally, the code search method of this application can be used as a search algorithm engine and incorporated into a code retrieval tool to provide efficient code retrieval capabilities. Alternatively, it can be combined with cloud development to enable cloud code search, thereby improving the development and user experience of massive amounts of code.
[0126] The above code search methods can be integrated into code retrieval and viewing tools as search engines, providing more efficient and flexible code query capabilities for code search entry points. This allows developers to efficiently and accurately retrieve target code based on functional module descriptions, business scenario descriptions, and the problems to be solved, thereby improving development efficiency.
[0127] In code deduplication, natural language description information refers to the description of the deduplicated code using natural language. After obtaining the code query results, further processing can include deduplicating the code snippets in the query results, thereby saving storage resources.
[0128] Optionally, in the code recommendation process, the description information of the target account's historical code searches can be obtained as natural language description information, so that the code query results can be recommended to the target account to facilitate the target account's code usage.
[0129] Figure 9 This diagram illustrates a block diagram of a code processing apparatus according to an embodiment of this application. Figure 9 As shown, the device may include:
[0130] The acquisition module 901 is used to acquire multiple code fragments to be processed and the code description information corresponding to each code fragment, wherein the code description information includes parameter description information and return value description information;
[0131] The word segmentation processing module 903 is used to generate the code segmentation sequence corresponding to each code segment and the program dependency graph corresponding to each code segment based on the word segmentation processing results of each code segment;
[0132] The syntactic analysis module 905 is used to analyze the text dependency relationships in the parameter description information and the return value description information respectively, to obtain a first syntactic analysis graph corresponding to the parameter description information and a second syntactic analysis graph corresponding to the return value description information;
[0133] The code semantic graph acquisition module 907 is used to perform fusion processing on the program dependency graph, the first syntactic analysis graph and the second syntactic analysis graph to obtain the code semantic graph corresponding to each code segment;
[0134] The code embedding processing module 909 is used to encode the code semantic graph and the code word segmentation sequence to obtain the target code embedding vector corresponding to each code fragment; the target code embedding vector is used to perform preset operations on the code based on natural language.
[0135] By fusing the program dependency graph, the first syntactic analysis graph, and the second syntactic analysis graph, a code semantic graph corresponding to each code segment is obtained. This effectively extracts structural information from the code segments. Furthermore, by using dependency parsing techniques from syntactic analysis, structural information from natural language descriptions can be effectively extracted. By fusing the syntactic analysis graphs corresponding to parameter description information and return value description information into the program dependency graph, the semantic gap between code language and natural language can be overcome. Moreover, parameter description information and return value description information can effectively represent the input and output information of the code, enabling the code semantic graph to accurately express the semantic information of the code segments.
[0136] Furthermore, the code semantic graph and code segmentation sequence are encoded to obtain the target code embedding vector corresponding to each code segment. This allows the target code embedding vector to better balance the structural and sequence information of the code segment, thereby improving the accuracy of the embedding representation of the code segment.
[0137] Furthermore, the precise representation of code snippets based on embedded vectors can improve search efficiency, thereby improving R&D efficiency, and also enhance the accuracy of code searches when faced with increasingly large code repositories and increasingly complex functional and business scenarios.
[0138] In one possible implementation, the code embedding processing module 909 described above may include:
[0139] The code structure vector acquisition unit is used to encode the code semantic graph based on the first graph neural network of the target code encoding model to obtain the code structure vector corresponding to each code segment.
[0140] The code sequence vector acquisition unit is used to encode the code segmentation sequence based on the first sequence encoding module of the target code encoding model to obtain the code sequence vector corresponding to each code segment.
[0141] The vector concatenation unit is used to concatenate the code structure vector and the code sequence vector to obtain the target code embedding vector corresponding to each code fragment.
[0142] In one possible implementation, the word segmentation module 903 described above may include:
[0143] Abstract syntax tree generation unit, used to generate abstract syntax trees for each code segment based on the word segmentation results of each code segment;
[0144] The program dependency graph building unit is used to add edges between target node pairs in the abstract syntax tree of each code segment to generate the program dependency graph corresponding to each code segment.
[0145] The target node pair includes at least one of the following: a leaf node pair in the abstract syntax tree, wherein the leaf node pair is adjacent in the corresponding code segment; a node pair corresponding to two variables in the assignment statement in the code segment; and a node pair corresponding to the write variable.
[0146] In one possible implementation, the syntactic analysis module 905 described above may include:
[0147] The text dependency analysis unit is used to analyze the text dependency relationships in the parameter description information and the return value description information respectively, to obtain a first initial syntactic analysis graph corresponding to the parameter description information and a second initial syntactic analysis graph corresponding to the return value description information;
[0148] The first edge expansion unit is used to add edges between first node pairs in the first initial syntactic analysis graph to obtain the first syntactic analysis graph; the text corresponding to the first node pairs is adjacent in the parameter description information;
[0149] The second edge expansion unit is used to add edges between the second node pairs in the second initial syntactic analysis graph to obtain the second syntactic analysis graph; the text corresponding to the second node pairs is adjacent in the return value description information.
[0150] In one possible implementation, the target code encoding model may further include a first pooling module and a second pooling module, and the vector concatenation unit may include:
[0151] The first pooling processing subunit is used to perform max pooling processing on the code structure vector based on the first pooling module to obtain the target structure vector;
[0152] The second pooling processing subunit is used to perform average pooling processing on the code sequence vector based on the second pooling module to obtain the target sequence vector.
[0153] The vector splicing subunit splices the target structure vector and the target sequence information to obtain the target code embedding vector.
[0154] In one possible implementation, the word segmentation module 903 may further include:
[0155] The code segmentation sequence acquisition unit is used to traverse each segment in the segmentation processing result to obtain the code segmentation sequence, wherein the segments in the code segmentation sequence are arranged in the order of traversal.
[0156] In one possible implementation, the device may further include:
[0157] The training sample acquisition module is used to acquire multiple sample code snippets and corresponding sample code description information. The sample code description information includes sample parameter description information, sample return value description information, and function description information.
[0158] The sample program dependency graph construction module is used to generate the sample code segmentation sequence and the sample program dependency graph corresponding to each sample code segment based on the word segmentation processing results of each sample code segment.
[0159] The syntactic analysis graph acquisition module is used to analyze the text dependency relationships in the sample parameter description information, the sample return value description information, and the function description information respectively, to obtain a first sample syntactic analysis graph corresponding to the sample parameter description information, a second sample syntactic analysis graph corresponding to the sample return value description information, and a third sample syntactic analysis graph corresponding to the function description information.
[0160] The sample code semantic graph acquisition module is used to fuse the sample program dependency graph, the first sample syntactic analysis graph and the second sample syntactic analysis graph to obtain the sample code semantic graph corresponding to each sample code fragment.
[0161] The sample code embedding vector representation module is used to encode the sample code semantic graph and the sample code word segmentation sequence based on a preset code encoding model to obtain the sample code embedding vector corresponding to each sample code fragment.
[0162] The code tag vector acquisition module is used to encode the word segmentation sequence of the sample text corresponding to the third sample syntactic analysis graph and the functional description information based on a preset query encoding model to obtain the code tag vector.
[0163] The loss information determination module is used to determine loss information based on the sample code embedding vector and the code label vector;
[0164] The training module is used to train the preset code encoding model and the preset query encoding model based on the loss information to obtain the target code encoding model and the target query encoding model.
[0165] In one possible implementation, the preset query encoding model may include a second initial graph neural network and a second initial sequence encoding module; the code label vector acquisition module may include:
[0166] The tag structure vector acquisition unit is used to encode the third sample syntactic analysis graph based on the second initial graph neural network to obtain the tag structure vector.
[0167] The tag sequence vector acquisition unit is used to encode the sample text word segmentation sequence based on the second initial sequence encoding module to obtain the tag sequence vector;
[0168] The code tag vector acquisition unit is used to concatenate the tag structure vector and the tag sequence vector to obtain the code tag vector.
[0169] In one possible implementation, the syntactic analysis graph acquisition module described above may include:
[0170] The text dependency analysis unit is used to analyze the text dependency relationships in the sample parameter description information, the sample return value description information, and the function description information respectively, to obtain a third initial syntactic analysis graph corresponding to the sample parameter description information, a fourth initial syntactic analysis graph corresponding to the sample return value description information, and a fifth initial syntactic analysis graph corresponding to the function description information.
[0171] The third edge expansion unit is used to add edges between the third node pairs in the third initial syntactic analysis graph to obtain the first sample syntactic analysis graph; the text corresponding to the third node pairs is adjacent in the sample parameter description information;
[0172] The fourth edge expansion unit is used to add edges between the fourth node pairs in the fourth initial syntactic analysis graph to obtain the second sample syntactic analysis graph; the text corresponding to the fourth node pairs is adjacent in the sample return value description information;
[0173] The fifth edge expansion unit is used to add edges between the fifth node pairs in the fifth initial syntactic analysis graph to obtain the third sample syntactic analysis graph; the text corresponding to the fifth node pairs is adjacent in the functional description information.
[0174] In one possible implementation, the device may further include:
[0175] The description information acquisition module is used to acquire natural language description information;
[0176] The query embedding vector acquisition module is used to encode the natural language description information based on the target query encoding model to obtain the query embedding vector;
[0177] The target code embedding vector acquisition module is used to obtain the target code embedding vector corresponding to each code segment to be queried.
[0178] The code query result determination module is used to embed the target code that matches the query embedding vector into the embedding vector, and the corresponding code fragment to be queried is used as the code query result corresponding to the natural language description information.
[0179] Regarding the apparatus in the above embodiments, the specific manner in which each module and unit performs its operations has been described in detail in the embodiments related to the method, and will not be elaborated upon here.
[0180] Figure 10 This diagram illustrates a block diagram of an electronic device for code processing according to an embodiment of this application. The electronic device may be a server, and its internal structure diagram may be as follows: Figure 10 As shown, the electronic device includes a processor 801, memory, and a network interface connected via a system bus 802. The processor provides computing and control capabilities. The memory includes a non-volatile storage medium and internal memory 803. The non-volatile storage medium stores an operating system 805 and a computer program 806. The internal memory 803 provides an environment for the operation of the operating system 805 and the computer program 806 stored in the non-volatile storage medium. The network interface is used to communicate with external terminals via a network connection. When the computer program is executed by the processor, it implements a method for asynchronous data snapshotting.
[0181] Those skilled in the art will understand that Figure 10 The structure shown is merely a block diagram of a portion of the structure related to the present application and does not constitute a limitation on the electronic device to which the present application is applied. The specific electronic device may include more or fewer components than shown in the figure, or combine certain components, or have different component arrangements.
[0182] In an exemplary embodiment, an electronic device is also provided, including: a processor; and a memory for storing processor-executable instructions; wherein the processor is configured to execute the instructions to implement the code processing method as described in the embodiments of this application.
[0183] In an exemplary embodiment, a storage medium is also provided, which, when the instructions in the storage medium are executed by the processor of an electronic device, enables the electronic device to execute the code processing method of the embodiments of this application.
[0184] In an exemplary embodiment, a computer program product containing instructions is also provided, which, when run on a computer, causes the computer to execute the code processing method of the embodiments of this application.
[0185] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. This computer program can be stored in a non-volatile computer-readable storage medium. When executed, the computer program can include the processes of the embodiments of the above methods. Any references to memory, storage, databases, or other media used in the embodiments provided in this application can include non-volatile and / or volatile memory. Non-volatile memory can include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM), or flash memory. Volatile memory can include random access memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in various forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), dual data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link DRAM (SLDRAM), RAMbus direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and RAMbus dynamic RAM (RDRAM), etc.
[0186] Other embodiments of this application will readily occur to those skilled in the art upon consideration of the specification and practice of the invention disclosed herein. This application is intended to cover any variations, uses, or adaptations of this application that follow the general principles of this application and include common knowledge or customary techniques in the art not disclosed herein. The specification and examples are to be considered exemplary only, and the true scope and spirit of this application are indicated by the following claims.
[0187] It should be understood that this application is not limited to the precise structure described above and shown in the accompanying drawings, and various modifications and changes can be made without departing from its scope. The scope of this application is limited only by the appended claims.
Claims
1. A code processing method, characterized in that, The method includes: Obtain multiple code snippets to be processed and the corresponding code description information for each code snippet, wherein the code description information includes parameter description information and return value description information; Based on the word segmentation results of each code segment, generate the code segmentation sequence corresponding to each code segment and the program dependency graph corresponding to each code segment; The text dependency relationships in the parameter description information and the return value description information are analyzed respectively to obtain the first syntactic analysis graph corresponding to the parameter description information and the second syntactic analysis graph corresponding to the return value description information; The program dependency graph, the first syntactic analysis graph, and the second syntactic analysis graph are fused together to obtain the code semantic graph corresponding to each code segment. The code semantic graph and the code word segmentation sequence are encoded to obtain the target code embedding vector corresponding to each code fragment; the target code embedding vector is used to perform preset operations on the code based on natural language.
2. The method according to claim 1, characterized in that, The process of encoding the code semantic graph and the code segmentation sequence to obtain the target code embedding vector corresponding to each code fragment includes: The first graph neural network based on the target code encoding model encodes the code semantic graph to obtain the code structure vector corresponding to each code segment; The first sequence encoding module based on the target code encoding model encodes the code segmentation sequence to obtain the code sequence vector corresponding to each code segment. The code structure vector and the code sequence vector are concatenated to obtain the target code embedding vector corresponding to each code fragment.
3. The method according to claim 1 or 2, characterized in that, The generation of a program dependency graph corresponding to each code segment based on the word segmentation results includes: Based on the word segmentation results of each code snippet, an abstract syntax tree is generated for each code snippet; Add edges between target node pairs in the abstract syntax tree of each code snippet to generate the program dependency graph corresponding to each code snippet; The target node pair includes at least one of the following: a leaf node pair in the abstract syntax tree, wherein the leaf node pair is adjacent in the corresponding code segment; a node pair corresponding to two variables in the assignment statement in the code segment; and a node pair corresponding to the write variable.
4. The method according to claim 3, characterized in that, The step of analyzing the text dependency relationships in the parameter description information and the return value description information respectively to obtain a first syntactic analysis graph corresponding to the parameter description information and a second syntactic analysis graph corresponding to the return value description information includes: The text dependency relationships in the parameter description information and the return value description information are analyzed respectively to obtain the first initial syntactic analysis graph corresponding to the parameter description information and the second initial syntactic analysis graph corresponding to the return value description information; An edge is added between the first node pairs in the first initial syntactic analysis graph to obtain the first syntactic analysis graph; the text corresponding to the first node pairs are adjacent in the parameter description information; An edge is added between the second node pairs in the second initial syntactic analysis graph to obtain the second syntactic analysis graph; the text corresponding to the second node pairs is adjacent in the return value description information.
5. The method according to claim 2, characterized in that, The target code encoding model further includes a first pooling module and a second pooling module. The concatenation of the code structure vector and the code sequence vector to obtain the target code embedding vector corresponding to each code segment includes: The code structure vector is subjected to max pooling based on the first pooling module to obtain the target structure vector; The code sequence vector is subjected to average pooling based on the second pooling module to obtain the target sequence vector. The target structure vector and the target sequence vector are concatenated to obtain the target code embedding vector.
6. The method according to claim 1, characterized in that, The generation of code segmentation sequences corresponding to each code segment based on the word segmentation results of each code segment includes: The word segments in the word segmentation result are traversed to obtain the code word segmentation sequence, and the word segments in the code word segmentation sequence are arranged in the order of the traversal.
7. The method according to claim 2, characterized in that, The method further includes: Obtain multiple sample code snippets and their corresponding sample code description information, including sample parameter description information, sample return value description information, and function description information; Based on the word segmentation results of each sample code segment, a sample code segmentation sequence and a sample program dependency graph corresponding to each sample code segment are generated. The text dependency relationships in the sample parameter description information, the sample return value description information, and the function description information are analyzed respectively to obtain the first sample syntactic analysis graph corresponding to the sample parameter description information, the second sample syntactic analysis graph corresponding to the sample return value description information, and the third sample syntactic analysis graph corresponding to the function description information. The sample program dependency graph, the first sample syntactic analysis graph, and the second sample syntactic analysis graph are fused to obtain the sample code semantic graph corresponding to each sample code fragment. Based on a preset code encoding model, the sample code semantic graph and the sample code word segmentation sequence are encoded to obtain the sample code embedding vector corresponding to each sample code fragment. Based on a preset query encoding model, the word segmentation sequence of the sample text corresponding to the third sample syntactic analysis graph and the functional description information is encoded to obtain a code tag vector. The loss information is determined based on the sample code embedding vector and the code label vector; The preset code encoding model and the preset query encoding model are trained based on the loss information to obtain the target code encoding model and the target query encoding model.
8. The method according to claim 7, characterized in that, The preset query encoding model includes a second initial graph neural network and a second initial sequence encoding module; the encoding process based on the preset query encoding model, which encodes the third sample syntactic analysis graph and the sample text segmentation sequence corresponding to the functional description information, yields a code tag vector, including: The third sample syntactic analysis graph is encoded based on the second initial graph neural network to obtain a label structure vector. The sample text segmentation sequence is encoded based on the second initial sequence encoding module to obtain a tag sequence vector; The tag structure vector and the tag sequence vector are concatenated to obtain the code tag vector.
9. The method according to claim 7 or 8, characterized in that, The step of analyzing the text dependency relationships in the sample parameter description information, the sample return value description information, and the function description information to obtain a first sample syntactic analysis graph corresponding to the sample parameter description information, a second sample syntactic analysis graph corresponding to the sample return value description information, and a third sample syntactic analysis graph corresponding to the function description information includes: The text dependency relationships in the sample parameter description information, the sample return value description information, and the function description information are analyzed respectively to obtain the third initial syntactic analysis graph corresponding to the sample parameter description information, the fourth initial syntactic analysis graph corresponding to the sample return value description information, and the fifth initial syntactic analysis graph corresponding to the function description information. An edge is added between the third node pairs in the third initial syntactic analysis graph to obtain the first sample syntactic analysis graph; the text corresponding to the third node pairs is adjacent in the sample parameter description information; An edge is added between the fourth node pairs in the fourth initial syntactic analysis graph to obtain the second sample syntactic analysis graph; the text corresponding to the fourth node pairs is adjacent in the sample return value description information; An edge is added between the fifth node pairs in the fifth initial syntactic analysis graph to obtain the third sample syntactic analysis graph; the text corresponding to the fifth node pairs is adjacent in the functional description information.
10. The method according to any one of claims 7-9, characterized in that, The method further includes: Obtain natural language description information; Based on the target query encoding model, the natural language description information is encoded to obtain a query embedding vector; Obtain the target code embedding vector corresponding to each code fragment to be queried; The target code embedding vector that matches the query embedding vector, and the corresponding code fragment to be queried, are used as the code query result corresponding to the natural language description information.
11. A code processing device, characterized in that, include: The acquisition module is used to acquire multiple code snippets to be processed and the code description information corresponding to each code snippet, wherein the code description information includes parameter description information and return value description information. The word segmentation module is used to generate the code segmentation sequence corresponding to each code segment and the program dependency graph corresponding to each code segment based on the word segmentation results of each code segment. The syntactic analysis module is used to analyze the text dependency relationships in the parameter description information and the return value description information respectively, to obtain a first syntactic analysis graph corresponding to the parameter description information and a second syntactic analysis graph corresponding to the return value description information; The code semantic graph acquisition module is used to fuse the program dependency graph, the first syntactic analysis graph and the second syntactic analysis graph to obtain the code semantic graph corresponding to each code segment. The code embedding processing module is used to encode the code semantic graph and the code word segmentation sequence to obtain the target code embedding vector corresponding to each code segment; The target code embedding vector is used to perform preset operations on the code based on natural language.
12. An electronic device, characterized in that, include: processor; Memory used to store processor-executable instructions; The processor is configured to execute the executable instructions to implement the method according to any one of claims 1 to 10.
13. A non-volatile computer-readable storage medium storing computer program instructions thereon, characterized in that, When the computer program instructions are executed by the processor, they implement the method described in any one of claims 1 to 10.