Learning with Small Data: Subgraph Counting Queries

Deep Learning (DL) has been widely used in many applications, and its success is achieved with large training data. A key issue is how to provide a DL solution when there is no large training data to learn initially. In this paper, we explore a meta-learning approach for a specific problem, subgraph isomorphism counting, which is a fundamental problem in graph analysis to count the number of a given pattern graph, p, in a data graph, g, that matches p. There are various data graphs and pattern graphs. A subgraph isomorphism counting query is specified by a pair, (g, p). This problem is NP-hard and needs large training data to learn by DL in nature. We design a Gaussian Process (GP) model which combines Graph Neural Network with Bayesian nonparametric, and we train the GP by a meta-learning algorithm on a small set of training data. By meta-learning, we can obtain a generalized meta-model to better encode the information of data and pattern graphs and capture the prior of small tasks. With the meta-model learned, we handle a collection of pairs (g, p), as a task, where some pairs may be associated with the ground-truth, and some pairs are the queries to answer. There are two cases. One is there are some with ground-truth (few-shot), and one is there is none with ground-truth (zero-shot). We provide our solutions for both. In particular, for zero-shot, we propose a new data-driven approach to predict the count values. Note that zero-shot learning for our regression tasks is difficult, and there is no hands-on solution in the literature. We conducted extensive experimental studies to confirm that our approach is robust to model degeneration on small training data, and our meta-model can fast adapt to new queries by few-shot and zero-shot learning.


Introduction
Deep learning (DL) has achieved great success in database systems to support query optimization [31], index recommendation [12], view materialization [27], cardinality estimation [13,25], and subgraph counting [28,65].The two main keys that lead to the success of deploying DL effectively to deal with real problems are (1) to learn an advanced model that meets the problem, and (2) to learn with large training data.Almost all the works focus on modeling techniques assuming that it is possible to collect enough training data to learn.Take query optimization as an example, training a feed-forward neural network consumes 20,000 unique queries over a fixed database schema [13].A natural question that arises is what a system can do if there are only a few training data to learn a model that can be effectively used.The solution rules out learning a model until the training dataset is large.This problem is important because a system needs to support various needs from time to time, and it is the last thing that the system responses negative if there is no sufficient training data to learn.To address this issue, it requires an approach by meta-learning.That is to learn a model and refine the model with limited or even no training data if any from time to time.We will discuss it with a specific problem in database, as it is difficult to come up with a general solution to deal with the requirement of sufficient training at this stage.
As a specific problem, in this paper, we study a subgraph isomorphism counting query that has been widely used in many applications in bioinformatics, chemoinformatics, and social network analysis [28].Such a query is specified by a pair of (g, p), where g is a data graph and p is a pattern graph, and is to find the number of matches of p in g.This problem itself is NP-hard [8] and is difficult to learn.In general, over a set of data graphs, G = {g 1 , g 2 , … , g n } , there is a set of pattern graphs P = ∪ 1≤i≤n P(g i ) where P(g i ) is a set of pattern graphs associ- ated with g i .In [28], a DL model is trained by feeding a large number of training pairs (g, p), aiming to be well generalized on unseen test pairs (g * , p * ) .The DL model consumes hundreds of thousands of pairs, and for each graph g i , its P(g i ) is large enough.The issue that arises is how to collect a sufficiently large training dataset to synthesize comprehensive features to be learned.In real applications, the data graph may come from different domains, and the pattern graphs may be diverse regarding the sizes, node/edge labels, and structures.For example, in computational biology, the data graphs could be the molecules in many drug banks, which have different scaffolds.The pattern graphs are functional groups which are a large combination of different numbers and types of atoms/bonds.
Hence, it is impractical to learn a model for given G and Q with limited training pairs, and it is impractical to learn a model for each data graph g i with its pattern graphs P(g i ) .To deal with such a dilemma, we construct a meta-model for given G and P , which learns the prior knowledge of subgraph counting across multiple tasks.Consider an encountered task, i.e., a collection of pairs, where some pairs may be with ground-truth (e.g., the exact number of matchings), and some pairs need to answer.With some possible pairs with ground-truth (known as shots), the meta-model can be swiftly adapted to deal with the other pairs in the task that need to answer.Inspired by deep kernel learning and deep kernel transfer [39,57], we devise a new meta-model that warps a graph neural network (GNN) as a special Gaussian Process (GP).For one thing, the graph neural network preserves the powerful modeling capability of deep learning for subgraph counting.For the other thing, Bayesian nonparametric, inherited by GP, enables learning from scratch over small samples with a distribution-free assumption, and the prior of structural subgraph counting tasks are captured via optimizing the prior of the GP.Furthermore, as there may be no pair in a task with ground-truth (zero-shot), we adapt the kernel-based meta-learning algorithm to support zero-shot cases in a data-driven fashion.It is worth mentioning that zero-shot learning for regression tasks is difficult, and there is no handson solution in the literature.The contributions of this paper are summarized as follows: • We study a specific problem of subgraph isomorphism counting in a paradigm of meta-learning to address the initial small training data issue in DL.We propose a Gaussian Process model, called RGIN-GP, that combines graph neural network and kernel method, aiming to learn over small training data.• We employ a meta-learning algorithm to train a meta-RGIN-GP model over a small set of training data.The small training dataset is divided into tasks, where a task is a collection of (g, p) pairs, for the purpose of predicting a new counting task that may share the similar task structure.• We provide solutions for both few-shot and zero-shot cases to deal with a new subgraph counting task.In particular, for zero-shot, we propose a new data-driven approach to predict the count values for a new task without any ground-truth.

