Fine-Tuned DistilBERT for Food vs Not Food Classification
A fine-tuned DistilBERT-base-uncased model for binary text classification that predicts whether a sentence refers to food or not food.
Model Description
This model was fine-tuned on a synthetic Food vs Not Food dataset generated using Large Language Models (LLMs).
The objective is to classify a given text input into one of two categories:
- food → Text refers to food, meals, beverages, ingredients, or edible items.
- not_food → Text refers to non-edible objects, places, activities, concepts, or entities.
The model is intended as an educational and experimental NLP project demonstrating the complete workflow of:
- Synthetic dataset generation
- Dataset preparation using Hugging Face Datasets
- Tokenization with DistilBERT Tokenizer
- Fine-tuning using Hugging Face Transformers
- Model evaluation and deployment on Hugging Face Hub
Base Model
This model is fine-tuned from:
distilbert-base-uncased
DistilBERT is a lightweight Transformer model that retains much of BERT's language understanding capability while requiring fewer parameters and faster inference.
Dataset
The model was trained on:
Food vs Not Food Synthetic Dataset
Dataset Link:
The dataset consists of text samples labeled as:
| Label | Description |
|---|
| food | Sentence refers to an edible item |
| not_food | Sentence refers to a non-edible item |
Example Inputs
Food
- "A slice of pepperoni pizza."
- "Fresh orange juice was served."
- "The chef prepared vegetable biryani."
Not Food
- "The laptop screen is cracked."
- "A red bicycle is parked outside."
- "The meeting starts at 2 PM."
Intended Uses
This model can be used for:
- Binary text classification
- NLP learning projects
- Hugging Face fine-tuning demonstrations
- Dataset validation experiments
- Educational purposes
Training Procedure
Preprocessing
- Tokenizer: DistilBERT Tokenizer
- Truncation enabled
- Padding applied during batching
Fine-Tuning
The model was fine-tuned using the Hugging Face Transformers Trainer API.
Training notebook:
Project repository:
Usage
Framework versions
- Transformers 5.0.0
- Pytorch 2.11.0+cu128
- Datasets 4.0.0
- Tokenizers 0.22.2
Load Model
1from transformers import pipeline
2
3classifier = pipeline(
4 "text-classification",
5 model="ashutosh-kedar/finetuned_distil_bert_food_not_food_classification_model"
6)
7
8result = classifier("A bowl of hot tomato soup.")
9print(result)
Example Output
1[
2 {
3 'label': 'food',
4 'score': 0.99
5 }
6]
Limitations
- The model was trained on a synthetic dataset.
- Real-world performance may differ from benchmark results.
- Predictions are limited to the binary categories food and not_food.
- Performance may degrade on ambiguous or context-dependent sentences.
Author
Ashutosh Kedar
This project demonstrates the complete NLP pipeline from synthetic dataset creation to Transformer model fine-tuning and deployment using the Hugging Face ecosystem.
Training procedure
Training hyperparameters
The following hyperparameters were used during training:
- learning_rate: 0.0001
- train_batch_size: 32
- eval_batch_size: 32
- seed: 42
- optimizer: Use OptimizerNames.ADAMW_TORCH_FUSED with betas=(0.9,0.999) and epsilon=1e-08 and optimizer_args=No additional optimizer arguments
- lr_scheduler_type: linear
- num_epochs: 10
Training results
| Training Loss | Epoch | Step | Validation Loss | Accuracy |
|---|
| 0.4674 | 1.0 | 7 | 0.2076 | 1.0 |
| 0.1237 | 2.0 | 14 | 0.0151 | 1.0 |
| 0.0105 | 3.0 | 21 | 0.0202 | 0.98 |
| 0.0026 | 4.0 | 28 | 0.0024 | 1.0 |
| 0.0013 | 5.0 | 35 | 0.0008 | 1.0 |
| 0.0009 | 6.0 | 42 | 0.0006 | 1.0 |
| 0.0007 | 7.0 | 49 | 0.0005 | 1.0 |
| 0.0006 | 8.0 | 56 | 0.0005 | 1.0 |
| 0.0006 | 9.0 | 63 | 0.0005 | 1.0 |
| 0.0006 | 10.0 | 70 | 0.0004 | 1.0 |