第 1 章 · 引言
Understanding Deep Learning — Introduction
Artificial intelligence, or AI, is concerned with building systems that simulate intelligent behavior. It encompasses a wide range of approaches, including those based on logic, search, and probabilistic reasoning. Machine learning is a subset of AI that learns to make decisions by fitting mathematical models to observed data. This area has seen explosive growth and is now (incorrectly) almost synonymous with the term AI.
A deep neural network (or deep network for short) is a type of machine learning model, and the process of fitting these models to data is referred to as deep learning. At the time of writing, deep networks are the most powerful and practical machine learning models and are often encountered in day-to-day life. It is commonplace to translate text to another language using a natural language processing algorithm, to search for images of a given object using a computer vision system, or to converse with a digital assistant via a speech recognition interface. All of these applications are powered by deep learning.
人工智能,或 AI,关注构建能够模拟智能行为的系统。它涵盖范围广泛的方法,包括基于逻辑、搜索和概率推理的方法。机器学习是 AI 的一个子集,通过用数学模型拟合观测数据来学习做出决策。这一领域经历了爆炸式增长,如今(错误地)几乎与 AI 一词同义。
深层神经网络(或深度网络)是一种机器学习模型,将这些模型与数据拟合的过程称为深度学习。在本书撰写时,深度网络是最强大且实用的机器学习模型,在日常生活中经常遇到。使用自然语言处理算法将文本翻译成另一种语言、使用计算机视觉系统搜索给定对象的图像,或通过语音识别界面与数字助手对话,都已经很常见。所有这些应用都由深度学习驱动。
As the title suggests, this book aims to help a reader new to this field understand the principles behind deep learning. The book is neither terribly theoretical (there are no proofs) nor extremely practical (there is almost no code). The goal is to explain the underlying ideas; after consuming this volume, the reader will be able to apply deep learning to novel situations where there is no existing recipe for success.
Machine learning methods can coarsely be divided into three areas: supervised, unsupervised, and reinforcement learning. At the time of writing, the cutting-edge methods in all three areas rely on deep learning (figure 1.1). This introductory chapter describes these three areas at a high level, and this taxonomy is also loosely reflected in the book’s organization. Whether we like it or not, deep learning is poised to change our world, and this change will not all be positive. Hence, this chapter also contains a brief primer on AI ethics. We conclude with advice on how to make the most of this book.
正如标题所示,本书旨在帮助初次接触该领域的读者理解深度学习背后的原理。本书既不是非常理论化(没有证明),也不是非常实用(几乎没有代码)。目标是解释其背后的思想;读完本书后,读者将能够将深度学习应用于没有现成成功方法的新情况。
机器学习方法大致可分为三个领域:监督学习、无监督学习和强化学习。在本书撰写时,这三个领域的尖端方法都依赖于深度学习(图 1.1)。本章从高层次介绍这三个领域,这种分类也大致体现在本书的结构中。无论我们是否愿意,深度学习都即将改变我们的世界,而这种变化不会全是积极的。因此,本章还简要介绍了人工智能伦理。最后,我们提供如何充分利用本书的建议。
Supervised learning models define a mapping from input data to an output prediction. In the following sections, we discuss the inputs, the outputs, the model itself, and what is meant by “training” a model.
监督学习模型定义了一个从输入数据到输出预测的映射。在以下各节中,我们将讨论输入、输出、模型本身,以及“训练”模型的含义。

Figure 1.2 depicts several regression and classification problems. In each case, there is a meaningful real-world input (a sentence, a sound file, an image, etc.), and this is encoded as a vector of numbers. This vector forms the model input. The model maps the input to an output vector which is then “translated” back to a meaningful real-world prediction. For now, we focus on the inputs and outputs and treat the model as a black box that ingests a vector of numbers and returns another vector of numbers.
The model in figure 1.2a predicts the price of a house based on input characteristics such as the square footage and the number of bedrooms. This is a regression problem because the model returns a continuous number (rather than a category assignment). In contrast, the model in figure 1.2b takes the chemical structure of a molecule as an input and predicts both the freezing and boiling points. This is a multivariate regression problem since it predicts more than one number.
The model in figure 1.2c receives a text string containing a restaurant review as input and predicts whether the review is positive or negative. This is a binary classification problem because the model attempts to assign the input to one of two categories. The output vector contains the probabilities that the input belongs to each category. Figures 1.2d and 1.2e depict multiclass classification problems. Here, the model assigns the input to one of N> 2 categories. In the first case, the input is an audio file, and the model predicts which genre of music it contains. In the second case, the input is an image, and the model predicts which object it contains. In each case, the model returns a vector of size N that contains the probabilities of the N categories.
图 1.2 展示了若干回归和分类问题。在每种情况下,都有一个有意义的现实世界输入(句子、音频文件、图像等),并且该输入被编码为一个数字向量。这个向量构成模型输入。模型将输入映射为一个输出向量,随后该向量被“翻译”回有意义的现实世界预测。目前,我们关注输入和输出,并将模型视为一个黑箱,它接收一个数字向量并返回另一个数字向量。
图 1.2a 中的模型基于面积和卧室数量等输入特征预测房屋价格。这是一个回归问题,因为模型回报一个连续数值(而不是类别分配)。相比之下,图 1.2b 中的模型以分子的化学结构作为输入,并预测凝固点和沸点。这是一个多元回归问题,因为它预测多个数值。
图 1.2c 中的模型接收包含餐厅评论的文本字符串作为输入,并预测该评论是正面还是负面。这是一个二分类问题,因为模型试图将输入归入两个类别之一。输出向量包含输入属于每个类别的概率。图 1.2d 和图 1.2e 展示了多分类问题。在这里,模型将输入归入 N> 2 个类别中的一个。在第一种情况下,输入是一个音频文件,模型预测其中包含哪种音乐类型。在第二种情况下,输入是一幅图像,模型预测其中包含哪个物体。在每种情况下,模型回报一个大小为 N 的向量,其中包含 N 个类别的概率。
The input data in figure 1.2 varies widely. In the house pricing example, the input is a fixed-length vector containing values that characterize the property. This is an example of tabular data because it has no internal structure; if we change the order of the inputs and build a new model, then we expect the model prediction to remain the same. Conversely, the input in the restaurant review example is a body of text. This may be of variable length depending on the number of words in the review, and here input
图 1.2 中的输入数据差异很大。在房价示例中,输入是一个固定长度的向量,其中包含用于表征该房产的数值。这是表格数据的示例,因为它没有内部结构;如果我们改变输入的顺序并构建一个新模型,那么预期模型的预测结果保持不变。相反,餐厅评论示例中的输入是一段文本。根据评论中的单词数量,其长度可能可变,而这里的输入