Preliminaries
We model both data graph g and pattern graph p as a labeled undirected graph as a tuple Here, V is a set of nodes, E is a set of undirected edges, and L V ( L E ) is a mapping function that maps a node u ∈ V (edge e ∈ E ) to a node label (edge label) in Σ V ( Σ E ).We denote neighbors of node u in G as , where V f is the set of nodes by f(u) for every u in V p , and E f is the set of edges by (f(u), f(v)) for every edge (u, v) in E p .We say g f is a subgraph isomorphism matching of p to g. Finding the subgraph isomorphism matching for given p and g is computationally hard as the decision problem of subgraph isomorphism is NP-complete [8].
Subgraph Isomorphism Counting Query: Given a pair of data graph g and a pattern graph p, a subgraph isomorphism counting query is to find the total number of subgraph isomorphism matchings of p to g, denoted as c(g, p).Here, a node in p is allowed to be unlabeled.When a node in p is unlabeled, a special label, interpreted as any, is assigned.A graph database is a set of small/medium sized graphs, G = {g 1 , g 2 , … , g n } , with a set of pattern graphs P = ∪ 1≤i≤n P(g i ) , where P(g i ) is a set of pattern graphs associated with g i .For simplicity, we also use P = {p 1 , p 2 , … , p m } to denote the whole possible set of pat- terns.A subgraph isomorphism counting query is a pair of (g, p) such that g ∈ G , and p ∈ P(g).
A machine learning model can be built from a set of pairs of data graph and pattern graph X = {x 1 , x 2 , … x |X| } , where x i is a pair of data and pattern graphs, x i = (g i , p i ) , with the corresponding true count denoted as c(x i ) (or c(g i , p i ) ) for all 1 ≤ i ≤ |X| .A true count is the exact count of subgraph isomorphism matching of p i in g i .The model will take an unseen pair x * = (g * , p * ) , and estimate its count ĉ(g * , p * ) .In estimation, the pair x * = (g * , p * ) is not seen in the train- ing set, where either g * or q * may appear in the training set.We use the absolute error to evaluate the accuracy of the estimated value.
Note that the model can answer the subgraph isomorphism query, i.e., whether p * is subgraph isomorphism to g * by ĉ(g * , p * ) > 0.5.

Problem Statement:
The problem is first to build a model M to support subgraph isomorphism counting queries, when the size of the training set is not large enough.Then, in testing M , there are new tasks coming, where a task T * is the union of two subsets, S * and Q * , denoted as T * = (S * , Q * ) , where S * is a support set with ground-truth such that , where c(g * i , p * i ) for each i is given, and Q * is a query set to be answered each such that Note that S * may be empty, i.e., l = 0 (called zero-shot), and is small in size when it is non-empty, i.e., l < k (called few-shot).The problem is how to enhance M to answer queries in Q * on-demand with the assistance of S * which may be empty.

A Model Learned with Large Data
Recently, a learning framework has been proposed for the subgraph isomorphism counting of a pair of data and pattern graphs in [28].This neural network framework is composed of graph representation layers, interaction layers, and Multilayer perceptron (MLP), to learn M with a large training data X.The graph representation layers take the labeled data and pattern graph as input and generate vector representation for the data graph and pattern graph, respectively.The interaction layer combines the two representations into one representation and the MLP finally outputs the estimated count.[28] explores different options for the graph representation layers (i.e., CNN [24], LSTM [20], Transformer-XL [10], Graph Neural Networks (GNN) [47,59]) and for the interaction layers (i.e., sum/mean/max pooling, multihead attention [52] and dynamic intermedium attention).
Regarding the trade-off between prediction accuracy and efficiency, a GNN variant, Relational Graph Isomorphism Network (RGIN), coupled with sum pooling interaction performs best in [28].Below, we introduce RGIN which we adopt to build a neural network.

RGIN Graph Representation.
The K-layer GNN [18,53,59] follows a neighborhood aggregation paradigm to update the representation of a node by aggregating the representations of its neighbors in K iterations.Let (k) v denote the representation of a node v generated in the k-th iteration.In the GNN k-th iteration (layer), for a node v, an aggregate function f (k)  A (⋅) aggregates the representations of the neighbors of v that are generated in the (k-1)-th iteration as Eq. ( 2).Then, a combine function f (k)  C (⋅) updates the representation of v by the aggregated representation a (k)  v and the previous representation (k−1) v itself as Eq.(3).The functions f (k)  A (⋅) and f (k)  C (⋅) are neural networks, e.g., linear transformation with nonlinearity and optional Dropout [49] for preventing overfitting.
Take the RGIN layer as an example, for each node v, the aggregate function in Eq. ( 4) distinguishes its neighbors by the edge label, and aggregates the |Σ E | types of neighbors respectively.W (k)  l is the weight matrix for the neighbors with edge label l in the k-th layer and the |L E | types aggregation are further summed up.In the combine function of Eq. ( 5), the aggregated a (k)  v is summed up with the (k − 1)-layer repre- sentation e (k−1) v , which transformed by weigh W (k)  0 , and finally be transformed by an MLP layer. (2) For the data graph g and pattern graph p, there are two independent K-layer RGIN models that generate the |V g | × d-dim data graph node embedding and |V p | × d-dim pattern graph node embedding of the K-th layer, respectively.Sum Pooling Interaction.After obtaining the data graph and pattern graph representations, the interaction layer is to combine the two representations to one pair-wise representation.The sum pooling interaction sums up the node embedding of the data and pattern graphs, respectively, and simply concatenates the two vectors to a long vector, as shown in Eq. ( 6).
The concatenated vector h will pass an MLP to generate the prediction ĉ(g, p) .The experimental study in [28] shows that although the sum pooling is simple, it is easy to train and achieve the approaching accuracy of the dynamic intermedium attention memory interaction (DIAMNet) and is two times faster than DIAMNet.In contrast, complex interaction layer such as DIAMNet and multi-head attention are hard to train and face the risk of overfitting.To train the DL models, [28] adopts the mean-squared-error loss.

A Meta-Learning Approach
We explore a meta-learning approach to build a metacounting model M .Here, the main problem is to answer each pair in Q * from a new coming task T * = (S * , Q * ) by M built with limited training data X = {x 1 , x 2 , … , x |X| } , where each x i = (g i , p i ) in X is with the ground-truth c(x i ) .To capture the prior knowledge by the meta-model that is persisted with task-common parameters, the initial training data, X, is disjointly distributed into multiple training tasks, D = {T 1 , … , T n } .Here, a task T i is also a pair, T i = (S i , Q i ) .Different from T * , we have ground-truth for both S i and Q i .A meta-learning algorithm is to learn the knowledge prior over multiple tasks which may exhibit some specific task structure.
Figure 1 presents the overview of the meta training and testing procedures.In training, for each task T i with a small number of pairs to train, we use RGIN-GP (RGIN Gaussian Process) to construct a kernel , which is specified by a deep neural network parameter w and a stationary kernel with hyperparameter .As illustrated in (Fig. 1a), a task T i is presented with multiple data graphs ( G i ) and multiple pattern graphs ( P i ), and the meta-model is a Gaussian Process whose parameters are trained by gradient descent task by task.With the kernel built with w and , in testing for a new incoming task there are two cases.One is few-shot where |S * | is small but is nonzero, and one is zero-shot where |S * | = 0 .For few-shot testing, the meta-model leverages the kernel matrix of the whole task to make a prediction for the query set (Fig. 1b).For zero-shot test, we take a datadriven approach to build the kernel by making use of one task, T i , drawn from the training data (Fig. 1c).In this work, meta-testing is not to refine the meta-model built with w and .The meta-model built remains unaffected.
With a new task, T * = (S * , Q * ) , it is to answer queries in Q * by Bayesian inference with additional S * , which we will discuss later.
The approach we take is based on an optimization-based Bayesian meta-learning algorithm, Deep Kernel Transfer [39], for four reasons, where two reasons are from the perspective of training algorithms, and two are from the perspective of model characteristics.From the perspective of training, first, as an optimization-based approach, DKT directly optimizes the task-common parameters by processing one task at a time via stochastic gradient descent, which is effective to learn the task-level prior knowledge.Second, the model can be learned by one-level gradient descent, which is more efficient and stable than classical bi-level meta-learning algorithms, e.g., MAML [15].From the perspective of the model, third, by leveraging DKL, the proposed GP model, RGIN-GP, is suitable for modeling small data and naturally endorses regression tasks, exploiting the main advantages of GP.Fourth, as a GP model which adapts Bayesian inference for prediction, RGIN-GP can provide robust prediction and principled uncertainty quantification derived from Bayesian method.In the following, we present how to deploy a kernel for a task, which exploits deep neural network transformation (Sect.3.1), how to train the kernel and test in the few-shot and zero-shot scenarios (Sect.3.2), and how to encode the input pairs (Sect.3.3).

