{
  "id": "energy-based-text-generation",
  "title": "基于能量的文本生成：残差模型、重采样与扩散",
  "eyebrow": "全局序列模型",
  "description": "Residual Energy-Based Models for Text Generation 将序列级能量、噪声对比估计和重要性重采样联系起来，并与基于能量的扩散语言模型直接相连。",
  "lead": "Residual Energy-Based Models for Text Generation（ICLR 2020）将预训练语言模型与整条序列的能量函数结合，构成全局归一化的生成模型。Energy-Based Diffusion Language Models（ICLR 2025）明确联系这项工作，并把残差能量修正放进扩散去噪步骤。两者共享的机制是：以基础分布为起点，再乘上模型学到的、针对完整候选序列的偏好。",
  "original_papers": [
    "residual-ebm",
    "residual-ebm-jmlr"
  ],
  "terms": [
    "基于能量的文本生成",
    "全局归一化语言模型",
    "采样与重排序（sample and rerank）",
    "重要性重采样",
    "基于能量的扩散语言模型",
    "序列级能量",
    "考虑依赖关系的并行解码"
  ],
  "demo": "energy",
  "related_guides": [
    "structured-decoding",
    "probabilistic-attention"
  ],
  "reading_order": [
    "residual-ebm",
    "residual-ebm-jmlr",
    "edlm",
    "unified-energy",
    "neural-trf-nce"
  ],
  "sections": [
    {
      "id": "original-method",
      "title": "用于文本生成的残差能量模型",
      "paragraphs": [
        "Yuntian Deng、Anton Bakhtin、Myle Ott、Arthur Szlam 和 Marc’Aurelio Ranzato 在 ICLR 2020 论文中提出了这一文本生成框架，其 arXiv 版本发表于 2020 年 4 月 22 日。固定的自回归语言模型提供候选序列，双向能量函数对候选序列评分。论文围绕这一模型提出了基于重要性加权的条件生成方法，以及用于困惑度评估的对数概率上下界。",
        "模型分布为 <code>p(y | x) = q(y | x) exp(−E(x,y)) / Z(x)</code>。其中，x 是上下文，y 是完整续写，q 是基础模型，E 是残差能量，Z 是对所有续写求和得到的归一化常数。能量越低，相对于 q 的概率就越高。训练采用噪声对比估计（noise-contrastive estimation，NCE），让能量函数区分真实文本和基础模型生成的样本。"
      ],
      "citations": [
        "residual-ebm"
      ]
    },
    {
      "id": "meaning-of-residual",
      "title": "判别器如何改变生成器",
      "paragraphs": [
        "JMLR 2021 论文 Residual Energy-Based Models for Text 进一步研究了如何将区分生成文本的能力用于改进生成分布。Anton Bakhtin 和 Yuntian Deng 贡献相同；其他作者为 Sam Gross、Myle Ott、Marc’Aurelio Ranzato 和 Arthur Szlam。判别器提供的信息指出生成器对哪些文本生成过多、对哪些文本生成不足；残差模型把这些信息转化为对概率的修正。",
        "基础模型提供流畅的候选文本及其相对出现频率；能量函数在看完整条序列后，调整不同候选的相对偏好。如果所有能量都为零，基础分布保持不变。给所有能量加上同一个常数，也不会改变归一化后的分布，因为这个常数在分子和分母中相互抵消。",
        "无论使用哪种网络计算能量，都有两项代数检查：改变所有候选共享的能量偏移量，选择概率保持不变；降低某一个候选的能量，它的概率就会增加。"
      ],
      "citations": [
        "residual-ebm-jmlr"
      ]
    },
    {
      "id": "sample-score-resample",
      "title": "先采样，再评分，然后重采样",
      "paragraphs": [
        "先从 q 中抽取候选，用 E 为每个候选评分，再按照与 <code>exp(−E)</code> 成正比的归一化权重选择输出。这就是重要性重采样。若改为直接选择得分最高的候选，则是重排序（reranking）：选择规则发生了变化。两者都经过生成候选与评分这两个环节，但定义的输出分布不同。",
        "例如，三个已采样候选的能量分别为 0、log(2) 和 log(4)，对应权重为 1、1/2 和 1/4，因此选择概率为 4/7、2/7 和 1/7。按最高分选择会始终输出第一个候选；重采样则保留候选池上的概率分布。",
        "从 q 抽取候选池这一步已经体现了基础概率。若再给每个候选池权重乘一次 q，就改变了原本的重要性计算。同样，有限候选池中的归一化常数，也不等于对所有可能文本精确求和的结果。增加候选数会改变近似程度和计算开销；改变能量则会改变目标分布。"
      ],
      "citations": [
        "residual-ebm",
        "residual-ebm-jmlr"
      ]
    },
    {
      "id": "diffusion-connection",
      "title": "与扩散语言模型的直接联系",
      "paragraphs": [
        "Minkai Xu 等人的 Energy-Based Diffusion Language Models（EDLM）于 2024 年 10 月 28 日发布，发表于 ICLR 2025。它在扩散去噪器的分布上乘以一个序列级残差能量项；该能量以带噪序列和时间步为条件，修正单个去噪步骤内因词元预测相互独立而遗漏的依赖关系。",
        "EDLM 使用从自回归模型导出的能量，或用 NCE 训练的能量，再通过并行重要性采样生成文本。它在相关工作中引用 Deng 等人（2020），并在配分函数估计中明确采用这项工作。两者的联系体现在数学形式和算法上：残差修正、对比训练、重采样和似然估计。",
        "2020 年的模型修正自回归候选分布，以完成文本生成；EDLM 则在迭代扩散过程中修正去噪分布。修正发生的位置不同，但“基础分布乘以能量权重”的构造将两者联系起来。"
      ],
      "citations": [
        "residual-ebm",
        "edlm"
      ]
    },
    {
      "id": "method-comparison",
      "title": "比较基础分布、能量和推断方式",
      "table": {
        "columns": [
          "方法",
          "基础分布与修正",
          "推断或评估重点"
        ],
        "rows": [
          [
            "Neural TRF with NCE · 2018",
            "对参考语言模型进行指数倾斜",
            "语音识别重评分"
          ],
          [
            "Residual EBM · 2020",
            "自回归语言模型 × 序列能量",
            "通过重要性重采样进行条件生成；似然上下界"
          ],
          [
            "EDLM · 2025",
            "扩散去噪器 × 条件序列能量",
            "在去噪步骤中并行生成候选并重采样"
          ],
          [
            "Unified Energy · 2026",
            "针对依赖关系与不变性的能量修正",
            "改进扩散解码"
          ]
        ]
      },
      "paragraphs": [
        "Wang 和 Ou 的 neural TRF 论文给出了更早的残差形式与 NCE 方法，2020 年论文明确引用了这项工作。2020 年工作的贡献是围绕残差模型建立条件文本生成与似然评估方法。Unified Energy（2026）进一步分析扩散解码中的依赖误差与不变性误差，并结合两类能量修正。"
      ],
      "citations": [
        "neural-trf-nce",
        "residual-ebm",
        "edlm",
        "unified-energy"
      ]
    },
    {
      "id": "reading-the-demo",
      "title": "通过能量示例观察这一机制",
      "paragraphs": [
        "调整示例中三种结果上的能量强度 β。当 β = 0 时，输出概率就是基础分布。增大 β 会把概率质量移向能量更低的结果，而基础概率仍会影响最终分布。这个示例对三条可能序列计算精确的归一化分布；它不抽取候选池，也不调用语言模型。",
        "如果候选已经从基础模型中采样，重要性重采样所用的候选池权重就是 exp(−E(x))。基础模型的概率因子已经由采样这一步体现。区分这两种计算，才能把归一化模型与实际采样流程对应起来。"
      ]
    },
    {
      "id": "runnable-energy-resampling",
      "title": "运行有限候选池的能量重采样",
      "paragraphs": [
        "下载可独立运行的<a href=\"/research/examples/energy_resampling.ipynb\" download>能量重采样 notebook</a>或 <a href=\"/research/examples/energy_resampling.py\" download>Python 脚本</a>。示例先计算三种结果上的精确残差模型，再从基础分布中抽取候选池，按能量权重选择其中的候选。",
        "代码还会遍历候选计数的所有组合，精确计算有限候选池所产生的输出分布，从而在没有蒙特卡洛噪声的情况下展示近似误差。重复出现的候选保留其出现次数；按最低能量选择和按概率重采样也分别展示。",
        "代码使用 Python 3.9+ 及其标准库运行。<a href=\"/research/examples/research-examples.zip\" download>下载全部三个示例及数值检查</a>。"
      ],
      "citations": [
        "residual-ebm"
      ]
    }
  ],
  "updated_at": "2026-11-11",
  "url": "https://yuntiandeng.com/research/zh/energy-based-text-generation/",
  "papers": [
    {
      "id": "residual-ebm",
      "title": "Residual Energy-Based Models for Text Generation",
      "authors": [
        {
          "given": "Yuntian",
          "family": "Deng"
        },
        {
          "given": "Anton",
          "family": "Bakhtin"
        },
        {
          "given": "Myle",
          "family": "Ott"
        },
        {
          "given": "Arthur",
          "family": "Szlam"
        },
        {
          "given": "Marc’Aurelio",
          "family": "Ranzato"
        }
      ],
      "year": 2020,
      "venue": "ICLR 2020",
      "paper_url": "https://arxiv.org/html/2004.11714v1",
      "summary": "将固定的自回归语言模型与学到的序列级能量结合，使用 NCE 训练、基于重要性重采样的条件生成，以及似然上下界。",
      "connection": "原始文本生成与评估框架，将序列级残差能量与采用能量修正的扩散解码联系起来。",
      "bibtex_type": "inproceedings",
      "citation_key": "residualebm",
      "source_urls": [
        "https://arxiv.org/html/2004.11714v1"
      ],
      "pdf_url": "https://arxiv.org/pdf/2004.11714",
      "code_url": "https://github.com/da03/Residual-EBM",
      "arxiv_id": "2004.11714",
      "arxiv_first_posted": "2020-04-22",
      "abstract": "Text generation is ubiquitous in many NLP tasks, from summarization, to dialogue and machine translation. The dominant parametric approach is based on locally normalized models which predict one word at a time. While these work remarkably well, they are plagued by exposure bias due to the greedy nature of the generation process. In this work, we investigate un-normalized energy-based models (EBMs) which operate not at the token but at the sequence level. In order to make training tractable, we first work in the residual of a pretrained locally normalized language model and second we train using noise contrastive estimation. Furthermore, since the EBM works at the sequence level, we can leverage pretrained bi-directional contextual representations, such as BERT and RoBERTa. Our experiments on two large language modeling datasets show that residual EBMs yield lower perplexity compared to locally normalized baselines. Moreover, generation via importance sampling is very efficient and of higher quality than the baseline models according to human evaluation.",
      "abstract_source": "https://arxiv.org/html/2004.11714v1",
      "updated_at": "2026-11-11",
      "description_language": "zh-Hans",
      "abstract_language": "en"
    },
    {
      "id": "residual-ebm-jmlr",
      "title": "Residual Energy-Based Models for Text",
      "authors": [
        {
          "given": "Anton",
          "family": "Bakhtin"
        },
        {
          "given": "Yuntian",
          "family": "Deng"
        },
        {
          "given": "Sam",
          "family": "Gross"
        },
        {
          "given": "Myle",
          "family": "Ott"
        },
        {
          "given": "Marc’Aurelio",
          "family": "Ranzato"
        },
        {
          "given": "Arthur",
          "family": "Szlam"
        }
      ],
      "year": 2021,
      "venue": "JMLR 22(40):1–41",
      "paper_url": "https://www.jmlr.org/papers/v22/20-326.html",
      "summary": "研究如何从统计上区分人类文本与模型文本，并把学到的判别器用于全局归一化生成。",
      "connection": "进一步讨论从判别器到生成器的联系，以及残差能量建模。",
      "bibtex_type": "article",
      "citation_key": "residualebmjmlr",
      "source_urls": [
        "https://www.jmlr.org/papers/v22/20-326.html"
      ],
      "pdf_url": "https://www.jmlr.org/papers/volume22/20-326/20-326.pdf",
      "equal_contribution": [
        "Anton Bakhtin",
        "Yuntian Deng"
      ],
      "container_title": "Journal of Machine Learning Research",
      "volume": "22",
      "issue": "40",
      "pages": "1–41",
      "abstract": "Current large-scale auto-regressive language models display impressive fluency and can generate convincing text. In this work we start by asking the question: Can the generations of these models be reliably distinguished from real text by statistical discriminators? We find experimentally that the answer is affirmative when we have access to the training data for the model, and guardedly affirmative even if we do not. This suggests that the auto-regressive models can be improved by incorporating the (globally normalized) discriminators into the generative process. We give a formalism for this using the Energy-Based Model framework, and show that it indeed improves the results of the generative models, measured both in terms of perplexity and in terms of human evaluation.",
      "abstract_source": "https://www.jmlr.org/papers/v22/20-326.html",
      "updated_at": "2026-11-11",
      "description_language": "zh-Hans",
      "abstract_language": "en"
    },
    {
      "id": "edlm",
      "title": "Energy-Based Diffusion Language Models for Text Generation",
      "authors": [
        {
          "given": "Minkai",
          "family": "Xu"
        },
        {
          "given": "Tomas",
          "family": "Geffner"
        },
        {
          "given": "Karsten",
          "family": "Kreis"
        },
        {
          "given": "Weili",
          "family": "Nie"
        },
        {
          "given": "Yilun",
          "family": "Xu"
        },
        {
          "given": "Jure",
          "family": "Leskovec"
        },
        {
          "given": "Stefano",
          "family": "Ermon"
        },
        {
          "given": "Arash",
          "family": "Vahdat"
        }
      ],
      "year": 2025,
      "venue": "ICLR 2025",
      "paper_url": "https://arxiv.org/html/2410.21357v4",
      "summary": "在每一步扩散去噪分布中加入完整序列的残差能量，采用自回归模型或 NCE 参数化，并通过并行重要性采样生成文本。",
      "connection": "直接引用 Deng 等人（2020），将残差修正与配分函数估计用于扩散语言建模。",
      "bibtex_type": "inproceedings",
      "citation_key": "edlm",
      "source_urls": [
        "https://arxiv.org/html/2410.21357v4"
      ],
      "arxiv_id": "2410.21357",
      "arxiv_first_posted": "2024-10-28",
      "updated_at": "2026-11-11",
      "description_language": "zh-Hans",
      "abstract_language": "en"
    },
    {
      "id": "unified-energy",
      "title": "Unified Energy for Invariant and Independent Decoding in Diffusion Language Models",
      "authors": [
        {
          "given": "Yuchen",
          "family": "Yan"
        },
        {
          "given": "Minkai",
          "family": "Xu"
        },
        {
          "given": "Zaiquan",
          "family": "Yang"
        },
        {
          "given": "Yatao",
          "family": "Bian"
        }
      ],
      "year": 2026,
      "venue": "arXiv:2606.09159",
      "paper_url": "https://arxiv.org/html/2606.09159v1",
      "summary": "结合针对扩散解码中依赖关系与不变性的能量修正。",
      "connection": "通过统一处理解码误差，扩展当前采用能量修正的扩散研究方向。",
      "bibtex_type": "article",
      "citation_key": "unifiedenergy",
      "source_urls": [
        "https://arxiv.org/html/2606.09159v1"
      ],
      "arxiv_id": "2606.09159",
      "arxiv_first_posted": "2026-06-08",
      "publication_type": "preprint",
      "container_title": "arXiv",
      "updated_at": "2026-11-11",
      "description_language": "zh-Hans",
      "abstract_language": "en"
    },
    {
      "id": "neural-trf-nce",
      "title": "Learning Neural Trans-Dimensional Random Field Language Models with Noise-Contrastive Estimation",
      "authors": [
        {
          "given": "Bin",
          "family": "Wang"
        },
        {
          "given": "Zhijian",
          "family": "Ou"
        }
      ],
      "year": 2018,
      "venue": "ICASSP 2018",
      "paper_url": "https://arxiv.org/abs/1710.10739",
      "summary": "对参考分布进行指数倾斜，并用噪声对比估计训练神经随机场语言模型。",
      "connection": "2020 年论文明确讨论的更早残差形式与 NCE 训练方法，其评估以语音识别重评分为中心。",
      "bibtex_type": "inproceedings",
      "citation_key": "neuraltrfnce",
      "source_urls": [
        "https://arxiv.org/abs/1710.10739"
      ],
      "arxiv_id": "1710.10739",
      "arxiv_first_posted": "2017-10-30",
      "updated_at": "2026-11-11",
      "description_language": "zh-Hans",
      "abstract_language": "en"
    }
  ]
}
