Web api recommendation method based on semantic enhancement and self-supervised graph learning
Patent Information
- Application Number
- CN202610957791.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-06-30
- Publication Date
- 2026-08-18
AI Technical Summary
此前的方法尝试通过增强文本特征提取以缓解此问题,但纯文本表示与功能语义之间存在语义鸿沟,使得孤立节点难以有效融入异构网络,阻碍了从信息网络中学习有价值的潜在信号
(1)本发明通过局部-全局语义融合编码器,从两个路径分别对Mashup和API的功能描述文本进行编码:在局部特征提取路径中,采用多尺度一维卷积层以不同窗口大小对嵌入矩阵进行卷积操作,并通过全局最大池化提取各尺度下最显著的局部短语模式;在全局特征提取路径中,通过Transformer编码器的多头自注意力层捕获整个描述文本中的长程依赖关系和全局上下文语义。将局部特征与全局特征拼接后投影到公共潜在空间,使各节点的初始语义特征同时蕴含关键短语信息和整体语义信息,能够有效应对文本信息不充分场景下的语义抽取需求,缓解了纯文本表示与功能语义之间的语义鸿沟,从而提高了后续推荐过程中语义匹配的准确性和可靠性。
Smart Images

Figure CN122594595A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of intelligent recommendation technology, and in particular to a Web API recommendation method based on semantic enhancement and self-supervised graph learning. Background Technology
[0002] Modern software engineering widely adopts distributed architectures such as service-oriented architecture. Web APIs, as the primary communication mechanism between services, facilitate data interoperability and function calls through standardized protocols, thereby accelerating the development of web applications. The continuous emergence of Web APIs has driven the prosperity of API sharing platforms, making the release, promotion, and evaluation of numerous service repositories possible. Against this backdrop, Mashup development has become a popular service composition paradigm, where developers aggregate the functionality of multiple third-party Web APIs to build customized applications. However, with the vast number of available Web APIs, accurately matching candidate APIs with the functional requirements of a Mashup has become a significant challenge for developers. Therefore, recommending Web APIs for Mashups has become a critical requirement.
[0003] Currently, recommendation methods for Mashups and Web APIs can be mainly divided into three categories. The first category is content-based methods, which focus on text semantic matching and typically apply natural language processing techniques such as topic modeling to extract features from Mashup requests and API descriptions. However, these methods usually only learn local semantic relationships and perform poorly when textual information is insufficient. The second category is interaction-based methods, which utilize historical call data to make recommendations through collaborative filtering models, such as matrix factorization and factorization machines. These methods uncover potential interaction patterns or capture high-order feature relationships, but their performance is sensitive to data density and often fails under conditions of sparse interaction data. The third category is graph-based methods, which model Mashups and APIs as information networks and extract structural semantics from these representations based on graph neural networks. Some recent studies have enhanced node representations by constructing heterogeneous information networks.
[0004] While the aforementioned methods have contributed to the development of Web API recommendation technology, existing research still faces several key challenges. Firstly, there are the issues of data sparsity and noise. Although heterogeneous networks can be constructed using Mashups, APIs, or categories to represent higher-order relationships, in sparse data scenarios, the constructed network structure often introduces a large number of edges or node connections unrelated to core functionalities. This structural noise masks stable functional relationships between entities, reducing the accuracy of interaction pattern recognition. Secondly, there is the cold-start dilemma of Mashups. Mashups to be created appear as isolated nodes in heterogeneous networks, structurally isolated due to a lack of historical call records. Previous methods attempted to alleviate this problem by enhancing text feature extraction, but a semantic gap exists between pure text representation and functional semantics, making it difficult for isolated nodes to effectively integrate into heterogeneous networks and hindering the learning of valuable potential signals from information networks. Therefore, how to effectively suppress structural noise caused by sparse interactions while alleviating the cold-start Mashup recommendation dilemma to improve the accuracy and ranking quality of Web API recommendations is a technical problem that needs to be solved. Summary of the Invention
[0005] The purpose of this invention is to overcome the shortcomings of the existing technology and provide a Web API recommendation method based on semantic enhancement and self-supervised graph learning. It generates initial semantic representations through a local-global semantic fusion encoder, decouples heterogeneous information networks into attribute views and interaction views, and designs a dual-view mask autoencoder to perform self-supervised learning for mask reconstruction to suppress structural noise. At the same time, for cold-start Mashups, it performs structural completion and neighborhood aggregation to inject interaction modes through semantic neighbor retrieval, thereby improving the accuracy and ranking quality of Web API recommendations under sparse and cold-start conditions.
[0006] The objective of this invention can be achieved through the following technical solutions: According to one aspect of the present invention, a Web API recommendation method based on semantic enhancement and self-supervised graph learning is provided, the specific steps of which include: S1. Obtain Mashup data, API data, and category data. The Mashup data includes the functional description text of the Mashup, and the API data includes the functional description text of the API. Based on the historical call relationship between the Mashup and the API data, and the attribute relationship between the Mashup, API, and category, construct a heterogeneous information network. Perform fusion encoding of local semantics and global semantics on the functional description text to obtain the initial semantic feature representation of each node. S2. Decouple the heterogeneous information network into an attribute view and an interaction view, perform graph attention propagation in the attribute view and the interaction view respectively, and perform self-supervised learning of mask reconstruction on the attribute view and the interaction view respectively during the training process, and obtain Mashup node representation and API node representation based on self-supervised loss. S3. For cold-start Mashup nodes, retrieve semantic neighbors based on the initial semantic feature representation, use the category connection of the semantic neighbors to complete the structure of the attribute view, and aggregate the graph representation of the semantic neighbors into the representation of the target Mashup node to obtain the enhanced Mashup representation. S4. Calculate the predicted call probability based on the enhanced Mashup representation and the API node representation, and output the API recommendation list based on the predicted call probability.
[0007] Furthermore, the specific steps of S1 include: Based on the collected Mashup data, API data, and category data, define Mashup sets, API sets, and category sets respectively; each element in the Mashup set is associated with a function description text, the set of APIs called, and the set of categories to which it belongs; each element in the API set is associated with a function description text and the set of categories to which it belongs; A heterogeneous information network is constructed and decoupled into an attribute graph and an interaction graph. The attribute graph is a heterogeneous graph, and its nodes include Mashup nodes, API nodes, and category nodes. The edges of the attribute graph represent the attribute relationships between each element in the Mashup set and the category, and between each element in the API set and the category. The interaction graph is a bipartite graph, and its nodes include Mashup nodes and API nodes. The edges of the interaction graph represent the historical call records between the Mashup set and the API set. The functional description text of Mashup nodes and API nodes, as well as the category names of category nodes, are converted into embedding matrices. These embedding matrices are then input into the local-global semantic fusion encoder to generate semantic vectors of a unified dimension, which serve as the initial semantic feature representations for each node.
[0008] Furthermore, the fusion encoding of local and global semantics includes a local feature extraction path and a global feature extraction path. The local feature extraction path employs a multi-scale one-dimensional convolutional layer, performing convolution operations on the embedding matrix with different window sizes, extracting local features through global max pooling, and concatenating the results of multiple convolutional branches to form a local semantic representation. The global feature extraction path employs a Transformer encoder, extracting global representations through a multi-head self-attention layer and a feedforward network, and then aggregating them into global semantic features through global average pooling. The local semantic representation and the global semantic features are concatenated and projected onto a common latent space to generate the initial semantic feature representation.
[0009] Furthermore, in S2, the attribute view and the interaction view adopt a serial decoupled architecture, with node representations flowing from the attribute view to the interaction view. In the attribute view, the initial semantic feature representation is used as input, and message propagation is performed on the attribute graph through a graph attention network. After multiple aggregations, the attribute-enhanced representation is obtained. In the interaction view, the attribute-enhanced representation is used as input, and message propagation is performed on the interaction graph through a graph attention network. After multiple aggregations, the Mashup node representation and the API node representation are obtained.
[0010] Further, in S2, the self-supervised learning for mask reconstruction includes a representation alignment task and a link prediction task; wherein, the representation alignment task involves randomly masking attribute edges in the attribute view to generate a corrupted attribute graph, and using a loss function to make the representation of the corrupted attribute graph approximate the representation of the complete attribute graph; the link prediction task involves randomly masking interaction edges in the interaction view, and using a loss function to train a model to predict whether the masked interaction edges exist; the self-supervised loss includes the representation alignment task loss and the link prediction task loss.
[0011] Further, in step S3, based on the initial semantic feature representation, the semantic similarity between the target Mashup and other Mashups is calculated using cosine similarity, and the Mashup with the highest preset number of similarities is retrieved as the semantic neighbor; for a cold-start Mashup, if there is an attribute connection between the semantic neighbor and a certain category, a pseudo-edge is constructed between the target Mashup and that category to complete the structural information in the attribute graph; according to the Mashup node representation, the graph representation of the semantic neighbor is subjected to similarity attention weighted aggregation to obtain the aggregated neighbor context; the aggregated neighbor context and the representation of the target Mashup itself are weighted and fused using an adaptive confidence parameter calculated by a learnable gating function to obtain the enhanced Mashup representation.
[0012] Furthermore, in S4, the predicted call probability is calculated by the inner product of the enhanced Mashup representation and the API node representation.
[0013] Furthermore, the expression for the predicted call probability is: , in, Indicates a Mashup node. Indicates an API node. express transpose, This represents the final representation of the enhanced Mashup. Represents the API node representation. It is the sigmoid activation function. This represents the probability of a call between Mashup node m and API node a, as predicted by the model.
[0014] Furthermore, in the end-to-end joint training process, the total loss function includes the recommendation task loss and the self-supervised loss; the recommendation task loss includes the binary cross-entropy loss and the marginal ranking loss; the binary cross-entropy loss is calculated based on the predicted probability of observed interactions and the predicted probability of unobserved interactions; the marginal ranking loss is calculated based on the difference between the predicted probability of observed interaction APIs and the predicted probability of unobserved interaction APIs within the same Mashup. Further, in step S4, after completing the end-to-end joint training, the model parameters are fixed, and the self-supervised learning of the mask reconstruction is stopped; the predicted call probability is calculated based on the inner product of the enhanced Mashup representation and the API node representation; the APIs are sorted in descending order of the predicted call probability, and the top preset number of APIs are used to form the final recommendation list and output. Compared with the prior art, the present invention has the following beneficial effects: (1) This invention encodes the functional description text of Mashup and API from two paths through a local-global semantic fusion encoder: In the local feature extraction path, a multi-scale one-dimensional convolutional layer is used to perform convolution operations on the embedding matrix with different window sizes, and the most significant local phrase patterns at each scale are extracted through global max pooling; In the global feature extraction path, the multi-head self-attention layer of the Transformer encoder captures the long-range dependencies and global contextual semantics in the entire description text. The local and global features are concatenated and projected into a common latent space, so that the initial semantic features of each node simultaneously contain key phrase information and overall semantic information. This can effectively address the semantic extraction needs in scenarios with insufficient text information, alleviate the semantic gap between pure text representation and functional semantics, and thus improve the accuracy and reliability of semantic matching in the subsequent recommendation process.
[0015] (2) This invention decouples a heterogeneous information network into an attribute view and an interaction view. In the attribute view, category nodes are used as intermediaries for message propagation to learn category-driven functional associations. In the interaction view, Mashup-API call relationships are used for message propagation to learn interaction patterns. During training, self-supervised learning of mask reconstruction is performed on both views. In the attribute view, attribute edges are randomly masked, and the representation of the damaged graph is made to approximate the representation of the complete graph through a representation alignment task. In the interaction view, interaction edges are randomly masked, and the model is trained through a link prediction task to predict whether the masked interaction exists. This enables the model to learn robust node representations under structurally incomplete conditions and maintain stable feature expression capabilities even when interaction data is sparse. It effectively suppresses the interference of irrelevant structural noise on functional association recognition in sparse data scenarios and improves the recommendation accuracy of the recommendation method under sparse data conditions.
[0016] (3) This invention uses a neighborhood semantic enhancement mechanism to search for the most similar semantic neighbors in the semantic space based on the initial semantic feature representation and cosine similarity, and uses the attribute connection between semantic neighbors and categories to construct pseudo edges for the target Mashup to complete the structure in the attribute view, so that isolated nodes can access heterogeneous information networks. After obtaining the Mashup node representation, the graph representation of the semantic neighbors is aggregated with similarity attention weighting, and the aggregated neighbor context is fused with the representation of the target Mashup itself, so that the cold start Mashup can inherit the interaction mode and functional knowledge from the semantically similar existing Mashup nodes, effectively making up for the information loss caused by the lack of historical call records, so that node representations with discriminative power can still be generated in the cold start scenario, and the recommendation ranking quality of Web API recommendation method under cold start conditions is improved. Attached Figure Description
[0017] Figure 1 A flowchart of a Web API recommendation method based on semantic enhancement and self-supervised graph learning; Figure 2 This is a schematic diagram illustrating the data flow of a Web API recommendation method based on semantic enhancement and self-supervised graph learning. Figure 3 This is a schematic diagram of a heterogeneous information network structure; Figure 4 This is a schematic diagram of the structure of a fusion encoder for local and global semantics. Figure 5 This is a graph showing the experimental results of the Web API recommendation method in this embodiment on the first dataset; Figure 6The figure shows the experimental results of the Web API recommendation method in this embodiment on the second dataset. Detailed Implementation
[0018] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort should fall within the scope of protection of the present invention.
[0019] The Web API recommendation technology involved in this embodiment helps Mashup developers accurately filter API services that match the functional requirements of their target Mashup from a vast number of available APIs. In a service-oriented distributed architecture, Web APIs, as the core medium for inter-service communication, have seen their number increase dramatically with the development of API sharing platforms, placing immense pressure on Mashup developers to filter APIs. Currently, mainstream Web API recommendation methods mainly include content-based, interaction-based, and graph-based methods. Content-based methods focus on text semantic matching, but typically only learn local semantic associations, resulting in significant performance degradation when text information is insufficient. Interaction-based methods utilize historical call data for collaborative filtering, but are highly sensitive to the density of interaction data, leading to severe degradation in recommendation performance under sparse conditions. Graph-based methods extract structural semantics by constructing heterogeneous information networks; however, in sparse data scenarios, they easily introduce structural noise unrelated to core functional relationships, masking stable functional associations. Furthermore, cold-start Mashups lacking historical interaction records appear as isolated nodes in the network, making it difficult to obtain effective representational information through graph propagation. Therefore, this embodiment proposes a Web API recommendation method based on semantic enhancement and self-supervised graph learning. It enhances the comprehensiveness of text representation through encoding with local and global semantic fusion, suppresses structural noise caused by sparse interactions through dual-view mask autoencoder, and injects interaction pattern information into cold-start Mashups through neighborhood semantic enhancement mechanism, thereby improving the accuracy and ranking quality of recommendations in data sparse and cold-start scenarios.
[0020] In this embodiment, we define: Web APIs provide function call interfaces through standardized protocols; Mashup development is a service composition paradigm where developers aggregate the functionality of multiple third-party Web APIs to build customized applications. Each Mashup m can be represented as a tuple. ,in, This is the functional description text for Mashup. The set of APIs called by Mashup. This is the set of categories to which the Mashup belongs. Each API 'a' can be represented as a tuple. ,in, This is the API's functional description text. This refers to the set of categories to which the API belongs.
[0021] Heterogeneous information networks are heterogeneous graphs composed of three types of nodes: Mashup nodes, API nodes, and category nodes. They include attribute edges between Mashup and category, attribute edges between API and category, and call edges between Mashup and API, and are used to model complex relationships between multiple types of entities.
[0022] The Web API recommendation task is as follows: Given an API set A, a Mashup set M, and a category set C in a dataset D, recommend recommendations for newly created Mashups. Recommend the top-N candidate APIs. This is for cold-start Mashups. Only its functional description is available. Available. This recommendation task can be mathematically abstracted as a mapping function. That is, based on the information of the Mashup set, API set, and category set, output the Top-N recommended APIs for the target Mashup.
[0023] like Figure 1 As shown, this embodiment provides a Web API recommendation method based on semantic enhancement and self-supervised graph learning. The specific steps include: S1. Obtain Mashup data, API data, and category data. Mashup data includes the functional description text of the Mashup, and API data includes the functional description text of the API. Based on the historical call relationship between Mashup and API data, and the attribute relationship between Mashup, API, and category, construct a heterogeneous information network. Perform fusion encoding of local and global semantics on the functional description text to obtain the initial semantic feature representation of each node. S2. Decouple the heterogeneous information network into an attribute view and an interaction view, perform graph attention propagation in the attribute view and the interaction view respectively, and perform self-supervised learning of mask reconstruction on the attribute view and the interaction view respectively during the training process. Based on the self-supervised loss, obtain the Mashup node representation and the API node representation. S3. For cold-start Mashup nodes, retrieve semantic neighbors based on the initial semantic feature representation, use the category connection of semantic neighbors to complete the structure of the attribute view, and aggregate the graph representation of semantic neighbors into the representation of the target Mashup node to obtain the enhanced Mashup representation. S4. Calculate the predicted call probability based on the enhanced Mashup representation and API node representation, and output the API recommendation list based on the predicted call probability.
[0024] like Figure 2 The diagram shown illustrates the data flow of the Web API recommendation method based on semantic enhancement and self-supervised graph learning provided in this embodiment.
[0025] Specifically, the steps of S1 include: Define Mashup sets based on the collected Mashup data, API data, and category data. API collection and category set Elements in a Mashup collection Related function description text The set of APIs called and the set of categories Elements in the API collection Related function description text and the set of categories ; Construct a heterogeneous information network, namely the Mashup-API-Category heterogeneous information network, and decouple the heterogeneous information network into a property graph. and interactive diagrams .like Figure 3 The diagram shown is a schematic of a heterogeneous information network structure. The attribute graph is a heterogeneous graph, and the nodes of the attribute graph... Including Mashup nodes, API nodes, and category nodes, the edges of the attribute graph. The interaction diagram represents the attribute relationships between elements and categories in the Mashup set and between elements and categories in the API set; the interaction diagram is a bipartite diagram, and the nodes of the interaction diagram... Including Mashup nodes and API nodes, the edges of the interaction graph This represents the historical call records between the Mashup collection and the API collection; The functional description text of Mashup nodes and API nodes, as well as the category names of category nodes, are converted into embedding matrices. The embedding matrices are then input into a local-global semantic fusion encoder to generate semantic vectors of uniform dimension, which serve as the initial semantic feature representations for each node.
[0026] The fusion encoding of local and global semantics includes local feature extraction paths and global feature extraction paths. The local feature extraction path uses multi-scale one-dimensional convolutional layers to perform convolution operations on the embedding matrix with different window sizes, extracts local features through global max pooling, and concatenates the results of multiple convolutional branches to form a local semantic representation. The global feature extraction path uses a Transformer encoder to extract global representations through multi-head self-attention layers and feedforward networks, and then aggregates them into global semantic features through global average pooling. The local semantic representation and global semantic features are concatenated and projected onto a common latent space to generate an initial semantic feature representation.
[0027] like Figure 4 The diagram shows the structure of a fusion encoder for local and global semantics. The local feature extraction path employs multi-scale one-dimensional convolutional layers with different window sizes. For embedding matrix E Convolutional operations are performed, and the most salient local features are extracted using global max pooling. The results of multiple convolutional branches are then concatenated to form a local semantic representation. The expression is: , in, For the first k The convolution operation result corresponding to each kernel size A set of window sizes.
[0028] The global feature extraction path employs a Transformer encoder, extracting context-aware global representations T through multi-head self-attention layers and a feedforward network, and then aggregating them into global semantic features through global average pooling. The expression is: , in, The length of the input sequence. For the first The encoded characteristics of each token.
[0029] Ultimately, local semantic representation will be used. and global semantic features Mapped to via stitching and linear projection d Maintaining public potential space: , in, and For the learnable parameters of the linear projection, This represents a vector concatenation operation. These serve as initial features for nodes in subsequent graph learning. d As a dimension of public potential space, This represents the initial characteristics of a Mashup node. This represents the initial characteristics of the API node. This represents the initial characteristics of the category node.
[0030] In S2, the attribute view and the interaction view adopt a serial decoupled architecture, with node representations flowing from the attribute view to the interaction view. In the attribute view, the initial semantic feature representation is used as input, and message propagation is performed on the attribute graph through a graph attention network. After multiple aggregations, the attribute-enhanced representation is obtained. In the interaction view, the attribute-enhanced representation is used as input, and message propagation is performed on the interaction graph through a graph attention network. After multiple aggregations, the Mashup node representation and the API node representation are obtained.
[0031] Specifically, in the attribute view, a graph attention network is used to focus on the attribute graph. To spread the message, the first The update rules for layer Mashup nodes are as follows: , No. l The update rules for the +1 layer API node are as follows: , in, Represents a property graph. This indicates the layer index of the current graph attention network. This represents the updated layer index. and They represent the first Layer and first The representation of layer Mashup nodes in the attribute view. and They represent the first Layer and first The representation of layer API nodes in the property view. This represents the set of category nodes connected to the Mashup node. This represents the set of category nodes connected to the API node. Indicates the first Attention weights between layer Mashup nodes and category nodes. Indicates the first Attention weights between layer API nodes and category nodes Indicates the first The graph attention network of the layer attribute view can learn parameters. Indicates the first Learnable parameters for layer self-connection, where R is the LeakyReLU activation function.
[0032] Self-supervised learning for mask reconstruction includes representation alignment and link prediction tasks. The representation alignment task involves randomly masking attribute edges in the attribute view to generate a corrupted attribute graph, and using a loss function to make the representation of the corrupted attribute graph approximate the representation of the complete attribute graph. The link prediction task involves randomly masking interaction edges in the interaction view, and using a loss function to train a model to predict whether the masked interaction edges exist. The self-supervised loss includes the representation alignment task loss and the link prediction task loss.
[0033] In the interactive view, the output of the property view is used as input, and a graph attention network is employed to process the interactive graph. The process involves message propagation, learning the interaction patterns between the Mashup and the API, and obtaining the final node representation after L-layer aggregation. and .
[0034] The mask reconstruction mechanism includes a representation alignment task and a mask link prediction task: the representation alignment task randomly masks the attribute edges between the Mashup and the category, as well as the attribute edges between the API and the category, in the attribute view to generate a corrupted attribute graph. Through mean square error loss This forces the representation of the corrupted attribute graph to approximate the representation of the complete attribute graph; the masked link prediction task randomly masks the interaction edges between the Mashup and the API in the interactive view, using binary cross-entropy loss. The trained model predicts whether the masked interaction edges exist; the total loss of the autoencoder is: , in, This represents the corrupted attribute map after masking. This represents the mean squared error loss characterizing the alignment task. This represents the binary cross-entropy loss for the masked link prediction task. To control the weighting coefficients that balance the characterization alignment task and the mask link prediction task, The value range is [0,1].
[0035] In S3, based on the initial semantic feature representation, the semantic similarity between the target Mashup and other Mashups is calculated using cosine similarity. The Mashup with the highest similarity (a preset number) is retrieved as the semantic neighbor. For cold-start Mashups, if there is an attribute connection between the semantic neighbor and a certain category, a pseudo-edge is constructed between the target Mashup and that category to complete the structural information in the attribute graph. Based on the Mashup node representation, the graph representation of the semantic neighbors is aggregated using similarity attention weighting to obtain the aggregated neighbor context. The aggregated neighbor context and the target Mashup's own representation are then weighted and fused using an adaptive confidence parameter calculated by a learnable gating function to obtain the enhanced Mashup representation.
[0036] Specifically, the data processing steps for the neighborhood-enhanced semantic enhancement mechanism include: Mashup semantic representation generated based on local-global semantic fusion encoder The top-K most similar neighbor nodes are retrieved using cosine similarity to form a semantic neighbor set. The similarity calculation formula is: , in, Indicates the target Mashup node The initial semantic feature representation, Indicates candidate Mashup neighbor nodes The initial semantic feature representation, Indicates the target Mashup node With candidate neighbor nodes The cosine similarity between them, where K is the number of semantic neighbors retrieved. Let m be the set of the K semantic neighbor nodes that are most similar to the target Mashup node m.
[0037] For cold start Mashup, if neighbors With category c If there is an attribute connection between them, then in the target Mashup node m With this category c Pseudo-edges are constructed between nodes to complete the structural information in the attribute graph. The final Mashup node representation is then output by the dual-view mask autoencoder. Then, the graph representations of semantic neighbors are aggregated using similarity attention weighting, and the aggregation formula is as follows: , in, Represents semantic neighbor nodes The final representation output after the dual-view mask autoencoder, Indicates the target Mashup node semantic neighbor nodes Cosine similarity between them This represents the neighbor context representation obtained from the aggregation.
[0038] Aggregate neighbor contexts With the node's own representation The fusion yields the final enhanced representation: , in, This is an adaptive confidence parameter used to dynamically balance the weighting of node self-representation and neighbor context information during fusion. Indicates the target Mashup node The final enhanced representation.
[0039] In S4, the predicted call probability is calculated by the inner product of the enhanced Mashup representation and the API node representation; During end-to-end joint training, the total loss function includes recommendation task loss and self-supervised loss; recommendation task loss includes binary cross-entropy loss and marginal ranking loss; binary cross-entropy loss is calculated based on the predicted probabilities of observed interactions and unobserved interactions; marginal ranking loss is calculated based on the difference between the predicted probabilities of observed interaction APIs and unobserved interaction APIs within the same Mashup.
[0040] Binary cross-entropy loss The calculation formula is: , in, Indicates a Mashup node. Indicates an API node. This represents the set of positive samples from which interactions have been observed. This represents the set of negative samples for which no interaction was observed. Indicates Mashup node With API nodes Are there tags indicating actual interaction between them? If so, then... If there is no interaction, then , Mashup nodes representing model predictions With API nodes The probability of calls between them.
[0041] Marginal ranking loss It is calculated based on the difference between the predicted probabilities of observed and unobserved interactive APIs within the same Mashup. The specific calculation formula is as follows: , in, This represents the training triple set, where each triple is a training triple set. From the same Mashup node A positive sample API node with observed interactions. A negative sample API node with no observed interaction composition, Mashup nodes representing model predictions With positive sample API node The probability of calling between them Mashup nodes representing model predictions With negative sample API node The probability of calling between them represents the marginal parameter, and ReLU represents the modified linear unit activation function.
[0042] The loss from the primary recommended task is: , in, The weighting coefficients are used to control the balance between binary cross-entropy loss and marginal ranking loss. The value range is [0,1].
[0043] The total joint training losses are: , in, This represents the self-supervised loss of the dual-view mask autoencoder.
[0044] In S4, after completing end-to-end joint training, the model parameters are fixed and the self-supervised learning of mask reconstruction is stopped; the predicted call probability is calculated based on the inner product of the enhanced Mashup representation and the API node representation; the APIs are sorted in descending order of the predicted call probability, and the top-ranked APIs are used to form the final recommendation list and output.
[0045] The expression for predicting the probability of invocation is: , in, Indicates a Mashup node. Indicates an API node. express transpose, This represents the final representation of the enhanced Mashup. Represents the API node representation. It is the sigmoid activation function. This represents the probability of a call between Mashup node m and API node a, as predicted by the model.
[0046] To verify the effectiveness of the method provided in this embodiment, two real-world Web API sharing platform datasets were used to validate the proposed method. The first dataset includes 8217 Mashups, 1647 APIs, and 499 categories, recording a total of 17182 Mashup-API call interactions, with each Mashup calling an average of 2.09 APIs. The second dataset includes 5772 Mashups, 327 APIs, and 611 categories, recording a total of 5818 call interactions, with each Mashup calling an average of only 1.01 APIs, exhibiting higher sparsity and a more severe cold start problem. A heterogeneous Mashup-API-Category information network was constructed, decoupling the network into an attribute graph and an interaction graph. The attribute graph is heterogeneous, consisting of Mashup nodes, API nodes, and category nodes, with edges representing the attribute relationships between Mashups, APIs, and their respective categories. The interaction graph is bipartite, consisting of Mashup nodes and API nodes, with edges representing historical call records.
[0047] In the semantic encoding stage, the original input includes Mashup description text, API description text, and category names. These are first preprocessed into a normalized text sequence, then converted into an embedding matrix using a pre-trained GloVe.6B.300d embedding model. The local feature extraction path uses a multi-scale one-dimensional convolutional layer with 256 convolutional filters to extract key phrase patterns. The global feature extraction path uses a 4-head Transformer encoder to capture long-range dependencies and global context. These two feature paths are concatenated and linearly projected onto a 128-dimensional common latent space to generate the initial semantic representations for each node.
[0048] In the dual-view masking autoencoder learning phase, a serially decoupled architecture is adopted. The attribute view and interaction view each employ a two-layer graph attention network for message propagation, with each layer integrating dropout and layer normalization. In the masking reconstruction mechanism, the representation alignment task sets the attribute edge masking rate between the Mashup and the category, and between the API and the category, to 0.3 in the attribute view, using mean squared error loss to force the masked graph representation to approximate the complete graph representation. The masking link prediction task sets the interaction edge masking rate between the Mashup and the API to 0.4 in the interaction view, using binary cross-entropy loss to train the model to predict whether the masked interaction exists. The losses of the two tasks are balanced by a weight coefficient of 0.6. In the neighborhood-facilitated semantic enhancement phase, for a cold-start target Mashup, the Top-K=5 most similar semantic neighbor nodes are retrieved using cosine similarity. The category connections of the neighbors are inherited to construct a pseudo-edge-completed attribute graph structure. After the dual-view masking autoencoder outputs the final representation, the graph representations of the neighbors are aggregated using similarity attention weighting, and an adaptive confidence parameter dynamically balances the neighbor information and the inherent node representations.
[0049] During the joint training phase, the predicted call probability is calculated by sigmoid activation through the inner product of the enhanced Mashup representation and the API node representation. The main recommendation task loss is combined with the binary cross-entropy loss and the marginal ranking loss, weighted by a weight coefficient of 0.8. The total loss is the sum of the recommendation task loss and the self-supervised loss, and end-to-end joint training is performed. Training uses the Adam optimizer with a learning rate of 0.001, a batch size of 128, dynamically sampling 5 negative samples, a maximum of 300 training epochs, and an early stopping strategy of 30 epochs. The dataset is randomly divided into training, validation, and test sets in an 8:1:1 ratio. After completing end-to-end joint training, the model parameters are fixed, the mask reconstruction task is stopped, and the Top-N recommendation list is output in descending order of predicted probability.
[0050] Figure 5 and Figure 6 The figures show the experimental results of the proposed method on two datasets. On the first dataset, when the recommendation list length is 5, NDCG@5, MAP@5, and Precision@5 reach 0.7791, 0.7552, and 0.2326, respectively, representing improvements of 2.06%, 2.85%, and 3.01% compared to the best baseline. On the second dataset, when the recommendation list length is 5, NDCG@5 and MAP@5 reach 0.7139 and 0.6898, respectively, representing improvements of 5.89% and 7.16% compared to the best baseline.
[0051] Therefore, the Web API recommendation method based on semantic enhancement and self-supervised graph learning proposed in this embodiment uses a local-global semantic fusion encoder to fuse and encode the functional description text of the Mashup and API with local and global features, generating initial semantic feature representations for each node. This ensures that the initial semantic representations of each node simultaneously contain local key phrase information and global contextual semantic information, effectively alleviating the semantic gap between plain text representation and functional semantics, and improving the accuracy of semantic matching.
[0052] Furthermore, by decoupling the heterogeneous information network into an attribute view and an interaction view, a graph attention network is used for message propagation on both views. A representation alignment task and a mask link prediction task are designed as self-supervised learning mechanisms for mask reconstruction. In the attribute view, the representation alignment task makes the representation of the mask graph approximate the representation of the complete graph. In the interaction view, the link prediction task trains the model to predict whether the masked interaction exists. This enables the model to learn robust node representations under structurally incomplete conditions, effectively suppressing the interference of irrelevant structural noise on functional association recognition in sparse data scenarios and improving the recommendation accuracy under sparse data conditions.
[0053] Through a neighborhood semantic enhancement mechanism, for cold-start Mashup nodes lacking historical call records, semantic neighbors are retrieved in the semantic space based on the initial semantic feature representation. Pseudo-edges are constructed using the category connections of semantic neighbors to complete the structure in the attribute view. After obtaining the Mashup node representation, similarity attention-weighted aggregation is performed on the graph representation of semantic neighbors. The aggregated neighbor context is fused with the representation of the target Mashup itself, enabling the cold-start Mashup to inherit interaction patterns and functional knowledge from semantically similar existing Mashup nodes. This effectively compensates for the information loss caused by the lack of historical call records and improves the recommendation ranking quality under cold-start conditions.
[0054] In summary, the method proposed in this embodiment can maintain stable recommendation performance in both data sparsity and cold start scenarios, effectively improving the accuracy and ranking quality of Web API recommendations.
[0055] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the specific working process of the described module can be referred to the corresponding process in the foregoing method embodiments, and will not be repeated here.
[0056] The above description is merely a specific embodiment of the present invention, but the scope of protection of the present invention is not limited thereto. Any person skilled in the art can easily conceive of various equivalent modifications or substitutions within the technical scope disclosed in the present invention, and these modifications or substitutions should all be covered within the scope of protection of the present invention. Therefore, the scope of protection of the present invention should be determined by the scope of the claims.
Claims
1. A Web API recommendation method based on semantic enhancement and self-supervised graph learning, characterized in that, The specific steps include: S1. Obtain Mashup data, API data, and category data. The Mashup data includes the functional description text of the Mashup, and the API data includes the functional description text of the API. Based on the historical call relationship between the Mashup and the API data, and the attribute relationship between the Mashup, API, and category, construct a heterogeneous information network. Perform fusion encoding of local semantics and global semantics on the functional description text to obtain the initial semantic feature representation of each node. S2. Decouple the heterogeneous information network into an attribute view and an interaction view, perform graph attention propagation in the attribute view and the interaction view respectively, and perform self-supervised learning of mask reconstruction on the attribute view and the interaction view respectively during the training process, and obtain Mashup node representation and API node representation based on self-supervised loss. S3. For cold-start Mashup nodes, retrieve semantic neighbors based on the initial semantic feature representation, use the category connection of the semantic neighbors to complete the structure of the attribute view, and aggregate the graph representation of the semantic neighbors into the representation of the target Mashup node to obtain the enhanced Mashup representation. S4. Calculate the predicted call probability based on the enhanced Mashup representation and the API node representation, and output the API recommendation list based on the predicted call probability.
2. The Web API recommendation method based on semantic enhancement and self-supervised graph learning according to claim 1, characterized in that, The specific steps of S1 include: Based on the collected Mashup data, API data, and category data, define Mashup sets, API sets, and category sets respectively; each element in the Mashup set is associated with a function description text, the set of APIs called, and the set of categories to which it belongs; each element in the API set is associated with a function description text and the set of categories to which it belongs; A heterogeneous information network is constructed and decoupled into an attribute graph and an interaction graph. The attribute graph is a heterogeneous graph, and its nodes include Mashup nodes, API nodes, and category nodes. The edges of the attribute graph represent the attribute relationships between each element in the Mashup set and the category, and between each element in the API set and the category. The interaction graph is a bipartite graph, and its nodes include Mashup nodes and API nodes. The edges of the interaction graph represent the historical call records between the Mashup set and the API set. The functional description text of Mashup nodes and API nodes, as well as the category names of category nodes, are converted into embedding matrices. These embedding matrices are then input into the local-global semantic fusion encoder to generate semantic vectors of a unified dimension, which serve as the initial semantic feature representations for each node.
3. The Web API recommendation method based on semantic enhancement and self-supervised graph learning according to claim 2, characterized in that, The fusion encoding of local and global semantics includes a local feature extraction path and a global feature extraction path. The local feature extraction path uses a multi-scale one-dimensional convolutional layer to perform convolution operations on the embedding matrix with different window sizes, extracts local features through global max pooling, and concatenates the results of multiple convolutional branches to form a local semantic representation. The global feature extraction path uses a Transformer encoder to extract global representations through a multi-head self-attention layer and a feedforward network, and then aggregates them into global semantic features through global average pooling. The local semantic representation and the global semantic features are concatenated and projected onto a common latent space to generate the initial semantic feature representation.
4. The Web API recommendation method based on semantic enhancement and self-supervised graph learning according to claim 1, characterized in that, In S2, the attribute view and the interaction view adopt a serial decoupled architecture, and the node representation flows from the attribute view to the interaction view; In the attribute view, the initial semantic feature representation is used as input, and message propagation is performed on the attribute graph through a graph attention network. After multiple aggregations, an attribute-enhanced representation is obtained. In the interactive view, the attribute-enhanced representation is used as input, and message propagation is performed on the interactive graph through a graph attention network. After multi-layer aggregation, the Mashup node representation and the API node representation are obtained.
5. The Web API recommendation method based on semantic enhancement and self-supervised graph learning according to claim 1, characterized in that, In step S2, the self-supervised learning for mask reconstruction includes a representation alignment task and a link prediction task; wherein, the representation alignment task involves randomly masking attribute edges in the attribute view to generate a corrupted attribute graph, and using a loss function to make the representation of the corrupted attribute graph approximate the representation of the complete attribute graph; the link prediction task involves randomly masking interaction edges in the interaction view, and using a loss function to train a model to predict whether the masked interaction edges exist; the self-supervised loss includes the representation alignment task loss and the link prediction task loss.
6. The Web API recommendation method based on semantic enhancement and self-supervised graph learning according to claim 1, characterized in that, In step S3, based on the initial semantic feature representation, the semantic similarity between the target Mashup and other Mashups is calculated using cosine similarity, and the Mashup with the highest preset number of similarities is retrieved as the semantic neighbor; for cold-start Mashups, if there is an attribute connection between the semantic neighbor and a certain category, a pseudo-edge is constructed between the target Mashup and that category to complete the structural information in the attribute graph; according to the Mashup node representation, the graph representation of the semantic neighbor is subjected to similarity attention weighted aggregation to obtain the aggregated neighbor context; The aggregated neighbor context and the target Mashup's own representation are weighted and fused using an adaptive confidence parameter calculated by a learnable gating function to obtain the enhanced Mashup representation.
7. The Web API recommendation method based on semantic enhancement and self-supervised graph learning according to claim 1, characterized in that, In step S4, the predicted call probability is calculated by the inner product of the enhanced Mashup representation and the API node representation.
8. The Web API recommendation method based on semantic enhancement and self-supervised graph learning according to claim 7, characterized in that, The expression for the predicted call probability is: , in, Indicates a Mashup node. Indicates an API node. express transpose, This represents the final representation of the enhanced Mashup. Represents the API node representation. It is the sigmoid activation function. This represents the probability of a call between Mashup node m and API node a, as predicted by the model.
9. The Web API recommendation method based on semantic enhancement and self-supervised graph learning according to claim 1, characterized in that, In S4, during the end-to-end joint training process, the total loss function includes the recommendation task loss and the self-supervised loss; the recommendation task loss includes the binary cross-entropy loss and the marginal ranking loss; the binary cross-entropy loss is calculated based on the predicted probabilities of observed interactions and unobserved interactions; the marginal ranking loss is calculated based on the difference between the predicted probabilities of observed interaction APIs and unobserved interaction APIs within the same Mashup.
10. The Web API recommendation method based on semantic enhancement and self-supervised graph learning according to claim 1, characterized in that, In step S4, after completing the end-to-end joint training, the model parameters are fixed, and the self-supervised learning of the mask reconstruction is stopped; the predicted call probability is calculated, the APIs are sorted in descending order according to the predicted call probability, and the top preset number of APIs are selected to form the final recommendation list and output.