liveBook · Manning

Sentiment analysis

As explained in Hugging Face in Action

Sentiment analysis is the computational classification of text according to the expressed attitude or polarity, such as positive or negative sentiment.

Sentiment analysis classifies the attitude expressed in text, commonly as positive, negative, or neutral. A Hugging Face pipeline makes binary classification practical without training a model from scratch. section 3.2.3 section 1.1

Classify a review with a pipeline

from transformers import pipeline classifier = pipeline( "text-classification", model="distilbert-base-uncased-finetuned-sst-2-english", revision="af0f99b" ) classifier("I loved the movie; it was fantastic!") The pipeline returns a sentiment label and confidence score. The demonstrated model supports positive and negative IMDb-style classification. section 1.1

For lower-level control, load the tokenizer and sequence-classification model, tokenize text into PyTorch tensors, pass the inputs to the model, and select the largest logit. The example maps class 0 to negative and class 1 to positive. section 3.2.3

Domain adaptation uses labeled reviews such as Yelp Polarity, whose binary labels support fine-tuning a pretrained model for restaurant, hotel, and service opinions. section 6.1.1

How Hugging Face in Action covers it

How deep it goes
Explains pipeline use, then descends through tokenization, attention masks, logits, class selection, and fine-tuning datasets.
Examples
Uses IMDb movie reviews, a positive movie sentence, and labeled Yelp restaurant and service reviews.
What it assumes
Assumes Python familiarity while teaching model loading, tokenization, tensor inputs, and prediction from operational examples.
What you can do after
Builds a classifier with a pipeline, or operates a tokenizer and model directly to produce sentiment predictions.
How it connects
Connects text classification with tokenization, pretrained models, PyTorch inference, and fine-tuning.

Also explained in

Compare how 12 books explain sentiment analysis →

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.