liveBook · Manning

Search space

As explained in Deep Learning with Python, Third Edition

The set of all hyperparameter choices that a tuning process is allowed to consider for a model.

A search space defines which hyperparameter values a tuning process may try. It replaces fixed settings such as units=32 with configurable ranges or choices. section 18.1.1

A small Keras search space

A model builder can vary Dense-layer width from 16 to 64 in steps of 16 and choose between rmsprop and adam. A tuner samples these settings, trains each resulting model, and records its metrics. section 18.1.1

Practical rules:

  • Define the space inside a model-building function or a HyperModel build method. section 18.1.1
  • Use hp.Int for numeric ranges and hp.Choice for discrete alternatives, then inspect them with search_space_summary(). section 18.1.1
Listing 18.1 A KerasTuner model-building function
import keras
from keras import layers

def build_model(hp):
    units = hp.Int(name="units", min_value=16, max_value=64, step=16) #1
    model = keras.Sequential(
        [
            layers.Dense(units, activation="relu"),
            layers.Dense(10, activation="softmax"),
        ]
    )
    optimizer = hp.Choice(name="optimizer", values=["rmsprop", "adam"])#2
    model.compile(
        optimizer=optimizer,
        loss="sparse_categorical_crossentropy",
        metrics=["accuracy"],
    )
    return model                                                       #3

Shows a complete model-building function with integer and categorical hyperparameters. section 18.1.1

How Deep Learning with Python, Third Edition covers it

How deep it goes
Defines spaces with hp.Int and hp.Choice, shows summaries and tuner integration, but does not explain search algorithms internally.
Examples
Uses Dense-layer units from 16–64 and optimizer choices between rmsprop and adam in a Keras model.
What you can do after
Apply it via KerasTuner by defining hp.Int or hp.Choice parameters and passing the model builder to a tuner.
How it connects
Links hyperparameter tuning to model-building functions, HyperModel, tuners, objectives, and validation data.

Also explained in

Compare how 11 books explain search space →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Deep Learning with Python, Third Edition. The section links point to the parts of the book it draws on.