NewsLens
An explainable news-topic classifier. Paste an article and it returns the topic, ranked probabilities and the words that drove the decision — served by a production-style FastAPI backend.
- test accuracy
- 0.4%
- macro-F1
- 0.863
- held-out docs
- 2,282
- topics
- 6
model selection · 5-fold CV macro-F1
winner tuned with GridSearchCV (α = 0.3) · bars scaled 0.78 → 0.92
per-class F1 · test set
def _keywords(self, row, class_idx: int, top_n: int) -> list[dict]:
"""Terms in the input that pushed the prediction towards the class."""
if self._weights is None or row.nnz == 0:
return []
contrib = row.data * self._weights[class_idx, row.indices]
order = np.argsort(contrib)[::-1][:top_n]
return [{"term": str(self.vocabulary[row.indices[i]]),
"weight": round(float(contrib[i]), 4)}
for i in order if contrib[i] > 0]
rest api · /api/v1
- GET/health
- GET/model
- POST/predict
- POST/predict/batch
- GET/history
- DEL/history
- GET/stats
Batch inference · prediction history & stats · non-root Docker image with healthcheck · tests run without downloading the dataset.