One package, every Transformer architecture
The transformers library (Hugging Face) gives you a uniform interface to every major NLP, vision, audio, and multimodal Transformer. Three layers of abstraction, from highest to lowest:
- Pipelines — one-line task-shaped APIs (
pipeline("sentiment-analysis"),pipeline("summarization")). Best for prototyping and one-off scripts. - Auto* classes —
AutoTokenizer,AutoModel,AutoModelForSequenceClassification, etc. They detect the architecture from the checkpoint name and instantiate the right class. The right level for "I want to control the model and the loop". - Specific model classes —
BertModel,GPT2LMHeadModel, etc. Use only when you need architecture-specific features the Auto layer hides.
Tokenizer + Model — the standard pair
Every Transformers model comes with a matching tokenizer. The model expects token IDs (and an attention mask). The tokenizer turns text into IDs. They MUST match — load both from the same checkpoint name.
The "head" pattern
For each base model architecture there are several "head" variants for different tasks:
AutoModel— base model, returns hidden states.AutoModelForSequenceClassification— classification head (with logits).AutoModelForTokenClassification— per-token labels (NER).AutoModelForCausalLM— language modeling (GPT-style).AutoModelForSeq2SeqLM— encoder-decoder (T5-style).AutoModelForQuestionAnswering— extractive QA (start/end positions).
Pick the one matching your task; the library hooks up the right output head automatically.