order is important; my wife ate the chicken is not the same as the chicken ate my wife. The text must be encoded into numerical form before passing it to the model. Here, we use a fixed vocabulary of size 10,000 and simply concatenate the word indices.
For the music classification example, the input vector might be of fixed size (perhaps a 10-second clip) but is very high-dimensional (i.e., contains many entries). Digital audio is usually sampled at 44.1 kHz and represented by 16-bit integers, so a ten-second clip consists of 441,000 integers. Clearly, supervised learning models will have to be able to process sizeable inputs. The input in the image classification example (which consists of the concatenated RGB values at every pixel) is also enormous. Moreover, it contains spatial structure; two pixels above and below one another are closely related, even if they are not adjacent in the input vector.
Finally, consider the input for the model that predicts the freezing and boiling points of the molecule. A molecule may contain varying numbers of atoms that can be connected in different ways. In this case, the model must ingest both the geometric structure of the molecule and the constituent atoms to the model.
顺序很重要;我的妻子吃了鸡肉并不等于鸡肉吃了我的妻子。文本必须编码为数值形式后再传递给模型。这里,我们使用大小为 10,000 的固定词汇表,并简单地拼接词索引。
在音乐分类示例中,输入向量可能具有固定大小(也许是 10 秒的片段),但维度非常高(即包含许多条目)。数字音频通常以 44.1 kHz 采样,并用 16 位整数表示,因此一个 10 秒的片段包含 441,000 个整数。显然,监督学习模型必须能够处理规模较大的输入。图像分类示例中的输入(由每个像素的拼接 RGB 值组成)也非常庞大。此外,它包含空间结构;上下相邻的两个像素密切相关,即使它们在输入向量中并不相邻。
最后,考虑预测分子凝固点和沸点的模型的输入。一个分子可能包含数量不等的原子,这些原子可以以不同方式连接。在这种情况下,模型必须同时接收分子的几何结构以及其组成原子。
Until now, we have treated the machine learning model as a black box that takes an input vector and returns an output vector. But what exactly is in this black box? Consider a model to predict the height of a child from their age (figure 1.3). The machine learning
model is a mathematical equation that describes how the average height varies as a function of age (cyan curve in figure 1.3). When we run the age through this equation, it returns the height. For example, if the age is 10 years, then we predict that the height will be 139 cm.
More precisely, the model represents a family of equations mapping the input to the output (i.e., a family of different cyan curves). The particular equation (curve) is chosen using training data (examples of input/output pairs). In figure 1.3, these pairs are represented by the orange points, and we can see that the model (cyan line) describes these data reasonably. When we talk about training or fitting a model, we mean that we search through the family of possible equations (possible cyan curves) relating input to output to find the one that describes the training data most accurately.
到目前为止,我们一直将机器学习模型视为一个黑箱,它接收输入向量并回报输出向量。但这个黑箱中究竟有什么?考虑一个根据儿童年龄预测身高的模型(图 1.3)。机器学习
模型是一个数学方程,描述平均身高如何随年龄变化(图 1.3 中的青色曲线)。当我们将年龄代入这个方程时,它会回报身高。例如,如果年龄为 10 岁,那么我们预测身高将是 139 厘米。
更准确地说,模型表示将输入映射到输出的一组方程(即一组不同的青色曲线)。特定方程(曲线)是使用训练数据(输入 / 输出对的示例)来选择的。在图 1.3 中,这些对由橙色点表示,我们可以看到模型(青色线)合理地描述了这些数据。当我们谈论训练或拟合模型时,意思是在将输入与输出关联的可能方程(可能的青色曲线)族中搜索,以找到最准确地描述训练数据的方程。
It follows that the models in figure 1.2 require labeled input/output pairs for training. For example, the music classification model would require a large number of audio clips where a human expert had identified the genre of each. These input/output pairs take the role of a teacher or supervisor for the training process, and this gives rise to the term supervised learning.
因此,图 1.2 中的模型需要带标签的输入 / 输出对进行训练。例如,音乐分类模型需要大量音频片段,其中人类专家已识别每个片段的流派。这些输入 / 输出对扮演训练过程中的教师或监督者角色,由此产生了术语监督学习。
This book concerns deep neural networks, which are a particularly useful type of machine learning model. They are equations that can represent an extremely broad family of relationships between input and output, and where it is particularly easy to search through this family to find the relationship that describes the training data.
Deep neural networks can process inputs that are very large, of variable length, and contain various kinds of internal structures. They can output single real numbers (regression), multiple numbers (multivariate regression), or probabilities over two or more classes (binary and multiclass classification, respectively). As we shall see in the next section, their outputs may also be very large, of variable length, and contain internal structure. It is probably hard to imagine equations with these properties, and the reader should endeavor to suspend disbelief for now.
本书关注深层神经网络,这是一种特别有用的机器学习模型。它们是一类方程,能够表示输入与输出之间极为广泛的关系族,并且在这一族关系中,尤其容易搜索出能够描述训练数据的关系。
深层神经网络能够处理非常庞大、长度可变且包含多种内部结构的输入。它们可以输出单个实数(回归)、多个数值(多元回归),或者两个或多个类别上的概率(分别为二分类和多分类)。正如我们在下一节中将要看到的,它们的输出也可能非常庞大、长度可变,并包含内部结构。具有这些性质的方程可能难以想象,读者现在应当尽量暂时搁置怀疑。
Figure 1.4a depicts a multivariate binary classification model for semantic segmentation. Here, every pixel of an input image is assigned a binary label that indicates whether it belongs to a cow or the background. Figure 1.4b shows a multivariate regression model where the input is an image of a street scene and the output is the depth at each pixel. In both cases, the output is high-dimensional and structured. However, this structure is closely tied to the input, and this can be exploited; if a pixel is labeled as “cow,” then a neighbor with a similar RGB value probably has the same label. Figures 1.4c–e depict three models where the output has a complex structure that is not so closely tied to the input. Figure 1.4c shows a model where the input is an audio file and the output is the transcribed words from that file. Figure 1.4d is a translation
model in which the input is a body of text in English, and the output contains the French translation. Figure 1.4e depicts a very challenging task in which the input is descriptive text, and the model must produce an image that matches this description.
图 1.4a 描绘了一个用于语义分割的多元二分类模型。这里,输入图像的每个像素都被分配一个二值标签,用以指示该像素属于牛还是背景。图 1.4b 展示了一个多元回归模型,其中输入是一幅街景图像,输出是每个像素的深度。在两种情况下,输出都是高维且结构化的。然而,这种结构与输入密切相关,这一点可以被利用;如果一个像素被标记为“牛”,那么具有相似 RGB 值的邻近像素很可能具有相同的标签。图 1.4c–e 展示了三个模型,其中输出具有复杂结构,与输入的关联不那么紧密。图 1.4c 展示了一个模型,其输入是音频文件,输出是该文件转录的文字。图 1.4d 是一个翻译
一种模型,其输入是一段英文文本,输出包含法文翻译。图 1.4e 描绘了一项极具挑战性的任务:输入为描述性文本,模型必须生成与该描述相符的图像。

