15
15
16
16
import os
17
17
from shutil import copyfile
18
- from typing import Dict , List , Optional , Tuple , Union
18
+ from typing import Dict , List , Literal , Optional , Tuple , Union
19
19
20
20
import numpy as np
21
21
import sentencepiece as spm
@@ -232,6 +232,7 @@ def _pad(
232
232
max_length : Optional [int ] = None ,
233
233
padding_strategy : PaddingStrategy = PaddingStrategy .DO_NOT_PAD ,
234
234
pad_to_multiple_of : Optional [int ] = None ,
235
+ padding_side : Optional [Literal ["right" , "left" ]] = None ,
235
236
return_attention_mask : Optional [bool ] = None ,
236
237
) -> dict :
237
238
"""
@@ -247,13 +248,16 @@ def _pad(
247
248
- PaddingStrategy.LONGEST Pad to the longest sequence in the batch
248
249
- PaddingStrategy.MAX_LENGTH: Pad to the max length (default)
249
250
- PaddingStrategy.DO_NOT_PAD: Do not pad
250
- The tokenizer padding sides are defined in self. padding_side:
251
+ The tokenizer padding sides are defined in ` padding_side` argument :
251
252
252
253
- 'left': pads on the left of the sequences
253
254
- 'right': pads on the right of the sequences
254
255
pad_to_multiple_of: (optional) Integer if set will pad the sequence to a multiple of the provided value.
255
256
This is especially useful to enable the use of Tensor Core on NVIDIA hardware with compute capability
256
257
>= 7.5 (Volta).
258
+ padding_side: (optional) The side on which the model should have padding applied.
259
+ Should be selected between ['right', 'left'].
260
+ Default value is picked from the class attribute of the same name.
257
261
return_attention_mask:
258
262
(optional) Set to False to avoid returning attention mask (default: set to model specifics)
259
263
"""
@@ -268,7 +272,7 @@ def _pad(
268
272
269
273
required_input = encoded_inputs [self .model_input_names [0 ]]
270
274
encoded_inputs = super ()._pad (
271
- encoded_inputs , max_length , padding_strategy , pad_to_multiple_of , return_attention_mask
275
+ encoded_inputs , max_length , padding_strategy , pad_to_multiple_of , padding_side , return_attention_mask
272
276
)
273
277
if attention_mask is not None and len (np .shape (attention_mask )) > 2 :
274
278
encoded_inputs ["attention_mask" ] = attention_mask
@@ -521,6 +525,7 @@ def _pad(
521
525
max_length : Optional [int ] = None ,
522
526
padding_strategy : PaddingStrategy = PaddingStrategy .DO_NOT_PAD ,
523
527
pad_to_multiple_of : Optional [int ] = None ,
528
+ padding_side : Optional [Literal ["right" , "left" ]] = None ,
524
529
return_attention_mask : Optional [bool ] = None ,
525
530
) -> dict :
526
531
"""
@@ -536,13 +541,16 @@ def _pad(
536
541
- PaddingStrategy.LONGEST Pad to the longest sequence in the batch
537
542
- PaddingStrategy.MAX_LENGTH: Pad to the max length (default)
538
543
- PaddingStrategy.DO_NOT_PAD: Do not pad
539
- The tokenizer padding sides are defined in self. padding_side:
544
+ The tokenizer padding sides are defined in ` padding_side` argument :
540
545
541
546
- 'left': pads on the left of the sequences
542
547
- 'right': pads on the right of the sequences
543
548
pad_to_multiple_of: (optional) Integer if set will pad the sequence to a multiple of the provided value.
544
549
This is especially useful to enable the use of Tensor Core on NVIDIA hardware with compute capability
545
550
>= 7.5 (Volta).
551
+ padding_side: (optional) The side on which the model should have padding applied.
552
+ Should be selected between ['right', 'left'].
553
+ Default value is picked from the class attribute of the same name.
546
554
return_attention_mask:
547
555
(optional) Set to False to avoid returning attention mask (default: set to model specifics)
548
556
"""
@@ -557,7 +565,7 @@ def _pad(
557
565
558
566
required_input = encoded_inputs [self .model_input_names [0 ]]
559
567
encoded_inputs = super ()._pad (
560
- encoded_inputs , max_length , padding_strategy , pad_to_multiple_of , return_attention_mask
568
+ encoded_inputs , max_length , padding_strategy , pad_to_multiple_of , padding_side , return_attention_mask
561
569
)
562
570
if attention_mask is not None and len (np .shape (attention_mask )) > 2 :
563
571
encoded_inputs ["attention_mask" ] = attention_mask
0 commit comments