Model Debugging - Hyperparameter 하이퍼파라미터 값 조정

Learning Rate, Regularization, Training epochs, Batch size, Depth, width 하이퍼파라미터 값 설정, 조정 가이드라인을 정리합니다.

Guide for adjusting Hyperparameter values
  • Learning Rate
  • Regularization
  • Training epochs
  • Batch size
  • Depth and width of layers (Model Capacity)

1. Learning Rate

  • 일반적으로 ML 라이브러리 initial learning rate 초기 학습률을 자동설정하고, 학습률을 조정하면서 훈련한다.
    • TF Estimators : AdagradOptimizer : 0.05, AdamOptimizer : 0.001
  • 만약 모델이 초기 학습률로 수렴하지 않는다면, 직접 수정해야한다. [0.0001,1.0] 사이 값을 수동으로 선택하고 모델이 수렴할 때까지 증가/감소 시켜야한다 (on a logarithmic scale)
  • the more difficult your problem, the more epochs your model must train for before loss starts to decrease. 어려운 problem일수록 loss가 감소하기 시작하기 전까지 더 많은 epoch를 훈련해야한다.
  • 손실 감소 속도가 느린경우, Learning rate을 높여 훈련을 이전보다 빠르게 만들 수 있다.

2. Regularization

정규화 없이도 모델이 예측할 수 있는 지 확인한 후, 과적합 문제가 확인되는 경우에만 Regularization 정규화한다.

선형 모델과 비선형 모델은 정규화 방법이 다르다.

  • linear model 선형모델 정규화

    • 모델의 size 크기를 줄이기 위해 : L1 regularization
    • 모델의 stability 안정성을 높이기 위해 : L2 regularization (model's stability makes your model training more reproducible)
    • regularization rate $λ$ starting from 1e-5 적절한 값을 찾는다.
  • Deep neural network model 정규화 : Dropout regularization
    고정된 비율의 뉴런 랜덤으로 삭제 removes a random selection of a fixed percentage of the neurons in a network layer for a single gradient step.

    • Dropout rate : between 10% and 50%

3. Training epochs

Epoch : How many times you run the optimization over the training data

  • should train for at least one epoch 적어도 한번의 에포크는 훈련해야한다.
  • continue to train so long as you are not overfitting.

4. Batch size

  • 일반적으로 사용하는 배치 크기 : < mini-batch : 10 ~ 1000> , < SGD : 1 >
  • upper/lower bound on the batch size
    • upper : 상한값 시스템 메모리에 들어갈 수 있는 데이터 양에 의해 제한된다.
    • lower : 하한값은 데이터와 알고리즘에 따라 달라진다.
  • Prefer using the smallest batch sizes that result in stable training
    더 작은 배치 크기로 훈련된 모델은 에포크당 graident update가 자주 발생해 손실이 더 많이 감소할 수 있고, 더 잘 일반화된다 (On large-batch training for deep learning: Generalization gap and sharp minima )

5. Depth and width of layers

  • model capacity : depth = # of layers , width = # of neurons per layer
  • 문제의 복잡도complexity가 높아지면, depth & width도 증가시킨다.

신경망 모델의 depth와 width 설정에 있어 다음과 같은 방식으로 접근하는 것이 좋다.

  1. 1 FC hidden layer with the same width as the input layer.
  2. Set Output layer
    • Regression : output layer's width to 1.
    • Classification : output layer's width to # of classes.
  3. If model doesn't work
    • depth : increase depth linearly by adding a fully-connected hidden layer at a time.
    • width (hidden layer) : try same width as the previous hidden layer and then discover the appropriate width
  • The change in width of successive layers also depends on your problem. 관행 : 이전의 레이어의 width와 동일하거나 작게 설정

Quiz 💡

Hyperparameters for training a clissifier - Choose actions that could fix the problem described.

(1)

Training loss is 0.24 and validation loss is 0.36. Which two of the following actions could reduce the difference between training and validation loss?
Train loss is smaller than val loss : overfitting

  • ❌ A. Increase the number of training epochs.
    훈련 epoch를 늘리는 것은 모델이 더 과적합되게 만든다.
  • B. Ensure the training and validation sets have the same statistical properties.
    모델이 훈련된 데이터와 검증 데이터가 통계적 속성이 다른 경우, 검증 데이터에 대해 예측을 잘 못할 수 있다. (Data Debugging)
  • C. Use regularization to prevent overfitting.
  • ❌ D. Decrease the learning rate.
    학습률을 늘리는 것은 과적합 해소에 도움되지 않는다.
(2)

You perform the correct actions described in the previous question, and now your training and validation losses decrease from 1.0 to roughly 0.24 after training for many epochs. Which one of the following actions could reduce your training loss further?
training loss did not decrease for many training epochs

  • A. Increase the depth and width of your neural network.
    여러번의 epoch 후에도 training loss가 0.24로 유지된다면, 모델 예측력이 부족할 수도 있다. 모델의 depth, width를 늘리는 것은 예측력을 증가시키고 train loss를 더 줄이는 데 도움이 될 수 있다.
  • ❌ B. Increase the number of training epochs.
    (이미 많은 epoch 훈련 후) 동일한 모델로 epoch만 늘리는 것은 train loss 줄이는 데 큰 영향을 주지 못할 것이다.
  • ❌ C. Increasing the learning rate.
    train loss가 더이상 줄어들지 않는 상황에서 학습률을 높이는 것은 오히려 훈련과정을 unstable하게 만들어 모델 훈련에 도움이 되지 않을 수 있다.
(3)

You take the correct action in the previous question. Your model's training loss decreased to 0.20. Assume you need to reduce your model's training loss a little more. You add a few features that appear to have predictive power. However, training loss continues to fluctuate around 0.20. Which three of the following options could reduce your training loss?
예측력을 가질 것으로 보이는 피쳐를 추가한 후에 train loss가 0.2 주변에서 fluctuate하는 경우

  • ⭕ A. The features don't add information relative to existing features. Try a different feature.
    새로 추가한 피쳐가 이미 모델에 포함된 피쳐에 존재하는 predictive signals을 가지는 것일 수 있다.
  • ⭕ B. Decrease the learning rate.
    손실의 fluctuation 현상이 학습률이 너무 높아서 최적지점 주변에서 jumping하는 것으로 볼 수 있다.
  • ⭕ C. Increase the depth and width of your layers.
    새 피쳐를 추가하는 것은 problem의 복잡도를 높일 수 있고, 문제가 복잡해지면 모델의 width, depth를 늘리는 것이 도움이 될 수 있다. lack of the capacity to learn the predictive signals in the new feature
  • ❌ D. Increase the training epochs.
    훈련 epoch를 늘리는 것은 손실의 fluctuation 현상이 지속되게 만들 수 있다.

Source&Reference : Model Debugging