import{S as jl,i as yl,s as wl,e as p,k as h,w as C,t as n,M as Ul,c as i,d as s,m as j,a as c,x as b,h as r,b as T,G as a,g as m,y as _,q as E,o as I,B as A,v as Jl,L as hl}from"../../chunks/vendor-hf-doc-builder.js";import{T as Ya}from"../../chunks/Tip-hf-doc-builder.js";import{Y as dl}from"../../chunks/Youtube-hf-doc-builder.js";import{I as Fa}from"../../chunks/IconCopyLink-hf-doc-builder.js";import{C as te}from"../../chunks/CodeBlock-hf-doc-builder.js";import{F as fl,M as qa}from"../../chunks/Markdown-hf-doc-builder.js";import"../../chunks/IconTensorflow-hf-doc-builder.js";function Tl(R){let l,d,t,f,w;return{c(){l=p("p"),d=n("Revisa la "),t=p("a"),f=n("p\xE1gina de la tarea"),w=n(" de responder preguntas para tener m\xE1s informaci\xF3n sobre otras formas de responder preguntas y los modelos, datasets y m\xE9tricas asociadas."),this.h()},l(y){l=i(y,"P",{});var U=c(l);d=r(U,"Revisa la "),t=i(U,"A",{href:!0,rel:!0});var Z=c(t);f=r(Z,"p\xE1gina de la tarea"),Z.forEach(s),w=r(U," de responder preguntas para tener m\xE1s informaci\xF3n sobre otras formas de responder preguntas y los modelos, datasets y m\xE9tricas asociadas."),U.forEach(s),this.h()},h(){T(t,"href","https://huggingface.co/tasks/question-answering"),T(t,"rel","nofollow")},m(y,U){m(y,l,U),a(l,d),a(l,t),a(t,f),a(l,w)},d(y){y&&s(l)}}}function gl(R){let l,d;return l=new te({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMERlZmF1bHREYXRhQ29sbGF0b3IlMEElMEFkYXRhX2NvbGxhdG9yJTIwJTNEJTIwRGVmYXVsdERhdGFDb2xsYXRvcigp",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()`}}),{c(){C(l.$$.fragment)},l(t){b(l.$$.fragment,t)},m(t,f){_(l,t,f),d=!0},p:hl,i(t){d||(E(l.$$.fragment,t),d=!0)},o(t){I(l.$$.fragment,t),d=!1},d(t){A(l,t)}}}function $l(R){let l,d;return l=new qa({props:{$$slots:{default:[gl]},$$scope:{ctx:R}}}),{c(){C(l.$$.fragment)},l(t){b(l.$$.fragment,t)},m(t,f){_(l,t,f),d=!0},p(t,f){const w={};f&2&&(w.$$scope={dirty:f,ctx:t}),l.$set(w)},i(t){d||(E(l.$$.fragment,t),d=!0)},o(t){I(l.$$.fragment,t),d=!1},d(t){A(l,t)}}}function Cl(R){let l,d;return l=new te({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>)`}}),{c(){C(l.$$.fragment)},l(t){b(l.$$.fragment,t)},m(t,f){_(l,t,f),d=!0},p:hl,i(t){d||(E(l.$$.fragment,t),d=!0)},o(t){I(l.$$.fragment,t),d=!1},d(t){A(l,t)}}}function bl(R){let l,d;return l=new qa({props:{$$slots:{default:[Cl]},$$scope:{ctx:R}}}),{c(){C(l.$$.fragment)},l(t){b(l.$$.fragment,t)},m(t,f){_(l,t,f),d=!0},p(t,f){const w={};f&2&&(w.$$scope={dirty:f,ctx:t}),l.$set(w)},i(t){d||(E(l.$$.fragment,t),d=!0)},o(t){I(l.$$.fragment,t),d=!1},d(t){A(l,t)}}}function _l(R){let l,d,t,f,w,y,U,Z;return{c(){l=p("p"),d=n("Para familiarizarte con el fine-tuning con "),t=p("code"),f=n("Trainer"),w=n(", \xA1mira el tutorial b\xE1sico "),y=p("a"),U=n("aqu\xED"),Z=n("!"),this.h()},l(v){l=i(v,"P",{});var g=c(l);d=r(g,"Para familiarizarte con el fine-tuning con "),t=i(g,"CODE",{});var k=c(t);f=r(k,"Trainer"),k.forEach(s),w=r(g,", \xA1mira el tutorial b\xE1sico "),y=i(g,"A",{href:!0});var G=c(y);U=r(G,"aqu\xED"),G.forEach(s),Z=r(g,"!"),g.forEach(s),this.h()},h(){T(y,"href","../training#finetune-with-trainer")},m(v,g){m(v,l,g),a(l,d),a(l,t),a(t,f),a(l,w),a(l,y),a(y,U),a(l,Z)},d(v){v&&s(l)}}}function El(R){let l,d,t,f,w,y,U,Z,v,g,k,G,H,X,P,N,Q,oe,O,ne,F,pe,x,ie,V,ce,z,K,Y,re,me,q,D,B;return U=new te({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9Nb2RlbEZvclF1ZXN0aW9uQW5zd2VyaW5nJTJDJTIwVHJhaW5pbmdBcmd1bWVudHMlMkMlMjBUcmFpbmVyJTBBJTBBbW9kZWwlMjAlM0QlMjBBdXRvTW9kZWxGb3JRdWVzdGlvbkFuc3dlcmluZy5mcm9tX3ByZXRyYWluZWQoJTIyZGlzdGlsYmVydC1iYXNlLXVuY2FzZWQlMjIp",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoModelForQuestionAnswering, TrainingArguments, Trainer

<span class="hljs-meta">&gt;&gt;&gt; </span>model = AutoModelForQuestionAnswering.from_pretrained(<span class="hljs-string">&quot;distilbert-base-uncased&quot;</span>)`}}),v=new Ya({props:{$$slots:{default:[_l]},$$scope:{ctx:R}}}),D=new te({props:{code:"dHJhaW5pbmdfYXJncyUyMCUzRCUyMFRyYWluaW5nQXJndW1lbnRzKCUwQSUyMCUyMCUyMCUyMG91dHB1dF9kaXIlM0QlMjIuJTJGcmVzdWx0cyUyMiUyQyUwQSUyMCUyMCUyMCUyMGV2YWx1YXRpb25fc3RyYXRlZ3klM0QlMjJlcG9jaCUyMiUyQyUwQSUyMCUyMCUyMCUyMGxlYXJuaW5nX3JhdGUlM0QyZS01JTJDJTBBJTIwJTIwJTIwJTIwcGVyX2RldmljZV90cmFpbl9iYXRjaF9zaXplJTNEMTYlMkMlMEElMjAlMjAlMjAlMjBwZXJfZGV2aWNlX2V2YWxfYmF0Y2hfc2l6ZSUzRDE2JTJDJTBBJTIwJTIwJTIwJTIwbnVtX3RyYWluX2Vwb2NocyUzRDMlMkMlMEElMjAlMjAlMjAlMjB3ZWlnaHRfZGVjYXklM0QwLjAxJTJDJTBBKSUwQSUwQXRyYWluZXIlMjAlM0QlMjBUcmFpbmVyKCUwQSUyMCUyMCUyMCUyMG1vZGVsJTNEbW9kZWwlMkMlMEElMjAlMjAlMjAlMjBhcmdzJTNEdHJhaW5pbmdfYXJncyUyQyUwQSUyMCUyMCUyMCUyMHRyYWluX2RhdGFzZXQlM0R0b2tlbml6ZWRfc3F1YWQlNUIlMjJ0cmFpbiUyMiU1RCUyQyUwQSUyMCUyMCUyMCUyMGV2YWxfZGF0YXNldCUzRHRva2VuaXplZF9zcXVhZCU1QiUyMnZhbGlkYXRpb24lMjIlNUQlMkMlMEElMjAlMjAlMjAlMjB0b2tlbml6ZXIlM0R0b2tlbml6ZXIlMkMlMEElMjAlMjAlMjAlMjBkYXRhX2NvbGxhdG9yJTNEZGF0YV9jb2xsYXRvciUyQyUwQSklMEElMEF0cmFpbmVyLnRyYWluKCk=",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span>training_args = TrainingArguments(
<span class="hljs-meta">... </span>    output_dir=<span class="hljs-string">&quot;./results&quot;</span>,
<span class="hljs-meta">... </span>    evaluation_strategy=<span class="hljs-string">&quot;epoch&quot;</span>,
<span class="hljs-meta">... </span>    learning_rate=<span class="hljs-number">2e-5</span>,
<span class="hljs-meta">... </span>    per_device_train_batch_size=<span class="hljs-number">16</span>,
<span class="hljs-meta">... </span>    per_device_eval_batch_size=<span class="hljs-number">16</span>,
<span class="hljs-meta">... </span>    num_train_epochs=<span class="hljs-number">3</span>,
<span class="hljs-meta">... </span>    weight_decay=<span class="hljs-number">0.01</span>,
<span class="hljs-meta">... </span>)

<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=tokenized_squad[<span class="hljs-string">&quot;train&quot;</span>],
<span class="hljs-meta">... </span>    eval_dataset=tokenized_squad[<span class="hljs-string">&quot;validation&quot;</span>],
<span class="hljs-meta">... </span>    tokenizer=tokenizer,
<span class="hljs-meta">... </span>    data_collator=data_collator,
<span class="hljs-meta">... </span>)

<span class="hljs-meta">&gt;&gt;&gt; </span>trainer.train()`}}),{c(){l=p("p"),d=n("Carga el modelo DistilBERT con "),t=p("code"),f=n("AutoModelForQuestionAnswering"),w=n(":"),y=h(),C(U.$$.fragment),Z=h(),C(v.$$.fragment),g=h(),k=p("p"),G=n("En este punto, solo quedan tres pasos:"),H=h(),X=p("ol"),P=p("li"),N=n("Definir tus hiperpar\xE1metros de entrenamiento en "),Q=p("code"),oe=n("TrainingArguments"),O=n("."),ne=h(),F=p("li"),pe=n("Pasarle los argumentos del entrenamiento al "),x=p("code"),ie=n("Trainer"),V=n(" junto con el modelo, el dataset, el tokenizer y el collator de datos."),ce=h(),z=p("li"),K=n("Invocar el m\xE9todo "),Y=p("code"),re=n("train()"),me=n(" para realizar el fine-tuning del modelo."),q=h(),C(D.$$.fragment)},l(M){l=i(M,"P",{});var $=c(l);d=r($,"Carga el modelo DistilBERT con "),t=i($,"CODE",{});var S=c(t);f=r(S,"AutoModelForQuestionAnswering"),S.forEach(s),w=r($,":"),$.forEach(s),y=j(M),b(U.$$.fragment,M),Z=j(M),b(v.$$.fragment,M),g=j(M),k=i(M,"P",{});var ae=c(k);G=r(ae,"En este punto, solo quedan tres pasos:"),ae.forEach(s),H=j(M),X=i(M,"OL",{});var W=c(X);P=i(W,"LI",{});var ue=c(P);N=r(ue,"Definir tus hiperpar\xE1metros de entrenamiento en "),Q=i(ue,"CODE",{});var he=c(Q);oe=r(he,"TrainingArguments"),he.forEach(s),O=r(ue,"."),ue.forEach(s),ne=j(W),F=i(W,"LI",{});var L=c(F);pe=r(L,"Pasarle los argumentos del entrenamiento al "),x=i(L,"CODE",{});var se=c(x);ie=r(se,"Trainer"),se.forEach(s),V=r(L," junto con el modelo, el dataset, el tokenizer y el collator de datos."),L.forEach(s),ce=j(W),z=i(W,"LI",{});var le=c(z);K=r(le,"Invocar el m\xE9todo "),Y=i(le,"CODE",{});var o=c(Y);re=r(o,"train()"),o.forEach(s),me=r(le," para realizar el fine-tuning del modelo."),le.forEach(s),W.forEach(s),q=j(M),b(D.$$.fragment,M)},m(M,$){m(M,l,$),a(l,d),a(l,t),a(t,f),a(l,w),m(M,y,$),_(U,M,$),m(M,Z,$),_(v,M,$),m(M,g,$),m(M,k,$),a(k,G),m(M,H,$),m(M,X,$),a(X,P),a(P,N),a(P,Q),a(Q,oe),a(P,O),a(X,ne),a(X,F),a(F,pe),a(F,x),a(x,ie),a(F,V),a(X,ce),a(X,z),a(z,K),a(z,Y),a(Y,re),a(z,me),m(M,q,$),_(D,M,$),B=!0},p(M,$){const S={};$&2&&(S.$$scope={dirty:$,ctx:M}),v.$set(S)},i(M){B||(E(U.$$.fragment,M),E(v.$$.fragment,M),E(D.$$.fragment,M),B=!0)},o(M){I(U.$$.fragment,M),I(v.$$.fragment,M),I(D.$$.fragment,M),B=!1},d(M){M&&s(l),M&&s(y),A(U,M),M&&s(Z),A(v,M),M&&s(g),M&&s(k),M&&s(H),M&&s(X),M&&s(q),A(D,M)}}}function Il(R){let l,d;return l=new qa({props:{$$slots:{default:[El]},$$scope:{ctx:R}}}),{c(){C(l.$$.fragment)},l(t){b(l.$$.fragment,t)},m(t,f){_(l,t,f),d=!0},p(t,f){const w={};f&2&&(w.$$scope={dirty:f,ctx:t}),l.$set(w)},i(t){d||(E(l.$$.fragment,t),d=!0)},o(t){I(l.$$.fragment,t),d=!1},d(t){A(l,t)}}}function Al(R){let l,d,t,f,w;return{c(){l=p("p"),d=n("Para familiarizarte con el fine-tuning con Keras, \xA1mira el tutorial b\xE1sico "),t=p("a"),f=n("aqu\xED"),w=n("!"),this.h()},l(y){l=i(y,"P",{});var U=c(l);d=r(U,"Para familiarizarte con el fine-tuning con Keras, \xA1mira el tutorial b\xE1sico "),t=i(U,"A",{href:!0});var Z=c(t);f=r(Z,"aqu\xED"),Z.forEach(s),w=r(U,"!"),U.forEach(s),this.h()},h(){T(t,"href","training#finetune-with-keras")},m(y,U){m(y,l,U),a(l,d),a(l,t),a(t,f),a(l,w)},d(y){y&&s(l)}}}function vl(R){let l,d,t,f,w,y,U,Z,v,g,k,G,H,X,P,N,Q,oe,O,ne,F,pe,x,ie,V,ce,z,K,Y,re,me,q,D,B,M,$,S,ae,W,ue,he,L,se,le;return g=new te({props:{code:"dGZfdHJhaW5fc2V0JTIwJTNEJTIwbW9kZWwucHJlcGFyZV90Zl9kYXRhc2V0KCUwQSUyMCUyMCUyMCUyMHRva2VuaXplZF9zcXVhZCU1QiUyMnRyYWluJTIyJTVEJTJDJTBBJTIwJTIwJTIwJTIwc2h1ZmZsZSUzRFRydWUlMkMlMEElMjAlMjAlMjAlMjBiYXRjaF9zaXplJTNEMTYlMkMlMEElMjAlMjAlMjAlMjBjb2xsYXRlX2ZuJTNEZGF0YV9jb2xsYXRvciUyQyUwQSklMEElMEF0Zl92YWxpZGF0aW9uX3NldCUyMCUzRCUyMG1vZGVsLnByZXBhcmVfdGZfZGF0YXNldCglMEElMjAlMjAlMjAlMjB0b2tlbml6ZWRfc3F1YWQlNUIlMjJ2YWxpZGF0aW9uJTIyJTVEJTJDJTBBJTIwJTIwJTIwJTIwc2h1ZmZsZSUzREZhbHNlJTJDJTBBJTIwJTIwJTIwJTIwYmF0Y2hfc2l6ZSUzRDE2JTJDJTBBJTIwJTIwJTIwJTIwY29sbGF0ZV9mbiUzRGRhdGFfY29sbGF0b3IlMkMlMEEp",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span>tf_train_set = model.prepare_tf_dataset(
<span class="hljs-meta">... </span>    tokenized_squad[<span class="hljs-string">&quot;train&quot;</span>],
<span class="hljs-meta">... </span>    shuffle=<span class="hljs-literal">True</span>,
<span class="hljs-meta">... </span>    batch_size=<span class="hljs-number">16</span>,
<span class="hljs-meta">... </span>    collate_fn=data_collator,
<span class="hljs-meta">... </span>)

<span class="hljs-meta">&gt;&gt;&gt; </span>tf_validation_set = model.prepare_tf_dataset(
<span class="hljs-meta">... </span>    tokenized_squad[<span class="hljs-string">&quot;validation&quot;</span>],
<span class="hljs-meta">... </span>    shuffle=<span class="hljs-literal">False</span>,
<span class="hljs-meta">... </span>    batch_size=<span class="hljs-number">16</span>,
<span class="hljs-meta">... </span>    collate_fn=data_collator,
<span class="hljs-meta">... </span>)`}}),G=new Ya({props:{$$slots:{default:[Al]},$$scope:{ctx:R}}}),Q=new te({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMGNyZWF0ZV9vcHRpbWl6ZXIlMEElMEFiYXRjaF9zaXplJTIwJTNEJTIwMTYlMEFudW1fZXBvY2hzJTIwJTNEJTIwMiUwQXRvdGFsX3RyYWluX3N0ZXBzJTIwJTNEJTIwKGxlbih0b2tlbml6ZWRfc3F1YWQlNUIlMjJ0cmFpbiUyMiU1RCklMjAlMkYlMkYlMjBiYXRjaF9zaXplKSUyMColMjBudW1fZXBvY2hzJTBBb3B0aW1pemVyJTJDJTIwc2NoZWR1bGUlMjAlM0QlMjBjcmVhdGVfb3B0aW1pemVyKCUwQSUyMCUyMCUyMCUyMGluaXRfbHIlM0QyZS01JTJDJTBBJTIwJTIwJTIwJTIwbnVtX3dhcm11cF9zdGVwcyUzRDAlMkMlMEElMjAlMjAlMjAlMjBudW1fdHJhaW5fc3RlcHMlM0R0b3RhbF90cmFpbl9zdGVwcyUyQyUwQSk=",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> create_optimizer

<span class="hljs-meta">&gt;&gt;&gt; </span>batch_size = <span class="hljs-number">16</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>num_epochs = <span class="hljs-number">2</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>total_train_steps = (<span class="hljs-built_in">len</span>(tokenized_squad[<span class="hljs-string">&quot;train&quot;</span>]) // batch_size) * num_epochs
<span class="hljs-meta">&gt;&gt;&gt; </span>optimizer, schedule = create_optimizer(
<span class="hljs-meta">... </span>    init_lr=<span class="hljs-number">2e-5</span>,
<span class="hljs-meta">... </span>    num_warmup_steps=<span class="hljs-number">0</span>,
<span class="hljs-meta">... </span>    num_train_steps=total_train_steps,
<span class="hljs-meta">... </span>)`}}),V=new te({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMFRGQXV0b01vZGVsRm9yUXVlc3Rpb25BbnN3ZXJpbmclMEElMEFtb2RlbCUyMCUzRCUyMFRGQXV0b01vZGVsRm9yUXVlc3Rpb25BbnN3ZXJpbmcoJTIyZGlzdGlsYmVydC1iYXNlLXVuY2FzZWQlMjIp",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> TFAutoModelForQuestionAnswering

<span class="hljs-meta">&gt;&gt;&gt; </span>model = TFAutoModelForQuestionAnswering(<span class="hljs-string">&quot;distilbert-base-uncased&quot;</span>)`}}),B=new te({props:{code:"aW1wb3J0JTIwdGVuc29yZmxvdyUyMGFzJTIwdGYlMEElMEFtb2RlbC5jb21waWxlKG9wdGltaXplciUzRG9wdGltaXplcik=",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>model.<span class="hljs-built_in">compile</span>(optimizer=optimizer)`}}),se=new te({props:{code:"bW9kZWwuZml0KHglM0R0Zl90cmFpbl9zZXQlMkMlMjB2YWxpZGF0aW9uX2RhdGElM0R0Zl92YWxpZGF0aW9uX3NldCUyQyUyMGVwb2NocyUzRDMp",highlighted:'<span class="hljs-meta">&gt;&gt;&gt; </span>model.fit(x=tf_train_set, validation_data=tf_validation_set, epochs=<span class="hljs-number">3</span>)'}}),{c(){l=p("p"),d=n("Para realizar el fine-tuning de un modelo en TensorFlow, primero convierte tus datasets al formato "),t=p("code"),f=n("tf.data.Dataset"),w=n(" con el m\xE9todo "),y=p("code"),U=n("prepare_tf_dataset()"),Z=n("."),v=h(),C(g.$$.fragment),k=h(),C(G.$$.fragment),H=h(),X=p("p"),P=n("Prepara una funci\xF3n de optimizaci\xF3n, un programa para la tasa de aprendizaje y algunos hiperpar\xE1metros de entrenamiento:"),N=h(),C(Q.$$.fragment),oe=h(),O=p("p"),ne=n("Carga el modelo DistilBERT con "),F=p("code"),pe=n("TFAutoModelForQuestionAnswering"),x=n(":"),ie=h(),C(V.$$.fragment),ce=h(),z=p("p"),K=n("Configura el modelo para entrenarlo con "),Y=p("a"),re=p("code"),me=n("compile"),q=n(":"),D=h(),C(B.$$.fragment),M=h(),$=p("p"),S=n("Invoca el m\xE9todo "),ae=p("a"),W=p("code"),ue=n("fit"),he=n(" para realizar el fine-tuning del modelo:"),L=h(),C(se.$$.fragment),this.h()},l(o){l=i(o,"P",{});var J=c(l);d=r(J,"Para realizar el fine-tuning de un modelo en TensorFlow, primero convierte tus datasets al formato "),t=i(J,"CODE",{});var Me=c(t);f=r(Me,"tf.data.Dataset"),Me.forEach(s),w=r(J," con el m\xE9todo "),y=i(J,"CODE",{});var Ye=c(y);U=r(Ye,"prepare_tf_dataset()"),Ye.forEach(s),Z=r(J,"."),J.forEach(s),v=j(o),b(g.$$.fragment,o),k=j(o),b(G.$$.fragment,o),H=j(o),X=i(o,"P",{});var Re=c(X);P=r(Re,"Prepara una funci\xF3n de optimizaci\xF3n, un programa para la tasa de aprendizaje y algunos hiperpar\xE1metros de entrenamiento:"),Re.forEach(s),N=j(o),b(Q.$$.fragment,o),oe=j(o),O=i(o,"P",{});var de=c(O);ne=r(de,"Carga el modelo DistilBERT con "),F=i(de,"CODE",{});var Ge=c(F);pe=r(Ge,"TFAutoModelForQuestionAnswering"),Ge.forEach(s),x=r(de,":"),de.forEach(s),ie=j(o),b(V.$$.fragment,o),ce=j(o),z=i(o,"P",{});var ee=c(z);K=r(ee,"Configura el modelo para entrenarlo con "),Y=i(ee,"A",{href:!0,rel:!0});var qe=c(Y);re=i(qe,"CODE",{});var $e=c(re);me=r($e,"compile"),$e.forEach(s),qe.forEach(s),q=r(ee,":"),ee.forEach(s),D=j(o),b(B.$$.fragment,o),M=j(o),$=i(o,"P",{});var Ce=c($);S=r(Ce,"Invoca el m\xE9todo "),ae=i(Ce,"A",{href:!0,rel:!0});var De=c(ae);W=i(De,"CODE",{});var be=c(W);ue=r(be,"fit"),be.forEach(s),De.forEach(s),he=r(Ce," para realizar el fine-tuning del modelo:"),Ce.forEach(s),L=j(o),b(se.$$.fragment,o),this.h()},h(){T(Y,"href","https://keras.io/api/models/model_training_apis/#compile-method"),T(Y,"rel","nofollow"),T(ae,"href","https://keras.io/api/models/model_training_apis/#fit-method"),T(ae,"rel","nofollow")},m(o,J){m(o,l,J),a(l,d),a(l,t),a(t,f),a(l,w),a(l,y),a(y,U),a(l,Z),m(o,v,J),_(g,o,J),m(o,k,J),_(G,o,J),m(o,H,J),m(o,X,J),a(X,P),m(o,N,J),_(Q,o,J),m(o,oe,J),m(o,O,J),a(O,ne),a(O,F),a(F,pe),a(O,x),m(o,ie,J),_(V,o,J),m(o,ce,J),m(o,z,J),a(z,K),a(z,Y),a(Y,re),a(re,me),a(z,q),m(o,D,J),_(B,o,J),m(o,M,J),m(o,$,J),a($,S),a($,ae),a(ae,W),a(W,ue),a($,he),m(o,L,J),_(se,o,J),le=!0},p(o,J){const Me={};J&2&&(Me.$$scope={dirty:J,ctx:o}),G.$set(Me)},i(o){le||(E(g.$$.fragment,o),E(G.$$.fragment,o),E(Q.$$.fragment,o),E(V.$$.fragment,o),E(B.$$.fragment,o),E(se.$$.fragment,o),le=!0)},o(o){I(g.$$.fragment,o),I(G.$$.fragment,o),I(Q.$$.fragment,o),I(V.$$.fragment,o),I(B.$$.fragment,o),I(se.$$.fragment,o),le=!1},d(o){o&&s(l),o&&s(v),A(g,o),o&&s(k),A(G,o),o&&s(H),o&&s(X),o&&s(N),A(Q,o),o&&s(oe),o&&s(O),o&&s(ie),A(V,o),o&&s(ce),o&&s(z),o&&s(D),A(B,o),o&&s(M),o&&s($),o&&s(L),A(se,o)}}}function Zl(R){let l,d;return l=new qa({props:{$$slots:{default:[vl]},$$scope:{ctx:R}}}),{c(){C(l.$$.fragment)},l(t){b(l.$$.fragment,t)},m(t,f){_(l,t,f),d=!0},p(t,f){const w={};f&2&&(w.$$scope={dirty:f,ctx:t}),l.$set(w)},i(t){d||(E(l.$$.fragment,t),d=!0)},o(t){I(l.$$.fragment,t),d=!1},d(t){A(l,t)}}}function kl(R){let l,d,t,f,w,y,U,Z;return{c(){l=p("p"),d=n(`Para un ejemplo con mayor profundidad de c\xF3mo hacer fine-tuning a un modelo para responder preguntas, \xE9chale un vistazo al
`),t=p("a"),f=n("cuaderno de PyTorch"),w=n(` o al
`),y=p("a"),U=n("cuaderno de TensorFlow"),Z=n(" correspondiente."),this.h()},l(v){l=i(v,"P",{});var g=c(l);d=r(g,`Para un ejemplo con mayor profundidad de c\xF3mo hacer fine-tuning a un modelo para responder preguntas, \xE9chale un vistazo al
`),t=i(g,"A",{href:!0,rel:!0});var k=c(t);f=r(k,"cuaderno de PyTorch"),k.forEach(s),w=r(g,` o al
`),y=i(g,"A",{href:!0,rel:!0});var G=c(y);U=r(G,"cuaderno de TensorFlow"),G.forEach(s),Z=r(g," correspondiente."),g.forEach(s),this.h()},h(){T(t,"href","https://colab.research.google.com/github/huggingface/notebooks/blob/main/examples/question_answering.ipynb"),T(t,"rel","nofollow"),T(y,"href","https://colab.research.google.com/github/huggingface/notebooks/blob/main/examples/question_answering-tf.ipynb"),T(y,"rel","nofollow")},m(v,g){m(v,l,g),a(l,d),a(l,t),a(t,f),a(l,w),a(l,y),a(y,U),a(l,Z)},d(v){v&&s(l)}}}function Rl(R){let l,d,t,f,w,y,U,Z,v,g,k,G,H,X,P,N,Q,oe,O,ne,F,pe,x,ie,V,ce,z,K,Y,re,me,q,D,B,M,$,S,ae,W,ue,he,L,se,le,o,J,Me,Ye,Re,de,Ge,ee,qe,$e,Ce,De,be,Da,Sa,Ta,Ue,_e,sa,Be,Ha,la,Pa,ga,Xe,$a,je,Oa,ta,La,Ka,na,es,as,Ca,xe,ba,Se,ss,_a,ye,Je,ls,ra,ts,ns,oa,rs,os,ps,Te,is,pa,cs,ms,ia,us,Ms,ds,ze,fs,Qe,ca,hs,js,Ea,Ee,ys,ma,ws,Us,Ia,Ve,Aa,fe,Js,ua,Ts,gs,Ma,$s,Cs,da,bs,_s,va,We,Za,we,Es,fa,Is,As,ha,vs,Zs,ka,Ie,Ra,ge,Ae,ja,Ne,ks,ya,Rs,Ga,ve,Ba,Ze,Xa;return y=new Fa({}),k=new dl({props:{id:"ajPx5LwJD-I"}}),q=new Ya({props:{$$slots:{default:[Tl]},$$scope:{ctx:R}}}),S=new Fa({}),o=new te({props:{code:"ZnJvbSUyMGRhdGFzZXRzJTIwaW1wb3J0JTIwbG9hZF9kYXRhc2V0JTBBJTBBc3F1YWQlMjAlM0QlMjBsb2FkX2RhdGFzZXQoJTIyc3F1YWQlMjIp",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>squad = load_dataset(<span class="hljs-string">&quot;squad&quot;</span>)`}}),de=new te({props:{code:"c3F1YWQlNUIlMjJ0cmFpbiUyMiU1RCU1QjAlNUQ=",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span>squad[<span class="hljs-string">&quot;train&quot;</span>][<span class="hljs-number">0</span>]
{<span class="hljs-string">&#x27;answers&#x27;</span>: {<span class="hljs-string">&#x27;answer_start&#x27;</span>: [<span class="hljs-number">515</span>], <span class="hljs-string">&#x27;text&#x27;</span>: [<span class="hljs-string">&#x27;Saint Bernadette Soubirous&#x27;</span>]},
 <span class="hljs-string">&#x27;context&#x27;</span>: <span class="hljs-string">&#x27;Architecturally, the school has a Catholic character. Atop the Main Building\\&#x27;s gold dome is a golden statue of the Virgin Mary. Immediately in front of the Main Building and facing it, is a copper statue of Christ with arms upraised with the legend &quot;Venite Ad Me Omnes&quot;. Next to the Main Building is the Basilica of the Sacred Heart. Immediately behind the basilica is the Grotto, a Marian place of prayer and reflection. It is a replica of the grotto at Lourdes, France where the Virgin Mary reputedly appeared to Saint Bernadette Soubirous in 1858. At the end of the main drive (and in a direct line that connects through 3 statues and the Gold Dome), is a simple, modern stone statue of Mary.&#x27;</span>,
 <span class="hljs-string">&#x27;id&#x27;</span>: <span class="hljs-string">&#x27;5733be284776f41900661182&#x27;</span>,
 <span class="hljs-string">&#x27;question&#x27;</span>: <span class="hljs-string">&#x27;To whom did the Virgin Mary allegedly appear in 1858 in Lourdes France?&#x27;</span>,
 <span class="hljs-string">&#x27;title&#x27;</span>: <span class="hljs-string">&#x27;University_of_Notre_Dame&#x27;</span>
}`}}),Be=new Fa({}),Xe=new dl({props:{id:"qgaM0weJHpA"}}),xe=new te({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9Ub2tlbml6ZXIlMEElMEF0b2tlbml6ZXIlMjAlM0QlMjBBdXRvVG9rZW5pemVyLmZyb21fcHJldHJhaW5lZCglMjJkaXN0aWxiZXJ0LWJhc2UtdW5jYXNlZCUyMik=",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;distilbert-base-uncased&quot;</span>)`}}),Ve=new te({props:{code:"ZGVmJTIwcHJlcHJvY2Vzc19mdW5jdGlvbihleGFtcGxlcyklM0ElMEElMjAlMjAlMjAlMjBxdWVzdGlvbnMlMjAlM0QlMjAlNUJxLnN0cmlwKCklMjBmb3IlMjBxJTIwaW4lMjBleGFtcGxlcyU1QiUyMnF1ZXN0aW9uJTIyJTVEJTVEJTBBJTIwJTIwJTIwJTIwaW5wdXRzJTIwJTNEJTIwdG9rZW5pemVyKCUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMHF1ZXN0aW9ucyUyQyUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMGV4YW1wbGVzJTVCJTIyY29udGV4dCUyMiU1RCUyQyUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMG1heF9sZW5ndGglM0QzODQlMkMlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjB0cnVuY2F0aW9uJTNEJTIyb25seV9zZWNvbmQlMjIlMkMlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjByZXR1cm5fb2Zmc2V0c19tYXBwaW5nJTNEVHJ1ZSUyQyUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMHBhZGRpbmclM0QlMjJtYXhfbGVuZ3RoJTIyJTJDJTBBJTIwJTIwJTIwJTIwKSUwQSUwQSUyMCUyMCUyMCUyMG9mZnNldF9tYXBwaW5nJTIwJTNEJTIwaW5wdXRzLnBvcCglMjJvZmZzZXRfbWFwcGluZyUyMiklMEElMjAlMjAlMjAlMjBhbnN3ZXJzJTIwJTNEJTIwZXhhbXBsZXMlNUIlMjJhbnN3ZXJzJTIyJTVEJTBBJTIwJTIwJTIwJTIwc3RhcnRfcG9zaXRpb25z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UzRCUyMGVuZF9wb3NpdGlvbnMlMEElMjAlMjAlMjAlMjByZXR1cm4lMjBpbnB1dHM=",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">def</span> <span class="hljs-title function_">preprocess_function</span>(<span class="hljs-params">examples</span>):
<span class="hljs-meta">... </span>    questions = [q.strip() <span class="hljs-keyword">for</span> q <span class="hljs-keyword">in</span> examples[<span class="hljs-string">&quot;question&quot;</span>]]
<span class="hljs-meta">... </span>    inputs = tokenizer(
<span class="hljs-meta">... </span>        questions,
<span class="hljs-meta">... </span>        examples[<span class="hljs-string">&quot;context&quot;</span>],
<span class="hljs-meta">... </span>        max_length=<span class="hljs-number">384</span>,
<span class="hljs-meta">... </span>        truncation=<span class="hljs-string">&quot;only_second&quot;</span>,
<span class="hljs-meta">... </span>        return_offsets_mapping=<span class="hljs-literal">True</span>,
<span class="hljs-meta">... </span>        padding=<span class="hljs-string">&quot;max_length&quot;</span>,
<span class="hljs-meta">... </span>    )

<span class="hljs-meta">... </span>    offset_mapping = inputs.pop(<span class="hljs-string">&quot;offset_mapping&quot;</span>)
<span class="hljs-meta">... </span>    answers = examples[<span class="hljs-string">&quot;answers&quot;</span>]
<span class="hljs-meta">... </span>    start_positions = []
<span class="hljs-meta">... </span>    end_positions = []

<span class="hljs-meta">... </span>    <span class="hljs-keyword">for</span> i, offset <span class="hljs-keyword">in</span> <span class="hljs-built_in">enumerate</span>(offset_mapping):
<span class="hljs-meta">... </span>        answer = answers[i]
<span class="hljs-meta">... </span>        start_char = answer[<span class="hljs-string">&quot;answer_start&quot;</span>][<span class="hljs-number">0</span>]
<span class="hljs-meta">... </span>        end_char = answer[<span class="hljs-string">&quot;answer_start&quot;</span>][<span class="hljs-number">0</span>] + <span class="hljs-built_in">len</span>(answer[<span class="hljs-string">&quot;text&quot;</span>][<span class="hljs-number">0</span>])
<span class="hljs-meta">... </span>        sequence_ids = inputs.sequence_ids(i)

<span class="hljs-meta">... </span>        <span class="hljs-comment"># Encuentra el inicio y el fin del contexto</span>
<span class="hljs-meta">... </span>        idx = <span class="hljs-number">0</span>
<span class="hljs-meta">... </span>        <span class="hljs-keyword">while</span> sequence_ids[idx] != <span class="hljs-number">1</span>:
<span class="hljs-meta">... </span>            idx += <span class="hljs-number">1</span>
<span class="hljs-meta">... </span>        context_start = idx
<span class="hljs-meta">... </span>        <span class="hljs-keyword">while</span> sequence_ids[idx] == <span class="hljs-number">1</span>:
<span class="hljs-meta">... </span>            idx += <span class="hljs-number">1</span>
<span class="hljs-meta">... </span>        context_end = idx - <span class="hljs-number">1</span>

<span class="hljs-meta">... </span>        <span class="hljs-comment"># Si la respuesta entera no est\xE1 dentro del contexto, etiqu\xE9tala como (0, 0)</span>
<span class="hljs-meta">... </span>        <span class="hljs-keyword">if</span> offset[context_start][<span class="hljs-number">0</span>] &gt; end_char <span class="hljs-keyword">or</span> offset[context_end][<span class="hljs-number">1</span>] &lt; start_char:
<span class="hljs-meta">... </span>            start_positions.append(<span class="hljs-number">0</span>)
<span class="hljs-meta">... </span>            end_positions.append(<span class="hljs-number">0</span>)
<span class="hljs-meta">... </span>        <span class="hljs-keyword">else</span>:
<span class="hljs-meta">... </span>            <span class="hljs-comment"># De lo contrario, esta es la posici\xF3n de los tokens de inicio y fin</span>
<span class="hljs-meta">... </span>            idx = context_start
<span class="hljs-meta">... </span>            <span class="hljs-keyword">while</span> idx &lt;= context_end <span class="hljs-keyword">and</span> offset[idx][<span class="hljs-number">0</span>] &lt;= start_char:
<span class="hljs-meta">... </span>                idx += <span class="hljs-number">1</span>
<span class="hljs-meta">... </span>            start_positions.append(idx - <span class="hljs-number">1</span>)

<span class="hljs-meta">... </span>            idx = context_end
<span class="hljs-meta">... </span>            <span class="hljs-keyword">while</span> idx &gt;= context_start <span class="hljs-keyword">and</span> offset[idx][<span class="hljs-number">1</span>] &gt;= end_char:
<span class="hljs-meta">... </span>                idx -= <span class="hljs-number">1</span>
<span class="hljs-meta">... </span>            end_positions.append(idx + <span class="hljs-number">1</span>)

<span class="hljs-meta">... </span>    inputs[<span class="hljs-string">&quot;start_positions&quot;</span>] = start_positions
<span class="hljs-meta">... </span>    inputs[<span class="hljs-string">&quot;end_positions&quot;</span>] = end_positions
<span class="hljs-meta">... </span>    <span class="hljs-keyword">return</span> inputs`}}),We=new te({props:{code:"dG9rZW5pemVkX3NxdWFkJTIwJTNEJTIwc3F1YWQubWFwKHByZXByb2Nlc3NfZnVuY3Rpb24lMkMlMjBiYXRjaGVkJTNEVHJ1ZSUyQyUyMHJlbW92ZV9jb2x1bW5zJTNEc3F1YWQlNUIlMjJ0cmFpbiUyMiU1RC5jb2x1bW5fbmFtZXMp",highlighted:'<span class="hljs-meta">&gt;&gt;&gt; </span>tokenized_squad = squad.<span class="hljs-built_in">map</span>(preprocess_function, batched=<span class="hljs-literal">True</span>, remove_columns=squad[<span class="hljs-string">&quot;train&quot;</span>].column_names)'}}),Ie=new fl({props:{pytorch:!0,tensorflow:!0,jax:!1,$$slots:{tensorflow:[bl],pytorch:[$l]},$$scope:{ctx:R}}}),Ne=new Fa({}),ve=new fl({props:{pytorch:!0,tensorflow:!0,jax:!1,$$slots:{tensorflow:[Zl],pytorch:[Il]},$$scope:{ctx:R}}}),Ze=new Ya({props:{$$slots:{default:[kl]},$$scope:{ctx:R}}}),{c(){l=p("meta"),d=h(),t=p("h1"),f=p("a"),w=p("span"),C(y.$$.fragment),U=h(),Z=p("span"),v=n("Respuesta a preguntas"),g=h(),C(k.$$.fragment),G=h(),H=p("p"),X=n("La respuesta a preguntas devuelve una respuesta a partir de una pregunta dada. Existen dos formas comunes de responder preguntas:"),P=h(),N=p("ul"),Q=p("li"),oe=n("Extractiva: extraer la respuesta a partir del contexto dado."),O=h(),ne=p("li"),F=n("Abstractiva: generar una respuesta que responda correctamente la pregunta a partir del contexto dado."),pe=h(),x=p("p"),ie=n("Esta gu\xEDa te mostrar\xE1 como hacer fine-tuning de "),V=p("a"),ce=n("DistilBERT"),z=n(" en el dataset "),K=p("a"),Y=n("SQuAD"),re=n(" para responder preguntas de forma extractiva."),me=h(),C(q.$$.fragment),D=h(),B=p("h2"),M=p("a"),$=p("span"),C(S.$$.fragment),ae=h(),W=p("span"),ue=n("Carga el dataset SQuAD"),he=h(),L=p("p"),se=n("Carga el dataset SQuAD con la biblioteca \u{1F917} Datasets:"),le=h(),C(o.$$.fragment),J=h(),Me=p("p"),Ye=n("Ahora, \xE9chale un vistazo a una muestra:"),Re=h(),C(de.$$.fragment),Ge=h(),ee=p("p"),qe=n("El campo "),$e=p("code"),Ce=n("answers"),De=n(" es un diccionario que contiene la posici\xF3n inicial de la respuesta y el "),be=p("code"),Da=n("texto"),Sa=n(" de la respuesta."),Ta=h(),Ue=p("h2"),_e=p("a"),sa=p("span"),C(Be.$$.fragment),Ha=h(),la=p("span"),Pa=n("Preprocesamiento"),ga=h(),C(Xe.$$.fragment),$a=h(),je=p("p"),Oa=n("Carga el tokenizer de DistilBERT para procesar los campos "),ta=p("code"),La=n("question"),Ka=n(" (pregunta) y "),na=p("code"),es=n("context"),as=n(" (contexto):"),Ca=h(),C(xe.$$.fragment),ba=h(),Se=p("p"),ss=n("Hay algunos pasos de preprocesamiento espec\xEDficos para la tarea de respuesta a preguntas que debes tener en cuenta:"),_a=h(),ye=p("ol"),Je=p("li"),ls=n("Algunos ejemplos en un dataset pueden tener un contexto que supera la longitud m\xE1xima de entrada de un modelo. Trunca solamente el contexto asign\xE1ndole el valor "),ra=p("code"),ts=n('"only_second"'),ns=n(" al par\xE1metro "),oa=p("code"),rs=n("truncation"),os=n("."),ps=h(),Te=p("li"),is=n("A continuaci\xF3n, mapea las posiciones de inicio y fin de la respuesta al contexto original asign\xE1ndole el valor "),pa=p("code"),cs=n("True"),ms=n(" al par\xE1metro "),ia=p("code"),us=n("return_offsets_mapping"),Ms=n("."),ds=h(),ze=p("li"),fs=n("Una vez tengas el mapeo, puedes encontrar los tokens de inicio y fin de la respuesta. Usa el m\xE9todo "),Qe=p("a"),ca=p("code"),hs=n("sequence_ids"),js=n(`
para encontrar qu\xE9 parte de la lista de tokens desplazados corresponde a la pregunta y cu\xE1l corresponde al contexto.`),Ea=h(),Ee=p("p"),ys=n("A continuaci\xF3n puedes ver como se crea una funci\xF3n para truncar y mapear los tokens de inicio y fin de la respuesta al "),ma=p("code"),ws=n("context"),Us=n(":"),Ia=h(),C(Ve.$$.fragment),Aa=h(),fe=p("p"),Js=n("Usa la funci\xF3n "),ua=p("code"),Ts=n("map"),gs=n(" de \u{1F917} Datasets para aplicarle la funci\xF3n de preprocesamiento al dataset entero. Puedes acelerar la funci\xF3n "),Ma=p("code"),$s=n("map"),Cs=n(" haciendo "),da=p("code"),bs=n("batched=True"),_s=n(` para procesar varios elementos del dataset a la vez.
Quita las columnas que no necesites:`),va=h(),C(We.$$.fragment),Za=h(),we=p("p"),Es=n("Usa el "),fa=p("code"),Is=n("DefaultDataCollator"),As=n(" para crear un lote de ejemplos. A diferencia de los otros collators de datos en \u{1F917} Transformers, el "),ha=p("code"),vs=n("DefaultDataCollator"),Zs=n(" no aplica ning\xFAn procesamiento adicional (como el rellenado)."),ka=h(),C(Ie.$$.fragment),Ra=h(),ge=p("h2"),Ae=p("a"),ja=p("span"),C(Ne.$$.fragment),ks=h(),ya=p("span"),Rs=n("Entrenamiento"),Ga=h(),C(ve.$$.fragment),Ba=h(),C(Ze.$$.fragment),this.h()},l(e){const u=Ul('[data-svelte="svelte-1phssyn"]',document.head);l=i(u,"META",{name:!0,content:!0}),u.forEach(s),d=j(e),t=i(e,"H1",{class:!0});var Fe=c(t);f=i(Fe,"A",{id:!0,class:!0,href:!0});var wa=c(f);w=i(wa,"SPAN",{});var Ua=c(w);b(y.$$.fragment,Ua),Ua.forEach(s),wa.forEach(s),U=j(Fe),Z=i(Fe,"SPAN",{});var Ja=c(Z);v=r(Ja,"Respuesta a preguntas"),Ja.forEach(s),Fe.forEach(s),g=j(e),b(k.$$.fragment,e),G=j(e),H=i(e,"P",{});var Gs=c(H);X=r(Gs,"La respuesta a preguntas devuelve una respuesta a partir de una pregunta dada. Existen dos formas comunes de responder preguntas:"),Gs.forEach(s),P=j(e),N=i(e,"UL",{});var xa=c(N);Q=i(xa,"LI",{});var Bs=c(Q);oe=r(Bs,"Extractiva: extraer la respuesta a partir del contexto dado."),Bs.forEach(s),O=j(xa),ne=i(xa,"LI",{});var Xs=c(ne);F=r(Xs,"Abstractiva: generar una respuesta que responda correctamente la pregunta a partir del contexto dado."),Xs.forEach(s),xa.forEach(s),pe=j(e),x=i(e,"P",{});var He=c(x);ie=r(He,"Esta gu\xEDa te mostrar\xE1 como hacer fine-tuning de "),V=i(He,"A",{href:!0,rel:!0});var xs=c(V);ce=r(xs,"DistilBERT"),xs.forEach(s),z=r(He," en el dataset "),K=i(He,"A",{href:!0,rel:!0});var zs=c(K);Y=r(zs,"SQuAD"),zs.forEach(s),re=r(He," para responder preguntas de forma extractiva."),He.forEach(s),me=j(e),b(q.$$.fragment,e),D=j(e),B=i(e,"H2",{class:!0});var za=c(B);M=i(za,"A",{id:!0,class:!0,href:!0});var Qs=c(M);$=i(Qs,"SPAN",{});var Vs=c($);b(S.$$.fragment,Vs),Vs.forEach(s),Qs.forEach(s),ae=j(za),W=i(za,"SPAN",{});var Ws=c(W);ue=r(Ws,"Carga el dataset SQuAD"),Ws.forEach(s),za.forEach(s),he=j(e),L=i(e,"P",{});var Ns=c(L);se=r(Ns,"Carga el dataset SQuAD con la biblioteca \u{1F917} Datasets:"),Ns.forEach(s),le=j(e),b(o.$$.fragment,e),J=j(e),Me=i(e,"P",{});var Fs=c(Me);Ye=r(Fs,"Ahora, \xE9chale un vistazo a una muestra:"),Fs.forEach(s),Re=j(e),b(de.$$.fragment,e),Ge=j(e),ee=i(e,"P",{});var Pe=c(ee);qe=r(Pe,"El campo "),$e=i(Pe,"CODE",{});var Ys=c($e);Ce=r(Ys,"answers"),Ys.forEach(s),De=r(Pe," es un diccionario que contiene la posici\xF3n inicial de la respuesta y el "),be=i(Pe,"CODE",{});var qs=c(be);Da=r(qs,"texto"),qs.forEach(s),Sa=r(Pe," de la respuesta."),Pe.forEach(s),Ta=j(e),Ue=i(e,"H2",{class:!0});var Qa=c(Ue);_e=i(Qa,"A",{id:!0,class:!0,href:!0});var Ds=c(_e);sa=i(Ds,"SPAN",{});var Ss=c(sa);b(Be.$$.fragment,Ss),Ss.forEach(s),Ds.forEach(s),Ha=j(Qa),la=i(Qa,"SPAN",{});var Hs=c(la);Pa=r(Hs,"Preprocesamiento"),Hs.forEach(s),Qa.forEach(s),ga=j(e),b(Xe.$$.fragment,e),$a=j(e),je=i(e,"P",{});var Oe=c(je);Oa=r(Oe,"Carga el tokenizer de DistilBERT para procesar los campos "),ta=i(Oe,"CODE",{});var Ps=c(ta);La=r(Ps,"question"),Ps.forEach(s),Ka=r(Oe," (pregunta) y "),na=i(Oe,"CODE",{});var Os=c(na);es=r(Os,"context"),Os.forEach(s),as=r(Oe," (contexto):"),Oe.forEach(s),Ca=j(e),b(xe.$$.fragment,e),ba=j(e),Se=i(e,"P",{});var Ls=c(Se);ss=r(Ls,"Hay algunos pasos de preprocesamiento espec\xEDficos para la tarea de respuesta a preguntas que debes tener en cuenta:"),Ls.forEach(s),_a=j(e),ye=i(e,"OL",{});var Le=c(ye);Je=i(Le,"LI",{});var Ke=c(Je);ls=r(Ke,"Algunos ejemplos en un dataset pueden tener un contexto que supera la longitud m\xE1xima de entrada de un modelo. Trunca solamente el contexto asign\xE1ndole el valor "),ra=i(Ke,"CODE",{});var Ks=c(ra);ts=r(Ks,'"only_second"'),Ks.forEach(s),ns=r(Ke," al par\xE1metro "),oa=i(Ke,"CODE",{});var el=c(oa);rs=r(el,"truncation"),el.forEach(s),os=r(Ke,"."),Ke.forEach(s),ps=j(Le),Te=i(Le,"LI",{});var ea=c(Te);is=r(ea,"A continuaci\xF3n, mapea las posiciones de inicio y fin de la respuesta al contexto original asign\xE1ndole el valor "),pa=i(ea,"CODE",{});var al=c(pa);cs=r(al,"True"),al.forEach(s),ms=r(ea," al par\xE1metro "),ia=i(ea,"CODE",{});var sl=c(ia);us=r(sl,"return_offsets_mapping"),sl.forEach(s),Ms=r(ea,"."),ea.forEach(s),ds=j(Le),ze=i(Le,"LI",{});var Va=c(ze);fs=r(Va,"Una vez tengas el mapeo, puedes encontrar los tokens de inicio y fin de la respuesta. Usa el m\xE9todo "),Qe=i(Va,"A",{href:!0,rel:!0});var ll=c(Qe);ca=i(ll,"CODE",{});var tl=c(ca);hs=r(tl,"sequence_ids"),tl.forEach(s),ll.forEach(s),js=r(Va,`
para encontrar qu\xE9 parte de la lista de tokens desplazados corresponde a la pregunta y cu\xE1l corresponde al contexto.`),Va.forEach(s),Le.forEach(s),Ea=j(e),Ee=i(e,"P",{});var Wa=c(Ee);ys=r(Wa,"A continuaci\xF3n puedes ver como se crea una funci\xF3n para truncar y mapear los tokens de inicio y fin de la respuesta al "),ma=i(Wa,"CODE",{});var nl=c(ma);ws=r(nl,"context"),nl.forEach(s),Us=r(Wa,":"),Wa.forEach(s),Ia=j(e),b(Ve.$$.fragment,e),Aa=j(e),fe=i(e,"P",{});var ke=c(fe);Js=r(ke,"Usa la funci\xF3n "),ua=i(ke,"CODE",{});var rl=c(ua);Ts=r(rl,"map"),rl.forEach(s),gs=r(ke," de \u{1F917} Datasets para aplicarle la funci\xF3n de preprocesamiento al dataset entero. Puedes acelerar la funci\xF3n "),Ma=i(ke,"CODE",{});var ol=c(Ma);$s=r(ol,"map"),ol.forEach(s),Cs=r(ke," haciendo "),da=i(ke,"CODE",{});var pl=c(da);bs=r(pl,"batched=True"),pl.forEach(s),_s=r(ke,` para procesar varios elementos del dataset a la vez.
Quita las columnas que no necesites:`),ke.forEach(s),va=j(e),b(We.$$.fragment,e),Za=j(e),we=i(e,"P",{});var aa=c(we);Es=r(aa,"Usa el "),fa=i(aa,"CODE",{});var il=c(fa);Is=r(il,"DefaultDataCollator"),il.forEach(s),As=r(aa," para crear un lote de ejemplos. A diferencia de los otros collators de datos en \u{1F917} Transformers, el "),ha=i(aa,"CODE",{});var cl=c(ha);vs=r(cl,"DefaultDataCollator"),cl.forEach(s),Zs=r(aa," no aplica ning\xFAn procesamiento adicional (como el rellenado)."),aa.forEach(s),ka=j(e),b(Ie.$$.fragment,e),Ra=j(e),ge=i(e,"H2",{class:!0});var Na=c(ge);Ae=i(Na,"A",{id:!0,class:!0,href:!0});var ml=c(Ae);ja=i(ml,"SPAN",{});var ul=c(ja);b(Ne.$$.fragment,ul),ul.forEach(s),ml.forEach(s),ks=j(Na),ya=i(Na,"SPAN",{});var Ml=c(ya);Rs=r(Ml,"Entrenamiento"),Ml.forEach(s),Na.forEach(s),Ga=j(e),b(ve.$$.fragment,e),Ba=j(e),b(Ze.$$.fragment,e),this.h()},h(){T(l,"name","hf:doc:metadata"),T(l,"content",JSON.stringify(Gl)),T(f,"id","respuesta-a-preguntas"),T(f,"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"),T(f,"href","#respuesta-a-preguntas"),T(t,"class","relative group"),T(V,"href","https://huggingface.co/distilbert-base-uncased"),T(V,"rel","nofollow"),T(K,"href","https://huggingface.co/datasets/squad"),T(K,"rel","nofollow"),T(M,"id","carga-el-dataset-squad"),T(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"),T(M,"href","#carga-el-dataset-squad"),T(B,"class","relative group"),T(_e,"id","preprocesamiento"),T(_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"),T(_e,"href","#preprocesamiento"),T(Ue,"class","relative group"),T(Qe,"href","https://huggingface.co/docs/tokenizers/python/latest/api/reference.html#tokenizers.Encoding.sequence_ids"),T(Qe,"rel","nofollow"),T(Ae,"id","entrenamiento"),T(Ae,"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"),T(Ae,"href","#entrenamiento"),T(ge,"class","relative group")},m(e,u){a(document.head,l),m(e,d,u),m(e,t,u),a(t,f),a(f,w),_(y,w,null),a(t,U),a(t,Z),a(Z,v),m(e,g,u),_(k,e,u),m(e,G,u),m(e,H,u),a(H,X),m(e,P,u),m(e,N,u),a(N,Q),a(Q,oe),a(N,O),a(N,ne),a(ne,F),m(e,pe,u),m(e,x,u),a(x,ie),a(x,V),a(V,ce),a(x,z),a(x,K),a(K,Y),a(x,re),m(e,me,u),_(q,e,u),m(e,D,u),m(e,B,u),a(B,M),a(M,$),_(S,$,null),a(B,ae),a(B,W),a(W,ue),m(e,he,u),m(e,L,u),a(L,se),m(e,le,u),_(o,e,u),m(e,J,u),m(e,Me,u),a(Me,Ye),m(e,Re,u),_(de,e,u),m(e,Ge,u),m(e,ee,u),a(ee,qe),a(ee,$e),a($e,Ce),a(ee,De),a(ee,be),a(be,Da),a(ee,Sa),m(e,Ta,u),m(e,Ue,u),a(Ue,_e),a(_e,sa),_(Be,sa,null),a(Ue,Ha),a(Ue,la),a(la,Pa),m(e,ga,u),_(Xe,e,u),m(e,$a,u),m(e,je,u),a(je,Oa),a(je,ta),a(ta,La),a(je,Ka),a(je,na),a(na,es),a(je,as),m(e,Ca,u),_(xe,e,u),m(e,ba,u),m(e,Se,u),a(Se,ss),m(e,_a,u),m(e,ye,u),a(ye,Je),a(Je,ls),a(Je,ra),a(ra,ts),a(Je,ns),a(Je,oa),a(oa,rs),a(Je,os),a(ye,ps),a(ye,Te),a(Te,is),a(Te,pa),a(pa,cs),a(Te,ms),a(Te,ia),a(ia,us),a(Te,Ms),a(ye,ds),a(ye,ze),a(ze,fs),a(ze,Qe),a(Qe,ca),a(ca,hs),a(ze,js),m(e,Ea,u),m(e,Ee,u),a(Ee,ys),a(Ee,ma),a(ma,ws),a(Ee,Us),m(e,Ia,u),_(Ve,e,u),m(e,Aa,u),m(e,fe,u),a(fe,Js),a(fe,ua),a(ua,Ts),a(fe,gs),a(fe,Ma),a(Ma,$s),a(fe,Cs),a(fe,da),a(da,bs),a(fe,_s),m(e,va,u),_(We,e,u),m(e,Za,u),m(e,we,u),a(we,Es),a(we,fa),a(fa,Is),a(we,As),a(we,ha),a(ha,vs),a(we,Zs),m(e,ka,u),_(Ie,e,u),m(e,Ra,u),m(e,ge,u),a(ge,Ae),a(Ae,ja),_(Ne,ja,null),a(ge,ks),a(ge,ya),a(ya,Rs),m(e,Ga,u),_(ve,e,u),m(e,Ba,u),_(Ze,e,u),Xa=!0},p(e,[u]){const Fe={};u&2&&(Fe.$$scope={dirty:u,ctx:e}),q.$set(Fe);const wa={};u&2&&(wa.$$scope={dirty:u,ctx:e}),Ie.$set(wa);const Ua={};u&2&&(Ua.$$scope={dirty:u,ctx:e}),ve.$set(Ua);const Ja={};u&2&&(Ja.$$scope={dirty:u,ctx:e}),Ze.$set(Ja)},i(e){Xa||(E(y.$$.fragment,e),E(k.$$.fragment,e),E(q.$$.fragment,e),E(S.$$.fragment,e),E(o.$$.fragment,e),E(de.$$.fragment,e),E(Be.$$.fragment,e),E(Xe.$$.fragment,e),E(xe.$$.fragment,e),E(Ve.$$.fragment,e),E(We.$$.fragment,e),E(Ie.$$.fragment,e),E(Ne.$$.fragment,e),E(ve.$$.fragment,e),E(Ze.$$.fragment,e),Xa=!0)},o(e){I(y.$$.fragment,e),I(k.$$.fragment,e),I(q.$$.fragment,e),I(S.$$.fragment,e),I(o.$$.fragment,e),I(de.$$.fragment,e),I(Be.$$.fragment,e),I(Xe.$$.fragment,e),I(xe.$$.fragment,e),I(Ve.$$.fragment,e),I(We.$$.fragment,e),I(Ie.$$.fragment,e),I(Ne.$$.fragment,e),I(ve.$$.fragment,e),I(Ze.$$.fragment,e),Xa=!1},d(e){s(l),e&&s(d),e&&s(t),A(y),e&&s(g),A(k,e),e&&s(G),e&&s(H),e&&s(P),e&&s(N),e&&s(pe),e&&s(x),e&&s(me),A(q,e),e&&s(D),e&&s(B),A(S),e&&s(he),e&&s(L),e&&s(le),A(o,e),e&&s(J),e&&s(Me),e&&s(Re),A(de,e),e&&s(Ge),e&&s(ee),e&&s(Ta),e&&s(Ue),A(Be),e&&s(ga),A(Xe,e),e&&s($a),e&&s(je),e&&s(Ca),A(xe,e),e&&s(ba),e&&s(Se),e&&s(_a),e&&s(ye),e&&s(Ea),e&&s(Ee),e&&s(Ia),A(Ve,e),e&&s(Aa),e&&s(fe),e&&s(va),A(We,e),e&&s(Za),e&&s(we),e&&s(ka),A(Ie,e),e&&s(Ra),e&&s(ge),A(Ne),e&&s(Ga),A(ve,e),e&&s(Ba),A(Ze,e)}}}const Gl={local:"respuesta-a-preguntas",sections:[{local:"carga-el-dataset-squad",title:"Carga el dataset SQuAD"},{local:"preprocesamiento",title:"Preprocesamiento"},{local:"entrenamiento",title:"Entrenamiento"}],title:"Respuesta a preguntas"};function Bl(R){return Jl(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Fl extends jl{constructor(l){super();yl(this,l,Bl,Rl,wl,{})}}export{Fl as default,Gl as metadata};
