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 U,q as J,o as v,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 o,m,n,M,w,j,B,F,_,G,R,A,S,I,W,ne,K,V,se,Y,H,N,x,C,u,$,L,O,de,Q,ee,ke,ae,ge,ye,be,Se,We,z,Fe,oe,Be,Ie,pe,ie,me,te,le,ce,we,_e,Ue,$e,re,g,X,Me,Ve,Je,D,ve,je,he,Re,ue,Ee,Ne,Te,Ze,fe,Ae,Ge,xe;return{c(){o=a(`The task illustrated in this tutorial is supported by the following model architectures:

`),m=p("p"),n=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"),ne=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"),oe=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"),Ue=a("Pegasus"),$e=a(", "),re=p("a"),g=a("PEGASUS-X"),X=a(", "),Me=p("a"),Ve=a("PLBart"),Je=a(", "),D=p("a"),ve=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){o=l(Xe,`The task illustrated in this tutorial is supported by the following model architectures:

`),m=i(Xe,"P",{});var r=c(m);n=i(r,"A",{href:!0});var Z=c(n);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 ot=c(A);S=l(ot,"BlenderbotSmall"),ot.forEach(s),I=l(r,", "),W=i(r,"A",{href:!0});var ze=c(W);ne=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 nt=c(Q);ee=l(nt,"M2M100"),nt.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),oe=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);Ue=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),Je=l(r,", "),D=i(r,"A",{href:!0});var tt=c(D);ve=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(n,"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,o,r),f(Xe,m,r),t(m,n),t(n,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,ne),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,oe),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,Ue),t(m,$e),t(m,re),t(re,g),t(m,X),t(m,Me),t(Me,Ve),t(m,Je),t(m,D),t(D,ve),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(o),Xe&&s(m)}}}function Ol(q){let o,m;return o=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(o.$$.fragment)},l(n){k(o.$$.fragment,n)},m(n,M){U(o,n,M),m=!0},p:aa,i(n){m||(J(o.$$.fragment,n),m=!0)},o(n){v(o.$$.fragment,n),m=!1},d(n){E(o,n)}}}function er(q){let o,m;return o=new ss({props:{$$slots:{default:[Ol]},$$scope:{ctx:q}}}),{c(){T(o.$$.fragment)},l(n){k(o.$$.fragment,n)},m(n,M){U(o,n,M),m=!0},p(n,M){const w={};M&2&&(w.$$scope={dirty:M,ctx:n}),o.$set(w)},i(n){m||(J(o.$$.fragment,n),m=!0)},o(n){v(o.$$.fragment,n),m=!1},d(n){E(o,n)}}}function tr(q){let o,m;return o=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(o.$$.fragment)},l(n){k(o.$$.fragment,n)},m(n,M){U(o,n,M),m=!0},p:aa,i(n){m||(J(o.$$.fragment,n),m=!0)},o(n){v(o.$$.fragment,n),m=!1},d(n){E(o,n)}}}function sr(q){let o,m;return o=new ss({props:{$$slots:{default:[tr]},$$scope:{ctx:q}}}),{c(){T(o.$$.fragment)},l(n){k(o.$$.fragment,n)},m(n,M){U(o,n,M),m=!0},p(n,M){const w={};M&2&&(w.$$scope={dirty:M,ctx:n}),o.$set(w)},i(n){m||(J(o.$$.fragment,n),m=!0)},o(n){v(o.$$.fragment,n),m=!1},d(n){E(o,n)}}}function ar(q){let o,m,n,M,w,j,B,F;return{c(){o=p("p"),m=a("If you aren\u2019t familiar with finetuning a model with the "),n=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(_){o=i(_,"P",{});var G=c(o);m=l(G,"If you aren\u2019t familiar with finetuning a model with the "),n=i(G,"A",{href:!0});var R=c(n);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(n,"href","/docs/transformers/main/en/main_classes/trainer#transformers.Trainer"),d(j,"href","../training#train-with-pytorch-trainer")},m(_,G){f(_,o,G),t(o,m),t(o,n),t(n,M),t(o,w),t(o,j),t(j,B),t(o,F)},d(_){_&&s(o)}}}function lr(q){let o,m,n,M,w,j,B,F,_,G,R,A,S,I,W,ne,K,V,se,Y,H,N,x,C,u,$,L,O,de,Q,ee,ke,ae,ge,ye,be,Se,We,z,Fe,oe,Be,Ie,pe,ie,me,te,le,ce,we,_e,Ue,$e,re;return o=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(o.$$.fragment),m=y(),n=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"),ne=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 "),oe=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:"),Ue=y(),T($e.$$.fragment),this.h()},l(g){k(o.$$.fragment,g),m=b(g),n=i(g,"P",{});var X=c(n);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 Je=c(I);W=i(Je,"LI",{});var D=c(W);ne=l(D,"Define your training hyperparameters in "),K=i(D,"A",{href:!0});var ve=c(K);V=l(ve,"Seq2SeqTrainingArguments"),ve.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(Je),Q=i(Je,"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(Je),z=i(Je,"LI",{});var Te=c(z);Fe=l(Te,"Call "),oe=i(Te,"A",{href:!0});var Ze=c(oe);Be=l(Ze,"train()"),Ze.forEach(s),Ie=l(Te," to finetune your model."),Te.forEach(s),Je.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),Ue=b(g),k($e.$$.fragment,g),this.h()},h(){d(w,"href","/docs/transformers/main/en/model_doc/auto#transformers.AutoModelForSeq2SeqLM"),d(K,"href","/docs/transformers/main/en/main_classes/trainer#transformers.Seq2SeqTrainingArguments"),d($,"href","/docs/transformers/main/en/main_classes/trainer#transformers.Trainer"),d(ke,"href","/docs/transformers/main/en/main_classes/trainer#transformers.Seq2SeqTrainer"),d(oe,"href","/docs/transformers/main/en/main_classes/trainer#transformers.Trainer.train"),d(ce,"href","/docs/transformers/main/en/main_classes/trainer#transformers.Trainer.push_to_hub")},m(g,X){U(o,g,X),f(g,m,X),f(g,n,X),t(n,M),t(n,w),t(w,j),t(n,B),f(g,F,X),U(_,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,ne),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,oe),t(oe,Be),t(z,Ie),f(g,pe,X),U(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,Ue,X),U($e,g,X),re=!0},p(g,X){const Me={};X&2&&(Me.$$scope={dirty:X,ctx:g}),o.$set(Me)},i(g){re||(J(o.$$.fragment,g),J(_.$$.fragment,g),J(ie.$$.fragment,g),J($e.$$.fragment,g),re=!0)},o(g){v(o.$$.fragment,g),v(_.$$.fragment,g),v(ie.$$.fragment,g),v($e.$$.fragment,g),re=!1},d(g){E(o,g),g&&s(m),g&&s(n),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(Ue),E($e,g)}}}function rr(q){let o,m;return o=new ss({props:{$$slots:{default:[lr]},$$scope:{ctx:q}}}),{c(){T(o.$$.fragment)},l(n){k(o.$$.fragment,n)},m(n,M){U(o,n,M),m=!0},p(n,M){const w={};M&2&&(w.$$scope={dirty:M,ctx:n}),o.$set(w)},i(n){m||(J(o.$$.fragment,n),m=!0)},o(n){v(o.$$.fragment,n),m=!1},d(n){E(o,n)}}}function nr(q){let o,m,n,M,w;return{c(){o=p("p"),m=a("If you aren\u2019t familiar with finetuning a model with Keras, take a look at the basic tutorial "),n=p("a"),M=a("here"),w=a("!"),this.h()},l(j){o=i(j,"P",{});var B=c(o);m=l(B,"If you aren\u2019t familiar with finetuning a model with Keras, take a look at the basic tutorial "),n=i(B,"A",{href:!0});var F=c(n);M=l(F,"here"),F.forEach(s),w=l(B,"!"),B.forEach(s),this.h()},h(){d(n,"href","../training#train-a-tensorflow-model-with-keras")},m(j,B){f(j,o,B),t(o,m),t(o,n),t(n,M),t(o,w)},d(j){j&&s(o)}}}function or(q){let o,m,n,M,w,j,B,F,_,G,R,A,S,I,W,ne,K,V,se,Y,H,N,x,C,u,$,L,O,de,Q,ee,ke,ae,ge,ye,be,Se,We,z,Fe,oe,Be,Ie,pe,ie,me,te,le,ce,we,_e,Ue,$e,re,g,X,Me,Ve,Je,D,ve,je,he,Re,ue,Ee,Ne,Te,Ze,fe,Ae,Ge,xe,Xe;return o=new sa({props:{$$slots:{default:[nr]},$$scope:{ctx:q}}}),n=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>)`}}),ve=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(o.$$.fragment),m=a(`
To finetune a model in TensorFlow, start by setting up an optimizer function, learning rate schedule, and some training hyperparameters:

	`),T(n.$$.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"),ne=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 "),oe=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 "),Ue=p("a"),$e=a("PushToHubCallback"),re=a(":"),g=y(),T(X.$$.fragment),Me=y(),Ve=p("p"),Je=a("Then bundle your callbacks together:"),D=y(),T(ve.$$.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(o.$$.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(n.$$.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 ot=c(W);ne=l(ot,"tf.data.Dataset"),ot.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 nt=c(ye);be=l(nt,"Keras callbacks"),nt.forEach(s),Se=l(rt,"."),rt.forEach(s),We=b(r),z=i(r,"P",{});var qe=c(z);Fe=l(qe,"Pass your "),oe=i(qe,"CODE",{});var pt=c(oe);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 "),Ue=i(Ke,"A",{href:!0});var Oe=c(Ue);$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);Je=l(mt,"Then bundle your callbacks together:"),mt.forEach(s),D=b(r),k(ve.$$.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/main/en/model_doc/auto#transformers.TFAutoModelForSeq2SeqLM"),d(V,"href","/docs/transformers/main/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/main/en/main_classes/keras_callbacks#transformers.KerasMetricCallback"),d(Ue,"href","/docs/transformers/main/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){U(o,r,Z),f(r,m,Z),U(n,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),U(R,r,Z),f(r,A,Z),f(r,S,Z),t(S,I),t(S,W),t(W,ne),t(S,K),t(S,V),t(V,se),t(S,Y),f(r,H,Z),U(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),U(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,oe),t(oe,Be),t(z,Ie),t(z,pe),t(pe,ie),t(z,me),f(r,te,Z),U(le,r,Z),f(r,ce,Z),f(r,we,Z),t(we,_e),t(we,Ue),t(Ue,$e),t(we,re),f(r,g,Z),U(X,r,Z),f(r,Me,Z),f(r,Ve,Z),t(Ve,Je),f(r,D,Z),U(ve,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),U(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}),o.$set(De)},i(r){Xe||(J(o.$$.fragment,r),J(n.$$.fragment,r),J(R.$$.fragment,r),J(N.$$.fragment,r),J(ee.$$.fragment,r),J(le.$$.fragment,r),J(X.$$.fragment,r),J(ve.$$.fragment,r),J(fe.$$.fragment,r),Xe=!0)},o(r){v(o.$$.fragment,r),v(n.$$.fragment,r),v(R.$$.fragment,r),v(N.$$.fragment,r),v(ee.$$.fragment,r),v(le.$$.fragment,r),v(X.$$.fragment,r),v(ve.$$.fragment,r),v(fe.$$.fragment,r),Xe=!1},d(r){E(o,r),r&&s(m),E(n,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(ve,r),r&&s(je),r&&s(he),r&&s(Ze),E(fe,r),r&&s(Ae),r&&s(Ge)}}}function pr(q){let o,m;return o=new ss({props:{$$slots:{default:[or]},$$scope:{ctx:q}}}),{c(){T(o.$$.fragment)},l(n){k(o.$$.fragment,n)},m(n,M){U(o,n,M),m=!0},p(n,M){const w={};M&2&&(w.$$scope={dirty:M,ctx:n}),o.$set(w)},i(n){m||(J(o.$$.fragment,n),m=!0)},o(n){v(o.$$.fragment,n),m=!1},d(n){E(o,n)}}}function ir(q){let o,m,n,M,w,j,B,F;return{c(){o=p("p"),m=a(`For a more in-depth example of how to finetune a model for translation, take a look at the corresponding
`),n=p("a"),M=a("PyTorch notebook"),w=a(`
or `),j=p("a"),B=a("TensorFlow notebook"),F=a("."),this.h()},l(_){o=i(_,"P",{});var G=c(o);m=l(G,`For a more in-depth example of how to finetune a model for translation, take a look at the corresponding
`),n=i(G,"A",{href:!0,rel:!0});var R=c(n);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(n,"href","https://colab.research.google.com/github/huggingface/notebooks/blob/main/examples/translation.ipynb"),d(n,"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(_,o,G),t(o,m),t(o,n),t(n,M),t(o,w),t(o,j),t(j,B),t(o,F)},d(_){_&&s(o)}}}function cr(q){let o,m,n,M,w,j,B,F,_,G,R,A,S,I,W,ne,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(){o=p("p"),m=a("Tokenize the text and return the "),n=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"),ne=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){o=i(u,"P",{});var $=c(o);m=l($,"Tokenize the text and return the "),n=i($,"CODE",{});var L=c(n);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),ne=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/main/en/main_classes/text_generation#transformers.GenerationMixin.generate"),d(I,"href","../main_classes/text_generation")},m(u,$){f(u,o,$),t(o,m),t(o,n),t(n,M),t(o,w),f(u,j,$),U(B,u,$),f(u,F,$),f(u,_,$),t(_,G),t(_,R),t(R,A),t(_,S),t(_,I),t(I,W),t(_,ne),f(u,K,$),U(V,u,$),f(u,se,$),f(u,Y,$),t(Y,H),f(u,N,$),U(x,u,$),C=!0},p:aa,i(u){C||(J(B.$$.fragment,u),J(V.$$.fragment,u),J(x.$$.fragment,u),C=!0)},o(u){v(B.$$.fragment,u),v(V.$$.fragment,u),v(x.$$.fragment,u),C=!1},d(u){u&&s(o),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 o,m;return o=new ss({props:{$$slots:{default:[cr]},$$scope:{ctx:q}}}),{c(){T(o.$$.fragment)},l(n){k(o.$$.fragment,n)},m(n,M){U(o,n,M),m=!0},p(n,M){const w={};M&2&&(w.$$scope={dirty:M,ctx:n}),o.$set(w)},i(n){m||(J(o.$$.fragment,n),m=!0)},o(n){v(o.$$.fragment,n),m=!1},d(n){E(o,n)}}}function mr(q){let o,m,n,M,w,j,B,F,_,G,R,A,S,I,W,ne,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(){o=p("p"),m=a("Tokenize the text and return the "),n=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"),ne=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){o=i(u,"P",{});var $=c(o);m=l($,"Tokenize the text and return the "),n=i($,"CODE",{});var L=c(n);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),ne=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/main/en/main_classes/text_generation#transformers.TFGenerationMixin.generate"),d(I,"href","../main_classes/text_generation")},m(u,$){f(u,o,$),t(o,m),t(o,n),t(n,M),t(o,w),f(u,j,$),U(B,u,$),f(u,F,$),f(u,_,$),t(_,G),t(_,R),t(R,A),t(_,S),t(_,I),t(I,W),t(_,ne),f(u,K,$),U(V,u,$),f(u,se,$),f(u,Y,$),t(Y,H),f(u,N,$),U(x,u,$),C=!0},p:aa,i(u){C||(J(B.$$.fragment,u),J(V.$$.fragment,u),J(x.$$.fragment,u),C=!0)},o(u){v(B.$$.fragment,u),v(V.$$.fragment,u),v(x.$$.fragment,u),C=!1},d(u){u&&s(o),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 o,m;return o=new ss({props:{$$slots:{default:[mr]},$$scope:{ctx:q}}}),{c(){T(o.$$.fragment)},l(n){k(o.$$.fragment,n)},m(n,M){U(o,n,M),m=!0},p(n,M){const w={};M&2&&(w.$$scope={dirty:M,ctx:n}),o.$set(w)},i(n){m||(J(o.$$.fragment,n),m=!0)},o(n){v(o.$$.fragment,n),m=!1},d(n){E(o,n)}}}function ur(q){let o,m,n,M,w,j,B,F,_,G,R,A,S,I,W,ne,K,V,se,Y,H,N,x,C,u,$,L,O,de,Q,ee,ke,ae,ge,ye,be,Se,We,z,Fe,oe,Be,Ie,pe,ie,me,te,le,ce,we,_e,Ue,$e,re,g,X,Me,Ve,Je,D,ve,je,he,Re,ue,Ee,Ne,Te,Ze,fe,Ae,Ge,xe,Xe,r,Z,De,Ye,ot,ze,Ce,lt,He,rt,nt,qe,pt,Qe,Ke,Oe,mt,et,Pe,it,tt,Ht,Et,Le,yt,la,ra,as,na,oa,Zt,pa,ls,ia,ca,_s,Bt,$s,st,fa,Rt,ma,ha,rs,ua,da,ns,ya,ba,js,Gt,Ts,ct,Ma,qt,ga,wa,os,_a,$a,ks,bt,Us,ht,Mt,ps,Xt,ja,is,Ta,Js,at,ka,Wt,Ua,Ja,Vt,va,Ea,Ft,Za,Ba,vs,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,Ut,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>}]`}}),Ut=new Oa({props:{pytorch:!0,tensorflow:!0,jax:!1,$$slots:{tensorflow:[hr],pytorch:[fr]},$$scope:{ctx:q}}}),{c(){o=p("meta"),m=y(),n=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"),ne=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(),oe=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"),Ue=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:"),Je=y(),T(D.$$.fragment),ve=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."),ot=y(),ze=p("h2"),Ce=p("a"),lt=p("span"),T(He.$$.fragment),rt=y(),nt=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"),na=a("Tokenize the input (English) and target (French) separately because you can\u2019t tokenize French text with a tokenizer pretrained on an English vocabulary."),oa=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 "),ns=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 "),os=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),Us=y(),ht=p("h2"),Mt=p("a"),ps=p("span"),T(Xt.$$.fragment),ja=y(),is=p("span"),Ta=a("Evaluate"),Js=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"),Ua=a("Evaluate"),Ja=a(" library. For this task, load the "),Vt=p("a"),va=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):"),vs=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(Ut.$$.fragment),this.h()},l(e){const h=Pl('[data-svelte="svelte-1phssyn"]',document.head);o=i(h,"META",{name:!0,content:!0}),h.forEach(s),m=b(e),n=i(e,"H1",{class:!0});var Yt=c(n);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);ne=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),oe=i(e,"P",{});var rl=c(oe);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 nl=c(te);le=i(nl,"SPAN",{});var ol=c(le);k(ce.$$.fragment,ol),ol.forEach(s),nl.forEach(s),we=b(Ys),_e=i(Ys,"SPAN",{});var pl=c(_e);Ue=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),Je=b(e),k(D.$$.fragment,e),ve=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),ot=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),nt=i(Qs,"SPAN",{});var dl=c(nt);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);na=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),oa=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 Jt=c(st);fa=l(Jt,"To apply the preprocessing function over the entire dataset, use \u{1F917} Datasets "),Rt=i(Jt,"A",{href:!0,rel:!0});var _l=c(Rt);ma=l(_l,"map"),_l.forEach(s),ha=l(Jt," method. You can speed up the "),rs=i(Jt,"CODE",{});var $l=c(rs);ua=l($l,"map"),$l.forEach(s),da=l(Jt," function by setting "),ns=i(Jt,"CODE",{});var jl=c(ns);ya=l(jl,"batched=True"),jl.forEach(s),ba=l(Jt," to process multiple elements of the dataset at once:"),Jt.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 "),os=i(Ot,"EM",{});var kl=c(os);_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),Us=b(e),ht=i(e,"H2",{class:!0});var Ls=c(ht);Mt=i(Ls,"A",{id:!0,class:!0,href:!0});var Ul=c(Mt);ps=i(Ul,"SPAN",{});var Jl=c(ps);k(Xt.$$.fragment,Jl),Jl.forEach(s),Ul.forEach(s),ja=b(Ls),is=i(Ls,"SPAN",{});var vl=c(is);Ta=l(vl,"Evaluate"),vl.forEach(s),Ls.forEach(s),Js=b(e),at=i(e,"P",{});var vt=c(at);ka=l(vt,"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(vt,"A",{href:!0,rel:!0});var El=c(Wt);Ua=l(El,"Evaluate"),El.forEach(s),Ja=l(vt," library. For this task, load the "),Vt=i(vt,"A",{href:!0,rel:!0});var Zl=c(Vt);va=l(Zl,"SacreBLEU"),Zl.forEach(s),Ea=l(vt," metric (see the \u{1F917} Evaluate "),Ft=i(vt,"A",{href:!0,rel:!0});var Bl=c(Ft);Za=l(Bl,"quick tour"),Bl.forEach(s),Ba=l(vt," to learn more about how to load and compute a metric):"),vt.forEach(s),vs=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(Ut.$$.fragment,e),this.h()},h(){d(o,"name","hf:doc:metadata"),d(o,"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(n,"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/main/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/main/en/package_reference/main_classes#datasets.Dataset.map"),d(Rt,"rel","nofollow"),d(qt,"href","/docs/transformers/main/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/main/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/main/en/main_classes/pipelines#transformers.pipeline")},m(e,h){t(document.head,o),f(e,m,h),f(e,n,h),t(n,M),t(M,w),U(j,w,null),t(n,B),t(n,F),t(F,_),f(e,G,h),U(R,e,h),f(e,A,h),U(S,e,h),f(e,I,h),f(e,W,h),t(W,ne),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),U(ge,e,h),f(e,ye,h),f(e,be,h),t(be,Se),f(e,We,h),U(z,e,h),f(e,Fe,h),f(e,oe,h),t(oe,Be),f(e,Ie,h),U(pe,e,h),f(e,ie,h),f(e,me,h),t(me,te),t(te,le),U(ce,le,null),t(me,we),t(me,_e),t(_e,Ue),f(e,$e,h),f(e,re,h),t(re,g),t(re,X),t(X,Me),t(re,Ve),f(e,Je,h),U(D,e,h),f(e,ve,h),f(e,je,h),t(je,he),t(je,Re),t(Re,ue),t(je,Ee),f(e,Ne,h),U(Te,e,h),f(e,Ze,h),f(e,fe,h),t(fe,Ae),f(e,Ge,h),U(xe,e,h),f(e,Xe,h),f(e,r,h),t(r,Z),t(Z,De),t(r,Ye),f(e,ot,h),f(e,ze,h),t(ze,Ce),t(Ce,lt),U(He,lt,null),t(ze,rt),t(ze,nt),t(nt,qe),f(e,pt,h),U(Qe,e,h),f(e,Ke,h),f(e,Oe,h),t(Oe,mt),f(e,et,h),U(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,na),t(Le,oa),t(Le,Zt),t(Zt,pa),t(Zt,ls),t(ls,ia),t(Zt,ca),f(e,_s,h),U(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,ns),t(ns,ya),t(st,ba),f(e,js,h),U(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,os),t(os,_a),t(ct,$a),f(e,ks,h),U(bt,e,h),f(e,Us,h),f(e,ht,h),t(ht,Mt),t(Mt,ps),U(Xt,ps,null),t(ht,ja),t(ht,is),t(is,Ta),f(e,Js,h),f(e,at,h),t(at,ka),t(at,Wt),t(Wt,Ua),t(at,Ja),t(at,Vt),t(Vt,va),t(at,Ea),t(at,Ft),t(Ft,Za),t(at,Ba),f(e,vs,h),U(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),U(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),U(Nt,fs,null),t(ut,Ia),t(ut,ms),t(ms,Ca),f(e,Gs,h),U($t,e,h),f(e,Xs,h),U(jt,e,h),f(e,Ws,h),f(e,dt,h),t(dt,Tt),t(Tt,hs),U(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),U(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),U(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),U(Ut,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}),Ut.$set(ws)},i(e){xs||(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(Ut.$$.fragment,e),xs=!0)},o(e){v(j.$$.fragment,e),v(R.$$.fragment,e),v(S.$$.fragment,e),v(ge.$$.fragment,e),v(z.$$.fragment,e),v(pe.$$.fragment,e),v(ce.$$.fragment,e),v(D.$$.fragment,e),v(Te.$$.fragment,e),v(xe.$$.fragment,e),v(He.$$.fragment,e),v(Qe.$$.fragment,e),v(Pe.$$.fragment,e),v(Bt.$$.fragment,e),v(Gt.$$.fragment,e),v(bt.$$.fragment,e),v(Xt.$$.fragment,e),v(It.$$.fragment,e),v(St.$$.fragment,e),v(Nt.$$.fragment,e),v($t.$$.fragment,e),v(jt.$$.fragment,e),v(At.$$.fragment,e),v(xt.$$.fragment,e),v(zt.$$.fragment,e),v(Ut.$$.fragment,e),xs=!1},d(e){s(o),e&&s(m),e&&s(n),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(oe),e&&s(Ie),E(pe,e),e&&s(ie),e&&s(me),E(ce),e&&s($e),e&&s(re),e&&s(Je),E(D,e),e&&s(ve),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(ot),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(Us),e&&s(ht),E(Xt),e&&s(Js),e&&s(at),e&&s(vs),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(Ut,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(o){super();ql(this,o,yr,ur,Ql,{})}}export{Tr as default,dr as metadata};
