NumPy allowed · plain Python earns 10 bonus points
Computed matrix × vector transformation
Collate variable-length token sequences into a uniform dense matrix with binary attention masks.
Implement collate_padded_batch(sequences, pad_val): determine max_len = max(len(s)) across input sequences. Pad shorter sequences on the right with pad_val. Concurrently create attention_mask where original tokens are 1 and padding tokens are 0. Return a dict {"padded_batch": ..., "attention_mask": ...}.
collate_padded_batch(sequences: list[list[int]], pad_val: int) -> dict[str, list]