Daniel RotkopfFull-stack engineer
Work

Reddit Stock Sentiment

A sentiment classifier for Reddit stock discussion, including the dataset it trains on.

How it runs

  1. 01ScrapeSelenium, old.reddit
  2. 02LabelGPT-4o-mini + post context
  3. 03Balanceundersample to smallest class
  4. 04Train3 LSTM variants
  5. 05ServeFlask, background jobs
Year2025
ContextAcademic research project
LanguagePython
Updated1y ago

No dataset existed for this, so the project starts with a Selenium scraper. It walks old.reddit.com search results for a given subreddit and keyword, pages until it has enough posts, then pulls the comment tree from each one.

Labelling thousands of comments by hand was not realistic. I used GPT-4o-mini to label each comment positive, negative or neutral, and passed it the original post as context. Without that context a comment like "this will age well" is unclassifiable. The run writes progress to disk after every batch, so a failed API call resumes instead of starting over.

Three LSTM variants train on GPT-2 tokenised sequences, 200 tokens with 128-dimensional embeddings. Reddit comments skew positive, so the training set is balanced by undersampling every class down to the size of the smallest one.

A Flask app runs the whole thing. You submit a subreddit, the scrape and inference run on a background thread against a UUID-keyed task registry, and the page polls for the result instead of blocking.

Highlights

  • GPT-4o-mini as a labeller, with post-level context
  • Labelling resumes after a crash instead of restarting
  • Class balancing by undersampling
  • Background jobs behind a polling endpoint

Built with

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