arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2601.01754cs.LGcs.CCcs.CLcs.FL
收藏

使用Transformer进行上下文无关语言识别

Context-Free Recognition with Transformers

ETH Zürich(苏黎世联邦理工学院);Boston University(波士顿大学);Allen Institute for AI(人工智能研究院)

Selim Jerad, Anej Svete, Sophie Hao, Ryan Cotterell, William Merrill

AI总结:

本文证明循环Transformer通过O(log N)层和O(N^6)填充符号可识别所有上下文无关语言,并针对无歧义子类将填充需求降至O(N^3)。

摘要:

Transformer在处理符合某种语法的良好形式输入(如自然语言和代码)的任务中表现出色。然而,它们如何处理语法句法仍不清楚。事实上,在标准复杂性猜想下,标准Transformer无法识别上下文无关语言(CFL)——一种描述句法的规范形式,甚至无法识别正则语言(CFL的子类)。过去的工作表明,O(log(N))循环层(相对于输入长度N)允许Transformer识别正则语言,但循环Transformer识别上下文无关语言的问题仍然开放。在这项工作中,我们证明具有O(log(N))循环层和O(N^6)填充符号的循环Transformer可以识别所有CFL。然而,使用O(N^6)填充符号的训练和推理可能不切实际。幸运的是,我们表明,对于无歧义CFL等自然子类,Transformer上的识别问题变得更加易处理,只需要O(N^3)填充。实验上,循环和填充Transformer在识别CFL方面比固定深度Transformer表现更好。总体而言,我们的结果揭示了Transformer识别CFL的复杂性:虽然一般识别可能需要难以处理的填充量,但无歧义性等自然约束产生了高效的识别算法。

英文摘要:

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.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