논문리뷰[2] - VAE(Variational AutoEncoder)

Leejaegun·2024년 8월 28일
2

논문리뷰

목록 보기
4/10
post-thumbnail

드디어 VAE 리뷰를 해본다..! 쉽지 않고 까다롭지만 그만큼 얻어가는게 많은 논문이다.

0. Abstract

How can we perform efficient inference and learning in directed probabilistic models, in the presence of continuous latent variables with intractable posterior distributions, and large datasets?

본 논문은 ①다루기 어려운(intractable)한 사후(posterior) 확률 분포를 가진② 연속적인(continuous) 잠재변수(latent variables) 와 대규모 데이터셋이 있는 경우, 어떻게 하면 ③방향성모델(directed probabilistic models) 에서 효율적인 추론과 학습을 진행할 수 있을까? 에서 시작한다.

😓 첫 문장부터 해석이 쉽지 않다. 차근차근히 하나씩 해보자.

①다루기 어려운(intractable)한 사후(posterior) 확률 분포 :
잠재 변수를 관찰할 수 없기 때문에, 그 변수가 특정한 값을 가질 확률(사후분포)를 계산하는 것이 어렵거나 불가능할 수 있습니다.

② 연속적인(continuous) 잠재변수(latent variables):
모델에서 직접적으로 관찰할 수 없는 숨겨진 변수인데, 그 값이 연속적이다.

③방향성모델(directed probabilistic models):
베이지안 네트워크로 변수들 사이의 관계를 화살표가 있는 그래프로 나타내는 모델임!

=> 즉, VAE 의 목표는 아주 다루기 어려운 posterior distribution 을 가진 연속 잠재변수를 가진 모델로부터 효율적으로 inference 및 학습을 시키는 것..

모델을 도식화해보면 다음과 같다.

  • zz 는 잠재변수 xx 는 관측된 데이터

  • pθ(z)pθ(xz)p_{\theta}(z) p_{\theta}(x \mid z) 는 사후분포

  • qϕ(zx)q_{\phi}(z \mid x) 는 사후분포 pθ(z)pθ(xz)p_{\theta}(z) p_{\theta}(x \mid z)<- 이거를 근사하기 위해서 사용하는 것.

  • 즉,qϕ(zx)q_{\phi}(z \mid x)zz 가 주어진 xx에 대해 어떻게 분포하는지를 나타내는 근사모델임

검은색 실선은 일반적인 generative model, pθ(z)pθ(xz)p_{\theta}(z) p_{\theta}(x \mid z) 을 나타낸 것이다. 하지만 이 경우 실제 dataset의 poserior 분포 pθ(zx)p_{\theta}(z \mid x) 을 알아내기란 불가능!! 왜냐하면 pθ(x)p_{\theta}(x) 를 모르기 떄문에 ㅠㅠ 그래서 이것을 근사하여(variational approximation) 하여 qϕ(zx)q_{\phi}(z \mid x) (검은색 점선) 을 두어 posterior 를 모델링 할 수 있도록 하는 것. ϕ{\phi}θ{\theta} 는 모두 학습되는 parameter임.

We introduce a stochastic variational inference and learning algorithm that scales to large datasets and, under some mild differentiability conditions, even works in the intractable case.

✍ 우리가 다루기 어려운 경우(intractable case) 에서도 작동하는 stochastic variational inference and learning algorithm 제안할꼐!!

Our contributions are two-fold. First, we show that a reparameterization of the variational lower bound yields a lower bound estimator that can be straightforwardly optimized using standard stochastic gradient methods.

✍ 위 논문의 기여는 2가지인데 . 첫번째는) variational lower bound의 reparameterization이 표준적인 stochastic gradient 방법론들을 사용하여 직접적으로 최적화될 수 있는 lower bound estimator를 만들어낸다는 것을 보였다.
=> 이거는 다시 해석할 필요가 있다.

  • 변분하한(variational lower bound) : 복잡한 확률분포를 직접 계산하는 대신, 계산이 쉬운 대체분포를 사용하여 근사하는 방법

  • 재매개변수화(reparameterization) : 복잡한 확률분포를 표준적인(쉽게 다룰 수 있는) 분포로 변환하는 기법

