Revisiting bread recipe generator

With the recent rise in Large Language Models (LLMs), recipe generation has become faster and easier. But is it actually better in terms of the actual dish at the end? According to one of my favorite sourdough bread websites, not really. LLMs are definitely more advanced than my home-grown recipe generator, which I wrote about a few years ago. But looks like even with a wealth of input data and supercomputer-powered training, machines don’t actually know the physics, chemistry and biology happening in the dough while it ferments, and the taste and aroma of a well-baked loaf of bread. Well, we’re still at the beginning of the generative AI journey – I’m looking forward to seeing how it evolves!

Relatedly, an Italian zine, L’Integrale about culture and baking (see details here) included an article about bread and AI, and featured my journey with recipe generation. I’m attaching the file here as well as the English translation, kindly provided to me by the author, Piero Macchioni.

English translation as follows:

INTELLIGENT DOUGHS

BY PIERO MACCHIONI

What happens when making

bread is the computing power of

an artificial intelligence?

Can a computer be trained

to imagine the perfect recipe

and to reproduce the sensitivity

of a gesture?

Someday some supercomputer will govern our lives. It will assign a value to our existence. It will distribute tasks to be done. It will tell us where, how and with whom to live. It will decide what we will eat. It will not do so with malice, but with rationality. And that should worry us a little: will he put a swollen, glowing Turkish pita in the oven to please our senses? Or a dark, moist bread made from orthoptera flour, to ensure our efficient nourishment? The answer to these questions depends greatly on what this great machine will have learned at some crucial moment in history. 

That moment is now. 

Today we often hear about artificial intelligence, but we consider it lateral in our lives. We don’t. The smartphone camera recognizes what we are framing thanks to neural networks compressed into a processor a few millimeters in size. Supercomputers capable of simulating millions of moves in a fraction of a second beat strong players at chess. Social media put before our eyes only what panders to our tastes or fuels our engagement. A few apps can predict our choices in music, movies to watch, things to buy. Of course, those are all “machine” activities. But how does an artificial intelligence behave when it has to make something human like bread?

The earliest evidence of dough has been found in Europe and Australia and dates back about 30,000 years. The oldest bread was baked in Jordan and is dated to 16,000 years ago. All over the world, since time immemorial, every community has found ways to mix water and grain flour to make something flat and edible to go with other dishes. We have tortillas in Mexico and Roti Canai in Malaysia, piadina in Rimini, Ngome in Mali. Bread is the product that perhaps defines most of all the fact that men and women are brothers and sisters, that we are all kneaded in the same humanity. What can a machine know about it? And, even if we taught it everything, what would it then do with it? 

By Artificial Intelligence we mean the ability of a computer system to perform complex actions that are usually performed by a human being. To achieve this kind of intelligence, machines need three elements: machine learning, which is the exploitation of algorithms or statistical models to learn how to perform tasks under certain conditions without receiving special instructions; training data, which is lots of information to train itself to learn; and finally a human being to conduct these training, called a human in the loop. 

Think of these machines as a child: it needs to be taught how to behave, how to communicate, and how to become self-sufficient, then it will store the information and develop its own personality. Here, artificial intelligence is like a super-child that is able to live billions of lives every second. 

Putting bakery and artificial intelligence together may seem eccentric to most, but it is already being done. Chilean company Protera is using the technology to create fermented proteins in the laboratory-one, in particular, allows it to act against mold in a way that extends the expiration date of packaged bread by 30-45 days. Britain’s Campden BRI has tried using supercomputers to make industrial bread-making more uniform since nearly 80 percent of the bread produced in the Kingdom is created using the same system, the Chorleywood Bread Process, which allows it to get from flour to sliced bread in as little as 3 1/2 hours. Bakkersland, the Netherlands’ largest bakery company uses artificial intelligence to calculate the exact amount of fresh bread required hour by hour, and day by day, in the country’s supermarkets. Alongside these purely industrial functions of super-technology, however, comes another, shall we say more philosophical one: if a superior intelligence had access to every bread recipe in the world, so that it could learn from every dough ever made, what would it put in the oven? What would the “bread of breads” look like? Today we begin to get the first answers. 

Pratima and smart bread

In the spring of 2020, in an apartment in Berkeley, California, United States, a 28-year-old girl named Pratima Satish combined two of her passions into an ambitious project: to bake a loaf of bread whose recipe had been compiled by a neural network, that is, one capable of processing so much information almost like a human mind. Pratima wanted to get closer to creating “smart bread,” but first he had to give birth to a digital mind up to the task.

In three months, Satish created a program capable of scouring the more than 10,000 posts on The Fresh Loaf bakery forum and deriving 1,257 recipes with which to train the artificial intelligence that was being born in his Macbook Air. “The problem,” she says, “is the time you spend training your system: with the computing power I had at my disposal, it’s as if I had raised a 3-year-old child who could only do certain things; with more training and more data, I could have raised a 7-year-old and he would definitely have had more capabilities.” 

However, it took Pratima a long time to teach her machine how to read recipes correctly: The Fresh Loaf is a forum with posts written by different people and different ways of expressing themselves, so it did not encapsulate codified directions, only complex texts that reflected the personality of each individual author. So the girl first had to teach her artificial intelligence to understand what the forum members wrote, then made it speak like them. Or almost.

When, after 99 days of work, Pratima sent the last command on the terminal, ready to discover the first intelligent bread formula, she received a message from the computer that sounded something like this: 

“Across the street is a guy who has an Airbnb directly on a kitchen towel dusted with flour….”

There was obviously some parameter in the semantics of the machine to fix. After a few hours, Pratima tried again. 

“A pizza made from sourdough with balsamic olive oil is covering the dough with a yellow patina, or is it?” 

Worse than before. 

The topic of the language of artificial intelligence is not insignificant. In the television series Person of Interest, which aired between 2011 and 2016, the real star was a highly evolved computer system capable of signaling whether a person would be a murder victim on a certain day. Advanced as it was, the software spoke no language: it communicated only the social security number of the man or woman in question. Numbers, not words: it was simpler that way. Pratima, therefore, did the same: she minimized the expository capacity of her digital child (i.e., programmed it to formulate more essential sentences) and finally, on the fifth attempt, got her first smart bread:

“I made bread cloves 1g water 384g water 735g high extraction spelt flour 200g red fife berries 50g freshly ground flax seeds 725g water 22g pink Himalayan salt 30g yogurt 20g salt 250g levain procedure recipe extra wholegrain flour feeding autolyze 88 g.”

Rearranged and translated, it comes something like this: 1 gram cloves, 384 grams water, 735 grams spelt flour (high-extraction?), 200 grams Red Fife wheat flour, 50 grams ground flax seeds, 725 grams water, 22 grams pink Himalayan salt, 30 grams yogurt, 20 grams salt, 250 grams sourdough, 88 grams extra wholegrain flour.

The experiment had succeeded. Now it was a matter of kneading, folding, and baking. The result was satisfactory: for Pratima’s taste, the flax seeds were too much, and the clove aroma and the acidity of the yogurt were a good addition to the usual bread. 

When I asked Pratima if she was looking for a way to improve something we have already perfected over thousands of years, she replied, “No, an artificial intelligence accomplishes what it is trained for. In my case, I started from existing recipes and told her, ‘Come on, learn from us and then invent a recipe yourself.’ A machine has a different way of reasoning than we humans do, so under certain conditions, it can create something new and fun.” 

The ability to imagine what does not exist has always been one of the prerogatives of the human intellect: think of art, music and, of course, even cooking. But the computing power of some computers, capable of simulating every possible choice we make, seems to be able to match or surpass us even in the exercise of the imagination. “The truth is that a human is just a short algorithm,” says an artificial intelligence in the futuristic series Westworld. And, algebraically speaking, he is right: a properly programmed machine can be not only more efficient than a human but also creative. At least in our eyes.

We’ve been there before in 2017 with AlphaGo, the artificial intelligence that taught itself the Chinese strategy game Go, beating the greatest champions every time. The news is not so much in its victories, but in the manifestation of a principle we will have to deal with sooner or later: a system that does not rely solely on human knowledge to solve a problem can find infinite creative ways to overcome it. And that brings us to Cambridge, Massachusetts, United States. 

The computer that created the Cakie

We are not on the technology campus of the famous MIT, but in the home of Sara Robinson, Google’s Developer Advocate and cooking enthusiast. In the days of the lockdown that followed the Covid-19 pandemic, Sara had no desire for the usual recipes, so she decided to train an artificial intelligence to do two things: recognize baked goods according to their ingredients and be able to invent something new that nevertheless respected the golden proportions of pastry. Sara thus collected 99 recipes: 33 of bread, 33 of cookies, 33 of cakes. With these she trained her artificial intelligence to recognize and imagine how to compose doughs. Once the computational model was consolidated, she tried to exaggerate, asking the software to invent a kind of anti-bread: something that was 50 percent cookie, 50 percent cake and 0 percent bread. And so “Cakie,” a contraction of Cake and Cookie, was born:

“½ cup + ¾ tablespoon butter, cold; ¼ cup granulated sugar; ¼ cup brown sugar, packed; 1 large egg; ¼ cup olive oil; ⅛ teaspoon vanilla extract; 1 cup flour; 1 teaspoon baking powder; ¼ teaspoon salt; ¼ cup chocolate chips.”

“It’s so good. And it tastes just as I expected, ” Sara says today, commenting on the result of her work. The Cakie, while looking nothing like a bakery product, proves that teaching machines what is to our taste can result in something new that we may actually like. 

What might hurt us, however, is to go overboard with expectations, to ask a machine to make something better, to the point of accidentally turning it into something else. American science fiction writer Fritz Leiber recounted this in the short story Bread Overhead, which we could translate as “Bread Overhead” or “It’s Raining Sandwiches.” Leiber wrote this story at the height of the 1950s boom, in a society that magnified industrial production, cheap food for all, shining houses, and universal abundance after the miseries of war. In the story he imagines a future in which giant mills run through the fields immediately grinding grain and turning it almost immediately into bread. In that tomorrow, people are so obsessed with the perfection of the industrial product that they want it not only white but very light, to the point that men end up telling the machines to enrich it with helium. 

The helium loaf is so ethereal that it flies. The result of the extreme quest for lightness is a bread that gives no bread, because it floats away and there is none for anyone. It abandons the Earth precisely the first product that comes from our connection with the Earth.

In the catalog of possible smart breads of the distant future, however, we risk losing a key ingredient: our gestures, that craftsmanship, transmitted in baking workshops almost like a low-frequency signal. A machine can save us the trouble of kneading, can glimpse new breads that satisfy or nourish us, can eliminate waste and hunger. But how does it learn the sensibility of gestures and smells, the store secrets that often even a baker cannot fully explain to his apprentice?

Today one can only speculate, but unless there is a database of the invisible power that makes a master baker’s fold successful and mine clumsy, all this is in danger of being lost. Every element that is impossible to calculate will be interpreted by a machine as deviation from the standard: a standard that returns a very good product 99.99 percent of the time. That 0.01 percent that would be lost along the way, however, would be a decisive part not only of the culture of baking, but of our history. Something incalculable to the most infallible of machines would thus become an incalculable loss to our being human. 

We will also have to remember this when training the artificial intelligences of tomorrow. And although the task seems out of our reach, because the more machines grow the smaller we become, perhaps there is hope. The one that Harold Finch, played by actor Michael Emerson in the aforementioned TV series Person of Interest, points to the artificial intelligence he created as he explains to it how a game of chess works:

“Every possible move represents a different game. A different universe where you make a better move. By the second move, there are 72,084 possible games. By the third, 9 million. Once you get to the fourth, there are more possible chess games than there are atoms in the universe. No one can predict all of them, not even you. Which means that that first move can be terrifying. It is the furthest point from the end of the game; there is a virtually infinite sea of possibilities between you and the other side of the chessboard. But it also means that if you make a mistake, there is an almost infinite amount of ways to fix it. So you should just relax and play.”

Someday some supercomputer will govern our lives. It will assign a value to our existence. It will distribute tasks to be done. It will tell us where, how and with whom to live. It will decide our futures, perhaps our loves, certainly our bread. Not too much, but let’s relax: we still have an infinite number of ways to help him find the right dough.

Neural network for bread recipe generation – Part III

Welcome to the third and last part of the bread journey! In parts I and II, I wrote about how I scraped data from The Fresh Loaf to get recipes, explored and visualized the text data and used topic modeling to see what trends exist. In this post, I will describe how I trained two different language generation models to predict AI-based recipes for sourdough bread.

On the left, a loaf of sourdough bread I made with a recipe generated from my neural network model. On the right, the code to analyze and predict bread recipes.
Continue reading “Neural network for bread recipe generation – Part III”

Neural network for bread recipe generation – Part II

Welcome back! I previously described how I scraped the baking forum The Fresh Loaf, where people post their bread recipes, to get data to train a neural network to generate new bread recipes. I also detailed how I explored the data. In this post, I explain how I used some unsupervised learning techniques in the Natural Language Processing toolkit to further understand the textual data. Note: all the code I used for this project is in this repo.

A sourdough loaf I made with buckwheat groats to start us off!
Continue reading “Neural network for bread recipe generation – Part II”

Neural network for bread recipe generation – Part I

In 2017, a friend gave me some sourdough starter to make bread with, and ever since then, my life has changed. It sounds cheesy, but I discovered a hobby that has led me to buy almost 200 pounds of flour at a time (seriously), develop a biweekly pizza baking habit, and dream of what bread I’m going to make in the coming days!

On the left, a loaf of sourdough bread I made with a recipe generated from my neural network model. On the right, the code to analyze and predict bread recipes.

Because I spend a lot of time baking sourdough and experimenting with new formulas, I wanted to see if I could create an artificial intelligence-powered recipe generator that would predict something for me to make! One of my go-to websites for technique, tips and tricks has been the helpful bread baking forum, The Fresh Loaf, where people ask questions and post recipes. My idea was to scrape this website and get data to train a neural network to generate new bread recipes – and that’s what I did. At the end of this project, I was able to achieve my goal: to bake a machine learning-inspired loaf of bread, with ingredients predicted with a neural network.

Since there are multiple components to this project, I am breaking them down in a few blog posts. All the code I used for the project is in this repo.

My walnut sourdough loaf, with the accompanying picture of the insides (called the crumb shot) showing purple streaks due to the tannins in walnuts. Chemistry!
Continue reading “Neural network for bread recipe generation – Part I”