A web api recommendation method based on a multi-task deep neural network

By using a multi-task deep neural network model to share information and optimize feature extraction, the problem of low accuracy in existing Web API recommendation methods is solved, achieving higher recall and accuracy.

CN119760231BActive Publication Date: 2026-07-21DALIAN MARITIME UNIVERSITY

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
DALIAN MARITIME UNIVERSITY
Filing Date
2024-12-11
Publication Date
2026-07-21

AI Technical Summary

Technical Problem

Existing Web API recommendation methods struggle to accurately recommend Web APIs with no or low interaction in historical data when faced with massive amounts of data. Furthermore, they fail to fully exploit the category-level and function-level semantic information between Mashups and Web APIs, resulting in low recommendation accuracy.

Method used

This paper adopts a multi-task deep neural network. By constructing a multi-task deep neural network model, multiple tasks are designed for pre-training using interaction information and category information from Mashups and Web APIs. Information is shared to expand the number of samples. Attention focusing and feature stealing techniques of multi-task learning are used. Semantic feature extraction and cross-entropy loss function are optimized through the BERT model to improve the speech feature extraction effect of the model and solve the technical challenges that have not been solved in the existing technology.

Benefits of technology

It improves the recall and accuracy of Web API recommendations, enabling more accurate recommendations of Web APIs with no or low interaction in historical data. It also enhances the model's textual semantic feature extraction performance, thereby improving the accuracy and recall of recommendations.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119760231B_ABST
    Figure CN119760231B_ABST
Patent Text Reader

Abstract

The application provides a Web API recommendation method based on a multi-task deep neural network, comprising the following steps: S1, cleaning Mashup description documents and Web API description documents in a data set; S2, mapping the text information in the cleaned data set into digital codes; S3, generating sample data based on the digital codes; S4, constructing a Web API recommendation model based on a multi-task deep neural network; S5, inputting the sample data into the Web API recommendation model for pre-training to obtain a pre-trained Web API recommendation model; S6, fine-tuning the pre-trained Web API recommendation model using a Mashup and API matching score prediction task; S7, obtaining a matching score list of Mashup requirements and each Web API; S8, sorting the matching score list of Mashup requirements and each Web API in descending order of matching scores, and selecting the top K Web APIs to form a final recommendation list. The application solves the problem of being difficult to accurately recommend Web APIs with no interaction or low interaction in historical data, and improves the recall rate, accuracy and other indicators of the recommendation.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of Web service recommendation technology, and more particularly to a Web API recommendation method based on a multi-task deep neural network. Background Technology

[0002] With the rapid development of Service Oriented Computing (SOC) technology, the number and diversity of available services have also increased dramatically, making services increasingly important in people's daily work and lives. Simultaneously, to meet complex development requirements, service composition application technologies, primarily Mashups (aggregated services), have also developed rapidly. By integrating data, content, or functionality from multiple Application Programming Interfaces (Web APIs), a new, integrated aggregated service is created, providing users with a richer and more convenient experience. In Mashup development, choosing the appropriate Web API is crucial, as it directly impacts the Mashup's performance, feature richness, and user experience. The sheer number of Web APIs presents developers with a significant challenge in effectively selecting, using, and managing services. Therefore, how to accurately and efficiently recommend candidate services for Mashups from a vast array of Web APIs has become an important issue in the field of service computing, possessing both research and application value.

[0003] Currently, Web API recommendation methods for Mashup development mainly include collaborative filtering, content-based recommendation, and hybrid recommendation methods. Collaborative filtering predicts recommendations based on historical interaction relationships, suggesting Web APIs called by Mashups similar to the developer's needs based on the historical call relationships between the Mashup and the Web API. However, this type of method only utilizes the similarity relationship between Mashups, neglecting the similarity of the functional description text and the consistency of categories between the Mashup and the Web API, resulting in a serious cold start problem. Content-based recommendation methods calculate the similarity between the Mashup's needs and the Web API's description text, recommending Web APIs more similar to the Mashup's needs to the user. However, this type of method focuses on the semantic features of the Mashup and Web API description documents, while the Web service ecosystem contains a wealth of information that can be used to enhance content representation, such as the call relationships and categories between Mashups and Web APIs; therefore, the quality of the obtained semantic features is relatively low.

[0004] Multi-task learning, by sharing representation information, simultaneously learns multiple related tasks, featuring implicit data augmentation, attention focus, feature eavesdropping, inductive bias, and regularization. Some researchers have proposed the MTFM recommendation method based on multi-model fusion and multi-task learning. First, semantic features and interaction features are extracted using a semantic feature extraction component based on convolutional neural networks and feature interaction components based on matrix factorization (MF) and multi-layer perceptron (MLP), respectively. Then, the extracted features are concatenated, and finally, the model is trained using the concatenated features in two multi-label classification tasks: Web API recommendation and Mashup classification, enabling the model to have multi-task learning capabilities. Similarly, the patent "Web Service Package Recommendation Method, System, Medium, and Device Based on Multi-Task Learning" constructs reusable service packages by using historical Mashup and Web API call records and learns their combined semantics. It fuses content-based and history-based call models through semantic feature extraction and feature interaction components, constructing a multi-task learning framework for service package recommendation. However, this method only treats the Mashup classification task as an auxiliary task and improves the model's generalization ability through inductive bias. It does not mine more fine-grained category-level semantic association information in semantic information, nor does it consider learning the category-level semantic association information and sparse function-level semantic association information between Mashup and Web API at the same time. This results in insufficient semantic information mining and low recommendation accuracy.

[0005] In summary, existing Web API recommendation methods still have the following problems: (1) Since Web API and Mashup requirement description documents are short texts with high noise and sparse features, it is difficult to obtain high-quality semantic feature representations by using only a single task to extract text information, resulting in low recommendation accuracy. (2) Existing Web API recommendation methods do not consider the mutual promotion of category-level semantic association information and function-level semantic information between Mashup and Web API at the same time. Learning them separately cannot fully explore semantic information, making it difficult to accurately recommend Web APIs with no or low interaction in historical data, resulting in low recommendation accuracy. Summary of the Invention

[0006] In view of this, the purpose of this invention is to propose a Web API recommendation method based on a multi-task deep neural network. This method utilizes the idea of ​​multi-task learning to construct a multi-task deep neural network, and designs multiple tasks for pre-training using Mashup and API interaction information, as well as category information. This implicitly augments data and expands the sample size, thereby improving the quality of the textual semantic features extracted by the model. Simultaneously, a category-related auxiliary task is introduced, leveraging the attention-focusing and feature-eavesdropping characteristics of multi-task learning to enable the model to capture easily classifiable category-level semantic association information. Furthermore, it learns and extracts more comprehensive semantic features from both category-level and function-level perspectives, thus solving the problem of accurately recommending Web APIs with no or low interaction in historical data, and improving recommendation recall, accuracy, and other metrics.

[0007] The technical means employed in this invention are as follows:

[0008] A Web API recommendation method based on a multi-task deep neural network includes the following steps:

[0009] S1. Obtain the Mashup and Web API datasets, which include Mashup names, Mashup categories, Mashup description documents, Web APIs called by the Mashup, Web API names, Web API categories, and Web API description documents; and clean the Mashup description documents and Web API description documents in the dataset by removing stop words, emojis, and special symbols from the documents.

[0010] S2. Map the text information in the cleaned dataset into numerical codes;

[0011] S3. Generate sample data for multiple tasks based on digital encoding; the multiple tasks include Mashup and Web API call matching score prediction task, Mashup and Web API category matching score prediction task, Web API category prediction task, and Mashup category prediction task.

[0012] S4. Construct a multi-task deep neural network based on multiple tasks; the multi-task deep neural network includes a BERT-based text semantic feature extraction layer, a Mashup and Web API call matching rating prediction task layer, a Mashup and Web API category matching rating prediction task layer, a Web API category prediction task layer, and a Mashup category prediction task layer; construct a Web API recommendation model based on the multi-task deep neural network;

[0013] S5. Input the sample data into the Web API recommendation model for pre-training to obtain the pre-trained Web API recommendation model;

[0014] S6. Fine-tune the pre-trained Web API recommendation model using Mashup and API matching rating prediction tasks;

[0015] S7. Combine the Mashup requirements with the description text of each Web API to form sentence pairs, and input them into the fine-tuned Mashup and Web API matching score prediction model to obtain a list of matching scores between Mashup requirements and each Web API.

[0016] S8. Sort the matching score list of Mashup requirements with each Web API in descending order of matching score, and select the top K Web APIs to form the final recommendation list.

[0017] Furthermore, S2 specifically includes the following steps:

[0018] The service category, Web API name, and Mashup name are converted into numbers, and the service category is mapped to the service category label, the Web API name is mapped to the Web API code, and the Mashup name is mapped to the Mashup code.

[0019] Based on the call relationship between Mashup and Web API, a Mashup-Web API call relationship encoding table is generated; using the BERT model's word segmentation tool, the Mashup description document and the Web API description document are segmented to obtain the word segmentation encoding of the Mashup description document and the Web API description document.

[0020] Furthermore, S3 specifically includes the following steps:

[0021] The training samples for the Mashup category prediction task are generated by combining the Mashup encoding, the tokenization encoding of the Mashup description document, the Mashup category label, and the task category label.

[0022] The Web API encoding, the word segmentation encoding of the Web API description document, the category label of the Web API, and the task category tag are combined to generate training samples for the Web API category prediction task;

[0023] The training samples for the Mashup and Web API category matching prediction task are obtained by combining sentence pairs composed of Mashup encoding, Web API encoding, Mashup description document encoding and Web API description document encoding, the corresponding category matching labels and task category labels. A category matching label of 1 indicates that the Mashup and Web API categories match, and a category label of 0 indicates that the Mashup and Web API categories do not match.

[0024] The training samples for the Mashup and Web API call matching prediction task are obtained by combining sentence pairs composed of Mashup encoding, Web API encoding, Mashup description document encoding and Web API description document encoding, the corresponding call relationship labels and task category labels. The call relationship label is 1 to indicate that there is a call relationship between Mashup and Web API, and 0 to indicate that there is no call relationship between Mashup and Web API.

[0025] Furthermore, in S4, the Web API recommendation model based on a multi-task deep neural network includes a BERT-based text semantic feature extraction layer and four task layers: Mashup and Web API call matching score prediction task layer, Mashup and Web API category matching score prediction task layer, Mashup and Web API category matching score prediction task layer, Web API category prediction task layer, and Mashup category prediction task layer.

[0026] Among them, the four task layers share the parameters of the BERT-based text semantic feature extraction layer;

[0027] The four task layers are fully connected layers. The prediction result P for each task is calculated according to the following formula. t :

[0028]

[0029] Where x is the semantic feature output by the BERT-based text semantic feature extraction layer, t is the task type, and W is the semantic feature output by the BERT-based text semantic feature extraction layer. t It is the parameter matrix of the fully connected layer corresponding to task t.

[0030] Furthermore, in S4:

[0031] BERT-based text semantic feature extraction layer: The BERT-based text semantic feature extraction layer uses BERT to mine the semantic features of Mashup or Web API-described text sentences;

[0032] Mashup and Web API Call Matching and Scoring Prediction Task Layer: The Mashup and Web API call matching and scoring prediction task layer uses Mashups and Web APIs with call relationships as positive samples and Mashups and Web APIs without call relationships as negative samples, and uses the actual call matching relationship between the two to assist the model in learning functional-level semantic features.

[0033] For sentence pairs consisting of Mashup and Web API description text, the semantic features x are extracted using the BERT semantic feature extraction layer. The probability P that Mashup and Web API have a call matching relationship is calculated according to formula (1). r The task loss is calculated using the cross-entropy loss function shown in formula (2), and the parameter matrix of the network corresponding to the task layer is adjusted according to the loss.

[0034]

