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

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

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

	`),k(n.$$.fragment),M=d(),$=o("p"),v=s("Then you can load T5 with "),C=o("a"),x=s("TFAutoModelForSeq2SeqLM"),_=s(":"),B=d(),k(V.$$.fragment),z=d(),X=o("p"),A=s("Convert your datasets to the "),S=o("code"),ce=s("tf.data.Dataset"),D=s(" format with "),W=o("a"),K=s("prepare_tf_dataset()"),Y=s(":"),ee=d(),k(H.$$.fragment),I=d(),F=o("p"),u=s("Configure the model for training with "),j=o("a"),te=o("code"),N=s("compile"),ae=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:"),Q=d(),k(L.$$.fragment),ke=d(),pe=o("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 "),we=o("a"),Ge=s("Keras callbacks"),Ae=s("."),Ce=d(),O=o("p"),Se=s("Pass your "),le=o("code"),Ue=s("compute_metrics"),Ve=s(" function to "),Ee=o("a"),he=s("KerasMetricCallback"),$e=s(":"),ue=d(),k(oe.$$.fragment),Je=d(),ye=o("p"),de=s("Specify where to push your model and tokenizer in the "),_e=o("a"),re=s("PushToHubCallback"),ne=s(":"),g=d(),k(R.$$.fragment),be=d(),Ze=o("p"),Be=s("Then bundle your callbacks together:"),se=d(),k(Me.$$.fragment),Xe=d(),me=o("p"),Re=s("Finally, you\u2019re ready to start training your model! Call "),fe=o("a"),ie=o("code"),ze=s("fit"),je=s(" with your training and validation datasets, the number of epochs, and your callbacks to finetune the model:"),We=d(),k(ve.$$.fragment),ge=d(),w=o("p"),tt=s("Once training is completed, your model is automatically uploaded to the Hub so everyone can use it!"),this.h()},l(p){T(c.$$.fragment,p),m=l(p,`
To finetune a model in TensorFlow, start by setting up an optimizer function, learning rate schedule, and some training hyperparameters:

	`),T(n.$$.fragment,p),M=y(p),$=r(p,"P",{});var G=i($);v=l(G,"Then you can load T5 with "),C=r(G,"A",{href:!0});var xe=i(C);x=l(xe,"TFAutoModelForSeq2SeqLM"),xe.forEach(a),_=l(G,":"),G.forEach(a),B=y(p),T(V.$$.fragment,p),z=y(p),X=r(p,"P",{});var Fe=i(X);A=l(Fe,"Convert your datasets to the "),S=r(Fe,"CODE",{});var De=i(S);ce=l(De,"tf.data.Dataset"),De.forEach(a),D=l(Fe," format with "),W=r(Fe,"A",{href:!0});var nt=i(W);K=l(nt,"prepare_tf_dataset()"),nt.forEach(a),Y=l(Fe,":"),Fe.forEach(a),ee=y(p),T(H.$$.fragment,p),I=y(p),F=r(p,"P",{});var Le=i(F);u=l(Le,"Configure the model for training with "),j=r(Le,"A",{href:!0,rel:!0});var Ne=i(j);te=r(Ne,"CODE",{});var Oe=i(te);N=l(Oe,"compile"),Oe.forEach(a),Ne.forEach(a),ae=l(Le,". Note that Transformers models all have a default task-relevant loss function, so you don\u2019t need to specify one unless you want to:"),Le.forEach(a),Q=y(p),T(L.$$.fragment,p),ke=y(p),pe=r(p,"P",{});var Ye=i(pe);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 "),we=r(Ye,"A",{href:!0});var it=i(we);Ge=l(it,"Keras callbacks"),it.forEach(a),Ae=l(Ye,"."),Ye.forEach(a),Ce=y(p),O=r(p,"P",{});var He=i(O);Se=l(He,"Pass your "),le=r(He,"CODE",{});var ct=i(le);Ue=l(ct,"compute_metrics"),ct.forEach(a),Ve=l(He," function to "),Ee=r(He,"A",{href:!0});var qe=i(Ee);he=l(qe,"KerasMetricCallback"),qe.forEach(a),$e=l(He,":"),He.forEach(a),ue=y(p),T(oe.$$.fragment,p),Je=y(p),ye=r(p,"P",{});var Qe=i(ye);de=l(Qe,"Specify where to push your model and tokenizer in the "),_e=r(Qe,"A",{href:!0});var pt=i(_e);re=l(pt,"PushToHubCallback"),pt.forEach(a),ne=l(Qe,":"),Qe.forEach(a),g=y(p),T(R.$$.fragment,p),be=y(p),Ze=r(p,"P",{});var ht=i(Ze);Be=l(ht,"Then bundle your callbacks together:"),ht.forEach(a),se=y(p),T(Me.$$.fragment,p),Xe=y(p),me=r(p,"P",{});var Pe=i(me);Re=l(Pe,"Finally, you\u2019re ready to start training your model! Call "),fe=r(Pe,"A",{href:!0,rel:!0});var mt=i(fe);ie=r(mt,"CODE",{});var ft=i(ie);ze=l(ft,"fit"),ft.forEach(a),mt.forEach(a),je=l(Pe," with your training and validation datasets, the number of epochs, and your callbacks to finetune the model:"),Pe.forEach(a),We=y(p),T(ve.$$.fragment,p),ge=y(p),w=r(p,"P",{});var at=i(w);tt=l(at,"Once training is completed, your model is automatically uploaded to the Hub so everyone can use it!"),at.forEach(a),this.h()},h(){b(C,"href","/docs/transformers/v4.30.0/en/model_doc/auto#transformers.TFAutoModelForSeq2SeqLM"),b(W,"href","/docs/transformers/v4.30.0/en/main_classes/model#transformers.TFPreTrainedModel.prepare_tf_dataset"),b(j,"href","https://keras.io/api/models/model_training_apis/#compile-method"),b(j,"rel","nofollow"),b(we,"href","../main_classes/keras_callbacks"),b(Ee,"href","/docs/transformers/v4.30.0/en/main_classes/keras_callbacks#transformers.KerasMetricCallback"),b(_e,"href","/docs/transformers/v4.30.0/en/main_classes/keras_callbacks#transformers.PushToHubCallback"),b(fe,"href","https://keras.io/api/models/model_training_apis/#fit-method"),b(fe,"rel","nofollow")},m(p,G){U(c,p,G),h(p,m,G),U(n,p,G),h(p,M,G),h(p,$,G),t($,v),t($,C),t(C,x),t($,_),h(p,B,G),U(V,p,G),h(p,z,G),h(p,X,G),t(X,A),t(X,S),t(S,ce),t(X,D),t(X,W),t(W,K),t(X,Y),h(p,ee,G),U(H,p,G),h(p,I,G),h(p,F,G),t(F,u),t(F,j),t(j,te),t(te,N),t(F,ae),h(p,Q,G),U(L,p,G),h(p,ke,G),h(p,pe,G),t(pe,Te),t(pe,we),t(we,Ge),t(pe,Ae),h(p,Ce,G),h(p,O,G),t(O,Se),t(O,le),t(le,Ue),t(O,Ve),t(O,Ee),t(Ee,he),t(O,$e),h(p,ue,G),U(oe,p,G),h(p,Je,G),h(p,ye,G),t(ye,de),t(ye,_e),t(_e,re),t(ye,ne),h(p,g,G),U(R,p,G),h(p,be,G),h(p,Ze,G),t(Ze,Be),h(p,se,G),U(Me,p,G),h(p,Xe,G),h(p,me,G),t(me,Re),t(me,fe),t(fe,ie),t(ie,ze),t(me,je),h(p,We,G),U(ve,p,G),h(p,ge,G),h(p,w,G),t(w,tt),Ie=!0},p(p,G){const xe={};G&2&&(xe.$$scope={dirty:G,ctx:p}),c.$set(xe)},i(p){Ie||(E(c.$$.fragment,p),E(n.$$.fragment,p),E(V.$$.fragment,p),E(H.$$.fragment,p),E(L.$$.fragment,p),E(oe.$$.fragment,p),E(R.$$.fragment,p),E(Me.$$.fragment,p),E(ve.$$.fragment,p),Ie=!0)},o(p){J(c.$$.fragment,p),J(n.$$.fragment,p),J(V.$$.fragment,p),J(H.$$.fragment,p),J(L.$$.fragment,p),J(oe.$$.fragment,p),J(R.$$.fragment,p),J(Me.$$.fragment,p),J(ve.$$.fragment,p),Ie=!1},d(p){Z(c,p),p&&a(m),Z(n,p),p&&a(M),p&&a($),p&&a(B),Z(V,p),p&&a(z),p&&a(X),p&&a(ee),Z(H,p),p&&a(I),p&&a(F),p&&a(Q),Z(L,p),p&&a(ke),p&&a(pe),p&&a(Ce),p&&a(O),p&&a(ue),Z(oe,p),p&&a(Je),p&&a(ye),p&&a(g),Z(R,p),p&&a(be),p&&a(Ze),p&&a(se),Z(Me,p),p&&a(Xe),p&&a(me),p&&a(We),Z(ve,p),p&&a(ge),p&&a(w)}}}function Io(q){let c,m;return c=new na({props:{$$slots:{default:[zo]},$$scope:{ctx:q}}}),{c(){k(c.$$.fragment)},l(n){T(c.$$.fragment,n)},m(n,M){U(c,n,M),m=!0},p(n,M){const $={};M&2&&($.$$scope={dirty:M,ctx:n}),c.$set($)},i(n){m||(E(c.$$.fragment,n),m=!0)},o(n){J(c.$$.fragment,n),m=!1},d(n){Z(c,n)}}}function Fo(q){let c,m,n,M,$,v,C,x;return{c(){c=o("p"),m=s(`For a more in-depth example of how to finetune a model for summarization, take a look at the corresponding