-> 즉, 쉽게 하는 방법을 만들었다는 말을 어렵게 한거임.

Second, we show that for i.i.d. datasets with continuous latent variables per datapoint, posterior inference can be made especially efficient by fitting an approximate inference model (also called a recognition model) to the intractable posterior using the proposed lower bound estimator.
Theoretical advantages are reflected in experimental results.

✍ 두번째) 각 datapoint가 연속형 잠재 변수를 가지는 i.i.d. 데이터셋에 대해서, 위에서 제안된 lower bound estimator를 사용해 approximate inference model(또는 recognition model)을 계산이 불가능한 posterior에 fitting 시킴으로써 posterior inference가 특히 효율적으로 만들어질 수 있다는 점을 보인다.

1. Introduction

How can we perform efficient approximate inference and learning with directed probabilistic models whose continuous latent variables and/or parameters have intractable posterior distributions? The variational Bayesian (VB) approach involves the optimization of an approximation to the intractable posterior

🤔 연속적인 잠재 변수 혹은 파라미터에서 풀 수 없는 사후 분포(intractble posterior distribution)을 가지는 directed probabilistic model을 효율적으로 근사치에 추정하고 학습할 수 있을까??
=> ✍ VB(Variational Bayesian) 접근 방식은 다루기 힘든 사후확률에 대한 근사의 최적화를 포함함 -> 논문 저자는 VB가 답이라고 함.

We show how a reparameterization of the variational lower bound yields a simple differentiable unbiased estimator of the lower bound;
this SGVB (Stochastic Gradient Variational Bayes) estimator can be used for efficient approximate posterior inference in almost any model with continuous latent variables and/or parameters

✍ SGVB를 통해 근사 사후확률을 추정하고 standard stochastic gradient 를 통해 최적화 가능

we propose the AutoEncoding VB (AEVB) algorithm. In the AEVB algorithm we make inference and learning especially efficient by using the SGVB estimator to optimize a recognition model that allows us to perform very efficient approximate posterior inference using simple ancestral sampling, which in turn allows us to efficiently learn the model parameters, without the need of expensive iterative inference schemes(such as MCMC) per datapoint

✍ AEVB(Auto-Encoding VB) 알고리즘을 제안하는데, 이는 효율적인 근사적 사후 추론과 모델 매개 변수의 효율적인 학습을 가능하게 한다고 함!

2. Method

The strategy in this section can be used to derive a lower bound estimator (a stochastic objective function) for a variety of directed graphical models with continuous latent variables. We will restrict ourselves here to the common case where we have an i.i.d. dataset with latent variables per datapoint,and where we like to perform maximum likelihood (ML) or maximum a posteriori (MAP) inference on the (global) parameters, and variational inference on the latent variables

✍ lower bound estimator 를 유도하는 전략
① data point 마다 잠재변수가 있는 iid data set 이라고 가정
② 이 가정하에서 전역 파라미터에 ML(Maximum Likelihood)나 MAP 추론을 수행
③ 잠재변수에는 변분(variational) 추론을 할려고 함.

  • 여기서 변분추론이란, 복잡한 후방 분포를 최적화 문제로 변환하여, 단순한 분포로 근사하는 방법을 가리킴. 변분(variational)이란 용어를 쓰는 이유는 함수의 최적화를 다루는 수학적 기법을 변분법이라고 하는데 여기서 쓰이게 됨.

2.1 Problem Scenario

Let us consider some dataset X={x(i)}i=1NX = \{{x^{(i)}}\}^N_{i=1} consisting of NN i.i.d. samples of some continuous or discrete variable x.

위와 같은 X={x(i)}i=1NX = \{{x^{(i)}}\}^N_{i=1} N개의 i.i.d 샘플로 구성된 데이터 셋을 고려함.
z : 관측되지 않은 연속랜덤함수 z
x : z를 포함하는 어떠한 랜덤 프로세스에 의해서 생성

이 dataset 각 x를 생성하는 과정은 크게 두가지로 나뉨.
① 잠재변수 ziz^{i} 는 사전분포 pθ(z)p_{\theta}(z)에서 생성
x(i)x^{(i)} 는 조건부확률 pθ(xz)p_{\theta}(x \mid z) 에서 생성.

prior 과 likelihood 는 parametric 한 distribution pθ(z)p_{\theta}(z)pθ(xz)p_{\theta}(x \mid z) 로 나타낼 수 있다고 가정함 하지만 실제 parameter θ{\theta} 의 값과 random variable z(i)z^{(i)} 를 모르기에 모델링은 매우 어럽다

Very importantly, we do not make the common simplifying assumptions about the marginal or posterior probabilities. Conversely, we are here interested in a general algorithm that even works efficiently
in the case of: Intractability, A large dataset:

✍ 여기서 중요한 점은 posterior 을 구하기 위한 값 중 marginal probability p(x) 를 쉽게 이용할 수 있다는 가정은 하지 않았고 단지 우리 모델은 Intractability 와 large dataset 에도 잘 작동하도록

We are interested in, and propose a solution to, three related problems in the above scenario:
1. Efficient approximate ML or MAP estimation for the parameters θ. The parameters can be of interest themselves, e.g. if we are analyzing some natural process. They also allow us to mimic the hidden random process and generate artificial data that resembles the real data.

2. Efficient approximate posterior inference of the latent variable z given an observed value x for a choice of parameters θ. This is useful for coding or data representation tasks.

3. Efficient approximate marginal inference of the variable x. This allows us to perform all kinds of inference tasks where a prior over x is required. Common applications in computer vision include image denoising, inpainting and super-resolution

✍ 본 논문에서는 3가지 문제에 대해 관심이 있고 해결책을 제안.
① 파라미터 θ\theta 에 대한 효율적인 ML,MAP 추정
-> 매개변수 자체에 관심을 갖는 것이고 이러한 파라미터를 사용하여 숨겨진 무작위 과정을 모방하고 실제 데이터와 유사한 가상 데이터를 생성할 수 있다.

② 파라미터 θ\theta 의 선택에 따른 관측값 x가 주어졌을때, 효과적인 근사치 사후 추정 pθ(xz)p_{\theta}(x \mid z)
-> 데이터 표현화에 유리함.

③ 변수 xx 의 효율적인 approximation marinal inference
-> x에 대한 사전분포가 필요한 모든 추론 작업을 수행할 수 있다.

For the purpose of solving the above problems, let us introduce a recognition model qφ(z|x): an approximation to the intractable true posterior pθ(z|x).. Note that in contrast with the approximate posterior in mean-field variational inference, it is not necessarily factorial and its parameters φ are not computed from some closed-form expectation. Instead, we’ll introduce a method for learning the recognition model parameters φ jointly with the generative model parameters θ.

qϕ(zx)q_{\phi}(z \mid x) 가 드디어 나온다!! 위와 같은 문제를 풀기위해 qϕ(zx)q_{\phi}(z \mid x)를 소개한다

  • qϕ(zx)q_{\phi}(z \mid x) : 추론하기 어려운 실제 사후분포(true posterior) pθ(xz)p_{\theta}(x \mid z) 근사치.

한번 정리해보자

  • qϕ(zx)q_{\phi}(z\mid x) : 데이터 포인터 xx 가 주어지면 xx 가 생성될 수 있는 코드 zz 의 가능한 값들에 대한 분포를 생성하는 확률적 인코더

  • pθ(xz)p_{\theta}(x \mid z) : zz가 주어지면 해당하는 xx 의 가능한 값들에 대한 분포를 생성하는 확률적 디코더

목표 : data likelihood 인 pθ(x)=pθ(z)pθ(xz)dzp_{\theta}(x) = \int p_\theta(z) p_\theta(x|z) \,dz 를 최대화 하는 것.
하지만 모든 zz에 대해서 pθ(xz)p_{\theta}(x \mid z)를 계산하는 것은 불가능함.(어찌보면 당연..!! zz 자체를 잘 모르는데 조건부를 어떻게 계산함..)

그래서 당연스럽게도, pθ(zx)=pθ(xz)pθ(z)pθp_{\theta}(z \mid x) = \frac{p_{\theta}(x \mid z)p_{\theta}(z)}{p_{\theta}} 도 계산을 할 수 없음 (pθ(x)p_{\theta}(x)를 알 수 없으니까)