[0035] Where, x i Let represent the i-th sample data of the Mashup and Web API call matching rating prediction task, i.e., the sentence pair consisting of the Mashup and the Web API description text, where p is the probability distribution of the true result and q is the probability distribution of the predicted result.

[0036] Mashup and Web API Category Matching Score Prediction Task Layer: For sentence pairs consisting of Mashup and Web API, the semantic features x are extracted using the BERT semantic feature extraction layer. The probability P that Mashup and Web API have a category matching relationship is calculated according to formula (1). c ;

[0037] The task loss is calculated using the cross-entropy loss function shown in formula (2);

[0038] Where, x i Let represent the i-th sample data of the Mashup and Web API category matching rating prediction task, i.e., the sentence pair consisting of Mashup and Web API description text, where p is the probability distribution of the true result and q is the probability distribution of the predicted result.

[0039] Web API Category Prediction Task Layer: For the Web API description text, the semantic features x of the Web API description statement extracted by the BERT semantic feature extraction layer are used to calculate the probability distribution P of the Web API belonging to each category according to formula (1). a =[P1,P2,P i ,...,P n ], where n is the total number of categories, P iThis represents the probability that the Web API belongs to the i-th category, and P is selected according to formula (3). a The category with the highest probability value This is the result predicted for this Web API category.

[0040]

[0041] in, It is the category prediction result. Indicates selecting P a The index with the highest probability value;

[0042] The task loss is calculated using the cross-entropy loss function shown in Equation (2).

[0043] Where, x i Let represent the i-th sample data of the Web API category prediction task, i.e., the Web API description text, p is the probability distribution of the true result, and q is the probability distribution of the predicted result;

[0044] Mashup category prediction task layer:

[0045] For the Mashup description text, the semantic features x generated by the BERT semantic feature extraction layer are used to predict the probability distribution P of the Mashup belonging to each category according to formula (1). m =[P1,P2,P i ,...,P n ], where n is the total number of categories, P i This represents the probability that the Mashup belongs to the i-th category;

[0046] The category of a Mashup is determined by setting a threshold, θ. m The probability value P corresponding to the i-th category i If P i If the value is greater than θ, then the Mashup is determined to belong to the i-th category.

[0047] The task loss is calculated using the binary cross-entropy loss function shown in Equation (4):

[0048]

[0049] Among them, y i q represents the true binary label of the i-th sample data in the Mashup class prediction task, with a value of 0 or 1. i It is the probability that the i-th sample is a positive sample.

[0050] Furthermore, S5 specifically includes the following steps:

[0051] Suppose there are n tasks of different types, the current task is denoted as t, and the pre-training input data is the set of task sample data T1, T2, ..., T generated in S3. n Dataset T for task t t In the middle, each sample r i denoted as a triple (s i ,l i ,c i ), where i represents the i-th sample, s i This represents the text data of the sample, l i c represents the true value label of this sample. i This indicates the task type of the sample;

[0052] Obtain samples for each task used for pre-training, divide these samples into small batches, and then merge and shuffle them.

[0053] Randomly select a small batch of data b t The text data set S of this batch of samples is input into a BERT-based semantic feature extraction layer to extract the contextual semantic features of the text data, resulting in a semantic feature set X for the samples. Based on the task type C recorded in the sample data of this batch, X is input into the corresponding task layer to obtain the predicted value for that task.

[0054] Calculate the task loss using the loss function corresponding to the task type, and update the model parameters using stochastic gradient descent until each b... t After all epochs have been selected, one epoch of pre-training is completed. Pre-training ends after all epochs are completed.

[0055] Furthermore, S6 includes the following steps:

[0056] S61. Obtain fine-tuning samples for the Mashup and Web API matching score prediction task;

[0057] S62. Input the text data of the fine-tuned samples of the Mashup and Web API matching rating prediction task into the BERT semantic feature extraction layer to extract the feature vectors of the Mashup text data and the Web API text data.

[0058] S63. Input the feature vectors of Mashup text data and Web API text data into this task layer to predict the matching score between Mashup and Web API.

[0059] S64. Calculate the task loss using the cross-entropy loss function based on the predicted and actual values;

[0060] S65. Use stochastic gradient descent to update model parameters based on task loss;

[0061] S66, repeat S62 to S65 until each sample has been selected, then one epoch of fine-tuning training is completed. After completing all epochs, the fine-tuning ends, and the Mashup and Web API matching score prediction model is obtained.

[0062] The present invention also provides a storage medium comprising a stored program, wherein, when the program is executed, it performs any of the above-described Web API recommendation methods based on a multi-task deep neural network.

[0063] The present invention also provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes any of the above-described Web API recommendation methods based on a multi-task deep neural network through the computer program.

[0064] Compared with the prior art, the present invention has the following advantages:

[0065] This invention employs a multi-task hard parameter sharing network structure during the pre-training phase. Utilizing the idea of ​​multi-task learning, multiple tasks share information to expand the sample size and implicitly augment data, effectively alleviating data sparsity issues and improving the model's textual semantic feature extraction performance, thereby enhancing recommendation accuracy and recall. The invention designs tasks for Mashup and Web API call matching rating prediction, Mashup and Web API category matching rating prediction, Web API category prediction, and Mashup category prediction, all simultaneously learning interaction and category information. Leveraging the attention-focusing and feature-stealing characteristics of multi-task learning, the feature vectors of Mashup and Web API descriptions of the same category are closer in representation and have higher similarity in the vector space. This prompts the model to focus on category-level semantic association information while sharing this feature knowledge and functional-level semantic details, thus accurately recommending Web APIs with no or low interaction in historical data but high matching degree, thereby improving recommendation accuracy and recall. Attached Figure Description

[0066] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0067] Figure 1This is a flowchart of the method of the present invention.

[0068] Figure 2 This is a comparison chart of the Recall metrics for the two methods in this embodiment of the invention.

[0069] Figure 3 This is a comparison chart of the Precision index of the two methods in the embodiments of the present invention.

[0070] Figure 4 This is a comparison chart of the F1 scores of the two methods in the embodiments of the present invention.

[0071] Figure 5 This is a comparison chart of the MAP index of the two methods in the embodiments of the present invention. Detailed Implementation

[0072] To enable those skilled in the art to better understand the present invention, the technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings of the embodiments of the present invention. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. 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.

[0073] It should be noted that the terms "first," "second," etc., in the specification, claims, and accompanying drawings of this invention are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of the invention described herein can be implemented in orders other than those illustrated or described herein. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover a non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.

[0074] like Figure 1 As shown, this invention provides a Web API recommendation method based on a multi-task deep neural network, comprising the following steps:

[0075] S1: Clean the Mashup description document and the Web API description document.

[0076] Web API description documents are unprocessed text containing various symbols and special characters for easy expression. To allow the model to focus on learning text features and reduce interference from other information, the text data of the description documents needs to be cleaned by removing stop words, emoticons, and special characters to facilitate subsequent semantic analysis.

[0077] The Mashup and Web API dataset includes: Mashup name, Mashup category, Mashup description document, Web API called by the Mashup, Web API name, Web API category, and Web API description document.

[0078] The cleaning method involves deleting stop words, emoticons, and special symbols from the document.

[0079] S2: Map text information to numerical codes.

[0080] Non-numeric information such as service categories, Web API names, and Mashup names are converted into numerical values ​​and mapped to service category tags, Web API codes, and Mashup codes, respectively. Based on the call relationship between Mashups and Web APIs, a Mashup-Web API call relationship encoding table is generated. Using the BERT model's word segmentation tool, the Mashup description documents and Web API description documents are segmented to obtain their respective word codes.

[0081] S3: Generate sample data.

[0082] The multi-task deep neural network includes four tasks: Mashup and Web API call matching score prediction, Mashup and Web API category matching score prediction, Web API category prediction, and Mashup category prediction. Each task layer has different input data types and computation methods, therefore, it is necessary to extract the information required for each task and generate sample data. The detailed process is as follows:

[0083] (1) Combine the Mashup encoding, the word segmentation encoding of the Mashup description document, the Mashup category label and the task category label to generate training samples for the Mashup category prediction task.

[0084] (2) Combine the Web API encoding, the word segmentation encoding of the Web API description document, the category label of the Web API, and the task category label to generate training samples for the Web API category prediction task;

[0085] (3) Combine the sentence pairs composed of Mashup encoding, Web API encoding, Mashup description document encoding and Web API description document encoding, the corresponding category matching labels and task category labels to obtain training samples for the Mashup and Web API category matching prediction task. A category matching label of 1 indicates that the Mashup and Web API categories match, and a category label of 0 indicates that the Mashup and Web API categories do not match.

[0086] (4) Combine the sentence pairs composed of Mashup encoding, Web API encoding, Mashup description document encoding and Web API description document encoding, the corresponding call relationship labels and task category labels to obtain training samples for the Mashup and Web API call matching prediction task. The call relationship label is 1 to indicate that Mashup and Web API have a call relationship, and 0 to indicate that Mashup and Web API have no call relationship.

[0087] S4: Construct a Web API recommendation model based on a multi-task deep neural network

[0088] Since different tasks may be related, but may also conflict, leading to a decrease in model performance, it is necessary to design relevant auxiliary tasks. This fully utilizes the features of multi-task learning, such as implicit data augmentation, attention focusing, feature eavesdropping, inductive bias, and regularization, to improve the extraction of text features by sharing information, thereby improving the recommendation effect.

[0089] The Web API recommendation model constructed in this invention based on a multi-task deep neural network consists of five layers: a BERT-based text semantic feature extraction layer, a Mashup and Web API call matching score prediction task layer, a Mashup and Web API category matching score prediction task layer, a Web API category prediction task layer, and a Mashup category prediction task layer. The four task layers share the parameters of the BERT-based text semantic feature extraction layer.

[0090] The four task layers mentioned above are fully connected layers. The corresponding task prediction result P is calculated according to formula (1). t .

[0091]

[0092] Where x is the semantic feature output by the BERT-based text semantic feature extraction layer, t is the task type, and W... t It is the parameter matrix of the fully connected layer corresponding to task t.

[0093] (1) Text semantic feature extraction layer based on BERT

[0094] Since each Mashup and Web API description text contains a large amount of feature information, BERT is used to mine the semantic features of Mashup or Web API description text sentences.

[0095] (2) Mashup and Web API call matching score prediction task layer

[0096] When a Mashup developer calls a Web API, they need to consider the consistency between the functionality described in the Web API description and their development requirements. However, simply using a natural language processing model to calculate text similarity only considers the co-occurrence frequency and distribution of words and the similarity of word vectors, without considering the call relationship that reflects the actual application utility. This makes it difficult to learn high-quality functional-level semantic features. This invention designs a Mashup and Web API call matching and scoring prediction task. Mashups and Web APIs with call relationships are used as positive samples, while those without call relationships are used as negative samples. The actual call matching relationship between the two is used to assist the model in learning functional-level semantic features.

[0097] For sentence pairs consisting of Mashup and Web API description text, the semantic features x are extracted using the BERT semantic feature extraction layer. The probability P that Mashup and Web API have a call matching relationship is calculated according to formula (1). r The task loss is calculated using the Cross-Entropy Loss Function (CE) as shown in Formula (2), and the parameter matrix of the network corresponding to the task layer is adjusted according to the loss.

[0098]

[0099] Where x i Let represent the i-th sample data of the Mashup and Web API call matching rating prediction task, i.e., the sentence pair consisting of the Mashup and the Web API description text, where p is the probability distribution of the true result and q is the probability distribution of the predicted result.

[0100] (3) Mashup and Web API category matching and score prediction task layer

