Which hyperparameters of deep learning model are important and how to find them

This is another of my blog post based on the notes I have made while watching Andrew Ng’s deep learning course.

According to Andrew Ng, the critical hyperparameters (in the order of their importance) are:

  • learning rate

  • momentum (if you are using gradient descent with momentum), mini-batch size, and the number of hidden units in layers

  • the number of layers and learning rate decay

When we look at the list, we may notice that Andrew Ng thinks that the hyperparameter is more significant when it has a stronger influence on the weights produced during training.

Andrew Ng recommends to stop using grid search and replace it with a random search of hyperparameters. This advice is based on an observation that it is better to try a more diverse set of parameters than keep an important parameter (for example learning rate) unchanged for a while to tweak some less crucial parameters (like mini-batch size or the number of layers).

Coarse to fine hyperparameter search

This approach consists of two steps. First, we look for the best hyperparameters using random search. Later, we repeat the random search, but limit the range to values similar to the best hyperparameters from the previous step.

We do it because that allows us to quickly find hyperparameters which are good enough and later continue tweaking them.

Use log scale for searching hyperparameters

The final advice suggested by Andrew Ng is using a logarithmic scale when randomly choosing hyperparameters. We do it because when we generate uniformly distributed random numbers, we are more likely to get more diverse result.

For example, if we want values between 1 and 0.0001, we can randomly generate the exponent and use a constant base:

1
2
n = -4 * np.random.rand(4)
parameter = 10**n

Did you enjoy reading this article?
Would you like to learn more about software craft in data engineering and MLOps?

Subscribe to the newsletter or add this blog to your RSS reader (does anyone still use them?) to get a notification when I publish a new essay!

Newsletter

Do you enjoy reading my articles?
Subscribe to the newsletter if you don't want to miss the new content, business offers, and free training materials.

Bartosz Mikulski

Bartosz Mikulski

  • Data/MLOps engineer by day
  • DevRel/copywriter by night
  • Python and data engineering trainer
  • Conference speaker
  • Contributed a chapter to the book "97 Things Every Data Engineer Should Know"
  • Twitter: @mikulskibartosz
Newsletter

Do you enjoy reading my articles?
Subscribe to the newsletter if you don't want to miss the new content, business offers, and free training materials.