Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release optimizer memory and fix legacy tokenization #3043

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion flair/embeddings/transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,8 @@ def _reconstruct_word_ids_from_subtokens(embedding, tokens: List[str], subtokens
special_tokens.append(embedding.tokenizer.bos_token)
if embedding.tokenizer._cls_token:
special_tokens.append(embedding.tokenizer.cls_token)
if embedding.tokenizer._sep_token:
special_tokens.append(embedding.tokenizer.sep_token)

# iterate over subtokens and reconstruct tokens
for subtoken_id, subtoken in enumerate(subtokens):
Expand All @@ -243,7 +245,6 @@ def _reconstruct_word_ids_from_subtokens(embedding, tokens: List[str], subtokens
subtoken_count += 1

reconstructed_token = reconstructed_token + subtoken
print(reconstructed_token)

if reconstructed_token.lower() == token_text:
# we cannot handle unk_tokens perfectly, so let's assume that one unk_token corresponds to one token.
Expand Down
2 changes: 2 additions & 0 deletions flair/trainers/trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -844,6 +844,8 @@ def train(
finally:
if use_tensorboard:
writer.close()
optimizer.zero_grad(set_to_none=True)
del optimizer

# test best model if test data is present
if self.corpus.test and not train_with_test:
Expand Down