本文整理汇总了Python中allennlp.training.trainer.Trainer._should_stop_early方法的典型用法代码示例。如果您正苦于以下问题:Python Trainer._should_stop_early方法的具体用法?Python Trainer._should_stop_early怎么用?Python Trainer._should_stop_early使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类allennlp.training.trainer.Trainer
的用法示例。
在下文中一共展示了Trainer._should_stop_early方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_should_stop_early_with_increasing_metric
# 需要导入模块: from allennlp.training.trainer import Trainer [as 别名]
# 或者: from allennlp.training.trainer.Trainer import _should_stop_early [as 别名]
def test_should_stop_early_with_increasing_metric(self):
new_trainer = Trainer(self.model, self.optimizer,
self.iterator, self.instances,
validation_dataset=self.instances,
num_epochs=3, serialization_dir=self.TEST_DIR,
patience=5, validation_metric="+test")
assert new_trainer._should_stop_early([.5, .3, .2, .1, .4, .4]) # pylint: disable=protected-access
assert not new_trainer._should_stop_early([.3, .3, .3, .2, .5, .1]) # pylint: disable=protected-access
示例2: test_should_stop_early_with_early_stopping_disabled
# 需要导入模块: from allennlp.training.trainer import Trainer [as 别名]
# 或者: from allennlp.training.trainer.Trainer import _should_stop_early [as 别名]
def test_should_stop_early_with_early_stopping_disabled(self):
# Increasing metric
trainer = Trainer(self.model, self.optimizer, self.iterator, self.instances,
validation_dataset=self.instances, num_epochs=100,
patience=None, validation_metric="+test")
decreasing_history = [float(i) for i in reversed(range(20))]
assert not trainer._should_stop_early(decreasing_history) # pylint: disable=protected-access
# Decreasing metric
trainer = Trainer(self.model, self.optimizer, self.iterator, self.instances,
validation_dataset=self.instances, num_epochs=100,
patience=None, validation_metric="-test")
increasing_history = [float(i) for i in range(20)]
assert not trainer._should_stop_early(increasing_history) # pylint: disable=protected-access