标题:《PLUG AND PLAY LANGUAGE MODELS: A SIMPLE APPROACH TO CONTROLLED TEXT GENERATION》

时间:2020年3月

作者:Uber AI

内容:本文关注可控生成,或条件生成问题。提出了一个Plug and Play Language Model (PPLM) 模型,它结合了一个预训练LM和一个或若干个属性分类器(attribute classifiers)来引导文本生成,而不需要进一步训练LM。

源码:https://github.com/uber-research/PPLM

Introduction

文本生成器: p ( x ) p(x) p(x)

可控的文本生成器: p ( x ∣ a ) p(x|a) p(xa)。a表示可控制的属性。

属性模型(判别器): p ( a ∣ x ) p(a|x) p(ax)

简单来说就是把属性模型plug进文本生成器里,然后从结果 p ( x ∣ a ) = k   p ( a ∣ x ) a ( x ) p(x|a)=k\ p(a|x)a(x) p(xa)=k p(ax)a(x)中sample。

属性模型可以是词袋形式,也可以是单层分类器。sample方法遵循Metropolis-adjusted Langevin (MALA)所启发的gradients in the latent representation space方法。

优化是ex post facto in the activation space地运行的,所以不需要重训练或微调。控制是细粒度的,伴随着一个强参数来决定属性的影响强度(0强度意味着恢复为原始的 p ( x ) p(x) p(x))。属性模型训练较为容器,且在推断阶段,多种控制器可以共同灵活地结合。不同强度的属性模型表现为一群control knobs。

我们的贡献总结如下:

1、提出了PPML模型。

2、展示了模型在a range of attributes的控制下的文本生成,包括7种topic和1个简单的sentiments判决器。我们利用了自动化指标(分开训练perplexity and sentiment models)和人工指标。

3、比较了PPLM与一些功能相近的baseline(主要是微调版本的GPT2以及CTRL。)

【按:这里两个baseline,分别来自(Keskar et al., 2019)《A Conditional Transformer Language Model for Controllable Generation》和(Ziegler et al., 2019)《Fine-tuning language models from human preferences》】

4、我们还展示了PPML模型可以用于detoxify instances where generation of toxic content is likely by following the negative gradient of a model trained to detect toxicity. 我们还展示了 PPLM可以用于结构化约束(structurally constrained)的故事创作。

在这里插入图片描述

Related Work

受控生成;噪声信道模型、加权解码、文本风格迁移。

PLUG AND PLAY LANGUAGE MODELS

1 GPT2

语言模型的基本形态如下:
o t + 1 , H t + 1 = LM ( x t , H t ) x t + 1 = Softmax ( W o t + 1 ) o_{t+1},H_{t+1}=\text{LM}(x_t,H_t)\\ x_{t+1}=\text{Softmax}(Wo_{t+1}) ot+1,Ht+1=LM(xt,Ht)xt+1=Softmax(Wot+1)
其中 o o o是logit vector,x表示word(对应的one-hot向量)

2 STEERING GENERATION: ASCENDING$ {log}\ p(a|x)$

为了控制语言模型的输出,在每一个生成step,我们把history H t H_t Ht在两个梯度的相加的方向上作shift:

1、one toward higher log-likelihood (LL) of the attribute a under the conditional attribute model p ( a ∣ x ) p(a|x) p(ax)

2、one toward higher LL of the unmodified language model p ( x ) p(x) p(x)

The updates are restricted to H t H_t Ht and not the other model activations.具体地:

在这里插入图片描述

如图,先前向计算无控制的分布,再利用属性模型反向更新隐变量H,然后重新计算新的分布。

在这里插入图片描述

3 ENSURING FLUENCY: ASCENDING $ {log}\ p(x)$

上一步的办法还有一个问题,就是可能输出unrealistic adversarial or fooling examples。为了对抗这种趋势,我们以两种方式利用无条件LM,确保生成文本的流畅度与原始语言模型无二。

1、KL散度(Kullback–Leibler (KL) Divergence)

2、 后范数几何平均融合 (Post-norm Geometric Mean Fusion)

在这里插入图片描述

如图,用黑点表示考虑的句子,红色表示 p ( a ∣ x ) p(a|x) p(ax)的梯度下降方向,蓝色表示 p ( x ) p(x) p(x)的梯度下降方向。图里把优化分成了两步,在实践中我们是一步(把两个log分布相加)。我们在H的连续空间中优化,而非在x的离散空间优化。

SAMPLING AND RANKING

PPLM中的属性模型 p ( a ∣ x ) p(a|x) p(ax)扮演两个功能:1、一个score可以基于期望的属性来rank samples(图1的第一步,仅前向传播)。2、一个梯度下降方向可以用于更新隐空壳(图1的第二三步)。前者可以用于对生成的多个样本做排序,然后选择最好的。这可以作为1种在sampling with updated latents之外的额外的属性控制方法。此外,传统上的各种text decoding tricks,如降重,我们也应用了。

EXPERIMENTS, RESULTS, AND EVALUATION

本节,我们描述性能评估方法、不同属性模型下的可控生成结果。We also show use cases of PPLM in language detoxification and in
controlled story telling。所有decoding结果都是基于top-k采样的。

1 评价结果、消融实验

我们考察2个性能:1、PPLM是否生成了满足desired attribute (topic or sentiment)的文本;2、当我们加强属性控制的时候,文本的质量是否下降。

注意,我们总能够turn the control knob down to zero to disable control of attributes and reach the fluency of the original model。如果愿意,user可以tune the knobs at inference until a
chosen tradeoff between attribute strength and fluency is reached。

自动化指标

Perplexity、diversity、external
sentiment classifiers

人工指标

Ablation study and baselines

模型说明
Bthe baseline, unchanged GPT-2 LM, sampled once
BRB but sampled r times, with best sample chosen based on the LL ranking and filtering based on Dist score
BCupdate the latent representations( H ^ t \hat H_t H^t) and then sample once
BCRupdate the latent representations ( H ^ t \hat H_t H^t) and generate r samples. choose the best sample based on the LL score (after filtering out samples with low Dist scores).
CTRLa recent language model

2 BOW ATTRIBUTE MODELS

词袋属性模型。rely on extracting a set of attribute-based phrases to control。
在这里插入图片描述

3 DISCRIMINATOR ATTRIBUTE MODELS

control attributes using more sophisticated discriminators is desirable when it is difficult to express the attribute with a simple bag of words.

The sentiment discriminator here distinguishes sentiment between POSITIVE and NEGATIVE and is trained on the SST-5 dataset

15 prefixes:
在这里插入图片描述

Logo

CSDN联合极客时间,共同打造面向开发者的精品内容学习社区,助力成长!

更多推荐