Spaces:
Sleeping
A newer version of the Gradio SDK is available: 6.14.0
title: FoodExtract v1
emoji: π
colorFrom: yellow
colorTo: red
sdk: gradio
sdk_version: 5.0.0
app_file: app.py
pinned: false
license: mit
python_version: '3.11'
short_description: Extract food & drinks from text with Gemma 3
π Fully Fine-Tune a Small Language Model (Gemma 3 270M)
A tutorial on how to fully fine-tune Google's Gemma 3 270M model using Hugging Face libraries to extract food and drink items from text.
π Overview
This project demonstrates Supervised Fine-Tuning (SFT) of a Small Language Model (SLM) for a specific task: extracting food and drink items from text. The fine-tuned model can process text inputs and return structured data about food/drink content.
Why Fine-tune a Small Language Model?
- β Own the model - Run anywhere without API costs
- β Simple tasks work well with smaller models
- β No API calls needed - Run offline
- β Batch processing - Much faster than API calls
- β Task-specific optimization - Better performance on your use case
π― What We're Building
A model that extracts food and drink items from text, returning structured output:
Input:
A plate of rice cakes, salmon, cottage cheese and small cherry tomatoes with a cup of tea.
Output:
food_or_drink: 1
tags: fi
foods: rice cakes, salmon, cottage cheese, cherry tomatoes
drinks: cup of tea
π οΈ Technologies Used
- Model: Gemma 3 270M
- Dataset: FoodExtract-1k
- Libraries:
transformers- Model loading and inferencetrl- Transformers Reinforcement Learning (SFT)datasets- Data loadingaccelerate- Training accelerationgradio- Interactive demo
π Requirements
- Python 3.8+
- GPU with at least 16GB VRAM (Google Colab T4 works!)
- Hugging Face account (for uploading model)
π Quick Start
1. Open in Google Colab
2. Enable GPU Runtime
- Go to
RuntimeβChange runtime typeβ SelectGPU
3. Run All Cells
The notebook will:
- Install dependencies
- Load the base model
- Prepare the dataset
- Fine-tune (3 epochs, ~18 minutes)
- Evaluate and create demo
π Training Results
After 3 epochs of training:
| Epoch | Training Loss | Validation Loss | Token Accuracy |
|---|---|---|---|
| 1 | 2.17 | 2.24 | 58.8% |
| 2 | 1.25 | 2.28 | 58.9% |
| 3 | 1.07 | 2.46 | 58.6% |
π Key Concepts
Full Fine-Tuning vs LORA
- Full Fine-Tuning: All model weights updated (used here)
- LORA: Only adapter weights trained (less resources needed)
SLM (Small Language Model)
- Models under 1B parameters
- Great for specific tasks
- Can be tailored for your use case
Tokens In, Tokens Out
- Think of any problem as: What tokens do I want in, and what tokens do I want out?
π Project Structure
βββ NVIDIA-DGX-Spark-hugging_face_llm_full_fine_tune_tutorial-VIDEO.ipynb
βββ README.md
βββ .gitignore
βββ Fully Fine-Tune a SLM-Gemma 3 270M.pdf (reference)
π₯ Video Tutorial
Watch the full video walkthrough
π Resources
- Original Notebook Source
- Hugging Face Transformers
- TRL Documentation
- Gemma 3 270M Model
- FoodExtract-1k Dataset
π·οΈ Tags Dictionary
The model assigns these tags to text:
| Tag | Meaning |
|---|---|
| np | Nutrition Panel |
| il | Ingredient List |
| me | Menu |
| re | Recipe |
| fi | Food Items |
| di | Drink Items |
| fa | Food Advertisement |
| fp | Food Packaging |
π License
This project is for educational purposes. Please refer to the original sources for licensing information.
π€ Author
Created following the tutorial by Daniel Bourke
Note: The model weights are not included in this repository. You can either:
- Run the notebook to create your own fine-tuned model
- Download from Hugging Face Hub if available