Transformers Provably Learn Sparse XOR with Polylogarithmic Parameters
Abstract
Learning sparse parity functions has become a theoretical testbed for studying feature learning in neural networks. However, existing analyses primarily focus on Feed-Forward Neural Networks (FFNNs). Meanwhile, theoretical understanding of Transformers in this setting remains limited, despite their empirical success and structural suitability for discovering sparse support over long sequences. To address this gap, we analyze how a single-layer, two-head Transformer learns the sparse XOR problem. Considering samples , where the label is defined by for some unknown , we prove that, with only trainable parameters, Transformers can successfully discover the relevant features and drive the loss for every input to nearly 0 with one gradient step. This result establishes that Transformers break the fundamental parameter bottleneck inherent to FFNNs for this problem. Furthermore, we empirically show that this rapid feature discovery is uniquely driven by the exact softmax attention, outperforming common substitutes such as linear or component-wise attention. Finally, we provide a theoretical sample complexity bound for learning from finite data, demonstrating the generalization ability of Transformers in this task.
Cite
@article{arxiv.2502.07553,
title = {Transformers Provably Learn Sparse XOR with Polylogarithmic Parameters},
author = {Yaomengxi Han and Debarghya Ghoshdastidar},
journal= {arXiv preprint arXiv:2502.07553},
year = {2026}
}