import{s as Vn,f as Rn,o as Xn,n as Fs}from"../chunks/scheduler.37c15a92.js";import{S as Yn,i as Qn,g as T,s as a,r as j,A as En,h as m,f as e,c as p,j as sn,u as w,x as o,k as $s,y as Hn,a as t,v as u,t as y,b as ae,d as J,w as b,p as pe}from"../chunks/index.2bf4358c.js";import{T as Me}from"../chunks/Tip.363c041f.js";import{Y as Wn}from"../chunks/Youtube.1e50a667.js";import{C as I}from"../chunks/CodeBlock.4f5fc1ad.js";import{D as vn}from"../chunks/DocNotebookDropdown.d9dfeb24.js";import{F as Nn}from"../chunks/FrameworkSwitchCourse.8d4d4ab6.js";import{H as ml,E as zn}from"../chunks/EditOnGithub.8916dc7c.js";function Fn(g){let M,U;return M=new vn({props:{classNames:"absolute z-10 right-0 top-0",options:[{label:"Google Colab",value:"https://colab.research.google.com/github/huggingface/notebooks/blob/master/course/chapter7/section2_tf.ipynb"},{label:"Aws Studio",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/master/course/chapter7/section2_tf.ipynb"}]}}),{c(){j(M.$$.fragment)},l(i){w(M.$$.fragment,i)},m(i,f){u(M,i,f),U=!0},i(i){U||(J(M.$$.fragment,i),U=!0)},o(i){y(M.$$.fragment,i),U=!1},d(i){b(M,i)}}}function Sn(g){let M,U;return M=new vn({props:{classNames:"absolute z-10 right-0 top-0",options:[{label:"Google Colab",value:"https://colab.research.google.com/github/huggingface/notebooks/blob/master/course/chapter7/section2_pt.ipynb"},{label:"Aws Studio",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/master/course/chapter7/section2_pt.ipynb"}]}}),{c(){j(M.$$.fragment)},l(i){w(M.$$.fragment,i)},m(i,f){u(M,i,f),U=!0},i(i){U||(J(M.$$.fragment,i),U=!0)},o(i){y(M.$$.fragment,i),U=!1},d(i){b(M,i)}}}function Ln(g){let M,U='💡 只要您的数据集由带有相应标签的分割成单词并的文本组成，您就能够将这里描述的数据处理过程应用到您自己的数据集。如果需要复习如何在.Dataset中加载自定义数据，请参阅<a href="/course/chapter5">Chapter 5</a>。';return{c(){M=T("p"),M.innerHTML=U},l(i){M=m(i,"P",{"data-svelte-h":!0}),o(M)!=="svelte-1xsbhx"&&(M.innerHTML=U)},m(i,f){t(i,M,f)},p:Fs,d(i){i&&e(M)}}}function Dn(g){let M,U="✏️ <strong>轮到你了！</strong> 使用 POS 或chunking标签识别同一个句子。";return{c(){M=T("p"),M.innerHTML=U},l(i){M=m(i,"P",{"data-svelte-h":!0}),o(M)!=="svelte-ejqqoj"&&(M.innerHTML=U)},m(i,f){t(i,M,f)},p:Fs,d(i){i&&e(M)}}}function qn(g){let M,U="✏️ <strong>轮到你了！</strong> 一些研究人员更喜欢每个词只归属一个标签, 并分配 <code>-100</code> 给定词中的其他子标记。这是为了避免分解成大量子标记的长词对损失造成严重影响。按照此规则更改前一个函数使标签与输入id对齐。";return{c(){M=T("p"),M.innerHTML=U},l(i){M=m(i,"P",{"data-svelte-h":!0}),o(M)!=="svelte-12qba3p"&&(M.innerHTML=U)},m(i,f){t(i,M,f)},p:Fs,d(i){i&&e(M)}}}function Pn(g){let M,U,i,f="使用Keras的实际代码将与之前非常相似;唯一的变化是将数据整理成批处理的方式和指标计算函数。",x;return M=new ml({props:{title:"使用 Keras 微调模型",local:"使用 Keras 微调模型",headingTag:"h2"}}),{c(){j(M.$$.fragment),U=a(),i=T("p"),i.textContent=f},l(h){w(M.$$.fragment,h),U=p(h),i=m(h,"P",{"data-svelte-h":!0}),o(i)!=="svelte-m18t4l"&&(i.textContent=f)},m(h,k){u(M,h,k),t(h,U,k),t(h,i,k),x=!0},i(h){x||(J(M.$$.fragment,h),x=!0)},o(h){y(M.$$.fragment,h),x=!1},d(h){h&&(e(U),e(i)),b(M,h)}}}function Kn(g){let M,U,i,f="使用 <code>Trainer</code> 的实际代码会和以前一样；唯一的变化是数据整理成时批处理的方式和度量计算函数。",x;return M=new ml({props:{title:"使用 Trainer API 微调模型",local:"使用 Trainer API 微调模型",headingTag:"h2"}}),{c(){j(M.$$.fragment),U=a(),i=T("p"),i.innerHTML=f},l(h){w(M.$$.fragment,h),U=p(h),i=m(h,"P",{"data-svelte-h":!0}),o(i)!=="svelte-157kpwt"&&(i.innerHTML=f)},m(h,k){u(M,h,k),t(h,U,k),t(h,i,k),x=!0},i(h){x||(J(M.$$.fragment,h),x=!0)},o(h){y(M.$$.fragment,h),x=!1},d(h){h&&(e(U),e(i)),b(M,h)}}}function On(g){let M,U;return M=new I({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(){j(M.$$.fragment)},l(i){w(M.$$.fragment,i)},m(i,f){u(M,i,f),U=!0},i(i){U||(J(M.$$.fragment,i),U=!0)},o(i){y(M.$$.fragment,i),U=!1},d(i){b(M,i)}}}function la(g){let M,U;return M=new I({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(){j(M.$$.fragment)},l(i){w(M.$$.fragment,i)},m(i,f){u(M,i,f),U=!0},i(i){U||(J(M.$$.fragment,i),U=!0)},o(i){y(M.$$.fragment,i),U=!1},d(i){b(M,i)}}}function sa(g){let M,U="我们的数据整理器已准备就绪！ 现在让我们使用它通过 <code>to_tf_dataset()</code> 方法制作一个 <code>tf.data.Dataset</code>。 您还可以使用 model.prepare_tf_dataset() 来使用更少的样板代码来执行此操作——您将在本章的其他部分中看到这一点。",i,f,x,h,k="Next stop: the model itself.",W;return f=new I({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(){M=T("p"),M.innerHTML=U,i=a(),j(f.$$.fragment),x=a(),h=T("p"),h.textContent=k},l(d){M=m(d,"P",{"data-svelte-h":!0}),o(M)!=="svelte-51vwxx"&&(M.innerHTML=U),i=p(d),w(f.$$.fragment,d),x=p(d),h=m(d,"P",{"data-svelte-h":!0}),o(h)!=="svelte-68qel6"&&(h.textContent=k)},m(d,Z){t(d,M,Z),t(d,i,Z),u(f,d,Z),t(d,x,Z),t(d,h,Z),W=!0},i(d){W||(J(f.$$.fragment,d),W=!0)},o(d){y(f.$$.fragment,d),W=!1},d(d){d&&(e(M),e(i),e(x),e(h)),b(f,d)}}}function ea(g){let M,U="正如我们所看到的，第二组标签的长度已经使用 <code>-100</code> 填充到与第一组标签相同。";return{c(){M=T("p"),M.innerHTML=U},l(i){M=m(i,"P",{"data-svelte-h":!0}),o(M)!=="svelte-xyzzqv"&&(M.innerHTML=U)},m(i,f){t(i,M,f)},i:Fs,o:Fs,d(i){i&&e(M)}}}function An(g){let M,U,i,f="由于我们正在研究Token分类问题，因此我们将使用 <code>AutoModelForTokenClassification</code> 类。定义这个模型时要记住的主要事情是传递一些关于我们的标签数量的信息。执行此操作的最简单方法是将该数字传递给 <code>num_labels</code> 参数，但是如果我们想要一个很好的推理小部件，就像我们在本节开头看到的那样，最好设置正确的标签对应关系。",x,h,k="它们应该由两个字典设置， <code>id2label</code> 和 <code>label2id</code> ，其中包含从 ID 到标签的映射，反之亦然：",W,d,Z,B,C="现在我们可以将它们传递给 <code>AutoModelForTokenClassification.from_pretrained()</code> 方法，它们将在模型的配置中设置，然后保存并上传到Hub：",A,_,v,D,ks='就像我们在<a href="/course/chapter3">第三章</a>,定义我们的 <code>AutoModelForSequenceClassification</code> ，创建模型会发出警告，提示一些权重未被使用（来自预训练头的权重）和一些其他权重被随机初始化（来自新Token分类头的权重），我们将要训练这个模型。我们将在一分钟内完成，但首先让我们仔细检查我们的模型是否具有正确数量的标签：',tl,X,nl,q,Al,G,vl,Y,F,P,_s="现在，我们已准备好训练模型了！不过，我们首先要做两件事：应该登录到Hugging Face并定义我们的训练超参数。如果你在notebook上工作，有一个便利功能可以帮助你做到这一点：",al,K,Gl,V,gs="这将显示一个小部件，您可以在其中输入您的 Hugging Face 账号和密码。",pl,O,Vl="如果您不是在notebook上工作，只需在终端中输入以下行：",R,ol,Ml,Q,jl="登录后，我们可以准备编译模型所需的一切。🤗 Transformers提供了一个方便的<code>create_optimizer()</code> 函数，该函数将为您提供一个<code>AdamW</code>优化器，其中包含适当的权重衰减和学习速率衰减设置，与内置的<code>Adam</code>优化器相似，这两者都将提高模型的性能：",wl,ul,il,E,bl="还要注意，我们不为<code>compile()</code>提供<code>loss</code>参数。这是因为模型实际上可以在内部计算损失 - 如果您编译时没有损失并在输入字典中提供标签（就像我们在数据集中所做的那样），那么模型将使用该内部损失进行训练，这将适用于您选择的任务和模型类型。",dl,Ul,fl="接下来，我们定义一个<code>PushToHubCallback</code>，以便在训练期间将模型上传到 Hub，并使用该回调来拟合模型：",rl,H,cl,ll,xs='您之前已经看过其中的大部分内容：我们设置了一些超参数（例如学习率、要训练的 epoch 数和权重衰减），然后我们指定 <code>push_to_hub=True</code> 表明我们想要保存模型并在每个时期结束时对其进行评估，并且我们想要将我们的结果上传到模型中心。请注意，可以使用hub_model_id参数指定要推送到的存储库的名称(特别是，必须使用这个参数来推送到一个组织)。例如，当我们将模型推送到<a href="https://huggingface.co/huggingface-course" rel="nofollow"><code>huggingface-course</code> organization</a>, 我们添加了 <code>hub_model_id=huggingface-course/bert-finetuned-ner</code> 到 <code>TrainingArguments</code> .默认情况下，使用的存储库将在您的命名空间中并以您设置的输出目录命名，因此在我们的例子中它将是 <code>sgugger/bert-finetuned-ner</code> .',Jl,sl,Rl,N,hl="请注意，当训练发生时，每次保存模型时（这里是每个epooch），它都会在后台上传到 Hub。这样，如有必要，您将能够在另一台机器上继续您的训练。",yl,el,Xl="在此阶段，您可以使用模型中心上的推理小组件来测试模型并与朋友共享。您已经成功微调了令牌分类任务的模型 - 恭喜！但是，我们的模型到底有多好呢？我们应该评估一些指标来找出答案。",z;return M=new ml({props:{title:"定义模型",local:"定义模型",headingTag:"h3"}}),d=new I({props:{code:"aWQybGFiZWwlMjAlM0QlMjAlN0JzdHIoaSklM0ElMjBsYWJlbCUyMGZvciUyMGklMkMlMjBsYWJlbCUyMGluJTIwZW51bWVyYXRlKGxhYmVsX25hbWVzKSU3RCUwQWxhYmVsMmlkJTIwJTNEJTIwJTdCdiUzQSUyMGslMjBmb3IlMjBrJTJDJTIwdiUyMGluJTIwaWQybGFiZWwuaXRlbXMoKSU3RA==",highlighted:`id2label = {<span class="hljs-built_in">str</span>(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 I({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMFRGQXV0b01vZGVsRm9yVG9rZW5DbGFzc2lmaWNhdGlvbiUwQSUwQW1vZGVsJTIwJTNEJTIwVEZBdXRvTW9kZWxGb3JUb2tlbkNsYXNzaWZpY2F0aW9uLmZyb21fcHJldHJhaW5lZCglMEElMjAlMjAlMjAlMjBtb2RlbF9jaGVja3BvaW50JTJDJTBBJTIwJTIwJTIwJTIwaWQybGFiZWwlM0RpZDJsYWJlbCUyQyUwQSUyMCUyMCUyMCUyMGxhYmVsMmlkJTNEbGFiZWwyaWQlMkMlMEEp",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> TFAutoModelForTokenClassification

model = TFAutoModelForTokenClassification.from_pretrained(
    model_checkpoint,
    id2label=id2label,
    label2id=label2id,
)`,wrap:!1}}),X=new I({props:{code:"bW9kZWwuY29uZmlnLm51bV9sYWJlbHM=",highlighted:"model.config.num_labels",wrap:!1}}),q=new I({props:{code:"OQ==",highlighted:'<span class="hljs-number">9</span>',wrap:!1}}),G=new Me({props:{warning:!0,$$slots:{default:[ta]},$$scope:{ctx:g}}}),Y=new ml({props:{title:"微调模型",local:"微调模型",headingTag:"h3"}}),K=new I({props:{code:"ZnJvbSUyMGh1Z2dpbmdmYWNlX2h1YiUyMGltcG9ydCUyMG5vdGVib29rX2xvZ2luJTBBJTBBbm90ZWJvb2tfbG9naW4oKQ==",highlighted:`<span class="hljs-keyword">from</span> huggingface_hub <span class="hljs-keyword">import</span> notebook_login

notebook_login()`,wrap:!1}}),ol=new I({props:{code:"aHVnZ2luZ2ZhY2UtY2xpJTIwbG9naW4=",highlighted:"huggingface-cli login",wrap:!1}}),ul=new I({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMGNyZWF0ZV9vcHRpbWl6ZXIlMEFpbXBvcnQlMjB0ZW5zb3JmbG93JTIwYXMlMjB0ZiUwQSUwQSUyMyUyMFRyYWluJTIwaW4lMjBtaXhlZC1wcmVjaXNpb24lMjBmbG9hdDE2JTBBdGYua2VyYXMubWl4ZWRfcHJlY2lzaW9uLnNldF9nbG9iYWxfcG9saWN5KCUyMm1peGVkX2Zsb2F0MTYlMjIpJTBBJTBBJTIzJTIwVGhlJTIwbnVtYmVyJTIwb2YlMjB0cmFpbmluZyUyMHN0ZXBzJTIwaXMlMjB0aGUlMjBudW1iZXIlMjBvZiUyMHNhbXBsZXMlMjBpbiUyMHRoZSUyMGRhdGFzZXQlMkMlMjBkaXZpZGVkJTIwYnklMjB0aGUlMjBiYXRjaCUyMHNpemUlMjB0aGVuJTIwbXVsdGlwbGllZCUwQSUyMyUyMGJ5JTIwdGhlJTIwdG90YWwlMjBudW1iZXIlMjBvZiUyMGVwb2Nocy4lMjBOb3RlJTIwdGhhdCUyMHRoZSUyMHRmX3RyYWluX2RhdGFzZXQlMjBoZXJlJTIwaXMlMjBhJTIwYmF0Y2hlZCUyMHRmLmRhdGEuRGF0YXNldCUyQyUwQSUyMyUyMG5vdCUyMHRoZSUyMG9yaWdpbmFsJTIwSHVnZ2luZyUyMEZhY2UlMjBEYXRhc2V0JTJDJTIwc28lMjBpdHMlMjBsZW4oKSUyMGlzJTIwYWxyZWFkeSUyMG51bV9zYW1wbGVzJTIwJTJGJTJGJTIwYmF0Y2hfc2l6ZS4lMEFudW1fZXBvY2hzJTIwJTNEJTIwMyUwQW51bV90cmFpbl9zdGVwcyUyMCUzRCUyMGxlbih0Zl90cmFpbl9kYXRhc2V0KSUyMColMjBudW1fZXBvY2hzJTBBJTBBb3B0aW1pemVyJTJDJTIwc2NoZWR1bGUlMjAlM0QlMjBjcmVhdGVfb3B0aW1pemVyKCUwQSUyMCUyMCUyMCUyMGluaXRfbHIlM0QyZS01JTJDJTBBJTIwJTIwJTIwJTIwbnVtX3dhcm11cF9zdGVwcyUzRDAlMkMlMEElMjAlMjAlMjAlMjBudW1fdHJhaW5fc3RlcHMlM0RudW1fdHJhaW5fc3RlcHMlMkMlMEElMjAlMjAlMjAlMjB3ZWlnaHRfZGVjYXlfcmF0ZSUzRDAuMDElMkMlMEEpJTBBbW9kZWwuY29tcGlsZShvcHRpbWl6ZXIlM0RvcHRpbWl6ZXIp",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>
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}}),H=new I({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}}),sl=new Me({props:{$$slots:{default:[na]},$$scope:{ctx:g}}}),{c(){j(M.$$.fragment),U=a(),i=T("p"),i.innerHTML=f,x=a(),h=T("p"),h.innerHTML=k,W=a(),j(d.$$.fragment),Z=a(),B=T("p"),B.innerHTML=C,A=a(),j(_.$$.fragment),v=a(),D=T("p"),D.innerHTML=ks,tl=a(),j(X.$$.fragment),nl=a(),j(q.$$.fragment),Al=a(),j(G.$$.fragment),vl=a(),j(Y.$$.fragment),F=a(),P=T("p"),P.textContent=_s,al=a(),j(K.$$.fragment),Gl=a(),V=T("p"),V.textContent=gs,pl=a(),O=T("p"),O.textContent=Vl,R=a(),j(ol.$$.fragment),Ml=a(),Q=T("p"),Q.innerHTML=jl,wl=a(),j(ul.$$.fragment),il=a(),E=T("p"),E.innerHTML=bl,dl=a(),Ul=T("p"),Ul.innerHTML=fl,rl=a(),j(H.$$.fragment),cl=a(),ll=T("p"),ll.innerHTML=xs,Jl=a(),j(sl.$$.fragment),Rl=a(),N=T("p"),N.textContent=hl,yl=a(),el=T("p"),el.textContent=Xl},l(r){w(M.$$.fragment,r),U=p(r),i=m(r,"P",{"data-svelte-h":!0}),o(i)!=="svelte-snq4oh"&&(i.innerHTML=f),x=p(r),h=m(r,"P",{"data-svelte-h":!0}),o(h)!=="svelte-hi5orh"&&(h.innerHTML=k),W=p(r),w(d.$$.fragment,r),Z=p(r),B=m(r,"P",{"data-svelte-h":!0}),o(B)!=="svelte-ty8bpp"&&(B.innerHTML=C),A=p(r),w(_.$$.fragment,r),v=p(r),D=m(r,"P",{"data-svelte-h":!0}),o(D)!=="svelte-1tztiyt"&&(D.innerHTML=ks),tl=p(r),w(X.$$.fragment,r),nl=p(r),w(q.$$.fragment,r),Al=p(r),w(G.$$.fragment,r),vl=p(r),w(Y.$$.fragment,r),F=p(r),P=m(r,"P",{"data-svelte-h":!0}),o(P)!=="svelte-1iias0p"&&(P.textContent=_s),al=p(r),w(K.$$.fragment,r),Gl=p(r),V=m(r,"P",{"data-svelte-h":!0}),o(V)!=="svelte-o6pmjh"&&(V.textContent=gs),pl=p(r),O=m(r,"P",{"data-svelte-h":!0}),o(O)!=="svelte-19efumu"&&(O.textContent=Vl),R=p(r),w(ol.$$.fragment,r),Ml=p(r),Q=m(r,"P",{"data-svelte-h":!0}),o(Q)!=="svelte-1i5mapt"&&(Q.innerHTML=jl),wl=p(r),w(ul.$$.fragment,r),il=p(r),E=m(r,"P",{"data-svelte-h":!0}),o(E)!=="svelte-1rw32sl"&&(E.innerHTML=bl),dl=p(r),Ul=m(r,"P",{"data-svelte-h":!0}),o(Ul)!=="svelte-5me0l6"&&(Ul.innerHTML=fl),rl=p(r),w(H.$$.fragment,r),cl=p(r),ll=m(r,"P",{"data-svelte-h":!0}),o(ll)!=="svelte-4rjcvs"&&(ll.innerHTML=xs),Jl=p(r),w(sl.$$.fragment,r),Rl=p(r),N=m(r,"P",{"data-svelte-h":!0}),o(N)!=="svelte-17b3wn4"&&(N.textContent=hl),yl=p(r),el=m(r,"P",{"data-svelte-h":!0}),o(el)!=="svelte-128cul"&&(el.textContent=Xl)},m(r,$){u(M,r,$),t(r,U,$),t(r,i,$),t(r,x,$),t(r,h,$),t(r,W,$),u(d,r,$),t(r,Z,$),t(r,B,$),t(r,A,$),u(_,r,$),t(r,v,$),t(r,D,$),t(r,tl,$),u(X,r,$),t(r,nl,$),u(q,r,$),t(r,Al,$),u(G,r,$),t(r,vl,$),u(Y,r,$),t(r,F,$),t(r,P,$),t(r,al,$),u(K,r,$),t(r,Gl,$),t(r,V,$),t(r,pl,$),t(r,O,$),t(r,R,$),u(ol,r,$),t(r,Ml,$),t(r,Q,$),t(r,wl,$),u(ul,r,$),t(r,il,$),t(r,E,$),t(r,dl,$),t(r,Ul,$),t(r,rl,$),u(H,r,$),t(r,cl,$),t(r,ll,$),t(r,Jl,$),u(sl,r,$),t(r,Rl,$),t(r,N,$),t(r,yl,$),t(r,el,$),z=!0},i(r){z||(J(M.$$.fragment,r),J(d.$$.fragment,r),J(_.$$.fragment,r),J(X.$$.fragment,r),J(q.$$.fragment,r),J(G.$$.fragment,r),J(Y.$$.fragment,r),J(K.$$.fragment,r),J(ol.$$.fragment,r),J(ul.$$.fragment,r),J(H.$$.fragment,r),J(sl.$$.fragment,r),z=!0)},o(r){y(M.$$.fragment,r),y(d.$$.fragment,r),y(_.$$.fragment,r),y(X.$$.fragment,r),y(q.$$.fragment,r),y(G.$$.fragment,r),y(Y.$$.fragment,r),y(K.$$.fragment,r),y(ol.$$.fragment,r),y(ul.$$.fragment,r),y(H.$$.fragment,r),y(sl.$$.fragment,r),z=!1},d(r){r&&(e(U),e(i),e(x),e(h),e(W),e(Z),e(B),e(A),e(v),e(D),e(tl),e(nl),e(Al),e(vl),e(F),e(P),e(al),e(Gl),e(V),e(pl),e(O),e(R),e(Ml),e(Q),e(wl),e(il),e(E),e(dl),e(Ul),e(rl),e(cl),e(ll),e(Jl),e(Rl),e(N),e(yl),e(el)),b(M,r),b(d,r),b(_,r),b(X,r),b(q,r),b(G,r),b(Y,r),b(K,r),b(ol,r),b(ul,r),b(H,r),b(sl,r)}}}function ta(g){let M,U="⚠️ 如果您的模型标签数量错误，则在稍后调用 <code>model.fit()</code> 时将收到一个模糊的错误。调试起来可能很烦人，因此请确保执行此检查以确认您具有预期的标签数。";return{c(){M=T("p"),M.innerHTML=U},l(i){M=m(i,"P",{"data-svelte-h":!0}),o(M)!=="svelte-zqw73w"&&(M.innerHTML=U)},m(i,f){t(i,M,f)},p:Fs,d(i){i&&e(M)}}}function na(g){let M,U="💡 如果您正在使用的输出目录已经存在，那么输出目录必须是从同一个存储库clone下来的。如果不是，您将在声明 <code>model.fit()</code> 时遇到错误，并且需要设置一个新名称。";return{c(){M=T("p"),M.innerHTML=U},l(i){M=m(i,"P",{"data-svelte-h":!0}),o(M)!=="svelte-186tmam"&&(M.innerHTML=U)},m(i,f){t(i,M,f)},p:Fs,d(i){i&&e(M)}}}function aa(g){let M,U='用于评估Token分类预测的传统框架是 <a href="https://github.com/chakki-works/seqeval" rel="nofollow"><em>seqeval</em></a>. 要使用此指标，我们首先需要安装seqeval库：',i,f,x,h,k='然后我们可以通过<code>evaluate.load()</code> 函数加载它就像我们在<a href="/course/chapter3">第三章</a>做的那样：',W;return f=new I({props:{code:"IXBpcCUyMGluc3RhbGwlMjBzZXFldmFs",highlighted:"!pip install seqeval",wrap:!1}}),{c(){M=T("p"),M.innerHTML=U,i=a(),j(f.$$.fragment),x=a(),h=T("p"),h.innerHTML=k},l(d){M=m(d,"P",{"data-svelte-h":!0}),o(M)!=="svelte-qb3v8g"&&(M.innerHTML=U),i=p(d),w(f.$$.fragment,d),x=p(d),h=m(d,"P",{"data-svelte-h":!0}),o(h)!=="svelte-12n3n9s"&&(h.innerHTML=k)},m(d,Z){t(d,M,Z),t(d,i,Z),u(f,d,Z),t(d,x,Z),t(d,h,Z),W=!0},i(d){W||(J(f.$$.fragment,d),W=!0)},o(d){y(f.$$.fragment,d),W=!1},d(d){d&&(e(M),e(i),e(x),e(h)),b(f,d)}}}function pa(g){let M,U="为了让 <code>Trainer</code> 在每个epoch计算一个度量，我们需要定义一个 <code>compute_metrics()</code> 函数，该函数接受预测和标签数组，并返回一个包含度量名称和值的字典",i,f,x='用于评估Token分类预测的传统框架是 <a href="https://github.com/chakki-works/seqeval" rel="nofollow"><em>seqeval</em></a>. 要使用此指标，我们首先需要安装seqeval库：',h,k,W,d,Z='然后我们可以通过加载它 <code>evaluate.load()</code> 函数就像我们在<a href="/course/chapter3">第三章</a>做的那样：',B;return k=new I({props:{code:"IXBpcCUyMGluc3RhbGwlMjBzZXFldmFs",highlighted:"!pip install seqeval",wrap:!1}}),{c(){M=T("p"),M.innerHTML=U,i=a(),f=T("p"),f.innerHTML=x,h=a(),j(k.$$.fragment),W=a(),d=T("p"),d.innerHTML=Z},l(C){M=m(C,"P",{"data-svelte-h":!0}),o(M)!=="svelte-1i4zfhu"&&(M.innerHTML=U),i=p(C),f=m(C,"P",{"data-svelte-h":!0}),o(f)!=="svelte-qb3v8g"&&(f.innerHTML=x),h=p(C),w(k.$$.fragment,C),W=p(C),d=m(C,"P",{"data-svelte-h":!0}),o(d)!=="svelte-1s4c174"&&(d.innerHTML=Z)},m(C,A){t(C,M,A),t(C,i,A),t(C,f,A),t(C,h,A),u(k,C,A),t(C,W,A),t(C,d,A),B=!0},i(C){B||(J(k.$$.fragment,C),B=!0)},o(C){y(k.$$.fragment,C),B=!1},d(C){C&&(e(M),e(i),e(f),e(h),e(W),e(d)),b(k,C)}}}function Ma(g){let M,U="它返回很多信息！我们获得每个单独实体以及整体的准确率、召回率和 F1 分数。对于我们的度量计算，我们将只保留总分，但可以随意调整 <code>compute_metrics()</code> 函数返回您想要查看的所有指标。",i,f,x="这<code>compute_metrics()</code> 函数首先采用 logits 的 argmax 将它们转换为预测（像往常一样，logits 和概率的顺序相同，因此我们不需要应用 softmax）。然后我们必须将标签和预测从整数转换为字符串。我们删除标签为 <code>-100</code> 所有值 ，然后将结果传递给 <code>metric.compute()</code> 方法：",h,k,W,d,Z,B,C="与我们的模型相比，您的模型做得如何？如果您获得类似的数字，那么您的训练就是成功的！",A;return k=new I({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}}),d=new I({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(){M=T("p"),M.innerHTML=U,i=a(),f=T("p"),f.innerHTML=x,h=a(),j(k.$$.fragment),W=a(),j(d.$$.fragment),Z=a(),B=T("p"),B.textContent=C},l(_){M=m(_,"P",{"data-svelte-h":!0}),o(M)!=="svelte-1sh394l"&&(M.innerHTML=U),i=p(_),f=m(_,"P",{"data-svelte-h":!0}),o(f)!=="svelte-1opwpmv"&&(f.innerHTML=x),h=p(_),w(k.$$.fragment,_),W=p(_),w(d.$$.fragment,_),Z=p(_),B=m(_,"P",{"data-svelte-h":!0}),o(B)!=="svelte-19yoxar"&&(B.textContent=C)},m(_,v){t(_,M,v),t(_,i,v),t(_,f,v),t(_,h,v),u(k,_,v),t(_,W,v),u(d,_,v),t(_,Z,v),t(_,B,v),A=!0},i(_){A||(J(k.$$.fragment,_),J(d.$$.fragment,_),A=!0)},o(_){y(k.$$.fragment,_),y(d.$$.fragment,_),A=!1},d(_){_&&(e(M),e(i),e(f),e(h),e(W),e(Z),e(B)),b(k,_),b(d,_)}}}function ia(g){let M,U="它返回很多信息！我们获得每个单独实体以及整体的准确率、召回率和 F1 分数。对于我们的度量计算，我们将只保留总分，但可以随意调整 <code>compute_metrics()</code> 函数返回您想要查看的所有指标。",i,f,x="这<code>compute_metrics()</code> 函数首先采用 logits 的 argmax 将它们转换为预测（像往常一样，logits 和概率的顺序相同，因此我们不需要应用 softmax）。然后我们必须将标签和预测从整数转换为字符串。我们删除标签为 <code>-100</code> 所有值 ，然后将结果传递给 <code>metric.compute()</code> 方法：",h,k,W,d,Z="现在已经完成了，我们几乎准备好定义我们的 <code>Trainer</code> .我们只需要一个 <code>model</code> 微调！",B;return k=new I({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(){M=T("p"),M.innerHTML=U,i=a(),f=T("p"),f.innerHTML=x,h=a(),j(k.$$.fragment),W=a(),d=T("p"),d.innerHTML=Z},l(C){M=m(C,"P",{"data-svelte-h":!0}),o(M)!=="svelte-1sh394l"&&(M.innerHTML=U),i=p(C),f=m(C,"P",{"data-svelte-h":!0}),o(f)!=="svelte-1opwpmv"&&(f.innerHTML=x),h=p(C),w(k.$$.fragment,C),W=p(C),d=m(C,"P",{"data-svelte-h":!0}),o(d)!=="svelte-11u0o90"&&(d.innerHTML=Z)},m(C,A){t(C,M,A),t(C,i,A),t(C,f,A),t(C,h,A),u(k,C,A),t(C,W,A),t(C,d,A),B=!0},i(C){B||(J(k.$$.fragment,C),B=!0)},o(C){y(k.$$.fragment,C),B=!1},d(C){C&&(e(M),e(i),e(f),e(h),e(W),e(d)),b(k,C)}}}function Gn(g){let M,U,i,f="由于我们正在研究Token分类问题，因此我们将使用 <code>AutoModelForTokenClassification</code> 类。定义这个模型时要记住的主要事情是传递一些关于我们的标签数量的信息。执行此操作的最简单方法是将该数字传递给 <code>num_labels</code> 参数，但是如果我们想要一个很好的推理小部件，就像我们在本节开头看到的那样，最好设置正确的标签对应关系。",x,h,k="它们应该由两个字典设置， <code>id2label</code> 和 <code>label2id</code> ，其中包含从 ID 到标签的映射，反之亦然：",W,d,Z,B,C="现在我们可以将它们传递给 <code>AutoModelForTokenClassification.from_pretrained()</code> 方法，它们将在模型的配置中设置，然后保存并上传到Hub：",A,_,v,D,ks='就像我们在<a href="/course/chapter3">第三章</a>,定义我们的 <code>AutoModelForSequenceClassification</code> ，创建模型会发出警告，提示一些权重未被使用（来自预训练头的权重）和一些其他权重被随机初始化（来自新Token分类头的权重），我们将要训练这个模型。我们将在一分钟内完成，但首先让我们仔细检查我们的模型是否具有正确数量的标签：',tl,X,nl,q,Al,G,vl,Y,F,P,_s="我们现在准备好训练我们的模型了！在定义我们的 <code>Trainer</code>之前，我们只需要做最后两件事：登录 Hugging Face 并定义我们的训练参数。如果您在notebook上工作，有一个方便的功能可以帮助您：",al,K,Gl,V,gs="这将显示一个小部件，您可以在其中输入您的 Hugging Face 账号和密码。如果您不是在notebook上工作，只需在终端中输入以下行：",pl,O,Vl,R,ol="Once this is done, we can define our <code>TrainingArguments</code>:",Ml,Q,jl,wl,ul='您之前已经看过其中的大部分内容：我们设置了一些超参数（例如学习率、要训练的 epoch 数和权重衰减），然后我们指定 <code>push_to_hub=True</code> 表明我们想要保存模型并在每个时期结束时对其进行评估，并且我们想要将我们的结果上传到模型中心。请注意，可以使用hub_model_id参数指定要推送到的存储库的名称(特别是，必须使用这个参数来推送到一个组织)。例如，当我们将模型推送到<a href="https://huggingface.co/huggingface-course" rel="nofollow"><code>huggingface-course</code> organization</a>, 我们添加了 <code>hub_model_id=huggingface-course/bert-finetuned-ner</code> 到 <code>TrainingArguments</code> 。默认情况下，使用的存储库将在您的命名空间中并以您设置的输出目录命名，因此在我们的例子中它将是 <code>sgugger/bert-finetuned-ner</code>。',il,E,bl,dl,Ul="最后，我们只是将所有内容传递给 <code>Trainer</code> 并启动训练：",fl,rl,H,cl,ll="请注意，当训练发生时，每次保存模型时（这里是每个epooch），它都会在后台上传到 Hub。这样，如有必要，您将能够在另一台机器上继续您的训练。",xs,Jl,sl="训练完成后，我们使用 <code>push_to_hub()</code> 确保我们上传模型的最新版本",Rl,N,hl,yl,el="This command returns the URL of the commit it just did, if you want to inspect it:",Xl,z,r,$,Zs="这 <code>Trainer</code> 还创建了一张包含所有评估结果的模型卡并上传。在此阶段，您可以使用模型中心上的推理小部件来测试您的模型并与您的朋友分享。您已成功在Token分类任务上微调模型 - 恭喜！",Ss,Il,ie="如果您想更深入地了解训练循环，我们现在将向您展示如何使用 🤗 Accelerate 做同样的事情。",Yl,Bs,Ls,Cl,re='现在让我们看一下完整的训练循环，这样您可以轻松定义所需的部分。它看起来很像我们在<a href="/course/chapter3/4">第三章</a>, 所做的，对评估进行了一些更改。',Ql,El,Hl,Ws,ce="首先我们需要为我们的数据集构建 <code>DataLoader</code> 。我们将重用我们的 <code>data_collator</code> 作为一个 <code>collate_fn</code> 并打乱训练集，但不打乱验证集：",Nl,zl,Fl,Sl,As="接下来，我们重新实例化我们的模型，以确保我们不会从之前的训练继续训练，而是再次从 BERT 预训练模型开始：",Je,Ll,Dl,Gs,ye="然后我们将需要一个优化器。我们将使用经典 <code>AdamW</code> ，这就像 <code>Adam</code> ，但在应用权重衰减的方式上进行了改进：",ql,vs,Ds,$l,Te="Once we have all those objects, we can send them to the <code>accelerator.prepare()</code> method:",Pl,Kl,Ol,Vs,qs,kl,me="现在我们已经发送了我们的 <code>train_dataloader</code> 到 <code>accelerator.prepare()</code> ，我们可以使用它的长度来计算训练步骤的数量。请记住，我们应该始终在准备好dataloader后执行此操作，因为该方法会改变其长度。我们使用经典线性学习率调度：",ls,Rs,Ps,Tl,oe="最后，要将我们的模型推送到 Hub，我们需要创建一个 <code>Repository</code> 工作文件夹中的对象。如果您尚未登录，请先登录 Hugging Face。我们将从我们想要为模型提供的模型 ID 中确定存储库名称（您可以自由地用自己的选择替换 <code>repo_name</code> ；它只需要包含您的用户名，可以使用<code>get_full_repo_name()</code>函数的查看目前的repo_name）：",ss,es,ts,ns,as,Xs,je="然后我们可以将该存储库克隆到本地文件夹中。 如果它已经存在，这个本地文件夹应该是我们正在使用的存储库的现有克隆：",ps,Ys,Ks,_l,we="我们现在可以通过调用 <code>repo.push_to_hub()</code> 方法上传保存在 <code>output_dir</code> 中的任何内容。 这将帮助我们在每个训练周期结束时上传中间模型。",Ms,Qs,Os,gl,ue="我们现在准备编写完整的训练循环。为了简化它的评估部分，我们定义了这个 <code>postprocess()</code> 接受预测和标签并将它们转换为字符串列表的函数，也就是 <code>metric</code>对象需要的输入格式：",is,rs,cs,Es,be="然后我们可以编写训练循环。在定义一个进度条来跟踪训练的进行后，循环分为三个部分：",Js,ys,Hs="<li>训练本身，这是对<code>train_dataloader</code>的经典迭代，向前传递模型，然后反向传递和优化参数</li> <li>评估,在获得我们模型的输出后:因为两个进程可能将输入和标签填充成不同的形状,在调用<code>gather()</code>方法前我们需要使用<code>accelerator.pad_across_processes()</code>来让预测和标签形状相同。如果我们不这样做，评估要么出错，要么永远不会得到结果。然后，我们将结果发送给<code>metric.add_batch()</code>，并在计算循环结束后调用<code>metric.compute()</code>。</li> <li>保存和上传，首先保存模型和标记器，然后调用<code>repo.push_to_hub()</code>。注意，我们使用参数<code>blocking=False</code>告诉🤗 hub 库用在异步进程中推送。这样，训练将正常继续，并且该（长）指令将在后台执行。</li>",le,xl,Tt="这是训练循环的完整代码：",se,Zl,ee,Bl,de="果这是您第一次看到用 🤗 Accelerate 保存的模型，让我们花点时间检查一下它附带的三行代码：",Ts,Ns,te,Wl,Ue=`第一行是不言自明的：它告诉所有进程等到都处于那个阶段再继续(阻塞)。这是为了确保在保存之前，我们在每个过程中都有相同的模型。然后获取<code>unwrapped_model</code>，它是我们定义的基本模型。
<code>accelerator.prepare()</code>方法将模型更改为在分布式训练中工作，所以它不再有<code>save_pretraining()</code>方法;<code>accelerator.unwrap_model()</code>方法将撤销该步骤。最后，我们调用<code>save_pretraining()</code>，但告诉该方法使用<code>accelerator.save()</code>而不是<code>torch.save()</code>。`,ms,zs,fe='当完成之后，你应该有一个模型，它产生的结果与<code>Trainer</code>的结果非常相似。你可以在<a href="https://huggingface.co/huggingface-course/bert-finetuned-ner-accelerate" rel="nofollow">hugs face-course/bert-fine - tuning -ner-accelerate</a>中查看我们使用这个代码训练的模型。如果你想测试训练循环的任何调整，你可以直接通过编辑上面显示的代码来实现它们!',os;return M=new ml({props:{title:"定义模型",local:"定义模型",headingTag:"h3"}}),d=new I({props:{code:"aWQybGFiZWwlMjAlM0QlMjAlN0JzdHIoaSklM0ElMjBsYWJlbCUyMGZvciUyMGklMkMlMjBsYWJlbCUyMGluJTIwZW51bWVyYXRlKGxhYmVsX25hbWVzKSU3RCUwQWxhYmVsMmlkJTIwJTNEJTIwJTdCdiUzQSUyMGslMjBmb3IlMjBrJTJDJTIwdiUyMGluJTIwaWQybGFiZWwuaXRlbXMoKSU3RA==",highlighted:`id2label = {<span class="hljs-built_in">str</span>(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 I({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9Nb2RlbEZvclRva2VuQ2xhc3NpZmljYXRpb24lMEElMEFtb2RlbCUyMCUzRCUyMEF1dG9Nb2RlbEZvclRva2VuQ2xhc3NpZmljYXRpb24uZnJvbV9wcmV0cmFpbmVkKCUwQSUyMCUyMCUyMCUyMG1vZGVsX2NoZWNrcG9pbnQlMkMlMEElMjAlMjAlMjAlMjBpZDJsYWJlbCUzRGlkMmxhYmVsJTJDJTBBJTIwJTIwJTIwJTIwbGFiZWwyaWQlM0RsYWJlbDJpZCUyQyUwQSk=",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoModelForTokenClassification

model = AutoModelForTokenClassification.from_pretrained(
    model_checkpoint,
    id2label=id2label,
    label2id=label2id,
)`,wrap:!1}}),X=new I({props:{code:"bW9kZWwuY29uZmlnLm51bV9sYWJlbHM=",highlighted:"model.config.num_labels",wrap:!1}}),q=new I({props:{code:"OQ==",highlighted:'<span class="hljs-number">9</span>',wrap:!1}}),G=new Me({props:{warning:!0,$$slots:{default:[ra]},$$scope:{ctx:g}}}),Y=new ml({props:{title:"微调模型",local:"微调模型",headingTag:"h3"}}),K=new I({props:{code:"ZnJvbSUyMGh1Z2dpbmdmYWNlX2h1YiUyMGltcG9ydCUyMG5vdGVib29rX2xvZ2luJTBBJTBBbm90ZWJvb2tfbG9naW4oKQ==",highlighted:`<span class="hljs-keyword">from</span> huggingface_hub <span class="hljs-keyword">import</span> notebook_login

notebook_login()`,wrap:!1}}),O=new I({props:{code:"aHVnZ2luZ2ZhY2UtY2xpJTIwbG9naW4=",highlighted:"huggingface-cli login",wrap:!1}}),Q=new I({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}}),E=new Me({props:{$$slots:{default:[ca]},$$scope:{ctx:g}}}),rl=new I({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMFRyYWluZXIlMEElMEF0cmFpbmVyJTIwJTNEJTIwVHJhaW5lciglMEElMjAlMjAlMjAlMjBtb2RlbCUzRG1vZGVsJTJDJTBBJTIwJTIwJTIwJTIwYXJncyUzRGFyZ3MlMkMlMEElMjAlMjAlMjAlMjB0cmFpbl9kYXRhc2V0JTNEdG9rZW5pemVkX2RhdGFzZXRzJTVCJTIydHJhaW4lMjIlNUQlMkMlMEElMjAlMjAlMjAlMjBldmFsX2RhdGFzZXQlM0R0b2tlbml6ZWRfZGF0YXNldHMlNUIlMjJ2YWxpZGF0aW9uJTIyJTVEJTJDJTBBJTIwJTIwJTIwJTIwZGF0YV9jb2xsYXRvciUzRGRhdGFfY29sbGF0b3IlMkMlMEElMjAlMjAlMjAlMjBjb21wdXRlX21ldHJpY3MlM0Rjb21wdXRlX21ldHJpY3MlMkMlMEElMjAlMjAlMjAlMjB0b2tlbml6ZXIlM0R0b2tlbml6ZXIlMkMlMEEpJTBBdHJhaW5lci50cmFpbigp",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,
    tokenizer=tokenizer,
)
trainer.train()`,wrap:!1}}),N=new I({props:{code:"dHJhaW5lci5wdXNoX3RvX2h1Yihjb21taXRfbWVzc2FnZSUzRCUyMlRyYWluaW5nJTIwY29tcGxldGUlMjIp",highlighted:'trainer.push_to_hub(commit_message=<span class="hljs-string">&quot;Training complete&quot;</span>)',wrap:!1}}),z=new I({props:{code:"J2h0dHBzJTNBJTJGJTJGaHVnZ2luZ2ZhY2UuY28lMkZzZ3VnZ2VyJTJGYmVydC1maW5ldHVuZWQtbmVyJTJGY29tbWl0JTJGMjZhYjIxZTViMTU2OGY5YWZlY2NkYWVkMmQ4NzE1ZjU3MWQ3ODZlZCc=",highlighted:'<span class="hljs-string">&#x27;https://huggingface.co/sgugger/bert-finetuned-ner/commit/26ab21e5b1568f9afeccdaed2d8715f571d786ed&#x27;</span>',wrap:!1}}),Bs=new ml({props:{title:"自定义训练循环",local:"自定义训练循环",headingTag:"h2"}}),El=new ml({props:{title:"做好训练前的准备",local:"做好训练前的准备",headingTag:"h3"}}),zl=new I({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}}),Ll=new I({props:{code:"bW9kZWwlMjAlM0QlMjBBdXRvTW9kZWxGb3JUb2tlbkNsYXNzaWZpY2F0aW9uLmZyb21fcHJldHJhaW5lZCglMEElMjAlMjAlMjAlMjBtb2RlbF9jaGVja3BvaW50JTJDJTBBJTIwJTIwJTIwJTIwaWQybGFiZWwlM0RpZDJsYWJlbCUyQyUwQSUyMCUyMCUyMCUyMGxhYmVsMmlkJTNEbGFiZWwyaWQlMkMlMEEp",highlighted:`model = AutoModelForTokenClassification.from_pretrained(
    model_checkpoint,
    id2label=id2label,
    label2id=label2id,
)`,wrap:!1}}),vs=new I({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}}),Kl=new I({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}}),Vs=new Me({props:{$$slots:{default:[Ja]},$$scope:{ctx:g}}}),Rs=new I({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}}),es=new I({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}}),ns=new I({props:{code:"J3NndWdnZXIlMkZiZXJ0LWZpbmV0dW5lZC1uZXItYWNjZWxlcmF0ZSc=",highlighted:'<span class="hljs-string">&#x27;sgugger/bert-finetuned-ner-accelerate&#x27;</span>',wrap:!1}}),Ys=new I({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}}),Qs=new ml({props:{title:"训练循环",local:"训练循环",headingTag:"h3"}}),rs=new I({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}}),Zl=new I({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}}),Ns=new I({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(){j(M.$$.fragment),U=a(),i=T("p"),i.innerHTML=f,x=a(),h=T("p"),h.innerHTML=k,W=a(),j(d.$$.fragment),Z=a(),B=T("p"),B.innerHTML=C,A=a(),j(_.$$.fragment),v=a(),D=T("p"),D.innerHTML=ks,tl=a(),j(X.$$.fragment),nl=a(),j(q.$$.fragment),Al=a(),j(G.$$.fragment),vl=a(),j(Y.$$.fragment),F=a(),P=T("p"),P.innerHTML=_s,al=a(),j(K.$$.fragment),Gl=a(),V=T("p"),V.textContent=gs,pl=a(),j(O.$$.fragment),Vl=a(),R=T("p"),R.innerHTML=ol,Ml=a(),j(Q.$$.fragment),jl=a(),wl=T("p"),wl.innerHTML=ul,il=a(),j(E.$$.fragment),bl=a(),dl=T("p"),dl.innerHTML=Ul,fl=a(),j(rl.$$.fragment),H=a(),cl=T("p"),cl.textContent=ll,xs=a(),Jl=T("p"),Jl.innerHTML=sl,Rl=a(),j(N.$$.fragment),hl=a(),yl=T("p"),yl.textContent=el,Xl=a(),j(z.$$.fragment),r=a(),$=T("p"),$.innerHTML=Zs,Ss=a(),Il=T("p"),Il.textContent=ie,Yl=a(),j(Bs.$$.fragment),Ls=a(),Cl=T("p"),Cl.innerHTML=re,Ql=a(),j(El.$$.fragment),Hl=a(),Ws=T("p"),Ws.innerHTML=ce,Nl=a(),j(zl.$$.fragment),Fl=a(),Sl=T("p"),Sl.textContent=As,Je=a(),j(Ll.$$.fragment),Dl=a(),Gs=T("p"),Gs.innerHTML=ye,ql=a(),j(vs.$$.fragment),Ds=a(),$l=T("p"),$l.innerHTML=Te,Pl=a(),j(Kl.$$.fragment),Ol=a(),j(Vs.$$.fragment),qs=a(),kl=T("p"),kl.innerHTML=me,ls=a(),j(Rs.$$.fragment),Ps=a(),Tl=T("p"),Tl.innerHTML=oe,ss=a(),j(es.$$.fragment),ts=a(),j(ns.$$.fragment),as=a(),Xs=T("p"),Xs.textContent=je,ps=a(),j(Ys.$$.fragment),Ks=a(),_l=T("p"),_l.innerHTML=we,Ms=a(),j(Qs.$$.fragment),Os=a(),gl=T("p"),gl.innerHTML=ue,is=a(),j(rs.$$.fragment),cs=a(),Es=T("p"),Es.textContent=be,Js=a(),ys=T("ul"),ys.innerHTML=Hs,le=a(),xl=T("p"),xl.textContent=Tt,se=a(),j(Zl.$$.fragment),ee=a(),Bl=T("p"),Bl.textContent=de,Ts=a(),j(Ns.$$.fragment),te=a(),Wl=T("p"),Wl.innerHTML=Ue,ms=a(),zs=T("p"),zs.innerHTML=fe},l(s){w(M.$$.fragment,s),U=p(s),i=m(s,"P",{"data-svelte-h":!0}),o(i)!=="svelte-snq4oh"&&(i.innerHTML=f),x=p(s),h=m(s,"P",{"data-svelte-h":!0}),o(h)!=="svelte-hi5orh"&&(h.innerHTML=k),W=p(s),w(d.$$.fragment,s),Z=p(s),B=m(s,"P",{"data-svelte-h":!0}),o(B)!=="svelte-ty8bpp"&&(B.innerHTML=C),A=p(s),w(_.$$.fragment,s),v=p(s),D=m(s,"P",{"data-svelte-h":!0}),o(D)!=="svelte-1tztiyt"&&(D.innerHTML=ks),tl=p(s),w(X.$$.fragment,s),nl=p(s),w(q.$$.fragment,s),Al=p(s),w(G.$$.fragment,s),vl=p(s),w(Y.$$.fragment,s),F=p(s),P=m(s,"P",{"data-svelte-h":!0}),o(P)!=="svelte-hv8b10"&&(P.innerHTML=_s),al=p(s),w(K.$$.fragment,s),Gl=p(s),V=m(s,"P",{"data-svelte-h":!0}),o(V)!=="svelte-7pz5gb"&&(V.textContent=gs),pl=p(s),w(O.$$.fragment,s),Vl=p(s),R=m(s,"P",{"data-svelte-h":!0}),o(R)!=="svelte-h1gi55"&&(R.innerHTML=ol),Ml=p(s),w(Q.$$.fragment,s),jl=p(s),wl=m(s,"P",{"data-svelte-h":!0}),o(wl)!=="svelte-87bd1c"&&(wl.innerHTML=ul),il=p(s),w(E.$$.fragment,s),bl=p(s),dl=m(s,"P",{"data-svelte-h":!0}),o(dl)!=="svelte-1cvms99"&&(dl.innerHTML=Ul),fl=p(s),w(rl.$$.fragment,s),H=p(s),cl=m(s,"P",{"data-svelte-h":!0}),o(cl)!=="svelte-17b3wn4"&&(cl.textContent=ll),xs=p(s),Jl=m(s,"P",{"data-svelte-h":!0}),o(Jl)!=="svelte-nvtt7s"&&(Jl.innerHTML=sl),Rl=p(s),w(N.$$.fragment,s),hl=p(s),yl=m(s,"P",{"data-svelte-h":!0}),o(yl)!=="svelte-mme7gz"&&(yl.textContent=el),Xl=p(s),w(z.$$.fragment,s),r=p(s),$=m(s,"P",{"data-svelte-h":!0}),o($)!=="svelte-jc22x1"&&($.innerHTML=Zs),Ss=p(s),Il=m(s,"P",{"data-svelte-h":!0}),o(Il)!=="svelte-h7k4v7"&&(Il.textContent=ie),Yl=p(s),w(Bs.$$.fragment,s),Ls=p(s),Cl=m(s,"P",{"data-svelte-h":!0}),o(Cl)!=="svelte-xxg7ih"&&(Cl.innerHTML=re),Ql=p(s),w(El.$$.fragment,s),Hl=p(s),Ws=m(s,"P",{"data-svelte-h":!0}),o(Ws)!=="svelte-630n7s"&&(Ws.innerHTML=ce),Nl=p(s),w(zl.$$.fragment,s),Fl=p(s),Sl=m(s,"P",{"data-svelte-h":!0}),o(Sl)!=="svelte-5t877m"&&(Sl.textContent=As),Je=p(s),w(Ll.$$.fragment,s),Dl=p(s),Gs=m(s,"P",{"data-svelte-h":!0}),o(Gs)!=="svelte-1f9m18n"&&(Gs.innerHTML=ye),ql=p(s),w(vs.$$.fragment,s),Ds=p(s),$l=m(s,"P",{"data-svelte-h":!0}),o($l)!=="svelte-1oqv3so"&&($l.innerHTML=Te),Pl=p(s),w(Kl.$$.fragment,s),Ol=p(s),w(Vs.$$.fragment,s),qs=p(s),kl=m(s,"P",{"data-svelte-h":!0}),o(kl)!=="svelte-1bqkj5p"&&(kl.innerHTML=me),ls=p(s),w(Rs.$$.fragment,s),Ps=p(s),Tl=m(s,"P",{"data-svelte-h":!0}),o(Tl)!=="svelte-wqdk2u"&&(Tl.innerHTML=oe),ss=p(s),w(es.$$.fragment,s),ts=p(s),w(ns.$$.fragment,s),as=p(s),Xs=m(s,"P",{"data-svelte-h":!0}),o(Xs)!=="svelte-1fc52ya"&&(Xs.textContent=je),ps=p(s),w(Ys.$$.fragment,s),Ks=p(s),_l=m(s,"P",{"data-svelte-h":!0}),o(_l)!=="svelte-dknau9"&&(_l.innerHTML=we),Ms=p(s),w(Qs.$$.fragment,s),Os=p(s),gl=m(s,"P",{"data-svelte-h":!0}),o(gl)!=="svelte-78mypp"&&(gl.innerHTML=ue),is=p(s),w(rs.$$.fragment,s),cs=p(s),Es=m(s,"P",{"data-svelte-h":!0}),o(Es)!=="svelte-1sn3xcp"&&(Es.textContent=be),Js=p(s),ys=m(s,"UL",{"data-svelte-h":!0}),o(ys)!=="svelte-igaqd1"&&(ys.innerHTML=Hs),le=p(s),xl=m(s,"P",{"data-svelte-h":!0}),o(xl)!=="svelte-2e5lqj"&&(xl.textContent=Tt),se=p(s),w(Zl.$$.fragment,s),ee=p(s),Bl=m(s,"P",{"data-svelte-h":!0}),o(Bl)!=="svelte-17zcln7"&&(Bl.textContent=de),Ts=p(s),w(Ns.$$.fragment,s),te=p(s),Wl=m(s,"P",{"data-svelte-h":!0}),o(Wl)!=="svelte-1656q4k"&&(Wl.innerHTML=Ue),ms=p(s),zs=m(s,"P",{"data-svelte-h":!0}),o(zs)!=="svelte-qnnj8x"&&(zs.innerHTML=fe)},m(s,c){u(M,s,c),t(s,U,c),t(s,i,c),t(s,x,c),t(s,h,c),t(s,W,c),u(d,s,c),t(s,Z,c),t(s,B,c),t(s,A,c),u(_,s,c),t(s,v,c),t(s,D,c),t(s,tl,c),u(X,s,c),t(s,nl,c),u(q,s,c),t(s,Al,c),u(G,s,c),t(s,vl,c),u(Y,s,c),t(s,F,c),t(s,P,c),t(s,al,c),u(K,s,c),t(s,Gl,c),t(s,V,c),t(s,pl,c),u(O,s,c),t(s,Vl,c),t(s,R,c),t(s,Ml,c),u(Q,s,c),t(s,jl,c),t(s,wl,c),t(s,il,c),u(E,s,c),t(s,bl,c),t(s,dl,c),t(s,fl,c),u(rl,s,c),t(s,H,c),t(s,cl,c),t(s,xs,c),t(s,Jl,c),t(s,Rl,c),u(N,s,c),t(s,hl,c),t(s,yl,c),t(s,Xl,c),u(z,s,c),t(s,r,c),t(s,$,c),t(s,Ss,c),t(s,Il,c),t(s,Yl,c),u(Bs,s,c),t(s,Ls,c),t(s,Cl,c),t(s,Ql,c),u(El,s,c),t(s,Hl,c),t(s,Ws,c),t(s,Nl,c),u(zl,s,c),t(s,Fl,c),t(s,Sl,c),t(s,Je,c),u(Ll,s,c),t(s,Dl,c),t(s,Gs,c),t(s,ql,c),u(vs,s,c),t(s,Ds,c),t(s,$l,c),t(s,Pl,c),u(Kl,s,c),t(s,Ol,c),u(Vs,s,c),t(s,qs,c),t(s,kl,c),t(s,ls,c),u(Rs,s,c),t(s,Ps,c),t(s,Tl,c),t(s,ss,c),u(es,s,c),t(s,ts,c),u(ns,s,c),t(s,as,c),t(s,Xs,c),t(s,ps,c),u(Ys,s,c),t(s,Ks,c),t(s,_l,c),t(s,Ms,c),u(Qs,s,c),t(s,Os,c),t(s,gl,c),t(s,is,c),u(rs,s,c),t(s,cs,c),t(s,Es,c),t(s,Js,c),t(s,ys,c),t(s,le,c),t(s,xl,c),t(s,se,c),u(Zl,s,c),t(s,ee,c),t(s,Bl,c),t(s,Ts,c),u(Ns,s,c),t(s,te,c),t(s,Wl,c),t(s,ms,c),t(s,zs,c),os=!0},i(s){os||(J(M.$$.fragment,s),J(d.$$.fragment,s),J(_.$$.fragment,s),J(X.$$.fragment,s),J(q.$$.fragment,s),J(G.$$.fragment,s),J(Y.$$.fragment,s),J(K.$$.fragment,s),J(O.$$.fragment,s),J(Q.$$.fragment,s),J(E.$$.fragment,s),J(rl.$$.fragment,s),J(N.$$.fragment,s),J(z.$$.fragment,s),J(Bs.$$.fragment,s),J(El.$$.fragment,s),J(zl.$$.fragment,s),J(Ll.$$.fragment,s),J(vs.$$.fragment,s),J(Kl.$$.fragment,s),J(Vs.$$.fragment,s),J(Rs.$$.fragment,s),J(es.$$.fragment,s),J(ns.$$.fragment,s),J(Ys.$$.fragment,s),J(Qs.$$.fragment,s),J(rs.$$.fragment,s),J(Zl.$$.fragment,s),J(Ns.$$.fragment,s),os=!0)},o(s){y(M.$$.fragment,s),y(d.$$.fragment,s),y(_.$$.fragment,s),y(X.$$.fragment,s),y(q.$$.fragment,s),y(G.$$.fragment,s),y(Y.$$.fragment,s),y(K.$$.fragment,s),y(O.$$.fragment,s),y(Q.$$.fragment,s),y(E.$$.fragment,s),y(rl.$$.fragment,s),y(N.$$.fragment,s),y(z.$$.fragment,s),y(Bs.$$.fragment,s),y(El.$$.fragment,s),y(zl.$$.fragment,s),y(Ll.$$.fragment,s),y(vs.$$.fragment,s),y(Kl.$$.fragment,s),y(Vs.$$.fragment,s),y(Rs.$$.fragment,s),y(es.$$.fragment,s),y(ns.$$.fragment,s),y(Ys.$$.fragment,s),y(Qs.$$.fragment,s),y(rs.$$.fragment,s),y(Zl.$$.fragment,s),y(Ns.$$.fragment,s),os=!1},d(s){s&&(e(U),e(i),e(x),e(h),e(W),e(Z),e(B),e(A),e(v),e(D),e(tl),e(nl),e(Al),e(vl),e(F),e(P),e(al),e(Gl),e(V),e(pl),e(Vl),e(R),e(Ml),e(jl),e(wl),e(il),e(bl),e(dl),e(fl),e(H),e(cl),e(xs),e(Jl),e(Rl),e(hl),e(yl),e(Xl),e(r),e($),e(Ss),e(Il),e(Yl),e(Ls),e(Cl),e(Ql),e(Hl),e(Ws),e(Nl),e(Fl),e(Sl),e(Je),e(Dl),e(Gs),e(ql),e(Ds),e($l),e(Pl),e(Ol),e(qs),e(kl),e(ls),e(Ps),e(Tl),e(ss),e(ts),e(as),e(Xs),e(ps),e(Ks),e(_l),e(Ms),e(Os),e(gl),e(is),e(cs),e(Es),e(Js),e(ys),e(le),e(xl),e(se),e(ee),e(Bl),e(Ts),e(te),e(Wl),e(ms),e(zs)),b(M,s),b(d,s),b(_,s),b(X,s),b(q,s),b(G,s),b(Y,s),b(K,s),b(O,s),b(Q,s),b(E,s),b(rl,s),b(N,s),b(z,s),b(Bs,s),b(El,s),b(zl,s),b(Ll,s),b(vs,s),b(Kl,s),b(Vs,s),b(Rs,s),b(es,s),b(ns,s),b(Ys,s),b(Qs,s),b(rs,s),b(Zl,s),b(Ns,s)}}}function ra(g){let M,U="⚠️ 如果模型的标签数量错误，稍后调用Trainer.train()方法时会出现一个模糊的错误（类似于“CUDA error: device-side assert triggered”）。这是用户报告此类错误的第一个原因，因此请确保进行这样的检查以确认您拥有预期数量的标签。";return{c(){M=T("p"),M.textContent=U},l(i){M=m(i,"P",{"data-svelte-h":!0}),o(M)!=="svelte-1rehhud"&&(M.textContent=U)},m(i,f){t(i,M,f)},p:Fs,d(i){i&&e(M)}}}function ca(g){let M,U="💡 如果您正在使用的输出目录已经存在，那么输出目录必须是从同一个存储库clone下来的。如果不是，您将在声明 <code>Trainer</code> 时遇到错误，并且需要设置一个新名称。";return{c(){M=T("p"),M.innerHTML=U},l(i){M=m(i,"P",{"data-svelte-h":!0}),o(M)!=="svelte-dsrt1g"&&(M.innerHTML=U)},m(i,f){t(i,M,f)},p:Fs,d(i){i&&e(M)}}}function Ja(g){let M,U='🚨 如果您在 TPU 上进行训练，则需要将以上单元格中的所有代码移动到专用的训练函数中。有关详细信息，请参阅 <a href="/course/chapter3">第3章</a>。';return{c(){M=T("p"),M.innerHTML=U},l(i){M=m(i,"P",{"data-svelte-h":!0}),o(M)!=="svelte-137nfpp"&&(M.innerHTML=U)},m(i,f){t(i,M,f)},p:Fs,d(i){i&&e(M)}}}function ya(g){let M,U,i,f,x,h,k,W,d,Z,B,C,A="我们将探索的第一个应用是Token分类。这个通用任务包括任何可以表述为“为句子中的词或字分配标签”的问题，例如：",_,v,D="<li><strong>实体命名识别 (NER)</strong>: 找出句子中的实体（如人物、地点或组织）。这可以通过为每个实体或“无实体”指定一个类别的标签。</li> <li><strong>词性标注 (POS)</strong>: 将句子中的每个单词标记为对应于特定的词性（如名词、动词、形容词等）。</li> <li><strong>分块（chunking）</strong>: 找到属于同一实体的Token。这个任务(可结合POS或NER)可以任何将一块Token作为制定一个标签(通常是B -),另一个标签(通常I -)表示Token是否是同一块,和第三个标签(通常是O)表示Token不属于任何块。也就是标出句子中的短语块，例如名词短语（NP），动词短语（VP）等。</li>",ks,tl,X,nl,q="当然，还有很多其他类型的token分类问题；这些只是几个有代表性的例子。在本节中，我们将在 NER 任务上微调模型 (BERT)，然后该模型将能够计算如下预测：",Al,G,vl,Y,F,P='<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."/>',_s,al,K='您可以<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">在这里</a>.找到我们将训练并上传到 Hub的模型，可以尝试输入一些句子看看模型的预测结果。',Gl,V,gs,pl,O='首先，我们需要一个适合标记分类的数据集。在本节中，我们将使用<a href="https://huggingface.co/datasets/conll2003" rel="nofollow">CoNLL-2003 数据集</a>, 其中包含来自路透社的新闻报道。',Vl,R,ol,Ml,Q,jl,wl="要加载 CoNLL-2003 数据集，我们使用 来自 🤗 Datasets 库的<strong>load_dataset()</strong> 方法：",ul,il,E,bl,dl='这将下载并缓存数据集，就像和我们在<a href="/course/chapter3">第三章</a> 加载GLUE MRPC 数据集一样。检查这个对象可以让我们看到存在哪些列，以及训练集、验证集和测试集之间是如何分割的:',Ul,fl,rl,H,cl,ll,xs="特别是，我们可以看到数据集包含我们之前提到的三个任务的标签：NER、POS 和chunking。与其他数据集的一个很大区别是输入文本不是作为句子或文档呈现的，而是单词列表（最后一列称为 <strong>tokens</strong> ，但它包含的是这些词是预先标记化的输入，仍然需要通过标记器进行子词标记）。",Jl,sl,Rl="我们来看看训练集的第一个元素：",N,hl,yl,el,Xl,z,r="由于我们要执行命名实体识别，我们将查看 NER 标签：",$,Zs,Ss,Il,ie,Yl,Bs="这一列是类标签的序列。元素的类型在ner_feature的feature属性中，我们可以通过查看该特性的names属性来访问名称列表:",Ls,Cl,re,Ql,El,Hl,Ws="因此，这一列包含的元素是ClassLabels的序列。序列元素的类型在<code>ner_feature</code>的<code>feature</code>中，我们可以通过查看该<code>feature</code>的<code>names</code>属性来访问名称列表:",ce,Nl,zl,Fl,Sl,As,Je='我们在<a href="/course/chapter6/3">第六章</a>, 深入研究<strong>token-classification</strong> 管道时已经看到了这些标签 ，但为了快速复习：',Ll,Dl,Gs="<li><code>O</code> 表示这个词不对应任何实体。</li> <li><code>B-PER</code>/<code>I-PER</code>意味着这个词对应于人名实体的开头/内部。</li> <li><code>B-ORG</code>/<code>I-ORG</code> 的意思是这个词对应于组织名称实体的开头/内部。</li> <li><code>B-LOC</code>/<code>I-LOC</code> 指的是是这个词对应于地名实体的开头/内部。</li> <li><code>B-MISC</code>/<code>I-MISC</code> 表示该词对应于一个杂项实体的开头/内部。</li>",ye,ql,vs="现在解码我们之前看到的标签：",Ds,$l,Te,Pl,Kl,Ol,Vs="例如混合 <strong>B-</strong> 和 <strong>I-</strong> 标签，这是相同的代码在索引 4 的训练集元素上的预测结果：",qs,kl,me,ls,Rs="正如我们所看到的，跨越两个单词的实体，如“European Union”和“Werner Zwingmann”，模型为第一个单词标注了一个B-标签，为第二个单词标注了一个I-标签。",Ps,Tl,oe,ss,es,ts,ns,as,Xs='像往常一样，我们的文本需要转换为Token ID，然后模型才能理解它们。正如我们在<a href="/course/chapter6/">第六章</a>所学的那样。不过在标记任务中，一个很大的区别是我们有pre-tokenized的输入。幸运的是，tokenizer API可以很容易地处理这个问题;我们只需要用一个特殊的tokenizer。',je,ps,Ys="首先，让我们创建<code>tokenizer</code>对象。如前所述，我们将使用 BERT 预训练模型，因此我们将从下载并缓存关联的分词器开始：",Ks,_l,we,Ms,Qs='你可以更换把 <code>model_checkpoint</code> 更换为 <a href="https://huggingface.co/models" rel="nofollow">Hub</a>,上您喜欢的任何其他型号，或使用您本地保存的预训练模型和分词器。唯一的限制是分词器需要由 🤗 Tokenizers 库支持，有一个“快速”版本可用。你可以在<a href="https://huggingface.co/transformers/#supported-frameworks" rel="nofollow">这张大表</a>, 上看到所有带有快速版本的架构，或者检查  您可以通过查看它<code>is_fast</code> 属性来检测正在使用的<code>tokenizer</code>对象是否由 🤗 Tokenizers 支持：',Os,gl,ue,is,rs,cs,Es="要对预先标记的输入进行标记，我们可以像往常一样使用我们的<code>tokenizer</code> 只需添加 <code>is_split_into_words=True</code>:",be,Js,ys,Hs,le,xl,Tt=`正如我们所见，分词器添加了模型使用的特殊Token(<code>[CLS]</code> 在开始和<code>[SEP]</code> 最后) 而大多数单词未被修改。然而，单词 <code>lamb</code>,被分为两个子单词 <code>la</code> and <code>##mb</code>。这导致了输入和标签之间的不匹配:标签列表只有9个元素，而我们的输入现在有12个token 。计算特殊Token很容易(我们知道它们在开头和结尾)，但我们还需要确保所有标签与适当的单词对齐。
幸运的是，由于我们使用的是快速分词器，因此我们可以访问🤗 Tokenizers超能力，这意味着我们可以轻松地将每个令牌映射到其相应的单词（如<a href="/course/chapter6/3">Chapter 6</a>):`,se,Zl,ee,Bl,de,Ts,Ns="通过一点点工作，我们可以扩展我们的标签列表以匹配token 。我们将应用的第一条规则是，特殊token 的标签为 <code>-100</code> 。这是因为默认情况下 <code>-100</code> 是一个在我们将使用的损失函数（交叉熵）中被忽略的索引。然后，每个token 都会获得与其所在单词的token 相同的标签，因为它们是同一实体的一部分。对于单词内部但不在开头的Token，我们将<code>B-</code> 替换为 <code>I-</code> (因为token 不以实体开头):",te,Wl,Ue,ms,zs="让我们在我们的第一句话上试一试：",fe,os,s,c,ot,he,en="正如我们所看到的，我们的函数为开头和结尾的两个特殊标记添加了  <code>-100</code> ，并为分成两个标记的单词添加了一个新的<code>0</code> 。",jt,ne,wt,Ie,tn="为了预处理我们的整个数据集，我们需要标记所有输入并在所有标签上应用 <code>align_labels_with_tokens()</code> 。为了利用我们的快速分词器的速度优势，最好同时对大量文本进行分词，因此我们将编写一个处理示例列表的函数并使用带 <code>batched=True</code> 有选项的 <code>Dataset.map()</code>方法 .与我们之前的示例唯一不同的是当分词器的输入是文本列表（或者像例子中的单词列表）时  <code>word_ids()</code> 函数需要获取我们想要单词的索引的ID，所以我们也添加它：",ut,Ce,bt,$e,nn="请注意，我们还没有填充我们的输入；我们稍后会在使用数据整理器创建batch时这样做。",dt,ke,an="我们现在可以一次性将所有预处理应用于数据集的其他部分：",Ut,_e,ft,ge,pn='我们已经完成了最难的部分！现在数据已经被预处理了，实际的训练看起来很像我们<a href="/course/chapter3">第三章</a>做的.',ht,js,ws,pt,xe,It,Ze,Mn='我们不能像<a href="/course/chapter3">第三章</a>那样只使用一个 <code>DataCollatorWithPadding </code>因为这只会填充输入（输入 ID、注意掩码和标记类型 ID）。在这里我们的标签应该以与输入完全相同的方式填充，以便它们保持长度相同，使用  <code>-100</code> ，这样在损失计算中就可以忽略相应的预测。',Ct,Be,rn='这一切都是由一个 <a href="https://huggingface.co/transformers/main_classes/data_collator.html#datacollatorfortokenclassification" rel="nofollow"><code>DataCollatorForTokenClassification</code></a>完成.它是一个带有填充的数据整理器它需要  <code>tokenizer</code> 用于预处理输入：',$t,us,bs,Mt,We,cn="为了在几个样本上测试这一点，我们可以在训练集中的示例列表上调用它：",kt,Ae,_t,Ge,gt,ve,Jn="让我们将其与数据集中第一个和第二个元素的标签进行比较：",xt,Ve,Zt,Re,Bt,ds,Us,it,rt,Xe,Wt,fs,hs,ct,Ye,At,Qe,yn="这个评估方式与标准精度不同:它实际上将标签列表作为字符串，而不是整数，因此在将预测和标签传递给它之前，我们需要完全解码它们。让我们看看它是如何工作的。首先，我们将获得第一个训练示例的标签:",Gt,Ee,vt,He,Vt,Ne,Tn="然后我们可以通过更改索引 2 处的值来为那些创建假的预测：",Rt,ze,Xt,Fe,mn="请注意，该指标的输入是预测列表（不仅仅是一个）和标签列表。这是输出：",Yt,Se,Qt,Is,Cs,Jt,yt,Le,Et,De,on="我们已经向您展示了如何使用我们在模型中心微调的模型和推理小部件。在本地使用它 <code>pipeline</code> ，您只需要指定正确的模型标识符：",Ht,qe,Nt,Pe,zt,Ke,jn="太棒了！我们的模型与此管道的默认模型一样有效！",Ft,Oe,St,mt,Lt;x=new Nn({props:{fw:g[0]}}),k=new ml({props:{title:"Token 分类",local:"Token 分类",headingTag:"h1"}});const wn=[Sn,Fn],lt=[];function un(l,n){return l[0]==="pt"?0:1}d=un(g),Z=lt[d]=wn[d](g),tl=new Wn({props:{id:"wVHdVlPScxA"}}),V=new ml({props:{title:"准备数据",local:"准备数据",headingTag:"h2"}}),R=new Me({props:{$$slots:{default:[Ln]},$$scope:{ctx:g}}}),Ml=new ml({props:{title:"CoNLL-2003 数据集",local:"CoNLL-2003 数据集",headingTag:"h3"}}),il=new I({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}}),fl=new I({props:{code:"cmF3X2RhdGFzZXRz",highlighted:"raw_datasets",wrap:!1}}),H=new I({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}}),hl=new I({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}}),el=new I({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}}),Zs=new I({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}}),Il=new I({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}}),Cl=new I({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}}),Ql=new I({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}}),Nl=new I({props:{code:"bGFiZWxfbmFtZXMlMjAlM0QlMjBuZXJfZmVhdHVyZS5mZWF0dXJlLm5hbWVzJTBBbGFiZWxfbmFtZXM=",highlighted:`label_names = ner_feature.feature.names
label_names`,wrap:!1}}),Fl=new I({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}}),$l=new I({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}}),Pl=new I({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}}),kl=new I({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}}),Tl=new Me({props:{$$slots:{default:[Dn]},$$scope:{ctx:g}}}),ss=new ml({props:{title:"处理数据",local:"处理数据",headingTag:"h3"}}),ts=new Wn({props:{id:"iY2AZYdZAr0"}}),_l=new I({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}}),gl=new I({props:{code:"dG9rZW5pemVyLmlzX2Zhc3Q=",highlighted:"tokenizer.is_fast",wrap:!1}}),is=new I({props:{code:"VHJ1ZQ==",highlighted:'<span class="hljs-literal">True</span>',wrap:!1}}),Js=new I({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}}),Hs=new I({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}}),Zl=new I({props:{code:"aW5wdXRzLndvcmRfaWRzKCk=",highlighted:"inputs.word_ids()",wrap:!1}}),Bl=new I({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 I({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}}),os=new I({props:{code:"bGFiZWxzJTIwJTNEJTIwcmF3X2RhdGFzZXRzJTVCJTIydHJhaW4lMjIlNUQlNUIwJTVEJTVCJTIybmVyX3RhZ3MlMjIlNUQlMEF3b3JkX2lkcyUyMCUzRCUyMGlucHV0cy53b3JkX2lkcygpJTBBcHJpbnQobGFiZWxzKSUwQXByaW50KGFsaWduX2xhYmVsc193aXRoX3Rva2VucyhsYWJlbHMlMkMlMjB3b3JkX2lkcykp",highlighted:`labels = raw_datasets[<span class="hljs-string">&quot;train&quot;</span>][<span class="hljs-number">0</span>][<span class="hljs-string">&quot;ner_tags&quot;</span>]
word_ids = inputs.word_ids()
<span class="hljs-built_in">print</span>(labels)
<span class="hljs-built_in">print</span>(align_labels_with_tokens(labels, word_ids))`,wrap:!1}}),c=new I({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}}),ne=new Me({props:{$$slots:{default:[qn]},$$scope:{ctx:g}}}),Ce=new I({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}}),_e=new I({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 bn=[Kn,Pn],st=[];function dn(l,n){return l[0]==="pt"?0:1}js=dn(g),ws=st[js]=bn[js](g),xe=new ml({props:{title:"数据排序",local:"数据排序",headingTag:"h3"}});const Un=[la,On],et=[];function fn(l,n){return l[0]==="pt"?0:1}us=fn(g),bs=et[us]=Un[us](g),Ae=new I({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}}),Ge=new I({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}}),Ve=new I({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}}),Re=new I({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 hn=[ea,sa],tt=[];function In(l,n){return l[0]==="pt"?0:1}ds=In(g),Us=tt[ds]=hn[ds](g);let S=g[0]==="tf"&&An(g);Xe=new ml({props:{title:"评估指标",local:"评估指标",headingTag:"h3"}});const Cn=[pa,aa],nt=[];function $n(l,n){return l[0]==="pt"?0:1}fs=$n(g),hs=nt[fs]=Cn[fs](g),Ye=new I({props:{code:"aW1wb3J0JTIwZXZhbHVhdGUlMEElMEFtZXRyaWMlMjAlM0QlMjBldmFsdWF0ZS5sb2FkKCUyMnNlcWV2YWwlMjIp",highlighted:`<span class="hljs-keyword">import</span> evaluate

metric = evaluate.load(<span class="hljs-string">&quot;seqeval&quot;</span>)`,wrap:!1}}),Ee=new I({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}}),He=new I({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}}),ze=new I({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}}),Se=new I({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 kn=[ia,Ma],at=[];function _n(l,n){return l[0]==="pt"?0:1}Is=_n(g),Cs=at[Is]=kn[Is](g);let L=g[0]==="pt"&&Gn(g);return Le=new ml({props:{title:"使用微调模型",local:"使用微调模型",headingTag:"h2"}}),qe=new I({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}}),Pe=new I({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}}),Oe=new zn({props:{source:"https://github.com/huggingface/course/blob/main/chapters/zh-CN/chapter7/2.mdx"}}),{c(){M=T("meta"),U=a(),i=T("p"),f=a(),j(x.$$.fragment),h=a(),j(k.$$.fragment),W=a(),Z.c(),B=a(),C=T("p"),C.textContent=A,_=a(),v=T("ul"),v.innerHTML=D,ks=a(),j(tl.$$.fragment),X=a(),nl=T("p"),nl.textContent=q,Al=a(),G=T("iframe"),Y=a(),F=T("a"),F.innerHTML=P,_s=a(),al=T("p"),al.innerHTML=K,Gl=a(),j(V.$$.fragment),gs=a(),pl=T("p"),pl.innerHTML=O,Vl=a(),j(R.$$.fragment),ol=a(),j(Ml.$$.fragment),Q=a(),jl=T("p"),jl.innerHTML=wl,ul=a(),j(il.$$.fragment),E=a(),bl=T("p"),bl.innerHTML=dl,Ul=a(),j(fl.$$.fragment),rl=a(),j(H.$$.fragment),cl=a(),ll=T("p"),ll.innerHTML=xs,Jl=a(),sl=T("p"),sl.textContent=Rl,N=a(),j(hl.$$.fragment),yl=a(),j(el.$$.fragment),Xl=a(),z=T("p"),z.textContent=r,$=a(),j(Zs.$$.fragment),Ss=a(),j(Il.$$.fragment),ie=a(),Yl=T("p"),Yl.textContent=Bs,Ls=a(),j(Cl.$$.fragment),re=a(),j(Ql.$$.fragment),El=a(),Hl=T("p"),Hl.innerHTML=Ws,ce=a(),j(Nl.$$.fragment),zl=a(),j(Fl.$$.fragment),Sl=a(),As=T("p"),As.innerHTML=Je,Ll=a(),Dl=T("ul"),Dl.innerHTML=Gs,ye=a(),ql=T("p"),ql.textContent=vs,Ds=a(),j($l.$$.fragment),Te=a(),j(Pl.$$.fragment),Kl=a(),Ol=T("p"),Ol.innerHTML=Vs,qs=a(),j(kl.$$.fragment),me=a(),ls=T("p"),ls.textContent=Rs,Ps=a(),j(Tl.$$.fragment),oe=a(),j(ss.$$.fragment),es=a(),j(ts.$$.fragment),ns=a(),as=T("p"),as.innerHTML=Xs,je=a(),ps=T("p"),ps.innerHTML=Ys,Ks=a(),j(_l.$$.fragment),we=a(),Ms=T("p"),Ms.innerHTML=Qs,Os=a(),j(gl.$$.fragment),ue=a(),j(is.$$.fragment),rs=a(),cs=T("p"),cs.innerHTML=Es,be=a(),j(Js.$$.fragment),ys=a(),j(Hs.$$.fragment),le=a(),xl=T("p"),xl.innerHTML=Tt,se=a(),j(Zl.$$.fragment),ee=a(),j(Bl.$$.fragment),de=a(),Ts=T("p"),Ts.innerHTML=Ns,te=a(),j(Wl.$$.fragment),Ue=a(),ms=T("p"),ms.textContent=zs,fe=a(),j(os.$$.fragment),s=a(),j(c.$$.fragment),ot=a(),he=T("p"),he.innerHTML=en,jt=a(),j(ne.$$.fragment),wt=a(),Ie=T("p"),Ie.innerHTML=tn,ut=a(),j(Ce.$$.fragment),bt=a(),$e=T("p"),$e.textContent=nn,dt=a(),ke=T("p"),ke.textContent=an,Ut=a(),j(_e.$$.fragment),ft=a(),ge=T("p"),ge.innerHTML=pn,ht=a(),ws.c(),pt=a(),j(xe.$$.fragment),It=a(),Ze=T("p"),Ze.innerHTML=Mn,Ct=a(),Be=T("p"),Be.innerHTML=rn,$t=a(),bs.c(),Mt=a(),We=T("p"),We.textContent=cn,kt=a(),j(Ae.$$.fragment),_t=a(),j(Ge.$$.fragment),gt=a(),ve=T("p"),ve.textContent=Jn,xt=a(),j(Ve.$$.fragment),Zt=a(),j(Re.$$.fragment),Bt=a(),Us.c(),it=a(),S&&S.c(),rt=a(),j(Xe.$$.fragment),Wt=a(),hs.c(),ct=a(),j(Ye.$$.fragment),At=a(),Qe=T("p"),Qe.textContent=yn,Gt=a(),j(Ee.$$.fragment),vt=a(),j(He.$$.fragment),Vt=a(),Ne=T("p"),Ne.textContent=Tn,Rt=a(),j(ze.$$.fragment),Xt=a(),Fe=T("p"),Fe.textContent=mn,Yt=a(),j(Se.$$.fragment),Qt=a(),Cs.c(),Jt=a(),L&&L.c(),yt=a(),j(Le.$$.fragment),Et=a(),De=T("p"),De.innerHTML=on,Ht=a(),j(qe.$$.fragment),Nt=a(),j(Pe.$$.fragment),zt=a(),Ke=T("p"),Ke.textContent=jn,Ft=a(),j(Oe.$$.fragment),St=a(),mt=T("p"),this.h()},l(l){const n=En("svelte-u9bgzb",document.head);M=m(n,"META",{name:!0,content:!0}),n.forEach(e),U=p(l),i=m(l,"P",{}),sn(i).forEach(e),f=p(l),w(x.$$.fragment,l),h=p(l),w(k.$$.fragment,l),W=p(l),Z.l(l),B=p(l),C=m(l,"P",{"data-svelte-h":!0}),o(C)!=="svelte-1egbhvu"&&(C.textContent=A),_=p(l),v=m(l,"UL",{"data-svelte-h":!0}),o(v)!=="svelte-n3z685"&&(v.innerHTML=D),ks=p(l),w(tl.$$.fragment,l),X=p(l),nl=m(l,"P",{"data-svelte-h":!0}),o(nl)!=="svelte-4e7lur"&&(nl.textContent=q),Al=p(l),G=m(l,"IFRAME",{src:!0,frameborder:!0,height:!0,title:!0,class:!0,allow:!0,sandbox:!0}),sn(G).forEach(e),Y=p(l),F=m(l,"A",{class:!0,href:!0,"data-svelte-h":!0}),o(F)!=="svelte-1n7oe9l"&&(F.innerHTML=P),_s=p(l),al=m(l,"P",{"data-svelte-h":!0}),o(al)!=="svelte-p5for5"&&(al.innerHTML=K),Gl=p(l),w(V.$$.fragment,l),gs=p(l),pl=m(l,"P",{"data-svelte-h":!0}),o(pl)!=="svelte-wump3e"&&(pl.innerHTML=O),Vl=p(l),w(R.$$.fragment,l),ol=p(l),w(Ml.$$.fragment,l),Q=p(l),jl=m(l,"P",{"data-svelte-h":!0}),o(jl)!=="svelte-me6sr3"&&(jl.innerHTML=wl),ul=p(l),w(il.$$.fragment,l),E=p(l),bl=m(l,"P",{"data-svelte-h":!0}),o(bl)!=="svelte-1fi30mm"&&(bl.innerHTML=dl),Ul=p(l),w(fl.$$.fragment,l),rl=p(l),w(H.$$.fragment,l),cl=p(l),ll=m(l,"P",{"data-svelte-h":!0}),o(ll)!=="svelte-1j17qn5"&&(ll.innerHTML=xs),Jl=p(l),sl=m(l,"P",{"data-svelte-h":!0}),o(sl)!=="svelte-1p63zux"&&(sl.textContent=Rl),N=p(l),w(hl.$$.fragment,l),yl=p(l),w(el.$$.fragment,l),Xl=p(l),z=m(l,"P",{"data-svelte-h":!0}),o(z)!=="svelte-190g14d"&&(z.textContent=r),$=p(l),w(Zs.$$.fragment,l),Ss=p(l),w(Il.$$.fragment,l),ie=p(l),Yl=m(l,"P",{"data-svelte-h":!0}),o(Yl)!=="svelte-uvoq7w"&&(Yl.textContent=Bs),Ls=p(l),w(Cl.$$.fragment,l),re=p(l),w(Ql.$$.fragment,l),El=p(l),Hl=m(l,"P",{"data-svelte-h":!0}),o(Hl)!=="svelte-gdbnsz"&&(Hl.innerHTML=Ws),ce=p(l),w(Nl.$$.fragment,l),zl=p(l),w(Fl.$$.fragment,l),Sl=p(l),As=m(l,"P",{"data-svelte-h":!0}),o(As)!=="svelte-1kukrxo"&&(As.innerHTML=Je),Ll=p(l),Dl=m(l,"UL",{"data-svelte-h":!0}),o(Dl)!=="svelte-24q5t1"&&(Dl.innerHTML=Gs),ye=p(l),ql=m(l,"P",{"data-svelte-h":!0}),o(ql)!=="svelte-1nzvro9"&&(ql.textContent=vs),Ds=p(l),w($l.$$.fragment,l),Te=p(l),w(Pl.$$.fragment,l),Kl=p(l),Ol=m(l,"P",{"data-svelte-h":!0}),o(Ol)!=="svelte-cvumx4"&&(Ol.innerHTML=Vs),qs=p(l),w(kl.$$.fragment,l),me=p(l),ls=m(l,"P",{"data-svelte-h":!0}),o(ls)!=="svelte-1r46hvf"&&(ls.textContent=Rs),Ps=p(l),w(Tl.$$.fragment,l),oe=p(l),w(ss.$$.fragment,l),es=p(l),w(ts.$$.fragment,l),ns=p(l),as=m(l,"P",{"data-svelte-h":!0}),o(as)!=="svelte-fc5kly"&&(as.innerHTML=Xs),je=p(l),ps=m(l,"P",{"data-svelte-h":!0}),o(ps)!=="svelte-nk6gwe"&&(ps.innerHTML=Ys),Ks=p(l),w(_l.$$.fragment,l),we=p(l),Ms=m(l,"P",{"data-svelte-h":!0}),o(Ms)!=="svelte-1y3vrry"&&(Ms.innerHTML=Qs),Os=p(l),w(gl.$$.fragment,l),ue=p(l),w(is.$$.fragment,l),rs=p(l),cs=m(l,"P",{"data-svelte-h":!0}),o(cs)!=="svelte-1pgztt5"&&(cs.innerHTML=Es),be=p(l),w(Js.$$.fragment,l),ys=p(l),w(Hs.$$.fragment,l),le=p(l),xl=m(l,"P",{"data-svelte-h":!0}),o(xl)!=="svelte-1eov4zj"&&(xl.innerHTML=Tt),se=p(l),w(Zl.$$.fragment,l),ee=p(l),w(Bl.$$.fragment,l),de=p(l),Ts=m(l,"P",{"data-svelte-h":!0}),o(Ts)!=="svelte-1rj1muc"&&(Ts.innerHTML=Ns),te=p(l),w(Wl.$$.fragment,l),Ue=p(l),ms=m(l,"P",{"data-svelte-h":!0}),o(ms)!=="svelte-1buu8kz"&&(ms.textContent=zs),fe=p(l),w(os.$$.fragment,l),s=p(l),w(c.$$.fragment,l),ot=p(l),he=m(l,"P",{"data-svelte-h":!0}),o(he)!=="svelte-16of5t5"&&(he.innerHTML=en),jt=p(l),w(ne.$$.fragment,l),wt=p(l),Ie=m(l,"P",{"data-svelte-h":!0}),o(Ie)!=="svelte-lbgqi6"&&(Ie.innerHTML=tn),ut=p(l),w(Ce.$$.fragment,l),bt=p(l),$e=m(l,"P",{"data-svelte-h":!0}),o($e)!=="svelte-hs12p7"&&($e.textContent=nn),dt=p(l),ke=m(l,"P",{"data-svelte-h":!0}),o(ke)!=="svelte-1y2qyj4"&&(ke.textContent=an),Ut=p(l),w(_e.$$.fragment,l),ft=p(l),ge=m(l,"P",{"data-svelte-h":!0}),o(ge)!=="svelte-5dixuq"&&(ge.innerHTML=pn),ht=p(l),ws.l(l),pt=p(l),w(xe.$$.fragment,l),It=p(l),Ze=m(l,"P",{"data-svelte-h":!0}),o(Ze)!=="svelte-jikqf7"&&(Ze.innerHTML=Mn),Ct=p(l),Be=m(l,"P",{"data-svelte-h":!0}),o(Be)!=="svelte-113a9bv"&&(Be.innerHTML=rn),$t=p(l),bs.l(l),Mt=p(l),We=m(l,"P",{"data-svelte-h":!0}),o(We)!=="svelte-1y888sx"&&(We.textContent=cn),kt=p(l),w(Ae.$$.fragment,l),_t=p(l),w(Ge.$$.fragment,l),gt=p(l),ve=m(l,"P",{"data-svelte-h":!0}),o(ve)!=="svelte-mhu2qd"&&(ve.textContent=Jn),xt=p(l),w(Ve.$$.fragment,l),Zt=p(l),w(Re.$$.fragment,l),Bt=p(l),Us.l(l),it=p(l),S&&S.l(l),rt=p(l),w(Xe.$$.fragment,l),Wt=p(l),hs.l(l),ct=p(l),w(Ye.$$.fragment,l),At=p(l),Qe=m(l,"P",{"data-svelte-h":!0}),o(Qe)!=="svelte-qbyee6"&&(Qe.textContent=yn),Gt=p(l),w(Ee.$$.fragment,l),vt=p(l),w(He.$$.fragment,l),Vt=p(l),Ne=m(l,"P",{"data-svelte-h":!0}),o(Ne)!=="svelte-1ua5r7i"&&(Ne.textContent=Tn),Rt=p(l),w(ze.$$.fragment,l),Xt=p(l),Fe=m(l,"P",{"data-svelte-h":!0}),o(Fe)!=="svelte-1hbqh1e"&&(Fe.textContent=mn),Yt=p(l),w(Se.$$.fragment,l),Qt=p(l),Cs.l(l),Jt=p(l),L&&L.l(l),yt=p(l),w(Le.$$.fragment,l),Et=p(l),De=m(l,"P",{"data-svelte-h":!0}),o(De)!=="svelte-17uskgs"&&(De.innerHTML=on),Ht=p(l),w(qe.$$.fragment,l),Nt=p(l),w(Pe.$$.fragment,l),zt=p(l),Ke=m(l,"P",{"data-svelte-h":!0}),o(Ke)!=="svelte-1vu89s1"&&(Ke.textContent=jn),Ft=p(l),w(Oe.$$.fragment,l),St=p(l),mt=m(l,"P",{}),sn(mt).forEach(e),this.h()},h(){$s(M,"name","hf:doc:metadata"),$s(M,"content",Ta),Rn(G.src,vl="https://course-demos-bert-finetuned-ner.hf.space")||$s(G,"src",vl),$s(G,"frameborder","0"),$s(G,"height","350"),$s(G,"title","Gradio app"),$s(G,"class","block dark:hidden container p-0 flex-grow space-iframe"),$s(G,"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"),$s(G,"sandbox","allow-forms allow-modals allow-popups allow-popups-to-escape-sandbox allow-same-origin allow-scripts allow-downloads"),$s(F,"class","flex justify-center"),$s(F,"href","/huggingface-course/bert-finetuned-ner")},m(l,n){Hn(document.head,M),t(l,U,n),t(l,i,n),t(l,f,n),u(x,l,n),t(l,h,n),u(k,l,n),t(l,W,n),lt[d].m(l,n),t(l,B,n),t(l,C,n),t(l,_,n),t(l,v,n),t(l,ks,n),u(tl,l,n),t(l,X,n),t(l,nl,n),t(l,Al,n),t(l,G,n),t(l,Y,n),t(l,F,n),t(l,_s,n),t(l,al,n),t(l,Gl,n),u(V,l,n),t(l,gs,n),t(l,pl,n),t(l,Vl,n),u(R,l,n),t(l,ol,n),u(Ml,l,n),t(l,Q,n),t(l,jl,n),t(l,ul,n),u(il,l,n),t(l,E,n),t(l,bl,n),t(l,Ul,n),u(fl,l,n),t(l,rl,n),u(H,l,n),t(l,cl,n),t(l,ll,n),t(l,Jl,n),t(l,sl,n),t(l,N,n),u(hl,l,n),t(l,yl,n),u(el,l,n),t(l,Xl,n),t(l,z,n),t(l,$,n),u(Zs,l,n),t(l,Ss,n),u(Il,l,n),t(l,ie,n),t(l,Yl,n),t(l,Ls,n),u(Cl,l,n),t(l,re,n),u(Ql,l,n),t(l,El,n),t(l,Hl,n),t(l,ce,n),u(Nl,l,n),t(l,zl,n),u(Fl,l,n),t(l,Sl,n),t(l,As,n),t(l,Ll,n),t(l,Dl,n),t(l,ye,n),t(l,ql,n),t(l,Ds,n),u($l,l,n),t(l,Te,n),u(Pl,l,n),t(l,Kl,n),t(l,Ol,n),t(l,qs,n),u(kl,l,n),t(l,me,n),t(l,ls,n),t(l,Ps,n),u(Tl,l,n),t(l,oe,n),u(ss,l,n),t(l,es,n),u(ts,l,n),t(l,ns,n),t(l,as,n),t(l,je,n),t(l,ps,n),t(l,Ks,n),u(_l,l,n),t(l,we,n),t(l,Ms,n),t(l,Os,n),u(gl,l,n),t(l,ue,n),u(is,l,n),t(l,rs,n),t(l,cs,n),t(l,be,n),u(Js,l,n),t(l,ys,n),u(Hs,l,n),t(l,le,n),t(l,xl,n),t(l,se,n),u(Zl,l,n),t(l,ee,n),u(Bl,l,n),t(l,de,n),t(l,Ts,n),t(l,te,n),u(Wl,l,n),t(l,Ue,n),t(l,ms,n),t(l,fe,n),u(os,l,n),t(l,s,n),u(c,l,n),t(l,ot,n),t(l,he,n),t(l,jt,n),u(ne,l,n),t(l,wt,n),t(l,Ie,n),t(l,ut,n),u(Ce,l,n),t(l,bt,n),t(l,$e,n),t(l,dt,n),t(l,ke,n),t(l,Ut,n),u(_e,l,n),t(l,ft,n),t(l,ge,n),t(l,ht,n),st[js].m(l,n),t(l,pt,n),u(xe,l,n),t(l,It,n),t(l,Ze,n),t(l,Ct,n),t(l,Be,n),t(l,$t,n),et[us].m(l,n),t(l,Mt,n),t(l,We,n),t(l,kt,n),u(Ae,l,n),t(l,_t,n),u(Ge,l,n),t(l,gt,n),t(l,ve,n),t(l,xt,n),u(Ve,l,n),t(l,Zt,n),u(Re,l,n),t(l,Bt,n),tt[ds].m(l,n),t(l,it,n),S&&S.m(l,n),t(l,rt,n),u(Xe,l,n),t(l,Wt,n),nt[fs].m(l,n),t(l,ct,n),u(Ye,l,n),t(l,At,n),t(l,Qe,n),t(l,Gt,n),u(Ee,l,n),t(l,vt,n),u(He,l,n),t(l,Vt,n),t(l,Ne,n),t(l,Rt,n),u(ze,l,n),t(l,Xt,n),t(l,Fe,n),t(l,Yt,n),u(Se,l,n),t(l,Qt,n),at[Is].m(l,n),t(l,Jt,n),L&&L.m(l,n),t(l,yt,n),u(Le,l,n),t(l,Et,n),t(l,De,n),t(l,Ht,n),u(qe,l,n),t(l,Nt,n),u(Pe,l,n),t(l,zt,n),t(l,Ke,n),t(l,Ft,n),u(Oe,l,n),t(l,St,n),t(l,mt,n),Lt=!0},p(l,[n]){const gn={};n&1&&(gn.fw=l[0]),x.$set(gn);let Dt=d;d=un(l),d!==Dt&&(pe(),y(lt[Dt],1,1,()=>{lt[Dt]=null}),ae(),Z=lt[d],Z||(Z=lt[d]=wn[d](l),Z.c()),J(Z,1),Z.m(B.parentNode,B));const xn={};n&2&&(xn.$$scope={dirty:n,ctx:l}),R.$set(xn);const Zn={};n&2&&(Zn.$$scope={dirty:n,ctx:l}),Tl.$set(Zn);const Bn={};n&2&&(Bn.$$scope={dirty:n,ctx:l}),ne.$set(Bn);let qt=js;js=dn(l),js!==qt&&(pe(),y(st[qt],1,1,()=>{st[qt]=null}),ae(),ws=st[js],ws||(ws=st[js]=bn[js](l),ws.c()),J(ws,1),ws.m(pt.parentNode,pt));let Pt=us;us=fn(l),us!==Pt&&(pe(),y(et[Pt],1,1,()=>{et[Pt]=null}),ae(),bs=et[us],bs||(bs=et[us]=Un[us](l),bs.c()),J(bs,1),bs.m(Mt.parentNode,Mt));let Kt=ds;ds=In(l),ds!==Kt&&(pe(),y(tt[Kt],1,1,()=>{tt[Kt]=null}),ae(),Us=tt[ds],Us||(Us=tt[ds]=hn[ds](l),Us.c()),J(Us,1),Us.m(it.parentNode,it)),l[0]==="tf"?S?n&1&&J(S,1):(S=An(l),S.c(),J(S,1),S.m(rt.parentNode,rt)):S&&(pe(),y(S,1,1,()=>{S=null}),ae());let Ot=fs;fs=$n(l),fs!==Ot&&(pe(),y(nt[Ot],1,1,()=>{nt[Ot]=null}),ae(),hs=nt[fs],hs||(hs=nt[fs]=Cn[fs](l),hs.c()),J(hs,1),hs.m(ct.parentNode,ct));let ln=Is;Is=_n(l),Is!==ln&&(pe(),y(at[ln],1,1,()=>{at[ln]=null}),ae(),Cs=at[Is],Cs||(Cs=at[Is]=kn[Is](l),Cs.c()),J(Cs,1),Cs.m(Jt.parentNode,Jt)),l[0]==="pt"?L?n&1&&J(L,1):(L=Gn(l),L.c(),J(L,1),L.m(yt.parentNode,yt)):L&&(pe(),y(L,1,1,()=>{L=null}),ae())},i(l){Lt||(J(x.$$.fragment,l),J(k.$$.fragment,l),J(Z),J(tl.$$.fragment,l),J(V.$$.fragment,l),J(R.$$.fragment,l),J(Ml.$$.fragment,l),J(il.$$.fragment,l),J(fl.$$.fragment,l),J(H.$$.fragment,l),J(hl.$$.fragment,l),J(el.$$.fragment,l),J(Zs.$$.fragment,l),J(Il.$$.fragment,l),J(Cl.$$.fragment,l),J(Ql.$$.fragment,l),J(Nl.$$.fragment,l),J(Fl.$$.fragment,l),J($l.$$.fragment,l),J(Pl.$$.fragment,l),J(kl.$$.fragment,l),J(Tl.$$.fragment,l),J(ss.$$.fragment,l),J(ts.$$.fragment,l),J(_l.$$.fragment,l),J(gl.$$.fragment,l),J(is.$$.fragment,l),J(Js.$$.fragment,l),J(Hs.$$.fragment,l),J(Zl.$$.fragment,l),J(Bl.$$.fragment,l),J(Wl.$$.fragment,l),J(os.$$.fragment,l),J(c.$$.fragment,l),J(ne.$$.fragment,l),J(Ce.$$.fragment,l),J(_e.$$.fragment,l),J(ws),J(xe.$$.fragment,l),J(bs),J(Ae.$$.fragment,l),J(Ge.$$.fragment,l),J(Ve.$$.fragment,l),J(Re.$$.fragment,l),J(Us),J(S),J(Xe.$$.fragment,l),J(hs),J(Ye.$$.fragment,l),J(Ee.$$.fragment,l),J(He.$$.fragment,l),J(ze.$$.fragment,l),J(Se.$$.fragment,l),J(Cs),J(L),J(Le.$$.fragment,l),J(qe.$$.fragment,l),J(Pe.$$.fragment,l),J(Oe.$$.fragment,l),Lt=!0)},o(l){y(x.$$.fragment,l),y(k.$$.fragment,l),y(Z),y(tl.$$.fragment,l),y(V.$$.fragment,l),y(R.$$.fragment,l),y(Ml.$$.fragment,l),y(il.$$.fragment,l),y(fl.$$.fragment,l),y(H.$$.fragment,l),y(hl.$$.fragment,l),y(el.$$.fragment,l),y(Zs.$$.fragment,l),y(Il.$$.fragment,l),y(Cl.$$.fragment,l),y(Ql.$$.fragment,l),y(Nl.$$.fragment,l),y(Fl.$$.fragment,l),y($l.$$.fragment,l),y(Pl.$$.fragment,l),y(kl.$$.fragment,l),y(Tl.$$.fragment,l),y(ss.$$.fragment,l),y(ts.$$.fragment,l),y(_l.$$.fragment,l),y(gl.$$.fragment,l),y(is.$$.fragment,l),y(Js.$$.fragment,l),y(Hs.$$.fragment,l),y(Zl.$$.fragment,l),y(Bl.$$.fragment,l),y(Wl.$$.fragment,l),y(os.$$.fragment,l),y(c.$$.fragment,l),y(ne.$$.fragment,l),y(Ce.$$.fragment,l),y(_e.$$.fragment,l),y(ws),y(xe.$$.fragment,l),y(bs),y(Ae.$$.fragment,l),y(Ge.$$.fragment,l),y(Ve.$$.fragment,l),y(Re.$$.fragment,l),y(Us),y(S),y(Xe.$$.fragment,l),y(hs),y(Ye.$$.fragment,l),y(Ee.$$.fragment,l),y(He.$$.fragment,l),y(ze.$$.fragment,l),y(Se.$$.fragment,l),y(Cs),y(L),y(Le.$$.fragment,l),y(qe.$$.fragment,l),y(Pe.$$.fragment,l),y(Oe.$$.fragment,l),Lt=!1},d(l){l&&(e(U),e(i),e(f),e(h),e(W),e(B),e(C),e(_),e(v),e(ks),e(X),e(nl),e(Al),e(G),e(Y),e(F),e(_s),e(al),e(Gl),e(gs),e(pl),e(Vl),e(ol),e(Q),e(jl),e(ul),e(E),e(bl),e(Ul),e(rl),e(cl),e(ll),e(Jl),e(sl),e(N),e(yl),e(Xl),e(z),e($),e(Ss),e(ie),e(Yl),e(Ls),e(re),e(El),e(Hl),e(ce),e(zl),e(Sl),e(As),e(Ll),e(Dl),e(ye),e(ql),e(Ds),e(Te),e(Kl),e(Ol),e(qs),e(me),e(ls),e(Ps),e(oe),e(es),e(ns),e(as),e(je),e(ps),e(Ks),e(we),e(Ms),e(Os),e(ue),e(rs),e(cs),e(be),e(ys),e(le),e(xl),e(se),e(ee),e(de),e(Ts),e(te),e(Ue),e(ms),e(fe),e(s),e(ot),e(he),e(jt),e(wt),e(Ie),e(ut),e(bt),e($e),e(dt),e(ke),e(Ut),e(ft),e(ge),e(ht),e(pt),e(It),e(Ze),e(Ct),e(Be),e($t),e(Mt),e(We),e(kt),e(_t),e(gt),e(ve),e(xt),e(Zt),e(Bt),e(it),e(rt),e(Wt),e(ct),e(At),e(Qe),e(Gt),e(vt),e(Vt),e(Ne),e(Rt),e(Xt),e(Fe),e(Yt),e(Qt),e(Jt),e(yt),e(Et),e(De),e(Ht),e(Nt),e(zt),e(Ke),e(Ft),e(St),e(mt)),e(M),b(x,l),b(k,l),lt[d].d(l),b(tl,l),b(V,l),b(R,l),b(Ml,l),b(il,l),b(fl,l),b(H,l),b(hl,l),b(el,l),b(Zs,l),b(Il,l),b(Cl,l),b(Ql,l),b(Nl,l),b(Fl,l),b($l,l),b(Pl,l),b(kl,l),b(Tl,l),b(ss,l),b(ts,l),b(_l,l),b(gl,l),b(is,l),b(Js,l),b(Hs,l),b(Zl,l),b(Bl,l),b(Wl,l),b(os,l),b(c,l),b(ne,l),b(Ce,l),b(_e,l),st[js].d(l),b(xe,l),et[us].d(l),b(Ae,l),b(Ge,l),b(Ve,l),b(Re,l),tt[ds].d(l),S&&S.d(l),b(Xe,l),nt[fs].d(l),b(Ye,l),b(Ee,l),b(He,l),b(ze,l),b(Se,l),at[Is].d(l),L&&L.d(l),b(Le,l),b(qe,l),b(Pe,l),b(Oe,l)}}}const Ta='{"title":"Token 分类","local":"Token 分类","sections":[{"title":"准备数据","local":"准备数据","sections":[{"title":"CoNLL-2003 数据集","local":"CoNLL-2003 数据集","sections":[],"depth":3},{"title":"处理数据","local":"处理数据","sections":[],"depth":3}],"depth":2},{"title":"使用 Trainer API 微调模型","local":"使用 Trainer API 微调模型","sections":[],"depth":2},{"title":"使用 Keras 微调模型","local":"使用 Keras 微调模型","sections":[{"title":"数据排序","local":"数据排序","sections":[],"depth":3},{"title":"定义模型","local":"定义模型","sections":[],"depth":3},{"title":"微调模型","local":"微调模型","sections":[],"depth":3},{"title":"评估指标","local":"评估指标","sections":[],"depth":3},{"title":"定义模型","local":"定义模型","sections":[],"depth":3},{"title":"微调模型","local":"微调模型","sections":[],"depth":3}],"depth":2},{"title":"自定义训练循环","local":"自定义训练循环","sections":[{"title":"做好训练前的准备","local":"做好训练前的准备","sections":[],"depth":3},{"title":"训练循环","local":"训练循环","sections":[],"depth":3}],"depth":2},{"title":"使用微调模型","local":"使用微调模型","sections":[],"depth":2}],"depth":1}';function ma(g,M,U){let i="pt";return Xn(()=>{const f=new URLSearchParams(window.location.search);U(0,i=f.get("fw")||"pt")}),[i]}class ha extends Yn{constructor(M){super(),Qn(this,M,ma,ya,Vn,{})}}export{ha as component};
