
Generating weird cooking recipes with TensorFlow - oleksiitwork
https://github.com/trekhleb/machine-learning-experiments/blob/master/assets/recipes_generation.en.md
======
userbinator
As amusing as the results are, I can't say I'd be too happy seeing pages of
search results filled with these. There's been plenty of discussion on HN
about how hard it is to find good recipes and skip over the SEO spam; imagine
having to determine if they're real too...

~~~
Y_Y
If you can get over the socialist aspect of it, the BBC consistently has great
recipes on its websites, and isn't even ad-supported (in some countries).

~~~
Torok
Is the BBC being paid for by taxpayers really a problem that people have?
Seems like American "capitalism good, socialism bad" rubbish that non
ideologues know to ignore. Why would the business structure of a website
impact the quality of articles?

~~~
jw1224
My first thought upon seeing that comment was "there's no way a Brit wrote
that".

I know the BBC has its critics here in the UK, but I've never seen any one of
them conflate it with socialism before. Just reading that sentence forced me
to do a double-take...

~~~
Y_Y
I'm sorry you feel the need to retract my nationality.

It was a joke, by the way. There are some hardcore free-market libertarians
here really who do make criticisms like that. Isn't monotone sarcasm just as
much a part of Britishness as the BBC?

~~~
YeGoblynQueenne
It is, but you have to laugh out loud after you tell a joke to make sure
everyone knows it's a joke.

There was something about that in The Name of the Rose- the book in any case.
Something about how Englishmen and Germans react differently to a joke etc.
I'll see if I can find a quote.

------
YeGoblynQueenne
>> For a couple of hours of training our character-level RNN model will learn
basic concepts of English grammar and punctuation (I wish I could learn
English that fast!).

Thankfully the task is rather easier than learning natural language concepts.
The LSTM only has to learn basic concepts of the language _of recipes_ , which
is considerably simpler than unrestricted natural English.

For example, in natural English one would say

    
    
      "You will need one cup of unsalted butter for this recipe, which you should soften.   
      Alternatively, you can measure 2 sticks of butter". 
    

Whereas a recipe will simply say:

    
    
      1 cup (2 sticks) unsalted butter, softened
    

As in the example on the repository.

Also, it seems that most, if not all, sentences begin with a verb that
describes an action followed by a list of ingredients to be combined. "Stir
the olive oil, garlic, thyme and 1 teaspoon salt in a saucepan;" etc. The
regularity and repetitiveness of such structures makes them much easier to
learn than arbitrary English text. In more practical terms, they also make the
instance space for this task a lot more dense than arbitrary English text,
were a sentence with a certain structure may only repeat once after a million
utterances.

Edit: OK, if I don't say this I'll explode. "one cup" is "two sticks"? This is
just not going to work.

~~~
131012
I find it interesting that the model doesn't get one of the simplest rule of a
recipe: the ingredients list and the ingredients in the instructions must be
the same.

Obviously, it is because the model "understands" the structure of the
sentence, but is oblivious of the text as a whole.

------
cheschire
I get that this was just a toy, but naturally I wanted to think through how to
make it useful. Like imagining building a real car from lego.

I know very little about machine learning or cooking or chemistry in general.
How would one make this actually useful and interesting?

My guess is you would need to provide a lot more context to the database.
Things like chemical composition seem like the most fundamental component of
recipes.

Backwards planning from the composition, you could teach it actions that
generate those chemicals such as methods of cooking, and the source foods that
provide the building blocks i.e. ingredients.

Then at some point you could link it back to the recipes to create
standardized instructions for generating certain chemical patterns.

Does that sound like the right way to make this more realistic?

~~~
YeGoblynQueenne
That's not how neural networks er work. This one is trained to predict the
next character in a sequence. It's trained on raw, unstructured text, not
high-level concepts like "chemical composition" or "actions that generate
chemicals" etc. Its inputs are character sequences and its outputs are
character sequences. There is no way to "provide context to the database"
(there is no database, just character sequences) or anything like that. If any
relations like that are useful to its task of predicting the next character
then your best hope is that it will somehow magickally learn them from its
input text. Otherwise, the knowlede of how cooking works will simply not be
encoded in its trained model.

~~~
cheschire
I don't know enough about machine learning to specify which neural network
type is correct for a given use case or which algorithm gets the most relevant
results, but I do know enough to use them for things once an engineer hands me
the tool.

I'm not talking about how this specific network is trained. I'm talking about
how this toy could be perhaps turned into something useful, like my original
analogy to building a car out of lego.

I understand enough about neural networks to know they are useful as Boolean
supersets. It's all about how the training is defined with your training data
containing the Boolean true/false values.

So what I'm saying is, in order to provide context and make this toy useful,
you could change your Boolean choices from sequence-based letter chains to
something with a little more value like popular chemical combinations.

To go further, consider how a restaurant picks its menu. That is a simple
Boolean statement of "accept" or "reject". So how do you work backwards from
there? Right now you require a combination of a head chef that has years of
experience (your database) and an owner that has a vision.

Don't miss the forest for the trees!

~~~
YeGoblynQueenne
>> Don't miss the forest for the trees!

I'm sorry, I think you took my comment in the wrong way. I didn't mean it as
some kind of put down. I wished to explain how this kind of thing works.

In the same spirit, of a friendly sharing of knowledge, I would also now
explain that what you are proposing, "buildig a car out of lego", or in
general assembling structure out of modular components, is not what neural
nets do best. Neural nets are best at mapping between sets of objects.
Typically, one set represents some entities we are interested to categorise
and the other set represents the categories to which we want to assign the
entities in the first set. To "build a car out of lego" you would need a
different type of AI, like a program synthesis algorithm, or an Inductive
Programming algorithm (machine learning algorithms that learn programs from
examples; and which I study). In such a setting, your "lego" would be
functions or sub-programs and your "car" would be a program created by
combinations of the given sub-programs.

