Skip to content
This repository has been archived by the owner on Nov 21, 2022. It is now read-only.

Commit

Permalink
Fix broken bleu metrics (#228)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sean Naren authored Feb 2, 2022
1 parent 9b9faf9 commit aa8f48a
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 6 deletions.
5 changes: 1 addition & 4 deletions lightning_transformers/task/nlp/translation/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,7 @@ def compute_generate_metrics(self, batch, prefix):
tgt_lns = self.tokenize_labels(batch["labels"])
pred_lns = self.generate(batch["input_ids"], batch["attention_mask"])
# wrap targets in list as score expects a list of potential references
tgt_tokens = tuple([tuple(tuple(reference.split()) for reference in tgt_lns)])
pred_tokens = tuple(tuple(prediction.split()) for prediction in pred_lns)
result = self.bleu(tgt_tokens, pred_tokens)

result = self.bleu(pred_lns, tgt_lns)
self.log(f"{prefix}_bleu_score", result, on_step=False, on_epoch=True, prog_bar=True)

def configure_metrics(self, stage: str):
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ numpy
tqdm

#metrics
torchmetrics>=0.5.1
torchmetrics>=0.7.0

# huggingface
transformers
Expand Down
1 change: 1 addition & 0 deletions requirements/docs.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ sphinx-autodoc-typehints>=1.11.1 # required by: https://github.com/agronholm/sp
sphinx-paramlinks>=0.4.0
sphinx-togglebutton>=0.2
sphinx-copybutton>=0.3
mistune==0.8.4
3 changes: 2 additions & 1 deletion tests/core/test_loggers.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ def setUp(self):
# run logger offline
self.logger = WABLogger(offline=True)

def tearDown(self):
@classmethod
def tearDownClass(cls):
# delete wandb folder
cwd = os.getcwd()
if os.path.exists(os.path.join(cwd, "wandb")):
Expand Down

0 comments on commit aa8f48a

Please sign in to comment.