import{S as Hl,i as ql,s as Ql,e as p,k as y,w as T,t as a,M as Pl,c as i,d as s,m as b,a as c,x as k,h as l,b as d,G as t,g as f,y as v,q as U,o as J,B as E,v as Ll,L as aa}from"../../chunks/vendor-hf-doc-builder.js";import{T as sa}from"../../chunks/Tip-hf-doc-builder.js";import{Y as Yl}from"../../chunks/Youtube-hf-doc-builder.js";import{I as ts}from"../../chunks/IconCopyLink-hf-doc-builder.js";import{C as P}from"../../chunks/CodeBlock-hf-doc-builder.js";import{D as Dl}from"../../chunks/DocNotebookDropdown-hf-doc-builder.js";import{F as Oa,M as ss}from"../../chunks/Markdown-hf-doc-builder.js";function Kl(q){let n,m,o,M,w,j,B,F,_,G,R,A,S,I,W,oe,K,V,se,Y,H,N,x,C,u,$,L,O,de,Q,ee,ke,ae,ge,ye,be,Se,We,z,Fe,ne,Be,Ie,pe,ie,me,te,le,ce,we,_e,ve,$e,re,g,X,Me,Ve,Ue,D,Je,je,he,Re,ue,Ee,Ne,Te,Ze,fe,Ae,Ge,xe;return{c(){n=a(`The task illustrated in this tutorial is supported by the following model architectures:

`),m=p("p"),o=p("a"),M=a("BART"),w=a(", "),j=p("a"),B=a("BigBird-Pegasus"),F=a(", "),_=p("a"),G=a("Blenderbot"),R=a(", "),A=p("a"),S=a("BlenderbotSmall"),I=a(", "),W=p("a"),oe=a("Encoder decoder"),K=a(", "),V=p("a"),se=a("FairSeq Machine-Translation"),Y=a(", "),H=p("a"),N=a("GPTSAN-japanese"),x=a(", "),C=p("a"),u=a("LED"),$=a(", "),L=p("a"),O=a("LongT5"),de=a(", "),Q=p("a"),ee=a("M2M100"),ke=a(", "),ae=p("a"),ge=a("Marian"),ye=a(", "),be=p("a"),Se=a("mBART"),We=a(", "),z=p("a"),Fe=a("MT5"),ne=a(", "),Be=p("a"),Ie=a("MVP"),pe=a(", "),ie=p("a"),me=a("NLLB"),te=a(", "),le=p("a"),ce=a("NLLB-MOE"),we=a(", "),_e=p("a"),ve=a("Pegasus"),$e=a(", "),re=p("a"),g=a("PEGASUS-X"),X=a(", "),Me=p("a"),Ve=a("PLBart"),Ue=a(", "),D=p("a"),Je=a("ProphetNet"),je=a(", "),he=p("a"),Re=a("SwitchTransformers"),ue=a(", "),Ee=p("a"),Ne=a("T5"),Te=a(", "),Ze=p("a"),fe=a("UMT5"),Ae=a(", "),Ge=p("a"),xe=a("XLM-ProphetNet"),this.h()},l(Xe){n=l(Xe,`The task illustrated in this tutorial is supported by the following model architectures:

`),m=i(Xe,"P",{});var r=c(m);o=i(r,"A",{href:!0});var Z=c(o);M=l(Z,"BART"),Z.forEach(s),w=l(r,", "),j=i(r,"A",{href:!0});var De=c(j);B=l(De,"BigBird-Pegasus"),De.forEach(s),F=l(r,", "),_=i(r,"A",{href:!0});var Ye=c(_);G=l(Ye,"Blenderbot"),Ye.forEach(s),R=l(r,", "),A=i(r,"A",{href:!0});var nt=c(A);S=l(nt,"BlenderbotSmall"),nt.forEach(s),I=l(r,", "),W=i(r,"A",{href:!0});var ze=c(W);oe=l(ze,"Encoder decoder"),ze.forEach(s),K=l(r,", "),V=i(r,"A",{href:!0});var Ce=c(V);se=l(Ce,"FairSeq Machine-Translation"),Ce.forEach(s),Y=l(r,", "),H=i(r,"A",{href:!0});var lt=c(H);N=l(lt,"GPTSAN-japanese"),lt.forEach(s),x=l(r,", "),C=i(r,"A",{href:!0});var He=c(C);u=l(He,"LED"),He.forEach(s),$=l(r,", "),L=i(r,"A",{href:!0});var rt=c(L);O=l(rt,"LongT5"),rt.forEach(s),de=l(r,", "),Q=i(r,"A",{href:!0});var ot=c(Q);ee=l(ot,"M2M100"),ot.forEach(s),ke=l(r,", "),ae=i(r,"A",{href:!0});var qe=c(ae);ge=l(qe,"Marian"),qe.forEach(s),ye=l(r,", "),be=i(r,"A",{href:!0});var pt=c(be);Se=l(pt,"mBART"),pt.forEach(s),We=l(r,", "),z=i(r,"A",{href:!0});var Qe=c(z);Fe=l(Qe,"MT5"),Qe.forEach(s),ne=l(r,", "),Be=i(r,"A",{href:!0});var Ke=c(Be);Ie=l(Ke,"MVP"),Ke.forEach(s),pe=l(r,", "),ie=i(r,"A",{href:!0});var Oe=c(ie);me=l(Oe,"NLLB"),Oe.forEach(s),te=l(r,", "),le=i(r,"A",{href:!0});var mt=c(le);ce=l(mt,"NLLB-MOE"),mt.forEach(s),we=l(r,", "),_e=i(r,"A",{href:!0});var et=c(_e);ve=l(et,"Pegasus"),et.forEach(s),$e=l(r,", "),re=i(r,"A",{href:!0});var Pe=c(re);g=l(Pe,"PEGASUS-X"),Pe.forEach(s),X=l(r,", "),Me=i(r,"A",{href:!0});var it=c(Me);Ve=l(it,"PLBart"),it.forEach(s),Ue=l(r,", "),D=i(r,"A",{href:!0});var tt=c(D);Je=l(tt,"ProphetNet"),tt.forEach(s),je=l(r,", "),he=i(r,"A",{href:!0});var Ht=c(he);Re=l(Ht,"SwitchTransformers"),Ht.forEach(s),ue=l(r,", "),Ee=i(r,"A",{href:!0});var Et=c(Ee);Ne=l(Et,"T5"),Et.forEach(s),Te=l(r,", "),Ze=i(r,"A",{href:!0});var Le=c(Ze);fe=l(Le,"UMT5"),Le.forEach(s),Ae=l(r,", "),Ge=i(r,"A",{href:!0});var yt=c(Ge);xe=l(yt,"XLM-ProphetNet"),yt.forEach(s),r.forEach(s),this.h()},h(){d(o,"href","../model_doc/bart"),d(j,"href","../model_doc/bigbird_pegasus"),d(_,"href","../model_doc/blenderbot"),d(A,"href","../model_doc/blenderbot-small"),d(W,"href","../model_doc/encoder-decoder"),d(V,"href","../model_doc/fsmt"),d(H,"href","../model_doc/gptsan-japanese"),d(C,"href","../model_doc/led"),d(L,"href","../model_doc/longt5"),d(Q,"href","../model_doc/m2m_100"),d(ae,"href","../model_doc/marian"),d(be,"href","../model_doc/mbart"),d(z,"href","../model_doc/mt5"),d(Be,"href","../model_doc/mvp"),d(ie,"href","../model_doc/nllb"),d(le,"href","../model_doc/nllb-moe"),d(_e,"href","../model_doc/pegasus"),d(re,"href","../model_doc/pegasus_x"),d(Me,"href","../model_doc/plbart"),d(D,"href","../model_doc/prophetnet"),d(he,"href","../model_doc/switch_transformers"),d(Ee,"href","../model_doc/t5"),d(Ze,"href","../model_doc/umt5"),d(Ge,"href","../model_doc/xlm-prophetnet")},m(Xe,r){f(Xe,n,r),f(Xe,m,r),t(m,o),t(o,M),t(m,w),t(m,j),t(j,B),t(m,F),t(m,_),t(_,G),t(m,R),t(m,A),t(A,S),t(m,I),t(m,W),t(W,oe),t(m,K),t(m,V),t(V,se),t(m,Y),t(m,H),t(H,N),t(m,x),t(m,C),t(C,u),t(m,$),t(m,L),t(L,O),t(m,de),t(m,Q),t(Q,ee),t(m,ke),t(m,ae),t(ae,ge),t(m,ye),t(m,be),t(be,Se),t(m,We),t(m,z),t(z,Fe),t(m,ne),t(m,Be),t(Be,Ie),t(m,pe),t(m,ie),t(ie,me),t(m,te),t(m,le),t(le,ce),t(m,we),t(m,_e),t(_e,ve),t(m,$e),t(m,re),t(re,g),t(m,X),t(m,Me),t(Me,Ve),t(m,Ue),t(m,D),t(D,Je),t(m,je),t(m,he),t(he,Re),t(m,ue),t(m,Ee),t(Ee,Ne),t(m,Te),t(m,Ze),t(Ze,fe),t(m,Ae),t(m,Ge),t(Ge,xe)},d(Xe){Xe&&s(n),Xe&&s(m)}}}function Ol(q){let n,m;return n=new P({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMERhdGFDb2xsYXRvckZvclNlcTJTZXElMEElMEFkYXRhX2NvbGxhdG9yJTIwJTNEJTIwRGF0YUNvbGxhdG9yRm9yU2VxMlNlcSh0b2tlbml6ZXIlM0R0b2tlbml6ZXIlMkMlMjBtb2RlbCUzRGNoZWNrcG9pbnQp",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> DataCollatorForSeq2Seq

<span class="hljs-meta">&gt;&gt;&gt; </span>data_collator = DataCollatorForSeq2Seq(tokenizer=tokenizer, model=checkpoint)`}}),{c(){T(n.$$.fragment)},l(o){k(n.$$.fragment,o)},m(o,M){v(n,o,M),m=!0},p:aa,i(o){m||(U(n.$$.fragment,o),m=!0)},o(o){J(n.$$.fragment,o),m=!1},d(o){E(n,o)}}}function er(q){let n,m;return n=new ss({props:{$$slots:{default:[Ol]},$$scope:{ctx:q}}}),{c(){T(n.$$.fragment)},l(o){k(n.$$.fragment,o)},m(o,M){v(n,o,M),m=!0},p(o,M){const w={};M&2&&(w.$$scope={dirty:M,ctx:o}),n.$set(w)},i(o){m||(U(n.$$.fragment,o),m=!0)},o(o){J(n.$$.fragment,o),m=!1},d(o){E(n,o)}}}function tr(q){let n,m;return n=new P({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMERhdGFDb2xsYXRvckZvclNlcTJTZXElMEElMEFkYXRhX2NvbGxhdG9yJTIwJTNEJTIwRGF0YUNvbGxhdG9yRm9yU2VxMlNlcSh0b2tlbml6ZXIlM0R0b2tlbml6ZXIlMkMlMjBtb2RlbCUzRGNoZWNrcG9pbnQlMkMlMjByZXR1cm5fdGVuc29ycyUzRCUyMnRmJTIyKQ==",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> DataCollatorForSeq2Seq

<span class="hljs-meta">&gt;&gt;&gt; </span>data_collator = DataCollatorForSeq2Seq(tokenizer=tokenizer, model=checkpoint, return_tensors=<span class="hljs-string">&quot;tf&quot;</span>)`}}),{c(){T(n.$$.fragment)},l(o){k(n.$$.fragment,o)},m(o,M){v(n,o,M),m=!0},p:aa,i(o){m||(U(n.$$.fragment,o),m=!0)},o(o){J(n.$$.fragment,o),m=!1},d(o){E(n,o)}}}function sr(q){let n,m;return n=new ss({props:{$$slots:{default:[tr]},$$scope:{ctx:q}}}),{c(){T(n.$$.fragment)},l(o){k(n.$$.fragment,o)},m(o,M){v(n,o,M),m=!0},p(o,M){const w={};M&2&&(w.$$scope={dirty:M,ctx:o}),n.$set(w)},i(o){m||(U(n.$$.fragment,o),m=!0)},o(o){J(n.$$.fragment,o),m=!1},d(o){E(n,o)}}}function ar(q){let n,m,o,M,w,j,B,F;return{c(){n=p("p"),m=a("If you aren\u2019t familiar with finetuning a model with the "),o=p("a"),M=a("Trainer"),w=a(", take a look at the basic tutorial "),j=p("a"),B=a("here"),F=a("!"),this.h()},l(_){n=i(_,"P",{});var G=c(n);m=l(G,"If you aren\u2019t familiar with finetuning a model with the "),o=i(G,"A",{href:!0});var R=c(o);M=l(R,"Trainer"),R.forEach(s),w=l(G,", take a look at the basic tutorial "),j=i(G,"A",{href:!0});var A=c(j);B=l(A,"here"),A.forEach(s),F=l(G,"!"),G.forEach(s),this.h()},h(){d(o,"href","/docs/transformers/v4.33.0/en/main_classes/trainer#transformers.Trainer"),d(j,"href","../training#train-with-pytorch-trainer")},m(_,G){f(_,n,G),t(n,m),t(n,o),t(o,M),t(n,w),t(n,j),t(j,B),t(n,F)},d(_){_&&s(n)}}}function lr(q){let n,m,o,M,w,j,B,F,_,G,R,A,S,I,W,oe,K,V,se,Y,H,N,x,C,u,$,L,O,de,Q,ee,ke,ae,ge,ye,be,Se,We,z,Fe,ne,Be,Ie,pe,ie,me,te,le,ce,we,_e,ve,$e,re;return n=new sa({props:{$$slots:{default:[ar]},$$scope:{ctx:q}}}),_=new P({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9Nb2RlbEZvclNlcTJTZXFMTSUyQyUyMFNlcTJTZXFUcmFpbmluZ0FyZ3VtZW50cyUyQyUyMFNlcTJTZXFUcmFpbmVyJTBBJTBBbW9kZWwlMjAlM0QlMjBBdXRvTW9kZWxGb3JTZXEyU2VxTE0uZnJvbV9wcmV0cmFpbmVkKGNoZWNrcG9pbnQp",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoModelForSeq2SeqLM, Seq2SeqTrainingArguments, Seq2SeqTrainer

<span class="hljs-meta">&gt;&gt;&gt; </span>model = AutoModelForSeq2SeqLM.from_pretrained(checkpoint)`}}),ie=new P({props:{code:"dHJhaW5pbmdfYXJncyUyMCUzRCUyMFNlcTJTZXFUcmFpbmluZ0FyZ3VtZW50cyglMEElMjAlMjAlMjAlMjBvdXRwdXRfZGlyJTNEJTIybXlfYXdlc29tZV9vcHVzX2Jvb2tzX21vZGVsJTIyJTJDJTBBJTIwJTIwJTIwJTIwZXZhbHVhdGlvbl9zdHJhdGVneSUzRCUyMmVwb2NoJTIyJTJDJTBBJTIwJTIwJTIwJTIwbGVhcm5pbmdfcmF0ZSUzRDJlLTUlMkMlMEElMjAlMjAlMjAlMjBwZXJfZGV2aWNlX3RyYWluX2JhdGNoX3NpemUlM0QxNiUyQyUwQSUyMCUyMCUyMCUyMHBlcl9kZXZpY2VfZXZhbF9iYXRjaF9zaXplJTNEMTYlMkMlMEElMjAlMjAlMjAlMjB3ZWlnaHRfZGVjYXklM0QwLjAxJTJDJTBBJTIwJTIwJTIwJTIwc2F2ZV90b3RhbF9saW1pdCUzRDMlMkMlMEElMjAlMjAlMjAlMjBudW1fdHJhaW5fZXBvY2hzJTNEMiUyQyUwQSUyMCUyMCUyMCUyMHByZWRpY3Rfd2l0aF9nZW5lcmF0ZSUzRFRydWUlMkMlMEElMjAlMjAlMjAlMjBmcDE2JTNEVHJ1ZSUyQyUwQSUyMCUyMCUyMCUyMHB1c2hfdG9faHViJTNEVHJ1ZSUyQyUwQSklMEElMEF0cmFpbmVyJTIwJTNEJTIwU2VxMlNlcVRyYWluZXIoJTBBJTIwJTIwJTIwJTIwbW9kZWwlM0Rtb2RlbCUyQyUwQSUyMCUyMCUyMCUyMGFyZ3MlM0R0cmFpbmluZ19hcmdzJTJDJTBBJTIwJTIwJTIwJTIwdHJhaW5fZGF0YXNldCUzRHRva2VuaXplZF9ib29rcyU1QiUyMnRyYWluJTIyJTVEJTJDJTBBJTIwJTIwJTIwJTIwZXZhbF9kYXRhc2V0JTNEdG9rZW5pemVkX2Jvb2tzJTVCJTIydGVzdCUyMiU1RCUyQyUwQSUyMCUyMCUyMCUyMHRva2VuaXplciUzRHRva2VuaXplciUyQyUwQSUyMCUyMCUyMCUyMGRhdGFfY29sbGF0b3IlM0RkYXRhX2NvbGxhdG9yJTJDJTBBJTIwJTIwJTIwJTIwY29tcHV0ZV9tZXRyaWNzJTNEY29tcHV0ZV9tZXRyaWNzJTJDJTBBKSUwQSUwQXRyYWluZXIudHJhaW4oKQ==",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span>training_args = Seq2SeqTrainingArguments(
<span class="hljs-meta">... </span>    output_dir=<span class="hljs-string">&quot;my_awesome_opus_books_model&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>    weight_decay=<span class="hljs-number">0.01</span>,
<span class="hljs-meta">... </span>    save_total_limit=<span class="hljs-number">3</span>,
<span class="hljs-meta">... </span>    num_train_epochs=<span class="hljs-number">2</span>,
<span class="hljs-meta">... </span>    predict_with_generate=<span class="hljs-literal">True</span>,
<span class="hljs-meta">... </span>    fp16=<span class="hljs-literal">True</span>,
<span class="hljs-meta">... </span>    push_to_hub=<span class="hljs-literal">True</span>,
<span class="hljs-meta">... </span>)

<span class="hljs-meta">&gt;&gt;&gt; </span>trainer = Seq2SeqTrainer(
<span class="hljs-meta">... </span>    model=model,
<span class="hljs-meta">... </span>    args=training_args,
<span class="hljs-meta">... </span>    train_dataset=tokenized_books[<span class="hljs-string">&quot;train&quot;</span>],
<span class="hljs-meta">... </span>    eval_dataset=tokenized_books[<span class="hljs-string">&quot;test&quot;</span>],
<span class="hljs-meta">... </span>    tokenizer=tokenizer,
<span class="hljs-meta">... </span>    data_collator=data_collator,
<span class="hljs-meta">... </span>    compute_metrics=compute_metrics,
<span class="hljs-meta">... </span>)

<span class="hljs-meta">&gt;&gt;&gt; </span>trainer.train()`}}),$e=new P({props:{code:"dHJhaW5lci5wdXNoX3RvX2h1Yigp",highlighted:'<span class="hljs-meta">&gt;&gt;&gt; </span>trainer.push_to_hub()'}}),{c(){T(n.$$.fragment),m=y(),o=p("p"),M=a("You\u2019re ready to start training your model now! Load T5 with "),w=p("a"),j=a("AutoModelForSeq2SeqLM"),B=a(":"),F=y(),T(_.$$.fragment),G=y(),R=p("p"),A=a("At this point, only three steps remain:"),S=y(),I=p("ol"),W=p("li"),oe=a("Define your training hyperparameters in "),K=p("a"),V=a("Seq2SeqTrainingArguments"),se=a(". The only required parameter is "),Y=p("code"),H=a("output_dir"),N=a(" which specifies where to save your model. You\u2019ll push this model to the Hub by setting "),x=p("code"),C=a("push_to_hub=True"),u=a(" (you need to be signed in to Hugging Face to upload your model). At the end of each epoch, the "),$=p("a"),L=a("Trainer"),O=a(" will evaluate the SacreBLEU metric and save the training checkpoint."),de=y(),Q=p("li"),ee=a("Pass the training arguments to "),ke=p("a"),ae=a("Seq2SeqTrainer"),ge=a(" along with the model, dataset, tokenizer, data collator, and "),ye=p("code"),be=a("compute_metrics"),Se=a(" function."),We=y(),z=p("li"),Fe=a("Call "),ne=p("a"),Be=a("train()"),Ie=a(" to finetune your model."),pe=y(),T(ie.$$.fragment),me=y(),te=p("p"),le=a("Once training is completed, share your model to the Hub with the "),ce=p("a"),we=a("push_to_hub()"),_e=a(" method so everyone can use your model:"),ve=y(),T($e.$$.fragment),this.h()},l(g){k(n.$$.fragment,g),m=b(g),o=i(g,"P",{});var X=c(o);M=l(X,"You\u2019re ready to start training your model now! Load T5 with "),w=i(X,"A",{href:!0});var Me=c(w);j=l(Me,"AutoModelForSeq2SeqLM"),Me.forEach(s),B=l(X,":"),X.forEach(s),F=b(g),k(_.$$.fragment,g),G=b(g),R=i(g,"P",{});var Ve=c(R);A=l(Ve,"At this point, only three steps remain:"),Ve.forEach(s),S=b(g),I=i(g,"OL",{});var Ue=c(I);W=i(Ue,"LI",{});var D=c(W);oe=l(D,"Define your training hyperparameters in "),K=i(D,"A",{href:!0});var Je=c(K);V=l(Je,"Seq2SeqTrainingArguments"),Je.forEach(s),se=l(D,". The only required parameter is "),Y=i(D,"CODE",{});var je=c(Y);H=l(je,"output_dir"),je.forEach(s),N=l(D," which specifies where to save your model. You\u2019ll push this model to the Hub by setting "),x=i(D,"CODE",{});var he=c(x);C=l(he,"push_to_hub=True"),he.forEach(s),u=l(D," (you need to be signed in to Hugging Face to upload your model). At the end of each epoch, the "),$=i(D,"A",{href:!0});var Re=c($);L=l(Re,"Trainer"),Re.forEach(s),O=l(D," will evaluate the SacreBLEU metric and save the training checkpoint."),D.forEach(s),de=b(Ue),Q=i(Ue,"LI",{});var ue=c(Q);ee=l(ue,"Pass the training arguments to "),ke=i(ue,"A",{href:!0});var Ee=c(ke);ae=l(Ee,"Seq2SeqTrainer"),Ee.forEach(s),ge=l(ue," along with the model, dataset, tokenizer, data collator, and "),ye=i(ue,"CODE",{});var Ne=c(ye);be=l(Ne,"compute_metrics"),Ne.forEach(s),Se=l(ue," function."),ue.forEach(s),We=b(Ue),z=i(Ue,"LI",{});var Te=c(z);Fe=l(Te,"Call "),ne=i(Te,"A",{href:!0});var Ze=c(ne);Be=l(Ze,"train()"),Ze.forEach(s),Ie=l(Te," to finetune your model."),Te.forEach(s),Ue.forEach(s),pe=b(g),k(ie.$$.fragment,g),me=b(g),te=i(g,"P",{});var fe=c(te);le=l(fe,"Once training is completed, share your model to the Hub with the "),ce=i(fe,"A",{href:!0});var Ae=c(ce);we=l(Ae,"push_to_hub()"),Ae.forEach(s),_e=l(fe," method so everyone can use your model:"),fe.forEach(s),ve=b(g),k($e.$$.fragment,g),this.h()},h(){d(w,"href","/docs/transformers/v4.33.0/en/model_doc/auto#transformers.AutoModelForSeq2SeqLM"),d(K,"href","/docs/transformers/v4.33.0/en/main_classes/trainer#transformers.Seq2SeqTrainingArguments"),d($,"href","/docs/transformers/v4.33.0/en/main_classes/trainer#transformers.Trainer"),d(ke,"href","/docs/transformers/v4.33.0/en/main_classes/trainer#transformers.Seq2SeqTrainer"),d(ne,"href","/docs/transformers/v4.33.0/en/main_classes/trainer#transformers.Trainer.train"),d(ce,"href","/docs/transformers/v4.33.0/en/main_classes/trainer#transformers.Trainer.push_to_hub")},m(g,X){v(n,g,X),f(g,m,X),f(g,o,X),t(o,M),t(o,w),t(w,j),t(o,B),f(g,F,X),v(_,g,X),f(g,G,X),f(g,R,X),t(R,A),f(g,S,X),f(g,I,X),t(I,W),t(W,oe),t(W,K),t(K,V),t(W,se),t(W,Y),t(Y,H),t(W,N),t(W,x),t(x,C),t(W,u),t(W,$),t($,L),t(W,O),t(I,de),t(I,Q),t(Q,ee),t(Q,ke),t(ke,ae),t(Q,ge),t(Q,ye),t(ye,be),t(Q,Se),t(I,We),t(I,z),t(z,Fe),t(z,ne),t(ne,Be),t(z,Ie),f(g,pe,X),v(ie,g,X),f(g,me,X),f(g,te,X),t(te,le),t(te,ce),t(ce,we),t(te,_e),f(g,ve,X),v($e,g,X),re=!0},p(g,X){const Me={};X&2&&(Me.$$scope={dirty:X,ctx:g}),n.$set(Me)},i(g){re||(U(n.$$.fragment,g),U(_.$$.fragment,g),U(ie.$$.fragment,g),U($e.$$.fragment,g),re=!0)},o(g){J(n.$$.fragment,g),J(_.$$.fragment,g),J(ie.$$.fragment,g),J($e.$$.fragment,g),re=!1},d(g){E(n,g),g&&s(m),g&&s(o),g&&s(F),E(_,g),g&&s(G),g&&s(R),g&&s(S),g&&s(I),g&&s(pe),E(ie,g),g&&s(me),g&&s(te),g&&s(ve),E($e,g)}}}function rr(q){let n,m;return n=new ss({props:{$$slots:{default:[lr]},$$scope:{ctx:q}}}),{c(){T(n.$$.fragment)},l(o){k(n.$$.fragment,o)},m(o,M){v(n,o,M),m=!0},p(o,M){const w={};M&2&&(w.$$scope={dirty:M,ctx:o}),n.$set(w)},i(o){m||(U(n.$$.fragment,o),m=!0)},o(o){J(n.$$.fragment,o),m=!1},d(o){E(n,o)}}}function or(q){let n,m,o,M,w;return{c(){n=p("p"),m=a("If you aren\u2019t familiar with finetuning a model with Keras, take a look at the basic tutorial "),o=p("a"),M=a("here"),w=a("!"),this.h()},l(j){n=i(j,"P",{});var B=c(n);m=l(B,"If you aren\u2019t familiar with finetuning a model with Keras, take a look at the basic tutorial "),o=i(B,"A",{href:!0});var F=c(o);M=l(F,"here"),F.forEach(s),w=l(B,"!"),B.forEach(s),this.h()},h(){d(o,"href","../training#train-a-tensorflow-model-with-keras")},m(j,B){f(j,n,B),t(n,m),t(n,o),t(o,M),t(n,w)},d(j){j&&s(n)}}}function nr(q){let n,m,o,M,w,j,B,F,_,G,R,A,S,I,W,oe,K,V,se,Y,H,N,x,C,u,$,L,O,de,Q,ee,ke,ae,ge,ye,be,Se,We,z,Fe,ne,Be,Ie,pe,ie,me,te,le,ce,we,_e,ve,$e,re,g,X,Me,Ve,Ue,D,Je,je,he,Re,ue,Ee,Ne,Te,Ze,fe,Ae,Ge,xe,Xe;return n=new sa({props:{$$slots:{default:[or]},$$scope:{ctx:q}}}),o=new P({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEFkYW1XZWlnaHREZWNheSUwQSUwQW9wdGltaXplciUyMCUzRCUyMEFkYW1XZWlnaHREZWNheShsZWFybmluZ19yYXRlJTNEMmUtNSUyQyUyMHdlaWdodF9kZWNheV9yYXRlJTNEMC4wMSk=",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AdamWeightDecay

<span class="hljs-meta">&gt;&gt;&gt; </span>optimizer = AdamWeightDecay(learning_rate=<span class="hljs-number">2e-5</span>, weight_decay_rate=<span class="hljs-number">0.01</span>)`}}),R=new P({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMFRGQXV0b01vZGVsRm9yU2VxMlNlcUxNJTBBJTBBbW9kZWwlMjAlM0QlMjBURkF1dG9Nb2RlbEZvclNlcTJTZXFMTS5mcm9tX3ByZXRyYWluZWQoY2hlY2twb2ludCk=",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> TFAutoModelForSeq2SeqLM

<span class="hljs-meta">&gt;&gt;&gt; </span>model = TFAutoModelForSeq2SeqLM.from_pretrained(checkpoint)`}}),N=new P({props:{code:"dGZfdHJhaW5fc2V0JTIwJTNEJTIwbW9kZWwucHJlcGFyZV90Zl9kYXRhc2V0KCUwQSUyMCUyMCUyMCUyMHRva2VuaXplZF9ib29rcyU1QiUyMnRyYWluJTIyJTVEJTJDJTBBJTIwJTIwJTIwJTIwc2h1ZmZsZSUzRFRydWUlMkMlMEElMjAlMjAlMjAlMjBiYXRjaF9zaXplJTNEMTYlMkMlMEElMjAlMjAlMjAlMjBjb2xsYXRlX2ZuJTNEZGF0YV9jb2xsYXRvciUyQyUwQSklMEElMEF0Zl90ZXN0X3NldCUyMCUzRCUyMG1vZGVsLnByZXBhcmVfdGZfZGF0YXNldCglMEElMjAlMjAlMjAlMjB0b2tlbml6ZWRfYm9va3MlNUIlMjJ0ZXN0JTIyJTVEJTJDJTBBJTIwJTIwJTIwJTIwc2h1ZmZsZSUzREZhbHNlJTJDJTBBJTIwJTIwJTIwJTIwYmF0Y2hfc2l6ZSUzRDE2JTJDJTBBJTIwJTIwJTIwJTIwY29sbGF0ZV9mbiUzRGRhdGFfY29sbGF0b3IlMkMlMEEp",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span>tf_train_set = model.prepare_tf_dataset(
<span class="hljs-meta">... </span>    tokenized_books[<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_test_set = model.prepare_tf_dataset(
<span class="hljs-meta">... </span>    tokenized_books[<span class="hljs-string">&quot;test&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>)`}}),ee=new P({props:{code:"aW1wb3J0JTIwdGVuc29yZmxvdyUyMGFzJTIwdGYlMEElMEFtb2RlbC5jb21waWxlKG9wdGltaXplciUzRG9wdGltaXplciklMjAlMjAlMjMlMjBObyUyMGxvc3MlMjBhcmd1bWVudCE=",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)  <span class="hljs-comment"># No loss argument!</span>`}}),le=new P({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycy5rZXJhc19jYWxsYmFja3MlMjBpbXBvcnQlMjBLZXJhc01ldHJpY0NhbGxiYWNrJTBBJTBBbWV0cmljX2NhbGxiYWNrJTIwJTNEJTIwS2VyYXNNZXRyaWNDYWxsYmFjayhtZXRyaWNfZm4lM0Rjb21wdXRlX21ldHJpY3MlMkMlMjBldmFsX2RhdGFzZXQlM0R0Zl92YWxpZGF0aW9uX3NldCk=",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers.keras_callbacks <span class="hljs-keyword">import</span> KerasMetricCallback

<span class="hljs-meta">&gt;&gt;&gt; </span>metric_callback = KerasMetricCallback(metric_fn=compute_metrics, eval_dataset=tf_validation_set)`}}),X=new P({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycy5rZXJhc19jYWxsYmFja3MlMjBpbXBvcnQlMjBQdXNoVG9IdWJDYWxsYmFjayUwQSUwQXB1c2hfdG9faHViX2NhbGxiYWNrJTIwJTNEJTIwUHVzaFRvSHViQ2FsbGJhY2soJTBBJTIwJTIwJTIwJTIwb3V0cHV0X2RpciUzRCUyMm15X2F3ZXNvbWVfb3B1c19ib29rc19tb2RlbCUyMiUyQyUwQSUyMCUyMCUyMCUyMHRva2VuaXplciUzRHRva2VuaXplciUyQyUwQSk=",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers.keras_callbacks <span class="hljs-keyword">import</span> PushToHubCallback

<span class="hljs-meta">&gt;&gt;&gt; </span>push_to_hub_callback = PushToHubCallback(
<span class="hljs-meta">... </span>    output_dir=<span class="hljs-string">&quot;my_awesome_opus_books_model&quot;</span>,
<span class="hljs-meta">... </span>    tokenizer=tokenizer,
<span class="hljs-meta">... </span>)`}}),Je=new P({props:{code:"Y2FsbGJhY2tzJTIwJTNEJTIwJTVCbWV0cmljX2NhbGxiYWNrJTJDJTIwcHVzaF90b19odWJfY2FsbGJhY2slNUQ=",highlighted:'<span class="hljs-meta">&gt;&gt;&gt; </span>callbacks = [metric_callback, push_to_hub_callback]'}}),fe=new P({props:{code:"bW9kZWwuZml0KHglM0R0Zl90cmFpbl9zZXQlMkMlMjB2YWxpZGF0aW9uX2RhdGElM0R0Zl90ZXN0X3NldCUyQyUyMGVwb2NocyUzRDMlMkMlMjBjYWxsYmFja3MlM0RjYWxsYmFja3Mp",highlighted:'<span class="hljs-meta">&gt;&gt;&gt; </span>model.fit(x=tf_train_set, validation_data=tf_test_set, epochs=<span class="hljs-number">3</span>, callbacks=callbacks)'}}),{c(){T(n.$$.fragment),m=a(`
To finetune a model in TensorFlow, start by setting up an optimizer function, learning rate schedule, and some training hyperparameters:

	`),T(o.$$.fragment),M=y(),w=p("p"),j=a("Then you can load T5 with "),B=p("a"),F=a("TFAutoModelForSeq2SeqLM"),_=a(":"),G=y(),T(R.$$.fragment),A=y(),S=p("p"),I=a("Convert your datasets to the "),W=p("code"),oe=a("tf.data.Dataset"),K=a(" format with "),V=p("a"),se=a("prepare_tf_dataset()"),Y=a(":"),H=y(),T(N.$$.fragment),x=y(),C=p("p"),u=a("Configure the model for training with "),$=p("a"),L=p("code"),O=a("compile"),de=a(". Note that Transformers models all have a default task-relevant loss function, so you don\u2019t need to specify one unless you want to:"),Q=y(),T(ee.$$.fragment),ke=y(),ae=p("p"),ge=a("The last two things to setup before you start training is to compute the SacreBLEU metric from the predictions, and provide a way to push your model to the Hub. Both are done by using "),ye=p("a"),be=a("Keras callbacks"),Se=a("."),We=y(),z=p("p"),Fe=a("Pass your "),ne=p("code"),Be=a("compute_metrics"),Ie=a(" function to "),pe=p("a"),ie=a("KerasMetricCallback"),me=a(":"),te=y(),T(le.$$.fragment),ce=y(),we=p("p"),_e=a("Specify where to push your model and tokenizer in the "),ve=p("a"),$e=a("PushToHubCallback"),re=a(":"),g=y(),T(X.$$.fragment),Me=y(),Ve=p("p"),Ue=a("Then bundle your callbacks together:"),D=y(),T(Je.$$.fragment),je=y(),he=p("p"),Re=a("Finally, you\u2019re ready to start training your model! Call "),ue=p("a"),Ee=p("code"),Ne=a("fit"),Te=a(" with your training and validation datasets, the number of epochs, and your callbacks to finetune the model:"),Ze=y(),T(fe.$$.fragment),Ae=y(),Ge=p("p"),xe=a("Once training is completed, your model is automatically uploaded to the Hub so everyone can use it!"),this.h()},l(r){k(n.$$.fragment,r),m=l(r,`
To finetune a model in TensorFlow, start by setting up an optimizer function, learning rate schedule, and some training hyperparameters:

	`),k(o.$$.fragment,r),M=b(r),w=i(r,"P",{});var Z=c(w);j=l(Z,"Then you can load T5 with "),B=i(Z,"A",{href:!0});var De=c(B);F=l(De,"TFAutoModelForSeq2SeqLM"),De.forEach(s),_=l(Z,":"),Z.forEach(s),G=b(r),k(R.$$.fragment,r),A=b(r),S=i(r,"P",{});var Ye=c(S);I=l(Ye,"Convert your datasets to the "),W=i(Ye,"CODE",{});var nt=c(W);oe=l(nt,"tf.data.Dataset"),nt.forEach(s),K=l(Ye," format with "),V=i(Ye,"A",{href:!0});var ze=c(V);se=l(ze,"prepare_tf_dataset()"),ze.forEach(s),Y=l(Ye,":"),Ye.forEach(s),H=b(r),k(N.$$.fragment,r),x=b(r),C=i(r,"P",{});var Ce=c(C);u=l(Ce,"Configure the model for training with "),$=i(Ce,"A",{href:!0,rel:!0});var lt=c($);L=i(lt,"CODE",{});var He=c(L);O=l(He,"compile"),He.forEach(s),lt.forEach(s),de=l(Ce,". Note that Transformers models all have a default task-relevant loss function, so you don\u2019t need to specify one unless you want to:"),Ce.forEach(s),Q=b(r),k(ee.$$.fragment,r),ke=b(r),ae=i(r,"P",{});var rt=c(ae);ge=l(rt,"The last two things to setup before you start training is to compute the SacreBLEU metric from the predictions, and provide a way to push your model to the Hub. Both are done by using "),ye=i(rt,"A",{href:!0});var ot=c(ye);be=l(ot,"Keras callbacks"),ot.forEach(s),Se=l(rt,"."),rt.forEach(s),We=b(r),z=i(r,"P",{});var qe=c(z);Fe=l(qe,"Pass your "),ne=i(qe,"CODE",{});var pt=c(ne);Be=l(pt,"compute_metrics"),pt.forEach(s),Ie=l(qe," function to "),pe=i(qe,"A",{href:!0});var Qe=c(pe);ie=l(Qe,"KerasMetricCallback"),Qe.forEach(s),me=l(qe,":"),qe.forEach(s),te=b(r),k(le.$$.fragment,r),ce=b(r),we=i(r,"P",{});var Ke=c(we);_e=l(Ke,"Specify where to push your model and tokenizer in the "),ve=i(Ke,"A",{href:!0});var Oe=c(ve);$e=l(Oe,"PushToHubCallback"),Oe.forEach(s),re=l(Ke,":"),Ke.forEach(s),g=b(r),k(X.$$.fragment,r),Me=b(r),Ve=i(r,"P",{});var mt=c(Ve);Ue=l(mt,"Then bundle your callbacks together:"),mt.forEach(s),D=b(r),k(Je.$$.fragment,r),je=b(r),he=i(r,"P",{});var et=c(he);Re=l(et,"Finally, you\u2019re ready to start training your model! Call "),ue=i(et,"A",{href:!0,rel:!0});var Pe=c(ue);Ee=i(Pe,"CODE",{});var it=c(Ee);Ne=l(it,"fit"),it.forEach(s),Pe.forEach(s),Te=l(et," with your training and validation datasets, the number of epochs, and your callbacks to finetune the model:"),et.forEach(s),Ze=b(r),k(fe.$$.fragment,r),Ae=b(r),Ge=i(r,"P",{});var tt=c(Ge);xe=l(tt,"Once training is completed, your model is automatically uploaded to the Hub so everyone can use it!"),tt.forEach(s),this.h()},h(){d(B,"href","/docs/transformers/v4.33.0/en/model_doc/auto#transformers.TFAutoModelForSeq2SeqLM"),d(V,"href","/docs/transformers/v4.33.0/en/main_classes/model#transformers.TFPreTrainedModel.prepare_tf_dataset"),d($,"href","https://keras.io/api/models/model_training_apis/#compile-method"),d($,"rel","nofollow"),d(ye,"href","../main_classes/keras_callbacks"),d(pe,"href","/docs/transformers/v4.33.0/en/main_classes/keras_callbacks#transformers.KerasMetricCallback"),d(ve,"href","/docs/transformers/v4.33.0/en/main_classes/keras_callbacks#transformers.PushToHubCallback"),d(ue,"href","https://keras.io/api/models/model_training_apis/#fit-method"),d(ue,"rel","nofollow")},m(r,Z){v(n,r,Z),f(r,m,Z),v(o,r,Z),f(r,M,Z),f(r,w,Z),t(w,j),t(w,B),t(B,F),t(w,_),f(r,G,Z),v(R,r,Z),f(r,A,Z),f(r,S,Z),t(S,I),t(S,W),t(W,oe),t(S,K),t(S,V),t(V,se),t(S,Y),f(r,H,Z),v(N,r,Z),f(r,x,Z),f(r,C,Z),t(C,u),t(C,$),t($,L),t(L,O),t(C,de),f(r,Q,Z),v(ee,r,Z),f(r,ke,Z),f(r,ae,Z),t(ae,ge),t(ae,ye),t(ye,be),t(ae,Se),f(r,We,Z),f(r,z,Z),t(z,Fe),t(z,ne),t(ne,Be),t(z,Ie),t(z,pe),t(pe,ie),t(z,me),f(r,te,Z),v(le,r,Z),f(r,ce,Z),f(r,we,Z),t(we,_e),t(we,ve),t(ve,$e),t(we,re),f(r,g,Z),v(X,r,Z),f(r,Me,Z),f(r,Ve,Z),t(Ve,Ue),f(r,D,Z),v(Je,r,Z),f(r,je,Z),f(r,he,Z),t(he,Re),t(he,ue),t(ue,Ee),t(Ee,Ne),t(he,Te),f(r,Ze,Z),v(fe,r,Z),f(r,Ae,Z),f(r,Ge,Z),t(Ge,xe),Xe=!0},p(r,Z){const De={};Z&2&&(De.$$scope={dirty:Z,ctx:r}),n.$set(De)},i(r){Xe||(U(n.$$.fragment,r),U(o.$$.fragment,r),U(R.$$.fragment,r),U(N.$$.fragment,r),U(ee.$$.fragment,r),U(le.$$.fragment,r),U(X.$$.fragment,r),U(Je.$$.fragment,r),U(fe.$$.fragment,r),Xe=!0)},o(r){J(n.$$.fragment,r),J(o.$$.fragment,r),J(R.$$.fragment,r),J(N.$$.fragment,r),J(ee.$$.fragment,r),J(le.$$.fragment,r),J(X.$$.fragment,r),J(Je.$$.fragment,r),J(fe.$$.fragment,r),Xe=!1},d(r){E(n,r),r&&s(m),E(o,r),r&&s(M),r&&s(w),r&&s(G),E(R,r),r&&s(A),r&&s(S),r&&s(H),E(N,r),r&&s(x),r&&s(C),r&&s(Q),E(ee,r),r&&s(ke),r&&s(ae),r&&s(We),r&&s(z),r&&s(te),E(le,r),r&&s(ce),r&&s(we),r&&s(g),E(X,r),r&&s(Me),r&&s(Ve),r&&s(D),E(Je,r),r&&s(je),r&&s(he),r&&s(Ze),E(fe,r),r&&s(Ae),r&&s(Ge)}}}function pr(q){let n,m;return n=new ss({props:{$$slots:{default:[nr]},$$scope:{ctx:q}}}),{c(){T(n.$$.fragment)},l(o){k(n.$$.fragment,o)},m(o,M){v(n,o,M),m=!0},p(o,M){const w={};M&2&&(w.$$scope={dirty:M,ctx:o}),n.$set(w)},i(o){m||(U(n.$$.fragment,o),m=!0)},o(o){J(n.$$.fragment,o),m=!1},d(o){E(n,o)}}}function ir(q){let n,m,o,M,w,j,B,F;return{c(){n=p("p"),m=a(`For a more in-depth example of how to finetune a model for translation, take a look at the corresponding
`),o=p("a"),M=a("PyTorch notebook"),w=a(`
or `),j=p("a"),B=a("TensorFlow notebook"),F=a("."),this.h()},l(_){n=i(_,"P",{});var G=c(n);m=l(G,`For a more in-depth example of how to finetune a model for translation, take a look at the corresponding
`),o=i(G,"A",{href:!0,rel:!0});var R=c(o);M=l(R,"PyTorch notebook"),R.forEach(s),w=l(G,`
or `),j=i(G,"A",{href:!0,rel:!0});var A=c(j);B=l(A,"TensorFlow notebook"),A.forEach(s),F=l(G,"."),G.forEach(s),this.h()},h(){d(o,"href","https://colab.research.google.com/github/huggingface/notebooks/blob/main/examples/translation.ipynb"),d(o,"rel","nofollow"),d(j,"href","https://colab.research.google.com/github/huggingface/notebooks/blob/main/examples/translation-tf.ipynb"),d(j,"rel","nofollow")},m(_,G){f(_,n,G),t(n,m),t(n,o),t(o,M),t(n,w),t(n,j),t(j,B),t(n,F)},d(_){_&&s(n)}}}function cr(q){let n,m,o,M,w,j,B,F,_,G,R,A,S,I,W,oe,K,V,se,Y,H,N,x,C;return B=new P({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9Ub2tlbml6ZXIlMEElMEF0b2tlbml6ZXIlMjAlM0QlMjBBdXRvVG9rZW5pemVyLmZyb21fcHJldHJhaW5lZCglMjJteV9hd2Vzb21lX29wdXNfYm9va3NfbW9kZWwlMjIpJTBBaW5wdXRzJTIwJTNEJTIwdG9rZW5pemVyKHRleHQlMkMlMjByZXR1cm5fdGVuc29ycyUzRCUyMnB0JTIyKS5pbnB1dF9pZHM=",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;my_awesome_opus_books_model&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>inputs = tokenizer(text, return_tensors=<span class="hljs-string">&quot;pt&quot;</span>).input_ids`}}),V=new P({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9Nb2RlbEZvclNlcTJTZXFMTSUwQSUwQW1vZGVsJTIwJTNEJTIwQXV0b01vZGVsRm9yU2VxMlNlcUxNLmZyb21fcHJldHJhaW5lZCglMjJteV9hd2Vzb21lX29wdXNfYm9va3NfbW9kZWwlMjIpJTBBb3V0cHV0cyUyMCUzRCUyMG1vZGVsLmdlbmVyYXRlKGlucHV0cyUyQyUyMG1heF9uZXdfdG9rZW5zJTNENDAlMkMlMjBkb19zYW1wbGUlM0RUcnVlJTJDJTIwdG9wX2slM0QzMCUyQyUyMHRvcF9wJTNEMC45NSk=",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoModelForSeq2SeqLM

<span class="hljs-meta">&gt;&gt;&gt; </span>model = AutoModelForSeq2SeqLM.from_pretrained(<span class="hljs-string">&quot;my_awesome_opus_books_model&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>outputs = model.generate(inputs, max_new_tokens=<span class="hljs-number">40</span>, do_sample=<span class="hljs-literal">True</span>, top_k=<span class="hljs-number">30</span>, top_p=<span class="hljs-number">0.95</span>)`}}),x=new P({props:{code:"dG9rZW5pemVyLmRlY29kZShvdXRwdXRzJTVCMCU1RCUyQyUyMHNraXBfc3BlY2lhbF90b2tlbnMlM0RUcnVlKQ==",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span>tokenizer.decode(outputs[<span class="hljs-number">0</span>], skip_special_tokens=<span class="hljs-literal">True</span>)
<span class="hljs-string">&#x27;Les lign\xE9es partagent des ressources avec des bact\xE9ries enfixant l&#x27;</span>azote.<span class="hljs-string">&#x27;</span>`}}),{c(){n=p("p"),m=a("Tokenize the text and return the "),o=p("code"),M=a("input_ids"),w=a(" as PyTorch tensors:"),j=y(),T(B.$$.fragment),F=y(),_=p("p"),G=a("Use the "),R=p("a"),A=a("generate()"),S=a(" method to create the translation. For more details about the different text generation strategies and parameters for controlling generation, check out the "),I=p("a"),W=a("Text Generation"),oe=a(" API."),K=y(),T(V.$$.fragment),se=y(),Y=p("p"),H=a("Decode the generated token ids back into text:"),N=y(),T(x.$$.fragment),this.h()},l(u){n=i(u,"P",{});var $=c(n);m=l($,"Tokenize the text and return the "),o=i($,"CODE",{});var L=c(o);M=l(L,"input_ids"),L.forEach(s),w=l($," as PyTorch tensors:"),$.forEach(s),j=b(u),k(B.$$.fragment,u),F=b(u),_=i(u,"P",{});var O=c(_);G=l(O,"Use the "),R=i(O,"A",{href:!0});var de=c(R);A=l(de,"generate()"),de.forEach(s),S=l(O," method to create the translation. For more details about the different text generation strategies and parameters for controlling generation, check out the "),I=i(O,"A",{href:!0});var Q=c(I);W=l(Q,"Text Generation"),Q.forEach(s),oe=l(O," API."),O.forEach(s),K=b(u),k(V.$$.fragment,u),se=b(u),Y=i(u,"P",{});var ee=c(Y);H=l(ee,"Decode the generated token ids back into text:"),ee.forEach(s),N=b(u),k(x.$$.fragment,u),this.h()},h(){d(R,"href","/docs/transformers/v4.33.0/en/main_classes/text_generation#transformers.GenerationMixin.generate"),d(I,"href","../main_classes/text_generation")},m(u,$){f(u,n,$),t(n,m),t(n,o),t(o,M),t(n,w),f(u,j,$),v(B,u,$),f(u,F,$),f(u,_,$),t(_,G),t(_,R),t(R,A),t(_,S),t(_,I),t(I,W),t(_,oe),f(u,K,$),v(V,u,$),f(u,se,$),f(u,Y,$),t(Y,H),f(u,N,$),v(x,u,$),C=!0},p:aa,i(u){C||(U(B.$$.fragment,u),U(V.$$.fragment,u),U(x.$$.fragment,u),C=!0)},o(u){J(B.$$.fragment,u),J(V.$$.fragment,u),J(x.$$.fragment,u),C=!1},d(u){u&&s(n),u&&s(j),E(B,u),u&&s(F),u&&s(_),u&&s(K),E(V,u),u&&s(se),u&&s(Y),u&&s(N),E(x,u)}}}function fr(q){let n,m;return n=new ss({props:{$$slots:{default:[cr]},$$scope:{ctx:q}}}),{c(){T(n.$$.fragment)},l(o){k(n.$$.fragment,o)},m(o,M){v(n,o,M),m=!0},p(o,M){const w={};M&2&&(w.$$scope={dirty:M,ctx:o}),n.$set(w)},i(o){m||(U(n.$$.fragment,o),m=!0)},o(o){J(n.$$.fragment,o),m=!1},d(o){E(n,o)}}}function mr(q){let n,m,o,M,w,j,B,F,_,G,R,A,S,I,W,oe,K,V,se,Y,H,N,x,C;return B=new P({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9Ub2tlbml6ZXIlMEElMEF0b2tlbml6ZXIlMjAlM0QlMjBBdXRvVG9rZW5pemVyLmZyb21fcHJldHJhaW5lZCglMjJteV9hd2Vzb21lX29wdXNfYm9va3NfbW9kZWwlMjIpJTBBaW5wdXRzJTIwJTNEJTIwdG9rZW5pemVyKHRleHQlMkMlMjByZXR1cm5fdGVuc29ycyUzRCUyMnRmJTIyKS5pbnB1dF9pZHM=",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;my_awesome_opus_books_model&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>inputs = tokenizer(text, return_tensors=<span class="hljs-string">&quot;tf&quot;</span>).input_ids`}}),V=new P({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMFRGQXV0b01vZGVsRm9yU2VxMlNlcUxNJTBBJTBBbW9kZWwlMjAlM0QlMjBURkF1dG9Nb2RlbEZvclNlcTJTZXFMTS5mcm9tX3ByZXRyYWluZWQoJTIybXlfYXdlc29tZV9vcHVzX2Jvb2tzX21vZGVsJTIyKSUwQW91dHB1dHMlMjAlM0QlMjBtb2RlbC5nZW5lcmF0ZShpbnB1dHMlMkMlMjBtYXhfbmV3X3Rva2VucyUzRDQwJTJDJTIwZG9fc2FtcGxlJTNEVHJ1ZSUyQyUyMHRvcF9rJTNEMzAlMkMlMjB0b3BfcCUzRDAuOTUp",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> TFAutoModelForSeq2SeqLM

<span class="hljs-meta">&gt;&gt;&gt; </span>model = TFAutoModelForSeq2SeqLM.from_pretrained(<span class="hljs-string">&quot;my_awesome_opus_books_model&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>outputs = model.generate(inputs, max_new_tokens=<span class="hljs-number">40</span>, do_sample=<span class="hljs-literal">True</span>, top_k=<span class="hljs-number">30</span>, top_p=<span class="hljs-number">0.95</span>)`}}),x=new P({props:{code:"dG9rZW5pemVyLmRlY29kZShvdXRwdXRzJTVCMCU1RCUyQyUyMHNraXBfc3BlY2lhbF90b2tlbnMlM0RUcnVlKQ==",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span>tokenizer.decode(outputs[<span class="hljs-number">0</span>], skip_special_tokens=<span class="hljs-literal">True</span>)
<span class="hljs-string">&#x27;Les lugumes partagent les ressources avec des bact\xE9ries fixatrices d&#x27;</span>azote.<span class="hljs-string">&#x27;</span>`}}),{c(){n=p("p"),m=a("Tokenize the text and return the "),o=p("code"),M=a("input_ids"),w=a(" as TensorFlow tensors:"),j=y(),T(B.$$.fragment),F=y(),_=p("p"),G=a("Use the "),R=p("a"),A=a("generate()"),S=a(" method to create the translation. For more details about the different text generation strategies and parameters for controlling generation, check out the "),I=p("a"),W=a("Text Generation"),oe=a(" API."),K=y(),T(V.$$.fragment),se=y(),Y=p("p"),H=a("Decode the generated token ids back into text:"),N=y(),T(x.$$.fragment),this.h()},l(u){n=i(u,"P",{});var $=c(n);m=l($,"Tokenize the text and return the "),o=i($,"CODE",{});var L=c(o);M=l(L,"input_ids"),L.forEach(s),w=l($," as TensorFlow tensors:"),$.forEach(s),j=b(u),k(B.$$.fragment,u),F=b(u),_=i(u,"P",{});var O=c(_);G=l(O,"Use the "),R=i(O,"A",{href:!0});var de=c(R);A=l(de,"generate()"),de.forEach(s),S=l(O," method to create the translation. For more details about the different text generation strategies and parameters for controlling generation, check out the "),I=i(O,"A",{href:!0});var Q=c(I);W=l(Q,"Text Generation"),Q.forEach(s),oe=l(O," API."),O.forEach(s),K=b(u),k(V.$$.fragment,u),se=b(u),Y=i(u,"P",{});var ee=c(Y);H=l(ee,"Decode the generated token ids back into text:"),ee.forEach(s),N=b(u),k(x.$$.fragment,u),this.h()},h(){d(R,"href","/docs/transformers/v4.33.0/en/main_classes/text_generation#transformers.TFGenerationMixin.generate"),d(I,"href","../main_classes/text_generation")},m(u,$){f(u,n,$),t(n,m),t(n,o),t(o,M),t(n,w),f(u,j,$),v(B,u,$),f(u,F,$),f(u,_,$),t(_,G),t(_,R),t(R,A),t(_,S),t(_,I),t(I,W),t(_,oe),f(u,K,$),v(V,u,$),f(u,se,$),f(u,Y,$),t(Y,H),f(u,N,$),v(x,u,$),C=!0},p:aa,i(u){C||(U(B.$$.fragment,u),U(V.$$.fragment,u),U(x.$$.fragment,u),C=!0)},o(u){J(B.$$.fragment,u),J(V.$$.fragment,u),J(x.$$.fragment,u),C=!1},d(u){u&&s(n),u&&s(j),E(B,u),u&&s(F),u&&s(_),u&&s(K),E(V,u),u&&s(se),u&&s(Y),u&&s(N),E(x,u)}}}function hr(q){let n,m;return n=new ss({props:{$$slots:{default:[mr]},$$scope:{ctx:q}}}),{c(){T(n.$$.fragment)},l(o){k(n.$$.fragment,o)},m(o,M){v(n,o,M),m=!0},p(o,M){const w={};M&2&&(w.$$scope={dirty:M,ctx:o}),n.$set(w)},i(o){m||(U(n.$$.fragment,o),m=!0)},o(o){J(n.$$.fragment,o),m=!1},d(o){E(n,o)}}}function ur(q){let n,m,o,M,w,j,B,F,_,G,R,A,S,I,W,oe,K,V,se,Y,H,N,x,C,u,$,L,O,de,Q,ee,ke,ae,ge,ye,be,Se,We,z,Fe,ne,Be,Ie,pe,ie,me,te,le,ce,we,_e,ve,$e,re,g,X,Me,Ve,Ue,D,Je,je,he,Re,ue,Ee,Ne,Te,Ze,fe,Ae,Ge,xe,Xe,r,Z,De,Ye,nt,ze,Ce,lt,He,rt,ot,qe,pt,Qe,Ke,Oe,mt,et,Pe,it,tt,Ht,Et,Le,yt,la,ra,as,oa,na,Zt,pa,ls,ia,ca,_s,Bt,$s,st,fa,Rt,ma,ha,rs,ua,da,os,ya,ba,js,Gt,Ts,ct,Ma,qt,ga,wa,ns,_a,$a,ks,bt,vs,ht,Mt,ps,Xt,ja,is,Ta,Us,at,ka,Wt,va,Ua,Vt,Ja,Ea,Ft,Za,Ba,Js,It,Es,gt,Ra,Ct,Ga,Xa,Zs,St,Bs,wt,Wa,cs,Va,Fa,Rs,ut,_t,fs,Nt,Ia,ms,Ca,Gs,$t,Xs,jt,Ws,dt,Tt,hs,At,Sa,us,Na,Vs,Qt,Aa,Fs,Pt,xa,Is,xt,Cs,ft,za,Lt,Ya,Ha,ds,qa,Qa,Ss,zt,Ns,kt,Pa,ys,La,Da,As,vt,xs;return j=new ts({}),R=new Dl({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/en/translation.ipynb"},{label:"PyTorch",value:"https://colab.research.google.com/github/huggingface/notebooks/blob/main/transformers_doc/en/pytorch/translation.ipynb"},{label:"TensorFlow",value:"https://colab.research.google.com/github/huggingface/notebooks/blob/main/transformers_doc/en/tensorflow/translation.ipynb"},{label:"Mixed",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/main/transformers_doc/en/translation.ipynb"},{label:"PyTorch",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/main/transformers_doc/en/pytorch/translation.ipynb"},{label:"TensorFlow",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/main/transformers_doc/en/tensorflow/translation.ipynb"}]}}),S=new Yl({props:{id:"1JvfrvZgi6c"}}),ge=new sa({props:{$$slots:{default:[Kl]},$$scope:{ctx:q}}}),z=new P({props:{code:"cGlwJTIwaW5zdGFsbCUyMHRyYW5zZm9ybWVycyUyMGRhdGFzZXRzJTIwZXZhbHVhdGUlMjBzYWNyZWJsZXU=",highlighted:"pip install transformers datasets evaluate sacrebleu"}}),pe=new P({props:{code:"ZnJvbSUyMGh1Z2dpbmdmYWNlX2h1YiUyMGltcG9ydCUyMG5vdGVib29rX2xvZ2luJTBBJTBBbm90ZWJvb2tfbG9naW4oKQ==",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> huggingface_hub <span class="hljs-keyword">import</span> notebook_login

<span class="hljs-meta">&gt;&gt;&gt; </span>notebook_login()`}}),ce=new ts({}),D=new P({props:{code:"ZnJvbSUyMGRhdGFzZXRzJTIwaW1wb3J0JTIwbG9hZF9kYXRhc2V0JTBBJTBBYm9va3MlMjAlM0QlMjBsb2FkX2RhdGFzZXQoJTIyb3B1c19ib29rcyUyMiUyQyUyMCUyMmVuLWZyJTIyKQ==",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>books = load_dataset(<span class="hljs-string">&quot;opus_books&quot;</span>, <span class="hljs-string">&quot;en-fr&quot;</span>)`}}),Te=new P({props:{code:"Ym9va3MlMjAlM0QlMjBib29rcyU1QiUyMnRyYWluJTIyJTVELnRyYWluX3Rlc3Rfc3BsaXQodGVzdF9zaXplJTNEMC4yKQ==",highlighted:'<span class="hljs-meta">&gt;&gt;&gt; </span>books = books[<span class="hljs-string">&quot;train&quot;</span>].train_test_split(test_size=<span class="hljs-number">0.2</span>)'}}),xe=new P({props:{code:"Ym9va3MlNUIlMjJ0cmFpbiUyMiU1RCU1QjAlNUQ=",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span>books[<span class="hljs-string">&quot;train&quot;</span>][<span class="hljs-number">0</span>]
{<span class="hljs-string">&#x27;id&#x27;</span>: <span class="hljs-string">&#x27;90560&#x27;</span>,
 <span class="hljs-string">&#x27;translation&#x27;</span>: {<span class="hljs-string">&#x27;en&#x27;</span>: <span class="hljs-string">&#x27;But this lofty plateau measured only a few fathoms, and soon we reentered Our Element.&#x27;</span>,
  <span class="hljs-string">&#x27;fr&#x27;</span>: <span class="hljs-string">&#x27;Mais ce plateau \xE9lev\xE9 ne mesurait que quelques toises, et bient\xF4t nous f\xFBmes rentr\xE9s dans notre \xE9l\xE9ment.&#x27;</span>}}`}}),He=new ts({}),Qe=new Yl({props:{id:"XAR8jnZZuUs"}}),Pe=new P({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9Ub2tlbml6ZXIlMEElMEFjaGVja3BvaW50JTIwJTNEJTIwJTIydDUtc21hbGwlMjIlMEF0b2tlbml6ZXIlMjAlM0QlMjBBdXRvVG9rZW5pemVyLmZyb21fcHJldHJhaW5lZChjaGVja3BvaW50KQ==",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>checkpoint = <span class="hljs-string">&quot;t5-small&quot;</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>tokenizer = AutoTokenizer.from_pretrained(checkpoint)`}}),Bt=new P({props:{code:"c291cmNlX2xhbmclMjAlM0QlMjAlMjJlbiUyMiUwQXRhcmdldF9sYW5nJTIwJTNEJTIwJTIyZnIlMjIlMEFwcmVmaXglMjAlM0QlMjAlMjJ0cmFuc2xhdGUlMjBFbmdsaXNoJTIwdG8lMjBGcmVuY2glM0ElMjAlMjIlMEElMEElMEFkZWYlMjBwcmVwcm9jZXNzX2Z1bmN0aW9uKGV4YW1wbGVzKSUzQSUwQSUyMCUyMCUyMCUyMGlucHV0cyUyMCUzRCUyMCU1QnByZWZpeCUyMCUyQiUyMGV4YW1wbGUlNUJzb3VyY2VfbGFuZyU1RCUyMGZvciUyMGV4YW1wbGUlMjBpbiUyMGV4YW1wbGVzJTVCJTIydHJhbnNsYXRpb24lMjIlNUQlNUQlMEElMjAlMjAlMjAlMjB0YXJnZXRzJTIwJTNEJTIwJTVCZXhhbXBsZSU1QnRhcmdldF9sYW5nJTVEJTIwZm9yJTIwZXhhbXBsZSUyMGluJTIwZXhhbXBsZXMlNUIlMjJ0cmFuc2xhdGlvbiUyMiU1RCU1RCUwQSUyMCUyMCUyMCUyMG1vZGVsX2lucHV0cyUyMCUzRCUyMHRva2VuaXplcihpbnB1dHMlMkMlMjB0ZXh0X3RhcmdldCUzRHRhcmdldHMlMkMlMjBtYXhfbGVuZ3RoJTNEMTI4JTJDJTIwdHJ1bmNhdGlvbiUzRFRydWUpJTBBJTIwJTIwJTIwJTIwcmV0dXJuJTIwbW9kZWxfaW5wdXRz",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span>source_lang = <span class="hljs-string">&quot;en&quot;</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>target_lang = <span class="hljs-string">&quot;fr&quot;</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>prefix = <span class="hljs-string">&quot;translate English to French: &quot;</span>


<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>    inputs = [prefix + example[source_lang] <span class="hljs-keyword">for</span> example <span class="hljs-keyword">in</span> examples[<span class="hljs-string">&quot;translation&quot;</span>]]
<span class="hljs-meta">... </span>    targets = [example[target_lang] <span class="hljs-keyword">for</span> example <span class="hljs-keyword">in</span> examples[<span class="hljs-string">&quot;translation&quot;</span>]]
<span class="hljs-meta">... </span>    model_inputs = tokenizer(inputs, text_target=targets, max_length=<span class="hljs-number">128</span>, truncation=<span class="hljs-literal">True</span>)
<span class="hljs-meta">... </span>    <span class="hljs-keyword">return</span> model_inputs`}}),Gt=new P({props:{code:"dG9rZW5pemVkX2Jvb2tzJTIwJTNEJTIwYm9va3MubWFwKHByZXByb2Nlc3NfZnVuY3Rpb24lMkMlMjBiYXRjaGVkJTNEVHJ1ZSk=",highlighted:'<span class="hljs-meta">&gt;&gt;&gt; </span>tokenized_books = books.<span class="hljs-built_in">map</span>(preprocess_function, batched=<span class="hljs-literal">True</span>)'}}),bt=new Oa({props:{pytorch:!0,tensorflow:!0,jax:!1,$$slots:{tensorflow:[sr],pytorch:[er]},$$scope:{ctx:q}}}),Xt=new ts({}),It=new P({props:{code:"aW1wb3J0JTIwZXZhbHVhdGUlMEElMEFtZXRyaWMlMjAlM0QlMjBldmFsdWF0ZS5sb2FkKCUyMnNhY3JlYmxldSUyMik=",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">import</span> evaluate

<span class="hljs-meta">&gt;&gt;&gt; </span>metric = evaluate.load(<span class="hljs-string">&quot;sacrebleu&quot;</span>)`}}),St=new P({props:{code:"aW1wb3J0JTIwbnVtcHklMjBhcyUyMG5wJTBBJTBBJTBBZGVmJTIwcG9zdHByb2Nlc3NfdGV4dChwcmVkcyUyQyUyMGxhYmVscyklM0ElMEElMjAlMjAlMjAlMjBwcmVkcyUyMCUzRCUyMCU1QnByZWQuc3RyaXAoKSUyMGZvciUyMHByZWQlMjBpbiUyMHByZWRzJTVEJTBBJTIwJTIwJTIwJTIwbGFiZWxzJTIwJTNEJTIwJTVCJTVCbGFiZWwuc3RyaXAoKSU1RCUyMGZvciUyMGxhYmVsJTIwaW4lMjBsYWJlbHMlNUQlMEElMEElMjAlMjAlMjAlMjByZXR1cm4lMjBwcmVkcyUyQyUyMGxhYmVscyUwQSUwQSUwQWRlZiUyMGNvbXB1dGVfbWV0cmljcyhldmFsX3ByZWRzKSUzQSUwQSUyMCUyMCUyMCUyMHByZWRzJTJDJTIwbGFiZWxzJTIwJTNEJTIwZXZhbF9wcmVkcyUwQSUyMCUyMCUyMCUyMGlmJTIwaXNpbnN0YW5jZShwcmVkcyUyQyUyMHR1cGxlKSUzQSUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMHByZWRzJTIwJTNEJTIwcHJlZHMlNUIwJTVEJTBBJTIwJTIwJTIwJTIwZGVjb2RlZF9wcmVkcyUyMCUzRCUyMHRva2VuaXplci5iYXRjaF9kZWNvZGUocHJlZHMlMkMlMjBza2lwX3NwZWNpYWxfdG9rZW5zJTNEVHJ1ZSklMEElMEElMjAlMjAlMjAlMjBsYWJlbHMlMjAlM0QlMjBucC53aGVyZShsYWJlbHMlMjAhJTNEJTIwLTEwMCUyQyUyMGxhYmVscyUyQyUyMHRva2VuaXplci5wYWRfdG9rZW5faWQpJTBBJTIwJTIwJTIwJTIwZGVjb2RlZF9sYWJlbHMlMjAlM0QlMjB0b2tlbml6ZXIuYmF0Y2hfZGVjb2RlKGxhYmVscyUyQyUyMHNraXBfc3BlY2lhbF90b2tlbnMlM0RUcnVlKSUwQSUwQSUyMCUyMCUyMCUyMGRlY29kZWRfcHJlZHMlMkMlMjBkZWNvZGVkX2xhYmVscyUyMCUzRCUyMHBvc3Rwcm9jZXNzX3RleHQoZGVjb2RlZF9wcmVkcyUyQyUyMGRlY29kZWRfbGFiZWxzKSUwQSUwQSUyMCUyMCUyMCUyMHJlc3VsdCUyMCUzRCUyMG1ldHJpYy5jb21wdXRlKHByZWRpY3Rpb25zJTNEZGVjb2RlZF9wcmVkcyUyQyUyMHJlZmVyZW5jZXMlM0RkZWNvZGVkX2xhYmVscyklMEElMjAlMjAlMjAlMjByZXN1bHQlMjAlM0QlMjAlN0IlMjJibGV1JTIyJTNBJTIwcmVzdWx0JTVCJTIyc2NvcmUlMjIlNUQlN0QlMEElMEElMjAlMjAlMjAlMjBwcmVkaWN0aW9uX2xlbnMlMjAlM0QlMjAlNUJucC5jb3VudF9ub256ZXJvKHByZWQlMjAhJTNEJTIwdG9rZW5pemVyLnBhZF90b2tlbl9pZCklMjBmb3IlMjBwcmVkJTIwaW4lMjBwcmVkcyU1RCUwQSUyMCUyMCUyMCUyMHJlc3VsdCU1QiUyMmdlbl9sZW4lMjIlNUQlMjAlM0QlMjBucC5tZWFuKHByZWRpY3Rpb25fbGVucyklMEElMjAlMjAlMjAlMjByZXN1bHQlMjAlM0QlMjAlN0JrJTNBJTIwcm91bmQodiUyQyUyMDQpJTIwZm9yJTIwayUyQyUyMHYlMjBpbiUyMHJlc3VsdC5pdGVtcygpJTdEJTBBJTIwJTIwJTIwJTIwcmV0dXJuJTIwcmVzdWx0",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">def</span> <span class="hljs-title function_">postprocess_text</span>(<span class="hljs-params">preds, labels</span>):
<span class="hljs-meta">... </span>    preds = [pred.strip() <span class="hljs-keyword">for</span> pred <span class="hljs-keyword">in</span> preds]
<span class="hljs-meta">... </span>    labels = [[label.strip()] <span class="hljs-keyword">for</span> label <span class="hljs-keyword">in</span> labels]

<span class="hljs-meta">... </span>    <span class="hljs-keyword">return</span> preds, labels


<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_preds</span>):
<span class="hljs-meta">... </span>    preds, labels = eval_preds
<span class="hljs-meta">... </span>    <span class="hljs-keyword">if</span> <span class="hljs-built_in">isinstance</span>(preds, <span class="hljs-built_in">tuple</span>):
<span class="hljs-meta">... </span>        preds = preds[<span class="hljs-number">0</span>]
<span class="hljs-meta">... </span>    decoded_preds = tokenizer.batch_decode(preds, skip_special_tokens=<span class="hljs-literal">True</span>)

<span class="hljs-meta">... </span>    labels = np.where(labels != -<span class="hljs-number">100</span>, labels, tokenizer.pad_token_id)
<span class="hljs-meta">... </span>    decoded_labels = tokenizer.batch_decode(labels, skip_special_tokens=<span class="hljs-literal">True</span>)

<span class="hljs-meta">... </span>    decoded_preds, decoded_labels = postprocess_text(decoded_preds, decoded_labels)

<span class="hljs-meta">... </span>    result = metric.compute(predictions=decoded_preds, references=decoded_labels)
<span class="hljs-meta">... </span>    result = {<span class="hljs-string">&quot;bleu&quot;</span>: result[<span class="hljs-string">&quot;score&quot;</span>]}

<span class="hljs-meta">... </span>    prediction_lens = [np.count_nonzero(pred != tokenizer.pad_token_id) <span class="hljs-keyword">for</span> pred <span class="hljs-keyword">in</span> preds]
<span class="hljs-meta">... </span>    result[<span class="hljs-string">&quot;gen_len&quot;</span>] = np.mean(prediction_lens)
<span class="hljs-meta">... </span>    result = {k: <span class="hljs-built_in">round</span>(v, <span class="hljs-number">4</span>) <span class="hljs-keyword">for</span> k, v <span class="hljs-keyword">in</span> result.items()}
<span class="hljs-meta">... </span>    <span class="hljs-keyword">return</span> result`}}),Nt=new ts({}),$t=new Oa({props:{pytorch:!0,tensorflow:!0,jax:!1,$$slots:{tensorflow:[pr],pytorch:[rr]},$$scope:{ctx:q}}}),jt=new sa({props:{$$slots:{default:[ir]},$$scope:{ctx:q}}}),At=new ts({}),xt=new P({props:{code:"dGV4dCUyMCUzRCUyMCUyMnRyYW5zbGF0ZSUyMEVuZ2xpc2glMjB0byUyMEZyZW5jaCUzQSUyMExlZ3VtZXMlMjBzaGFyZSUyMHJlc291cmNlcyUyMHdpdGglMjBuaXRyb2dlbi1maXhpbmclMjBiYWN0ZXJpYS4lMjI=",highlighted:'<span class="hljs-meta">&gt;&gt;&gt; </span>text = <span class="hljs-string">&quot;translate English to French: Legumes share resources with nitrogen-fixing bacteria.&quot;</span>'}}),zt=new P({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMHBpcGVsaW5lJTBBJTBBdHJhbnNsYXRvciUyMCUzRCUyMHBpcGVsaW5lKCUyMnRyYW5zbGF0aW9uJTIyJTJDJTIwbW9kZWwlM0QlMjJteV9hd2Vzb21lX29wdXNfYm9va3NfbW9kZWwlMjIpJTBBdHJhbnNsYXRvcih0ZXh0KQ==",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> pipeline

<span class="hljs-meta">&gt;&gt;&gt; </span>translator = pipeline(<span class="hljs-string">&quot;translation&quot;</span>, model=<span class="hljs-string">&quot;my_awesome_opus_books_model&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>translator(text)
[{<span class="hljs-string">&#x27;translation_text&#x27;</span>: <span class="hljs-string">&#x27;Legumes partagent des ressources avec des bact\xE9ries azotantes.&#x27;</span>}]`}}),vt=new Oa({props:{pytorch:!0,tensorflow:!0,jax:!1,$$slots:{tensorflow:[hr],pytorch:[fr]},$$scope:{ctx:q}}}),{c(){n=p("meta"),m=y(),o=p("h1"),M=p("a"),w=p("span"),T(j.$$.fragment),B=y(),F=p("span"),_=a("Translation"),G=y(),T(R.$$.fragment),A=y(),T(S.$$.fragment),I=y(),W=p("p"),oe=a("Translation converts a sequence of text from one language to another. It is one of several tasks you can formulate as a sequence-to-sequence problem, a powerful framework for returning some output from an input, like translation or summarization. Translation systems are commonly used for translation between different language texts, but it can also be used for speech or some combination in between like text-to-speech or speech-to-text."),K=y(),V=p("p"),se=a("This guide will show you how to:"),Y=y(),H=p("ol"),N=p("li"),x=a("Finetune "),C=p("a"),u=a("T5"),$=a(" on the English-French subset of the "),L=p("a"),O=a("OPUS Books"),de=a(" dataset to translate English text to French."),Q=y(),ee=p("li"),ke=a("Use your finetuned model for inference."),ae=y(),T(ge.$$.fragment),ye=y(),be=p("p"),Se=a("Before you begin, make sure you have all the necessary libraries installed:"),We=y(),T(z.$$.fragment),Fe=y(),ne=p("p"),Be=a("We encourage you to login to your Hugging Face account so you can upload and share your model with the community. When prompted, enter your token to login:"),Ie=y(),T(pe.$$.fragment),ie=y(),me=p("h2"),te=p("a"),le=p("span"),T(ce.$$.fragment),we=y(),_e=p("span"),ve=a("Load OPUS Books dataset"),$e=y(),re=p("p"),g=a("Start by loading the English-French subset of the "),X=p("a"),Me=a("OPUS Books"),Ve=a(" dataset from the \u{1F917} Datasets library:"),Ue=y(),T(D.$$.fragment),Je=y(),je=p("p"),he=a("Split the dataset into a train and test set with the "),Re=p("a"),ue=a("train_test_split"),Ee=a(" method:"),Ne=y(),T(Te.$$.fragment),Ze=y(),fe=p("p"),Ae=a("Then take a look at an example:"),Ge=y(),T(xe.$$.fragment),Xe=y(),r=p("p"),Z=p("code"),De=a("translation"),Ye=a(": an English and French translation of the text."),nt=y(),ze=p("h2"),Ce=p("a"),lt=p("span"),T(He.$$.fragment),rt=y(),ot=p("span"),qe=a("Preprocess"),pt=y(),T(Qe.$$.fragment),Ke=y(),Oe=p("p"),mt=a("The next step is to load a T5 tokenizer to process the English-French language pairs:"),et=y(),T(Pe.$$.fragment),it=y(),tt=p("p"),Ht=a("The preprocessing function you want to create needs to:"),Et=y(),Le=p("ol"),yt=p("li"),la=a("Prefix the input with a prompt so T5 knows this is a translation task. Some models capable of multiple NLP tasks require prompting for specific tasks."),ra=y(),as=p("li"),oa=a("Tokenize the input (English) and target (French) separately because you can\u2019t tokenize French text with a tokenizer pretrained on an English vocabulary."),na=y(),Zt=p("li"),pa=a("Truncate sequences to be no longer than the maximum length set by the "),ls=p("code"),ia=a("max_length"),ca=a(" parameter."),_s=y(),T(Bt.$$.fragment),$s=y(),st=p("p"),fa=a("To apply the preprocessing function over the entire dataset, use \u{1F917} Datasets "),Rt=p("a"),ma=a("map"),ha=a(" method. You can speed up the "),rs=p("code"),ua=a("map"),da=a(" function by setting "),os=p("code"),ya=a("batched=True"),ba=a(" to process multiple elements of the dataset at once:"),js=y(),T(Gt.$$.fragment),Ts=y(),ct=p("p"),Ma=a("Now create a batch of examples using "),qt=p("a"),ga=a("DataCollatorForSeq2Seq"),wa=a(". It\u2019s more efficient to "),ns=p("em"),_a=a("dynamically pad"),$a=a(" the sentences to the longest length in a batch during collation, instead of padding the whole dataset to the maximum length."),ks=y(),T(bt.$$.fragment),vs=y(),ht=p("h2"),Mt=p("a"),ps=p("span"),T(Xt.$$.fragment),ja=y(),is=p("span"),Ta=a("Evaluate"),Us=y(),at=p("p"),ka=a("Including a metric during training is often helpful for evaluating your model\u2019s performance. You can quickly load a evaluation method with the \u{1F917} "),Wt=p("a"),va=a("Evaluate"),Ua=a(" library. For this task, load the "),Vt=p("a"),Ja=a("SacreBLEU"),Ea=a(" metric (see the \u{1F917} Evaluate "),Ft=p("a"),Za=a("quick tour"),Ba=a(" to learn more about how to load and compute a metric):"),Js=y(),T(It.$$.fragment),Es=y(),gt=p("p"),Ra=a("Then create a function that passes your predictions and labels to "),Ct=p("a"),Ga=a("compute"),Xa=a(" to calculate the SacreBLEU score:"),Zs=y(),T(St.$$.fragment),Bs=y(),wt=p("p"),Wa=a("Your "),cs=p("code"),Va=a("compute_metrics"),Fa=a(" function is ready to go now, and you\u2019ll return to it when you setup your training."),Rs=y(),ut=p("h2"),_t=p("a"),fs=p("span"),T(Nt.$$.fragment),Ia=y(),ms=p("span"),Ca=a("Train"),Gs=y(),T($t.$$.fragment),Xs=y(),T(jt.$$.fragment),Ws=y(),dt=p("h2"),Tt=p("a"),hs=p("span"),T(At.$$.fragment),Sa=y(),us=p("span"),Na=a("Inference"),Vs=y(),Qt=p("p"),Aa=a("Great, now that you\u2019ve finetuned a model, you can use it for inference!"),Fs=y(),Pt=p("p"),xa=a("Come up with some text you\u2019d like to translate to another language. For T5, you need to prefix your input depending on the task you\u2019re working on. For translation from English to French, you should prefix your input as shown below:"),Is=y(),T(xt.$$.fragment),Cs=y(),ft=p("p"),za=a("The simplest way to try out your finetuned model for inference is to use it in a "),Lt=p("a"),Ya=a("pipeline()"),Ha=a(". Instantiate a "),ds=p("code"),qa=a("pipeline"),Qa=a(" for translation with your model, and pass your text to it:"),Ss=y(),T(zt.$$.fragment),Ns=y(),kt=p("p"),Pa=a("You can also manually replicate the results of the "),ys=p("code"),La=a("pipeline"),Da=a(" if you\u2019d like:"),As=y(),T(vt.$$.fragment),this.h()},l(e){const h=Pl('[data-svelte="svelte-1phssyn"]',document.head);n=i(h,"META",{name:!0,content:!0}),h.forEach(s),m=b(e),o=i(e,"H1",{class:!0});var Yt=c(o);M=i(Yt,"A",{id:!0,class:!0,href:!0});var bs=c(M);w=i(bs,"SPAN",{});var Ms=c(w);k(j.$$.fragment,Ms),Ms.forEach(s),bs.forEach(s),B=b(Yt),F=i(Yt,"SPAN",{});var gs=c(F);_=l(gs,"Translation"),gs.forEach(s),Yt.forEach(s),G=b(e),k(R.$$.fragment,e),A=b(e),k(S.$$.fragment,e),I=b(e),W=i(e,"P",{});var ws=c(W);oe=l(ws,"Translation converts a sequence of text from one language to another. It is one of several tasks you can formulate as a sequence-to-sequence problem, a powerful framework for returning some output from an input, like translation or summarization. Translation systems are commonly used for translation between different language texts, but it can also be used for speech or some combination in between like text-to-speech or speech-to-text."),ws.forEach(s),K=b(e),V=i(e,"P",{});var el=c(V);se=l(el,"This guide will show you how to:"),el.forEach(s),Y=b(e),H=i(e,"OL",{});var zs=c(H);N=i(zs,"LI",{});var Dt=c(N);x=l(Dt,"Finetune "),C=i(Dt,"A",{href:!0,rel:!0});var tl=c(C);u=l(tl,"T5"),tl.forEach(s),$=l(Dt," on the English-French subset of the "),L=i(Dt,"A",{href:!0,rel:!0});var sl=c(L);O=l(sl,"OPUS Books"),sl.forEach(s),de=l(Dt," dataset to translate English text to French."),Dt.forEach(s),Q=b(zs),ee=i(zs,"LI",{});var al=c(ee);ke=l(al,"Use your finetuned model for inference."),al.forEach(s),zs.forEach(s),ae=b(e),k(ge.$$.fragment,e),ye=b(e),be=i(e,"P",{});var ll=c(be);Se=l(ll,"Before you begin, make sure you have all the necessary libraries installed:"),ll.forEach(s),We=b(e),k(z.$$.fragment,e),Fe=b(e),ne=i(e,"P",{});var rl=c(ne);Be=l(rl,"We encourage you to login to your Hugging Face account so you can upload and share your model with the community. When prompted, enter your token to login:"),rl.forEach(s),Ie=b(e),k(pe.$$.fragment,e),ie=b(e),me=i(e,"H2",{class:!0});var Ys=c(me);te=i(Ys,"A",{id:!0,class:!0,href:!0});var ol=c(te);le=i(ol,"SPAN",{});var nl=c(le);k(ce.$$.fragment,nl),nl.forEach(s),ol.forEach(s),we=b(Ys),_e=i(Ys,"SPAN",{});var pl=c(_e);ve=l(pl,"Load OPUS Books dataset"),pl.forEach(s),Ys.forEach(s),$e=b(e),re=i(e,"P",{});var Hs=c(re);g=l(Hs,"Start by loading the English-French subset of the "),X=i(Hs,"A",{href:!0,rel:!0});var il=c(X);Me=l(il,"OPUS Books"),il.forEach(s),Ve=l(Hs," dataset from the \u{1F917} Datasets library:"),Hs.forEach(s),Ue=b(e),k(D.$$.fragment,e),Je=b(e),je=i(e,"P",{});var qs=c(je);he=l(qs,"Split the dataset into a train and test set with the "),Re=i(qs,"A",{href:!0,rel:!0});var cl=c(Re);ue=l(cl,"train_test_split"),cl.forEach(s),Ee=l(qs," method:"),qs.forEach(s),Ne=b(e),k(Te.$$.fragment,e),Ze=b(e),fe=i(e,"P",{});var fl=c(fe);Ae=l(fl,"Then take a look at an example:"),fl.forEach(s),Ge=b(e),k(xe.$$.fragment,e),Xe=b(e),r=i(e,"P",{});var Ka=c(r);Z=i(Ka,"CODE",{});var ml=c(Z);De=l(ml,"translation"),ml.forEach(s),Ye=l(Ka,": an English and French translation of the text."),Ka.forEach(s),nt=b(e),ze=i(e,"H2",{class:!0});var Qs=c(ze);Ce=i(Qs,"A",{id:!0,class:!0,href:!0});var hl=c(Ce);lt=i(hl,"SPAN",{});var ul=c(lt);k(He.$$.fragment,ul),ul.forEach(s),hl.forEach(s),rt=b(Qs),ot=i(Qs,"SPAN",{});var dl=c(ot);qe=l(dl,"Preprocess"),dl.forEach(s),Qs.forEach(s),pt=b(e),k(Qe.$$.fragment,e),Ke=b(e),Oe=i(e,"P",{});var yl=c(Oe);mt=l(yl,"The next step is to load a T5 tokenizer to process the English-French language pairs:"),yl.forEach(s),et=b(e),k(Pe.$$.fragment,e),it=b(e),tt=i(e,"P",{});var bl=c(tt);Ht=l(bl,"The preprocessing function you want to create needs to:"),bl.forEach(s),Et=b(e),Le=i(e,"OL",{});var Kt=c(Le);yt=i(Kt,"LI",{});var Ml=c(yt);la=l(Ml,"Prefix the input with a prompt so T5 knows this is a translation task. Some models capable of multiple NLP tasks require prompting for specific tasks."),Ml.forEach(s),ra=b(Kt),as=i(Kt,"LI",{});var gl=c(as);oa=l(gl,"Tokenize the input (English) and target (French) separately because you can\u2019t tokenize French text with a tokenizer pretrained on an English vocabulary."),gl.forEach(s),na=b(Kt),Zt=i(Kt,"LI",{});var Ps=c(Zt);pa=l(Ps,"Truncate sequences to be no longer than the maximum length set by the "),ls=i(Ps,"CODE",{});var wl=c(ls);ia=l(wl,"max_length"),wl.forEach(s),ca=l(Ps," parameter."),Ps.forEach(s),Kt.forEach(s),_s=b(e),k(Bt.$$.fragment,e),$s=b(e),st=i(e,"P",{});var Ut=c(st);fa=l(Ut,"To apply the preprocessing function over the entire dataset, use \u{1F917} Datasets "),Rt=i(Ut,"A",{href:!0,rel:!0});var _l=c(Rt);ma=l(_l,"map"),_l.forEach(s),ha=l(Ut," method. You can speed up the "),rs=i(Ut,"CODE",{});var $l=c(rs);ua=l($l,"map"),$l.forEach(s),da=l(Ut," function by setting "),os=i(Ut,"CODE",{});var jl=c(os);ya=l(jl,"batched=True"),jl.forEach(s),ba=l(Ut," to process multiple elements of the dataset at once:"),Ut.forEach(s),js=b(e),k(Gt.$$.fragment,e),Ts=b(e),ct=i(e,"P",{});var Ot=c(ct);Ma=l(Ot,"Now create a batch of examples using "),qt=i(Ot,"A",{href:!0});var Tl=c(qt);ga=l(Tl,"DataCollatorForSeq2Seq"),Tl.forEach(s),wa=l(Ot,". It\u2019s more efficient to "),ns=i(Ot,"EM",{});var kl=c(ns);_a=l(kl,"dynamically pad"),kl.forEach(s),$a=l(Ot," the sentences to the longest length in a batch during collation, instead of padding the whole dataset to the maximum length."),Ot.forEach(s),ks=b(e),k(bt.$$.fragment,e),vs=b(e),ht=i(e,"H2",{class:!0});var Ls=c(ht);Mt=i(Ls,"A",{id:!0,class:!0,href:!0});var vl=c(Mt);ps=i(vl,"SPAN",{});var Ul=c(ps);k(Xt.$$.fragment,Ul),Ul.forEach(s),vl.forEach(s),ja=b(Ls),is=i(Ls,"SPAN",{});var Jl=c(is);Ta=l(Jl,"Evaluate"),Jl.forEach(s),Ls.forEach(s),Us=b(e),at=i(e,"P",{});var Jt=c(at);ka=l(Jt,"Including a metric during training is often helpful for evaluating your model\u2019s performance. You can quickly load a evaluation method with the \u{1F917} "),Wt=i(Jt,"A",{href:!0,rel:!0});var El=c(Wt);va=l(El,"Evaluate"),El.forEach(s),Ua=l(Jt," library. For this task, load the "),Vt=i(Jt,"A",{href:!0,rel:!0});var Zl=c(Vt);Ja=l(Zl,"SacreBLEU"),Zl.forEach(s),Ea=l(Jt," metric (see the \u{1F917} Evaluate "),Ft=i(Jt,"A",{href:!0,rel:!0});var Bl=c(Ft);Za=l(Bl,"quick tour"),Bl.forEach(s),Ba=l(Jt," to learn more about how to load and compute a metric):"),Jt.forEach(s),Js=b(e),k(It.$$.fragment,e),Es=b(e),gt=i(e,"P",{});var Ds=c(gt);Ra=l(Ds,"Then create a function that passes your predictions and labels to "),Ct=i(Ds,"A",{href:!0,rel:!0});var Rl=c(Ct);Ga=l(Rl,"compute"),Rl.forEach(s),Xa=l(Ds," to calculate the SacreBLEU score:"),Ds.forEach(s),Zs=b(e),k(St.$$.fragment,e),Bs=b(e),wt=i(e,"P",{});var Ks=c(wt);Wa=l(Ks,"Your "),cs=i(Ks,"CODE",{});var Gl=c(cs);Va=l(Gl,"compute_metrics"),Gl.forEach(s),Fa=l(Ks," function is ready to go now, and you\u2019ll return to it when you setup your training."),Ks.forEach(s),Rs=b(e),ut=i(e,"H2",{class:!0});var Os=c(ut);_t=i(Os,"A",{id:!0,class:!0,href:!0});var Xl=c(_t);fs=i(Xl,"SPAN",{});var Wl=c(fs);k(Nt.$$.fragment,Wl),Wl.forEach(s),Xl.forEach(s),Ia=b(Os),ms=i(Os,"SPAN",{});var Vl=c(ms);Ca=l(Vl,"Train"),Vl.forEach(s),Os.forEach(s),Gs=b(e),k($t.$$.fragment,e),Xs=b(e),k(jt.$$.fragment,e),Ws=b(e),dt=i(e,"H2",{class:!0});var ea=c(dt);Tt=i(ea,"A",{id:!0,class:!0,href:!0});var Fl=c(Tt);hs=i(Fl,"SPAN",{});var Il=c(hs);k(At.$$.fragment,Il),Il.forEach(s),Fl.forEach(s),Sa=b(ea),us=i(ea,"SPAN",{});var Cl=c(us);Na=l(Cl,"Inference"),Cl.forEach(s),ea.forEach(s),Vs=b(e),Qt=i(e,"P",{});var Sl=c(Qt);Aa=l(Sl,"Great, now that you\u2019ve finetuned a model, you can use it for inference!"),Sl.forEach(s),Fs=b(e),Pt=i(e,"P",{});var Nl=c(Pt);xa=l(Nl,"Come up with some text you\u2019d like to translate to another language. For T5, you need to prefix your input depending on the task you\u2019re working on. For translation from English to French, you should prefix your input as shown below:"),Nl.forEach(s),Is=b(e),k(xt.$$.fragment,e),Cs=b(e),ft=i(e,"P",{});var es=c(ft);za=l(es,"The simplest way to try out your finetuned model for inference is to use it in a "),Lt=i(es,"A",{href:!0});var Al=c(Lt);Ya=l(Al,"pipeline()"),Al.forEach(s),Ha=l(es,". Instantiate a "),ds=i(es,"CODE",{});var xl=c(ds);qa=l(xl,"pipeline"),xl.forEach(s),Qa=l(es," for translation with your model, and pass your text to it:"),es.forEach(s),Ss=b(e),k(zt.$$.fragment,e),Ns=b(e),kt=i(e,"P",{});var ta=c(kt);Pa=l(ta,"You can also manually replicate the results of the "),ys=i(ta,"CODE",{});var zl=c(ys);La=l(zl,"pipeline"),zl.forEach(s),Da=l(ta," if you\u2019d like:"),ta.forEach(s),As=b(e),k(vt.$$.fragment,e),this.h()},h(){d(n,"name","hf:doc:metadata"),d(n,"content",JSON.stringify(dr)),d(M,"id","translation"),d(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"),d(M,"href","#translation"),d(o,"class","relative group"),d(C,"href","https://huggingface.co/t5-small"),d(C,"rel","nofollow"),d(L,"href","https://huggingface.co/datasets/opus_books"),d(L,"rel","nofollow"),d(te,"id","load-opus-books-dataset"),d(te,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),d(te,"href","#load-opus-books-dataset"),d(me,"class","relative group"),d(X,"href","https://huggingface.co/datasets/opus_books"),d(X,"rel","nofollow"),d(Re,"href","https://huggingface.co/docs/datasets/v2.14.4/en/package_reference/main_classes#datasets.Dataset.train_test_split"),d(Re,"rel","nofollow"),d(Ce,"id","preprocess"),d(Ce,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),d(Ce,"href","#preprocess"),d(ze,"class","relative group"),d(Rt,"href","https://huggingface.co/docs/datasets/v2.14.4/en/package_reference/main_classes#datasets.Dataset.map"),d(Rt,"rel","nofollow"),d(qt,"href","/docs/transformers/v4.33.0/en/main_classes/data_collator#transformers.DataCollatorForSeq2Seq"),d(Mt,"id","evaluate"),d(Mt,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),d(Mt,"href","#evaluate"),d(ht,"class","relative group"),d(Wt,"href","https://huggingface.co/docs/evaluate/index"),d(Wt,"rel","nofollow"),d(Vt,"href","https://huggingface.co/spaces/evaluate-metric/sacrebleu"),d(Vt,"rel","nofollow"),d(Ft,"href","https://huggingface.co/docs/evaluate/a_quick_tour"),d(Ft,"rel","nofollow"),d(Ct,"href","https://huggingface.co/docs/evaluate/v0.4.0/en/package_reference/main_classes#evaluate.EvaluationModule.compute"),d(Ct,"rel","nofollow"),d(_t,"id","train"),d(_t,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),d(_t,"href","#train"),d(ut,"class","relative group"),d(Tt,"id","inference"),d(Tt,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),d(Tt,"href","#inference"),d(dt,"class","relative group"),d(Lt,"href","/docs/transformers/v4.33.0/en/main_classes/pipelines#transformers.pipeline")},m(e,h){t(document.head,n),f(e,m,h),f(e,o,h),t(o,M),t(M,w),v(j,w,null),t(o,B),t(o,F),t(F,_),f(e,G,h),v(R,e,h),f(e,A,h),v(S,e,h),f(e,I,h),f(e,W,h),t(W,oe),f(e,K,h),f(e,V,h),t(V,se),f(e,Y,h),f(e,H,h),t(H,N),t(N,x),t(N,C),t(C,u),t(N,$),t(N,L),t(L,O),t(N,de),t(H,Q),t(H,ee),t(ee,ke),f(e,ae,h),v(ge,e,h),f(e,ye,h),f(e,be,h),t(be,Se),f(e,We,h),v(z,e,h),f(e,Fe,h),f(e,ne,h),t(ne,Be),f(e,Ie,h),v(pe,e,h),f(e,ie,h),f(e,me,h),t(me,te),t(te,le),v(ce,le,null),t(me,we),t(me,_e),t(_e,ve),f(e,$e,h),f(e,re,h),t(re,g),t(re,X),t(X,Me),t(re,Ve),f(e,Ue,h),v(D,e,h),f(e,Je,h),f(e,je,h),t(je,he),t(je,Re),t(Re,ue),t(je,Ee),f(e,Ne,h),v(Te,e,h),f(e,Ze,h),f(e,fe,h),t(fe,Ae),f(e,Ge,h),v(xe,e,h),f(e,Xe,h),f(e,r,h),t(r,Z),t(Z,De),t(r,Ye),f(e,nt,h),f(e,ze,h),t(ze,Ce),t(Ce,lt),v(He,lt,null),t(ze,rt),t(ze,ot),t(ot,qe),f(e,pt,h),v(Qe,e,h),f(e,Ke,h),f(e,Oe,h),t(Oe,mt),f(e,et,h),v(Pe,e,h),f(e,it,h),f(e,tt,h),t(tt,Ht),f(e,Et,h),f(e,Le,h),t(Le,yt),t(yt,la),t(Le,ra),t(Le,as),t(as,oa),t(Le,na),t(Le,Zt),t(Zt,pa),t(Zt,ls),t(ls,ia),t(Zt,ca),f(e,_s,h),v(Bt,e,h),f(e,$s,h),f(e,st,h),t(st,fa),t(st,Rt),t(Rt,ma),t(st,ha),t(st,rs),t(rs,ua),t(st,da),t(st,os),t(os,ya),t(st,ba),f(e,js,h),v(Gt,e,h),f(e,Ts,h),f(e,ct,h),t(ct,Ma),t(ct,qt),t(qt,ga),t(ct,wa),t(ct,ns),t(ns,_a),t(ct,$a),f(e,ks,h),v(bt,e,h),f(e,vs,h),f(e,ht,h),t(ht,Mt),t(Mt,ps),v(Xt,ps,null),t(ht,ja),t(ht,is),t(is,Ta),f(e,Us,h),f(e,at,h),t(at,ka),t(at,Wt),t(Wt,va),t(at,Ua),t(at,Vt),t(Vt,Ja),t(at,Ea),t(at,Ft),t(Ft,Za),t(at,Ba),f(e,Js,h),v(It,e,h),f(e,Es,h),f(e,gt,h),t(gt,Ra),t(gt,Ct),t(Ct,Ga),t(gt,Xa),f(e,Zs,h),v(St,e,h),f(e,Bs,h),f(e,wt,h),t(wt,Wa),t(wt,cs),t(cs,Va),t(wt,Fa),f(e,Rs,h),f(e,ut,h),t(ut,_t),t(_t,fs),v(Nt,fs,null),t(ut,Ia),t(ut,ms),t(ms,Ca),f(e,Gs,h),v($t,e,h),f(e,Xs,h),v(jt,e,h),f(e,Ws,h),f(e,dt,h),t(dt,Tt),t(Tt,hs),v(At,hs,null),t(dt,Sa),t(dt,us),t(us,Na),f(e,Vs,h),f(e,Qt,h),t(Qt,Aa),f(e,Fs,h),f(e,Pt,h),t(Pt,xa),f(e,Is,h),v(xt,e,h),f(e,Cs,h),f(e,ft,h),t(ft,za),t(ft,Lt),t(Lt,Ya),t(ft,Ha),t(ft,ds),t(ds,qa),t(ft,Qa),f(e,Ss,h),v(zt,e,h),f(e,Ns,h),f(e,kt,h),t(kt,Pa),t(kt,ys),t(ys,La),t(kt,Da),f(e,As,h),v(vt,e,h),xs=!0},p(e,[h]){const Yt={};h&2&&(Yt.$$scope={dirty:h,ctx:e}),ge.$set(Yt);const bs={};h&2&&(bs.$$scope={dirty:h,ctx:e}),bt.$set(bs);const Ms={};h&2&&(Ms.$$scope={dirty:h,ctx:e}),$t.$set(Ms);const gs={};h&2&&(gs.$$scope={dirty:h,ctx:e}),jt.$set(gs);const ws={};h&2&&(ws.$$scope={dirty:h,ctx:e}),vt.$set(ws)},i(e){xs||(U(j.$$.fragment,e),U(R.$$.fragment,e),U(S.$$.fragment,e),U(ge.$$.fragment,e),U(z.$$.fragment,e),U(pe.$$.fragment,e),U(ce.$$.fragment,e),U(D.$$.fragment,e),U(Te.$$.fragment,e),U(xe.$$.fragment,e),U(He.$$.fragment,e),U(Qe.$$.fragment,e),U(Pe.$$.fragment,e),U(Bt.$$.fragment,e),U(Gt.$$.fragment,e),U(bt.$$.fragment,e),U(Xt.$$.fragment,e),U(It.$$.fragment,e),U(St.$$.fragment,e),U(Nt.$$.fragment,e),U($t.$$.fragment,e),U(jt.$$.fragment,e),U(At.$$.fragment,e),U(xt.$$.fragment,e),U(zt.$$.fragment,e),U(vt.$$.fragment,e),xs=!0)},o(e){J(j.$$.fragment,e),J(R.$$.fragment,e),J(S.$$.fragment,e),J(ge.$$.fragment,e),J(z.$$.fragment,e),J(pe.$$.fragment,e),J(ce.$$.fragment,e),J(D.$$.fragment,e),J(Te.$$.fragment,e),J(xe.$$.fragment,e),J(He.$$.fragment,e),J(Qe.$$.fragment,e),J(Pe.$$.fragment,e),J(Bt.$$.fragment,e),J(Gt.$$.fragment,e),J(bt.$$.fragment,e),J(Xt.$$.fragment,e),J(It.$$.fragment,e),J(St.$$.fragment,e),J(Nt.$$.fragment,e),J($t.$$.fragment,e),J(jt.$$.fragment,e),J(At.$$.fragment,e),J(xt.$$.fragment,e),J(zt.$$.fragment,e),J(vt.$$.fragment,e),xs=!1},d(e){s(n),e&&s(m),e&&s(o),E(j),e&&s(G),E(R,e),e&&s(A),E(S,e),e&&s(I),e&&s(W),e&&s(K),e&&s(V),e&&s(Y),e&&s(H),e&&s(ae),E(ge,e),e&&s(ye),e&&s(be),e&&s(We),E(z,e),e&&s(Fe),e&&s(ne),e&&s(Ie),E(pe,e),e&&s(ie),e&&s(me),E(ce),e&&s($e),e&&s(re),e&&s(Ue),E(D,e),e&&s(Je),e&&s(je),e&&s(Ne),E(Te,e),e&&s(Ze),e&&s(fe),e&&s(Ge),E(xe,e),e&&s(Xe),e&&s(r),e&&s(nt),e&&s(ze),E(He),e&&s(pt),E(Qe,e),e&&s(Ke),e&&s(Oe),e&&s(et),E(Pe,e),e&&s(it),e&&s(tt),e&&s(Et),e&&s(Le),e&&s(_s),E(Bt,e),e&&s($s),e&&s(st),e&&s(js),E(Gt,e),e&&s(Ts),e&&s(ct),e&&s(ks),E(bt,e),e&&s(vs),e&&s(ht),E(Xt),e&&s(Us),e&&s(at),e&&s(Js),E(It,e),e&&s(Es),e&&s(gt),e&&s(Zs),E(St,e),e&&s(Bs),e&&s(wt),e&&s(Rs),e&&s(ut),E(Nt),e&&s(Gs),E($t,e),e&&s(Xs),E(jt,e),e&&s(Ws),e&&s(dt),E(At),e&&s(Vs),e&&s(Qt),e&&s(Fs),e&&s(Pt),e&&s(Is),E(xt,e),e&&s(Cs),e&&s(ft),e&&s(Ss),E(zt,e),e&&s(Ns),e&&s(kt),e&&s(As),E(vt,e)}}}const dr={local:"translation",sections:[{local:"load-opus-books-dataset",title:"Load OPUS Books dataset"},{local:"preprocess",title:"Preprocess"},{local:"evaluate",title:"Evaluate"},{local:"train",title:"Train"},{local:"inference",title:"Inference"}],title:"Translation"};function yr(q){return Ll(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Tr extends Hl{constructor(n){super();ql(this,n,yr,ur,Ql,{})}}export{Tr as default,dr as metadata};
