Method and device for representing application programming interface

By identifying APIs in the syntax tree and using the call stack to train neural network models, obtaining more accurate API representation vectors, the challenge of API similarity analysis in cross-platform code migration is solved, and a more efficient code migration process is achieved.

CN120407015APending Publication Date: 2025-08-01HUAWEI TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410134834.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-01-30
Publication Date
2025-08-01

AI Technical Summary

Technical Problem

How to learn to obtain a more accurate distributed representation of application programming interfaces (APIs) in the prior art is still an urgent problem, especially in cross-platform or cross-environment code migration scenarios, there are challenges in API similarity analysis and recommendation.

Method used

By obtaining the syntax tree of the source code file, identifying the associated API, and using the depth-first search and subtree pattern matching algorithm to extract the call stack, train the neural network model to obtain more accurate API representation vectors, and improve the correlation between APIs.

Benefits of technology

It improves the accuracy of API representation vectors, so that API recommendations and code migration can be performed more accurately during the code migration process between different platforms, and improves the efficiency and accuracy of code migration.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120407015A_ABST
    Figure CN120407015A_ABST
Patent Text Reader

Abstract

The invention discloses an application programming interface representation method and device, in the method, a computing node can obtain a syntax tree ST corresponding to a source code file, the ST comprises a plurality of nodes and attribute information of the nodes, and each node is at most associated with one application programming interface API; identifying m first APIs associated with the ST, wherein m is an integer greater than or equal to 1; obtaining a call stack according to the attribute information of the plurality of nodes, wherein the call stack indicates a call relationship existing among the m first APIs; a neural network model is trained according to the m first APIs and the call stack, model parameters of the trained neural network model comprise a first representation vector set, and the first representation vector set comprises first representation vectors of part of or all the first APIs in the m first APIs. According to the method, the more accurate representation vector of the API can be obtained.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of computer technologies, and particularly to a method and apparatus for representing application programming interfaces. Background Art

[0002] Code migration is the process of transferring an existing software system or application program from one platform or environment to another. Code migration can help developers transfer an existing code library to a target platform, thereby accelerating the development and deployment speed of application programs. Code migration problems widely exist in the code development process, including cross-platform code migration, cross-version code migration, cross-programming language code migration, etc.

[0003] To quickly implement code migration, a solution is to learn the distributed representation of application programming interfaces (APIs). This distributed representation of APIs, also known as embedding representation, carries semantic information of the APIs. In scenarios such as cross-platform or cross-environment code migration, the similarity between APIs of different platforms can be analyzed through the distributed representation of APIs, and API recommendation / migration can be performed based on the similarity.

[0004] Currently, how to learn a more accurate distributed representation of APIs remains an important problem that urgently needs to be solved. Summary of the Invention

[0005] This application provides a method for representing application programming interfaces. This method can be applied to a computing node, or a component of a computing node, or can also be software. The embodiments of this application do not make any limitations in this regard.

[0006] In a first aspect, this application provides a method for representing application programming interfaces. In this method, a computing node can obtain a syntax tree ST corresponding to a source code file. The ST includes multiple nodes and attribute information of the multiple nodes. Each node is associated with at most one application programming interface API; identify m first APIs associated with the ST, where m is an integer greater than or equal to 1; obtain a call stack according to the attribute information of the multiple nodes, and the call stack indicates the call relationships existing between the m first APIs; train a neural network model according to the m first APIs and the call stack. Among them, the model parameters of the trained neural network model include a first representation vector set, and the first representation vector set includes first representation vectors of some or all of the m first APIs.

[0007] Through the above method, the model parameters of the neural network model can be trained in combination with the call stack, improving the correlation between different APIs, so that the representation vectors of each obtained API are more accurate. In this method, multiple APIs without semantic relationships in the syntax tree can be converted into a call stack with semantic relationships, so that the semantic information of the representation vectors of each obtained API is more accurate.

[0008] In a possible implementation, the attribute information of the multiple nodes includes the parameters of the API associated with each node. The obtaining of the call stack according to the attribute information of the multiple nodes includes: obtaining the call stack according to the parameters of the APIs respectively associated with the multiple nodes.

[0009] In a possible implementation, the parameters of the API associated with each node include the input parameters of the API. The m first APIs include a second API. The call stack includes the input parameter call stack of the second API. The obtaining of the call stack according to the parameters of the APIs associated with the multiple nodes includes: for the second API, if in the ST, the input parameter of the second API is a child node of the second API, traversing the multiple nodes by using a post-order traversal method to obtain the input parameter call stack of the second API.

[0010] In a possible implementation, the parameters of the API associated with each node include the output parameters of the API. The m first APIs include a second API. The call stack includes the output parameter call stack of the second API. The obtaining of the call stack according to the parameters of the APIs associated with the multiple nodes includes: for the second API among the m first APIs, if in the ST, the output parameter of the second API is a child node of the second API, traversing the multiple nodes by using a pre-order traversal method to obtain the output parameter call stack of the second API.

[0011] In a possible implementation, the training of the neural network model according to the m first APIs and the call stack includes: constructing a first neural network model with n third APIs among the m first APIs as the corpus, where the model parameters of the first neural network model include the second representation vectors of the n third APIs; selecting an input API and an output API from the n third APIs according to the call stack, and training the first neural network model according to the input API and the output API to obtain a second neural network model, where the model parameters of the second neural network model include the first representation vectors of the n third APIs.

[0012] In a possible implementation manner, the recognition of the m first APIs associated with the ST includes: scanning the ST through a depth-first search algorithm and a subtree pattern matching algorithm to recognize the m first APIs associated with the ST.

[0013] In a second aspect, the present application provides a code migration method, which is applied to a computing node, or a component of a computing node, or can also be software, and the embodiments of the present application do not make any limitations in this regard. The computing node includes representation vectors of multiple APIs, and the multiple API representation vectors are obtained based on a first call stack and a neural network model. The first call stack indicates the call relationships existing between the multiple APIs. The method may include: obtaining a first code file used by a first platform; extracting m first APIs based on the first code file; obtaining the representation vectors of the m first APIs from the multiple API representation vectors; determining the representation vectors of n second APIs that satisfy a similarity condition with the representation vectors of the m first APIs; and recommending the code of the m first APIs to a second platform that uses the n second APIs for code migration between the first platform and the second platform.

[0014] In a third aspect, the present application provides a representation device for application programming interfaces, including: an acquisition unit, configured to acquire a syntax tree ST corresponding to a source code file, where the ST includes multiple nodes and attribute information of the multiple nodes, and each node is associated with at most one application programming interface API; an identification unit, configured to identify m first APIs associated with the ST, where m is an integer greater than or equal to 1; the acquisition unit is further configured to obtain a call stack according to the attribute information of the multiple nodes, and the call stack indicates the call relationships existing between the m first APIs; and a training unit, configured to train a neural network model according to the m first APIs and the call stack. Among them, the model parameters of the trained neural network model include a first representation vector set, and the first representation vector set includes the first representation vectors of some or all of the m first APIs.

[0015] In a possible implementation manner, the attribute information of the multiple nodes includes the parameters of the API associated with each node, and the obtaining of the call stack according to the attribute information of the multiple nodes includes: obtaining the call stack according to the parameters of the APIs respectively associated with the multiple nodes.

[0016] In a possible implementation, the parameters of the API associated with each node include the input parameters of the API. Among the m first APIs, there is a second API. The call stack includes the call stack of the input parameters of the second API. Obtaining the call stack according to the parameters of the APIs associated with the multiple nodes includes: for the second API, if in the ST, the input parameter of the second API is a child node of the second API, traverse the multiple nodes using a post-order traversal method to obtain the call stack of the input parameters of the second API.

[0017] In a possible implementation, the parameters of the API associated with each node include the output parameters of the API. Among the m first APIs, there is a second API. The call stack includes the call stack of the output parameters of the second API. Obtaining the call stack according to the parameters of the APIs associated with the multiple nodes includes: for the second API among the m first APIs, if in the ST, the output parameter of the second API is a child node of the second API, traverse the multiple nodes using a pre-order traversal method to obtain the call stack of the output parameters of the second API.

[0018] In a possible implementation, training the neural network model according to the m first APIs and the call stack includes: constructing a first neural network model with n third APIs among the m first APIs as the corpus, where the model parameters of the first neural network model include the second representation vectors of the n third APIs; selecting an input API and an output API from the n third APIs according to the call stack, and training the first neural network model according to the input API and the output API to obtain a second neural network model, where the model parameters of the second neural network model include the first representation vectors of the n third APIs.

[0019] In a possible implementation, identifying the m first APIs associated with the ST includes: scanning the ST through a depth-first search algorithm and a subtree pattern matching algorithm to identify the m first APIs associated with the ST.

[0020] Fourth aspect, the present application provides a code migration device, which is applied to a computing node. The computing node includes representation vectors of multiple APIs, and the representation vectors of the multiple APIs are obtained by training based on a first call stack and a neural network model. The first call stack indicates the call relationships existing among the multiple APIs. The device includes: an acquisition unit, configured to acquire a first code file used by a first platform; an extraction unit, configured to extract m first APIs based on the first code file; the acquisition unit is further configured to acquire the representation vectors of the m first APIs from the representation vectors of the multiple APIs; a determination unit, configured to determine the representation vectors of n second APIs that satisfy a similarity condition with the representation vectors of the m first APIs; and a recommendation unit, configured to recommend the code of the m first APIs to a second platform that uses the n second APIs, so as to perform code migration between the first platform and the second platform.

[0021] Fifth aspect, the present application provides a computing device, including at least one processor and an interface circuit. The interface circuit is configured to provide data or code instructions for the at least one processor, and the at least one processor is configured to implement the method as described in the first aspect and any possible design of the first aspect, or implement the method as described in the second aspect and any possible design of the second aspect through logic circuits or by executing code instructions.

[0022] Sixth aspect, the present application provides a computer-readable storage medium. The computer-readable medium stores program code, and when the program code runs on a computer, it causes the computer to execute the method as described in the first aspect and any possible design of the first aspect, or when the program code runs on a computer, it causes the computer to execute the method as described in the second aspect and any possible design of the second aspect.

[0023] Seventh aspect, the present application provides a computer program product. When the computer program product runs on a computer, it causes the computer to execute the method as described in the first aspect and any possible design of the first aspect, or execute the method as described in the second aspect and any possible design of the second aspect.

[0024] Eighth aspect, the present application provides a computing chip, and the computing chip may include the computing device provided in the first aspect.

[0025] Based on the implementations provided in the above aspects, the embodiments of the present application can be further combined to provide more implementations. Description of the Drawings

[0026] Figure 1 Shows a schematic diagram of the compilation principle of a syntax tree;

[0027] Figure 2 Shows a schematic structural diagram of a continuous call stack;

[0028] Figure 3 Shows a schematic structural diagram of a discontinuous call stack;

[0029] Figure 4 Shows a schematic flowchart of the representation method of the API in the embodiments of the present application;

[0030] Figure 5A Shows a schematic diagram of the principle of a depth - first search algorithm;

[0031] Figure 5B Shows a schematic diagram of a subtree pattern matching algorithm;

[0032] Figure 6 Shows the extraction method of the call stack;

[0033] Figure 7 Shows a schematic diagram of a neural network model;

[0034] Figure 8 Shows a schematic flowchart of obtaining an API representation vector in a code migration scenario;

[0035] Figure 9 Shows a schematic structural diagram of a computing device;

[0036] Figure 10 Shows a schematic structural diagram of another computing device. Detailed implementation manners

[0037] For ease of understanding, the terms or technologies involved in the present application are introduced below:

[0038] 1. Syntax tree:

[0039] Also called an abstract syntax tree (AST), it is a data structure used in compilers and interpreters to represent the syntax structure of a program. It can convert the program source code into a tree - like structure composed of nodes, and each node represents a syntax structure in the source code.

[0040] Such as Figure 1As shown in the figure, the underlying principle of the syntax tree is that after preprocessing the source file, during the compilation stage, through lexical analysis and syntactic analysis of the source code, a tree-like structure composed of nodes is constructed. The lexical analyzer decomposes the source code into individual lexical units (tokens), such as keywords, identifiers, operators, etc. The syntax analyzer then combines the lexical units into syntactic structures, such as functions, expressions, statements, etc. Finally, the syntax analyzer converts the source code into a tree-like structure composed of nodes, where each node represents a syntactic structure.

[0041] A syntax tree usually consists of a root node and several child nodes. Each node contains some attributes and child nodes. The attributes are used to represent the type and content of the node, and the child nodes represent the sub-syntactic structures contained in the node. For example, in a simple assignment statement, the root node of the syntax tree can represent the entire statement, while the child nodes represent the variable and the assignment operation respectively.

[0042] The advantage of the syntax tree is that it can represent the structured information of the source code in an easily processable form. In compilers and interpreters, syntax trees are often used for operations such as code optimization, error checking, and code generation. At the same time, the syntax tree is also the basis for many program analysis tools and programming assistance tools, such as code completion, automatic refactoring, and code analysis tools.

[0043] 2. Application Programming Interface (API) sequence:

[0044] Traversing or scanning the syntax tree can obtain the API sequence. The API sequence is a string sequence that includes multiple APIs, and there is no clear relationship between the APIs within the sequence.

[0045] 3. Call stack:

[0046] It can be abbreviated as "the stack", and can also be called the execution stack, control stack, run-time stack, machine stack, etc. It is a stack in computer science that stores information about the running subroutines. Sometimes it is only called "the stack", but the stack does not necessarily only store subroutine messages. Almost all computer programs rely on the call stack, and high-level languages generally hide the details of the call stack in the background.

[0047] The main function of the call stack is to store the return address. In addition, the call stack is also used to store the following content:

[0048] (1) Local variables: The variables of a subroutine can be stored on the call stack, so that variables can be separated between different subroutines.

[0049] (2) Parameter passing: If the registers are not sufficient to hold the parameters of a subroutine, the parameters can be stored on the call stack.

[0050] (3) Environment passing: Some languages (such as Pascal and Ada) support "nested subroutines", that is, local variables of the main program can be used in subroutines. These variables can be passed into the subroutine through the call stack.

[0051] 4. Call relationship:

[0052] The call relationship is used to indicate the relationship between two APIs. Among them, in the two APIs with a call relationship, the output parameters of the called API are the input parameters of the other API.

[0053] 5. Continuous call stack and discontinuous call stack:

[0054] The APIs in the call stack have a dependency relationship (such as a call relationship) and also a semantic relationship. The call stack is not necessarily the parent-child nodes in the syntax tree.

[0055] (1) When the APIs with a call relationship in the code appear continuously and are not separated by the calls of other APIs, the APIs in the API sequence obtained by traversing the corresponding syntax tree have a continuous call relationship.

[0056] The following shows a set of pseudocode and its code meaning:

[0057] main(img): main represents the function name; img is the input parameter, the image path; the subsequent code is the function body;

[0058] mat = decode(img): decode represents the image decoding API; mat is the matrix returned by the decoding API, storing the content of the image;

[0059] mat = crop(mat): crop represents the image cropping API;

[0060] mat = resize(mat): resize represents the image scaling API;

[0061] mat = normalize(mat): normalize represents normalizing the pixel values of the image;

[0062] mat = hwc2chw(mat): hwc2chw represents converting the image storage format from HWC to CHW (H represents height, W represents width, C represents channels);

[0063] return mat: "return" indicates that the function returns;

[0064] Figure 2 The tree structure from main to each node of the above pseudocode is an example of a syntax tree, and the arrows represent the call relationships. Traversing the syntax tree (such as post-order traversal) yields the API sequence [decode, crop, resize, normalize, hwc2chw]. There is a call relationship directly between two consecutive APIs in this sequence, meaning the call stack is consecutive. Two consecutive APIs in this call stack are sibling nodes in the syntax tree, not parent-child nodes.

[0065] (2) When APIs with a call relationship in the code do not appear consecutively and are separated by calls to other APIs, then the APIs in the API sequence obtained by traversing the corresponding syntax tree do not have a consecutive call relationship.

[0066] The following shows another set of pseudocode and its code meanings:

[0067] main(img): "main" represents the function name; img is the input parameter, the path of the image; the subsequent code is the function body;

[0068] mat = decode(img): "decode" represents the image decoding API; mat is the matrix returned by the decoding API, storing the content of the image;

[0069] mat = crop(mat): "crop" represents the image cropping API;

[0070] xxx: Any other API call;

[0071] xxx: Any other API call;

[0072] mat = resize(mat): "resize" represents the image scaling API;

[0073] xxx: Any other API call;

[0074] xxx: Any other API call;

[0075] mat = normalize(mat): "normalize" represents normalizing the pixel values of the image;

[0076] mat = hwc2chw(mat): "hwc2chw" represents converting the image storage format from HWC to CHW;

[0077] return mat: "return" indicates that the function returns;

[0078] Figure 3 The tree structure from the main of the above pseudocode to each node is an example of a syntax tree, and the arrows represent the call relationships. Traversing the syntax tree (such as post-order traversal) yields an API sequence [decode, crop, xxx, xxx, resize, xxx, xxx, normalize, hwc2chw], where not all consecutive pairs of APIs have direct call relationships, such as crop and xxx, i.e., the call stack is not continuous.

[0079] 6. Input and output parameters:

[0080] Input parameters refer to the parameters that need to be passed in a function or method.

[0081] Output parameters refer to the values returned from the running result of a function or method.

[0082] Input parameters are required (e.g., when data needs to be passed into a function or method). In this case, the direction of passing is from the outside to the inside, that is, data is passed from the caller into the function. Output parameters may not be required, and the direction of passing is from the inside to the outside.

[0083] 7. API distributed representation:

[0084] Or it can be called API distributed representation.

[0085] Word embedding or word distributed representation is a prerequisite for almost all natural language processing applications. Similarly, API distributed representation is a prerequisite for AI+code applications, including code detection, code migration, code understanding, code completion, code generation, etc. With an accurate API distributed representation, neural network models can accurately perform code-related tasks.

[0086] 8. Depth-First-Search (DFS) algorithm:

[0087] It is an algorithm used to traverse or search a tree or graph. This algorithm will search the branches of the tree as deeply as possible. When all the edges of node v have been explored, the search will backtrack to the starting node of the edge where node v was discovered. This process continues until all nodes reachable from the source node have been discovered.

[0088] 9. Subtree pattern matching algorithm:

[0089] Each node in the syntax tree has some attributes, such as the API corresponding to the node and the source of the API, etc. If several nodes meet certain rules, the corresponding APIs can be extracted.

[0090] The embodiments of the present application provide a method and a device for representing an application programming interface, which are used to obtain a distributed representation vector of an API based on a call stack, so as to perform AI+code applications by using the distributed representation vector of the API, including but not limited to code detection, code migration, code understanding, code completion, code generation, etc. Among them, the method and the device are based on the same technical concept. Since the principles of the method and the device for solving problems are similar, the implementation of the device and the method can be referred to each other, and the repeated parts will not be described again. Moreover, in each embodiment of the present application, if there is no special description and logical conflict, the terms and / or descriptions among the embodiments are consistent and can be referred to each other, and the technical features in different embodiments can be combined to form new embodiments according to their internal logical relationships.

[0091] It should be noted that in the embodiments of the present application, "at least one" means one or more, and "a plurality" means two or more. "And / or" describes the association relationship of associated objects, indicating that there can be three relationships. For example, A and / or B can represent: A exists alone, A and B exist simultaneously, and B exists alone, where A and B can be singular or plural. The character " / " generally represents an "or" relationship between the associated objects before and after. "At least one (item)" or its similar expression refers to any combination of these items, including any combination of single item (item) or plural items (items). For example, at least one (item) of a, b, or c can represent: a, b, c, a and b, a and c, b and c, or a, b, and c, where a, b, and c can be single or multiple.

[0092] Moreover, unless otherwise specified, the ordinal numbers such as "first" and "second" mentioned in the embodiments of the present application are used to distinguish multiple objects, and are not used to limit the priority or importance of multiple objects.

[0093] The following is a detailed introduction in combination with the drawings and embodiments.

[0094] Figure 4 A flowchart of the method for representing an API according to an embodiment of the present application is shown. Among them, this method can be implemented by a computing node, and the computing node can be any device with computing capabilities. The product form of this device is not limited in the embodiments of the present application.

[0095] As Figure 4 shown, the method may include the following steps:

[0096] S410: The computing node obtains a syntax tree ST corresponding to the source code file.

[0097] In the embodiments of the present application, the source code file may be the source code file of a platform, an environment, an application program, etc. The source code file is an uncompiled text file written according to a certain programming language specification, including a series of readable computer language instructions.

[0098] Exemplarily, taking the source code file of a platform as an example, the source code file may include the following content:

[0099]

[0100]

[0101] It can be seen from the above content that the source code file of the platform may indicate the dependent library. The dependent library is an external module or library required by the source program during runtime, and can also be understood as a toolkit used by the source program to run. The source code file of the platform may indicate the parameters of the operations involved. The embodiments of the present application do not make specific limitations on the content included in the source code file.

[0102] When implementing S410 above, the computing node may read the required source code file from the local storage medium or the storage medium of other devices as needed, and associate the source code file with the corresponding dependent library. The embodiments of the present application do not limit the acquisition method of the source code file.

[0103] A compilation tool (or compiler) may be set on the computing node. Using compilation technology, the source code file can be compiled to generate a corresponding syntax tree. Exemplarily, the compilation tool may be a low level virtual machine (LLVM), Clang, etc. The embodiments of the present application do not limit the compilation tool used.

[0104] This syntax tree is the abstract syntax tree introduced above, and is simply referred to as the syntax tree hereinafter. As Figure 1 shown, the nodes of the syntax tree are represented by circles "○". The syntax tree may include multiple nodes, and each node represents a structure in the source code. At the same time, the syntax tree may also include the attribute information of multiple nodes. Among them, the attribute information of each node is hidden in the structure of the tree and is not presented in the form of a node. In specific implementation, each node of the syntax tree is associated with at most one API, that is, one node of the syntax tree may be associated with one API, or two or more nodes of the syntax tree may be associated with one API. The embodiments of the present application do not make limitations on this.

[0105] S420: The computing node identifies m first APIs associated with the syntax tree, where m is an integer greater than or equal to 1.

[0106] In the embodiments of the present application, the computing node can scan the syntax tree through a depth-first search algorithm and a subtree pattern matching algorithm to identify m first APIs associated with the syntax tree.

[0107] As Figure 5A shown, different nodes of the syntax tree are numbered. Starting from the source node (the node numbered 1), the depth-first search algorithm is used to search the tree branches as deeply as possible. For example, from the node numbered 1, search to the node numbered 2, then to the node numbered 3, and then to the node numbered 4. When all the edges where the node numbered 4 is located have been explored, the search will backtrack to the starting node of the edge where the node numbered 4 is found, such as the node numbered 3, and search the tree branches as deeply as possible again from the node numbered 3, such as searching to the node numbered 5. When all the edges where the node numbered 5 is located have been explored, the search will backtrack to the starting node of the edge where the node numbered 5 is found, such as the node numbered 3. When all the edges where the node numbered 3 is located have been explored, the search will backtrack to the starting node of the edge where the node numbered 3 is found, such as the node numbered 2, and search the tree branches as deeply as possible again from the node numbered 2, such as searching to the node numbered 6. When all the edges where the node numbered 6 is located have been explored, the search will backtrack to the starting node of the edge where the node numbered 6 is found, such as the node numbered 2. When all the edges where the node numbered 2 is located have been explored, the search will backtrack to the starting node of the edge where the node numbered 2 is found, such as the node numbered 1, and search the tree branches as deeply as possible again from the node numbered 1, such as searching to the node numbered 7. When all the edges where the node numbered 7 is located have been explored, the search will backtrack to the starting node of the edge where the node numbered 7 is found, such as the node numbered 1, and search the tree branches as deeply as possible again from the node numbered 1, such as searching to the node numbered 8, the node numbered 9, and the node numbered 10. When all the edges where the node numbered 10 is located have been explored, the search will backtrack to the starting node of the edge where the node numbered 10 is found, such as the node numbered 9, and search the tree branches as deeply as possible again from the node numbered 9, such as searching to the node numbered 11. When all the nodes reachable from the source node have been found, the depth search stops.

[0108] If only the depth-first search algorithm is used, only the nodes that may be included in the syntax tree can be searched, and the association relationship between each node and the API cannot be known. For this reason, in the embodiments of the present application, the subtree pattern matching algorithm can also be used to analyze the attributes of each node in the syntax tree, such as the API corresponding to the node and the source of the API, etc. If several nodes meet the preset rules, the corresponding API can be extracted. For example Figure 5BAs shown, CALL_EXPR and DECL_REF_EXPR exist in the source code, and the API is from OpenCV, so it is recognized as a call to the cv::resize() API. Similarly, the APIs associated with other nodes can also be obtained by using this method for analysis, which will not be elaborated here.

[0109] Among them, the m first APIs recognized in S420 can be all the APIs associated with the syntax tree. Since the types of APIs associated with the syntax tree are diverse, for example, they include built-in language APIs such as print and operators, or for example, they include acceleration library APIs. In an optional implementation manner, before implementing S420, the key APIs to be recognized can be specified according to needs, such as acceleration library APIs. When implementing S420, specifically, it can be to recognize the key APIs associated with the syntax tree, then the computing node can scan the syntax tree by using the depth-first search algorithm and subtree pattern matching algorithm introduced above to identify the key APIs of the syntax tree.

[0110] S430: The computing node obtains a call stack according to the attribute information of the multiple nodes.

[0111] In the embodiment of the present application, the call stack indicates the call relationship existing between the m first APIs. For example, if the call relationship between different APIs in the syntax tree satisfies the situation of continuous call stack introduced above, a call stack can be obtained according to the attribute information of the multiple nodes, and this call stack can indicate the continuous call relationship existing between the m first APIs. Or for example, if the call relationship between different APIs in the syntax tree satisfies the situation of discontinuous call stack introduced above, at least one call stack can be obtained according to the attribute information of the multiple nodes, and any call stack in the at least one call stack can indicate the continuous call relationship existing between some of the m first APIs. It should be noted that for an API that does not have a call relationship with any other API, it can be ignored. That is to say, when implementing S430, at least one call stack can be extracted according to the actual situation of each node and its attributes of the syntax tree, and each call stack can indicate the call relationship of at least two APIs.

[0112] It can be understood that when implementing the above steps, it can be to execute S420 first and then S430, or it can be to execute S420 and S430 simultaneously. The embodiment of the present application does not make specific limitations on this implementation step.

[0113] In an optional implementation manner, the attribute information of the multiple nodes includes the parameters of the API associated with each node. When implementing S430, the computing node can obtain the call stack according to the parameters of the APIs respectively associated with the multiple nodes.

[0114] Taking the parameters of the API associated with each node including the input parameters of the API as an example, when a certain first API among the m first APIs is selected and represented as the second API, in implementing S430, the input parameter call stack of the second API can be obtained based on the input parameters of the second API. Specifically, for example, for the second API, if in the syntax tree, the input parameters of the second API are the child nodes of the second API, the method of post-order traversal is used to traverse the multiple nodes to obtain the input parameter call stack of the second API. As shown in Figure 6 (a) shown, if the input parameter of the API numbered A is the child node of the current API, then the method of post-order traversal is used to traverse the API numbered 1, the API numbered 2, and the API numbered A to obtain the input parameter call stack of the API numbered A.

[0115] Taking the parameters of the API associated with each node including the output parameters of the API as an example, when a certain first API among the m first APIs is selected and represented as the second API, in implementing S430, the output parameter call stack of the second API can be obtained based on the output parameters of the second API. Specifically, for example, for the second API among the m first APIs, if in the ST, the output parameters of the second API are the child nodes of the second API, the method of pre-order traversal is used to traverse the multiple nodes to obtain the output parameter call stack of the second API. As shown in Figure 6 (b) shown, if the output parameter of the API numbered A is the child node of the current API, then the method of pre-order traversal is used to traverse the API numbered A, the API numbered 3, and the API numbered 4 to obtain the output parameter call stack of the API numbered A. In an alternative implementation, based on the input parameter call stack of the API numbered A and the output parameter call stack of the API numbered A, a continuous call stack including the API numbered A can also be obtained, as shown in Figure 6 (c) shown.

[0116] It should be noted that in the embodiments of the present application, before implementing S430, it can be agreed that the call stack to be extracted is the input parameter call stack and / or the output parameter call stack. The computing node can implement S430 according to the agreement to extract the call stack that meets the requirements, and this call stack can indicate the call relationship between different APIs associated with the syntax tree. In an alternative implementation, to ensure the accuracy of the representation methods of each API in the embodiments of the present application, at least one call stack extraction method can be agreed to obtain more call relationships, which is convenient for subsequent obtaining the accuracy of the distributed representation vectors of multiple first APIs associated with the syntax tree based on the neural network model.

[0117] S440: The computing node trains the neural network model according to the m first APIs and the call stack.

[0118] In the embodiments of the present application, the model parameters of the trained neural network model include a first representation vector set, and the first representation vector set includes first representation vectors of some or all of the m first APIs.

[0119] For ease of distinction, the initialized neural network model before training can be represented as a first neural network model. The model parameters of the first neural network model may include second representation vectors based on some or all of the m first APIs. The neural network model obtained after training is represented as a second neural network model, and the model parameters of the second neural network model may include first representation vectors of some or all of the m first APIs.

[0120] Taking n third APIs to represent some or all of the m first APIs, when specifically implementing S440, for example, n third APIs among the m first APIs can be used as a corpus to construct a first neural network model, where the model parameters of the first neural network model include second representation vectors of the n third APIs; select an input API and an output API from the n third APIs according to the call stack, and train the first neural network model according to the input API and the output API to obtain a second neural network model, and the model parameters of the second neural network model include first representation vectors of the n third APIs.

[0121] Taking the elements of the weight matrix between the input layer and the hidden layer of the neural network model as the model parameters as an example, before constructing the first neural network model, an API dictionary can be extracted with the m first APIs and the corresponding call stack as the corpus. The API dictionary contains all the key APIs scanned from the syntax tree, which is represented as n third APIs (that is, the APIs that appear repeatedly in different call stacks have been de-duplicated), and can be used to construct the weight matrix between the input layer and the hidden layer of the first neural network model, which is represented as W {v,d} , where v represents the size of the API dictionary and d represents the vector length. Each element in this W {v,d} is the second representation vector of the n third APIs. The second representation vector can be a randomly initialized value or a specified value, and the embodiments of the present application do not limit this.

[0122] After a given API vector is used as the output, other APIs that have a call relationship with this API can be obtained from the call stack as input APIs. For example Figure 6 in, if the API numbered A is specified as the output API, then according to the corresponding call stack in (c), the APIs numbered 1, 2, 3, and 4 can all be used as input APIs. As Figure 7As shown, when training the first neural network model, it is necessary to make each input API pass through the input layer and the weight matrix between the input layer and the hidden layer to reach the hidden layer. After passing through 0 - N layers of neural networks (not shown in the figure), the output API is obtained. If, based on the above corpus, the mapping between the input API and the output API can be obtained with the assistance of the neural network model, it can be considered that the training is completed, and at this time, the second neural network model is obtained. Then, the elements in the weight matrix between the input layer and the hidden layer of the second neural network model are the first representation vectors of n third APIs.

[0123] Thus, through the above method, the model parameters of the neural network model can be trained in combination with the call stack, improving the correlation between different APIs, so that the representation vectors of each obtained API are more accurate. In this method, multiple APIs without semantic relationships in the syntax tree can be converted into a call stack with semantic relationships, so that the semantic information of the representation vectors of each obtained API is more accurate.

[0124] The above method can be used to obtain the representation vectors of different APIs in different business scenarios. The representation vectors of multiple different types / uses of APIs can form an API embedding table, and this API embedding table is the distributed representation vector of the API, which can be applied to different AI + code applications, including but not limited to code detection, code migration, code understanding, code completion, code generation, etc.

[0125] Taking the code migration scenario as an example, the computing node can pre - obtain the representation vectors of multiple APIs. The representation vectors of the multiple APIs are obtained by training based on the first call stack and the neural network model introduced above, and the first call stack indicates the call relationships existing between the multiple APIs. When performing code migration, the computing node can execute the following steps:

[0126] S1: Obtain the first code file used by the first platform;

[0127] S2: Extract m first APIs based on the first code file;

[0128] S3: Obtain the representation vectors of the m first APIs from the representation vectors of the multiple APIs;

[0129] S4: Determine the representation vectors of n second APIs that satisfy the similarity condition with the representation vectors of the m first APIs;

[0130] S5: Recommend the code of the m first APIs to the second platform using the n second APIs to perform code migration between the first platform and the second platform.

[0131] In an alternative embodiment, it is also possible to calculate the similarity matrix of APIs between different platforms in real time in the AI+code application scenario, and perform API recommendation and code migration based on this similarity matrix. For example, Figure 8 as shown, this method may include the following steps:

[0132] S801: Perform API space fusion on Platform 1 and Platform 2 to be migrated across platforms. Among them, when the APIs between Platform 1 and Platform 2 are significantly different, equivalent API replacement can be performed manually to make some APIs in Platform 2 the same as those in Platform 1, so as to achieve API space fusion between platforms and facilitate the semantic association of APIs between platforms.

[0133] Exemplarily, the source code of Platform 1 may be as follows:

[0134]

[0135]

[0136] The source code of Platform 2 may be as follows:

[0137]

[0138]

[0139] S802: Read the source code file and associate the dependent libraries at the same time. Using compilation technology, generate a syntax tree. For specific implementation details, please refer to the introduction in conjunction with S410 above and will not be elaborated here.

[0140] S803: Scan the syntax tree through the depth-first search algorithm and the subtree pattern matching algorithm to identify the key APIs associated with the syntax tree. For specific implementation details, please refer to the introduction in conjunction with S420 above and will not be elaborated here.

[0141] After that, in the aforementioned manner, it is possible to enter S809 to perform fuzzy recommendation and code migration by querying the API Embedding table, as shown in S1-S5 above. Or, in accordance with the aforementioned representation method, it is possible to enter S804 to obtain the representation vectors of different APIs in real time and perform accurate recommendation and code migration.

[0142] S804: Extract the call stack based on the syntax tree. For specific implementation details, please refer to the introduction in conjunction with S430 above and will not be elaborated here.

[0143] S805: Construct an API corpus.

[0144] S806: Construct and train a neural network model.

[0145] S807: Obtain the distributed representation of the API based on the trained neural network model. For the specific implementation details of S805 - S807, refer to the introduction in combination with S440 above, which will not be elaborated here.

[0146] Exemplarily, taking the key APIs including Decode, Cv::Mat, Image::Image, etc. as an example, the distributed representation of the API can be as shown in Table 1 below:

[0147] Table 1

