学习资料 理解深度学习 第 4 章 · 深度神经网络
学 习 资 料 · 中 英 对 照

第 4 章 · 深度神经网络

Understanding Deep Learning — Deep neural networks

深层神经网络
Deep neural networks

The last chapter described shallow neural networks, which have a single hidden layer. This chapter introduces deep neural networks, which have more than one hidden layer. With ReLU activation functions, both shallow and deep networks describe piecewise linear mappings from input to output.

As the number of hidden units increases, shallow neural networks improve their descriptive power.

Indeed, with enough hidden units, shallow networks can describe arbitrarily complex functions in high dimensions. However, it turns out that for some functions, the required number of hidden units is impractically large. Deep networks can produce many more linear regions than shallow networks for a given number of parameters. Hence, from a practical standpoint, they can be used to describe a broader family of functions.

上一章描述了浅层神经网络,它们只有一个隐藏层。本章介绍深层神经网络,它们有不止一个隐藏层。使用 ReLU 激活函数时,浅层和深层网络都描述了从输入到输出的分段线性映射。

随着隐藏单元数量的增加,浅层神经网络的描述能力会增强。事实上,只要有足够多的隐藏单元,浅层网络就能描述高维空间中任意复杂的函数。然而,事实证明,对于某些函数,所需的隐藏单元数量大得不切实际。在给定参数数量的情况下,深层网络能够产生比浅层网络多得多的线性区域。因此,从实际角度来看,它们可用于描述更广泛的函数族。

4.1 组合神经网络
4.1 Composing neural networks

To gain insight into the behavior of deep neural networks, we first consider composing two shallow networks so the output of the first becomes the input of the second. Consider two shallow networks with three hidden units each (figure 4.1a). The first network takes an input x and returns output y and is defined by: and

为了深入了解深层神经网络的行为,我们首先考虑将两个浅层网络组合起来,使第一个网络的输出成为第二个网络的输入。考虑两个浅层网络,每个网络有三个隐藏单元(图 4.1a)。第一个网络接受输入 x 并回报输出 y,定义如下: and

The second network takes y as input and returns y′ and is defined by: and With ReLU activations, this model also describes a family of piecewise linear functions. However, the number of linear regions is potentially greater than for a shallow network with six hidden units. To see this, consider choosing the first network to produce three alternating regions of positive and negative slope (figure 4.1b). This means that three different ranges of x are mapped to the same output range y∈[−1, 1], and the subsequent mapping from this range of y to y′ is applied three times. The overall effect is that the function defined by the second network is duplicated three times to create nine linear

第二个网络接受 y 作为输入并回报 y′,定义如下: and使用 ReLU 激活函数时,该模型同样描述了一族分段线性函数。然而,其线性区域的数量可能多于具有六个隐藏单元的浅层网络。要理解这一点,可以考虑选择第一个网络来产生三个正负斜率交替的区域(图 4.1b)。这意味着 x 的三个不同范围被映射到同一个输出范围 y∈[−1, 1],并且随后从 y 的这一范围到 y′ 的映射会重复应用三次。总体效果是

图 4.1 组合两个各含三个隐藏单元的单层网络。 a) 输出 y 构成第二个网络的输入。 b) 第一个网络将输入 x ∈[−1, 1] 映射为输出 y∈[−1,
图 4.1 组合两个各含三个隐藏单元的单层网络。 a) 输出 y 构成第二个网络的输入。 b) 第一个网络将输入 x ∈[−1, 1] 映射为输出 y∈[−1, 1],该函数包含三个线性区域,这些区域的选择使得其斜率符号交替变化(第四个线性区域位于图形范围之外)。多个输入 x (灰色圆圈)现在映射到同一输出 y (青色圆圈)。 c) 第二个网络定义了一个包含三个线性区域的函数,该函数接收 y 并回报 y′ (即青色圆圈被映射到棕色圆圈)。 d) 这两个函数组合后的综合效果是: (i) 三个不同的输入 x 被第一个网络映射到 y 的任一给定值,并且 (ii) 被第二个网络以相同方式处理;结果是,面板 (c) 中第二个网络定义的函数被复制了三次,并根据面板 (b) 中各区域的斜率进行不同的翻转和缩放。(交互图)Figure 4.1 Composing two single-layer networks with three hidden units each. a) The output y of the first network constitutes the input to the second network. b) The first network maps inputs x ∈[−1, 1] to outputs y∈[−1, 1] using a function comprising three linear regions that are chosen so that they alternate the sign of their slope (fourth linear region is outside range of graph). Multiple inputs x (gray circles) now map to the same output y (cyan circle). c) The second network defines a function comprising three linear regions that takes y and returns y′ (i.e., the cyan circle is mapped to the brown circle). d) The combined effect of these two functions when composed is that (i) three different inputs x are mapped to any given value of y by the first network and (ii) are processed in the same way by the second network; the result is that the function defined by the second network in panel (c) is duplicated three times, variously flipped and rescaled according to the slope of the regions of panel (b). (Interactive figure)

regions. The same principle applies in higher dimensions (figure 4.2).

A different way to think about composing networks is that the first network “folds” the input space x back onto itself so that multiple inputs generate the same output. Then the second network applies a function, which is replicated at all points that were folded on top of one another (figure 4.3).

另一种思考组合网络的方式是,第一个网络将输入空间 x 折回自身,使得多个输入产生相同的输出。然后,第二个网络应用一个函数,该函数在所有被折叠到一起的点上被复制(图 4.3)。

4.2 从组合网络到深度网络
4.2 From composing networks to deep networks

The previous section showed that we could create complex functions by passing the output of one shallow neural network into a second network. We now show that this is a special case of a deep network with two hidden layers.

The output of the first network (y=ϕ0 + ϕ1h1 + ϕ2h2 + ϕ3h3) is a linear combination of the activations at the hidden units. The first operations of the second network (equation 4.3 in which we calculate θ′ the output of the first network. Applying one linear function to another yields another linear function. Substituting the expression for y into equation 4.3 gives:

上一节表明,我们可以将第一个浅层神经网络的输出传入第二个网络,从而创建复杂函数。我们现在说明,这是具有两个隐藏层的深度网络的一种特殊情况。

第一个网络(y=ϕ0 + ϕ1h1 + ϕ2h2 + ϕ3h3)的输出是隐藏单元激活值的线性组合。第二个网络的最初几步运算(在方程 4.3 中计算 θ′ 对第一个网络的输出是线性的。将一个线性函数作用于另一个线性函数会得到另一个线性函数。将 y 的表达式代入方程 4.3 得到:

我们可以将其改写为:由此可知,具有两层的网络可以表示将一个单层网络的输出传入另一个单层网络所产生的函数族。实际上,它表示一个更广泛的函数族,因为在公式 4.6 中,九个斜率参数 ψ11, ψ21,..., ψ33 可以取任意值,而在公式 4.5 中,这些参数被约束为外积

which we can rewrite as:

图 4.2 用二维输入组合神经网络。 a) 第一个网络(来自图 3.8)有三个隐藏单元,接收两个输入  x1 和  x2,并回报一个标量输出 y。该输出被传入一
图 4.2 用二维输入组合神经网络。 a) 第一个网络(来自图 3.8)有三个隐藏单元,接收两个输入 x1 和 x2,并回报一个标量输出 y。该输出被传入一个具有两个隐藏单元的第二个网络,以产生 y′。 b) 第一个网络产生一个由七个线性区域组成的函数,其中一个是平坦区域。 c) 第二个网络定义了一个在 y∈[−1, 1] 中由两个线性区域组成的函数。 d) 当这些网络组合时,第一个网络的六个非平坦区域中的每个区域都被第二个网络分成两个新区域,从而总共创建 13 个线性区域。Figure 4.2 Composing neural networks with a 2D input. a) The first network (from figure 3.8) has three hidden units and takes two inputs x1 and x2 and returns a scalar output y. This is passed into a second network with two hidden units to produce y′. b) The first network produces a function consisting of seven linear regions, one of which is flat. c) The second network defines a function comprising two linear regions in y∈[−1, 1]. d) When these networks are composed, each of the six non-flat regions from the first network is divided into two new regions by the second network to create a total of 13 linear regions.
图 4.3 将深度网络视为折叠输入空间。 a) 理解图 4.1 中第一个网络的一种方式是,它将输入空间“折叠”回自身之上。 b) 第二个网络将其函数应用于折叠后
图 4.3 将深度网络视为折叠输入空间。 a) 理解图 4.1 中第一个网络的一种方式是,它将输入空间“折叠”回自身之上。 b) 第二个网络将其函数应用于折叠后的空间。 c) 最终输出通过再次“展开”而显现。Figure 4.3 Deep networks as folding input space. a) One way to think about the first network from figure 4.1 is that it “folds” the input space back on top of itself. b) The second network applies its function to the folded space. c) The final output is revealed by “unfolding” again.
图 4.4 具有一个输入、一个输出和两个隐藏层的神经网络,每个隐藏层包含三个隐藏单元。(图 4.4)。
图 4.4 具有一个输入、一个输出和两个隐藏层的神经网络,每个隐藏层包含三个隐藏单元。(图 4.4)。Figure 4.4 Neural network with one input, one output, and two hidden layers, each containing three hidden units.

