Migrated API estimation device, migrated API estimation method, and program
The device and method address the challenge of identifying migration destination APIs without explanatory text by calculating embeddings and using machine learning to determine API relationships, ensuring efficient library updates.
Patent Information
- Application Number
- JP2021204264
- Authority / Receiving Office
- JP · JP
- Patent Type
- Patents
- Current Assignee / Owner
- Filing Date
- 2021-12-16
- Publication Date
- 2024-10-23
- Estimated Expiration
- 2041-12-16
AI Technical Summary
Existing methods struggle to identify migration destination APIs for library updates when explanatory text is absent, hindering efficient library updates due to the variability in indicating destination APIs across different sources.
A device and method that calculates signature embeddings for APIs, using similarity calculations and machine learning to determine migration destination APIs based on source APIs and candidate APIs, even without explanatory text, through a determination unit and learning unit.
Enables accurate estimation of migration destination APIs even when explanatory text is missing, facilitating efficient library updates by determining API relationships through embeddings and similarity calculations.
Smart Images

Figure 0007571719000001 
Figure 0007571719000002 
Figure 0007571719000003
Abstract
Description
[Technical field]
[0001] The present invention relates to a destination API estimation device, a destination API estimation method, and a program. [Background technology]
[0002] Libraries are widely used in software development. When using libraries, it is recommended to use or update to the new version. However, there are cases where the replacement API for the application program interface (API) that has been deprecated or removed from the new version is not indicated. Even if the replacement API is indicated, the way it is indicated varies from library to library or API to API. For example, the replacement API may be indicated in the API documentation, or in the commit message, release notes, or technical SNS or blogs. Therefore, a lot of effort is required to identify the replacement API, such as searching and collecting information. This is a factor that prevents libraries from being updated.
[0003] Conventionally, when a finite number of candidates are given as the migration destination of an API, there is a technology that determines whether the candidate is suitable as the migration destination API based on the signatures and API descriptions of the source API and the migration destination candidate API (Non-Patent Document 1). [Prior art documents] [Non-patent literature]
[0004] [Non-Patent Document 1] Alrubaye, H., Mkaouer, MW, Khokhlov, I., Reznik, L., Ouni, A., and Mcgoff, J. "Learning to recommend third-party library migration opportunities at the api level". Applied Soft Computing 90 (2020), 106140. Summary of the Invention [Problem to be solved by the invention]
[0005] However, there are many cases where no description is provided for an API. Therefore, when there is an API for which no description is provided, it is difficult to use the technology of Non-Patent Document 1.
[0006] The present invention has been made in consideration of the above-mentioned points, and has an object to make it possible to estimate the migration destination API of a certain API even when there exists an API for which no description is provided. [Means for solving the problem]
[0007] In order to solve the above problem, the destination API estimation device has a first calculation unit configured to calculate an embedding of each signature of a source API and a candidate API that is a candidate destination of the source API, and calculate a first similarity between the two calculated embeddings, a second calculation unit configured to calculate an embedding of each source code of the source API and the candidate API, and calculate a second similarity between the two calculated embeddings, and a determination unit configured to determine whether the candidate API is a destination of the source API based on the first similarity and the second similarity. Effect of the Invention
[0008] Even when there exists an API for which no description is given, it is possible to infer the API to which a certain API will migrate. [Brief description of the drawings]
[0009] [Figure 1] 1 is a diagram illustrating an example of a hardware configuration of a destination API estimation device 10 according to an embodiment of the present invention. [Diagram 2] 1 is a diagram illustrating an example of a functional configuration of a destination API estimation device 10 according to an embodiment of the present invention. [Diagram 3] FIG. 2 is a diagram illustrating an example of the configuration of a determination unit 11. [Figure 4] 11 is a flowchart illustrating an example of a process procedure for determining a weighting coefficient θ by machine learning. [Diagram 5] 13 is a flowchart illustrating an example of a procedure for a migration destination API estimation process. [Figure 6] FIG. 2 is a diagram for explaining a signature and a body. [Figure 7] FIG. 13 is a diagram showing a state in which an instance of the determination unit 11 has been copied. DETAILED DESCRIPTION OF THE PREFERRED EMBODIMENTS
[0010] Hereinafter, an embodiment of the present invention will be described with reference to the drawings. Fig. 1 is a diagram showing an example of a hardware configuration of a destination API estimation device 10 in an embodiment of the present invention. The destination API estimation device 10 in Fig. 1 has a drive device 100, an auxiliary storage device 102, a memory device 103, a processor 104, an interface device 105, and the like, which are all connected to each other via a bus B.
[0011] A program for realizing the processing in the destination API estimation device 10 is provided by a recording medium 101 such as a CD-ROM. When the recording medium 101 storing the program is set in the drive device 100, the program is installed from the recording medium 101 via the drive device 100 into the auxiliary storage device 102. However, the program does not necessarily have to be installed from the recording medium 101, but may be downloaded from another computer via a network. The auxiliary storage device 102 stores the installed program as well as necessary files, data, and the like.
[0012] When an instruction to start a program is received, the memory device 103 reads out and stores the program from the auxiliary storage device 102. The processor 104 is a CPU or a GPU (Graphics Processing Unit), or a CPU and a GPU, and executes functions related to the destination API estimation device 10 in accordance with the program stored in the memory device 103. The interface device 105 is used as an interface for connecting to a network.
[0013] Fig. 2 is a diagram showing an example of a functional configuration of the destination API estimation device 10 in the embodiment of the present invention. As shown in Fig. 2, the destination API estimation device 10 has a determination unit 11 and a learning unit 12. These units are realized by a process in which one or more programs installed in the destination API estimation device 10 are executed by the processor 104.
[0014] The determination unit 11 receives as input information on the source API (hereinafter referred to as the "source API") and information on a finite number of candidates (hereinafter referred to as the "candidate API") for the destination of that API (hereinafter referred to as the "destination API"), and determines whether each candidate API is a destination API. The API information (hereinafter referred to as the "API information") is a set of source code (hereinafter referred to as the unit "source code") that defines the API and a signature.
[0015] However, the API information for some or all of the APIs among the source API and the candidate API group may further include a description of the API in natural language (hereinafter simply referred to as a "description").
[0016] The learning unit 12 learns the values of parameters (coefficients) used by the determination unit 11.
[0017] 3 is a diagram showing an example of the configuration of the determination unit 11. In FIG. 3, the determination unit 11 includes a description / signature similarity calculation unit 111, a chord similarity calculation unit 112, a linear combination unit 113, and a classification unit 114.
[0018] The description and signature similarity calculation unit 111 calculates an embedding of a string in which the description and signature of each of the source API and one candidate API are concatenated, and calculates the similarity (cosine similarity) between the two calculated embeddings. Note that since the description is not a required element, the embedding of a string in which the description and signature are concatenated may be an embedding of a string that includes only the signature.
[0019] The code similarity calculation unit 112 calculates the embedding of the source code of each of the source API and one candidate API, and calculates the similarity between the two calculated embeddings. The determination by the determination unit 11 is made based on the similarity of the embedding of the description and signature of each of the two APIs, and the similarity of the embedding of the source code.
[0020] However, embedding of data A refers to the result of encoding A into a multidimensional vector. The reason for using similarity as a basis is that if two APIs are in a source / destination relationship, the meanings of their source codes, descriptions, and signatures tend to be similar, and this is used for estimation.
[0021] The reason for using embedding is that the "meaning" of source code, description, and signatures can be mapped to points in a multidimensional space. The embedding of source code, description, and signatures uses representation learning models such as those in References 1 and 2 below, respectively (publicly available pre-trained models for each may be used). [References 1] Devlin, J., Chang, M.-W., Lee, K., and Toutanova, K. BERT: Pre-training of deep bidirectional transformers for language understanding. In Proceedings of the 2019 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies, Volume 1 (Long and Short Papers) (Minneapolis, Minnesota, June 2019), Association for Computational Linguistics, pp. 4171-4186. [Reference 2] Feng, Z., Guo, D., Tang, D., Duan, N., Feng, X., Gong, M., Shou, L., Qin, B., Liu, T., Jiang, D., and Zhou, M. CodeBERT: A pre-trained model for programming and natural languages. In Findings of the Association for Computational Linguistics: EMNLP 2020 (Online, Nov. 2020), Association for Computational Linguistics, pp. 1536-1547. The linear combination unit 113 linearly combines the respective similarities calculated by the description / signature similarity calculation unit 111 and the chord similarity calculation unit 112 with a weighting factor θ. N , p C Then, it is given by the following equation (1). θ N +p N +θC +p C +θ i (1) However, θ i is the bias term. θ N , θ C , θ i is determined by the learning unit 12 through learning using teacher data so as to minimize the cross entropy error regarding the binary classification result.
[0022] The classification unit 114 activates the linear combination result using a sigmoid function to output a binary classification result indicating whether or not the two APIs are in a source / destination relationship.
[0023] The following describes the processing procedure executed by the destination API estimation device 10. Fig. 4 is a flowchart for explaining an example of the processing procedure for determining the weighting coefficient θ by machine learning.
[0024] In step S101, the learning unit 12 reads training data. Here, the training data includes a positive example pair consisting of two APIs (λs, λt) that have a known source-destination relationship, and a negative example pair consisting of λs and an API that belongs to the same library as λt but is not the destination of λs. These positive example pairs and negative example pairs are created in advance. The configuration of the training data is defined in a format conforming to the BNF (Backus-Naur form) notation as follows: teaching Training data::=(λs, λt, label)+ λs::=API information λt::=API information Label::=0|1 The label value of a positive example is 1, and the label value of a negative example is 0.
[0025] Next, the learning unit 12 determines the weighting factor θ by machine learning using the teacher data as an input to the judgment unit 11 (S102). Specifically, the learning unit 12 determines the weighting factor θ so that the cross entropy error of the judgment result by the judgment unit 11 is minimized when the positive examples and negative examples included in the teacher data are used as teacher signals.N , θ C , θ i Optimize using gradient descent.
[0026] FIG. 5 is a flowchart illustrating an example of a process for estimating a migration destination API.
[0027] In step S201, the determination unit 11 reads the source API and the candidate API list. In the description of FIG. 5, the source API and the candidate API list are defined as follows. Source API::=API information Candidate API List::= List of candidate APIs Candidate API::=API Information API information::=(NL-info,Code-info) NL-info::=Description~Delimiter~Signature|Signature Code-info::=Signature~Delimiter~Body Delimiter::=any delimiter Note that "~" is the string concatenation operator. "Signature" and "Body" respectively refer to the signature and body of the source code that defines the API. A signature is a string that represents modifier information such as API type information, argument information, and visibility. A body is a sequence of instructions that defines the operation of an API. In other words, a body is a part of a source code that does not include a signature (a part excluding the signature). For example, the signature of the source code shown in Figure 6 is part p1, and the body is part p2.
[0028] Next, the determination unit 11 generates a pair with the source API for each candidate API included in the candidate API list (S202). Then, steps S203 to S208 are executed for each pair. Hereinafter, the pair to be processed (target) is referred to as a "target pair."
[0029] In step S203, the description and signature similarity calculation unit 111 calculates the embedding of each of the NL-info of the source API and the NL-info of the candidate API of the target pair. That is, the description and signature similarity calculation unit 111 encodes each of these NL-info into a multi-valued vector. Thus, two embeddings are obtained. Next, the description and signature similarity calculation unit 111 calculates the cosine similarity between the two embeddings (S204).
[0030] In step S205, the chord similarity calculation unit 112 calculates embeddings of the Code-info of the source API and the Code-info of the candidate API of the target pair. That is, the chord similarity calculation unit 112 encodes each of these Code-infos into a multi-valued vector. Thus, two embeddings are obtained. Next, the chord similarity calculation unit 112 calculates the cosine similarity between the two embeddings (S206).
[0031] Next, the linear combination unit 113 applies the cosine similarity calculated in step S204, the cosine similarity calculated in step S206, and the learned weighting coefficient θ to equation (1) to linearly combine the two cosine similarities (S207).
[0032] Next, the classification unit 114 activates the result of the linear combination using a sigmoid function to classify the source API and the candidate API of the target pair into two values according to whether they are in a source-destination relationship (S208).
[0033] When steps S203 to S208 have been executed for all pairs, the determination unit 11 outputs the estimation result of the migration destination API (S209). The estimation result is defined as follows. inference result::= list of labels Label::=0|1 Regarding the label, 0 indicates a presumption (determination result) that the API is not a migration target API, and 1 indicates a presumption (determination result) that the API is a migration target API.
[0034] 5, steps S203 to S208 are described as loop processing for convenience, but for example, as shown in Fig. 7, the determination unit 11 may generate copies of its own instance as many as the number of pairs (the number of candidate APIs). In this case, each instance can execute steps S203 to S208 in parallel.
[0035] As described above, according to this embodiment, the similarity between two APIs is calculated based on the signatures and source code embedding of the two APIs, and whether or not the two APIs have a source / destination relationship is determined based on the similarity. Therefore, even if there is an API for which no description is given, it is possible to estimate the destination API of a certain API.
[0036] In the present embodiment, the description / signature similarity calculation unit 111 is an example of a first calculation unit, and the code similarity calculation unit 112 is an example of a second calculation unit.
[0037] Although the embodiment of the present invention has been described in detail above, the present invention is not limited to such specific embodiment, and various modifications and variations are possible within the scope of the gist of the present invention described in the claims. [Explanation of symbols]
[0038] 10 Migration destination API estimation device 11 Judgment section 12 Learning Department 100 Drive device 101 Recording media 102 Auxiliary storage 103 Memory device 104 processors 105 Interface device 111 Description Signature Similarity Calculation Unit 112 Chord Similarity Calculation Unit 113 Linear combination part 114 Classification Department B Bus
Claims
1. A first calculation unit configured to calculate an embedding of a signature of a source API and a candidate API that is a candidate for a migration destination of the source API, and to calculate a first similarity between the two calculated embeddings; a second calculation unit configured to calculate embeddings of source codes of the source API and the candidate API, and to calculate a second similarity between the two calculated embeddings; a determination unit configured to determine whether the candidate API is a migration destination of the migration source API based on the first similarity and the second similarity; A migration destination API estimation device comprising:
2. The first calculation unit is further configured to calculate an embedding of a string including a signature and a description of an API among the source API and the candidate API, for an API having a description.
2. The migration destination API estimation device according to claim 1.
3. The determination unit is configured to determine whether or not the candidate API is a migration destination of the migration source API based on a result of linearly combining the first similarity and the second similarity.
3. The migration destination API estimation device according to claim 1 or 2.
4. a learning unit configured to learn weighting coefficients for the first similarity and the second similarity in the linear combination based on teacher data including pairs of a source API and a destination API; 4. The migration destination API estimation device according to claim 3, further comprising:
5. A first calculation step of calculating an embedding of a signature of a source API and a candidate API that is a candidate for a migration destination of the source API, and calculating a first similarity between the two calculated embeddings; a second calculation step of calculating an embedding of each of the source codes of the source API and the candidate API, and calculating a second similarity between the two calculated embeddings; a determination step of determining whether the candidate API is a migration destination of the migration source API based on the first similarity and the second similarity; A method for estimating a migration destination API, the method being executed by a computer.
6. A first calculation step of calculating an embedding of a signature of a source API and a candidate API that is a candidate for a migration destination of the source API, and calculating a first similarity between the two calculated embeddings; a second calculation step of calculating an embedding of each of the source codes of the source API and the candidate API, and calculating a second similarity between the two calculated embeddings; a determination step of determining whether the candidate API is a migration destination of the migration source API based on the first similarity and the second similarity; A program characterized by being executed by a computer.
Citation Information
Patent Citations
Program porting support system
JP2004246690A
System transition support device and support method
JP2012113536A
Bidirectional protection of application package
US20200133690A1
Search device, search method, search program, and learning model search system
WO2021074990A1
Information processing program, information processing method, and information processing device
WO2021245950A1
