第一章 生成式AI导论:从判别到创造的范式转移 / Chapter 1 Introduction to Generative AI: From Discrimination to Creation
第一章 生成式AI导论:从判别到创造的范式转移
Chapter 1 Introduction to Generative AI: From Discrimination to Creation
如果让你向一位从未接触过人工智能的祖父解释"生成式 AI"这五个字,你会怎么说?一个简洁的切入点是:请他想象两位艺术家。第一位是技艺精湛的鉴赏家,给他一万张真迹与赝品,他能在毫秒之间判断哪一张出自凡·高之手,但他本人不会画画。第二位是初出茅庐的画家,他看过无数凡·高的作品后闭门创作,画出的新画能让博物馆专家犹豫——"这究竟是真迹还是模仿?"。在 AI 领域,第一位艺术家对应判别式模型(Discriminative Model),第二位对应生成式模型(Generative Model)。这一章的全部讨论,都将围绕这两类模型的根本分野展开,并回答一个更具时代感的问题:为什么 2022 年之后,生成式 AI 会突然从学术论文走入大众视野?
> *If you had to explain "Generative AI" to a grandparent who has never encountered artificial intelligence, how would you do it? A concise entry point: imagine two artists. The first is a connoisseur of extraordinary skill — given ten thousand genuine paintings and forgeries, he can judge within milliseconds which one came from Van Gogh's hand, yet he himself cannot paint. The second is an emerging painter who, after studying countless Van Gogh originals, retreats to his studio and produces new paintings capable of making museum experts hesitate: "Is this genuine or imitation?" In the AI domain, the first artist corresponds to a Discriminative Model, the second to a Generative Model. All discussions in this chapter will revolve around this fundamental divide and address a more temporally charged question: why, after 2022, did generative AI suddenly leap from academic papers into public consciousness?*
---
1.1 一个核心问题:生成式 AI 究竟在学什么?
1.1.1 判别式模型与生成式模型的形式化分野
从机器学习的视角看,模型的"输入—输出"关系可以拆成两个方向:给定输入预测输出,或者学习输入本身的结构。判别式模型关注前者,它学习的是条件概率 $p(y \mid x)$——在已知输入 $x$ 的前提下,输出 $y$ 的概率分布。典型的判别式任务包括:邮件是垃圾邮件还是正常邮件($y \in \{0,1\}$)、图像中的像素属于哪个语义类别($y$ 是高维标签向量)、一段语音对应的文字是什么($y$ 是词序列)。这些任务的共同特征是:模型只关心"决策边界",而不必理解数据本身是如何产生的。
生成式模型关注后者,它试图对联合概率分布 $p(x, y)$ 或数据的边缘分布 $p(x)$ 建模。一旦掌握了 $p(x)$,模型不仅能做判别(通过贝叶斯公式 $p(y \mid x) = p(x \mid y) p(y) / p(x)$),还能完成判别式模型无法完成的任务:从分布中采样(sampling),生成全新的、与训练数据相似却又从未出现过的样本。
> *From a machine learning perspective, the "input–output" relationship of a model can be split into two directions: predicting the output given the input, or learning the structure of the input itself. Discriminative models focus on the former — they learn the conditional probability $p(y \mid x)$. Generative models focus on the latter — they attempt to model the joint probability distribution $p(x, y)$ or the marginal distribution $p(x)$. Once $p(x)$ is mastered, the model can not only discriminate (via Bayes' rule) but also sample, producing entirely new instances that resemble yet never existed in the training data.*
用一幅对照表呈现这一差异会更清晰:
| 维度 Dimension | 判别式模型 Discriminative | 生成式模型 Generative | | --- | --- | --- | | 学习目标 Objective | 条件概率 $p(y \mid x)$ | 数据分布 $p(x)$ 或联合分布 $p(x, y)$ | | 核心问题 Core Question | 给定 $x$,$y$ 是什么? | 数据看起来像什么?它如何产生? | | 典型任务 Typical Tasks | 分类、回归、检测、识别 | 图像合成、文本生成、音频合成、视频创作 | | 训练数据需求 Data | 通常需要标签 Labels | 大量情况下无需标签 Self-supervised | | 评估方式 Evaluation | 准确率、F1、AUC 等指标 | FID、IS、CLIP Score 等分布距离 | | 代表算法 Representatives | Logistic Regression、SVM、CNN 分类器 | VAE、GAN、Diffusion、LLM |
理解这一表格的关键在于:判别式模型的"天花板"是判别,生成式模型的"天花板"是创造。前者再精准,也无法凭空画出新的猫;后者即使在判别任务上稍逊一筹,也能在从未见过的数据空间中"想象"出新样本。这一本质差别,决定了二者在产业价值曲线上的不同位置。
1.1.2 一个非形式化的直觉:画家与鉴赏家的认知差异
为了把这一定义拉到普通读者的直觉层面,我们可以借助神经科学的一个类比。认知神经科学家发现,专业画家与专业鉴赏家的大脑活动模式存在显著差异:鉴赏家高度依赖视觉识别腹侧通路(ventral stream) 进行"看—判断—命名";画家则同时激活背侧通路(dorsal stream) 与运动皮层,因为他们在"看"的同时必须想象"如何画"。这与两类 AI 模型的差异惊人地相似——判别式 AI 只学习"看与判别"的映射;生成式 AI 必须额外学习"看—想象—构造"这一闭环。
> *To pull this definition down to an intuitive level, we can borrow an analogy from neuroscience. Cognitive neuroscientists have observed that professional painters and professional connoisseurs exhibit significantly different patterns of brain activity. Connoisseurs rely heavily on the visual recognition ventral stream for "see–judge–name"; painters simultaneously activate the dorsal stream and motor cortex because, while seeing, they must also imagine how to paint. This mirrors the difference between the two AI model classes with striking fidelity — discriminative AI only learns the "see and judge" mapping, while generative AI must additionally learn the closed loop of "see–imagine–construct".*
这一认知差异带来一个重要的工程后果:生成式模型通常更难训练。判别只需一个损失函数(如交叉熵)度量"判错多少";生成则需要度量"生成的样本有多像真实分布",而两个高维分布之间的距离本身就是一个未完全解决的数学问题。这也是为什么 GAN 在 2014 年提出后,训练稳定性困扰了学界整整四年,而扩散模型直到 2020 年才以可扩展的方式被工程化落地。
---
1.2 概率视角:学习数据分布 $p(x)$
1.2.1 为什么 $p(x)$ 如此重要?
生成式建模的核心命题可以浓缩为一句话:如果我们能精确写出 $p(x)$,我们就掌握了该类数据的全部结构。这是因为 $p(x)$ 是一个概率密度函数,它对每一组合法数据赋予一个概率——高概率区域对应"常见"样本,低概率区域对应"罕见"样本,零概率区域对应"不可能"样本。一旦估算出 $p(x)$,以下能力自然涌现:
- **采样(Sampling)**:从高概率区域抽取新样本 $\tilde{x} \sim p(x)$,等价于"创造"新数据。
- **密度估计(Density Estimation)**:计算 $p(x_{\text{new}})$ 判断新样本是否属于同分布。
- **条件生成(Conditional Generation)**:通过贝叶斯公式得到 $p(x \mid y)$,生成"满足条件 $y$"的样本。
- **缺失填补(Inpainting / Imputation)**:已知部分观测,求解缺失维度的后验分布。
> *The central proposition of generative modeling can be condensed into a single sentence: if we can write down $p(x)$ precisely, we have mastered the full structure of that data class. This is because $p(x)$ assigns a probability to every legitimate datum — high-probability regions correspond to "common" samples, low-probability regions to "rare" samples, zero-probability regions to "impossible" ones.*
1.2.2 一个玩具示例:高斯混合模型
为帮助读者建立直观,我们以高斯混合模型(Gaussian Mixture Model, GMM) 为例。假设真实数据由两个二维高斯分布混合而成:
$$p(x) = \pi_1 \, \mathcal{N}(x \mid \mu_1, \Sigma_1) + \pi_2 \, \mathcal{N}(x \mid \mu_2, \Sigma_2)$$
其中 $\pi_1 + \pi_2 = 1$ 为混合权重。给定 $N$ 个样本 $\{x_i\}_{i=1}^N$,我们可以通过期望最大化算法(Expectation-Maximization, EM) 迭代求解 $\pi_k, \mu_k, \Sigma_k$。一旦参数估出,就可以从 $p(x)$ 中通过"先采样分量 $k \sim \text{Categorical}(\pi_1, \pi_2)$,再从 $\mathcal{N}(\mu_k, \Sigma_k)$ 采样"的方式生成无限多新样本。
```python import numpy as np from sklearn.mixture import GaussianMixture
1. 生成玩具数据:两个二维高斯混合
np.random.seed(42) X1 = np.random.multivariate_normal(mean=[0, 0], cov=np.eye(2), size=300) X2 = np.random.multivariate_normal(mean=[5, 5], cov=np.eye(2), size=300) X = np.vstack([X1, X2])
2. 拟合高斯混合模型
gmm = GaussianMixture(n_components=2, covariance_type="full", random_state=0) gmm.fit(X)
3. 从学到的 p(x) 中采样 5 个新样本
new_samples, _ = gmm.sample(5) print("Generated samples:\n", new_samples) ```
虽然 GMM 只能建模简单分布,但它完整呈现了生成式建模的三大步骤:定义模型族 → 拟合参数 → 采样。本书后续章节的 VAE、GAN、Diffusion 等模型,可以看作 GMM 思路在高维复杂数据(图像、视频、文本)上的层层升级。
1.2.3 高维数据的诅咒与生成模型的演进路线
现实中的图像、视频、文本分布是高维、复杂、多模态的。例如一张 $64 \times 64$ 的彩色图像位于 $64 \times 64 \times 3 = 12288$ 维空间;一张 $1024 \times 1024$ 高清图像则高达 $3{,}145{,}728$ 维。在这种空间里:
- **维数灾难(Curse of Dimensionality)**:直接估计 $p(x)$ 所需的样本数随维度指数增长。
- **流形假设(Manifold Hypothesis)**:自然数据并非充满高维空间,而是集中在一个低维流形上(例如所有"猫脸"图像可能只构成 $10^2$ 维的子流形)。
- **多模态性(Multi-modality)**:同一条件 $y$ 下可能存在多种合法输出。
这三类挑战决定了生成模型的演进路径:HMM → 隐变量模型 → VAE → GAN → 扩散模型,每一步都在尝试用更优雅的方式绕过上述障碍。
> *These three classes of challenges determine the evolutionary path of generative models: HMM → latent variable models → VAE → GAN → diffusion models, with each step attempting to circumvent the obstacles in a more elegant way.*
---
1.3 六十年 AI 史中的三次浪潮与两次拐点
1.3.1 三次浪潮的宏观叙事
人工智能作为一个学科,自 1956 年达特茅斯会议(Dartmouth Conference)正式诞生以来,经历了多次潮起潮落。我们可以将其归纳为三次浪潮:
1. 符号主义浪潮(Symbolic AI, 1956–1980s):以专家系统、逻辑推理、知识工程为代表。这一代 AI 擅长"演绎",但难以处理感知类任务。生成能力非常有限,主要体现在自动作曲(如 David Cope 的 EMI)、自动证明等小众方向。 2. 连接主义浪潮(Connectionist AI, 1980s–2010s):以神经网络为代表。1986 年 Rumelhart 等人重新发现反向传播算法(Backpropagation),1997 年 Hochreiter & Schmidhuber 提出 LSTM。但受限于算力与数据,连接主义长期处于"寒冬"。 3. 深度学习浪潮(Deep Learning, 2012–至今):2012 年 AlexNet 在 ImageNet 上以 15.3% 的 Top-5 错误率(亚军 26.2%)颠覆图像识别。这一次浪潮又可分为两个阶段:
- **判别主导期(2012–2017)**:CNN 在视觉、RNN/LSTM 在语音、CRF 在 NLP,主流任务均为判别式。
- **生成主导期(2014–至今)**:GAN、VAE、Diffusion、LLM 相继登场,生成能力成为新焦点。
> *Artificial intelligence as a discipline was formally born at the 1956 Dartmouth Conference. It has since experienced three waves: Symbolic AI (1956–1980s), Connectionist AI (1980s–2010s), and Deep Learning (2012–present). The deep-learning wave itself subdivides into a discrimination-dominated era (2012–2017) and a generation-dominated era (2014–pre