SlideShare a Scribd company logo
Variational Inference
Deeplearning chapter 19
민다빈
Variational Autoencoder
2
잠재변수 𝑧
데이터 𝑥
우도함수 𝑝(𝑥|𝑧)
𝑧의 사전확률 𝑝(𝑧)
𝑥의 사전확률 𝑝 𝑥
𝑧가 주어진 상황에서 𝑥가 나타날 확률 𝑝 𝑥 𝑧 : 우도
𝑥가 주어진 상황에서 𝑧가 나타날 확률 𝑝 𝑧 𝑥 : 사후확률
사후확률 𝑝(𝑧|𝑥)를 알기 어렵기 때문에 근사하는 간단한
함수를 찾음 𝑞(𝑧) 또는 𝑞(𝑧|𝑥)
Variational inference
흰색: 잠재변수(z)
회색: 관측변수(x)
- 주어진 데이터(𝑥)와 주어지지 않은 잠재변수(𝑧)가 모델에 관여하는 상황.
- 어떤 잠재변수로부터 주어진 데이터를 만들어낼 확률𝑝(𝑥|𝑧)이 가장 높은 모델과, 그때 최적의
잠재변수를 만드는 함수 𝑝(𝑧|𝑥)를 찾아야한다고 생각해보자.
- 이 때, 사후확률 분포 𝑝(𝑧|𝑥) 를 계산하는 것이 불가능에 가까울 정도로 어려운 경우가 많다.
잠재변수간 상호작용 때문에 marginal probability 계산이 힘들다.
Marginal probability: 𝑝(𝑥) = σ 𝑧 𝑝(𝑥, 𝑧)
3
Variational inference
VI란 사후확률(posterior) 분포 𝑝(𝑧|𝑥)를 다루기 쉬운 확률분포 𝑞(𝑧)로 근사(approximation)하는 것
사후확률 분포를 우리가 익히 알고 있는 정규분포로 근사한 경우
4
Variational inference
사후확률 𝑝(𝑧|𝑥)에 근사한 𝑞(𝑧)를 만들기 위해 두 분포의 차이를 줄여야 함.
→ 두 확률분포의 차이를 계산하는 KL-Divergence 개념 활용
사후확률 분포 𝑝(𝑧|𝑥)와 𝑞(𝑧) 사이의 KLD를 계산하고, KLD가 줄어드는 쪽으로 𝑞(𝑧)를 조금
씩 업데이트하는 과정을 반복하면 사후확률을 잘 근사하는 𝑞∗
(𝑧)를 얻게 될 것
→ 이 과정이 Variational Inference
KLD를 줄어들게 하는데 몇가지 방법이 있음.
5
Variational inference
이 KLD를 줄어들게 하는데 몇가지 방법이 있음.
우리가 최소화하고자 하는 KLD를 정리해보면,
6
1. Variational Inference with Monte Carlo
Sampling
몬테카를로 방법(Monte Carlo Method): 랜덤 표본을 뽑아 함수의 값을 확률적으로 계산하는 방법.
이를 이용하여 KLD 텀에 대한 근사식을 유도
7
1. Variational Inference with Monte Carlo
Sampling
실제 문제에서는 사후확률 분포𝑝(𝑧|𝑥)에 대해 아무런 정보가 없지만 몬테카를로 방법을
이용하면 𝑞(𝑧)를 어떤 분포로든 설정할 수 있다.
Ex) 사후분포에 대한 정보가 없어서 𝑞(𝑧)를 정규분포로 정해 볼 경우
1. 이 정규분포에서 K개의 z들을 뽑으면 KLD의 근사값을 계산 가능.
2. 정규분포의 파라메터(평균, 분산)를 조금씩 바꿔가면서 KLD 근사값을 최소로 하는
파라메터를 구할 수 있을 것.
3. 구해진 정규분포가 바로 VI의 결과.
≈
8
2. Variational Inference with SGD
KLD를 줄이는 방향으로 𝑞(𝑧)의 파라메터를 업데이트 하여 VI하는 것도 가능
→ Gradient를 계산하기 위해 KLD가 미분가능 해야함
Ex)
𝑞 𝑧 는 정규분포 𝜃 𝑞 = 𝜇 𝑞, 𝜎 𝑞 , 𝑝 𝑧 는 베타분포 𝛼, 𝛽 라고 두고 𝐾𝐿𝐷 식을 𝜃 𝑞에 대해 미분해 보자.
(적절한 𝜃 𝑞를 추론하려 하는것)
이때, z가 𝜃 𝑞를 파라메터로 갖는 𝑞에 의해 랜덤 샘플링되기 때문에 𝜃 𝑞 에 대한 미분이 불가능
→ z대신 노이즈를 샘플링해서 z를 계산하는 reparameterization trick 사용
9
2. Variational Inference with SGD
여기서도 몬테카를로 샘플링을 이용하여 KLD의 gradient 근사값을 계산.
→ Gradient 이용하여 𝜃 𝑞를 수정함으로써 사후확률 분포 𝑝(𝑧|𝑥)에 근사하는 𝑞(𝑧)를 찾을 수 있다.
10
Vatiational EM algorithm
- 지금까지는 사전확률함수 𝑝 𝑧 와 우도함수 𝑝 𝑥 𝑧 를 이미 알고 있다는 전제 하에 𝑝 𝑧 𝑥
에근사하는 𝑞 𝑧 를 찾는 𝑉𝐼 과정을 설명하였음.
- 하지만 실제 문제에서는 사전호가률과 우도함수의 파라메터 또한 알고 있지 못하는 경우가 많다.
우도함수를 모르는 상황에서 VI를 하기 위해선?
1. 사전확률 𝑝 𝑧 는 상수로 고정하여도 됨
2. 사후확률 𝑝(𝑧|𝑥)에 근사한 𝑞(𝑧)의 파라메터를 찾는 것과 동시에, 우도함수 𝑝(𝑥|𝑧)의 파라메터 또
한 추정해야 함
3. But, 이 둘을 동시에 찾는 것은 불가능.
→ 한 파라메터를 고정하고 나머지 파라메터를 최적화하는 것을 반복하는 EM algorithm 사용
11
Vatiational EM algorithm
𝑞(𝑧)의 파라메터를 𝜃 𝑞, 우도함수𝑝(𝑥|𝑧)의 파라메터를 𝜃𝑙라고 둘 때
EM algorithm은 다음과 같은 과정을 수렴할 때까지 반복함
E-step에서는 KLD를 줄이기 위해 q만을 업데이트하므로 이 과정에서 𝑝(𝑥) 는 변하지 않음.
KLD를 줄이기 위해선 M-step을 통해 𝑝(𝑥)또한 줄여야 한다.
log 𝑝(𝑥)에 대해 정리하면,
- Expectation: 우도함수 𝑝 𝑥 𝑧 의 파라메터 𝜃𝑙을 고정한 상태에서 𝐷 𝐾𝐿(𝑞(𝑧)||𝑝 𝑧 𝑥 )를
줄이는 q의파라메터 𝜃 𝑞를 찾는다.(앞에 소개한 방법 이용)
- Maximization: E-step에서 찾은 𝜃 𝑞를 고정한 상태에서 evidence 𝑝 𝑥 를 최대화하
는 우도함수 𝑝(𝑥|𝑧)의 파라메터 𝜃𝑙를 찾는다.
12
Vatiational EM algorithm
이 때, KLD는 항상 양수이므로
우변이 Evidence인 𝑝(𝑥)의 하한을 나타내므로 Evidence Lower Bound(ELBO)라고 부름
양수
M-step 설명중임
13
Vatiational EM algorithm
ELBO 두 분포의 차이
(줄이고자 하는것)
ELBO를 최대화 시킨다면?
→ 등호를 만족시키기 위해서 KLD가 최소화 될 것.
𝜃 𝑞가 고정된 상태에서 우도함수𝑝(𝑥|𝑧)의 파라메터 𝜃𝑙
를 KLD가 최소화되는 방향으로 업데이트 하는 것임
이 또한 reparameterization trick을 이용한 SGD를
사용하면 된다.(참고: http://edwardlib.org/tutorials/klqp)
Prior, 상수취급
M-step 설명중임
14

More Related Content

What's hot

알기쉬운 Variational autoencoder
알기쉬운 Variational autoencoder알기쉬운 Variational autoencoder
알기쉬운 Variational autoencoder
홍배 김
 
「3.1.2最小二乗法の幾何学」PRML勉強会4 @筑波大学 #prml学ぼう
「3.1.2最小二乗法の幾何学」PRML勉強会4 @筑波大学 #prml学ぼう 「3.1.2最小二乗法の幾何学」PRML勉強会4 @筑波大学 #prml学ぼう
「3.1.2最小二乗法の幾何学」PRML勉強会4 @筑波大学 #prml学ぼう
Junpei Tsuji
 
PRML第6章「カーネル法」
PRML第6章「カーネル法」PRML第6章「カーネル法」
PRML第6章「カーネル法」
Keisuke Sugawara
 
boosting 기법 이해 (bagging vs boosting)
boosting 기법 이해 (bagging vs boosting)boosting 기법 이해 (bagging vs boosting)
boosting 기법 이해 (bagging vs boosting)
SANG WON PARK
 
오토인코더의 모든 것
오토인코더의 모든 것오토인코더의 모든 것
오토인코더의 모든 것
NAVER Engineering
 
[PR12] categorical reparameterization with gumbel softmax
[PR12] categorical reparameterization with gumbel softmax[PR12] categorical reparameterization with gumbel softmax
[PR12] categorical reparameterization with gumbel softmax
JaeJun Yoo
 
PRML輪読#7
PRML輪読#7PRML輪読#7
PRML輪読#7
matsuolab
 
Variational Autoencoder Tutorial
Variational Autoencoder Tutorial Variational Autoencoder Tutorial
Variational Autoencoder Tutorial
Hojin Yang
 
スペクトラル・クラスタリング
スペクトラル・クラスタリングスペクトラル・クラスタリング
スペクトラル・クラスタリング
Akira Miyazawa
 
PRML輪読#6
PRML輪読#6PRML輪読#6
PRML輪読#6
matsuolab
 
劣モジュラ最適化と機械学習1章
劣モジュラ最適化と機械学習1章劣モジュラ最適化と機械学習1章
劣モジュラ最適化と機械学習1章
Hakky St
 
강화 학습 기초 Reinforcement Learning an introduction
강화 학습 기초 Reinforcement Learning an introduction강화 학습 기초 Reinforcement Learning an introduction
강화 학습 기초 Reinforcement Learning an introduction
Taehoon Kim
 
[DL輪読会]Deep Learning 第5章 機械学習の基礎
[DL輪読会]Deep Learning 第5章 機械学習の基礎[DL輪読会]Deep Learning 第5章 機械学習の基礎
[DL輪読会]Deep Learning 第5章 機械学習の基礎
Deep Learning JP
 
강화학습 알고리즘의 흐름도 Part 2
강화학습 알고리즘의 흐름도 Part 2강화학습 알고리즘의 흐름도 Part 2
강화학습 알고리즘의 흐름도 Part 2
Dongmin Lee
 
連続最適化勉強会
連続最適化勉強会連続最適化勉強会
連続最適化勉強会
shima o
 
알아두면 쓸데있는 신기한 강화학습 NAVER 2017
알아두면 쓸데있는 신기한 강화학습 NAVER 2017알아두면 쓸데있는 신기한 강화학습 NAVER 2017
알아두면 쓸데있는 신기한 강화학습 NAVER 2017
Taehoon Kim
 
PRML輪読#4
PRML輪読#4PRML輪読#4
PRML輪読#4
matsuolab
 
[한글] Tutorial: Sparse variational dropout
[한글] Tutorial: Sparse variational dropout[한글] Tutorial: Sparse variational dropout
[한글] Tutorial: Sparse variational dropout
Wuhyun Rico Shin
 
PRML第9章「混合モデルとEM」
PRML第9章「混合モデルとEM」PRML第9章「混合モデルとEM」
PRML第9章「混合モデルとEM」
Keisuke Sugawara
 
RBM、Deep Learningと学習(全脳アーキテクチャ若手の会 第3回DL勉強会発表資料)
RBM、Deep Learningと学習(全脳アーキテクチャ若手の会 第3回DL勉強会発表資料)RBM、Deep Learningと学習(全脳アーキテクチャ若手の会 第3回DL勉強会発表資料)
RBM、Deep Learningと学習(全脳アーキテクチャ若手の会 第3回DL勉強会発表資料)
Takuma Yagi
 

What's hot (20)

알기쉬운 Variational autoencoder
알기쉬운 Variational autoencoder알기쉬운 Variational autoencoder
알기쉬운 Variational autoencoder
 
「3.1.2最小二乗法の幾何学」PRML勉強会4 @筑波大学 #prml学ぼう
「3.1.2最小二乗法の幾何学」PRML勉強会4 @筑波大学 #prml学ぼう 「3.1.2最小二乗法の幾何学」PRML勉強会4 @筑波大学 #prml学ぼう
「3.1.2最小二乗法の幾何学」PRML勉強会4 @筑波大学 #prml学ぼう
 
PRML第6章「カーネル法」
PRML第6章「カーネル法」PRML第6章「カーネル法」
PRML第6章「カーネル法」
 
boosting 기법 이해 (bagging vs boosting)
boosting 기법 이해 (bagging vs boosting)boosting 기법 이해 (bagging vs boosting)
boosting 기법 이해 (bagging vs boosting)
 
오토인코더의 모든 것
오토인코더의 모든 것오토인코더의 모든 것
오토인코더의 모든 것
 
[PR12] categorical reparameterization with gumbel softmax
[PR12] categorical reparameterization with gumbel softmax[PR12] categorical reparameterization with gumbel softmax
[PR12] categorical reparameterization with gumbel softmax
 
PRML輪読#7
PRML輪読#7PRML輪読#7
PRML輪読#7
 
Variational Autoencoder Tutorial
Variational Autoencoder Tutorial Variational Autoencoder Tutorial
Variational Autoencoder Tutorial
 
スペクトラル・クラスタリング
スペクトラル・クラスタリングスペクトラル・クラスタリング
スペクトラル・クラスタリング
 
PRML輪読#6
PRML輪読#6PRML輪読#6
PRML輪読#6
 
劣モジュラ最適化と機械学習1章
劣モジュラ最適化と機械学習1章劣モジュラ最適化と機械学習1章
劣モジュラ最適化と機械学習1章
 
강화 학습 기초 Reinforcement Learning an introduction
강화 학습 기초 Reinforcement Learning an introduction강화 학습 기초 Reinforcement Learning an introduction
강화 학습 기초 Reinforcement Learning an introduction
 
[DL輪読会]Deep Learning 第5章 機械学習の基礎
[DL輪読会]Deep Learning 第5章 機械学習の基礎[DL輪読会]Deep Learning 第5章 機械学習の基礎
[DL輪読会]Deep Learning 第5章 機械学習の基礎
 
강화학습 알고리즘의 흐름도 Part 2
강화학습 알고리즘의 흐름도 Part 2강화학습 알고리즘의 흐름도 Part 2
강화학습 알고리즘의 흐름도 Part 2
 
連続最適化勉強会
連続最適化勉強会連続最適化勉強会
連続最適化勉強会
 
알아두면 쓸데있는 신기한 강화학습 NAVER 2017
알아두면 쓸데있는 신기한 강화학습 NAVER 2017알아두면 쓸데있는 신기한 강화학습 NAVER 2017
알아두면 쓸데있는 신기한 강화학습 NAVER 2017
 
PRML輪読#4
PRML輪読#4PRML輪読#4
PRML輪読#4
 
[한글] Tutorial: Sparse variational dropout
[한글] Tutorial: Sparse variational dropout[한글] Tutorial: Sparse variational dropout
[한글] Tutorial: Sparse variational dropout
 
PRML第9章「混合モデルとEM」
PRML第9章「混合モデルとEM」PRML第9章「混合モデルとEM」
PRML第9章「混合モデルとEM」
 
RBM、Deep Learningと学習(全脳アーキテクチャ若手の会 第3回DL勉強会発表資料)
RBM、Deep Learningと学習(全脳アーキテクチャ若手の会 第3回DL勉強会発表資料)RBM、Deep Learningと学習(全脳アーキテクチャ若手の会 第3回DL勉強会発表資料)
RBM、Deep Learningと学習(全脳アーキテクチャ若手の会 第3回DL勉強会発表資料)
 

Similar to Chapter 19 Variational Inference

Deep Learning from scratch 5장 : backpropagation
 Deep Learning from scratch 5장 : backpropagation Deep Learning from scratch 5장 : backpropagation
Deep Learning from scratch 5장 : backpropagation
JinSooKim80
 
Variational AutoEncoder(VAE)
Variational AutoEncoder(VAE)Variational AutoEncoder(VAE)
Variational AutoEncoder(VAE)
강민국 강민국
 
Variational Auto Encoder, Generative Adversarial Model
Variational Auto Encoder, Generative Adversarial ModelVariational Auto Encoder, Generative Adversarial Model
Variational Auto Encoder, Generative Adversarial Model
SEMINARGROOT
 
Auto-Encoders and Variational Auto-Encoders
Auto-Encoders and Variational Auto-EncodersAuto-Encoders and Variational Auto-Encoders
Auto-Encoders and Variational Auto-Encoders
Jinho Lee
 
Neural network (perceptron)
Neural network (perceptron)Neural network (perceptron)
Neural network (perceptron)
Jeonghun Yoon
 
Eigendecomposition and pca
Eigendecomposition and pcaEigendecomposition and pca
Eigendecomposition and pca
Jinhwan Suk
 
Deep Learning from scratch 4장 : neural network learning
Deep Learning from scratch 4장 : neural network learningDeep Learning from scratch 4장 : neural network learning
Deep Learning from scratch 4장 : neural network learning
JinSooKim80
 
04. logistic regression ( 로지스틱 회귀 )
04. logistic regression ( 로지스틱 회귀 )04. logistic regression ( 로지스틱 회귀 )
04. logistic regression ( 로지스틱 회귀 )
Jeonghun Yoon
 
03. linear regression
03. linear regression03. linear regression
03. linear regression
Jeonghun Yoon
 
[Probability for machine learning]
[Probability for machine learning][Probability for machine learning]
[Probability for machine learning]
강민국 강민국
 
Crash Course on Graphical models
Crash Course on Graphical modelsCrash Course on Graphical models
Crash Course on Graphical models
Jong Wook Kim
 
Multinomial classification and application of ML
Multinomial classification and application of MLMultinomial classification and application of ML
Multinomial classification and application of ML
희수 박
 
개념 이해가 쉬운 Variational Autoencoder (VAE)
개념 이해가 쉬운 Variational Autoencoder (VAE)개념 이해가 쉬운 Variational Autoencoder (VAE)
개념 이해가 쉬운 Variational Autoencoder (VAE)
jaypi Ko
 
8. Logistic Regression
8. Logistic Regression8. Logistic Regression
8. Logistic Regression
Jungkyu Lee
 
Coursera Machine Learning (by Andrew Ng)_강의정리
Coursera Machine Learning (by Andrew Ng)_강의정리Coursera Machine Learning (by Andrew Ng)_강의정리
Coursera Machine Learning (by Andrew Ng)_강의정리
SANG WON PARK
 
07. PCA
07. PCA07. PCA
07. PCA
Jeonghun Yoon
 
Probability with MLE, MAP
Probability with MLE, MAPProbability with MLE, MAP
Probability with MLE, MAP
Junho Lee
 
0228 2 sample_distribution
0228 2 sample_distribution0228 2 sample_distribution
0228 2 sample_distribution
Jeonghun Yoon
 
3 sat with randomization
3 sat with randomization3 sat with randomization
3 sat with randomization
Changki Yun
 
KOOC Ch8. k-means & GMM
KOOC Ch8. k-means & GMMKOOC Ch8. k-means & GMM
KOOC Ch8. k-means & GMM
suman_lim
 

Similar to Chapter 19 Variational Inference (20)

Deep Learning from scratch 5장 : backpropagation
 Deep Learning from scratch 5장 : backpropagation Deep Learning from scratch 5장 : backpropagation
Deep Learning from scratch 5장 : backpropagation
 
Variational AutoEncoder(VAE)
Variational AutoEncoder(VAE)Variational AutoEncoder(VAE)
Variational AutoEncoder(VAE)
 
Variational Auto Encoder, Generative Adversarial Model
Variational Auto Encoder, Generative Adversarial ModelVariational Auto Encoder, Generative Adversarial Model
Variational Auto Encoder, Generative Adversarial Model
 
Auto-Encoders and Variational Auto-Encoders
Auto-Encoders and Variational Auto-EncodersAuto-Encoders and Variational Auto-Encoders
Auto-Encoders and Variational Auto-Encoders
 
Neural network (perceptron)
Neural network (perceptron)Neural network (perceptron)
Neural network (perceptron)
 
Eigendecomposition and pca
Eigendecomposition and pcaEigendecomposition and pca
Eigendecomposition and pca
 
Deep Learning from scratch 4장 : neural network learning
Deep Learning from scratch 4장 : neural network learningDeep Learning from scratch 4장 : neural network learning
Deep Learning from scratch 4장 : neural network learning
 
04. logistic regression ( 로지스틱 회귀 )
04. logistic regression ( 로지스틱 회귀 )04. logistic regression ( 로지스틱 회귀 )
04. logistic regression ( 로지스틱 회귀 )
 
03. linear regression
03. linear regression03. linear regression
03. linear regression
 
[Probability for machine learning]
[Probability for machine learning][Probability for machine learning]
[Probability for machine learning]
 
Crash Course on Graphical models
Crash Course on Graphical modelsCrash Course on Graphical models
Crash Course on Graphical models
 
Multinomial classification and application of ML
Multinomial classification and application of MLMultinomial classification and application of ML
Multinomial classification and application of ML
 
개념 이해가 쉬운 Variational Autoencoder (VAE)
개념 이해가 쉬운 Variational Autoencoder (VAE)개념 이해가 쉬운 Variational Autoencoder (VAE)
개념 이해가 쉬운 Variational Autoencoder (VAE)
 
8. Logistic Regression
8. Logistic Regression8. Logistic Regression
8. Logistic Regression
 
Coursera Machine Learning (by Andrew Ng)_강의정리
Coursera Machine Learning (by Andrew Ng)_강의정리Coursera Machine Learning (by Andrew Ng)_강의정리
Coursera Machine Learning (by Andrew Ng)_강의정리
 
07. PCA
07. PCA07. PCA
07. PCA
 
Probability with MLE, MAP
Probability with MLE, MAPProbability with MLE, MAP
Probability with MLE, MAP
 
0228 2 sample_distribution
0228 2 sample_distribution0228 2 sample_distribution
0228 2 sample_distribution
 
3 sat with randomization
3 sat with randomization3 sat with randomization
3 sat with randomization
 
KOOC Ch8. k-means & GMM
KOOC Ch8. k-means & GMMKOOC Ch8. k-means & GMM
KOOC Ch8. k-means & GMM
 

More from KyeongUkJang

Photo wake up - 3d character animation from a single photo
Photo wake up - 3d character animation from a single photoPhoto wake up - 3d character animation from a single photo
Photo wake up - 3d character animation from a single photo
KyeongUkJang
 
AlphagoZero
AlphagoZeroAlphagoZero
AlphagoZero
KyeongUkJang
 
GoogLenet
GoogLenetGoogLenet
GoogLenet
KyeongUkJang
 
GAN - Generative Adversarial Nets
GAN - Generative Adversarial NetsGAN - Generative Adversarial Nets
GAN - Generative Adversarial Nets
KyeongUkJang
 
Distilling the knowledge in a neural network
Distilling the knowledge in a neural networkDistilling the knowledge in a neural network
Distilling the knowledge in a neural network
KyeongUkJang
 
Latent Dirichlet Allocation
Latent Dirichlet AllocationLatent Dirichlet Allocation
Latent Dirichlet Allocation
KyeongUkJang
 
CNN for sentence classification
CNN for sentence classificationCNN for sentence classification
CNN for sentence classification
KyeongUkJang
 
Visualizing data using t-SNE
Visualizing data using t-SNEVisualizing data using t-SNE
Visualizing data using t-SNE
KyeongUkJang
 
Playing atari with deep reinforcement learning
Playing atari with deep reinforcement learningPlaying atari with deep reinforcement learning
Playing atari with deep reinforcement learning
KyeongUkJang
 
Chapter 20 - GAN
Chapter 20 - GANChapter 20 - GAN
Chapter 20 - GAN
KyeongUkJang
 
Chapter 20 - VAE
Chapter 20 - VAEChapter 20 - VAE
Chapter 20 - VAE
KyeongUkJang
 
Chapter 20 Deep generative models
Chapter 20 Deep generative modelsChapter 20 Deep generative models
Chapter 20 Deep generative models
KyeongUkJang
 
Natural Language Processing(NLP) - basic 2
Natural Language Processing(NLP) - basic 2Natural Language Processing(NLP) - basic 2
Natural Language Processing(NLP) - basic 2
KyeongUkJang
 
Natural Language Processing(NLP) - Basic
Natural Language Processing(NLP) - BasicNatural Language Processing(NLP) - Basic
Natural Language Processing(NLP) - Basic
KyeongUkJang
 
Chapter 17 monte carlo methods
Chapter 17 monte carlo methodsChapter 17 monte carlo methods
Chapter 17 monte carlo methods
KyeongUkJang
 
Chapter 16 structured probabilistic models for deep learning - 2
Chapter 16 structured probabilistic models for deep learning - 2Chapter 16 structured probabilistic models for deep learning - 2
Chapter 16 structured probabilistic models for deep learning - 2
KyeongUkJang
 
Chapter 16 structured probabilistic models for deep learning - 1
Chapter 16 structured probabilistic models for deep learning - 1Chapter 16 structured probabilistic models for deep learning - 1
Chapter 16 structured probabilistic models for deep learning - 1
KyeongUkJang
 
Chapter 15 Representation learning - 2
Chapter 15 Representation learning - 2Chapter 15 Representation learning - 2
Chapter 15 Representation learning - 2
KyeongUkJang
 
Chapter 15 Representation learning - 1
Chapter 15 Representation learning - 1Chapter 15 Representation learning - 1
Chapter 15 Representation learning - 1
KyeongUkJang
 

More from KyeongUkJang (20)

Photo wake up - 3d character animation from a single photo
Photo wake up - 3d character animation from a single photoPhoto wake up - 3d character animation from a single photo
Photo wake up - 3d character animation from a single photo
 
YOLO
YOLOYOLO
YOLO
 
AlphagoZero
AlphagoZeroAlphagoZero
AlphagoZero
 
GoogLenet
GoogLenetGoogLenet
GoogLenet
 
GAN - Generative Adversarial Nets
GAN - Generative Adversarial NetsGAN - Generative Adversarial Nets
GAN - Generative Adversarial Nets
 
Distilling the knowledge in a neural network
Distilling the knowledge in a neural networkDistilling the knowledge in a neural network
Distilling the knowledge in a neural network
 
Latent Dirichlet Allocation
Latent Dirichlet AllocationLatent Dirichlet Allocation
Latent Dirichlet Allocation
 
CNN for sentence classification
CNN for sentence classificationCNN for sentence classification
CNN for sentence classification
 
Visualizing data using t-SNE
Visualizing data using t-SNEVisualizing data using t-SNE
Visualizing data using t-SNE
 
Playing atari with deep reinforcement learning
Playing atari with deep reinforcement learningPlaying atari with deep reinforcement learning
Playing atari with deep reinforcement learning
 
Chapter 20 - GAN
Chapter 20 - GANChapter 20 - GAN
Chapter 20 - GAN
 
Chapter 20 - VAE
Chapter 20 - VAEChapter 20 - VAE
Chapter 20 - VAE
 
Chapter 20 Deep generative models
Chapter 20 Deep generative modelsChapter 20 Deep generative models
Chapter 20 Deep generative models
 
Natural Language Processing(NLP) - basic 2
Natural Language Processing(NLP) - basic 2Natural Language Processing(NLP) - basic 2
Natural Language Processing(NLP) - basic 2
 
Natural Language Processing(NLP) - Basic
Natural Language Processing(NLP) - BasicNatural Language Processing(NLP) - Basic
Natural Language Processing(NLP) - Basic
 
Chapter 17 monte carlo methods
Chapter 17 monte carlo methodsChapter 17 monte carlo methods
Chapter 17 monte carlo methods
 
Chapter 16 structured probabilistic models for deep learning - 2
Chapter 16 structured probabilistic models for deep learning - 2Chapter 16 structured probabilistic models for deep learning - 2
Chapter 16 structured probabilistic models for deep learning - 2
 
Chapter 16 structured probabilistic models for deep learning - 1
Chapter 16 structured probabilistic models for deep learning - 1Chapter 16 structured probabilistic models for deep learning - 1
Chapter 16 structured probabilistic models for deep learning - 1
 
Chapter 15 Representation learning - 2
Chapter 15 Representation learning - 2Chapter 15 Representation learning - 2
Chapter 15 Representation learning - 2
 
Chapter 15 Representation learning - 1
Chapter 15 Representation learning - 1Chapter 15 Representation learning - 1
Chapter 15 Representation learning - 1
 

Chapter 19 Variational Inference

  • 2. Variational Autoencoder 2 잠재변수 𝑧 데이터 𝑥 우도함수 𝑝(𝑥|𝑧) 𝑧의 사전확률 𝑝(𝑧) 𝑥의 사전확률 𝑝 𝑥 𝑧가 주어진 상황에서 𝑥가 나타날 확률 𝑝 𝑥 𝑧 : 우도 𝑥가 주어진 상황에서 𝑧가 나타날 확률 𝑝 𝑧 𝑥 : 사후확률 사후확률 𝑝(𝑧|𝑥)를 알기 어렵기 때문에 근사하는 간단한 함수를 찾음 𝑞(𝑧) 또는 𝑞(𝑧|𝑥)
  • 3. Variational inference 흰색: 잠재변수(z) 회색: 관측변수(x) - 주어진 데이터(𝑥)와 주어지지 않은 잠재변수(𝑧)가 모델에 관여하는 상황. - 어떤 잠재변수로부터 주어진 데이터를 만들어낼 확률𝑝(𝑥|𝑧)이 가장 높은 모델과, 그때 최적의 잠재변수를 만드는 함수 𝑝(𝑧|𝑥)를 찾아야한다고 생각해보자. - 이 때, 사후확률 분포 𝑝(𝑧|𝑥) 를 계산하는 것이 불가능에 가까울 정도로 어려운 경우가 많다. 잠재변수간 상호작용 때문에 marginal probability 계산이 힘들다. Marginal probability: 𝑝(𝑥) = σ 𝑧 𝑝(𝑥, 𝑧) 3
  • 4. Variational inference VI란 사후확률(posterior) 분포 𝑝(𝑧|𝑥)를 다루기 쉬운 확률분포 𝑞(𝑧)로 근사(approximation)하는 것 사후확률 분포를 우리가 익히 알고 있는 정규분포로 근사한 경우 4
  • 5. Variational inference 사후확률 𝑝(𝑧|𝑥)에 근사한 𝑞(𝑧)를 만들기 위해 두 분포의 차이를 줄여야 함. → 두 확률분포의 차이를 계산하는 KL-Divergence 개념 활용 사후확률 분포 𝑝(𝑧|𝑥)와 𝑞(𝑧) 사이의 KLD를 계산하고, KLD가 줄어드는 쪽으로 𝑞(𝑧)를 조금 씩 업데이트하는 과정을 반복하면 사후확률을 잘 근사하는 𝑞∗ (𝑧)를 얻게 될 것 → 이 과정이 Variational Inference KLD를 줄어들게 하는데 몇가지 방법이 있음. 5
  • 6. Variational inference 이 KLD를 줄어들게 하는데 몇가지 방법이 있음. 우리가 최소화하고자 하는 KLD를 정리해보면, 6
  • 7. 1. Variational Inference with Monte Carlo Sampling 몬테카를로 방법(Monte Carlo Method): 랜덤 표본을 뽑아 함수의 값을 확률적으로 계산하는 방법. 이를 이용하여 KLD 텀에 대한 근사식을 유도 7
  • 8. 1. Variational Inference with Monte Carlo Sampling 실제 문제에서는 사후확률 분포𝑝(𝑧|𝑥)에 대해 아무런 정보가 없지만 몬테카를로 방법을 이용하면 𝑞(𝑧)를 어떤 분포로든 설정할 수 있다. Ex) 사후분포에 대한 정보가 없어서 𝑞(𝑧)를 정규분포로 정해 볼 경우 1. 이 정규분포에서 K개의 z들을 뽑으면 KLD의 근사값을 계산 가능. 2. 정규분포의 파라메터(평균, 분산)를 조금씩 바꿔가면서 KLD 근사값을 최소로 하는 파라메터를 구할 수 있을 것. 3. 구해진 정규분포가 바로 VI의 결과. ≈ 8
  • 9. 2. Variational Inference with SGD KLD를 줄이는 방향으로 𝑞(𝑧)의 파라메터를 업데이트 하여 VI하는 것도 가능 → Gradient를 계산하기 위해 KLD가 미분가능 해야함 Ex) 𝑞 𝑧 는 정규분포 𝜃 𝑞 = 𝜇 𝑞, 𝜎 𝑞 , 𝑝 𝑧 는 베타분포 𝛼, 𝛽 라고 두고 𝐾𝐿𝐷 식을 𝜃 𝑞에 대해 미분해 보자. (적절한 𝜃 𝑞를 추론하려 하는것) 이때, z가 𝜃 𝑞를 파라메터로 갖는 𝑞에 의해 랜덤 샘플링되기 때문에 𝜃 𝑞 에 대한 미분이 불가능 → z대신 노이즈를 샘플링해서 z를 계산하는 reparameterization trick 사용 9
  • 10. 2. Variational Inference with SGD 여기서도 몬테카를로 샘플링을 이용하여 KLD의 gradient 근사값을 계산. → Gradient 이용하여 𝜃 𝑞를 수정함으로써 사후확률 분포 𝑝(𝑧|𝑥)에 근사하는 𝑞(𝑧)를 찾을 수 있다. 10
  • 11. Vatiational EM algorithm - 지금까지는 사전확률함수 𝑝 𝑧 와 우도함수 𝑝 𝑥 𝑧 를 이미 알고 있다는 전제 하에 𝑝 𝑧 𝑥 에근사하는 𝑞 𝑧 를 찾는 𝑉𝐼 과정을 설명하였음. - 하지만 실제 문제에서는 사전호가률과 우도함수의 파라메터 또한 알고 있지 못하는 경우가 많다. 우도함수를 모르는 상황에서 VI를 하기 위해선? 1. 사전확률 𝑝 𝑧 는 상수로 고정하여도 됨 2. 사후확률 𝑝(𝑧|𝑥)에 근사한 𝑞(𝑧)의 파라메터를 찾는 것과 동시에, 우도함수 𝑝(𝑥|𝑧)의 파라메터 또 한 추정해야 함 3. But, 이 둘을 동시에 찾는 것은 불가능. → 한 파라메터를 고정하고 나머지 파라메터를 최적화하는 것을 반복하는 EM algorithm 사용 11
  • 12. Vatiational EM algorithm 𝑞(𝑧)의 파라메터를 𝜃 𝑞, 우도함수𝑝(𝑥|𝑧)의 파라메터를 𝜃𝑙라고 둘 때 EM algorithm은 다음과 같은 과정을 수렴할 때까지 반복함 E-step에서는 KLD를 줄이기 위해 q만을 업데이트하므로 이 과정에서 𝑝(𝑥) 는 변하지 않음. KLD를 줄이기 위해선 M-step을 통해 𝑝(𝑥)또한 줄여야 한다. log 𝑝(𝑥)에 대해 정리하면, - Expectation: 우도함수 𝑝 𝑥 𝑧 의 파라메터 𝜃𝑙을 고정한 상태에서 𝐷 𝐾𝐿(𝑞(𝑧)||𝑝 𝑧 𝑥 )를 줄이는 q의파라메터 𝜃 𝑞를 찾는다.(앞에 소개한 방법 이용) - Maximization: E-step에서 찾은 𝜃 𝑞를 고정한 상태에서 evidence 𝑝 𝑥 를 최대화하 는 우도함수 𝑝(𝑥|𝑧)의 파라메터 𝜃𝑙를 찾는다. 12
  • 13. Vatiational EM algorithm 이 때, KLD는 항상 양수이므로 우변이 Evidence인 𝑝(𝑥)의 하한을 나타내므로 Evidence Lower Bound(ELBO)라고 부름 양수 M-step 설명중임 13
  • 14. Vatiational EM algorithm ELBO 두 분포의 차이 (줄이고자 하는것) ELBO를 최대화 시킨다면? → 등호를 만족시키기 위해서 KLD가 최소화 될 것. 𝜃 𝑞가 고정된 상태에서 우도함수𝑝(𝑥|𝑧)의 파라메터 𝜃𝑙 를 KLD가 최소화되는 방향으로 업데이트 하는 것임 이 또한 reparameterization trick을 이용한 SGD를 사용하면 된다.(참고: http://edwardlib.org/tutorials/klqp) Prior, 상수취급 M-step 설명중임 14