Fairseq needs padding direction correction
@@ -19,6 +19,7 @@ from fairseq.sequence_generator import SequenceGenerator
from fairseq.sequence_scorer import SequenceScorer
from fairseq import options
from fairseq.tasks.fairseq_task import FairseqTask
+from fairseq.utils import convert_padding_direction
from parlai.core.torch_agent import TorchAgent, Output
from parlai.core.build_data import modelzoo_path
@@ -597,10 +598,11 @@ class FairseqAgent(TorchAgent):
"""Generate a sample object that Fairseq expects."""
# add extra info to samples
# TODO: should the right/left padding thing be in torch agent?
+ repadded = convert_padding_direction(xs, self.dict.pad(), right_to_left=True)
sample = {}
sample["id"] = torch.arange(len(xs) - 1)
sample["net_input"] = {
- "src_tokens": xs,
+ "src_tokens": repadded,
"src_lengths": self._seq_length(xs),
}
if ys is not None:
