Views
No views yet
bert-base-uncased for
multi-label news topic classification using Asymmetric Loss (ASL, ICCV 2021).
ASL suppresses easy-negative gradients (γ⁻=4, γ⁺=1, margin=0.15), which helps
on the long tail of rare topic codes.| Base model | bert-base-uncased |
| Task | Multi-label classification |
| Loss | Asymmetric Loss (γ⁺=1, γ⁻=4, margin=0.15) |
| Number of labels | 126 topic codes |
| Max input length | 256 tokens (title + body) |
| Best val micro-F1 | ~0.844 |
1from transformers import BertForSequenceClassification, AutoTokenizer
2import torch
3
4tokenizer = AutoTokenizer.from_pretrained("chiunhau/news-classifier-2")
5model = BertForSequenceClassification.from_pretrained("chiunhau/news-classifier-2")
6model.eval()
7
8title = "Finland wins gold in ice hockey."
9text = "The Finnish national team claimed victory in the final."
10inputs = tokenizer(title, text, return_tensors="pt",
11 truncation=True, max_length=256)
12with torch.no_grad():
13 logits = model(**inputs).logits
14
15threshold = 0.5
16probs = logits.sigmoid().squeeze()
17predicted = [model.config.id2label[i]
18 for i, p in enumerate(probs) if p > threshold]
19print("Topics:", predicted)title + text fields, separated by the tokenizer's [SEP] token.sigmoid() and threshold at 0.5 for binary predictions.chiunhau/news-classifier-1) uses standard Binary Cross-Entropy and
achieves slightly higher overall micro-F1.