Skip to content

Commit

Permalink
Fix classification script: enable dynamic padding with truncation (#9554
Browse files Browse the repository at this point in the history
)

Co-authored-by: Pavel Tarashkevich <Pavel.Tarashkievich@orange.com>
  • Loading branch information
pashok3d and Pavel Tarashkevich authored Jan 13, 2021
1 parent 245cdb4 commit 27d0e01
Showing 1 changed file with 1 addition and 3 deletions.
4 changes: 1 addition & 3 deletions examples/text-classification/run_glue.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,11 +283,9 @@ def main():
# Padding strategy
if data_args.pad_to_max_length:
padding = "max_length"
max_length = data_args.max_seq_length
else:
# We will pad later, dynamically at batch creation, to the max sequence length in each batch
padding = False
max_length = None

# Some models have set the order of the labels to use, so let's make sure we do use it.
label_to_id = None
Expand All @@ -314,7 +312,7 @@ def preprocess_function(examples):
args = (
(examples[sentence1_key],) if sentence2_key is None else (examples[sentence1_key], examples[sentence2_key])
)
result = tokenizer(*args, padding=padding, max_length=max_length, truncation=True)
result = tokenizer(*args, padding=padding, max_length=data_args.max_seq_length, truncation=True)

# Map labels to IDs (not necessary for GLUE tasks)
if label_to_id is not None and "label" in examples:
Expand Down

0 comments on commit 27d0e01

Please sign in to comment.