Spaces:
Running on Zero
Running on Zero
Keep representation playback compact on mobile and pause at recorded stages
Browse files- style.css +15 -0
- token_space.js +13 -5
- token_space.py +2 -2
style.css
CHANGED
|
@@ -183,3 +183,18 @@ header p { font: 18px/1.6 Georgia, serif; color: #777; }
|
|
| 183 |
.representation-actions input { accent-color:#f4bf67; }
|
| 184 |
|
| 185 |
.connection-detail { color:#eef3f5 !important; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 183 |
.representation-actions input { accent-color:#f4bf67; }
|
| 184 |
|
| 185 |
.connection-detail { color:#eef3f5 !important; }
|
| 186 |
+
|
| 187 |
+
.representation-connection-details > summary { display:none; }
|
| 188 |
+
@media(max-width:640px) {
|
| 189 |
+
#token-universe[data-position-mode="representations"] .space-detail { max-height:210px; }
|
| 190 |
+
#token-universe[data-position-mode="representations"] .representation-controls { margin-bottom:8px;padding-bottom:8px; }
|
| 191 |
+
#token-universe[data-position-mode="representations"] .representation-controls > .attention-title { display:none; }
|
| 192 |
+
#token-universe[data-position-mode="representations"] .representation-note { font-size:11px;line-height:1.35;margin:0 0 6px;max-height:32px;overflow:auto; }
|
| 193 |
+
#token-universe[data-position-mode="representations"] .representation-layer-label { font-size:0;line-height:0;gap:0; }
|
| 194 |
+
#token-universe[data-position-mode="representations"] .representation-stage { font-size:12px;margin:4px 0 8px; }
|
| 195 |
+
#token-universe[data-position-mode="representations"] .representation-actions { gap:8px; }
|
| 196 |
+
#token-universe[data-position-mode="representations"] .representation-actions button { font-size:12px;padding:4px 8px; }
|
| 197 |
+
#token-universe[data-position-mode="representations"] .representation-actions label { font-size:11px; }
|
| 198 |
+
#token-universe[data-position-mode="representations"] .representation-controls .attention-help { margin-top:6px;padding-top:6px; }
|
| 199 |
+
#token-universe[data-position-mode="representations"] .representation-connection-details > summary { display:list-item;color:#f4bf67 !important;cursor:pointer;font:12px/1.5 system-ui,sans-serif;margin:6px 0; }
|
| 200 |
+
}
|
token_space.js
CHANGED
|
@@ -41,6 +41,12 @@
|
|
| 41 |
return layers[a].map((value,i)=>value*(1-t)+layers[b][i]*t);
|
| 42 |
}
|
| 43 |
function representationControls(){
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
const host=root?.querySelector('.representation-controls');if(!host?.querySelector)return;
|
| 45 |
host.hidden=positionMode!=='representations';if(host.hidden)return;
|
| 46 |
const note=host.querySelector('[data-representation-note]'),slider=host.querySelector('[data-representation-layer]');
|
|
@@ -52,6 +58,7 @@
|
|
| 52 |
const stage=Math.round(representationStage),between=Math.abs(representationStage-stage)>.04;
|
| 53 |
caption.textContent=stage===0?'Input to first layer':`After layer ${stage-1}${stage===maximum?' + final normalisation':''}`;
|
| 54 |
if(between)caption.textContent+=' / interpolating';
|
|
|
|
| 55 |
let message=!representationMeta?'Enable Capture layer representations in Settings, then generate a new stream.':
|
| 56 |
!ready?`Collecting token states: ${representationMeta.calibrating} / ${representationMeta.calibration_target}. Pause after a few tokens to fit the shared projection.`:
|
| 57 |
`${[...representationPoints.keys()].filter(n=>n>=0).length} token trajectories / ${maximum} layers / one fixed projection.`;
|
|
@@ -65,7 +72,7 @@
|
|
| 65 |
if(value==='representations'){
|
| 66 |
positionMode='representations';mode='history';representationStage=0;connections='attention';legendFocus=null;
|
| 67 |
const links=root?.querySelector('[data-space-links]');if(links)links.value='attention';
|
| 68 |
-
target=[0,0,0];panX=panY=0;zoom=1;
|
| 69 |
if(selected==null||!representationPoints.has(selected))selected=Math.max(-1,...[...representationPoints.keys()].filter(n=>n>=0));
|
| 70 |
if(selected<0)selected=history.at(-1)?.n??null;
|
| 71 |
if(!paused){
|
|
@@ -188,7 +195,7 @@
|
|
| 188 |
const point=history.find(p=>p.n===selected)||externalSelected||(connections==='attention'?sourcePoint():null);
|
| 189 |
if(positionMode==='representations'&&connections==='attention'&&Math.round(representationStage)===0){
|
| 190 |
delete box.dataset.attentionSignature;delete box.dataset.connectionSignature;
|
| 191 |
-
box.textContent='Input stage: no attention layer has been applied yet. Advance the
|
| 192 |
return;
|
| 193 |
}
|
| 194 |
if(connections!=='attention'){
|
|
@@ -385,7 +392,7 @@
|
|
| 385 |
root.querySelector('[data-representation-play]')?.addEventListener('click',()=>{
|
| 386 |
if(!paused||!representationMeta?.ready)return;
|
| 387 |
if(representationStage>=representationMeta.stages-1)representationStage=0;
|
| 388 |
-
representationPlaying=!representationPlaying;representationControls();details();
|
| 389 |
});
|
| 390 |
const trailInput=root.querySelector('[data-representation-trail]');
|
| 391 |
if(trailInput){trailInput.checked=representationTrail;trailInput.addEventListener('change',event=>representationTrail=event.target.checked);}
|
|
@@ -409,7 +416,7 @@
|
|
| 409 |
}
|
| 410 |
},700);
|
| 411 |
}
|
| 412 |
-
if(data.stream!==stream){representationPoints.clear();representationMeta=null;representationPlaying=false;representationStage=0;lastRepresentationLayer=-1;layerRows.clear();layerTargets.clear();hiddenLayers.clear();layerCount=0;hoverEdge=null;stream=data.stream;seen=-1;history=[];selected=null;paused=false;textView=null;externalSelected=null;details();}
|
| 413 |
const now=Date.now(),existing=new Set(history.map(p=>p.n));
|
| 414 |
for(const p of data.points||[]){
|
| 415 |
if(existing.has(p.n)){const old=history.find(q=>q.n===p.n);if(p.attention){if(!old.attention)old.attentionBorn=now;old.attention=p.attention;}continue;}
|
|
@@ -428,6 +435,7 @@
|
|
| 428 |
}
|
| 429 |
if(data.representations){
|
| 430 |
representationMeta=data.representations;
|
|
|
|
| 431 |
for(const point of data.representations.points)representationPoints.set(point.n,point.layers);
|
| 432 |
for(const n of representationPoints.keys())if(n>=0&&n<seen-128)representationPoints.delete(n);
|
| 433 |
}
|
|
@@ -446,7 +454,7 @@
|
|
| 446 |
const[x,y,z]=v.map((a,i)=>a-target[i]),cy=Math.cos(yaw),sy=Math.sin(yaw),rx=x*cy+z*sy,rz=-x*sy+z*cy;
|
| 447 |
const cp=Math.cos(pitch),sp=Math.sin(pitch),ry=y*cp-rz*sp,depth=y*sp+rz*cp,distance=7/zoom;
|
| 448 |
const denominator=distance+depth,scale=Math.min(width,height)*.91/Math.max(.08,denominator);
|
| 449 |
-
return{x:width/2+panX+rx*scale,y:height
|
| 450 |
}
|
| 451 |
function tick(){
|
| 452 |
if(disposed)return;
|
|
|
|
| 41 |
return layers[a].map((value,i)=>value*(1-t)+layers[b][i]*t);
|
| 42 |
}
|
| 43 |
function representationControls(){
|
| 44 |
+
if(root?.dataset)root.dataset.positionMode=positionMode;
|
| 45 |
+
const extra=root?.querySelector('.representation-connection-details');
|
| 46 |
+
if(extra?.dataset){
|
| 47 |
+
const key=`${positionMode}:${window.innerWidth<=640}`;
|
| 48 |
+
if(extra.dataset.layout!==key){extra.open=!(positionMode==='representations'&&window.innerWidth<=640);extra.dataset.layout=key;}
|
| 49 |
+
}
|
| 50 |
const host=root?.querySelector('.representation-controls');if(!host?.querySelector)return;
|
| 51 |
host.hidden=positionMode!=='representations';if(host.hidden)return;
|
| 52 |
const note=host.querySelector('[data-representation-note]'),slider=host.querySelector('[data-representation-layer]');
|
|
|
|
| 58 |
const stage=Math.round(representationStage),between=Math.abs(representationStage-stage)>.04;
|
| 59 |
caption.textContent=stage===0?'Input to first layer':`After layer ${stage-1}${stage===maximum?' + final normalisation':''}`;
|
| 60 |
if(between)caption.textContent+=' / interpolating';
|
| 61 |
+
slider.setAttribute('aria-valuetext',caption.textContent);
|
| 62 |
let message=!representationMeta?'Enable Capture layer representations in Settings, then generate a new stream.':
|
| 63 |
!ready?`Collecting token states: ${representationMeta.calibrating} / ${representationMeta.calibration_target}. Pause after a few tokens to fit the shared projection.`:
|
| 64 |
`${[...representationPoints.keys()].filter(n=>n>=0).length} token trajectories / ${maximum} layers / one fixed projection.`;
|
|
|
|
| 72 |
if(value==='representations'){
|
| 73 |
positionMode='representations';mode='history';representationStage=0;connections='attention';legendFocus=null;
|
| 74 |
const links=root?.querySelector('[data-space-links]');if(links)links.value='attention';
|
| 75 |
+
target=[0,0,0];panX=panY=0;zoom=window.innerWidth<=640?.8:1;
|
| 76 |
if(selected==null||!representationPoints.has(selected))selected=Math.max(-1,...[...representationPoints.keys()].filter(n=>n>=0));
|
| 77 |
if(selected<0)selected=history.at(-1)?.n??null;
|
| 78 |
if(!paused){
|
|
|
|
| 195 |
const point=history.find(p=>p.n===selected)||externalSelected||(connections==='attention'?sourcePoint():null);
|
| 196 |
if(positionMode==='representations'&&connections==='attention'&&Math.round(representationStage)===0){
|
| 197 |
delete box.dataset.attentionSignature;delete box.dataset.connectionSignature;
|
| 198 |
+
box.textContent='Input stage: no attention layer has been applied yet. Advance the slider to inspect layers. Attention appears if it was captured; only targets with recorded representations can be drawn.';
|
| 199 |
return;
|
| 200 |
}
|
| 201 |
if(connections!=='attention'){
|
|
|
|
| 392 |
root.querySelector('[data-representation-play]')?.addEventListener('click',()=>{
|
| 393 |
if(!paused||!representationMeta?.ready)return;
|
| 394 |
if(representationStage>=representationMeta.stages-1)representationStage=0;
|
| 395 |
+
representationPlaying=!representationPlaying;if(!representationPlaying)representationStage=Math.round(representationStage);representationControls();details();
|
| 396 |
});
|
| 397 |
const trailInput=root.querySelector('[data-representation-trail]');
|
| 398 |
if(trailInput){trailInput.checked=representationTrail;trailInput.addEventListener('change',event=>representationTrail=event.target.checked);}
|
|
|
|
| 416 |
}
|
| 417 |
},700);
|
| 418 |
}
|
| 419 |
+
if(data.stream!==stream){positionMode='embeddings';const view=root?.querySelector('[data-space-mode]');if(view)view.value=mode;representationPoints.clear();representationMeta=null;representationPlaying=false;representationStage=0;lastRepresentationLayer=-1;layerRows.clear();layerTargets.clear();hiddenLayers.clear();layerCount=0;hoverEdge=null;stream=data.stream;seen=-1;history=[];selected=null;paused=false;textView=null;externalSelected=null;details();}
|
| 420 |
const now=Date.now(),existing=new Set(history.map(p=>p.n));
|
| 421 |
for(const p of data.points||[]){
|
| 422 |
if(existing.has(p.n)){const old=history.find(q=>q.n===p.n);if(p.attention){if(!old.attention)old.attentionBorn=now;old.attention=p.attention;}continue;}
|
|
|
|
| 435 |
}
|
| 436 |
if(data.representations){
|
| 437 |
representationMeta=data.representations;
|
| 438 |
+
if(!data.attention_layers&&data.representations.stages)layerCount=data.representations.stages-1;
|
| 439 |
for(const point of data.representations.points)representationPoints.set(point.n,point.layers);
|
| 440 |
for(const n of representationPoints.keys())if(n>=0&&n<seen-128)representationPoints.delete(n);
|
| 441 |
}
|
|
|
|
| 454 |
const[x,y,z]=v.map((a,i)=>a-target[i]),cy=Math.cos(yaw),sy=Math.sin(yaw),rx=x*cy+z*sy,rz=-x*sy+z*cy;
|
| 455 |
const cp=Math.cos(pitch),sp=Math.sin(pitch),ry=y*cp-rz*sp,depth=y*sp+rz*cp,distance=7/zoom;
|
| 456 |
const denominator=distance+depth,scale=Math.min(width,height)*.91/Math.max(.08,denominator);
|
| 457 |
+
return{x:width/2+panX+rx*scale,y:height*(positionMode==='representations'&&width<=640?.4:.5)+panY+ry*scale,z:depth,scale:Math.min(3,7/Math.max(.08,denominator)),visible:denominator>.08};
|
| 458 |
}
|
| 459 |
function tick(){
|
| 460 |
if(disposed)return;
|
token_space.py
CHANGED
|
@@ -156,9 +156,9 @@ SCENE = '''<div id="token-universe">
|
|
| 156 |
<label class="representation-layer-label">Layer <input type="range" data-representation-layer min="0" max="1" step="1" value="0" aria-label="Representation layer"></label>
|
| 157 |
<p class="representation-stage" data-representation-stage>Input to first layer</p>
|
| 158 |
<div class="representation-actions"><button type="button" data-representation-play>Play layers</button><label><input type="checkbox" data-representation-trail checked> Selected-token trail</label></div>
|
| 159 |
-
<details class="attention-help"><summary>How to read representations</summary><p>Each token shows its hidden states recorded when it was processed to predict the following token. These are historical token recordings, not one full-context snapshot. One shared PCA projection is fitted across the first captured tokens and all layers, then frozen for the stream. Vectors are normalised to compare directions. The input stage may include positional processing; the final stage includes the model's final normalisation. Animation interpolates between recorded stages. Movement is not a direct measure of meaning or importance. Only the most recent 128 processed tokens are retained.</p></details>
|
| 160 |
</section>
|
| 161 |
-
<div class="connection-detail" aria-live="polite">Click a token to inspect its earlier neighbours.</div>
|
| 162 |
</div>
|
| 163 |
<div class="space-edge-tooltip" role="tooltip" hidden></div>
|
| 164 |
<div class="space-bottom"><span>Drag to orbit · Shift-drag to pan · Wheel to zoom · Double-click a token to focus</span><span>Embedding PCA</span></div>
|
|
|
|
| 156 |
<label class="representation-layer-label">Layer <input type="range" data-representation-layer min="0" max="1" step="1" value="0" aria-label="Representation layer"></label>
|
| 157 |
<p class="representation-stage" data-representation-stage>Input to first layer</p>
|
| 158 |
<div class="representation-actions"><button type="button" data-representation-play>Play layers</button><label><input type="checkbox" data-representation-trail checked> Selected-token trail</label></div>
|
| 159 |
+
<details class="attention-help"><summary>How to read representations</summary><p>Each token shows its hidden states recorded when it was processed to predict the following token. These are historical token recordings, not one full-context snapshot. One shared PCA projection is fitted across the first captured tokens and all layers, then frozen for the stream. These axes differ from the input-embedding view. Only context tokens with saved trajectories can be plotted. Vectors are normalised to compare directions. The input stage may include positional processing; the final stage includes the model's final normalisation. Animation interpolates between recorded stages. Movement is not a direct measure of meaning or importance. Only the most recent 128 processed tokens are retained.</p></details>
|
| 160 |
</section>
|
| 161 |
+
<details class="representation-connection-details" open><summary>Connection details</summary><div class="connection-detail" aria-live="polite">Click a token to inspect its earlier neighbours.</div></details>
|
| 162 |
</div>
|
| 163 |
<div class="space-edge-tooltip" role="tooltip" hidden></div>
|
| 164 |
<div class="space-bottom"><span>Drag to orbit · Shift-drag to pan · Wheel to zoom · Double-click a token to focus</span><span>Embedding PCA</span></div>
|