그래서 똑똑한 양반들이 "어떻게 하면 확률적 디코터 pθ(xz)p_{\theta}(x\mid z ) 를 잘 만들어서, 실제 xx값과 유사한 확률분포를 만들어 낼 수 있을까?" 의문을 가짐
-> 네트워크 출력값이 있을 때 우리가 원하는 정답 x가 나올 확률을 높길 바람

=>xx의 likelihood 의 최대화하는 확률 분포를 찾자
=> Maximize pθ(x)=pθ(z)pθ(xz)dzp_{\theta}(x) = \int p_{\theta}(z)p_{\theta}(x \mid z)dz
=>확률적 디코더인 pθ(xz)p_{\theta}(x \mid z)를 계산하는 것은 불가능 하기에 encoder network인
qϕ(zx)q_{\phi}(z \mid x) 를 추가하여 대신 근사화!!

(이런걸 어떻게 생각함..)


2.2 the Variational bound

우리가 원하는 것은 결국 xx에 관한 marginal likelihood logPθ(x)marginal\ likelihood\ logP_{\theta}(x)의 값임!!

The marginal likelihood is composed of a sum over the marginal likelihoods of individual datapoints:  log pθ(x(1),,x(N))=i=1Nlogpθ(x(i))\ log\ p_{\theta}(x^{(1)}, \ldots, x^{(N)}) = \sum_{i=1}^{N} \log p_{\theta}(x^{(i)})

✍ marinalization 한다는 것은 주변 확률의 경우의 수를 모두 고려한다는 뜻이므로 \sum 해서 주변 모수들을 모두 고려한 우도를 계산한다는 것이다.

Each term can be rewritten as:
logpθ(x(i))=DKL(qϕ(zx(i))pθ(zx(i)))+L(θ,ϕ;x(i))\log p_{\theta}(x^{(i)}) = \text{D}_{KL}(q_{\phi}(z \mid x^{(i)}) \| p_{\theta}(z \mid x^{(i)})) + L(\theta, \phi; x^{(i)})

①The first term on the right-hand side (RHS) is the KL divergence of the approximate posterior from the true posterior. Since this KL divergence is non-negative,
_
②the second term L(θ,ϕ;x(i)))L(\theta, \phi; x^{(i)})) is called the (variational) lower bound on the marginal likelihood of datapoint x(i)x(i), and can be written as:

[logpθ(x(i))L(θ,ϕ;x(i))=Eqϕ(zx(i))[logqϕ(zx(i))+logpθ(x(i),z)]][ \log p_{\theta}(x^{(i)}) \geq L(\theta, \phi; x^{(i)}) = \mathbb{E}{q{\phi}(z \mid x^{(i)})} \left[ -\log q_{\phi}(z \mid x^{(i)}) + \log p_{\theta}(x^{(i)}, z) \right] ]


① 첫번째 항은, 참 후방분포(true posterior) 와 근사후방분포(approximate posterior) 간의 KL 발산을 의미한다.
->KL 발산이 비음수라는 성질을 이용해, 이 차이를 줄이도록 근사 후방 분포를 조정함
(헷깔릴까봐 적어둠) 근사후방분포는 qϕ(zx)q_{\phi}(z \mid x) 이거고 진짜후방분포는 pθ(zx)p_{\theta}(z \mid x)임 두개의 분포의 차이가 DKLD_{KL})

② 두번째 항은, 변분하한(variational lower bound) 이다. => ELBO 임!!

두번째 항은 이렇게도 바꿀 수 있다.(증명 생략)

L(θ,ϕ;x(i))=DKL(qϕ(zx(i))pθ(z))+Eqϕ(zx(i))[logpθ(x(i)z)]L(\theta, \phi; x^{(i)}) =-D_{KL}(q_{\phi}(z \mid x^{(i)})||p_{\theta}(z))+\mathbb{E}_{q{\phi}}(z \mid x^{(i)})[logp_{\theta}(x^{(i)}|z)]
-> 우리는 이 lower bound 을 variational parameter인 ϕ\phi와 generative parameter 인 θ\theta 에 대해서 모두 최적화하고 싶은것. 하지만 이 lower bound 로 gradient를 흘려보내 주는 것은 약간의 문제가 있는데 , 이 경우에 monte carlo gradient estimator는 분산이 커서 우리의 목적에는 실용적이지 않다고 한다,,!


