harbor run -t LiteCoder/ag-news-topic-classifierharbor download LiteCoder/ag-news-topic-classifierBuild a CPU-only, end-to-end text-classification pipeline that trains a model on the AG News dataset, evaluates it on the held-out test set, persists artifacts, and serves batch predictions via a CLI tool. Everything must be implemented in Python.
/app/
├── requirements.txt
├── train.py
├── predict.py
├── model/
│ ├── model.joblib
│ └── vectorizer.joblib
└── data/
├── train.csv
└── test.csv
The AG News dataset must be downloaded and stored under /app/data/. The dataset has 4 classes:
| Label | Topic |
|---|---|
| 1 | World |
| 2 | Sports |
| 3 | Business |
| 4 | Sci/Tech |
Each CSV row contains: label, title, description. The train split has 120,000 samples and the test split has 7,600 samples.
/app/train.py)Running python /app/train.py must:
/app/data/.title and description into a single text field for each sample.random_state=42 wherever randomness is involved for reproducibility.{
"test_accuracy": 0.XX,
"num_train_samples": 120000,
"num_test_samples": 7600,
"num_classes": 4,
"classes": ["World", "Sports", "Business", "Sci/Tech"]
}
test_accuracy must be a float rounded to 4 decimal places.test_accuracy of at least 0.88 on the AG News test set./app/model/model.joblib and the TF-IDF vectorizer to /app/model/vectorizer.joblib./app/predict.py)Running the CLI must load the persisted artifacts from /app/model/ and classify input text.
Usage:
python /app/predict.py --input /app/input.json --output /app/output.json
Input format (/app/input.json): A JSON array of objects, each with an "id" (integer) and "text" (string):
[
{"id": 1, "text": "NASA launches new Mars rover mission"},
{"id": 2, "text": "Stock market hits record high amid economic growth"},
{"id": 3, "text": "World Cup final draws millions of viewers worldwide"}
]
Output format (/app/output.json): A JSON array of objects with "id", "predicted_label" (integer 1-4), and "predicted_topic" (string from the label mapping above):
[
{"id": 1, "predicted_label": 4, "predicted_topic": "Sci/Tech"},
{"id": 2, "predicted_label": 3, "predicted_topic": "Business"},
{"id": 3, "predicted_label": 2, "predicted_topic": "Sports"}
]
[]), the output must also be []./app/requirements.txt must list all required pip packages, one per line.