Cooking Recipes By GPT-2: Thanksgiving Edition

Daniel Vitiello
13 min readNov 27, 2020

--

Final results of recipes generated by GPT-2

Over the last two years Open AI has released a series of natural language models that have shown an amazing capability on tasks ranging from writing poetry to coding. As a cofounder at Cooklist, I was curious to see if this type of model could generate recipes since they are a relatively structured form of natural language.

I pulled 300K recipes from the Cooklist database to use as training data and then used the wonderful GPT-2-Simple notebook to finetune the 335M parameter model. After a few hours of training the results started to look pretty good.

While a recipe may sound good on paper, there’s no way to tell how it tastes until you cook it. So as a fun experiment we decided to cook five of the generated recipes for Thanksgiving this year, with a few rules.

  1. No editing the generated recipe, ingredients or direction steps
  2. Follow the directions exactly as the AI wrote them
  3. We have to eat the final result

This is V0 so our plan is that these rules will be a good incentive to make the AI better over time. You can find quick videos of the results on our TikTok account, or continue below for the full story.

Brandon & Daniel, the cofounders of Cooklist

Initial Experiments

The first test was simple. Can the model generate recipe titles with a corresponding list of ingredient names? The short answer is, yes.

It quickly learned the pattern and started producing some results that are on par with the human generated recipes. The titles sounded appetizing and the list of ingredient names was plausible for each recipe. Occasionally it would duplicate ingredients or make odd flavor combinations but the results were overall better than expected.

Example Recipe Title + Ingredient List

// Recipe title:
Grilled Chicken With A Raspberry & Black Pepper Sauce
// Ingredient names:
butter, butter, chicken breast, chicken thigh, cream, fresh basil, fresh parsley, lemon juice, marsala wine, minced garlic, olive oil, red pepper flakes, raspberry, red pepper flakes, shallot

In the example above the title looks good but then it duplicated “butter” and “red pepper flakes”. It also calls for using both chicken breast and chicken thighs. This is kind of odd since recipes usually use one or the other.

The next step was to try generating the recipe title, ingredient names and full list of step by step directions. This is more challenging because it has to keep the context of the title and ingredient names throughout the direction steps.

Example Recipe Title + Ingredient List + Step by Step Directions

// Recipe title:
Easy Chocolate Brownie Cookies
// Ingredient names:
baking powder, baking soda, brown sugar, eggs, flour, salt, semi-sweet chocolate chips, sugar, unsalted butter, unsweetened cocoa powder, vanilla extract
// Directions:
1. Preheat oven to 350F
2. Line a baking sheet with parchment paper
3. Whisk flour, cocoa powder, baking powder, baking soda, and salt together in a medium bowl and set aside
4. Set a heatproof bowl over a saucepan of barely simmering water
5. Add butter and sugars to bowl
6. Stir frequently until mixture is butter and sugars are melted and smooth
7. Remove bowl from heat.
8. Add vanilla extract, eggs and egg yolk, as well as the hot butter mixture to the bowl with the sugar mixture
9. Stir until smooth
10. Add cocoa powder mixture.
11. Add flour mixture to the bowl with the egg and sugar mixture and stir until just combined.
12. Using two tablespoons measuring spoon out cookie dough onto prepared baking sheet
13. You may need to slightly press the top of your tines of prepared cookie dough into the back of a spoon to get a flat cookie that is about 2-inches in diameter
14. A lightly floured fork helps you to get that really flat, even top in the oven.
15. Bake for 20 minutes, let cool on the baking sheet for 10 minutes before transferring to a rack to cool completely
16. I found these store well but I usually double the recipe to make two batches
17. I think the brownies are perfect for quick brownies, but they are a little better if you let them sit out for at least a few hours before they cool and are stored in the refrigerator.

At first glance the directions look pretty good. The steps are in a logical order and it even adds some helpful “tips” from it’s imagined first hand experience.

However this longer format is definitely more challenging for the model. There are times where it mentions an ingredient in the list and then never uses it in the directions. For example, the recipe above lists “brown sugar” and “semi-sweet chocolate chips” in the ingredient list but never calls for them in the directions.

Generating 5 Complete Recipes For Thanksgiving

The initial results were encouraging enough that it seemed possible to go all the way and generate complete recipes where each ingredient specifies quantity, unit, ingredient name and preparation steps.

Since mistakes were starting to appear in the last experiment, I upgraded from the 335M parameter medium model to the 774M parameter large model. Additionally I increased the number of example training recipes from 300K to 500K.

Then I let it run for 50,000 training steps which took about 24 hours on a Tesla V100 GPU. We used this model to generate a few hundred recipes and selected the 5 below from the output that fit our Thanksgiving theme.

Text in the grey boxes is unedited output generated by our GPT-2 model.

#1. Sweet Potato Cornbread

Watch Recipe Video Here: Sweet Potato Cornbread

// Recipe title: 
Sweet Potato Cornbread
// Ingredients:
1 teaspoon baking soda
1 teaspoon salt
2 cups all-purpose flour
1 cup (2 sticks) unsalted butter, melted
1 cup sweet potato, mashed
1 cup sugar
1/2 cup cornmeal
1 egg
// Directions:
1. Preheat oven to 400°F
2. Butter an 8-by-8-inch baking pan and set aside.
3. In a large bowl, whisk together flour, cornmeal, sugar, baking soda, and salt.
4. In a small bowl, whisk together butter and sweet potato
5. Stir into dry ingredients
6. Stir until just combined, then fold in sweet potato.
7. Pour batter into prepared pan and smooth top
8. Bake for 25 minutes, or until a toothpick inserted in the center comes out clean
9. Cool in pan for 10 minutes before serving.

This recipe was short and sweet which works in its favor. The directions correctly use every ingredient that was called for and the ratios of the ingredients worked well. When mixing everything up the dough seemed a little on the dry side but it ended up cooking nicely.

There’s only one mistake where the directions say to “fold in the sweet potato” after the sweet potato is already mixed in. Overall this recipe was easy to follow and came out great.

#2. Green Bean Casserole with Bacon, Tomatoes, and Garlic

Watch recipe video here: Green Bean Casserole with Bacon, Tomatoes, and Garlic

// Recipe title:
Green Bean Casserole with Bacon, Tomatoes, and Garlic
// Ingredients:
2-3 cloves garlic
1 large shallot
1 pound fresh green beans
1/2 pound bacon
3 large roma or plum tomatoes
2 tablespoons fresh parsley
1/4 cup heavy cream
1/2 cup grated Parmesan cheese
// Directions
1. Prepare the green beans in boiling water
2. Cook until very bright green and tender (1-2 minutes)
3. Transfer to a large bowl and toss with 2 tablespoons of olive oil
4. Meanwhile, sauté the bacon in a large sauté pan until crispy
5. Remove to a paper-towel-lined plate
6. Pour off all but 2 tablespoons of bacon fat from the pan and add the shallots to the pan
7. Sauté over low heat until translucent (about 3 minutes)
8. Add the garlic and sauté until fragrant (about 1 minute)
9. Stir in the cream and Parmesan and then season with salt and pepper.
10. Drain the beans, then add them to the bacon/shallots mixture along with the bacon and the drained tomatoes
11. Stir to combine and then transfer to a large casserole dish.
12. Preheat the oven to 375 degrees F
13. Place the sliced tomatoes over the green bean casserole and sprinkle with the remaining 1 tablespoon of olive oil
14. Roast until the tomatoes are slightly softened and starting to break down, about 10 minutes
15. Stir in the parsley and serve hot.

This recipe is a little more complex but again it successfully kept the context of ingredients across the title, ingredient list and direction steps without forgetting any. It was rather unconventional for a “green bean casserole” because it lacked cream of mushroom soup and crispy toppings. The sliced tomatoes on top were an odd detail yet it’s hard to go wrong once you add bacon and a cream sauce.

