본문 바로가기

학습공간/빅데이터활용실무

[10주차] Autoencoders

반응형

 Autoencoders (Unsupervised Learning)

비 지도학습(unsupervised learning) 측면에서는 오토인코더(auto-encoders) 개념을 빼놓을 수 없다. 딥 러닝에서 뉴럴 넷을 통해 차원이 축소(compression) 되고, 다시 복원(reconstruction) 시키는 형태이다. 사실, 히든 레이어를 많이 쌓으면 복원에 대해서는 문제가 없겠지만, 히든 레이어의 히든 유닛 수를 줄이는 차원 축소에 그 의의가 있다. Reconstruction-Compression Trade-off 관계와 축소된 벡터를 어떤 식으로 활용할 수 있는지에 대해 공부하도록 한다.

 

• 입력 복사를 위한 FNN 의 특별한 경우이다. (simply, 𝒚 = 𝒙)

Two main parts: \(\hat{𝒙}\)=𝑔(𝑓(𝒙;𝝓);𝜽)

  (1) an encoder function 𝒉=𝑓(𝒙;𝝓) maps the input to a (compressed) hidden representation

  (2) a decoder function \(\hat{𝒙}\)=𝑔(𝒉;𝜽) that produces a reconstruction from the hidden representation

• Neural Network for Unsupervised Learning (Autoencoder)
- 기본적으로 Feed-forward Neural Networks 으로 구현되어 있다.
- 입력 값 𝒙 에 대하여 예측 값을 𝒚 가 아닌, 자기 자신(입력 값 𝒙)으로 복원되도록 구현되어 있다. (FNN 과의 차별성)
  -. 히든 레이어에서 차원이 축소 되었다가 다시 복원되는 형태로, 복원에 의의가 있는 것은 아니다. (차원 축소)
- 그림과 같이, Encode \(𝑓_𝝓\)(Input to Hidden) 부분Decode \(𝑔_𝜽\)(Hidden to Output) 부분으로 나뉘어져 있다.
Feed-forward Neural Networks

• Autoencoders: Main Operations:
- Given a training dataset \(𝐷=\{𝒙_1,𝒙_2,…,𝒙_𝑛\}\) such that \(𝒙_𝑖=(𝑥_{𝑖1},…,𝑥_{𝑖𝑑})\) is the 𝑖-th input vector of the 𝑑 input variables.
- The model: \(\hat{𝒙}\)=𝑔(𝑓(𝒙;𝝓);𝜽) ⋯ 예측 모델 (to attempt to copy its input to its output)
- The cost function (to be minimized)
  : reconstruction loss \(𝐿(𝒙, \hat{𝒙})\)
  \[ 𝐽(𝜽,𝝓) = \frac{1}{𝑛} \sum_{𝒙_𝑖 ∈ 𝐷} {𝐿(𝒙_𝑖, \hat{𝒙}_𝑖)} \]
  -. loss function when \(𝒙_𝑖\) ∈ ℝ\({}^𝑑\)?
  -. loss function when \(𝒙_𝑖\) ∈ {0,1}\({}^𝑑\)?
- For training, any gradient-based optimization algorithms can be used.

 

 Applications of Autoencoders : 오토인코더 활용

오토인코더를 활용한 세 가지 변형된 형태와 몇 가지 응용 사례를 살펴보도록 한다.

① Sparse Autoencoders ⋯ 유닛 개수를 줄이지 않고, 일부 유닛만 Active 되도록 함 (dropout 유사함)
    : Constrain the hidden representation of Autoencoder to have sparsity
    - Add "sparsity penalty" to the cost function.
    - Sparse autoencoder may include more hidden units, but only a small number of the hidden units are allowed to be active at once.

Main Operations:
- Given a training dataset \(𝐷=\{𝒙_1,𝒙_2,…,𝒙_𝑛\}\) such that \(𝒙_𝑖=(𝑥_{𝑖1},…,𝑥_{𝑖𝑑})\) is the 𝑖-th input vector of the 𝑑 input variables.
- The model: \(\hat{𝒙}\)=𝑔(𝑓(𝒙;𝝓);𝜽)
- The cost function (to be minimized)
  : reconstruction loss \(𝐿(𝒙, \hat{𝒙})\) with a sparsity penalty Ω(𝒉)=Ω(𝑓(𝒙;𝝓))
  \[ 𝐽(𝜽,𝝓) = \frac{1}{𝑛} \sum_{𝒙_𝑖 ∈ 𝐷} {𝐿(𝒙_𝑖, \hat{𝒙}_𝑖)} {\color{Red}+𝜆Ω(𝒉_𝑖)} \]
  -. e.g., L1 regularization as the sparsity penalty Ω(𝒉)=||𝒉||₁
    → Some elements of 𝒉 have an optimal value of zero
  -. what is the difference with the standard L1 regularization?