where ψ10=θ′ with two hidden layers (figure 4.4). It follows that a network with two layers can represent the family of functions created by passing the output of one single-layer network into another. In fact, it represents a broader family because in equation 4.6, the nine slope parameters ψ11, ψ21,..., ψ33 can take arbitrary values, whereas, in equation 4.5, these parameters are constrained to be the outer product[θ′

公式
4.3 深度神经网络
4.3 Deep neural networks

In the previous section, we showed that composing two shallow networks yields a special case of a deep network with two hidden layers. Now we consider the general case of a deep network with two hidden layers, each containing three hidden units (figure 4.4). The first layer is defined by:

the second layer by:

在上一节中,我们证明了组合两个浅层网络会得到一个具有两个隐藏层的深度网络的特殊情况。现在,我们考虑具有两个隐藏层(每个隐藏层包含三个隐藏单元)的深度网络的一般情况(图 4.4)。第一层定义如下:

第二层由:

and the output by: Considering these equations leads to another way to think about how the network con-

以及输出为:考虑这些方程,可以引出另一种思考网络如何计算的方式

structs an increasingly complicated function (figure 4.5): 1. The three hidden units h1, h2, and h3 in the first layer are computed as usual by forming linear functions of the input and passing these through ReLU activation

functions (equation 4.7). 2. The pre-activations at the second layer are computed by taking three new linear functions of these hidden units (arguments of the activation functions in equa- tion 4.8). At this point, we effectively have a shallow network with three outputs; we have computed three piecewise linear functions with the “joints” between linear

构造出越来越复杂的函数(图 4.5): 1. 第一层中的三个隐藏单元 h1, h2,和 h3 按常规方式计算:先根据输入构造线性函数,再将这些线性函数通过 ReLU 激活函数(公式 4.7)。 2. 第二层的预激活值通过对这些隐藏单元取三个新的线性函数来计算(公式 4.8 中激活函数的自变量)。此时,我们实际上得到了一个具有三个输出的浅层网络;我们已经计算出了三个分段线性函数,其线性区域之间的“连接点”位于相同位置(见图 3.6)。 3. 在第二隐藏层,对每个函数应用另一个 ReLU 函数 a[•] (公式 4.8),从而截断它们并为每个函数添

regions in the same places (see figure 3.6). 3. At the second hidden layer, another ReLU function a[•] is applied to each function

(equation 4.8), which clips them and adds new “joints” to each.

4. The final output is a linear combination of these hidden units (equation 4.9).

加新的“连接点”。 4. 最终输出是这些隐藏单元的线性组合(公式 4.9)。

In conclusion, we can either think of each layer as “folding” the input space or as creating new functions, which are clipped (creating new regions) and then recombined. The former view emphasizes the dependencies in the output function but not how clipping creates new joints, and the latter has the opposite emphasis. Ultimately, both descriptions provide only partial insight into how deep neural networks operate. Regardless, it’s important not to lose sight of the fact that this is still merely an equation relating input x to output y′. Indeed, we can combine equations 4.7–4.9 to get one expression:

although this is admittedly rather difficult to understand.

总之,我们可以将每一层视为对输入空间的“折叠”,或者视为创建新的函数,这些函数经过裁剪(形成新的区域)后再重新组合。前一种视角强调输出函数中的依赖关系,但没有强调裁剪如何形成新的接缝,后一种视角则相反。归根结底,这两种描述都只能让我们部分理解深层神经网络如何运作。无论如何,重要的是不要忽视这样一个事实:这仍然只是将输入 x 与输出 y′ 联系起来的方程。实际上,我们可以将公式 4.7–4.9 合并为一个表达式:

尽管这确实相当难以理解。

4.3.1 超参数
4.3.1 Hyperparameters

We can extend the deep network construction to more than two hidden layers; modern networks might have more than a hundred layers with thousands of hidden units at each layer. The number of hidden units in each layer is referred to as the width of the network, and the number of hidden layers as the depth. The total number of hidden units is a measure of the network’s capacity. We denote the number of layers as K and the number of hidden units in each layer as D1, D2,..., DK. These are examples of hyperparameters. They are quantities chosen

before we learn the model parameters (i.e., the slope and intercept terms). For fixed hyperparameters (e.g., K=2 layers with Dk=3 hidden units in each), the model describes a family of functions, and the parameters determine the particular function. Hence, when we also consider the hyperparameters, we can think of neural networks as representing a family of families of functions relating input to output.

我们可以将深层网络构造扩展到两个以上的隐藏层;现代网络可能有上百层,每层有数千个隐藏单元。每层隐藏单元的数量称为网络的宽度,隐藏层的数量称为深度。隐藏单元的总数是衡量网络容量的指标。

在我们学习模型参数之前(即斜率和截距项)。对于固定的超参数(例如, K=2 层且每层 Dk=3 个隐藏单元),模型描述一个函数族,而参数决定特定函数。因此,当我们同时考虑超参数时,可以将神经网络视为表示将输入映射到输出的函数族的族。

图 4.5 图 4.4 中深度网络的计算过程。 a–c) 第二个隐藏层的输入(即预激活值)是三个分段线性函数,其线性区域之间的“拐点”位于相同位置(见图 3.6
图 4.5 图 4.4 中深度网络的计算过程。 a–c) 第二个隐藏层的输入(即预激活值)是三个分段线性函数,其线性区域之间的“拐点”位于相同位置(见图 3.6)。 d–f) 每个分段线性函数都被 ReLU 激活函数截断为零。 g–i) 这些截断后的函数随后分别乘 3。 j) 最后,将截断并加权后的函数求和,并添加一个偏移量Figure 4.5 Computation for the deep network in figure 4.4. to the second hidden layer (i.e., the pre-activations) are three piecewise linear functions where the “joints” between the linear regions are at the same places (see figure 3.6). d–f) Each piecewise linear function is clipped to zero by the ReLU activation function. g–i) These clipped functions are then weighted with parameters ϕ′ 3, respectively. functions are summed and an offset ϕ′ (Interactive figure) a–c) The inputs j) Finally, the clipped and weighted 0 that controls the overall height is added.
公式
4.4 矩阵表示
4.4 Matrix notation

