import{S as ko,i as To,s as Uo,e as r,k as d,w as v,t as s,M as Eo,c as n,d as a,m as y,a as i,x as k,h as l,b,G as t,g as h,y as T,q as U,o as E,B as J,v as Jo,L as ws}from"../../chunks/vendor-hf-doc-builder.js";import{T as gs}from"../../chunks/Tip-hf-doc-builder.js";import{Y as Zo}from"../../chunks/Youtube-hf-doc-builder.js";import{I as na}from"../../chunks/IconCopyLink-hf-doc-builder.js";import{C as Q}from"../../chunks/CodeBlock-hf-doc-builder.js";import{D as Go}from"../../chunks/DocNotebookDropdown-hf-doc-builder.js";import{F as Tl,M as ia}from"../../chunks/Markdown-hf-doc-builder.js";function Co(N){let p,m,c,M,w,j,G,S,$,V,C,X,x,A,W,ie,P,R,O,q,K,Y,z,I,u,_,ee,F,te,H,D,ke,ce,Te,ge,Ge,Xe,Ce,L,Se,se,Ue,Ve,Ee,pe,we,fe,le,Je,de,ue,$e,oe,re,g,B,ye,Ze,Be,ae,be,ze,he,Re,me,ne,Ie,_e,We,je,Ae,Me,De;return{c(){p=s(`The task illustrated in this tutorial is supported by the following model architectures:

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

`),m=n(ve,"P",{});var o=i(m);c=n(o,"A",{href:!0});var Z=i(c);M=l(Z,"BART"),Z.forEach(a),w=l(o,", "),j=n(o,"A",{href:!0});var xe=i(j);G=l(xe,"BigBird-Pegasus"),xe.forEach(a),S=l(o,", "),$=n(o,"A",{href:!0});var Fe=i($);V=l(Fe,"Blenderbot"),Fe.forEach(a),C=l(o,", "),X=n(o,"A",{href:!0});var Le=i(X);x=l(Le,"BlenderbotSmall"),Le.forEach(a),A=l(o,", "),W=n(o,"A",{href:!0});var pt=i(W);ie=l(pt,"Encoder decoder"),pt.forEach(a),P=l(o,", "),R=n(o,"A",{href:!0});var Oe=i(R);O=l(Oe,"FairSeq Machine-Translation"),Oe.forEach(a),q=l(o,", "),K=n(o,"A",{href:!0});var Ne=i(K);Y=l(Ne,"GPTSAN-japanese"),Ne.forEach(a),z=l(o,", "),I=n(o,"A",{href:!0});var Ke=i(I);u=l(Ke,"LED"),Ke.forEach(a),_=l(o,", "),ee=n(o,"A",{href:!0});var Ye=i(ee);F=l(Ye,"LongT5"),Ye.forEach(a),te=l(o,", "),H=n(o,"A",{href:!0});var ht=i(H);D=l(ht,"M2M100"),ht.forEach(a),ke=l(o,", "),ce=n(o,"A",{href:!0});var He=i(ce);Te=l(He,"Marian"),He.forEach(a),ge=l(o,", "),Ge=n(o,"A",{href:!0});var mt=i(Ge);Xe=l(mt,"mBART"),mt.forEach(a),Ce=l(o,", "),L=n(o,"A",{href:!0});var qe=i(L);Se=l(qe,"MT5"),qe.forEach(a),se=l(o,", "),Ue=n(o,"A",{href:!0});var Qe=i(Ue);Ve=l(Qe,"MVP"),Qe.forEach(a),Ee=l(o,", "),pe=n(o,"A",{href:!0});var ft=i(pe);we=l(ft,"NLLB"),ft.forEach(a),fe=l(o,", "),le=n(o,"A",{href:!0});var ut=i(le);Je=l(ut,"NLLB-MOE"),ut.forEach(a),de=l(o,", "),ue=n(o,"A",{href:!0});var Pe=i(ue);$e=l(Pe,"Pegasus"),Pe.forEach(a),oe=l(o,", "),re=n(o,"A",{href:!0});var dt=i(re);g=l(dt,"PEGASUS-X"),dt.forEach(a),B=l(o,", "),ye=n(o,"A",{href:!0});var yt=i(ye);Ze=l(yt,"PLBart"),yt.forEach(a),Be=l(o,", "),ae=n(o,"A",{href:!0});var lt=i(ae);be=l(lt,"ProphetNet"),lt.forEach(a),ze=l(o,", "),he=n(o,"A",{href:!0});var et=i(he);Re=l(et,"SwitchTransformers"),et.forEach(a),me=l(o,", "),ne=n(o,"A",{href:!0});var st=i(ne);Ie=l(st,"T5"),st.forEach(a),_e=l(o,", "),We=n(o,"A",{href:!0});var wt=i(We);je=l(wt,"UMT5"),wt.forEach(a),Ae=l(o,", "),Me=n(o,"A",{href:!0});var ot=i(Me);De=l(ot,"XLM-ProphetNet"),ot.forEach(a),o.forEach(a),this.h()},h(){b(c,"href","../model_doc/bart"),b(j,"href","../model_doc/bigbird_pegasus"),b($,"href","../model_doc/blenderbot"),b(X,"href","../model_doc/blenderbot-small"),b(W,"href","../model_doc/encoder-decoder"),b(R,"href","../model_doc/fsmt"),b(K,"href","../model_doc/gptsan-japanese"),b(I,"href","../model_doc/led"),b(ee,"href","../model_doc/longt5"),b(H,"href","../model_doc/m2m_100"),b(ce,"href","../model_doc/marian"),b(Ge,"href","../model_doc/mbart"),b(L,"href","../model_doc/mt5"),b(Ue,"href","../model_doc/mvp"),b(pe,"href","../model_doc/nllb"),b(le,"href","../model_doc/nllb-moe"),b(ue,"href","../model_doc/pegasus"),b(re,"href","../model_doc/pegasus_x"),b(ye,"href","../model_doc/plbart"),b(ae,"href","../model_doc/prophetnet"),b(he,"href","../model_doc/switch_transformers"),b(ne,"href","../model_doc/t5"),b(We,"href","../model_doc/umt5"),b(Me,"href","../model_doc/xlm-prophetnet")},m(ve,o){h(ve,p,o),h(ve,m,o),t(m,c),t(c,M),t(m,w),t(m,j),t(j,G),t(m,S),t(m,$),t($,V),t(m,C),t(m,X),t(X,x),t(m,A),t(m,W),t(W,ie),t(m,P),t(m,R),t(R,O),t(m,q),t(m,K),t(K,Y),t(m,z),t(m,I),t(I,u),t(m,_),t(m,ee),t(ee,F),t(m,te),t(m,H),t(H,D),t(m,ke),t(m,ce),t(ce,Te),t(m,ge),t(m,Ge),t(Ge,Xe),t(m,Ce),t(m,L),t(L,Se),t(m,se),t(m,Ue),t(Ue,Ve),t(m,Ee),t(m,pe),t(pe,we),t(m,fe),t(m,le),t(le,Je),t(m,de),t(m,ue),t(ue,$e),t(m,oe),t(m,re),t(re,g),t(m,B),t(m,ye),t(ye,Ze),t(m,Be),t(m,ae),t(ae,be),t(m,ze),t(m,he),t(he,Re),t(m,me),t(m,ne),t(ne,Ie),t(m,_e),t(m,We),t(We,je),t(m,Ae),t(m,Me),t(Me,De)},d(ve){ve&&a(p),ve&&a(m)}}}function Vo(N){let p,m;return p=new Q({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(){v(p.$$.fragment)},l(c){k(p.$$.fragment,c)},m(c,M){T(p,c,M),m=!0},p:ws,i(c){m||(U(p.$$.fragment,c),m=!0)},o(c){E(p.$$.fragment,c),m=!1},d(c){J(p,c)}}}function Bo(N){let p,m;return p=new ia({props:{$$slots:{default:[Vo]},$$scope:{ctx:N}}}),{c(){v(p.$$.fragment)},l(c){k(p.$$.fragment,c)},m(c,M){T(p,c,M),m=!0},p(c,M){const w={};M&2&&(w.$$scope={dirty:M,ctx:c}),p.$set(w)},i(c){m||(U(p.$$.fragment,c),m=!0)},o(c){E(p.$$.fragment,c),m=!1},d(c){J(p,c)}}}function Ro(N){let p,m;return p=new Q({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(){v(p.$$.fragment)},l(c){k(p.$$.fragment,c)},m(c,M){T(p,c,M),m=!0},p:ws,i(c){m||(U(p.$$.fragment,c),m=!0)},o(c){E(p.$$.fragment,c),m=!1},d(c){J(p,c)}}}function Wo(N){let p,m;return p=new ia({props:{$$slots:{default:[Ro]},$$scope:{ctx:N}}}),{c(){v(p.$$.fragment)},l(c){k(p.$$.fragment,c)},m(c,M){T(p,c,M),m=!0},p(c,M){const w={};M&2&&(w.$$scope={dirty:M,ctx:c}),p.$set(w)},i(c){m||(U(p.$$.fragment,c),m=!0)},o(c){E(p.$$.fragment,c),m=!1},d(c){J(p,c)}}}function So(N){let p,m,c,M,w,j,G,S;return{c(){p=r("p"),m=s("If you aren\u2019t familiar with finetuning a model with the "),c=r("a"),M=s("Trainer"),w=s(", take a look at the basic tutorial "),j=r("a"),G=s("here"),S=s("!"),this.h()},l($){p=n($,"P",{});var V=i(p);m=l(V,"If you aren\u2019t familiar with finetuning a model with the "),c=n(V,"A",{href:!0});var C=i(c);M=l(C,"Trainer"),C.forEach(a),w=l(V,", take a look at the basic tutorial "),j=n(V,"A",{href:!0});var X=i(j);G=l(X,"here"),X.forEach(a),S=l(V,"!"),V.forEach(a),this.h()},h(){b(c,"href","/docs/transformers/v4.33.0/en/main_classes/trainer#transformers.Trainer"),b(j,"href","../training#train-with-pytorch-trainer")},m($,V){h($,p,V),t(p,m),t(p,c),t(c,M),t(p,w),t(p,j),t(j,G),t(p,S)},d($){$&&a(p)}}}function Ao(N){let p,m,c,M,w,j,G,S,$,V,C,X,x,A,W,ie,P,R,O,q,K,Y,z,I,u,_,ee,F,te,H,D,ke,ce,Te,ge,Ge,Xe,Ce,L,Se,se,Ue,Ve,Ee,pe,we,fe,le,Je,de,ue,$e,oe,re;return p=new gs({props:{$$slots:{default:[So]},$$scope:{ctx:N}}}),$=new Q({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)`}}),pe=new Q({props:{code:"dHJhaW5pbmdfYXJncyUyMCUzRCUyMFNlcTJTZXFUcmFpbmluZ0FyZ3VtZW50cyglMEElMjAlMjAlMjAlMjBvdXRwdXRfZGlyJTNEJTIybXlfYXdlc29tZV9iaWxsc3VtX21vZGVsJTIyJTJDJTBBJTIwJTIwJTIwJTIwZXZhbHVhdGlvbl9zdHJhdGVneSUzRCUyMmVwb2NoJTIyJTJDJTBBJTIwJTIwJTIwJTIwbGVhcm5pbmdfcmF0ZSUzRDJlLTUlMkMlMEElMjAlMjAlMjAlMjBwZXJfZGV2aWNlX3RyYWluX2JhdGNoX3NpemUlM0QxNiUyQyUwQSUyMCUyMCUyMCUyMHBlcl9kZXZpY2VfZXZhbF9iYXRjaF9zaXplJTNEMTYlMkMlMEElMjAlMjAlMjAlMjB3ZWlnaHRfZGVjYXklM0QwLjAxJTJDJTBBJTIwJTIwJTIwJTIwc2F2ZV90b3RhbF9saW1pdCUzRDMlMkMlMEElMjAlMjAlMjAlMjBudW1fdHJhaW5fZXBvY2hzJTNENCUyQyUwQSUyMCUyMCUyMCUyMHByZWRpY3Rfd2l0aF9nZW5lcmF0ZSUzRFRydWUlMkMlMEElMjAlMjAlMjAlMjBmcDE2JTNEVHJ1ZSUyQyUwQSUyMCUyMCUyMCUyMHB1c2hfdG9faHViJTNEVHJ1ZSUyQyUwQSklMEElMEF0cmFpbmVyJTIwJTNEJTIwU2VxMlNlcVRyYWluZXIoJTBBJTIwJTIwJTIwJTIwbW9kZWwlM0Rtb2RlbCUyQyUwQSUyMCUyMCUyMCUyMGFyZ3MlM0R0cmFpbmluZ19hcmdzJTJDJTBBJTIwJTIwJTIwJTIwdHJhaW5fZGF0YXNldCUzRHRva2VuaXplZF9iaWxsc3VtJTVCJTIydHJhaW4lMjIlNUQlMkMlMEElMjAlMjAlMjAlMjBldmFsX2RhdGFzZXQlM0R0b2tlbml6ZWRfYmlsbHN1bSU1QiUyMnRlc3QlMjIlNUQlMkMlMEElMjAlMjAlMjAlMjB0b2tlbml6ZXIlM0R0b2tlbml6ZXIlMkMlMEElMjAlMjAlMjAlMjBkYXRhX2NvbGxhdG9yJTNEZGF0YV9jb2xsYXRvciUyQyUwQSUyMCUyMCUyMCUyMGNvbXB1dGVfbWV0cmljcyUzRGNvbXB1dGVfbWV0cmljcyUyQyUwQSklMEElMEF0cmFpbmVyLnRyYWluKCk=",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_billsum_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">4</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_billsum[<span class="hljs-string">&quot;train&quot;</span>],
<span class="hljs-meta">... </span>    eval_dataset=tokenized_billsum[<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()`}}),oe=new Q({props:{code:"dHJhaW5lci5wdXNoX3RvX2h1Yigp",highlighted:'<span class="hljs-meta">&gt;&gt;&gt; </span>trainer.push_to_hub()'}}),{c(){v(p.$$.fragment),m=d(),c=r("p"),M=s("You\u2019re ready to start training your model now! Load T5 with "),w=r("a"),j=s("AutoModelForSeq2SeqLM"),G=s(":"),S=d(),v($.$$.fragment),V=d(),C=r("p"),X=s("At this point, only three steps remain:"),x=d(),A=r("ol"),W=r("li"),ie=s("Define your training hyperparameters in "),P=r("a"),R=s("Seq2SeqTrainingArguments"),O=s(". The only required parameter is "),q=r("code"),K=s("output_dir"),Y=s(" which specifies where to save your model. You\u2019ll push this model to the Hub by setting "),z=r("code"),I=s("push_to_hub=True"),u=s(" (you need to be signed in to Hugging Face to upload your model). At the end of each epoch, the "),_=r("a"),ee=s("Trainer"),F=s(" will evaluate the ROUGE metric and save the training checkpoint."),te=d(),H=r("li"),D=s("Pass the training arguments to "),ke=r("a"),ce=s("Seq2SeqTrainer"),Te=s(" along with the model, dataset, tokenizer, data collator, and "),ge=r("code"),Ge=s("compute_metrics"),Xe=s(" function."),Ce=d(),L=r("li"),Se=s("Call "),se=r("a"),Ue=s("train()"),Ve=s(" to finetune your model."),Ee=d(),v(pe.$$.fragment),we=d(),fe=r("p"),le=s("Once training is completed, share your model to the Hub with the "),Je=r("a"),de=s("push_to_hub()"),ue=s(" method so everyone can use your model:"),$e=d(),v(oe.$$.fragment),this.h()},l(g){k(p.$$.fragment,g),m=y(g),c=n(g,"P",{});var B=i(c);M=l(B,"You\u2019re ready to start training your model now! Load T5 with "),w=n(B,"A",{href:!0});var ye=i(w);j=l(ye,"AutoModelForSeq2SeqLM"),ye.forEach(a),G=l(B,":"),B.forEach(a),S=y(g),k($.$$.fragment,g),V=y(g),C=n(g,"P",{});var Ze=i(C);X=l(Ze,"At this point, only three steps remain:"),Ze.forEach(a),x=y(g),A=n(g,"OL",{});var Be=i(A);W=n(Be,"LI",{});var ae=i(W);ie=l(ae,"Define your training hyperparameters in "),P=n(ae,"A",{href:!0});var be=i(P);R=l(be,"Seq2SeqTrainingArguments"),be.forEach(a),O=l(ae,". The only required parameter is "),q=n(ae,"CODE",{});var ze=i(q);K=l(ze,"output_dir"),ze.forEach(a),Y=l(ae," which specifies where to save your model. You\u2019ll push this model to the Hub by setting "),z=n(ae,"CODE",{});var he=i(z);I=l(he,"push_to_hub=True"),he.forEach(a),u=l(ae," (you need to be signed in to Hugging Face to upload your model). At the end of each epoch, the "),_=n(ae,"A",{href:!0});var Re=i(_);ee=l(Re,"Trainer"),Re.forEach(a),F=l(ae," will evaluate the ROUGE metric and save the training checkpoint."),ae.forEach(a),te=y(Be),H=n(Be,"LI",{});var me=i(H);D=l(me,"Pass the training arguments to "),ke=n(me,"A",{href:!0});var ne=i(ke);ce=l(ne,"Seq2SeqTrainer"),ne.forEach(a),Te=l(me," along with the model, dataset, tokenizer, data collator, and "),ge=n(me,"CODE",{});var Ie=i(ge);Ge=l(Ie,"compute_metrics"),Ie.forEach(a),Xe=l(me," function."),me.forEach(a),Ce=y(Be),L=n(Be,"LI",{});var _e=i(L);Se=l(_e,"Call "),se=n(_e,"A",{href:!0});var We=i(se);Ue=l(We,"train()"),We.forEach(a),Ve=l(_e," to finetune your model."),_e.forEach(a),Be.forEach(a),Ee=y(g),k(pe.$$.fragment,g),we=y(g),fe=n(g,"P",{});var je=i(fe);le=l(je,"Once training is completed, share your model to the Hub with the "),Je=n(je,"A",{href:!0});var Ae=i(Je);de=l(Ae,"push_to_hub()"),Ae.forEach(a),ue=l(je," method so everyone can use your model:"),je.forEach(a),$e=y(g),k(oe.$$.fragment,g),this.h()},h(){b(w,"href","/docs/transformers/v4.33.0/en/model_doc/auto#transformers.AutoModelForSeq2SeqLM"),b(P,"href","/docs/transformers/v4.33.0/en/main_classes/trainer#transformers.Seq2SeqTrainingArguments"),b(_,"href","/docs/transformers/v4.33.0/en/main_classes/trainer#transformers.Trainer"),b(ke,"href","/docs/transformers/v4.33.0/en/main_classes/trainer#transformers.Seq2SeqTrainer"),b(se,"href","/docs/transformers/v4.33.0/en/main_classes/trainer#transformers.Trainer.train"),b(Je,"href","/docs/transformers/v4.33.0/en/main_classes/trainer#transformers.Trainer.push_to_hub")},m(g,B){T(p,g,B),h(g,m,B),h(g,c,B),t(c,M),t(c,w),t(w,j),t(c,G),h(g,S,B),T($,g,B),h(g,V,B),h(g,C,B),t(C,X),h(g,x,B),h(g,A,B),t(A,W),t(W,ie),t(W,P),t(P,R),t(W,O),t(W,q),t(q,K),t(W,Y),t(W,z),t(z,I),t(W,u),t(W,_),t(_,ee),t(W,F),t(A,te),t(A,H),t(H,D),t(H,ke),t(ke,ce),t(H,Te),t(H,ge),t(ge,Ge),t(H,Xe),t(A,Ce),t(A,L),t(L,Se),t(L,se),t(se,Ue),t(L,Ve),h(g,Ee,B),T(pe,g,B),h(g,we,B),h(g,fe,B),t(fe,le),t(fe,Je),t(Je,de),t(fe,ue),h(g,$e,B),T(oe,g,B),re=!0},p(g,B){const ye={};B&2&&(ye.$$scope={dirty:B,ctx:g}),p.$set(ye)},i(g){re||(U(p.$$.fragment,g),U($.$$.fragment,g),U(pe.$$.fragment,g),U(oe.$$.fragment,g),re=!0)},o(g){E(p.$$.fragment,g),E($.$$.fragment,g),E(pe.$$.fragment,g),E(oe.$$.fragment,g),re=!1},d(g){J(p,g),g&&a(m),g&&a(c),g&&a(S),J($,g),g&&a(V),g&&a(C),g&&a(x),g&&a(A),g&&a(Ee),J(pe,g),g&&a(we),g&&a(fe),g&&a($e),J(oe,g)}}}function xo(N){let p,m;return p=new ia({props:{$$slots:{default:[Ao]},$$scope:{ctx:N}}}),{c(){v(p.$$.fragment)},l(c){k(p.$$.fragment,c)},m(c,M){T(p,c,M),m=!0},p(c,M){const w={};M&2&&(w.$$scope={dirty:M,ctx:c}),p.$set(w)},i(c){m||(U(p.$$.fragment,c),m=!0)},o(c){E(p.$$.fragment,c),m=!1},d(c){J(p,c)}}}function Xo(N){let p,m,c,M,w;return{c(){p=r("p"),m=s("If you aren\u2019t familiar with finetuning a model with Keras, take a look at the basic tutorial "),c=r("a"),M=s("here"),w=s("!"),this.h()},l(j){p=n(j,"P",{});var G=i(p);m=l(G,"If you aren\u2019t familiar with finetuning a model with Keras, take a look at the basic tutorial "),c=n(G,"A",{href:!0});var S=i(c);M=l(S,"here"),S.forEach(a),w=l(G,"!"),G.forEach(a),this.h()},h(){b(c,"href","../training#train-a-tensorflow-model-with-keras")},m(j,G){h(j,p,G),t(p,m),t(p,c),t(c,M),t(p,w)},d(j){j&&a(p)}}}function zo(N){let p,m,c,M,w,j,G,S,$,V,C,X,x,A,W,ie,P,R,O,q,K,Y,z,I,u,_,ee,F,te,H,D,ke,ce,Te,ge,Ge,Xe,Ce,L,Se,se,Ue,Ve,Ee,pe,we,fe,le,Je,de,ue,$e,oe,re,g,B,ye,Ze,Be,ae,be,ze,he,Re,me,ne,Ie,_e,We,je,Ae,Me,De,ve;return p=new gs({props:{$$slots:{default:[Xo]},$$scope:{ctx:N}}}),c=new Q({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMGNyZWF0ZV9vcHRpbWl6ZXIlMkMlMjBBZGFtV2VpZ2h0RGVjYXklMEElMEFvcHRpbWl6ZXIlMjAlM0QlMjBBZGFtV2VpZ2h0RGVjYXkobGVhcm5pbmdfcmF0ZSUzRDJlLTUlMkMlMjB3ZWlnaHRfZGVjYXlfcmF0ZSUzRDAuMDEp",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> create_optimizer, 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>)`}}),C=new Q({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)`}}),Y=new Q({props:{code:"dGZfdHJhaW5fc2V0JTIwJTNEJTIwbW9kZWwucHJlcGFyZV90Zl9kYXRhc2V0KCUwQSUyMCUyMCUyMCUyMHRva2VuaXplZF9iaWxsc3VtJTVCJTIydHJhaW4lMjIlNUQlMkMlMEElMjAlMjAlMjAlMjBzaHVmZmxlJTNEVHJ1ZSUyQyUwQSUyMCUyMCUyMCUyMGJhdGNoX3NpemUlM0QxNiUyQyUwQSUyMCUyMCUyMCUyMGNvbGxhdGVfZm4lM0RkYXRhX2NvbGxhdG9yJTJDJTBBKSUwQSUwQXRmX3Rlc3Rfc2V0JTIwJTNEJTIwbW9kZWwucHJlcGFyZV90Zl9kYXRhc2V0KCUwQSUyMCUyMCUyMCUyMHRva2VuaXplZF9iaWxsc3VtJTVCJTIydGVzdCUyMiU1RCUyQyUwQSUyMCUyMCUyMCUyMHNodWZmbGUlM0RGYWxzZSUyQyUwQSUyMCUyMCUyMCUyMGJhdGNoX3NpemUlM0QxNiUyQyUwQSUyMCUyMCUyMCUyMGNvbGxhdGVfZm4lM0RkYXRhX2NvbGxhdG9yJTJDJTBBKQ==",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span>tf_train_set = model.prepare_tf_dataset(
<span class="hljs-meta">... </span>    tokenized_billsum[<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_billsum[<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>)`}}),D=new Q({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 Q({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)`}}),B=new Q({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycy5rZXJhc19jYWxsYmFja3MlMjBpbXBvcnQlMjBQdXNoVG9IdWJDYWxsYmFjayUwQSUwQXB1c2hfdG9faHViX2NhbGxiYWNrJTIwJTNEJTIwUHVzaFRvSHViQ2FsbGJhY2soJTBBJTIwJTIwJTIwJTIwb3V0cHV0X2RpciUzRCUyMm15X2F3ZXNvbWVfYmlsbHN1bV9tb2RlbCUyMiUyQyUwQSUyMCUyMCUyMCUyMHRva2VuaXplciUzRHRva2VuaXplciUyQyUwQSk=",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_billsum_model&quot;</span>,
<span class="hljs-meta">... </span>    tokenizer=tokenizer,
<span class="hljs-meta">... </span>)`}}),be=new Q({props:{code:"Y2FsbGJhY2tzJTIwJTNEJTIwJTVCbWV0cmljX2NhbGxiYWNrJTJDJTIwcHVzaF90b19odWJfY2FsbGJhY2slNUQ=",highlighted:'<span class="hljs-meta">&gt;&gt;&gt; </span>callbacks = [metric_callback, push_to_hub_callback]'}}),je=new Q({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(){v(p.$$.fragment),m=s(`
To finetune a model in TensorFlow, start by setting up an optimizer function, learning rate schedule, and some training hyperparameters:

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

	`),k(c.$$.fragment,o),M=y(o),w=n(o,"P",{});var Z=i(w);j=l(Z,"Then you can load T5 with "),G=n(Z,"A",{href:!0});var xe=i(G);S=l(xe,"TFAutoModelForSeq2SeqLM"),xe.forEach(a),$=l(Z,":"),Z.forEach(a),V=y(o),k(C.$$.fragment,o),X=y(o),x=n(o,"P",{});var Fe=i(x);A=l(Fe,"Convert your datasets to the "),W=n(Fe,"CODE",{});var Le=i(W);ie=l(Le,"tf.data.Dataset"),Le.forEach(a),P=l(Fe," format with "),R=n(Fe,"A",{href:!0});var pt=i(R);O=l(pt,"prepare_tf_dataset()"),pt.forEach(a),q=l(Fe,":"),Fe.forEach(a),K=y(o),k(Y.$$.fragment,o),z=y(o),I=n(o,"P",{});var Oe=i(I);u=l(Oe,"Configure the model for training with "),_=n(Oe,"A",{href:!0,rel:!0});var Ne=i(_);ee=n(Ne,"CODE",{});var Ke=i(ee);F=l(Ke,"compile"),Ke.forEach(a),Ne.forEach(a),te=l(Oe,". Note that Transformers models all have a default task-relevant loss function, so you don\u2019t need to specify one unless you want to:"),Oe.forEach(a),H=y(o),k(D.$$.fragment,o),ke=y(o),ce=n(o,"P",{});var Ye=i(ce);Te=l(Ye,"The last two things to setup before you start training is to compute the ROUGE score from the predictions, and provide a way to push your model to the Hub. Both are done by using "),ge=n(Ye,"A",{href:!0});var ht=i(ge);Ge=l(ht,"Keras callbacks"),ht.forEach(a),Xe=l(Ye,"."),Ye.forEach(a),Ce=y(o),L=n(o,"P",{});var He=i(L);Se=l(He,"Pass your "),se=n(He,"CODE",{});var mt=i(se);Ue=l(mt,"compute_metrics"),mt.forEach(a),Ve=l(He," function to "),Ee=n(He,"A",{href:!0});var qe=i(Ee);pe=l(qe,"KerasMetricCallback"),qe.forEach(a),we=l(He,":"),He.forEach(a),fe=y(o),k(le.$$.fragment,o),Je=y(o),de=n(o,"P",{});var Qe=i(de);ue=l(Qe,"Specify where to push your model and tokenizer in the "),$e=n(Qe,"A",{href:!0});var ft=i($e);oe=l(ft,"PushToHubCallback"),ft.forEach(a),re=l(Qe,":"),Qe.forEach(a),g=y(o),k(B.$$.fragment,o),ye=y(o),Ze=n(o,"P",{});var ut=i(Ze);Be=l(ut,"Then bundle your callbacks together:"),ut.forEach(a),ae=y(o),k(be.$$.fragment,o),ze=y(o),he=n(o,"P",{});var Pe=i(he);Re=l(Pe,"Finally, you\u2019re ready to start training your model! Call "),me=n(Pe,"A",{href:!0,rel:!0});var dt=i(me);ne=n(dt,"CODE",{});var yt=i(ne);Ie=l(yt,"fit"),yt.forEach(a),dt.forEach(a),_e=l(Pe," with your training and validation datasets, the number of epochs, and your callbacks to finetune the model:"),Pe.forEach(a),We=y(o),k(je.$$.fragment,o),Ae=y(o),Me=n(o,"P",{});var lt=i(Me);De=l(lt,"Once training is completed, your model is automatically uploaded to the Hub so everyone can use it!"),lt.forEach(a),this.h()},h(){b(G,"href","/docs/transformers/v4.33.0/en/model_doc/auto#transformers.TFAutoModelForSeq2SeqLM"),b(R,"href","/docs/transformers/v4.33.0/en/main_classes/model#transformers.TFPreTrainedModel.prepare_tf_dataset"),b(_,"href","https://keras.io/api/models/model_training_apis/#compile-method"),b(_,"rel","nofollow"),b(ge,"href","../main_classes/keras_callbacks"),b(Ee,"href","/docs/transformers/v4.33.0/en/main_classes/keras_callbacks#transformers.KerasMetricCallback"),b($e,"href","/docs/transformers/v4.33.0/en/main_classes/keras_callbacks#transformers.PushToHubCallback"),b(me,"href","https://keras.io/api/models/model_training_apis/#fit-method"),b(me,"rel","nofollow")},m(o,Z){T(p,o,Z),h(o,m,Z),T(c,o,Z),h(o,M,Z),h(o,w,Z),t(w,j),t(w,G),t(G,S),t(w,$),h(o,V,Z),T(C,o,Z),h(o,X,Z),h(o,x,Z),t(x,A),t(x,W),t(W,ie),t(x,P),t(x,R),t(R,O),t(x,q),h(o,K,Z),T(Y,o,Z),h(o,z,Z),h(o,I,Z),t(I,u),t(I,_),t(_,ee),t(ee,F),t(I,te),h(o,H,Z),T(D,o,Z),h(o,ke,Z),h(o,ce,Z),t(ce,Te),t(ce,ge),t(ge,Ge),t(ce,Xe),h(o,Ce,Z),h(o,L,Z),t(L,Se),t(L,se),t(se,Ue),t(L,Ve),t(L,Ee),t(Ee,pe),t(L,we),h(o,fe,Z),T(le,o,Z),h(o,Je,Z),h(o,de,Z),t(de,ue),t(de,$e),t($e,oe),t(de,re),h(o,g,Z),T(B,o,Z),h(o,ye,Z),h(o,Ze,Z),t(Ze,Be),h(o,ae,Z),T(be,o,Z),h(o,ze,Z),h(o,he,Z),t(he,Re),t(he,me),t(me,ne),t(ne,Ie),t(he,_e),h(o,We,Z),T(je,o,Z),h(o,Ae,Z),h(o,Me,Z),t(Me,De),ve=!0},p(o,Z){const xe={};Z&2&&(xe.$$scope={dirty:Z,ctx:o}),p.$set(xe)},i(o){ve||(U(p.$$.fragment,o),U(c.$$.fragment,o),U(C.$$.fragment,o),U(Y.$$.fragment,o),U(D.$$.fragment,o),U(le.$$.fragment,o),U(B.$$.fragment,o),U(be.$$.fragment,o),U(je.$$.fragment,o),ve=!0)},o(o){E(p.$$.fragment,o),E(c.$$.fragment,o),E(C.$$.fragment,o),E(Y.$$.fragment,o),E(D.$$.fragment,o),E(le.$$.fragment,o),E(B.$$.fragment,o),E(be.$$.fragment,o),E(je.$$.fragment,o),ve=!1},d(o){J(p,o),o&&a(m),J(c,o),o&&a(M),o&&a(w),o&&a(V),J(C,o),o&&a(X),o&&a(x),o&&a(K),J(Y,o),o&&a(z),o&&a(I),o&&a(H),J(D,o),o&&a(ke),o&&a(ce),o&&a(Ce),o&&a(L),o&&a(fe),J(le,o),o&&a(Je),o&&a(de),o&&a(g),J(B,o),o&&a(ye),o&&a(Ze),o&&a(ae),J(be,o),o&&a(ze),o&&a(he),o&&a(We),J(je,o),o&&a(Ae),o&&a(Me)}}}function Io(N){let p,m;return p=new ia({props:{$$slots:{default:[zo]},$$scope:{ctx:N}}}),{c(){v(p.$$.fragment)},l(c){k(p.$$.fragment,c)},m(c,M){T(p,c,M),m=!0},p(c,M){const w={};M&2&&(w.$$scope={dirty:M,ctx:c}),p.$set(w)},i(c){m||(U(p.$$.fragment,c),m=!0)},o(c){E(p.$$.fragment,c),m=!1},d(c){J(p,c)}}}function Fo(N){let p,m,c,M,w,j,G,S;return{c(){p=r("p"),m=s(`For a more in-depth example of how to finetune a model for summarization, take a look at the corresponding
`),c=r("a"),M=s("PyTorch notebook"),w=s(`
or `),j=r("a"),G=s("TensorFlow notebook"),S=s("."),this.h()},l($){p=n($,"P",{});var V=i(p);m=l(V,`For a more in-depth example of how to finetune a model for summarization, take a look at the corresponding
`),c=n(V,"A",{href:!0,rel:!0});var C=i(c);M=l(C,"PyTorch notebook"),C.forEach(a),w=l(V,`
or `),j=n(V,"A",{href:!0,rel:!0});var X=i(j);G=l(X,"TensorFlow notebook"),X.forEach(a),S=l(V,"."),V.forEach(a),this.h()},h(){b(c,"href","https://colab.research.google.com/github/huggingface/notebooks/blob/main/examples/summarization.ipynb"),b(c,"rel","nofollow"),b(j,"href","https://colab.research.google.com/github/huggingface/notebooks/blob/main/examples/summarization-tf.ipynb"),b(j,"rel","nofollow")},m($,V){h($,p,V),t(p,m),t(p,c),t(c,M),t(p,w),t(p,j),t(j,G),t(p,S)},d($){$&&a(p)}}}function No(N){let p,m,c,M,w,j,G,S,$,V,C,X,x,A,W,ie,P,R,O,q,K,Y,z,I;return G=new Q({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9Ub2tlbml6ZXIlMEElMEF0b2tlbml6ZXIlMjAlM0QlMjBBdXRvVG9rZW5pemVyLmZyb21fcHJldHJhaW5lZCglMjJzdGV2aGxpdSUyRm15X2F3ZXNvbWVfYmlsbHN1bV9tb2RlbCUyMiklMEFpbnB1dHMlMjAlM0QlMjB0b2tlbml6ZXIodGV4dCUyQyUyMHJldHVybl90ZW5zb3JzJTNEJTIycHQlMjIpLmlucHV0X2lkcw==",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;stevhliu/my_awesome_billsum_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`}}),R=new Q({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9Nb2RlbEZvclNlcTJTZXFMTSUwQSUwQW1vZGVsJTIwJTNEJTIwQXV0b01vZGVsRm9yU2VxMlNlcUxNLmZyb21fcHJldHJhaW5lZCglMjJzdGV2aGxpdSUyRm15X2F3ZXNvbWVfYmlsbHN1bV9tb2RlbCUyMiklMEFvdXRwdXRzJTIwJTNEJTIwbW9kZWwuZ2VuZXJhdGUoaW5wdXRzJTJDJTIwbWF4X25ld190b2tlbnMlM0QxMDAlMkMlMjBkb19zYW1wbGUlM0RGYWxzZSk=",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;stevhliu/my_awesome_billsum_model&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>outputs = model.generate(inputs, max_new_tokens=<span class="hljs-number">100</span>, do_sample=<span class="hljs-literal">False</span>)`}}),z=new Q({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;the inflation reduction act lowers prescription drug costs, health care costs, and energy costs. it&#x27;</span>s the most aggressive action on tackling the climate crisis <span class="hljs-keyword">in</span> american history. it will ask the ultra-wealthy <span class="hljs-keyword">and</span> corporations to pay their fair share.<span class="hljs-string">&#x27;</span>`}}),{c(){p=r("p"),m=s("Tokenize the text and return the "),c=r("code"),M=s("input_ids"),w=s(" as PyTorch tensors:"),j=d(),v(G.$$.fragment),S=d(),$=r("p"),V=s("Use the "),C=r("a"),X=s("generate()"),x=s(" method to create the summarization. For more details about the different text generation strategies and parameters for controlling generation, check out the "),A=r("a"),W=s("Text Generation"),ie=s(" API."),P=d(),v(R.$$.fragment),O=d(),q=r("p"),K=s("Decode the generated token ids back into text:"),Y=d(),v(z.$$.fragment),this.h()},l(u){p=n(u,"P",{});var _=i(p);m=l(_,"Tokenize the text and return the "),c=n(_,"CODE",{});var ee=i(c);M=l(ee,"input_ids"),ee.forEach(a),w=l(_," as PyTorch tensors:"),_.forEach(a),j=y(u),k(G.$$.fragment,u),S=y(u),$=n(u,"P",{});var F=i($);V=l(F,"Use the "),C=n(F,"A",{href:!0});var te=i(C);X=l(te,"generate()"),te.forEach(a),x=l(F," method to create the summarization. For more details about the different text generation strategies and parameters for controlling generation, check out the "),A=n(F,"A",{href:!0});var H=i(A);W=l(H,"Text Generation"),H.forEach(a),ie=l(F," API."),F.forEach(a),P=y(u),k(R.$$.fragment,u),O=y(u),q=n(u,"P",{});var D=i(q);K=l(D,"Decode the generated token ids back into text:"),D.forEach(a),Y=y(u),k(z.$$.fragment,u),this.h()},h(){b(C,"href","/docs/transformers/v4.33.0/en/main_classes/text_generation#transformers.GenerationMixin.generate"),b(A,"href","../main_classes/text_generation")},m(u,_){h(u,p,_),t(p,m),t(p,c),t(c,M),t(p,w),h(u,j,_),T(G,u,_),h(u,S,_),h(u,$,_),t($,V),t($,C),t(C,X),t($,x),t($,A),t(A,W),t($,ie),h(u,P,_),T(R,u,_),h(u,O,_),h(u,q,_),t(q,K),h(u,Y,_),T(z,u,_),I=!0},p:ws,i(u){I||(U(G.$$.fragment,u),U(R.$$.fragment,u),U(z.$$.fragment,u),I=!0)},o(u){E(G.$$.fragment,u),E(R.$$.fragment,u),E(z.$$.fragment,u),I=!1},d(u){u&&a(p),u&&a(j),J(G,u),u&&a(S),u&&a($),u&&a(P),J(R,u),u&&a(O),u&&a(q),u&&a(Y),J(z,u)}}}function qo(N){let p,m;return p=new ia({props:{$$slots:{default:[No]},$$scope:{ctx:N}}}),{c(){v(p.$$.fragment)},l(c){k(p.$$.fragment,c)},m(c,M){T(p,c,M),m=!0},p(c,M){const w={};M&2&&(w.$$scope={dirty:M,ctx:c}),p.$set(w)},i(c){m||(U(p.$$.fragment,c),m=!0)},o(c){E(p.$$.fragment,c),m=!1},d(c){J(p,c)}}}function Yo(N){let p,m,c,M,w,j,G,S,$,V,C,X,x,A,W,ie,P,R,O,q,K,Y,z,I;return G=new Q({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9Ub2tlbml6ZXIlMEElMEF0b2tlbml6ZXIlMjAlM0QlMjBBdXRvVG9rZW5pemVyLmZyb21fcHJldHJhaW5lZCglMjJzdGV2aGxpdSUyRm15X2F3ZXNvbWVfYmlsbHN1bV9tb2RlbCUyMiklMEFpbnB1dHMlMjAlM0QlMjB0b2tlbml6ZXIodGV4dCUyQyUyMHJldHVybl90ZW5zb3JzJTNEJTIydGYlMjIpLmlucHV0X2lkcw==",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;stevhliu/my_awesome_billsum_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`}}),R=new Q({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMFRGQXV0b01vZGVsRm9yU2VxMlNlcUxNJTBBJTBBbW9kZWwlMjAlM0QlMjBURkF1dG9Nb2RlbEZvclNlcTJTZXFMTS5mcm9tX3ByZXRyYWluZWQoJTIyc3RldmhsaXUlMkZteV9hd2Vzb21lX2JpbGxzdW1fbW9kZWwlMjIpJTBBb3V0cHV0cyUyMCUzRCUyMG1vZGVsLmdlbmVyYXRlKGlucHV0cyUyQyUyMG1heF9uZXdfdG9rZW5zJTNEMTAwJTJDJTIwZG9fc2FtcGxlJTNERmFsc2Up",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;stevhliu/my_awesome_billsum_model&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>outputs = model.generate(inputs, max_new_tokens=<span class="hljs-number">100</span>, do_sample=<span class="hljs-literal">False</span>)`}}),z=new Q({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;the inflation reduction act lowers prescription drug costs, health care costs, and energy costs. it&#x27;</span>s the most aggressive action on tackling the climate crisis <span class="hljs-keyword">in</span> american history. it will ask the ultra-wealthy <span class="hljs-keyword">and</span> corporations to pay their fair share.<span class="hljs-string">&#x27;</span>`}}),{c(){p=r("p"),m=s("Tokenize the text and return the "),c=r("code"),M=s("input_ids"),w=s(" as TensorFlow tensors:"),j=d(),v(G.$$.fragment),S=d(),$=r("p"),V=s("Use the "),C=r("a"),X=s("generate()"),x=s(" method to create the summarization. For more details about the different text generation strategies and parameters for controlling generation, check out the "),A=r("a"),W=s("Text Generation"),ie=s(" API."),P=d(),v(R.$$.fragment),O=d(),q=r("p"),K=s("Decode the generated token ids back into text:"),Y=d(),v(z.$$.fragment),this.h()},l(u){p=n(u,"P",{});var _=i(p);m=l(_,"Tokenize the text and return the "),c=n(_,"CODE",{});var ee=i(c);M=l(ee,"input_ids"),ee.forEach(a),w=l(_," as TensorFlow tensors:"),_.forEach(a),j=y(u),k(G.$$.fragment,u),S=y(u),$=n(u,"P",{});var F=i($);V=l(F,"Use the "),C=n(F,"A",{href:!0});var te=i(C);X=l(te,"generate()"),te.forEach(a),x=l(F," method to create the summarization. For more details about the different text generation strategies and parameters for controlling generation, check out the "),A=n(F,"A",{href:!0});var H=i(A);W=l(H,"Text Generation"),H.forEach(a),ie=l(F," API."),F.forEach(a),P=y(u),k(R.$$.fragment,u),O=y(u),q=n(u,"P",{});var D=i(q);K=l(D,"Decode the generated token ids back into text:"),D.forEach(a),Y=y(u),k(z.$$.fragment,u),this.h()},h(){b(C,"href","/docs/transformers/v4.33.0/en/main_classes/text_generation#transformers.TFGenerationMixin.generate"),b(A,"href","../main_classes/text_generation")},m(u,_){h(u,p,_),t(p,m),t(p,c),t(c,M),t(p,w),h(u,j,_),T(G,u,_),h(u,S,_),h(u,$,_),t($,V),t($,C),t(C,X),t($,x),t($,A),t(A,W),t($,ie),h(u,P,_),T(R,u,_),h(u,O,_),h(u,q,_),t(q,K),h(u,Y,_),T(z,u,_),I=!0},p:ws,i(u){I||(U(G.$$.fragment,u),U(R.$$.fragment,u),U(z.$$.fragment,u),I=!0)},o(u){E(G.$$.fragment,u),E(R.$$.fragment,u),E(z.$$.fragment,u),I=!1},d(u){u&&a(p),u&&a(j),J(G,u),u&&a(S),u&&a($),u&&a(P),J(R,u),u&&a(O),u&&a(q),u&&a(Y),J(z,u)}}}function Ho(N){let p,m;return p=new ia({props:{$$slots:{default:[Yo]},$$scope:{ctx:N}}}),{c(){v(p.$$.fragment)},l(c){k(p.$$.fragment,c)},m(c,M){T(p,c,M),m=!0},p(c,M){const w={};M&2&&(w.$$scope={dirty:M,ctx:c}),p.$set(w)},i(c){m||(U(p.$$.fragment,c),m=!0)},o(c){E(p.$$.fragment,c),m=!1},d(c){J(p,c)}}}function Qo(N){let p,m,c,M,w,j,G,S,$,V,C,X,x,A,W,ie,P,R,O,q,K,Y,z,I,u,_,ee,F,te,H,D,ke,ce,Te,ge,Ge,Xe,Ce,L,Se,se,Ue,Ve,Ee,pe,we,fe,le,Je,de,ue,$e,oe,re,g,B,ye,Ze,Be,ae,be,ze,he,Re,me,ne,Ie,_e,We,je,Ae,Me,De,ve,o,Z,xe,Fe,Le,pt,Oe,Ne,Ke,Ye,ht,He,mt,qe,Qe,ft,ut,Pe,dt,yt,lt,et,st,wt,ot,$s,ca,_s,Ca,rt,js,pa,vs,ks,ha,Ts,Us,Va,Vt,Ba,Lt,Es,Ra,nt,ma,Js,Zs,Bt,Gs,fa,Cs,Vs,Bs,Rt,Rs,ua,Ws,Ss,Wa,Wt,Sa,tt,As,St,xs,Xs,da,zs,Is,ya,Fs,Ns,Aa,At,xa,it,qs,Ot,Ys,Hs,ba,Qs,Ps,Xa,$t,za,bt,_t,Ma,xt,Ds,ga,Ls,Ia,at,Os,Xt,Ks,el,zt,tl,al,It,sl,ll,Fa,Ft,Na,jt,ol,Nt,rl,nl,qa,qt,Ya,vt,il,wa,cl,pl,Ha,Mt,kt,$a,Yt,hl,_a,ml,Qa,Tt,Pa,Ut,Da,gt,Et,ja,Ht,fl,va,ul,La,Kt,dl,Oa,ea,yl,Ka,Qt,es,ct,bl,ta,Ml,gl,ka,wl,$l,ts,Pt,as,Jt,_l,Ta,jl,vl,ss,Zt,ls;return j=new na({}),C=new Go({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/summarization.ipynb"},{label:"PyTorch",value:"https://colab.research.google.com/github/huggingface/notebooks/blob/main/transformers_doc/en/pytorch/summarization.ipynb"},{label:"TensorFlow",value:"https://colab.research.google.com/github/huggingface/notebooks/blob/main/transformers_doc/en/tensorflow/summarization.ipynb"},{label:"Mixed",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/main/transformers_doc/en/summarization.ipynb"},{label:"PyTorch",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/main/transformers_doc/en/pytorch/summarization.ipynb"},{label:"TensorFlow",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/main/transformers_doc/en/tensorflow/summarization.ipynb"}]}}),x=new Zo({props:{id:"yHnr5Dk2zCI"}}),se=new gs({props:{$$slots:{default:[Co]},$$scope:{ctx:N}}}),we=new Q({props:{code:"cGlwJTIwaW5zdGFsbCUyMHRyYW5zZm9ybWVycyUyMGRhdGFzZXRzJTIwZXZhbHVhdGUlMjByb3VnZV9zY29yZQ==",highlighted:"pip install transformers datasets evaluate rouge_score"}}),ue=new Q({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()`}}),B=new na({}),Re=new Q({props:{code:"ZnJvbSUyMGRhdGFzZXRzJTIwaW1wb3J0JTIwbG9hZF9kYXRhc2V0JTBBJTBBYmlsbHN1bSUyMCUzRCUyMGxvYWRfZGF0YXNldCglMjJiaWxsc3VtJTIyJTJDJTIwc3BsaXQlM0QlMjJjYV90ZXN0JTIyKQ==",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>billsum = load_dataset(<span class="hljs-string">&quot;billsum&quot;</span>, split=<span class="hljs-string">&quot;ca_test&quot;</span>)`}}),Me=new Q({props:{code:"YmlsbHN1bSUyMCUzRCUyMGJpbGxzdW0udHJhaW5fdGVzdF9zcGxpdCh0ZXN0X3NpemUlM0QwLjIp",highlighted:'<span class="hljs-meta">&gt;&gt;&gt; </span>billsum = billsum.train_test_split(test_size=<span class="hljs-number">0.2</span>)'}}),xe=new Q({props:{code:"YmlsbHN1bSU1QiUyMnRyYWluJTIyJTVEJTVCMCU1RA==",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span>billsum[<span class="hljs-string">&quot;train&quot;</span>][<span class="hljs-number">0</span>]
{<span class="hljs-string">&#x27;summary&#x27;</span>: <span class="hljs-string">&#x27;Existing law authorizes state agencies to enter into contracts for the acquisition of goods or services upon approval by the Department of General Services. Existing law sets forth various requirements and prohibitions for those contracts, including, but not limited to, a prohibition on entering into contracts for the acquisition of goods or services of $100,000 or more with a contractor that discriminates between spouses and domestic partners or same-sex and different-sex couples in the provision of benefits. Existing law provides that a contract entered into in violation of those requirements and prohibitions is void and authorizes the state or any person acting on behalf of the state to bring a civil action seeking a determination that a contract is in violation and therefore void. Under existing law, a willful violation of those requirements and prohibitions is a misdemeanor.\\nThis bill would also prohibit a state agency from entering into contracts for the acquisition of goods or services of $100,000 or more with a contractor that discriminates between employees on the basis of gender identity in the provision of benefits, as specified. By expanding the scope of a crime, this bill would impose a state-mandated local program.\\nThe California Constitution requires the state to reimburse local agencies and school districts for certain costs mandated by the state. Statutory provisions establish procedures for making that reimbursement.\\nThis bill would provide that no reimbursement is required by this act for a specified reason.&#x27;</span>,
 <span class="hljs-string">&#x27;text&#x27;</span>: <span class="hljs-string">&#x27;The people of the State of California do enact as follows:\\n\\n\\nSECTION 1.\\nSection 10295.35 is added to the Public Contract Code, to read:\\n10295.35.\\n(a) (1) Notwithstanding any other law, a state agency shall not enter into any contract for the acquisition of goods or services in the amount of one hundred thousand dollars ($100,000) or more with a contractor that, in the provision of benefits, discriminates between employees on the basis of an employee\u2019s or dependent\u2019s actual or perceived gender identity, including, but not limited to, the employee\u2019s or dependent\u2019s identification as transgender.\\n(2) For purposes of this section, \u201Ccontract\u201D includes contracts with a cumulative amount of one hundred thousand dollars ($100,000) or more per contractor in each fiscal year.\\n(3) For purposes of this section, an employee health plan is discriminatory if the plan is not consistent with Section 1365.5 of the Health and Safety Code and Section 10140 of the Insurance Code.\\n(4) The requirements of this section shall apply only to those portions of a contractor\u2019s operations that occur under any of the following conditions:\\n(A) Within the state.\\n(B) On real property outside the state if the property is owned by the state or if the state has a right to occupy the property, and if the contractor\u2019s presence at that location is connected to a contract with the state.\\n(C) Elsewhere in the United States where work related to a state contract is being performed.\\n(b) Contractors shall treat as confidential, to the maximum extent allowed by law or by the requirement of the contractor\u2019s insurance provider, any request by an employee or applicant for employment benefits or any documentation of eligibility for benefits submitted by an employee or applicant for employment.\\n(c) After taking all reasonable measures to find a contractor that complies with this section, as determined by the state agency, the requirements of this section may be waived under any of the following circumstances:\\n(1) There is only one prospective contractor willing to enter into a specific contract with the state agency.\\n(2) The contract is necessary to respond to an emergency, as determined by the state agency, that endangers the public health, welfare, or safety, or the contract is necessary for the provision of essential services, and no entity that complies with the requirements of this section capable of responding to the emergency is immediately available.\\n(3) The requirements of this section violate, or are inconsistent with, the terms or conditions of a grant, subvention, or agreement, if the agency has made a good faith attempt to change the terms or conditions of any grant, subvention, or agreement to authorize application of this section.\\n(4) The contractor is providing wholesale or bulk water, power, or natural gas, the conveyance or transmission of the same, or ancillary services, as required for ensuring reliable services in accordance with good utility practice, if the purchase of the same cannot practically be accomplished through the standard competitive bidding procedures and the contractor is not providing direct retail services to end users.\\n(d) (1) A contractor shall not be deemed to discriminate in the provision of benefits if the contractor, in providing the benefits, pays the actual costs incurred in obtaining the benefit.\\n(2) If a contractor is unable to provide a certain benefit, despite taking reasonable measures to do so, the contractor shall not be deemed to discriminate in the provision of benefits.\\n(e) (1) Every contract subject to this chapter shall contain a statement by which the contractor certifies that the contractor is in compliance with this section.\\n(2) The department or other contracting agency shall enforce this section pursuant to its existing enforcement powers.\\n(3) (A) If a contractor falsely certifies that it is in compliance with this section, the contract with that contractor shall be subject to Article 9 (commencing with Section 10420), unless, within a time period specified by the department or other contracting agency, the contractor provides to the department or agency proof that it has complied, or is in the process of complying, with this section.\\n(B) The application of the remedies or penalties contained in Article 9 (commencing with Section 10420) to a contract subject to this chapter shall not preclude the application of any existing remedies otherwise available to the department or other contracting agency under its existing enforcement powers.\\n(f) Nothing in this section is intended to regulate the contracting practices of any local jurisdiction.\\n(g) This section shall be construed so as not to conflict with applicable federal laws, rules, or regulations. In the event that a court or agency of competent jurisdiction holds that federal law, rule, or regulation invalidates any clause, sentence, paragraph, or section of this code or the application thereof to any person or circumstances, it is the intent of the state that the court or agency sever that clause, sentence, paragraph, or section so that the remainder of this section shall remain in effect.\\nSEC. 2.\\nSection 10295.35 of the Public Contract Code shall not be construed to create any new enforcement authority or responsibility in the Department of General Services or any other contracting agency.\\nSEC. 3.\\nNo reimbursement is required by this act pursuant to Section 6 of Article XIII\\u2009B of the California Constitution because the only costs that may be incurred by a local agency or school district will be incurred because this act creates a new crime or infraction, eliminates a crime or infraction, or changes the penalty for a crime or infraction, within the meaning of Section 17556 of the Government Code, or changes the definition of a crime within the meaning of Section 6 of Article XIII\\u2009B of the California Constitution.&#x27;</span>,
 <span class="hljs-string">&#x27;title&#x27;</span>: <span class="hljs-string">&#x27;An act to add Section 10295.35 to the Public Contract Code, relating to public contracts.&#x27;</span>}`}}),ot=new na({}),Vt=new Q({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)`}}),Wt=new Q({props:{code:"cHJlZml4JTIwJTNEJTIwJTIyc3VtbWFyaXplJTNBJTIwJTIyJTBBJTBBJTBBZGVmJTIwcHJlcHJvY2Vzc19mdW5jdGlvbihleGFtcGxlcyklM0ElMEElMjAlMjAlMjAlMjBpbnB1dHMlMjAlM0QlMjAlNUJwcmVmaXglMjAlMkIlMjBkb2MlMjBmb3IlMjBkb2MlMjBpbiUyMGV4YW1wbGVzJTVCJTIydGV4dCUyMiU1RCU1RCUwQSUyMCUyMCUyMCUyMG1vZGVsX2lucHV0cyUyMCUzRCUyMHRva2VuaXplcihpbnB1dHMlMkMlMjBtYXhfbGVuZ3RoJTNEMTAyNCUyQyUyMHRydW5jYXRpb24lM0RUcnVlKSUwQSUwQSUyMCUyMCUyMCUyMGxhYmVscyUyMCUzRCUyMHRva2VuaXplcih0ZXh0X3RhcmdldCUzRGV4YW1wbGVzJTVCJTIyc3VtbWFyeSUyMiU1RCUyQyUyMG1heF9sZW5ndGglM0QxMjglMkMlMjB0cnVuY2F0aW9uJTNEVHJ1ZSklMEElMEElMjAlMjAlMjAlMjBtb2RlbF9pbnB1dHMlNUIlMjJsYWJlbHMlMjIlNUQlMjAlM0QlMjBsYWJlbHMlNUIlMjJpbnB1dF9pZHMlMjIlNUQlMEElMjAlMjAlMjAlMjByZXR1cm4lMjBtb2RlbF9pbnB1dHM=",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span>prefix = <span class="hljs-string">&quot;summarize: &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 + doc <span class="hljs-keyword">for</span> doc <span class="hljs-keyword">in</span> examples[<span class="hljs-string">&quot;text&quot;</span>]]
<span class="hljs-meta">... </span>    model_inputs = tokenizer(inputs, max_length=<span class="hljs-number">1024</span>, truncation=<span class="hljs-literal">True</span>)

<span class="hljs-meta">... </span>    labels = tokenizer(text_target=examples[<span class="hljs-string">&quot;summary&quot;</span>], max_length=<span class="hljs-number">128</span>, truncation=<span class="hljs-literal">True</span>)

<span class="hljs-meta">... </span>    model_inputs[<span class="hljs-string">&quot;labels&quot;</span>] = labels[<span class="hljs-string">&quot;input_ids&quot;</span>]
<span class="hljs-meta">... </span>    <span class="hljs-keyword">return</span> model_inputs`}}),At=new Q({props:{code:"dG9rZW5pemVkX2JpbGxzdW0lMjAlM0QlMjBiaWxsc3VtLm1hcChwcmVwcm9jZXNzX2Z1bmN0aW9uJTJDJTIwYmF0Y2hlZCUzRFRydWUp",highlighted:'<span class="hljs-meta">&gt;&gt;&gt; </span>tokenized_billsum = billsum.<span class="hljs-built_in">map</span>(preprocess_function, batched=<span class="hljs-literal">True</span>)'}}),$t=new Tl({props:{pytorch:!0,tensorflow:!0,jax:!1,$$slots:{tensorflow:[Wo],pytorch:[Bo]},$$scope:{ctx:N}}}),xt=new na({}),Ft=new Q({props:{code:"aW1wb3J0JTIwZXZhbHVhdGUlMEElMEFyb3VnZSUyMCUzRCUyMGV2YWx1YXRlLmxvYWQoJTIycm91Z2UlMjIp",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">import</span> evaluate

<span class="hljs-meta">&gt;&gt;&gt; </span>rouge = evaluate.load(<span class="hljs-string">&quot;rouge&quot;</span>)`}}),qt=new Q({props:{code:"aW1wb3J0JTIwbnVtcHklMjBhcyUyMG5wJTBBJTBBJTBBZGVmJTIwY29tcHV0ZV9tZXRyaWNzKGV2YWxfcHJlZCklM0ElMEElMjAlMjAlMjAlMjBwcmVkaWN0aW9ucyUyQyUyMGxhYmVscyUyMCUzRCUyMGV2YWxfcHJlZCUwQSUyMCUyMCUyMCUyMGRlY29kZWRfcHJlZHMlMjAlM0QlMjB0b2tlbml6ZXIuYmF0Y2hfZGVjb2RlKHByZWRpY3Rpb25zJTJDJTIwc2tpcF9zcGVjaWFsX3Rva2VucyUzRFRydWUpJTBBJTIwJTIwJTIwJTIwbGFiZWxzJTIwJTNEJTIwbnAud2hlcmUobGFiZWxzJTIwISUzRCUyMC0xMDAlMkMlMjBsYWJlbHMlMkMlMjB0b2tlbml6ZXIucGFkX3Rva2VuX2lkKSUwQSUyMCUyMCUyMCUyMGRlY29kZWRfbGFiZWxzJTIwJTNEJTIwdG9rZW5pemVyLmJhdGNoX2RlY29kZShsYWJlbHMlMkMlMjBza2lwX3NwZWNpYWxfdG9rZW5zJTNEVHJ1ZSklMEElMEElMjAlMjAlMjAlMjByZXN1bHQlMjAlM0QlMjByb3VnZS5jb21wdXRlKHByZWRpY3Rpb25zJTNEZGVjb2RlZF9wcmVkcyUyQyUyMHJlZmVyZW5jZXMlM0RkZWNvZGVkX2xhYmVscyUyQyUyMHVzZV9zdGVtbWVyJTNEVHJ1ZSklMEElMEElMjAlMjAlMjAlMjBwcmVkaWN0aW9uX2xlbnMlMjAlM0QlMjAlNUJucC5jb3VudF9ub256ZXJvKHByZWQlMjAhJTNEJTIwdG9rZW5pemVyLnBhZF90b2tlbl9pZCklMjBmb3IlMjBwcmVkJTIwaW4lMjBwcmVkaWN0aW9ucyU1RCUwQSUyMCUyMCUyMCUyMHJlc3VsdCU1QiUyMmdlbl9sZW4lMjIlNUQlMjAlM0QlMjBucC5tZWFuKHByZWRpY3Rpb25fbGVucyklMEElMEElMjAlMjAlMjAlMjByZXR1cm4lMjAlN0JrJTNBJTIwcm91bmQodiUyQyUyMDQpJTIwZm9yJTIwayUyQyUyMHYlMjBpbiUyMHJlc3VsdC5pdGVtcygpJTdE",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_">compute_metrics</span>(<span class="hljs-params">eval_pred</span>):
<span class="hljs-meta">... </span>    predictions, labels = eval_pred
<span class="hljs-meta">... </span>    decoded_preds = tokenizer.batch_decode(predictions, 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>    result = rouge.compute(predictions=decoded_preds, references=decoded_labels, use_stemmer=<span class="hljs-literal">True</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> predictions]
<span class="hljs-meta">... </span>    result[<span class="hljs-string">&quot;gen_len&quot;</span>] = np.mean(prediction_lens)

<span class="hljs-meta">... </span>    <span class="hljs-keyword">return</span> {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()}`}}),Yt=new na({}),Tt=new Tl({props:{pytorch:!0,tensorflow:!0,jax:!1,$$slots:{tensorflow:[Io],pytorch:[xo]},$$scope:{ctx:N}}}),Ut=new gs({props:{$$slots:{default:[Fo]},$$scope:{ctx:N}}}),Ht=new na({}),Qt=new Q({props:{code:"dGV4dCUyMCUzRCUyMCUyMnN1bW1hcml6ZSUzQSUyMFRoZSUyMEluZmxhdGlvbiUyMFJlZHVjdGlvbiUyMEFjdCUyMGxvd2VycyUyMHByZXNjcmlwdGlvbiUyMGRydWclMjBjb3N0cyUyQyUyMGhlYWx0aCUyMGNhcmUlMjBjb3N0cyUyQyUyMGFuZCUyMGVuZXJneSUyMGNvc3RzLiUyMEl0J3MlMjB0aGUlMjBtb3N0JTIwYWdncmVzc2l2ZSUyMGFjdGlvbiUyMG9uJTIwdGFja2xpbmclMjB0aGUlMjBjbGltYXRlJTIwY3Jpc2lzJTIwaW4lMjBBbWVyaWNhbiUyMGhpc3RvcnklMkMlMjB3aGljaCUyMHdpbGwlMjBsaWZ0JTIwdXAlMjBBbWVyaWNhbiUyMHdvcmtlcnMlMjBhbmQlMjBjcmVhdGUlMjBnb29kLXBheWluZyUyQyUyMHVuaW9uJTIwam9icyUyMGFjcm9zcyUyMHRoZSUyMGNvdW50cnkuJTIwSXQnbGwlMjBsb3dlciUyMHRoZSUyMGRlZmljaXQlMjBhbmQlMjBhc2slMjB0aGUlMjB1bHRyYS13ZWFsdGh5JTIwYW5kJTIwY29ycG9yYXRpb25zJTIwdG8lMjBwYXklMjB0aGVpciUyMGZhaXIlMjBzaGFyZS4lMjBBbmQlMjBubyUyMG9uZSUyMG1ha2luZyUyMHVuZGVyJTIwJTI0NDAwJTJDMDAwJTIwcGVyJTIweWVhciUyMHdpbGwlMjBwYXklMjBhJTIwcGVubnklMjBtb3JlJTIwaW4lMjB0YXhlcy4lMjI=",highlighted:'<span class="hljs-meta">&gt;&gt;&gt; </span>text = <span class="hljs-string">&quot;summarize: The Inflation Reduction Act lowers prescription drug costs, health care costs, and energy costs. It&#x27;s the most aggressive action on tackling the climate crisis in American history, which will lift up American workers and create good-paying, union jobs across the country. It&#x27;ll lower the deficit and ask the ultra-wealthy and corporations to pay their fair share. And no one making under $400,000 per year will pay a penny more in taxes.&quot;</span>'}}),Pt=new Q({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMHBpcGVsaW5lJTBBJTBBc3VtbWFyaXplciUyMCUzRCUyMHBpcGVsaW5lKCUyMnN1bW1hcml6YXRpb24lMjIlMkMlMjBtb2RlbCUzRCUyMnN0ZXZobGl1JTJGbXlfYXdlc29tZV9iaWxsc3VtX21vZGVsJTIyKSUwQXN1bW1hcml6ZXIodGV4dCk=",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>summarizer = pipeline(<span class="hljs-string">&quot;summarization&quot;</span>, model=<span class="hljs-string">&quot;stevhliu/my_awesome_billsum_model&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>summarizer(text)
[{<span class="hljs-string">&quot;summary_text&quot;</span>: <span class="hljs-string">&quot;The Inflation Reduction Act lowers prescription drug costs, health care costs, and energy costs. It&#x27;s the most aggressive action on tackling the climate crisis in American history, which will lift up American workers and create good-paying, union jobs across the country.&quot;</span>}]`}}),Zt=new Tl({props:{pytorch:!0,tensorflow:!0,jax:!1,$$slots:{tensorflow:[Ho],pytorch:[qo]},$$scope:{ctx:N}}}),{c(){p=r("meta"),m=d(),c=r("h1"),M=r("a"),w=r("span"),v(j.$$.fragment),G=d(),S=r("span"),$=s("Summarization"),V=d(),v(C.$$.fragment),X=d(),v(x.$$.fragment),A=d(),W=r("p"),ie=s("Summarization creates a shorter version of a document or an article that captures all the important information. Along with translation, it is another example of a task that can be formulated as a sequence-to-sequence task. Summarization can be:"),P=d(),R=r("ul"),O=r("li"),q=s("Extractive: extract the most relevant information from a document."),K=d(),Y=r("li"),z=s("Abstractive: generate new text that captures the most relevant information."),I=d(),u=r("p"),_=s("This guide will show you how to:"),ee=d(),F=r("ol"),te=r("li"),H=s("Finetune "),D=r("a"),ke=s("T5"),ce=s(" on the California state bill subset of the "),Te=r("a"),ge=s("BillSum"),Ge=s(" dataset for abstractive summarization."),Xe=d(),Ce=r("li"),L=s("Use your finetuned model for inference."),Se=d(),v(se.$$.fragment),Ue=d(),Ve=r("p"),Ee=s("Before you begin, make sure you have all the necessary libraries installed:"),pe=d(),v(we.$$.fragment),fe=d(),le=r("p"),Je=s("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:"),de=d(),v(ue.$$.fragment),$e=d(),oe=r("h2"),re=r("a"),g=r("span"),v(B.$$.fragment),ye=d(),Ze=r("span"),Be=s("Load BillSum dataset"),ae=d(),be=r("p"),ze=s("Start by loading the smaller California state bill subset of the BillSum dataset from the \u{1F917} Datasets library:"),he=d(),v(Re.$$.fragment),me=d(),ne=r("p"),Ie=s("Split the dataset into a train and test set with the "),_e=r("a"),We=s("train_test_split"),je=s(" method:"),Ae=d(),v(Me.$$.fragment),De=d(),ve=r("p"),o=s("Then take a look at an example:"),Z=d(),v(xe.$$.fragment),Fe=d(),Le=r("p"),pt=s("There are two fields that you\u2019ll want to use:"),Oe=d(),Ne=r("ul"),Ke=r("li"),Ye=r("code"),ht=s("text"),He=s(": the text of the bill which\u2019ll be the input to the model."),mt=d(),qe=r("li"),Qe=r("code"),ft=s("summary"),ut=s(": a condensed version of "),Pe=r("code"),dt=s("text"),yt=s(" which\u2019ll be the model target."),lt=d(),et=r("h2"),st=r("a"),wt=r("span"),v(ot.$$.fragment),$s=d(),ca=r("span"),_s=s("Preprocess"),Ca=d(),rt=r("p"),js=s("The next step is to load a T5 tokenizer to process "),pa=r("code"),vs=s("text"),ks=s(" and "),ha=r("code"),Ts=s("summary"),Us=s(":"),Va=d(),v(Vt.$$.fragment),Ba=d(),Lt=r("p"),Es=s("The preprocessing function you want to create needs to:"),Ra=d(),nt=r("ol"),ma=r("li"),Js=s("Prefix the input with a prompt so T5 knows this is a summarization task. Some models capable of multiple NLP tasks require prompting for specific tasks."),Zs=d(),Bt=r("li"),Gs=s("Use the keyword "),fa=r("code"),Cs=s("text_target"),Vs=s(" argument when tokenizing labels."),Bs=d(),Rt=r("li"),Rs=s("Truncate sequences to be no longer than the maximum length set by the "),ua=r("code"),Ws=s("max_length"),Ss=s(" parameter."),Wa=d(),v(Wt.$$.fragment),Sa=d(),tt=r("p"),As=s("To apply the preprocessing function over the entire dataset, use \u{1F917} Datasets "),St=r("a"),xs=s("map"),Xs=s(" method. You can speed up the "),da=r("code"),zs=s("map"),Is=s(" function by setting "),ya=r("code"),Fs=s("batched=True"),Ns=s(" to process multiple elements of the dataset at once:"),Aa=d(),v(At.$$.fragment),xa=d(),it=r("p"),qs=s("Now create a batch of examples using "),Ot=r("a"),Ys=s("DataCollatorForSeq2Seq"),Hs=s(". It\u2019s more efficient to "),ba=r("em"),Qs=s("dynamically pad"),Ps=s(" the sentences to the longest length in a batch during collation, instead of padding the whole dataset to the maximum length."),Xa=d(),v($t.$$.fragment),za=d(),bt=r("h2"),_t=r("a"),Ma=r("span"),v(xt.$$.fragment),Ds=d(),ga=r("span"),Ls=s("Evaluate"),Ia=d(),at=r("p"),Os=s("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} "),Xt=r("a"),Ks=s("Evaluate"),el=s(" library. For this task, load the "),zt=r("a"),tl=s("ROUGE"),al=s(" metric (see the \u{1F917} Evaluate "),It=r("a"),sl=s("quick tour"),ll=s(" to learn more about how to load and compute a metric):"),Fa=d(),v(Ft.$$.fragment),Na=d(),jt=r("p"),ol=s("Then create a function that passes your predictions and labels to "),Nt=r("a"),rl=s("compute"),nl=s(" to calculate the ROUGE metric:"),qa=d(),v(qt.$$.fragment),Ya=d(),vt=r("p"),il=s("Your "),wa=r("code"),cl=s("compute_metrics"),pl=s(" function is ready to go now, and you\u2019ll return to it when you setup your training."),Ha=d(),Mt=r("h2"),kt=r("a"),$a=r("span"),v(Yt.$$.fragment),hl=d(),_a=r("span"),ml=s("Train"),Qa=d(),v(Tt.$$.fragment),Pa=d(),v(Ut.$$.fragment),Da=d(),gt=r("h2"),Et=r("a"),ja=r("span"),v(Ht.$$.fragment),fl=d(),va=r("span"),ul=s("Inference"),La=d(),Kt=r("p"),dl=s("Great, now that you\u2019ve finetuned a model, you can use it for inference!"),Oa=d(),ea=r("p"),yl=s("Come up with some text you\u2019d like to summarize. For T5, you need to prefix your input depending on the task you\u2019re working on. For summarization you should prefix your input as shown below:"),Ka=d(),v(Qt.$$.fragment),es=d(),ct=r("p"),bl=s("The simplest way to try out your finetuned model for inference is to use it in a "),ta=r("a"),Ml=s("pipeline()"),gl=s(". Instantiate a "),ka=r("code"),wl=s("pipeline"),$l=s(" for summarization with your model, and pass your text to it:"),ts=d(),v(Pt.$$.fragment),as=d(),Jt=r("p"),_l=s("You can also manually replicate the results of the "),Ta=r("code"),jl=s("pipeline"),vl=s(" if you\u2019d like:"),ss=d(),v(Zt.$$.fragment),this.h()},l(e){const f=Eo('[data-svelte="svelte-1phssyn"]',document.head);p=n(f,"META",{name:!0,content:!0}),f.forEach(a),m=y(e),c=n(e,"H1",{class:!0});var Dt=i(c);M=n(Dt,"A",{id:!0,class:!0,href:!0});var Ua=i(M);w=n(Ua,"SPAN",{});var Ea=i(w);k(j.$$.fragment,Ea),Ea.forEach(a),Ua.forEach(a),G=y(Dt),S=n(Dt,"SPAN",{});var Ja=i(S);$=l(Ja,"Summarization"),Ja.forEach(a),Dt.forEach(a),V=y(e),k(C.$$.fragment,e),X=y(e),k(x.$$.fragment,e),A=y(e),W=n(e,"P",{});var Za=i(W);ie=l(Za,"Summarization creates a shorter version of a document or an article that captures all the important information. Along with translation, it is another example of a task that can be formulated as a sequence-to-sequence task. Summarization can be:"),Za.forEach(a),P=y(e),R=n(e,"UL",{});var os=i(R);O=n(os,"LI",{});var Ul=i(O);q=l(Ul,"Extractive: extract the most relevant information from a document."),Ul.forEach(a),K=y(os),Y=n(os,"LI",{});var El=i(Y);z=l(El,"Abstractive: generate new text that captures the most relevant information."),El.forEach(a),os.forEach(a),I=y(e),u=n(e,"P",{});var Jl=i(u);_=l(Jl,"This guide will show you how to:"),Jl.forEach(a),ee=y(e),F=n(e,"OL",{});var rs=i(F);te=n(rs,"LI",{});var aa=i(te);H=l(aa,"Finetune "),D=n(aa,"A",{href:!0,rel:!0});var Zl=i(D);ke=l(Zl,"T5"),Zl.forEach(a),ce=l(aa," on the California state bill subset of the "),Te=n(aa,"A",{href:!0,rel:!0});var Gl=i(Te);ge=l(Gl,"BillSum"),Gl.forEach(a),Ge=l(aa," dataset for abstractive summarization."),aa.forEach(a),Xe=y(rs),Ce=n(rs,"LI",{});var Cl=i(Ce);L=l(Cl,"Use your finetuned model for inference."),Cl.forEach(a),rs.forEach(a),Se=y(e),k(se.$$.fragment,e),Ue=y(e),Ve=n(e,"P",{});var Vl=i(Ve);Ee=l(Vl,"Before you begin, make sure you have all the necessary libraries installed:"),Vl.forEach(a),pe=y(e),k(we.$$.fragment,e),fe=y(e),le=n(e,"P",{});var Bl=i(le);Je=l(Bl,"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:"),Bl.forEach(a),de=y(e),k(ue.$$.fragment,e),$e=y(e),oe=n(e,"H2",{class:!0});var ns=i(oe);re=n(ns,"A",{id:!0,class:!0,href:!0});var Rl=i(re);g=n(Rl,"SPAN",{});var Wl=i(g);k(B.$$.fragment,Wl),Wl.forEach(a),Rl.forEach(a),ye=y(ns),Ze=n(ns,"SPAN",{});var Sl=i(Ze);Be=l(Sl,"Load BillSum dataset"),Sl.forEach(a),ns.forEach(a),ae=y(e),be=n(e,"P",{});var Al=i(be);ze=l(Al,"Start by loading the smaller California state bill subset of the BillSum dataset from the \u{1F917} Datasets library:"),Al.forEach(a),he=y(e),k(Re.$$.fragment,e),me=y(e),ne=n(e,"P",{});var is=i(ne);Ie=l(is,"Split the dataset into a train and test set with the "),_e=n(is,"A",{href:!0,rel:!0});var xl=i(_e);We=l(xl,"train_test_split"),xl.forEach(a),je=l(is," method:"),is.forEach(a),Ae=y(e),k(Me.$$.fragment,e),De=y(e),ve=n(e,"P",{});var Xl=i(ve);o=l(Xl,"Then take a look at an example:"),Xl.forEach(a),Z=y(e),k(xe.$$.fragment,e),Fe=y(e),Le=n(e,"P",{});var zl=i(Le);pt=l(zl,"There are two fields that you\u2019ll want to use:"),zl.forEach(a),Oe=y(e),Ne=n(e,"UL",{});var cs=i(Ne);Ke=n(cs,"LI",{});var kl=i(Ke);Ye=n(kl,"CODE",{});var Il=i(Ye);ht=l(Il,"text"),Il.forEach(a),He=l(kl,": the text of the bill which\u2019ll be the input to the model."),kl.forEach(a),mt=y(cs),qe=n(cs,"LI",{});var Ga=i(qe);Qe=n(Ga,"CODE",{});var Fl=i(Qe);ft=l(Fl,"summary"),Fl.forEach(a),ut=l(Ga,": a condensed version of "),Pe=n(Ga,"CODE",{});var Nl=i(Pe);dt=l(Nl,"text"),Nl.forEach(a),yt=l(Ga," which\u2019ll be the model target."),Ga.forEach(a),cs.forEach(a),lt=y(e),et=n(e,"H2",{class:!0});var ps=i(et);st=n(ps,"A",{id:!0,class:!0,href:!0});var ql=i(st);wt=n(ql,"SPAN",{});var Yl=i(wt);k(ot.$$.fragment,Yl),Yl.forEach(a),ql.forEach(a),$s=y(ps),ca=n(ps,"SPAN",{});var Hl=i(ca);_s=l(Hl,"Preprocess"),Hl.forEach(a),ps.forEach(a),Ca=y(e),rt=n(e,"P",{});var sa=i(rt);js=l(sa,"The next step is to load a T5 tokenizer to process "),pa=n(sa,"CODE",{});var Ql=i(pa);vs=l(Ql,"text"),Ql.forEach(a),ks=l(sa," and "),ha=n(sa,"CODE",{});var Pl=i(ha);Ts=l(Pl,"summary"),Pl.forEach(a),Us=l(sa,":"),sa.forEach(a),Va=y(e),k(Vt.$$.fragment,e),Ba=y(e),Lt=n(e,"P",{});var Dl=i(Lt);Es=l(Dl,"The preprocessing function you want to create needs to:"),Dl.forEach(a),Ra=y(e),nt=n(e,"OL",{});var la=i(nt);ma=n(la,"LI",{});var Ll=i(ma);Js=l(Ll,"Prefix the input with a prompt so T5 knows this is a summarization task. Some models capable of multiple NLP tasks require prompting for specific tasks."),Ll.forEach(a),Zs=y(la),Bt=n(la,"LI",{});var hs=i(Bt);Gs=l(hs,"Use the keyword "),fa=n(hs,"CODE",{});var Ol=i(fa);Cs=l(Ol,"text_target"),Ol.forEach(a),Vs=l(hs," argument when tokenizing labels."),hs.forEach(a),Bs=y(la),Rt=n(la,"LI",{});var ms=i(Rt);Rs=l(ms,"Truncate sequences to be no longer than the maximum length set by the "),ua=n(ms,"CODE",{});var Kl=i(ua);Ws=l(Kl,"max_length"),Kl.forEach(a),Ss=l(ms," parameter."),ms.forEach(a),la.forEach(a),Wa=y(e),k(Wt.$$.fragment,e),Sa=y(e),tt=n(e,"P",{});var Gt=i(tt);As=l(Gt,"To apply the preprocessing function over the entire dataset, use \u{1F917} Datasets "),St=n(Gt,"A",{href:!0,rel:!0});var eo=i(St);xs=l(eo,"map"),eo.forEach(a),Xs=l(Gt," method. You can speed up the "),da=n(Gt,"CODE",{});var to=i(da);zs=l(to,"map"),to.forEach(a),Is=l(Gt," function by setting "),ya=n(Gt,"CODE",{});var ao=i(ya);Fs=l(ao,"batched=True"),ao.forEach(a),Ns=l(Gt," to process multiple elements of the dataset at once:"),Gt.forEach(a),Aa=y(e),k(At.$$.fragment,e),xa=y(e),it=n(e,"P",{});var oa=i(it);qs=l(oa,"Now create a batch of examples using "),Ot=n(oa,"A",{href:!0});var so=i(Ot);Ys=l(so,"DataCollatorForSeq2Seq"),so.forEach(a),Hs=l(oa,". It\u2019s more efficient to "),ba=n(oa,"EM",{});var lo=i(ba);Qs=l(lo,"dynamically pad"),lo.forEach(a),Ps=l(oa," the sentences to the longest length in a batch during collation, instead of padding the whole dataset to the maximum length."),oa.forEach(a),Xa=y(e),k($t.$$.fragment,e),za=y(e),bt=n(e,"H2",{class:!0});var fs=i(bt);_t=n(fs,"A",{id:!0,class:!0,href:!0});var oo=i(_t);Ma=n(oo,"SPAN",{});var ro=i(Ma);k(xt.$$.fragment,ro),ro.forEach(a),oo.forEach(a),Ds=y(fs),ga=n(fs,"SPAN",{});var no=i(ga);Ls=l(no,"Evaluate"),no.forEach(a),fs.forEach(a),Ia=y(e),at=n(e,"P",{});var Ct=i(at);Os=l(Ct,"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} "),Xt=n(Ct,"A",{href:!0,rel:!0});var io=i(Xt);Ks=l(io,"Evaluate"),io.forEach(a),el=l(Ct," library. For this task, load the "),zt=n(Ct,"A",{href:!0,rel:!0});var co=i(zt);tl=l(co,"ROUGE"),co.forEach(a),al=l(Ct," metric (see the \u{1F917} Evaluate "),It=n(Ct,"A",{href:!0,rel:!0});var po=i(It);sl=l(po,"quick tour"),po.forEach(a),ll=l(Ct," to learn more about how to load and compute a metric):"),Ct.forEach(a),Fa=y(e),k(Ft.$$.fragment,e),Na=y(e),jt=n(e,"P",{});var us=i(jt);ol=l(us,"Then create a function that passes your predictions and labels to "),Nt=n(us,"A",{href:!0,rel:!0});var ho=i(Nt);rl=l(ho,"compute"),ho.forEach(a),nl=l(us," to calculate the ROUGE metric:"),us.forEach(a),qa=y(e),k(qt.$$.fragment,e),Ya=y(e),vt=n(e,"P",{});var ds=i(vt);il=l(ds,"Your "),wa=n(ds,"CODE",{});var mo=i(wa);cl=l(mo,"compute_metrics"),mo.forEach(a),pl=l(ds," function is ready to go now, and you\u2019ll return to it when you setup your training."),ds.forEach(a),Ha=y(e),Mt=n(e,"H2",{class:!0});var ys=i(Mt);kt=n(ys,"A",{id:!0,class:!0,href:!0});var fo=i(kt);$a=n(fo,"SPAN",{});var uo=i($a);k(Yt.$$.fragment,uo),uo.forEach(a),fo.forEach(a),hl=y(ys),_a=n(ys,"SPAN",{});var yo=i(_a);ml=l(yo,"Train"),yo.forEach(a),ys.forEach(a),Qa=y(e),k(Tt.$$.fragment,e),Pa=y(e),k(Ut.$$.fragment,e),Da=y(e),gt=n(e,"H2",{class:!0});var bs=i(gt);Et=n(bs,"A",{id:!0,class:!0,href:!0});var bo=i(Et);ja=n(bo,"SPAN",{});var Mo=i(ja);k(Ht.$$.fragment,Mo),Mo.forEach(a),bo.forEach(a),fl=y(bs),va=n(bs,"SPAN",{});var go=i(va);ul=l(go,"Inference"),go.forEach(a),bs.forEach(a),La=y(e),Kt=n(e,"P",{});var wo=i(Kt);dl=l(wo,"Great, now that you\u2019ve finetuned a model, you can use it for inference!"),wo.forEach(a),Oa=y(e),ea=n(e,"P",{});var $o=i(ea);yl=l($o,"Come up with some text you\u2019d like to summarize. For T5, you need to prefix your input depending on the task you\u2019re working on. For summarization you should prefix your input as shown below:"),$o.forEach(a),Ka=y(e),k(Qt.$$.fragment,e),es=y(e),ct=n(e,"P",{});var ra=i(ct);bl=l(ra,"The simplest way to try out your finetuned model for inference is to use it in a "),ta=n(ra,"A",{href:!0});var _o=i(ta);Ml=l(_o,"pipeline()"),_o.forEach(a),gl=l(ra,". Instantiate a "),ka=n(ra,"CODE",{});var jo=i(ka);wl=l(jo,"pipeline"),jo.forEach(a),$l=l(ra," for summarization with your model, and pass your text to it:"),ra.forEach(a),ts=y(e),k(Pt.$$.fragment,e),as=y(e),Jt=n(e,"P",{});var Ms=i(Jt);_l=l(Ms,"You can also manually replicate the results of the "),Ta=n(Ms,"CODE",{});var vo=i(Ta);jl=l(vo,"pipeline"),vo.forEach(a),vl=l(Ms," if you\u2019d like:"),Ms.forEach(a),ss=y(e),k(Zt.$$.fragment,e),this.h()},h(){b(p,"name","hf:doc:metadata"),b(p,"content",JSON.stringify(Po)),b(M,"id","summarization"),b(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"),b(M,"href","#summarization"),b(c,"class","relative group"),b(D,"href","https://huggingface.co/t5-small"),b(D,"rel","nofollow"),b(Te,"href","https://huggingface.co/datasets/billsum"),b(Te,"rel","nofollow"),b(re,"id","load-billsum-dataset"),b(re,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),b(re,"href","#load-billsum-dataset"),b(oe,"class","relative group"),b(_e,"href","https://huggingface.co/docs/datasets/v2.14.4/en/package_reference/main_classes#datasets.Dataset.train_test_split"),b(_e,"rel","nofollow"),b(st,"id","preprocess"),b(st,"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"),b(st,"href","#preprocess"),b(et,"class","relative group"),b(St,"href","https://huggingface.co/docs/datasets/v2.14.4/en/package_reference/main_classes#datasets.Dataset.map"),b(St,"rel","nofollow"),b(Ot,"href","/docs/transformers/v4.33.0/en/main_classes/data_collator#transformers.DataCollatorForSeq2Seq"),b(_t,"id","evaluate"),b(_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"),b(_t,"href","#evaluate"),b(bt,"class","relative group"),b(Xt,"href","https://huggingface.co/docs/evaluate/index"),b(Xt,"rel","nofollow"),b(zt,"href","https://huggingface.co/spaces/evaluate-metric/rouge"),b(zt,"rel","nofollow"),b(It,"href","https://huggingface.co/docs/evaluate/a_quick_tour"),b(It,"rel","nofollow"),b(Nt,"href","https://huggingface.co/docs/evaluate/v0.4.0/en/package_reference/main_classes#evaluate.EvaluationModule.compute"),b(Nt,"rel","nofollow"),b(kt,"id","train"),b(kt,"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"),b(kt,"href","#train"),b(Mt,"class","relative group"),b(Et,"id","inference"),b(Et,"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"),b(Et,"href","#inference"),b(gt,"class","relative group"),b(ta,"href","/docs/transformers/v4.33.0/en/main_classes/pipelines#transformers.pipeline")},m(e,f){t(document.head,p),h(e,m,f),h(e,c,f),t(c,M),t(M,w),T(j,w,null),t(c,G),t(c,S),t(S,$),h(e,V,f),T(C,e,f),h(e,X,f),T(x,e,f),h(e,A,f),h(e,W,f),t(W,ie),h(e,P,f),h(e,R,f),t(R,O),t(O,q),t(R,K),t(R,Y),t(Y,z),h(e,I,f),h(e,u,f),t(u,_),h(e,ee,f),h(e,F,f),t(F,te),t(te,H),t(te,D),t(D,ke),t(te,ce),t(te,Te),t(Te,ge),t(te,Ge),t(F,Xe),t(F,Ce),t(Ce,L),h(e,Se,f),T(se,e,f),h(e,Ue,f),h(e,Ve,f),t(Ve,Ee),h(e,pe,f),T(we,e,f),h(e,fe,f),h(e,le,f),t(le,Je),h(e,de,f),T(ue,e,f),h(e,$e,f),h(e,oe,f),t(oe,re),t(re,g),T(B,g,null),t(oe,ye),t(oe,Ze),t(Ze,Be),h(e,ae,f),h(e,be,f),t(be,ze),h(e,he,f),T(Re,e,f),h(e,me,f),h(e,ne,f),t(ne,Ie),t(ne,_e),t(_e,We),t(ne,je),h(e,Ae,f),T(Me,e,f),h(e,De,f),h(e,ve,f),t(ve,o),h(e,Z,f),T(xe,e,f),h(e,Fe,f),h(e,Le,f),t(Le,pt),h(e,Oe,f),h(e,Ne,f),t(Ne,Ke),t(Ke,Ye),t(Ye,ht),t(Ke,He),t(Ne,mt),t(Ne,qe),t(qe,Qe),t(Qe,ft),t(qe,ut),t(qe,Pe),t(Pe,dt),t(qe,yt),h(e,lt,f),h(e,et,f),t(et,st),t(st,wt),T(ot,wt,null),t(et,$s),t(et,ca),t(ca,_s),h(e,Ca,f),h(e,rt,f),t(rt,js),t(rt,pa),t(pa,vs),t(rt,ks),t(rt,ha),t(ha,Ts),t(rt,Us),h(e,Va,f),T(Vt,e,f),h(e,Ba,f),h(e,Lt,f),t(Lt,Es),h(e,Ra,f),h(e,nt,f),t(nt,ma),t(ma,Js),t(nt,Zs),t(nt,Bt),t(Bt,Gs),t(Bt,fa),t(fa,Cs),t(Bt,Vs),t(nt,Bs),t(nt,Rt),t(Rt,Rs),t(Rt,ua),t(ua,Ws),t(Rt,Ss),h(e,Wa,f),T(Wt,e,f),h(e,Sa,f),h(e,tt,f),t(tt,As),t(tt,St),t(St,xs),t(tt,Xs),t(tt,da),t(da,zs),t(tt,Is),t(tt,ya),t(ya,Fs),t(tt,Ns),h(e,Aa,f),T(At,e,f),h(e,xa,f),h(e,it,f),t(it,qs),t(it,Ot),t(Ot,Ys),t(it,Hs),t(it,ba),t(ba,Qs),t(it,Ps),h(e,Xa,f),T($t,e,f),h(e,za,f),h(e,bt,f),t(bt,_t),t(_t,Ma),T(xt,Ma,null),t(bt,Ds),t(bt,ga),t(ga,Ls),h(e,Ia,f),h(e,at,f),t(at,Os),t(at,Xt),t(Xt,Ks),t(at,el),t(at,zt),t(zt,tl),t(at,al),t(at,It),t(It,sl),t(at,ll),h(e,Fa,f),T(Ft,e,f),h(e,Na,f),h(e,jt,f),t(jt,ol),t(jt,Nt),t(Nt,rl),t(jt,nl),h(e,qa,f),T(qt,e,f),h(e,Ya,f),h(e,vt,f),t(vt,il),t(vt,wa),t(wa,cl),t(vt,pl),h(e,Ha,f),h(e,Mt,f),t(Mt,kt),t(kt,$a),T(Yt,$a,null),t(Mt,hl),t(Mt,_a),t(_a,ml),h(e,Qa,f),T(Tt,e,f),h(e,Pa,f),T(Ut,e,f),h(e,Da,f),h(e,gt,f),t(gt,Et),t(Et,ja),T(Ht,ja,null),t(gt,fl),t(gt,va),t(va,ul),h(e,La,f),h(e,Kt,f),t(Kt,dl),h(e,Oa,f),h(e,ea,f),t(ea,yl),h(e,Ka,f),T(Qt,e,f),h(e,es,f),h(e,ct,f),t(ct,bl),t(ct,ta),t(ta,Ml),t(ct,gl),t(ct,ka),t(ka,wl),t(ct,$l),h(e,ts,f),T(Pt,e,f),h(e,as,f),h(e,Jt,f),t(Jt,_l),t(Jt,Ta),t(Ta,jl),t(Jt,vl),h(e,ss,f),T(Zt,e,f),ls=!0},p(e,[f]){const Dt={};f&2&&(Dt.$$scope={dirty:f,ctx:e}),se.$set(Dt);const Ua={};f&2&&(Ua.$$scope={dirty:f,ctx:e}),$t.$set(Ua);const Ea={};f&2&&(Ea.$$scope={dirty:f,ctx:e}),Tt.$set(Ea);const Ja={};f&2&&(Ja.$$scope={dirty:f,ctx:e}),Ut.$set(Ja);const Za={};f&2&&(Za.$$scope={dirty:f,ctx:e}),Zt.$set(Za)},i(e){ls||(U(j.$$.fragment,e),U(C.$$.fragment,e),U(x.$$.fragment,e),U(se.$$.fragment,e),U(we.$$.fragment,e),U(ue.$$.fragment,e),U(B.$$.fragment,e),U(Re.$$.fragment,e),U(Me.$$.fragment,e),U(xe.$$.fragment,e),U(ot.$$.fragment,e),U(Vt.$$.fragment,e),U(Wt.$$.fragment,e),U(At.$$.fragment,e),U($t.$$.fragment,e),U(xt.$$.fragment,e),U(Ft.$$.fragment,e),U(qt.$$.fragment,e),U(Yt.$$.fragment,e),U(Tt.$$.fragment,e),U(Ut.$$.fragment,e),U(Ht.$$.fragment,e),U(Qt.$$.fragment,e),U(Pt.$$.fragment,e),U(Zt.$$.fragment,e),ls=!0)},o(e){E(j.$$.fragment,e),E(C.$$.fragment,e),E(x.$$.fragment,e),E(se.$$.fragment,e),E(we.$$.fragment,e),E(ue.$$.fragment,e),E(B.$$.fragment,e),E(Re.$$.fragment,e),E(Me.$$.fragment,e),E(xe.$$.fragment,e),E(ot.$$.fragment,e),E(Vt.$$.fragment,e),E(Wt.$$.fragment,e),E(At.$$.fragment,e),E($t.$$.fragment,e),E(xt.$$.fragment,e),E(Ft.$$.fragment,e),E(qt.$$.fragment,e),E(Yt.$$.fragment,e),E(Tt.$$.fragment,e),E(Ut.$$.fragment,e),E(Ht.$$.fragment,e),E(Qt.$$.fragment,e),E(Pt.$$.fragment,e),E(Zt.$$.fragment,e),ls=!1},d(e){a(p),e&&a(m),e&&a(c),J(j),e&&a(V),J(C,e),e&&a(X),J(x,e),e&&a(A),e&&a(W),e&&a(P),e&&a(R),e&&a(I),e&&a(u),e&&a(ee),e&&a(F),e&&a(Se),J(se,e),e&&a(Ue),e&&a(Ve),e&&a(pe),J(we,e),e&&a(fe),e&&a(le),e&&a(de),J(ue,e),e&&a($e),e&&a(oe),J(B),e&&a(ae),e&&a(be),e&&a(he),J(Re,e),e&&a(me),e&&a(ne),e&&a(Ae),J(Me,e),e&&a(De),e&&a(ve),e&&a(Z),J(xe,e),e&&a(Fe),e&&a(Le),e&&a(Oe),e&&a(Ne),e&&a(lt),e&&a(et),J(ot),e&&a(Ca),e&&a(rt),e&&a(Va),J(Vt,e),e&&a(Ba),e&&a(Lt),e&&a(Ra),e&&a(nt),e&&a(Wa),J(Wt,e),e&&a(Sa),e&&a(tt),e&&a(Aa),J(At,e),e&&a(xa),e&&a(it),e&&a(Xa),J($t,e),e&&a(za),e&&a(bt),J(xt),e&&a(Ia),e&&a(at),e&&a(Fa),J(Ft,e),e&&a(Na),e&&a(jt),e&&a(qa),J(qt,e),e&&a(Ya),e&&a(vt),e&&a(Ha),e&&a(Mt),J(Yt),e&&a(Qa),J(Tt,e),e&&a(Pa),J(Ut,e),e&&a(Da),e&&a(gt),J(Ht),e&&a(La),e&&a(Kt),e&&a(Oa),e&&a(ea),e&&a(Ka),J(Qt,e),e&&a(es),e&&a(ct),e&&a(ts),J(Pt,e),e&&a(as),e&&a(Jt),e&&a(ss),J(Zt,e)}}}const Po={local:"summarization",sections:[{local:"load-billsum-dataset",title:"Load BillSum dataset"},{local:"preprocess",title:"Preprocess"},{local:"evaluate",title:"Evaluate"},{local:"train",title:"Train"},{local:"inference",title:"Inference"}],title:"Summarization"};function Do(N){return Jo(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class lr extends ko{constructor(p){super();To(this,p,Do,Qo,Uo,{})}}export{lr as default,Po as metadata};
