L ATENT B OTTLENECKED A TTENTIVE N EURAL P ROCESSES
Anonymous authors
Paper under double-blind review
A BSTRACT
Neural Processes (NPs) are popular methods in meta-learning that can estimate predictive uncertainty on target datapoints by conditioning on a context dataset.
Previous state-of-the-art method Transformer Neural Processes (TNPs) achieve strong performance but require quadratic computation with respect to the number of context datapoints, significantly limiting its scalability.
Conversely, existing sub-quadratic NP variants perform significantly worse than that of TNPs.
Tackling this issue, we propose Latent Bottlenecked Attentive Neural Processes (LBANPs), a new computationally efficient sub-quadratic NP variant, that has a querying computational complexity independent of the number of context datapoints.
The model encodes the context dataset into a constant number of latent vectors on which self-attention is performed.
When making predictions, the model retrieves higher-order information from the context dataset via multiple crossattention mechanisms on the latent vectors.
We empirically show that LBANPs achieve results competitive with the state-of-the-art on meta-regression, image completion, and contextual multi-armed bandits.
We demonstrate that LBANPs can trade-off the computational cost and performance according to the number of latent vectors.
Finally, we show LBANPs can scale beyond existing attentionbased NP variants to larger dataset settings.
I NTRODUCTION
Meta-learning aims to learn a model that can adapt quickly and computationally efficiently to new tasks.
Neural Processes (NPs) are a popular method in meta-learning that models a conditional distribution of the prediction of a target datapoint given a set of labelled (context) datapoints, providing uncertainty estimates.
NP variants (Garnelo et al., 2018a; Gordon et al., 2019; Kim et al., 2019) adapt via a conditioning step in which they compute embeddings representative of the context dataset.
NPs can be divided into two categories: (1) computationally efficient (sub-quadratic complexity) but poor performance and (2) computationally expensive (quadratic complexity) but good performance.
Early NP variants were especially computationally efficient, requiring only linear computation in the number of context datapoints but suffered from underfitting and as a result, overall poor performance.
In contrast, recent state-of-the-art methods have proposed to use self-attention mechanisms such as transformers.
However, these state-of-the-art methods are computationally expensive in that they require quadratic computation in the number of context datapoints.
The quadratic computation makes the method inapplicable in settings with large number of datapoints and in low-resource settings.
ConvCNPs (Gordon et al., 2019) partly address this problem by proposing to use convolutional neural networks to encode the context dataset instead of a self-attention mechanism, but this (1) requires the data to satisfy a grid-like structure, limiting the method to low-dimensional settings, and (2) the recent attention-based method Transformer Neural Processes (TNPs) have been shown to greatly outperform ConvCNPs.
Inspired by recent developments in efficient attention mechanisms, (1) we propose Latent Bottlenecked Attentive Neural Processes (LBANP), a computationally efficient NP variant that has a querying computational complexity independent of the number of context datapoints.
Furthermore, the model requires only linear computation overhead for conditioning on the context dataset.
The model encodes the context dataset into a fixed number of latent vectors on which self-attention is performed.
When making predictions, the model retrieves higher-order information from the context dataset via multiple cross-attention mechanisms on the latent vectors.
(2) We empirically show
[Table]
that LBANPs achieve results competitive with the state-of-the-art on meta-regression, image completion, and contextual multi-armed bandits.
(3) We demonstrate that LBANPs can trade-off the computational cost and performance according to the number of latent vectors.
In addition, we show that LBANPs can scale to larger dataset settings where existing attention-based NP variants fail to run because of their expensive computational requirements.
(5) Lastly, we show that similarly to TNPs, we can propose different variants of LBANPs for different settings.
B ACKGROUND 2. M ETA -L EARNING FOR P REDICTIVE U NCERTAINTY E STIMATION
In meta-learning, models are trained on a distribution of tasks Ω( T ) .
During each meta-training iteration, a batch of B tasks T = {T i } Bi
=1 is sampled from a task distribution Ω( T ) .
A task T i is a tuple ( X , Y , L , q ), where X is the input space, Y is the output space, L is the task-specific loss function, and q ( x, y ) is a distribution over data points.
During each meta-training iteration, for each T i ∈ T , we sample from q T i : a context dataset D context i = { ( x, y ) i,j } Nj =1 and a target dataset
D target i = { ( x, y ) i,j } Mj =1 , where N and M are the fixed number of context and target datapoints respectively.
The context data is used to perform an update to the model f such that the type of update differs depending on the model.
In Neural Processes, these updates refer to its conditioning step where embeddings of the dataset are computed.
Afterwards, the update is evaluated on the target data and the update rule is adjusted.
In this setting, we use a neural network to model the probabilistic predictive distribution p θ ( y | x, D context ) where θ are the parameters of the NN.
2. N EURAL P ROCESSES
Neural Processes (NPs) are a class of models that define an infinite family of conditional distributions where one can condition on arbitrary number of context datapoints (labelled datapoints) and make predictions for an arbitrary number of target datapoints (unlabelled datapoints), while preserving invariance in the ordering of the contexts.
Several NP models have proposed to model it as follows:
[Equation]
with r C :
=
Agg( D context ) where Agg is a deterministic function varying across the variants that aggeregates D context into a finite represention with permutation invariance in the context dataset.
These NPs aim to maximise to likelihood of the target dataset given the context dataset.
Conditional
Neural Processes (CNPs) (Garnelo et al., 2018a), proposes an aggregator using DEEPSETs (Zaheer et al., 2017) and Conditional Attentive Neural Processes (CANPs) (Kim et al., 2019)
(a deterministic variant of ANPs without the latent path) proposes an aggreagator using a single self-attention layer.
In these NP variants, for a new task, we first (in a conditioning step) compute the embedding of the context dataset r C .
Afterwards, in a separate querying step, the model makse predictions for target datapoints.
Note that for a given context dataset and independent of the number of batches of predictions, the conditioning step needs only be performed once.
Neural Processes have several desirable properties (1) Scalability : NPs generates predictions more computationally efficiently than Gaussian Processes which scale cubically with the size of the context dataset.
In Table 1, we show the complexity of NP variants relative to the size of the context dataset.
It suffices to perform the conditioning step once but for each prediction, the querying step needs to be performed independently.
As such, the complexity of the query step is the most important when considering the model’s efficiency.
(2) Flexibility : NPs can condition on an arbitrary number of context datapoints and make predictions on an arbitrary number of target datapoints, and (3) Permutation invariance : the predictions are order invariant in the context datapoints.
2.2. T RANSFORMER N EURAL P ROCESSES
Transformer Neural Processes (TNPs) (Nguyen & Grover, 2022) comprises of a transformer-like architecture that takes both the context dataset and the target dataset as input.
However, unlike previous NP variants that model the predictive distribution of target datapoints independently, i.e., p ( y i | x i , D context ) , TNPs propose to model the predictive distribution of all target datapoints in conjunction p ( y 1 ,...,M | x 1 ,...,M , D context ) as follows:
[Equation]
with r C,T :=
Agg( x C , y C , x T ) where Agg comprises of multiple Self-Attention layers with a masking mechanism such that the context datapoints and target datapoints only attend to the context datapoints.
The output of the aggregator r C,T that corresponds to the target datapoints embeddings are passed to a predictor model for prediction.
Three variants of TNPs have been proposed: TNP-D, TNP-ND, and
TNP-A.
However, TNP-A, as the authors highlighted has low tractability due to being an autoregressive model.
As such, TNP-D and TNP-ND are proposed as the practical methods for comparison.
Specifically, TNP-D proposes a predictor model comprising of a vanilla MLP which outputs the mean and a diagonal covariance matrix for the target datapoints.
In contrast, TNP-ND outputs a full covariance matrix for all target datapoints.
TNP-ND’s predictor architecture comprises of self-attention layers applied to the embeddings of target datapoints and a network to output a low-rank matrix to compute a full covariance matrix either via cholesky decomposition or a low-rank decomposition.
We highlight that although the ND predictor architecture was only introduced for TNP, in fact, it can be easily extended to other NP variants such as CNP, CANP, and BNP.
In which case, it would result in models such as
CNP-ND, CANP-ND, and BNP-ND.
In contrast to previous NP variants, TNPs computes its embeddings with both the context dataset and target dataset.
Thus, there is no conditioning step for TNPs.
Instead, when making queries for a batch of target datapoints, the self-attention on both context and target datapoints must be recomputed, requiring quadratic computation O (( N + M ) 2 ) in both the number of context datapoints
N and number of target datapoints M .
The quadratic complexity makes deployment of the model (1) computationally costly for deployment and (2) restricts the model from scaling to settings with larger amounts of context or target datapoints.
M ETHODOLOGY
In this section, we introduce Latent Bottlenecked Attentive Neural Processes (LBANPs), an NP variant that achieves competitive results while being computationally efficient.
Firstly, we show how to fix the quadratic computation query issue in TNPs.
Secondly, we propose, LBANP, a model that utilises a latent bottlenecked attention mechanism to reduce the querying step’s complexity to constant computation per target datapoint and conditioning step’s overhead to linear computation.
Lastly, we show how LBANP can be extended to other variants similar to TNP depending on the problem setting.
3. R EDUCING THE QUERYING COMPLEXITY OF TNP
Due to passing both the context and query dataset through a self-attention mechanism, for TNP, each prediction requires a quadratic amount of computation.
We propose to compute an embedding for each self-attention layer encompassing the information of the context dataset.
This way, we can perform cross-attention to retrieve information from the context dataset for predictions.
Unlike in
TNP whose queries require quadratic computation O (( N + M ) 2 )) in both the number of context and target datapoints, the queries can instead be made in O ( NM ) .
Figure 1 describes how the architecture of TNP is modified to give a more efficient variant that we name Efficient Queries
TNPs (EQTNPs).
Although EQTNPs are more efficient than TNPs, they unfortunately still require quadratic computation to compute the embeddings of the context dataset, limiting its applications.
[Figure]
Inspired by the recent successes in efficient attention mechanisms (Lee et al., 2019; Jaegle et al., 2021b), we propose Latent Bottlenecked Attentive Neural Processes (LBANPs), an NP variant that reduces the quadratic conditioning complexity to linear and further reduces the query complexity to linear in the number of target datapoints, while retaining similar performance.
See Figure 2 for the architecture.
Conditioning Phase: Instead of performing Self-Attention on the embeddings of all datapoints, we propose to reduce the dimensionality of the context dataset embeddings to a set of L × D L latent vectors LEMB where LEMB 0 is meta-learned during training.
The size of the latent vectors ( L ×
D L ) represents the size of the latent bottleneck and is set according to prespecified hyperparameters
L and D L .
By interleaving retrieving information from the context dataset ( CONTEXT ) via a cross-attention and performing self-attention, we can compute embeddings of the context dataset that comprise of higher-order interactions between datapoints that is typically achieved by a multilayer self-attention mechanism.
Note that LBANPs also satisfy the property of being invariant to the ordering of the context and target dataset.
By scaling the number of latent vectors, we can increase the size of the bottleneck, allowing for more expressive models.
[Equation]
Since the cross-attention is between the latent vectors and context dataset, thus the cost of this computation is O ( NL ) .
Furthermore, since the self-attention is only performed on a set of L latent vectors, thus it only requires O ( L 2 ) computation.
Therefore, the amount of computation required to compute these latent vectors is linear in the number of context datapoints i.e., O ( NL + L 2 )
=
O ( N ) since L is a prespecified constant.
The outputs of the conditioning phase are the latent embeddings
LEMB i representative of the context dataset.
In contrast with EQTNP, the number of (latent) vectors representing the context dataset is a constant and is thus independent of the number of context datapoints.
This crucial difference contributes to a significant improvement in the overall computational complexity over both EQTNP and TNP.
Querying Phase: The querying phase is similar to that of EQTNP in that multiple cross-attention layers are used to retrieve information from the context dataset.
The multiple cross-attention layers allow for the model to compute higher-order information between a target datapoint and the context datapoints to use in its prediction.
Specifically, this is performed as follows:
[Equation]
Notice that computing QEMB (short for Query Embeddings) is dependent on the number of latent vectors (a constant L ) and is independent of the number of context datapoints.
As a result, making the prediction of a single datapoint is overall constant in computational complexity, i.e., O (1) .
Naturally, for a batch of M datapoints, the amount of computation thus would be O ( M ) .
Furthermore, note that LEMB only requires a constant amount of memory to store regardless of the number of datapoints.
As such, unlike TNP, only constant memory is required to make a query per datapoint, allowing the method to be more applicable in settings with limited-resources.
3.2. LBANP V ARIANTS
Similar to TNP-Not Diagonal (TNP-ND)
(Nguyen & Grover, 2022) which predicts a covariance matrix for batch of targets, we can propose a similar variant of LBANP for settings where the predictions on target datapoints ought to be conditionally dependent.
When making predictions using the target datapoint embeddings, TNP-ND first applies a self-attention mechanism solely on the target datapoint embeddings before passing into an MLP that outputs a low-rank matrix that is used to construct approximations of the full covariance matrix e.g., via Cholesky decomposition.
Similarly, we could follow the same framework, resulting in a method called LBANP-ND.
Unfortunately, this self-attention mechanism once again requires quadratic computation with respect to the number of target datapoints when querying.
As a result, although LBANP-ND is efficient in terms of the number of context datapoints, it would not be scalable in terms of the large number of target datapoints.
As a result, we propose a more efficient variant called LBANP-END (Efficient Not Diagonal).
Instead of a self-attention mechanism which has a quadratic computational cost, LBANP-END proposes a latent bottlenecked attention mechanism that is linear in terms of computation.
Specifically, the predictor information from the target datapoint embeddings via a cross-attention mechanism to a fixed set of latent vectors LQEMB (Latent Query Embeddings).
The initialization of this set of latent vectors LQEMB 0 is meta-learned.
We apply a self-attention mechanism to compute the higher-order information in latent space.
After the higher-order information has been computed, we retrieve the information from the latent vectors via another cross-attention mechanism.
Specifically, this is performed as follows:
[Equation]
where Q is a hyperparameter representing the number of layers.
E XPERIMENTS
We evaluate Latent Bottlenecked Attentive Neural Processes (LBANPs) on several tasks: meta regression, image completion, and contextual bandits.
These experiment settings have been used extensively to benchmark NP models in prior works (Garnelo et al., 2018a;
Kim et al., 2019; Lee et al., 2020; Nguyen & Grover, 2022).
We compare LBANPs with the following members of the
NP family: Conditional Neural Processes (CNPs) (Garnelo et al., 2018a), Neural Processes (NPs) (Garnelo et al., 2018b), Bootstrapping Neural Processes (BNPs) (Lee et al., 2020), and Transformer
Neural Processes (TNPs) (Nguyen & Grover, 2022).
In addition, we compare with their attentive variants (Kim et al., 2019) (CANPs, ANPs, and BANPs).
Implementation details of the baselines and LBANPs are included in the Appendix.
In this experiments section, we focus on comparisons with the well-established vanilla versions of NP models.
Specifically, for the case of TNPs, we compare with TNP-D. Due to its masking mechanism and architecture, TNP-D models the probabilistic predictive distribution identical to that of previous NP variants.
As such, it offers a fair comparison to prior NP works.
In contrast, TNP-ND models the predictive distribution differently.
This choice of modelling by TNP-ND benefits settings where the predictive uncertainty of all target datapoints are evaluated in conjunction such as in image completion settings.
However, this does not benefit and can instead be detrimental to settings where the uncertainty of individual datapoints is evaluated independently such as in multi-armed bandits or bayesian optimization.
For a fair comparison of TNP-ND with prior works, it would require modifying the existing NP methods into ND variants (e.g., CNP-ND, CANP-ND, and BNP-ND).
However, this is outside the scope of our work.
Nonetheless, for the sake of completeness, we detailed how to construct the ND variants previously in Section 3.2.1 and include comparisons with
TNP-ND in Section 4.4.3.
The aim of the experimental evaluation is to answer the following questions: (1) What is the performance of LBANP compared to the existing NP methods?
(2) Does LBANP scale to problems with larger number of context datapoints?
(3) How does the number of latent vectors affect the performance of LBANPs?
(4) How do the different variants of LBANP (LBANP-ND and LBANP-END) perform compared to TNP-ND?
4. 1-D R EGRESSION
[Table]
All experiments are run with 5 seeds.
In this experiment, the model observes a set of N context points pertaining from an unknown function f .
The model is expected to make predictions for a set of M target datapoints that comes from the same function.
In each training epoch, B =functions are sampled from a GP prior with an
RBF kernel f i ∼ GP ( m, k ) where m ( x ) =
and k ( x, x ′ )
=
σ 2 f exp (cid:16) − ( x − x ′ ) 2 2 l(cid:17) .
The hyperparameters l and σ f are randomly sampled per task.
The hyperparameters are sampled as follows: l ∼ U [0 . 6 , 1 . 0) , σ f ∼ U [0 . 1 , 1 . 0) , N ∼ U [3 , 47) , and M ∼ U [3 , 50 − N ) .
At test-time, the models are evaluated on unseen functions sampled from GPs with RBF and Matern 5 / 2 kernels.
Specifically, the methods are evaluated according to the log-likelihood of the target datapoints.
The number of context datapoints N and the number of evaluation points M are sampled according to the same distribution as in training.
Results: As shown in Table 2, with 8 latent vectors, LBANP outperforms all the baselines by a large margin except TNP-D. Moreover, when using 128 latent vectors instead of 8 , LBANP has competitive performance with TNP-D.
It is important to note that the performance of LBANP can be further improved by increasing the number of latent vectors as shown in Figure ?? .
4. I MAGE C OMPLETION
In this problem, the model observes a subset of pixel values of an image and predicts the remaining pixels of the image.
As a result, the problem can be perceived as a 2-D meta-regression problem in which x is the coordinates of a pixel and y is the value of the pixel.
The image can be interpreted as
[Table]
a unique function in itself (Garnelo et al., 2018b).
For these experiments, the x values are rescaled to [-1, 1] and the y values are rescaled to [ − 0 .
Randomly selected subsets of pixels are selected as context datapoints and target datapoints.
For these experiments, we consider two datasets:
EMNIST (Cohen et al., 2017) and CelebA (Liu et al., 2015).
EMNIST comprises of black and white images of handwritten letters of 32 × 32 resolution.
In total, 10 classes are used for training, N ∼ U [3 , 197) context datapoints are sampled, and M ∼
U [3 , 200 − N ) target datapoints are sampled.
CelebA comprises of colored images of celebrity faces.
We evaluate the models on settings of various resolutions.
For CelebA32, the images are down-sampled to 32 × 32 and N ∼ U [3 , 197) and M ∼ U [3 , 200 − N ) .
For CelebA64, the images are down-sampled to 64 × 64 and N ∼
U [3 , 797) and M ∼ U [3 , 800 − N ) .
For CelebA128, the images are down-sampled to 128 ×and N ∼ U [3 , 1597) and M ∼ U [3 , 1600 − N ) .
Results: As shown in Table 3), using only 8 latent vectors, LBANP with only 8 latent vectors significantly outperforms all baselines except for TNP-D.
In addition, we see in both CelebA and
EMNIST experiments that going from 8 to 128 latent vectors improves the performance.
For CelebA ( 32 × 32 ), using 128 latent vectors, LBANP outperforms TNP-D, achieving state-of-the-art results.
For CelebA ( 64 × 64 ), a few attention-based NP variants (ANP and BANP) were not able to be trained due to the quadratic memory required during training.
This issue was also previously reported by Garnelo et al.
(2018a).
Furthermore, we show that by increasing the number of latent vectors (see Section 3.2.1 and the Appendix) LBANP can perform competitively with TNP-D. For
CelebA ( 128 × 128 ), due to its large number of datapoints, all existing attention-based NPs (CANP,
ANP, BANP, and TNP-D) were not able to be trained.
Our results show that LBANP outperforms all trainable baselines (CNP, NP, and BNP) by a significant margin.
This demonstrates the advantage of our proposed method in terms of scalability and performance.
4. C ONTEXTUAL B ANDITS
In this problem previousy introduced in Riquelme et al.
(2018), a unit circle is divided into 5 regions: 1 low reward region and 4 high reward regions.
A scalar δ determines the size of the low reward region.
The 4 high reward regions have equal sizes.
The agent, however, has to select amongstarms (each representing one of the regions) given its 2-D co-ordinate X and its actions in previous rounds.
If || X || <
δ , then the agent is within the low reward region.
In this scenario, the optimal action is to select arm 1 which provides a reward r ∼ N (1 . 2 , 0 . 012) .
The other arms provide a reward r ∼ N (1 . 0 , 0 . 012) .
If the agent is in a high-reward region (i.e., || X || > δ ), then the optimal arm would be to pull one of the other arms corresponding to the region.
If the optimal arm is pulled, then the agent receives a reward of N ∼ N (50 . 0 , 0 . 012) .
Pulling arm 1 will reward the agent with r ∼ N (1 . 2 , 0 . 012) .
Pulling any of the other 3 arms rewards the agent with r ∼ N (1 . 0 , 0 . 012) .
In each training iteration, B = 8 different wheel problems are sampled { δ i } Bi =
according to a uniform distribution δ ∼ U (0 , 1) .
For the iteration, M = 50 points are sampled for evaluation and
[Table]
mean the cumulative
Results: Table 4 show that LBANPs outperform all methods except for TNPs by a significant margin.
For lower δ values, we see that LBANP performs similarly to TNP-D and occasionally outperforms TNP-D in the case of δ = 0 .
95 even with 8 latent vectors.
Interestingly, we see that EQTNP outperforms TNP-D substantially for δ = 0 .
4. A BLATION S TUDIES 4.4. N UMBER OF L ATENTS
In this experiment (see Figure 3a) on CelebA ( 32 × 32 ), we vary the number of latent vectors from 8 until 256 to evaluate the effect of different number of latent vectors.
The experiments show that by scaling the number of latent vectors, the performance increases.
This is inline with our previous results that show that LBANP with 128 latent vectors outperforms LBANP with 8 latent vectors.
Specifically, in this CelebA32 setting, we see that 128 latent vectors already achieves state-of-theart results but results can be further improved with 256 latent vectors.
Furthermore, we can see that even with 8 latent vectors LBANPs achieve strong results, outperforming all baselines except TNP-D.
4.4. E MPIRICAL A NALYSIS OF C OMPUTATIONAL C OMPLEXITY
Empirical Time Cost: In these experiments, we show the empirical time cost to perform predictions with various Neural Process models. In Figure 3b, we fix the number of target datapoints and vary the number of context datapoints.
We see that TNPs required time scales quadratically.
In contrast, we see that EQTNPs and LBANPs remain efficient regardless of the number of datapoints.
Importantly, we see that regardless of the number of context datapoints, LBANPs queries use the same amount of time.
Empirical Memory Cost:
In these experiments, we show the empirical memory cost to perform predictions with various Neural Process models.
In Figure 4a, we fix the number of target datapoints and vary the number of context datapoints.
The figure shows that with respect to the number of context datapoints: (1) TNP’s memory cost scales quadratically, (2) EQTNP’s memory cost scales linearly, and (3) LBANP’s memory cost stays constant.
These results confirm the big-O complexity analysis in Table 1.
When N = 1400 , LBANP ( L = 128 ) uses 1172 MBs of memory and TNP uses 13730 MBs of memory (more than 11 times the memory LBANP used), showing a significant benefit of using LBANPs in practice.
[Figure]
[Figure]
In Figure 4b, we fix the number of context and target datapoints and vary only the number of latent vectors for LBANPs.
The plot shows that the memory cost of LBANPs indeed scales linearly with the number of latent vectors.
4.4. N OT -D IAGONAL
In this experiment, we evaluate the performance of the non-diagonal variants of the methods on the image completion task.
Table 5 shows that LBANP-ND performs competitively with TNP-ND across both the CelebA and EMNIST datasets.
In the table, we include TNP-D and LBANP (128) as a reference of the performance of the vanilla variants.
In the results, we see that both TNP-ND and
LBANP-ND are incapable of scaling to CelebA64.
In contrast, we see that, our proposed efficient non-diagonal variant, LBANP-END is more scalable than LBANP-ND and TNP-ND, and achieves state-of-the-art results on both the 32 × 32 and 64 × 64 .
Finally, similar to previous experiments, we see that scaling the number of latent vectors improves the performance of these variants as well.
R ELATED W ORK
The first NP model was Conditional Neural Processes (CNPs) (Garnelo et al., 2018a).
CNPs encode the context dataset by encoding the context datapoints via a deep sets encoder.
NP (Garnelo [Table] et al., 2018b) proposes to use a global latent variable to encode functional stochasticity.
Later, other variants proposed to build in translational equivariance (Gordon et al., 2019), attention to tackle underfitting (Kim et al., 2019), transformer attention (Nguyen & Grover, 2022), bootstrapping (Lee et al., 2020), modeling predictive uncertainty (Bruinsma et al., 2020), and tackling sequence data (Singh et al., 2019; Willi et al., 2019).
From a practical perspective, NPs have also been applied to a large range of problems, including modeling sequences of stochastic processes (Singh et al., 2019), sequential decision making settings (Galashov et al., 2019), and modeling stochastic physics fields (Holderrieth et al., 2021).
Mathieu et al.
(2021) propose a contrastive learning framework to learn better representations for NPs.
Transformers have been shown to achieve amazing results while being very flexible, but the quadratic scaling in terms of the number of inputs due to its self-attention layers renders it inapplicable to settings with large amounts of inputs e.g., an image.
Several groups have proposed strategies in image settings to reduce the size of the input to the Transformer e.g., subsampling the input (Chen et al., 2020) and preprocessing the input using convolutions (Dosovitskiy et al., 2020;
Wu et al., 2020).
Other groups have proposed to modify the internal self-attention mechanism of
Transformers to obtain enhanced efficiency.
Specifically, Set Transformers and related works (Lee et al., 2019; Goyal et al., 2021) induce a latent bottleneck by mapping an input array back and forth via cross-attention between an array with fewer elements or manipulating the size of the array Jaegle et al.
(2021b;a).
Perceiver (Jaegle et al., 2021b) proposes a deep latent network which takes as input a simple 2D byte array (e.g., pixels) and evaluates the proposed model on image classification, audio, video, and point clouds.
Perceiver IO (Jaegle et al., 2021a) extends Perceiver to inputs and outputs of different sizes.
C ONCLUSION
Prior NP methods have generally been split between (1) computationally efficient (sub-quadratic) variants of Neural Processes but poor overall performance and (2) computationally expensive (quadratic) attention-based variants of Neural Processes that perform well.
In this work, we fix the slow querying of the previous state-of-the-art method, TNPs, by proposing to apply self-attention only on the context dataset and retrieve information to the target datapoints via cross-attention mechanisms.
Taking the idea a step further, we introduce Latent Bottlenecked Neural Processes (LBANPs) a new member of the NP family that achieves results comparable with the state-of-theart while being computationally efficient.
Specifically, the deployed LBANPs have a linear cost in the number of context datapoints for conditioning on the context dataset.
Afterwards, each query requires linear computation in the number of target datapoints.
In our experimental results, we show that LBANPs achieve results comparable to state-of-the-art while being more scalable.
In our analysis, we show that LBANPs can trade-off the computational cost and performance according to a single hyperparameter ( L : the number of latent vectors).
This allows a user to easily select the expressivity of LBANPs depending on the computational requirement of the setting.
Importantly, unlike with TNPs, the amount of computation required to query a single target datapoint will always be constant regardless of the number of context datapoints.
Finally, we show that LBANPs can be extended to different variants similar to TNPs which achieve competitive results while being more computationally efficient and scalable than those of TNPs.
R EPRODUCIBILITY S TATEMENT
The baselines and code for the experiment settings are available here: https://github.com/tungnd/TNP-pytorch.
The code for LBANP is based on the same framework as the linked code and will be released with the camera-ready version.
Hyperparameters and implementation details are available in the Appendix, Section 3, and Section
A A PPENDIX : A DDITIONAL M ETHODOLOGY D ETAILS A. E FFICIENT Q UERY T RANSFORMER N EURAL P ROCESSES
Conditioning Phase:
In the conditioning phase, we compute the embeddings representative of the context dataset
[Equation]
Since the number of context datapoints is O ( N ) , the computational cost per SelfAttention layer is O ( N 2 ) .
Let K be the number of self-attention layers.
Then the embeddings { CEMB 1 , . .
. , CEMB K } encode the model’s knowledge of the context dataset.
Querying Phase: When making predictions, we make predictions by retrieving information from the context dataset, specifically from { CEMB 1 , . .
. , CEMB K } , via multiple cross-attention layers.
[Equation]
Each CrossAttention layer is linear in CEMB .
Since there is an embedding per datapoint, the computational cost is O ( NM ) .
The multiple cross-attention layers that retrieve information from the context dataset embeddings allows the predictor to retrieve higher-order information just like in
TNPs.
A. C OMPUTATIONAL AND M EMORY C OMPLEXITY
In Table 6, we include the computational and memory complexity for the NP variants with N context datapoints and M target datapoints.
Note that in the case of a complexity of O ( M ) , the computational and memory cost for a single target datapoint is constant.
[Table]
[Table] [Table]
(Big-O)
[Table]
Step
Condition
Query
[Equation]
CANP
[Equation]
NP
N
[Equation]
M
N
M
[Equation]
N
[Equation]
N
[Equation]
NM
BNP
N
[Equation]
N
M
[Equation]
N
[Equation]
NM
N
[Equation]
NM
TNP
[Equation]
D ( N + M )— ( N + M )
EQTNP
N 2 + NM
N
NM
LBANP ( N + M + L ) L
NL + L
ML
TNP-ND ( N + M )
N( N + M )
LBANP-ND
N + M
N
M
LBANP-END
N + M
N
M
B A PPENDIX : A DDITIONAL E XPERIMENTAL D ETAILS AND R ESULTS B. I MPLEMENTATION AND H YPERPARAMETER D ETAILS
We use the implementation of the baselines from the official repository of TNPs (see https://github.com/tung-nd/TNP-pytorch and its respective paper (Nguyen & Grover, 2022)).
The hyperparameters for the CelebA experiments are the same regardless of the resolution.
EQTNP experiments follow almost identically the TNP experiment hyperparameters.
The only difference is that EQTNPs architecture is slightly different than that of TNP.
Specifically, EQTNP has a crossattention mechanism to retrieve information from the context dataset.
The number of cross-attention layers in EQTNP is equivalent to that of the number of self-attention layers in TNP.
Similarly,
LBANP hyperparameters are almost identical to that of EQTNP and that of TNP.
LBANP consists of blocks each comprising of a cross-attention mechanism from the context dataset to the latent space and a self-attention mechanism in the latent space.
In LBANP, the number of blocks for the conditioning phase is equivalent to the number self-attention mechanisms in the conditioning phase of EQTNP.
Due to its cross-attention mechanisms, LBANP allows for varying embedding sizes for the context dataset D C , latent vectors D L , and query dataset D C .
For simplicity, we set D C
= D L = D Q = 64 , following TNP’s embedding size of 64 .
Similarly for EQTNP, we set D c
= D Q = 64 .
We do not tune the number of latent vectors ( L ).
Instead, we showed results for LBANP with L = 8 and
L = 128 latent vectors.
The remainder of the hyperparameters is the same for LBANP, EQTNP, and
TNP.
For the ND experiments, we follow TNP-ND (Nguyen & Grover, 2022) and use cholesky decomposition for our LBANP-NP and LBANP-ENP experiments.
All experiments were either run on a
GTX 1080ti (12 GB RAM) or P100 GPU (16 GB RAM).
When verifying if computationally expensive models were trainable for CelebA64 and CelebA128, we used the P100 GPU (the GPU with larger amounts of RAM).
B. A NALYSIS : N UMBER OF L ATENTS
In this section, we include an additional plot (see Figure 5) that analyses the effect of varying the number of latent vectors.
We clearly see that scaling the number of latent vectors improves the performance of LBANP.
At 512 latent vectors, we see that LBANP achieves performance competitive with that of TNP-D.
B. A BLATION : I NTERLEAVING CROSS - ATTENTION LAYERS
In this ablation, we verify whether interleaving the cross-attention layers is important for LBANP.
In this experiment, we consider LBANP-L (LBANP-Last) where instead of multiple cross-attention layers for querying, the model only uses a single cross-attention layer which attends over the last latent embedding.
In Table 7, we see that LBANP outperforms LBANP-L.
As such, indeed in- terleaving the multiple cross-attention layers to retrieve higher-order information from the context dataset for the target datapoint is important.
[Table]
B. A NALYSIS : C OMPUTATIONAL C OMPLEXITY B.4. E MPIRICAL T IME C OMPLEXITY
In these experiments, we show the empirical time cost to perform predictions with various Neural
Process models.
In Figure 6a, we fix the number of target datapoints and vary the number of context datapoints. In Figure 6b, we fix the number of context datapoints and vary the number of target datapoints.
In both experiments, we see that TNP’s require significantly more time as the number of datapoints scale.
In contrast, we see that EQTNPs and LBANPs remain efficient regardless of the number of datapoints.
Importantly, we see that regardless of the number of context datapoints, LBANPs queries use the same amount of time.
[Figure]
B.4. E MPIRICAL M EMORY C OMPLEXITY
In these experiments, we show the empirical memory cost to perform predictions with various Neural
Process models.
In Figure 7a, we fix the number of target datapoints and vary the number of context datapoints.
The figure shows that with respect to the number of context datapoints: (1) TNP’s memory cost scales quadratically, (2) EQTNP’s memory cost scales linearly, and (3) LBANP’s memory cost stays constant.
These results confirm the big-O complexity analysis in Table 1.
When
N = 1400 , LBANP ( L = 128 ) uses 1172 MBs of memory and TNP uses 13730 MBs of memory (more than 11 times the memory LBANP used), showing a significant benefit of using LBANPs in practice.
In Figure 7b, we fix the number of context and target datapoints and vary only the number of latent vectors for LBANPs.
The plot shows that the memory cost of LBANPs indeed scales linearly with the number of latent vectors.
[Figure]
B. A NALYSIS : C ONVERGENCE
Following TNPs, we run our experiments for 200 epochs.
In Fig 8, we see that TNPs converge slightly quicker than that of LBANPs and EQTNPs.
By comparing LBANP ( L = 128 ) and LBANP ( L = 8 ), we see that increasing the number of latent vectors help LBANPs learn quicker.