In principle, the latter three tasks can be tackled in the standard supervised learning framework, but they are more difficult for two reasons. First, the output may genuinely be ambiguous; there are multiple valid translations from an English sentence to a French one and multiple images that are compatible with any caption.
Second, the output contains considerable structure; not all strings of words make valid English and French sentences, and not all collections of RGB values make plausible images. In addition to learning the mapping, we also have to respect the “grammar” of the output.
Fortunately, this “grammar” can be learned without the need for output labels. For example, we can learn how to form valid English sentences by learning the statistics of a large corpus of text data. This provides a connection with the next section of the book, which considers unsupervised learning models.
原则上,后三项任务可以在标准监督学习框架中处理,但由于两个原因而更难。首先,输出本身可能确实存在歧义;从一句英文到一句法文存在多种有效翻译,并且任何说明文字都有多张兼容图像。其次,输出包含相当多的结构;并非所有单词串都能构成有效的英文或法文句子,也并非所有 RGB 值集合都能构成合理的图像。除了学习映射之外,我们还必须遵守输出的“语法”。
幸运的是,这种“语法”可以在不需要输出标签的情况下学习。例如,我们可以通过学习大型文本语料库的统计信息来学习如何构成有效的英文句子。这为本书下一节提供了联系,该节考虑无监督学习模型。
Constructing a model from input data without corresponding output labels is termed unsupervised learning; the absence of output labels means there can be no “supervision.” Rather than learning a mapping from input to output, the goal is to describe or understand the structure of the data. As was the case for supervised learning, the data may have very different characteristics; it may be discrete or continuous, low-dimensional or high-dimensional, and of constant or variable length.
根据输入数据构建模型而没有对应的输出标签,这被称为无监督学习;没有输出标签意味着无法进行“监督”。目标不是学习从输入到输出的映射,而是描述或理解数据的结构。与监督学习一样,数据可能具有非常不同的特征;它可能是离散或连续、低维或高维,长度固定或可变。
This book focuses on generative unsupervised models, which learn to synthesize new data examples that are statistically indistinguishable from the training data.
Some generative models explicitly describe the probability distribution over the input data and here new examples are generated by sampling from this distribution. Others merely learn a mechanism to generate new examples without explicitly describing their distribution.
State-of-the-art generative models can synthesize examples that are extremely plausible but distinct from the training examples. They have been particularly successful at generating images (figure 1.5) and text (figure 1.6). They can also synthesize data under the constraint that some outputs are predetermined (termed conditional generation). Examples include image inpainting (figure 1.7) and text completion (figure 1.8). Indeed, modern generative models for text are so powerful that they can appear intelligent. Given a body of text followed by a question, the model can often “fill in” the missing answer by generating the most likely completion of the document. However, in reality, the model only knows about the statistics of language and does not understand the significance of its answers.
本书聚焦于生成式无监督模型,这些模型学习合成在统计上与训练数据无法区分的新数据样本。一些生成模型明确描述输入数据上的概率分布,此时新样本通过从该分布采样生成。另一些模型则仅学习生成新样本的机制,而不明确描述其分布。
最先进的生成模型可以合成极其可信但与训练样本不同的样本。它们在生成图像(图 1.5)和文本(图 1.6)方面尤为成功。它们还可以在某些输出预先确定的约束下合成数据(称为条件生成)。示例包括图像修复(图 1.7)和文本补全(图 1.8)。事实上,现代文本生成模型如此强大,以至于它们可以显得智能。给定一段文本后接一个问题,模型通常可以通过生成文档最可能的补全来“填补”缺失的答案。然而,实际上,模型只了解语言的统计规律,并不理解其答案的意义。





