Download lecture-05/assets/EmbeddingLab-ykKavple.js from DeepLearning-VT/DeepLearning_2026: direct link, hf CLI and curl.
- Browser
- Download file 5.17 kB
-
https://huggingface.co/spaces/DeepLearning-VT/DeepLearning_2026/resolve/main/lecture-05/assets/EmbeddingLab-ykKavple.js
- Command line
-
hf download hf://spaces/DeepLearning-VT/DeepLearning_2026/lecture-05/assets/EmbeddingLab-ykKavple.js
-
curl -L -o EmbeddingLab-ykKavple.js https://huggingface.co/spaces/DeepLearning-VT/DeepLearning_2026/resolve/main/lecture-05/assets/EmbeddingLab-ykKavple.js
5.17 kB
| import{$ as e,S as t,St as n,V as r,_ as i,b as a,g as o,m as s,ut as c,v as l,vt as u,w as d,x as f,y as p,yt 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{n as v}from"./useConvolution-mOidZmS_.js";import{n as y}from"./interactive-Dm0CtntL.js";import{t as b}from"./Plot2D-C9URVmMB.js";import{t as x}from"./PlotLabel-BilrlAqg.js";import{t as S}from"./PlotPoints-CeOGnq0p.js";var C={key:0,class:`dl-emb`},w={class:`dl-emb__grid`},T={class:`dl-emb__head dl-emb__head--wide`},E=[`onClick`],D={class:`dl-emb__result`},O={class:`dl-emb__out`},k={class:`dl-emb__outcap`},A={key:0,class:`dl-emb__tabs`},j=[`onClick`],M={class:`dl-emb__scale`},N={class:`dl-emb__scale`},P=g(d({__name:`EmbeddingLab`,props:{mode:{default:`lookup`},vocabulary:{default:2e4},dim:{default:64},hidden:{default:128}},setup(d){let{$slidev:g,$nav:P,$clicksContext:F,$clicks:I,$page:L,$renderContext:R,$frontmatter:z}=_(),B=[{word:`the`,vec:[0,0,0,.9],group:`function`},{word:`a`,vec:[0,.1,0,.8],group:`function`},{word:`movie`,vec:[.1,.9,.1,.1],group:`thing`},{word:`plot`,vec:[0,.8,0,.1],group:`thing`},{word:`ending`,vec:[0,.7,.1,.1],group:`thing`},{word:`great`,vec:[.8,.1,.6,0],group:`positive`},{word:`brilliant`,vec:[.9,0,.8,0],group:`positive`},{word:`awful`,vec:[-.8,.1,.6,0],group:`negative`},{word:`terrible`,vec:[-.9,0,.8,0],group:`negative`}],V={plot:{dx:-10,dy:-9,anchor:`end`},brilliant:{dx:-10,dy:16,anchor:`end`},terrible:{dx:10,dy:16,anchor:`start`}};function H(e){return V[e.word]??(e.vec[0]>.3?{dx:-10,dy:-9,anchor:`end`}:{dx:10,dy:-9,anchor:`start`})}let U=d,W=c(5),G=o(()=>B[W.value]),K=e=>e.toLocaleString(`en-US`),q=o(()=>U.vocabulary*U.hidden),J=o(()=>U.vocabulary*U.dim+U.dim*U.hidden),Y={positive:`var(--dl-accent)`,negative:`var(--dl-danger)`,thing:`var(--dl-heading)`,function:`var(--dl-muted)`},X=o(()=>B.map((e,t)=>({x:e.vec[0],y:e.vec[1],cls:e.group,highlight:t===W.value})));return(o,c)=>{let d=S,g=x,_=b,P=y;return h(),l(P,{"max-width":U.mode===`space`?`34rem`:`40rem`},{controls:e(()=>[U.mode===`space`?(h(),a(`div`,A,[(h(),a(s,null,r(B,(e,t)=>i(`button`,{key:e.word,type:`button`,class:m({"is-selected":t===W.value}),onClick:e=>W.value=t},n(e.word),11,j)),64))])):p(`v-if`,!0)]),readout:e(()=>[U.mode===`lookup`?(h(),a(s,{key:0},[f(` The one-hot column has a single 1, in row `+n(W.value)+` — so the product picks `,1),i(`strong`,null,`row `+n(W.value),1),c[6]||=f(` of E and nothing else. `,-1),c[7]||=i(`code`,null,`nn.Embedding`,-1),c[8]||=f(` skips the multiply and indexes the row directly. `,-1),i(`div`,M,[f(` At real scale, `+n(K(U.vocabulary))+` words into a `+n(U.hidden)+`-unit layer: one-hot needs `+n(K(U.vocabulary))+` × `+n(U.hidden)+` = `,1),i(`strong`,null,n(K(q.value)),1),f(` weights; a `+n(U.dim)+`-wide embedding needs `+n(K(U.vocabulary))+` × `+n(U.dim)+` + `+n(U.dim)+` × `+n(U.hidden)+` = `,1),i(`strong`,null,n(K(J.value)),1),c[5]||=f(`. `,-1)])],64)):(h(),a(s,{key:1},[c[9]||=f(` Nobody wrote these coordinates — they are weights, trained by the same gradient descent as every other layer. `,-1),c[10]||=i(`strong`,null,`great`,-1),c[11]||=f(` and `,-1),c[12]||=i(`strong`,null,`brilliant`,-1),c[13]||=f(` end up beside each other because they did the same job in the training reviews; one-hot puts every pair of words exactly the same distance apart. `,-1),i(`div`,N,` The axes are named here so the picture is readable. In a real `+n(U.dim)+`-dimensional table no single axis means anything you could name. `,1)],64))]),default:e(()=>[U.mode===`lookup`?(h(),a(`div`,C,[i(`div`,w,[c[0]||=i(`div`,{class:`dl-emb__head`},`word`,-1),c[1]||=i(`div`,{class:`dl-emb__head`},`one-hot`,-1),i(`div`,T,`E — the embedding matrix, `+n(B.length)+` × 4`,1),(h(),a(s,null,r(B,(e,t)=>(h(),a(s,{key:e.word},[i(`button`,{type:`button`,class:m([`dl-emb__word`,{"is-selected":t===W.value}]),onClick:e=>W.value=t},n(e.word),11,E),i(`div`,{class:m([`dl-emb__onehot`,{"is-hot":t===W.value}])},n(+(t===W.value)),3),i(`div`,{class:m([`dl-emb__row`,{"is-selected":t===W.value}])},[(h(!0),a(s,null,r(e.vec,(e,t)=>(h(),a(`div`,{key:t,class:`dl-emb__cell`},n(u(v)(e)),1))),128))],2)],64))),64))]),i(`div`,D,[c[4]||=i(`div`,{class:`dl-emb__arrow`,"aria-hidden":`true`},`→`,-1),i(`div`,O,[(h(!0),a(s,null,r(G.value.vec,(e,t)=>(h(),a(`div`,{key:t,class:`dl-emb__cell is-out`},n(u(v)(e)),1))),128))]),i(`div`,k,[c[2]||=f(`the vector for`,-1),c[3]||=i(`br`,null,null,-1),i(`strong`,null,n(G.value.word),1)])])])):(h(),a(s,{key:1},[p(` The same table, read as a map. `),t(_,{"x-domain":[-1.15,1.15],"y-domain":[-.25,1.15],"x-ticks":[-1,-.5,0,.5,1],"y-ticks":[0,.5,1],"x-label":`learned dimension 1`,"y-label":`learned dimension 2`,width:520,height:300},{default:e(()=>[t(d,{points:X.value,radius:6,colors:Y},null,8,[`points`]),(h(),a(s,null,r(B,(e,n)=>t(g,{key:e.word,at:[e.vec[0],e.vec[1]],dx:H(e).dx,dy:H(e).dy,anchor:H(e).anchor,color:Y[e.group],bold:n===W.value,size:12,text:e.word},null,8,[`at`,`dx`,`dy`,`anchor`,`color`,`bold`,`text`])),64))]),_:1})],2112))]),_:1},8,[`max-width`])}}}),[[`__scopeId`,`data-v-3a7d772c`]]);export{P as t}; |