liveBook · Manning

Classifier

As explained in Hugging Face in Action

Classification is the task of assigning an input to one or more predefined categories.

Classification assigns an input to one or more predefined categories. In practical AI workflows, pretrained models classify text or images without requiring a model to be trained from scratch. section 1.1 section 4.3

from transformers import pipeline

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

Run a text-classification pipeline by selecting an explicit model and revision; pass text to receive a sentiment label and score. section 1.1

Common classification applications include:

  • Sentiment analysis labels reviews as positive or negative. section 3.2.4
  • Question detection identifies whether a sentence contains a question. section 3.3.1
  • Language detection assigns a language label to text, such as Japanese. section 3.3.1
  • Spam classification separates unwanted messages from legitimate messages. section 3.3.1
  • Image classification labels visual content, including an estimated age range in a portrait. section 4.3

Classify several reviews

Create a Transformers pipeline with the DistilBERT sentiment model, then call it with one review or a list of reviews. The result contains labels such as POSITIVE or NEGATIVE and a score for each input. section 3.2.4

How Hugging Face in Action covers it

How deep it goes
Explains category assignment and pipeline usage with outputs, but defers detailed transformer architecture and model-training internals.
Examples
Uses movie and restaurant reviews, questions, Japanese text, spam messages, and a portrait for age-range classification.
What it assumes
Assumes basic Python use while teaching task selection, explicit model specification, revisions, and CPU or CUDA device choices.
What you can do after
Apply it via Hugging Face Transformers pipelines to classify text or images and inspect returned labels and scores.
How it connects
Connects classification with sentiment analysis, natural language processing, computer vision, pretrained models, and pipelines.

Also explained in

Compare how 31 books explain classifier →

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.