본문 바로가기
AI/NLP

[논문리뷰] Diffusion-LM Improves Controllable Text Generation

by didi0di 2022. 9. 20.
728x90

https://deepai.org/publication/diffusion-lm-improves-controllable-text-generation

 

Diffusion-LM Improves Controllable Text Generation

05/27/22 - Controlling the behavior of language models (LMs) without re-training is a major open problem in natural language generation. Whil...

deepai.org

2205.14217.pdf
1.02MB

 

Abstract

 

re-training 없이 language models (LMs)의 행동을 컨트롤하는 것은 NLP에서 major open problem임.

 

최근 연구들에서 simple sentence attributes (e.g., sentiment)를 성공적으로 컨트롤하는 것을 증명했으며, complex하고 fine-grained controls (e.g., syntactic structure)로 발전을 했다.

 

저자들은 Diffusion-LM이라고 부르는 continuous diffusions 기반의 새로운 non-autoregressive LM을 제안함.

continuous domains에서의 diffusion models의 최근 성공에 따라, Diffusion-LM은 반복적으로 a sequence of Gaussian vectors를 word vectors로 denoises함. 이러한 intermediate variables의 continuous, hierarchical한 성질이 simple gradient-based algorithm이 complex, controllable generation tasks 수행을 가능하게 함.

 

6개의 challenging fine-grained control tasks에서 Diffusion-LM이 성공적으로 컨트롤함을 증명했으며, 기존 방식들보다 뛰어난 성능을 냈음.

 

1 Introduction

Large autoregressive language models (LMs)은 양질의 텍스트를 생성할 수 있지만, real word application에 적용하기 위해서는  text generation process가 컨트롤 될 수 있어야 하며, 이는 특정 요건 (e.g. topic, syntactic structure)에 맞게 텍스트를 생성하는 것이 필요하다는 것.

LM을 컨트롤하는 자연스러운 방법은 supervised data of the form (control, text)으로 fine-tune 하는 것이지만, 각각의 control task에 맞게 updating the LM parameters를 업데이트하는 것은 비용이 많이 들며, multiple controls (e.g. generate text that is both positive sentiment and non-toxic)의 조합을 허락하지 않음. 이런 점에서 LM을 frozen하고 얼마나 컨트롤에 맞게 잘 생성하는지를 측정하는 external classifier를 사용해 generation process를 조작하는 light-weight and modular plug-and-play approaches를 제안하게 되었음.

 

Diffusion-LM : a new language model based on continuous diffusions

sequence of Gaussian noise vectors로 시작하며, words에 상응하는 vectors로 점진적으로 노이즈를 제거함.

이러한 gradual denoising steps continuous latent representations의 계층을 생성하며

이렇게 계층적이고 연속적인 latent variable simple한 gradient-based methods가 생성된 문장의 parse tree를 constraining하는 것과 같은 complex control tasks를 수행하게 함

 

 

 

diffusion model은 Continuous diffusion models은 비전이나 오디오 도메인에서 매우 성공적이지만, 텍스트에는 적용되지 않았는데 그것이 바로 inherently discrete하다는  텍스트의 속성 때문이다. 이러한 모델들을 텍스트에 적용시키려면 standard diffusions에서 몇가지 수정이 필요하다.

  • add an embedding step and a rounding step
    : design a training objective to learn the embedding, and propose techniques to improve rounding
  • control Diffusion-LM using a gradient-based method 
    : text generation process가 target structural and semantic controls를 만족하는 아웃풋을 내도록 컨트롤함.

six control targets

  • range :  from fine-grained attributes (e.g., semantic content) to complex structures (e.g., parse trees).
  • 기존의 plug-and-play methods보다 2배 가까운 성능을 냈으며, fine-tuning 모델과 근접하거나 뛰어난 성능을 보여줌.
  • semantic content와 syntactic structure 두 요구에 맞게 문장을 생성하도록 유도된 multiple classifier를 구성하는 것에도 성공.
  • 마지막으로, length control and infilling 같은 span-anchored controls도 고려했다.

Diffusion-LM은 이러한 컨트롤들을 classifier 없이도 가능하게 하며, 기존의 plug-and-play methods 보다 월등히 우수한 성능을 내고 infilling task를 scratch부터 학습한 LM모델과 대등한 성능을 냄.

 

3 Problem Statement and Background

 

우선 controllable generation(3.1)을 정의하고 continuous diffusion models(3.3)에 대해 리뷰함

 

3.1 Generative Models and Controllable Generation for Text

Text generation is the task of sampling w from a trained language model plm(w), where w = [w1 · · · wn] is a sequence of discrete words and plm(w) is a probability distribution over sequences of words. Controllable text generation is the task of sampling w from a conditional distribution p(w | c), where c denotes a control variable. For syntactic control, c can be a target syntax tree (Figure 1), while for sentiment control, c could be a desired sentiment label. The goal of controllable generation is to generate w that satisfies the control target c.

plug-and-play controllable generation setting: 
 given a language model plm(w) trained from a large amount of unlabeled text data, and for each control task, we are given a classifier p(c | w) trained from smaller amount of labeled text data
The goal is to utilize these two models to approximately sample from the posterior p(w | c) via Bayes rule p(w | c) ∝ plm(w) · p(c | w). plm(w) encourages w to be fluent, and the p(c | w) encourages w to fulfill the control.

3-2.  Auto-regressive models(ARMs)
순서를 가지는 변수(variable)들의 조건부 확률(conditional probability)의 곱으로 데이터의 likelihood를 계산하는 모델. 주어진 데이터의 likelihood를 계산할 수 있는 장점은 있지만 sampling이 느리고, 데이터에 내재된 잠재형상(latent feature)은 학습할 수 없는 단점이 있음.

 

3-3. Diffusion
데이터 x에서 점점 noise를 추가해서 noise data로 만들고, noise data에서 데이터 x로 돌아오는 과정을 학습해 distribution을 estimate하는 모델. Likelihood는 다루기 힘들지만 좋은 likelihood 값을 가지고 특별한 제한 조건 없이 complex distribution을 잘 estimate하는 특징이 있다.

  • Diffusion process :  주어진 데이터 x에 점점 noise를 추가 (지정한 noise ratio 값 βt를 time step마다 추가)하는 것이고 관련된 분포를 모두 가우스분포(Gaussian distribution)로 표현할 수 있음. Markov 성질을 가정하며, 여기서는 따로 학습이 진행되지 않음.

  • Reverse Diffusion process : noise data에서 원래의 데이터 x로 돌아오는 과정(generative model). 모델을 통해 모르는 Reverse Diffusion process를 학습하는 것

4 Diffusion-LM: Continuous Diffusion Language Modeling

Diffusion-LM을 구성하기 위해서는 standard diffusion model에서 몇가지 수정이 필요하다.

 

1. must define an embedding function

: discrete text를 a continuous space로 mapping하기 위해 embedding function 필요하며, 임베딩을 학습하는 end-to-end training objective를 제안함.

 

2. rounding method

: embedding space에 있는 vectors 들을 다시 words로 mapping

 

 

4.1 End-to-end Training

 

continuous diffusion model을 discrete text에 적용하기 위해, 각 단어들을 Rd로 맵핑하는 embedding function EMB(wi)를 정의

- length 가 n인 sequence w의 embedding  : 

diffusion model’s parameters와 word embeddings을 결합해서 학습하도록 수정된 diffusion model training objective를 제안.

random Gaussian embeddings과 pre-trained word embeddings을 사용

 

- forward process : discrete words w에서 x0까지 Markov transition을 추가.

qφ(x0|w) = N (EMB(w), σ0I).

- reverse process : trainable rounding step을 추가.

pθ(w | x0) = Qn i=1 pθ(wi | xi), where pθ(wi | xi) is a softmax distribution

- training objectives :

training objectives

아래 수식은 the simplification에 따라서 도출한 수식이며 자세한 내용은 appendix A와 아래 내용 참고

this objective(위 수식) can be unstable and require many optimization tricks to stabilize [27]. To circumvent this issue, Ho et al. [12] devised a simple surrogate objective that expands and reweights each KL-divergence term in Lvlb to obtain a mean-squared error loss (derivation in Appendix E) which we will refer to as  (아래수식)

embedding function을 학습시키기 때문에, qφ 는 trainable parameters를 포함하고 있으며 

이 sampling step를 통해 backpropagate 하기 위해서 reparametrization trick을 사용함.

학습된 임베딩 클러스터가 의미있음 발견 : POS 태그가 같은 단어들이 군집화됨 (Figure 3)

4.2 Reducing Rounding Errors

inverse process  :  predicted x0를 rounding해서  discrete text로 돌아가도록 함

Rounding은 아래와 같은 argmax에 따라 각각의 포지션에서 most probable word를 고르는 것으로 얻어진다.

이상적으로 디노이징 스텝에서 x0이 어떤 단어의 임베딩에 정확하게 놓여있다는 것을 보장함에 따라 이러한 argmax-rounding이 충분하게 이산적인 텍스트로 치환되어야 하지만, 모델은 x0이 한 단어에 전념하도록 생성하는것에 실패함.

이러한 현상이 일어나는 이유는 simple objevtive가 x0의 구조를 모델링할 때 충분히 강조를 못해서 라고 설명함. 

그래서 심플 로스를 re-parametrize 했다함.

 

5 Decoding and Controllable Generation with Diffusion-LM

Diffusion-LM에서 plug-and-play control이 가능하게 되는 과정 설명

3-1에서 정의한 것 처럼,  Bayesian formulation에서 영감을 받음.

하지만 discrete text에 대해 직접 컨트롤을 하는게 아니라, Diffusion-LM을 통해 정의된 sequence of continuous latent variables x0:T에 컨트롤을 하고, 이 latents들을 text로 변환하기 위해 rounding step을 적용

 

6 Experimental Setup

학습과 디코딩에 대해 개선

  • two language modeling tasks에 대해 학습
  • 5 classifier-guided control tasks에 controllable generation method를 적용
  • classifier-free control task (i.e. infilling)에 MBR (Minimum Bayes Risk) decoding 적용

 

6.1 Datasets and Hyperparameters

Datasets

 

- E2E : 50K restaurant reviews labeled by 8 fields including food type, price, and customer rating

- ROCStories : 98K five-sentence stories, capturing a rich set of causal and temporal commonsense relations between daily event. E2E보다 챌린징

 

Hyperparameters

 

Diffusion-LM is based on Transformer [42] architecture with 80M parameters

hyperparameters

  • sequence length n = 64
  • diffusion steps T = 2000
  • square-root noise schedule (see Appendix A for details)
  • embedding dimension as a hyperparameter (d = 16 for E2E and d = 128 for ROCStories).

6.2 Control tasks

6 control tasks

- the first 4 tasks rely on a classifier, and the last 2 tasks are classifier free.

- 각 task에 대해서 200 control targets c 샘플링, 각 control target에 대해서 50개 샘플을 생성했다.

- generated text의 fluency를 평가하기 위해서, a teacher LM (i.e., a carefully fine-tuned GPT-2 model)에 생성된 text를 넣고 perplexity를 리포트함. 이 metric을 lm-score 라고 부르며, 낮을수록 퀄리티가 좋음을 의미.

 

- 각 task에 대한 metric

Control Task target - generate sentence Metric
Semantic Content field (e.g., rating)와 value (e.g., 5 star)가 주어졌을때,  field=value를 커버하도록 문장 생성함. exact match of ‘value’
Parts-of-speech sequence of parts-of-speech (POS) tags가 주어졌을때, 이 POS 태그와 매칭되고 그 길이가 같은 단어들의 sequence를 생성. word-level exact match
Syntax Tree target syntactic parse tree가 주어졌을때, 이와 동일한 형태를 갖도록 생성 생성된 문장을 off-the-shelf parser를 이용해 파싱, F1 scores
Syntax Spans target (span, syntactic category) pair가 주어졌을때, span[i,j]의 parse tree가 target syntactic category (e.g. prepositional phrase)와 일치하는 텍스트 생성 (syntactic category란 전치사 구 등 특정 문법 요소를 말함) the fraction of spans that match exactly
Length target length가 주어졌을때, ±2 길이의 문장 생성.  a classifier-free control task로 취급
Infilling aNLG dataset의 a left context (O1) and a right context (O2)가 주어졌을때, 논리적으로 이 둘을 연결하는 문장을 생성 both automatic and human evaluation from the Genie leaderboard

 

6-3. Classifier-Guided Control Baselines

 

5개 task에 대해 PPLM, FUDGE, 그리고 FT(a fine-tuning oracle)을 베이스라인으로 설정

PPLM과 FUDGE는 GPT-2 small architecture를 scratch부터 학습시킨 autoregressive LM 기반 plug-and-play controllable generation approaches이다. 

6-4. Infilling Baselines

DELOREAN, COLD, AR-infilling 사용.

 

반응형

7 Main Results

 

E2E와 ROCStories datasets에 대해 Diffusion-LMs 학습.

systems based on autoregressive LMs 보다 좋은 성능을 냄.

7.1 Classifier-Guided Controllable Text Generation Results

high success and fluency across all classifier-guided control tasks

5개 task에서 모두 PPLM과 FUDGE보다 좋은 성능을 냄. 심지어 syntactic parse trees and spans에서는 fine-tuning oracle보다 좋은 성능.

 

Diffusion-LM의 non-autoregressive nature가 precise future planning이 필요한 task(Syntax Spans and Length)를 쉽게 풀게 해줌.

또한 global structures를 포함한 복잡한 컨트롤(Parts-of-speech, Syntax Tree)에서도 잘 동작하는데, coarse-to-fine representations이 classifier가 individual tokens (near t = 0) 뿐만 아니라 entire sequence (near t = T)에 대한 컨트롤을 하도록 하기 때문.

 

Qualitative Results.

 

one key difference between our method and fine-tuning  :

Diffusion-LM은 예측을 실패하고 나서도 뒤에 나오는 span을 잘 생성하는데 비해, FT model은 한번 틀리면 그 뒤로 쭉 틀림.

 

 

7.2 Composition of Controls

 

plug-and-play controllable generation의 한가지 특이한 능력은 modularity.

classifiers에게 multiple independent tasks를 줘도, gradient guided control makes 가 gradients on the sum of the classifier log-probabilitie를 통해 multiple controls의 intersection으로부터 생성하는것을 간단하게 만든다.

 

Semantic Content + Syntax Tree control and Semantic Content + Parts-of-speech control의 combination task에서도 좋은 성능을 냄. 

 

7.3 Infilling Results

 diffusion LM이 마찬가지로 좋은 성능을 냄. 따라서 specialized training 없이 generation order나 lexical constraints (such as infilling)에 영향을 받는 task들을 잘 풀수 있을 것.

 

7.4 Ablation Studies

 

Learned v.s. Random Embeddings

Learned embeddings이 더 좋은 성능을 냄. 

 

Objective Parametrization

저자들은 diffusion model이  x0을 directly predict하는 방법을 제안함. 이 부분에서  image generation에서 standard parametrization인 noise term ϵ을 parametrizes 하는 것과 비교함. 

ϵ를 parametrizes하는 것이 small dimensions에서는 잘 동작하나, dimensions이 커지면 안되는 것에 비해서 x0을 parametrizes하는 것은 꾸준히 좋은 성능을 냄.

 

8 Conclusion and Limitations

복잡하고 세밀한 control task를 가능하게 하는 Diffusion-LM이라는 ccontinuous diffusions에 기반 controllable language model 을 제안함. 6개의 fine-grained control tasks에서 좋은 성능을 내는 것을 확인했으며, 기존 방법들에 비해 두배 가까운 성능을 내고 추가 학습이 요구되는 fine-tuning methods과도 견줄말한 성능을 냄. Diffusion-LM을 통해 복잡한 제어가 가능하게 된 것은 매력적이라는 것을 발견했으며, 이것이 현재의 discrete autoregressive generation 패러다임을 크게 벗어난 것에 대해 흥분함.

 

drawbacks

 

(1) it has higher perplexity

(2) decoding is substantially slower

(3) training converges more slowly

 

 

 

참고

https://www.lgresearch.ai/kor/blog/view/?seq=190&page=1&pageSize=12 

728x90

댓글