Views
No views yet
t5-small using LoRA adapters and merged into a standalone checkpoint.t5-smallinput_text, target_text pairs), originally prepared from a Kaggle recipe dataset.1from transformers import T5ForConditionalGeneration, T5TokenizerFast
2
3tok = T5TokenizerFast.from_pretrained("MahmutCanBoran/t5-recipe-card-en-lora-merged")
4model = T5ForConditionalGeneration.from_pretrained("MahmutCanBoran/t5-recipe-card-en-lora-merged").eval()
5
6prompt = "STRICT=yes | Ingredients: 1 cup sugar, 2 cups flour, 1/2 cup butter"
7enc = tok(prompt, return_tensors="pt")
8out = model.generate(
9 **enc,
10 max_new_tokens=160,
11 num_beams=4,
12 length_penalty=0.8,
13 no_repeat_ngram_size=3
14)
15print(tok.decode(out[0], skip_special_tokens=True))
16
17🔍 Example
18
19Input:
20
21STRICT=yes | Ingredients: 1 cup milk, 2 eggs, 1 cup flour
22
23
24Output:
25
26Title: Pancakes
27Ingredients:
28- 1 cup milk
29- 2 eggs
30- 1 cup flour
31Directions:
321. Whisk eggs and milk.
332. Add flour slowly.
343. Cook on pan.
35Time: 20-60 minutes
36Servings: 4
37
38## 🚀 Features
39- **Input**: Raw ingredient list (e.g., `"chicken breast, yogurt, garlic, salt, pepper"`).
40- **Output**: Structured **recipe card** with:
41 - Title suggestion 📝
42 - Ingredients (cleaned + normalized) 🧂
43 - Step-by-step cooking instructions 🍲
44 - Optional serving tips 🍽️
45
46- Supports **strict** and **flexible** generation modes:
47 - `STRICT=yes` → Uses **only** given ingredients
48 - `STRICT=no` → Allows creative variations
49
50---
51
52## ⚙️ Installation
53
54```bash
55# Clone repo
56git clone https://github.com/<your-username>/recipe-card-t5-lora.git
57cd recipe-card-t5-lora
58
59# Create environment
60python -m venv venv
61source venv/bin/activate # (Windows: venv\Scripts\activate)
62
63# Install dependencies
64pip install -r requirements.txt
65
66
67pip install transformers peft torch
68from transformers import pipeline
69pipe = pipeline("text2text-generation", model="MahmutCanBoran/t5-recipe-card-en-lora-merged")
70
71
72
73
74⚠️ Limitations
75
76Time/Servings fields are currently fixed values (20-60 minutes, Servings: 4).
77
78Model may hallucinate instructions if STRICT=no mode is used (future work: add dataset with variable strictness).
79
80Optimized for English outputs.