Files
myWiki/concepts/classifier-free-guidance-language.md

54 lines
1.9 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
title: "Classifier-Free Guidance for Language"
created: 2026-05-13
updated: 2026-05-13
type: concept
tags: [guidance, diffusion-language-model, controllable-generation]
sources:
- https://arxiv.org/abs/2605.10938
---
# CFG for Language (Classifier-Free Guidance)
Classifier-Free Guidance (CFG) 最早在图像扩散模型中提出,通过外推条件和无条件预测来引导生成方向。[[embedded-language-flows|ELF]] 将其首次有效应用于语言扩散模型。
## 核心公式
在 Flow Matching 框架中:
```
v_cfg(z_t | c) = ω · v(z_t | c) + (1-ω) · v(z_t | ∅)
```
其中 ω 是引导强度guidance scalec 是条件信号,∅ 是空条件。
## ELF 中的实现
### 条件信号构造
由于语言生成没有显式 class labelELF 使用 [[self-conditioning]] 构造条件信号 c将上一时间步的预测 x̂' 作为当前步的条件。
### 训练时 CFG
为避免推理时双倍前向开销ELF 采用**训练时 CFG**
- 训练时随机丢弃条件信号(以概率 p_uncond让网络同时学习条件和无条件预测
- 单个前向 pass 输出 x_cfg而非 x通过条件信号的线性组合隐式建模 CFG
- 推理时无需双倍计算
## 为什么在连续 DLM 中特别有效
CFG 原本为连续量设计score function, velocity field。在连续空间中 CFG 直接作用于速度/嵌入预测在离散空间中需要处理离散概率分布的外推效果通常更差。ELF 的连续嵌入设计使其能**自然受益于图像域积累的 CFG 经验**。
## 效果
ELF 中 CFG 显著降低 Gen. PPL
- CFG=1.0 → 效果中等
- CFG=2.0-3.0 → 最优区间
- CFG>3.0 → 收益递减,质量可能下降
## 相关概念
- [[self-conditioning]] — ELF 的条件信号源
- [[embedded-language-flows]] — 使用此技术的模型
- [[continuous-diffusion-language-models]] — CFG 天然适用的模型类别