Also, neural nets, especially more modern ones of the "deep learning" variety
are not limited to boolean features ("data containing Boolean true/false
values") and can instead be trained on arbitrary real-valued data. What is
often done when training language models is to encode training data in a "one-
hot encoding" manner, in which the "features" are very long boolean vectors,
with one element for each word or character in the raw text and with a "0"
representing "no occurrence" and a "1" "occurrence", of a particular character
or word. This is not the case for other types of data, e.g. in machine vision
the feature values are raw pixel data, in time series regression they're
arbitrary precision real numbers etc.

I confess that I'm not sure how the data looks for neural nets trained to
predict chemical structures. It's possible they're one-hot encoded vectors,
like for text.

No doubt you can train a neural net classifier to make yes/no decisions about
possible items on a menu, but my guess is that a system of this kind would
look at customer preferences primarily, rather than the chemical composition
of food items. After all, the chemical composition of a dish will vary a lot
more than the preference of a particular individual, or group of individuals,
for that dish. By which I mean, if I like spaghetti carbonara, I will probably
like it regardless of its exact chemical composition, but I won't like it.
e.g. if it lacks pancetta. My guess is that the relevant elements of the dish
are in the scale of cooking ingredients, rather than the scale of molecules.
So a system like the one you describe would be better off taking into account
the composition of a dish on that scale.

On the other hand, if you wanted to assemble a menu with finished dishes from
a list of ingredients and examples of recipes, then you would need a system
like the ones I describe above, in the program synthesis or (preferrably)
Inductive Programming category. Or of course you could write a program
encoding the rules you have in mind by hand. This is not a task where AI is
absolutely necessary, I feel.

------
mrweasel
It seems to be missing the three page back story of how the author meet her
husband on a last minute discount vacation to Uganda and how they had to seek
shelter at a local tribes man who made her this exact burger in the back of
his 1984 Toyota HiAce.

------
9nGQluzmnq3M
It's probably a matter of time until a restaurant gets a Michelin star through
AI recipes. Unlikely but tasty juxtapositions are big in trendy, high-end
cuisine, as are "fusion" restaurants mixing two unrelated cuisines (yuzu all
the things!), and AI seems like it would excel at finding these, hopefully
with a bit of human quality control.

------
eatbitseveryday
I don’t see how weird recipes is an achievement? Wouldn’t stellar, workable,
recipes be something more worthwhile?

~~~
Broken_Hippo
I sometimes cook things because they seem weird or make me curious. It is
definitely an achievement. It doesn't mean they aren't stellar, workable
recipes by any means: Historical recipes (or even old ones from 50-70 years
ago) are often weird. And workable, though if they get old enough, you have to
fill in some blanks since they assume the cook is experienced more than modern
recipes do. And some of the things are absolutely stellar. If you don't want
to go historical, go sideways to different cultures - especially fusion foods.
Indian-spiced potatoes, bell peppers, and some cheese stuff into bread
cinnamon-roll-style? Yes please.

Right now, AI recipes are just an oddity. Weird and barely workable at best,
and that's OK. We'll get there.

------
bentpins
Reminds me of Chef Watson, the recipes and directions that generated were
supposed to be plausible [https://www.welcome.ai/tech/food/ibm-chef-
watson](https://www.welcome.ai/tech/food/ibm-chef-watson)

------
mark_l_watson
I like this, although it is yet another example of a learned language model
not capturing underlying meaning.

I started a similar project last year, but using GAN (RecipeGAN). Using a GAN
would learn underlying meaning, based on my experience using GANs to
synthesize data that maintained univariate statistics and correlation between
features of the original data.

The example in the article shows how RNNs can capture structure (I have used
LSTM models to synthesize JSON data, and just for fun, to model source code).

------
monkeydust
Clock is ticking before we get the first 'AI Restaurant' where you have to eat
the Chef special and the Chef is code. Might work for the novelty factor as a
pop-up that moves around, could be a way to get people into the tech.

------
Abishek_Muthian
Nice work.

I think generating a final 'cooked recipe' image and publishing it to the
social media would attract more eyes, but that would involve whole lot of
other variables and could become WMD for the recipe video spammers/scammers.

------
Baeocystin
Research on the Blue Personality Core is proceeding apace!

[https://www.youtube.com/watch?v=ylN8WTAfq8w](https://www.youtube.com/watch?v=ylN8WTAfq8w)

------
Natsu
Those are hilarious, but can you make it so that the directions only refer to
ingredients actually on the list?

Maybe if you just generate the description and backfill the ingredient list
afterward? Hmm.

~~~
RodgerTheGreat
for comparison, instead of ML, this program uses a simple collection of
heuristics to generate plausible (sometimes) recipes from a name:

[http://beyondloom.com/things/reciprocity.html#chicken%20curr...](http://beyondloom.com/things/reciprocity.html#chicken%20curry)

~~~
YeGoblynQueenne
Not bad:

    
    
      What are you trying to cook?  fried onions
      Hmm. Never heard of fried onions. I guess it's some kind of salad? How about:
      Ingredients
      
          1 oz. onion
          3/4 tsp clove
          1 oz. swiss cheese
          1 cups lima beans
          2 cups tomato juice
          3/4 liters goat milk
      
      Preparation
      
      start with a large mixing bowl.
      chop onion, removing any seeds, and stir in.
      season with clove.
      crumble over swiss cheese.
      stir in lima beans (fresh).
      apply dressing made by blending goat milk and tomato juice.
      toss thoroughly.
      Serves
      
      2, at 1050 calories per serving. 
    

More context? What is this, how and why was it made, etc?

Edit: aAAAAAAH! I don't want to know what it is. INSECTOID BUTTONS. AAAH.

~~~
jojobas
This is seriously funny, suggesting adding 1.5 liters of melted butter and 6kg
of fried tofu per 2 cups or pork (sic) to make stir-fried pork.

~~~
Natsu
It gets worse:

Hmm. Never heard of hacker news. I guess it's some kind of baked dish? How
about: Ingredients

    
    
        1 1/2 liters simple syrup
        1 tbsp mother of vinegar
        3 cups white flour
        2 large salmon eggs
        2 1/2 oz. american cheese
        1 1/2 tbsp star anise
        1 oz. pork chops
        7 cups chicken breast
        9 cups kiwifruit juice
        3/4 cups water

------
samradelie
maybe it will produce recipes such as in this book
[https://www.thisiscolossal.com/2016/10/les-diners-de-gala-
da...](https://www.thisiscolossal.com/2016/10/les-diners-de-gala-dali/)

------
Frost1x
This XKCD seems all too relevant:
[https://xkcd.com/720/](https://xkcd.com/720/)

