import{s as Dl,o as Ll,n as Al}from"../chunks/scheduler.37c15a92.js";import{S as Kl,i as Pl,g as J,s as o,r as u,A as Ol,h as b,f as l,c as M,j as El,u as h,x as j,k as De,l as il,y as es,a as s,v as y,t as c,b as el,d,w as U,p as tl}from"../chunks/index.7cb9c9b8.js";import{T as Hl}from"../chunks/Tip.d10b3fc9.js";import{Y as ts}from"../chunks/Youtube.8666c400.js";import{C as f}from"../chunks/CodeBlock.abae2786.js";import{C as ql}from"../chunks/CourseFloatingBanner.df82c153.js";import{F as ls}from"../chunks/FrameworkSwitchCourse.97630871.js";import{H as Le,E as ss}from"../chunks/getInferenceSnippets.c47ae3ea.js";function as(C){let a,p;return a=new ql({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(){u(a.$$.fragment)},l(n){h(a.$$.fragment,n)},m(n,T){y(a,n,T),p=!0},i(n){p||(d(a.$$.fragment,n),p=!0)},o(n){c(a.$$.fragment,n),p=!1},d(n){U(a,n)}}}function ns(C){let a,p;return a=new ql({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(){u(a.$$.fragment)},l(n){h(a.$$.fragment,n)},m(n,T){y(a,n,T),p=!0},i(n){p||(d(a.$$.fragment,n),p=!0)},o(n){c(a.$$.fragment,n),p=!1},d(n){U(a,n)}}}function is(C){let a,p='✏️ <strong>Try it out!</strong> See if you can use <code>Dataset.map()</code> to explode the <code>comments</code> column of <code>issues_dataset</code> <em>without</em> resorting to the use of Pandas. This is a little tricky; you might find the <a href="https://huggingface.co/docs/datasets/about_map_batch#batch-mapping" rel="nofollow">“Batch mapping”</a> section of the 🤗 Datasets documentation useful for this task.';return{c(){a=J("p"),a.innerHTML=p},l(n){a=b(n,"P",{"data-svelte-h":!0}),j(a)!=="svelte-vkr8m0"&&(a.innerHTML=p)},m(n,T){s(n,a,T)},p:Al,d(n){n&&l(a)}}}function os(C){let a,p,n,T="Note that we’ve set <code>from_pt=True</code> as an argument of the <code>from_pretrained()</code> method. That’s because the <code>multi-qa-mpnet-base-dot-v1</code> checkpoint only has PyTorch weights, so setting <code>from_pt=True</code> will automatically convert them to the TensorFlow format for us. As you can see, it is very simple to switch between frameworks in 🤗 Transformers!",r;return a=new f({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9Ub2tlbml6ZXIlMkMlMjBURkF1dG9Nb2RlbCUwQSUwQW1vZGVsX2NrcHQlMjAlM0QlMjAlMjJzZW50ZW5jZS10cmFuc2Zvcm1lcnMlMkZtdWx0aS1xYS1tcG5ldC1iYXNlLWRvdC12MSUyMiUwQXRva2VuaXplciUyMCUzRCUyMEF1dG9Ub2tlbml6ZXIuZnJvbV9wcmV0cmFpbmVkKG1vZGVsX2NrcHQpJTBBbW9kZWwlMjAlM0QlMjBURkF1dG9Nb2RlbC5mcm9tX3ByZXRyYWluZWQobW9kZWxfY2twdCUyQyUyMGZyb21fcHQlM0RUcnVlKQ==",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>)`,wrap:!1}}),{c(){u(a.$$.fragment),p=o(),n=J("p"),n.innerHTML=T},l(m){h(a.$$.fragment,m),p=M(m),n=b(m,"P",{"data-svelte-h":!0}),j(n)!=="svelte-104jwge"&&(n.innerHTML=T)},m(m,G){y(a,m,G),s(m,p,G),s(m,n,G),r=!0},i(m){r||(d(a.$$.fragment,m),r=!0)},o(m){c(a.$$.fragment,m),r=!1},d(m){m&&(l(p),l(n)),U(a,m)}}}function Ms(C){let a,p,n,T="To speed up the embedding process, it helps to place the model and inputs on a GPU device, so let’s do that now:",r,m,G;return a=new f({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9Ub2tlbml6ZXIlMkMlMjBBdXRvTW9kZWwlMEElMEFtb2RlbF9ja3B0JTIwJTNEJTIwJTIyc2VudGVuY2UtdHJhbnNmb3JtZXJzJTJGbXVsdGktcWEtbXBuZXQtYmFzZS1kb3QtdjElMjIlMEF0b2tlbml6ZXIlMjAlM0QlMjBBdXRvVG9rZW5pemVyLmZyb21fcHJldHJhaW5lZChtb2RlbF9ja3B0KSUwQW1vZGVsJTIwJTNEJTIwQXV0b01vZGVsLmZyb21fcHJldHJhaW5lZChtb2RlbF9ja3B0KQ==",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)`,wrap:!1}}),m=new f({props:{code:"aW1wb3J0JTIwdG9yY2glMEElMEFkZXZpY2UlMjAlM0QlMjB0b3JjaC5kZXZpY2UoJTIyY3VkYSUyMiklMEFtb2RlbC50byhkZXZpY2Up",highlighted:`<span class="hljs-keyword">import</span> torch

device = torch.device(<span class="hljs-string">&quot;cuda&quot;</span>)
model.to(device)`,wrap:!1}}),{c(){u(a.$$.fragment),p=o(),n=J("p"),n.textContent=T,r=o(),u(m.$$.fragment)},l(w){h(a.$$.fragment,w),p=M(w),n=b(w,"P",{"data-svelte-h":!0}),j(n)!=="svelte-1daalrm"&&(n.textContent=T),r=M(w),h(m.$$.fragment,w)},m(w,Q){y(a,w,Q),s(w,p,Q),s(w,n,Q),s(w,r,Q),y(m,w,Q),G=!0},i(w){G||(d(a.$$.fragment,w),d(m.$$.fragment,w),G=!0)},o(w){c(a.$$.fragment,w),c(m.$$.fragment,w),G=!1},d(w){w&&(l(p),l(n),l(r)),U(a,w),U(m,w)}}}function rs(C){let a,p,n,T="We can test the function works by feeding it the first text entry in our corpus and inspecting the output shape:",r,m,G,w,Q,Z,R="Great, we’ve converted the first entry in our corpus into a 768-dimensional vector! We can use <code>Dataset.map()</code> to apply our <code>get_embeddings()</code> function to each row in our corpus, so let’s create a new <code>embeddings</code> column as follows:",I,k,$;return a=new f({props:{code:"ZGVmJTIwZ2V0X2VtYmVkZGluZ3ModGV4dF9saXN0KSUzQSUwQSUyMCUyMCUyMCUyMGVuY29kZWRfaW5wdXQlMjAlM0QlMjB0b2tlbml6ZXIoJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwdGV4dF9saXN0JTJDJTIwcGFkZGluZyUzRFRydWUlMkMlMjB0cnVuY2F0aW9uJTNEVHJ1ZSUyQyUyMHJldHVybl90ZW5zb3JzJTNEJTIydGYlMjIlMEElMjAlMjAlMjAlMjApJTBBJTIwJTIwJTIwJTIwZW5jb2RlZF9pbnB1dCUyMCUzRCUyMCU3QmslM0ElMjB2JTIwZm9yJTIwayUyQyUyMHYlMjBpbiUyMGVuY29kZWRfaW5wdXQuaXRlbXMoKSU3RCUwQSUyMCUyMCUyMCUyMG1vZGVsX291dHB1dCUyMCUzRCUyMG1vZGVsKCoqZW5jb2RlZF9pbnB1dCklMEElMjAlMjAlMjAlMjByZXR1cm4lMjBjbHNfcG9vbGluZyhtb2RlbF9vdXRwdXQp",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)`,wrap:!1}}),m=new f({props:{code:"ZW1iZWRkaW5nJTIwJTNEJTIwZ2V0X2VtYmVkZGluZ3MoY29tbWVudHNfZGF0YXNldCU1QiUyMnRleHQlMjIlNUQlNUIwJTVEKSUwQWVtYmVkZGluZy5zaGFwZQ==",highlighted:`embedding = get_embeddings(comments_dataset[<span class="hljs-string">&quot;text&quot;</span>][<span class="hljs-number">0</span>])
embedding.shape`,wrap:!1}}),w=new f({props:{code:"VGVuc29yU2hhcGUoJTVCMSUyQyUyMDc2OCU1RCk=",highlighted:'TensorShape([<span class="hljs-number">1</span>, <span class="hljs-number">768</span>])',wrap:!1}}),k=new f({props:{code:"ZW1iZWRkaW5nc19kYXRhc2V0JTIwJTNEJTIwY29tbWVudHNfZGF0YXNldC5tYXAoJTBBJTIwJTIwJTIwJTIwbGFtYmRhJTIweCUzQSUyMCU3QiUyMmVtYmVkZGluZ3MlMjIlM0ElMjBnZXRfZW1iZWRkaW5ncyh4JTVCJTIydGV4dCUyMiU1RCkubnVtcHkoKSU1QjAlNUQlN0QlMEEp",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>]}
)`,wrap:!1}}),{c(){u(a.$$.fragment),p=o(),n=J("p"),n.textContent=T,r=o(),u(m.$$.fragment),G=o(),u(w.$$.fragment),Q=o(),Z=J("p"),Z.innerHTML=R,I=o(),u(k.$$.fragment)},l(i){h(a.$$.fragment,i),p=M(i),n=b(i,"P",{"data-svelte-h":!0}),j(n)!=="svelte-1ptiihw"&&(n.textContent=T),r=M(i),h(m.$$.fragment,i),G=M(i),h(w.$$.fragment,i),Q=M(i),Z=b(i,"P",{"data-svelte-h":!0}),j(Z)!=="svelte-1gu7iii"&&(Z.innerHTML=R),I=M(i),h(k.$$.fragment,i)},m(i,g){y(a,i,g),s(i,p,g),s(i,n,g),s(i,r,g),y(m,i,g),s(i,G,g),y(w,i,g),s(i,Q,g),s(i,Z,g),s(i,I,g),y(k,i,g),$=!0},i(i){$||(d(a.$$.fragment,i),d(m.$$.fragment,i),d(w.$$.fragment,i),d(k.$$.fragment,i),$=!0)},o(i){c(a.$$.fragment,i),c(m.$$.fragment,i),c(w.$$.fragment,i),c(k.$$.fragment,i),$=!1},d(i){i&&(l(p),l(n),l(r),l(G),l(Q),l(Z),l(I)),U(a,i),U(m,i),U(w,i),U(k,i)}}}function cs(C){let a,p,n,T="We can test the function works by feeding it the first text entry in our corpus and inspecting the output shape:",r,m,G,w,Q,Z,R="Great, we’ve converted the first entry in our corpus into a 768-dimensional vector! We can use <code>Dataset.map()</code> to apply our <code>get_embeddings()</code> function to each row in our corpus, so let’s create a new <code>embeddings</code> column as follows:",I,k,$;return a=new f({props:{code:"ZGVmJTIwZ2V0X2VtYmVkZGluZ3ModGV4dF9saXN0KSUzQSUwQSUyMCUyMCUyMCUyMGVuY29kZWRfaW5wdXQlMjAlM0QlMjB0b2tlbml6ZXIoJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwdGV4dF9saXN0JTJDJTIwcGFkZGluZyUzRFRydWUlMkMlMjB0cnVuY2F0aW9uJTNEVHJ1ZSUyQyUyMHJldHVybl90ZW5zb3JzJTNEJTIycHQlMjIlMEElMjAlMjAlMjAlMjApJTBBJTIwJTIwJTIwJTIwZW5jb2RlZF9pbnB1dCUyMCUzRCUyMCU3QmslM0ElMjB2LnRvKGRldmljZSklMjBmb3IlMjBrJTJDJTIwdiUyMGluJTIwZW5jb2RlZF9pbnB1dC5pdGVtcygpJTdEJTBBJTIwJTIwJTIwJTIwbW9kZWxfb3V0cHV0JTIwJTNEJTIwbW9kZWwoKiplbmNvZGVkX2lucHV0KSUwQSUyMCUyMCUyMCUyMHJldHVybiUyMGNsc19wb29saW5nKG1vZGVsX291dHB1dCk=",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)`,wrap:!1}}),m=new f({props:{code:"ZW1iZWRkaW5nJTIwJTNEJTIwZ2V0X2VtYmVkZGluZ3MoY29tbWVudHNfZGF0YXNldCU1QiUyMnRleHQlMjIlNUQlNUIwJTVEKSUwQWVtYmVkZGluZy5zaGFwZQ==",highlighted:`embedding = get_embeddings(comments_dataset[<span class="hljs-string">&quot;text&quot;</span>][<span class="hljs-number">0</span>])
embedding.shape`,wrap:!1}}),w=new f({props:{code:"dG9yY2guU2l6ZSglNUIxJTJDJTIwNzY4JTVEKQ==",highlighted:'torch.Size([<span class="hljs-number">1</span>, <span class="hljs-number">768</span>])',wrap:!1}}),k=new f({props:{code:"ZW1iZWRkaW5nc19kYXRhc2V0JTIwJTNEJTIwY29tbWVudHNfZGF0YXNldC5tYXAoJTBBJTIwJTIwJTIwJTIwbGFtYmRhJTIweCUzQSUyMCU3QiUyMmVtYmVkZGluZ3MlMjIlM0ElMjBnZXRfZW1iZWRkaW5ncyh4JTVCJTIydGV4dCUyMiU1RCkuZGV0YWNoKCkuY3B1KCkubnVtcHkoKSU1QjAlNUQlN0QlMEEp",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>]}
)`,wrap:!1}}),{c(){u(a.$$.fragment),p=o(),n=J("p"),n.textContent=T,r=o(),u(m.$$.fragment),G=o(),u(w.$$.fragment),Q=o(),Z=J("p"),Z.innerHTML=R,I=o(),u(k.$$.fragment)},l(i){h(a.$$.fragment,i),p=M(i),n=b(i,"P",{"data-svelte-h":!0}),j(n)!=="svelte-1ptiihw"&&(n.textContent=T),r=M(i),h(m.$$.fragment,i),G=M(i),h(w.$$.fragment,i),Q=M(i),Z=b(i,"P",{"data-svelte-h":!0}),j(Z)!=="svelte-1gu7iii"&&(Z.innerHTML=R),I=M(i),h(k.$$.fragment,i)},m(i,g){y(a,i,g),s(i,p,g),s(i,n,g),s(i,r,g),y(m,i,g),s(i,G,g),y(w,i,g),s(i,Q,g),s(i,Z,g),s(i,I,g),y(k,i,g),$=!0},i(i){$||(d(a.$$.fragment,i),d(m.$$.fragment,i),d(w.$$.fragment,i),d(k.$$.fragment,i),$=!0)},o(i){c(a.$$.fragment,i),c(m.$$.fragment,i),c(w.$$.fragment,i),c(k.$$.fragment,i),$=!1},d(i){i&&(l(p),l(n),l(r),l(G),l(Q),l(Z),l(I)),U(a,i),U(m,i),U(w,i),U(k,i)}}}function ds(C){let a,p,n,T;return a=new f({props:{code:"cXVlc3Rpb24lMjAlM0QlMjAlMjJIb3clMjBjYW4lMjBJJTIwbG9hZCUyMGElMjBkYXRhc2V0JTIwb2ZmbGluZSUzRiUyMiUwQXF1ZXN0aW9uX2VtYmVkZGluZyUyMCUzRCUyMGdldF9lbWJlZGRpbmdzKCU1QnF1ZXN0aW9uJTVEKS5udW1weSgpJTBBcXVlc3Rpb25fZW1iZWRkaW5nLnNoYXBl",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`,wrap:!1}}),n=new f({props:{code:"KDElMkMlMjA3Njgp",highlighted:'(<span class="hljs-number">1</span>, <span class="hljs-number">768</span>)',wrap:!1}}),{c(){u(a.$$.fragment),p=o(),u(n.$$.fragment)},l(r){h(a.$$.fragment,r),p=M(r),h(n.$$.fragment,r)},m(r,m){y(a,r,m),s(r,p,m),y(n,r,m),T=!0},i(r){T||(d(a.$$.fragment,r),d(n.$$.fragment,r),T=!0)},o(r){c(a.$$.fragment,r),c(n.$$.fragment,r),T=!1},d(r){r&&l(p),U(a,r),U(n,r)}}}function ps(C){let a,p,n,T;return a=new f({props:{code:"cXVlc3Rpb24lMjAlM0QlMjAlMjJIb3clMjBjYW4lMjBJJTIwbG9hZCUyMGElMjBkYXRhc2V0JTIwb2ZmbGluZSUzRiUyMiUwQXF1ZXN0aW9uX2VtYmVkZGluZyUyMCUzRCUyMGdldF9lbWJlZGRpbmdzKCU1QnF1ZXN0aW9uJTVEKS5jcHUoKS5kZXRhY2goKS5udW1weSgpJTBBcXVlc3Rpb25fZW1iZWRkaW5nLnNoYXBl",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`,wrap:!1}}),n=new f({props:{code:"dG9yY2guU2l6ZSglNUIxJTJDJTIwNzY4JTVEKQ==",highlighted:'torch.Size([<span class="hljs-number">1</span>, <span class="hljs-number">768</span>])',wrap:!1}}),{c(){u(a.$$.fragment),p=o(),u(n.$$.fragment)},l(r){h(a.$$.fragment,r),p=M(r),h(n.$$.fragment,r)},m(r,m){y(a,r,m),s(r,p,m),y(n,r,m),T=!0},i(r){T||(d(a.$$.fragment,r),d(n.$$.fragment,r),T=!0)},o(r){c(a.$$.fragment,r),c(n.$$.fragment,r),T=!1},d(r){r&&l(p),U(a,r),U(n,r)}}}function ms(C){let a,p="✏️ <strong>Try it out!</strong> Create your own query and see whether you can find an answer in the retrieved documents. You might have to increase the <code>k</code> parameter in <code>Dataset.get_nearest_examples()</code> to broaden the search.";return{c(){a=J("p"),a.innerHTML=p},l(n){a=b(n,"P",{"data-svelte-h":!0}),j(a)!=="svelte-1819xkn"&&(a.innerHTML=p)},m(n,T){s(n,a,T)},p:Al,d(n){n&&l(a)}}}function us(C){let a,p,n,T,r,m,G,w,Q,Z,R,I,k='In <a href="/course/chapter5/5">section 5</a>, we created a dataset of GitHub issues and comments from the 🤗 Datasets repository. In this section we’ll use this information to build a search engine that can help us find answers to our most pressing questions about the library!',$,i,g,S,Ke,F,ol='As we saw in <a href="/course/chapter1">Chapter 1</a>, Transformer-based language models represent each token in a span of text as an <em>embedding vector</em>. It turns out that one can “pool” 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.',Pe,E,Ml="In this section we’ll 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.",Oe,v,rl='<img class="block dark:hidden" src="https://huggingface.co/datasets/huggingface-course/documentation-images/resolve/main/en/chapter5/semantic-search.svg" alt="Semantic search."/> <img class="hidden dark:block" src="https://huggingface.co/datasets/huggingface-course/documentation-images/resolve/main/en/chapter5/semantic-search-dark.svg" alt="Semantic search."/>',et,H,tt,A,cl="The first thing we need to do is download our dataset of GitHub issues, so let’s use <code>load_dataset()</code> function as usual:",lt,q,st,D,at,L,dl="Here we’ve specified the default <code>train</code> split in <code>load_dataset()</code>, so it returns a <code>Dataset</code> instead of a <code>DatasetDict</code>. 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 <code>Dataset.filter()</code> function to exclude these rows in our dataset. While we’re at it, let’s also filter out rows with no comments, since these provide no answers to user queries:",nt,K,it,P,ot,O,pl="We can see that there are a lot of columns in our dataset, most of which we don’t need to build our search engine. From a search perspective, the most informative columns are <code>title</code>, <code>body</code>, and <code>comments</code>, while <code>html_url</code> provides us with a link back to the source issue. Let’s use the <code>Dataset.remove_columns()</code> function to drop the rest:",Mt,ee,rt,te,ct,le,ml='To create our embeddings we’ll augment each comment with the issue’s title and body, since these fields often include useful contextual information. Because our <code>comments</code> column is currently a list of comments for each issue, we need to “explode” the column so that each row consists of an <code>(html_url, title, body, comment)</code> tuple. In Pandas we can do this with the <a href="https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.explode.html" rel="nofollow"><code>DataFrame.explode()</code> function</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’s first switch to the Pandas  <code>DataFrame</code> format:',dt,se,pt,ae,ul="If we inspect the first row in this <code>DataFrame</code> we can see there are four comments associated with this issue:",mt,ne,ut,ie,ht,oe,hl="When we explode <code>df</code>, we expect to get one row for each of these comments. Let’s check if that’s the case:",yt,Me,Ut,_,yl='<thead><tr style="text-align: right;"><th></th> <th>html_url</th> <th>title</th> <th>comments</th> <th>body</th></tr></thead> <tbody><tr><th>0</th> <td>https://github.com/huggingface/datasets/issues/2787</td> <td>ConnectionError: Couldn&#39;t reach https://raw.githubusercontent.com</td> <td>the bug code locate in ：\\r\\n    if data_args.task_name is not None...</td> <td>Hello,\\r\\nI am trying to run run_glue.py and it gives me this error...</td></tr> <tr><th>1</th> <td>https://github.com/huggingface/datasets/issues/2787</td> <td>ConnectionError: Couldn&#39;t reach https://raw.githubusercontent.com</td> <td>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...</td> <td>Hello,\\r\\nI am trying to run run_glue.py and it gives me this error...</td></tr> <tr><th>2</th> <td>https://github.com/huggingface/datasets/issues/2787</td> <td>ConnectionError: Couldn&#39;t reach https://raw.githubusercontent.com</td> <td>cannot connect，even by Web browser，please check that  there is some  problems。</td> <td>Hello,\\r\\nI am trying to run run_glue.py and it gives me this error...</td></tr> <tr><th>3</th> <td>https://github.com/huggingface/datasets/issues/2787</td> <td>ConnectionError: Couldn&#39;t reach https://raw.githubusercontent.com</td> <td>I can access https://raw.githubusercontent.com/huggingface/datasets/1.7.0/datasets/glue/glue.py without problem...</td> <td>Hello,\\r\\nI am trying to run run_glue.py and it gives me this error...</td></tr></tbody>',wt,re,Ul="Great, we can see the rows have been replicated, with the <code>comments</code> column containing the individual comments! Now that we’re finished with Pandas, we can quickly switch back to a <code>Dataset</code> by loading the <code>DataFrame</code> in memory:",Jt,ce,bt,de,ft,pe,wl="Okay, this has given us a few thousand comments to work with!",Tt,z,jt,me,Jl="Now that we have one comment per row, let’s create a new <code>comments_length</code> column that contains the number of words per comment:",gt,ue,Qt,he,bl="We can use this new column to filter out short comments, which typically include things like “cc @lewtun” or “Thanks!” that are not relevant for our search engine. There’s no precise number to select for the filter, but around 15 words seems like a good start:",Zt,ye,Gt,Ue,Ct,we,fl="Having cleaned up our dataset a bit, let’s concatenate the issue title, description, and comments together in a new <code>text</code> column. As usual, we’ll write a simple function that we can pass to <code>Dataset.map()</code>:",kt,Je,It,be,Tl="We’re finally ready to create some embeddings! Let’s take a look.",$t,fe,Rt,Te,jl='We saw in <a href="/course/chapter2">Chapter 2</a> that we can obtain token embeddings by using the <code>AutoModel</code> class. All we need to do is pick a suitable checkpoint to load the model from. Fortunately, there’s a library called <code>sentence-transformers</code> that is dedicated to creating embeddings. As described in the library’s <a href="https://www.sbert.net/examples/applications/semantic-search/README.html#symmetric-vs-asymmetric-semantic-search" rel="nofollow">documentation</a>, our use case is an example of <em>asymmetric semantic search</em> because we have a short query whose answer we’d like to find in a longer document, like a an issue comment. The handy <a href="https://www.sbert.net/docs/pretrained_models.html#model-overview" rel="nofollow">model overview table</a> in the documentation indicates that the <code>multi-qa-mpnet-base-dot-v1</code> checkpoint has the best performance for semantic search, so we’ll use that for our application. We’ll also load the tokenizer using the same checkpoint:',_t,N,x,Ee,je,gl="As we mentioned earlier, we’d like to represent each entry in our GitHub issues corpus as a single vector, so we need to “pool” or average our token embeddings in some way. One popular approach is to perform <em>CLS pooling</em> on our model’s outputs, where we simply collect the last hidden state for the special <code>[CLS]</code> token. The following function does the trick for us:",Nt,ge,xt,Qe,Ql="Next, we’ll 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:",Bt,B,W,He,Ze,Zl="Notice that we’ve converted the embeddings to NumPy arrays — that’s because 🤗 Datasets requires this format when we try to index them with FAISS, which we’ll do next.",Wt,Ge,Xt,Ce,Gl='Now that we have a dataset of embeddings, we need some way to search over them. To do this, we’ll use a special data structure in 🤗 Datasets called a <em>FAISS index</em>. <a href="https://faiss.ai/" rel="nofollow">FAISS</a> (short for Facebook AI Similarity Search) is a library that provides efficient algorithms to quickly search and cluster embedding vectors.',Vt,ke,Cl="The basic idea behind FAISS is to create a special data structure called an <em>index</em> that allows one to find which embeddings are similar to an input embedding. Creating a FAISS index in 🤗 Datasets is simple — we use the <code>Dataset.add_faiss_index()</code> function and specify which column of our dataset we’d like to index:",vt,Ie,zt,$e,kl="We can now perform queries on this index by doing a nearest neighbor lookup with the <code>Dataset.get_nearest_examples()</code> function. Let’s test this out by first embedding a question as follows:",Yt,X,V,Ae,Re,Il="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:",St,_e,Ft,Ne,$l="The <code>Dataset.get_nearest_examples()</code> 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’s collect these in a <code>pandas.DataFrame</code> so we can easily sort them:",Et,xe,Ht,Be,Rl="Now we can iterate over the first few rows to see how well our query matched the available comments:",At,We,qt,Xe,Dt,Ve,_l="Not bad! Our second hit seems to match the query.",Lt,Y,Kt,ve,Pt,qe,Ot;r=new ls({props:{fw:C[0]}}),G=new Le({props:{title:"Semantic search with FAISS",local:"semantic-search-with-faiss",headingTag:"h1"}});const Nl=[ns,as],ze=[];function xl(e,t){return e[0]==="pt"?0:1}Q=xl(C),Z=ze[Q]=Nl[Q](C),i=new ts({props:{id:"OATCgQtNX2o"}}),S=new Le({props:{title:"Using embeddings for semantic search",local:"using-embeddings-for-semantic-search",headingTag:"h2"}}),H=new Le({props:{title:"Loading and preparing the dataset",local:"loading-and-preparing-the-dataset",headingTag:"h2"}}),q=new f({props:{code:"ZnJvbSUyMGRhdGFzZXRzJTIwaW1wb3J0JTIwbG9hZF9kYXRhc2V0JTBBJTBBaXNzdWVzX2RhdGFzZXQlMjAlM0QlMjBsb2FkX2RhdGFzZXQoJTIybGV3dHVuJTJGZ2l0aHViLWlzc3VlcyUyMiUyQyUyMHNwbGl0JTNEJTIydHJhaW4lMjIpJTBBaXNzdWVzX2RhdGFzZXQ=",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`,wrap:!1}}),D=new f({props:{code:"RGF0YXNldCglN0IlMEElMjAlMjAlMjAlMjBmZWF0dXJlcyUzQSUyMCU1Qid1cmwnJTJDJTIwJ3JlcG9zaXRvcnlfdXJsJyUyQyUyMCdsYWJlbHNfdXJsJyUyQyUyMCdjb21tZW50c191cmwnJTJDJTIwJ2V2ZW50c191cmwnJTJDJTIwJ2h0bWxfdXJsJyUyQyUyMCdpZCclMkMlMjAnbm9kZV9pZCclMkMlMjAnbnVtYmVyJyUyQyUyMCd0aXRsZSclMkMlMjAndXNlciclMkMlMjAnbGFiZWxzJyUyQyUyMCdzdGF0ZSclMkMlMjAnbG9ja2VkJyUyQyUyMCdhc3NpZ25lZSclMkMlMjAnYXNzaWduZWVzJyUyQyUyMCdtaWxlc3RvbmUnJTJDJTIwJ2NvbW1lbnRzJyUyQyUyMCdjcmVhdGVkX2F0JyUyQyUyMCd1cGRhdGVkX2F0JyUyQyUyMCdjbG9zZWRfYXQnJTJDJTIwJ2F1dGhvcl9hc3NvY2lhdGlvbiclMkMlMjAnYWN0aXZlX2xvY2tfcmVhc29uJyUyQyUyMCdwdWxsX3JlcXVlc3QnJTJDJTIwJ2JvZHknJTJDJTIwJ3BlcmZvcm1lZF92aWFfZ2l0aHViX2FwcCclMkMlMjAnaXNfcHVsbF9yZXF1ZXN0JyU1RCUyQyUwQSUyMCUyMCUyMCUyMG51bV9yb3dzJTNBJTIwMjg1NSUwQSU3RCk=",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>
})`,wrap:!1}}),K=new f({props:{code:"aXNzdWVzX2RhdGFzZXQlMjAlM0QlMjBpc3N1ZXNfZGF0YXNldC5maWx0ZXIoJTBBJTIwJTIwJTIwJTIwbGFtYmRhJTIweCUzQSUyMCh4JTVCJTIyaXNfcHVsbF9yZXF1ZXN0JTIyJTVEJTIwJTNEJTNEJTIwRmFsc2UlMjBhbmQlMjBsZW4oeCU1QiUyMmNvbW1lbnRzJTIyJTVEKSUyMCUzRSUyMDApJTBBKSUwQWlzc3Vlc19kYXRhc2V0",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`,wrap:!1}}),P=new f({props:{code:"RGF0YXNldCglN0IlMEElMjAlMjAlMjAlMjBmZWF0dXJlcyUzQSUyMCU1Qid1cmwnJTJDJTIwJ3JlcG9zaXRvcnlfdXJsJyUyQyUyMCdsYWJlbHNfdXJsJyUyQyUyMCdjb21tZW50c191cmwnJTJDJTIwJ2V2ZW50c191cmwnJTJDJTIwJ2h0bWxfdXJsJyUyQyUyMCdpZCclMkMlMjAnbm9kZV9pZCclMkMlMjAnbnVtYmVyJyUyQyUyMCd0aXRsZSclMkMlMjAndXNlciclMkMlMjAnbGFiZWxzJyUyQyUyMCdzdGF0ZSclMkMlMjAnbG9ja2VkJyUyQyUyMCdhc3NpZ25lZSclMkMlMjAnYXNzaWduZWVzJyUyQyUyMCdtaWxlc3RvbmUnJTJDJTIwJ2NvbW1lbnRzJyUyQyUyMCdjcmVhdGVkX2F0JyUyQyUyMCd1cGRhdGVkX2F0JyUyQyUyMCdjbG9zZWRfYXQnJTJDJTIwJ2F1dGhvcl9hc3NvY2lhdGlvbiclMkMlMjAnYWN0aXZlX2xvY2tfcmVhc29uJyUyQyUyMCdwdWxsX3JlcXVlc3QnJTJDJTIwJ2JvZHknJTJDJTIwJ3BlcmZvcm1lZF92aWFfZ2l0aHViX2FwcCclMkMlMjAnaXNfcHVsbF9yZXF1ZXN0JyU1RCUyQyUwQSUyMCUyMCUyMCUyMG51bV9yb3dzJTNBJTIwNzcxJTBBJTdEKQ==",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>
})`,wrap:!1}}),ee=new f({props:{code:"Y29sdW1ucyUyMCUzRCUyMGlzc3Vlc19kYXRhc2V0LmNvbHVtbl9uYW1lcyUwQWNvbHVtbnNfdG9fa2VlcCUyMCUzRCUyMCU1QiUyMnRpdGxlJTIyJTJDJTIwJTIyYm9keSUyMiUyQyUyMCUyMmh0bWxfdXJsJTIyJTJDJTIwJTIyY29tbWVudHMlMjIlNUQlMEFjb2x1bW5zX3RvX3JlbW92ZSUyMCUzRCUyMHNldChjb2x1bW5zX3RvX2tlZXApLnN5bW1ldHJpY19kaWZmZXJlbmNlKGNvbHVtbnMpJTBBaXNzdWVzX2RhdGFzZXQlMjAlM0QlMjBpc3N1ZXNfZGF0YXNldC5yZW1vdmVfY29sdW1ucyhjb2x1bW5zX3RvX3JlbW92ZSklMEFpc3N1ZXNfZGF0YXNldA==",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`,wrap:!1}}),te=new f({props:{code:"RGF0YXNldCglN0IlMEElMjAlMjAlMjAlMjBmZWF0dXJlcyUzQSUyMCU1QidodG1sX3VybCclMkMlMjAndGl0bGUnJTJDJTIwJ2NvbW1lbnRzJyUyQyUyMCdib2R5JyU1RCUyQyUwQSUyMCUyMCUyMCUyMG51bV9yb3dzJTNBJTIwNzcxJTBBJTdEKQ==",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>
})`,wrap:!1}}),se=new f({props:{code:"aXNzdWVzX2RhdGFzZXQuc2V0X2Zvcm1hdCglMjJwYW5kYXMlMjIpJTBBZGYlMjAlM0QlMjBpc3N1ZXNfZGF0YXNldCU1QiUzQSU1RA==",highlighted:`issues_dataset.set_format(<span class="hljs-string">&quot;pandas&quot;</span>)
df = issues_dataset[:]`,wrap:!1}}),ne=new f({props:{code:"ZGYlNUIlMjJjb21tZW50cyUyMiU1RCU1QjAlNUQudG9saXN0KCk=",highlighted:'df[<span class="hljs-string">&quot;comments&quot;</span>][<span class="hljs-number">0</span>].tolist()',wrap:!1}}),ie=new f({props:{code:"JTVCJ3RoZSUyMGJ1ZyUyMGNvZGUlMjBsb2NhdGUlMjBpbiUyMCVFRiVCQyU5QSU1Q3IlNUNuJTIwJTIwJTIwJTIwaWYlMjBkYXRhX2FyZ3MudGFza19uYW1lJTIwaXMlMjBub3QlMjBOb25lJTNBJTVDciU1Q24lMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjMlMjBEb3dubG9hZGluZyUyMGFuZCUyMGxvYWRpbmclMjBhJTIwZGF0YXNldCUyMGZyb20lMjB0aGUlMjBodWIuJTVDciU1Q24lMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBkYXRhc2V0cyUyMCUzRCUyMGxvYWRfZGF0YXNldCglMjJnbHVlJTIyJTJDJTIwZGF0YV9hcmdzLnRhc2tfbmFtZSUyQyUyMGNhY2hlX2RpciUzRG1vZGVsX2FyZ3MuY2FjaGVfZGlyKSclMkMlMEElMjAnSGklMjAlNDBqaW5lYyUyQyU1Q3IlNUNuJTVDciU1Q25Gcm9tJTIwdGltZSUyMHRvJTIwdGltZSUyMHdlJTIwZ2V0JTIwdGhpcyUyMGtpbmQlMjBvZiUyMCU2MENvbm5lY3Rpb25FcnJvciU2MCUyMGNvbWluZyUyMGZyb20lMjB0aGUlMjBnaXRodWIuY29tJTIwd2Vic2l0ZSUzQSUyMGh0dHBzJTNBJTJGJTJGcmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSU1Q3IlNUNuJTVDciU1Q25Ob3JtYWxseSUyQyUyMGl0JTIwc2hvdWxkJTIwd29yayUyMGlmJTIweW91JTIwd2FpdCUyMGElMjBsaXR0bGUlMjBhbmQlMjB0aGVuJTIwcmV0cnkuJTVDciU1Q24lNUNyJTVDbkNvdWxkJTIweW91JTIwcGxlYXNlJTIwY29uZmlybSUyMGlmJTIwdGhlJTIwcHJvYmxlbSUyMHBlcnNpc3RzJTNGJyUyQyUwQSUyMCdjYW5ub3QlMjBjb25uZWN0JUVGJUJDJThDZXZlbiUyMGJ5JTIwV2ViJTIwYnJvd3NlciVFRiVCQyU4Q3BsZWFzZSUyMGNoZWNrJTIwdGhhdCUyMCUyMHRoZXJlJTIwaXMlMjBzb21lJTIwJTIwcHJvYmxlbXMlRTMlODAlODInJTJDJTBBJTIwJ0klMjBjYW4lMjBhY2Nlc3MlMjBodHRwcyUzQSUyRiUyRnJhdy5naXRodWJ1c2VyY29udGVudC5jb20lMkZodWdnaW5nZmFjZSUyRmRhdGFzZXRzJTJGMS43LjAlMkZkYXRhc2V0cyUyRmdsdWUlMkZnbHVlLnB5JTIwd2l0aG91dCUyMHByb2JsZW0uLi4nJTVE",highlighted:`[<span class="hljs-string">&#x27;the bug code locate in ：\\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，even by Web browser，please check that  there is some  problems。&#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>]`,wrap:!1}}),Me=new f({props:{code:"Y29tbWVudHNfZGYlMjAlM0QlMjBkZi5leHBsb2RlKCUyMmNvbW1lbnRzJTIyJTJDJTIwaWdub3JlX2luZGV4JTNEVHJ1ZSklMEFjb21tZW50c19kZi5oZWFkKDQp",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>)`,wrap:!1}}),ce=new f({props:{code:"ZnJvbSUyMGRhdGFzZXRzJTIwaW1wb3J0JTIwRGF0YXNldCUwQSUwQWNvbW1lbnRzX2RhdGFzZXQlMjAlM0QlMjBEYXRhc2V0LmZyb21fcGFuZGFzKGNvbW1lbnRzX2RmKSUwQWNvbW1lbnRzX2RhdGFzZXQ=",highlighted:`<span class="hljs-keyword">from</span> datasets <span class="hljs-keyword">import</span> Dataset

comments_dataset = Dataset.from_pandas(comments_df)
comments_dataset`,wrap:!1}}),de=new f({props:{code:"RGF0YXNldCglN0IlMEElMjAlMjAlMjAlMjBmZWF0dXJlcyUzQSUyMCU1QidodG1sX3VybCclMkMlMjAndGl0bGUnJTJDJTIwJ2NvbW1lbnRzJyUyQyUyMCdib2R5JyU1RCUyQyUwQSUyMCUyMCUyMCUyMG51bV9yb3dzJTNBJTIwMjg0MiUwQSU3RCk=",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>
})`,wrap:!1}}),z=new Hl({props:{$$slots:{default:[is]},$$scope:{ctx:C}}}),ue=new f({props:{code:"Y29tbWVudHNfZGF0YXNldCUyMCUzRCUyMGNvbW1lbnRzX2RhdGFzZXQubWFwKCUwQSUyMCUyMCUyMCUyMGxhbWJkYSUyMHglM0ElMjAlN0IlMjJjb21tZW50X2xlbmd0aCUyMiUzQSUyMGxlbih4JTVCJTIyY29tbWVudHMlMjIlNUQuc3BsaXQoKSklN0QlMEEp",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())}
)`,wrap:!1}}),ye=new f({props:{code:"Y29tbWVudHNfZGF0YXNldCUyMCUzRCUyMGNvbW1lbnRzX2RhdGFzZXQuZmlsdGVyKGxhbWJkYSUyMHglM0ElMjB4JTVCJTIyY29tbWVudF9sZW5ndGglMjIlNUQlMjAlM0UlMjAxNSklMEFjb21tZW50c19kYXRhc2V0",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`,wrap:!1}}),Ue=new f({props:{code:"RGF0YXNldCglN0IlMEElMjAlMjAlMjAlMjBmZWF0dXJlcyUzQSUyMCU1QidodG1sX3VybCclMkMlMjAndGl0bGUnJTJDJTIwJ2NvbW1lbnRzJyUyQyUyMCdib2R5JyUyQyUyMCdjb21tZW50X2xlbmd0aCclNUQlMkMlMEElMjAlMjAlMjAlMjBudW1fcm93cyUzQSUyMDIwOTglMEElN0Qp",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>
})`,wrap:!1}}),Je=new f({props:{code:"ZGVmJTIwY29uY2F0ZW5hdGVfdGV4dChleGFtcGxlcyklM0ElMEElMjAlMjAlMjAlMjByZXR1cm4lMjAlN0IlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjJ0ZXh0JTIyJTNBJTIwZXhhbXBsZXMlNUIlMjJ0aXRsZSUyMiU1RCUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyQiUyMCUyMiUyMCU1Q24lMjAlMjIlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMkIlMjBleGFtcGxlcyU1QiUyMmJvZHklMjIlNUQlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMkIlMjAlMjIlMjAlNUNuJTIwJTIyJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTJCJTIwZXhhbXBsZXMlNUIlMjJjb21tZW50cyUyMiU1RCUwQSUyMCUyMCUyMCUyMCU3RCUwQSUwQSUwQWNvbW1lbnRzX2RhdGFzZXQlMjAlM0QlMjBjb21tZW50c19kYXRhc2V0Lm1hcChjb25jYXRlbmF0ZV90ZXh0KQ==",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)`,wrap:!1}}),fe=new Le({props:{title:"Creating text embeddings",local:"creating-text-embeddings",headingTag:"h2"}});const Bl=[Ms,os],Ye=[];function Wl(e,t){return e[0]==="pt"?0:1}N=Wl(C),x=Ye[N]=Bl[N](C),ge=new f({props:{code:"ZGVmJTIwY2xzX3Bvb2xpbmcobW9kZWxfb3V0cHV0KSUzQSUwQSUyMCUyMCUyMCUyMHJldHVybiUyMG1vZGVsX291dHB1dC5sYXN0X2hpZGRlbl9zdGF0ZSU1QiUzQSUyQyUyMDAlNUQ=",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>]`,wrap:!1}});const Xl=[cs,rs],Se=[];function Vl(e,t){return e[0]==="pt"?0:1}B=Vl(C),W=Se[B]=Xl[B](C),Ge=new Le({props:{title:"Using FAISS for efficient similarity search",local:"using-faiss-for-efficient-similarity-search",headingTag:"h2"}}),Ie=new f({props:{code:"ZW1iZWRkaW5nc19kYXRhc2V0LmFkZF9mYWlzc19pbmRleChjb2x1bW4lM0QlMjJlbWJlZGRpbmdzJTIyKQ==",highlighted:'embeddings_dataset.add_faiss_index(column=<span class="hljs-string">&quot;embeddings&quot;</span>)',wrap:!1}});const vl=[ps,ds],Fe=[];function zl(e,t){return e[0]==="pt"?0:1}return X=zl(C),V=Fe[X]=vl[X](C),_e=new f({props:{code:"c2NvcmVzJTJDJTIwc2FtcGxlcyUyMCUzRCUyMGVtYmVkZGluZ3NfZGF0YXNldC5nZXRfbmVhcmVzdF9leGFtcGxlcyglMEElMjAlMjAlMjAlMjAlMjJlbWJlZGRpbmdzJTIyJTJDJTIwcXVlc3Rpb25fZW1iZWRkaW5nJTJDJTIwayUzRDUlMEEp",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>
)`,wrap:!1}}),xe=new f({props:{code:"aW1wb3J0JTIwcGFuZGFzJTIwYXMlMjBwZCUwQSUwQXNhbXBsZXNfZGYlMjAlM0QlMjBwZC5EYXRhRnJhbWUuZnJvbV9kaWN0KHNhbXBsZXMpJTBBc2FtcGxlc19kZiU1QiUyMnNjb3JlcyUyMiU1RCUyMCUzRCUyMHNjb3JlcyUwQXNhbXBsZXNfZGYuc29ydF92YWx1ZXMoJTIyc2NvcmVzJTIyJTJDJTIwYXNjZW5kaW5nJTNERmFsc2UlMkMlMjBpbnBsYWNlJTNEVHJ1ZSk=",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>)`,wrap:!1}}),We=new f({props:{code:"Zm9yJTIwXyUyQyUyMHJvdyUyMGluJTIwc2FtcGxlc19kZi5pdGVycm93cygpJTNBJTBBJTIwJTIwJTIwJTIwcHJpbnQoZiUyMkNPTU1FTlQlM0ElMjAlN0Jyb3cuY29tbWVudHMlN0QlMjIpJTBBJTIwJTIwJTIwJTIwcHJpbnQoZiUyMlNDT1JFJTNBJTIwJTdCcm93LnNjb3JlcyU3RCUyMiklMEElMjAlMjAlMjAlMjBwcmludChmJTIyVElUTEUlM0ElMjAlN0Jyb3cudGl0bGUlN0QlMjIpJTBBJTIwJTIwJTIwJTIwcHJpbnQoZiUyMlVSTCUzQSUyMCU3QnJvdy5odG1sX3VybCU3RCUyMiklMEElMjAlMjAlMjAlMjBwcmludCglMjIlM0QlMjIlMjAqJTIwNTApJTBBJTIwJTIwJTIwJTIwcHJpbnQoKQ==",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>()`,wrap:!1}}),Xe=new f({props:{code:" ",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>`,wrap:!1}}),Y=new Hl({props:{$$slots:{default:[ms]},$$scope:{ctx:C}}}),ve=new ss({props:{source:"https://github.com/huggingface/course/blob/main/chapters/en/chapter5/6.mdx"}}),{c(){a=J("meta"),p=o(),n=J("p"),T=o(),u(r.$$.fragment),m=o(),u(G.$$.fragment),w=o(),Z.c(),R=o(),I=J("p"),I.innerHTML=k,$=o(),u(i.$$.fragment),g=o(),u(S.$$.fragment),Ke=o(),F=J("p"),F.innerHTML=ol,Pe=o(),E=J("p"),E.textContent=Ml,Oe=o(),v=J("div"),v.innerHTML=rl,et=o(),u(H.$$.fragment),tt=o(),A=J("p"),A.innerHTML=cl,lt=o(),u(q.$$.fragment),st=o(),u(D.$$.fragment),at=o(),L=J("p"),L.innerHTML=dl,nt=o(),u(K.$$.fragment),it=o(),u(P.$$.fragment),ot=o(),O=J("p"),O.innerHTML=pl,Mt=o(),u(ee.$$.fragment),rt=o(),u(te.$$.fragment),ct=o(),le=J("p"),le.innerHTML=ml,dt=o(),u(se.$$.fragment),pt=o(),ae=J("p"),ae.innerHTML=ul,mt=o(),u(ne.$$.fragment),ut=o(),u(ie.$$.fragment),ht=o(),oe=J("p"),oe.innerHTML=hl,yt=o(),u(Me.$$.fragment),Ut=o(),_=J("table"),_.innerHTML=yl,wt=o(),re=J("p"),re.innerHTML=Ul,Jt=o(),u(ce.$$.fragment),bt=o(),u(de.$$.fragment),ft=o(),pe=J("p"),pe.textContent=wl,Tt=o(),u(z.$$.fragment),jt=o(),me=J("p"),me.innerHTML=Jl,gt=o(),u(ue.$$.fragment),Qt=o(),he=J("p"),he.textContent=bl,Zt=o(),u(ye.$$.fragment),Gt=o(),u(Ue.$$.fragment),Ct=o(),we=J("p"),we.innerHTML=fl,kt=o(),u(Je.$$.fragment),It=o(),be=J("p"),be.textContent=Tl,$t=o(),u(fe.$$.fragment),Rt=o(),Te=J("p"),Te.innerHTML=jl,_t=o(),x.c(),Ee=o(),je=J("p"),je.innerHTML=gl,Nt=o(),u(ge.$$.fragment),xt=o(),Qe=J("p"),Qe.textContent=Ql,Bt=o(),W.c(),He=o(),Ze=J("p"),Ze.textContent=Zl,Wt=o(),u(Ge.$$.fragment),Xt=o(),Ce=J("p"),Ce.innerHTML=Gl,Vt=o(),ke=J("p"),ke.innerHTML=Cl,vt=o(),u(Ie.$$.fragment),zt=o(),$e=J("p"),$e.innerHTML=kl,Yt=o(),V.c(),Ae=o(),Re=J("p"),Re.textContent=Il,St=o(),u(_e.$$.fragment),Ft=o(),Ne=J("p"),Ne.innerHTML=$l,Et=o(),u(xe.$$.fragment),Ht=o(),Be=J("p"),Be.textContent=Rl,At=o(),u(We.$$.fragment),qt=o(),u(Xe.$$.fragment),Dt=o(),Ve=J("p"),Ve.textContent=_l,Lt=o(),u(Y.$$.fragment),Kt=o(),u(ve.$$.fragment),Pt=o(),qe=J("p"),this.h()},l(e){const t=Ol("svelte-u9bgzb",document.head);a=b(t,"META",{name:!0,content:!0}),t.forEach(l),p=M(e),n=b(e,"P",{}),El(n).forEach(l),T=M(e),h(r.$$.fragment,e),m=M(e),h(G.$$.fragment,e),w=M(e),Z.l(e),R=M(e),I=b(e,"P",{"data-svelte-h":!0}),j(I)!=="svelte-x8t0is"&&(I.innerHTML=k),$=M(e),h(i.$$.fragment,e),g=M(e),h(S.$$.fragment,e),Ke=M(e),F=b(e,"P",{"data-svelte-h":!0}),j(F)!=="svelte-1o2ff16"&&(F.innerHTML=ol),Pe=M(e),E=b(e,"P",{"data-svelte-h":!0}),j(E)!=="svelte-s1v4o8"&&(E.textContent=Ml),Oe=M(e),v=b(e,"DIV",{class:!0,"data-svelte-h":!0}),j(v)!=="svelte-yxatr"&&(v.innerHTML=rl),et=M(e),h(H.$$.fragment,e),tt=M(e),A=b(e,"P",{"data-svelte-h":!0}),j(A)!=="svelte-dttrye"&&(A.innerHTML=cl),lt=M(e),h(q.$$.fragment,e),st=M(e),h(D.$$.fragment,e),at=M(e),L=b(e,"P",{"data-svelte-h":!0}),j(L)!=="svelte-snpg6v"&&(L.innerHTML=dl),nt=M(e),h(K.$$.fragment,e),it=M(e),h(P.$$.fragment,e),ot=M(e),O=b(e,"P",{"data-svelte-h":!0}),j(O)!=="svelte-1k5h1so"&&(O.innerHTML=pl),Mt=M(e),h(ee.$$.fragment,e),rt=M(e),h(te.$$.fragment,e),ct=M(e),le=b(e,"P",{"data-svelte-h":!0}),j(le)!=="svelte-a4bqz"&&(le.innerHTML=ml),dt=M(e),h(se.$$.fragment,e),pt=M(e),ae=b(e,"P",{"data-svelte-h":!0}),j(ae)!=="svelte-1j8nktv"&&(ae.innerHTML=ul),mt=M(e),h(ne.$$.fragment,e),ut=M(e),h(ie.$$.fragment,e),ht=M(e),oe=b(e,"P",{"data-svelte-h":!0}),j(oe)!=="svelte-1z9n9m"&&(oe.innerHTML=hl),yt=M(e),h(Me.$$.fragment,e),Ut=M(e),_=b(e,"TABLE",{border:!0,class:!0,style:!0,"data-svelte-h":!0}),j(_)!=="svelte-1g5whzd"&&(_.innerHTML=yl),wt=M(e),re=b(e,"P",{"data-svelte-h":!0}),j(re)!=="svelte-nn2zp6"&&(re.innerHTML=Ul),Jt=M(e),h(ce.$$.fragment,e),bt=M(e),h(de.$$.fragment,e),ft=M(e),pe=b(e,"P",{"data-svelte-h":!0}),j(pe)!=="svelte-1iu9xg3"&&(pe.textContent=wl),Tt=M(e),h(z.$$.fragment,e),jt=M(e),me=b(e,"P",{"data-svelte-h":!0}),j(me)!=="svelte-gtnurf"&&(me.innerHTML=Jl),gt=M(e),h(ue.$$.fragment,e),Qt=M(e),he=b(e,"P",{"data-svelte-h":!0}),j(he)!=="svelte-gxus05"&&(he.textContent=bl),Zt=M(e),h(ye.$$.fragment,e),Gt=M(e),h(Ue.$$.fragment,e),Ct=M(e),we=b(e,"P",{"data-svelte-h":!0}),j(we)!=="svelte-1gpu2kt"&&(we.innerHTML=fl),kt=M(e),h(Je.$$.fragment,e),It=M(e),be=b(e,"P",{"data-svelte-h":!0}),j(be)!=="svelte-1vac1i6"&&(be.textContent=Tl),$t=M(e),h(fe.$$.fragment,e),Rt=M(e),Te=b(e,"P",{"data-svelte-h":!0}),j(Te)!=="svelte-1ug85qi"&&(Te.innerHTML=jl),_t=M(e),x.l(e),Ee=M(e),je=b(e,"P",{"data-svelte-h":!0}),j(je)!=="svelte-wm9gvo"&&(je.innerHTML=gl),Nt=M(e),h(ge.$$.fragment,e),xt=M(e),Qe=b(e,"P",{"data-svelte-h":!0}),j(Qe)!=="svelte-10gf7d0"&&(Qe.textContent=Ql),Bt=M(e),W.l(e),He=M(e),Ze=b(e,"P",{"data-svelte-h":!0}),j(Ze)!=="svelte-ft8b80"&&(Ze.textContent=Zl),Wt=M(e),h(Ge.$$.fragment,e),Xt=M(e),Ce=b(e,"P",{"data-svelte-h":!0}),j(Ce)!=="svelte-r92oxb"&&(Ce.innerHTML=Gl),Vt=M(e),ke=b(e,"P",{"data-svelte-h":!0}),j(ke)!=="svelte-92fmoe"&&(ke.innerHTML=Cl),vt=M(e),h(Ie.$$.fragment,e),zt=M(e),$e=b(e,"P",{"data-svelte-h":!0}),j($e)!=="svelte-1rt01ml"&&($e.innerHTML=kl),Yt=M(e),V.l(e),Ae=M(e),Re=b(e,"P",{"data-svelte-h":!0}),j(Re)!=="svelte-lxeh2g"&&(Re.textContent=Il),St=M(e),h(_e.$$.fragment,e),Ft=M(e),Ne=b(e,"P",{"data-svelte-h":!0}),j(Ne)!=="svelte-pvgl7e"&&(Ne.innerHTML=$l),Et=M(e),h(xe.$$.fragment,e),Ht=M(e),Be=b(e,"P",{"data-svelte-h":!0}),j(Be)!=="svelte-brolnw"&&(Be.textContent=Rl),At=M(e),h(We.$$.fragment,e),qt=M(e),h(Xe.$$.fragment,e),Dt=M(e),Ve=b(e,"P",{"data-svelte-h":!0}),j(Ve)!=="svelte-cnuz8o"&&(Ve.textContent=_l),Lt=M(e),h(Y.$$.fragment,e),Kt=M(e),h(ve.$$.fragment,e),Pt=M(e),qe=b(e,"P",{}),El(qe).forEach(l),this.h()},h(){De(a,"name","hf:doc:metadata"),De(a,"content",hs),De(v,"class","flex justify-center"),De(_,"border","1"),De(_,"class","dataframe"),il(_,"table-layout","fixed"),il(_,"word-wrap","break-word"),il(_,"width","100%")},m(e,t){es(document.head,a),s(e,p,t),s(e,n,t),s(e,T,t),y(r,e,t),s(e,m,t),y(G,e,t),s(e,w,t),ze[Q].m(e,t),s(e,R,t),s(e,I,t),s(e,$,t),y(i,e,t),s(e,g,t),y(S,e,t),s(e,Ke,t),s(e,F,t),s(e,Pe,t),s(e,E,t),s(e,Oe,t),s(e,v,t),s(e,et,t),y(H,e,t),s(e,tt,t),s(e,A,t),s(e,lt,t),y(q,e,t),s(e,st,t),y(D,e,t),s(e,at,t),s(e,L,t),s(e,nt,t),y(K,e,t),s(e,it,t),y(P,e,t),s(e,ot,t),s(e,O,t),s(e,Mt,t),y(ee,e,t),s(e,rt,t),y(te,e,t),s(e,ct,t),s(e,le,t),s(e,dt,t),y(se,e,t),s(e,pt,t),s(e,ae,t),s(e,mt,t),y(ne,e,t),s(e,ut,t),y(ie,e,t),s(e,ht,t),s(e,oe,t),s(e,yt,t),y(Me,e,t),s(e,Ut,t),s(e,_,t),s(e,wt,t),s(e,re,t),s(e,Jt,t),y(ce,e,t),s(e,bt,t),y(de,e,t),s(e,ft,t),s(e,pe,t),s(e,Tt,t),y(z,e,t),s(e,jt,t),s(e,me,t),s(e,gt,t),y(ue,e,t),s(e,Qt,t),s(e,he,t),s(e,Zt,t),y(ye,e,t),s(e,Gt,t),y(Ue,e,t),s(e,Ct,t),s(e,we,t),s(e,kt,t),y(Je,e,t),s(e,It,t),s(e,be,t),s(e,$t,t),y(fe,e,t),s(e,Rt,t),s(e,Te,t),s(e,_t,t),Ye[N].m(e,t),s(e,Ee,t),s(e,je,t),s(e,Nt,t),y(ge,e,t),s(e,xt,t),s(e,Qe,t),s(e,Bt,t),Se[B].m(e,t),s(e,He,t),s(e,Ze,t),s(e,Wt,t),y(Ge,e,t),s(e,Xt,t),s(e,Ce,t),s(e,Vt,t),s(e,ke,t),s(e,vt,t),y(Ie,e,t),s(e,zt,t),s(e,$e,t),s(e,Yt,t),Fe[X].m(e,t),s(e,Ae,t),s(e,Re,t),s(e,St,t),y(_e,e,t),s(e,Ft,t),s(e,Ne,t),s(e,Et,t),y(xe,e,t),s(e,Ht,t),s(e,Be,t),s(e,At,t),y(We,e,t),s(e,qt,t),y(Xe,e,t),s(e,Dt,t),s(e,Ve,t),s(e,Lt,t),y(Y,e,t),s(e,Kt,t),y(ve,e,t),s(e,Pt,t),s(e,qe,t),Ot=!0},p(e,[t]){const Yl={};t&1&&(Yl.fw=e[0]),r.$set(Yl);let ll=Q;Q=xl(e),Q!==ll&&(tl(),c(ze[ll],1,1,()=>{ze[ll]=null}),el(),Z=ze[Q],Z||(Z=ze[Q]=Nl[Q](e),Z.c()),d(Z,1),Z.m(R.parentNode,R));const Sl={};t&2&&(Sl.$$scope={dirty:t,ctx:e}),z.$set(Sl);let sl=N;N=Wl(e),N!==sl&&(tl(),c(Ye[sl],1,1,()=>{Ye[sl]=null}),el(),x=Ye[N],x||(x=Ye[N]=Bl[N](e),x.c()),d(x,1),x.m(Ee.parentNode,Ee));let al=B;B=Vl(e),B!==al&&(tl(),c(Se[al],1,1,()=>{Se[al]=null}),el(),W=Se[B],W||(W=Se[B]=Xl[B](e),W.c()),d(W,1),W.m(He.parentNode,He));let nl=X;X=zl(e),X!==nl&&(tl(),c(Fe[nl],1,1,()=>{Fe[nl]=null}),el(),V=Fe[X],V||(V=Fe[X]=vl[X](e),V.c()),d(V,1),V.m(Ae.parentNode,Ae));const Fl={};t&2&&(Fl.$$scope={dirty:t,ctx:e}),Y.$set(Fl)},i(e){Ot||(d(r.$$.fragment,e),d(G.$$.fragment,e),d(Z),d(i.$$.fragment,e),d(S.$$.fragment,e),d(H.$$.fragment,e),d(q.$$.fragment,e),d(D.$$.fragment,e),d(K.$$.fragment,e),d(P.$$.fragment,e),d(ee.$$.fragment,e),d(te.$$.fragment,e),d(se.$$.fragment,e),d(ne.$$.fragment,e),d(ie.$$.fragment,e),d(Me.$$.fragment,e),d(ce.$$.fragment,e),d(de.$$.fragment,e),d(z.$$.fragment,e),d(ue.$$.fragment,e),d(ye.$$.fragment,e),d(Ue.$$.fragment,e),d(Je.$$.fragment,e),d(fe.$$.fragment,e),d(x),d(ge.$$.fragment,e),d(W),d(Ge.$$.fragment,e),d(Ie.$$.fragment,e),d(V),d(_e.$$.fragment,e),d(xe.$$.fragment,e),d(We.$$.fragment,e),d(Xe.$$.fragment,e),d(Y.$$.fragment,e),d(ve.$$.fragment,e),Ot=!0)},o(e){c(r.$$.fragment,e),c(G.$$.fragment,e),c(Z),c(i.$$.fragment,e),c(S.$$.fragment,e),c(H.$$.fragment,e),c(q.$$.fragment,e),c(D.$$.fragment,e),c(K.$$.fragment,e),c(P.$$.fragment,e),c(ee.$$.fragment,e),c(te.$$.fragment,e),c(se.$$.fragment,e),c(ne.$$.fragment,e),c(ie.$$.fragment,e),c(Me.$$.fragment,e),c(ce.$$.fragment,e),c(de.$$.fragment,e),c(z.$$.fragment,e),c(ue.$$.fragment,e),c(ye.$$.fragment,e),c(Ue.$$.fragment,e),c(Je.$$.fragment,e),c(fe.$$.fragment,e),c(x),c(ge.$$.fragment,e),c(W),c(Ge.$$.fragment,e),c(Ie.$$.fragment,e),c(V),c(_e.$$.fragment,e),c(xe.$$.fragment,e),c(We.$$.fragment,e),c(Xe.$$.fragment,e),c(Y.$$.fragment,e),c(ve.$$.fragment,e),Ot=!1},d(e){e&&(l(p),l(n),l(T),l(m),l(w),l(R),l(I),l($),l(g),l(Ke),l(F),l(Pe),l(E),l(Oe),l(v),l(et),l(tt),l(A),l(lt),l(st),l(at),l(L),l(nt),l(it),l(ot),l(O),l(Mt),l(rt),l(ct),l(le),l(dt),l(pt),l(ae),l(mt),l(ut),l(ht),l(oe),l(yt),l(Ut),l(_),l(wt),l(re),l(Jt),l(bt),l(ft),l(pe),l(Tt),l(jt),l(me),l(gt),l(Qt),l(he),l(Zt),l(Gt),l(Ct),l(we),l(kt),l(It),l(be),l($t),l(Rt),l(Te),l(_t),l(Ee),l(je),l(Nt),l(xt),l(Qe),l(Bt),l(He),l(Ze),l(Wt),l(Xt),l(Ce),l(Vt),l(ke),l(vt),l(zt),l($e),l(Yt),l(Ae),l(Re),l(St),l(Ft),l(Ne),l(Et),l(Ht),l(Be),l(At),l(qt),l(Dt),l(Ve),l(Lt),l(Kt),l(Pt),l(qe)),l(a),U(r,e),U(G,e),ze[Q].d(e),U(i,e),U(S,e),U(H,e),U(q,e),U(D,e),U(K,e),U(P,e),U(ee,e),U(te,e),U(se,e),U(ne,e),U(ie,e),U(Me,e),U(ce,e),U(de,e),U(z,e),U(ue,e),U(ye,e),U(Ue,e),U(Je,e),U(fe,e),Ye[N].d(e),U(ge,e),Se[B].d(e),U(Ge,e),U(Ie,e),Fe[X].d(e),U(_e,e),U(xe,e),U(We,e),U(Xe,e),U(Y,e),U(ve,e)}}}const hs='{"title":"Semantic search with FAISS","local":"semantic-search-with-faiss","sections":[{"title":"Using embeddings for semantic search","local":"using-embeddings-for-semantic-search","sections":[],"depth":2},{"title":"Loading and preparing the dataset","local":"loading-and-preparing-the-dataset","sections":[],"depth":2},{"title":"Creating text embeddings","local":"creating-text-embeddings","sections":[],"depth":2},{"title":"Using FAISS for efficient similarity search","local":"using-faiss-for-efficient-similarity-search","sections":[],"depth":2}],"depth":1}';function ys(C,a,p){let n="pt";return Ll(()=>{const T=new URLSearchParams(window.location.search);p(0,n=T.get("fw")||"pt")}),[n]}class Qs extends Kl{constructor(a){super(),Pl(this,a,ys,us,Dl,{})}}export{Qs as component};
