[NeurIPS 2022]Energy-Based Contrastive Learning of Visual Representations (작성중)

ma-kjh·2023년 8월 25일
0

EBM

목록 보기
4/7

EBCLR

Contrastive learning은 Deep Neural Networks (DNNs)를 훈련함으로써 visual representation을 학습하는 방법이다. 일반적으로 positive pairs (transformations of the same image)들의 유사도는 증가시키고 negative pairs (transformations of different images)들의 유사도는 감소시킨다.

이 논문에서는 EBM(Energy-based Models)contrastive learning을 결합하여 the power of generative learning을 활용한다. EBCLR은 이론적으로 joint distribution of positive pairs를 학습하는 것으로 해석할 수 있고, MNIST, Fashion MNIST, CIFAR-10 및 CIFAR100과 같은 중소 규모 데이터 셋에서 좋은 결과를 얻는다.


EBM에 대해 모르는 사람이라면, Energy-based Model이 가지고 있는 power of generative learning이라는 뜻의 의미를 제대로 해석하기가 어렵다. Energy-based model을 아주 간단하게 설명해보면, 어떤 에너지 함수를 통해 두 변수 X,Y를 scalar로 매핑하는 모델이며, 이 때 옳은 페어인 (X,Y)에 대해서 에너지 값이 낮아지도록 model을 만들어 낸다고 생각하면 될 것이다. 마치 머신러닝 모델이 어떤 입력을 받아 모든 y의 logits값중에 가장 높은 값이 정답 class라고 예측하듯, EBM은 어떤 입력 joint distribution p(x,y)p(x,y) 혹은 p(x)p(x)에 대한 옳은 정답을 내뱉도록 하는 모델링 방법이라고 이해하면 되지 않을까 싶다.


특히, EBCLR은 SimCLR과 MoCo v2에 비해 4배에서 20배의 가속도를 보인다.

더불어, 하나의 positive pair당 254개의 negative pairs(batch 256)로 훈련된 SimCLR과 비교하여 30개의 negative pairs(batch 32)로 거의 동일한 성능을 달성하여 적은 수의 네거티브 페어에 대한 EBCLR의 우수성을 입증했다. EBCLR은 합리적인 성능을 달성하기 위해 다른 방법들에 비해 적은 수의 negative pair가 필요한 방법이다.

왼쪽 그림이 EBCLR을 잘 나타낸 그림이다. 여기서 \propto 가 의미하는 것은 “is a monotonically increasing function of”이다. 여기서 논문의 저자들은 joint distribution p(v,v)p(v,v^\prime)를 사용하는데, 이것은 positive pairs의 joint distribution으로 이미지들의 semantic similarity를 측정한 것이다. 특별히, p(v,v)p(v,v^\prime)vvvv^\prime가 semantically similar할 때 높게 측정되고, 아닐때 낮게 측정된다. DNN fθf_\theta는 Projection space에서 보이는 거리로 훈련이 되는데, 이 거리가 1/p(v,v)1/p(v,v^\prime) 으로부터 조절된다.

오른쪽 그림의 경우 EBCLR과 SimCLR, MoCo v2에서의 CIFAR10에 대한 linear evaluation accuracy 결과이다. 그림에서 알 수 있듯이, EBCLR의 10 epoch이 MoCo v2의 100epoch를 이기는 것을 확인할 수 있다. 그 외에도 좋은 성능을 보이는 것을 확인할 수 있음.

이 논문에서는 새로운 visaul representation learning 방법인 Energy-Based Contrastive Learning (EBCLR)방법을 제안한다. 이 방법은 leverages the power of geneartive learning by combining contrastive learning with energy-based models(EBMs).

EBCLR은 Contrastive learning loss를 generative loss로 보완하며, 이것은 positive pairs의 joint distribution 을 학습시키는 것으로 해석할 수 있다. 이를 통해, 기존의 Contrastive learning loss가 EBCLR의 특수한 경우임을 증명한다. 그리고 EBM은 SGLD에 의존하기 때문에, 훈련이 어려운 것으로 알려져 있지만, 논문에서는 특별한 SGLD를 제안하여 이를 극복하였다.

EBCLR을 이해하기 위해서, EBM과 contrastive learning, generative model에 대해 간략하게 설명한다.

Contrastive Learning

한 배치의 이미지 {xn}n=1N\{x_n\}^N_{n=1} 와 두개의 transformations t,tt,t^\prime이 주어졌을 때, contrastive learning methods는 먼저 각 instance xnx_n에 대하여 이미지를 두개의 view로 만들어낸다. vn=t(xn),vn=t(xn)v_n=t(x_n),v^\prime_n=t^\prime(x_n). 여기서 만약 n=mn=m인 경우, pair (vn,vm)(v_n,v_m^\prime)은 positive pair로 불리고 nmn\neq m인 경우는 negative pair로 불린다. DNN fθf_\theta가 주어질때, 이 view들은 fθf_\theta와 normalizing을 통해 projection space로 embedding된다.

Contrastive methods는 fθf_\theta가 positive pair의 projection에 대해서는 일치할 수 있도록 만들며, negative pairs에 대해서는 일치하지 않도록 학습한다. 특히, fθf_\theta는 InfoNCE objective를 최대화하기 위해 훈련된다. 훈련이 끝난 뒤에, fθf_\theta의 마지막 레이어 혹은 중간 레이어로부터 나오는 outputs들은 downstream task에 이용된다.

Energy-Based Models

scalar값을 가지는 energy function Eθ(v)E_\theta(v) with parameter θ\theta가 주어졌을 때, energy-based model(EBM)은 다음의 식으로부터 분포가 정의된다.

qθ(v):=1Z(θ)exp{Eθ(v)}q_\theta(v):={1\over{Z(\theta)}}\exp\{-E_\theta(v)\}

여기서 Z(θ)Z(\theta)는 partition function이며 qθq_\theta의 integrates가 1이 되도록 보장해준다. 여기에 필수적으로 energy function의 선택에 대한 아무런 제약이 존재하지 않기 때문에, EBM은 distributions을 모델링하는데 있어서 매우 유연하게 작동한다. 따라서 EBM은 매우 다양한 머신러닝 테스크(차원축소, generative classifier, generating images, 등등)에 사용된다. Wang은 EBM과 InfoNCE사이의 EBM의 generative performance를 향상시키는 연결에 대해 조사했는데, 이 논문에서는 처음으로 EBM을 representation learning을 위한 contrastive learning으로 사용하였다.

target distribution이 주어지면, EBM은 오직 pp로부터 샘플링할 때, density qθq_\theta에 대해 추정할 수 있다. 이를 가능케하는 한가지 방법은 qθq_\thetapp 사이의 Kullback-Leibler (KL) divergence를 최소화하는 방법이며, pp에 대하여, qθq_\theta의 log-likelihood의 기댓값을 최대화하는 것이다.

maxθEp[logqθ(v)].\max_\theta\mathbb{E}_p[\log q_\theta(v)].

Stochastic gradient ascent가 이를 해결하기 위해 사용될 수 있다. 특히, paramether θ\theta의 관점에서 log-likelihood의 기댓값의 gradient는 다음과 같다.

θEp[logqθ(v)]=Eqθ[θEθ(v)]Ep[θEθ(v)].(3)\nabla_\theta\mathbb{E}_p[\log q_\theta(v)]=\mathbb{E}_{q_\theta}[\nabla_\theta E_\theta(v)]-\mathbb{E}_p[\nabla_\theta E_\theta(v)].\:\:\:(3)

유도

logpθ(x)=logexp(Eθ(x))Z(θ)=log[exp(Eθ(x))]log[Z(θ)]=logZ(θ)Eθ(x)\log p_\theta(\mathbf{x})=\log{\exp(-E_\theta(\mathbf{x}))\over{Z(\theta)}}=\log[\exp(-E_\theta(\mathbf{x}))]-\log[Z(\theta)]\\=-\log Z(\theta)-E_\theta(\mathbf{x})
θlogpθ(x)=1Z(θ)θZ(θ)θEθ(x)=1Z(θ)θxexp(Eθ(x))θEθ(x)=1Z(θ)xexp(Eθ(x))θEθ(x)θEθ(x)=xexp(Eθ(x))Z(θ)θEθ(x)θEθ(x)=Epθ(x)[θEθ(x)]θEθ(x)\nabla_\theta \log p_\theta(\mathbf{x})=-{1\over{Z(\theta)}}\nabla_\theta Z(\theta)-\nabla_\theta E_\theta(\mathbf{x})\\=-{1\over{Z(\theta)}}\nabla_\theta\int_\mathbf{x}\exp(-E_\theta(\mathbf{x}))-\nabla_\theta E_\theta(\mathbf{x})\\={1\over{Z(\theta)}}\int_{\mathbf{x}^\prime}\exp(-E_\theta(\mathbf{x}^\prime))\nabla_\theta E_\theta(\mathbf{x}^\prime)-\nabla_\theta E_\theta(\mathbf{x})\\=\int_{\mathbf{x}^\prime}{\exp(-E_\theta(\mathbf{x}^\prime))\over{Z(\theta)}}\nabla_\theta E_\theta(\mathbf{x}^\prime) -\nabla_\theta E_\theta(\mathbf{x})\\=\mathbb{E}_{p_\theta(\mathbf{x}^\prime)}[\nabla_\theta E_\theta(\mathbf{x}^\prime)]-\nabla_\theta E_\theta(\mathbf{x})

따라서, θ\theta를 업데이트 하는 것은 qθq_\theta로 부터 샘플링된 에너지에 대해 pulling up하는 것이고 pp로부터 샘플링된 energy에 대해서는 pushing down하는 것이다. 이러한 optimization methods는 contrastive divergence로 잘 알려져있다.

위 식에서 두번째 있는 term (Ep[θEθ(v)])(-\mathbb{E}_p[\nabla_\theta E_\theta(v)])pp로부터 샘플함으로써 쉽게 계산될 수 있는 반면에, 첫번 째 텀은 (Eqθ[θEθ(v)])(\mathbb{E}_{q_\theta}[\nabla_\theta E_\theta(v)])qθq_\theta로 부터 샘플이 필요하다. 이전 works들은 Stochastic Gradient Langevin Dynamic을 통해 qθq_\theta로 부터 샘플을 생성해준다. 특히, some proposal distribution q0q_0로부터의 하나의 샘플 v0v_0이 주어질때,

vt+1=vtαt2vtEθ(vt)+ϵt,ϵtN(0,σt2)v_{t+1}=v_t-{\alpha_t\over{2}}\nabla_{v_t}E_\theta(v_t)+\epsilon_t,\:\:\epsilon_t\sim\mathcal{N}(0,\sigma^2_t)

{vt}\{v_t\}의 시퀀스가 qθq_\theta로부터 나온 샘플로 converge함을 guarantee한다. (guarantees that the sequence {vt}\{v_t\} converges to a sample from qθq_\theta assuming {αt}\{\alpha_t\} decays at a polynomial rate )

무슨 말이냐면, EBM은 위 생성된 샘플이 qθq_\theta에서 생성된 샘플이라는 것을 guarantee하는 방향으로 생성된다는 의미이다. 위의 에너지함수 Eθ(vt)E_\theta(v_t)vtv_t에 대한 미분값은 위 에너지 함수가 작아지는 방향으로 이미지를 만든다는 의미인데, 이 때 에너지함수가 작아진다는 것은 샘플 vtv_t가 분포 qθq_\theta에서 나올 확률을 높여준다는 것을 의미한다. 즉, step이 무한이 진행된다면 {vt}\{v_t\}의 시퀀스가 qθq_\theta로부터 나온 샘플임을 guarantee한다.

하지만, SGLD는 proposal distribution 로부터 나온 샘플이 target distribution로 converge할 때 까지 엄청나게 많은 step 수를 필요로 한다. 이것은 현실적으로 불가능하고, 오직 constant step size, i.e. αt=α\alpha_t=\alpha 와 constant noise variance σt=σ2\sigma_t=\sigma^2 가 사용된다. 게다가 Yang and Ji는 SGLD가 EBM을 훈련도중 발산하도록 하는 pixel값을 생성한다고 주장한다. 따라서 그들은 proximal SGLD라는 방법으로 gradient values를 threshold δ>0\delta>0을 갖는 특정 구간 [δ,δ][-\delta,\delta]로 clamp해줌으로써 EBM의 발산을 막는다. 따라서, update equation은

vt+1=vtαclamp{vEθ(vt),δ}+ϵ(5)v_{t+1}=v_t-\alpha\cdot\text{clamp}\{\nabla_vE_\theta(v_t),\delta\}+\epsilon\:\:\:(5)

for t=0,...T1t=0,...T-1, where ϵN(0,σ2)\epsilon\sim\mathcal{N}(0,\sigma^2) and clamp{,δ}\{\cdot,\delta\} clamps each element of the input vector into [δ,δ][-\delta,\delta].

본 논문에서는 추가적인 수정을 통해 SGLD를 EBCLR에 더욱 가속해서 수렴하도록 만들었다.

Theory

Let D\mathcal{D} be a distribution of images and T\mathcal{T} a distribution of stochastic image transformations. Given xDx\sim{\mathcal{D}} and i.i.d. t,tTt,t^\prime\sim\mathcal{T}, our goal is to approximate the joint distribution of the views

우선 D\mathcal{D}라는 image distribution과 T\mathcal{T}라는 image transformationdl 있다고 생각해보자. 주어진 분포 D\mathcal{D}에서의 샘플 xx,xDx\sim\mathcal{D}와 i.i.d t,tTt,t^\prime\sim\mathcal{T}, 에서 우리의 목표는 model distribution qθq_\theta를 사용해 실제 joint distribution pp인 아래 분포를 잘 근사하는 것이다.

p(v,v),wherev=t(x),v=t(x)p(v,v^\prime),\:\: \text{where}\:\:v=t(x),v^\prime=t^\prime(x)

using the model distribution

qθ(v,v):=1Z(θ)exp{zz2/τ}.(6)q_\theta(v,v^\prime):={1\over{Z(\theta)}}\exp\{-||z-z^\prime||^2/\tau\}.\:(6)

where Z(θ)Z(\theta) is a normalization constant, τ>0\tau \gt0 is a temperature hyper-parameter, and zz and zz^\prime are projections computed by passing the views vv and vv^\prime through the DNN fθf_\theta and then normalizing to have unit norm. We now explain the intuitive meaning of matching qθq_\theta to p.p.

본 논문의 키 아이디어는 p(v,v)p(v,v^\prime)vvvv^\prime의 semantic similarity를 측정하기 위해 사용한다는 것이다. 만약에 두 이미지 v,vv,v^\prime이 semantically 비슷하다면, 그것들은 비슷한 이미지의 transformation일 가능성이 높다는 것을 의미할 것이다. 따라서 p(v,v)p(v,v^\prime)은 semantically 비슷한 v,vv,v^\prime에서는 높고, 다른 경우에는 낮다.

qθq_\thetapp를 아주 잘 근사한다고 가정하자. 만약 식 6번 처럼 식을 만들어 내고 zz||z-z^\prime||을 풀게 한다면, zzzz^\prime 사이의 거리는 monotone increasing function of 1/p(v,v)1/p(v,v^\prime)이 될 것이다. 이 1/p(v,v)1/p(v,v^\prime)v,vv,v^\prime의 semantic similarity의 inverse이다. 따라서 semantically 비슷한 이미지들은 가까운 projections을 가지고, 다른 이미지들은 먼 projection을 가진다. 이것은 Figure.1을 보면 알 수 있다.

To approximate pp using qθq_\theta, we train fθf_\theta to maximize the expected log-likelihood of qθq_\theta under pp:

maxθEp[logqθ(v,v)](7)\max_\theta\mathbb{E} _p[\log q_\theta(v,v^\prime)]\:\:\:(7)

In order to solve this problem with stochastic gradient ascent, we could naively extend (3) to the setting of joint distributions to obtain the following result.

Proposition 1

Proposition 1. The joint distribution (6) can be formulated as an EBM

qθ(v,v):=1Z(θ)exp{Eθ(z,z)},Eθ(v,v)=zz2/τq_\theta(v,v^\prime):={1\over{Z(\theta)}}\exp\{-E_\theta(z,z^\prime)\},\:\:\: E_\theta(v,v^\prime)=||z-z^\prime||^2/\tau

and the gradient of the objective of (7) is given by

θEp[logqθ(v,v)]=Eqθ[θEθ(v,v)]Ep[θEθ(v,v)].(9)\nabla_{\theta}\mathbb{E}_p[\log q_\theta(v,v^\prime)]=\mathbb{E}_{q_\theta}[\nabla_\theta E_\theta(v,v^\prime)]-\mathbb{E}_p[\nabla_\theta E_\theta(v,v^\prime)]. \:\:\: (9)

However, computing the first expectation in (9) requires sampling pairs of views (v,v)(v,v^\prime) from qθ(v,v)q_\theta(v,v^\prime) via SGLD, which could be expensive. To avert this problem, we use Bayes’rule to decompose

모델에서 샘플링 된 데이터에 대한 에너지함수의 기댓값인 Eqθ[θEθ(v,v)]\mathbb{E}_{q_\theta}[\nabla_\theta E_\theta(v,v^\prime)] 는 모델 qθq_\theta에서 샘플링 해야 된다는 치명적인 문제가 발생한다. 이러한 문제가 발생하지않게 하기 위해 베이즈룰을 이용해 위 식을 decompose해주면 아래와 같다.

Ep[logqθ(v,v)]=Ep[logqθ(vv)]+Ep[logqθ(v)]whereqθ(v)=qθ(v,v)dv.\mathbb{E}_p[\log q_\theta(v,v^\prime)]=\mathbb{E}_p[\log q_\theta(v^\prime|v)]+\mathbb{E}_p[\log q_\theta(v)]\:\:\text{where} \: \:q_\theta(v)=\int q_\theta(v,v^\prime)dv^\prime.

위 식에서 우변의 첫번째와 두번째 term들은 각각 discriminativegenerative term을 나타낸다.

the first and second terms at the RHS will be referred to as discriminative and generative terms, respectively, throughout the paper. A similar decomposition was used by Grathwohl et al. in the setting of learning generative classifiers.

Furthermore, we add a hyper-parameter λ\lambda to balance the strength of the disciriminative term and the generative term. The advantage of this modification will be discussed in Section 4.3. This yields our EBCLR objective

L(θ):=Ep[logqθ(vv)]+λEp[logqθ(v)].(11)\mathcal{L}(\theta):=\mathbb{E}_p[\log q_\theta(v^\prime |v)]+ \lambda\mathbb{E}_p[\log q_\theta(v)]. \:\:\: (11)

The discriminative term can be easily differentiated since the partition function Z(θ)Z(\theta) cancels out when qθ(v,v)q_\theta(v,v^\prime) is divided by qθ(v)q_\theta(v). However, the generative term still contains Z(θ)Z(\theta). We now present our key result, which is used to maximize (11). The proof is deferred to Appendix C.1.

What your classifier is hiding

최근 머신러닝에서, KK class를 갖는 분류 문제는 전형적으로 각각의 데이터 포인트 xRD\mathbf{x}\in\mathbb{R}^DKK real-valued numbers known as logits로 맵핑해주는 parametric function, fθ:RDRKf_\theta:\mathbb{R}^D\rightarrow\mathbb{R}^K를 사용하여 푸는 것이다. 이러한 logits는 categorical distribution을 parameterize하는 것으로 사용되는데, 이 때 Softmax transfer function을 사용한다.

pθ(yx)=exp(fθ(x)[y])yexp(fθ(x)[y]),(4)p_\theta(y|\mathbf{x})={\exp(f_\theta(\mathbf{x})[y])\over\sum_{y^\prime}\exp(f_\theta(\mathbf{x})[y^\prime])},\:\:\:\:(4)

여기서 fθ(x)[y]f_\theta(\mathbf{x})[y]fθ(x)f_\theta(\mathbf{x})ythy^\text{th} index를 가리키고, logit은 ythy^\text{th} class label을 의미한다.

논문의 저자의 주요한 관점은 다음과 같다.

fθf_\theta로 부터 얻은 logit을 p(x,y)p(\mathbf{x},y)p(x)p(\mathbf{x})로 약간 재해석할 수 있다는 것이다. fθf_\theta를 변화시키지 않고, logits을 재활용 하여 joint distribution of data point x\mathbf{x} and labels yy 에 기반한 energy based model을 만들어낼 수 있다 :

pθ(x,y)=exp(fθ(x)[y])Z(θ),(5)p_\theta(\mathbf{x},y)={\exp{(f_\theta(\mathbf{x})[y])}\over Z(\theta)},\:\:\:\:(5)

여기서 Z(θ)Z(\theta)는 unknown normalizing constant이고, Eθ(x,y)=fθ(x)[y]E_\theta(\mathbf{x},y)=-f_\theta(\mathbf{x})[y]이다.

yy를 marginalizing함으로써, unnormalized density model x\mathbf{x}를 얻어낼 수 있다.

pθ(x)=ypθ(x,y)=yexp(fθ(x)[y])Z(θ),(6)p_\theta(\mathbf{x})=\sum_y p_\theta(\mathbf{x},y)={\sum_y\exp(f_\theta(\mathbf{x})[y])\over Z(\theta)},\:\:\:\:(6)

여기서 아무 분류기의 logtis의 LogSumExp()\text{LogSumExp}(\cdot)x\mathbf{x} data point에서 energy function으로 정의되기 위해 재사용될 수 있다.

Eθ(x)=LogSumExpy(fθ(x)[y])=logyexp(fθ(x)[y]).(7)E_\theta(\mathbf{x})=-\text{LogSumExp}_y(f_\theta(\mathbf{x})[y])=-\log\sum_y\exp(f_\theta(\mathbf{x})[y]).\:\:\:\:(7)

이게 무슨 말이냐면, 위에 pθ(x)p_\theta(\mathbf{x})에서의 Energy function Eθ(x)E_\theta(\mathbf{x})가 energy based model 기준에서 LogSumExp-\text{LogSumExp}가 되어야 pθ(x)p_\theta(\mathbf{x})가 만들어진다는 의미이다.


pθ(x)=exp(Eθ(x))Z(θ)p_\theta(\mathbf{x})={\exp(-E_\theta(\mathbf{x}))\over{Z(\theta)}}
logpθ(x)=logZ(θ)Eθ(x)θlogpθ(x)=1Z(θ)θZ(θ)θEθ(x)=1Z(θ)θexp{Eθ(x)}dxθEθ(x)=1Z(θ){θEθ(x)}exp{Eθ(x)}dxθEθ(x)={θEθ(x)}1Z(θ)exp{Eθ(x)}dxθEθ(x)={θEθ(x)}pθ(x)dxθEθ(x)=Epθ(x)[θEθ(x)]θEθ(x).\log p_\theta(\mathbf{x})=-\log Z(\theta)-E_\theta(\mathbf{x})\\ \nabla_\theta\log p_\theta(\mathbf{x})= -{1\over{Z(\theta)}}\nabla_\theta Z(\theta)-\nabla_\theta E_\theta(\mathbf{x})\\={-{1\over{Z(\theta)}}}\nabla_\theta\int\exp\{-E_\theta(\mathbf{x})\}d\mathbf{x}-\nabla_\theta E_\theta(\mathbf{x})\\=-{1\over{Z(\theta)}}\int\{-\nabla_\theta E_\theta(\mathbf{x})\}\cdot\exp\{-E_\theta(\mathbf{x})\}d\mathbf{x} -\nabla_\theta E_\theta(\mathbf{x})\\=\int\{\nabla_\theta E_\theta(\mathbf{x})\}\cdot{1\over{Z(\theta)}}\exp\{-E_\theta(\mathbf{x})\}d\mathbf{x} -\nabla_\theta E_\theta(\mathbf{x})\\=\int\{\nabla_\theta E_\theta(\mathbf{x})\}\cdot p_\theta(\mathbf{x})d\mathbf{x}-\nabla_\theta E_\theta(\mathbf{x})\\=\mathbb{E}_{p_\theta(\mathbf{x}^\prime)}[\nabla_\theta E_\theta(\mathbf{x})]-\nabla_\theta E_\theta(\mathbf{x}).

