import{S as Wc,i as zc,s as Ac,e as l,k as c,w as u,t as i,M as Xc,c as n,d as a,m as d,a as r,x as f,h as p,b as m,G as t,g as o,y as h,q as y,o as b,B as g,v as Fc}from"../chunks/vendor-hf-doc-builder.js";import{T as Xi}from"../chunks/Tip-hf-doc-builder.js";import{Y as Yn}from"../chunks/Youtube-hf-doc-builder.js";import{I as U}from"../chunks/IconCopyLink-hf-doc-builder.js";import{C as j}from"../chunks/CodeBlock-hf-doc-builder.js";import{D as Bc}from"../chunks/DocNotebookDropdown-hf-doc-builder.js";function Nc(se){let v,J;return{c(){v=l("p"),J=i(`Ver\xE1s una advertencia acerca de que algunos de los pesos pre-entrenados no est\xE1n siendo utilizados y que algunos pesos est\xE1n siendo inicializados al azar. No te preocupes, esto es completamente normal.
El head/cabezal pre-entrenado del modelo BERT se descarta y se sustituye por un head de clasificaci\xF3n inicializado aleatoriamente. Puedes aplicar fine-tuning a este nuevo head del modelo en tu tarea de clasificaci\xF3n de secuencias haciendo transfer learning del modelo pre-entrenado.`)},l(w){v=n(w,"P",{});var M=r(v);J=p(M,`Ver\xE1s una advertencia acerca de que algunos de los pesos pre-entrenados no est\xE1n siendo utilizados y que algunos pesos est\xE1n siendo inicializados al azar. No te preocupes, esto es completamente normal.
El head/cabezal pre-entrenado del modelo BERT se descarta y se sustituye por un head de clasificaci\xF3n inicializado aleatoriamente. Puedes aplicar fine-tuning a este nuevo head del modelo en tu tarea de clasificaci\xF3n de secuencias haciendo transfer learning del modelo pre-entrenado.`),M.forEach(a)},m(w,M){o(w,v,M),t(v,J)},d(w){w&&a(v)}}}function Yc(se){let v,J,w,M,k,$,W;return{c(){v=l("p"),J=l("code"),w=i("Trainer"),M=i(" utiliza "),k=l("code"),$=i("DataCollatorWithPadding"),W=i(" por defecto por lo que no es necesario especificar expl\xEDcitamente un intercalador de datos (data collator, en ingl\xE9s).")},l(Z){v=n(Z,"P",{});var T=r(v);J=n(T,"CODE",{});var _=r(J);w=p(_,"Trainer"),_.forEach(a),M=p(T," utiliza "),k=n(T,"CODE",{});var I=r(k);$=p(I,"DataCollatorWithPadding"),I.forEach(a),W=p(T," por defecto por lo que no es necesario especificar expl\xEDcitamente un intercalador de datos (data collator, en ingl\xE9s)."),T.forEach(a)},m(Z,T){o(Z,v,T),t(v,J),t(J,w),t(v,M),t(v,k),t(k,$),t(v,W)},d(Z){Z&&a(v)}}}function Vc(se){let v,J,w,M,k,$,W,Z;return{c(){v=l("p"),J=i("Consigue acceso gratuito a una GPU en la nube si es que no tienes este recurso de forma local con un notebook alojado en "),w=l("a"),M=i("Colaboratory"),k=i(" o "),$=l("a"),W=i("SageMaker StudioLab"),Z=i("."),this.h()},l(T){v=n(T,"P",{});var _=r(v);J=p(_,"Consigue acceso gratuito a una GPU en la nube si es que no tienes este recurso de forma local con un notebook alojado en "),w=n(_,"A",{href:!0,rel:!0});var I=r(w);M=p(I,"Colaboratory"),I.forEach(a),k=p(_," o "),$=n(_,"A",{href:!0,rel:!0});var Xe=r($);W=p(Xe,"SageMaker StudioLab"),Xe.forEach(a),Z=p(_,"."),_.forEach(a),this.h()},h(){m(w,"href","https://colab.research.google.com/"),m(w,"rel","nofollow"),m($,"href","https://studiolab.sagemaker.aws/"),m($,"rel","nofollow")},m(T,_){o(T,v,_),t(v,J),t(v,w),t(w,M),t(v,k),t(v,$),t($,W),t(v,Z)},d(T){T&&a(v)}}}function qc(se){let v,J,w,M,k,$,W,Z,T,_,I,Xe,Ha,Vn,Cs,A,Fe,qn,vt,Pn,Hn,xn,wt,Sn,Dn,jt,Qn,Rs,xa,Gs,V,le,Mt,Be,Ln,$t,Kn,Ws,Ne,zs,Sa,On,As,ne,er,Ye,ar,tr,Xs,Ve,Fs,Da,sr,Bs,qe,Ns,Qa,lr,Ys,Pe,Vs,La,qs,q,re,Jt,He,nr,Ka,rr,Tt,or,Ps,xe,Hs,X,ir,_t,pr,cr,Et,dr,mr,xs,oe,ur,Se,fr,hr,Ss,De,Ds,ie,Qs,P,pe,kt,Qe,yr,Zt,br,Ls,F,gr,Ut,vr,wr,Le,jr,Mr,Ks,Oa,$r,Os,Ke,el,H,ce,It,Oe,Jr,Ct,Tr,al,E,_r,Rt,Er,kr,Gt,Zr,Ur,ea,Wt,Ir,Cr,zt,Rr,Gr,aa,Wr,zr,tl,ta,sl,C,Ar,At,Xr,Fr,Xt,Br,Nr,Ft,Yr,Vr,ll,sa,nl,de,qr,Bt,Pr,Hr,rl,la,ol,x,me,Nt,na,xr,Yt,Sr,il,ue,Dr,Vt,Qr,Lr,pl,ra,cl,fe,Kr,qt,Or,eo,dl,oa,ml,et,ul,S,he,Pt,ia,ao,Ht,to,fl,pa,hl,at,so,yl,D,ye,xt,ca,lo,St,no,bl,B,ro,Dt,oo,io,Qt,po,co,gl,da,vl,be,wl,R,mo,ma,Lt,uo,fo,Kt,ho,yo,Ot,bo,go,jl,ua,Ml,Q,ge,es,fa,vo,as,wo,$l,tt,jo,Jl,ha,Tl,ve,Mo,ya,ts,$o,Jo,_l,ba,El,st,kl,L,we,ss,ga,To,ls,_o,Zl,va,Ul,je,Eo,ns,ko,Zo,Il,lt,Uo,Cl,wa,Rl,Me,Io,rs,Co,Ro,Gl,N,ja,Ma,Go,os,Wo,zo,Ao,$a,Xo,Ja,z,Fo,is,Bo,No,ps,Yo,Vo,cs,qo,Po,Ho,Ta,xo,_a,ds,So,Do,Ea,Wl,nt,Qo,zl,ka,Al,K,$e,ms,Za,Lo,us,Ko,Xl,Je,Oo,fs,ei,ai,Fl,Ua,Bl,rt,ti,Nl,Ia,Yl,O,Te,hs,Ca,si,ys,li,Vl,_e,ni,Ra,bs,ri,oi,ql,Ga,Pl,Ee,ii,gs,pi,ci,Hl,Wa,xl,ke,di,vs,mi,ui,Sl,za,Dl,Ze,Ql,ot,fi,Ll,ee,Ue,ws,Aa,hi,js,yi,Kl,Ie,bi,Xa,gi,vi,Ol,Fa,en,ae,Ce,Ms,Ba,wi,$s,ji,an,Y,Mi,Js,$i,Ji,Na,Ts,Ti,_i,tn,Ya,sn,it,ln,te,Re,_s,Va,Ei,Es,ki,nn,pt,Zi,rn,Ge,ks,ct,qa,Ui,Ii,Ci,Zs,dt,mt,Ri,Gi,on;return $=new U({}),I=new Bc({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/es/training.ipynb"},{label:"PyTorch",value:"https://colab.research.google.com/github/huggingface/notebooks/blob/main/transformers_doc/es/pytorch/training.ipynb"},{label:"TensorFlow",value:"https://colab.research.google.com/github/huggingface/notebooks/blob/main/transformers_doc/es/tensorflow/training.ipynb"},{label:"Mixed",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/main/transformers_doc/es/training.ipynb"},{label:"PyTorch",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/main/transformers_doc/es/pytorch/training.ipynb"},{label:"TensorFlow",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/main/transformers_doc/es/tensorflow/training.ipynb"}]}}),Be=new U({}),Ne=new Yn({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>}`}}),qe=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>)`}}),Pe=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 U({}),xe=new Yn({props:{id:"nvBXf7s7vTI"}}),De=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>)`}}),ie=new Xi({props:{$$slots:{default:[Nc]},$$scope:{ctx:se}}}),Qe=new U({}),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>)`}}),Oe=new U({}),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>)`}}),sa=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)`}}),la=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>)`}}),na=new U({}),ra=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>)`}}),oa=new j({props:{code:"dHJhaW5lci50cmFpbigp",highlighted:'<span class="hljs-meta">&gt;&gt;&gt; </span>trainer.train()'}}),ia=new U({}),pa=new Yn({props:{id:"rnTGBy2ax1c"}}),ca=new U({}),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>)`}}),be=new Xi({props:{$$slots:{default:[Yc]},$$scope:{ctx:se}}}),ua=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>)`}}),fa=new U({}),ha=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>)`}}),ga=new U({}),va=new Yn({props:{id:"Dh9CL8fyG80"}}),wa=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()`}}),$a=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>])'}}),Ta=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>)'}}),Ea=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>)'}}),ka=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>))`}}),Za=new U({}),Ua=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>)`}}),Ia=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>)`}}),Ca=new U({}),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>)`}}),za=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)`}}),Ze=new Xi({props:{$$slots:{default:[Vc]},$$scope:{ctx:se}}}),Aa=new U({}),Fa=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 U({}),Ya=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()`}}),Va=new U({}),{c(){v=l("meta"),J=c(),w=l("h1"),M=l("a"),k=l("span"),u($.$$.fragment),W=c(),Z=l("span"),T=i("Fine-tuning a un modelo pre-entrenado"),_=c(),u(I.$$.fragment),Xe=c(),Ha=l("p"),Vn=i("El uso de un modelo pre-entrenado tiene importantes ventajas. Reduce los costos de computaci\xF3n, la huella de carbono y te permite utilizar modelos de \xFAltima generaci\xF3n sin tener que entrenar uno desde cero."),Cs=c(),A=l("ul"),Fe=l("li"),qn=i("Fine-tuning a un modelo pre-entrenado con \u{1F917} Transformers "),vt=l("code"),Pn=i("Trainer"),Hn=i("."),xn=c(),wt=l("li"),Sn=i("Fine-tuning a un modelo pre-entrenado en TensorFlow con Keras."),Dn=c(),jt=l("li"),Qn=i("Fine-tuning a un modelo pre-entrenado en PyTorch nativo."),Rs=c(),xa=l("a"),Gs=c(),V=l("h2"),le=l("a"),Mt=l("span"),u(Be.$$.fragment),Ln=c(),$t=l("span"),Kn=i("Prepara un dataset"),Ws=c(),u(Ne.$$.fragment),zs=c(),Sa=l("p"),On=i("Antes de aplicar fine-tuning a un modelo pre-entrenado, descarga un dataset y prep\xE1ralo para el entrenamiento. El tutorial anterior nos ense\xF1\xF3 c\xF3mo procesar los datos para el entrenamiento, y ahora es la oportunidad de poner a prueba estas habilidades."),As=c(),ne=l("p"),er=i("Comienza cargando el dataset de "),Ye=l("a"),ar=i("Yelp Reviews"),tr=i(":"),Xs=c(),u(Ve.$$.fragment),Fs=c(),Da=l("p"),sr=i("Como ya sabes, necesitas un tokenizador para procesar el texto e incluir una estrategia para el padding y el truncamiento para manejar cualquier longitud de secuencia variable. Para procesar tu dataset en un solo paso, utiliza el m\xE9todo de \u{1F917} Datasets map para aplicar una funci\xF3n de preprocesamiento sobre todo el dataset:"),Bs=c(),u(qe.$$.fragment),Ns=c(),Qa=l("p"),lr=i("Si lo deseas, puedes crear un subconjunto m\xE1s peque\xF1o del dataset completo para aplicarle fine-tuning y as\xED reducir el tiempo."),Ys=c(),u(Pe.$$.fragment),Vs=c(),La=l("a"),qs=c(),q=l("h2"),re=l("a"),Jt=l("span"),u(He.$$.fragment),nr=c(),Ka=l("span"),rr=i("Fine-tuning con "),Tt=l("code"),or=i("Trainer"),Ps=c(),u(xe.$$.fragment),Hs=c(),X=l("p"),ir=i("\u{1F917} Transformers proporciona una clase "),_t=l("code"),pr=i("Trainer"),cr=i(" optimizada para el entrenamiento de modelos de \u{1F917} Transformers, haciendo m\xE1s f\xE1cil el inicio del entrenamiento sin necesidad de escribir manualmente tu propio ciclo. La API del "),Et=l("code"),dr=i("Trainer"),mr=i(" soporta una amplia gama de opciones de entrenamiento y caracter\xEDsticas como el logging, el gradient accumulation y el mixed precision."),xs=c(),oe=l("p"),ur=i("Comienza cargando tu modelo y especifica el n\xFAmero de labels previstas. A partir del "),Se=l("a"),fr=i("Card Dataset"),hr=i(" de Yelp Review, que como ya sabemos tiene 5 labels:"),Ss=c(),u(De.$$.fragment),Ds=c(),u(ie.$$.fragment),Qs=c(),P=l("h3"),pe=l("a"),kt=l("span"),u(Qe.$$.fragment),yr=c(),Zt=l("span"),br=i("Hiperpar\xE1metros de entrenamiento"),Ls=c(),F=l("p"),gr=i("A continuaci\xF3n, crea una clase "),Ut=l("code"),vr=i("TrainingArguments"),wr=i(" que contenga todos los hiperpar\xE1metros que puedes ajustar as\xED como los indicadores para activar las diferentes opciones de entrenamiento. Para este tutorial puedes empezar con los "),Le=l("a"),jr=i("hiperpar\xE1metros"),Mr=i(" de entrenamiento por defecto, pero si\xE9ntete libre de experimentar con ellos para encontrar tu configuraci\xF3n \xF3ptima."),Ks=c(),Oa=l("p"),$r=i("Especifica d\xF3nde vas a guardar los checkpoints de tu entrenamiento:"),Os=c(),u(Ke.$$.fragment),el=c(),H=l("h3"),ce=l("a"),It=l("span"),u(Oe.$$.fragment),Jr=c(),Ct=l("span"),Tr=i("M\xE9tricas"),al=c(),E=l("p"),_r=i("El "),Rt=l("code"),Er=i("Trainer"),kr=i(" no eval\xFAa autom\xE1ticamente el rendimiento del modelo durante el entrenamiento. Tendr\xE1s que pasarle a "),Gt=l("code"),Zr=i("Trainer"),Ur=i(" una funci\xF3n para calcular y hacer un reporte de las m\xE9tricas. La biblioteca de \u{1F917} Datasets proporciona una funci\xF3n de "),ea=l("a"),Wt=l("code"),Ir=i("accuracy"),Cr=i(" simple que puedes cargar con la funci\xF3n "),zt=l("code"),Rr=i("load_metric"),Gr=i(" (ver este "),aa=l("a"),Wr=i("tutorial"),zr=i(" para m\xE1s informaci\xF3n):"),tl=c(),u(ta.$$.fragment),sl=c(),C=l("p"),Ar=i("Define la funci\xF3n "),At=l("code"),Xr=i("compute"),Fr=i(" en "),Xt=l("code"),Br=i("metric"),Nr=i(" para calcular el accuracy de tus predicciones. Antes de pasar tus predicciones a "),Ft=l("code"),Yr=i("compute"),Vr=i(", necesitas convertir las predicciones a logits (recuerda que todos los modelos de \u{1F917} Transformers devuelven logits)."),ll=c(),u(sa.$$.fragment),nl=c(),de=l("p"),qr=i("Si quieres controlar tus m\xE9tricas de evaluaci\xF3n durante el fine-tuning, especifica el par\xE1metro "),Bt=l("code"),Pr=i("evaluation_strategy"),Hr=i(" en tus argumentos de entrenamiento para que el modelo tenga en cuenta la m\xE9trica de evaluaci\xF3n al final de cada \xE9poca:"),rl=c(),u(la.$$.fragment),ol=c(),x=l("h3"),me=l("a"),Nt=l("span"),u(na.$$.fragment),xr=c(),Yt=l("span"),Sr=i("Trainer"),il=c(),ue=l("p"),Dr=i("Crea un objeto "),Vt=l("code"),Qr=i("Trainer"),Lr=i(" con tu modelo, argumentos de entrenamiento, datasets de entrenamiento y de prueba, y tu funci\xF3n de evaluaci\xF3n:"),pl=c(),u(ra.$$.fragment),cl=c(),fe=l("p"),Kr=i("A continuaci\xF3n, aplica fine-tuning a tu modelo llamando "),qt=l("code"),Or=i("train()"),eo=i(":"),dl=c(),u(oa.$$.fragment),ml=c(),et=l("a"),ul=c(),S=l("h2"),he=l("a"),Pt=l("span"),u(ia.$$.fragment),ao=c(),Ht=l("span"),to=i("Fine-tuning con Keras"),fl=c(),u(pa.$$.fragment),hl=c(),at=l("p"),so=i("Los modelos de \u{1F917} Transformers tambi\xE9n permiten realizar el entrenamiento en TensorFlow con la API de Keras. Solo es necesario hacer algunos cambios antes de hacer fine-tuning."),yl=c(),D=l("h3"),ye=l("a"),xt=l("span"),u(ca.$$.fragment),lo=c(),St=l("span"),no=i("Convierte el dataset al formato de TensorFlow"),bl=c(),B=l("p"),ro=i("El "),Dt=l("code"),oo=i("DefaultDataCollator"),io=i(" junta los tensores en un batch para que el modelo se entrene en \xE9l. Aseg\xFArate de especificar "),Qt=l("code"),po=i("return_tensors"),co=i(" para devolver los tensores de TensorFlow:"),gl=c(),u(da.$$.fragment),vl=c(),u(be.$$.fragment),wl=c(),R=l("p"),mo=i("A continuaci\xF3n, convierte los datasets tokenizados en datasets de TensorFlow con el m\xE9todo "),ma=l("a"),Lt=l("code"),uo=i("to_tf_dataset"),fo=i(". Especifica tus entradas en "),Kt=l("code"),ho=i("columns"),yo=i(" y tu etiqueta en "),Ot=l("code"),bo=i("label_cols"),go=i(":"),jl=c(),u(ua.$$.fragment),Ml=c(),Q=l("h3"),ge=l("a"),es=l("span"),u(fa.$$.fragment),vo=c(),as=l("span"),wo=i("Compila y ajusta"),$l=c(),tt=l("p"),jo=i("Carguemos un modelo TensorFlow con el n\xFAmero esperado de labels:"),Jl=c(),u(ha.$$.fragment),Tl=c(),ve=l("p"),Mo=i("A continuaci\xF3n, compila y aplica fine-tuning a tu modelo con "),ya=l("a"),ts=l("code"),$o=i("fit"),Jo=i(" como lo har\xEDas con cualquier otro modelo de Keras:"),_l=c(),u(ba.$$.fragment),El=c(),st=l("a"),kl=c(),L=l("h2"),we=l("a"),ss=l("span"),u(ga.$$.fragment),To=c(),ls=l("span"),_o=i("Fine-tune en PyTorch nativo"),Zl=c(),u(va.$$.fragment),Ul=c(),je=l("p"),Eo=i("El "),ns=l("code"),ko=i("Trainer"),Zo=i(" se encarga del ciclo de entrenamiento y permite aplicar fine-tuning a un modelo en una sola l\xEDnea de c\xF3digo. Para los que prefieran escribir su propio ciclo de entrenamiento, tambi\xE9n pueden aplicar fine-tuning a un modelo de \u{1F917} Transformers en PyTorch nativo."),Il=c(),lt=l("p"),Uo=i("En este punto, es posible que necesites reiniciar tu notebook o ejecutar el siguiente c\xF3digo para liberar algo de memoria:"),Cl=c(),u(wa.$$.fragment),Rl=c(),Me=l("p"),Io=i("A continuaci\xF3n, haremos un post-procesamiento manual al "),rs=l("code"),Co=i("tokenized_dataset"),Ro=i(" y as\xED prepararlo para el entrenamiento."),Gl=c(),N=l("ol"),ja=l("li"),Ma=l("p"),Go=i("Elimina la columna de "),os=l("code"),Wo=i("text"),zo=i(" porque el modelo no acepta texto en crudo como entrada:"),Ao=c(),u($a.$$.fragment),Xo=c(),Ja=l("li"),z=l("p"),Fo=i("Cambia el nombre de la columna de "),is=l("code"),Bo=i("label"),No=i(" a "),ps=l("code"),Yo=i("labels"),Vo=i(" porque el modelo espera que el argumento se llame "),cs=l("code"),qo=i("labels"),Po=i(":"),Ho=c(),u(Ta.$$.fragment),xo=c(),_a=l("li"),ds=l("p"),So=i("Establece el formato del dataset para devolver tensores PyTorch en lugar de listas:"),Do=c(),u(Ea.$$.fragment),Wl=c(),nt=l("p"),Qo=i("A continuaci\xF3n, crea un subconjunto m\xE1s peque\xF1o del dataset como se ha mostrado anteriormente para acelerar el fine-tuning:"),zl=c(),u(ka.$$.fragment),Al=c(),K=l("h3"),$e=l("a"),ms=l("span"),u(Za.$$.fragment),Lo=c(),us=l("span"),Ko=i("DataLoader"),Xl=c(),Je=l("p"),Oo=i("Crea un "),fs=l("code"),ei=i("DataLoader"),ai=i(" para tus datasets de entrenamiento y de prueba para poder iterar sobre batches de datos:"),Fl=c(),u(Ua.$$.fragment),Bl=c(),rt=l("p"),ti=i("Carga tu modelo con el n\xFAmero de labels previstas:"),Nl=c(),u(Ia.$$.fragment),Yl=c(),O=l("h3"),Te=l("a"),hs=l("span"),u(Ca.$$.fragment),si=c(),ys=l("span"),li=i("Optimiza y programa el learning rate"),Vl=c(),_e=l("p"),ni=i("Crea un optimizador y el learning rate para aplicar fine-tuning al modelo. Vamos a utilizar el optimizador "),Ra=l("a"),bs=l("code"),ri=i("AdamW"),oi=i(" de PyTorch:"),ql=c(),u(Ga.$$.fragment),Pl=c(),Ee=l("p"),ii=i("Crea el learning rate desde el "),gs=l("code"),pi=i("Trainer"),ci=i(":"),Hl=c(),u(Wa.$$.fragment),xl=c(),ke=l("p"),di=i("Por \xFAltimo, especifica el "),vs=l("code"),mi=i("device"),ui=i(" o entorno de ejecuci\xF3n para utilizar una GPU si tienes acceso a una. De lo contrario, el entrenamiento en una CPU puede llevarte varias horas en lugar de un par de minutos."),Sl=c(),u(za.$$.fragment),Dl=c(),u(Ze.$$.fragment),Ql=c(),ot=l("p"),fi=i("Genial, \xA1ahora podemos entrenar! \u{1F973}"),Ll=c(),ee=l("h3"),Ue=l("a"),ws=l("span"),u(Aa.$$.fragment),hi=c(),js=l("span"),yi=i("Ciclo de entrenamiento"),Kl=c(),Ie=l("p"),bi=i("Para hacer un seguimiento al progreso del entrenamiento, utiliza la biblioteca "),Xa=l("a"),gi=i("tqdm"),vi=i(" para a\xF1adir una barra de progreso sobre el n\xFAmero de pasos de entrenamiento:"),Ol=c(),u(Fa.$$.fragment),en=c(),ae=l("h3"),Ce=l("a"),Ms=l("span"),u(Ba.$$.fragment),wi=c(),$s=l("span"),ji=i("M\xE9tricas"),an=c(),Y=l("p"),Mi=i("De la misma manera que necesitas a\xF1adir una funci\xF3n de evaluaci\xF3n al "),Js=l("code"),$i=i("Trainer"),Ji=i(", necesitas hacer lo mismo cuando escribas tu propio ciclo de entrenamiento. Pero en lugar de calcular y reportar la m\xE9trica al final de cada \xE9poca, esta vez acumular\xE1s todos los batches con "),Na=l("a"),Ts=l("code"),Ti=i("add_batch"),_i=i(" y calcular\xE1s la m\xE9trica al final."),tn=c(),u(Ya.$$.fragment),sn=c(),it=l("a"),ln=c(),te=l("h2"),Re=l("a"),_s=l("span"),u(Va.$$.fragment),Ei=c(),Es=l("span"),ki=i("Recursos adicionales"),nn=c(),pt=l("p"),Zi=i("Para m\xE1s ejemplos de fine-tuning consulta:"),rn=c(),Ge=l("ul"),ks=l("li"),ct=l("p"),qa=l("a"),Ui=i("\u{1F917} Transformers Examples"),Ii=i(` incluye scripts
para entrenar tareas comunes de NLP en PyTorch y TensorFlow.`),Ci=c(),Zs=l("li"),dt=l("p"),mt=l("a"),Ri=i("\u{1F917} Transformers Notebooks"),Gi=i(" contiene varios notebooks sobre c\xF3mo aplicar fine-tuning a un modelo para tareas espec\xEDficas en PyTorch y TensorFlow."),this.h()},l(e){const s=Xc('[data-svelte="svelte-1phssyn"]',document.head);v=n(s,"META",{name:!0,content:!0}),s.forEach(a),J=d(e),w=n(e,"H1",{class:!0});var Pa=r(w);M=n(Pa,"A",{id:!0,class:!0,href:!0});var Us=r(M);k=n(Us,"SPAN",{});var Is=r(k);f($.$$.fragment,Is),Is.forEach(a),Us.forEach(a),W=d(Pa),Z=n(Pa,"SPAN",{});var Fi=r(Z);T=p(Fi,"Fine-tuning a un modelo pre-entrenado"),Fi.forEach(a),Pa.forEach(a),_=d(e),f(I.$$.fragment,e),Xe=d(e),Ha=n(e,"P",{});var Bi=r(Ha);Vn=p(Bi,"El uso de un modelo pre-entrenado tiene importantes ventajas. Reduce los costos de computaci\xF3n, la huella de carbono y te permite utilizar modelos de \xFAltima generaci\xF3n sin tener que entrenar uno desde cero."),Bi.forEach(a),Cs=d(e),A=n(e,"UL",{});var ut=r(A);Fe=n(ut,"LI",{});var pn=r(Fe);qn=p(pn,"Fine-tuning a un modelo pre-entrenado con \u{1F917} Transformers "),vt=n(pn,"CODE",{});var Ni=r(vt);Pn=p(Ni,"Trainer"),Ni.forEach(a),Hn=p(pn,"."),pn.forEach(a),xn=d(ut),wt=n(ut,"LI",{});var Yi=r(wt);Sn=p(Yi,"Fine-tuning a un modelo pre-entrenado en TensorFlow con Keras."),Yi.forEach(a),Dn=d(ut),jt=n(ut,"LI",{});var Vi=r(jt);Qn=p(Vi,"Fine-tuning a un modelo pre-entrenado en PyTorch nativo."),Vi.forEach(a),ut.forEach(a),Rs=d(e),xa=n(e,"A",{id:!0}),r(xa).forEach(a),Gs=d(e),V=n(e,"H2",{class:!0});var cn=r(V);le=n(cn,"A",{id:!0,class:!0,href:!0});var qi=r(le);Mt=n(qi,"SPAN",{});var Pi=r(Mt);f(Be.$$.fragment,Pi),Pi.forEach(a),qi.forEach(a),Ln=d(cn),$t=n(cn,"SPAN",{});var Hi=r($t);Kn=p(Hi,"Prepara un dataset"),Hi.forEach(a),cn.forEach(a),Ws=d(e),f(Ne.$$.fragment,e),zs=d(e),Sa=n(e,"P",{});var xi=r(Sa);On=p(xi,"Antes de aplicar fine-tuning a un modelo pre-entrenado, descarga un dataset y prep\xE1ralo para el entrenamiento. El tutorial anterior nos ense\xF1\xF3 c\xF3mo procesar los datos para el entrenamiento, y ahora es la oportunidad de poner a prueba estas habilidades."),xi.forEach(a),As=d(e),ne=n(e,"P",{});var dn=r(ne);er=p(dn,"Comienza cargando el dataset de "),Ye=n(dn,"A",{href:!0,rel:!0});var Si=r(Ye);ar=p(Si,"Yelp Reviews"),Si.forEach(a),tr=p(dn,":"),dn.forEach(a),Xs=d(e),f(Ve.$$.fragment,e),Fs=d(e),Da=n(e,"P",{});var Di=r(Da);sr=p(Di,"Como ya sabes, necesitas un tokenizador para procesar el texto e incluir una estrategia para el padding y el truncamiento para manejar cualquier longitud de secuencia variable. Para procesar tu dataset en un solo paso, utiliza el m\xE9todo de \u{1F917} Datasets map para aplicar una funci\xF3n de preprocesamiento sobre todo el dataset:"),Di.forEach(a),Bs=d(e),f(qe.$$.fragment,e),Ns=d(e),Qa=n(e,"P",{});var Qi=r(Qa);lr=p(Qi,"Si lo deseas, puedes crear un subconjunto m\xE1s peque\xF1o del dataset completo para aplicarle fine-tuning y as\xED reducir el tiempo."),Qi.forEach(a),Ys=d(e),f(Pe.$$.fragment,e),Vs=d(e),La=n(e,"A",{id:!0}),r(La).forEach(a),qs=d(e),q=n(e,"H2",{class:!0});var mn=r(q);re=n(mn,"A",{id:!0,class:!0,href:!0});var Li=r(re);Jt=n(Li,"SPAN",{});var Ki=r(Jt);f(He.$$.fragment,Ki),Ki.forEach(a),Li.forEach(a),nr=d(mn),Ka=n(mn,"SPAN",{});var Wi=r(Ka);rr=p(Wi,"Fine-tuning con "),Tt=n(Wi,"CODE",{});var Oi=r(Tt);or=p(Oi,"Trainer"),Oi.forEach(a),Wi.forEach(a),mn.forEach(a),Ps=d(e),f(xe.$$.fragment,e),Hs=d(e),X=n(e,"P",{});var ft=r(X);ir=p(ft,"\u{1F917} Transformers proporciona una clase "),_t=n(ft,"CODE",{});var ep=r(_t);pr=p(ep,"Trainer"),ep.forEach(a),cr=p(ft," optimizada para el entrenamiento de modelos de \u{1F917} Transformers, haciendo m\xE1s f\xE1cil el inicio del entrenamiento sin necesidad de escribir manualmente tu propio ciclo. La API del "),Et=n(ft,"CODE",{});var ap=r(Et);dr=p(ap,"Trainer"),ap.forEach(a),mr=p(ft," soporta una amplia gama de opciones de entrenamiento y caracter\xEDsticas como el logging, el gradient accumulation y el mixed precision."),ft.forEach(a),xs=d(e),oe=n(e,"P",{});var un=r(oe);ur=p(un,"Comienza cargando tu modelo y especifica el n\xFAmero de labels previstas. A partir del "),Se=n(un,"A",{href:!0,rel:!0});var tp=r(Se);fr=p(tp,"Card Dataset"),tp.forEach(a),hr=p(un," de Yelp Review, que como ya sabemos tiene 5 labels:"),un.forEach(a),Ss=d(e),f(De.$$.fragment,e),Ds=d(e),f(ie.$$.fragment,e),Qs=d(e),P=n(e,"H3",{class:!0});var fn=r(P);pe=n(fn,"A",{id:!0,class:!0,href:!0});var sp=r(pe);kt=n(sp,"SPAN",{});var lp=r(kt);f(Qe.$$.fragment,lp),lp.forEach(a),sp.forEach(a),yr=d(fn),Zt=n(fn,"SPAN",{});var np=r(Zt);br=p(np,"Hiperpar\xE1metros de entrenamiento"),np.forEach(a),fn.forEach(a),Ls=d(e),F=n(e,"P",{});var ht=r(F);gr=p(ht,"A continuaci\xF3n, crea una clase "),Ut=n(ht,"CODE",{});var rp=r(Ut);vr=p(rp,"TrainingArguments"),rp.forEach(a),wr=p(ht," que contenga todos los hiperpar\xE1metros que puedes ajustar as\xED como los indicadores para activar las diferentes opciones de entrenamiento. Para este tutorial puedes empezar con los "),Le=n(ht,"A",{href:!0,rel:!0});var op=r(Le);jr=p(op,"hiperpar\xE1metros"),op.forEach(a),Mr=p(ht," de entrenamiento por defecto, pero si\xE9ntete libre de experimentar con ellos para encontrar tu configuraci\xF3n \xF3ptima."),ht.forEach(a),Ks=d(e),Oa=n(e,"P",{});var ip=r(Oa);$r=p(ip,"Especifica d\xF3nde vas a guardar los checkpoints de tu entrenamiento:"),ip.forEach(a),Os=d(e),f(Ke.$$.fragment,e),el=d(e),H=n(e,"H3",{class:!0});var hn=r(H);ce=n(hn,"A",{id:!0,class:!0,href:!0});var pp=r(ce);It=n(pp,"SPAN",{});var cp=r(It);f(Oe.$$.fragment,cp),cp.forEach(a),pp.forEach(a),Jr=d(hn),Ct=n(hn,"SPAN",{});var dp=r(Ct);Tr=p(dp,"M\xE9tricas"),dp.forEach(a),hn.forEach(a),al=d(e),E=n(e,"P",{});var G=r(E);_r=p(G,"El "),Rt=n(G,"CODE",{});var mp=r(Rt);Er=p(mp,"Trainer"),mp.forEach(a),kr=p(G," no eval\xFAa autom\xE1ticamente el rendimiento del modelo durante el entrenamiento. Tendr\xE1s que pasarle a "),Gt=n(G,"CODE",{});var up=r(Gt);Zr=p(up,"Trainer"),up.forEach(a),Ur=p(G," una funci\xF3n para calcular y hacer un reporte de las m\xE9tricas. La biblioteca de \u{1F917} Datasets proporciona una funci\xF3n de "),ea=n(G,"A",{href:!0,rel:!0});var fp=r(ea);Wt=n(fp,"CODE",{});var hp=r(Wt);Ir=p(hp,"accuracy"),hp.forEach(a),fp.forEach(a),Cr=p(G," simple que puedes cargar con la funci\xF3n "),zt=n(G,"CODE",{});var yp=r(zt);Rr=p(yp,"load_metric"),yp.forEach(a),Gr=p(G," (ver este "),aa=n(G,"A",{href:!0,rel:!0});var bp=r(aa);Wr=p(bp,"tutorial"),bp.forEach(a),zr=p(G," para m\xE1s informaci\xF3n):"),G.forEach(a),tl=d(e),f(ta.$$.fragment,e),sl=d(e),C=n(e,"P",{});var We=r(C);Ar=p(We,"Define la funci\xF3n "),At=n(We,"CODE",{});var gp=r(At);Xr=p(gp,"compute"),gp.forEach(a),Fr=p(We," en "),Xt=n(We,"CODE",{});var vp=r(Xt);Br=p(vp,"metric"),vp.forEach(a),Nr=p(We," para calcular el accuracy de tus predicciones. Antes de pasar tus predicciones a "),Ft=n(We,"CODE",{});var wp=r(Ft);Yr=p(wp,"compute"),wp.forEach(a),Vr=p(We,", necesitas convertir las predicciones a logits (recuerda que todos los modelos de \u{1F917} Transformers devuelven logits)."),We.forEach(a),ll=d(e),f(sa.$$.fragment,e),nl=d(e),de=n(e,"P",{});var yn=r(de);qr=p(yn,"Si quieres controlar tus m\xE9tricas de evaluaci\xF3n durante el fine-tuning, especifica el par\xE1metro "),Bt=n(yn,"CODE",{});var jp=r(Bt);Pr=p(jp,"evaluation_strategy"),jp.forEach(a),Hr=p(yn," en tus argumentos de entrenamiento para que el modelo tenga en cuenta la m\xE9trica de evaluaci\xF3n al final de cada \xE9poca:"),yn.forEach(a),rl=d(e),f(la.$$.fragment,e),ol=d(e),x=n(e,"H3",{class:!0});var bn=r(x);me=n(bn,"A",{id:!0,class:!0,href:!0});var Mp=r(me);Nt=n(Mp,"SPAN",{});var $p=r(Nt);f(na.$$.fragment,$p),$p.forEach(a),Mp.forEach(a),xr=d(bn),Yt=n(bn,"SPAN",{});var Jp=r(Yt);Sr=p(Jp,"Trainer"),Jp.forEach(a),bn.forEach(a),il=d(e),ue=n(e,"P",{});var gn=r(ue);Dr=p(gn,"Crea un objeto "),Vt=n(gn,"CODE",{});var Tp=r(Vt);Qr=p(Tp,"Trainer"),Tp.forEach(a),Lr=p(gn," con tu modelo, argumentos de entrenamiento, datasets de entrenamiento y de prueba, y tu funci\xF3n de evaluaci\xF3n:"),gn.forEach(a),pl=d(e),f(ra.$$.fragment,e),cl=d(e),fe=n(e,"P",{});var vn=r(fe);Kr=p(vn,"A continuaci\xF3n, aplica fine-tuning a tu modelo llamando "),qt=n(vn,"CODE",{});var _p=r(qt);Or=p(_p,"train()"),_p.forEach(a),eo=p(vn,":"),vn.forEach(a),dl=d(e),f(oa.$$.fragment,e),ml=d(e),et=n(e,"A",{id:!0}),r(et).forEach(a),ul=d(e),S=n(e,"H2",{class:!0});var wn=r(S);he=n(wn,"A",{id:!0,class:!0,href:!0});var Ep=r(he);Pt=n(Ep,"SPAN",{});var kp=r(Pt);f(ia.$$.fragment,kp),kp.forEach(a),Ep.forEach(a),ao=d(wn),Ht=n(wn,"SPAN",{});var Zp=r(Ht);to=p(Zp,"Fine-tuning con Keras"),Zp.forEach(a),wn.forEach(a),fl=d(e),f(pa.$$.fragment,e),hl=d(e),at=n(e,"P",{});var Up=r(at);so=p(Up,"Los modelos de \u{1F917} Transformers tambi\xE9n permiten realizar el entrenamiento en TensorFlow con la API de Keras. Solo es necesario hacer algunos cambios antes de hacer fine-tuning."),Up.forEach(a),yl=d(e),D=n(e,"H3",{class:!0});var jn=r(D);ye=n(jn,"A",{id:!0,class:!0,href:!0});var Ip=r(ye);xt=n(Ip,"SPAN",{});var Cp=r(xt);f(ca.$$.fragment,Cp),Cp.forEach(a),Ip.forEach(a),lo=d(jn),St=n(jn,"SPAN",{});var Rp=r(St);no=p(Rp,"Convierte el dataset al formato de TensorFlow"),Rp.forEach(a),jn.forEach(a),bl=d(e),B=n(e,"P",{});var yt=r(B);ro=p(yt,"El "),Dt=n(yt,"CODE",{});var Gp=r(Dt);oo=p(Gp,"DefaultDataCollator"),Gp.forEach(a),io=p(yt," junta los tensores en un batch para que el modelo se entrene en \xE9l. Aseg\xFArate de especificar "),Qt=n(yt,"CODE",{});var Wp=r(Qt);po=p(Wp,"return_tensors"),Wp.forEach(a),co=p(yt," para devolver los tensores de TensorFlow:"),yt.forEach(a),gl=d(e),f(da.$$.fragment,e),vl=d(e),f(be.$$.fragment,e),wl=d(e),R=n(e,"P",{});var ze=r(R);mo=p(ze,"A continuaci\xF3n, convierte los datasets tokenizados en datasets de TensorFlow con el m\xE9todo "),ma=n(ze,"A",{href:!0,rel:!0});var zp=r(ma);Lt=n(zp,"CODE",{});var Ap=r(Lt);uo=p(Ap,"to_tf_dataset"),Ap.forEach(a),zp.forEach(a),fo=p(ze,". Especifica tus entradas en "),Kt=n(ze,"CODE",{});var Xp=r(Kt);ho=p(Xp,"columns"),Xp.forEach(a),yo=p(ze," y tu etiqueta en "),Ot=n(ze,"CODE",{});var Fp=r(Ot);bo=p(Fp,"label_cols"),Fp.forEach(a),go=p(ze,":"),ze.forEach(a),jl=d(e),f(ua.$$.fragment,e),Ml=d(e),Q=n(e,"H3",{class:!0});var Mn=r(Q);ge=n(Mn,"A",{id:!0,class:!0,href:!0});var Bp=r(ge);es=n(Bp,"SPAN",{});var Np=r(es);f(fa.$$.fragment,Np),Np.forEach(a),Bp.forEach(a),vo=d(Mn),as=n(Mn,"SPAN",{});var Yp=r(as);wo=p(Yp,"Compila y ajusta"),Yp.forEach(a),Mn.forEach(a),$l=d(e),tt=n(e,"P",{});var Vp=r(tt);jo=p(Vp,"Carguemos un modelo TensorFlow con el n\xFAmero esperado de labels:"),Vp.forEach(a),Jl=d(e),f(ha.$$.fragment,e),Tl=d(e),ve=n(e,"P",{});var $n=r(ve);Mo=p($n,"A continuaci\xF3n, compila y aplica fine-tuning a tu modelo con "),ya=n($n,"A",{href:!0,rel:!0});var qp=r(ya);ts=n(qp,"CODE",{});var Pp=r(ts);$o=p(Pp,"fit"),Pp.forEach(a),qp.forEach(a),Jo=p($n," como lo har\xEDas con cualquier otro modelo de Keras:"),$n.forEach(a),_l=d(e),f(ba.$$.fragment,e),El=d(e),st=n(e,"A",{id:!0}),r(st).forEach(a),kl=d(e),L=n(e,"H2",{class:!0});var Jn=r(L);we=n(Jn,"A",{id:!0,class:!0,href:!0});var Hp=r(we);ss=n(Hp,"SPAN",{});var xp=r(ss);f(ga.$$.fragment,xp),xp.forEach(a),Hp.forEach(a),To=d(Jn),ls=n(Jn,"SPAN",{});var Sp=r(ls);_o=p(Sp,"Fine-tune en PyTorch nativo"),Sp.forEach(a),Jn.forEach(a),Zl=d(e),f(va.$$.fragment,e),Ul=d(e),je=n(e,"P",{});var Tn=r(je);Eo=p(Tn,"El "),ns=n(Tn,"CODE",{});var Dp=r(ns);ko=p(Dp,"Trainer"),Dp.forEach(a),Zo=p(Tn," se encarga del ciclo de entrenamiento y permite aplicar fine-tuning a un modelo en una sola l\xEDnea de c\xF3digo. Para los que prefieran escribir su propio ciclo de entrenamiento, tambi\xE9n pueden aplicar fine-tuning a un modelo de \u{1F917} Transformers en PyTorch nativo."),Tn.forEach(a),Il=d(e),lt=n(e,"P",{});var Qp=r(lt);Uo=p(Qp,"En este punto, es posible que necesites reiniciar tu notebook o ejecutar el siguiente c\xF3digo para liberar algo de memoria:"),Qp.forEach(a),Cl=d(e),f(wa.$$.fragment,e),Rl=d(e),Me=n(e,"P",{});var _n=r(Me);Io=p(_n,"A continuaci\xF3n, haremos un post-procesamiento manual al "),rs=n(_n,"CODE",{});var Lp=r(rs);Co=p(Lp,"tokenized_dataset"),Lp.forEach(a),Ro=p(_n," y as\xED prepararlo para el entrenamiento."),_n.forEach(a),Gl=d(e),N=n(e,"OL",{});var bt=r(N);ja=n(bt,"LI",{});var En=r(ja);Ma=n(En,"P",{});var kn=r(Ma);Go=p(kn,"Elimina la columna de "),os=n(kn,"CODE",{});var Kp=r(os);Wo=p(Kp,"text"),Kp.forEach(a),zo=p(kn," porque el modelo no acepta texto en crudo como entrada:"),kn.forEach(a),Ao=d(En),f($a.$$.fragment,En),En.forEach(a),Xo=d(bt),Ja=n(bt,"LI",{});var Zn=r(Ja);z=n(Zn,"P",{});var Ae=r(z);Fo=p(Ae,"Cambia el nombre de la columna de "),is=n(Ae,"CODE",{});var Op=r(is);Bo=p(Op,"label"),Op.forEach(a),No=p(Ae," a "),ps=n(Ae,"CODE",{});var ec=r(ps);Yo=p(ec,"labels"),ec.forEach(a),Vo=p(Ae," porque el modelo espera que el argumento se llame "),cs=n(Ae,"CODE",{});var ac=r(cs);qo=p(ac,"labels"),ac.forEach(a),Po=p(Ae,":"),Ae.forEach(a),Ho=d(Zn),f(Ta.$$.fragment,Zn),Zn.forEach(a),xo=d(bt),_a=n(bt,"LI",{});var Un=r(_a);ds=n(Un,"P",{});var tc=r(ds);So=p(tc,"Establece el formato del dataset para devolver tensores PyTorch en lugar de listas:"),tc.forEach(a),Do=d(Un),f(Ea.$$.fragment,Un),Un.forEach(a),bt.forEach(a),Wl=d(e),nt=n(e,"P",{});var sc=r(nt);Qo=p(sc,"A continuaci\xF3n, crea un subconjunto m\xE1s peque\xF1o del dataset como se ha mostrado anteriormente para acelerar el fine-tuning:"),sc.forEach(a),zl=d(e),f(ka.$$.fragment,e),Al=d(e),K=n(e,"H3",{class:!0});var In=r(K);$e=n(In,"A",{id:!0,class:!0,href:!0});var lc=r($e);ms=n(lc,"SPAN",{});var nc=r(ms);f(Za.$$.fragment,nc),nc.forEach(a),lc.forEach(a),Lo=d(In),us=n(In,"SPAN",{});var rc=r(us);Ko=p(rc,"DataLoader"),rc.forEach(a),In.forEach(a),Xl=d(e),Je=n(e,"P",{});var Cn=r(Je);Oo=p(Cn,"Crea un "),fs=n(Cn,"CODE",{});var oc=r(fs);ei=p(oc,"DataLoader"),oc.forEach(a),ai=p(Cn," para tus datasets de entrenamiento y de prueba para poder iterar sobre batches de datos:"),Cn.forEach(a),Fl=d(e),f(Ua.$$.fragment,e),Bl=d(e),rt=n(e,"P",{});var ic=r(rt);ti=p(ic,"Carga tu modelo con el n\xFAmero de labels previstas:"),ic.forEach(a),Nl=d(e),f(Ia.$$.fragment,e),Yl=d(e),O=n(e,"H3",{class:!0});var Rn=r(O);Te=n(Rn,"A",{id:!0,class:!0,href:!0});var pc=r(Te);hs=n(pc,"SPAN",{});var cc=r(hs);f(Ca.$$.fragment,cc),cc.forEach(a),pc.forEach(a),si=d(Rn),ys=n(Rn,"SPAN",{});var dc=r(ys);li=p(dc,"Optimiza y programa el learning rate"),dc.forEach(a),Rn.forEach(a),Vl=d(e),_e=n(e,"P",{});var Gn=r(_e);ni=p(Gn,"Crea un optimizador y el learning rate para aplicar fine-tuning al modelo. Vamos a utilizar el optimizador "),Ra=n(Gn,"A",{href:!0,rel:!0});var mc=r(Ra);bs=n(mc,"CODE",{});var uc=r(bs);ri=p(uc,"AdamW"),uc.forEach(a),mc.forEach(a),oi=p(Gn," de PyTorch:"),Gn.forEach(a),ql=d(e),f(Ga.$$.fragment,e),Pl=d(e),Ee=n(e,"P",{});var Wn=r(Ee);ii=p(Wn,"Crea el learning rate desde el "),gs=n(Wn,"CODE",{});var fc=r(gs);pi=p(fc,"Trainer"),fc.forEach(a),ci=p(Wn,":"),Wn.forEach(a),Hl=d(e),f(Wa.$$.fragment,e),xl=d(e),ke=n(e,"P",{});var zn=r(ke);di=p(zn,"Por \xFAltimo, especifica el "),vs=n(zn,"CODE",{});var hc=r(vs);mi=p(hc,"device"),hc.forEach(a),ui=p(zn," o entorno de ejecuci\xF3n para utilizar una GPU si tienes acceso a una. De lo contrario, el entrenamiento en una CPU puede llevarte varias horas en lugar de un par de minutos."),zn.forEach(a),Sl=d(e),f(za.$$.fragment,e),Dl=d(e),f(Ze.$$.fragment,e),Ql=d(e),ot=n(e,"P",{});var yc=r(ot);fi=p(yc,"Genial, \xA1ahora podemos entrenar! \u{1F973}"),yc.forEach(a),Ll=d(e),ee=n(e,"H3",{class:!0});var An=r(ee);Ue=n(An,"A",{id:!0,class:!0,href:!0});var bc=r(Ue);ws=n(bc,"SPAN",{});var gc=r(ws);f(Aa.$$.fragment,gc),gc.forEach(a),bc.forEach(a),hi=d(An),js=n(An,"SPAN",{});var vc=r(js);yi=p(vc,"Ciclo de entrenamiento"),vc.forEach(a),An.forEach(a),Kl=d(e),Ie=n(e,"P",{});var Xn=r(Ie);bi=p(Xn,"Para hacer un seguimiento al progreso del entrenamiento, utiliza la biblioteca "),Xa=n(Xn,"A",{href:!0,rel:!0});var wc=r(Xa);gi=p(wc,"tqdm"),wc.forEach(a),vi=p(Xn," para a\xF1adir una barra de progreso sobre el n\xFAmero de pasos de entrenamiento:"),Xn.forEach(a),Ol=d(e),f(Fa.$$.fragment,e),en=d(e),ae=n(e,"H3",{class:!0});var Fn=r(ae);Ce=n(Fn,"A",{id:!0,class:!0,href:!0});var jc=r(Ce);Ms=n(jc,"SPAN",{});var Mc=r(Ms);f(Ba.$$.fragment,Mc),Mc.forEach(a),jc.forEach(a),wi=d(Fn),$s=n(Fn,"SPAN",{});var $c=r($s);ji=p($c,"M\xE9tricas"),$c.forEach(a),Fn.forEach(a),an=d(e),Y=n(e,"P",{});var gt=r(Y);Mi=p(gt,"De la misma manera que necesitas a\xF1adir una funci\xF3n de evaluaci\xF3n al "),Js=n(gt,"CODE",{});var Jc=r(Js);$i=p(Jc,"Trainer"),Jc.forEach(a),Ji=p(gt,", necesitas hacer lo mismo cuando escribas tu propio ciclo de entrenamiento. Pero en lugar de calcular y reportar la m\xE9trica al final de cada \xE9poca, esta vez acumular\xE1s todos los batches con "),Na=n(gt,"A",{href:!0,rel:!0});var Tc=r(Na);Ts=n(Tc,"CODE",{});var _c=r(Ts);Ti=p(_c,"add_batch"),_c.forEach(a),Tc.forEach(a),_i=p(gt," y calcular\xE1s la m\xE9trica al final."),gt.forEach(a),tn=d(e),f(Ya.$$.fragment,e),sn=d(e),it=n(e,"A",{id:!0}),r(it).forEach(a),ln=d(e),te=n(e,"H2",{class:!0});var Bn=r(te);Re=n(Bn,"A",{id:!0,class:!0,href:!0});var Ec=r(Re);_s=n(Ec,"SPAN",{});var kc=r(_s);f(Va.$$.fragment,kc),kc.forEach(a),Ec.forEach(a),Ei=d(Bn),Es=n(Bn,"SPAN",{});var Zc=r(Es);ki=p(Zc,"Recursos adicionales"),Zc.forEach(a),Bn.forEach(a),nn=d(e),pt=n(e,"P",{});var Uc=r(pt);Zi=p(Uc,"Para m\xE1s ejemplos de fine-tuning consulta:"),Uc.forEach(a),rn=d(e),Ge=n(e,"UL",{});var Nn=r(Ge);ks=n(Nn,"LI",{});var Ic=r(ks);ct=n(Ic,"P",{});var zi=r(ct);qa=n(zi,"A",{href:!0,rel:!0});var Cc=r(qa);Ui=p(Cc,"\u{1F917} Transformers Examples"),Cc.forEach(a),Ii=p(zi,` incluye scripts
para entrenar tareas comunes de NLP en PyTorch y TensorFlow.`),zi.forEach(a),Ic.forEach(a),Ci=d(Nn),Zs=n(Nn,"LI",{});var Rc=r(Zs);dt=n(Rc,"P",{});var Ai=r(dt);mt=n(Ai,"A",{href:!0});var Gc=r(mt);Ri=p(Gc,"\u{1F917} Transformers Notebooks"),Gc.forEach(a),Gi=p(Ai," contiene varios notebooks sobre c\xF3mo aplicar fine-tuning a un modelo para tareas espec\xEDficas en PyTorch y TensorFlow."),Ai.forEach(a),Rc.forEach(a),Nn.forEach(a),this.h()},h(){m(v,"name","hf:doc:metadata"),m(v,"content",JSON.stringify(Pc)),m(M,"id","finetuning-a-un-modelo-preentrenado"),m(M,"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"),m(M,"href","#finetuning-a-un-modelo-preentrenado"),m(w,"class","relative group"),m(xa,"id","data-processing"),m(le,"id","prepara-un-dataset"),m(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"),m(le,"href","#prepara-un-dataset"),m(V,"class","relative group"),m(Ye,"href","https://huggingface.co/datasets/yelp_review_full"),m(Ye,"rel","nofollow"),m(La,"id","trainer"),m(re,"id","finetuning-con-trainer"),m(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"),m(re,"href","#finetuning-con-trainer"),m(q,"class","relative group"),m(Se,"href","https://huggingface.co/datasets/yelp_review_full#data-fields"),m(Se,"rel","nofollow"),m(pe,"id","hiperparmetros-de-entrenamiento"),m(pe,"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"),m(pe,"href","#hiperparmetros-de-entrenamiento"),m(P,"class","relative group"),m(Le,"href","https://huggingface.co/docs/transformers/main_classes/trainer#transformers.TrainingArguments"),m(Le,"rel","nofollow"),m(ce,"id","mtricas"),m(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"),m(ce,"href","#mtricas"),m(H,"class","relative group"),m(ea,"href","https://huggingface.co/metrics/accuracy"),m(ea,"rel","nofollow"),m(aa,"href","https://huggingface.co/docs/datasets/metrics.html"),m(aa,"rel","nofollow"),m(me,"id","trainer"),m(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"),m(me,"href","#trainer"),m(x,"class","relative group"),m(et,"id","keras"),m(he,"id","finetuning-con-keras"),m(he,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),m(he,"href","#finetuning-con-keras"),m(S,"class","relative group"),m(ye,"id","convierte-el-dataset-al-formato-de-tensorflow"),m(ye,"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"),m(ye,"href","#convierte-el-dataset-al-formato-de-tensorflow"),m(D,"class","relative group"),m(ma,"href","https://huggingface.co/docs/datasets/package_reference/main_classes.html#datasets.Dataset.to_tf_dataset"),m(ma,"rel","nofollow"),m(ge,"id","compila-y-ajusta"),m(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"),m(ge,"href","#compila-y-ajusta"),m(Q,"class","relative group"),m(ya,"href","https://keras.io/api/models/model_training_apis/"),m(ya,"rel","nofollow"),m(st,"id","pytorch_native"),m(we,"id","finetune-en-pytorch-nativo"),m(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"),m(we,"href","#finetune-en-pytorch-nativo"),m(L,"class","relative group"),m($e,"id","dataloader"),m($e,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),m($e,"href","#dataloader"),m(K,"class","relative group"),m(Te,"id","optimiza-y-programa-el-learning-rate"),m(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"),m(Te,"href","#optimiza-y-programa-el-learning-rate"),m(O,"class","relative group"),m(Ra,"href","https://pytorch.org/docs/stable/generated/torch.optim.AdamW.html"),m(Ra,"rel","nofollow"),m(Ue,"id","ciclo-de-entrenamiento"),m(Ue,"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"),m(Ue,"href","#ciclo-de-entrenamiento"),m(ee,"class","relative group"),m(Xa,"href","https://tqdm.github.io/"),m(Xa,"rel","nofollow"),m(Ce,"id","mtricas"),m(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"),m(Ce,"href","#mtricas"),m(ae,"class","relative group"),m(Na,"href","https://huggingface.co/docs/datasets/package_reference/main_classes.html?highlight=add_batch#datasets.Metric.add_batch"),m(Na,"rel","nofollow"),m(it,"id","additional-resources"),m(Re,"id","recursos-adicionales"),m(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"),m(Re,"href","#recursos-adicionales"),m(te,"class","relative group"),m(qa,"href","https://github.com/huggingface/transformers/tree/main/examples"),m(qa,"rel","nofollow"),m(mt,"href","notebooks")},m(e,s){t(document.head,v),o(e,J,s),o(e,w,s),t(w,M),t(M,k),h($,k,null),t(w,W),t(w,Z),t(Z,T),o(e,_,s),h(I,e,s),o(e,Xe,s),o(e,Ha,s),t(Ha,Vn),o(e,Cs,s),o(e,A,s),t(A,Fe),t(Fe,qn),t(Fe,vt),t(vt,Pn),t(Fe,Hn),t(A,xn),t(A,wt),t(wt,Sn),t(A,Dn),t(A,jt),t(jt,Qn),o(e,Rs,s),o(e,xa,s),o(e,Gs,s),o(e,V,s),t(V,le),t(le,Mt),h(Be,Mt,null),t(V,Ln),t(V,$t),t($t,Kn),o(e,Ws,s),h(Ne,e,s),o(e,zs,s),o(e,Sa,s),t(Sa,On),o(e,As,s),o(e,ne,s),t(ne,er),t(ne,Ye),t(Ye,ar),t(ne,tr),o(e,Xs,s),h(Ve,e,s),o(e,Fs,s),o(e,Da,s),t(Da,sr),o(e,Bs,s),h(qe,e,s),o(e,Ns,s),o(e,Qa,s),t(Qa,lr),o(e,Ys,s),h(Pe,e,s),o(e,Vs,s),o(e,La,s),o(e,qs,s),o(e,q,s),t(q,re),t(re,Jt),h(He,Jt,null),t(q,nr),t(q,Ka),t(Ka,rr),t(Ka,Tt),t(Tt,or),o(e,Ps,s),h(xe,e,s),o(e,Hs,s),o(e,X,s),t(X,ir),t(X,_t),t(_t,pr),t(X,cr),t(X,Et),t(Et,dr),t(X,mr),o(e,xs,s),o(e,oe,s),t(oe,ur),t(oe,Se),t(Se,fr),t(oe,hr),o(e,Ss,s),h(De,e,s),o(e,Ds,s),h(ie,e,s),o(e,Qs,s),o(e,P,s),t(P,pe),t(pe,kt),h(Qe,kt,null),t(P,yr),t(P,Zt),t(Zt,br),o(e,Ls,s),o(e,F,s),t(F,gr),t(F,Ut),t(Ut,vr),t(F,wr),t(F,Le),t(Le,jr),t(F,Mr),o(e,Ks,s),o(e,Oa,s),t(Oa,$r),o(e,Os,s),h(Ke,e,s),o(e,el,s),o(e,H,s),t(H,ce),t(ce,It),h(Oe,It,null),t(H,Jr),t(H,Ct),t(Ct,Tr),o(e,al,s),o(e,E,s),t(E,_r),t(E,Rt),t(Rt,Er),t(E,kr),t(E,Gt),t(Gt,Zr),t(E,Ur),t(E,ea),t(ea,Wt),t(Wt,Ir),t(E,Cr),t(E,zt),t(zt,Rr),t(E,Gr),t(E,aa),t(aa,Wr),t(E,zr),o(e,tl,s),h(ta,e,s),o(e,sl,s),o(e,C,s),t(C,Ar),t(C,At),t(At,Xr),t(C,Fr),t(C,Xt),t(Xt,Br),t(C,Nr),t(C,Ft),t(Ft,Yr),t(C,Vr),o(e,ll,s),h(sa,e,s),o(e,nl,s),o(e,de,s),t(de,qr),t(de,Bt),t(Bt,Pr),t(de,Hr),o(e,rl,s),h(la,e,s),o(e,ol,s),o(e,x,s),t(x,me),t(me,Nt),h(na,Nt,null),t(x,xr),t(x,Yt),t(Yt,Sr),o(e,il,s),o(e,ue,s),t(ue,Dr),t(ue,Vt),t(Vt,Qr),t(ue,Lr),o(e,pl,s),h(ra,e,s),o(e,cl,s),o(e,fe,s),t(fe,Kr),t(fe,qt),t(qt,Or),t(fe,eo),o(e,dl,s),h(oa,e,s),o(e,ml,s),o(e,et,s),o(e,ul,s),o(e,S,s),t(S,he),t(he,Pt),h(ia,Pt,null),t(S,ao),t(S,Ht),t(Ht,to),o(e,fl,s),h(pa,e,s),o(e,hl,s),o(e,at,s),t(at,so),o(e,yl,s),o(e,D,s),t(D,ye),t(ye,xt),h(ca,xt,null),t(D,lo),t(D,St),t(St,no),o(e,bl,s),o(e,B,s),t(B,ro),t(B,Dt),t(Dt,oo),t(B,io),t(B,Qt),t(Qt,po),t(B,co),o(e,gl,s),h(da,e,s),o(e,vl,s),h(be,e,s),o(e,wl,s),o(e,R,s),t(R,mo),t(R,ma),t(ma,Lt),t(Lt,uo),t(R,fo),t(R,Kt),t(Kt,ho),t(R,yo),t(R,Ot),t(Ot,bo),t(R,go),o(e,jl,s),h(ua,e,s),o(e,Ml,s),o(e,Q,s),t(Q,ge),t(ge,es),h(fa,es,null),t(Q,vo),t(Q,as),t(as,wo),o(e,$l,s),o(e,tt,s),t(tt,jo),o(e,Jl,s),h(ha,e,s),o(e,Tl,s),o(e,ve,s),t(ve,Mo),t(ve,ya),t(ya,ts),t(ts,$o),t(ve,Jo),o(e,_l,s),h(ba,e,s),o(e,El,s),o(e,st,s),o(e,kl,s),o(e,L,s),t(L,we),t(we,ss),h(ga,ss,null),t(L,To),t(L,ls),t(ls,_o),o(e,Zl,s),h(va,e,s),o(e,Ul,s),o(e,je,s),t(je,Eo),t(je,ns),t(ns,ko),t(je,Zo),o(e,Il,s),o(e,lt,s),t(lt,Uo),o(e,Cl,s),h(wa,e,s),o(e,Rl,s),o(e,Me,s),t(Me,Io),t(Me,rs),t(rs,Co),t(Me,Ro),o(e,Gl,s),o(e,N,s),t(N,ja),t(ja,Ma),t(Ma,Go),t(Ma,os),t(os,Wo),t(Ma,zo),t(ja,Ao),h($a,ja,null),t(N,Xo),t(N,Ja),t(Ja,z),t(z,Fo),t(z,is),t(is,Bo),t(z,No),t(z,ps),t(ps,Yo),t(z,Vo),t(z,cs),t(cs,qo),t(z,Po),t(Ja,Ho),h(Ta,Ja,null),t(N,xo),t(N,_a),t(_a,ds),t(ds,So),t(_a,Do),h(Ea,_a,null),o(e,Wl,s),o(e,nt,s),t(nt,Qo),o(e,zl,s),h(ka,e,s),o(e,Al,s),o(e,K,s),t(K,$e),t($e,ms),h(Za,ms,null),t(K,Lo),t(K,us),t(us,Ko),o(e,Xl,s),o(e,Je,s),t(Je,Oo),t(Je,fs),t(fs,ei),t(Je,ai),o(e,Fl,s),h(Ua,e,s),o(e,Bl,s),o(e,rt,s),t(rt,ti),o(e,Nl,s),h(Ia,e,s),o(e,Yl,s),o(e,O,s),t(O,Te),t(Te,hs),h(Ca,hs,null),t(O,si),t(O,ys),t(ys,li),o(e,Vl,s),o(e,_e,s),t(_e,ni),t(_e,Ra),t(Ra,bs),t(bs,ri),t(_e,oi),o(e,ql,s),h(Ga,e,s),o(e,Pl,s),o(e,Ee,s),t(Ee,ii),t(Ee,gs),t(gs,pi),t(Ee,ci),o(e,Hl,s),h(Wa,e,s),o(e,xl,s),o(e,ke,s),t(ke,di),t(ke,vs),t(vs,mi),t(ke,ui),o(e,Sl,s),h(za,e,s),o(e,Dl,s),h(Ze,e,s),o(e,Ql,s),o(e,ot,s),t(ot,fi),o(e,Ll,s),o(e,ee,s),t(ee,Ue),t(Ue,ws),h(Aa,ws,null),t(ee,hi),t(ee,js),t(js,yi),o(e,Kl,s),o(e,Ie,s),t(Ie,bi),t(Ie,Xa),t(Xa,gi),t(Ie,vi),o(e,Ol,s),h(Fa,e,s),o(e,en,s),o(e,ae,s),t(ae,Ce),t(Ce,Ms),h(Ba,Ms,null),t(ae,wi),t(ae,$s),t($s,ji),o(e,an,s),o(e,Y,s),t(Y,Mi),t(Y,Js),t(Js,$i),t(Y,Ji),t(Y,Na),t(Na,Ts),t(Ts,Ti),t(Y,_i),o(e,tn,s),h(Ya,e,s),o(e,sn,s),o(e,it,s),o(e,ln,s),o(e,te,s),t(te,Re),t(Re,_s),h(Va,_s,null),t(te,Ei),t(te,Es),t(Es,ki),o(e,nn,s),o(e,pt,s),t(pt,Zi),o(e,rn,s),o(e,Ge,s),t(Ge,ks),t(ks,ct),t(ct,qa),t(qa,Ui),t(ct,Ii),t(Ge,Ci),t(Ge,Zs),t(Zs,dt),t(dt,mt),t(mt,Ri),t(dt,Gi),on=!0},p(e,[s]){const Pa={};s&2&&(Pa.$$scope={dirty:s,ctx:e}),ie.$set(Pa);const Us={};s&2&&(Us.$$scope={dirty:s,ctx:e}),be.$set(Us);const Is={};s&2&&(Is.$$scope={dirty:s,ctx:e}),Ze.$set(Is)},i(e){on||(y($.$$.fragment,e),y(I.$$.fragment,e),y(Be.$$.fragment,e),y(Ne.$$.fragment,e),y(Ve.$$.fragment,e),y(qe.$$.fragment,e),y(Pe.$$.fragment,e),y(He.$$.fragment,e),y(xe.$$.fragment,e),y(De.$$.fragment,e),y(ie.$$.fragment,e),y(Qe.$$.fragment,e),y(Ke.$$.fragment,e),y(Oe.$$.fragment,e),y(ta.$$.fragment,e),y(sa.$$.fragment,e),y(la.$$.fragment,e),y(na.$$.fragment,e),y(ra.$$.fragment,e),y(oa.$$.fragment,e),y(ia.$$.fragment,e),y(pa.$$.fragment,e),y(ca.$$.fragment,e),y(da.$$.fragment,e),y(be.$$.fragment,e),y(ua.$$.fragment,e),y(fa.$$.fragment,e),y(ha.$$.fragment,e),y(ba.$$.fragment,e),y(ga.$$.fragment,e),y(va.$$.fragment,e),y(wa.$$.fragment,e),y($a.$$.fragment,e),y(Ta.$$.fragment,e),y(Ea.$$.fragment,e),y(ka.$$.fragment,e),y(Za.$$.fragment,e),y(Ua.$$.fragment,e),y(Ia.$$.fragment,e),y(Ca.$$.fragment,e),y(Ga.$$.fragment,e),y(Wa.$$.fragment,e),y(za.$$.fragment,e),y(Ze.$$.fragment,e),y(Aa.$$.fragment,e),y(Fa.$$.fragment,e),y(Ba.$$.fragment,e),y(Ya.$$.fragment,e),y(Va.$$.fragment,e),on=!0)},o(e){b($.$$.fragment,e),b(I.$$.fragment,e),b(Be.$$.fragment,e),b(Ne.$$.fragment,e),b(Ve.$$.fragment,e),b(qe.$$.fragment,e),b(Pe.$$.fragment,e),b(He.$$.fragment,e),b(xe.$$.fragment,e),b(De.$$.fragment,e),b(ie.$$.fragment,e),b(Qe.$$.fragment,e),b(Ke.$$.fragment,e),b(Oe.$$.fragment,e),b(ta.$$.fragment,e),b(sa.$$.fragment,e),b(la.$$.fragment,e),b(na.$$.fragment,e),b(ra.$$.fragment,e),b(oa.$$.fragment,e),b(ia.$$.fragment,e),b(pa.$$.fragment,e),b(ca.$$.fragment,e),b(da.$$.fragment,e),b(be.$$.fragment,e),b(ua.$$.fragment,e),b(fa.$$.fragment,e),b(ha.$$.fragment,e),b(ba.$$.fragment,e),b(ga.$$.fragment,e),b(va.$$.fragment,e),b(wa.$$.fragment,e),b($a.$$.fragment,e),b(Ta.$$.fragment,e),b(Ea.$$.fragment,e),b(ka.$$.fragment,e),b(Za.$$.fragment,e),b(Ua.$$.fragment,e),b(Ia.$$.fragment,e),b(Ca.$$.fragment,e),b(Ga.$$.fragment,e),b(Wa.$$.fragment,e),b(za.$$.fragment,e),b(Ze.$$.fragment,e),b(Aa.$$.fragment,e),b(Fa.$$.fragment,e),b(Ba.$$.fragment,e),b(Ya.$$.fragment,e),b(Va.$$.fragment,e),on=!1},d(e){a(v),e&&a(J),e&&a(w),g($),e&&a(_),g(I,e),e&&a(Xe),e&&a(Ha),e&&a(Cs),e&&a(A),e&&a(Rs),e&&a(xa),e&&a(Gs),e&&a(V),g(Be),e&&a(Ws),g(Ne,e),e&&a(zs),e&&a(Sa),e&&a(As),e&&a(ne),e&&a(Xs),g(Ve,e),e&&a(Fs),e&&a(Da),e&&a(Bs),g(qe,e),e&&a(Ns),e&&a(Qa),e&&a(Ys),g(Pe,e),e&&a(Vs),e&&a(La),e&&a(qs),e&&a(q),g(He),e&&a(Ps),g(xe,e),e&&a(Hs),e&&a(X),e&&a(xs),e&&a(oe),e&&a(Ss),g(De,e),e&&a(Ds),g(ie,e),e&&a(Qs),e&&a(P),g(Qe),e&&a(Ls),e&&a(F),e&&a(Ks),e&&a(Oa),e&&a(Os),g(Ke,e),e&&a(el),e&&a(H),g(Oe),e&&a(al),e&&a(E),e&&a(tl),g(ta,e),e&&a(sl),e&&a(C),e&&a(ll),g(sa,e),e&&a(nl),e&&a(de),e&&a(rl),g(la,e),e&&a(ol),e&&a(x),g(na),e&&a(il),e&&a(ue),e&&a(pl),g(ra,e),e&&a(cl),e&&a(fe),e&&a(dl),g(oa,e),e&&a(ml),e&&a(et),e&&a(ul),e&&a(S),g(ia),e&&a(fl),g(pa,e),e&&a(hl),e&&a(at),e&&a(yl),e&&a(D),g(ca),e&&a(bl),e&&a(B),e&&a(gl),g(da,e),e&&a(vl),g(be,e),e&&a(wl),e&&a(R),e&&a(jl),g(ua,e),e&&a(Ml),e&&a(Q),g(fa),e&&a($l),e&&a(tt),e&&a(Jl),g(ha,e),e&&a(Tl),e&&a(ve),e&&a(_l),g(ba,e),e&&a(El),e&&a(st),e&&a(kl),e&&a(L),g(ga),e&&a(Zl),g(va,e),e&&a(Ul),e&&a(je),e&&a(Il),e&&a(lt),e&&a(Cl),g(wa,e),e&&a(Rl),e&&a(Me),e&&a(Gl),e&&a(N),g($a),g(Ta),g(Ea),e&&a(Wl),e&&a(nt),e&&a(zl),g(ka,e),e&&a(Al),e&&a(K),g(Za),e&&a(Xl),e&&a(Je),e&&a(Fl),g(Ua,e),e&&a(Bl),e&&a(rt),e&&a(Nl),g(Ia,e),e&&a(Yl),e&&a(O),g(Ca),e&&a(Vl),e&&a(_e),e&&a(ql),g(Ga,e),e&&a(Pl),e&&a(Ee),e&&a(Hl),g(Wa,e),e&&a(xl),e&&a(ke),e&&a(Sl),g(za,e),e&&a(Dl),g(Ze,e),e&&a(Ql),e&&a(ot),e&&a(Ll),e&&a(ee),g(Aa),e&&a(Kl),e&&a(Ie),e&&a(Ol),g(Fa,e),e&&a(en),e&&a(ae),g(Ba),e&&a(an),e&&a(Y),e&&a(tn),g(Ya,e),e&&a(sn),e&&a(it),e&&a(ln),e&&a(te),g(Va),e&&a(nn),e&&a(pt),e&&a(rn),e&&a(Ge)}}}const Pc={local:"finetuning-a-un-modelo-preentrenado",sections:[{local:"prepara-un-dataset",title:"Prepara un dataset"},{local:"finetuning-con-trainer",sections:[{local:"hiperparmetros-de-entrenamiento",title:"Hiperpar\xE1metros de entrenamiento"},{local:"mtricas",title:"M\xE9tricas"},{local:"trainer",title:"Trainer"}],title:"Fine-tuning con `Trainer`"},{local:"finetuning-con-keras",sections:[{local:"convierte-el-dataset-al-formato-de-tensorflow",title:"Convierte el dataset al formato de TensorFlow"},{local:"compila-y-ajusta",title:"Compila y ajusta"}],title:"Fine-tuning con Keras"},{local:"finetune-en-pytorch-nativo",sections:[{local:"dataloader",title:"DataLoader"},{local:"optimiza-y-programa-el-learning-rate",title:"Optimiza y programa el learning rate"},{local:"ciclo-de-entrenamiento",title:"Ciclo de entrenamiento"},{local:"mtricas",title:"M\xE9tricas"}],title:"Fine-tune en PyTorch nativo"},{local:"recursos-adicionales",title:"Recursos adicionales"}],title:"Fine-tuning a un modelo pre-entrenado"};function Hc(se){return Fc(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Oc extends Wc{constructor(v){super();zc(this,v,Hc,qc,Ac,{})}}export{Oc as default,Pc as metadata};
