Skip to content

feat(gui): Add Attention Maps visualization tool#653

Merged
fderuiter merged 1 commit intomainfrom
feat/ai-attention-maps-17698362353464505205
Mar 13, 2026
Merged

feat(gui): Add Attention Maps visualization tool#653
fderuiter merged 1 commit intomainfrom
feat/ai-attention-maps-17698362353464505205

Conversation

@fderuiter
Copy link
Owner

This PR adds an "Attention Maps" interactive visualization to the AI tab of the math_explorer_gui, fulfilling the corresponding task in todo_gui.md.

It adheres to the AiTool trait and encapsulates its logic within attention_maps.rs. The tool allows users to manually manipulate small (4x4) Query, Key, and Value matrices and see the resulting Attention Weights and Output update in real time via a custom-drawn heatmap. The underlying mathematical calculation leverages the existing scaled_dot_product_attention function from the math_explorer core library.


PR created automatically by Jules for task 17698362353464505205 started by @fderuiter

- Implement `AttentionMapsTool` for visualizing transformer self-attention mechanisms.
- Provide interactive inputs for Queries (Q), Keys (K), and Values (V) using `egui::Grid`.
- Visualize resulting Attention Weights and final Output matrices using custom egui heatmaps.
- Integrate tool into the existing `AiTab` via the `AiTool` strategy pattern.
- Update `todo_gui.md` to mark the feature as complete.

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
@google-labs-jules
Copy link
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@fderuiter fderuiter marked this pull request as ready for review March 13, 2026 18:39
Copilot AI review requested due to automatic review settings March 13, 2026 18:39
@fderuiter fderuiter merged commit 63f61b8 into main Mar 13, 2026
1 check passed
@fderuiter fderuiter deleted the feat/ai-attention-maps-17698362353464505205 branch March 13, 2026 18:39
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds an “Attention Maps” interactive visualization tool to the AI tab in math_explorer_gui, completing the corresponding Transformers roadmap item and leveraging the existing scaled_dot_product_attention implementation in math_explorer.

Changes:

  • Mark “Attention Maps” as implemented in todo_gui.md.
  • Register a new AttentionMapsTool under the AI tab tool selector.
  • Introduce attention_maps.rs implementing an interactive Q/K/V editor with heatmap rendering for attention weights and output.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
todo_gui.md Marks “Attention Maps” feature as completed in the GUI roadmap.
math_explorer_gui/src/tabs/ai/mod.rs Exposes and registers the new Attention Maps tool in the AI tab.
math_explorer_gui/src/tabs/ai/attention_maps.rs Implements the new tool UI and hooks it up to scaled_dot_product_attention.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +133 to +166
egui::ScrollArea::vertical().show(ui, |ui| {
ui.horizontal(|ui| {
ui.vertical(|ui| {
let mut changed = false;
ui.group(|ui| {
changed |= Self::draw_matrix_input(ui, "Queries (Q)", &mut self.q_matrix);
});
ui.group(|ui| {
changed |= Self::draw_matrix_input(ui, "Keys (K)", &mut self.k_matrix);
});
ui.group(|ui| {
changed |= Self::draw_matrix_input(ui, "Values (V)", &mut self.v_matrix);
});

if changed {
self.recalculate();
}
});

ui.separator();

ui.vertical(|ui| {
ui.group(|ui| {
Self::draw_heatmap(ui, "Attention Weights (softmax(Q * K^T / sqrt(d_k)))", &self.attention_weights);
});

ui.add_space(20.0);

ui.group(|ui| {
Self::draw_heatmap(ui, "Output (Weights * V)", &self.output_matrix);
});
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants