Skip to content
This repository was archived by the owner on Apr 8, 2026. It is now read-only.

Repository files navigation

Privacy-Preserving Neural Processes for Probabilistic User Modeling

This code repository is for our paper Privacy-Preserving Neural Processes for Probabilistic User Modeling (in python). In this work, we explore the integration of Neural Processes with Differential Privacy using DP-SGD and PLD for user-level privacy in probabilistic user modeling. This is a python implementation of this Julia repo.

Features

  • Neural Process-based user modeling: Learn probabilistic representations of user behavior.

  • Differential Privacy Integration: Achieve privacy-preserving predictions with DP-SGD and PLD.

  • Customizable Pipeline: Adapt the model for various user data types and privacy budgets.

Contact Details

This repo was developed by Jonathan Taylor, Research IT, University of Manchester.

Questions about the scientific content should be directed to the paper's corresponding author, Haripriya Harikumar.

Installation Instructions

  1. Clone and enter the repo, then switch to the main branch for the latest release:

    git clone https://github.com/AI-Fundamentals/dp-priv-python.git
    cd dp-priv-python
    git checkout main

    NB if using CSF, please ignore the rest of the instructions and follow the workflow in the jobscripts folder.

  2. Create and activate a python 3.11 environment

  3. Install packages from pip:

    pip install -r requirements.txt
  4. Install PyTorch:

    • On a system with Nvidia GPU:
    pip install torch==2.3.0
    • On Mac with Silicon GPU:
    pip install --pre torch==2.3.0 --extra-index-url https://download.pytorch.org/whl/nightly/cpu
    • On high-performance computing systems, refer to the relevant documentation.
  5. Test the environment installation:

    pytest tests/test_nps.py
  6. Run unit tests:

    python -m pytest

Training and Evaluation

Training data

This repo requires pre-computed data which are generated using this Julia code.

Example training

To run the training for experiment 2:

python -m experiments.train -settings settings/ex2/settings_ex2_train.json

Settings must be loaded from a valid json file. If no valid file is found (or the -settings argument isn't used), the default settings will be loaded instead. For full details of the settings files, and some example files, see the settings folder.

Re-training a pre-trained model

In the training settings json file, there is an item 'init_weights'. Set this to the path of a file containing weights from a previous model training run. These weights will then be used as the initial training weights.

Example validation

To run the validation script (i.e. model performance vs number of training epochs) for experiment 2:

python -m experiments.val -settings settings/ex2/settings_ex2_val.json

This will then save a figure in your figs_dir folder from the settings file, and also the evaluation metrics will also be saved in the models_dir folder.

Example evaluation

To run the n_traj evaluation (i.e. model performance vs number of context trajectories), run the experiment2_eval_ntraj script:

python -m experiments.eval_ntraj -settings settings/ex2/settings_ex2_val.json

Workflow Overview

  1. Generate training data using the Julia data generation code.
  2. Run training script experiments/train.py with an appropriate settings file. Load training data from data folder. Save model weights and metadata parameters in models folder. Save training metrics plot to figures folder.
  3. Run experiments/val.py, with an appropriate settings file, to validate model performance for different numbers of training epochs.
  4. Run experiments/eval_ntraj.py, with an appropriate settings file, to evaluate model performence for different numbers of inference trajectories. This requires the user to specify a specific set of model weights to use- this will likely be the best training epoch (as evaluated during step 3).
  5. Load test performance data from CSV files and plot. Save to figures folder.

For a detailed description of the workflow, see the jobscripts folder.

Settings Files

Each model training or evaluation run requires a json settings file (otherwise a set of default settings will be used). Example files, and a detailed explanation of the various settings, are given in the settings folder.

Scripts Folder

The scripts folder contains some useful scripts. Most of these are for plotting the final output data by loading the CSV files created during steps 3 and 4 in the workflow overview section.

About

Differentially Private Probabilistic User Modelling (in python)

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages