Stoppers
Early stoppers.
The following code will create a scenario in which training will stop
(quite) early when training pykeen.models.TransE
on the
pykeen.datasets.Nations
dataset.
>>> from pykeen.pipeline import pipeline
>>> pipeline_result = pipeline(
... dataset='nations',
... model='transe',
... model_kwargs=dict(embedding_dim=20, scoring_fct_norm=1),
... optimizer='SGD',
... optimizer_kwargs=dict(lr=0.01),
... loss='marginranking',
... loss_kwargs=dict(margin=1),
... training_loop='slcwa',
... training_kwargs=dict(num_epochs=100, batch_size=128),
... negative_sampler='basic',
... negative_sampler_kwargs=dict(num_negs_per_pos=1),
... evaluator_kwargs=dict(filtered=True),
... evaluation_kwargs=dict(batch_size=128),
... stopper='early',
... stopper_kwargs=dict(frequency=5, patience=2, relative_delta=0.002),
... )
- class NopStopper(*args, **kwargs)[source]
A stopper that does nothing.
- class EarlyStopper(model, evaluator, training_triples_factory, evaluation_triples_factory, evaluation_batch_size=None, evaluation_slice_size=None, frequency=10, patience=2, metric='hits_at_k', relative_delta=0.01, results=<factory>, larger_is_better=True, result_tracker=None, result_callbacks=<factory>, continue_callbacks=<factory>, stopped_callbacks=<factory>, stopped=False)[source]
A harness for early stopping.
- continue_callbacks: List[Callable[[pykeen.stoppers.stopper.Stopper, Union[int, float], int], None]]
Callbacks when training gets continued
- evaluation_triples_factory: pykeen.triples.triples_factory.CoreTriplesFactory
The triples to use for evaluation
- evaluator: pykeen.evaluation.evaluator.Evaluator
The evaluator
- model: pykeen.models.base.Model
The model
- patience: int = 2
The number of iterations (one iteration can correspond to various epochs) with no improvement after which training will be stopped.
- relative_delta: float = 0.01
The minimum relative improvement necessary to consider it an improved result
- result_callbacks: List[Callable[[pykeen.stoppers.stopper.Stopper, Union[int, float], int], None]]
Callbacks when after results are calculated
- result_tracker: Optional[pykeen.trackers.base.ResultTracker] = None
The result tracker
- should_evaluate(epoch)[source]
Decide if evaluation should be done based on the current epoch and the internal frequency.
- Return type
- should_stop(epoch, *, mode=None)[source]
Evaluate on a metric and compare to past evaluations to decide if training should stop.
- Return type
- stopped_callbacks: List[Callable[[pykeen.stoppers.stopper.Stopper, Union[int, float], int], None]]
Callbacks when training is stopped early
- training_triples_factory: pykeen.triples.triples_factory.CoreTriplesFactory
The triples to use for training (to be used during filtered evaluation)
Base Classes
- class Stopper(*args, **kwargs)[source]
A harness for stopping training.
- static load_summary_dict_from_training_loop_checkpoint(path)[source]
Load the summary dict from a training loop checkpoint.