Skip to content

Possible simplification in T5 docs #14731

@xhluca

Description

@xhluca

I noticed the following nested list comprehension being recommended in the T5 docs:

# replace padding token id's of the labels by -100
labels = [
           [(label if label != tokenizer.pad_token_id else -100) for label in labels_example] for labels_example in labels
] 
labels = torch.tensor(labels)

I believe it's possible to simplify above to:

labels = torch.tensor(labels)
labels[labels == tokenizer.pad_token_id] = -100

I would be happy to make a PR if the change is deemed relevant, though I'm not sure where the docs are located so please let me know if needed :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions