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






