We have seen that a deep neural network consists of linear transformations alternating with activation functions. We could equivalently describe equations 4.7–4.9 in matrix

我们已经看到,深层神经网络由交替的线性变换组成

带有激活函数。我们可以等价地将公式 4.7–4.9 用矩阵表示法描述为: and

notation as: and

图 4.6 具有  Di= 3 维输入 x、 Do= 2 维输出 y,以及 K=3 个隐藏层 h 1,、 h 2, 和 h 3,其维度分别为 D1= 4、 D2
图 4.6 具有 Di= 3 维输入 x、 Do= 2 维输出 y,以及 K=3 个隐藏层 h 1,、 h 2, 和 h 3,其维度分别为 D1= 4、 D2= 2 和 D3= 3。权重存储在矩阵 Ω k 中,这些矩阵乘以来自前一层的激活值,以生成后续层的预激活值。例如,权重矩阵 Ω 1 计算 h 2 处的预激活值,这些预激活值由 h 1 处的激活值计算得到,其维度为 2×4。它被应用于第一层中的四个隐藏单元,并生成第二层中两个隐藏单元的输入。偏差存储在向量 βk 中,其维度等于它们所馈入层的维度。例如,偏差向量 β2 的长度为三,因为层 h 3 包含三个隐藏单元。Figure 4.6 Matrix notation for network with Di= 3 -dimensional input x, Do= 2 dimensional output y, and K=3 hidden layers h 1, h 2, and h 3 of dimensions D1= 4, D2= 2, and D3= 3 respectively. The weights are stored in matrices Ω k that multiply the activations from the preceding layer to create the pre-activations at the subsequent layer. For example, the weight matrix Ω 1 that computes the pre-activations at h 2 from the activations at h 1 has dimension 2×4. It is applied to the four hidden units in layer one and creates the inputs to the two hidden units at layer two. The biases are stored in vectors βk and have the dimension of the layer into which they feed. For example, the bias vector β2 is length three because layer h 3 contains three hidden units.