RGIN Gaussian Process (RGIN-GP)
To learn over a small set of samples, nonparametric modeling is an effective method in Bayesian learning.Deep Kernel Learning (DKL) [45,57] provides a way to integrate Bayesian nonparametric into deep learning models.It constructs a special GP model which has a conventional stationary kernel function, e.g., the RBF kernel, but the input features space is the embedding space of deep learning models.The hyperparameters of the kernel and the parameters of the deep learning model can be jointly optimized by stochastic gradient descent.Inspired by this, we adopt RGIN with sum pooling layer as the deep learning model that transforms the data and pattern graph into the input vector embedding for a stationary kernel, and the RGIN-GP derives from the deep kernel function constructed as follows.Given an input x = (g, p) as a pair of data and pat- tern graphs, the deep kernel function measures the similarity of a pair of inputs x i , x j as Here, F(x;w) is a nonlinear transformation specified by a deep neural network with parameters w, i.e., the RGIN together with the sum pooling interaction layer.And the function K(h i , h j ; ) is a stationary kernel function that is invariant to input transformation with the hyperparameter , e.g., the RBF kernel.In a nutshell, the neural network F(x;w) is responsible for learning an effective intermediate representation h to capture the non-stationary and hierarchical features of the input.Then, the kernel K(h i , h j ; ) discovery stationary structure by an interpretable basis function.
Given n training inputs, X = {x 1 , … , x n } , the deep kernel defined in Eq. ( 7), the model f(X) is a Gaussian Process as Eq. ( 8) [43] that we call RGIN-GP, where X = [ ] n is an assumed constant mean and X,X = [ (x i , x j ;w, )] n×n is the covariance function.
To make prediction for the testing inputs X * = {x * 1 , … x * m } , we need to compute the conditional distribution p(f (X * )|f (X)) as the prediction, assuming the output is dis- turbed by a Gaussian noise N(0, 2 ) .It is also proved to be a Gaussian distribution as Eq. ( 9), where the expectation and covariance of the predictive distribution can be solved in closed form in Eqs.(10), (11).( 7) Here, c = [c(x i )] n is the ground-truth vector of the input X.The matrices X,X = [ (x i , x j ;w, )] n×n , X,X * = [ (x i , x * j ; w, )] n×m and X * ,X * = [ (x * i , x * j ; w, )] m×m are the train-train, train-test, test-test kernels, respectively.The expectation (c * ) will be treated as the explicit prediction counts ĉ , and the diagonal element of matrix C in Eq. ( 11) measures the variance of the prediction.Meanwhile, we can easily comp u t e t h e -c o n f i d e n t i a l i n t e r va l o f ĉ a s [ĉ − q diag(C), ĉ + q diag(C)] , where q is the -quantile of N(0, 1).
The predictive distribution highly depends on the kernel matrix , which is determined by the neural network weight w and the stationary kernel hyperparameter .Training the kernel is to infer these parameters to adapt to the training data.The optimization is conducted by minimizing the negative marginal (log) likelihood of the training data X.
There is no analytical solution for optimizing the loss of Eq. ( 12), but the objective is differentiable.To train an RGIN-GP, the neural network weights w and the kernel hyperparameter are jointly optimized by stochastic gradient descent.We use the spectral mixtures base kernels [56] as the stationary kernel function K since the kernel is able to approximate continuous stationary kernels to an arbitrary precision given sufficient number of mixtures.

Meta-Learning for RGIN-GP
In this section, we discuss how to train an RGIN-GP as a meta-model and test it in the few-shot and zero-shot scenarios.In real applications, new tasks may arrive in different ways, since the data graph may come from different domains, and the pattern graphs may be diverse regarding the sizes, node/edge labels, and structures.In this paper, we firstly explore the following 5 task configurations where a single variable (e.g., a data/pattern graph) is controlled.Here, given a training data X, we have a set of data graphs, G = {g 1 , g 2 , … , g n } , and a set of pattern graphs, ( 9) The graphs in G may come from dif- ferent domains.Instead of specifying a task as T i = (S i , Q i ) , below, for the task structure configuration, we specify a task T i = (G i , P i ) , where G i ⊂ G and P i ⊂ P , and we have the ground-truth for any pair (g, p) for g ∈ G i and p ∈ P i .
• Same Graph Tasks ( ): Data-pattern pairs are from a single domain.The data graphs that appear in training tasks will not appear in any testing task.The pattern graphs P(g i ) that are associated with a data graph g i will appear together with g i in a task where g i appears.Note that a pattern graph p j may appear in both training and testing pairs.• Same Pattern Tasks ( ). Data-pattern pairs are from a single domain.The pattern graphs that appear in training tasks will not appear in any testing task.The data graphs g i will appear in a task together with p j if p j ∈ P(g i ) appears in the task.Note that a data graph g i may appear in both training and testing pairs.• Hybrid Domains with Same Graph Tasks ( ). Data-pattern pairs are from multiple domains, whereas pairs in one task are from the same domain.For one domain, training and testing tasks follow .• Hybrid Domains with Same Pattern Tasks ( ). Data-pattern pairs are from multiple domains, whereas pairs in one task are from the same domain.For one domain, training and testing tasks follow .• Random Tasks ( ). Data-pattern graph pairs are from a single domain.Pairs are randomly and disjointly distributed in all the tasks in the training and testing task sets.A pair in a training task does not appear in any testing tasks.
Here, corresponds to the situations where the pattern graphs are static and there may have new arrival data graphs.
corresponds to the situations where the data graphs are static and there may have new arrival pattern graphs.and do similar like and in the same single domain, but are on multiple domains.
is to test different possibilities in a single domain.

Meta-Training:
Algorithm 1 presents the meta-training process for RGIN-GP.The algorithm is to learn (w, ) of the kernel that minimizes the negative marginal likelihood across all the training tasks.As shown in Fig. 1a, for each gradient step, a task T is sampled from the training tasks (line 1), then the marginal likelihood L (Eq. ( 12)) is com- puted over all the pairs in the task, i.e., S ∪ Q (line 4), and the parameters (w, ) are updated for that task (line 5).The meta-training algorithm is different from training the kernel from scratch, where marginalization of the likelihood is over all data instead of a distinct task.The parameters (w, ) learned by Algorithm 1 better leverage the structure of the tasks, which are shared across all tasks as the task-common parameters.
Few-shot Testing: Given a testing task T * = (S * , Q * ) where |S * | ≠ 0 , the meta-model will adapt to the task based on its support set and the task-common parameters learned.Algorithm 2 shows the steps to compute the predictive distribution of Eq. ( 9) for the query set Q * .It is computed by con- ditioning on the support set S * (line 1-2), which analytical solution is given in Eqs. ( 10)- (11).The Bayesian inference is essential to compute the integral where w is the learned neural network weights, and T * is the task-specific parameters derived from the kernel hyperparameters .Equation ( 13) ensembles all the models with all possible configurations of the task-specific parameters T * , weighted by the posterior of the parameters p( T * |c S * , X S * ) given the support set S * .Equation ( 13) is known as Bayesian model average [58].
Zero-shot Testing: Given a testing task T * = (S * , Q * ) where |S * | = 0 , the meta-model cannot adapt to the task based on its support set.In the literature [55,60], zero-shot learning is mainly done for classification where the classes are limited.Different from classification, our problem here is for subgraph isomorphism counting by regression.Performing zero-shot testing for a regression task is difficult as it is to predict a value.To make predictions, we utilize training tasks.The basic idea is to borrow one training task T i as the support set for the new coming task T * .The assump- tions are that the training tasks and test tasks may be similar regarding data/pattern graph, and they share some specific task structures.The kernel leverages the similarity.The algorithm is given in Algorithm 3. First, a training task is sampled randomly from the training data (line 1).Then, a set of auxiliary data (X, c) is taken from the task to serve as the support set (line 2), and is used to compute the posterior of the parameters p( T * |c, X) (line 3-4).
The discrepancy between the two posterior densities p( T * |c, X) and p( T * |c S * , X S * ) determines the difference between the few-and zero-shot testing, which is further determined by the discrepancy of p(c, X) and p(c S * , X S * ) .As the shape of p(c, X) is delineated by p(X) and p(c|X), the higher the similarity between p(X) and p(X S * ) , and p(c|X) and p(c S * |X S * ) , the well the auxiliary task works in the zero-shot testing [60].
For the subgraph counting tasks, it is difficult to make practical assumptions for both p(X) and p(c|X), for the 5 task configurations.The zero-shot testing will also have ( 13) different effects on different task configurations.It is worth noting that, for and tasks, the auxiliary task sampled should be the same domain/database with the testing task to pursue a high similarity between p(c, X) and p(c S * , X S * ) .We also explore adding the auxiliary data (c, X) in the few-shot testing, together with (c S * , X S * ) to approximate the posterior of T * .Bayesian model aver- age marginalizes all possible T * and gives a smooth and robust prediction.

Feature Encoding
Encoding initial node representation (0) v for RGIN-GP in the neural network mapping F is important in learning.The one-hot encoding is widely used to represent the attribute features in GNN models for node classification, link prediction [26,59] and subgraph counting [28].However, such sparse encoding is lack of insight for the analytical subgraph counting.It is worth noting that the labels of a pattern node serve as the predicates of the pattern, and are used to filter nodes in the data graph.We explore frequency-based encoding and pre-trained embedding-based encoding to encode label information and topological structure.
Frequency − based Encoding.T h e f r e q u e n c y - based features encode the filter capability of a pattern node regarding the data graph.For a data graph g i , we denote the number of occurrence of a node label l as , where Σ V is the universal set of the node labels on data graphs, and the i-th dimension corresponds to the i-th node label l i ∈ Σ V .The value of (0)  v [i] is the fraction of the nodes in g can be matched to v.In detail, if node v is associated with a node label l i , (0)  v [i] will be set to ϝ(l i )∕|V| , otherwise (0)  v [i] will be set to 1.0.It is worth noting that for one query, its frequency-based encoding for different data graphs is different.
Embedding − based Encoding.The frequency-based encoding takes the attribute frequency of the data graph into account, but fails to leverage the topology of the data graphs.An encoding to encode the topological structure of the data graph together with its labels is needed.As feeding GNN a pre-trained and unsupervised embedding as node features can boost the performance, we pre-train a node label embedding for the data graphs to enhance the pattern graph encoding.To preserve the topological property of the training data graphs {g 1 , … , g n } together with the uni- versal node label set ( Σ V ), we construct a label-augmented graph which means the data graphs are treated as connected components of a large graph with node V and E. V L is a set of nodes where a node represents a label in Σ V , and there are |Σ V | nodes in V L .E L is a set of edges where an edge is between a node, v, in V with a node, l, in V L , if v has the node label l that the node l corresponds to.We use a scalable, task-independent graph embedding algorithm (e.g., DeepWalk [40], node2vec [17], ProNE [62]) to pre-train a node embedding for the label-augmented graph G L .With the pre-trained label embedding, we encode every node in a pattern graph q.For a node v in q, we set (0)  v to be where � (l) is the pre-trained embedding of the label l in G L if v has the label l.A node v will have an all-zero vector if it does not have any labels.

Experimental Setup
Implementation and Setting.We give the settings of RGIN- GP.For the neural network transformation F , the number of RGIN layers is 3, where each hidden layer has 64 units and a Dropout probability of 0.2.For the stationary kernel function K , we use the spectral mixtures based kernels [56], whose loss is consistently easy to converge than the widely used RBF kernel for our learning task.For the embeddingbased encoding, we try 4 scalable task-independent node embedding approaches, i.e., DeepWalk [40], node2vec [17], ProNE [62], NRP [61] and finally choose ProNE as the embedding algorithm for the label-augmented graph due to its efficiency and stable performance.Following the setting in [62], the dimension of the embedding is 128.
The learning framework is built on PyTorch with PyTorch Geometric and GPyTorch [16].We use the Adam optimizer with a decaying learning rate to train our models via 200 epochs.The initial learning rates for the neural network parameters and kernel hyperparameters ( w and in Algorithm 1) are set to 5e-4 and 1e-3 empirically, respectively.Both training and prediction are performed on a Linux server with a Tesla V100 with 16GB memory.
Datasets.We use one real graph database , and two synthetic graph databases -and -. collection [11] has 188 unique nitroaromatic compounds where nodes represent atoms and edges represent bonds.The node (edge) label represents the atom (bond) type.The 24 patterns are from [28].The two synthetic datasets -and -are generated by the generator of [28].
follows the same scale of for the data graphs and pattern graphs.
enlarges the scale of the data and pattern graphs two times.Here, the data graphs are generated from patterns by adding nodes and edges to the patterns.Table 1 lists the profile of the three datasets.
Baseline Approaches.From the perspective of the model, we compare meta-learned RGIN-GP ( − ) with its neural network counterpart in [28], + and the model in [28] with the best prediction accuracy, + .From the perspective of the learning algorithm, we compare our meta-learned − with + trained by a classical meta-learning algorithm Model-Agnostic Meta-Learning ( ) [15] and transfer learning under the linear protocol ( ). optimizes the task parameters end-to-end by a bi-level back propagation.Specifically, the algorithm optimizes the task-specific parameters in one inner loop and the task-common parameters in the outer loop.
treats each training task as one batch to optimize the task-common parameters.For a testing task, the parameters of the final layer in the MLP are finetuned by one gradient step.For the two algorithms, the model is the neural network model + .Evaluation Metrics : We use the mean of -, i.e., MAE (Eq.(1)), of the counts and the accuracy of the subgraph isomorphism query to evaluate the model performance.The two metrics do not have a direct correlation.The well performed model should achieve small MAE and high accuracy simultaneously on the test set.Small MAE but low accuracy indicates all the estimations are over-smoothed to the mean of the true counts.Large MAE but high accuracy indicates the model can only distinguish zero and nonzero counts but cannot predict well for nonzero counts.

