Wojak Index
View project →I set out to create a real Wojak Index, tracking the number of screaming wojak memes on crypto forums with an image classifier to compile a satirical financial index.
Problems
- Reliable image classification: having never used Pytorch or image classifiers, this was tough going. I gathered as many positive screaming wojaks as I could, only around 250, which wasn't enough to train ImageNetv2 reliably. It was also hard to account for the random negatives that show up on forums since there's no consistent theme.
- Maximum Dynamo query return: DynamoDB queries cap out at 1MB, which I'd hit quickly if a user asked for data across a large timestamp range. That much data could also tank the Lambda instance, so I needed a way to limit how much was returned per request.
- Rendering highs and lows: financial charts usually show activity over a period, but my earliest data model only stored the index value per period, missing the highs and lows we take for granted on financial charts.
Solutions
- Reliable image classification: instead of training a model like ImageNetv2, OpenAI's CLIP lets you 'zero shot' images by writing prompts for positive and negative cases. The model weighs how well each image matches each prompt, and you accept it as a positive case above a confidence threshold. Results were much more accurate than ImageNetv2 and still ran on a lightweight Lambda instance.
- Maximum Dynamo query return: DynamoDB returns a
LastEvaluatedKeyfield, the PK of the last row scanned before the limit was reached, giving a starting point for the next scan. I wrapped this in the API response and extended the GET endpoint's Pydantic model to let users start their next request from that key. - Rendering highs and lows: this is a common pattern called 'bucketing', siloing values over a period of time to run logic over them. Since I wanted this to update in real time rather than on a cron, I had to do it as data comes in: floor each new reading to its hour or day bucket, check for existing values, and overwrite the high/low if needed.
Technologies
- FastAPI (Python)
- Next.js (Tailwind + React + Typescript)
- AWS (DynamoDB, S3, Cloudfront, Route53, Lambda, EventBridge)
- Pytorch (OpenAI CLIP)
- Terraform
Highlights
- Working public api
- Automated forum scraper updating index value every 15 minutes
- OpenAI CLIP zero shot image classifier
- Image caching to reduce Lambda costs