第 14 章 · 无监督学习
Understanding Deep Learning — Unsupervised learning
Chapters 2–9 walked through the supervised learning pipeline. We defined models that mapped observed data x to output values y and introduced loss functions that measured the quality of that mapping for a training dataset{ x i, y i}.
Then we discussed how to fit and measure the performance of these models. Chapters 10–13 introduced more sophisticated model architectures incorporating parameter sharing and allowing parallel computational paths.
The defining characteristic of unsupervised learning models is that they are learned from a set of observed data{ x i} in the absence of labels. All unsupervised models share this property, but they have diverse goals. They may be used to generate plausible new samples from the dataset or to manipulate, denoise, interpolate between, or compress examples. They can also be used to reveal the internal structure of a dataset (e.g., by dividing it into coherent clusters) or to distinguish whether new examples belong to the same dataset or are outliers. This chapter introduces a taxonomy of unsupervised learning models and then discusses the desirable properties of models and how to measure their performance. The four subsequent chapters discuss four particular models: generative adversarial networks (GANs), normalizing flows, variational autoencoders (VAEs), and diffusion models. 1
第 2–9 章讲解了监督学习流程。我们定义了将观测数据 x 映射到输出值 y 的模型,并引入了损失函数,以衡量该映射在训练数据集 { x i, y i} 上的质量。随后,我们讨论了如何拟合这些模型并衡量其性能。第 10–13 章介绍了更复杂的模型架构,这些架构包含参数共享并允许并行计算路径。
无监督学习模型的定义特征是:它们是在没有标签的情况下,从一组观测数据{ x i} 中学习得到的。所有无监督模型都具有这一特性,但目标各异。它们可用于从数据集中生成合理的新样本,也可用于对样本进行操纵、去噪、插值或压缩。它们还可用于揭示数据集的内部结构(例如将其划分为一致的簇),或区分新样本是否属于同一数据集或是离群点。本章介绍无监督学习模型的分类体系,然后讨论模型的理想属性以及如何衡量其性能。随后的四章讨论四种特定模型:生成对抗网络(GANs)、归一化流、变分自编码器(VAEs)和扩散模型。 1
无监督学习中的一种常见策略是在数据样本 x 与一组未见过的隐变量 z 之间定义映射。这些隐变量捕捉数据集中的底层结构,并且通常具有比原始数据更低的维度;在这个意义上,隐变量 z 可以被视为数据样本 x 的压缩版本,该版本捕捉了其本质特征(图 1.91.10)。
A common strategy in unsupervised learning is to define a mapping between the data examples x and a set of unseen latent variables z. These latent variables capture underlying structure in the dataset and usually have a lower dimension than the original data; in this sense, a latent variable z can be considered a compressed version of a data example x that captures its essential qualities (figures 1.9–1.10). In principle, the mapping between the observed and latent variables can be in either direction. Some models map from the data x to latent variables z. For example, the
famous k-means algorithm maps the data x to a cluster assignment z∈{1, 2,..., K}. Other models map from the latent variables z to the data x. Consider defining a distribution Pr( z ) over the latent variable z in these models. New examples can now be generated by (i) drawing from this distribution and (ii) mapping the sample to the data space x. Accordingly, these are termed generativemodels (see figure 14.1).
著名的 k-means 算法将数据 x 映射到聚类分配 z∈{1, 2,..., K}。其他模型则从隐变量 z 映射到数据 x。在这些模型中,可以考虑在隐变量 z 上定义一个分布 Pr (z)。现在可以生成新示例,方法是 (i) 从该分布中采样,并 (ii) 将样本映射到数据空间 x。因此,这些模型被称为生成模型(见图 14.1)。

The four models in chapters 15 to 18 are all generative models that use latent variables. Generativeadversarialnetworks (chapter 15) learn to generate data examples x ∗ from latent variables z, using a loss that encourages the generated samples to be indistinguishable from real examples (figure 14.2a).
Normalizing flows, variational autoencoders, and diffusion models (chapters 16–18) are probabilistic generative models. In addition to generating new examples, they assign a probability Pr( x |ϕ) to each data point x. This will depend on the model parameters ϕ, and in training, we maximize the probability of the observed data{ x i}, so the loss is the sum of the negative log-likelihoods (figure 14.2b): Since probability distributions must sum to one, this implicitly reduces the probability of examples that lie far from the observed data. As well as providing a training criterion, assigning probabilities is useful in its own right; the probability on a test set can be used to compare two models quantitatively, and the probability for an example can be thresholded to determine if it belongs to the same dataset or is an outlier. 2
第 15 至 18 章中的四个模型都是使用隐变量的生成模型。生成对抗网络(第 15 章)学习生成数据示例 x ∗,这些示例来自隐变量 z,并使用一种损失函数,使生成样本与真实示例无法区分(图 14.2a)。
归一化流、变分自编码器和扩散模型(第 16–18 章)是概率生成模型。除了生成新示例之外,它们还分配概率 Pr (x |ϕ) 给每个数据点 x。这取决于模型参数 ϕ,在训练过程中,我们最大化观测数据 { x i} 的概率,因此损失是负对数似然之和(图 14.2b):由于概率分布必须总和为一,这实际上降低了远离观测数据的样本的概率。除了提供训练准则外,赋予概率本身也很有用;测试集上的概率可用于定量比较两个模型,并且可以对样本的概率设置阈值,以判断它属于同一数据集还是异常值。 2
Generative models based on latent variables should have the following properties:
基于隐变量的生成模型应具备以下性质:
• Efficient sampling: Generating samples from the model should be computationally inexpensive and take advantage of the parallelism of modern hardware. • High-quality sampling: The samples should be indistinguishable from the real data with which the model was trained. • Coverage: Samples should represent the entire training distribution. It is insufficient to generate samples that all look like a subset of the training examples. • Well-behaved latent space: Every latent variable z corresponds to a plausible data example x. Smooth changes in z correspond to smooth changes in x. • Disentangled latent space: Manipulating each dimension of z should correspond to changing an interpretable property of the data. For example, in a model of language, it might change the topic, tense, or verbosity. • Efficient likelihood computation: If the model is probabilistic, we would like to be able to calculate the probability of new examples efficiently and accurately.
• 高效采样:从模型中生成样本应当计算开销低廉,并充分利用现代硬件的并行性。
• 高质量采样:生成的样本应与模型训练所用的真实数据难以区分。

• 覆盖性:样本应代表整个训练分布。仅生成看起来像训练示例子集的样本是不够的。
• 良好的隐空间:每个隐变量 z 都对应一个合理的数据示例 x。 z 中的平滑变化对应于 x 中的平滑变化。 • 解耦的潜空间:对 z 的每个维度进行操作,应能对应数据中可解释属性的变化。例如,在语言模型中,它可能改变主题、时态或冗长程度。
• 高效的似然计算:如果模型是概率模型,我们希望能够高效且准确地计算新样本的概率。
这自然引出了一个问题:我们所考虑的生成模型是否满足这些性质。答案具有主观性,但图 14.3 提供了指导。具体的归类可能存在争议,但大多数实践者都会同意,没有任何单一模型能够满足所有这些特征。


The previous section discussed the desirable properties of generative models. We now consider quantitative measures of success for generative models. Much experimentation with generative models has used images due to the widespread availability of that data and the ease of qualitatively judging the samples. Consequently, some of these metrics only apply to images.
Test likelihood:
One way to compare probabilistic models is to measure their likelihood for a test dataset. It is ineffective to measure the training data likelihood because a model could assign a very high probability to each training point and very low probabilities in between. This model would have a very high training likelihood but could only reproduce the training data. The test likelihood captures how well the model generalizes from the training data and also the coverage; if the model assigns a high probability to just a subset of the training data, it must assign lower probabilities elsewhere, so a portion of the test examples will have low probability.
上一节讨论了生成模型的期望性质。我们现在考虑生成模型成功程度的量化度量。由于图像数据广泛可得,并且对样本进行定性判断较为容易,许多生成模型实验都使用了图像。因此,其中一些指标仅适用于图像。
测试似然:比较概率模型的一种方法是测量它们在测试数据集上的似然。测量训练数据似然并不有效,因为模型可以为每个训练点赋予非常高的概率,而在训练点之间赋予非常低的概率。这样的模型会有非常高的训练似然,但只能复现训练数据。测试似然能够反映模型从训练数据泛化的能力以及覆盖范围;如果模型只为训练数据的一个子集赋予高概率,它就必须为其他地方赋予较低概率,因此一部分测试样本的概率会很低。
Test likelihood is a sensible way to quantify probabilistic models, but unfortunately, it is not relevant for generative adversarial models (which do not assign a probability) and is expensive to estimate for variational autoencoders and diffusion models (although it is possible to compute a lower bound on the log-likelihood). Normalizing flows are the only type of model for which the likelihood can be computed exactly and efficiently.
Inception score: The inception score (IS) is specialized for images and ideally for generative models trained on the ImageNet database. The score is calculated using a pretrained classification model – usually the “Inception” model, from which the name is derived. It is based on two criteria. First, each generated image x ∗ should look like one and only one of the 1000 possible classes y in the ImageNet database. Hence, the probability distribution Pr(y| x ∗
测试似然是量化概率模型的一种合理方式,但不幸的是,它不适用于生成对抗模型(它们不赋予概率),并且对于变分自编码器和扩散模型而言,估计成本很高(尽管可以计算对数似然的下界)。归一化流是唯一可以精确且高效计算似然的模型类型。 Inception 分数: Inception 分数(IS)专门用于图像,并且最适合用于在 I mageNet 数据库上训练的生成模型。该分数使用预训练的分类模型计算 —— 通常是“Inception”模型,其名称即由此而来。它基于两个标准。第一,每个生成的图像 x ∗ 应当看起来只像 ImageNet 数据库中 1000 个可能类别中的某一个 y。因此,概率分布
i) should be highly peaked at the correct class. Second, the entire set of generated images should be assigned to the classes with equal probability, so Pr(y) should be flat when averaged over all generated examples. The inception score measures the average distance between these two distributions over the generated set. This distance will be large if one is peaked and the other flat (figure 14.4). More precisely, it returns the exponential of the expected KL-divergence between Pr(y| x ∗
给各个类别,因此 Pr(y) 在所有生成样本上平均时应当是平坦的。 Inception 分数衡量生成集合上这两个分布之间的平均距离。如果一个是尖锐的,另一个是平坦的,则该距离会很大(图 14.4)。更准确地说,它回报的是期望的 KL 散度的指数


This metric is only sensible for generative models of the ImageNet database and is sensitive to the particular classification model; retraining this model can give quite different numerical results. Moreover, it does not reward diversity within an object class; it returns a high value if the model only generates one realistic example of each class.
Fréchet inception distance: This measure is also intended for images and computes a symmetric distance between the distributions of generated samples and real examples. This must be approximate since it is hard to characterize either distribution (indeed, characterizing the distribution of real examples is the job of generative models in the first place). Hence, the Fréchet inception distance approximates both distributions by multivariate Gaussians and (as the name suggests) estimates the distance between them
该指标仅对 ImageNet 数据库的生成模型有意义,并且对所用的分类模型敏感;重新训练该模型可能得到相当不同的数值结果。此外,它不会奖励同一对象类别内的多样性;如果模型仅为每个类别生成一个逼真的样本,它也会给出较高的值。弗雷歇初始距离:该度量同样适用于图像,并计算生成样本分布与真实样本分布之间的对称距离。由于很难刻画任一分布,这必然是近似的(事实上,刻画真实样本分布本来就是生成模型的任务)。因此,弗雷歇初始距离通过
using the Fréchet distance.
多元高斯分布,并且(顾名思义)估计它们之间的距离,使用的是 Fréchet 距离。
However, it does not model the distance with respect to the original data but rather the activations in the deepest layer of the inception classification network. These hidden units are the ones most associated with object classes, so the comparison occurs at a semantic level, ignoring the more fine-grained details of the images. This metric does take account of diversity within classes but relies heavily on the information retained by the features in the inception network; any information discarded by the network does not contribute to the result. Some of this discarded information may still be important to generate realistic samples.
Manifold precision/recall:
Fréchet inception distance is sensitive both to the realism of the samples and their diversity but does not distinguish between these factors. To disentangle these qualities, we consider the overlap between the data manifold (i.e., the subset of the data space where the real examples lie) and the model manifold (i.e., where the generated samples lie). The precision is the fraction of model samples that fall into the data manifold. This measures the proportion of generated samples that are realistic. The recall is the fraction of data examples that fall within the model manifold. This measures the proportion of the real data the model can generate (figure 14.5).
To estimate the manifold, we place a hypersphere around each data example, whose radius is the distance to the kth nearest neighbor. The union of these spheres is an approximation of the manifold, and it’s easy to determine if a new point lies within it. This manifold is also typically computed in the feature space of a classifier with the advantages and disadvantages that entails.
然而,它并不根据原始数据来建模距离,而是根据 Inception 分类网络最深一层的激活值来建模。这些隐藏单元与物体类别关联最强,因此比较发生在语义层面,忽略了图像中更细粒度的细节。该指标确实考虑了类别内的多样性,但严重依赖 Inception 网络中特征所保留的信息;网络丢弃的任何信息都不会对结果产生贡献。这些被丢弃的信息中,有些对于生成逼真样本仍然可能很重要。
流形精确率 / 召回率: Fréchet Inception 距离既对样本的真实感敏感,也对样本的多样性敏感,但不区分这些因素。为了区分这些特性,我们考虑数据流形(即真实样本所在的数据空间子集)与模型流形(即生成样本所在之处)之间的重叠。精确率是模型样本中落入数据流形的比例。这衡量了生成样本中逼真样本的比例。召回率是真实样本中落在模型流形内的比例。这衡量了模型能够生成的真实数据比例(图 14.5)。
为了估计流形,我们在每个数据样本周围放置一个超球体,其半径为到 kth 最近邻的距离。这些球体的并集是对流形的近似,因此很容易判断新点是否位于其中。该流形通常也是在分类器的特征空间中计算得到的,这随之带来优点和缺点。
Unsupervised models learn about the structure of a dataset in the absence of labels. A subset of these models is generative and can synthesize new data examples. A further subset is probabilistic in that they can both generate new examples and assign a probability to observed data. The models considered in the following four chapters start with a latent variable z which has a known distribution. A deep neural network then maps from the latent variable to the observed data space. We considered desirable properties of generative models and introduced metrics that attempt to quantify their performance.
无监督模型在没有标签的情况下学习数据集的结构。其中一部分是生成模型,能够合成新的数据样本。再有一部分是概率模型,它们既能生成新样本,又能为观测数据赋予概率。接下来四章所考虑的模型都从一个具有已知分布的隐变量 z 开始。深层神经网络随后将隐变量映射到观测数据空间。我们讨论了生成模型的理想特性,并引入了试图量化其性能的指标。
Evaluation:
