Targeted ads without user tracking!
Table of Contents
AnonymousAds is a web application that serves targeted advertising to users, without compromising user privacy. It uses fully homomorphic encryption (FHE) and noise injection to allow for these ads to be served. For more information, you can watch our team's video. This project is a submission to TikTok TechJam 2024 to address Problem Statement 1: Innovating Privacy.
- ConcreteML
- Flask
- NTLK
- Docker
- Sklearn
- Torch
- Pandas
- numpy
- requests
- shutil
The dev
container contains all files and code required to generate pre-requisites.
- The ML model is fitted on clear training data.
- The model is compiled and then used to generate
server.zip
andclient.zip
in thedev/fhe_directory/
directory
Fully Homomorphic Encryption (provided by the Concrete-ML library) allows us to apply functions to encrypted data, for them to be in effect, when decryption takes place later. This allows encryption and decryption to be entirely on the local machine, and yet allow the encrypted data to be processed on an external machine. As a proof of concept, this project uses FHE to serve targeted advertising to end-users, while ensuring the privacy of their search history.
- The
search-engine
generates public keys and sends it to theserver
. - The user inputs 5 search queries into the
search-engine
. - The search queries is processed into vector, encrypted and is sent to
server
. - The
server
takes this input runs the model, and sends the still encrypted predictions back to thesearch-engine
. - The
search-engine
decrypts the predictions and updates its predictions. - The
search-engine
makes a request to theserver
for ads, adding noise to the request, obfuscating the predictions. - The
search-engine
selects the relevant ads from this set of ads, and serves the targeted ads to the user.
AnonymousAds is built to run on desktops.
To get a local copy of AnonymousAds up and running follow these simple steps.
Docker desktop is required to run the application.
Download Docker at https://www.docker.com/products/docker-desktop/
We recommend having at least 6GB of Disk Space and 4GB of RAM.
This proof of concept was tested on Windows 11 and Ubuntu. It was also tested with Firefox, Google Chrome, and Microsoft Edge. If you face any issues, please free to let us know.
-
Clone the repo
git clone https://github.com/Apzure/AnonymousAds.git
-
Open Docker desktop
-
Enter in the terminal
docker compose up --build
-
Open up the link http://127.0.0.1:5000 provided in the terminal
- When the opening the link above, you will be greeted by this landing page. Enter your queries into the search bar and hit ENTER or click the search button on the right.
- Initially, there would be no ads displayed on the page.
- Every 5 queries, the page would be automatically updated with new ads based on your search results. It would take 5-10 seconds for the ads to be updated. See Queries and Keywords for more information.
- You can view your past queries by clicking on the history icon on the top left corner. Click on the same icon to hide your history.
- You view the logs on Docker Desktop for more information.
As you input more queries, our search engine tracks and updates your preferences using a Bayesian update scheme. Initially, the engine makes larger adjustments to its predictions as it gathers more information. Over time, as more queries are entered, the model stabilizes, and the ads displayed become more consistent.
To help our machine learning model categorize your queries effectively, please include the following keywords. Your queries can contain punctuation and additional words besides the keywords. The keywords are not case-sensitive, and you can use different words with the same "stem" as the keyword. For more about stemming, see the nltk documentation for more about stemming.
Example: "games" shares the same stem "gam" as "gaming" which is a keyword, so "games" would be picked up by the model.
sports, fitness, athletics, training, running, gear, gym, exercise, sportswear, outdoors, wellness
food, cuisine, gourmet, organic, recipes, delivery, dining, snacks, cooking, restaurants, healthy
music, concerts, streaming, instruments, bands, festivals, songs, albums, lessons, dj, sound
gaming, consoles, accessories, esports, multiplayer, virtual, pc, development, merchandise, livestream, communities
tv, dramas, shows, smart, reviews, theater, cable, series, reality, channels, binge, sports, food, music, gaming, tv
As described in the methodology above, the server.zip
and client.zip
files are used to generate the public keys and stores the model for the server. If you would like to train the model yourself and generate these files, you can follow these steps:
-
Enable the
dev
container by settingENABLE_DEV_SERVICE=1
in the.env
file in the root of the repo -
Open Docker desktop
-
Enter in the terminal
docker compose up --build
-
The
dev
container should be running on Docker Desktop, you can view the logs and track the progress of the model -
Once the
dev
container has exited, access the files generated by the container underdev/fhe_directory/
. You can save them in your local machine. You may delete the other two containers after this. -
Replace the respective zip files in
search-engine/fhe
andserver/fhe
-
Run
docker compose up --build
again, and the model is now the newly trained model!
Note that we have chosen to display top 2 ads from 2 different categories. This means that if the user has searches that only focuses on one category e.g. sports, which normally only occurs with low quantites of searches, one of the ads may be relatively untargeted.
We used royalty-free stock photos in our application. For more information, see docs/credits.txt
in our repo.