DALE MARKOWITZ: All right, we are 15 minutes in.
And-- oh, it doesn't look that compelling, I'll be honest.
It's the holidays.
And there is nothing that that makes
me want to do more than machine learning.
Today I'm going to build a machine learning model that
will analyze recipes and then dream up an entirely new recipe
that I'll bake and eat right before you here today.
And to make the project a little bit sweeter,
I'll add just a sprinkle of model explainability
so that we understand why our model is making
the predictions that it is.
I'll be joined by Sara Robinson.
Sara is an AI expert and baking extraordinaire
who works with me at Google.
Hey, Sara.
SARA ROBINSON: Hey, Dale.
Thanks for having me.
DALE MARKOWITZ: I heard that a couple of months
ago you use a machine learning model
to come up with a new recipe that you baked.
Can you tell me about that?
SARA ROBINSON: So I've been baking
a ton over the past few months.
And after following a lot of recipes,
I started to notice that a lot of baking recipes
follow a pattern.
So I started to wonder, since machine learning
is all about finding patterns in data,
could I build a machine learning model
to predict what I'm baking, given
a list of ingredient amounts?
So I built a model to predict whether a recipe was
a bread, a cake, or a cookie.
DALE MARKOWITZ: So we're going to do exactly the same thing
here today.
We'll build a model that takes a list of ingredients
and then predicts bread, cake, or cookie.
And then we're going to use that core model
to come up with new recipes that we'll bake, right?
SARA ROBINSON: Awesome.
Let's get started.
So step one is to collect a data set of cookies, cake, and bread
recipes.
We gathered about 700 recipes.
Next we had to do a bit of data pre-processing.
For example, there's a lot of consensus
that banana bread and pumpkin bread are actually cakes.
Even Paul Hollywood agrees.
So we had to move the banana and pumpkin
breads from the bread category into the cake category.
DALE MARKOWITZ: Next, we slimmed down the recipes
to just their core ingredients, like flour, eggs, butter,
sugar, and a couple more.
SARA ROBINSON: We also converted all of our ingredient amounts
from cups and sticks and teaspoons and tablespoons
into one single measurement unit.
We used ounces.
OK, so here are all of my recipes.
They're converted into ounces, and cleaned up
and labeled in a Google Sheet.
To build my model, I'm going to use a tool
in Google Cloud called AutoML Tables, which
is a no-code tool for building machine learning models
to analyze tabular data, like spreadsheets or databases.
OK, I'm opening up Tables, and I'll
import my data from that CSV I just showed you.
I have to select the bucket where
I want the data to be stored.
And it'll take a second to import.
When it's done, I can click on my new data set.
And as you can see, a couple of stats about the data
are automatically generated, like whether certain columns
are missing values, and also this useful field, Correlation
With Target, which says in isolation
how good is each of these columns
at predicting whether or not something is cake, bread,
or cookie.
I've also selected a target field,
which is what we're trying to predict,
which is, in this case, Type, that I've already selected.
To train a model, I'll click the Train Model button,
name my model, say how long I want it to train for,
specify which columns I want to include.
I don't want to use the name of the recipe or URLs or IDs
or anything like that.
And then I click Train Model and wait.
This part could take a couple of hours.
When my model is done training, I
can see how well it did in the Evaluate Model tab.
Here I can see lots of stats on model accuracy.
And if I scroll down to the Confusion Matrix,
I can also see how often my model correctly
predicted recipes.
So it was most accurate for bread,
which it labeled correctly 93% of the time,
and a little less accurate for cookies, which it confused
for cake 21% of the time.
When I'm ready to use my model, I can hop into the Test
and Use tab.
And here I can make predictions right from within the UI.
So I can fill in the values for a cake recipe, click Predict,
and boom.
The model thinks this is cake, which is correct.
DALE MARKOWITZ: So Sara was able to build
a model that takes the recipe and then predicts cookie, cake,
or bread.
But the inquisitive baker might want
to know, what is it that makes a cookie a cookie?
What gives it that chewy-crunchy property,
that cookieness, if you will?
And what makes bread fluffy and cake spongy?
In other words, we want to model that not just made
a prediction, but also explains what
ingredients it was looking at when it made that prediction.
And that's called model explainability.
SARA ROBINSON: Right.
We want to understand how important each ingredient is
to the model when it's deciding whether something is
a bread, a cookie, or a cake.
I can take a look at Feature Importance, which tells me
how important different ingredients are
to the overall model's predictions.
So in this case, butter, sugar, and yeast
were really good at helping differentiate the baked goods.
Now, even though butter might be important to the overall model,
it might be that different ingredients matter more
depending on the recipe.
So if I go into the Test and Use tab,
I'm going to put in a cake recipe.
And then I'll hit this Generate Feature Importance box,
hit Predict.
And then I'll be able to see how ingredients
matter for a specific recipe.
Here egg and fat got the highest feature importance scores,
so we can assume that they're the most important thing
the model is looking at when it decided that this was a cake.
DALE MARKOWITZ: OK, so now I'm going
to try something really radical.
I'm going to bake not a cookie or cake, but something
that our model deems to be a split between the two,
a "cakie," if you will.
SARA ROBINSON: And I'm going to bake something that's
a half bread, half cookie.
I'm going to call it a "breakie."
To find a breakie recipe, I adjusted the ingredients
in the model UI until our model predicted
that our recipe was about equal parts cookie and bread.
Same for Dale's cakie.
DALE MARKOWITZ: All right, Sara, you ready to bake?
SARA ROBINSON: Yes.
Let's do it.
On your marks, get set, bake.
[MUSIC PLAYING]
DALE MARKOWITZ: None of my training prepared me for this.
Um.
All right, here's the cakie.
Good luck, little cake--
cookie.
Cakie.
SARA ROBINSON: Here is what we've got.
DALE MARKOWITZ: OK.
I guess I'll try to pry it from the pan.
SARA ROBINSON: It does taste like a cookie,
but it is a little bit more airy.
DALE MARKOWITZ: I can't tell if it's cooked all the way.
SARA ROBINSON: [LAUGHING]
[THUMPING]
DALE MARKOWITZ: Did not work exactly the way
I had hoped it might work.
SARA ROBINSON: This is actually pretty good.
[TRUMPET FANFARE]
DALE MARKOWITZ: OK, it's kind of nasty.
SARA ROBINSON: So, yeah, I guess it's a success.
DALE MARKOWITZ: I wonder if I put the right amount of flour
or double the amount of flour.
So I feel I kind of flubbed that recipe, something
with the flour.
But Sara then went back and baked it herself,
and her cakie came out just fine.
So I guess we'll have to attribute that to human error.
If you want to know the details of this project
and steal our recipes, make sure you check out
the blog post linked below.
Happy holidays, and see you next year.