Downloads · 30 days
27
33% of all-time downloads
Shoriful025/recipe-generator-gpt2-small
recipe-generator-gpt2-small is a machine learning model from Shoriful025. Use it for the machine learning task on the model card, and read the license before you ship it in a product.
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,…
Downloads · 30 days
27
33% of all-time downloads
All-time downloads
83
Public
Repo size
—
Likes
0
Public
Click a slice to open those files.
.md3.3 KB · 58%
From the Hugging Face model README
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:").
This model utilizes the GPT-2 (Generative Pre-trained Transformer 2) architecture.
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.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)