[0101] Since a Mashup typically calls only 1-3 Web APIs, while there are many Web APIs that match a Mashup's category, using it as an auxiliary task can significantly expand the training data. This invention designs a Mashup and Web API category matching scoring prediction task, using Mashups and Web APIs of the same category as positive samples and those of different categories as negative samples. This makes the feature vectors of Mashups and Web APIs of the same category closer in representation and more similar in vector space, enabling the model to delve deeper into higher-order category-level semantic association information, sharing this feature knowledge and functional-level semantic details. This aids in learning the matching features, effectively "eavesdropping" on features, ultimately allowing the model to learn and extract more comprehensive semantic features of Mashups and Web APIs.

[0102] For sentence pairs consisting of Mashup and Web API, the semantic features x are extracted using the BERT semantic feature extraction layer, and the probability P that Mashup and Web API have a category matching relationship is calculated according to formula (1). c .

[0103] The task loss is calculated using the cross-entropy loss function CE as shown in formula (2).

[0104] Where x i Let represent the i-th sample data of the Mashup and Web API category matching rating prediction task, i.e., the sentence pair consisting of Mashup and Web API description text, p is the probability distribution of the true result, and q is the probability distribution of the predicted result.

[0105] (4) Web API Category Prediction Task Layer

[0106] Since Web API descriptions within the same category often share similar linguistic descriptions, predicting the category of a Web API helps the model learn the semantic features of that category, discarding noise and other unimportant information in the descriptive language, thus achieving a focus effect. This invention designs a Web API classification task, using the classification of Web API description documents to train the model and improve its ability to capture category-level semantic information.

[0107] For the Web API description text, the semantic features x of the Web API description statement are extracted using the BERT semantic feature extraction layer, and the probability distribution P of the Web API belonging to each category is calculated according to formula (1). a =[P1,P2,P i ,...,P n ], where n is the total number of categories, P iThis represents the probability that the Web API belongs to the i-th category, and P is selected according to formula (3). a The category with the highest probability value This is the result predicted for this Web API category.

[0108]

[0109] in, It is the category prediction result. Indicates selecting P a The index with the highest probability value.

[0110] The task loss is calculated using the cross-entropy loss function CE as shown in formula (2).

[0111] Where x i Let represent the i-th sample data of the Web API category prediction task, i.e., the Web API description text, p is the probability distribution of the true result, and q is the probability distribution of the predicted result.

[0112] (5) Mashup category prediction task layer

[0113] This task is similar to the Web API category prediction task. Its design allows the model to focus on category-level semantic information, and learning simultaneously with the Web API category prediction task helps align the contextual differences between Mashup requirements and Web API description text. However, unlike Web API category prediction, Mashup functionality is diverse and may belong to multiple categories; therefore, Mashup category prediction is designed as a multi-label classification task.

[0114] For the Mashup description text, the semantic features x generated by the BERT semantic feature extraction layer are used to predict the probability distribution P of the Mashup belonging to each category according to formula (1). m =[P1,P2,P i ,...,P n ], where n is the total number of categories, P i This represents the probability that the Mashup belongs to the i-th category.

[0115] Since this is a multi-label classification task and the number of categories is uncertain, a threshold method is used to determine the category to which the Mashup belongs. The threshold is set to θ, and for P... m The probability value P corresponding to the i-th category i If P i If the value is greater than θ, then the Mashup is determined to belong to the i-th category.

[0116] The task loss is calculated using the binary cross-entropy loss function (BCE) as shown in formula (4).

[0117]

[0118] Among them, y i q represents the true binary label of the i-th sample data in the Mashup class prediction task, with a value of 0 or 1. i It is the probability that the i-th sample is a positive sample.

[0119] S5: A pre-trained Web API recommendation model based on a multi-task deep neural network.

[0120] To fully exploit the semantic features of Mashup description documents and Web API description documents, obtain high-quality feature vectors, and use them to calculate matching scores, it is necessary to pre-train the Web API recommendation model based on a multi-task deep neural network constructed in step four.

[0121] Suppose there are n tasks of different types, the current task is denoted as t, and the input data for pre-training is the set of sample data for each task generated in step three, T1, T2, ..., T. n Dataset T for task t t In the middle, each sample r i denoted as a triple (s i ,l i ,c i ), where i represents the i-th sample, s i This represents the text data of the sample, l i c represents the true value label of this sample. i This indicates the task type of this sample.

[0122] The detailed process of pre-training a Web API recommendation model based on a multi-task deep neural network is as follows.

[0123] In the pre-training phase, samples for each task are first acquired, and these samples are divided into mini-batches, then merged and shuffled. Then, a mini-batch of data b is randomly selected. t The text data set S of this batch of samples is input into a BERT-based semantic feature extraction layer to extract the contextual semantic features of the text data, resulting in a semantic feature set X for the samples. Based on the task type C recorded in the sample data of this batch, X is input into the corresponding task layer to obtain the predicted value for that task. Finally, the loss for the corresponding task type is calculated using the loss function, and the model parameters are updated using stochastic gradient descent (SGD) until each b... t After all epochs have been selected, one epoch of pre-training is completed. Pre-training ends after all epochs are completed.

[0124] S6: Fine-tune the Web API recommendation model using Mashup and API matching rating prediction tasks.

[0125] Pre-trained Web API recommendation models can learn features that perform well on multiple tasks. However, different tasks converge at different speeds; some tasks are simple and converge quickly, while others converge slowly. This leads to some tasks becoming overfitted and others underfitting after a certain number of training epochs. To maximize the accuracy of matching rating prediction and make the model focus more on learning fine-grained matching features between Mashup requirements and Web API descriptions, thereby improving recommendation accuracy, the pre-trained Web API recommendation model is fine-tuned using a Mashup and Web API matching rating prediction task. The detailed process is as follows:

[0126] (1) Obtain fine-tuning samples;

[0127] (2) Input the text data of the fine-tuning sample of the Mashup and Web API matching score prediction task into the BERT semantic feature extraction layer to extract the feature vectors of the Mashup text data and the Web API text data;

[0128] (3) Input the feature vectors of Mashup text data and Web API text data into this task layer to predict the matching score between Mashup and Web API;

[0129] (4) Calculate the task loss using the cross-entropy loss function based on the predicted and actual values;

[0130] (5) Use stochastic gradient descent to update the model parameters based on the task loss;

