hyperparameter_hunter.library_helpers package

Submodules

hyperparameter_hunter.library_helpers.keras_helper module

This module defines utilities for assisting in processing Keras Experiments

hyperparameter_hunter.library_helpers.keras_helper.keras_callback_to_key(callback)
Convert a Keras callback instance to a string that identifies it, along with the parameters

used to create it

Parameters
callback: Child instance of `keras.callbacks.Callback`

A Keras callback for which a key string describing it will be created

Returns
callback_key: String

A string identifying and describing callback

hyperparameter_hunter.library_helpers.keras_helper.keras_callback_to_dict(callback)

Convert a Keras callback instance to a dict that identifies it, along with the parameters used to create it

Parameters
callback: Child instance of `keras.callbacks.Callback`

A Keras callback for which a dict describing it will be created

Returns
callback_dict: Dict

A dict identifying and describing callback

hyperparameter_hunter.library_helpers.keras_helper.reinitialize_callbacks(callbacks)

Ensures the contents of callbacks are valid Keras callbacks

Parameters
callbacks: List

Expected to contain Keras callbacks, or dicts describing callbacks

Returns
callbacks: List

A validated list of Keras callbacks

hyperparameter_hunter.library_helpers.keras_helper.keras_initializer_to_dict(initializer)
hyperparameter_hunter.library_helpers.keras_helper.get_concise_params_dict(params, split_args=False)
hyperparameter_hunter.library_helpers.keras_helper.parameters_by_signature(instance, signature_filter=None)

Get a dict of the parameters used to create an instance of a class. This is only suited for classes whose attributes are named according to their input parameters

Parameters
instance: Class instance

Instance of a class that has attributes named for the class’s input parameters

signature_filter: Callable, or None, default=None

If not None, should be callable that expects as input (<arg_name>, <arg_val>), which are signature parameter names, and values, respectively. The callable should return a boolean: True if the pair should be added to params, or False if it should be ignored. If signature_filter is None, all signature parameters will be added to params

Returns
params: Dict

Mapping of input parameters in class’s __init__ signature to instance attribute values

hyperparameter_hunter.library_helpers.keras_helper.get_keras_attr(model, attr, max_depth=3, default=<object object at 0x7fe863a905d0>)

Retrieve specific Keras model attributes safely across different versions of Keras

Parameters
model: Instance of :class:`keras.wrappers.scikit_learn.<KerasClassifier; KerasRegressor>`

A compiled instance of a Keras model, made using the Keras wrappers.scikit_learn module

attr: String

Name of the attribute to retrieve from model

max_depth: Integer, default=3

Maximum number of times to check the “model” attribute of model for the target attr if attr itself is not in model before returning default or raising AttributeError

default: Object, default=object()

If given, default will be returned once max_depth attempts have been made to find attr in model. If not given and total attempts exceed max_depth, AttributeError is raised

Returns
Object

Value of attr for model (or a nested model if necessary), or None

hyperparameter_hunter.library_helpers.keras_helper.parameterize_compiled_keras_model(model)

Traverse a compiled Keras model to gather critical information about the layers used to construct its architecture, and the parameters used to compile it

Parameters
model: Instance of :class:`keras.wrappers.scikit_learn.<KerasClassifier; KerasRegressor>`

A compiled instance of a Keras model, made using the Keras wrappers.scikit_learn module. This must be a completely valid Keras model, which means that it often must be the result of library_helpers.keras_optimization_helper.initialize_dummy_model(). Using the resulting dummy model ensures the model will pass Keras checks that would otherwise reject instances of space.Space descendants used to provide hyperparameter choices

Returns
layers: List

A list containing a dict for each layer found in the architecture of model. A layer dict should contain the following keys: [‘class_name’, ‘__hh_default_args’, ‘__hh_default_kwargs’, ‘__hh_used_args’, ‘__hh_used_kwargs’]

compile_params: Dict

The parameters used on the call to model.compile(). If a value for a certain parameter was not explicitly provided, its default value will be included in compile_params

hyperparameter_hunter.library_helpers.keras_optimization_helper module

This module performs additional processing necessary when optimizing hyperparameters in the Keras library. Its purpose is twofold: 1) to enable the construction of Keras models while requiring minimal syntactic changes on the user’s end when defining hyperparameter space choices; and 2) to enable thorough collection of all hyperparameters used to define a Keras model - not only those being optimized - in order to ensure the continued usefulness of an Experiment’s result files even under different hyperparameter search constraints

Module contents