“注意力”是智能的本质吗?

内容来源:https://www.quantamagazine.org/is-attention-the-essence-of-intelligence-20261012/
内容总结:
“注意力”是智能的本质吗?
2022年ChatGPT发布后席卷全球的一切——所谓的“AI经济”、数据中心、充当挚友和医生及数学家的聊天机器人、关于生存风险的讨论——从某种意义上说,都始于蒙特利尔大学实验室里一位名叫德米特里·巴赫达瑙的实习生。
那是2014年。这位23岁的白俄罗斯人从小参加编程竞赛,但此前没有做过学术研究,他被要求帮助研究如何让计算机将英语句子翻译成法语。巴赫达瑙当时在研究人工神经网络,这种网络在破译手写文字和识别照片中的物体等模式识别任务中已经展现出潜力。神经网络通过根据训练数据增强和削弱节点之间的连接来学习识别模式。巴赫达瑙私下怀疑它们能否达到人类水平的智能,但他的导师、计算机科学家约书亚·本吉奥和项目博士后赵京焕都是信徒。而翻译被广泛视为神经网络尝试解决的重大而有趣的问题。
翻译并不像把每个英语单词换成法语单词那么简单。不同语言的语法结构不同,而且充满习语和内涵,这些长期以来一直阻碍着自动化的尝试。你不能简单地实施翻译规则,因为根本不存在这样的规则。但神经网络似乎很有前景,因为它们通过示例学习。它们可以在大量英法配对句子的数据库上训练,最终吸收那些准规则、例外和微妙之处。
然而结果一直平平;句子越长,神经网络的表现越差。这是因为研究人员试图在解码目标语言句子之前,将每个句子的数据塞进固定大小的记忆中。这个瓶颈限制了翻译的复杂程度。网络架构根本不对。
于是巴赫达瑙尝试了不同的方法。“这显然是正确的做法——科学中偶尔会发生这样的事,对于一个在该领域经验不多的人来说,事情就是非常清楚,”他在蒙特利尔接受我采访时回忆道,他至今仍在那里从事AI工作。“而且它就这么奏效了。从第一次尝试就成功了。”
巴赫达瑙的技巧——一种他、赵京焕和本吉奥称为“注意力”的数学运算——使他们的神经网络翻译长句的效果与短句一样好。这意味着该方法可以规模化。当时其他AI研究人员迅速将注意力机制整合到他们的神经网络设计中。然后,2017年,谷歌的一个团队设计了一种新型神经网络架构,称为“变换器”,它强化了注意力方法并剥离了其他一切。该团队的论文《注意力就是你所需的一切》报告称,变换器在翻译方面达到了最先进的水平,同时所需的计算量仅为训练先前模型的一小部分。这篇论文此后被引用超过25万次,是AI领域的分水岭时刻。ChatGPT和Claude等大型语言模型随之而来。
鉴于已经被释放的惊人力量,值得追问的是:这个注意力机制究竟是什么,为什么它“就是你所需的一切”,以及为什么机器翻译是解锁这一切的任务。注意力是我们理解单个AI模型如何与我们对话、诊断疾病、生成逼真视频、解决长期存在的数学问题等的一种方式。它在某种程度上是智能的核心吗——无论是人工的还是其他的?
包含“it”等代词的句子说明了注意力所克服的挑战。考虑:“The animal didn‘t cross the street because it was too tired.”以及:“The animal didn’t cross the street because it was too wide.”要将这些句子正确翻译成法语,AI模型必须确定:在第一句中,“it”指的是动物,而动物在法语中是阳性词,因此翻译应使用阳性代词il。但在第二句中,“it”指的是街道,街道是阴性词,需要不同的代词elle。机器如何弄清楚这一点?
巴赫达瑙记得在学校学英语时做翻译练习。要写出翻译句子的下一个词,他必须环顾源文本以确定接下来应该是什么。“字面上就是源句子在左边,你的书写在右边,你会这样左右转头,左-右,左-右,”他说。“这个过程就是我所表达的神经机制。”他赋予神经网络的注意力工具是一种数学方式,让网络能够识别句子中任何位置最能提示翻译下一个词的单词。对于我们的歧义代词“it”,系统在句子其余部分中导航,以确定哪些词对其含义影响最大。
变换器由许多层节点组成,节点与相邻层的节点相连。当句子被输入变换器时,每个词首先被转换为称为向量的数值表示,我们可以将其想象为指向某个方向的箭头。这些向量通过网络传递,称为权重的数字(由模型的训练决定)决定了它们在每一层中如何被变换。权重将每个词当前的向量表示转换为该词特有的三个新向量——“查询”、“键”和“值”——每个在注意力操作中服务于不同的目的。
网络通过称为注意力头的系统并行执行此操作多次。一个注意力头将每个词的查询与句子中所有其他词的键进行比较。这些向量的匹配程度——它们在多大程度上指向同一方向——决定了其他每个词的值对当前词的新更新向量的贡献强度。句子中其他词的信息实际上被融入了每个词的表示中。系统正在将上下文转换为数学。
当“The animal didn‘t cross the street because it was too tired”进入变换器时,网络中被称为编码器的第一叠层使用注意力操作来建立对句子的上下文理解。在每一层中,每个注意力头为“it”生成一个查询(以及一个键和值)。这个查询向量可以被视为对句子中其他地方存在的信息的请求。例如,在深层(网络已经积累了关于词的信息之后),对“it”的查询可能可以被解释为:“我需要一个较早出现的名词,它可能是那个疲倦的东西。”与此同时,与“animal”相关的键可能有效地将自己宣传为一个能够疲倦的名词,以及许多其他特征。因此它的键比“street”的键更好地匹配查询。这导致与“animal”相关的值对“it”的更新表示贡献更大。
“it”的这个新的、上下文丰富的表示进入下一层。在那里,网络再次执行注意力。连续的轮次给词越来越丰富的自身表示。
专家表示,通常很难解释任何给定注意力头在做什么,但它们集体捕捉到许多种关系,从名词和动词之间的搭配到生物与感受之间的关联。后面的层建立在前面层建立的关联之上,因此当句子从编码器出来时,“it”被赋予了某种类似含义的东西。
之后,变换器的第二部分——解码器——一次一个词地生成法语翻译,在决定下一个输出哪个法语词时,使用注意力来调用编码器对英语词的数值表示。英语句子中编码的上下文信息有助于将“it”翻译为阳性代词il。
至关重要的是,没有人需要告诉变换器动物会疲倦、街道可能很宽。神经网络在训练过程中通过从大量英法配对句子中学习来发现这些关联。这些关联被构建到权重中。网络开始时具有随机权重,产生无用的查询、键和值,因此翻译质量很差。但每个翻译错误都会通过网络向后发送一个校正信号,轻微改变产生该错误的权重。通过数万亿次这样的调整,网络最终生成有用的向量,产生正确的翻译,即使它处理的是从未见过的句子。
注意力被证明是连接词语和构建上下文——翻译的基础——的正确数学运算。当你能够翻译无限大小的文本块时,似乎你就能做任何事情。
一个已经学会足够多语言知识来将英语句子翻译成法语的神经网络,也能用任何一种语言完成句子。预测翻译的下一个词,换句话说,是更一般的“预测下一个词”任务的一个子任务。而这正是大型语言模型所做的。它们在整个互联网的内容上训练,学习在各种上下文中哪些词应该关注哪些其他词。它们处理和重新处理整个数据集,并尝试数万亿次预测训练期间它们碰巧所在的网络任何部分的下一个词。这些模型中神经元之间的连接逐渐被调整,产生越来越有用的词间注意力模式,用于预测任何上下文中的下一个词——或对人类提示产生适当的回应。
从翻译“it”这个词的能力,我们不知怎么就得到了一场革命。
“这是一个相当大的飞跃,不是吗?”《注意力就是你所需的一切》的作者之一利昂·琼斯说,他现在是Sakana AI的首席技术官。
琼斯和其他人怀疑,预测下一个词——即所谓的语言建模——是“AI完备”的:一个如此困难的任务,以至于解决它意味着你可以说已经解决了AI整体。它可能是AI完备的原因在于,这个任务包含了几乎人类以书面形式所做的一切作为子任务。“互联网上有翻译,”琼斯指出。“所以如果我说‘The animal didn’t cross the street because it was too tired’的法语是[空白],’那么为了完成这个句子,变换器需要能够翻译成法语。如果我说‘2 + 3是[空白],’它需要做算术。如果它看到一排数学符号并想知道接下来是什么,它需要理解高等数学。如果我说‘美国总统是[空白],’它需要知道事实。所以能够预测下一个词要求你能够做所有这些事情。而且因为它是AI完备的,语言建模在某种程度上是我们对智能最接近的定义。”
说大型语言模型“知道”或“理解”任何事情可能并不恰当——不是以人类的方式——但这只是我们习惯用来谈论它们所展示的能力的方式。无论如何,注意力是人工神经网络获取和传达意义、关联和上下文的工具,通常足以以其流畅性让我们惊叹。(对于高等数学等任务,当今前沿AI模型通常在其语言建模之上叠加更明确的形式推理和证明验证系统来检查其工作。)
但人类智能呢?我们的大脑是否会采用类似于巴赫达瑙发明的数学运算的机制?毕竟,我们在说话、写作甚至思考时,也在做类似于“产生最佳可能的下一个词”的事情。也许我们的智能形式也等同于语言建模?
认知科学家已经开始研究这个问题——这是关于语言与思维关系的古老问题的新版本。可以肯定的是,大型语言模型的成功表明,仅语言的统计模式中就编码了关于世界的大量信息。问题是:当我们掌握语言时,智能是否就免费到来了?
最近的研究使我确信,人类思维并非纯粹是语言的(而且大多数其他动物的智能根本不是语言的):当我们思考时,亮起的大脑区域不仅仅是大脑皮层中与语言相关的专门网络。语言是我们交流世界的方式,但我们的思想似乎借助感官印象、身体和社会经验、记忆以及推理能力,这些至少部分存在于大脑语言网络之外。因此,语言建模似乎只是人类认知的一个强大组成部分,而不是其等价物或来源。
至于我们如何做到“它”——我如何瞬间理解疲倦的是动物而不是街道——还没有人知道。琼斯本人现在认为,注意力并不是真正掌握语言建模所需的全部。毕竟,大脑显然比变换器更高效地完成这项任务。我们流利地对话,甚至没有读过一遍整个互联网,也没有消耗那么多能量。“当前的范式不会解决这个[效率]问题,”琼斯说。“你似乎必须跳到某种非常非常不同的东西。”
无论我们自己的神经机制可能是什么,事后看来,解决翻译解锁了AI是有道理的。无论你是人类还是机器,有效翻译的能力意味着你在某种意义上已经理解了。现在机器理解得如此之多——至少实际上是如此——以至于我们几乎不知道该怎么想了。
中文翻译:
“注意力”是智能的本质吗?
引言
自2022年ChatGPT发布以来,席卷世界的一切——“人工智能经济”、数据中心、充当挚友、医生和数学家的聊天机器人、关于生存风险的讨论——从某种意义上说,这一切都始于蒙特利尔大学实验室里一位名叫德米特里·巴达瑙的实习生。
那是2014年。这位23岁的白俄罗斯人从小就在编程竞赛中摸爬滚打,但从未做过学术研究。他被要求帮忙想办法让计算机把英文句子翻译成法文。巴达瑙当时研究的是人工神经网络,这种网络已经在手写识别和照片物体辨识等模式识别任务中展现出潜力。网络通过根据训练数据增强或减弱节点之间的连接来学习识别模式。巴达瑙私下怀疑它们能否实现接近人类水平的智能,但他的导师、计算机科学家约书亚·本吉奥以及项目博士后赵京焕都是坚定的信徒。而翻译被普遍认为是神经网络可以尝试解决的重大而有趣的问题。
翻译并不像把每个英文单词换成对应的法文单词那么简单。不同语言的语法结构各异,而且充斥着习语和言外之意,这些长期以来一直阻碍着自动翻译的尝试。你无法简单地实施翻译规则,因为根本不存在这样的规则。但神经网络似乎大有希望,因为它们通过实例来学习。它们可以在庞大的英法对照句库上训练,最终吸收那些准规则、例外和微妙之处。
然而结果一直平平;句子越长,神经网络的表现越差。这是因为研究人员试图在解码目标语言句子之前,把每个句子的数据塞进固定大小的记忆中。这个瓶颈限制了翻译的复杂度和精细度。网络架构就是不对。
于是巴达瑙尝试了不同的做法。“这显然是正确的事——科学中偶尔会出现这种情况,一个在该领域经验并不丰富的人却看得非常清楚,”他在蒙特利尔接受我采访时回忆道,他至今仍在那里从事人工智能工作。“而且它就这么奏效了。从第一次尝试就成功了。”
巴达瑙的技巧——一种他、赵京焕和本吉奥称之为“注意力”的数学运算——使他们的神经网络翻译长句的效果与短句一样好。这意味着这种方法可以规模化。当时其他人工智能研究人员迅速将注意力机制整合到他们的神经网络设计中。然后,2017年,谷歌的一个团队设计了一种新型神经网络架构,称为“Transformer”,它强化了注意力方法并剥离了其他一切。该团队的论文《注意力就是你所需要的一切》报告称,Transformer在翻译上达到了最先进的水平,同时所需的计算量仅为训练先前模型的一小部分。这篇论文此后被引用超过25万次,是人工智能领域的分水岭时刻。ChatGPT和Claude等大语言模型随之而来。
鉴于已经被释放出的惊人力量,值得追问的是:这个注意力机制到底是什么,为什么它“就是你所需要的一切”,以及为什么机器翻译是解锁这一切的任务。注意力是我们理解单个AI模型如何能与我们对话、诊断疾病、生成逼真视频、解决长期数学难题等的途径。它在某种程度上是智能的核心吗——无论是人工的还是其他的?
包含“它”这类代词的句子说明了注意力所克服的挑战。试看:“那只动物没有过马路,因为它太累了。”以及:“那只动物没有过马路,因为它太宽了。”要把这些句子正确翻译成法文,AI模型必须判断出:在第一句中,“它”指的是那只动物,而法语中动物是阳性词,所以翻译应使用阳性代词il。但在第二句中,“它”指的是马路,法语中马路是阴性词,需要不同的代词elle。机器如何能弄清这一点?
巴达瑙记得在学校学英语时做翻译练习的情景。要写出译句中每一个下一个词,他必须环顾源文本四周来判断接下来该写什么。“真的是源句在左边,你的译文在右边,你就得这样,头转来转去,左—右,左—右,”他说。“那个过程就是我用神经机制所表达的东西。”他赋予神经网络的注意力工具,是一种数学方式,让网络能够识别句子中任何位置最能决定翻译中下一个词的那个或那些词。对于有歧义的代词“它”,系统会在句子其余部分中搜索,确定哪些词对它的含义影响最大。
一个Transformer由许多层节点组成,层与相邻层的节点相连。当一个句子被输入Transformer时,每个词首先被转换成一个称为向量的数值表示,我们可以把它想象成指向某个方向的箭头。这些向量通过网络传递,称为权重(由模型的训练决定)的数值决定着它们在每一层如何被变换。权重把每个词当前的向量表示转换成三个特定于该词的新向量——“查询”、“键”和“值”——它们在注意力运算中各有不同用途。
网络通过称为“注意力头”的系统并行执行这个运算多次。一个注意力头将每个词的查询与句子中所有其他词的键进行比较。这些向量的匹配程度——它们在多大程度上指向同一方向——决定了其他每个词的值对当前词的新更新向量的贡献有多大。句子中其他词的信息实际上被融入了每个词的表示中。系统正在把上下文转化为数学。
当“那只动物没有过马路,因为它太累了”进入一个Transformer时,网络中的第一组层——称为编码器——使用注意力运算来建立对句子的语境理解。在每一层中,每个注意力头为“它”生成一个查询(以及一个键和一个值)。这个查询向量可以被理解为对句子中其他地方存在的信息的请求。例如,在一个深层(在网络已经积累了关于各词的信息之后),“它”的查询可能可以被解读为:“我需要一个更早出现的名词,它有可能就是那个累的东西。”与此同时,“动物”对应的键可能会有效地标榜自己是一个能够感到累的名词,以及其他许多特征。因此它的键比“马路”的键更匹配这个查询。这就使得“动物”对应的值对“它”的更新表示贡献更大。
“它”的这个新的、语境丰富的表示进入下一层。在那里,网络再次执行注意力运算。一轮又一轮赋予每个词越来越丰富的自身表示。
专家们说,通常很难解读某个特定注意力头在做什么,但总体来说,它们能捕捉到多种关系,从名词与动词之间的搭配到生物与情感之间的关联。后面的层建立在前面的层所建立的关联之上,因此当句子从编码器出来时,“它”已经被赋予了某种类似含义的东西。
之后,Transformer的第二部分——解码器——逐词生成法文翻译,在决定下一个该输出哪个法文词时,利用注意力来调用编码器对英文词的数值表示。英文句子中编码的语境信息帮助把“它”翻译成阳性代词il。
关键在于,没有人需要告诉Transformer动物会累、马路可能很宽。神经网络在训练过程中通过从大量英法对照句子中学习,自行发现了这些关联。这些关联被内建到权重中。网络最初使用随机权重,产生无用的查询、键和值,因而翻译质量很差。但每一次翻译错误都会通过网络反向发送一个纠正信号,稍微改变产生该错误的权重。经过数万亿次这样的调整,网络最终生成有用的向量,产生正确的翻译,即使处理从未见过的句子也是如此。
注意力被证明是连接词语和构建上下文——翻译的基本要素——的正确数学运算。而当你能够翻译无限大小的文本块时,你似乎就能做任何事情。
一个已经学会足够多语言知识来把英文句子翻译成法文的神经网络,也能用两种语言中的任何一种来完成句子。换句话说,预测翻译中的下一个词,是更一般的“预测下一个词”任务的子任务。而这就是大语言模型所做的。它们在整互联网的内容上训练,学习在各种语境中哪些词应该关注哪些其他词。它们反复处理整个数据集,尝试数万亿次预测训练过程中任意时刻所处网页位置的下一个词。这些模型中神经元之间的连接被逐步调整,产生词与词之间越来越有用的注意力模式,以便在任何语境中预测下一个词——或者对人类的提示生成恰当的回应。
从翻译“它”这个词的能力出发,我们不知怎么地就引发了一场革命。
“这真是相当大的飞跃,不是吗?”《注意力就是你所需要的一切》的作者之一利昂·琼斯说道,他现在是Sakana AI的首席技术官。
琼斯和其他人怀疑,预测下一个词——即所谓的语言建模——是“AI完备”的:这个任务如此困难,以至于解决了它就等于说你在广义上解决了AI。它可能是AI完备的原因在于,这个任务几乎把人类以书面形式所做的一切都作为子任务包含在内。“互联网上有翻译,”琼斯指出。“所以如果我说‘“那只动物没有过马路,因为它太累了”的法文是[空白],’那么为了完成这个句子,Transformer需要能够翻译成法文。如果我说‘2+3=[空白],’它需要做算术。如果它看到一连串数学符号,想知道接下来是什么,它需要理解高等数学。如果我说‘美国总统是[空白],’它需要知道事实。所以能够预测下一个词要求你能够做所有这些事情。而因为它是AI完备的,语言建模可以说是我们拥有的最接近智能的定义。”
说一个大语言模型“知道”或“理解”某事物——不是以人类的方式——可能并不恰当,但这只是我们习惯于谈论它们所展示能力的方式。无论如何,注意力是人工神经网络获取和传达含义、关联和上下文的工具,其效果常常足以以其流畅程度令我们惊叹。(对于高等数学等任务,当今前沿AI模型通常在其语言建模之上叠加更明确的形式推理和证明验证系统来检查其工作。)
但人类智能呢?我们的大脑是否可能采用一种类似于巴达瑙发明的数学运算的机制?毕竟,我们在说话、写作甚至思考时,也在做某种类似于“产生最佳可能的下一个词”的事情。也许我们的智能形式也等同于语言建模?
认知科学家已经开始研究这个问题——这是“语言与思维关系”这一古老问题的新版本。诚然,大语言模型的成功表明,仅凭语言的统计模式就编码了多少关于世界的信息。问题是:当我们掌握了语言,智能是否就免费附赠了?
最近的研究让我相信,人类思维并非纯粹是语言的(而且大多数其他动物的智能根本与语言无关):当我们思考时,亮起的大脑区域不仅仅是大脑皮层中与语言相关的专门网络。语言是我们交流世界的方式,但我们的思维似乎还依赖于感官印象、身体和社会经验、记忆以及推理能力,这些至少部分存在于大脑语言网络之外。因此,语言建模似乎只是人类认知的一个强大组成部分,而不是其等价物或来源。
至于我们是如何做到“它”的——我如何瞬间理解到累的是动物而不是马路——还没有人知道。琼斯本人现在认为,注意力并非真正掌握语言建模所需要的一切。毕竟,大脑显然比Transformer更高效地完成了这项任务。我们流利地对话,却从未读完整个互联网一遍,也没有消耗那么多能量。“当前的范式不会解决这个[效率]问题,”琼斯说。“你似乎必须跳到某种非常非常不同的东西。”
不管我们自己的神经机制可能是什么,事后看来,解决翻译问题解锁了AI,这对我来说是合理的。无论你是人类还是机器,有效翻译的能力意味着你在某种意义上已经理解了。现在机器理解得如此之多——至少实际上是如此——以至于我们几乎不知道该作何感想了。
英文来源:
Is ‘Attention’ the Essence of Intelligence?
Introduction
Everything that’s swept the world since the 2022 release of ChatGPT — “the AI economy”; data centers; chatbots acting as best friends, doctors, and mathematicians; talk of existential risk — it all starts, in some sense, with an intern in a University of Montreal lab named Dzmitry Bahdanau.
It was 2014. The 23-year-old Belarusian, who had been coding competitively since he was a kid but hadn’t done academic research before, was asked to help figure out how to get a computer to translate sentences from English to French. Bahdanau was working with artificial neural networks, which had already shown promise in pattern-recognition tasks such as deciphering handwriting and identifying objects in photos. The networks learn to recognize patterns by strengthening and weakening connections between nodes in response to training data. Bahdanau quietly doubted their potential to achieve anything like human-level intelligence, but his adviser, the computer scientist Yoshua Bengio, and the postdoc on the project, Kyunghyun Cho, were believers. And translation was widely seen as a formidable and interesting problem for neural networks to try to solve.
Translation is not as simple as swapping each English word for a French one. Languages have different grammatical structures and are riddled with idioms and connotations, all of which had long stymied attempts to automate the process. You can’t simply implement rules of translation because there are none. But neural networks seemed promising because they learn by example. They can be trained on huge databases of paired English and French sentences to, eventually, absorb the quasi-rules, exceptions, and subtleties.
Results had been mediocre, though; the longer the sentence, the worse neural networks performed. That’s because researchers were trying to cram each sentence’s data into a fixed amount of memory before decoding the sentence in the target language. It was a bottleneck that limited how complex and sophisticated translations could be. The network architecture just wasn’t right.
So Bahdanau tried something different. “It was just obviously the right thing to do — one of these things that happens once in a while in science where it’s just very clear to someone who is not very experienced in the field,” he recalled, speaking to me from Montreal, where he still works in AI. “And it just worked. From the very first attempt.”
Bahdanau’s trick, a mathematical operation that he, Cho, and Bengio referred to as “attention,” enabled their neural network to translate long sentences just as well as short ones. That meant the approach was scalable. Other AI researchers at the time quickly integrated attention into their neural network designs. Then, in 2017, a team at Google devised a new kind of neural network architecture called a transformer that supercharged the attention method and stripped away everything else. The team’s paper, “Attention Is All You Need,” reported that transformers achieved state-of-the-art translation while requiring a fraction of the computation needed to train prior models. The paper, which has since been cited more than 250,000 times, was a watershed moment in AI. Large language models such as ChatGPT and Claude followed.
Given the staggering power that’s been unleashed, it’s worth asking what this attention mechanism is exactly, why it is “all you need,” and why machine translation was the task that unlocked it all. Attention is a way for us to understand how a single AI model can converse with us, diagnose diseases, generate realistic videos, solve long-standing math problems, and more. Is it somehow at the heart of intelligence — artificial and otherwise?
Sentences with pronouns such as “it” in them illustrate the challenge that attention overcomes. Consider: “The animal didn’t cross the street because it was too tired.” And: “The animal didn’t cross the street because it was too wide.” To translate these sentences correctly into French, an AI model must determine that, in the first one, “it” refers to the animal, which is a masculine word in French, so the translation should use that form of the pronoun, il. But in the second sentence, “it” refers to the street, a feminine word that requires a different pronoun, elle. How can the machine figure this out?
Bahdanau remembered doing translation exercises when he was learning English in school. To write each next word of his translated sentence, he’d have to glance all around the source text to figure out what should come next. “Literally you have your source sentence on the left and your writing on the right, and you’ll be, like, turning your head, left-right, left-right,” he said. “That process is what I expressed as a neural mechanism.” The tool of attention that he gave to his neural network was a mathematical way for the network to identify the word or words anywhere in a sentence that would most inform the next word of the translation. In the case of our ambiguous pronoun, “it,” the system navigates the rest of the sentence to determine which words affect its meaning the most.
A transformer consists of many layers of nodes connected to nodes in adjacent layers. When a sentence is fed into a transformer, each word is first converted into a numerical representation called a vector, which we can imagine as an arrow pointing in a certain direction. These vectors pass through the network, and numbers called weights (determined by the model’s training) dictate how they are transformed in each layer. The weights turn each word’s current vector representation into three new vectors specific to that word — a “query,” “key,” and “value” — that each serve a different purpose in the attention operation.
The network performs this operation several times in parallel through systems called attention heads. An attention head compares each word’s query with the keys of all the other words in the sentence. How well these vectors match up — how much they point in the same direction — determines how strongly the value of each other word contributes to a new, updated vector for the word at hand. Information about other words in the sentence literally becomes incorporated into each word’s representation. The system is converting context into math.
When “The animal didn’t cross the street because it was too tired” enters a transformer, the first stack of layers in the network, known as the encoder, uses the attention operation to build up a contextual understanding of the sentence. In each layer, each attention head generates a query (along with a key and value) for “it.” This query vector can be thought of as a request for information that exists elsewhere in the sentence. For instance, in a deep layer (after the network has already accumulated information about words), the query for “it” might be interpretable as: “I need an earlier noun that could plausibly be the thing that is tired.” Meanwhile, the key associated with “animal” might effectively advertise itself as a noun that’s capable of being tired, among many other features. Its key therefore matches the query better than the key for “street.” And that causes the value associated with “animal” to contribute more heavily to the updated representation of “it.”
That new, context-enriched representation of “it” passes into the next layer. There, the network performs attention all over again. Successive rounds give the words increasingly rich representations of themselves.
Experts say it’s often hard to interpret what any given attention head is doing, but collectively they pick up on many kinds of relationships, from the partnership between nouns and verbs to the association between living beings and feelings. Later layers build on associations established by earlier layers, so that by the time the sentence emerges from the encoder, “it” is imbued with something resembling meaning.
After that, the second part of the transformer, the decoder, produces the French translation one word at a time, using attention to draw on the encoder’s numerical representations of the English words as it decides which French word to spit out next. The contextual information encoded in the English sentence helps translate “it” as the masculine il.
Crucially, no one had to tell a transformer that animals get tired and streets may be wide. The neural network discovers such associations during training, by learning from huge numbers of English sentences paired with their French translations. These associations get built into the weights. The network starts out with random weights that produce unhelpful queries, keys, and values, and thus poor translations. But each translation error sends a correction signal backward through the network that slightly alters the weights that produced it. Through trillions of these adjustments, the network eventually generates useful vectors that yield correct translations, even when it processes sentences it has never seen before.
Attention turned out to be the right mathematical operation for linking words and building context — the fundamentals of translation. And when you can translate blocks of text of unlimited size, it seems you can do anything.
A neural network that has learned enough about language to translate sentences from English into French can also complete sentences in either language. Predicting the next word of a translation is, in other words, a subtask of the more general task of “predicting the next word,” period. And that’s what large language models do. They’re trained on the contents of the entire internet, learning which words should attend to which other words in all sorts of contexts. They process and reprocess the whole dataset and try trillions of times to predict the next word in whatever part of the web they happen to be in at any point during training. The connections between neurons in these models are gradually tweaked in a way that produces patterns of attention between words that are ever more useful for predicting the next word in any context — or for producing an appropriate response to a prompt from a human.
From the ability to translate the word “it,” we somehow got a revolution.
“That’s quite a leap, isn’t it?” said Llion Jones, one of the authors of “Attention Is All You Need,” who is now the chief technology officer of Sakana AI.
Jones and others suspect that predicting the next word, which is known as language modeling, is “AI-complete”: a task so difficult that solving it means you have arguably solved AI in general. The reason it may be AI-complete is that this task includes, as a subtask, virtually anything humans do in written form. “The internet has translations,” Jones notes. “So if I said ‘“The animal didn’t cross the street because it was too tired” in French is [blank],’ then in order to complete that sentence, the transformer needs to be able to translate into French. If I say ‘2 + 3 is [blank],’ it needs to do arithmetic. If it sees a bunch of mathematical symbols in a row and wants to know what comes next, it needs to understand high-level mathematics. If I say ‘The president of the United States is [blank],’ it needs to know facts. So being able to predict the next word requires you to be able to do all these things. And because it’s AI-complete, language modeling is kind of the closest definition that we have to intelligence.”
It might not be apt to say that an LLM “knows” or “understands” anything — not in the way that a human does — but that’s just how we’re accustomed to talking about the abilities they display. Regardless, attention is the tool by which artificial neural networks access and convey meaning, association, and context, often well enough to astonish us with their fluency. (For tasks such as advanced mathematics, today’s frontier AI models often have more explicit formal reasoning and proof verification systems layered on top of their language modeling to check their work.)
But what about human intelligence? Might our brains employ a mechanism similar to the mathematical operation Bahdanau invented? After all, we, too, do something akin to “producing the best possible next word” when we speak, write, and even think. Perhaps our form of intelligence is tantamount to language modeling, too?
Cognitive scientists have begun to study this question — a new version of the ancient question of how language relates to thought. To be sure, the success of LLMs shows how much information about the world is encoded in the statistical patterns of language alone. The question is: When we master language, does intelligence come for free?
Recent research persuades me that human thought is not purely linguistic (and most other animals’ intelligence is not linguistic at all): When we are thinking, more brain regions light up than just the specialized networks in the cerebral cortex that are associated with language. Language is how we communicate about the world, but our thoughts seem to draw on sensory impressions, physical and social experiences, memories, and reasoning abilities that exist at least partly outside the brain’s language networks. So language modeling seems to be merely a powerful component of human cognition, not its equivalent or source.
As for how we do “it” — how I instantly understand that it’s the animal rather than the street that is tired — no one yet knows. Jones, for his part, now thinks that attention is not all you need to truly master language modeling. After all, the brain evidently accomplishes this task far more efficiently than transformers do. We converse fluently without having read the whole internet even once, and without burning as much energy. “The current paradigm won’t solve this [efficiency] problem,” Jones said. “You seem to have to jump to something very, very different.”
Regardless of what our own neural mechanisms might be, it makes sense to me in hindsight that solving translation unlocked AI. Whether you’re human or machine, the ability to translate effectively means you have understood, in some sense. Now the machines understand so much — effectively, at least — that we hardly know what to think anymore.