import{s as Pl,o as Ol,n as Ll}from"../chunks/scheduler.37c15a92.js";import{S as et,i as st,g as j,s as i,r as u,A as lt,h,f as l,c as r,j as ql,u as U,x as f,k as Le,l as rl,y as tt,a as t,v as y,t as m,b as ll,d as M,w as J,p as tl}from"../chunks/index.2bf4358c.js";import{T as Dl}from"../chunks/Tip.363c041f.js";import{Y as at}from"../chunks/Youtube.1e50a667.js";import{C as T}from"../chunks/CodeBlock.4f5fc1ad.js";import{C as Kl}from"../chunks/CourseFloatingBanner.15ba07e6.js";import{F as nt}from"../chunks/FrameworkSwitchCourse.8d4d4ab6.js";import{H as Ke}from"../chunks/Heading.8ada512a.js";function ot(C){let a,p;return a=new Kl({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){m(a.$$.fragment,n),p=!1},d(n){J(a,n)}}}function it(C){let a,p;return a=new Kl({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){m(a.$$.fragment,n),p=!1},d(n){J(a,n)}}}function rt(C){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}),f(a)!=="svelte-83kmej"&&(a.innerHTML=p)},m(n,w){t(n,a,w)},p:Ll,d(n){n&&l(a)}}}function dt(C){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!",d;return a=new T({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=i(),n=j("p"),n.innerHTML=w},l(c){U(a.$$.fragment,c),p=r(c),n=h(c,"P",{"data-svelte-h":!0}),f(n)!=="svelte-m83kxk"&&(n.innerHTML=w)},m(c,G){y(a,c,G),t(c,p,G),t(c,n,G),d=!0},i(c){d||(M(a.$$.fragment,c),d=!0)},o(c){m(a.$$.fragment,c),d=!1},d(c){c&&(l(p),l(n)),J(a,c)}}}function mt(C){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:",d,c,G;return a=new T({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 T({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=i(),n=j("p"),n.textContent=w,d=i(),u(c.$$.fragment)},l(b){U(a.$$.fragment,b),p=r(b),n=h(b,"P",{"data-svelte-h":!0}),f(n)!=="svelte-19fxoub"&&(n.textContent=w),d=r(b),U(c.$$.fragment,b)},m(b,Q){y(a,b,Q),t(b,p,Q),t(b,n,Q),t(b,d,Q),y(c,b,Q),G=!0},i(b){G||(M(a.$$.fragment,b),M(c.$$.fragment,b),G=!0)},o(b){m(a.$$.fragment,b),m(c.$$.fragment,b),G=!1},d(b){b&&(l(p),l(n),l(d)),J(a,b),J(c,b)}}}function Mt(C){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:",d,c,G,b,Q,Z,R="Ó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:",k,I,$;return a=new T({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 T({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 T({props:{code:"VGVuc29yU2hhcGUoJTVCMSUyQyUyMDc2OCU1RCk=",highlighted:'TensorShape([<span class="hljs-number">1</span>, <span class="hljs-number">768</span>])',wrap:!1}}),I=new T({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=i(),n=j("p"),n.textContent=w,d=i(),u(c.$$.fragment),G=i(),u(b.$$.fragment),Q=i(),Z=j("p"),Z.innerHTML=R,k=i(),u(I.$$.fragment)},l(o){U(a.$$.fragment,o),p=r(o),n=h(o,"P",{"data-svelte-h":!0}),f(n)!=="svelte-1yecorf"&&(n.textContent=w),d=r(o),U(c.$$.fragment,o),G=r(o),U(b.$$.fragment,o),Q=r(o),Z=h(o,"P",{"data-svelte-h":!0}),f(Z)!=="svelte-whkpu9"&&(Z.innerHTML=R),k=r(o),U(I.$$.fragment,o)},m(o,g){y(a,o,g),t(o,p,g),t(o,n,g),t(o,d,g),y(c,o,g),t(o,G,g),y(b,o,g),t(o,Q,g),t(o,Z,g),t(o,k,g),y(I,o,g),$=!0},i(o){$||(M(a.$$.fragment,o),M(c.$$.fragment,o),M(b.$$.fragment,o),M(I.$$.fragment,o),$=!0)},o(o){m(a.$$.fragment,o),m(c.$$.fragment,o),m(b.$$.fragment,o),m(I.$$.fragment,o),$=!1},d(o){o&&(l(p),l(n),l(d),l(G),l(Q),l(Z),l(k)),J(a,o),J(c,o),J(b,o),J(I,o)}}}function pt(C){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:",d,c,G,b,Q,Z,R="Ó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:",k,I,$;return a=new T({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 T({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 T({props:{code:"dG9yY2guU2l6ZSglNUIxJTJDJTIwNzY4JTVEKQ==",highlighted:'torch.Size([<span class="hljs-number">1</span>, <span class="hljs-number">768</span>])',wrap:!1}}),I=new T({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=i(),n=j("p"),n.textContent=w,d=i(),u(c.$$.fragment),G=i(),u(b.$$.fragment),Q=i(),Z=j("p"),Z.innerHTML=R,k=i(),u(I.$$.fragment)},l(o){U(a.$$.fragment,o),p=r(o),n=h(o,"P",{"data-svelte-h":!0}),f(n)!=="svelte-1yecorf"&&(n.textContent=w),d=r(o),U(c.$$.fragment,o),G=r(o),U(b.$$.fragment,o),Q=r(o),Z=h(o,"P",{"data-svelte-h":!0}),f(Z)!=="svelte-whkpu9"&&(Z.innerHTML=R),k=r(o),U(I.$$.fragment,o)},m(o,g){y(a,o,g),t(o,p,g),t(o,n,g),t(o,d,g),y(c,o,g),t(o,G,g),y(b,o,g),t(o,Q,g),t(o,Z,g),t(o,k,g),y(I,o,g),$=!0},i(o){$||(M(a.$$.fragment,o),M(c.$$.fragment,o),M(b.$$.fragment,o),M(I.$$.fragment,o),$=!0)},o(o){m(a.$$.fragment,o),m(c.$$.fragment,o),m(b.$$.fragment,o),m(I.$$.fragment,o),$=!1},d(o){o&&(l(p),l(n),l(d),l(G),l(Q),l(Z),l(k)),J(a,o),J(c,o),J(b,o),J(I,o)}}}function ct(C){let a,p,n,w;return a=new T({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 T({props:{code:"KDElMkMlMjA3Njgp",highlighted:'(<span class="hljs-number">1</span>, <span class="hljs-number">768</span>)',wrap:!1}}),{c(){u(a.$$.fragment),p=i(),u(n.$$.fragment)},l(d){U(a.$$.fragment,d),p=r(d),U(n.$$.fragment,d)},m(d,c){y(a,d,c),t(d,p,c),y(n,d,c),w=!0},i(d){w||(M(a.$$.fragment,d),M(n.$$.fragment,d),w=!0)},o(d){m(a.$$.fragment,d),m(n.$$.fragment,d),w=!1},d(d){d&&l(p),J(a,d),J(n,d)}}}function ut(C){let a,p,n,w;return a=new T({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 T({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=i(),u(n.$$.fragment)},l(d){U(a.$$.fragment,d),p=r(d),U(n.$$.fragment,d)},m(d,c){y(a,d,c),t(d,p,c),y(n,d,c),w=!0},i(d){w||(M(a.$$.fragment,d),M(n.$$.fragment,d),w=!0)},o(d){m(a.$$.fragment,d),m(n.$$.fragment,d),w=!1},d(d){d&&l(p),J(a,d),J(n,d)}}}function Ut(C){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}),f(a)!=="svelte-1c1kivx"&&(a.innerHTML=p)},m(n,w){t(n,a,w)},p:Ll,d(n){n&&l(a)}}}function yt(C){let a,p,n,w,d,c,G,b,Q,Z,R,k,I='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!',$,o,g,F,Pe,S,dl='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.',Oe,E,ml="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.",es,W,Ml='<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."/>',ss,A,ls,H,pl="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:",ts,q,as,D,cl='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>:',ns,L,os,K,is,P,ul="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:",rs,O,ds,ee,ms,se,Ul="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:",Ms,le,ps,te,cs,ae,yl='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:',us,ne,Us,oe,Jl="Se inspecionarmos a primeira linha neste <code>DataFrame</code>, podemos ver que há quatro comentários associados a esta issue:",ys,ie,Js,re,bs,de,bl="Quando explodimos <code>df</code>, esperamos obter uma linha para cada um desses comentários. Vamos verificar se é o caso:",js,me,hs,_,jl='<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>',Ts,Me,hl="Ó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",fs,pe,ws,ce,gs,ue,Tl="Ok, isso nos deu alguns milhares de comentários para trabalhar!",Qs,z,Zs,Ue,fl="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:",Gs,ye,Cs,Je,wl="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:",Is,be,ks,je,$s,he,gl="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>:",Rs,Te,_s,fe,Ql="Finalmente estamos prontos para criar alguns embeddings! Vamos dar uma olhada.",Ns,we,xs,ge,Zl='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:',Bs,N,x,Ae,Qe,Gl="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:",vs,Ze,Xs,Ge,Cl="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:",Vs,B,v,He,Ce,Il="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.",Ws,Ie,zs,ke,kl='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.',Ys,$e,$l="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:",Fs,Re,Ss,_e,Rl="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:",Es,X,V,qe,Ne,_l="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:",As,xe,Hs,Be,Nl="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:",qs,ve,Ds,Xe,xl="Agora podemos iterar nas primeiras linhas para ver como nossa consulta correspondeu aos comentários disponíveis:",Ls,Ve,Ks,We,Ps,ze,Bl="Nada mal! Nosso segundo resultado parece corresponder à consulta.",Os,Y,el,De,sl;d=new nt({props:{fw:C[0]}}),G=new Ke({props:{title:"Busca semântica com o FAISS",local:"busca-semântica-com-o-faiss",headingTag:"h1"}});const vl=[it,ot],Ye=[];function Xl(e,s){return e[0]==="pt"?0:1}Q=Xl(C),Z=Ye[Q]=vl[Q](C),o=new at({props:{id:"OATCgQtNX2o"}}),F=new Ke({props:{title:"Usando embeddings para pesquisa semântica",local:"usando-embeddings-para-pesquisa-semântica",headingTag:"h2"}}),A=new Ke({props:{title:"Carregando e preparando o conjunto de dados",local:"carregando-e-preparando-o-conjunto-de-dados",headingTag:"h2"}}),q=new T({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}}),L=new T({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}}),K=new T({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}}),O=new T({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}}),ee=new T({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}}),le=new T({props:{code:"Y29sdW1ucyUyMCUzRCUyMGlzc3Vlc19kYXRhc2V0LmNvbHVtbl9uYW1lcyUwQWNvbHVtbnNfdG9fa2VlcCUyMCUzRCUyMCU1QiUyMnRpdGxlJTIyJTJDJTIwJTIyYm9keSUyMiUyQyUyMCUyMmh0bWxfdXJsJTIyJTJDJTIwJTIyY29tbWVudHMlMjIlNUQlMEFjb2x1bW5zX3RvX3JlbW92ZSUyMCUzRCUyMHNldChjb2x1bW5zX3RvX2tlZXApLnN5bW1ldHJpY19kaWZmZXJlbmNlKGNvbHVtbnMpJTBBaXNzdWVzX2RhdGFzZXQlMjAlM0QlMjBpc3N1ZXNfZGF0YXNldC5yZW1vdmVfY29sdW1ucyhjb2x1bW5zX3RvX3JlbW92ZSklMEFpc3N1ZXNfZGF0YXNldA==",highlighted:`columns = issues_dataset.column_names
columns_to_keep = [<span class="hljs-string">&quot;title&quot;</span>, <span class="hljs-string">&quot;body&quot;</span>, <span class="hljs-string">&quot;html_url&quot;</span>, <span class="hljs-string">&quot;comments&quot;</span>]
columns_to_remove = <span class="hljs-built_in">set</span>(columns_to_keep).symmetric_difference(columns)
issues_dataset = issues_dataset.remove_columns(columns_to_remove)
issues_dataset`,wrap:!1}}),te=new T({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}}),ne=new T({props:{code:"aXNzdWVzX2RhdGFzZXQuc2V0X2Zvcm1hdCglMjJwYW5kYXMlMjIpJTBBZGYlMjAlM0QlMjBpc3N1ZXNfZGF0YXNldCU1QiUzQSU1RA==",highlighted:`issues_dataset.set_format(<span class="hljs-string">&quot;pandas&quot;</span>)
df = issues_dataset[:]`,wrap:!1}}),ie=new T({props:{code:"ZGYlNUIlMjJjb21tZW50cyUyMiU1RCU1QjAlNUQudG9saXN0KCk=",highlighted:'df[<span class="hljs-string">&quot;comments&quot;</span>][<span class="hljs-number">0</span>].tolist()',wrap:!1}}),re=new T({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 T({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}}),pe=new T({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}}),ce=new T({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 Dl({props:{$$slots:{default:[rt]},$$scope:{ctx:C}}}),ye=new T({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}}),be=new T({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}}),je=new T({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 T({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}}),we=new Ke({props:{title:"Criando embeddings de texto",local:"criando-embeddings-de-texto",headingTag:"h2"}});const Vl=[mt,dt],Fe=[];function Wl(e,s){return e[0]==="pt"?0:1}N=Wl(C),x=Fe[N]=Vl[N](C),Ze=new T({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 zl=[pt,Mt],Se=[];function Yl(e,s){return e[0]==="pt"?0:1}B=Yl(C),v=Se[B]=zl[B](C),Ie=new Ke({props:{title:"Usando FAISS para busca de similaridade",local:"usando-faiss-para-busca-de-similaridade",headingTag:"h2"}}),Re=new T({props:{code:"ZW1iZWRkaW5nc19kYXRhc2V0LmFkZF9mYWlzc19pbmRleChjb2x1bW4lM0QlMjJlbWJlZGRpbmdzJTIyKQ==",highlighted:'embeddings_dataset.add_faiss_index(column=<span class="hljs-string">&quot;embeddings&quot;</span>)',wrap:!1}});const Fl=[ut,ct],Ee=[];function Sl(e,s){return e[0]==="pt"?0:1}return X=Sl(C),V=Ee[X]=Fl[X](C),xe=new T({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}}),ve=new T({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}}),Ve=new T({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}}),We=new T({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 Dl({props:{$$slots:{default:[Ut]},$$scope:{ctx:C}}}),{c(){a=j("meta"),p=i(),n=j("p"),w=i(),u(d.$$.fragment),c=i(),u(G.$$.fragment),b=i(),Z.c(),R=i(),k=j("p"),k.innerHTML=I,$=i(),u(o.$$.fragment),g=i(),u(F.$$.fragment),Pe=i(),S=j("p"),S.innerHTML=dl,Oe=i(),E=j("p"),E.textContent=ml,es=i(),W=j("div"),W.innerHTML=Ml,ss=i(),u(A.$$.fragment),ls=i(),H=j("p"),H.textContent=pl,ts=i(),u(q.$$.fragment),as=i(),D=j("p"),D.innerHTML=cl,ns=i(),u(L.$$.fragment),os=i(),u(K.$$.fragment),is=i(),P=j("p"),P.innerHTML=ul,rs=i(),u(O.$$.fragment),ds=i(),u(ee.$$.fragment),ms=i(),se=j("p"),se.innerHTML=Ul,Ms=i(),u(le.$$.fragment),ps=i(),u(te.$$.fragment),cs=i(),ae=j("p"),ae.innerHTML=yl,us=i(),u(ne.$$.fragment),Us=i(),oe=j("p"),oe.innerHTML=Jl,ys=i(),u(ie.$$.fragment),Js=i(),u(re.$$.fragment),bs=i(),de=j("p"),de.innerHTML=bl,js=i(),u(me.$$.fragment),hs=i(),_=j("table"),_.innerHTML=jl,Ts=i(),Me=j("p"),Me.innerHTML=hl,fs=i(),u(pe.$$.fragment),ws=i(),u(ce.$$.fragment),gs=i(),ue=j("p"),ue.textContent=Tl,Qs=i(),u(z.$$.fragment),Zs=i(),Ue=j("p"),Ue.innerHTML=fl,Gs=i(),u(ye.$$.fragment),Cs=i(),Je=j("p"),Je.textContent=wl,Is=i(),u(be.$$.fragment),ks=i(),u(je.$$.fragment),$s=i(),he=j("p"),he.innerHTML=gl,Rs=i(),u(Te.$$.fragment),_s=i(),fe=j("p"),fe.textContent=Ql,Ns=i(),u(we.$$.fragment),xs=i(),ge=j("p"),ge.innerHTML=Zl,Bs=i(),x.c(),Ae=i(),Qe=j("p"),Qe.innerHTML=Gl,vs=i(),u(Ze.$$.fragment),Xs=i(),Ge=j("p"),Ge.textContent=Cl,Vs=i(),v.c(),He=i(),Ce=j("p"),Ce.textContent=Il,Ws=i(),u(Ie.$$.fragment),zs=i(),ke=j("p"),ke.innerHTML=kl,Ys=i(),$e=j("p"),$e.innerHTML=$l,Fs=i(),u(Re.$$.fragment),Ss=i(),_e=j("p"),_e.innerHTML=Rl,Es=i(),V.c(),qe=i(),Ne=j("p"),Ne.textContent=_l,As=i(),u(xe.$$.fragment),Hs=i(),Be=j("p"),Be.innerHTML=Nl,qs=i(),u(ve.$$.fragment),Ds=i(),Xe=j("p"),Xe.textContent=xl,Ls=i(),u(Ve.$$.fragment),Ks=i(),u(We.$$.fragment),Ps=i(),ze=j("p"),ze.textContent=Bl,Os=i(),u(Y.$$.fragment),el=i(),De=j("p"),this.h()},l(e){const s=lt("svelte-u9bgzb",document.head);a=h(s,"META",{name:!0,content:!0}),s.forEach(l),p=r(e),n=h(e,"P",{}),ql(n).forEach(l),w=r(e),U(d.$$.fragment,e),c=r(e),U(G.$$.fragment,e),b=r(e),Z.l(e),R=r(e),k=h(e,"P",{"data-svelte-h":!0}),f(k)!=="svelte-gjg3xh"&&(k.innerHTML=I),$=r(e),U(o.$$.fragment,e),g=r(e),U(F.$$.fragment,e),Pe=r(e),S=h(e,"P",{"data-svelte-h":!0}),f(S)!=="svelte-isds6h"&&(S.innerHTML=dl),Oe=r(e),E=h(e,"P",{"data-svelte-h":!0}),f(E)!=="svelte-1xgdub6"&&(E.textContent=ml),es=r(e),W=h(e,"DIV",{class:!0,"data-svelte-h":!0}),f(W)!=="svelte-yxatr"&&(W.innerHTML=Ml),ss=r(e),U(A.$$.fragment,e),ls=r(e),H=h(e,"P",{"data-svelte-h":!0}),f(H)!=="svelte-r8uu0o"&&(H.textContent=pl),ts=r(e),U(q.$$.fragment,e),as=r(e),D=h(e,"P",{"data-svelte-h":!0}),f(D)!=="svelte-136cz13"&&(D.innerHTML=cl),ns=r(e),U(L.$$.fragment,e),os=r(e),U(K.$$.fragment,e),is=r(e),P=h(e,"P",{"data-svelte-h":!0}),f(P)!=="svelte-1dvqw0"&&(P.innerHTML=ul),rs=r(e),U(O.$$.fragment,e),ds=r(e),U(ee.$$.fragment,e),ms=r(e),se=h(e,"P",{"data-svelte-h":!0}),f(se)!=="svelte-nwy9uh"&&(se.innerHTML=Ul),Ms=r(e),U(le.$$.fragment,e),ps=r(e),U(te.$$.fragment,e),cs=r(e),ae=h(e,"P",{"data-svelte-h":!0}),f(ae)!=="svelte-xiuizr"&&(ae.innerHTML=yl),us=r(e),U(ne.$$.fragment,e),Us=r(e),oe=h(e,"P",{"data-svelte-h":!0}),f(oe)!=="svelte-b7um6f"&&(oe.innerHTML=Jl),ys=r(e),U(ie.$$.fragment,e),Js=r(e),U(re.$$.fragment,e),bs=r(e),de=h(e,"P",{"data-svelte-h":!0}),f(de)!=="svelte-tnp87o"&&(de.innerHTML=bl),js=r(e),U(me.$$.fragment,e),hs=r(e),_=h(e,"TABLE",{border:!0,class:!0,style:!0,"data-svelte-h":!0}),f(_)!=="svelte-1g5whzd"&&(_.innerHTML=jl),Ts=r(e),Me=h(e,"P",{"data-svelte-h":!0}),f(Me)!=="svelte-11z2n8l"&&(Me.innerHTML=hl),fs=r(e),U(pe.$$.fragment,e),ws=r(e),U(ce.$$.fragment,e),gs=r(e),ue=h(e,"P",{"data-svelte-h":!0}),f(ue)!=="svelte-11iemom"&&(ue.textContent=Tl),Qs=r(e),U(z.$$.fragment,e),Zs=r(e),Ue=h(e,"P",{"data-svelte-h":!0}),f(Ue)!=="svelte-1y0kl1b"&&(Ue.innerHTML=fl),Gs=r(e),U(ye.$$.fragment,e),Cs=r(e),Je=h(e,"P",{"data-svelte-h":!0}),f(Je)!=="svelte-rgaukq"&&(Je.textContent=wl),Is=r(e),U(be.$$.fragment,e),ks=r(e),U(je.$$.fragment,e),$s=r(e),he=h(e,"P",{"data-svelte-h":!0}),f(he)!=="svelte-yjini6"&&(he.innerHTML=gl),Rs=r(e),U(Te.$$.fragment,e),_s=r(e),fe=h(e,"P",{"data-svelte-h":!0}),f(fe)!=="svelte-tbk9kh"&&(fe.textContent=Ql),Ns=r(e),U(we.$$.fragment,e),xs=r(e),ge=h(e,"P",{"data-svelte-h":!0}),f(ge)!=="svelte-ep5a0v"&&(ge.innerHTML=Zl),Bs=r(e),x.l(e),Ae=r(e),Qe=h(e,"P",{"data-svelte-h":!0}),f(Qe)!=="svelte-1vq7v6g"&&(Qe.innerHTML=Gl),vs=r(e),U(Ze.$$.fragment,e),Xs=r(e),Ge=h(e,"P",{"data-svelte-h":!0}),f(Ge)!=="svelte-wrdycy"&&(Ge.textContent=Cl),Vs=r(e),v.l(e),He=r(e),Ce=h(e,"P",{"data-svelte-h":!0}),f(Ce)!=="svelte-183luvk"&&(Ce.textContent=Il),Ws=r(e),U(Ie.$$.fragment,e),zs=r(e),ke=h(e,"P",{"data-svelte-h":!0}),f(ke)!=="svelte-70zzak"&&(ke.innerHTML=kl),Ys=r(e),$e=h(e,"P",{"data-svelte-h":!0}),f($e)!=="svelte-z1611h"&&($e.innerHTML=$l),Fs=r(e),U(Re.$$.fragment,e),Ss=r(e),_e=h(e,"P",{"data-svelte-h":!0}),f(_e)!=="svelte-1w5adwn"&&(_e.innerHTML=Rl),Es=r(e),V.l(e),qe=r(e),Ne=h(e,"P",{"data-svelte-h":!0}),f(Ne)!=="svelte-v8tlmq"&&(Ne.textContent=_l),As=r(e),U(xe.$$.fragment,e),Hs=r(e),Be=h(e,"P",{"data-svelte-h":!0}),f(Be)!=="svelte-vun2q"&&(Be.innerHTML=Nl),qs=r(e),U(ve.$$.fragment,e),Ds=r(e),Xe=h(e,"P",{"data-svelte-h":!0}),f(Xe)!=="svelte-j214oi"&&(Xe.textContent=xl),Ls=r(e),U(Ve.$$.fragment,e),Ks=r(e),U(We.$$.fragment,e),Ps=r(e),ze=h(e,"P",{"data-svelte-h":!0}),f(ze)!=="svelte-mo1i2k"&&(ze.textContent=Bl),Os=r(e),U(Y.$$.fragment,e),el=r(e),De=h(e,"P",{}),ql(De).forEach(l),this.h()},h(){Le(a,"name","hf:doc:metadata"),Le(a,"content",Jt),Le(W,"class","flex justify-center"),Le(_,"border","1"),Le(_,"class","dataframe"),rl(_,"table-layout","fixed"),rl(_,"word-wrap","break-word"),rl(_,"width","100%")},m(e,s){tt(document.head,a),t(e,p,s),t(e,n,s),t(e,w,s),y(d,e,s),t(e,c,s),y(G,e,s),t(e,b,s),Ye[Q].m(e,s),t(e,R,s),t(e,k,s),t(e,$,s),y(o,e,s),t(e,g,s),y(F,e,s),t(e,Pe,s),t(e,S,s),t(e,Oe,s),t(e,E,s),t(e,es,s),t(e,W,s),t(e,ss,s),y(A,e,s),t(e,ls,s),t(e,H,s),t(e,ts,s),y(q,e,s),t(e,as,s),t(e,D,s),t(e,ns,s),y(L,e,s),t(e,os,s),y(K,e,s),t(e,is,s),t(e,P,s),t(e,rs,s),y(O,e,s),t(e,ds,s),y(ee,e,s),t(e,ms,s),t(e,se,s),t(e,Ms,s),y(le,e,s),t(e,ps,s),y(te,e,s),t(e,cs,s),t(e,ae,s),t(e,us,s),y(ne,e,s),t(e,Us,s),t(e,oe,s),t(e,ys,s),y(ie,e,s),t(e,Js,s),y(re,e,s),t(e,bs,s),t(e,de,s),t(e,js,s),y(me,e,s),t(e,hs,s),t(e,_,s),t(e,Ts,s),t(e,Me,s),t(e,fs,s),y(pe,e,s),t(e,ws,s),y(ce,e,s),t(e,gs,s),t(e,ue,s),t(e,Qs,s),y(z,e,s),t(e,Zs,s),t(e,Ue,s),t(e,Gs,s),y(ye,e,s),t(e,Cs,s),t(e,Je,s),t(e,Is,s),y(be,e,s),t(e,ks,s),y(je,e,s),t(e,$s,s),t(e,he,s),t(e,Rs,s),y(Te,e,s),t(e,_s,s),t(e,fe,s),t(e,Ns,s),y(we,e,s),t(e,xs,s),t(e,ge,s),t(e,Bs,s),Fe[N].m(e,s),t(e,Ae,s),t(e,Qe,s),t(e,vs,s),y(Ze,e,s),t(e,Xs,s),t(e,Ge,s),t(e,Vs,s),Se[B].m(e,s),t(e,He,s),t(e,Ce,s),t(e,Ws,s),y(Ie,e,s),t(e,zs,s),t(e,ke,s),t(e,Ys,s),t(e,$e,s),t(e,Fs,s),y(Re,e,s),t(e,Ss,s),t(e,_e,s),t(e,Es,s),Ee[X].m(e,s),t(e,qe,s),t(e,Ne,s),t(e,As,s),y(xe,e,s),t(e,Hs,s),t(e,Be,s),t(e,qs,s),y(ve,e,s),t(e,Ds,s),t(e,Xe,s),t(e,Ls,s),y(Ve,e,s),t(e,Ks,s),y(We,e,s),t(e,Ps,s),t(e,ze,s),t(e,Os,s),y(Y,e,s),t(e,el,s),t(e,De,s),sl=!0},p(e,[s]){const El={};s&1&&(El.fw=e[0]),d.$set(El);let al=Q;Q=Xl(e),Q!==al&&(tl(),m(Ye[al],1,1,()=>{Ye[al]=null}),ll(),Z=Ye[Q],Z||(Z=Ye[Q]=vl[Q](e),Z.c()),M(Z,1),Z.m(R.parentNode,R));const Al={};s&2&&(Al.$$scope={dirty:s,ctx:e}),z.$set(Al);let nl=N;N=Wl(e),N!==nl&&(tl(),m(Fe[nl],1,1,()=>{Fe[nl]=null}),ll(),x=Fe[N],x||(x=Fe[N]=Vl[N](e),x.c()),M(x,1),x.m(Ae.parentNode,Ae));let ol=B;B=Yl(e),B!==ol&&(tl(),m(Se[ol],1,1,()=>{Se[ol]=null}),ll(),v=Se[B],v||(v=Se[B]=zl[B](e),v.c()),M(v,1),v.m(He.parentNode,He));let il=X;X=Sl(e),X!==il&&(tl(),m(Ee[il],1,1,()=>{Ee[il]=null}),ll(),V=Ee[X],V||(V=Ee[X]=Fl[X](e),V.c()),M(V,1),V.m(qe.parentNode,qe));const Hl={};s&2&&(Hl.$$scope={dirty:s,ctx:e}),Y.$set(Hl)},i(e){sl||(M(d.$$.fragment,e),M(G.$$.fragment,e),M(Z),M(o.$$.fragment,e),M(F.$$.fragment,e),M(A.$$.fragment,e),M(q.$$.fragment,e),M(L.$$.fragment,e),M(K.$$.fragment,e),M(O.$$.fragment,e),M(ee.$$.fragment,e),M(le.$$.fragment,e),M(te.$$.fragment,e),M(ne.$$.fragment,e),M(ie.$$.fragment,e),M(re.$$.fragment,e),M(me.$$.fragment,e),M(pe.$$.fragment,e),M(ce.$$.fragment,e),M(z.$$.fragment,e),M(ye.$$.fragment,e),M(be.$$.fragment,e),M(je.$$.fragment,e),M(Te.$$.fragment,e),M(we.$$.fragment,e),M(x),M(Ze.$$.fragment,e),M(v),M(Ie.$$.fragment,e),M(Re.$$.fragment,e),M(V),M(xe.$$.fragment,e),M(ve.$$.fragment,e),M(Ve.$$.fragment,e),M(We.$$.fragment,e),M(Y.$$.fragment,e),sl=!0)},o(e){m(d.$$.fragment,e),m(G.$$.fragment,e),m(Z),m(o.$$.fragment,e),m(F.$$.fragment,e),m(A.$$.fragment,e),m(q.$$.fragment,e),m(L.$$.fragment,e),m(K.$$.fragment,e),m(O.$$.fragment,e),m(ee.$$.fragment,e),m(le.$$.fragment,e),m(te.$$.fragment,e),m(ne.$$.fragment,e),m(ie.$$.fragment,e),m(re.$$.fragment,e),m(me.$$.fragment,e),m(pe.$$.fragment,e),m(ce.$$.fragment,e),m(z.$$.fragment,e),m(ye.$$.fragment,e),m(be.$$.fragment,e),m(je.$$.fragment,e),m(Te.$$.fragment,e),m(we.$$.fragment,e),m(x),m(Ze.$$.fragment,e),m(v),m(Ie.$$.fragment,e),m(Re.$$.fragment,e),m(V),m(xe.$$.fragment,e),m(ve.$$.fragment,e),m(Ve.$$.fragment,e),m(We.$$.fragment,e),m(Y.$$.fragment,e),sl=!1},d(e){e&&(l(p),l(n),l(w),l(c),l(b),l(R),l(k),l($),l(g),l(Pe),l(S),l(Oe),l(E),l(es),l(W),l(ss),l(ls),l(H),l(ts),l(as),l(D),l(ns),l(os),l(is),l(P),l(rs),l(ds),l(ms),l(se),l(Ms),l(ps),l(cs),l(ae),l(us),l(Us),l(oe),l(ys),l(Js),l(bs),l(de),l(js),l(hs),l(_),l(Ts),l(Me),l(fs),l(ws),l(gs),l(ue),l(Qs),l(Zs),l(Ue),l(Gs),l(Cs),l(Je),l(Is),l(ks),l($s),l(he),l(Rs),l(_s),l(fe),l(Ns),l(xs),l(ge),l(Bs),l(Ae),l(Qe),l(vs),l(Xs),l(Ge),l(Vs),l(He),l(Ce),l(Ws),l(zs),l(ke),l(Ys),l($e),l(Fs),l(Ss),l(_e),l(Es),l(qe),l(Ne),l(As),l(Hs),l(Be),l(qs),l(Ds),l(Xe),l(Ls),l(Ks),l(Ps),l(ze),l(Os),l(el),l(De)),l(a),J(d,e),J(G,e),Ye[Q].d(e),J(o,e),J(F,e),J(A,e),J(q,e),J(L,e),J(K,e),J(O,e),J(ee,e),J(le,e),J(te,e),J(ne,e),J(ie,e),J(re,e),J(me,e),J(pe,e),J(ce,e),J(z,e),J(ye,e),J(be,e),J(je,e),J(Te,e),J(we,e),Fe[N].d(e),J(Ze,e),Se[B].d(e),J(Ie,e),J(Re,e),Ee[X].d(e),J(xe,e),J(ve,e),J(Ve,e),J(We,e),J(Y,e)}}}const Jt='{"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 bt(C,a,p){let n="pt";return Ol(()=>{const w=new URLSearchParams(window.location.search);p(0,n=w.get("fw")||"pt")}),[n]}class Gt extends et{constructor(a){super(),st(this,a,bt,yt,Pl,{})}}export{Gt as component};
