🤖 AI/ML

Hyperparameter

Hyperparameter

A parameter set before training, such as learning rate and batch size. Optimized through tuning.

📖 Detailed Explanation

A hyperparameter is a value that a person must set directly before a model begins training. Typical examples include the learning rate, batch size, number of epochs, and dropout rate. It is distinguished from parameters, such as a model's weights, which are updated automatically during the training process.

The concept of hyperparameters has existed since the early days of machine learning, but its importance has come to the fore with the advancement of deep learning. In large-scale models such as GPT and BERT in particular, dozens of hyperparameters directly affect performance.

Hyperparameter tuning is performed using methods such as Grid Search (exhaustive search of all combinations), Random Search (random search), and Bayesian Optimization. Recently, AutoML tools such as Optuna and Ray Tune support automatic search.

In practice, a learning rate between 0.001 and 0.1 and a batch size between 8 and 32 are common starting points. For LLM fine-tuning, a learning rate multiplier in the range of 0.02 to 0.2 is recommended, and the larger the batch size, the higher the learning rate should also be raised.

💻 Code Example

import optuna
from sklearn.ensemble import RandomForestClassifier
from sklearn.model_selection import cross_val_score
from sklearn.datasets import load_iris

# Optuna를 활용한 하이퍼파라미터 자동 튜닝
def objective(trial):
    # 탐색할 하이퍼파라미터 정의
    n_estimators = trial.suggest_int('n_estimators', 10, 200)
    max_depth = trial.suggest_int('max_depth', 2, 32)
    min_samples_split = trial.suggest_float('min_samples_split', 0.1, 1.0)

    # 모델 생성 및 학습
    clf = RandomForestClassifier(
        n_estimators=n_estimators,
        max_depth=max_depth,
        min_samples_split=min_samples_split,
        random_state=42
    )

    # 교차 검증으로 성능 평가
    X, y = load_iris(return_X_y=True)
    score = cross_val_score(clf, X, y, cv=5).mean()
    return score

# 100회 시도로 최적 하이퍼파라미터 탐색
study = optuna.create_study(direction='maximize')
study.optimize(objective, n_trials=100)

print(f"최적 하이퍼파라미터: {study.best_params}")
print(f"최고 정확도: {study.best_value:.4f}")

🗣️ Say It Like This in Practice

💬 In a Meeting
"I started with a learning rate of 0.001, but convergence was too slow, so I raised it to 0.01, and it converged 3 times faster. I set the batch size to 32, taking GPU memory into account."
💬 In an Interview
"A hyperparameter is a value that a person sets before training, and a parameter is a value that the model updates by itself during training. If you apply Bayesian Optimization with Optuna, you can find the optimal values more efficiently than with Grid Search."
💬 In a Technical Discussion
"If you increase the batch size, training speed goes up, but generalization performance may drop. It's a good idea to apply a Learning Rate Warmup or Cosine Annealing scheduler together with it."

Take a mock interview on this topic → WIA SOOM AI Interview · Start for free

⚠️ Common Mistakes & Cautions

❌
The misconception that raising only the learning rate makes training converge quickly

If the learning rate is too high, training diverges or jumps over local minima and misses the optimal point. Always monitor the loss graph.

❌
Setting the batch size as large as possible without exception

If the batch size is too large, gradient noise decreases and generalization performance degrades. For GPU optimization, multiples of 8 (8, 16, 32) are recommended.

✅
Use a Learning Rate Scheduler

Apply Cosine Annealing or Step Decay, which converges quickly with a large learning rate at the beginning and then reduces it in the later stage for fine-tuned adjustment.

🔗 Related Terms

📚 Learn More