import{s as Kl,o as Pl,n as Dl}from"../chunks/scheduler.cc52f4b9.js";import{S as Ol,i as es,e as J,s as o,c as u,h as ts,a as b,d as l,b as M,f as Al,g as h,j,k as Le,v as Ml,l as ls,m as s,n as y,o as c,E as ll,t as d,p as U,F as sl}from"../chunks/index.5b747fde.js";import{T as ql}from"../chunks/Tip.f0925d57.js";import{C as ss,H as Ke,E as as}from"../chunks/MermaidChart.svelte_svelte_type_style_lang.d38ac5a9.js";import{Y as ns}from"../chunks/Youtube.8bb4154e.js";import{C as f}from"../chunks/CodeBlock.665bfc37.js";import{C as Ll}from"../chunks/CourseFloatingBanner.b33fcd79.js";import{F as is}from"../chunks/FrameworkSwitchCourse.b3b657b3.js";function os(Z){let a,p;return a=new Ll({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 Ms(Z){let a,p;return a=new Ll({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 rs(Z){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:Dl,d(n){n&&l(a)}}}function cs(Z){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,Q){y(a,m,Q),s(m,p,Q),s(m,n,Q),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 ds(Z){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,Q;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,G){y(a,w,G),s(w,p,G),s(w,n,G),s(w,r,G),y(m,w,G),Q=!0},i(w){Q||(d(a.$$.fragment,w),d(m.$$.fragment,w),Q=!0)},o(w){c(a.$$.fragment,w),c(m.$$.fragment,w),Q=!1},d(w){w&&(l(p),l(n),l(r)),U(a,w),U(m,w)}}}function ps(Z){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,Q,w,G,I,$="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:",k,C,R;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}}),C=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),Q=o(),u(w.$$.fragment),G=o(),I=J("p"),I.innerHTML=$,k=o(),u(C.$$.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),Q=M(i),h(w.$$.fragment,i),G=M(i),I=b(i,"P",{"data-svelte-h":!0}),j(I)!=="svelte-1gu7iii"&&(I.innerHTML=$),k=M(i),h(C.$$.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,Q,g),y(w,i,g),s(i,G,g),s(i,I,g),s(i,k,g),y(C,i,g),R=!0},i(i){R||(d(a.$$.fragment,i),d(m.$$.fragment,i),d(w.$$.fragment,i),d(C.$$.fragment,i),R=!0)},o(i){c(a.$$.fragment,i),c(m.$$.fragment,i),c(w.$$.fragment,i),c(C.$$.fragment,i),R=!1},d(i){i&&(l(p),l(n),l(r),l(Q),l(G),l(I),l(k)),U(a,i),U(m,i),U(w,i),U(C,i)}}}function ms(Z){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,Q,w,G,I,$="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:",k,C,R;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}}),C=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),Q=o(),u(w.$$.fragment),G=o(),I=J("p"),I.innerHTML=$,k=o(),u(C.$$.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),Q=M(i),h(w.$$.fragment,i),G=M(i),I=b(i,"P",{"data-svelte-h":!0}),j(I)!=="svelte-1gu7iii"&&(I.innerHTML=$),k=M(i),h(C.$$.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,Q,g),y(w,i,g),s(i,G,g),s(i,I,g),s(i,k,g),y(C,i,g),R=!0},i(i){R||(d(a.$$.fragment,i),d(m.$$.fragment,i),d(w.$$.fragment,i),d(C.$$.fragment,i),R=!0)},o(i){c(a.$$.fragment,i),c(m.$$.fragment,i),c(w.$$.fragment,i),c(C.$$.fragment,i),R=!1},d(i){i&&(l(p),l(n),l(r),l(Q),l(G),l(I),l(k)),U(a,i),U(m,i),U(w,i),U(C,i)}}}function us(Z){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 hs(Z){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 ys(Z){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:Dl,d(n){n&&l(a)}}}function Us(Z){let a,p,n,T,r,m,Q,w,G,I,$,k,C,R,i='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!',g,S,Pe,F,Oe,E,rl='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.',et,H,cl="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.",tt,v,dl='<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."/>',lt,A,st,q,pl="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:",at,D,nt,L,it,K,ml="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:",ot,P,Mt,O,rt,ee,ul="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:",ct,te,dt,le,pt,se,hl='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:',mt,ae,ut,ne,yl="If we inspect the first row in this <code>DataFrame</code> we can see there are four comments associated with this issue:",ht,ie,yt,oe,Ut,Me,Ul="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:",wt,re,Jt,_,wl='<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>',bt,ce,Jl="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:",ft,de,Tt,pe,jt,me,bl="Okay, this has given us a few thousand comments to work with!",gt,z,Qt,ue,fl="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:",Zt,he,Gt,ye,Tl="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:",Ct,Ue,kt,we,It,Je,jl="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>:",$t,be,Rt,fe,gl="We’re finally ready to create some embeddings! Let’s take a look.",_t,Te,Nt,je,Ql='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:',xt,N,x,He,ge,Zl="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:",Bt,Qe,Wt,Ze,Gl="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:",Xt,B,W,Ae,Ge,Cl="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.",Vt,Ce,vt,ke,kl='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.',zt,Ie,Il="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:",Yt,$e,St,Re,$l="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:",Ft,X,V,qe,_e,Rl="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:",Et,Ne,Ht,xe,_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:",At,Be,qt,We,Nl="Now we can iterate over the first few rows to see how well our query matched the available comments:",Dt,Xe,Lt,Ve,Kt,ve,xl="Not bad! Our second hit seems to match the query.",Pt,Y,Ot,ze,el,De,tl;r=new is({props:{fw:Z[0]}}),Q=new ss({props:{containerStyle:"float: right; margin-left: 10px; display: inline-flex; position: relative; z-index: 10;"}}),G=new Ke({props:{title:"Semantic search with FAISS",local:"semantic-search-with-faiss",headingTag:"h1"}});const Bl=[Ms,os],Ye=[];function Wl(e,t){return e[0]==="pt"?0:1}$=Wl(Z),k=Ye[$]=Bl[$](Z),S=new ns({props:{id:"OATCgQtNX2o"}}),F=new Ke({props:{title:"Using embeddings for semantic search",local:"using-embeddings-for-semantic-search",headingTag:"h2"}}),A=new Ke({props:{title:"Loading and preparing the dataset",local:"loading-and-preparing-the-dataset",headingTag:"h2"}}),D=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}}),L=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}}),P=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}}),O=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}}),te=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}}),le=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}}),ae=new f({props:{code:"aXNzdWVzX2RhdGFzZXQuc2V0X2Zvcm1hdCglMjJwYW5kYXMlMjIpJTBBZGYlMjAlM0QlMjBpc3N1ZXNfZGF0YXNldCU1QiUzQSU1RA==",highlighted:`issues_dataset.set_format(<span class="hljs-string">&quot;pandas&quot;</span>)
df = issues_dataset[:]`,wrap:!1}}),ie=new f({props:{code:"ZGYlNUIlMjJjb21tZW50cyUyMiU1RCU1QjAlNUQudG9saXN0KCk=",highlighted:'df[<span class="hljs-string">&quot;comments&quot;</span>][<span class="hljs-number">0</span>].tolist()',wrap:!1}}),oe=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}}),re=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}}),de=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}}),pe=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 ql({props:{$$slots:{default:[rs]},$$scope:{ctx:Z}}}),he=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}}),Ue=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}}),we=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}}),be=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}}),Te=new Ke({props:{title:"Creating text embeddings",local:"creating-text-embeddings",headingTag:"h2"}});const Xl=[ds,cs],Se=[];function Vl(e,t){return e[0]==="pt"?0:1}N=Vl(Z),x=Se[N]=Xl[N](Z),Qe=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 vl=[ms,ps],Fe=[];function zl(e,t){return e[0]==="pt"?0:1}B=zl(Z),W=Fe[B]=vl[B](Z),Ce=new Ke({props:{title:"Using FAISS for efficient similarity search",local:"using-faiss-for-efficient-similarity-search",headingTag:"h2"}}),$e=new f({props:{code:"ZW1iZWRkaW5nc19kYXRhc2V0LmFkZF9mYWlzc19pbmRleChjb2x1bW4lM0QlMjJlbWJlZGRpbmdzJTIyKQ==",highlighted:'embeddings_dataset.add_faiss_index(column=<span class="hljs-string">&quot;embeddings&quot;</span>)',wrap:!1}});const Yl=[hs,us],Ee=[];function Sl(e,t){return e[0]==="pt"?0:1}return X=Sl(Z),V=Ee[X]=Yl[X](Z),Ne=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}}),Be=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}}),Xe=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}}),Ve=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 ql({props:{$$slots:{default:[ys]},$$scope:{ctx:Z}}}),ze=new as({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(Q.$$.fragment),w=o(),u(G.$$.fragment),I=o(),k.c(),C=o(),R=J("p"),R.innerHTML=i,g=o(),u(S.$$.fragment),Pe=o(),u(F.$$.fragment),Oe=o(),E=J("p"),E.innerHTML=rl,et=o(),H=J("p"),H.textContent=cl,tt=o(),v=J("div"),v.innerHTML=dl,lt=o(),u(A.$$.fragment),st=o(),q=J("p"),q.innerHTML=pl,at=o(),u(D.$$.fragment),nt=o(),u(L.$$.fragment),it=o(),K=J("p"),K.innerHTML=ml,ot=o(),u(P.$$.fragment),Mt=o(),u(O.$$.fragment),rt=o(),ee=J("p"),ee.innerHTML=ul,ct=o(),u(te.$$.fragment),dt=o(),u(le.$$.fragment),pt=o(),se=J("p"),se.innerHTML=hl,mt=o(),u(ae.$$.fragment),ut=o(),ne=J("p"),ne.innerHTML=yl,ht=o(),u(ie.$$.fragment),yt=o(),u(oe.$$.fragment),Ut=o(),Me=J("p"),Me.innerHTML=Ul,wt=o(),u(re.$$.fragment),Jt=o(),_=J("table"),_.innerHTML=wl,bt=o(),ce=J("p"),ce.innerHTML=Jl,ft=o(),u(de.$$.fragment),Tt=o(),u(pe.$$.fragment),jt=o(),me=J("p"),me.textContent=bl,gt=o(),u(z.$$.fragment),Qt=o(),ue=J("p"),ue.innerHTML=fl,Zt=o(),u(he.$$.fragment),Gt=o(),ye=J("p"),ye.textContent=Tl,Ct=o(),u(Ue.$$.fragment),kt=o(),u(we.$$.fragment),It=o(),Je=J("p"),Je.innerHTML=jl,$t=o(),u(be.$$.fragment),Rt=o(),fe=J("p"),fe.textContent=gl,_t=o(),u(Te.$$.fragment),Nt=o(),je=J("p"),je.innerHTML=Ql,xt=o(),x.c(),He=o(),ge=J("p"),ge.innerHTML=Zl,Bt=o(),u(Qe.$$.fragment),Wt=o(),Ze=J("p"),Ze.textContent=Gl,Xt=o(),W.c(),Ae=o(),Ge=J("p"),Ge.textContent=Cl,Vt=o(),u(Ce.$$.fragment),vt=o(),ke=J("p"),ke.innerHTML=kl,zt=o(),Ie=J("p"),Ie.innerHTML=Il,Yt=o(),u($e.$$.fragment),St=o(),Re=J("p"),Re.innerHTML=$l,Ft=o(),V.c(),qe=o(),_e=J("p"),_e.textContent=Rl,Et=o(),u(Ne.$$.fragment),Ht=o(),xe=J("p"),xe.innerHTML=_l,At=o(),u(Be.$$.fragment),qt=o(),We=J("p"),We.textContent=Nl,Dt=o(),u(Xe.$$.fragment),Lt=o(),u(Ve.$$.fragment),Kt=o(),ve=J("p"),ve.textContent=xl,Pt=o(),u(Y.$$.fragment),Ot=o(),u(ze.$$.fragment),el=o(),De=J("p"),this.h()},l(e){const t=ts("svelte-u9bgzb",document.head);a=b(t,"META",{name:!0,content:!0}),t.forEach(l),p=M(e),n=b(e,"P",{}),Al(n).forEach(l),T=M(e),h(r.$$.fragment,e),m=M(e),h(Q.$$.fragment,e),w=M(e),h(G.$$.fragment,e),I=M(e),k.l(e),C=M(e),R=b(e,"P",{"data-svelte-h":!0}),j(R)!=="svelte-x8t0is"&&(R.innerHTML=i),g=M(e),h(S.$$.fragment,e),Pe=M(e),h(F.$$.fragment,e),Oe=M(e),E=b(e,"P",{"data-svelte-h":!0}),j(E)!=="svelte-1o2ff16"&&(E.innerHTML=rl),et=M(e),H=b(e,"P",{"data-svelte-h":!0}),j(H)!=="svelte-s1v4o8"&&(H.textContent=cl),tt=M(e),v=b(e,"DIV",{class:!0,"data-svelte-h":!0}),j(v)!=="svelte-yxatr"&&(v.innerHTML=dl),lt=M(e),h(A.$$.fragment,e),st=M(e),q=b(e,"P",{"data-svelte-h":!0}),j(q)!=="svelte-dttrye"&&(q.innerHTML=pl),at=M(e),h(D.$$.fragment,e),nt=M(e),h(L.$$.fragment,e),it=M(e),K=b(e,"P",{"data-svelte-h":!0}),j(K)!=="svelte-snpg6v"&&(K.innerHTML=ml),ot=M(e),h(P.$$.fragment,e),Mt=M(e),h(O.$$.fragment,e),rt=M(e),ee=b(e,"P",{"data-svelte-h":!0}),j(ee)!=="svelte-1k5h1so"&&(ee.innerHTML=ul),ct=M(e),h(te.$$.fragment,e),dt=M(e),h(le.$$.fragment,e),pt=M(e),se=b(e,"P",{"data-svelte-h":!0}),j(se)!=="svelte-a4bqz"&&(se.innerHTML=hl),mt=M(e),h(ae.$$.fragment,e),ut=M(e),ne=b(e,"P",{"data-svelte-h":!0}),j(ne)!=="svelte-1j8nktv"&&(ne.innerHTML=yl),ht=M(e),h(ie.$$.fragment,e),yt=M(e),h(oe.$$.fragment,e),Ut=M(e),Me=b(e,"P",{"data-svelte-h":!0}),j(Me)!=="svelte-1z9n9m"&&(Me.innerHTML=Ul),wt=M(e),h(re.$$.fragment,e),Jt=M(e),_=b(e,"TABLE",{border:!0,class:!0,style:!0,"data-svelte-h":!0}),j(_)!=="svelte-1g5whzd"&&(_.innerHTML=wl),bt=M(e),ce=b(e,"P",{"data-svelte-h":!0}),j(ce)!=="svelte-nn2zp6"&&(ce.innerHTML=Jl),ft=M(e),h(de.$$.fragment,e),Tt=M(e),h(pe.$$.fragment,e),jt=M(e),me=b(e,"P",{"data-svelte-h":!0}),j(me)!=="svelte-1iu9xg3"&&(me.textContent=bl),gt=M(e),h(z.$$.fragment,e),Qt=M(e),ue=b(e,"P",{"data-svelte-h":!0}),j(ue)!=="svelte-gtnurf"&&(ue.innerHTML=fl),Zt=M(e),h(he.$$.fragment,e),Gt=M(e),ye=b(e,"P",{"data-svelte-h":!0}),j(ye)!=="svelte-gxus05"&&(ye.textContent=Tl),Ct=M(e),h(Ue.$$.fragment,e),kt=M(e),h(we.$$.fragment,e),It=M(e),Je=b(e,"P",{"data-svelte-h":!0}),j(Je)!=="svelte-1gpu2kt"&&(Je.innerHTML=jl),$t=M(e),h(be.$$.fragment,e),Rt=M(e),fe=b(e,"P",{"data-svelte-h":!0}),j(fe)!=="svelte-1vac1i6"&&(fe.textContent=gl),_t=M(e),h(Te.$$.fragment,e),Nt=M(e),je=b(e,"P",{"data-svelte-h":!0}),j(je)!=="svelte-1ug85qi"&&(je.innerHTML=Ql),xt=M(e),x.l(e),He=M(e),ge=b(e,"P",{"data-svelte-h":!0}),j(ge)!=="svelte-wm9gvo"&&(ge.innerHTML=Zl),Bt=M(e),h(Qe.$$.fragment,e),Wt=M(e),Ze=b(e,"P",{"data-svelte-h":!0}),j(Ze)!=="svelte-10gf7d0"&&(Ze.textContent=Gl),Xt=M(e),W.l(e),Ae=M(e),Ge=b(e,"P",{"data-svelte-h":!0}),j(Ge)!=="svelte-ft8b80"&&(Ge.textContent=Cl),Vt=M(e),h(Ce.$$.fragment,e),vt=M(e),ke=b(e,"P",{"data-svelte-h":!0}),j(ke)!=="svelte-r92oxb"&&(ke.innerHTML=kl),zt=M(e),Ie=b(e,"P",{"data-svelte-h":!0}),j(Ie)!=="svelte-92fmoe"&&(Ie.innerHTML=Il),Yt=M(e),h($e.$$.fragment,e),St=M(e),Re=b(e,"P",{"data-svelte-h":!0}),j(Re)!=="svelte-1rt01ml"&&(Re.innerHTML=$l),Ft=M(e),V.l(e),qe=M(e),_e=b(e,"P",{"data-svelte-h":!0}),j(_e)!=="svelte-lxeh2g"&&(_e.textContent=Rl),Et=M(e),h(Ne.$$.fragment,e),Ht=M(e),xe=b(e,"P",{"data-svelte-h":!0}),j(xe)!=="svelte-pvgl7e"&&(xe.innerHTML=_l),At=M(e),h(Be.$$.fragment,e),qt=M(e),We=b(e,"P",{"data-svelte-h":!0}),j(We)!=="svelte-brolnw"&&(We.textContent=Nl),Dt=M(e),h(Xe.$$.fragment,e),Lt=M(e),h(Ve.$$.fragment,e),Kt=M(e),ve=b(e,"P",{"data-svelte-h":!0}),j(ve)!=="svelte-cnuz8o"&&(ve.textContent=xl),Pt=M(e),h(Y.$$.fragment,e),Ot=M(e),h(ze.$$.fragment,e),el=M(e),De=b(e,"P",{}),Al(De).forEach(l),this.h()},h(){Le(a,"name","hf:doc:metadata"),Le(a,"content",ws),Le(v,"class","flex justify-center"),Le(_,"border","1"),Le(_,"class","dataframe"),Ml(_,"table-layout","fixed"),Ml(_,"word-wrap","break-word"),Ml(_,"width","100%")},m(e,t){ls(document.head,a),s(e,p,t),s(e,n,t),s(e,T,t),y(r,e,t),s(e,m,t),y(Q,e,t),s(e,w,t),y(G,e,t),s(e,I,t),Ye[$].m(e,t),s(e,C,t),s(e,R,t),s(e,g,t),y(S,e,t),s(e,Pe,t),y(F,e,t),s(e,Oe,t),s(e,E,t),s(e,et,t),s(e,H,t),s(e,tt,t),s(e,v,t),s(e,lt,t),y(A,e,t),s(e,st,t),s(e,q,t),s(e,at,t),y(D,e,t),s(e,nt,t),y(L,e,t),s(e,it,t),s(e,K,t),s(e,ot,t),y(P,e,t),s(e,Mt,t),y(O,e,t),s(e,rt,t),s(e,ee,t),s(e,ct,t),y(te,e,t),s(e,dt,t),y(le,e,t),s(e,pt,t),s(e,se,t),s(e,mt,t),y(ae,e,t),s(e,ut,t),s(e,ne,t),s(e,ht,t),y(ie,e,t),s(e,yt,t),y(oe,e,t),s(e,Ut,t),s(e,Me,t),s(e,wt,t),y(re,e,t),s(e,Jt,t),s(e,_,t),s(e,bt,t),s(e,ce,t),s(e,ft,t),y(de,e,t),s(e,Tt,t),y(pe,e,t),s(e,jt,t),s(e,me,t),s(e,gt,t),y(z,e,t),s(e,Qt,t),s(e,ue,t),s(e,Zt,t),y(he,e,t),s(e,Gt,t),s(e,ye,t),s(e,Ct,t),y(Ue,e,t),s(e,kt,t),y(we,e,t),s(e,It,t),s(e,Je,t),s(e,$t,t),y(be,e,t),s(e,Rt,t),s(e,fe,t),s(e,_t,t),y(Te,e,t),s(e,Nt,t),s(e,je,t),s(e,xt,t),Se[N].m(e,t),s(e,He,t),s(e,ge,t),s(e,Bt,t),y(Qe,e,t),s(e,Wt,t),s(e,Ze,t),s(e,Xt,t),Fe[B].m(e,t),s(e,Ae,t),s(e,Ge,t),s(e,Vt,t),y(Ce,e,t),s(e,vt,t),s(e,ke,t),s(e,zt,t),s(e,Ie,t),s(e,Yt,t),y($e,e,t),s(e,St,t),s(e,Re,t),s(e,Ft,t),Ee[X].m(e,t),s(e,qe,t),s(e,_e,t),s(e,Et,t),y(Ne,e,t),s(e,Ht,t),s(e,xe,t),s(e,At,t),y(Be,e,t),s(e,qt,t),s(e,We,t),s(e,Dt,t),y(Xe,e,t),s(e,Lt,t),y(Ve,e,t),s(e,Kt,t),s(e,ve,t),s(e,Pt,t),y(Y,e,t),s(e,Ot,t),y(ze,e,t),s(e,el,t),s(e,De,t),tl=!0},p(e,[t]){const Fl={};t&1&&(Fl.fw=e[0]),r.$set(Fl);let al=$;$=Wl(e),$!==al&&(sl(),c(Ye[al],1,1,()=>{Ye[al]=null}),ll(),k=Ye[$],k||(k=Ye[$]=Bl[$](e),k.c()),d(k,1),k.m(C.parentNode,C));const El={};t&2&&(El.$$scope={dirty:t,ctx:e}),z.$set(El);let nl=N;N=Vl(e),N!==nl&&(sl(),c(Se[nl],1,1,()=>{Se[nl]=null}),ll(),x=Se[N],x||(x=Se[N]=Xl[N](e),x.c()),d(x,1),x.m(He.parentNode,He));let il=B;B=zl(e),B!==il&&(sl(),c(Fe[il],1,1,()=>{Fe[il]=null}),ll(),W=Fe[B],W||(W=Fe[B]=vl[B](e),W.c()),d(W,1),W.m(Ae.parentNode,Ae));let ol=X;X=Sl(e),X!==ol&&(sl(),c(Ee[ol],1,1,()=>{Ee[ol]=null}),ll(),V=Ee[X],V||(V=Ee[X]=Yl[X](e),V.c()),d(V,1),V.m(qe.parentNode,qe));const Hl={};t&2&&(Hl.$$scope={dirty:t,ctx:e}),Y.$set(Hl)},i(e){tl||(d(r.$$.fragment,e),d(Q.$$.fragment,e),d(G.$$.fragment,e),d(k),d(S.$$.fragment,e),d(F.$$.fragment,e),d(A.$$.fragment,e),d(D.$$.fragment,e),d(L.$$.fragment,e),d(P.$$.fragment,e),d(O.$$.fragment,e),d(te.$$.fragment,e),d(le.$$.fragment,e),d(ae.$$.fragment,e),d(ie.$$.fragment,e),d(oe.$$.fragment,e),d(re.$$.fragment,e),d(de.$$.fragment,e),d(pe.$$.fragment,e),d(z.$$.fragment,e),d(he.$$.fragment,e),d(Ue.$$.fragment,e),d(we.$$.fragment,e),d(be.$$.fragment,e),d(Te.$$.fragment,e),d(x),d(Qe.$$.fragment,e),d(W),d(Ce.$$.fragment,e),d($e.$$.fragment,e),d(V),d(Ne.$$.fragment,e),d(Be.$$.fragment,e),d(Xe.$$.fragment,e),d(Ve.$$.fragment,e),d(Y.$$.fragment,e),d(ze.$$.fragment,e),tl=!0)},o(e){c(r.$$.fragment,e),c(Q.$$.fragment,e),c(G.$$.fragment,e),c(k),c(S.$$.fragment,e),c(F.$$.fragment,e),c(A.$$.fragment,e),c(D.$$.fragment,e),c(L.$$.fragment,e),c(P.$$.fragment,e),c(O.$$.fragment,e),c(te.$$.fragment,e),c(le.$$.fragment,e),c(ae.$$.fragment,e),c(ie.$$.fragment,e),c(oe.$$.fragment,e),c(re.$$.fragment,e),c(de.$$.fragment,e),c(pe.$$.fragment,e),c(z.$$.fragment,e),c(he.$$.fragment,e),c(Ue.$$.fragment,e),c(we.$$.fragment,e),c(be.$$.fragment,e),c(Te.$$.fragment,e),c(x),c(Qe.$$.fragment,e),c(W),c(Ce.$$.fragment,e),c($e.$$.fragment,e),c(V),c(Ne.$$.fragment,e),c(Be.$$.fragment,e),c(Xe.$$.fragment,e),c(Ve.$$.fragment,e),c(Y.$$.fragment,e),c(ze.$$.fragment,e),tl=!1},d(e){e&&(l(p),l(n),l(T),l(m),l(w),l(I),l(C),l(R),l(g),l(Pe),l(Oe),l(E),l(et),l(H),l(tt),l(v),l(lt),l(st),l(q),l(at),l(nt),l(it),l(K),l(ot),l(Mt),l(rt),l(ee),l(ct),l(dt),l(pt),l(se),l(mt),l(ut),l(ne),l(ht),l(yt),l(Ut),l(Me),l(wt),l(Jt),l(_),l(bt),l(ce),l(ft),l(Tt),l(jt),l(me),l(gt),l(Qt),l(ue),l(Zt),l(Gt),l(ye),l(Ct),l(kt),l(It),l(Je),l($t),l(Rt),l(fe),l(_t),l(Nt),l(je),l(xt),l(He),l(ge),l(Bt),l(Wt),l(Ze),l(Xt),l(Ae),l(Ge),l(Vt),l(vt),l(ke),l(zt),l(Ie),l(Yt),l(St),l(Re),l(Ft),l(qe),l(_e),l(Et),l(Ht),l(xe),l(At),l(qt),l(We),l(Dt),l(Lt),l(Kt),l(ve),l(Pt),l(Ot),l(el),l(De)),l(a),U(r,e),U(Q,e),U(G,e),Ye[$].d(e),U(S,e),U(F,e),U(A,e),U(D,e),U(L,e),U(P,e),U(O,e),U(te,e),U(le,e),U(ae,e),U(ie,e),U(oe,e),U(re,e),U(de,e),U(pe,e),U(z,e),U(he,e),U(Ue,e),U(we,e),U(be,e),U(Te,e),Se[N].d(e),U(Qe,e),Fe[B].d(e),U(Ce,e),U($e,e),Ee[X].d(e),U(Ne,e),U(Be,e),U(Xe,e),U(Ve,e),U(Y,e),U(ze,e)}}}const ws='{"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 Js(Z,a,p){let n="pt";return Pl(()=>{const T=new URLSearchParams(window.location.search);p(0,n=T.get("fw")||"pt")}),[n]}class Cs extends Ol{constructor(a){super(),es(this,a,Js,Us,Kl,{})}}export{Cs as component};
