Spaces:
Running
Running
Paar, F. (Ferdinand) commited on
Commit ·
1058f09
1
Parent(s): 00a52d1
thubnail filled and layer head box next to each other
Browse files- frontend/index.html +14 -4
- frontend/script.js +5 -5
frontend/index.html
CHANGED
|
@@ -83,10 +83,20 @@
|
|
| 83 |
<p>Type in a token sequence (below 50 characters) and hit process. After some loading time, you will be able to see the attention patterns of individual so-called "heads" in the LLM.
|
| 84 |
Each head focuses on different aspects of the input text, and by visualizing these patterns, you can gain insights into how the model processes and understands language.
|
| 85 |
</p>
|
| 86 |
-
|
| 87 |
<p>Here is an example view of a head, with tokens on each side. If you see a connection between two tokens, it means that the head is paying attention to the relationship between those tokens. This way you can see attention heads which "pay attention" to the previous token, the first token, or other patterns.
|
| 88 |
Click on an attention head to select the respective head in a layer. Afterwards you can hover over tokens to see the attention weights of the selected head for that token. </p>
|
| 89 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 90 |
<!-- Text Input & Process Button -->
|
| 91 |
<form id="textForm" class="text-form">
|
| 92 |
<textarea id="inputText" rows="2" cols="50" maxlength="50" placeholder="Enter your text here..." autofocus></textarea>
|
|
@@ -103,14 +113,14 @@
|
|
| 103 |
</div>
|
| 104 |
<!-- Display for selected head and layer -->
|
| 105 |
<div id="display_info">
|
| 106 |
-
<div id="display_head" class="info-container">
|
| 107 |
<span class="label">Head:</span>
|
| 108 |
<span class="number-box">-</span>
|
| 109 |
</div>
|
| 110 |
<div id="display_layer" class="info-container">
|
| 111 |
<span class="label">Layer:</span>
|
| 112 |
<span class="number-box">-</span>
|
| 113 |
-
</div>
|
| 114 |
</div>
|
| 115 |
</section>
|
| 116 |
|
|
|
|
| 83 |
<p>Type in a token sequence (below 50 characters) and hit process. After some loading time, you will be able to see the attention patterns of individual so-called "heads" in the LLM.
|
| 84 |
Each head focuses on different aspects of the input text, and by visualizing these patterns, you can gain insights into how the model processes and understands language.
|
| 85 |
</p>
|
| 86 |
+
<div id="thumbnailContainer"></div>
|
| 87 |
<p>Here is an example view of a head, with tokens on each side. If you see a connection between two tokens, it means that the head is paying attention to the relationship between those tokens. This way you can see attention heads which "pay attention" to the previous token, the first token, or other patterns.
|
| 88 |
Click on an attention head to select the respective head in a layer. Afterwards you can hover over tokens to see the attention weights of the selected head for that token. </p>
|
| 89 |
+
<section id="display_info">
|
| 90 |
+
<div id="display_head" class="info-container">
|
| 91 |
+
<span class="label">Head:</span>
|
| 92 |
+
<span class="number-box">-</span>
|
| 93 |
+
<span class="spacer"></span> <!-- Adds space between Head and Layer -->
|
| 94 |
+
<span class="label">Layer:</span>
|
| 95 |
+
<span class="number-box">-</span>
|
| 96 |
+
</div>
|
| 97 |
+
</section>
|
| 98 |
+
|
| 99 |
+
</section>
|
| 100 |
<!-- Text Input & Process Button -->
|
| 101 |
<form id="textForm" class="text-form">
|
| 102 |
<textarea id="inputText" rows="2" cols="50" maxlength="50" placeholder="Enter your text here..." autofocus></textarea>
|
|
|
|
| 113 |
</div>
|
| 114 |
<!-- Display for selected head and layer -->
|
| 115 |
<div id="display_info">
|
| 116 |
+
<!-- <div id="display_head" class="info-container">
|
| 117 |
<span class="label">Head:</span>
|
| 118 |
<span class="number-box">-</span>
|
| 119 |
</div>
|
| 120 |
<div id="display_layer" class="info-container">
|
| 121 |
<span class="label">Layer:</span>
|
| 122 |
<span class="number-box">-</span>
|
| 123 |
+
</div> -->
|
| 124 |
</div>
|
| 125 |
</section>
|
| 126 |
|
frontend/script.js
CHANGED
|
@@ -72,7 +72,7 @@ function createAttentionThumbnail(data, layerIdx, headIdx) {
|
|
| 72 |
.style("width", width + "px")
|
| 73 |
.style("border", "1px solid #ddd")
|
| 74 |
.style("border-radius", "4px")
|
| 75 |
-
.style("padding", "
|
| 76 |
.style("background", "#fff")
|
| 77 |
.style("cursor", "pointer"); // Indicate clickability
|
| 78 |
|
|
@@ -81,12 +81,12 @@ function createAttentionThumbnail(data, layerIdx, headIdx) {
|
|
| 81 |
.attr("width", width)
|
| 82 |
.attr("height", height)
|
| 83 |
.attr("viewBox", `0 0 ${width} ${height}`) // not sure
|
| 84 |
-
.attr("preserveAspectRatio", "
|
| 85 |
|
| 86 |
// Add header text for layer and head
|
| 87 |
svg.append("text")
|
| 88 |
.attr("x", width / 2)
|
| 89 |
-
.attr("y",
|
| 90 |
.attr("text-anchor", "middle") // not sure
|
| 91 |
.attr("dominant-baseline", "middle") // not sure
|
| 92 |
.attr("font-size", "10")
|
|
@@ -99,9 +99,9 @@ function createAttentionThumbnail(data, layerIdx, headIdx) {
|
|
| 99 |
if (weight > 0.01 && sourceIdx !== targetIdx) {
|
| 100 |
const normalizedWeight = weight / rowMax;
|
| 101 |
svg.append("line")
|
| 102 |
-
.attr("x1", padding
|
| 103 |
.attr("y1", padding + sourceIdx * tokenHeight - 5)
|
| 104 |
-
.attr("x2", xRight
|
| 105 |
.attr("y2", padding + targetIdx * tokenHeight - 5)
|
| 106 |
.attr("stroke", "#800000") // Bordo red
|
| 107 |
.attr("stroke-width", Math.max(0.5, normalizedWeight * maxLineWidth))
|
|
|
|
| 72 |
.style("width", width + "px")
|
| 73 |
.style("border", "1px solid #ddd")
|
| 74 |
.style("border-radius", "4px")
|
| 75 |
+
.style("padding", "0px")
|
| 76 |
.style("background", "#fff")
|
| 77 |
.style("cursor", "pointer"); // Indicate clickability
|
| 78 |
|
|
|
|
| 81 |
.attr("width", width)
|
| 82 |
.attr("height", height)
|
| 83 |
.attr("viewBox", `0 0 ${width} ${height}`) // not sure
|
| 84 |
+
.attr("preserveAspectRatio", "none"); // not sure
|
| 85 |
|
| 86 |
// Add header text for layer and head
|
| 87 |
svg.append("text")
|
| 88 |
.attr("x", width / 2)
|
| 89 |
+
.attr("y", 10)
|
| 90 |
.attr("text-anchor", "middle") // not sure
|
| 91 |
.attr("dominant-baseline", "middle") // not sure
|
| 92 |
.attr("font-size", "10")
|
|
|
|
| 99 |
if (weight > 0.01 && sourceIdx !== targetIdx) {
|
| 100 |
const normalizedWeight = weight / rowMax;
|
| 101 |
svg.append("line")
|
| 102 |
+
.attr("x1", padding )
|
| 103 |
.attr("y1", padding + sourceIdx * tokenHeight - 5)
|
| 104 |
+
.attr("x2", xRight )
|
| 105 |
.attr("y2", padding + targetIdx * tokenHeight - 5)
|
| 106 |
.attr("stroke", "#800000") // Bordo red
|
| 107 |
.attr("stroke-width", Math.max(0.5, normalizedWeight * maxLineWidth))
|