Swish , Selu activation function 둘중에는 Selu?

2019. 9. 14. 22:09관심있는 주제/Activation Function

728x90

https://towardsdatascience.com/gentle-introduction-to-selus-b19943068cd9

 

A first Introduction to SELUs and why you should start using them as your Activation Functions

A first introduction to SELUs, their relation to ReLUs as well as the issues of vanishing gradients and normalization.

towardsdatascience.com

기존에 포스팅하고자 했더 selu를 쓰라고 했는데, 다른 함수에 대한 설명들도 있길래, 일단 끄적여본다.

일단 selu가 relu보다 좋은 점은 다음과 같다고 한다.

  1. Similar to ReLUs, SELUs enable deep neural networks since there is no problem with vanishing gradients.
  2. In contrast to ReLUs, SELUs cannot die.
  3. SELUs on their own learn faster and better than other activation functions, even if they are combined with batch normalization.

활성화 함수는 y가 평균을 이동하기 위해 양의 값과 음의 값을 모두 필요로 한다. 두 가지 선택권은 모두 여기에 주어진다. 또한, ReLU가 음수 값을 출력할 수 없기 때문에 자가 정규화 활성화 기능의 후보가 되지 않는 이유도 여기에 있다.

gradient는 분산을 조정하는 데 사용할 수 있다. 

활성화 함수는 gradient를 증가시키기 위해 1보다 큰 gradient를 가진 영역이 필요하다.


 

아래 미디엄 글에서는 swish를 사용해야 하는 이유가 나오는 글이다. 

위의 글에서는 selu를 사용하라고 했는데,... 역시 답은 없나보다.

모든 심층 네트워크의 중심에는 선형 변환에 이어 ReLU, sigmoid 등과 같은 활성화 기능이 있다.

활성화 함수는 필요한 이유는 다음과 같다.

 neural network가 어떤 목적으로 만들었는지 예측하기 위해서 비선형 복잡한 함수를 배울 수 있기를 바라지만, 만약 활성화 함수를 쓰지 않는다면 단순히 인풋에다가 가중치를 곱하기 bias를 더한 선형성만 다룰 수 있게 된다.

이러한 모델은 복잡한 것을 예측할 수가 없게 된다. 만약에 모델이 복잡한 것을 예측하게 만들고 싶다면, 복잡한 함수를 흉내 낼 수 있게 만들어야 하고, 이러한 이유로 비선형성을 가지는 모델을 만들어야 한다.

swish

 

그러면 우리가 대체로 알고 있는 relu 같은 좋은 함수가 있는데, 굳이 이걸 왜 써야 하는지 물어볼 수 있다.

relu도 좋긴 하지만, relu가 미분을 했을 때 음수 값에서는 0을 가지게 돼서 결국 neural network 가 더 이상 update가 되지 않는다. 

gradient가 0이 되면, 더이상 업데이트는 되지 않고 즉 발전하지 않는다. 

그래서 이러한 문제를 해결하기 위해 leakyrelu를 쓰지만, 실제로 의도대로 도움이 되지는 않는다.

swish 함수는 음수 쪽으로는 경계가 있고 양수 쪽으로는 제한이 없다. 

그러나 Relu와는 달리 swish는 smooth 한 형태를 가진다. 비 단조함수로써 음수 값이 0이 되지 않는다.

그래 일단 Relu보다는 swish 함수가 좋다는 것을 알 수 있는 것 같다.

그리고 이 글에서는 self-gated라는 문구에 신경을 쓸 필요가 있다.

Self-Gating 은 LSTM , Highway Network에서 sigmoid 함수의 사용에 의해 영감을 받은 기술이다. 

Self-Gating 장점은 단일 입력만 있으면 되지만 일반 게이트에는 여러 개의 스칼라 입력이 있어야 한다는 것이다.

단일 scaler 인풋에서도 사용할 수 있기 때문에 swish는 쉽게 relu를 대체할 수 있다.

Properties of Swish:

  1. Unboundedness: Unlike sigmoid and tanh functions, Swish is unbounded above which makes it useful near the gradients with values near to 0. This feature avoids Saturation as training becomes slow near 0 gradient values.
  2. Smoothness of the curve: Smoothness plays an important role in generalization and optimization. Unlike ReLU, Swish is a smooth function which makes it less sensitive to initializing weights and learning rate.
  3. Bounded Below: Like most of the activation functions out there, Swish is also bounded below which helps in strong regularization effects. Like ReLU and softplus, Swish produces produces negative outputs for small negative inputs due to its non-monotonicity. The non-monotonicity of Swish increases expressivity and improves gradient flow, which is important considering that many preactivation fall into this range.

1) Unboundedness : sigmoid나 tanh 함수들과는 달리, swish는 위로 경계가 없기 때문에 0 근처 값을 가진 gradient를 유용하게 사용 가능하다. 이러한 특징은 학습하는 동안 0 근처에서 gradient 값이 포화되는 것을 막는다.

2) Smoothness of the curve : Smooth는 일반화와 최적화에 중요한 역할을 한다. Relu와 달리 Swish는 Smooth 함수이므로, 초기값과 learing rate에 덜 민감하다.

3) Bounded Below :  Swish 함수는 아래로는 하한이 있기 때문에 강한 regularization 효과를 줄 수 있다. (Relu , Softplus) Swish 함수는 비단 조성 때문에 작은 음수 입력에도 음수 결과를 만들 수 있다. swish의 비단 조성은 표현력을 증가시키고 gradient flow를 개선시킨다. 이는 많은 사전 활성화 함수가 이 범위에 속하는 것을 고려할 때 중요하다고 한다.


생각 정리

일반적으로 활성화 함수를 비교할 때 relu랑 하다 보니, 현재 구성이 swish vs relu /  selu vs relu 형태의 2개의 글이 있는 것 같다. 

selu의 일단 장점은 internal normalization이 있는 것 같다. (paper)

main idea는 각 layer는 이전 layer로부터 평균과 분산을 보존한다. 결국 gradient 사라지는 거 방지한다는 것 같다.

swish 같은 경우에는 위의 글에서는 음수 값에도 영향을 줄 수 있고 하한은 있지만 상한이 없다는 장점을 가지고 있는데,

이러한 이유에서는 selu도 동일한 이유를 가지고 있어서, 2개 중에 만약 어떤 게 좋아보냐고 한다면 오히려 selu가 좋아 보인다.

 

https://medium.com/techspace-usict/swish-a-self-gated-activation-function-3b7e551dacb5

 

Swish: A self-gated Activation Function

Recently, Google Brain has proposed a new activation function called Swish. It is showing some remarkable performance in the networks like…

medium.com

 

728x90