From 9a13ab570025a0c1659986009d2abddb2e652020 Mon Sep 17 00:00:00 2001 From: Joel Grus Date: Mon, 24 Jun 2019 10:45:00 -0700 Subject: [PATCH] do not evaluate after training if non-default trainer (#2997) --- allennlp/commands/train.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/allennlp/commands/train.py b/allennlp/commands/train.py index 7ab846fbf7c..a4fb24229f2 100644 --- a/allennlp/commands/train.py +++ b/allennlp/commands/train.py @@ -225,18 +225,19 @@ def train_model(params: Params, validation_data=pieces.validation_dataset, params=pieces.params, validation_iterator=pieces.validation_iterator) + + evaluation_iterator = pieces.validation_iterator or pieces.iterator + evaluation_dataset = pieces.test_dataset + else: - # Workaround to obtain the evaluation parts. - pieces = TrainerPieces.from_params(params.duplicate(), # pylint: disable=no-member - serialization_dir, - recover, - cache_directory, - cache_prefix) + if evaluate_on_test: + raise ValueError("--evaluate-on-test only works with the default Trainer. " + "If you're using the CallbackTrainer you can use a callback " + "to evaluate at Events.TRAINING_END; otherwise you'll have " + "to run allennlp evaluate separately.") trainer = TrainerBase.from_params(params, serialization_dir, recover) - - evaluation_iterator = pieces.validation_iterator or pieces.iterator - evaluation_dataset = pieces.test_dataset + evaluation_dataset = None params.assert_empty('base train command')