qθ(v):=1Z(θ)exp{Eθ(v)},Eθ(v):=logezz2/τdv(12)q_\theta(v):={1\over{Z(\theta)}}\exp\{-E_\theta(v)\},\:\:\: E_\theta(v):=-\log\int e^{||z-z^\prime||^2/\tau}dv^\prime\:\:\:\:(12)
1Z(θ)exp{Eθ(v)}=1Z(θ)ezz2/τdv=1Z(θ)ezz2/τdv=qθ(v,v)dv=qθ(v){1\over{Z(\theta)}}\exp\{-E_\theta(v)\}={1\over{Z(\theta)}}\int e^{-||z-z^\prime||^2/\tau}dv^\prime\\=\int {1\over{Z(\theta)}}e^{-||z-z^\prime||^2/\tau}dv^\prime\\= \int q_\theta(v,v^\prime)dv^\prime\\=q_\theta(v)
qθ(v,v):=1Z(θ)exp{zz2/τ}.(6)q_\theta(v,v^\prime):={1\over{Z(\theta)}}\exp\{-||z-z^\prime||^2/\tau\}.\:(6)
logqθ(v)=logZ(θ)Eθ(v)\log q_\theta(v)=-\log Z(\theta)-E_\theta(v)
θlogqθ(v)=1Z(θ)θZ(θ)θEθ(v)=1Z(θ)θexp{Eθ(v)}dvθEθ(v)=1Z(θ)θexp{Eθ(v)}dvθEθ(v)=1Z(θ){θEθ(v)}exp{Eθ(v)}dvθEθ(v)={θEθ(v)}1Z(θ)exp{Eθ(v)}dvθEθ(v)={θEθ(v)}qθ(v)dvθEθ(v)=Eqθ[θEθ(v)]θEθ(v).\nabla_\theta \log q_\theta(v)=-{1\over{Z(\theta)}}\nabla_\theta Z(\theta)- \nabla_\theta E_\theta(v)\\=-{1\over Z(\theta)}\nabla_\theta\int\exp\{-E_\theta(v)\}dv-\nabla_\theta E_\theta(v)\\=-{1\over Z(\theta)}\int\nabla_\theta\exp\{-E_\theta(v)\}dv-\nabla_\theta E_\theta(v)\\=-{1\over{Z(\theta)}}\int\{-\nabla_\theta E_\theta(v)\}\cdot\exp\{-E_\theta(v)\}dv -\nabla_\theta E_\theta(v)\\=\int\{\nabla_\theta E_\theta(v)\}\cdot{1\over{Z(\theta)}}\exp\{-E_\theta(v)\}dv -\nabla_\theta E_\theta(v)\\=\int\{\nabla_\theta E_\theta(v)\}\cdot q_\theta(v)dv-\nabla_\theta E_\theta(v)\\=\mathbb{E}_{q_\theta}[\nabla_\theta E_\theta(v)]-\nabla_\theta E_\theta(v).

where Z(θ)Z(\theta) is the partition function in (6), and the gradient of the generative term is given by

θEp[logqθ(v)]=Eqθ(v)[θEθ(v)]Ep[θEθ(v)].(13)\nabla_{\theta}\mathbb{E}_p[\log q_\theta(v)]=\mathbb{E}_{q_\theta(v)}[\nabla_\theta E_\theta(v)]-\mathbb{E}_p[\nabla_\theta E_\theta(v)].\:\:\:\:(13)

Thus, the gradient of the EBCLR objective(14) is

θL(θ)=Ep[θlogqθ(vv)]+λEqθ(v)[θEθ(v)]λEp[θEθ(v)].(14)\nabla_\theta\mathcal{L}(\theta)=\mathbb{E}_p[\nabla_\theta\log q_\theta(v^\prime |v)]+\lambda\mathbb{E}_{q_\theta(v)}[\nabla_\theta\mathbb{E}_\theta(v)]-\lambda\mathbb{E}_p[\nabla_\theta\mathbb{E}_\theta(v)].\:\:\:\:(14)

