Skip to content

About

LLM news classification + entity extraction, scored against ground truth with field-level F1. GPT-4o vs DeepSeek, with retries and reliability runs

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

LLM News Classification & Extraction Eval

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?

What it does

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

Engineering details

  • Schema-validated outputs: responses are parsed into Pydantic models; malformed JSON is recovered from fenced or partial output before validation
  • Deterministic eval: temperature=0 so 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 = True and NUM_EVALUATION_RUNS > 1 to run each article N times and measure output consistency

Run it

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

Adding articles

  1. Drop a text file next to the script (e.g. news-article-5.txt)
  2. Add it to ARTICLE_FILES in classification.py
  3. Add its labels to GROUND_TRUTH_DATA to include it in the accuracy scores

Stack

Python · OpenAI SDK (GPT-4o, and DeepSeek via its OpenAI-compatible API) · Pydantic · Poetry

About

LLM news classification + entity extraction, scored against ground truth with field-level F1. GPT-4o vs DeepSeek, with retries and reliability runs

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages