본문 바로가기

데이터 다루기/머신러닝 이론

하이퍼 파라미터 튜닝 (1)

728x90
반응형

논문 : Yu, T., & Zhu, H. (2020). Hyper-parameter optimization: A review of algorithms and applications. arXiv preprint arXiv:2003.05689.

1. Contribution

- Hyper-parameters are systematically categorized into structure-related and training-related. The discussion of their importance and empirical strategies are helpful to determine which hyper-parameters are involved in HPO.

- HPO algorithms are analyzed and compared in detail, according to their accuracy, efficiency and scope of application. The analysis on previous studies is not only committed to include state-of-the-art algorithms, but also to clarify limitations on certain scenarios.

- By comparing HPO toolkits, this study gives insights of the design of close-sourced libraries and open-sourced services, and clarifies the targeted users for each of them.

- The potential research direction regarding to existing problems are suggested on algorithms, applications and techniques.

2. Major Hyper-Parameters and Search Space

위 논문에서 얘기하는 바로, 하이퍼 파라미터는 크게 두 종류로 정의될 수 있다.

하나는 Training-related parameter로 모델 학습 과정에 관련된 하이퍼파라미터이다.

본 섹션에서 소개될 대표적인 예로, LR (learning rate)와 Optimizer 가 존재한다.

두 번째는 structure-related parameter로 모델의 구조에 관련된 하이퍼파라미터이다.

본 섹션에서 소개될 대표적인 예로, 히든 레이어의 개수, 각 레이어에 사용되는 뉴런의 개수 등이 존재한다.

(1) Training-related parameter

(A) LR

논문에 제시되는 그림 4는 하이퍼파라미터로서 LR의 중요성을 한 눈에 보여준다.

너무 작은 LR은 Loss의 최적화에 큰 도움을 주지 못하며, 너무 큰 LR은 Loss의 변화가 매우 커서, 수렴에 어려움을 만든다. 이 처럼 적절한 LR을 찾는 것이 중요하지만, 데이터의 특성에 따라 최적의 LR이 다르다는 것이 중요한 문제이다.

Deep learning 모델에서는 최적의 LR을 유동적으로 찾기 위해서, 여러가지 technique을 사용한다.

가장 대표적인 방법으로, 모델의 학습 Process 도중에 LR을 바꿔주는 것이다.

그림 1이 이에 대한 예시이다.

위 식처럼 t (학습 Process) 가 진행됨에 따라 LR을 줄여 줄 수 있다.

또한 위 식처럼 특정 iteration을 주기로 점차 LR을 줄일 수 있다.

가장 효과적이라고 알려져 있는 방법은 exponential learning decay 라고 할 수 있다.

하지만, 위 식에서 알 수 있다시피 이러한 방법에 또한 하이퍼파라미터 (floor, epchsdrop)이 존재한다.

이처럼 초기의 하이퍼 파라미터 세팅은 모델의 성능을 결정하는 데 매우 중요한 역할을 할 수 밖에 없다.

위 논문은 LR에 대한 하이퍼파라미터 튜닝의 general rule을 다음과 같이 요약한다.

- In practice, it is difficult to decide the importance of a hyper-parameter if one has no experience of it. A sensitivity test is suggested (Hamby, 1994; Breierova and Choudhari, 1996) to ensure the influence of a certain hyper-parameter.

- Initial values of hyper-parameters are influential and must be carefully determined. The initial LR could be a comparatively large value because it will decay during training. In the early stage of training, a large LR will lead to fast convergence with fewer risks (Figure 4)

- Use log scale to update the LR. Thus, exponential decay could be a better choice. An exponential schedule could be applicable for many other tuning hyper-parameters, such as momentum and weight decay.

- Try more schedules. Exponential decay is not always the best choice; it depends on the model and dataset.

(B) Optimizer

Optimizer는 모델의 정확도와, 학습 속도에 매우 밀접하게 관련된 하이퍼파라미터이다.

현재 시점에서 굉장히 다양한 Optimizer가 연구된 상태이지만, 위 논문에서는 유명한 Optimizer로서 mini-batch gradient descent, RMSprop, Adam) 정도만 리뷰하였다.

Mini-batch gradient descent 방법은 초기의 SGD (mini-batch = 1)에 비해서 노이즈를 감소시키고, 수렴의 확률을 높일 수 있다는 장점이 있다. 이 때, mini-batch 또한 매우 중요한 하이퍼파라미터라고 할 수 있으며, CPU/GPU 연산에 따라 2의 제곱 수로 결정하는 것이 가장 효율적이다.

여러 선행 연구를 통해, mini-batch = 32 가 가장 안정적인 default 값이라고 한다.

하지만 최근 연구에서는 Mini-batch gradient descent 방법 보다 momentum을 추가한 SGD가 자주 사용되고 있다.

사실상 이 방법은 매우 기초적인 내용이라, 본 포스팅에서 다루지는 않도록 하겠습니다.

자세히 알고 싶으신 분들은 아래의 포스팅에서 확인 가능합니다.

 

https://blog.naver.com/ollehw/221517456116

더 나아가, RMSProp 이나 Adam은 더 복잡한 Optimizer 방법으로, 효율성을 더욱 향상시켰다.

이러한 Optimizer 안에서도 다양한 하이퍼파라미터가 존재한다.

(2) Structure-related parameter

(A) The number of hidden layers (d)

히든 레이어 개수는 모델의 전반적인 구조를 결정하는데 가장 중요한 하이퍼파라미터입니다. 딥러닝 네트워크들은 히든 레이어의 개수가 많아 질수록 대체로, 높은 훈련 정확도와 복잡한 피처를 추출할 수 있습니다.

하지만 그에 따라, 오버 피팅으로 인한 리스크도 존재합니다.

따라서 적절한 히든 레이거 개수를 찾는 것은 매우 중요한 테스크라고 할 수 있습니다. 예를 들어서, 분석가들은 데이터의 특성에 따라 ResNet-18 과 ResNet-200 중에서 선택해야 합니다.

(B) The number of neurons in each layer (w)

각 레이어마다 뉴런의 개수를 선택하는 것 또한 매우 중요합니다. 너무 적은 뉴런은 언더피팅 문제를 유발하며, 너무 많은 뉴런은 오버피팅 문제를 유발합니다.

(C) Regularization term

Regularization term은 모델의 과적합을 막는 가장 좋은 방법 중 하나입니다.

크게 두 가지 방법이 존재합니다.

두 방법 모두 각자의 장점과 단점을 가지고 있습니다. 데이터 혹은 목적 함수의 특징에 따라 적절한 방법과 함께 결정해야 할 하이퍼파라미터를 고려할 필요가 있습니다.

Loss function을 변경하는 방법 외에도, 데이터 증강이나 dropout layer를 추가하는 방법 또한 있습니다.

(D) Activation function

레이어의 활성화 함수는 아웃풋의 형태를 결정하는 중요한 하이퍼파라미터입니다.

자주 사용되는 활성화 함수는 tanh, ReLU, sigmoid 등이 있습니다.

반응형