证明带循环层的Transformer可识别上下文无关语言,关键在合理设计冗余填充。
Context-Free Recognition with Transformers
- 引入循环层与冗余填充,使Transformer能处理语法结构复杂的上下文无关语言
- 通用情况需O(N^6)填充,但无歧义语言只需O(N^3)即可高效识别
- 实验验证循环结构优于固定深度模型,适合研究语言建模与神经语法解析者
Transformers 在遵循语法规则的输入任务(如自然语言、代码)中表现优异,但其对语法结构的处理能力尚不明确。在标准复杂度假设下,标准Transformer无法识别上下文无关语言(CFLs),甚至无法识别正则语言(正则语言是CFL的子集)。已有研究指出,需使用$\\(mathcal{O}(\log(N))$循环层才能让Transformer识别正则语言,但关于循环Transformer能否识别上下文无关语言仍悬而未决。本文证明:带有$\\mathcal{O}(\log(N))$循环层和$\\mathcal{O}(N^6)$填充符号的循环Transformer可识别所有CFLs。然而,如此大规模的填充在训练与推理中可能不切实际。幸运的是,我们发现对于自然子类如无歧义上下文无关语言,识别问题可大幅简化,仅需$\\mathcal{O}(N^3)$填充。实验表明,循环且填充的Transformer在识别CFLs方面优于固定深度模型。整体结果揭示了变压器识别上下文无关语言的复杂性:尽管一般情况需要不可行的填充量,但在无歧义等自然约束下,仍可实现高效识别。
原文摘要 · Abstract (English)
Transformers excel empirically on tasks that process well-formed inputs according to some grammar, such as natural language and code. However, it remains unclear how they can process grammatical syntax. In fact, under standard complexity conjectures, standard transformers cannot recognize context-free languages (CFLs), a canonical formalism to describe syntax, or even regular languages, a subclass of CFLs. Past work has shown that $\mathcal{O}(\log(N))$ looping layers (w.r.t. input length $N$) allow transformers to recognize regular languages, but the question of context-free recognition with looped transformers remained open. In this work, we show that looped transformers with $\mathcal{O}(\log(N))$ looping layers and $\mathcal{O}(N^6)$ padding symbols can recognize all CFLs. However, training and inference with $\mathcal{O}(N^6)$ padding symbols is potentially impractical. Fortunately, we show that, for natural subclasses such as unambiguous CFLs, the recognition problem on transformers becomes more tractable, requiring $\mathcal{O}(N^3)$ padding. Empirically, looped and padded transformers perform better than fixed-depth transformers in recognizing CFLs. Overall, our results shed light on the intricacy of CFL recognition by transformers: while general recognition may require an intractable amount of padding, natural constraints such as unambiguity yield efficient recognition algorithms.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。