or even more compactly in matrix notation as:

where, in each case, the function a[•] applies the activation function separately to every element of its vector input.

或者更简洁地用矩阵表示法表示为:

其中,在每种情况下,函数 a[•] 分别对其向量输入的每个元素应用激活函数。

4.4.1 一般形式
4.4.1 General formulation

This notation becomes cumbersome for networks with many layers. Hence, from now on, we will describe the vector of hidden units at layer k as h k, the vector of biases (intercepts) that contribute to hidden layer k+1 as βk, and the weights (slopes) that are applied to the kth layer and contribute to the(k+1)th layer as Ω k. A general deep network y = f[ x , ϕ] with K layers can now be written as: If the kth layer has Dk hidden units, then the bias vector βk−1 will be of size Dk. The last bias vector βK has the size Do of the output. The first weight matrix Ω 0 has size D1 × Di where Di is the size of the input. The last weight matrix Ω K is Do × DK,

对于层数较多的网络,这种记法会变得繁琐。因此,从现在起,我们将第 k 层的隐藏单元向量表示为 h k,将对隐藏层 k+1 有贡献的偏差(截距)向量表示为 βk,并将作用于第 kth 层、对第 (k+1) th 层有贡献的权重(斜率)表示为 Ω k。现在,一个具有 K 层的一般深层神经网络 y = f[ x ϕ] 可以写成:该模型的参数 ϕ 由所有这些权重矩阵和偏差向量 ϕ = {βk, Ω k}K

k=0 组成。

and the remaining matrices Ω k are Dk+1 × Dk (figure 4.6).

We can equivalently write the network as a single function:

我们可以将网络等价地表示为单一函数:

4.5 浅层与深层神经网络
4.5 Shallow vs. deep neural networks

Chapter 3 discussed shallow networks (with a single hidden layer), and here we have described deep networks (with multiple hidden layers). We now compare these models.

第 3 章讨论了浅层网络(只有一个隐藏层),而这里我们介绍了深层网络(有多个隐藏层)。现在我们来比较这些模型。

4.5.1 逼近不同函数的能力
4.5.1 Ability to approximate different functions

In section 3.2, we argued that shallow neural networks with enough capacity (hidden units) could model any continuous function arbitrarily closely. In this chapter, we saw that a deep network with two hidden layers could represent the composition of two shallow networks. If the second of these networks computes the identity function, then this deep network replicates a single shallow network. Hence, it can also approximate any continuous function arbitrarily closely given sufficient capacity.

在第 3.2 节中,我们论证了具有足够容量(隐藏单元)的浅层神经网络可以任意接近地模拟任何连续函数。在本章中,我们看到具有两个隐藏层的深层网络可以表示两个浅层网络的复合。如果这些网络中的第二个计算恒等函数,那么该深层网络就复现了单个浅层网络。因此,在容量足够的情况下,它也可以任意接近地逼近任何连续函数。

4.5.2 每个参数的线性区域数量
4.5.2 Number of linear regions per parameter

A shallow network with one input, one output, and D>2 hidden units can create up to D + 1 linear regions and is defined by 3D + 1 parameters. A deep network with one

input, one output, and K layers of D> 2 hidden units can create a function with up to (D + 1)K linear regions using 3D + 1 + (K −1)D(D + 1) parameters.

Figure 4.7a shows how the maximum number of linear regions increases as a function of the number of parameters for networks mapping scalar input x to scalar output y. Deep neural networks create much more complex functions for a fixed parameter budget. This effect is magnified as the number of input dimensions Di increases (figure 4.7b), although computing the maximum number of regions is less straightforward.

This seems attractive, but the flexibility of the functions is still limited by the number of parameters. Deep networks can create extremely large numbers of linear regions, but these contain complex dependencies and symmetries. We saw some of these when we considered deep networks as “folding” the input space (figure 4.3). So, it’s not clear that the greater number of regions is an advantage unless (i) there are similar symmetries in the real-world functions that we wish to approximate or (ii) we have reason to believe that the mapping from input to output really does involve a composition of simpler functions.

