Downloads · 30 days
0
asolinxavier/nutrition-calorie-predictor-v2
nutrition-calorie-predictor-v2 is a machine learning model from asolinxavier. Use it for the machine learning task on the model card, and read the license before you ship it in a product. The card lists the license as mit.
Fine-tuned distilgpt2 model that predicts calories per 100g from a food description.
Downloads · 30 days
0
Access
Public
Updated Jun 1, 2026
Repo size
2.4 MB
Likes
0
Public
Click a slice to open those files.
.json3.6 MB · 75%
From the Hugging Face model README
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
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)
| 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 |
| 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!
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"
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
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
Asolin Xavier
MIT License — free to use and modify.