import{s as Bt,o as At,n as Ut}from"../chunks/scheduler.36a0863c.js";import{S as Vt,i as Yt,g as n,s as i,u as $,A as St,h as r,f as e,c as o,j as w,v as y,y as M,k as f,o as m,a as s,w as b,d as v,t as j,x as T}from"../chunks/index.d0f7a4c4.js";import{T as zt}from"../chunks/Tip.4c7d7eb1.js";import{Y as Zt}from"../chunks/Youtube.d15bb502.js";import{I as qe}from"../chunks/IconCopyLink.bc5fad79.js";import{C as A}from"../chunks/CodeBlock.69433f87.js";import{D as qt}from"../chunks/DocNotebookDropdown.df566a23.js";import{F as Nt,M as It}from"../chunks/Markdown.1d1f160a.js";function Qt(ge){let c,_="Potresti vedere un warning dato che alcuni dei pesi pre-addestrati non sono stati utilizzati e altri pesi sono stati inizializzati casualmente. Non preoccuparti, è completamente normale! L’head pre-addestrata del modello BERT viene scartata e rimpiazzata da una classification head inizializzata casualmente. Farai il fine-tuning di questa nuova head del modello sul tuo compito di classificazione, trasferendogli la conoscenza del modello pre-addestrato.";return{c(){c=n("p"),c.textContent=_},l(d){c=r(d,"P",{"data-svelte-h":!0}),M(c)!=="svelte-1gl2557"&&(c.textContent=_)},m(d,k){s(d,c,k)},p:Ut,d(d){d&&e(c)}}}function Pt(ge){let c,_,d,k="🤗 Transformers mette a disposizione la classe <code>Trainer</code> ottimizzata per addestrare modelli 🤗 Transformers, rendendo semplice iniziare l’addestramento senza scrivere manualmente il tuo ciclo di addestramento. L’API <code>Trainer</code> supporta un’ampia gamma di opzioni e funzionalità di addestramento come logging, gradient accumulation e mixed precision.",C,X,xe='Inizia caricando il tuo modello e specificando il numero di etichette (labels) attese. Nel dataset Yelp Review <a href="https://huggingface.co/datasets/yelp_review_full#data-fields" rel="nofollow">dataset card</a>, sai che ci sono cinque etichette:',E,x,ae,F,Re,U,H,N,V,Ye,P,pe="Iperparametri per il training",be,Z,Me='Successivamente, crea una classe <code>TrainingArguments</code> contenente tutti gli iperparametri che si possono regore nonché le variabili per attivare le differenti opzioni di addestramento. Per questa esercitazione puoi iniziare con gli <a href="https://huggingface.co/docs/transformers/main_classes/trainer#transformers.TrainingArguments" rel="nofollow">iperparametri</a> di ddestramento predefiniti, ma sentiti libero di sperimentare per trovare la configurazione ottimale per te.',Y,L,ce="Specifica dove salvare i checkpoints del tuo addestramento:",S,q,R,Q,D,z,de,B,Ne,Ce="Metriche",G,ve,se='<code>Trainer</code> non valuta automaticamente le performance del modello durante l’addestramento. Dovrai passare a <code>Trainer</code> una funzione che calcola e restituisce le metriche. La libreria 🤗 Datasets mette a disposizione una semplice funzione <a href="https://huggingface.co/metrics/accuracy" rel="nofollow"><code>accuracy</code></a> che puoi caricare con la funzione <code>load_metric</code> (guarda questa <a href="https://huggingface.co/docs/datasets/metrics.html" rel="nofollow">esercitazione</a> per maggiori informazioni):',I,K,W,Ze,we="Richiama <code>compute</code> su <code>metric</code> per calcolare l’accuratezza delle tue previsioni. Prima di passare le tue previsioni a <code>compute</code>, hai bisogno di convertirle in logits (ricorda che tutti i modelli 🤗 Transformers restituiscono logits):",O,le,p,J,je="Se preferisci monitorare le tue metriche di valutazione durante il fine-tuning, specifica il parametro <code>evaluation_strategy</code> nei tuoi training arguments per restituire le metriche di valutazione ad ogni epoca di addestramento:",ee,ne,re,he,te,ie,Te,me,$e,Be="Trainer",Ae,Ge,Je="Crea un oggetto <code>Trainer</code> col tuo modello, training arguments, dataset di training e test, e funzione di valutazione:",Pe,ye,Ue,ue,We="Poi metti a punto il modello richiamando <code>train()</code>:",_e,fe,Xe;return c=new Zt({props:{id:"nvBXf7s7vTI"}}),x=new A({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9Nb2RlbEZvclNlcXVlbmNlQ2xhc3NpZmljYXRpb24lMEElMEFtb2RlbCUyMCUzRCUyMEF1dG9Nb2RlbEZvclNlcXVlbmNlQ2xhc3NpZmljYXRpb24uZnJvbV9wcmV0cmFpbmVkKCUyMmJlcnQtYmFzZS1jYXNlZCUyMiUyQyUyMG51bV9sYWJlbHMlM0Q1KQ==",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoModelForSequenceClassification

<span class="hljs-meta">&gt;&gt;&gt; </span>model = AutoModelForSequenceClassification.from_pretrained(<span class="hljs-string">&quot;bert-base-cased&quot;</span>, num_labels=<span class="hljs-number">5</span>)`}}),F=new zt({props:{$$slots:{default:[Qt]},$$scope:{ctx:ge}}}),V=new qe({}),q=new A({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMFRyYWluaW5nQXJndW1lbnRzJTBBJTBBdHJhaW5pbmdfYXJncyUyMCUzRCUyMFRyYWluaW5nQXJndW1lbnRzKG91dHB1dF9kaXIlM0QlMjJ0ZXN0X3RyYWluZXIlMjIp",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> TrainingArguments

<span class="hljs-meta">&gt;&gt;&gt; </span>training_args = TrainingArguments(output_dir=<span class="hljs-string">&quot;test_trainer&quot;</span>)`}}),de=new qe({}),K=new A({props:{code:"aW1wb3J0JTIwbnVtcHklMjBhcyUyMG5wJTBBZnJvbSUyMGRhdGFzZXRzJTIwaW1wb3J0JTIwbG9hZF9tZXRyaWMlMEElMEFtZXRyaWMlMjAlM0QlMjBsb2FkX21ldHJpYyglMjJhY2N1cmFjeSUyMik=",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">import</span> numpy <span class="hljs-keyword">as</span> np
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> datasets <span class="hljs-keyword">import</span> load_metric

<span class="hljs-meta">&gt;&gt;&gt; </span>metric = load_metric(<span class="hljs-string">&quot;accuracy&quot;</span>)`}}),le=new A({props:{code:"ZGVmJTIwY29tcHV0ZV9tZXRyaWNzKGV2YWxfcHJlZCklM0ElMEElMjAlMjAlMjAlMjBsb2dpdHMlMkMlMjBsYWJlbHMlMjAlM0QlMjBldmFsX3ByZWQlMEElMjAlMjAlMjAlMjBwcmVkaWN0aW9ucyUyMCUzRCUyMG5wLmFyZ21heChsb2dpdHMlMkMlMjBheGlzJTNELTEpJTBBJTIwJTIwJTIwJTIwcmV0dXJuJTIwbWV0cmljLmNvbXB1dGUocHJlZGljdGlvbnMlM0RwcmVkaWN0aW9ucyUyQyUyMHJlZmVyZW5jZXMlM0RsYWJlbHMp",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">def</span> <span class="hljs-title function_">compute_metrics</span>(<span class="hljs-params">eval_pred</span>):
<span class="hljs-meta">... </span>    logits, labels = eval_pred
<span class="hljs-meta">... </span>    predictions = np.argmax(logits, axis=-<span class="hljs-number">1</span>)
<span class="hljs-meta">... </span>    <span class="hljs-keyword">return</span> metric.compute(predictions=predictions, references=labels)`}}),ne=new A({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMFRyYWluaW5nQXJndW1lbnRzJTJDJTIwVHJhaW5lciUwQSUwQXRyYWluaW5nX2FyZ3MlMjAlM0QlMjBUcmFpbmluZ0FyZ3VtZW50cyhvdXRwdXRfZGlyJTNEJTIydGVzdF90cmFpbmVyJTIyJTJDJTIwZXZhbHVhdGlvbl9zdHJhdGVneSUzRCUyMmVwb2NoJTIyKQ==",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> TrainingArguments, Trainer

<span class="hljs-meta">&gt;&gt;&gt; </span>training_args = TrainingArguments(output_dir=<span class="hljs-string">&quot;test_trainer&quot;</span>, evaluation_strategy=<span class="hljs-string">&quot;epoch&quot;</span>)`}}),Te=new qe({}),ye=new A({props:{code:"dHJhaW5lciUyMCUzRCUyMFRyYWluZXIoJTBBJTIwJTIwJTIwJTIwbW9kZWwlM0Rtb2RlbCUyQyUwQSUyMCUyMCUyMCUyMGFyZ3MlM0R0cmFpbmluZ19hcmdzJTJDJTBBJTIwJTIwJTIwJTIwdHJhaW5fZGF0YXNldCUzRHNtYWxsX3RyYWluX2RhdGFzZXQlMkMlMEElMjAlMjAlMjAlMjBldmFsX2RhdGFzZXQlM0RzbWFsbF9ldmFsX2RhdGFzZXQlMkMlMEElMjAlMjAlMjAlMjBjb21wdXRlX21ldHJpY3MlM0Rjb21wdXRlX21ldHJpY3MlMkMlMEEp",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span>trainer = Trainer(
<span class="hljs-meta">... </span>    model=model,
<span class="hljs-meta">... </span>    args=training_args,
<span class="hljs-meta">... </span>    train_dataset=small_train_dataset,
<span class="hljs-meta">... </span>    eval_dataset=small_eval_dataset,
<span class="hljs-meta">... </span>    compute_metrics=compute_metrics,
<span class="hljs-meta">... </span>)`}}),fe=new A({props:{code:"dHJhaW5lci50cmFpbigp",highlighted:'<span class="hljs-meta">&gt;&gt;&gt; </span>trainer.train()'}}),{c(){$(c.$$.fragment),_=i(),d=n("p"),d.innerHTML=k,C=i(),X=n("p"),X.innerHTML=xe,E=i(),$(x.$$.fragment),ae=i(),$(F.$$.fragment),Re=i(),U=n("h3"),H=n("a"),N=n("span"),$(V.$$.fragment),Ye=i(),P=n("span"),P.textContent=pe,be=i(),Z=n("p"),Z.innerHTML=Me,Y=i(),L=n("p"),L.textContent=ce,S=i(),$(q.$$.fragment),R=i(),Q=n("h3"),D=n("a"),z=n("span"),$(de.$$.fragment),B=i(),Ne=n("span"),Ne.textContent=Ce,G=i(),ve=n("p"),ve.innerHTML=se,I=i(),$(K.$$.fragment),W=i(),Ze=n("p"),Ze.innerHTML=we,O=i(),$(le.$$.fragment),p=i(),J=n("p"),J.innerHTML=je,ee=i(),$(ne.$$.fragment),re=i(),he=n("h3"),te=n("a"),ie=n("span"),$(Te.$$.fragment),me=i(),$e=n("span"),$e.textContent=Be,Ae=i(),Ge=n("p"),Ge.innerHTML=Je,Pe=i(),$(ye.$$.fragment),Ue=i(),ue=n("p"),ue.innerHTML=We,_e=i(),$(fe.$$.fragment),this.h()},l(l){y(c.$$.fragment,l),_=o(l),d=r(l,"P",{"data-svelte-h":!0}),M(d)!=="svelte-w7p6ip"&&(d.innerHTML=k),C=o(l),X=r(l,"P",{"data-svelte-h":!0}),M(X)!=="svelte-tdx1mf"&&(X.innerHTML=xe),E=o(l),y(x.$$.fragment,l),ae=o(l),y(F.$$.fragment,l),Re=o(l),U=r(l,"H3",{class:!0});var g=w(U);H=r(g,"A",{id:!0,class:!0,href:!0});var ke=w(H);N=r(ke,"SPAN",{});var Ee=w(N);y(V.$$.fragment,Ee),Ee.forEach(e),ke.forEach(e),Ye=o(g),P=r(g,"SPAN",{"data-svelte-h":!0}),M(P)!=="svelte-1t99m12"&&(P.textContent=pe),g.forEach(e),be=o(l),Z=r(l,"P",{"data-svelte-h":!0}),M(Z)!=="svelte-ae6lm"&&(Z.innerHTML=Me),Y=o(l),L=r(l,"P",{"data-svelte-h":!0}),M(L)!=="svelte-1b2tmkh"&&(L.textContent=ce),S=o(l),y(q.$$.fragment,l),R=o(l),Q=r(l,"H3",{class:!0});var ze=w(Q);D=r(ze,"A",{id:!0,class:!0,href:!0});var Le=w(D);z=r(Le,"SPAN",{});var De=w(z);y(de.$$.fragment,De),De.forEach(e),Le.forEach(e),B=o(ze),Ne=r(ze,"SPAN",{"data-svelte-h":!0}),M(Ne)!=="svelte-ygnsok"&&(Ne.textContent=Ce),ze.forEach(e),G=o(l),ve=r(l,"P",{"data-svelte-h":!0}),M(ve)!=="svelte-xr4ry3"&&(ve.innerHTML=se),I=o(l),y(K.$$.fragment,l),W=o(l),Ze=r(l,"P",{"data-svelte-h":!0}),M(Ze)!=="svelte-1i3t4rh"&&(Ze.innerHTML=we),O=o(l),y(le.$$.fragment,l),p=o(l),J=r(l,"P",{"data-svelte-h":!0}),M(J)!=="svelte-ijtp5w"&&(J.innerHTML=je),ee=o(l),y(ne.$$.fragment,l),re=o(l),he=r(l,"H3",{class:!0});var oe=w(he);te=r(oe,"A",{id:!0,class:!0,href:!0});var Fe=w(te);ie=r(Fe,"SPAN",{});var Ie=w(ie);y(Te.$$.fragment,Ie),Ie.forEach(e),Fe.forEach(e),me=o(oe),$e=r(oe,"SPAN",{"data-svelte-h":!0}),M($e)!=="svelte-1db8bfa"&&($e.textContent=Be),oe.forEach(e),Ae=o(l),Ge=r(l,"P",{"data-svelte-h":!0}),M(Ge)!=="svelte-5ioy4b"&&(Ge.innerHTML=Je),Pe=o(l),y(ye.$$.fragment,l),Ue=o(l),ue=r(l,"P",{"data-svelte-h":!0}),M(ue)!=="svelte-1y3qbve"&&(ue.innerHTML=We),_e=o(l),y(fe.$$.fragment,l),this.h()},h(){f(H,"id","iperparametri-per-il-training"),f(H,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),f(H,"href","#iperparametri-per-il-training"),f(U,"class","relative group"),f(D,"id","metriche"),f(D,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),f(D,"href","#metriche"),f(Q,"class","relative group"),f(te,"id","trainer"),f(te,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),f(te,"href","#trainer"),f(he,"class","relative group")},m(l,g){b(c,l,g),s(l,_,g),s(l,d,g),s(l,C,g),s(l,X,g),s(l,E,g),b(x,l,g),s(l,ae,g),b(F,l,g),s(l,Re,g),s(l,U,g),m(U,H),m(H,N),b(V,N,null),m(U,Ye),m(U,P),s(l,be,g),s(l,Z,g),s(l,Y,g),s(l,L,g),s(l,S,g),b(q,l,g),s(l,R,g),s(l,Q,g),m(Q,D),m(D,z),b(de,z,null),m(Q,B),m(Q,Ne),s(l,G,g),s(l,ve,g),s(l,I,g),b(K,l,g),s(l,W,g),s(l,Ze,g),s(l,O,g),b(le,l,g),s(l,p,g),s(l,J,g),s(l,ee,g),b(ne,l,g),s(l,re,g),s(l,he,g),m(he,te),m(te,ie),b(Te,ie,null),m(he,me),m(he,$e),s(l,Ae,g),s(l,Ge,g),s(l,Pe,g),b(ye,l,g),s(l,Ue,g),s(l,ue,g),s(l,_e,g),b(fe,l,g),Xe=!0},p(l,g){const ke={};g&2&&(ke.$$scope={dirty:g,ctx:l}),F.$set(ke)},i(l){Xe||(v(c.$$.fragment,l),v(x.$$.fragment,l),v(F.$$.fragment,l),v(V.$$.fragment,l),v(q.$$.fragment,l),v(de.$$.fragment,l),v(K.$$.fragment,l),v(le.$$.fragment,l),v(ne.$$.fragment,l),v(Te.$$.fragment,l),v(ye.$$.fragment,l),v(fe.$$.fragment,l),Xe=!0)},o(l){j(c.$$.fragment,l),j(x.$$.fragment,l),j(F.$$.fragment,l),j(V.$$.fragment,l),j(q.$$.fragment,l),j(de.$$.fragment,l),j(K.$$.fragment,l),j(le.$$.fragment,l),j(ne.$$.fragment,l),j(Te.$$.fragment,l),j(ye.$$.fragment,l),j(fe.$$.fragment,l),Xe=!1},d(l){l&&(e(_),e(d),e(C),e(X),e(E),e(ae),e(Re),e(U),e(be),e(Z),e(Y),e(L),e(S),e(R),e(Q),e(G),e(ve),e(I),e(W),e(Ze),e(O),e(p),e(J),e(ee),e(re),e(he),e(Ae),e(Ge),e(Pe),e(Ue),e(ue),e(_e)),T(c,l),T(x,l),T(F,l),T(V),T(q,l),T(de),T(K,l),T(le,l),T(ne,l),T(Te),T(ye,l),T(fe,l)}}}function Lt(ge){let c,_;return c=new It({props:{$$slots:{default:[Pt]},$$scope:{ctx:ge}}}),{c(){$(c.$$.fragment)},l(d){y(c.$$.fragment,d)},m(d,k){b(c,d,k),_=!0},p(d,k){const C={};k&2&&(C.$$scope={dirty:k,ctx:d}),c.$set(C)},i(d){_||(v(c.$$.fragment,d),_=!0)},o(d){j(c.$$.fragment,d),_=!1},d(d){T(c,d)}}}function Dt(ge){let c,_="<code>Trainer</code> usa <code>DataCollatorWithPadding</code> in maniera predefinita in modo da non dover specificare esplicitamente un collettore di dati.";return{c(){c=n("p"),c.innerHTML=_},l(d){c=r(d,"P",{"data-svelte-h":!0}),M(c)!=="svelte-1qdpgxe"&&(c.innerHTML=_)},m(d,k){s(d,c,k)},p:Ut,d(d){d&&e(c)}}}function Kt(ge){let c,_,d,k,C,X="I modelli 🤗 Transformers supportano anche l’addestramento in TensorFlow usando l’API di Keras.",xe,E,x,ae,F,Re,U,H="Convertire dataset nel formato per TensorFlow",N,V,Ye="Il <code>DefaultDataCollator</code> assembla tensori in lotti su cui il modello si addestrerà. Assicurati di specificare di restituire tensori per TensorFlow in <code>return_tensors</code>:",P,pe,be,Z,Me,Y,L='Successivamente, converti i datasets tokenizzati in TensorFlow datasets con il metodo <a href="https://huggingface.co/docs/datasets/package_reference/main_classes.html#datasets.Dataset.to_tf_dataset" rel="nofollow"><code>to_tf_dataset</code></a>. Specifica il tuo input in <code>columns</code> e le tue etichette in <code>label_cols</code>:',ce,S,q,R,Q,D,z,de,B,Ne="Compilazione e addestramento",Ce,G,ve="Carica un modello TensorFlow col numero atteso di etichette:",se,I,K,W,Ze='Poi compila e fai il fine-tuning del tuo modello usando <a href="https://keras.io/api/models/model_training_apis/" rel="nofollow"><code>fit</code></a> come faresti con qualsiasi altro modello di Keras:',we,O,le;return d=new Zt({props:{id:"rnTGBy2ax1c"}}),F=new qe({}),pe=new A({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMERlZmF1bHREYXRhQ29sbGF0b3IlMEElMEFkYXRhX2NvbGxhdG9yJTIwJTNEJTIwRGVmYXVsdERhdGFDb2xsYXRvcihyZXR1cm5fdGVuc29ycyUzRCUyMnRmJTIyKQ==",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> DefaultDataCollator

<span class="hljs-meta">&gt;&gt;&gt; </span>data_collator = DefaultDataCollator(return_tensors=<span class="hljs-string">&quot;tf&quot;</span>)`}}),Z=new zt({props:{$$slots:{default:[Dt]},$$scope:{ctx:ge}}}),S=new A({props:{code:"dGZfdHJhaW5fZGF0YXNldCUyMCUzRCUyMHNtYWxsX3RyYWluX2RhdGFzZXQudG9fdGZfZGF0YXNldCglMEElMjAlMjAlMjAlMjBjb2x1bW5zJTNEJTVCJTIyYXR0ZW50aW9uX21hc2slMjIlMkMlMjAlMjJpbnB1dF9pZHMlMjIlMkMlMjAlMjJ0b2tlbl90eXBlX2lkcyUyMiU1RCUyQyUwQSUyMCUyMCUyMCUyMGxhYmVsX2NvbHMlM0QlNUIlMjJsYWJlbHMlMjIlNUQlMkMlMEElMjAlMjAlMjAlMjBzaHVmZmxlJTNEVHJ1ZSUyQyUwQSUyMCUyMCUyMCUyMGNvbGxhdGVfZm4lM0RkYXRhX2NvbGxhdG9yJTJDJTBBJTIwJTIwJTIwJTIwYmF0Y2hfc2l6ZSUzRDglMkMlMEEpJTBBJTBBdGZfdmFsaWRhdGlvbl9kYXRhc2V0JTIwJTNEJTIwc21hbGxfZXZhbF9kYXRhc2V0LnRvX3RmX2RhdGFzZXQoJTBBJTIwJTIwJTIwJTIwY29sdW1ucyUzRCU1QiUyMmF0dGVudGlvbl9tYXNrJTIyJTJDJTIwJTIyaW5wdXRfaWRzJTIyJTJDJTIwJTIydG9rZW5fdHlwZV9pZHMlMjIlNUQlMkMlMEElMjAlMjAlMjAlMjBsYWJlbF9jb2xzJTNEJTVCJTIybGFiZWxzJTIyJTVEJTJDJTBBJTIwJTIwJTIwJTIwc2h1ZmZsZSUzREZhbHNlJTJDJTBBJTIwJTIwJTIwJTIwY29sbGF0ZV9mbiUzRGRhdGFfY29sbGF0b3IlMkMlMEElMjAlMjAlMjAlMjBiYXRjaF9zaXplJTNEOCUyQyUwQSk=",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span>tf_train_dataset = small_train_dataset.to_tf_dataset(
<span class="hljs-meta">... </span>    columns=[<span class="hljs-string">&quot;attention_mask&quot;</span>, <span class="hljs-string">&quot;input_ids&quot;</span>, <span class="hljs-string">&quot;token_type_ids&quot;</span>],
<span class="hljs-meta">... </span>    label_cols=[<span class="hljs-string">&quot;labels&quot;</span>],
<span class="hljs-meta">... </span>    shuffle=<span class="hljs-literal">True</span>,
<span class="hljs-meta">... </span>    collate_fn=data_collator,
<span class="hljs-meta">... </span>    batch_size=<span class="hljs-number">8</span>,
<span class="hljs-meta">... </span>)

<span class="hljs-meta">&gt;&gt;&gt; </span>tf_validation_dataset = small_eval_dataset.to_tf_dataset(
<span class="hljs-meta">... </span>    columns=[<span class="hljs-string">&quot;attention_mask&quot;</span>, <span class="hljs-string">&quot;input_ids&quot;</span>, <span class="hljs-string">&quot;token_type_ids&quot;</span>],
<span class="hljs-meta">... </span>    label_cols=[<span class="hljs-string">&quot;labels&quot;</span>],
<span class="hljs-meta">... </span>    shuffle=<span class="hljs-literal">False</span>,
<span class="hljs-meta">... </span>    collate_fn=data_collator,
<span class="hljs-meta">... </span>    batch_size=<span class="hljs-number">8</span>,
<span class="hljs-meta">... </span>)`}}),z=new qe({}),I=new A({props:{code:"aW1wb3J0JTIwdGVuc29yZmxvdyUyMGFzJTIwdGYlMEFmcm9tJTIwdHJhbnNmb3JtZXJzJTIwaW1wb3J0JTIwVEZBdXRvTW9kZWxGb3JTZXF1ZW5jZUNsYXNzaWZpY2F0aW9uJTBBJTBBbW9kZWwlMjAlM0QlMjBURkF1dG9Nb2RlbEZvclNlcXVlbmNlQ2xhc3NpZmljYXRpb24uZnJvbV9wcmV0cmFpbmVkKCUyMmJlcnQtYmFzZS1jYXNlZCUyMiUyQyUyMG51bV9sYWJlbHMlM0Q1KQ==",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">import</span> tensorflow <span class="hljs-keyword">as</span> tf
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> TFAutoModelForSequenceClassification

<span class="hljs-meta">&gt;&gt;&gt; </span>model = TFAutoModelForSequenceClassification.from_pretrained(<span class="hljs-string">&quot;bert-base-cased&quot;</span>, num_labels=<span class="hljs-number">5</span>)`}}),O=new A({props:{code:"bW9kZWwuY29tcGlsZSglMEElMjAlMjAlMjAlMjBvcHRpbWl6ZXIlM0R0Zi5rZXJhcy5vcHRpbWl6ZXJzLkFkYW0obGVhcm5pbmdfcmF0ZSUzRDVlLTUpJTJDJTBBJTIwJTIwJTIwJTIwbG9zcyUzRHRmLmtlcmFzLmxvc3Nlcy5TcGFyc2VDYXRlZ29yaWNhbENyb3NzZW50cm9weShmcm9tX2xvZ2l0cyUzRFRydWUpJTJDJTBBJTIwJTIwJTIwJTIwbWV0cmljcyUzRHRmLm1ldHJpY3MuU3BhcnNlQ2F0ZWdvcmljYWxBY2N1cmFjeSgpJTJDJTBBKSUwQSUwQW1vZGVsLmZpdCh0Zl90cmFpbl9kYXRhc2V0JTJDJTIwdmFsaWRhdGlvbl9kYXRhJTNEdGZfdmFsaWRhdGlvbl9kYXRhc2V0JTJDJTIwZXBvY2hzJTNEMyk=",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span>model.<span class="hljs-built_in">compile</span>(
<span class="hljs-meta">... </span>    optimizer=tf.keras.optimizers.Adam(learning_rate=<span class="hljs-number">5e-5</span>),
<span class="hljs-meta">... </span>    loss=tf.keras.losses.SparseCategoricalCrossentropy(from_logits=<span class="hljs-literal">True</span>),
<span class="hljs-meta">... </span>    metrics=tf.metrics.SparseCategoricalAccuracy(),
<span class="hljs-meta">... </span>)

<span class="hljs-meta">&gt;&gt;&gt; </span>model.fit(tf_train_dataset, validation_data=tf_validation_dataset, epochs=<span class="hljs-number">3</span>)`}}),{c(){c=n("a"),_=i(),$(d.$$.fragment),k=i(),C=n("p"),C.textContent=X,xe=i(),E=n("h3"),x=n("a"),ae=n("span"),$(F.$$.fragment),Re=i(),U=n("span"),U.textContent=H,N=i(),V=n("p"),V.innerHTML=Ye,P=i(),$(pe.$$.fragment),be=i(),$(Z.$$.fragment),Me=i(),Y=n("p"),Y.innerHTML=L,ce=i(),$(S.$$.fragment),q=i(),R=n("h3"),Q=n("a"),D=n("span"),$(z.$$.fragment),de=i(),B=n("span"),B.textContent=Ne,Ce=i(),G=n("p"),G.textContent=ve,se=i(),$(I.$$.fragment),K=i(),W=n("p"),W.innerHTML=Ze,we=i(),$(O.$$.fragment),this.h()},l(p){c=r(p,"A",{id:!0}),w(c).forEach(e),_=o(p),y(d.$$.fragment,p),k=o(p),C=r(p,"P",{"data-svelte-h":!0}),M(C)!=="svelte-1czjgf4"&&(C.textContent=X),xe=o(p),E=r(p,"H3",{class:!0});var J=w(E);x=r(J,"A",{id:!0,class:!0,href:!0});var je=w(x);ae=r(je,"SPAN",{});var ee=w(ae);y(F.$$.fragment,ee),ee.forEach(e),je.forEach(e),Re=o(J),U=r(J,"SPAN",{"data-svelte-h":!0}),M(U)!=="svelte-101lomr"&&(U.textContent=H),J.forEach(e),N=o(p),V=r(p,"P",{"data-svelte-h":!0}),M(V)!=="svelte-18ilv9j"&&(V.innerHTML=Ye),P=o(p),y(pe.$$.fragment,p),be=o(p),y(Z.$$.fragment,p),Me=o(p),Y=r(p,"P",{"data-svelte-h":!0}),M(Y)!=="svelte-10qeq0e"&&(Y.innerHTML=L),ce=o(p),y(S.$$.fragment,p),q=o(p),R=r(p,"H3",{class:!0});var ne=w(R);Q=r(ne,"A",{id:!0,class:!0,href:!0});var re=w(Q);D=r(re,"SPAN",{});var he=w(D);y(z.$$.fragment,he),he.forEach(e),re.forEach(e),de=o(ne),B=r(ne,"SPAN",{"data-svelte-h":!0}),M(B)!=="svelte-5f84rr"&&(B.textContent=Ne),ne.forEach(e),Ce=o(p),G=r(p,"P",{"data-svelte-h":!0}),M(G)!=="svelte-7tvbf1"&&(G.textContent=ve),se=o(p),y(I.$$.fragment,p),K=o(p),W=r(p,"P",{"data-svelte-h":!0}),M(W)!=="svelte-q3nlbx"&&(W.innerHTML=Ze),we=o(p),y(O.$$.fragment,p),this.h()},h(){f(c,"id","keras"),f(x,"id","convertire-dataset-nel-formato-per-tensorflow"),f(x,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),f(x,"href","#convertire-dataset-nel-formato-per-tensorflow"),f(E,"class","relative group"),f(Q,"id","compilazione-e-addestramento"),f(Q,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),f(Q,"href","#compilazione-e-addestramento"),f(R,"class","relative group")},m(p,J){s(p,c,J),s(p,_,J),b(d,p,J),s(p,k,J),s(p,C,J),s(p,xe,J),s(p,E,J),m(E,x),m(x,ae),b(F,ae,null),m(E,Re),m(E,U),s(p,N,J),s(p,V,J),s(p,P,J),b(pe,p,J),s(p,be,J),b(Z,p,J),s(p,Me,J),s(p,Y,J),s(p,ce,J),b(S,p,J),s(p,q,J),s(p,R,J),m(R,Q),m(Q,D),b(z,D,null),m(R,de),m(R,B),s(p,Ce,J),s(p,G,J),s(p,se,J),b(I,p,J),s(p,K,J),s(p,W,J),s(p,we,J),b(O,p,J),le=!0},p(p,J){const je={};J&2&&(je.$$scope={dirty:J,ctx:p}),Z.$set(je)},i(p){le||(v(d.$$.fragment,p),v(F.$$.fragment,p),v(pe.$$.fragment,p),v(Z.$$.fragment,p),v(S.$$.fragment,p),v(z.$$.fragment,p),v(I.$$.fragment,p),v(O.$$.fragment,p),le=!0)},o(p){j(d.$$.fragment,p),j(F.$$.fragment,p),j(pe.$$.fragment,p),j(Z.$$.fragment,p),j(S.$$.fragment,p),j(z.$$.fragment,p),j(I.$$.fragment,p),j(O.$$.fragment,p),le=!1},d(p){p&&(e(c),e(_),e(k),e(C),e(xe),e(E),e(N),e(V),e(P),e(be),e(Me),e(Y),e(ce),e(q),e(R),e(Ce),e(G),e(se),e(K),e(W),e(we)),T(d,p),T(F),T(pe,p),T(Z,p),T(S,p),T(z),T(I,p),T(O,p)}}}function Ot(ge){let c,_;return c=new It({props:{$$slots:{default:[Kt]},$$scope:{ctx:ge}}}),{c(){$(c.$$.fragment)},l(d){y(c.$$.fragment,d)},m(d,k){b(c,d,k),_=!0},p(d,k){const C={};k&2&&(C.$$scope={dirty:k,ctx:d}),c.$set(C)},i(d){_||(v(c.$$.fragment,d),_=!0)},o(d){j(c.$$.fragment,d),_=!1},d(d){T(c,d)}}}function ea(ge){let c,_='Ottieni l’accesso gratuito a una GPU sul cloud se non ne possiedi una usando un notebook sul web come <a href="https://colab.research.google.com/" rel="nofollow">Colaboratory</a> o <a href="https://studiolab.sagemaker.aws/" rel="nofollow">SageMaker StudioLab</a>.';return{c(){c=n("p"),c.innerHTML=_},l(d){c=r(d,"P",{"data-svelte-h":!0}),M(c)!=="svelte-1uxpyqe"&&(c.innerHTML=_)},m(d,k){s(d,c,k)},p:Ut,d(d){d&&e(c)}}}function ta(ge){let c,_,d,k="<code>Trainer</code> si occupa del ciclo di addestramento e ti consente di mettere a punto un modello con una sola riga di codice. Per chi preferisse scrivere un proprio ciclo di addestramento personale, puoi anche fare il fine-tuning di un modello 🤗 Transformers in PyTorch nativo.",C,X,xe="A questo punto, potresti avere bisogno di riavviare il tuo notebook o eseguire il seguente codice per liberare un po’ di memoria:",E,x,ae,F,Re="Successivamente, postprocessa manualmente il <code>tokenized_dataset</code> per prepararlo ad essere allenato.",U,H,N,V,Ye="Rimuovi la colonna <code>text</code> perché il modello non accetta testo grezzo come input:",P,pe,be,Z,Me,Y="Rinomina la colonna <code>label</code> in <code>labels</code> perché il modello si aspetta che questo argomento si chiami <code>labels</code>:",L,ce,S,q,R,Q="Imposta il formato del dataset per farti restituire tensori di PyTorch all’interno delle liste:",D,z,de,B,Ne="Poi crea un piccolo sottocampione del dataset come visto precedentemente per velocizzare il fine-tuning:",Ce,G,ve,se,I,K,W,Ze,we,O="DataLoader",le,p,J="Crea un <code>DataLoader</code> per i tuoi datasets di train e test così puoi iterare sui lotti di dati:",je,ee,ne,re,he="Carica il tuo modello con il numero atteso di etichette:",te,ie,Te,me,$e,Be,Ae,Ge,Je,Pe="Ottimizzatore e learning rate scheduler",ye,Ue,ue='Crea un ottimizzatore e il learning rate scheduler per fare il fine-tuning del modello. Usa l’ottimizzatore <a href="https://pytorch.org/docs/stable/generated/torch.optim.AdamW.html" rel="nofollow"><code>AdamW</code></a> di PyTorch:',We,_e,fe,Xe,l="Crea il learning rate scheduler predefinito da <code>Trainer</code>:",g,ke,Ee,ze,Le="Infine specifica come <code>device</code> da usare una GPU se ne hai una. Altrimenti, l’addestramento su una CPU può richiedere diverse ore invece di un paio di minuti.",De,oe,Fe,Ie,Ke,at,pt="Ottimo, adesso possiamo addestrare! 🥳",Mt,Se,He,ut,Oe,st,ct,wt="Training loop",lt,et,a='Per tenere traccia dei tuoi progressi durante l’addestramento, usa la libreria <a href="https://tqdm.github.io/" rel="nofollow">tqdm</a> per aggiungere una progress bar sopra il numero dei passi di addestramento:',h,Ve,nt,tt,Qe,ft,rt,gt,dt,bt="Metriche",mt,it,vt='Proprio come è necessario aggiungere una funzione di valutazione del <code>Trainer</code>, è necessario fare lo stesso quando si scrive il proprio ciclo di addestramento. Ma invece di calcolare e riportare la metrica alla fine di ogni epoca, questa volta accumulerai tutti i batch con <a href="https://huggingface.co/docs/datasets/package_reference/main_classes.html?highlight=add_batch#datasets.Metric.add_batch" rel="nofollow"><code>add_batch</code></a> e calcolerai la metrica alla fine.',ht,ot,$t;return c=new Zt({props:{id:"Dh9CL8fyG80"}}),x=new A({props:{code:"ZGVsJTIwbW9kZWwlMEFkZWwlMjBweXRvcmNoX21vZGVsJTBBZGVsJTIwdHJhaW5lciUwQXRvcmNoLmN1ZGEuZW1wdHlfY2FjaGUoKQ==",highlighted:`<span class="hljs-keyword">del</span> model
<span class="hljs-keyword">del</span> pytorch_model
<span class="hljs-keyword">del</span> trainer
torch.cuda.empty_cache()`}}),pe=new A({props:{code:"dG9rZW5pemVkX2RhdGFzZXRzJTIwJTNEJTIwdG9rZW5pemVkX2RhdGFzZXRzLnJlbW92ZV9jb2x1bW5zKCU1QiUyMnRleHQlMjIlNUQp",highlighted:'<span class="hljs-meta">&gt;&gt;&gt; </span>tokenized_datasets = tokenized_datasets.remove_columns([<span class="hljs-string">&quot;text&quot;</span>])'}}),ce=new A({props:{code:"dG9rZW5pemVkX2RhdGFzZXRzJTIwJTNEJTIwdG9rZW5pemVkX2RhdGFzZXRzLnJlbmFtZV9jb2x1bW4oJTIybGFiZWwlMjIlMkMlMjAlMjJsYWJlbHMlMjIp",highlighted:'<span class="hljs-meta">&gt;&gt;&gt; </span>tokenized_datasets = tokenized_datasets.rename_column(<span class="hljs-string">&quot;label&quot;</span>, <span class="hljs-string">&quot;labels&quot;</span>)'}}),z=new A({props:{code:"dG9rZW5pemVkX2RhdGFzZXRzLnNldF9mb3JtYXQoJTIydG9yY2glMjIp",highlighted:'<span class="hljs-meta">&gt;&gt;&gt; </span>tokenized_datasets.set_format(<span class="hljs-string">&quot;torch&quot;</span>)'}}),G=new A({props:{code:"c21hbGxfdHJhaW5fZGF0YXNldCUyMCUzRCUyMHRva2VuaXplZF9kYXRhc2V0cyU1QiUyMnRyYWluJTIyJTVELnNodWZmbGUoc2VlZCUzRDQyKS5zZWxlY3QocmFuZ2UoMTAwMCkpJTBBc21hbGxfZXZhbF9kYXRhc2V0JTIwJTNEJTIwdG9rZW5pemVkX2RhdGFzZXRzJTVCJTIydGVzdCUyMiU1RC5zaHVmZmxlKHNlZWQlM0Q0Mikuc2VsZWN0KHJhbmdlKDEwMDApKQ==",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span>small_train_dataset = tokenized_datasets[<span class="hljs-string">&quot;train&quot;</span>].shuffle(seed=<span class="hljs-number">42</span>).select(<span class="hljs-built_in">range</span>(<span class="hljs-number">1000</span>))
<span class="hljs-meta">&gt;&gt;&gt; </span>small_eval_dataset = tokenized_datasets[<span class="hljs-string">&quot;test&quot;</span>].shuffle(seed=<span class="hljs-number">42</span>).select(<span class="hljs-built_in">range</span>(<span class="hljs-number">1000</span>))`}}),W=new qe({}),ee=new A({props:{code:"ZnJvbSUyMHRvcmNoLnV0aWxzLmRhdGElMjBpbXBvcnQlMjBEYXRhTG9hZGVyJTBBJTBBdHJhaW5fZGF0YWxvYWRlciUyMCUzRCUyMERhdGFMb2FkZXIoc21hbGxfdHJhaW5fZGF0YXNldCUyQyUyMHNodWZmbGUlM0RUcnVlJTJDJTIwYmF0Y2hfc2l6ZSUzRDgpJTBBZXZhbF9kYXRhbG9hZGVyJTIwJTNEJTIwRGF0YUxvYWRlcihzbWFsbF9ldmFsX2RhdGFzZXQlMkMlMjBiYXRjaF9zaXplJTNEOCk=",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> torch.utils.data <span class="hljs-keyword">import</span> DataLoader

<span class="hljs-meta">&gt;&gt;&gt; </span>train_dataloader = DataLoader(small_train_dataset, shuffle=<span class="hljs-literal">True</span>, batch_size=<span class="hljs-number">8</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>eval_dataloader = DataLoader(small_eval_dataset, batch_size=<span class="hljs-number">8</span>)`}}),ie=new A({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9Nb2RlbEZvclNlcXVlbmNlQ2xhc3NpZmljYXRpb24lMEElMEFtb2RlbCUyMCUzRCUyMEF1dG9Nb2RlbEZvclNlcXVlbmNlQ2xhc3NpZmljYXRpb24uZnJvbV9wcmV0cmFpbmVkKCUyMmJlcnQtYmFzZS1jYXNlZCUyMiUyQyUyMG51bV9sYWJlbHMlM0Q1KQ==",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoModelForSequenceClassification

<span class="hljs-meta">&gt;&gt;&gt; </span>model = AutoModelForSequenceClassification.from_pretrained(<span class="hljs-string">&quot;bert-base-cased&quot;</span>, num_labels=<span class="hljs-number">5</span>)`}}),Ae=new qe({}),_e=new A({props:{code:"ZnJvbSUyMHRvcmNoLm9wdGltJTIwaW1wb3J0JTIwQWRhbVclMEElMEFvcHRpbWl6ZXIlMjAlM0QlMjBBZGFtVyhtb2RlbC5wYXJhbWV0ZXJzKCklMkMlMjBsciUzRDVlLTUp",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> torch.optim <span class="hljs-keyword">import</span> AdamW

<span class="hljs-meta">&gt;&gt;&gt; </span>optimizer = AdamW(model.parameters(), lr=<span class="hljs-number">5e-5</span>)`}}),ke=new A({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMGdldF9zY2hlZHVsZXIlMEElMEFudW1fZXBvY2hzJTIwJTNEJTIwMyUwQW51bV90cmFpbmluZ19zdGVwcyUyMCUzRCUyMG51bV9lcG9jaHMlMjAqJTIwbGVuKHRyYWluX2RhdGFsb2FkZXIpJTBBbHJfc2NoZWR1bGVyJTIwJTNEJTIwZ2V0X3NjaGVkdWxlciglMEElMjAlMjAlMjAlMjBuYW1lJTNEJTIybGluZWFyJTIyJTJDJTIwb3B0aW1pemVyJTNEb3B0aW1pemVyJTJDJTIwbnVtX3dhcm11cF9zdGVwcyUzRDAlMkMlMjBudW1fdHJhaW5pbmdfc3RlcHMlM0RudW1fdHJhaW5pbmdfc3RlcHMlMEEp",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> get_scheduler

<span class="hljs-meta">&gt;&gt;&gt; </span>num_epochs = <span class="hljs-number">3</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>num_training_steps = num_epochs * <span class="hljs-built_in">len</span>(train_dataloader)
<span class="hljs-meta">&gt;&gt;&gt; </span>lr_scheduler = get_scheduler(
<span class="hljs-meta">... </span>    name=<span class="hljs-string">&quot;linear&quot;</span>, optimizer=optimizer, num_warmup_steps=<span class="hljs-number">0</span>, num_training_steps=num_training_steps
<span class="hljs-meta">... </span>)`}}),oe=new A({props:{code:"aW1wb3J0JTIwdG9yY2glMEElMEFkZXZpY2UlMjAlM0QlMjB0b3JjaC5kZXZpY2UoJTIyY3VkYSUyMiklMjBpZiUyMHRvcmNoLmN1ZGEuaXNfYXZhaWxhYmxlKCklMjBlbHNlJTIwdG9yY2guZGV2aWNlKCUyMmNwdSUyMiklMEFtb2RlbC50byhkZXZpY2Up",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">import</span> torch

<span class="hljs-meta">&gt;&gt;&gt; </span>device = torch.device(<span class="hljs-string">&quot;cuda&quot;</span>) <span class="hljs-keyword">if</span> torch.cuda.is_available() <span class="hljs-keyword">else</span> torch.device(<span class="hljs-string">&quot;cpu&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>model.to(device)`}}),Ie=new zt({props:{$$slots:{default:[ea]},$$scope:{ctx:ge}}}),Oe=new qe({}),Ve=new A({props:{code:"ZnJvbSUyMHRxZG0uYXV0byUyMGltcG9ydCUyMHRxZG0lMEElMEFwcm9ncmVzc19iYXIlMjAlM0QlMjB0cWRtKHJhbmdlKG51bV90cmFpbmluZ19zdGVwcykpJTBBJTBBbW9kZWwudHJhaW4oKSUwQWZvciUyMGVwb2NoJTIwaW4lMjByYW5nZShudW1fZXBvY2hzKSUzQSUwQSUyMCUyMCUyMCUyMGZvciUyMGJhdGNoJTIwaW4lMjB0cmFpbl9kYXRhbG9hZGVyJTNBJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwYmF0Y2glMjAlM0QlMjAlN0JrJTNBJTIwdi50byhkZXZpY2UpJTIwZm9yJTIwayUyQyUyMHYlMjBpbiUyMGJhdGNoLml0ZW1zKCklN0QlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBvdXRwdXRzJTIwJTNEJTIwbW9kZWwoKipiYXRjaCklMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBsb3NzJTIwJTNEJTIwb3V0cHV0cy5sb3NzJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwbG9zcy5iYWNrd2FyZCgpJTBBJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwb3B0aW1pemVyLnN0ZXAoKSUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMGxyX3NjaGVkdWxlci5zdGVwKCklMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBvcHRpbWl6ZXIuemVyb19ncmFkKCklMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBwcm9ncmVzc19iYXIudXBkYXRlKDEp",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> tqdm.auto <span class="hljs-keyword">import</span> tqdm

<span class="hljs-meta">&gt;&gt;&gt; </span>progress_bar = tqdm(<span class="hljs-built_in">range</span>(num_training_steps))

<span class="hljs-meta">&gt;&gt;&gt; </span>model.train()
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">for</span> epoch <span class="hljs-keyword">in</span> <span class="hljs-built_in">range</span>(num_epochs):
<span class="hljs-meta">... </span>    <span class="hljs-keyword">for</span> batch <span class="hljs-keyword">in</span> train_dataloader:
<span class="hljs-meta">... </span>        batch = {k: v.to(device) <span class="hljs-keyword">for</span> k, v <span class="hljs-keyword">in</span> batch.items()}
<span class="hljs-meta">... </span>        outputs = model(**batch)
<span class="hljs-meta">... </span>        loss = outputs.loss
<span class="hljs-meta">... </span>        loss.backward()

<span class="hljs-meta">... </span>        optimizer.step()
<span class="hljs-meta">... </span>        lr_scheduler.step()
<span class="hljs-meta">... </span>        optimizer.zero_grad()
<span class="hljs-meta">... </span>        progress_bar.update(<span class="hljs-number">1</span>)`}}),rt=new qe({}),ot=new A({props:{code:"bWV0cmljJTIwJTNEJTIwbG9hZF9tZXRyaWMoJTIyYWNjdXJhY3klMjIpJTBBbW9kZWwuZXZhbCgpJTBBZm9yJTIwYmF0Y2glMjBpbiUyMGV2YWxfZGF0YWxvYWRlciUzQSUwQSUyMCUyMCUyMCUyMGJhdGNoJTIwJTNEJTIwJTdCayUzQSUyMHYudG8oZGV2aWNlKSUyMGZvciUyMGslMkMlMjB2JTIwaW4lMjBiYXRjaC5pdGVtcygpJTdEJTBBJTIwJTIwJTIwJTIwd2l0aCUyMHRvcmNoLm5vX2dyYWQoKSUzQSUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMG91dHB1dHMlMjAlM0QlMjBtb2RlbCgqKmJhdGNoKSUwQSUwQSUyMCUyMCUyMCUyMGxvZ2l0cyUyMCUzRCUyMG91dHB1dHMubG9naXRzJTBBJTIwJTIwJTIwJTIwcHJlZGljdGlvbnMlMjAlM0QlMjB0b3JjaC5hcmdtYXgobG9naXRzJTJDJTIwZGltJTNELTEpJTBBJTIwJTIwJTIwJTIwbWV0cmljLmFkZF9iYXRjaChwcmVkaWN0aW9ucyUzRHByZWRpY3Rpb25zJTJDJTIwcmVmZXJlbmNlcyUzRGJhdGNoJTVCJTIybGFiZWxzJTIyJTVEKSUwQSUwQW1ldHJpYy5jb21wdXRlKCk=",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span>metric = load_metric(<span class="hljs-string">&quot;accuracy&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>model.<span class="hljs-built_in">eval</span>()
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">for</span> batch <span class="hljs-keyword">in</span> eval_dataloader:
<span class="hljs-meta">... </span>    batch = {k: v.to(device) <span class="hljs-keyword">for</span> k, v <span class="hljs-keyword">in</span> batch.items()}
<span class="hljs-meta">... </span>    <span class="hljs-keyword">with</span> torch.no_grad():
<span class="hljs-meta">... </span>        outputs = model(**batch)

<span class="hljs-meta">... </span>    logits = outputs.logits
<span class="hljs-meta">... </span>    predictions = torch.argmax(logits, dim=-<span class="hljs-number">1</span>)
<span class="hljs-meta">... </span>    metric.add_batch(predictions=predictions, references=batch[<span class="hljs-string">&quot;labels&quot;</span>])

<span class="hljs-meta">&gt;&gt;&gt; </span>metric.compute()`}}),{c(){$(c.$$.fragment),_=i(),d=n("p"),d.innerHTML=k,C=i(),X=n("p"),X.textContent=xe,E=i(),$(x.$$.fragment),ae=i(),F=n("p"),F.innerHTML=Re,U=i(),H=n("ol"),N=n("li"),V=n("p"),V.innerHTML=Ye,P=i(),$(pe.$$.fragment),be=i(),Z=n("li"),Me=n("p"),Me.innerHTML=Y,L=i(),$(ce.$$.fragment),S=i(),q=n("li"),R=n("p"),R.textContent=Q,D=i(),$(z.$$.fragment),de=i(),B=n("p"),B.textContent=Ne,Ce=i(),$(G.$$.fragment),ve=i(),se=n("h3"),I=n("a"),K=n("span"),$(W.$$.fragment),Ze=i(),we=n("span"),we.textContent=O,le=i(),p=n("p"),p.innerHTML=J,je=i(),$(ee.$$.fragment),ne=i(),re=n("p"),re.textContent=he,te=i(),$(ie.$$.fragment),Te=i(),me=n("h3"),$e=n("a"),Be=n("span"),$(Ae.$$.fragment),Ge=i(),Je=n("span"),Je.textContent=Pe,ye=i(),Ue=n("p"),Ue.innerHTML=ue,We=i(),$(_e.$$.fragment),fe=i(),Xe=n("p"),Xe.innerHTML=l,g=i(),$(ke.$$.fragment),Ee=i(),ze=n("p"),ze.innerHTML=Le,De=i(),$(oe.$$.fragment),Fe=i(),$(Ie.$$.fragment),Ke=i(),at=n("p"),at.textContent=pt,Mt=i(),Se=n("h3"),He=n("a"),ut=n("span"),$(Oe.$$.fragment),st=i(),ct=n("span"),ct.textContent=wt,lt=i(),et=n("p"),et.innerHTML=a,h=i(),$(Ve.$$.fragment),nt=i(),tt=n("h3"),Qe=n("a"),ft=n("span"),$(rt.$$.fragment),gt=i(),dt=n("span"),dt.textContent=bt,mt=i(),it=n("p"),it.innerHTML=vt,ht=i(),$(ot.$$.fragment),this.h()},l(t){y(c.$$.fragment,t),_=o(t),d=r(t,"P",{"data-svelte-h":!0}),M(d)!=="svelte-1czap62"&&(d.innerHTML=k),C=o(t),X=r(t,"P",{"data-svelte-h":!0}),M(X)!=="svelte-1jv7qcp"&&(X.textContent=xe),E=o(t),y(x.$$.fragment,t),ae=o(t),F=r(t,"P",{"data-svelte-h":!0}),M(F)!=="svelte-p1uyrm"&&(F.innerHTML=Re),U=o(t),H=r(t,"OL",{});var u=w(H);N=r(u,"LI",{});var yt=w(N);V=r(yt,"P",{"data-svelte-h":!0}),M(V)!=="svelte-unbmvy"&&(V.innerHTML=Ye),P=o(yt),y(pe.$$.fragment,yt),yt.forEach(e),be=o(u),Z=r(u,"LI",{});var jt=w(Z);Me=r(jt,"P",{"data-svelte-h":!0}),M(Me)!=="svelte-zdvzgi"&&(Me.innerHTML=Y),L=o(jt),y(ce.$$.fragment,jt),jt.forEach(e),S=o(u),q=r(u,"LI",{});var Tt=w(q);R=r(Tt,"P",{"data-svelte-h":!0}),M(R)!=="svelte-ufikes"&&(R.textContent=Q),D=o(Tt),y(z.$$.fragment,Tt),Tt.forEach(e),u.forEach(e),de=o(t),B=r(t,"P",{"data-svelte-h":!0}),M(B)!=="svelte-6j1d26"&&(B.textContent=Ne),Ce=o(t),y(G.$$.fragment,t),ve=o(t),se=r(t,"H3",{class:!0});var Jt=w(se);I=r(Jt,"A",{id:!0,class:!0,href:!0});var xt=w(I);K=r(xt,"SPAN",{});var Rt=w(K);y(W.$$.fragment,Rt),Rt.forEach(e),xt.forEach(e),Ze=o(Jt),we=r(Jt,"SPAN",{"data-svelte-h":!0}),M(we)!=="svelte-19b0x1w"&&(we.textContent=O),Jt.forEach(e),le=o(t),p=r(t,"P",{"data-svelte-h":!0}),M(p)!=="svelte-1wjjxmk"&&(p.innerHTML=J),je=o(t),y(ee.$$.fragment,t),ne=o(t),re=r(t,"P",{"data-svelte-h":!0}),M(re)!=="svelte-k6va0p"&&(re.textContent=he),te=o(t),y(ie.$$.fragment,t),Te=o(t),me=r(t,"H3",{class:!0});var _t=w(me);$e=r(_t,"A",{id:!0,class:!0,href:!0});var Gt=w($e);Be=r(Gt,"SPAN",{});var Wt=w(Be);y(Ae.$$.fragment,Wt),Wt.forEach(e),Gt.forEach(e),Ge=o(_t),Je=r(_t,"SPAN",{"data-svelte-h":!0}),M(Je)!=="svelte-lzr108"&&(Je.textContent=Pe),_t.forEach(e),ye=o(t),Ue=r(t,"P",{"data-svelte-h":!0}),M(Ue)!=="svelte-q4abxx"&&(Ue.innerHTML=ue),We=o(t),y(_e.$$.fragment,t),fe=o(t),Xe=r(t,"P",{"data-svelte-h":!0}),M(Xe)!=="svelte-1o911h5"&&(Xe.innerHTML=l),g=o(t),y(ke.$$.fragment,t),Ee=o(t),ze=r(t,"P",{"data-svelte-h":!0}),M(ze)!=="svelte-jmyeit"&&(ze.innerHTML=Le),De=o(t),y(oe.$$.fragment,t),Fe=o(t),y(Ie.$$.fragment,t),Ke=o(t),at=r(t,"P",{"data-svelte-h":!0}),M(at)!=="svelte-1x4skh5"&&(at.textContent=pt),Mt=o(t),Se=r(t,"H3",{class:!0});var kt=w(Se);He=r(kt,"A",{id:!0,class:!0,href:!0});var Xt=w(He);ut=r(Xt,"SPAN",{});var Et=w(ut);y(Oe.$$.fragment,Et),Et.forEach(e),Xt.forEach(e),st=o(kt),ct=r(kt,"SPAN",{"data-svelte-h":!0}),M(ct)!=="svelte-1pquwg7"&&(ct.textContent=wt),kt.forEach(e),lt=o(t),et=r(t,"P",{"data-svelte-h":!0}),M(et)!=="svelte-yb503k"&&(et.innerHTML=a),h=o(t),y(Ve.$$.fragment,t),nt=o(t),tt=r(t,"H3",{class:!0});var Ct=w(tt);Qe=r(Ct,"A",{id:!0,class:!0,href:!0});var Ft=w(Qe);ft=r(Ft,"SPAN",{});var Ht=w(ft);y(rt.$$.fragment,Ht),Ht.forEach(e),Ft.forEach(e),gt=o(Ct),dt=r(Ct,"SPAN",{"data-svelte-h":!0}),M(dt)!=="svelte-ygnsok"&&(dt.textContent=bt),Ct.forEach(e),mt=o(t),it=r(t,"P",{"data-svelte-h":!0}),M(it)!=="svelte-1eki98u"&&(it.innerHTML=vt),ht=o(t),y(ot.$$.fragment,t),this.h()},h(){f(I,"id","dataloader"),f(I,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),f(I,"href","#dataloader"),f(se,"class","relative group"),f($e,"id","ottimizzatore-e-learning-rate-scheduler"),f($e,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),f($e,"href","#ottimizzatore-e-learning-rate-scheduler"),f(me,"class","relative group"),f(He,"id","training-loop"),f(He,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),f(He,"href","#training-loop"),f(Se,"class","relative group"),f(Qe,"id","metriche"),f(Qe,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),f(Qe,"href","#metriche"),f(tt,"class","relative group")},m(t,u){b(c,t,u),s(t,_,u),s(t,d,u),s(t,C,u),s(t,X,u),s(t,E,u),b(x,t,u),s(t,ae,u),s(t,F,u),s(t,U,u),s(t,H,u),m(H,N),m(N,V),m(N,P),b(pe,N,null),m(H,be),m(H,Z),m(Z,Me),m(Z,L),b(ce,Z,null),m(H,S),m(H,q),m(q,R),m(q,D),b(z,q,null),s(t,de,u),s(t,B,u),s(t,Ce,u),b(G,t,u),s(t,ve,u),s(t,se,u),m(se,I),m(I,K),b(W,K,null),m(se,Ze),m(se,we),s(t,le,u),s(t,p,u),s(t,je,u),b(ee,t,u),s(t,ne,u),s(t,re,u),s(t,te,u),b(ie,t,u),s(t,Te,u),s(t,me,u),m(me,$e),m($e,Be),b(Ae,Be,null),m(me,Ge),m(me,Je),s(t,ye,u),s(t,Ue,u),s(t,We,u),b(_e,t,u),s(t,fe,u),s(t,Xe,u),s(t,g,u),b(ke,t,u),s(t,Ee,u),s(t,ze,u),s(t,De,u),b(oe,t,u),s(t,Fe,u),b(Ie,t,u),s(t,Ke,u),s(t,at,u),s(t,Mt,u),s(t,Se,u),m(Se,He),m(He,ut),b(Oe,ut,null),m(Se,st),m(Se,ct),s(t,lt,u),s(t,et,u),s(t,h,u),b(Ve,t,u),s(t,nt,u),s(t,tt,u),m(tt,Qe),m(Qe,ft),b(rt,ft,null),m(tt,gt),m(tt,dt),s(t,mt,u),s(t,it,u),s(t,ht,u),b(ot,t,u),$t=!0},p(t,u){const yt={};u&2&&(yt.$$scope={dirty:u,ctx:t}),Ie.$set(yt)},i(t){$t||(v(c.$$.fragment,t),v(x.$$.fragment,t),v(pe.$$.fragment,t),v(ce.$$.fragment,t),v(z.$$.fragment,t),v(G.$$.fragment,t),v(W.$$.fragment,t),v(ee.$$.fragment,t),v(ie.$$.fragment,t),v(Ae.$$.fragment,t),v(_e.$$.fragment,t),v(ke.$$.fragment,t),v(oe.$$.fragment,t),v(Ie.$$.fragment,t),v(Oe.$$.fragment,t),v(Ve.$$.fragment,t),v(rt.$$.fragment,t),v(ot.$$.fragment,t),$t=!0)},o(t){j(c.$$.fragment,t),j(x.$$.fragment,t),j(pe.$$.fragment,t),j(ce.$$.fragment,t),j(z.$$.fragment,t),j(G.$$.fragment,t),j(W.$$.fragment,t),j(ee.$$.fragment,t),j(ie.$$.fragment,t),j(Ae.$$.fragment,t),j(_e.$$.fragment,t),j(ke.$$.fragment,t),j(oe.$$.fragment,t),j(Ie.$$.fragment,t),j(Oe.$$.fragment,t),j(Ve.$$.fragment,t),j(rt.$$.fragment,t),j(ot.$$.fragment,t),$t=!1},d(t){t&&(e(_),e(d),e(C),e(X),e(E),e(ae),e(F),e(U),e(H),e(de),e(B),e(Ce),e(ve),e(se),e(le),e(p),e(je),e(ne),e(re),e(te),e(Te),e(me),e(ye),e(Ue),e(We),e(fe),e(Xe),e(g),e(Ee),e(ze),e(De),e(Fe),e(Ke),e(at),e(Mt),e(Se),e(lt),e(et),e(h),e(nt),e(tt),e(mt),e(it),e(ht)),T(c,t),T(x,t),T(pe),T(ce),T(z),T(G,t),T(W),T(ee,t),T(ie,t),T(Ae),T(_e,t),T(ke,t),T(oe,t),T(Ie,t),T(Oe),T(Ve,t),T(rt),T(ot,t)}}}function aa(ge){let c,_;return c=new It({props:{$$slots:{default:[ta]},$$scope:{ctx:ge}}}),{c(){$(c.$$.fragment)},l(d){y(c.$$.fragment,d)},m(d,k){b(c,d,k),_=!0},p(d,k){const C={};k&2&&(C.$$scope={dirty:k,ctx:d}),c.$set(C)},i(d){_||(v(c.$$.fragment,d),_=!0)},o(d){j(c.$$.fragment,d),_=!1},d(d){T(c,d)}}}function sa(ge){let c,_,d,k,C,X,xe,E,x,ae,F="Fine-tuning di un modello pre-addestrato",Re,U,H,N,V="Ci sono benefici significativi nell’usare un modello pre-addestrato. Si riducono i costi computazionali, l’impronta di carbonio e ti consente di usare modelli stato dell’arte senza doverli addestrare da zero. 🤗 Transformers consente l’accesso a migliaia di modelli pre-addestrati per un’ampia gamma di compiti. Quando usi un modello pre-addestrato, lo alleni su un dataset specifico per il tuo compito. Questo è conosciuto come fine-tuning, una tecnica di addestramento incredibilmente potente. In questa esercitazione, potrai fare il fine-tuning di un modello pre-addestrato, con un framework di deep learning a tua scelta:",Ye,P,pe="<li>Fine-tuning di un modello pre-addestrato con 🤗 Transformers <code>Trainer</code>.</li> <li>Fine-tuning di un modello pre-addestrato in TensorFlow con Keras.</li> <li>Fine-tuning di un modello pre-addestrato con PyTorch.</li>",be,Z,Me,Y,L,ce,S,q,R,Q="Preparare un dataset",D,z,de,B,Ne="Prima di poter fare il fine-tuning di un modello pre-addestrato, scarica un dataset e preparalo per l’addestramento. La precedente esercitazione ti ha mostrato come processare i dati per l’addestramento e adesso hai l’opportunità di metterti alla prova!",Ce,G,ve='Inizia caricando il dataset <a href="https://huggingface.co/datasets/yelp_review_full" rel="nofollow">Yelp Reviews</a>:',se,I,K,W,Ze='Come già sai, hai bisogno di un tokenizer per processare il testo e includere una strategia di padding e truncation per gestire sequenze di lunghezza variabile. Per processare il dataset in un unico passo, usa il metodo <a href="https://huggingface.co/docs/datasets/process.html#map" rel="nofollow"><code>map</code></a> di 🤗 Datasets che applica la funzione di preprocessing all’intero dataset:',we,O,le,p,J="Se vuoi, puoi creare un sottoinsieme più piccolo del dataset per il fine-tuning così da ridurre il tempo necessario:",je,ee,ne,re,he,te,ie,Te,me,$e,Be,Ae="Addestramento",Ge,Je,Pe,ye,Ue,ue,We,_e,fe,Xe,l,g="Addestramento in PyTorch nativo",ke,Ee,ze,Le,De,oe,Fe,Ie,Ke,at,pt,Mt="Altre risorse",Se,He,ut="Per altri esempi sul fine-tuning, fai riferimento a:",Oe,st,ct='<li><p><a href="https://github.com/huggingface/transformers/tree/main/examples" rel="nofollow">🤗 Transformers Examples</a> include scripts per addestrare compiti comuni di NLP in PyTorch e TensorFlow.</p></li> <li><p><a href="notebooks">🤗 Transformers Notebooks</a> contiene diversi notebooks su come mettere a punto un modello per compiti specifici in PyTorch e TensorFlow.</p></li>',wt,lt,et;return E=new qe({}),U=new qt({props:{classNames:"absolute z-10 right-0 top-0",options:[{label:"Mixed",value:"https://colab.research.google.com/github/huggingface/notebooks/blob/main/transformers_doc/it/training.ipynb"},{label:"PyTorch",value:"https://colab.research.google.com/github/huggingface/notebooks/blob/main/transformers_doc/it/pytorch/training.ipynb"},{label:"TensorFlow",value:"https://colab.research.google.com/github/huggingface/notebooks/blob/main/transformers_doc/it/tensorflow/training.ipynb"},{label:"Mixed",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/main/transformers_doc/it/training.ipynb"},{label:"PyTorch",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/main/transformers_doc/it/pytorch/training.ipynb"},{label:"TensorFlow",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/main/transformers_doc/it/tensorflow/training.ipynb"}]}}),S=new qe({}),z=new Zt({props:{id:"_BZearw7f0w"}}),I=new A({props:{code:"ZnJvbSUyMGRhdGFzZXRzJTIwaW1wb3J0JTIwbG9hZF9kYXRhc2V0JTBBJTBBZGF0YXNldCUyMCUzRCUyMGxvYWRfZGF0YXNldCglMjJ5ZWxwX3Jldmlld19mdWxsJTIyKSUwQWRhdGFzZXQlNUIlMjJ0cmFpbiUyMiU1RCU1QjEwMCU1RA==",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> datasets <span class="hljs-keyword">import</span> load_dataset

<span class="hljs-meta">&gt;&gt;&gt; </span>dataset = load_dataset(<span class="hljs-string">&quot;yelp_review_full&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>dataset[<span class="hljs-string">&quot;train&quot;</span>][<span class="hljs-number">100</span>]
{<span class="hljs-string">&#x27;label&#x27;</span>: <span class="hljs-number">0</span>,
 <span class="hljs-string">&#x27;text&#x27;</span>: <span class="hljs-string">&#x27;My expectations for McDonalds are t rarely high. But for one to still fail so spectacularly...that takes something special!\\\\nThe cashier took my friends\\&#x27;s order, then promptly ignored me. I had to force myself in front of a cashier who opened his register to wait on the person BEHIND me. I waited over five minutes for a gigantic order that included precisely one kid\\&#x27;s meal. After watching two people who ordered after me be handed their food, I asked where mine was. The manager started yelling at the cashiers for \\\\&quot;serving off their orders\\\\&quot; when they didn\\&#x27;t have their food. But neither cashier was anywhere near those controls, and the manager was the one serving food to customers and clearing the boards.\\\\nThe manager was rude when giving me my order. She didn\\&#x27;t make sure that I had everything ON MY RECEIPT, and never even had the decency to apologize that I felt I was getting poor service.\\\\nI\\&#x27;ve eaten at various McDonalds restaurants for over 30 years. I\\&#x27;ve worked at more than one location. I expect bad days, bad moods, and the occasional mistake. But I have yet to have a decent experience at this store. It will remain a place I avoid unless someone in my party needs to avoid illness from low blood sugar. Perhaps I should go back to the racially biased service of Steak n Shake instead!&#x27;</span>}`}}),O=new A({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9Ub2tlbml6ZXIlMEElMEF0b2tlbml6ZXIlMjAlM0QlMjBBdXRvVG9rZW5pemVyLmZyb21fcHJldHJhaW5lZCglMjJiZXJ0LWJhc2UtY2FzZWQlMjIpJTBBJTBBJTBBZGVmJTIwdG9rZW5pemVfZnVuY3Rpb24oZXhhbXBsZXMpJTNBJTBBJTIwJTIwJTIwJTIwcmV0dXJuJTIwdG9rZW5pemVyKGV4YW1wbGVzJTVCJTIydGV4dCUyMiU1RCUyQyUyMHBhZGRpbmclM0QlMjJtYXhfbGVuZ3RoJTIyJTJDJTIwdHJ1bmNhdGlvbiUzRFRydWUpJTBBJTBBJTBBdG9rZW5pemVkX2RhdGFzZXRzJTIwJTNEJTIwZGF0YXNldC5tYXAodG9rZW5pemVfZnVuY3Rpb24lMkMlMjBiYXRjaGVkJTNEVHJ1ZSk=",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoTokenizer

<span class="hljs-meta">&gt;&gt;&gt; </span>tokenizer = AutoTokenizer.from_pretrained(<span class="hljs-string">&quot;bert-base-cased&quot;</span>)


<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">def</span> <span class="hljs-title function_">tokenize_function</span>(<span class="hljs-params">examples</span>):
<span class="hljs-meta">... </span>    <span class="hljs-keyword">return</span> tokenizer(examples[<span class="hljs-string">&quot;text&quot;</span>], padding=<span class="hljs-string">&quot;max_length&quot;</span>, truncation=<span class="hljs-literal">True</span>)


<span class="hljs-meta">&gt;&gt;&gt; </span>tokenized_datasets = dataset.<span class="hljs-built_in">map</span>(tokenize_function, batched=<span class="hljs-literal">True</span>)`}}),ee=new A({props:{code:"c21hbGxfdHJhaW5fZGF0YXNldCUyMCUzRCUyMHRva2VuaXplZF9kYXRhc2V0cyU1QiUyMnRyYWluJTIyJTVELnNodWZmbGUoc2VlZCUzRDQyKS5zZWxlY3QocmFuZ2UoMTAwMCkpJTBBc21hbGxfZXZhbF9kYXRhc2V0JTIwJTNEJTIwdG9rZW5pemVkX2RhdGFzZXRzJTVCJTIydGVzdCUyMiU1RC5zaHVmZmxlKHNlZWQlM0Q0Mikuc2VsZWN0KHJhbmdlKDEwMDApKQ==",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span>small_train_dataset = tokenized_datasets[<span class="hljs-string">&quot;train&quot;</span>].shuffle(seed=<span class="hljs-number">42</span>).select(<span class="hljs-built_in">range</span>(<span class="hljs-number">1000</span>))
<span class="hljs-meta">&gt;&gt;&gt; </span>small_eval_dataset = tokenized_datasets[<span class="hljs-string">&quot;test&quot;</span>].shuffle(seed=<span class="hljs-number">42</span>).select(<span class="hljs-built_in">range</span>(<span class="hljs-number">1000</span>))`}}),me=new qe({}),Je=new Nt({props:{pytorch:!0,tensorflow:!0,jax:!1,$$slots:{tensorflow:[Ot],pytorch:[Lt]},$$scope:{ctx:ge}}}),fe=new qe({}),Ee=new Nt({props:{pytorch:!0,tensorflow:!1,jax:!1,$$slots:{pytorch:[aa]},$$scope:{ctx:ge}}}),Ke=new qe({}),{c(){c=n("meta"),_=i(),d=n("p"),k=i(),C=n("h1"),X=n("a"),xe=n("span"),$(E.$$.fragment),x=i(),ae=n("span"),ae.textContent=F,Re=i(),$(U.$$.fragment),H=i(),N=n("p"),N.textContent=V,Ye=i(),P=n("ul"),P.innerHTML=pe,be=i(),Z=n("a"),Me=i(),Y=n("h2"),L=n("a"),ce=n("span"),$(S.$$.fragment),q=i(),R=n("span"),R.textContent=Q,D=i(),$(z.$$.fragment),de=i(),B=n("p"),B.textContent=Ne,Ce=i(),G=n("p"),G.innerHTML=ve,se=i(),$(I.$$.fragment),K=i(),W=n("p"),W.innerHTML=Ze,we=i(),$(O.$$.fragment),le=i(),p=n("p"),p.textContent=J,je=i(),$(ee.$$.fragment),ne=i(),re=n("a"),he=i(),te=n("h2"),ie=n("a"),Te=n("span"),$(me.$$.fragment),$e=i(),Be=n("span"),Be.textContent=Ae,Ge=i(),$(Je.$$.fragment),Pe=i(),ye=n("a"),Ue=i(),ue=n("h2"),We=n("a"),_e=n("span"),$(fe.$$.fragment),Xe=i(),l=n("span"),l.textContent=g,ke=i(),$(Ee.$$.fragment),ze=i(),Le=n("a"),De=i(),oe=n("h2"),Fe=n("a"),Ie=n("span"),$(Ke.$$.fragment),at=i(),pt=n("span"),pt.textContent=Mt,Se=i(),He=n("p"),He.textContent=ut,Oe=i(),st=n("ul"),st.innerHTML=ct,wt=i(),lt=n("p"),this.h()},l(a){const h=St("svelte-1phssyn",document.head);c=r(h,"META",{name:!0,content:!0}),h.forEach(e),_=o(a),d=r(a,"P",{}),w(d).forEach(e),k=o(a),C=r(a,"H1",{class:!0});var Ve=w(C);X=r(Ve,"A",{id:!0,class:!0,href:!0});var nt=w(X);xe=r(nt,"SPAN",{});var tt=w(xe);y(E.$$.fragment,tt),tt.forEach(e),nt.forEach(e),x=o(Ve),ae=r(Ve,"SPAN",{"data-svelte-h":!0}),M(ae)!=="svelte-1sx52fm"&&(ae.textContent=F),Ve.forEach(e),Re=o(a),y(U.$$.fragment,a),H=o(a),N=r(a,"P",{"data-svelte-h":!0}),M(N)!=="svelte-gx4agk"&&(N.textContent=V),Ye=o(a),P=r(a,"UL",{"data-svelte-h":!0}),M(P)!=="svelte-cwrdoc"&&(P.innerHTML=pe),be=o(a),Z=r(a,"A",{id:!0}),w(Z).forEach(e),Me=o(a),Y=r(a,"H2",{class:!0});var Qe=w(Y);L=r(Qe,"A",{id:!0,class:!0,href:!0});var ft=w(L);ce=r(ft,"SPAN",{});var rt=w(ce);y(S.$$.fragment,rt),rt.forEach(e),ft.forEach(e),q=o(Qe),R=r(Qe,"SPAN",{"data-svelte-h":!0}),M(R)!=="svelte-gemgaq"&&(R.textContent=Q),Qe.forEach(e),D=o(a),y(z.$$.fragment,a),de=o(a),B=r(a,"P",{"data-svelte-h":!0}),M(B)!=="svelte-n29iv5"&&(B.textContent=Ne),Ce=o(a),G=r(a,"P",{"data-svelte-h":!0}),M(G)!=="svelte-128hpxg"&&(G.innerHTML=ve),se=o(a),y(I.$$.fragment,a),K=o(a),W=r(a,"P",{"data-svelte-h":!0}),M(W)!=="svelte-199xk0z"&&(W.innerHTML=Ze),we=o(a),y(O.$$.fragment,a),le=o(a),p=r(a,"P",{"data-svelte-h":!0}),M(p)!=="svelte-14sxrz7"&&(p.textContent=J),je=o(a),y(ee.$$.fragment,a),ne=o(a),re=r(a,"A",{id:!0}),w(re).forEach(e),he=o(a),te=r(a,"H2",{class:!0});var gt=w(te);ie=r(gt,"A",{id:!0,class:!0,href:!0});var dt=w(ie);Te=r(dt,"SPAN",{});var bt=w(Te);y(me.$$.fragment,bt),bt.forEach(e),dt.forEach(e),$e=o(gt),Be=r(gt,"SPAN",{"data-svelte-h":!0}),M(Be)!=="svelte-1v8nlte"&&(Be.textContent=Ae),gt.forEach(e),Ge=o(a),y(Je.$$.fragment,a),Pe=o(a),ye=r(a,"A",{id:!0}),w(ye).forEach(e),Ue=o(a),ue=r(a,"H2",{class:!0});var mt=w(ue);We=r(mt,"A",{id:!0,class:!0,href:!0});var it=w(We);_e=r(it,"SPAN",{});var vt=w(_e);y(fe.$$.fragment,vt),vt.forEach(e),it.forEach(e),Xe=o(mt),l=r(mt,"SPAN",{"data-svelte-h":!0}),M(l)!=="svelte-1gq95r"&&(l.textContent=g),mt.forEach(e),ke=o(a),y(Ee.$$.fragment,a),ze=o(a),Le=r(a,"A",{id:!0}),w(Le).forEach(e),De=o(a),oe=r(a,"H2",{class:!0});var ht=w(oe);Fe=r(ht,"A",{id:!0,class:!0,href:!0});var ot=w(Fe);Ie=r(ot,"SPAN",{});var $t=w(Ie);y(Ke.$$.fragment,$t),$t.forEach(e),ot.forEach(e),at=o(ht),pt=r(ht,"SPAN",{"data-svelte-h":!0}),M(pt)!=="svelte-nmcm6e"&&(pt.textContent=Mt),ht.forEach(e),Se=o(a),He=r(a,"P",{"data-svelte-h":!0}),M(He)!=="svelte-1ja6793"&&(He.textContent=ut),Oe=o(a),st=r(a,"UL",{"data-svelte-h":!0}),M(st)!=="svelte-1y57zg6"&&(st.innerHTML=ct),wt=o(a),lt=r(a,"P",{}),w(lt).forEach(e),this.h()},h(){f(c,"name","hf:doc:metadata"),f(c,"content",JSON.stringify(la)),f(X,"id","finetuning-di-un-modello-preaddestrato"),f(X,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),f(X,"href","#finetuning-di-un-modello-preaddestrato"),f(C,"class","relative group"),f(Z,"id","data-processing"),f(L,"id","preparare-un-dataset"),f(L,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),f(L,"href","#preparare-un-dataset"),f(Y,"class","relative group"),f(re,"id","trainer"),f(ie,"id","addestramento"),f(ie,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),f(ie,"href","#addestramento"),f(te,"class","relative group"),f(ye,"id","pytorch_native"),f(We,"id","addestramento-in-pytorch-nativo"),f(We,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),f(We,"href","#addestramento-in-pytorch-nativo"),f(ue,"class","relative group"),f(Le,"id","additional-resources"),f(Fe,"id","altre-risorse"),f(Fe,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),f(Fe,"href","#altre-risorse"),f(oe,"class","relative group")},m(a,h){m(document.head,c),s(a,_,h),s(a,d,h),s(a,k,h),s(a,C,h),m(C,X),m(X,xe),b(E,xe,null),m(C,x),m(C,ae),s(a,Re,h),b(U,a,h),s(a,H,h),s(a,N,h),s(a,Ye,h),s(a,P,h),s(a,be,h),s(a,Z,h),s(a,Me,h),s(a,Y,h),m(Y,L),m(L,ce),b(S,ce,null),m(Y,q),m(Y,R),s(a,D,h),b(z,a,h),s(a,de,h),s(a,B,h),s(a,Ce,h),s(a,G,h),s(a,se,h),b(I,a,h),s(a,K,h),s(a,W,h),s(a,we,h),b(O,a,h),s(a,le,h),s(a,p,h),s(a,je,h),b(ee,a,h),s(a,ne,h),s(a,re,h),s(a,he,h),s(a,te,h),m(te,ie),m(ie,Te),b(me,Te,null),m(te,$e),m(te,Be),s(a,Ge,h),b(Je,a,h),s(a,Pe,h),s(a,ye,h),s(a,Ue,h),s(a,ue,h),m(ue,We),m(We,_e),b(fe,_e,null),m(ue,Xe),m(ue,l),s(a,ke,h),b(Ee,a,h),s(a,ze,h),s(a,Le,h),s(a,De,h),s(a,oe,h),m(oe,Fe),m(Fe,Ie),b(Ke,Ie,null),m(oe,at),m(oe,pt),s(a,Se,h),s(a,He,h),s(a,Oe,h),s(a,st,h),s(a,wt,h),s(a,lt,h),et=!0},p(a,[h]){const Ve={};h&2&&(Ve.$$scope={dirty:h,ctx:a}),Je.$set(Ve);const nt={};h&2&&(nt.$$scope={dirty:h,ctx:a}),Ee.$set(nt)},i(a){et||(v(E.$$.fragment,a),v(U.$$.fragment,a),v(S.$$.fragment,a),v(z.$$.fragment,a),v(I.$$.fragment,a),v(O.$$.fragment,a),v(ee.$$.fragment,a),v(me.$$.fragment,a),v(Je.$$.fragment,a),v(fe.$$.fragment,a),v(Ee.$$.fragment,a),v(Ke.$$.fragment,a),et=!0)},o(a){j(E.$$.fragment,a),j(U.$$.fragment,a),j(S.$$.fragment,a),j(z.$$.fragment,a),j(I.$$.fragment,a),j(O.$$.fragment,a),j(ee.$$.fragment,a),j(me.$$.fragment,a),j(Je.$$.fragment,a),j(fe.$$.fragment,a),j(Ee.$$.fragment,a),j(Ke.$$.fragment,a),et=!1},d(a){a&&(e(_),e(d),e(k),e(C),e(Re),e(H),e(N),e(Ye),e(P),e(be),e(Z),e(Me),e(Y),e(D),e(de),e(B),e(Ce),e(G),e(se),e(K),e(W),e(we),e(le),e(p),e(je),e(ne),e(re),e(he),e(te),e(Ge),e(Pe),e(ye),e(Ue),e(ue),e(ke),e(ze),e(Le),e(De),e(oe),e(Se),e(He),e(Oe),e(st),e(wt),e(lt)),e(c),T(E),T(U,a),T(S),T(z,a),T(I,a),T(O,a),T(ee,a),T(me),T(Je,a),T(fe),T(Ee,a),T(Ke)}}}const la={local:"finetuning-di-un-modello-preaddestrato",sections:[{local:"preparare-un-dataset",title:"Preparare un dataset"},{local:"addestramento",sections:[{local:"iperparametri-per-il-training",title:"Iperparametri per il training"},{local:"metriche",title:"Metriche"},{local:"trainer",title:"Trainer"},{local:"convertire-dataset-nel-formato-per-tensorflow",title:"Convertire dataset nel formato per TensorFlow"},{local:"compilazione-e-addestramento",title:"Compilazione e addestramento"}],title:"Addestramento"},{local:"addestramento-in-pytorch-nativo",sections:[{local:"dataloader",title:"DataLoader"},{local:"ottimizzatore-e-learning-rate-scheduler",title:"Ottimizzatore e learning rate scheduler"},{local:"training-loop",title:"Training loop"},{local:"metriche",title:"Metriche"}],title:"Addestramento in PyTorch nativo"},{local:"altre-risorse",title:"Altre risorse"}],title:"Fine-tuning di un modello pre-addestrato"};function na(ge){return At(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class ua extends Vt{constructor(c){super(),Yt(this,c,na,sa,Bt,{})}}export{ua as component};
