---
title: "Getting Started with Sentiment Analysis on Twitter"
description: "Twitter sentiment analysis can be done with an off-the-shelf model instead of manual labeling, and two routes are shown: code and no-code."
url: "https://swe.quest/articles/getting-started-with-sentiment-analysis-on-twitter-905f15e14131b6f1"
canonical: "https://huggingface.co/blog/sentiment-analysis-twitter"
source: "Hugging Face"
published: "2022-07-07"
difficulty: "medium"
kind: "How-to"
reading_minutes: 15
tags: ["machine-learning","python","inference"]
---

# Getting Started with Sentiment Analysis on Twitter

A post on [Hugging Face](https://swe.quest/sources/hugging-face.md), published 2022-07-07, 15 min read, How-to. Original: [https://huggingface.co/blog/sentiment-analysis-twitter](https://huggingface.co/blog/sentiment-analysis-twitter)

## Summary

Twitter sentiment analysis can be done with an off-the-shelf model instead of manual labeling, and two routes are shown: code and no-code. Developers can pull tweets with Tweepy and classify them through the Hugging Face Inference API using cardiffnlp/twitter-roberta-base-sentiment-latest, then chart the results with pandas, Matplotlib and WordCloud. A sample run on 1,000 tweets mentioning Notion came out 50% positive and 8.2% negative. Non-coders can build a Zapier workflow that triggers on Twitter mentions, calls the Inference API and writes the results to Google Sheets.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [Machine learning](https://swe.quest/tags/machine-learning.md) (AI & ML)
- [Python](https://swe.quest/tags/python.md) (Languages)
- [Inference & serving](https://swe.quest/tags/inference.md) (AI & ML)

## Prerequisites

- Python basics ([easy posts on Python](https://swe.quest/tags/python.md?difficulty=easy))
- REST APIs ([easy posts on API design](https://swe.quest/tags/api-design.md?difficulty=easy))

## Keywords

Hugging Face Inference API, Tweepy, Twitter API, RoBERTa, Zapier, Google Sheets, WordCloud

## Related posts

- [Supercharged Customer Service with Machine Learning](https://swe.quest/articles/supercharged-customer-service-with-machine-learning-40f2ea8336a86ea0.md): Hugging Face · 2022-04-25 · Medium · 22 min read · Model training, Machine learning, Python
  A walkthrough of building a classifier that flags very unsatisfied customer messages by framing the problem as 5-class sentiment text classification.
- [Data-Centric Machine Learning: Building Shopify Inbox’s Message Classification Model](https://swe.quest/articles/data-centric-machine-learning-building-shopify-inbox-s-message-classification-89547c88c3590e73.md): Shopify Engineering · 2022-07-21 · Medium · 12 min read · Machine learning, Model training, Privacy, Communications
  Shopify Inbox's message classifier improved from ~70% to ~90% accuracy, and from ~35% to ~80% high-confidence coverage, by investing in better training data rather than model tweaks.
- [Opinion Classification with Kili and HuggingFace AutoTrain](https://swe.quest/articles/opinion-classification-with-kili-and-huggingface-autotrain-97ebbffd8c146463.md): Hugging Face · 2022-04-28 · Medium · 18 min read · Machine learning, Model training, Python
  Kili's annotation platform and Hugging Face AutoTrain combine into an active-learning pipeline that classifies about 40,000 Google Play reviews of the Medium app into Subscription, Content, Interface and User Experience, then applies sentiment analysis to the classified reviews.
- [SetFitABSA: Few-Shot Aspect Based Sentiment Analysis using SetFit](https://swe.quest/articles/setfitabsa-few-shot-aspect-based-sentiment-analysis-using-setfit-1531f1fb3bd2dc96.md): Hugging Face · 2023-12-06 · Medium · 9 min read · Machine learning, Model training, Python
  SetFitABSA performs few-shot aspect-based sentiment analysis in three stages: spaCy extracts noun and noun-compound aspect candidates, one SetFit model classifies each candidate as aspect or non-aspect, and a second SetFit model assigns a sentiment polarity to each aspect.
- [Sentiment Analysis on Encrypted Data with Homomorphic Encryption](https://swe.quest/articles/sentiment-analysis-on-encrypted-data-with-homomorphic-encryption-62bd5104a9f4964a.md): Hugging Face · 2022-11-17 · Medium · 8 min read · Privacy, Cryptography, Machine learning, Inference & serving, Python
  Sentiment classification can run on encrypted text by computing a transformer (RoBERTa) hidden representation on the client, then running a quantized XGBoost classifier under fully homomorphic encryption with Concrete-ML.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
