Order Matters: Sequence to Sequence for Sets

How input and output ordering affects seq2seq learning on set-structured data

Updated

Contents
  1. Why Students Should Care
  2. The Problem, in Plain English
  3. Input Order Sensitivity
  4. Interactive Demo
  5. Solution: Read-Process-Write
  6. 1. Read
  7. 2. Process
  8. 3. Write
  9. Output Order Learning
  10. Key Results
  11. Sorting
  12. Convex Hull
  13. Implications
  14. Connection to Transformers
  15. Common Confusion
  16. Where To Go Next
  17. Key Paper

Order Matters: Sequence to Sequence for Sets asks a deceptively simple question: sequence models require you to feed elements in some order — so what happens when the data is really a set, with no natural order at all? The answer: the order you pick genuinely changes what the model learns, and there are architectures that fix this.

This page builds on Seq2Seq and Pointer Networks. Read those first if the terms “encoder-decoder” or “pointer” are new.

Why Students Should Care

  • Lots of real data is set-shaped — point clouds, tags, detected objects — and pretending sets are sequences quietly hurts your model.
  • The paper’s fix, attention-based order-invariant processing, is an early blueprint for what Transformers later made standard.
  • It teaches a subtle general lesson: choices that look like formatting details (how you order your data) are actually part of your model design.

The Problem, in Plain English

An LSTM reads its input one element at a time, so something has to come first. But if your input is the set of points A, B, and C, feeding “A, B, C” versus “C, A, B” should not change the answer — the set is the same. In practice, it does change the answer, because the model’s hidden state depends on the order it read things.

Standard seq2seq models assume ordered sequences. But many tasks involve sets:

  • Input sets: Point clouds, object collections
  • Output sets: Predicted tags, detected objects
  • Both: Sorting (input set → output sequence)

Naively treating sets as sequences introduces spurious ordering dependencies — the model wastes capacity learning to cope with orderings that never should have mattered.

Input Order Sensitivity

Experiment: sort numbers using seq2seq. The same set, presented in different orders, can succeed or fail:

Input OrderOutput
[3, 1, 4, 2][1, 2, 3, 4] ✓
[1, 2, 3, 4][1, 2, 3, 4] ✓
[4, 3, 2, 1][1, 2, 3, ?] ✗

Different input orderings can lead to different (wrong) outputs — even though logically the task is identical.

Interactive Demo

Explore how input order affects set processing:

Order Matters

Input: Unordered set (order shouldn't matter)
5
1
3
4
6
1
9
2
Same set, different order → model should give same output
Read-Process-Write
Read: Embed all inputs. Process: Attention over set. Write: Generate sequence.
Permutation Invariance
Use attention to aggregate—order of input doesn't affect representation.
Applications
• Sorting: Input set → sorted sequence
• Convex hull: Points → ordered hull vertices
• Sentence ordering: Shuffled sentences → coherent paragraph

Solution: Read-Process-Write

The paper proposes a three-phase architecture. The trick: replace “read the elements in order” with “look at all elements through attention”, which is order-invariant by construction.

1. Read

Embed all input elements independently (no order involved yet):

{e1,e2,...,en}=Embed(x1,x2,...,xn)\{e_1, e_2, ..., e_n\} = \text{Embed}(x_1, x_2, ..., x_n)

2. Process

An LSTM repeatedly attends over the whole set instead of consuming elements one by one:

qt=LSTM(qt1)q_t = \text{LSTM}(q_{t-1}) αi=softmax(eiqt)\alpha_i = \text{softmax}(e_i \cdot q_t) rt=iαieir_t = \sum_i \alpha_i e_i

The weighted sum rtr_t is the same no matter how you shuffle the elements — that is where the order-invariance comes from. Multiple processing steps refine the representation.

3. Write

Generate the output sequence with a pointer network, selecting input elements one at a time:

p(yiy<i,M)=Attention(si,M)p(y_i | y_{<i}, M) = \text{Attention}(s_i, M)

Output Order Learning

Some tasks have output sets too — the correct answer is a collection, but the model must emit it in some order. Which order should the training data use? The paper’s answer: let the model search for the ordering that is easiest to learn:

L=minπSnilogp(yπ(i)yπ(<i))\mathcal{L} = \min_{\pi \in S_n} \sum_i -\log p(y_{\pi(i)} | y_{\pi(<i)})

In words: among all permutations of the target output, train against the one the model currently finds most probable.

Key Results

Sorting

ModelAccuracy
Seq2seq72%
Seq2seq + Attention87%
Read-Process-Write94%

Convex Hull

Sorting input points by angle dramatically improved performance — demonstrating that “natural” orderings help learning even when the task is order-free in principle.

Implications

  1. Order is a hyperparameter: Choice of ordering affects learning
  2. Attention enables invariance: Attention over sets removes order dependence
  3. Output order matters: Some orderings are easier to learn than others

Connection to Transformers

The Read-Process-Write architecture anticipated:

  • Set attention (now standard in Transformers)
  • Iterative refinement (multiple attention layers)
  • Permutation invariance (via attention aggregation)

A Transformer encoder without positional encodings is essentially a permutation-invariant set processor — the same core insight, scaled up.

Common Confusion

  • “Order matters” — for what? The title means input/output element ordering affects seq2seq training. It is not about word order in language.
  • Set vs. sequence: a sequence has meaningful positions (“first”, “second”); a set does not. The bug this paper diagnoses is feeding sets into models that assume positions mean something.
  • Order Matters vs. Pointer Networks: Pointer Networks (same lead author) give models an input-sized output vocabulary; this paper studies ordering effects and uses a pointer network as its Write phase.
  • Invariance from attention vs. from sorting: the paper offers two remedies — an architecture that ignores order (attention), and picking a good canonical order (e.g., sort by angle). Both work; they are different strategies.

Where To Go Next

Key Paper

Found an error or want to contribute? Edit this page on GitHub

↑↓ to navigate ↵ to open esc to close