본문 바로가기
카테고리 없음

aif-3

by 자벤 2025. 6. 4.

Linear Layer

we get input vector x and perform linear transformation y = Wx+b (W:weight matix, b:bias vector)

it can called as "fully connected layer, dense layer, affine layer and so on)

The # of input nodes : m

The # of output nodes : n

parameters to learn : weight (m * n), bias (n)

 

Euqation Example

(2, 1): 2 inputs, 1 output -> y=w1x1+w2x2 + b

(2, 3): 2 inputs, 3 ouputs -> y1, y2, y3 will be calculated to each other weight set

Y = XW + B

 

Activation Layer

Role : we can make only linear model if we just stack linear layers => expression is limited

So we can use activation layer to make non-linearity to solve complicated problems

 

Main activation layer function

Step : h(x) = 0 if x<=0, 1 if x>0 : non propagation is impossible, not use these days

Sigmoid : h(x) = 1/(1+e^-x) : 0~1 output, soft but gradient vansihing problem exist

ReLU : h(x) =0 if x<=0, x if x>0 : the most used model.

tanh : h(x) = (e^x - e^-x)/(e^x+e^-x) : -1 ~ 1 output, more symmetric than sigmoid model

 

gradient vanishing : Backpropagation 과정에서 gradient가 layer을 거치며 점점 작아져 0에 수렴하는 현상 0 -> 초기 층들이 거의 학습되지 않는 문제 발생

여기서 말하는 gradient가 저기 저 dL/dw이다.

L은 Loss function이고 이는 chain rule에 따라 아래와 같이 표현된다

저렇게 중간에 sigmoid layer가 들어가게 된다면 결국 시그모이드의 미분값이 필요한데 시그모이드 미분값은 정확하지는 않지만 확실히 0~1 사이다. 이는 gradient의 값을 0에 수렴하게 되는 원인이고, 이로 인해 gradient vanishing 문제가 생긴다는 것이다.

 

Comprision : (2, 3, 2, 2)

input layer 2

1st hidden layer 3 nodes

2nd hidden layer 2 nodes

output layer 2 nodes

 

Equation example

출력층 함수 : sigmoid vs softmax

sigmoid layer : 출력값을 0~1 사이의 확률로 변환

Binary Classification(2가지 클래스)에서 사용

수식 : p(s) = 1/(1+e^-s)

 

Softmax Layer

We use to select one of multiple classes. (ex. MNIST 0~9 numbers)

Each classes will be converted to probability , the sum would be 1

p_k=e^s_k/sigma_1_to_Nc(e^s_i)

input : [1,2] => softmax => [0.269, 0.731]

input : [1, -2] => softmax => [0.953, 0.047]

 

Entire Sturucture Summary

[input] -> [Linear Layer(Affine)] -> [Activation Function (ReLU, sigmoid), several layers repeatitive if possible] -> [Output : Linear + Softmax or Sigmoid] -> [Loss Calculation (Cross Entropy and so on)]