matchzoo.auto.tuner.tuner

Module Contents

class matchzoo.auto.tuner.tuner.Tuner(params:'mz.ParamTable', optimizer:str='adam', trainloader:mz.dataloader.DataLoader=None, validloader:mz.dataloader.DataLoader=None, embedding:np.ndarray=None, fit_kwargs:dict=None, metric:typing.Union[str, BaseMetric]=None, mode:str='maximize', num_runs:int=10, verbose=1)

Bases: object

Model hyper-parameters tuner.

model.params.hyper_space reprensents the model’s hyper-parameters search space, which is the cross-product of individual hyper parameter’s hyper space. When a Tuner builds a model, for each hyper parameter in model.params, if the hyper-parameter has a hyper-space, then a sample will be taken in the space. However, if the hyper-parameter does not have a hyper-space, then the default value of the hyper-parameter will be used.

See tutorials/model_tuning.ipynb for a detailed walkthrough on usage.

Parameters:
  • params – A completed parameter table to tune. Usually model.params of the desired model to tune. params.completed() should be True.
  • optimizer – Str or Optimizer class. Optimizer for optimizing model.
  • trainloader – Training data to use. Should be a DataLoader.
  • validloader – Testing data to use. Should be a DataLoader.
  • embedding – Embedding used by model.
  • fit_kwargs – Extra keyword arguments to pass to fit. (default: dict(epochs=10, verbose=0))
  • metric – Metric to tune upon. Must be one of the metrics in model.params[‘task’].metrics. (default: the first metric in params.[‘task’].metrics.
  • mode – Either maximize the metric or minimize the metric. (default: ‘maximize’)
  • num_runs – Number of runs. Each run takes a sample in params.hyper_space and build a model based on the sample. (default: 10)
  • verbose – Verbosity. (default: 1)
params

params getter.

trainloader

trainloader getter.

validloader

validloader getter.

fit_kwargs

fit_kwargs getter.

metric

metric getter.

mode

mode getter.

num_runs

num_runs getter.

verbose

verbose getter.

tune(self)

Start tuning.

Notice that tune does not affect the tuner’s inner state, so each new call to tune starts fresh. In other words, hyperspaces are suggestive only within the same tune call.

_fmin(self, trials)
_run(self, sample)
_create_full_params(self, sample)
_fix_loss_sign(self, loss)
classmethod _log_result(cls, result)
classmethod _validate_params(cls, params)
classmethod _validate_optimizer(cls, optimizer)
classmethod _validate_dataloader(cls, data)
classmethod _validate_kwargs(cls, kwargs)
classmethod _validate_mode(cls, mode)
classmethod _validate_metric(cls, params, metric)
classmethod _validate_num_runs(cls, num_runs)