import{S as vr,i as jr,s as qr,e as i,k as h,w as q,t as a,M as Er,c as p,d as t,m as d,a as c,x as E,h as o,b as $,G as s,g as m,y as T,q as S,o as x,B as z,v as Tr,L as $a}from"../../chunks/vendor-hf-doc-builder.js";import{T as ga}from"../../chunks/Tip-hf-doc-builder.js";import{Y as Sr}from"../../chunks/Youtube-hf-doc-builder.js";import{I as os}from"../../chunks/IconCopyLink-hf-doc-builder.js";import{C as O}from"../../chunks/CodeBlock-hf-doc-builder.js";import{F as qo,M as rs}from"../../chunks/Markdown-hf-doc-builder.js";function xr(I){let n,_,r,g,w;return{c(){n=i("p"),_=a("See the summarization "),r=i("a"),g=a("task page"),w=a(" for more information about its associated models, datasets, and metrics."),this.h()},l(j){n=p(j,"P",{});var v=c(n);_=o(v,"See the summarization "),r=p(v,"A",{href:!0,rel:!0});var C=c(r);g=o(C,"task page"),C.forEach(t),w=o(v," for more information about its associated models, datasets, and metrics."),v.forEach(t),this.h()},h(){$(r,"href","https://huggingface.co/tasks/summarization"),$(r,"rel","nofollow")},m(j,v){m(j,n,v),s(n,_),s(n,r),s(r,g),s(n,w)},d(j){j&&t(n)}}}function zr(I){let n,_;return n=new O({props:{code:`from transformers import DataCollatorForSeq2Seq

data_collator = DataCollatorForSeq2Seq(tokenizer=tokenizer, model=model)`,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=model)`}}),{c(){q(n.$$.fragment)},l(r){E(n.$$.fragment,r)},m(r,g){T(n,r,g),_=!0},p:$a,i(r){_||(S(n.$$.fragment,r),_=!0)},o(r){x(n.$$.fragment,r),_=!1},d(r){z(n,r)}}}function Ar(I){let n,_;return n=new rs({props:{$$slots:{default:[zr]},$$scope:{ctx:I}}}),{c(){q(n.$$.fragment)},l(r){E(n.$$.fragment,r)},m(r,g){T(n,r,g),_=!0},p(r,g){const w={};g&2&&(w.$$scope={dirty:g,ctx:r}),n.$set(w)},i(r){_||(S(n.$$.fragment,r),_=!0)},o(r){x(n.$$.fragment,r),_=!1},d(r){z(n,r)}}}function Cr(I){let n,_;return n=new O({props:{code:`from transformers import DataCollatorForSeq2Seq

data_collator = DataCollatorForSeq2Seq(tokenizer=tokenizer, model=model, return_tensors="tf")`,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=model, return_tensors=<span class="hljs-string">&quot;tf&quot;</span>)`}}),{c(){q(n.$$.fragment)},l(r){E(n.$$.fragment,r)},m(r,g){T(n,r,g),_=!0},p:$a,i(r){_||(S(n.$$.fragment,r),_=!0)},o(r){x(n.$$.fragment,r),_=!1},d(r){z(n,r)}}}function Pr(I){let n,_;return n=new rs({props:{$$slots:{default:[Cr]},$$scope:{ctx:I}}}),{c(){q(n.$$.fragment)},l(r){E(n.$$.fragment,r)},m(r,g){T(n,r,g),_=!0},p(r,g){const w={};g&2&&(w.$$scope={dirty:g,ctx:r}),n.$set(w)},i(r){_||(S(n.$$.fragment,r),_=!0)},o(r){x(n.$$.fragment,r),_=!1},d(r){z(n,r)}}}function Fr(I){let n,_,r,g,w,j,v,C;return{c(){n=i("p"),_=a("If you aren\u2019t familiar with finetuning a model with the "),r=i("a"),g=a("Trainer"),w=a(", take a look at the basic tutorial "),j=i("a"),v=a("here"),C=a("!"),this.h()},l(k){n=p(k,"P",{});var F=c(n);_=o(F,"If you aren\u2019t familiar with finetuning a model with the "),r=p(F,"A",{href:!0});var P=c(r);g=o(P,"Trainer"),P.forEach(t),w=o(F,", take a look at the basic tutorial "),j=p(F,"A",{href:!0});var G=c(j);v=o(G,"here"),G.forEach(t),C=o(F,"!"),F.forEach(t),this.h()},h(){$(r,"href","/docs/transformers/v4.25.1/en/main_classes/trainer#transformers.Trainer"),$(j,"href","../training#train-with-pytorch-trainer")},m(k,F){m(k,n,F),s(n,_),s(n,r),s(r,g),s(n,w),s(n,j),s(j,v),s(n,C)},d(k){k&&t(n)}}}function Mr(I){let n,_,r,g,w,j,v,C,k,F,P,G,U,B,ee,Q,W,H,te,N,oe,R,L,D,u,y,X,J,V,ne,se,me,re,Ie,ie,je,Le,ye,Y,qe,ae,Oe,de,le,ze,_e,fe,pe;return n=new ga({props:{$$slots:{default:[Fr]},$$scope:{ctx:I}}}),r=new O({props:{code:`from transformers import AutoModelForSeq2SeqLM, Seq2SeqTrainingArguments, Seq2SeqTrainer

model = AutoModelForSeq2SeqLM.from_pretrained("t5-small")`,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(<span class="hljs-string">&quot;t5-small&quot;</span>)`}}),Y=new O({props:{code:`training_args = Seq2SeqTrainingArguments(
    output_dir="my_awesome_billsum_model",
    evaluation_strategy="epoch",
    learning_rate=2e-5,
    per_device_train_batch_size=16,
    per_device_eval_batch_size=16,
    weight_decay=0.01,
    save_total_limit=3,
    num_train_epochs=4,
    predict_with_generate=True,
    fp16=True,
    push_to_hub=True,
)

trainer = Seq2SeqTrainer(
    model=model,
    args=training_args,
    train_dataset=tokenized_billsum["train"],
    eval_dataset=tokenized_billsum["test"],
    tokenizer=tokenizer,
    data_collator=data_collator,
    compute_metrics=compute_metrics,
)

trainer.train()`,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()`}}),fe=new O({props:{code:"trainer.push_to_hub()",highlighted:'<span class="hljs-meta">&gt;&gt;&gt; </span>trainer.push_to_hub()'}}),{c(){q(n.$$.fragment),_=a(`
You're ready to start training your model now! Load T5 with [AutoModelForSeq2SeqLM](/docs/transformers/v4.25.1/en/model_doc/auto#transformers.AutoModelForSeq2SeqLM):

	`),q(r.$$.fragment),g=h(),w=i("p"),j=a("At this point, only three steps remain:"),v=h(),C=i("ol"),k=i("li"),F=a("Define your training hyperparameters in "),P=i("a"),G=a("Seq2SeqTrainingArguments"),U=a(". The only required parameter is "),B=i("code"),ee=a("output_dir"),Q=a(" which specifies where to save your model. You\u2019ll push this model to the Hub by setting "),W=i("code"),H=a("push_to_hub=True"),te=a(" (you need to be signed in to Hugging Face to upload your model). At the end of each epoch, the "),N=i("a"),oe=a("Trainer"),R=a(" will evaluate the ROUGE metric and save the training checkpoint."),L=h(),D=i("li"),u=a("Pass the training arguments to "),y=i("a"),X=a("Seq2SeqTrainer"),J=a(" along with the model, dataset, tokenizer, data collator, and "),V=i("code"),ne=a("compute_metrics"),se=a(" function."),me=h(),re=i("li"),Ie=a("Call "),ie=i("a"),je=a("train()"),Le=a(" to finetune your model."),ye=h(),q(Y.$$.fragment),qe=h(),ae=i("p"),Oe=a("Once training is completed, share your model to the Hub with the "),de=i("a"),le=a("push_to_hub()"),ze=a(" method so everyone can use your model:"),_e=h(),q(fe.$$.fragment),this.h()},l(b){E(n.$$.fragment,b),_=o(b,`
You're ready to start training your model now! Load T5 with [AutoModelForSeq2SeqLM](/docs/transformers/v4.25.1/en/model_doc/auto#transformers.AutoModelForSeq2SeqLM):

	`),E(r.$$.fragment,b),g=d(b),w=p(b,"P",{});var M=c(w);j=o(M,"At this point, only three steps remain:"),M.forEach(t),v=d(b),C=p(b,"OL",{});var Z=c(C);k=p(Z,"LI",{});var K=c(k);F=o(K,"Define your training hyperparameters in "),P=p(K,"A",{href:!0});var Ae=c(P);G=o(Ae,"Seq2SeqTrainingArguments"),Ae.forEach(t),U=o(K,". The only required parameter is "),B=p(K,"CODE",{});var ke=c(B);ee=o(ke,"output_dir"),ke.forEach(t),Q=o(K," which specifies where to save your model. You\u2019ll push this model to the Hub by setting "),W=p(K,"CODE",{});var He=c(W);H=o(He,"push_to_hub=True"),He.forEach(t),te=o(K," (you need to be signed in to Hugging Face to upload your model). At the end of each epoch, the "),N=p(K,"A",{href:!0});var ue=c(N);oe=o(ue,"Trainer"),ue.forEach(t),R=o(K," will evaluate the ROUGE metric and save the training checkpoint."),K.forEach(t),L=d(Z),D=p(Z,"LI",{});var ge=c(D);u=o(ge,"Pass the training arguments to "),y=p(ge,"A",{href:!0});var ve=c(y);X=o(ve,"Seq2SeqTrainer"),ve.forEach(t),J=o(ge," along with the model, dataset, tokenizer, data collator, and "),V=p(ge,"CODE",{});var Ee=c(V);ne=o(Ee,"compute_metrics"),Ee.forEach(t),se=o(ge," function."),ge.forEach(t),me=d(Z),re=p(Z,"LI",{});var Te=c(re);Ie=o(Te,"Call "),ie=p(Te,"A",{href:!0});var $e=c(ie);je=o($e,"train()"),$e.forEach(t),Le=o(Te," to finetune your model."),Te.forEach(t),Z.forEach(t),ye=d(b),E(Y.$$.fragment,b),qe=d(b),ae=p(b,"P",{});var ce=c(ae);Oe=o(ce,"Once training is completed, share your model to the Hub with the "),de=p(ce,"A",{href:!0});var he=c(de);le=o(he,"push_to_hub()"),he.forEach(t),ze=o(ce," method so everyone can use your model:"),ce.forEach(t),_e=d(b),E(fe.$$.fragment,b),this.h()},h(){$(P,"href","/docs/transformers/v4.25.1/en/main_classes/trainer#transformers.Seq2SeqTrainingArguments"),$(N,"href","/docs/transformers/v4.25.1/en/main_classes/trainer#transformers.Trainer"),$(y,"href","/docs/transformers/v4.25.1/en/main_classes/trainer#transformers.Seq2SeqTrainer"),$(ie,"href","/docs/transformers/v4.25.1/en/main_classes/trainer#transformers.Trainer.train"),$(de,"href","/docs/transformers/v4.25.1/en/main_classes/trainer#transformers.Trainer.push_to_hub")},m(b,M){T(n,b,M),m(b,_,M),T(r,b,M),m(b,g,M),m(b,w,M),s(w,j),m(b,v,M),m(b,C,M),s(C,k),s(k,F),s(k,P),s(P,G),s(k,U),s(k,B),s(B,ee),s(k,Q),s(k,W),s(W,H),s(k,te),s(k,N),s(N,oe),s(k,R),s(C,L),s(C,D),s(D,u),s(D,y),s(y,X),s(D,J),s(D,V),s(V,ne),s(D,se),s(C,me),s(C,re),s(re,Ie),s(re,ie),s(ie,je),s(re,Le),m(b,ye,M),T(Y,b,M),m(b,qe,M),m(b,ae,M),s(ae,Oe),s(ae,de),s(de,le),s(ae,ze),m(b,_e,M),T(fe,b,M),pe=!0},p(b,M){const Z={};M&2&&(Z.$$scope={dirty:M,ctx:b}),n.$set(Z)},i(b){pe||(S(n.$$.fragment,b),S(r.$$.fragment,b),S(Y.$$.fragment,b),S(fe.$$.fragment,b),pe=!0)},o(b){x(n.$$.fragment,b),x(r.$$.fragment,b),x(Y.$$.fragment,b),x(fe.$$.fragment,b),pe=!1},d(b){z(n,b),b&&t(_),z(r,b),b&&t(g),b&&t(w),b&&t(v),b&&t(C),b&&t(ye),z(Y,b),b&&t(qe),b&&t(ae),b&&t(_e),z(fe,b)}}}function Dr(I){let n,_;return n=new rs({props:{$$slots:{default:[Mr]},$$scope:{ctx:I}}}),{c(){q(n.$$.fragment)},l(r){E(n.$$.fragment,r)},m(r,g){T(n,r,g),_=!0},p(r,g){const w={};g&2&&(w.$$scope={dirty:g,ctx:r}),n.$set(w)},i(r){_||(S(n.$$.fragment,r),_=!0)},o(r){x(n.$$.fragment,r),_=!1},d(r){z(n,r)}}}function Ir(I){let n,_,r,g,w;return{c(){n=i("p"),_=a("If you aren\u2019t familiar with finetuning a model with Keras, take a look at the basic tutorial "),r=i("a"),g=a("here"),w=a("!"),this.h()},l(j){n=p(j,"P",{});var v=c(n);_=o(v,"If you aren\u2019t familiar with finetuning a model with Keras, take a look at the basic tutorial "),r=p(v,"A",{href:!0});var C=c(r);g=o(C,"here"),C.forEach(t),w=o(v,"!"),v.forEach(t),this.h()},h(){$(r,"href","../training#train-a-tensorflow-model-with-keras")},m(j,v){m(j,n,v),s(n,_),s(n,r),s(r,g),s(n,w)},d(j){j&&t(n)}}}function Lr(I){let n,_,r,g,w,j,v,C,k,F,P,G,U,B,ee,Q,W,H,te,N,oe,R,L,D,u,y,X,J,V,ne,se,me,re,Ie,ie,je,Le,ye,Y,qe,ae,Oe,de,le,ze,_e,fe,pe,b,M,Z,K,Ae,ke,He,ue,ge,ve,Ee,Te,$e,ce,he,Ce,Ne,Se,wt,yt,Je,be,Qe,xe,kt,Ve;return n=new ga({props:{$$slots:{default:[Ir]},$$scope:{ctx:I}}}),r=new O({props:{code:`from transformers import create_optimizer, AdamWeightDecay

optimizer = AdamWeightDecay(learning_rate=2e-5, weight_decay_rate=0.01)`,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>)`}}),P=new O({props:{code:`from transformers import TFAutoModelForSeq2SeqLM

model = TFAutoModelForSeq2SeqLM.from_pretrained("t5-small")`,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;t5-small&quot;</span>)`}}),R=new O({props:{code:`tf_train_set = model.prepare_tf_dataset(
    tokenized_billsum["train"],
    shuffle=True,
    batch_size=16,
    collate_fn=data_collator,
)

tf_test_set = model.prepare_tf_dataset(
    tokenized_billsum["test"],
    shuffle=False,
    batch_size=16,
    collate_fn=data_collator,
)`,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>)`}}),se=new O({props:{code:`import tensorflow as tf

model.compile(optimizer=optimizer)`,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)`}}),pe=new O({props:{code:`from transformers.keras_callbacks import KerasMetricCallback

metric_callback = KerasMetricCallback(metric_fn=compute_metrics, eval_dataset=tf_validation_set)`,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)`}}),ue=new O({props:{code:`from transformers.keras_callbacks import PushToHubCallback

push_to_hub_callback = PushToHubCallback(
    output_dir="my_awesome_billsum_model",
    tokenizer=tokenizer,
)`,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>)`}}),$e=new O({props:{code:"callbacks = [metric_callback, push_to_hub_callback]",highlighted:'<span class="hljs-meta">&gt;&gt;&gt; </span>callbacks = [metric_callback, push_to_hub_callback]'}}),be=new O({props:{code:"model.fit(x=tf_train_set, validation_data=tf_test_set, epochs=3, callbacks=callbacks)",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(){q(n.$$.fragment),_=a(`
To finetune a model in TensorFlow, start by setting up an optimizer function, learning rate schedule, and some training hyperparameters:

	`),q(r.$$.fragment),g=h(),w=i("p"),j=a("Then you can load T5 with "),v=i("a"),C=a("TFAutoModelForSeq2SeqLM"),k=a(":"),F=h(),q(P.$$.fragment),G=h(),U=i("p"),B=a("Convert your datasets to the "),ee=i("code"),Q=a("tf.data.Dataset"),W=a(" format with "),H=i("a"),te=a("prepare_tf_dataset()"),N=a(":"),oe=h(),q(R.$$.fragment),L=h(),D=i("p"),u=a("Configure the model for training with "),y=i("a"),X=i("code"),J=a("compile"),V=a(":"),ne=h(),q(se.$$.fragment),me=h(),re=i("p"),Ie=a("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 "),ie=i("a"),je=a("Keras callbacks"),Le=a("."),ye=h(),Y=i("p"),qe=a("Pass your "),ae=i("code"),Oe=a("compute_metrics"),de=a(" function to "),le=i("a"),ze=a("KerasMetricCallback"),_e=a(":"),fe=h(),q(pe.$$.fragment),b=h(),M=i("p"),Z=a("Specify where to push your model and tokenizer in the "),K=i("a"),Ae=a("PushToHubCallback"),ke=a(":"),He=h(),q(ue.$$.fragment),ge=h(),ve=i("p"),Ee=a("Then bundle your callbacks together:"),Te=h(),q($e.$$.fragment),ce=h(),he=i("p"),Ce=a("Finally, you\u2019re ready to start training your model! Call "),Ne=i("a"),Se=i("code"),wt=a("fit"),yt=a(" with your training and validation datasets, the number of epochs, and your callbacks to finetune the model:"),Je=h(),q(be.$$.fragment),Qe=h(),xe=i("p"),kt=a("Once training is completed, your model is automatically uploaded to the Hub so everyone can use it!"),this.h()},l(l){E(n.$$.fragment,l),_=o(l,`
To finetune a model in TensorFlow, start by setting up an optimizer function, learning rate schedule, and some training hyperparameters:

	`),E(r.$$.fragment,l),g=d(l),w=p(l,"P",{});var A=c(w);j=o(A,"Then you can load T5 with "),v=p(A,"A",{href:!0});var Pe=c(v);C=o(Pe,"TFAutoModelForSeq2SeqLM"),Pe.forEach(t),k=o(A,":"),A.forEach(t),F=d(l),E(P.$$.fragment,l),G=d(l),U=p(l,"P",{});var Ye=c(U);B=o(Ye,"Convert your datasets to the "),ee=p(Ye,"CODE",{});var vt=c(ee);Q=o(vt,"tf.data.Dataset"),vt.forEach(t),W=o(Ye," format with "),H=p(Ye,"A",{href:!0});var Ue=c(H);te=o(Ue,"prepare_tf_dataset()"),Ue.forEach(t),N=o(Ye,":"),Ye.forEach(t),oe=d(l),E(R.$$.fragment,l),L=d(l),D=p(l,"P",{});var Ge=c(D);u=o(Ge,"Configure the model for training with "),y=p(Ge,"A",{href:!0,rel:!0});var st=c(y);X=p(st,"CODE",{});var Bt=c(X);J=o(Bt,"compile"),Bt.forEach(t),st.forEach(t),V=o(Ge,":"),Ge.forEach(t),ne=d(l),E(se.$$.fragment,l),me=d(l),re=p(l,"P",{});var at=c(re);Ie=o(at,"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 "),ie=p(at,"A",{href:!0});var Yt=c(ie);je=o(Yt,"Keras callbacks"),Yt.forEach(t),Le=o(at,"."),at.forEach(t),ye=d(l),Y=p(l,"P",{});var we=c(Y);qe=o(we,"Pass your "),ae=p(we,"CODE",{});var ot=c(ae);Oe=o(ot,"compute_metrics"),ot.forEach(t),de=o(we," function to "),le=p(we,"A",{href:!0});var Rt=c(le);ze=o(Rt,"KerasMetricCallback"),Rt.forEach(t),_e=o(we,":"),we.forEach(t),fe=d(l),E(pe.$$.fragment,l),b=d(l),M=p(l,"P",{});var rt=c(M);Z=o(rt,"Specify where to push your model and tokenizer in the "),K=p(rt,"A",{href:!0});var nt=c(K);Ae=o(nt,"PushToHubCallback"),nt.forEach(t),ke=o(rt,":"),rt.forEach(t),He=d(l),E(ue.$$.fragment,l),ge=d(l),ve=p(l,"P",{});var Kt=c(ve);Ee=o(Kt,"Then bundle your callbacks together:"),Kt.forEach(t),Te=d(l),E($e.$$.fragment,l),ce=d(l),he=p(l,"P",{});var lt=c(he);Ce=o(lt,"Finally, you\u2019re ready to start training your model! Call "),Ne=p(lt,"A",{href:!0,rel:!0});var jt=c(Ne);Se=p(jt,"CODE",{});var Fe=c(Se);wt=o(Fe,"fit"),Fe.forEach(t),jt.forEach(t),yt=o(lt," with your training and validation datasets, the number of epochs, and your callbacks to finetune the model:"),lt.forEach(t),Je=d(l),E(be.$$.fragment,l),Qe=d(l),xe=p(l,"P",{});var Be=c(xe);kt=o(Be,"Once training is completed, your model is automatically uploaded to the Hub so everyone can use it!"),Be.forEach(t),this.h()},h(){$(v,"href","/docs/transformers/v4.25.1/en/model_doc/auto#transformers.TFAutoModelForSeq2SeqLM"),$(H,"href","/docs/transformers/v4.25.1/en/main_classes/model#transformers.TFPreTrainedModel.prepare_tf_dataset"),$(y,"href","https://keras.io/api/models/model_training_apis/#compile-method"),$(y,"rel","nofollow"),$(ie,"href","./main_classes/keras_callbacks"),$(le,"href","/docs/transformers/v4.25.1/en/main_classes/keras_callbacks#transformers.KerasMetricCallback"),$(K,"href","/docs/transformers/v4.25.1/en/main_classes/keras_callbacks#transformers.PushToHubCallback"),$(Ne,"href","https://keras.io/api/models/model_training_apis/#fit-method"),$(Ne,"rel","nofollow")},m(l,A){T(n,l,A),m(l,_,A),T(r,l,A),m(l,g,A),m(l,w,A),s(w,j),s(w,v),s(v,C),s(w,k),m(l,F,A),T(P,l,A),m(l,G,A),m(l,U,A),s(U,B),s(U,ee),s(ee,Q),s(U,W),s(U,H),s(H,te),s(U,N),m(l,oe,A),T(R,l,A),m(l,L,A),m(l,D,A),s(D,u),s(D,y),s(y,X),s(X,J),s(D,V),m(l,ne,A),T(se,l,A),m(l,me,A),m(l,re,A),s(re,Ie),s(re,ie),s(ie,je),s(re,Le),m(l,ye,A),m(l,Y,A),s(Y,qe),s(Y,ae),s(ae,Oe),s(Y,de),s(Y,le),s(le,ze),s(Y,_e),m(l,fe,A),T(pe,l,A),m(l,b,A),m(l,M,A),s(M,Z),s(M,K),s(K,Ae),s(M,ke),m(l,He,A),T(ue,l,A),m(l,ge,A),m(l,ve,A),s(ve,Ee),m(l,Te,A),T($e,l,A),m(l,ce,A),m(l,he,A),s(he,Ce),s(he,Ne),s(Ne,Se),s(Se,wt),s(he,yt),m(l,Je,A),T(be,l,A),m(l,Qe,A),m(l,xe,A),s(xe,kt),Ve=!0},p(l,A){const Pe={};A&2&&(Pe.$$scope={dirty:A,ctx:l}),n.$set(Pe)},i(l){Ve||(S(n.$$.fragment,l),S(r.$$.fragment,l),S(P.$$.fragment,l),S(R.$$.fragment,l),S(se.$$.fragment,l),S(pe.$$.fragment,l),S(ue.$$.fragment,l),S($e.$$.fragment,l),S(be.$$.fragment,l),Ve=!0)},o(l){x(n.$$.fragment,l),x(r.$$.fragment,l),x(P.$$.fragment,l),x(R.$$.fragment,l),x(se.$$.fragment,l),x(pe.$$.fragment,l),x(ue.$$.fragment,l),x($e.$$.fragment,l),x(be.$$.fragment,l),Ve=!1},d(l){z(n,l),l&&t(_),z(r,l),l&&t(g),l&&t(w),l&&t(F),z(P,l),l&&t(G),l&&t(U),l&&t(oe),z(R,l),l&&t(L),l&&t(D),l&&t(ne),z(se,l),l&&t(me),l&&t(re),l&&t(ye),l&&t(Y),l&&t(fe),z(pe,l),l&&t(b),l&&t(M),l&&t(He),z(ue,l),l&&t(ge),l&&t(ve),l&&t(Te),z($e,l),l&&t(ce),l&&t(he),l&&t(Je),z(be,l),l&&t(Qe),l&&t(xe)}}}function Or(I){let n,_;return n=new rs({props:{$$slots:{default:[Lr]},$$scope:{ctx:I}}}),{c(){q(n.$$.fragment)},l(r){E(n.$$.fragment,r)},m(r,g){T(n,r,g),_=!0},p(r,g){const w={};g&2&&(w.$$scope={dirty:g,ctx:r}),n.$set(w)},i(r){_||(S(n.$$.fragment,r),_=!0)},o(r){x(n.$$.fragment,r),_=!1},d(r){z(n,r)}}}function Hr(I){let n,_,r,g,w,j,v,C;return{c(){n=i("p"),_=a(`For a more in-depth example of how to finetune a model for summarization, take a look at the corresponding
`),r=i("a"),g=a("PyTorch notebook"),w=a(`
or `),j=i("a"),v=a("TensorFlow notebook"),C=a("."),this.h()},l(k){n=p(k,"P",{});var F=c(n);_=o(F,`For a more in-depth example of how to finetune a model for summarization, take a look at the corresponding
`),r=p(F,"A",{href:!0,rel:!0});var P=c(r);g=o(P,"PyTorch notebook"),P.forEach(t),w=o(F,`
or `),j=p(F,"A",{href:!0,rel:!0});var G=c(j);v=o(G,"TensorFlow notebook"),G.forEach(t),C=o(F,"."),F.forEach(t),this.h()},h(){$(r,"href","https://colab.research.google.com/github/huggingface/notebooks/blob/main/examples/summarization.ipynb"),$(r,"rel","nofollow"),$(j,"href","https://colab.research.google.com/github/huggingface/notebooks/blob/main/examples/summarization-tf.ipynb"),$(j,"rel","nofollow")},m(k,F){m(k,n,F),s(n,_),s(n,r),s(r,g),s(n,w),s(n,j),s(j,v),s(n,C)},d(k){k&&t(n)}}}function Nr(I){let n,_,r,g,w,j,v,C,k,F,P,G,U,B,ee,Q,W,H,te,N,oe,R,L,D;return v=new O({props:{code:`from transformers import AutoTokenizer

tokenizer = AutoTokenizer.from_pretrained("stevhliu/my_awesome_billsum_model")
inputs = tokenizer(text, return_tensors="pt").input_ids`,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`}}),H=new O({props:{code:`from transformers import AutoModelForSeq2SeqLM

model = AutoModelForSeq2SeqLM.from_pretrained("stevhliu/my_awesome_billsum_model")
outputs = model.generate(inputs, max_new_tokens=100, do_sample=False)`,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>)`}}),L=new O({props:{code:"tokenizer.decode(outputs[0], skip_special_tokens=True)",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(){n=i("p"),_=a("Tokenize the text and return the "),r=i("code"),g=a("input_ids"),w=a(" as PyTorch tensors:"),j=h(),q(v.$$.fragment),C=h(),k=i("p"),F=a("Use the "),P=i("a"),G=a("generate()"),U=a(" method to create the summarization. For more details about the different text generation strategies and parameters for controlling generation, check out the "),B=i("a"),ee=a("Text Generation"),Q=a(" API."),W=h(),q(H.$$.fragment),te=h(),N=i("p"),oe=a("Decode the generated token ids back into text:"),R=h(),q(L.$$.fragment),this.h()},l(u){n=p(u,"P",{});var y=c(n);_=o(y,"Tokenize the text and return the "),r=p(y,"CODE",{});var X=c(r);g=o(X,"input_ids"),X.forEach(t),w=o(y," as PyTorch tensors:"),y.forEach(t),j=d(u),E(v.$$.fragment,u),C=d(u),k=p(u,"P",{});var J=c(k);F=o(J,"Use the "),P=p(J,"A",{href:!0});var V=c(P);G=o(V,"generate()"),V.forEach(t),U=o(J," method to create the summarization. For more details about the different text generation strategies and parameters for controlling generation, check out the "),B=p(J,"A",{href:!0});var ne=c(B);ee=o(ne,"Text Generation"),ne.forEach(t),Q=o(J," API."),J.forEach(t),W=d(u),E(H.$$.fragment,u),te=d(u),N=p(u,"P",{});var se=c(N);oe=o(se,"Decode the generated token ids back into text:"),se.forEach(t),R=d(u),E(L.$$.fragment,u),this.h()},h(){$(P,"href","/docs/transformers/v4.25.1/en/main_classes/text_generation#transformers.GenerationMixin.generate"),$(B,"href","./main_classes/text_generation")},m(u,y){m(u,n,y),s(n,_),s(n,r),s(r,g),s(n,w),m(u,j,y),T(v,u,y),m(u,C,y),m(u,k,y),s(k,F),s(k,P),s(P,G),s(k,U),s(k,B),s(B,ee),s(k,Q),m(u,W,y),T(H,u,y),m(u,te,y),m(u,N,y),s(N,oe),m(u,R,y),T(L,u,y),D=!0},p:$a,i(u){D||(S(v.$$.fragment,u),S(H.$$.fragment,u),S(L.$$.fragment,u),D=!0)},o(u){x(v.$$.fragment,u),x(H.$$.fragment,u),x(L.$$.fragment,u),D=!1},d(u){u&&t(n),u&&t(j),z(v,u),u&&t(C),u&&t(k),u&&t(W),z(H,u),u&&t(te),u&&t(N),u&&t(R),z(L,u)}}}function Ur(I){let n,_;return n=new rs({props:{$$slots:{default:[Nr]},$$scope:{ctx:I}}}),{c(){q(n.$$.fragment)},l(r){E(n.$$.fragment,r)},m(r,g){T(n,r,g),_=!0},p(r,g){const w={};g&2&&(w.$$scope={dirty:g,ctx:r}),n.$set(w)},i(r){_||(S(n.$$.fragment,r),_=!0)},o(r){x(n.$$.fragment,r),_=!1},d(r){z(n,r)}}}function Gr(I){let n,_,r,g,w,j,v,C,k,F,P,G,U,B,ee,Q,W,H,te,N,oe,R,L,D;return v=new O({props:{code:`from transformers import AutoTokenizer

tokenizer = AutoTokenizer.from_pretrained("stevhliu/my_awesome_billsum_model")
inputs = tokenizer(text, return_tensors="tf").input_ids`,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`}}),H=new O({props:{code:`from transformers import TFAutoModelForSeq2SeqLM

model = TFAutoModelForSeq2SeqLM.from_pretrained("stevhliu/my_awesome_billsum_model")
outputs = model.generate(inputs, max_new_tokens=100, do_sample=False)`,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>)`}}),L=new O({props:{code:"tokenizer.decode(outputs[0], skip_special_tokens=True)",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(){n=i("p"),_=a("Tokenize the text and return the "),r=i("code"),g=a("input_ids"),w=a(" as TensorFlow tensors:"),j=h(),q(v.$$.fragment),C=h(),k=i("p"),F=a("Use the "),P=i("a"),G=a("generate()"),U=a(" method to create the summarization. For more details about the different text generation strategies and parameters for controlling generation, check out the "),B=i("a"),ee=a("Text Generation"),Q=a(" API."),W=h(),q(H.$$.fragment),te=h(),N=i("p"),oe=a("Decode the generated token ids back into text:"),R=h(),q(L.$$.fragment),this.h()},l(u){n=p(u,"P",{});var y=c(n);_=o(y,"Tokenize the text and return the "),r=p(y,"CODE",{});var X=c(r);g=o(X,"input_ids"),X.forEach(t),w=o(y," as TensorFlow tensors:"),y.forEach(t),j=d(u),E(v.$$.fragment,u),C=d(u),k=p(u,"P",{});var J=c(k);F=o(J,"Use the "),P=p(J,"A",{href:!0});var V=c(P);G=o(V,"generate()"),V.forEach(t),U=o(J," method to create the summarization. For more details about the different text generation strategies and parameters for controlling generation, check out the "),B=p(J,"A",{href:!0});var ne=c(B);ee=o(ne,"Text Generation"),ne.forEach(t),Q=o(J," API."),J.forEach(t),W=d(u),E(H.$$.fragment,u),te=d(u),N=p(u,"P",{});var se=c(N);oe=o(se,"Decode the generated token ids back into text:"),se.forEach(t),R=d(u),E(L.$$.fragment,u),this.h()},h(){$(P,"href","/docs/transformers/v4.25.1/en/main_classes/text_generation#transformers.TFGenerationMixin.generate"),$(B,"href","./main_classes/text_generation")},m(u,y){m(u,n,y),s(n,_),s(n,r),s(r,g),s(n,w),m(u,j,y),T(v,u,y),m(u,C,y),m(u,k,y),s(k,F),s(k,P),s(P,G),s(k,U),s(k,B),s(B,ee),s(k,Q),m(u,W,y),T(H,u,y),m(u,te,y),m(u,N,y),s(N,oe),m(u,R,y),T(L,u,y),D=!0},p:$a,i(u){D||(S(v.$$.fragment,u),S(H.$$.fragment,u),S(L.$$.fragment,u),D=!0)},o(u){x(v.$$.fragment,u),x(H.$$.fragment,u),x(L.$$.fragment,u),D=!1},d(u){u&&t(n),u&&t(j),z(v,u),u&&t(C),u&&t(k),u&&t(W),z(H,u),u&&t(te),u&&t(N),u&&t(R),z(L,u)}}}function Br(I){let n,_;return n=new rs({props:{$$slots:{default:[Gr]},$$scope:{ctx:I}}}),{c(){q(n.$$.fragment)},l(r){E(n.$$.fragment,r)},m(r,g){T(n,r,g),_=!0},p(r,g){const w={};g&2&&(w.$$scope={dirty:g,ctx:r}),n.$set(w)},i(r){_||(S(n.$$.fragment,r),_=!0)},o(r){x(n.$$.fragment,r),_=!1},d(r){z(n,r)}}}function Yr(I){let n,_,r,g,w,j,v,C,k,F,P,G,U,B,ee,Q,W,H,te,N,oe,R,L,D,u,y,X,J,V,ne,se,me,re,Ie,ie,je,Le,ye,Y,qe,ae,Oe,de,le,ze,_e,fe,pe,b,M,Z,K,Ae,ke,He,ue,ge,ve,Ee,Te,$e,ce,he,Ce,Ne,Se,wt,yt,Je,be,Qe,xe,kt,Ve,l,A,Pe,Ye,vt,Ue,Ge,st,Bt,at,Yt,we,ot,Rt,rt,nt,Kt,lt,jt,Fe,Be,ns,qt,ba,ls,wa,zs,Re,ya,is,ka,va,ps,ja,qa,As,Et,Cs,Wt,Ea,Ps,Ke,cs,Ta,Sa,Tt,xa,ms,za,Aa,Ca,St,Pa,fs,Fa,Ma,Fs,xt,Ms,Me,Da,zt,Ia,La,us,Oa,Ha,hs,Na,Ua,Ds,At,Is,We,Ga,Xt,Ba,Ya,ds,Ra,Ka,Ls,it,Os,Ze,pt,_s,Ct,Wa,gs,Xa,Hs,De,Ja,Pt,Qa,Va,Ft,Za,eo,Mt,to,so,Ns,Dt,Us,ct,ao,It,oo,ro,Gs,Lt,Bs,mt,no,$s,lo,io,Ys,et,ft,bs,Ot,po,ws,co,Rs,ut,Ks,ht,Ws,tt,dt,ys,Ht,mo,ks,fo,Xs,Jt,uo,Js,Qt,ho,Qs,Nt,Vs,Xe,_o,Vt,go,$o,vs,bo,wo,Zs,Ut,ea,_t,yo,js,ko,vo,ta,gt,sa;return j=new os({}),P=new Sr({props:{id:"yHnr5Dk2zCI"}}),Y=new ga({props:{$$slots:{default:[xr]},$$scope:{ctx:I}}}),le=new O({props:{code:"pip install transformers datasets evaluate",highlighted:"pip install transformers datasets evaluate"}}),b=new O({props:{code:`from huggingface_hub import notebook_login

notebook_login()`,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()`}}),ke=new os({}),ce=new O({props:{code:`from datasets import load_dataset

billsum = load_dataset("billsum", split="ca_test")`,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>)`}}),be=new O({props:{code:"billsum = billsum.train_test_split(test_size=0.2)",highlighted:'<span class="hljs-meta">&gt;&gt;&gt; </span>billsum = billsum.train_test_split(test_size=<span class="hljs-number">0.2</span>)'}}),l=new O({props:{code:'billsum["train"][0]',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>}`}}),qt=new os({}),Et=new O({props:{code:`from transformers import AutoTokenizer

tokenizer = AutoTokenizer.from_pretrained("t5-small")`,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;t5-small&quot;</span>)`}}),xt=new O({props:{code:`prefix = "summarize: "


def preprocess_function(examples):
    inputs = [prefix + doc for doc in examples["text"]]
    model_inputs = tokenizer(inputs, max_length=1024, truncation=True)

    labels = tokenizer(text_target=examples["summary"], max_length=128, truncation=True)

    model_inputs["labels"] = labels["input_ids"]
    return model_inputs`,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 O({props:{code:"tokenized_billsum = billsum.map(preprocess_function, batched=True)",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>)'}}),it=new qo({props:{pytorch:!0,tensorflow:!0,jax:!1,$$slots:{tensorflow:[Pr],pytorch:[Ar]},$$scope:{ctx:I}}}),Ct=new os({}),Dt=new O({props:{code:`import evaluate

rouge = evaluate.load("rouge")`,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>)`}}),Lt=new O({props:{code:`import numpy as np


def compute_metrics(eval_pred):
    predictions, labels = eval_pred
    decoded_preds = tokenizer.batch_decode(predictions, skip_special_tokens=True)
    labels = np.where(labels != -100, labels, tokenizer.pad_token_id)
    decoded_labels = tokenizer.batch_decode(labels, skip_special_tokens=True)

    result = rouge.compute(predictions=decoded_preds, references=decoded_labels, use_stemmer=True)

    prediction_lens = [np.count_nonzero(pred != tokenizer.pad_token_id) for pred in predictions]
    result["gen_len"] = np.mean(prediction_lens)

    return {k: round(v, 4) for k, v in result.items()}`,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()}`}}),Ot=new os({}),ut=new qo({props:{pytorch:!0,tensorflow:!0,jax:!1,$$slots:{tensorflow:[Or],pytorch:[Dr]},$$scope:{ctx:I}}}),ht=new ga({props:{$$slots:{default:[Hr]},$$scope:{ctx:I}}}),Ht=new os({}),Nt=new O({props:{code:`text = "summarize: The Inflation Reduction Act lowers prescription drug costs, health care costs, and energy costs. It'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'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."`,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>'}}),Ut=new O({props:{code:`from transformers import pipeline

summarizer = pipeline("summarization", model="stevhliu/my_awesome_billsum_model")
summarizer(text)`,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>}]`}}),gt=new qo({props:{pytorch:!0,tensorflow:!0,jax:!1,$$slots:{tensorflow:[Br],pytorch:[Ur]},$$scope:{ctx:I}}}),{c(){n=i("meta"),_=h(),r=i("h1"),g=i("a"),w=i("span"),q(j.$$.fragment),v=h(),C=i("span"),k=a("Summarization"),F=h(),q(P.$$.fragment),G=h(),U=i("p"),B=a("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:"),ee=h(),Q=i("ul"),W=i("li"),H=a("Extractive: extract the most relevant information from a document."),te=h(),N=i("li"),oe=a("Abstractive: generate new text that captures the most relevant information."),R=h(),L=i("p"),D=a("This guide will show you how to:"),u=h(),y=i("ol"),X=i("li"),J=a("Finetune "),V=i("a"),ne=a("T5"),se=a(" on the California state bill subset of the "),me=i("a"),re=a("BillSum"),Ie=a(" dataset for abstractive summarization."),ie=h(),je=i("li"),Le=a("Use your finetuned model for inference."),ye=h(),q(Y.$$.fragment),qe=h(),ae=i("p"),Oe=a("Before you begin, make sure you have all the necessary libraries installed:"),de=h(),q(le.$$.fragment),ze=h(),_e=i("p"),fe=a("We encourage you to login to your Hugging Face account so you can upload and share your model with the community. When prompted, enter your token to login:"),pe=h(),q(b.$$.fragment),M=h(),Z=i("h2"),K=i("a"),Ae=i("span"),q(ke.$$.fragment),He=h(),ue=i("span"),ge=a("Load BillSum dataset"),ve=h(),Ee=i("p"),Te=a("Start by loading the smaller California state bill subset of the BillSum dataset from the \u{1F917} Datasets library:"),$e=h(),q(ce.$$.fragment),he=h(),Ce=i("p"),Ne=a("Split the dataset into a train and test set with the "),Se=i("a"),wt=a("train_test_split"),yt=a(" method:"),Je=h(),q(be.$$.fragment),Qe=h(),xe=i("p"),kt=a("Then take a look at an example:"),Ve=h(),q(l.$$.fragment),A=h(),Pe=i("p"),Ye=a("There are two fields that you\u2019ll want to use:"),vt=h(),Ue=i("ul"),Ge=i("li"),st=i("code"),Bt=a("text"),at=a(": the text of the bill which\u2019ll be the input to the model."),Yt=h(),we=i("li"),ot=i("code"),Rt=a("summary"),rt=a(": a condensed version of "),nt=i("code"),Kt=a("text"),lt=a(" which\u2019ll be the model target."),jt=h(),Fe=i("h2"),Be=i("a"),ns=i("span"),q(qt.$$.fragment),ba=h(),ls=i("span"),wa=a("Preprocess"),zs=h(),Re=i("p"),ya=a("The next step is to load a T5 tokenizer to process "),is=i("code"),ka=a("text"),va=a(" and "),ps=i("code"),ja=a("summary"),qa=a(":"),As=h(),q(Et.$$.fragment),Cs=h(),Wt=i("p"),Ea=a("The preprocessing function you want to create needs to:"),Ps=h(),Ke=i("ol"),cs=i("li"),Ta=a("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."),Sa=h(),Tt=i("li"),xa=a("Use the keyword "),ms=i("code"),za=a("text_target"),Aa=a(" argument when tokenizing labels."),Ca=h(),St=i("li"),Pa=a("Truncate sequences to be no longer than the maximum length set by the "),fs=i("code"),Fa=a("max_length"),Ma=a(" parameter."),Fs=h(),q(xt.$$.fragment),Ms=h(),Me=i("p"),Da=a("To apply the preprocessing function over the entire dataset, use \u{1F917} Datasets "),zt=i("a"),Ia=a("map"),La=a(" method. You can speed up the "),us=i("code"),Oa=a("map"),Ha=a(" function by setting "),hs=i("code"),Na=a("batched=True"),Ua=a(" to process multiple elements of the dataset at once:"),Ds=h(),q(At.$$.fragment),Is=h(),We=i("p"),Ga=a("Now create a batch of examples using "),Xt=i("a"),Ba=a("DataCollatorForSeq2Seq"),Ya=a(". It\u2019s more efficient to "),ds=i("em"),Ra=a("dynamically pad"),Ka=a(" the sentences to the longest length in a batch during collation, instead of padding the whole dataset to the maximium length."),Ls=h(),q(it.$$.fragment),Os=h(),Ze=i("h2"),pt=i("a"),_s=i("span"),q(Ct.$$.fragment),Wa=h(),gs=i("span"),Xa=a("Evaluate"),Hs=h(),De=i("p"),Ja=a("Including a metric during training is often helpful for evaluating your model\u2019s performance. You can quickly load a evaluation method with the \u{1F917} "),Pt=i("a"),Qa=a("Evaluate"),Va=a(" library. For this task, load the "),Ft=i("a"),Za=a("ROUGE"),eo=a(" metric (see the \u{1F917} Evaluate "),Mt=i("a"),to=a("quick tour"),so=a(" to learn more about how to load and compute a metric):"),Ns=h(),q(Dt.$$.fragment),Us=h(),ct=i("p"),ao=a("Then create a function that passes your predictions and labels to "),It=i("a"),oo=a("compute"),ro=a(" to calculate the ROUGE metric:"),Gs=h(),q(Lt.$$.fragment),Bs=h(),mt=i("p"),no=a("Your "),$s=i("code"),lo=a("compute_metrics"),io=a(" function is ready to go now, and you\u2019ll return to it when you setup your training."),Ys=h(),et=i("h2"),ft=i("a"),bs=i("span"),q(Ot.$$.fragment),po=h(),ws=i("span"),co=a("Train"),Rs=h(),q(ut.$$.fragment),Ks=h(),q(ht.$$.fragment),Ws=h(),tt=i("h2"),dt=i("a"),ys=i("span"),q(Ht.$$.fragment),mo=h(),ks=i("span"),fo=a("Inference"),Xs=h(),Jt=i("p"),uo=a("Great, now that you\u2019ve finetuned a model, you can use it for inference!"),Js=h(),Qt=i("p"),ho=a("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:"),Qs=h(),q(Nt.$$.fragment),Vs=h(),Xe=i("p"),_o=a("The simplest way to try out your finetuned model for inference is to use it in a "),Vt=i("a"),go=a("pipeline()"),$o=a(". Instantiate a "),vs=i("code"),bo=a("pipeline"),wo=a(" for summarization with your model, and pass your text to it:"),Zs=h(),q(Ut.$$.fragment),ea=h(),_t=i("p"),yo=a("You can also manually replicate the results of the "),js=i("code"),ko=a("pipeline"),vo=a(" if you\u2019d like:"),ta=h(),q(gt.$$.fragment),this.h()},l(e){const f=Er('[data-svelte="svelte-1phssyn"]',document.head);n=p(f,"META",{name:!0,content:!0}),f.forEach(t),_=d(e),r=p(e,"H1",{class:!0});var Gt=c(r);g=p(Gt,"A",{id:!0,class:!0,href:!0});var qs=c(g);w=p(qs,"SPAN",{});var Es=c(w);E(j.$$.fragment,Es),Es.forEach(t),qs.forEach(t),v=d(Gt),C=p(Gt,"SPAN",{});var Ts=c(C);k=o(Ts,"Summarization"),Ts.forEach(t),Gt.forEach(t),F=d(e),E(P.$$.fragment,e),G=d(e),U=p(e,"P",{});var Ss=c(U);B=o(Ss,"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:"),Ss.forEach(t),ee=d(e),Q=p(e,"UL",{});var aa=c(Q);W=p(aa,"LI",{});var Eo=c(W);H=o(Eo,"Extractive: extract the most relevant information from a document."),Eo.forEach(t),te=d(aa),N=p(aa,"LI",{});var To=c(N);oe=o(To,"Abstractive: generate new text that captures the most relevant information."),To.forEach(t),aa.forEach(t),R=d(e),L=p(e,"P",{});var So=c(L);D=o(So,"This guide will show you how to:"),So.forEach(t),u=d(e),y=p(e,"OL",{});var oa=c(y);X=p(oa,"LI",{});var Zt=c(X);J=o(Zt,"Finetune "),V=p(Zt,"A",{href:!0,rel:!0});var xo=c(V);ne=o(xo,"T5"),xo.forEach(t),se=o(Zt," on the California state bill subset of the "),me=p(Zt,"A",{href:!0,rel:!0});var zo=c(me);re=o(zo,"BillSum"),zo.forEach(t),Ie=o(Zt," dataset for abstractive summarization."),Zt.forEach(t),ie=d(oa),je=p(oa,"LI",{});var Ao=c(je);Le=o(Ao,"Use your finetuned model for inference."),Ao.forEach(t),oa.forEach(t),ye=d(e),E(Y.$$.fragment,e),qe=d(e),ae=p(e,"P",{});var Co=c(ae);Oe=o(Co,"Before you begin, make sure you have all the necessary libraries installed:"),Co.forEach(t),de=d(e),E(le.$$.fragment,e),ze=d(e),_e=p(e,"P",{});var Po=c(_e);fe=o(Po,"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:"),Po.forEach(t),pe=d(e),E(b.$$.fragment,e),M=d(e),Z=p(e,"H2",{class:!0});var ra=c(Z);K=p(ra,"A",{id:!0,class:!0,href:!0});var Fo=c(K);Ae=p(Fo,"SPAN",{});var Mo=c(Ae);E(ke.$$.fragment,Mo),Mo.forEach(t),Fo.forEach(t),He=d(ra),ue=p(ra,"SPAN",{});var Do=c(ue);ge=o(Do,"Load BillSum dataset"),Do.forEach(t),ra.forEach(t),ve=d(e),Ee=p(e,"P",{});var Io=c(Ee);Te=o(Io,"Start by loading the smaller California state bill subset of the BillSum dataset from the \u{1F917} Datasets library:"),Io.forEach(t),$e=d(e),E(ce.$$.fragment,e),he=d(e),Ce=p(e,"P",{});var na=c(Ce);Ne=o(na,"Split the dataset into a train and test set with the "),Se=p(na,"A",{href:!0,rel:!0});var Lo=c(Se);wt=o(Lo,"train_test_split"),Lo.forEach(t),yt=o(na," method:"),na.forEach(t),Je=d(e),E(be.$$.fragment,e),Qe=d(e),xe=p(e,"P",{});var Oo=c(xe);kt=o(Oo,"Then take a look at an example:"),Oo.forEach(t),Ve=d(e),E(l.$$.fragment,e),A=d(e),Pe=p(e,"P",{});var Ho=c(Pe);Ye=o(Ho,"There are two fields that you\u2019ll want to use:"),Ho.forEach(t),vt=d(e),Ue=p(e,"UL",{});var la=c(Ue);Ge=p(la,"LI",{});var jo=c(Ge);st=p(jo,"CODE",{});var No=c(st);Bt=o(No,"text"),No.forEach(t),at=o(jo,": the text of the bill which\u2019ll be the input to the model."),jo.forEach(t),Yt=d(la),we=p(la,"LI",{});var xs=c(we);ot=p(xs,"CODE",{});var Uo=c(ot);Rt=o(Uo,"summary"),Uo.forEach(t),rt=o(xs,": a condensed version of "),nt=p(xs,"CODE",{});var Go=c(nt);Kt=o(Go,"text"),Go.forEach(t),lt=o(xs," which\u2019ll be the model target."),xs.forEach(t),la.forEach(t),jt=d(e),Fe=p(e,"H2",{class:!0});var ia=c(Fe);Be=p(ia,"A",{id:!0,class:!0,href:!0});var Bo=c(Be);ns=p(Bo,"SPAN",{});var Yo=c(ns);E(qt.$$.fragment,Yo),Yo.forEach(t),Bo.forEach(t),ba=d(ia),ls=p(ia,"SPAN",{});var Ro=c(ls);wa=o(Ro,"Preprocess"),Ro.forEach(t),ia.forEach(t),zs=d(e),Re=p(e,"P",{});var es=c(Re);ya=o(es,"The next step is to load a T5 tokenizer to process "),is=p(es,"CODE",{});var Ko=c(is);ka=o(Ko,"text"),Ko.forEach(t),va=o(es," and "),ps=p(es,"CODE",{});var Wo=c(ps);ja=o(Wo,"summary"),Wo.forEach(t),qa=o(es,":"),es.forEach(t),As=d(e),E(Et.$$.fragment,e),Cs=d(e),Wt=p(e,"P",{});var Xo=c(Wt);Ea=o(Xo,"The preprocessing function you want to create needs to:"),Xo.forEach(t),Ps=d(e),Ke=p(e,"OL",{});var ts=c(Ke);cs=p(ts,"LI",{});var Jo=c(cs);Ta=o(Jo,"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."),Jo.forEach(t),Sa=d(ts),Tt=p(ts,"LI",{});var pa=c(Tt);xa=o(pa,"Use the keyword "),ms=p(pa,"CODE",{});var Qo=c(ms);za=o(Qo,"text_target"),Qo.forEach(t),Aa=o(pa," argument when tokenizing labels."),pa.forEach(t),Ca=d(ts),St=p(ts,"LI",{});var ca=c(St);Pa=o(ca,"Truncate sequences to be no longer than the maximum length set by the "),fs=p(ca,"CODE",{});var Vo=c(fs);Fa=o(Vo,"max_length"),Vo.forEach(t),Ma=o(ca," parameter."),ca.forEach(t),ts.forEach(t),Fs=d(e),E(xt.$$.fragment,e),Ms=d(e),Me=p(e,"P",{});var $t=c(Me);Da=o($t,"To apply the preprocessing function over the entire dataset, use \u{1F917} Datasets "),zt=p($t,"A",{href:!0,rel:!0});var Zo=c(zt);Ia=o(Zo,"map"),Zo.forEach(t),La=o($t," method. You can speed up the "),us=p($t,"CODE",{});var er=c(us);Oa=o(er,"map"),er.forEach(t),Ha=o($t," function by setting "),hs=p($t,"CODE",{});var tr=c(hs);Na=o(tr,"batched=True"),tr.forEach(t),Ua=o($t," to process multiple elements of the dataset at once:"),$t.forEach(t),Ds=d(e),E(At.$$.fragment,e),Is=d(e),We=p(e,"P",{});var ss=c(We);Ga=o(ss,"Now create a batch of examples using "),Xt=p(ss,"A",{href:!0});var sr=c(Xt);Ba=o(sr,"DataCollatorForSeq2Seq"),sr.forEach(t),Ya=o(ss,". It\u2019s more efficient to "),ds=p(ss,"EM",{});var ar=c(ds);Ra=o(ar,"dynamically pad"),ar.forEach(t),Ka=o(ss," the sentences to the longest length in a batch during collation, instead of padding the whole dataset to the maximium length."),ss.forEach(t),Ls=d(e),E(it.$$.fragment,e),Os=d(e),Ze=p(e,"H2",{class:!0});var ma=c(Ze);pt=p(ma,"A",{id:!0,class:!0,href:!0});var or=c(pt);_s=p(or,"SPAN",{});var rr=c(_s);E(Ct.$$.fragment,rr),rr.forEach(t),or.forEach(t),Wa=d(ma),gs=p(ma,"SPAN",{});var nr=c(gs);Xa=o(nr,"Evaluate"),nr.forEach(t),ma.forEach(t),Hs=d(e),De=p(e,"P",{});var bt=c(De);Ja=o(bt,"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} "),Pt=p(bt,"A",{href:!0,rel:!0});var lr=c(Pt);Qa=o(lr,"Evaluate"),lr.forEach(t),Va=o(bt," library. For this task, load the "),Ft=p(bt,"A",{href:!0,rel:!0});var ir=c(Ft);Za=o(ir,"ROUGE"),ir.forEach(t),eo=o(bt," metric (see the \u{1F917} Evaluate "),Mt=p(bt,"A",{href:!0,rel:!0});var pr=c(Mt);to=o(pr,"quick tour"),pr.forEach(t),so=o(bt," to learn more about how to load and compute a metric):"),bt.forEach(t),Ns=d(e),E(Dt.$$.fragment,e),Us=d(e),ct=p(e,"P",{});var fa=c(ct);ao=o(fa,"Then create a function that passes your predictions and labels to "),It=p(fa,"A",{href:!0,rel:!0});var cr=c(It);oo=o(cr,"compute"),cr.forEach(t),ro=o(fa," to calculate the ROUGE metric:"),fa.forEach(t),Gs=d(e),E(Lt.$$.fragment,e),Bs=d(e),mt=p(e,"P",{});var ua=c(mt);no=o(ua,"Your "),$s=p(ua,"CODE",{});var mr=c($s);lo=o(mr,"compute_metrics"),mr.forEach(t),io=o(ua," function is ready to go now, and you\u2019ll return to it when you setup your training."),ua.forEach(t),Ys=d(e),et=p(e,"H2",{class:!0});var ha=c(et);ft=p(ha,"A",{id:!0,class:!0,href:!0});var fr=c(ft);bs=p(fr,"SPAN",{});var ur=c(bs);E(Ot.$$.fragment,ur),ur.forEach(t),fr.forEach(t),po=d(ha),ws=p(ha,"SPAN",{});var hr=c(ws);co=o(hr,"Train"),hr.forEach(t),ha.forEach(t),Rs=d(e),E(ut.$$.fragment,e),Ks=d(e),E(ht.$$.fragment,e),Ws=d(e),tt=p(e,"H2",{class:!0});var da=c(tt);dt=p(da,"A",{id:!0,class:!0,href:!0});var dr=c(dt);ys=p(dr,"SPAN",{});var _r=c(ys);E(Ht.$$.fragment,_r),_r.forEach(t),dr.forEach(t),mo=d(da),ks=p(da,"SPAN",{});var gr=c(ks);fo=o(gr,"Inference"),gr.forEach(t),da.forEach(t),Xs=d(e),Jt=p(e,"P",{});var $r=c(Jt);uo=o($r,"Great, now that you\u2019ve finetuned a model, you can use it for inference!"),$r.forEach(t),Js=d(e),Qt=p(e,"P",{});var br=c(Qt);ho=o(br,"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:"),br.forEach(t),Qs=d(e),E(Nt.$$.fragment,e),Vs=d(e),Xe=p(e,"P",{});var as=c(Xe);_o=o(as,"The simplest way to try out your finetuned model for inference is to use it in a "),Vt=p(as,"A",{href:!0});var wr=c(Vt);go=o(wr,"pipeline()"),wr.forEach(t),$o=o(as,". Instantiate a "),vs=p(as,"CODE",{});var yr=c(vs);bo=o(yr,"pipeline"),yr.forEach(t),wo=o(as," for summarization with your model, and pass your text to it:"),as.forEach(t),Zs=d(e),E(Ut.$$.fragment,e),ea=d(e),_t=p(e,"P",{});var _a=c(_t);yo=o(_a,"You can also manually replicate the results of the "),js=p(_a,"CODE",{});var kr=c(js);ko=o(kr,"pipeline"),kr.forEach(t),vo=o(_a," if you\u2019d like:"),_a.forEach(t),ta=d(e),E(gt.$$.fragment,e),this.h()},h(){$(n,"name","hf:doc:metadata"),$(n,"content",JSON.stringify(Rr)),$(g,"id","summarization"),$(g,"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"),$(g,"href","#summarization"),$(r,"class","relative group"),$(V,"href","https://huggingface.co/t5-small"),$(V,"rel","nofollow"),$(me,"href","https://huggingface.co/datasets/billsum"),$(me,"rel","nofollow"),$(K,"id","load-billsum-dataset"),$(K,"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"),$(K,"href","#load-billsum-dataset"),$(Z,"class","relative group"),$(Se,"href","https://huggingface.co/docs/datasets/v2.7.1/en/package_reference/main_classes#datasets.Dataset.train_test_split"),$(Se,"rel","nofollow"),$(Be,"id","preprocess"),$(Be,"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"),$(Be,"href","#preprocess"),$(Fe,"class","relative group"),$(zt,"href","https://huggingface.co/docs/datasets/v2.7.1/en/package_reference/main_classes#datasets.Dataset.map"),$(zt,"rel","nofollow"),$(Xt,"href","/docs/transformers/v4.25.1/en/main_classes/data_collator#transformers.DataCollatorForSeq2Seq"),$(pt,"id","evaluate"),$(pt,"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"),$(pt,"href","#evaluate"),$(Ze,"class","relative group"),$(Pt,"href","https://huggingface.co/docs/evaluate/index"),$(Pt,"rel","nofollow"),$(Ft,"href","https://huggingface.co/spaces/evaluate-metric/rouge"),$(Ft,"rel","nofollow"),$(Mt,"href","https://huggingface.co/docs/evaluate/a_quick_tour"),$(Mt,"rel","nofollow"),$(It,"href","https://huggingface.co/docs/evaluate/v0.3.0/en/package_reference/main_classes#evaluate.EvaluationModule.compute"),$(It,"rel","nofollow"),$(ft,"id","train"),$(ft,"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"),$(ft,"href","#train"),$(et,"class","relative group"),$(dt,"id","inference"),$(dt,"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"),$(dt,"href","#inference"),$(tt,"class","relative group"),$(Vt,"href","/docs/transformers/v4.25.1/en/main_classes/pipelines#transformers.pipeline")},m(e,f){s(document.head,n),m(e,_,f),m(e,r,f),s(r,g),s(g,w),T(j,w,null),s(r,v),s(r,C),s(C,k),m(e,F,f),T(P,e,f),m(e,G,f),m(e,U,f),s(U,B),m(e,ee,f),m(e,Q,f),s(Q,W),s(W,H),s(Q,te),s(Q,N),s(N,oe),m(e,R,f),m(e,L,f),s(L,D),m(e,u,f),m(e,y,f),s(y,X),s(X,J),s(X,V),s(V,ne),s(X,se),s(X,me),s(me,re),s(X,Ie),s(y,ie),s(y,je),s(je,Le),m(e,ye,f),T(Y,e,f),m(e,qe,f),m(e,ae,f),s(ae,Oe),m(e,de,f),T(le,e,f),m(e,ze,f),m(e,_e,f),s(_e,fe),m(e,pe,f),T(b,e,f),m(e,M,f),m(e,Z,f),s(Z,K),s(K,Ae),T(ke,Ae,null),s(Z,He),s(Z,ue),s(ue,ge),m(e,ve,f),m(e,Ee,f),s(Ee,Te),m(e,$e,f),T(ce,e,f),m(e,he,f),m(e,Ce,f),s(Ce,Ne),s(Ce,Se),s(Se,wt),s(Ce,yt),m(e,Je,f),T(be,e,f),m(e,Qe,f),m(e,xe,f),s(xe,kt),m(e,Ve,f),T(l,e,f),m(e,A,f),m(e,Pe,f),s(Pe,Ye),m(e,vt,f),m(e,Ue,f),s(Ue,Ge),s(Ge,st),s(st,Bt),s(Ge,at),s(Ue,Yt),s(Ue,we),s(we,ot),s(ot,Rt),s(we,rt),s(we,nt),s(nt,Kt),s(we,lt),m(e,jt,f),m(e,Fe,f),s(Fe,Be),s(Be,ns),T(qt,ns,null),s(Fe,ba),s(Fe,ls),s(ls,wa),m(e,zs,f),m(e,Re,f),s(Re,ya),s(Re,is),s(is,ka),s(Re,va),s(Re,ps),s(ps,ja),s(Re,qa),m(e,As,f),T(Et,e,f),m(e,Cs,f),m(e,Wt,f),s(Wt,Ea),m(e,Ps,f),m(e,Ke,f),s(Ke,cs),s(cs,Ta),s(Ke,Sa),s(Ke,Tt),s(Tt,xa),s(Tt,ms),s(ms,za),s(Tt,Aa),s(Ke,Ca),s(Ke,St),s(St,Pa),s(St,fs),s(fs,Fa),s(St,Ma),m(e,Fs,f),T(xt,e,f),m(e,Ms,f),m(e,Me,f),s(Me,Da),s(Me,zt),s(zt,Ia),s(Me,La),s(Me,us),s(us,Oa),s(Me,Ha),s(Me,hs),s(hs,Na),s(Me,Ua),m(e,Ds,f),T(At,e,f),m(e,Is,f),m(e,We,f),s(We,Ga),s(We,Xt),s(Xt,Ba),s(We,Ya),s(We,ds),s(ds,Ra),s(We,Ka),m(e,Ls,f),T(it,e,f),m(e,Os,f),m(e,Ze,f),s(Ze,pt),s(pt,_s),T(Ct,_s,null),s(Ze,Wa),s(Ze,gs),s(gs,Xa),m(e,Hs,f),m(e,De,f),s(De,Ja),s(De,Pt),s(Pt,Qa),s(De,Va),s(De,Ft),s(Ft,Za),s(De,eo),s(De,Mt),s(Mt,to),s(De,so),m(e,Ns,f),T(Dt,e,f),m(e,Us,f),m(e,ct,f),s(ct,ao),s(ct,It),s(It,oo),s(ct,ro),m(e,Gs,f),T(Lt,e,f),m(e,Bs,f),m(e,mt,f),s(mt,no),s(mt,$s),s($s,lo),s(mt,io),m(e,Ys,f),m(e,et,f),s(et,ft),s(ft,bs),T(Ot,bs,null),s(et,po),s(et,ws),s(ws,co),m(e,Rs,f),T(ut,e,f),m(e,Ks,f),T(ht,e,f),m(e,Ws,f),m(e,tt,f),s(tt,dt),s(dt,ys),T(Ht,ys,null),s(tt,mo),s(tt,ks),s(ks,fo),m(e,Xs,f),m(e,Jt,f),s(Jt,uo),m(e,Js,f),m(e,Qt,f),s(Qt,ho),m(e,Qs,f),T(Nt,e,f),m(e,Vs,f),m(e,Xe,f),s(Xe,_o),s(Xe,Vt),s(Vt,go),s(Xe,$o),s(Xe,vs),s(vs,bo),s(Xe,wo),m(e,Zs,f),T(Ut,e,f),m(e,ea,f),m(e,_t,f),s(_t,yo),s(_t,js),s(js,ko),s(_t,vo),m(e,ta,f),T(gt,e,f),sa=!0},p(e,[f]){const Gt={};f&2&&(Gt.$$scope={dirty:f,ctx:e}),Y.$set(Gt);const qs={};f&2&&(qs.$$scope={dirty:f,ctx:e}),it.$set(qs);const Es={};f&2&&(Es.$$scope={dirty:f,ctx:e}),ut.$set(Es);const Ts={};f&2&&(Ts.$$scope={dirty:f,ctx:e}),ht.$set(Ts);const Ss={};f&2&&(Ss.$$scope={dirty:f,ctx:e}),gt.$set(Ss)},i(e){sa||(S(j.$$.fragment,e),S(P.$$.fragment,e),S(Y.$$.fragment,e),S(le.$$.fragment,e),S(b.$$.fragment,e),S(ke.$$.fragment,e),S(ce.$$.fragment,e),S(be.$$.fragment,e),S(l.$$.fragment,e),S(qt.$$.fragment,e),S(Et.$$.fragment,e),S(xt.$$.fragment,e),S(At.$$.fragment,e),S(it.$$.fragment,e),S(Ct.$$.fragment,e),S(Dt.$$.fragment,e),S(Lt.$$.fragment,e),S(Ot.$$.fragment,e),S(ut.$$.fragment,e),S(ht.$$.fragment,e),S(Ht.$$.fragment,e),S(Nt.$$.fragment,e),S(Ut.$$.fragment,e),S(gt.$$.fragment,e),sa=!0)},o(e){x(j.$$.fragment,e),x(P.$$.fragment,e),x(Y.$$.fragment,e),x(le.$$.fragment,e),x(b.$$.fragment,e),x(ke.$$.fragment,e),x(ce.$$.fragment,e),x(be.$$.fragment,e),x(l.$$.fragment,e),x(qt.$$.fragment,e),x(Et.$$.fragment,e),x(xt.$$.fragment,e),x(At.$$.fragment,e),x(it.$$.fragment,e),x(Ct.$$.fragment,e),x(Dt.$$.fragment,e),x(Lt.$$.fragment,e),x(Ot.$$.fragment,e),x(ut.$$.fragment,e),x(ht.$$.fragment,e),x(Ht.$$.fragment,e),x(Nt.$$.fragment,e),x(Ut.$$.fragment,e),x(gt.$$.fragment,e),sa=!1},d(e){t(n),e&&t(_),e&&t(r),z(j),e&&t(F),z(P,e),e&&t(G),e&&t(U),e&&t(ee),e&&t(Q),e&&t(R),e&&t(L),e&&t(u),e&&t(y),e&&t(ye),z(Y,e),e&&t(qe),e&&t(ae),e&&t(de),z(le,e),e&&t(ze),e&&t(_e),e&&t(pe),z(b,e),e&&t(M),e&&t(Z),z(ke),e&&t(ve),e&&t(Ee),e&&t($e),z(ce,e),e&&t(he),e&&t(Ce),e&&t(Je),z(be,e),e&&t(Qe),e&&t(xe),e&&t(Ve),z(l,e),e&&t(A),e&&t(Pe),e&&t(vt),e&&t(Ue),e&&t(jt),e&&t(Fe),z(qt),e&&t(zs),e&&t(Re),e&&t(As),z(Et,e),e&&t(Cs),e&&t(Wt),e&&t(Ps),e&&t(Ke),e&&t(Fs),z(xt,e),e&&t(Ms),e&&t(Me),e&&t(Ds),z(At,e),e&&t(Is),e&&t(We),e&&t(Ls),z(it,e),e&&t(Os),e&&t(Ze),z(Ct),e&&t(Hs),e&&t(De),e&&t(Ns),z(Dt,e),e&&t(Us),e&&t(ct),e&&t(Gs),z(Lt,e),e&&t(Bs),e&&t(mt),e&&t(Ys),e&&t(et),z(Ot),e&&t(Rs),z(ut,e),e&&t(Ks),z(ht,e),e&&t(Ws),e&&t(tt),z(Ht),e&&t(Xs),e&&t(Jt),e&&t(Js),e&&t(Qt),e&&t(Qs),z(Nt,e),e&&t(Vs),e&&t(Xe),e&&t(Zs),z(Ut,e),e&&t(ea),e&&t(_t),e&&t(ta),z(gt,e)}}}const Rr={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 Kr(I){return Tr(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class en extends vr{constructor(n){super();jr(this,n,Kr,Yr,qr,{})}}export{en as default,Rr as metadata};
