toad.nn.trainer module

class toad.nn.trainer.History[source]

Bases: object

model history

__init__()[source]

Initialize self. See help(type(self)) for accurate signature.

log(key, value)[source]

log message to history

Parameters:
  • key (str) – name of message
  • value (Tensor) – tensor of values
class toad.nn.trainer.callback(*args, is_class=False, **kwargs)[source]

Bases: toad.utils.decorator.Decorator

Examples

>>> @callback
... def savemodel(model):
...     model.save("path_to_file")
...
... trainer.train(model, callback = savemodel)
class toad.nn.trainer.earlystopping(*args, delta=-0.001, patience=10, skip=0, **kwargs)[source]

Bases: toad.utils.decorator.Decorator

Examples

>>> @earlystopping(delta = 1e-3, patience = 5)
... def auc(history):
...     return AUC(history['y_hat'], history['y'])
__init__(*args, delta=-0.001, patience=10, skip=0, **kwargs)[source]
Parameters:
  • delta (float) – stop training if diff of new score is smaller than delta
  • patience (int) – patience of rounds to stop training
  • skip (int) – n rounds from starting training to warm up
get_best_state()[source]

get best state of model

reset()[source]