Download lecture-05/assets/GradientFlow-BOW0fXlu.js from DeepLearning-VT/DeepLearning_2026: direct link, hf CLI and curl.
- Browser
- Download file 5.49 kB
-
https://huggingface.co/spaces/DeepLearning-VT/DeepLearning_2026/resolve/main/lecture-05/assets/GradientFlow-BOW0fXlu.js
- Command line
-
hf download hf://spaces/DeepLearning-VT/DeepLearning_2026/lecture-05/assets/GradientFlow-BOW0fXlu.js
-
curl -L -o GradientFlow-BOW0fXlu.js https://huggingface.co/spaces/DeepLearning-VT/DeepLearning_2026/resolve/main/lecture-05/assets/GradientFlow-BOW0fXlu.js
5.49 kB
| import{$ as e,S as t,St as n,_ as r,b as i,c as a,et as o,g as s,m as c,ut as l,v as u,vt as d,w as f,x as p,y as m,z as h}from"./modules/shiki-CkJq9tSf.js";import{t as g}from"./_plugin-vue_export-helper-BDNMzG2s.js";import{n as _}from"./slidev/context-DnYiQGy6.js";import{a as v,f as y}from"./useRecurrence-PhWWMav6.js";import{n as b}from"./interactive-Dm0CtntL.js";import{t as x}from"./Slider-Bf0ITYx4.js";import{t as S}from"./Plot2D-C9URVmMB.js";import{t as C}from"./PlotLabel-BilrlAqg.js";import{n as w,t as T}from"./PlotLine-yjOYb3U7.js";var E={key:1,class:`dl-gflow__toggle`},D=5,O=-12,k=4,A=g(f({__name:`GradientFlow`,props:{mode:{default:`decay`},steps:{default:25},w:{default:.6},forget:{default:.99},clip:{type:Boolean,default:!0}},setup(f){let{$slidev:g,$nav:A,$clicksContext:j,$clicks:M,$page:N,$renderContext:P,$frontmatter:F}=_(),I=f,L=l(I.w),R=l(I.forget),z=l(!1),B=Math.log10(D);function V(e,t){return v(e,I.steps).map((e,n)=>{let r=e===0?-13:Math.log10(e);return{x:n,y:t&&r>B?B:r}})}let H=s(()=>V(L.value,z.value&&I.clip)),U=s(()=>V(R.value,!1)),W=s(()=>Math.abs(L.value-1)<1e-9?`hold`:L.value<1?`vanish`:`explode`),G=s(()=>Math.abs(L.value)**Math.min(20,I.steps)),K=s(()=>Math.abs(R.value)**Math.min(20,I.steps)),q=s(()=>y(L.value,.01)),J={0:`⁰`,1:`¹`,2:`²`,3:`³`,4:`⁴`,5:`⁵`,6:`⁶`,7:`⁷`,8:`⁸`,9:`⁹`,"-":`⁻`,"+":``};function Y(e){if(e===0)return`0`;let t=Math.abs(e);if(t>=.001&&t<1)return String(Number(e.toPrecision(2)));if(t>=1&&t<1e4)return String(Number(e.toPrecision(3)));let[n,r]=e.toExponential(1).split(`e`);return`${n} \u00d7 10${[...r].map(e=>J[e]??e).join(``)}`}return(s,l)=>{let f=T,g=w,_=C,v=S,y=x,A=b;return h(),u(A,{"max-width":`34rem`},{controls:e(()=>[t(y,{modelValue:L.value,"onUpdate:modelValue":l[0]||=e=>L.value=e,label:`recurrent weight W`,min:.2,max:1.6,step:.05,precision:2},null,8,[`modelValue`]),I.mode===`gated`?(h(),u(y,{key:0,modelValue:R.value,"onUpdate:modelValue":l[1]||=e=>R.value=e,label:`forget gate f`,min:.8,max:1,step:.005,precision:3},null,8,[`modelValue`])):m(`v-if`,!0),I.clip&&I.mode===`decay`?(h(),i(`label`,E,[o(r(`input`,{"onUpdate:modelValue":l[2]||=e=>z.value=e,type:`checkbox`},null,512),[[a,z.value]]),l[3]||=p(` gradient clipping `,-1)])):m(`v-if`,!0)]),readout:e(()=>[I.mode===`gated`?(h(),i(c,{key:0},[l[4]||=p(` Twenty steps back, the plain recurrence has multiplied by `,-1),r(`strong`,null,n(Y(G.value)),1),l[5]||=p(`; the cell state, by `,-1),r(`strong`,null,n(Y(K.value)),1),l[6]||=p(`. Push `,-1),l[7]||=r(`em`,null,`f`,-1),l[8]||=p(` to 1.000 and the factor is exactly `,-1),l[9]||=r(`strong`,null,`1`,-1),l[10]||=p(` — the gradient reaches the start of the sequence undamaged. `,-1)],64)):W.value===`vanish`?(h(),i(c,{key:1},[l[11]||=r(`strong`,null,`Vanishing.`,-1),p(` Twenty steps back the gradient carries a factor of `+n(L.value.toFixed(2)),1),l[12]||=r(`sup`,null,`20`,-1),l[13]||=p(` = `,-1),r(`strong`,null,n(Y(G.value)),1),l[14]||=p(`. It is still worth 1% of its original size about `,-1),r(`strong`,null,n(q.value),1),l[15]||=p(` steps back — past that, the end of the sentence cannot teach the weights that read its beginning. `,-1)],64)):W.value===`hold`?(h(),i(c,{key:2},[l[16]||=r(`strong`,null,`The knife edge.`,-1),l[17]||=p(` At exactly 1 the gradient neither shrinks nor grows. Nothing keeps a trained weight there, and this is one number out of a whole matrix. `,-1)],64)):(h(),i(c,{key:3},[l[21]||=r(`strong`,null,`Exploding.`,-1),p(` `+n(L.value.toFixed(2)),1),l[22]||=r(`sup`,null,`20`,-1),l[23]||=p(` = `,-1),r(`strong`,null,n(Y(G.value)),1),p(`, and by step `+n(I.steps)+` it is `+n(Y(Math.abs(L.value)**I.steps))+`. One long sequence and the update overshoots — the loss goes to NaN in a single batch. `,1),I.clip?(h(),i(c,{key:0},[l[18]||=p(` Tick `,-1),l[19]||=r(`strong`,null,`gradient clipping`,-1),l[20]||=p(`: the ceiling caps it. Notice it does nothing at all to the vanishing end. `,-1)],64)):m(`v-if`,!0)],64))]),default:e(()=>[t(v,{"x-domain":[0,I.steps],"y-domain":[O,k],"x-ticks":[0,5,10,15,20,25].filter(e=>e<=I.steps),"y-ticks":[-12,-9,-6,-3,0,3],"x-label":`time steps back through the sequence`,"y-label":`log₁₀ of the gradient's size`,width:520,height:290},{default:e(()=>[m(` Unity: the gradient neither grows nor shrinks. `),t(f,{from:[0,0],to:[I.steps,0],color:`var(--dl-muted)`,width:1.2,dashed:``},null,8,[`to`]),z.value&&I.clip&&I.mode===`decay`?(h(),u(f,{key:0,from:[0,d(B)],to:[I.steps,d(B)],color:`var(--dl-danger)`,width:1.2,dashed:``},null,8,[`from`,`to`])):m(`v-if`,!0),t(g,{points:H.value,color:I.mode===`gated`?`var(--dl-danger)`:`var(--dl-accent)`,width:2.6},null,8,[`points`,`color`]),I.mode===`gated`?(h(),u(g,{key:1,points:U.value,color:`var(--dl-accent)`,width:2.6},null,8,[`points`])):m(`v-if`,!0),I.mode===`gated`?(h(),u(_,{key:2,at:[I.steps,U.value[I.steps].y],dx:-6,dy:-10,anchor:`end`,color:`var(--dl-accent)`,text:`LSTM cell state — multiplied by the forget gate`,size:11,bold:``},null,8,[`at`])):m(`v-if`,!0),I.mode===`gated`?(h(),u(_,{key:3,at:[I.steps,Math.min(Math.max(H.value[I.steps].y,-11),3)],dx:-6,dy:22,anchor:`end`,color:`var(--dl-danger)`,text:`plain RNN — multiplied by W`,size:11,bold:``},null,8,[`at`])):m(`v-if`,!0),z.value&&I.clip&&I.mode===`decay`?(h(),u(_,{key:4,at:[1,d(B)],dx:4,dy:-6,color:`var(--dl-danger)`,text:`clipped at ${D}×`,size:11},null,8,[`at`,`text`])):m(`v-if`,!0)]),_:1},8,[`x-domain`,`y-domain`,`x-ticks`])]),_:1})}}}),[[`__scopeId`,`data-v-d7ea900e`]]);export{A as t}; |