Processing math: 13%

ABOUT ME

땅콩맘 블로그

Today
Yesterday
Total
  • Continual Learning (2)
    학교 수업/ADL 2023. 9. 21. 22:03

     

     

    이전 편에서 continual learning의 개념과 세 가지 접근 방식들에 대해 설명했고, 지금부터는 각 접근 방식의 대표적인 방법들을 소개할 것이다. 

     

    reference : Kirkpatrick et al., Overcoming catastrophic forgetting in neural networks, PNAS 2017

    EWC (Elastic Weight Consolidation)

    - 어떤 nodes or weights가 중요한지 찾는다. 

    - important nodes or weights에 high regularization을 준다.

    - stability에 초점이 맞춰져 있다. 

     

    EWC

    task A를 수행하는 모델의 parameter를 θA라고 했을 때, parameter space of low error for task A는 회색이고 new task인 task B를 수행할 때 parameter space of low error for task B는 노란색이라고 하자. 모델이 task B로 forward transfer 될 때 penalty를 주지 않는다면 노란색 parameter space로 이동할 것이다. 그러나 이렇게 되면 이전의 task A에서는 high error를 갖게 된다. 간단하게 L2 regularizer를 주게 되면? 왜 바깥으로 이동하는지 잘은 모르겠다. 아마 방법이 너무  naive하기 때문 아닐까? 아무튼 EWC는 두 parameter space 가 겹치는 공간으로 θA를 이동하게 하여 두 task 모두 잘 수행하려 한다. 

     

    Bayesian framework

     

    1. Single task case with a neural network model θ

        - Let D={xi,yi}ni=1 be the training data

        - Maximum Likelihood (ML) estimate of θ

    θML=argmin

        - Maximum a Posteriori (MAP) estimate of θ 

    θMAP=argminθ{logp(D|θ)logp(θ)}=argminθ{i=1nlogp(yi|xi,θ)logp(θ)}

    이 때 MAP의 logp(θ)θ의 prior 이며, standard Gaussian이다. 

     

    2. Two tasks arriving sequentially

        - Let D1D2 be the training data for each task

        - A natural MAP estimate of θ after learning Task 2

    θMAP,1:2=argminθ{logp(D2|θ)logp(θ|D1)}

    D1의 posterior를 entire dataset의 prior로 줘서 regularizer 역할을 하도록 한다. 그러나 posterior이므로 계산하기 어려워 approximate 할 것이다. 

     

    갑자기 왜 posterior가 prior가 됐으며 왜 regularizer 역할을 하는지? 

    D1의 posterior는 어떤 parameter가 중요한지에 대한 정보를 포함하고 있으므로 이를 prior로 준다. negative loss function L(θ)인  logp(D2|θ)안에서 곱해지므로 regularizer 역할을 하게 된다. 하지만 task1의 posterior를 entire task의 prior로 주는 식이 heuristic인지 아니면 수학적으로 계산된 식인지는 여쭤봐야 할 것 같다.  

     

    3. Laplace Approximation to approximate posterior logp(θ|D1)

        - Let the MAP solution be θ1=argminθ{logp(θ|D1)}

        - Approximate p(θ|D1) as a Gaussian with mean θ1 and covariance σ1

        - Approximate Σ1 with Fisher Information Matrix (FIM)

       logp(θ|D1)logp(θ1|D1)+12(θθ1)(θ2logp(θ|D1)|θ1)(θθ1)

    logp(θ|D1)N(θ1,(θ2logp(θ|D1)|θ1)1) θ2(logp(θ|D1))=θ2(logp(D1|θ)logp(θ))=1ni=1nθ2(logp(yi|xi,θ))+I

    Then, 

    θ2(logp(y|x,θ))=θ2p(y|x,θ)p(y|x,θ)+θp(y|x,θ)θp(y|x,θ)p(y|x,θ)2

    θ2(logp(y|x,θ))=θ2p(y|x,θ)p(y|x,θ)+θp(y|x,θ)θp(y|x,θ)p(y|x,θ)2

    =θ2p(y|x,θ)p(y|x,θ)+θlogp(y|x,θ)θlogp(y|x,θ)

    Take expectations leads to the identity (first term vanishes)

    Ex,y|θ(θ2(logp(y|x,θ)))=Ex,y|θ(θlogp(y|x,θ)θlogp(y|x,θ))Fθ

    여기서 Fθ가 Fisher Information Matrix (FIM) 이다. θlogp(y|x,θ) matrix는 Neural Network의 gradient이고 parameter dimension x parameter dimension 크기의 matrix이기 때문에 계산이 또 복잡해진다. 따라서 diagonal Fisher Information Matrix로 근사하여 최종적으로 covariance matrix를 구한다. 

    θ2(logp(θ|D1))|θ11ni=1nθ(logp(yi|xi,θ))θ(logp(yi|xi,θ))+I

    Hence, the final approximation becomes

    p(θ|D1)N(θ1,(diag(Fθ)|θ1+I)1)

     

    그럼 task 2를 학습하는 EWC의 loss function은 다음과 같다.

    L2(θ)=1niD2logp(yi|xi,θ)+λ2θj(1+Fθ,jj1)(θjθ1,j)2

    General task t에 대한 loss function은 FIM이 계속 더해지는 형태이다. 

    Lt(θ)=logp(Dt|θ)+λ2θj(1+s=1t1Fθ,jjs)(θjθt1,j)2

     

    이미 알고있는 다른 분포로 posterior를 approximation하는 방법은 Variational Inference와 비슷하다. 따라서 이런 방법들을 Variational Continual Learning 이라고 한다. 

     

    EWC는 위와 같이 중요한 parameter에 regularizer를 취해줌으로써 그 weight가 크게 변하지 않고 유지되도록 한다. 

    '학교 수업 > ADL' 카테고리의 다른 글

    Self-Supervised Learning (2)  (1) 2023.10.19
    Self-Supervised Learning (1)  (0) 2023.10.12
    Continual Learning (4)  (0) 2023.10.06
    Continual Learning (3)  (1) 2023.09.26
    Continual Learning (1)  (0) 2023.09.21
Designed by Tistory.