Classify the sentiment of text with a Transformers pipeline
In short: Use the pipeline() function to label a sentence as positive or not, with a pretrained sentiment model.
Use the pipeline() function to label a sentence as positive or not, with a pretrained sentiment model. 1. Import pipeline from the transformers library. 2. Create a classifier with pipeline("sentiment-analysis"): a pretrained English sentiment model is selected by default. 3. Expect a short wait the first time: the model is downloaded and cached when you create the classifier. 4. Call the classifier on a sentence to get its label and score. 5. Pass several sentences at once to classify them together.
Based on: Hugging Face LLM Course — Transformers, what can they do? · Licence: Apache License 2.0. Written by Intellect in its own words from this source. The source does not endorse Intellect.
Steps
- Import pipeline from the transformers library.
- Create a classifier with pipeline("sentiment-analysis"): a pretrained English sentiment model is selected by default.
- Expect a short wait the first time: the model is downloaded and cached when you create the classifier.
- Call the classifier on a sentence to get its label and score.
- Pass several sentences at once to classify them together.
Based on: Hugging Face LLM Course — Transformers, what can they do? · Licence: Apache License 2.0 · View source →
Opens the Intellect+ feed with this card first. Swipe up for the next one.
Sources
- Source: Hugging Face LLM Course: Transformers, what can they do? · Apache License 2.0
To cite this card, link to https://intellectplus.co.uk/app/studio-classify-sentiment-with-a-transformers-pipeline.
How we source, check and correct cards: Editorial standards.
General information, not professional advice. Spotted an error? Flag the card or see corrections and complaints.
Intellect Plus is a visual educational discovery platform for exploring fascinating facts and ideas. Brain Food, Not Brain Rot. What is Intellect Plus?