Skip to content

Tabular, time-series, scientific, and geometric deep learning · Sets, point clouds, and geometric learning · SPE006 · Architecture

Set Transformer

Set Transformer learns interactions among unordered elements using attention while maintaining permutation-compatible processing and invariant pooling.

Runs in CodeSplash (Experimental) Component demo, not a trained model CodeSplash's run and the reference's record

In CodeSplash

A CodeSplash method runs this entry in Python and R. Set it up from the method's page. The methods that run it are Experimental.

Do it in CodeSplash Run it on your own data. It's in the Experimental lane in the app.

Availability
Runs in CodeSplash (Experimental)
Code example
Component demo, not a trained model
Who ran it
CodeSplash's run and the reference's record
CodeSplash's run
Verified in Python and R through learn.set_model. The reference's example ran in Python and R here, and they agree.
The reference's record
Python: Ran in the reference's review. The report doesn't record which version of the code ran. R: Reviewed but not run: R wasn't available to the reference's authors.

Purpose

Set Transformer learns interactions among unordered elements using attention while maintaining permutation-compatible processing and invariant pooling. Inducing-point attention can reduce the cost of processing large sets.

Question / hypotheses

The operative question is whether the specified representation, symmetry, likelihood or physical constraint improves held-out behavior for this data domain. This is a learning framework, not a null-hypothesis test; losses, attention weights and predictive confidence are not statistical p-values.

Architecture / computational structure

Self-attention blocks or inducing-point attention blocks produce equivariant element representations; pooling by multihead attention uses learned seed queries to summarize the set into a fixed number of outputs.

Assumptions

Adding arbitrary positional embeddings breaks intended set invariance. Attention cost and expressivity depend on inducing/seed choices; identical or missing elements and varying cardinality need deliberate handling.

Formula / computational definition

PMAk(Z)=MAB(S,rFF⁡(Z))PMA_k(Z)=MAB(S,\operatorname{rFF}(Z)), with learned seed matrix S∈Rk×dS\in R^{k\times d}. Attention depends on QKTQK^T and weighted values; permuting key/value rows together leaves the pooled output invariant.

Parameters and notation

Learned or estimated: Attention projections, feedforward layers, inducing vectors, seed queries and output-head parameters.

Hyperparameters and effects: Number of inducing points and seed outputs, head count, width/depth, dropout and pooling configuration. More inducing points improve interaction capacity while raising memory and compute.

Fitting, fine-tuning, and adaptation

Fit the task loss with correctly masked variable-size sets. For transfer, freeze element blocks and fit seed/output pooling first, then unfreeze gradually with smaller learning rates. If cardinality changes, validate inducing-point sufficiency and padding masks. Monitor source retention after adapting the set representation.

How to use and calibrate

Define the independent evaluation unit before preprocessing: row/entity, whole set/object, molecule/trajectory, input function or chronological forecasting origin. Keep target construction and normalization within permitted training data. Test permutation invariance/equivariance, set-size shift, padded-batch correctness and task performance against Deep Sets. Measure latency as cardinality grows rather than relying only on asymptotic complexity.

Example application

Aggregate a variable number of detected objects to classify a scene without imposing an object order. This is a proposed use case, not a claim of validated performance on supplied real data.

Interpretation / pitfalls

Watch out

Assess model error against domain baselines and the stated assumptions. Component-level mathematical correctness does not establish paper reproduction or scientific validity. Invariance/equivariance checks validate transformation behavior; they do not establish correct physical dynamics or chemical accuracy.

Python and R code examples

Scope: Learned-seed attention pooling invariant to input order; one head only. Use the shared setup. Dependencies: NumPy / base R. Validation: Python executed; R unexecuted.

Full-model route: Python/R: custom attention blocks using PyTorch/native torch. The example demonstrates one learned-seed attention pooling operation and its permutation invariance, not the complete multihead/inducing stack.

Python and R

The reference's own programs, shown as written. A component demo shows one central piece of the method; it doesn't train a full model.

Python

Component demo, not a trained model — Learned-seed attention pooling invariant to input order; one head only. Use the shared setup.

Shared setup for this chapter
import numpy as np
def sm(x):
    x=np.asarray(x); e=np.exp(x-x.max(axis=-1,keepdims=True)); return e/e.sum(axis=-1,keepdims=True)
X=np.array([[1.,0.],[.2,.8],[-.3,.5]])
seed=np.array([[.4,.7]])
def pool(A): return sm(seed@A.T/np.sqrt(2))@A
assert np.allclose(pool(X),pool(X[[2,0,1]]))
print(pool(X))
R

Component demo, not a trained model — Learned-seed attention pooling invariant to input order; one head only. Use the shared setup.

Shared setup for this chapter
sm <- function(x) {
  if(is.null(dim(x))) { e<-exp(x-max(x)); return(e/sum(e)) }
  t(apply(x,1,function(v) { e<-exp(v-max(v)); e/sum(e) }))
}
X<-matrix(c(1,0,.2,.8,-.3,.5),3,byrow=TRUE); seed<-matrix(c(.4,.7),1)
pool<-function(A) sm(seed%*%t(A)/sqrt(2))%*%A
stopifnot(max(abs(pool(X)-pool(X[c(3,1,2),])))<1e-12); print(pool(X))

Sources

From the CodeSplash reference, entry SPE006.