Set Transformer
Set Transformer
Juho Lee 1 2 Yoonho Lee 3 Jungtaek Kim 4 Adam R. Kosiorek 1 5 Seungjin Choi 4 Yee Whye Teh 1
Many machine learning tasks such as multiple input and the corresponding target is a label for the entire
instance learning, 3D shape recognition and few- set. Other problems such as 3D shape recognition (Wu et al.,
shot image classification are defined on sets of in- 2015; Shi et al., 2015; Su et al., 2015; Charles et al., 2017),
stances. Since solutions to such problems do not sequence ordering (Vinyals et al., 2016), and various set op-
depend on the order of elements of the set, mod- erations (Muandet et al., 2012; Oliva et al., 2013; Edwards &
els used to address them should be permutation Storkey, 2017; Zaheer et al., 2017) can also be viewed as the
invariant. We present an attention-based neural set-input problems. Moreover, many meta-learning (Thrun
network module, the Set Transformer, specifically & Pratt, 1998; Schmidhuber, 1987) problems which learn
designed to model interactions among elements using different, but related tasks may also be treated as set-
in the input set. The model consists of an encoder input tasks where an input set corresponds to the training
and a decoder, both of which rely on attention dataset of a single task. For example, few-shot image clas-
mechanisms. In an effort to reduce computational sification (Finn et al., 2017; Snell et al., 2017; Lee & Choi,
complexity, we introduce an attention scheme in- 2018) operates by building a classifier using a support set
spired by inducing point methods from sparse of images, which is evaluated with query images.
Gaussian process literature. It reduces computa-
tion time of self-attention from quadratic to linear A model for set-input problems should satisfy two critical
in the number of elements in the set. We show requirements. First, it should be permutation invariant —
that our model is theoretically attractive and we the output of the model should not change under any permu-
evaluate it on a range of tasks, demonstrating in- tation of the elements in the input set. Second, such a model
creased performance compared to recent methods should be able to process input sets of any size. While these
for set-structured data. requirements stem from the definition of a set, they are not
easily satisfied in neural-network-based models: classical
feed-forward neural networks violate both requirements,
1. Introduction and RNNs are sensitive to input order.
Recently, Edwards & Storkey (2017) and Zaheer et al.
Learning representations has proven to be an essential prob-
(2017) propose neural network architectures which meet
lem for deep learning and its many success stories. The
both criteria, which we call set pooling methods. In this
majority of problems tackled by deep learning are instance-
model, each element in a set is first independently fed into
based and take the form of mapping a fixed-dimensional
a feed-forward neural network that takes fixed-size inputs.
input tensor to its corresponding target value (Krizhevsky
Resulting feature-space embeddings are then aggregated
et al., 2012; Graves et al., 2013).
using a pooling operation (mean, sum, max or similar).
For some applications, we are required to process set- The final output is obtained by further non-linear processing
structured data. Multiple instance learning (Dietterich et al., of the aggregated embedding. This remarkably simple ar-
1 chitecture satisfies both aforementioned requirements, and
Department of Statistics, University of Oxford, United King-
dom 2 AITRICS, Republic of Korea 3 Kakao Corporation, Repub- more importantly, is proven to be a universal approximator
lic of Korea 4 Department of Computer Science and Engineering, for any set function (Zaheer et al., 2017). Thanks to this
POSTECH, Republic of Korea 5 Oxford Robotics Institute, Univer- property, it is possible to learn a complex mapping between
sity of Oxford, United Kingdom. Correspondence to: Juho Lee input sets and their target outputs in a black-box fashion,
<[Link]@[Link]>. much like with feed-forward or recurrent neural networks.
Proceedings of the 36 th International Conference on Machine Even though this set pooling approach is theoretically at-
Learning, Long Beach, California, PMLR 97, 2019. Copyright tractive, it remains unclear whether we can approximate
2019 by the author(s).
Set Transformer
scheme. Instead of computing a single attention func- neural network blocks with their own parameters, and not
tion, this method first projects Q, K, V onto h different fixed functions.
dMq , dq , dv -dimensional vectors, respectively. An atten-
M M
Given matrices X, Y ∈ Rn×d which represent two sets of
tion function (Att(·; ωj )) is applied to each of these h pro-
d-dimensional vectors, we define the Multihead Attention
jections. The output is a linear transformation of the con-
Block (MAB) with parameters ω as follows:
catenation of all attention outputs:
MAB(X, Y ) = LayerNorm(H + rFF(H)), (6)
Multihead(Q, K, V ; λ, ω) = concat(O1 , · · · , Oh )W O , where H = LayerNorm(X + Multihead(X, Y, Y ; ω)),
(4) (7)
where Oj = Att(QWjQ , KWjK , V WjV ; ωj ) (5) rFF is any row-wise feedforward layer (i.e., it pro-
cesses each instance independently and identically), and
Note that Multihead(·, ·, ·; λ) has learnable parameters LayerNorm is layer normalization (Ba et al., 2016). The
M
λ = {WjQ , WjK , WjV }hj=1 , where WjQ , WjK ∈ Rdq ×dq , MAB is an adaptation of the encoder block of the Trans-
former (Vaswani et al., 2017) without positional encoding
M M
WjV ∈ Rdv ×dv , W O ∈ Rhdv ×d . A typical choice for the
dimension hyperparameters is dM M and dropout. Using the MAB, we define the Set Attention
q = dq /h, dv = dv /h,
d = dq . For brevity, we set dq = dv = d, dM M Block (SAB) as
q = dv = d/h
throughout the rest of the paper. Unless otherwise
√ specified, SAB(X) := MAB(X, X). (8)
we use a scaled softmax ωj (·) = softmax(·/ d), which
our experiments were worked robustly in most settings. 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
3. Set Transformer about pairwise interactions among the elements in the input
In this section, we motivate and describe the Set Trans- set X, we can stack multiple SABs to encode higher order
former: an attention-based neural network that is designed interactions. Note that while the SAB (8) involves a multi-
to process sets of data. Similar to other architectures, a Set head attention operation (7), where Q = K = V = X, it
Transformer consists of an encoder followed by a decoder could reduce to applying a residual block on X. In practice,
(cf. Section 2.1), but a distinguishing feature is that each it learns more complicated functions due to linear projec-
layer in the encoder and decoder attends to their inputs to tions of X inside attention heads, (3) and (5).
produce activations. Additionally, instead of a fixed pooling A potential problem with using SABs for set-structured
operation such as mean, our aggregating function pool(·) data is the quadratic time complexity O(n2 ), which may be
is parameterized and can thus adapt to the problem at hand. too expensive for large sets (n 1). We thus introduce
the Induced Set Attention Block (ISAB), which bypasses
3.1. Permutation Equivariant (Induced) Set Attention this problem. Along with the set X ∈ Rn×d , additionally
Blocks define m d-dimensional vectors I ∈ Rm×d , which we call
inducing points. Inducing points I are part of the ISAB
We begin by defining our attention-based set operations,
itself, and they are trainable parameters which we train
which we call SAB and ISAB. While existing pooling meth-
along with other parameters of the network. An ISAB with
ods for sets obtain instance features independently of other
m inducing points I is defined as:
instances, we use self-attention to concurrently encode the
whole set. This gives the Set Transformer the ability to com- ISABm (X) = MAB(X, H) ∈ Rn×d , (9)
pute pairwise as well as higher-order interactions among m×d
where H = MAB(I, X) ∈ R . (10)
instances during the encoding process. For this purpose,
we adapt the multihead attention mechanism used in Trans- The ISAB first transforms I into H by attending to the
former. We emphasize that all blocks introduced here are input set. The set of transformed inducing points H, which
Set Transformer
contains information about the input set X, is again attended 3.3. Overall Architecture
to by the input set X to finally produce a set of n elements.
Using the ingredients explained above, we describe how we
This is analogous to low-rank projection or autoencoder
would construct a set transformer consists of an encoder and
models, where inputs (X) are first projected onto a low-
a decoder. The encoder Encoder : X 7→ Z ∈ Rn×d is a
dimensional object (H) and then reconstructed to produce
stack of SABs or ISABs, for example:
outputs. The difference is that the goal of these methods is
reconstruction whereas ISAB aims to obtain good features Encoder(X) = SAB(SAB(X)) (13)
for the final task. We expect the learned inducing points
to encode some global structure which helps explain the Encoder(X) = ISABm (ISABm (X)). (14)
inputs X. For example, in the amortized clustering problem
We point out again that the time complexity for ` stacks
on a 2D plane, the inducing points could be appropriately
of SABs and ISABs are O(`n2 ) and O(`nm), respectively.
distributed points on the 2D plane so that the encoder can
This can result in much lower processing times when using
compare elements in the query dataset indirectly through
ISAB (as compared to SAB), while still maintaining high
their proximity to these grid points.
representational power. After the encoder transforms data
Note that in (9) and (10), attention was computed between X ∈ Rn×dx into features Z ∈ Rn×d , the decoder aggre-
a set of size m and a set of size n. Therefore, the time gates them into a single or a set of vectors which is fed into
complexity of ISABm (X; λ) is O(nm) where m is a (typ- a feed-forward network to get final outputs. Note that PMA
ically small) hyperparameter — an improvement over the with k > 1 seed vectors should be followed by SABs to
quadratic complexity of the SAB. We also emphasize that model the correlation between k outputs.
both of our set operations (SAB and ISAB) are permutation
equivariant (definition in Section 2.1): Decoder(Z; λ) = rFF(SAB(PMAk (Z))) ∈ Rk×d (15)
Property 1. Both SAB(X) and ISABm (X) are permuta- where PMAk (Z) = MAB(S, rFF(Z)) ∈ Rk×d , (16)
tion equivariant.
3.4. Analysis
3.2. Pooling by Multihead Attention
Since the blocks used to construct the encoder (i.e., SAB,
A common aggregation scheme in permutation invariant ISAB) are permutation equivariant, the mapping of the en-
networks is a dimension-wise average or maximum of the coder X → Z is permutation equivariant as well. Combined
feature vectors (cf. Section 1). We instead propose to aggre- with the fact that the PMA in the decoder is a permutation
gate features by applying multihead attention on a learnable invariant transformation, we have the following:
set of k seed vectors S ∈ Rk×d . Let Z ∈ Rn×d be the set of
features constructed from an encoder. Pooling by Multihead Proposition 1. The Set Transformer is permutation invari-
Attention (PMA) with k seed vectors is defined as ant.
PMAk (Z) = MAB(S, rFF(Z)). (11) Being able to approximate any function is a desirable prop-
erty, especially for black-box models such as deep neural
Note that the output of PMAk is a set of k items. We use networks. Building on previous results about the universal
one seed vector (k = 1) in most cases, but for problems such approximation of permutation invariant functions, we prove
as amortized clustering which requires k correlated outputs, the universality of Set Transformers:
the natural thing to do is to use k seed vectors. To further
Proposition 2. The Set Transformer is a universal approxi-
model the interactions among the k outputs, we apply an
mator of permutation invariant functions.
SAB afterwards:
H = SAB(PMAk (Z)). (12) Proof. See supplementary material.
We later empirically show that such self-attention after pool-
ing helps in modeling explaining-away (e.g., among clusters 4. Related Works
in an amortized clustering problem).
Pooling architectures for permutation invariant map-
Intuitively, feature aggregation using attention should be pings Pooling architectures for sets have been used in
beneficial because the influence of each instance on the various problems such as 3D shape recognition (Shi et al.,
target is not necessarily equal. For example, consider a 2015; Su et al., 2015), discovering causality (Lopez-Paz
problem where the target value is the maximum value of a et al., 2017), learning the statistics of a set (Edwards &
set of real numbers. Since the target can be recovered using Storkey, 2017), few-shot image classification (Snell et al.,
only a single instance (the largest), finding and attending to 2017), and conditional regression and classification (Gar-
that instance during aggregation will be advantageous. nelo et al., 2018). Zaheer et al. (2017) discuss the structure
Set Transformer
60
0.
55
Accuracy
0.
ISAB(n)+PMA
Figure 2. Counting unique characters: this is a randomly sampled
50
SAB+PMA
0.
set of 20 images from the Omniglot dataset. There are 14 different SAB + Pooling
rFF + PMA
characters inside this set.
45
rFF + Pooling
0.
1 2 3 4 5 6 7 8 9 10 11
Number of Inducing Points (n)
Table 2. Accuracy on the unique character counting task.
In order to test the ability of modelling interactions between The goal is to learn the optimal parameters θ∗ (X) =
objects in a set, we introduce a new task of counting unique arg maxθ log p(X; θ). The typical approach to this prob-
elements in an input set. We use the Omniglot (Lake et al., lem is to run an iterative algorithm such as Expectation-
Maximisation (EM) until convergence. Instead, we aim
2015) dataset, which consists of 1,623 different handwritten to learn a generic meta-algorithm that directly maps the
characters from various alphabets, where each character is input set X to θ∗ (X). One can also view this as amor-
represented by 20 different images. tized maximum likelihood learning. Specifically, given a
dataset X, we train a neural network to output parameters
We split all characters (and corresponding images) into train, f (X; λ) = {π(X), {µj (X), σj (X)}kj=1 } which maximize
validation, and test sets and only train using images from the
train character classes. We generate input sets by sampling |X|
X k
X
between 6 and 10 images and we train the model to predict EX log πj (X)N (xi ; µj (X), diag(σj2 (X))) . (18)
the number of different characters inside the set. We used i=1 j=1
Table 3. Meta clustering results. The number inside parenthesis indicates the number of inducing points used in ISABs of encoders. We
show average likelihood per data for the synthetic dataset and the adjusted rand index (ARI) for the CIFAR-100 experiment. LL1/data,
ARI1 are the evaluation metrics after a single EM update step. The oracle for the synthetic dataset is the log likelihood of the actual
parameters used to generate the set, and the CIFAR oracle was computed by running EM until convergence.
Synthetic CIFAR-100
Architecture LL0/data LL1/data ARI0 ARI1
Oracle -1.4726 0.9150
rFF + Pooling -2.0006 ± 0.0123 -1.6186 ± 0.0042 0.5593 ± 0.0149 0.5693 ± 0.0171
rFFp-mean + Pooling -1.7606 ± 0.0213 -1.5191 ± 0.0026 0.5673 ± 0.0053 0.5798 ± 0.0058
rFFp-max + Pooling -1.7692 ± 0.0130 -1.5103 ± 0.0035 0.5369 ± 0.0154 0.5536 ± 0.0186
rFF + Dotprod -1.8549 ± 0.0128 -1.5621 ± 0.0046 0.5666 ± 0.0221 0.5763 ± 0.0212
SAB + Pooling (ours) -1.6772 ± 0.0066 -1.5070 ± 0.0115 0.5831 ± 0.0341 0.5943 ± 0.0337
ISAB (16) + Pooling (ours) -1.6955 ± 0.0730 -1.4742 ± 0.0158 0.5672 ± 0.0124 0.5805 ± 0.0122
rFF + PMA (ours) -1.6680 ± 0.0040 -1.5409 ± 0.0037 0.7612 ± 0.0237 0.7670 ± 0.0231
SAB + PMA (ours) -1.5145 ± 0.0046 -1.4619 ± 0.0048 0.9015 ± 0.0097 0.9024 ± 0.0097
ISAB (16) + PMA (ours) -1.5009 ± 0.0068 -1.4530 ± 0.0037 0.9210 ± 0.0055 0.9223 ± 0.0056
Figure 4. Clustering results for 10 test datasets, along with centers and covariance matrices. rFF+Pooling (top-left), SAB+Pooling
(top-right), rFF+PMA (bottom-left), Set Transformer (bottom-right). Best viewed magnified in color.
We report the performance of the oracle along with the set- tive processes, network architectures, and training schemes
input neural networks in Table 3. We additionally report along with additional experiments with various numbers of
scores of all models after a single EM update. Overall, inducing points in the supplementary material.
the Set Transformer found accurate parameters and even
outperformed the oracles after a single EM update. This 5.4. Set Anomaly Detection
may be due to the relatively small size of the input sets;
some clusters have fewer than 10 points. In this regime, We evaluate our methods on the task of meta-anomaly de-
sample statistics can differ substantially from population tection within a set using the CelebA dataset. The dataset
statistics, which limits the performance of the oracle while consists of 202,599 images with the total of 40 attributes.
the Set Transformer can adapt accordingly. Notably, the We randomly sample 1,000 sets of images. For every set,
Set Transformer with only 16 inducing points showed the we select two attributes at random and construct the set
best performance, even outperforming the full Set Trans- by selecting seven images containing both attributes and
former. We believe this is due to the knowledge transfer one image with neither. The goal of this task is to find the
and regularization via inducing points, helping the network image that does not belong to the set. We give a detailed
to learn global structures. Our results also imply that the description of the experimental setup in the supplementary
improvement from using the PMA is more significant than material. We report the area under receiver operating char-
that of the SAB, supporting our claim of the importance acteristic curve (AUROC) and area under precision-recall
of attention-based decoders. We provide detailed genera- curve (AUPR) in Table 5. Set Transformers outperformed
all other methods by a significant margin.
Set Transformer
Table 4. Test accuracy for the point cloud classification task using 100, 1000, 5000 points.
Charles, R. Q., Su, H., Kaichun, M., and Guibas, L. J. Point- Lopez-Paz, D., Nishihara, R., Chintala, S., Schölkopf, B.,
Net: Deep learning on point sets for 3D classification and and Bottou, L. Discovering causal signals in images. In
segmentation. In Proceedings of the IEEE Conference on Proceedings of the IEEE Conference on Computer Vision
Computer Vision and Pattern Recognition (CVPR), 2017. and Pattern Recognition (CVPR), 2017.
Dietterich, T. G., Lathrop Richard, H., and Lozano-Pérez, T. Ma, C.-Y., Kadav, A., Melvin, I., Kira, Z., AlRegib, G., and
Solving the multiple instance problem with axis-parallel Peter Graf, H. Attend and interact: higher-order object
rectangles. Artificial intelligence, 89(1-2):31–71, 1997. interactions for video understanding. In Proceedings of
the IEEE Conference on Computer Vision and Pattern
Edwards, H. and Storkey, A. Towards a neural statistician. In Recognition (CVPR), 2018.
Proceedings of the International Conference on Learning
Representations (ICLR), 2017. Maron, O. and Lozano-Pérez, T. A framework for multiple-
instance learning. In Advances in Neural Information
Finn, C., Abbeel, P., and Levine, S. Model-agnostic meta- Processing Systems (NeurIPS), 1998.
learning for fast adaptation of deep networks. In Pro-
ceedings of the International Conference on Machine Mishra, N., Rohaninejad, M., Chen, X., and Abbeel, P.
Learning (ICML), 2017. A simple neural attentive meta-learner. In Proceedings
of the International Conference on Machine Learning
Fowlkes, C., Belongie, S., Chung, F., and Malik, J. Spectral (ICML), 2018.
grouping using the Nyström method. IEEE Transactions
on Pattern Analysis and Machine Intelligence, 25(2):215– Muandet, K., Fukumizu, K., Dinuzzo, F., and Schölkopf,
225, 2004. B. Learning from distributions via support measure ma-
chines. In Advances in Neural Information Processing
Garnelo, M., Rosenbaum, D., Maddison, C. J., Ramalho, Systems (NeurIPS), 2012.
T., Saxton, D., Shanahan, M., Teh, Y. W., Rezende, D. J.,
and Eslami, S. M. A. Conditional neural processes. In Oliva, J., Póczos, B., and Schneider, J. Distribution to dis-
Proceedings of the International Conference on Machine tribution regression. In Proceedings of the International
Learning (ICML), 2018. Conference on Machine Learning (ICML), 2013.
Graves, A., Mohamed, A.-r., and Hinton, G. E. Speech Pritzel, A., Uria, B., Srinivasan, S., Puigdomenech, A.,
recognition with deep recurrent neural networks. In Pro- Vinyals, O., Hassabis, D., Wierstra, D., and Blundell,
ceedings of the IEEE International Conference on Acous- C. Neural episodic control. In Proceedings of the In-
tics, Speech, and Signal Processing (ICASSP), 2013. ternational Conference on Machine Learning (ICML),
2017.
Ilse, M., Tomczak, J. M., and Welling, M. Attention-based
deep multiple instance learning. In Proceedings of the Santoro, A., Raposo, D., Barret, D. G. T., Malinowski, M.,
International Conference on Machine Learning (ICML), Pascanu, R., and Battaglia, P. A simple neural network
2018. module for relational reasoning. In Advances in Neural
Information Processing Systems (NeurIPS), 2017.
Kim, H., Mnih, A., Schwarz, J., Garnelo, M., Eslami, A.,
Rosenbaum, D., Vinyals, O., and Teh, Y. W. Attentive Schmidhuber, J. Evolutionary Principles in Self-Referential
neural processes. In Proceedings of International Confer- Learning. PhD thesis, Technical University of Munich,
ence on Learning Representations, 2019. 1987.
Set Transformer
Juho Lee 1 2 Yoonho Lee 3 Jungtaek Kim 4 Adam R. Kosiorek 1 5 Seungjin Choi 4 Yee Whye Teh 1
1. Proofs
arXiv:1810.00825v3 [[Link]] 26 May 2019
Pn
Lemma 1. The mean operator mean({x1 , . . . , xn }) = 1
n i=1 xi is a special case of dot-product attention with softmax.
Lemma 2. The decoder of a Set Transformer, given enough nodes, can express any element-wise function of the form
Pn p p
1
1
n i=1 zi .
Proof. We first note that we can view the decoder as the composition of functions
We focus on H in (2). Since feed-forward networks are universal function approximators at the limit of infinite nodes, let
1
the feed-forward layers in front and back of the MAB encode the element-wise functions z → z p and z → z 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 (WjQ , WjK , WjV ) 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
n
! p1
1X p
Mp (z1 , · · · , zn ) = z . (3)
n i=1 i
Pn
Lemma 3. A PMA, given enough nodes, can express sum pooling ( i=1 zi ).
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 1. 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.
2. Experiment Details
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. ISABm (d, h) denotes the ISAB with d units, h heads and m inducing points.
PMAk (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.
Encoder Decoder
FF SAB Pooling PMA
FC(64, ReLU) SAB(64, 4) mean, sum, max PMA1 (64, 4)
FC(64, ReLU) SAB(64, 4) FC(64, ReLU) FC(1, −)
FC(64, ReLU) FC(1, −)
FC(64, −)
We show the detailed architectures used for the experiments in Table 1. We trained all networks using the Adam optimizer (?)
with a constant learning rate of 10−3 and a batch size of 128 for 20,000 batches, after which loss converged for all
architectures.
Architecture Accuracy
rFF + Pooling 0.4366 ± 0.0071
rFF + PMA 0.4617 ± 0.0073
rFFp-mean + Pooling 0.4617 ± 0.0076
rFFp-max + Pooling 0.4359 ± 0.0077
rFF + Dotprod 0.4471 ± 0.0076
SAB + Pooling 0.5659 ± 0.0067
SAB + Dotprod 0.5888 ± 0.0072
SAB + PMA (1) 0.6037 ± 0.0072
SAB + PMA (2) 0.5806 ± 0.0075
SAB + PMA (4) 0.5945 ± 0.0072
SAB + PMA (8) 0.6001 ± 0.0078
Encoder Decoder
rFF SAB Pooling PMA
Conv(64, 3, 2, BN, ReLU) Conv(64, 3, 2, BN, ReLU) mean PMA1 (8, 8)
Conv(64, 3, 2, BN, ReLU) Conv(64, 3, 2, BN, ReLU) FC(64, ReLU) FC(1, softplus)
Conv(64, 3, 2, BN, ReLU) Conv(64, 3, 2, BN, ReLU) FC(1, softplus)
Conv(64, 3, 2, BN, ReLU) Conv(64, 3, 2, BN, ReLU)
FC(64, ReLU) SAB(64, 4)
FC(64, ReLU) SAB(64, 4)
FC(64, ReLU)
FC(64, −)
The loss function we optimize, as previously mentioned, 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.
2. Generate k centers.
Table 4 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 50k steps, and decayed the learning rate to 10−4 after 35k steps.
Table 5 summarizes the detailed results with various number of inducing points in the ISAB. Figure ?? shows the actual
clustering results based on the predicted parameters.
Encoder Decoder
rFF SAB ISAB Pooling PMA
FC(128, ReLU) SAB(128, 4) ISABm (128, 4) mean PMA4 (128, 4)
FC(128, ReLU) SAB(128, 4) ISABm (128, 4) FC(128, ReLU) SAB(128, 4)
FC(128, ReLU) FC(128, ReLU) FC(4 · (1 + 2 · 2), −)
FC(128, ReLU) FC(128, ReLU)
FC(4 · (1 + 2 · 2), −)
Table 5. Average log-likelihood/data (LL0/data) and average log-likelihood/data after single EM iteration (LL1/data) the clustering
experiment. The number inside parenthesis indicates the number of inducing points used in the SABs of encoder. For all PMAs, four seed
vectors were used.
Table 6. Average log-likelihood/data (LL0/data) and average log-likelihood/data after single EM iteration (LL1/data) the clustering
experiment on large-scale data. The number inside parenthesis indicates the number of inducing points used in the SABs of encoder. For
all PMAs, six seed vectors were used.
Encoder Decoder
rFF SAB ISAB rFF PMA
FC(256, ReLU) SAB(256, 4) ISABm (256, 4) mean PMA4 (128, 4)
FC(256, ReLU) SAB(256, 4) ISABm (256, 4) FC(256, ReLU) SAB(256, 4)
FC(256, ReLU) SAB(256, 4) ISABm (256, 4) FC(256, ReLU) SAB(256, 4)
FC(256, ReLU) FC(256, ReLU)) FC(4 · (1 + 2 · 512), −)
FC(256, ReLU) FC(256, ReLU)
FC(256, −) FC(256, ReLU)
FC(4 · (1 + 2 · 512), −)
Table 7 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 50k steps, and decayed the learning rate to 10−5 after 35k steps.
Table 8 summarizes the detailed results with various number of inducing points in the ISAB.
3. Additional Experiments
3.1. Runtime of SAB and ISAB
We measured the runtime of SAB and ISAB on a simple benchmark (Figure 1). We used a single GPU (Tesla P40) for this
experiment. The input data was a constant (zero) tensor of n three-dimensional vectors. We report the number of seconds it
Supplementary Material for Set Transformer
Table 8. Average clustering accuracies measured by Adjusted Rand Index (ARI) for CIFAR100 clustering experiments. The number
inside parenthesis indicates the number of inducing points used in the SABs of encoder. For all PMAs, four seed vectors were used.
Table 9. Detailed architectures used in CelebA meta set anomaly experiments. Conv(d, k, s, r, f ) is a convolutional layer with d output
channels, k kernel size, s stride size, r regularization method, and activation function f . If d is a list, each element in the list is distributed.
FC(d, f, r) denotes a fully-connected layer with d units, activation function f and r regularization method. If d is a list, each element in
the list is distributed. SAB(d, h) denotes the SAB with d units and h heads. PMA(d, h, nseed ) denotes the PMA with d units, h heads
and nseed vectors. All MABs used in SAB and PMA uses FC layers with ReLU activations for rFF layers.
Encoder Decoder
rFF SAB Pooling PMA
Conv([32, 64, 128], 3, 2, Dropout, ReLU) mean PMA4 (128, 4)
FC([1024, 512, 256], −, Dropout) FC(128, ReLU, −) SAB(128, 4)
FC(256, −, −) FC(128, ReLU, −) FC(256 · 8, −, −)
FC([128, 128, 128], ReLU, −) SAB(128, 4) FC(128, ReLU, −)
FC([128, 128, 128], ReLU, −) SAB(128, 4) FC(256 · 8, −, −)
FC(128, ReLU, −) SAB(128, 4)
FC(128, −, −) SAB(128, 4)
took to process 10,000 sets of each size. The maximum set size we report for SAB is 2,000 because the computation graph
of bigger sets could not fit on our GPU. The specific attention blocks used are ISAB4 (64, 8) and SAB(64, 8).
Supplementary Material for Set Transformer
Table 10. Detailed architectures used in the point cloud classification experiments.
Encoder Decoder
rFF ISAB Pooling PMA
FC(256, ReLU) ISAB(256, 4) max Dropout(0.5)
FC(256, ReLU) ISAB(256, 4) Dropout(0.5) PMA1 (256, 4)
FC(256, ReLU) FC(256, ReLU) Dropout(0.5)
FC(256, −) Dropout(0.5) FC(40, −)
FC(40, −)
Figure 1. Runtime of a single SAB/ISAB block on dummy data. x axis is the size of the input set and y axis is time (seconds). Note that
the x-axis is log-scale.