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:
Âź 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.
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
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.
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:
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!