import{s as Xn,f as Qn,o as Hn,n as Pl}from"../chunks/scheduler.37c15a92.js";import{S as En,i as Nn,g as d,s as a,r as w,A as Fn,h as y,f as t,c as i,j as nn,u,x as m,k as Zl,y as zn,a as s,v as J,t as h,b as ot,d as M,w as T,p as rt}from"../chunks/index.7cb9c9b8.js";import{T as pt}from"../chunks/Tip.d10b3fc9.js";import{Y as Gn}from"../chunks/Youtube.8666c400.js";import{C as g}from"../chunks/CodeBlock.abae2786.js";import{C as Yn}from"../chunks/CourseFloatingBanner.df82c153.js";import{F as Sn}from"../chunks/FrameworkSwitchCourse.97630871.js";import{H as ye,E as Ln}from"../chunks/index.c99deea2.js";function Dn(_){let o,f;return o=new Yn({props:{chapter:7,classNames:"absolute z-10 right-0 top-0",notebooks:[{label:"Google Colab",value:"https://colab.research.google.com/github/huggingface/notebooks/blob/master/course/en/chapter7/section2_tf.ipynb"},{label:"Aws Studio",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/master/course/en/chapter7/section2_tf.ipynb"}]}}),{c(){w(o.$$.fragment)},l(r){u(o.$$.fragment,r)},m(r,j){J(o,r,j),f=!0},i(r){f||(M(o.$$.fragment,r),f=!0)},o(r){h(o.$$.fragment,r),f=!1},d(r){T(o,r)}}}function qn(_){let o,f;return o=new Yn({props:{chapter:7,classNames:"absolute z-10 right-0 top-0",notebooks:[{label:"Google Colab",value:"https://colab.research.google.com/github/huggingface/notebooks/blob/master/course/en/chapter7/section2_pt.ipynb"},{label:"Aws Studio",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/master/course/en/chapter7/section2_pt.ipynb"}]}}),{c(){w(o.$$.fragment)},l(r){u(o.$$.fragment,r)},m(r,j){J(o,r,j),f=!0},i(r){f||(M(o.$$.fragment,r),f=!0)},o(r){h(o.$$.fragment,r),f=!1},d(r){T(o,r)}}}function Pn(_){let o,f='💡 As long as your dataset consists of texts split into words with their corresponding labels, you will be able to adapt the data processing procedures described here to your own dataset. Refer back to <a href="/course/chapter5">Chapter 5</a> if you need a refresher on how to load your own custom data in a <code>Dataset</code>.';return{c(){o=d("p"),o.innerHTML=f},l(r){o=y(r,"P",{"data-svelte-h":!0}),m(o)!=="svelte-1ghphyr"&&(o.innerHTML=f)},m(r,j){s(r,o,j)},p:Pl,d(r){r&&t(o)}}}function On(_){let o,f="✏️ <strong>Your turn!</strong> Print the same two sentences with their POS or chunking labels.";return{c(){o=d("p"),o.innerHTML=f},l(r){o=y(r,"P",{"data-svelte-h":!0}),m(o)!=="svelte-86uio9"&&(o.innerHTML=f)},m(r,j){s(r,o,j)},p:Pl,d(r){r&&t(o)}}}function Kn(_){let o,f="✏️ <strong>Your turn!</strong> Some researchers prefer to attribute only one label per word, and assign <code>-100</code> to the other subtokens in a given word. This is to avoid long words that split into lots of subtokens contributing heavily to the loss. Change the previous function to align labels with input IDs by following this rule.";return{c(){o=d("p"),o.innerHTML=f},l(r){o=y(r,"P",{"data-svelte-h":!0}),m(o)!=="svelte-efx0pg"&&(o.innerHTML=f)},m(r,j){s(r,o,j)},p:Pl,d(r){r&&t(o)}}}function ea(_){let o,f,r,j="The actual code using Keras will be very similar to before; the only changes are the way the data is collated into a batch and the metric computation function.",x;return o=new ye({props:{title:"Fine-tuning the model with Keras",local:"fine-tuning-the-model-with-keras",headingTag:"h2"}}),{c(){w(o.$$.fragment),f=a(),r=d("p"),r.textContent=j},l(U){u(o.$$.fragment,U),f=i(U),r=y(U,"P",{"data-svelte-h":!0}),m(r)!=="svelte-y8bzv6"&&(r.textContent=j)},m(U,k){J(o,U,k),s(U,f,k),s(U,r,k),x=!0},i(U){x||(M(o.$$.fragment,U),x=!0)},o(U){h(o.$$.fragment,U),x=!1},d(U){U&&(t(f),t(r)),T(o,U)}}}function la(_){let o,f,r,j="The actual code using the <code>Trainer</code> will be the same as before; the only changes are the way the data is collated into a batch and the metric computation function.",x;return o=new ye({props:{title:"Fine-tuning the model with the Trainer API",local:"fine-tuning-the-model-with-the-trainer-api",headingTag:"h2"}}),{c(){w(o.$$.fragment),f=a(),r=d("p"),r.innerHTML=j},l(U){u(o.$$.fragment,U),f=i(U),r=y(U,"P",{"data-svelte-h":!0}),m(r)!=="svelte-g0rerq"&&(r.innerHTML=j)},m(U,k){J(o,U,k),s(U,f,k),s(U,r,k),x=!0},i(U){x||(M(o.$$.fragment,U),x=!0)},o(U){h(o.$$.fragment,U),x=!1},d(U){U&&(t(f),t(r)),T(o,U)}}}function ta(_){let o,f;return o=new g({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMERhdGFDb2xsYXRvckZvclRva2VuQ2xhc3NpZmljYXRpb24lMEElMEFkYXRhX2NvbGxhdG9yJTIwJTNEJTIwRGF0YUNvbGxhdG9yRm9yVG9rZW5DbGFzc2lmaWNhdGlvbiglMEElMjAlMjAlMjAlMjB0b2tlbml6ZXIlM0R0b2tlbml6ZXIlMkMlMjByZXR1cm5fdGVuc29ycyUzRCUyMnRmJTIyJTBBKQ==",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> DataCollatorForTokenClassification

data_collator = DataCollatorForTokenClassification(
    tokenizer=tokenizer, return_tensors=<span class="hljs-string">&quot;tf&quot;</span>
)`,wrap:!1}}),{c(){w(o.$$.fragment)},l(r){u(o.$$.fragment,r)},m(r,j){J(o,r,j),f=!0},i(r){f||(M(o.$$.fragment,r),f=!0)},o(r){h(o.$$.fragment,r),f=!1},d(r){T(o,r)}}}function sa(_){let o,f;return o=new g({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMERhdGFDb2xsYXRvckZvclRva2VuQ2xhc3NpZmljYXRpb24lMEElMEFkYXRhX2NvbGxhdG9yJTIwJTNEJTIwRGF0YUNvbGxhdG9yRm9yVG9rZW5DbGFzc2lmaWNhdGlvbih0b2tlbml6ZXIlM0R0b2tlbml6ZXIp",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> DataCollatorForTokenClassification

data_collator = DataCollatorForTokenClassification(tokenizer=tokenizer)`,wrap:!1}}),{c(){w(o.$$.fragment)},l(r){u(o.$$.fragment,r)},m(r,j){J(o,r,j),f=!0},i(r){f||(M(o.$$.fragment,r),f=!0)},o(r){h(o.$$.fragment,r),f=!1},d(r){T(o,r)}}}function na(_){let o,f="Our data collator is ready to go! Now let’s use it to make a <code>tf.data.Dataset</code> with the <code>to_tf_dataset()</code> method. You can also use <code>model.prepare_tf_dataset()</code> to do this with a bit less boilerplate code - you’ll see this in some of the other sections of this chapter.",r,j,x,U,k="Next stop: the model itself.",W;return j=new g({props:{code:"dGZfdHJhaW5fZGF0YXNldCUyMCUzRCUyMHRva2VuaXplZF9kYXRhc2V0cyU1QiUyMnRyYWluJTIyJTVELnRvX3RmX2RhdGFzZXQoJTBBJTIwJTIwJTIwJTIwY29sdW1ucyUzRCU1QiUyMmF0dGVudGlvbl9tYXNrJTIyJTJDJTIwJTIyaW5wdXRfaWRzJTIyJTJDJTIwJTIybGFiZWxzJTIyJTJDJTIwJTIydG9rZW5fdHlwZV9pZHMlMjIlNUQlMkMlMEElMjAlMjAlMjAlMjBjb2xsYXRlX2ZuJTNEZGF0YV9jb2xsYXRvciUyQyUwQSUyMCUyMCUyMCUyMHNodWZmbGUlM0RUcnVlJTJDJTBBJTIwJTIwJTIwJTIwYmF0Y2hfc2l6ZSUzRDE2JTJDJTBBKSUwQSUwQXRmX2V2YWxfZGF0YXNldCUyMCUzRCUyMHRva2VuaXplZF9kYXRhc2V0cyU1QiUyMnZhbGlkYXRpb24lMjIlNUQudG9fdGZfZGF0YXNldCglMEElMjAlMjAlMjAlMjBjb2x1bW5zJTNEJTVCJTIyYXR0ZW50aW9uX21hc2slMjIlMkMlMjAlMjJpbnB1dF9pZHMlMjIlMkMlMjAlMjJsYWJlbHMlMjIlMkMlMjAlMjJ0b2tlbl90eXBlX2lkcyUyMiU1RCUyQyUwQSUyMCUyMCUyMCUyMGNvbGxhdGVfZm4lM0RkYXRhX2NvbGxhdG9yJTJDJTBBJTIwJTIwJTIwJTIwc2h1ZmZsZSUzREZhbHNlJTJDJTBBJTIwJTIwJTIwJTIwYmF0Y2hfc2l6ZSUzRDE2JTJDJTBBKQ==",highlighted:`tf_train_dataset = tokenized_datasets[<span class="hljs-string">&quot;train&quot;</span>].to_tf_dataset(
    columns=[<span class="hljs-string">&quot;attention_mask&quot;</span>, <span class="hljs-string">&quot;input_ids&quot;</span>, <span class="hljs-string">&quot;labels&quot;</span>, <span class="hljs-string">&quot;token_type_ids&quot;</span>],
    collate_fn=data_collator,
    shuffle=<span class="hljs-literal">True</span>,
    batch_size=<span class="hljs-number">16</span>,
)

tf_eval_dataset = tokenized_datasets[<span class="hljs-string">&quot;validation&quot;</span>].to_tf_dataset(
    columns=[<span class="hljs-string">&quot;attention_mask&quot;</span>, <span class="hljs-string">&quot;input_ids&quot;</span>, <span class="hljs-string">&quot;labels&quot;</span>, <span class="hljs-string">&quot;token_type_ids&quot;</span>],
    collate_fn=data_collator,
    shuffle=<span class="hljs-literal">False</span>,
    batch_size=<span class="hljs-number">16</span>,
)`,wrap:!1}}),{c(){o=d("p"),o.innerHTML=f,r=a(),w(j.$$.fragment),x=a(),U=d("p"),U.textContent=k},l(b){o=y(b,"P",{"data-svelte-h":!0}),m(o)!=="svelte-jx45qx"&&(o.innerHTML=f),r=i(b),u(j.$$.fragment,b),x=i(b),U=y(b,"P",{"data-svelte-h":!0}),m(U)!=="svelte-68qel6"&&(U.textContent=k)},m(b,Z){s(b,o,Z),s(b,r,Z),J(j,b,Z),s(b,x,Z),s(b,U,Z),W=!0},i(b){W||(M(j.$$.fragment,b),W=!0)},o(b){h(j.$$.fragment,b),W=!1},d(b){b&&(t(o),t(r),t(x),t(U)),T(j,b)}}}function aa(_){let o,f="As we can see, the second set of labels has been padded to the length of the first one using <code>-100</code>s.";return{c(){o=d("p"),o.innerHTML=f},l(r){o=y(r,"P",{"data-svelte-h":!0}),m(o)!=="svelte-110uur8"&&(o.innerHTML=f)},m(r,j){s(r,o,j)},i:Pl,o:Pl,d(r){r&&t(o)}}}function Vn(_){let o,f,r,j="Since we are working on a token classification problem, we will use the <code>TFAutoModelForTokenClassification</code> class. The main thing to remember when defining this model is to pass along some information on the number of labels we have. The easiest way to do this is to pass that number with the <code>num_labels</code> argument, but if we want a nice inference widget working like the one we saw at the beginning of this section, it’s better to set the correct label correspondences instead.",x,U,k="They should be set by two dictionaries, <code>id2label</code> and <code>label2id</code>, which contain the mapping from ID to label and vice versa:",W,b,Z,v,I="Now we can just pass them to the <code>TFAutoModelForTokenClassification.from_pretrained()</code> method, and they will be set in the model’s configuration, then properly saved and uploaded to the Hub:",B,$,G,O,vl='Like when we defined our <code>TFAutoModelForSequenceClassification</code> in <a href="/course/chapter3">Chapter 3</a>, creating the model issues a warning that some weights were not used (the ones from the pretraining head) and some other weights are randomly initialized (the ones from the new token classification head), and that this model should be trained. We will do that in a minute, but first let’s double-check that our model has the right number of labels:',ie,X,oe,K,Ie,A,We,Q,D,ee,Wl="We are now ready to train our model! We have just a little more housekeeping to do first, though: we should log in to Hugging Face and define our training hyperparameters. If you’re working in a notebook, there’s a convenience function to help you with this:",re,le,Ce,V,Bl="This will display a widget where you can enter your Hugging Face login credentials.",pe,te,Al="If you aren’t working in a notebook, just type the following line in your terminal:",se,H,ce,E,_e="After logging in, we can prepare everything we need to compile our model. 🤗 Transformers provides a convenient <code>create_optimizer()</code> function that will give you an <code>AdamW</code> optimizer with appropriate settings for the weight decay and learning rate decay, both of which will improve your model’s performance compared to the built-in <code>Adam</code> optimizer:",Be,N,Me,F,xe="Note also that we don’t supply a <code>loss</code> argument to <code>compile()</code>. This is because the models can actually compute loss internally — if you compile without a loss and supply your labels in the input dictionary (as we do in our datasets), then the model will train using that internal loss, which will be appropriate for the task and model type you have chosen.",Ae,z,me="Next, we define a <code>PushToHubCallback</code> to upload our model to the Hub during training, and fit the model with that callback:",he,ne,ke,R,Gl='You can specify the full name of the repository you want to push to with the <code>hub_model_id</code> argument (in particular, you will have to use this argument to push to an organization). For instance, when we pushed the model to the <a href="https://huggingface.co/huggingface-course" rel="nofollow"><code>huggingface-course</code> organization</a>, we added <code>hub_model_id=&quot;huggingface-course/bert-finetuned-ner&quot;</code>. By default, the repository used will be in your namespace and named after the output directory you set, for example <code>&quot;cool_huggingface_user/bert-finetuned-ner&quot;</code>.',de,ae,Ge,S,Ze="Note that while the training happens, each time the model is saved (here, every epoch) it is uploaded to the Hub in the background. This way, you will be able to to resume your training on another machine if necessary.",$e,Y,Ve="At this stage, you can use the inference widget on the Model Hub to test your model and share it with your friends. You have successfully fine-tuned a model on a token classification task — congratulations! But how good is our model, really? We should evaluate some metrics to find out.",L;return o=new ye({props:{title:"Defining the model",local:"defining-the-model",headingTag:"h3"}}),b=new g({props:{code:"aWQybGFiZWwlMjAlM0QlMjAlN0JpJTNBJTIwbGFiZWwlMjBmb3IlMjBpJTJDJTIwbGFiZWwlMjBpbiUyMGVudW1lcmF0ZShsYWJlbF9uYW1lcyklN0QlMEFsYWJlbDJpZCUyMCUzRCUyMCU3QnYlM0ElMjBrJTIwZm9yJTIwayUyQyUyMHYlMjBpbiUyMGlkMmxhYmVsLml0ZW1zKCklN0Q=",highlighted:`id2label = {i: label <span class="hljs-keyword">for</span> i, label <span class="hljs-keyword">in</span> <span class="hljs-built_in">enumerate</span>(label_names)}
label2id = {v: k <span class="hljs-keyword">for</span> k, v <span class="hljs-keyword">in</span> id2label.items()}`,wrap:!1}}),$=new g({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMFRGQXV0b01vZGVsRm9yVG9rZW5DbGFzc2lmaWNhdGlvbiUwQSUwQW1vZGVsJTIwJTNEJTIwVEZBdXRvTW9kZWxGb3JUb2tlbkNsYXNzaWZpY2F0aW9uLmZyb21fcHJldHJhaW5lZCglMEElMjAlMjAlMjAlMjBtb2RlbF9jaGVja3BvaW50JTJDJTBBJTIwJTIwJTIwJTIwaWQybGFiZWwlM0RpZDJsYWJlbCUyQyUwQSUyMCUyMCUyMCUyMGxhYmVsMmlkJTNEbGFiZWwyaWQlMkMlMEEp",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> TFAutoModelForTokenClassification

model = TFAutoModelForTokenClassification.from_pretrained(
    model_checkpoint,
    id2label=id2label,
    label2id=label2id,
)`,wrap:!1}}),X=new g({props:{code:"bW9kZWwuY29uZmlnLm51bV9sYWJlbHM=",highlighted:"model.config.num_labels",wrap:!1}}),K=new g({props:{code:"OQ==",highlighted:'<span class="hljs-number">9</span>',wrap:!1}}),A=new pt({props:{warning:!0,$$slots:{default:[ia]},$$scope:{ctx:_}}}),Q=new ye({props:{title:"Fine-tuning the model",local:"fine-tuning-the-model",headingTag:"h3"}}),le=new g({props:{code:"ZnJvbSUyMGh1Z2dpbmdmYWNlX2h1YiUyMGltcG9ydCUyMG5vdGVib29rX2xvZ2luJTBBJTBBbm90ZWJvb2tfbG9naW4oKQ==",highlighted:`<span class="hljs-keyword">from</span> huggingface_hub <span class="hljs-keyword">import</span> notebook_login

notebook_login()`,wrap:!1}}),H=new g({props:{code:"aHVnZ2luZ2ZhY2UtY2xpJTIwbG9naW4=",highlighted:"huggingface-cli login",wrap:!1}}),N=new g({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMGNyZWF0ZV9vcHRpbWl6ZXIlMEFpbXBvcnQlMjB0ZW5zb3JmbG93JTIwYXMlMjB0ZiUwQSUwQSUyMyUyMFRyYWluJTIwaW4lMjBtaXhlZC1wcmVjaXNpb24lMjBmbG9hdDE2JTBBJTIzJTIwQ29tbWVudCUyMHRoaXMlMjBsaW5lJTIwb3V0JTIwaWYlMjB5b3UncmUlMjB1c2luZyUyMGElMjBHUFUlMjB0aGF0JTIwd2lsbCUyMG5vdCUyMGJlbmVmaXQlMjBmcm9tJTIwdGhpcyUwQXRmLmtlcmFzLm1peGVkX3ByZWNpc2lvbi5zZXRfZ2xvYmFsX3BvbGljeSglMjJtaXhlZF9mbG9hdDE2JTIyKSUwQSUwQSUyMyUyMFRoZSUyMG51bWJlciUyMG9mJTIwdHJhaW5pbmclMjBzdGVwcyUyMGlzJTIwdGhlJTIwbnVtYmVyJTIwb2YlMjBzYW1wbGVzJTIwaW4lMjB0aGUlMjBkYXRhc2V0JTJDJTIwZGl2aWRlZCUyMGJ5JTIwdGhlJTIwYmF0Y2glMjBzaXplJTIwdGhlbiUyMG11bHRpcGxpZWQlMEElMjMlMjBieSUyMHRoZSUyMHRvdGFsJTIwbnVtYmVyJTIwb2YlMjBlcG9jaHMuJTIwTm90ZSUyMHRoYXQlMjB0aGUlMjB0Zl90cmFpbl9kYXRhc2V0JTIwaGVyZSUyMGlzJTIwYSUyMGJhdGNoZWQlMjB0Zi5kYXRhLkRhdGFzZXQlMkMlMEElMjMlMjBub3QlMjB0aGUlMjBvcmlnaW5hbCUyMEh1Z2dpbmclMjBGYWNlJTIwRGF0YXNldCUyQyUyMHNvJTIwaXRzJTIwbGVuKCklMjBpcyUyMGFscmVhZHklMjBudW1fc2FtcGxlcyUyMCUyRiUyRiUyMGJhdGNoX3NpemUuJTBBbnVtX2Vwb2NocyUyMCUzRCUyMDMlMEFudW1fdHJhaW5fc3RlcHMlMjAlM0QlMjBsZW4odGZfdHJhaW5fZGF0YXNldCklMjAqJTIwbnVtX2Vwb2NocyUwQSUwQW9wdGltaXplciUyQyUyMHNjaGVkdWxlJTIwJTNEJTIwY3JlYXRlX29wdGltaXplciglMEElMjAlMjAlMjAlMjBpbml0X2xyJTNEMmUtNSUyQyUwQSUyMCUyMCUyMCUyMG51bV93YXJtdXBfc3RlcHMlM0QwJTJDJTBBJTIwJTIwJTIwJTIwbnVtX3RyYWluX3N0ZXBzJTNEbnVtX3RyYWluX3N0ZXBzJTJDJTBBJTIwJTIwJTIwJTIwd2VpZ2h0X2RlY2F5X3JhdGUlM0QwLjAxJTJDJTBBKSUwQW1vZGVsLmNvbXBpbGUob3B0aW1pemVyJTNEb3B0aW1pemVyKQ==",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> create_optimizer
<span class="hljs-keyword">import</span> tensorflow <span class="hljs-keyword">as</span> tf

<span class="hljs-comment"># Train in mixed-precision float16</span>
<span class="hljs-comment"># Comment this line out if you&#x27;re using a GPU that will not benefit from this</span>
tf.keras.mixed_precision.set_global_policy(<span class="hljs-string">&quot;mixed_float16&quot;</span>)

<span class="hljs-comment"># The number of training steps is the number of samples in the dataset, divided by the batch size then multiplied</span>
<span class="hljs-comment"># by the total number of epochs. Note that the tf_train_dataset here is a batched tf.data.Dataset,</span>
<span class="hljs-comment"># not the original Hugging Face Dataset, so its len() is already num_samples // batch_size.</span>
num_epochs = <span class="hljs-number">3</span>
num_train_steps = <span class="hljs-built_in">len</span>(tf_train_dataset) * num_epochs

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=num_train_steps,
    weight_decay_rate=<span class="hljs-number">0.01</span>,
)
model.<span class="hljs-built_in">compile</span>(optimizer=optimizer)`,wrap:!1}}),ne=new g({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycy5rZXJhc19jYWxsYmFja3MlMjBpbXBvcnQlMjBQdXNoVG9IdWJDYWxsYmFjayUwQSUwQWNhbGxiYWNrJTIwJTNEJTIwUHVzaFRvSHViQ2FsbGJhY2sob3V0cHV0X2RpciUzRCUyMmJlcnQtZmluZXR1bmVkLW5lciUyMiUyQyUyMHRva2VuaXplciUzRHRva2VuaXplciklMEElMEFtb2RlbC5maXQoJTBBJTIwJTIwJTIwJTIwdGZfdHJhaW5fZGF0YXNldCUyQyUwQSUyMCUyMCUyMCUyMHZhbGlkYXRpb25fZGF0YSUzRHRmX2V2YWxfZGF0YXNldCUyQyUwQSUyMCUyMCUyMCUyMGNhbGxiYWNrcyUzRCU1QmNhbGxiYWNrJTVEJTJDJTBBJTIwJTIwJTIwJTIwZXBvY2hzJTNEbnVtX2Vwb2NocyUyQyUwQSk=",highlighted:`<span class="hljs-keyword">from</span> transformers.keras_callbacks <span class="hljs-keyword">import</span> PushToHubCallback

callback = PushToHubCallback(output_dir=<span class="hljs-string">&quot;bert-finetuned-ner&quot;</span>, tokenizer=tokenizer)

model.fit(
    tf_train_dataset,
    validation_data=tf_eval_dataset,
    callbacks=[callback],
    epochs=num_epochs,
)`,wrap:!1}}),ae=new pt({props:{$$slots:{default:[oa]},$$scope:{ctx:_}}}),{c(){w(o.$$.fragment),f=a(),r=d("p"),r.innerHTML=j,x=a(),U=d("p"),U.innerHTML=k,W=a(),w(b.$$.fragment),Z=a(),v=d("p"),v.innerHTML=I,B=a(),w($.$$.fragment),G=a(),O=d("p"),O.innerHTML=vl,ie=a(),w(X.$$.fragment),oe=a(),w(K.$$.fragment),Ie=a(),w(A.$$.fragment),We=a(),w(Q.$$.fragment),D=a(),ee=d("p"),ee.textContent=Wl,re=a(),w(le.$$.fragment),Ce=a(),V=d("p"),V.textContent=Bl,pe=a(),te=d("p"),te.textContent=Al,se=a(),w(H.$$.fragment),ce=a(),E=d("p"),E.innerHTML=_e,Be=a(),w(N.$$.fragment),Me=a(),F=d("p"),F.innerHTML=xe,Ae=a(),z=d("p"),z.innerHTML=me,he=a(),w(ne.$$.fragment),ke=a(),R=d("p"),R.innerHTML=Gl,de=a(),w(ae.$$.fragment),Ge=a(),S=d("p"),S.textContent=Ze,$e=a(),Y=d("p"),Y.textContent=Ve},l(p){u(o.$$.fragment,p),f=i(p),r=y(p,"P",{"data-svelte-h":!0}),m(r)!=="svelte-g65pls"&&(r.innerHTML=j),x=i(p),U=y(p,"P",{"data-svelte-h":!0}),m(U)!=="svelte-1u16d4j"&&(U.innerHTML=k),W=i(p),u(b.$$.fragment,p),Z=i(p),v=y(p,"P",{"data-svelte-h":!0}),m(v)!=="svelte-110sik5"&&(v.innerHTML=I),B=i(p),u($.$$.fragment,p),G=i(p),O=y(p,"P",{"data-svelte-h":!0}),m(O)!=="svelte-1diayaf"&&(O.innerHTML=vl),ie=i(p),u(X.$$.fragment,p),oe=i(p),u(K.$$.fragment,p),Ie=i(p),u(A.$$.fragment,p),We=i(p),u(Q.$$.fragment,p),D=i(p),ee=y(p,"P",{"data-svelte-h":!0}),m(ee)!=="svelte-7gicgg"&&(ee.textContent=Wl),re=i(p),u(le.$$.fragment,p),Ce=i(p),V=y(p,"P",{"data-svelte-h":!0}),m(V)!=="svelte-1ied0vh"&&(V.textContent=Bl),pe=i(p),te=y(p,"P",{"data-svelte-h":!0}),m(te)!=="svelte-648vlf"&&(te.textContent=Al),se=i(p),u(H.$$.fragment,p),ce=i(p),E=y(p,"P",{"data-svelte-h":!0}),m(E)!=="svelte-18iprmy"&&(E.innerHTML=_e),Be=i(p),u(N.$$.fragment,p),Me=i(p),F=y(p,"P",{"data-svelte-h":!0}),m(F)!=="svelte-iieayr"&&(F.innerHTML=xe),Ae=i(p),z=y(p,"P",{"data-svelte-h":!0}),m(z)!=="svelte-b3y3so"&&(z.innerHTML=me),he=i(p),u(ne.$$.fragment,p),ke=i(p),R=y(p,"P",{"data-svelte-h":!0}),m(R)!=="svelte-ff9ew6"&&(R.innerHTML=Gl),de=i(p),u(ae.$$.fragment,p),Ge=i(p),S=y(p,"P",{"data-svelte-h":!0}),m(S)!=="svelte-2l4fow"&&(S.textContent=Ze),$e=i(p),Y=y(p,"P",{"data-svelte-h":!0}),m(Y)!=="svelte-1s4h6ig"&&(Y.textContent=Ve)},m(p,C){J(o,p,C),s(p,f,C),s(p,r,C),s(p,x,C),s(p,U,C),s(p,W,C),J(b,p,C),s(p,Z,C),s(p,v,C),s(p,B,C),J($,p,C),s(p,G,C),s(p,O,C),s(p,ie,C),J(X,p,C),s(p,oe,C),J(K,p,C),s(p,Ie,C),J(A,p,C),s(p,We,C),J(Q,p,C),s(p,D,C),s(p,ee,C),s(p,re,C),J(le,p,C),s(p,Ce,C),s(p,V,C),s(p,pe,C),s(p,te,C),s(p,se,C),J(H,p,C),s(p,ce,C),s(p,E,C),s(p,Be,C),J(N,p,C),s(p,Me,C),s(p,F,C),s(p,Ae,C),s(p,z,C),s(p,he,C),J(ne,p,C),s(p,ke,C),s(p,R,C),s(p,de,C),J(ae,p,C),s(p,Ge,C),s(p,S,C),s(p,$e,C),s(p,Y,C),L=!0},i(p){L||(M(o.$$.fragment,p),M(b.$$.fragment,p),M($.$$.fragment,p),M(X.$$.fragment,p),M(K.$$.fragment,p),M(A.$$.fragment,p),M(Q.$$.fragment,p),M(le.$$.fragment,p),M(H.$$.fragment,p),M(N.$$.fragment,p),M(ne.$$.fragment,p),M(ae.$$.fragment,p),L=!0)},o(p){h(o.$$.fragment,p),h(b.$$.fragment,p),h($.$$.fragment,p),h(X.$$.fragment,p),h(K.$$.fragment,p),h(A.$$.fragment,p),h(Q.$$.fragment,p),h(le.$$.fragment,p),h(H.$$.fragment,p),h(N.$$.fragment,p),h(ne.$$.fragment,p),h(ae.$$.fragment,p),L=!1},d(p){p&&(t(f),t(r),t(x),t(U),t(W),t(Z),t(v),t(B),t(G),t(O),t(ie),t(oe),t(Ie),t(We),t(D),t(ee),t(re),t(Ce),t(V),t(pe),t(te),t(se),t(ce),t(E),t(Be),t(Me),t(F),t(Ae),t(z),t(he),t(ke),t(R),t(de),t(Ge),t(S),t($e),t(Y)),T(o,p),T(b,p),T($,p),T(X,p),T(K,p),T(A,p),T(Q,p),T(le,p),T(H,p),T(N,p),T(ne,p),T(ae,p)}}}function ia(_){let o,f="⚠️ If you have a model with the wrong number of labels, you will get an obscure error when calling <code>model.fit()</code> later. This can be annoying to debug, so make sure you do this check to confirm you have the expected number of labels.";return{c(){o=d("p"),o.innerHTML=f},l(r){o=y(r,"P",{"data-svelte-h":!0}),m(o)!=="svelte-rp5bkg"&&(o.innerHTML=f)},m(r,j){s(r,o,j)},p:Pl,d(r){r&&t(o)}}}function oa(_){let o,f="💡 If the output directory you are using already exists, it needs to be a local clone of the repository you want to push to. If it isn’t, you’ll get an error when calling <code>model.fit()</code> and will need to set a new name.";return{c(){o=d("p"),o.innerHTML=f},l(r){o=y(r,"P",{"data-svelte-h":!0}),m(o)!=="svelte-fiahcl"&&(o.innerHTML=f)},m(r,j){s(r,o,j)},p:Pl,d(r){r&&t(o)}}}function ra(_){let o,f='The traditional framework used to evaluate token classification prediction is <a href="https://github.com/chakki-works/seqeval" rel="nofollow"><em>seqeval</em></a>. To use this metric, we first need to install the <em>seqeval</em> library:',r,j,x,U,k='We can then load it via the <code>evaluate.load()</code> function like we did in <a href="/course/chapter3">Chapter 3</a>:',W;return j=new g({props:{code:"IXBpcCUyMGluc3RhbGwlMjBzZXFldmFs",highlighted:"!pip install seqeval",wrap:!1}}),{c(){o=d("p"),o.innerHTML=f,r=a(),w(j.$$.fragment),x=a(),U=d("p"),U.innerHTML=k},l(b){o=y(b,"P",{"data-svelte-h":!0}),m(o)!=="svelte-1fnrqj4"&&(o.innerHTML=f),r=i(b),u(j.$$.fragment,b),x=i(b),U=y(b,"P",{"data-svelte-h":!0}),m(U)!=="svelte-1jg3d4v"&&(U.innerHTML=k)},m(b,Z){s(b,o,Z),s(b,r,Z),J(j,b,Z),s(b,x,Z),s(b,U,Z),W=!0},i(b){W||(M(j.$$.fragment,b),W=!0)},o(b){h(j.$$.fragment,b),W=!1},d(b){b&&(t(o),t(r),t(x),t(U)),T(j,b)}}}function pa(_){let o,f="To have the <code>Trainer</code> compute a metric every epoch, we will need to define a <code>compute_metrics()</code> function that takes the arrays of predictions and labels, and returns a dictionary with the metric names and values.",r,j,x='The traditional framework used to evaluate token classification prediction is <a href="https://github.com/chakki-works/seqeval" rel="nofollow"><em>seqeval</em></a>. To use this metric, we first need to install the <em>seqeval</em> library:',U,k,W,b,Z='We can then load it via the <code>evaluate.load()</code> function like we did in <a href="/course/chapter3">Chapter 3</a>:',v;return k=new g({props:{code:"IXBpcCUyMGluc3RhbGwlMjBzZXFldmFs",highlighted:"!pip install seqeval",wrap:!1}}),{c(){o=d("p"),o.innerHTML=f,r=a(),j=d("p"),j.innerHTML=x,U=a(),w(k.$$.fragment),W=a(),b=d("p"),b.innerHTML=Z},l(I){o=y(I,"P",{"data-svelte-h":!0}),m(o)!=="svelte-iegzyq"&&(o.innerHTML=f),r=i(I),j=y(I,"P",{"data-svelte-h":!0}),m(j)!=="svelte-1fnrqj4"&&(j.innerHTML=x),U=i(I),u(k.$$.fragment,I),W=i(I),b=y(I,"P",{"data-svelte-h":!0}),m(b)!=="svelte-1jg3d4v"&&(b.innerHTML=Z)},m(I,B){s(I,o,B),s(I,r,B),s(I,j,B),s(I,U,B),J(k,I,B),s(I,W,B),s(I,b,B),v=!0},i(I){v||(M(k.$$.fragment,I),v=!0)},o(I){h(k.$$.fragment,I),v=!1},d(I){I&&(t(o),t(r),t(j),t(U),t(W),t(b)),T(k,I)}}}function ca(_){let o,f="This is sending back a lot of information! We get the precision, recall, and F1 score for each separate entity, as well as overall. Now let’s see what happens if we try using our actual model predictions to compute some real scores.",r,j,x="TensorFlow doesn’t like concatenating our predictions together, because they have variable sequence lengths. This means we can’t just use <code>model.predict()</code> — but that’s not going to stop us. We’ll get some predictions a batch at a time and concatenate them into one big long list as we go, dropping the <code>-100</code> tokens that indicate masking/padding, then compute metrics on the list at the end:",U,k,W,b,Z,v,I="How did your model do, compared to ours? If you got similar numbers, your training was a success!",B;return k=new g({props:{code:"aW1wb3J0JTIwbnVtcHklMjBhcyUyMG5wJTBBJTBBYWxsX3ByZWRpY3Rpb25zJTIwJTNEJTIwJTVCJTVEJTBBYWxsX2xhYmVscyUyMCUzRCUyMCU1QiU1RCUwQWZvciUyMGJhdGNoJTIwaW4lMjB0Zl9ldmFsX2RhdGFzZXQlM0ElMEElMjAlMjAlMjAlMjBsb2dpdHMlMjAlM0QlMjBtb2RlbC5wcmVkaWN0X29uX2JhdGNoKGJhdGNoKSU1QiUyMmxvZ2l0cyUyMiU1RCUwQSUyMCUyMCUyMCUyMGxhYmVscyUyMCUzRCUyMGJhdGNoJTVCJTIybGFiZWxzJTIyJTVEJTBBJTIwJTIwJTIwJTIwcHJlZGljdGlvbnMlMjAlM0QlMjBucC5hcmdtYXgobG9naXRzJTJDJTIwYXhpcyUzRC0xKSUwQSUyMCUyMCUyMCUyMGZvciUyMHByZWRpY3Rpb24lMkMlMjBsYWJlbCUyMGluJTIwemlwKHByZWRpY3Rpb25zJTJDJTIwbGFiZWxzKSUzQSUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMGZvciUyMHByZWRpY3RlZF9pZHglMkMlMjBsYWJlbF9pZHglMjBpbiUyMHppcChwcmVkaWN0aW9uJTJDJTIwbGFiZWwpJTNBJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwaWYlMjBsYWJlbF9pZHglMjAlM0QlM0QlMjAtMTAwJTNBJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwY29udGludWUlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBhbGxfcHJlZGljdGlvbnMuYXBwZW5kKGxhYmVsX25hbWVzJTVCcHJlZGljdGVkX2lkeCU1RCklMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBhbGxfbGFiZWxzLmFwcGVuZChsYWJlbF9uYW1lcyU1QmxhYmVsX2lkeCU1RCklMEFtZXRyaWMuY29tcHV0ZShwcmVkaWN0aW9ucyUzRCU1QmFsbF9wcmVkaWN0aW9ucyU1RCUyQyUyMHJlZmVyZW5jZXMlM0QlNUJhbGxfbGFiZWxzJTVEKQ==",highlighted:`<span class="hljs-keyword">import</span> numpy <span class="hljs-keyword">as</span> np

all_predictions = []
all_labels = []
<span class="hljs-keyword">for</span> batch <span class="hljs-keyword">in</span> tf_eval_dataset:
    logits = model.predict_on_batch(batch)[<span class="hljs-string">&quot;logits&quot;</span>]
    labels = batch[<span class="hljs-string">&quot;labels&quot;</span>]
    predictions = np.argmax(logits, axis=-<span class="hljs-number">1</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-keyword">for</span> predicted_idx, label_idx <span class="hljs-keyword">in</span> <span class="hljs-built_in">zip</span>(prediction, label):
            <span class="hljs-keyword">if</span> label_idx == -<span class="hljs-number">100</span>:
                <span class="hljs-keyword">continue</span>
            all_predictions.append(label_names[predicted_idx])
            all_labels.append(label_names[label_idx])
metric.compute(predictions=[all_predictions], references=[all_labels])`,wrap:!1}}),b=new g({props:{code:"JTdCJ0xPQyclM0ElMjAlN0IncHJlY2lzaW9uJyUzQSUyMDAuOTElMkMlMjAncmVjYWxsJyUzQSUyMDAuOTIlMkMlMjAnZjEnJTNBJTIwMC45MSUyQyUyMCdudW1iZXInJTNBJTIwMTY2OCU3RCUyQyUwQSUyMCdNSVNDJyUzQSUyMCU3QidwcmVjaXNpb24nJTNBJTIwMC43MCUyQyUyMCdyZWNhbGwnJTNBJTIwMC43OSUyQyUyMCdmMSclM0ElMjAwLjc0JTJDJTIwJ251bWJlciclM0ElMjA3MDIlN0QlMkMlMEElMjAnT1JHJyUzQSUyMCU3QidwcmVjaXNpb24nJTNBJTIwMC44NSUyQyUyMCdyZWNhbGwnJTNBJTIwMC45MCUyQyUyMCdmMSclM0ElMjAwLjg4JTJDJTIwJ251bWJlciclM0ElMjAxNjYxJTdEJTJDJTBBJTIwJ1BFUiclM0ElMjAlN0IncHJlY2lzaW9uJyUzQSUyMDAuOTUlMkMlMjAncmVjYWxsJyUzQSUyMDAuOTUlMkMlMjAnZjEnJTNBJTIwMC45NSUyQyUyMCdudW1iZXInJTNBJTIwMTYxNyU3RCUyQyUwQSUyMCdvdmVyYWxsX3ByZWNpc2lvbiclM0ElMjAwLjg3JTJDJTBBJTIwJ292ZXJhbGxfcmVjYWxsJyUzQSUyMDAuOTElMkMlMEElMjAnb3ZlcmFsbF9mMSclM0ElMjAwLjg5JTJDJTBBJTIwJ292ZXJhbGxfYWNjdXJhY3knJTNBJTIwMC45NyU3RA==",highlighted:`{<span class="hljs-string">&#x27;LOC&#x27;</span>: {<span class="hljs-string">&#x27;precision&#x27;</span>: <span class="hljs-number">0.91</span>, <span class="hljs-string">&#x27;recall&#x27;</span>: <span class="hljs-number">0.92</span>, <span class="hljs-string">&#x27;f1&#x27;</span>: <span class="hljs-number">0.91</span>, <span class="hljs-string">&#x27;number&#x27;</span>: <span class="hljs-number">1668</span>},
 <span class="hljs-string">&#x27;MISC&#x27;</span>: {<span class="hljs-string">&#x27;precision&#x27;</span>: <span class="hljs-number">0.70</span>, <span class="hljs-string">&#x27;recall&#x27;</span>: <span class="hljs-number">0.79</span>, <span class="hljs-string">&#x27;f1&#x27;</span>: <span class="hljs-number">0.74</span>, <span class="hljs-string">&#x27;number&#x27;</span>: <span class="hljs-number">702</span>},
 <span class="hljs-string">&#x27;ORG&#x27;</span>: {<span class="hljs-string">&#x27;precision&#x27;</span>: <span class="hljs-number">0.85</span>, <span class="hljs-string">&#x27;recall&#x27;</span>: <span class="hljs-number">0.90</span>, <span class="hljs-string">&#x27;f1&#x27;</span>: <span class="hljs-number">0.88</span>, <span class="hljs-string">&#x27;number&#x27;</span>: <span class="hljs-number">1661</span>},
 <span class="hljs-string">&#x27;PER&#x27;</span>: {<span class="hljs-string">&#x27;precision&#x27;</span>: <span class="hljs-number">0.95</span>, <span class="hljs-string">&#x27;recall&#x27;</span>: <span class="hljs-number">0.95</span>, <span class="hljs-string">&#x27;f1&#x27;</span>: <span class="hljs-number">0.95</span>, <span class="hljs-string">&#x27;number&#x27;</span>: <span class="hljs-number">1617</span>},
 <span class="hljs-string">&#x27;overall_precision&#x27;</span>: <span class="hljs-number">0.87</span>,
 <span class="hljs-string">&#x27;overall_recall&#x27;</span>: <span class="hljs-number">0.91</span>,
 <span class="hljs-string">&#x27;overall_f1&#x27;</span>: <span class="hljs-number">0.89</span>,
 <span class="hljs-string">&#x27;overall_accuracy&#x27;</span>: <span class="hljs-number">0.97</span>}`,wrap:!1}}),{c(){o=d("p"),o.textContent=f,r=a(),j=d("p"),j.innerHTML=x,U=a(),w(k.$$.fragment),W=a(),w(b.$$.fragment),Z=a(),v=d("p"),v.textContent=I},l($){o=y($,"P",{"data-svelte-h":!0}),m(o)!=="svelte-4fafsz"&&(o.textContent=f),r=i($),j=y($,"P",{"data-svelte-h":!0}),m(j)!=="svelte-1sq6h2i"&&(j.innerHTML=x),U=i($),u(k.$$.fragment,$),W=i($),u(b.$$.fragment,$),Z=i($),v=y($,"P",{"data-svelte-h":!0}),m(v)!=="svelte-1ci3syi"&&(v.textContent=I)},m($,G){s($,o,G),s($,r,G),s($,j,G),s($,U,G),J(k,$,G),s($,W,G),J(b,$,G),s($,Z,G),s($,v,G),B=!0},i($){B||(M(k.$$.fragment,$),M(b.$$.fragment,$),B=!0)},o($){h(k.$$.fragment,$),h(b.$$.fragment,$),B=!1},d($){$&&(t(o),t(r),t(j),t(U),t(W),t(Z),t(v)),T(k,$),T(b,$)}}}function Ma(_){let o,f="This is sending back a lot of information! We get the precision, recall, and F1 score for each separate entity, as well as overall. For our metric computation we will only keep the overall score, but feel free to tweak the <code>compute_metrics()</code> function to return all the metrics you would like reported.",r,j,x="This <code>compute_metrics()</code> function first takes the argmax of the logits to convert them to predictions (as usual, the logits and the probabilities are in the same order, so we don’t need to apply the softmax). Then we have to convert both labels and predictions from integers to strings. We remove all the values where the label is <code>-100</code>, then pass the results to the <code>metric.compute()</code> method:",U,k,W,b,Z="Now that this is done, we are almost ready to define our <code>Trainer</code>. We just need a <code>model</code> to fine-tune!",v;return k=new g({props:{code:"aW1wb3J0JTIwbnVtcHklMjBhcyUyMG5wJTBBJTBBJTBBZGVmJTIwY29tcHV0ZV9tZXRyaWNzKGV2YWxfcHJlZHMpJTNBJTBBJTIwJTIwJTIwJTIwbG9naXRzJTJDJTIwbGFiZWxzJTIwJTNEJTIwZXZhbF9wcmVkcyUwQSUyMCUyMCUyMCUyMHByZWRpY3Rpb25zJTIwJTNEJTIwbnAuYXJnbWF4KGxvZ2l0cyUyQyUyMGF4aXMlM0QtMSklMEElMEElMjAlMjAlMjAlMjAlMjMlMjBSZW1vdmUlMjBpZ25vcmVkJTIwaW5kZXglMjAoc3BlY2lhbCUyMHRva2VucyklMjBhbmQlMjBjb252ZXJ0JTIwdG8lMjBsYWJlbHMlMEElMjAlMjAlMjAlMjB0cnVlX2xhYmVscyUyMCUzRCUyMCU1QiU1QmxhYmVsX25hbWVzJTVCbCU1RCUyMGZvciUyMGwlMjBpbiUyMGxhYmVsJTIwaWYlMjBsJTIwISUzRCUyMC0xMDAlNUQlMjBmb3IlMjBsYWJlbCUyMGluJTIwbGFiZWxzJTVEJTBBJTIwJTIwJTIwJTIwdHJ1ZV9wcmVkaWN0aW9ucyUyMCUzRCUyMCU1QiUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCU1QmxhYmVsX25hbWVzJTVCcCU1RCUyMGZvciUyMChwJTJDJTIwbCklMjBpbiUyMHppcChwcmVkaWN0aW9uJTJDJTIwbGFiZWwpJTIwaWYlMjBsJTIwISUzRCUyMC0xMDAlNUQlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBmb3IlMjBwcmVkaWN0aW9uJTJDJTIwbGFiZWwlMjBpbiUyMHppcChwcmVkaWN0aW9ucyUyQyUyMGxhYmVscyklMEElMjAlMjAlMjAlMjAlNUQlMEElMjAlMjAlMjAlMjBhbGxfbWV0cmljcyUyMCUzRCUyMG1ldHJpYy5jb21wdXRlKHByZWRpY3Rpb25zJTNEdHJ1ZV9wcmVkaWN0aW9ucyUyQyUyMHJlZmVyZW5jZXMlM0R0cnVlX2xhYmVscyklMEElMjAlMjAlMjAlMjByZXR1cm4lMjAlN0IlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjJwcmVjaXNpb24lMjIlM0ElMjBhbGxfbWV0cmljcyU1QiUyMm92ZXJhbGxfcHJlY2lzaW9uJTIyJTVEJTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIycmVjYWxsJTIyJTNBJTIwYWxsX21ldHJpY3MlNUIlMjJvdmVyYWxsX3JlY2FsbCUyMiU1RCUyQyUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMmYxJTIyJTNBJTIwYWxsX21ldHJpY3MlNUIlMjJvdmVyYWxsX2YxJTIyJTVEJTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIyYWNjdXJhY3klMjIlM0ElMjBhbGxfbWV0cmljcyU1QiUyMm92ZXJhbGxfYWNjdXJhY3klMjIlNUQlMkMlMEElMjAlMjAlMjAlMjAlN0Q=",highlighted:`<span class="hljs-keyword">import</span> numpy <span class="hljs-keyword">as</span> np


<span class="hljs-keyword">def</span> <span class="hljs-title function_">compute_metrics</span>(<span class="hljs-params">eval_preds</span>):
    logits, labels = eval_preds
    predictions = np.argmax(logits, axis=-<span class="hljs-number">1</span>)

    <span class="hljs-comment"># Remove ignored index (special tokens) and convert to labels</span>
    true_labels = [[label_names[l] <span class="hljs-keyword">for</span> l <span class="hljs-keyword">in</span> label <span class="hljs-keyword">if</span> l != -<span class="hljs-number">100</span>] <span class="hljs-keyword">for</span> label <span class="hljs-keyword">in</span> labels]
    true_predictions = [
        [label_names[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-keyword">for</span> prediction, label <span class="hljs-keyword">in</span> <span class="hljs-built_in">zip</span>(predictions, labels)
    ]
    all_metrics = metric.compute(predictions=true_predictions, references=true_labels)
    <span class="hljs-keyword">return</span> {
        <span class="hljs-string">&quot;precision&quot;</span>: all_metrics[<span class="hljs-string">&quot;overall_precision&quot;</span>],
        <span class="hljs-string">&quot;recall&quot;</span>: all_metrics[<span class="hljs-string">&quot;overall_recall&quot;</span>],
        <span class="hljs-string">&quot;f1&quot;</span>: all_metrics[<span class="hljs-string">&quot;overall_f1&quot;</span>],
        <span class="hljs-string">&quot;accuracy&quot;</span>: all_metrics[<span class="hljs-string">&quot;overall_accuracy&quot;</span>],
    }`,wrap:!1}}),{c(){o=d("p"),o.innerHTML=f,r=a(),j=d("p"),j.innerHTML=x,U=a(),w(k.$$.fragment),W=a(),b=d("p"),b.innerHTML=Z},l(I){o=y(I,"P",{"data-svelte-h":!0}),m(o)!=="svelte-xoqkxx"&&(o.innerHTML=f),r=i(I),j=y(I,"P",{"data-svelte-h":!0}),m(j)!=="svelte-1cvuvr4"&&(j.innerHTML=x),U=i(I),u(k.$$.fragment,I),W=i(I),b=y(I,"P",{"data-svelte-h":!0}),m(b)!=="svelte-8nj8ty"&&(b.innerHTML=Z)},m(I,B){s(I,o,B),s(I,r,B),s(I,j,B),s(I,U,B),J(k,I,B),s(I,W,B),s(I,b,B),v=!0},i(I){v||(M(k.$$.fragment,I),v=!0)},o(I){h(k.$$.fragment,I),v=!1},d(I){I&&(t(o),t(r),t(j),t(U),t(W),t(b)),T(k,I)}}}function Rn(_){let o,f,r,j="Since we are working on a token classification problem, we will use the <code>AutoModelForTokenClassification</code> class. The main thing to remember when defining this model is to pass along some information on the number of labels we have. The easiest way to do this is to pass that number with the <code>num_labels</code> argument, but if we want a nice inference widget working like the one we saw at the beginning of this section, it’s better to set the correct label correspondences instead.",x,U,k="They should be set by two dictionaries, <code>id2label</code> and <code>label2id</code>, which contain the mappings from ID to label and vice versa:",W,b,Z,v,I="Now we can just pass them to the <code>AutoModelForTokenClassification.from_pretrained()</code> method, and they will be set in the model’s configuration and then properly saved and uploaded to the Hub:",B,$,G,O,vl='Like when we defined our <code>AutoModelForSequenceClassification</code> in <a href="/course/chapter3">Chapter 3</a>, creating the model issues a warning that some weights were not used (the ones from the pretraining head) and some other weights are randomly initialized (the ones from the new token classification head), and that this model should be trained. We will do that in a minute, but first let’s double-check that our model has the right number of labels:',ie,X,oe,K,Ie,A,We,Q,D,ee,Wl="We are now ready to train our model! We just need to do two last things before we define our <code>Trainer</code>: log in to Hugging Face and define our training arguments. If you’re working in a notebook, there’s a convenience function to help you with this:",re,le,Ce,V,Bl="This will display a widget where you can enter your Hugging Face login credentials.",pe,te,Al="If you aren’t working in a notebook, just type the following line in your terminal:",se,H,ce,E,_e="Once this is done, we can define our <code>TrainingArguments</code>:",Be,N,Me,F,xe='You’ve seen most of those before: we set some hyperparameters (like the learning rate, the number of epochs to train for, and the weight decay), and we specify <code>push_to_hub=True</code> to indicate that we want to save the model and evaluate it at the end of every epoch, and that we want to upload our results to the Model Hub. Note that you can specify the name of the repository you want to push to with the <code>hub_model_id</code> argument (in particular, you will have to use this argument to push to an organization). For instance, when we pushed the model to the <a href="https://huggingface.co/huggingface-course" rel="nofollow"><code>huggingface-course</code> organization</a>, we added <code>hub_model_id=&quot;huggingface-course/bert-finetuned-ner&quot;</code> to <code>TrainingArguments</code>. By default, the repository used will be in your namespace and named after the output directory you set, so in our case it will be <code>&quot;sgugger/bert-finetuned-ner&quot;</code>.',Ae,z,me,he,ne="Finally, we just pass everything to the <code>Trainer</code> and launch the training:",ke,R,Gl,de,ae="Note that while the training happens, each time the model is saved (here, every epoch) it is uploaded to the Hub in the background. This way, you will be able to to resume your training on another machine if necessary.",Ge,S,Ze="Once the training is complete, we use the <code>push_to_hub()</code> method to make sure we upload the most recent version of the model:",$e,Y,Ve,L,p="This command returns the URL of the commit it just did, if you want to inspect it:",C,we,Ol,ue,ct="The <code>Trainer</code> also drafts a model card with all the evaluation results and uploads it. At this stage, you can use the inference widget on the Model Hub to test your model and share it with your friends. You have successfully fine-tuned a model on a token classification task — congratulations!",Re,Vl,Mt="If you want to dive a bit more deeply into the training loop, we will now show you how to do the same thing using 🤗 Accelerate.",Ye,Xe,Qe,He,Rl='Let’s now take a look at the full training loop, so you can easily customize the parts you need. It will look a lot like what we did in <a href="/course/chapter3/4">Chapter 3</a>, with a few changes for the evaluation.',ht,Ee,Ne,Fe,Yl="First we need to build the <code>DataLoader</code>s from our datasets. We’ll reuse our <code>data_collator</code> as a <code>collate_fn</code> and shuffle the training set, but not the validation set:",Kl,Je,dt,ze,Xl="Next we reinstantiate our model, to make sure we’re not continuing the fine-tuning from before but starting from the BERT pretrained model again:",yt,Se,Le,Ql,mt="Then we will need an optimizer. We’ll use the classic <code>AdamW</code>, which is like <code>Adam</code>, but with a fix in the way weight decay is applied:",De,qe,Pe,Oe,Hl="Once we have all those objects, we can send them to the <code>accelerator.prepare()</code> method:",wt,Ke,el,ll,tl,El,ut="Now that we have sent our <code>train_dataloader</code> to <code>accelerator.prepare()</code>, we can use its length to compute the number of training steps. Remember that we should always do this after preparing the dataloader, as that method will change its length. We use a classic linear schedule from the learning rate to 0:",ve,sl,nl,al,Nl="Lastly, to push our model to the Hub, we will need to create a <code>Repository</code> object in a working folder. First log in to Hugging Face, if you’re not logged in already. We’ll determine the repository name from the model ID we want to give our model (feel free to replace the <code>repo_name</code> with your own choice; it just needs to contain your username, which is what the function <code>get_full_repo_name()</code> does):",et,Te,Jt,il,ol,Fl,Tt="Then we can clone that repository in a local folder. If it already exists, this local folder should be an existing clone of the repository we are working with:",rl,pl,cl,zl,bt="We can now upload anything we save in <code>output_dir</code> by calling the <code>repo.push_to_hub()</code> method. This will help us upload the intermediate models at the end of each epoch.",Ml,hl,dl,yl,Sl="We are now ready to write the full training loop. To simplify its evaluation part, we define this <code>postprocess()</code> function that takes predictions and labels and converts them to lists of strings, like our <code>metric</code> object expects:",ft,ml,wl,ul,Ll="Then we can write the training loop. After defining a progress bar to follow how training goes, the loop has three parts:",lt,be,ms="<li>The training in itself, which is the classic iteration over the <code>train_dataloader</code>, forward pass through the model, then backward pass and optimizer step.</li> <li>The evaluation, in which there is a novelty after getting the outputs of our model on a batch: since two processes may have padded the inputs and labels to different shapes, we need to use <code>accelerator.pad_across_processes()</code> to make the predictions and labels the same shape before calling the <code>gather()</code> method. If we don’t do this, the evaluation will either error out or hang forever. Then we send the results to <code>metric.add_batch()</code> and call <code>metric.compute()</code> once the evaluation loop is over.</li> <li>Saving and uploading, where we first save the model and the tokenizer, then call <code>repo.push_to_hub()</code>. Notice that we use the argument <code>blocking=False</code> to tell the 🤗 Hub library to push in an asynchronous process. This way, training continues normally and this (long) instruction is executed in the background.</li>",tt,fe,ws="Here’s the complete code for the training loop:",st,je,nt,Ue,jt="In case this is the first time you’re seeing a model saved with 🤗 Accelerate, let’s take a moment to inspect the three lines of code that go with it:",Jl,Dl,at,ge,Ut="The first line is self-explanatory: it tells all the processes to wait until everyone is at that stage before continuing. This is to make sure we have the same model in every process before saving. Then we grab the <code>unwrapped_model</code>, which is the base model we defined. The <code>accelerator.prepare()</code> method changes the model to work in distributed training, so it won’t have the <code>save_pretrained()</code> method anymore; the <code>accelerator.unwrap_model()</code> method undoes that step. Lastly, we call <code>save_pretrained()</code> but tell that method to use <code>accelerator.save()</code> instead of <code>torch.save()</code>.",Tl,ql,gt='Once this is done, you should have a model that produces results pretty similar to the one trained with the <code>Trainer</code>. You can check the model we trained using this code at <a href="https://huggingface.co/huggingface-course/bert-finetuned-ner-accelerate" rel="nofollow"><em>huggingface-course/bert-finetuned-ner-accelerate</em></a>. And if you want to test out any tweaks to the training loop, you can directly implement them by editing the code shown above!',bl;return o=new ye({props:{title:"Defining the model",local:"defining-the-model",headingTag:"h3"}}),b=new g({props:{code:"aWQybGFiZWwlMjAlM0QlMjAlN0JpJTNBJTIwbGFiZWwlMjBmb3IlMjBpJTJDJTIwbGFiZWwlMjBpbiUyMGVudW1lcmF0ZShsYWJlbF9uYW1lcyklN0QlMEFsYWJlbDJpZCUyMCUzRCUyMCU3QnYlM0ElMjBrJTIwZm9yJTIwayUyQyUyMHYlMjBpbiUyMGlkMmxhYmVsLml0ZW1zKCklN0Q=",highlighted:`id2label = {i: label <span class="hljs-keyword">for</span> i, label <span class="hljs-keyword">in</span> <span class="hljs-built_in">enumerate</span>(label_names)}
label2id = {v: k <span class="hljs-keyword">for</span> k, v <span class="hljs-keyword">in</span> id2label.items()}`,wrap:!1}}),$=new g({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9Nb2RlbEZvclRva2VuQ2xhc3NpZmljYXRpb24lMEElMEFtb2RlbCUyMCUzRCUyMEF1dG9Nb2RlbEZvclRva2VuQ2xhc3NpZmljYXRpb24uZnJvbV9wcmV0cmFpbmVkKCUwQSUyMCUyMCUyMCUyMG1vZGVsX2NoZWNrcG9pbnQlMkMlMEElMjAlMjAlMjAlMjBpZDJsYWJlbCUzRGlkMmxhYmVsJTJDJTBBJTIwJTIwJTIwJTIwbGFiZWwyaWQlM0RsYWJlbDJpZCUyQyUwQSk=",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoModelForTokenClassification

model = AutoModelForTokenClassification.from_pretrained(
    model_checkpoint,
    id2label=id2label,
    label2id=label2id,
)`,wrap:!1}}),X=new g({props:{code:"bW9kZWwuY29uZmlnLm51bV9sYWJlbHM=",highlighted:"model.config.num_labels",wrap:!1}}),K=new g({props:{code:"OQ==",highlighted:'<span class="hljs-number">9</span>',wrap:!1}}),A=new pt({props:{warning:!0,$$slots:{default:[ha]},$$scope:{ctx:_}}}),Q=new ye({props:{title:"Fine-tuning the model",local:"fine-tuning-the-model",headingTag:"h3"}}),le=new g({props:{code:"ZnJvbSUyMGh1Z2dpbmdmYWNlX2h1YiUyMGltcG9ydCUyMG5vdGVib29rX2xvZ2luJTBBJTBBbm90ZWJvb2tfbG9naW4oKQ==",highlighted:`<span class="hljs-keyword">from</span> huggingface_hub <span class="hljs-keyword">import</span> notebook_login

notebook_login()`,wrap:!1}}),H=new g({props:{code:"aHVnZ2luZ2ZhY2UtY2xpJTIwbG9naW4=",highlighted:"huggingface-cli login",wrap:!1}}),N=new g({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMFRyYWluaW5nQXJndW1lbnRzJTBBJTBBYXJncyUyMCUzRCUyMFRyYWluaW5nQXJndW1lbnRzKCUwQSUyMCUyMCUyMCUyMCUyMmJlcnQtZmluZXR1bmVkLW5lciUyMiUyQyUwQSUyMCUyMCUyMCUyMGV2YWx1YXRpb25fc3RyYXRlZ3klM0QlMjJlcG9jaCUyMiUyQyUwQSUyMCUyMCUyMCUyMHNhdmVfc3RyYXRlZ3klM0QlMjJlcG9jaCUyMiUyQyUwQSUyMCUyMCUyMCUyMGxlYXJuaW5nX3JhdGUlM0QyZS01JTJDJTBBJTIwJTIwJTIwJTIwbnVtX3RyYWluX2Vwb2NocyUzRDMlMkMlMEElMjAlMjAlMjAlMjB3ZWlnaHRfZGVjYXklM0QwLjAxJTJDJTBBJTIwJTIwJTIwJTIwcHVzaF90b19odWIlM0RUcnVlJTJDJTBBKQ==",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> TrainingArguments

args = TrainingArguments(
    <span class="hljs-string">&quot;bert-finetuned-ner&quot;</span>,
    evaluation_strategy=<span class="hljs-string">&quot;epoch&quot;</span>,
    save_strategy=<span class="hljs-string">&quot;epoch&quot;</span>,
    learning_rate=<span class="hljs-number">2e-5</span>,
    num_train_epochs=<span class="hljs-number">3</span>,
    weight_decay=<span class="hljs-number">0.01</span>,
    push_to_hub=<span class="hljs-literal">True</span>,
)`,wrap:!1}}),z=new pt({props:{$$slots:{default:[da]},$$scope:{ctx:_}}}),R=new g({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMFRyYWluZXIlMEElMEF0cmFpbmVyJTIwJTNEJTIwVHJhaW5lciglMEElMjAlMjAlMjAlMjBtb2RlbCUzRG1vZGVsJTJDJTBBJTIwJTIwJTIwJTIwYXJncyUzRGFyZ3MlMkMlMEElMjAlMjAlMjAlMjB0cmFpbl9kYXRhc2V0JTNEdG9rZW5pemVkX2RhdGFzZXRzJTVCJTIydHJhaW4lMjIlNUQlMkMlMEElMjAlMjAlMjAlMjBldmFsX2RhdGFzZXQlM0R0b2tlbml6ZWRfZGF0YXNldHMlNUIlMjJ2YWxpZGF0aW9uJTIyJTVEJTJDJTBBJTIwJTIwJTIwJTIwZGF0YV9jb2xsYXRvciUzRGRhdGFfY29sbGF0b3IlMkMlMEElMjAlMjAlMjAlMjBjb21wdXRlX21ldHJpY3MlM0Rjb21wdXRlX21ldHJpY3MlMkMlMEElMjAlMjAlMjAlMjBwcm9jZXNzaW5nX2NsYXNzJTNEdG9rZW5pemVyJTJDJTBBKSUwQXRyYWluZXIudHJhaW4oKQ==",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> Trainer

trainer = Trainer(
    model=model,
    args=args,
    train_dataset=tokenized_datasets[<span class="hljs-string">&quot;train&quot;</span>],
    eval_dataset=tokenized_datasets[<span class="hljs-string">&quot;validation&quot;</span>],
    data_collator=data_collator,
    compute_metrics=compute_metrics,
    processing_class=tokenizer,
)
trainer.train()`,wrap:!1}}),Y=new g({props:{code:"dHJhaW5lci5wdXNoX3RvX2h1Yihjb21taXRfbWVzc2FnZSUzRCUyMlRyYWluaW5nJTIwY29tcGxldGUlMjIp",highlighted:'trainer.push_to_hub(commit_message=<span class="hljs-string">&quot;Training complete&quot;</span>)',wrap:!1}}),we=new g({props:{code:"J2h0dHBzJTNBJTJGJTJGaHVnZ2luZ2ZhY2UuY28lMkZzZ3VnZ2VyJTJGYmVydC1maW5ldHVuZWQtbmVyJTJGY29tbWl0JTJGMjZhYjIxZTViMTU2OGY5YWZlY2NkYWVkMmQ4NzE1ZjU3MWQ3ODZlZCc=",highlighted:'<span class="hljs-string">&#x27;https://huggingface.co/sgugger/bert-finetuned-ner/commit/26ab21e5b1568f9afeccdaed2d8715f571d786ed&#x27;</span>',wrap:!1}}),Xe=new ye({props:{title:"A custom training loop",local:"a-custom-training-loop",headingTag:"h2"}}),Ee=new ye({props:{title:"Preparing everything for training",local:"preparing-everything-for-training",headingTag:"h3"}}),Je=new g({props:{code:"ZnJvbSUyMHRvcmNoLnV0aWxzLmRhdGElMjBpbXBvcnQlMjBEYXRhTG9hZGVyJTBBJTBBdHJhaW5fZGF0YWxvYWRlciUyMCUzRCUyMERhdGFMb2FkZXIoJTBBJTIwJTIwJTIwJTIwdG9rZW5pemVkX2RhdGFzZXRzJTVCJTIydHJhaW4lMjIlNUQlMkMlMEElMjAlMjAlMjAlMjBzaHVmZmxlJTNEVHJ1ZSUyQyUwQSUyMCUyMCUyMCUyMGNvbGxhdGVfZm4lM0RkYXRhX2NvbGxhdG9yJTJDJTBBJTIwJTIwJTIwJTIwYmF0Y2hfc2l6ZSUzRDglMkMlMEEpJTBBZXZhbF9kYXRhbG9hZGVyJTIwJTNEJTIwRGF0YUxvYWRlciglMEElMjAlMjAlMjAlMjB0b2tlbml6ZWRfZGF0YXNldHMlNUIlMjJ2YWxpZGF0aW9uJTIyJTVEJTJDJTIwY29sbGF0ZV9mbiUzRGRhdGFfY29sbGF0b3IlMkMlMjBiYXRjaF9zaXplJTNEOCUwQSk=",highlighted:`<span class="hljs-keyword">from</span> torch.utils.data <span class="hljs-keyword">import</span> DataLoader

train_dataloader = DataLoader(
    tokenized_datasets[<span class="hljs-string">&quot;train&quot;</span>],
    shuffle=<span class="hljs-literal">True</span>,
    collate_fn=data_collator,
    batch_size=<span class="hljs-number">8</span>,
)
eval_dataloader = DataLoader(
    tokenized_datasets[<span class="hljs-string">&quot;validation&quot;</span>], collate_fn=data_collator, batch_size=<span class="hljs-number">8</span>
)`,wrap:!1}}),Se=new g({props:{code:"bW9kZWwlMjAlM0QlMjBBdXRvTW9kZWxGb3JUb2tlbkNsYXNzaWZpY2F0aW9uLmZyb21fcHJldHJhaW5lZCglMEElMjAlMjAlMjAlMjBtb2RlbF9jaGVja3BvaW50JTJDJTBBJTIwJTIwJTIwJTIwaWQybGFiZWwlM0RpZDJsYWJlbCUyQyUwQSUyMCUyMCUyMCUyMGxhYmVsMmlkJTNEbGFiZWwyaWQlMkMlMEEp",highlighted:`model = AutoModelForTokenClassification.from_pretrained(
    model_checkpoint,
    id2label=id2label,
    label2id=label2id,
)`,wrap:!1}}),qe=new g({props:{code:"ZnJvbSUyMHRvcmNoLm9wdGltJTIwaW1wb3J0JTIwQWRhbVclMEElMEFvcHRpbWl6ZXIlMjAlM0QlMjBBZGFtVyhtb2RlbC5wYXJhbWV0ZXJzKCklMkMlMjBsciUzRDJlLTUp",highlighted:`<span class="hljs-keyword">from</span> torch.optim <span class="hljs-keyword">import</span> AdamW

optimizer = AdamW(model.parameters(), lr=<span class="hljs-number">2e-5</span>)`,wrap:!1}}),Ke=new g({props:{code:"ZnJvbSUyMGFjY2VsZXJhdGUlMjBpbXBvcnQlMjBBY2NlbGVyYXRvciUwQSUwQWFjY2VsZXJhdG9yJTIwJTNEJTIwQWNjZWxlcmF0b3IoKSUwQW1vZGVsJTJDJTIwb3B0aW1pemVyJTJDJTIwdHJhaW5fZGF0YWxvYWRlciUyQyUyMGV2YWxfZGF0YWxvYWRlciUyMCUzRCUyMGFjY2VsZXJhdG9yLnByZXBhcmUoJTBBJTIwJTIwJTIwJTIwbW9kZWwlMkMlMjBvcHRpbWl6ZXIlMkMlMjB0cmFpbl9kYXRhbG9hZGVyJTJDJTIwZXZhbF9kYXRhbG9hZGVyJTBBKQ==",highlighted:`<span class="hljs-keyword">from</span> accelerate <span class="hljs-keyword">import</span> Accelerator

accelerator = Accelerator()
model, optimizer, train_dataloader, eval_dataloader = accelerator.prepare(
    model, optimizer, train_dataloader, eval_dataloader
)`,wrap:!1}}),ll=new pt({props:{$$slots:{default:[ya]},$$scope:{ctx:_}}}),sl=new g({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMGdldF9zY2hlZHVsZXIlMEElMEFudW1fdHJhaW5fZXBvY2hzJTIwJTNEJTIwMyUwQW51bV91cGRhdGVfc3RlcHNfcGVyX2Vwb2NoJTIwJTNEJTIwbGVuKHRyYWluX2RhdGFsb2FkZXIpJTBBbnVtX3RyYWluaW5nX3N0ZXBzJTIwJTNEJTIwbnVtX3RyYWluX2Vwb2NocyUyMColMjBudW1fdXBkYXRlX3N0ZXBzX3Blcl9lcG9jaCUwQSUwQWxyX3NjaGVkdWxlciUyMCUzRCUyMGdldF9zY2hlZHVsZXIoJTBBJTIwJTIwJTIwJTIwJTIybGluZWFyJTIyJTJDJTBBJTIwJTIwJTIwJTIwb3B0aW1pemVyJTNEb3B0aW1pemVyJTJDJTBBJTIwJTIwJTIwJTIwbnVtX3dhcm11cF9zdGVwcyUzRDAlMkMlMEElMjAlMjAlMjAlMjBudW1fdHJhaW5pbmdfc3RlcHMlM0RudW1fdHJhaW5pbmdfc3RlcHMlMkMlMEEp",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> get_scheduler

num_train_epochs = <span class="hljs-number">3</span>
num_update_steps_per_epoch = <span class="hljs-built_in">len</span>(train_dataloader)
num_training_steps = num_train_epochs * num_update_steps_per_epoch

lr_scheduler = get_scheduler(
    <span class="hljs-string">&quot;linear&quot;</span>,
    optimizer=optimizer,
    num_warmup_steps=<span class="hljs-number">0</span>,
    num_training_steps=num_training_steps,
)`,wrap:!1}}),Te=new g({props:{code:"ZnJvbSUyMGh1Z2dpbmdmYWNlX2h1YiUyMGltcG9ydCUyMFJlcG9zaXRvcnklMkMlMjBnZXRfZnVsbF9yZXBvX25hbWUlMEElMEFtb2RlbF9uYW1lJTIwJTNEJTIwJTIyYmVydC1maW5ldHVuZWQtbmVyLWFjY2VsZXJhdGUlMjIlMEFyZXBvX25hbWUlMjAlM0QlMjBnZXRfZnVsbF9yZXBvX25hbWUobW9kZWxfbmFtZSklMEFyZXBvX25hbWU=",highlighted:`<span class="hljs-keyword">from</span> huggingface_hub <span class="hljs-keyword">import</span> Repository, get_full_repo_name

model_name = <span class="hljs-string">&quot;bert-finetuned-ner-accelerate&quot;</span>
repo_name = get_full_repo_name(model_name)
repo_name`,wrap:!1}}),il=new g({props:{code:"J3NndWdnZXIlMkZiZXJ0LWZpbmV0dW5lZC1uZXItYWNjZWxlcmF0ZSc=",highlighted:'<span class="hljs-string">&#x27;sgugger/bert-finetuned-ner-accelerate&#x27;</span>',wrap:!1}}),pl=new g({props:{code:"b3V0cHV0X2RpciUyMCUzRCUyMCUyMmJlcnQtZmluZXR1bmVkLW5lci1hY2NlbGVyYXRlJTIyJTBBcmVwbyUyMCUzRCUyMFJlcG9zaXRvcnkob3V0cHV0X2RpciUyQyUyMGNsb25lX2Zyb20lM0RyZXBvX25hbWUp",highlighted:`output_dir = <span class="hljs-string">&quot;bert-finetuned-ner-accelerate&quot;</span>
repo = Repository(output_dir, clone_from=repo_name)`,wrap:!1}}),hl=new ye({props:{title:"Training loop",local:"training-loop",headingTag:"h3"}}),ml=new g({props:{code:"ZGVmJTIwcG9zdHByb2Nlc3MocHJlZGljdGlvbnMlMkMlMjBsYWJlbHMpJTNBJTBBJTIwJTIwJTIwJTIwcHJlZGljdGlvbnMlMjAlM0QlMjBwcmVkaWN0aW9ucy5kZXRhY2goKS5jcHUoKS5jbG9uZSgpLm51bXB5KCklMEElMjAlMjAlMjAlMjBsYWJlbHMlMjAlM0QlMjBsYWJlbHMuZGV0YWNoKCkuY3B1KCkuY2xvbmUoKS5udW1weSgpJTBBJTBBJTIwJTIwJTIwJTIwJTIzJTIwUmVtb3ZlJTIwaWdub3JlZCUyMGluZGV4JTIwKHNwZWNpYWwlMjB0b2tlbnMpJTIwYW5kJTIwY29udmVydCUyMHRvJTIwbGFiZWxzJTBBJTIwJTIwJTIwJTIwdHJ1ZV9sYWJlbHMlMjAlM0QlMjAlNUIlNUJsYWJlbF9uYW1lcyU1QmwlNUQlMjBmb3IlMjBsJTIwaW4lMjBsYWJlbCUyMGlmJTIwbCUyMCElM0QlMjAtMTAwJTVEJTIwZm9yJTIwbGFiZWwlMjBpbiUyMGxhYmVscyU1RCUwQSUyMCUyMCUyMCUyMHRydWVfcHJlZGljdGlvbnMlMjAlM0QlMjAlNUIlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlNUJsYWJlbF9uYW1lcyU1QnAlNUQlMjBmb3IlMjAocCUyQyUyMGwpJTIwaW4lMjB6aXAocHJlZGljdGlvbiUyQyUyMGxhYmVsKSUyMGlmJTIwbCUyMCElM0QlMjAtMTAwJTVEJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwZm9yJTIwcHJlZGljdGlvbiUyQyUyMGxhYmVsJTIwaW4lMjB6aXAocHJlZGljdGlvbnMlMkMlMjBsYWJlbHMpJTBBJTIwJTIwJTIwJTIwJTVEJTBBJTIwJTIwJTIwJTIwcmV0dXJuJTIwdHJ1ZV9sYWJlbHMlMkMlMjB0cnVlX3ByZWRpY3Rpb25z",highlighted:`<span class="hljs-keyword">def</span> <span class="hljs-title function_">postprocess</span>(<span class="hljs-params">predictions, labels</span>):
    predictions = predictions.detach().cpu().clone().numpy()
    labels = labels.detach().cpu().clone().numpy()

    <span class="hljs-comment"># Remove ignored index (special tokens) and convert to labels</span>
    true_labels = [[label_names[l] <span class="hljs-keyword">for</span> l <span class="hljs-keyword">in</span> label <span class="hljs-keyword">if</span> l != -<span class="hljs-number">100</span>] <span class="hljs-keyword">for</span> label <span class="hljs-keyword">in</span> labels]
    true_predictions = [
        [label_names[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-keyword">for</span> prediction, label <span class="hljs-keyword">in</span> <span class="hljs-built_in">zip</span>(predictions, labels)
    ]
    <span class="hljs-keyword">return</span> true_labels, true_predictions`,wrap:!1}}),je=new g({props:{code:"ZnJvbSUyMHRxZG0uYXV0byUyMGltcG9ydCUyMHRxZG0lMEFpbXBvcnQlMjB0b3JjaCUwQSUwQXByb2dyZXNzX2JhciUyMCUzRCUyMHRxZG0ocmFuZ2UobnVtX3RyYWluaW5nX3N0ZXBzKSklMEElMEFmb3IlMjBlcG9jaCUyMGluJTIwcmFuZ2UobnVtX3RyYWluX2Vwb2NocyklM0ElMEElMjAlMjAlMjAlMjAlMjMlMjBUcmFpbmluZyUwQSUyMCUyMCUyMCUyMG1vZGVsLnRyYWluKCklMEElMjAlMjAlMjAlMjBmb3IlMjBiYXRjaCUyMGluJTIwdHJhaW5fZGF0YWxvYWRlciUzQSUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMG91dHB1dHMlMjAlM0QlMjBtb2RlbCgqKmJhdGNoKSUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMGxvc3MlMjAlM0QlMjBvdXRwdXRzLmxvc3MlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBhY2NlbGVyYXRvci5iYWNrd2FyZChsb3NzKSUwQSUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMG9wdGltaXplci5zdGVwKCklMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBscl9zY2hlZHVsZXIuc3RlcCgpJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwb3B0aW1pemVyLnplcm9fZ3JhZCgpJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwcHJvZ3Jlc3NfYmFyLnVwZGF0ZSgxKSUwQSUwQSUyMCUyMCUyMCUyMCUyMyUyMEV2YWx1YXRpb24lMEElMjAlMjAlMjAlMjBtb2RlbC5ldmFsKCklMEElMjAlMjAlMjAlMjBmb3IlMjBiYXRjaCUyMGluJTIwZXZhbF9kYXRhbG9hZGVyJTNBJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwd2l0aCUyMHRvcmNoLm5vX2dyYWQoKSUzQSUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMG91dHB1dHMlMjAlM0QlMjBtb2RlbCgqKmJhdGNoKSUwQSUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMHByZWRpY3Rpb25zJTIwJTNEJTIwb3V0cHV0cy5sb2dpdHMuYXJnbWF4KGRpbSUzRC0xKSUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMGxhYmVscyUyMCUzRCUyMGJhdGNoJTVCJTIybGFiZWxzJTIyJTVEJTBBJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIzJTIwTmVjZXNzYXJ5JTIwdG8lMjBwYWQlMjBwcmVkaWN0aW9ucyUyMGFuZCUyMGxhYmVscyUyMGZvciUyMGJlaW5nJTIwZ2F0aGVyZWQlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBwcmVkaWN0aW9ucyUyMCUzRCUyMGFjY2VsZXJhdG9yLnBhZF9hY3Jvc3NfcHJvY2Vzc2VzKHByZWRpY3Rpb25zJTJDJTIwZGltJTNEMSUyQyUyMHBhZF9pbmRleCUzRC0xMDApJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwbGFiZWxzJTIwJTNEJTIwYWNjZWxlcmF0b3IucGFkX2Fjcm9zc19wcm9jZXNzZXMobGFiZWxzJTJDJTIwZGltJTNEMSUyQyUyMHBhZF9pbmRleCUzRC0xMDApJTBBJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwcHJlZGljdGlvbnNfZ2F0aGVyZWQlMjAlM0QlMjBhY2NlbGVyYXRvci5nYXRoZXIocHJlZGljdGlvbnMpJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwbGFiZWxzX2dhdGhlcmVkJTIwJTNEJTIwYWNjZWxlcmF0b3IuZ2F0aGVyKGxhYmVscyklMEElMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjB0cnVlX3ByZWRpY3Rpb25zJTJDJTIwdHJ1ZV9sYWJlbHMlMjAlM0QlMjBwb3N0cHJvY2VzcyhwcmVkaWN0aW9uc19nYXRoZXJlZCUyQyUyMGxhYmVsc19nYXRoZXJlZCklMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBtZXRyaWMuYWRkX2JhdGNoKHByZWRpY3Rpb25zJTNEdHJ1ZV9wcmVkaWN0aW9ucyUyQyUyMHJlZmVyZW5jZXMlM0R0cnVlX2xhYmVscyklMEElMEElMjAlMjAlMjAlMjByZXN1bHRzJTIwJTNEJTIwbWV0cmljLmNvbXB1dGUoKSUwQSUyMCUyMCUyMCUyMHByaW50KCUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMGYlMjJlcG9jaCUyMCU3QmVwb2NoJTdEJTNBJTIyJTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTdCJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwa2V5JTNBJTIwcmVzdWx0cyU1QmYlMjJvdmVyYWxsXyU3QmtleSU3RCUyMiU1RCUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMGZvciUyMGtleSUyMGluJTIwJTVCJTIycHJlY2lzaW9uJTIyJTJDJTIwJTIycmVjYWxsJTIyJTJDJTIwJTIyZjElMjIlMkMlMjAlMjJhY2N1cmFjeSUyMiU1RCUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCU3RCUyQyUwQSUyMCUyMCUyMCUyMCklMEElMEElMjAlMjAlMjAlMjAlMjMlMjBTYXZlJTIwYW5kJTIwdXBsb2FkJTBBJTIwJTIwJTIwJTIwYWNjZWxlcmF0b3Iud2FpdF9mb3JfZXZlcnlvbmUoKSUwQSUyMCUyMCUyMCUyMHVud3JhcHBlZF9tb2RlbCUyMCUzRCUyMGFjY2VsZXJhdG9yLnVud3JhcF9tb2RlbChtb2RlbCklMEElMjAlMjAlMjAlMjB1bndyYXBwZWRfbW9kZWwuc2F2ZV9wcmV0cmFpbmVkKG91dHB1dF9kaXIlMkMlMjBzYXZlX2Z1bmN0aW9uJTNEYWNjZWxlcmF0b3Iuc2F2ZSklMEElMjAlMjAlMjAlMjBpZiUyMGFjY2VsZXJhdG9yLmlzX21haW5fcHJvY2VzcyUzQSUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMHRva2VuaXplci5zYXZlX3ByZXRyYWluZWQob3V0cHV0X2RpciklMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjByZXBvLnB1c2hfdG9faHViKCUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMGNvbW1pdF9tZXNzYWdlJTNEZiUyMlRyYWluaW5nJTIwaW4lMjBwcm9ncmVzcyUyMGVwb2NoJTIwJTdCZXBvY2glN0QlMjIlMkMlMjBibG9ja2luZyUzREZhbHNlJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwKQ==",highlighted:`<span class="hljs-keyword">from</span> tqdm.auto <span class="hljs-keyword">import</span> tqdm
<span class="hljs-keyword">import</span> torch

progress_bar = tqdm(<span class="hljs-built_in">range</span>(num_training_steps))

<span class="hljs-keyword">for</span> epoch <span class="hljs-keyword">in</span> <span class="hljs-built_in">range</span>(num_train_epochs):
    <span class="hljs-comment"># Training</span>
    model.train()
    <span class="hljs-keyword">for</span> batch <span class="hljs-keyword">in</span> train_dataloader:
        outputs = model(**batch)
        loss = outputs.loss
        accelerator.backward(loss)

        optimizer.step()
        lr_scheduler.step()
        optimizer.zero_grad()
        progress_bar.update(<span class="hljs-number">1</span>)

    <span class="hljs-comment"># Evaluation</span>
    model.<span class="hljs-built_in">eval</span>()
    <span class="hljs-keyword">for</span> batch <span class="hljs-keyword">in</span> eval_dataloader:
        <span class="hljs-keyword">with</span> torch.no_grad():
            outputs = model(**batch)

        predictions = outputs.logits.argmax(dim=-<span class="hljs-number">1</span>)
        labels = batch[<span class="hljs-string">&quot;labels&quot;</span>]

        <span class="hljs-comment"># Necessary to pad predictions and labels for being gathered</span>
        predictions = accelerator.pad_across_processes(predictions, dim=<span class="hljs-number">1</span>, pad_index=-<span class="hljs-number">100</span>)
        labels = accelerator.pad_across_processes(labels, dim=<span class="hljs-number">1</span>, pad_index=-<span class="hljs-number">100</span>)

        predictions_gathered = accelerator.gather(predictions)
        labels_gathered = accelerator.gather(labels)

        true_predictions, true_labels = postprocess(predictions_gathered, labels_gathered)
        metric.add_batch(predictions=true_predictions, references=true_labels)

    results = metric.compute()
    <span class="hljs-built_in">print</span>(
        <span class="hljs-string">f&quot;epoch <span class="hljs-subst">{epoch}</span>:&quot;</span>,
        {
            key: results[<span class="hljs-string">f&quot;overall_<span class="hljs-subst">{key}</span>&quot;</span>]
            <span class="hljs-keyword">for</span> key <span class="hljs-keyword">in</span> [<span class="hljs-string">&quot;precision&quot;</span>, <span class="hljs-string">&quot;recall&quot;</span>, <span class="hljs-string">&quot;f1&quot;</span>, <span class="hljs-string">&quot;accuracy&quot;</span>]
        },
    )

    <span class="hljs-comment"># Save and upload</span>
    accelerator.wait_for_everyone()
    unwrapped_model = accelerator.unwrap_model(model)
    unwrapped_model.save_pretrained(output_dir, save_function=accelerator.save)
    <span class="hljs-keyword">if</span> accelerator.is_main_process:
        tokenizer.save_pretrained(output_dir)
        repo.push_to_hub(
            commit_message=<span class="hljs-string">f&quot;Training in progress epoch <span class="hljs-subst">{epoch}</span>&quot;</span>, blocking=<span class="hljs-literal">False</span>
        )`,wrap:!1}}),Dl=new g({props:{code:"YWNjZWxlcmF0b3Iud2FpdF9mb3JfZXZlcnlvbmUoKSUwQXVud3JhcHBlZF9tb2RlbCUyMCUzRCUyMGFjY2VsZXJhdG9yLnVud3JhcF9tb2RlbChtb2RlbCklMEF1bndyYXBwZWRfbW9kZWwuc2F2ZV9wcmV0cmFpbmVkKG91dHB1dF9kaXIlMkMlMjBzYXZlX2Z1bmN0aW9uJTNEYWNjZWxlcmF0b3Iuc2F2ZSk=",highlighted:`accelerator.wait_for_everyone()
unwrapped_model = accelerator.unwrap_model(model)
unwrapped_model.save_pretrained(output_dir, save_function=accelerator.save)`,wrap:!1}}),{c(){w(o.$$.fragment),f=a(),r=d("p"),r.innerHTML=j,x=a(),U=d("p"),U.innerHTML=k,W=a(),w(b.$$.fragment),Z=a(),v=d("p"),v.innerHTML=I,B=a(),w($.$$.fragment),G=a(),O=d("p"),O.innerHTML=vl,ie=a(),w(X.$$.fragment),oe=a(),w(K.$$.fragment),Ie=a(),w(A.$$.fragment),We=a(),w(Q.$$.fragment),D=a(),ee=d("p"),ee.innerHTML=Wl,re=a(),w(le.$$.fragment),Ce=a(),V=d("p"),V.textContent=Bl,pe=a(),te=d("p"),te.textContent=Al,se=a(),w(H.$$.fragment),ce=a(),E=d("p"),E.innerHTML=_e,Be=a(),w(N.$$.fragment),Me=a(),F=d("p"),F.innerHTML=xe,Ae=a(),w(z.$$.fragment),me=a(),he=d("p"),he.innerHTML=ne,ke=a(),w(R.$$.fragment),Gl=a(),de=d("p"),de.textContent=ae,Ge=a(),S=d("p"),S.innerHTML=Ze,$e=a(),w(Y.$$.fragment),Ve=a(),L=d("p"),L.textContent=p,C=a(),w(we.$$.fragment),Ol=a(),ue=d("p"),ue.innerHTML=ct,Re=a(),Vl=d("p"),Vl.textContent=Mt,Ye=a(),w(Xe.$$.fragment),Qe=a(),He=d("p"),He.innerHTML=Rl,ht=a(),w(Ee.$$.fragment),Ne=a(),Fe=d("p"),Fe.innerHTML=Yl,Kl=a(),w(Je.$$.fragment),dt=a(),ze=d("p"),ze.textContent=Xl,yt=a(),w(Se.$$.fragment),Le=a(),Ql=d("p"),Ql.innerHTML=mt,De=a(),w(qe.$$.fragment),Pe=a(),Oe=d("p"),Oe.innerHTML=Hl,wt=a(),w(Ke.$$.fragment),el=a(),w(ll.$$.fragment),tl=a(),El=d("p"),El.innerHTML=ut,ve=a(),w(sl.$$.fragment),nl=a(),al=d("p"),al.innerHTML=Nl,et=a(),w(Te.$$.fragment),Jt=a(),w(il.$$.fragment),ol=a(),Fl=d("p"),Fl.textContent=Tt,rl=a(),w(pl.$$.fragment),cl=a(),zl=d("p"),zl.innerHTML=bt,Ml=a(),w(hl.$$.fragment),dl=a(),yl=d("p"),yl.innerHTML=Sl,ft=a(),w(ml.$$.fragment),wl=a(),ul=d("p"),ul.textContent=Ll,lt=a(),be=d("ul"),be.innerHTML=ms,tt=a(),fe=d("p"),fe.textContent=ws,st=a(),w(je.$$.fragment),nt=a(),Ue=d("p"),Ue.textContent=jt,Jl=a(),w(Dl.$$.fragment),at=a(),ge=d("p"),ge.innerHTML=Ut,Tl=a(),ql=d("p"),ql.innerHTML=gt},l(l){u(o.$$.fragment,l),f=i(l),r=y(l,"P",{"data-svelte-h":!0}),m(r)!=="svelte-1gu7qwi"&&(r.innerHTML=j),x=i(l),U=y(l,"P",{"data-svelte-h":!0}),m(U)!=="svelte-7hlsqs"&&(U.innerHTML=k),W=i(l),u(b.$$.fragment,l),Z=i(l),v=y(l,"P",{"data-svelte-h":!0}),m(v)!=="svelte-13yu0lk"&&(v.innerHTML=I),B=i(l),u($.$$.fragment,l),G=i(l),O=y(l,"P",{"data-svelte-h":!0}),m(O)!=="svelte-matl7x"&&(O.innerHTML=vl),ie=i(l),u(X.$$.fragment,l),oe=i(l),u(K.$$.fragment,l),Ie=i(l),u(A.$$.fragment,l),We=i(l),u(Q.$$.fragment,l),D=i(l),ee=y(l,"P",{"data-svelte-h":!0}),m(ee)!=="svelte-1sk4x6s"&&(ee.innerHTML=Wl),re=i(l),u(le.$$.fragment,l),Ce=i(l),V=y(l,"P",{"data-svelte-h":!0}),m(V)!=="svelte-1ied0vh"&&(V.textContent=Bl),pe=i(l),te=y(l,"P",{"data-svelte-h":!0}),m(te)!=="svelte-648vlf"&&(te.textContent=Al),se=i(l),u(H.$$.fragment,l),ce=i(l),E=y(l,"P",{"data-svelte-h":!0}),m(E)!=="svelte-h1gi55"&&(E.innerHTML=_e),Be=i(l),u(N.$$.fragment,l),Me=i(l),F=y(l,"P",{"data-svelte-h":!0}),m(F)!=="svelte-12dako6"&&(F.innerHTML=xe),Ae=i(l),u(z.$$.fragment,l),me=i(l),he=y(l,"P",{"data-svelte-h":!0}),m(he)!=="svelte-4qeoka"&&(he.innerHTML=ne),ke=i(l),u(R.$$.fragment,l),Gl=i(l),de=y(l,"P",{"data-svelte-h":!0}),m(de)!=="svelte-2l4fow"&&(de.textContent=ae),Ge=i(l),S=y(l,"P",{"data-svelte-h":!0}),m(S)!=="svelte-ujrb5b"&&(S.innerHTML=Ze),$e=i(l),u(Y.$$.fragment,l),Ve=i(l),L=y(l,"P",{"data-svelte-h":!0}),m(L)!=="svelte-mme7gz"&&(L.textContent=p),C=i(l),u(we.$$.fragment,l),Ol=i(l),ue=y(l,"P",{"data-svelte-h":!0}),m(ue)!=="svelte-724xks"&&(ue.innerHTML=ct),Re=i(l),Vl=y(l,"P",{"data-svelte-h":!0}),m(Vl)!=="svelte-1q5ysr9"&&(Vl.textContent=Mt),Ye=i(l),u(Xe.$$.fragment,l),Qe=i(l),He=y(l,"P",{"data-svelte-h":!0}),m(He)!=="svelte-1ckbt7o"&&(He.innerHTML=Rl),ht=i(l),u(Ee.$$.fragment,l),Ne=i(l),Fe=y(l,"P",{"data-svelte-h":!0}),m(Fe)!=="svelte-m7xeud"&&(Fe.innerHTML=Yl),Kl=i(l),u(Je.$$.fragment,l),dt=i(l),ze=y(l,"P",{"data-svelte-h":!0}),m(ze)!=="svelte-fdz4rk"&&(ze.textContent=Xl),yt=i(l),u(Se.$$.fragment,l),Le=i(l),Ql=y(l,"P",{"data-svelte-h":!0}),m(Ql)!=="svelte-172e81w"&&(Ql.innerHTML=mt),De=i(l),u(qe.$$.fragment,l),Pe=i(l),Oe=y(l,"P",{"data-svelte-h":!0}),m(Oe)!=="svelte-1oqv3so"&&(Oe.innerHTML=Hl),wt=i(l),u(Ke.$$.fragment,l),el=i(l),u(ll.$$.fragment,l),tl=i(l),El=y(l,"P",{"data-svelte-h":!0}),m(El)!=="svelte-1409oc7"&&(El.innerHTML=ut),ve=i(l),u(sl.$$.fragment,l),nl=i(l),al=y(l,"P",{"data-svelte-h":!0}),m(al)!=="svelte-8puci4"&&(al.innerHTML=Nl),et=i(l),u(Te.$$.fragment,l),Jt=i(l),u(il.$$.fragment,l),ol=i(l),Fl=y(l,"P",{"data-svelte-h":!0}),m(Fl)!=="svelte-lt5x8r"&&(Fl.textContent=Tt),rl=i(l),u(pl.$$.fragment,l),cl=i(l),zl=y(l,"P",{"data-svelte-h":!0}),m(zl)!=="svelte-1mcbsiy"&&(zl.innerHTML=bt),Ml=i(l),u(hl.$$.fragment,l),dl=i(l),yl=y(l,"P",{"data-svelte-h":!0}),m(yl)!=="svelte-19n1hlu"&&(yl.innerHTML=Sl),ft=i(l),u(ml.$$.fragment,l),wl=i(l),ul=y(l,"P",{"data-svelte-h":!0}),m(ul)!=="svelte-7ueq0n"&&(ul.textContent=Ll),lt=i(l),be=y(l,"UL",{"data-svelte-h":!0}),m(be)!=="svelte-1yegd0"&&(be.innerHTML=ms),tt=i(l),fe=y(l,"P",{"data-svelte-h":!0}),m(fe)!=="svelte-1yi720t"&&(fe.textContent=ws),st=i(l),u(je.$$.fragment,l),nt=i(l),Ue=y(l,"P",{"data-svelte-h":!0}),m(Ue)!=="svelte-10bu99i"&&(Ue.textContent=jt),Jl=i(l),u(Dl.$$.fragment,l),at=i(l),ge=y(l,"P",{"data-svelte-h":!0}),m(ge)!=="svelte-est4dk"&&(ge.innerHTML=Ut),Tl=i(l),ql=y(l,"P",{"data-svelte-h":!0}),m(ql)!=="svelte-1lhqne3"&&(ql.innerHTML=gt)},m(l,c){J(o,l,c),s(l,f,c),s(l,r,c),s(l,x,c),s(l,U,c),s(l,W,c),J(b,l,c),s(l,Z,c),s(l,v,c),s(l,B,c),J($,l,c),s(l,G,c),s(l,O,c),s(l,ie,c),J(X,l,c),s(l,oe,c),J(K,l,c),s(l,Ie,c),J(A,l,c),s(l,We,c),J(Q,l,c),s(l,D,c),s(l,ee,c),s(l,re,c),J(le,l,c),s(l,Ce,c),s(l,V,c),s(l,pe,c),s(l,te,c),s(l,se,c),J(H,l,c),s(l,ce,c),s(l,E,c),s(l,Be,c),J(N,l,c),s(l,Me,c),s(l,F,c),s(l,Ae,c),J(z,l,c),s(l,me,c),s(l,he,c),s(l,ke,c),J(R,l,c),s(l,Gl,c),s(l,de,c),s(l,Ge,c),s(l,S,c),s(l,$e,c),J(Y,l,c),s(l,Ve,c),s(l,L,c),s(l,C,c),J(we,l,c),s(l,Ol,c),s(l,ue,c),s(l,Re,c),s(l,Vl,c),s(l,Ye,c),J(Xe,l,c),s(l,Qe,c),s(l,He,c),s(l,ht,c),J(Ee,l,c),s(l,Ne,c),s(l,Fe,c),s(l,Kl,c),J(Je,l,c),s(l,dt,c),s(l,ze,c),s(l,yt,c),J(Se,l,c),s(l,Le,c),s(l,Ql,c),s(l,De,c),J(qe,l,c),s(l,Pe,c),s(l,Oe,c),s(l,wt,c),J(Ke,l,c),s(l,el,c),J(ll,l,c),s(l,tl,c),s(l,El,c),s(l,ve,c),J(sl,l,c),s(l,nl,c),s(l,al,c),s(l,et,c),J(Te,l,c),s(l,Jt,c),J(il,l,c),s(l,ol,c),s(l,Fl,c),s(l,rl,c),J(pl,l,c),s(l,cl,c),s(l,zl,c),s(l,Ml,c),J(hl,l,c),s(l,dl,c),s(l,yl,c),s(l,ft,c),J(ml,l,c),s(l,wl,c),s(l,ul,c),s(l,lt,c),s(l,be,c),s(l,tt,c),s(l,fe,c),s(l,st,c),J(je,l,c),s(l,nt,c),s(l,Ue,c),s(l,Jl,c),J(Dl,l,c),s(l,at,c),s(l,ge,c),s(l,Tl,c),s(l,ql,c),bl=!0},i(l){bl||(M(o.$$.fragment,l),M(b.$$.fragment,l),M($.$$.fragment,l),M(X.$$.fragment,l),M(K.$$.fragment,l),M(A.$$.fragment,l),M(Q.$$.fragment,l),M(le.$$.fragment,l),M(H.$$.fragment,l),M(N.$$.fragment,l),M(z.$$.fragment,l),M(R.$$.fragment,l),M(Y.$$.fragment,l),M(we.$$.fragment,l),M(Xe.$$.fragment,l),M(Ee.$$.fragment,l),M(Je.$$.fragment,l),M(Se.$$.fragment,l),M(qe.$$.fragment,l),M(Ke.$$.fragment,l),M(ll.$$.fragment,l),M(sl.$$.fragment,l),M(Te.$$.fragment,l),M(il.$$.fragment,l),M(pl.$$.fragment,l),M(hl.$$.fragment,l),M(ml.$$.fragment,l),M(je.$$.fragment,l),M(Dl.$$.fragment,l),bl=!0)},o(l){h(o.$$.fragment,l),h(b.$$.fragment,l),h($.$$.fragment,l),h(X.$$.fragment,l),h(K.$$.fragment,l),h(A.$$.fragment,l),h(Q.$$.fragment,l),h(le.$$.fragment,l),h(H.$$.fragment,l),h(N.$$.fragment,l),h(z.$$.fragment,l),h(R.$$.fragment,l),h(Y.$$.fragment,l),h(we.$$.fragment,l),h(Xe.$$.fragment,l),h(Ee.$$.fragment,l),h(Je.$$.fragment,l),h(Se.$$.fragment,l),h(qe.$$.fragment,l),h(Ke.$$.fragment,l),h(ll.$$.fragment,l),h(sl.$$.fragment,l),h(Te.$$.fragment,l),h(il.$$.fragment,l),h(pl.$$.fragment,l),h(hl.$$.fragment,l),h(ml.$$.fragment,l),h(je.$$.fragment,l),h(Dl.$$.fragment,l),bl=!1},d(l){l&&(t(f),t(r),t(x),t(U),t(W),t(Z),t(v),t(B),t(G),t(O),t(ie),t(oe),t(Ie),t(We),t(D),t(ee),t(re),t(Ce),t(V),t(pe),t(te),t(se),t(ce),t(E),t(Be),t(Me),t(F),t(Ae),t(me),t(he),t(ke),t(Gl),t(de),t(Ge),t(S),t($e),t(Ve),t(L),t(C),t(Ol),t(ue),t(Re),t(Vl),t(Ye),t(Qe),t(He),t(ht),t(Ne),t(Fe),t(Kl),t(dt),t(ze),t(yt),t(Le),t(Ql),t(De),t(Pe),t(Oe),t(wt),t(el),t(tl),t(El),t(ve),t(nl),t(al),t(et),t(Jt),t(ol),t(Fl),t(rl),t(cl),t(zl),t(Ml),t(dl),t(yl),t(ft),t(wl),t(ul),t(lt),t(be),t(tt),t(fe),t(st),t(nt),t(Ue),t(Jl),t(at),t(ge),t(Tl),t(ql)),T(o,l),T(b,l),T($,l),T(X,l),T(K,l),T(A,l),T(Q,l),T(le,l),T(H,l),T(N,l),T(z,l),T(R,l),T(Y,l),T(we,l),T(Xe,l),T(Ee,l),T(Je,l),T(Se,l),T(qe,l),T(Ke,l),T(ll,l),T(sl,l),T(Te,l),T(il,l),T(pl,l),T(hl,l),T(ml,l),T(je,l),T(Dl,l)}}}function ha(_){let o,f="⚠️ If you have a model with the wrong number of labels, you will get an obscure error when calling the <code>Trainer.train()</code> method later on (something like “CUDA error: device-side assert triggered”). This is the number one cause of bugs reported by users for such errors, so make sure you do this check to confirm that you have the expected number of labels.";return{c(){o=d("p"),o.innerHTML=f},l(r){o=y(r,"P",{"data-svelte-h":!0}),m(o)!=="svelte-6bajlm"&&(o.innerHTML=f)},m(r,j){s(r,o,j)},p:Pl,d(r){r&&t(o)}}}function da(_){let o,f="💡 If the output directory you are using already exists, it needs to be a local clone of the repository you want to push to. If it isn’t, you’ll get an error when defining your <code>Trainer</code> and will need to set a new name.";return{c(){o=d("p"),o.innerHTML=f},l(r){o=y(r,"P",{"data-svelte-h":!0}),m(o)!=="svelte-v7zk46"&&(o.innerHTML=f)},m(r,j){s(r,o,j)},p:Pl,d(r){r&&t(o)}}}function ya(_){let o,f='🚨 If you’re training on a TPU, you’ll need to move all the code starting from the cell above into a dedicated training function. See <a href="/course/chapter3">Chapter 3</a> for more details.';return{c(){o=d("p"),o.innerHTML=f},l(r){o=y(r,"P",{"data-svelte-h":!0}),m(o)!=="svelte-1511c7a"&&(o.innerHTML=f)},m(r,j){s(r,o,j)},p:Pl,d(r){r&&t(o)}}}function ma(_){let o,f,r,j,x,U,k,W,b,Z,v,I,B="The first application we’ll explore is token classification. This generic task encompasses any problem that can be formulated as “attributing a label to each token in a sentence,” such as:",$,G,O="<li><strong>Named entity recognition (NER)</strong>: Find the entities (such as persons, locations, or organizations) in a sentence. This can be formulated as attributing a label to each token by having one class per entity and one class for “no entity.”</li> <li><strong>Part-of-speech tagging (POS)</strong>: Mark each word in a sentence as corresponding to a particular part of speech (such as noun, verb, adjective, etc.).</li> <li><strong>Chunking</strong>: Find the tokens that belong to the same entity. This task (which can be combined with POS or NER) can be formulated as attributing one label (usually <code>B-</code>) to any tokens that are at the beginning of a chunk, another label (usually <code>I-</code>) to tokens that are inside a chunk, and a third label (usually <code>O</code>) to tokens that don’t belong to any chunk.</li>",vl,ie,X,oe,K="Of course, there are many other types of token classification problem; those are just a few representative examples. In this section, we will fine-tune a model (BERT) on a NER task, which will then be able to compute predictions like this one:",Ie,A,We,Q,D,ee='<img class="block dark:hidden lg:w-3/5" src="https://huggingface.co/datasets/huggingface-course/documentation-images/resolve/main/en/chapter7/model-eval-bert-finetuned-ner.png" alt="One-hot encoded labels for question answering."/> <img class="hidden dark:block lg:w-3/5" src="https://huggingface.co/datasets/huggingface-course/documentation-images/resolve/main/en/chapter7/model-eval-bert-finetuned-ner-dark.png" alt="One-hot encoded labels for question answering."/>',Wl,re,le='You can find the model we’ll train and upload to the Hub and double-check its predictions <a href="https://huggingface.co/huggingface-course/bert-finetuned-ner?text=My+name+is+Sylvain+and+I+work+at+Hugging+Face+in+Brooklyn" rel="nofollow">here</a>.',Ce,V,Bl,pe,te='First things first, we need a dataset suitable for token classification. In this section we will use the <a href="https://huggingface.co/datasets/conll2003" rel="nofollow">CoNLL-2003 dataset</a>, which contains news stories from Reuters.',Al,se,H,ce,E,_e,Be="To load the CoNLL-2003 dataset, we use the <code>load_dataset()</code> method from the 🤗 Datasets library:",N,Me,F,xe,Ae='This will download and cache the dataset, like we saw in <a href="/course/chapter3">Chapter 3</a> for the GLUE MRPC dataset. Inspecting this object shows us the columns present and the split between the training, validation, and test sets:',z,me,he,ne,ke,R,Gl="In particular, we can see the dataset contains labels for the three tasks we mentioned earlier: NER, POS, and chunking. A big difference from other datasets is that the input texts are not presented as sentences or documents, but lists of words (the last column is called <code>tokens</code>, but it contains words in the sense that these are pre-tokenized inputs that still need to go through the tokenizer for subword tokenization).",de,ae,Ge="Let’s have a look at the first element of the training set:",S,Ze,$e,Y,Ve,L,p="Since we want to perform named entity recognition, we will look at the NER tags:",C,we,Ol,ue,ct,Re,Vl="Those are the labels as integers ready for training, but they’re not necessarily useful when we want to inspect the data. Like for text classification, we can access the correspondence between those integers and the label names by looking at the <code>features</code> attribute of our dataset:",Mt,Ye,Xe,Qe,He,Rl,ht="So this column contains elements that are sequences of <code>ClassLabel</code>s. The type of the elements of the sequence is in the <code>feature</code> attribute of this <code>ner_feature</code>, and we can access the list of names by looking at the <code>names</code> attribute of that <code>feature</code>:",Ee,Ne,Fe,Yl,Kl,Je,dt='We already saw these labels when digging into the <code>token-classification</code> pipeline in <a href="/course/chapter6/3">Chapter 6</a>, but for a quick refresher:',ze,Xl,yt="<li><code>O</code> means the word doesn’t correspond to any entity.</li> <li><code>B-PER</code>/<code>I-PER</code> means the word corresponds to the beginning of/is inside a <em>person</em> entity.</li> <li><code>B-ORG</code>/<code>I-ORG</code> means the word corresponds to the beginning of/is inside an <em>organization</em> entity.</li> <li><code>B-LOC</code>/<code>I-LOC</code> means the word corresponds to the beginning of/is inside a <em>location</em> entity.</li> <li><code>B-MISC</code>/<code>I-MISC</code> means the word corresponds to the beginning of/is inside a <em>miscellaneous</em> entity.</li>",Se,Le,Ql="Now decoding the labels we saw earlier gives us this:",mt,De,qe,Pe,Oe,Hl,wt="And for an example mixing <code>B-</code> and <code>I-</code> labels, here’s what the same code gives us on the element of the training set at index 4:",Ke,el,ll,tl,El="As we can see, entities spanning two words, like “European Union” and “Werner Zwingmann,” are attributed a <code>B-</code> label for the first word and an <code>I-</code> label for the second.",ut,ve,sl,nl,al,Nl,et,Te,Jt='As usual, our texts need to be converted to token IDs before the model can make sense of them. As we saw in <a href="/course/chapter6/">Chapter 6</a>, a big difference in the case of token classification tasks is that we have pre-tokenized inputs. Fortunately, the tokenizer API can deal with that pretty easily; we just need to warn the <code>tokenizer</code> with a special flag.',il,ol,Fl="To begin, let’s create our <code>tokenizer</code> object. As we said before, we will be using a BERT pretrained model, so we’ll start by downloading and caching the associated tokenizer:",Tt,rl,pl,cl,zl='You can replace the <code>model_checkpoint</code> with any other model you prefer from the <a href="https://huggingface.co/models" rel="nofollow">Hub</a>, or with a local folder in which you’ve saved a pretrained model and a tokenizer. The only constraint is that the tokenizer needs to be backed by the 🤗 Tokenizers library, so there’s a “fast” version available. You can see all the architectures that come with a fast version in <a href="https://huggingface.co/transformers/#supported-frameworks" rel="nofollow">this big table</a>, and to check that the <code>tokenizer</code> object you’re using is indeed backed by 🤗 Tokenizers you can look at its <code>is_fast</code> attribute:',bt,Ml,hl,dl,yl,Sl,ft="To tokenize a pre-tokenized input, we can use our <code>tokenizer</code> as usual and just add <code>is_split_into_words=True</code>:",ml,wl,ul,Ll,lt,be,ms="As we can see, the tokenizer added the special tokens used by the model (<code>[CLS]</code> at the beginning and <code>[SEP]</code> at the end) and left most of the words untouched. The word <code>lamb</code>, however, was tokenized into two subwords, <code>la</code> and <code>##mb</code>. This introduces a mismatch between our inputs and the labels: the list of labels has only 9 elements, whereas our input now has 12 tokens. Accounting for the special tokens is easy (we know they are at the beginning and the end), but we also need to make sure we align all the labels with the proper words.",tt,fe,ws='Fortunately, because we’re using a fast tokenizer we have access to the 🤗 Tokenizers superpowers, which means we can easily map each token to its corresponding word (as seen in <a href="/course/chapter6/3">Chapter 6</a>):',st,je,nt,Ue,jt,Jl,Dl="With a tiny bit of work, we can then expand our label list to match the tokens. The first rule we’ll apply is that special tokens get a label of <code>-100</code>. This is because by default <code>-100</code> is an index that is ignored in the loss function we will use (cross entropy). Then, each token gets the same label as the token that started the word it’s inside, since they are part of the same entity. For tokens inside a word but not at the beginning, we replace the <code>B-</code> with <code>I-</code> (since the token does not begin the entity):",at,ge,Ut,Tl,ql="Let’s try it out on our first sentence:",gt,bl,l,c,Js,It,an="As we can see, our function added the <code>-100</code> for the two special tokens at the beginning and the end, and a new <code>0</code> for our word that was split into two tokens.",Ts,it,bs,Ct,on="To preprocess our whole dataset, we need to tokenize all the inputs and apply <code>align_labels_with_tokens()</code> on all the labels. To take advantage of the speed of our fast tokenizer, it’s best to tokenize lots of texts at the same time, so we’ll write a function that processes a list of examples and use the <code>Dataset.map()</code> method with the option <code>batched=True</code>. The only thing that is different from our previous example is that the <code>word_ids()</code> function needs to get the index of the example we want the word IDs of when the inputs to the tokenizer are lists of texts (or in our case, list of lists of words), so we add that too:",fs,kt,js,$t,rn="Note that we haven’t padded our inputs yet; we’ll do that later, when creating the batches with a data collator.",Us,_t,pn="We can now apply all that preprocessing in one go on the other splits of our dataset:",gs,xt,Is,Zt,cn='We’ve done the hardest part! Now that the data has been preprocessed, the actual training will look a lot like what we did in <a href="/course/chapter3">Chapter 3</a>.',Cs,fl,jl,rs,vt,ks,Wt,Mn='We can’t just use a <code>DataCollatorWithPadding</code> like in <a href="/course/chapter3">Chapter 3</a> because that only pads the inputs (input IDs, attention mask, and token type IDs). Here our labels should be padded the exact same way as the inputs so that they stay the same size, using <code>-100</code> as a value so that the corresponding predictions are ignored in the loss computation.',$s,Bt,hn='This is all done by a <a href="https://huggingface.co/transformers/main_classes/data_collator.html#datacollatorfortokenclassification" rel="nofollow"><code>DataCollatorForTokenClassification</code></a>. Like the <code>DataCollatorWithPadding</code>, it takes the <code>tokenizer</code> used to preprocess the inputs:',_s,Ul,gl,ps,At,dn="To test this on a few samples, we can just call it on a list of examples from our tokenized training set:",xs,Gt,Zs,Vt,vs,Rt,yn="Let’s compare this to the labels for the first and second elements in our dataset:",Ws,Yt,Bs,Xt,As,Il,Cl,cs,Ms,Qt,Gs,kl,$l,hs,Ht,Vs,Et,mn="This metric does not behave like the standard accuracy: it will actually take the lists of labels as strings, not integers, so we will need to fully decode the predictions and labels before passing them to the metric. Let’s see how it works. First, we’ll get the labels for our first training example:",Rs,Nt,Ys,Ft,Xs,zt,wn="We can then create fake predictions for those by just changing the value at index 2:",Qs,St,Hs,Lt,un="Note that the metric takes a list of predictions (not just one) and a list of labels. Here’s the output:",Es,Dt,Ns,_l,xl,ds,ys,qt,Fs,Pt,Jn="We’ve already shown you how you can use the model we fine-tuned on the Model Hub with the inference widget. To use it locally in a <code>pipeline</code>, you just have to specify the proper model identifier:",zs,Ot,Ss,Kt,Ls,es,Tn="Great! Our model is working as well as the default one for this pipeline!",Ds,ls,qs,us,Ps;x=new Sn({props:{fw:_[0]}}),k=new ye({props:{title:"Token classification",local:"token-classification",headingTag:"h1"}});const bn=[qn,Dn],ts=[];function fn(e,n){return e[0]==="pt"?0:1}b=fn(_),Z=ts[b]=bn[b](_),ie=new Gn({props:{id:"wVHdVlPScxA"}}),V=new ye({props:{title:"Preparing the data",local:"preparing-the-data",headingTag:"h2"}}),se=new pt({props:{$$slots:{default:[Pn]},$$scope:{ctx:_}}}),ce=new ye({props:{title:"The CoNLL-2003 dataset",local:"the-conll-2003-dataset",headingTag:"h3"}}),Me=new g({props:{code:"ZnJvbSUyMGRhdGFzZXRzJTIwaW1wb3J0JTIwbG9hZF9kYXRhc2V0JTBBJTBBcmF3X2RhdGFzZXRzJTIwJTNEJTIwbG9hZF9kYXRhc2V0KCUyMmNvbmxsMjAwMyUyMik=",highlighted:`<span class="hljs-keyword">from</span> datasets <span class="hljs-keyword">import</span> load_dataset

raw_datasets = load_dataset(<span class="hljs-string">&quot;conll2003&quot;</span>)`,wrap:!1}}),me=new g({props:{code:"cmF3X2RhdGFzZXRz",highlighted:"raw_datasets",wrap:!1}}),ne=new g({props:{code:"RGF0YXNldERpY3QoJTdCJTBBJTIwJTIwJTIwJTIwdHJhaW4lM0ElMjBEYXRhc2V0KCU3QiUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMGZlYXR1cmVzJTNBJTIwJTVCJ2NodW5rX3RhZ3MnJTJDJTIwJ2lkJyUyQyUyMCduZXJfdGFncyclMkMlMjAncG9zX3RhZ3MnJTJDJTIwJ3Rva2VucyclNUQlMkMlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBudW1fcm93cyUzQSUyMDE0MDQxJTBBJTIwJTIwJTIwJTIwJTdEKSUwQSUyMCUyMCUyMCUyMHZhbGlkYXRpb24lM0ElMjBEYXRhc2V0KCU3QiUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMGZlYXR1cmVzJTNBJTIwJTVCJ2NodW5rX3RhZ3MnJTJDJTIwJ2lkJyUyQyUyMCduZXJfdGFncyclMkMlMjAncG9zX3RhZ3MnJTJDJTIwJ3Rva2VucyclNUQlMkMlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBudW1fcm93cyUzQSUyMDMyNTAlMEElMjAlMjAlMjAlMjAlN0QpJTBBJTIwJTIwJTIwJTIwdGVzdCUzQSUyMERhdGFzZXQoJTdCJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwZmVhdHVyZXMlM0ElMjAlNUInY2h1bmtfdGFncyclMkMlMjAnaWQnJTJDJTIwJ25lcl90YWdzJyUyQyUyMCdwb3NfdGFncyclMkMlMjAndG9rZW5zJyU1RCUyQyUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMG51bV9yb3dzJTNBJTIwMzQ1MyUwQSUyMCUyMCUyMCUyMCU3RCklMEElN0Qp",highlighted:`DatasetDict({
    train: Dataset({
        features: [<span class="hljs-string">&#x27;chunk_tags&#x27;</span>, <span class="hljs-string">&#x27;id&#x27;</span>, <span class="hljs-string">&#x27;ner_tags&#x27;</span>, <span class="hljs-string">&#x27;pos_tags&#x27;</span>, <span class="hljs-string">&#x27;tokens&#x27;</span>],
        num_rows: <span class="hljs-number">14041</span>
    })
    validation: Dataset({
        features: [<span class="hljs-string">&#x27;chunk_tags&#x27;</span>, <span class="hljs-string">&#x27;id&#x27;</span>, <span class="hljs-string">&#x27;ner_tags&#x27;</span>, <span class="hljs-string">&#x27;pos_tags&#x27;</span>, <span class="hljs-string">&#x27;tokens&#x27;</span>],
        num_rows: <span class="hljs-number">3250</span>
    })
    test: Dataset({
        features: [<span class="hljs-string">&#x27;chunk_tags&#x27;</span>, <span class="hljs-string">&#x27;id&#x27;</span>, <span class="hljs-string">&#x27;ner_tags&#x27;</span>, <span class="hljs-string">&#x27;pos_tags&#x27;</span>, <span class="hljs-string">&#x27;tokens&#x27;</span>],
        num_rows: <span class="hljs-number">3453</span>
    })
})`,wrap:!1}}),Ze=new g({props:{code:"cmF3X2RhdGFzZXRzJTVCJTIydHJhaW4lMjIlNUQlNUIwJTVEJTVCJTIydG9rZW5zJTIyJTVE",highlighted:'raw_datasets[<span class="hljs-string">&quot;train&quot;</span>][<span class="hljs-number">0</span>][<span class="hljs-string">&quot;tokens&quot;</span>]',wrap:!1}}),Y=new g({props:{code:"JTVCJ0VVJyUyQyUyMCdyZWplY3RzJyUyQyUyMCdHZXJtYW4nJTJDJTIwJ2NhbGwnJTJDJTIwJ3RvJyUyQyUyMCdib3ljb3R0JyUyQyUyMCdCcml0aXNoJyUyQyUyMCdsYW1iJyUyQyUyMCcuJyU1RA==",highlighted:'[<span class="hljs-string">&#x27;EU&#x27;</span>, <span class="hljs-string">&#x27;rejects&#x27;</span>, <span class="hljs-string">&#x27;German&#x27;</span>, <span class="hljs-string">&#x27;call&#x27;</span>, <span class="hljs-string">&#x27;to&#x27;</span>, <span class="hljs-string">&#x27;boycott&#x27;</span>, <span class="hljs-string">&#x27;British&#x27;</span>, <span class="hljs-string">&#x27;lamb&#x27;</span>, <span class="hljs-string">&#x27;.&#x27;</span>]',wrap:!1}}),we=new g({props:{code:"cmF3X2RhdGFzZXRzJTVCJTIydHJhaW4lMjIlNUQlNUIwJTVEJTVCJTIybmVyX3RhZ3MlMjIlNUQ=",highlighted:'raw_datasets[<span class="hljs-string">&quot;train&quot;</span>][<span class="hljs-number">0</span>][<span class="hljs-string">&quot;ner_tags&quot;</span>]',wrap:!1}}),ue=new g({props:{code:"JTVCMyUyQyUyMDAlMkMlMjA3JTJDJTIwMCUyQyUyMDAlMkMlMjAwJTJDJTIwNyUyQyUyMDAlMkMlMjAwJTVE",highlighted:'[<span class="hljs-number">3</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">7</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>]',wrap:!1}}),Ye=new g({props:{code:"bmVyX2ZlYXR1cmUlMjAlM0QlMjByYXdfZGF0YXNldHMlNUIlMjJ0cmFpbiUyMiU1RC5mZWF0dXJlcyU1QiUyMm5lcl90YWdzJTIyJTVEJTBBbmVyX2ZlYXR1cmU=",highlighted:`ner_feature = raw_datasets[<span class="hljs-string">&quot;train&quot;</span>].features[<span class="hljs-string">&quot;ner_tags&quot;</span>]
ner_feature`,wrap:!1}}),Qe=new g({props:{code:"U2VxdWVuY2UoZmVhdHVyZSUzRENsYXNzTGFiZWwobnVtX2NsYXNzZXMlM0Q5JTJDJTIwbmFtZXMlM0QlNUInTyclMkMlMjAnQi1QRVInJTJDJTIwJ0ktUEVSJyUyQyUyMCdCLU9SRyclMkMlMjAnSS1PUkcnJTJDJTIwJ0ItTE9DJyUyQyUyMCdJLUxPQyclMkMlMjAnQi1NSVNDJyUyQyUyMCdJLU1JU0MnJTVEJTJDJTIwbmFtZXNfZmlsZSUzRE5vbmUlMkMlMjBpZCUzRE5vbmUpJTJDJTIwbGVuZ3RoJTNELTElMkMlMjBpZCUzRE5vbmUp",highlighted:'<span class="hljs-type">Sequence</span>(feature=ClassLabel(num_classes=<span class="hljs-number">9</span>, names=[<span class="hljs-string">&#x27;O&#x27;</span>, <span class="hljs-string">&#x27;B-PER&#x27;</span>, <span class="hljs-string">&#x27;I-PER&#x27;</span>, <span class="hljs-string">&#x27;B-ORG&#x27;</span>, <span class="hljs-string">&#x27;I-ORG&#x27;</span>, <span class="hljs-string">&#x27;B-LOC&#x27;</span>, <span class="hljs-string">&#x27;I-LOC&#x27;</span>, <span class="hljs-string">&#x27;B-MISC&#x27;</span>, <span class="hljs-string">&#x27;I-MISC&#x27;</span>], names_file=<span class="hljs-literal">None</span>, <span class="hljs-built_in">id</span>=<span class="hljs-literal">None</span>), length=-<span class="hljs-number">1</span>, <span class="hljs-built_in">id</span>=<span class="hljs-literal">None</span>)',wrap:!1}}),Ne=new g({props:{code:"bGFiZWxfbmFtZXMlMjAlM0QlMjBuZXJfZmVhdHVyZS5mZWF0dXJlLm5hbWVzJTBBbGFiZWxfbmFtZXM=",highlighted:`label_names = ner_feature.feature.names
label_names`,wrap:!1}}),Yl=new g({props:{code:"JTVCJ08nJTJDJTIwJ0ItUEVSJyUyQyUyMCdJLVBFUiclMkMlMjAnQi1PUkcnJTJDJTIwJ0ktT1JHJyUyQyUyMCdCLUxPQyclMkMlMjAnSS1MT0MnJTJDJTIwJ0ItTUlTQyclMkMlMjAnSS1NSVNDJyU1RA==",highlighted:'[<span class="hljs-string">&#x27;O&#x27;</span>, <span class="hljs-string">&#x27;B-PER&#x27;</span>, <span class="hljs-string">&#x27;I-PER&#x27;</span>, <span class="hljs-string">&#x27;B-ORG&#x27;</span>, <span class="hljs-string">&#x27;I-ORG&#x27;</span>, <span class="hljs-string">&#x27;B-LOC&#x27;</span>, <span class="hljs-string">&#x27;I-LOC&#x27;</span>, <span class="hljs-string">&#x27;B-MISC&#x27;</span>, <span class="hljs-string">&#x27;I-MISC&#x27;</span>]',wrap:!1}}),De=new g({props:{code:"d29yZHMlMjAlM0QlMjByYXdfZGF0YXNldHMlNUIlMjJ0cmFpbiUyMiU1RCU1QjAlNUQlNUIlMjJ0b2tlbnMlMjIlNUQlMEFsYWJlbHMlMjAlM0QlMjByYXdfZGF0YXNldHMlNUIlMjJ0cmFpbiUyMiU1RCU1QjAlNUQlNUIlMjJuZXJfdGFncyUyMiU1RCUwQWxpbmUxJTIwJTNEJTIwJTIyJTIyJTBBbGluZTIlMjAlM0QlMjAlMjIlMjIlMEFmb3IlMjB3b3JkJTJDJTIwbGFiZWwlMjBpbiUyMHppcCh3b3JkcyUyQyUyMGxhYmVscyklM0ElMEElMjAlMjAlMjAlMjBmdWxsX2xhYmVsJTIwJTNEJTIwbGFiZWxfbmFtZXMlNUJsYWJlbCU1RCUwQSUyMCUyMCUyMCUyMG1heF9sZW5ndGglMjAlM0QlMjBtYXgobGVuKHdvcmQpJTJDJTIwbGVuKGZ1bGxfbGFiZWwpKSUwQSUyMCUyMCUyMCUyMGxpbmUxJTIwJTJCJTNEJTIwd29yZCUyMCUyQiUyMCUyMiUyMCUyMiUyMColMjAobWF4X2xlbmd0aCUyMC0lMjBsZW4od29yZCklMjAlMkIlMjAxKSUwQSUyMCUyMCUyMCUyMGxpbmUyJTIwJTJCJTNEJTIwZnVsbF9sYWJlbCUyMCUyQiUyMCUyMiUyMCUyMiUyMColMjAobWF4X2xlbmd0aCUyMC0lMjBsZW4oZnVsbF9sYWJlbCklMjAlMkIlMjAxKSUwQSUwQXByaW50KGxpbmUxKSUwQXByaW50KGxpbmUyKQ==",highlighted:`words = raw_datasets[<span class="hljs-string">&quot;train&quot;</span>][<span class="hljs-number">0</span>][<span class="hljs-string">&quot;tokens&quot;</span>]
labels = raw_datasets[<span class="hljs-string">&quot;train&quot;</span>][<span class="hljs-number">0</span>][<span class="hljs-string">&quot;ner_tags&quot;</span>]
line1 = <span class="hljs-string">&quot;&quot;</span>
line2 = <span class="hljs-string">&quot;&quot;</span>
<span class="hljs-keyword">for</span> word, label <span class="hljs-keyword">in</span> <span class="hljs-built_in">zip</span>(words, labels):
    full_label = label_names[label]
    max_length = <span class="hljs-built_in">max</span>(<span class="hljs-built_in">len</span>(word), <span class="hljs-built_in">len</span>(full_label))
    line1 += word + <span class="hljs-string">&quot; &quot;</span> * (max_length - <span class="hljs-built_in">len</span>(word) + <span class="hljs-number">1</span>)
    line2 += full_label + <span class="hljs-string">&quot; &quot;</span> * (max_length - <span class="hljs-built_in">len</span>(full_label) + <span class="hljs-number">1</span>)

<span class="hljs-built_in">print</span>(line1)
<span class="hljs-built_in">print</span>(line2)`,wrap:!1}}),Pe=new g({props:{code:"J0VVJTIwJTIwJTIwJTIwcmVqZWN0cyUyMEdlcm1hbiUyMGNhbGwlMjB0byUyMGJveWNvdHQlMjBCcml0aXNoJTIwbGFtYiUyMC4nJTBBJ0ItT1JHJTIwTyUyMCUyMCUyMCUyMCUyMCUyMCUyMEItTUlTQyUyME8lMjAlMjAlMjAlMjBPJTIwJTIwTyUyMCUyMCUyMCUyMCUyMCUyMCUyMEItTUlTQyUyMCUyME8lMjAlMjAlMjAlMjBPJw==",highlighted:`<span class="hljs-string">&#x27;EU    rejects German call to boycott British lamb .&#x27;</span>
<span class="hljs-string">&#x27;B-ORG O       B-MISC O    O  O       B-MISC  O    O&#x27;</span>`,wrap:!1}}),el=new g({props:{code:"J0dlcm1hbnklMjAlNUMncyUyMHJlcHJlc2VudGF0aXZlJTIwdG8lMjB0aGUlMjBFdXJvcGVhbiUyMFVuaW9uJTIwJTVDJ3MlMjB2ZXRlcmluYXJ5JTIwY29tbWl0dGVlJTIwV2VybmVyJTIwWndpbmdtYW5uJTIwc2FpZCUyMG9uJTIwV2VkbmVzZGF5JTIwY29uc3VtZXJzJTIwc2hvdWxkJTIwYnV5JTIwc2hlZXBtZWF0JTIwZnJvbSUyMGNvdW50cmllcyUyMG90aGVyJTIwdGhhbiUyMEJyaXRhaW4lMjB1bnRpbCUyMHRoZSUyMHNjaWVudGlmaWMlMjBhZHZpY2UlMjB3YXMlMjBjbGVhcmVyJTIwLiclMEEnQi1MT0MlMjAlMjAlMjBPJTIwJTIwTyUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyME8lMjAlMjBPJTIwJTIwJTIwQi1PUkclMjAlMjAlMjAlMjBJLU9SRyUyME8lMjAlMjBPJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwTyUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMEItUEVSJTIwJTIwSS1QRVIlMjAlMjAlMjAlMjAlMjBPJTIwJTIwJTIwJTIwTyUyMCUyME8lMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBPJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwTyUyMCUyMCUyMCUyMCUyMCUyME8lMjAlMjAlMjBPJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwTyUyMCUyMCUyMCUyME8lMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBPJTIwJTIwJTIwJTIwJTIwTyUyMCUyMCUyMCUyMEItTE9DJTIwJTIwJTIwTyUyMCUyMCUyMCUyMCUyME8lMjAlMjAlMjBPJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwTyUyMCUyMCUyMCUyMCUyMCUyME8lMjAlMjAlMjBPJTIwJTIwJTIwJTIwJTIwJTIwJTIwTyc=",highlighted:`<span class="hljs-string">&#x27;Germany \\&#x27;s representative to the European Union \\&#x27;s veterinary committee Werner Zwingmann said on Wednesday consumers should buy sheepmeat from countries other than Britain until the scientific advice was clearer .&#x27;</span>
<span class="hljs-string">&#x27;B-LOC   O  O              O  O   B-ORG    I-ORG O  O          O         B-PER  I-PER     O    O  O         O         O      O   O         O    O         O     O    B-LOC   O     O   O          O      O   O       O&#x27;</span>`,wrap:!1}}),ve=new pt({props:{$$slots:{default:[On]},$$scope:{ctx:_}}}),nl=new ye({props:{title:"Processing the data",local:"processing-the-data",headingTag:"h3"}}),Nl=new Gn({props:{id:"iY2AZYdZAr0"}}),rl=new g({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9Ub2tlbml6ZXIlMEElMEFtb2RlbF9jaGVja3BvaW50JTIwJTNEJTIwJTIyYmVydC1iYXNlLWNhc2VkJTIyJTBBdG9rZW5pemVyJTIwJTNEJTIwQXV0b1Rva2VuaXplci5mcm9tX3ByZXRyYWluZWQobW9kZWxfY2hlY2twb2ludCk=",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoTokenizer

model_checkpoint = <span class="hljs-string">&quot;bert-base-cased&quot;</span>
tokenizer = AutoTokenizer.from_pretrained(model_checkpoint)`,wrap:!1}}),Ml=new g({props:{code:"dG9rZW5pemVyLmlzX2Zhc3Q=",highlighted:"tokenizer.is_fast",wrap:!1}}),dl=new g({props:{code:"VHJ1ZQ==",highlighted:'<span class="hljs-literal">True</span>',wrap:!1}}),wl=new g({props:{code:"aW5wdXRzJTIwJTNEJTIwdG9rZW5pemVyKHJhd19kYXRhc2V0cyU1QiUyMnRyYWluJTIyJTVEJTVCMCU1RCU1QiUyMnRva2VucyUyMiU1RCUyQyUyMGlzX3NwbGl0X2ludG9fd29yZHMlM0RUcnVlKSUwQWlucHV0cy50b2tlbnMoKQ==",highlighted:`inputs = tokenizer(raw_datasets[<span class="hljs-string">&quot;train&quot;</span>][<span class="hljs-number">0</span>][<span class="hljs-string">&quot;tokens&quot;</span>], is_split_into_words=<span class="hljs-literal">True</span>)
inputs.tokens()`,wrap:!1}}),Ll=new g({props:{code:"JTVCJyU1QkNMUyU1RCclMkMlMjAnRVUnJTJDJTIwJ3JlamVjdHMnJTJDJTIwJ0dlcm1hbiclMkMlMjAnY2FsbCclMkMlMjAndG8nJTJDJTIwJ2JveWNvdHQnJTJDJTIwJ0JyaXRpc2gnJTJDJTIwJ2xhJyUyQyUyMCclMjMlMjNtYiclMkMlMjAnLiclMkMlMjAnJTVCU0VQJTVEJyU1RA==",highlighted:'[<span class="hljs-string">&#x27;[CLS]&#x27;</span>, <span class="hljs-string">&#x27;EU&#x27;</span>, <span class="hljs-string">&#x27;rejects&#x27;</span>, <span class="hljs-string">&#x27;German&#x27;</span>, <span class="hljs-string">&#x27;call&#x27;</span>, <span class="hljs-string">&#x27;to&#x27;</span>, <span class="hljs-string">&#x27;boycott&#x27;</span>, <span class="hljs-string">&#x27;British&#x27;</span>, <span class="hljs-string">&#x27;la&#x27;</span>, <span class="hljs-string">&#x27;##mb&#x27;</span>, <span class="hljs-string">&#x27;.&#x27;</span>, <span class="hljs-string">&#x27;[SEP]&#x27;</span>]',wrap:!1}}),je=new g({props:{code:"aW5wdXRzLndvcmRfaWRzKCk=",highlighted:"inputs.word_ids()",wrap:!1}}),Ue=new g({props:{code:"JTVCTm9uZSUyQyUyMDAlMkMlMjAxJTJDJTIwMiUyQyUyMDMlMkMlMjA0JTJDJTIwNSUyQyUyMDYlMkMlMjA3JTJDJTIwNyUyQyUyMDglMkMlMjBOb25lJTVE",highlighted:'[<span class="hljs-literal">None</span>, <span class="hljs-number">0</span>, <span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">4</span>, <span class="hljs-number">5</span>, <span class="hljs-number">6</span>, <span class="hljs-number">7</span>, <span class="hljs-number">7</span>, <span class="hljs-number">8</span>, <span class="hljs-literal">None</span>]',wrap:!1}}),ge=new g({props:{code:"ZGVmJTIwYWxpZ25fbGFiZWxzX3dpdGhfdG9rZW5zKGxhYmVscyUyQyUyMHdvcmRfaWRzKSUzQSUwQSUyMCUyMCUyMCUyMG5ld19sYWJlbHMlMjAlM0QlMjAlNUIlNUQlMEElMjAlMjAlMjAlMjBjdXJyZW50X3dvcmQlMjAlM0QlMjBOb25lJTBBJTIwJTIwJTIwJTIwZm9yJTIwd29yZF9pZCUyMGluJTIwd29yZF9pZHMlM0ElMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBpZiUyMHdvcmRfaWQlMjAhJTNEJTIwY3VycmVudF93b3JkJTNBJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIzJTIwU3RhcnQlMjBvZiUyMGElMjBuZXclMjB3b3JkISUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMGN1cnJlbnRfd29yZCUyMCUzRCUyMHdvcmRfaWQlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBsYWJlbCUyMCUzRCUyMC0xMDAlMjBpZiUyMHdvcmRfaWQlMjBpcyUyME5vbmUlMjBlbHNlJTIwbGFiZWxzJTVCd29yZF9pZCU1RCUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMG5ld19sYWJlbHMuYXBwZW5kKGxhYmVsKSUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMGVsaWYlMjB3b3JkX2lkJTIwaXMlMjBOb25lJTNBJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIzJTIwU3BlY2lhbCUyMHRva2VuJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwbmV3X2xhYmVscy5hcHBlbmQoLTEwMCklMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBlbHNlJTNBJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIzJTIwU2FtZSUyMHdvcmQlMjBhcyUyMHByZXZpb3VzJTIwdG9rZW4lMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBsYWJlbCUyMCUzRCUyMGxhYmVscyU1QndvcmRfaWQlNUQlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjMlMjBJZiUyMHRoZSUyMGxhYmVsJTIwaXMlMjBCLVhYWCUyMHdlJTIwY2hhbmdlJTIwaXQlMjB0byUyMEktWFhYJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwaWYlMjBsYWJlbCUyMCUyNSUyMDIlMjAlM0QlM0QlMjAxJTNBJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwbGFiZWwlMjAlMkIlM0QlMjAxJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwbmV3X2xhYmVscy5hcHBlbmQobGFiZWwpJTBBJTBBJTIwJTIwJTIwJTIwcmV0dXJuJTIwbmV3X2xhYmVscw==",highlighted:`<span class="hljs-keyword">def</span> <span class="hljs-title function_">align_labels_with_tokens</span>(<span class="hljs-params">labels, word_ids</span>):
    new_labels = []
    current_word = <span class="hljs-literal">None</span>
    <span class="hljs-keyword">for</span> word_id <span class="hljs-keyword">in</span> word_ids:
        <span class="hljs-keyword">if</span> word_id != current_word:
            <span class="hljs-comment"># Start of a new word!</span>
            current_word = word_id
            label = -<span class="hljs-number">100</span> <span class="hljs-keyword">if</span> word_id <span class="hljs-keyword">is</span> <span class="hljs-literal">None</span> <span class="hljs-keyword">else</span> labels[word_id]
            new_labels.append(label)
        <span class="hljs-keyword">elif</span> word_id <span class="hljs-keyword">is</span> <span class="hljs-literal">None</span>:
            <span class="hljs-comment"># Special token</span>
            new_labels.append(-<span class="hljs-number">100</span>)
        <span class="hljs-keyword">else</span>:
            <span class="hljs-comment"># Same word as previous token</span>
            label = labels[word_id]
            <span class="hljs-comment"># If the label is B-XXX we change it to I-XXX</span>
            <span class="hljs-keyword">if</span> label % <span class="hljs-number">2</span> == <span class="hljs-number">1</span>:
                label += <span class="hljs-number">1</span>
            new_labels.append(label)

    <span class="hljs-keyword">return</span> new_labels`,wrap:!1}}),bl=new g({props:{code:"bGFiZWxzJTIwJTNEJTIwcmF3X2RhdGFzZXRzJTVCJTIydHJhaW4lMjIlNUQlNUIwJTVEJTVCJTIybmVyX3RhZ3MlMjIlNUQlMEF3b3JkX2lkcyUyMCUzRCUyMGlucHV0cy53b3JkX2lkcygpJTBBcHJpbnQobGFiZWxzKSUwQXByaW50KGFsaWduX2xhYmVsc193aXRoX3Rva2VucyhsYWJlbHMlMkMlMjB3b3JkX2lkcykp",highlighted:`labels = raw_datasets[<span class="hljs-string">&quot;train&quot;</span>][<span class="hljs-number">0</span>][<span class="hljs-string">&quot;ner_tags&quot;</span>]
word_ids = inputs.word_ids()
<span class="hljs-built_in">print</span>(labels)
<span class="hljs-built_in">print</span>(align_labels_with_tokens(labels, word_ids))`,wrap:!1}}),c=new g({props:{code:"JTVCMyUyQyUyMDAlMkMlMjA3JTJDJTIwMCUyQyUyMDAlMkMlMjAwJTJDJTIwNyUyQyUyMDAlMkMlMjAwJTVEJTBBJTVCLTEwMCUyQyUyMDMlMkMlMjAwJTJDJTIwNyUyQyUyMDAlMkMlMjAwJTJDJTIwMCUyQyUyMDclMkMlMjAwJTJDJTIwMCUyQyUyMDAlMkMlMjAtMTAwJTVE",highlighted:`[<span class="hljs-number">3</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">7</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>]
[-<span class="hljs-number">100</span>, <span class="hljs-number">3</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">7</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, -<span class="hljs-number">100</span>]`,wrap:!1}}),it=new pt({props:{$$slots:{default:[Kn]},$$scope:{ctx:_}}}),kt=new g({props:{code:"ZGVmJTIwdG9rZW5pemVfYW5kX2FsaWduX2xhYmVscyhleGFtcGxlcyklM0ElMEElMjAlMjAlMjAlMjB0b2tlbml6ZWRfaW5wdXRzJTIwJTNEJTIwdG9rZW5pemVyKCUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMGV4YW1wbGVzJTVCJTIydG9rZW5zJTIyJTVEJTJDJTIwdHJ1bmNhdGlvbiUzRFRydWUlMkMlMjBpc19zcGxpdF9pbnRvX3dvcmRzJTNEVHJ1ZSUwQSUyMCUyMCUyMCUyMCklMEElMjAlMjAlMjAlMjBhbGxfbGFiZWxzJTIwJTNEJTIwZXhhbXBsZXMlNUIlMjJuZXJfdGFncyUyMiU1RCUwQSUyMCUyMCUyMCUyMG5ld19sYWJlbHMlMjAlM0QlMjAlNUIlNUQlMEElMjAlMjAlMjAlMjBmb3IlMjBpJTJDJTIwbGFiZWxzJTIwaW4lMjBlbnVtZXJhdGUoYWxsX2xhYmVscyklM0ElMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjB3b3JkX2lkcyUyMCUzRCUyMHRva2VuaXplZF9pbnB1dHMud29yZF9pZHMoaSklMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBuZXdfbGFiZWxzLmFwcGVuZChhbGlnbl9sYWJlbHNfd2l0aF90b2tlbnMobGFiZWxzJTJDJTIwd29yZF9pZHMpKSUwQSUwQSUyMCUyMCUyMCUyMHRva2VuaXplZF9pbnB1dHMlNUIlMjJsYWJlbHMlMjIlNUQlMjAlM0QlMjBuZXdfbGFiZWxzJTBBJTIwJTIwJTIwJTIwcmV0dXJuJTIwdG9rZW5pemVkX2lucHV0cw==",highlighted:`<span class="hljs-keyword">def</span> <span class="hljs-title function_">tokenize_and_align_labels</span>(<span class="hljs-params">examples</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>
    )
    all_labels = examples[<span class="hljs-string">&quot;ner_tags&quot;</span>]
    new_labels = []
    <span class="hljs-keyword">for</span> i, labels <span class="hljs-keyword">in</span> <span class="hljs-built_in">enumerate</span>(all_labels):
        word_ids = tokenized_inputs.word_ids(i)
        new_labels.append(align_labels_with_tokens(labels, word_ids))

    tokenized_inputs[<span class="hljs-string">&quot;labels&quot;</span>] = new_labels
    <span class="hljs-keyword">return</span> tokenized_inputs`,wrap:!1}}),xt=new g({props:{code:"dG9rZW5pemVkX2RhdGFzZXRzJTIwJTNEJTIwcmF3X2RhdGFzZXRzLm1hcCglMEElMjAlMjAlMjAlMjB0b2tlbml6ZV9hbmRfYWxpZ25fbGFiZWxzJTJDJTBBJTIwJTIwJTIwJTIwYmF0Y2hlZCUzRFRydWUlMkMlMEElMjAlMjAlMjAlMjByZW1vdmVfY29sdW1ucyUzRHJhd19kYXRhc2V0cyU1QiUyMnRyYWluJTIyJTVELmNvbHVtbl9uYW1lcyUyQyUwQSk=",highlighted:`tokenized_datasets = raw_datasets.<span class="hljs-built_in">map</span>(
    tokenize_and_align_labels,
    batched=<span class="hljs-literal">True</span>,
    remove_columns=raw_datasets[<span class="hljs-string">&quot;train&quot;</span>].column_names,
)`,wrap:!1}});const jn=[la,ea],ss=[];function Un(e,n){return e[0]==="pt"?0:1}fl=Un(_),jl=ss[fl]=jn[fl](_),vt=new ye({props:{title:"Data collation",local:"data-collation",headingTag:"h3"}});const gn=[sa,ta],ns=[];function In(e,n){return e[0]==="pt"?0:1}Ul=In(_),gl=ns[Ul]=gn[Ul](_),Gt=new g({props:{code:"YmF0Y2glMjAlM0QlMjBkYXRhX2NvbGxhdG9yKCU1QnRva2VuaXplZF9kYXRhc2V0cyU1QiUyMnRyYWluJTIyJTVEJTVCaSU1RCUyMGZvciUyMGklMjBpbiUyMHJhbmdlKDIpJTVEKSUwQWJhdGNoJTVCJTIybGFiZWxzJTIyJTVE",highlighted:`batch = data_collator([tokenized_datasets[<span class="hljs-string">&quot;train&quot;</span>][i] <span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> <span class="hljs-built_in">range</span>(<span class="hljs-number">2</span>)])
batch[<span class="hljs-string">&quot;labels&quot;</span>]`,wrap:!1}}),Vt=new g({props:{code:"dGVuc29yKCU1QiU1Qi0xMDAlMkMlMjAlMjAlMjAlMjAzJTJDJTIwJTIwJTIwJTIwMCUyQyUyMCUyMCUyMCUyMDclMkMlMjAlMjAlMjAlMjAwJTJDJTIwJTIwJTIwJTIwMCUyQyUyMCUyMCUyMCUyMDAlMkMlMjAlMjAlMjAlMjA3JTJDJTIwJTIwJTIwJTIwMCUyQyUyMCUyMCUyMCUyMDAlMkMlMjAlMjAlMjAlMjAwJTJDJTIwLTEwMCU1RCUyQyUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCU1Qi0xMDAlMkMlMjAlMjAlMjAlMjAxJTJDJTIwJTIwJTIwJTIwMiUyQyUyMC0xMDAlMkMlMjAtMTAwJTJDJTIwLTEwMCUyQyUyMC0xMDAlMkMlMjAtMTAwJTJDJTIwLTEwMCUyQyUyMC0xMDAlMkMlMjAtMTAwJTJDJTIwLTEwMCU1RCU1RCk=",highlighted:`tensor([[-<span class="hljs-number">100</span>,    <span class="hljs-number">3</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">7</span>,    <span class="hljs-number">0</span>,    <span class="hljs-number">0</span>,    <span class="hljs-number">0</span>, -<span class="hljs-number">100</span>],
        [-<span class="hljs-number">100</span>,    <span class="hljs-number">1</span>,    <span class="hljs-number">2</span>, -<span class="hljs-number">100</span>, -<span class="hljs-number">100</span>, -<span class="hljs-number">100</span>, -<span class="hljs-number">100</span>, -<span class="hljs-number">100</span>, -<span class="hljs-number">100</span>, -<span class="hljs-number">100</span>, -<span class="hljs-number">100</span>, -<span class="hljs-number">100</span>]])`,wrap:!1}}),Yt=new g({props:{code:"Zm9yJTIwaSUyMGluJTIwcmFuZ2UoMiklM0ElMEElMjAlMjAlMjAlMjBwcmludCh0b2tlbml6ZWRfZGF0YXNldHMlNUIlMjJ0cmFpbiUyMiU1RCU1QmklNUQlNUIlMjJsYWJlbHMlMjIlNUQp",highlighted:`<span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> <span class="hljs-built_in">range</span>(<span class="hljs-number">2</span>):
    <span class="hljs-built_in">print</span>(tokenized_datasets[<span class="hljs-string">&quot;train&quot;</span>][i][<span class="hljs-string">&quot;labels&quot;</span>])`,wrap:!1}}),Xt=new g({props:{code:"JTVCLTEwMCUyQyUyMDMlMkMlMjAwJTJDJTIwNyUyQyUyMDAlMkMlMjAwJTJDJTIwMCUyQyUyMDclMkMlMjAwJTJDJTIwMCUyQyUyMDAlMkMlMjAtMTAwJTVEJTBBJTVCLTEwMCUyQyUyMDElMkMlMjAyJTJDJTIwLTEwMCU1RA==",highlighted:`[-<span class="hljs-number">100</span>, <span class="hljs-number">3</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">7</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, -<span class="hljs-number">100</span>]
[-<span class="hljs-number">100</span>, <span class="hljs-number">1</span>, <span class="hljs-number">2</span>, -<span class="hljs-number">100</span>]`,wrap:!1}});const Cn=[aa,na],as=[];function kn(e,n){return e[0]==="pt"?0:1}Il=kn(_),Cl=as[Il]=Cn[Il](_);let q=_[0]==="tf"&&Vn(_);Qt=new ye({props:{title:"Metrics",local:"metrics",headingTag:"h3"}});const $n=[pa,ra],is=[];function _n(e,n){return e[0]==="pt"?0:1}kl=_n(_),$l=is[kl]=$n[kl](_),Ht=new g({props:{code:"aW1wb3J0JTIwZXZhbHVhdGUlMEElMEFtZXRyaWMlMjAlM0QlMjBldmFsdWF0ZS5sb2FkKCUyMnNlcWV2YWwlMjIp",highlighted:`<span class="hljs-keyword">import</span> evaluate

metric = evaluate.load(<span class="hljs-string">&quot;seqeval&quot;</span>)`,wrap:!1}}),Nt=new g({props:{code:"bGFiZWxzJTIwJTNEJTIwcmF3X2RhdGFzZXRzJTVCJTIydHJhaW4lMjIlNUQlNUIwJTVEJTVCJTIybmVyX3RhZ3MlMjIlNUQlMEFsYWJlbHMlMjAlM0QlMjAlNUJsYWJlbF9uYW1lcyU1QmklNUQlMjBmb3IlMjBpJTIwaW4lMjBsYWJlbHMlNUQlMEFsYWJlbHM=",highlighted:`labels = raw_datasets[<span class="hljs-string">&quot;train&quot;</span>][<span class="hljs-number">0</span>][<span class="hljs-string">&quot;ner_tags&quot;</span>]
labels = [label_names[i] <span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> labels]
labels`,wrap:!1}}),Ft=new g({props:{code:"JTVCJ0ItT1JHJyUyQyUyMCdPJyUyQyUyMCdCLU1JU0MnJTJDJTIwJ08nJTJDJTIwJ08nJTJDJTIwJ08nJTJDJTIwJ0ItTUlTQyclMkMlMjAnTyclMkMlMjAnTyclNUQ=",highlighted:'[<span class="hljs-string">&#x27;B-ORG&#x27;</span>, <span class="hljs-string">&#x27;O&#x27;</span>, <span class="hljs-string">&#x27;B-MISC&#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-MISC&#x27;</span>, <span class="hljs-string">&#x27;O&#x27;</span>, <span class="hljs-string">&#x27;O&#x27;</span>]',wrap:!1}}),St=new g({props:{code:"cHJlZGljdGlvbnMlMjAlM0QlMjBsYWJlbHMuY29weSgpJTBBcHJlZGljdGlvbnMlNUIyJTVEJTIwJTNEJTIwJTIyTyUyMiUwQW1ldHJpYy5jb21wdXRlKHByZWRpY3Rpb25zJTNEJTVCcHJlZGljdGlvbnMlNUQlMkMlMjByZWZlcmVuY2VzJTNEJTVCbGFiZWxzJTVEKQ==",highlighted:`predictions = labels.copy()
predictions[<span class="hljs-number">2</span>] = <span class="hljs-string">&quot;O&quot;</span>
metric.compute(predictions=[predictions], references=[labels])`,wrap:!1}}),Dt=new g({props:{code:"JTdCJ01JU0MnJTNBJTIwJTdCJ3ByZWNpc2lvbiclM0ElMjAxLjAlMkMlMjAncmVjYWxsJyUzQSUyMDAuNSUyQyUyMCdmMSclM0ElMjAwLjY3JTJDJTIwJ251bWJlciclM0ElMjAyJTdEJTJDJTBBJTIwJ09SRyclM0ElMjAlN0IncHJlY2lzaW9uJyUzQSUyMDEuMCUyQyUyMCdyZWNhbGwnJTNBJTIwMS4wJTJDJTIwJ2YxJyUzQSUyMDEuMCUyQyUyMCdudW1iZXInJTNBJTIwMSU3RCUyQyUwQSUyMCdvdmVyYWxsX3ByZWNpc2lvbiclM0ElMjAxLjAlMkMlMEElMjAnb3ZlcmFsbF9yZWNhbGwnJTNBJTIwMC42NyUyQyUwQSUyMCdvdmVyYWxsX2YxJyUzQSUyMDAuOCUyQyUwQSUyMCdvdmVyYWxsX2FjY3VyYWN5JyUzQSUyMDAuODklN0Q=",highlighted:`{<span class="hljs-string">&#x27;MISC&#x27;</span>: {<span class="hljs-string">&#x27;precision&#x27;</span>: <span class="hljs-number">1.0</span>, <span class="hljs-string">&#x27;recall&#x27;</span>: <span class="hljs-number">0.5</span>, <span class="hljs-string">&#x27;f1&#x27;</span>: <span class="hljs-number">0.67</span>, <span class="hljs-string">&#x27;number&#x27;</span>: <span class="hljs-number">2</span>},
 <span class="hljs-string">&#x27;ORG&#x27;</span>: {<span class="hljs-string">&#x27;precision&#x27;</span>: <span class="hljs-number">1.0</span>, <span class="hljs-string">&#x27;recall&#x27;</span>: <span class="hljs-number">1.0</span>, <span class="hljs-string">&#x27;f1&#x27;</span>: <span class="hljs-number">1.0</span>, <span class="hljs-string">&#x27;number&#x27;</span>: <span class="hljs-number">1</span>},
 <span class="hljs-string">&#x27;overall_precision&#x27;</span>: <span class="hljs-number">1.0</span>,
 <span class="hljs-string">&#x27;overall_recall&#x27;</span>: <span class="hljs-number">0.67</span>,
 <span class="hljs-string">&#x27;overall_f1&#x27;</span>: <span class="hljs-number">0.8</span>,
 <span class="hljs-string">&#x27;overall_accuracy&#x27;</span>: <span class="hljs-number">0.89</span>}`,wrap:!1}});const xn=[Ma,ca],os=[];function Zn(e,n){return e[0]==="pt"?0:1}_l=Zn(_),xl=os[_l]=xn[_l](_);let P=_[0]==="pt"&&Rn(_);return qt=new ye({props:{title:"Using the fine-tuned model",local:"using-the-fine-tuned-model",headingTag:"h2"}}),Ot=new g({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMHBpcGVsaW5lJTBBJTBBJTIzJTIwUmVwbGFjZSUyMHRoaXMlMjB3aXRoJTIweW91ciUyMG93biUyMGNoZWNrcG9pbnQlMEFtb2RlbF9jaGVja3BvaW50JTIwJTNEJTIwJTIyaHVnZ2luZ2ZhY2UtY291cnNlJTJGYmVydC1maW5ldHVuZWQtbmVyJTIyJTBBdG9rZW5fY2xhc3NpZmllciUyMCUzRCUyMHBpcGVsaW5lKCUwQSUyMCUyMCUyMCUyMCUyMnRva2VuLWNsYXNzaWZpY2F0aW9uJTIyJTJDJTIwbW9kZWwlM0Rtb2RlbF9jaGVja3BvaW50JTJDJTIwYWdncmVnYXRpb25fc3RyYXRlZ3klM0QlMjJzaW1wbGUlMjIlMEEpJTBBdG9rZW5fY2xhc3NpZmllciglMjJNeSUyMG5hbWUlMjBpcyUyMFN5bHZhaW4lMjBhbmQlMjBJJTIwd29yayUyMGF0JTIwSHVnZ2luZyUyMEZhY2UlMjBpbiUyMEJyb29rbHluLiUyMik=",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> pipeline

<span class="hljs-comment"># Replace this with your own checkpoint</span>
model_checkpoint = <span class="hljs-string">&quot;huggingface-course/bert-finetuned-ner&quot;</span>
token_classifier = pipeline(
    <span class="hljs-string">&quot;token-classification&quot;</span>, model=model_checkpoint, aggregation_strategy=<span class="hljs-string">&quot;simple&quot;</span>
)
token_classifier(<span class="hljs-string">&quot;My name is Sylvain and I work at Hugging Face in Brooklyn.&quot;</span>)`,wrap:!1}}),Kt=new g({props:{code:"JTVCJTdCJ2VudGl0eV9ncm91cCclM0ElMjAnUEVSJyUyQyUyMCdzY29yZSclM0ElMjAwLjk5ODg1MDYlMkMlMjAnd29yZCclM0ElMjAnU3lsdmFpbiclMkMlMjAnc3RhcnQnJTNBJTIwMTElMkMlMjAnZW5kJyUzQSUyMDE4JTdEJTJDJTBBJTIwJTdCJ2VudGl0eV9ncm91cCclM0ElMjAnT1JHJyUyQyUyMCdzY29yZSclM0ElMjAwLjk2NDc2MjUlMkMlMjAnd29yZCclM0ElMjAnSHVnZ2luZyUyMEZhY2UnJTJDJTIwJ3N0YXJ0JyUzQSUyMDMzJTJDJTIwJ2VuZCclM0ElMjA0NSU3RCUyQyUwQSUyMCU3QidlbnRpdHlfZ3JvdXAnJTNBJTIwJ0xPQyclMkMlMjAnc2NvcmUnJTNBJTIwMC45OTg2MTE4JTJDJTIwJ3dvcmQnJTNBJTIwJ0Jyb29rbHluJyUyQyUyMCdzdGFydCclM0ElMjA0OSUyQyUyMCdlbmQnJTNBJTIwNTclN0QlNUQ=",highlighted:`[{<span class="hljs-string">&#x27;entity_group&#x27;</span>: <span class="hljs-string">&#x27;PER&#x27;</span>, <span class="hljs-string">&#x27;score&#x27;</span>: <span class="hljs-number">0.9988506</span>, <span class="hljs-string">&#x27;word&#x27;</span>: <span class="hljs-string">&#x27;Sylvain&#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">18</span>},
 {<span class="hljs-string">&#x27;entity_group&#x27;</span>: <span class="hljs-string">&#x27;ORG&#x27;</span>, <span class="hljs-string">&#x27;score&#x27;</span>: <span class="hljs-number">0.9647625</span>, <span class="hljs-string">&#x27;word&#x27;</span>: <span class="hljs-string">&#x27;Hugging Face&#x27;</span>, <span class="hljs-string">&#x27;start&#x27;</span>: <span class="hljs-number">33</span>, <span class="hljs-string">&#x27;end&#x27;</span>: <span class="hljs-number">45</span>},
 {<span class="hljs-string">&#x27;entity_group&#x27;</span>: <span class="hljs-string">&#x27;LOC&#x27;</span>, <span class="hljs-string">&#x27;score&#x27;</span>: <span class="hljs-number">0.9986118</span>, <span class="hljs-string">&#x27;word&#x27;</span>: <span class="hljs-string">&#x27;Brooklyn&#x27;</span>, <span class="hljs-string">&#x27;start&#x27;</span>: <span class="hljs-number">49</span>, <span class="hljs-string">&#x27;end&#x27;</span>: <span class="hljs-number">57</span>}]`,wrap:!1}}),ls=new Ln({props:{source:"https://github.com/huggingface/course/blob/main/chapters/en/chapter7/2.mdx"}}),{c(){o=d("meta"),f=a(),r=d("p"),j=a(),w(x.$$.fragment),U=a(),w(k.$$.fragment),W=a(),Z.c(),v=a(),I=d("p"),I.textContent=B,$=a(),G=d("ul"),G.innerHTML=O,vl=a(),w(ie.$$.fragment),X=a(),oe=d("p"),oe.textContent=K,Ie=a(),A=d("iframe"),Q=a(),D=d("a"),D.innerHTML=ee,Wl=a(),re=d("p"),re.innerHTML=le,Ce=a(),w(V.$$.fragment),Bl=a(),pe=d("p"),pe.innerHTML=te,Al=a(),w(se.$$.fragment),H=a(),w(ce.$$.fragment),E=a(),_e=d("p"),_e.innerHTML=Be,N=a(),w(Me.$$.fragment),F=a(),xe=d("p"),xe.innerHTML=Ae,z=a(),w(me.$$.fragment),he=a(),w(ne.$$.fragment),ke=a(),R=d("p"),R.innerHTML=Gl,de=a(),ae=d("p"),ae.textContent=Ge,S=a(),w(Ze.$$.fragment),$e=a(),w(Y.$$.fragment),Ve=a(),L=d("p"),L.textContent=p,C=a(),w(we.$$.fragment),Ol=a(),w(ue.$$.fragment),ct=a(),Re=d("p"),Re.innerHTML=Vl,Mt=a(),w(Ye.$$.fragment),Xe=a(),w(Qe.$$.fragment),He=a(),Rl=d("p"),Rl.innerHTML=ht,Ee=a(),w(Ne.$$.fragment),Fe=a(),w(Yl.$$.fragment),Kl=a(),Je=d("p"),Je.innerHTML=dt,ze=a(),Xl=d("ul"),Xl.innerHTML=yt,Se=a(),Le=d("p"),Le.textContent=Ql,mt=a(),w(De.$$.fragment),qe=a(),w(Pe.$$.fragment),Oe=a(),Hl=d("p"),Hl.innerHTML=wt,Ke=a(),w(el.$$.fragment),ll=a(),tl=d("p"),tl.innerHTML=El,ut=a(),w(ve.$$.fragment),sl=a(),w(nl.$$.fragment),al=a(),w(Nl.$$.fragment),et=a(),Te=d("p"),Te.innerHTML=Jt,il=a(),ol=d("p"),ol.innerHTML=Fl,Tt=a(),w(rl.$$.fragment),pl=a(),cl=d("p"),cl.innerHTML=zl,bt=a(),w(Ml.$$.fragment),hl=a(),w(dl.$$.fragment),yl=a(),Sl=d("p"),Sl.innerHTML=ft,ml=a(),w(wl.$$.fragment),ul=a(),w(Ll.$$.fragment),lt=a(),be=d("p"),be.innerHTML=ms,tt=a(),fe=d("p"),fe.innerHTML=ws,st=a(),w(je.$$.fragment),nt=a(),w(Ue.$$.fragment),jt=a(),Jl=d("p"),Jl.innerHTML=Dl,at=a(),w(ge.$$.fragment),Ut=a(),Tl=d("p"),Tl.textContent=ql,gt=a(),w(bl.$$.fragment),l=a(),w(c.$$.fragment),Js=a(),It=d("p"),It.innerHTML=an,Ts=a(),w(it.$$.fragment),bs=a(),Ct=d("p"),Ct.innerHTML=on,fs=a(),w(kt.$$.fragment),js=a(),$t=d("p"),$t.textContent=rn,Us=a(),_t=d("p"),_t.textContent=pn,gs=a(),w(xt.$$.fragment),Is=a(),Zt=d("p"),Zt.innerHTML=cn,Cs=a(),jl.c(),rs=a(),w(vt.$$.fragment),ks=a(),Wt=d("p"),Wt.innerHTML=Mn,$s=a(),Bt=d("p"),Bt.innerHTML=hn,_s=a(),gl.c(),ps=a(),At=d("p"),At.textContent=dn,xs=a(),w(Gt.$$.fragment),Zs=a(),w(Vt.$$.fragment),vs=a(),Rt=d("p"),Rt.textContent=yn,Ws=a(),w(Yt.$$.fragment),Bs=a(),w(Xt.$$.fragment),As=a(),Cl.c(),cs=a(),q&&q.c(),Ms=a(),w(Qt.$$.fragment),Gs=a(),$l.c(),hs=a(),w(Ht.$$.fragment),Vs=a(),Et=d("p"),Et.textContent=mn,Rs=a(),w(Nt.$$.fragment),Ys=a(),w(Ft.$$.fragment),Xs=a(),zt=d("p"),zt.textContent=wn,Qs=a(),w(St.$$.fragment),Hs=a(),Lt=d("p"),Lt.textContent=un,Es=a(),w(Dt.$$.fragment),Ns=a(),xl.c(),ds=a(),P&&P.c(),ys=a(),w(qt.$$.fragment),Fs=a(),Pt=d("p"),Pt.innerHTML=Jn,zs=a(),w(Ot.$$.fragment),Ss=a(),w(Kt.$$.fragment),Ls=a(),es=d("p"),es.textContent=Tn,Ds=a(),w(ls.$$.fragment),qs=a(),us=d("p"),this.h()},l(e){const n=Fn("svelte-u9bgzb",document.head);o=y(n,"META",{name:!0,content:!0}),n.forEach(t),f=i(e),r=y(e,"P",{}),nn(r).forEach(t),j=i(e),u(x.$$.fragment,e),U=i(e),u(k.$$.fragment,e),W=i(e),Z.l(e),v=i(e),I=y(e,"P",{"data-svelte-h":!0}),m(I)!=="svelte-149mswf"&&(I.textContent=B),$=i(e),G=y(e,"UL",{"data-svelte-h":!0}),m(G)!=="svelte-rebxe7"&&(G.innerHTML=O),vl=i(e),u(ie.$$.fragment,e),X=i(e),oe=y(e,"P",{"data-svelte-h":!0}),m(oe)!=="svelte-lkr4ab"&&(oe.textContent=K),Ie=i(e),A=y(e,"IFRAME",{src:!0,frameborder:!0,height:!0,title:!0,class:!0,allow:!0,sandbox:!0}),nn(A).forEach(t),Q=i(e),D=y(e,"A",{class:!0,href:!0,"data-svelte-h":!0}),m(D)!=="svelte-1n7oe9l"&&(D.innerHTML=ee),Wl=i(e),re=y(e,"P",{"data-svelte-h":!0}),m(re)!=="svelte-1nxnbu7"&&(re.innerHTML=le),Ce=i(e),u(V.$$.fragment,e),Bl=i(e),pe=y(e,"P",{"data-svelte-h":!0}),m(pe)!=="svelte-1as9qr9"&&(pe.innerHTML=te),Al=i(e),u(se.$$.fragment,e),H=i(e),u(ce.$$.fragment,e),E=i(e),_e=y(e,"P",{"data-svelte-h":!0}),m(_e)!=="svelte-1h1iv00"&&(_e.innerHTML=Be),N=i(e),u(Me.$$.fragment,e),F=i(e),xe=y(e,"P",{"data-svelte-h":!0}),m(xe)!=="svelte-1hbl8kq"&&(xe.innerHTML=Ae),z=i(e),u(me.$$.fragment,e),he=i(e),u(ne.$$.fragment,e),ke=i(e),R=y(e,"P",{"data-svelte-h":!0}),m(R)!=="svelte-80heu6"&&(R.innerHTML=Gl),de=i(e),ae=y(e,"P",{"data-svelte-h":!0}),m(ae)!=="svelte-htmsfr"&&(ae.textContent=Ge),S=i(e),u(Ze.$$.fragment,e),$e=i(e),u(Y.$$.fragment,e),Ve=i(e),L=y(e,"P",{"data-svelte-h":!0}),m(L)!=="svelte-a7wbyy"&&(L.textContent=p),C=i(e),u(we.$$.fragment,e),Ol=i(e),u(ue.$$.fragment,e),ct=i(e),Re=y(e,"P",{"data-svelte-h":!0}),m(Re)!=="svelte-1ammq33"&&(Re.innerHTML=Vl),Mt=i(e),u(Ye.$$.fragment,e),Xe=i(e),u(Qe.$$.fragment,e),He=i(e),Rl=y(e,"P",{"data-svelte-h":!0}),m(Rl)!=="svelte-1rtshpl"&&(Rl.innerHTML=ht),Ee=i(e),u(Ne.$$.fragment,e),Fe=i(e),u(Yl.$$.fragment,e),Kl=i(e),Je=y(e,"P",{"data-svelte-h":!0}),m(Je)!=="svelte-3bj295"&&(Je.innerHTML=dt),ze=i(e),Xl=y(e,"UL",{"data-svelte-h":!0}),m(Xl)!=="svelte-1aahq62"&&(Xl.innerHTML=yt),Se=i(e),Le=y(e,"P",{"data-svelte-h":!0}),m(Le)!=="svelte-2mh8n6"&&(Le.textContent=Ql),mt=i(e),u(De.$$.fragment,e),qe=i(e),u(Pe.$$.fragment,e),Oe=i(e),Hl=y(e,"P",{"data-svelte-h":!0}),m(Hl)!=="svelte-1v8gutz"&&(Hl.innerHTML=wt),Ke=i(e),u(el.$$.fragment,e),ll=i(e),tl=y(e,"P",{"data-svelte-h":!0}),m(tl)!=="svelte-1r7hfcn"&&(tl.innerHTML=El),ut=i(e),u(ve.$$.fragment,e),sl=i(e),u(nl.$$.fragment,e),al=i(e),u(Nl.$$.fragment,e),et=i(e),Te=y(e,"P",{"data-svelte-h":!0}),m(Te)!=="svelte-j28vlc"&&(Te.innerHTML=Jt),il=i(e),ol=y(e,"P",{"data-svelte-h":!0}),m(ol)!=="svelte-pykhfo"&&(ol.innerHTML=Fl),Tt=i(e),u(rl.$$.fragment,e),pl=i(e),cl=y(e,"P",{"data-svelte-h":!0}),m(cl)!=="svelte-rceabt"&&(cl.innerHTML=zl),bt=i(e),u(Ml.$$.fragment,e),hl=i(e),u(dl.$$.fragment,e),yl=i(e),Sl=y(e,"P",{"data-svelte-h":!0}),m(Sl)!=="svelte-qrwwy3"&&(Sl.innerHTML=ft),ml=i(e),u(wl.$$.fragment,e),ul=i(e),u(Ll.$$.fragment,e),lt=i(e),be=y(e,"P",{"data-svelte-h":!0}),m(be)!=="svelte-13d4q0o"&&(be.innerHTML=ms),tt=i(e),fe=y(e,"P",{"data-svelte-h":!0}),m(fe)!=="svelte-1fhsp2i"&&(fe.innerHTML=ws),st=i(e),u(je.$$.fragment,e),nt=i(e),u(Ue.$$.fragment,e),jt=i(e),Jl=y(e,"P",{"data-svelte-h":!0}),m(Jl)!=="svelte-deopbg"&&(Jl.innerHTML=Dl),at=i(e),u(ge.$$.fragment,e),Ut=i(e),Tl=y(e,"P",{"data-svelte-h":!0}),m(Tl)!=="svelte-lz79df"&&(Tl.textContent=ql),gt=i(e),u(bl.$$.fragment,e),l=i(e),u(c.$$.fragment,e),Js=i(e),It=y(e,"P",{"data-svelte-h":!0}),m(It)!=="svelte-1bgynna"&&(It.innerHTML=an),Ts=i(e),u(it.$$.fragment,e),bs=i(e),Ct=y(e,"P",{"data-svelte-h":!0}),m(Ct)!=="svelte-1dnr87f"&&(Ct.innerHTML=on),fs=i(e),u(kt.$$.fragment,e),js=i(e),$t=y(e,"P",{"data-svelte-h":!0}),m($t)!=="svelte-198ff0u"&&($t.textContent=rn),Us=i(e),_t=y(e,"P",{"data-svelte-h":!0}),m(_t)!=="svelte-yl3xx9"&&(_t.textContent=pn),gs=i(e),u(xt.$$.fragment,e),Is=i(e),Zt=y(e,"P",{"data-svelte-h":!0}),m(Zt)!=="svelte-1syo56o"&&(Zt.innerHTML=cn),Cs=i(e),jl.l(e),rs=i(e),u(vt.$$.fragment,e),ks=i(e),Wt=y(e,"P",{"data-svelte-h":!0}),m(Wt)!=="svelte-1j0tke5"&&(Wt.innerHTML=Mn),$s=i(e),Bt=y(e,"P",{"data-svelte-h":!0}),m(Bt)!=="svelte-2kw0z8"&&(Bt.innerHTML=hn),_s=i(e),gl.l(e),ps=i(e),At=y(e,"P",{"data-svelte-h":!0}),m(At)!=="svelte-ltlhnk"&&(At.textContent=dn),xs=i(e),u(Gt.$$.fragment,e),Zs=i(e),u(Vt.$$.fragment,e),vs=i(e),Rt=y(e,"P",{"data-svelte-h":!0}),m(Rt)!=="svelte-1hl8zfk"&&(Rt.textContent=yn),Ws=i(e),u(Yt.$$.fragment,e),Bs=i(e),u(Xt.$$.fragment,e),As=i(e),Cl.l(e),cs=i(e),q&&q.l(e),Ms=i(e),u(Qt.$$.fragment,e),Gs=i(e),$l.l(e),hs=i(e),u(Ht.$$.fragment,e),Vs=i(e),Et=y(e,"P",{"data-svelte-h":!0}),m(Et)!=="svelte-1dfdizz"&&(Et.textContent=mn),Rs=i(e),u(Nt.$$.fragment,e),Ys=i(e),u(Ft.$$.fragment,e),Xs=i(e),zt=y(e,"P",{"data-svelte-h":!0}),m(zt)!=="svelte-1qhns3f"&&(zt.textContent=wn),Qs=i(e),u(St.$$.fragment,e),Hs=i(e),Lt=y(e,"P",{"data-svelte-h":!0}),m(Lt)!=="svelte-q6wd42"&&(Lt.textContent=un),Es=i(e),u(Dt.$$.fragment,e),Ns=i(e),xl.l(e),ds=i(e),P&&P.l(e),ys=i(e),u(qt.$$.fragment,e),Fs=i(e),Pt=y(e,"P",{"data-svelte-h":!0}),m(Pt)!=="svelte-13vy17t"&&(Pt.innerHTML=Jn),zs=i(e),u(Ot.$$.fragment,e),Ss=i(e),u(Kt.$$.fragment,e),Ls=i(e),es=y(e,"P",{"data-svelte-h":!0}),m(es)!=="svelte-19li140"&&(es.textContent=Tn),Ds=i(e),u(ls.$$.fragment,e),qs=i(e),us=y(e,"P",{}),nn(us).forEach(t),this.h()},h(){Zl(o,"name","hf:doc:metadata"),Zl(o,"content",wa),Qn(A.src,We="https://course-demos-bert-finetuned-ner.hf.space")||Zl(A,"src",We),Zl(A,"frameborder","0"),Zl(A,"height","350"),Zl(A,"title","Gradio app"),Zl(A,"class","block dark:hidden container p-0 flex-grow space-iframe"),Zl(A,"allow","accelerometer; ambient-light-sensor; autoplay; battery; camera; document-domain; encrypted-media; fullscreen; geolocation; gyroscope; layout-animations; legacy-image-formats; magnetometer; microphone; midi; oversized-images; payment; picture-in-picture; publickey-credentials-get; sync-xhr; usb; vr ; wake-lock; xr-spatial-tracking"),Zl(A,"sandbox","allow-forms allow-modals allow-popups allow-popups-to-escape-sandbox allow-same-origin allow-scripts allow-downloads"),Zl(D,"class","flex justify-center"),Zl(D,"href","/huggingface-course/bert-finetuned-ner")},m(e,n){zn(document.head,o),s(e,f,n),s(e,r,n),s(e,j,n),J(x,e,n),s(e,U,n),J(k,e,n),s(e,W,n),ts[b].m(e,n),s(e,v,n),s(e,I,n),s(e,$,n),s(e,G,n),s(e,vl,n),J(ie,e,n),s(e,X,n),s(e,oe,n),s(e,Ie,n),s(e,A,n),s(e,Q,n),s(e,D,n),s(e,Wl,n),s(e,re,n),s(e,Ce,n),J(V,e,n),s(e,Bl,n),s(e,pe,n),s(e,Al,n),J(se,e,n),s(e,H,n),J(ce,e,n),s(e,E,n),s(e,_e,n),s(e,N,n),J(Me,e,n),s(e,F,n),s(e,xe,n),s(e,z,n),J(me,e,n),s(e,he,n),J(ne,e,n),s(e,ke,n),s(e,R,n),s(e,de,n),s(e,ae,n),s(e,S,n),J(Ze,e,n),s(e,$e,n),J(Y,e,n),s(e,Ve,n),s(e,L,n),s(e,C,n),J(we,e,n),s(e,Ol,n),J(ue,e,n),s(e,ct,n),s(e,Re,n),s(e,Mt,n),J(Ye,e,n),s(e,Xe,n),J(Qe,e,n),s(e,He,n),s(e,Rl,n),s(e,Ee,n),J(Ne,e,n),s(e,Fe,n),J(Yl,e,n),s(e,Kl,n),s(e,Je,n),s(e,ze,n),s(e,Xl,n),s(e,Se,n),s(e,Le,n),s(e,mt,n),J(De,e,n),s(e,qe,n),J(Pe,e,n),s(e,Oe,n),s(e,Hl,n),s(e,Ke,n),J(el,e,n),s(e,ll,n),s(e,tl,n),s(e,ut,n),J(ve,e,n),s(e,sl,n),J(nl,e,n),s(e,al,n),J(Nl,e,n),s(e,et,n),s(e,Te,n),s(e,il,n),s(e,ol,n),s(e,Tt,n),J(rl,e,n),s(e,pl,n),s(e,cl,n),s(e,bt,n),J(Ml,e,n),s(e,hl,n),J(dl,e,n),s(e,yl,n),s(e,Sl,n),s(e,ml,n),J(wl,e,n),s(e,ul,n),J(Ll,e,n),s(e,lt,n),s(e,be,n),s(e,tt,n),s(e,fe,n),s(e,st,n),J(je,e,n),s(e,nt,n),J(Ue,e,n),s(e,jt,n),s(e,Jl,n),s(e,at,n),J(ge,e,n),s(e,Ut,n),s(e,Tl,n),s(e,gt,n),J(bl,e,n),s(e,l,n),J(c,e,n),s(e,Js,n),s(e,It,n),s(e,Ts,n),J(it,e,n),s(e,bs,n),s(e,Ct,n),s(e,fs,n),J(kt,e,n),s(e,js,n),s(e,$t,n),s(e,Us,n),s(e,_t,n),s(e,gs,n),J(xt,e,n),s(e,Is,n),s(e,Zt,n),s(e,Cs,n),ss[fl].m(e,n),s(e,rs,n),J(vt,e,n),s(e,ks,n),s(e,Wt,n),s(e,$s,n),s(e,Bt,n),s(e,_s,n),ns[Ul].m(e,n),s(e,ps,n),s(e,At,n),s(e,xs,n),J(Gt,e,n),s(e,Zs,n),J(Vt,e,n),s(e,vs,n),s(e,Rt,n),s(e,Ws,n),J(Yt,e,n),s(e,Bs,n),J(Xt,e,n),s(e,As,n),as[Il].m(e,n),s(e,cs,n),q&&q.m(e,n),s(e,Ms,n),J(Qt,e,n),s(e,Gs,n),is[kl].m(e,n),s(e,hs,n),J(Ht,e,n),s(e,Vs,n),s(e,Et,n),s(e,Rs,n),J(Nt,e,n),s(e,Ys,n),J(Ft,e,n),s(e,Xs,n),s(e,zt,n),s(e,Qs,n),J(St,e,n),s(e,Hs,n),s(e,Lt,n),s(e,Es,n),J(Dt,e,n),s(e,Ns,n),os[_l].m(e,n),s(e,ds,n),P&&P.m(e,n),s(e,ys,n),J(qt,e,n),s(e,Fs,n),s(e,Pt,n),s(e,zs,n),J(Ot,e,n),s(e,Ss,n),J(Kt,e,n),s(e,Ls,n),s(e,es,n),s(e,Ds,n),J(ls,e,n),s(e,qs,n),s(e,us,n),Ps=!0},p(e,[n]){const vn={};n&1&&(vn.fw=e[0]),x.$set(vn);let Os=b;b=fn(e),b!==Os&&(rt(),h(ts[Os],1,1,()=>{ts[Os]=null}),ot(),Z=ts[b],Z||(Z=ts[b]=bn[b](e),Z.c()),M(Z,1),Z.m(v.parentNode,v));const Wn={};n&2&&(Wn.$$scope={dirty:n,ctx:e}),se.$set(Wn);const Bn={};n&2&&(Bn.$$scope={dirty:n,ctx:e}),ve.$set(Bn);const An={};n&2&&(An.$$scope={dirty:n,ctx:e}),it.$set(An);let Ks=fl;fl=Un(e),fl!==Ks&&(rt(),h(ss[Ks],1,1,()=>{ss[Ks]=null}),ot(),jl=ss[fl],jl||(jl=ss[fl]=jn[fl](e),jl.c()),M(jl,1),jl.m(rs.parentNode,rs));let en=Ul;Ul=In(e),Ul!==en&&(rt(),h(ns[en],1,1,()=>{ns[en]=null}),ot(),gl=ns[Ul],gl||(gl=ns[Ul]=gn[Ul](e),gl.c()),M(gl,1),gl.m(ps.parentNode,ps));let ln=Il;Il=kn(e),Il!==ln&&(rt(),h(as[ln],1,1,()=>{as[ln]=null}),ot(),Cl=as[Il],Cl||(Cl=as[Il]=Cn[Il](e),Cl.c()),M(Cl,1),Cl.m(cs.parentNode,cs)),e[0]==="tf"?q?n&1&&M(q,1):(q=Vn(e),q.c(),M(q,1),q.m(Ms.parentNode,Ms)):q&&(rt(),h(q,1,1,()=>{q=null}),ot());let tn=kl;kl=_n(e),kl!==tn&&(rt(),h(is[tn],1,1,()=>{is[tn]=null}),ot(),$l=is[kl],$l||($l=is[kl]=$n[kl](e),$l.c()),M($l,1),$l.m(hs.parentNode,hs));let sn=_l;_l=Zn(e),_l!==sn&&(rt(),h(os[sn],1,1,()=>{os[sn]=null}),ot(),xl=os[_l],xl||(xl=os[_l]=xn[_l](e),xl.c()),M(xl,1),xl.m(ds.parentNode,ds)),e[0]==="pt"?P?n&1&&M(P,1):(P=Rn(e),P.c(),M(P,1),P.m(ys.parentNode,ys)):P&&(rt(),h(P,1,1,()=>{P=null}),ot())},i(e){Ps||(M(x.$$.fragment,e),M(k.$$.fragment,e),M(Z),M(ie.$$.fragment,e),M(V.$$.fragment,e),M(se.$$.fragment,e),M(ce.$$.fragment,e),M(Me.$$.fragment,e),M(me.$$.fragment,e),M(ne.$$.fragment,e),M(Ze.$$.fragment,e),M(Y.$$.fragment,e),M(we.$$.fragment,e),M(ue.$$.fragment,e),M(Ye.$$.fragment,e),M(Qe.$$.fragment,e),M(Ne.$$.fragment,e),M(Yl.$$.fragment,e),M(De.$$.fragment,e),M(Pe.$$.fragment,e),M(el.$$.fragment,e),M(ve.$$.fragment,e),M(nl.$$.fragment,e),M(Nl.$$.fragment,e),M(rl.$$.fragment,e),M(Ml.$$.fragment,e),M(dl.$$.fragment,e),M(wl.$$.fragment,e),M(Ll.$$.fragment,e),M(je.$$.fragment,e),M(Ue.$$.fragment,e),M(ge.$$.fragment,e),M(bl.$$.fragment,e),M(c.$$.fragment,e),M(it.$$.fragment,e),M(kt.$$.fragment,e),M(xt.$$.fragment,e),M(jl),M(vt.$$.fragment,e),M(gl),M(Gt.$$.fragment,e),M(Vt.$$.fragment,e),M(Yt.$$.fragment,e),M(Xt.$$.fragment,e),M(Cl),M(q),M(Qt.$$.fragment,e),M($l),M(Ht.$$.fragment,e),M(Nt.$$.fragment,e),M(Ft.$$.fragment,e),M(St.$$.fragment,e),M(Dt.$$.fragment,e),M(xl),M(P),M(qt.$$.fragment,e),M(Ot.$$.fragment,e),M(Kt.$$.fragment,e),M(ls.$$.fragment,e),Ps=!0)},o(e){h(x.$$.fragment,e),h(k.$$.fragment,e),h(Z),h(ie.$$.fragment,e),h(V.$$.fragment,e),h(se.$$.fragment,e),h(ce.$$.fragment,e),h(Me.$$.fragment,e),h(me.$$.fragment,e),h(ne.$$.fragment,e),h(Ze.$$.fragment,e),h(Y.$$.fragment,e),h(we.$$.fragment,e),h(ue.$$.fragment,e),h(Ye.$$.fragment,e),h(Qe.$$.fragment,e),h(Ne.$$.fragment,e),h(Yl.$$.fragment,e),h(De.$$.fragment,e),h(Pe.$$.fragment,e),h(el.$$.fragment,e),h(ve.$$.fragment,e),h(nl.$$.fragment,e),h(Nl.$$.fragment,e),h(rl.$$.fragment,e),h(Ml.$$.fragment,e),h(dl.$$.fragment,e),h(wl.$$.fragment,e),h(Ll.$$.fragment,e),h(je.$$.fragment,e),h(Ue.$$.fragment,e),h(ge.$$.fragment,e),h(bl.$$.fragment,e),h(c.$$.fragment,e),h(it.$$.fragment,e),h(kt.$$.fragment,e),h(xt.$$.fragment,e),h(jl),h(vt.$$.fragment,e),h(gl),h(Gt.$$.fragment,e),h(Vt.$$.fragment,e),h(Yt.$$.fragment,e),h(Xt.$$.fragment,e),h(Cl),h(q),h(Qt.$$.fragment,e),h($l),h(Ht.$$.fragment,e),h(Nt.$$.fragment,e),h(Ft.$$.fragment,e),h(St.$$.fragment,e),h(Dt.$$.fragment,e),h(xl),h(P),h(qt.$$.fragment,e),h(Ot.$$.fragment,e),h(Kt.$$.fragment,e),h(ls.$$.fragment,e),Ps=!1},d(e){e&&(t(f),t(r),t(j),t(U),t(W),t(v),t(I),t($),t(G),t(vl),t(X),t(oe),t(Ie),t(A),t(Q),t(D),t(Wl),t(re),t(Ce),t(Bl),t(pe),t(Al),t(H),t(E),t(_e),t(N),t(F),t(xe),t(z),t(he),t(ke),t(R),t(de),t(ae),t(S),t($e),t(Ve),t(L),t(C),t(Ol),t(ct),t(Re),t(Mt),t(Xe),t(He),t(Rl),t(Ee),t(Fe),t(Kl),t(Je),t(ze),t(Xl),t(Se),t(Le),t(mt),t(qe),t(Oe),t(Hl),t(Ke),t(ll),t(tl),t(ut),t(sl),t(al),t(et),t(Te),t(il),t(ol),t(Tt),t(pl),t(cl),t(bt),t(hl),t(yl),t(Sl),t(ml),t(ul),t(lt),t(be),t(tt),t(fe),t(st),t(nt),t(jt),t(Jl),t(at),t(Ut),t(Tl),t(gt),t(l),t(Js),t(It),t(Ts),t(bs),t(Ct),t(fs),t(js),t($t),t(Us),t(_t),t(gs),t(Is),t(Zt),t(Cs),t(rs),t(ks),t(Wt),t($s),t(Bt),t(_s),t(ps),t(At),t(xs),t(Zs),t(vs),t(Rt),t(Ws),t(Bs),t(As),t(cs),t(Ms),t(Gs),t(hs),t(Vs),t(Et),t(Rs),t(Ys),t(Xs),t(zt),t(Qs),t(Hs),t(Lt),t(Es),t(Ns),t(ds),t(ys),t(Fs),t(Pt),t(zs),t(Ss),t(Ls),t(es),t(Ds),t(qs),t(us)),t(o),T(x,e),T(k,e),ts[b].d(e),T(ie,e),T(V,e),T(se,e),T(ce,e),T(Me,e),T(me,e),T(ne,e),T(Ze,e),T(Y,e),T(we,e),T(ue,e),T(Ye,e),T(Qe,e),T(Ne,e),T(Yl,e),T(De,e),T(Pe,e),T(el,e),T(ve,e),T(nl,e),T(Nl,e),T(rl,e),T(Ml,e),T(dl,e),T(wl,e),T(Ll,e),T(je,e),T(Ue,e),T(ge,e),T(bl,e),T(c,e),T(it,e),T(kt,e),T(xt,e),ss[fl].d(e),T(vt,e),ns[Ul].d(e),T(Gt,e),T(Vt,e),T(Yt,e),T(Xt,e),as[Il].d(e),q&&q.d(e),T(Qt,e),is[kl].d(e),T(Ht,e),T(Nt,e),T(Ft,e),T(St,e),T(Dt,e),os[_l].d(e),P&&P.d(e),T(qt,e),T(Ot,e),T(Kt,e),T(ls,e)}}}const wa='{"title":"Token classification","local":"token-classification","sections":[{"title":"Preparing the data","local":"preparing-the-data","sections":[{"title":"The CoNLL-2003 dataset","local":"the-conll-2003-dataset","sections":[],"depth":3},{"title":"Processing the data","local":"processing-the-data","sections":[],"depth":3}],"depth":2},{"title":"Fine-tuning the model with the Trainer API","local":"fine-tuning-the-model-with-the-trainer-api","sections":[],"depth":2},{"title":"Fine-tuning the model with Keras","local":"fine-tuning-the-model-with-keras","sections":[{"title":"Data collation","local":"data-collation","sections":[],"depth":3},{"title":"Defining the model","local":"defining-the-model","sections":[],"depth":3},{"title":"Fine-tuning the model","local":"fine-tuning-the-model","sections":[],"depth":3},{"title":"Metrics","local":"metrics","sections":[],"depth":3},{"title":"Defining the model","local":"defining-the-model","sections":[],"depth":3},{"title":"Fine-tuning the model","local":"fine-tuning-the-model","sections":[],"depth":3}],"depth":2},{"title":"A custom training loop","local":"a-custom-training-loop","sections":[{"title":"Preparing everything for training","local":"preparing-everything-for-training","sections":[],"depth":3},{"title":"Training loop","local":"training-loop","sections":[],"depth":3}],"depth":2},{"title":"Using the fine-tuned model","local":"using-the-fine-tuned-model","sections":[],"depth":2}],"depth":1}';function ua(_,o,f){let r="pt";return Hn(()=>{const j=new URLSearchParams(window.location.search);f(0,r=j.get("fw")||"pt")}),[r]}class Ca extends En{constructor(o){super(),Nn(this,o,ua,ma,Xn,{})}}export{Ca as component};
