--- license: mit language: - en base_model: - google-t5/t5-small pipeline_tag: text-generation library_name: transformers tags: - text2text-generation - LoRA - t5 - recipe - cooking - fine-tuning --- # 🍳 Recipe Card Generator (T5-small + LoRA merged) This model generates **recipe cards** (title, ingredients, and step-by-step directions) from a list of ingredients. It is fine-tuned from [`t5-small`](https://huggingface.co/t5-small) using [LoRA adapters](https://huggingface.co/docs/peft/index) and merged into a standalone checkpoint. --- ## ✨ Model Details - **Base model**: `t5-small` - **Fine-tuning method**: LoRA (rank=16, α=32, dropout=0.05, query/value projection layers) - **Dataset**: Custom JSONL (`input_text`, `target_text` pairs), originally prepared from a Kaggle recipe dataset. - **Task**: Text-to-Text Generation --- ## 📥 Usage ```python from transformers import T5ForConditionalGeneration, T5TokenizerFast tok = T5TokenizerFast.from_pretrained("MahmutCanBoran/t5-recipe-card-en-lora-merged") model = T5ForConditionalGeneration.from_pretrained("MahmutCanBoran/t5-recipe-card-en-lora-merged").eval() prompt = "STRICT=yes | Ingredients: 1 cup sugar, 2 cups flour, 1/2 cup butter" enc = tok(prompt, return_tensors="pt") out = model.generate( **enc, max_new_tokens=160, num_beams=4, length_penalty=0.8, no_repeat_ngram_size=3 ) print(tok.decode(out[0], skip_special_tokens=True)) 🔍 Example Input: STRICT=yes | Ingredients: 1 cup milk, 2 eggs, 1 cup flour Output: Title: Pancakes Ingredients: - 1 cup milk - 2 eggs - 1 cup flour Directions: 1. Whisk eggs and milk. 2. Add flour slowly. 3. Cook on pan. Time: 20-60 minutes Servings: 4 ## 🚀 Features - **Input**: Raw ingredient list (e.g., `"chicken breast, yogurt, garlic, salt, pepper"`). - **Output**: Structured **recipe card** with: - Title suggestion 📝 - Ingredients (cleaned + normalized) 🧂 - Step-by-step cooking instructions 🍲 - Optional serving tips 🍽️ - Supports **strict** and **flexible** generation modes: - `STRICT=yes` → Uses **only** given ingredients - `STRICT=no` → Allows creative variations --- ## ⚙️ Installation ```bash # Clone repo git clone https://github.com//recipe-card-t5-lora.git cd recipe-card-t5-lora # Create environment python -m venv venv source venv/bin/activate # (Windows: venv\Scripts\activate) # Install dependencies pip install -r requirements.txt pip install transformers peft torch from transformers import pipeline pipe = pipeline("text2text-generation", model="MahmutCanBoran/t5-recipe-card-en-lora-merged") ⚠️ Limitations Time/Servings fields are currently fixed values (20-60 minutes, Servings: 4). Model may hallucinate instructions if STRICT=no mode is used (future work: add dataset with variable strictness). Optimized for English outputs.