Skip to main content

No project description provided

Project description

tokenfool

Widely recognized methods for producing adversarial examples (e.g., PGD, FGSM) were developed and popularized in the context of convolutional neural network (CNN)-based image models. These attacks operate in continuous input space and rely on end-to-end differentiability; in practice, they are typically applied as pixel-level perturbations to induce misclassification. Existing open-source adversarial toolkits such as Foolbox, CleverHans, and Adversarial Robustness Toolbox (ART) consolidate these implementations, enabling users to benchmark robustness and evaluate defenses through standardized interfaces.

In recent years, transformer-based models have emerged as a dominant alternative to CNNs in computer vision. Architectures such as ViT, DeiT, Swin, and DETR replace convolutional feature extraction with patch tokenization and self-attention mechanisms. These models are now widely deployed across classification, detection, and segmentation tasks. Like CNNs, vision transformers are vulnerable to adversarial examples under standard white-box gradient attacks. However, their token-based representation and global self-attention introduce different structural sensitivities compared to convolutional architectures. In addition to conventional pixel-space perturbations, transformers are susceptible to structured patch-level attacks, token/embedding-space perturbations, and attacks that exploit attention distributions or object query representations in detection models.

About

TokenFool is an open-source toolkit for adversarial attacks on image transformers. It is modular and extensible, enabling straightforward integration of new attack algorithms. Attacks operate under gradient-based white-box assumptions and integrate directly with standard PyTorch training and evaluation workflows. Users can support their own models by implementing the interface contract expected by the attacks. This keeps attack code separate from provider-specific or model-specific wiring and makes it possible to extend TokenFool beyond the built-in adapters.

Current Status

TokenFool currently includes:

  • a core tokenfool package for attack implementations
  • an adapter/interface layer for transformer classifier integrations
  • example usage notebooks
  • automated test coverage
  • repository CI workflows

Current attack coverage includes:

  • Patch-Fool (paper)
  • Adaptive Token Tuning (ATT) (paper)

Current model support is focused on:

  • timm-style ViT/DeiT classifier implementations
  • user-defined models that implement the required interface contract via a custom adapter

Next Steps

Planned expansion areas include:

  • additional transformer-specific attack methods
  • broader model-family and provider coverage
  • support for non-classification transformer settings through new interfaces and adapters

TokenFool Architecture

Architecture diagram

The library is structured as a layered system: attacks depend on stable interface contracts rather than directly on model implementations. Concrete adapters bridge those interfaces to supported model implementations, while custom adapters provide the path for integrating user-owned models without changing attack logic.

Development

  1. Clone the repository
    (External contributors: fork the repository first, then clone your fork)
git clone https://github.com/TrustThink/tokenfool.git
cd tokenfool
  1. (Recommended) Create a virtual environment

  2. Install the project in editable mode with development dependencies

pip install -e ".[dev]"
  1. Make changes on a new branch, including tests were appropriate

  2. Run tests

pytest
  1. Run lint checks
ruff check
  1. Open a Pull Request

Repository checks also run through GitHub Actions.

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

tokenfool-0.1.1.tar.gz (21.6 kB view details)

Uploaded Source

Built Distribution

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

tokenfool-0.1.1-py3-none-any.whl (19.8 kB view details)

Uploaded Python 3

File details

Details for the file tokenfool-0.1.1.tar.gz.

File metadata

  • Download URL: tokenfool-0.1.1.tar.gz
  • Upload date:
  • Size: 21.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for tokenfool-0.1.1.tar.gz
Algorithm Hash digest
SHA256 b5cb1f537ca5735de12903c93b55dd7f4b41995f345487714f0ea98ad252be90
MD5 b213e5d780680b1d693da7f94f22c49f
BLAKE2b-256 b96e4c00575e66369418db1d9ff4d51c24c9801963ce4f3c72a18e3e4c98d7fb

See more details on using hashes here.

Provenance

The following attestation bundles were made for tokenfool-0.1.1.tar.gz:

Publisher: publish.yml on TrustThink/tokenfool

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

File details

Details for the file tokenfool-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: tokenfool-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 19.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for tokenfool-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4a7ec64df6f68fd36d552dcd5e631d1ebb9a6bfdfe003da7e7e6d6f869403eb0
MD5 b9e57fb384fb3d013ad1a0916df5653d
BLAKE2b-256 b4ae27ec472e91b049a933e00859bb37290b4e047f57ae20013228b1b547446e

See more details on using hashes here.

Provenance

The following attestation bundles were made for tokenfool-0.1.1-py3-none-any.whl:

Publisher: publish.yml on TrustThink/tokenfool

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