It did make a couple mistakes by instructing you to add “drained tomatoes” to the pan in one step and later it calls for “sliced tomatoes” on the top of the casserole. It didn’t specify how to prepare the tomatoes in the ingredient list so this was up for interpretation. Overall the flavor was great and it would make a good Keto friendly dish.

#3. Roast Turkey with a Peach Salsa

Watch recipe video here: Roast Turkey with a Peach Salsa

// Recipe title:
Roast Turkey with a Peach Salsa
// Ingredients:
1/2 cup extra-virgin olive oil
2 pounds fresh peaches, halved and pitted
1/2 cup fresh lemon juice
1/2 cup chopped fresh cilantro
2 tablespoons coarse salt
2 tablespoons coarse salt
1 1/2 pounds fresh boneless turkey breast, cut into 4 pieces
2 tablespoons coarsely ground pepper
// Directions:
1. Preheat oven to 325 degrees
2. In a large bowl, toss together turkey, salt, and pepper
3. In a large roasting pan, heat 1 tablespoon oil over medium-high heat
4. Add turkey and cook until browned on all sides, about 5 minutes per side
5. Transfer to a platter and cover loosely with aluminum foil to keep warm
6. Add remaining 1 tablespoon oil to pan and heat over medium-high heat until shimmering
7. Add peaches, lemon juice, and salt to pan and cook, stirring occasionally, until slightly softened, about 3 minutes
8. Add cilantro and cook until slightly wilted, about 1 minute
9. Return turkey to pan and stir to coat with sauce
10. Serve immediately with salsa and warm cornbread.

This dish looks appetizing but it was awful for one simple reason. TOO. MUCH. SALT.

You’ll notice it calls for 2 tablespoons of salt, twice. This is correct because the directions have two separate steps which call for salt, but it is very incorrect in the total amount of salt needed to season this recipe.

Another thing that was off was that it called for 1 1/2 pounds of turkey breast which is likely a bias introduced from the endless number of recipes which use chicken breast. The smallest turkey breast we could find was several pounds.

This recipe would have been delicious if we had used less salt, yet that’s the price we pay for letting an AI model tell us how to cook Thanksgiving dinner.

#4. Crazy Love

Watch recipe video here: Crazy Love

// Recipe title:
Crazy Love
// Ingredients:
1⁄4 teaspoon ground cinnamon
1⁄4 teaspoon ground nutmeg
1 cup sugar
2 eggs
1⁄4 cup heavy cream
2 tablespoons powdered sugar
1⁄4 cup coconut oil
1⁄4 cup coconut flour
1⁄4 cup powdered sugar
1 teaspoon vanilla
1 teaspoon vanilla
2 tablespoons coconut oil
1⁄2 cup heavy cream
2 tablespoons milk
// Directions
1. Preheat oven to 350 degrees
2. In a small bowl, combine 1 cup of sugar and 2 tablespoons of water
3. Stir until all the sugar has dissolved
4. This should take about 5 minutes.
5. Line an 8x8 pan with parchment paper. Set aside.
6. In a mixing bowl, beat the 2 eggs, 1⁄2 cup sugar, and 1 teaspoon of vanilla until creamy.
7. Add the heavy cream and mix well.
8. Add the heavy cream mixture to the egg mixture and beat well.
9. Add the coconut flour, 1/2 cup at a time, until the dough is soft and smooth.
10. Using a rubber spatula, spread the dough evenly in the pan.
11. Bake for 15 minutes, or until a toothpick inserted in the middle comes out clean.
12. Let cool for 10 minutes before removing from pan and cooling completely on a wire rack.
13. Place the cream and powdered sugar in a small bowl. Mix well.
14. Spread the cream evenly on top of the cooled bars and sprinkle with nutmeg and cinnamon.
15. Cut into bars and serve.

With a name like “Crazy Love” we knew this was going to be the dessert that we had to cook. Searching Google doesn’t turn up any similar recipe results so this is truly an AI original recipe.

