아이공의 AI 공부 도전기

[논문 Summary] NCSN (2019 NIPS) "Generative Modeling by Estimating Gradients of the data distribution"

 

     

 

논문 정보

Citation : 2022.12.08 목요일 기준 531회

저자

Yang Song, Stefano Ermon

- Stanford University

논문 링크

Official

https://proceedings.neurips.cc/paper/2019/file/3001ef257407d5a371a96dcd947c7d93-Paper.pdf

 

Arxiv

https://arxiv.org/abs/1907.05600

 

Generative Modeling by Estimating Gradients of the Data Distribution

We introduce a new generative model where samples are produced via Langevin dynamics using gradients of the data distribution estimated with score matching. Because gradients can be ill-defined and hard to estimate when the data resides on low-dimensional

arxiv.org

 

 

논문 Summary

Abstract

 

 

0. 설명 시작 전 Overview

 

이 논문을 2 문장으로 요약하면 다음과 같다.

 

1) 저차원 manifold 문제에서 score가 정의되고 score matching이 가능하도록 다양한 종류의 Gaussian noise를 데이터 분포에 추가함으로써 데이터 분포의 grdient를 통한 score matching이 가능하게 한다.

 

2) 모든 level의 noise를 추가한 데이터 분포의 gradient를 활용하여 score network를 학습시킨 후 annealed Langevin dynamics를 통해 데이터를 sampling한다. 

 

1. Introduction

 

최근 생성 모델은 크게 2가지 접근 방법이 존재한다.

1) likelihood-based 방법 - log-likelihood를 training objective로 활용

https://yang-song.net/blog/2021/score/

2) GAN - f-divergence를 최소화하는 adversarial training

https://yang-song.net/blog/2021/score/

 

훌륭한 성과에도 각 방법에는 한계점이 존재한다.

1) likelihood-based 방법 - normalized 확률 모델을 설계하기 위한 특별한 architecture(autoregressive model, flow model)가 사용되거나 대체 loss가 사용 된다 (VAE의 ELBO, EB 모델의 contrasive divergence)

2) GAN - adversarail training 때문에 불안정한 학습을 진행, 평가에 어려움이 존재

 

본 논문에서는 input data 지점에서의 log density의 gradient를 활용하는 logarithmic data density의 score를 활용하여 추정하고 sampling을 통한 생성 모델을 제안한다.

1) data의 vector field를 학습하기 위해 score matching을 neural network에 훈련 시킨다.

2) Langevin dynamics를 통해 sample을 생성한다.

 

그러나 여기에도 2가지 문제가 발생

1) 실제 세계에서의 데이터세트가 그러하듯 데이터 분포가 low dimensional manifold에 존재한다면 score는 ambient space에서 정의되지 않고 score matching도 일관된 score 추정치를 제공하는데 실패한다.

(참조: 여기서의 score는 데이터 분포의 log-gradient라고 생각하시면 됩니다.)

2) low data density 영역에서 훈련 데이터의 희소성(예 : manifold로부터 멀어진 경우)은 score estimation의 정확도를 방해하고 Langevin dynamics sampling의 mixing을 느리게 한다.

 

두 문제를 해결하기 위해

1) 다양한 크기의 random Gaussian noise를 data에 perturb한다.

- random noise를 주입하는 것은 low dimension manifold에 국한되지 않게 한다.

- 모든 noise level로 조건화된 단일 score network를 학습하고 모든 noise 크기에 대해 score를 추정한다. 

2) annealed version of Langevin dynamics를 제안한다.

 

이를 통해 제안한 objective는 score network의 모든 파라미터가 tractable하고 어떠한 구조적 제약을 받지 않도록한다.

또한, 다른 모델들과도 정량적 비교가 가능하다.

 

2. Score-based generative modeling

 

가정 : $\{ x_i \in \mathbb{R}^D\}_i^N$는 i.i.d. dataset from $p_{data}(x)$.

Score : $\nabla_x \log p(x)$

Score network : $s_\theta : \mathbb{R}^D \to \mathbb{R}^D$  ($\theta$로 파라미터화된 neural network)

 

Score-based generative modeling의 2가지 요소

1) Score matching

2) Langevin dynamics 

 

2.1 Score matching for score estimation

Score matching을 사용하여 $\nabla_x \log p(x)$를 추정하는 score network인 $s_\theta$를 훈련한다.

objective인 $\frac{1}{2} \mathbb{E}_{p_{data}}[\| s_\theta(x) - \nabla_x \log p_{data}(x) \|_2^2]$를 최소화

Score matching

A. Hyvärinen. "Estimation of non-normalized statistical models by score matching." Journal of Machine Learning Research, 6(Apr):695–709, 2005.

https://www.jmlr.org/papers/volume6/hyvarinen05a/hyvarinen05a.pdf

 

다만 score matching은 $tr(\nabla_x s_\theta(x))$의 계산량 때문에 고차원 데이터와 deep network에는 scalable하지 않다.

 

