Self-Attention Networks Can Process Bounded Hierarchical Languages

  • 2023-03-13 02:47:55
  • Shunyu Yao, Binghui Peng, Christos Papadimitriou, Karthik Narasimhan
  • 0


Despite their impressive performance in NLP, self-attention networks wererecently proved to be limited for processing formal languages with hierarchicalstructure, such as $\mathsf{Dyck}_k$, the language consisting of well-nestedparentheses of $k$ types. This suggested that natural language can beapproximated well with models that are too weak for formal languages, or thatthe role of hierarchy and recursion in natural language might be limited. Wequalify 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 ofnatural 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 showthat self-attention networks trained on $\mathsf{Dyck}_{k, D}$ generalize tolonger inputs with near-perfect accuracy, and also verify the theoreticalmemory advantage of self-attention networks over recurrent networks.


Quick Read (beta)

loading the full paper ...