[BUG] - Bleu of machine translation
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 9.3k
- Forks
- 4.4k
- Avg merge
- 1d 21h
- Merged PRs (30d)
- 4
Description
Add Link
https://pytorch.org/tutorials/beginner/translation_transformer.html
Describe the bug
-
Expected Blue score of 35 -30
-
got near 0.6 - tested on test set got from Multi30k -Attaching here. (format: de|en)
-
Same code as the tutorial
-
code used to calculate Bleu score:
from nltk.translate.bleu_score import sentence_bleu import numpy as np def bleu4(candidate, reference): score = sentence_bleu([reference], candidate, weights=(0.25, 0.25, 0.25, 0.25)) # score = sentence_bleu([reference], candidate) return score -
Modified BlocK:
`from timeit import default_timer as timer NUM_EPOCHS = 100 for epoch in range(1, NUM_EPOCHS+1): start_time = timer() train_loss = train_epoch(transformer, optimizer) end_time = timer() val_loss = evaluate(transformer) print((f"Epoch: {epoch}, Train loss: {train_loss:.3f}, Val loss: {val_loss:.3f}, "f"Epoch time = {(end_time - start_time):.3f}s")) if epoch % 10 == 0: transformer.eval() i=0 total_bleu = 0 test = open("test.txt", "r").readlines() for r in test: data = r.strip().split('|') reference = data[1].split() candidate = translate(transformer, data[0]).split() total_bleu += bleu4(candidate, reference) print ("----------------- START -----------------") print ("GT: ", reference) print ("OUT: ", candidate) print ("BLEU for this example: ", bleu4(candidate, reference)) print ("Average BLEU: ", total_bleu/(i+1)) print ("----------------- END -----------------") i+=1 print ("------FINAL BLEU: ", total_bleu/(i)) with open("bleu_ours.txt", "a") as f: f.write("Epoch: " + str(epoch) + " BLEU: " + str(total_bleu/(i)) + "\n") if epoch % 50 == 0: torch.save(transformer.state_dict(), "transformer_ours"+str(epoch)+".pt")`
Describe your environment
Linux
Name: torch
Version: 2.0.1
cc @pytorch/team-text-core @Nayef211
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the linked translation transformer tutorial and compare its evaluation flow with the modified training block. Reproduce the reported result using test.txt and the shown NLTK sentence_bleu call, then determine whether the tutorial or its evaluation guidance needs correction; done means the expected BLEU calculation and any required tutorial change are clearly established.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- documentation, machine-learning
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100