liveBook · Manning

Transformers

As explained in Hugging Face in Action

Transformers is an open-source library for working with pretrained machine-learning models, especially models for natural-language processing and computer vision.

Transformers is an open-source Python library for using pretrained transformer-based models across natural-language processing, computer vision, audio, and reinforcement-learning tasks. It provides accessible APIs so developers can apply capable models without building or training them from scratch. section 1.1 section 3.3

Classify sentiment with a pipeline

from transformers import pipeline classifier = pipeline( 'text-classification', model='distilbert-base-uncased-finetuned-sst-2-english', revision='af0f99b' ) result = classifier('This film was witty, enjoyable, and beautifully acted.') The pipeline loads the specified pretrained model and returns a formatted classification result. Pipelines provide a high-level interface for common workflows such as classification, named entity recognition, translation, summarization, and generation. section 1.1 section 3.0

Use Transformers to perform tasks including:

  • Text classification, including sentiment analysis and zero-shot classification. section 1.1 section 3.3
  • Text generation, summarization, translation, and question answering. section 3.3
  • Computer-vision work such as object detection with models hosted on the Hugging Face Hub. section 1.2
  • Named entity recognition and other workflows through pretrained models and pipelines. section 2.2 section 3.0

Install the package with pip in a notebook, terminal, or Anaconda Prompt. Pretrained models include BERT, GPT, RoBERTa, DistilBERT, and T5; each supplies a different starting point for NLP applications. section 2.2 section 3.2.1

from transformers import pipeline

classifier = pipeline('text-classification',
             model = 'distilbert-base-uncased-finetuned-sst-2-english',
             revision = 'af0f99b')

Runnable pipeline example showing model selection and revision pinning. section 1.1

How Hugging Face in Action covers it

How deep it goes
Explains installation, pretrained models, pipelines, and task categories while stopping short of detailed transformer internals.
Examples
Demonstrates sentiment classification with DistilBERT and object detection with a hosted DETR model.
What it assumes
Assumes basic Python and pip familiarity while avoiding requirements to build neural networks or train models from scratch.
What you can do after
Apply it via the pipeline API to run pretrained models for common language and vision tasks.
How it connects
Connects pipelines with pretrained models, transformer architecture, the Hugging Face Hub, and natural-language processing tasks.

Also explained in

Compare how 6 books explain transformers →

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.