๐Ÿฅ— Nutrition Calorie Predictor

Fine-tuned distilgpt2 model that predicts calories per 100g from a food description.

Built as part of the LLM Engineering Course โ€” Week 7 Capstone Project by @asolinxavier


๐ŸŽฏ What This Model Does

Give it a food description โ†’ it predicts calories per 100g.

Input  : "Steamed fermented rice and lentil cake, soft and fluffy, low fat."
Output : "58"  (kcal per 100g)

๐Ÿ—๏ธ Model Architecture

Property Value
Base Model distilgpt2 (82M parameters)
Fine-tuning Method QLoRA (Parameter Efficient Fine-Tuning)
Trainable Parameters 294,912 (only 0.36% of total!)
LoRA Rank (r) 16
LoRA Alpha 32
Target Module c_attn
Task Causal Language Modeling

๐Ÿ“Š Training Results

Epoch Train Loss Val Loss
1 5.383 0.022
2 0.003 0.014 โ† Best
5 0.001 0.031
10 0.000 0.036

Best Val Loss: 0.014 โœ…

Loss dropped from 5.38 โ†’ 0.003 โ€” the model learned dramatically!


๐Ÿฝ๏ธ Dataset

  • 85 foods total (Indian + Global)
  • 42 Indian foods: Idli, Dosa, Biryani, Paneer Butter Masala, Sambar...
  • 43 Global foods: Apple, Chicken Breast, Salmon, Oats...
  • Split: Train 57 | Val 7 | Test 8
  • Dataset: asolinxavier/nutrition_items

๐Ÿš€ How to Use

import torch
from transformers import AutoTokenizer, AutoModelForCausalLM
from peft import PeftModel

BASE_MODEL      = "distilgpt2"
FINETUNED_MODEL = "asolinxavier/nutrition-calorie-predictor-v2"

tokenizer  = AutoTokenizer.from_pretrained(BASE_MODEL)
base_model = AutoModelForCausalLM.from_pretrained(BASE_MODEL)
model      = PeftModel.from_pretrained(base_model, FINETUNED_MODEL)
model.eval()

def predict_calories(food_description: str) -> str:
    prompt = (
        f"How many calories are in 100g of this food?\n\n"
        f"{food_description}\n\n"
        f"Calories per 100g: "
    )
    inputs = tokenizer(prompt, return_tensors="pt")
    with torch.no_grad():
        outputs = model.generate(
            **inputs,
            max_new_tokens=10,
            do_sample=False,
            pad_token_id=tokenizer.eos_token_id,
        )
    decoded = tokenizer.decode(outputs[0], skip_special_tokens=True)
    return decoded.split("Calories per 100g:")[-1].strip().split()[0]

# Test it!
print(predict_calories("Steamed fermented rice and lentil cake, soft and fluffy."))
# Output: "58"

๐Ÿ—‚๏ธ Project Structure

Week 7/
โ”œโ”€โ”€ day1_qlora_setup.ipynb      โ† QLoRA concepts + environment setup
โ”œโ”€โ”€ day2_dataset_prep.ipynb     โ† Dataset preparation + HuggingFace push
โ”œโ”€โ”€ day3_4_training.ipynb       โ† QLoRA fine-tuning (training loop)
โ”œโ”€โ”€ day5_evaluation.ipynb       โ† Model evaluation + custom food testing
โ””โ”€โ”€ nutrition/
    โ”œโ”€โ”€ items.py                โ† NutritionItem data class
    โ””โ”€โ”€ evaluator.py            โ† Evaluation metrics + charts

๐Ÿ”ฎ Week 8 โ€” Multi-Agent Meal Planner (Next Steps)

This fine-tuned model will be used as the SpecialistAgent inside a 4-agent meal planning framework:

ScannerAgent   โ†’ Fetch recipes from TheMealDB API
NutritionAgent โ†’ Estimate calories (this model + Claude AI ensemble)
PlannerAgent   โ†’ Build personalised weekly meal plan
MessagingAgent โ†’ Send daily plan via Pushover notification

๐Ÿ‘ค Author

Asolin Xavier

  • HuggingFace: @asolinxavier
  • Project: Diet & Nutrition Planner โ€” LLM Engineering Course Week 7 & 8

๐Ÿ“„ License

MIT License โ€” free to use and modify.

Downloads last month

-

Downloads are not tracked for this model. How to track
Inference Providers NEW
This model isn't deployed by any Inference Provider. ๐Ÿ™‹ Ask for provider support