Classifies news articles and extracts structured entities with LLMs, then scores the output against hand-labeled ground truth and compares two models (GPT-4o vs DeepSeek-Chat) head to head.
The point isn't the prompt, it's the measurement: how often does a model get the label right, how complete are its extracted entities, and how reliable is it under rate limits and retries?
For each article, the model returns JSON validated against a Pydantic schema:
| Task | Fields | Scored by |
|---|---|---|
| Classification | topic, sentiment, urgency (enums) |
exact match |
| Extraction | namesOfPeople, location, effects (lists) |
set-level F1 (precision × recall) |
| Extraction | day, event (strings) |
reported side by side |
Then it reports, per article and overall:
- accuracy vs. ground truth for each model
- agreement between the two models (exact-match rate, classification match, extraction F1)
- latency per model
- reliability: success rate, retries, and rate-limit events across repeated runs
- Schema-validated outputs: responses are parsed into Pydantic models; malformed JSON is recovered from fenced or partial output before validation
- Deterministic eval:
temperature=0so repeated runs measure the model, not sampling noise - Resilient API layer: exponential backoff with separate handling for rate limits, connection errors, and API errors
- Reliability mode: set
EVALUATION_MODE = TrueandNUM_EVALUATION_RUNS > 1to run each article N times and measure output consistency
Requires Python 3.9+ and Poetry.
poetry install
cp .env.example .env # add OPENAI_API_KEY and DEEPSEEK_API_KEY
poetry run python classification.py- Drop a text file next to the script (e.g.
news-article-5.txt) - Add it to
ARTICLE_FILESinclassification.py - Add its labels to
GROUND_TRUTH_DATAto include it in the accuracy scores
Python · OpenAI SDK (GPT-4o, and DeepSeek via its OpenAI-compatible API) · Pydantic · Poetry