Harsh-svg988 GitHub avatar

financial-sentiment-nlp

Harsh-svg988

A project fine-tuning DistilBERT to classify financial tweets as Bearish, Bullish, or Neutral, with a TF-IDF+Logistic Regression baseline for benchmarking.

Stars

4

7-day growth

No data

Forks

0

Open issues

0

License

No data

Last updated

2026-07-29

AI repository intelligence
FR-AI / ANALYSIS

Why it is worth attention

It demonstrates a clean, reproducible pipeline with class imbalance handled through weighted loss and macro-F1 selection, and an honest baseline that confirms transformer gains on minority classes.

Who it is for

  • NLP practitioners interested in financial text classification
  • Data scientists building sentiment analysis for trading signals
  • Students learning transfer learning and model evaluation
  • Financial analysts seeking automated news sentiment tools

Use cases

  • Classifying financial news headlines or tweets into bullish/bearish/neutral sentiment
  • Enhancing trading strategies with real-time sentiment signals
  • Benchmarking transformer models against classical baselines in imbalanced settings
  • Educational example of fine-tuning DistilBERT with class-weighted loss on Apple Silicon

Strengths

  • Clear problem definition and evaluation using macro-F1 to account for class imbalance
  • Honest baseline (TF-IDF bigrams with class weights) ensuring transformer improvement is real
  • Reproducible pipeline with documented steps, code structure, and figures
  • Handles imbalance at both loss function and evaluation metric levels

Considerations

  • Only tested on a single dataset of ~12k tweets; generalization to other financial text sources is unverified
  • Uses DistilBERT alone; no comparison with other transformer models or larger architectures
  • No deployment or inference API; requires local Python environment to run predictions

README quick start

Financial Sentiment Analysis with DistilBERT

Fine-tuning a transformer to classify the sentiment of financial-news tweets as Bearish, Bullish, or Neutral, and benchmarking it against a classical TF-IDF + Logistic Regression baseline. Fine-tuning runs on Apple-Silicon GPU (MPS).

Problem

Given a short financial statement (e.g. "$AAPL smashes revenue estimates, guidance raised"), predict market sentiment. This is a 3-class, imbalanced text classification task (65% of tweets are Neutral), so the project reports macro-F1 alongside accuracy so the minority classes actually count.

Results (validation set, 2,388 tweets)

ModelAccuracyMacro-F1
TF-IDF + Logistic Regression (baseline)0.8120.755
Fine-tuned DistilBERT0.8510.818

Fine-tuning lifts macro-F1 by +6.3 points — the gain concentrates on the minority Bearish/Bullish classes, where the transformer's contextual understanding beats bag-of-words. Per-class DistilBERT F1: Bearish 0.76, Bullish 0.81, Neutral 0.89.

Live inference examples (src/predict.py):

"Tesla shares tumble after disappointing quarterly earnings"   -> Bearish (98%)
"$AAPL smashes revenue estimates, guidance raised next quarter" -> Bullish (98%)
"The Federal Reserve will announce its rate decision Wednesday" -> Neutral (98%)

Approach

  1. Data + EDA (src/data.py) — 9,543 train / 2,388 validation tweets; light cleaning that keeps $TICKERS and % since they carry sentiment signal.
  2. Baseline (src/baseline.py) — TF-IDF (1–2 grams) + Logistic Regression with balanced class weights. A strong baseline so the transformer has something real to beat.
  3. Fine-tuning (src/train.py) — DistilBERT with a class-weighted cross-entropy loss to handle imbalance; best checkpoint selected by macro-F1; 3 epochs, lr 2e-5, on MPS.
  4. Evaluation (src/evaluate.py) — classification report, confusion matrix, and a baseline-vs-transformer comparison chart.
  5. Inference (src/predict.py) — sentiment + class probabilities for any text.

Figures (reports/figures/)

01_class_distribution.pngclass imbalance in the training set
02_tweet_length.pngtweet-length distribution
03_confusion_matrix.pngDistilBERT errors by class
04_model_comparison.pngbaseline vs. fine-tuned m

Related repositories

Similar projects matched by category, topics, and programming language.

slvDev
Featured
slvDev GitHub avatar

esp32-ai

A 28.9 million parameter language model runs on an $8 ESP32-S3 microcontroller entirely on-device, generating simple stories at about 9.5 tokens per second.

AI & Machine LearningLarge Language Models
1,960
gavamedia
Featured
gavamedia GitHub avatar

deltafin

Deltafin is a research project that runs the 2.8-trillion-parameter Mixture-of-Experts model Kimi K3 on a single Apple Silicon Mac (e.g., M1 Max with 64 GB) at about 16 seconds per token, using exact, reproducible inference with local or streaming expert loading.

AI & Machine LearningLarge Language Models
304
jamesob
Featured
jamesob GitHub avatar

local-llm

A comprehensive guide for building and configuring a high-end local machine to run state-of-the-art LLMs, with detailed hardware choices, BIOS tuning, and Docker-based model serving.

AI & Machine LearningLarge Language Models
1,660