Package: tfrec
Tf-Recis a python💻 package for building⚒ Recommender Systems. It is built on top ofKerasandTensorflow 2to utilizeGPU Accelerationduring training.ContentsWhy Tf-Rec?🧐Installation⚡Quick Start & Docs📝API DocsSVD ExampleSVD++ ExampleKFold Cross Validation ExampleSupported Algorithms🎯Benchmark🔥Contribute😇Why Tf-Rec? 🧐There are several open source libraries which implement popular recommender algorithms in, infact this library is inspired by them -SurpriseandFunk-SVD. However, there is bottleneck in training time, when the training data is huge. This can be solved by using ready frameworks likeTensorflow 2&Keraswhich 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 providesready implementations of algorithmswhich can be directly used with few lines of Tensorflow Code.Installation ⚡The package is available on PyPi:pip install tfrecQuick Start & Documentation 📝API DocsAPI DocumentationSVD Examplefromtfrec.modelsimportSVDfromtfrec.datasetsimportfetch_ml_100kfromtfrec.utilsimportpreprocess_and_splitimportnumpyasnpdata=fetch_ml_100k()dataset,user_item_encodings=preprocess_and_split(data)(x_train,y_train),(x_test,y_test)=datasetnum_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.9963SVD++ Examplefromtfrec.modelsimportSVDppmodel=SVDpp(num_users,num_movies,global_mean)# Needs to be called before fittingmodel.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.0332KFold Cross Validation Examplefromtfrec.utilsimportcross_validatemodel=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.8578477501869202Supported 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: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 wasAdamand batch size used was128.
These are the 5-Fold Cross Validation Scores:AlgorithmMean MAEMean RMSETime per EpochSVD0.67010.8694< 3 secSVD++0.68380.8862< 45 sec