이에 large scale score matching에서 2가지 유명한 방법을 논의한다.

 

2.1.1 Denoising score matching

 

$tr(\nabla_x s_\theta(x))$을 회피하기 위해 score matching의 변화를 준 것이 Denoising score matching이다.

사전 정의된 noise distribution $q_\sigma(\tilde{x}|x)$

perturbed data distribution $q_\sigma(\tilde{x}) = \int q_\sigma (\tilde{x} \,|x) p_{data} dx$의 score를 추정하기 위해 score matching을 활용한다. 

 

하지만 $s_\theta^* (x) = \nabla_\tilde{x} \log q_\sigma (\tilde{x} | x) \approx \nabla_x \log p_{data}(x)$가 참(true)이기 위해서는 noise가 매우 작아야만 가능하다.

 

2.1.2 Sliced score matching

 

Sliced score matching은 $tr(\nabla_x s_\theta(x))$을 근사하기 위해 random projection을 사용한다.

 $v^T\nabla_x s_\theta(x)v$는 forward mode auto-differentiation에 의해 효율적으로 계산할 수 있다.

unperturbed data distribution에서도 사용할 수 있으나 forward mode auto-differentiation 때문에 4배의 계산량이 필요하다.

 

2.2 Sampling with Langevin dynamics

Langevin dynamics는 score function $\log p_{data}(x)$만을 사용하여 probability density로부터 sample을 생성할 수 있다.

 

stochastic process의 각 step마다 recursive하게 계산한다.

$\epsilon \rightarrow 0, T \rightarrow \infty$일 때 $p(x)$에서 정확한 샘플을 계산할 수 있지만 실제로는 그렇지 않기 때문에 $\epsilon$이 작고 $T$가 클 때의 error는 무시한다.(자세한 이야기는 불필요해서 생략.)

 

고로 $p_{data} (x)$로부터 샘플을 획득하기 위해서 

1) $s_\theta^* (x)  \approx \nabla_x \log p_{data}(x)$에 해당하는 score network를 훈련시킨다.

2) $s_\theta(x)$를 사용해서 Langevin dynamics로부터 샘플을 획득한다.

 

3. Challenges of score-based generative modeling

 

3.1 The manifold hypothesis

 

Manifold hypothesis란 실제 세상 속 데이터는 고차원 공간을 포함한 low demensional manifold에 집중되는 경향이 있다는 것을 의미한다. (ambient space) 

본 가정 아래 score-based generative model은 2가지 어려움을 만난다.

1) data x가 low demensional manifold에 국한될 때 data의 score를 정의할 수 없다.

-> score는 $\nabla_x \log p_{data}(x)$이므로 gradient를 구할 수 없으니 정의 불가.

2) data distribution의 support(저는 영역이라 판단함.)가 whole space일 때만 score matching objective가 일관된 score estimator를 제공한다. 그리고 data가 low demensional manifold에 존재한다면 일관되지 않는다.

 

 

Figure 1 (좌)는 ResNet을 CIFAR-10에서 Sliced score matching을 통한 score 추정을 진행했을 때의 결과이다. 그림에서 확인할 수 있듯 manifold hypothesis 하에서 어려움을 겪는 것을 확인할 수 있다.

반면 data에 정말 약간의 Gaussian noise를 perturb줄 때 loss curve는 수렴하는 것을 확인할 수 있다.(Figure 1 (우))

이는 perturbed data distrubution이 $\mathbb{R}^D$로 온전히 support되기 때문이다.

 

참조) data에 Gaussian noise를 넣어주면 low demensional manifold에서 벗어나 $\mathbb{R}^D$로 support 된다.

 

3.2 Low data density regions

 

Low density region(낮은 밀도 영역)에서의 데이터 희소성은 score matching을 활용한 score estimation 과 Langevin dynamics를 활용한 MCMC sampling의 어려움의 원인이 된다.

 

3.2.1 Inaccurate score estimation with score matching

 

 

Low density region에서 데이터 샘플의 부재로 score matching은 socre function을 정확히 추정하는데 어려움이 있을 가능성이 있다. 반면 data density가 높은 곳에서는 score estimation이 유효하다.

 

3.2 Slow mixing of Langevin dynamics

 

Low density region에 의해 data distribution의 2 모드가 분리된다면 Langevin dynamics는 2 모드의 상대적 weight를 정확하게 회복할 수 없으며 true distribution이 수렴하지도 않을 것이다.

 

예를 들어 $p_{data} (x) = \pi p_1 (x) + (1-\pi) p_2(x)$와 같은 mixture distribution이 있다고 가정하자.

이때 $\nabla_x \log p_{data}(x)$는 $\pi$에 의존하지 않기 때문에 Langevin dynamics에서는 정확한 $\pi$를 알 수 없고 결국 Langevin dynamics는 작은 step size와 많은 수의 step이 요구 받는다.

 

 

Figure 3 (a)를 닮아야하는 Langevin dyamics는 Low density region의 문제 때문에 정확한 $\pi$를 알 수 없고 결국 생성된 sample은 원본과 정확하지 않은 것을 생성한다.

 

