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 proves that $\mathcal{O}(\log(n))$ looping layers (w.r.t. input length n) allows transformers to recognize regular languages, but the question of context-free recognition remained open. In this work, we show that looped transformers with $\mathcal{O}(\log(n))$ looping layers and $\mathcal{O}(n^6)$ padding tokens can recognize all CFLs. However, training and inference with $\mathcal{O}(n^6)$ padding tokens 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. We empirically validate our results and show that looping helps on a language that provably requires logarithmic depth. 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.


翻译:Transformer模型在处理符合特定语法结构的输入(如自然语言和代码)任务中展现出卓越的实证性能。然而,其处理语法结构的具体机制尚不明确。事实上,在标准计算复杂性假设下,标准Transformer模型无法识别描述语法结构的经典形式化模型——上下文无关语言,甚至无法识别其子类正则语言。已有研究证明,通过引入$\mathcal{O}(\log(n))$层循环结构(相对于输入长度n),Transformer能够识别正则语言,但上下文无关语言的识别问题仍未解决。本研究证明,具有$\mathcal{O}(\log(n))$层循环结构和$\mathcal{O}(n^6)$个填充标记的循环Transformer能够识别所有上下文无关语言。然而,使用$\mathcal{O}(n^6)$个填充标记进行训练和推理可能缺乏实际可行性。值得庆幸的是,我们发现对于自然子类(如无歧义上下文无关语言),Transformer的识别问题变得更为可行,仅需$\mathcal{O}(n^3)$个填充标记。我们通过实验验证了理论结果,并证明循环结构在处理可证明需要对数深度的语言任务中具有积极作用。总体而言,我们的研究揭示了Transformer识别上下文无关语言的复杂性:虽然通用识别可能需要不可行的填充标记数量,但通过引入无歧义性等自然约束条件,可以获得高效的识别算法。

0
下载
关闭预览

相关内容

Transformer的无限之路:位置编码视角下的长度外推综述
专知会员服务
44+阅读 · 2024年1月17日
【ICML2022】Transformer是元强化学习器
专知会员服务
56+阅读 · 2022年6月15日
【Google】高效Transformer综述,Efficient Transformers: A Survey
专知会员服务
66+阅读 · 2022年3月17日
Transformer文本分类代码
专知会员服务
118+阅读 · 2020年2月3日
【Tutorial】计算机视觉中的Transformer,98页ppt
专知
21+阅读 · 2021年10月25日
基于句子嵌入的无监督文本摘要(附代码实现)
百闻不如一码!手把手教你用Python搭一个Transformer
大数据文摘
18+阅读 · 2019年4月22日
BERT大火却不懂Transformer?读这一篇就够了
大数据文摘
12+阅读 · 2019年1月8日
国家自然科学基金
2+阅读 · 2017年12月31日
国家自然科学基金
1+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
5+阅读 · 2015年12月31日
国家自然科学基金
1+阅读 · 2015年12月31日
国家自然科学基金
1+阅读 · 2015年12月31日
国家自然科学基金
3+阅读 · 2014年12月31日
国家自然科学基金
0+阅读 · 2014年12月31日
国家自然科学基金
0+阅读 · 2014年12月31日
Arxiv
0+阅读 · 2月10日
Arxiv
0+阅读 · 2月5日
VIP会员
相关基金
国家自然科学基金
2+阅读 · 2017年12月31日
国家自然科学基金
1+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
5+阅读 · 2015年12月31日
国家自然科学基金
1+阅读 · 2015年12月31日
国家自然科学基金
1+阅读 · 2015年12月31日
国家自然科学基金
3+阅读 · 2014年12月31日
国家自然科学基金
0+阅读 · 2014年12月31日
国家自然科学基金
0+阅读 · 2014年12月31日
Top
微信扫码咨询专知VIP会员