图 4.7a 展示了对于将标量输入 x 映射到标量输出 y 的网络,线性区域的最大数量如何随参数数量而增加。在固定参数预算下,深层神经网络能创建复杂得多的函数。随着输入维度数量 Di 增加(图 4.7b),这种效应会被放大,尽管计算区域的最大数量不那么直接。

这似乎很有吸引力,但函数的灵活性仍然受参数数量的限制。深层网络可以创建极其大量的线性区域,但这些区域包含复杂的依赖关系和对称性。当我们把深层网络视为“折叠”输入空间时,已经看到其中一些(图 4.3)。因此,除非(i)我们想要逼近的现实世界函数中存在类似的对称性,或(ii)我们有理由相信从输入到输出的映射确实涉及较简单函数的复合,否则区域数量更多是否是一种优势并不明确。

4.5.3 深度效率
4.5.3 Depth efficiency

Both deep and shallow networks can model arbitrary functions, but some functions can be approximated much more efficiently with deep networks. Functions have been identified that require a shallow network with exponentially more hidden units to achieve an equivalent approximation to that of a deep network. This phenomenon is referred to as the depth efficiency of neural networks. This property is also attractive, but it’s not clear that the real-world functions that we want to approximate fall into this category.

深度网络和浅层网络都可以建模任意函数,但有些函数用深度网络可以更高效地近似。已经发现某些函数需要具有指数级更多隐藏单元的浅层网络,才能达到与深度网络相当的近似效果。这种现象被称为神经网络的深度效率。这一特性也很有吸引力,但目前尚不清楚我们想要近似的现实世界函数是否属于这一类。

4.5.4 大型、结构化输入
4.5.4 Large, structured inputs

We have discussed fully connected networks where every element of each layer contributes to every element of the subsequent one. However, these are not practical for large,

我们已经讨论了全连接网络,其中每一层的每个元素都对后续一层的每个元素作出贡献。然而,这些网络并不适用于大型,

图 4.7 神经网络的最大线性区域数量随网络深度迅速增加。 a) 具有 Di= 1 个输入的网络。每条曲线代表固定的隐藏层数  K,同时我们改变每层的隐藏单元数
图 4.7 神经网络的最大线性区域数量随网络深度迅速增加。 a) 具有 Di= 1 个输入的网络。每条曲线代表固定的隐藏层数 K,同时我们改变每层的隐藏单元数 D。在参数预算固定(横轴位置)时,深层网络比浅层网络产生更多线性区域。具有 K=5 层和每层 D=10 个隐藏单元的网络有 471 个参数(高亮点),可以产生 161,051 个区域。 b) 具有 Di= 10 个输入的网络。沿每条曲线的后续每个点代表十个隐藏单元。在此,具有 K= 5 层和每层 D= 50 个隐藏单元的模型有 10,801 个参数(高亮点),可以创建超过 1040 个线性区域。Figure 4.7 The maximum number of linear regions for neural networks increases rapidly with the network depth. a) Network with Di= 1 input. Each curve represents a fixed number of hidden layers K, as we vary the number of hidden units D per layer. For a fixed parameter budget (horizontal position), deeper networks produce more linear regions than shallower ones. A network with K=5 layers and D=10 hidden units per layer has 471 parameters (highlighted point) and can produce 161,051 regions. b) Network with Di= 10 inputs. Each subsequent point along a curve represents ten hidden units. Here, a model with K= 5 layers and D= 50 hidden units per layer has 10,801 parameters (highlighted point) and can create more than 1040 linear regions.

structured inputs like images, where the input might comprise ∼106 pixels. The number of parameters would be prohibitive, and moreover, we want different parts of the image to be processed similarly; there is no point in independently learning to recognize the same object at every possible position in the image.

The solution is to process local image regions in parallel and then gradually integrate information from increasingly large regions. This kind of local-to-global processing is difficult to specify without using multiple layers (see chapter 10).

像图像这样的结构化输入,其输入可能包含 ∼106 个像素。参数数量会高得难以承受,而且我们希望图像的不同部分以类似方式处理;在图像中每个可能位置独立学习识别同一物体是没有意义的。

解决方案是并行处理局部图像区域,然后逐步整合来自越来越大的区域的信息。如果不使用多层,这种局部到全局的处理很难加以规定(见第 10 章)。

4.5.5 训练与泛化
4.5.5 Training and generalization

