Views
No views yet
1Input : "Steamed fermented rice and lentil cake, soft and fluffy, low fat."
2Output : "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 |
1import torch
2from transformers import AutoTokenizer, AutoModelForCausalLM
3from peft import PeftModel
4
5BASE_MODEL = "distilgpt2"
6FINETUNED_MODEL = "asolinxavier/nutrition-calorie-predictor-v2"
7
8tokenizer = AutoTokenizer.from_pretrained(BASE_MODEL)
9base_model = AutoModelForCausalLM.from_pretrained(BASE_MODEL)
10model = PeftModel.from_pretrained(base_model, FINETUNED_MODEL)
11model.eval()
12
13def predict_calories(food_description: str) -> str:
14 prompt = (
15 f"How many calories are in 100g of this food?\n\n"
16 f"{food_description}\n\n"
17 f"Calories per 100g: "
18 )
19 inputs = tokenizer(prompt, return_tensors="pt")
20 with torch.no_grad():
21 outputs = model.generate(
22 **inputs,
23 max_new_tokens=10,
24 do_sample=False,
25 pad_token_id=tokenizer.eos_token_id,
26 )
27 decoded = tokenizer.decode(outputs[0], skip_special_tokens=True)
28 return decoded.split("Calories per 100g:")[-1].strip().split()[0]
29
30# Test it!
31print(predict_calories("Steamed fermented rice and lentil cake, soft and fluffy."))
32# 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 + chartsScannerAgent → 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