Git Product home page Git Product logo

ibm / turi-create-movie-recommender Goto Github PK

View Code? Open in Web Editor NEW
25.0 21.0 16.0 252 KB

Creating a movie recommendation system for iOS with Turi Create

Home Page: https://developer.ibm.com/patterns/creating-a-movie-recommendation-with-turi-create-on-watson-studio-coreml/

License: Apache License 2.0

Jupyter Notebook 43.08% Shell 0.94% Swift 54.55% Ruby 0.41% Python 1.02%
ibmcode movielens flask turi ios ngrok swift

turi-create-movie-recommender's Introduction

Creating a Movie Recommendation System with Turi Create

This code pattern is an iOS Application that helps you find new movies to watch! It's been built to show you how you can use Turi Create, Apple's new deep learning framework, to build amazing recommendation systems very quickly, locally, on your machine - in under 2 minutes training time.

When the reader has completed this Code Pattern, they will understand how to:

  • Create "Item Similarity" recommender models in Turi Create
  • Use Flask to expose a REST API that provides recommendations based off of users' past movie ratings
  • Call that REST API from Swift to create a GUI around the recommender

Flow

  1. Download the MovieLens latest dataset (at the time of writing, there are 26,000,000 rows of data).
  2. Train an item similarity recommender with turi create on MovieLens.
  3. Expose that model through a REST API with Flask.
  4. Open a tunnel to the REST API with ngrok.
  5. User searches for and rates movies on the iOS app.
  6. iOS app sends the movie rating data to the REST API.
  7. The REST API will provide the iOS App with a list of movies and their scores.
  8. The iOS App will display those movies and scores.
  9. User will watch & rate those movies, and go back to step 6, getting better recommendations every time.

Included components

  • Turi Create: is a task-focused deep learning library - allowing you to build intelligent apps by focusing on the machine learning use case, not the algorithm.
  • Flask: is a micro web framework.
  • ngrok: allows you to open an HTTPS tunnel into your REST API.

Featured technologies

  • Artificial Intelligence: Artificial intelligence can be applied to disparate solution spaces to deliver disruptive technologies.
  • Python: Python is a programming language that lets you work more quickly and integrate your systems more effectively.

Prerequisites

The following are prerequisites to start developing this application:

Steps

  1. Download and organize the latest MovieLens dataset
  2. Train the Turi Create Recommender model
  3. Run the backend
  4. Deploy the iOS app

1. Download and organize the latest MovieLens dataset

In order to get the MovieLens dataset setup, run the following script:

$ sh setup.sh

It'll download the data and move the files to their relevant locations.

2. Train the Turi Create Recommender model

In order for the recommendations to work, you need a trained model. Turi Create is a Python package that will train this model for you.

Go ahead and start your Jupyter Notebooks. In the local_model_training folder, open the TrainRecommendationModel.ipynb notebook. Run the notebook, and once it's done executing, you're going to have a folder called movie_rec, which contains the trained Turi Create model. Unlike other machine learning libraries, Turi Create does not use files for models; instead, it uses folders.

3. Run the backend

Turi Create supports exporting recommender models to CoreML, so they can run on-device, and there's no need for a backend. However, it only works with iOS 12 and above (which is currently in Beta), and there's an issue with linking the custom model framework. Therefore, this code pattern will use a backend that takes requests from the iOS Application, and runs the users' preferences through the Turi Create model, to return predictions as to what the user would like to watch next.

First, copy the movie_rec folder (your trained model) from local_model_training, and paste it into the serverside_prediction_api folder. Once that's done, run the following command from a terminal window within that folder:

FLASK_APP=backend.py flask run

This will run the backend.py file, which is the flask application.

Next, open up a tunnel to the backend with ngrok, so your iOS App can access it:

ngrok http 5000 (change 5000 to whichever port you chose with Flask)

4. Deploy the iOS app

Finally, you can run the front-end of the application.

Start by pointing your iOS app to the backend. Go to the iOS_Frontend/MovieRecommender/MovieRecommender/MovieHandler.swift file, and change the backend constant to the link of the ngrok tunnel.

Then, in the iOS_frontend/MovieRecommender folder, and open the xcworkspace file. Once you're there, run the application by hitting โŒ˜ + R or clicking the run button beside the window controls on the top left of Xcode.

License

This code pattern is licensed under the Apache Software License, Version 2. Separate third party code objects invoked within this code pattern are licensed by their respective providers pursuant to their own separate licenses. Contributions are subject to the Developer Certificate of Origin, Version 1.1 (DCO) and the Apache Software License, Version 2.

Apache Software License (ASL) FAQ

turi-create-movie-recommender's People

Contributors

dolph avatar imgbot[bot] avatar kant avatar ljbennett62 avatar stevemart avatar tanmayb123 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

turi-create-movie-recommender's Issues

Use CoreML for on-device recommendations

In Core ML 2 (coming in September), Apple has added support for custom models. This means that recommender systems trained in Turi Create v5 are compatible with Core ML 2 / Xcode 10 / macOS Mojave / iOS 12 / watchOS 5 / tvOS 12.

Because these versions are currently in beta, I'll create a branch with code that works with Core ML 2, but will merge with master in September, when everything's stable.

There are also a few issues that the Turi Create team is working around in terms of custom models and getting recommender systems to work with Core ML 2.

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.