GithubHelp home page GithubHelp logo

choco427 / whatscooking- Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jackmleitch/whatscooking-

0.0 0.0 0.0 4.52 MB

:fork_and_knife: :thumbsup: Recipe reccomendation system using Word2Vec, TF-IDF, and Cosine Similarity.

Shell 0.63% Python 97.22% Dockerfile 2.15%

whatscooking-'s Introduction

Recipe Recommendation System

Project Overview

  • Created a tool that recommends recipes based on ingredients inputted to help students eat better food.
  • Scraped over 4000 recipes from All Recipes and Jamie Oliver using python and beautiful soup.
  • Parsed recipe ingredients and created word embeddings using Word2Vec and TF-IDF.
  • Created a recipe recommendation system using cosine similarity to measure Euclidean distance between the word embeddings of recipe ingredients.
  • Built a client-facing API using flask, and a user-friendly app with Streamlit.

Motivation

Cooking is a hobby for some and a major problem for others. However, you can always use a helping hand for cooking. Being a student, it is always a difficult decision to decide what to eat for lunch or dinner. Sometimes faced with limited items in the kitchen, it is always a challenge to decide what to cook for a meal. This inspired me to create a system that can recommend recipes based on ingredient suggestions.

Code

Python Version: 3.7
Packages: pandas, numpy, sklearn, gensim, matplotlib, seaborn, beautifulsoup, flask, streamlit, json, pickle
For Web Framework Requirements: pip install -r requirements.txt
You can run this model yourself using my API:

docker pull jackmleitch/whatscooking:API
docker run -p 5000:5000 -d whatscooking:api

Project Write-Up

I have three blogs on this project and they can be found here:

Web Scraping

Built a web scraper using Beautiful Soup to scrape over 4000 food recipes from All Recipes and Jamie Oliver. For each recipe, I retrieved the following:

  • Recipe name
  • Ingredients
  • URL
  • Rating

Data Cleaning

After scraping the data, we needed to parse the ingredients to remove redundant information that would not help distinguish recipes. The ingredient parser does the following:

  • Lemmatize words to ensure we remove all versions of words, e.g. both pounds and pound
  • Removed stopwords 
  • Removed cooking measures, e.g. pounds and lbs
  • Removed common household items, such as oil and butter 
  • Some standard NLP preprocessing: getting rid of punctuation, removing accents, making everything lowercase, getting rid of Unicode, etc.  

Model Building

I fed my collection of individual ingredients into a continuous bag of words Word2Vec neural network to produce word embeddings. Word2Vec was used because I wanted the text representations to capture distributional similarities between words. In the context of recipe ingredients, Word2vec allowed me to capture similarities between recipe ingredients that are commonly used together. For example, mozzarella cheese which is commonly used when making pizza is most similar to other cheeses and pizza-related ingredients.

In order to build the recipe recommendation system, I needed to represent each ingredient list as a single embedding as this would then allow me to calculate corresponding similarities. TF-IDF was used to aggregate embeddings (as opposed to simple averaging) as it gives us better distinguishing power between recipes by favoring unique ingredients.

The recommendation system was built using a content-based filtering approach which enables us to recommend recipes to people based on the ingredients the user provides. To measure the similarity between user-given ingredients and recipes cosine similarity was used. Spacy and KNN were also trialed but cosine similarity won in terms of performance (it was also the most simple approach). The recommendation model computes the cosine similarity between the inputted ingredient list and all recipes in the corpus. It then outputs the top-N most similar recipes, along with their ingredients and URLs, for the user to choose from.

Productionization

In this step, I built a Flask API endpoint that was hosted on a local webserver. The API endpoint takes in a request with a list of ingredients and returns the top 5 recommended recipes (along with URLs to the recipe webpage).

I also created and deployed a more user-freindly app using Streamlit, which can be accessed here.

whatscooking-'s People

Contributors

jackmleitch avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.