import{S as ns,i as ps,s as cs,e as r,k as m,w as $,t as p,M as ds,c as o,d as e,m as f,a as i,x as y,h as c,b as u,G as a,g as n,y as M,q as j,o as J,B as T,v as ms}from"../chunks/vendor-hf-doc-builder.js";import{T as Zt}from"../chunks/Tip-hf-doc-builder.js";import{Y as zt}from"../chunks/Youtube-hf-doc-builder.js";import{I as Xa}from"../chunks/IconCopyLink-hf-doc-builder.js";import{C as Q}from"../chunks/CodeBlock-hf-doc-builder.js";import{D as fs}from"../chunks/DocNotebookDropdown-hf-doc-builder.js";import{F as is,M as Ut}from"../chunks/Markdown-hf-doc-builder.js";import"../chunks/IconTensorflow-hf-doc-builder.js";function us(Fe){let g,E;return{c(){g=r("p"),E=p("Potresti vedere un warning dato che alcuni dei pesi pre-addestrati non sono stati utilizzati e altri pesi sono stati inizializzati casualmente. Non preoccuparti, \xE8 completamente normale! L\u2019head 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.")},l(h){g=o(h,"P",{});var _=i(g);E=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, \xE8 completamente normale! L\u2019head 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."),_.forEach(e)},m(h,_){n(h,g,_),a(g,E)},d(h){h&&e(g)}}}function hs(Fe){let g,E,h,_,z,W,x,Z,R,A,G,D,L,Ne,Be,F,Ge,ue,K,ae,he,_e,te,Le,oe,Ke,S,ia,C,X,O,H,na,Ye,ie,pa,za,Ee,ge,$a,Ce,N,Oe,U,B,ne,pe,Ve,ke,ve,ea,I,ze,Ze,Y,ce,we,We,V,be,aa,ya,se,de,Pe,d,k,q,le,Ue,$e,P,ca,Ae,ye,ee,Me,Se,He,re,Ie,Ma,Xe,me,qe,fe,da,ta,Sa,Za,ma,je,Je,Qe,Te,Fa,fa,Ha,sa,Ua,ua,ha,la,Ia,Ca,ja,Ja,Ta,ga,xe,va,_a,qa,wa,ra,s,v;return g=new zt({props:{id:"nvBXf7s7vTI"}}),ue=new Q({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 Zt({props:{$$slots:{default:[us]},$$scope:{ctx:Fe}}}),oe=new Xa({}),N=new Q({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>)`}}),pe=new Xa({}),Ue=new Q({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>)`}}),me=new Q({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)`}}),je=new Q({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>)`}}),fa=new Xa({}),Ta=new Q({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>)`}}),s=new Q({props:{code:"dHJhaW5lci50cmFpbigp",highlighted:'<span class="hljs-meta">&gt;&gt;&gt; </span>trainer.train()'}}),{c(){$(g.$$.fragment),E=m(),h=r("p"),_=p("\u{1F917} Transformers mette a disposizione la classe "),z=r("code"),W=p("Trainer"),x=p(" ottimizzata per addestrare modelli \u{1F917} Transformers, rendendo semplice iniziare l\u2019addestramento senza scrivere manualmente il tuo ciclo di addestramento. L\u2019API "),Z=r("code"),R=p("Trainer"),A=p(" supporta un\u2019ampia gamma di opzioni e funzionalit\xE0 di addestramento come logging, gradient accumulation e mixed precision."),G=m(),D=r("p"),L=p("Inizia caricando il tuo modello e specificando il numero di etichette (labels) attese. Nel dataset Yelp Review "),Ne=r("a"),Be=p("dataset card"),F=p(", sai che ci sono cinque etichette:"),Ge=m(),$(ue.$$.fragment),K=m(),$(ae.$$.fragment),he=m(),_e=r("h3"),te=r("a"),Le=r("span"),$(oe.$$.fragment),Ke=m(),S=r("span"),ia=p("Iperparametri per il training"),C=m(),X=r("p"),O=p("Successivamente, crea una classe "),H=r("code"),na=p("TrainingArguments"),Ye=p(" contenente tutti gli iperparametri che si possono regore nonch\xE9 le variabili per attivare le differenti opzioni di addestramento. Per questa esercitazione puoi iniziare con gli "),ie=r("a"),pa=p("iperparametri"),za=p(" di ddestramento predefiniti, ma sentiti libero di sperimentare per trovare la configurazione ottimale per te."),Ee=m(),ge=r("p"),$a=p("Specifica dove salvare i checkpoints del tuo addestramento:"),Ce=m(),$(N.$$.fragment),Oe=m(),U=r("h3"),B=r("a"),ne=r("span"),$(pe.$$.fragment),Ve=m(),ke=r("span"),ve=p("Metriche"),ea=m(),I=r("p"),ze=r("code"),Ze=p("Trainer"),Y=p(" non valuta automaticamente le performance del modello durante l\u2019addestramento. Dovrai passare a "),ce=r("code"),we=p("Trainer"),We=p(" una funzione che calcola e restituisce le metriche. La libreria \u{1F917} Datasets mette a disposizione una semplice funzione "),V=r("a"),be=r("code"),aa=p("accuracy"),ya=p(" che puoi caricare con la funzione "),se=r("code"),de=p("load_metric"),Pe=p(" (guarda questa "),d=r("a"),k=p("esercitazione"),q=p(" per maggiori informazioni):"),le=m(),$(Ue.$$.fragment),$e=m(),P=r("p"),ca=p("Richiama "),Ae=r("code"),ye=p("compute"),ee=p(" su "),Me=r("code"),Se=p("metric"),He=p(" per calcolare l\u2019accuratezza delle tue previsioni. Prima di passare le tue previsioni a "),re=r("code"),Ie=p("compute"),Ma=p(", hai bisogno di convertirle in logits (ricorda che tutti i modelli \u{1F917} Transformers restituiscono logits):"),Xe=m(),$(me.$$.fragment),qe=m(),fe=r("p"),da=p("Se preferisci monitorare le tue metriche di valutazione durante il fine-tuning, specifica il parametro "),ta=r("code"),Sa=p("evaluation_strategy"),Za=p(" nei tuoi training arguments per restituire le metriche di valutazione ad ogni epoca di addestramento:"),ma=m(),$(je.$$.fragment),Je=m(),Qe=r("h3"),Te=r("a"),Fa=r("span"),$(fa.$$.fragment),Ha=m(),sa=r("span"),Ua=p("Trainer"),ua=m(),ha=r("p"),la=p("Crea un oggetto "),Ia=r("code"),Ca=p("Trainer"),ja=p(" col tuo modello, training arguments, dataset di training e test, e funzione di valutazione:"),Ja=m(),$(Ta.$$.fragment),ga=m(),xe=r("p"),va=p("Poi metti a punto il modello richiamando "),_a=r("code"),qa=p("train()"),wa=p(":"),ra=m(),$(s.$$.fragment),this.h()},l(l){y(g.$$.fragment,l),E=f(l),h=o(l,"P",{});var b=i(h);_=c(b,"\u{1F917} Transformers mette a disposizione la classe "),z=o(b,"CODE",{});var Qa=i(z);W=c(Qa,"Trainer"),Qa.forEach(e),x=c(b," ottimizzata per addestrare modelli \u{1F917} Transformers, rendendo semplice iniziare l\u2019addestramento senza scrivere manualmente il tuo ciclo di addestramento. L\u2019API "),Z=o(b,"CODE",{});var at=i(Z);R=c(at,"Trainer"),at.forEach(e),A=c(b," supporta un\u2019ampia gamma di opzioni e funzionalit\xE0 di addestramento come logging, gradient accumulation e mixed precision."),b.forEach(e),G=f(l),D=o(l,"P",{});var Ea=i(D);L=c(Ea,"Inizia caricando il tuo modello e specificando il numero di etichette (labels) attese. Nel dataset Yelp Review "),Ne=o(Ea,"A",{href:!0,rel:!0});var Na=i(Ne);Be=c(Na,"dataset card"),Na.forEach(e),F=c(Ea,", sai che ci sono cinque etichette:"),Ea.forEach(e),Ge=f(l),y(ue.$$.fragment,l),K=f(l),y(ae.$$.fragment,l),he=f(l),_e=o(l,"H3",{class:!0});var ba=i(_e);te=o(ba,"A",{id:!0,class:!0,href:!0});var it=i(te);Le=o(it,"SPAN",{});var nt=i(Le);y(oe.$$.fragment,nt),nt.forEach(e),it.forEach(e),Ke=f(ba),S=o(ba,"SPAN",{});var tt=i(S);ia=c(tt,"Iperparametri per il training"),tt.forEach(e),ba.forEach(e),C=f(l),X=o(l,"P",{});var De=i(X);O=c(De,"Successivamente, crea una classe "),H=o(De,"CODE",{});var st=i(H);na=c(st,"TrainingArguments"),st.forEach(e),Ye=c(De," contenente tutti gli iperparametri che si possono regore nonch\xE9 le variabili per attivare le differenti opzioni di addestramento. Per questa esercitazione puoi iniziare con gli "),ie=o(De,"A",{href:!0,rel:!0});var Ra=i(ie);pa=c(Ra,"iperparametri"),Ra.forEach(e),za=c(De," di ddestramento predefiniti, ma sentiti libero di sperimentare per trovare la configurazione ottimale per te."),De.forEach(e),Ee=f(l),ge=o(l,"P",{});var Wa=i(ge);$a=c(Wa,"Specifica dove salvare i checkpoints del tuo addestramento:"),Wa.forEach(e),Ce=f(l),y(N.$$.fragment,l),Oe=f(l),U=o(l,"H3",{class:!0});var Ba=i(U);B=o(Ba,"A",{id:!0,class:!0,href:!0});var Ga=i(B);ne=o(Ga,"SPAN",{});var pt=i(ne);y(pe.$$.fragment,pt),pt.forEach(e),Ga.forEach(e),Ve=f(Ba),ke=o(Ba,"SPAN",{});var Ya=i(ke);ve=c(Ya,"Metriche"),Ya.forEach(e),Ba.forEach(e),ea=f(l),I=o(l,"P",{});var oa=i(I);ze=o(oa,"CODE",{});var lt=i(ze);Ze=c(lt,"Trainer"),lt.forEach(e),Y=c(oa," non valuta automaticamente le performance del modello durante l\u2019addestramento. Dovrai passare a "),ce=o(oa,"CODE",{});var ka=i(ce);we=c(ka,"Trainer"),ka.forEach(e),We=c(oa," una funzione che calcola e restituisce le metriche. La libreria \u{1F917} Datasets mette a disposizione una semplice funzione "),V=o(oa,"A",{href:!0,rel:!0});var La=i(V);be=o(La,"CODE",{});var Ka=i(be);aa=c(Ka,"accuracy"),Ka.forEach(e),La.forEach(e),ya=c(oa," che puoi caricare con la funzione "),se=o(oa,"CODE",{});var ct=i(se);de=c(ct,"load_metric"),ct.forEach(e),Pe=c(oa," (guarda questa "),d=o(oa,"A",{href:!0,rel:!0});var dt=i(d);k=c(dt,"esercitazione"),dt.forEach(e),q=c(oa," per maggiori informazioni):"),oa.forEach(e),le=f(l),y(Ue.$$.fragment,l),$e=f(l),P=o(l,"P",{});var Re=i(P);ca=c(Re,"Richiama "),Ae=o(Re,"CODE",{});var Oa=i(Ae);ye=c(Oa,"compute"),Oa.forEach(e),ee=c(Re," su "),Me=o(Re,"CODE",{});var mt=i(Me);Se=c(mt,"metric"),mt.forEach(e),He=c(Re," per calcolare l\u2019accuratezza delle tue previsioni. Prima di passare le tue previsioni a "),re=o(Re,"CODE",{});var ft=i(re);Ie=c(ft,"compute"),ft.forEach(e),Ma=c(Re,", hai bisogno di convertirle in logits (ricorda che tutti i modelli \u{1F917} Transformers restituiscono logits):"),Re.forEach(e),Xe=f(l),y(me.$$.fragment,l),qe=f(l),fe=o(l,"P",{});var Aa=i(fe);da=c(Aa,"Se preferisci monitorare le tue metriche di valutazione durante il fine-tuning, specifica il parametro "),ta=o(Aa,"CODE",{});var Va=i(ta);Sa=c(Va,"evaluation_strategy"),Va.forEach(e),Za=c(Aa," nei tuoi training arguments per restituire le metriche di valutazione ad ogni epoca di addestramento:"),Aa.forEach(e),ma=f(l),y(je.$$.fragment,l),Je=f(l),Qe=o(l,"H3",{class:!0});var xa=i(Qe);Te=o(xa,"A",{id:!0,class:!0,href:!0});var t=i(Te);Fa=o(t,"SPAN",{});var w=i(Fa);y(fa.$$.fragment,w),w.forEach(e),t.forEach(e),Ha=f(xa),sa=o(xa,"SPAN",{});var Pa=i(sa);Ua=c(Pa,"Trainer"),Pa.forEach(e),xa.forEach(e),ua=f(l),ha=o(l,"P",{});var rt=i(ha);la=c(rt,"Crea un oggetto "),Ia=o(rt,"CODE",{});var et=i(Ia);Ca=c(et,"Trainer"),et.forEach(e),ja=c(rt," col tuo modello, training arguments, dataset di training e test, e funzione di valutazione:"),rt.forEach(e),Ja=f(l),y(Ta.$$.fragment,l),ga=f(l),xe=o(l,"P",{});var ot=i(xe);va=c(ot,"Poi metti a punto il modello richiamando "),_a=o(ot,"CODE",{});var Da=i(_a);qa=c(Da,"train()"),Da.forEach(e),wa=c(ot,":"),ot.forEach(e),ra=f(l),y(s.$$.fragment,l),this.h()},h(){u(Ne,"href","https://huggingface.co/datasets/yelp_review_full#data-fields"),u(Ne,"rel","nofollow"),u(te,"id","iperparametri-per-il-training"),u(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"),u(te,"href","#iperparametri-per-il-training"),u(_e,"class","relative group"),u(ie,"href","https://huggingface.co/docs/transformers/main_classes/trainer#transformers.TrainingArguments"),u(ie,"rel","nofollow"),u(B,"id","metriche"),u(B,"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"),u(B,"href","#metriche"),u(U,"class","relative group"),u(V,"href","https://huggingface.co/metrics/accuracy"),u(V,"rel","nofollow"),u(d,"href","https://huggingface.co/docs/datasets/metrics.html"),u(d,"rel","nofollow"),u(Te,"id","trainer"),u(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"),u(Te,"href","#trainer"),u(Qe,"class","relative group")},m(l,b){M(g,l,b),n(l,E,b),n(l,h,b),a(h,_),a(h,z),a(z,W),a(h,x),a(h,Z),a(Z,R),a(h,A),n(l,G,b),n(l,D,b),a(D,L),a(D,Ne),a(Ne,Be),a(D,F),n(l,Ge,b),M(ue,l,b),n(l,K,b),M(ae,l,b),n(l,he,b),n(l,_e,b),a(_e,te),a(te,Le),M(oe,Le,null),a(_e,Ke),a(_e,S),a(S,ia),n(l,C,b),n(l,X,b),a(X,O),a(X,H),a(H,na),a(X,Ye),a(X,ie),a(ie,pa),a(X,za),n(l,Ee,b),n(l,ge,b),a(ge,$a),n(l,Ce,b),M(N,l,b),n(l,Oe,b),n(l,U,b),a(U,B),a(B,ne),M(pe,ne,null),a(U,Ve),a(U,ke),a(ke,ve),n(l,ea,b),n(l,I,b),a(I,ze),a(ze,Ze),a(I,Y),a(I,ce),a(ce,we),a(I,We),a(I,V),a(V,be),a(be,aa),a(I,ya),a(I,se),a(se,de),a(I,Pe),a(I,d),a(d,k),a(I,q),n(l,le,b),M(Ue,l,b),n(l,$e,b),n(l,P,b),a(P,ca),a(P,Ae),a(Ae,ye),a(P,ee),a(P,Me),a(Me,Se),a(P,He),a(P,re),a(re,Ie),a(P,Ma),n(l,Xe,b),M(me,l,b),n(l,qe,b),n(l,fe,b),a(fe,da),a(fe,ta),a(ta,Sa),a(fe,Za),n(l,ma,b),M(je,l,b),n(l,Je,b),n(l,Qe,b),a(Qe,Te),a(Te,Fa),M(fa,Fa,null),a(Qe,Ha),a(Qe,sa),a(sa,Ua),n(l,ua,b),n(l,ha,b),a(ha,la),a(ha,Ia),a(Ia,Ca),a(ha,ja),n(l,Ja,b),M(Ta,l,b),n(l,ga,b),n(l,xe,b),a(xe,va),a(xe,_a),a(_a,qa),a(xe,wa),n(l,ra,b),M(s,l,b),v=!0},p(l,b){const Qa={};b&2&&(Qa.$$scope={dirty:b,ctx:l}),ae.$set(Qa)},i(l){v||(j(g.$$.fragment,l),j(ue.$$.fragment,l),j(ae.$$.fragment,l),j(oe.$$.fragment,l),j(N.$$.fragment,l),j(pe.$$.fragment,l),j(Ue.$$.fragment,l),j(me.$$.fragment,l),j(je.$$.fragment,l),j(fa.$$.fragment,l),j(Ta.$$.fragment,l),j(s.$$.fragment,l),v=!0)},o(l){J(g.$$.fragment,l),J(ue.$$.fragment,l),J(ae.$$.fragment,l),J(oe.$$.fragment,l),J(N.$$.fragment,l),J(pe.$$.fragment,l),J(Ue.$$.fragment,l),J(me.$$.fragment,l),J(je.$$.fragment,l),J(fa.$$.fragment,l),J(Ta.$$.fragment,l),J(s.$$.fragment,l),v=!1},d(l){T(g,l),l&&e(E),l&&e(h),l&&e(G),l&&e(D),l&&e(Ge),T(ue,l),l&&e(K),T(ae,l),l&&e(he),l&&e(_e),T(oe),l&&e(C),l&&e(X),l&&e(Ee),l&&e(ge),l&&e(Ce),T(N,l),l&&e(Oe),l&&e(U),T(pe),l&&e(ea),l&&e(I),l&&e(le),T(Ue,l),l&&e($e),l&&e(P),l&&e(Xe),T(me,l),l&&e(qe),l&&e(fe),l&&e(ma),T(je,l),l&&e(Je),l&&e(Qe),T(fa),l&&e(ua),l&&e(ha),l&&e(Ja),T(Ta,l),l&&e(ga),l&&e(xe),l&&e(ra),T(s,l)}}}function gs(Fe){let g,E;return g=new Ut({props:{$$slots:{default:[hs]},$$scope:{ctx:Fe}}}),{c(){$(g.$$.fragment)},l(h){y(g.$$.fragment,h)},m(h,_){M(g,h,_),E=!0},p(h,_){const z={};_&2&&(z.$$scope={dirty:_,ctx:h}),g.$set(z)},i(h){E||(j(g.$$.fragment,h),E=!0)},o(h){J(g.$$.fragment,h),E=!1},d(h){T(g,h)}}}function vs(Fe){let g,E,h,_,z,W,x;return{c(){g=r("p"),E=r("code"),h=p("Trainer"),_=p(" usa "),z=r("code"),W=p("DataCollatorWithPadding"),x=p(" in maniera predefinita in modo da non dover specificare esplicitamente un collettore di dati.")},l(Z){g=o(Z,"P",{});var R=i(g);E=o(R,"CODE",{});var A=i(E);h=c(A,"Trainer"),A.forEach(e),_=c(R," usa "),z=o(R,"CODE",{});var G=i(z);W=c(G,"DataCollatorWithPadding"),G.forEach(e),x=c(R," in maniera predefinita in modo da non dover specificare esplicitamente un collettore di dati."),R.forEach(e)},m(Z,R){n(Z,g,R),a(g,E),a(E,h),a(g,_),a(g,z),a(z,W),a(g,x)},d(Z){Z&&e(g)}}}function ws(Fe){let g,E,h,_,z,W,x,Z,R,A,G,D,L,Ne,Be,F,Ge,ue,K,ae,he,_e,te,Le,oe,Ke,S,ia,C,X,O,H,na,Ye,ie,pa,za,Ee,ge,$a,Ce,N,Oe,U,B,ne,pe,Ve,ke,ve,ea,I,ze,Ze,Y,ce,we,We,V,be,aa,ya,se,de,Pe;return h=new zt({props:{id:"rnTGBy2ax1c"}}),G=new Xa({}),oe=new Q({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>)`}}),S=new Zt({props:{$$slots:{default:[vs]},$$scope:{ctx:Fe}}}),N=new Q({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>)`}}),pe=new Xa({}),Y=new Q({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>)`}}),de=new Q({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(){g=r("a"),E=m(),$(h.$$.fragment),_=m(),z=r("p"),W=p("I modelli \u{1F917} Transformers supportano anche l\u2019addestramento in TensorFlow usando l\u2019API di Keras."),x=m(),Z=r("h3"),R=r("a"),A=r("span"),$(G.$$.fragment),D=m(),L=r("span"),Ne=p("Convertire dataset nel formato per TensorFlow"),Be=m(),F=r("p"),Ge=p("Il "),ue=r("code"),K=p("DefaultDataCollator"),ae=p(" assembla tensori in lotti su cui il modello si addestrer\xE0. Assicurati di specificare di restituire tensori per TensorFlow in "),he=r("code"),_e=p("return_tensors"),te=p(":"),Le=m(),$(oe.$$.fragment),Ke=m(),$(S.$$.fragment),ia=m(),C=r("p"),X=p("Successivamente, converti i datasets tokenizzati in TensorFlow datasets con il metodo "),O=r("a"),H=r("code"),na=p("to_tf_dataset"),Ye=p(". Specifica il tuo input in "),ie=r("code"),pa=p("columns"),za=p(" e le tue etichette in "),Ee=r("code"),ge=p("label_cols"),$a=p(":"),Ce=m(),$(N.$$.fragment),Oe=m(),U=r("h3"),B=r("a"),ne=r("span"),$(pe.$$.fragment),Ve=m(),ke=r("span"),ve=p("Compilazione e addestramento"),ea=m(),I=r("p"),ze=p("Carica un modello TensorFlow col numero atteso di etichette:"),Ze=m(),$(Y.$$.fragment),ce=m(),we=r("p"),We=p("Poi compila e fai il fine-tuning del tuo modello usando "),V=r("a"),be=r("code"),aa=p("fit"),ya=p(" come faresti con qualsiasi altro modello di Keras:"),se=m(),$(de.$$.fragment),this.h()},l(d){g=o(d,"A",{id:!0}),i(g).forEach(e),E=f(d),y(h.$$.fragment,d),_=f(d),z=o(d,"P",{});var k=i(z);W=c(k,"I modelli \u{1F917} Transformers supportano anche l\u2019addestramento in TensorFlow usando l\u2019API di Keras."),k.forEach(e),x=f(d),Z=o(d,"H3",{class:!0});var q=i(Z);R=o(q,"A",{id:!0,class:!0,href:!0});var le=i(R);A=o(le,"SPAN",{});var Ue=i(A);y(G.$$.fragment,Ue),Ue.forEach(e),le.forEach(e),D=f(q),L=o(q,"SPAN",{});var $e=i(L);Ne=c($e,"Convertire dataset nel formato per TensorFlow"),$e.forEach(e),q.forEach(e),Be=f(d),F=o(d,"P",{});var P=i(F);Ge=c(P,"Il "),ue=o(P,"CODE",{});var ca=i(ue);K=c(ca,"DefaultDataCollator"),ca.forEach(e),ae=c(P," assembla tensori in lotti su cui il modello si addestrer\xE0. Assicurati di specificare di restituire tensori per TensorFlow in "),he=o(P,"CODE",{});var Ae=i(he);_e=c(Ae,"return_tensors"),Ae.forEach(e),te=c(P,":"),P.forEach(e),Le=f(d),y(oe.$$.fragment,d),Ke=f(d),y(S.$$.fragment,d),ia=f(d),C=o(d,"P",{});var ye=i(C);X=c(ye,"Successivamente, converti i datasets tokenizzati in TensorFlow datasets con il metodo "),O=o(ye,"A",{href:!0,rel:!0});var ee=i(O);H=o(ee,"CODE",{});var Me=i(H);na=c(Me,"to_tf_dataset"),Me.forEach(e),ee.forEach(e),Ye=c(ye,". Specifica il tuo input in "),ie=o(ye,"CODE",{});var Se=i(ie);pa=c(Se,"columns"),Se.forEach(e),za=c(ye," e le tue etichette in "),Ee=o(ye,"CODE",{});var He=i(Ee);ge=c(He,"label_cols"),He.forEach(e),$a=c(ye,":"),ye.forEach(e),Ce=f(d),y(N.$$.fragment,d),Oe=f(d),U=o(d,"H3",{class:!0});var re=i(U);B=o(re,"A",{id:!0,class:!0,href:!0});var Ie=i(B);ne=o(Ie,"SPAN",{});var Ma=i(ne);y(pe.$$.fragment,Ma),Ma.forEach(e),Ie.forEach(e),Ve=f(re),ke=o(re,"SPAN",{});var Xe=i(ke);ve=c(Xe,"Compilazione e addestramento"),Xe.forEach(e),re.forEach(e),ea=f(d),I=o(d,"P",{});var me=i(I);ze=c(me,"Carica un modello TensorFlow col numero atteso di etichette:"),me.forEach(e),Ze=f(d),y(Y.$$.fragment,d),ce=f(d),we=o(d,"P",{});var qe=i(we);We=c(qe,"Poi compila e fai il fine-tuning del tuo modello usando "),V=o(qe,"A",{href:!0,rel:!0});var fe=i(V);be=o(fe,"CODE",{});var da=i(be);aa=c(da,"fit"),da.forEach(e),fe.forEach(e),ya=c(qe," come faresti con qualsiasi altro modello di Keras:"),qe.forEach(e),se=f(d),y(de.$$.fragment,d),this.h()},h(){u(g,"id","keras"),u(R,"id","convertire-dataset-nel-formato-per-tensorflow"),u(R,"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"),u(R,"href","#convertire-dataset-nel-formato-per-tensorflow"),u(Z,"class","relative group"),u(O,"href","https://huggingface.co/docs/datasets/package_reference/main_classes.html#datasets.Dataset.to_tf_dataset"),u(O,"rel","nofollow"),u(B,"id","compilazione-e-addestramento"),u(B,"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"),u(B,"href","#compilazione-e-addestramento"),u(U,"class","relative group"),u(V,"href","https://keras.io/api/models/model_training_apis/"),u(V,"rel","nofollow")},m(d,k){n(d,g,k),n(d,E,k),M(h,d,k),n(d,_,k),n(d,z,k),a(z,W),n(d,x,k),n(d,Z,k),a(Z,R),a(R,A),M(G,A,null),a(Z,D),a(Z,L),a(L,Ne),n(d,Be,k),n(d,F,k),a(F,Ge),a(F,ue),a(ue,K),a(F,ae),a(F,he),a(he,_e),a(F,te),n(d,Le,k),M(oe,d,k),n(d,Ke,k),M(S,d,k),n(d,ia,k),n(d,C,k),a(C,X),a(C,O),a(O,H),a(H,na),a(C,Ye),a(C,ie),a(ie,pa),a(C,za),a(C,Ee),a(Ee,ge),a(C,$a),n(d,Ce,k),M(N,d,k),n(d,Oe,k),n(d,U,k),a(U,B),a(B,ne),M(pe,ne,null),a(U,Ve),a(U,ke),a(ke,ve),n(d,ea,k),n(d,I,k),a(I,ze),n(d,Ze,k),M(Y,d,k),n(d,ce,k),n(d,we,k),a(we,We),a(we,V),a(V,be),a(be,aa),a(we,ya),n(d,se,k),M(de,d,k),Pe=!0},p(d,k){const q={};k&2&&(q.$$scope={dirty:k,ctx:d}),S.$set(q)},i(d){Pe||(j(h.$$.fragment,d),j(G.$$.fragment,d),j(oe.$$.fragment,d),j(S.$$.fragment,d),j(N.$$.fragment,d),j(pe.$$.fragment,d),j(Y.$$.fragment,d),j(de.$$.fragment,d),Pe=!0)},o(d){J(h.$$.fragment,d),J(G.$$.fragment,d),J(oe.$$.fragment,d),J(S.$$.fragment,d),J(N.$$.fragment,d),J(pe.$$.fragment,d),J(Y.$$.fragment,d),J(de.$$.fragment,d),Pe=!1},d(d){d&&e(g),d&&e(E),T(h,d),d&&e(_),d&&e(z),d&&e(x),d&&e(Z),T(G),d&&e(Be),d&&e(F),d&&e(Le),T(oe,d),d&&e(Ke),T(S,d),d&&e(ia),d&&e(C),d&&e(Ce),T(N,d),d&&e(Oe),d&&e(U),T(pe),d&&e(ea),d&&e(I),d&&e(Ze),T(Y,d),d&&e(ce),d&&e(we),d&&e(se),T(de,d)}}}function bs(Fe){let g,E;return g=new Ut({props:{$$slots:{default:[ws]},$$scope:{ctx:Fe}}}),{c(){$(g.$$.fragment)},l(h){y(g.$$.fragment,h)},m(h,_){M(g,h,_),E=!0},p(h,_){const z={};_&2&&(z.$$scope={dirty:_,ctx:h}),g.$set(z)},i(h){E||(j(g.$$.fragment,h),E=!0)},o(h){J(g.$$.fragment,h),E=!1},d(h){T(g,h)}}}function $s(Fe){let g,E,h,_,z,W,x,Z;return{c(){g=r("p"),E=p("Ottieni l\u2019accesso gratuito a una GPU sul cloud se non ne possiedi una usando un notebook sul web come "),h=r("a"),_=p("Colaboratory"),z=p(" o "),W=r("a"),x=p("SageMaker StudioLab"),Z=p("."),this.h()},l(R){g=o(R,"P",{});var A=i(g);E=c(A,"Ottieni l\u2019accesso gratuito a una GPU sul cloud se non ne possiedi una usando un notebook sul web come "),h=o(A,"A",{href:!0,rel:!0});var G=i(h);_=c(G,"Colaboratory"),G.forEach(e),z=c(A," o "),W=o(A,"A",{href:!0,rel:!0});var D=i(W);x=c(D,"SageMaker StudioLab"),D.forEach(e),Z=c(A,"."),A.forEach(e),this.h()},h(){u(h,"href","https://colab.research.google.com/"),u(h,"rel","nofollow"),u(W,"href","https://studiolab.sagemaker.aws/"),u(W,"rel","nofollow")},m(R,A){n(R,g,A),a(g,E),a(g,h),a(h,_),a(g,z),a(g,W),a(W,x),a(g,Z)},d(R){R&&e(g)}}}function ys(Fe){let g,E,h,_,z,W,x,Z,R,A,G,D,L,Ne,Be,F,Ge,ue,K,ae,he,_e,te,Le,oe,Ke,S,ia,C,X,O,H,na,Ye,ie,pa,za,Ee,ge,$a,Ce,N,Oe,U,B,ne,pe,Ve,ke,ve,ea,I,ze,Ze,Y,ce,we,We,V,be,aa,ya,se,de,Pe,d,k,q,le,Ue,$e,P,ca,Ae,ye,ee,Me,Se,He,re,Ie,Ma,Xe,me,qe,fe,da,ta,Sa,Za,ma,je,Je,Qe,Te,Fa,fa,Ha,sa,Ua,ua,ha,la,Ia,Ca,ja,Ja,Ta,ga,xe,va,_a,qa,wa,ra,s,v,l,b,Qa,at,Ea,Na,ba,it,nt,tt,De,st,Ra,Wa,Ba,Ga,pt,Ya,oa,lt,ka,La,Ka,ct,dt,Re,Oa,mt,ft,Aa,Va,xa;return g=new zt({props:{id:"Dh9CL8fyG80"}}),G=new Q({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()`}}),S=new Q({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>])'}}),N=new Q({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>)'}}),Ve=new Q({props:{code:"dG9rZW5pemVkX2RhdGFzZXRzLnNldF9mb3JtYXQoJTIydG9yY2glMjIp",highlighted:'<span class="hljs-meta">&gt;&gt;&gt; </span>tokenized_datasets.set_format(<span class="hljs-string">&quot;torch&quot;</span>)'}}),ze=new Q({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>))`}}),We=new Xa({}),le=new Q({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>)`}}),Ae=new Q({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>)`}}),He=new Xa({}),ma=new Q({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>)`}}),sa=new Q({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>)`}}),Ja=new Q({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)`}}),ga=new Zt({props:{$$slots:{default:[$s]},$$scope:{ctx:Fe}}}),v=new Xa({}),De=new Q({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>)`}}),Ga=new Xa({}),Va=new Q({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(){$(g.$$.fragment),E=m(),h=r("p"),_=r("code"),z=p("Trainer"),W=p(" 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 \u{1F917} Transformers in PyTorch nativo."),x=m(),Z=r("p"),R=p("A questo punto, potresti avere bisogno di riavviare il tuo notebook o eseguire il seguente codice per liberare un po\u2019 di memoria:"),A=m(),$(G.$$.fragment),D=m(),L=r("p"),Ne=p("Successivamente, postprocessa manualmente il "),Be=r("code"),F=p("tokenized_dataset"),Ge=p(" per prepararlo ad essere allenato."),ue=m(),K=r("ol"),ae=r("li"),he=r("p"),_e=p("Rimuovi la colonna "),te=r("code"),Le=p("text"),oe=p(" perch\xE9 il modello non accetta testo grezzo come input:"),Ke=m(),$(S.$$.fragment),ia=m(),C=r("li"),X=r("p"),O=p("Rinomina la colonna "),H=r("code"),na=p("label"),Ye=p(" in "),ie=r("code"),pa=p("labels"),za=p(" perch\xE9 il modello si aspetta che questo argomento si chiami "),Ee=r("code"),ge=p("labels"),$a=p(":"),Ce=m(),$(N.$$.fragment),Oe=m(),U=r("li"),B=r("p"),ne=p("Imposta il formato del dataset per farti restituire tensori di PyTorch all\u2019interno delle liste:"),pe=m(),$(Ve.$$.fragment),ke=m(),ve=r("p"),ea=p("Poi crea un piccolo sottocampione del dataset come visto precedentemente per velocizzare il fine-tuning:"),I=m(),$(ze.$$.fragment),Ze=m(),Y=r("h3"),ce=r("a"),we=r("span"),$(We.$$.fragment),V=m(),be=r("span"),aa=p("DataLoader"),ya=m(),se=r("p"),de=p("Crea un "),Pe=r("code"),d=p("DataLoader"),k=p(" per i tuoi datasets di train e test cos\xEC puoi iterare sui lotti di dati:"),q=m(),$(le.$$.fragment),Ue=m(),$e=r("p"),P=p("Carica il tuo modello con il numero atteso di etichette:"),ca=m(),$(Ae.$$.fragment),ye=m(),ee=r("h3"),Me=r("a"),Se=r("span"),$(He.$$.fragment),re=m(),Ie=r("span"),Ma=p("Ottimizzatore e learning rate scheduler"),Xe=m(),me=r("p"),qe=p("Crea un ottimizzatore e il learning rate scheduler per fare il fine-tuning del modello. Usa l\u2019ottimizzatore "),fe=r("a"),da=r("code"),ta=p("AdamW"),Sa=p(" di PyTorch:"),Za=m(),$(ma.$$.fragment),je=m(),Je=r("p"),Qe=p("Crea il learning rate scheduler predefinito da "),Te=r("code"),Fa=p("Trainer"),fa=p(":"),Ha=m(),$(sa.$$.fragment),Ua=m(),ua=r("p"),ha=p("Infine specifica come "),la=r("code"),Ia=p("device"),Ca=p(" da usare una GPU se ne hai una. Altrimenti, l\u2019addestramento su una CPU pu\xF2 richiedere diverse ore invece di un paio di minuti."),ja=m(),$(Ja.$$.fragment),Ta=m(),$(ga.$$.fragment),xe=m(),va=r("p"),_a=p("Ottimo, adesso possiamo addestrare! \u{1F973}"),qa=m(),wa=r("h3"),ra=r("a"),s=r("span"),$(v.$$.fragment),l=m(),b=r("span"),Qa=p("Training loop"),at=m(),Ea=r("p"),Na=p("Per tenere traccia dei tuoi progressi durante l\u2019addestramento, usa la libreria "),ba=r("a"),it=p("tqdm"),nt=p(" per aggiungere una progress bar sopra il numero dei passi di addestramento:"),tt=m(),$(De.$$.fragment),st=m(),Ra=r("h3"),Wa=r("a"),Ba=r("span"),$(Ga.$$.fragment),pt=m(),Ya=r("span"),oa=p("Metriche"),lt=m(),ka=r("p"),La=p("Proprio come \xE8 necessario aggiungere una funzione di valutazione del "),Ka=r("code"),ct=p("Trainer"),dt=p(", \xE8 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 "),Re=r("a"),Oa=r("code"),mt=p("add_batch"),ft=p(" e calcolerai la metrica alla fine."),Aa=m(),$(Va.$$.fragment),this.h()},l(t){y(g.$$.fragment,t),E=f(t),h=o(t,"P",{});var w=i(h);_=o(w,"CODE",{});var Pa=i(_);z=c(Pa,"Trainer"),Pa.forEach(e),W=c(w," 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 \u{1F917} Transformers in PyTorch nativo."),w.forEach(e),x=f(t),Z=o(t,"P",{});var rt=i(Z);R=c(rt,"A questo punto, potresti avere bisogno di riavviare il tuo notebook o eseguire il seguente codice per liberare un po\u2019 di memoria:"),rt.forEach(e),A=f(t),y(G.$$.fragment,t),D=f(t),L=o(t,"P",{});var et=i(L);Ne=c(et,"Successivamente, postprocessa manualmente il "),Be=o(et,"CODE",{});var ot=i(Be);F=c(ot,"tokenized_dataset"),ot.forEach(e),Ge=c(et," per prepararlo ad essere allenato."),et.forEach(e),ue=f(t),K=o(t,"OL",{});var Da=i(K);ae=o(Da,"LI",{});var ut=i(ae);he=o(ut,"P",{});var gt=i(he);_e=c(gt,"Rimuovi la colonna "),te=o(gt,"CODE",{});var It=i(te);Le=c(It,"text"),It.forEach(e),oe=c(gt," perch\xE9 il modello non accetta testo grezzo come input:"),gt.forEach(e),Ke=f(ut),y(S.$$.fragment,ut),ut.forEach(e),ia=f(Da),C=o(Da,"LI",{});var wt=i(C);X=o(wt,"P",{});var ht=i(X);O=c(ht,"Rinomina la colonna "),H=o(ht,"CODE",{});var Rt=i(H);na=c(Rt,"label"),Rt.forEach(e),Ye=c(ht," in "),ie=o(ht,"CODE",{});var Gt=i(ie);pa=c(Gt,"labels"),Gt.forEach(e),za=c(ht," perch\xE9 il modello si aspetta che questo argomento si chiami "),Ee=o(ht,"CODE",{});var Ct=i(Ee);ge=c(Ct,"labels"),Ct.forEach(e),$a=c(ht,":"),ht.forEach(e),Ce=f(wt),y(N.$$.fragment,wt),wt.forEach(e),Oe=f(Da),U=o(Da,"LI",{});var bt=i(U);B=o(bt,"P",{});var Wt=i(B);ne=c(Wt,"Imposta il formato del dataset per farti restituire tensori di PyTorch all\u2019interno delle liste:"),Wt.forEach(e),pe=f(bt),y(Ve.$$.fragment,bt),bt.forEach(e),Da.forEach(e),ke=f(t),ve=o(t,"P",{});var At=i(ve);ea=c(At,"Poi crea un piccolo sottocampione del dataset come visto precedentemente per velocizzare il fine-tuning:"),At.forEach(e),I=f(t),y(ze.$$.fragment,t),Ze=f(t),Y=o(t,"H3",{class:!0});var $t=i(Y);ce=o($t,"A",{id:!0,class:!0,href:!0});var Xt=i(ce);we=o(Xt,"SPAN",{});var Ft=i(we);y(We.$$.fragment,Ft),Ft.forEach(e),Xt.forEach(e),V=f($t),be=o($t,"SPAN",{});var Nt=i(be);aa=c(Nt,"DataLoader"),Nt.forEach(e),$t.forEach(e),ya=f(t),se=o(t,"P",{});var yt=i(se);de=c(yt,"Crea un "),Pe=o(yt,"CODE",{});var Bt=i(Pe);d=c(Bt,"DataLoader"),Bt.forEach(e),k=c(yt," per i tuoi datasets di train e test cos\xEC puoi iterare sui lotti di dati:"),yt.forEach(e),q=f(t),y(le.$$.fragment,t),Ue=f(t),$e=o(t,"P",{});var Yt=i($e);P=c(Yt,"Carica il tuo modello con il numero atteso di etichette:"),Yt.forEach(e),ca=f(t),y(Ae.$$.fragment,t),ye=f(t),ee=o(t,"H3",{class:!0});var Mt=i(ee);Me=o(Mt,"A",{id:!0,class:!0,href:!0});var Vt=i(Me);Se=o(Vt,"SPAN",{});var Pt=i(Se);y(He.$$.fragment,Pt),Pt.forEach(e),Vt.forEach(e),re=f(Mt),Ie=o(Mt,"SPAN",{});var St=i(Ie);Ma=c(St,"Ottimizzatore e learning rate scheduler"),St.forEach(e),Mt.forEach(e),Xe=f(t),me=o(t,"P",{});var jt=i(me);qe=c(jt,"Crea un ottimizzatore e il learning rate scheduler per fare il fine-tuning del modello. Usa l\u2019ottimizzatore "),fe=o(jt,"A",{href:!0,rel:!0});var Ht=i(fe);da=o(Ht,"CODE",{});var qt=i(da);ta=c(qt,"AdamW"),qt.forEach(e),Ht.forEach(e),Sa=c(jt," di PyTorch:"),jt.forEach(e),Za=f(t),y(ma.$$.fragment,t),je=f(t),Je=o(t,"P",{});var Jt=i(Je);Qe=c(Jt,"Crea il learning rate scheduler predefinito da "),Te=o(Jt,"CODE",{});var Qt=i(Te);Fa=c(Qt,"Trainer"),Qt.forEach(e),fa=c(Jt,":"),Jt.forEach(e),Ha=f(t),y(sa.$$.fragment,t),Ua=f(t),ua=o(t,"P",{});var Tt=i(ua);ha=c(Tt,"Infine specifica come "),la=o(Tt,"CODE",{});var xt=i(la);Ia=c(xt,"device"),xt.forEach(e),Ca=c(Tt," da usare una GPU se ne hai una. Altrimenti, l\u2019addestramento su una CPU pu\xF2 richiedere diverse ore invece di un paio di minuti."),Tt.forEach(e),ja=f(t),y(Ja.$$.fragment,t),Ta=f(t),y(ga.$$.fragment,t),xe=f(t),va=o(t,"P",{});var Dt=i(va);_a=c(Dt,"Ottimo, adesso possiamo addestrare! \u{1F973}"),Dt.forEach(e),qa=f(t),wa=o(t,"H3",{class:!0});var _t=i(wa);ra=o(_t,"A",{id:!0,class:!0,href:!0});var Lt=i(ra);s=o(Lt,"SPAN",{});var Kt=i(s);y(v.$$.fragment,Kt),Kt.forEach(e),Lt.forEach(e),l=f(_t),b=o(_t,"SPAN",{});var Ot=i(b);Qa=c(Ot,"Training loop"),Ot.forEach(e),_t.forEach(e),at=f(t),Ea=o(t,"P",{});var Et=i(Ea);Na=c(Et,"Per tenere traccia dei tuoi progressi durante l\u2019addestramento, usa la libreria "),ba=o(Et,"A",{href:!0,rel:!0});var es=i(ba);it=c(es,"tqdm"),es.forEach(e),nt=c(Et," per aggiungere una progress bar sopra il numero dei passi di addestramento:"),Et.forEach(e),tt=f(t),y(De.$$.fragment,t),st=f(t),Ra=o(t,"H3",{class:!0});var kt=i(Ra);Wa=o(kt,"A",{id:!0,class:!0,href:!0});var as=i(Wa);Ba=o(as,"SPAN",{});var ts=i(Ba);y(Ga.$$.fragment,ts),ts.forEach(e),as.forEach(e),pt=f(kt),Ya=o(kt,"SPAN",{});var ss=i(Ya);oa=c(ss,"Metriche"),ss.forEach(e),kt.forEach(e),lt=f(t),ka=o(t,"P",{});var vt=i(ka);La=c(vt,"Proprio come \xE8 necessario aggiungere una funzione di valutazione del "),Ka=o(vt,"CODE",{});var ls=i(Ka);ct=c(ls,"Trainer"),ls.forEach(e),dt=c(vt,", \xE8 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 "),Re=o(vt,"A",{href:!0,rel:!0});var rs=i(Re);Oa=o(rs,"CODE",{});var os=i(Oa);mt=c(os,"add_batch"),os.forEach(e),rs.forEach(e),ft=c(vt," e calcolerai la metrica alla fine."),vt.forEach(e),Aa=f(t),y(Va.$$.fragment,t),this.h()},h(){u(ce,"id","dataloader"),u(ce,"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"),u(ce,"href","#dataloader"),u(Y,"class","relative group"),u(Me,"id","ottimizzatore-e-learning-rate-scheduler"),u(Me,"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"),u(Me,"href","#ottimizzatore-e-learning-rate-scheduler"),u(ee,"class","relative group"),u(fe,"href","https://pytorch.org/docs/stable/generated/torch.optim.AdamW.html"),u(fe,"rel","nofollow"),u(ra,"id","training-loop"),u(ra,"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"),u(ra,"href","#training-loop"),u(wa,"class","relative group"),u(ba,"href","https://tqdm.github.io/"),u(ba,"rel","nofollow"),u(Wa,"id","metriche"),u(Wa,"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"),u(Wa,"href","#metriche"),u(Ra,"class","relative group"),u(Re,"href","https://huggingface.co/docs/datasets/package_reference/main_classes.html?highlight=add_batch#datasets.Metric.add_batch"),u(Re,"rel","nofollow")},m(t,w){M(g,t,w),n(t,E,w),n(t,h,w),a(h,_),a(_,z),a(h,W),n(t,x,w),n(t,Z,w),a(Z,R),n(t,A,w),M(G,t,w),n(t,D,w),n(t,L,w),a(L,Ne),a(L,Be),a(Be,F),a(L,Ge),n(t,ue,w),n(t,K,w),a(K,ae),a(ae,he),a(he,_e),a(he,te),a(te,Le),a(he,oe),a(ae,Ke),M(S,ae,null),a(K,ia),a(K,C),a(C,X),a(X,O),a(X,H),a(H,na),a(X,Ye),a(X,ie),a(ie,pa),a(X,za),a(X,Ee),a(Ee,ge),a(X,$a),a(C,Ce),M(N,C,null),a(K,Oe),a(K,U),a(U,B),a(B,ne),a(U,pe),M(Ve,U,null),n(t,ke,w),n(t,ve,w),a(ve,ea),n(t,I,w),M(ze,t,w),n(t,Ze,w),n(t,Y,w),a(Y,ce),a(ce,we),M(We,we,null),a(Y,V),a(Y,be),a(be,aa),n(t,ya,w),n(t,se,w),a(se,de),a(se,Pe),a(Pe,d),a(se,k),n(t,q,w),M(le,t,w),n(t,Ue,w),n(t,$e,w),a($e,P),n(t,ca,w),M(Ae,t,w),n(t,ye,w),n(t,ee,w),a(ee,Me),a(Me,Se),M(He,Se,null),a(ee,re),a(ee,Ie),a(Ie,Ma),n(t,Xe,w),n(t,me,w),a(me,qe),a(me,fe),a(fe,da),a(da,ta),a(me,Sa),n(t,Za,w),M(ma,t,w),n(t,je,w),n(t,Je,w),a(Je,Qe),a(Je,Te),a(Te,Fa),a(Je,fa),n(t,Ha,w),M(sa,t,w),n(t,Ua,w),n(t,ua,w),a(ua,ha),a(ua,la),a(la,Ia),a(ua,Ca),n(t,ja,w),M(Ja,t,w),n(t,Ta,w),M(ga,t,w),n(t,xe,w),n(t,va,w),a(va,_a),n(t,qa,w),n(t,wa,w),a(wa,ra),a(ra,s),M(v,s,null),a(wa,l),a(wa,b),a(b,Qa),n(t,at,w),n(t,Ea,w),a(Ea,Na),a(Ea,ba),a(ba,it),a(Ea,nt),n(t,tt,w),M(De,t,w),n(t,st,w),n(t,Ra,w),a(Ra,Wa),a(Wa,Ba),M(Ga,Ba,null),a(Ra,pt),a(Ra,Ya),a(Ya,oa),n(t,lt,w),n(t,ka,w),a(ka,La),a(ka,Ka),a(Ka,ct),a(ka,dt),a(ka,Re),a(Re,Oa),a(Oa,mt),a(ka,ft),n(t,Aa,w),M(Va,t,w),xa=!0},p(t,w){const Pa={};w&2&&(Pa.$$scope={dirty:w,ctx:t}),ga.$set(Pa)},i(t){xa||(j(g.$$.fragment,t),j(G.$$.fragment,t),j(S.$$.fragment,t),j(N.$$.fragment,t),j(Ve.$$.fragment,t),j(ze.$$.fragment,t),j(We.$$.fragment,t),j(le.$$.fragment,t),j(Ae.$$.fragment,t),j(He.$$.fragment,t),j(ma.$$.fragment,t),j(sa.$$.fragment,t),j(Ja.$$.fragment,t),j(ga.$$.fragment,t),j(v.$$.fragment,t),j(De.$$.fragment,t),j(Ga.$$.fragment,t),j(Va.$$.fragment,t),xa=!0)},o(t){J(g.$$.fragment,t),J(G.$$.fragment,t),J(S.$$.fragment,t),J(N.$$.fragment,t),J(Ve.$$.fragment,t),J(ze.$$.fragment,t),J(We.$$.fragment,t),J(le.$$.fragment,t),J(Ae.$$.fragment,t),J(He.$$.fragment,t),J(ma.$$.fragment,t),J(sa.$$.fragment,t),J(Ja.$$.fragment,t),J(ga.$$.fragment,t),J(v.$$.fragment,t),J(De.$$.fragment,t),J(Ga.$$.fragment,t),J(Va.$$.fragment,t),xa=!1},d(t){T(g,t),t&&e(E),t&&e(h),t&&e(x),t&&e(Z),t&&e(A),T(G,t),t&&e(D),t&&e(L),t&&e(ue),t&&e(K),T(S),T(N),T(Ve),t&&e(ke),t&&e(ve),t&&e(I),T(ze,t),t&&e(Ze),t&&e(Y),T(We),t&&e(ya),t&&e(se),t&&e(q),T(le,t),t&&e(Ue),t&&e($e),t&&e(ca),T(Ae,t),t&&e(ye),t&&e(ee),T(He),t&&e(Xe),t&&e(me),t&&e(Za),T(ma,t),t&&e(je),t&&e(Je),t&&e(Ha),T(sa,t),t&&e(Ua),t&&e(ua),t&&e(ja),T(Ja,t),t&&e(Ta),T(ga,t),t&&e(xe),t&&e(va),t&&e(qa),t&&e(wa),T(v),t&&e(at),t&&e(Ea),t&&e(tt),T(De,t),t&&e(st),t&&e(Ra),T(Ga),t&&e(lt),t&&e(ka),t&&e(Aa),T(Va,t)}}}function Ms(Fe){let g,E;return g=new Ut({props:{$$slots:{default:[ys]},$$scope:{ctx:Fe}}}),{c(){$(g.$$.fragment)},l(h){y(g.$$.fragment,h)},m(h,_){M(g,h,_),E=!0},p(h,_){const z={};_&2&&(z.$$scope={dirty:_,ctx:h}),g.$set(z)},i(h){E||(j(g.$$.fragment,h),E=!0)},o(h){J(g.$$.fragment,h),E=!1},d(h){T(g,h)}}}function js(Fe){let g,E,h,_,z,W,x,Z,R,A,G,D,L,Ne,Be,F,Ge,ue,K,ae,he,_e,te,Le,oe,Ke,S,ia,C,X,O,H,na,Ye,ie,pa,za,Ee,ge,$a,Ce,N,Oe,U,B,ne,pe,Ve,ke,ve,ea,I,ze,Ze,Y,ce,we,We,V,be,aa,ya,se,de,Pe,d,k,q,le,Ue,$e,P,ca,Ae,ye,ee,Me,Se,He,re,Ie,Ma,Xe,me,qe,fe,da,ta,Sa,Za,ma,je,Je,Qe,Te,Fa,fa,Ha,sa,Ua,ua,ha,la,Ia,Ca,ja,Ja,Ta,ga,xe,va,_a,qa,wa,ra;return W=new Xa({}),G=new fs({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"}]}}),Ye=new Xa({}),ge=new zt({props:{id:"_BZearw7f0w"}}),ve=new Q({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>}`}}),V=new Q({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>)`}}),de=new Q({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>))`}}),$e=new Xa({}),ee=new is({props:{pytorch:!0,tensorflow:!0,jax:!1,$$slots:{tensorflow:[bs],pytorch:[gs]},$$scope:{ctx:Fe}}}),Xe=new Xa({}),ta=new is({props:{pytorch:!0,tensorflow:!1,jax:!1,$$slots:{pytorch:[Ms]},$$scope:{ctx:Fe}}}),Te=new Xa({}),{c(){g=r("meta"),E=m(),h=r("h1"),_=r("a"),z=r("span"),$(W.$$.fragment),x=m(),Z=r("span"),R=p("Fine-tuning di un modello pre-addestrato"),A=m(),$(G.$$.fragment),D=m(),L=r("p"),Ne=p("Ci sono benefici significativi nell\u2019usare un modello pre-addestrato. Si riducono i costi computazionali, l\u2019impronta di carbonio e ti consente di usare modelli stato dell\u2019arte senza doverli addestrare da zero. \u{1F917} Transformers consente l\u2019accesso a migliaia di modelli pre-addestrati per un\u2019ampia gamma di compiti. Quando usi un modello pre-addestrato, lo alleni su un dataset specifico per il tuo compito. Questo \xE8 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:"),Be=m(),F=r("ul"),Ge=r("li"),ue=p("Fine-tuning di un modello pre-addestrato con \u{1F917} Transformers "),K=r("code"),ae=p("Trainer"),he=p("."),_e=m(),te=r("li"),Le=p("Fine-tuning di un modello pre-addestrato in TensorFlow con Keras."),oe=m(),Ke=r("li"),S=p("Fine-tuning di un modello pre-addestrato con PyTorch."),ia=m(),C=r("a"),X=m(),O=r("h2"),H=r("a"),na=r("span"),$(Ye.$$.fragment),ie=m(),pa=r("span"),za=p("Preparare un dataset"),Ee=m(),$(ge.$$.fragment),$a=m(),Ce=r("p"),N=p("Prima di poter fare il fine-tuning di un modello pre-addestrato, scarica un dataset e preparalo per l\u2019addestramento. La precedente esercitazione ti ha mostrato come processare i dati per l\u2019addestramento e adesso hai l\u2019opportunit\xE0 di metterti alla prova!"),Oe=m(),U=r("p"),B=p("Inizia caricando il dataset "),ne=r("a"),pe=p("Yelp Reviews"),Ve=p(":"),ke=m(),$(ve.$$.fragment),ea=m(),I=r("p"),ze=p("Come gi\xE0 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 "),Ze=r("a"),Y=r("code"),ce=p("map"),we=p(" di \u{1F917} Datasets che applica la funzione di preprocessing all\u2019intero dataset:"),We=m(),$(V.$$.fragment),be=m(),aa=r("p"),ya=p("Se vuoi, puoi creare un sottoinsieme pi\xF9 piccolo del dataset per il fine-tuning cos\xEC da ridurre il tempo necessario:"),se=m(),$(de.$$.fragment),Pe=m(),d=r("a"),k=m(),q=r("h2"),le=r("a"),Ue=r("span"),$($e.$$.fragment),P=m(),ca=r("span"),Ae=p("Addestramento"),ye=m(),$(ee.$$.fragment),Me=m(),Se=r("a"),He=m(),re=r("h2"),Ie=r("a"),Ma=r("span"),$(Xe.$$.fragment),me=m(),qe=r("span"),fe=p("Addestramento in PyTorch nativo"),da=m(),$(ta.$$.fragment),Sa=m(),Za=r("a"),ma=m(),je=r("h2"),Je=r("a"),Qe=r("span"),$(Te.$$.fragment),Fa=m(),fa=r("span"),Ha=p("Altre risorse"),sa=m(),Ua=r("p"),ua=p("Per altri esempi sul fine-tuning, fai riferimento a:"),ha=m(),la=r("ul"),Ia=r("li"),Ca=r("p"),ja=r("a"),Ja=p("\u{1F917} Transformers Examples"),Ta=p(" include scripts per addestrare compiti comuni di NLP in PyTorch e TensorFlow."),ga=m(),xe=r("li"),va=r("p"),_a=r("a"),qa=p("\u{1F917} Transformers Notebooks"),wa=p(" contiene diversi notebooks su come mettere a punto un modello per compiti specifici in PyTorch e TensorFlow."),this.h()},l(s){const v=ds('[data-svelte="svelte-1phssyn"]',document.head);g=o(v,"META",{name:!0,content:!0}),v.forEach(e),E=f(s),h=o(s,"H1",{class:!0});var l=i(h);_=o(l,"A",{id:!0,class:!0,href:!0});var b=i(_);z=o(b,"SPAN",{});var Qa=i(z);y(W.$$.fragment,Qa),Qa.forEach(e),b.forEach(e),x=f(l),Z=o(l,"SPAN",{});var at=i(Z);R=c(at,"Fine-tuning di un modello pre-addestrato"),at.forEach(e),l.forEach(e),A=f(s),y(G.$$.fragment,s),D=f(s),L=o(s,"P",{});var Ea=i(L);Ne=c(Ea,"Ci sono benefici significativi nell\u2019usare un modello pre-addestrato. Si riducono i costi computazionali, l\u2019impronta di carbonio e ti consente di usare modelli stato dell\u2019arte senza doverli addestrare da zero. \u{1F917} Transformers consente l\u2019accesso a migliaia di modelli pre-addestrati per un\u2019ampia gamma di compiti. Quando usi un modello pre-addestrato, lo alleni su un dataset specifico per il tuo compito. Questo \xE8 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:"),Ea.forEach(e),Be=f(s),F=o(s,"UL",{});var Na=i(F);Ge=o(Na,"LI",{});var ba=i(Ge);ue=c(ba,"Fine-tuning di un modello pre-addestrato con \u{1F917} Transformers "),K=o(ba,"CODE",{});var it=i(K);ae=c(it,"Trainer"),it.forEach(e),he=c(ba,"."),ba.forEach(e),_e=f(Na),te=o(Na,"LI",{});var nt=i(te);Le=c(nt,"Fine-tuning di un modello pre-addestrato in TensorFlow con Keras."),nt.forEach(e),oe=f(Na),Ke=o(Na,"LI",{});var tt=i(Ke);S=c(tt,"Fine-tuning di un modello pre-addestrato con PyTorch."),tt.forEach(e),Na.forEach(e),ia=f(s),C=o(s,"A",{id:!0}),i(C).forEach(e),X=f(s),O=o(s,"H2",{class:!0});var De=i(O);H=o(De,"A",{id:!0,class:!0,href:!0});var st=i(H);na=o(st,"SPAN",{});var Ra=i(na);y(Ye.$$.fragment,Ra),Ra.forEach(e),st.forEach(e),ie=f(De),pa=o(De,"SPAN",{});var Wa=i(pa);za=c(Wa,"Preparare un dataset"),Wa.forEach(e),De.forEach(e),Ee=f(s),y(ge.$$.fragment,s),$a=f(s),Ce=o(s,"P",{});var Ba=i(Ce);N=c(Ba,"Prima di poter fare il fine-tuning di un modello pre-addestrato, scarica un dataset e preparalo per l\u2019addestramento. La precedente esercitazione ti ha mostrato come processare i dati per l\u2019addestramento e adesso hai l\u2019opportunit\xE0 di metterti alla prova!"),Ba.forEach(e),Oe=f(s),U=o(s,"P",{});var Ga=i(U);B=c(Ga,"Inizia caricando il dataset "),ne=o(Ga,"A",{href:!0,rel:!0});var pt=i(ne);pe=c(pt,"Yelp Reviews"),pt.forEach(e),Ve=c(Ga,":"),Ga.forEach(e),ke=f(s),y(ve.$$.fragment,s),ea=f(s),I=o(s,"P",{});var Ya=i(I);ze=c(Ya,"Come gi\xE0 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 "),Ze=o(Ya,"A",{href:!0,rel:!0});var oa=i(Ze);Y=o(oa,"CODE",{});var lt=i(Y);ce=c(lt,"map"),lt.forEach(e),oa.forEach(e),we=c(Ya," di \u{1F917} Datasets che applica la funzione di preprocessing all\u2019intero dataset:"),Ya.forEach(e),We=f(s),y(V.$$.fragment,s),be=f(s),aa=o(s,"P",{});var ka=i(aa);ya=c(ka,"Se vuoi, puoi creare un sottoinsieme pi\xF9 piccolo del dataset per il fine-tuning cos\xEC da ridurre il tempo necessario:"),ka.forEach(e),se=f(s),y(de.$$.fragment,s),Pe=f(s),d=o(s,"A",{id:!0}),i(d).forEach(e),k=f(s),q=o(s,"H2",{class:!0});var La=i(q);le=o(La,"A",{id:!0,class:!0,href:!0});var Ka=i(le);Ue=o(Ka,"SPAN",{});var ct=i(Ue);y($e.$$.fragment,ct),ct.forEach(e),Ka.forEach(e),P=f(La),ca=o(La,"SPAN",{});var dt=i(ca);Ae=c(dt,"Addestramento"),dt.forEach(e),La.forEach(e),ye=f(s),y(ee.$$.fragment,s),Me=f(s),Se=o(s,"A",{id:!0}),i(Se).forEach(e),He=f(s),re=o(s,"H2",{class:!0});var Re=i(re);Ie=o(Re,"A",{id:!0,class:!0,href:!0});var Oa=i(Ie);Ma=o(Oa,"SPAN",{});var mt=i(Ma);y(Xe.$$.fragment,mt),mt.forEach(e),Oa.forEach(e),me=f(Re),qe=o(Re,"SPAN",{});var ft=i(qe);fe=c(ft,"Addestramento in PyTorch nativo"),ft.forEach(e),Re.forEach(e),da=f(s),y(ta.$$.fragment,s),Sa=f(s),Za=o(s,"A",{id:!0}),i(Za).forEach(e),ma=f(s),je=o(s,"H2",{class:!0});var Aa=i(je);Je=o(Aa,"A",{id:!0,class:!0,href:!0});var Va=i(Je);Qe=o(Va,"SPAN",{});var xa=i(Qe);y(Te.$$.fragment,xa),xa.forEach(e),Va.forEach(e),Fa=f(Aa),fa=o(Aa,"SPAN",{});var t=i(fa);Ha=c(t,"Altre risorse"),t.forEach(e),Aa.forEach(e),sa=f(s),Ua=o(s,"P",{});var w=i(Ua);ua=c(w,"Per altri esempi sul fine-tuning, fai riferimento a:"),w.forEach(e),ha=f(s),la=o(s,"UL",{});var Pa=i(la);Ia=o(Pa,"LI",{});var rt=i(Ia);Ca=o(rt,"P",{});var et=i(Ca);ja=o(et,"A",{href:!0,rel:!0});var ot=i(ja);Ja=c(ot,"\u{1F917} Transformers Examples"),ot.forEach(e),Ta=c(et," include scripts per addestrare compiti comuni di NLP in PyTorch e TensorFlow."),et.forEach(e),rt.forEach(e),ga=f(Pa),xe=o(Pa,"LI",{});var Da=i(xe);va=o(Da,"P",{});var ut=i(va);_a=o(ut,"A",{href:!0});var gt=i(_a);qa=c(gt,"\u{1F917} Transformers Notebooks"),gt.forEach(e),wa=c(ut," contiene diversi notebooks su come mettere a punto un modello per compiti specifici in PyTorch e TensorFlow."),ut.forEach(e),Da.forEach(e),Pa.forEach(e),this.h()},h(){u(g,"name","hf:doc:metadata"),u(g,"content",JSON.stringify(Js)),u(_,"id","finetuning-di-un-modello-preaddestrato"),u(_,"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"),u(_,"href","#finetuning-di-un-modello-preaddestrato"),u(h,"class","relative group"),u(C,"id","data-processing"),u(H,"id","preparare-un-dataset"),u(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"),u(H,"href","#preparare-un-dataset"),u(O,"class","relative group"),u(ne,"href","https://huggingface.co/datasets/yelp_review_full"),u(ne,"rel","nofollow"),u(Ze,"href","https://huggingface.co/docs/datasets/process.html#map"),u(Ze,"rel","nofollow"),u(d,"id","trainer"),u(le,"id","addestramento"),u(le,"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"),u(le,"href","#addestramento"),u(q,"class","relative group"),u(Se,"id","pytorch_native"),u(Ie,"id","addestramento-in-pytorch-nativo"),u(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"),u(Ie,"href","#addestramento-in-pytorch-nativo"),u(re,"class","relative group"),u(Za,"id","additional-resources"),u(Je,"id","altre-risorse"),u(Je,"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"),u(Je,"href","#altre-risorse"),u(je,"class","relative group"),u(ja,"href","https://github.com/huggingface/transformers/tree/main/examples"),u(ja,"rel","nofollow"),u(_a,"href","notebooks")},m(s,v){a(document.head,g),n(s,E,v),n(s,h,v),a(h,_),a(_,z),M(W,z,null),a(h,x),a(h,Z),a(Z,R),n(s,A,v),M(G,s,v),n(s,D,v),n(s,L,v),a(L,Ne),n(s,Be,v),n(s,F,v),a(F,Ge),a(Ge,ue),a(Ge,K),a(K,ae),a(Ge,he),a(F,_e),a(F,te),a(te,Le),a(F,oe),a(F,Ke),a(Ke,S),n(s,ia,v),n(s,C,v),n(s,X,v),n(s,O,v),a(O,H),a(H,na),M(Ye,na,null),a(O,ie),a(O,pa),a(pa,za),n(s,Ee,v),M(ge,s,v),n(s,$a,v),n(s,Ce,v),a(Ce,N),n(s,Oe,v),n(s,U,v),a(U,B),a(U,ne),a(ne,pe),a(U,Ve),n(s,ke,v),M(ve,s,v),n(s,ea,v),n(s,I,v),a(I,ze),a(I,Ze),a(Ze,Y),a(Y,ce),a(I,we),n(s,We,v),M(V,s,v),n(s,be,v),n(s,aa,v),a(aa,ya),n(s,se,v),M(de,s,v),n(s,Pe,v),n(s,d,v),n(s,k,v),n(s,q,v),a(q,le),a(le,Ue),M($e,Ue,null),a(q,P),a(q,ca),a(ca,Ae),n(s,ye,v),M(ee,s,v),n(s,Me,v),n(s,Se,v),n(s,He,v),n(s,re,v),a(re,Ie),a(Ie,Ma),M(Xe,Ma,null),a(re,me),a(re,qe),a(qe,fe),n(s,da,v),M(ta,s,v),n(s,Sa,v),n(s,Za,v),n(s,ma,v),n(s,je,v),a(je,Je),a(Je,Qe),M(Te,Qe,null),a(je,Fa),a(je,fa),a(fa,Ha),n(s,sa,v),n(s,Ua,v),a(Ua,ua),n(s,ha,v),n(s,la,v),a(la,Ia),a(Ia,Ca),a(Ca,ja),a(ja,Ja),a(Ca,Ta),a(la,ga),a(la,xe),a(xe,va),a(va,_a),a(_a,qa),a(va,wa),ra=!0},p(s,[v]){const l={};v&2&&(l.$$scope={dirty:v,ctx:s}),ee.$set(l);const b={};v&2&&(b.$$scope={dirty:v,ctx:s}),ta.$set(b)},i(s){ra||(j(W.$$.fragment,s),j(G.$$.fragment,s),j(Ye.$$.fragment,s),j(ge.$$.fragment,s),j(ve.$$.fragment,s),j(V.$$.fragment,s),j(de.$$.fragment,s),j($e.$$.fragment,s),j(ee.$$.fragment,s),j(Xe.$$.fragment,s),j(ta.$$.fragment,s),j(Te.$$.fragment,s),ra=!0)},o(s){J(W.$$.fragment,s),J(G.$$.fragment,s),J(Ye.$$.fragment,s),J(ge.$$.fragment,s),J(ve.$$.fragment,s),J(V.$$.fragment,s),J(de.$$.fragment,s),J($e.$$.fragment,s),J(ee.$$.fragment,s),J(Xe.$$.fragment,s),J(ta.$$.fragment,s),J(Te.$$.fragment,s),ra=!1},d(s){e(g),s&&e(E),s&&e(h),T(W),s&&e(A),T(G,s),s&&e(D),s&&e(L),s&&e(Be),s&&e(F),s&&e(ia),s&&e(C),s&&e(X),s&&e(O),T(Ye),s&&e(Ee),T(ge,s),s&&e($a),s&&e(Ce),s&&e(Oe),s&&e(U),s&&e(ke),T(ve,s),s&&e(ea),s&&e(I),s&&e(We),T(V,s),s&&e(be),s&&e(aa),s&&e(se),T(de,s),s&&e(Pe),s&&e(d),s&&e(k),s&&e(q),T($e),s&&e(ye),T(ee,s),s&&e(Me),s&&e(Se),s&&e(He),s&&e(re),T(Xe),s&&e(da),T(ta,s),s&&e(Sa),s&&e(Za),s&&e(ma),s&&e(je),T(Te),s&&e(sa),s&&e(Ua),s&&e(ha),s&&e(la)}}}const Js={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 Ts(Fe){return ms(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Gs extends ns{constructor(g){super();ps(this,g,Ts,js,cs,{})}}export{Gs as default,Js as metadata};
