A lightweight NLP model that reads any sentence and determines whether it's talking about food or not — returning a label and a confidence score. Simple premise. Real ML pipeline.
"I love pizza on Friday nights"
"The stock market dropped today"
A clean end-to-end pipeline from pre-trained foundation model through fine-tuning to hosted, interactive deployment.
01
DistilBERT (base, uncased)
pre-trained foundation
02
Fine-tuning
Hugging Face Trainer API
03
Sequence Classification Head
Food / Not Food
04
Hosted Model
Hugging Face Hub
05
Gradio Demo
Hugging Face Spaces
DistilBERT is a distilled (compressed) version of BERT — retaining ~97% of its language understanding at 40% fewer parameters and 60% faster inference.
97%
Language understanding retained vs. BERT
40%
Fewer parameters than BERT
60%
Faster inference speed
distilbert/distilbert-base-uncased
Rather than training from scratch, this project uses transfer learning — taking a model already pre-trained on massive text corpora (Wikipedia, BookCorpus) and adapting it to a specific binary classification task.
Hyperparameters
| Parameter | Value |
|---|---|
| Learning Rate | 2e-05 |
| Optimizer | AdamW (fused) — β=(0.9, 0.999), ε=1e-08 |
| LR Scheduler | Linear decay |
| Train Batch Size | 32 |
| Eval Batch Size | 32 |
| Epochs | 10 |
| Seed | 42 |
Training Results
| Epoch | Train Loss | Val Loss | Accuracy | F1 |
|---|---|---|---|---|
| 1 | 0.3420 | 0.2034 | 1.0 | 1.0 |
| 2 | 0.2167 | 0.1099 | 1.0 | 1.0 |
| 3 | 0.0960 | 0.0430 | 1.0 | 1.0 |
| 5 | 0.0246 | 0.0154 | 1.0 | 1.0 |
| 8 | 0.0124 | 0.0093 | 1.0 | 1.0 |
| 10 ★ | 0.0112 | 0.0087 | 1.0 | 1.0 |
The model reached perfect accuracy on the validation set by epoch 1 and continued refining its confidence through all 10 epochs, with training and validation loss steadily converging toward near-zero.
Built and deployed as a Gradio app on Hugging Face Spaces — no backend required, no server to manage.
How it works
Live on Hugging Face Spaces
No setup required. Open the demo, type a sentence, and see the classifier run in real time.
Open Live Demo →With a Pipeline — Easiest
Pythonfrom transformers import pipeline
classifier = pipeline(
"text-classification",
model="DayWalker2226/learn_hf_food_not_food_text_classifier-distilbert-base-uncased"
)
result = classifier("I had tacos for dinner last night")
# → [{'label': 'Food', 'score': 0.999}]
Loading the Model Directly
Pythonfrom transformers import AutoTokenizer, AutoModelForSequenceClassification
tokenizer = AutoTokenizer.from_pretrained(
"DayWalker2226/learn_hf_food_not_food_text_classifier-distilbert-base-uncased"
)
model = AutoModelForSequenceClassification.from_pretrained(
"DayWalker2226/learn_hf_food_not_food_text_classifier-distilbert-base-uncased"
)
End-to-end ML workflow
On Hugging Face: from dataset → tokenization → fine-tuning → model hub → live demo. The full pipeline in one project.
Transfer learning in practice
How pre-trained weights dramatically reduce the data and compute needed for task-specific performance.
Hugging Face Trainer API
Managing hyperparameters, evaluation loops, and logging with minimal boilerplate.
Gradio + Spaces
Spinning up a shareable, interactive ML demo without writing a backend — zero deployment overhead.
Model cards and versioning
Publishing reproducible, documented model artifacts that others can build on.