Download lecture-05/class/assets/GatedCell-DdShG2te.js from DeepLearning-VT/DeepLearning_2026: direct link, hf CLI and curl.
- Browser
- Download file 15.3 kB
-
https://huggingface.co/spaces/DeepLearning-VT/DeepLearning_2026/resolve/main/lecture-05/class/assets/GatedCell-DdShG2te.js
- Command line
-
hf download hf://spaces/DeepLearning-VT/DeepLearning_2026/lecture-05/class/assets/GatedCell-DdShG2te.js
-
curl -L -o GatedCell-DdShG2te.js https://huggingface.co/spaces/DeepLearning-VT/DeepLearning_2026/resolve/main/lecture-05/class/assets/GatedCell-DdShG2te.js
15.3 kB
| import{$ as e,S as t,St as n,V as r,X as ee,_ as i,b as a,g as o,m as s,ut as c,v as te,vt as l,w as u,x as d,y as f,yt as p,z as m}from"./modules/shiki-CkJq9tSf.js";import{t as h}from"./_plugin-vue_export-helper-BDNMzG2s.js";import{n as g}from"./slidev/context-DnYiQGy6.js";import{t as _}from"./useConvolution-qO1u8ksh.js";import{d as ne,o as re,s as ie}from"./useRecurrence-PhWWMav6.js";import{n as ae}from"./interactive-CigWxCoZ.js";import{t as oe}from"./StepButton-BvnaUJaa.js";import{t as se}from"./Katex-BmYihQiH.js";import{t as ce}from"./Slider-Bf0ITYx4.js";var le=[`viewBox`],ue=[`x2`],de=[`y`],fe=[`x1`,`x2`],pe=[`x1`,`x2`],me=[`x`,`y`],he=[`y`],ge=[`y2`],_e=[`x`],ve=[`y`],ye=[`x`,`y`],be=[`y`],xe=[`y1`,`y2`],Se=[`x2`,`y2`],Ce=[`x2`,`y2`],we=[`x`],Te=[`y`],Ee=[`x`,`y`],De=[`x`],Oe=[`y`],ke=[`x`,`y`],Ae=[`y`],je=[`y2`],Me=[`x`,`y`],Ne=[`y`],Pe=[`x1`,`x2`],Fe=[`y`],Ie=[`y2`],Le=[`x`],Re=[`y`],ze=[`x`,`y`],Be=[`x1`,`x2`],Ve=[`x`,`y`],He=[`y`],Ue=[`y`],We=[`x1`,`x2`,`y2`],Ge=[`y`],Ke=[`viewBox`],qe=[`y2`],Je=[`x`],Ye=[`x`,`y`],Xe=[`y`],Ze=[`x`,`y`,`width`],Qe=[`x`,`y`],$e=[`y1`,`x2`,`y2`],et=[`y`],tt={class:`dl-gcell__eq dl-math-sm`},v=580,y=272,b=46,x=162,S=56,C=30,w=236,T=180,E=300,D=300,nt=108,O=398,rt=398,k=120,it=470,A=262,j=338,M=470,N=13,P=196,F=300,at=h(u({__name:`GatedCell`,props:{variant:{default:`lstm`}},setup(u){let{$slidev:h,$nav:at,$clicksContext:ot,$clicks:st,$page:ct,$renderContext:lt,$frontmatter:ut}=g(),I=u,L=c(.6),R=c(.9),z=c(.4),B=c(.8),V=c(.7),H=c(.6),U=c(.5),W=c(1),G=c(.4),K=o(()=>ie(L.value,R.value,z.value,B.value,V.value)),q=o(()=>ne(U.value+.9*W.value*H.value)),J=o(()=>re(H.value,G.value,W.value,q.value)),dt=[{key:`forget`,name:`forget gate`,lit:[`cin`,`fgate`,`fmul`,`bus`],latex:`f_t = \\sigma\\!\\left(W_{xf}x_t + W_{hf}h_{t-1} + b_f\\right)`,numeric:()=>`f_t \\cdot c_{t-1} = ${_(R.value)} \\times ${_(L.value)} = ${_(K.value.kept)}`,note:`How much of the old cell state survives. 1 keeps all of it, 0 wipes it. Added to the LSTM in 2000 — the original 1997 cell could not forget.`},{key:`input`,name:`input gate`,lit:[`igate`,`bus`],latex:`i_t = \\sigma\\!\\left(W_{xi}x_t + W_{hi}h_{t-1} + b_i\\right)`,numeric:()=>`i_t = ${_(z.value)}`,note:`How much of the new candidate is allowed in. Note that it decides the amount, not the content.`},{key:`candidate`,name:`candidate`,lit:[`ggate`,`igmul`,`bus`],latex:`\\tilde{c}_t = \\tanh\\!\\left(W_{xc}x_t + W_{hc}h_{t-1} + b_c\\right)`,numeric:()=>`i_t \\cdot \\tilde{c}_t = ${_(z.value)} \\times ${_(B.value)} = ${_(K.value.written)}`,note:`The content: what this step would like to write. tanh, so it is signed — the cell state can be pushed down as well as up.`},{key:`cell`,name:`cell state`,lit:[`cin`,`fmul`,`igmul`,`plus`,`cout`],latex:`c_t = f_t \\odot c_{t-1} + i_t \\odot \\tilde{c}_t`,numeric:()=>`c_t = ${_(K.value.kept)} + ${_(K.value.written)} = ${_(K.value.c)}`,note:`The whole point of the architecture: an addition, not a matrix multiply. Nothing on this path can shrink the gradient by a factor per step.`},{key:`output`,name:`output gate`,lit:[`ogate`,`bus`],latex:`o_t = \\sigma\\!\\left(W_{xo}x_t + W_{ho}h_{t-1} + b_o\\right)`,numeric:()=>`o_t = ${_(V.value)}`,note:`How much of the cell state to expose. The cell can hold something for fifty steps and show it on exactly one of them.`},{key:`hidden`,name:`hidden state`,lit:[`cout`,`ctanh`,`hmul`,`hout`],latex:`h_t = o_t \\odot \\tanh(c_t)`,numeric:()=>`h_t = ${_(V.value)} \\times \\tanh(${_(K.value.c)}) = ${_(K.value.h)}`,note:`What leaves the cell, and the only thing the next layer sees. c_t stays inside.`}],ft=[{key:`update`,name:`update gate`,lit:[`z`],latex:`z_t = \\sigma\\!\\left(W_{xz}x_t + W_{hz}h_{t-1} + b_z\\right)`,numeric:()=>`z_t = ${_(G.value)}`,note:`One gate doing the LSTM’s forget and input jobs at once: whatever is not written is kept, by construction.`},{key:`reset`,name:`reset gate`,lit:[`r`,`cand`],latex:`r_t = \\sigma\\!\\left(W_{xr}x_t + W_{hr}h_{t-1} + b_r\\right)`,numeric:()=>`r_t \\cdot h_{t-1} = ${_(W.value)} \\times ${_(H.value)} = ${_(W.value*H.value)}`,note:`How much of the past the candidate is allowed to read. Drag it to 0: the candidate forgets the sentence so far and answers from this word alone.`},{key:`candidate`,name:`candidate`,lit:[`cand`],latex:`\\tilde{h}_t = \\tanh\\!\\left(W_{xh}x_t + W_{hh}(r_t \\odot h_{t-1}) + b_h\\right)`,numeric:()=>`\\tilde{h}_t = ${_(q.value)}`,note:`The proposed new state. Same shape as h — there is no second state vector in a GRU.`},{key:`blend`,name:`new state`,lit:[`kept`,`written`,`hnew`],latex:`h_t = (1 - z_t) \\odot h_{t-1} + z_t \\odot \\tilde{h}_t`,numeric:()=>`h_t = ${_(1-G.value)} \\times ${_(H.value)} + ${_(G.value)} \\times ${_(q.value)} = ${_(J.value.h)}`,note:`A weighted blend of old and new, and the two weights always sum to 1. Set z to 0 and the state is frozen; set it to 1 and the past is gone.`}],Y=o(()=>I.variant===`lstm`?dt:ft),X=c(-1);ee(()=>I.variant,()=>{X.value=-1});let Z=o(()=>X.value<0?null:Y.value[X.value]),pt=o(()=>X.value>=Y.value.length-1);function mt(){X.value=pt.value?-1:X.value+1}let ht=e=>!Z.value||Z.value.lit.includes(e),gt=e=>Z.value?!Z.value.lit.includes(e):!1;function Q(e){return{"is-dim":gt(e),"is-lit":!!Z.value&&ht(e)}}let _t=e=>e>=0?346:346+e*F/2,vt=e=>Math.abs(e)*F/2,yt=o(()=>[{key:`hprev`,label:`h(t−1)`,value:H.value,tone:`old`},{key:`cand`,label:`candidate`,value:q.value,tone:`new`},{key:`kept`,label:`kept: (1−z)·h(t−1)`,value:J.value.kept,tone:`old`},{key:`written`,label:`written: z·candidate`,value:J.value.written,tone:`new`},{key:`hnew`,label:`h(t)`,value:J.value.h,tone:`result`}]),$=e=>40+e*44+(e>=2?16:0);return(ee,o)=>{let c=ce,u=oe,h=se,g=ae;return m(),te(g,{"max-width":`40rem`},{controls:e(()=>[I.variant===`lstm`?(m(),a(s,{key:0},[t(c,{modelValue:L.value,"onUpdate:modelValue":o[0]||=e=>L.value=e,label:`c(t−1)`,min:-1,max:1,step:.05},null,8,[`modelValue`]),t(c,{modelValue:R.value,"onUpdate:modelValue":o[1]||=e=>R.value=e,label:`forget f`,min:0,max:1,step:.05},null,8,[`modelValue`]),t(c,{modelValue:z.value,"onUpdate:modelValue":o[2]||=e=>z.value=e,label:`input i`,min:0,max:1,step:.05},null,8,[`modelValue`]),t(c,{modelValue:B.value,"onUpdate:modelValue":o[3]||=e=>B.value=e,label:`candidate c̃`,min:-1,max:1,step:.05},null,8,[`modelValue`]),t(c,{modelValue:V.value,"onUpdate:modelValue":o[4]||=e=>V.value=e,label:`output o`,min:0,max:1,step:.05},null,8,[`modelValue`])],64)):(m(),a(s,{key:1},[t(c,{modelValue:H.value,"onUpdate:modelValue":o[5]||=e=>H.value=e,label:`h(t−1)`,min:-1,max:1,step:.05},null,8,[`modelValue`]),t(c,{modelValue:U.value,"onUpdate:modelValue":o[6]||=e=>U.value=e,label:`input drive`,min:-2,max:2,step:.1,precision:1},null,8,[`modelValue`]),t(c,{modelValue:W.value,"onUpdate:modelValue":o[7]||=e=>W.value=e,label:`reset r`,min:0,max:1,step:.05},null,8,[`modelValue`]),t(c,{modelValue:G.value,"onUpdate:modelValue":o[8]||=e=>G.value=e,label:`update z`,min:0,max:1,step:.05},null,8,[`modelValue`])],64)),t(u,{label:pt.value?`Start over`:X.value<0?`Walk the cell`:`Next part`,glyph:`▸`,onClick:mt},null,8,[`label`])]),readout:e(()=>[Z.value?(m(),a(s,{key:0},[i(`div`,tt,[t(h,{expr:Z.value.latex},null,8,[`expr`]),o[18]||=i(`span`,{class:`dl-gcell__arrow`},`→`,-1),t(h,{expr:Z.value.numeric()},null,8,[`expr`])]),i(`div`,null,[i(`strong`,null,n(Z.value.name)+`.`,1),d(` `+n(Z.value.note),1)])],64)):I.variant===`lstm`?(m(),a(s,{key:1},[o[19]||=d(` c`,-1),o[20]||=i(`sub`,null,`t`,-1),d(` = `+n(l(_)(R.value))+`×`+n(l(_)(L.value))+` + `+n(l(_)(z.value))+`×`+n(l(_)(B.value))+` = `,1),i(`strong`,null,n(l(_)(K.value.c)),1),o[21]||=d(`, and h`,-1),o[22]||=i(`sub`,null,`t`,-1),o[23]||=d(` = `,-1),i(`strong`,null,n(l(_)(K.value.h)),1),o[24]||=d(`. Set `,-1),o[25]||=i(`em`,null,`f`,-1),o[26]||=d(` = 1 and `,-1),o[27]||=i(`em`,null,`i`,-1),o[28]||=d(` = 0: the cell state passes through untouched, for as many steps as you like. The gates here are set directly — in a real cell each is its own σ(Wx + Wh + b). `,-1)],64)):(m(),a(s,{key:2},[o[29]||=d(` h`,-1),o[30]||=i(`sub`,null,`t`,-1),d(` = `+n(l(_)(1-G.value))+`×`+n(l(_)(H.value))+` + `+n(l(_)(G.value))+`×`+n(l(_)(q.value))+` = `,1),i(`strong`,null,n(l(_)(J.value.h)),1),o[31]||=d(`. Two gates instead of three, one state instead of two, and the kept and written shares always sum to 1 — so a GRU cannot forget without writing. `,-1)],64))]),default:e(()=>[I.variant===`lstm`?(m(),a(`svg`,{key:0,class:`dl-gcell`,viewBox:`0 0 ${v} ${y}`,preserveAspectRatio:`xMidYMid meet`,role:`img`,"aria-label":`An LSTM memory block: the cell state runs across the top through a multiply by the forget gate and an add of the input gate times the candidate; the hidden state leaves through the output gate`},[o[17]||=i(`defs`,null,[i(`marker`,{id:`dl-gcell-arrow`,viewBox:`0 0 8 8`,refX:`7`,refY:`4`,markerWidth:`5`,markerHeight:`5`,orient:`auto-start-reverse`},[i(`path`,{d:`M0,0 L8,4 L0,8 z`,fill:`currentColor`})])],-1),f(` The cell state: one straight line from edge to edge. `),i(`g`,{class:p([`dl-gcell__highway`,Q(`cin`)])},[i(`line`,{x1:26,y1:b,x2:167,y2:b,"marker-end":`url(#dl-gcell-arrow)`},null,8,ue),i(`text`,{class:`dl-gcell__port`,x:22,y:50,"text-anchor":`end`},[...o[9]||=[d(`c`,-1),i(`tspan`,{class:`dl-gcell__sub`,dy:`3`},`t−1`,-1)]],8,de)],2),i(`line`,{class:p([`dl-gcell__highway-seg`,Q(`fmul`)]),x1:193,y1:b,x2:287,y2:b,"marker-end":`url(#dl-gcell-arrow)`},null,10,fe),i(`g`,{class:p([`dl-gcell__highway`,Q(`cout`)])},[i(`line`,{x1:313,y1:b,x2:520,y2:b,"marker-end":`url(#dl-gcell-arrow)`},null,8,pe),i(`text`,{class:`dl-gcell__port`,x:526,y:50},[...o[10]||=[d(`c`,-1),i(`tspan`,{class:`dl-gcell__sub`,dy:`3`},`t`,-1)]],8,me)],2),f(` forget: × on the highway, fed by a sigmoid `),i(`g`,{class:p(Q(`fmul`))},[i(`circle`,{class:`dl-gcell__node`,cx:T,cy:b,r:N}),i(`text`,{class:`dl-gcell__op`,x:T,y:51,"text-anchor":`middle`},`×`,8,he)],2),i(`line`,{class:p([`dl-gcell__wire`,Q(`fgate`)]),x1:T,y1:x,x2:T,y2:63,"marker-end":`url(#dl-gcell-arrow)`},null,10,ge),i(`g`,{class:p(Q(`fgate`))},[i(`rect`,{class:`dl-gcell__gate`,x:T-S/2,y:x,width:S,height:C,rx:`5`},null,8,_e),i(`text`,{class:`dl-gcell__gatelabel`,x:T,y:181,"text-anchor":`middle`},`σ = `+n(l(_)(R.value)),9,ve),i(`text`,{class:`dl-gcell__gatename`,x:164,y:157,"text-anchor":`end`},[...o[11]||=[d(`f`,-1),i(`tspan`,{class:`dl-gcell__sub`,dy:`3`},`t`,-1)]],8,ye)],2),f(` input × candidate, then + on to the highway `),i(`g`,{class:p(Q(`igmul`))},[i(`circle`,{class:`dl-gcell__node`,cx:D,cy:nt,r:N}),i(`text`,{class:`dl-gcell__op`,x:D,y:113,"text-anchor":`middle`},`×`,8,be),i(`line`,{class:`dl-gcell__wire`,x1:D,y1:95,x2:E,y2:63,"marker-end":`url(#dl-gcell-arrow)`},null,8,xe)],2),i(`line`,{class:p([`dl-gcell__wire`,Q(`igate`)]),x1:A,y1:x,x2:291,y2:117,"marker-end":`url(#dl-gcell-arrow)`},null,10,Se),i(`line`,{class:p([`dl-gcell__wire`,Q(`ggate`)]),x1:j,y1:x,x2:309,y2:117,"marker-end":`url(#dl-gcell-arrow)`},null,10,Ce),i(`g`,{class:p(Q(`igate`))},[i(`rect`,{class:`dl-gcell__gate`,x:A-S/2,y:x,width:S,height:C,rx:`5`},null,8,we),i(`text`,{class:`dl-gcell__gatelabel`,x:A,y:181,"text-anchor":`middle`},`σ = `+n(l(_)(z.value)),9,Te),i(`text`,{class:`dl-gcell__gatename`,x:246,y:157,"text-anchor":`end`},[...o[12]||=[d(`i`,-1),i(`tspan`,{class:`dl-gcell__sub`,dy:`3`},`t`,-1)]],8,Ee)],2),i(`g`,{class:p(Q(`ggate`))},[i(`rect`,{class:`dl-gcell__gate is-tanh`,x:j-S/2,y:x,width:S,height:C,rx:`5`},null,8,De),i(`text`,{class:`dl-gcell__gatelabel`,x:j,y:181,"text-anchor":`middle`},`tanh = `+n(l(_)(B.value)),9,Oe),i(`text`,{class:`dl-gcell__gatename`,x:354,y:157,"text-anchor":`start`},[...o[13]||=[d(`c̃`,-1),i(`tspan`,{class:`dl-gcell__sub`,dy:`3`},`t`,-1)]],8,ke)],2),i(`g`,{class:p(Q(`plus`))},[i(`circle`,{class:`dl-gcell__node is-plus`,cx:E,cy:b,r:N}),i(`text`,{class:`dl-gcell__op`,x:E,y:51,"text-anchor":`middle`},`+`,8,Ae)],2),f(` the branch that becomes h_t `),i(`g`,{class:p(Q(`ctanh`))},[i(`line`,{class:`dl-gcell__wire`,x1:O,y1:b,x2:O,y2:101,"marker-end":`url(#dl-gcell-arrow)`},null,8,je),i(`rect`,{class:`dl-gcell__gate is-tanh`,x:rt-S/2,y:105,width:S,height:C,rx:`5`},null,8,Me),i(`text`,{class:`dl-gcell__gatelabel`,x:rt,y:125,"text-anchor":`middle`},`tanh`,8,Ne)],2),i(`g`,{class:p(Q(`hmul`))},[i(`line`,{class:`dl-gcell__wire`,x1:426,y1:k,x2:453,y2:k,"marker-end":`url(#dl-gcell-arrow)`},null,8,Pe),i(`circle`,{class:`dl-gcell__node`,cx:it,cy:k,r:N}),i(`text`,{class:`dl-gcell__op`,x:it,y:125,"text-anchor":`middle`},`×`,8,Fe)],2),i(`line`,{class:p([`dl-gcell__wire`,Q(`ogate`)]),x1:M,y1:x,x2:M,y2:137,"marker-end":`url(#dl-gcell-arrow)`},null,10,Ie),i(`g`,{class:p(Q(`ogate`))},[i(`rect`,{class:`dl-gcell__gate`,x:M-S/2,y:x,width:S,height:C,rx:`5`},null,8,Le),i(`text`,{class:`dl-gcell__gatelabel`,x:M,y:181,"text-anchor":`middle`},`σ = `+n(l(_)(V.value)),9,Re),i(`text`,{class:`dl-gcell__gatename`,x:454,y:157,"text-anchor":`end`},[...o[14]||=[d(`o`,-1),i(`tspan`,{class:`dl-gcell__sub`,dy:`3`},`t`,-1)]],8,ze)],2),i(`g`,{class:p(Q(`hout`))},[i(`line`,{class:`dl-gcell__wire`,x1:483,y1:k,x2:520,y2:k,"marker-end":`url(#dl-gcell-arrow)`},null,8,Be),i(`text`,{class:`dl-gcell__port`,x:526,y:124},[...o[15]||=[d(`h`,-1),i(`tspan`,{class:`dl-gcell__sub`,dy:`3`},`t`,-1)]],8,Ve)],2),f(` what every gate reads: this step's input and the last hidden state `),i(`g`,{class:p(Q(`bus`))},[i(`rect`,{class:`dl-gcell__inbox`,x:20,y:221,width:112,height:30,rx:`5`},null,8,He),i(`text`,{class:`dl-gcell__inlabel`,x:76,y:240,"text-anchor":`middle`},[...o[16]||=[d(`x`,-1),i(`tspan`,{class:`dl-gcell__sub`,dy:`3`},`t`,-1),i(`tspan`,{dy:`-3`},`, h`,-1),i(`tspan`,{class:`dl-gcell__sub`,dy:`3`},`t−1`,-1)]],8,Ue),i(`line`,{class:`dl-gcell__bus`,x1:132,y1:w,x2:M,y2:w}),(m(!0),a(s,null,r([T,A,j,M],e=>(m(),a(`line`,{key:`stub${e}`,class:`dl-gcell__wire`,x1:e,y1:w,x2:e,y2:196,"marker-end":`url(#dl-gcell-arrow)`},null,8,We))),128))],2),i(`text`,{class:`dl-gcell__caption`,x:26,y:28},`the cell state — a multiply and an add, nothing else`,8,Ge)],8,le)):(m(),a(s,{key:1},[f(` The GRU, as the interpolation it is. `),(m(),a(`svg`,{class:`dl-gcell`,viewBox:`0 0 ${v} ${y}`,preserveAspectRatio:`xMidYMid meet`,role:`img`,"aria-label":`A GRU step shown as bars: the old state and the candidate, each scaled by the update gate, adding up to the new state`},[i(`line`,{class:`dl-gcell__zero`,x1:346,y1:26,x2:346,y2:246},null,8,qe),i(`text`,{class:`dl-gcell__tick`,x:P,y:20,"text-anchor":`middle`},`−1`),i(`text`,{class:`dl-gcell__tick`,x:346,y:20,"text-anchor":`middle`},`0`),i(`text`,{class:`dl-gcell__tick`,x:496,y:20,"text-anchor":`middle`},`+1`,8,Je),(m(!0),a(s,null,r(yt.value,(e,t)=>(m(),a(`g`,{key:e.key,class:p(Q(e.key))},[i(`text`,{class:`dl-gcell__rowlabel`,x:182,y:$(t)+14,"text-anchor":`end`},n(e.label),9,Ye),i(`rect`,{class:`dl-gcell__track`,x:P,y:$(t),width:F,height:20,rx:`3`},null,8,Xe),i(`rect`,{class:p([`dl-gcell__bar`,`is-${e.tone}`]),x:_t(e.value),y:$(t),width:vt(e.value),height:20,rx:`2`},null,10,Ze),i(`text`,{class:`dl-gcell__rowval`,x:508,y:$(t)+14},n(l(_)(e.value)),9,Qe)],2))),128)),i(`line`,{class:`dl-gcell__sep`,x1:40,y1:$(2)-14,x2:536,y2:$(2)-14},null,8,$e),i(`text`,{class:`dl-gcell__caption`,x:40,y:$(2)-20},`the blend`,8,et)],8,Ke))],2112))]),_:1})}}}),[[`__scopeId`,`data-v-bf0d1e22`]]);export{at as t}; |