import{s as ts,o as ss,n as es}from"../chunks/scheduler.cc52f4b9.js";import{S as as,i as ns,e as h,s as i,c as u,h as is,a as f,d as t,b as o,f as Kt,g as U,j,k as Ke,w as dt,l as os,m as s,n as y,o as c,u as it,t as p,p as b,v as ot}from"../chunks/index.d2856393.js";import{T as Ot}from"../chunks/Tip.a5bdccc4.js";import{C as rs,H as Oe,E as Ms}from"../chunks/MermaidChart.svelte_svelte_type_style_lang.8ffb7edb.js";import{Y as cs}from"../chunks/Youtube.00df107c.js";import{C as T}from"../chunks/CodeBlock.5f8dc025.js";import{C as ls}from"../chunks/CourseFloatingBanner.59eb3fdc.js";import{F as ps}from"../chunks/FrameworkSwitchCourse.22a5e932.js";function ds(Z){let a,d;return a=new ls({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/it/chapter5/section6_tf.ipynb"},{label:"Aws Studio",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/master/course/it/chapter5/section6_tf.ipynb"}]}}),{c(){u(a.$$.fragment)},l(n){U(a.$$.fragment,n)},m(n,w){y(a,n,w),d=!0},i(n){d||(p(a.$$.fragment,n),d=!0)},o(n){c(a.$$.fragment,n),d=!1},d(n){b(a,n)}}}function ms(Z){let a,d;return a=new ls({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/it/chapter5/section6_pt.ipynb"},{label:"Aws Studio",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/master/course/it/chapter5/section6_pt.ipynb"}]}}),{c(){u(a.$$.fragment)},l(n){U(a.$$.fragment,n)},m(n,w){y(a,n,w),d=!0},i(n){d||(p(a.$$.fragment,n),d=!0)},o(n){c(a.$$.fragment,n),d=!1},d(n){b(a,n)}}}function us(Z){let a,d='✏️ <strong>Prova tu!</strong> Prova ad utilizzare <code>Dataset.map()</code> per far esplodere la colonna <code>commenti</code> di <code>issues_dataset</code> <em>senza</em> utilizzare Pandas. È un po’ difficile: potrebbe tornarti utile la sezione <a href="https://huggingface.co/docs/datasets/about_map_batch#batch-mapping" rel="nofollow">“Batch mapping”</a> della documentazione di 🤗 Datasets.';return{c(){a=h("p"),a.innerHTML=d},l(n){a=f(n,"P",{"data-svelte-h":!0}),j(a)!=="svelte-123safh"&&(a.innerHTML=d)},m(n,w){s(n,a,w)},p:es,d(n){n&&t(a)}}}function Us(Z){let a,d,n,w="Nota che abbiamo impostato <code>from_pt=True</code> come argomento del metodo <code>from_pretrained()</code>. Questo perchè il checkpoint <code>multi-qa-mpnet-base-dot-v1</code> ha solo pesi PyTorch, quindi impostare <code>from_pt=True</code> li convertirà automaticamente in formato TensorFlow. Come puoi vedere, è molto facile passare dall’uno all’altro su 🤗 Transformers!",M;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),d=i(),n=h("p"),n.innerHTML=w},l(m){U(a.$$.fragment,m),d=o(m),n=f(m,"P",{"data-svelte-h":!0}),j(n)!=="svelte-yr7k0b"&&(n.innerHTML=w)},m(m,Q){y(a,m,Q),s(m,d,Q),s(m,n,Q),M=!0},i(m){M||(p(a.$$.fragment,m),M=!0)},o(m){c(a.$$.fragment,m),M=!1},d(m){m&&(t(d),t(n)),b(a,m)}}}function ys(Z){let a,d,n,w="Per accelerare il processo di embedding, è bene usare la GPU per il modello e gli input, quindi:",M,m,Q;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}}),m=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),d=i(),n=h("p"),n.textContent=w,M=i(),u(m.$$.fragment)},l(J){U(a.$$.fragment,J),d=o(J),n=f(J,"P",{"data-svelte-h":!0}),j(n)!=="svelte-kh1hef"&&(n.textContent=w),M=o(J),U(m.$$.fragment,J)},m(J,G){y(a,J,G),s(J,d,G),s(J,n,G),s(J,M,G),y(m,J,G),Q=!0},i(J){Q||(p(a.$$.fragment,J),p(m.$$.fragment,J),Q=!0)},o(J){c(a.$$.fragment,J),c(m.$$.fragment,J),Q=!1},d(J){J&&(t(d),t(n),t(M)),b(a,J),b(m,J)}}}function bs(Z){let a,d,n,w="Possiamo testare la funzione dandole in input la prima voce testuale del nostro corpus e studiando le dimensioni dell’output:",M,m,Q,J,G,$,k="Bene, abbiamo convertito la prima voce del nostro corpus in un vettore a 768 dimensioni! Possiamo usare <code>Dataset.map()</code> per applicare la nostra funzione <code>get_embedding()</code> a ogni riga del nostro corpus, quindi creiamo una nuova colonna <code>embedding</code> così:",I,C,R;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}}),m=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}}),J=new T({props:{code:"VGVuc29yU2hhcGUoJTVCMSUyQyUyMDc2OCU1RCk=",highlighted:'TensorShape([<span class="hljs-number">1</span>, <span class="hljs-number">768</span>])',wrap:!1}}),C=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),d=i(),n=h("p"),n.textContent=w,M=i(),u(m.$$.fragment),Q=i(),u(J.$$.fragment),G=i(),$=h("p"),$.innerHTML=k,I=i(),u(C.$$.fragment)},l(r){U(a.$$.fragment,r),d=o(r),n=f(r,"P",{"data-svelte-h":!0}),j(n)!=="svelte-1cfq1o3"&&(n.textContent=w),M=o(r),U(m.$$.fragment,r),Q=o(r),U(J.$$.fragment,r),G=o(r),$=f(r,"P",{"data-svelte-h":!0}),j($)!=="svelte-ayfaqa"&&($.innerHTML=k),I=o(r),U(C.$$.fragment,r)},m(r,g){y(a,r,g),s(r,d,g),s(r,n,g),s(r,M,g),y(m,r,g),s(r,Q,g),y(J,r,g),s(r,G,g),s(r,$,g),s(r,I,g),y(C,r,g),R=!0},i(r){R||(p(a.$$.fragment,r),p(m.$$.fragment,r),p(J.$$.fragment,r),p(C.$$.fragment,r),R=!0)},o(r){c(a.$$.fragment,r),c(m.$$.fragment,r),c(J.$$.fragment,r),c(C.$$.fragment,r),R=!1},d(r){r&&(t(d),t(n),t(M),t(Q),t(G),t($),t(I)),b(a,r),b(m,r),b(J,r),b(C,r)}}}function Js(Z){let a,d,n,w="Possiamo testare la funzione sul primo testo nel nostro corpus, e ispezionandone le dimensioni dell’ouput:",M,m,Q,J,G,$,k="Bene, abbiamo convertito la prima voce del nostro corpus in un vettore a 768 dimensioni! Possiamo usare <code>Dataset.map()</code> per applicare la nostra funzione <code>get_embedding()</code> a ogni riga del nostro corpus, quindi creiamo una nuova colonna <code>embedding</code> così:",I,C,R;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}}),m=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}}),J=new T({props:{code:"dG9yY2guU2l6ZSglNUIxJTJDJTIwNzY4JTVEKQ==",highlighted:'torch.Size([<span class="hljs-number">1</span>, <span class="hljs-number">768</span>])',wrap:!1}}),C=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),d=i(),n=h("p"),n.textContent=w,M=i(),u(m.$$.fragment),Q=i(),u(J.$$.fragment),G=i(),$=h("p"),$.innerHTML=k,I=i(),u(C.$$.fragment)},l(r){U(a.$$.fragment,r),d=o(r),n=f(r,"P",{"data-svelte-h":!0}),j(n)!=="svelte-x4eorg"&&(n.textContent=w),M=o(r),U(m.$$.fragment,r),Q=o(r),U(J.$$.fragment,r),G=o(r),$=f(r,"P",{"data-svelte-h":!0}),j($)!=="svelte-ayfaqa"&&($.innerHTML=k),I=o(r),U(C.$$.fragment,r)},m(r,g){y(a,r,g),s(r,d,g),s(r,n,g),s(r,M,g),y(m,r,g),s(r,Q,g),y(J,r,g),s(r,G,g),s(r,$,g),s(r,I,g),y(C,r,g),R=!0},i(r){R||(p(a.$$.fragment,r),p(m.$$.fragment,r),p(J.$$.fragment,r),p(C.$$.fragment,r),R=!0)},o(r){c(a.$$.fragment,r),c(m.$$.fragment,r),c(J.$$.fragment,r),c(C.$$.fragment,r),R=!1},d(r){r&&(t(d),t(n),t(M),t(Q),t(G),t($),t(I)),b(a,r),b(m,r),b(J,r),b(C,r)}}}function hs(Z){let a,d,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),d=i(),u(n.$$.fragment)},l(M){U(a.$$.fragment,M),d=o(M),U(n.$$.fragment,M)},m(M,m){y(a,M,m),s(M,d,m),y(n,M,m),w=!0},i(M){w||(p(a.$$.fragment,M),p(n.$$.fragment,M),w=!0)},o(M){c(a.$$.fragment,M),c(n.$$.fragment,M),w=!1},d(M){M&&t(d),b(a,M),b(n,M)}}}function fs(Z){let a,d,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),d=i(),u(n.$$.fragment)},l(M){U(a.$$.fragment,M),d=o(M),U(n.$$.fragment,M)},m(M,m){y(a,M,m),s(M,d,m),y(n,M,m),w=!0},i(M){w||(p(a.$$.fragment,M),p(n.$$.fragment,M),w=!0)},o(M){c(a.$$.fragment,M),c(n.$$.fragment,M),w=!1},d(M){M&&t(d),b(a,M),b(n,M)}}}function Ts(Z){let a,d="✏️ <strong>Prova tu!</strong> Crea la tua query e prova a trovare una risposta tra i documenti raccolti. Potresti aver bisogno di aumentare il parametro <code>k</code> in <code>Dataset.get_nearest_examples()</code> per allargare la ricerca.";return{c(){a=h("p"),a.innerHTML=d},l(n){a=f(n,"P",{"data-svelte-h":!0}),j(a)!=="svelte-xjwbls"&&(a.innerHTML=d)},m(n,w){s(n,a,w)},p:es,d(n){n&&t(a)}}}function js(Z){let a,d,n,w,M,m,Q,J,G,$,k,I,C,R,r='Nella <a href="/course/chapter5/5">sezione 5</a> abbiamo creato un dataset di issue e commenti dalla repository GitHub di 🤗 Datasets. In questa sezione useremo queste informazioni per costrure un motore di ricerca semantico che ci può aiutare a trovare risposte alle nostre domande urgenti sulla libreria!',g,S,el,F,ll,E,mt='Come abbiamo visto nel <a href="/course/chapter1">Capitolo 1</a>, i language model basati su Transformer rappresentano ogni token in un testo come un <em>vettore</em>, detto <em>embedding</em>. È possibile “mettere insieme” i diversi embedding per creare una rappresentazione vettoriale di un’intera frase, paragrafo o (in alcuni casi) documento. Questi embedding possono essere usati per trovare documenti simili in un corpus calcolandone la similarità, ad esempio usando il prodotto scalere (o altre misure di similarità) tra ogni embedding, e restituendo i documenti più simili.',tl,H,ut="In questa sezione useremo gli embedding per sviluppare un motore di ricerca semantico. Questi motori di ricerca offrono diversi vantagig rispetto ai metodo convenzionali, basati sulla ricerca, all’interno dei documenti, delle parole chiavi presente in una query.",sl,V,Ut='<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."/>',al,A,nl,q,yt="La prima cosa che dobbiamo fare è scaricare il nostro dataset di issue, quindi utilizziamo la libreria 🤗 Hub per scaricare i file usando l’URL dell’Hub Hugging Face:",il,D,ol,L,bt='Se conseriamo l’URL iin <code>data_files</code>, possiamo caricare il dataset utilizzando il metodo introdotto nella <a href="/course/chapter5/2">sezione 2</a>:',rl,P,Ml,K,cl,O,Jt="Qui abbiamo specificato la sezione di defaul <code>train</code> in <code>load_dataset()</code>, così che questa funzione resituisce un <code>Dataset</code> invece di un <code>DatasetDict</code>. La prima cosa da fare è filtrare le richieste di pull, poichè queste tendono a essere usate raramente come risposta alle domande degli utenti, e introdurrebbero rumore nel nostro motore di ricerca. Come dovrebbe esser enoto, possiamo usare la funzione <code>Dataset.filter()</code> per escludere questi dati dal nostro dataset. Già che ci siamo, eliminiamo anche le righe senza commenti, poiché queste non presentano nessuna risposta alle domande degli utenti:",pl,ee,dl,le,ml,te,ht="Possiamo vedere che ci sono molte colonne nel nostro dataset, molte delle quali non servono alla costruzione del nostro motore di ricerca. Da una prospettiva di ricerca, le colonne maggiormente informative sono <code>title</code>, <code>body</code>, e <code>comments</code>, mentre <code>html_url</code> ci fornisce un link all’issue originale. Usiamo la funzione <code>Dataset.remove_columns()</code> per eliminare le colonne rimanenti:",ul,se,Ul,ae,yl,ne,ft='Per crare i nostri embedding arricchiremo ognu commento con il titolo e il corpo dell’issue, visto che questi campi spesso includono informazioni utili sul contesto. Poiché la nostra colonna <code>comment</code> è al momento una lista di commenti per ogni issue, dobbiamo “farla esplodere” così che ogni riga consista in una tupla <code>(html_url, title, body, comment)</code>. In panda è possibile farlo utilizzando la <a href="https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.explode.html" rel="nofollow">funzione <code>Dataframe.explode()</code></a>, che crea una nuova riga per ogni elemento in una colonna in formato di lista, ripetendo i valori di tutte le altre colonne. Per vederlo in azione, prima di tutto passiamo al formato <code>DataFrame</code>:',bl,ie,Jl,oe,Tt="Se diamo un’occhiata alla prima riga di questo <code>DataFrame</code>, possiamo vedere che ci sono quattro commenti associati con quest’issue:",hl,re,fl,Me,Tl,ce,jt="Quando “esplodiamo” <code>df</code>, ci aspettiamo di avere una riga per ognuno di questi commenti. Controlliamo se è così:",jl,pe,wl,_,wt='<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>',gl,de,gt="bene, possiamo vedere che le righe sono state duplicate, e che la colonna <code>comment</code> contiene i diversi comment! Ora che abbiamo finito con Pandas, possiamo passare velocemente a <code>Dataset</code> caricando il <code>DataFrame</code> in memoria:",Ql,me,Zl,ue,Gl,Ue,Qt="Perfetto, ora abbiamo qualche migliaio di commenti con cui lavorare!",Cl,W,Il,ye,Zt="Ora che abbiamo un commento per riga, creiamo una nuova colonna <code>comments_length</code> che contiene il numero di parole per ogni commento:",$l,be,kl,Je,Gt="Possiamo usare questa nuova colonna per eliminare i commenti brevi, che solitamente includono cose del tipo “cc @lewtun” o “Grazie!”, che non sono pertinenti per il nostro motore di ricerca. Non abbiamo un numero preciso da selezionare per questo filtro, ma 15 parole dovrebbero andare bene:",Rl,he,_l,fe,Nl,Te,Ct="Una volta data una pulizia al nostro dataset, possiamo concatenare il titolo, la descrizione e i commenti delle issue in una nuova colonna <code>text</code>. Come al solito , scriveremo una semplice funzione che possiamo passare a <code>Dataset.map()</code>:",Bl,je,xl,we,It="Siamo finalmente pronti a creare degli embedding! Diamo un’occhiata.",zl,ge,Xl,Qe,$t='Abbiamo visto nel <a href="/course/chapter2">Capitolo 2</a> che possiamo ottenere i token embedding utilizando la classe <code>AutoModel</code>. Dobbiamo solo scegliere un checkpoint valido da cui caricare il modell. Per fortuna, esiste una libreria chiamata <code>sentence-transformers</code>, dedicata alla creazione di embedding. Seguendo la descrizione nella <a href="https://www.sbert.net/examples/applications/semantic-search/README.html#symmetric-vs-asymmetric-semantic-search" rel="nofollow">documentazione</a>della libreria, il nostro caso d’uso è un esempio di <em>asymmetric semantic search</em> perché abbiamo una breve query per cui vogliamo trovare risposte in un documento lungo, come ad esempio un commento a un issue. La <a href="https://www.sbert.net/docs/pretrained_models.html#model-overview" rel="nofollow">scheda di riepilogo dei modelli</a> nella documentazione ci indica che il checkpoint <code>multi-qa-mpnet-base-dot-v1</code> ha mostrato la performance migliore per la ricerca semantica, quindi è quello che useremo per la nostra applicazione. Caricheremo anche il tokenizzatore usando lo stesso checkpoint:',vl,N,B,qe,Ze,kt="Come abbiamo già detto prima, vorremmo rappresentare ogni entrata nel nostro corpus di issue GitHub come un vettore singolo, per cui avremo bisogno di calcolare la media, o il “pool” dei nostri token embedding. Un metodo comune è di effettuare un <em>CLS pooling</em> sull’output del nostro modello: questa tecnica su basa sul recuperare semplicemente l’ultimo stato nascosto del token speciale <code>[CLS]</code>. La funzione seguente fa proprio questo:",Vl,Ge,Wl,Ce,Rt="Poi, creeremo una funzione di supporto che: tokenizza una lista di documenti, inserire i tensori sulla GPU, li usa come input per il modello, e infine applica il CLS pooling agli output:",Yl,x,z,De,Ie,_t="Node che abbiamo convertito gli embedding in array NumPy — questo perchè 🤗 Datasets ha bisogno di questo formato per indicizzare gli embedding con FAISS, che è ciò che faremo nella prossima sezione.",Sl,$e,Fl,ke,Nt=`Ora che abbiamo un dataset di embedding, abbiamo bisogno di un modo per effettuare una ricerca. Per far ciò, useremo una struttura specialie di 🤗 Datasets
chiamato <em>indice FAISS</em>. <a href="https://faiss.ai/" rel="nofollow">FAISS</a> (Facebook AI Similarity Search) è una libreria che permette di utilizzare algoritmi efficient per ricercare e raggruppare gli embedding.`,El,Re,Bt="L’idea di base dietro FAISS è di creare un formato speciale di dati chiamato <em>indice</em> che permette di trovare quali embedding sono simili a un embedding in input. Creare un indice FAISS su 🤗 Datasets è semplice — usiamo la funzione <code>Dataset.add_faiss_index()</code> e specificare quale colonna nel nostro dataset vorremmo indicizzare:",Hl,_e,Al,Ne,xt="Ora possiamo eseguire dele query su questo indice effettuando una ricerca degli elementi più vicini usando la funzione <code>Dataset.get_nearest_examples()</code>. Testiamolo creando un embedding per una domanda.",ql,X,v,Le,Be,zt="Proprio come con i documenti, ora abbiamo un vettore di 768 dimensioni che rappresenta la query, che possiamo confrontare con l’intero corpus per trovare gli embedding più simili:",Dl,xe,Ll,ze,Xt="La funzione <code>Dataset.get_nearest_examples()</code> restituisce una tupla di valori che valutano la sovrapposizione tra la query e il documento, e un set corrispondente di campioni (in questo caso, le 5 corrispondenze migliori). Salviamole in un <code>pandas.DataFrame</code>, così che possiamo ordinarle facilmente:",Pl,Xe,Kl,ve,vt="Ora possiamo iterare sulle prime righe per vedere quanto bene la nostra query corrisponde ai commenti disponibili:",Ol,Ve,et,We,lt,Ye,Vt="Non male! Il nostro secondo risultato sembra soddisfare la nostra richiesta.",tt,Y,st,Se,at,Pe,nt;M=new ps({props:{fw:Z[0]}}),Q=new rs({props:{containerStyle:"float: right; margin-left: 10px; display: inline-flex; position: relative; z-index: 10;"}}),G=new Oe({props:{title:"Ricerca semantica con FAISS",local:"ricerca-semantica-con-faiss",headingTag:"h1"}});const Wt=[ms,ds],Fe=[];function Yt(e,l){return e[0]==="pt"?0:1}k=Yt(Z),I=Fe[k]=Wt[k](Z),S=new cs({props:{id:"OATCgQtNX2o"}}),F=new Oe({props:{title:"Usare gli embedding per la ricerca semantica",local:"usare-gli-embedding-per-la-ricerca-semantica",headingTag:"h2"}}),A=new Oe({props:{title:"Caricare e preparare il dataset",local:"caricare-e-preparare-il-dataset",headingTag:"h2"}}),D=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}}),P=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}}),ee=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}}),le=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}}),se=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}}),ae=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}}),ie=new T({props:{code:"aXNzdWVzX2RhdGFzZXQuc2V0X2Zvcm1hdCglMjJwYW5kYXMlMjIpJTBBZGYlMjAlM0QlMjBpc3N1ZXNfZGF0YXNldCU1QiUzQSU1RA==",highlighted:`issues_dataset.set_format(<span class="hljs-string">&quot;pandas&quot;</span>)
df = issues_dataset[:]`,wrap:!1}}),re=new T({props:{code:"ZGYlNUIlMjJjb21tZW50cyUyMiU1RCU1QjAlNUQudG9saXN0KCk=",highlighted:'df[<span class="hljs-string">&quot;comments&quot;</span>][<span class="hljs-number">0</span>].tolist()',wrap:!1}}),Me=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}}),pe=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}}),me=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}}),ue=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}}),W=new Ot({props:{$$slots:{default:[us]},$$scope:{ctx:Z}}}),be=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}}),he=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}}),fe=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}}),je=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}}),ge=new Oe({props:{title:"Creare i text embedding",local:"creare-i-text-embedding",headingTag:"h2"}});const St=[ys,Us],Ee=[];function Ft(e,l){return e[0]==="pt"?0:1}N=Ft(Z),B=Ee[N]=St[N](Z),Ge=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 Et=[Js,bs],He=[];function Ht(e,l){return e[0]==="pt"?0:1}x=Ht(Z),z=He[x]=Et[x](Z),$e=new Oe({props:{title:"Usare FAISS per ricerca di similarità efficiente",local:"usare-faiss-per-ricerca-di-similarità-efficiente",headingTag:"h2"}}),_e=new T({props:{code:"ZW1iZWRkaW5nc19kYXRhc2V0LmFkZF9mYWlzc19pbmRleChjb2x1bW4lM0QlMjJlbWJlZGRpbmdzJTIyKQ==",highlighted:'embeddings_dataset.add_faiss_index(column=<span class="hljs-string">&quot;embeddings&quot;</span>)',wrap:!1}});const At=[fs,hs],Ae=[];function qt(e,l){return e[0]==="pt"?0:1}return X=qt(Z),v=Ae[X]=At[X](Z),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}}),Xe=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 Ot({props:{$$slots:{default:[Ts]},$$scope:{ctx:Z}}}),Se=new Ms({props:{source:"https://github.com/huggingface/course/blob/main/chapters/it/chapter5/6.mdx"}}),{c(){a=h("meta"),d=i(),n=h("p"),w=i(),u(M.$$.fragment),m=i(),u(Q.$$.fragment),J=i(),u(G.$$.fragment),$=i(),I.c(),C=i(),R=h("p"),R.innerHTML=r,g=i(),u(S.$$.fragment),el=i(),u(F.$$.fragment),ll=i(),E=h("p"),E.innerHTML=mt,tl=i(),H=h("p"),H.textContent=ut,sl=i(),V=h("div"),V.innerHTML=Ut,al=i(),u(A.$$.fragment),nl=i(),q=h("p"),q.textContent=yt,il=i(),u(D.$$.fragment),ol=i(),L=h("p"),L.innerHTML=bt,rl=i(),u(P.$$.fragment),Ml=i(),u(K.$$.fragment),cl=i(),O=h("p"),O.innerHTML=Jt,pl=i(),u(ee.$$.fragment),dl=i(),u(le.$$.fragment),ml=i(),te=h("p"),te.innerHTML=ht,ul=i(),u(se.$$.fragment),Ul=i(),u(ae.$$.fragment),yl=i(),ne=h("p"),ne.innerHTML=ft,bl=i(),u(ie.$$.fragment),Jl=i(),oe=h("p"),oe.innerHTML=Tt,hl=i(),u(re.$$.fragment),fl=i(),u(Me.$$.fragment),Tl=i(),ce=h("p"),ce.innerHTML=jt,jl=i(),u(pe.$$.fragment),wl=i(),_=h("table"),_.innerHTML=wt,gl=i(),de=h("p"),de.innerHTML=gt,Ql=i(),u(me.$$.fragment),Zl=i(),u(ue.$$.fragment),Gl=i(),Ue=h("p"),Ue.textContent=Qt,Cl=i(),u(W.$$.fragment),Il=i(),ye=h("p"),ye.innerHTML=Zt,$l=i(),u(be.$$.fragment),kl=i(),Je=h("p"),Je.textContent=Gt,Rl=i(),u(he.$$.fragment),_l=i(),u(fe.$$.fragment),Nl=i(),Te=h("p"),Te.innerHTML=Ct,Bl=i(),u(je.$$.fragment),xl=i(),we=h("p"),we.textContent=It,zl=i(),u(ge.$$.fragment),Xl=i(),Qe=h("p"),Qe.innerHTML=$t,vl=i(),B.c(),qe=i(),Ze=h("p"),Ze.innerHTML=kt,Vl=i(),u(Ge.$$.fragment),Wl=i(),Ce=h("p"),Ce.textContent=Rt,Yl=i(),z.c(),De=i(),Ie=h("p"),Ie.textContent=_t,Sl=i(),u($e.$$.fragment),Fl=i(),ke=h("p"),ke.innerHTML=Nt,El=i(),Re=h("p"),Re.innerHTML=Bt,Hl=i(),u(_e.$$.fragment),Al=i(),Ne=h("p"),Ne.innerHTML=xt,ql=i(),v.c(),Le=i(),Be=h("p"),Be.textContent=zt,Dl=i(),u(xe.$$.fragment),Ll=i(),ze=h("p"),ze.innerHTML=Xt,Pl=i(),u(Xe.$$.fragment),Kl=i(),ve=h("p"),ve.textContent=vt,Ol=i(),u(Ve.$$.fragment),et=i(),u(We.$$.fragment),lt=i(),Ye=h("p"),Ye.textContent=Vt,tt=i(),u(Y.$$.fragment),st=i(),u(Se.$$.fragment),at=i(),Pe=h("p"),this.h()},l(e){const l=is("svelte-u9bgzb",document.head);a=f(l,"META",{name:!0,content:!0}),l.forEach(t),d=o(e),n=f(e,"P",{}),Kt(n).forEach(t),w=o(e),U(M.$$.fragment,e),m=o(e),U(Q.$$.fragment,e),J=o(e),U(G.$$.fragment,e),$=o(e),I.l(e),C=o(e),R=f(e,"P",{"data-svelte-h":!0}),j(R)!=="svelte-zmfqyi"&&(R.innerHTML=r),g=o(e),U(S.$$.fragment,e),el=o(e),U(F.$$.fragment,e),ll=o(e),E=f(e,"P",{"data-svelte-h":!0}),j(E)!=="svelte-ol4drb"&&(E.innerHTML=mt),tl=o(e),H=f(e,"P",{"data-svelte-h":!0}),j(H)!=="svelte-17yhsv1"&&(H.textContent=ut),sl=o(e),V=f(e,"DIV",{class:!0,"data-svelte-h":!0}),j(V)!=="svelte-yxatr"&&(V.innerHTML=Ut),al=o(e),U(A.$$.fragment,e),nl=o(e),q=f(e,"P",{"data-svelte-h":!0}),j(q)!=="svelte-a3kzw0"&&(q.textContent=yt),il=o(e),U(D.$$.fragment,e),ol=o(e),L=f(e,"P",{"data-svelte-h":!0}),j(L)!=="svelte-162oxkz"&&(L.innerHTML=bt),rl=o(e),U(P.$$.fragment,e),Ml=o(e),U(K.$$.fragment,e),cl=o(e),O=f(e,"P",{"data-svelte-h":!0}),j(O)!=="svelte-nxqhiv"&&(O.innerHTML=Jt),pl=o(e),U(ee.$$.fragment,e),dl=o(e),U(le.$$.fragment,e),ml=o(e),te=f(e,"P",{"data-svelte-h":!0}),j(te)!=="svelte-ikowdy"&&(te.innerHTML=ht),ul=o(e),U(se.$$.fragment,e),Ul=o(e),U(ae.$$.fragment,e),yl=o(e),ne=f(e,"P",{"data-svelte-h":!0}),j(ne)!=="svelte-1ofr137"&&(ne.innerHTML=ft),bl=o(e),U(ie.$$.fragment,e),Jl=o(e),oe=f(e,"P",{"data-svelte-h":!0}),j(oe)!=="svelte-1ltyg57"&&(oe.innerHTML=Tt),hl=o(e),U(re.$$.fragment,e),fl=o(e),U(Me.$$.fragment,e),Tl=o(e),ce=f(e,"P",{"data-svelte-h":!0}),j(ce)!=="svelte-1aw5ud4"&&(ce.innerHTML=jt),jl=o(e),U(pe.$$.fragment,e),wl=o(e),_=f(e,"TABLE",{border:!0,class:!0,style:!0,"data-svelte-h":!0}),j(_)!=="svelte-1g5whzd"&&(_.innerHTML=wt),gl=o(e),de=f(e,"P",{"data-svelte-h":!0}),j(de)!=="svelte-1co8std"&&(de.innerHTML=gt),Ql=o(e),U(me.$$.fragment,e),Zl=o(e),U(ue.$$.fragment,e),Gl=o(e),Ue=f(e,"P",{"data-svelte-h":!0}),j(Ue)!=="svelte-ul1oyx"&&(Ue.textContent=Qt),Cl=o(e),U(W.$$.fragment,e),Il=o(e),ye=f(e,"P",{"data-svelte-h":!0}),j(ye)!=="svelte-txz5a1"&&(ye.innerHTML=Zt),$l=o(e),U(be.$$.fragment,e),kl=o(e),Je=f(e,"P",{"data-svelte-h":!0}),j(Je)!=="svelte-q63izi"&&(Je.textContent=Gt),Rl=o(e),U(he.$$.fragment,e),_l=o(e),U(fe.$$.fragment,e),Nl=o(e),Te=f(e,"P",{"data-svelte-h":!0}),j(Te)!=="svelte-1w0qnmy"&&(Te.innerHTML=Ct),Bl=o(e),U(je.$$.fragment,e),xl=o(e),we=f(e,"P",{"data-svelte-h":!0}),j(we)!=="svelte-1evji84"&&(we.textContent=It),zl=o(e),U(ge.$$.fragment,e),Xl=o(e),Qe=f(e,"P",{"data-svelte-h":!0}),j(Qe)!=="svelte-gakban"&&(Qe.innerHTML=$t),vl=o(e),B.l(e),qe=o(e),Ze=f(e,"P",{"data-svelte-h":!0}),j(Ze)!=="svelte-1blfpo3"&&(Ze.innerHTML=kt),Vl=o(e),U(Ge.$$.fragment,e),Wl=o(e),Ce=f(e,"P",{"data-svelte-h":!0}),j(Ce)!=="svelte-98guag"&&(Ce.textContent=Rt),Yl=o(e),z.l(e),De=o(e),Ie=f(e,"P",{"data-svelte-h":!0}),j(Ie)!=="svelte-coeq7k"&&(Ie.textContent=_t),Sl=o(e),U($e.$$.fragment,e),Fl=o(e),ke=f(e,"P",{"data-svelte-h":!0}),j(ke)!=="svelte-1qbifcu"&&(ke.innerHTML=Nt),El=o(e),Re=f(e,"P",{"data-svelte-h":!0}),j(Re)!=="svelte-2zpjb1"&&(Re.innerHTML=Bt),Hl=o(e),U(_e.$$.fragment,e),Al=o(e),Ne=f(e,"P",{"data-svelte-h":!0}),j(Ne)!=="svelte-gcr4ir"&&(Ne.innerHTML=xt),ql=o(e),v.l(e),Le=o(e),Be=f(e,"P",{"data-svelte-h":!0}),j(Be)!=="svelte-wmwufy"&&(Be.textContent=zt),Dl=o(e),U(xe.$$.fragment,e),Ll=o(e),ze=f(e,"P",{"data-svelte-h":!0}),j(ze)!=="svelte-m2y78c"&&(ze.innerHTML=Xt),Pl=o(e),U(Xe.$$.fragment,e),Kl=o(e),ve=f(e,"P",{"data-svelte-h":!0}),j(ve)!=="svelte-1x83w58"&&(ve.textContent=vt),Ol=o(e),U(Ve.$$.fragment,e),et=o(e),U(We.$$.fragment,e),lt=o(e),Ye=f(e,"P",{"data-svelte-h":!0}),j(Ye)!=="svelte-19hbgpn"&&(Ye.textContent=Vt),tt=o(e),U(Y.$$.fragment,e),st=o(e),U(Se.$$.fragment,e),at=o(e),Pe=f(e,"P",{}),Kt(Pe).forEach(t),this.h()},h(){Ke(a,"name","hf:doc:metadata"),Ke(a,"content",ws),Ke(V,"class","flex justify-center"),Ke(_,"border","1"),Ke(_,"class","dataframe"),dt(_,"table-layout","fixed"),dt(_,"word-wrap","break-word"),dt(_,"width","100%")},m(e,l){os(document.head,a),s(e,d,l),s(e,n,l),s(e,w,l),y(M,e,l),s(e,m,l),y(Q,e,l),s(e,J,l),y(G,e,l),s(e,$,l),Fe[k].m(e,l),s(e,C,l),s(e,R,l),s(e,g,l),y(S,e,l),s(e,el,l),y(F,e,l),s(e,ll,l),s(e,E,l),s(e,tl,l),s(e,H,l),s(e,sl,l),s(e,V,l),s(e,al,l),y(A,e,l),s(e,nl,l),s(e,q,l),s(e,il,l),y(D,e,l),s(e,ol,l),s(e,L,l),s(e,rl,l),y(P,e,l),s(e,Ml,l),y(K,e,l),s(e,cl,l),s(e,O,l),s(e,pl,l),y(ee,e,l),s(e,dl,l),y(le,e,l),s(e,ml,l),s(e,te,l),s(e,ul,l),y(se,e,l),s(e,Ul,l),y(ae,e,l),s(e,yl,l),s(e,ne,l),s(e,bl,l),y(ie,e,l),s(e,Jl,l),s(e,oe,l),s(e,hl,l),y(re,e,l),s(e,fl,l),y(Me,e,l),s(e,Tl,l),s(e,ce,l),s(e,jl,l),y(pe,e,l),s(e,wl,l),s(e,_,l),s(e,gl,l),s(e,de,l),s(e,Ql,l),y(me,e,l),s(e,Zl,l),y(ue,e,l),s(e,Gl,l),s(e,Ue,l),s(e,Cl,l),y(W,e,l),s(e,Il,l),s(e,ye,l),s(e,$l,l),y(be,e,l),s(e,kl,l),s(e,Je,l),s(e,Rl,l),y(he,e,l),s(e,_l,l),y(fe,e,l),s(e,Nl,l),s(e,Te,l),s(e,Bl,l),y(je,e,l),s(e,xl,l),s(e,we,l),s(e,zl,l),y(ge,e,l),s(e,Xl,l),s(e,Qe,l),s(e,vl,l),Ee[N].m(e,l),s(e,qe,l),s(e,Ze,l),s(e,Vl,l),y(Ge,e,l),s(e,Wl,l),s(e,Ce,l),s(e,Yl,l),He[x].m(e,l),s(e,De,l),s(e,Ie,l),s(e,Sl,l),y($e,e,l),s(e,Fl,l),s(e,ke,l),s(e,El,l),s(e,Re,l),s(e,Hl,l),y(_e,e,l),s(e,Al,l),s(e,Ne,l),s(e,ql,l),Ae[X].m(e,l),s(e,Le,l),s(e,Be,l),s(e,Dl,l),y(xe,e,l),s(e,Ll,l),s(e,ze,l),s(e,Pl,l),y(Xe,e,l),s(e,Kl,l),s(e,ve,l),s(e,Ol,l),y(Ve,e,l),s(e,et,l),y(We,e,l),s(e,lt,l),s(e,Ye,l),s(e,tt,l),y(Y,e,l),s(e,st,l),y(Se,e,l),s(e,at,l),s(e,Pe,l),nt=!0},p(e,[l]){const Dt={};l&1&&(Dt.fw=e[0]),M.$set(Dt);let rt=k;k=Yt(e),k!==rt&&(ot(),c(Fe[rt],1,1,()=>{Fe[rt]=null}),it(),I=Fe[k],I||(I=Fe[k]=Wt[k](e),I.c()),p(I,1),I.m(C.parentNode,C));const Lt={};l&2&&(Lt.$$scope={dirty:l,ctx:e}),W.$set(Lt);let Mt=N;N=Ft(e),N!==Mt&&(ot(),c(Ee[Mt],1,1,()=>{Ee[Mt]=null}),it(),B=Ee[N],B||(B=Ee[N]=St[N](e),B.c()),p(B,1),B.m(qe.parentNode,qe));let ct=x;x=Ht(e),x!==ct&&(ot(),c(He[ct],1,1,()=>{He[ct]=null}),it(),z=He[x],z||(z=He[x]=Et[x](e),z.c()),p(z,1),z.m(De.parentNode,De));let pt=X;X=qt(e),X!==pt&&(ot(),c(Ae[pt],1,1,()=>{Ae[pt]=null}),it(),v=Ae[X],v||(v=Ae[X]=At[X](e),v.c()),p(v,1),v.m(Le.parentNode,Le));const Pt={};l&2&&(Pt.$$scope={dirty:l,ctx:e}),Y.$set(Pt)},i(e){nt||(p(M.$$.fragment,e),p(Q.$$.fragment,e),p(G.$$.fragment,e),p(I),p(S.$$.fragment,e),p(F.$$.fragment,e),p(A.$$.fragment,e),p(D.$$.fragment,e),p(P.$$.fragment,e),p(K.$$.fragment,e),p(ee.$$.fragment,e),p(le.$$.fragment,e),p(se.$$.fragment,e),p(ae.$$.fragment,e),p(ie.$$.fragment,e),p(re.$$.fragment,e),p(Me.$$.fragment,e),p(pe.$$.fragment,e),p(me.$$.fragment,e),p(ue.$$.fragment,e),p(W.$$.fragment,e),p(be.$$.fragment,e),p(he.$$.fragment,e),p(fe.$$.fragment,e),p(je.$$.fragment,e),p(ge.$$.fragment,e),p(B),p(Ge.$$.fragment,e),p(z),p($e.$$.fragment,e),p(_e.$$.fragment,e),p(v),p(xe.$$.fragment,e),p(Xe.$$.fragment,e),p(Ve.$$.fragment,e),p(We.$$.fragment,e),p(Y.$$.fragment,e),p(Se.$$.fragment,e),nt=!0)},o(e){c(M.$$.fragment,e),c(Q.$$.fragment,e),c(G.$$.fragment,e),c(I),c(S.$$.fragment,e),c(F.$$.fragment,e),c(A.$$.fragment,e),c(D.$$.fragment,e),c(P.$$.fragment,e),c(K.$$.fragment,e),c(ee.$$.fragment,e),c(le.$$.fragment,e),c(se.$$.fragment,e),c(ae.$$.fragment,e),c(ie.$$.fragment,e),c(re.$$.fragment,e),c(Me.$$.fragment,e),c(pe.$$.fragment,e),c(me.$$.fragment,e),c(ue.$$.fragment,e),c(W.$$.fragment,e),c(be.$$.fragment,e),c(he.$$.fragment,e),c(fe.$$.fragment,e),c(je.$$.fragment,e),c(ge.$$.fragment,e),c(B),c(Ge.$$.fragment,e),c(z),c($e.$$.fragment,e),c(_e.$$.fragment,e),c(v),c(xe.$$.fragment,e),c(Xe.$$.fragment,e),c(Ve.$$.fragment,e),c(We.$$.fragment,e),c(Y.$$.fragment,e),c(Se.$$.fragment,e),nt=!1},d(e){e&&(t(d),t(n),t(w),t(m),t(J),t($),t(C),t(R),t(g),t(el),t(ll),t(E),t(tl),t(H),t(sl),t(V),t(al),t(nl),t(q),t(il),t(ol),t(L),t(rl),t(Ml),t(cl),t(O),t(pl),t(dl),t(ml),t(te),t(ul),t(Ul),t(yl),t(ne),t(bl),t(Jl),t(oe),t(hl),t(fl),t(Tl),t(ce),t(jl),t(wl),t(_),t(gl),t(de),t(Ql),t(Zl),t(Gl),t(Ue),t(Cl),t(Il),t(ye),t($l),t(kl),t(Je),t(Rl),t(_l),t(Nl),t(Te),t(Bl),t(xl),t(we),t(zl),t(Xl),t(Qe),t(vl),t(qe),t(Ze),t(Vl),t(Wl),t(Ce),t(Yl),t(De),t(Ie),t(Sl),t(Fl),t(ke),t(El),t(Re),t(Hl),t(Al),t(Ne),t(ql),t(Le),t(Be),t(Dl),t(Ll),t(ze),t(Pl),t(Kl),t(ve),t(Ol),t(et),t(lt),t(Ye),t(tt),t(st),t(at),t(Pe)),t(a),b(M,e),b(Q,e),b(G,e),Fe[k].d(e),b(S,e),b(F,e),b(A,e),b(D,e),b(P,e),b(K,e),b(ee,e),b(le,e),b(se,e),b(ae,e),b(ie,e),b(re,e),b(Me,e),b(pe,e),b(me,e),b(ue,e),b(W,e),b(be,e),b(he,e),b(fe,e),b(je,e),b(ge,e),Ee[N].d(e),b(Ge,e),He[x].d(e),b($e,e),b(_e,e),Ae[X].d(e),b(xe,e),b(Xe,e),b(Ve,e),b(We,e),b(Y,e),b(Se,e)}}}const ws='{"title":"Ricerca semantica con FAISS","local":"ricerca-semantica-con-faiss","sections":[{"title":"Usare gli embedding per la ricerca semantica","local":"usare-gli-embedding-per-la-ricerca-semantica","sections":[],"depth":2},{"title":"Caricare e preparare il dataset","local":"caricare-e-preparare-il-dataset","sections":[],"depth":2},{"title":"Creare i text embedding","local":"creare-i-text-embedding","sections":[],"depth":2},{"title":"Usare FAISS per ricerca di similarità efficiente","local":"usare-faiss-per-ricerca-di-similarità-efficiente","sections":[],"depth":2}],"depth":1}';function gs(Z,a,d){let n="pt";return ss(()=>{const w=new URLSearchParams(window.location.search);d(0,n=w.get("fw")||"pt")}),[n]}class _s extends as{constructor(a){super(),ns(this,a,gs,js,ts,{})}}export{_s as component};
