S ET T RANSFORMER
Anonymous authors
Paper under double-blind review
A BSTRACT
Many machine learning tasks such as multiple instance learning, 3D shape recognition and few-shot image classiﬁcation are deﬁned on sets of instances .
Since solutions to such problems do not depend on the permutation of elements of the set, models used to address them should be permutation invariant .
We present an attention-based neural network module, the Set Transformer , speciﬁcally designed to model interactions among elements in the input set.
The model consists of an encoder and a decoder, both of which rely on attention mechanisms.
In an effort to reduce computational complexity, we introduce an attention scheme inspired by inducing point methods from sparse Gaussian process literature.
It reduces computation time of self-attention from quadratic to linear in the number of elements in the set.
We show that our model is theoretically attractive and we evaluate it on a range of tasks, demonstrating increased performance compared to recent methods for set-structured data.
I NTRODUCTION
Learning representations has proven to be an essential problem for deep learning and its many success stories.
The majority of problems tackled by deep learning are instance-based and take the form of mapping a ﬁxed-dimensional input tensor to its corresponding target value (Krizhevsky et al., 2012; Graves et al., 2013).
For some applications, we are required to process set-structured data .
Multiple instance learning (Dietterich et al., 1997; Maron & Lozano-P ´ erez, 1998) is an example of such a set-input problem, where a set of instances is given as an input and the corresponding target is a label for the entire set.
Other problems such as 3D shape recognition (Wu et al., 2015; Shi et al., 2015; Su et al., 2015; Charles et al., 2017), sequence ordering (Vinyals et al., 2016), and various set operations (Muandet et al., 2012; Oliva et al., 2013; Edwards & Storkey, 2017; Zaheer et al., 2017) can also be viewed as such set-input problems.
Moreover, many meta-learning (Thrun & Pratt, 1998; Schmidhuber, 1987) problems which learn using a set of different but related tasks may also be treated as set-input tasks where an input set corresponds to the training dataset of a single task.
For example, few-shot image classiﬁcation (Finn et al., 2017; Snell et al., 2017; Lee & Choi, 2018) operates by building a classiﬁer using a support set of images, which is evaluated with query images.
A model for set-input problems should satisfy two critical requirements.
First, it should be permutation invariant — the output of the model should not change under any permutation of the elements in the input set.
Second, such a model should be able to process input sets of any size.
While these requirements stem from the deﬁnition of a set, they are not easily satisﬁed in neursal-network-based models: classical feed-forward neural networks violate both requirements, and RNNs are sensitive to input order.
Recently, Edwards & Storkey (2017) and Zaheer et al.
(2017) propose neural network architectures which meet both criteria, which we call set pooling methods.
In this model, each element in a set is ﬁrst independently fed into a feed-forward neural network that takes ﬁxed-size inputs.
Resulting feature-space embeddings are then aggregated using a pooling operation ( mean , sum , max or similar).
The ﬁnal output is obtained by further non-linear processing of the aggregated embedding.
This remarkably simple architecture satisﬁes both aforementioned requirements, and more importantly, is proven to be a universal approximator for any set function (Zaheer et al., 2017).
Thanks to this property, it is possible to learn complex mapping between input sets and their target outputs in a black-box fashion, much like with feed-forward or recurrent neural networks.
Even though this set pooling approach is theoretically attractive, it remains unclear whether we can approximate complex mappings well using only instance-based feature extractors and simple pooling operations.
Since every element in a set is processed independently in a set pooling operation, some information regarding interactions between elements has to be necessarily discarded.
This can make some classes of problems unnecessarily difﬁcult to solve.
Consider the problem of meta-clustering: we would like to learn a parametric mapping from an input set of points to centers of any clusters in the set, for many such sets.
Even though a neural network with a set pooling operation can approximate such a mapping by learning to quantize space, this quantization cannot depend on the contents of the set.
It limits the quality of the solution on one hand, and may make optimization of such a model more difﬁcult; we show empirically in Sectionthat it leads to under-ﬁtting.
In this paper, we propose a novel set-input deep neural network architecture called the Set Transformer , ( cf.
Transformer , Vaswani et al.
The novelty of the Set Transformer comes from three important design choices: 1) We use a self-attention mechanism based on the Transformer to process every element in an input set, which allows our approach to naturally encode pairwiseor higher-order interactions between elements in the set.
We propose a method to reduce the
O ( n 2 ) computation time of Transformers to O ( nm ) where m is a ﬁxed hyperparameter.
We use a self-attention mechanism to aggregate features, which is especially beneﬁcial when the problem of interest requires multiple dependent outputs, such as the problem of meta-clustering, where the meaning of each cluster center heavily depends its location relative to the other clusters.
We apply the Set Transformer to several set-input problems and empirically demonstrate the importance and effectiveness of these design choices.
This paper is organized as follows.
In Section 2, we brieﬂy review the concept of set functions, existing architectures, and the self-attention mechanism.
In Section 3, we introduce Set Transformers, our novel neural network architecture for set functions.
In Section 4, we present various experiments that demonstrate the beneﬁts of the Set Transformer.
We discuss related works in Sectionand conclude the paper in Section 6.
B ACKGROUND 2. P OOLING ARCHITECTURE FOR SETS
Problems involving a set of objects have the permutation invariance property: the target value for a given set is the same regardless of the order of objects in the set.
A simple example of a permutation invariant model is a network that performs pooling over embeddings extracted from the elements of a set.
More formally,
[Equation]
Zaheer et al.
(2017) has proven that all permutation invariant functions can be represented as (1) when pool is the sum operator and ρ, φ any continuous functions, thus justifying the use of this architecture for set-input problems.
Note that we can deconstruct (1) into two parts: an encoder ( φ ) which independently acts on each element of a set of n items, and a decoder ( ρ (pool( · )) ) which aggregates these encoded features and produces our desired output.
Most network architectures for set-structured data follow this encoderdecoder structure.
Our proposed method is also composed of an encoder and a decoder, but our embedding function φ does not act independently on each item but considers the whole set to obtain the embedding.
Additionally, instead of a ﬁxed function such as mean , our aggregating function pool( · ) is parameterized and can thus adapt to the problem at hand.
2. A TTENTION
Assume we have n query vectors (corresponding to n points in an input set)
each with dimension d q : Q ∈ R n × d q .
An attention function Att( Q, K, V ) is a function that maps queries Q to outputs using n v key-value pairs K ∈ R n v × d q , V ∈ R n v × d v . Att( [Equation] , K,
[Equation]
=
[Equation]
V. [Table] [Figure] The pairwise dot product QK (cid:62) ∈ R n × n v measures how similar each pair of query and key vectors is, with weights computed with an activation function ω .
The output ω ( QK (cid:62) )
V is a weighted sum of V where a value gets more weight if its corresponding key has larger dot product with the query.
Multi-head attention , originally introduced in Vaswani et al.
(2017), is an extension of the previous attention scheme.
Instead of computing a single attention function, this method ﬁrst projects
Q, K, V onto h different d Mq , d Mq , d Mv -dimensional vectors, respectively.
An attention function ( Att( · ; ω j ) ) is applied to each of these h projections.
The output is a linear transformation of the concatenation of all attention outputs:
[Equation]
where
[Equation]
Note that Multihead( · , · , · ; λ ) has learnable parameters
λ
= { W Qj , W Kj , W Vj } hj =1 , where
[Equation] Vj ∈ R
d v × d Mv , W O ∈ R hd Mv × d .
A typical choice for the dimension hyperparameters is d Mq =
d q /h , d Mv = d v /h , d = d q .
For brevity, we set d q = d v = d and d Mq =
d
Mv = d/h throughout the rest of the paper.
Unless speciﬁed otherwise, we use the scaled softmax ω j ( · ) = softmax( · / √ d ) , which our experiments showed worked robustly in most settings.
S ET TRANSFORMER
In this section, we motivate and describe the Set Transformer : an attention-based neural network architecture that is designed to process sets of data.
A Set Transformer consists of an encoder followed by a decoder ( cf.
Section 2.1).
The encoder transforms a set of instances into a set of features, which the decoder transforms into the desired ﬁxed-dimensional output.
3. A TTENTION - BASED SET OPERATIONS
We begin by deﬁning our attention-based set operations.
While existing pooling methods for sets obtain instance features independently of other instances, we use self-attention to concurrently encode the whole set.
This gives the Set Transformer the ability to preserve pairwise as well as higher-order interactions among instances during the encoding process.
For this purpose, we adapt the multihead attention mechanism used in Transformer.
We emphasize that all blocks introduced here are neural network blocks with their own parameters, and not ﬁxed functions.
Given matrices X, Y ∈ R n × d which represent two sets of d -dimensional vectors, we deﬁne the
Multihead Attention Block (MAB) with parameters λ as follows:
[Equation]
where H = LayerNorm
( X + Multihead
( X, Y, Y ; ω )) ,
[Equation]
6) where rFF is any row-wise feedforward layer (i.e. it processes each instance independently and identically), and LayerNorm is layer normalization (Ba et al., 2016).
The MAB is an adaptation of the encoder block of the Transformer (Vaswani et al., 2017) without positional encoding and dropout.
Using the MAB, we deﬁne the Set Attention Block (SAB) as
[Equation]
In other words, an SAB takes a set and performs self-attention between the elements in the set, resulting in a set of equal size.
Since the output of SAB contains information about pairwise interactions between the elements in the input set X , we can stack multiple SABs to encode higher order interactions.
Note that while the SAB (7) involves a multihead attention operation (6), where
Q = K = V
=
X , it could reduce to applying a residual block on X .
In practice, it learns more complicated functions due to linear projections of X inside attention heads, (2) and (4).
A potential problem with using SABs for set-structured data is the quadratic time complexity O ( n 2 ) , which may be too expensive for large sets ( n (cid:29) 1 ).
We thus introduce the Induced Set Attention
Block (ISAB), which bypasses this problem.
Along with the set X ∈ R n × d , additionally deﬁne m d -dimensional vectors I ∈ R m × d , which we call inducing points .
Inducing points I are part of the
ISAB itself, and they are trainable parameters which we train along with other parameters of the network.
An ISAB with m inducing points I is deﬁned as:
[Equation]
where H = MAB( I, X ) ∈ R m × d
[Equation]
The ISAB ﬁrst transforms I into H by attending to the input set.
The set of transformed inducing points H , which contains information about the input set X , is again attended to by the input set X to ﬁnally produce a set of n elements.
This is analogous to low-rank projection or autoencoder models, where inputs ( X ) are ﬁrst projected onto a low-dimensional object ( H ) and then reconstructed to produce outputs.
The difference is that the goal of these methods is reconstruction whereas ISAB aims to obtain good features for the ﬁnal task.
We expect the learned inducing points to encode some global structure which helps explain the inputs X .
As an example, think of a clustering problem on a 2D plane.
The inducing points could be appropriately distributed points on the 2D plane so that the encoder can compare elements in the query dataset indirectly through their proximity to these grid points.
Note that in (8) and (9), attention was computed between a set of size m and a set of size n .
Therefore, the time complexity of ISAB m ( X ; λ ) is O ( nm ) where m is a hyperparameter — an improvement over the quadratic complexity of the SAB.
We compare characteristics of various set operations in Table 1.
We also emphasize that both of our set operations are permutation equivariant :
Deﬁnition 1.
We say a function f : X n → Y n is permutation equivariant iff for any permutation π ∈ S n , f ( πx ) =
πf ( x ) .
Here S n is the set of all permutations of indices { 1 , · · · , n } .
Property 1.
Both SAB( X ) and ISAB m ( X ) are permutation equivariant.
3. E NCODER
Using the SAB and ISAB deﬁned above, we construct the encoder Encoder :
X (cid:55)→ Z ∈ R n × d of the Set Transformer by stacking multiple SABs or multiple ISABs, for example:
[Equation]
We point out again that the time complexity for (cid:96) stacks of SABs and ISABs are O ( (cid:96)n 2 ) and
O ( (cid:96)nm ) , respectively.
This can result in much lower processing times when using ISAB (as compared to SAB), while still maintaining high representational power.
3. D ECODER
After the encoder transforms data X ∈ R n × d x into features Z ∈ R n × d , the decoder aggregates them into a single vector which is fed into a feed-forward network to get ﬁnal outputs.
A common aggregation scheme is to simply take the average or dimension-wise maximum of the feature vectors ( cf.
Section 1).
We instead aggregate features by applying multihead attention on a learnable set of k seed vectors S ∈ R k × d .
We call this scheme Pooling by Multihead Attention (PMA):
[Equation]
) where PMA k
[Equation]
Z [Equation]
=
[Equation]
Note that the output of PMA k is a set of k items.
In most cases, using one seed vector ( k = 1 ) and no SAB sufﬁced.
However, when the problem of interest requires k correlated outputs, the natural thing to do is to use k inducing points.
An example of such a problem is clustering where the desired output is k centers.
In this case, the additional SAB was crucial because it allowed the network to directly take the correlation between the k pooled features into account.
Intuitively, feature aggregation using attention should be beneﬁcial because the inﬂuence of each instance on the target is not necessarily equal.
For example, consider a problem where the target value is the maximum value of a set of real numbers.
Since the target can be recovered using only a single instance (the largest), ﬁnding and attending to that instance during aggregation will be advantageous.
In the next subsection, we further analyze both the encoder and decoder structures more rigorously.
3. A NALYSIS
Since the blocks used to construct the encoder (i.e., SAB, ISAB) are permutation equivariant, the mapping of the encoder X
→ Z is permutation equivariant as well.
Combined with the fact that
the
PMA in the decoder is a permutation invariant transformation, we have the following:
Proposition
The Set Transformer is permutation invariant.
Being able to approximate any function is a desirable property, especially for black-box models such as deep neural networks.
Building on previous results about the universal approximation of permutation invariant functions, we prove the universality of Set Transformers:
Proposition 2.
The Set Transformer is a universal approximator of permutation invariant functions.
Proof.
See Appendix A.
E XPERIMENTS
To evaluate the Set Transformer, we apply it to a suite of tasks involving sets of data points.
We repeat all experiments ﬁve times and report performance metrics evaluated on corresponding test datasets.
Along with baselines, we compared various architectures arising from the combination of the choices of having attention in encoders and decoders.
Unless speciﬁed otherwise, ”simple pooling” means average pooling.
• rFF + Pooling ( Zaheer et al.
(2017)): rFF layers in encoder and simple pooling + rFF layers in decoder.
• rFFp-mean/rFFp-max
+ Pooling
(Zaheer et al.
(2017)): rFF layers with permutation equivariant variants in encoder (Eq (4) in Zaheer et al. and simple pooling + rFF layers in decoder.
• rFF + Dotprod (Yang et al. ; Ilse et al.
(2018)): rFF layers in encoder and dot product attention based pooling + rFF layers in decoder. • SAB(ISAB) + Pooling: Stack of SABs (ISABs) in encoder and simple pooling + rFF layers in decoder. • rFF + PMA: rFF layers in encoder and PMA (followed by stack of SABs) in decoder.
• Set Transformer: Stack of SABs (ISABs) in encoder and PMA (followed by stack of SABs) in decoder. [Table] [Table]
4. T OY P ROBLEM : M AXIMUM V ALUE R EGRESSION
To demonstrate the advantage of attention-based set aggregation over simple pooling operations [Table] we consider a toy problem: regression to the maximum value of a given set.
Given a set of real numbers { x 1 , · · · , x n } , the goal is to return max( x 1 , · · · , x n ) .
Given prediction p , we use the mean absolute error | p − max( x 1 , · · · , x n ) | as the loss function.
We constructed simple pooling architectures with three different pooling operations: max , mea n, and sum .
We report loss values after training in Table 2.
Mean- and sum-pooling architectures result in a high mean absolute error (MAE).
The model with max-pooling can predict the output perfectly by learning its encoder to be an identity function, and thus achieves the highest performance.
Notably, the Set Transformer achieves performance comparable to the max-pooling model, which underlines the importance of additional ﬂexibility granted by attention mechanisms — it can learn to ﬁnd and attend to the maximum element
. 4. C OUNTING U NIQUE C HARACTERS
In order to test the ability of modelling interactions between objects in a set, we introduce a new task of counting unique elements in an input set.
We use the Omniglot (Lake et al., 2015) dataset, which consists of 1,623 different handwritten characters from various alphabets, where each character is represented by 20 different images.
We split all characters (and corresponding images) into train, validation, and test sets and only train using images from the train character classes.
We generate input sets by sampling between 6 andimages and we train the model to predict the number of different characters inside the set.
We used a Poisson regression model to predict this number, with the rate λ given as the output of a neural network.
We maximized the log likelihood of this model using stochastic gradient ascent.
We evaluated model performance using sets of images sampled from the test set of characters.
Table 3 reports accuracy, measured as the frequency at which the mode of the Poisson distribution chosen by the network is equal to the number of characters inside the input set.
4. S OLVING M AXIMUM LIKELIHOOD PROBLS FOR MIXTURE OF G AUSSIANS
We applied the set-input networks to the task of maximum likelihood of mixture of Gaussians (MoGs).
The log-likelihood of a dataset X = { x 1 , . . .
, x n } generated from an MoG with k components is
[Equation]
[Equation]
The goal is to learn the optimal parameters θ ∗ ( X ) =
arg max θ log p (
X ; θ ) .
The typical approach to this problem is to run an iterative algorithm such as Expectation-Maximisation (EM) until convergence.
Instead, we aim to learn a generic meta-algorithm that directly maps the input set X to θ ∗ ( X ) .
One can also view this as amortized maximum likelihood learning.
Speciﬁcally, given a dataset X , we train a neural network to output parameters f
( X ; λ ) =
{ π ( X ) , { µ j ( X ) , σ j ( X ) } kj =1 } which maximize
[Equation]
We structured f ( · ; λ ) as a set-input neural network and learned its parameters λ using stochastic gradient ascent, where we approximate gradients using minibatches of datasets .
We tested Set Transformers along with other set-input networks on two types of datasets.
We used four seed vectors for the PMA ( S ∈ R 4 × d ), the same as the number of clusters.
Synthetic 2D mixtures of Gaussians : Each dataset contains n ∈ [100 , 500] points on a 2D plane, each sampled from one of four Gaussians.
CIFAR-100 meta-clustering : Each dataset contains n ∈ [100 , 500] images sampled from four random classes in the CIFAR-100 dataset.
Each image is represented by a 512-dim vector obtained from a pretrained VGG net (Simonyan & Zisserman, 2014). [Table]
We report the performance of the oracle and of different models in Table 4.
Additionally, it contains scores attained by all models after a single EM update.
Overall, the Set Transformer found accurate parameters and even outperformed the oracles after a single EM update.
This can be explained by relatively small size of the input sets, which leads to some clusters having fewer than 10 points.
In this regime
[Table]
sample statistics can differ from population statistics, which limits the performance of the oracle
[Table]
but the Set Transformer can adapt accordingly.
Notably, the Set Transformer with only 16 inducing points showed the best performance, even outperforming the full Set Transformer.
We believe this is due to the knowledge transfer and regularization via inducing points, helping the network to learn global structures.
Our results also imply that the improvements from using the PMA is more signiﬁcant than that of using SAB, supporting our claim of the importance of attention-based decoders.
We provide detailed generative processes, network architectures, and training schemes along with additional experiments with various numbers of inducing points in Appendix B. [Table]
4. M ETA S ET A NOMALY D ETECTION
[Table]
We evaluate our methods on the task of meta-anomaly detection within a set using the CelebA dataset.
The dataset consists of 202,599 images with the total of 40 attributes.
We randomly sample 1,000 sets of images.
For every set, we select two attributes at random and construct the set by selecting seven images containing both attributes and one image with neither.
The goal of this task is to ﬁnd the image that does not belong to the set.
We give a detailed description of the experimental setup in Appendix B.4.
Table 5 contains empirical results, which show that Set Transformers outperformed all other methods by a signiﬁcant margin.
4. P OINT C LOUD C LASSIFICATION
We evaluated Set Transformers on a classiﬁcation task using the ModelNet40 (Chang et al., 2015) dataset, containing 40 categories of three-dimensional objects.
Each object is represented as a point cloud, which we treat as a set of n elements in R 3 .
Table 6 contains experimental results on point clouds 1 with n = 1000 points each.
In this setting, MABs turned out to be prohibitively expensive due to their O ( n 2 ) time complexity.
Additional results with n = 100 points and experiment details are available in Appendix B.5.
Note that ISAB (16) + Pooling outperformed Set Transformers (ISAB (16) + PMA (1)) by a large margin.
Our interpretation is that the class of a point cloud object could be efﬁciently represented by simple aggregation of point features, and the PMA suffered from an optimization issue in this setting.
We would like to point out that PMA outperformed simple pooling in all other experiments.
[Table]
R ELATED W ORKS
Pooling architectures for permutation invariant mappings Pooling architectures for sets have been used in various problems such as 3D shape recognition (Shi et al., 2015;
Su et al., 2015), discovering causality (Lopez-Paz et al., 2016), learning the statistics of a set (Edwards & Storkey, 2017), few-shot image classiﬁcation (Snell et al., 2017), and conditional regression and classiﬁcation (Garnelo et al., 2018).
Zaheer et al.
(2017) discusses the structure in general and provides a partial proof of the universality of the pooling architecture.
Attention-based approaches for sets Vinyals et al.
(2016) proposes an architecture to map sets into sequences, where elements in a set are pooled by weighted average with weights computed from attention mechanism.
Several recent works have highlighted the competency of attention mechanisms in modeling sets.
(Yang et al., 2018) proposes AttSets for multi-view 3D reconstruction, where attention is applied to the encoded features of elements in sets before pooling.
Similarly, (Ilse et al., 2018) uses an attention in pooling for multiple instance learning.
However, the attention applied in those papers are simple dot-product attention that does not encode higher-order interactions between elements.
Although not permutation invariant, (Mishra et al., 2018) has an attention as one of its core components to meta-learn to solve various tasks using sequences of inputs.
Modeling interactions between elements in sets An important reason to use the Transformer is to explicitly model higher-order interactions among the elements in a set.
Santoro et al.
(2017) proposes the relational network, a simple architecture that sum-pools all pairwise interactions of elements in a given set, but not higher-order interactions.
Similarly to our work, Ma et al.
(2018) uses the Transformer to model interactions between the objects in a video.
They use mean-pooling to obtain aggregated features which they fed into an LSTM.
Inducing point methods The idea of letting trainable vectors I directly interact with datapoints is loosely based on the inducing point methods used in sparse Gaussian processes (Qui˜nonero-Candela et al. Rasmussen, 2005) and the Nystr¨om method for matrix decomposition (Fowlkes et al., 2004).
m trainable inducing points can also be seen as m independent memory cells accessed with an attention mechanism.
The Differential Neural Dictionary (Pritzel et al., 2017) stores previous experience as key-value pairs and uses this to process queries.
One can view the ISAB is the inversion of this idea, where queries I are stored and the input features are used as key-value pairs.
C ONCLUSION
In this paper, we introduced the Set Transformer, an attention-based set-input neural network architecture.
Our proposed method uses attention mechanisms for both encoding and aggregating features, and we have empirically validated that both of them are necessary for modelling complicated interactions among elements of a set.
We also proposed an inducing point method for self-attention, which makes our approach scalable to large sets.
We also showed useful theoretical properties of our model, including the fact that it is a universal approximator for permutation invariant functions.
To the best of our knowledge, no previous work has successfully trained a neural network to perform amortized clustering in a single forward pass.
An interesting topic for future work would be to apply Set Transformers to meta-learning problems other than meta-clustering.
In particular, using Set Transformers to meta-learn posterior inference in Bayesian models seems like a promising line of research.
Another exciting extension of our work would be to model the uncertainty in set functions by injecting noise variables into Set Transformers in a principled way.
Appendices A P ROOFS
Lemma 1.
The mean operator mean( { x 1 , · · · , x n } )
= 1 n (cid:80) ni
=1 x i is a special case of dot-product attention with softmax.
Proof.
Let s = 0 ∈ R d and X ∈ R n × d .
[Equation]
Lemma 2.
The decoder of a Set Transformer, given enough nodes, can express any element-wise function of the form (cid:0) 1 n
[Equation]
Proof.
We ﬁrst note that we can view the decoder as the composition of functions
[Equation]
where H = rFF(MAB
( Z, rFF( Z )))
We focus on H in equation (17).
Since feed-forward networks are universal function approximators at the limit of inﬁnite nodes, let the feed-forward layers in front and back of the MAB encode the element-wise functions z → z p and z → z 1 p , respectively.
We let h =
d , so the number of heads is the same as the dimensionality of the inputs, and each head is one-dimensional.
Let the projection matrices in multi-head attention ( W Qj , W Kj , W Vj ) represent projections onto the jth dimension and the output matrix ( W O ) the identity matrix.
Since the mean operator is a special case of dot-product attention, by simple composition, we see that an MAB can express any dimension-wise function of the form
[Equation] [Equation]
Lemma 3.
A PMA, given enough nodes, can express sum pooling ( (cid:80) ni
[Equation]
1 z i ) .
Proof.
We prove this by construction.
Set the seed s to a zero vector and let ω ( · ) = 1 + f ( · ) , where f is any activation function such that f (0) = 0 .
The identiy, sigmoid, or relu functions are suitable choices for f .
The output of the multihead attention is then simply a sum of the values, which is Z in this case.
We additionally have the following universality theorem for pooling architectures:
Theorem 1.
Models of the form rFF(sum(rFF( · ))) are universal function approximators in the space of permutation invariant functions.
Proof.
See Appendix A of Zaheer et al.
By Lemma 3, we know that decoder( Z ) can express any function of the form rFF (sum( Z )) .
Using this fact along with Theorem 1, we can prove the universality of Set Transformers:
Proposition 2.
The Set Transformer is a universal function approximator in the space of permutation invariant functions.
Proof.
By setting the matrix W O to a zero matrix in every SAB and ISAB, we can ignore all pairwise interaction terms in the encoder.
Therefore, the encoder( X ) can express any instance-wise feed-forward network ( Z = rFF( X ) ).
Directly invoking Theorem 1 concludes this proof.
While this proof required us to ignore the pairwise interaction terms inside the SABs and ISABs to prove that Set Transformers are universal function approximators, our experiments indicated that self-attention in the encoder was crucial for good performance.
B E XPERIMENT D ETAILS
In all implementations, we omit the feed-forward layer in the beginning of the decoder ( rFF( Z ) )
because the end of the previous block contains a feed-forward layer.
All MABs (inside SAB, ISAB and PMA) use fully-connected layers with ReLU activations for rFF layers.
In the architecture descriptions, FC( d, f ) denotes the fully-connected layer with d units and activation function f .
SAB( d, h ) denotes the SAB with d units and h heads.
ISAB m ( d, h ) denotes the
ISAB with d units, h heads and m inducing points.
PMA k ( d, h ) denotes the PMA with d units, h heads and k vectors.
All MABs used in SAB and PMA uses FC layers with ReLU activations for
FF layers.
B. M AX R EGRESSION
Given a set of real numbers { x 1 , · · · , x n } , the goal of this task is to return the maximum value in the set max( x 1 , · · · , x n ) .
We construct training data as follows.
We ﬁrst sample a dataset size n uniformly from the set of integers { 1 , · · · , 10 } .
We then sample real numbers x i independently from the interval [0 , 100] .
Given the network’s prediction p , we use the actual maximum value max( x 1 , · · · , x n ) to compute the mean absolute error | p − max( x 1 , · · · , x n ) | .
We don’t explicitly consider splits of train and test data, since we sample a new set { x 1 , · · · , x n } at each time step.
[Table]
[Figure]
We show the detailed architectures used for the experiments in Table 7.
We trained all networks using the Adam optimizer (Kingma & Ba, 2015)with a constant learning rate of 10 − 3 and a batch size of 128 for 20000 batches, after which loss converged for all architectures.
B. C OUNTING U NIQUE C HARACTERS
The task generation procedure is as follows.
We ﬁrst sample a set size n uniformly from the set of integers { 6 , · · · , 10 } .
We then sample the number of characters c uniformly from { 1 , · · · , n } .
We sample c characters from the training set of characters, and randomly sample instances of each character so that the total number of instances sums to n and each set of characters has at least one instance in the resulting set.
We show the detailed architectures used for the experiments in Table 9.
For both architectures, the resulting 1 -dimensional output is passed through a softplus activation to produce the Poisson parameter γ .
The role of softplus is to ensure that γ is always positive.
[Table] [Table]
The loss function we optimize, as previously mentioned
[Table]
is the log likelihood log p ( x | γ ) =
x log( γ ) − γ − log( x !) .
We chose this loss function over mean squared error or mean absolute error because it seemed like the more logical choice when trying to make a real number match a target integer.
Early experiments showed that directly optimizing for mean absolute error had roughly the same result as optimizing γ in this way and measuring | γ − x | .
We train using the Adam optimizer with a constant learning rate of 10 − 4 for 200 , 000 batches each with batch size 32 .
B. S OLVING MAXIMUM LIKELIHOOD PROBLEMS FOR MIXTURE OF G AUSSIANS B.3. D ETAILS FOR 2D SYNTHETIC MIXTURES OF G AUSSIANS EXPERIMENT
We generated the datasets according to the following generative process.
Generate the number of data points, n ∼ Unif(100 , 500) .
Generate k centers.
[Equation]
Generate cluster labels.
[Equation]
Generate data from spherical Gaussian.
[Equation]
Table 10 summarizes the architectures used for the experiments.
For all architectures, at each training step, we generate 10 random datasets according to the above generative process, and updated the parameters via Adam optimizer with initial learning rate 10 − 3 .
We trained all the algorithms for 50 k steps, and decayed the learning rate to 10 − 4 after 35 k steps.
Table 11 summarizes the detailed results with various number of inducing points in the ISAB.
Figure 3 shows the actual clustering results based on the predicted parameters. [Table] [Table]
± 0. [Table] rFF + PMA - [Table]
6680 ±
[Table]
[Table]
5409 ±
[Table]
Set Transformer -1.5145 ± 0.
[Table]
[Table]
4619 ± 0.
[Table]
Set Transformer (16) -1.5009 ± 0.
[Table]
-1.4530 ± 0.
[Table]
Set Transformer (32) -1.4963 ±
[Table]
-1.4524 ±
[Table]
Set Transformer (64) -
[Table]
±
[Table]
[Table]
4535 ±
[Table] B.3. 2D S YNTHETIC M IXTURES OF G AUSSIANS E XPERIMENT ON L ARGE - SCALE D ATA To show the scalability of the set transformer, we conducted additional experiments on large-scale 2D synthetic clustering dataset. We generated the synthetic data as before, except that we sample the number of data points n Unif(1000 , 5000) and set k = 6 .
We report the clustering accuracy of a subset of comparing methods in Table 12. The set transformer with only 32 inducing points works extremely well, demonstrating its scalability and efﬁciency.
[Table]
[Table]
We pretrained VGG net (Simonyan & Zisserman, 2014) with CIFAR-100, and obtained the test accuracy 68.54%.
Then, we extracted feature vectors of 50k training images of CIFAR-100 from the 512-dimensional hidden layers of the VGG net (the layer just before the last layer).
Given these feature vectors, the generative process of datasets is as follows.
Generate the number of data points, n ∼ Unif(100 , 500) .
Uniformly sample four classes among 100 classes.
Uniformly sample n data points among four sampled classes.
Table 13 summarizes the architectures used for the experiments.
For all architectures, at each training step, we generate 10 random datasets according to the above generative process, and updated the parameters via Adam optimizer with initial learning rate 10 − 4 .
We trained all the algorithms for 50 k steps, and decayed the learning rate to 10 − 5 after 35 k steps.
Table 14 summarizes the detailed results with various number of inducing points in the ISAB.
B. M ETA S ET A NOMALY
Table 15 describes the architecture for meta set anomaly experiments.
We trained all models via
Adam optimizer with learning rate 10 − 4 and exponential decay of learning rate for 1,000 iterations.
1,000 datasets subsampled from CelebA dataset (see Figure 4) are used to train and test all the methods.
We split 800 training datasets and 200 test datasets for the subsampled datasets.
B. P OINT C LOUD C LASSIFICATION
We used the ModelNet40 dataset for our point cloud classiﬁcation experiments.
This dataset consists of a 3-dimensional representation of 9,843 training and 2,468 test data which each belong to one of 40 object classes.
As input to our architectures, we produce point clouds with n = 100 , 1 , 000 points each (each point is represented by ( x, y, z ) coordinates).
For generalization, we randomly rotate and scale each set during training.
We show results our architectures in Table 16 and additional experiments which used n = 100 points in Table 17.
We trained using the Adam optimizer with an initial learning rate of 10 − 3 which we decayed by a factor of 0 .
3 every 20 , 000 steps.
[Table]
of ﬁgure.
On the other hand, abnormal image does not contain the two attributes.
C A DDITIONAL E XPERIMENTS C. R UNTIME OF SAB AND ISAB
We measured the runtime of SAB and ISAB on a simple benchmark (Figure 5).
We used a single
GPU (Tesla P40) for this experiment.
The input data was a constant (zero) tensor of n 3 -dimensional vectors.
We report the number of seconds it took to process 10000 sets of each size.
The maximum set size we report for SAB is 2000 because the computation graph of bigger sets could not ﬁt on our
GPU.
The speciﬁc attention blocks used are ISAB 4 (64 , 8) and SAB(64 , 8) .
C. N UMBER OF I NDUCING POINTS AND PERFORMANCE
We trained ISAB n + PMA on the unique character counting task, varying the number of inducing points n .
Accuracies are shown in Figure 6.
Accuracies of other architectures (from Table 8) are shown as horizontal lines for comparison.
Note ﬁrst that even the accuracy of ISAB 1 + PMA surpasses that of both rFF + Pooling and rFF + PMA.
Also observe that accuracy tends to increase as n increases. We additionally found that [Table] [Table]
using larger values of n (32, 64) did not increase accuracy by a signiﬁcant margin.
However, ISAB + PMA actually outperformed SAB + PMA in the clustering task (see Table 11).
[Table]