Instructions to use Potatodawang/fox-nbc-headline-classifier with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- fastText
How to use Potatodawang/fox-nbc-headline-classifier with fastText:
from huggingface_hub import hf_hub_download import fasttext model = fasttext.load_model(hf_hub_download("Potatodawang/fox-nbc-headline-classifier", "model.bin")) - Notebooks
- Google Colab
- Kaggle
Fox News vs NBC News headline classifier (CIS 4190/5190, Track B)
Predicts whether a news link comes from Fox News or NBC News from its headline words alone,
for example /biden-signs-infrastructure-bill. Code, training scripts and report:
https://github.com/EvelynGao233/519. Training data: Potatodawang/fox-nbc-headline-links.
Every folder holds the course leaderboard's three files: model.py, preprocess.py, model.pt.
All models are plain PyTorch with fixed tensor shapes and run on CPU without transformers.
| Folder | Model | val20 accuracy (unseen headlines) | model.pt |
|---|---|---|---|
final/ |
Equal-weight ensemble of the three below (our submission) | 89.9% | 285 MB |
tfidf/ |
Hashed TF-IDF (word 1β3, char 1β5 grams, length) + logistic regression | 88.5% | 16 MB |
fasttext/ |
Hashed sub-word EmbeddingBag (64-d) + 128-unit MLP | 88.4% | 134 MB |
distilbert/ |
distilbert-base-uncased fine-tuned 1.5 epochs, re-implemented in plain PyTorch with its WordPiece tokenizer |
88.5% | 134 MB |
The provided baseline scores 73.9% on the same split. The submitted ensemble scored 96.09% on the course leaderboard (8,000 hidden links; 96.34% before the teammate links were added); the leaderboard is higher than val20 because many test headlines also appear in the public sitemaps we trained on. No model here looks up training headlines.
Usage
import importlib.util, torch
def load(folder):
spec = importlib.util.spec_from_file_location("m", f"{folder}/model.py")
m = importlib.util.module_from_spec(spec); spec.loader.exec_module(m)
model = m.Model()
model.load_state_dict(torch.load(f"{folder}/model.pt", map_location="cpu"))
return model.eval()
model = load("final")
print(model.predict(["biden signs infrastructure bill", "patrick mahomes fiery message win bills"]))
# ['NBC', 'FoxNews']
preprocess.prepare_data(csv_path) turns a CSV with a url column into these lowercase headline
strings, reducing full links exactly as the leaderboard does.
Training
About 639k headlines: the course's links plus links scraped from both outlets' sitemaps (Fox News
2022+, NBC News 2015+) and teammate-collected Fox live-news links, with every val20 headline removed
(the submitted TF-IDF model is refit on all of them, val20 included). TF-IDF: liblinear logistic regression, C = 10.
DistilBERT was trained before the teammate links were added (637k headlines).
fastText network: SparseAdam/Adam, lr 1e-2 with linear decay, batch 256, best of 6 epochs on val20.
DistilBERT: AdamW 5e-5, batch 256, 6% warm-up, fp16, max 64 tokens, best checkpoint of 2 epochs on
a Colab T4. Training histories are in fasttext/train_history.json and distilbert/bert_history.json.
Limitations
val20 holds 959 links (one standard error is about one point), and epochs were picked on it. Fox News changed its URL style around 2022 (older slugs keep function words), so the models partly learn link style and do poorly on Fox links from 2014β2021.
- Downloads last month
- -