Skip to main content

A recommender library built on top of Tensorflow and Keras with implementations of SVD and SVD++ algorithms.

Project description

Tf-rec

Tf-Rec is a python💻 package for building⚒ Recommender Systems. It is built on top of Keras and Tensorflow 2 to utilize GPU Acceleration during training.

Contents

Why Tf-Rec? 🧐

There are several open source libraries which implement popular recommender algorithms in, infact this library is inspired by them - Surprise and Funk-SVD. However, there is bottleneck in training time, when the training data is huge. This can be solved by using ready frameworks like Tensorflow 2 & Keras which support running computations on GPU thus delivering speed and higher throughput. Building on top of such frameworks also provide us with off the shelf capabilities such as using different optimizers, Data API, exporting the model to other platforms and much more. Tfrec provides ready implementations of algorithms which can be directly used with few lines of Tensorflow Code.

Installation ⚡

The package is available on PyPi:

pip install tfrec

Quick Start & Documentation 📝

API Docs

SVD Example

from tfrec.models import SVD
from tfrec.datasets import fetch_ml_100k
from tfrec.utils import preprocess_and_split
import numpy as np

data = fetch_ml_100k()
dataset, user_item_encodings = preprocess_and_split(data)

(x_train, y_train), (x_test, y_test) = dataset
num_users = len(np.unique(data['userId']))
num_movies = len(np.unique(data['movieId']))
global_mean = np.mean(data['rating'])

model = SVD(num_users, num_movies, global_mean)
model.compile(loss = 'mean_squared_error', optimizer = 'adam')
model.fit(x_train, y_train)
2521/2521 [==============================] - 11s 4ms/step - loss: 0.9963

SVD++ Example

from tfrec.models import SVDpp

model = SVDpp(num_users, num_movies, global_mean)
# Needs to be called before fitting
model.implicit_feedback(x_train)
model.compile(loss = 'mean_squared_error', optimizer = 'adam')

model.fit(x_train, y_train)
2521/2521 [==============================] - 49s 20ms/step - loss: 1.0332

KFold Cross Validation Example

from tfrec.utils import cross_validate
model = SVD(num_users, num_movies, global_mean)
model.compile(loss = 'mean_squared_error', optimizer = 'adam', metrics=['mae','RootMeanSquaredError'])
all_metrics = cross_validate(model, x_train, y_train)
Mean Loss : 0.899022102355957
Mean Mae : 0.6596329569816589
Mean Root_mean_squared_error : 0.8578477501869202

Supported Algorithms 🎯

Currently the library supports these algorithms:

  • SVD - Despite the Name, it is different from the Eigen Decomposition of Assymmetric Matrices. In a gist, it approximates a vector for each user and each item. The vector contains latent factors which signify for brevity sake, if the item is a movie the movie vector would represent - how much the movie contains action or romance likewise. Similarly for the user. The predicted rating is given by:

  • SVD++ - This is an extension of SVD which incorporates implicit feedback, by also taking into account the interactions between the user and the item by involving another factor. More Precisely, it takes into account the fact that the user has rated an item itself as a preference than an item which the user has not rated. The predicted rating is given by:
    image

Benchmark 🔥

Both of the algorithms were tested on Google Collab using a GPU Runtime. The dataset used was the MovieLens-100k. Default parameters were used for intilization of Model. Optimizer used was Adam and batch size used was 128. These are the 5-Fold Cross Validation Scores:

Algorithm Mean MAE Mean RMSE Time per Epoch
SVD 0.6701 0.8694 < 3 sec
SVD++ 0.6838 0.8862 < 45 sec

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tfrec-1.0.0.tar.gz (11.7 kB view details)

Uploaded Source

Built Distribution

tfrec-1.0.0-py3-none-any.whl (12.9 kB view details)

Uploaded Python 3

File details

Details for the file tfrec-1.0.0.tar.gz.

File metadata

  • Download URL: tfrec-1.0.0.tar.gz
  • Upload date:
  • Size: 11.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.8.6

File hashes

Hashes for tfrec-1.0.0.tar.gz
Algorithm Hash digest
SHA256 c8528b7007d3eb1984ac64494a2f012f8bd1e26a9ca7c35162e9488995142947
MD5 c3f178504283a94bfb389c90feb799a1
BLAKE2b-256 e36e188e37fd392313a0ff15225f15e88e8531d71817ada6cdad3ab6cd08c103

See more details on using hashes here.

File details

Details for the file tfrec-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: tfrec-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 12.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.8.6

File hashes

Hashes for tfrec-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 fc8b306d97d6b97c4032b161929c22c9f047b6ead384f66f8c7243fdbbbba79e
MD5 740d559a01c4790d8d1c8efbd471b94f
BLAKE2b-256 a2b852018ea7b8e782ba1228967f440268171ecb2f454726234643572586196e

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page