(input_ids, channels, tokenizer)
| 327 | |
| 328 | |
| 329 | def rpadding(input_ids, channels, tokenizer): |
| 330 | attention_masks = [np.ones(inputs.shape[0]) for inputs in input_ids] |
| 331 | max_length = max(ids.shape[0] for ids in input_ids) |
| 332 | padded_input_ids, padded_attns = [], [] |
| 333 | |
| 334 | for ids, attn in zip(input_ids, attention_masks): |
| 335 | pad_len = max_length - ids.shape[0] |
| 336 | input_pad = np.full((pad_len, channels), 1024) |
| 337 | input_pad[:, 0] = tokenizer.pad_token_id |
| 338 | padded_input_ids.append(np.concatenate([input_pad, ids])) |
| 339 | attn_pad = np.zeros(pad_len) |
| 340 | padded_attns.append(np.concatenate([attn_pad, attn])) |
| 341 | |
| 342 | input_ids = torch.tensor(np.stack(padded_input_ids)) |
| 343 | attention_mask = torch.tensor(np.stack(padded_attns)) |
| 344 | |
| 345 | return input_ids, attention_mask |
| 346 | |
| 347 | |
| 348 | def find_max_valid_positions(C: torch.Tensor, invalid_value=1024) -> torch.Tensor: |
no outgoing calls
no test coverage detected