Note1. 각 Layer는 linear / non-linear function들오 연결되어 있다. Note 2. “pattern” == “embedding”, “weights”, “feature representation”, “feature vectors” 다 비슷한 걸 가르킨다. ! Note 3 !. layer의 개수를 셀 때에는 input-layer는 제외한다.
Why Do We Need Non-linearity?
Non-Linearity
Nonlinearity
복잡한 현실 세계의 복잡한 함수를 다루기 위해
matrix의 matmul이 결국 linear하니까, non-linear 함수를 중간에 끼지 않는 이상 결국은 하나의 큰 선형 시스템을 벗어날 수 없음. 세상이 선형함수로만 설명 가능할리 없잖아,,
→ 선형 연산을 거듭해도 선형.
Numerical Proof
Assume that,
f=W2⋅max(0,W1⋅x)
where x∈RD, W1∈RH×D, W2∈RC×H
ReLU
ReLU(x)=max(0,x)
one of non-linear activation
In this time, it is impossible to distinguish below 2 models,
f=W2⋅W1⋅x f=W3⋅x
where W3∈RC×H
→ 결국 linear
→ 그러니 non-linear function을 activation으로 사용하자!!
Linearly Separable ← 고민 좀 해보자. 왜 좋냐?
Important
non-linear map은 data를 linearly-separable하게 바꿀 수 있다.
Examples
Activation Functions
나중에 transformer 계열에 최근 가장 많이 사용되는 GeLU 계열이나 찾아볼 것.
Summary
No one-size-fits-all: Choice of activation function depends on problem.
We only showed the most common ones, there exist many more
Best activation function / model is often using trial-and-error in practice
It is important to ensure a good “gradient flow” during optimization
Rule of Thumb
Use ReLU by default(with small enough lr)
Try Leaky ReLU, Maxout, ELU for some small additional gain
Prefer Tanh over sigmoid(Tanh often used in RNNs)
ReLU
ReLU(Rectified Linear Unit)
activation 중 하나로 대표적으로 많이 사용됨. g(x)=max(x,0)
Does not saturate(for x>0)
Leads to fast convergence
Computationally efficient
Problems
No learning for x<0 → dead/dying ReLU
downstream gradient가 0(input이 0 이하일 때,)
often initialize with pos. bias (b>0)
Outputs are not zero-centered → introduces bias after the layer
sigmoid와 그 gradient는 항상 positive이기 때문에 model wight의 bias