`),n=o("a"),M=s("PyTorch notebook"),$=s(`
or `),v=o("a"),C=s("TensorFlow notebook"),x=s("."),this.h()},l(_){c=r(_,"P",{});var B=i(c);m=l(B,`For a more in-depth example of how to finetune a model for summarization, take a look at the corresponding
`),n=r(B,"A",{href:!0,rel:!0});var V=i(n);M=l(V,"PyTorch notebook"),V.forEach(a),$=l(B,`
or `),v=r(B,"A",{href:!0,rel:!0});var z=i(v);C=l(z,"TensorFlow notebook"),z.forEach(a),x=l(B,"."),B.forEach(a),this.h()},h(){b(n,"href","https://colab.research.google.com/github/huggingface/notebooks/blob/main/examples/summarization.ipynb"),b(n,"rel","nofollow"),b(v,"href","https://colab.research.google.com/github/huggingface/notebooks/blob/main/examples/summarization-tf.ipynb"),b(v,"rel","nofollow")},m(_,B){h(_,c,B),t(c,m),t(c,n),t(n,M),t(c,$),t(c,v),t(v,C),t(c,x)},d(_){_&&a(c)}}}function No(q){let c,m,n,M,$,v,C,x,_,B,V,z,X,A,S,ce,D,W,K,Y,ee,H,I,F;return C=new P({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`}}),W=new P({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>)`}}),I=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;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(){c=o("p"),m=s("Tokenize the text and return the "),n=o("code"),M=s("input_ids"),$=s(" as PyTorch tensors:"),v=d(),k(C.$$.fragment),x=d(),_=o("p"),B=s("Use the "),V=o("a"),z=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=o("a"),S=s("Text Generation"),ce=s(" API."),D=d(),k(W.$$.fragment),K=d(),Y=o("p"),ee=s("Decode the generated token ids back into text:"),H=d(),k(I.$$.fragment),this.h()},l(u){c=r(u,"P",{});var j=i(c);m=l(j,"Tokenize the text and return the "),n=r(j,"CODE",{});var te=i(n);M=l(te,"input_ids"),te.forEach(a),$=l(j," as PyTorch tensors:"),j.forEach(a),v=y(u),T(C.$$.fragment,u),x=y(u),_=r(u,"P",{});var N=i(_);B=l(N,"Use the "),V=r(N,"A",{href:!0});var ae=i(V);z=l(ae,"generate()"),ae.forEach(a),X=l(N," method to create the summarization. For more details about the different text generation strategies and parameters for controlling generation, check out the "),A=r(N,"A",{href:!0});var Q=i(A);S=l(Q,"Text Generation"),Q.forEach(a),ce=l(N," API."),N.forEach(a),D=y(u),T(W.$$.fragment,u),K=y(u),Y=r(u,"P",{});var L=i(Y);ee=l(L,"Decode the generated token ids back into text:"),L.forEach(a),H=y(u),T(I.$$.fragment,u),this.h()},h(){b(V,"href","/docs/transformers/v4.30.0/en/main_classes/text_generation#transformers.GenerationMixin.generate"),b(A,"href","../main_classes/text_generation")},m(u,j){h(u,c,j),t(c,m),t(c,n),t(n,M),t(c,$),h(u,v,j),U(C,u,j),h(u,x,j),h(u,_,j),t(_,B),t(_,V),t(V,z),t(_,X),t(_,A),t(A,S),t(_,ce),h(u,D,j),U(W,u,j),h(u,K,j),h(u,Y,j),t(Y,ee),h(u,H,j),U(I,u,j),F=!0},p:ws,i(u){F||(E(C.$$.fragment,u),E(W.$$.fragment,u),E(I.$$.fragment,u),F=!0)},o(u){J(C.$$.fragment,u),J(W.$$.fragment,u),J(I.$$.fragment,u),F=!1},d(u){u&&a(c),u&&a(v),Z(C,u),u&&a(x),u&&a(_),u&&a(D),Z(W,u),u&&a(K),u&&a(Y),u&&a(H),Z(I,u)}}}function qo(q){let c,m;return c=new na({props:{$$slots:{default:[No]},$$scope:{ctx:q}}}),{c(){k(c.$$.fragment)},l(n){T(c.$$.fragment,n)},m(n,M){U(c,n,M),m=!0},p(n,M){const $={};M&2&&($.$$scope={dirty:M,ctx:n}),c.$set($)},i(n){m||(E(c.$$.fragment,n),m=!0)},o(n){J(c.$$.fragment,n),m=!1},d(n){Z(c,n)}}}function Yo(q){let c,m,n,M,$,v,C,x,_,B,V,z,X,A,S,ce,D,W,K,Y,ee,H,I,F;return C=new P({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`}}),W=new P({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>)`}}),I=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;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(){c=o("p"),m=s("Tokenize the text and return the "),n=o("code"),M=s("input_ids"),$=s(" as TensorFlow tensors:"),v=d(),k(C.$$.fragment),x=d(),_=o("p"),B=s("Use the "),V=o("a"),z=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=o("a"),S=s("Text Generation"),ce=s(" API."),D=d(),k(W.$$.fragment),K=d(),Y=o("p"),ee=s("Decode the generated token ids back into text:"),H=d(),k(I.$$.fragment),this.h()},l(u){c=r(u,"P",{});var j=i(c);m=l(j,"Tokenize the text and return the "),n=r(j,"CODE",{});var te=i(n);M=l(te,"input_ids"),te.forEach(a),$=l(j," as TensorFlow tensors:"),j.forEach(a),v=y(u),T(C.$$.fragment,u),x=y(u),_=r(u,"P",{});var N=i(_);B=l(N,"Use the "),V=r(N,"A",{href:!0});var ae=i(V);z=l(ae,"generate()"),ae.forEach(a),X=l(N," method to create the summarization. For more details about the different text generation strategies and parameters for controlling generation, check out the "),A=r(N,"A",{href:!0});var Q=i(A);S=l(Q,"Text Generation"),Q.forEach(a),ce=l(N," API."),N.forEach(a),D=y(u),T(W.$$.fragment,u),K=y(u),Y=r(u,"P",{});var L=i(Y);ee=l(L,"Decode the generated token ids back into text:"),L.forEach(a),H=y(u),T(I.$$.fragment,u),this.h()},h(){b(V,"href","/docs/transformers/v4.30.0/en/main_classes/text_generation#transformers.TFGenerationMixin.generate"),b(A,"href","../main_classes/text_generation")},m(u,j){h(u,c,j),t(c,m),t(c,n),t(n,M),t(c,$),h(u,v,j),U(C,u,j),h(u,x,j),h(u,_,j),t(_,B),t(_,V),t(V,z),t(_,X),t(_,A),t(A,S),t(_,ce),h(u,D,j),U(W,u,j),h(u,K,j),h(u,Y,j),t(Y,ee),h(u,H,j),U(I,u,j),F=!0},p:ws,i(u){F||(E(C.$$.fragment,u),E(W.$$.fragment,u),E(I.$$.fragment,u),F=!0)},o(u){J(C.$$.fragment,u),J(W.$$.fragment,u),J(I.$$.fragment,u),F=!1},d(u){u&&a(c),u&&a(v),Z(C,u),u&&a(x),u&&a(_),u&&a(D),Z(W,u),u&&a(K),u&&a(Y),u&&a(H),Z(I,u)}}}function Ho(q){let c,m;return c=new na({props:{$$slots:{default:[Yo]},$$scope:{ctx:q}}}),{c(){k(c.$$.fragment)},l(n){T(c.$$.fragment,n)},m(n,M){U(c,n,M),m=!0},p(n,M){const $={};M&2&&($.$$scope={dirty:M,ctx:n}),c.$set($)},i(n){m||(E(c.$$.fragment,n),m=!0)},o(n){J(c.$$.fragment,n),m=!1},d(n){Z(c,n)}}}function Qo(q){let c,m,n,M,$,v,C,x,_,B,V,z,X,A,S,ce,D,W,K,Y,ee,H,I,F,u,j,te,N,ae,Q,L,ke,pe,Te,we,Ge,Ae,Ce,O,Se,le,Ue,Ve,Ee,he,$e,ue,oe,Je,ye,de,_e,re,ne,g,R,be,Ze,Be,se,Me,Xe,me,Re,fe,ie,ze,je,We,ve,ge,w,tt,Ie,p,G,xe,Fe,De,nt,Le,Ne,Oe,Ye,it,He,ct,qe,Qe,pt,ht,Pe,mt,ft,at,ut,Mt,ia,Gt,$s,ca,_s,Ca,st,js,pa,vs,ks,ha,Ts,Us,Va,Ct,Ba,Dt,Es,Ra,lt,ma,Js,Zs,Vt,Gs,fa,Cs,Vs,Bs,Bt,Rs,ua,Ws,Ss,Wa,Rt,Sa,Ke,xs,Wt,As,Xs,da,zs,Is,ya,Fs,Ns,xa,St,Aa,ot,qs,Lt,Ys,Hs,ba,Qs,Ps,Xa,gt,za,dt,wt,Ma,xt,Ds,ga,Ls,Ia,et,Os,At,Ks,el,Xt,tl,al,zt,sl,ll,Fa,It,Na,$t,ol,Ft,rl,nl,qa,Nt,Ya,_t,il,wa,cl,pl,Ha,yt,jt,$a,qt,hl,_a,ml,Qa,vt,Pa,kt,Da,bt,Tt,ja,Yt,fl,va,ul,La,Ot,dl,Oa,Kt,yl,Ka,Ht,es,rt,bl,ea,Ml,gl,ka,wl,$l,ts,Qt,as,Ut,_l,Ta,jl,vl,ss,Et,ls;return v=new ra({}),V=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"}}),le=new gs({props:{$$slots:{default:[Co]},$$scope:{ctx:q}}}),$e=new P({props:{code:"cGlwJTIwaW5zdGFsbCUyMHRyYW5zZm9ybWVycyUyMGRhdGFzZXRzJTIwZXZhbHVhdGUlMjByb3VnZV9zY29yZQ==",highlighted:"pip install transformers datasets evaluate rouge_score"}}),de=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()`}}),R=new ra({}),Re=new P({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>)`}}),w=new P({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 P({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>}`}}),Gt=new ra({}),Ct=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)`}}),Rt=new P({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`}}),St=new P({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>)'}}),gt=new Tl({props:{pytorch:!0,tensorflow:!0,jax:!1,$$slots:{tensorflow:[Wo],pytorch:[Bo]},$$scope:{ctx:q}}}),xt=new ra({}),It=new P({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>)`}}),Nt=new P({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()}`}}),qt=new ra({}),vt=new Tl({props:{pytorch:!0,tensorflow:!0,jax:!1,$$slots:{tensorflow:[Io],pytorch:[Ao]},$$scope:{ctx:q}}}),kt=new gs({props:{$$slots:{default:[Fo]},$$scope:{ctx:q}}}),Yt=new ra({}),Ht=new P({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>'}}),Qt=new P({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>}]`}}),Et=new Tl({props:{pytorch:!0,tensorflow:!0,jax:!1,$$slots:{tensorflow:[Ho],pytorch:[qo]},$$scope:{ctx:q}}}),{c(){c=o("meta"),m=d(),n=o("h1"),M=o("a"),$=o("span"),k(v.$$.fragment),C=d(),x=o("span"),_=s("Summarization"),B=d(),k(V.$$.fragment),z=d(),k(X.$$.fragment),A=d(),S=o("p"),ce=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:"),D=d(),W=o("ul"),K=o("li"),Y=s("Extractive: extract the most relevant information from a document."),ee=d(),H=o("li"),I=s("Abstractive: generate new text that captures the most relevant information."),F=d(),u=o("p"),j=s("This guide will show you how to:"),te=d(),N=o("ol"),ae=o("li"),Q=s("Finetune "),L=o("a"),ke=s("T5"),pe=s(" on the California state bill subset of the "),Te=o("a"),we=s("BillSum"),Ge=s(" dataset for abstractive summarization."),Ae=d(),Ce=o("li"),O=s("Use your finetuned model for inference."),Se=d(),k(le.$$.fragment),Ue=d(),Ve=o("p"),Ee=s("Before you begin, make sure you have all the necessary libraries installed:"),he=d(),k($e.$$.fragment),ue=d(),oe=o("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:"),ye=d(),k(de.$$.fragment),_e=d(),re=o("h2"),ne=o("a"),g=o("span"),k(R.$$.fragment),be=d(),Ze=o("span"),Be=s("Load BillSum dataset"),se=d(),Me=o("p"),Xe=s("Start by loading the smaller California state bill subset of the BillSum dataset from the \u{1F917} Datasets library:"),me=d(),k(Re.$$.fragment),fe=d(),ie=o("p"),ze=s("Split the dataset into a train and test set with the "),je=o("a"),We=s("train_test_split"),ve=s(" method:"),ge=d(),k(w.$$.fragment),tt=d(),Ie=o("p"),p=s("Then take a look at an example:"),G=d(),k(xe.$$.fragment),Fe=d(),De=o("p"),nt=s("There are two fields that you\u2019ll want to use:"),Le=d(),Ne=o("ul"),Oe=o("li"),Ye=o("code"),it=s("text"),He=s(": the text of the bill which\u2019ll be the input to the model."),ct=d(),qe=o("li"),Qe=o("code"),pt=s("summary"),ht=s(": a condensed version of "),Pe=o("code"),mt=s("text"),ft=s(" which\u2019ll be the model target."),at=d(),ut=o("h2"),Mt=o("a"),ia=o("span"),k(Gt.$$.fragment),$s=d(),ca=o("span"),_s=s("Preprocess"),Ca=d(),st=o("p"),js=s("The next step is to load a T5 tokenizer to process "),pa=o("code"),vs=s("text"),ks=s(" and "),ha=o("code"),Ts=s("summary"),Us=s(":"),Va=d(),k(Ct.$$.fragment),Ba=d(),Dt=o("p"),Es=s("The preprocessing function you want to create needs to:"),Ra=d(),lt=o("ol"),ma=o("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(),Vt=o("li"),Gs=s("Use the keyword "),fa=o("code"),Cs=s("text_target"),Vs=s(" argument when tokenizing labels."),Bs=d(),Bt=o("li"),Rs=s("Truncate sequences to be no longer than the maximum length set by the "),ua=o("code"),Ws=s("max_length"),Ss=s(" parameter."),Wa=d(),k(Rt.$$.fragment),Sa=d(),Ke=o("p"),xs=s("To apply the preprocessing function over the entire dataset, use \u{1F917} Datasets "),Wt=o("a"),As=s("map"),Xs=s(" method. You can speed up the "),da=o("code"),zs=s("map"),Is=s(" function by setting "),ya=o("code"),Fs=s("batched=True"),Ns=s(" to process multiple elements of the dataset at once:"),xa=d(),k(St.$$.fragment),Aa=d(),ot=o("p"),qs=s("Now create a batch of examples using "),Lt=o("a"),Ys=s("DataCollatorForSeq2Seq"),Hs=s(". It\u2019s more efficient to "),ba=o("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(),k(gt.$$.fragment),za=d(),dt=o("h2"),wt=o("a"),Ma=o("span"),k(xt.$$.fragment),Ds=d(),ga=o("span"),Ls=s("Evaluate"),Ia=d(),et=o("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} "),At=o("a"),Ks=s("Evaluate"),el=s(" library. For this task, load the "),Xt=o("a"),tl=s("ROUGE"),al=s(" metric (see the \u{1F917} Evaluate "),zt=o("a"),sl=s("quick tour"),ll=s(" to learn more about how to load and compute a metric):"),Fa=d(),k(It.$$.fragment),Na=d(),$t=o("p"),ol=s("Then create a function that passes your predictions and labels to "),Ft=o("a"),rl=s("compute"),nl=s(" to calculate the ROUGE metric:"),qa=d(),k(Nt.$$.fragment),Ya=d(),_t=o("p"),il=s("Your "),wa=o("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(),yt=o("h2"),jt=o("a"),$a=o("span"),k(qt.$$.fragment),hl=d(),_a=o("span"),ml=s("Train"),Qa=d(),k(vt.$$.fragment),Pa=d(),k(kt.$$.fragment),Da=d(),bt=o("h2"),Tt=o("a"),ja=o("span"),k(Yt.$$.fragment),fl=d(),va=o("span"),ul=s("Inference"),La=d(),Ot=o("p"),dl=s("Great, now that you\u2019ve finetuned a model, you can use it for inference!"),Oa=d(),Kt=o("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(),k(Ht.$$.fragment),es=d(),rt=o("p"),bl=s("The simplest way to try out your finetuned model for inference is to use it in a "),ea=o("a"),Ml=s("pipeline()"),gl=s(". Instantiate a "),ka=o("code"),wl=s("pipeline"),$l=s(" for summarization with your model, and pass your text to it:"),ts=d(),k(Qt.$$.fragment),as=d(),Ut=o("p"),_l=s("You can also manually replicate the results of the "),Ta=o("code"),jl=s("pipeline"),vl=s(" if you\u2019d like:"),ss=d(),k(Et.$$.fragment),this.h()},l(e){const f=Eo('[data-svelte="svelte-1phssyn"]',document.head);c=r(f,"META",{name:!0,content:!0}),f.forEach(a),m=y(e),n=r(e,"H1",{class:!0});var Pt=i(n);M=r(Pt,"A",{id:!0,class:!0,href:!0});var Ua=i(M);$=r(Ua,"SPAN",{});var Ea=i($);T(v.$$.fragment,Ea),Ea.forEach(a),Ua.forEach(a),C=y(Pt),x=r(Pt,"SPAN",{});var Ja=i(x);_=l(Ja,"Summarization"),Ja.forEach(a),Pt.forEach(a),B=y(e),T(V.$$.fragment,e),z=y(e),T(X.$$.fragment,e),A=y(e),S=r(e,"P",{});var Za=i(S);ce=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),D=y(e),W=r(e,"UL",{});var os=i(W);K=r(os,"LI",{});var Ul=i(K);Y=l(Ul,"Extractive: extract the most relevant information from a document."),Ul.forEach(a),ee=y(os),H=r(os,"LI",{});var El=i(H);I=l(El,"Abstractive: generate new text that captures the most relevant information."),El.forEach(a),os.forEach(a),F=y(e),u=r(e,"P",{});var Jl=i(u);j=l(Jl,"This guide will show you how to:"),Jl.forEach(a),te=y(e),N=r(e,"OL",{});var rs=i(N);ae=r(rs,"LI",{});var ta=i(ae);Q=l(ta,"Finetune "),L=r(ta,"A",{href:!0,rel:!0});var Zl=i(L);ke=l(Zl,"T5"),Zl.forEach(a),pe=l(ta," on the California state bill subset of the "),Te=r(ta,"A",{href:!0,rel:!0});var Gl=i(Te);we=l(Gl,"BillSum"),Gl.forEach(a),Ge=l(ta," dataset for abstractive summarization."),ta.forEach(a),Ae=y(rs),Ce=r(rs,"LI",{});var Cl=i(Ce);O=l(Cl,"Use your finetuned model for inference."),Cl.forEach(a),rs.forEach(a),Se=y(e),T(le.$$.fragment,e),Ue=y(e),Ve=r(e,"P",{});var Vl=i(Ve);Ee=l(Vl,"Before you begin, make sure you have all the necessary libraries installed:"),Vl.forEach(a),he=y(e),T($e.$$.fragment,e),ue=y(e),oe=r(e,"P",{});var Bl=i(oe);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),ye=y(e),T(de.$$.fragment,e),_e=y(e),re=r(e,"H2",{class:!0});var ns=i(re);ne=r(ns,"A",{id:!0,class:!0,href:!0});var Rl=i(ne);g=r(Rl,"SPAN",{});var Wl=i(g);T(R.$$.fragment,Wl),Wl.forEach(a),Rl.forEach(a),be=y(ns),Ze=r(ns,"SPAN",{});var Sl=i(Ze);Be=l(Sl,"Load BillSum dataset"),Sl.forEach(a),ns.forEach(a),se=y(e),Me=r(e,"P",{});var xl=i(Me);Xe=l(xl,"Start by loading the smaller California state bill subset of the BillSum dataset from the \u{1F917} Datasets library:"),xl.forEach(a),me=y(e),T(Re.$$.fragment,e),fe=y(e),ie=r(e,"P",{});var is=i(ie);ze=l(is,"Split the dataset into a train and test set with the "),je=r(is,"A",{href:!0,rel:!0});var Al=i(je);We=l(Al,"train_test_split"),Al.forEach(a),ve=l(is," method:"),is.forEach(a),ge=y(e),T(w.$$.fragment,e),tt=y(e),Ie=r(e,"P",{});var Xl=i(Ie);p=l(Xl,"Then take a look at an example:"),Xl.forEach(a),G=y(e),T(xe.$$.fragment,e),Fe=y(e),De=r(e,"P",{});var zl=i(De);nt=l(zl,"There are two fields that you\u2019ll want to use:"),zl.forEach(a),Le=y(e),Ne=r(e,"UL",{});var cs=i(Ne);Oe=r(cs,"LI",{});var kl=i(Oe);Ye=r(kl,"CODE",{});var Il=i(Ye);it=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),ct=y(cs),qe=r(cs,"LI",{});var Ga=i(qe);Qe=r(Ga,"CODE",{});var Fl=i(Qe);pt=l(Fl,"summary"),Fl.forEach(a),ht=l(Ga,": a condensed version of "),Pe=r(Ga,"CODE",{});var Nl=i(Pe);mt=l(Nl,"text"),Nl.forEach(a),ft=l(Ga," which\u2019ll be the model target."),Ga.forEach(a),cs.forEach(a),at=y(e),ut=r(e,"H2",{class:!0});var ps=i(ut);Mt=r(ps,"A",{id:!0,class:!0,href:!0});var ql=i(Mt);ia=r(ql,"SPAN",{});var Yl=i(ia);T(Gt.$$.fragment,Yl),Yl.forEach(a),ql.forEach(a),$s=y(ps),ca=r(ps,"SPAN",{});var Hl=i(ca);_s=l(Hl,"Preprocess"),Hl.forEach(a),ps.forEach(a),Ca=y(e),st=r(e,"P",{});var aa=i(st);js=l(aa,"The next step is to load a T5 tokenizer to process "),pa=r(aa,"CODE",{});var Ql=i(pa);vs=l(Ql,"text"),Ql.forEach(a),ks=l(aa," and "),ha=r(aa,"CODE",{});var Pl=i(ha);Ts=l(Pl,"summary"),Pl.forEach(a),Us=l(aa,":"),aa.forEach(a),Va=y(e),T(Ct.$$.fragment,e),Ba=y(e),Dt=r(e,"P",{});var Dl=i(Dt);Es=l(Dl,"The preprocessing function you want to create needs to:"),Dl.forEach(a),Ra=y(e),lt=r(e,"OL",{});var sa=i(lt);ma=r(sa,"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(sa),Vt=r(sa,"LI",{});var hs=i(Vt);Gs=l(hs,"Use the keyword "),fa=r(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(sa),Bt=r(sa,"LI",{});var ms=i(Bt);Rs=l(ms,"Truncate sequences to be no longer than the maximum length set by the "),ua=r(ms,"CODE",{});var Kl=i(ua);Ws=l(Kl,"max_length"),Kl.forEach(a),Ss=l(ms," parameter."),ms.forEach(a),sa.forEach(a),Wa=y(e),T(Rt.$$.fragment,e),Sa=y(e),Ke=r(e,"P",{});var Jt=i(Ke);xs=l(Jt,"To apply the preprocessing function over the entire dataset, use \u{1F917} Datasets "),Wt=r(Jt,"A",{href:!0,rel:!0});var eo=i(Wt);As=l(eo,"map"),eo.forEach(a),Xs=l(Jt," method. You can speed up the "),da=r(Jt,"CODE",{});var to=i(da);zs=l(to,"map"),to.forEach(a),Is=l(Jt," function by setting "),ya=r(Jt,"CODE",{});var ao=i(ya);Fs=l(ao,"batched=True"),ao.forEach(a),Ns=l(Jt," to process multiple elements of the dataset at once:"),Jt.forEach(a),xa=y(e),T(St.$$.fragment,e),Aa=y(e),ot=r(e,"P",{});var la=i(ot);qs=l(la,"Now create a batch of examples using "),Lt=r(la,"A",{href:!0});var so=i(Lt);Ys=l(so,"DataCollatorForSeq2Seq"),so.forEach(a),Hs=l(la,". It\u2019s more efficient to "),ba=r(la,"EM",{});var lo=i(ba);Qs=l(lo,"dynamically pad"),lo.forEach(a),Ps=l(la," the sentences to the longest length in a batch during collation, instead of padding the whole dataset to the maximum length."),la.forEach(a),Xa=y(e),T(gt.$$.fragment,e),za=y(e),dt=r(e,"H2",{class:!0});var fs=i(dt);wt=r(fs,"A",{id:!0,class:!0,href:!0});var oo=i(wt);Ma=r(oo,"SPAN",{});var ro=i(Ma);T(xt.$$.fragment,ro),ro.forEach(a),oo.forEach(a),Ds=y(fs),ga=r(fs,"SPAN",{});var no=i(ga);Ls=l(no,"Evaluate"),no.forEach(a),fs.forEach(a),Ia=y(e),et=r(e,"P",{});var Zt=i(et);Os=l(Zt,"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} "),At=r(Zt,"A",{href:!0,rel:!0});var io=i(At);Ks=l(io,"Evaluate"),io.forEach(a),el=l(Zt," library. For this task, load the "),Xt=r(Zt,"A",{href:!0,rel:!0});var co=i(Xt);tl=l(co,"ROUGE"),co.forEach(a),al=l(Zt," metric (see the \u{1F917} Evaluate "),zt=r(Zt,"A",{href:!0,rel:!0});var po=i(zt);sl=l(po,"quick tour"),po.forEach(a),ll=l(Zt," to learn more about how to load and compute a metric):"),Zt.forEach(a),Fa=y(e),T(It.$$.fragment,e),Na=y(e),$t=r(e,"P",{});var us=i($t);ol=l(us,"Then create a function that passes your predictions and labels to "),Ft=r(us,"A",{href:!0,rel:!0});var ho=i(Ft);rl=l(ho,"compute"),ho.forEach(a),nl=l(us," to calculate the ROUGE metric:"),us.forEach(a),qa=y(e),T(Nt.$$.fragment,e),Ya=y(e),_t=r(e,"P",{});var ds=i(_t);il=l(ds,"Your "),wa=r(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),yt=r(e,"H2",{class:!0});var ys=i(yt);jt=r(ys,"A",{id:!0,class:!0,href:!0});var fo=i(jt);$a=r(fo,"SPAN",{});var uo=i($a);T(qt.$$.fragment,uo),uo.forEach(a),fo.forEach(a),hl=y(ys),_a=r(ys,"SPAN",{});var yo=i(_a);ml=l(yo,"Train"),yo.forEach(a),ys.forEach(a),Qa=y(e),T(vt.$$.fragment,e),Pa=y(e),T(kt.$$.fragment,e),Da=y(e),bt=r(e,"H2",{class:!0});var bs=i(bt);Tt=r(bs,"A",{id:!0,class:!0,href:!0});var bo=i(Tt);ja=r(bo,"SPAN",{});var Mo=i(ja);T(Yt.$$.fragment,Mo),Mo.forEach(a),bo.forEach(a),fl=y(bs),va=r(bs,"SPAN",{});var go=i(va);ul=l(go,"Inference"),go.forEach(a),bs.forEach(a),La=y(e),Ot=r(e,"P",{});var wo=i(Ot);dl=l(wo,"Great, now that you\u2019ve finetuned a model, you can use it for inference!"),wo.forEach(a),Oa=y(e),Kt=r(e,"P",{});var $o=i(Kt);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),T(Ht.$$.fragment,e),es=y(e),rt=r(e,"P",{});var oa=i(rt);bl=l(oa,"The simplest way to try out your finetuned model for inference is to use it in a "),ea=r(oa,"A",{href:!0});var _o=i(ea);Ml=l(_o,"pipeline()"),_o.forEach(a),gl=l(oa,". Instantiate a "),ka=r(oa,"CODE",{});var jo=i(ka);wl=l(jo,"pipeline"),jo.forEach(a),$l=l(oa," for summarization with your model, and pass your text to it:"),oa.forEach(a),ts=y(e),T(Qt.$$.fragment,e),as=y(e),Ut=r(e,"P",{});var Ms=i(Ut);_l=l(Ms,"You can also manually replicate the results of the "),Ta=r(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),T(Et.$$.fragment,e),this.h()},h(){b(c,"name","hf:doc:metadata"),b(c,"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(n,"class","relative group"),b(L,"href","https://huggingface.co/t5-small"),b(L,"rel","nofollow"),b(Te,"href","https://huggingface.co/datasets/billsum"),b(Te,"rel","nofollow"),b(ne,"id","load-billsum-dataset"),b(ne,"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(ne,"href","#load-billsum-dataset"),b(re,"class","relative group"),b(je,"href","https://huggingface.co/docs/datasets/v2.12.0/en/package_reference/main_classes#datasets.Dataset.train_test_split"),b(je,"rel","nofollow"),b(Mt,"id","preprocess"),b(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"),b(Mt,"href","#preprocess"),b(ut,"class","relative group"),b(Wt,"href","https://huggingface.co/docs/datasets/v2.12.0/en/package_reference/main_classes#datasets.Dataset.map"),b(Wt,"rel","nofollow"),b(Lt,"href","/docs/transformers/v4.30.0/en/main_classes/data_collator#transformers.DataCollatorForSeq2Seq"),b(wt,"id","evaluate"),b(wt,"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(wt,"href","#evaluate"),b(dt,"class","relative group"),b(At,"href","https://huggingface.co/docs/evaluate/index"),b(At,"rel","nofollow"),b(Xt,"href","https://huggingface.co/spaces/evaluate-metric/rouge"),b(Xt,"rel","nofollow"),b(zt,"href","https://huggingface.co/docs/evaluate/a_quick_tour"),b(zt,"rel","nofollow"),b(Ft,"href","https://huggingface.co/docs/evaluate/v0.4.0/en/package_reference/main_classes#evaluate.EvaluationModule.compute"),b(Ft,"rel","nofollow"),b(jt,"id","train"),b(jt,"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(jt,"href","#train"),b(yt,"class","relative group"),b(Tt,"id","inference"),b(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"),b(Tt,"href","#inference"),b(bt,"class","relative group"),b(ea,"href","/docs/transformers/v4.30.0/en/main_classes/pipelines#transformers.pipeline")},m(e,f){t(document.head,c),h(e,m,f),h(e,n,f),t(n,M),t(M,$),U(v,$,null),t(n,C),t(n,x),t(x,_),h(e,B,f),U(V,e,f),h(e,z,f),U(X,e,f),h(e,A,f),h(e,S,f),t(S,ce),h(e,D,f),h(e,W,f),t(W,K),t(K,Y),t(W,ee),t(W,H),t(H,I),h(e,F,f),h(e,u,f),t(u,j),h(e,te,f),h(e,N,f),t(N,ae),t(ae,Q),t(ae,L),t(L,ke),t(ae,pe),t(ae,Te),t(Te,we),t(ae,Ge),t(N,Ae),t(N,Ce),t(Ce,O),h(e,Se,f),U(le,e,f),h(e,Ue,f),h(e,Ve,f),t(Ve,Ee),h(e,he,f),U($e,e,f),h(e,ue,f),h(e,oe,f),t(oe,Je),h(e,ye,f),U(de,e,f),h(e,_e,f),h(e,re,f),t(re,ne),t(ne,g),U(R,g,null),t(re,be),t(re,Ze),t(Ze,Be),h(e,se,f),h(e,Me,f),t(Me,Xe),h(e,me,f),U(Re,e,f),h(e,fe,f),h(e,ie,f),t(ie,ze),t(ie,je),t(je,We),t(ie,ve),h(e,ge,f),U(w,e,f),h(e,tt,f),h(e,Ie,f),t(Ie,p),h(e,G,f),U(xe,e,f),h(e,Fe,f),h(e,De,f),t(De,nt),h(e,Le,f),h(e,Ne,f),t(Ne,Oe),t(Oe,Ye),t(Ye,it),t(Oe,He),t(Ne,ct),t(Ne,qe),t(qe,Qe),t(Qe,pt),t(qe,ht),t(qe,Pe),t(Pe,mt),t(qe,ft),h(e,at,f),h(e,ut,f),t(ut,Mt),t(Mt,ia),U(Gt,ia,null),t(ut,$s),t(ut,ca),t(ca,_s),h(e,Ca,f),h(e,st,f),t(st,js),t(st,pa),t(pa,vs),t(st,ks),t(st,ha),t(ha,Ts),t(st,Us),h(e,Va,f),U(Ct,e,f),h(e,Ba,f),h(e,Dt,f),t(Dt,Es),h(e,Ra,f),h(e,lt,f),t(lt,ma),t(ma,Js),t(lt,Zs),t(lt,Vt),t(Vt,Gs),t(Vt,fa),t(fa,Cs),t(Vt,Vs),t(lt,Bs),t(lt,Bt),t(Bt,Rs),t(Bt,ua),t(ua,Ws),t(Bt,Ss),h(e,Wa,f),U(Rt,e,f),h(e,Sa,f),h(e,Ke,f),t(Ke,xs),t(Ke,Wt),t(Wt,As),t(Ke,Xs),t(Ke,da),t(da,zs),t(Ke,Is),t(Ke,ya),t(ya,Fs),t(Ke,Ns),h(e,xa,f),U(St,e,f),h(e,Aa,f),h(e,ot,f),t(ot,qs),t(ot,Lt),t(Lt,Ys),t(ot,Hs),t(ot,ba),t(ba,Qs),t(ot,Ps),h(e,Xa,f),U(gt,e,f),h(e,za,f),h(e,dt,f),t(dt,wt),t(wt,Ma),U(xt,Ma,null),t(dt,Ds),t(dt,ga),t(ga,Ls),h(e,Ia,f),h(e,et,f),t(et,Os),t(et,At),t(At,Ks),t(et,el),t(et,Xt),t(Xt,tl),t(et,al),t(et,zt),t(zt,sl),t(et,ll),h(e,Fa,f),U(It,e,f),h(e,Na,f),h(e,$t,f),t($t,ol),t($t,Ft),t(Ft,rl),t($t,nl),h(e,qa,f),U(Nt,e,f),h(e,Ya,f),h(e,_t,f),t(_t,il),t(_t,wa),t(wa,cl),t(_t,pl),h(e,Ha,f),h(e,yt,f),t(yt,jt),t(jt,$a),U(qt,$a,null),t(yt,hl),t(yt,_a),t(_a,ml),h(e,Qa,f),U(vt,e,f),h(e,Pa,f),U(kt,e,f),h(e,Da,f),h(e,bt,f),t(bt,Tt),t(Tt,ja),U(Yt,ja,null),t(bt,fl),t(bt,va),t(va,ul),h(e,La,f),h(e,Ot,f),t(Ot,dl),h(e,Oa,f),h(e,Kt,f),t(Kt,yl),h(e,Ka,f),U(Ht,e,f),h(e,es,f),h(e,rt,f),t(rt,bl),t(rt,ea),t(ea,Ml),t(rt,gl),t(rt,ka),t(ka,wl),t(rt,$l),h(e,ts,f),U(Qt,e,f),h(e,as,f),h(e,Ut,f),t(Ut,_l),t(Ut,Ta),t(Ta,jl),t(Ut,vl),h(e,ss,f),U(Et,e,f),ls=!0},p(e,[f]){const Pt={};f&2&&(Pt.$$scope={dirty:f,ctx:e}),le.$set(Pt);const Ua={};f&2&&(Ua.$$scope={dirty:f,ctx:e}),gt.$set(Ua);const Ea={};f&2&&(Ea.$$scope={dirty:f,ctx:e}),vt.$set(Ea);const Ja={};f&2&&(Ja.$$scope={dirty:f,ctx:e}),kt.$set(Ja);const Za={};f&2&&(Za.$$scope={dirty:f,ctx:e}),Et.$set(Za)},i(e){ls||(E(v.$$.fragment,e),E(V.$$.fragment,e),E(X.$$.fragment,e),E(le.$$.fragment,e),E($e.$$.fragment,e),E(de.$$.fragment,e),E(R.$$.fragment,e),E(Re.$$.fragment,e),E(w.$$.fragment,e),E(xe.$$.fragment,e),E(Gt.$$.fragment,e),E(Ct.$$.fragment,e),E(Rt.$$.fragment,e),E(St.$$.fragment,e),E(gt.$$.fragment,e),E(xt.$$.fragment,e),E(It.$$.fragment,e),E(Nt.$$.fragment,e),E(qt.$$.fragment,e),E(vt.$$.fragment,e),E(kt.$$.fragment,e),E(Yt.$$.fragment,e),E(Ht.$$.fragment,e),E(Qt.$$.fragment,e),E(Et.$$.fragment,e),ls=!0)},o(e){J(v.$$.fragment,e),J(V.$$.fragment,e),J(X.$$.fragment,e),J(le.$$.fragment,e),J($e.$$.fragment,e),J(de.$$.fragment,e),J(R.$$.fragment,e),J(Re.$$.fragment,e),J(w.$$.fragment,e),J(xe.$$.fragment,e),J(Gt.$$.fragment,e),J(Ct.$$.fragment,e),J(Rt.$$.fragment,e),J(St.$$.fragment,e),J(gt.$$.fragment,e),J(xt.$$.fragment,e),J(It.$$.fragment,e),J(Nt.$$.fragment,e),J(qt.$$.fragment,e),J(vt.$$.fragment,e),J(kt.$$.fragment,e),J(Yt.$$.fragment,e),J(Ht.$$.fragment,e),J(Qt.$$.fragment,e),J(Et.$$.fragment,e),ls=!1},d(e){a(c),e&&a(m),e&&a(n),Z(v),e&&a(B),Z(V,e),e&&a(z),Z(X,e),e&&a(A),e&&a(S),e&&a(D),e&&a(W),e&&a(F),e&&a(u),e&&a(te),e&&a(N),e&&a(Se),Z(le,e),e&&a(Ue),e&&a(Ve),e&&a(he),Z($e,e),e&&a(ue),e&&a(oe),e&&a(ye),Z(de,e),e&&a(_e),e&&a(re),Z(R),e&&a(se),e&&a(Me),e&&a(me),Z(Re,e),e&&a(fe),e&&a(ie),e&&a(ge),Z(w,e),e&&a(tt),e&&a(Ie),e&&a(G),Z(xe,e),e&&a(Fe),e&&a(De),e&&a(Le),e&&a(Ne),e&&a(at),e&&a(ut),Z(Gt),e&&a(Ca),e&&a(st),e&&a(Va),Z(Ct,e),e&&a(Ba),e&&a(Dt),e&&a(Ra),e&&a(lt),e&&a(Wa),Z(Rt,e),e&&a(Sa),e&&a(Ke),e&&a(xa),Z(St,e),e&&a(Aa),e&&a(ot),e&&a(Xa),Z(gt,e),e&&a(za),e&&a(dt),Z(xt),e&&a(Ia),e&&a(et),e&&a(Fa),Z(It,e),e&&a(Na),e&&a($t),e&&a(qa),Z(Nt,e),e&&a(Ya),e&&a(_t),e&&a(Ha),e&&a(yt),Z(qt),e&&a(Qa),Z(vt,e),e&&a(Pa),Z(kt,e),e&&a(Da),e&&a(bt),Z(Yt),e&&a(La),e&&a(Ot),e&&a(Oa),e&&a(Kt),e&&a(Ka),Z(Ht,e),e&&a(es),e&&a(rt),e&&a(ts),Z(Qt,e),e&&a(as),e&&a(Ut),e&&a(ss),Z(Et,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(q){return Jo(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class lr extends ko{constructor(c){super();To(this,c,Do,Qo,Uo,{})}}export{lr as default,Po as metadata};
