Write an interactive visualization code of self attention of Transformer in HTML and JavaScript without any libraries.
Use an example sentence "The quick brown fox"
When hovering over a token, visualize the edges whose thicknesses are proportional to the attention score.
The edges should be curved and should not overlap each other.
Make sure that the edges start and end from each token's center
When clicked on a token, show the value of attention scores.
Visualize this nicely in a latex-rendered vector notation. Put each token next to the score. Make sure the Latex rendering is well-aligned.
When clicked again, remove the attention score vector.
have vertical spacing of 50px at the top
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Hover over a token: Curved edges will appear, connecting the hovered token to the others. The thickness of each edge is proportional to the attention score.
Click on a token: The attention scores vector for that token will appear below the tokens. Click again to remove it.
Notes:
The edges are drawn using SVG paths with cubic Bézier curves to ensure they are curved and do not overlap excessively.
Since libraries are not used, LaTeX rendering isn't possible. Instead, the attention scores are displayed in a plaintext vector-like format.
The tokens are centered horizontally, and there is a 50px vertical spacing at the top as specified.
Screenshot of the Visualization:
[image: Self-Attention Visualization Screenshot] open
Feel free to copy the code into an HTML file and open it in a browser to interact with the visualization.