A further possible advantage of deep networks over shallow networks is their ease of fitting; it is usually easier to train moderately deep networks than to train shallow ones (see figure 20.2). It may be that over-parameterized deep models (i.e., those with more parameters than training examples) have a large family of roughly equivalent solutions that are easy to find. However, as we add more hidden layers, training becomes more difficult again. Many methods have been developed to mitigate this problem (see chapter 11).

Deep neural networks also seem to generalize to new data better than shallow ones. In practice, the best results for most tasks have been achieved using networks with tens or hundreds of layers. Neither of these phenomena are well understood, and we return to them in chapter 20.

深度网络相对于浅层网络的一个可能的进一步优势是易于拟合;通常来说,训练中等深度的网络比训练浅层网络更容易(见图 20.2)。过参数化的深度模型(即参数数量多于训练样本数量的模型)可能拥有一大族大致等价的解,这些解很容易找到。然而,随着我们添加更多隐藏层,训练再次变得更困难。已经开发了许多方法来缓解这一问题(见第 11 章)。

深层神经网络似乎也比浅层网络更好地泛化到新数据。在实践中,大多数任务的最佳结果都是通过具有数十层或数百层的神经网络实现的。这些现象都没有被充分理解,我们将在第 20 章再次讨论它们。

4.6 小结
4.6 Summary

In this chapter, we first considered what happens when we compose two shallow networks. We argued that the first network “folds” the input space, and the second network then applies a piecewise linear function. The effects of the second network are duplicated where the input space is folded onto itself.

We then showed that this composition of shallow networks is a special case of a deep network with two layers. We interpreted the ReLU functions in each layer as clipping the input functions in multiple places and creating more “joints” in the output function. We introduced the idea of hyperparameters, which for the networks we’ve seen so far, comprise the number of hidden layers and the number of hidden units in each.

在本章中,我们首先考虑了组合两个浅层网络时会发生什么。我们提出,第一个网络“折叠”输入空间,第二个网络随后施加一个分段线性函数。在输入空间被折叠到自身的位置,第二个网络的效果会被复制。

随后我们证明了这种浅层网络的组合是两层深度网络的特例。我们将每层中的 ReLU 函数解释为在多个位置截断输入函数,并在输出函数中创建更多“关节”。我们引入了超参数的概念;就我们目前见过的网络而言,超参数包括隐藏层的数量和每层隐藏单元的数量。

Finally, we compared shallow and deep networks. We saw that (i) both networks can approximate any function given enough capacity, (ii) deep networks produce many more linear regions per parameter, (iii) some functions can be approximated much more efficiently by deep networks, (iv) large, structured inputs like images are best processed in multiple stages, and (v) in practice, the best results for most tasks are achieved using deep networks with many layers.

Now that we understand deep and shallow network models, we turn our attention to training them. In the next chapter, we discuss loss functions. For any given parameter values ϕ, the loss function returns a single number that indicates the mismatch between the model outputs and the ground truth predictions for a training dataset. In chapters 6 and 7, we deal with the training process itself, in which we seek the parameter values that minimize this loss.

最后,我们比较了浅层网络和深度网络。我们发现: (i) 在容量足够的情况下,两种网络都可以逼近任意函数; (ii) 深度网络每个参数能产生多得多的线性区域; (iii) 某些函数可以由深度网络更高效地逼近; (iv) 像图像这样的大型结构化输入最好分多个阶段处理; (v) 在实践中,大多数任务的最佳结果是通过具有许多层的深度网络取得的。

既然我们已经理解了深度网络和浅层网络模型,接下来我们将注意力转向训练它们。在下一章中,我们将讨论损失函数。对于任意给定的参数值 ϕ,损失函数会回报一个单一数字,用以指示模型输出与训练数据集的真值预测之间的不匹配。在第 6 章和第 7 章中,我们将处理训练过程本身,其中我们寻找使该损失最小化的参数值。

注释
Notes

Deep learning:

Number of linear regions:

公式

Universal approximation theorem:

Depth efficiency:

Width efficiency:

问题
Problems
图 4.8 问题 4.1 中两个网络的组合。 a)第一个网络的输出 y 成为第二个网络的输入。 b)第一个网络以输出值 y∈[−1, 1] 计算该函数。 c)第
图 4.8 问题 4.1 中两个网络的组合。 a)第一个网络的输出 y 成为第二个网络的输入。 b)第一个网络以输出值 y∈[−1, 1] 计算该函数。 c)第二个网络在输入范围 y∈[−1, 1] 上计算该函数。问题 4.3 利用 ReLU 函数的非负齐次性(见问题 3.5),证明: ReLU 其中 λ0 和 λ1 是非负标量。由此我们可以看出,只要偏差也相应调整,权重矩阵就可以按任意幅度重新缩放,并且缩放因子可以在网络末尾重新应用。问题 4.4 分别以方程 4.15 和 4.16 的形式,写出一个具有 Di= 5 个输入、 Do= 4 个输出以及大小分别为 D1=20、 D2=10 和 D3=7 的三个隐藏层的深层神经网络的方程。每个权重矩阵 Ω • 和偏差向量 β• 的大小是多少? 问题 4.5 考虑一个具有 Di=5 个输入、 Do=1 个输出和 K=20 个隐藏层的深层神经网络,每个隐藏层包含 D=30 个隐藏单元。该网络的深度是多少?宽度是多少? 问题 4.6 考虑一个具有 Di=1 个输入、 Do=1 个输出和 K=10 层的网络,其中每层有 D=10 个隐藏单元。如果我们将深度增加 1 或宽度增加 1,权重的数量会增加得更多吗?请给出你的理由。Figure 4.8 Composition of two networks for problem 4.1. a) The output y of the first network becomes the input to the second. b) The first network computes this function with output values y∈[−1, 1]. c) The second network computes this function on the input range y∈[−1, 1]. Problem 4.3 Using the non-negative homogeneity property of the ReLU function (see problem 3.5), show that: ReLU where λ0 and λ1 are non-negative scalars. From this, we see that the weight matrices can be rescaled by any magnitude as long as the biases are also adjusted, and the scale factors can be re-applied at the end of the network. Problem 4.4 Write out the equations for a deep neural network that takes Di= 5 inputs, Do= 4 outputs and has three hidden layers of sizes D1=20, D2=10, and D3=7, respectively, in both the forms of equations 4.15 and 4.16. What are the sizes of each weight matrix Ω • and bias vector β•? Problem 4.5 Consider a deep neural network with Di=5 inputs, Do=1 output, and K=20 hidden layers containing D= 30 hidden units each. What is the depth of this network? What is the width? Problem 4.6 Consider a network with Di=1 input, Do=1 output, and K=10 layers, with D=10 hidden units in each. Would the number of weights increase more if we increased the depth by one or the width by one? Provide your reasoning.
图 4.9 问题 4.8 的隐藏单元激活值。 a) 第一个隐藏单元在位置  x = 1/6 处有一个折点,在激活区域中的斜率为 1。 b) 第二个隐藏单元在位置
图 4.9 问题 4.8 的隐藏单元激活值。 a) 第一个隐藏单元在位置 x = 1/6 处有一个折点,在激活区域中的斜率为 1。 b) 第二个隐藏单元在位置 x=2/6 处有一个折点,在激活区域中的斜率为 1。 c) 第三个隐藏单元在位置 x = 4/6 处有一个折点,在激活区域中的斜率为 -1。问题 4.10 考虑一个具有单个输入、单个输出和 K 个隐藏层的深层神经网络,每个隐藏层包含 D 个隐藏单元。证明该网络总共有 3D + 1 + (K−1) D (D + 1) 个参数。问题 4。 11 ∗ 考虑两个神经网络,它们将标量输入 x 映射为标量输出 y。第一个网络是浅层神经网络,包含 D= 95 个隐藏单元。第二个网络是深层神经网络,包含 K= 10 层,每层包含 D=5 个隐藏单元。每个网络有多少个参数?每个网络可以形成多少个线性区域(见公式 4.17)?哪个运行更快?Figure 4.9 Hidden unit activations for problem 4.8. a) First hidden unit has a joint at position x = 1/6 and a slope of one in the active region. b) Second hidden unit has a joint at position x=2/6 and a slope of one in the active region. c) Third hidden unit has a joint at position x = 4/6 and a slope of minus one in the active region. Problem 4.10 Consider a deep neural network with a single input, a single output, and K hidden layers, each of which contains D hidden units. Show that this network will have a total Problem 4.11 ∗ Consider two neural networks that map a scalar input x to a scalar output y. The first network is shallow and has D= 95 hidden units. The second is deep and has K= 10 layers, each containing D=5 hidden units. How many parameters does each network have? How many linear regions can each network make (see equation 4.17)? Which would run faster?
公式