Now Cooking with RecipeGPT- Exploring a Generative Machine Learning System

By on May 12, 2022
Using RecipeGPT to generate a recipe for chocolate mousse.

Written by: Jasmine DeHart

Cooking can involve a lot of ingredients, preparation, tools, and time to create a delicious dish. The flavor patterns and combinations in cooking can be represented by using flavor networks. A flavor network captures culinary ingredients in respect to their flavor compounds. To generate recipes researchers have proposed the use of bayesian optimization, spatial regularization networks, steiner tree algorithm, and recommender systems [1-4]. Every week, I enjoy cooking and exploring a new dessert. This week, I wanted to explore a quick and simple dessert. Instead of using online cooking recipe websites like Allrecipes, Delish, and Yummly; I decided to use machine learning to generate recipes, RecipeGPT: A Generative Pre-training Based Cooking Recipe Generation and Evaluation System.

This system was generated by Lee et al. from Singapore Management University and the University of Illinois at Urbana-Champaign. The demo for this system was presented at The Web Conference 2020. The image below is the interface and functionalities described during the demonstration.

The ingredient and recipe generation system uses a machine learning model called a Transformer. The authors start with the GPT-2 model from OpenAI and fine-tune it using the Recipe1M+ dataset. The use of transfer learning allows modelers to customize pre-trained machine learning models to improve performance on a specific task. The data was pre-processed by cleaning for numbers, quantity words, and other comments in the Recipe 1M+ dataset. The data was further cleaned with the use of an ingredient phrase parser and rule-based filtering. If there were recipes with non-ingredients or non-instructional sentences, the recipe was removed in the pre-processing stage. Furthermore, the remaining recipes had to meet 3 additional criteria to remain: at least two ingredients, two or more instructional sentences, and 20 or more words in the instructions.

The researchers performed multi-field learning and generation with the cleaned data. Each recipe in the Recipe1M+ dataset consisted of a title, ingredients, and cooking instructions. This multi-field dataset was shuffled to create the training, test, and validation datasets. Top-k sampling was used to select a token among the k highest-ranked tokens from the vocabulary which is sorted by a prediction probability. The learning rate for the model is based on the perplexity using the validation set. RecipeGPT can generate two types of text for a recipe. (1) Given a recipe title and ingredients, the system can generate instructions. (2) Given a recipe title and cooking instructions, the system can generate ingredients. The system is comprised of a GUI with RESTful web services and a MongoDB database for data storage. The API service was built upon Nginx and UWSGI server.

To evaluate the output of the fine-tuned model and quality of the user interface, users can compare the overlap of ingredient words in the specified recipe and the generated text, the provided similar recipe given the specified recipe contexts, and the user is able to comment and rate the suggestions.

Chocolate Mousse a la RecipeGPT

With this understanding of RecipeGPT, I began exploring the interface and results for my desired recipe. For exploring this system, I chose to make a simple Chocolate Mousse. I wasn’t sure what the ingredients were for a chocolate mousse, so I started with the cooking instruction generation. The only input I provided the interface was the name of the recipe I wanted to make. The interface returned a list of ingredients separated by a dollar sign.

I took the generated ingredient list and used them and the title as input to generate the cooking recipe. The RecipeGPT did not return any specific ingredient measurements, but it returned a cooking recipe.

After looking thru my pantry, I had two (heavy whipping cream and chocolate) of the four ingredients. I decided to narrow the ingredients to the items in my pantry and added a third ingredient (vanilla extract) to the list. With the new list of ingredients (chocolate, heavy whipping cream, vanilla extract), I entered the recipe title and updated ingredients. It is important to note that the cooking recipe can vary each time the generator is run. I ran generator several times and RecipeGPT returned slight variations of cooking instructions when given the same ingredients and title.

Neither one of these cooking instructions would yield the dessert I wanted. I ran the ingredient list paired with the titles chocolate mousse and whipped chocolate mousse and this yielded similar cooking processes but different final results. The whipped chocolate mousse would produce the ideal dessert.

Cooking with RecipeGPT

In the end, I decided to prepare both recipes for a comparison. Since the recipes generated from RecipeGPT did not provide ingredient measurements, I eyeballed the measurements. The chocolate mousse recipe turned out similar to a chocolate ganache. A ganache is a smooth and velvety mixture of chocolate and cream. The whipped chocolate mousse recipe turned close to a mousse, light and fluffy. As the chef, I decided to layer the desserts together to produce the ultimate chocolate dessert.

References

  1. Garrido-Merchán, E. C., & Albarca-Molina, A. (2018, November). Suggesting cooking recipes through simulation and bayesian optimization. In International Conference on Intelligent Data Engineering and Automated Learning (pp. 277-284). Springer, Cham.

  2. Kuo, F. F., Li, C. T., Shan, M. K., & Lee, S. Y. (2012, November). Intelligent menu planning: Recommending set of recipes by ingredients. In Proceedings of the ACM multimedia 2012 workshop on Multimedia for cooking and eating activities (pp. 1-6).

  3. Trevisiol, M., Chiarandini, L., & Baeza-Yates, R. (2014, September). Buon appetito: recommending personalized menus. In Proceedings of the 25th ACM conference on Hypertext and social media (pp. 327-329).

  4. Zhang, L., Zhao, J., Li, S., Shi, B., & Duan, L. Y. (2019, July). From Market to Dish: Multi-ingredient Image Recognition for Personalized Recipe Recommendation. In 2019 IEEE International Conference on Multimedia and Expo (ICME) (pp. 1252-1257). IEEE.

© Copyright 2024 by UF Data Studio. Built with ♥ by ceg.me (via CreativeDesignsGuru!).