mia

A library for running membership inference attacks against ML models

https://github.com/spring-epfl/mia

Science Score: 23.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
  • .zenodo.json file
  • DOI references
    Found 4 DOI reference(s) in README
  • Academic publication links
    Links to: arxiv.org, zenodo.org
  • Committers with academic emails
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (14.2%) to scientific vocabulary

Keywords

adversarial-machine-learning machine-learning privacy
Last synced: 6 months ago · JSON representation

Repository

A library for running membership inference attacks against ML models

Basic Info
  • Host: GitHub
  • Owner: spring-epfl
  • License: mit
  • Language: Python
  • Default Branch: master
  • Homepage:
  • Size: 71.3 KB
Statistics
  • Stars: 149
  • Watchers: 6
  • Forks: 28
  • Open Issues: 20
  • Releases: 0
Archived
Topics
adversarial-machine-learning machine-learning privacy
Created over 7 years ago · Last pushed about 3 years ago
Metadata Files
Readme Contributing License

README.rst

--------

**ATTENTION:** This library is not maintained at the moment due to lack of capacity. There's a plan to eventually update it, but meanwhile check out `these `_ `projects `_ for more up-to-date attacks. 

--------

###
mia
###

|pypi| |license| |build_status| |docs_status| |zenodo|

.. |pypi| image:: https://img.shields.io/pypi/v/mia.svg
   :target: https://pypi.org/project/mia/
   :alt: PyPI version

.. |build_status| image:: https://travis-ci.org/spring-epfl/mia.svg?branch=master
   :target: https://travis-ci.org/spring-epfl/mia
   :alt: Build status

.. |docs_status| image:: https://readthedocs.org/projects/mia-lib/badge/?version=latest
   :target: https://mia-lib.readthedocs.io/?badge=latest
   :alt: Documentation status

.. |license| image:: https://img.shields.io/pypi/l/mia.svg
   :target: https://pypi.org/project/mia/
   :alt: License

.. |zenodo| image:: https://zenodo.org/badge/DOI/10.5281/zenodo.1433744.svg
   :target: https://zenodo.org/record/1433744
   :alt: Citing with the Zenodo

A library for running membership inference attacks (MIA) against machine learning models. Check out
the `documentation `_.

.. description-marker-do-not-remove

These are attacks against privacy of the training data. In MIA, an attacker tries to guess whether a
given example was used during training of a target model or not, only by querying the model. See
more in the paper by `Shokri et al `_. Currently, you can use the
library to evaluate the robustness of your Keras or PyTorch models to MIA.

Features:

* Implements the original shadow model `attack `_
* Is customizable, can use any scikit learn's ``Estimator``-like object as a shadow or attack model
* Is tested with Keras and PyTorch

.. getting-started-marker-do-not-remove

===============
Getting started
===============

You can install mia from PyPI:

.. code-block::  bash

    pip install mia

.. usage-marker-do-not-remove

=====
Usage 
=====

Shokri et al. attack
====================

See the `full runnable example
`_.  Read the details of the
attack in the `paper `_.

Let ``target_model_fn()`` return the target model architecture as a scikit-like classifier. The
attack is white-box, meaning the attacker is assumed to know the architecture. Let ``NUM_CLASSES``
be the number of classes of the classification problem.

First, the attacker needs to train several *shadow models* —that mimick the target model—
on different datasets sampled from the original data distribution. The following code snippet
initializes a *shadow model bundle*, and runs the training of the shadows. For each shadow model,
``2 * SHADOW_DATASET_SIZE`` examples are sampled without replacement from the full attacker's
dataset.  Half of them will be used for control, and the other half for training of the shadow model.

.. code-block::  python

    from mia.estimators import ShadowModelBundle

    smb = ShadowModelBundle(
        target_model_fn,
        shadow_dataset_size=SHADOW_DATASET_SIZE,
        num_models=NUM_MODELS,
    )
    X_shadow, y_shadow = smb.fit_transform(attacker_X_train, attacker_y_train)

``fit_transform`` returns *attack data* ``X_shadow, y_shadow``. Each row in ``X_shadow`` is a
concatenated vector consisting of the prediction vector of a shadow model for an example from the
original dataset, and the example's class (one-hot encoded). Its shape is hence ``(2 *
SHADOW_DATASET_SIZE, 2 * NUM_CLASSES)``. Each label in ``y_shadow`` is zero if a corresponding
example was "out" of the training dataset of the shadow model (control), or one, if it was "in" the
training.

mia provides a class to train a bundle of attack models, one model per class. ``attack_model_fn()``
is supposed to return a scikit-like classifier that takes a vector of model predictions ``(NUM_CLASSES, )``,
and returns whether an example with these predictions was in the training, or out.

.. code-block::  python
    
    from mia.estimators import AttackModelBundle
    
    amb = AttackModelBundle(attack_model_fn, num_classes=NUM_CLASSES)
    amb.fit(X_shadow, y_shadow)

In place of the ``AttackModelBundle`` one can use any binary classifier that takes ``(2 *
NUM_CLASSES, )``-shape examples (as explained above, the first half of an input is the prediction
vector from a model, the second half is the true class of a corresponding example).

To evaluate the attack, one must encode the data in the above-mentioned format. Let ``target_model`` be
the target model, ``data_in`` the data (tuple ``X, y``) that was used in the training of the target model, and
``data_out`` the data that was not used in the training.
    
.. code-block::  python

    from mia.estimators import prepare_attack_data    

    attack_test_data, real_membership_labels = prepare_attack_data(
        target_model, data_in, data_out
    )

    attack_guesses = amb.predict(attack_test_data)
    attack_accuracy = np.mean(attack_guesses == real_membership_labels)

.. misc-marker-do-not-remove

======
Citing
======

.. code-block::

   @misc{mia,
     author       = {Bogdan Kulynych and
                     Mohammad Yaghini},
     title        = {{mia: A library for running membership inference 
                      attacks against ML models}},
     month        = sep,
     year         = 2018,
     doi          = {10.5281/zenodo.1433744},
     url          = {https://doi.org/10.5281/zenodo.1433744}
   }

Owner

  • Name: SPRING Lab
  • Login: spring-epfl
  • Kind: organization

Security and Privacy Engineering Laboratory @ EPFL

GitHub Events

Total
  • Watch event: 15
  • Fork event: 2
Last Year
  • Watch event: 15
  • Fork event: 2

Committers

Last synced: over 2 years ago

All Time
  • Total Commits: 10
  • Total Committers: 2
  • Avg Commits per committer: 5.0
  • Development Distribution Score (DDS): 0.2
Past Year
  • Commits: 0
  • Committers: 0
  • Avg Commits per committer: 0.0
  • Development Distribution Score (DDS): 0.0
Top Committers
Name Email Commits
Bogdan Kulynych h****o@b****e 8
Bogdan Kulynych b****h 2
Committer Domains (Top 20 + Academic)

Issues and Pull Requests

Last synced: 6 months ago

All Time
  • Total issues: 13
  • Total pull requests: 10
  • Average time to close issues: 14 days
  • Average time to close pull requests: over 1 year
  • Total issue authors: 13
  • Total pull request authors: 2
  • Average comments per issue: 0.54
  • Average comments per pull request: 0.1
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 9
Past Year
  • Issues: 0
  • Pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Issue authors: 0
  • Pull request authors: 0
  • Average comments per issue: 0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • NickMeeker (1)
  • ogencoglu (1)
  • nabladev (1)
  • fpiedrah (1)
  • amanoel (1)
  • Kickstaro (1)
  • icmpnorequest (1)
  • zliangak (1)
  • trevorcohen (1)
  • blackvvine (1)
  • Zeltserj (1)
  • opupo2021 (1)
  • ineiti (1)
Pull Request Authors
  • dependabot[bot] (9)
  • blackvvine (1)
Top Labels
Issue Labels
Pull Request Labels
dependencies (9)

Packages

  • Total packages: 2
  • Total downloads:
    • pypi 63 last-month
  • Total dependent packages: 0
    (may contain duplicates)
  • Total dependent repositories: 4
    (may contain duplicates)
  • Total versions: 3
  • Total maintainers: 1
proxy.golang.org: github.com/spring-epfl/mia
  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
Rankings
Stargazers count: 4.1%
Forks count: 4.3%
Average: 5.0%
Dependent packages count: 5.6%
Dependent repos count: 5.9%
Last synced: 6 months ago
pypi.org: mia

A library for running membership inference attacks against ML models

  • Versions: 2
  • Dependent Packages: 0
  • Dependent Repositories: 4
  • Downloads: 63 Last month
Rankings
Stargazers count: 6.5%
Dependent repos count: 7.5%
Forks count: 7.6%
Dependent packages count: 10.0%
Average: 10.6%
Downloads: 21.4%
Maintainers (1)
Last synced: 6 months ago

Dependencies

docs/requirements.txt pypi
  • Babel ==2.6.0
  • Jinja2 ==2.10
  • MarkupSafe ==1.0
  • Pygments ==2.2.0
  • Sphinx ==1.8.1
  • alabaster ==0.7.11
  • certifi ==2018.8.24
  • chardet ==3.0.4
  • docutils ==0.14
  • idna ==2.7
  • imagesize ==1.1.0
  • numpy ==1.15.1
  • packaging ==17.1
  • pyparsing ==2.2.1
  • pytz ==2018.5
  • requests ==2.19.1
  • scikit-learn ==0.19.2
  • scipy ==1.1.0
  • six ==1.11.0
  • snowballstemmer ==1.2.1
  • sphinx-rtd-theme ==0.4.1
  • sphinxcontrib-websupport ==1.1.0
  • tqdm ==4.26.0
  • urllib3 ==1.23