In the world of deep learning, sequences are king. From translation to speech recognition, the "sequence-to-sequence" (seq2seq) framework—usually powered by LSTMs—has become the standard tool for mapping one string of data to another. But what happens when your data isn't a sequence? What if you’re dealing with a set of numbers to sort, or a collection of objects in an image?
In their ICLR 2016 paper, Order Matters: Sequence to Sequence for Sets, Oriol Vinyals and his colleagues at Google Brain reveal a fascinating paradox: even when data has no inherent order, the order in which you show it to a neural network matters immensely. They propose a new architecture to handle sets as inputs and a clever training strategy to deal with sets as outputs.
TL;DR
Standard seq2seq models struggle with unordered data (sets) because they force an arbitrary sequence structure. This paper introduces a "Read-Process-Write" architecture that is mathematically invariant to input permutations and demonstrates that searching for an "optimal" ordering during training significantly boosts performance on tasks like sorting and parsing.
What Problem Does This Paper Address?
The seq2seq framework relies on the chain rule to decompose the joint probability of a sequence. This works beautifully for language because words have a natural order. However, many real-world problems involve sets—collections where $\{a, b, c\}$ is identical to $\{c, b, a\}$.
If you try to use a standard LSTM to "read" a set, you have to pick an arbitrary order. If you shuffle that order, the LSTM’s internal state changes, which is theoretically undesirable. Similarly, if the model needs to "write" a set (like predicting a group of objects), there are $n!$ possible valid sequences it could produce. Forcing the model to learn just one arbitrary order—or worse, allowing it to try and learn all of them simultaneously—makes the optimization problem much harder and less statistically efficient.
Methods
The authors propose two main contributions to address these sequence-forcing issues:
1. Handling Input Sets: Read-Process-Write
To make the encoder "set-aware," they replace the standard sequential LSTM with a three-part architecture:
- Read: Each element of the input set is embedded independently into a memory vector using a shared neural network.
- Process: This is the "aha" moment. Instead of reading elements one by one, an LSTM performs $T$ steps of computation using an attention mechanism over the entire memory. Because attention is a weighted sum, it doesn't care about the order of the memory vectors. After $T$ steps, the model has a "thought vector" that is permutation-invariant.
- Write: A standard decoder (like a Pointer Network) takes this thought vector and produces the output sequence.
2. Handling Output Sets: Finding Optimal Orderings
When the target is a set, we don't know which of the $n!$ permutations is easiest for the model to learn. The authors propose a training loss that treats the ordering as a latent variable. During training, the model essentially "searches" for the ordering that maximizes the probability of the data, using a sampling-based approach to keep the computation manageable.
Datasets
The researchers evaluated their approach across several domains:
- Artificial Sorting: Sorting $N$ random floating-point numbers.
- Language Modeling: Using the Penn Treebank (PTB) to see how word order affects perplexity.
- 5-Gram Modeling: A simplified task where 5-word sequences are treated as sets to see if the model can "recover" the natural order.
- Parsing: Constituency parsing, where trees are linearized into sequences.
- Graphical Models: Estimating joint probabilities for "star-like" synthetic graphical models.
Key Insights and Ideas
- The "Order Matters" Paradox: Even in tasks where order shouldn't matter (like sorting points for a convex hull), the authors found that pre-sorting the inputs by angle improved accuracy by up to 10%. The model can learn from any order, but some orders are much easier to optimize than others.
- Computation vs. Memory: The "Process" block allows the model to "think" for $T$ steps before committing to an output. Increasing $T$ consistently improved performance on the sorting task, suggesting that complex sets require more mental "cycles" to represent accurately.
- Optimization over Theory: Theoretically, an LSTM is a universal approximator and should handle any order. In practice, the non-convex nature of neural network training means that a "bad" choice of order acts as a confounding factor that hinders learning.
Key Results
- Sorting: On the hardest sorting task ($N=15$), a standard Pointer Network (Ptr-Net) achieved near 0% accuracy. The Read-Process-Write model with 10 processing steps ($P=10$) and "glimpses" (extra attention) reached 10% accuracy—a massive relative improvement, though it highlights how difficult set-based sorting remains. For $N=10$, accuracy jumped from 8% (Ptr-Net) to 50%.
- Parsing: The choice of how to flatten a tree matters. Using a depth-first traversal yielded an 89.5% F1 score, while a breadth-first traversal dropped significantly to 81.5%.
- Recovering Order: In the 5-gram experiment, the model was given shuffled sets of words. By searching for the optimal order during training, the model successfully recovered the "natural" English order and achieved the same perplexity (225) as a model trained on ordered data.
Limitations and Future Work
- Scalability: Searching over $n!$ permutations is computationally expensive. While the sampling approach helps, it may still struggle with very large sets.
- The $T$ Hyperparameter: The number of processing steps $T$ must be chosen beforehand. Ideally, the model would learn when to stop "processing" and start "writing."
- Complexity of Sorting: Even with the new architecture, sorting 15 numbers is surprisingly difficult for these models compared to classical algorithms, suggesting there is still a gap in how neural networks represent relational logic.
This paper remains a foundational read for anyone working on combinatorial optimization, graph neural networks, or any task where the data doesn't arrive in a neat, chronological line.
Summary updated