import{s as Hn,a as En,o as Nn,n as Sl}from"../chunks/scheduler.cc52f4b9.js";import{S as Fn,i as zn,e as d,s as a,c as w,h as Sn,a as y,d as t,b as i,f as on,g as u,j as m,k as kl,l as Ln,m as s,n as J,o as h,E as ot,t as M,p as T,F as rt}from"../chunks/index.5b747fde.js";import{T as pt}from"../chunks/Tip.f0925d57.js";import{C as Dn,H as ce,E as qn}from"../chunks/MermaidChart.svelte_svelte_type_style_lang.d38ac5a9.js";import{Y as Rn}from"../chunks/Youtube.8bb4154e.js";import{C as g}from"../chunks/CodeBlock.665bfc37.js";import{C as Qn}from"../chunks/CourseFloatingBanner.b33fcd79.js";import{F as Pn}from"../chunks/FrameworkSwitchCourse.b3b657b3.js";function On(x){let o,f;return o=new Qn({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 Kn(x){let o,f;return o=new Qn({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 ea(x){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:Sl,d(r){r&&t(o)}}}function la(x){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:Sl,d(r){r&&t(o)}}}function ta(x){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:Sl,d(r){r&&t(o)}}}function sa(x){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.",_;return o=new ce({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),_=!0},i(U){_||(M(o.$$.fragment,U),_=!0)},o(U){h(o.$$.fragment,U),_=!1},d(U){U&&(t(f),t(r)),T(o,U)}}}function na(x){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.",_;return o=new ce({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),_=!0},i(U){_||(M(o.$$.fragment,U),_=!0)},o(U){h(o.$$.fragment,U),_=!1},d(U){U&&(t(f),t(r)),T(o,U)}}}function aa(x){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 ia(x){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 oa(x){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,_,U,k="Next stop: the model itself.",v;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),_=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),_=i(b),U=y(b,"P",{"data-svelte-h":!0}),m(U)!=="svelte-68qel6"&&(U.textContent=k)},m(b,W){s(b,o,W),s(b,r,W),J(j,b,W),s(b,_,W),s(b,U,W),v=!0},i(b){v||(M(j.$$.fragment,b),v=!0)},o(b){h(j.$$.fragment,b),v=!1},d(b){b&&(t(o),t(r),t(_),t(U)),T(j,b)}}}function ra(x){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:Sl,o:Sl,d(r){r&&t(o)}}}function Yn(x){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.",_,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:",v,b,W,Z,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,$,Q,H,xe='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:',Ae,E,ae,N,ie,le,Ue,A,Ge,F,Me="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:",Ve,z,oe,te,xl="This will display a widget where you can enter your Hugging Face login credentials.",re,S,_e="If you aren’t working in a notebook, just type the following line in your terminal:",Re,L,se,D,Ze="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:",ge,G,Ye,q,ve="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.",Ie,V,_l="Next, we define a <code>PushToHubCallback</code> to upload our model to the Hub during training, and fit the model with that callback:",pe,ne,Ce,R,Xe='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>.',P,We,$e,Y,at="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.",ke,X,Qe="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.",O;return o=new ce({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}}),E=new g({props:{code:"bW9kZWwuY29uZmlnLm51bV9sYWJlbHM=",highlighted:"model.config.num_labels",wrap:!1}}),N=new g({props:{code:"OQ==",highlighted:'<span class="hljs-number">9</span>',wrap:!1}}),le=new pt({props:{warning:!0,$$slots:{default:[pa]},$$scope:{ctx:x}}}),A=new ce({props:{title:"Fine-tuning the model",local:"fine-tuning-the-model",headingTag:"h3"}}),z=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}}),L=new g({props:{code:"aHVnZ2luZ2ZhY2UtY2xpJTIwbG9naW4=",highlighted:"huggingface-cli login",wrap:!1}}),G=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}}),We=new pt({props:{$$slots:{default:[ca]},$$scope:{ctx:x}}}),{c(){w(o.$$.fragment),f=a(),r=d("p"),r.innerHTML=j,_=a(),U=d("p"),U.innerHTML=k,v=a(),w(b.$$.fragment),W=a(),Z=d("p"),Z.innerHTML=I,B=a(),w($.$$.fragment),Q=a(),H=d("p"),H.innerHTML=xe,Ae=a(),w(E.$$.fragment),ae=a(),w(N.$$.fragment),ie=a(),w(le.$$.fragment),Ue=a(),w(A.$$.fragment),Ge=a(),F=d("p"),F.textContent=Me,Ve=a(),w(z.$$.fragment),oe=a(),te=d("p"),te.textContent=xl,re=a(),S=d("p"),S.textContent=_e,Re=a(),w(L.$$.fragment),se=a(),D=d("p"),D.innerHTML=Ze,ge=a(),w(G.$$.fragment),Ye=a(),q=d("p"),q.innerHTML=ve,Ie=a(),V=d("p"),V.innerHTML=_l,pe=a(),w(ne.$$.fragment),Ce=a(),R=d("p"),R.innerHTML=Xe,P=a(),w(We.$$.fragment),$e=a(),Y=d("p"),Y.textContent=at,ke=a(),X=d("p"),X.textContent=Qe},l(p){u(o.$$.fragment,p),f=i(p),r=y(p,"P",{"data-svelte-h":!0}),m(r)!=="svelte-g65pls"&&(r.innerHTML=j),_=i(p),U=y(p,"P",{"data-svelte-h":!0}),m(U)!=="svelte-1u16d4j"&&(U.innerHTML=k),v=i(p),u(b.$$.fragment,p),W=i(p),Z=y(p,"P",{"data-svelte-h":!0}),m(Z)!=="svelte-110sik5"&&(Z.innerHTML=I),B=i(p),u($.$$.fragment,p),Q=i(p),H=y(p,"P",{"data-svelte-h":!0}),m(H)!=="svelte-1diayaf"&&(H.innerHTML=xe),Ae=i(p),u(E.$$.fragment,p),ae=i(p),u(N.$$.fragment,p),ie=i(p),u(le.$$.fragment,p),Ue=i(p),u(A.$$.fragment,p),Ge=i(p),F=y(p,"P",{"data-svelte-h":!0}),m(F)!=="svelte-7gicgg"&&(F.textContent=Me),Ve=i(p),u(z.$$.fragment,p),oe=i(p),te=y(p,"P",{"data-svelte-h":!0}),m(te)!=="svelte-1ied0vh"&&(te.textContent=xl),re=i(p),S=y(p,"P",{"data-svelte-h":!0}),m(S)!=="svelte-648vlf"&&(S.textContent=_e),Re=i(p),u(L.$$.fragment,p),se=i(p),D=y(p,"P",{"data-svelte-h":!0}),m(D)!=="svelte-18iprmy"&&(D.innerHTML=Ze),ge=i(p),u(G.$$.fragment,p),Ye=i(p),q=y(p,"P",{"data-svelte-h":!0}),m(q)!=="svelte-iieayr"&&(q.innerHTML=ve),Ie=i(p),V=y(p,"P",{"data-svelte-h":!0}),m(V)!=="svelte-b3y3so"&&(V.innerHTML=_l),pe=i(p),u(ne.$$.fragment,p),Ce=i(p),R=y(p,"P",{"data-svelte-h":!0}),m(R)!=="svelte-ff9ew6"&&(R.innerHTML=Xe),P=i(p),u(We.$$.fragment,p),$e=i(p),Y=y(p,"P",{"data-svelte-h":!0}),m(Y)!=="svelte-2l4fow"&&(Y.textContent=at),ke=i(p),X=y(p,"P",{"data-svelte-h":!0}),m(X)!=="svelte-1s4h6ig"&&(X.textContent=Qe)},m(p,C){J(o,p,C),s(p,f,C),s(p,r,C),s(p,_,C),s(p,U,C),s(p,v,C),J(b,p,C),s(p,W,C),s(p,Z,C),s(p,B,C),J($,p,C),s(p,Q,C),s(p,H,C),s(p,Ae,C),J(E,p,C),s(p,ae,C),J(N,p,C),s(p,ie,C),J(le,p,C),s(p,Ue,C),J(A,p,C),s(p,Ge,C),s(p,F,C),s(p,Ve,C),J(z,p,C),s(p,oe,C),s(p,te,C),s(p,re,C),s(p,S,C),s(p,Re,C),J(L,p,C),s(p,se,C),s(p,D,C),s(p,ge,C),J(G,p,C),s(p,Ye,C),s(p,q,C),s(p,Ie,C),s(p,V,C),s(p,pe,C),J(ne,p,C),s(p,Ce,C),s(p,R,C),s(p,P,C),J(We,p,C),s(p,$e,C),s(p,Y,C),s(p,ke,C),s(p,X,C),O=!0},i(p){O||(M(o.$$.fragment,p),M(b.$$.fragment,p),M($.$$.fragment,p),M(E.$$.fragment,p),M(N.$$.fragment,p),M(le.$$.fragment,p),M(A.$$.fragment,p),M(z.$$.fragment,p),M(L.$$.fragment,p),M(G.$$.fragment,p),M(ne.$$.fragment,p),M(We.$$.fragment,p),O=!0)},o(p){h(o.$$.fragment,p),h(b.$$.fragment,p),h($.$$.fragment,p),h(E.$$.fragment,p),h(N.$$.fragment,p),h(le.$$.fragment,p),h(A.$$.fragment,p),h(z.$$.fragment,p),h(L.$$.fragment,p),h(G.$$.fragment,p),h(ne.$$.fragment,p),h(We.$$.fragment,p),O=!1},d(p){p&&(t(f),t(r),t(_),t(U),t(v),t(W),t(Z),t(B),t(Q),t(H),t(Ae),t(ae),t(ie),t(Ue),t(Ge),t(F),t(Ve),t(oe),t(te),t(re),t(S),t(Re),t(se),t(D),t(ge),t(Ye),t(q),t(Ie),t(V),t(pe),t(Ce),t(R),t(P),t($e),t(Y),t(ke),t(X)),T(o,p),T(b,p),T($,p),T(E,p),T(N,p),T(le,p),T(A,p),T(z,p),T(L,p),T(G,p),T(ne,p),T(We,p)}}}function pa(x){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:Sl,d(r){r&&t(o)}}}function ca(x){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:Sl,d(r){r&&t(o)}}}function Ma(x){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,_,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>:',v;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),_=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),_=i(b),U=y(b,"P",{"data-svelte-h":!0}),m(U)!=="svelte-1jg3d4v"&&(U.innerHTML=k)},m(b,W){s(b,o,W),s(b,r,W),J(j,b,W),s(b,_,W),s(b,U,W),v=!0},i(b){v||(M(j.$$.fragment,b),v=!0)},o(b){h(j.$$.fragment,b),v=!1},d(b){b&&(t(o),t(r),t(_),t(U)),T(j,b)}}}function ha(x){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,_='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,v,b,W='We can then load it via the <code>evaluate.load()</code> function like we did in <a href="/course/chapter3">Chapter 3</a>:',Z;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=_,U=a(),w(k.$$.fragment),v=a(),b=d("p"),b.innerHTML=W},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=_),U=i(I),u(k.$$.fragment,I),v=i(I),b=y(I,"P",{"data-svelte-h":!0}),m(b)!=="svelte-1jg3d4v"&&(b.innerHTML=W)},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,v,B),s(I,b,B),Z=!0},i(I){Z||(M(k.$$.fragment,I),Z=!0)},o(I){h(k.$$.fragment,I),Z=!1},d(I){I&&(t(o),t(r),t(j),t(U),t(v),t(b)),T(k,I)}}}function da(x){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,_="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,v,b,W,Z,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=_,U=a(),w(k.$$.fragment),v=a(),w(b.$$.fragment),W=a(),Z=d("p"),Z.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=_),U=i($),u(k.$$.fragment,$),v=i($),u(b.$$.fragment,$),W=i($),Z=y($,"P",{"data-svelte-h":!0}),m(Z)!=="svelte-1ci3syi"&&(Z.textContent=I)},m($,Q){s($,o,Q),s($,r,Q),s($,j,Q),s($,U,Q),J(k,$,Q),s($,v,Q),J(b,$,Q),s($,W,Q),s($,Z,Q),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(v),t(W),t(Z)),T(k,$),T(b,$)}}}function ya(x){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,_="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,v,b,W="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!",Z;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=_,U=a(),w(k.$$.fragment),v=a(),b=d("p"),b.innerHTML=W},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=_),U=i(I),u(k.$$.fragment,I),v=i(I),b=y(I,"P",{"data-svelte-h":!0}),m(b)!=="svelte-8nj8ty"&&(b.innerHTML=W)},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,v,B),s(I,b,B),Z=!0},i(I){Z||(M(k.$$.fragment,I),Z=!0)},o(I){h(k.$$.fragment,I),Z=!1},d(I){I&&(t(o),t(r),t(j),t(U),t(v),t(b)),T(k,I)}}}function Xn(x){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.",_,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:",v,b,W,Z,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,$,Q,H,xe='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:',Ae,E,ae,N,ie,le,Ue,A,Ge,F,Me="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:",Ve,z,oe,te,xl="This will display a widget where you can enter your Hugging Face login credentials.",re,S,_e="If you aren’t working in a notebook, just type the following line in your terminal:",Re,L,se,D,Ze="Once this is done, we can define our <code>TrainingArguments</code>:",ge,G,Ye,q,ve='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>.',Ie,V,_l,pe,ne="Finally, we just pass everything to the <code>Trainer</code> and launch the training:",Ce,R,Xe,P,We="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,at="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:",ke,X,Qe,O,p="This command returns the URL of the commit it just did, if you want to inspect it:",C,Zl,Ll,he,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!",He,Ee,vl="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.",Mt,Ne,Fe,ze,Wl='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.',Dl,de,ht,Se,Bl="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:",ql,ye,Pl,me,us="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:",Ol,we,dt,Le,Al="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:",yt,De,qe,Pe,Gl="Once we have all those objects, we can send them to the <code>accelerator.prepare()</code> method:",Kl,ue,mt,Oe,Ke,el,Vl="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:",wt,ll,Be,tl,Rl="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,Je,lt,Te,ut,sl,Yl="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:",Jt,nl,al,il,Xl="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.",Tt,ol,rl,pl,Ql="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:",tt,fe,ft,cl,Hl="Then we can write the training loop. After defining a progress bar to follow how training goes, the loop has three parts:",st,be,bt="<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>",Ml,El,jt="Here’s the complete code for the training loop:",hl,Nl,nt,je,Ut="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:",dl,yl,ml,Fl,gt="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>.",wl,ul,zl='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!',It;return o=new ce({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}}),E=new g({props:{code:"bW9kZWwuY29uZmlnLm51bV9sYWJlbHM=",highlighted:"model.config.num_labels",wrap:!1}}),N=new g({props:{code:"OQ==",highlighted:'<span class="hljs-number">9</span>',wrap:!1}}),le=new pt({props:{warning:!0,$$slots:{default:[ma]},$$scope:{ctx:x}}}),A=new ce({props:{title:"Fine-tuning the model",local:"fine-tuning-the-model",headingTag:"h3"}}),z=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}}),L=new g({props:{code:"aHVnZ2luZ2ZhY2UtY2xpJTIwbG9naW4=",highlighted:"huggingface-cli login",wrap:!1}}),G=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}}),V=new pt({props:{$$slots:{default:[wa]},$$scope:{ctx:x}}}),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}}),X=new g({props:{code:"dHJhaW5lci5wdXNoX3RvX2h1Yihjb21taXRfbWVzc2FnZSUzRCUyMlRyYWluaW5nJTIwY29tcGxldGUlMjIp",highlighted:'trainer.push_to_hub(commit_message=<span class="hljs-string">&quot;Training complete&quot;</span>)',wrap:!1}}),Zl=new g({props:{code:"J2h0dHBzJTNBJTJGJTJGaHVnZ2luZ2ZhY2UuY28lMkZzZ3VnZ2VyJTJGYmVydC1maW5ldHVuZWQtbmVyJTJGY29tbWl0JTJGMjZhYjIxZTViMTU2OGY5YWZlY2NkYWVkMmQ4NzE1ZjU3MWQ3ODZlZCc=",highlighted:'<span class="hljs-string">&#x27;https://huggingface.co/sgugger/bert-finetuned-ner/commit/26ab21e5b1568f9afeccdaed2d8715f571d786ed&#x27;</span>',wrap:!1}}),Ne=new ce({props:{title:"A custom training loop",local:"a-custom-training-loop",headingTag:"h2"}}),de=new ce({props:{title:"Preparing everything for training",local:"preparing-everything-for-training",headingTag:"h3"}}),ye=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}}),we=new g({props:{code:"bW9kZWwlMjAlM0QlMjBBdXRvTW9kZWxGb3JUb2tlbkNsYXNzaWZpY2F0aW9uLmZyb21fcHJldHJhaW5lZCglMEElMjAlMjAlMjAlMjBtb2RlbF9jaGVja3BvaW50JTJDJTBBJTIwJTIwJTIwJTIwaWQybGFiZWwlM0RpZDJsYWJlbCUyQyUwQSUyMCUyMCUyMCUyMGxhYmVsMmlkJTNEbGFiZWwyaWQlMkMlMEEp",highlighted:`model = AutoModelForTokenClassification.from_pretrained(
    model_checkpoint,
    id2label=id2label,
    label2id=label2id,
)`,wrap:!1}}),De=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}}),ue=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}}),Oe=new pt({props:{$$slots:{default:[ua]},$$scope:{ctx:x}}}),ll=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}}),Je=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}}),Te=new g({props:{code:"J3NndWdnZXIlMkZiZXJ0LWZpbmV0dW5lZC1uZXItYWNjZWxlcmF0ZSc=",highlighted:'<span class="hljs-string">&#x27;sgugger/bert-finetuned-ner-accelerate&#x27;</span>',wrap:!1}}),nl=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}}),ol=new ce({props:{title:"Training loop",local:"training-loop",headingTag:"h3"}}),fe=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}}),Nl=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}}),yl=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,_=a(),U=d("p"),U.innerHTML=k,v=a(),w(b.$$.fragment),W=a(),Z=d("p"),Z.innerHTML=I,B=a(),w($.$$.fragment),Q=a(),H=d("p"),H.innerHTML=xe,Ae=a(),w(E.$$.fragment),ae=a(),w(N.$$.fragment),ie=a(),w(le.$$.fragment),Ue=a(),w(A.$$.fragment),Ge=a(),F=d("p"),F.innerHTML=Me,Ve=a(),w(z.$$.fragment),oe=a(),te=d("p"),te.textContent=xl,re=a(),S=d("p"),S.textContent=_e,Re=a(),w(L.$$.fragment),se=a(),D=d("p"),D.innerHTML=Ze,ge=a(),w(G.$$.fragment),Ye=a(),q=d("p"),q.innerHTML=ve,Ie=a(),w(V.$$.fragment),_l=a(),pe=d("p"),pe.innerHTML=ne,Ce=a(),w(R.$$.fragment),Xe=a(),P=d("p"),P.textContent=We,$e=a(),Y=d("p"),Y.innerHTML=at,ke=a(),w(X.$$.fragment),Qe=a(),O=d("p"),O.textContent=p,C=a(),w(Zl.$$.fragment),Ll=a(),he=d("p"),he.innerHTML=ct,He=a(),Ee=d("p"),Ee.textContent=vl,Mt=a(),w(Ne.$$.fragment),Fe=a(),ze=d("p"),ze.innerHTML=Wl,Dl=a(),w(de.$$.fragment),ht=a(),Se=d("p"),Se.innerHTML=Bl,ql=a(),w(ye.$$.fragment),Pl=a(),me=d("p"),me.textContent=us,Ol=a(),w(we.$$.fragment),dt=a(),Le=d("p"),Le.innerHTML=Al,yt=a(),w(De.$$.fragment),qe=a(),Pe=d("p"),Pe.innerHTML=Gl,Kl=a(),w(ue.$$.fragment),mt=a(),w(Oe.$$.fragment),Ke=a(),el=d("p"),el.innerHTML=Vl,wt=a(),w(ll.$$.fragment),Be=a(),tl=d("p"),tl.innerHTML=Rl,et=a(),w(Je.$$.fragment),lt=a(),w(Te.$$.fragment),ut=a(),sl=d("p"),sl.textContent=Yl,Jt=a(),w(nl.$$.fragment),al=a(),il=d("p"),il.innerHTML=Xl,Tt=a(),w(ol.$$.fragment),rl=a(),pl=d("p"),pl.innerHTML=Ql,tt=a(),w(fe.$$.fragment),ft=a(),cl=d("p"),cl.textContent=Hl,st=a(),be=d("ul"),be.innerHTML=bt,Ml=a(),El=d("p"),El.textContent=jt,hl=a(),w(Nl.$$.fragment),nt=a(),je=d("p"),je.textContent=Ut,dl=a(),w(yl.$$.fragment),ml=a(),Fl=d("p"),Fl.innerHTML=gt,wl=a(),ul=d("p"),ul.innerHTML=zl},l(l){u(o.$$.fragment,l),f=i(l),r=y(l,"P",{"data-svelte-h":!0}),m(r)!=="svelte-1gu7qwi"&&(r.innerHTML=j),_=i(l),U=y(l,"P",{"data-svelte-h":!0}),m(U)!=="svelte-7hlsqs"&&(U.innerHTML=k),v=i(l),u(b.$$.fragment,l),W=i(l),Z=y(l,"P",{"data-svelte-h":!0}),m(Z)!=="svelte-13yu0lk"&&(Z.innerHTML=I),B=i(l),u($.$$.fragment,l),Q=i(l),H=y(l,"P",{"data-svelte-h":!0}),m(H)!=="svelte-matl7x"&&(H.innerHTML=xe),Ae=i(l),u(E.$$.fragment,l),ae=i(l),u(N.$$.fragment,l),ie=i(l),u(le.$$.fragment,l),Ue=i(l),u(A.$$.fragment,l),Ge=i(l),F=y(l,"P",{"data-svelte-h":!0}),m(F)!=="svelte-1sk4x6s"&&(F.innerHTML=Me),Ve=i(l),u(z.$$.fragment,l),oe=i(l),te=y(l,"P",{"data-svelte-h":!0}),m(te)!=="svelte-1ied0vh"&&(te.textContent=xl),re=i(l),S=y(l,"P",{"data-svelte-h":!0}),m(S)!=="svelte-648vlf"&&(S.textContent=_e),Re=i(l),u(L.$$.fragment,l),se=i(l),D=y(l,"P",{"data-svelte-h":!0}),m(D)!=="svelte-h1gi55"&&(D.innerHTML=Ze),ge=i(l),u(G.$$.fragment,l),Ye=i(l),q=y(l,"P",{"data-svelte-h":!0}),m(q)!=="svelte-12dako6"&&(q.innerHTML=ve),Ie=i(l),u(V.$$.fragment,l),_l=i(l),pe=y(l,"P",{"data-svelte-h":!0}),m(pe)!=="svelte-4qeoka"&&(pe.innerHTML=ne),Ce=i(l),u(R.$$.fragment,l),Xe=i(l),P=y(l,"P",{"data-svelte-h":!0}),m(P)!=="svelte-2l4fow"&&(P.textContent=We),$e=i(l),Y=y(l,"P",{"data-svelte-h":!0}),m(Y)!=="svelte-ujrb5b"&&(Y.innerHTML=at),ke=i(l),u(X.$$.fragment,l),Qe=i(l),O=y(l,"P",{"data-svelte-h":!0}),m(O)!=="svelte-mme7gz"&&(O.textContent=p),C=i(l),u(Zl.$$.fragment,l),Ll=i(l),he=y(l,"P",{"data-svelte-h":!0}),m(he)!=="svelte-724xks"&&(he.innerHTML=ct),He=i(l),Ee=y(l,"P",{"data-svelte-h":!0}),m(Ee)!=="svelte-1q5ysr9"&&(Ee.textContent=vl),Mt=i(l),u(Ne.$$.fragment,l),Fe=i(l),ze=y(l,"P",{"data-svelte-h":!0}),m(ze)!=="svelte-1ckbt7o"&&(ze.innerHTML=Wl),Dl=i(l),u(de.$$.fragment,l),ht=i(l),Se=y(l,"P",{"data-svelte-h":!0}),m(Se)!=="svelte-m7xeud"&&(Se.innerHTML=Bl),ql=i(l),u(ye.$$.fragment,l),Pl=i(l),me=y(l,"P",{"data-svelte-h":!0}),m(me)!=="svelte-fdz4rk"&&(me.textContent=us),Ol=i(l),u(we.$$.fragment,l),dt=i(l),Le=y(l,"P",{"data-svelte-h":!0}),m(Le)!=="svelte-172e81w"&&(Le.innerHTML=Al),yt=i(l),u(De.$$.fragment,l),qe=i(l),Pe=y(l,"P",{"data-svelte-h":!0}),m(Pe)!=="svelte-1oqv3so"&&(Pe.innerHTML=Gl),Kl=i(l),u(ue.$$.fragment,l),mt=i(l),u(Oe.$$.fragment,l),Ke=i(l),el=y(l,"P",{"data-svelte-h":!0}),m(el)!=="svelte-1409oc7"&&(el.innerHTML=Vl),wt=i(l),u(ll.$$.fragment,l),Be=i(l),tl=y(l,"P",{"data-svelte-h":!0}),m(tl)!=="svelte-8puci4"&&(tl.innerHTML=Rl),et=i(l),u(Je.$$.fragment,l),lt=i(l),u(Te.$$.fragment,l),ut=i(l),sl=y(l,"P",{"data-svelte-h":!0}),m(sl)!=="svelte-lt5x8r"&&(sl.textContent=Yl),Jt=i(l),u(nl.$$.fragment,l),al=i(l),il=y(l,"P",{"data-svelte-h":!0}),m(il)!=="svelte-1mcbsiy"&&(il.innerHTML=Xl),Tt=i(l),u(ol.$$.fragment,l),rl=i(l),pl=y(l,"P",{"data-svelte-h":!0}),m(pl)!=="svelte-19n1hlu"&&(pl.innerHTML=Ql),tt=i(l),u(fe.$$.fragment,l),ft=i(l),cl=y(l,"P",{"data-svelte-h":!0}),m(cl)!=="svelte-7ueq0n"&&(cl.textContent=Hl),st=i(l),be=y(l,"UL",{"data-svelte-h":!0}),m(be)!=="svelte-1yegd0"&&(be.innerHTML=bt),Ml=i(l),El=y(l,"P",{"data-svelte-h":!0}),m(El)!=="svelte-1yi720t"&&(El.textContent=jt),hl=i(l),u(Nl.$$.fragment,l),nt=i(l),je=y(l,"P",{"data-svelte-h":!0}),m(je)!=="svelte-10bu99i"&&(je.textContent=Ut),dl=i(l),u(yl.$$.fragment,l),ml=i(l),Fl=y(l,"P",{"data-svelte-h":!0}),m(Fl)!=="svelte-est4dk"&&(Fl.innerHTML=gt),wl=i(l),ul=y(l,"P",{"data-svelte-h":!0}),m(ul)!=="svelte-1lhqne3"&&(ul.innerHTML=zl)},m(l,c){J(o,l,c),s(l,f,c),s(l,r,c),s(l,_,c),s(l,U,c),s(l,v,c),J(b,l,c),s(l,W,c),s(l,Z,c),s(l,B,c),J($,l,c),s(l,Q,c),s(l,H,c),s(l,Ae,c),J(E,l,c),s(l,ae,c),J(N,l,c),s(l,ie,c),J(le,l,c),s(l,Ue,c),J(A,l,c),s(l,Ge,c),s(l,F,c),s(l,Ve,c),J(z,l,c),s(l,oe,c),s(l,te,c),s(l,re,c),s(l,S,c),s(l,Re,c),J(L,l,c),s(l,se,c),s(l,D,c),s(l,ge,c),J(G,l,c),s(l,Ye,c),s(l,q,c),s(l,Ie,c),J(V,l,c),s(l,_l,c),s(l,pe,c),s(l,Ce,c),J(R,l,c),s(l,Xe,c),s(l,P,c),s(l,$e,c),s(l,Y,c),s(l,ke,c),J(X,l,c),s(l,Qe,c),s(l,O,c),s(l,C,c),J(Zl,l,c),s(l,Ll,c),s(l,he,c),s(l,He,c),s(l,Ee,c),s(l,Mt,c),J(Ne,l,c),s(l,Fe,c),s(l,ze,c),s(l,Dl,c),J(de,l,c),s(l,ht,c),s(l,Se,c),s(l,ql,c),J(ye,l,c),s(l,Pl,c),s(l,me,c),s(l,Ol,c),J(we,l,c),s(l,dt,c),s(l,Le,c),s(l,yt,c),J(De,l,c),s(l,qe,c),s(l,Pe,c),s(l,Kl,c),J(ue,l,c),s(l,mt,c),J(Oe,l,c),s(l,Ke,c),s(l,el,c),s(l,wt,c),J(ll,l,c),s(l,Be,c),s(l,tl,c),s(l,et,c),J(Je,l,c),s(l,lt,c),J(Te,l,c),s(l,ut,c),s(l,sl,c),s(l,Jt,c),J(nl,l,c),s(l,al,c),s(l,il,c),s(l,Tt,c),J(ol,l,c),s(l,rl,c),s(l,pl,c),s(l,tt,c),J(fe,l,c),s(l,ft,c),s(l,cl,c),s(l,st,c),s(l,be,c),s(l,Ml,c),s(l,El,c),s(l,hl,c),J(Nl,l,c),s(l,nt,c),s(l,je,c),s(l,dl,c),J(yl,l,c),s(l,ml,c),s(l,Fl,c),s(l,wl,c),s(l,ul,c),It=!0},i(l){It||(M(o.$$.fragment,l),M(b.$$.fragment,l),M($.$$.fragment,l),M(E.$$.fragment,l),M(N.$$.fragment,l),M(le.$$.fragment,l),M(A.$$.fragment,l),M(z.$$.fragment,l),M(L.$$.fragment,l),M(G.$$.fragment,l),M(V.$$.fragment,l),M(R.$$.fragment,l),M(X.$$.fragment,l),M(Zl.$$.fragment,l),M(Ne.$$.fragment,l),M(de.$$.fragment,l),M(ye.$$.fragment,l),M(we.$$.fragment,l),M(De.$$.fragment,l),M(ue.$$.fragment,l),M(Oe.$$.fragment,l),M(ll.$$.fragment,l),M(Je.$$.fragment,l),M(Te.$$.fragment,l),M(nl.$$.fragment,l),M(ol.$$.fragment,l),M(fe.$$.fragment,l),M(Nl.$$.fragment,l),M(yl.$$.fragment,l),It=!0)},o(l){h(o.$$.fragment,l),h(b.$$.fragment,l),h($.$$.fragment,l),h(E.$$.fragment,l),h(N.$$.fragment,l),h(le.$$.fragment,l),h(A.$$.fragment,l),h(z.$$.fragment,l),h(L.$$.fragment,l),h(G.$$.fragment,l),h(V.$$.fragment,l),h(R.$$.fragment,l),h(X.$$.fragment,l),h(Zl.$$.fragment,l),h(Ne.$$.fragment,l),h(de.$$.fragment,l),h(ye.$$.fragment,l),h(we.$$.fragment,l),h(De.$$.fragment,l),h(ue.$$.fragment,l),h(Oe.$$.fragment,l),h(ll.$$.fragment,l),h(Je.$$.fragment,l),h(Te.$$.fragment,l),h(nl.$$.fragment,l),h(ol.$$.fragment,l),h(fe.$$.fragment,l),h(Nl.$$.fragment,l),h(yl.$$.fragment,l),It=!1},d(l){l&&(t(f),t(r),t(_),t(U),t(v),t(W),t(Z),t(B),t(Q),t(H),t(Ae),t(ae),t(ie),t(Ue),t(Ge),t(F),t(Ve),t(oe),t(te),t(re),t(S),t(Re),t(se),t(D),t(ge),t(Ye),t(q),t(Ie),t(_l),t(pe),t(Ce),t(Xe),t(P),t($e),t(Y),t(ke),t(Qe),t(O),t(C),t(Ll),t(he),t(He),t(Ee),t(Mt),t(Fe),t(ze),t(Dl),t(ht),t(Se),t(ql),t(Pl),t(me),t(Ol),t(dt),t(Le),t(yt),t(qe),t(Pe),t(Kl),t(mt),t(Ke),t(el),t(wt),t(Be),t(tl),t(et),t(lt),t(ut),t(sl),t(Jt),t(al),t(il),t(Tt),t(rl),t(pl),t(tt),t(ft),t(cl),t(st),t(be),t(Ml),t(El),t(hl),t(nt),t(je),t(dl),t(ml),t(Fl),t(wl),t(ul)),T(o,l),T(b,l),T($,l),T(E,l),T(N,l),T(le,l),T(A,l),T(z,l),T(L,l),T(G,l),T(V,l),T(R,l),T(X,l),T(Zl,l),T(Ne,l),T(de,l),T(ye,l),T(we,l),T(De,l),T(ue,l),T(Oe,l),T(ll,l),T(Je,l),T(Te,l),T(nl,l),T(ol,l),T(fe,l),T(Nl,l),T(yl,l)}}}function ma(x){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:Sl,d(r){r&&t(o)}}}function wa(x){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:Sl,d(r){r&&t(o)}}}function ua(x){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:Sl,d(r){r&&t(o)}}}function Ja(x){let o,f,r,j,_,U,k,v,b,W,Z,I,B,$,Q="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:",H,xe,Ae="<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>",E,ae,N,ie,le="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:",Ue,A,Ge,F,Me,Ve='<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."/>',z,oe,te='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>.',xl,re,S,_e,Re='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.',L,se,D,Ze,ge,G,Ye="To load the CoNLL-2003 dataset, we use the <code>load_dataset()</code> method from the 🤗 Datasets library:",q,ve,Ie,V,_l='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:',pe,ne,Ce,R,Xe,P,We="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).",$e,Y,at="Let’s have a look at the first element of the training set:",ke,X,Qe,O,p,C,Zl="Since we want to perform named entity recognition, we will look at the NER tags:",Ll,he,ct,He,Ee,vl,Mt="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:",Ne,Fe,ze,Wl,Dl,de,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>:",Se,Bl,ql,ye,Pl,me,us='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:',Ol,we,dt="<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>",Le,Al,yt="Now decoding the labels we saw earlier gives us this:",De,qe,Pe,Gl,Kl,ue,mt="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:",Oe,Ke,el,Vl,wt="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.",ll,Be,tl,Rl,et,Je,lt,Te,ut='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.',sl,Yl,Jt="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:",nl,al,il,Xl,Tt='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:',ol,rl,pl,Ql,tt,fe,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>:",cl,Hl,st,be,bt,Ml,El="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.",jt,hl,Nl='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>):',nt,je,Ut,dl,yl,ml,Fl="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):",gt,wl,ul,zl,It="Let’s try it out on our first sentence:",l,c,Ts,Ct,fs,$t,rn="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.",bs,it,js,kt,pn="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:",Us,xt,gs,_t,cn="Note that we haven’t padded our inputs yet; we’ll do that later, when creating the batches with a data collator.",Is,Zt,Mn="We can now apply all that preprocessing in one go on the other splits of our dataset:",Cs,vt,$s,Wt,hn='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>.',ks,Jl,Tl,cs,Bt,xs,At,dn='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,Gt,yn='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:',Zs,fl,bl,Ms,Vt,mn="To test this on a few samples, we can just call it on a list of examples from our tokenized training set:",vs,Rt,Ws,Yt,Bs,Xt,wn="Let’s compare this to the labels for the first and second elements in our dataset:",As,Qt,Gs,Ht,Vs,jl,Ul,hs,ds,Et,Rs,gl,Il,ys,Nt,Ys,Ft,un="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:",Xs,zt,Qs,St,Hs,Lt,Jn="We can then create fake predictions for those by just changing the value at index 2:",Es,Dt,Ns,qt,Tn="Note that the metric takes a list of predictions (not just one) and a list of labels. Here’s the output:",Fs,Pt,zs,Cl,$l,ms,ws,Ot,Ss,Kt,fn="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:",Ls,es,Ds,ls,qs,ts,bn="Great! Our model is working as well as the default one for this pipeline!",Ps,ss,Os,Js,Ks;_=new Pn({props:{fw:x[0]}}),k=new Dn({props:{containerStyle:"float: right; margin-left: 10px; display: inline-flex; position: relative; z-index: 10;"}}),b=new ce({props:{title:"Token classification",local:"token-classification",headingTag:"h1"}});const jn=[Kn,On],ns=[];function Un(e,n){return e[0]==="pt"?0:1}Z=Un(x),I=ns[Z]=jn[Z](x),ae=new Rn({props:{id:"wVHdVlPScxA"}}),re=new ce({props:{title:"Preparing the data",local:"preparing-the-data",headingTag:"h2"}}),se=new pt({props:{$$slots:{default:[ea]},$$scope:{ctx:x}}}),Ze=new ce({props:{title:"The CoNLL-2003 dataset",local:"the-conll-2003-dataset",headingTag:"h3"}}),ve=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}}),ne=new g({props:{code:"cmF3X2RhdGFzZXRz",highlighted:"raw_datasets",wrap:!1}}),R=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}}),X=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}}),O=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}}),he=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}}),He=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}}),Fe=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}}),Wl=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}}),Bl=new g({props:{code:"bGFiZWxfbmFtZXMlMjAlM0QlMjBuZXJfZmVhdHVyZS5mZWF0dXJlLm5hbWVzJTBBbGFiZWxfbmFtZXM=",highlighted:`label_names = ner_feature.feature.names
label_names`,wrap:!1}}),ye=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}}),qe=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}}),Gl=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}}),Ke=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}}),Be=new pt({props:{$$slots:{default:[la]},$$scope:{ctx:x}}}),Rl=new ce({props:{title:"Processing the data",local:"processing-the-data",headingTag:"h3"}}),Je=new Rn({props:{id:"iY2AZYdZAr0"}}),al=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}}),rl=new g({props:{code:"dG9rZW5pemVyLmlzX2Zhc3Q=",highlighted:"tokenizer.is_fast",wrap:!1}}),Ql=new g({props:{code:"VHJ1ZQ==",highlighted:'<span class="hljs-literal">True</span>',wrap:!1}}),Hl=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}}),be=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}}),dl=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}}),wl=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}}),c=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}}),Ct=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:[ta]},$$scope:{ctx:x}}}),xt=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}}),vt=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 gn=[na,sa],as=[];function In(e,n){return e[0]==="pt"?0:1}Jl=In(x),Tl=as[Jl]=gn[Jl](x),Bt=new ce({props:{title:"Data collation",local:"data-collation",headingTag:"h3"}});const Cn=[ia,aa],is=[];function $n(e,n){return e[0]==="pt"?0:1}fl=$n(x),bl=is[fl]=Cn[fl](x),Rt=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}}),Yt=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}}),Qt=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}}),Ht=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 kn=[ra,oa],os=[];function xn(e,n){return e[0]==="pt"?0:1}jl=xn(x),Ul=os[jl]=kn[jl](x);let K=x[0]==="tf"&&Yn(x);Et=new ce({props:{title:"Metrics",local:"metrics",headingTag:"h3"}});const _n=[ha,Ma],rs=[];function Zn(e,n){return e[0]==="pt"?0:1}gl=Zn(x),Il=rs[gl]=_n[gl](x),Nt=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}}),zt=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}}),St=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}}),Dt=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}}),Pt=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 vn=[ya,da],ps=[];function Wn(e,n){return e[0]==="pt"?0:1}Cl=Wn(x),$l=ps[Cl]=vn[Cl](x);let ee=x[0]==="pt"&&Xn(x);return Ot=new ce({props:{title:"Using the fine-tuned model",local:"using-the-fine-tuned-model",headingTag:"h2"}}),es=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}}),ls=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}}),ss=new qn({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(_.$$.fragment),U=a(),w(k.$$.fragment),v=a(),w(b.$$.fragment),W=a(),I.c(),B=a(),$=d("p"),$.textContent=Q,H=a(),xe=d("ul"),xe.innerHTML=Ae,E=a(),w(ae.$$.fragment),N=a(),ie=d("p"),ie.textContent=le,Ue=a(),A=d("iframe"),F=a(),Me=d("a"),Me.innerHTML=Ve,z=a(),oe=d("p"),oe.innerHTML=te,xl=a(),w(re.$$.fragment),S=a(),_e=d("p"),_e.innerHTML=Re,L=a(),w(se.$$.fragment),D=a(),w(Ze.$$.fragment),ge=a(),G=d("p"),G.innerHTML=Ye,q=a(),w(ve.$$.fragment),Ie=a(),V=d("p"),V.innerHTML=_l,pe=a(),w(ne.$$.fragment),Ce=a(),w(R.$$.fragment),Xe=a(),P=d("p"),P.innerHTML=We,$e=a(),Y=d("p"),Y.textContent=at,ke=a(),w(X.$$.fragment),Qe=a(),w(O.$$.fragment),p=a(),C=d("p"),C.textContent=Zl,Ll=a(),w(he.$$.fragment),ct=a(),w(He.$$.fragment),Ee=a(),vl=d("p"),vl.innerHTML=Mt,Ne=a(),w(Fe.$$.fragment),ze=a(),w(Wl.$$.fragment),Dl=a(),de=d("p"),de.innerHTML=ht,Se=a(),w(Bl.$$.fragment),ql=a(),w(ye.$$.fragment),Pl=a(),me=d("p"),me.innerHTML=us,Ol=a(),we=d("ul"),we.innerHTML=dt,Le=a(),Al=d("p"),Al.textContent=yt,De=a(),w(qe.$$.fragment),Pe=a(),w(Gl.$$.fragment),Kl=a(),ue=d("p"),ue.innerHTML=mt,Oe=a(),w(Ke.$$.fragment),el=a(),Vl=d("p"),Vl.innerHTML=wt,ll=a(),w(Be.$$.fragment),tl=a(),w(Rl.$$.fragment),et=a(),w(Je.$$.fragment),lt=a(),Te=d("p"),Te.innerHTML=ut,sl=a(),Yl=d("p"),Yl.innerHTML=Jt,nl=a(),w(al.$$.fragment),il=a(),Xl=d("p"),Xl.innerHTML=Tt,ol=a(),w(rl.$$.fragment),pl=a(),w(Ql.$$.fragment),tt=a(),fe=d("p"),fe.innerHTML=ft,cl=a(),w(Hl.$$.fragment),st=a(),w(be.$$.fragment),bt=a(),Ml=d("p"),Ml.innerHTML=El,jt=a(),hl=d("p"),hl.innerHTML=Nl,nt=a(),w(je.$$.fragment),Ut=a(),w(dl.$$.fragment),yl=a(),ml=d("p"),ml.innerHTML=Fl,gt=a(),w(wl.$$.fragment),ul=a(),zl=d("p"),zl.textContent=It,l=a(),w(c.$$.fragment),Ts=a(),w(Ct.$$.fragment),fs=a(),$t=d("p"),$t.innerHTML=rn,bs=a(),w(it.$$.fragment),js=a(),kt=d("p"),kt.innerHTML=pn,Us=a(),w(xt.$$.fragment),gs=a(),_t=d("p"),_t.textContent=cn,Is=a(),Zt=d("p"),Zt.textContent=Mn,Cs=a(),w(vt.$$.fragment),$s=a(),Wt=d("p"),Wt.innerHTML=hn,ks=a(),Tl.c(),cs=a(),w(Bt.$$.fragment),xs=a(),At=d("p"),At.innerHTML=dn,_s=a(),Gt=d("p"),Gt.innerHTML=yn,Zs=a(),bl.c(),Ms=a(),Vt=d("p"),Vt.textContent=mn,vs=a(),w(Rt.$$.fragment),Ws=a(),w(Yt.$$.fragment),Bs=a(),Xt=d("p"),Xt.textContent=wn,As=a(),w(Qt.$$.fragment),Gs=a(),w(Ht.$$.fragment),Vs=a(),Ul.c(),hs=a(),K&&K.c(),ds=a(),w(Et.$$.fragment),Rs=a(),Il.c(),ys=a(),w(Nt.$$.fragment),Ys=a(),Ft=d("p"),Ft.textContent=un,Xs=a(),w(zt.$$.fragment),Qs=a(),w(St.$$.fragment),Hs=a(),Lt=d("p"),Lt.textContent=Jn,Es=a(),w(Dt.$$.fragment),Ns=a(),qt=d("p"),qt.textContent=Tn,Fs=a(),w(Pt.$$.fragment),zs=a(),$l.c(),ms=a(),ee&&ee.c(),ws=a(),w(Ot.$$.fragment),Ss=a(),Kt=d("p"),Kt.innerHTML=fn,Ls=a(),w(es.$$.fragment),Ds=a(),w(ls.$$.fragment),qs=a(),ts=d("p"),ts.textContent=bn,Ps=a(),w(ss.$$.fragment),Os=a(),Js=d("p"),this.h()},l(e){const n=Sn("svelte-u9bgzb",document.head);o=y(n,"META",{name:!0,content:!0}),n.forEach(t),f=i(e),r=y(e,"P",{}),on(r).forEach(t),j=i(e),u(_.$$.fragment,e),U=i(e),u(k.$$.fragment,e),v=i(e),u(b.$$.fragment,e),W=i(e),I.l(e),B=i(e),$=y(e,"P",{"data-svelte-h":!0}),m($)!=="svelte-149mswf"&&($.textContent=Q),H=i(e),xe=y(e,"UL",{"data-svelte-h":!0}),m(xe)!=="svelte-rebxe7"&&(xe.innerHTML=Ae),E=i(e),u(ae.$$.fragment,e),N=i(e),ie=y(e,"P",{"data-svelte-h":!0}),m(ie)!=="svelte-lkr4ab"&&(ie.textContent=le),Ue=i(e),A=y(e,"IFRAME",{src:!0,frameborder:!0,height:!0,title:!0,class:!0,allow:!0,sandbox:!0}),on(A).forEach(t),F=i(e),Me=y(e,"A",{class:!0,href:!0,"data-svelte-h":!0}),m(Me)!=="svelte-1n7oe9l"&&(Me.innerHTML=Ve),z=i(e),oe=y(e,"P",{"data-svelte-h":!0}),m(oe)!=="svelte-1nxnbu7"&&(oe.innerHTML=te),xl=i(e),u(re.$$.fragment,e),S=i(e),_e=y(e,"P",{"data-svelte-h":!0}),m(_e)!=="svelte-1as9qr9"&&(_e.innerHTML=Re),L=i(e),u(se.$$.fragment,e),D=i(e),u(Ze.$$.fragment,e),ge=i(e),G=y(e,"P",{"data-svelte-h":!0}),m(G)!=="svelte-1h1iv00"&&(G.innerHTML=Ye),q=i(e),u(ve.$$.fragment,e),Ie=i(e),V=y(e,"P",{"data-svelte-h":!0}),m(V)!=="svelte-1hbl8kq"&&(V.innerHTML=_l),pe=i(e),u(ne.$$.fragment,e),Ce=i(e),u(R.$$.fragment,e),Xe=i(e),P=y(e,"P",{"data-svelte-h":!0}),m(P)!=="svelte-80heu6"&&(P.innerHTML=We),$e=i(e),Y=y(e,"P",{"data-svelte-h":!0}),m(Y)!=="svelte-htmsfr"&&(Y.textContent=at),ke=i(e),u(X.$$.fragment,e),Qe=i(e),u(O.$$.fragment,e),p=i(e),C=y(e,"P",{"data-svelte-h":!0}),m(C)!=="svelte-a7wbyy"&&(C.textContent=Zl),Ll=i(e),u(he.$$.fragment,e),ct=i(e),u(He.$$.fragment,e),Ee=i(e),vl=y(e,"P",{"data-svelte-h":!0}),m(vl)!=="svelte-1ammq33"&&(vl.innerHTML=Mt),Ne=i(e),u(Fe.$$.fragment,e),ze=i(e),u(Wl.$$.fragment,e),Dl=i(e),de=y(e,"P",{"data-svelte-h":!0}),m(de)!=="svelte-1rtshpl"&&(de.innerHTML=ht),Se=i(e),u(Bl.$$.fragment,e),ql=i(e),u(ye.$$.fragment,e),Pl=i(e),me=y(e,"P",{"data-svelte-h":!0}),m(me)!=="svelte-3bj295"&&(me.innerHTML=us),Ol=i(e),we=y(e,"UL",{"data-svelte-h":!0}),m(we)!=="svelte-1aahq62"&&(we.innerHTML=dt),Le=i(e),Al=y(e,"P",{"data-svelte-h":!0}),m(Al)!=="svelte-2mh8n6"&&(Al.textContent=yt),De=i(e),u(qe.$$.fragment,e),Pe=i(e),u(Gl.$$.fragment,e),Kl=i(e),ue=y(e,"P",{"data-svelte-h":!0}),m(ue)!=="svelte-1v8gutz"&&(ue.innerHTML=mt),Oe=i(e),u(Ke.$$.fragment,e),el=i(e),Vl=y(e,"P",{"data-svelte-h":!0}),m(Vl)!=="svelte-1r7hfcn"&&(Vl.innerHTML=wt),ll=i(e),u(Be.$$.fragment,e),tl=i(e),u(Rl.$$.fragment,e),et=i(e),u(Je.$$.fragment,e),lt=i(e),Te=y(e,"P",{"data-svelte-h":!0}),m(Te)!=="svelte-j28vlc"&&(Te.innerHTML=ut),sl=i(e),Yl=y(e,"P",{"data-svelte-h":!0}),m(Yl)!=="svelte-pykhfo"&&(Yl.innerHTML=Jt),nl=i(e),u(al.$$.fragment,e),il=i(e),Xl=y(e,"P",{"data-svelte-h":!0}),m(Xl)!=="svelte-rceabt"&&(Xl.innerHTML=Tt),ol=i(e),u(rl.$$.fragment,e),pl=i(e),u(Ql.$$.fragment,e),tt=i(e),fe=y(e,"P",{"data-svelte-h":!0}),m(fe)!=="svelte-qrwwy3"&&(fe.innerHTML=ft),cl=i(e),u(Hl.$$.fragment,e),st=i(e),u(be.$$.fragment,e),bt=i(e),Ml=y(e,"P",{"data-svelte-h":!0}),m(Ml)!=="svelte-13d4q0o"&&(Ml.innerHTML=El),jt=i(e),hl=y(e,"P",{"data-svelte-h":!0}),m(hl)!=="svelte-1fhsp2i"&&(hl.innerHTML=Nl),nt=i(e),u(je.$$.fragment,e),Ut=i(e),u(dl.$$.fragment,e),yl=i(e),ml=y(e,"P",{"data-svelte-h":!0}),m(ml)!=="svelte-deopbg"&&(ml.innerHTML=Fl),gt=i(e),u(wl.$$.fragment,e),ul=i(e),zl=y(e,"P",{"data-svelte-h":!0}),m(zl)!=="svelte-lz79df"&&(zl.textContent=It),l=i(e),u(c.$$.fragment,e),Ts=i(e),u(Ct.$$.fragment,e),fs=i(e),$t=y(e,"P",{"data-svelte-h":!0}),m($t)!=="svelte-1bgynna"&&($t.innerHTML=rn),bs=i(e),u(it.$$.fragment,e),js=i(e),kt=y(e,"P",{"data-svelte-h":!0}),m(kt)!=="svelte-1dnr87f"&&(kt.innerHTML=pn),Us=i(e),u(xt.$$.fragment,e),gs=i(e),_t=y(e,"P",{"data-svelte-h":!0}),m(_t)!=="svelte-198ff0u"&&(_t.textContent=cn),Is=i(e),Zt=y(e,"P",{"data-svelte-h":!0}),m(Zt)!=="svelte-yl3xx9"&&(Zt.textContent=Mn),Cs=i(e),u(vt.$$.fragment,e),$s=i(e),Wt=y(e,"P",{"data-svelte-h":!0}),m(Wt)!=="svelte-1syo56o"&&(Wt.innerHTML=hn),ks=i(e),Tl.l(e),cs=i(e),u(Bt.$$.fragment,e),xs=i(e),At=y(e,"P",{"data-svelte-h":!0}),m(At)!=="svelte-1j0tke5"&&(At.innerHTML=dn),_s=i(e),Gt=y(e,"P",{"data-svelte-h":!0}),m(Gt)!=="svelte-2kw0z8"&&(Gt.innerHTML=yn),Zs=i(e),bl.l(e),Ms=i(e),Vt=y(e,"P",{"data-svelte-h":!0}),m(Vt)!=="svelte-ltlhnk"&&(Vt.textContent=mn),vs=i(e),u(Rt.$$.fragment,e),Ws=i(e),u(Yt.$$.fragment,e),Bs=i(e),Xt=y(e,"P",{"data-svelte-h":!0}),m(Xt)!=="svelte-1hl8zfk"&&(Xt.textContent=wn),As=i(e),u(Qt.$$.fragment,e),Gs=i(e),u(Ht.$$.fragment,e),Vs=i(e),Ul.l(e),hs=i(e),K&&K.l(e),ds=i(e),u(Et.$$.fragment,e),Rs=i(e),Il.l(e),ys=i(e),u(Nt.$$.fragment,e),Ys=i(e),Ft=y(e,"P",{"data-svelte-h":!0}),m(Ft)!=="svelte-1dfdizz"&&(Ft.textContent=un),Xs=i(e),u(zt.$$.fragment,e),Qs=i(e),u(St.$$.fragment,e),Hs=i(e),Lt=y(e,"P",{"data-svelte-h":!0}),m(Lt)!=="svelte-1qhns3f"&&(Lt.textContent=Jn),Es=i(e),u(Dt.$$.fragment,e),Ns=i(e),qt=y(e,"P",{"data-svelte-h":!0}),m(qt)!=="svelte-q6wd42"&&(qt.textContent=Tn),Fs=i(e),u(Pt.$$.fragment,e),zs=i(e),$l.l(e),ms=i(e),ee&&ee.l(e),ws=i(e),u(Ot.$$.fragment,e),Ss=i(e),Kt=y(e,"P",{"data-svelte-h":!0}),m(Kt)!=="svelte-13vy17t"&&(Kt.innerHTML=fn),Ls=i(e),u(es.$$.fragment,e),Ds=i(e),u(ls.$$.fragment,e),qs=i(e),ts=y(e,"P",{"data-svelte-h":!0}),m(ts)!=="svelte-19li140"&&(ts.textContent=bn),Ps=i(e),u(ss.$$.fragment,e),Os=i(e),Js=y(e,"P",{}),on(Js).forEach(t),this.h()},h(){kl(o,"name","hf:doc:metadata"),kl(o,"content",Ta),En(A.src,Ge="https://course-demos-bert-finetuned-ner.hf.space")||kl(A,"src",Ge),kl(A,"frameborder","0"),kl(A,"height","350"),kl(A,"title","Gradio app"),kl(A,"class","block dark:hidden container p-0 flex-grow space-iframe"),kl(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"),kl(A,"sandbox","allow-forms allow-modals allow-popups allow-popups-to-escape-sandbox allow-same-origin allow-scripts allow-downloads"),kl(Me,"class","flex justify-center"),kl(Me,"href","/huggingface-course/bert-finetuned-ner")},m(e,n){Ln(document.head,o),s(e,f,n),s(e,r,n),s(e,j,n),J(_,e,n),s(e,U,n),J(k,e,n),s(e,v,n),J(b,e,n),s(e,W,n),ns[Z].m(e,n),s(e,B,n),s(e,$,n),s(e,H,n),s(e,xe,n),s(e,E,n),J(ae,e,n),s(e,N,n),s(e,ie,n),s(e,Ue,n),s(e,A,n),s(e,F,n),s(e,Me,n),s(e,z,n),s(e,oe,n),s(e,xl,n),J(re,e,n),s(e,S,n),s(e,_e,n),s(e,L,n),J(se,e,n),s(e,D,n),J(Ze,e,n),s(e,ge,n),s(e,G,n),s(e,q,n),J(ve,e,n),s(e,Ie,n),s(e,V,n),s(e,pe,n),J(ne,e,n),s(e,Ce,n),J(R,e,n),s(e,Xe,n),s(e,P,n),s(e,$e,n),s(e,Y,n),s(e,ke,n),J(X,e,n),s(e,Qe,n),J(O,e,n),s(e,p,n),s(e,C,n),s(e,Ll,n),J(he,e,n),s(e,ct,n),J(He,e,n),s(e,Ee,n),s(e,vl,n),s(e,Ne,n),J(Fe,e,n),s(e,ze,n),J(Wl,e,n),s(e,Dl,n),s(e,de,n),s(e,Se,n),J(Bl,e,n),s(e,ql,n),J(ye,e,n),s(e,Pl,n),s(e,me,n),s(e,Ol,n),s(e,we,n),s(e,Le,n),s(e,Al,n),s(e,De,n),J(qe,e,n),s(e,Pe,n),J(Gl,e,n),s(e,Kl,n),s(e,ue,n),s(e,Oe,n),J(Ke,e,n),s(e,el,n),s(e,Vl,n),s(e,ll,n),J(Be,e,n),s(e,tl,n),J(Rl,e,n),s(e,et,n),J(Je,e,n),s(e,lt,n),s(e,Te,n),s(e,sl,n),s(e,Yl,n),s(e,nl,n),J(al,e,n),s(e,il,n),s(e,Xl,n),s(e,ol,n),J(rl,e,n),s(e,pl,n),J(Ql,e,n),s(e,tt,n),s(e,fe,n),s(e,cl,n),J(Hl,e,n),s(e,st,n),J(be,e,n),s(e,bt,n),s(e,Ml,n),s(e,jt,n),s(e,hl,n),s(e,nt,n),J(je,e,n),s(e,Ut,n),J(dl,e,n),s(e,yl,n),s(e,ml,n),s(e,gt,n),J(wl,e,n),s(e,ul,n),s(e,zl,n),s(e,l,n),J(c,e,n),s(e,Ts,n),J(Ct,e,n),s(e,fs,n),s(e,$t,n),s(e,bs,n),J(it,e,n),s(e,js,n),s(e,kt,n),s(e,Us,n),J(xt,e,n),s(e,gs,n),s(e,_t,n),s(e,Is,n),s(e,Zt,n),s(e,Cs,n),J(vt,e,n),s(e,$s,n),s(e,Wt,n),s(e,ks,n),as[Jl].m(e,n),s(e,cs,n),J(Bt,e,n),s(e,xs,n),s(e,At,n),s(e,_s,n),s(e,Gt,n),s(e,Zs,n),is[fl].m(e,n),s(e,Ms,n),s(e,Vt,n),s(e,vs,n),J(Rt,e,n),s(e,Ws,n),J(Yt,e,n),s(e,Bs,n),s(e,Xt,n),s(e,As,n),J(Qt,e,n),s(e,Gs,n),J(Ht,e,n),s(e,Vs,n),os[jl].m(e,n),s(e,hs,n),K&&K.m(e,n),s(e,ds,n),J(Et,e,n),s(e,Rs,n),rs[gl].m(e,n),s(e,ys,n),J(Nt,e,n),s(e,Ys,n),s(e,Ft,n),s(e,Xs,n),J(zt,e,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),s(e,qt,n),s(e,Fs,n),J(Pt,e,n),s(e,zs,n),ps[Cl].m(e,n),s(e,ms,n),ee&&ee.m(e,n),s(e,ws,n),J(Ot,e,n),s(e,Ss,n),s(e,Kt,n),s(e,Ls,n),J(es,e,n),s(e,Ds,n),J(ls,e,n),s(e,qs,n),s(e,ts,n),s(e,Ps,n),J(ss,e,n),s(e,Os,n),s(e,Js,n),Ks=!0},p(e,[n]){const Bn={};n&1&&(Bn.fw=e[0]),_.$set(Bn);let en=Z;Z=Un(e),Z!==en&&(rt(),h(ns[en],1,1,()=>{ns[en]=null}),ot(),I=ns[Z],I||(I=ns[Z]=jn[Z](e),I.c()),M(I,1),I.m(B.parentNode,B));const An={};n&2&&(An.$$scope={dirty:n,ctx:e}),se.$set(An);const Gn={};n&2&&(Gn.$$scope={dirty:n,ctx:e}),Be.$set(Gn);const Vn={};n&2&&(Vn.$$scope={dirty:n,ctx:e}),it.$set(Vn);let ln=Jl;Jl=In(e),Jl!==ln&&(rt(),h(as[ln],1,1,()=>{as[ln]=null}),ot(),Tl=as[Jl],Tl||(Tl=as[Jl]=gn[Jl](e),Tl.c()),M(Tl,1),Tl.m(cs.parentNode,cs));let tn=fl;fl=$n(e),fl!==tn&&(rt(),h(is[tn],1,1,()=>{is[tn]=null}),ot(),bl=is[fl],bl||(bl=is[fl]=Cn[fl](e),bl.c()),M(bl,1),bl.m(Ms.parentNode,Ms));let sn=jl;jl=xn(e),jl!==sn&&(rt(),h(os[sn],1,1,()=>{os[sn]=null}),ot(),Ul=os[jl],Ul||(Ul=os[jl]=kn[jl](e),Ul.c()),M(Ul,1),Ul.m(hs.parentNode,hs)),e[0]==="tf"?K?n&1&&M(K,1):(K=Yn(e),K.c(),M(K,1),K.m(ds.parentNode,ds)):K&&(rt(),h(K,1,1,()=>{K=null}),ot());let nn=gl;gl=Zn(e),gl!==nn&&(rt(),h(rs[nn],1,1,()=>{rs[nn]=null}),ot(),Il=rs[gl],Il||(Il=rs[gl]=_n[gl](e),Il.c()),M(Il,1),Il.m(ys.parentNode,ys));let an=Cl;Cl=Wn(e),Cl!==an&&(rt(),h(ps[an],1,1,()=>{ps[an]=null}),ot(),$l=ps[Cl],$l||($l=ps[Cl]=vn[Cl](e),$l.c()),M($l,1),$l.m(ms.parentNode,ms)),e[0]==="pt"?ee?n&1&&M(ee,1):(ee=Xn(e),ee.c(),M(ee,1),ee.m(ws.parentNode,ws)):ee&&(rt(),h(ee,1,1,()=>{ee=null}),ot())},i(e){Ks||(M(_.$$.fragment,e),M(k.$$.fragment,e),M(b.$$.fragment,e),M(I),M(ae.$$.fragment,e),M(re.$$.fragment,e),M(se.$$.fragment,e),M(Ze.$$.fragment,e),M(ve.$$.fragment,e),M(ne.$$.fragment,e),M(R.$$.fragment,e),M(X.$$.fragment,e),M(O.$$.fragment,e),M(he.$$.fragment,e),M(He.$$.fragment,e),M(Fe.$$.fragment,e),M(Wl.$$.fragment,e),M(Bl.$$.fragment,e),M(ye.$$.fragment,e),M(qe.$$.fragment,e),M(Gl.$$.fragment,e),M(Ke.$$.fragment,e),M(Be.$$.fragment,e),M(Rl.$$.fragment,e),M(Je.$$.fragment,e),M(al.$$.fragment,e),M(rl.$$.fragment,e),M(Ql.$$.fragment,e),M(Hl.$$.fragment,e),M(be.$$.fragment,e),M(je.$$.fragment,e),M(dl.$$.fragment,e),M(wl.$$.fragment,e),M(c.$$.fragment,e),M(Ct.$$.fragment,e),M(it.$$.fragment,e),M(xt.$$.fragment,e),M(vt.$$.fragment,e),M(Tl),M(Bt.$$.fragment,e),M(bl),M(Rt.$$.fragment,e),M(Yt.$$.fragment,e),M(Qt.$$.fragment,e),M(Ht.$$.fragment,e),M(Ul),M(K),M(Et.$$.fragment,e),M(Il),M(Nt.$$.fragment,e),M(zt.$$.fragment,e),M(St.$$.fragment,e),M(Dt.$$.fragment,e),M(Pt.$$.fragment,e),M($l),M(ee),M(Ot.$$.fragment,e),M(es.$$.fragment,e),M(ls.$$.fragment,e),M(ss.$$.fragment,e),Ks=!0)},o(e){h(_.$$.fragment,e),h(k.$$.fragment,e),h(b.$$.fragment,e),h(I),h(ae.$$.fragment,e),h(re.$$.fragment,e),h(se.$$.fragment,e),h(Ze.$$.fragment,e),h(ve.$$.fragment,e),h(ne.$$.fragment,e),h(R.$$.fragment,e),h(X.$$.fragment,e),h(O.$$.fragment,e),h(he.$$.fragment,e),h(He.$$.fragment,e),h(Fe.$$.fragment,e),h(Wl.$$.fragment,e),h(Bl.$$.fragment,e),h(ye.$$.fragment,e),h(qe.$$.fragment,e),h(Gl.$$.fragment,e),h(Ke.$$.fragment,e),h(Be.$$.fragment,e),h(Rl.$$.fragment,e),h(Je.$$.fragment,e),h(al.$$.fragment,e),h(rl.$$.fragment,e),h(Ql.$$.fragment,e),h(Hl.$$.fragment,e),h(be.$$.fragment,e),h(je.$$.fragment,e),h(dl.$$.fragment,e),h(wl.$$.fragment,e),h(c.$$.fragment,e),h(Ct.$$.fragment,e),h(it.$$.fragment,e),h(xt.$$.fragment,e),h(vt.$$.fragment,e),h(Tl),h(Bt.$$.fragment,e),h(bl),h(Rt.$$.fragment,e),h(Yt.$$.fragment,e),h(Qt.$$.fragment,e),h(Ht.$$.fragment,e),h(Ul),h(K),h(Et.$$.fragment,e),h(Il),h(Nt.$$.fragment,e),h(zt.$$.fragment,e),h(St.$$.fragment,e),h(Dt.$$.fragment,e),h(Pt.$$.fragment,e),h($l),h(ee),h(Ot.$$.fragment,e),h(es.$$.fragment,e),h(ls.$$.fragment,e),h(ss.$$.fragment,e),Ks=!1},d(e){e&&(t(f),t(r),t(j),t(U),t(v),t(W),t(B),t($),t(H),t(xe),t(E),t(N),t(ie),t(Ue),t(A),t(F),t(Me),t(z),t(oe),t(xl),t(S),t(_e),t(L),t(D),t(ge),t(G),t(q),t(Ie),t(V),t(pe),t(Ce),t(Xe),t(P),t($e),t(Y),t(ke),t(Qe),t(p),t(C),t(Ll),t(ct),t(Ee),t(vl),t(Ne),t(ze),t(Dl),t(de),t(Se),t(ql),t(Pl),t(me),t(Ol),t(we),t(Le),t(Al),t(De),t(Pe),t(Kl),t(ue),t(Oe),t(el),t(Vl),t(ll),t(tl),t(et),t(lt),t(Te),t(sl),t(Yl),t(nl),t(il),t(Xl),t(ol),t(pl),t(tt),t(fe),t(cl),t(st),t(bt),t(Ml),t(jt),t(hl),t(nt),t(Ut),t(yl),t(ml),t(gt),t(ul),t(zl),t(l),t(Ts),t(fs),t($t),t(bs),t(js),t(kt),t(Us),t(gs),t(_t),t(Is),t(Zt),t(Cs),t($s),t(Wt),t(ks),t(cs),t(xs),t(At),t(_s),t(Gt),t(Zs),t(Ms),t(Vt),t(vs),t(Ws),t(Bs),t(Xt),t(As),t(Gs),t(Vs),t(hs),t(ds),t(Rs),t(ys),t(Ys),t(Ft),t(Xs),t(Qs),t(Hs),t(Lt),t(Es),t(Ns),t(qt),t(Fs),t(zs),t(ms),t(ws),t(Ss),t(Kt),t(Ls),t(Ds),t(qs),t(ts),t(Ps),t(Os),t(Js)),t(o),T(_,e),T(k,e),T(b,e),ns[Z].d(e),T(ae,e),T(re,e),T(se,e),T(Ze,e),T(ve,e),T(ne,e),T(R,e),T(X,e),T(O,e),T(he,e),T(He,e),T(Fe,e),T(Wl,e),T(Bl,e),T(ye,e),T(qe,e),T(Gl,e),T(Ke,e),T(Be,e),T(Rl,e),T(Je,e),T(al,e),T(rl,e),T(Ql,e),T(Hl,e),T(be,e),T(je,e),T(dl,e),T(wl,e),T(c,e),T(Ct,e),T(it,e),T(xt,e),T(vt,e),as[Jl].d(e),T(Bt,e),is[fl].d(e),T(Rt,e),T(Yt,e),T(Qt,e),T(Ht,e),os[jl].d(e),K&&K.d(e),T(Et,e),rs[gl].d(e),T(Nt,e),T(zt,e),T(St,e),T(Dt,e),T(Pt,e),ps[Cl].d(e),ee&&ee.d(e),T(Ot,e),T(es,e),T(ls,e),T(ss,e)}}}const Ta='{"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 fa(x,o,f){let r="pt";return Nn(()=>{const j=new URLSearchParams(window.location.search);f(0,r=j.get("fw")||"pt")}),[r]}class xa extends Fn{constructor(o){super(),zn(this,o,fa,Ja,Hn,{})}}export{xa as component};
