import{s as lt,o as tt,n as et}from"../chunks/scheduler.cc52f4b9.js";import{S as at,i as nt,e as j,s as o,c as u,h as ot,a as h,d as l,b as i,f as Pl,g as U,j as T,k as Pe,w as pl,l as it,m as t,n as y,o as d,u as ol,t as M,p as J,v as il}from"../chunks/index.d2856393.js";import{T as Ol}from"../chunks/Tip.a5bdccc4.js";import{C as rt,H as Oe,E as mt}from"../chunks/MermaidChart.svelte_svelte_type_style_lang.e6659d4e.js";import{Y as dt}from"../chunks/Youtube.00df107c.js";import{C as f}from"../chunks/CodeBlock.9c179ed7.js";import{C as st}from"../chunks/CourseFloatingBanner.1c404cc0.js";import{F as Mt}from"../chunks/FrameworkSwitchCourse.22a5e932.js";function pt(Z){let a,p;return a=new st({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/pt/chapter5/section6_tf.ipynb"},{label:"Aws Studio",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/master/course/pt/chapter5/section6_tf.ipynb"}]}}),{c(){u(a.$$.fragment)},l(n){U(a.$$.fragment,n)},m(n,w){y(a,n,w),p=!0},i(n){p||(M(a.$$.fragment,n),p=!0)},o(n){d(a.$$.fragment,n),p=!1},d(n){J(a,n)}}}function ct(Z){let a,p;return a=new st({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/pt/chapter5/section6_pt.ipynb"},{label:"Aws Studio",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/master/course/pt/chapter5/section6_pt.ipynb"}]}}),{c(){u(a.$$.fragment)},l(n){U(a.$$.fragment,n)},m(n,w){y(a,n,w),p=!0},i(n){p||(M(a.$$.fragment,n),p=!0)},o(n){d(a.$$.fragment,n),p=!1},d(n){J(a,n)}}}function ut(Z){let a,p='✏️ <strong>Experimente!</strong> Veja se você pode usar <code>Dataset.map()</code> para explodir a coluna <code>comments</code> de <code>issues_dataset</code> <em>sem</em> recorrer ao uso de Pandas. Isso é um pouco complicado; você pode achar útil para esta tarefa a seção <a href="https://huggingface.co/docs/datasets/v1.12.1/about_map_batch#batch-mapping" rel="nofollow">“Mapeamento em lote”</a> da documentação do 🤗 Dataset.';return{c(){a=j("p"),a.innerHTML=p},l(n){a=h(n,"P",{"data-svelte-h":!0}),T(a)!=="svelte-83kmej"&&(a.innerHTML=p)},m(n,w){t(n,a,w)},p:et,d(n){n&&l(a)}}}function Ut(Z){let a,p,n,w="Observe que definimos <code>from_pt=True</code> como um argumento do método <code>from_pretrained()</code>. Isso ocorre porque o checkpoint <code>multi-qa-mpnet-base-dot-v1</code> só tem pesos PyTorch, portanto, definir <code>from_pt=True</code> irá convertê-los automaticamente para o formato TensorFlow para nós. Como você pode ver, é muito simples alternar entre frameworks no 🤗 Transformers!",m;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=w},l(c){U(a.$$.fragment,c),p=i(c),n=h(c,"P",{"data-svelte-h":!0}),T(n)!=="svelte-m83kxk"&&(n.innerHTML=w)},m(c,Q){y(a,c,Q),t(c,p,Q),t(c,n,Q),m=!0},i(c){m||(M(a.$$.fragment,c),m=!0)},o(c){d(a.$$.fragment,c),m=!1},d(c){c&&(l(p),l(n)),J(a,c)}}}function yt(Z){let a,p,n,w="Para acelerar o processo de embedding, é útil colocar o modelo e as entradas em um dispositivo GPU, então vamos fazer isso agora:",m,c,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}}),c=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=w,m=o(),u(c.$$.fragment)},l(b){U(a.$$.fragment,b),p=i(b),n=h(b,"P",{"data-svelte-h":!0}),T(n)!=="svelte-19fxoub"&&(n.textContent=w),m=i(b),U(c.$$.fragment,b)},m(b,G){y(a,b,G),t(b,p,G),t(b,n,G),t(b,m,G),y(c,b,G),Q=!0},i(b){Q||(M(a.$$.fragment,b),M(c.$$.fragment,b),Q=!0)},o(b){d(a.$$.fragment,b),d(c.$$.fragment,b),Q=!1},d(b){b&&(l(p),l(n),l(m)),J(a,b),J(c,b)}}}function Jt(Z){let a,p,n,w="Podemos testar o funcionamento da função alimentando-a com a primeira entrada de texto em nosso corpus e inspecionando a forma de saída:",m,c,Q,b,G,k,$="Ótimo, convertemos a primeira entrada em nosso corpus em um vetor de 768 dimensões! Podemos usar <code>Dataset.map()</code> para aplicar nossa função <code>get_embeddings()</code> a cada linha em nosso corpus, então vamos criar uma nova coluna <code>embeddings</code> da seguinte forma:",I,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}}),c=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}}),b=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=w,m=o(),u(c.$$.fragment),Q=o(),u(b.$$.fragment),G=o(),k=j("p"),k.innerHTML=$,I=o(),u(C.$$.fragment)},l(r){U(a.$$.fragment,r),p=i(r),n=h(r,"P",{"data-svelte-h":!0}),T(n)!=="svelte-1yecorf"&&(n.textContent=w),m=i(r),U(c.$$.fragment,r),Q=i(r),U(b.$$.fragment,r),G=i(r),k=h(r,"P",{"data-svelte-h":!0}),T(k)!=="svelte-whkpu9"&&(k.innerHTML=$),I=i(r),U(C.$$.fragment,r)},m(r,g){y(a,r,g),t(r,p,g),t(r,n,g),t(r,m,g),y(c,r,g),t(r,Q,g),y(b,r,g),t(r,G,g),t(r,k,g),t(r,I,g),y(C,r,g),R=!0},i(r){R||(M(a.$$.fragment,r),M(c.$$.fragment,r),M(b.$$.fragment,r),M(C.$$.fragment,r),R=!0)},o(r){d(a.$$.fragment,r),d(c.$$.fragment,r),d(b.$$.fragment,r),d(C.$$.fragment,r),R=!1},d(r){r&&(l(p),l(n),l(m),l(Q),l(G),l(k),l(I)),J(a,r),J(c,r),J(b,r),J(C,r)}}}function bt(Z){let a,p,n,w="Podemos testar o funcionamento da função alimentando-a com a primeira entrada de texto em nosso corpus e inspecionando a forma de saída:",m,c,Q,b,G,k,$="Ótimo, convertemos a primeira entrada em nosso corpus em um vetor de 768 dimensões! Podemos usar <code>Dataset.map()</code> para aplicar nossa função <code>get_embeddings()</code> a cada linha em nosso corpus, então vamos criar uma nova coluna <code>embeddings</code> da seguinte forma:",I,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}}),c=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}}),b=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=w,m=o(),u(c.$$.fragment),Q=o(),u(b.$$.fragment),G=o(),k=j("p"),k.innerHTML=$,I=o(),u(C.$$.fragment)},l(r){U(a.$$.fragment,r),p=i(r),n=h(r,"P",{"data-svelte-h":!0}),T(n)!=="svelte-1yecorf"&&(n.textContent=w),m=i(r),U(c.$$.fragment,r),Q=i(r),U(b.$$.fragment,r),G=i(r),k=h(r,"P",{"data-svelte-h":!0}),T(k)!=="svelte-whkpu9"&&(k.innerHTML=$),I=i(r),U(C.$$.fragment,r)},m(r,g){y(a,r,g),t(r,p,g),t(r,n,g),t(r,m,g),y(c,r,g),t(r,Q,g),y(b,r,g),t(r,G,g),t(r,k,g),t(r,I,g),y(C,r,g),R=!0},i(r){R||(M(a.$$.fragment,r),M(c.$$.fragment,r),M(b.$$.fragment,r),M(C.$$.fragment,r),R=!0)},o(r){d(a.$$.fragment,r),d(c.$$.fragment,r),d(b.$$.fragment,r),d(C.$$.fragment,r),R=!1},d(r){r&&(l(p),l(n),l(m),l(Q),l(G),l(k),l(I)),J(a,r),J(c,r),J(b,r),J(C,r)}}}function jt(Z){let a,p,n,w;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(m){U(a.$$.fragment,m),p=i(m),U(n.$$.fragment,m)},m(m,c){y(a,m,c),t(m,p,c),y(n,m,c),w=!0},i(m){w||(M(a.$$.fragment,m),M(n.$$.fragment,m),w=!0)},o(m){d(a.$$.fragment,m),d(n.$$.fragment,m),w=!1},d(m){m&&l(p),J(a,m),J(n,m)}}}function ht(Z){let a,p,n,w;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(m){U(a.$$.fragment,m),p=i(m),U(n.$$.fragment,m)},m(m,c){y(a,m,c),t(m,p,c),y(n,m,c),w=!0},i(m){w||(M(a.$$.fragment,m),M(n.$$.fragment,m),w=!0)},o(m){d(a.$$.fragment,m),d(n.$$.fragment,m),w=!1},d(m){m&&l(p),J(a,m),J(n,m)}}}function ft(Z){let a,p="✏️ <strong>Experimente!</strong> Crie sua própria consulta e veja se consegue encontrar uma resposta nos documentos recuperados. Você pode ter que aumentar o parâmetro <code>k</code> em <code>Dataset.get_nearest_examples()</code> para ampliar a pesquisa.";return{c(){a=j("p"),a.innerHTML=p},l(n){a=h(n,"P",{"data-svelte-h":!0}),T(a)!=="svelte-1c1kivx"&&(a.innerHTML=p)},m(n,w){t(n,a,w)},p:et,d(n){n&&l(a)}}}function Tt(Z){let a,p,n,w,m,c,Q,b,G,k,$,I,C,R,r='Na <a href="/course/chapter5/5">seção 5</a>, criamos um conjunto de dados de issues e comentários do GitHub do repositório 🤗 Datasets. Nesta seção, usaremos essas informações para construir um mecanismo de pesquisa que pode nos ajudar a encontrar respostas para nossas perguntas mais urgentes sobre a biblioteca!',g,F,es,S,ss,E,cl='Como vimos no <a href="/course/chapter1">Capítulo 1</a>, os modelos de linguagem baseados em Transformer representam cada token em um intervalo de texto como um <em>vetor de incorporação</em>. Acontece que é possível “agrupar” as incorporações individuais para criar uma representação vetorial para frases inteiras, parágrafos ou (em alguns casos) documentos. Essas incorporações podem ser usadas para encontrar documentos semelhantes no corpus calculando a similaridade do produto escalar (ou alguma outra métrica de similaridade) entre cada incorporação e retornando os documentos com maior sobreposição.',ls,A,ul="Nesta seção, usaremos embeddings para desenvolver um mecanismo de pesquisa semântica. Esses mecanismos de pesquisa oferecem várias vantagens sobre as abordagens convencionais que se baseiam na correspondência de palavras-chave em uma consulta com os documentos.",ts,W,Ul='<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."/>',as,H,ns,q,yl="A primeira coisa que precisamos fazer é baixar nosso conjunto de dados de issues do GitHub, então vamos usar a biblioteca 🤗 Hub para resolver a URL onde nosso arquivo está armazenado no Hugging Face Hub:",os,D,is,L,Jl='Com a URL armazenada em <code>data_files</code>, podemos carregar o conjunto de dados remoto usando o método apresentado na <a href="/course/chapter5/2">seção 2</a>:',rs,K,ms,P,ds,O,bl="Aqui nós especificamos a divisão padrão <code>train</code> em <code>load_dataset()</code>, então ele retorna um <code>Dataset</code> em vez de um <code>DatasetDict</code>. A primeira ordem de negócios é filtrar os pull request, pois elas tendem a ser raramente usadas para responder a consultas de usuários e introduzirão ruído em nosso mecanismo de pesquisa. Como já deve ser familiar, podemos usar a função <code>Dataset.filter()</code> para excluir essas linhas em nosso conjunto de dados. Enquanto estamos nisso, também vamos filtrar as linhas sem comentários, pois elas não fornecem respostas às consultas dos usuários:",Ms,ee,ps,se,cs,le,jl="Podemos ver que há muitas colunas em nosso conjunto de dados, a maioria das quais não precisamos para construir nosso mecanismo de pesquisa. De uma perspectiva de pesquisa, as colunas mais informativas são <code>title</code>, <code>body</code> e <code>comments</code>, enquanto <code>html_url</code> nos fornece um link de volta para a issue de origem. Vamos usar a função <code>Dataset.remove_columns()</code> para descartar o resto:",us,te,Us,ae,ys,ne,hl='Para criar nossos embeddings, aumentaremos cada comentário com o título e o corpo da issue, pois esses campos geralmente incluem informações contextuais úteis. Como nossa coluna <code>comments</code> é atualmente uma lista de comentários para cada issue, precisamos “explodir” a coluna para que cada linha consista em uma tupla <code>(html_url, title, body, comment)</code>. No Pandas podemos fazer isso com a função <a href="https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.explode.html" rel="nofollow"><code>DataFrame.explode()</code></a>, que cria uma nova linha para cada elemento em uma coluna semelhante a uma lista, enquanto replica todos os outros valores de coluna. Para ver isso em ação, vamos primeiro mudar para o formato <code>DataFrame</code> do Pandas:',Js,oe,bs,ie,fl="Se inspecionarmos a primeira linha neste <code>DataFrame</code>, podemos ver que há quatro comentários associados a esta issue:",js,re,hs,me,fs,de,Tl="Quando explodimos <code>df</code>, esperamos obter uma linha para cada um desses comentários. Vamos verificar se é o caso:",Ts,Me,ws,_,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>',gs,pe,gl="Ótimo, podemos ver que as linhas foram replicadas, com a coluna <code>comments</code> contendo os comentários individuais! Agora que terminamos com o Pandas, podemos voltar rapidamente para um <code>Dataset</code> carregando o <code>DataFrame</code> na memória",Qs,ce,Zs,ue,Gs,Ue,Ql="Ok, isso nos deu alguns milhares de comentários para trabalhar!",Cs,z,Is,ye,Zl="Agora que temos um comentário por linha, vamos criar uma nova coluna <code>comments_length</code> que contém o número de palavras por comentário:",ks,Je,$s,be,Gl="Podemos usar essa nova coluna para filtrar comentários curtos, que normalmente incluem coisas como “cc @lewtun” ou “Obrigado!” que não são relevantes para o nosso motor de busca. Não há um número preciso para selecionar o filtro, mas cerca de 15 palavras parece um bom começo:",Rs,je,_s,he,Ns,fe,Cl="Depois de limpar um pouco nosso conjunto de dados, vamos concatenar o título, a descrição e os comentários da issue em uma nova coluna <code>text</code>. Como de costume, escreveremos uma função simples que podemos passar para <code>Dataset.map()</code>:",xs,Te,Bs,we,Il="Finalmente estamos prontos para criar alguns embeddings! Vamos dar uma olhada.",vs,ge,Xs,Qe,kl='Vimos no <a href="/course/chapter2">Capítulo 2</a> que podemos obter tokens embeddings usando a classe <code>AutoModel</code>. Tudo o que precisamos fazer é escolher um checkpoint adequado para carregar o modelo. Felizmente, existe uma biblioteca chamada <code>sentence-transformers</code> dedicada à criação de embeddings. Conforme descrito na <a href="https://www.sbert.net/examples/applications/semantic-search/README.html#symmetric-vs-asymmetric-semantic-search" rel="nofollow">documentação da biblioteca</a>, nosso caso de uso é um exemplo de <em>asymmetric semantic search</em> porque temos uma consulta curta cuja resposta gostaríamos de encontrar em um documento mais longo, como um comentário da issue. A útil <a href="https://www.sbert.net/docs/pretrained_models.html#model-overview" rel="nofollow">tabela de visão geral do modelo</a> na documentação indica que o checkpoint <code>multi-qa-mpnet-base-dot-v1</code> tem o melhor desempenho para pesquisa semântica, então usaremos isso para nosso aplicativo. Também carregaremos o tokenizer usando o mesmo checkpoint:',Vs,N,x,qe,Ze,$l="Como mencionamos anteriormente, gostaríamos de representar cada entrada em nosso corpus de issues do GitHub como um único vetor, portanto, precisamos “pool” ou calcular a média de nossas incorporações de token de alguma forma. Uma abordagem popular é realizar <em>CLS pooling</em> nas saídas do nosso modelo, onde simplesmente coletamos o último estado oculto para o token especial <code>[CLS]</code>. A função a seguir faz o truque para nós:",Ws,Ge,zs,Ce,Rl="Em seguida, criaremos uma função auxiliar que tokenizará uma lista de documentos, colocará os tensores na GPU, os alimentará no modelo e, finalmente, aplicará o agrupamento CLS às saídas:",Ys,B,v,De,Ie,_l="Observe que convertemos os embeddings em arrays NumPy — isso porque 🤗 Datasets requer esse formato quando tentamos indexá-los com FAISS, o que faremos a seguir.",Fs,ke,Ss,$e,Nl='Agora que temos um conjunto de dados de embeddings, precisamos de alguma maneira de pesquisá-los. Para fazer isso, usaremos uma estrutura de dados especial em 🤗 Datasets chamada <em>FAISS index</em>. <a href="https://faiss.ai/" rel="nofollow">FAISS</a> (abreviação de Facebook AI Similarity Search) é uma biblioteca que fornece algoritmos eficientes para pesquisar rapidamente e agrupar vetores de incorporação.',Es,Re,xl="A idéia básica por trás do FAISS é criar uma estrutura de dados especial chamada <em>index</em> que permite descobrir quais embeddings são semelhantes a um embedding de entrada. Criar um índice FAISS em 🤗 Datasets é simples — usamos a função <code>Dataset.add_faiss_index()</code> e especificamos qual coluna do nosso conjunto de dados gostaríamos de indexar:",As,_e,Hs,Ne,Bl="Agora podemos realizar consultas neste índice fazendo uma pesquisa do vizinho mais próximo com a função <code>Dataset.get_nearest_examples()</code>. Vamos testar isso primeiro incorporando uma pergunta da seguinte forma:",qs,X,V,Le,xe,vl="Assim como com os documentos, agora temos um vetor de 768 dimensões representando a consulta, que podemos comparar com todo o corpus para encontrar os embeddings mais semelhantes:",Ds,Be,Ls,ve,Xl="A função <code>Dataset.get_nearest_examples()</code> retorna uma tupla de pontuações que classificam a sobreposição entre a consulta e o documento e um conjunto correspondente de amostras (aqui, as 5 melhores correspondências). Vamos coletá-los em um <code>pandas.DataFrame</code> para que possamos classificá-los facilmente:",Ks,Xe,Ps,Ve,Vl="Agora podemos iterar nas primeiras linhas para ver como nossa consulta correspondeu aos comentários disponíveis:",Os,We,el,ze,sl,Ye,Wl="Nada mal! Nosso segundo resultado parece corresponder à consulta.",ll,Y,tl,Fe,al,Ke,nl;m=new Mt({props:{fw:Z[0]}}),Q=new rt({props:{containerStyle:"float: right; margin-left: 10px; display: inline-flex; position: relative; z-index: 10;"}}),G=new Oe({props:{title:"Busca semântica com o FAISS",local:"busca-semântica-com-o-faiss",headingTag:"h1"}});const zl=[ct,pt],Se=[];function Yl(e,s){return e[0]==="pt"?0:1}$=Yl(Z),I=Se[$]=zl[$](Z),F=new dt({props:{id:"OATCgQtNX2o"}}),S=new Oe({props:{title:"Usando embeddings para pesquisa semântica",local:"usando-embeddings-para-pesquisa-semântica",headingTag:"h2"}}),H=new Oe({props:{title:"Carregando e preparando o conjunto de dados",local:"carregando-e-preparando-o-conjunto-de-dados",headingTag:"h2"}}),D=new f({props:{code:"ZnJvbSUyMGh1Z2dpbmdmYWNlX2h1YiUyMGltcG9ydCUyMGhmX2h1Yl91cmwlMEElMEFkYXRhX2ZpbGVzJTIwJTNEJTIwaGZfaHViX3VybCglMEElMjAlMjAlMjAlMjByZXBvX2lkJTNEJTIybGV3dHVuJTJGZ2l0aHViLWlzc3VlcyUyMiUyQyUwQSUyMCUyMCUyMCUyMGZpbGVuYW1lJTNEJTIyZGF0YXNldHMtaXNzdWVzLXdpdGgtY29tbWVudHMuanNvbmwlMjIlMkMlMEElMjAlMjAlMjAlMjByZXBvX3R5cGUlM0QlMjJkYXRhc2V0JTIyJTJDJTBBKQ==",highlighted:`<span class="hljs-keyword">from</span> huggingface_hub <span class="hljs-keyword">import</span> hf_hub_url

data_files = hf_hub_url(
    repo_id=<span class="hljs-string">&quot;lewtun/github-issues&quot;</span>,
    filename=<span class="hljs-string">&quot;datasets-issues-with-comments.jsonl&quot;</span>,
    repo_type=<span class="hljs-string">&quot;dataset&quot;</span>,
)`,wrap:!1}}),K=new f({props:{code:"ZnJvbSUyMGRhdGFzZXRzJTIwaW1wb3J0JTIwbG9hZF9kYXRhc2V0JTBBJTBBaXNzdWVzX2RhdGFzZXQlMjAlM0QlMjBsb2FkX2RhdGFzZXQoJTIyanNvbiUyMiUyQyUyMGRhdGFfZmlsZXMlM0RkYXRhX2ZpbGVzJTJDJTIwc3BsaXQlM0QlMjJ0cmFpbiUyMiklMEFpc3N1ZXNfZGF0YXNldA==",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;json&quot;</span>, data_files=data_files, split=<span class="hljs-string">&quot;train&quot;</span>)
issues_dataset`,wrap:!1}}),P=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}}),ee=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}}),se=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}}),ae=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}}),oe=new f({props:{code:"aXNzdWVzX2RhdGFzZXQuc2V0X2Zvcm1hdCglMjJwYW5kYXMlMjIpJTBBZGYlMjAlM0QlMjBpc3N1ZXNfZGF0YXNldCU1QiUzQSU1RA==",highlighted:`issues_dataset.set_format(<span class="hljs-string">&quot;pandas&quot;</span>)
df = issues_dataset[:]`,wrap:!1}}),re=new f({props:{code:"ZGYlNUIlMjJjb21tZW50cyUyMiU1RCU1QjAlNUQudG9saXN0KCk=",highlighted:'df[<span class="hljs-string">&quot;comments&quot;</span>][<span class="hljs-number">0</span>].tolist()',wrap:!1}}),me=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}}),ue=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 Ol({props:{$$slots:{default:[ut]},$$scope:{ctx:Z}}}),Je=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}}),je=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}}),he=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}}),Te=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}}),ge=new Oe({props:{title:"Criando embeddings de texto",local:"criando-embeddings-de-texto",headingTag:"h2"}});const Fl=[yt,Ut],Ee=[];function Sl(e,s){return e[0]==="pt"?0:1}N=Sl(Z),x=Ee[N]=Fl[N](Z),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 El=[bt,Jt],Ae=[];function Al(e,s){return e[0]==="pt"?0:1}B=Al(Z),v=Ae[B]=El[B](Z),ke=new Oe({props:{title:"Usando FAISS para busca de similaridade",local:"usando-faiss-para-busca-de-similaridade",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 Hl=[ht,jt],He=[];function ql(e,s){return e[0]==="pt"?0:1}return X=ql(Z),V=He[X]=Hl[X](Z),Be=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}}),ze=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 Ol({props:{$$slots:{default:[ft]},$$scope:{ctx:Z}}}),Fe=new mt({props:{source:"https://github.com/huggingface/course/blob/main/chapters/pt/chapter5/6.mdx"}}),{c(){a=j("meta"),p=o(),n=j("p"),w=o(),u(m.$$.fragment),c=o(),u(Q.$$.fragment),b=o(),u(G.$$.fragment),k=o(),I.c(),C=o(),R=j("p"),R.innerHTML=r,g=o(),u(F.$$.fragment),es=o(),u(S.$$.fragment),ss=o(),E=j("p"),E.innerHTML=cl,ls=o(),A=j("p"),A.textContent=ul,ts=o(),W=j("div"),W.innerHTML=Ul,as=o(),u(H.$$.fragment),ns=o(),q=j("p"),q.textContent=yl,os=o(),u(D.$$.fragment),is=o(),L=j("p"),L.innerHTML=Jl,rs=o(),u(K.$$.fragment),ms=o(),u(P.$$.fragment),ds=o(),O=j("p"),O.innerHTML=bl,Ms=o(),u(ee.$$.fragment),ps=o(),u(se.$$.fragment),cs=o(),le=j("p"),le.innerHTML=jl,us=o(),u(te.$$.fragment),Us=o(),u(ae.$$.fragment),ys=o(),ne=j("p"),ne.innerHTML=hl,Js=o(),u(oe.$$.fragment),bs=o(),ie=j("p"),ie.innerHTML=fl,js=o(),u(re.$$.fragment),hs=o(),u(me.$$.fragment),fs=o(),de=j("p"),de.innerHTML=Tl,Ts=o(),u(Me.$$.fragment),ws=o(),_=j("table"),_.innerHTML=wl,gs=o(),pe=j("p"),pe.innerHTML=gl,Qs=o(),u(ce.$$.fragment),Zs=o(),u(ue.$$.fragment),Gs=o(),Ue=j("p"),Ue.textContent=Ql,Cs=o(),u(z.$$.fragment),Is=o(),ye=j("p"),ye.innerHTML=Zl,ks=o(),u(Je.$$.fragment),$s=o(),be=j("p"),be.textContent=Gl,Rs=o(),u(je.$$.fragment),_s=o(),u(he.$$.fragment),Ns=o(),fe=j("p"),fe.innerHTML=Cl,xs=o(),u(Te.$$.fragment),Bs=o(),we=j("p"),we.textContent=Il,vs=o(),u(ge.$$.fragment),Xs=o(),Qe=j("p"),Qe.innerHTML=kl,Vs=o(),x.c(),qe=o(),Ze=j("p"),Ze.innerHTML=$l,Ws=o(),u(Ge.$$.fragment),zs=o(),Ce=j("p"),Ce.textContent=Rl,Ys=o(),v.c(),De=o(),Ie=j("p"),Ie.textContent=_l,Fs=o(),u(ke.$$.fragment),Ss=o(),$e=j("p"),$e.innerHTML=Nl,Es=o(),Re=j("p"),Re.innerHTML=xl,As=o(),u(_e.$$.fragment),Hs=o(),Ne=j("p"),Ne.innerHTML=Bl,qs=o(),V.c(),Le=o(),xe=j("p"),xe.textContent=vl,Ds=o(),u(Be.$$.fragment),Ls=o(),ve=j("p"),ve.innerHTML=Xl,Ks=o(),u(Xe.$$.fragment),Ps=o(),Ve=j("p"),Ve.textContent=Vl,Os=o(),u(We.$$.fragment),el=o(),u(ze.$$.fragment),sl=o(),Ye=j("p"),Ye.textContent=Wl,ll=o(),u(Y.$$.fragment),tl=o(),u(Fe.$$.fragment),al=o(),Ke=j("p"),this.h()},l(e){const s=ot("svelte-u9bgzb",document.head);a=h(s,"META",{name:!0,content:!0}),s.forEach(l),p=i(e),n=h(e,"P",{}),Pl(n).forEach(l),w=i(e),U(m.$$.fragment,e),c=i(e),U(Q.$$.fragment,e),b=i(e),U(G.$$.fragment,e),k=i(e),I.l(e),C=i(e),R=h(e,"P",{"data-svelte-h":!0}),T(R)!=="svelte-gjg3xh"&&(R.innerHTML=r),g=i(e),U(F.$$.fragment,e),es=i(e),U(S.$$.fragment,e),ss=i(e),E=h(e,"P",{"data-svelte-h":!0}),T(E)!=="svelte-isds6h"&&(E.innerHTML=cl),ls=i(e),A=h(e,"P",{"data-svelte-h":!0}),T(A)!=="svelte-1xgdub6"&&(A.textContent=ul),ts=i(e),W=h(e,"DIV",{class:!0,"data-svelte-h":!0}),T(W)!=="svelte-yxatr"&&(W.innerHTML=Ul),as=i(e),U(H.$$.fragment,e),ns=i(e),q=h(e,"P",{"data-svelte-h":!0}),T(q)!=="svelte-r8uu0o"&&(q.textContent=yl),os=i(e),U(D.$$.fragment,e),is=i(e),L=h(e,"P",{"data-svelte-h":!0}),T(L)!=="svelte-136cz13"&&(L.innerHTML=Jl),rs=i(e),U(K.$$.fragment,e),ms=i(e),U(P.$$.fragment,e),ds=i(e),O=h(e,"P",{"data-svelte-h":!0}),T(O)!=="svelte-1dvqw0"&&(O.innerHTML=bl),Ms=i(e),U(ee.$$.fragment,e),ps=i(e),U(se.$$.fragment,e),cs=i(e),le=h(e,"P",{"data-svelte-h":!0}),T(le)!=="svelte-nwy9uh"&&(le.innerHTML=jl),us=i(e),U(te.$$.fragment,e),Us=i(e),U(ae.$$.fragment,e),ys=i(e),ne=h(e,"P",{"data-svelte-h":!0}),T(ne)!=="svelte-xiuizr"&&(ne.innerHTML=hl),Js=i(e),U(oe.$$.fragment,e),bs=i(e),ie=h(e,"P",{"data-svelte-h":!0}),T(ie)!=="svelte-b7um6f"&&(ie.innerHTML=fl),js=i(e),U(re.$$.fragment,e),hs=i(e),U(me.$$.fragment,e),fs=i(e),de=h(e,"P",{"data-svelte-h":!0}),T(de)!=="svelte-tnp87o"&&(de.innerHTML=Tl),Ts=i(e),U(Me.$$.fragment,e),ws=i(e),_=h(e,"TABLE",{border:!0,class:!0,style:!0,"data-svelte-h":!0}),T(_)!=="svelte-1g5whzd"&&(_.innerHTML=wl),gs=i(e),pe=h(e,"P",{"data-svelte-h":!0}),T(pe)!=="svelte-11z2n8l"&&(pe.innerHTML=gl),Qs=i(e),U(ce.$$.fragment,e),Zs=i(e),U(ue.$$.fragment,e),Gs=i(e),Ue=h(e,"P",{"data-svelte-h":!0}),T(Ue)!=="svelte-11iemom"&&(Ue.textContent=Ql),Cs=i(e),U(z.$$.fragment,e),Is=i(e),ye=h(e,"P",{"data-svelte-h":!0}),T(ye)!=="svelte-1y0kl1b"&&(ye.innerHTML=Zl),ks=i(e),U(Je.$$.fragment,e),$s=i(e),be=h(e,"P",{"data-svelte-h":!0}),T(be)!=="svelte-rgaukq"&&(be.textContent=Gl),Rs=i(e),U(je.$$.fragment,e),_s=i(e),U(he.$$.fragment,e),Ns=i(e),fe=h(e,"P",{"data-svelte-h":!0}),T(fe)!=="svelte-yjini6"&&(fe.innerHTML=Cl),xs=i(e),U(Te.$$.fragment,e),Bs=i(e),we=h(e,"P",{"data-svelte-h":!0}),T(we)!=="svelte-tbk9kh"&&(we.textContent=Il),vs=i(e),U(ge.$$.fragment,e),Xs=i(e),Qe=h(e,"P",{"data-svelte-h":!0}),T(Qe)!=="svelte-ep5a0v"&&(Qe.innerHTML=kl),Vs=i(e),x.l(e),qe=i(e),Ze=h(e,"P",{"data-svelte-h":!0}),T(Ze)!=="svelte-1vq7v6g"&&(Ze.innerHTML=$l),Ws=i(e),U(Ge.$$.fragment,e),zs=i(e),Ce=h(e,"P",{"data-svelte-h":!0}),T(Ce)!=="svelte-wrdycy"&&(Ce.textContent=Rl),Ys=i(e),v.l(e),De=i(e),Ie=h(e,"P",{"data-svelte-h":!0}),T(Ie)!=="svelte-183luvk"&&(Ie.textContent=_l),Fs=i(e),U(ke.$$.fragment,e),Ss=i(e),$e=h(e,"P",{"data-svelte-h":!0}),T($e)!=="svelte-70zzak"&&($e.innerHTML=Nl),Es=i(e),Re=h(e,"P",{"data-svelte-h":!0}),T(Re)!=="svelte-z1611h"&&(Re.innerHTML=xl),As=i(e),U(_e.$$.fragment,e),Hs=i(e),Ne=h(e,"P",{"data-svelte-h":!0}),T(Ne)!=="svelte-1w5adwn"&&(Ne.innerHTML=Bl),qs=i(e),V.l(e),Le=i(e),xe=h(e,"P",{"data-svelte-h":!0}),T(xe)!=="svelte-v8tlmq"&&(xe.textContent=vl),Ds=i(e),U(Be.$$.fragment,e),Ls=i(e),ve=h(e,"P",{"data-svelte-h":!0}),T(ve)!=="svelte-vun2q"&&(ve.innerHTML=Xl),Ks=i(e),U(Xe.$$.fragment,e),Ps=i(e),Ve=h(e,"P",{"data-svelte-h":!0}),T(Ve)!=="svelte-j214oi"&&(Ve.textContent=Vl),Os=i(e),U(We.$$.fragment,e),el=i(e),U(ze.$$.fragment,e),sl=i(e),Ye=h(e,"P",{"data-svelte-h":!0}),T(Ye)!=="svelte-mo1i2k"&&(Ye.textContent=Wl),ll=i(e),U(Y.$$.fragment,e),tl=i(e),U(Fe.$$.fragment,e),al=i(e),Ke=h(e,"P",{}),Pl(Ke).forEach(l),this.h()},h(){Pe(a,"name","hf:doc:metadata"),Pe(a,"content",wt),Pe(W,"class","flex justify-center"),Pe(_,"border","1"),Pe(_,"class","dataframe"),pl(_,"table-layout","fixed"),pl(_,"word-wrap","break-word"),pl(_,"width","100%")},m(e,s){it(document.head,a),t(e,p,s),t(e,n,s),t(e,w,s),y(m,e,s),t(e,c,s),y(Q,e,s),t(e,b,s),y(G,e,s),t(e,k,s),Se[$].m(e,s),t(e,C,s),t(e,R,s),t(e,g,s),y(F,e,s),t(e,es,s),y(S,e,s),t(e,ss,s),t(e,E,s),t(e,ls,s),t(e,A,s),t(e,ts,s),t(e,W,s),t(e,as,s),y(H,e,s),t(e,ns,s),t(e,q,s),t(e,os,s),y(D,e,s),t(e,is,s),t(e,L,s),t(e,rs,s),y(K,e,s),t(e,ms,s),y(P,e,s),t(e,ds,s),t(e,O,s),t(e,Ms,s),y(ee,e,s),t(e,ps,s),y(se,e,s),t(e,cs,s),t(e,le,s),t(e,us,s),y(te,e,s),t(e,Us,s),y(ae,e,s),t(e,ys,s),t(e,ne,s),t(e,Js,s),y(oe,e,s),t(e,bs,s),t(e,ie,s),t(e,js,s),y(re,e,s),t(e,hs,s),y(me,e,s),t(e,fs,s),t(e,de,s),t(e,Ts,s),y(Me,e,s),t(e,ws,s),t(e,_,s),t(e,gs,s),t(e,pe,s),t(e,Qs,s),y(ce,e,s),t(e,Zs,s),y(ue,e,s),t(e,Gs,s),t(e,Ue,s),t(e,Cs,s),y(z,e,s),t(e,Is,s),t(e,ye,s),t(e,ks,s),y(Je,e,s),t(e,$s,s),t(e,be,s),t(e,Rs,s),y(je,e,s),t(e,_s,s),y(he,e,s),t(e,Ns,s),t(e,fe,s),t(e,xs,s),y(Te,e,s),t(e,Bs,s),t(e,we,s),t(e,vs,s),y(ge,e,s),t(e,Xs,s),t(e,Qe,s),t(e,Vs,s),Ee[N].m(e,s),t(e,qe,s),t(e,Ze,s),t(e,Ws,s),y(Ge,e,s),t(e,zs,s),t(e,Ce,s),t(e,Ys,s),Ae[B].m(e,s),t(e,De,s),t(e,Ie,s),t(e,Fs,s),y(ke,e,s),t(e,Ss,s),t(e,$e,s),t(e,Es,s),t(e,Re,s),t(e,As,s),y(_e,e,s),t(e,Hs,s),t(e,Ne,s),t(e,qs,s),He[X].m(e,s),t(e,Le,s),t(e,xe,s),t(e,Ds,s),y(Be,e,s),t(e,Ls,s),t(e,ve,s),t(e,Ks,s),y(Xe,e,s),t(e,Ps,s),t(e,Ve,s),t(e,Os,s),y(We,e,s),t(e,el,s),y(ze,e,s),t(e,sl,s),t(e,Ye,s),t(e,ll,s),y(Y,e,s),t(e,tl,s),y(Fe,e,s),t(e,al,s),t(e,Ke,s),nl=!0},p(e,[s]){const Dl={};s&1&&(Dl.fw=e[0]),m.$set(Dl);let rl=$;$=Yl(e),$!==rl&&(il(),d(Se[rl],1,1,()=>{Se[rl]=null}),ol(),I=Se[$],I||(I=Se[$]=zl[$](e),I.c()),M(I,1),I.m(C.parentNode,C));const Ll={};s&2&&(Ll.$$scope={dirty:s,ctx:e}),z.$set(Ll);let ml=N;N=Sl(e),N!==ml&&(il(),d(Ee[ml],1,1,()=>{Ee[ml]=null}),ol(),x=Ee[N],x||(x=Ee[N]=Fl[N](e),x.c()),M(x,1),x.m(qe.parentNode,qe));let dl=B;B=Al(e),B!==dl&&(il(),d(Ae[dl],1,1,()=>{Ae[dl]=null}),ol(),v=Ae[B],v||(v=Ae[B]=El[B](e),v.c()),M(v,1),v.m(De.parentNode,De));let Ml=X;X=ql(e),X!==Ml&&(il(),d(He[Ml],1,1,()=>{He[Ml]=null}),ol(),V=He[X],V||(V=He[X]=Hl[X](e),V.c()),M(V,1),V.m(Le.parentNode,Le));const Kl={};s&2&&(Kl.$$scope={dirty:s,ctx:e}),Y.$set(Kl)},i(e){nl||(M(m.$$.fragment,e),M(Q.$$.fragment,e),M(G.$$.fragment,e),M(I),M(F.$$.fragment,e),M(S.$$.fragment,e),M(H.$$.fragment,e),M(D.$$.fragment,e),M(K.$$.fragment,e),M(P.$$.fragment,e),M(ee.$$.fragment,e),M(se.$$.fragment,e),M(te.$$.fragment,e),M(ae.$$.fragment,e),M(oe.$$.fragment,e),M(re.$$.fragment,e),M(me.$$.fragment,e),M(Me.$$.fragment,e),M(ce.$$.fragment,e),M(ue.$$.fragment,e),M(z.$$.fragment,e),M(Je.$$.fragment,e),M(je.$$.fragment,e),M(he.$$.fragment,e),M(Te.$$.fragment,e),M(ge.$$.fragment,e),M(x),M(Ge.$$.fragment,e),M(v),M(ke.$$.fragment,e),M(_e.$$.fragment,e),M(V),M(Be.$$.fragment,e),M(Xe.$$.fragment,e),M(We.$$.fragment,e),M(ze.$$.fragment,e),M(Y.$$.fragment,e),M(Fe.$$.fragment,e),nl=!0)},o(e){d(m.$$.fragment,e),d(Q.$$.fragment,e),d(G.$$.fragment,e),d(I),d(F.$$.fragment,e),d(S.$$.fragment,e),d(H.$$.fragment,e),d(D.$$.fragment,e),d(K.$$.fragment,e),d(P.$$.fragment,e),d(ee.$$.fragment,e),d(se.$$.fragment,e),d(te.$$.fragment,e),d(ae.$$.fragment,e),d(oe.$$.fragment,e),d(re.$$.fragment,e),d(me.$$.fragment,e),d(Me.$$.fragment,e),d(ce.$$.fragment,e),d(ue.$$.fragment,e),d(z.$$.fragment,e),d(Je.$$.fragment,e),d(je.$$.fragment,e),d(he.$$.fragment,e),d(Te.$$.fragment,e),d(ge.$$.fragment,e),d(x),d(Ge.$$.fragment,e),d(v),d(ke.$$.fragment,e),d(_e.$$.fragment,e),d(V),d(Be.$$.fragment,e),d(Xe.$$.fragment,e),d(We.$$.fragment,e),d(ze.$$.fragment,e),d(Y.$$.fragment,e),d(Fe.$$.fragment,e),nl=!1},d(e){e&&(l(p),l(n),l(w),l(c),l(b),l(k),l(C),l(R),l(g),l(es),l(ss),l(E),l(ls),l(A),l(ts),l(W),l(as),l(ns),l(q),l(os),l(is),l(L),l(rs),l(ms),l(ds),l(O),l(Ms),l(ps),l(cs),l(le),l(us),l(Us),l(ys),l(ne),l(Js),l(bs),l(ie),l(js),l(hs),l(fs),l(de),l(Ts),l(ws),l(_),l(gs),l(pe),l(Qs),l(Zs),l(Gs),l(Ue),l(Cs),l(Is),l(ye),l(ks),l($s),l(be),l(Rs),l(_s),l(Ns),l(fe),l(xs),l(Bs),l(we),l(vs),l(Xs),l(Qe),l(Vs),l(qe),l(Ze),l(Ws),l(zs),l(Ce),l(Ys),l(De),l(Ie),l(Fs),l(Ss),l($e),l(Es),l(Re),l(As),l(Hs),l(Ne),l(qs),l(Le),l(xe),l(Ds),l(Ls),l(ve),l(Ks),l(Ps),l(Ve),l(Os),l(el),l(sl),l(Ye),l(ll),l(tl),l(al),l(Ke)),l(a),J(m,e),J(Q,e),J(G,e),Se[$].d(e),J(F,e),J(S,e),J(H,e),J(D,e),J(K,e),J(P,e),J(ee,e),J(se,e),J(te,e),J(ae,e),J(oe,e),J(re,e),J(me,e),J(Me,e),J(ce,e),J(ue,e),J(z,e),J(Je,e),J(je,e),J(he,e),J(Te,e),J(ge,e),Ee[N].d(e),J(Ge,e),Ae[B].d(e),J(ke,e),J(_e,e),He[X].d(e),J(Be,e),J(Xe,e),J(We,e),J(ze,e),J(Y,e),J(Fe,e)}}}const wt='{"title":"Busca semântica com o FAISS","local":"busca-semântica-com-o-faiss","sections":[{"title":"Usando embeddings para pesquisa semântica","local":"usando-embeddings-para-pesquisa-semântica","sections":[],"depth":2},{"title":"Carregando e preparando o conjunto de dados","local":"carregando-e-preparando-o-conjunto-de-dados","sections":[],"depth":2},{"title":"Criando embeddings de texto","local":"criando-embeddings-de-texto","sections":[],"depth":2},{"title":"Usando FAISS para busca de similaridade","local":"usando-faiss-para-busca-de-similaridade","sections":[],"depth":2}],"depth":1}';function gt(Z,a,p){let n="pt";return tt(()=>{const w=new URLSearchParams(window.location.search);p(0,n=w.get("fw")||"pt")}),[n]}class _t extends at{constructor(a){super(),nt(this,a,gt,Tt,lt,{})}}export{_t as component};
