Views
No views yet
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:").gpt2 (124M parameters, Small)GPT2LMHeadModel). The model predicts the next token in the sequence based on all preceding tokens.top_p) or temperature control is recommended.1from transformers import AutoTokenizer, AutoModelForCausalLM
2import torch
3
4# Load model and tokenizer
5model_name = "YourOrg/recipe-generator-gpt2-small"
6tokenizer = AutoTokenizer.from_pretrained(model_name)
7model = AutoModelForCausalLM.from_pretrained(model_name)
8
9# Define the prompt
10prompt = "Recipe Title: Quick Tomato Basil Pasta"
11input_ids = tokenizer.encode(prompt, return_tensors='pt')
12
13# Generate text
14output = model.generate(
15 input_ids,
16 max_length=200, # Max sequence length
17 num_return_sequences=1, # Generate 1 sequence
18 no_repeat_ngram_size=2, # Avoid simple repetitions
19 do_sample=True, # Enable sampling for creativity
20 top_k=50, # Top-K sampling
21 top_p=0.95, # Nucleus sampling
22 temperature=0.7, # Controlled randomness
23 pad_token_id=tokenizer.eos_token_id
24)
25
26generated_recipe = tokenizer.decode(output[0], skip_special_tokens=True)
27print(generated_recipe)