Theorem 2 suggests that the EBM for the joint distribution can be learned by computing the gradients of the discriminative term and the EBM for the marginal distribution. Moreover, we only need to sample vv from qθ(v)q_\theta(v) to compute the second expectation in (14).

Approximating the EBCLR Objective

L(θ):=Ep[logqθ(vv)]+λEp[logqθ(v)].(11)\mathcal{L}(\theta):=\mathbb{E}_p[\log q_\theta(v^\prime |v)]+ \lambda\mathbb{E}_p[\log q_\theta(v)]. \:\:\: (11)

To implement EBCLR, we need to approximate expectations in (11) with their empirical means.

For a given batch of images {xn}n=1N\{x_n\}^N_{n=1} and two image transformations t,tt,t^\prime, contrastive learning methods first create two views vn=t(xn),vn=t(xn)v_n=t(x_n),v_n^\prime=t^\prime(x_n) of each instance xnx_n.

Suppose samples {(vn,vn)}n=1N\{(v_n,v^\prime_n)\}^N_{n=1} from p(v,v)p(v,v^\prime) are given, and let {(zn,zn)}n=1N\{(z_n, z^\prime_n)\}^N_{n=1} be the corresponding projections. As the learning goal is to make qθ(vn,vn)q_\theta(v_n, v^\prime_n) approximate the joint probability density function p(vn,vn)p(v_n, v^\prime_n), the empirical mean qθ^(vn)\hat{q_\theta}(v_n) can be defined as:

qθ^(vn)=1Nvm:vmvnqθ(vn,vm)(15)\hat{q_\theta}(v_n)={1\over{N^\prime}} \:\:\:\sum_{v^\prime_m:v^\prime_m\neq v_n}q_\theta(v_n,v^\prime_m) \:\:\:(15)

where the sum is over the collection of vmv^\prime_m defined as

{vm:vmvn}:={vk}k=1N{vk}k=1N{vn}\{v^\prime_m:v^\prime_m\neq v_n\}:=\{v_k\}^N_{k=1}\cup\{v^\prime_k\}^N_{k=1}-\{v_n\}

and N:={vm:vmvn}=2N1N^\prime :=|\{v^\prime_m:v^\prime_m\neq v_n\}|=2N-1. One could also use a simpler form of the empirical mean :

qθ^(vn)=1Nm=1Nqθ(vn,vm)(17)\hat{q_\theta}(v_n)={1\over{N}}\sum^N_{m=1}q_\theta(v_n,v^\prime_m)\:\:\:(17)
L(θ):=Ep[logqθ(vv)]+λEp[logqθ(v)].(11)\mathcal{L}(\theta):=\mathbb{E}_p[\log q_\theta(v^\prime |v)]+ \lambda\mathbb{E}_p[\log q_\theta(v)]. \:\:\: (11)

Similarly, qθ(vv)q_\theta(v^\prime|v) in (11), which should approximate the conditional probability density p(vv)p(v^\prime|v), can be represented in terms of qθ(vn,vn)q_\theta(v_n,v^\prime_n). Specifically, we have

qθ(vnvn)qθ(vn,vn)qθ^(vn)=qθ(vn,vn)1Nvm:vmvnqθ(vn,vm)=eznzm2/τ1Nvm:vmvneznzm2/τq_\theta(v^\prime_n|v_n)\simeq{q_\theta(v_n,v^\prime_n)\over{\hat{q_\theta}(v_n)}}={q_\theta(v_n,v^\prime_n)\over{{1\over N^\prime}\sum_{v^\prime_m:v^\prime_m\neq v_n}q_\theta(v_n,v^\prime_m)}}={e^{-||z_n-z_m^\prime||^2/\tau}\over{{1\over N^\prime}\sum_{v^\prime_m:v^\prime_m\neq v_n}e^{-||z_n-z_m^\prime||^2/\tau}}}

It is then immediately apparent that the empirical form of the discriminative term using (18) is a particular instance of the contrastive learning objective such as InfoNCE and SimCLR. Hence, EBCLR can be interpreted as complementing contrastive learning with a generative term defined by an EBM.

For the second term, we use the simpler form of the empirical mean in (17):

qθ^(vn)=1Nm=1Nqθ(vn,vm)=1Z(θ)1Nm=1Nexp{znzm2/τ}\hat{q_\theta}(v_n)={1\over{N}}\sum^N_{m=1}q_\theta(v_n,v^\prime_m)={1\over Z(\theta)}\cdot{1\over N}\sum^N_{m=1}\exp\{-||z_n-z_m^\prime||^2/\tau\}

We could also use (15) as the empirical mean, but either choice showed identical performance (see Appendix E.3.). So, we have found (15) to be not worth the additional complexity, and have resorted to the simpler approximation (17) instead. (17이 더 간단)

Eθ(v;{vm}m=1N):=log(m=1Nezzm2/τ).(20)E_\theta(v;\{v^\prime_m\}^N_{m=1}):=-\log(\sum^N_{m=1} e^{-||z-z^\prime_m||^2/\tau}).\:\:\:(20)

Modifications to SGLD

θL(θ)=Ep[θlogqθ(vv)]+λEqθ(v)[θEθ(v)]λEp[θEθ(v)].(14)\nabla_\theta\mathcal{L}(\theta)=\mathbb{E}_p[\nabla_\theta\log q_\theta(v^\prime |v)]+\lambda\mathbb{E}_{q_\theta(v)}[\nabla_\theta\mathbb{E}_\theta(v)]-\lambda\mathbb{E}_p[\nabla_\theta\mathbb{E}_\theta(v)].\:\:\:\:(14)

Theorem 2에 따르면, 식 14에서 두번째 기댓값을 계산하기 위해서는 marginal qθ(v)q_\theta(v)로부터의 샘플이 필요하다. 따라서, 이를 위해 proximal SGLD with the energy function (20)을 적용하면

v~t+1=v~tαclamp{vEθ(v~t;{vm}m=1N),δ}+ϵ(21)\tilde{v}_{t+1}=\tilde{v}_t-\alpha\cdot\text{clamp}\{\nabla_vE_\theta(\tilde{v}_t;\{v^\prime_m\}^N_{m=1}),\delta\}+\epsilon\:\:\:\:(21)

fort=0,...,T1,whereϵN(0,σ2)\text{for}\:t=0,...,T-1,\:\text{where}\:\epsilon\sim\mathcal{N}(0,\sigma^2)이다. 본 논문에서는 proximal SGLD를 추가적으로 세가지를 수정한다. 지금부터 언급하는 SGLD는 아래의 proximal SGLD를 의미한다

vt+1=vtαclamp{vEθ(vt),δ}+ϵ(5)v_{t+1}=v_t-\alpha\cdot\text{clamp}\{\nabla_vE_\theta(v_t),\delta\}+\epsilon\:\:\:(5)

첫번째로, 논문에서는 SGLD를 probability ρ\rho를 가지고, 이전 iterations으로 부터 나온 generated samples 으로부터 initialize하고, 다시 SGLD chains를 proposal distribution q0q_0로부터 샘플링된 샘플로부터 reinitialize한다. 이것은 keeping a replay buffer B\mathcal{B} of SGLD samples from previous iterations를 통해 달성한다. 이러한 기술은 replay buffer를 유지하는 기술로, EBM의 convergence를 가속화시키고 안정화시키기 위해 중요한 기술이며, 이전 works에서 증명되었다.

First, we initialize SGLD from generated samples from previous iterations, and with probability ρ\rho, we reinitialize SGLD chains from samples from a proposal distribution q0q_0. This is achieved by keeping a replay buffer B\mathcal{B} of SGLD samples from previous iterations. This technique of maintaining a replay buffer has also been used in previous works and has proven to be crucial for stabilizing and accelerating the convergence of EBMs.

Second, the proposal distribution q0q_0 is set to be the data distribution p(v)p(v). This choice differs from those of previous works which have either used the uniform distribution or a mixture of Gaussians as the proposal distribution.

Finally, we use multi-stage SGLD (MSGLD), which adaptively controls the magnitude of noise added in SGLD. For each sample v~\tilde{v} in the replay buffer B\mathcal{B}, we keep a count κv~\kappa_{\tilde{v}} of number of times it has been used as the initial point of SGLD. For samples with a low count, we use noise of high variance, and for samples with a high count, we use noise of low variance. Specifically, in (5), we set

σ=σmin+(σmaxσmin)[1κv~/K]+\sigma=\sigma_{\min}+(\sigma_{\max}-\sigma_{\min})\cdot[1-\kappa_{\tilde{v}}/K]_+

where []+:=max{0,},σmax2andσmin2[\cdot]_+:=\max\{0,\cdot\},\sigma^2_{\max}\:\text{and}\:\sigma^2_{\min} are the upper and lower bounds on the noise variance, respectively, and KK controls the decay rate of noise variance. The purpose of this technique is to facilitate quick exploration of the modes of qθq_\theta and still gurantee SGLD generates samples with sufficiently low energy. The pseudocodes for MSGLD and EBCLR are given in Algorithms 1 and 2, respectively, in Appendix B, and the overall learning flow of EBCLR is described in Figure 2.

profile
거인의 어깨에 올라서서 더 넓은 세상을 바라보라 - 아이작 뉴턴

0개의 댓글