- For training, any gradient-based optimization algorithms can be used.
⇒ 목적 함수에 L1 Regularization 하나 추가한 부분만 달라지고 모두 동일하다.

② Denoising Autoencoders ⋯ 노이즈가 섞인 입력 값(corruption input \(\tilde{x}\))으로 학습함
    : Train Autoencoder with corrupted inputs to improve robustness to small input perturbations
    - During training, the input 𝒙 is randomly corrupted by some form of noise, but the model is forced to reconstruct the original input 𝒙
    - Examples of the corrupted input \(\tilde{𝒙}\)
      -. some elements of \(\tilde{𝒙}\) are set to zero
      -. \(\tilde{𝒙}\)=𝒙+𝝐, 𝝐 is random noise

Main Operations:
- Given a training dataset \(𝐷=\{𝒙_1,𝒙_2,…,𝒙_𝑛\}\) such that \(𝒙_𝑖=(𝑥_{𝑖1},…,𝑥_{𝑖𝑑})\) is the 𝑖-th input vector of the 𝑑 input variables.
- The model: \(\hat{𝒙}\)=𝑔(𝑓(\(\tilde{𝒙}\);𝝓);𝜽)
- The cost function (to be minimized)
  : reconstruction loss \(𝐿(𝒙, \hat{𝒙})\)
  \[ 𝐽(𝜽,𝝓) = \frac{1}{𝑛} \sum_{𝒙_𝑖 ∈ 𝐷} {𝐿(𝒙_𝑖, \hat{𝒙}_𝑖)} \]
- For training, any gradient-based optimization algorithms can be used.
⇒ 노이즈 입력 값으로 학습하지만, 목적은 실제 입력이 되도록 한다.

③ Deep Autoencoders ⋯ auto-encoder 개수를 deep 하게 쌓는다.
    : Better compress the hidden representation (fewer hidden units)
    - Empirically performs better (improved trade-off between reconstruction and compression)
⇒ 경험적으로 여러 개를 적층 시 성능이 높게 나오는 경향이 있다.

※ Convolutional/Recurrent Autoencoder ⋯ 이미지나 시리얼을 벡터 형태로 바꾸고 싶을 때 사용
   : FNN 이 아닌, CNN 및 RNN 구조를 Encoder/Decoder 형태로 응용할 수도 있다.
  - Convolutional Autoencoder
Encoder: Convolutional NN, Decoder: Deconvolutional NN

  - Recurrent Autoencoder
Encoder: many-to-one (Bidirectional) RNN, Decoder: one-to-many RNN (with teacher forcing)

• Dimensionality Reduction: Autoencoder for non-linear dimensionality reduction
  : 차원 축소를 통해 가시화(Visualization) 가능하도록 2~3차원으로 축소
  - Use the "encoder" output 𝑓(𝒙;𝝓) - 인코더 부분을 사용
  - Reduce the dimensionality down to two (or three) so that we can plot a high-dimensional data on a scatterplot
  - Machine learning in the reduced space

784 차원을 2 차원으로 축소

784 차원을 3 차원으로 축소

• One-class classification / Anomaly Detection: Autoencoder as "one-class classifier"
  : 단일 데이터로만 학습하고, 새로운 데이터가 기존 데이터와 거리가 멀면 Anomaly Detection 하다고 판단한다.
  - Classification with only a single class of interest called a target class (unsupervised learning)
  - "One-class classifier" defines a decision boundary that describes the target class structure
Autoencoder (one-class classifier)

• Unsupervised Pretraining: Greedy Layer-Wise Unsupervised Pretraining
  : DNN 학습이 어려웠던 시절, random initialization 대신 오토인코더를 1 단계씩 학습시켜서 사용했었다.
  - An efficient initialization method to train a deep neural network, but not being used today …
  - Starting from the first hidden layer, train each hidden layer to reconstruct the input (unsupervised learning)
  - Then, fine tune the entire network (supervised learning)


• Denoising: Denoising autoencoder reduces noise in the input
  : 노이즈로 학습했기 때문에 노이즈를 제거해 원본에 가깝게 만듦, 앞의 ② Denoising Autoencoders 참조


반응형