RGIN-GP versus Neural Network Models
We first compare our − with its neural network counterpart + , and a more powerful model For − , we organize the training and testing pairs as tasks with 128 pairs in each task.Testing is conducted in the zeroshot mode (Algorithm 3) with 128 auxiliary pairs drawn from the training data.For the two neural network models, they are trained by standard supervised learning.Table 2 shows the testing performance on 20% testing pairs when the training pairs are set to 60%, 40%, and 20% of the overall 4,512 pairs, respectively.In general, the 3 − variants remarkably outperform the two neural network models w.r.t.MAE.When the training ratio is 60% and 40%, the test MAE of − models is below 1.0.When the training ratio declines to 20%, the MAE only arises to about 1.2.The neural network + and + suffer from model degradation.We observed the loss converges slowly during training, and the test performance has a large variance w.r.t.multiple training, particularly for the complicated model + .The implication of this experiment is our − is robust, data-efficient and much easier to train than its neural network counterpart.This is because of its nature as a GP whose prediction is conducted by Bayesian model average.

Influence of Task Configuration
We investigate how task configurations influence the performance of − .For the 5 types of tasks, i.e., , , , , , by default, we use − ( ) as the model and use 7 training tasks from database with 128 pairs and 16 shots for one task.For and , 239 tasks from the domain of -are added into the training task set.First, we vary the number of shots in {1, 4, 16, 64} , and the prediction MAE and accuracy are shown in Fig. 2a and b.The number of shots has a large influence on the testing MAE and accuracy.The larger the support set in each task, the better the performance, which is consistent with our intuition.As the number of shots grows exponentially, the performance gain improves marginally.Second, we vary the number of pairs in each task in {32, 64, 128, 256} by fixing the number of shots to 16 and training tasks to 7. The testing results are shown in Fig. 2c and d.In general, varying the task size will not incur a large influence as varying the number of shots.However, we observe , are more sensitive to the task size compared with the other 3 task types.The reason would be when varying the MUTAG task size, the task structure between synthetic tasks and MUTAG task becomes different, e.g., the percentage of pairs with groundtruth in one task.And this difference brings greater performance variation.Third, we vary the number of training tasks in {7, 14, 21, 28} by fixing the task size to 128 and the number of shots to 16.The corresponding MAE and accuracy on task is presented in Fig. 2e and f.We conjecture that here the performance change of 21 training tasks is that some new task introduces inconsistent noise when training together with the synthetic dataset.
Furthermore, we investigate the effect of adding sampled data from the training tasks to the support set of the test task in the zero-shot and few-shot scenarios for the 5 task types.For , and , 7 tasks from are used for training.For and , 239 tasks from are added to the training tasks.We test 28 tasks by varying the number of shots and the auxiliary pairs in {0, 1, 4, 16, 64} , {0, 16, 32, 64, 128} , respectively.The size of all the train and test tasks is 128.The testing performance over the 5 task configurations is shown in Table 3.For , , and , the upper-left cell of the table is the worst performance for zero-shot without auxiliary data and the lower-right cell is the best performance for 64 shots with 128 auxiliary.As the number of shots or auxiliary pairs increases, the test performance improves from the upper-left to the upper-right, lower-left and upper-right, which is consistent with intuition.In addition, we find when the number of shots or the auxiliary pairs is sufficiently large, e.g., 64 shots or 128 auxiliary pairs, increasing the amount of auxiliary data or shot only contributes to marginal improvement.For a fixed size support set, the more data from the shot, the better the performance.For example, 16 shots without auxiliary pairs is better than zero-shot with 16 pairs.This is because the support set in a test task exhibits more taskspecific features than the sampled training data.However, we find for tasks with the type and , adding auxiliary data from training tasks will degrade the MAE and accuracy.Recall that and task is one new pattern p * for different data graphs G in a database.We observe that, for different patterns p 1 and p 2 , their true count distributions of G are rather different, because of the different topology between p 1 and p 2 .For example, p 1 in G has most zero counts and p 2 in G has most nonzero counts.A large discrepancy between the ground-truth distribution makes the knowledge transfer difficult.Under this circumstance, fewshot for the new pattern is important.

Comparison with Meta-Algorithms
We compare the meta-learned − with the metalearned + by and for conducts the inner and outer loop gradient update end-to-end, differentiating through the inner loop to obtain the gradients for the outer loop, which will cause instability problems [1].For the subgraph counting task, training loss of converges slow. is also resource consuming as it runs out of GPU memory on Hybrid tasks from and -. finetunes the final layer of + one gradient step for each task by freezing the parameters of the former feature transformation layers.The one gradient step may underfit the task data, whereas more gradient steps will overfit the task data.

Comparison with Algorithmic Approaches
We compare our meta-learned − with traditional subgraph counting algorithms, including 7 approximate algorithms in the GCARE benchmark [38], and an exact counting algorithm [9] implemented by NetworkX.
The MAE, quantiles of the error and the total counting time are presented in Table 5.The prediction results of − are collected by fivefold cross-validation where one − ( ) model is trained over 20% pairs that are organized in 7 tasks with type of and size of 128.The prediction is conducted by zero-shot testing with 128 auxiliary pairs.In Table 5, − achieves the lowest MAE among the 8 approximate approaches and its prediction is 6× faster than the exact algorithm .Most of the approximate baselines have the problem of underestimation due to sampling failure.

Related Work
Subgraph Counting.There are exact and approximate subgraph counting algorithms [44].For exact counting, existing approaches in the literature are categorized into enumeration-based [19,22,37] and analytical approaches [32,36,41].For approximate subgraph counting, various estimation strategies have been explored, such as path sampling [23,54], color coding [3,4], random walk [6], and graph summarization [34,50].Most of the above approaches are designed to count graphlets [42], a.k.a.graph motifs, small, unlabeled graph queries, over a simple undirected graph.Recently, ML/DLbased approaches have been proposed to estimate the subgraph counting.[64,65] devise a GNN based model as the counting sketch to estimate the subgraph isomorphism/homomorphism count over a large data graph, but the model cannot generalize to unseen data graphs.[28] proposes DL models to count queries specified by a pair of data graph and pattern graph.Both of the two models need training by a large number of training data.[7] analyzes the ability of GNNs in detecting subgraph isomorphism, and proposes a Local Relational Pooling model for counting both subgraphs and induced subgraphs.However, the model is specific to a given query pattern.
Meta-Learning on Graphs.There are three types of meta-learning algorithms, i.e., black-box adaption [33,46], optimization-based [15,35] and metric-based [48,51] metalearning algorithms.Black-box adaption relies on specific neural network architecture, e.g., RNN to learn each task one by one.These approaches have the powerful expressive power to model the task prior but are data inefficient and challenging for optimization.The optimization-based algorithms learn a hierarchical model by gradient-based back propagation.These algorithms are effective regarding learning the meta-model but are time and memory consuming in computation due to the hierarchical optimization paradigm.The metric-based algorithms borrow the idea from the clustering algorithms that learn an embedding for the input.The algorithms are applicable for small data but only classification tasks.These meta-learning approaches have been adopted over graph data to deal with various graph learning tasks, including node classification [21,66], link prediction [2,21], graph classification [5,29].[14] proposes a meta-learning framework, conditional graph neural process, for community search.A survey summarizes the applications and methods can be found in [30].Here, GNN is widely used as the base model or core component of these approaches.However, all the existing approaches are oriented to few-shot graph learning tasks and cannot be directly applied to zero-shot learning or the subgraph counting task, where the input is specified by a data graph and a pattern graph.

Conclusion
In this paper, we study an NP-complete problem, subgraph isomorphism counting, by DL techniques.To alleviate the reliance on a large volume of training data, we devise a Gaussian Process, called RGIN-GP, which warps a neural network layer.The model is trained end-to-end by a meta-learning algorithm, which aims to exploit the knowledge prior of training tasks.Compared with the baseline approach, the meta-trained RGIN-GP reduces the MAE from 8 to 1, with only one thousand training samples.In addition, in our extensive experiments, the meta-learned RGIN-GP can fast adapt to new tasks by few-shot and zero-shot learning.

Fig. 1
Fig. 1 Meta-model train and test

Algorithm 1 :1 repeat 2
RGIN-GP Meta TrainInput : Training Task Set D = {T 1 , • • • , T n },learning rates α w and α θ Output: neural network parameter w, kernel hyperparameter θ Sample a task T •We conduct extensive experiments for few-shot and zeroshot learning, using real and synthetic graph datasets in different scenarios.The experimental results verify that the meta-learned RGIN-GP outperforms the supervised learned neural network counterparts by small training data and is effective to adapt to new tasks by few-shot/ zero-shot learning.
Roadmap: Section 2 gives the problem statement and a neural network framework for subgraph counting.In Sect.3, we introduce the RGIN-GP model, the meta training and testing algorithms, and the feature encoding.Section 4 reports the experimental results.Finally, we review the related works in Sect. 5 and conclude the paper in Sect.6.

Table 1
Profile of datasets

Table 2
MAE and accuracy on

Table 4
Test MAE/accuracy for different algorithms