--- language: en license: apache-2.0 library_name: transformers tags: - text-classification - bert - ag-news - news-classification - pytorch - transformers - nlp datasets: - ag_news metrics: - accuracy - f1 pipeline_tag: text-classification model-index: - name: ag-news-bert-classifier results: - task: type: text-classification name: News Topic Classification dataset: name: AG News type: ag_news split: test metrics: - type: accuracy value: 0.947 name: Test Accuracy - type: f1 value: 0.94 name: Macro F1 --- # AG News BERT Classifier Fine-tuned :contentReference[oaicite:1]{index=1} model for 4-class news topic classification using the :contentReference[oaicite:2]{index=2} dataset. The model classifies news articles into: - World - Sports - Business - Sci/Tech --- # Model Details | Property | Value | |---|---| | Base Model | `bert-base-uncased` | | Task | Text Classification | | Framework | PyTorch + Transformers | | Dataset | AG News | | Classes | 4 | | Test Accuracy | 94.7% | | Macro F1 | 0.94 | --- # Label Mapping | ID | Label | |---|---| | 0 | World | | 1 | Sports | | 2 | Business | | 3 | Sci/Tech | --- # Training Configuration | Parameter | Value | |---|---| | Epochs | 3 | | Batch Size | 16 | | Learning Rate | 2e-5 | | Max Sequence Length | 128 | | Warmup Steps | 500 | | Optimizer | AdamW | | Weight Decay | 0.01 | | LR Scheduler | Linear Warmup + Linear Decay | | Gradient Clipping | Max Norm = 1.0 | --- # Dataset Information | Split | Samples | |---|---| | Train | 120,000 | | Test | 7,600 | Dataset source: :contentReference[oaicite:3]{index=3} --- # Performance ## Classification Report | Class | Precision | Recall | F1-Score | |---|---|---|---| | World | 0.97 | 0.95 | 0.96 | | Sports | 0.98 | 0.99 | 0.99 | | Business | 0.92 | 0.91 | 0.92 | | Sci/Tech | 0.91 | 0.93 | 0.92 | --- # Usage ## Install ```bash pip install transformers torch ``` ## Inference ```python from transformers import pipeline classifier = pipeline( "text-classification", model="theshekslaw/ag_news_bert_full" ) result = classifier( "Apple announces new MacBook Pro with M3 chip" ) print(result) ``` Example output: ```python [{'label': 'Sci/Tech', 'score': 0.9895}] ``` --- # Example Predictions | Text | Prediction | |---|---| | Apple announces new MacBook Pro with M3 chip | Sci/Tech | | Federal Reserve raises interest rates | Business | | UN calls for ceasefire in ongoing conflict | World | | Real Madrid wins Champions League final | Sports | --- # Training Approach The model was fine-tuned using a custom PyTorch training loop instead of the Hugging Face `Trainer` API. Key components: - Dynamic padding with `DataCollatorWithPadding` - Linear learning-rate scheduling - AdamW optimizer - Mixed precision training (FP16) - GPU training on NVIDIA T4 --- # Limitations - The model is trained only on AG News categories. - It may struggle with: - ambiguous headlines - multi-topic articles - very short text - domain-specific financial or scientific jargon --- # Citation ```bibtex @misc{ag_news_bert_classifier, title={AG News BERT Classifier}, author={Abhishek Pandey}, year={2026}, publisher={Hugging Face} } ```