Remove columns that are populated exclusively by pad_token_id
(
input_ids,
pad_token_id,
attention_mask=None,
)
| 105 | |
| 106 | |
| 107 | def trim_batch( |
| 108 | input_ids, |
| 109 | pad_token_id, |
| 110 | attention_mask=None, |
| 111 | ): |
| 112 | """Remove columns that are populated exclusively by pad_token_id""" |
| 113 | keep_column_mask = input_ids.ne(pad_token_id).any(dim=0) |
| 114 | if attention_mask is None: |
| 115 | return input_ids[:, keep_column_mask] |
| 116 | else: |
| 117 | return (input_ids[:, keep_column_mask], attention_mask[:, keep_column_mask]) |
| 118 | |
| 119 | |
| 120 | class AbstractSeq2SeqDataset(Dataset): |
no outgoing calls
no test coverage detected