Skip to Content
变形金刚权威指南 (Chinese Edition)
book

变形金刚权威指南 (Chinese Edition)

by Nicole Koenigstein
March 2026
Intermediate
372 pages
4h 53m
Chinese
O'Reilly Media, Inc.
Content preview from 变形金刚权威指南 (Chinese Edition)

第1章 从 第一性原理到 最先进的Transformer模型

本作品已使用人工智能进行翻译。欢迎您提供反馈和意见:translation-feedback@oreilly.com

自2017年推出以来,变压器架构1 彻底革新了自然语言处理(NLP)领域 ,标志着向具备自然语言理解(NLU)能力的模型迈出了范式转变的一步 。这一转变之所以成为可能,是因为Transformer能够并行处理序列数据,从而实现了比长短期记忆(LSTM)网络 等传统序列模型更深入、更具上下文关联的语言理解。

近年来,Transformer 模型已发展到影响包括计算机视觉、语音识别、强化学习和数学运算在内的广泛领域,超越了其在自然语言处理(NLP)中的最初应用。其适应性推动了机器翻译领域的重大进步,实现了基于上下文的翻译;在科学研究领域,特别是蛋白质结构预测方面,也取得了惊人的准确度。

其中最令人振奋的发展当属推理模型 ,这是一种通过强化学习 训练的高级大型语言模型(LLMs) ,能够进行复杂的多步骤推理。它们在回答问题前会生成内部思维链,这种机制借鉴了人类的思维过程。该技术首先解决中间步骤,然后得出最终答案。

本书假设您对Transformer架构至少有一定了解。也许您读过这本书 《基于Transformer的自然语言处理》 (O’Reilly)或类似著作。此外,我认为您对Transformer的兴趣不仅止于好奇。您来到这里,是因为您希望利用Transformer构建真正的应用程序,并且希望做到尽善尽美。

本章将对Transformer架构进行重点回顾,为后续章节中将要探讨的、超越自然语言处理(NLP)范畴的更高级、更复杂的模型奠定基础。

我将从基础的Transformer架构开始,接着解释如何实现更长的上下文处理,最后带您了解各种注意力机制。在本章及后续章节中,我将分享来自实际部署的实践见解,以便您能从我的经验中获益,并掌握当理论与生产环境的严苛现实相遇时,那些至关重要的模式、陷阱和原则。

Transformer基础

本节将介绍架构,阐述原始Transformer模型的主要架构组件,包括编码器和解码器、位置嵌入以及注意力 机制

的Transformer架构最初是为机器翻译而开发的,这是一种具有挑战性的序列到序列任务,其中分词概念起着关键作用。分词将 中的句子等序列分解为可管理的单元(即令牌),以便Transformer能够有效处理。例如,在 句子

The Transformer has revolutionized NLP.

单词the代表一个单词级别的令牌。

在深入探讨架构组件之前,理解分词至关重要,因为它有助于增强Transformer解读文本的能力,并为其在其他序列中的应用奠定了基础。

分词器:Transformer 中的文本表示

分词器(tokenizer)用于将文本进行分词处理。这是使自然语言能够被模型理解的第一步,之后才会应用词向量,最后应用位置向量。分词的类型包括:

字符级分词

字符级分词将底层字母表拆分为序列中存在的每个字符。若对以下内容使用字符级分词:

"The Transformer has revolutionized NLP."

将生成:

[T,h,e, ', …​ 'N,L,P,.]

这将导致序列长度过长,从而增加计算复杂度。此外,模型在学习长程依赖关系时也会面临挑战。不过,如果您的任务需要精细的 理解,这种方法会很有帮助。

词级分词

词级分词会将该示例句子拆分为:

[The,Transformer, …​NLP,., ]

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

LLM 网格 (Chinese Edition)

LLM 网格 (Chinese Edition)

Kurt Muehmel

Publisher Resources

ISBN: 0642572364274