MCPcopy Create free account
hub / github.com/huggingface/transformers / build_mask

Function build_mask

examples/seq2seq/bertabs/utils_summarization.py:121–127  ·  view source on GitHub ↗

Builds the mask. The attention mechanism will only attend to positions with value 1.

(sequence, pad_token_id)

Source from the content-addressed store, hash-verified

119
120
121def 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
130def encode_for_summarization(story_lines, summary_lines, tokenizer):

Callers 4

test_build_maskMethod · 0.85
collateFunction · 0.85

Calls

no outgoing calls