import{S as Am,i as Xm,s as Fm,e as o,k as m,w as u,t as i,M as Nm,c as r,d as a,m as c,a as l,x as f,h as p,b as d,G as s,g as n,y as h,q as g,o as v,B as b,v as Bm}from"../chunks/vendor-hf-doc-builder.js";import{T as Ni}from"../chunks/Tip-hf-doc-builder.js";import{Y as qr}from"../chunks/Youtube-hf-doc-builder.js";import{I as k}from"../chunks/IconCopyLink-hf-doc-builder.js";import{C as j}from"../chunks/CodeBlock-hf-doc-builder.js";import{D as Ym}from"../chunks/DocNotebookDropdown-hf-doc-builder.js";function Vm(oe){let y,T;return{c(){y=o("p"),T=i(`Voc\xEA ver\xE1 um alerta sobre alguns pesos pr\xE9-treinados que n\xE3o est\xE3o sendo utilizados e que alguns pesos est\xE3o
sendo inicializados aleatoriamente. N\xE3o se preocupe, essa mensagem \xE9 completamente normal.
O header/cabe\xE7\xE1rio pr\xE9-treinado do modelo BERT \xE9 descartado e substitui-se por um header de classifica\xE7\xE3o
inicializado aleatoriamente. Assim, pode aplicar o fine-tuning a este novo header do modelo em sua tarefa
de classifica\xE7\xE3o de sequ\xEAncias fazendo um transfer learning do modelo pr\xE9-treinado.`)},l(w){y=r(w,"P",{});var $=l(y);T=p($,`Voc\xEA ver\xE1 um alerta sobre alguns pesos pr\xE9-treinados que n\xE3o est\xE3o sendo utilizados e que alguns pesos est\xE3o
sendo inicializados aleatoriamente. N\xE3o se preocupe, essa mensagem \xE9 completamente normal.
O header/cabe\xE7\xE1rio pr\xE9-treinado do modelo BERT \xE9 descartado e substitui-se por um header de classifica\xE7\xE3o
inicializado aleatoriamente. Assim, pode aplicar o fine-tuning a este novo header do modelo em sua tarefa
de classifica\xE7\xE3o de sequ\xEAncias fazendo um transfer learning do modelo pr\xE9-treinado.`),$.forEach(a)},m(w,$){n(w,y,$),s(y,T)},d(w){w&&a(y)}}}function qm(oe){let y,T,w,$,Z,J,G,U;return{c(){y=o("p"),T=i("O "),w=o("code"),$=i("Trainer"),Z=i(" utiliza "),J=o("code"),G=i("DataCollatorWithPadding"),U=i(` por padr\xE3o, ent\xE3o voc\xEA n\xE3o precisa especificar explicitamente um
colador de dados (data collator).`)},l(E){y=r(E,"P",{});var M=l(y);T=p(M,"O "),w=r(M,"CODE",{});var I=l(w);$=p(I,"Trainer"),I.forEach(a),Z=p(M," utiliza "),J=r(M,"CODE",{});var W=l(J);G=p(W,"DataCollatorWithPadding"),W.forEach(a),U=p(M,` por padr\xE3o, ent\xE3o voc\xEA n\xE3o precisa especificar explicitamente um
colador de dados (data collator).`),M.forEach(a)},m(E,M){n(E,y,M),s(y,T),s(y,w),s(w,$),s(y,Z),s(y,J),s(J,G),s(y,U)},d(E){E&&a(y)}}}function Pm(oe){let y,T,w,$,Z,J,G,U;return{c(){y=o("p"),T=i(`Se necess\xE1rio, voc\xEA pode obter o acesso gratuito a uma GPU na n\xFAvem por meio de um notebook no
`),w=o("a"),$=i("Colaboratory"),Z=i(" ou "),J=o("a"),G=i("SageMaker StudioLab"),U=i(`
se n\xE3o tiver esse recurso de forma local.`),this.h()},l(E){y=r(E,"P",{});var M=l(y);T=p(M,`Se necess\xE1rio, voc\xEA pode obter o acesso gratuito a uma GPU na n\xFAvem por meio de um notebook no
`),w=r(M,"A",{href:!0,rel:!0});var I=l(w);$=p(I,"Colaboratory"),I.forEach(a),Z=p(M," ou "),J=r(M,"A",{href:!0,rel:!0});var W=l(J);G=p(W,"SageMaker StudioLab"),W.forEach(a),U=p(M,`
se n\xE3o tiver esse recurso de forma local.`),M.forEach(a),this.h()},h(){d(w,"href","https://colab.research.google.com/"),d(w,"rel","nofollow"),d(J,"href","https://studiolab.sagemaker.aws/"),d(J,"rel","nofollow")},m(E,M){n(E,y,M),s(y,T),s(y,w),s(w,$),s(y,Z),s(y,J),s(J,G),s(y,U)},d(E){E&&a(y)}}}function xm(oe){let y,T,w,$,Z,J,G,U,E,M,I,W,Ha,Pr,Rt,A,Fe,xr,ws,Hr,Sr,Dr,js,Qr,Or,Ms,Lr,zt,Sa,Gt,V,re,$s,Ne,Kr,Js,el,Wt,Be,At,Da,al,Xt,le,sl,Ye,tl,ol,Ft,Ve,Nt,ne,rl,qe,Ts,ll,nl,Bt,Pe,Yt,Qa,il,Vt,xe,qt,Oa,Pt,q,ie,_s,He,pl,La,ml,Es,cl,xt,Se,Ht,X,dl,ks,ul,fl,Zs,hl,gl,St,pe,vl,De,bl,yl,Dt,Qe,Qt,me,Ot,P,ce,Us,Oe,wl,Is,jl,Lt,F,Ml,Cs,$l,Jl,Le,Tl,_l,Kt,Ka,El,eo,Ke,ao,x,de,Rs,ea,kl,zs,Zl,so,_,Ul,Gs,Il,Cl,Ws,Rl,zl,aa,As,Gl,Wl,Xs,Al,Xl,sa,Fl,Nl,to,ta,oo,C,Bl,Fs,Yl,Vl,Ns,ql,Pl,Bs,xl,Hl,ro,oa,lo,ue,Sl,Ys,Dl,Ql,no,ra,io,H,fe,Vs,la,Ol,qs,Ll,po,he,Kl,Ps,en,an,mo,na,co,ge,sn,xs,tn,on,uo,ia,fo,es,ho,S,ve,Hs,pa,rn,Ss,ln,go,ma,vo,as,nn,bo,D,be,Ds,ca,pn,Qs,mn,yo,N,cn,Os,dn,un,Ls,fn,hn,wo,da,jo,ye,Mo,R,gn,ua,Ks,vn,bn,et,yn,wn,at,jn,Mn,$o,fa,Jo,Q,we,st,ha,$n,tt,Jn,To,ss,Tn,_o,ga,Eo,je,_n,va,ot,En,kn,ko,ba,Zo,ts,Uo,O,Me,rt,ya,Zn,lt,Un,Io,wa,Co,$e,In,nt,Cn,Rn,Ro,os,zn,zo,ja,Go,Je,Gn,it,Wn,An,Wo,B,Ma,$a,Xn,pt,Fn,Nn,Bn,Ja,Yn,Ta,L,Vn,mt,qn,Pn,ct,xn,Hn,Sn,_a,Dn,Ea,dt,Qn,On,ka,Ao,rs,Ln,Xo,Za,Fo,K,Te,ut,Ua,Kn,ft,ei,No,_e,ai,ht,si,ti,Bo,Ia,Yo,ls,oi,Vo,Ca,qo,ee,Ee,gt,Ra,ri,vt,li,Po,ke,ni,za,bt,ii,pi,xo,Ga,Ho,Ze,mi,yt,ci,di,So,Wa,Do,Ue,ui,wt,fi,hi,Qo,Aa,Oo,Ie,Lo,ns,gi,Ko,ae,Ce,jt,Xa,vi,Mt,bi,er,Re,yi,Fa,wi,ji,ar,Na,sr,se,ze,$t,Ba,Mi,Jt,$i,tr,Y,Ji,Tt,Ti,_i,Ya,_t,Ei,ki,or,Va,rr,is,lr,te,Ge,Et,qa,Zi,kt,Ui,nr,ps,Ii,ir,We,Zt,ms,Pa,Ci,Ri,zi,Ut,cs,ds,Gi,Wi,pr;return J=new k({}),I=new Ym({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/pt/training.ipynb"},{label:"PyTorch",value:"https://colab.research.google.com/github/huggingface/notebooks/blob/main/transformers_doc/pt/pytorch/training.ipynb"},{label:"TensorFlow",value:"https://colab.research.google.com/github/huggingface/notebooks/blob/main/transformers_doc/pt/tensorflow/training.ipynb"},{label:"Mixed",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/main/transformers_doc/pt/training.ipynb"},{label:"PyTorch",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/main/transformers_doc/pt/pytorch/training.ipynb"},{label:"TensorFlow",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/main/transformers_doc/pt/tensorflow/training.ipynb"}]}}),Ne=new k({}),Be=new qr({props:{id:"_BZearw7f0w"}}),Ve=new j({props:{code:"ZnJvbSUyMGRhdGFzZXRzJTIwaW1wb3J0JTIwbG9hZF9kYXRhc2V0JTBBJTBBZGF0YXNldCUyMCUzRCUyMGxvYWRfZGF0YXNldCglMjJ5ZWxwX3Jldmlld19mdWxsJTIyKSUwQWRhdGFzZXQlNUIxMDAlNUQ=",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-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>}`}}),Pe=new j({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>)`}}),xe=new j({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>))`}}),He=new k({}),Se=new qr({props:{id:"nvBXf7s7vTI"}}),Qe=new j({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>)`}}),me=new Ni({props:{$$slots:{default:[Vm]},$$scope:{ctx:oe}}}),Oe=new k({}),Ke=new j({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>)`}}),ea=new k({}),ta=new j({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>)`}}),oa=new j({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)`}}),ra=new j({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMFRyYWluaW5nQXJndW1lbnRzJTBBJTBBdHJhaW5pbmdfYXJncyUyMCUzRCUyMFRyYWluaW5nQXJndW1lbnRzKG91dHB1dF9kaXIlM0QlMjJ0ZXN0X3RyYWluZXIlMjIlMkMlMjBldmFsdWF0aW9uX3N0cmF0ZWd5JTNEJTIyZXBvY2glMjIp",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>, evaluation_strategy=<span class="hljs-string">&quot;epoch&quot;</span>)`}}),la=new k({}),na=new j({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>)`}}),ia=new j({props:{code:"dHJhaW5lci50cmFpbigp",highlighted:'<span class="hljs-meta">&gt;&gt;&gt; </span>trainer.train()'}}),pa=new k({}),ma=new qr({props:{id:"rnTGBy2ax1c"}}),ca=new k({}),da=new j({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>)`}}),ye=new Ni({props:{$$slots:{default:[qm]},$$scope:{ctx:oe}}}),fa=new j({props:{code:"dGZfdHJhaW5fZGF0YXNldCUyMCUzRCUyMHNtYWxsX3RyYWluX2RhdGFzZXQudG9fdGZfZGF0YXNldCglMEElMjAlMjAlMjAlMjBjb2x1bW5zJTNEJTVCJTIyYXR0ZW50aW9uX21hc2slMjIlMkMlMjAlMjJpbnB1dF9pZHMlMjIlMkMlMjAlMjJ0b2tlbl90eXBlX2lkcyUyMiU1RCUyQyUwQSUyMCUyMCUyMCUyMGxhYmVsX2NvbHMlM0QlMjJsYWJlbHMlMjIlMkMlMEElMjAlMjAlMjAlMjBzaHVmZmxlJTNEVHJ1ZSUyQyUwQSUyMCUyMCUyMCUyMGNvbGxhdGVfZm4lM0RkYXRhX2NvbGxhdG9yJTJDJTBBJTIwJTIwJTIwJTIwYmF0Y2hfc2l6ZSUzRDglMkMlMEEpJTBBJTBBdGZfdmFsaWRhdGlvbl9kYXRhc2V0JTIwJTNEJTIwc21hbGxfZXZhbF9kYXRhc2V0LnRvX3RmX2RhdGFzZXQoJTBBJTIwJTIwJTIwJTIwY29sdW1ucyUzRCU1QiUyMmF0dGVudGlvbl9tYXNrJTIyJTJDJTIwJTIyaW5wdXRfaWRzJTIyJTJDJTIwJTIydG9rZW5fdHlwZV9pZHMlMjIlNUQlMkMlMEElMjAlMjAlMjAlMjBsYWJlbF9jb2xzJTNEJTIybGFiZWxzJTIyJTJDJTBBJTIwJTIwJTIwJTIwc2h1ZmZsZSUzREZhbHNlJTJDJTBBJTIwJTIwJTIwJTIwY29sbGF0ZV9mbiUzRGRhdGFfY29sbGF0b3IlMkMlMEElMjAlMjAlMjAlMjBiYXRjaF9zaXplJTNEOCUyQyUwQSk=",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>)`}}),ha=new k({}),ga=new j({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>)`}}),ba=new j({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>)`}}),ya=new k({}),wa=new qr({props:{id:"Dh9CL8fyG80"}}),ja=new j({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()`}}),Ja=new j({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>])'}}),_a=new j({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>)'}}),ka=new j({props:{code:"dG9rZW5pemVkX2RhdGFzZXRzLnNldF9mb3JtYXQoJTIydG9yY2glMjIp",highlighted:'<span class="hljs-meta">&gt;&gt;&gt; </span>tokenized_datasets.set_format(<span class="hljs-string">&quot;torch&quot;</span>)'}}),Za=new j({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>))`}}),Ua=new k({}),Ia=new j({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>)`}}),Ca=new j({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>)`}}),Ra=new k({}),Ga=new j({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>)`}}),Wa=new j({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>)`}}),Aa=new j({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 Ni({props:{$$slots:{default:[Pm]},$$scope:{ctx:oe}}}),Xa=new k({}),Na=new j({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>)`}}),Ba=new k({}),Va=new j({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()`}}),qa=new k({}),{c(){y=o("meta"),T=m(),w=o("h1"),$=o("a"),Z=o("span"),u(J.$$.fragment),G=m(),U=o("span"),E=i("Fine-tuning de um modelo pr\xE9-treinado"),M=m(),u(I.$$.fragment),W=m(),Ha=o("p"),Pr=i(`O uso de um modelo pr\xE9-treinado tem importantes vantagens. Redu\xE7\xE3o do custo computacional, a pegada de carbono, e te
permite utilizar modelos de \xFAltima gera\xE7\xE3o sem ter que treinar um novo desde o in\xEDcio.
O \u{1F917} Transformers proporciona acesso a milhares de modelos pr\xE9-treinados numa ampla gama de tarefas.
Quando utilizar um modelo pr\xE9-treinado, treine-o com um dataset espec\xEDfico para a sua tarefa.
Isto \xE9 chamado de fine-tuning, uma t\xE9cnica de treinamento incrivelmente poderosa. Neste tutorial faremos o fine-tuning
de um modelo pr\xE9-treinado com um framework de Deep Learning da sua escolha:`),Rt=m(),A=o("ul"),Fe=o("li"),xr=i("Fine-tuning de um modelo pr\xE9-treinado com o \u{1F917} Transformers "),ws=o("code"),Hr=i("Trainer"),Sr=i("."),Dr=m(),js=o("li"),Qr=i("Fine-tuning de um modelo pr\xE9-treinado no TensorFlow com o Keras."),Or=m(),Ms=o("li"),Lr=i("Fine-tuning de um modelo pr\xE9-treinado em PyTorch nativo."),zt=m(),Sa=o("a"),Gt=m(),V=o("h2"),re=o("a"),$s=o("span"),u(Ne.$$.fragment),Kr=m(),Js=o("span"),el=i("Preparando um dataset"),Wt=m(),u(Be.$$.fragment),At=m(),Da=o("p"),al=i(`Antes de aplicar o fine-tuning a um modelo pr\xE9-treinado, baixe um dataset e prepare-o para o treinamento.
O tutorial anterior ensinar\xE1 a processar os dados para o treinamento, e ent\xE3o poder\xE1 ter a oportunidade de testar
esse novo conhecimento em algo pr\xE1tico.`),Xt=m(),le=o("p"),sl=i("Comece carregando o dataset "),Ye=o("a"),tl=i("Yelp Reviews"),ol=i(":"),Ft=m(),u(Ve.$$.fragment),Nt=m(),ne=o("p"),rl=i(`Como j\xE1 sabe, \xE9 necess\xE1rio ter um tokenizador para processar o texto e incluir uma estrat\xE9gia de padding e truncamento,
para manejar qualquer tamanho var\xEDavel de sequ\xEAncia. Para processar o seu dataset em apenas um passo, utilize o m\xE9todo de
\u{1F917} Datasets `),qe=o("a"),Ts=o("code"),ll=i("map"),nl=i(` para aplicar uma fun\xE7\xE3o de preprocessamento sobre
todo o dataset.`),Bt=m(),u(Pe.$$.fragment),Yt=m(),Qa=o("p"),il=i("Se desejar, \xE9 poss\xEDvel criar um subconjunto menor do dataset completo para aplicar o fine-tuning e assim reduzir o tempo necess\xE1rio."),Vt=m(),u(xe.$$.fragment),qt=m(),Oa=o("a"),Pt=m(),q=o("h2"),ie=o("a"),_s=o("span"),u(He.$$.fragment),pl=m(),La=o("span"),ml=i("Fine-tuning com o "),Es=o("code"),cl=i("Trainer"),xt=m(),u(Se.$$.fragment),Ht=m(),X=o("p"),dl=i("O \u{1F917} Transformers proporciona uma classe "),ks=o("code"),ul=i("Trainer"),fl=i(` otimizada para o treinamento de modelos de \u{1F917} Transformers,
facilitando os primeiros passos do treinamento sem a necessidade de escrever manualmente o seu pr\xF3prio ciclo.
A API do `),Zs=o("code"),hl=i("Trainer"),gl=i(` suporta um grande conjunto de op\xE7\xF5es de treinamento e funcionalidades, como o logging,
o gradient accumulation e o mixed precision.`),St=m(),pe=o("p"),vl=i(`Comece carregando seu modelo e especifique o n\xFAmero de labels de previs\xE3o.
A partir do `),De=o("a"),bl=i("Card Dataset"),yl=i(` do Yelp Reveiw, que ja
sabemos ter 5 labels usamos o seguinte c\xF3digo:`),Dt=m(),u(Qe.$$.fragment),Qt=m(),u(me.$$.fragment),Ot=m(),P=o("h3"),ce=o("a"),Us=o("span"),u(Oe.$$.fragment),wl=m(),Is=o("span"),jl=i("Hiperpar\xE2metros de treinamento"),Lt=m(),F=o("p"),Ml=i("Em seguida, crie uma classe "),Cs=o("code"),$l=i("TrainingArguments"),Jl=i(` que contenha todos os hiperpar\xE2metros que possam ser ajustados, assim
como os indicadores para ativar as diferentes op\xE7\xF5es de treinamento. Para este tutorial, voc\xEA pode come\xE7ar o treinamento
usando os `),Le=o("a"),Tl=i("hiperpar\xE1metros"),_l=i(` padr\xE3o,
por\xE9m, sinta-se livre para experimentar com eles e encontrar uma configura\xE7\xE3o \xF3tima.`),Kt=m(),Ka=o("p"),El=i("Especifique onde salvar os checkpoints do treinamento:"),eo=m(),u(Ke.$$.fragment),ao=m(),x=o("h3"),de=o("a"),Rs=o("span"),u(ea.$$.fragment),kl=m(),zs=o("span"),Zl=i("M\xE9tricas"),so=m(),_=o("p"),Ul=i("O "),Gs=o("code"),Il=i("Trainer"),Cl=i(` n\xE3o avalia automaticamente o rendimento do modelo durante o treinamento. Ser\xE1 necess\xE1rio passar ao
`),Ws=o("code"),Rl=i("Trainer"),zl=i(` uma fun\xE7\xE3o para calcular e fazer um diagn\xF3stico sobre as m\xE9tricas. A biblioteca \u{1F917} Datasets proporciona
uma fun\xE7\xE3o de `),aa=o("a"),As=o("code"),Gl=i("accuracy"),Wl=i(` simples que pode ser carregada com a fun\xE7\xE3o
`),Xs=o("code"),Al=i("load_metric"),Xl=i(" (ver este "),sa=o("a"),Fl=i("tutorial"),Nl=i(" para mais informa\xE7\xF5es):"),to=m(),u(ta.$$.fragment),oo=m(),C=o("p"),Bl=i("Defina a fun\xE7\xE3o "),Fs=o("code"),Yl=i("compute"),Vl=i(" dentro de "),Ns=o("code"),ql=i("metric"),Pl=i(` para calcular a precis\xE3o das suas predi\xE7\xF5es.
Antes de passar as suas predi\xE7\xF5es ao `),Bs=o("code"),xl=i("compute"),Hl=i(`, \xE9 necess\xE1rio converter as predi\xE7\xF5es \xE0 logits (lembre-se que
todos os modelos de \u{1F917} Transformers retornam logits).`),ro=m(),u(oa.$$.fragment),lo=m(),ue=o("p"),Sl=i("Se quiser controlar as suas m\xE9tricas de avalia\xE7\xE3o durante o fine-tuning, especifique o par\xE2metro "),Ys=o("code"),Dl=i("evaluation_strategy"),Ql=i(`
nos seus argumentos de treinamento para que o modelo considere a m\xE9trica de avalia\xE7\xE3o ao final de cada \xE9poca:`),no=m(),u(ra.$$.fragment),io=m(),H=o("h3"),fe=o("a"),Vs=o("span"),u(la.$$.fragment),Ol=m(),qs=o("span"),Ll=i("Trainer"),po=m(),he=o("p"),Kl=i("Crie um objeto "),Ps=o("code"),en=i("Trainer"),an=i(" com o seu modelo, argumentos de treinamento, conjuntos de dados de treinamento e de teste, e a sua fun\xE7\xE3o de avalia\xE7\xE3o:"),mo=m(),u(na.$$.fragment),co=m(),ge=o("p"),sn=i("Em seguida, aplique o fine-tuning a seu modelo chamado "),xs=o("code"),tn=i("train()"),on=i(":"),uo=m(),u(ia.$$.fragment),fo=m(),es=o("a"),ho=m(),S=o("h2"),ve=o("a"),Hs=o("span"),u(pa.$$.fragment),rn=m(),Ss=o("span"),ln=i("Fine-tuning com Keras"),go=m(),u(ma.$$.fragment),vo=m(),as=o("p"),nn=i(`Os modelos de \u{1F917} Transformers tamb\xE9m permitem realizar o treinamento com o TensorFlow com a API do Keras.
Contudo, ser\xE1 necess\xE1rio fazer algumas mudan\xE7as antes de realizar o fine-tuning.`),bo=m(),D=o("h3"),be=o("a"),Ds=o("span"),u(ca.$$.fragment),pn=m(),Qs=o("span"),mn=i("Convers\xE3o do dataset ao formato do TensorFlow"),yo=m(),N=o("p"),cn=i("O "),Os=o("code"),dn=i("DefaultDataCollator"),un=i(` junta os tensores em um batch para que o modelo possa ser treinado em cima deles.
Assegure-se de especificar os `),Ls=o("code"),fn=i("return_tensors"),hn=i(" para retornar os tensores do TensorFlow:"),wo=m(),u(da.$$.fragment),jo=m(),u(ye.$$.fragment),Mo=m(),R=o("p"),gn=i(`Em seguida, converta os datasets tokenizados em datasets do TensorFlow com o m\xE9todo
`),ua=o("a"),Ks=o("code"),vn=i("to_tf_dataset"),bn=i(`.
Especifique suas entradas em `),et=o("code"),yn=i("columns"),wn=i(" e seu r\xF3tulo em "),at=o("code"),jn=i("label_cols"),Mn=i(":"),$o=m(),u(fa.$$.fragment),Jo=m(),Q=o("h3"),we=o("a"),st=o("span"),u(ha.$$.fragment),$n=m(),tt=o("span"),Jn=i("Compila\xE7\xE3o e ajustes"),To=m(),ss=o("p"),Tn=i("Carregue um modelo do TensorFlow com o n\xFAmero esperado de r\xF3tulos:"),_o=m(),u(ga.$$.fragment),Eo=m(),je=o("p"),_n=i("A seguir, compile e ajuste o fine-tuning a seu modelo com "),va=o("a"),ot=o("code"),En=i("fit"),kn=i(` como
faria com qualquer outro modelo do Keras:`),ko=m(),u(ba.$$.fragment),Zo=m(),ts=o("a"),Uo=m(),O=o("h2"),Me=o("a"),rt=o("span"),u(ya.$$.fragment),Zn=m(),lt=o("span"),Un=i("Fine-tune em PyTorch nativo"),Io=m(),u(wa.$$.fragment),Co=m(),$e=o("p"),In=i("O "),nt=o("code"),Cn=i("Trainer"),Rn=i(` se encarrega do ciclo de treinamento e permite aplicar o fine-tuning a um modelo em uma linha de c\xF3digo apenas.
Para os usu\xE1rios que preferirem escrever o seu pr\xF3prio ciclo de treinamento, tamb\xE9m \xE9 poss\xEDvel aplicar o fine-tuning a um
modelo de \u{1F917} Transformers em PyTorch nativo.`),Ro=m(),os=o("p"),zn=i(`Neste momento, talvez ocorra a necessidade de reinicar seu notebook ou executar a seguinte linha de c\xF3digo para liberar
mem\xF3ria:`),zo=m(),u(ja.$$.fragment),Go=m(),Je=o("p"),Gn=i("Em sequ\xEAncia, faremos um post-processing manual do "),it=o("code"),Wn=i("tokenized_dataset"),An=i(" e assim prepar\xE1-lo para o treinamento."),Wo=m(),B=o("ol"),Ma=o("li"),$a=o("p"),Xn=i("Apague a coluna de "),pt=o("code"),Fn=i("text"),Nn=i(" porque o modelo n\xE3o aceita texto cru como entrada:"),Bn=m(),u(Ja.$$.fragment),Yn=m(),Ta=o("li"),L=o("p"),Vn=i("Troque o nome da coluna "),mt=o("code"),qn=i("label"),Pn=i(" para "),ct=o("code"),xn=i("labels"),Hn=i(", pois o modelo espera um argumento de mesmo nome:"),Sn=m(),u(_a.$$.fragment),Dn=m(),Ea=o("li"),dt=o("p"),Qn=i("Defina o formato do dataset para retornar tensores do PyTorch no lugar de listas:"),On=m(),u(ka.$$.fragment),Ao=m(),rs=o("p"),Ln=i("Em sequ\xEAncia, crie um subconjunto menor do dataset, como foi mostrado anteriormente, para aceler\xE1-lo o fine-tuning."),Xo=m(),u(Za.$$.fragment),Fo=m(),K=o("h3"),Te=o("a"),ut=o("span"),u(Ua.$$.fragment),Kn=m(),ft=o("span"),ei=i("DataLoader"),No=m(),_e=o("p"),ai=i("Crie um "),ht=o("code"),si=i("DataLoader"),ti=i(" para os seus datasets de treinamento e de teste para poder iterar sobre batches de dados:"),Bo=m(),u(Ia.$$.fragment),Yo=m(),ls=o("p"),oi=i("Carregue seu modelo com o n\xFAmero de labels esperados:"),Vo=m(),u(Ca.$$.fragment),qo=m(),ee=o("h3"),Ee=o("a"),gt=o("span"),u(Ra.$$.fragment),ri=m(),vt=o("span"),li=i("Otimiza\xE7\xE3o e configura\xE7\xE3o do Learning Rate"),Po=m(),ke=o("p"),ni=i(`Crie um otimizador e um learning rate para aplicar o fine-tuning ao modelo.
Iremos utilizar o otimizador `),za=o("a"),bt=o("code"),ii=i("AdamW"),pi=i(" do PyTorch:"),xo=m(),u(Ga.$$.fragment),Ho=m(),Ze=o("p"),mi=i("Defina o learning rate do "),yt=o("code"),ci=i("Trainer"),di=i(":"),So=m(),u(Wa.$$.fragment),Do=m(),Ue=o("p"),ui=i("Por \xFAltimo, especifique o "),wt=o("code"),fi=i("device"),hi=i(` do ambiente para utilizar uma GPU se tiver acesso \xE0 alguma. Caso contr\xE1rio, o treinamento
em uma CPU pode acabar levando v\xE1rias horas em vez de minutos.`),Qo=m(),u(Aa.$$.fragment),Oo=m(),u(Ie.$$.fragment),Lo=m(),ns=o("p"),gi=i("Perfeito, agora estamos prontos para come\xE7ar o treinamento! \u{1F973}"),Ko=m(),ae=o("h3"),Ce=o("a"),jt=o("span"),u(Xa.$$.fragment),vi=m(),Mt=o("span"),bi=i("Ciclo de treinamento"),er=m(),Re=o("p"),yi=i("Para visualizar melhor o processo de treinamento, utilize a biblioteca "),Fa=o("a"),wi=i("tqdm"),ji=i(` para adicionar
uma barra de progresso sobre o n\xFAmero de passos percorridos no treinamento atual:`),ar=m(),u(Na.$$.fragment),sr=m(),se=o("h3"),ze=o("a"),$t=o("span"),u(Ba.$$.fragment),Mi=m(),Jt=o("span"),$i=i("M\xE9tricas"),tr=m(),Y=o("p"),Ji=i("Da mesma forma que \xE9 necess\xE1rio adicionar uma fun\xE7\xE3o de avalia\xE7\xE3o ao "),Tt=o("code"),Ti=i("Trainer"),_i=i(`, \xE9 necess\xE1rio fazer o mesmo quando
escrevendo o pr\xF3prio ciclo de treinamento. Contudo, em vez de calcular e retornar a m\xE9trica final de cada \xE9poca,
voc\xEA dever\xE1 adicionar todos os batches com `),Ya=o("a"),_t=o("code"),Ei=i("add_batch"),ki=i(`
e calcular a m\xE9trica apenas no final.`),or=m(),u(Va.$$.fragment),rr=m(),is=o("a"),lr=m(),te=o("h2"),Ge=o("a"),Et=o("span"),u(qa.$$.fragment),Zi=m(),kt=o("span"),Ui=i("Recursos adicionais"),nr=m(),ps=o("p"),Ii=i("Para mais exemplos de fine-tuning acesse:"),ir=m(),We=o("ul"),Zt=o("li"),ms=o("p"),Pa=o("a"),Ci=i("\u{1F917} Transformers Examples"),Ri=i(` inclui scripts
para treinas tarefas comuns de NLP em PyTorch e TensorFlow.`),zi=m(),Ut=o("li"),cs=o("p"),ds=o("a"),Gi=i("\u{1F917} Transformers Notebooks"),Wi=i(` cont\xE9m v\xE1rios notebooks sobre como aplicar o fine-tuning a um modelo
para tarefas espec\xEDficas no PyTorch e TensorFlow.`),this.h()},l(e){const t=Nm('[data-svelte="svelte-1phssyn"]',document.head);y=r(t,"META",{name:!0,content:!0}),t.forEach(a),T=c(e),w=r(e,"H1",{class:!0});var xa=l(w);$=r(xa,"A",{id:!0,class:!0,href:!0});var It=l($);Z=r(It,"SPAN",{});var Ct=l(Z);f(J.$$.fragment,Ct),Ct.forEach(a),It.forEach(a),G=c(xa),U=r(xa,"SPAN",{});var Bi=l(U);E=p(Bi,"Fine-tuning de um modelo pr\xE9-treinado"),Bi.forEach(a),xa.forEach(a),M=c(e),f(I.$$.fragment,e),W=c(e),Ha=r(e,"P",{});var Yi=l(Ha);Pr=p(Yi,`O uso de um modelo pr\xE9-treinado tem importantes vantagens. Redu\xE7\xE3o do custo computacional, a pegada de carbono, e te
permite utilizar modelos de \xFAltima gera\xE7\xE3o sem ter que treinar um novo desde o in\xEDcio.
O \u{1F917} Transformers proporciona acesso a milhares de modelos pr\xE9-treinados numa ampla gama de tarefas.
Quando utilizar um modelo pr\xE9-treinado, treine-o com um dataset espec\xEDfico para a sua tarefa.
Isto \xE9 chamado de fine-tuning, uma t\xE9cnica de treinamento incrivelmente poderosa. Neste tutorial faremos o fine-tuning
de um modelo pr\xE9-treinado com um framework de Deep Learning da sua escolha:`),Yi.forEach(a),Rt=c(e),A=r(e,"UL",{});var us=l(A);Fe=r(us,"LI",{});var mr=l(Fe);xr=p(mr,"Fine-tuning de um modelo pr\xE9-treinado com o \u{1F917} Transformers "),ws=r(mr,"CODE",{});var Vi=l(ws);Hr=p(Vi,"Trainer"),Vi.forEach(a),Sr=p(mr,"."),mr.forEach(a),Dr=c(us),js=r(us,"LI",{});var qi=l(js);Qr=p(qi,"Fine-tuning de um modelo pr\xE9-treinado no TensorFlow com o Keras."),qi.forEach(a),Or=c(us),Ms=r(us,"LI",{});var Pi=l(Ms);Lr=p(Pi,"Fine-tuning de um modelo pr\xE9-treinado em PyTorch nativo."),Pi.forEach(a),us.forEach(a),zt=c(e),Sa=r(e,"A",{id:!0}),l(Sa).forEach(a),Gt=c(e),V=r(e,"H2",{class:!0});var cr=l(V);re=r(cr,"A",{id:!0,class:!0,href:!0});var xi=l(re);$s=r(xi,"SPAN",{});var Hi=l($s);f(Ne.$$.fragment,Hi),Hi.forEach(a),xi.forEach(a),Kr=c(cr),Js=r(cr,"SPAN",{});var Si=l(Js);el=p(Si,"Preparando um dataset"),Si.forEach(a),cr.forEach(a),Wt=c(e),f(Be.$$.fragment,e),At=c(e),Da=r(e,"P",{});var Di=l(Da);al=p(Di,`Antes de aplicar o fine-tuning a um modelo pr\xE9-treinado, baixe um dataset e prepare-o para o treinamento.
O tutorial anterior ensinar\xE1 a processar os dados para o treinamento, e ent\xE3o poder\xE1 ter a oportunidade de testar
esse novo conhecimento em algo pr\xE1tico.`),Di.forEach(a),Xt=c(e),le=r(e,"P",{});var dr=l(le);sl=p(dr,"Comece carregando o dataset "),Ye=r(dr,"A",{href:!0,rel:!0});var Qi=l(Ye);tl=p(Qi,"Yelp Reviews"),Qi.forEach(a),ol=p(dr,":"),dr.forEach(a),Ft=c(e),f(Ve.$$.fragment,e),Nt=c(e),ne=r(e,"P",{});var ur=l(ne);rl=p(ur,`Como j\xE1 sabe, \xE9 necess\xE1rio ter um tokenizador para processar o texto e incluir uma estrat\xE9gia de padding e truncamento,
para manejar qualquer tamanho var\xEDavel de sequ\xEAncia. Para processar o seu dataset em apenas um passo, utilize o m\xE9todo de
\u{1F917} Datasets `),qe=r(ur,"A",{href:!0,rel:!0});var Oi=l(qe);Ts=r(Oi,"CODE",{});var Li=l(Ts);ll=p(Li,"map"),Li.forEach(a),Oi.forEach(a),nl=p(ur,` para aplicar uma fun\xE7\xE3o de preprocessamento sobre
todo o dataset.`),ur.forEach(a),Bt=c(e),f(Pe.$$.fragment,e),Yt=c(e),Qa=r(e,"P",{});var Ki=l(Qa);il=p(Ki,"Se desejar, \xE9 poss\xEDvel criar um subconjunto menor do dataset completo para aplicar o fine-tuning e assim reduzir o tempo necess\xE1rio."),Ki.forEach(a),Vt=c(e),f(xe.$$.fragment,e),qt=c(e),Oa=r(e,"A",{id:!0}),l(Oa).forEach(a),Pt=c(e),q=r(e,"H2",{class:!0});var fr=l(q);ie=r(fr,"A",{id:!0,class:!0,href:!0});var ep=l(ie);_s=r(ep,"SPAN",{});var ap=l(_s);f(He.$$.fragment,ap),ap.forEach(a),ep.forEach(a),pl=c(fr),La=r(fr,"SPAN",{});var Ai=l(La);ml=p(Ai,"Fine-tuning com o "),Es=r(Ai,"CODE",{});var sp=l(Es);cl=p(sp,"Trainer"),sp.forEach(a),Ai.forEach(a),fr.forEach(a),xt=c(e),f(Se.$$.fragment,e),Ht=c(e),X=r(e,"P",{});var fs=l(X);dl=p(fs,"O \u{1F917} Transformers proporciona uma classe "),ks=r(fs,"CODE",{});var tp=l(ks);ul=p(tp,"Trainer"),tp.forEach(a),fl=p(fs,` otimizada para o treinamento de modelos de \u{1F917} Transformers,
facilitando os primeiros passos do treinamento sem a necessidade de escrever manualmente o seu pr\xF3prio ciclo.
A API do `),Zs=r(fs,"CODE",{});var op=l(Zs);hl=p(op,"Trainer"),op.forEach(a),gl=p(fs,` suporta um grande conjunto de op\xE7\xF5es de treinamento e funcionalidades, como o logging,
o gradient accumulation e o mixed precision.`),fs.forEach(a),St=c(e),pe=r(e,"P",{});var hr=l(pe);vl=p(hr,`Comece carregando seu modelo e especifique o n\xFAmero de labels de previs\xE3o.
A partir do `),De=r(hr,"A",{href:!0,rel:!0});var rp=l(De);bl=p(rp,"Card Dataset"),rp.forEach(a),yl=p(hr,` do Yelp Reveiw, que ja
sabemos ter 5 labels usamos o seguinte c\xF3digo:`),hr.forEach(a),Dt=c(e),f(Qe.$$.fragment,e),Qt=c(e),f(me.$$.fragment,e),Ot=c(e),P=r(e,"H3",{class:!0});var gr=l(P);ce=r(gr,"A",{id:!0,class:!0,href:!0});var lp=l(ce);Us=r(lp,"SPAN",{});var np=l(Us);f(Oe.$$.fragment,np),np.forEach(a),lp.forEach(a),wl=c(gr),Is=r(gr,"SPAN",{});var ip=l(Is);jl=p(ip,"Hiperpar\xE2metros de treinamento"),ip.forEach(a),gr.forEach(a),Lt=c(e),F=r(e,"P",{});var hs=l(F);Ml=p(hs,"Em seguida, crie uma classe "),Cs=r(hs,"CODE",{});var pp=l(Cs);$l=p(pp,"TrainingArguments"),pp.forEach(a),Jl=p(hs,` que contenha todos os hiperpar\xE2metros que possam ser ajustados, assim
como os indicadores para ativar as diferentes op\xE7\xF5es de treinamento. Para este tutorial, voc\xEA pode come\xE7ar o treinamento
usando os `),Le=r(hs,"A",{href:!0,rel:!0});var mp=l(Le);Tl=p(mp,"hiperpar\xE1metros"),mp.forEach(a),_l=p(hs,` padr\xE3o,
por\xE9m, sinta-se livre para experimentar com eles e encontrar uma configura\xE7\xE3o \xF3tima.`),hs.forEach(a),Kt=c(e),Ka=r(e,"P",{});var cp=l(Ka);El=p(cp,"Especifique onde salvar os checkpoints do treinamento:"),cp.forEach(a),eo=c(e),f(Ke.$$.fragment,e),ao=c(e),x=r(e,"H3",{class:!0});var vr=l(x);de=r(vr,"A",{id:!0,class:!0,href:!0});var dp=l(de);Rs=r(dp,"SPAN",{});var up=l(Rs);f(ea.$$.fragment,up),up.forEach(a),dp.forEach(a),kl=c(vr),zs=r(vr,"SPAN",{});var fp=l(zs);Zl=p(fp,"M\xE9tricas"),fp.forEach(a),vr.forEach(a),so=c(e),_=r(e,"P",{});var z=l(_);Ul=p(z,"O "),Gs=r(z,"CODE",{});var hp=l(Gs);Il=p(hp,"Trainer"),hp.forEach(a),Cl=p(z,` n\xE3o avalia automaticamente o rendimento do modelo durante o treinamento. Ser\xE1 necess\xE1rio passar ao
`),Ws=r(z,"CODE",{});var gp=l(Ws);Rl=p(gp,"Trainer"),gp.forEach(a),zl=p(z,` uma fun\xE7\xE3o para calcular e fazer um diagn\xF3stico sobre as m\xE9tricas. A biblioteca \u{1F917} Datasets proporciona
uma fun\xE7\xE3o de `),aa=r(z,"A",{href:!0,rel:!0});var vp=l(aa);As=r(vp,"CODE",{});var bp=l(As);Gl=p(bp,"accuracy"),bp.forEach(a),vp.forEach(a),Wl=p(z,` simples que pode ser carregada com a fun\xE7\xE3o
`),Xs=r(z,"CODE",{});var yp=l(Xs);Al=p(yp,"load_metric"),yp.forEach(a),Xl=p(z," (ver este "),sa=r(z,"A",{href:!0,rel:!0});var wp=l(sa);Fl=p(wp,"tutorial"),wp.forEach(a),Nl=p(z," para mais informa\xE7\xF5es):"),z.forEach(a),to=c(e),f(ta.$$.fragment,e),oo=c(e),C=r(e,"P",{});var Ae=l(C);Bl=p(Ae,"Defina a fun\xE7\xE3o "),Fs=r(Ae,"CODE",{});var jp=l(Fs);Yl=p(jp,"compute"),jp.forEach(a),Vl=p(Ae," dentro de "),Ns=r(Ae,"CODE",{});var Mp=l(Ns);ql=p(Mp,"metric"),Mp.forEach(a),Pl=p(Ae,` para calcular a precis\xE3o das suas predi\xE7\xF5es.
Antes de passar as suas predi\xE7\xF5es ao `),Bs=r(Ae,"CODE",{});var $p=l(Bs);xl=p($p,"compute"),$p.forEach(a),Hl=p(Ae,`, \xE9 necess\xE1rio converter as predi\xE7\xF5es \xE0 logits (lembre-se que
todos os modelos de \u{1F917} Transformers retornam logits).`),Ae.forEach(a),ro=c(e),f(oa.$$.fragment,e),lo=c(e),ue=r(e,"P",{});var br=l(ue);Sl=p(br,"Se quiser controlar as suas m\xE9tricas de avalia\xE7\xE3o durante o fine-tuning, especifique o par\xE2metro "),Ys=r(br,"CODE",{});var Jp=l(Ys);Dl=p(Jp,"evaluation_strategy"),Jp.forEach(a),Ql=p(br,`
nos seus argumentos de treinamento para que o modelo considere a m\xE9trica de avalia\xE7\xE3o ao final de cada \xE9poca:`),br.forEach(a),no=c(e),f(ra.$$.fragment,e),io=c(e),H=r(e,"H3",{class:!0});var yr=l(H);fe=r(yr,"A",{id:!0,class:!0,href:!0});var Tp=l(fe);Vs=r(Tp,"SPAN",{});var _p=l(Vs);f(la.$$.fragment,_p),_p.forEach(a),Tp.forEach(a),Ol=c(yr),qs=r(yr,"SPAN",{});var Ep=l(qs);Ll=p(Ep,"Trainer"),Ep.forEach(a),yr.forEach(a),po=c(e),he=r(e,"P",{});var wr=l(he);Kl=p(wr,"Crie um objeto "),Ps=r(wr,"CODE",{});var kp=l(Ps);en=p(kp,"Trainer"),kp.forEach(a),an=p(wr," com o seu modelo, argumentos de treinamento, conjuntos de dados de treinamento e de teste, e a sua fun\xE7\xE3o de avalia\xE7\xE3o:"),wr.forEach(a),mo=c(e),f(na.$$.fragment,e),co=c(e),ge=r(e,"P",{});var jr=l(ge);sn=p(jr,"Em seguida, aplique o fine-tuning a seu modelo chamado "),xs=r(jr,"CODE",{});var Zp=l(xs);tn=p(Zp,"train()"),Zp.forEach(a),on=p(jr,":"),jr.forEach(a),uo=c(e),f(ia.$$.fragment,e),fo=c(e),es=r(e,"A",{id:!0}),l(es).forEach(a),ho=c(e),S=r(e,"H2",{class:!0});var Mr=l(S);ve=r(Mr,"A",{id:!0,class:!0,href:!0});var Up=l(ve);Hs=r(Up,"SPAN",{});var Ip=l(Hs);f(pa.$$.fragment,Ip),Ip.forEach(a),Up.forEach(a),rn=c(Mr),Ss=r(Mr,"SPAN",{});var Cp=l(Ss);ln=p(Cp,"Fine-tuning com Keras"),Cp.forEach(a),Mr.forEach(a),go=c(e),f(ma.$$.fragment,e),vo=c(e),as=r(e,"P",{});var Rp=l(as);nn=p(Rp,`Os modelos de \u{1F917} Transformers tamb\xE9m permitem realizar o treinamento com o TensorFlow com a API do Keras.
Contudo, ser\xE1 necess\xE1rio fazer algumas mudan\xE7as antes de realizar o fine-tuning.`),Rp.forEach(a),bo=c(e),D=r(e,"H3",{class:!0});var $r=l(D);be=r($r,"A",{id:!0,class:!0,href:!0});var zp=l(be);Ds=r(zp,"SPAN",{});var Gp=l(Ds);f(ca.$$.fragment,Gp),Gp.forEach(a),zp.forEach(a),pn=c($r),Qs=r($r,"SPAN",{});var Wp=l(Qs);mn=p(Wp,"Convers\xE3o do dataset ao formato do TensorFlow"),Wp.forEach(a),$r.forEach(a),yo=c(e),N=r(e,"P",{});var gs=l(N);cn=p(gs,"O "),Os=r(gs,"CODE",{});var Ap=l(Os);dn=p(Ap,"DefaultDataCollator"),Ap.forEach(a),un=p(gs,` junta os tensores em um batch para que o modelo possa ser treinado em cima deles.
Assegure-se de especificar os `),Ls=r(gs,"CODE",{});var Xp=l(Ls);fn=p(Xp,"return_tensors"),Xp.forEach(a),hn=p(gs," para retornar os tensores do TensorFlow:"),gs.forEach(a),wo=c(e),f(da.$$.fragment,e),jo=c(e),f(ye.$$.fragment,e),Mo=c(e),R=r(e,"P",{});var Xe=l(R);gn=p(Xe,`Em seguida, converta os datasets tokenizados em datasets do TensorFlow com o m\xE9todo
`),ua=r(Xe,"A",{href:!0,rel:!0});var Fp=l(ua);Ks=r(Fp,"CODE",{});var Np=l(Ks);vn=p(Np,"to_tf_dataset"),Np.forEach(a),Fp.forEach(a),bn=p(Xe,`.
Especifique suas entradas em `),et=r(Xe,"CODE",{});var Bp=l(et);yn=p(Bp,"columns"),Bp.forEach(a),wn=p(Xe," e seu r\xF3tulo em "),at=r(Xe,"CODE",{});var Yp=l(at);jn=p(Yp,"label_cols"),Yp.forEach(a),Mn=p(Xe,":"),Xe.forEach(a),$o=c(e),f(fa.$$.fragment,e),Jo=c(e),Q=r(e,"H3",{class:!0});var Jr=l(Q);we=r(Jr,"A",{id:!0,class:!0,href:!0});var Vp=l(we);st=r(Vp,"SPAN",{});var qp=l(st);f(ha.$$.fragment,qp),qp.forEach(a),Vp.forEach(a),$n=c(Jr),tt=r(Jr,"SPAN",{});var Pp=l(tt);Jn=p(Pp,"Compila\xE7\xE3o e ajustes"),Pp.forEach(a),Jr.forEach(a),To=c(e),ss=r(e,"P",{});var xp=l(ss);Tn=p(xp,"Carregue um modelo do TensorFlow com o n\xFAmero esperado de r\xF3tulos:"),xp.forEach(a),_o=c(e),f(ga.$$.fragment,e),Eo=c(e),je=r(e,"P",{});var Tr=l(je);_n=p(Tr,"A seguir, compile e ajuste o fine-tuning a seu modelo com "),va=r(Tr,"A",{href:!0,rel:!0});var Hp=l(va);ot=r(Hp,"CODE",{});var Sp=l(ot);En=p(Sp,"fit"),Sp.forEach(a),Hp.forEach(a),kn=p(Tr,` como
faria com qualquer outro modelo do Keras:`),Tr.forEach(a),ko=c(e),f(ba.$$.fragment,e),Zo=c(e),ts=r(e,"A",{id:!0}),l(ts).forEach(a),Uo=c(e),O=r(e,"H2",{class:!0});var _r=l(O);Me=r(_r,"A",{id:!0,class:!0,href:!0});var Dp=l(Me);rt=r(Dp,"SPAN",{});var Qp=l(rt);f(ya.$$.fragment,Qp),Qp.forEach(a),Dp.forEach(a),Zn=c(_r),lt=r(_r,"SPAN",{});var Op=l(lt);Un=p(Op,"Fine-tune em PyTorch nativo"),Op.forEach(a),_r.forEach(a),Io=c(e),f(wa.$$.fragment,e),Co=c(e),$e=r(e,"P",{});var Er=l($e);In=p(Er,"O "),nt=r(Er,"CODE",{});var Lp=l(nt);Cn=p(Lp,"Trainer"),Lp.forEach(a),Rn=p(Er,` se encarrega do ciclo de treinamento e permite aplicar o fine-tuning a um modelo em uma linha de c\xF3digo apenas.
Para os usu\xE1rios que preferirem escrever o seu pr\xF3prio ciclo de treinamento, tamb\xE9m \xE9 poss\xEDvel aplicar o fine-tuning a um
modelo de \u{1F917} Transformers em PyTorch nativo.`),Er.forEach(a),Ro=c(e),os=r(e,"P",{});var Kp=l(os);zn=p(Kp,`Neste momento, talvez ocorra a necessidade de reinicar seu notebook ou executar a seguinte linha de c\xF3digo para liberar
mem\xF3ria:`),Kp.forEach(a),zo=c(e),f(ja.$$.fragment,e),Go=c(e),Je=r(e,"P",{});var kr=l(Je);Gn=p(kr,"Em sequ\xEAncia, faremos um post-processing manual do "),it=r(kr,"CODE",{});var em=l(it);Wn=p(em,"tokenized_dataset"),em.forEach(a),An=p(kr," e assim prepar\xE1-lo para o treinamento."),kr.forEach(a),Wo=c(e),B=r(e,"OL",{});var vs=l(B);Ma=r(vs,"LI",{});var Zr=l(Ma);$a=r(Zr,"P",{});var Ur=l($a);Xn=p(Ur,"Apague a coluna de "),pt=r(Ur,"CODE",{});var am=l(pt);Fn=p(am,"text"),am.forEach(a),Nn=p(Ur," porque o modelo n\xE3o aceita texto cru como entrada:"),Ur.forEach(a),Bn=c(Zr),f(Ja.$$.fragment,Zr),Zr.forEach(a),Yn=c(vs),Ta=r(vs,"LI",{});var Ir=l(Ta);L=r(Ir,"P",{});var bs=l(L);Vn=p(bs,"Troque o nome da coluna "),mt=r(bs,"CODE",{});var sm=l(mt);qn=p(sm,"label"),sm.forEach(a),Pn=p(bs," para "),ct=r(bs,"CODE",{});var tm=l(ct);xn=p(tm,"labels"),tm.forEach(a),Hn=p(bs,", pois o modelo espera um argumento de mesmo nome:"),bs.forEach(a),Sn=c(Ir),f(_a.$$.fragment,Ir),Ir.forEach(a),Dn=c(vs),Ea=r(vs,"LI",{});var Cr=l(Ea);dt=r(Cr,"P",{});var om=l(dt);Qn=p(om,"Defina o formato do dataset para retornar tensores do PyTorch no lugar de listas:"),om.forEach(a),On=c(Cr),f(ka.$$.fragment,Cr),Cr.forEach(a),vs.forEach(a),Ao=c(e),rs=r(e,"P",{});var rm=l(rs);Ln=p(rm,"Em sequ\xEAncia, crie um subconjunto menor do dataset, como foi mostrado anteriormente, para aceler\xE1-lo o fine-tuning."),rm.forEach(a),Xo=c(e),f(Za.$$.fragment,e),Fo=c(e),K=r(e,"H3",{class:!0});var Rr=l(K);Te=r(Rr,"A",{id:!0,class:!0,href:!0});var lm=l(Te);ut=r(lm,"SPAN",{});var nm=l(ut);f(Ua.$$.fragment,nm),nm.forEach(a),lm.forEach(a),Kn=c(Rr),ft=r(Rr,"SPAN",{});var im=l(ft);ei=p(im,"DataLoader"),im.forEach(a),Rr.forEach(a),No=c(e),_e=r(e,"P",{});var zr=l(_e);ai=p(zr,"Crie um "),ht=r(zr,"CODE",{});var pm=l(ht);si=p(pm,"DataLoader"),pm.forEach(a),ti=p(zr," para os seus datasets de treinamento e de teste para poder iterar sobre batches de dados:"),zr.forEach(a),Bo=c(e),f(Ia.$$.fragment,e),Yo=c(e),ls=r(e,"P",{});var mm=l(ls);oi=p(mm,"Carregue seu modelo com o n\xFAmero de labels esperados:"),mm.forEach(a),Vo=c(e),f(Ca.$$.fragment,e),qo=c(e),ee=r(e,"H3",{class:!0});var Gr=l(ee);Ee=r(Gr,"A",{id:!0,class:!0,href:!0});var cm=l(Ee);gt=r(cm,"SPAN",{});var dm=l(gt);f(Ra.$$.fragment,dm),dm.forEach(a),cm.forEach(a),ri=c(Gr),vt=r(Gr,"SPAN",{});var um=l(vt);li=p(um,"Otimiza\xE7\xE3o e configura\xE7\xE3o do Learning Rate"),um.forEach(a),Gr.forEach(a),Po=c(e),ke=r(e,"P",{});var Wr=l(ke);ni=p(Wr,`Crie um otimizador e um learning rate para aplicar o fine-tuning ao modelo.
Iremos utilizar o otimizador `),za=r(Wr,"A",{href:!0,rel:!0});var fm=l(za);bt=r(fm,"CODE",{});var hm=l(bt);ii=p(hm,"AdamW"),hm.forEach(a),fm.forEach(a),pi=p(Wr," do PyTorch:"),Wr.forEach(a),xo=c(e),f(Ga.$$.fragment,e),Ho=c(e),Ze=r(e,"P",{});var Ar=l(Ze);mi=p(Ar,"Defina o learning rate do "),yt=r(Ar,"CODE",{});var gm=l(yt);ci=p(gm,"Trainer"),gm.forEach(a),di=p(Ar,":"),Ar.forEach(a),So=c(e),f(Wa.$$.fragment,e),Do=c(e),Ue=r(e,"P",{});var Xr=l(Ue);ui=p(Xr,"Por \xFAltimo, especifique o "),wt=r(Xr,"CODE",{});var vm=l(wt);fi=p(vm,"device"),vm.forEach(a),hi=p(Xr,` do ambiente para utilizar uma GPU se tiver acesso \xE0 alguma. Caso contr\xE1rio, o treinamento
em uma CPU pode acabar levando v\xE1rias horas em vez de minutos.`),Xr.forEach(a),Qo=c(e),f(Aa.$$.fragment,e),Oo=c(e),f(Ie.$$.fragment,e),Lo=c(e),ns=r(e,"P",{});var bm=l(ns);gi=p(bm,"Perfeito, agora estamos prontos para come\xE7ar o treinamento! \u{1F973}"),bm.forEach(a),Ko=c(e),ae=r(e,"H3",{class:!0});var Fr=l(ae);Ce=r(Fr,"A",{id:!0,class:!0,href:!0});var ym=l(Ce);jt=r(ym,"SPAN",{});var wm=l(jt);f(Xa.$$.fragment,wm),wm.forEach(a),ym.forEach(a),vi=c(Fr),Mt=r(Fr,"SPAN",{});var jm=l(Mt);bi=p(jm,"Ciclo de treinamento"),jm.forEach(a),Fr.forEach(a),er=c(e),Re=r(e,"P",{});var Nr=l(Re);yi=p(Nr,"Para visualizar melhor o processo de treinamento, utilize a biblioteca "),Fa=r(Nr,"A",{href:!0,rel:!0});var Mm=l(Fa);wi=p(Mm,"tqdm"),Mm.forEach(a),ji=p(Nr,` para adicionar
uma barra de progresso sobre o n\xFAmero de passos percorridos no treinamento atual:`),Nr.forEach(a),ar=c(e),f(Na.$$.fragment,e),sr=c(e),se=r(e,"H3",{class:!0});var Br=l(se);ze=r(Br,"A",{id:!0,class:!0,href:!0});var $m=l(ze);$t=r($m,"SPAN",{});var Jm=l($t);f(Ba.$$.fragment,Jm),Jm.forEach(a),$m.forEach(a),Mi=c(Br),Jt=r(Br,"SPAN",{});var Tm=l(Jt);$i=p(Tm,"M\xE9tricas"),Tm.forEach(a),Br.forEach(a),tr=c(e),Y=r(e,"P",{});var ys=l(Y);Ji=p(ys,"Da mesma forma que \xE9 necess\xE1rio adicionar uma fun\xE7\xE3o de avalia\xE7\xE3o ao "),Tt=r(ys,"CODE",{});var _m=l(Tt);Ti=p(_m,"Trainer"),_m.forEach(a),_i=p(ys,`, \xE9 necess\xE1rio fazer o mesmo quando
escrevendo o pr\xF3prio ciclo de treinamento. Contudo, em vez de calcular e retornar a m\xE9trica final de cada \xE9poca,
voc\xEA dever\xE1 adicionar todos os batches com `),Ya=r(ys,"A",{href:!0,rel:!0});var Em=l(Ya);_t=r(Em,"CODE",{});var km=l(_t);Ei=p(km,"add_batch"),km.forEach(a),Em.forEach(a),ki=p(ys,`
e calcular a m\xE9trica apenas no final.`),ys.forEach(a),or=c(e),f(Va.$$.fragment,e),rr=c(e),is=r(e,"A",{id:!0}),l(is).forEach(a),lr=c(e),te=r(e,"H2",{class:!0});var Yr=l(te);Ge=r(Yr,"A",{id:!0,class:!0,href:!0});var Zm=l(Ge);Et=r(Zm,"SPAN",{});var Um=l(Et);f(qa.$$.fragment,Um),Um.forEach(a),Zm.forEach(a),Zi=c(Yr),kt=r(Yr,"SPAN",{});var Im=l(kt);Ui=p(Im,"Recursos adicionais"),Im.forEach(a),Yr.forEach(a),nr=c(e),ps=r(e,"P",{});var Cm=l(ps);Ii=p(Cm,"Para mais exemplos de fine-tuning acesse:"),Cm.forEach(a),ir=c(e),We=r(e,"UL",{});var Vr=l(We);Zt=r(Vr,"LI",{});var Rm=l(Zt);ms=r(Rm,"P",{});var Xi=l(ms);Pa=r(Xi,"A",{href:!0,rel:!0});var zm=l(Pa);Ci=p(zm,"\u{1F917} Transformers Examples"),zm.forEach(a),Ri=p(Xi,` inclui scripts
para treinas tarefas comuns de NLP em PyTorch e TensorFlow.`),Xi.forEach(a),Rm.forEach(a),zi=c(Vr),Ut=r(Vr,"LI",{});var Gm=l(Ut);cs=r(Gm,"P",{});var Fi=l(cs);ds=r(Fi,"A",{href:!0});var Wm=l(ds);Gi=p(Wm,"\u{1F917} Transformers Notebooks"),Wm.forEach(a),Wi=p(Fi,` cont\xE9m v\xE1rios notebooks sobre como aplicar o fine-tuning a um modelo
para tarefas espec\xEDficas no PyTorch e TensorFlow.`),Fi.forEach(a),Gm.forEach(a),Vr.forEach(a),this.h()},h(){d(y,"name","hf:doc:metadata"),d(y,"content",JSON.stringify(Hm)),d($,"id","finetuning-de-um-modelo-prtreinado"),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"),d($,"href","#finetuning-de-um-modelo-prtreinado"),d(w,"class","relative group"),d(Sa,"id","data-processing"),d(re,"id","preparando-um-dataset"),d(re,"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"),d(re,"href","#preparando-um-dataset"),d(V,"class","relative group"),d(Ye,"href","https://huggingface.co/datasets/yelp_review_full"),d(Ye,"rel","nofollow"),d(qe,"href","https://huggingface.co/docs/datasets/process.html#map"),d(qe,"rel","nofollow"),d(Oa,"id","trainer"),d(ie,"id","finetuning-com-o-trainer"),d(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"),d(ie,"href","#finetuning-com-o-trainer"),d(q,"class","relative group"),d(De,"href","https://huggingface.co/datasets/yelp_review_full#data-fields"),d(De,"rel","nofollow"),d(ce,"id","hiperparmetros-de-treinamento"),d(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"),d(ce,"href","#hiperparmetros-de-treinamento"),d(P,"class","relative group"),d(Le,"href","https://huggingface.co/docs/transformers/main_classes/trainer#transformers.TrainingArguments"),d(Le,"rel","nofollow"),d(de,"id","mtricas"),d(de,"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"),d(de,"href","#mtricas"),d(x,"class","relative group"),d(aa,"href","https://huggingface.co/metrics/accuracy"),d(aa,"rel","nofollow"),d(sa,"href","https://huggingface.co/docs/datasets/metrics.html"),d(sa,"rel","nofollow"),d(fe,"id","trainer"),d(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"),d(fe,"href","#trainer"),d(H,"class","relative group"),d(es,"id","keras"),d(ve,"id","finetuning-com-keras"),d(ve,"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"),d(ve,"href","#finetuning-com-keras"),d(S,"class","relative group"),d(be,"id","converso-do-dataset-ao-formato-do-tensorflow"),d(be,"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"),d(be,"href","#converso-do-dataset-ao-formato-do-tensorflow"),d(D,"class","relative group"),d(ua,"href","https://huggingface.co/docs/datasets/package_reference/main_classes.html#datasets.Dataset.to_tf_dataset"),d(ua,"rel","nofollow"),d(we,"id","compilao-e-ajustes"),d(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"),d(we,"href","#compilao-e-ajustes"),d(Q,"class","relative group"),d(va,"href","https://keras.io/api/models/model_training_apis/"),d(va,"rel","nofollow"),d(ts,"id","pytorch_native"),d(Me,"id","finetune-em-pytorch-nativo"),d(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"),d(Me,"href","#finetune-em-pytorch-nativo"),d(O,"class","relative group"),d(Te,"id","dataloader"),d(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"),d(Te,"href","#dataloader"),d(K,"class","relative group"),d(Ee,"id","otimizao-e-configurao-do-learning-rate"),d(Ee,"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"),d(Ee,"href","#otimizao-e-configurao-do-learning-rate"),d(ee,"class","relative group"),d(za,"href","https://pytorch.org/docs/stable/generated/torch.optim.AdamW.html"),d(za,"rel","nofollow"),d(Ce,"id","ciclo-de-treinamento"),d(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"),d(Ce,"href","#ciclo-de-treinamento"),d(ae,"class","relative group"),d(Fa,"href","https://tqdm.github.io/"),d(Fa,"rel","nofollow"),d(ze,"id","mtricas"),d(ze,"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"),d(ze,"href","#mtricas"),d(se,"class","relative group"),d(Ya,"href","https://huggingface.co/docs/datasets/package_reference/main_classes.html?highlight=add_batch#datasets.Metric.add_batch"),d(Ya,"rel","nofollow"),d(is,"id","additional-resources"),d(Ge,"id","recursos-adicionais"),d(Ge,"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"),d(Ge,"href","#recursos-adicionais"),d(te,"class","relative group"),d(Pa,"href","https://github.com/huggingface/transformers/tree/main/examples"),d(Pa,"rel","nofollow"),d(ds,"href","notebooks")},m(e,t){s(document.head,y),n(e,T,t),n(e,w,t),s(w,$),s($,Z),h(J,Z,null),s(w,G),s(w,U),s(U,E),n(e,M,t),h(I,e,t),n(e,W,t),n(e,Ha,t),s(Ha,Pr),n(e,Rt,t),n(e,A,t),s(A,Fe),s(Fe,xr),s(Fe,ws),s(ws,Hr),s(Fe,Sr),s(A,Dr),s(A,js),s(js,Qr),s(A,Or),s(A,Ms),s(Ms,Lr),n(e,zt,t),n(e,Sa,t),n(e,Gt,t),n(e,V,t),s(V,re),s(re,$s),h(Ne,$s,null),s(V,Kr),s(V,Js),s(Js,el),n(e,Wt,t),h(Be,e,t),n(e,At,t),n(e,Da,t),s(Da,al),n(e,Xt,t),n(e,le,t),s(le,sl),s(le,Ye),s(Ye,tl),s(le,ol),n(e,Ft,t),h(Ve,e,t),n(e,Nt,t),n(e,ne,t),s(ne,rl),s(ne,qe),s(qe,Ts),s(Ts,ll),s(ne,nl),n(e,Bt,t),h(Pe,e,t),n(e,Yt,t),n(e,Qa,t),s(Qa,il),n(e,Vt,t),h(xe,e,t),n(e,qt,t),n(e,Oa,t),n(e,Pt,t),n(e,q,t),s(q,ie),s(ie,_s),h(He,_s,null),s(q,pl),s(q,La),s(La,ml),s(La,Es),s(Es,cl),n(e,xt,t),h(Se,e,t),n(e,Ht,t),n(e,X,t),s(X,dl),s(X,ks),s(ks,ul),s(X,fl),s(X,Zs),s(Zs,hl),s(X,gl),n(e,St,t),n(e,pe,t),s(pe,vl),s(pe,De),s(De,bl),s(pe,yl),n(e,Dt,t),h(Qe,e,t),n(e,Qt,t),h(me,e,t),n(e,Ot,t),n(e,P,t),s(P,ce),s(ce,Us),h(Oe,Us,null),s(P,wl),s(P,Is),s(Is,jl),n(e,Lt,t),n(e,F,t),s(F,Ml),s(F,Cs),s(Cs,$l),s(F,Jl),s(F,Le),s(Le,Tl),s(F,_l),n(e,Kt,t),n(e,Ka,t),s(Ka,El),n(e,eo,t),h(Ke,e,t),n(e,ao,t),n(e,x,t),s(x,de),s(de,Rs),h(ea,Rs,null),s(x,kl),s(x,zs),s(zs,Zl),n(e,so,t),n(e,_,t),s(_,Ul),s(_,Gs),s(Gs,Il),s(_,Cl),s(_,Ws),s(Ws,Rl),s(_,zl),s(_,aa),s(aa,As),s(As,Gl),s(_,Wl),s(_,Xs),s(Xs,Al),s(_,Xl),s(_,sa),s(sa,Fl),s(_,Nl),n(e,to,t),h(ta,e,t),n(e,oo,t),n(e,C,t),s(C,Bl),s(C,Fs),s(Fs,Yl),s(C,Vl),s(C,Ns),s(Ns,ql),s(C,Pl),s(C,Bs),s(Bs,xl),s(C,Hl),n(e,ro,t),h(oa,e,t),n(e,lo,t),n(e,ue,t),s(ue,Sl),s(ue,Ys),s(Ys,Dl),s(ue,Ql),n(e,no,t),h(ra,e,t),n(e,io,t),n(e,H,t),s(H,fe),s(fe,Vs),h(la,Vs,null),s(H,Ol),s(H,qs),s(qs,Ll),n(e,po,t),n(e,he,t),s(he,Kl),s(he,Ps),s(Ps,en),s(he,an),n(e,mo,t),h(na,e,t),n(e,co,t),n(e,ge,t),s(ge,sn),s(ge,xs),s(xs,tn),s(ge,on),n(e,uo,t),h(ia,e,t),n(e,fo,t),n(e,es,t),n(e,ho,t),n(e,S,t),s(S,ve),s(ve,Hs),h(pa,Hs,null),s(S,rn),s(S,Ss),s(Ss,ln),n(e,go,t),h(ma,e,t),n(e,vo,t),n(e,as,t),s(as,nn),n(e,bo,t),n(e,D,t),s(D,be),s(be,Ds),h(ca,Ds,null),s(D,pn),s(D,Qs),s(Qs,mn),n(e,yo,t),n(e,N,t),s(N,cn),s(N,Os),s(Os,dn),s(N,un),s(N,Ls),s(Ls,fn),s(N,hn),n(e,wo,t),h(da,e,t),n(e,jo,t),h(ye,e,t),n(e,Mo,t),n(e,R,t),s(R,gn),s(R,ua),s(ua,Ks),s(Ks,vn),s(R,bn),s(R,et),s(et,yn),s(R,wn),s(R,at),s(at,jn),s(R,Mn),n(e,$o,t),h(fa,e,t),n(e,Jo,t),n(e,Q,t),s(Q,we),s(we,st),h(ha,st,null),s(Q,$n),s(Q,tt),s(tt,Jn),n(e,To,t),n(e,ss,t),s(ss,Tn),n(e,_o,t),h(ga,e,t),n(e,Eo,t),n(e,je,t),s(je,_n),s(je,va),s(va,ot),s(ot,En),s(je,kn),n(e,ko,t),h(ba,e,t),n(e,Zo,t),n(e,ts,t),n(e,Uo,t),n(e,O,t),s(O,Me),s(Me,rt),h(ya,rt,null),s(O,Zn),s(O,lt),s(lt,Un),n(e,Io,t),h(wa,e,t),n(e,Co,t),n(e,$e,t),s($e,In),s($e,nt),s(nt,Cn),s($e,Rn),n(e,Ro,t),n(e,os,t),s(os,zn),n(e,zo,t),h(ja,e,t),n(e,Go,t),n(e,Je,t),s(Je,Gn),s(Je,it),s(it,Wn),s(Je,An),n(e,Wo,t),n(e,B,t),s(B,Ma),s(Ma,$a),s($a,Xn),s($a,pt),s(pt,Fn),s($a,Nn),s(Ma,Bn),h(Ja,Ma,null),s(B,Yn),s(B,Ta),s(Ta,L),s(L,Vn),s(L,mt),s(mt,qn),s(L,Pn),s(L,ct),s(ct,xn),s(L,Hn),s(Ta,Sn),h(_a,Ta,null),s(B,Dn),s(B,Ea),s(Ea,dt),s(dt,Qn),s(Ea,On),h(ka,Ea,null),n(e,Ao,t),n(e,rs,t),s(rs,Ln),n(e,Xo,t),h(Za,e,t),n(e,Fo,t),n(e,K,t),s(K,Te),s(Te,ut),h(Ua,ut,null),s(K,Kn),s(K,ft),s(ft,ei),n(e,No,t),n(e,_e,t),s(_e,ai),s(_e,ht),s(ht,si),s(_e,ti),n(e,Bo,t),h(Ia,e,t),n(e,Yo,t),n(e,ls,t),s(ls,oi),n(e,Vo,t),h(Ca,e,t),n(e,qo,t),n(e,ee,t),s(ee,Ee),s(Ee,gt),h(Ra,gt,null),s(ee,ri),s(ee,vt),s(vt,li),n(e,Po,t),n(e,ke,t),s(ke,ni),s(ke,za),s(za,bt),s(bt,ii),s(ke,pi),n(e,xo,t),h(Ga,e,t),n(e,Ho,t),n(e,Ze,t),s(Ze,mi),s(Ze,yt),s(yt,ci),s(Ze,di),n(e,So,t),h(Wa,e,t),n(e,Do,t),n(e,Ue,t),s(Ue,ui),s(Ue,wt),s(wt,fi),s(Ue,hi),n(e,Qo,t),h(Aa,e,t),n(e,Oo,t),h(Ie,e,t),n(e,Lo,t),n(e,ns,t),s(ns,gi),n(e,Ko,t),n(e,ae,t),s(ae,Ce),s(Ce,jt),h(Xa,jt,null),s(ae,vi),s(ae,Mt),s(Mt,bi),n(e,er,t),n(e,Re,t),s(Re,yi),s(Re,Fa),s(Fa,wi),s(Re,ji),n(e,ar,t),h(Na,e,t),n(e,sr,t),n(e,se,t),s(se,ze),s(ze,$t),h(Ba,$t,null),s(se,Mi),s(se,Jt),s(Jt,$i),n(e,tr,t),n(e,Y,t),s(Y,Ji),s(Y,Tt),s(Tt,Ti),s(Y,_i),s(Y,Ya),s(Ya,_t),s(_t,Ei),s(Y,ki),n(e,or,t),h(Va,e,t),n(e,rr,t),n(e,is,t),n(e,lr,t),n(e,te,t),s(te,Ge),s(Ge,Et),h(qa,Et,null),s(te,Zi),s(te,kt),s(kt,Ui),n(e,nr,t),n(e,ps,t),s(ps,Ii),n(e,ir,t),n(e,We,t),s(We,Zt),s(Zt,ms),s(ms,Pa),s(Pa,Ci),s(ms,Ri),s(We,zi),s(We,Ut),s(Ut,cs),s(cs,ds),s(ds,Gi),s(cs,Wi),pr=!0},p(e,[t]){const xa={};t&2&&(xa.$$scope={dirty:t,ctx:e}),me.$set(xa);const It={};t&2&&(It.$$scope={dirty:t,ctx:e}),ye.$set(It);const Ct={};t&2&&(Ct.$$scope={dirty:t,ctx:e}),Ie.$set(Ct)},i(e){pr||(g(J.$$.fragment,e),g(I.$$.fragment,e),g(Ne.$$.fragment,e),g(Be.$$.fragment,e),g(Ve.$$.fragment,e),g(Pe.$$.fragment,e),g(xe.$$.fragment,e),g(He.$$.fragment,e),g(Se.$$.fragment,e),g(Qe.$$.fragment,e),g(me.$$.fragment,e),g(Oe.$$.fragment,e),g(Ke.$$.fragment,e),g(ea.$$.fragment,e),g(ta.$$.fragment,e),g(oa.$$.fragment,e),g(ra.$$.fragment,e),g(la.$$.fragment,e),g(na.$$.fragment,e),g(ia.$$.fragment,e),g(pa.$$.fragment,e),g(ma.$$.fragment,e),g(ca.$$.fragment,e),g(da.$$.fragment,e),g(ye.$$.fragment,e),g(fa.$$.fragment,e),g(ha.$$.fragment,e),g(ga.$$.fragment,e),g(ba.$$.fragment,e),g(ya.$$.fragment,e),g(wa.$$.fragment,e),g(ja.$$.fragment,e),g(Ja.$$.fragment,e),g(_a.$$.fragment,e),g(ka.$$.fragment,e),g(Za.$$.fragment,e),g(Ua.$$.fragment,e),g(Ia.$$.fragment,e),g(Ca.$$.fragment,e),g(Ra.$$.fragment,e),g(Ga.$$.fragment,e),g(Wa.$$.fragment,e),g(Aa.$$.fragment,e),g(Ie.$$.fragment,e),g(Xa.$$.fragment,e),g(Na.$$.fragment,e),g(Ba.$$.fragment,e),g(Va.$$.fragment,e),g(qa.$$.fragment,e),pr=!0)},o(e){v(J.$$.fragment,e),v(I.$$.fragment,e),v(Ne.$$.fragment,e),v(Be.$$.fragment,e),v(Ve.$$.fragment,e),v(Pe.$$.fragment,e),v(xe.$$.fragment,e),v(He.$$.fragment,e),v(Se.$$.fragment,e),v(Qe.$$.fragment,e),v(me.$$.fragment,e),v(Oe.$$.fragment,e),v(Ke.$$.fragment,e),v(ea.$$.fragment,e),v(ta.$$.fragment,e),v(oa.$$.fragment,e),v(ra.$$.fragment,e),v(la.$$.fragment,e),v(na.$$.fragment,e),v(ia.$$.fragment,e),v(pa.$$.fragment,e),v(ma.$$.fragment,e),v(ca.$$.fragment,e),v(da.$$.fragment,e),v(ye.$$.fragment,e),v(fa.$$.fragment,e),v(ha.$$.fragment,e),v(ga.$$.fragment,e),v(ba.$$.fragment,e),v(ya.$$.fragment,e),v(wa.$$.fragment,e),v(ja.$$.fragment,e),v(Ja.$$.fragment,e),v(_a.$$.fragment,e),v(ka.$$.fragment,e),v(Za.$$.fragment,e),v(Ua.$$.fragment,e),v(Ia.$$.fragment,e),v(Ca.$$.fragment,e),v(Ra.$$.fragment,e),v(Ga.$$.fragment,e),v(Wa.$$.fragment,e),v(Aa.$$.fragment,e),v(Ie.$$.fragment,e),v(Xa.$$.fragment,e),v(Na.$$.fragment,e),v(Ba.$$.fragment,e),v(Va.$$.fragment,e),v(qa.$$.fragment,e),pr=!1},d(e){a(y),e&&a(T),e&&a(w),b(J),e&&a(M),b(I,e),e&&a(W),e&&a(Ha),e&&a(Rt),e&&a(A),e&&a(zt),e&&a(Sa),e&&a(Gt),e&&a(V),b(Ne),e&&a(Wt),b(Be,e),e&&a(At),e&&a(Da),e&&a(Xt),e&&a(le),e&&a(Ft),b(Ve,e),e&&a(Nt),e&&a(ne),e&&a(Bt),b(Pe,e),e&&a(Yt),e&&a(Qa),e&&a(Vt),b(xe,e),e&&a(qt),e&&a(Oa),e&&a(Pt),e&&a(q),b(He),e&&a(xt),b(Se,e),e&&a(Ht),e&&a(X),e&&a(St),e&&a(pe),e&&a(Dt),b(Qe,e),e&&a(Qt),b(me,e),e&&a(Ot),e&&a(P),b(Oe),e&&a(Lt),e&&a(F),e&&a(Kt),e&&a(Ka),e&&a(eo),b(Ke,e),e&&a(ao),e&&a(x),b(ea),e&&a(so),e&&a(_),e&&a(to),b(ta,e),e&&a(oo),e&&a(C),e&&a(ro),b(oa,e),e&&a(lo),e&&a(ue),e&&a(no),b(ra,e),e&&a(io),e&&a(H),b(la),e&&a(po),e&&a(he),e&&a(mo),b(na,e),e&&a(co),e&&a(ge),e&&a(uo),b(ia,e),e&&a(fo),e&&a(es),e&&a(ho),e&&a(S),b(pa),e&&a(go),b(ma,e),e&&a(vo),e&&a(as),e&&a(bo),e&&a(D),b(ca),e&&a(yo),e&&a(N),e&&a(wo),b(da,e),e&&a(jo),b(ye,e),e&&a(Mo),e&&a(R),e&&a($o),b(fa,e),e&&a(Jo),e&&a(Q),b(ha),e&&a(To),e&&a(ss),e&&a(_o),b(ga,e),e&&a(Eo),e&&a(je),e&&a(ko),b(ba,e),e&&a(Zo),e&&a(ts),e&&a(Uo),e&&a(O),b(ya),e&&a(Io),b(wa,e),e&&a(Co),e&&a($e),e&&a(Ro),e&&a(os),e&&a(zo),b(ja,e),e&&a(Go),e&&a(Je),e&&a(Wo),e&&a(B),b(Ja),b(_a),b(ka),e&&a(Ao),e&&a(rs),e&&a(Xo),b(Za,e),e&&a(Fo),e&&a(K),b(Ua),e&&a(No),e&&a(_e),e&&a(Bo),b(Ia,e),e&&a(Yo),e&&a(ls),e&&a(Vo),b(Ca,e),e&&a(qo),e&&a(ee),b(Ra),e&&a(Po),e&&a(ke),e&&a(xo),b(Ga,e),e&&a(Ho),e&&a(Ze),e&&a(So),b(Wa,e),e&&a(Do),e&&a(Ue),e&&a(Qo),b(Aa,e),e&&a(Oo),b(Ie,e),e&&a(Lo),e&&a(ns),e&&a(Ko),e&&a(ae),b(Xa),e&&a(er),e&&a(Re),e&&a(ar),b(Na,e),e&&a(sr),e&&a(se),b(Ba),e&&a(tr),e&&a(Y),e&&a(or),b(Va,e),e&&a(rr),e&&a(is),e&&a(lr),e&&a(te),b(qa),e&&a(nr),e&&a(ps),e&&a(ir),e&&a(We)}}}const Hm={local:"finetuning-de-um-modelo-prtreinado",sections:[{local:"preparando-um-dataset",title:"Preparando um dataset"},{local:"finetuning-com-o-trainer",sections:[{local:"hiperparmetros-de-treinamento",title:"Hiperpar\xE2metros de treinamento"},{local:"mtricas",title:"M\xE9tricas"},{local:"trainer",title:"Trainer"}],title:"Fine-tuning com o `Trainer`"},{local:"finetuning-com-keras",sections:[{local:"converso-do-dataset-ao-formato-do-tensorflow",title:"Convers\xE3o do dataset ao formato do TensorFlow"},{local:"compilao-e-ajustes",title:"Compila\xE7\xE3o e ajustes"}],title:"Fine-tuning com Keras"},{local:"finetune-em-pytorch-nativo",sections:[{local:"dataloader",title:"DataLoader"},{local:"otimizao-e-configurao-do-learning-rate",title:"Otimiza\xE7\xE3o e configura\xE7\xE3o do Learning Rate"},{local:"ciclo-de-treinamento",title:"Ciclo de treinamento"},{local:"mtricas",title:"M\xE9tricas"}],title:"Fine-tune em PyTorch nativo"},{local:"recursos-adicionais",title:"Recursos adicionais"}],title:"Fine-tuning de um modelo pr\xE9-treinado"};function Sm(oe){return Bm(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class ac extends Am{constructor(y){super();Xm(this,y,Sm,xm,Fm,{})}}export{ac as default,Hm as metadata};