[0148] Decode 0.3 0.2 0.9 … Cv::Mat 0.0 0.4 0.5 … Image::Image 0.1 0.5 0.4 … … … … … <![CDATA[W {v,d} >

[0149] Among them, in the above Table 1, except for the first column, it includes elements of v rows and d columns. Each row is the representation vector of an API in the API dictionary corresponding to the syntax tree, and the length of the API representation vector is d.

[0150] S808: Calculate the API similarity matrix between Platform 1 and Platform 2, and perform API recommendation and code migration based on the similarity matrix.

[0151] Exemplarily, the similarity matrix can be as shown in Table 2 below:

[0152] Table 2

[0153] cv::Size cv::Mat … Size 0.9 0.3 … Image::Image 0.1 0.8 … … … … …

[0154] S809: Perform fuzzy recommendation and code migration by querying the API Embedding table, as detailed in S1 - S5 above.

[0155] Through the above method, the model parameters of the neural network model can be trained in combination with the call stack, improving the correlation between different APIs, so that the obtained representation vectors of each API are more accurate. In this method, multiple APIs without semantic relationships in the syntax tree can be converted into call stacks with semantic relationships, so that the semantic information of the obtained representation vectors of each API is more accurate.

[0156] The embodiment of the present application also provides a computing device (or a representation device of the API) for executing the method executed by the computing node in the above method embodiment. For related features, refer to the above method embodiment, which will not be elaborated here.

[0157] Such as Figure 9As shown, the computing device 900 may include: an obtaining unit 901, configured to obtain a syntax tree ST corresponding to a source code file, where the ST includes a plurality of nodes and attribute information of the plurality of nodes, and each node is associated with at most one application programming interface API; an identifying unit 902, configured to identify m first APIs associated with the ST, where m is an integer greater than or equal to 1; the obtaining unit 901 is further configured to obtain a call stack according to the attribute information of the plurality of nodes, and the call stack indicates a call relationship existing between the m first APIs; a training unit 903, configured to train a neural network model according to the m first APIs and the call stack, where model parameters of the trained neural network model include a first representation vector set, and the first representation vector set includes first representation vectors of some or all of the m first APIs. For specific implementation manners, please refer to the method steps implemented by the computing node in the foregoing method embodiment, which will not be elaborated here.

[0158] In a code migration scenario, the foregoing computing device 900 may further include an extracting unit, a determining unit, and a recommending unit. Among them, the computing node includes representation vectors of a plurality of APIs, the representation vectors of the plurality of APIs are obtained by training based on a first call stack and a neural network model, the first call stack indicates a call relationship existing between the plurality of APIs, and the device includes: an obtaining unit, configured to obtain a first code file used by a first platform; an extracting unit, configured to extract m first APIs based on the first code file; the obtaining unit is further configured to obtain the representation vectors of the m first APIs from the representation vectors of the plurality of APIs; a determining unit, configured to determine representation vectors of n second APIs that satisfy a similarity condition with the representation vectors of the m first APIs; a recommending unit, configured to recommend the code of the m first APIs to a second platform using the n second APIs for code migration between the first platform and the second platform. For specific implementation manners, please refer to the method steps implemented by the computing node in the foregoing method embodiment, which will not be elaborated here.

[0159] It should be understood that the division of each unit in the above device is only a division of logical functions. In actual implementation, it can be fully or partially integrated into a physical entity, or physically separated. In addition, the units in the device can be implemented in the form of a processor calling software. For example, the device includes a processor, the processor is connected to a memory, and instructions are stored in the memory. The processor calls the instructions stored in the memory to implement any of the above methods or the functions of each unit of the device. The processor is, for example, a general-purpose processor, such as a Central Processing Unit (CPU) or a microprocessor, and the memory is a memory inside or outside the device. Alternatively, the units in the device can be implemented in the form of a hardware circuit, and the functions of some or all of the units can be implemented through the design of the hardware circuit. The hardware circuit can be understood as one or more processors. For example, in one implementation, the hardware circuit is an application-specific integrated circuit (ASIC), and the functions of some or all of the above units are implemented through the design of the logical relationship of the components in the circuit. Again, in another implementation, the hardware circuit can be implemented by a programmable logic device (PLD). Taking a Field Programmable Gate Array (FPGA) as an example, it can include a large number of logic gate circuits, and the connection relationship between the logic gate circuits is configured through a configuration file, thereby implementing the functions of some or all of the above units. All units of the above device can be implemented entirely in the form of a processor calling software, or entirely in the form of a hardware circuit, or partially in the form of a processor calling software, and the remaining part in the form of a hardware circuit.

[0160] In the embodiments of the present application, a processor is a circuit with signal processing capabilities. In one implementation, the processor can be a circuit with instruction reading and running capabilities, such as a CPU, a microprocessor, a graphics processing unit (GPU) (which can be understood as a type of microprocessor), or a digital signal processor (DSP), etc.; in another implementation, the processor can achieve certain functions through the logical relationship of hardware circuits, and the logical relationship of the hardware circuits is fixed or can be reconfigured. For example, the processor is a hardware circuit implemented by an ASIC or a PLD, such as an FPGA. In a reconfigurable hardware circuit, the process of the processor loading a configuration document to implement the configuration of the hardware circuit can be understood as the process of the processor loading instructions to implement the functions of some or all of the above units. In addition, it can also be a hardware circuit designed for artificial intelligence, which can be understood as a type of ASIC, such as a neural network processing unit (NPU), a tensor processing unit (TPU), a deep learning processing unit (DPU), etc.

[0161] It can be seen that each unit in the above device can be one or more processors (or processing circuits) configured to implement the above method, such as: CPU, GPU, NPU, TPU, DPU, microprocessor, DSP, ASIC, FPGA, or a combination of at least two of these processor forms.

[0162] In addition, each unit in the above device can be integrated in whole or in part, or can be independently implemented. In one implementation, these units are integrated together and implemented in the form of a system-on-a-chip (SOC). The SOC can include at least one processor for implementing any of the above methods or implementing the functions of each unit of the device. The types of the at least one processor can be different, such as including a CPU and an FPGA, a CPU and an artificial intelligence processor, a CPU and a GPU, etc.

[0163] In a simple embodiment, those skilled in the art can think that the computing devices in the above embodiments can all adopt Figure 10 the form shown.

[0164] As Figure 10 shown in the device 1000, it includes at least one processor 1010 and a communication interface 1030. In an optional design, a memory 1020 can also be included.

[0165] In the embodiments of the present application, the specific connection medium between the above-mentioned processor 1010 and the memory 1020 is not limited.

[0166] In a device such as Figure 10 when the processor 1010 communicates with other devices, data transmission can be performed through the communication interface 1030.

[0167] When the computing device adopts the form shown in Figure 10 the processor 1010 in Figure 10 can execute any of the above method embodiments by calling the computer-executable instructions stored in the memory 1020, so that the device 1000 can execute.

[0168] The embodiments of the present application also relate to a chip system, which includes a processor for calling a computer program or computer instructions stored in a memory, so that the processor executes the method of any of the above embodiments.

[0169] In a possible implementation manner, the processor can be coupled to the memory through an interface.

[0170] In a possible implementation manner, the chip system may also directly include a memory, and a computer program or computer instructions are stored in the memory.

[0171] Exemplarily, the memory may be a volatile memory or a non-volatile memory, or may include both volatile and non-volatile memories. Among them, the non-volatile memory may be a read-only memory (ROM), a programmable ROM (PROM), an erasable PROM (EPROM), an electrically erasable PROM (EEPROM), or a flash memory. The volatile memory may be a random access memory (RAM), which is used as an external cache. By way of example but not limitation, many forms of RAM are available, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDR SDRAM), enhanced SDRAM (ESDRAM), synchlink DRAM (SLDRAM), and direct rambus RAM (DRRAM).

[0172] An embodiment of the present application further relates to a processor, which is used to call a computer program or computer instructions stored in the memory, so that the processor executes the method described in any one of the above embodiments.

[0173] Exemplarily, in the embodiments of the present application, the processor is an integrated circuit chip with the ability to process signals. For example, the processor can be an FPGA, a general-purpose processor, a DSP, an ASIC, or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components. It can also be a system on chip (SoC), a CPU, a network processor (NP), a microcontroller unit (MCU), a PLD, or other integrated chips, and can implement or execute the various methods, steps, and logic block diagrams disclosed in the embodiments of the present application. The general-purpose processor can be a microprocessor or the processor can also be any conventional processor, etc. The steps of the method disclosed in combination with the embodiments of the present application can be directly embodied as being executed and completed by a hardware decoding processor, or executed and completed by a combination of hardware and software modules in the decoding processor. The software module can be located in a random access memory, flash memory, read-only memory, programmable read-only memory, or electrically erasable programmable memory, registers, and other mature storage media in the art. This storage media is located in the memory, and the processor reads the information in the memory and combines its hardware to complete the steps of the above method.

[0174] It should be understood that the embodiments of the present application can be provided as a method, a system, or a computer program product.

[0175] In a possible implementation manner, the embodiments of the present application provide a computer-readable storage medium, and the computer-readable storage medium stores program code. When the program code runs on the computer, the computer is caused to execute the above method embodiments.

[0176] In a possible implementation manner, the embodiments of the present application provide a computer program product. When the computer program product runs on the computer, the computer is caused to execute the above method embodiments.

[0177] Therefore, the present application can adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware aspects. Moreover, the present application can adopt the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk memories, CD-ROMs, optical memories, etc.) containing computer-usable program code.

