A network API recommendation method and device based on hypergraph contrastive learning
By constructing a heterogeneous hypergraph of Mashups and APIs, and utilizing hypergraph neural networks and an overall loss function, the sparsity and oversmoothing problems in network API recommendations are solved, thereby improving the accuracy of recommendations and the model training effect.
Patent Information
- Application Number
- CN202310858930.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-07-12
- Publication Date
- 2025-12-26
- Estimated Expiration
- 2043-07-12
AI Technical Summary
Existing network API recommendation methods suffer from poor recommendation performance due to the sparsity of historical interaction records between Mashups and APIs, and the oversmoothing phenomenon when graph neural networks aggregate multi-order neighbors.
A heterogeneous hypergraph for Mashup and API is constructed. Neighbor information is aggregated through a hypergraph neural network, and error is calculated by combining the overall loss function to obtain the target feature vector. Dot product operation is then performed to perform API recommendation.
It improves the accuracy of API recommendations, solves the sparsity problem of historical interaction records, avoids oversmoothing, and enhances model training and parameter updates.
Smart Images

Figure CN116821508B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The application relates to the field of computer technology application, and in particular to a network API recommendation method and device based on supergraph contrast learning. BACKGROUND
[0002] API (Application Programming Interface) refers to an application programming interface, which provides an interface for connecting different parts of a software system or different software systems. More and more enterprises release their core functions or data through APIs to be called by third parties. For example, Google has released more than one hundred kinds of APIs including Google Maps, Google Calendar, Google Photos and the like, and has created a large number of quality application programs on this basis. Mashup is a lightweight API combination technology, which enables non-professional programmers to easily use APIs to develop web applications, and such web applications are also called Mashup applications.
[0003] With the increasing number of network APIs, Mashup developers face a serious information overload problem; it is very time-consuming to manually search for APIs that meet their needs, and developers are required to have detailed knowledge of various APIs. A recommendation system is one of the methods for effectively alleviating information overload, which not only helps developers avoid the tedious process of manually searching for APIs, thereby saving a lot of time and effort, but also recommends some unexpected APIs to help developers develop innovative application programs, thereby promoting the continuous development and progress of the API ecosystem.
[0004] The existing recommendation technology mainly has the following problems:
[0005] 1. Traditional collaborative filtering recommendation methods and matrix decomposition methods are limited by the sparsity of historical interaction records between Mashup and APIs.
[0006] 2. Although the graph neural network method can alleviate the influence of data sparsity, aggregating multi-order neighbors is prone to over-smoothing, which makes the node feature vectors too similar and cannot be distinguished, resulting in low recommendation performance. SUMMARY
[0007] Therefore, the embodiments of the application provide a network API recommendation method based on supergraph contrast learning with high recommendation performance, which comprises the following steps:
[0008] Mashup information, API information and interaction information between Mashup and APIs are obtained;
[0009] constructing a heterogeneous hypergraph of Mashups and APIs according to the Mashup information, the API information, and the interaction information, to obtain an initial Mashup heterogeneous hypergraph and an initial API heterogeneous hypergraph;
[0010] converting the Mashup information and the API information into Mashup embedding vectors and API embedding vectors;
[0011] performing hypergraph neural network aggregation and summation based on the initial Mashup heterogeneous hypergraph, the initial API heterogeneous hypergraph, the Mashup embedding vectors, and the API embedding vectors, to obtain an initial Mashup feature vector and an initial API feature vector;
[0012] performing dot product operation on the initial Mashup feature vector and the initial API feature vector, to obtain an initial prediction score of Mashups to APIs;
[0013] performing error calculation on the initial prediction score through a total loss function, to obtain a target Mashup feature vector and a target API feature vector, performing dot product calculation on the target Mashup feature vector and the target API feature vector to obtain a target prediction score, and performing API recommendation for Mashups according to the target prediction score.
[0014] Optionally, the constructing a heterogeneous hypergraph of Mashups and APIs according to the Mashup information, the API information, and the interaction information, to obtain an initial Mashup heterogeneous hypergraph and an initial API heterogeneous hypergraph, comprises:
[0015] obtaining five entity types according to the Mashup information, the API information, and the interaction information between the Mashups and the APIs, the five entity types comprising: Mashups, APIs, Mashup categories, API categories, and API providers;
[0016] obtaining four entity relationships according to the five entity types, the four entity relationships comprising: an invocation relationship between the Mashups and the APIs, a belonging relationship between the Mashups and the Mashup categories, a belonging relationship between the APIs and the API categories, and a providing relationship between the APIs and the API providers;
[0017] constructing the initial Mashup heterogeneous hypergraph and the initial API heterogeneous hypergraph according to the five entity types and the four entity relationships.
[0018] Optionally, the converting the Mashup information and the API information into Mashup embedding vectors and API embedding vectors comprises:
[0019] The name of the Mashup and the name of the API are identified by a number;
[0020] The number mapping is converted into an embedding vector by an embedding layer, obtaining a Mashup embedding vector and an API embedding vector.
[0021] Optionally, based on the initial Mashup heterogeneous hypergraph, the initial API heterogeneous hypergraph, the Mashup embedding vector and the API embedding vector, the initial Mashup feature vector and the initial API feature vector are obtained by hypergraph neural network aggregation and summation, comprising:
[0022] The neighbor information of the nodes of the initial Mashup heterogeneous hypergraph, the initial API heterogeneous hypergraph, the Mashup embedding vector and the API embedding vector is aggregated by a hypergraph neural network, and the order of aggregation is controlled by setting the number of layers to obtain Mashup vectors and API vectors under each layer number;
[0023] The Mashup vectors and the API vectors are summed to obtain the initial Mashup feature vector and the initial API feature vector.
[0024] Optionally, the error of the initial predicted score is calculated by the total loss function to obtain a target Mashup feature vector and a target API feature vector, and the target Mashup feature vector and the target API feature vector are calculated by dot product to obtain a target predicted score, and the Mashup is recommended according to the target predicted score API, comprising:
[0025] The Mashup information and the API information are obtained by twice random edge discarding operation to obtain a Mashup first relationship matrix, a Mashup second relationship matrix, an API first relationship matrix and an API second relationship matrix;
[0026] Based on the Mashup first relationship matrix, the Mashup second relationship matrix, the API first relationship matrix and the API second relationship matrix, the Mashup first feature vector, the Mashup second feature vector, the API first feature vector and the API second feature vector are obtained by processing;
[0027] Based on the Mashup first feature vector, the Mashup second feature vector, the API first feature vector and the API second feature vector, the total loss function is calculated;
[0028] error calculation is performed on the initial Mashup feature vector, the initial API feature vector, the Mashup first feature vector, the Mashup second feature vector, the API first feature vector and the API second feature vector through the overall loss function, to obtain a target Mashup feature vector and a target API feature vector;
[0029] Point product calculation is performed on the target Mashup feature vector and the target API feature vector to obtain a target prediction score of Mashup to API, and API recommendation is performed on Mashup according to the target prediction score.
[0030] Optionally, the calculation of the overall loss function based on the Mashup first feature vector, the Mashup second feature vector, the API first feature vector and the API second feature vector comprises:
[0031] Point product operation is performed on the initial Mashup feature vector and the initial API feature vector to obtain an initial prediction score;
[0032] Based on the initial prediction score, a Bayesian loss is calculated;
[0033] Calculation is performed on the Mashup first feature vector and the Mashup second feature vector to obtain a Mashup contrast loss;
[0034] Calculation is performed on the API first feature vector and the API second feature vector to obtain an API contrast loss;
[0035] Calculation is performed on the Bayesian loss, the Mashup contrast loss and the API contrast loss to obtain the overall loss function.
[0036] Optionally, in the step of calculating the overall loss function based on the initial prediction score, the intermediate prediction score, the Mashup contrast loss and the API contrast loss, the calculation formula of the overall loss function is:
[0037]
[0038] wherein, the overall loss is, the Bayesian loss is, the Mashup contrast loss is, the API contrast loss is, and λ2 is a hyperparameter for controlling the proportion of the Mashup contrast loss and the API contrast loss.
[0039] In another aspect, the embodiment of the present application also provides a network API recommendation device based on hypergraph contrast learning, comprising:
[0040] The first module is configured to acquire Mashup information, API information, and interaction information between the Mashup and the API.
[0041] The second module is configured to construct a heterogeneous hypergraph between the Mashup and the API according to the Mashup information, the API information, and the interaction information, to obtain an initial Mashup heterogeneous hypergraph and an initial API heterogeneous hypergraph.
[0042] The third module is configured to convert the Mashup information and the API information into a Mashup embedding vector and an API embedding vector.
[0043] The fourth module is configured to obtain an initial Mashup feature vector and an initial API feature vector through hypergraph neural network aggregation and summation based on the initial Mashup heterogeneous hypergraph, the initial API heterogeneous hypergraph, the Mashup embedding vector, and the API embedding vector.
[0044] The fifth module is configured to perform dot product operation on the initial Mashup feature vector and the initial API feature vector to obtain an initial prediction score of the Mashup to the API.
[0045] The sixth module is configured to perform error calculation on the initial prediction score through a total loss function to obtain a target Mashup feature vector and a target API feature vector, to perform dot product calculation on the target Mashup feature vector and the target API feature vector to obtain a target prediction score, and to perform API recommendation for the Mashup according to the target prediction score.
[0046] In another aspect, an electronic device is also provided, which includes a processor and a memory; the memory is configured to store a program; and the processor is configured to execute the program to implement a network API recommendation method based on hypergraph contrast learning.
[0047] In another aspect, a computer readable storage medium is also provided, which stores a program; and the program is executed by a processor to implement a network API recommendation method based on hypergraph contrast learning.
[0048] The embodiments of the present application also disclose a computer program product or a computer program, which comprises computer instructions stored in a computer readable storage medium. A processor of a computer device can read the computer instructions from the computer readable storage medium, and the processor executes the computer instructions to enable the computer device to perform the foregoing method.
[0049] The embodiments of the present application at least have the following beneficial results: the embodiments of the present application can aggregate higher-order neighbor information through the heterogeneous hypergraph, avoid the occurrence of over-smoothing phenomenon, solve the sparsity problem of historical interaction records between Mashup and API, and improve the accuracy of recommendation by constructing an initial Mashup heterogeneous hypergraph and an initial API heterogeneous hypergraph; the embodiments of the present application calculate the error of the initial prediction score through the overall loss function, obtain a target Mashup feature vector and a target API feature vector, perform dot product calculation on the target Mashup feature vector and the target API feature vector to obtain a target prediction score, and recommend API to Mashup according to the target prediction score, which is beneficial to model training and parameter updating and improves the accuracy of recommendation. BRIEF DESCRIPTION OF DRAWINGS
[0050] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings needed in the embodiment description will be briefly introduced. Obviously, the drawings in the following description are only some embodiments of the present application, and other drawings can be obtained by those skilled in the art without creative labor.
[0051] Figure 1 A flowchart of a network API recommendation method based on hypergraph contrast learning provided by the embodiments of the present application;
[0052] Figure 2 An example graph of constructing a heterogeneous graph for a network API recommendation method based on hypergraph contrast learning provided by the embodiments of the present application;
[0053] Figure 3 A model structure diagram of a network API recommendation method based on hypergraph contrast learning provided by the embodiments of the present application;
[0054] Figure 4 A schematic diagram of a network API recommendation device based on hypergraph contrast learning provided by the embodiments of the present application. DETAILED DESCRIPTION
[0055] In order to make the purposes, technical solutions and advantages of the present application clearer, the present application will be further described in detail below with reference to the drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and do not limit the present application.
[0056] In one aspect, the embodiments of the present application provide a network API recommendation method based on hypergraph contrast learning, referring to Figure 1 , the method includes but is not limited to steps S100-S600:
[0057] S100: Obtain Mashup information, API information, and interaction information between Mashup and API.
[0058] Optionally, the API (Application Programming Interface) provides an interface for connecting different parts of a software system or different software systems. More and more enterprises release their core functions or data through APIs for third-party calls; Mashup is a lightweight API combination technology that allows non-professional programmers to easily use APIs to develop Web applications, which are also called Mashup applications. In an embodiment of the present application, Mashup information, API information, and heterogeneous information related to Mashup and API are obtained from a network API portal website (Programmableweb.com). The heterogeneous information includes Mashup category information, API category information, and API provider information; an embodiment of the present application uses the calling relationship of Mashup to API on ProgrammableWeb as the interaction relationship.
[0059] S200: Construct a heterogeneous hypergraph of Mashup and API according to the Mashup information, the API information, and the interaction information, to obtain an initial Mashup heterogeneous hypergraph and an initial API heterogeneous hypergraph.
[0060] Optionally, five entity types are obtained according to the Mashup information, the API information, and the interaction information between Mashup and API. The five entity types include Mashup, API, Mashup category, API category, and API provider.
[0061] Optionally, four entity relationships are obtained according to the five entity types. The four entity relationships include a calling relationship between Mashup and API, a belonging relationship between Mashup and Mashup category, a belonging relationship between API and API category, and a providing relationship between API and API provider.
[0062] Optionally, the initial Mashup heterogeneous hypergraph and the initial API heterogeneous hypergraph are constructed according to the five entity types and the four entity relationships. As shown in the following formula (1), the initial Mashup heterogeneous hypergraph G Figure 2 is constructed according to the four entity relationships. ma ∈R M×N , R mc ∈R M ×C, R ac ∈R N×D and R ap ∈R N×P where M, N, C, D, P represent the total number of Mashup, API, Mashup category, API category and API provider respectively, R ma represents the relationship matrix between Mashup and API, R mc represents the relationship matrix between Mashup and Mashup category, R ac represents the relationship matrix between API and API category, R ap represents the relationship matrix between API and API provider, the values of these relationship matrices are only 0 and 1, and 1 indicates that there is a relationship, and 0 indicates that there is no relationship. Then, the heterogeneous hypergraphs of Mashup and API are constructed according to the above relationship matrices, and the calculation formula of the construction process is as follows:
[0063] R m = R ma || R mc ∈R M×(N+C)
[0064]
[0065]
[0066]
[0067] where R m is the initial relationship matrix related to Mashup, R a is the initial relationship matrix related to API, and are the diagonal matrices of nodes and hyperedges in R m relationship matrix. The diagonal matrix is a kind of diagonal matrix, and the values on the diagonal line are determined by the degree, which represents the total number of connections, the degree of the node represents how many hyperedges the node is located in, and the degree of the hyperedge represents how many nodes the hyperedge contains. and are the diagonal matrices of nodes and hyperedges in R a relationship matrix. A m is the heterogeneous hypergraph related to Mashup, and A a is the heterogeneous hypergraph related to API.
[0068] S300: converting the Mashup information and the API information into Mashup embedding vectors and API embedding vectors.
[0069] Optionally, in one embodiment of the present application, asFigure 3 As shown, Mashup information and API information are converted into Mashup embedding vectors and API embedding vectors by the embedding layer of deep learning. First, the names of Mashups and the names of APIs are identified by numbers, and an embodiment of the present application uses the ID number (1, 2,...) to identify Mashups and APIs; then the embedding layer is used to map and convert the numbers into embedding vectors to obtain Mashup embedding vectors and API embedding vectors. The embedding layer can convert discrete input data into continuous feature vectors, thereby better performing model training and prediction. An embodiment of the present application converts the Mashup and API numbers ID into continuous and dense embedding vector matrices in a low-dimensional space through the embedding layer in deep learning, that is, different Mashups and APIs are each converted into a corresponding embedding vector for representation. Each Mashup m is mapped into an embedding vector e m ∈R d where d represents the dimension of the embedding vector; each API a is mapped into an embedding vector e a ∈R d where d represents the dimension of the embedding vector. The embedding vector matrix can be regarded as a lookup table of embedding vectors:
[0070]
[0071] where E∈R (M+N)×d is the embedding vector matrix, represents the Mashup embedding vector corresponding to the No. 1 Mashup, represents the Mashup embedding vector corresponding to the No. M Mashup. represents the API embedding vector corresponding to the No. 1 API, represents the API embedding vector corresponding to the No. N API.
[0072] S400: Based on the initial Mashup heterogeneous hypergraph, the initial API heterogeneous hypergraph, the Mashup embedding vector, and the API embedding vector, an initial Mashup feature vector and an initial API feature vector are obtained by hypergraph neural network aggregation and summation.
[0073] Optionally, first, the neighbor information of the nodes of the initial Mashup heterogeneous hypergraph, the initial API heterogeneous hypergraph, the Mashup embedding vector and the API embedding vector is aggregated by a hypergraph neural network, the order of aggregation is controlled by setting the number of layers, and the Mashup vector and the API vector under each layer number are obtained; then the Mashup vector and the API vector are summed to obtain an initial Mashup feature vector and an initial API feature vector.
[0074] Optionally, an embodiment of the present application Mashup hypergraph A m and API hypergraph A a , Mashup embedding vector e m and API embedding vector e a , the neighbor information of the nodes is aggregated by a hypergraph neural network, the order of aggregation is controlled by setting the number of layers L, and the Mashup vector and the API vector under each layer number are obtained; then the Mashup vector and the API vector are summed to obtain an initial Mashup feature vector and an initial API feature vector, and the calculation formula of the aggregation and summation process is:
[0075]
[0076]
[0077]
[0078]
[0079] Wherein, L represents the number of layers of neighbor information to be aggregated, represents the (l+1)th layer Mashup vector, which is obtained by neighbor aggregation and updating of the lth layer Mashup vector and hypergraph A m , represents the (l+1)th layer API vector, which is obtained by neighbor aggregation and updating of the lth layer API vector and hypergraph A a , m represents the initial Mashup feature vector, and e a represents the initial API feature vector.
[0080] S500: Dot product operation is performed on the initial Mashup feature vector and the initial API feature vector to obtain an initial prediction score of Mashup to API.
[0081] Optionally, an embodiment of the present application performs dot product operation on the initial Mashup feature vector and the initial API feature vector to obtain an initial prediction score of Mashup to API, and the calculation formula of the dot product operation is:
[0082]
[0083] wherein, is an initial prediction score, is a transposed vector of the initial Mashup feature vector, e a represents an initial API feature vector.
[0084] S600: error calculation on the initial prediction score by a total loss function, to obtain a target Mashup feature vector and a target API feature vector, dot product calculation on the target Mashup feature vector and the target API feature vector to obtain a target prediction score, API recommendation to a Mashup according to the target prediction score.
[0085] Optionally, step S600 includes but is not limited to steps S610-S650:
[0086] S610: Mashup information and API information are obtained through twice random edge discarding operations to obtain a Mashup first relationship matrix, a Mashup second relationship matrix, an API first relationship matrix and an API second relationship matrix.
[0087] Optionally, the random edge discarding operation is to multiply the initial relationship matrix R m and R a by a mask matrix composed of only 0 and 1 randomly, so that the position of the relationship matrix with 1 may be multiplied by 0 to become 0, indicating that the edge relationship does not exist, and then discarded, and the position of the original relationship matrix with 0 remains 0 regardless of multiplication by 1 or 0, and then retained. Through the random edge discarding operation on the original relationship edge, a disturbed relationship matrix, i.e., a Mashup first relationship matrix and an API first relationship matrix
[0088] Optionally, the calculation formula of the random edge discarding operation is:
[0089]
[0090]
[0091] wherein, is a Mashup first relationship matrix, is an API first relationship matrix, R m is an initial relationship matrix related to the Mashup, R a is an initial relationship matrix related to the API, M1∈R M×(N+C) and M2∈R N×(M+D+P) is a mask matrix composed of 0 and 1 randomly, and is an element product operation.
[0092] S620: obtaining Mashup first feature vector, Mashup second feature vector, API first feature vector and API second feature vector by processing based on the Mashup first relationship matrix, the Mashup second relationship matrix, the API first relationship matrix and the API second relationship matrix.
[0093] Optionally, Mashup first feature vector, Mashup second feature vector, API first feature vector and API second feature vector are obtained by processing based on the Mashup first relationship matrix, the Mashup second relationship matrix, the API first relationship matrix and the API second relationship matrix.
[0094] S630: obtaining overall loss function based on the Mashup first feature vector, the Mashup second feature vector, the API first feature vector and the API second feature vector.
[0095] Optionally, step S630 includes but is not limited to steps S631-S635:
[0096] S631: performing dot product operation on initial Mashup feature vector and initial API feature vector to obtain initial prediction score.
[0097] Optionally, dot product operation is performed on initial Mashup feature vector and initial API feature vector to obtain initial prediction score.
[0098] S632: obtaining Bayesian loss by calculation based on the initial prediction score.
[0099] Optionally, the calculation formula of Bayesian loss is:
[0100]
[0101] wherein, Bayesian loss, initial prediction score, non-interaction prediction score, O = {(m, a, a') | (m, a) ∈ R + ,(m, a') ∈ R -} is a training data set, R + represents observable interaction data, R - represents unobservable interaction data. σ(·) is a sigmoid activation function, Θ refers to all trainable model parameters, and λ1 is a hyperparameter used to control regularization to prevent model overfitting.
[0102] S633: Calculate the Mashup first feature vector and the Mashup second feature vector to obtain a Mashup contrast loss.
[0103] Optionally, the calculation formula of the Mashup contrast loss is:
[0104]
[0105] wherein, is the Mashup contrast loss, s(·) is a cosine similarity function, τ is a temperature hyperparameter, e′ m is the Mashup first feature vector, e″ m is the Mashup second feature vector, e″ m′ is the second feature vector of the remaining Mashups.
[0106] S634: Calculate the API first feature vector and the API second feature vector to obtain an API contrast loss.
[0107] Optionally, the calculation formula of the API contrast loss is:
[0108]
[0109] wherein, is the API contrast loss, s(·) is a cosine similarity function, τ is a temperature hyperparameter, e′ a is the API first feature vector, e″ a is the API second feature vector, e″ a′ is the second feature vector of the remaining APIs.
[0110] S635: Calculate the Bayesian loss, the Mashup contrast loss and the API contrast loss to obtain a total loss function.
[0111] Optionally, the calculation formula of the total loss function is:
[0112]
[0113] wherein, is the total loss, is the Bayesian loss, is the Mashup contrast loss, is the API contrast loss, and λ2 is a hyperparameter for controlling the proportion of the Mashup contrast loss and the API contrast loss.
[0114] S640: error calculation is performed on the initial Mashup feature vector, the initial API feature vector, the Mashup first feature vector, the Mashup second feature vector, the API first feature vector and the API second feature vector through the overall loss function, to obtain a target Mashup feature vector and a target API feature vector.
[0115] Optionally, the model parameters of Θ are updated based on the overall loss function, and each parameter is updated by calculating the gradient of the error for the parameter, and the calculation formula for the update is:
[0116]
[0117]
[0118] where w and b are examples of parameters in Θ, the parameters are updated by calculating the gradient of the error for the parameters, so as to update the original parameters w and b, and the above process is repeatedly repeated until the error gradually decreases to be stable, at which time the parameters constitute the final model, and η represents a learning rate for controlling the magnitude of the parameter update.
[0119] S650: point product calculation is performed on the target Mashup feature vector and the target API feature vector to obtain a target prediction score of Mashup to API, and API recommendation is performed for Mashup according to the target prediction score.
[0120] Optionally, point product calculation is performed on the target Mashup feature vector and the target API feature vector to obtain a target prediction score of Mashup to API, and API recommendation is performed for Mashup according to the target prediction score.
[0121] Below, an application of a network API recommendation method based on hypergraph contrast learning is introduced through an embodiment of the application:
[0122] 1. First, Mashup information, API information and interaction information between Mashup and API are obtained; a heterogeneous hypergraph of Mashup and API is constructed according to the Mashup information, the API information and the interaction information, to obtain an initial Mashup heterogeneous hypergraph and an initial API heterogeneous hypergraph;
[0123] 2. Then, the Mashup information and the API information are converted into Mashup embedding vectors and API embedding vectors; initial Mashup feature vectors and initial API feature vectors are obtained by hypergraph neural network aggregation and summation based on the initial Mashup heterogeneous hypergraph, the initial API heterogeneous hypergraph, the Mashup embedding vectors and the API embedding vectors;
[0124] 3、Finally, the initial Mashup feature vector and the initial API feature vector are dot product operation to obtain the initial prediction score of Mashup to API, the initial prediction score is error calculation through the overall loss function to obtain the target Mashup feature vector and the target API feature vector, the target Mashup feature vector and the target API feature vector are dot product calculation to obtain the target prediction score, and Mashup is recommended to API according to the target prediction score.
[0125] In summary, the network API recommendation method based on hypergraph contrast learning of the embodiment has the following advantages:
[0126] 1、The embodiment constructs the initial Mashup heterogeneous hypergraph and the initial API heterogeneous hypergraph, can aggregate higher-order neighbor information through the heterogeneous hypergraph, avoids the occurrence of over-smoothing phenomenon, solves the sparsity problem of historical interaction records between Mashup and API, and improves the accuracy of recommendation.
[0127] 2、The embodiment calculates the error of the initial prediction score through the overall loss function to obtain the target prediction score, and recommends API to Mashup according to the target prediction score, which is beneficial to model training and parameter updating, and also improves the accuracy of recommendation.
[0128] 3、The embodiment combines five entity types and four entity relationships, captures the association relationship between Mashup and API, and integrates these relationships into the vector representation of Mashup and API to improve the accuracy of recommendation.
[0129] 4、The embodiment uses the contrast learning method to enhance the learning of the graph nodes of the Mashup and API hypergraph through the first and second feature vectors, so that the vectors learned by the same node on different graphs are as similar as possible, and the vectors of different nodes are as different as possible. It is essentially a loss function, which is beneficial to model training and parameter updating.
[0130] On the other hand, as shown in the figure, the embodiment also provides a network API recommendation device based on hypergraph contrast learning, comprising: Figure 4 The first module 401 is used for acquiring Mashup information, API information and interaction information between Mashup and API.
[0131]
[0132] The second module 402 is configured to construct a heterogeneous hypergraph between the Mashup and the API according to the Mashup information, the API information and the interaction information, to obtain an initial Mashup heterogeneous hypergraph and an initial API heterogeneous hypergraph.
[0133] The third module 403 is configured to convert the Mashup information and the API information into a Mashup embedding vector and an API embedding vector.
[0134] The fourth module 404 is configured to obtain an initial Mashup feature vector and an initial API feature vector by hypergraph neural network aggregation and summation based on the initial Mashup heterogeneous hypergraph, the initial API heterogeneous hypergraph, the Mashup embedding vector and the API embedding vector.
[0135] The fifth module 405 is configured to perform dot product operation on the initial Mashup feature vector and the initial API feature vector to obtain an initial prediction score of the Mashup to the API.
[0136] The sixth module 406 is configured to perform error calculation on the initial prediction score by a total loss function to obtain a target Mashup feature vector and a target API feature vector, to perform dot product calculation on the target Mashup feature vector and the target API feature vector to obtain a target prediction score, and to perform API recommendation for the Mashup according to the target prediction score.
[0137] In another aspect, the embodiment of the present application further provides an electronic device, including a processor and a memory; the memory is used to store a program; the processor executes the program to realize a network API recommendation method based on hypergraph contrast learning.
[0138] In another aspect, the embodiment of the present application further provides a computer readable storage medium, the storage medium stores a program, and the program is executed by a processor to realize a network API recommendation method based on hypergraph contrast learning.
[0139] The embodiment of the present application further discloses a computer program product or a computer program, which comprises computer instructions stored in a computer readable storage medium. A processor of a computer device can read the computer instructions from the computer readable storage medium, and the processor executes the computer instructions to enable the computer device to execute the method shown in the embodiment of the present application. Figure 1 The method shown in the embodiment of the present application.
[0140] In some alternative embodiments, the function / operations mentioned in the block diagrams can not occur in the order mentioned in the operational illustrations. For example, depending on the involved function / operation, two blocks shown in succession can in fact be executed substantially concurrently or the blocks can sometimes be executed in reverse order, depending upon the functionality / operations involved. Furthermore, embodiments presented and described in the flowcharts are only examples of implementing the present application. Alternative embodiments are possible where functions described as portions of independent operations are implemented as a combined operation or functions described as a combined operation are implemented as separate operations. The flowcharts can also represent code segments when executed that provide the processes described and / or illustrated therein. Alternatively, the flowcharts can also represent program steps in a procedural, object-oriented, or other programming language object- oriented programming language.
[0141] Furthermore, although the present application is described in the context of functional modules, it is understood that one or more of the functions and / or features described can be integrated in a single physical device and / or software module, or one or more functions and / or features can be implemented in separate physical devices or software modules. It is also understood that detailed discussion of the actual implementation of each module is unnecessary to an understanding of the present application. Rather, the actual implementation is within the routine skill of engineers familiar with the attributes, functions, and internal relationships of the various functional modules disclosed herein. Accordingly, the present application is not limited to the implementations illustrated herein but is intended to be limited only by the claims attached hereto and by their equivalents. It is understood that the specific order or hierarchy of functions and / or features described in the specification is an example and can be performed in any other order or hierarchy.
[0142] The functions described can be implemented in software, firmware, or hardware. The functions can be created in or transferred to a computer-readable storage medium, such as a floppy disk, a CD-ROM, an optical disk, or a hard disk or magnetic tape, having a computer-readable program code embodied in the medium. The computer-readable program code can be downloaded from an Internet location or from a server or other remote source using a computer network or a data transmission link. Alternatively, the computer-readable program code can be embodied in a storage medium as described above. Further, the functions described can be implemented in a distributed computing environment, where functions or components of a program or applications are located in both a central computer storage medium and in a client storage medium. Furthermore, the source code for the software implemented by the present application can conveniently be presented in a source code format called the Java® programming language by Sun Microsystems, Inc. of Santa Clara, California, or in a source code format called the C++ programming language by the Microsoft Corporation of Redmond, Washington. The software implemented by the present application can be any combination of semantically interoperable abstract computer processes and objects, including structured queries, rules, constraints, and machine learning algorithms.
[0143] The logic and / or steps represented in the flowcharts and / or described herein, for example, can be embodied in non-transitory computer-readable media, executed by one or more computing devices, and / or in any other way. The logic and / or steps represented in the flowcharts and / or described herein, for example, can be considered a list of executable instructions for implementing logic functions, and can be embodied in any computer-readable medium for use by or in connection with an instruction execution system, apparatus, or device, such as a computer-based system, processor- containing system, or other system that can fetch the instructions from the instruction execution system, apparatus, or device and execute the instructions. For purposes of this specification, a "computer-readable medium" can be any apparatus that can contain, store, communicate, propagate, or transport the program for use by or in connection with the instruction execution system, apparatus, or device. The computer-readable medium can be, for example but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device. More specific examples (a non-exhaustive list) of the computer-readable medium include the following: an electrical connection (electronic) having one or more wires, a portable computer diskette (magnetic), a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or Flash memory), an optical fiber (optical), and a portable compact disc read-only memory (CDROM). Additionally, the computer-readable medium can even be paper or another suitable medium upon which the program is printed, as the program can be electronically captured, for example via an optical scanner, then compiled, interpreted, or otherwise processed, and stored in a computer memory in a form that can be later executed by a computer. In this context, a "computer-readable medium" can be any means that can store the program for use by or in connection with the instruction execution system, apparatus, or device.
[0144] The foregoing description of various embodiments of the application has been presented for the purposes of illustration and description. It is not intended to be exhaustive or to limit the application to the precise form disclosed, and various modifications and variations are possible in light of the above teachings. It is intended that the scope of the application be limited not with this detailed description, but rather by the claims appended hereto.
[0145] It should be understood that aspects of the application can be implemented in hardware, software, firmware or combinations thereof. In the above embodiments, various steps or methods can be implemented, for example, by software or firmware stored in memory and executed by a suitable instruction execution system. For example, if implemented in hardware, and in another embodiment, any of the following can be used: discrete logic circuitry, application specific integrated circuits (ASICs), programmable gate arrays (PGAs), field programmable gate arrays (FPGAs), and / or the like.
[0146] In the description of the specification, the description of the terms "one embodiment", "some embodiments", "an example", "a specific example", or "some examples" and the like means that the particular feature, structure, material, or characteristic being described is included in at least one embodiment or example of the application. The illustrative examples described in this specification are not meant to be exhaustive or limiting. The terms "one embodiment", "some embodiments", "an example", "a specific example", or "some examples" and the like are intended to mean that the particular feature, structure, material, or characteristic being described is included in at least one embodiment or example of the application. The illustrative examples described in this specification are not meant to be exhaustive or limiting.
[0147] While the embodiments of the application have been shown and described, it is to be understood that the embodiments described are merely exemplary and are not to be taken as limiting the scope of the application. The scope of the application is defined by the claims and their equivalents.
[0148] The above is a specific description of the preferred embodiment of the present application, but the present application is not limited to the described embodiment, and those skilled in the art can make various equivalent modifications or replacements without departing from the spirit of the present application, and these equivalent modifications or replacements are all included in the scope defined by the claims of the present application.
Claims
1. A network API recommendation method based on hypergraph contrastive learning, characterized in that, include: Retrieve Mashup information, API information, and interaction information between Mashup and API; Based on the Mashup information, the API information, and the interaction information, construct a heterogeneous hypergraph of Mashup and API to obtain an initial Mashup heterogeneous hypergraph and an initial API heterogeneous hypergraph. Convert the Mashup information and the API information into Mashup embedding vectors and API embedding vectors; Based on the initial Mashup heterogeneous hypergraph, the initial API heterogeneous hypergraph, the Mashup embedding vector, and the API embedding vector, the initial Mashup feature vector and the initial API feature vector are obtained by aggregation and summation through a hypergraph neural network. Perform a dot product operation on the initial Mashup feature vector and the initial API feature vector to obtain the initial prediction score of the Mashup for the API; The initial prediction score is calculated using the overall loss function to obtain the target Mashup feature vector and the target API feature vector. The target prediction score is obtained by performing a dot product on the target Mashup feature vector and the target API feature vector. API recommendations are then made to the Mashup based on the target prediction score. The process of aggregating and summing the initial Mashup feature vector and initial API feature vector based on the initial Mashup heterogeneous hypergraph, the initial API heterogeneous hypergraph, the Mashup embedding vector, and the API embedding vector through a hypergraph neural network, includes: The neighbor information of the nodes of the initial Mashup heterogeneous hypergraph, the initial API heterogeneous hypergraph, the Mashup embedding vector, and the API embedding vector is aggregated by a hypergraph neural network. The order of aggregation is controlled by setting the number of layers to obtain the Mashup vector and API vector at each layer. Summing the Mashup vector and the API vector yields the initial Mashup feature vector and the initial API feature vector; The process involves calculating the error of the initial prediction score using the overall loss function to obtain the target Mashup feature vector and the target API feature vector. The target prediction score is then calculated by performing a dot product between the target Mashup feature vector and the target API feature vector. Finally, API recommendations are made to the Mashup based on the target prediction score. By performing two random edge discarding operations on the Mashup information and API information, we obtain the first Mashup relation matrix, the second Mashup relation matrix, the first API relation matrix, and the second API relation matrix; Based on the Mashup first relation matrix, the Mashup second relation matrix, the API first relation matrix, and the API second relation matrix, the Mashup first feature vector, the Mashup second feature vector, the API first feature vector, and the API second feature vector are obtained through processing. Based on the first feature vector of the Mashup, the second feature vector of the Mashup, the first feature vector of the API, and the second feature vector of the API, the overall loss function is calculated. The overall loss function is used to calculate the error of the initial Mashup feature vector, the initial API feature vector, the first Mashup feature vector, the second Mashup feature vector, the first API feature vector, and the second API feature vector to obtain the target Mashup feature vector and the target API feature vector. The target Mashup feature vector and the target API feature vector are multiplied by a dot product to obtain the target prediction score of the Mashup for the API. The Mashup is then used to recommend APIs based on the target prediction score. The overall loss function is calculated based on the Mashup first feature vector, the Mashup second feature vector, the API first feature vector, and the API second feature vector, including: The initial prediction score is obtained by performing a dot product operation between the initial Mashup feature vector and the initial API feature vector. Based on the initial prediction score, the Bayesian loss is calculated. The Mashup contrast loss is obtained by calculating the first feature vector and the second feature vector of the Mashup. The API contrast loss is obtained by calculating the first feature vector and the second feature vector of the API. The Bayesian loss, the Mashup contrastive loss, and the API contrastive loss are calculated to obtain the overall loss function. The formula for the overall loss function is as follows: in, For the total loss, For Bayesian loss, For Mashup comparison loss, For API comparison loss, This is a hyperparameter used to control the proportion of Mashup contrast loss and API contrast loss.
2. The network API recommendation method based on hypergraph contrastive learning according to claim 1, characterized in that, The step of constructing a heterogeneous hypergraph of Mashup and API based on the Mashup information, the API information, and the interaction information to obtain an initial Mashup heterogeneous hypergraph and an initial API heterogeneous hypergraph includes: Based on the Mashup information, the API information, and the interaction information between the Mashup and the API, five entity types are obtained, including: Mashup, API, Mashup category, API category, and API provider. Based on the five entity types, four entity relationships are derived, which include: a calling relationship between Mashup and API; a belonging relationship between Mashup and Mashup category; a belonging relationship between API and API category; and a providing relationship between API and API provider. Based on the five entity types and the four entity relationships, construct the initial Mashup heterogeneous hypergraph and the initial API heterogeneous hypergraph.
3. The network API recommendation method based on hypergraph contrastive learning according to claim 1, characterized in that, The step of converting the Mashup information and the API information into Mashup embedding vectors and API embedding vectors includes: Identify the Mashup name and the API name using numbers; The number mapping is converted into an embedding vector through the embedding layer, resulting in a Mashup embedding vector and an API embedding vector.
4. An apparatus for implementing the network API recommendation method based on hypergraph contrastive learning as described in any one of claims 1-3, characterized in that, include: The first module is used to obtain Mashup information, API information, and interaction information between Mashup and API. The second module is used to construct a heterogeneous hypergraph between Mashup and API based on the Mashup information, the API information and the interaction information, so as to obtain an initial Mashup heterogeneous hypergraph and an initial API heterogeneous hypergraph. The third module is used to convert the Mashup information and the API information into Mashup embedding vectors and API embedding vectors; The fourth module is used to aggregate and sum the initial Mashup feature vector and the initial API feature vector based on the initial Mashup heterogeneous hypergraph, the initial API heterogeneous hypergraph, the Mashup embedding vector and the API embedding vector through a hypergraph neural network to obtain the initial Mashup feature vector and the initial API feature vector. The fifth module is used to perform a dot product operation on the initial Mashup feature vector and the initial API feature vector to obtain the initial prediction score of the Mashup for the API. The sixth module is used to calculate the error of the initial prediction score through the overall loss function, obtain the target Mashup feature vector and the target API feature vector, calculate the target prediction score by performing a dot product of the target Mashup feature vector and the target API feature vector, and make API recommendations to the Mashup based on the target prediction score.
5. An electronic device, characterized in that, Including the processor and memory; The memory is used to store programs; The processor executes the program to implement the method as described in any one of claims 1 to 3.
6. A computer-readable storage medium, characterized in that, The storage medium stores a program that is executed by a processor to implement the method as described in any one of claims 1 to 3.