liveBook · Manning

Hyperparameter

As explained in Distributed Machine Learning Patterns

A configuration value chosen before or during model training that controls the model structure or training procedure rather than being learned directly from the data.

A hyperparameter is a configuration value selected for model structure or training rather than learned directly from data. It remains fixed during a training run and can directly affect model performance. Typical choices include neural-network layer counts, hidden units, learning rate, and tree maximum depth. section 5.4 section 8.1.1

Changing hyperparameters commonly requires a new training run. In an end-to-end workflow, rerunning unchanged data ingestion just to test a new configuration is time-consuming; step memoization addresses this by skipping redundant work while experiments vary model architecture or configuration. section 5.4

A practical tuning flow is:

  • Expose candidate values in the model-building function, such as 32–512 units in steps of 32 and a choice of learning rates. section 8.1.1
  • Run a tuner against validation accuracy; Hyperband uses adaptive resource allocation and early stopping to find a high-performing model faster. section 8.1.1
  • Retrieve the best configuration, build its model, train it further, and evaluate it on test data. section 8.1.1

Tuning an MNIST classifier

A Keras model exposes the first dense layer's unit count and Adam learning rate as hyperparameters. Hyperband searches these choices with validation data and an EarlyStopping callback, then the selected configuration is used to train and evaluate the final classifier. section 8.1.1

Listing 8.15 The model building function using TensorFlow and Keras Tuner
def model_builder(hp):
 model = keras.Sequential()
 model.add(keras.layers.Flatten(input_shape=(28, 28)))
 hp_units = hp.Int('units', min_value=32, max_value=512, step=32)
 model.add(keras.layers.Dense(units=hp_units, activation='relu'))
 model.add(keras.layers.Dense(10))
 hp_learning_rate = hp.Choice('learning_rate', values=[1e-2, 1e-3, 1e-4])
 model.compile(optimizer=keras.optimizers.Adam(learning_rate=hp_learning_rate),
               loss=keras.losses.SparseCategoricalCrossentropy(from_logits=True),
               metrics=['accuracy'])
 return model

The model-builder listing shows how named search-space values are inserted into a dense layer and Adam optimizer. section 8.1.1

How Distributed Machine Learning Patterns covers it

How deep it goes
Works through defining search spaces, Hyperband search, early stopping, selection, retraining, and evaluation without detailing tuner internals.
Examples
Uses MNIST digit classification with tunable dense-layer units and Adam learning rate, plus workflow experiments over architectures and configurations.
What it assumes
Assumes a TensorFlow Keras training workflow and introduces tuning from a single fixed configuration.
What you can do after
Apply it via Keras Tuner to search configurations, select the best values, train a model, and evaluate it.
How it connects
Connects hyperparameters to model architecture, model training, model serving, step memoization, Hyperband, and early stopping.

Also explained in

Compare how 19 books explain hyperparameter →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Distributed Machine Learning Patterns. The section links point to the parts of the book it draws on.