The Silicon Gourmet: training a neural network to generate cooking recipes
Neural networks are computer learning algorithms that mimic the interconnected neurons of a living brain, managing astonishing feats of image classification, speech recognition, or music generation by forming connections between simulated neurons.
I’m not a neural network researcher, but there’s never been a better time to experiment with them, thanks to open-source packages like torch, a scientific computing framework with built-in neural network capabilities. Inspired by Tom Brewe’s neural network-generated recipes, and enabled by the open-source torch add-on for character-based neural networks by Andrej Karpathy, I fired up the neural network code on my 2010 Macbook Pro, and started training it on a bunch of recipes I downloaded from a collection by David Shields.
Here’s a recipe my network has generated:
Pears Or To Garnestmeam
meats
¼ lb bones or fresh bread; optional
½ cup flour
1 teaspoon vinegar
¼ teaspoon lime juice
2 eggs
Brown salmon in oil. Add creamed meat and another deep mixture.
Discard filets. Discard head and turn into a nonstick spice. Pour 4 eggs onto clean a thin fat to sink halves.
Brush each with roast and refrigerate. Lay tart in deep baking dish in chipec sweet body; cut oof with crosswise and onions. Remove peas and place in a 4-dgg serving. Cover lightly with plastic wrap. Chill in refrigerator until casseroles are tender and ridges done. Serve immediately in sugar may be added 2 handles overginger or with boiling water until very cracker pudding is hot.
Yield: 4 servings
This is from a network that’s been trained for a relatively long time - starting from a complete unawareness of whether it’s looking at prose or code, English or Spanish, etc, it’s already got a lot of the vocabulary and structure worked out.
This is particularly impressive given that it has the memory of a goldfish - it can only analyze 65 characters at a time, so by the time it begins the instructions, the recipe title has already passed out of its memory, and it has to guess what it’s making. It knows, though, to start by browning meat, to cover with plastic wrap before chilling in the refrigerator, and to finish by serving the dish.
Compare that to a recipe generated by a much earlier version of the network:
Immediately Cares, Heavy Mim
upe, chips
3 dill loasted substetcant
1 cubed chopped whipped cream
3 unpreased, stock; prepared; in season
1 oil
3 cup milk
1 ½ cup mOyzanel chopped
½ teaspoon lemon juice
1 ¼ teaspoon chili powder
2 tablespoon dijon stem – minced
30 dates afrester beater remaining
Bake until juice. Brush from the potato sauce: Lightly butter into the viscin. Cook combine water. Source: 0 25 seconds; transfer a madiun in orenge cinnamon with electres if the based, make drained off tala whili; or chicken to well. Sprinkle over skin greased with a boiling bowl. Toast the bread spritkries.
Yield: 6 servings
which bakes first, has the source in the middle of the recipe directions, mixes sweet and savory, and doesn’t yet know that you can’t cube or chop whipped cream.
An even earlier version of the network hasn’t yet figured out how long an ingredients list should be; it just generates ingredients for pages and pages:
Tued Bick Car
apies
2 1/5 cup tomato whene intte
1 cup with (17 g cas pans or
½ cup simmer powder in patsorwe ½ tablespoon chansed in
1 ½ cup nunabes baste flour fite (115 leclic
2 tablespown bread to
¼ cup 12". oz mice
1 egg barte, chopped shrild end
2 cup olasto hote
¼ cup fite saucepon; peppen; cut defold
12 cup mestsentoly speeded boilly,, ( Hone
1 Live breseed
1 22 ozcugarlic
1 cup from woth a soup
4 teaspoon vinegar
2 9/2 tablespoon pepper garlic
2 tablespoon deatt
…
And here’s where it started out after only a few tens of iterations:
ooi eb d1ec Nahelrs egv eael
ns hi es itmyer
aceneyom aelse aatrol a
ho i nr do base
e2
o cm raipre l1o/r Sp degeedB
twis e ee s vh nean ios iwr vp e
sase
pt e
i2h8
ePst e na drea d epaesop
ee4seea .n anlp
o s1c1p , e tlsd
4upeehe
lwcc eeta p ri bgl as eumilrt
Even this shows some progress compared to the random ASCII characters it started with - it’s already figured out that lower case letters predominate, and that there are lots of line breaks. Pretty impressive!