Overall the quantities it called for seemed a little small for the 8x8 pan. It probably would of made sense to use more flour with the recipe as well. Oddly it called for “coconut oil” twice in the ingredient list but never used it in the directions.

It tasted ok and came out a bit like spongy flan. To be honest we had been cooking for 10 hours at this point and didn’t let it cool completely as instructed in the directions so when we ate it the pieces were still a bit warm and floppy.

#5. Pineapple-Cherry-Molasses-Bourbon

Watch recipe video here: Pineapple-Cherry-Molasses-Bourbon

// Recipe title:
Pineapple-Cherry-Molasses-Bourbon
// Ingredients:
1/3 cup chicken broth
1 pound (about 1 3/4 cups) fresh or frozen pitted tart cherries, thawed
1 1/2 pounds fresh or frozen pitted and unthawed pineapple chunks (about 4 cups)
1/4 teaspoon coarse salt
1 teaspoon kosher salt
1 tablespoon hot sauce
1 tablespoon finely grated orange zest
2 tablespoons bourbon
2 cups sliced pecans
1/3 cup packed dark-brown sugar
// Directions:
1. Combine juice ingredients in a medium saucepan; bring to a boil over high heat, stirring occasionally, 1 minute
2. Pour mixture through a fine sieve into a measuring cup; let cool to room temperature, about 2 hours
3. Let stand until thickened, about 3 hours
4. Reserve 3 tablespoons-pineapple mixture for another use.
5. Combine cherries and remaining liquid ingredients in a blender
6. Blend until smooth
7. Transfer to a small saucepan
8. Bring to a boil over medium-high heat, stirring occasionally
9. Reduce heat, and simmer, uncovered, until cherries are soft and liquid has reduced by about 1/2, about 5 minutes.
10. Transfer mixture to a bowl, and cover surface with plastic wrap
11. Let stand 1 hour or up to 3 days.
12. Combine pecans, orange zest, and remaining 1/3 cup cherries in a blender, and pulse until coarsely ground
13. Add remaining 1 tablespoon syrup, 1 tablespoon at a time, pulsing constantly, until mixture holds together when you press your hand against the side of the blender with your fist
14. Transfer to a bowl, and cover surface with plastic wrap
15. Let stand 1 hour or up to 3 days.
16. Stir cherries, bourbon, and salt in a bowl
17. Divide chilled drink among 2 glasses.
18. Garnish drinks with reserved pecans, cherries, pecans, and rim of glasses.

This was supposed to be a cocktail recipe but it turned out as more of a smoothie bowl. The directions called for letting the mixture stand for at least an hour, three separate times. So this was the first recipe we started in the morning and the last one we finished after the sun had gone down.

There were a lot of the directions which were up for interpretation. We decided that the “Juice ingredients” meant to boil the pineapple chunks and hot sauce. It also called for a comically large amount of pecans (2 cups) and small amount of bourbon (2 tablespoons).

It seems like the model got confused on whether it was making a cocktail or a smoothie and ended up writing recipe that fell somewhere in the middle. The final result actually tasted pretty good but was obviously was not a cocktail.

Is There A Future In AI Generated Recipes?

Overall I would consider this experiment to be a success and a great starting place for AI generated recipes. We were able to follow the recipes generated by the model and all but one of the dishes were editable. A few of them were tasty enough that we saved to eat the leftovers.

There is still a long way to go until the model is generating useful enough output to use in recipe development or every day cooking.

For the next iteration we are planning to improve the model in three ways.

  • Use a bigger model (Can you help us get access to the GPT-3 Beta?)
  • Train for a longer time
  • Add more example recipes to the training data

If you’d like to see videos of the process of cooking each recipe and the tasting reactions checkout our TikTok account. To find the best human generated recipes that you can cook with the groceries you already have, checkout the Cooklist app.

Thanks for reading. I would love to hear your ideas in the comments for types of recipes we should have the model generate the next time we attempt to cook with AI.

--

--

Daniel Vitiello
Daniel Vitiello

Written by Daniel Vitiello

Cofounder at Cooklist and Handground

Responses (1)