What is Label Smoothing? - 리뷰 (Overconfidence)

2020. 1. 4. 16:52관심있는 주제/뉴럴넷 질문

728x90

 

도움이 되셨다면, 광고 한번만 눌러주세요 :)

Lable Smoothing
- Neural Netowork 모델 덜 과신하게 만드는 기술

딥러닝 문제로 분류 문제에 사용할 때, 보통 다음과 같은 문제에 직면하게 된다.
( Overfitting, overconfidence )  

Overfitting은 많이 연구가 되고 있고, Early Stopping, Dropout, Weight Regularization etc  등을 해결할 수 있다.
반면에 Overconfidence는 아직 해결할 툴은 적어 보인다.

Label Smoothing은 2가지 문제들에 대해서 해결할만한 regularization technique이라고 한다. 


Overconfidence and Calibration

만약 결과값의 예측된 확률들이 정확도에 반영한다면 분류 모델은 calibrated(교정되어진다.?)
예를 들어, 100개 데이터 중에서,  모델이 예측된 확률이 각 값들이 90%라고 하자.
만약 모델이 calibrated 된다면, 90개의 데이터에 대해서는 맞게 분류가 될 것이다.
유사하게 또 다른 100개에서는 예측된 확률이 60%면 60%는 맞게 분류된 걸로 기대할 수가 있다.

wiki calibration
Calibration in classification means turning transform classifier scores into class membership probabilities

 

Calibration (statistics) - Wikipedia

There are two main uses of the term calibration in statistics that denote special types of statistical inference problems. "Calibration" can mean a reverse process to regression, where instead of a future dependent variable being predicted from known expla

en.wikipedia.org

참고 : https://3months.tistory.com/490

 

위의 그림에서 알 수 있는 것은 Lenet 같은 경우 약간 각 샘플에 대해서 클래스들에 대해서 평탄하게 확률 값이 나오지만,
요즘 최근 Resnet 같은 경우에는 모형이 클래스 예측하는데 굉장히 90% 확률로 overconfident 한다는 것이다.
이것이 실제 정확도에는 잘 맞추면 좋긴 하지만, confidence 관점에서는 한쪽에 치우쳐서 어긋난다는 것을 알 수 있다.

딥러닝에서 Calibration에 대한 설명은 아래 글이 참 좋은 것 같은 참고!

https://3months.tistory.com/490

 

[논문리뷰] 현대 딥러닝의 Calibration 에 대하여

[논문리뷰] 현대 딥러닝의 Calibration 에 대하여 현대 Neural network 의 calibration 에 관하여라는 논문을 리뷰하여 포스팅하겠습니다. 딥러닝의 성능 (performance) 이라 하면 일반적인 용어 '정확도' 를 뜻..

3months.tistory.com

 


Model Calibration은 아래 항목에서 중요하다.

  • model interpretability and reliability
  • deciding decision thresholds for downstream application
  • integrating our model into an ensemble or a ML pipeline

(overconfident) 과신하는 모델은 calibrated하지 못하다. 그리고 예측된 확률은 일관적으로 정확도보다 높게 나온다.
정확도는 60% 이지만, 인풋들에 대해서 예측이 90%가 되는 것과 같은 것이 하나의 예다.

모델의 작은 test errors 여전히 overconfient 하다는 것에 대해 주목해야 하고,
이러한 것에 label smooting이 도움이 된다.


Formula of Label Smoothing

Label Smoothing은  one-hot으로 인코딩 된 label vector에다가 uniform distribution의 결합이다.

K는 클래스의 개수, alpha는 하이퍼 파라미터이고
만약 alpha=1이면 uniform distribution이고 alpha=0 이면, 그냥 encoding 된 one-hot이다.

The motivation of Label Smoothing

Label Smoothing은 loss function으 cross entropy일 때 사용된다. 
모델은 출력 확률을 계산하기 위해 penultimate layer의 logit 벡터 z에 softmax 함수를 적용한다.
이러한 세팅에서, logits에 대하여 cross-entropy loss function의 gradient는 간단하다.

y는 label distribution이다.

  1. Gradient descent will try to make p as close to y as possible.
  2. The gradient is bounded between -1 and 1.

Graident Descent는 p값이 y값에 가깝도록 만들게 한다. (그래서 극단적으로 가게 하는 것 같다)
gradient는 -1,1로 bounded 되어 있다.

one-hot encoded labels는 가능한 최대 logit 간격을 softmax function 함수로 반영되게 한다.
bounded gradient와 결합된 larget logit gaps는 모델을 덜 적응하게 하고 예측에 대해 너무 자신감을 갖게 할 것이다.

이와는 대조적으로 smoothed labels은 아래에서 설명한 것처럼작은 logit gap을 권장하게 한다. 

A Concrete Example

3개의 클래스가 있고 a, b, c가 있다고 하자. 여기서 현재 1st class에 속한다고 하자.
만약 label smoothing을 사용하지 않는다면 label vector 은 (1,0,0)이고 모델은 a >> b, a>>c로 될 것이다.
그래서 logit vector (10,0,0)을 사용한다면 (0.9999,0,0)을 얻게 될 것이다.

만약 label smoothing을 alpha =0.1을 사용한다면, label vector는 (0.9333,0.033,0.033)이라고 하자.
logit vector는 (3.3322,0,0)에 적용하면 기존보다 더 적은 logit gap을 가질 것이다.
This is why we call label smoothing a regularization technique as it restrains the largest logit from becoming much bigger than the rest.

이미 Tensor flow에서는 이 기술이 적용되고 있다.
https://www.tensorflow.org/api_docs/python/tf/keras/losses/BinaryCrossentropy?version=stable

불러오는 중입니다...

https://www.tensorflow.org/api_docs/python/tf/keras/losses/CategoricalCrossentropy?version=stable

 

tf.keras.losses.CategoricalCrossentropy  |  TensorFlow Core r2.0

See Stable See Nightly Class CategoricalCrossentropy Computes the crossentropy loss between the labels and predictions. Aliases: tf.losses.CategoricalCrossentropy Used in the guide: Used in the tutorials: Use this crossentropy loss function when there are

www.tensorflow.org

## tensorflwo 1.x
alpha = 0.9
y_one_hot = tf.add(alpha* tf.one_hot( tf.cast(y , tf.int32) , depth=target_dim) ,
                   (1-alpha) / target_dim)

Frequently Asked Questions

Q: When do we use label smoothing?

A: Whenever a classification neural network suffers from overfitting and/or overconfidence, we can try label smoothing.

Q: How do we choose α?

A: Just like other regularization hyperparameters, there is no formula for choosing α. It is usually done by trial and error, and α = 0.1 is a good place to start.

Q: Can we use distributions other than uniform distribution in label smoothing?

A: Technically yes. In [4] the theoretical groundwork is developed for arbitrary distributions. That being said, the vast majority of empirical studies on label smoothing use uniform distribution.

Q: Is label smoothing used outside deep learning?

A: Not really. Most popular non-deep learning methods do not use the softmax function. Thus label smoothing is usually not applicable.

 

https://towardsdatascience.com/what-is-label-smoothing-108debd7ef06

 

What is Label Smoothing?

A technique to make your model less overconfident

towardsdatascience.com

 

 

728x90