[0131] (6) Repeat the steps described in (2) to (5) above until each sample has been selected, thus completing one epoch of fine-tuning training. After completing all epochs, the fine-tuning ends, and the Mashup and Web API matching score prediction model is obtained.

[0132] S7: Predict Mashup demand and match scores with various Web APIs.

[0133] The Mashup request and the description text of each Web API are combined into sentence pairs, which are then input into a fine-tuned Mashup and Web API matching score prediction model to obtain a list of matching scores between the Mashup request and each Web API.

[0134] S8: Sort the Mashup requirements with the matching scores of each Web API to obtain the recommendation results.

[0135] To obtain the final recommendation results, the matching score list of Mashup requests and each Web API needs to be sorted in descending order of matching score, and the top K Web APIs are selected to form the final recommendation list, where K is the number of recommendations that can be set arbitrarily.

[0136] Example

[0137] To verify the effectiveness of the proposed method, a series of experiments were conducted on real-world service datasets, and the recommendation results were evaluated using common evaluation metrics for Web API recommendation problems.

[0138] (1) Dataset selection and experimental setup

[0139] The dataset used in this invention is real service data crawled from the ProgrammableWeb website, specifically including information such as the name, description document, and category of the Mashup and Web API. The Mashup dataset includes the name, description document, category of the Mashup, and the name of the Web API it calls. The Web API dataset includes the name, description document, and category of the Web API.

[0140] In this invention, 80% of the dataset is used as the training set for model training, 10% as the validation set for model parameter tuning, and 10% as the test set for verifying model performance.

[0141] (2) Evaluation indicators

[0142] The following provides formal definitions for four evaluation metrics: Precision, Recall, F1 Score, and Mean Average Precision (MAP).

[0143] 1) Precision: This is the ratio of the number of correctly recommended Web APIs to the total number of recommended Web APIs, also known as precision. In other words, of the recommended Web APIs, how many are actually called by the Mashup? The precision calculation formula is shown in Formula (5), where R(u) is the recommendation result, and T(u) is the set of Web APIs actually called by the Mashup on the test set. The higher the precision, the better the recommendation effect.

[0144]

[0145] 2) Recall: This is the ratio of the number of correctly recommended Web APIs to all Web APIs actually called by the Mashup, also known as recall rate. In other words, of the Web APIs actually called by the Mashup, how many were actually recommended? The recall rate calculation formula is shown in formula (6), where R(u) is the recommendation result, and T(u) is the set of Web APIs actually called by the Mashup on the test set. The higher the recall, the better the recommendation effect.

[0146]

[0147] 3) F1: F1 is the weighted harmonic mean of precision and recall, calculated as shown in formula (7), where P is precision and R is recall. Since precision and recall are negatively correlated and depend on the length of the recommendation list, they are mutually constrained. Therefore, the F1 metric is used to comprehensively consider precision and recall. The larger the F1, the better the recommendation effect.

[0148]

[0149] 4) MAP: Sensitive to the recommendation order, calculated as shown in formula (8), where K is the length of the recommendation list, m is the number of correctly recommended Web APIs, P(k) refers to the precision from the first-ranked Web API to the k-th ranked Web API in the recommendation list, and rel(k) indicates whether the k-th ranked Web API was correctly recommended. The larger the MAP, the better the recommendation effect.

[0150]

[0151] (3) Experimental Comparison Analysis

[0152] This invention presents comparative experiments in two parts. The first part is an ablation experiment, comparing the proposed Web API recommendation method based on multi-task deep neural networks with single-task recommendation methods. The second part is a comparative analysis of conventional experiments, comparing the proposed method with current mainstream methods.

[0153] 1) Ablation experiment

[0154] This invention utilizes the concept of multi-task learning, designing multiple related tasks to construct a multi-task deep neural network for pre-training a Web API recommendation model. The Mashup and Web API matching and rating tasks are then used as downstream tasks for fine-tuning, improving the accuracy of rating prediction and thus enhancing recommendation performance. Therefore, to verify the effectiveness of the proposed method, ablation experiments were designed to compare the performance of the multi-task method with that of the single-task method. Typically, the Mashup calls approximately four Web APIs; therefore, a recommendation list length K of 4 is most representative. The experimental results are shown in Table 1.

[0155] Table 1 Ablation Experiment Results

[0156]

[0157] As shown in Table 1, when K=4, the method proposed in this invention improves all indicators, with a 12.24% increase in recall, a 3.72% increase in precision, a 5.50% increase in F1 score, and a 13.30% increase in MAP. This indicates that the method proposed in this invention has better recommendation performance. This is because the present invention designs multiple related tasks to construct a multi-task deep neural network. Compared with models that rely on only a single task, the pre-training stage can achieve implicit data augmentation, expanding the training samples of the model without directly adding extra datasets, increasing data diversity, and providing richer contextual information for model learning. Furthermore, the simultaneous learning of category-related and interaction-related tasks enables the model to not only learn functional-level semantic feature representations but also to delve into higher-order category-level semantic associations. This refined feature learning mechanism allows the model to obtain higher-quality semantic feature representations. Finally, the Web API recommendation model is further fine-tuned through Mashup and Web API matching and scoring tasks to obtain the Mashup and Web API matching and scoring prediction model. The scoring accuracy of the model in specific recommendation scenarios is specifically optimized to ensure that the model performs optimally in actual scoring prediction, ultimately improving performance indicators such as recommendation recall and accuracy.

[0158] 2) Comparative Experiment

[0159] To verify the effectiveness of the proposed method, the state-of-the-art Mashup-oriented Web API recommendation method (MTFM) based on multi-model fusion and multi-task learning was selected as the baseline method. MTFM first extracts features using semantic components and feature interaction components respectively, then concatenates the extracted features from the two aspects, and finally uses the concatenated features to train two multi-label classification tasks: Web API recommendation and Mashup classification, enabling the model to have multi-task learning capabilities.

