import{S as Ec,i as jc,s as qc,e as n,k as d,w as v,t as a,M as Tc,c as r,d as s,m as u,x as y,a as l,h as o,b as j,N as yc,f as jo,G as t,g as c,y as k,o as b,p as qo,q as w,B as x,v as Dc,n as To}from"../../chunks/vendor-hf-doc-builder.js";import{T as kc}from"../../chunks/Tip-hf-doc-builder.js";import{Y as Cc}from"../../chunks/Youtube-hf-doc-builder.js";import{I as pa}from"../../chunks/IconCopyLink-hf-doc-builder.js";import{C as O}from"../../chunks/CodeBlock-hf-doc-builder.js";import{C as xc}from"../../chunks/CourseFloatingBanner-hf-doc-builder.js";import{F as Ac}from"../../chunks/FrameworkSwitchCourse-hf-doc-builder.js";function Sc(W){let p,$;return p=new xc({props:{chapter:5,classNames:"absolute z-10 right-0 top-0",notebooks:[{label:"Google Colab",value:"https://colab.research.google.com/github/huggingface/notebooks/blob/master/course/en/chapter5/section6_tf.ipynb"},{label:"Aws Studio",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/master/course/en/chapter5/section6_tf.ipynb"}]}}),{c(){v(p.$$.fragment)},l(h){y(p.$$.fragment,h)},m(h,E){k(p,h,E),$=!0},i(h){$||(w(p.$$.fragment,h),$=!0)},o(h){b(p.$$.fragment,h),$=!1},d(h){x(p,h)}}}function Oc(W){let p,$;return p=new xc({props:{chapter:5,classNames:"absolute z-10 right-0 top-0",notebooks:[{label:"Google Colab",value:"https://colab.research.google.com/github/huggingface/notebooks/blob/master/course/en/chapter5/section6_pt.ipynb"},{label:"Aws Studio",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/master/course/en/chapter5/section6_pt.ipynb"}]}}),{c(){v(p.$$.fragment)},l(h){y(p.$$.fragment,h)},m(h,E){k(p,h,E),$=!0},i(h){$||(w(p.$$.fragment,h),$=!0)},o(h){b(p.$$.fragment,h),$=!1},d(h){x(p,h)}}}function Ic(W){let p,$,h,E,f,g,I,_,A,q,M,P,S,N,F,R,U,D,H,B;return{c(){p=n("p"),$=a("\u270F\uFE0F "),h=n("strong"),E=a("Try it out!"),f=a(" See if you can use "),g=n("code"),I=a("Dataset.map()"),_=a(" to explode the "),A=n("code"),q=a("comments"),M=a(" column of "),P=n("code"),S=a("issues_dataset"),N=d(),F=n("em"),R=a("without"),U=a(" resorting to the use of Pandas. This is a little tricky; you might find the "),D=n("a"),H=a("\u201CBatch mapping\u201D"),B=a(" section of the \u{1F917} Datasets documentation useful for this task."),this.h()},l(z){p=r(z,"P",{});var T=l(p);$=o(T,"\u270F\uFE0F "),h=r(T,"STRONG",{});var G=l(h);E=o(G,"Try it out!"),G.forEach(s),f=o(T," See if you can use "),g=r(T,"CODE",{});var m=l(g);I=o(m,"Dataset.map()"),m.forEach(s),_=o(T," to explode the "),A=r(T,"CODE",{});var C=l(A);q=o(C,"comments"),C.forEach(s),M=o(T," column of "),P=r(T,"CODE",{});var L=l(P);S=o(L,"issues_dataset"),L.forEach(s),N=u(T),F=r(T,"EM",{});var V=l(F);R=o(V,"without"),V.forEach(s),U=o(T," resorting to the use of Pandas. This is a little tricky; you might find the "),D=r(T,"A",{href:!0,rel:!0});var ne=l(D);H=o(ne,"\u201CBatch mapping\u201D"),ne.forEach(s),B=o(T," section of the \u{1F917} Datasets documentation useful for this task."),T.forEach(s),this.h()},h(){j(D,"href","https://huggingface.co/docs/datasets/v1.12.1/about_map_batch.html?batch-mapping#batch-mapping"),j(D,"rel","nofollow")},m(z,T){c(z,p,T),t(p,$),t(p,h),t(h,E),t(p,f),t(p,g),t(g,I),t(p,_),t(p,A),t(A,q),t(p,M),t(p,P),t(P,S),t(p,N),t(p,F),t(F,R),t(p,U),t(p,D),t(D,H),t(p,B)},d(z){z&&s(p)}}}function Pc(W){let p,$,h,E,f,g,I,_,A,q,M,P,S,N,F,R,U;return p=new O({props:{code:`from transformers import AutoTokenizer, TFAutoModel

model_ckpt = "sentence-transformers/multi-qa-mpnet-base-dot-v1"
tokenizer = AutoTokenizer.from_pretrained(model_ckpt)
model = TFAutoModel.from_pretrained(model_ckpt, from_pt=True)`,highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoTokenizer, TFAutoModel

model_ckpt = <span class="hljs-string">&quot;sentence-transformers/multi-qa-mpnet-base-dot-v1&quot;</span>
tokenizer = AutoTokenizer.from_pretrained(model_ckpt)
model = TFAutoModel.from_pretrained(model_ckpt, from_pt=<span class="hljs-literal">True</span>)`}}),{c(){v(p.$$.fragment),$=d(),h=n("p"),E=a("Note that we\u2019ve set "),f=n("code"),g=a("from_pt=True"),I=a(" as an argument of the "),_=n("code"),A=a("from_pretrained()"),q=a(" method. That\u2019s because the "),M=n("code"),P=a("multi-qa-mpnet-base-dot-v1"),S=a(" checkpoint only has PyTorch weights, so setting "),N=n("code"),F=a("from_pt=True"),R=a(" will automatically convert them to the TensorFlow format for us. As you can see, it is very simple to switch between frameworks in \u{1F917} Transformers!")},l(D){y(p.$$.fragment,D),$=u(D),h=r(D,"P",{});var H=l(h);E=o(H,"Note that we\u2019ve set "),f=r(H,"CODE",{});var B=l(f);g=o(B,"from_pt=True"),B.forEach(s),I=o(H," as an argument of the "),_=r(H,"CODE",{});var z=l(_);A=o(z,"from_pretrained()"),z.forEach(s),q=o(H," method. That\u2019s because the "),M=r(H,"CODE",{});var T=l(M);P=o(T,"multi-qa-mpnet-base-dot-v1"),T.forEach(s),S=o(H," checkpoint only has PyTorch weights, so setting "),N=r(H,"CODE",{});var G=l(N);F=o(G,"from_pt=True"),G.forEach(s),R=o(H," will automatically convert them to the TensorFlow format for us. As you can see, it is very simple to switch between frameworks in \u{1F917} Transformers!"),H.forEach(s)},m(D,H){k(p,D,H),c(D,$,H),c(D,h,H),t(h,E),t(h,f),t(f,g),t(h,I),t(h,_),t(_,A),t(h,q),t(h,M),t(M,P),t(h,S),t(h,N),t(N,F),t(h,R),U=!0},i(D){U||(w(p.$$.fragment,D),U=!0)},o(D){b(p.$$.fragment,D),U=!1},d(D){x(p,D),D&&s($),D&&s(h)}}}function Nc(W){let p,$,h,E,f,g,I;return p=new O({props:{code:`from transformers import AutoTokenizer, AutoModel

model_ckpt = "sentence-transformers/multi-qa-mpnet-base-dot-v1"
tokenizer = AutoTokenizer.from_pretrained(model_ckpt)
model = AutoModel.from_pretrained(model_ckpt)`,highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoTokenizer, AutoModel

model_ckpt = <span class="hljs-string">&quot;sentence-transformers/multi-qa-mpnet-base-dot-v1&quot;</span>
tokenizer = AutoTokenizer.from_pretrained(model_ckpt)
model = AutoModel.from_pretrained(model_ckpt)`}}),g=new O({props:{code:`import torch

device = torch.device("cuda")
model.to(device)`,highlighted:`<span class="hljs-keyword">import</span> torch

device = torch.device(<span class="hljs-string">&quot;cuda&quot;</span>)
model.to(device)`}}),{c(){v(p.$$.fragment),$=d(),h=n("p"),E=a("To speed up the embedding process, it helps to place the model and inputs on a GPU device, so let\u2019s do that now:"),f=d(),v(g.$$.fragment)},l(_){y(p.$$.fragment,_),$=u(_),h=r(_,"P",{});var A=l(h);E=o(A,"To speed up the embedding process, it helps to place the model and inputs on a GPU device, so let\u2019s do that now:"),A.forEach(s),f=u(_),y(g.$$.fragment,_)},m(_,A){k(p,_,A),c(_,$,A),c(_,h,A),t(h,E),c(_,f,A),k(g,_,A),I=!0},i(_){I||(w(p.$$.fragment,_),w(g.$$.fragment,_),I=!0)},o(_){b(p.$$.fragment,_),b(g.$$.fragment,_),I=!1},d(_){x(p,_),_&&s($),_&&s(h),_&&s(f),x(g,_)}}}function Fc(W){let p,$,h,E,f,g,I,_,A,q,M,P,S,N,F,R,U,D,H,B,z,T,G;return p=new O({props:{code:`def get_embeddings(text_list):
    encoded_input = tokenizer(
        text_list, padding=True, truncation=True, return_tensors="tf"
    )
    encoded_input = {k: v for k, v in encoded_input.items()}
    model_output = model(**encoded_input)
    return cls_pooling(model_output)`,highlighted:`<span class="hljs-keyword">def</span> <span class="hljs-title function_">get_embeddings</span>(<span class="hljs-params">text_list</span>):
    encoded_input = tokenizer(
        text_list, padding=<span class="hljs-literal">True</span>, truncation=<span class="hljs-literal">True</span>, return_tensors=<span class="hljs-string">&quot;tf&quot;</span>
    )
    encoded_input = {k: v <span class="hljs-keyword">for</span> k, v <span class="hljs-keyword">in</span> encoded_input.items()}
    model_output = model(**encoded_input)
    <span class="hljs-keyword">return</span> cls_pooling(model_output)`}}),g=new O({props:{code:`embedding = get_embeddings(comments_dataset["text"][0])
embedding.shape`,highlighted:`embedding = get_embeddings(comments_dataset[<span class="hljs-string">&quot;text&quot;</span>][<span class="hljs-number">0</span>])
embedding.shape`}}),_=new O({props:{code:"TensorShape([1, 768])",highlighted:'TensorShape([<span class="hljs-number">1</span>, <span class="hljs-number">768</span>])'}}),T=new O({props:{code:`embeddings_dataset = comments_dataset.map(
    lambda x: {"embeddings": get_embeddings(x["text"]).numpy()[0]}
)`,highlighted:`embeddings_dataset = comments_dataset.<span class="hljs-built_in">map</span>(
    <span class="hljs-keyword">lambda</span> x: {<span class="hljs-string">&quot;embeddings&quot;</span>: get_embeddings(x[<span class="hljs-string">&quot;text&quot;</span>]).numpy()[<span class="hljs-number">0</span>]}
)`}}),{c(){v(p.$$.fragment),$=d(),h=n("p"),E=a("We can test the function works by feeding it the first text entry in our corpus and inspecting the output shape:"),f=d(),v(g.$$.fragment),I=d(),v(_.$$.fragment),A=d(),q=n("p"),M=a("Great, we\u2019ve converted the first entry in our corpus into a 768-dimensional vector! We can use "),P=n("code"),S=a("Dataset.map()"),N=a(" to apply our "),F=n("code"),R=a("get_embeddings()"),U=a(" function to each row in our corpus, so let\u2019s create a new "),D=n("code"),H=a("embeddings"),B=a(" column as follows:"),z=d(),v(T.$$.fragment)},l(m){y(p.$$.fragment,m),$=u(m),h=r(m,"P",{});var C=l(h);E=o(C,"We can test the function works by feeding it the first text entry in our corpus and inspecting the output shape:"),C.forEach(s),f=u(m),y(g.$$.fragment,m),I=u(m),y(_.$$.fragment,m),A=u(m),q=r(m,"P",{});var L=l(q);M=o(L,"Great, we\u2019ve converted the first entry in our corpus into a 768-dimensional vector! We can use "),P=r(L,"CODE",{});var V=l(P);S=o(V,"Dataset.map()"),V.forEach(s),N=o(L," to apply our "),F=r(L,"CODE",{});var ne=l(F);R=o(ne,"get_embeddings()"),ne.forEach(s),U=o(L," function to each row in our corpus, so let\u2019s create a new "),D=r(L,"CODE",{});var ce=l(D);H=o(ce,"embeddings"),ce.forEach(s),B=o(L," column as follows:"),L.forEach(s),z=u(m),y(T.$$.fragment,m)},m(m,C){k(p,m,C),c(m,$,C),c(m,h,C),t(h,E),c(m,f,C),k(g,m,C),c(m,I,C),k(_,m,C),c(m,A,C),c(m,q,C),t(q,M),t(q,P),t(P,S),t(q,N),t(q,F),t(F,R),t(q,U),t(q,D),t(D,H),t(q,B),c(m,z,C),k(T,m,C),G=!0},i(m){G||(w(p.$$.fragment,m),w(g.$$.fragment,m),w(_.$$.fragment,m),w(T.$$.fragment,m),G=!0)},o(m){b(p.$$.fragment,m),b(g.$$.fragment,m),b(_.$$.fragment,m),b(T.$$.fragment,m),G=!1},d(m){x(p,m),m&&s($),m&&s(h),m&&s(f),x(g,m),m&&s(I),x(_,m),m&&s(A),m&&s(q),m&&s(z),x(T,m)}}}function Hc(W){let p,$,h,E,f,g,I,_,A,q,M,P,S,N,F,R,U,D,H,B,z,T,G;return p=new O({props:{code:`def get_embeddings(text_list):
    encoded_input = tokenizer(
        text_list, padding=True, truncation=True, return_tensors="pt"
    )
    encoded_input = {k: v.to(device) for k, v in encoded_input.items()}
    model_output = model(**encoded_input)
    return cls_pooling(model_output)`,highlighted:`<span class="hljs-keyword">def</span> <span class="hljs-title function_">get_embeddings</span>(<span class="hljs-params">text_list</span>):
    encoded_input = tokenizer(
        text_list, padding=<span class="hljs-literal">True</span>, truncation=<span class="hljs-literal">True</span>, return_tensors=<span class="hljs-string">&quot;pt&quot;</span>
    )
    encoded_input = {k: v.to(device) <span class="hljs-keyword">for</span> k, v <span class="hljs-keyword">in</span> encoded_input.items()}
    model_output = model(**encoded_input)
    <span class="hljs-keyword">return</span> cls_pooling(model_output)`}}),g=new O({props:{code:`embedding = get_embeddings(comments_dataset["text"][0])
embedding.shape`,highlighted:`embedding = get_embeddings(comments_dataset[<span class="hljs-string">&quot;text&quot;</span>][<span class="hljs-number">0</span>])
embedding.shape`}}),_=new O({props:{code:"torch.Size([1, 768])",highlighted:'torch.Size([<span class="hljs-number">1</span>, <span class="hljs-number">768</span>])'}}),T=new O({props:{code:`embeddings_dataset = comments_dataset.map(
    lambda x: {"embeddings": get_embeddings(x["text"]).detach().cpu().numpy()[0]}
)`,highlighted:`embeddings_dataset = comments_dataset.<span class="hljs-built_in">map</span>(
    <span class="hljs-keyword">lambda</span> x: {<span class="hljs-string">&quot;embeddings&quot;</span>: get_embeddings(x[<span class="hljs-string">&quot;text&quot;</span>]).detach().cpu().numpy()[<span class="hljs-number">0</span>]}
)`}}),{c(){v(p.$$.fragment),$=d(),h=n("p"),E=a("We can test the function works by feeding it the first text entry in our corpus and inspecting the output shape:"),f=d(),v(g.$$.fragment),I=d(),v(_.$$.fragment),A=d(),q=n("p"),M=a("Great, we\u2019ve converted the first entry in our corpus into a 768-dimensional vector! We can use "),P=n("code"),S=a("Dataset.map()"),N=a(" to apply our "),F=n("code"),R=a("get_embeddings()"),U=a(" function to each row in our corpus, so let\u2019s create a new "),D=n("code"),H=a("embeddings"),B=a(" column as follows:"),z=d(),v(T.$$.fragment)},l(m){y(p.$$.fragment,m),$=u(m),h=r(m,"P",{});var C=l(h);E=o(C,"We can test the function works by feeding it the first text entry in our corpus and inspecting the output shape:"),C.forEach(s),f=u(m),y(g.$$.fragment,m),I=u(m),y(_.$$.fragment,m),A=u(m),q=r(m,"P",{});var L=l(q);M=o(L,"Great, we\u2019ve converted the first entry in our corpus into a 768-dimensional vector! We can use "),P=r(L,"CODE",{});var V=l(P);S=o(V,"Dataset.map()"),V.forEach(s),N=o(L," to apply our "),F=r(L,"CODE",{});var ne=l(F);R=o(ne,"get_embeddings()"),ne.forEach(s),U=o(L," function to each row in our corpus, so let\u2019s create a new "),D=r(L,"CODE",{});var ce=l(D);H=o(ce,"embeddings"),ce.forEach(s),B=o(L," column as follows:"),L.forEach(s),z=u(m),y(T.$$.fragment,m)},m(m,C){k(p,m,C),c(m,$,C),c(m,h,C),t(h,E),c(m,f,C),k(g,m,C),c(m,I,C),k(_,m,C),c(m,A,C),c(m,q,C),t(q,M),t(q,P),t(P,S),t(q,N),t(q,F),t(F,R),t(q,U),t(q,D),t(D,H),t(q,B),c(m,z,C),k(T,m,C),G=!0},i(m){G||(w(p.$$.fragment,m),w(g.$$.fragment,m),w(_.$$.fragment,m),w(T.$$.fragment,m),G=!0)},o(m){b(p.$$.fragment,m),b(g.$$.fragment,m),b(_.$$.fragment,m),b(T.$$.fragment,m),G=!1},d(m){x(p,m),m&&s($),m&&s(h),m&&s(f),x(g,m),m&&s(I),x(_,m),m&&s(A),m&&s(q),m&&s(z),x(T,m)}}}function Rc(W){let p,$,h,E;return p=new O({props:{code:`question = "How can I load a dataset offline?"
question_embedding = get_embeddings([question]).numpy()
question_embedding.shape`,highlighted:`question = <span class="hljs-string">&quot;How can I load a dataset offline?&quot;</span>
question_embedding = get_embeddings([question]).numpy()
question_embedding.shape`}}),h=new O({props:{code:"(1, 768)",highlighted:'(<span class="hljs-number">1</span>, <span class="hljs-number">768</span>)'}}),{c(){v(p.$$.fragment),$=d(),v(h.$$.fragment)},l(f){y(p.$$.fragment,f),$=u(f),y(h.$$.fragment,f)},m(f,g){k(p,f,g),c(f,$,g),k(h,f,g),E=!0},i(f){E||(w(p.$$.fragment,f),w(h.$$.fragment,f),E=!0)},o(f){b(p.$$.fragment,f),b(h.$$.fragment,f),E=!1},d(f){x(p,f),f&&s($),x(h,f)}}}function Lc(W){let p,$,h,E;return p=new O({props:{code:`question = "How can I load a dataset offline?"
question_embedding = get_embeddings([question]).cpu().detach().numpy()
question_embedding.shape`,highlighted:`question = <span class="hljs-string">&quot;How can I load a dataset offline?&quot;</span>
question_embedding = get_embeddings([question]).cpu().detach().numpy()
question_embedding.shape`}}),h=new O({props:{code:"torch.Size([1, 768])",highlighted:'torch.Size([<span class="hljs-number">1</span>, <span class="hljs-number">768</span>])'}}),{c(){v(p.$$.fragment),$=d(),v(h.$$.fragment)},l(f){y(p.$$.fragment,f),$=u(f),y(h.$$.fragment,f)},m(f,g){k(p,f,g),c(f,$,g),k(h,f,g),E=!0},i(f){E||(w(p.$$.fragment,f),w(h.$$.fragment,f),E=!0)},o(f){b(p.$$.fragment,f),b(h.$$.fragment,f),E=!1},d(f){x(p,f),f&&s($),x(h,f)}}}function Mc(W){let p,$,h,E,f,g,I,_,A,q,M;return{c(){p=n("p"),$=a("\u270F\uFE0F "),h=n("strong"),E=a("Try it out!"),f=a(" Create your own query and see whether you can find an answer in the retrieved documents. You might have to increase the "),g=n("code"),I=a("k"),_=a(" parameter in "),A=n("code"),q=a("Dataset.get_nearest_examples()"),M=a(" to broaden the search.")},l(P){p=r(P,"P",{});var S=l(p);$=o(S,"\u270F\uFE0F "),h=r(S,"STRONG",{});var N=l(h);E=o(N,"Try it out!"),N.forEach(s),f=o(S," Create your own query and see whether you can find an answer in the retrieved documents. You might have to increase the "),g=r(S,"CODE",{});var F=l(g);I=o(F,"k"),F.forEach(s),_=o(S," parameter in "),A=r(S,"CODE",{});var R=l(A);q=o(R,"Dataset.get_nearest_examples()"),R.forEach(s),M=o(S," to broaden the search."),S.forEach(s)},m(P,S){c(P,p,S),t(p,$),t(p,h),t(h,E),t(p,f),t(p,g),t(g,I),t(p,_),t(p,A),t(A,q),t(p,M)},d(P){P&&s(p)}}}function Wc(W){let p,$,h,E,f,g,I,_,A,q,M,P,S,N,F,R,U,D,H,B,z,T,G,m,C,L,V,ne,ce,Do,ma,ge,Co,Dt,Ao,So,Kt,Oo,Io,ha,Ct,Po,fa,De,Be,Ol,No,Ve,Il,_a,Ce,Oe,Zt,Je,Fo,es,Ho,ga,Ie,Ro,ts,Lo,Mo,ba,Qe,wa,Xe,$a,J,Wo,ss,zo,Uo,as,Go,Yo,os,Bo,Vo,ns,Jo,Qo,rs,Xo,Ko,va,Ke,ya,Ze,ka,Q,Zo,ls,en,tn,is,sn,an,cs,on,nn,ds,rn,ln,us,cn,dn,xa,et,Ea,tt,ja,K,un,ps,pn,mn,ms,hn,fn,Pe,hs,_n,gn,bn,fs,wn,$n,qa,st,Ta,Ne,vn,_s,yn,kn,Da,at,Ca,ot,Aa,Fe,xn,gs,En,jn,Sa,nt,Oa,ee,bs,Z,Ia,qn,ws,Tn,Dn,$s,Cn,An,vs,Sn,On,ys,In,Pn,de,te,ks,Nn,Fn,xs,Hn,Rn,Es,Ln,Mn,js,Wn,zn,qs,Un,Gn,se,Ts,Yn,Bn,Ds,Vn,Jn,Cs,Qn,Xn,As,Kn,Zn,Ss,er,tr,ae,Os,sr,ar,Is,or,nr,Ps,rr,lr,Ns,ir,cr,Fs,dr,ur,oe,Hs,pr,mr,Rs,hr,fr,Ls,_r,gr,Ms,br,wr,Ws,$r,Pa,re,vr,zs,yr,kr,Us,xr,Er,Gs,jr,qr,Na,rt,Fa,lt,Ha,At,Tr,Ra,He,La,Re,Dr,Ys,Cr,Ar,Ma,it,Wa,St,Sr,za,ct,Ua,dt,Ga,be,Or,Bs,Ir,Pr,Vs,Nr,Fr,Ya,ut,Ba,Ot,Hr,Va,Ae,Le,Js,pt,Rr,Qs,Lr,Ja,Y,Mr,It,Wr,zr,Xs,Ur,Gr,Ks,Yr,Br,mt,Vr,Jr,Zs,Qr,Xr,ht,Kr,Zr,ea,el,tl,Qa,ue,pe,Pt,we,sl,ta,al,ol,sa,nl,rl,Xa,ft,Ka,Nt,ll,Za,me,he,Ft,Ht,il,eo,Se,Me,aa,_t,cl,oa,dl,to,$e,ul,na,pl,ml,gt,hl,fl,so,ve,_l,ra,gl,bl,la,wl,$l,ao,bt,oo,We,vl,ia,yl,kl,no,fe,_e,Rt,Lt,xl,ro,wt,lo,ye,El,ca,jl,ql,da,Tl,Dl,io,$t,co,Mt,Cl,uo,vt,po,yt,mo,Wt,Al,ho,ze,fo;h=new Ac({props:{fw:W[0]}}),_=new pa({});const Pl=[Oc,Sc],kt=[];function Nl(e,i){return e[0]==="pt"?0:1}S=Nl(W),N=kt[S]=Pl[S](W),T=new Cc({props:{id:"OATCgQtNX2o"}}),V=new pa({}),Je=new pa({}),Qe=new O({props:{code:`from datasets import load_dataset

issues_dataset = load_dataset("lewtun/github-issues", split="train")
issues_dataset`,highlighted:`<span class="hljs-keyword">from</span> datasets <span class="hljs-keyword">import</span> load_dataset

issues_dataset = load_dataset(<span class="hljs-string">&quot;lewtun/github-issues&quot;</span>, split=<span class="hljs-string">&quot;train&quot;</span>)
issues_dataset`}}),Xe=new O({props:{code:`Dataset({
    features: ['url', 'repository_url', 'labels_url', 'comments_url', 'events_url', 'html_url', 'id', 'node_id', 'number', 'title', 'user', 'labels', 'state', 'locked', 'assignee', 'assignees', 'milestone', 'comments', 'created_at', 'updated_at', 'closed_at', 'author_association', 'active_lock_reason', 'pull_request', 'body', 'performed_via_github_app', 'is_pull_request'],
    num_rows: 2855
})`,highlighted:`Dataset({
    features: [<span class="hljs-string">&#x27;url&#x27;</span>, <span class="hljs-string">&#x27;repository_url&#x27;</span>, <span class="hljs-string">&#x27;labels_url&#x27;</span>, <span class="hljs-string">&#x27;comments_url&#x27;</span>, <span class="hljs-string">&#x27;events_url&#x27;</span>, <span class="hljs-string">&#x27;html_url&#x27;</span>, <span class="hljs-string">&#x27;id&#x27;</span>, <span class="hljs-string">&#x27;node_id&#x27;</span>, <span class="hljs-string">&#x27;number&#x27;</span>, <span class="hljs-string">&#x27;title&#x27;</span>, <span class="hljs-string">&#x27;user&#x27;</span>, <span class="hljs-string">&#x27;labels&#x27;</span>, <span class="hljs-string">&#x27;state&#x27;</span>, <span class="hljs-string">&#x27;locked&#x27;</span>, <span class="hljs-string">&#x27;assignee&#x27;</span>, <span class="hljs-string">&#x27;assignees&#x27;</span>, <span class="hljs-string">&#x27;milestone&#x27;</span>, <span class="hljs-string">&#x27;comments&#x27;</span>, <span class="hljs-string">&#x27;created_at&#x27;</span>, <span class="hljs-string">&#x27;updated_at&#x27;</span>, <span class="hljs-string">&#x27;closed_at&#x27;</span>, <span class="hljs-string">&#x27;author_association&#x27;</span>, <span class="hljs-string">&#x27;active_lock_reason&#x27;</span>, <span class="hljs-string">&#x27;pull_request&#x27;</span>, <span class="hljs-string">&#x27;body&#x27;</span>, <span class="hljs-string">&#x27;performed_via_github_app&#x27;</span>, <span class="hljs-string">&#x27;is_pull_request&#x27;</span>],
    num_rows: <span class="hljs-number">2855</span>
})`}}),Ke=new O({props:{code:`issues_dataset = issues_dataset.filter(
    lambda x: (x["is_pull_request"] == False and len(x["comments"]) > 0)
)
issues_dataset`,highlighted:`issues_dataset = issues_dataset.<span class="hljs-built_in">filter</span>(
    <span class="hljs-keyword">lambda</span> x: (x[<span class="hljs-string">&quot;is_pull_request&quot;</span>] == <span class="hljs-literal">False</span> <span class="hljs-keyword">and</span> <span class="hljs-built_in">len</span>(x[<span class="hljs-string">&quot;comments&quot;</span>]) &gt; <span class="hljs-number">0</span>)
)
issues_dataset`}}),Ze=new O({props:{code:`Dataset({
    features: ['url', 'repository_url', 'labels_url', 'comments_url', 'events_url', 'html_url', 'id', 'node_id', 'number', 'title', 'user', 'labels', 'state', 'locked', 'assignee', 'assignees', 'milestone', 'comments', 'created_at', 'updated_at', 'closed_at', 'author_association', 'active_lock_reason', 'pull_request', 'body', 'performed_via_github_app', 'is_pull_request'],
    num_rows: 771
})`,highlighted:`Dataset({
    features: [<span class="hljs-string">&#x27;url&#x27;</span>, <span class="hljs-string">&#x27;repository_url&#x27;</span>, <span class="hljs-string">&#x27;labels_url&#x27;</span>, <span class="hljs-string">&#x27;comments_url&#x27;</span>, <span class="hljs-string">&#x27;events_url&#x27;</span>, <span class="hljs-string">&#x27;html_url&#x27;</span>, <span class="hljs-string">&#x27;id&#x27;</span>, <span class="hljs-string">&#x27;node_id&#x27;</span>, <span class="hljs-string">&#x27;number&#x27;</span>, <span class="hljs-string">&#x27;title&#x27;</span>, <span class="hljs-string">&#x27;user&#x27;</span>, <span class="hljs-string">&#x27;labels&#x27;</span>, <span class="hljs-string">&#x27;state&#x27;</span>, <span class="hljs-string">&#x27;locked&#x27;</span>, <span class="hljs-string">&#x27;assignee&#x27;</span>, <span class="hljs-string">&#x27;assignees&#x27;</span>, <span class="hljs-string">&#x27;milestone&#x27;</span>, <span class="hljs-string">&#x27;comments&#x27;</span>, <span class="hljs-string">&#x27;created_at&#x27;</span>, <span class="hljs-string">&#x27;updated_at&#x27;</span>, <span class="hljs-string">&#x27;closed_at&#x27;</span>, <span class="hljs-string">&#x27;author_association&#x27;</span>, <span class="hljs-string">&#x27;active_lock_reason&#x27;</span>, <span class="hljs-string">&#x27;pull_request&#x27;</span>, <span class="hljs-string">&#x27;body&#x27;</span>, <span class="hljs-string">&#x27;performed_via_github_app&#x27;</span>, <span class="hljs-string">&#x27;is_pull_request&#x27;</span>],
    num_rows: <span class="hljs-number">771</span>
})`}}),et=new O({props:{code:`columns = issues_dataset.column_names
columns_to_keep = ["title", "body", "html_url", "comments"]
columns_to_remove = set(columns_to_keep).symmetric_difference(columns)
issues_dataset = issues_dataset.remove_columns(columns_to_remove)
issues_dataset`,highlighted:`columns = issues_dataset.column_names
columns_to_keep = [<span class="hljs-string">&quot;title&quot;</span>, <span class="hljs-string">&quot;body&quot;</span>, <span class="hljs-string">&quot;html_url&quot;</span>, <span class="hljs-string">&quot;comments&quot;</span>]
columns_to_remove = <span class="hljs-built_in">set</span>(columns_to_keep).symmetric_difference(columns)
issues_dataset = issues_dataset.remove_columns(columns_to_remove)
issues_dataset`}}),tt=new O({props:{code:`Dataset({
    features: ['html_url', 'title', 'comments', 'body'],
    num_rows: 771
})`,highlighted:`Dataset({
    features: [<span class="hljs-string">&#x27;html_url&#x27;</span>, <span class="hljs-string">&#x27;title&#x27;</span>, <span class="hljs-string">&#x27;comments&#x27;</span>, <span class="hljs-string">&#x27;body&#x27;</span>],
    num_rows: <span class="hljs-number">771</span>
})`}}),st=new O({props:{code:`issues_dataset.set_format("pandas")
df = issues_dataset[:]`,highlighted:`issues_dataset.set_format(<span class="hljs-string">&quot;pandas&quot;</span>)
df = issues_dataset[:]`}}),at=new O({props:{code:'df["comments"][0].tolist()',highlighted:'df[<span class="hljs-string">&quot;comments&quot;</span>][<span class="hljs-number">0</span>].tolist()'}}),ot=new O({props:{code:`['the bug code locate in \uFF1A\\r\\n    if data_args.task_name is not None:\\r\\n        # Downloading and loading a dataset from the hub.\\r\\n        datasets = load_dataset("glue", data_args.task_name, cache_dir=model_args.cache_dir)',
 'Hi @jinec,\\r\\n\\r\\nFrom time to time we get this kind of \`ConnectionError\` coming from the github.com website: https://raw.githubusercontent.com\\r\\n\\r\\nNormally, it should work if you wait a little and then retry.\\r\\n\\r\\nCould you please confirm if the problem persists?',
 'cannot connect\uFF0Ceven by Web browser\uFF0Cplease check that  there is some  problems\u3002',
 'I can access https://raw.githubusercontent.com/huggingface/datasets/1.7.0/datasets/glue/glue.py without problem...']`,highlighted:`[<span class="hljs-string">&#x27;the bug code locate in \uFF1A\\r\\n    if data_args.task_name is not None:\\r\\n        # Downloading and loading a dataset from the hub.\\r\\n        datasets = load_dataset(&quot;glue&quot;, data_args.task_name, cache_dir=model_args.cache_dir)&#x27;</span>,
 <span class="hljs-string">&#x27;Hi @jinec,\\r\\n\\r\\nFrom time to time we get this kind of \`ConnectionError\` coming from the github.com website: https://raw.githubusercontent.com\\r\\n\\r\\nNormally, it should work if you wait a little and then retry.\\r\\n\\r\\nCould you please confirm if the problem persists?&#x27;</span>,
 <span class="hljs-string">&#x27;cannot connect\uFF0Ceven by Web browser\uFF0Cplease check that  there is some  problems\u3002&#x27;</span>,
 <span class="hljs-string">&#x27;I can access https://raw.githubusercontent.com/huggingface/datasets/1.7.0/datasets/glue/glue.py without problem...&#x27;</span>]`}}),nt=new O({props:{code:`comments_df = df.explode("comments", ignore_index=True)
comments_df.head(4)`,highlighted:`comments_df = df.explode(<span class="hljs-string">&quot;comments&quot;</span>, ignore_index=<span class="hljs-literal">True</span>)
comments_df.head(<span class="hljs-number">4</span>)`}}),rt=new O({props:{code:`from datasets import Dataset

comments_dataset = Dataset.from_pandas(comments_df)
comments_dataset`,highlighted:`<span class="hljs-keyword">from</span> datasets <span class="hljs-keyword">import</span> Dataset

comments_dataset = Dataset.from_pandas(comments_df)
comments_dataset`}}),lt=new O({props:{code:`Dataset({
    features: ['html_url', 'title', 'comments', 'body'],
    num_rows: 2842
})`,highlighted:`Dataset({
    features: [<span class="hljs-string">&#x27;html_url&#x27;</span>, <span class="hljs-string">&#x27;title&#x27;</span>, <span class="hljs-string">&#x27;comments&#x27;</span>, <span class="hljs-string">&#x27;body&#x27;</span>],
    num_rows: <span class="hljs-number">2842</span>
})`}}),He=new kc({props:{$$slots:{default:[Ic]},$$scope:{ctx:W}}}),it=new O({props:{code:`comments_dataset = comments_dataset.map(
    lambda x: {"comment_length": len(x["comments"].split())}
)`,highlighted:`comments_dataset = comments_dataset.<span class="hljs-built_in">map</span>(
    <span class="hljs-keyword">lambda</span> x: {<span class="hljs-string">&quot;comment_length&quot;</span>: <span class="hljs-built_in">len</span>(x[<span class="hljs-string">&quot;comments&quot;</span>].split())}
)`}}),ct=new O({props:{code:`comments_dataset = comments_dataset.filter(lambda x: x["comment_length"] > 15)
comments_dataset`,highlighted:`comments_dataset = comments_dataset.<span class="hljs-built_in">filter</span>(<span class="hljs-keyword">lambda</span> x: x[<span class="hljs-string">&quot;comment_length&quot;</span>] &gt; <span class="hljs-number">15</span>)
comments_dataset`}}),dt=new O({props:{code:`Dataset({
    features: ['html_url', 'title', 'comments', 'body', 'comment_length'],
    num_rows: 2098
})`,highlighted:`Dataset({
    features: [<span class="hljs-string">&#x27;html_url&#x27;</span>, <span class="hljs-string">&#x27;title&#x27;</span>, <span class="hljs-string">&#x27;comments&#x27;</span>, <span class="hljs-string">&#x27;body&#x27;</span>, <span class="hljs-string">&#x27;comment_length&#x27;</span>],
    num_rows: <span class="hljs-number">2098</span>
})`}}),ut=new O({props:{code:`def concatenate_text(examples):
    return {
        "text": examples["title"]
        + " \\n "
        + examples["body"]
        + " \\n "
        + examples["comments"]
    }


comments_dataset = comments_dataset.map(concatenate_text)`,highlighted:`<span class="hljs-keyword">def</span> <span class="hljs-title function_">concatenate_text</span>(<span class="hljs-params">examples</span>):
    <span class="hljs-keyword">return</span> {
        <span class="hljs-string">&quot;text&quot;</span>: examples[<span class="hljs-string">&quot;title&quot;</span>]
        + <span class="hljs-string">&quot; \\n &quot;</span>
        + examples[<span class="hljs-string">&quot;body&quot;</span>]
        + <span class="hljs-string">&quot; \\n &quot;</span>
        + examples[<span class="hljs-string">&quot;comments&quot;</span>]
    }


comments_dataset = comments_dataset.<span class="hljs-built_in">map</span>(concatenate_text)`}}),pt=new pa({});const Fl=[Nc,Pc],xt=[];function Hl(e,i){return e[0]==="pt"?0:1}ue=Hl(W),pe=xt[ue]=Fl[ue](W),ft=new O({props:{code:`def cls_pooling(model_output):
    return model_output.last_hidden_state[:, 0]`,highlighted:`<span class="hljs-keyword">def</span> <span class="hljs-title function_">cls_pooling</span>(<span class="hljs-params">model_output</span>):
    <span class="hljs-keyword">return</span> model_output.last_hidden_state[:, <span class="hljs-number">0</span>]`}});const Rl=[Hc,Fc],Et=[];function Ll(e,i){return e[0]==="pt"?0:1}me=Ll(W),he=Et[me]=Rl[me](W),_t=new pa({}),bt=new O({props:{code:'embeddings_dataset.add_faiss_index(column="embeddings")',highlighted:'embeddings_dataset.add_faiss_index(column=<span class="hljs-string">&quot;embeddings&quot;</span>)'}});const Ml=[Lc,Rc],jt=[];function Wl(e,i){return e[0]==="pt"?0:1}return fe=Wl(W),_e=jt[fe]=Ml[fe](W),wt=new O({props:{code:`scores, samples = embeddings_dataset.get_nearest_examples(
    "embeddings", question_embedding, k=5
)`,highlighted:`scores, samples = embeddings_dataset.get_nearest_examples(
    <span class="hljs-string">&quot;embeddings&quot;</span>, question_embedding, k=<span class="hljs-number">5</span>
)`}}),$t=new O({props:{code:`import pandas as pd

samples_df = pd.DataFrame.from_dict(samples)
samples_df["scores"] = scores
samples_df.sort_values("scores", ascending=False, inplace=True)`,highlighted:`<span class="hljs-keyword">import</span> pandas <span class="hljs-keyword">as</span> pd

samples_df = pd.DataFrame.from_dict(samples)
samples_df[<span class="hljs-string">&quot;scores&quot;</span>] = scores
samples_df.sort_values(<span class="hljs-string">&quot;scores&quot;</span>, ascending=<span class="hljs-literal">False</span>, inplace=<span class="hljs-literal">True</span>)`}}),vt=new O({props:{code:`for _, row in samples_df.iterrows():
    print(f"COMMENT: {row.comments}")
    print(f"SCORE: {row.scores}")
    print(f"TITLE: {row.title}")
    print(f"URL: {row.html_url}")
    print("=" * 50)
    print()`,highlighted:`<span class="hljs-keyword">for</span> _, row <span class="hljs-keyword">in</span> samples_df.iterrows():
    <span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;COMMENT: <span class="hljs-subst">{row.comments}</span>&quot;</span>)
    <span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;SCORE: <span class="hljs-subst">{row.scores}</span>&quot;</span>)
    <span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;TITLE: <span class="hljs-subst">{row.title}</span>&quot;</span>)
    <span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;URL: <span class="hljs-subst">{row.html_url}</span>&quot;</span>)
    <span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;=&quot;</span> * <span class="hljs-number">50</span>)
    <span class="hljs-built_in">print</span>()`}}),yt=new O({props:{code:`"""
COMMENT: Requiring online connection is a deal breaker in some cases unfortunately so it'd be great if offline mode is added similar to how \`transformers\` loads models offline fine.

@mandubian's second bullet point suggests that there's a workaround allowing you to use your offline (custom?) dataset with \`datasets\`. Could you please elaborate on how that should look like?
SCORE: 25.505046844482422
TITLE: Discussion using datasets in offline mode
URL: https://github.com/huggingface/datasets/issues/824
==================================================

COMMENT: The local dataset builders (csv, text , json and pandas) are now part of the \`datasets\` package since #1726 :)
You can now use them offline
\\\`\\\`\\\`python
datasets = load_dataset("text", data_files=data_files)
\\\`\\\`\\\`

We'll do a new release soon
SCORE: 24.555509567260742
TITLE: Discussion using datasets in offline mode
URL: https://github.com/huggingface/datasets/issues/824
==================================================

COMMENT: I opened a PR that allows to reload modules that have already been loaded once even if there's no internet.

Let me know if you know other ways that can make the offline mode experience better. I'd be happy to add them :)

I already note the "freeze" modules option, to prevent local modules updates. It would be a cool feature.

----------

> @mandubian's second bullet point suggests that there's a workaround allowing you to use your offline (custom?) dataset with \`datasets\`. Could you please elaborate on how that should look like?

Indeed \`load_dataset\` allows to load remote dataset script (squad, glue, etc.) but also you own local ones.
For example if you have a dataset script at \`./my_dataset/my_dataset.py\` then you can do
\\\`\\\`\\\`python
load_dataset("./my_dataset")
\\\`\\\`\\\`
and the dataset script will generate your dataset once and for all.

----------

About I'm looking into having \`csv\`, \`json\`, \`text\`, \`pandas\` dataset builders already included in the \`datasets\` package, so that they are available offline by default, as opposed to the other datasets that require the script to be downloaded.
cf #1724
SCORE: 24.14896583557129
TITLE: Discussion using datasets in offline mode
URL: https://github.com/huggingface/datasets/issues/824
==================================================

COMMENT: > here is my way to load a dataset offline, but it **requires** an online machine
>
> 1. (online machine)
>
> \`\`\`
>
> import datasets
>
> data = datasets.load_dataset(...)
>
> data.save_to_disk(/YOUR/DATASET/DIR)
>
> \`\`\`
>
> 2. copy the dir from online to the offline machine
>
> 3. (offline machine)
>
> \`\`\`
>
> import datasets
>
> data = datasets.load_from_disk(/SAVED/DATA/DIR)
>
> \`\`\`
>
>
>
> HTH.


SCORE: 22.893993377685547
TITLE: Discussion using datasets in offline mode
URL: https://github.com/huggingface/datasets/issues/824
==================================================

COMMENT: here is my way to load a dataset offline, but it **requires** an online machine
1. (online machine)
\\\`\\\`\\\`
import datasets
data = datasets.load_dataset(...)
data.save_to_disk(/YOUR/DATASET/DIR)
\\\`\\\`\\\`
2. copy the dir from online to the offline machine
3. (offline machine)
\\\`\\\`\\\`
import datasets
data = datasets.load_from_disk(/SAVED/DATA/DIR)
\\\`\\\`\\\`

HTH.
SCORE: 22.406635284423828
TITLE: Discussion using datasets in offline mode
URL: https://github.com/huggingface/datasets/issues/824
==================================================
"""`,highlighted:`<span class="hljs-string">&quot;&quot;&quot;
COMMENT: Requiring online connection is a deal breaker in some cases unfortunately so it&#x27;d be great if offline mode is added similar to how \`transformers\` loads models offline fine.

@mandubian&#x27;s second bullet point suggests that there&#x27;s a workaround allowing you to use your offline (custom?) dataset with \`datasets\`. Could you please elaborate on how that should look like?
SCORE: 25.505046844482422
TITLE: Discussion using datasets in offline mode
URL: https://github.com/huggingface/datasets/issues/824
==================================================

COMMENT: The local dataset builders (csv, text , json and pandas) are now part of the \`datasets\` package since #1726 :)
You can now use them offline
\\\`\\\`\\\`python
datasets = load_dataset(&quot;text&quot;, data_files=data_files)
\\\`\\\`\\\`

We&#x27;ll do a new release soon
SCORE: 24.555509567260742
TITLE: Discussion using datasets in offline mode
URL: https://github.com/huggingface/datasets/issues/824
==================================================

COMMENT: I opened a PR that allows to reload modules that have already been loaded once even if there&#x27;s no internet.

Let me know if you know other ways that can make the offline mode experience better. I&#x27;d be happy to add them :)

I already note the &quot;freeze&quot; modules option, to prevent local modules updates. It would be a cool feature.

----------

&gt; @mandubian&#x27;s second bullet point suggests that there&#x27;s a workaround allowing you to use your offline (custom?) dataset with \`datasets\`. Could you please elaborate on how that should look like?

Indeed \`load_dataset\` allows to load remote dataset script (squad, glue, etc.) but also you own local ones.
For example if you have a dataset script at \`./my_dataset/my_dataset.py\` then you can do
\\\`\\\`\\\`python
load_dataset(&quot;./my_dataset&quot;)
\\\`\\\`\\\`
and the dataset script will generate your dataset once and for all.

----------

About I&#x27;m looking into having \`csv\`, \`json\`, \`text\`, \`pandas\` dataset builders already included in the \`datasets\` package, so that they are available offline by default, as opposed to the other datasets that require the script to be downloaded.
cf #1724
SCORE: 24.14896583557129
TITLE: Discussion using datasets in offline mode
URL: https://github.com/huggingface/datasets/issues/824
==================================================

COMMENT: &gt; here is my way to load a dataset offline, but it **requires** an online machine
&gt;
&gt; 1. (online machine)
&gt;
&gt; \`\`\`
&gt;
&gt; import datasets
&gt;
&gt; data = datasets.load_dataset(...)
&gt;
&gt; data.save_to_disk(/YOUR/DATASET/DIR)
&gt;
&gt; \`\`\`
&gt;
&gt; 2. copy the dir from online to the offline machine
&gt;
&gt; 3. (offline machine)
&gt;
&gt; \`\`\`
&gt;
&gt; import datasets
&gt;
&gt; data = datasets.load_from_disk(/SAVED/DATA/DIR)
&gt;
&gt; \`\`\`
&gt;
&gt;
&gt;
&gt; HTH.


SCORE: 22.893993377685547
TITLE: Discussion using datasets in offline mode
URL: https://github.com/huggingface/datasets/issues/824
==================================================

COMMENT: here is my way to load a dataset offline, but it **requires** an online machine
1. (online machine)
\\\`\\\`\\\`
import datasets
data = datasets.load_dataset(...)
data.save_to_disk(/YOUR/DATASET/DIR)
\\\`\\\`\\\`
2. copy the dir from online to the offline machine
3. (offline machine)
\\\`\\\`\\\`
import datasets
data = datasets.load_from_disk(/SAVED/DATA/DIR)
\\\`\\\`\\\`

HTH.
SCORE: 22.406635284423828
TITLE: Discussion using datasets in offline mode
URL: https://github.com/huggingface/datasets/issues/824
==================================================
&quot;&quot;&quot;</span>`}}),ze=new kc({props:{$$slots:{default:[Mc]},$$scope:{ctx:W}}}),{c(){p=n("meta"),$=d(),v(h.$$.fragment),E=d(),f=n("h1"),g=n("a"),I=n("span"),v(_.$$.fragment),A=d(),q=n("span"),M=a("Semantic search with FAISS"),P=d(),N.c(),F=d(),R=n("p"),U=a("In "),D=n("a"),H=a("section 5"),B=a(", we created a dataset of GitHub issues and comments from the \u{1F917} Datasets repository. In this section we\u2019ll use this information to build a search engine that can help us find answers to our most pressing questions about the library!"),z=d(),v(T.$$.fragment),G=d(),m=n("h2"),C=n("a"),L=n("span"),v(V.$$.fragment),ne=d(),ce=n("span"),Do=a("Using embeddings for semantic search"),ma=d(),ge=n("p"),Co=a("As we saw in "),Dt=n("a"),Ao=a("Chapter 1"),So=a(", Transformer-based language models represent each token in a span of text as an "),Kt=n("em"),Oo=a("embedding vector"),Io=a(". It turns out that one can \u201Cpool\u201D the individual embeddings to create a vector representation for whole sentences, paragraphs, or (in some cases) documents. These embeddings can then be used to find similar documents in the corpus by computing the dot-product similarity (or some other similarity metric) between each embedding and returning the documents with the greatest overlap."),ha=d(),Ct=n("p"),Po=a("In this section we\u2019ll use embeddings to develop a semantic search engine. These search engines offer several advantages over conventional approaches that are based on matching keywords in a query with the documents."),fa=d(),De=n("div"),Be=n("img"),No=d(),Ve=n("img"),_a=d(),Ce=n("h2"),Oe=n("a"),Zt=n("span"),v(Je.$$.fragment),Fo=d(),es=n("span"),Ho=a("Loading and preparing the dataset"),ga=d(),Ie=n("p"),Ro=a("The first thing we need to do is download our dataset of GitHub issues, so let\u2019s use "),ts=n("code"),Lo=a("load_dataset()"),Mo=a(" function as usual:"),ba=d(),v(Qe.$$.fragment),wa=d(),v(Xe.$$.fragment),$a=d(),J=n("p"),Wo=a("Here we\u2019ve specified the default "),ss=n("code"),zo=a("train"),Uo=a(" split in "),as=n("code"),Go=a("load_dataset()"),Yo=a(", so it returns a "),os=n("code"),Bo=a("Dataset"),Vo=a(" instead of a "),ns=n("code"),Jo=a("DatasetDict"),Qo=a(". The first order of business is to filter out the pull requests, as these tend to be rarely used for answering user queries and will introduce noise in our search engine. As should be familiar by now, we can use the "),rs=n("code"),Xo=a("Dataset.filter()"),Ko=a(" function to exclude these rows in our dataset. While we\u2019re at it, let\u2019s also filter out rows with no comments, since these provide no answers to user queries:"),va=d(),v(Ke.$$.fragment),ya=d(),v(Ze.$$.fragment),ka=d(),Q=n("p"),Zo=a("We can see that there are a lot of columns in our dataset, most of which we don\u2019t need to build our search engine. From a search perspective, the most informative columns are "),ls=n("code"),en=a("title"),tn=a(", "),is=n("code"),sn=a("body"),an=a(", and "),cs=n("code"),on=a("comments"),nn=a(", while "),ds=n("code"),rn=a("html_url"),ln=a(" provides us with a link back to the source issue. Let\u2019s use the "),us=n("code"),cn=a("Dataset.remove_columns()"),dn=a(" function to drop the rest:"),xa=d(),v(et.$$.fragment),Ea=d(),v(tt.$$.fragment),ja=d(),K=n("p"),un=a("To create our embeddings we\u2019ll augment each comment with the issue\u2019s title and body, since these fields often include useful contextual information. Because our "),ps=n("code"),pn=a("comments"),mn=a(" column is currently a list of comments for each issue, we need to \u201Cexplode\u201D the column so that each row consists of an "),ms=n("code"),hn=a("(html_url, title, body, comment)"),fn=a(" tuple. In Pandas we can do this with the "),Pe=n("a"),hs=n("code"),_n=a("DataFrame.explode()"),gn=a(" function"),bn=a(", which creates a new row for each element in a list-like column, while replicating all the other column values. To see this in action, let\u2019s first switch to the Pandas  "),fs=n("code"),wn=a("DataFrame"),$n=a(" format:"),qa=d(),v(st.$$.fragment),Ta=d(),Ne=n("p"),vn=a("If we inspect the first row in this "),_s=n("code"),yn=a("DataFrame"),kn=a(" we can see there are four comments associated with this issue:"),Da=d(),v(at.$$.fragment),Ca=d(),v(ot.$$.fragment),Aa=d(),Fe=n("p"),xn=a("When we explode "),gs=n("code"),En=a("df"),jn=a(", we expect to get one row for each of these comments. Let\u2019s check if that\u2019s the case:"),Sa=d(),v(nt.$$.fragment),Oa=d(),ee=n("table"),bs=n("thead"),Z=n("tr"),Ia=n("th"),qn=d(),ws=n("th"),Tn=a("html_url"),Dn=d(),$s=n("th"),Cn=a("title"),An=d(),vs=n("th"),Sn=a("comments"),On=d(),ys=n("th"),In=a("body"),Pn=d(),de=n("tbody"),te=n("tr"),ks=n("th"),Nn=a("0"),Fn=d(),xs=n("td"),Hn=a("https://github.com/huggingface/datasets/issues/2787"),Rn=d(),Es=n("td"),Ln=a("ConnectionError: Couldn't reach https://raw.githubusercontent.com"),Mn=d(),js=n("td"),Wn=a("the bug code locate in \uFF1A\\r\\n    if data_args.task_name is not None..."),zn=d(),qs=n("td"),Un=a("Hello,\\r\\nI am trying to run run_glue.py and it gives me this error..."),Gn=d(),se=n("tr"),Ts=n("th"),Yn=a("1"),Bn=d(),Ds=n("td"),Vn=a("https://github.com/huggingface/datasets/issues/2787"),Jn=d(),Cs=n("td"),Qn=a("ConnectionError: Couldn't reach https://raw.githubusercontent.com"),Xn=d(),As=n("td"),Kn=a("Hi @jinec,\\r\\n\\r\\nFrom time to time we get this kind of `ConnectionError` coming from the github.com website: https://raw.githubusercontent.com..."),Zn=d(),Ss=n("td"),er=a("Hello,\\r\\nI am trying to run run_glue.py and it gives me this error..."),tr=d(),ae=n("tr"),Os=n("th"),sr=a("2"),ar=d(),Is=n("td"),or=a("https://github.com/huggingface/datasets/issues/2787"),nr=d(),Ps=n("td"),rr=a("ConnectionError: Couldn't reach https://raw.githubusercontent.com"),lr=d(),Ns=n("td"),ir=a("cannot connect\uFF0Ceven by Web browser\uFF0Cplease check that  there is some  problems\u3002"),cr=d(),Fs=n("td"),dr=a("Hello,\\r\\nI am trying to run run_glue.py and it gives me this error..."),ur=d(),oe=n("tr"),Hs=n("th"),pr=a("3"),mr=d(),Rs=n("td"),hr=a("https://github.com/huggingface/datasets/issues/2787"),fr=d(),Ls=n("td"),_r=a("ConnectionError: Couldn't reach https://raw.githubusercontent.com"),gr=d(),Ms=n("td"),br=a("I can access https://raw.githubusercontent.com/huggingface/datasets/1.7.0/datasets/glue/glue.py without problem..."),wr=d(),Ws=n("td"),$r=a("Hello,\\r\\nI am trying to run run_glue.py and it gives me this error..."),Pa=d(),re=n("p"),vr=a("Great, we can see the rows have been replicated, with the "),zs=n("code"),yr=a("comments"),kr=a(" column containing the individual comments! Now that we\u2019re finished with Pandas, we can quickly switch back to a "),Us=n("code"),xr=a("Dataset"),Er=a(" by loading the "),Gs=n("code"),jr=a("DataFrame"),qr=a(" in memory:"),Na=d(),v(rt.$$.fragment),Fa=d(),v(lt.$$.fragment),Ha=d(),At=n("p"),Tr=a("Okay, this has given us a few thousand comments to work with!"),Ra=d(),v(He.$$.fragment),La=d(),Re=n("p"),Dr=a("Now that we have one comment per row, let\u2019s create a new "),Ys=n("code"),Cr=a("comments_length"),Ar=a(" column that contains the number of words per comment:"),Ma=d(),v(it.$$.fragment),Wa=d(),St=n("p"),Sr=a("We can use this new column to filter out short comments, which typically include things like \u201Ccc @lewtun\u201D or \u201CThanks!\u201D that are not relevant for our search engine. There\u2019s no precise number to select for the filter, but around 15 words seems like a good start:"),za=d(),v(ct.$$.fragment),Ua=d(),v(dt.$$.fragment),Ga=d(),be=n("p"),Or=a("Having cleaned up our dataset a bit, let\u2019s concatenate the issue title, description, and comments together in a new "),Bs=n("code"),Ir=a("text"),Pr=a(" column. As usual, we\u2019ll write a simple function that we can pass to "),Vs=n("code"),Nr=a("Dataset.map()"),Fr=a(":"),Ya=d(),v(ut.$$.fragment),Ba=d(),Ot=n("p"),Hr=a("We\u2019re finally ready to create some embeddings! Let\u2019s take a look."),Va=d(),Ae=n("h2"),Le=n("a"),Js=n("span"),v(pt.$$.fragment),Rr=d(),Qs=n("span"),Lr=a("Creating text embeddings"),Ja=d(),Y=n("p"),Mr=a("We saw in "),It=n("a"),Wr=a("Chapter 2"),zr=a(" that we can obtain token embeddings by using the "),Xs=n("code"),Ur=a("AutoModel"),Gr=a(" class. All we need to do is pick a suitable checkpoint to load the model from. Fortunately, there\u2019s a library called "),Ks=n("code"),Yr=a("sentence-transformers"),Br=a(" that is dedicated to creating embeddings. As described in the library\u2019s "),mt=n("a"),Vr=a("documentation"),Jr=a(", our use case is an example of "),Zs=n("em"),Qr=a("asymmetric semantic search"),Xr=a(" because we have a short query whose answer we\u2019d like to find in a longer document, like a an issue comment. The handy "),ht=n("a"),Kr=a("model overview table"),Zr=a(" in the documentation indicates that the "),ea=n("code"),el=a("multi-qa-mpnet-base-dot-v1"),tl=a(" checkpoint has the best performance for semantic search, so we\u2019ll use that for our application. We\u2019ll also load the tokenizer using the same checkpoint:"),Qa=d(),pe.c(),Pt=d(),we=n("p"),sl=a("As we mentioned earlier, we\u2019d like to represent each entry in our GitHub issues corpus as a single vector, so we need to \u201Cpool\u201D or average our token embeddings in some way. One popular approach is to perform "),ta=n("em"),al=a("CLS pooling"),ol=a(" on our model\u2019s outputs, where we simply collect the last hidden state for the special "),sa=n("code"),nl=a("[CLS]"),rl=a(" token. The following function does the trick for us:"),Xa=d(),v(ft.$$.fragment),Ka=d(),Nt=n("p"),ll=a("Next, we\u2019ll create a helper function that will tokenize a list of documents, place the tensors on the GPU, feed them to the model, and finally apply CLS pooling to the outputs:"),Za=d(),he.c(),Ft=d(),Ht=n("p"),il=a("Notice that we\u2019ve converted the embeddings to NumPy arrays \u2014 that\u2019s because \u{1F917} Datasets requires this format when we try to index them with FAISS, which we\u2019ll do next."),eo=d(),Se=n("h2"),Me=n("a"),aa=n("span"),v(_t.$$.fragment),cl=d(),oa=n("span"),dl=a("Using FAISS for efficient similarity search"),to=d(),$e=n("p"),ul=a("Now that we have a dataset of embeddings, we need some way to search over them. To do this, we\u2019ll use a special data structure in \u{1F917} Datasets called a "),na=n("em"),pl=a("FAISS index"),ml=a(". "),gt=n("a"),hl=a("FAISS"),fl=a(" (short for Facebook AI Similarity Search) is a library that provides efficient algorithms to quickly search and cluster embedding vectors."),so=d(),ve=n("p"),_l=a("The basic idea behind FAISS is to create a special data structure called an "),ra=n("em"),gl=a("index"),bl=a(" that allows one to find which embeddings are similar to an input embedding. Creating a FAISS index in \u{1F917} Datasets is simple \u2014 we use the "),la=n("code"),wl=a("Dataset.add_faiss_index()"),$l=a(" function and specify which column of our dataset we\u2019d like to index:"),ao=d(),v(bt.$$.fragment),oo=d(),We=n("p"),vl=a("We can now perform queries on this index by doing a nearest neighbor lookup with the "),ia=n("code"),yl=a("Dataset.get_nearest_examples()"),kl=a(" function. Let\u2019s test this out by first embedding a question as follows:"),no=d(),_e.c(),Rt=d(),Lt=n("p"),xl=a("Just like with the documents, we now have a 768-dimensional vector representing the query, which we can compare against the whole corpus to find the most similar embeddings:"),ro=d(),v(wt.$$.fragment),lo=d(),ye=n("p"),El=a("The "),ca=n("code"),jl=a("Dataset.get_nearest_examples()"),ql=a(" function returns a tuple of scores that rank the overlap between the query and the document, and a corresponding set of samples (here, the 5 best matches). Let\u2019s collect these in a "),da=n("code"),Tl=a("pandas.DataFrame"),Dl=a(" so we can easily sort them:"),io=d(),v($t.$$.fragment),co=d(),Mt=n("p"),Cl=a("Now we can iterate over the first few rows to see how well our query matched the available comments:"),uo=d(),v(vt.$$.fragment),po=d(),v(yt.$$.fragment),mo=d(),Wt=n("p"),Al=a("Not bad! Our second hit seems to match the query."),ho=d(),v(ze.$$.fragment),this.h()},l(e){const i=Tc('[data-svelte="svelte-1phssyn"]',document.head);p=r(i,"META",{name:!0,content:!0}),i.forEach(s),$=u(e),y(h.$$.fragment,e),E=u(e),f=r(e,"H1",{class:!0});var qt=l(f);g=r(qt,"A",{id:!0,class:!0,href:!0});var zt=l(g);I=r(zt,"SPAN",{});var ua=l(I);y(_.$$.fragment,ua),ua.forEach(s),zt.forEach(s),A=u(qt),q=r(qt,"SPAN",{});var Ut=l(q);M=o(Ut,"Semantic search with FAISS"),Ut.forEach(s),qt.forEach(s),P=u(e),N.l(e),F=u(e),R=r(e,"P",{});var Ue=l(R);U=o(Ue,"In "),D=r(Ue,"A",{href:!0});var Gt=l(D);H=o(Gt,"section 5"),Gt.forEach(s),B=o(Ue,", we created a dataset of GitHub issues and comments from the \u{1F917} Datasets repository. In this section we\u2019ll use this information to build a search engine that can help us find answers to our most pressing questions about the library!"),Ue.forEach(s),z=u(e),y(T.$$.fragment,e),G=u(e),m=r(e,"H2",{class:!0});var Tt=l(m);C=r(Tt,"A",{id:!0,class:!0,href:!0});var zl=l(C);L=r(zl,"SPAN",{});var Ul=l(L);y(V.$$.fragment,Ul),Ul.forEach(s),zl.forEach(s),ne=u(Tt),ce=r(Tt,"SPAN",{});var Gl=l(ce);Do=o(Gl,"Using embeddings for semantic search"),Gl.forEach(s),Tt.forEach(s),ma=u(e),ge=r(e,"P",{});var Yt=l(ge);Co=o(Yt,"As we saw in "),Dt=r(Yt,"A",{href:!0});var Yl=l(Dt);Ao=o(Yl,"Chapter 1"),Yl.forEach(s),So=o(Yt,", Transformer-based language models represent each token in a span of text as an "),Kt=r(Yt,"EM",{});var Bl=l(Kt);Oo=o(Bl,"embedding vector"),Bl.forEach(s),Io=o(Yt,". It turns out that one can \u201Cpool\u201D the individual embeddings to create a vector representation for whole sentences, paragraphs, or (in some cases) documents. These embeddings can then be used to find similar documents in the corpus by computing the dot-product similarity (or some other similarity metric) between each embedding and returning the documents with the greatest overlap."),Yt.forEach(s),ha=u(e),Ct=r(e,"P",{});var Vl=l(Ct);Po=o(Vl,"In this section we\u2019ll use embeddings to develop a semantic search engine. These search engines offer several advantages over conventional approaches that are based on matching keywords in a query with the documents."),Vl.forEach(s),fa=u(e),De=r(e,"DIV",{class:!0});var _o=l(De);Be=r(_o,"IMG",{class:!0,src:!0,alt:!0}),No=u(_o),Ve=r(_o,"IMG",{class:!0,src:!0,alt:!0}),_o.forEach(s),_a=u(e),Ce=r(e,"H2",{class:!0});var go=l(Ce);Oe=r(go,"A",{id:!0,class:!0,href:!0});var Jl=l(Oe);Zt=r(Jl,"SPAN",{});var Ql=l(Zt);y(Je.$$.fragment,Ql),Ql.forEach(s),Jl.forEach(s),Fo=u(go),es=r(go,"SPAN",{});var Xl=l(es);Ho=o(Xl,"Loading and preparing the dataset"),Xl.forEach(s),go.forEach(s),ga=u(e),Ie=r(e,"P",{});var bo=l(Ie);Ro=o(bo,"The first thing we need to do is download our dataset of GitHub issues, so let\u2019s use "),ts=r(bo,"CODE",{});var Kl=l(ts);Lo=o(Kl,"load_dataset()"),Kl.forEach(s),Mo=o(bo," function as usual:"),bo.forEach(s),ba=u(e),y(Qe.$$.fragment,e),wa=u(e),y(Xe.$$.fragment,e),$a=u(e),J=r(e,"P",{});var le=l(J);Wo=o(le,"Here we\u2019ve specified the default "),ss=r(le,"CODE",{});var Zl=l(ss);zo=o(Zl,"train"),Zl.forEach(s),Uo=o(le," split in "),as=r(le,"CODE",{});var ei=l(as);Go=o(ei,"load_dataset()"),ei.forEach(s),Yo=o(le,", so it returns a "),os=r(le,"CODE",{});var ti=l(os);Bo=o(ti,"Dataset"),ti.forEach(s),Vo=o(le," instead of a "),ns=r(le,"CODE",{});var si=l(ns);Jo=o(si,"DatasetDict"),si.forEach(s),Qo=o(le,". The first order of business is to filter out the pull requests, as these tend to be rarely used for answering user queries and will introduce noise in our search engine. As should be familiar by now, we can use the "),rs=r(le,"CODE",{});var ai=l(rs);Xo=o(ai,"Dataset.filter()"),ai.forEach(s),Ko=o(le," function to exclude these rows in our dataset. While we\u2019re at it, let\u2019s also filter out rows with no comments, since these provide no answers to user queries:"),le.forEach(s),va=u(e),y(Ke.$$.fragment,e),ya=u(e),y(Ze.$$.fragment,e),ka=u(e),Q=r(e,"P",{});var ie=l(Q);Zo=o(ie,"We can see that there are a lot of columns in our dataset, most of which we don\u2019t need to build our search engine. From a search perspective, the most informative columns are "),ls=r(ie,"CODE",{});var oi=l(ls);en=o(oi,"title"),oi.forEach(s),tn=o(ie,", "),is=r(ie,"CODE",{});var ni=l(is);sn=o(ni,"body"),ni.forEach(s),an=o(ie,", and "),cs=r(ie,"CODE",{});var ri=l(cs);on=o(ri,"comments"),ri.forEach(s),nn=o(ie,", while "),ds=r(ie,"CODE",{});var li=l(ds);rn=o(li,"html_url"),li.forEach(s),ln=o(ie," provides us with a link back to the source issue. Let\u2019s use the "),us=r(ie,"CODE",{});var ii=l(us);cn=o(ii,"Dataset.remove_columns()"),ii.forEach(s),dn=o(ie," function to drop the rest:"),ie.forEach(s),xa=u(e),y(et.$$.fragment,e),Ea=u(e),y(tt.$$.fragment,e),ja=u(e),K=r(e,"P",{});var ke=l(K);un=o(ke,"To create our embeddings we\u2019ll augment each comment with the issue\u2019s title and body, since these fields often include useful contextual information. Because our "),ps=r(ke,"CODE",{});var ci=l(ps);pn=o(ci,"comments"),ci.forEach(s),mn=o(ke," column is currently a list of comments for each issue, we need to \u201Cexplode\u201D the column so that each row consists of an "),ms=r(ke,"CODE",{});var di=l(ms);hn=o(di,"(html_url, title, body, comment)"),di.forEach(s),fn=o(ke," tuple. In Pandas we can do this with the "),Pe=r(ke,"A",{href:!0,rel:!0});var Sl=l(Pe);hs=r(Sl,"CODE",{});var ui=l(hs);_n=o(ui,"DataFrame.explode()"),ui.forEach(s),gn=o(Sl," function"),Sl.forEach(s),bn=o(ke,", which creates a new row for each element in a list-like column, while replicating all the other column values. To see this in action, let\u2019s first switch to the Pandas  "),fs=r(ke,"CODE",{});var pi=l(fs);wn=o(pi,"DataFrame"),pi.forEach(s),$n=o(ke," format:"),ke.forEach(s),qa=u(e),y(st.$$.fragment,e),Ta=u(e),Ne=r(e,"P",{});var wo=l(Ne);vn=o(wo,"If we inspect the first row in this "),_s=r(wo,"CODE",{});var mi=l(_s);yn=o(mi,"DataFrame"),mi.forEach(s),kn=o(wo," we can see there are four comments associated with this issue:"),wo.forEach(s),Da=u(e),y(at.$$.fragment,e),Ca=u(e),y(ot.$$.fragment,e),Aa=u(e),Fe=r(e,"P",{});var $o=l(Fe);xn=o($o,"When we explode "),gs=r($o,"CODE",{});var hi=l(gs);En=o(hi,"df"),hi.forEach(s),jn=o($o,", we expect to get one row for each of these comments. Let\u2019s check if that\u2019s the case:"),$o.forEach(s),Sa=u(e),y(nt.$$.fragment,e),Oa=u(e),ee=r(e,"TABLE",{border:!0,class:!0,style:!0});var vo=l(ee);bs=r(vo,"THEAD",{});var fi=l(bs);Z=r(fi,"TR",{style:!0});var xe=l(Z);Ia=r(xe,"TH",{}),l(Ia).forEach(s),qn=u(xe),ws=r(xe,"TH",{});var _i=l(ws);Tn=o(_i,"html_url"),_i.forEach(s),Dn=u(xe),$s=r(xe,"TH",{});var gi=l($s);Cn=o(gi,"title"),gi.forEach(s),An=u(xe),vs=r(xe,"TH",{});var bi=l(vs);Sn=o(bi,"comments"),bi.forEach(s),On=u(xe),ys=r(xe,"TH",{});var wi=l(ys);In=o(wi,"body"),wi.forEach(s),xe.forEach(s),fi.forEach(s),Pn=u(vo),de=r(vo,"TBODY",{});var Ge=l(de);te=r(Ge,"TR",{});var Ee=l(te);ks=r(Ee,"TH",{});var $i=l(ks);Nn=o($i,"0"),$i.forEach(s),Fn=u(Ee),xs=r(Ee,"TD",{});var vi=l(xs);Hn=o(vi,"https://github.com/huggingface/datasets/issues/2787"),vi.forEach(s),Rn=u(Ee),Es=r(Ee,"TD",{});var yi=l(Es);Ln=o(yi,"ConnectionError: Couldn't reach https://raw.githubusercontent.com"),yi.forEach(s),Mn=u(Ee),js=r(Ee,"TD",{});var ki=l(js);Wn=o(ki,"the bug code locate in \uFF1A\\r\\n    if data_args.task_name is not None..."),ki.forEach(s),zn=u(Ee),qs=r(Ee,"TD",{});var xi=l(qs);Un=o(xi,"Hello,\\r\\nI am trying to run run_glue.py and it gives me this error..."),xi.forEach(s),Ee.forEach(s),Gn=u(Ge),se=r(Ge,"TR",{});var je=l(se);Ts=r(je,"TH",{});var Ei=l(Ts);Yn=o(Ei,"1"),Ei.forEach(s),Bn=u(je),Ds=r(je,"TD",{});var ji=l(Ds);Vn=o(ji,"https://github.com/huggingface/datasets/issues/2787"),ji.forEach(s),Jn=u(je),Cs=r(je,"TD",{});var qi=l(Cs);Qn=o(qi,"ConnectionError: Couldn't reach https://raw.githubusercontent.com"),qi.forEach(s),Xn=u(je),As=r(je,"TD",{});var Ti=l(As);Kn=o(Ti,"Hi @jinec,\\r\\n\\r\\nFrom time to time we get this kind of `ConnectionError` coming from the github.com website: https://raw.githubusercontent.com..."),Ti.forEach(s),Zn=u(je),Ss=r(je,"TD",{});var Di=l(Ss);er=o(Di,"Hello,\\r\\nI am trying to run run_glue.py and it gives me this error..."),Di.forEach(s),je.forEach(s),tr=u(Ge),ae=r(Ge,"TR",{});var qe=l(ae);Os=r(qe,"TH",{});var Ci=l(Os);sr=o(Ci,"2"),Ci.forEach(s),ar=u(qe),Is=r(qe,"TD",{});var Ai=l(Is);or=o(Ai,"https://github.com/huggingface/datasets/issues/2787"),Ai.forEach(s),nr=u(qe),Ps=r(qe,"TD",{});var Si=l(Ps);rr=o(Si,"ConnectionError: Couldn't reach https://raw.githubusercontent.com"),Si.forEach(s),lr=u(qe),Ns=r(qe,"TD",{});var Oi=l(Ns);ir=o(Oi,"cannot connect\uFF0Ceven by Web browser\uFF0Cplease check that  there is some  problems\u3002"),Oi.forEach(s),cr=u(qe),Fs=r(qe,"TD",{});var Ii=l(Fs);dr=o(Ii,"Hello,\\r\\nI am trying to run run_glue.py and it gives me this error..."),Ii.forEach(s),qe.forEach(s),ur=u(Ge),oe=r(Ge,"TR",{});var Te=l(oe);Hs=r(Te,"TH",{});var Pi=l(Hs);pr=o(Pi,"3"),Pi.forEach(s),mr=u(Te),Rs=r(Te,"TD",{});var Ni=l(Rs);hr=o(Ni,"https://github.com/huggingface/datasets/issues/2787"),Ni.forEach(s),fr=u(Te),Ls=r(Te,"TD",{});var Fi=l(Ls);_r=o(Fi,"ConnectionError: Couldn't reach https://raw.githubusercontent.com"),Fi.forEach(s),gr=u(Te),Ms=r(Te,"TD",{});var Hi=l(Ms);br=o(Hi,"I can access https://raw.githubusercontent.com/huggingface/datasets/1.7.0/datasets/glue/glue.py without problem..."),Hi.forEach(s),wr=u(Te),Ws=r(Te,"TD",{});var Ri=l(Ws);$r=o(Ri,"Hello,\\r\\nI am trying to run run_glue.py and it gives me this error..."),Ri.forEach(s),Te.forEach(s),Ge.forEach(s),vo.forEach(s),Pa=u(e),re=r(e,"P",{});var Ye=l(re);vr=o(Ye,"Great, we can see the rows have been replicated, with the "),zs=r(Ye,"CODE",{});var Li=l(zs);yr=o(Li,"comments"),Li.forEach(s),kr=o(Ye," column containing the individual comments! Now that we\u2019re finished with Pandas, we can quickly switch back to a "),Us=r(Ye,"CODE",{});var Mi=l(Us);xr=o(Mi,"Dataset"),Mi.forEach(s),Er=o(Ye," by loading the "),Gs=r(Ye,"CODE",{});var Wi=l(Gs);jr=o(Wi,"DataFrame"),Wi.forEach(s),qr=o(Ye," in memory:"),Ye.forEach(s),Na=u(e),y(rt.$$.fragment,e),Fa=u(e),y(lt.$$.fragment,e),Ha=u(e),At=r(e,"P",{});var zi=l(At);Tr=o(zi,"Okay, this has given us a few thousand comments to work with!"),zi.forEach(s),Ra=u(e),y(He.$$.fragment,e),La=u(e),Re=r(e,"P",{});var yo=l(Re);Dr=o(yo,"Now that we have one comment per row, let\u2019s create a new "),Ys=r(yo,"CODE",{});var Ui=l(Ys);Cr=o(Ui,"comments_length"),Ui.forEach(s),Ar=o(yo," column that contains the number of words per comment:"),yo.forEach(s),Ma=u(e),y(it.$$.fragment,e),Wa=u(e),St=r(e,"P",{});var Gi=l(St);Sr=o(Gi,"We can use this new column to filter out short comments, which typically include things like \u201Ccc @lewtun\u201D or \u201CThanks!\u201D that are not relevant for our search engine. There\u2019s no precise number to select for the filter, but around 15 words seems like a good start:"),Gi.forEach(s),za=u(e),y(ct.$$.fragment,e),Ua=u(e),y(dt.$$.fragment,e),Ga=u(e),be=r(e,"P",{});var Bt=l(be);Or=o(Bt,"Having cleaned up our dataset a bit, let\u2019s concatenate the issue title, description, and comments together in a new "),Bs=r(Bt,"CODE",{});var Yi=l(Bs);Ir=o(Yi,"text"),Yi.forEach(s),Pr=o(Bt," column. As usual, we\u2019ll write a simple function that we can pass to "),Vs=r(Bt,"CODE",{});var Bi=l(Vs);Nr=o(Bi,"Dataset.map()"),Bi.forEach(s),Fr=o(Bt,":"),Bt.forEach(s),Ya=u(e),y(ut.$$.fragment,e),Ba=u(e),Ot=r(e,"P",{});var Vi=l(Ot);Hr=o(Vi,"We\u2019re finally ready to create some embeddings! Let\u2019s take a look."),Vi.forEach(s),Va=u(e),Ae=r(e,"H2",{class:!0});var ko=l(Ae);Le=r(ko,"A",{id:!0,class:!0,href:!0});var Ji=l(Le);Js=r(Ji,"SPAN",{});var Qi=l(Js);y(pt.$$.fragment,Qi),Qi.forEach(s),Ji.forEach(s),Rr=u(ko),Qs=r(ko,"SPAN",{});var Xi=l(Qs);Lr=o(Xi,"Creating text embeddings"),Xi.forEach(s),ko.forEach(s),Ja=u(e),Y=r(e,"P",{});var X=l(Y);Mr=o(X,"We saw in "),It=r(X,"A",{href:!0});var Ki=l(It);Wr=o(Ki,"Chapter 2"),Ki.forEach(s),zr=o(X," that we can obtain token embeddings by using the "),Xs=r(X,"CODE",{});var Zi=l(Xs);Ur=o(Zi,"AutoModel"),Zi.forEach(s),Gr=o(X," class. All we need to do is pick a suitable checkpoint to load the model from. Fortunately, there\u2019s a library called "),Ks=r(X,"CODE",{});var ec=l(Ks);Yr=o(ec,"sentence-transformers"),ec.forEach(s),Br=o(X," that is dedicated to creating embeddings. As described in the library\u2019s "),mt=r(X,"A",{href:!0,rel:!0});var tc=l(mt);Vr=o(tc,"documentation"),tc.forEach(s),Jr=o(X,", our use case is an example of "),Zs=r(X,"EM",{});var sc=l(Zs);Qr=o(sc,"asymmetric semantic search"),sc.forEach(s),Xr=o(X," because we have a short query whose answer we\u2019d like to find in a longer document, like a an issue comment. The handy "),ht=r(X,"A",{href:!0,rel:!0});var ac=l(ht);Kr=o(ac,"model overview table"),ac.forEach(s),Zr=o(X," in the documentation indicates that the "),ea=r(X,"CODE",{});var oc=l(ea);el=o(oc,"multi-qa-mpnet-base-dot-v1"),oc.forEach(s),tl=o(X," checkpoint has the best performance for semantic search, so we\u2019ll use that for our application. We\u2019ll also load the tokenizer using the same checkpoint:"),X.forEach(s),Qa=u(e),pe.l(e),Pt=u(e),we=r(e,"P",{});var Vt=l(we);sl=o(Vt,"As we mentioned earlier, we\u2019d like to represent each entry in our GitHub issues corpus as a single vector, so we need to \u201Cpool\u201D or average our token embeddings in some way. One popular approach is to perform "),ta=r(Vt,"EM",{});var nc=l(ta);al=o(nc,"CLS pooling"),nc.forEach(s),ol=o(Vt," on our model\u2019s outputs, where we simply collect the last hidden state for the special "),sa=r(Vt,"CODE",{});var rc=l(sa);nl=o(rc,"[CLS]"),rc.forEach(s),rl=o(Vt," token. The following function does the trick for us:"),Vt.forEach(s),Xa=u(e),y(ft.$$.fragment,e),Ka=u(e),Nt=r(e,"P",{});var lc=l(Nt);ll=o(lc,"Next, we\u2019ll create a helper function that will tokenize a list of documents, place the tensors on the GPU, feed them to the model, and finally apply CLS pooling to the outputs:"),lc.forEach(s),Za=u(e),he.l(e),Ft=u(e),Ht=r(e,"P",{});var ic=l(Ht);il=o(ic,"Notice that we\u2019ve converted the embeddings to NumPy arrays \u2014 that\u2019s because \u{1F917} Datasets requires this format when we try to index them with FAISS, which we\u2019ll do next."),ic.forEach(s),eo=u(e),Se=r(e,"H2",{class:!0});var xo=l(Se);Me=r(xo,"A",{id:!0,class:!0,href:!0});var cc=l(Me);aa=r(cc,"SPAN",{});var dc=l(aa);y(_t.$$.fragment,dc),dc.forEach(s),cc.forEach(s),cl=u(xo),oa=r(xo,"SPAN",{});var uc=l(oa);dl=o(uc,"Using FAISS for efficient similarity search"),uc.forEach(s),xo.forEach(s),to=u(e),$e=r(e,"P",{});var Jt=l($e);ul=o(Jt,"Now that we have a dataset of embeddings, we need some way to search over them. To do this, we\u2019ll use a special data structure in \u{1F917} Datasets called a "),na=r(Jt,"EM",{});var pc=l(na);pl=o(pc,"FAISS index"),pc.forEach(s),ml=o(Jt,". "),gt=r(Jt,"A",{href:!0,rel:!0});var mc=l(gt);hl=o(mc,"FAISS"),mc.forEach(s),fl=o(Jt," (short for Facebook AI Similarity Search) is a library that provides efficient algorithms to quickly search and cluster embedding vectors."),Jt.forEach(s),so=u(e),ve=r(e,"P",{});var Qt=l(ve);_l=o(Qt,"The basic idea behind FAISS is to create a special data structure called an "),ra=r(Qt,"EM",{});var hc=l(ra);gl=o(hc,"index"),hc.forEach(s),bl=o(Qt," that allows one to find which embeddings are similar to an input embedding. Creating a FAISS index in \u{1F917} Datasets is simple \u2014 we use the "),la=r(Qt,"CODE",{});var fc=l(la);wl=o(fc,"Dataset.add_faiss_index()"),fc.forEach(s),$l=o(Qt," function and specify which column of our dataset we\u2019d like to index:"),Qt.forEach(s),ao=u(e),y(bt.$$.fragment,e),oo=u(e),We=r(e,"P",{});var Eo=l(We);vl=o(Eo,"We can now perform queries on this index by doing a nearest neighbor lookup with the "),ia=r(Eo,"CODE",{});var _c=l(ia);yl=o(_c,"Dataset.get_nearest_examples()"),_c.forEach(s),kl=o(Eo," function. Let\u2019s test this out by first embedding a question as follows:"),Eo.forEach(s),no=u(e),_e.l(e),Rt=u(e),Lt=r(e,"P",{});var gc=l(Lt);xl=o(gc,"Just like with the documents, we now have a 768-dimensional vector representing the query, which we can compare against the whole corpus to find the most similar embeddings:"),gc.forEach(s),ro=u(e),y(wt.$$.fragment,e),lo=u(e),ye=r(e,"P",{});var Xt=l(ye);El=o(Xt,"The "),ca=r(Xt,"CODE",{});var bc=l(ca);jl=o(bc,"Dataset.get_nearest_examples()"),bc.forEach(s),ql=o(Xt," function returns a tuple of scores that rank the overlap between the query and the document, and a corresponding set of samples (here, the 5 best matches). Let\u2019s collect these in a "),da=r(Xt,"CODE",{});var wc=l(da);Tl=o(wc,"pandas.DataFrame"),wc.forEach(s),Dl=o(Xt," so we can easily sort them:"),Xt.forEach(s),io=u(e),y($t.$$.fragment,e),co=u(e),Mt=r(e,"P",{});var $c=l(Mt);Cl=o($c,"Now we can iterate over the first few rows to see how well our query matched the available comments:"),$c.forEach(s),uo=u(e),y(vt.$$.fragment,e),po=u(e),y(yt.$$.fragment,e),mo=u(e),Wt=r(e,"P",{});var vc=l(Wt);Al=o(vc,"Not bad! Our second hit seems to match the query."),vc.forEach(s),ho=u(e),y(ze.$$.fragment,e),this.h()},h(){j(p,"name","hf:doc:metadata"),j(p,"content",JSON.stringify(zc)),j(g,"id","semantic-search-with-faiss"),j(g,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),j(g,"href","#semantic-search-with-faiss"),j(f,"class","relative group"),j(D,"href","/course/chapter5/5"),j(C,"id","using-embeddings-for-semantic-search"),j(C,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),j(C,"href","#using-embeddings-for-semantic-search"),j(m,"class","relative group"),j(Dt,"href","/course/chapter1"),j(Be,"class","block dark:hidden"),yc(Be.src,Ol="https://huggingface.co/datasets/huggingface-course/documentation-images/resolve/main/en/chapter5/semantic-search.svg")||j(Be,"src",Ol),j(Be,"alt","Semantic search."),j(Ve,"class","hidden dark:block"),yc(Ve.src,Il="https://huggingface.co/datasets/huggingface-course/documentation-images/resolve/main/en/chapter5/semantic-search-dark.svg")||j(Ve,"src",Il),j(Ve,"alt","Semantic search."),j(De,"class","flex justify-center"),j(Oe,"id","loading-and-preparing-the-dataset"),j(Oe,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),j(Oe,"href","#loading-and-preparing-the-dataset"),j(Ce,"class","relative group"),j(Pe,"href","https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.explode.html"),j(Pe,"rel","nofollow"),jo(Z,"text-align","right"),j(ee,"border","1"),j(ee,"class","dataframe"),jo(ee,"table-layout","fixed"),jo(ee,"word-wrap","break-word"),jo(ee,"width","100%"),j(Le,"id","creating-text-embeddings"),j(Le,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),j(Le,"href","#creating-text-embeddings"),j(Ae,"class","relative group"),j(It,"href","/course/chapter2"),j(mt,"href","https://www.sbert.net/examples/applications/semantic-search/README.html#symmetric-vs-asymmetric-semantic-search"),j(mt,"rel","nofollow"),j(ht,"href","https://www.sbert.net/docs/pretrained_models.html#model-overview"),j(ht,"rel","nofollow"),j(Me,"id","using-faiss-for-efficient-similarity-search"),j(Me,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),j(Me,"href","#using-faiss-for-efficient-similarity-search"),j(Se,"class","relative group"),j(gt,"href","https://faiss.ai/"),j(gt,"rel","nofollow")},m(e,i){t(document.head,p),c(e,$,i),k(h,e,i),c(e,E,i),c(e,f,i),t(f,g),t(g,I),k(_,I,null),t(f,A),t(f,q),t(q,M),c(e,P,i),kt[S].m(e,i),c(e,F,i),c(e,R,i),t(R,U),t(R,D),t(D,H),t(R,B),c(e,z,i),k(T,e,i),c(e,G,i),c(e,m,i),t(m,C),t(C,L),k(V,L,null),t(m,ne),t(m,ce),t(ce,Do),c(e,ma,i),c(e,ge,i),t(ge,Co),t(ge,Dt),t(Dt,Ao),t(ge,So),t(ge,Kt),t(Kt,Oo),t(ge,Io),c(e,ha,i),c(e,Ct,i),t(Ct,Po),c(e,fa,i),c(e,De,i),t(De,Be),t(De,No),t(De,Ve),c(e,_a,i),c(e,Ce,i),t(Ce,Oe),t(Oe,Zt),k(Je,Zt,null),t(Ce,Fo),t(Ce,es),t(es,Ho),c(e,ga,i),c(e,Ie,i),t(Ie,Ro),t(Ie,ts),t(ts,Lo),t(Ie,Mo),c(e,ba,i),k(Qe,e,i),c(e,wa,i),k(Xe,e,i),c(e,$a,i),c(e,J,i),t(J,Wo),t(J,ss),t(ss,zo),t(J,Uo),t(J,as),t(as,Go),t(J,Yo),t(J,os),t(os,Bo),t(J,Vo),t(J,ns),t(ns,Jo),t(J,Qo),t(J,rs),t(rs,Xo),t(J,Ko),c(e,va,i),k(Ke,e,i),c(e,ya,i),k(Ze,e,i),c(e,ka,i),c(e,Q,i),t(Q,Zo),t(Q,ls),t(ls,en),t(Q,tn),t(Q,is),t(is,sn),t(Q,an),t(Q,cs),t(cs,on),t(Q,nn),t(Q,ds),t(ds,rn),t(Q,ln),t(Q,us),t(us,cn),t(Q,dn),c(e,xa,i),k(et,e,i),c(e,Ea,i),k(tt,e,i),c(e,ja,i),c(e,K,i),t(K,un),t(K,ps),t(ps,pn),t(K,mn),t(K,ms),t(ms,hn),t(K,fn),t(K,Pe),t(Pe,hs),t(hs,_n),t(Pe,gn),t(K,bn),t(K,fs),t(fs,wn),t(K,$n),c(e,qa,i),k(st,e,i),c(e,Ta,i),c(e,Ne,i),t(Ne,vn),t(Ne,_s),t(_s,yn),t(Ne,kn),c(e,Da,i),k(at,e,i),c(e,Ca,i),k(ot,e,i),c(e,Aa,i),c(e,Fe,i),t(Fe,xn),t(Fe,gs),t(gs,En),t(Fe,jn),c(e,Sa,i),k(nt,e,i),c(e,Oa,i),c(e,ee,i),t(ee,bs),t(bs,Z),t(Z,Ia),t(Z,qn),t(Z,ws),t(ws,Tn),t(Z,Dn),t(Z,$s),t($s,Cn),t(Z,An),t(Z,vs),t(vs,Sn),t(Z,On),t(Z,ys),t(ys,In),t(ee,Pn),t(ee,de),t(de,te),t(te,ks),t(ks,Nn),t(te,Fn),t(te,xs),t(xs,Hn),t(te,Rn),t(te,Es),t(Es,Ln),t(te,Mn),t(te,js),t(js,Wn),t(te,zn),t(te,qs),t(qs,Un),t(de,Gn),t(de,se),t(se,Ts),t(Ts,Yn),t(se,Bn),t(se,Ds),t(Ds,Vn),t(se,Jn),t(se,Cs),t(Cs,Qn),t(se,Xn),t(se,As),t(As,Kn),t(se,Zn),t(se,Ss),t(Ss,er),t(de,tr),t(de,ae),t(ae,Os),t(Os,sr),t(ae,ar),t(ae,Is),t(Is,or),t(ae,nr),t(ae,Ps),t(Ps,rr),t(ae,lr),t(ae,Ns),t(Ns,ir),t(ae,cr),t(ae,Fs),t(Fs,dr),t(de,ur),t(de,oe),t(oe,Hs),t(Hs,pr),t(oe,mr),t(oe,Rs),t(Rs,hr),t(oe,fr),t(oe,Ls),t(Ls,_r),t(oe,gr),t(oe,Ms),t(Ms,br),t(oe,wr),t(oe,Ws),t(Ws,$r),c(e,Pa,i),c(e,re,i),t(re,vr),t(re,zs),t(zs,yr),t(re,kr),t(re,Us),t(Us,xr),t(re,Er),t(re,Gs),t(Gs,jr),t(re,qr),c(e,Na,i),k(rt,e,i),c(e,Fa,i),k(lt,e,i),c(e,Ha,i),c(e,At,i),t(At,Tr),c(e,Ra,i),k(He,e,i),c(e,La,i),c(e,Re,i),t(Re,Dr),t(Re,Ys),t(Ys,Cr),t(Re,Ar),c(e,Ma,i),k(it,e,i),c(e,Wa,i),c(e,St,i),t(St,Sr),c(e,za,i),k(ct,e,i),c(e,Ua,i),k(dt,e,i),c(e,Ga,i),c(e,be,i),t(be,Or),t(be,Bs),t(Bs,Ir),t(be,Pr),t(be,Vs),t(Vs,Nr),t(be,Fr),c(e,Ya,i),k(ut,e,i),c(e,Ba,i),c(e,Ot,i),t(Ot,Hr),c(e,Va,i),c(e,Ae,i),t(Ae,Le),t(Le,Js),k(pt,Js,null),t(Ae,Rr),t(Ae,Qs),t(Qs,Lr),c(e,Ja,i),c(e,Y,i),t(Y,Mr),t(Y,It),t(It,Wr),t(Y,zr),t(Y,Xs),t(Xs,Ur),t(Y,Gr),t(Y,Ks),t(Ks,Yr),t(Y,Br),t(Y,mt),t(mt,Vr),t(Y,Jr),t(Y,Zs),t(Zs,Qr),t(Y,Xr),t(Y,ht),t(ht,Kr),t(Y,Zr),t(Y,ea),t(ea,el),t(Y,tl),c(e,Qa,i),xt[ue].m(e,i),c(e,Pt,i),c(e,we,i),t(we,sl),t(we,ta),t(ta,al),t(we,ol),t(we,sa),t(sa,nl),t(we,rl),c(e,Xa,i),k(ft,e,i),c(e,Ka,i),c(e,Nt,i),t(Nt,ll),c(e,Za,i),Et[me].m(e,i),c(e,Ft,i),c(e,Ht,i),t(Ht,il),c(e,eo,i),c(e,Se,i),t(Se,Me),t(Me,aa),k(_t,aa,null),t(Se,cl),t(Se,oa),t(oa,dl),c(e,to,i),c(e,$e,i),t($e,ul),t($e,na),t(na,pl),t($e,ml),t($e,gt),t(gt,hl),t($e,fl),c(e,so,i),c(e,ve,i),t(ve,_l),t(ve,ra),t(ra,gl),t(ve,bl),t(ve,la),t(la,wl),t(ve,$l),c(e,ao,i),k(bt,e,i),c(e,oo,i),c(e,We,i),t(We,vl),t(We,ia),t(ia,yl),t(We,kl),c(e,no,i),jt[fe].m(e,i),c(e,Rt,i),c(e,Lt,i),t(Lt,xl),c(e,ro,i),k(wt,e,i),c(e,lo,i),c(e,ye,i),t(ye,El),t(ye,ca),t(ca,jl),t(ye,ql),t(ye,da),t(da,Tl),t(ye,Dl),c(e,io,i),k($t,e,i),c(e,co,i),c(e,Mt,i),t(Mt,Cl),c(e,uo,i),k(vt,e,i),c(e,po,i),k(yt,e,i),c(e,mo,i),c(e,Wt,i),t(Wt,Al),c(e,ho,i),k(ze,e,i),fo=!0},p(e,[i]){const qt={};i&1&&(qt.fw=e[0]),h.$set(qt);let zt=S;S=Nl(e),S!==zt&&(To(),b(kt[zt],1,1,()=>{kt[zt]=null}),qo(),N=kt[S],N||(N=kt[S]=Pl[S](e),N.c()),w(N,1),N.m(F.parentNode,F));const ua={};i&2&&(ua.$$scope={dirty:i,ctx:e}),He.$set(ua);let Ut=ue;ue=Hl(e),ue!==Ut&&(To(),b(xt[Ut],1,1,()=>{xt[Ut]=null}),qo(),pe=xt[ue],pe||(pe=xt[ue]=Fl[ue](e),pe.c()),w(pe,1),pe.m(Pt.parentNode,Pt));let Ue=me;me=Ll(e),me!==Ue&&(To(),b(Et[Ue],1,1,()=>{Et[Ue]=null}),qo(),he=Et[me],he||(he=Et[me]=Rl[me](e),he.c()),w(he,1),he.m(Ft.parentNode,Ft));let Gt=fe;fe=Wl(e),fe!==Gt&&(To(),b(jt[Gt],1,1,()=>{jt[Gt]=null}),qo(),_e=jt[fe],_e||(_e=jt[fe]=Ml[fe](e),_e.c()),w(_e,1),_e.m(Rt.parentNode,Rt));const Tt={};i&2&&(Tt.$$scope={dirty:i,ctx:e}),ze.$set(Tt)},i(e){fo||(w(h.$$.fragment,e),w(_.$$.fragment,e),w(N),w(T.$$.fragment,e),w(V.$$.fragment,e),w(Je.$$.fragment,e),w(Qe.$$.fragment,e),w(Xe.$$.fragment,e),w(Ke.$$.fragment,e),w(Ze.$$.fragment,e),w(et.$$.fragment,e),w(tt.$$.fragment,e),w(st.$$.fragment,e),w(at.$$.fragment,e),w(ot.$$.fragment,e),w(nt.$$.fragment,e),w(rt.$$.fragment,e),w(lt.$$.fragment,e),w(He.$$.fragment,e),w(it.$$.fragment,e),w(ct.$$.fragment,e),w(dt.$$.fragment,e),w(ut.$$.fragment,e),w(pt.$$.fragment,e),w(pe),w(ft.$$.fragment,e),w(he),w(_t.$$.fragment,e),w(bt.$$.fragment,e),w(_e),w(wt.$$.fragment,e),w($t.$$.fragment,e),w(vt.$$.fragment,e),w(yt.$$.fragment,e),w(ze.$$.fragment,e),fo=!0)},o(e){b(h.$$.fragment,e),b(_.$$.fragment,e),b(N),b(T.$$.fragment,e),b(V.$$.fragment,e),b(Je.$$.fragment,e),b(Qe.$$.fragment,e),b(Xe.$$.fragment,e),b(Ke.$$.fragment,e),b(Ze.$$.fragment,e),b(et.$$.fragment,e),b(tt.$$.fragment,e),b(st.$$.fragment,e),b(at.$$.fragment,e),b(ot.$$.fragment,e),b(nt.$$.fragment,e),b(rt.$$.fragment,e),b(lt.$$.fragment,e),b(He.$$.fragment,e),b(it.$$.fragment,e),b(ct.$$.fragment,e),b(dt.$$.fragment,e),b(ut.$$.fragment,e),b(pt.$$.fragment,e),b(pe),b(ft.$$.fragment,e),b(he),b(_t.$$.fragment,e),b(bt.$$.fragment,e),b(_e),b(wt.$$.fragment,e),b($t.$$.fragment,e),b(vt.$$.fragment,e),b(yt.$$.fragment,e),b(ze.$$.fragment,e),fo=!1},d(e){s(p),e&&s($),x(h,e),e&&s(E),e&&s(f),x(_),e&&s(P),kt[S].d(e),e&&s(F),e&&s(R),e&&s(z),x(T,e),e&&s(G),e&&s(m),x(V),e&&s(ma),e&&s(ge),e&&s(ha),e&&s(Ct),e&&s(fa),e&&s(De),e&&s(_a),e&&s(Ce),x(Je),e&&s(ga),e&&s(Ie),e&&s(ba),x(Qe,e),e&&s(wa),x(Xe,e),e&&s($a),e&&s(J),e&&s(va),x(Ke,e),e&&s(ya),x(Ze,e),e&&s(ka),e&&s(Q),e&&s(xa),x(et,e),e&&s(Ea),x(tt,e),e&&s(ja),e&&s(K),e&&s(qa),x(st,e),e&&s(Ta),e&&s(Ne),e&&s(Da),x(at,e),e&&s(Ca),x(ot,e),e&&s(Aa),e&&s(Fe),e&&s(Sa),x(nt,e),e&&s(Oa),e&&s(ee),e&&s(Pa),e&&s(re),e&&s(Na),x(rt,e),e&&s(Fa),x(lt,e),e&&s(Ha),e&&s(At),e&&s(Ra),x(He,e),e&&s(La),e&&s(Re),e&&s(Ma),x(it,e),e&&s(Wa),e&&s(St),e&&s(za),x(ct,e),e&&s(Ua),x(dt,e),e&&s(Ga),e&&s(be),e&&s(Ya),x(ut,e),e&&s(Ba),e&&s(Ot),e&&s(Va),e&&s(Ae),x(pt),e&&s(Ja),e&&s(Y),e&&s(Qa),xt[ue].d(e),e&&s(Pt),e&&s(we),e&&s(Xa),x(ft,e),e&&s(Ka),e&&s(Nt),e&&s(Za),Et[me].d(e),e&&s(Ft),e&&s(Ht),e&&s(eo),e&&s(Se),x(_t),e&&s(to),e&&s($e),e&&s(so),e&&s(ve),e&&s(ao),x(bt,e),e&&s(oo),e&&s(We),e&&s(no),jt[fe].d(e),e&&s(Rt),e&&s(Lt),e&&s(ro),x(wt,e),e&&s(lo),e&&s(ye),e&&s(io),x($t,e),e&&s(co),e&&s(Mt),e&&s(uo),x(vt,e),e&&s(po),x(yt,e),e&&s(mo),e&&s(Wt),e&&s(ho),x(ze,e)}}}const zc={local:"semantic-search-with-faiss",sections:[{local:"using-embeddings-for-semantic-search",title:"Using embeddings for semantic search"},{local:"loading-and-preparing-the-dataset",title:"Loading and preparing the dataset"},{local:"creating-text-embeddings",title:"Creating text embeddings"},{local:"using-faiss-for-efficient-similarity-search",title:"Using FAISS for efficient similarity search"}],title:"Semantic search with FAISS"};function Uc(W,p,$){let h="pt";return Dc(()=>{const E=new URLSearchParams(window.location.search);$(0,h=E.get("fw")||"pt")}),[h]}class Kc extends Ec{constructor(p){super();jc(this,p,Uc,Wc,qc,{})}}export{Kc as default,zc as metadata};
