Downloads Β· 30 days
0
havvanur92/news-topic-classification-model
news-topic-classification-model is a text classification model from havvanur92. Use it when you need a label for a piece of text. It is set up for keras. The card lists the license as apache-2.0.
[](https://www.kaggle.com/datasets/amananandrai/ag-news-classification-dataset/data)
Downloads Β· 30 days
0
Access
Public
Updated Nov 24, 2025
Repo size
15.9 MB
Likes
0
Public
Click a slice to open those files.
.h515.9 MB Β· 100%
From the Hugging Face model README
The goal of this project is to build an RNN-based model that automatically classifies news articles from the AG News dataset into four predefined categories.
| Library | Purpose |
|---|---|
| numpy, pandas | Data manipulation and preprocessing |
| matplotlib, seaborn | Visualizations (plots, ROC curves, confusion matrix) |
| tensorflow / keras | Building, training, and tuning the RNN model |
| keras-tuner | Hyperparameter optimization (Random Search) |
| scikit-learn | Evaluation metrics (classification report, ROC, confusion matrix) |
π§ Environment: Kaggle Notebooks using the GPU T4 (Python 3.x, TensorFlow 2.x)
π§ Installation
If running locally, install dependencies with:
pip install numpy pandas matplotlib seaborn scikit-learn tensorflow keras-tuner
The AG News dataset contains news articles labeled into four main categories: World, Sports, Business, and Science/Technology. Each sample consists of a title and a short description, providing concise textual information for classification tasks.
π Source: AG News β Academic news search engine ComeToMyHead
π Categories: 4 predefined classes
π Files: train.csv and test.csv
π Content: Class index, title, and description
π’ Total Samples: 127,600 (120,000 training + 7,600 test)
The Title and Description fields were merged into a single text input and prepared for the RNN model using tokenization.
Process:
ποΈ The model uses a SimpleRNN structure to learn patterns from the text.
The model was trained using the Adam optimizer, gradient clipping for stability, and categorical crossentropy for multi-class classification.
To improve model performance, Random Search (via Keras Tuner) was used to find the best hyperparameters. βοΈπ The search optimized:
After the hyperparameter search, the tuner identified the best configuration, achieving a validation accuracy of 0.888.
Selected Hyperparameters:
After selecting the best hyperparameters, the final model wasevaluated on the test set.
Test Performance:
Accuracy: 0.8915
Loss: 0.3542
AUC: 0.9756
These results show that the model generalizes well across the four news categories.
ROC curves were plotted for each class using the predicted probabilities. They show how well the model distinguishes each category across different thresholds.
<img width="700" height="650" alt="image" src="https://github.com/user-attachments/assets/7c760bed-5617-48ce-bc45-b0076f092066" />Multi Class Roc Curve - Source
| Class | Precision | Recall | F1-Score | Support |
|---|---|---|---|---|
| World | 0.91 | 0.89 | 0.90 | 1900 |
| Sports | 0.95 | 0.95 | 0.95 | 1900 |
| Business | 0.84 | 0.89 | 0.87 | 1900 |
| Science | 0.89 | 0.86 | 0.87 | 1900 |
| Overall Accuracy | β | β | 0.90 | 7600 |
The model performs strongest on Sports and World, with slightly lower performance on Business and Science, which typically contain more overlapping terminology.
A confusion matrix was generated to visualize how well the model distinguishes between the four categories.
<img width="700" height="780" alt="image" src="https://github.com/user-attachments/assets/b9154848-44b9-416a-9b86-f881864d6df4" />