Self-Attention Networks Can Process Bounded Hierarchical Languages

Shunyu Yao, Binghui Peng, Christos Papadimitriou, Karthik Narasimhan
5/24/2021
cs.CLcs.AIcs.FL
transformer-attention

Official code: princeton-nlp/dyck-transformer (13 stars, Python, last commit 2021-06-01).

Abstract

Despite their impressive performance in NLP, self-attention networks were recently proved to be limited for processing formal languages with hierarchical structure, such as $\mathsf{Dyck}_k$, the language consisting of well-nested parentheses of $k$ types. This suggested that natural language can be approximated well with models that are too weak for formal languages, or that the role of hierarchy and recursion in natural language might be limited.

Show full abstract

We qualify this implication by proving that self-attention networks can process $\mathsf{Dyck}_{k, D}$, the subset of $\mathsf{Dyck}_{k}$ with depth bounded by $D$, which arguably better captures the bounded hierarchical structure of natural language. Specifically, we construct a hard-attention network with $D+1$ layers and $O(\log k)$ memory size (per token per layer) that recognizes $\mathsf{Dyck}_{k, D}$, and a soft-attention network with two layers and $O(\log k)$ memory size that generates $\mathsf{Dyck}_{k, D}$. Experiments show that self-attention networks trained on $\mathsf{Dyck}_{k, D}$ generalize to longer inputs with near-perfect accuracy, and also verify the theoretical memory advantage of self-attention networks over recurrent networks.

View on arXivView PDF

Code Implementations(1)

[ACL 2021] Self-Attention Networks Can Process Bounded Hierarchical Languages

132PythonMay 17, 20215 years ago
aclacl2021dyckformal-languageregular-language+2 more

Similar Papers

Cite this paper

@article{yao2021selfattention,
  title  = {Self-Attention Networks Can Process Bounded Hierarchical Languages},
  author = {Shunyu Yao and Binghui Peng and Christos Papadimitriou and Karthik Narasimhan},
  year   = {2021},
  eprint = {2105.11115},
  archivePrefix = {arXiv},
  url    = {https://arxiv.org/abs/2105.11115}
}

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/2105.11115.svg)](https://codeofpaper.com/paper/2105.11115)

Discussion