[0160] In recommendation scenarios, the length K of the recommendation list significantly impacts the evaluation of recommendation performance. A smaller K value assesses performance when fewer recommendation targets are provided, which is crucial for users who want to choose from a small number of high-confidence recommendations. Conversely, a larger K value assesses performance when longer recommendation lists are provided, which is meaningful for users who need more choices or want to explore more possibilities. Therefore, to comprehensively evaluate the performance of the two methods under different recommendation list lengths, the performance of Recall, Precision, F1, and MAP metrics were compared for recommendation list lengths K of 1, 2, 3, 4, 5, 10, 20, and 30. The comparison results are as follows: Figures 2-5 As shown.

[0161] As can be seen, when the recommendation list length K is 1, 2, 3, 4, 5, 10, 20, and 30, the recall rate of this invention is improved by 11.94%, 12.93%, 14.88%, 17.11%, 18.05%, 14.56%, 16.2%, and 16.05%, respectively, with an average improvement of 15.22%; the precision rate is improved by 7.03%, 2.55%, 1.74%, 2.52%, 1.96%, and 0.82%, respectively. The recall rate increased by 0.57% and 0.24%, respectively, with an average improvement of 2.18%; the F1 score increased by 8.39%, 4.17%, 3.14%, 3.60%, 2.97%, 1.07%, 0.86%, and 0.37%, respectively, with an average improvement of 3.07%; and the mean average (MAP) increased by 7.03%, 6.44%, 8.20%, 8.10%, 8.75%, 8.52%, 8.03%, and 8.72%, respectively, with an average improvement of 7.97%. It can be seen that when K is between 1 and 5, the increase in recall rate increases continuously with the increase in the length of the recommendation list. When K is 10, the increase decreases because the recall rate is already high. Precision and F1 score decrease as K increases, so the improvement in these two metrics decreases with increasing K. The MAP improvement fluctuates between 7.03% and 8.75%. Overall, with varying recommendation numbers K, the proposed method demonstrates significant performance advantages across four evaluation metrics: recall, accuracy, F1 score, and MAP, proving the effectiveness of the proposed Web API recommendation method. The main reasons are as follows: First, this invention enables simultaneous learning across multiple tasks, achieving implicit data augmentation and expanding the sample size. Compared to MTFM, which only mines interaction features and functional semantic features, this method mines finer-grained category-level semantic associations within the semantic information, optimizing model learning capabilities and extracting higher-quality features. Second, the multi-task framework designed in this invention synchronously integrates the learning processes of interaction information and deep semantic information. Compared to MTFM, which only uses Mashup classification as an auxiliary task to leverage multi-task learning inductive bias, this method simultaneously learns category-level semantic associations and sparse functional-level semantic associations between Mashups and Web APIs. It utilizes the attention-focusing and feature-stealing characteristics of multi-task learning to encourage the model to concentrate on key category-level semantic associations while sharing these feature knowledge and functional-level semantic details, increasing the model's rating prediction accuracy and thus improving recommendation performance.

[0162] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, and not to limit them; although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some or all of the technical features; and these modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of the present invention.

Claims

1. A Web API recommendation method based on a multi-task deep neural network, characterized in that, Includes the following steps: S1. Obtain the Mashup and Web API datasets, which include Mashup names, Mashup categories, Mashup description documents, Web APIs called by the Mashup, Web API names, Web API categories, and Web API description documents; and clean the Mashup description documents and Web API description documents in the dataset by removing stop words, emojis, and special symbols from the documents. S2. Map the text information in the cleaned dataset into numerical codes; S3. Generate sample data for multiple tasks based on digital encoding; the multiple tasks include Mashup and Web API call matching score prediction task, Mashup and Web API category matching score prediction task, Web API category prediction task, and Mashup category prediction task. S4. Construct a multi-task deep neural network based on multiple tasks; the multi-task deep neural network includes a BERT-based text semantic feature extraction layer, a Mashup and Web API call matching score prediction task layer, a Mashup and Web API category matching score prediction task layer, a Web API category prediction task layer, and a Mashup category prediction task layer; construct a Web API recommendation model based on the multi-task deep neural network; S5. Input the sample data into the Web API recommendation model for pre-training to obtain the pre-trained Web API recommendation model; Suppose there are n tasks of different types, and the current task is denoted as n. The input data for pre-training is the set of task sample data generated in S3. ,Task dataset In each sample denoted as a triple ( ),in Indicates the first Sample, The text data of this sample, This indicates the true value label for that sample. This indicates the task type of the sample; Obtain samples for each task used for pre-training, divide these samples into small batches, and then merge and shuffle them. Randomly select a small batch of data The text data set of this batch of samples Input a BERT-based semantic feature extraction layer to extract contextual semantic features from the text data, resulting in a set of semantic features for the sample. And based on the task type recorded in the sample data of that batch. ,Will Input the corresponding task layer to obtain the predicted value for that task. ; Calculate the task loss using the loss function corresponding to the task type, and update the model parameters using stochastic gradient descent until each task is completed. After all epochs have been selected, one epoch of pre-training is completed. Pre-training ends after all epochs are completed. S6. Fine-tune the pre-trained Web API recommendation model using Mashup and API matching rating prediction tasks; S61. Obtain fine-tuning samples for the Mashup and Web API matching score prediction task; S62. Input the text data of the fine-tuned samples of the Mashup and Web API matching rating prediction task into the BERT semantic feature extraction layer to extract the feature vectors of the Mashup text data and the Web API text data. S63. Input the feature vectors of Mashup text data and Web API text data into this task layer to predict the matching score between Mashup and Web API. S64. Calculate the task loss using the cross-entropy loss function based on the predicted and actual values; S65. Use stochastic gradient descent to update model parameters based on task loss; S66, repeat S62~S65 until each sample has been selected, then complete 1 epoch of fine-tuning training. After completing all epochs, the fine-tuning ends, and the Mashup and Web API matching score prediction model is obtained. S7. Combine the Mashup requirements with the description text of each Web API to form sentence pairs, and input them into the fine-tuned Mashup and Web API matching score prediction model to obtain a list of matching scores between Mashup requirements and each Web API. S8. Sort the matching score list of Mashup requirements with each Web API in descending order of matching score, and select the top K Web APIs to form the final recommendation list.

