change finally block

This commit is contained in:
thomashacker 2023-03-27 14:18:47 +02:00
parent 33b39baf61
commit bce15df01c
2 changed files with 6 additions and 6 deletions

View File

@ -181,7 +181,7 @@ def test_pretraining_tok2vec_characters(objective):
pretrain(filled, tmp_dir)
assert Path(tmp_dir / "model0.bin").exists()
assert Path(tmp_dir / "model4.bin").exists()
assert Path(tmp_dir / "model_last.bin").exists()
assert Path(tmp_dir / "model-last.bin").exists()
assert not Path(tmp_dir / "model5.bin").exists()
@ -238,7 +238,7 @@ def test_pretraining_tagger_tok2vec(config):
pretrain(filled, tmp_dir)
assert Path(tmp_dir / "model0.bin").exists()
assert Path(tmp_dir / "model4.bin").exists()
assert Path(tmp_dir / "model_last.bin").exists()
assert Path(tmp_dir / "model-last.bin").exists()
assert not Path(tmp_dir / "model5.bin").exists()

View File

@ -80,8 +80,8 @@ def pretrain(
# TODO: I think we probably want this to look more like the
# 'create_train_batches' function?
for epoch in range(epoch_resume, P["max_epochs"]):
try:
try:
for epoch in range(epoch_resume, P["max_epochs"]):
for batch_id, batch in enumerate(batcher(corpus(nlp))):
docs = ensure_docs(batch)
loss = make_update(model, docs, optimizer, objective)
@ -97,8 +97,8 @@ def pretrain(
else:
_save_model(epoch)
tracker.epoch_loss = 0.0
finally:
_save_model(epoch, is_last=True)
finally:
_save_model(P["max_epochs"], is_last=True)
def ensure_docs(examples_or_docs: Iterable[Union[Doc, Example]]) -> List[Doc]: