✨ New Features
Single-Prompt Activation Analysis
get_prompt_activations() — captures raw activations for a single prompt without requiring pairwise comparison. Mirrors the existing prompt-pair workflow while returning a single activation dictionary keyed by layer name.
Single-Prompt Activation Heatmaps
visualize_prompt_heatmap() — renders a one-layer heatmap for a single prompt (Y-axis: token positions, X-axis: neuron dimensions grouped by bin_size).
visualize_prompt_layer_heatmap() — renders a layer-by-layer heatmap across model depth for a single prompt.
- Both follow the same plotting style as existing bias visualizations and accept
output_dir for optional saving.
🔧 Bug Fixes
Activation Heatmaps Now Show Negative Values Correctly
- Both heatmap functions now use a diverging colormap (
RdBu_r) with zero-centered symmetric normalization (TwoSlopeNorm). Negative activations are no longer clipped and hidden.
- No signature changes — existing calls continue to work.
_calculate_cosine_importance Excludes Padding Tokens (closes #38)
- Cosine similarity is now computed token-by-token (
dim=-1). When attention_mask is provided, padding positions are zeroed out so only real tokens contribute to importance scores.
- New optional parameter
attention_mask=None — backward compatible, existing callers unaffected.
📦 Installation
pip install optipfair==0.4.2