2. The Web API recommendation method based on a multi-task deep neural network according to claim 1, characterized in that, S2 specifically includes the following steps: The service category, Web API name, and Mashup name are converted into numbers, and the service category is mapped to the service category label, the Web API name is mapped to the Web API code, and the Mashup name is mapped to the Mashup code. Based on the call relationship between Mashup and Web API, a Mashup-Web API call relationship encoding table is generated; using the BERT model's word segmentation tool, the Mashup description document and the Web API description document are segmented to obtain the word segmentation encoding of the Mashup description document and the Web API description document.

3. The Web API recommendation method based on a multi-task deep neural network according to claim 1, characterized in that, S3 specifically includes the following steps: The training samples for the Mashup category prediction task are generated by combining the Mashup encoding, the tokenization encoding of the Mashup description document, the Mashup category label, and the task category label. The Web API encoding, the word segmentation encoding of the Web API description document, the category label of the Web API, and the task category tag are combined to generate training samples for the Web API category prediction task; The training samples for the Mashup and Web API category matching prediction task are obtained by combining sentence pairs composed of Mashup encoding, Web API encoding, Mashup description document encoding and Web API description document encoding, the corresponding category matching labels and task category labels. A category matching label of 1 indicates that the Mashup and Web API categories match, and a category label of 0 indicates that the Mashup and Web API categories do not match. The training samples for the Mashup and Web API call matching prediction task are obtained by combining sentence pairs composed of Mashup encoding, Web API encoding, Mashup description document encoding and Web API description document encoding, the corresponding call relationship labels and task category labels. The call relationship label is 1 to indicate that there is a call relationship between Mashup and Web API, and 0 to indicate that there is no call relationship between Mashup and Web API.

4. The Web API recommendation method based on a multi-task deep neural network according to claim 1, characterized in that, In S4, the Web API recommendation model based on multi-task deep neural networks includes a BERT-based text semantic feature extraction layer and four task layers: Mashup and Web API call matching score prediction task layer, Mashup and Web API category matching score prediction task layer, Mashup and Web API category matching score prediction task layer, Web API category prediction task layer, and Mashup category prediction task layer. Among them, the four task layers share the parameters of the BERT-based text semantic feature extraction layer; The four task layers are fully connected layers, and the prediction results for the corresponding tasks are calculated according to the following formula. : (1) in, It is the semantic feature output by the text semantic feature extraction layer based on BERT. t It is the task type. It is the parameter matrix of the fully connected layer corresponding to task t.

5. The Web API recommendation method based on a multi-task deep neural network according to claim 3, characterized in that, In S4: BERT-based text semantic feature extraction layer: The BERT-based text semantic feature extraction layer uses BERT to mine the semantic features of Mashup or Web API-described text sentences; Mashup and Web API Call Matching and Scoring Prediction Task Layer: The Mashup and Web API call matching and scoring prediction task layer uses Mashups and Web APIs with call relationships as positive samples and Mashups and Web APIs without call relationships as negative samples, and uses the actual call matching relationship between the two to assist the model in learning functional-level semantic features. For sentence pairs consisting of Mashup and Web API description text, the semantic features are extracted using the BERT semantic feature extraction layer. The probability that Mashup and Web API have a call matching relationship is calculated according to formula (1). The task loss is calculated using the cross-entropy loss function shown in formula (2), and the parameter matrix of the network corresponding to the task layer is adjusted according to the loss. (2) in, This represents the i-th sample data in the Mashup and Web API call matching score prediction task, i.e., the sentence pair consisting of the Mashup and the Web API description text. It is the probability distribution of the true result. It is the probability distribution of the predicted results; Mashup and Web API category matching and scoring prediction task layer: For sentence pairs composed of Mashup and Web API, the semantic features are extracted using the BERT semantic feature extraction layer. The probability that Mashup and Web API have a category matching relationship is calculated according to formula (1). The task loss is calculated using the cross-entropy loss function shown in formula (2); in, This represents the i-th sample data from the Mashup and Web API category matching score prediction task, i.e., a sentence pair consisting of the Mashup and the Web API description text. It is the probability distribution of the true result. It is the probability distribution of the predicted results; Web API Category Prediction Task Layer: Extracts semantic features from the Web API description text using the BERT semantic feature extraction layer. The probability distribution of the Web API belonging to each category is calculated according to formula (1). ,in It is the total number of categories. This indicates that the Web API belongs to the first... The probabilities of each category are selected according to formula (3). The category with the highest probability value As a result of the prediction for this Web API category; (3) in, It is the category prediction result. Indicates selection The index with the highest probability value; The task loss is calculated using the cross-entropy loss function shown in formula (2); in, This represents the i-th sample data from the Web API category prediction task, i.e., the Web API description text. It is the probability distribution of the true result. It is the probability distribution of the predicted results; Mashup category prediction task layer: For Mashup description text, the semantic features of the Mashup description text generated by the BERT semantic feature extraction layer are used. Based on formula (1), predict the probability distribution of Mashup belonging to each category. ,in It is the total number of categories. This indicates that the Mashup belongs to the first... The probability of each category; The category of a Mashup is determined by setting a threshold, with the threshold set to θ. The Middle The probability value corresponding to each category ,like Then determine that Mashup belongs to the first... One category; The task loss is calculated using the binary cross-entropy loss function shown in formula (4): (4) in, Represents the first category prediction task in the Mashup category prediction task. The true binary label for each sample data point, with a value of either 0 or 1. Is it a prediction of the first The probability that a sample is a positive sample.

6. A storage medium, characterized in that, The storage medium includes a stored program, wherein, when the program is executed, it performs the Web API recommendation method based on a multi-task deep neural network as described in any one of claims 1 to 5.

7. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, The processor executes the Web API recommendation method based on a multi-task deep neural network as described in any one of claims 1 to 5 through the computer program.