liveBook · Manning

Auto class

As explained in Hugging Face in Action

AutoTokenizer is a Transformers factory class that selects and loads the tokenizer appropriate for a specified pretrained model.

AutoTokenizer is a Transformers factory class that selects and loads the tokenizer associated with a specified pretrained model. Pass a model identifier to from_pretrained(); the tokenizer can then convert text into model-ready token IDs and masks. section 3.2.3 section 5.2.2

Load a tokenizer for sentiment analysis

from transformers import AutoTokenizer tokenizer = AutoTokenizer.from_pretrained( "distilbert/distilbert-base-uncased-finetuned-sst-2-english" ) inputs = tokenizer("I loved the movie, it was fantastic!", return_tensors="pt") The result is a dictionary containing input_ids and attention_mask tensors that can be passed to a PyTorch model. section 3.2.3

Use the tokenizer to:

  • Load the tokenizer matching a pretrained model identifier. section 5.2.2
  • Convert text into input_ids and attention_mask values, with optional token_type_ids for some models. section 3.2.3 section 5.2.2
  • Tokenize dataset rows efficiently with dataset.map(), using batching, truncation, and max-length padding. section 5.2.2
  • Inspect token IDs, convert IDs back to tokens, and identify padding through the attention mask. section 5.2.2
from transformers import AutoTokenizer

tokenizer = AutoTokenizer.from_pretrained(
    "distilbert/distilbert-base-uncased-finetuned-sst-2-english")

Browse the minimal loading example for a tokenizer tied to a pretrained sentiment-analysis model. section 3.2.3

How Hugging Face in Action covers it

How deep it goes
Explains loading, tokenization, padding, masks, and ID conversion, but does not detail tokenizer-selection internals.
Examples
Demonstrates DistilBERT sentiment inputs and BERT IMDb dataset fields, including input IDs, tokens, padding, and attention masks.
What it assumes
Uses a pretrained model identifier and introduces token IDs, subword tokens, padding, and attention masks through examples.
What you can do after
Apply it via Hugging Face Transformers to prepare single texts or dataset batches for model inference.
How it connects
Connects pretrained models, tokenization, PyTorch tensors, datasets, padding, attention masks, and model inference.

Also explained in

Compare how 2 books explain auto class →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Hugging Face in Action. The section links point to the parts of the book it draws on.