Instructions to use alexgeh196/twitter-sentiment-analysis with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use alexgeh196/twitter-sentiment-analysis with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-classification", model="alexgeh196/twitter-sentiment-analysis")# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForSequenceClassification tokenizer = AutoTokenizer.from_pretrained("alexgeh196/twitter-sentiment-analysis") model = AutoModelForSequenceClassification.from_pretrained("alexgeh196/twitter-sentiment-analysis", device_map="auto") - Notebooks
- Google Colab
- Kaggle
Twitter Sentiment Analysis (DistilBERT, fine-tuned on Sentiment140)
Binary sentiment classifier (negative / positive) for short English social-media text. Fine-tuned from distilbert-base-uncased on the Sentiment140 dataset (1.6 million labelled tweets).
Built by Alexander Gehbrezgi as part of his Master's thesis at Goethe University Frankfurt, Chair of Information Systems and Information Management (2023): "Impact of Russia's 2022 Invasion of Ukraine on Global Financial Markets: A Machine Learning-Based Sentiment Analysis of News and Social Media" (grade 1.3).
Use in the thesis
The model scored the sentiment of 210,000+ Facebook posts and 149,000+ articles from 20 news outlets in Africa, Asia, Europe and the US (January–July 2023). Together with RoBERTa-based emotion and topic classifiers, the scores were used to explain daily market movements across sector and regional indices with logistic regression.
Training
| Setting | Value |
|---|---|
| Base model | distilbert-base-uncased |
| Data | Sentiment140 (1.6M tweets, labels 0 = negative, 4 = positive) |
| Validation | Hold-out, shuffled, ~60:40 train/test split |
| Learning rate | 2e-5 (linear decay) |
| Batch size | 16 (train and eval) |
| Epochs | 3 |
| Weight decay | 0.01 |
| Hardware | NVIDIA A100 GPU (Google Colab) |
Evaluation (test split)
| Loss | Accuracy | F1 | Precision | Recall |
|---|---|---|---|---|
| 0.3724 | 0.8660 | 0.8652 | 0.8712 | 0.8593 |
How to use
from transformers import pipeline
classifier = pipeline("text-classification", model="alexgeh196/twitter-sentiment-analysis")
classifier("Ukrainian forces report very good results on the front line.")
Limitations
- Binary only (negative / positive); no neutral class.
- Trained on tweets from 2009; language and topics differ from today's news and from long-form text.
- Long articles must be split into sentences and the scores averaged, as done in the thesis.
- English only. Labels from Sentiment140 were created by distant supervision (emoticons) and contain noise.
- Downloads last month
- 3
Model tree for alexgeh196/twitter-sentiment-analysis
Base model
distilbert/distilbert-base-uncasedDataset used to train alexgeh196/twitter-sentiment-analysis
Evaluation results
- accuracy on Sentiment140self-reported0.866
- f1 on Sentiment140self-reported0.865
- precision on Sentiment140self-reported0.871
- recall on Sentiment140self-reported0.859