Order Matters: Sequence to sequence for sets

Oriol Vinyals, Samy Bengio, Manjunath Kudlur

TL;DR

While sequence-to-sequence (seq2seq) models excel at processing sequential data, they struggle when forced to handle unordered sets. This paper demonstrates that the arbitrary order chosen to feed in or extract data heavily impacts performance, and introduces a novel "Read-Process-Write" architecture for input sets alongside an optimization strategy to discover the best orderings for output sets.

What Problem Does This Paper Address?

Deep learning architectures like LSTMs rely on the sequence-to-sequence framework, using the chain rule to break down the joint probability of data step-by-step. This works beautifully for data with a natural sequence, like text or speech. However, many real-world problems deal with sets—unordered collections of variable sizes (e.g., a set of numbers to sort, or a collection of objects detected in an image).

Forcing a set into an arbitrary sequence introduces artificial structure. If you train a model on randomly ordered sets, it must waste capacity learning to map multiple equivalent permutations to the same output, severely harming statistical efficiency. The authors tackle two fundamental questions:

  1. How do we encode an input set such that the model is invariant to the order of its elements?
  2. How do we train a model to output a set when no natural output order exists?

Methods

1. Handling Input Sets: The Read-Process-Write Model

To process input sets without imposing an artificial sequence, the authors propose a three-part architecture:

Figure 1: The Read-Process-and-Write model.
  • Read: A small neural network embeds each element of the input set $X$ independently into a memory vector $m_i$.
  • Process: An LSTM without sequential inputs or outputs runs for $T$ steps. At each step, it uses a content-based attention mechanism to read from the memory vectors. Because content-based attention is permutation-invariant, shuffling the input elements does not change the final state $q_T^*$.
  • Write: An LSTM pointer network uses the invariant embedding to point back to the input elements one by one to construct the target sequence. The authors also introduce "glimpses"—an extra attention step interleaved between pointer outputs—to boost performance.

2. Handling Output Sets: Finding Optimal Orderings

For output sets, the authors modify the loss function. Instead of forcing the model to match a single predefined target order, they optimize over all possible permutations ($\pi$) to find the ordering that maximizes the log probability:

$$\theta^* = \arg\max_\theta \sum_i \max_{\pi(X_i)} \log p(Y_{\pi(X_i)}|X_i; \theta)$$

To prevent the model from getting stuck in poor local minima early in training, they pretrain the model with a uniform prior over all permutations, and then use efficient ancestral sampling ($O(1)$ complexity) to explore the space of orderings.

Datasets

The authors evaluate their approaches on both synthetic and real-world datasets:

  • Artificial Sorting Dataset: Unordered floating-point numbers between 0 and 1 that the model must return in sorted order.
  • Penn Treebank (PTB): Used for benchmark language modeling (evaluating natural vs. reversed word order) and constituency parsing (mapping sentences to linearized parse trees).
  • Toy Star-like Graphical Models: Synthetic datasets with varying numbers of random variables to test joint probability estimation.
  • 5-Gram Dataset: Extracted text snippets converted into sets by pairing words with their original sequence indices.

Key Insights and Ideas

  • Universal Approximation $\neq$ Easy Optimization: LSTMs are theoretically capable of learning functions regardless of input order. However, because deep learning relies on non-convex optimization, choosing a bad data ordering leads to poor local minima and drastically slower convergence.
  • Linearization Strategy Dictates Performance: In parsing, how you flatten a tree matters. Linearizing a parse tree via depth-first traversal preserves local context much better than breadth-first traversal, making it significantly easier for the network to learn.
Figure 2: Depth first and breadth first linearizations of a parse tree which shows our different setups for output ordering in the parsing task.
  • Dynamic Order Discovery: When trained on fully scrambled 5-grams, the proposed output-loss framework successfully "discovers" the natural, left-to-right language structure because it is the mathematically easiest sequence to model.

Key Results

Sorting Numbers

The Read-Process-Write model significantly outperforms vanilla Pointer Networks (Ptr-Net) on the sorting task as the sequence length $N$ increases.

Table 1: The sorting experiment: out-of-sample sorting accuracy for various problem sizes and processing steps, with or without glimpses. All the reported accuracies are shown after reaching 10000 training iterations, at which point all models had converged but none overfitted. Higher is better.

As shown in Table 1, for a sequence length of $N=10$, a standard Ptr-Net with 1 glimpse achieves only 28% accuracy. By introducing 5 processing steps ($P=5$) in the Read-Process-Write model, accuracy jumps to 57%.

Parsing and Language Modeling

  • Parsing: The depth-first traversal model achieved an 89.5% F1 score, whereas the breadth-first model dropped sharply to 81.5% F1, proving that output ordering choices are critical.
  • 5-Gram Modeling: On the "Hard" task (where training data was uniformly sampled from all $5!$ possible permutations), the model successfully converged to the optimal natural ordering, matching the baseline validation perplexity of 225 (compared to a scrambled baseline perplexity of 280).

Limitations and Future Work

While ancestral sampling reduces the search complexity over output permutations to $O(1)$ evaluations, the underlying optimization space remains highly non-convex. For very large output sets, finding the absolute optimal ordering remains a difficult search problem. The authors note that applying this framework to more complex, high-dimensional real-world output sets (such as object detection bounding boxes in computer vision) is an open avenue for future research.

Summary updated

BibTeX
@inproceedings{vinyals2016order,
  author = {Oriol Vinyals and Samy Bengio and Manjunath Kudlur},
  title = {{Order Matters: Sequence to sequence for sets}},
  booktitle = {International Conference on Learning Representations},
  year = {2016},
  url = {http://arxiv.org/abs/1511.06391},
}
Figure