UltraBERT-380M · Turkish News Topic Classifier (TRNEWS-2025)
thealper2/ultrabert-380m-turkish-news is dmis-lab/UltraBERT-380M — a 24-layer, 1024-wide, 32K-context English-pretrained bidirectional encoder — fully fine-tuned to classify Turkish news articles into 9 topics using the TRNEWS-2025 dataset.
Türkçe özet: Bu model, İngilizce ön eğitimli UltraBERT-380M encoder'ının TRNEWS-2025 veri setiyle tam fine-tuning edilmiş hâlidir. Haber gövdesini girdi olarak alır ve 9 kategoriden birini tahmin eder. Sınıf dengesizliği karekök tabanlı ters frekans ağırlıklı çapraz entropiyle ele alınmıştır. Olasılıklar kalibre edilmemiştir.
Results at a glance
Held-out test split (39,819 articles, never used for model selection or tuning):
| Accuracy | Macro-F1 | Weighted-F1 | Macro-Precision | Macro-Recall |
|---|---|---|---|---|
| 0.9604 | 0.9305 | 0.9602 | 0.9360 | 0.9254 |
Macro-F1 is the primary metric (every class counts equally); the checkpoint was selected by validation macro-F1.
Model details
| Base model | dmis-lab/UltraBERT-380M @ 7789071ca161 |
| Architecture | Pre-norm Transformer encoder, 24 layers, hidden 1024, 8 heads × 128, SwiGLU 3072, RMSNorm, RoPE (10,000 / 2,560,000), no biases, vocabulary 49,152 |
| Parameters | 377,546,761 total / 377,546,761 trainable |
| Attention | 16 local layers (±128-token window) and 8 global layers (pattern: local, local, global); SDPA kernels |
| Head | UltrabertForSequenceClassification: linear layer on the first-token hidden state (the tokenizer prepends `< |
| Fine-tuning | Full fine-tuning — all parameters trainable, no LoRA / no frozen layers |
| Task | Single-label, 9-way classification of Turkish news bodies |
| Max input length | 512 tokens (head truncation) |
| Language | Turkish (input); the base model was pre-trained on English only |
| License | CC BY-NC 4.0 (inherits the non-commercial dataset license; base model is Apache-2.0) |
Labels
| id | Label (TR) | English | Train examples | Loss weight |
|---|---|---|---|---|
| 0 | Bilim-Teknoloji | Science & Technology | 1,903 | 1.2532 |
| 1 | Finans-Ekonomi | Finance & Economy | 2,286 | 1.1434 |
| 2 | Kültür-Sanat | Culture & Arts | 2,908 | 1.0138 |
| 3 | Magazin | Entertainment / Celebrity | 19,708 | 0.3894 |
| 4 | Sağlık | Health | 2,985 | 1.0006 |
| 5 | Siyaset | Politics | 9,196 | 0.5701 |
| 6 | Spor | Sports | 8,195 | 0.6039 |
| 7 | Turizm | Tourism | 1,847 | 1.2721 |
| 8 | Çevre | Environment | 972 | 1.7535 |
How to use
The architecture ships as remote code, so trust_remote_code=True is required (the code is the unmodified UltraBERT modeling file from the base repo). Requires transformers>=5.
from transformers import pipeline
clf = pipeline("text-classification", model="thealper2/ultrabert-380m-turkish-news", trust_remote_code=True)
clf("Merkez Bankası politika faizini sabit tuttu.", truncation=True, max_length=512, top_k=3)
Manual inference with all class probabilities:
import torch
from transformers import AutoModelForSequenceClassification, AutoTokenizer
repo = "thealper2/ultrabert-380m-turkish-news"
tok = AutoTokenizer.from_pretrained(repo, trust_remote_code=True)
model = AutoModelForSequenceClassification.from_pretrained(repo, trust_remote_code=True).eval()
texts = ["Galatasaray deplasmanda 2-1 kazandı.", "Yeni aşı çalışmasının sonuçları açıklandı."]
enc = tok(texts, truncation=True, max_length=512, padding=True, return_tensors="pt")
with torch.inference_mode():
probs = model(**enc).logits.softmax(-1)
for p in probs:
print(model.config.id2label[int(p.argmax())], float(p.max()))
Keep padding_side="right" (the default): the classifier reads the first token.
Training data
Not available yet — this section is filled in automatically after make evaluate.
Training procedure
| Hyperparameter | Value |
|---|---|
| Epochs | 3 |
| Learning rate | 3e-05 |
| Optimizer | AdamW (fused), β=(0.9, 0.98), ε=1e-06 |
| Weight decay | 0.1 |
| Schedule | linear, 5% warm-up |
| Gradient clipping | 1.0 |
| Batch | 8 × 2 accumulation = 16 |
| Max length / padding | 512, dynamic padding, length-grouped sampling |
| Precision | bf16 autocast, fp32 master weights and AdamW states |
| Gradient checkpointing | off |
| Seed | 42 |
| Model selection | best validation macro-F1 over epochs (early-stopping patience 2) |
These follow the UltraBERT model card's fine-tuning recipe (AdamW β2=0.98, ε=1e-6, wd 0.1, linear schedule with 5% warm-up; the card reports 3e-5 as the best learning rate for UltraBERT-380M, which is used here). A controlled sweep over 5e-6 / 1e-5 / 5e-5 is reported under Controlled experiments below.
Class imbalance
Weighted cross-entropy with square-root inverse-frequency weights computed on the training split only: $w_c = n_c^{-1/2}$, normalised to mean 1. This boosts minority classes more gently than $1/n_c$. Loss reduction is PyTorch's weighted mean per micro-batch ($\sum_i w_{y_i},\mathrm{CE}i / \sum_i w{y_i}$), divided by the accumulation steps. No over/under-sampling.
Compute
- Hardware: 1 × NVIDIA GeForce RTX 5060 Ti (15.9 GiB), PyTorch 2.11.0+cu128, CUDA 12.8
- Training time: 2.26 h for 9,375 optimizer steps over 50,000 examples
- Peak GPU memory (allocated): 11.893 GiB

Evaluation
Per-class results (test split)
| Class | Precision | Recall | F1 | Support |
|---|---|---|---|---|
| Bilim-Teknoloji | 0.8701 | 0.8401 | 0.8548 | 1,507 |
| Finans-Ekonomi | 0.9744 | 0.9407 | 0.9573 | 1,822 |
| Kültür-Sanat | 0.8652 | 0.8641 | 0.8646 | 2,325 |
| Magazin | 0.9787 | 0.9814 | 0.9800 | 15,718 |
| Sağlık | 0.9659 | 0.9663 | 0.9661 | 2,377 |
| Siyaset | 0.9564 | 0.9701 | 0.9632 | 7,220 |
| Spor | 0.9828 | 0.9823 | 0.9826 | 6,571 |
| Turizm | 0.9266 | 0.9477 | 0.9370 | 1,492 |
| Çevre | 0.9038 | 0.8361 | 0.8686 | 787 |

Most frequent confusions (true → predicted):
- Kültür-Sanat → Magazin: 146 (6.3% of Kültür-Sanat)
- Magazin → Kültür-Sanat: 140 (0.9% of Magazin)
- Spor → Magazin: 81 (1.2% of Spor)
- Kültür-Sanat → Siyaset: 79 (3.4% of Kültür-Sanat)
- Bilim-Teknoloji → Kültür-Sanat: 77 (5.1% of Bilim-Teknoloji)
- Çevre → Siyaset: 68 (8.6% of Çevre)
Expected calibration error (15 bins): 0.0285. The probabilities are not calibrated — treat them as scores.
Controlled experiments
Ablations run on a fixed stratified 50k training subset (per-epoch selection on a fixed 10k validation subset, full test split); compare them with each other, not with the full-data model.
| experiment | train_samples | weighting | lr | max_length | val_macro_f1 | test_macro_f1 | test_accuracy | train_hours |
|---|---|---|---|---|---|---|---|---|
| weighted_lr_3e-5_n50000 | 50000 | sqrt_inverse | 0.0000 | 512 | 0.9252 | 0.9305 | 0.9604 | 2.26 |
Limitations and bias
- English base model. UltraBERT never saw Turkish during pre-training and its tokenizer fragments Turkish heavily. Topic cues are learned during fine-tuning on 50,000 articles; the model should not be taken as a general-purpose Turkish encoder. A Turkish-pretrained encoder may be stronger and is the natural baseline to compare with.
- Truncation. Only the first 512 tokens are read; because of the tokenizer this is roughly the first ? words.
- Source/label coupling. In TRNEWS-2025 labels largely follow the source site or its URL section; the model may learn outlet style rather than topic and can degrade on outlets not in the data. No domain-held-out evaluation was done.
- Near duplicates. Exact duplicates were removed and URL chunks grouped, but syndicated agency copies published under different URLs may still appear on both sides of the split, making test scores somewhat optimistic.
- Time. The crawl covers July–August 2025; topics drift and the date column is the crawl date, not publication date.
- Label set. 9 fixed topics; texts outside them (e.g. crime, weather, world news) are forced into one of the 9.
- Not for moderation, legal or other high-stakes decisions. Commercial use is not permitted by the dataset license.
Reproduction
make install # deps into ~/venv
make audit # data_audit.json / .md
make prepare # cleaning + URL-grouped 90/5/5 split + class weights
make smoke # tiny end-to-end run
make train # full fine-tuning (resume with: make resume)
make evaluate # test-set metrics, confusion matrix, predictions
make report card # experiment report + this model card
Citation
@misc{park2026ultrabert,
title = {UltraBERT: Beyond the Limit of BERT Pre-Training},
author = {Jungwoo Park and Taewhoo Lee and Jaewoo Kang},
year = {2026},
eprint = {2610.15028},
archivePrefix = {arXiv}
}
Dataset: TRNEWS-2025 by Kaggle user sengulbayrak (collected with students of BIM 432 – NLP, Istanbul Sabahattin Zaim University), https://www.kaggle.com/datasets/sengulbayrak/trnews-2025 — CC BY-NC 4.0.