Some (but not all) generative models exploit the fact that data can be lower dimensional than the raw number of observed variables suggests. For example, the number of valid and meaningful English sentences is much smaller than the number of strings created by drawing words at random. Similarly, real-world images are a tiny subset of the images that can be created by drawing random red, green, and blue (RGB) values for every pixel. This is because images are generated by physical processes (see figure 1.9). This leads to the idea that we can describe each data example using a smaller number of underlying latent variables. Here, the role of deep learning is to describe the mapping between these latent variables and the data. The latent variables typically have a simple
一些(但并非所有)生成模型利用了这样一个事实:数据的维度可能低于观测变量的原始数量所暗示的维度。例如,有效且有意义的英语句子数量远少于随机抽取单词所生成的字符串数量。同样,真实世界图像只是为每个像素随机生成红、绿、蓝(RGB)值所能产生的图像中的极小一部分。这是因为图像是由物理过程生成的(见图 1.9)。这引出了这样一个想法:我们可以用更少的底层隐变量来描述每个数据样本。这里,深度学习的作用是描述这些隐变量与数据之间的映射关系。隐变量通常具有简单的


probability distribution by design. By sampling from this distribution and passing the result through the deep learning model, we can create new samples (figure 1.10).
These models lead to new methods for manipulating real data. For example, consider finding the latent variables that underpin two real examples. We can interpolate between these examples by interpolating between their latent representations and mapping the intermediate positions back into the data space (figure 1.11).
这些模型催生了操控真实数据的新方法。例如,考虑找出支撑两个真实示例的隐变量。我们可以通过在它们的隐表示之间插值,并将中间位置映射回数据空间,来在这些示例之间进行插值(图 1.11)。

Generative models with latent variables can also benefit supervised learning models where the outputs have structure (figure 1.4). For example, consider learning to predict the images corresponding to a caption. Rather than directly map the text input to an image, we can learn a relation between latent variables that explain the text and the latent variables that explain the image.
This has three advantages. First, we may need fewer text/image pairs to learn this mapping now that the inputs and outputs are lower dimensional. Second, we are more likely to generate a plausible-looking image; any sensible values of the latent variables should produce something that looks like a plausible example. Third, if we introduce randomness to either the mapping between the two sets of latent variables or the mapping from the latent variables to the image, then we can generate multiple images that are all described well by the caption (figure 1.12).
带有隐变量的生成模型也可以使输出具有结构的监督学习模型受益(图 1.4)。例如,考虑学习预测与图注对应的图像。我们可以不直接将文本输入映射为图像,而是学习解释文本的隐变量与解释图像的隐变量之间的关系。
这有三个优点。首先,由于输入和输出的维度更低,我们现在可能只需要更少的文本 / 图像配对即可学习这种映射。其次,我们更有可能生成看起来合理的图像;隐变量的任何合理取值都应能生成看起来像合理示例的内容。第三,如果我们在两组隐变量之间的映射或从隐变量到图像的映射中引入随机性,那么就可以生成多张图像,且这些图像都能被该标题很好地描述(图 1.12)。
The final area of machine learning is reinforcement learning. This paradigm introduces the idea of an agent which lives in a world and can perform certain actions at each time step. The actions change the state of the system but not necessarily in a deterministic way. Taking an action can also produce rewards, and the goal of reinforcement learning
is for the agent to learn to choose actions that lead to high rewards on average.
One complication is that the reward may occur some time after the action is taken, so associating a reward with an action is not straightforward. This is known as the temporal credit assignment problem. As the agent learns, it must trade off exploration and exploitation of what it already knows; perhaps the agent has already learned how to receive modest rewards; should it follow this strategy (exploit what it knows), or should it try different actions to see if it can improve (explore other opportunities)?
机器学习的最后一个领域是强化学习。这种范式引入了智能体的概念,智能体生活在世界中,并可以在每个时间步执行某些动作。这些动作会改变系统的状态,但不一定是确定性的。采取动作也可能产生奖励,而强化学习的目标
是让智能体学会选择平均而言能带来高奖励的动作。
一个复杂之处在于,奖励可能在采取行动后一段时间才出现,因此将奖励与行动关联起来并不简单。这被称为时间信用分配问题。随着智能体学习,它必须在探索和利用已有知识之间进行权衡;也许智能体已经学会了如何获得适度的奖励;它应该遵循这一策略(利用自己已知的知识),还是应该尝试不同的行动,看看能否改进(探索其他机会)?
Consider teaching a humanoid robot to locomote.
The robot can perform a limited number of actions at a given time (moving various joints), and these change the state of the world (its pose). We might reward the robot for reaching checkpoints in an obstacle course. To reach each checkpoint, it must perform many actions, and it’s unclear which ones contributed to the reward when it is received and which were irrelevant. This is an example of the temporal credit assignment problem.
考虑教一个人形机器人进行移动。机器人在给定时间只能执行有限数量的动作(移动各个关节),而这些动作会改变世界的状态(它的姿态)。我们可能会因机器人到达障碍赛道中的检查点而给予奖励。为了到达每个检查点,它必须执行许多动作,而当奖励到来时,哪些动作促成了奖励、哪些动作无关,并不清楚。这就是时间信用分配问题的一个示例。
A second example is learning to play chess. Again, the agent has a set of valid actions (chess moves) at any given time. However, these actions change the state of the system in a non-deterministic way; for any choice of action, the opposing player might respond with many different moves. Here, we might set up a reward structure based on capturing pieces or just have a single reward at the end of the game for winning. In the latter case, the temporal credit assignment problem is extreme; the system must learn which of the many moves it made were instrumental to success or failure.
The exploration-exploitation trade-off is also apparent in these two examples. The robot may have discovered that it can make progress by lying on its side and pushing with one leg. This strategy will move the robot and yields rewards, but much more slowly than the optimal solution: to balance on its legs and walk. So, it faces a choice between exploiting what it already knows (how to slide along the floor awkwardly) and exploring the space of actions (which might result in much faster locomotion). Similarly, in the chess example, the agent may learn a reasonable sequence of opening moves. Should it exploit this knowledge or explore different opening sequences?
It is perhaps not obvious how deep learning fits into the reinforcement learning framework. There are several possible approaches, but one technique is to use deep networks to build a mapping from the observed world state to an action. This is known as a policy network. In the robot example, the policy network would learn a mapping from its sensor measurements to joint movements. In the chess example, the network would learn a mapping from the current state of the board to the choice of move (figure 1.13).
第二个例子是学习下棋。同样,智能体在任意时刻都有一组合法动作(棋步)。然而,这些动作会以非确定性的方式改变系统状态;对于任何动作选择,对手都可能以许多不同的着法回应。这里,我们可以根据吃子情况设置奖励结构,或者只在终局为获胜设置单一奖励。在后一种情况下,时序信用分配问题极为突出;系统必须从它所走的众多着法中学会哪些对成功或失败起了关键作用。
探索 - 利用权衡在这两个例子中同样显而易见。机器人可能已经发现,侧躺并用一条腿推地可以取得进展。这种策略能让机器人移动并获得奖励,但比最优解 —— 用腿保持平衡并行走 —— 要慢得多。因此,它面临一个选择:是利用自己已经知道的知识(如何笨拙地沿地面滑行),还是探索动作空间(这可能会带来更快速的移动)。同样,在下棋例子中,智能体可能学到了一套合理的开局着法。它应该利用这一知识,还是探索不同的开局序列?
深度学习如何融入强化学习框架,这一点或许并不明显。有几种可能的途径,但其中一种技术是使用深度网络来建立从观测到的世界状态到动作的映射。这被称为策略网络。在机器人示例中,策略网络将学习从传感器测量值到关节运动的映射。在国际象棋示例中,网络将学习从当前棋盘状态到走法选择的映射(图 1.13)。
It would be irresponsible to write this book without discussing the ethical implications of artificial intelligence. This potent technology will change the world to at least the
same extent as electricity, the internal combustion engine, the transistor, or the internet. The potential benefits in healthcare, design, entertainment, transport, education, and almost every area of commerce are enormous. However, scientists and engineers are often unrealistically optimistic about the outcomes of their work, and the potential for harm is just as great. The following paragraphs highlight five concerns.
如果不讨论人工智能的伦理影响,写这本书就是不负责任的。这项强大的技术将改变世界,至少达到
与电力、内燃机、晶体管或互联网相同的程度。在医疗、设计、娱乐、交通、教育以及几乎所有商业领域,潜在收益都是巨大的。然而,科学家和工程师往往对自己工作的成果抱有不切实际的乐观态度,而潜在危害也同样巨大。以下段落将重点阐述五个方面的关切。

