/PyVertical

Privacy Preserving Vertical Federated Learning

Primary LanguagePythonApache License 2.0Apache-2.0

om-logo

Tests License OpenCollective

PyVertical

A project developing privacy-preserving, vertically-distributed learning.

  • 🔗 Links vertically partitioned data without exposing membership using Private Set Intersection (PSI)
  • 🔒 Trains a model on vertically partitioned data using SplitNNs, so only data holders can access data

Vertically-partitioned data is data in which fields relating to a single record are distributed across multiple datasets. For example, multiple hospitals may have admissions data on the same individuals. Vertically-partitioned data could be applied to solve vital problems, but data holders can't combine their datasets by simply comparing notes with other data holders unless they want to break user privacy. PyVertical uses PSI to link datasets in a privacy-preserving way. We train SplitNNs on the partitioned data to ensure the data remains separate throughout the entire process.

See the changelog for information on the current status of PyVertical.

The Process

PyVertical diagram

PyVertical process:

  1. Create partitioned dataset
    • Simulate real-world partitioned dataset by splitting MNIST into a dataset of images and a dataset of labels
    • Give each data point (image + label) a unique ID
    • Randomly shuffle each dataset
    • Randomly remove some elements from each dataset
  2. Link datasets using PSI
    • Use PSI to link indices in each dataset using unique IDs
    • Reorder datasets using linked indices
  3. Train a split neural network
    • Hold both datasets in a dataloader
    • Send images to first part of split network
    • Send labels to second part of split network
    • Train the network

Requirements

This project is written in Python. The work is displayed in jupyter notebooks.

Environment

To install the dependencies, we recommend using Conda:

  1. Clone this repository
  2. In the command line, navigate to your local copy of the repository
  3. Run conda env create -f environment.yml
    • This creates an environment pyvertical-dev
    • Comes with most dependencies you will need
  4. Activate the environment with conda activate pyvertical-dev
  5. Run pip install syft[udacity]
  6. Run conda install notebook

N.b. Installing the dependencies takes several steps to circumvent versioning incompatibility between syft and jupyter. In the future, all packages will be moved into the environment.yml.

PSI

In order to use PSI with PyVertical, you need to install bazel to build the necessary Python bindings for the C++ core. After you have installed bazel, run the build script with .github/workflows/scripts/build-psi.sh.

This should generate a _psi_bindings.so file and place it in src/psi/.

Docker

You can instead opt to use Docker.

To run:

  1. Build the image with docker build -t pyvertical:latest .
  2. Launch a container with docker run -it -p 8888:8888 pyvertical:latest
  • Defaults to launching jupyter lab

Usage

Check out examples/PyVertical Example.ipynb to see PyVertical in action.

Goals

  • MVP
    • Simple example on MNIST dataset
    • One data holder has images, the other has labels
  • Extension demonstration
    • Apply process to electronic health records (EHR) dataset
    • Dual-headed SplitNN: input data is split amongst several data holders
  • Integrate with syft

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Read the OpenMined contributing guidelines and styleguide for more information.

Contributors

TTitcombe Pavlos-P H4ll rsandmann
TTitcombe Pavlos-p H4LL rsandmann

Testing

We use pytest to test the source code. To run the tests manually:

  1. In the command line, navigate to the root of this repository
  2. Run python -m pytest

CI also checks the code conforms to flake8 standards and black formatting

License

Apache License 2.0