Ainsteinx Logo
Ainsteinx
👤
欢迎使用 Ainsteinx
登录

切换语言

货币

首页
博客
服务
第 01 课 · 入门

什么是生成式建模?

从数据中学习 p(x),再生成从未存在过的新数据。

判别模型回答“这张图是猫吗?”,而生成模型学习整个数据集是什么样子——即分布 p(x)——并从中采样出新的样本。

最小的示例:把 1,000 个人的身高学成正态分布,然后“生成”5 个新的人,并衡量某个身高有多合理。

判别式学习 p(y | x):数据 → 标签
生成式学习 p(x),再采样出像真实数据的新 x

生成模型的六大家族

思路家族课
近似密度VAE · Energy-based · Diffusion3 · 7 · 8
精确密度,但限制模型形式Autoregressive · Normalizing flow5 · 6
不建模密度,只学会采样GAN4

要点

  • 目标:学习数据的 p(x),并采样出逼真的新数据
  • 似然度表示某个数据点在模型下有多“合理”
generative-ai-ep01-generative-modeling.py
import numpy as np

# A generative model learns p(x) from data, then samples new x from it.
rng = np.random.default_rng(0)
heights = rng.normal(170, 7, size=1000)          # "real" data we observe

mu, sigma = heights.mean(), heights.std()        # learn p(x) = N(mu, sigma^2)
new_people = rng.normal(mu, sigma, size=5)       # generate new samples

print(f"learned  mu={mu:.1f}  sigma={sigma:.1f}")
print("generated:", np.round(new_people, 1))
# Likelihood tells how plausible a value is under the model
for x in (170, 200):
    p = np.exp(-(x - mu) ** 2 / (2 * sigma ** 2)) / (sigma * np.sqrt(2 * np.pi))
    print(f"p({x}) = {p:.5f}")

输出结果

learned  mu=169.7  sigma=6.8
generated: [177.8 171.7 171.  171.5 160.3]
p(170) = 0.05828
p(200) = 0.00000
  • #GenerativeAI
  • #DeepLearning
  • #PythonສຳລັບຄົນLaos
  • #AI
  • #ບອກຕໍ່ຄວາມຮູ້