I would like to construct system that would suggest user ingredients once he/she inputs title of the recipe.

I think that this is the task of machine learning or AI, but on the other hand I am pretty new to ML and generally in AI development and I feel kinda lost, since I don't know where to start and with what to start.

So far, I've managed to crawl data from web page with recipe title and ingredients which are used for this recipes.

My thoughts are that, this problem may be solved with suggester system, but on the other hand I think classification / clustering algorithms may be used to divide recipes in clusters / categories and once input title is associated to cluster ingredients may be generated from that cluster, but I don't know which is best solution and I wonder if there may be other ones.

Thanks in advance!

I'm posting my temporary solution

which may help others solve similar problems and I think this is pretty basic, but works nice:

  1. import all data to database (postgres in my case), where Recipe table has only name and Ingredient table has name and ForeignKey to recipe
  2. once user inputs recipe name (rname), I run query using postgres' Trigram Similarity module to detect similarity between rname and recipe table names. Then I filter out recipes which similarity is greater than .1 (for example)
  3. After that, I get all ingredients which are linked to filtered recipes, annotate ingredient usage for individual ingredient (calculate ingredient usage ratio). And order by usage ratio DESC
  4. Finally, I return ingredients (10 mostly used ones)

I think, looking through proposed solutions and also posting them.

  • $\begingroup$ You could try to investigate the Google Assistant and its related APIs $\endgroup$ – knb Jun 4 '18 at 10:14
  • $\begingroup$ This task is called food/ingredient pairing; cf. e.g., Flavor network and the principles of food pairing $\endgroup$ – Emre Jun 5 '18 at 17:28

If the user inputs a title, then you could construct a system which finds the most similar titles in the corpus, and outputs the ingredients in the retrieved recipes. Some ideas below:

1) Represent the titles in a common vector space using a vocabulary-based vectorization and use Jaccard or Cosine similarity to find the most similar titles. examples of similarity measures

2) Convert the words in the title to their respective word-embeddings using FastText, GloVe, or Word2Vec (publicly available), and then use cosine distance or word-movers distance to find the most similar titles. example of publicly available GloVe word embeddings

3) Create sentence embeddings for the title by taking the average of the word embedding vectors or using InferSent embeddings, and then use a distance function to find the most similar titles. InferSent repository link

spaCy is a good Python package for performing these type of NLP tasks link

| improve this answer | |
  • $\begingroup$ Thanks, it really helps me, I'll look through resources you've provided $\endgroup$ – Giorgi Jambazishvili Jun 4 '18 at 10:08

Not the answer you're looking for? Browse other questions tagged or ask your own question.