여기서 잠깐!!
🤔 ELBO(Evidence Lower Bound) 란 무엇인가?

  • ELBO는 주변 가능도(Evidence) 또는 데이터의 우도에 대한 하한을 제공하는 함수로, 이는 변분 추론에서 사용되는 주요 도구이며 변분 추론의 목적은 이 ELBO를 최대화하는 것!!
    -> 왜냐하면 ELBO 가 데이터 우도에 대한 하한을 제공하면서 이를 최대화하여 복잡한 후방분포를 근사화 할 수 있는 것임

  • 수식: L(θ,ϕ;x(i))L(\theta, \phi; x^{(i)})$


2.3 The SGVB estimator and AEVB algorithm

Under certain mild conditions outlined in section 2.4 for a chosen approximate posterior qϕ(zx)q_{\phi}(z \mid x) we can reparameterize the random variable(zqϕ(zx)( z \sim q_{\phi}(z \mid x) using a differentiable transformation gϕ(ϵ,x)g_{\phi}(\epsilon,x) of an (auxiliary) noise variable :

z=gϕ(ϵ,x) with ϵp(ϵ)z = g_{\phi}(\epsilon, x) \text{ with } \epsilon \sim p(\epsilon)

✍ 최적화하고 싶은 식을 어떻게 optimize 할 건지 estimator를 찾아야 하는데 본 논문 저자는 mild 한 조건이 있다면 posterior를 다음과 같이 reparametetrize 할 수 있다고 봤다.

  • SGVB (Stochastic Gradient Variational Bayes) 추정기는 변분 추론에서 사용되는 기법. 주요 내용은 다음과 같다:
    근사 후방 분포 qϕ(zx)q_{\phi}(z \mid x)를 사용하여 변분 하한 L(θ,ϕ;x(i))L(\theta, \phi; x^{(i)})을 추정. SGVB 추정기는 몬테 카를로(Monte Carlo) 샘플링을 사용하여 기대값을 근사합니다.

  • AEVB (Auto-Encoding Variational Bayes) 알고리즘
    AEVB 알고리즘은 변분 추론에서 미니배치(minibatch)를 사용하여 SGVB 추정기를 최적화하는 방법입니다. 구체적인 알고리즘은 밑에 것과 같다.

2.4 The reparameterization trick

xx가 가우시안 인코더로 들어가면, 뮤와 시그마를 output으로 뱉습니다. 여기서 이 뮤와 시그마를 통해 정규분포를 만들고, 여기서 zz를 샘플링하는데 zz 자체를 sampling한다면 random 연산은 미분이 불가능하기에 gradient backward가 불가능하게 됩니다. 그렇기에 reparameterization trick을 이용합니다.

reparameterization trick은 표준정규분포에서 입실론을 샘플링한 후에, 이를 인코더에서 나온 시그마와 곱하고 뮤를 더해 z를 만들어주는 것. 이렇게 만들어진 z는 뮤와 시그마로 표현이 가능하게 되어z=μ+σεz =μ+σㆍε(: element-wise 곱) 미분이 가능하게 되고 back propagation이 가능하게 됨

이렇게 만들어진 z가 디코더를 통과하면 원래의 input x값과 비슷하게 생긴 output을 복원시키게 된다.

->Reparameterization Trick 원래의 샘플링 과정을 미분 가능하게 변환하여, 신경망의 학습 과정에서 기울기를 계산하고 파라미터를 업데이트할 수 있게 해줌.이를 통해 생성된 𝑧𝑧는 인코더에서 출력된 μμσσ를 사용하여 생성되며, 디코더를 통해 원래의 입력 xx와 비슷한 출력을 생성하는 데 사용.-> 역전파를 위해 필수적

3. Example: Variational Auto-Encoder

오토인코더(AE)에서는 각 이미지가 잠재 공간의 한 포인트에 직접 매핑되는 반면에, VAE는 각 이미지가 잠재 공간에 있는 포인트 주변의 다변량 정규분포에 매핑된다.

4. Related Work

5. Experiment

6. Conclusion

profile
Lee_AA

0개의 댓글

관련 채용 정보