Attention Heatmap Calculator

Visualize transformer attention matrices, compare layers and heads, apply masks, inspect token relationships, calculate entropy, and export polished interactive heatmap reports instantly with ease.

Attention Heatmap Results

Results appear here after calculation.

Enter attention data, then select Calculate Heatmap.
No heatmap generated yet.
Use a sample matrix or paste your own values.

Top Attention Pairs

RankQueryKeyWeight

Token Summary

QueryTop KeyMaxEntropy

Selected Cell or Token Details

Click a heatmap cell to inspect its relationship.

Processed Matrix


      

1. Attention Data

Paste a matrix, upload a file, or load an example.

Rows are query tokens. Columns are key tokens.
Dimensions must match the processed primary matrix.

2. Model and Aggregation

3. Processing and Masks

Use 1 to keep a cell and 0 to mask it.
Use zero to retain every value.

4. Heatmap Appearance

Formula Used

Row normalization divides each attention value by its row sum. This makes each query distribution total one. Percent mode then multiplies normalized values by one hundred.

A′ij = Aij ÷ ΣkAik

Attention entropy measures how broadly each query distributes attention. Lower entropy indicates focused attention across fewer key tokens. Higher entropy indicates a more distributed attention pattern.

Hi = −Σjpij log(pij)

Difference modes compare corresponding cells between two matrices. Absolute difference removes direction while preserving change magnitude. Percentage change uses the comparison matrix as baseline.

How to Use

  1. Paste an attention matrix or load an example.
  2. Add matching query and key token labels.
  3. Select normalization, transformation, masking, and filtering settings.
  4. Choose colours, annotations, dimensions, and comparison options.
  5. Select Calculate Heatmap and inspect the generated analysis.
  6. Export the graph, matrix, statistics, or complete report.

Example Data

Query[CLS]Thecatsat[SEP]
[CLS]0.400.200.150.150.10
The0.100.350.300.150.10
cat0.050.200.450.200.10
sat0.050.100.300.450.10
[SEP]0.100.100.150.200.45

Understanding Attention Heatmaps

Rows usually represent queries and columns represent keys. Darker cells commonly indicate stronger token relationships. Interpretation depends on the chosen colour scale.

Self-attention compares tokens within the same sequence. Cross-attention links decoder queries with encoder key tokens. Causal attention hides future positions during generation.

Attention weights are useful diagnostic signals, not complete explanations. High attention does not always prove causal importance. Compare multiple heads, layers, and attribution methods.

Frequently Asked Questions

What does each heatmap cell represent?

Each cell shows one query token's weight for one key token.

Should every attention row sum to one?

Transformer attention commonly uses row softmax, making rows total one.

What is attention entropy?

Entropy measures whether attention is concentrated or broadly distributed.

Can I compare two attention heads?

Yes. Paste both matrices and select a difference output.

What does a causal mask do?

It prevents each position from viewing later sequence positions.

How are padding tokens detected?

Labels matching PAD patterns are removed or masked automatically.

Can I average several heads?

Yes. Provide JSON matrices and choose an aggregation method.

Why can attention contain negative values?

Raw scores or difference matrices can contain negative values.

Does attention explain model decisions completely?

No. Combine attention with gradients, ablations, and other attribution methods.

Related Calculators

Neural Network Architecture DiagramNeuron Activation PlotActivation Function GraphLoss Landscape PlotGradient Distribution HistogramWeight Distribution HistogramGradient Flow PlotLearning-Rate CurveEmbedding Projection PlotConvolution Feature Map

Important Note: All the Calculators listed in this site are for educational purpose only and we do not guarentee the accuracy of results. Please do consult with other sources as well.