[0178] These computer program instructions can also be stored in a computer-readable memory that can direct a computer or other programmable data processing device to work in a specific manner, so that the instructions stored in the computer-readable memory produce a manufactured article including an instruction device, and the instruction device implements the process Figure 1 one process or multiple processes and / or blocksFigure 1 The functions specified in one or more boxes.

[0179] These computer program instructions can also be loaded onto a computer or other programmable data processing device, so that a series of operation steps are executed on the computer or other programmable device to generate a computer-implemented process. Thus, the instructions executed on the computer or other programmable device provide for implementing the steps of the functions specified in one or more processes and / or boxes Figure 1 one process or more processes and / or boxes Figure 1 The steps of the functions specified in one or more boxes.

[0180] Obviously, those skilled in the art can make various changes and modifications to the embodiments of the present application without departing from the scope of the embodiments of the present application. Thus, if these modifications and variations of the embodiments of the present application fall within the scope of the claims of the present application and their equivalent technologies, the present application also intends to include these changes and modifications. In each embodiment of the present application, if there is no special description and logical conflict, the terms and / or descriptions between the embodiments are consistent and can be referenced to each other. The technical features in different embodiments can be combined to form new embodiments according to their inherent logical relationships.

Claims

1. A representation method of an application programming interface, characterized in that, Including: Obtain a syntax tree ST corresponding to a source code file, where the ST includes a plurality of nodes and attribute information of the plurality of nodes, and each node is associated with at most one application programming interface API; Identify m first APIs associated with the ST, where m is an integer greater than or equal to 1; Obtain a call stack according to the attribute information of the plurality of nodes, where the call stack indicates the call relationship existing between the m first APIs; Train a neural network model according to the m first APIs and the call stack, where the model parameters of the trained neural network model include a first representation vector set, and the first representation vector set includes first representation vectors of some or all of the m first APIs.

2. The method according to claim 1, wherein The attribute information of the plurality of nodes includes the parameters of the API associated with each node, and obtaining the call stack according to the attribute information of the plurality of nodes includes: Obtain the call stack according to the parameters of the APIs respectively associated with the plurality of nodes.

3. The method according to claim 2, wherein The parameters of the API associated with each node include the input parameters of the API, the m first APIs include a second API, the call stack includes the input parameter call stack of the second API, and obtaining the call stack according to the parameters of the APIs associated with the plurality of nodes includes: For the second API, if in the ST, the input parameter of the second API is a child node of the second API, traverse the plurality of nodes by using a post-order traversal method to obtain the input parameter call stack of the second API.

4. The method according to claim 2, wherein The parameters of the API associated with each node include the output parameters of the API, the m first APIs include a second API, the call stack includes the output parameter call stack of the second API, and obtaining the call stack according to the parameters of the APIs associated with the plurality of nodes includes: For the second API among the m first APIs, if in the ST, the output parameter of the second API is a child node of the second API, traverse the plurality of nodes by using a pre-order traversal method to obtain the output parameter call stack of the second API.

5. The method according to any one of claims 1-4, characterized in that, Training the neural network model according to the m first APIs and the call stack includes: Construct a first neural network model with n third APIs among the m first APIs as corpus, where the model parameters of the first neural network model include second representation vectors of the n third APIs; Select an input API and an output API from the n third APIs according to the call stack, and train the first neural network model according to the input API and the output API to obtain a second neural network model, where the model parameters of the second neural network model include first representation vectors of the n third APIs.

6. The method according to any one of claims 1-5, characterized in that, Identifying the m first APIs associated with the ST includes: Scan the ST through a depth-first search algorithm and a subtree pattern matching algorithm to identify the m first APIs associated with the ST.

7. A code migration method, characterized in that, Applied to a computing node, the computing node includes representation vectors of multiple APIs, the representation vectors of the multiple APIs are obtained based on a first call stack and a neural network model, and the first call stack indicates the call relationships existing among the multiple APIs. The method includes: Obtain a first code file used by a first platform; Extract m first APIs based on the first code file; Obtain the representation vectors of the m first APIs from the representation vectors of the multiple APIs; Determine the representation vectors of n second APIs that satisfy the similarity condition with the representation vectors of the m first APIs; Recommend the code of the m first APIs to a second platform that uses the n second APIs for code migration between the first platform and the second platform.

8. A representation device for an application programming interface, characterized in that, Includes: An acquisition unit, configured to obtain a syntax tree ST corresponding to a source code file, the ST includes multiple nodes and attribute information of the multiple nodes, and each node is associated with at most one application programming interface API; An identification unit, configured to identify m first APIs associated with the ST, where m is an integer greater than or equal to 1; The acquisition unit is further configured to obtain a call stack according to the attribute information of the multiple nodes, and the call stack indicates the call relationships existing among the m first APIs; A training unit, configured to train a neural network model according to the m first APIs and the call stack. Among them, the model parameters of the trained neural network model include a first representation vector set, and the first representation vector set includes the first representation vectors of some or all of the m first APIs.

9. A code migration device, characterized in that, Applied to a computing node, the computing node includes representation vectors of multiple APIs, the representation vectors of the multiple APIs are obtained based on a first call stack and a neural network model, and the first call stack indicates the call relationships existing among the multiple APIs. The device includes: An acquisition unit, configured to obtain a first code file used by a first platform; An extraction unit, configured to extract m first APIs based on the first code file; The acquisition unit is further configured to obtain the representation vectors of the m first APIs from the representation vectors of the multiple APIs; A determination unit, configured to determine the representation vectors of n second APIs that satisfy the similarity condition with the representation vectors of the m first APIs; A recommendation unit, configured to recommend the code of the m first APIs to a second platform that uses the n second APIs for code migration between the first platform and the second platform.

10. A computing device, characterized in that, Includes at least one processor and an interface circuit. The interface circuit is configured to provide data or code instructions for the at least one processor. The at least one processor is configured to implement the method according to any one of claims 1-6 through logic circuits or by executing code instructions, or implement the method according to claim 7.

11. A computer-readable storage medium, characterized in that, The computer-readable medium stores program code. When the program code runs on a computer, it causes the computer to execute the method according to any one of claims 1-6, or causes the computer to execute the method according to claim 7.

12. A computer program product, characterized in that, When the computer program product runs on a computer, it causes the computer to execute the method according to any one of claims 1-6, or causes the computer to execute the method according to claim 7.