YAML Metadata Warning: empty or missing yaml metadata in repo card (https://huggingface.co/docs/hub/model-cards#model-card-metadata)

recipe-generator-gpt2-small

Model Overview

The recipe-generator-gpt2-small is a lightweight language model adapted from the standard GPT-2 architecture. It has been fine-tuned on a vast dataset of cooking recipes, including ingredient lists, preparation steps, and serving suggestions. Its primary function is unconditional and conditional text generation to create new, coherent, and stylistically consistent recipes when given a starting prompt (e.g., "A quick vegetarian dinner recipe:").

Model Architecture

This model utilizes the GPT-2 (Generative Pre-trained Transformer 2) architecture.

  • Base Model: gpt2 (124M parameters, Small)
  • Architecture: A standard decoder-only transformer stack (12 layers, 12 attention heads, 768 embedding dimension).
  • Task: Causal Language Modeling (GPT2LMHeadModel). The model predicts the next token in the sequence based on all preceding tokens.
  • Fine-tuning: The model was fine-tuned with a custom dataset of structured recipes, learning the unique format (title, ingredients, instructions, notes).

Intended Use

  • Creative Content Generation: Generating new recipe ideas for food blogs, cookbooks, or social media.
  • Recipe Completion: Completing partially written recipes or expanding simple prompts into full guides.
  • Educational Tool: Demonstrating the capabilities of large language models in a highly structured, domain-specific task.

Limitations and Ethical Considerations

  • Plausibility vs. Safety: The model generates text based on learned patterns and does not perform real-world checks. Generated recipes may contain plausible-sounding but chemically incompatible, non-edible, or potentially unsafe ingredient combinations (e.g., incorrect oven temperatures, non-food items).
  • Nutritional Accuracy: The model makes no claims regarding nutritional value, allergies, or dietary requirements. Users must verify all outputs for safety and suitability.
  • Repetition: In long generations, the model may occasionally fall into repetitive loops common with autoregressive models. Using techniques like nucleus sampling (top_p) or temperature control is recommended.

Example Code

To generate a new recipe given a starting prompt:

from transformers import AutoTokenizer, AutoModelForCausalLM
import torch

# Load model and tokenizer
model_name = "YourOrg/recipe-generator-gpt2-small"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(model_name)

# Define the prompt
prompt = "Recipe Title: Quick Tomato Basil Pasta"
input_ids = tokenizer.encode(prompt, return_tensors='pt')

# Generate text
output = model.generate(
    input_ids,
    max_length=200,             # Max sequence length
    num_return_sequences=1,     # Generate 1 sequence
    no_repeat_ngram_size=2,     # Avoid simple repetitions
    do_sample=True,             # Enable sampling for creativity
    top_k=50,                   # Top-K sampling
    top_p=0.95,                 # Nucleus sampling
    temperature=0.7,            # Controlled randomness
    pad_token_id=tokenizer.eos_token_id
)

generated_recipe = tokenizer.decode(output[0], skip_special_tokens=True)
print(generated_recipe)
Downloads last month
25
Inference Providers NEW
This model isn't deployed by any Inference Provider. ๐Ÿ™‹ Ask for provider support