Builds the mask. The attention mechanism will only attend to positions with value 1.
(sequence, pad_token_id)
| 119 | |
| 120 | |
| 121 | def build_mask(sequence, pad_token_id): |
| 122 | """ Builds the mask. The attention mechanism will only attend to positions |
| 123 | with value 1. """ |
| 124 | mask = torch.ones_like(sequence) |
| 125 | idx_pad_tokens = sequence == pad_token_id |
| 126 | mask[idx_pad_tokens] = 0 |
| 127 | return mask |
| 128 | |
| 129 | |
| 130 | def encode_for_summarization(story_lines, summary_lines, tokenizer): |
no outgoing calls