4. Noise Conditional Score Networks: learning and inference

 

Intuition

1) Gaussian noise distribution의 support가 whole space가 되므로 perturbed data는 low dimensional manifold에 국한되지 않게 되고 이는 manifold hypothesis로부터 회피하고 score estimation이 잘 정의되도록 한다.

2) Large Gaussian noise는 low density region을 채우는 효과가 발생하므로 score matching은 더 향상된 score estimation이 가능하게 한다.

3) 다수의 noise level을 사용함으로써 true distribution이 수렴할 수 있는 noise-perturbed distribution의 sequence를 획득한다. 

https://yang-song.net/blog/2021/score/

이에 따라

1) 다양한 noise를 사용한 perturbing data를 만들고

2) 단일 conditional score network를 훈련함에 따라 모든 noise level과 상응하는 score를 동시에 추정함으로써

=> 향상된 score-based generative modeling을 제안한다.

 

Langevin dynamics를 통한 Sampling에 있어서도 큰 노이스부터 점진적으로 줄여가는 anneal down을 진행함으로써 score를 통한 sampling을 진행한다.

 

4.1 Noise Conditional Score Networks(NCSN)

 

$\{\sigma_i\}_{i=1}^L$은 등비수열로 $\sigma_1 < \sigma_2 < \cdots < \sigma_L$을 만족.

$q_{\sigma}(x) \triangleq \int p_{data}(t) \mathcal{N}(x|t, \sigma^2 I)$가 perturbed data distribution이라 하자.

이때 $x \in \mathbb{R}^D$일 때, conditional score network 또한 $\mathbb{R}^D$에 support함에 따라 정의 되는 score network $s_\theta (x, \sigma)$를 Noise Conditional Score Networks(NCSN)라 부르기로 하자.

 

$s_\theta (x, \sigma)$는 dilated/astrous conv를 포함하는 U-Net 구조이며 $\sigma$를 조율하는 conditional instance normalization을 사용한다. 자세한 이야기는 Appendix A 참조.

 

4.2 Learning NCSNs via score matching

 

Sec 2.1.1에서 다룬 denoising score matching을 조금 더 빠르기 때문에 score matching에 사용한다. sliced score matching도 사용가능하다는 점 유의.

 

$q_\sigma(\tilde{x} \,|x) = \mathcal{N}(\tilde{x} \, \| x, \sigma^2 I)$라고 Noise distribution을 정의할 때

$\sigma$가 주어지면 denoising score matching objective는 다음과 같이 정의된다.

 

모든 $\sigma$에 대하여 합친 objective는 다음과 같이 정의된다.

 

정의된 objective가 $\sigma$에 의존적이지 않게하기 위해 가정하는 것들은 생략

이것만 기억!

$\lambda(\sigma) = \sigma^2$로 선택!

 

4.3 NCSN inference via annealed Langevin dynamics

 

 

5. Experiments

CelebA의 경우 140x140으로 center-crop 이후 32x32로 resize

L=10, $\sigma_1=1, \sigma_{10}=0.01$

T=100, $\epsilon=2 \times 10^{-5}$, 초기 uniform noise로 초기화

 

Appendix A. Architecture

 

Instance normalization

 

Dilated convolutions

 

U-Net

 

GPU

 

Dataset : MNIST  (1 Titan XP GPU)

Dataset : CelebA and CIFAR-10 (2 Titan XP GPUs)

 

Reference

공식 Github

https://github.com/ermongroup/ncsn

 

GitHub - ermongroup/ncsn: Noise Conditional Score Networks (NeurIPS 2019, Oral)

Noise Conditional Score Networks (NeurIPS 2019, Oral) - GitHub - ermongroup/ncsn: Noise Conditional Score Networks (NeurIPS 2019, Oral)

github.com

 

도움이 되는 YouTube

1. Yang Song(1저자) NIPS 2019 Oral 발표

 

https://crossminds.ai/video/generative-modeling-by-estimating-gradients-of-the-data-distribution-6070ac11fa08279acdb219f0/

 

Generative Modeling by Estimating Gradients of the Data Distribution - Crossminds

We introduce a new generative model where samples are produced via Langevin dynamics using gradients of the data distribution estimated with score matching. Because gradients might be ill-defined when...

crossminds.ai

 

2. 

 

 

 

 

 

도움이 되는 블로그

1. Yang Song 공식 Blog

 

https://yang-song.net/blog/2021/score/

 

Generative Modeling by Estimating Gradients of the Data Distribution | Yang Song

Generative Modeling by Estimating Gradients of the Data Distribution This blog post focuses on a promising new direction for generative modeling. We can learn score functions (gradients of log probability density functions) on a large number of noise-pertu

yang-song.net

 

2. Yang Song 공식 Blog

 

 

3. Yang Song 공식 Blog

 

 

 

 

 

 

 

 

 

0000 

공유하기

facebook twitter kakaoTalk kakaostory naver band
loading