Unhack eval

This commit is contained in:
Matthew Honnibal 2020-10-12 11:50:45 +02:00
parent 9964dad76e
commit ac13af80fe

View File

@ -197,9 +197,9 @@ def train_while_improving(
if not (step % eval_frequency): if not (step % eval_frequency):
if optimizer.averages: if optimizer.averages:
with nlp.use_params(optimizer.averages): with nlp.use_params(optimizer.averages):
score, other_scores = evaluate(step) score, other_scores = evaluate()
else: else:
score, other_scores = evaluate(step) score, other_scores = evaluate()
results.append((score, step)) results.append((score, step))
is_best_checkpoint = score == max(results)[0] is_best_checkpoint = score == max(results)[0]
else: else:
@ -248,10 +248,8 @@ def create_evaluation_callback(
) -> Callable[[], Tuple[float, Dict[str, float]]]: ) -> Callable[[], Tuple[float, Dict[str, float]]]:
weights = {key: value for key, value in weights.items() if value is not None} weights = {key: value for key, value in weights.items() if value is not None}
def evaluate(step) -> Tuple[float, Dict[str, float]]: def evaluate() -> Tuple[float, Dict[str, float]]:
# Limit dev_examples by steps, so we don't spend longer on dev_examples = list(dev_corpus(nlp))
# the estimation than we have training.
dev_examples = list(itertools.islice(dev_corpus(nlp), step))
try: try:
scores = nlp.evaluate(dev_examples) scores = nlp.evaluate(dev_examples)
except KeyError as e: except KeyError as e: