MCPcopy Create free account
hub / github.com/RingBDStack/GDAP / trim_batch

Function trim_batch

seq2seq/utils.py:107–117  ·  view source on GitHub ↗

Remove columns that are populated exclusively by pad_token_id

(
        input_ids,
        pad_token_id,
        attention_mask=None,
)

Source from the content-addressed store, hash-verified

105
106
107def 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
120class AbstractSeq2SeqDataset(Dataset):

Callers 2

collate_fnMethod · 0.85
__call__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected