Introduction
Large Language Models (LLMs) are inherently sequential, relying on positional encodings to interpret the order of tokens. While effective for standard text, this reliance introduces two critical limitations: positional bias and context window constraints. Positional bias occurs when models favor certain options in a list (e.g., the first or last) regardless of content. Context window limits arise because models struggle with positional IDs beyond their training range, leading to performance collapse on long inputs.
The Set Encoding Mechanism
To address these issues, researchers have proposed Set Encoding, a method that treats a collection of items as an unordered set rather than a sequence. This is achieved through two primary modifications to the Transformer architecture during inference:
- Positional Overloading: Instead of incrementing positional IDs linearly, all elements within a designated "set" are assigned the same starting positional ID. This effectively "stacks" the items in the same positional slot from the model's perspective.
- Attention Masking: To prevent interference between these overlapping items, the causal attention mask is modified. While tokens within a set item can attend to preceding "Pre-Set" tokens, and subsequent "Post-Set" tokens can attend to everything, items within the set are prohibited from attending to one another.
This dual approach ensures that the model processes each set item independently, making the final representation invariant to the order in which items are presented.
Experimental Evaluation
The efficacy of Set Encoding was tested across several benchmarks, including MMLU (for bias), RULER (for long-context retrieval), and HotpotQA (for multi-hop reasoning). The study utilized popular open-weight models such as Llama2, Llama3, Falcon, and Mistral.
Key Results
- Bias Elimination: Set Encoding virtually eliminates positional bias. Even when models were intentionally fine-tuned on biased data, the Set Encoding mechanism prevented them from exhibiting positional preferences, as all options occupied the same mathematical "position."
- Context Extension: The method significantly extends effective context windows without retraining. For instance, Llama3-8B’s functional context was extended from its native 8k tokens to 128k tokens. In multi-hop reasoning tasks (HotpotQA) at 16k tokens, a fine-tuned Llama3 using Set Encoding maintained 36% accuracy, while the standard model failed completely.
Discussion and Limitations
Set Encoding demonstrates that LLMs are surprisingly robust to "positional collisions," capable of processing overlapping sequences without specialized training. However, the method introduces trade-offs. Because set items cannot "see" each other, the model loses the ability to perform cross-item comparisons or global operations, such as counting the total number of items in a set. Furthermore, while the aggregate context can be vast, each individual item within the set must still fit within the model's original training window.
Currently, Set Encoding requires internal modifications to the attention mechanism, limiting its application to open-source models where inference logic can be customized. Future work may explore hybrid attention masks to restore inter-item communication for comparative tasks.
Summary updated