Skip to content
AI & Machine Learning Medium #attention#cross-attention#encoder-decoder

Self vs Cross Attention

Self: Q, K, V from same sequence. Cross: Q from one, K/V from another. Decoder bridge.

A free, animated self vs cross attention you can read here or embed on any website, from Scrollchart.

Self vs Cross Attention

Self vs Cross AttentionSelf: Q, K, V from one sequence. Cross: Q from decoder, K/V from encoder.Self-AttentionCross-AttentionThecatsatonthematQ = K = V (same sequence)QKVUsed in encoder blocksBERT, GPT, LlamaThecatsatonthematDieKatzesassdortEncoderK, V sourceDecoderQ sourceUsed in encoder-decoder bridgeT5, original Transformer, image-text modelsCross-attention is the only place decoder reads encoder output; removing it collapses encoder-decoder to decoder-only (GPT style)

Two attention layouts. Self-attention: Q, K, V from same sequence (encoder or decoder). Cross-attention: Q from decoder, K/V from encoder. Used in T5, original Transformer, and modern image-text models.

Good for

  • Transformer architecture explainers contrasting encoder-only, decoder-only, and encoder-decoder models
  • Tutorial content on T5, BART, and seq2seq models where the encoder-decoder bridge matters
  • Image-text model articles (Flamingo, LLaVA) explaining how visual tokens are cross-attended by the language decoder

Source & accuracy

This self vs cross attention is an editorial illustration built to represent the concept accurately. Where it shows figures, they are typical or representative values chosen to make the relationship clear, not a single underlying dataset. The diagram and its explainer are reviewed and maintained centrally, and updated over time as understanding improves.

Self-attention: internal relationship mapping

Self-attention allows each token to directly attend to all other tokens within the same sequence, creating a global dependency map. The query, key, and value vectors all come from the same sequence, which means every token can learn relationships to its neighbors, distant context, and even itself. This is the core mechanism in encoder stacks, where each layer refines token representations by incorporating information from the entire sequence.

Cross-attention: bridging separate sequences

Cross-attention computes attention between two different sequences. Typically, the query comes from one sequence (the decoder or target stream) while the key and value come from another sequence (the encoder or source stream). This asymmetry allows the decoder to learn which parts of the input are relevant to each output position. Machine translation, image captioning, and question-answering all rely on cross-attention to align information from disparate sources.

A standard transformer encoder-decoder uses self-attention in both the encoder (to process the input) and the decoder (to process previously generated tokens), with cross-attention in the decoder to bind the output to the input context.

Embed this diagram

Add this animated self vs cross attention to your own site. Copy one line of HTML, or use the embed builder for theme and sizing options.

Reference

What this is
A free, embeddable, animated self vs cross attention for any website.
Who uses it
AI/ML blogs, CS educators.
How to embed
Copy one line of HTML. No signup. No watermark. Works in WordPress, Webflow, Ghost, Substack, plain HTML.
File size
iframe embed, ~80 KB gzipped (loads on demand, does not block your page paint).
License
Free forever. Editorial explainer text included; updated centrally over time.

Embed format options

Copy the universal HTML snippet, the WordPress shortcode, or an iframe fallback - see the WordPress plugin page for details. Any format keeps the same Core Web Vitals profile and the same explainer text.

Embed snippet
<div data-scrollchart="self-vs-cross-attention" data-scrollchart-v="1"></div>
<script src="https://scrollchart.com/embed.js" async></script>

Frequently asked questions

Where can I get a free animated "Self vs Cross Attention" for my website?
Scrollchart provides "Self vs Cross Attention" as a free, embeddable animated diagram you can add to any website with one line of HTML. No signup is required and there is no watermark. The diagram and its explainer text are served from scrollchart.com, so the embed stays current without any maintenance on your end.
How do I embed a self vs cross attention in a developer or tech blog?
Copy the one-line snippet from the Scrollchart diagram page and paste it into your post HTML. It works in any static site generator, CMS, or hand-coded HTML page. The embed is a thin loader, not an iframe, so the content is fully in your DOM.