-
3. Neural Network 기초-2 (개념과 구조)NN 2021. 10. 9. 13:16
안녕하세요. 조쉬입니다!🙃🙃
오늘은 Nerual Network(이하 NN) 두 번째 주제인 Network의 개념과 구조입니다.
구조 자체가 성능과 직결되는 NN의 특성상 모델 전체 구조를 먼저 알기보다는 대표적인 구조들이 가지는 특성들에 대해서 먼저 알아보려 합니다.
1. 기초 개념
source: https://en.wikipedia.org/wiki/Neuron#/media/File:Blausen_0657_MultipolarNeuron.png 위의 그림은 사람의 신경세포입니다. 신경세포는 신체 내의 세포들 중 가장 긴 세포로서 그림 왼쪽의 Dendrite에서 다른 세포로부터 전달되어온 신경 물질들을 받습니다. 전달된 물질은 cell body로 전달되어 axon으로 확산되며 우측의 Telodendria의 채널들을 활성화시켜 다음 세포로 물질(정보)을 전달합니다.
Feed Forward Network 이러한 신경세포의 구조는 input을 받아 activate 하여 output 또는 hidden state로 정보를 넘기는 형태의 알고리즘과 유사하다고 판단한 신경학자 Warren McCulloch가 1943년에 처음으로 인공 뉴런이라고 명명하였습니다.
2. 대표 Network 특성 및 구조
- Feed Forward (FF)
source: https://www.researchgate.net/figure/Sample-of-a-feed-forward-neural-network_fig1_234055177 특성:
1. input으로부터 output까지 모든 node들이 연결
2. input ➡️ output 단방향으로 데이터가 흐름
3. input, output 사이에 hidden layer가 한층만 존재
4. 역전파(Backpropagation)를 통하여 학습
- Deep Feed Forward (DFF)
source: https://afit-r.github.io/feedforward_DNN 특성:
1. vashishing & exploding gradient 발생 가능
2. Hidden layer를 여러층 보유함
초기 Deep NN의 형태로서 역전파시에 gradient가 사라지거나 너무 커지는 경향이 문제가 되어서 사용을 어렵게 하였었습니다. 하지만 2000년대 이후로 여러 방법을 통해 해당 문제를 해결하고 구조적 이점을 활용하는 방법들의 등장을 통해 지금까지도 NN의 기초구조로 활용 중입니다.
- Recurrent NN
source: https://www.mdpi.com/1996-1073/13/1/147 특성:
1. 현시점 input cell과 고정된 특정 이전 시점(상기 이미지는 t-1)의 hidden cell의 값을 동시에 input으로 입력 받음
2. hidden cell뿐 아니라 input node 또는 variable delay 등 여러 가지 변형이 가능
Jordan Network라고도 불리는 RNN구조는 현시점과 이전 시점의 데이터를 모두 사용하여 판단을 내리는 구조입니다. 예시로 문장(context)을 입력할 때 이전 시점의 문자와 현재 시점의 문자는 서로 영향을 줄 수 있습니다.
- Long Short Term Memory (LSTM)
source: https://www.mdpi.com/1996-1073/13/1/147 특성:
- Memory cell(상기 이미지 C)의 등장
- Gate 구조(상기 이미지 x)의 활용으로 데이터의 저장 / 삭제 판단
Time lags를 구조 내에 추가한 형식입니다. C로 표현되는 Cell State로 이전 시점들의 정보를 계속 누적하여 저장함으로서 RNN이 가지는 단점인 "이전 시점과의 거리가 멀수록 정보 전달이 어렵다"를 구조적으로 해결하였습니다. Gate 구조는 forget, input, output과 같이 3개의 다른 gate구조로 구성되어 있습니다.
구조:
Forget Gate는 sigmoid function을 통하여 0 ~ 1 사이의 값으로 이전 시점(t-1)의 hidden state와 현시점의 input data를 변형시킨 후 cell state에 1에 가까울수록 반영 0에 가까울수록 미반영시킵니다.
Input Gate는 cell state로 중요 정보를 전달하는 역할을 맡고 있습니다.
1. 이전 시점 hidden state와 현시점 data를 Sigmoid 함수에 통과시킵니다. Forget Gate와 동일합니다.
2. 1번과 동일한 input을 Tanh 함수에 통과시켜 -1 ~ 1의 확률 벡터를 생성합니다.
3. 2번에서 생성된 확률 벡터를 Sigmoid gate와 곱한 뒤 결과물을 cell state에 합칩니다.
Output Gate는 다음 단계로 넘어갈 hidden state가 무엇인지 결정하는 역할을 수행합니다. 이 단계에서 최종적으로 산출되는 hidden state는 이전 단계의 input data의 정보를 가지고 있습니다. Hidden state는 예측치로도 활용 가능합니다.
1. Cell State에 Tanh 함수를 곱하여 +-1 사이로 값을 스케일링합니다.
2. 이전 시점 hidden state와 현시점 data로 만든 Sigmoid 함수 필터를 생성합니다.
3. 1번과 2번의 결과물을 곱하여 다음 단계로 넘겨줄 hidden state를 생성합니다.
- GRU
source: https://www.mdpi.com/1996-1073/13/1/147 특성:
- Cell state 미존재
- Gate 구조의 활용으로 정보의 리셋 / 업데이트 수행
GRU는 LSTM의 변형 NN입니다. GRU는 LSTM의 cell state를 없애고 hidden state로 이전 시점들의 정보를 전달하는 구조를 가지고 있습니다. GRU에는 핵심 두 가지 구조인 update, reset gate로 이뤄져 있습니다. LSTM보다 훨씬 간단한 tensor operation으로 이뤄져 있기 때문에 LSTM보다 런타임이 적습니다.
Update Gate는 LSTM에서 forget gate와 비슷한 역할을 합니다. 현시점 데이터에서 어떠한 정보를 없애고 더할지 결정하는 역할을 합니다.
Reset Gate는 이전 시점의 데이터들을 얼마나 잊어야 하는지 결정하는 구조입니다.
- Auto Encoder
source: https://excelsior-cjh.tistory.com/187 특성:
1. 비지도 학습(unsupervised learn)
2. 데이터 제약성 추가
상기 이미지를 얼핏 보면 FNN이라고 착각하기 쉽습니다. 그만큼 구조 자체는 단순해 보이지만 네트워크에 제약 사항들을 추가하며 복잡성을 가지게 됩니다. Input layer 수 보다 작은 hidden layer들을 내부에 연결시킴으로써 데이터의 차원을 축소하거나 noise를 추가하기도 하며 최대 압축 layer에서 random성을 추가하기도 하고 오히여 차원을 늘려 sparsity를 추가하기도 합니다. 이렇게 네트워크가 데이터 내에서 단순히 input을 뱉어내지 못하게 하도록 제약을 한 뒤에 데이터를 효율적으로 표현하는 방법을 학습하도록 유도합니다.
Encoder와 decoder 두 가지 핵심 구조로 AE는 이뤄져 있습니다. Input을 저 차원으로 압축시키는 부분이 encoder이며 압축된 차원의 데이터를 다시 원형태로 복구시키는 부분이 decoder가 됩니다. 데이터 및 차원 압축 과정에서 정보의 손실은 불가피하므로 중요 정보를 선택하게 되며 이와 같은 방법은 pca와 비슷하다 볼 수 있습니다.
또한 AE를 비지도 사전학습 진행시킨 후에 decoder를 classifier(MLP)로 변환하여 추후에 사용하는 방법도 가능합니다.
오늘 언급한 네트워크 구조들은 다양한 모델들의 기본 구조 및 레이어로 사용 중인 방식들입니다. 구조들에 관한 레퍼런스 코드와 내용들은 아래 링크들을 참고하시면 도움이 될 것 같습니다. 다음 시간에는 좀 더 심화 구조 예시들로 찾아뵙겠습니다. 🐶
🌳참고자료 :
- https://towardsdatascience.com/the-mostly-complete-chart-of-neural-networks-explained-3fb6f2367464
The mostly complete chart of Neural Networks, explained
The zoo of neural network types grows exponentially. One needs a map to navigate between many emerging architectures and approaches.
towardsdatascience.com
- https://en.wikipedia.org/wiki/Neural_network
Neural network - Wikipedia
From Wikipedia, the free encyclopedia Jump to navigation Jump to search Structure in biology and artificial intelligence Simplified view of a feedforward artificial neural network A neural network is a network or circuit of neurons, or in a modern sense, a
en.wikipedia.org
- https://training.galaxyproject.org/training-material/topics/statistics/tutorials/FNN/tutorial.html
Galaxy Training: Deep Learning (Part 1) - Feedforward neural networks (FNN)
Statistical Analyses for omics data and machine learning ...
training.galaxyproject.org
Artificial Neural Network for Machine Learning — Structure & Layers
Introduction of Artificial Neural Network for Machine Learning
medium.com
- https://en.wikipedia.org/wiki/Backpropagation
Backpropagation - Wikipedia
From Wikipedia, the free encyclopedia Jump to navigation Jump to search Optimization algorithm for artificial neural networks Backpropagation can also refer to the way the result of a playout is propagated up the search tree in Monte Carlo tree search. In
en.wikipedia.org
- https://medium.com/analytics-vidhya/recurrent-neural-network-and-its-variants-de75f9ee063
Recurrent Neural Network and it’s variants….
Humans when read understand each word based on their previous word understanding. We don’t forget all the information and start thinking…
medium.com
- https://en.wikipedia.org/wiki/Long_short-term_memory#/
Long short-term memory - Wikipedia
From Wikipedia, the free encyclopedia Jump to navigation Jump to search Artificial recurrent neural network architecture used in deep learning The Long Short-Term Memory (LSTM) cell can process data sequentially and keep its hidden state through time. Long
en.wikipedia.org
Illustrated Guide to LSTM’s and GRU’s: A step by step explanation
Hi and welcome to an Illustrated Guide to Long Short-Term Memory (LSTM) and Gated Recurrent Units (GRU). I’m Michael, and I’m a Machine…
towardsdatascience.com
3 Deep Learning Algorithms in under 5 minutes — Part 1 (Feed forward models)
No traces of intimidating linear algebra detected …
towardsdatascience.com
- https://excelsior-cjh.tistory.com/187
08. 오토인코더 (AutoEncoder)
이번 포스팅은 핸즈온 머신러닝 교재를 가지고 공부한 것을 정리한 포스팅입니다. 08. 오토인코더 - Autoencoder 저번 포스팅 07. 순환 신경망, RNN에서는 자연어, 음성신호, 주식과 같은 연속적인 데
excelsior-cjh.tistory.com
'NN' 카테고리의 다른 글
6. Temporal Fusion Transformers (0) 2021.12.30 5. TabNet (0) 2021.12.28 4. CNN과 Computer Vision (0) 2021.11.14 2. Neural Network 기초-1 ( 데이터 정의 및 활성함수) (0) 2021.09.12 1. Attention A to N까지(feat. Transformer) (0) 2021.07.04