taljindergill78/indian-recipe-llama3.2-qlora
Indian Recipe Generator — LLaMA 3.2-3B QLoRA Fine-Tune
A QLoRA fine-tuned version of meta-llama/Llama-3.2-3B-Instruct trained on 3,263 authentic Indian recipes. Given a dish name, diet type, and regional cuisine, the model generates a structured recipe with a full ingredients list and step-by-step cooking instructions.
Model Description
The base LLaMA 3.2-3B-Instruct model has general language understanding but no domain-specific knowledge of Indian cuisine — it hallucinates ingredients, misses regional cooking techniques, and produces generic Western-style recipe formats. This fine-tune teaches the model:
- Ingredient vocabulary: turmeric, asafoetida, methi, kasuri methi, hing, and 200+ other ingredients common in Indian cooking
- Regional variation: North Indian, South Indian, Bengali, Gujarati, Rajasthani, and other regional cuisines each have distinct flavor profiles and techniques
- Diet-aware generation: Vegetarian, Non-Vegetarian, and Vegan recipe variants
- Structured output format: bold-header format with
**Ingredients:**and**Instructions:**sections, matching the training data format
Intended Use
Intended for:
- Generating authentic Indian recipes from a dish name + diet + region prompt
- Portfolio demonstration of end-to-end LLM fine-tuning with QLoRA
Not intended for:
- Medical or dietary advice
- Production food safety applications
- Real-time serving without GPU (CPU inference is very slow for a 3B model)
How to Use
from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
from peft import PeftModel
import torch
# Step 1: Load base model with 4-bit quantization
bnb_config = BitsAndBytesConfig(
load_in_4bit=True,
bnb_4bit_quant_type="nf4",
bnb_4bit_compute_dtype=torch.bfloat16,
bnb_4bit_use_double_quant=True,
)
base_model = AutoModelForCausalLM.from_pretrained(
"meta-llama/Llama-3.2-3B-Instruct",
quantization_config=bnb_config,
device_map="auto",
)
# Step 2: Load the LoRA adapter on top
model = PeftModel.from_pretrained(base_model, "taljindergill78/indian-recipe-llama3.2-qlora")
model.eval()
# Step 3: Load the tokenizer (stored alongside adapter for convenience)
tokenizer = AutoTokenizer.from_pretrained("taljindergill78/indian-recipe-llama3.2-qlora")
# Step 4: Generate a recipe
def generate_recipe(dish_name, diet="Vegetarian", region="North Indian"):
messages = [
{
"role": "system",
"content": (
"You are an expert Indian chef. Generate authentic Indian recipes "
"with detailed ingredients and clear step-by-step cooking instructions."
),
},
{
"role": "user",
"content": f"Generate a {diet} {region} recipe for {dish_name}",
},
]
text = tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=True
)
inputs = tokenizer(text, return_tensors="pt").to(model.device)
input_len = inputs["input_ids"].shape[1]
with torch.inference_mode():
output_ids = model.generate(
**inputs,
max_new_tokens=768,
do_sample=True,
temperature=0.7,
top_p=0.9,
repetition_penalty=1.3, # prevents ingredient repetition loops
)
new_tokens = output_ids[0, input_len:]
return tokenizer.decode(new_tokens, skip_special_tokens=True).strip()
# Example
print(generate_recipe("Dal Makhani"))
print(generate_recipe("Dosa", diet="Vegetarian", region="South Indian"))
print(generate_recipe("Chicken Biryani", diet="Non Vegetarian", region="Hyderabadi"))Hardware requirements: GPU with ≥8GB VRAM recommended (A100 / T4 / RTX 3080+). Loads as ~3GB with 4-bit quantization.
Training Data
Fine-tuned on 3,263 Indian recipes from the Anupam007/indian-recipe-dataset (originally scraped from archanaskitchen.com).
Dataset split used for training:
- Train: 3,263 recipes
- Validation: 250 recipes (used for per-epoch eval_loss during training)
- Test: 500 recipes (held out; used for final evaluation metrics below)
Filtering applied: The raw dataset contains ~5,938 rows including Continental, Italian, and other non-Indian cuisines. Only rows tagged as Indian cuisine were retained.
Prompt format: Each training example uses the chat template format:
System: You are an expert Indian chef...
User: Generate a {diet} {region} recipe for {dish_name}
Assistant: **{recipe_name}**\n\n**Ingredients:**\n...\n\n**Instructions:**\n...Loss was computed only on the assistant response tokens (loss masking via TRL's assistant_only_loss=True), so the model learns to generate recipes, not to repeat prompts.
Training Procedure
Method: QLoRA — 4-bit NF4 quantization of the base model (frozen) + LoRA adapters on the 7 projection layers of each transformer block
Hardware: NVIDIA A100-SXM4-80GB (RunPod Community Cloud) Training time: 28 minutes 16 seconds (612 steps) VRAM peak: 41 GB / 80 GB (52%)
Evaluation Results
All metrics computed on the full 500-row held-out test set (not seen during training or validation). Baselines use greedy decoding. Fine-tuned model uses nucleus sampling (do_sample=True, temperature=0.7, top_p=0.9, repetition_penalty=1.3, max_new_tokens=768). 95% bootstrap confidence intervals reported where available.
Before vs After Fine-Tuning
All metrics on the full 500-row held-out test set. Ingredient F1 uses name normalization (strips leading quantities and trailing prep notes such as "- to taste", "- finely chopped").
Fine-tuned model 95% CIs: Ingredient F1 [0.2942, 0.3166] · ROUGE-L [0.1802, 0.1872] · BERTScore [0.8503, 0.8524]
Ingredient F1 (2.85× improvement) is the primary signal that fine-tuning worked. The model learned Indian ingredient vocabulary — turmeric, asafoetida, methi, kasuri methi, poppy seeds, and 200+ other region-specific ingredients the base model had no training signal on. ROUGE-L is slightly lower than baseline (0.1835 vs 0.1954). Expected for a fine-tuned generative model: the fine-tuned model generates plausible, authentic recipes that differ in wording from the reference. ROUGE-L measures exact text overlap and penalizes creativity. BERTScore improved (+0.7%), confirming generated instructions are semantically more appropriate even when phrased differently. BERTScore up + ROUGE-L down is the healthy pattern for a creative generative model. BLEU improved 34% — solid n-gram overlap improvement on cooking instructions.
Prompt Ablation Study (Phase 5)
To confirm the production system prompt is a data-backed design choice (not intuition), three prompt variants were tested on 50 held-out recipes with identical model weights and generation config.
Variant A wins Ingredient F1 by +23.8% over B and +12.9% over C, confirming the detailed expert persona with regional culinary context gives the model the strongest signal for domain-specific ingredient selection. The production prompt is the correct choice.
Training Convergence (Validation Set, 250 recipes)
Best checkpoint: Epoch 3 (selected automatically by load_best_model_at_end=True).
Metric Definitions
- Ingredient F1: Set-overlap precision/recall/F1 on ingredient lists after name normalization (strips leading quantities and trailing prep notes like "- to taste"). Measures whether the model generates the correct Indian ingredients.
- ROUGE-L: Longest common subsequence overlap between generated and reference instructions. Measures structural similarity of cooking steps.
- BERTScore F1: Semantic similarity of instructions using RoBERTa embeddings. Measures whether the generated instructions mean the same thing even if worded differently.
- BLEU: N-gram precision of generated instructions against reference. Strict surface-form match — expected to be low for generative recipes.
Limitations
- Vocabulary bias: Training data is from a single source (archanaskitchen.com). Less common regional dishes (Northeastern Indian, tribal cuisines) are underrepresented.
- Quantity accuracy: Ingredient quantities may not always be correct for the number of servings generated.
- Hallucination: The model may occasionally generate plausible-sounding but incorrect steps for dishes it saw rarely in training.
- Language: English only. The training data is English-translated recipes.
- Format dependency: The model expects the exact system prompt and user message format shown in the usage example. Deviating from it may produce off-format outputs.
Repository
Training code, evaluation scripts, and full documentation: github.com/taljindergill78/AI-Indian-Recipe-Generator
Built as part of an end-to-end LLM fine-tuning portfolio project. MS Data Science, Arizona State University.
