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
tokenfoolpackage for attack implementations - an adapter/interface layer for transformer classifier integrations
- example usage notebooks
- automated test coverage
- repository CI workflows
Current attack coverage includes:
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
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
- Clone the repository
(External contributors: fork the repository first, then clone your fork)
git clone https://github.com/TrustThink/tokenfool.git
cd tokenfool
-
(Recommended) Create a virtual environment
-
Install the project in editable mode with development dependencies
pip install -e ".[dev]"
-
Make changes on a new branch, including tests were appropriate
-
Run tests
pytest
- Run lint checks
ruff check
- Open a Pull Request
Repository checks also run through GitHub Actions.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file tokenfool-0.0.1.tar.gz.
File metadata
- Download URL: tokenfool-0.0.1.tar.gz
- Upload date:
- Size: 20.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5b168bd36357af2d830cd28bb4c7c366bed0a6d48ef1a6641d0f39ee5986e32f
|
|
| MD5 |
a00de6224ebcef10475aafd2ba6c5f23
|
|
| BLAKE2b-256 |
5d637426c1a2e4badff9abe2cc0f9f79a2a65858b78bc0270946156d158d60a5
|
File details
Details for the file tokenfool-0.0.1-py3-none-any.whl.
File metadata
- Download URL: tokenfool-0.0.1-py3-none-any.whl
- Upload date:
- Size: 16.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0586136335e34adb5c8c2cbcda57ad5f9a492f11dfd310fe2e729d14d3a36ba8
|
|
| MD5 |
95cc825761787b073530c73e8bd2991b
|
|
| BLAKE2b-256 |
bcabe2c08463f41259666e458554b1bda3341c7224768ddae1b773e20629563b
|