Transformers, Pytorch, Machine Learning, Deep Dives, Data Science.
src_batch, tgt_batch = [], [] for src_sample, tgt_sample in batch: src_batch.append(src_sample) tgt_batch.append(tgt_sample) src_batch = pad_sequence(src_batch, padding_value=PAD_IDX, batch_first=True) tgt_batch = pad_sequence(tgt_batch, padding_value=PAD_IDX, batch_first=True) return src_batch,