NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

The Locality and Symmetry of Positional Encodings

Lihu Chen, Gael Varoquaux, Fabian M. Suchanek · DOI

TL;DR

This paper investigates the fundamental properties of positional encodings (PEs) in transformer models, identifying "Locality" and "Symmetry" as key to their effectiveness. The authors introduce new probing tasks that reveal a critical weakness in current PEs: their fragility to semantic role swaps, suggesting a need for more robust positional representations.

What Problem Does This Paper Address?

Transformer models, like BERT, rely on positional encodings (PEs) to understand word order, a crucial aspect of language. While PEs significantly boost performance, their precise contribution and underlying mechanisms remain somewhat mysterious. Recent studies have even suggested that some PEs might be surprisingly insensitive to word order. This paper aims to demystify PEs by systematically analyzing their properties and their impact on model performance, particularly in bidirectional models like BERT. They seek to understand why PEs work and where they fall short.

Methods

The authors propose two quantitative metrics, Locality and Symmetry, to analyze PEs.

  • Locality measures how concentrated an attention weight vector is on adjacent positions.
  • Symmetry measures how balanced the attention weights are around a central position.

They then apply these metrics to various PEs, both human-designed and learned, before and after pre-training. To probe the limitations of current PEs, they introduce two novel word-swapping tasks:

  • Constituency Shuffling: Swaps words within a phrase, preserving semantics but altering local word order.
  • Semantic Role Shuffling: Swaps the agent and patient roles in a sentence, fundamentally changing the meaning and global structure.

Datasets

The paper utilizes several standard datasets for evaluation:

  • MR, SUBJ, SST: For sentiment analysis.
  • QNLI, RTE, MNLI: For textual entailment.
  • MRPC, QQP: For paraphrase identification.
  • STS-B, SICK-R: For textual similarity.

The authors also construct new datasets for their word-swapping probes:

  • Shuffle-x SNLI: Based on the SNLI dataset, where phrases of length 'x' (3 to 5) have their internal word order disrupted.
  • Shuffle-SR SNLI: Also based on SNLI, where the semantic roles of agent and patient are swapped.

Key Insights and Ideas

  • Locality and Symmetry are Learned: Pre-training significantly enhances both the locality and symmetry of PEs in BERT-style models, indicating these are learned properties crucial for effective sentence representation.
  • Locality is Key for Syntactic Tasks: Positional encodings are more critical for syntactic tasks (like dependency parsing) that rely on local word order, while contextual encodings are more important for semantic tasks.
  • Symmetry's Hidden Flaw: While symmetry seems beneficial, it implies that forward and backward tokens contribute equally, which is counter-intuitive and can lead to models being misled by semantic role inversions.
  • Fragility to Semantic Role Swaps: Current PEs are robust to local word order changes (constituency shuffling) but are extremely sensitive to global semantic role swaps, highlighting a significant limitation.

Key Results

  • Improved Performance with Good PEs: Language models initialized with PEs exhibiting good locality and symmetry show improved performance on downstream tasks.
  • Locality Correlates with Accuracy: Increasing locality generally leads to better accuracy on sentiment analysis tasks, though perfect locality isn't always necessary.
  • Symmetry Benefits Performance (Up to a Point): Increased symmetry also improves accuracy, but only beyond a certain threshold, and its benefits might be task-dependent.
  • Robustness to Local Swaps: All tested models performed well on constituency shuffling tasks, confirming the benefits of locality and symmetry for local order.
  • Failure on Global Swaps: Most models significantly degraded in performance on semantic role shuffling tasks, demonstrating that local symmetry does not capture global word order well.

Limitations and Future Work

  • Focus on Bidirectional Models: The study primarily focuses on BERT-style bidirectional models and does not extend to decoder-only models (like GPT), where PEs might behave differently.
  • English-Centric: The analysis is limited to English, which has a relatively fixed word order. Other languages with more flexible word orders might reveal different PE behaviors.
  • Handcrafted PE Limitations: The handcrafted PEs used, while simplified, still replicate limitations of current PEs. Future work should aim to address the "electric guitar playing a man on stage" type of semantic ambiguity.
  • Developing Better PEs: The authors hope their findings will inspire the development of more robust and semantically aware positional encodings that can better handle global word order and semantic role changes.

Summary updated

BibTeX
@inproceedings{chen2023locality,
  author = {Lihu Chen and Gael Varoquaux and Fabian M. Suchanek},
  title = {{The Locality and Symmetry of Positional Encodings}},
  booktitle = {Conference on Empirical Methods in Natural Language Processing},
  year = {2023},
  doi = {10.18653/v1/2023.findings-emnlp.955},
}
Figure