Skip to main content

Dataset fingerprinting library

Project description

Dataset fingerprinting

This repository contains our proof-of-concept for fingerprinting a dataset.

Local installation

git clone https://github.com/trailofbits/datasig && cd datasig
uv sync

Usage

Fingerprinting

The code below shows experimental usage of the library. This will be subject to frequent changes in early development stages.

from torchvision.datasets import MNIST
from datasig.dataset import TorchVisionDataset
from datasig.algo import KeyedShaMinHash, UID

torch_dataset = MNIST(root="/tmp/data", train=True, download=True)

# Wrap the dataset with one of the classes in `datasig.dataset`.
# These classes provide a uniform interface to access serialized data points.
dataset = TorchVisionDataset(torch_dataset)

# Pass the dataset to the fingerprinting algorithm.
print("Dataset UID: ", UID(dataset).digest())
print("Dataset fingerprint: ", KeyedShaMinHash(dataset).digest())

Manual serialization/deserialization

The dataset classes defined in datasig.dataset provide static serialization and deserialization to convert datapoints between their usual representation and bytes.

from torchvision.datasets import MNIST
from datasig.dataset import TorchVisionDataset

torch_dataset = MNIST(root="/tmp/data", train=True, download=True)

# Serializing data points to bytes
serialized = TorchVisionDataset.serialize_data_point(torch_dataset[0])

# Deserializing data points from bytes
deserialized = TorchVisionDataset.deserialize_data_point(serialized)

Development

Unit tests

Tests are in the datasig/test directory. You can run the tests with:

uv run python -m pytest # Run all tests
uv run python -m pytest -s datasig/test/test_csv.py # Run only one test file
uv run python -m pytest -s datasig/test/test_csv.py -k test_similarity # Run only one specific test function

Profiling

The profiling script generates a profile for dataset processing and fingerprint generation using cProfile. To profile the MNIST dataset from the torch framework, you can run:

uv run python profiling.py torch_mnist --full

The --full argument tells the script to include dataset canonization, UID generation, and fingerprint generation in the profile. If you want to profile only some of these steps you can cherry pick by using or omitting the following arguments instead:

uv run python profiling.py torch_mnist --canonical --uid --fingerprint

You can optionally specify the datasig config version to use (at the time of writing we have only v0) with:

uv run python profiling.py torch_mnist -v 0 --all

Currently we support only one target dataset: torch_mnist. To add another dataset, add a class in profiling.py similar to TorchMNISTV0, that implements the _setup() method which is responsible for loading the dataset.

Benchmarking

!!! This is currently broken !!!

Datasig has a built-in benchmark module that allows to run experiments to benchmark speed and accuracy of various fingerprinting methods with varying configurations and on several datasets.

Benchmarks are configured programmatically using the datasig library directly. The benchmarking.py script gives a comprehensive overview of how to configure and run a benchmark, export results, as well as plot them on graph.

You can run the example benchmark with

uv run python benchmarking.py

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

datasig-0.0.6.tar.gz (88.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

datasig-0.0.6-py3-none-any.whl (93.1 kB view details)

Uploaded Python 3

File details

Details for the file datasig-0.0.6.tar.gz.

File metadata

  • Download URL: datasig-0.0.6.tar.gz
  • Upload date:
  • Size: 88.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for datasig-0.0.6.tar.gz
Algorithm Hash digest
SHA256 9660a9433d3a4a7da0f6c73ab369b2c62f8fd4e0c13b392c71ba799d4281a8ee
MD5 aad4076eb73cdf684daa3b9d66b9d348
BLAKE2b-256 7b5ef5fadaffb71ac0513e5d39c4b16ea260cafb74983932e0cf1c986bb7ef20

See more details on using hashes here.

Provenance

The following attestation bundles were made for datasig-0.0.6.tar.gz:

Publisher: release.yml on trailofbits/datasig

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file datasig-0.0.6-py3-none-any.whl.

File metadata

  • Download URL: datasig-0.0.6-py3-none-any.whl
  • Upload date:
  • Size: 93.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for datasig-0.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 d4a3ff1e6c555f6269f04a8bb8e58377f90d2f51e85c976037cf50efc415e683
MD5 14e49a8b16dc2448d8a2e430533fec24
BLAKE2b-256 059e547891261aa5a8a29b77133a8a9f246d6e1d579433797755eb8d350a9085

See more details on using hashes here.

Provenance

The following attestation bundles were made for datasig-0.0.6-py3-none-any.whl:

Publisher: release.yml on trailofbits/datasig

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page