본문 바로가기

데이터 과학/데이터 과학 기초

Batch Normalization

출처: https://www.srose.biz/wp-content/uploads/2020/08/Deep-Learning-Performance-Part-3-Batch-Normalization-Dropout-Noise.html

Layer 를 많이 쌓게되면 학습을 하는 동안 각 layer 의 input 의 분포가 계속 달라지게 된다. 이런 현상을 internal covariate shift 라 하는데, 이로 인하여 모델의 학습이 어렵고, learning rate 를 낮게 셋팅해야 하는 문제가 발생한다.

 

Batch normalization 은 internal covariate shift 를 해결하기 위해 layer 의 input batch 를 normalization 하는 방법이다. Batch normalization 은 non-linear activation funtion 앞에 배치되며, activation function 의 input 에 대하여 아래와 같은 transformation 을 적용한다.

 

$n$ 은 batch size, $x_{i,j}$ 는 batch $\mathcal{B}$ 내에서 i 번째 example 의 feature vector 의 $j$ 번째 value 라 하자.

이 때 feature vector batch 의 $j$ 번째 value 에 대한 batch normalization transformation 은 아래와 같다.

$$ \mu_{\mathcal{B}, j} \leftarrow {1 \over n} \sum_{i=1}^n x_{i, j} $$

$$ \sigma^2_{\mathcal{B}, j} \leftarrow {1 \over n} \sum_{i=1}^n (x_{i,j} - \mu_{\mathcal{B}, j})^2 $$

$$ \hat{x_{i,j}} \leftarrow {x_{i,j} - \mu_{\mathcal{B}, j} \over \sqrt{\sigma_{\mathcal{B},j}^2 + \epsilon}} $$

$$ y_{i, j} \leftarrow \gamma \hat{x_{i,j}} + \beta $$

두 번째 식에서 batch 의 분산을 구할 때 공분산을 구할 경우 Cov[x] 의 inverse square root 를 계산해야 하기 때문에 연산량이 많이 요구된다. 그래서 batch normalization 에서는 feature vector 내의 scalar 들이 독립이라 가정하고 분산을 구한다.

 

세 번째 식을 거치면 batch 의 평균과 분산은 0, 1 이 된다. 이런 값이 sigmoid function 의 input 으로 주어질 경우 0 에 가까운 값에 대한 output 만 나오기 때문에 sigmoid function 이 linear 함수와 비슷하게 쓰이게 된다. 그 결과 neural network 의 표현력이 줄어들 수 있으므로, 마지막 식에서 normalization 된 $\hat{x_{i,j}}$ 을 $\gamma$ 와 $\beta$ 로 linear transformation 한다.

Sigmoid function 은 0 부근에서 linear function 과 유사하게 동작한다.

Linear transformation 을 위한 $\gamma$ 와 $\beta$ 는 학습된다.

 

 

Batch normalization 을 적용한 neural network 는 parameter 의 scale 에 영향을 받지 않기 때문에 더 큰 learning rate 로 학습할 수 있고, 덤으로 dropout 없이도 generalization 이 잘 된다고 한다.

'데이터 과학 > 데이터 과학 기초' 카테고리의 다른 글

직관적인 Universal Approximation Theorem 증명  (0) 2020.12.18
L1, L2 Regularization  (0) 2020.12.08
Bias-Variance Trade-off  (0) 2020.12.06
Overfitting과 Underfitting  (0) 2020.12.03
본 블로그는 쿠팡 파트너스 활동을 포함하고 있으며, 이에 따른 일정액의 수수료를 제공받습니다.