import{S as Co,i as Ao,s as Po,e as r,k as f,w,t,M as Oo,c as p,d as e,m as d,a as i,x,h as n,b as j,G as a,g as c,y as v,q as y,o as E,B as q,v as Fo,L as Kt}from"../../chunks/vendor-hf-doc-builder.js";import{T as Gt}from"../../chunks/Tip-hf-doc-builder.js";import{Y as zo}from"../../chunks/Youtube-hf-doc-builder.js";import{I as ba}from"../../chunks/IconCopyLink-hf-doc-builder.js";import{C as I}from"../../chunks/CodeBlock-hf-doc-builder.js";import{D as Bo}from"../../chunks/DocNotebookDropdown-hf-doc-builder.js";import{F as wl,M as $a}from"../../chunks/Markdown-hf-doc-builder.js";function Do(H){let o,_,l,g,$;return{c(){o=r("p"),_=t("See the token classification "),l=r("a"),g=t("task page"),$=t(" for more information about other forms of token classification and their associated models, datasets, and metrics."),this.h()},l(k){o=p(k,"P",{});var C=i(o);_=n(C,"See the token classification "),l=p(C,"A",{href:!0,rel:!0});var z=i(l);g=n(z,"task page"),z.forEach(e),$=n(C," for more information about other forms of token classification and their associated models, datasets, and metrics."),C.forEach(e),this.h()},h(){j(l,"href","https://huggingface.co/tasks/token-classification"),j(l,"rel","nofollow")},m(k,C){c(k,o,C),a(o,_),a(o,l),a(l,g),a(o,$)},d(k){k&&e(o)}}}function Io(H){let o,_;return o=new I({props:{code:`from transformers import DataCollatorForTokenClassification

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

<span class="hljs-meta">&gt;&gt;&gt; </span>data_collator = DataCollatorForTokenClassification(tokenizer=tokenizer)`}}),{c(){w(o.$$.fragment)},l(l){x(o.$$.fragment,l)},m(l,g){v(o,l,g),_=!0},p:Kt,i(l){_||(y(o.$$.fragment,l),_=!0)},o(l){E(o.$$.fragment,l),_=!1},d(l){q(o,l)}}}function So(H){let o,_;return o=new $a({props:{$$slots:{default:[Io]},$$scope:{ctx:H}}}),{c(){w(o.$$.fragment)},l(l){x(o.$$.fragment,l)},m(l,g){v(o,l,g),_=!0},p(l,g){const $={};g&2&&($.$$scope={dirty:g,ctx:l}),o.$set($)},i(l){_||(y(o.$$.fragment,l),_=!0)},o(l){E(o.$$.fragment,l),_=!1},d(l){q(o,l)}}}function Mo(H){let o,_;return o=new I({props:{code:`from transformers import DataCollatorForTokenClassification

data_collator = DataCollatorForTokenClassification(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> DataCollatorForTokenClassification

<span class="hljs-meta">&gt;&gt;&gt; </span>data_collator = DataCollatorForTokenClassification(tokenizer=tokenizer, return_tensors=<span class="hljs-string">&quot;tf&quot;</span>)`}}),{c(){w(o.$$.fragment)},l(l){x(o.$$.fragment,l)},m(l,g){v(o,l,g),_=!0},p:Kt,i(l){_||(y(o.$$.fragment,l),_=!0)},o(l){E(o.$$.fragment,l),_=!1},d(l){q(o,l)}}}function No(H){let o,_;return o=new $a({props:{$$slots:{default:[Mo]},$$scope:{ctx:H}}}),{c(){w(o.$$.fragment)},l(l){x(o.$$.fragment,l)},m(l,g){v(o,l,g),_=!0},p(l,g){const $={};g&2&&($.$$scope={dirty:g,ctx:l}),o.$set($)},i(l){_||(y(o.$$.fragment,l),_=!0)},o(l){E(o.$$.fragment,l),_=!1},d(l){q(o,l)}}}function Ho(H){let o,_,l,g,$,k,C,z;return{c(){o=r("p"),_=t("If you aren\u2019t familiar with finetuning a model with the "),l=r("a"),g=t("Trainer"),$=t(", take a look at the basic tutorial "),k=r("a"),C=t("here"),z=t("!"),this.h()},l(P){o=p(P,"P",{});var O=i(o);_=n(O,"If you aren\u2019t familiar with finetuning a model with the "),l=p(O,"A",{href:!0});var F=i(l);g=n(F,"Trainer"),F.forEach(e),$=n(O,", take a look at the basic tutorial "),k=p(O,"A",{href:!0});var D=i(k);C=n(D,"here"),D.forEach(e),z=n(O,"!"),O.forEach(e),this.h()},h(){j(l,"href","/docs/transformers/v4.25.1/en/main_classes/trainer#transformers.Trainer"),j(k,"href","../training#train-with-pytorch-trainer")},m(P,O){c(P,o,O),a(o,_),a(o,l),a(l,g),a(o,$),a(o,k),a(k,C),a(o,z)},d(P){P&&e(o)}}}function Lo(H){let o,_,l,g,$,k,C,z,P,O,F,D,S,M,K,U,Z,G,J,L,Y,m,A,B,ps,R,V,Fs,xs,Ts,is,zs,Q,us,ns,$s,Bs,ks,W,vs,X,Ds,fs,ls,Cs,os,ss,rs;return o=new Gt({props:{$$slots:{default:[Ho]},$$scope:{ctx:H}}}),l=new I({props:{code:`from transformers import AutoModelForTokenClassification, TrainingArguments, Trainer

model = AutoModelForTokenClassification.from_pretrained(
    "distilbert-base-uncased", num_labels=13, 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> AutoModelForTokenClassification, TrainingArguments, Trainer

<span class="hljs-meta">&gt;&gt;&gt; </span>model = AutoModelForTokenClassification.from_pretrained(
<span class="hljs-meta">... </span>    <span class="hljs-string">&quot;distilbert-base-uncased&quot;</span>, num_labels=<span class="hljs-number">13</span>, id2label=id2label, label2id=label2id
<span class="hljs-meta">... </span>)`}}),W=new I({props:{code:`training_args = TrainingArguments(
    output_dir="my_awesome_wnut_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_wnut["train"],
    eval_dataset=tokenized_wnut["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_wnut_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_wnut[<span class="hljs-string">&quot;train&quot;</span>],
<span class="hljs-meta">... </span>    eval_dataset=tokenized_wnut[<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()`}}),ss=new I({props:{code:"trainer.push_to_hub()",highlighted:'<span class="hljs-meta">&gt;&gt;&gt; </span>trainer.push_to_hub()'}}),{c(){w(o.$$.fragment),_=t(`
You're ready to start training your model now! Load DistilBERT with [AutoModelForTokenClassification](/docs/transformers/v4.25.1/en/model_doc/auto#transformers.AutoModelForTokenClassification) along with the number of expected labels, and the label mappings:

	`),w(l.$$.fragment),g=f(),$=r("p"),k=t("At this point, only three steps remain:"),C=f(),z=r("ol"),P=r("li"),O=t("Define your training hyperparameters in "),F=r("a"),D=t("TrainingArguments"),S=t(". The only required parameter is "),M=r("code"),K=t("output_dir"),U=t(" which specifies where to save your model. You\u2019ll push this model to the Hub by setting "),Z=r("code"),G=t("push_to_hub=True"),J=t(" (you need to be signed in to Hugging Face to upload your model). At the end of each epoch, the "),L=r("a"),Y=t("Trainer"),m=t(" will evaluate the seqeval scores and save the training checkpoint."),A=f(),B=r("li"),ps=t("Pass the training arguments to "),R=r("a"),V=t("Trainer"),Fs=t(" along with the model, dataset, tokenizer, data collator, and "),xs=r("code"),Ts=t("compute_metrics"),is=t(" function."),zs=f(),Q=r("li"),us=t("Call "),ns=r("a"),$s=t("train()"),Bs=t(" to finetune your model."),ks=f(),w(W.$$.fragment),vs=f(),X=r("p"),Ds=t("Once training is completed, share your model to the Hub with the "),fs=r("a"),ls=t("push_to_hub()"),Cs=t(" method so everyone can use your model:"),os=f(),w(ss.$$.fragment),this.h()},l(b){x(o.$$.fragment,b),_=n(b,`
You're ready to start training your model now! Load DistilBERT with [AutoModelForTokenClassification](/docs/transformers/v4.25.1/en/model_doc/auto#transformers.AutoModelForTokenClassification) along with the number of expected labels, and the label mappings:

	`),x(l.$$.fragment,b),g=d(b),$=p(b,"P",{});var N=i($);k=n(N,"At this point, only three steps remain:"),N.forEach(e),C=d(b),z=p(b,"OL",{});var as=i(z);P=p(as,"LI",{});var es=i(P);O=n(es,"Define your training hyperparameters in "),F=p(es,"A",{href:!0});var Is=i(F);D=n(Is,"TrainingArguments"),Is.forEach(e),S=n(es,". The only required parameter is "),M=p(es,"CODE",{});var ys=i(M);K=n(ys,"output_dir"),ys.forEach(e),U=n(es," which specifies where to save your model. You\u2019ll push this model to the Hub by setting "),Z=p(es,"CODE",{});var Ss=i(Z);G=n(Ss,"push_to_hub=True"),Ss.forEach(e),J=n(es," (you need to be signed in to Hugging Face to upload your model). At the end of each epoch, the "),L=p(es,"A",{href:!0});var ds=i(L);Y=n(ds,"Trainer"),ds.forEach(e),m=n(es," will evaluate the seqeval scores and save the training checkpoint."),es.forEach(e),A=d(as),B=p(as,"LI",{});var ts=i(B);ps=n(ts,"Pass the training arguments to "),R=p(ts,"A",{href:!0});var ws=i(R);V=n(ws,"Trainer"),ws.forEach(e),Fs=n(ts," along with the model, dataset, tokenizer, data collator, and "),xs=p(ts,"CODE",{});var Es=i(xs);Ts=n(Es,"compute_metrics"),Es.forEach(e),is=n(ts," function."),ts.forEach(e),zs=d(as),Q=p(as,"LI",{});var qs=i(Q);us=n(qs,"Call "),ns=p(qs,"A",{href:!0});var gs=i(ns);$s=n(gs,"train()"),gs.forEach(e),Bs=n(qs," to finetune your model."),qs.forEach(e),as.forEach(e),ks=d(b),x(W.$$.fragment,b),vs=d(b),X=p(b,"P",{});var cs=i(X);Ds=n(cs,"Once training is completed, share your model to the Hub with the "),fs=p(cs,"A",{href:!0});var ms=i(fs);ls=n(ms,"push_to_hub()"),ms.forEach(e),Cs=n(cs," method so everyone can use your model:"),cs.forEach(e),os=d(b),x(ss.$$.fragment,b),this.h()},h(){j(F,"href","/docs/transformers/v4.25.1/en/main_classes/trainer#transformers.TrainingArguments"),j(L,"href","/docs/transformers/v4.25.1/en/main_classes/trainer#transformers.Trainer"),j(R,"href","/docs/transformers/v4.25.1/en/main_classes/trainer#transformers.Trainer"),j(ns,"href","/docs/transformers/v4.25.1/en/main_classes/trainer#transformers.Trainer.train"),j(fs,"href","/docs/transformers/v4.25.1/en/main_classes/trainer#transformers.Trainer.push_to_hub")},m(b,N){v(o,b,N),c(b,_,N),v(l,b,N),c(b,g,N),c(b,$,N),a($,k),c(b,C,N),c(b,z,N),a(z,P),a(P,O),a(P,F),a(F,D),a(P,S),a(P,M),a(M,K),a(P,U),a(P,Z),a(Z,G),a(P,J),a(P,L),a(L,Y),a(P,m),a(z,A),a(z,B),a(B,ps),a(B,R),a(R,V),a(B,Fs),a(B,xs),a(xs,Ts),a(B,is),a(z,zs),a(z,Q),a(Q,us),a(Q,ns),a(ns,$s),a(Q,Bs),c(b,ks,N),v(W,b,N),c(b,vs,N),c(b,X,N),a(X,Ds),a(X,fs),a(fs,ls),a(X,Cs),c(b,os,N),v(ss,b,N),rs=!0},p(b,N){const as={};N&2&&(as.$$scope={dirty:N,ctx:b}),o.$set(as)},i(b){rs||(y(o.$$.fragment,b),y(l.$$.fragment,b),y(W.$$.fragment,b),y(ss.$$.fragment,b),rs=!0)},o(b){E(o.$$.fragment,b),E(l.$$.fragment,b),E(W.$$.fragment,b),E(ss.$$.fragment,b),rs=!1},d(b){q(o,b),b&&e(_),q(l,b),b&&e(g),b&&e($),b&&e(C),b&&e(z),b&&e(ks),q(W,b),b&&e(vs),b&&e(X),b&&e(os),q(ss,b)}}}function Ro(H){let o,_;return o=new $a({props:{$$slots:{default:[Lo]},$$scope:{ctx:H}}}),{c(){w(o.$$.fragment)},l(l){x(o.$$.fragment,l)},m(l,g){v(o,l,g),_=!0},p(l,g){const $={};g&2&&($.$$scope={dirty:g,ctx:l}),o.$set($)},i(l){_||(y(o.$$.fragment,l),_=!0)},o(l){E(o.$$.fragment,l),_=!1},d(l){q(o,l)}}}function Yo(H){let o,_,l,g,$;return{c(){o=r("p"),_=t("If you aren\u2019t familiar with finetuning a model with Keras, take a look at the basic tutorial "),l=r("a"),g=t("here"),$=t("!"),this.h()},l(k){o=p(k,"P",{});var C=i(o);_=n(C,"If you aren\u2019t familiar with finetuning a model with Keras, take a look at the basic tutorial "),l=p(C,"A",{href:!0});var z=i(l);g=n(z,"here"),z.forEach(e),$=n(C,"!"),C.forEach(e),this.h()},h(){j(l,"href","../training#train-a-tensorflow-model-with-keras")},m(k,C){c(k,o,C),a(o,_),a(o,l),a(l,g),a(o,$)},d(k){k&&e(o)}}}function Wo(H){let o,_,l,g,$,k,C,z,P,O,F,D,S,M,K,U,Z,G,J,L,Y,m,A,B,ps,R,V,Fs,xs,Ts,is,zs,Q,us,ns,$s,Bs,ks,W,vs,X,Ds,fs,ls,Cs,os,ss,rs,b,N,as,es,Is,ys,Ss,ds,ts,ws,Es,qs,gs,cs,ms,As,Ms,Ns,qe,Te,Js,_s,Qs,js,ze,Ls;return o=new Gt({props:{$$slots:{default:[Yo]},$$scope:{ctx:H}}}),l=new I({props:{code:`from transformers import create_optimizer

batch_size = 16
num_train_epochs = 3
num_train_steps = (len(tokenized_wnut["train"]) // batch_size) * num_train_epochs
optimizer, lr_schedule = create_optimizer(
    init_lr=2e-5,
    num_train_steps=num_train_steps,
    weight_decay_rate=0.01,
    num_warmup_steps=0,
)`,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>batch_size = <span class="hljs-number">16</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>num_train_epochs = <span class="hljs-number">3</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>num_train_steps = (<span class="hljs-built_in">len</span>(tokenized_wnut[<span class="hljs-string">&quot;train&quot;</span>]) // batch_size) * num_train_epochs
<span class="hljs-meta">&gt;&gt;&gt; </span>optimizer, lr_schedule = create_optimizer(
<span class="hljs-meta">... </span>    init_lr=<span class="hljs-number">2e-5</span>,
<span class="hljs-meta">... </span>    num_train_steps=num_train_steps,
<span class="hljs-meta">... </span>    weight_decay_rate=<span class="hljs-number">0.01</span>,
<span class="hljs-meta">... </span>    num_warmup_steps=<span class="hljs-number">0</span>,
<span class="hljs-meta">... </span>)`}}),F=new I({props:{code:`from transformers import TFAutoModelForTokenClassification

model = TFAutoModelForTokenClassification.from_pretrained(
    "distilbert-base-uncased", num_labels=13, 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> TFAutoModelForTokenClassification

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

tf_validation_set = model.prepare_tf_dataset(
    tokenized_wnut["validation"],
    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_wnut[<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_wnut[<span class="hljs-string">&quot;validation&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>)`}}),is=new I({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)`}}),rs=new I({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)`}}),ds=new I({props:{code:`from transformers.keras_callbacks import PushToHubCallback

push_to_hub_callback = PushToHubCallback(
    output_dir="my_awesome_wnut_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_wnut_model&quot;</span>,
<span class="hljs-meta">... </span>    tokenizer=tokenizer,
<span class="hljs-meta">... </span>)`}}),gs=new I({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]'}}),_s=new I({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(){w(o.$$.fragment),_=t(`
To finetune a model in TensorFlow, start by setting up an optimizer function, learning rate schedule, and some training hyperparameters:

	`),w(l.$$.fragment),g=f(),$=r("p"),k=t("Then you can load DistilBERT with "),C=r("a"),z=t("TFAutoModelForTokenClassification"),P=t(" along with the number of expected labels, and the label mappings:"),O=f(),w(F.$$.fragment),D=f(),S=r("p"),M=t("Convert your datasets to the "),K=r("code"),U=t("tf.data.Dataset"),Z=t(" format with "),G=r("a"),J=t("prepare_tf_dataset()"),L=t(":"),Y=f(),w(m.$$.fragment),A=f(),B=r("p"),ps=t("Configure the model for training with "),R=r("a"),V=r("code"),Fs=t("compile"),xs=t(":"),Ts=f(),w(is.$$.fragment),zs=f(),Q=r("p"),us=t("The last two things to setup before you start training is to compute the seqeval scores from the predictions, and provide a way to push your model to the Hub. Both are done by using "),ns=r("a"),$s=t("Keras callbacks"),Bs=t("."),ks=f(),W=r("p"),vs=t("Pass your "),X=r("code"),Ds=t("compute_metrics"),fs=t(" function to "),ls=r("a"),Cs=t("KerasMetricCallback"),os=t(":"),ss=f(),w(rs.$$.fragment),b=f(),N=r("p"),as=t("Specify where to push your model and tokenizer in the "),es=r("a"),Is=t("PushToHubCallback"),ys=t(":"),Ss=f(),w(ds.$$.fragment),ts=f(),ws=r("p"),Es=t("Then bundle your callbacks together:"),qs=f(),w(gs.$$.fragment),cs=f(),ms=r("p"),As=t("Finally, you\u2019re ready to start training your model! Call "),Ms=r("a"),Ns=r("code"),qe=t("fit"),Te=t(" with your training and validation datasets, the number of epochs, and your callbacks to finetune the model:"),Js=f(),w(_s.$$.fragment),Qs=f(),js=r("p"),ze=t("Once training is completed, your model is automatically uploaded to the Hub so everyone can use it!"),this.h()},l(h){x(o.$$.fragment,h),_=n(h,`
To finetune a model in TensorFlow, start by setting up an optimizer function, learning rate schedule, and some training hyperparameters:

	`),x(l.$$.fragment,h),g=d(h),$=p(h,"P",{});var T=i($);k=n(T,"Then you can load DistilBERT with "),C=p(T,"A",{href:!0});var Rs=i(C);z=n(Rs,"TFAutoModelForTokenClassification"),Rs.forEach(e),P=n(T," along with the number of expected labels, and the label mappings:"),T.forEach(e),O=d(h),x(F.$$.fragment,h),D=d(h),S=p(h,"P",{});var hs=i(S);M=n(hs,"Convert your datasets to the "),K=p(hs,"CODE",{});var Xs=i(K);U=n(Xs,"tf.data.Dataset"),Xs.forEach(e),Z=n(hs," format with "),G=p(hs,"A",{href:!0});var le=i(G);J=n(le,"prepare_tf_dataset()"),le.forEach(e),L=n(hs,":"),hs.forEach(e),Y=d(h),x(m.$$.fragment,h),A=d(h),B=p(h,"P",{});var oe=i(B);ps=n(oe,"Configure the model for training with "),R=p(oe,"A",{href:!0,rel:!0});var sa=i(R);V=p(sa,"CODE",{});var ea=i(V);Fs=n(ea,"compile"),ea.forEach(e),sa.forEach(e),xs=n(oe,":"),oe.forEach(e),Ts=d(h),x(is.$$.fragment,h),zs=d(h),Q=p(h,"P",{});var bs=i(Q);us=n(bs,"The last two things to setup before you start training is to compute the seqeval scores from the predictions, and provide a way to push your model to the Hub. Both are done by using "),ns=p(bs,"A",{href:!0});var re=i(ns);$s=n(re,"Keras callbacks"),re.forEach(e),Bs=n(bs,"."),bs.forEach(e),ks=d(h),W=p(h,"P",{});var Ys=i(W);vs=n(Ys,"Pass your "),X=p(Ys,"CODE",{});var aa=i(X);Ds=n(aa,"compute_metrics"),aa.forEach(e),fs=n(Ys," function to "),ls=p(Ys,"A",{href:!0});var pe=i(ls);Cs=n(pe,"KerasMetricCallback"),pe.forEach(e),os=n(Ys,":"),Ys.forEach(e),ss=d(h),x(rs.$$.fragment,h),b=d(h),N=p(h,"P",{});var ie=i(N);as=n(ie,"Specify where to push your model and tokenizer in the "),es=p(ie,"A",{href:!0});var ta=i(es);Is=n(ta,"PushToHubCallback"),ta.forEach(e),ys=n(ie,":"),ie.forEach(e),Ss=d(h),x(ds.$$.fragment,h),ts=d(h),ws=p(h,"P",{});var ce=i(ws);Es=n(ce,"Then bundle your callbacks together:"),ce.forEach(e),qs=d(h),x(gs.$$.fragment,h),cs=d(h),ms=p(h,"P",{});var he=i(ms);As=n(he,"Finally, you\u2019re ready to start training your model! Call "),Ms=p(he,"A",{href:!0,rel:!0});var na=i(Ms);Ns=p(na,"CODE",{});var la=i(Ns);qe=n(la,"fit"),la.forEach(e),na.forEach(e),Te=n(he," with your training and validation datasets, the number of epochs, and your callbacks to finetune the model:"),he.forEach(e),Js=d(h),x(_s.$$.fragment,h),Qs=d(h),js=p(h,"P",{});var se=i(js);ze=n(se,"Once training is completed, your model is automatically uploaded to the Hub so everyone can use it!"),se.forEach(e),this.h()},h(){j(C,"href","/docs/transformers/v4.25.1/en/model_doc/auto#transformers.TFAutoModelForTokenClassification"),j(G,"href","/docs/transformers/v4.25.1/en/main_classes/model#transformers.TFPreTrainedModel.prepare_tf_dataset"),j(R,"href","https://keras.io/api/models/model_training_apis/#compile-method"),j(R,"rel","nofollow"),j(ns,"href","./main_classes/keras_callbacks"),j(ls,"href","/docs/transformers/v4.25.1/en/main_classes/keras_callbacks#transformers.KerasMetricCallback"),j(es,"href","/docs/transformers/v4.25.1/en/main_classes/keras_callbacks#transformers.PushToHubCallback"),j(Ms,"href","https://keras.io/api/models/model_training_apis/#fit-method"),j(Ms,"rel","nofollow")},m(h,T){v(o,h,T),c(h,_,T),v(l,h,T),c(h,g,T),c(h,$,T),a($,k),a($,C),a(C,z),a($,P),c(h,O,T),v(F,h,T),c(h,D,T),c(h,S,T),a(S,M),a(S,K),a(K,U),a(S,Z),a(S,G),a(G,J),a(S,L),c(h,Y,T),v(m,h,T),c(h,A,T),c(h,B,T),a(B,ps),a(B,R),a(R,V),a(V,Fs),a(B,xs),c(h,Ts,T),v(is,h,T),c(h,zs,T),c(h,Q,T),a(Q,us),a(Q,ns),a(ns,$s),a(Q,Bs),c(h,ks,T),c(h,W,T),a(W,vs),a(W,X),a(X,Ds),a(W,fs),a(W,ls),a(ls,Cs),a(W,os),c(h,ss,T),v(rs,h,T),c(h,b,T),c(h,N,T),a(N,as),a(N,es),a(es,Is),a(N,ys),c(h,Ss,T),v(ds,h,T),c(h,ts,T),c(h,ws,T),a(ws,Es),c(h,qs,T),v(gs,h,T),c(h,cs,T),c(h,ms,T),a(ms,As),a(ms,Ms),a(Ms,Ns),a(Ns,qe),a(ms,Te),c(h,Js,T),v(_s,h,T),c(h,Qs,T),c(h,js,T),a(js,ze),Ls=!0},p(h,T){const Rs={};T&2&&(Rs.$$scope={dirty:T,ctx:h}),o.$set(Rs)},i(h){Ls||(y(o.$$.fragment,h),y(l.$$.fragment,h),y(F.$$.fragment,h),y(m.$$.fragment,h),y(is.$$.fragment,h),y(rs.$$.fragment,h),y(ds.$$.fragment,h),y(gs.$$.fragment,h),y(_s.$$.fragment,h),Ls=!0)},o(h){E(o.$$.fragment,h),E(l.$$.fragment,h),E(F.$$.fragment,h),E(m.$$.fragment,h),E(is.$$.fragment,h),E(rs.$$.fragment,h),E(ds.$$.fragment,h),E(gs.$$.fragment,h),E(_s.$$.fragment,h),Ls=!1},d(h){q(o,h),h&&e(_),q(l,h),h&&e(g),h&&e($),h&&e(O),q(F,h),h&&e(D),h&&e(S),h&&e(Y),q(m,h),h&&e(A),h&&e(B),h&&e(Ts),q(is,h),h&&e(zs),h&&e(Q),h&&e(ks),h&&e(W),h&&e(ss),q(rs,h),h&&e(b),h&&e(N),h&&e(Ss),q(ds,h),h&&e(ts),h&&e(ws),h&&e(qs),q(gs,h),h&&e(cs),h&&e(ms),h&&e(Js),q(_s,h),h&&e(Qs),h&&e(js)}}}function Go(H){let o,_;return o=new $a({props:{$$slots:{default:[Wo]},$$scope:{ctx:H}}}),{c(){w(o.$$.fragment)},l(l){x(o.$$.fragment,l)},m(l,g){v(o,l,g),_=!0},p(l,g){const $={};g&2&&($.$$scope={dirty:g,ctx:l}),o.$set($)},i(l){_||(y(o.$$.fragment,l),_=!0)},o(l){E(o.$$.fragment,l),_=!1},d(l){q(o,l)}}}function Ko(H){let o,_,l,g,$,k,C,z;return{c(){o=r("p"),_=t(`For a more in-depth example of how to finetune a model for token classification, take a look at the corresponding
`),l=r("a"),g=t("PyTorch notebook"),$=t(`
or `),k=r("a"),C=t("TensorFlow notebook"),z=t("."),this.h()},l(P){o=p(P,"P",{});var O=i(o);_=n(O,`For a more in-depth example of how to finetune a model for token classification, take a look at the corresponding
`),l=p(O,"A",{href:!0,rel:!0});var F=i(l);g=n(F,"PyTorch notebook"),F.forEach(e),$=n(O,`
or `),k=p(O,"A",{href:!0,rel:!0});var D=i(k);C=n(D,"TensorFlow notebook"),D.forEach(e),z=n(O,"."),O.forEach(e),this.h()},h(){j(l,"href","https://colab.research.google.com/github/huggingface/notebooks/blob/main/examples/token_classification.ipynb"),j(l,"rel","nofollow"),j(k,"href","https://colab.research.google.com/github/huggingface/notebooks/blob/main/examples/token_classification-tf.ipynb"),j(k,"rel","nofollow")},m(P,O){c(P,o,O),a(o,_),a(o,l),a(l,g),a(o,$),a(o,k),a(k,C),a(o,z)},d(P){P&&e(o)}}}function Uo(H){let o,_,l,g,$,k,C,z,P,O,F,D,S,M,K,U,Z,G,J,L,Y;return g=new I({props:{code:`from transformers import AutoTokenizer

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

model = AutoModelForTokenClassification.from_pretrained("stevhliu/my_awesome_wnut_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> AutoModelForTokenClassification

<span class="hljs-meta">&gt;&gt;&gt; </span>model = AutoModelForTokenClassification.from_pretrained(<span class="hljs-string">&quot;stevhliu/my_awesome_wnut_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`}}),L=new I({props:{code:`predictions = torch.argmax(logits, dim=2)
predicted_token_class = [model.config.id2label[t.item()] for t in predictions[0]]
predicted_token_class`,highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span>predictions = torch.argmax(logits, dim=<span class="hljs-number">2</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>predicted_token_class = [model.config.id2label[t.item()] <span class="hljs-keyword">for</span> t <span class="hljs-keyword">in</span> predictions[<span class="hljs-number">0</span>]]
<span class="hljs-meta">&gt;&gt;&gt; </span>predicted_token_class
[<span class="hljs-string">&#x27;O&#x27;</span>,
 <span class="hljs-string">&#x27;O&#x27;</span>,
 <span class="hljs-string">&#x27;B-location&#x27;</span>,
 <span class="hljs-string">&#x27;I-location&#x27;</span>,
 <span class="hljs-string">&#x27;B-group&#x27;</span>,
 <span class="hljs-string">&#x27;O&#x27;</span>,
 <span class="hljs-string">&#x27;O&#x27;</span>,
 <span class="hljs-string">&#x27;O&#x27;</span>,
 <span class="hljs-string">&#x27;O&#x27;</span>,
 <span class="hljs-string">&#x27;O&#x27;</span>,
 <span class="hljs-string">&#x27;O&#x27;</span>,
 <span class="hljs-string">&#x27;O&#x27;</span>,
 <span class="hljs-string">&#x27;O&#x27;</span>,
 <span class="hljs-string">&#x27;B-location&#x27;</span>,
 <span class="hljs-string">&#x27;B-location&#x27;</span>,
 <span class="hljs-string">&#x27;O&#x27;</span>,
 <span class="hljs-string">&#x27;O&#x27;</span>]`}}),{c(){o=r("p"),_=t("Tokenize the text and return PyTorch tensors:"),l=f(),w(g.$$.fragment),$=f(),k=r("p"),C=t("Pass your inputs to the model and return the "),z=r("code"),P=t("logits"),O=t(":"),F=f(),w(D.$$.fragment),S=f(),M=r("p"),K=t("Get the class with the highest probability, and use the model\u2019s "),U=r("code"),Z=t("id2label"),G=t(" mapping to convert it to a text label:"),J=f(),w(L.$$.fragment)},l(m){o=p(m,"P",{});var A=i(o);_=n(A,"Tokenize the text and return PyTorch tensors:"),A.forEach(e),l=d(m),x(g.$$.fragment,m),$=d(m),k=p(m,"P",{});var B=i(k);C=n(B,"Pass your inputs to the model and return the "),z=p(B,"CODE",{});var ps=i(z);P=n(ps,"logits"),ps.forEach(e),O=n(B,":"),B.forEach(e),F=d(m),x(D.$$.fragment,m),S=d(m),M=p(m,"P",{});var R=i(M);K=n(R,"Get the class with the highest probability, and use the model\u2019s "),U=p(R,"CODE",{});var V=i(U);Z=n(V,"id2label"),V.forEach(e),G=n(R," mapping to convert it to a text label:"),R.forEach(e),J=d(m),x(L.$$.fragment,m)},m(m,A){c(m,o,A),a(o,_),c(m,l,A),v(g,m,A),c(m,$,A),c(m,k,A),a(k,C),a(k,z),a(z,P),a(k,O),c(m,F,A),v(D,m,A),c(m,S,A),c(m,M,A),a(M,K),a(M,U),a(U,Z),a(M,G),c(m,J,A),v(L,m,A),Y=!0},p:Kt,i(m){Y||(y(g.$$.fragment,m),y(D.$$.fragment,m),y(L.$$.fragment,m),Y=!0)},o(m){E(g.$$.fragment,m),E(D.$$.fragment,m),E(L.$$.fragment,m),Y=!1},d(m){m&&e(o),m&&e(l),q(g,m),m&&e($),m&&e(k),m&&e(F),q(D,m),m&&e(S),m&&e(M),m&&e(J),q(L,m)}}}function Vo(H){let o,_;return o=new $a({props:{$$slots:{default:[Uo]},$$scope:{ctx:H}}}),{c(){w(o.$$.fragment)},l(l){x(o.$$.fragment,l)},m(l,g){v(o,l,g),_=!0},p(l,g){const $={};g&2&&($.$$scope={dirty:g,ctx:l}),o.$set($)},i(l){_||(y(o.$$.fragment,l),_=!0)},o(l){E(o.$$.fragment,l),_=!1},d(l){q(o,l)}}}function Zo(H){let o,_,l,g,$,k,C,z,P,O,F,D,S,M,K,U,Z,G,J,L,Y;return g=new I({props:{code:`from transformers import AutoTokenizer

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

model = TFAutoModelForTokenClassification.from_pretrained("stevhliu/my_awesome_wnut_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> TFAutoModelForTokenClassification

<span class="hljs-meta">&gt;&gt;&gt; </span>model = TFAutoModelForTokenClassification.from_pretrained(<span class="hljs-string">&quot;stevhliu/my_awesome_wnut_model&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>logits = model(**inputs).logits`}}),L=new I({props:{code:`predicted_token_class_ids = tf.math.argmax(logits, axis=-1)
predicted_token_class = [model.config.id2label[t] for t in predicted_token_class_ids[0].numpy().tolist()]
predicted_token_class`,highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span>predicted_token_class_ids = tf.math.argmax(logits, axis=-<span class="hljs-number">1</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>predicted_token_class = [model.config.id2label[t] <span class="hljs-keyword">for</span> t <span class="hljs-keyword">in</span> predicted_token_class_ids[<span class="hljs-number">0</span>].numpy().tolist()]
<span class="hljs-meta">&gt;&gt;&gt; </span>predicted_token_class
[<span class="hljs-string">&#x27;O&#x27;</span>,
 <span class="hljs-string">&#x27;O&#x27;</span>,
 <span class="hljs-string">&#x27;B-location&#x27;</span>,
 <span class="hljs-string">&#x27;I-location&#x27;</span>,
 <span class="hljs-string">&#x27;B-group&#x27;</span>,
 <span class="hljs-string">&#x27;O&#x27;</span>,
 <span class="hljs-string">&#x27;O&#x27;</span>,
 <span class="hljs-string">&#x27;O&#x27;</span>,
 <span class="hljs-string">&#x27;O&#x27;</span>,
 <span class="hljs-string">&#x27;O&#x27;</span>,
 <span class="hljs-string">&#x27;O&#x27;</span>,
 <span class="hljs-string">&#x27;O&#x27;</span>,
 <span class="hljs-string">&#x27;O&#x27;</span>,
 <span class="hljs-string">&#x27;B-location&#x27;</span>,
 <span class="hljs-string">&#x27;B-location&#x27;</span>,
 <span class="hljs-string">&#x27;O&#x27;</span>,
 <span class="hljs-string">&#x27;O&#x27;</span>]`}}),{c(){o=r("p"),_=t("Tokenize the text and return TensorFlow tensors:"),l=f(),w(g.$$.fragment),$=f(),k=r("p"),C=t("Pass your inputs to the model and return the "),z=r("code"),P=t("logits"),O=t(":"),F=f(),w(D.$$.fragment),S=f(),M=r("p"),K=t("Get the class with the highest probability, and use the model\u2019s "),U=r("code"),Z=t("id2label"),G=t(" mapping to convert it to a text label:"),J=f(),w(L.$$.fragment)},l(m){o=p(m,"P",{});var A=i(o);_=n(A,"Tokenize the text and return TensorFlow tensors:"),A.forEach(e),l=d(m),x(g.$$.fragment,m),$=d(m),k=p(m,"P",{});var B=i(k);C=n(B,"Pass your inputs to the model and return the "),z=p(B,"CODE",{});var ps=i(z);P=n(ps,"logits"),ps.forEach(e),O=n(B,":"),B.forEach(e),F=d(m),x(D.$$.fragment,m),S=d(m),M=p(m,"P",{});var R=i(M);K=n(R,"Get the class with the highest probability, and use the model\u2019s "),U=p(R,"CODE",{});var V=i(U);Z=n(V,"id2label"),V.forEach(e),G=n(R," mapping to convert it to a text label:"),R.forEach(e),J=d(m),x(L.$$.fragment,m)},m(m,A){c(m,o,A),a(o,_),c(m,l,A),v(g,m,A),c(m,$,A),c(m,k,A),a(k,C),a(k,z),a(z,P),a(k,O),c(m,F,A),v(D,m,A),c(m,S,A),c(m,M,A),a(M,K),a(M,U),a(U,Z),a(M,G),c(m,J,A),v(L,m,A),Y=!0},p:Kt,i(m){Y||(y(g.$$.fragment,m),y(D.$$.fragment,m),y(L.$$.fragment,m),Y=!0)},o(m){E(g.$$.fragment,m),E(D.$$.fragment,m),E(L.$$.fragment,m),Y=!1},d(m){m&&e(o),m&&e(l),q(g,m),m&&e($),m&&e(k),m&&e(F),q(D,m),m&&e(S),m&&e(M),m&&e(J),q(L,m)}}}function Jo(H){let o,_;return o=new $a({props:{$$slots:{default:[Zo]},$$scope:{ctx:H}}}),{c(){w(o.$$.fragment)},l(l){x(o.$$.fragment,l)},m(l,g){v(o,l,g),_=!0},p(l,g){const $={};g&2&&($.$$scope={dirty:g,ctx:l}),o.$set($)},i(l){_||(y(o.$$.fragment,l),_=!0)},o(l){E(o.$$.fragment,l),_=!1},d(l){q(o,l)}}}function Qo(H){let o,_,l,g,$,k,C,z,P,O,F,D,S,M,K,U,Z,G,J,L,Y,m,A,B,ps,R,V,Fs,xs,Ts,is,zs,Q,us,ns,$s,Bs,ks,W,vs,X,Ds,fs,ls,Cs,os,ss,rs,b,N,as,es,Is,ys,Ss,ds,ts,ws,Es,qs,gs,cs,ms,As,Ms,Ns,qe,Te,Js,_s,Qs,js,ze,Ls,h,T,Rs,hs,Xs,le,oe,sa,ea,bs,re,Ys,aa,pe,ie,ta,ce,he,na,la,se,ka,Ut,Vt,Qa,ee,ue,wa,Ce,Zt,xa,Jt,Xa,Ae,st,me,Qt,va,Xt,sn,et,Pe,at,Ws,en,ya,an,tn,Ea,nn,ln,tt,Oe,nt,Gs,on,qa,rn,pn,Ta,cn,hn,lt,Ks,Fe,un,Be,za,mn,fn,dn,Hs,gn,Ca,_n,jn,Aa,bn,$n,Pa,kn,wn,xn,De,vn,Oa,yn,En,ot,oa,qn,rt,Ie,pt,Ps,Tn,Se,zn,Cn,Fa,An,Pn,Ba,On,Fn,it,Me,ct,Us,Bn,ra,Dn,In,Da,Sn,Mn,ht,fe,ut,ae,de,Ia,Ne,Nn,Sa,Hn,mt,Os,Ln,He,Rn,Yn,Le,Wn,Gn,Re,Kn,Un,ft,Ye,dt,ge,Vn,We,Zn,Jn,gt,Ge,_t,_e,Qn,Ma,Xn,sl,jt,te,je,Na,Ke,el,Ha,al,bt,Vs,tl,La,nl,ll,Ra,ol,rl,$t,Ue,kt,be,wt,$e,xt,ne,ke,Ya,Ve,pl,Wa,il,vt,pa,cl,yt,ia,hl,Et,Ze,qt,Zs,ul,ca,ml,fl,Ga,dl,gl,Tt,Je,zt,we,_l,Ka,jl,bl,Ct,xe,At;return k=new ba({}),F=new Bo({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/token_classification.ipynb"},{label:"PyTorch",value:"https://colab.research.google.com/github/huggingface/notebooks/blob/main/transformers_doc/en/pytorch/token_classification.ipynb"},{label:"TensorFlow",value:"https://colab.research.google.com/github/huggingface/notebooks/blob/main/transformers_doc/en/tensorflow/token_classification.ipynb"},{label:"Mixed",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/main/transformers_doc/en/token_classification.ipynb"},{label:"PyTorch",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/main/transformers_doc/en/pytorch/token_classification.ipynb"},{label:"TensorFlow",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/main/transformers_doc/en/tensorflow/token_classification.ipynb"}]}}),S=new zo({props:{id:"wVHdVlPScxA"}}),us=new Gt({props:{$$slots:{default:[Do]},$$scope:{ctx:H}}}),W=new I({props:{code:"pip install transformers datasets evaluate",highlighted:"pip install transformers datasets evaluate"}}),ls=new I({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()`}}),b=new ba({}),ts=new I({props:{code:`from datasets import load_dataset

wnut = load_dataset("wnut_17")`,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>wnut = load_dataset(<span class="hljs-string">&quot;wnut_17&quot;</span>)`}}),cs=new I({props:{code:'wnut["train"][0]',highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span>wnut[<span class="hljs-string">&quot;train&quot;</span>][<span class="hljs-number">0</span>]
{<span class="hljs-string">&#x27;id&#x27;</span>: <span class="hljs-string">&#x27;0&#x27;</span>,
 <span class="hljs-string">&#x27;ner_tags&#x27;</span>: [<span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">7</span>, <span class="hljs-number">8</span>, <span class="hljs-number">8</span>, <span class="hljs-number">0</span>, <span class="hljs-number">7</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>],
 <span class="hljs-string">&#x27;tokens&#x27;</span>: [<span class="hljs-string">&#x27;@paulwalk&#x27;</span>, <span class="hljs-string">&#x27;It&#x27;</span>, <span class="hljs-string">&quot;&#x27;s&quot;</span>, <span class="hljs-string">&#x27;the&#x27;</span>, <span class="hljs-string">&#x27;view&#x27;</span>, <span class="hljs-string">&#x27;from&#x27;</span>, <span class="hljs-string">&#x27;where&#x27;</span>, <span class="hljs-string">&#x27;I&#x27;</span>, <span class="hljs-string">&quot;&#x27;m&quot;</span>, <span class="hljs-string">&#x27;living&#x27;</span>, <span class="hljs-string">&#x27;for&#x27;</span>, <span class="hljs-string">&#x27;two&#x27;</span>, <span class="hljs-string">&#x27;weeks&#x27;</span>, <span class="hljs-string">&#x27;.&#x27;</span>, <span class="hljs-string">&#x27;Empire&#x27;</span>, <span class="hljs-string">&#x27;State&#x27;</span>, <span class="hljs-string">&#x27;Building&#x27;</span>, <span class="hljs-string">&#x27;=&#x27;</span>, <span class="hljs-string">&#x27;ESB&#x27;</span>, <span class="hljs-string">&#x27;.&#x27;</span>, <span class="hljs-string">&#x27;Pretty&#x27;</span>, <span class="hljs-string">&#x27;bad&#x27;</span>, <span class="hljs-string">&#x27;storm&#x27;</span>, <span class="hljs-string">&#x27;here&#x27;</span>, <span class="hljs-string">&#x27;last&#x27;</span>, <span class="hljs-string">&#x27;evening&#x27;</span>, <span class="hljs-string">&#x27;.&#x27;</span>]
}`}}),_s=new I({props:{code:`label_list = wnut["train"].features[f"ner_tags"].feature.names
label_list`,highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span>label_list = wnut[<span class="hljs-string">&quot;train&quot;</span>].features[<span class="hljs-string">f&quot;ner_tags&quot;</span>].feature.names
<span class="hljs-meta">&gt;&gt;&gt; </span>label_list
[
    <span class="hljs-string">&quot;O&quot;</span>,
    <span class="hljs-string">&quot;B-corporation&quot;</span>,
    <span class="hljs-string">&quot;I-corporation&quot;</span>,
    <span class="hljs-string">&quot;B-creative-work&quot;</span>,
    <span class="hljs-string">&quot;I-creative-work&quot;</span>,
    <span class="hljs-string">&quot;B-group&quot;</span>,
    <span class="hljs-string">&quot;I-group&quot;</span>,
    <span class="hljs-string">&quot;B-location&quot;</span>,
    <span class="hljs-string">&quot;I-location&quot;</span>,
    <span class="hljs-string">&quot;B-person&quot;</span>,
    <span class="hljs-string">&quot;I-person&quot;</span>,
    <span class="hljs-string">&quot;B-product&quot;</span>,
    <span class="hljs-string">&quot;I-product&quot;</span>,
]`}}),Ce=new ba({}),Ae=new zo({props:{id:"iY2AZYdZAr0"}}),Pe=new I({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>)`}}),Oe=new I({props:{code:`example = wnut["train"][0]
tokenized_input = tokenizer(example["tokens"], is_split_into_words=True)
tokens = tokenizer.convert_ids_to_tokens(tokenized_input["input_ids"])
tokens`,highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span>example = wnut[<span class="hljs-string">&quot;train&quot;</span>][<span class="hljs-number">0</span>]
<span class="hljs-meta">&gt;&gt;&gt; </span>tokenized_input = tokenizer(example[<span class="hljs-string">&quot;tokens&quot;</span>], is_split_into_words=<span class="hljs-literal">True</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>tokens = tokenizer.convert_ids_to_tokens(tokenized_input[<span class="hljs-string">&quot;input_ids&quot;</span>])
<span class="hljs-meta">&gt;&gt;&gt; </span>tokens
[<span class="hljs-string">&#x27;[CLS]&#x27;</span>, <span class="hljs-string">&#x27;@&#x27;</span>, <span class="hljs-string">&#x27;paul&#x27;</span>, <span class="hljs-string">&#x27;##walk&#x27;</span>, <span class="hljs-string">&#x27;it&#x27;</span>, <span class="hljs-string">&quot;&#x27;&quot;</span>, <span class="hljs-string">&#x27;s&#x27;</span>, <span class="hljs-string">&#x27;the&#x27;</span>, <span class="hljs-string">&#x27;view&#x27;</span>, <span class="hljs-string">&#x27;from&#x27;</span>, <span class="hljs-string">&#x27;where&#x27;</span>, <span class="hljs-string">&#x27;i&#x27;</span>, <span class="hljs-string">&quot;&#x27;&quot;</span>, <span class="hljs-string">&#x27;m&#x27;</span>, <span class="hljs-string">&#x27;living&#x27;</span>, <span class="hljs-string">&#x27;for&#x27;</span>, <span class="hljs-string">&#x27;two&#x27;</span>, <span class="hljs-string">&#x27;weeks&#x27;</span>, <span class="hljs-string">&#x27;.&#x27;</span>, <span class="hljs-string">&#x27;empire&#x27;</span>, <span class="hljs-string">&#x27;state&#x27;</span>, <span class="hljs-string">&#x27;building&#x27;</span>, <span class="hljs-string">&#x27;=&#x27;</span>, <span class="hljs-string">&#x27;es&#x27;</span>, <span class="hljs-string">&#x27;##b&#x27;</span>, <span class="hljs-string">&#x27;.&#x27;</span>, <span class="hljs-string">&#x27;pretty&#x27;</span>, <span class="hljs-string">&#x27;bad&#x27;</span>, <span class="hljs-string">&#x27;storm&#x27;</span>, <span class="hljs-string">&#x27;here&#x27;</span>, <span class="hljs-string">&#x27;last&#x27;</span>, <span class="hljs-string">&#x27;evening&#x27;</span>, <span class="hljs-string">&#x27;.&#x27;</span>, <span class="hljs-string">&#x27;[SEP]&#x27;</span>]`}}),Ie=new I({props:{code:`def tokenize_and_align_labels(examples):
    tokenized_inputs = tokenizer(examples["tokens"], truncation=True, is_split_into_words=True)

    labels = []
    for i, label in enumerate(examples[f"ner_tags"]):
        word_ids = tokenized_inputs.word_ids(batch_index=i)  # Map tokens to their respective word.
        previous_word_idx = None
        label_ids = []
        for word_idx in word_ids:  # Set the special tokens to -100.
            if word_idx is None:
                label_ids.append(-100)
            elif word_idx != previous_word_idx:  # Only label the first token of a given word.
                label_ids.append(label[word_idx])
            else:
                label_ids.append(-100)
            previous_word_idx = word_idx
        labels.append(label_ids)

    tokenized_inputs["labels"] = labels
    return tokenized_inputs`,highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">def</span> <span class="hljs-title function_">tokenize_and_align_labels</span>(<span class="hljs-params">examples</span>):
<span class="hljs-meta">... </span>    tokenized_inputs = tokenizer(examples[<span class="hljs-string">&quot;tokens&quot;</span>], truncation=<span class="hljs-literal">True</span>, is_split_into_words=<span class="hljs-literal">True</span>)

<span class="hljs-meta">... </span>    labels = []
<span class="hljs-meta">... </span>    <span class="hljs-keyword">for</span> i, label <span class="hljs-keyword">in</span> <span class="hljs-built_in">enumerate</span>(examples[<span class="hljs-string">f&quot;ner_tags&quot;</span>]):
<span class="hljs-meta">... </span>        word_ids = tokenized_inputs.word_ids(batch_index=i)  <span class="hljs-comment"># Map tokens to their respective word.</span>
<span class="hljs-meta">... </span>        previous_word_idx = <span class="hljs-literal">None</span>
<span class="hljs-meta">... </span>        label_ids = []
<span class="hljs-meta">... </span>        <span class="hljs-keyword">for</span> word_idx <span class="hljs-keyword">in</span> word_ids:  <span class="hljs-comment"># Set the special tokens to -100.</span>
<span class="hljs-meta">... </span>            <span class="hljs-keyword">if</span> word_idx <span class="hljs-keyword">is</span> <span class="hljs-literal">None</span>:
<span class="hljs-meta">... </span>                label_ids.append(-<span class="hljs-number">100</span>)
<span class="hljs-meta">... </span>            <span class="hljs-keyword">elif</span> word_idx != previous_word_idx:  <span class="hljs-comment"># Only label the first token of a given word.</span>
<span class="hljs-meta">... </span>                label_ids.append(label[word_idx])
<span class="hljs-meta">... </span>            <span class="hljs-keyword">else</span>:
<span class="hljs-meta">... </span>                label_ids.append(-<span class="hljs-number">100</span>)
<span class="hljs-meta">... </span>            previous_word_idx = word_idx
<span class="hljs-meta">... </span>        labels.append(label_ids)

<span class="hljs-meta">... </span>    tokenized_inputs[<span class="hljs-string">&quot;labels&quot;</span>] = labels
<span class="hljs-meta">... </span>    <span class="hljs-keyword">return</span> tokenized_inputs`}}),Me=new I({props:{code:"tokenized_wnut = wnut.map(tokenize_and_align_labels, batched=True)",highlighted:'<span class="hljs-meta">&gt;&gt;&gt; </span>tokenized_wnut = wnut.<span class="hljs-built_in">map</span>(tokenize_and_align_labels, batched=<span class="hljs-literal">True</span>)'}}),fe=new wl({props:{pytorch:!0,tensorflow:!0,jax:!1,$$slots:{tensorflow:[No],pytorch:[So]},$$scope:{ctx:H}}}),Ne=new ba({}),Ye=new I({props:{code:`import evaluate

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

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

labels = [label_list[i] for i in example[f"ner_tags"]]


def compute_metrics(p):
    predictions, labels = p
    predictions = np.argmax(predictions, axis=2)

    true_predictions = [
        [label_list[p] for (p, l) in zip(prediction, label) if l != -100]
        for prediction, label in zip(predictions, labels)
    ]
    true_labels = [
        [label_list[l] for (p, l) in zip(prediction, label) if l != -100]
        for prediction, label in zip(predictions, labels)
    ]

    results = seqeval.compute(predictions=true_predictions, references=true_labels)
    return {
        "precision": results["overall_precision"],
        "recall": results["overall_recall"],
        "f1": results["overall_f1"],
        "accuracy": results["overall_accuracy"],
    }`,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>labels = [label_list[i] <span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> example[<span class="hljs-string">f&quot;ner_tags&quot;</span>]]


<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">p</span>):
<span class="hljs-meta">... </span>    predictions, labels = p
<span class="hljs-meta">... </span>    predictions = np.argmax(predictions, axis=<span class="hljs-number">2</span>)

<span class="hljs-meta">... </span>    true_predictions = [
<span class="hljs-meta">... </span>        [label_list[p] <span class="hljs-keyword">for</span> (p, l) <span class="hljs-keyword">in</span> <span class="hljs-built_in">zip</span>(prediction, label) <span class="hljs-keyword">if</span> l != -<span class="hljs-number">100</span>]
<span class="hljs-meta">... </span>        <span class="hljs-keyword">for</span> prediction, label <span class="hljs-keyword">in</span> <span class="hljs-built_in">zip</span>(predictions, labels)
<span class="hljs-meta">... </span>    ]
<span class="hljs-meta">... </span>    true_labels = [
<span class="hljs-meta">... </span>        [label_list[l] <span class="hljs-keyword">for</span> (p, l) <span class="hljs-keyword">in</span> <span class="hljs-built_in">zip</span>(prediction, label) <span class="hljs-keyword">if</span> l != -<span class="hljs-number">100</span>]
<span class="hljs-meta">... </span>        <span class="hljs-keyword">for</span> prediction, label <span class="hljs-keyword">in</span> <span class="hljs-built_in">zip</span>(predictions, labels)
<span class="hljs-meta">... </span>    ]

<span class="hljs-meta">... </span>    results = seqeval.compute(predictions=true_predictions, references=true_labels)
<span class="hljs-meta">... </span>    <span class="hljs-keyword">return</span> {
<span class="hljs-meta">... </span>        <span class="hljs-string">&quot;precision&quot;</span>: results[<span class="hljs-string">&quot;overall_precision&quot;</span>],
<span class="hljs-meta">... </span>        <span class="hljs-string">&quot;recall&quot;</span>: results[<span class="hljs-string">&quot;overall_recall&quot;</span>],
<span class="hljs-meta">... </span>        <span class="hljs-string">&quot;f1&quot;</span>: results[<span class="hljs-string">&quot;overall_f1&quot;</span>],
<span class="hljs-meta">... </span>        <span class="hljs-string">&quot;accuracy&quot;</span>: results[<span class="hljs-string">&quot;overall_accuracy&quot;</span>],
<span class="hljs-meta">... </span>    }`}}),Ke=new ba({}),Ue=new I({props:{code:`id2label = {
    0: "O",
    1: "B-corporation",
    2: "I-corporation",
    3: "B-creative-work",
    4: "I-creative-work",
    5: "B-group",
    6: "I-group",
    7: "B-location",
    8: "I-location",
    9: "B-person",
    10: "I-person",
    11: "B-product",
    12: "I-product",
}
label2id = {
    "O": 0,
    "B-corporation": 1,
    "I-corporation": 2,
    "B-creative-work": 3,
    "I-creative-work": 4,
    "B-group": 5,
    "I-group": 6,
    "B-location": 7,
    "I-location": 8,
    "B-person": 9,
    "I-person": 10,
    "B-product": 11,
    "I-product": 12,
}`,highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span>id2label = {
<span class="hljs-meta">... </span>    <span class="hljs-number">0</span>: <span class="hljs-string">&quot;O&quot;</span>,
<span class="hljs-meta">... </span>    <span class="hljs-number">1</span>: <span class="hljs-string">&quot;B-corporation&quot;</span>,
<span class="hljs-meta">... </span>    <span class="hljs-number">2</span>: <span class="hljs-string">&quot;I-corporation&quot;</span>,
<span class="hljs-meta">... </span>    <span class="hljs-number">3</span>: <span class="hljs-string">&quot;B-creative-work&quot;</span>,
<span class="hljs-meta">... </span>    <span class="hljs-number">4</span>: <span class="hljs-string">&quot;I-creative-work&quot;</span>,
<span class="hljs-meta">... </span>    <span class="hljs-number">5</span>: <span class="hljs-string">&quot;B-group&quot;</span>,
<span class="hljs-meta">... </span>    <span class="hljs-number">6</span>: <span class="hljs-string">&quot;I-group&quot;</span>,
<span class="hljs-meta">... </span>    <span class="hljs-number">7</span>: <span class="hljs-string">&quot;B-location&quot;</span>,
<span class="hljs-meta">... </span>    <span class="hljs-number">8</span>: <span class="hljs-string">&quot;I-location&quot;</span>,
<span class="hljs-meta">... </span>    <span class="hljs-number">9</span>: <span class="hljs-string">&quot;B-person&quot;</span>,
<span class="hljs-meta">... </span>    <span class="hljs-number">10</span>: <span class="hljs-string">&quot;I-person&quot;</span>,
<span class="hljs-meta">... </span>    <span class="hljs-number">11</span>: <span class="hljs-string">&quot;B-product&quot;</span>,
<span class="hljs-meta">... </span>    <span class="hljs-number">12</span>: <span class="hljs-string">&quot;I-product&quot;</span>,
<span class="hljs-meta">... </span>}
<span class="hljs-meta">&gt;&gt;&gt; </span>label2id = {
<span class="hljs-meta">... </span>    <span class="hljs-string">&quot;O&quot;</span>: <span class="hljs-number">0</span>,
<span class="hljs-meta">... </span>    <span class="hljs-string">&quot;B-corporation&quot;</span>: <span class="hljs-number">1</span>,
<span class="hljs-meta">... </span>    <span class="hljs-string">&quot;I-corporation&quot;</span>: <span class="hljs-number">2</span>,
<span class="hljs-meta">... </span>    <span class="hljs-string">&quot;B-creative-work&quot;</span>: <span class="hljs-number">3</span>,
<span class="hljs-meta">... </span>    <span class="hljs-string">&quot;I-creative-work&quot;</span>: <span class="hljs-number">4</span>,
<span class="hljs-meta">... </span>    <span class="hljs-string">&quot;B-group&quot;</span>: <span class="hljs-number">5</span>,
<span class="hljs-meta">... </span>    <span class="hljs-string">&quot;I-group&quot;</span>: <span class="hljs-number">6</span>,
<span class="hljs-meta">... </span>    <span class="hljs-string">&quot;B-location&quot;</span>: <span class="hljs-number">7</span>,
<span class="hljs-meta">... </span>    <span class="hljs-string">&quot;I-location&quot;</span>: <span class="hljs-number">8</span>,
<span class="hljs-meta">... </span>    <span class="hljs-string">&quot;B-person&quot;</span>: <span class="hljs-number">9</span>,
<span class="hljs-meta">... </span>    <span class="hljs-string">&quot;I-person&quot;</span>: <span class="hljs-number">10</span>,
<span class="hljs-meta">... </span>    <span class="hljs-string">&quot;B-product&quot;</span>: <span class="hljs-number">11</span>,
<span class="hljs-meta">... </span>    <span class="hljs-string">&quot;I-product&quot;</span>: <span class="hljs-number">12</span>,
<span class="hljs-meta">... </span>}`}}),be=new wl({props:{pytorch:!0,tensorflow:!0,jax:!1,$$slots:{tensorflow:[Go],pytorch:[Ro]},$$scope:{ctx:H}}}),$e=new Gt({props:{$$slots:{default:[Ko]},$$scope:{ctx:H}}}),Ve=new ba({}),Ze=new I({props:{code:'text = "The Golden State Warriors are an American professional basketball team based in San Francisco."',highlighted:'<span class="hljs-meta">&gt;&gt;&gt; </span>text = <span class="hljs-string">&quot;The Golden State Warriors are an American professional basketball team based in San Francisco.&quot;</span>'}}),Je=new I({props:{code:`from transformers import pipeline

classifier = pipeline("ner", model="stevhliu/my_awesome_wnut_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;ner&quot;</span>, model=<span class="hljs-string">&quot;stevhliu/my_awesome_wnut_model&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>classifier(text)
[{<span class="hljs-string">&#x27;entity&#x27;</span>: <span class="hljs-string">&#x27;B-location&#x27;</span>,
  <span class="hljs-string">&#x27;score&#x27;</span>: <span class="hljs-number">0.42658573</span>,
  <span class="hljs-string">&#x27;index&#x27;</span>: <span class="hljs-number">2</span>,
  <span class="hljs-string">&#x27;word&#x27;</span>: <span class="hljs-string">&#x27;golden&#x27;</span>,
  <span class="hljs-string">&#x27;start&#x27;</span>: <span class="hljs-number">4</span>,
  <span class="hljs-string">&#x27;end&#x27;</span>: <span class="hljs-number">10</span>},
 {<span class="hljs-string">&#x27;entity&#x27;</span>: <span class="hljs-string">&#x27;I-location&#x27;</span>,
  <span class="hljs-string">&#x27;score&#x27;</span>: <span class="hljs-number">0.35856336</span>,
  <span class="hljs-string">&#x27;index&#x27;</span>: <span class="hljs-number">3</span>,
  <span class="hljs-string">&#x27;word&#x27;</span>: <span class="hljs-string">&#x27;state&#x27;</span>,
  <span class="hljs-string">&#x27;start&#x27;</span>: <span class="hljs-number">11</span>,
  <span class="hljs-string">&#x27;end&#x27;</span>: <span class="hljs-number">16</span>},
 {<span class="hljs-string">&#x27;entity&#x27;</span>: <span class="hljs-string">&#x27;B-group&#x27;</span>,
  <span class="hljs-string">&#x27;score&#x27;</span>: <span class="hljs-number">0.3064001</span>,
  <span class="hljs-string">&#x27;index&#x27;</span>: <span class="hljs-number">4</span>,
  <span class="hljs-string">&#x27;word&#x27;</span>: <span class="hljs-string">&#x27;warriors&#x27;</span>,
  <span class="hljs-string">&#x27;start&#x27;</span>: <span class="hljs-number">17</span>,
  <span class="hljs-string">&#x27;end&#x27;</span>: <span class="hljs-number">25</span>},
 {<span class="hljs-string">&#x27;entity&#x27;</span>: <span class="hljs-string">&#x27;B-location&#x27;</span>,
  <span class="hljs-string">&#x27;score&#x27;</span>: <span class="hljs-number">0.65523505</span>,
  <span class="hljs-string">&#x27;index&#x27;</span>: <span class="hljs-number">13</span>,
  <span class="hljs-string">&#x27;word&#x27;</span>: <span class="hljs-string">&#x27;san&#x27;</span>,
  <span class="hljs-string">&#x27;start&#x27;</span>: <span class="hljs-number">80</span>,
  <span class="hljs-string">&#x27;end&#x27;</span>: <span class="hljs-number">83</span>},
 {<span class="hljs-string">&#x27;entity&#x27;</span>: <span class="hljs-string">&#x27;B-location&#x27;</span>,
  <span class="hljs-string">&#x27;score&#x27;</span>: <span class="hljs-number">0.4668663</span>,
  <span class="hljs-string">&#x27;index&#x27;</span>: <span class="hljs-number">14</span>,
  <span class="hljs-string">&#x27;word&#x27;</span>: <span class="hljs-string">&#x27;francisco&#x27;</span>,
  <span class="hljs-string">&#x27;start&#x27;</span>: <span class="hljs-number">84</span>,
  <span class="hljs-string">&#x27;end&#x27;</span>: <span class="hljs-number">93</span>}]`}}),xe=new wl({props:{pytorch:!0,tensorflow:!0,jax:!1,$$slots:{tensorflow:[Jo],pytorch:[Vo]},$$scope:{ctx:H}}}),{c(){o=r("meta"),_=f(),l=r("h1"),g=r("a"),$=r("span"),w(k.$$.fragment),C=f(),z=r("span"),P=t("Token classification"),O=f(),w(F.$$.fragment),D=f(),w(S.$$.fragment),M=f(),K=r("p"),U=t("Token classification assigns a label to individual tokens in a sentence. One of the most common token classification tasks is Named Entity Recognition (NER). NER attempts to find a label for each entity in a sentence, such as a person, location, or organization."),Z=f(),G=r("p"),J=t("This guide will show you how to:"),L=f(),Y=r("ol"),m=r("li"),A=t("Finetune "),B=r("a"),ps=t("DistilBERT"),R=t(" on the "),V=r("a"),Fs=t("WNUT 17"),xs=t(" dataset to detect new entities."),Ts=f(),is=r("li"),zs=t("Use your finetuned model for inference."),Q=f(),w(us.$$.fragment),ns=f(),$s=r("p"),Bs=t("Before you begin, make sure you have all the necessary libraries installed:"),ks=f(),w(W.$$.fragment),vs=f(),X=r("p"),Ds=t("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:"),fs=f(),w(ls.$$.fragment),Cs=f(),os=r("h2"),ss=r("a"),rs=r("span"),w(b.$$.fragment),N=f(),as=r("span"),es=t("Load WNUT 17 dataset"),Is=f(),ys=r("p"),Ss=t("Start by loading the WNUT 17 dataset from the \u{1F917} Datasets library:"),ds=f(),w(ts.$$.fragment),ws=f(),Es=r("p"),qs=t("Then take a look at an example:"),gs=f(),w(cs.$$.fragment),ms=f(),As=r("p"),Ms=t("Each number in "),Ns=r("code"),qe=t("ner_tags"),Te=t(" represents an entity. Convert the numbers to their label names to find out what the entities are:"),Js=f(),w(_s.$$.fragment),Qs=f(),js=r("p"),ze=t("The letter that prefixes each "),Ls=r("code"),h=t("ner_tag"),T=t(" indicates the token position of the entity:"),Rs=f(),hs=r("ul"),Xs=r("li"),le=r("code"),oe=t("B-"),sa=t(" indicates the beginning of an entity."),ea=f(),bs=r("li"),re=r("code"),Ys=t("I-"),aa=t(" indicates a token is contained inside the same entity (for example, the "),pe=r("code"),ie=t("State"),ta=t(` token is a part of an entity like
`),ce=r("code"),he=t("Empire State Building"),na=t(")."),la=f(),se=r("li"),ka=r("code"),Ut=t("0"),Vt=t(" indicates the token doesn\u2019t correspond to any entity."),Qa=f(),ee=r("h2"),ue=r("a"),wa=r("span"),w(Ce.$$.fragment),Zt=f(),xa=r("span"),Jt=t("Preprocess"),Xa=f(),w(Ae.$$.fragment),st=f(),me=r("p"),Qt=t("The next step is to load a DistilBERT tokenizer to preprocess the "),va=r("code"),Xt=t("tokens"),sn=t(" field:"),et=f(),w(Pe.$$.fragment),at=f(),Ws=r("p"),en=t("As you saw in the example "),ya=r("code"),an=t("tokens"),tn=t(" field above, it looks like the input has already been tokenized. But the input actually hasn\u2019t been tokenized yet and you\u2019ll need to set "),Ea=r("code"),nn=t("is_split_into_words=True"),ln=t(" to tokenize the words into subwords. For example:"),tt=f(),w(Oe.$$.fragment),nt=f(),Gs=r("p"),on=t("However, this adds some special tokens "),qa=r("code"),rn=t("[CLS]"),pn=t(" and "),Ta=r("code"),cn=t("[SEP]"),hn=t(" and the subword tokenization creates a mismatch between the input and labels. A single word corresponding to a single label may now be split into two subwords. You\u2019ll need to realign the tokens and labels by:"),lt=f(),Ks=r("ol"),Fe=r("li"),un=t("Mapping all tokens to their corresponding word with the "),Be=r("a"),za=r("code"),mn=t("word_ids"),fn=t(" method."),dn=f(),Hs=r("li"),gn=t("Assigning the label "),Ca=r("code"),_n=t("-100"),jn=t(" to the special tokens "),Aa=r("code"),bn=t("[CLS]"),$n=t(" and "),Pa=r("code"),kn=t("[SEP]"),wn=t(" so they\u2019re ignored by the PyTorch loss function."),xn=f(),De=r("li"),vn=t("Only labeling the first token of a given word. Assign "),Oa=r("code"),yn=t("-100"),En=t(" to other subtokens from the same word."),ot=f(),oa=r("p"),qn=t("Here is how you can create a function to realign the tokens and labels, and truncate sequences to be no longer than DistilBERT\u2019s maximum input length:"),rt=f(),w(Ie.$$.fragment),pt=f(),Ps=r("p"),Tn=t("To apply the preprocessing function over the entire dataset, use \u{1F917} Datasets "),Se=r("a"),zn=t("map"),Cn=t(" function. You can speed up the "),Fa=r("code"),An=t("map"),Pn=t(" function by setting "),Ba=r("code"),On=t("batched=True"),Fn=t(" to process multiple elements of the dataset at once:"),it=f(),w(Me.$$.fragment),ct=f(),Us=r("p"),Bn=t("Now create a batch of examples using "),ra=r("a"),Dn=t("DataCollatorWithPadding"),In=t(". It\u2019s more efficient to "),Da=r("em"),Sn=t("dynamically pad"),Mn=t(" the sentences to the longest length in a batch during collation, instead of padding the whole dataset to the maximium length."),ht=f(),w(fe.$$.fragment),ut=f(),ae=r("h2"),de=r("a"),Ia=r("span"),w(Ne.$$.fragment),Nn=f(),Sa=r("span"),Hn=t("Evaluate"),mt=f(),Os=r("p"),Ln=t("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} "),He=r("a"),Rn=t("Evaluate"),Yn=t(" library. For this task, load the "),Le=r("a"),Wn=t("seqeval"),Gn=t(" framework (see the \u{1F917} Evaluate "),Re=r("a"),Kn=t("quick tour"),Un=t(" to learn more about how to load and compute a metric). Seqeval actually produces several scores: precision, recall, F1, and accuracy."),ft=f(),w(Ye.$$.fragment),dt=f(),ge=r("p"),Vn=t("Get the NER labels first, and then create a function that passes your true predictions and true labels to "),We=r("a"),Zn=t("compute"),Jn=t(" to calculate the scores:"),gt=f(),w(Ge.$$.fragment),_t=f(),_e=r("p"),Qn=t("Your "),Ma=r("code"),Xn=t("compute_metrics"),sl=t(" function is ready to go now, and you\u2019ll return to it when you setup your training."),jt=f(),te=r("h2"),je=r("a"),Na=r("span"),w(Ke.$$.fragment),el=f(),Ha=r("span"),al=t("Train"),bt=f(),Vs=r("p"),tl=t("Before you start training your model, create a map of the expected ids to their labels with "),La=r("code"),nl=t("id2label"),ll=t(" and "),Ra=r("code"),ol=t("label2id"),rl=t(":"),$t=f(),w(Ue.$$.fragment),kt=f(),w(be.$$.fragment),wt=f(),w($e.$$.fragment),xt=f(),ne=r("h2"),ke=r("a"),Ya=r("span"),w(Ve.$$.fragment),pl=f(),Wa=r("span"),il=t("Inference"),vt=f(),pa=r("p"),cl=t("Great, now that you\u2019ve finetuned a model, you can use it for inference!"),yt=f(),ia=r("p"),hl=t("Grab some text you\u2019d like to run inference on:"),Et=f(),w(Ze.$$.fragment),qt=f(),Zs=r("p"),ul=t("The simplest way to try out your finetuned model for inference is to use it in a "),ca=r("a"),ml=t("pipeline()"),fl=t(". Instantiate a "),Ga=r("code"),dl=t("pipeline"),gl=t(" for NER with your model, and pass your text to it:"),Tt=f(),w(Je.$$.fragment),zt=f(),we=r("p"),_l=t("You can also manually replicate the results of the "),Ka=r("code"),jl=t("pipeline"),bl=t(" if you\u2019d like:"),Ct=f(),w(xe.$$.fragment),this.h()},l(s){const u=Oo('[data-svelte="svelte-1phssyn"]',document.head);o=p(u,"META",{name:!0,content:!0}),u.forEach(e),_=d(s),l=p(s,"H1",{class:!0});var Qe=i(l);g=p(Qe,"A",{id:!0,class:!0,href:!0});var Ua=i(g);$=p(Ua,"SPAN",{});var Va=i($);x(k.$$.fragment,Va),Va.forEach(e),Ua.forEach(e),C=d(Qe),z=p(Qe,"SPAN",{});var Za=i(z);P=n(Za,"Token classification"),Za.forEach(e),Qe.forEach(e),O=d(s),x(F.$$.fragment,s),D=d(s),x(S.$$.fragment,s),M=d(s),K=p(s,"P",{});var Ja=i(K);U=n(Ja,"Token classification assigns a label to individual tokens in a sentence. One of the most common token classification tasks is Named Entity Recognition (NER). NER attempts to find a label for each entity in a sentence, such as a person, location, or organization."),Ja.forEach(e),Z=d(s),G=p(s,"P",{});var xl=i(G);J=n(xl,"This guide will show you how to:"),xl.forEach(e),L=d(s),Y=p(s,"OL",{});var Pt=i(Y);m=p(Pt,"LI",{});var ha=i(m);A=n(ha,"Finetune "),B=p(ha,"A",{href:!0,rel:!0});var vl=i(B);ps=n(vl,"DistilBERT"),vl.forEach(e),R=n(ha," on the "),V=p(ha,"A",{href:!0,rel:!0});var yl=i(V);Fs=n(yl,"WNUT 17"),yl.forEach(e),xs=n(ha," dataset to detect new entities."),ha.forEach(e),Ts=d(Pt),is=p(Pt,"LI",{});var El=i(is);zs=n(El,"Use your finetuned model for inference."),El.forEach(e),Pt.forEach(e),Q=d(s),x(us.$$.fragment,s),ns=d(s),$s=p(s,"P",{});var ql=i($s);Bs=n(ql,"Before you begin, make sure you have all the necessary libraries installed:"),ql.forEach(e),ks=d(s),x(W.$$.fragment,s),vs=d(s),X=p(s,"P",{});var Tl=i(X);Ds=n(Tl,"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:"),Tl.forEach(e),fs=d(s),x(ls.$$.fragment,s),Cs=d(s),os=p(s,"H2",{class:!0});var Ot=i(os);ss=p(Ot,"A",{id:!0,class:!0,href:!0});var zl=i(ss);rs=p(zl,"SPAN",{});var Cl=i(rs);x(b.$$.fragment,Cl),Cl.forEach(e),zl.forEach(e),N=d(Ot),as=p(Ot,"SPAN",{});var Al=i(as);es=n(Al,"Load WNUT 17 dataset"),Al.forEach(e),Ot.forEach(e),Is=d(s),ys=p(s,"P",{});var Pl=i(ys);Ss=n(Pl,"Start by loading the WNUT 17 dataset from the \u{1F917} Datasets library:"),Pl.forEach(e),ds=d(s),x(ts.$$.fragment,s),ws=d(s),Es=p(s,"P",{});var Ol=i(Es);qs=n(Ol,"Then take a look at an example:"),Ol.forEach(e),gs=d(s),x(cs.$$.fragment,s),ms=d(s),As=p(s,"P",{});var Ft=i(As);Ms=n(Ft,"Each number in "),Ns=p(Ft,"CODE",{});var Fl=i(Ns);qe=n(Fl,"ner_tags"),Fl.forEach(e),Te=n(Ft," represents an entity. Convert the numbers to their label names to find out what the entities are:"),Ft.forEach(e),Js=d(s),x(_s.$$.fragment,s),Qs=d(s),js=p(s,"P",{});var Bt=i(js);ze=n(Bt,"The letter that prefixes each "),Ls=p(Bt,"CODE",{});var Bl=i(Ls);h=n(Bl,"ner_tag"),Bl.forEach(e),T=n(Bt," indicates the token position of the entity:"),Bt.forEach(e),Rs=d(s),hs=p(s,"UL",{});var ua=i(hs);Xs=p(ua,"LI",{});var $l=i(Xs);le=p($l,"CODE",{});var Dl=i(le);oe=n(Dl,"B-"),Dl.forEach(e),sa=n($l," indicates the beginning of an entity."),$l.forEach(e),ea=d(ua),bs=p(ua,"LI",{});var Xe=i(bs);re=p(Xe,"CODE",{});var Il=i(re);Ys=n(Il,"I-"),Il.forEach(e),aa=n(Xe," indicates a token is contained inside the same entity (for example, the "),pe=p(Xe,"CODE",{});var Sl=i(pe);ie=n(Sl,"State"),Sl.forEach(e),ta=n(Xe,` token is a part of an entity like
`),ce=p(Xe,"CODE",{});var Ml=i(ce);he=n(Ml,"Empire State Building"),Ml.forEach(e),na=n(Xe,")."),Xe.forEach(e),la=d(ua),se=p(ua,"LI",{});var kl=i(se);ka=p(kl,"CODE",{});var Nl=i(ka);Ut=n(Nl,"0"),Nl.forEach(e),Vt=n(kl," indicates the token doesn\u2019t correspond to any entity."),kl.forEach(e),ua.forEach(e),Qa=d(s),ee=p(s,"H2",{class:!0});var Dt=i(ee);ue=p(Dt,"A",{id:!0,class:!0,href:!0});var Hl=i(ue);wa=p(Hl,"SPAN",{});var Ll=i(wa);x(Ce.$$.fragment,Ll),Ll.forEach(e),Hl.forEach(e),Zt=d(Dt),xa=p(Dt,"SPAN",{});var Rl=i(xa);Jt=n(Rl,"Preprocess"),Rl.forEach(e),Dt.forEach(e),Xa=d(s),x(Ae.$$.fragment,s),st=d(s),me=p(s,"P",{});var It=i(me);Qt=n(It,"The next step is to load a DistilBERT tokenizer to preprocess the "),va=p(It,"CODE",{});var Yl=i(va);Xt=n(Yl,"tokens"),Yl.forEach(e),sn=n(It," field:"),It.forEach(e),et=d(s),x(Pe.$$.fragment,s),at=d(s),Ws=p(s,"P",{});var ma=i(Ws);en=n(ma,"As you saw in the example "),ya=p(ma,"CODE",{});var Wl=i(ya);an=n(Wl,"tokens"),Wl.forEach(e),tn=n(ma," field above, it looks like the input has already been tokenized. But the input actually hasn\u2019t been tokenized yet and you\u2019ll need to set "),Ea=p(ma,"CODE",{});var Gl=i(Ea);nn=n(Gl,"is_split_into_words=True"),Gl.forEach(e),ln=n(ma," to tokenize the words into subwords. For example:"),ma.forEach(e),tt=d(s),x(Oe.$$.fragment,s),nt=d(s),Gs=p(s,"P",{});var fa=i(Gs);on=n(fa,"However, this adds some special tokens "),qa=p(fa,"CODE",{});var Kl=i(qa);rn=n(Kl,"[CLS]"),Kl.forEach(e),pn=n(fa," and "),Ta=p(fa,"CODE",{});var Ul=i(Ta);cn=n(Ul,"[SEP]"),Ul.forEach(e),hn=n(fa," and the subword tokenization creates a mismatch between the input and labels. A single word corresponding to a single label may now be split into two subwords. You\u2019ll need to realign the tokens and labels by:"),fa.forEach(e),lt=d(s),Ks=p(s,"OL",{});var da=i(Ks);Fe=p(da,"LI",{});var St=i(Fe);un=n(St,"Mapping all tokens to their corresponding word with the "),Be=p(St,"A",{href:!0,rel:!0});var Vl=i(Be);za=p(Vl,"CODE",{});var Zl=i(za);mn=n(Zl,"word_ids"),Zl.forEach(e),Vl.forEach(e),fn=n(St," method."),St.forEach(e),dn=d(da),Hs=p(da,"LI",{});var ve=i(Hs);gn=n(ve,"Assigning the label "),Ca=p(ve,"CODE",{});var Jl=i(Ca);_n=n(Jl,"-100"),Jl.forEach(e),jn=n(ve," to the special tokens "),Aa=p(ve,"CODE",{});var Ql=i(Aa);bn=n(Ql,"[CLS]"),Ql.forEach(e),$n=n(ve," and "),Pa=p(ve,"CODE",{});var Xl=i(Pa);kn=n(Xl,"[SEP]"),Xl.forEach(e),wn=n(ve," so they\u2019re ignored by the PyTorch loss function."),ve.forEach(e),xn=d(da),De=p(da,"LI",{});var Mt=i(De);vn=n(Mt,"Only labeling the first token of a given word. Assign "),Oa=p(Mt,"CODE",{});var so=i(Oa);yn=n(so,"-100"),so.forEach(e),En=n(Mt," to other subtokens from the same word."),Mt.forEach(e),da.forEach(e),ot=d(s),oa=p(s,"P",{});var eo=i(oa);qn=n(eo,"Here is how you can create a function to realign the tokens and labels, and truncate sequences to be no longer than DistilBERT\u2019s maximum input length:"),eo.forEach(e),rt=d(s),x(Ie.$$.fragment,s),pt=d(s),Ps=p(s,"P",{});var ye=i(Ps);Tn=n(ye,"To apply the preprocessing function over the entire dataset, use \u{1F917} Datasets "),Se=p(ye,"A",{href:!0,rel:!0});var ao=i(Se);zn=n(ao,"map"),ao.forEach(e),Cn=n(ye," function. You can speed up the "),Fa=p(ye,"CODE",{});var to=i(Fa);An=n(to,"map"),to.forEach(e),Pn=n(ye," function by setting "),Ba=p(ye,"CODE",{});var no=i(Ba);On=n(no,"batched=True"),no.forEach(e),Fn=n(ye," to process multiple elements of the dataset at once:"),ye.forEach(e),it=d(s),x(Me.$$.fragment,s),ct=d(s),Us=p(s,"P",{});var ga=i(Us);Bn=n(ga,"Now create a batch of examples using "),ra=p(ga,"A",{href:!0});var lo=i(ra);Dn=n(lo,"DataCollatorWithPadding"),lo.forEach(e),In=n(ga,". It\u2019s more efficient to "),Da=p(ga,"EM",{});var oo=i(Da);Sn=n(oo,"dynamically pad"),oo.forEach(e),Mn=n(ga," the sentences to the longest length in a batch during collation, instead of padding the whole dataset to the maximium length."),ga.forEach(e),ht=d(s),x(fe.$$.fragment,s),ut=d(s),ae=p(s,"H2",{class:!0});var Nt=i(ae);de=p(Nt,"A",{id:!0,class:!0,href:!0});var ro=i(de);Ia=p(ro,"SPAN",{});var po=i(Ia);x(Ne.$$.fragment,po),po.forEach(e),ro.forEach(e),Nn=d(Nt),Sa=p(Nt,"SPAN",{});var io=i(Sa);Hn=n(io,"Evaluate"),io.forEach(e),Nt.forEach(e),mt=d(s),Os=p(s,"P",{});var Ee=i(Os);Ln=n(Ee,"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} "),He=p(Ee,"A",{href:!0,rel:!0});var co=i(He);Rn=n(co,"Evaluate"),co.forEach(e),Yn=n(Ee," library. For this task, load the "),Le=p(Ee,"A",{href:!0,rel:!0});var ho=i(Le);Wn=n(ho,"seqeval"),ho.forEach(e),Gn=n(Ee," framework (see the \u{1F917} Evaluate "),Re=p(Ee,"A",{href:!0,rel:!0});var uo=i(Re);Kn=n(uo,"quick tour"),uo.forEach(e),Un=n(Ee," to learn more about how to load and compute a metric). Seqeval actually produces several scores: precision, recall, F1, and accuracy."),Ee.forEach(e),ft=d(s),x(Ye.$$.fragment,s),dt=d(s),ge=p(s,"P",{});var Ht=i(ge);Vn=n(Ht,"Get the NER labels first, and then create a function that passes your true predictions and true labels to "),We=p(Ht,"A",{href:!0,rel:!0});var mo=i(We);Zn=n(mo,"compute"),mo.forEach(e),Jn=n(Ht," to calculate the scores:"),Ht.forEach(e),gt=d(s),x(Ge.$$.fragment,s),_t=d(s),_e=p(s,"P",{});var Lt=i(_e);Qn=n(Lt,"Your "),Ma=p(Lt,"CODE",{});var fo=i(Ma);Xn=n(fo,"compute_metrics"),fo.forEach(e),sl=n(Lt," function is ready to go now, and you\u2019ll return to it when you setup your training."),Lt.forEach(e),jt=d(s),te=p(s,"H2",{class:!0});var Rt=i(te);je=p(Rt,"A",{id:!0,class:!0,href:!0});var go=i(je);Na=p(go,"SPAN",{});var _o=i(Na);x(Ke.$$.fragment,_o),_o.forEach(e),go.forEach(e),el=d(Rt),Ha=p(Rt,"SPAN",{});var jo=i(Ha);al=n(jo,"Train"),jo.forEach(e),Rt.forEach(e),bt=d(s),Vs=p(s,"P",{});var _a=i(Vs);tl=n(_a,"Before you start training your model, create a map of the expected ids to their labels with "),La=p(_a,"CODE",{});var bo=i(La);nl=n(bo,"id2label"),bo.forEach(e),ll=n(_a," and "),Ra=p(_a,"CODE",{});var $o=i(Ra);ol=n($o,"label2id"),$o.forEach(e),rl=n(_a,":"),_a.forEach(e),$t=d(s),x(Ue.$$.fragment,s),kt=d(s),x(be.$$.fragment,s),wt=d(s),x($e.$$.fragment,s),xt=d(s),ne=p(s,"H2",{class:!0});var Yt=i(ne);ke=p(Yt,"A",{id:!0,class:!0,href:!0});var ko=i(ke);Ya=p(ko,"SPAN",{});var wo=i(Ya);x(Ve.$$.fragment,wo),wo.forEach(e),ko.forEach(e),pl=d(Yt),Wa=p(Yt,"SPAN",{});var xo=i(Wa);il=n(xo,"Inference"),xo.forEach(e),Yt.forEach(e),vt=d(s),pa=p(s,"P",{});var vo=i(pa);cl=n(vo,"Great, now that you\u2019ve finetuned a model, you can use it for inference!"),vo.forEach(e),yt=d(s),ia=p(s,"P",{});var yo=i(ia);hl=n(yo,"Grab some text you\u2019d like to run inference on:"),yo.forEach(e),Et=d(s),x(Ze.$$.fragment,s),qt=d(s),Zs=p(s,"P",{});var ja=i(Zs);ul=n(ja,"The simplest way to try out your finetuned model for inference is to use it in a "),ca=p(ja,"A",{href:!0});var Eo=i(ca);ml=n(Eo,"pipeline()"),Eo.forEach(e),fl=n(ja,". Instantiate a "),Ga=p(ja,"CODE",{});var qo=i(Ga);dl=n(qo,"pipeline"),qo.forEach(e),gl=n(ja," for NER with your model, and pass your text to it:"),ja.forEach(e),Tt=d(s),x(Je.$$.fragment,s),zt=d(s),we=p(s,"P",{});var Wt=i(we);_l=n(Wt,"You can also manually replicate the results of the "),Ka=p(Wt,"CODE",{});var To=i(Ka);jl=n(To,"pipeline"),To.forEach(e),bl=n(Wt," if you\u2019d like:"),Wt.forEach(e),Ct=d(s),x(xe.$$.fragment,s),this.h()},h(){j(o,"name","hf:doc:metadata"),j(o,"content",JSON.stringify(Xo)),j(g,"id","token-classification"),j(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"),j(g,"href","#token-classification"),j(l,"class","relative group"),j(B,"href","https://huggingface.co/distilbert-base-uncased"),j(B,"rel","nofollow"),j(V,"href","https://huggingface.co/datasets/wnut_17"),j(V,"rel","nofollow"),j(ss,"id","load-wnut-17-dataset"),j(ss,"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"),j(ss,"href","#load-wnut-17-dataset"),j(os,"class","relative group"),j(ue,"id","preprocess"),j(ue,"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"),j(ue,"href","#preprocess"),j(ee,"class","relative group"),j(Be,"href","https://huggingface.co/docs/tokenizers/python/latest/api/reference.html#tokenizers.Encoding.word_ids"),j(Be,"rel","nofollow"),j(Se,"href","https://huggingface.co/docs/datasets/v2.7.1/en/package_reference/main_classes#datasets.Dataset.map"),j(Se,"rel","nofollow"),j(ra,"href","/docs/transformers/v4.25.1/en/main_classes/data_collator#transformers.DataCollatorWithPadding"),j(de,"id","evaluate"),j(de,"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"),j(de,"href","#evaluate"),j(ae,"class","relative group"),j(He,"href","https://huggingface.co/docs/evaluate/index"),j(He,"rel","nofollow"),j(Le,"href","https://huggingface.co/spaces/evaluate-metric/seqeval"),j(Le,"rel","nofollow"),j(Re,"href","https://huggingface.co/docs/evaluate/a_quick_tour"),j(Re,"rel","nofollow"),j(We,"href","https://huggingface.co/docs/evaluate/v0.3.0/en/package_reference/main_classes#evaluate.EvaluationModule.compute"),j(We,"rel","nofollow"),j(je,"id","train"),j(je,"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"),j(je,"href","#train"),j(te,"class","relative group"),j(ke,"id","inference"),j(ke,"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"),j(ke,"href","#inference"),j(ne,"class","relative group"),j(ca,"href","/docs/transformers/v4.25.1/en/main_classes/pipelines#transformers.pipeline")},m(s,u){a(document.head,o),c(s,_,u),c(s,l,u),a(l,g),a(g,$),v(k,$,null),a(l,C),a(l,z),a(z,P),c(s,O,u),v(F,s,u),c(s,D,u),v(S,s,u),c(s,M,u),c(s,K,u),a(K,U),c(s,Z,u),c(s,G,u),a(G,J),c(s,L,u),c(s,Y,u),a(Y,m),a(m,A),a(m,B),a(B,ps),a(m,R),a(m,V),a(V,Fs),a(m,xs),a(Y,Ts),a(Y,is),a(is,zs),c(s,Q,u),v(us,s,u),c(s,ns,u),c(s,$s,u),a($s,Bs),c(s,ks,u),v(W,s,u),c(s,vs,u),c(s,X,u),a(X,Ds),c(s,fs,u),v(ls,s,u),c(s,Cs,u),c(s,os,u),a(os,ss),a(ss,rs),v(b,rs,null),a(os,N),a(os,as),a(as,es),c(s,Is,u),c(s,ys,u),a(ys,Ss),c(s,ds,u),v(ts,s,u),c(s,ws,u),c(s,Es,u),a(Es,qs),c(s,gs,u),v(cs,s,u),c(s,ms,u),c(s,As,u),a(As,Ms),a(As,Ns),a(Ns,qe),a(As,Te),c(s,Js,u),v(_s,s,u),c(s,Qs,u),c(s,js,u),a(js,ze),a(js,Ls),a(Ls,h),a(js,T),c(s,Rs,u),c(s,hs,u),a(hs,Xs),a(Xs,le),a(le,oe),a(Xs,sa),a(hs,ea),a(hs,bs),a(bs,re),a(re,Ys),a(bs,aa),a(bs,pe),a(pe,ie),a(bs,ta),a(bs,ce),a(ce,he),a(bs,na),a(hs,la),a(hs,se),a(se,ka),a(ka,Ut),a(se,Vt),c(s,Qa,u),c(s,ee,u),a(ee,ue),a(ue,wa),v(Ce,wa,null),a(ee,Zt),a(ee,xa),a(xa,Jt),c(s,Xa,u),v(Ae,s,u),c(s,st,u),c(s,me,u),a(me,Qt),a(me,va),a(va,Xt),a(me,sn),c(s,et,u),v(Pe,s,u),c(s,at,u),c(s,Ws,u),a(Ws,en),a(Ws,ya),a(ya,an),a(Ws,tn),a(Ws,Ea),a(Ea,nn),a(Ws,ln),c(s,tt,u),v(Oe,s,u),c(s,nt,u),c(s,Gs,u),a(Gs,on),a(Gs,qa),a(qa,rn),a(Gs,pn),a(Gs,Ta),a(Ta,cn),a(Gs,hn),c(s,lt,u),c(s,Ks,u),a(Ks,Fe),a(Fe,un),a(Fe,Be),a(Be,za),a(za,mn),a(Fe,fn),a(Ks,dn),a(Ks,Hs),a(Hs,gn),a(Hs,Ca),a(Ca,_n),a(Hs,jn),a(Hs,Aa),a(Aa,bn),a(Hs,$n),a(Hs,Pa),a(Pa,kn),a(Hs,wn),a(Ks,xn),a(Ks,De),a(De,vn),a(De,Oa),a(Oa,yn),a(De,En),c(s,ot,u),c(s,oa,u),a(oa,qn),c(s,rt,u),v(Ie,s,u),c(s,pt,u),c(s,Ps,u),a(Ps,Tn),a(Ps,Se),a(Se,zn),a(Ps,Cn),a(Ps,Fa),a(Fa,An),a(Ps,Pn),a(Ps,Ba),a(Ba,On),a(Ps,Fn),c(s,it,u),v(Me,s,u),c(s,ct,u),c(s,Us,u),a(Us,Bn),a(Us,ra),a(ra,Dn),a(Us,In),a(Us,Da),a(Da,Sn),a(Us,Mn),c(s,ht,u),v(fe,s,u),c(s,ut,u),c(s,ae,u),a(ae,de),a(de,Ia),v(Ne,Ia,null),a(ae,Nn),a(ae,Sa),a(Sa,Hn),c(s,mt,u),c(s,Os,u),a(Os,Ln),a(Os,He),a(He,Rn),a(Os,Yn),a(Os,Le),a(Le,Wn),a(Os,Gn),a(Os,Re),a(Re,Kn),a(Os,Un),c(s,ft,u),v(Ye,s,u),c(s,dt,u),c(s,ge,u),a(ge,Vn),a(ge,We),a(We,Zn),a(ge,Jn),c(s,gt,u),v(Ge,s,u),c(s,_t,u),c(s,_e,u),a(_e,Qn),a(_e,Ma),a(Ma,Xn),a(_e,sl),c(s,jt,u),c(s,te,u),a(te,je),a(je,Na),v(Ke,Na,null),a(te,el),a(te,Ha),a(Ha,al),c(s,bt,u),c(s,Vs,u),a(Vs,tl),a(Vs,La),a(La,nl),a(Vs,ll),a(Vs,Ra),a(Ra,ol),a(Vs,rl),c(s,$t,u),v(Ue,s,u),c(s,kt,u),v(be,s,u),c(s,wt,u),v($e,s,u),c(s,xt,u),c(s,ne,u),a(ne,ke),a(ke,Ya),v(Ve,Ya,null),a(ne,pl),a(ne,Wa),a(Wa,il),c(s,vt,u),c(s,pa,u),a(pa,cl),c(s,yt,u),c(s,ia,u),a(ia,hl),c(s,Et,u),v(Ze,s,u),c(s,qt,u),c(s,Zs,u),a(Zs,ul),a(Zs,ca),a(ca,ml),a(Zs,fl),a(Zs,Ga),a(Ga,dl),a(Zs,gl),c(s,Tt,u),v(Je,s,u),c(s,zt,u),c(s,we,u),a(we,_l),a(we,Ka),a(Ka,jl),a(we,bl),c(s,Ct,u),v(xe,s,u),At=!0},p(s,[u]){const Qe={};u&2&&(Qe.$$scope={dirty:u,ctx:s}),us.$set(Qe);const Ua={};u&2&&(Ua.$$scope={dirty:u,ctx:s}),fe.$set(Ua);const Va={};u&2&&(Va.$$scope={dirty:u,ctx:s}),be.$set(Va);const Za={};u&2&&(Za.$$scope={dirty:u,ctx:s}),$e.$set(Za);const Ja={};u&2&&(Ja.$$scope={dirty:u,ctx:s}),xe.$set(Ja)},i(s){At||(y(k.$$.fragment,s),y(F.$$.fragment,s),y(S.$$.fragment,s),y(us.$$.fragment,s),y(W.$$.fragment,s),y(ls.$$.fragment,s),y(b.$$.fragment,s),y(ts.$$.fragment,s),y(cs.$$.fragment,s),y(_s.$$.fragment,s),y(Ce.$$.fragment,s),y(Ae.$$.fragment,s),y(Pe.$$.fragment,s),y(Oe.$$.fragment,s),y(Ie.$$.fragment,s),y(Me.$$.fragment,s),y(fe.$$.fragment,s),y(Ne.$$.fragment,s),y(Ye.$$.fragment,s),y(Ge.$$.fragment,s),y(Ke.$$.fragment,s),y(Ue.$$.fragment,s),y(be.$$.fragment,s),y($e.$$.fragment,s),y(Ve.$$.fragment,s),y(Ze.$$.fragment,s),y(Je.$$.fragment,s),y(xe.$$.fragment,s),At=!0)},o(s){E(k.$$.fragment,s),E(F.$$.fragment,s),E(S.$$.fragment,s),E(us.$$.fragment,s),E(W.$$.fragment,s),E(ls.$$.fragment,s),E(b.$$.fragment,s),E(ts.$$.fragment,s),E(cs.$$.fragment,s),E(_s.$$.fragment,s),E(Ce.$$.fragment,s),E(Ae.$$.fragment,s),E(Pe.$$.fragment,s),E(Oe.$$.fragment,s),E(Ie.$$.fragment,s),E(Me.$$.fragment,s),E(fe.$$.fragment,s),E(Ne.$$.fragment,s),E(Ye.$$.fragment,s),E(Ge.$$.fragment,s),E(Ke.$$.fragment,s),E(Ue.$$.fragment,s),E(be.$$.fragment,s),E($e.$$.fragment,s),E(Ve.$$.fragment,s),E(Ze.$$.fragment,s),E(Je.$$.fragment,s),E(xe.$$.fragment,s),At=!1},d(s){e(o),s&&e(_),s&&e(l),q(k),s&&e(O),q(F,s),s&&e(D),q(S,s),s&&e(M),s&&e(K),s&&e(Z),s&&e(G),s&&e(L),s&&e(Y),s&&e(Q),q(us,s),s&&e(ns),s&&e($s),s&&e(ks),q(W,s),s&&e(vs),s&&e(X),s&&e(fs),q(ls,s),s&&e(Cs),s&&e(os),q(b),s&&e(Is),s&&e(ys),s&&e(ds),q(ts,s),s&&e(ws),s&&e(Es),s&&e(gs),q(cs,s),s&&e(ms),s&&e(As),s&&e(Js),q(_s,s),s&&e(Qs),s&&e(js),s&&e(Rs),s&&e(hs),s&&e(Qa),s&&e(ee),q(Ce),s&&e(Xa),q(Ae,s),s&&e(st),s&&e(me),s&&e(et),q(Pe,s),s&&e(at),s&&e(Ws),s&&e(tt),q(Oe,s),s&&e(nt),s&&e(Gs),s&&e(lt),s&&e(Ks),s&&e(ot),s&&e(oa),s&&e(rt),q(Ie,s),s&&e(pt),s&&e(Ps),s&&e(it),q(Me,s),s&&e(ct),s&&e(Us),s&&e(ht),q(fe,s),s&&e(ut),s&&e(ae),q(Ne),s&&e(mt),s&&e(Os),s&&e(ft),q(Ye,s),s&&e(dt),s&&e(ge),s&&e(gt),q(Ge,s),s&&e(_t),s&&e(_e),s&&e(jt),s&&e(te),q(Ke),s&&e(bt),s&&e(Vs),s&&e($t),q(Ue,s),s&&e(kt),q(be,s),s&&e(wt),q($e,s),s&&e(xt),s&&e(ne),q(Ve),s&&e(vt),s&&e(pa),s&&e(yt),s&&e(ia),s&&e(Et),q(Ze,s),s&&e(qt),s&&e(Zs),s&&e(Tt),q(Je,s),s&&e(zt),s&&e(we),s&&e(Ct),q(xe,s)}}}const Xo={local:"token-classification",sections:[{local:"load-wnut-17-dataset",title:"Load WNUT 17 dataset"},{local:"preprocess",title:"Preprocess"},{local:"evaluate",title:"Evaluate"},{local:"train",title:"Train"},{local:"inference",title:"Inference"}],title:"Token classification"};function sr(H){return Fo(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class pr extends Co{constructor(o){super();Ao(this,o,sr,Qo,Po,{})}}export{pr as default,Xo as metadata};