Bias and fairness:
If we train a system to predict salary levels for individuals based on historical data, then this system will reproduce historical biases; for example, it will probably predict that women should be paid less than men. Several such cases have already become international news stories: an AI system for super-resolving face images made non-white people look more white; a system for generating images produced only pictures of men when asked to synthesize pictures of lawyers. Careless application of algorithmic decision-making using AI has the potential to entrench or aggravate existing biases. See Binns (2018) for further discussion.
Explainability:
偏差与公平性:如果我们基于历史数据训练一个系统来预测个人的薪资水平,那么该系统会复制历史偏差;例如,它很可能会预测女性应比男性薪资更低。已有若干此类案例成为国际新闻:一个用于人脸图像超分辨率的 AI 系统使非白人看起来更白;一个图像生成系统在要求合成律师图片时只生成男性图片。轻率地应用基于 AI 的算法决策,有可能固化或加剧现有偏差。更多讨论参见 Binns (2018)。
Deep learning systems make decisions, but we do not usually know exactly how or based on what information. They may be enormous, and there is no way we can understand how they work based on examination. This has led to the sub-field of explainable AI. One moderately successful area is producing local explanations; we cannot explain the entire system, but we can produce an interpretable description of why a particular decision was made. However, it remains unknown whether it is possible to build complex decision-making systems that are fully transparent to their users or even their creators. See Grennan et al. (2022) for further information.
Weaponizing AI:
All significant technologies have been applied directly or indirectly toward war. Sadly, violent conflict seems to be an inevitable feature of human behavior. AI is arguably the most powerful technology ever built and will doubtless be deployed extensively in a military context. Indeed, this is already happening (Heikkilä, 2022).
可解释性:深度学习系统会做出决策,但我们通常并不确切知道它们如何决策,或基于什么信息。它们可能规模庞大,我们无法通过检查来理解其工作原理。这催生了可解释 AI 这一子领域。一个较为成功的方向是生成局部解释;我们无法解释整个系统,但可以生成可解释的描述,说明为何做出某个特定决策。然而,能否构建对用户甚至其创建者完全透明的复杂决策系统,目前仍未知。更多信息参见 Grennan et al. (2022)。
人工智能武器化:所有重要技术都直接或间接地用于战争。令人遗憾的是,暴力冲突似乎是人类行为不可避免的特征。人工智能可以说是迄今建造的最强大的技术,无疑将在军事环境中得到广泛部署。事实上,这已经在发生(Heikkilä, 2022)。
Concentrating power:
It is not from a benevolent interest in improving the lot of the human race that the world’s most powerful companies are investing heavily in artificial intelligence. They know that these technologies will allow them to reap enormous profits. Like any advanced technology, deep learning is likely to concentrate power in the hands of the few organizations that control it. Automating jobs that are currently done by humans will change the economic environment and disproportionately affect the livelihoods of lower-paid workers with fewer skills. Optimists argue similar disruptions happened during the industrial revolution and resulted in shorter working hours. The truth is that we simply do not know what effects the large-scale adoption of AI will have on society (see David, 2015).
Existential risk:
权力集中:世界上最强大的公司大力投资人工智能,并非出于改善人类处境的善意。他们知道这些技术将使他们获得巨额利润。与任何先进技术一样,深度学习可能会把权力集中在少数控制它的组织手中。将目前由人类完成的工作自动化,会改变经济环境,并对技能较少、收入较低的工人的生计造成不成比例的影响。乐观主义者认为,类似的动荡在工业革命期间也曾发生,并导致工作时间缩短。事实是,我们根本不知道大规模采用人工智能会对社会产生什么影响(参见 David, 2015)。
The major existential risks to the human race all result from technology. Climate change has been driven by industrialization. Nuclear weapons derive from the study of physics. Pandemics are more probable and spread faster because innovations in transport, agriculture, and construction have allowed a larger, denser, and more interconnected population. Artificial intelligence brings new existential risks. We should be very cautious about building systems that are more capable and extensible than human beings. In the most optimistic case, it will put vast power in the hands of the owners.
In the most pessimistic case, we will be unable to control it or even understand its motives (see Tegmark, 2018).
This list is far from exhaustive. AI could also enable surveillance, disinformation, violations of privacy, fraud, and manipulation of financial markets, and the energy required to train AI systems contributes to climate change. Moreover, these concerns are not speculative; there are already many examples of ethically dubious applications of AI (consult Dao, 2021, for a partial list). In addition, the recent history of the internet has shown how new technology can cause harm in unexpected ways. The online community of the eighties and early nineties could hardly have predicted the proliferation of fake news, spam, online harassment, fraud, cyberbullying, incel culture, political manipulation, doxxing, online radicalization, and revenge porn.
生存风险:人类面临的主要生存风险均源自技术。气候变化由工业化推动。核武器源于物理学研究。由于交通、农业和建筑方面的创新使人口规模更大、密度更高、联系更紧密,疫情更有可能发生并传播得更快。人工智能带来了新的生存风险。在构建比人类能力更强、可扩展性更高的系统时,我们应当格外谨慎。在最乐观的情况下,它会将巨大权力交到所有者手中。在最悲观的情况下,我们将无法控制它,甚至无法理解其动机(参见 Tegmark, 2018)。
这份清单远非详尽。人工智能还可能助长监控、虚假信息、侵犯隐私、欺诈以及操纵金融市场,而训练人工智能系统所需的能源也会加剧气候变化。此外,这些担忧并非空穴来风;已经有许多伦理可疑的人工智能应用实例(可参见 Dao, 2021 中的部分清单)。另外,互联网的近期历史表明,新技术可能以出人意料的方式造成伤害。 20 世纪 80 年代和 90 年代初的网络社区几乎无法预料到假新闻、垃圾信息、网络骚扰、欺诈、网络霸凌、非自愿单身者(incel)文化、政治操纵、人肉搜索、网络激进化以及报复色情的泛滥。
Everyone studying or researching (or writing books about) AI should contemplate to what degree scientists are accountable for the uses of their technology. We should consider that capitalism primarily drives the development of AI and that legal advances and deployment for social good are likely to lag significantly behind. We should reflect on whether it’s possible, as scientists and engineers, to control progress in this field and to reduce the potential for harm. We should consider what kind of organizations we are prepared to work for. How serious are they in their commitment to reducing the potential harms of AI? Are they simply “ethics-washing” to reduce reputational risk, or do they actually implement mechanisms to halt ethically suspect projects?
All readers are encouraged to investigate these issues further.
The online course at https://ethics-of-ai.mooc.fi/ is a useful introductory resource. If you are a professor teaching from this book, you are encouraged to raise these issues with your students. If you are a student taking a course where this is not done, then lobby your professor to make this happen. If you are deploying or researching AI in a corporate environment, you are encouraged to scrutinize your employer’s values and to help change them (or leave) if they are wanting.
所有学习或研究(或撰写相关书籍)人工智能的人都应当思考:科学家在多大程度上需要为其技术的用途负责。我们应当认识到,人工智能的发展主要由资本主义驱动,而法律进步以及面向公共利益的技术部署很可能远远滞后。我们应当反思,作为科学家和工程师,是否有可能控制这一领域的进展并减少潜在危害。我们应当考虑自己准备为怎样的机构工作。它们在减少人工智能潜在危害方面的承诺有多认真?它们是否只是在通过“伦理洗白”来降低声誉风险,还是真正建立了机制以中止存在伦理疑点的项目?
鼓励所有读者进一步研究这些问题。在线课程位于 https://ethics-of-ai.mooc.fi/ 是一份有用的入门资源。如果你是使用本书授课的教授,鼓励你与学生讨论这些问题。如果你正在修读一门未涉及这些问题的课程,请游说你的教授促成此事。如果你在企业环境中部署或研究 AI,鼓励你仔细审视雇主的价值观,并在这些价值观有所欠缺时帮助改变它们(或离开)。
The structure of the book follows the structure of this introduction. Chapters 2–9 walk through the supervised learning pipeline. We describe shallow and deep neural networks and discuss how to train them and measure and improve their performance.
Chapters 10–13 describe common architectural variations of deep neural networks, including convolutional networks, residual connections, and transformers. These architectures are used across supervised, unsupervised, and reinforcement learning.
本书的结构与本引言的结构一致。第 2–9 章逐步介绍监督学习流程。我们描述浅层和深层神经网络,并讨论如何训练它们、衡量并提升其性能。第 10–13 章介绍深层神经网络的常见架构变体,包括卷积网络、残差连接和 Transformer 模型。这些架构应用于监督学习、无监督学习和强化学习。
Chapters 14–18 tackle unsupervised learning using deep neural networks. We devote a chapter each to four modern deep generative models: generative adversarial networks, variational autoencoders, normalizing flows, and diffusion models. Chapter 19 is a brief introduction to deep reinforcement learning. This is a topic that easily justifies its own book, so the treatment is necessarily superficial. However, this treatment is intended to be a good starting point for readers unfamiliar with this area.
Despite the title of this book, some aspects of deep learning remain poorly understood. Chapter 20 poses some fundamental questions. Why are deep networks so easy to train? Why do they generalize so well? Why do they need to be so large? Do they need to be deep? Along the way, we explore unexpected phenomena such as the structure of the loss function, double descent, grokking, and lottery tickets. The book concludes with chapter 21, which discusses ethics and deep learning.
第 14–18 章探讨利用深层神经网络的无监督学习。我们分别用一章介绍四种现代深度生成模型:生成对抗网络、变分自编码器、归一化流和扩散模型。第 19 章是对深度强化学习的简要介绍。这一主题足以单独成书,因此这里的论述难免浅显。不过,这一论述旨在为不熟悉该领域的读者提供一个良好的起点。
尽管本书标题如此,深度学习的某些方面仍未被充分理解。第 20 章提出了一些基本问题。为什么深层网络如此容易训练?为什么它们泛化能力如此强?为什么它们需要如此庞大?它们需要很深吗?在此过程中,我们探讨了诸如损失函数的结构、双下降、顿悟和彩票票券等意想不到的现象。本书以第 21 章作结,讨论伦理与深度学习。
This book is self-contained but is limited to coverage of deep learning. It is intended to be the spiritual successor to Deep Learning (Goodfellow et al., 2016) which is a fantastic resource but does not cover recent advances. For a broader look at machine learning, the most up-to-date and encyclopedic resource is Probabilistic Machine Learning (Murphy, 2022, 2023). However, Pattern Recognition and Machine Learning (Bishop, 2006) is still an excellent and relevant book.
If you enjoy this book, then my previous volume, Computer Vision: Models, Learning, and Inference (Prince, 2012), is still worth reading. Some parts have dated badly, but it contains a thorough introduction to probability, including Bayesian methods, and good introductory coverage of latent variable models, geometry for computer vision, Gaussian processes, and graphical models. It uses identical notation to this book and can be found online. A detailed treatment of graphical models can be found in Probabilistic Graphical Models: Principles and Techniques (Koller & Friedman, 2009), and Gaussian processes are covered by Gaussian Processes for Machine Learning (Williams & Rasmussen, 2006). For background mathematics, consult Mathematics for Machine Learning (Deisenroth et al., 2020). For a more coding-oriented approach, consult Dive into Deep Learning (Zhang et al., 2023). The best overviews for computer vision are Computer Vision: Algorithms and Applications (Szeliski, 2022), and Foundations of Computer Vision (Torralba et al., 2024). A good starting point to learn about graph neural networks is Graph Representation Learning (Hamilton, 2020). The definitive work on reinforcement learning
本书自成体系,但仅涵盖深度学习。它旨在作为深度学习(Goodfellow 等, 2016)的精神续作;该书是一份极佳的资源,但未涵盖最新进展。若要更全面地看待机器学习,最新且最具百科性的资源是概率机器学习(Murphy, 2022, 2023)。不过,模式识别与机器学习(Bishop, 2006)仍然是一本出色且切题的书。
如果你喜欢本书,那么我之前的著作计算机视觉:模型、学习与推断(Prince, 2012)仍然值得一读。其中一些部分已经严重过时,但它对概率论进行了全面介绍,包括贝叶斯方法,并对隐变量模型、计算机视觉中的几何、高斯过程和图模型给出了良好的入门性介绍。它使用与本书完全相同的记号,且可在网上找到。关于图模型的详细论述可在概率图模型:原理与技术(Koller 与 Friedman, 2009)中找到,高斯过程则由机器学习中的高斯过程(Williams 与 Rasmussen, 2006)涵盖。如需了解基础数学,请参考机器学习中的数学(Deisenroth 等人, 2020)。若想采用更偏重编程的方法,请参考动手学深度学习(Zhang 等人, 2023)。计算机视觉领域最好的综述是计算机视觉:算法与应用(Szeliski, 2022)和计算机视觉基础(Torralba 等人, 2024)。学习图神经网络的良好起点是图表示学习(Hamilton, 2020)。关于强化学习的权威著作
is Reinforcement Learning: An Introduction (Sutton & Barto, 2018).
A good initial resource is Foundations of Deep Reinforcement Learning (Graesser & Keng, 2019).
是强化学习:导论(Sutton 和 Barto, 2018)。一个良好的入门资源是深度强化学习基础(Graesser 和 Keng, 2019)。
Most remaining chapters in this book contain a main body of text, a notes section, and a set of problems. The main body of the text is intended to be self-contained and can be read without recourse to the other parts of the chapter. As much as possible, background mathematics is incorporated into the main body of the text. However, for larger topics that would be a distraction to the main thread of the argument, the background material is appendicized, and a reference is provided in the margin. Most notation in this book is standard. However, some conventions are less widely used, and the reader is encouraged
本书其余各章大多包含正文、注释部分和一组习题。正文旨在自成一体,阅读时无需参考本章的其他部分。背景数学知识尽可能被纳入正文。然而,对于较大的主题,如果纳入正文会干扰论证主线,则将这些背景材料放入附录,并在页边提供引用。大多数符号在本书中是标准的。然而,有些约定使用得不太广泛,建议读者在继续阅读前先查阅附录 A。
to consult appendix A before proceeding.
The main body of text includes many novel illustrations and visualizations of deep learning models and results. I’ve worked hard to provide new explanations of existing ideas rather than merely curate the work of others. Deep learning is a new field, and sometimes phenomena are poorly understood. I try to make it clear where this is the case and when my explanations should be treated with caution.
References are included in the main body of the chapter only where results are depicted. Instead, they can be found in the notes section at the end of the chapter. I do not generally respect historical precedent in the main text; if an ancestor of a current technique is no longer useful, then I will not mention it. However, the historical development of the field is described in the notes section, and hopefully, credit is fairly assigned. The notes are organized into paragraphs and provide pointers for further reading. They should help the reader orient themselves within the sub-area and understand how it relates to other parts of machine learning. The notes are less self-contained than the main text. Depending on your level of background knowledge and interest, you may find these sections more or less useful. Each chapter has a number of associated problems. They are referenced in the margin of the main text at the point that they should be attempted. As George Pólya noted, “Mathematics, you see, is not a spectator sport.” He was correct, and I highly recommend that you attempt the problems as you go. In some cases, they provide insights that will help you understand the main text. Problems for which the answers are provided on the associated website (http://udlbook.com) are indicated with an asterisk. Additionally, Python notebooks that will help you understand the ideas in this book are also available via the website, and these are also referenced in the margins of the text. Indeed, if If you are feeling rusty, it might be worth working through the notebook on background mathematics right now.
正文包含许多关于深度学习模型和结果的新颖插图与可视化。我努力对已有观点提供新的解释,而非仅仅整理他人的工作。深度学习是一个新领域,有时现象尚未被充分理解。我尽量明确说明哪些情况确实如此,以及我的解释应在何时谨慎对待。
正文中只在展示结果之处包含参考文献;否则,可在每章末尾的注释部分找到它们。我通常不会在正文中遵循历史先例;如果当前技术的某个前身已不再有用,我就不会提及它。不过,该领域的历史发展会在注释部分中描述,并且我希望能够公允地给予应有的功劳。注释按段落组织,并为进一步阅读提供指引。它们应有助于读者在子领域中定位自己,并理解它与其他机器学习部分的关系。注释不如正文那样独立完整。根据背景知识和兴趣水平的不同,你可能会觉得这些章节更有用或更没用。每章都有若干相关习题。它们会在正文页边空白处被引用,并标明应在何处尝试解答。正如乔治 · 波利亚所说,“数学并不是旁观者的运动。”他说得对,我强烈建议你边阅读边尝试这些习题。在某些情况下,它们能为你提供有助于理解正文的洞见。答案在相关网站(http://udlbook.com)上给出的习题会以星号标出。此外,帮助你理解本书思想的 Python 笔记本也可通过该网站获取,并且同样在正文页边空白处有引用。事实上,如果
Unfortunately, the pace of research in AI makes it inevitable that this book will be a constant work in progress. If there are parts you find hard to understand, notable omissions, or sections that seem extraneous, please get in touch via the associated website. Together, we can make the next edition better.
如果你觉得生疏,不妨现在通读关于背景数学的笔记本。
不幸的是,人工智能研究进展迅速,这使得本书不可避免地成为一部持续修订的作品。如果您发现某些部分难以理解、存在明显遗漏,或某些章节显得多余,请通过相关网站与我们联系。我们可以一起让下一版更好。