Show HN: LLM Attention Visualization

(ishamf.dev)

66 points | by ifz 3 hours ago

7 comments

  • ex-aws-dude 8 minutes ago
    I don't know much about LLMs but does that mean you have N^2 computation with the context size since every token needs to track how it relates to every other token?
    • acedTrex 4 minutes ago
      For full self attention yes
  • fuddle 1 hour ago
    This is great, I've read multiple books and watched videos about the attention mechanism. Now that I understand it, this is the clearest example I've seen on how attention works.
  • sva_ 2 hours ago
    I highly question this simplistic idea of high vector magnitude = high influence.
    • smallmancontrov 2 hours ago
      You get what you pay for. If you want to think harder and get more, https://transformer-circuits.pub/2025/attention-qk/index.htm...
    • ifz 2 hours ago
      I don't disagree with that. I did add an entire caveat paragraph there.

      To me, it's more of a neat visualization, not something that can be used to interpret LLM behavior. Even with a lot of simplification, it can show some interesting patterns.

    • apnabhidu47 1 hour ago
      Same I dont get it just, could you clarify it
  • wopak 1 hour ago
    neat, combining info from two phrases is hard to see without such a tool.

    are you worried later-layer attention gets drowned out by earlier layers just because there are more of them contributing to the sum?

    • ifz 1 hour ago
      Hmm, I might try to add some controls to limit which layers get summed up. It might be able to reveal more patterns.

      Right now only simple correlations are visible.

  • itsnasme 1 hour ago
    I like the visualisation. Pretty cool
  • stared 1 hour ago
    I am curious what's the actual formula.

    I mean, there so many headers and layers, it is tricky to make a choice that will resonate with our intuition . Is it some weighted average? Or maybe ablation test?

    • ifz 1 hour ago
      It's really simple, basically just the magnitude of the value vector, weighted by QK dot product, summed across all attention heads and layers.

      When I started, I expected I'd have to experiment a lot to find something comprehensible. But this simple computation can already show some patterns.

      • stared 53 minutes ago
        Nice! Sometimes the simplest approaches work the best.
    • visarga 54 minutes ago
      If you want quick access look at google images for "transformer attention formula" there are some interesting depictions
  • colophontio 2 hours ago
    [dead]