In this project we will show how to use our framework for building privacy-preserving recommender system.
For demonstration purposes we will use Book Recommenation Dataset from Kaggle.
We don't to create fancy recommender system in order to show how to use our framework, so we will use XGBoost model for classification built on top of 3 features: user_age
, user_location
and book_publication_year
.
Following steps are required to build privacy-preserving recommender system:
- Data preprocessing and model training
- Creating Aleo Project
- Model transplilation to Aleo Smart Contracts
- Smart contract execution
a. Download dataset from here and put it into data
folder.
Now let's open this notebook and follow instructions there.
To create new Aleo project run following command:
leo new aleo_book_recommender
Instructions for model transpilation can be found here
Due to unstable testnet we will use local development environment for now.
- Build Aleo Smart Contracts
leo build
- Create mock data for testing
Let's pick a few random users and books from our dataset and create mock data for them. We've prepared this data for you, so you can find it here.
We apply quantization to our model, so we need to quantize our data as well. Our model uses 32-bit floating point numbers, so we need to quantize our data to 32-bit integers. This notebook shows how to do it.
Here is Aleo inputs from test dataset with positive target (user liked the book):
[main]
book_publication_year: i32 = 32571i32;
user_age: i32 = 32767i32;
user_in_canada: i32 = 32767i32;
user_in_italy: i32 = 0i32;
user_in_spain: i32 = 0i32;
user_in_united_kingdom: i32 = 0i32;
user_in_usa: i32 = 0i32;
Here is Aleo inputs from test dataset with negative target (user didn't like the book):
[main]
book_publication_year: i32 = 32539i32;
user_age: i32 = 4387i32;
user_in_canada: i32 = 0i32;
user_in_italy: i32 = 0i32;
user_in_spain: i32 = 0i32;
user_in_united_kingdom: i32 = 0i32;
user_in_usa: i32 = 32767i32;
Let's grab the first one and paste in aleo_book_recommender.in file.
Run the following command to compile and execute smart contract:
leo run
# 5144i32
Okay we've got positive result, so our model works as expected.
Let's try the second one:
leo run
# -5290i32
Okay we've got negative result, so our model works as expected.
This is how you can build privacy-preserving recommender system using Aleo framework. Score of the model is not very high, but you can improve it by adding more features and using more complex model.