In what order should we tune hyperparameters in Neural Networks?
ML System Design practice on Codemia
Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.
Introduction
Tuning hyperparameters in neural networks is a critical step towards optimizing performance. While neural networks have transformed various domains due to their flexibility and robustness, their performance heavily relies on selecting the appropriate hyperparameters. This article examines the sequence in which hyperparameters should be adjusted and the pivotal role each one plays in the learning process.
Understanding Hyperparameters
In contrast to model parameters learned during training, hyperparameters are set before training begins. They influence the training process and architecture, thus impacting the network's final performance. However, the vast space of hyperparameters can make tuning an intricate task. The key to effective tuning lies in following a methodical approach, focusing on sensitivity and impact levels of different hyperparameters.
Tuning Order
1. Learning Rate
The learning rate is arguably the most critical hyperparameter to tune. It determines how much the model's weights will be updated during training. A learning rate that's too high can lead to divergence, while a too-low learning rate might result in slow convergence.
Advice: Start with a moderate learning rate and use a learning rate schedule or decay strategy. Adaptive methods like Adam inherently adjust learning rates and are often a good starting point.
2. Batch Size
The batch size affects the stability of the training process and memory utilization. Smaller batch sizes provide a regularizing effect and tend to generalize better but take longer to converge, while larger batch sizes speed up training but might lead to overfitting.
Advice: Experiment with various batch sizes, balancing between model accuracy and resource constraints.
3. Network Architecture
Hyperparameters that define the architecture include the number of layers and units per layer. Neural networks with more layers can capture more complex functions but at a cost of increased risk of overfitting and longer training times.
Advice: Use domain knowledge to determine initial architecture size. Fine-tune by gradually increasing or decreasing layers and units.
4. Activation Functions
Activation functions influence the model's ability to capture non-linear patterns. Commonly used functions include ReLU, Sigmoid, and Tanh.
Advice: Start with ReLU and consider alternatives if vanishing gradient problems or dead neurons are encountered.
5. Optimizers
Different optimizers (SGD, Adam, RMSProp, etc.) affect how the learning rate adapts during training. While SGD with momentum can be efficient, adaptive methods like Adam have become popular for their robustness in different contexts.
Advice: Begin with Adam due to its efficient handling of sparse gradients and adaptability.
6. Regularization `Parameters`
Regularization techniques help prevent overfitting by penalizing complexity. Popular methods include L2-regularization and dropout.
Advice: For L2-regularization, try values like 0.01 or 0.001. For dropout, start with a rate around 0.5 for dense layers and adjust based on performance.
7. Weight Initialization and Others
Good weight initialization can speed up convergence and stabilize training. Techniques such as Xavier/Glorot or He initialization are preferred over random initialization.
Advice: Choose initialization schemes that align with the activation functions used.
Summary Table
| Hyperparameter | Initial Choice | Tuning Strategy |
| Learning Rate | Moderate (e.g., 0.001 for Adam) | Use decay strategy or learning rate schedule |
| Batch Size | Moderate (e.g., 32 or 64) | Balance between resources and generalization |
| Network Architecture | Based on domain knowledge | Incrementally refine by adding/reducing layers or units |
| Activation Function | ReLU | Evaluate performance and switch if needed |
| Optimizer | Adam | Experiment with SGD + momentum if needed |
| Regularization | L2: 0.01-0.001, Dropout: 0.5 | Adjust to prevent overfitting based on model performance |
| Weight Initialization | Xavier/Glorot or He | Ensure compatibility with activation functions |
Additional Considerations
Hyperparameter Search Techniques
- Grid Search: Evaluates all combinations within specified ranges. Computationally expensive but exhaustive.
- Random Search: Samples hyperparameters randomly, often more efficient as explored by Bergstra and Bengio.
- Bayesian Optimization: Models the performance as a probabilistic function, iteratively focusing on promising regions.
Tools and Libraries
Automated tools like Hyperopt, Optuna, and Ray Tune can ease the hyperparameter tuning process by implementing sophisticated search strategies.
Final Words
Hyperparameter tuning remains a blend of art and science. Iterative adjustment, coupled with intuition and experimentation, often yields improved model performance. By following a structured approach and using modern tools, practitioners can efficiently navigate the vast hyperparameter space and achieve optimal configurations in their neural networks.
Related reading
- Inception-ResNet-v2 model consists of how many layers?
- Inconsistency between image resizing with Keras PIL and TensorFlow?
- Increase or decrease learning rate for adding neurons or weights?
- Index of a maximum element in TensorFlow tensor
- In which cases is the cross-entropy preferred over the mean squared error?
- Incorporating user feedback in a ML model
- In what order should you insert a set of known keys into a B-Tree to get minimal height?
- In which situations do we need to write the __autoreleasing ownership qualifier under ARC?

DSA Fundamentals
Master algorithmic patterns and data structures through hands-on LeetCode-style problems - from arrays and hashing to dynamic programming and advanced graphs.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
ML System Design practice on Codemia
Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.