Chama99's picture
Upload folder using huggingface_hub
0269a37 verified
metadata
language: en
license: apache-2.0
base_model: google/flan-t5-small
tags:
  - recipe-generation
  - cooking
  - food
  - instruction-following
  - t5
  - flan-t5
  - peft
  - lora
datasets:
  - recipe-nlg
pipeline_tag: text2text-generation
widget:
  - text: >-
      Create a detailed recipe using these ingredients: chicken, mushrooms,
      garlic, cream. Include step-by-step cooking instructions:
    example_title: Chicken Mushroom Recipe
  - text: >-
      Generate a restaurant-style recipe with: pasta, tomatoes, basil, olive
      oil. Provide precise cooking methods:
    example_title: Italian Pasta Recipe
  - text: >-
      Make a gourmet dish using these ingredients: salmon, lemon, dill, butter.
      Write comprehensive cooking directions:
    example_title: Salmon Recipe

FLAN-T5-Small Recipe Generator

Model Description

This model is a fine-tuned version of google/flan-t5-small specifically optimized for recipe generation. It can create detailed, step-by-step cooking instructions based on a list of ingredients.

Model Details

  • Base Model: google/flan-t5-small (80M parameters)
  • Fine-tuning Method: LoRA (Low-Rank Adaptation)
  • Training Data: High-quality recipe dataset with professional cooking instructions
  • Model Size: ~3.4 MB (LoRA adapter only)
  • Precision: Float32
  • Max Input Length: 512 tokens

Key Features

Instruction-Following: Responds to natural language prompts ✅ Detailed Recipes: Generates step-by-step cooking instructions ✅ Professional Quality: Includes temperatures, timing, and techniques ✅ Memory Efficient: Uses LoRA for minimal storage requirements ✅ CPU Compatible: Optimized for CPU inference with 16GB RAM

Usage

Quick Start

from transformers import T5ForConditionalGeneration, T5Tokenizer
from peft import PeftModel

# Load base model and tokenizer
base_model = T5ForConditionalGeneration.from_pretrained("google/flan-t5-small")
tokenizer = T5Tokenizer.from_pretrained("google/flan-t5-small")

# Load LoRA adapter
model = PeftModel.from_pretrained(base_model, "Chama99/flan-t5-small-recipe-generator")

# Generate recipe
def generate_recipe(ingredients):
    prompt = f"Create a detailed recipe using these ingredients: {ingredients}. Include step-by-step cooking instructions:"

    inputs = tokenizer(prompt, return_tensors="pt", max_length=512, truncation=True)

    with torch.no_grad():
        outputs = model.generate(
            **inputs,
            max_length=400,
            num_beams=5,
            temperature=0.8,
            do_sample=True,
            repetition_penalty=1.4,
            no_repeat_ngram_size=3
        )

    recipe = tokenizer.decode(outputs[0], skip_special_tokens=True)
    return recipe.replace(prompt, "").strip()

# Example usage
ingredients = "chicken, mushrooms, garlic, cream"
recipe = generate_recipe(ingredients)
print(recipe)