TL;DR
Large Language Models (LLMs) are notoriously sensitive to the order of input options—shuffling the choices in a multiple-choice question can often change the model's answer. This paper introduces Set-Based Prompting, an inference-time technique that modifies attention masks and positional encodings to mathematically guarantee that an LLM treats specific sub-sequences as an unordered set, ensuring perfectly consistent outputs without any fine-tuning.
The Problem: Order Dependency in LLMs
LLMs are fundamentally sequential. Because they are trained to predict the next token based on a specific order of previous tokens, they develop "order dependency." This manifests as a frustrating inconsistency: if you ask a model a multiple-choice question, it might pick "B" when the options are in one order, but "C" if you simply swap them.
This isn't just a quirk; it’s a reliability and fairness nightmare. If an LLM is used to screen job candidates or summarize medical papers, the order in which it reads those inputs shouldn't change its conclusion. Previous solutions usually involved "debiasing" (estimating the model's bias and trying to subtract it) or shuffling inputs multiple times and averaging the results. Both approaches are computationally expensive and offer no hard guarantees.
Methods: Set-Based Prompting
To solve this, the authors propose Set-Based Prompting, a "drop-in" modification to the transformer's internal mechanics at inference time. It relies on two main modifications to how the model processes text:
- Modified Attention Mask: In a standard transformer, every token can "see" every token that came before it (causal attention). The authors change this so that tokens within "parallel" sub-sequences (like different multiple-choice options) are masked from each other. They can see the common prompt and their own text, but they cannot see the other options.
- Modified Positional Encoding: Usually, every token gets a unique, sequentially increasing position ID. In Set-Based Prompting, the authors "reset the clock." The first token of every parallel sub-sequence is given the same position ID.
By combining these two changes, the model's internal math becomes identical regardless of the order in which those sub-sequences are fed into the GPU. The authors provide a formal proof that this makes the attention mechanism strictly permutation-invariant.
Experimental Setup
The researchers evaluated their method across several standard benchmarks to see if this "out-of-distribution" input style would break the models:
- MMLU (Massive Multitask Language Understanding): A diverse set of multiple-choice questions across 57 subjects.
- CommonsenseQA (CSQA): A dataset for commonsense reasoning.
- Financial Phrase Bank: Used to test sentiment analysis in an "in-context learning" setting (providing examples before the task).
- Wikipedia: Used to test long-context information retrieval and summarization.
Key Insights and Results
- Perfect Invariance: As mathematically proven, the variance of the model's output across different input permutations dropped to exactly zero.
- Base Models are Surprisingly Robust: Even though models like Llama 2 or GPT-2 were never trained to see multiple tokens with the same position ID or "parallel" attention masks, they still function remarkably well. The authors hypothesize that the "learned manifold" of these models is flexible enough to handle minor positional shifts.
- Accuracy Stability: On MMLU and CSQA, the accuracy of Set-Based Prompting generally stayed within the range of the "best" and "worst" possible orderings of a standard prompt. While it didn't always beat the "best" ordering, it guaranteed the model wouldn't suffer from the "worst" ordering. In few-shot sentiment classification, it often outperformed the "Worst of 2" baseline.
- The "Sweet Spot" for Long Context: In long-document retrieval, order dependency often causes the "lost in the middle" phenomenon. Parallelizing the documents naturally reduces this dependency and can actually improve retrieval accuracy in some cases.
- Bypassing the Context Window: A fascinating side effect is that because position IDs are reset for parallel blocks, you can technically feed a model more tokens than its trained context window allows, provided no single "path" through the attention mask exceeds the limit.
- Efficiency: Because the attention mask has more zeros (due to parallel masking), the computational complexity is slightly lower than standard attention.
Limitations and Future Work
The primary limitation of Set-Based Prompting is that by preventing options from "seeing" each other, the model loses the ability to perform direct comparisons between them during the encoding phase. This can lead to a slight drop in accuracy compared to a perfectly ordered, optimal sequential prompt. Furthermore, "Instruct" versions of models were found to be more sensitive to these changes than their "Base" counterparts, suggesting fine-tuning makes a model's performance more rigid regarding positional distributions.
The authors suggest that the next logical step is training models with these parallel structures from the start. If a model expects "set-based" inputs during pre-training, it could potentially achieve higher accuracy while maintaining the mathematical guarantee of order-independence. They also envision moving toward a "Graph-Based" input representation, where text isn't just a line, but a complex web of related sets and sequences.
Summary updated