liveBook · Manning

Hyperparameter tuning

As explained in Transfer Learning for Natural Language Processing

The process of searching for hyperparameter values that improve a model's performance.

Hyperparameter tuning searches for settings that improve a model’s performance. Results from a single initial setting cannot establish an algorithm’s best attainable performance or reliably settle model rankings. section 3.3 section 3.4

Two practical approaches range from intuition-led experiments to systematic searches:

  • Manual tuning changes selected settings and evaluates the results. For email and movie-review classification, increasing the maximum tokens per document and maximum token length improved many models’ accuracy, while sometimes changing which model led. section 3.3.1
  • Systematic tuning specifies ranges for algorithm-specific settings. GridSearchCV exhaustively tests a parameter grid; HyperOpt performs a random search over parameter ranges. section 3.3.2

A random-forest grid search

For email classification, a GridSearchCV experiment tested three values each for three random-forest parameters: 27 combinations in total. It took less than five minutes and achieved 95.7% accuracy, improving by more than one percentage point over the initial 94.5%. section 3.3.2

Table 3.1 Comparison of algorithm accuracies at different general hyperparameter settings explored during the manual tuning process for the email classification example (view table figure)

General hyperparameter settings

LR

SVM

RF

GBM

ELMo

BERT

Nsamp = 1000 maxtokens = 50 maxtokenlen = 20

97.7%

70.2%

94.5%

94.2%

97.3%

98.3%

Nsamp = 1000 maxtokens = 100 maxtokenlen = 100

99.2%

72.3%

97.2%

97.3%

98.2%

98.8%

Nsamp = 1000, maxtokens = 200, maxtokenlen = 100

98.7%

90.0%

97.7%

97.2%

99.7%

98.8%

Compare email-classification accuracies across three general hyperparameter settings to see how tuning changes model performance. section 3.3.1

Table 3.2 Comparison of algorithm accuracies at different general hyperparameter settings explored during the manual tuning process for the IMDB movie review classification example (view table figure)

General hyperparameter settings

LR

SVM

RF

GBM

ELMo

BERT

Nsamp = 1000 maxtokens = 50 maxtokenlen = 20

69.1%

66.0%

63.9%

67.0%

69.7%

71.0%

Nsamp = 1000 maxtokens = 100 maxtokenlen = 100

74.3%

72.5%

70.0%

72.0%

75.2%

79.1%

Nsamp = 1000 maxtokens = 200 maxtokenlen = 100

79.0%

78.3%

67.2%

77.5%

77.7%

81.0%

Compare movie-review classification accuracies across three general hyperparameter settings. section 3.3.1

How Transfer Learning for Natural Language Processing covers it

How deep it goes
Walks through intuition-led changes and a 27-combination grid search, without exhaustively tuning every possible setting.
Examples
Compares email and IMDB classification while varying token limits and tuning random-forest parameters.
What you can do after
Apply hyperparameter search with GridSearchCV to evaluate a specified parameter grid and identify strong settings.
How it connects
Connects model selection with logistic regression, support vector machines, random forests, gradient boosting, and neural networks.

Also explained in

Compare how 19 books explain hyperparameter tuning →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Transfer Learning for Natural Language Processing. The section links point to the parts of the book it draws on.