saccade-ai 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of saccade-ai might be problematic. Click here for more details.
- saccade_ai-0.1.0/.github/workflows/publish.yml +36 -0
- saccade_ai-0.1.0/.gitignore +50 -0
- saccade_ai-0.1.0/CITATION.cff +19 -0
- saccade_ai-0.1.0/LICENSE +21 -0
- saccade_ai-0.1.0/PKG-INFO +311 -0
- saccade_ai-0.1.0/README.md +274 -0
- saccade_ai-0.1.0/assets/samples/eagle.jpg +0 -0
- saccade_ai-0.1.0/assets/samples/espresso.jpg +0 -0
- saccade_ai-0.1.0/assets/samples/giant_panda.jpg +0 -0
- saccade_ai-0.1.0/assets/samples/golden_retriever.jpg +0 -0
- saccade_ai-0.1.0/assets/samples/sports_car.jpg +0 -0
- saccade_ai-0.1.0/assets/samples/tabby_cat.jpg +0 -0
- saccade_ai-0.1.0/examples/benchmark_faithfulness.py +79 -0
- saccade_ai-0.1.0/examples/generate_intuitive_showcase.py +1019 -0
- saccade_ai-0.1.0/examples/generate_layer_by_layer_inspector.py +1376 -0
- saccade_ai-0.1.0/examples/generate_llm_saccade_interactive.py +591 -0
- saccade_ai-0.1.0/examples/generate_multiscene_showcase.py +937 -0
- saccade_ai-0.1.0/examples/llm_prompt_saccade.py +131 -0
- saccade_ai-0.1.0/examples/quickstart.py +89 -0
- saccade_ai-0.1.0/pyproject.toml +67 -0
- saccade_ai-0.1.0/saccade/__init__.py +39 -0
- saccade_ai-0.1.0/saccade/benchmarks/faithfulness.py +151 -0
- saccade_ai-0.1.0/saccade/bottleneck.py +239 -0
- saccade_ai-0.1.0/saccade/exporter.py +869 -0
- saccade_ai-0.1.0/saccade/models.py +507 -0
- saccade_ai-0.1.0/saccade/text/__init__.py +11 -0
- saccade_ai-0.1.0/saccade/text/token_saccade.py +198 -0
- saccade_ai-0.1.0/saccade/visualization.py +171 -0
- saccade_ai-0.1.0/tests/test_bottleneck.py +61 -0
- saccade_ai-0.1.0/tests/test_exporter.py +45 -0
- saccade_ai-0.1.0/tests/test_faithfulness.py +47 -0
- saccade_ai-0.1.0/tests/test_models.py +102 -0
- saccade_ai-0.1.0/tests/test_text_saccade.py +51 -0
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
name: Publish to PyPI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
release:
|
|
5
|
+
types: [published]
|
|
6
|
+
workflow_dispatch:
|
|
7
|
+
|
|
8
|
+
jobs:
|
|
9
|
+
pypi-publish:
|
|
10
|
+
name: Build and publish Python ๐ distributions ๐ฆ to PyPI
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
permissions:
|
|
13
|
+
# IMPORTANT: this permission is mandatory for trusted publishing (OIDC)
|
|
14
|
+
id-token: write
|
|
15
|
+
environment:
|
|
16
|
+
name: pypi
|
|
17
|
+
url: https://pypi.org/p/saccade-ai
|
|
18
|
+
steps:
|
|
19
|
+
- name: Checkout repository
|
|
20
|
+
uses: actions/checkout@v4
|
|
21
|
+
|
|
22
|
+
- name: Set up Python
|
|
23
|
+
uses: actions/setup-python@v5
|
|
24
|
+
with:
|
|
25
|
+
python-version: "3.11"
|
|
26
|
+
|
|
27
|
+
- name: Install build dependencies
|
|
28
|
+
run: |
|
|
29
|
+
python -m pip install --upgrade pip
|
|
30
|
+
pip install build
|
|
31
|
+
|
|
32
|
+
- name: Build binary wheel and source tarball
|
|
33
|
+
run: python -m build
|
|
34
|
+
|
|
35
|
+
- name: Publish package distributions to PyPI
|
|
36
|
+
uses: pypa/gh-action-pypi-publish@release/v1
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
__pycache__/
|
|
2
|
+
*.py[cod]
|
|
3
|
+
*$py.class
|
|
4
|
+
*.so
|
|
5
|
+
.Python
|
|
6
|
+
env/
|
|
7
|
+
build/
|
|
8
|
+
develop-eggs/
|
|
9
|
+
dist/
|
|
10
|
+
downloads/
|
|
11
|
+
eggs/
|
|
12
|
+
.eggs/
|
|
13
|
+
lib/
|
|
14
|
+
lib64/
|
|
15
|
+
parts/
|
|
16
|
+
sdist/
|
|
17
|
+
var/
|
|
18
|
+
wheels/
|
|
19
|
+
*.egg-info/
|
|
20
|
+
.installed.cfg
|
|
21
|
+
*.egg
|
|
22
|
+
|
|
23
|
+
# Pytest / coverage
|
|
24
|
+
.pytest_cache/
|
|
25
|
+
.coverage
|
|
26
|
+
htmlcov/
|
|
27
|
+
|
|
28
|
+
# Environments
|
|
29
|
+
.env
|
|
30
|
+
.venv
|
|
31
|
+
env/
|
|
32
|
+
venv/
|
|
33
|
+
ENV/
|
|
34
|
+
|
|
35
|
+
# IDE
|
|
36
|
+
.idea/
|
|
37
|
+
.vscode/
|
|
38
|
+
*.swp
|
|
39
|
+
*.swo
|
|
40
|
+
.DS_Store
|
|
41
|
+
|
|
42
|
+
# Generated HTML exports & screenshot artifacts
|
|
43
|
+
*.html
|
|
44
|
+
*.png
|
|
45
|
+
assets/*.html
|
|
46
|
+
assets/*.png
|
|
47
|
+
examples/*.html
|
|
48
|
+
|
|
49
|
+
# Keep evaluation sample images
|
|
50
|
+
!assets/samples/*.jpg
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
cff-version: 1.2.0
|
|
2
|
+
message: "If you use saccade in your research or applications, please cite it as below."
|
|
3
|
+
authors:
|
|
4
|
+
- family-names: "Patel"
|
|
5
|
+
given-names: "Daksh"
|
|
6
|
+
title: "saccade: Intrinsic Attention Bottlenecks for Vision Transformers and LLM Prompt Compression"
|
|
7
|
+
version: 0.1.0
|
|
8
|
+
date-released: 2026-11-04
|
|
9
|
+
url: "https://github.com/helloitsdaksh/saccade"
|
|
10
|
+
repository-code: "https://github.com/helloitsdaksh/saccade"
|
|
11
|
+
license: MIT
|
|
12
|
+
keywords:
|
|
13
|
+
- vision-transformer
|
|
14
|
+
- interpretability
|
|
15
|
+
- attention-bottleneck
|
|
16
|
+
- prompt-compression
|
|
17
|
+
- llm
|
|
18
|
+
- pytorch
|
|
19
|
+
|
saccade_ai-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Daksh Patel
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: saccade-ai
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Intrinsic Attention Bottlenecks for Vision Transformers & LLM Prompt Compression.
|
|
5
|
+
Project-URL: Homepage, https://github.com/helloitsdaksh/saccade
|
|
6
|
+
Project-URL: Repository, https://github.com/helloitsdaksh/saccade
|
|
7
|
+
Project-URL: Documentation, https://github.com/helloitsdaksh/saccade#readme
|
|
8
|
+
Author-email: Daksh Patel <helloitsdaksh007@gmail.com>
|
|
9
|
+
License-Expression: MIT
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Keywords: attention-bottleneck,explainable-ai,interpretability,llm,mechanistic-interpretability,prompt-compression,pytorch,token-pruning,vision-transformer
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: Intended Audience :: Science/Research
|
|
15
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
21
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
22
|
+
Requires-Python: >=3.9
|
|
23
|
+
Requires-Dist: matplotlib>=3.5.0
|
|
24
|
+
Requires-Dist: numpy>=1.20.0
|
|
25
|
+
Requires-Dist: pillow>=9.0.0
|
|
26
|
+
Requires-Dist: scipy>=1.9.0
|
|
27
|
+
Requires-Dist: timm>=0.9.0
|
|
28
|
+
Requires-Dist: torch>=2.0.0
|
|
29
|
+
Requires-Dist: torchvision>=0.15.0
|
|
30
|
+
Requires-Dist: transformers>=4.30.0
|
|
31
|
+
Provides-Extra: dev
|
|
32
|
+
Requires-Dist: build>=1.0.0; extra == 'dev'
|
|
33
|
+
Requires-Dist: pytest>=7.0.0; extra == 'dev'
|
|
34
|
+
Requires-Dist: ruff>=0.1.0; extra == 'dev'
|
|
35
|
+
Requires-Dist: twine>=4.0.0; extra == 'dev'
|
|
36
|
+
Description-Content-Type: text/markdown
|
|
37
|
+
|
|
38
|
+
# saccade ๐๏ธโก
|
|
39
|
+
|
|
40
|
+
[](https://github.com/helloitsdaksh/saccade)
|
|
41
|
+
[](https://www.python.org/)
|
|
42
|
+
[](https://pytorch.org/)
|
|
43
|
+
[](https://opensource.org/licenses/MIT)
|
|
44
|
+
[](#guaranteed-causal-faithfulness)
|
|
45
|
+
|
|
46
|
+
> *"Don't explain the black box after the crime was committed. Physically blindfold the model."*
|
|
47
|
+
|
|
48
|
+
**saccade** is an open-source Python library for **Intrinsically Interpretable Vision Transformers (ViTs)** and **LLM Prompt Token Compression**. Instead of relying on post-hoc saliency heuristics (like Grad-CAM) that generate plausible-looking "interpretability illusions", `saccade` introduces an explicit **hard attention bottleneck** that physically discards uninformative tokens.
|
|
49
|
+
|
|
50
|
+
1. **Vision ViT Saccading**: Discard up to **94% of image patches** while preserving full diagnostic accuracy. Downstream predictions are causally bound only to the preserved $K$ coordinates ($\partial \hat{y} / \partial x_m \equiv 0$).
|
|
51
|
+
2. **LLM Prompt Saccading**: Prune **60% to 75% of input prompt tokens** by discarding syntactic fluff and conversational padding ("breaking grammar"), slashing API costs, prefill latency, and KV-cache footprint while maintaining reasoning fidelity.
|
|
52
|
+
|
|
53
|
+
---
|
|
54
|
+
|
|
55
|
+
## โก Quickstart
|
|
56
|
+
|
|
57
|
+
Install directly from GitHub via pip:
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
pip install git+https://github.com/helloitsdaksh/saccade.git
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
Or clone for local development:
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
git clone https://github.com/helloitsdaksh/saccade.git
|
|
67
|
+
cd saccade
|
|
68
|
+
pip install -e .
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### 1. Vision ViT Saccade (3 Lines)
|
|
72
|
+
|
|
73
|
+
```python
|
|
74
|
+
import torch
|
|
75
|
+
from saccade import SaccadeViT, export_interactive_html
|
|
76
|
+
|
|
77
|
+
# 1. Instantiate ViT with intrinsic attention bottleneck
|
|
78
|
+
# Only 12 out of 196 patches (6.1% budget) reach downstream layers
|
|
79
|
+
model = SaccadeViT.from_pretrained(
|
|
80
|
+
"vit_tiny_patch16_224",
|
|
81
|
+
num_classes=1000,
|
|
82
|
+
top_k_patches=12,
|
|
83
|
+
bottleneck_layer=6
|
|
84
|
+
)
|
|
85
|
+
|
|
86
|
+
# 2. Forward pass returns class predictions and exact spatial metadata
|
|
87
|
+
image = torch.randn(1, 3, 224, 224)
|
|
88
|
+
logits, meta = model(image, return_saccades=True)
|
|
89
|
+
|
|
90
|
+
print("Preserved Patch Indices:", meta.patch_indices)
|
|
91
|
+
print("Bounding Boxes [ymin, xmin, ymax, xmax]:", meta.bounding_boxes)
|
|
92
|
+
|
|
93
|
+
# 3. Export standalone interactive web visualizer (zero dependencies)
|
|
94
|
+
export_interactive_html(model=model, image=image, output_path="saccade_viewer.html")
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
### 2. LLM Prompt Token Saccade (3 Lines)
|
|
98
|
+
|
|
99
|
+
```python
|
|
100
|
+
from saccade import PromptSaccade
|
|
101
|
+
|
|
102
|
+
# 1. Instantiate the prompt compressor
|
|
103
|
+
compressor = PromptSaccade(model_name="distilgpt2", device="cpu")
|
|
104
|
+
|
|
105
|
+
# 2. Compress prompt by 70% (strips syntactic fluff, retains semantic hubs)
|
|
106
|
+
prompt = (
|
|
107
|
+
"Please carefully review and analyze the following quarterly report and "
|
|
108
|
+
"summarize whether enterprise cloud software revenue grew year-over-year: "
|
|
109
|
+
"'The company reported enterprise cloud revenue surged 34% to $6.8 billion.' "
|
|
110
|
+
"What was the growth rate?"
|
|
111
|
+
)
|
|
112
|
+
|
|
113
|
+
result = compressor.compress(prompt, compression_ratio=0.30)
|
|
114
|
+
|
|
115
|
+
print(result.compressed_text)
|
|
116
|
+
# => "quarterly report summarize enterprise cloud software revenue grew: enterprise cloud revenue surged 34% $6.8 billion. What growth rate?"
|
|
117
|
+
|
|
118
|
+
print(f"Token reduction: {result.token_savings_pct:.1f}% ({result.original_tokens} -> {result.compressed_tokens} tokens)")
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
---
|
|
122
|
+
|
|
123
|
+
## ๐ฌ Core Mechanics: ViT Spatial Bottleneck
|
|
124
|
+
|
|
125
|
+
In standard ViTs, downstream classification heads observe all $N$ tokens across the full image sequence. `saccade` intercepts the self-attention affinity matrix $A$ at an intermediate probing layer $L_b$:
|
|
126
|
+
|
|
127
|
+
```
|
|
128
|
+
Input Image [B, C, H, W]
|
|
129
|
+
โ
|
|
130
|
+
โผ
|
|
131
|
+
Patch Tokenizer & ViT Blocks 0 .. L_b [B, N, D]
|
|
132
|
+
โ
|
|
133
|
+
โผ
|
|
134
|
+
Self-Attention Matrix A โ R^{N ร N} (Layer L_b)
|
|
135
|
+
โ
|
|
136
|
+
โผ
|
|
137
|
+
Patch Importance Voting: p_j = โ_{i=1}^N A_{i, j}
|
|
138
|
+
โ
|
|
139
|
+
โผ
|
|
140
|
+
Hard Top-K Bottleneck (Discard all but K tokens)
|
|
141
|
+
โ
|
|
142
|
+
โผ
|
|
143
|
+
Sparse Downstream Predictor Blocks (L_b + 1 .. L_end)
|
|
144
|
+
โ
|
|
145
|
+
โผ
|
|
146
|
+
Class Prediction ลท (Causally derived ONLY from K patches)
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
### 1. Patch Importance Voting ($p$)
|
|
150
|
+
For an input sequence of $N$ spatial patches, let $A \in \mathbb{R}^{N \times N}$ denote the attention affinity matrix from probing layer $L_b$. The **column sum** represents the total "votes" cast for patch $j$ by all other spatial querying locations:
|
|
151
|
+
|
|
152
|
+
$$p_j = \sum_{i=1}^N A_{i, j}$$
|
|
153
|
+
|
|
154
|
+
### 2. Hard Top-$K$ Spatial Saccade
|
|
155
|
+
The model sorts $p$ and routes only the top-$K$ patches (e.g., $K=12$ out of $196$ patches, representing $< 7\%$ of the visual scene) into subsequent transformer layers:
|
|
156
|
+
|
|
157
|
+
$$\mathcal{J}_K = \text{TopK}(p, K)$$
|
|
158
|
+
|
|
159
|
+
$$\mathbf{Z}_{\text{downstream}} = [\mathbf{z}_{\text{cls}}, \; \mathbf{z}_{\mathcal{J}_K}]$$
|
|
160
|
+
|
|
161
|
+
### 3. Guaranteed Causal Faithfulness
|
|
162
|
+
Downstream predictions are causally bound to only those $K$ patches. All non-selected patches are physically removed from the compute graph:
|
|
163
|
+
|
|
164
|
+
$$\frac{\partial \hat{y}}{\partial x_m} \equiv 0 \quad \forall m \notin \mathcal{J}_K$$
|
|
165
|
+
|
|
166
|
+
---
|
|
167
|
+
|
|
168
|
+
## ๐ฌ LLM Prompt Token Saccading ("Breaking Grammar")
|
|
169
|
+
|
|
170
|
+
Large Language Models do not read like humans. Conversational politeness (*"Could you please assist me by..."*, *"It should be noted that in accordance with..."*) consumes up to **70% of prompt token budgets** and bloats the KV cache with low-information syntactic glue.
|
|
171
|
+
|
|
172
|
+
`PromptSaccade` runs a fast single-pass attention probe over the prompt to calculate:
|
|
173
|
+
1. **Self-Attention In-Degree**: Identifies semantic anchor tokens that subsequent clauses heavily attend to.
|
|
174
|
+
2. **Shannon Entropy Sieve**: Filters out predictable, high-probability syntactic padding.
|
|
175
|
+
|
|
176
|
+
### Empirical Prompt Compression Benchmark
|
|
177
|
+
|
|
178
|
+
Run the benchmark locally:
|
|
179
|
+
```bash
|
|
180
|
+
python examples/llm_prompt_saccade.py
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
| Task Category | Original Tokens | Saccaded Tokens | Tokens Saved | Token Reduction | Estimated Prefill Speedup |
|
|
184
|
+
| :--- | :---: | :---: | :---: | :---: | :---: |
|
|
185
|
+
| **Pathology / Medical Report** | 124 | 39 | 85 | **68.5%** | ~3.2ร |
|
|
186
|
+
| **Financial SEC 10-Q Analysis** | 116 | 34 | 82 | **70.7%** | ~3.4ร |
|
|
187
|
+
| **Python Bug Diagnostic** | 91 | 30 | 61 | **67.0%** | ~3.0ร |
|
|
188
|
+
| **Average Across Workloads** | **110** | **34** | **76** | **68.9%** | **~3.2ร** |
|
|
189
|
+
|
|
190
|
+
*Estimated API savings: **\$2,280 saved per 1M queries** (at \$10/M tokens).*
|
|
191
|
+
|
|
192
|
+
---
|
|
193
|
+
|
|
194
|
+
## ๐ Standalone Interactive Web Artifacts
|
|
195
|
+
|
|
196
|
+
`saccade` includes a built-in exporter that compiles interactive scientific visualizers into a **single, zero-dependency, self-contained HTML file** with embedded base64 assets and client-side canvas rendering:
|
|
197
|
+
|
|
198
|
+
- ๐๏ธ **Real-Time Sparsity Slider**: Vary $K$ dynamically from $1$ to $N$, observing how confidence shifts as visual context is revealed.
|
|
199
|
+
- ๐ฏ **Interactive Patch Ablation**: Click individual active patches to manually disable them, instantly viewing the counterfactual logit penalty:
|
|
200
|
+
$$\Delta \text{logit} = \text{logit}_{\text{base}} - \text{logit}_{\text{ablated}}$$
|
|
201
|
+
- ๐๏ธ **Scanpath Arcs**: Visualizes the model's saccadic fixation order with sleek vector lines and rank tags (`#1`, `#2`, ...).
|
|
202
|
+
- ๐ **Zero Backend Required**: Pure client-side HTML5 Canvas + vanilla JS. No node servers, no Python backends, instant sharing on GitHub Pages or static hosts.
|
|
203
|
+
|
|
204
|
+
---
|
|
205
|
+
|
|
206
|
+
## ๐ Faithfulness Benchmark: Intrinsic vs Post-Hoc
|
|
207
|
+
|
|
208
|
+
| Property | Post-Hoc Saliency (Grad-CAM / IG) | Saccade Intrinsic Bottleneck |
|
|
209
|
+
| :--- | :---: | :---: |
|
|
210
|
+
| **Causal Bound** | โ Heuristic approximation | โ
**100% Causal Guarantee** |
|
|
211
|
+
| **Gradient Leakage on Discarded Pixels** | โ ๏ธ Non-zero everywhere ($\|\nabla_x\| > 0$) | โ
**Identically 0.000000** |
|
|
212
|
+
| **Pruning Capability** | โ None (observes full image) | โ
**Prunes 94% of input tokens** |
|
|
213
|
+
| **AUC-Deletion (Steeper drop is better)** | ~0.35 | **0.166** |
|
|
214
|
+
| **Interactive Perturbation in Browser** | โ Requires live Python backend | โ
**Zero-dependency standalone HTML** |
|
|
215
|
+
|
|
216
|
+
Run the quantitative benchmark:
|
|
217
|
+
```bash
|
|
218
|
+
python examples/benchmark_faithfulness.py
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
---
|
|
222
|
+
|
|
223
|
+
## ๐ Repository Structure
|
|
224
|
+
|
|
225
|
+
```
|
|
226
|
+
saccade/
|
|
227
|
+
โโโ saccade/
|
|
228
|
+
โ โโโ __init__.py # Public API exports
|
|
229
|
+
โ โโโ bottleneck.py # AttentionBottleneck & column-sum voting
|
|
230
|
+
โ โโโ models.py # SaccadeViT wrapper & CleanViT native
|
|
231
|
+
โ โโโ visualization.py # Overlays, scanpaths, & matplotlib breakdown
|
|
232
|
+
โ โโโ exporter.py # Standalone interactive HTML generator
|
|
233
|
+
โ โโโ benchmarks/
|
|
234
|
+
โ โ โโโ faithfulness.py # AUC-Del, AUC-Ins, & gradient leakage test
|
|
235
|
+
โ โโโ text/
|
|
236
|
+
โ โโโ token_saccade.py # LLM prompt token saccader & entropy compression
|
|
237
|
+
โโโ examples/
|
|
238
|
+
โ โโโ quickstart.py # ViT end-to-end quickstart & HTML exporter
|
|
239
|
+
โ โโโ llm_prompt_saccade.py # LLM prompt token pruning & cost benchmarks
|
|
240
|
+
โ โโโ generate_layer_by_layer_inspector.py # Interactive layer visualizer generator
|
|
241
|
+
โ โโโ benchmark_faithfulness.py # Deletion & Insertion curve benchmarks
|
|
242
|
+
โโโ tests/
|
|
243
|
+
โ โโโ test_bottleneck.py # Bottleneck & voting unit tests
|
|
244
|
+
โ โโโ test_models.py # SaccadeViT & CleanViT tests
|
|
245
|
+
โ โโโ test_exporter.py # HTML export verification tests
|
|
246
|
+
โ โโโ test_faithfulness.py # Causal gradient isolation verification
|
|
247
|
+
โ โโโ test_text_saccade.py # LLM prompt token saccading tests
|
|
248
|
+
โโโ assets/
|
|
249
|
+
โ โโโ samples/ # Real evaluation scenes (Eagle, Panda, etc.)
|
|
250
|
+
โโโ CITATION.cff # Citation metadata for GitHub 1-click cite
|
|
251
|
+
โโโ LICENSE # MIT License
|
|
252
|
+
โโโ pyproject.toml # Modern PEP 621 packaging
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
---
|
|
256
|
+
|
|
257
|
+
## ๐งช Running Tests
|
|
258
|
+
|
|
259
|
+
```bash
|
|
260
|
+
pytest tests/ -v
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
All 15 test suites verify:
|
|
264
|
+
- Column-sum patch importance voting correctness
|
|
265
|
+
- Normalized bounding box conversions
|
|
266
|
+
- Dynamic top-$K$ budget switching
|
|
267
|
+
- Standalone HTML generation with embedded base64 data
|
|
268
|
+
- Exact 0.0 causal gradient isolation
|
|
269
|
+
- Text token saccading & Shannon entropy compression
|
|
270
|
+
|
|
271
|
+
---
|
|
272
|
+
|
|
273
|
+
## ๐ Credits & Acknowledgements
|
|
274
|
+
|
|
275
|
+
- **Inspiration:** The intrinsic attention column-voting mechanism was inspired by **David Ha** ([@hardmaru](https://twitter.com/hardmaru)) and the foundational paper *Neuroevolution of Self-Interpretable Agents* (Tang, Nguyen, & Ha, 2020).
|
|
276
|
+
- **Vision Backbones:** Built with Ross Wightman's [timm](https://github.com/huggingface/pytorch-image-models) library (`vit_small_patch16_224.dino`, `deit_small_patch16_224`).
|
|
277
|
+
- **Language Models:** DistilGPT2 / Hugging Face Transformers for causal attention extraction and next-token perplexity entropy.
|
|
278
|
+
|
|
279
|
+
---
|
|
280
|
+
|
|
281
|
+
## ๐ Citation
|
|
282
|
+
|
|
283
|
+
If you use `saccade` in your research, experiments, or applications, please cite:
|
|
284
|
+
|
|
285
|
+
```bibtex
|
|
286
|
+
@misc{patel2026saccade,
|
|
287
|
+
author = {Patel, Daksh},
|
|
288
|
+
title = {saccade: Intrinsic Attention Bottlenecks for Vision Transformers and LLM Prompt Compression},
|
|
289
|
+
year = {2026},
|
|
290
|
+
month = {November},
|
|
291
|
+
howpublished = {\url{https://github.com/helloitsdaksh/saccade}},
|
|
292
|
+
note = {Version 0.1.0}
|
|
293
|
+
}
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
Or using BibLaTeX:
|
|
297
|
+
|
|
298
|
+
```bibtex
|
|
299
|
+
@software{patel2026saccade,
|
|
300
|
+
author = {Patel, Daksh},
|
|
301
|
+
title = {saccade: Intrinsic Attention Bottlenecks for Vision Transformers and LLM Prompt Compression},
|
|
302
|
+
year = {2026},
|
|
303
|
+
month = {11},
|
|
304
|
+
version = {0.1.0},
|
|
305
|
+
publisher = {GitHub},
|
|
306
|
+
url = {https://github.com/helloitsdaksh/saccade}
|
|
307
|
+
}
|
|
308
|
+
```
|
|
309
|
+
|
|
310
|
+
## ๐ License
|
|
311
|
+
MIT License. Free for academic research, open-source development, and commercial use.
|