daniel rotkopf

← all projects

Reddit Stock Sentiment

End-to-end sentiment pipeline with LLM-assisted labeling

Final project, 12th grade machine learning · 2025 · Python · updated 1y ago

A complete pipeline that turns unstructured Reddit discussion into a trained sentiment classifier — and then serves it.

The dataset didn't exist, so the project starts with a Selenium scraper that walks old.reddit.com search results for a given subreddit and keyword, paginating until it has enough posts, then pulling the comment tree from each one.

Hand-labeling thousands of comments wasn't realistic. Instead GPT-4o-mini acts as a weak supervisor, classifying each comment as positive, negative, or neutral — and critically, it receives the original post as context, since a comment like "this is going to age well" means nothing on its own. The labeling run checkpoints progress to disk after every batch, so an API failure resumes instead of restarting.

Three LSTM architectures train on GPT-2 tokenized sequences (200 tokens, 128-dim embeddings) over the labeled set. Because Reddit skews heavily positive, the training set is balanced by undersampling every class to the size of the rarest one.

A Flask app ties it together: submit a subreddit, the scrape and inference run on a background thread with a UUID-keyed task registry, and the page polls for results rather than blocking.

# highlights

  • LLM weak supervision with post-level context
  • Crash-resumable labeling via disk checkpoints
  • Class balancing by undersampling
  • Threaded async jobs behind a polling API

# built with

  • Python
  • TensorFlow/Keras
  • LSTM
  • GPT-2 tokenizer
  • OpenAI API
  • Selenium
  • Flask
  • scikit-learn