import{S as tl,i as al,s as sl,e as i,k as d,w as y,t as l,M as ol,c as p,d as t,m as _,a as c,x as k,h as r,b as v,G as a,g as f,y as j,q as E,o as T,B as x,v as ll,L as is}from"../../chunks/vendor-hf-doc-builder.js";import{T as ya}from"../../chunks/Tip-hf-doc-builder.js";import{Y as rl}from"../../chunks/Youtube-hf-doc-builder.js";import{I as ta}from"../../chunks/IconCopyLink-hf-doc-builder.js";import{C as L}from"../../chunks/CodeBlock-hf-doc-builder.js";import{D as nl}from"../../chunks/DocNotebookDropdown-hf-doc-builder.js";import{F as ro,M as aa}from"../../chunks/Markdown-hf-doc-builder.js";function il(O){let s,g,o,h,b;return{c(){s=i("p"),g=l("See the text classification "),o=i("a"),h=l("task page"),b=l(" for more information about other forms of text classification and their associated models, datasets, and metrics."),this.h()},l(w){s=p(w,"P",{});var P=c(s);g=r(P,"See the text classification "),o=p(P,"A",{href:!0,rel:!0});var q=c(o);h=r(q,"task page"),q.forEach(t),b=r(P," for more information about other forms of text classification and their associated models, datasets, and metrics."),P.forEach(t),this.h()},h(){v(o,"href","https://huggingface.co/tasks/text-classification"),v(o,"rel","nofollow")},m(w,P){f(w,s,P),a(s,g),a(s,o),a(o,h),a(s,b)},d(w){w&&t(s)}}}function pl(O){let s,g;return s=new L({props:{code:`from transformers import DataCollatorWithPadding

data_collator = DataCollatorWithPadding(tokenizer=tokenizer)`,highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> DataCollatorWithPadding

<span class="hljs-meta">&gt;&gt;&gt; </span>data_collator = DataCollatorWithPadding(tokenizer=tokenizer)`}}),{c(){y(s.$$.fragment)},l(o){k(s.$$.fragment,o)},m(o,h){j(s,o,h),g=!0},p:is,i(o){g||(E(s.$$.fragment,o),g=!0)},o(o){T(s.$$.fragment,o),g=!1},d(o){x(s,o)}}}function fl(O){let s,g;return s=new aa({props:{$$slots:{default:[pl]},$$scope:{ctx:O}}}),{c(){y(s.$$.fragment)},l(o){k(s.$$.fragment,o)},m(o,h){j(s,o,h),g=!0},p(o,h){const b={};h&2&&(b.$$scope={dirty:h,ctx:o}),s.$set(b)},i(o){g||(E(s.$$.fragment,o),g=!0)},o(o){T(s.$$.fragment,o),g=!1},d(o){x(s,o)}}}function cl(O){let s,g;return s=new L({props:{code:`from transformers import DataCollatorWithPadding

data_collator = DataCollatorWithPadding(tokenizer=tokenizer, 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> DataCollatorWithPadding

<span class="hljs-meta">&gt;&gt;&gt; </span>data_collator = DataCollatorWithPadding(tokenizer=tokenizer, return_tensors=<span class="hljs-string">&quot;tf&quot;</span>)`}}),{c(){y(s.$$.fragment)},l(o){k(s.$$.fragment,o)},m(o,h){j(s,o,h),g=!0},p:is,i(o){g||(E(s.$$.fragment,o),g=!0)},o(o){T(s.$$.fragment,o),g=!1},d(o){x(s,o)}}}function ml(O){let s,g;return s=new aa({props:{$$slots:{default:[cl]},$$scope:{ctx:O}}}),{c(){y(s.$$.fragment)},l(o){k(s.$$.fragment,o)},m(o,h){j(s,o,h),g=!0},p(o,h){const b={};h&2&&(b.$$scope={dirty:h,ctx:o}),s.$set(b)},i(o){g||(E(s.$$.fragment,o),g=!0)},o(o){T(s.$$.fragment,o),g=!1},d(o){x(s,o)}}}function ul(O){let s,g,o,h,b,w,P,q;return{c(){s=i("p"),g=l("If you aren\u2019t familiar with finetuning a model with the "),o=i("a"),h=l("Trainer"),b=l(", take a look at the basic tutorial "),w=i("a"),P=l("here"),q=l("!"),this.h()},l(A){s=p(A,"P",{});var C=c(s);g=r(C,"If you aren\u2019t familiar with finetuning a model with the "),o=p(C,"A",{href:!0});var S=c(o);h=r(S,"Trainer"),S.forEach(t),b=r(C,", take a look at the basic tutorial "),w=p(C,"A",{href:!0});var I=c(w);P=r(I,"here"),I.forEach(t),q=r(C,"!"),C.forEach(t),this.h()},h(){v(o,"href","/docs/transformers/v4.25.1/en/main_classes/trainer#transformers.Trainer"),v(w,"href","../training#train-with-pytorch-trainer")},m(A,C){f(A,s,C),a(s,g),a(s,o),a(o,h),a(s,b),a(s,w),a(w,P),a(s,q)},d(A){A&&t(s)}}}function hl(O){let s,g,o,h,b,w,P;return{c(){s=i("p"),g=i("a"),o=l("Trainer"),h=l(" applies dynamic padding by default when you pass "),b=i("code"),w=l("tokenizer"),P=l(" to it. In this case, you don\u2019t need to specify a data collator explicitly."),this.h()},l(q){s=p(q,"P",{});var A=c(s);g=p(A,"A",{href:!0});var C=c(g);o=r(C,"Trainer"),C.forEach(t),h=r(A," applies dynamic padding by default when you pass "),b=p(A,"CODE",{});var S=c(b);w=r(S,"tokenizer"),S.forEach(t),P=r(A," to it. In this case, you don\u2019t need to specify a data collator explicitly."),A.forEach(t),this.h()},h(){v(g,"href","/docs/transformers/v4.25.1/en/main_classes/trainer#transformers.Trainer")},m(q,A){f(q,s,A),a(s,g),a(g,o),a(s,h),a(s,b),a(b,w),a(s,P)},d(q){q&&t(s)}}}function dl(O){let s,g,o,h,b,w,P,q,A,C,S,I,N,H,R,U,Q,Y,X,B,G,m,D,F,re,W,J,Me,xe,Ae,ne,ze,Z,he,ae,we,Oe,ye,V,qe,ee,Ce,ie,se,_e,pe,fe,oe,te,ce;return s=new ya({props:{$$slots:{default:[ul]},$$scope:{ctx:O}}}),o=new L({props:{code:`from transformers import AutoModelForSequenceClassification, TrainingArguments, Trainer

model = AutoModelForSequenceClassification.from_pretrained(
    "distilbert-base-uncased", num_labels=2, id2label=id2label, label2id=label2id
)`,highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoModelForSequenceClassification, TrainingArguments, Trainer

<span class="hljs-meta">&gt;&gt;&gt; </span>model = AutoModelForSequenceClassification.from_pretrained(
<span class="hljs-meta">... </span>    <span class="hljs-string">&quot;distilbert-base-uncased&quot;</span>, num_labels=<span class="hljs-number">2</span>, id2label=id2label, label2id=label2id
<span class="hljs-meta">... </span>)`}}),V=new L({props:{code:`training_args = TrainingArguments(
    output_dir="my_awesome_model",
    learning_rate=2e-5,
    per_device_train_batch_size=16,
    per_device_eval_batch_size=16,
    num_train_epochs=2,
    weight_decay=0.01,
    evaluation_strategy="epoch",
    save_strategy="epoch",
    load_best_model_at_end=True,
    push_to_hub=True,
)

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

trainer.train()`,highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span>training_args = TrainingArguments(
<span class="hljs-meta">... </span>    output_dir=<span class="hljs-string">&quot;my_awesome_model&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>    num_train_epochs=<span class="hljs-number">2</span>,
<span class="hljs-meta">... </span>    weight_decay=<span class="hljs-number">0.01</span>,
<span class="hljs-meta">... </span>    evaluation_strategy=<span class="hljs-string">&quot;epoch&quot;</span>,
<span class="hljs-meta">... </span>    save_strategy=<span class="hljs-string">&quot;epoch&quot;</span>,
<span class="hljs-meta">... </span>    load_best_model_at_end=<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 = Trainer(
<span class="hljs-meta">... </span>    model=model,
<span class="hljs-meta">... </span>    args=training_args,
<span class="hljs-meta">... </span>    train_dataset=tokenized_imdb[<span class="hljs-string">&quot;train&quot;</span>],
<span class="hljs-meta">... </span>    eval_dataset=tokenized_imdb[<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()`}}),ee=new ya({props:{$$slots:{default:[hl]},$$scope:{ctx:O}}}),te=new L({props:{code:"trainer.push_to_hub()",highlighted:'<span class="hljs-meta">&gt;&gt;&gt; </span>trainer.push_to_hub()'}}),{c(){y(s.$$.fragment),g=l(`
You're ready to start training your model now! Load DistilBERT with [AutoModelForSequenceClassification](/docs/transformers/v4.25.1/en/model_doc/auto#transformers.AutoModelForSequenceClassification) along with the number of expected labels, and the label mappings:

	`),y(o.$$.fragment),h=d(),b=i("p"),w=l("At this point, only three steps remain:"),P=d(),q=i("ol"),A=i("li"),C=l("Define your training hyperparameters in "),S=i("a"),I=l("TrainingArguments"),N=l(". The only required parameter is "),H=i("code"),R=l("output_dir"),U=l(" which specifies where to save your model. You\u2019ll push this model to the Hub by setting "),Q=i("code"),Y=l("push_to_hub=True"),X=l(" (you need to be signed in to Hugging Face to upload your model). At the end of each epoch, the "),B=i("a"),G=l("Trainer"),m=l(" will evaluate the accuracy and save the training checkpoint."),D=d(),F=i("li"),re=l("Pass the training arguments to "),W=i("a"),J=l("Trainer"),Me=l(" along with the model, dataset, tokenizer, data collator, and "),xe=i("code"),Ae=l("compute_metrics"),ne=l(" function."),ze=d(),Z=i("li"),he=l("Call "),ae=i("a"),we=l("train()"),Oe=l(" to finetune your model."),ye=d(),y(V.$$.fragment),qe=d(),y(ee.$$.fragment),Ce=d(),ie=i("p"),se=l("Once training is completed, share your model to the Hub with the "),_e=i("a"),pe=l("push_to_hub()"),fe=l(" method so everyone can use your model:"),oe=d(),y(te.$$.fragment),this.h()},l($){k(s.$$.fragment,$),g=r($,`
You're ready to start training your model now! Load DistilBERT with [AutoModelForSequenceClassification](/docs/transformers/v4.25.1/en/model_doc/auto#transformers.AutoModelForSequenceClassification) along with the number of expected labels, and the label mappings:

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

batch_size = 16
num_epochs = 5
batches_per_epoch = len(tokenized_imdb["train"]) // batch_size
total_train_steps = int(batches_per_epoch * num_epochs)
optimizer, schedule = create_optimizer(init_lr=2e-5, num_warmup_steps=0, num_train_steps=total_train_steps)`,highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> create_optimizer
<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>batch_size = <span class="hljs-number">16</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>num_epochs = <span class="hljs-number">5</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>batches_per_epoch = <span class="hljs-built_in">len</span>(tokenized_imdb[<span class="hljs-string">&quot;train&quot;</span>]) // batch_size
<span class="hljs-meta">&gt;&gt;&gt; </span>total_train_steps = <span class="hljs-built_in">int</span>(batches_per_epoch * num_epochs)
<span class="hljs-meta">&gt;&gt;&gt; </span>optimizer, schedule = create_optimizer(init_lr=<span class="hljs-number">2e-5</span>, num_warmup_steps=<span class="hljs-number">0</span>, num_train_steps=total_train_steps)`}}),S=new L({props:{code:`from transformers import TFAutoModelForSequenceClassification

model = TFAutoModelForSequenceClassification.from_pretrained(
    "distilbert-base-uncased", num_labels=2, id2label=id2label, label2id=label2id
)`,highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> TFAutoModelForSequenceClassification

<span class="hljs-meta">&gt;&gt;&gt; </span>model = TFAutoModelForSequenceClassification.from_pretrained(
<span class="hljs-meta">... </span>    <span class="hljs-string">&quot;distilbert-base-uncased&quot;</span>, num_labels=<span class="hljs-number">2</span>, id2label=id2label, label2id=label2id
<span class="hljs-meta">... </span>)`}}),m=new L({props:{code:`tf_train_set = model.prepare_tf_dataset(
    tokenized_imdb["train"],
    shuffle=True,
    batch_size=16,
    collate_fn=data_collator,
)

tf_validation_set = model.prepare_tf_dataset(
    tokenized_imdb["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_imdb[<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_validation_set = model.prepare_tf_dataset(
<span class="hljs-meta">... </span>    tokenized_imdb[<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>)`}}),ne=new L({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)`}}),oe=new L({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)`}}),ge=new L({props:{code:`from transformers.keras_callbacks import PushToHubCallback

push_to_hub_callback = PushToHubCallback(
    output_dir="my_awesome_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_model&quot;</span>,
<span class="hljs-meta">... </span>    tokenizer=tokenizer,
<span class="hljs-meta">... </span>)`}}),be=new L({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 L({props:{code:"model.fit(x=tf_train_set, validation_data=tf_validation_set, epochs=3, callbacks=callbacks)",highlighted:'<span class="hljs-meta">&gt;&gt;&gt; </span>model.fit(x=tf_train_set, validation_data=tf_validation_set, epochs=<span class="hljs-number">3</span>, callbacks=callbacks)'}}),{c(){y(s.$$.fragment),g=l(`
To finetune a model in TensorFlow, start by setting up an optimizer function, learning rate schedule, and some training hyperparameters:

	`),y(o.$$.fragment),h=d(),b=i("p"),w=l("Then you can load DistilBERT with "),P=i("a"),q=l("TFAutoModelForSequenceClassification"),A=l(" along with the number of expected labels, and the label mappings:"),C=d(),y(S.$$.fragment),I=d(),N=i("p"),H=l("Convert your datasets to the "),R=i("code"),U=l("tf.data.Dataset"),Q=l(" format with "),Y=i("a"),X=l("prepare_tf_dataset()"),B=l(":"),G=d(),y(m.$$.fragment),D=d(),F=i("p"),re=l("Configure the model for training with "),W=i("a"),J=i("code"),Me=l("compile"),xe=l(":"),Ae=d(),y(ne.$$.fragment),ze=d(),Z=i("p"),he=l("The last two things to setup before you start training is to compute the accuracy from the predictions, and provide a way to push your model to the Hub. Both are done by using "),ae=i("a"),we=l("Keras callbacks"),Oe=l("."),ye=d(),V=i("p"),qe=l("Pass your "),ee=i("code"),Ce=l("compute_metrics"),ie=l(" function to "),se=i("a"),_e=l("KerasMetricCallback"),pe=l(":"),fe=d(),y(oe.$$.fragment),te=d(),ce=i("p"),$=l("Specify where to push your model and tokenizer in the "),M=i("a"),le=l("PushToHubCallback"),K=l(":"),Ne=d(),y(ge.$$.fragment),$e=d(),ke=i("p"),me=l("Then bundle your callbacks together:"),He=d(),y(be.$$.fragment),ue=d(),de=i("p"),ve=l("Finally, you\u2019re ready to start training your model! Call "),je=i("a"),Ge=i("code"),De=l("fit"),Ve=l(" with your training and validation datasets, the number of epochs, and your callbacks to finetune the model:"),Ye=d(),y(Be.$$.fragment),ot=d(),Re=i("p"),Ee=l("Once training is completed, your model is automatically uploaded to the Hub so everyone can use it!"),this.h()},l(n){k(s.$$.fragment,n),g=r(n,`
To finetune a model in TensorFlow, start by setting up an optimizer function, learning rate schedule, and some training hyperparameters:

	`),k(o.$$.fragment,n),h=_(n),b=p(n,"P",{});var z=c(b);w=r(z,"Then you can load DistilBERT with "),P=p(z,"A",{href:!0});var Le=c(P);q=r(Le,"TFAutoModelForSequenceClassification"),Le.forEach(t),A=r(z," along with the number of expected labels, and the label mappings:"),z.forEach(t),C=_(n),k(S.$$.fragment,n),I=_(n),N=p(n,"P",{});var Ue=c(N);H=r(Ue,"Convert your datasets to the "),R=p(Ue,"CODE",{});var Bt=c(R);U=r(Bt,"tf.data.Dataset"),Bt.forEach(t),Q=r(Ue," format with "),Y=p(Ue,"A",{href:!0});var lt=c(Y);X=r(lt,"prepare_tf_dataset()"),lt.forEach(t),B=r(Ue,":"),Ue.forEach(t),G=_(n),k(m.$$.fragment,n),D=_(n),F=p(n,"P",{});var rt=c(F);re=r(rt,"Configure the model for training with "),W=p(rt,"A",{href:!0,rel:!0});var Lt=c(W);J=p(Lt,"CODE",{});var wt=c(J);Me=r(wt,"compile"),wt.forEach(t),Lt.forEach(t),xe=r(rt,":"),rt.forEach(t),Ae=_(n),k(ne.$$.fragment,n),ze=_(n),Z=p(n,"P",{});var Te=c(Z);he=r(Te,"The last two things to setup before you start training is to compute the accuracy from the predictions, and provide a way to push your model to the Hub. Both are done by using "),ae=p(Te,"A",{href:!0});var We=c(ae);we=r(We,"Keras callbacks"),We.forEach(t),Oe=r(Te,"."),Te.forEach(t),ye=_(n),V=p(n,"P",{});var Se=c(V);qe=r(Se,"Pass your "),ee=p(Se,"CODE",{});var Je=c(ee);Ce=r(Je,"compute_metrics"),Je.forEach(t),ie=r(Se," function to "),se=p(Se,"A",{href:!0});var Wt=c(se);_e=r(Wt,"KerasMetricCallback"),Wt.forEach(t),pe=r(Se,":"),Se.forEach(t),fe=_(n),k(oe.$$.fragment,n),te=_(n),ce=p(n,"P",{});var Qe=c(ce);$=r(Qe,"Specify where to push your model and tokenizer in the "),M=p(Qe,"A",{href:!0});var Gt=c(M);le=r(Gt,"PushToHubCallback"),Gt.forEach(t),K=r(Qe,":"),Qe.forEach(t),Ne=_(n),k(ge.$$.fragment,n),$e=_(n),ke=p(n,"P",{});var yt=c(ke);me=r(yt,"Then bundle your callbacks together:"),yt.forEach(t),He=_(n),k(be.$$.fragment,n),ue=_(n),de=p(n,"P",{});var Pe=c(de);ve=r(Pe,"Finally, you\u2019re ready to start training your model! Call "),je=p(Pe,"A",{href:!0,rel:!0});var Vt=c(je);Ge=p(Vt,"CODE",{});var nt=c(Ge);De=r(nt,"fit"),nt.forEach(t),Vt.forEach(t),Ve=r(Pe," with your training and validation datasets, the number of epochs, and your callbacks to finetune the model:"),Pe.forEach(t),Ye=_(n),k(Be.$$.fragment,n),ot=_(n),Re=p(n,"P",{});var Yt=c(Re);Ee=r(Yt,"Once training is completed, your model is automatically uploaded to the Hub so everyone can use it!"),Yt.forEach(t),this.h()},h(){v(P,"href","/docs/transformers/v4.25.1/en/model_doc/auto#transformers.TFAutoModelForSequenceClassification"),v(Y,"href","/docs/transformers/v4.25.1/en/main_classes/model#transformers.TFPreTrainedModel.prepare_tf_dataset"),v(W,"href","https://keras.io/api/models/model_training_apis/#compile-method"),v(W,"rel","nofollow"),v(ae,"href","./main_classes/keras_callbacks"),v(se,"href","/docs/transformers/v4.25.1/en/main_classes/keras_callbacks#transformers.KerasMetricCallback"),v(M,"href","/docs/transformers/v4.25.1/en/main_classes/keras_callbacks#transformers.PushToHubCallback"),v(je,"href","https://keras.io/api/models/model_training_apis/#fit-method"),v(je,"rel","nofollow")},m(n,z){j(s,n,z),f(n,g,z),j(o,n,z),f(n,h,z),f(n,b,z),a(b,w),a(b,P),a(P,q),a(b,A),f(n,C,z),j(S,n,z),f(n,I,z),f(n,N,z),a(N,H),a(N,R),a(R,U),a(N,Q),a(N,Y),a(Y,X),a(N,B),f(n,G,z),j(m,n,z),f(n,D,z),f(n,F,z),a(F,re),a(F,W),a(W,J),a(J,Me),a(F,xe),f(n,Ae,z),j(ne,n,z),f(n,ze,z),f(n,Z,z),a(Z,he),a(Z,ae),a(ae,we),a(Z,Oe),f(n,ye,z),f(n,V,z),a(V,qe),a(V,ee),a(ee,Ce),a(V,ie),a(V,se),a(se,_e),a(V,pe),f(n,fe,z),j(oe,n,z),f(n,te,z),f(n,ce,z),a(ce,$),a(ce,M),a(M,le),a(ce,K),f(n,Ne,z),j(ge,n,z),f(n,$e,z),f(n,ke,z),a(ke,me),f(n,He,z),j(be,n,z),f(n,ue,z),f(n,de,z),a(de,ve),a(de,je),a(je,Ge),a(Ge,De),a(de,Ve),f(n,Ye,z),j(Be,n,z),f(n,ot,z),f(n,Re,z),a(Re,Ee),Ke=!0},p(n,z){const Le={};z&2&&(Le.$$scope={dirty:z,ctx:n}),s.$set(Le)},i(n){Ke||(E(s.$$.fragment,n),E(o.$$.fragment,n),E(S.$$.fragment,n),E(m.$$.fragment,n),E(ne.$$.fragment,n),E(oe.$$.fragment,n),E(ge.$$.fragment,n),E(be.$$.fragment,n),E(Be.$$.fragment,n),Ke=!0)},o(n){T(s.$$.fragment,n),T(o.$$.fragment,n),T(S.$$.fragment,n),T(m.$$.fragment,n),T(ne.$$.fragment,n),T(oe.$$.fragment,n),T(ge.$$.fragment,n),T(be.$$.fragment,n),T(Be.$$.fragment,n),Ke=!1},d(n){x(s,n),n&&t(g),x(o,n),n&&t(h),n&&t(b),n&&t(C),x(S,n),n&&t(I),n&&t(N),n&&t(G),x(m,n),n&&t(D),n&&t(F),n&&t(Ae),x(ne,n),n&&t(ze),n&&t(Z),n&&t(ye),n&&t(V),n&&t(fe),x(oe,n),n&&t(te),n&&t(ce),n&&t(Ne),x(ge,n),n&&t($e),n&&t(ke),n&&t(He),x(be,n),n&&t(ue),n&&t(de),n&&t(Ye),x(Be,n),n&&t(ot),n&&t(Re)}}}function bl(O){let s,g;return s=new aa({props:{$$slots:{default:[$l]},$$scope:{ctx:O}}}),{c(){y(s.$$.fragment)},l(o){k(s.$$.fragment,o)},m(o,h){j(s,o,h),g=!0},p(o,h){const b={};h&2&&(b.$$scope={dirty:h,ctx:o}),s.$set(b)},i(o){g||(E(s.$$.fragment,o),g=!0)},o(o){T(s.$$.fragment,o),g=!1},d(o){x(s,o)}}}function vl(O){let s,g,o,h,b,w,P,q;return{c(){s=i("p"),g=l(`For a more in-depth example of how to finetune a model for text classification, take a look at the corresponding
`),o=i("a"),h=l("PyTorch notebook"),b=l(`
or `),w=i("a"),P=l("TensorFlow notebook"),q=l("."),this.h()},l(A){s=p(A,"P",{});var C=c(s);g=r(C,`For a more in-depth example of how to finetune a model for text classification, take a look at the corresponding
`),o=p(C,"A",{href:!0,rel:!0});var S=c(o);h=r(S,"PyTorch notebook"),S.forEach(t),b=r(C,`
or `),w=p(C,"A",{href:!0,rel:!0});var I=c(w);P=r(I,"TensorFlow notebook"),I.forEach(t),q=r(C,"."),C.forEach(t),this.h()},h(){v(o,"href","https://colab.research.google.com/github/huggingface/notebooks/blob/main/examples/text_classification.ipynb"),v(o,"rel","nofollow"),v(w,"href","https://colab.research.google.com/github/huggingface/notebooks/blob/main/examples/text_classification-tf.ipynb"),v(w,"rel","nofollow")},m(A,C){f(A,s,C),a(s,g),a(s,o),a(o,h),a(s,b),a(s,w),a(w,P),a(s,q)},d(A){A&&t(s)}}}function wl(O){let s,g,o,h,b,w,P,q,A,C,S,I,N,H,R,U,Q,Y,X,B,G;return h=new L({props:{code:`from transformers import AutoTokenizer

tokenizer = AutoTokenizer.from_pretrained("stevhliu/my_awesome_model")
inputs = tokenizer(text, return_tensors="pt")`,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_model&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>inputs = tokenizer(text, return_tensors=<span class="hljs-string">&quot;pt&quot;</span>)`}}),I=new L({props:{code:`from transformers import AutoModelForSequenceClassification

model = AutoModelForSequenceClassification.from_pretrained("stevhliu/my_awesome_model")
with torch.no_grad():
    logits = model(**inputs).logits`,highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoModelForSequenceClassification

<span class="hljs-meta">&gt;&gt;&gt; </span>model = AutoModelForSequenceClassification.from_pretrained(<span class="hljs-string">&quot;stevhliu/my_awesome_model&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">with</span> torch.no_grad():
<span class="hljs-meta">... </span>    logits = model(**inputs).logits`}}),B=new L({props:{code:`predicted_class_id = logits.argmax().item()
model.config.id2label[predicted_class_id]`,highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span>predicted_class_id = logits.argmax().item()
<span class="hljs-meta">&gt;&gt;&gt; </span>model.config.id2label[predicted_class_id]
<span class="hljs-string">&#x27;POSITIVE&#x27;</span>`}}),{c(){s=i("p"),g=l("Tokenize the text and return PyTorch tensors:"),o=d(),y(h.$$.fragment),b=d(),w=i("p"),P=l("Pass your inputs to the model and return the "),q=i("code"),A=l("logits"),C=l(":"),S=d(),y(I.$$.fragment),N=d(),H=i("p"),R=l("Get the class with the highest probability, and use the model\u2019s "),U=i("code"),Q=l("id2label"),Y=l(" mapping to convert it to a text label:"),X=d(),y(B.$$.fragment)},l(m){s=p(m,"P",{});var D=c(s);g=r(D,"Tokenize the text and return PyTorch tensors:"),D.forEach(t),o=_(m),k(h.$$.fragment,m),b=_(m),w=p(m,"P",{});var F=c(w);P=r(F,"Pass your inputs to the model and return the "),q=p(F,"CODE",{});var re=c(q);A=r(re,"logits"),re.forEach(t),C=r(F,":"),F.forEach(t),S=_(m),k(I.$$.fragment,m),N=_(m),H=p(m,"P",{});var W=c(H);R=r(W,"Get the class with the highest probability, and use the model\u2019s "),U=p(W,"CODE",{});var J=c(U);Q=r(J,"id2label"),J.forEach(t),Y=r(W," mapping to convert it to a text label:"),W.forEach(t),X=_(m),k(B.$$.fragment,m)},m(m,D){f(m,s,D),a(s,g),f(m,o,D),j(h,m,D),f(m,b,D),f(m,w,D),a(w,P),a(w,q),a(q,A),a(w,C),f(m,S,D),j(I,m,D),f(m,N,D),f(m,H,D),a(H,R),a(H,U),a(U,Q),a(H,Y),f(m,X,D),j(B,m,D),G=!0},p:is,i(m){G||(E(h.$$.fragment,m),E(I.$$.fragment,m),E(B.$$.fragment,m),G=!0)},o(m){T(h.$$.fragment,m),T(I.$$.fragment,m),T(B.$$.fragment,m),G=!1},d(m){m&&t(s),m&&t(o),x(h,m),m&&t(b),m&&t(w),m&&t(S),x(I,m),m&&t(N),m&&t(H),m&&t(X),x(B,m)}}}function yl(O){let s,g;return s=new aa({props:{$$slots:{default:[wl]},$$scope:{ctx:O}}}),{c(){y(s.$$.fragment)},l(o){k(s.$$.fragment,o)},m(o,h){j(s,o,h),g=!0},p(o,h){const b={};h&2&&(b.$$scope={dirty:h,ctx:o}),s.$set(b)},i(o){g||(E(s.$$.fragment,o),g=!0)},o(o){T(s.$$.fragment,o),g=!1},d(o){x(s,o)}}}function kl(O){let s,g,o,h,b,w,P,q,A,C,S,I,N,H,R,U,Q,Y,X,B,G;return h=new L({props:{code:`from transformers import AutoTokenizer

tokenizer = AutoTokenizer.from_pretrained("stevhliu/my_awesome_model")
inputs = tokenizer(text, 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> AutoTokenizer

<span class="hljs-meta">&gt;&gt;&gt; </span>tokenizer = AutoTokenizer.from_pretrained(<span class="hljs-string">&quot;stevhliu/my_awesome_model&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>inputs = tokenizer(text, return_tensors=<span class="hljs-string">&quot;tf&quot;</span>)`}}),I=new L({props:{code:`from transformers import TFAutoModelForSequenceClassification

model = TFAutoModelForSequenceClassification.from_pretrained("stevhliu/my_awesome_model")
logits = model(**inputs).logits`,highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> TFAutoModelForSequenceClassification

<span class="hljs-meta">&gt;&gt;&gt; </span>model = TFAutoModelForSequenceClassification.from_pretrained(<span class="hljs-string">&quot;stevhliu/my_awesome_model&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>logits = model(**inputs).logits`}}),B=new L({props:{code:`predicted_class_id = int(tf.math.argmax(logits, axis=-1)[0])
model.config.id2label[predicted_class_id]`,highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span>predicted_class_id = <span class="hljs-built_in">int</span>(tf.math.argmax(logits, axis=-<span class="hljs-number">1</span>)[<span class="hljs-number">0</span>])
<span class="hljs-meta">&gt;&gt;&gt; </span>model.config.id2label[predicted_class_id]
<span class="hljs-string">&#x27;POSITIVE&#x27;</span>`}}),{c(){s=i("p"),g=l("Tokenize the text and return TensorFlow tensors:"),o=d(),y(h.$$.fragment),b=d(),w=i("p"),P=l("Pass your inputs to the model and return the "),q=i("code"),A=l("logits"),C=l(":"),S=d(),y(I.$$.fragment),N=d(),H=i("p"),R=l("Get the class with the highest probability, and use the model\u2019s "),U=i("code"),Q=l("id2label"),Y=l(" mapping to convert it to a text label:"),X=d(),y(B.$$.fragment)},l(m){s=p(m,"P",{});var D=c(s);g=r(D,"Tokenize the text and return TensorFlow tensors:"),D.forEach(t),o=_(m),k(h.$$.fragment,m),b=_(m),w=p(m,"P",{});var F=c(w);P=r(F,"Pass your inputs to the model and return the "),q=p(F,"CODE",{});var re=c(q);A=r(re,"logits"),re.forEach(t),C=r(F,":"),F.forEach(t),S=_(m),k(I.$$.fragment,m),N=_(m),H=p(m,"P",{});var W=c(H);R=r(W,"Get the class with the highest probability, and use the model\u2019s "),U=p(W,"CODE",{});var J=c(U);Q=r(J,"id2label"),J.forEach(t),Y=r(W," mapping to convert it to a text label:"),W.forEach(t),X=_(m),k(B.$$.fragment,m)},m(m,D){f(m,s,D),a(s,g),f(m,o,D),j(h,m,D),f(m,b,D),f(m,w,D),a(w,P),a(w,q),a(q,A),a(w,C),f(m,S,D),j(I,m,D),f(m,N,D),f(m,H,D),a(H,R),a(H,U),a(U,Q),a(H,Y),f(m,X,D),j(B,m,D),G=!0},p:is,i(m){G||(E(h.$$.fragment,m),E(I.$$.fragment,m),E(B.$$.fragment,m),G=!0)},o(m){T(h.$$.fragment,m),T(I.$$.fragment,m),T(B.$$.fragment,m),G=!1},d(m){m&&t(s),m&&t(o),x(h,m),m&&t(b),m&&t(w),m&&t(S),x(I,m),m&&t(N),m&&t(H),m&&t(X),x(B,m)}}}function jl(O){let s,g;return s=new aa({props:{$$slots:{default:[kl]},$$scope:{ctx:O}}}),{c(){y(s.$$.fragment)},l(o){k(s.$$.fragment,o)},m(o,h){j(s,o,h),g=!0},p(o,h){const b={};h&2&&(b.$$scope={dirty:h,ctx:o}),s.$set(b)},i(o){g||(E(s.$$.fragment,o),g=!0)},o(o){T(s.$$.fragment,o),g=!1},d(o){x(s,o)}}}function El(O){let s,g,o,h,b,w,P,q,A,C,S,I,N,H,R,U,Q,Y,X,B,G,m,D,F,re,W,J,Me,xe,Ae,ne,ze,Z,he,ae,we,Oe,ye,V,qe,ee,Ce,ie,se,_e,pe,fe,oe,te,ce,$,M,le,K,Ne,ge,$e,ke,me,He,be,ue,de,ve,je,Ge,De,Ve,Ye,Be,ot,Re,Ee,Ke,n,z,Le,Ue,Bt,lt,rt,Lt,wt,Te,We,Se,Je,Wt,Qe,Gt,yt,Pe,Vt,nt,Yt,ps,ka,kt,ja,it,fs,sa,cs,ms,Ea,jt,Ta,Fe,us,Et,hs,ds,oa,_s,gs,la,$s,bs,xa,Tt,qa,Xe,vs,Rt,ws,ys,ra,ks,js,Pa,pt,Aa,tt,ft,na,xt,Es,ia,Ts,za,Ie,xs,qt,qs,Ps,Pt,As,zs,At,Cs,Ds,Ca,zt,Da,ct,Ss,Ct,Fs,Is,Sa,Dt,Fa,mt,Ms,pa,Os,Ns,Ia,at,ut,fa,St,Hs,ca,Bs,Ma,Ze,Ls,ma,Ws,Gs,ua,Vs,Ys,Oa,Ft,Na,ht,Ha,dt,Ba,st,_t,ha,It,Rs,da,Ks,La,Kt,Us,Wa,Ut,Js,Ga,Mt,Va,et,Qs,Jt,Xs,Zs,_a,eo,to,Ya,Ot,Ra,gt,ao,ga,so,oo,Ka,$t,Ua;return w=new ta({}),S=new nl({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/sequence_classification.ipynb"},{label:"PyTorch",value:"https://colab.research.google.com/github/huggingface/notebooks/blob/main/transformers_doc/en/pytorch/sequence_classification.ipynb"},{label:"TensorFlow",value:"https://colab.research.google.com/github/huggingface/notebooks/blob/main/transformers_doc/en/tensorflow/sequence_classification.ipynb"},{label:"Mixed",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/main/transformers_doc/en/sequence_classification.ipynb"},{label:"PyTorch",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/main/transformers_doc/en/pytorch/sequence_classification.ipynb"},{label:"TensorFlow",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/main/transformers_doc/en/tensorflow/sequence_classification.ipynb"}]}}),N=new rl({props:{id:"leNG9fN9FQU"}}),he=new ya({props:{$$slots:{default:[il]},$$scope:{ctx:O}}}),V=new L({props:{code:"pip install transformers datasets evaluate",highlighted:"pip install transformers datasets evaluate"}}),se=new L({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()`}}),te=new ta({}),$e=new L({props:{code:`from datasets import load_dataset

imdb = load_dataset("imdb")`,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>imdb = load_dataset(<span class="hljs-string">&quot;imdb&quot;</span>)`}}),ue=new L({props:{code:'imdb["test"][0]',highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span>imdb[<span class="hljs-string">&quot;test&quot;</span>][<span class="hljs-number">0</span>]
{
    <span class="hljs-string">&quot;label&quot;</span>: <span class="hljs-number">0</span>,
    <span class="hljs-string">&quot;text&quot;</span>: <span class="hljs-string">&quot;I love sci-fi and am willing to put up with a lot. Sci-fi movies/TV are usually underfunded, under-appreciated and misunderstood. I tried to like this, I really did, but it is to good TV sci-fi as Babylon 5 is to Star Trek (the original). Silly prosthetics, cheap cardboard sets, stilted dialogues, CG that doesn&#x27;t match the background, and painfully one-dimensional characters cannot be overcome with a &#x27;sci-fi&#x27; setting. (I&#x27;m sure there are those of you out there who think Babylon 5 is good sci-fi TV. It&#x27;s not. It&#x27;s clich\xE9d and uninspiring.) While US viewers might like emotion and character development, sci-fi is a genre that does not take itself seriously (cf. Star Trek). It may treat important issues, yet not as a serious philosophy. It&#x27;s really difficult to care about the characters here as they are not simply foolish, just missing a spark of life. Their actions and reactions are wooden and predictable, often painful to watch. The makers of Earth KNOW it&#x27;s rubbish as they have to always say \\&quot;Gene Roddenberry&#x27;s Earth...\\&quot; otherwise people would not continue watching. Roddenberry&#x27;s ashes must be turning in their orbit as this dull, cheap, poorly edited (watching it without advert breaks really brings this home) trudging Trabant of a show lumbers into space. Spoiler. So, kill off a main character. And then bring him back as another actor. Jeeez! Dallas all over again.&quot;</span>,
}`}}),Je=new ta({}),kt=new L({props:{code:`from transformers import AutoTokenizer

tokenizer = AutoTokenizer.from_pretrained("distilbert-base-uncased")`,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;distilbert-base-uncased&quot;</span>)`}}),jt=new L({props:{code:`def preprocess_function(examples):
    return tokenizer(examples["text"], truncation=True)`,highlighted:`<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>    <span class="hljs-keyword">return</span> tokenizer(examples[<span class="hljs-string">&quot;text&quot;</span>], truncation=<span class="hljs-literal">True</span>)`}}),Tt=new L({props:{code:"tokenized_imdb = imdb.map(preprocess_function, batched=True)",highlighted:'tokenized_imdb = imdb.<span class="hljs-built_in">map</span>(preprocess_function, batched=<span class="hljs-literal">True</span>)'}}),pt=new ro({props:{pytorch:!0,tensorflow:!0,jax:!1,$$slots:{tensorflow:[ml],pytorch:[fl]},$$scope:{ctx:O}}}),xt=new ta({}),zt=new L({props:{code:`import evaluate

accuracy = evaluate.load("accuracy")`,highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">import</span> evaluate

<span class="hljs-meta">&gt;&gt;&gt; </span>accuracy = evaluate.load(<span class="hljs-string">&quot;accuracy&quot;</span>)`}}),Dt=new L({props:{code:`import numpy as np


def compute_metrics(eval_pred):
    predictions, labels = eval_pred
    predictions = np.argmax(predictions, axis=1)
    return accuracy.compute(predictions=predictions, references=labels)`,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>    predictions = np.argmax(predictions, axis=<span class="hljs-number">1</span>)
<span class="hljs-meta">... </span>    <span class="hljs-keyword">return</span> accuracy.compute(predictions=predictions, references=labels)`}}),St=new ta({}),Ft=new L({props:{code:`id2label = {0: "NEGATIVE", 1: "POSITIVE"}
label2id = {"NEGATIVE": 0, "POSITIVE": 1}`,highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span>id2label = {<span class="hljs-number">0</span>: <span class="hljs-string">&quot;NEGATIVE&quot;</span>, <span class="hljs-number">1</span>: <span class="hljs-string">&quot;POSITIVE&quot;</span>}
<span class="hljs-meta">&gt;&gt;&gt; </span>label2id = {<span class="hljs-string">&quot;NEGATIVE&quot;</span>: <span class="hljs-number">0</span>, <span class="hljs-string">&quot;POSITIVE&quot;</span>: <span class="hljs-number">1</span>}`}}),ht=new ro({props:{pytorch:!0,tensorflow:!0,jax:!1,$$slots:{tensorflow:[bl],pytorch:[_l]},$$scope:{ctx:O}}}),dt=new ya({props:{$$slots:{default:[vl]},$$scope:{ctx:O}}}),It=new ta({}),Mt=new L({props:{code:'text = "This was a masterpiece. Not completely faithful to the books, but enthralling from beginning to end. Might be my favorite of the three."',highlighted:'<span class="hljs-meta">&gt;&gt;&gt; </span>text = <span class="hljs-string">&quot;This was a masterpiece. Not completely faithful to the books, but enthralling from beginning to end. Might be my favorite of the three.&quot;</span>'}}),Ot=new L({props:{code:`from transformers import pipeline

classifier = pipeline("sentiment-analysis", model="stevhliu/my_awesome_model")
classifier(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>classifier = pipeline(<span class="hljs-string">&quot;sentiment-analysis&quot;</span>, model=<span class="hljs-string">&quot;stevhliu/my_awesome_model&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>classifier(text)
[{<span class="hljs-string">&#x27;label&#x27;</span>: <span class="hljs-string">&#x27;POSITIVE&#x27;</span>, <span class="hljs-string">&#x27;score&#x27;</span>: <span class="hljs-number">0.9994940757751465</span>}]`}}),$t=new ro({props:{pytorch:!0,tensorflow:!0,jax:!1,$$slots:{tensorflow:[jl],pytorch:[yl]},$$scope:{ctx:O}}}),{c(){s=i("meta"),g=d(),o=i("h1"),h=i("a"),b=i("span"),y(w.$$.fragment),P=d(),q=i("span"),A=l("Text classification"),C=d(),y(S.$$.fragment),I=d(),y(N.$$.fragment),H=d(),R=i("p"),U=l("Text classification is a common NLP task that assigns a label or class to text. Some of the largest companies run text classification in production for a wide range of practical applications. One of the most popular forms of text classification is sentiment analysis, which assigns a label like \u{1F642} positive, \u{1F641} negative, or \u{1F610} neutral to a sequence of text."),Q=d(),Y=i("p"),X=l("This guide will show you how to:"),B=d(),G=i("ol"),m=i("li"),D=l("Finetune "),F=i("a"),re=l("DistilBERT"),W=l(" on the "),J=i("a"),Me=l("IMDb"),xe=l(" dataset to determine whether a movie review is positive or negative."),Ae=d(),ne=i("li"),ze=l("Use your finetuned model for inference."),Z=d(),y(he.$$.fragment),ae=d(),we=i("p"),Oe=l("Before you begin, make sure you have all the necessary libraries installed:"),ye=d(),y(V.$$.fragment),qe=d(),ee=i("p"),Ce=l("We encourage you to login to your Hugging Face account so you can upload and share your model with the community. When prompted, enter your token to login:"),ie=d(),y(se.$$.fragment),_e=d(),pe=i("h2"),fe=i("a"),oe=i("span"),y(te.$$.fragment),ce=d(),$=i("span"),M=l("Load IMDb dataset"),le=d(),K=i("p"),Ne=l("Start by loading the IMDb dataset from the \u{1F917} Datasets library:"),ge=d(),y($e.$$.fragment),ke=d(),me=i("p"),He=l("Then take a look at an example:"),be=d(),y(ue.$$.fragment),de=d(),ve=i("p"),je=l("There are two fields in this dataset:"),Ge=d(),De=i("ul"),Ve=i("li"),Ye=i("code"),Be=l("text"),ot=l(": the movie review text."),Re=d(),Ee=i("li"),Ke=i("code"),n=l("label"),z=l(": a value that is either "),Le=i("code"),Ue=l("0"),Bt=l(" for a negative review or "),lt=i("code"),rt=l("1"),Lt=l(" for a positive review."),wt=d(),Te=i("h2"),We=i("a"),Se=i("span"),y(Je.$$.fragment),Wt=d(),Qe=i("span"),Gt=l("Preprocess"),yt=d(),Pe=i("p"),Vt=l("The next step is to load a DistilBERT tokenizer to preprocess the "),nt=i("code"),Yt=l("text"),ps=l(" field:"),ka=d(),y(kt.$$.fragment),ja=d(),it=i("p"),fs=l("Create a preprocessing function to tokenize "),sa=i("code"),cs=l("text"),ms=l(" and truncate sequences to be no longer than DistilBERT\u2019s maximum input length:"),Ea=d(),y(jt.$$.fragment),Ta=d(),Fe=i("p"),us=l("To apply the preprocessing function over the entire dataset, use \u{1F917} Datasets "),Et=i("a"),hs=l("map"),ds=l(" function. You can speed up "),oa=i("code"),_s=l("map"),gs=l(" by setting "),la=i("code"),$s=l("batched=True"),bs=l(" to process multiple elements of the dataset at once:"),xa=d(),y(Tt.$$.fragment),qa=d(),Xe=i("p"),vs=l("Now create a batch of examples using "),Rt=i("a"),ws=l("DataCollatorWithPadding"),ys=l(". It\u2019s more efficient to "),ra=i("em"),ks=l("dynamically pad"),js=l(" the sentences to the longest length in a batch during collation, instead of padding the whole dataset to the maximium length."),Pa=d(),y(pt.$$.fragment),Aa=d(),tt=i("h2"),ft=i("a"),na=i("span"),y(xt.$$.fragment),Es=d(),ia=i("span"),Ts=l("Evaluate"),za=d(),Ie=i("p"),xs=l("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} "),qt=i("a"),qs=l("Evaluate"),Ps=l(" library. For this task, load the "),Pt=i("a"),As=l("accuracy"),zs=l(" metric (see the \u{1F917} Evaluate "),At=i("a"),Cs=l("quick tour"),Ds=l(" to learn more about how to load and compute a metric):"),Ca=d(),y(zt.$$.fragment),Da=d(),ct=i("p"),Ss=l("Then create a function that passes your predictions and labels to "),Ct=i("a"),Fs=l("compute"),Is=l(" to calculate the accuracy:"),Sa=d(),y(Dt.$$.fragment),Fa=d(),mt=i("p"),Ms=l("Your "),pa=i("code"),Os=l("compute_metrics"),Ns=l(" function is ready to go now, and you\u2019ll return to it when you setup your training."),Ia=d(),at=i("h2"),ut=i("a"),fa=i("span"),y(St.$$.fragment),Hs=d(),ca=i("span"),Bs=l("Train"),Ma=d(),Ze=i("p"),Ls=l("Before you start training your model, create a map of the expected ids to their labels with "),ma=i("code"),Ws=l("id2label"),Gs=l(" and "),ua=i("code"),Vs=l("label2id"),Ys=l(":"),Oa=d(),y(Ft.$$.fragment),Na=d(),y(ht.$$.fragment),Ha=d(),y(dt.$$.fragment),Ba=d(),st=i("h2"),_t=i("a"),ha=i("span"),y(It.$$.fragment),Rs=d(),da=i("span"),Ks=l("Inference"),La=d(),Kt=i("p"),Us=l("Great, now that you\u2019ve finetuned a model, you can use it for inference!"),Wa=d(),Ut=i("p"),Js=l("Grab some text you\u2019d like to run inference on:"),Ga=d(),y(Mt.$$.fragment),Va=d(),et=i("p"),Qs=l("The simplest way to try out your finetuned model for inference is to use it in a "),Jt=i("a"),Xs=l("pipeline()"),Zs=l(". Instantiate a "),_a=i("code"),eo=l("pipeline"),to=l(" for sentiment analysis with your model, and pass your text to it:"),Ya=d(),y(Ot.$$.fragment),Ra=d(),gt=i("p"),ao=l("You can also manually replicate the results of the "),ga=i("code"),so=l("pipeline"),oo=l(" if you\u2019d like:"),Ka=d(),y($t.$$.fragment),this.h()},l(e){const u=ol('[data-svelte="svelte-1phssyn"]',document.head);s=p(u,"META",{name:!0,content:!0}),u.forEach(t),g=_(e),o=p(e,"H1",{class:!0});var Nt=c(o);h=p(Nt,"A",{id:!0,class:!0,href:!0});var $a=c(h);b=p($a,"SPAN",{});var ba=c(b);k(w.$$.fragment,ba),ba.forEach(t),$a.forEach(t),P=_(Nt),q=p(Nt,"SPAN",{});var va=c(q);A=r(va,"Text classification"),va.forEach(t),Nt.forEach(t),C=_(e),k(S.$$.fragment,e),I=_(e),k(N.$$.fragment,e),H=_(e),R=p(e,"P",{});var wa=c(R);U=r(wa,"Text classification is a common NLP task that assigns a label or class to text. Some of the largest companies run text classification in production for a wide range of practical applications. One of the most popular forms of text classification is sentiment analysis, which assigns a label like \u{1F642} positive, \u{1F641} negative, or \u{1F610} neutral to a sequence of text."),wa.forEach(t),Q=_(e),Y=p(e,"P",{});var no=c(Y);X=r(no,"This guide will show you how to:"),no.forEach(t),B=_(e),G=p(e,"OL",{});var Ja=c(G);m=p(Ja,"LI",{});var Qt=c(m);D=r(Qt,"Finetune "),F=p(Qt,"A",{href:!0,rel:!0});var io=c(F);re=r(io,"DistilBERT"),io.forEach(t),W=r(Qt," on the "),J=p(Qt,"A",{href:!0,rel:!0});var po=c(J);Me=r(po,"IMDb"),po.forEach(t),xe=r(Qt," dataset to determine whether a movie review is positive or negative."),Qt.forEach(t),Ae=_(Ja),ne=p(Ja,"LI",{});var fo=c(ne);ze=r(fo,"Use your finetuned model for inference."),fo.forEach(t),Ja.forEach(t),Z=_(e),k(he.$$.fragment,e),ae=_(e),we=p(e,"P",{});var co=c(we);Oe=r(co,"Before you begin, make sure you have all the necessary libraries installed:"),co.forEach(t),ye=_(e),k(V.$$.fragment,e),qe=_(e),ee=p(e,"P",{});var mo=c(ee);Ce=r(mo,"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:"),mo.forEach(t),ie=_(e),k(se.$$.fragment,e),_e=_(e),pe=p(e,"H2",{class:!0});var Qa=c(pe);fe=p(Qa,"A",{id:!0,class:!0,href:!0});var uo=c(fe);oe=p(uo,"SPAN",{});var ho=c(oe);k(te.$$.fragment,ho),ho.forEach(t),uo.forEach(t),ce=_(Qa),$=p(Qa,"SPAN",{});var _o=c($);M=r(_o,"Load IMDb dataset"),_o.forEach(t),Qa.forEach(t),le=_(e),K=p(e,"P",{});var go=c(K);Ne=r(go,"Start by loading the IMDb dataset from the \u{1F917} Datasets library:"),go.forEach(t),ge=_(e),k($e.$$.fragment,e),ke=_(e),me=p(e,"P",{});var $o=c(me);He=r($o,"Then take a look at an example:"),$o.forEach(t),be=_(e),k(ue.$$.fragment,e),de=_(e),ve=p(e,"P",{});var bo=c(ve);je=r(bo,"There are two fields in this dataset:"),bo.forEach(t),Ge=_(e),De=p(e,"UL",{});var Xa=c(De);Ve=p(Xa,"LI",{});var lo=c(Ve);Ye=p(lo,"CODE",{});var vo=c(Ye);Be=r(vo,"text"),vo.forEach(t),ot=r(lo,": the movie review text."),lo.forEach(t),Re=_(Xa),Ee=p(Xa,"LI",{});var Ht=c(Ee);Ke=p(Ht,"CODE",{});var wo=c(Ke);n=r(wo,"label"),wo.forEach(t),z=r(Ht,": a value that is either "),Le=p(Ht,"CODE",{});var yo=c(Le);Ue=r(yo,"0"),yo.forEach(t),Bt=r(Ht," for a negative review or "),lt=p(Ht,"CODE",{});var ko=c(lt);rt=r(ko,"1"),ko.forEach(t),Lt=r(Ht," for a positive review."),Ht.forEach(t),Xa.forEach(t),wt=_(e),Te=p(e,"H2",{class:!0});var Za=c(Te);We=p(Za,"A",{id:!0,class:!0,href:!0});var jo=c(We);Se=p(jo,"SPAN",{});var Eo=c(Se);k(Je.$$.fragment,Eo),Eo.forEach(t),jo.forEach(t),Wt=_(Za),Qe=p(Za,"SPAN",{});var To=c(Qe);Gt=r(To,"Preprocess"),To.forEach(t),Za.forEach(t),yt=_(e),Pe=p(e,"P",{});var es=c(Pe);Vt=r(es,"The next step is to load a DistilBERT tokenizer to preprocess the "),nt=p(es,"CODE",{});var xo=c(nt);Yt=r(xo,"text"),xo.forEach(t),ps=r(es," field:"),es.forEach(t),ka=_(e),k(kt.$$.fragment,e),ja=_(e),it=p(e,"P",{});var ts=c(it);fs=r(ts,"Create a preprocessing function to tokenize "),sa=p(ts,"CODE",{});var qo=c(sa);cs=r(qo,"text"),qo.forEach(t),ms=r(ts," and truncate sequences to be no longer than DistilBERT\u2019s maximum input length:"),ts.forEach(t),Ea=_(e),k(jt.$$.fragment,e),Ta=_(e),Fe=p(e,"P",{});var bt=c(Fe);us=r(bt,"To apply the preprocessing function over the entire dataset, use \u{1F917} Datasets "),Et=p(bt,"A",{href:!0,rel:!0});var Po=c(Et);hs=r(Po,"map"),Po.forEach(t),ds=r(bt," function. You can speed up "),oa=p(bt,"CODE",{});var Ao=c(oa);_s=r(Ao,"map"),Ao.forEach(t),gs=r(bt," by setting "),la=p(bt,"CODE",{});var zo=c(la);$s=r(zo,"batched=True"),zo.forEach(t),bs=r(bt," to process multiple elements of the dataset at once:"),bt.forEach(t),xa=_(e),k(Tt.$$.fragment,e),qa=_(e),Xe=p(e,"P",{});var Xt=c(Xe);vs=r(Xt,"Now create a batch of examples using "),Rt=p(Xt,"A",{href:!0});var Co=c(Rt);ws=r(Co,"DataCollatorWithPadding"),Co.forEach(t),ys=r(Xt,". It\u2019s more efficient to "),ra=p(Xt,"EM",{});var Do=c(ra);ks=r(Do,"dynamically pad"),Do.forEach(t),js=r(Xt," the sentences to the longest length in a batch during collation, instead of padding the whole dataset to the maximium length."),Xt.forEach(t),Pa=_(e),k(pt.$$.fragment,e),Aa=_(e),tt=p(e,"H2",{class:!0});var as=c(tt);ft=p(as,"A",{id:!0,class:!0,href:!0});var So=c(ft);na=p(So,"SPAN",{});var Fo=c(na);k(xt.$$.fragment,Fo),Fo.forEach(t),So.forEach(t),Es=_(as),ia=p(as,"SPAN",{});var Io=c(ia);Ts=r(Io,"Evaluate"),Io.forEach(t),as.forEach(t),za=_(e),Ie=p(e,"P",{});var vt=c(Ie);xs=r(vt,"Including a metric during training is often helpful for evaluating your model\u2019s performance. You can quickly load a evaluation method with the \u{1F917} "),qt=p(vt,"A",{href:!0,rel:!0});var Mo=c(qt);qs=r(Mo,"Evaluate"),Mo.forEach(t),Ps=r(vt," library. For this task, load the "),Pt=p(vt,"A",{href:!0,rel:!0});var Oo=c(Pt);As=r(Oo,"accuracy"),Oo.forEach(t),zs=r(vt," metric (see the \u{1F917} Evaluate "),At=p(vt,"A",{href:!0,rel:!0});var No=c(At);Cs=r(No,"quick tour"),No.forEach(t),Ds=r(vt," to learn more about how to load and compute a metric):"),vt.forEach(t),Ca=_(e),k(zt.$$.fragment,e),Da=_(e),ct=p(e,"P",{});var ss=c(ct);Ss=r(ss,"Then create a function that passes your predictions and labels to "),Ct=p(ss,"A",{href:!0,rel:!0});var Ho=c(Ct);Fs=r(Ho,"compute"),Ho.forEach(t),Is=r(ss," to calculate the accuracy:"),ss.forEach(t),Sa=_(e),k(Dt.$$.fragment,e),Fa=_(e),mt=p(e,"P",{});var os=c(mt);Ms=r(os,"Your "),pa=p(os,"CODE",{});var Bo=c(pa);Os=r(Bo,"compute_metrics"),Bo.forEach(t),Ns=r(os," function is ready to go now, and you\u2019ll return to it when you setup your training."),os.forEach(t),Ia=_(e),at=p(e,"H2",{class:!0});var ls=c(at);ut=p(ls,"A",{id:!0,class:!0,href:!0});var Lo=c(ut);fa=p(Lo,"SPAN",{});var Wo=c(fa);k(St.$$.fragment,Wo),Wo.forEach(t),Lo.forEach(t),Hs=_(ls),ca=p(ls,"SPAN",{});var Go=c(ca);Bs=r(Go,"Train"),Go.forEach(t),ls.forEach(t),Ma=_(e),Ze=p(e,"P",{});var Zt=c(Ze);Ls=r(Zt,"Before you start training your model, create a map of the expected ids to their labels with "),ma=p(Zt,"CODE",{});var Vo=c(ma);Ws=r(Vo,"id2label"),Vo.forEach(t),Gs=r(Zt," and "),ua=p(Zt,"CODE",{});var Yo=c(ua);Vs=r(Yo,"label2id"),Yo.forEach(t),Ys=r(Zt,":"),Zt.forEach(t),Oa=_(e),k(Ft.$$.fragment,e),Na=_(e),k(ht.$$.fragment,e),Ha=_(e),k(dt.$$.fragment,e),Ba=_(e),st=p(e,"H2",{class:!0});var rs=c(st);_t=p(rs,"A",{id:!0,class:!0,href:!0});var Ro=c(_t);ha=p(Ro,"SPAN",{});var Ko=c(ha);k(It.$$.fragment,Ko),Ko.forEach(t),Ro.forEach(t),Rs=_(rs),da=p(rs,"SPAN",{});var Uo=c(da);Ks=r(Uo,"Inference"),Uo.forEach(t),rs.forEach(t),La=_(e),Kt=p(e,"P",{});var Jo=c(Kt);Us=r(Jo,"Great, now that you\u2019ve finetuned a model, you can use it for inference!"),Jo.forEach(t),Wa=_(e),Ut=p(e,"P",{});var Qo=c(Ut);Js=r(Qo,"Grab some text you\u2019d like to run inference on:"),Qo.forEach(t),Ga=_(e),k(Mt.$$.fragment,e),Va=_(e),et=p(e,"P",{});var ea=c(et);Qs=r(ea,"The simplest way to try out your finetuned model for inference is to use it in a "),Jt=p(ea,"A",{href:!0});var Xo=c(Jt);Xs=r(Xo,"pipeline()"),Xo.forEach(t),Zs=r(ea,". Instantiate a "),_a=p(ea,"CODE",{});var Zo=c(_a);eo=r(Zo,"pipeline"),Zo.forEach(t),to=r(ea," for sentiment analysis with your model, and pass your text to it:"),ea.forEach(t),Ya=_(e),k(Ot.$$.fragment,e),Ra=_(e),gt=p(e,"P",{});var ns=c(gt);ao=r(ns,"You can also manually replicate the results of the "),ga=p(ns,"CODE",{});var el=c(ga);so=r(el,"pipeline"),el.forEach(t),oo=r(ns," if you\u2019d like:"),ns.forEach(t),Ka=_(e),k($t.$$.fragment,e),this.h()},h(){v(s,"name","hf:doc:metadata"),v(s,"content",JSON.stringify(Tl)),v(h,"id","text-classification"),v(h,"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"),v(h,"href","#text-classification"),v(o,"class","relative group"),v(F,"href","https://huggingface.co/distilbert-base-uncased"),v(F,"rel","nofollow"),v(J,"href","https://huggingface.co/datasets/imdb"),v(J,"rel","nofollow"),v(fe,"id","load-imdb-dataset"),v(fe,"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"),v(fe,"href","#load-imdb-dataset"),v(pe,"class","relative group"),v(We,"id","preprocess"),v(We,"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"),v(We,"href","#preprocess"),v(Te,"class","relative group"),v(Et,"href","https://huggingface.co/docs/datasets/v2.7.1/en/package_reference/main_classes#datasets.Dataset.map"),v(Et,"rel","nofollow"),v(Rt,"href","/docs/transformers/v4.25.1/en/main_classes/data_collator#transformers.DataCollatorWithPadding"),v(ft,"id","evaluate"),v(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"),v(ft,"href","#evaluate"),v(tt,"class","relative group"),v(qt,"href","https://huggingface.co/docs/evaluate/index"),v(qt,"rel","nofollow"),v(Pt,"href","https://huggingface.co/spaces/evaluate-metric/accuracy"),v(Pt,"rel","nofollow"),v(At,"href","https://huggingface.co/docs/evaluate/a_quick_tour"),v(At,"rel","nofollow"),v(Ct,"href","https://huggingface.co/docs/evaluate/v0.3.0/en/package_reference/main_classes#evaluate.EvaluationModule.compute"),v(Ct,"rel","nofollow"),v(ut,"id","train"),v(ut,"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"),v(ut,"href","#train"),v(at,"class","relative group"),v(_t,"id","inference"),v(_t,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),v(_t,"href","#inference"),v(st,"class","relative group"),v(Jt,"href","/docs/transformers/v4.25.1/en/main_classes/pipelines#transformers.pipeline")},m(e,u){a(document.head,s),f(e,g,u),f(e,o,u),a(o,h),a(h,b),j(w,b,null),a(o,P),a(o,q),a(q,A),f(e,C,u),j(S,e,u),f(e,I,u),j(N,e,u),f(e,H,u),f(e,R,u),a(R,U),f(e,Q,u),f(e,Y,u),a(Y,X),f(e,B,u),f(e,G,u),a(G,m),a(m,D),a(m,F),a(F,re),a(m,W),a(m,J),a(J,Me),a(m,xe),a(G,Ae),a(G,ne),a(ne,ze),f(e,Z,u),j(he,e,u),f(e,ae,u),f(e,we,u),a(we,Oe),f(e,ye,u),j(V,e,u),f(e,qe,u),f(e,ee,u),a(ee,Ce),f(e,ie,u),j(se,e,u),f(e,_e,u),f(e,pe,u),a(pe,fe),a(fe,oe),j(te,oe,null),a(pe,ce),a(pe,$),a($,M),f(e,le,u),f(e,K,u),a(K,Ne),f(e,ge,u),j($e,e,u),f(e,ke,u),f(e,me,u),a(me,He),f(e,be,u),j(ue,e,u),f(e,de,u),f(e,ve,u),a(ve,je),f(e,Ge,u),f(e,De,u),a(De,Ve),a(Ve,Ye),a(Ye,Be),a(Ve,ot),a(De,Re),a(De,Ee),a(Ee,Ke),a(Ke,n),a(Ee,z),a(Ee,Le),a(Le,Ue),a(Ee,Bt),a(Ee,lt),a(lt,rt),a(Ee,Lt),f(e,wt,u),f(e,Te,u),a(Te,We),a(We,Se),j(Je,Se,null),a(Te,Wt),a(Te,Qe),a(Qe,Gt),f(e,yt,u),f(e,Pe,u),a(Pe,Vt),a(Pe,nt),a(nt,Yt),a(Pe,ps),f(e,ka,u),j(kt,e,u),f(e,ja,u),f(e,it,u),a(it,fs),a(it,sa),a(sa,cs),a(it,ms),f(e,Ea,u),j(jt,e,u),f(e,Ta,u),f(e,Fe,u),a(Fe,us),a(Fe,Et),a(Et,hs),a(Fe,ds),a(Fe,oa),a(oa,_s),a(Fe,gs),a(Fe,la),a(la,$s),a(Fe,bs),f(e,xa,u),j(Tt,e,u),f(e,qa,u),f(e,Xe,u),a(Xe,vs),a(Xe,Rt),a(Rt,ws),a(Xe,ys),a(Xe,ra),a(ra,ks),a(Xe,js),f(e,Pa,u),j(pt,e,u),f(e,Aa,u),f(e,tt,u),a(tt,ft),a(ft,na),j(xt,na,null),a(tt,Es),a(tt,ia),a(ia,Ts),f(e,za,u),f(e,Ie,u),a(Ie,xs),a(Ie,qt),a(qt,qs),a(Ie,Ps),a(Ie,Pt),a(Pt,As),a(Ie,zs),a(Ie,At),a(At,Cs),a(Ie,Ds),f(e,Ca,u),j(zt,e,u),f(e,Da,u),f(e,ct,u),a(ct,Ss),a(ct,Ct),a(Ct,Fs),a(ct,Is),f(e,Sa,u),j(Dt,e,u),f(e,Fa,u),f(e,mt,u),a(mt,Ms),a(mt,pa),a(pa,Os),a(mt,Ns),f(e,Ia,u),f(e,at,u),a(at,ut),a(ut,fa),j(St,fa,null),a(at,Hs),a(at,ca),a(ca,Bs),f(e,Ma,u),f(e,Ze,u),a(Ze,Ls),a(Ze,ma),a(ma,Ws),a(Ze,Gs),a(Ze,ua),a(ua,Vs),a(Ze,Ys),f(e,Oa,u),j(Ft,e,u),f(e,Na,u),j(ht,e,u),f(e,Ha,u),j(dt,e,u),f(e,Ba,u),f(e,st,u),a(st,_t),a(_t,ha),j(It,ha,null),a(st,Rs),a(st,da),a(da,Ks),f(e,La,u),f(e,Kt,u),a(Kt,Us),f(e,Wa,u),f(e,Ut,u),a(Ut,Js),f(e,Ga,u),j(Mt,e,u),f(e,Va,u),f(e,et,u),a(et,Qs),a(et,Jt),a(Jt,Xs),a(et,Zs),a(et,_a),a(_a,eo),a(et,to),f(e,Ya,u),j(Ot,e,u),f(e,Ra,u),f(e,gt,u),a(gt,ao),a(gt,ga),a(ga,so),a(gt,oo),f(e,Ka,u),j($t,e,u),Ua=!0},p(e,[u]){const Nt={};u&2&&(Nt.$$scope={dirty:u,ctx:e}),he.$set(Nt);const $a={};u&2&&($a.$$scope={dirty:u,ctx:e}),pt.$set($a);const ba={};u&2&&(ba.$$scope={dirty:u,ctx:e}),ht.$set(ba);const va={};u&2&&(va.$$scope={dirty:u,ctx:e}),dt.$set(va);const wa={};u&2&&(wa.$$scope={dirty:u,ctx:e}),$t.$set(wa)},i(e){Ua||(E(w.$$.fragment,e),E(S.$$.fragment,e),E(N.$$.fragment,e),E(he.$$.fragment,e),E(V.$$.fragment,e),E(se.$$.fragment,e),E(te.$$.fragment,e),E($e.$$.fragment,e),E(ue.$$.fragment,e),E(Je.$$.fragment,e),E(kt.$$.fragment,e),E(jt.$$.fragment,e),E(Tt.$$.fragment,e),E(pt.$$.fragment,e),E(xt.$$.fragment,e),E(zt.$$.fragment,e),E(Dt.$$.fragment,e),E(St.$$.fragment,e),E(Ft.$$.fragment,e),E(ht.$$.fragment,e),E(dt.$$.fragment,e),E(It.$$.fragment,e),E(Mt.$$.fragment,e),E(Ot.$$.fragment,e),E($t.$$.fragment,e),Ua=!0)},o(e){T(w.$$.fragment,e),T(S.$$.fragment,e),T(N.$$.fragment,e),T(he.$$.fragment,e),T(V.$$.fragment,e),T(se.$$.fragment,e),T(te.$$.fragment,e),T($e.$$.fragment,e),T(ue.$$.fragment,e),T(Je.$$.fragment,e),T(kt.$$.fragment,e),T(jt.$$.fragment,e),T(Tt.$$.fragment,e),T(pt.$$.fragment,e),T(xt.$$.fragment,e),T(zt.$$.fragment,e),T(Dt.$$.fragment,e),T(St.$$.fragment,e),T(Ft.$$.fragment,e),T(ht.$$.fragment,e),T(dt.$$.fragment,e),T(It.$$.fragment,e),T(Mt.$$.fragment,e),T(Ot.$$.fragment,e),T($t.$$.fragment,e),Ua=!1},d(e){t(s),e&&t(g),e&&t(o),x(w),e&&t(C),x(S,e),e&&t(I),x(N,e),e&&t(H),e&&t(R),e&&t(Q),e&&t(Y),e&&t(B),e&&t(G),e&&t(Z),x(he,e),e&&t(ae),e&&t(we),e&&t(ye),x(V,e),e&&t(qe),e&&t(ee),e&&t(ie),x(se,e),e&&t(_e),e&&t(pe),x(te),e&&t(le),e&&t(K),e&&t(ge),x($e,e),e&&t(ke),e&&t(me),e&&t(be),x(ue,e),e&&t(de),e&&t(ve),e&&t(Ge),e&&t(De),e&&t(wt),e&&t(Te),x(Je),e&&t(yt),e&&t(Pe),e&&t(ka),x(kt,e),e&&t(ja),e&&t(it),e&&t(Ea),x(jt,e),e&&t(Ta),e&&t(Fe),e&&t(xa),x(Tt,e),e&&t(qa),e&&t(Xe),e&&t(Pa),x(pt,e),e&&t(Aa),e&&t(tt),x(xt),e&&t(za),e&&t(Ie),e&&t(Ca),x(zt,e),e&&t(Da),e&&t(ct),e&&t(Sa),x(Dt,e),e&&t(Fa),e&&t(mt),e&&t(Ia),e&&t(at),x(St),e&&t(Ma),e&&t(Ze),e&&t(Oa),x(Ft,e),e&&t(Na),x(ht,e),e&&t(Ha),x(dt,e),e&&t(Ba),e&&t(st),x(It),e&&t(La),e&&t(Kt),e&&t(Wa),e&&t(Ut),e&&t(Ga),x(Mt,e),e&&t(Va),e&&t(et),e&&t(Ya),x(Ot,e),e&&t(Ra),e&&t(gt),e&&t(Ka),x($t,e)}}}const Tl={local:"text-classification",sections:[{local:"load-imdb-dataset",title:"Load IMDb dataset"},{local:"preprocess",title:"Preprocess"},{local:"evaluate",title:"Evaluate"},{local:"train",title:"Train"},{local:"inference",title:"Inference"}],title:"Text classification"};function xl(O){return ll(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Fl extends tl{constructor(s){super();al(this,s,xl,El,sl,{})}}export{Fl as default,Tl as metadata};
