Code recognition method, and code recognition model training method and apparatus
By using a code recognition model based on graph neural networks, the problem of high time cost for traditional subgraph matching algorithms in identifying large-scale code libraries in high-performance computing is solved. This achieves efficient and accurate code recognition and location of standard operators, improving the efficiency of application migration and performance optimization.
Patent Information
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- HUAWEI TECH CO LTD
- Filing Date
- 2025-04-08
- Publication Date
- 2026-05-15
AI Technical Summary
In the field of high-performance computing, traditional subgraph matching algorithms struggle to efficiently identify standard operator code in large-scale codebases, resulting in high time costs and hindering application migration and performance optimization.
A code recognition model based on graph neural networks is adopted. By converting the code into an attribute graph and using graph neural networks to identify the inclusion relationship between two codes, the code of standard operators can be identified.
It improves the accuracy and efficiency of code recognition, enabling efficient identification of code inclusion relationships, locating the code position of operators, and reducing time costs.
Smart Images

Figure CN2025087725_15052026_PF_FP_ABST
Abstract
Description
A code recognition method, a code recognition model training method and apparatus
[0001] This application claims priority to Chinese Patent Application No. 202411566442.2, filed on November 5, 2024, entitled "A Code Recognition Method, Code Recognition Model Training Method and Apparatus", the entire contents of which are incorporated herein by reference.
[0002] Technology Neighborhood
[0003] This application relates to the field of computer technology, and in particular to a code recognition method, a code recognition model training method, and an apparatus. Background Technology
[0004] In high-performance computing (HPC) and similar fields, application migration and performance optimization are frequently required. These processes often necessitate rewriting or adjusting the code of standard operators within the application's program code. This requires identifying the standard operators within the application's program code.
[0005] In related technologies, traditional subgraph matching algorithms, such as graph isomorphism algorithms (e.g., VF2), are used to identify code containing standard operators within the application's program code. However, traditional subgraph matching algorithms struggle to handle large-scale codebases and long code segments. Implementing traditional subgraph matching algorithms on large-scale codebases is very time-consuming. Furthermore, the codebase in the HPC neighborhood is large, and the code segments are often long. Therefore, a code identification scheme that can reduce time costs is urgently needed. Summary of the Invention
[0006] This application provides a code recognition method, a code recognition model training method, and an apparatus, which can efficiently identify operator code in application program code and reduce the time cost of code recognition.
[0007] In a first aspect, a code recognition method is provided, comprising: acquiring a first code and a second code; wherein the length of the second code is less than or equal to the length of the first code; converting the first code into a first code attribute graph and converting the second code into a second code attribute graph; inputting the first code attribute graph and the second code attribute graph into a code recognition model based on a graph neural network, such that the code recognition model outputs a recognition result; wherein the recognition result includes a graph relationship between the second code attribute graph and the first code attribute graph; when the graph relationship indicates that the second code attribute graph is a subgraph of the first code attribute graph, it is confirmed that the first code contains the second code.
[0008] For example, the first code can be the application's program code, and the second code can be the operator's code, such as the code of a standard operator.
[0009] The code recognition method provided in this application utilizes a graph neural network-based code recognition model to identify the relationship between the code attribute graphs of two codes, thereby identifying the inclusion relationship between the two codes. In other words, the code recognition method provided in this application uses a graph neural network algorithm to identify the inclusion relationship between two codes. Compared to traditional subgraph matching algorithms (such as VF2), the code recognition method provided in this application can improve recognition accuracy and efficiency.
[0010] In one possible implementation, the first code attribute graph includes a first node, and the second code attribute graph includes a second node. The first node is derived from a first code element in the first code, and the second node is derived from a second code element in the second code. The recognition result also includes the first node relationship between the first node and the second node. The method further includes: when the first node relationship indicates a match between the first node and the second node, recording the correspondence between the position of the first code element in the first code and the position of the second code element in the second code. The position of the first code element in the first code can be the line containing the code element in the first code, and the position of the second code element in the second code can be the line containing the code element in the second code.
[0011] In this implementation, it's possible to confirm that the first code contains the second code, and also to determine the position of the second code within the first code, such as its line number. This allows for the location of the operator's code within the application's program code.
[0012] In one possible implementation, the first code attribute graph further includes a third node, which is transformed from the third code element in the first code. The recognition result also includes the second node relationship between the first node and the third node. When the first node relationship indicates that the first node and the second node match, the correspondence between the position of the first code element in the first code and the position of the second code element in the second code is recorded, including: when the first node relationship indicates that the first node and the second node match, and the second node relationship indicates that the third node and the second node match, the third node relationship between the neighboring nodes of the second node and the neighboring nodes of the first node is identified, and the fourth node relationship between the neighboring nodes of the second node and the neighboring nodes of the third node is identified; when the third node relationship indicates that the neighboring nodes of the second node and the neighboring nodes of the first node match, and the fourth node relationship indicates that the neighboring nodes of the second node and the neighboring nodes of the third node do not match, the correspondence between the position of the first code element in the first code and the position of the second code element in the second code is recorded.
[0013] It's possible that the recognition results will show that the second node matches multiple nodes in the first code attribute graph. In this case, this implementation can specifically identify the node that truly matches the second node among these multiple nodes, thereby improving the accuracy of the recognition.
[0014] In one possible implementation, the first code attribute graph further includes a third node, which is transformed from the third code element in the first code. The recognition result also includes the second node relationship between the first node and the third node. When the first node relationship indicates that the first node and the second node match, the correspondence between the position of the first code element in the first code and the position of the second code element in the second code is recorded, including: when the first node relationship indicates that the first node and the second node match, and the second node relationship indicates that the third node and the second node match, the first node, the second node, and the third node are input into the node recognition model, so that the node recognition model inputs the node recognition result; when the node recognition result indicates that the first node and the second node match, and the third node and the second node do not match, the correspondence between the position of the first code element in the first code and the position of the second code element in the second code is recorded.
[0015] It is possible that the recognition results show that the second node matches multiple nodes in the first code attribute graph. In this case, this implementation can specifically identify the node that actually matches the second node among the multiple nodes, thereby improving the accuracy of the recognition.
[0016] In one possible implementation, inputting a first code attribute graph and a second code attribute graph into a code recognition model includes: splitting the first code attribute graph into multiple neighborhood graphs and splitting the second code attribute graph into at least two neighborhood graphs; inputting the multiple neighborhood graphs and the at least two neighborhood graphs into the code recognition model, such that the code recognition model outputs a recognition result; wherein, when each neighborhood graph in the at least two neighborhood graphs matches at least one neighborhood graph in the multiple neighborhood graphs, the graph relation indicates that the second code attribute graph is a subgraph of the first code attribute graph.
[0017] In this implementation, the graph relationships between code attribute graphs can be identified through neighborhood graph matching, which further improves the efficiency of identifying code inclusion relationships.
[0018] In one possible implementation, multiple neighborhood graphs include a first neighborhood graph, and at least two neighborhood graphs include a second neighborhood graph; the method further includes: when the first neighborhood graph and the second neighborhood graph match, confirming that nodes in the first neighborhood graph and nodes in the second neighborhood graph match.
[0019] In this implementation method, node matching can be identified through neighborhood graph matching, which further improves the identification efficiency of node matching.
[0020] Secondly, a method for training a code recognition model is provided. This method includes: acquiring training graph pairs; wherein the training graph pairs include a third code attribute graph and a fourth code attribute graph, and the training graph pairs have a first label, which indicates that the fourth code attribute graph is a subgraph of the third code attribute graph; inputting the training graph pairs into a code recognition model based on a graph neural network, such that the code recognition model outputs a recognition result for the training graph pairs; wherein the recognition result includes a graph relationship between the fourth code attribute graph and the third code attribute graph; when the graph relationship between the fourth code attribute graph and the third code attribute graph in the recognition result is inconsistent with the first label, updating the parameters of the code recognition model so that the graph relationship between the fourth code attribute graph and the third code attribute graph in the recognition result of the training graph pairs output by the code recognition model again is consistent with the first label.
[0021] In one possible implementation, the third code attribute graph includes a fourth node, the fourth code attribute graph includes a fifth node, the training graph pair has a second label, the second label is used to indicate the matching of the fourth node and the fifth node, and the recognition result also includes the node relationship between the fourth node and the fifth node; the method further includes: when the node relationship between the fourth node and the fifth node in the recognition result is inconsistent with the second label, updating the parameters of the code recognition model so that the node relationship between the fourth node and the fifth node in the recognition result of the training graph pair output by the code recognition model again is consistent with the second label.
[0022] In one possible implementation, the training graph pairs are input into a code recognition model, causing the code recognition model to output the recognition result of the training graph pairs, including: splitting the third code attribute graph into multiple neighborhood graphs and splitting the fourth code attribute graph into at least two neighborhood graphs; inputting the multiple neighborhood graphs and at least two neighborhood graphs into the code recognition model, causing the code recognition model to output the recognition result; wherein, when each neighborhood graph in the at least two neighborhood graphs matches at least one neighborhood graph in the multiple neighborhood graphs, the graph relation indicates that the fourth code attribute graph is a subgraph of the third code attribute graph.
[0023] Thirdly, a code recognition device is provided, comprising: an acquisition module for acquiring a first code and a second code; wherein the length of the second code is less than or equal to the length of the first code; a conversion module for converting the first code into a first code attribute graph and converting the second code into a second code attribute graph; a recognition module for inputting the first code attribute graph and the second code attribute graph into a code recognition model based on a graph neural network, such that the code recognition model outputs a recognition result; wherein the recognition result includes a graph relationship between the second code attribute graph and the first code attribute graph; and a confirmation module for confirming that the first code contains the second code when the graph relationship indicates that the second code attribute graph is a subgraph of the first code attribute graph.
[0024] In one possible implementation, the first code attribute graph includes a first node, and the second code attribute graph includes a second node. The first node is transformed from the first code element in the first code, and the second node is transformed from the second code element in the second code. The recognition result also includes the first node relationship between the first node and the second node. The confirmation module is further used to: when the first node relationship indicates that the first node and the second node match, record the correspondence between the position of the first code element in the first code and the position of the second code element in the second code.
[0025] In one possible implementation, the first code attribute graph further includes a third node, which is transformed from the third code element in the first code. The identification result also includes the second node relationship between the first node and the third node. The confirmation module is further configured to: when the first node relationship indicates that the first node and the second node match, and the second node relationship indicates that the third node and the second node match, identify the third node relationship between the neighboring nodes of the second node and the neighboring nodes of the first node, and identify the fourth node relationship between the neighboring nodes of the second node and the neighboring nodes of the third node; when the third node relationship indicates that the neighboring nodes of the second node and the neighboring nodes of the first node match, and the fourth node relationship indicates that the neighboring nodes of the second node and the neighboring nodes of the third node do not match, record the correspondence between the position of the first code element in the first code and the position of the second code element in the second code.
[0026] In one possible implementation, the first code attribute graph also includes a third node, which is transformed from the third code element in the first code. The recognition result also includes the second node relationship between the first node and the third node. The confirmation module is further configured to: input the first node, the second node, and the third node into the node recognition model when the first node relationship indicates that the first node and the second node match, and the second node relationship indicates that the third node and the second node match, so that the node recognition model inputs the node recognition result; when the node recognition result indicates that the first node and the second node match, and the third node and the second node do not match, record the correspondence between the position of the first code element in the first code and the position of the second code element in the second code.
[0027] In one possible implementation, the recognition module is further configured to: split the first code attribute graph into multiple neighborhood graphs, and split the second code attribute graph into at least two neighborhood graphs; input the multiple neighborhood graphs and at least two neighborhood graphs into the code recognition model, so that the code recognition model outputs a recognition result; wherein, when each neighborhood graph in the at least two neighborhood graphs matches at least one neighborhood graph in the multiple neighborhood graphs, the graph relation indicates that the second code attribute graph is a subgraph of the first code attribute graph.
[0028] In one possible implementation, multiple neighborhood graphs include a first neighborhood graph, and at least two neighborhood graphs include a second neighborhood graph; the confirmation module is further configured to: confirm that nodes in the first neighborhood graph and nodes in the second neighborhood graph match when the first neighborhood graph and the second neighborhood graph match.
[0029] Fourthly, a code recognition model training apparatus is provided, comprising: an acquisition module for acquiring training graph pairs; wherein the training graph pairs include a third code attribute graph and a fourth code attribute graph, and the training graph pairs have a first label, the first label indicating that the fourth code attribute graph is a subgraph of the third code attribute graph; an input module for inputting the training graph pairs into a code recognition model based on a graph neural network, such that the code recognition model outputs a recognition result of the training graph pairs; wherein the recognition result includes a graph relationship between the fourth code attribute graph and the third code attribute graph; and a training module for updating the parameters of the code recognition model when the graph relationship between the fourth code attribute graph and the third code attribute graph in the recognition result is inconsistent with the first label, so that the graph relationship between the fourth code attribute graph and the third code attribute graph in the recognition result of the training graph pairs output by the code recognition model again is consistent with the first label.
[0030] In one possible implementation, the third code attribute graph includes a fourth node, the fourth code attribute graph includes a fifth node, the training graph pair has a second label, the second label is used to indicate the matching of the fourth node and the fifth node, and the recognition result also includes the node relationship between the fourth node and the fifth node; the training module is also used to: when the node relationship between the fourth node and the fifth node in the recognition result is inconsistent with the second label, update the parameters of the code recognition model so that the node relationship between the fourth node and the fifth node in the recognition result of the training graph pair output by the code recognition model again is consistent with the second label.
[0031] In one possible implementation, the input module is further configured to: split the third code attribute graph into multiple neighborhood graphs and split the fourth code attribute graph into at least two neighborhood graphs; input the multiple neighborhood graphs and at least two neighborhood graphs into the code recognition model, so that the code recognition model outputs a recognition result; wherein, when each neighborhood graph in the at least two neighborhood graphs matches at least one neighborhood graph in the multiple neighborhood graphs, the graph relation indicates that the fourth code attribute graph is a subgraph of the third code attribute graph.
[0032] Fifthly, a computing device cluster is provided, including at least one computing device, each computing device including a processor and a 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, such that the computing device cluster performs the method provided in the first aspect.
[0033] In a sixth aspect, a computing device cluster is provided, including at least one computing device, each computing device including a processor and a 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, such that the computing device cluster performs the method provided in the second aspect.
[0034] In a seventh aspect, a computer-readable storage medium is provided, including computer program instructions that, when executed by a cluster of computing devices, execute the method provided in the first aspect.
[0035] In an eighth aspect, a computer-readable storage medium is provided, including computer program instructions that, when executed by a cluster of computing devices, execute the method provided in the second aspect.
[0036] In a ninth aspect, a computer program product containing instructions is provided, which, when executed by a cluster of computer devices, cause the cluster of computer devices to perform the method provided in the first aspect.
[0037] In a tenth aspect, a computer program product containing instructions is provided, which, when executed by a cluster of computer devices, cause the cluster of computer devices to perform the method provided in the second aspect.
[0038] The beneficial effects of aspects two through ten can be found in the above description of the beneficial effects of aspect one, and will not be repeated here. Attached Figure Description
[0039] Figure 1 is a schematic diagram of a system architecture provided in an embodiment of this application;
[0040] Figure 2 is a flowchart of a code recognition model training method provided in an embodiment of this application;
[0041] Figure 3 is a schematic diagram of a system architecture provided in an embodiment of this application;
[0042] Figure 4 is a flowchart of a code recognition method provided in an embodiment of this application;
[0043] Figure 5 is a schematic diagram of the structure of a code recognition model training device provided in an embodiment of this application;
[0044] Figure 6 is a schematic diagram of the structure of a computing device provided in an embodiment of this application;
[0045] Figure 7 is a schematic diagram of the structure of a computing device cluster provided in an embodiment of this application;
[0046] Figure 8 is a schematic diagram of the structure of a computing device cluster provided in an embodiment of this application;
[0047] Figure 9 is a schematic diagram of the structure of a code recognition device provided in an embodiment of this application;
[0048] Figure 10 is a schematic diagram of the structure of a computing device provided in an embodiment of this application;
[0049] Figure 11 is a schematic diagram of the structure of a computing device cluster provided in an embodiment of this application;
[0050] Figure 12 is a schematic diagram of the structure of a computing device cluster provided in an embodiment of this application. Detailed Implementation
[0051] The solutions provided in the embodiments of this application will now be described with reference to the accompanying drawings. In the embodiments of this application, "multiple" refers to two or more objects, and "various types" refers to two or more types. Terms such as "first," "second," etc., are only used to distinguish similar objects and are not necessarily used to describe a specific order or number of objects.
[0052] To facilitate understanding of the solutions provided in the embodiments of this application, the technical terms that may be involved in the embodiments of this application will be introduced first.
[0053] Application code: Also known as application program code, it refers to the code that implements the functionality of the application. Application code can include user-written code as well as code for one or more standard operators.
[0054] Standard operators, also known as typical operators, refer to a class of operators with general functions, such as operators for performing matrix multiplication, fast Fourier transform (FFT), and sparse matrix operations. Users can add the code of standard operators to their application code when developing applications, thus eliminating the need for users to manually develop standard operators.
[0055] A code property graph (CPG) is a graphical model representing the structure of source code. It consists of nodes and connecting edges, where edges connect nodes. Nodes represent code elements (such as variables and functions), and the connecting edges represent the relationships between these elements. CPGs capture the structural features and semantic information of code, allowing for formal representation and processing. Common types of CPGs include abstract syntax trees (ASTs), control flow graphs (CFGs), program dependence graphs (PDGs), and call graphs (CGs).
[0056] Code element: This is the unit of code, such as a variable or function. Application code can consist of multiple code elements, while the code of a standard operator consists of at least one code element.
[0057] Code structure characteristics refer to the way code is organized and laid out, including code modularization, function partitioning, and class definitions. Good code structure characteristics can improve code readability, maintainability, and extensibility. For example, encapsulating related functionalities in functions or classes makes the code more modular, easier to manage, and more reusable. Furthermore, a reasonable code structure can reduce the occurrence of errors because complex logic is broken down into multiple simpler parts, each of which is easier to understand and debug.
[0058] Code semantics refers to the meaning of statements and expressions in a programming language. It describes the behavior and results of a program, including static and dynamic semantics. Static semantics refers to semantics determined at compile time, such as variable type checking; dynamic semantics refers to semantics determined at runtime, such as the return value of a function call. Semantic analysis is an important part of programming language processing, helping the compiler understand the intent of the code, thereby enabling correct compilation and optimization.
[0059] Subgraph: A subgraph is a smaller code attribute graph that belongs to the larger code attribute graph. A subgraph of a code attribute graph is a local graph within that code attribute graph, or in other words, a subgraph of a code attribute graph is identical to a part of that code attribute graph, or a subgraph of a code attribute graph is contained within that code attribute graph.
[0060] A neighborhood graph is a graph consisting of a central node and its N-order neighbors. Here, N is an integer greater than or equal to 1.
[0061] A graph pair is a graph combination consisting of two code attribute graphs. Within the same graph pair, the smaller code attribute graph can be a subgraph of the larger code attribute graph. That is, the two graphs in the same pair have a subgraph matching relationship. Alternatively, the two graphs in the same pair may not have a subgraph relationship, meaning the smaller code attribute graph is not a subgraph of the larger code attribute graph. The two graphs in the same graph pair can be called the target graph and the query graph, respectively. If the two graphs have a subgraph matching relationship, then the smaller code attribute graph is the query graph, and the other graph is the target graph. If the two graphs do not have a subgraph matching relationship, then one of the two graphs is the query graph, and the other is the target graph.
[0062] Subgraph matching: This determines whether a smaller code attribute graph is a subgraph of a larger code attribute graph.
[0063] Graph relationships refer to the relationships between two code attribute graphs. For example, a graph relationship between two code attribute graphs can be a subgraph matching relationship, meaning that one of the two code attribute graphs is a subgraph of the other. A graph relationship between two code attribute graphs can also be a non-subgraph matching relationship, meaning that the two code attribute graphs do not have a subgraph matching relationship.
[0064] Node relationships refer to the relationships between two nodes. Node relationships can be matching or non-matching. Two nodes with a matching relationship are identical, while two nodes with a non-matching relationship are different. Specifically, for a target graph and a query graph that constitute a subgraph matching relationship, some or all nodes in the query graph have corresponding nodes in the target graph.
[0065] Graph neural network (GNN) is an artificial intelligence (AI) model that uses neural networks to learn graph-structured data, extract and discover features and patterns in the graph-structured data, and meet the needs of graph learning tasks such as clustering, classification, prediction, segmentation or generation.
[0066] High-performance computing (HPC) refers to the use of supercomputers and parallel processing techniques to solve complex computational problems in the fields of science and engineering.
[0067] With the rapid development of computing hardware and chip technology, HPC systems have become a crucial pillar of scientific research and industrial innovation. However, as the scale and complexity of HPC systems continue to grow, application migration and performance optimization have become significant challenges. Application migration refers to porting existing application code to a new hardware platform. Therefore, application migration typically requires adjusting application code to adapt to the new hardware environment. Performance optimization refers to improving application code so that it can run faster and more efficiently on given hardware. The efficiency of application migration and performance optimization directly impacts the overall performance and scalability of the HPC system.
[0068] Generally, adjustments or improvements to application code specifically involve adjusting or improving the standard operators within the application code. Therefore, the efficiency of identifying standard operators from application code directly impacts the efficiency of application migration or performance optimization. Semantic-based code similarity recognition techniques can capture subtle differences in different lexical structures within application code and can also identify similarities between codes at the logical level. Among these, subgraph matching based on code attribute graphs is a commonly used semantic-based code similarity technique.
[0069] Subgraph matching based on code attribute graphs is used to identify whether a smaller code attribute graph is contained within a larger code attribute graph. The smaller code attribute graph can be called the query graph, and the larger code attribute graph can be called the target graph. The query graph is the code attribute graph of the standard operator, and the target graph is the code attribute graph of the application code. The goal is to determine whether a subgraph identical to the query graph exists in the target graph. If it does, the target graph contains the query graph, meaning the application code contains the code of the standard operator. If it does not, the target graph does not contain the query graph, meaning the application code does not contain the code of the standard operator.
[0070] In related technologies, traditional subgraph matching algorithms (such as VF2) are used to identify code with standard operators in application code. However, traditional subgraph matching algorithms have high time complexity for code identification and cannot be used for large-scale code attribute graphs. Since the computational requirements of traditional subgraph matching algorithms increase non-linearly with the size of the graph, the processing time can become unacceptable when dealing with code attribute graphs containing a large number of nodes, severely hindering the practical application of similar code identification in HPC environments.
[0071] When adjusting or improving application code, it's necessary to pinpoint the specific lines of code that require modification or optimization; that is, to identify the location of the code segment within the application code. However, traditional similar code identification methods often only provide overall results and cannot pinpoint the exact lines of code that need modification when trying to adapt to new hardware platforms or optimize performance. This lack of information makes it difficult for developers to directly locate the code that needs modification when attempting to adapt to new hardware platforms or optimize performance, increasing the difficulty and uncertainty of application migration and performance optimization.
[0072] In view of this, embodiments of this application provide a code recognition model training method and a code recognition method based on a code recognition model.
[0073] The code recognition model training method described herein can train a code recognition model. This code recognition model is based on a graph neural network and can also be called a graph neural network model. This code recognition model is used to identify the inclusion relationship between two code attribute graphs. Specifically, the inclusion relationship between two code attribute graphs can be used to obtain the inclusion relationship between the corresponding codes in the two code attribute graphs.
[0074] This code recognition method utilizes a code recognition model to identify code inclusion relationships. In summary, it obtains two codes, A1 and A2, where the length of A2 is shorter than the length of A1. Code A1 is converted into a code attribute graph B1, and code A2 is converted into a code attribute graph B2. Next, code attribute graphs B1 and B2 are input into the code recognition model, which performs relevant calculations on them to obtain and output the recognition result. This result can include the graph relationship between code attribute graphs B1 and B2. The graph relationship indicates that code attribute graph B2 is a subgraph of code attribute graph B1, or vice versa. When the graph relationship indicates that code attribute graph B2 is a subgraph of code attribute graph B1, it can be confirmed that code A1 contains code A2. Therefore, code inclusion relationships can be identified efficiently.
[0075] Next, we will introduce in detail the code recognition model training method provided in the embodiments of this application.
[0076] Figure 1 illustrates a system architecture 100 that can be used to implement this model training method. The system architecture 100 includes a transformation module 110, a training set construction module 120, and a training module 130.
[0077] The conversion module 110 can convert each code in the multiple code sets into a code attribute graph, with one code set corresponding to one code attribute graph. The code set can specifically be source code. For example, the multiple code sets can be several randomly selected existing code sets, such as multiple code sets taken from a code hosting service platform (GitHub). The following description uses code A3 from these multiple code sets as an example.
[0078] Code analysis tools can be used to parse code A3, obtaining its code elements and extracting its semantic and structural features. Then, based on these code elements, semantics, and structural features, code A3 can be transformed into a code attribute graph B3. The code elements can serve as nodes in code attribute graph B3, and connections between these nodes can be constructed based on the semantic and structural features of code A3.
[0079] In some embodiments, the code analysis tool can be a static code analysis tool, such as Joern. Joern can parse code and automatically extract semantic and structural features (such as control flow structure) and, based on the extracted information, convert the code into a program dependency graph or other code attribute graph.
[0080] The conversion module 110 can send the converted code attribute graph to the training graph pair construction module 120. The training graph pair construction module 120 can construct training graph pairs based on the code attribute graph received from the conversion module 110. Taking code attribute graph B3 as an example, code attribute graph B4 can be obtained based on code attribute graph B3. Code attribute graph B3 and code attribute graph B4 form a graph pair with a subgraph matching relationship.
[0081] In some embodiments, code attribute graph B4 is a subgraph of code attribute graph B3. The training graph construction module 120 can delete at least one node and / or at least one connecting edge in code attribute graph B3 to obtain code attribute graph B4.
[0082] In some embodiments, code attribute graph B3 is a subgraph of code attribute graph B4. The training graph construction module 120 can add at least one node and / or at least one connecting edge to code attribute graph B3 to obtain code attribute graph B4.
[0083] In some embodiments, the code attribute graph received by the training graph pair construction module 120 from the transformation module 110 further includes code attribute graph B5. Code attribute graph B6 can be obtained based on code attribute graph B5. Code attribute graph B5 and code attribute graph B6 form a graph pair without subgraph matching relationships. Specifically, the semantics of at least one node and / or at least one connecting edge in code attribute graph B5 can be modified to obtain code attribute graph 6.
[0084] The graph pairs constructed by the training graph pair building module 120 are used to train the code recognition model and can be called training graph pairs.
[0085] Labels can be added to each training graph pair. Specifically, label C1 is added to training graph pairs with subgraph matching relationships (e.g., the pair consisting of code attribute graph B3 and code attribute graph B4), and label C2 is added to training graph pairs without subgraph matching relationships (e.g., the pair consisting of code attribute graph B5 and code attribute graph B6). Label C1 indicates that code attribute graph B4 is a subgraph of code attribute graph B3, or code attribute graph B3 is a subgraph of code attribute graph B4. Label C2 indicates that code attribute graph B5 is not a subgraph of code attribute graph B6, and code attribute graph B6 is not a subgraph of code attribute graph B3.
[0086] In some embodiments, a label D1 is added to training graph pairs that have subgraph matching relationships. Label D1 indicates that nodes shared by code attribute graph B4 and code attribute graph B3 have node matching relationships. For example, code attribute graph B3 includes nodes B31, B32, B33, etc., and code attribute graph B4 includes nodes B41, B42, etc. If nodes B31 and B41 are the same, and nodes B32 and B42 are the same, then the label D1 added to the graph pair composed of code attribute graphs B3 and B4 indicates that nodes B31 and B41 have node matching relationships, and nodes B32 and B42 have node matching relationships.
[0087] Specifically, for the target graph and query graph that constitute the subgraph matching relationship, some or all of the nodes in the query graph have corresponding nodes in the target graph.
[0088] In some embodiments, at least one piece of information can be selected from multiple pieces of information about a node in the code attribute graph. The selected information is used as the feature vector of that node for relevant calculations in a graph neural network or code recognition model. Nodes in the code attribute graph are derived from code elements and possess relevant information about the code elements, such as code snippets, variable names, programming languages, and code types. The code type of the code element can also be referred to as the node type of the node derived from that code element. For example, the node type, code snippets, variable names, etc., from the multiple pieces of information possessed by a node can be used as the feature vector of that node.
[0089] In some embodiments, at least one piece of information can be selected from multiple pieces of information about the connecting edges in the code attribute graph. The selected information is used as the feature vector of the connecting edge for relevant calculations in the graph neural network or code recognition model. A connecting edge represents the relationship between the codes corresponding to the nodes it connects to, such as call relationships, data flow relationships, etc. The multiple pieces of information about a connecting edge can include the relationships between the codes corresponding to the nodes it connects to, and call relationships, data flow relationships, etc., can be used as the feature vector of the connecting edge.
[0090] Thus, the training graph pair construction module 120 can construct multiple labeled training graph pairs.
[0091] The training graph pair construction module 120 can send multiple labeled training graph pairs to the training module 130. The training module 130 can use these labeled training graph pairs to train a code recognition model. The model to be recognized is a graph neural network-based model. That is, multiple labeled training graph pairs can be used to train the graph neural network, enabling it to learn the ability to recognize relationships between graph pairs (e.g., subgraph matching relationships, node matching relationships). The graph neural network that learns to recognize relationships between graph pairs can be called a code recognition model.
[0092] Specifically, the multiple labeled training graph pairs can be input into a graph neural network. For example, the graph neural network can be a graph convolutional neural network (GCNN) or a graph attention network (GAT). For example, before inputting the training graph pairs into the graph neural network, the data format of the code attribute graphs in the graph pairs can be converted to match the data format of the code attribute graphs with the graph neural network.
[0093] Graph neural networks can perform relevant calculations on code attribute graphs within a graph pair. For example, using relevant parameters, they can calculate the feature vectors of nodes and the feature vectors of connecting edges in the code attribute graph, and based on the calculation results, obtain and output the recognition results. The recognition results can include the graph relationships between the two code attribute graphs in the same graph pair. Graph relationships are used to represent the relationship between the two code attribute graphs, such as subgraph matching relationships or non-subgraph matching relationships.
[0094] In one example, for the same graph pair, the similarity between a node in the query graph and each node in the target graph can be calculated to find the node in the target graph with the highest similarity for that node in the query graph. If the similarity between the node in the query graph and its highest-similar node in the target graph meets a requirement (e.g., greater than a certain threshold, which is a parameter of the graph neural network), it can be confirmed that the node matches the node with its highest-similar node in the target graph. If every node in the query graph matches at least one node in the target graph, it can be confirmed that the query graph is a subgraph of the target graph, and the graph relationships included in the recognition result indicate that the query graph is a subgraph of the target graph. If at least one node in the query graph does not match a node in the target graph, it can be confirmed that the query graph is not a subgraph of the target graph, and the graph relationships included in the recognition result indicate that the query graph is not a subgraph of the target graph. Furthermore, in this example, the graph neural network can specifically be an end-to-end graph neural network.
[0095] For example, the identification result may also include the node relationships between nodes in the query graph and nodes in the target graph. For example, a node matching matrix can be used to represent or record the node relationships between nodes in the query graph and nodes in the target graph. Here, the node relationship between a node in the query graph and its matching node in the target graph indicates a match between the node in the query graph and its matching node in the target graph. The node in the query graph does not match with other nodes. Here, "other nodes" refers to nodes in the target graph other than those nodes that match the node in the query graph.
[0096] In each training iteration of the graph neural network, it is determined whether the recognition result of the graph pair output in this iteration matches the label of the graph pair. If they do not match, the parameters of the graph neural network are updated for the next iteration. This process is repeated until the recognition result of the graph pair output by the graph neural network matches the label of the graph pair again, that is, the graph neural network converges. Thus, the code recognition model can be obtained.
[0097] For example, consider a graph pair consisting of code attribute graphs B3 and B4. Code attribute graph B4 can be defined as a subgraph of code attribute graph B3, meaning this graph pair has a label C1. This graph pair is input into a graph neural network (GNN), which outputs a recognition result for the pair. This recognition result includes the graph relationship between code attribute graphs B3 and B4. If the graph relationship does not match the label C1, meaning the graph relationship indicates that code attribute graph B4 is not a subgraph of code attribute graph B3, while label C1 indicates that code attribute graph B4 is a subgraph of code attribute graph B3, the parameters of the GNN are updated so that the graph relationship in the recognition result output by the GNN again matches the label C1. It's important to understand that the graph relationship in the recognition result output by the GNN does not necessarily match the label C1 after just one parameter adjustment or training iteration; multiple adjustments or training iterations are required.
[0098] For example, the graph neural network outputs the recognition result of the graph pair, which also includes the node relationship between nodes in code attribute graph B3 and nodes in code attribute graph B4. The graph pair composed of code attribute graphs B3 and B4 also has a label D1. Label D1 indicates that nodes shared by code attribute graphs B4 and B3 have a node matching relationship. Specifically, node B31 in code attribute graph B3 and node B41 in code attribute graph B4 can be set to be the same. Label D1 indicates that nodes B31 and B41 have a node matching relationship. If the node relationship between nodes B31 and B41 in the recognition result is inconsistent with label D1, the parameters of the graph neural network are updated so that the node relationship between nodes B31 and B41 in the recognition result output by the graph neural network again is consistent with label D1. It is understood that the node relationship between nodes B31 and B41 in the recognition result output by the graph neural network again will not be consistent with label D1 after only one parameter adjustment or one training iteration; rather, multiple adjustments or training iterations are required.
[0099] In some embodiments, the training module 130 can split the code attribute graph in the graph pair into neighborhood graphs and input the split neighborhood graphs into a graph neural network. For example, the graph neural network can specifically be an anchor comparison graph neural network. Taking code attribute graphs B3 and B4 as examples, code attribute graph B3 can be split into multiple neighborhood graphs, and code attribute graph B4 can be split into at least two neighborhood graphs. The multiple neighborhood graphs and the at least two neighborhood graphs are then input into the graph neural network. The graph neural network can calculate the similarity between the neighborhood graphs in the multiple neighborhood graphs and the neighborhood graphs in the at least two neighborhood graphs. If the similarity between two neighborhood graphs meets a condition (e.g., greater than a certain threshold), it can be confirmed that the two neighborhood graphs match, and that the nodes in the two neighborhood graphs match. If each neighborhood graph in the at least two neighborhood graphs matches at least one neighborhood graph in the multiple neighborhood graphs, it can be confirmed that code attribute graph B4 is a subgraph of code attribute graph B3. Therefore, the graph relationship between code attribute graphs B3 and B4 in the recognition result output by the graph neural network is consistent with the label C1. If at least one of the at least two neighborhood graphs does not have a matching neighborhood graph in the plurality of neighborhood graphs, then it can be confirmed that code attribute graph B4 is not a subgraph of code attribute graph B3. Therefore, the graph relationship between code attribute graph B3 and code attribute graph B4 in the recognition result output by the graph neural network is inconsistent with the label C1.
[0100] In some embodiments, a loss can be calculated based on the graph relationships, node relationships, and graph pair labels in the recognition results of the training graph pairs. This loss can be a binary classification loss, i.e., whether subgraphs match or not, and whether nodes match or not. The node matching or non-matching can be represented using the mean squared error loss of the node matching matrix. Then, based on the calculated loss, the parameters of the graph neural network are updated using the backpropagation algorithm to train the graph neural network.
[0101] In this way, a code recognition model based on a graph neural network can be trained.
[0102] The example above introduced a system architecture that can be used to implement a code recognition model training method. Next, using this system architecture as an example, the process of training the code recognition model is described. As shown in Figure 2, the method includes the following steps.
[0103] Step 201: Obtain training graph pairs; wherein the training graph pairs include a third code attribute graph and a fourth code attribute graph, and the training graph pairs have a first label, which is used to indicate that the fourth code attribute graph is a subgraph of the third code attribute graph.
[0104] The third code attribute graph can be code attribute graph B3 as described above, the fourth code attribute graph can be code attribute graph B4 as described above, and the first label can be label C1 as described above. The specific implementation of step 201 can be found in the above description of the training graph pair implementation, and will not be repeated here.
[0105] Step 202: Input the training graph pair into the code recognition model based on graph neural network, so that the code recognition model outputs the recognition result of the training graph pair; wherein, the recognition result includes the graph relationship between the fourth code attribute graph and the third code attribute graph.
[0106] Here, the code recognition model can also be called a graph neural network, referring to the code recognition model that is being trained. The specific implementation of step 202 can be found in the description of the embodiment shown in Figure 1 above, and will not be repeated here.
[0107] Step 203: When the graph relationship between the fourth code attribute graph and the third code attribute graph in the recognition result is inconsistent with the first label, update the parameters of the code recognition model so that the graph relationship between the fourth code attribute graph and the third code attribute graph in the recognition result of the training graph pair output by the code recognition model again is consistent with the first label.
[0108] The specific implementation of step 203 can be referred to the above description of the embodiment shown in Figure 1, and will not be repeated here.
[0109] In some embodiments, the third code attribute graph includes a fourth node, the fourth code attribute graph includes a fifth node, the training graph pair has a second label, the second label is used to indicate that the fourth node and the fifth node match, and the recognition result also includes the node relationship between the fourth node and the fifth node; the method further includes: when the node relationship between the fourth node and the fifth node in the recognition result is inconsistent with the second label, updating the parameters of the code recognition model so that the node relationship between the fourth node and the fifth node in the recognition result of the training graph pair output by the code recognition model again is consistent with the second label.
[0110] The fourth node can be node B31 as described above, and the fifth node can be node B41 as described above. The specific implementation of this embodiment can be found in the description of the embodiment shown in Figure 1 above, and will not be repeated here.
[0111] In some embodiments, inputting the training graph pair into a code recognition model, such that the code recognition model outputs the recognition result of the training graph pair, includes: splitting the third code attribute graph into multiple neighborhood graphs, and splitting the fourth code attribute graph into at least two neighborhood graphs; inputting the multiple neighborhood graphs and the at least two neighborhood graphs into the code recognition model, such that the code recognition model outputs the recognition result; wherein, when each neighborhood graph in the at least two neighborhood graphs matches at least one neighborhood graph in the multiple neighborhood graphs, the graph relationship indicates that the fourth code attribute graph is a subgraph of the third code attribute graph.
[0112] The specific implementation of this embodiment can be referred to the above description of the embodiment shown in Figure 1, and will not be repeated here.
[0113] In summary, the code recognition model training method adopted in the embodiments of this application can provide a code recognition model capable of determining whether there is a subgraph relationship between two code attribute graphs. This code recognition model can efficiently identify the inclusion relationship between codes.
[0114] This application provides a code recognition method that can identify the inclusion relationship between two pieces of code using the code recognition model provided in this application. Details are as follows.
[0115] Figure 3 illustrates a system architecture 300 that can be used to implement this code recognition method. As shown in Figure 3, the system architecture 300 includes an acquisition module 310, a conversion module 320, a recognition module 330, and a recognition module 340. The recognition module 330 is equipped with a code recognition model. This code recognition model can be trained according to the method shown in Figure 2.
[0116] The acquisition module 310 can acquire the code pairs to be identified. Each code pair consists of two codes. The following section will describe a code pair consisting of code A1 and code A2.
[0117] As shown in Figure 3, the acquisition module 310 can acquire code A1 and code A2. The length of code A2 is less than or equal to the length of code A3. In some embodiments, code A1 can be application code, and code A2 can be operator code, such as the code of a standard operator.
[0118] The acquisition module 310 can send code A1 and code A2 to the conversion module 320. The conversion module 320 can convert code A1 into code attribute graph B1 and code A2 into code attribute graph B2. For details, please refer to the above description of the implementation of conversion module 110.
[0119] The conversion module 320 can input code attribute map B1 and code attribute map B2 into the recognition module 330. The recognition module 330 can input code attribute map B1 and code attribute map B2 into the code recognition model. For example, before inputting code attribute map B1 and code attribute map B2, the recognition module 330 can perform format conversion on the data format of code attribute map B1 and code attribute map B2 so that the data format of code attribute map B1 and code attribute map B2 matches the code recognition model.
[0120] The code recognition model performs relevant calculations on code attribute graphs B1 and B2 to obtain and output the recognition results.
[0121] The recognition module 340 can acquire the recognition results output by the code recognition model. The recognition results may include the graph relationship between code attribute graph B1 and code attribute graph B2. Based on this graph relationship, the recognition module 340 can identify the relationship between code A1 and code A2. When the graph relationship indicates that code attribute graph B2 is a subgraph of code attribute graph B1, the recognition module 340 can confirm that code A1 contains code A2. When the graph relationship indicates that code attribute graph B2 is not a subgraph of code attribute graph B1, the recognition module 340 can confirm that code A1 does not contain code A2.
[0122] The above example illustrates a system architecture that can be used to implement the code recognition method provided in the embodiments of this application. Next, the flow of the code recognition method provided in the embodiments of this application will be described in conjunction with this system architecture. As shown in Figure 4, the method includes the following steps.
[0123] Step 401: Obtain the first code and the second code; wherein the length of the second code is less than or equal to the length of the first code.
[0124] The first code can be code A1 as described above, and the second code can be code A2 as described above.
[0125] Step 402: Convert the first code into a first code attribute map and convert the second code into a second code attribute map.
[0126] The first code attribute diagram can be the code attribute diagram B1 described above, and the second code attribute diagram can be the code attribute diagram B2 described above. Step 402 can be implemented with reference to the description of the conversion module 110 above.
[0127] Step 403: Input the first code attribute map and the second code attribute map into the code recognition model based on graph neural network, so that the code recognition model outputs the recognition result; wherein, the recognition result includes the graph relationship between the second code attribute map and the first code attribute map.
[0128] The code recognition model can calculate the first code attribute map and the second code attribute map, and obtain the recognition result based on the calculation result.
[0129] In some embodiments, the similarity between a node in the second code attribute graph and each node in the first code attribute graph can be calculated to obtain the node in the second code attribute graph with the highest similarity in the first code attribute graph. If the similarity between the node in the second code attribute graph and the node with the highest similarity in the first code attribute graph meets the requirement (e.g., greater than a certain threshold, which is a parameter trained in the code recognition model), it can be confirmed that the node matches the node with the highest similarity in the first code attribute graph. If each node in the second code attribute graph matches at least one node in the target graph, it can be confirmed that the second code attribute graph is a subgraph of the first code attribute graph, and the graph relationships included in the recognition result indicate that the second code attribute graph is a subgraph of the first code attribute graph. If at least one node in the second code attribute graph does not match a node in the first code attribute graph, it can be confirmed that the second code attribute graph is not a subgraph of the first code attribute graph, and the graph relationships included in the recognition result indicate that the second code attribute graph is not a subgraph of the first code attribute graph.
[0130] In some embodiments, inputting the first code attribute graph and the second code attribute graph into the code recognition model includes: splitting the first code attribute graph into a plurality of neighborhood graphs, and splitting the second code attribute graph into at least two neighborhood graphs; inputting the plurality of neighborhood graphs and the at least two neighborhood graphs into the code recognition model, such that the code recognition model outputs the recognition result; wherein, when each neighborhood graph in the at least two neighborhood graphs matches at least one neighborhood graph in the plurality of neighborhood graphs, the graph relationship indicates that the second code attribute graph is a subgraph of the first code attribute graph.
[0131] The first code attribute graph can be split into multiple neighborhood graphs, and the second code attribute graph can be split into at least two neighborhood graphs. The multiple neighborhood graphs and the at least two neighborhood graphs are input into a code recognition model. The code recognition model can calculate the similarity between the neighborhood graphs in the multiple neighborhood graphs and the neighborhood graphs in the at least two neighborhood graphs. If the similarity between two neighborhood graphs meets a condition (e.g., greater than a certain threshold, which is a parameter trained in the code recognition model), it can be confirmed that the two neighborhood graphs match, and that the nodes in the two neighborhood graphs match. If each neighborhood graph in the at least two neighborhood graphs matches at least one neighbor graph in the multiple neighborhood graphs, it can be confirmed that the second code attribute graph is a subgraph of the first code attribute graph, and the graph relations included in the recognition result indicate that the second code attribute graph is a subgraph of the first code attribute graph. If at least one neighborhood graph in the at least two neighborhood graphs does not match a neighbor graph in the multiple neighborhood graphs, it can be confirmed that the second code attribute graph is not a subgraph of the first code attribute graph, and the graph relations included in the recognition result indicate that the second code attribute graph is not a subgraph of the first code attribute graph.
[0132] Step 404: When the graph relationship indicates that the second code attribute graph is a subgraph of the first code attribute graph, confirm that the first code contains the second code.
[0133] Additionally, when the graph relationship indicates that the second code attribute graph is not a subgraph of the first code attribute graph, it is confirmed that the first code does not contain the second code.
[0134] In some embodiments, the first code attribute graph includes a first node, the second code attribute graph includes a second node, the first node is transformed from a first code element in the first code, the second node is transformed from a second code element in the second code, and the recognition result also includes a first node relationship between the first node and the second node; the method further includes: when the first node relationship indicates that the first node and the second node match, recording the correspondence between the position of the first code element in the first code and the position of the second code element in the second code.
[0135] Nodes can also carry the position of their corresponding code element within the code. This code refers to the code containing the code element, and the code element corresponding to the node refers to the code element that is transformed into that node. For example, the position of the code element corresponding to a node within the code can serve as the node's identifier. For example, the position of the code element within the code can be the line identifier of the code element within the code. Matching nodes in different code attribute graphs allows recording the positional correspondence of the nodes, which is the position of the code element corresponding to the node within the code. Therefore, by matching two nodes, the correspondence between the positions of their respective code elements within their respective code can be obtained. For example, if the first code element is located at position P1 in the first code and the second code element is located at position P2 in the second code, and the node transformed from the first code element (i.e., the first node) matches the node transformed from the second code element (i.e., the second node), then it can be recorded that the code element at position P1 in the first code and the code element at position P2 in the second code are matched.
[0136] In one example of this embodiment, the first code attribute graph further includes a third node, which is transformed from a third code element in the first code. The recognition result also includes a second node relationship between the first node and the third node. When the first node relationship indicates that the first node and the second node match, the correspondence between the position of the first code element in the first code and the position of the second code element in the second code is recorded, including: when the first node relationship indicates that the first node and the second node match, and the second node relationship indicates that the third node and the second node match, identifying a third node relationship between the neighboring nodes of the second node and the neighboring nodes of the first node, and identifying a fourth node relationship between the neighboring nodes of the second node and the neighboring nodes of the third node; when the third node relationship indicates that the neighboring nodes of the second node and the neighboring nodes of the first node match, and the fourth node relationship indicates that the neighboring nodes of the second node and the neighboring nodes of the third node do not match, the correspondence between the position of the first code element in the first code and the position of the second code element in the second code is recorded.
[0137] In the recognition results output by the code recognition model, a node in the second code attribute graph may match multiple nodes in the same graph. In this case, the matching of neighboring nodes can be used to identify which of these multiple nodes the node should match. For example, if a second node in the second code attribute graph matches both the first and third nodes in the first code attribute graph, and the neighboring nodes of the second node match the neighboring nodes of the first node, but the neighboring nodes of the second node and the third node do not match, then the second node should match the first node, not the third node. In other words, matching the second node with the first node is the correct recognition result, while matching the second node with the third node is an incorrect recognition result.
[0138] In one example of this embodiment, the first code attribute graph further includes a third node, which is transformed from the third code element in the first code. The recognition result also includes a second node relationship between the first node and the third node. When the first node relationship indicates that the first node and the second node match, recording the correspondence between the position of the first code element in the first code and the position of the second code element in the second code includes: when the first node relationship indicates that the first node and the second node match, and the second node relationship indicates that the third node and the second node match, inputting the first node, the second node, and the third node into the node recognition model, so that the node recognition model inputs the node recognition result; when the node recognition result indicates that the first node and the second node match, and the third node and the second node do not match, recording the correspondence between the position of the first code element in the first code and the position of the second code element in the second code.
[0139] When a node in the second code attribute graph matches multiple nodes in the second code attribute graph, the node and the multiple nodes in the second code attribute graph can be input into the node recognition model. The node recognition model can output the node recognition result, which can represent the correct matching node of the node in the second code attribute graph among the multiple nodes.
[0140] The node recognition model can be a neural network-based model, which can be trained in the following way.
[0141] When using a code recognition model for inference, data can be collected showing that a node in the query graph matches multiple nodes in the target graph from the model's output. For example, node E1 matches multiple nodes such as F1 and F2. The correct match for node E1 among these multiple nodes can be manually determined, and node F1 can be identified as the correct match. A label can be added to node F1, indicating that node F1 is the correct match for node E1. Then, nodes E1, F1, F2, etc., are input into the node recognition model to be trained, causing the model to output node recognition results. The node recognition model is trained while improving the consistency between the node recognition results and the label added to node F1. Thus, the node recognition model is obtained.
[0142] In one example, the feature vectors of multiple nodes, such as node F1 and node F2, can be summed, and the summation result can be concatenated with the feature vector of node E1. The concatenated feature vector is then input into the code recognition model, causing the model to output the node recognition result.
[0143] In some embodiments, as described above, in step 403, the first code attribute graph can be split into multiple neighborhood graphs, and the second code attribute graph can be split into at least two neighborhood graphs. The multiple neighborhood graphs include the first neighborhood graph, and the at least two neighborhood graphs include the second neighborhood graph. The method further includes: when the first neighborhood graph and the second neighborhood graph match, confirming that a node in the first neighborhood graph matches a node in the second neighborhood graph.
[0144] If two neighborhood graphs match, it means that the nodes in those two neighborhood graphs are matched. By identifying the matching relationships in the neighborhood graphs, we can identify the matching relationships in the nodes, which can improve the efficiency of node matching.
[0145] In summary, the method provided in this application embodiment can efficiently identify the inclusion relationships between codes using graph neural networks. It improves recognition efficiency while ensuring accuracy. Experimental results show that, compared to traditional subgraph matching algorithms, the code recognition method provided in this application embodiment can improve recognition speed by 1-2 orders of magnitude, and the larger the code attribute graph, the more significant the improvement in recognition speed.
[0146] Based on the above description, this application provides a code recognition model training device 500. As shown in Figure 5, the device 500 includes:
[0147] The acquisition module 510 is used to acquire training graph pairs; wherein, the training graph pair includes a third code attribute graph and a fourth code attribute graph, and the training graph pair has a first label, which is used to indicate that the fourth code attribute graph is a subgraph of the third code attribute graph;
[0148] The input module 520 is used to input the training graph pairs into the code recognition model based on the graph neural network, so that the code recognition model outputs the recognition result of the training graph pairs; wherein, the recognition result includes the graph relationship between the fourth code attribute graph and the third code attribute graph;
[0149] The training module 530 is used to update the parameters of the code recognition model when the graph relationship between the fourth code attribute graph and the third code attribute graph in the recognition result is inconsistent with the first label, so that the graph relationship between the fourth code attribute graph and the third code attribute graph in the recognition result of the training graph pair output by the code recognition model is consistent with the first label.
[0150] In some embodiments, the third code attribute graph includes a fourth node, the fourth code attribute graph includes a fifth node, the training graph pair has a second label, the second label is used to indicate that the fourth node and the fifth node match, and the recognition result also includes the node relationship between the fourth node and the fifth node; the training module 530 is further configured to: when the node relationship between the fourth node and the fifth node in the recognition result is inconsistent with the second label, update the parameters of the code recognition model so that the node relationship between the fourth node and the fifth node in the recognition result of the training graph pair output by the code recognition model again is consistent with the second label.
[0151] In some embodiments, the input module 520 is further configured to: split the third code attribute graph into multiple neighborhood graphs and split the fourth code attribute graph into at least two neighborhood graphs; input the multiple neighborhood graphs and at least two neighborhood graphs into the code recognition model, so that the code recognition model outputs a recognition result; wherein, when each neighborhood graph in the at least two neighborhood graphs matches at least one neighborhood graph in the multiple neighborhood graphs, the graph relation indicates that the fourth code attribute graph is a subgraph of the third code attribute graph.
[0152] The acquisition module 510, input module 520, and training module 530 can all be implemented in software or in hardware. For example, the implementation of the acquisition module 510 will be described below. Similarly, the implementation of the input module 520 and training module 530 can refer to the implementation of the acquisition module 510.
[0153] As an example of a software functional unit, module 510 may include code running on a computing instance. The computing instance may include at least one of a physical host (computing device), a virtual machine, or a container. Further, the aforementioned computing instance may be one or more. For example, module 510 may include code running on multiple hosts / virtual machines / containers. It should be noted that the multiple hosts / virtual machines / containers used to run the code may be distributed in the same region or in different regions. Further, the multiple hosts / virtual machines / containers used to run the code may be distributed in the same Availability Zone (AZ) or in different AZs, each AZ including one or more geographically proximate data centers. Typically, a region may include multiple AZs.
[0154] Similarly, multiple hosts / virtual machines / containers used to run this code can be distributed within the same VPC or across multiple VPCs. Typically, a VPC is set up within a region. Communication between two VPCs within the same region, as well as between VPCs in different regions, requires a communication gateway to be set up within each VPC to enable interconnection between VPCs.
[0155] As an example of a hardware functional unit, the acquisition module 510 may include at least one computing device, such as a server. Alternatively, the acquisition module 510 may also be a device implemented using an application-specific integrated circuit (ASIC) or a programmable logic device (PLD). The PLD may be implemented using a complex programmable logical device (CPLD), a field-programmable gate array (FPGA), generic array logic (GAL), or any combination thereof.
[0156] The multiple computing devices included in the acquisition module 510 can be distributed in the same region or in different regions. Similarly, the multiple computing devices included in the acquisition module 510 can be distributed in the same Availability Zone (AZ) or in different AZs. Likewise, the multiple computing devices included in the acquisition module 510 can be distributed in the same Virtual Private Cloud (VPC) or in multiple VPCs. These multiple computing devices can be any combination of computing devices such as servers, ASICs, PLDs, CPLDs, FPGAs, and GALs.
[0157] It should be noted that, in other embodiments, the acquisition module 510 can be used to execute any step in the method shown in FIG2, the input module 520 can be used to execute any step in the method shown in FIG2, and the training module 530 can be used to execute any step in the method shown in FIG2. The steps implemented by the acquisition module 510, the input module 520, and the training module 530 can be specified as needed. By implementing different steps in the method shown in FIG2 through the acquisition module 510, the input module 520, and the training module 530, all functions of the device 500 can be realized.
[0158] This application also provides a computing device 600. As shown in FIG6, the computing device 600 includes: a bus 602, a processor 604, a memory 606, and a communication interface 608. The processor 604, the memory 606, and the communication interface 608 communicate with each other via the bus 602. The computing device 600 may be a server or a terminal device. It should be understood that this application does not limit the number of processors and memories in the computing device 600.
[0159] Bus 602 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 illustration, only one line is used in Figure 6, but this does not imply that there is only one bus or one type of bus. Bus 602 can include pathways for transmitting information between various components of computing device 600 (e.g., memory 606, processor 604, communication interface 608).
[0160] Processor 604 may include any one or more processors such as a central processing unit (CPU), a graphics processing unit (GPU), a microprocessor (MP), or a digital signal processor (DSP).
[0161] Memory 606 may include volatile memory, such as random access memory (RAM). Memory 606 may also include non-volatile memory, such as read-only memory (ROM), flash memory, hard disk drive (HDD), or solid state drive (SSD).
[0162] The memory 606 stores executable program code, which the processor 604 executes to implement the functions of the aforementioned acquisition module 510, input module 520, and training module 530, thereby realizing the method shown in FIG2. That is, the memory 606 stores instructions for executing the method shown in FIG2.
[0163] The communication interface 608 uses transceiver modules, such as, but not limited to, network interface cards and transceivers, to enable communication between the computing device 600 and other devices or communication networks.
[0164] This application also provides a computing device cluster. The computing device cluster includes at least one computing device. The computing device can 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 can also be a terminal device such as a desktop computer, a laptop computer, or a smartphone.
[0165] As shown in Figure 7, the computing device cluster includes at least one computing device 600. The memory 606 of one or more computing devices 600 in the computing device cluster may store the same instructions for executing the method shown in Figure 2.
[0166] In some possible implementations, the memory 606 of one or more computing devices 600 in the computing device cluster may also store partial instructions for executing the method shown in FIG2. In other words, a combination of one or more computing devices 600 can jointly execute the instructions for executing the method shown in FIG2.
[0167] It should be noted that the memory 606 in different computing devices 600 within the computing device cluster can store different instructions, each used to execute a portion of the functions of the device 500. That is, the instructions stored in the memory 606 of different computing devices 600 can implement the functions of one or more modules among the acquisition module 510, input module 520, and training module 530.
[0168] In some possible implementations, one or more computing devices in a computing device cluster can be connected via a network. This network can be a wide area network (WAN) or a local area network (LAN), etc. Figure 8 illustrates one possible implementation. As shown in Figure 8, two computing devices 600A and 600B are connected via a network. Specifically, they are connected to the network through communication interfaces in each computing device. In this type of possible implementation, the memory 606 in computing device 600A stores instructions for executing the functions of the acquisition module 510. Simultaneously, the memory 606 in computing device 600B stores instructions for executing the functions of the input module 520 and the training module 530.
[0169] It should be understood that the functions of computing device 600A shown in Figure 8 can also be performed by multiple computing devices 600. Similarly, the functions of computing device 600B can also be performed by multiple computing devices 600.
[0170] This application embodiment also provides another computing device cluster. The connection relationship between the computing devices in this computing device cluster can be similarly referred to the connection method of the computing device cluster described in Figures 7 and 8. The difference is that the memory 606 of one or more computing devices 600 in this computing device cluster can store the same instructions for executing the method shown in Figure 2.
[0171] In some possible implementations, the memory 606 of one or more computing devices 600 in the computing device cluster may also store partial instructions for executing the method shown in FIG2. In other words, a combination of one or more computing devices 600 can jointly execute the instructions for executing the method shown in FIG2.
[0172] This application also provides a computer program product containing instructions. The computer program product may be a software or program product containing instructions, capable of running on a computing device or stored on any usable medium. When the computer program product is run on at least one computing device, it causes the at least one computing device to perform the method shown in FIG2.
[0173] This application also provides a computer-readable storage medium. The computer-readable storage medium can be any available medium that a computing device can store, or a host migration device such as a data center that includes one or more available media. The available medium can be a magnetic medium (e.g., floppy disk, hard disk, magnetic tape), an optical medium (e.g., DVD), or a semiconductor medium (e.g., solid-state drive). The computer-readable storage medium includes instructions that instruct the computing device to perform the method shown in FIG2.
[0174] Based on the above description, this application also provides a code recognition device 900. As shown in FIG9, the device 900 includes:
[0175] The acquisition module 910 is used to acquire the first code and the second code; wherein the length of the second code is less than or equal to the length of the first code;
[0176] The conversion module 920 is used to convert the first code into a first code attribute map and to convert the second code into a second code attribute map;
[0177] The recognition module 930 is used to input the first code attribute map and the second code attribute map into the code recognition model based on the graph neural network, so that the code recognition model outputs the recognition result; wherein, the recognition result includes the graph relationship between the second code attribute map and the first code attribute map;
[0178] The confirmation module 940 is used to confirm that the first code contains the second code when the graph relationship indicates that the second code attribute graph is a subgraph of the first code attribute graph.
[0179] In some embodiments, the first code attribute graph includes a first node, the second code attribute graph includes a second node, the first node is transformed from the first code element in the first code, the second node is transformed from the second code element in the second code, and the identification result also includes the first node relationship between the first node and the second node; the confirmation module 940 is further configured to: when the first node relationship indicates that the first node and the second node match, record the correspondence between the position of the first code element in the first code and the position of the second code element in the second code.
[0180] In some embodiments, the first code attribute graph further includes a third node, which is transformed from the third code element in the first code, and the identification result also includes a second node relationship between the first node and the third node; the confirmation module 940 is further configured to: when the first node relationship indicates that the first node and the second node match, and the second node relationship indicates that the third node and the second node match, identify the third node relationship between the neighboring nodes of the second node and the neighboring nodes of the first node, and identify the fourth node relationship between the neighboring nodes of the second node and the neighboring nodes of the third node; when the third node relationship indicates that the neighboring nodes of the second node and the neighboring nodes of the first node match, and the fourth node relationship indicates that the neighboring nodes of the second node and the neighboring nodes of the third node do not match, record the correspondence between the position of the first code element in the first code and the position of the second code element in the second code.
[0181] In some embodiments, the first code attribute graph further includes a third node, which is transformed from the third code element in the first code, and the recognition result also includes the second node relationship between the first node and the third node; the confirmation module 940 is further configured to: when the first node relationship indicates that the first node and the second node match, and the second node relationship indicates that the third node and the second node match, input the first node, the second node, and the third node into the node recognition model, so that the node recognition model inputs the node recognition result; when the node recognition result indicates that the first node and the second node match, and the third node and the second node do not match, record the correspondence between the position of the first code element in the first code and the position of the second code element in the second code.
[0182] In some embodiments, the recognition module 930 is further configured to: split the first code attribute graph into multiple neighborhood graphs and split the second code attribute graph into at least two neighborhood graphs; input the multiple neighborhood graphs and at least two neighborhood graphs into a code recognition model, so that the code recognition model outputs a recognition result; wherein, when each neighborhood graph in the at least two neighborhood graphs matches at least one neighborhood graph in the multiple neighborhood graphs, the graph relationship indicates that the second code attribute graph is a subgraph of the first code attribute graph.
[0183] In some embodiments, the plurality of neighborhood graphs include a first neighborhood graph, and at least two neighborhood graphs include a second neighborhood graph; the confirmation module 940 is further configured to: when the first neighborhood graph and the second neighborhood graph match, confirm that the nodes in the first neighborhood graph and the nodes in the second neighborhood graph match.
[0184] The acquisition module 910, conversion module 920, identification module 930, and confirmation module 940 can all be implemented in software or in hardware. For example, the implementation of the acquisition module 910 will be described below. Similarly, the implementation of the conversion module 920, identification module 930, and confirmation module 940 can refer to the implementation of the acquisition module 910.
[0185] As an example of a software functional unit, module 910 may include code running on a computing instance. The computing instance may include at least one of a physical host (computing device), a virtual machine, or a container. Further, the aforementioned computing instance may be one or more. For example, module 910 may include code running on multiple hosts / virtual machines / containers. It should be noted that the multiple hosts / virtual machines / containers used to run the code may be distributed in the same region or in different regions. Further, the multiple hosts / virtual machines / containers used to run the code may be distributed in the same Availability Zone (AZ) or in different AZs, each AZ including one or more geographically proximate data centers. Typically, a region may include multiple AZs.
[0186] Similarly, multiple hosts / virtual machines / containers used to run this code can be distributed within the same Virtual Private Cloud (VPC) or across multiple VPCs. Typically, a VPC is set up within a region. Communication between two VPCs within the same region, as well as between VPCs in different regions, requires a communication gateway to be set up within each VPC to enable interconnection between VPCs.
[0187] As an example of a hardware functional unit, the acquisition module 910 may include at least one computing device, such as a server. Alternatively, the acquisition module 910 may also be a device implemented using an ASIC or a PLD. The aforementioned PLD may be implemented using a CPLD, FPGA, GAL, or any combination thereof.
[0188] The multiple computing devices included in the acquisition module 910 can be distributed in the same region or in different regions. Similarly, the multiple computing devices included in the acquisition module 910 can be distributed in the same Availability Zone (AZ) or in different AZs. Likewise, the multiple computing devices included in the acquisition module 910 can be distributed in the same Virtual Private Cloud (VPC) or in multiple VPCs. These multiple computing devices can be any combination of computing devices such as servers, ASICs, PLDs, CPLDs, FPGAs, and GALs.
[0189] It should be noted that, in other embodiments, the acquisition module 910 can be used to execute any step in the method shown in FIG4, the conversion module 920 can be used to execute any step in the method shown in FIG4, the identification module 930 can be used to execute any step in the method shown in FIG4, and the confirmation module 940 can be used to execute any step in the method shown in FIG4. The steps implemented by the acquisition module 910, conversion module 920, identification module 930, and confirmation module 940 can be specified as needed. By implementing different steps in the method shown in FIG4 through the acquisition module 910, conversion module 920, identification module 930, and confirmation module 940, all functions of the device 900 can be realized.
[0190] This application also provides a computing device 1000. As shown in FIG10, the computing device 1000 includes: a bus 1002, a processor 1004, a memory 1006, and a communication interface 1008. The processor 1004, the memory 1006, and the communication interface 1008 communicate with each other 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 memories in the computing device 1000.
[0191] Bus 1002 can be a PCI bus or an EISA bus, etc. Buses can be divided into address buses, data buses, control buses, etc. For ease of illustration, only one line is used in Figure 10, but this does not mean that there is only one bus or one type of bus. Bus 1002 can include a path for transmitting information between various components of computing device 1000 (e.g., memory 1006, processor 1004, communication interface 1008).
[0192] Processor 1004 may include any one or more processors such as CPU, GPU, MP or digital signal processor (DSP).
[0193] The memory 1006 may include volatile memory, such as RAM. The memory 1006 may also include non-volatile memory, such as ROM, flash memory, HDD, or SSD.
[0194] The memory 1006 stores executable program code, and the processor 1004 executes this executable program code to implement the functions of the aforementioned acquisition module 910, conversion module 920, identification module 930, and confirmation module 940, thereby realizing the method shown in FIG4. That is, the memory 1006 stores instructions for executing the method shown in FIG4.
[0195] The communication interface 1008 uses transceiver modules such as, but not limited to, network interface cards and transceivers to enable communication between the computing device 1000 and other devices or communication networks.
[0196] This application also provides a computing device cluster. The computing device cluster includes at least one computing device. The computing device can 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 can also be a terminal device such as a desktop computer, a laptop computer, or a smartphone.
[0197] As shown in Figure 11, the computing device cluster includes at least one computing device 1000. The memory 1006 of one or more computing devices 1000 in the computing device cluster may store the same instructions for executing the method shown in Figure 4.
[0198] 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 method shown in FIG4. In other words, a combination of one or more computing devices 1000 can jointly execute the instructions for executing the method shown in FIG4.
[0199] It should be noted that the memory 1006 in different computing devices 1000 within the computing device cluster can store different instructions, each used to execute a portion of the functions of the device 1000. 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 acquisition module 910, conversion module 920, identification module 930, and confirmation module 940.
[0200] In some possible implementations, one or more computing devices in a computing device cluster can be connected via a network. This network can be a wide area network (WAN) or a local area network (LAN), etc. Figure 12 illustrates one possible implementation. As shown in Figure 12, two computing devices 1000A and 1000B are connected via a network. Specifically, they are connected to the network through communication interfaces in each computing device. In this type of possible implementation, the memory 1006 in computing device 1000A stores instructions for executing the functions of the acquisition module 910 and the conversion module 920. Simultaneously, the memory 1006 in computing device 1000B stores instructions for the functions of the identification module 930 and the confirmation module 940.
[0201] It should be understood that the functions of computing device 1000A shown in Figure 12 can also be performed by multiple computing devices 1000. Similarly, the functions of computing device 1000B can also be performed by multiple computing devices 1000.
[0202] This application also provides another computing device cluster. The connection relationship between the computing devices in this computing device cluster can be similar to the connection method of the computing device clusters described in Figures 11 and 12. The difference is that the memory 1006 of one or more computing devices 1000 in this computing device cluster can store the same instructions for executing the method shown in Figure 4.
[0203] 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 method shown in FIG4. In other words, a combination of one or more computing devices 1000 can jointly execute the instructions for executing the method shown in FIG4.
[0204] This application also provides a computer program product containing instructions. The computer program product may be a software or program product containing instructions, capable of running on a computing device or stored on any usable medium. When the computer program product is run on at least one computing device, it causes the at least one computing device to perform the method shown in FIG4.
[0205] This application also provides a computer-readable storage medium. The computer-readable storage medium can be any available medium that a computing device can store, or a host migration device such as a data center that includes one or more available media. The available medium can be a magnetic medium (e.g., floppy disk, hard disk, magnetic tape), an optical medium (e.g., DVD), or a semiconductor medium (e.g., solid-state drive). The computer-readable storage medium includes instructions that instruct the computing device to perform the method shown in FIG4.
[0206] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of this application, and are not intended to limit them. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the foregoing embodiments, or make equivalent substitutions for some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the protection scope of the technical solutions of the embodiments of this application.
Claims
1. A code recognition method, characterized in that, The method includes: Obtain a first code and a second code; wherein the length of the second code is less than or equal to the length of the first code; Convert the first code into a first code attribute map, and convert the second code into a second code attribute map; The first code attribute map and the second code attribute map are input into a code recognition model based on a graph neural network, so that the code recognition model outputs a recognition result; wherein, the recognition result includes the graph relationship between the second code attribute map and the first code attribute map; When the graph relationship indicates that the second code attribute graph is a subgraph of the first code attribute graph, it is confirmed that the first code contains the second code.
2. The method according to claim 1, characterized in that, The first code attribute graph includes a first node, and the second code attribute graph includes a second node. The first node is transformed from the first code element in the first code, and the second node is transformed from the second code element in the second code. The recognition result also includes the first node relationship between the first node and the second node. The method further includes: when the first node relationship indicates that the first node and the second node match, recording the correspondence between the position of the first code element in the first code and the position of the second code element in the second code.
3. The method according to claim 2, characterized in that, The first code attribute graph also includes a third node, which is transformed from the third code element in the first code, and the recognition result also includes a second node relationship between the first node and the third node; When the first node relationship indicates that the first node and the second node match, the correspondence between the position of the first code element in the first code and the position of the second code element in the second code is recorded, including: When the first node relationship indicates that the first node and the second node match, and the second node relationship indicates that the third node and the second node match, identify the third node relationship between the neighboring nodes of the second node and the neighboring nodes of the first node, and identify the fourth node relationship between the neighboring nodes of the second node and the neighboring nodes of the third node. When the third node relationship indicates that the neighboring node of the second node matches the neighboring node of the first node, and the fourth node relationship indicates that the neighboring node of the second node does not match the neighboring node of the third node, the correspondence between the position of the first code element in the first code and the position of the second code element in the second code is recorded.
4. The method according to claim 2, characterized in that, The first code attribute graph also includes a third node, which is transformed from the third code element in the first code, and the recognition result also includes a second node relationship between the first node and the third node; When the first node relationship indicates that the first node and the second node match, the correspondence between the position of the first code element in the first code and the position of the second code element in the second code is recorded, including: When the first node relationship indicates that the first node and the second node match, and the second node relationship indicates that the third node and the second node match, the first node, the second node, and the third node are input into the node recognition model, so that the node recognition model inputs the node recognition result; When the node identification result indicates that the first node and the second node match, and the third node and the second node do not match, the correspondence between the position of the first code element in the first code and the position of the second code element in the second code is recorded.
5. The method according to claim 1, characterized in that, The step of inputting the first code attribute map and the second code attribute map into the code recognition model includes: The first code attribute graph is split into multiple neighborhood graphs, and the second code attribute graph is split into at least two neighborhood graphs; The plurality of neighborhood graphs and the at least two neighborhood graphs are input into the code recognition model, so that the code recognition model outputs the recognition result; Wherein, when each of the at least two neighborhood graphs matches at least one neighborhood graph in the plurality of neighborhood graphs, the graph relationship indicates that the second code attribute graph is a subgraph of the first code attribute graph.
6. The method according to claim 5, characterized in that, The plurality of neighborhood graphs includes a first neighborhood graph, and the at least two neighborhood graphs include a second neighborhood graph; The method further includes: when the first neighborhood graph and the second neighborhood graph match, confirming that the nodes in the first neighborhood graph and the nodes in the second neighborhood graph match.
7. A method for training a code recognition model, characterized in that, The method includes: Obtain training graph pairs; wherein, the training graph pairs include a third code attribute graph and a fourth code attribute graph, and the training graph pairs have a first label, the first label being used to indicate that the fourth code attribute graph is a subgraph of the third code attribute graph; The training graph pairs are input into a code recognition model based on a graph neural network, so that the code recognition model outputs the recognition result of the training graph pairs; wherein, the recognition result includes the graph relationship between the fourth code attribute graph and the third code attribute graph; When the graph relationship between the fourth code attribute graph and the third code attribute graph in the recognition result is inconsistent with the first label, the parameters of the code recognition model are updated so that the graph relationship between the fourth code attribute graph and the third code attribute graph in the recognition result of the training graph pair output by the code recognition model again is consistent with the first label.
8. The method according to claim 7, characterized in that, The third code attribute graph includes a fourth node, the fourth code attribute graph includes a fifth node, the training graph pair has a second label, the second label is used to indicate that the fourth node and the fifth node match, and the recognition result also includes the node relationship between the fourth node and the fifth node; The method further includes: when the node relationship between the fourth node and the fifth node in the recognition result is inconsistent with the second label, updating the parameters of the code recognition model so that the node relationship between the fourth node and the fifth node in the recognition result of the training graph pair output by the code recognition model again is consistent with the second label.
9. The method according to claim 7 or 8, characterized in that, The step of inputting the training image pair into the code recognition model, so that the code recognition model outputs the recognition result of the training image pair, includes: The third code attribute graph is split into multiple neighborhood graphs, and the fourth code attribute graph is split into at least two neighborhood graphs; The plurality of neighborhood graphs and the at least two neighborhood graphs are input into the code recognition model, so that the code recognition model outputs the recognition result; Wherein, when each of the at least two neighborhood graphs matches at least one neighborhood graph in the plurality of neighborhood graphs, the graph relationship indicates that the fourth code attribute graph is a subgraph of the third code attribute graph.
10. A code recognition device, characterized in that, The device includes: An acquisition module is used to acquire a first code and a second code; wherein the length of the second code is less than or equal to the length of the first code; A conversion module is used to convert the first code into a first code attribute map and to convert the second code into a second code attribute map; The recognition module is used to input the first code attribute map and the second code attribute map into a code recognition model based on a graph neural network, so that the code recognition model outputs a recognition result; wherein, the recognition result includes the graph relationship between the second code attribute map and the first code attribute map; The confirmation module is used to confirm that the first code contains the second code when the graph relationship indicates that the second code attribute graph is a subgraph of the first code attribute graph.
11. A code recognition model training device, characterized in that, The device includes: An acquisition module is used to acquire training graph pairs; wherein, the training graph pair includes a third code attribute graph and a fourth code attribute graph, and the training graph pair has a first label, the first label being used to indicate that the fourth code attribute graph is a subgraph of the third code attribute graph; An input module is used to input the training graph pair into a code recognition model based on a graph neural network, so that the code recognition model outputs the recognition result of the training graph pair; wherein, the recognition result includes the graph relationship between the fourth code attribute graph and the third code attribute graph; The training module is used to update the parameters of the code recognition model when the graph relationship between the fourth code attribute map and the third code attribute map in the recognition result is inconsistent with the first label, so that the graph relationship between the fourth code attribute map and the third code attribute map in the recognition result of the training graph pair output by the code recognition model again is consistent with the first label.
12. A computing device cluster, characterized in that, It 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 cluster of computing devices to perform the method as described in any one of claims 1-6, or the method as described in any one of claims 7-9.
13. A computer-readable storage medium, characterized in that, It includes computer program instructions, which, when executed by a cluster of computing devices, perform the method as described in any one of claims 1-6, or the method as described in any one of claims 7-9.
14. A computer program product containing instructions, characterized in that, When the instructions are executed by a cluster of computer devices, the cluster of computer devices causes the cluster of computer devices to perform the method as described in any one of claims 1-6, or the method as described in any one of claims 7-9.