import{s as Hn,a as Rn,o as Nn,n as Es}from"../chunks/scheduler.cc52f4b9.js";import{S as Fn,i as zn,e as m,s as a,c as T,h as Sn,a as o,d as e,b as p,f as ln,g as w,j as d,k as tl,l as Ln,m as t,n as j,o as y,u as Me,t as J,p as b,v as ie}from"../chunks/index.9480bb2b.js";import{T as re}from"../chunks/Tip.f7b80743.js";import{C as Dn,H as ml,E as qn}from"../chunks/MermaidChart.svelte_svelte_type_style_lang.52103c90.js";import{Y as Xn}from"../chunks/Youtube.7b12d9e8.js";import{C as I}from"../chunks/CodeBlock.c5404643.js";import{D as En}from"../chunks/DocNotebookDropdown.ea74f0e0.js";import{F as Pn}from"../chunks/FrameworkSwitchCourse.42d12053.js";function Kn(g){let M,u;return M=new En({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(){T(M.$$.fragment)},l(i){w(M.$$.fragment,i)},m(i,f){j(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 On(g){let M,u;return M=new En({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(){T(M.$$.fragment)},l(i){w(M.$$.fragment,i)},m(i,f){j(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='💡 只要您的數據集由帶有相應標籤的分割成單詞並的文本組成，您就能夠將這裡描述的數據處理過程應用到您自己的數據集。如果需要複習如何在.Dataset中加載自定義數據，請參閱<a href="/course/chapter5">Chapter 5</a>。';return{c(){M=m("p"),M.innerHTML=u},l(i){M=o(i,"P",{"data-svelte-h":!0}),d(M)!=="svelte-196ipzf"&&(M.innerHTML=u)},m(i,f){t(i,M,f)},p:Es,d(i){i&&e(M)}}}function sa(g){let M,u="✏️ <strong>輪到你了！</strong> 使用 POS 或chunking標籤識別同一個句子。";return{c(){M=m("p"),M.innerHTML=u},l(i){M=o(i,"P",{"data-svelte-h":!0}),d(M)!=="svelte-vqz3tk"&&(M.innerHTML=u)},m(i,f){t(i,M,f)},p:Es,d(i){i&&e(M)}}}function ea(g){let M,u="✏️ <strong>輪到你了！</strong> 一些研究人員更喜歡每個詞只歸屬一個標籤, 並分配 <code>-100</code> 給定詞中的其他子標記。這是為了避免分解成大量子標記的長詞對損失造成嚴重影響。按照此規則更改前一個函數使標籤與輸入id對齊。";return{c(){M=m("p"),M.innerHTML=u},l(i){M=o(i,"P",{"data-svelte-h":!0}),d(M)!=="svelte-q7rrku"&&(M.innerHTML=u)},m(i,f){t(i,M,f)},p:Es,d(i){i&&e(M)}}}function ta(g){let M,u,i,f="使用Keras的實際代碼將與之前非常相似;唯一的變化是將數據整理成批處理的方式和指標計算函數。",x;return M=new ml({props:{title:"使用 Keras 微調模型",local:"使用-keras-微調模型",headingTag:"h2"}}),{c(){T(M.$$.fragment),u=a(),i=m("p"),i.textContent=f},l(h){w(M.$$.fragment,h),u=p(h),i=o(h,"P",{"data-svelte-h":!0}),d(i)!=="svelte-1ay6z2d"&&(i.textContent=f)},m(h,_){j(M,h,_),t(h,u,_),t(h,i,_),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 na(g){let M,u,i,f="使用 <code>Trainer</code> 的實際代碼會和以前一樣；唯一的變化是數據整理成時批處理的方式和度量計算函數。",x;return M=new ml({props:{title:"使用 Trainer API 微調模型",local:"使用-trainer-api-微調模型",headingTag:"h2"}}),{c(){T(M.$$.fragment),u=a(),i=m("p"),i.innerHTML=f},l(h){w(M.$$.fragment,h),u=p(h),i=o(h,"P",{"data-svelte-h":!0}),d(i)!=="svelte-1higdwj"&&(i.innerHTML=f)},m(h,_){j(M,h,_),t(h,u,_),t(h,i,_),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 aa(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(){T(M.$$.fragment)},l(i){w(M.$$.fragment,i)},m(i,f){j(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 pa(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(){T(M.$$.fragment)},l(i){w(M.$$.fragment,i)},m(i,f){j(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 Ma(g){let M,u="我們的數據整理器已準備就緒！現在，讓我們用它來製作一個帶有<code>to_tf_dataset()</code>方法的<code>tf.data.Dataset</code>。",i,f,x,h,_="Next stop: the model itself.",B;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=m("p"),M.innerHTML=u,i=a(),T(f.$$.fragment),x=a(),h=m("p"),h.textContent=_},l(U){M=o(U,"P",{"data-svelte-h":!0}),d(M)!=="svelte-1hvqwv4"&&(M.innerHTML=u),i=p(U),w(f.$$.fragment,U),x=p(U),h=o(U,"P",{"data-svelte-h":!0}),d(h)!=="svelte-68qel6"&&(h.textContent=_)},m(U,W){t(U,M,W),t(U,i,W),j(f,U,W),t(U,x,W),t(U,h,W),B=!0},i(U){B||(J(f.$$.fragment,U),B=!0)},o(U){y(f.$$.fragment,U),B=!1},d(U){U&&(e(M),e(i),e(x),e(h)),b(f,U)}}}function ia(g){let M,u="正如我們所看到的，第二組標籤的長度已經使用 <code>-100</code> 填充到與第一組標籤相同。";return{c(){M=m("p"),M.innerHTML=u},l(i){M=o(i,"P",{"data-svelte-h":!0}),d(M)!=="svelte-1hygkvj"&&(M.innerHTML=u)},m(i,f){t(i,M,f)},i:Es,o:Es,d(i){i&&e(M)}}}function Yn(g){let M,u,i,f="由於我們正在研究Token分類問題，因此我們將使用 <code>AutoModelForTokenClassification</code> 類。定義這個模型時要記住的主要事情是傳遞一些關於我們的標籤數量的信息。執行此操作的最簡單方法是將該數字傳遞給 <code>num_labels</code> 參數，但是如果我們想要一個很好的推理小部件，就像我們在本節開頭看到的那樣，最好設置正確的標籤對應關係。",x,h,_="它們應該由兩個字典設置， <code>id2label</code> 和 <code>label2id</code> ，其中包含從 ID 到標籤的映射，反之亦然：",B,U,W,Z,C="現在我們可以將它們傳遞給 <code>AutoModelForTokenClassification.from_pretrained()</code> 方法，它們將在模型的配置中設置，然後保存並上傳到Hub：",G,k,V,X,El='就像我們在<a href="/course/chapter3">第三章</a>,定義我們的 <code>AutoModelForSequenceClassification</code> ，創建模型會發出警告，提示一些權重未被使用（來自預訓練頭的權重）和一些其他權重被隨機初始化（來自新Token分類頭的權重），我們將要訓練這個模型。我們將在一分鐘內完成，但首先讓我們仔細檢查我們的模型是否具有正確數量的標籤：',Hl,Y,nl,Q,al,P,Yl,A,Nl,E,S="現在，我們已準備好訓練模型了！不過，我們首先要做兩件事：應該登錄到Hugging Face並定義我們的訓練超參數。如果你在notebook上工作，有一個便利功能可以幫助你做到這一點：",Fl,H,L,K,$s="這將顯示一個小部件，您可以在其中輸入您的 Hugging Face 賬號和密碼。",pl,O,zl="如果您不是在notebook上工作，只需在終端中輸入以下行：",N,Tl,Ml,ll,Sl="登錄後，我們可以準備編譯模型所需的一切。🤗 Transformers提供了一個方便的<code>create_optimizer()</code> 函數，該函數將為您提供一個<code>AdamW</code>優化器，其中包含適當的權重衰減和學習速率衰減設置，與內置的<code>Adam</code>優化器相似，這兩者都將提高模型的性能：",R,wl,il,F,jl="還要注意，我們不為<code>compile()</code>提供<code>loss</code>參數。這是因為模型實際上可以在內部計算損失 - 如果您編譯時沒有損失並在輸入字典中提供標籤（就像我們在數據集中所做的那樣），那麼模型將使用該內部損失進行訓練，這將適用於您選擇的任務和模型類型。",bl,dl,ul="接下來，我們定義一個<code>PushToHubCallback</code>，以便在訓練期間將模型上傳到 Hub，並使用該回調來擬合模型：",rl,z,Ul,fl,hl='您之前已經看過其中的大部分內容：我們設置了一些超參數（例如學習率、要訓練的 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> .',cl,sl,Ql,v,ks="請注意，當訓練發生時，每次保存模型時（這裡是每個epooch），它都會在後臺上傳到 Hub。這樣，如有必要，您將能夠在另一臺機器上繼續您的訓練。",Jl,el,_s="在此階段，您可以使用模型中心上的推理小組件來測試模型並與朋友共享。您已經成功微調了令牌分類任務的模型 - 恭喜！但是，我們的模型到底有多好呢？我們應該評估一些指標來找出答案。",yl;return M=new ml({props:{title:"定義模型",local:"定義模型",headingTag:"h3"}}),U=new I({props:{code:"aWQybGFiZWwlMjAlM0QlMjAlN0JpJTNBJTIwbGFiZWwlMjBmb3IlMjBpJTJDJTIwbGFiZWwlMjBpbiUyMGVudW1lcmF0ZShsYWJlbF9uYW1lcyklN0QlMEFsYWJlbDJpZCUyMCUzRCUyMCU3QnYlM0ElMjBrJTIwZm9yJTIwayUyQyUyMHYlMjBpbiUyMGlkMmxhYmVsLml0ZW1zKCklN0Q=",highlighted:`id2label = {i: label <span class="hljs-keyword">for</span> i, label <span class="hljs-keyword">in</span> <span class="hljs-built_in">enumerate</span>(label_names)}
label2id = {v: k <span class="hljs-keyword">for</span> k, v <span class="hljs-keyword">in</span> id2label.items()}`,wrap:!1}}),k=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}}),Y=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}}),P=new re({props:{warning:!0,$$slots:{default:[ra]},$$scope:{ctx:g}}}),A=new ml({props:{title:"微調模型",local:"微調模型",headingTag:"h3"}}),H=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}}),Tl=new I({props:{code:"aHVnZ2luZ2ZhY2UtY2xpJTIwbG9naW4=",highlighted:"huggingface-cli login",wrap:!1}}),wl=new I({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMGNyZWF0ZV9vcHRpbWl6ZXIlMEFpbXBvcnQlMjB0ZW5zb3JmbG93JTIwYXMlMjB0ZiUwQSUwQSUyMyUyMFRyYWluJTIwaW4lMjBtaXhlZC1wcmVjaXNpb24lMjBmbG9hdDE2JTBBJTIzJTIwQ29tbWVudCUyMHRoaXMlMjBsaW5lJTIwb3V0JTIwaWYlMjB5b3UncmUlMjB1c2luZyUyMGElMjBHUFUlMjB0aGF0JTIwd2lsbCUyMG5vdCUyMGJlbmVmaXQlMjBmcm9tJTIwdGhpcyUwQXRmLmtlcmFzLm1peGVkX3ByZWNpc2lvbi5zZXRfZ2xvYmFsX3BvbGljeSglMjJtaXhlZF9mbG9hdDE2JTIyKSUwQSUwQSUyMyUyMFRoZSUyMG51bWJlciUyMG9mJTIwdHJhaW5pbmclMjBzdGVwcyUyMGlzJTIwdGhlJTIwbnVtYmVyJTIwb2YlMjBzYW1wbGVzJTIwaW4lMjB0aGUlMjBkYXRhc2V0JTJDJTIwZGl2aWRlZCUyMGJ5JTIwdGhlJTIwYmF0Y2glMjBzaXplJTIwdGhlbiUyMG11bHRpcGxpZWQlMEElMjMlMjBieSUyMHRoZSUyMHRvdGFsJTIwbnVtYmVyJTIwb2YlMjBlcG9jaHMuJTIwTm90ZSUyMHRoYXQlMjB0aGUlMjB0Zl90cmFpbl9kYXRhc2V0JTIwaGVyZSUyMGlzJTIwYSUyMGJhdGNoZWQlMjB0Zi5kYXRhLkRhdGFzZXQlMkMlMEElMjMlMjBub3QlMjB0aGUlMjBvcmlnaW5hbCUyMEh1Z2dpbmclMjBGYWNlJTIwRGF0YXNldCUyQyUyMHNvJTIwaXRzJTIwbGVuKCklMjBpcyUyMGFscmVhZHklMjBudW1fc2FtcGxlcyUyMCUyRiUyRiUyMGJhdGNoX3NpemUuJTBBbnVtX2Vwb2NocyUyMCUzRCUyMDMlMEFudW1fdHJhaW5fc3RlcHMlMjAlM0QlMjBsZW4odGZfdHJhaW5fZGF0YXNldCklMjAqJTIwbnVtX2Vwb2NocyUwQSUwQW9wdGltaXplciUyQyUyMHNjaGVkdWxlJTIwJTNEJTIwY3JlYXRlX29wdGltaXplciglMEElMjAlMjAlMjAlMjBpbml0X2xyJTNEMmUtNSUyQyUwQSUyMCUyMCUyMCUyMG51bV93YXJtdXBfc3RlcHMlM0QwJTJDJTBBJTIwJTIwJTIwJTIwbnVtX3RyYWluX3N0ZXBzJTNEbnVtX3RyYWluX3N0ZXBzJTJDJTBBJTIwJTIwJTIwJTIwd2VpZ2h0X2RlY2F5X3JhdGUlM0QwLjAxJTJDJTBBKSUwQW1vZGVsLmNvbXBpbGUob3B0aW1pemVyJTNEb3B0aW1pemVyKQ==",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> create_optimizer
<span class="hljs-keyword">import</span> tensorflow <span class="hljs-keyword">as</span> tf

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

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

optimizer, schedule = create_optimizer(
    init_lr=<span class="hljs-number">2e-5</span>,
    num_warmup_steps=<span class="hljs-number">0</span>,
    num_train_steps=num_train_steps,
    weight_decay_rate=<span class="hljs-number">0.01</span>,
)
model.<span class="hljs-built_in">compile</span>(optimizer=optimizer)`,wrap:!1}}),z=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 re({props:{$$slots:{default:[ca]},$$scope:{ctx:g}}}),{c(){T(M.$$.fragment),u=a(),i=m("p"),i.innerHTML=f,x=a(),h=m("p"),h.innerHTML=_,B=a(),T(U.$$.fragment),W=a(),Z=m("p"),Z.innerHTML=C,G=a(),T(k.$$.fragment),V=a(),X=m("p"),X.innerHTML=El,Hl=a(),T(Y.$$.fragment),nl=a(),T(Q.$$.fragment),al=a(),T(P.$$.fragment),Yl=a(),T(A.$$.fragment),Nl=a(),E=m("p"),E.textContent=S,Fl=a(),T(H.$$.fragment),L=a(),K=m("p"),K.textContent=$s,pl=a(),O=m("p"),O.textContent=zl,N=a(),T(Tl.$$.fragment),Ml=a(),ll=m("p"),ll.innerHTML=Sl,R=a(),T(wl.$$.fragment),il=a(),F=m("p"),F.innerHTML=jl,bl=a(),dl=m("p"),dl.innerHTML=ul,rl=a(),T(z.$$.fragment),Ul=a(),fl=m("p"),fl.innerHTML=hl,cl=a(),T(sl.$$.fragment),Ql=a(),v=m("p"),v.textContent=ks,Jl=a(),el=m("p"),el.textContent=_s},l(r){w(M.$$.fragment,r),u=p(r),i=o(r,"P",{"data-svelte-h":!0}),d(i)!=="svelte-1min3sz"&&(i.innerHTML=f),x=p(r),h=o(r,"P",{"data-svelte-h":!0}),d(h)!=="svelte-6jnith"&&(h.innerHTML=_),B=p(r),w(U.$$.fragment,r),W=p(r),Z=o(r,"P",{"data-svelte-h":!0}),d(Z)!=="svelte-a1wka0"&&(Z.innerHTML=C),G=p(r),w(k.$$.fragment,r),V=p(r),X=o(r,"P",{"data-svelte-h":!0}),d(X)!=="svelte-1t3x82c"&&(X.innerHTML=El),Hl=p(r),w(Y.$$.fragment,r),nl=p(r),w(Q.$$.fragment,r),al=p(r),w(P.$$.fragment,r),Yl=p(r),w(A.$$.fragment,r),Nl=p(r),E=o(r,"P",{"data-svelte-h":!0}),d(E)!=="svelte-lwyrol"&&(E.textContent=S),Fl=p(r),w(H.$$.fragment,r),L=p(r),K=o(r,"P",{"data-svelte-h":!0}),d(K)!=="svelte-zkdh66"&&(K.textContent=$s),pl=p(r),O=o(r,"P",{"data-svelte-h":!0}),d(O)!=="svelte-pruo9h"&&(O.textContent=zl),N=p(r),w(Tl.$$.fragment,r),Ml=p(r),ll=o(r,"P",{"data-svelte-h":!0}),d(ll)!=="svelte-kol9d8"&&(ll.innerHTML=Sl),R=p(r),w(wl.$$.fragment,r),il=p(r),F=o(r,"P",{"data-svelte-h":!0}),d(F)!=="svelte-2u3hy3"&&(F.innerHTML=jl),bl=p(r),dl=o(r,"P",{"data-svelte-h":!0}),d(dl)!=="svelte-jv6tr4"&&(dl.innerHTML=ul),rl=p(r),w(z.$$.fragment,r),Ul=p(r),fl=o(r,"P",{"data-svelte-h":!0}),d(fl)!=="svelte-1hzakdn"&&(fl.innerHTML=hl),cl=p(r),w(sl.$$.fragment,r),Ql=p(r),v=o(r,"P",{"data-svelte-h":!0}),d(v)!=="svelte-phco4r"&&(v.textContent=ks),Jl=p(r),el=o(r,"P",{"data-svelte-h":!0}),d(el)!=="svelte-1m3wx0m"&&(el.textContent=_s)},m(r,$){j(M,r,$),t(r,u,$),t(r,i,$),t(r,x,$),t(r,h,$),t(r,B,$),j(U,r,$),t(r,W,$),t(r,Z,$),t(r,G,$),j(k,r,$),t(r,V,$),t(r,X,$),t(r,Hl,$),j(Y,r,$),t(r,nl,$),j(Q,r,$),t(r,al,$),j(P,r,$),t(r,Yl,$),j(A,r,$),t(r,Nl,$),t(r,E,$),t(r,Fl,$),j(H,r,$),t(r,L,$),t(r,K,$),t(r,pl,$),t(r,O,$),t(r,N,$),j(Tl,r,$),t(r,Ml,$),t(r,ll,$),t(r,R,$),j(wl,r,$),t(r,il,$),t(r,F,$),t(r,bl,$),t(r,dl,$),t(r,rl,$),j(z,r,$),t(r,Ul,$),t(r,fl,$),t(r,cl,$),j(sl,r,$),t(r,Ql,$),t(r,v,$),t(r,Jl,$),t(r,el,$),yl=!0},i(r){yl||(J(M.$$.fragment,r),J(U.$$.fragment,r),J(k.$$.fragment,r),J(Y.$$.fragment,r),J(Q.$$.fragment,r),J(P.$$.fragment,r),J(A.$$.fragment,r),J(H.$$.fragment,r),J(Tl.$$.fragment,r),J(wl.$$.fragment,r),J(z.$$.fragment,r),J(sl.$$.fragment,r),yl=!0)},o(r){y(M.$$.fragment,r),y(U.$$.fragment,r),y(k.$$.fragment,r),y(Y.$$.fragment,r),y(Q.$$.fragment,r),y(P.$$.fragment,r),y(A.$$.fragment,r),y(H.$$.fragment,r),y(Tl.$$.fragment,r),y(wl.$$.fragment,r),y(z.$$.fragment,r),y(sl.$$.fragment,r),yl=!1},d(r){r&&(e(u),e(i),e(x),e(h),e(B),e(W),e(Z),e(G),e(V),e(X),e(Hl),e(nl),e(al),e(Yl),e(Nl),e(E),e(Fl),e(L),e(K),e(pl),e(O),e(N),e(Ml),e(ll),e(R),e(il),e(F),e(bl),e(dl),e(rl),e(Ul),e(fl),e(cl),e(Ql),e(v),e(Jl),e(el)),b(M,r),b(U,r),b(k,r),b(Y,r),b(Q,r),b(P,r),b(A,r),b(H,r),b(Tl,r),b(wl,r),b(z,r),b(sl,r)}}}function ra(g){let M,u="⚠️ 如果您的模型標籤數量錯誤，則在稍後調用 <code>model.fit()</code> 時將收到一個模糊的錯誤。調試起來可能很煩人，因此請確保執行此檢查以確認您具有預期的標籤數。";return{c(){M=m("p"),M.innerHTML=u},l(i){M=o(i,"P",{"data-svelte-h":!0}),d(M)!=="svelte-yordje"&&(M.innerHTML=u)},m(i,f){t(i,M,f)},p:Es,d(i){i&&e(M)}}}function ca(g){let M,u="💡 如果您正在使用的輸出目錄已經存在，那麼輸出目錄必須是從同一個存儲庫clone下來的。如果不是，您將在聲明 <code>model.fit()</code> 時遇到錯誤，並且需要設置一個新名稱。";return{c(){M=m("p"),M.innerHTML=u},l(i){M=o(i,"P",{"data-svelte-h":!0}),d(M)!=="svelte-kwyipi"&&(M.innerHTML=u)},m(i,f){t(i,M,f)},p:Es,d(i){i&&e(M)}}}function Ja(g){let M,u='用於評估Token分類預測的傳統框架是 <a href="https://github.com/chakki-works/seqeval" rel="nofollow"><em>seqeval</em></a>. 要使用此指標，我們首先需要安裝seqeval庫：',i,f,x,h,_='然後我們可以通過加載它 <code>load_metric()</code> 函數就像我們在<a href="/course/chapter3">第三章</a>做的那樣：',B;return f=new I({props:{code:"IXBpcCUyMGluc3RhbGwlMjBzZXFldmFs",highlighted:"!pip install seqeval",wrap:!1}}),{c(){M=m("p"),M.innerHTML=u,i=a(),T(f.$$.fragment),x=a(),h=m("p"),h.innerHTML=_},l(U){M=o(U,"P",{"data-svelte-h":!0}),d(M)!=="svelte-16kw28d"&&(M.innerHTML=u),i=p(U),w(f.$$.fragment,U),x=p(U),h=o(U,"P",{"data-svelte-h":!0}),d(h)!=="svelte-14sahcb"&&(h.innerHTML=_)},m(U,W){t(U,M,W),t(U,i,W),j(f,U,W),t(U,x,W),t(U,h,W),B=!0},i(U){B||(J(f.$$.fragment,U),B=!0)},o(U){y(f.$$.fragment,U),B=!1},d(U){U&&(e(M),e(i),e(x),e(h)),b(f,U)}}}function ya(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,_,B,U,W='然後我們可以通過加載它 <code>load_metric()</code> 函數就像我們在<a href="/course/chapter3">第三章</a>做的那樣：',Z;return _=new I({props:{code:"IXBpcCUyMGluc3RhbGwlMjBzZXFldmFs",highlighted:"!pip install seqeval",wrap:!1}}),{c(){M=m("p"),M.innerHTML=u,i=a(),f=m("p"),f.innerHTML=x,h=a(),T(_.$$.fragment),B=a(),U=m("p"),U.innerHTML=W},l(C){M=o(C,"P",{"data-svelte-h":!0}),d(M)!=="svelte-zayi6n"&&(M.innerHTML=u),i=p(C),f=o(C,"P",{"data-svelte-h":!0}),d(f)!=="svelte-16kw28d"&&(f.innerHTML=x),h=p(C),w(_.$$.fragment,C),B=p(C),U=o(C,"P",{"data-svelte-h":!0}),d(U)!=="svelte-14sahcb"&&(U.innerHTML=W)},m(C,G){t(C,M,G),t(C,i,G),t(C,f,G),t(C,h,G),j(_,C,G),t(C,B,G),t(C,U,G),Z=!0},i(C){Z||(J(_.$$.fragment,C),Z=!0)},o(C){y(_.$$.fragment,C),Z=!1},d(C){C&&(e(M),e(i),e(f),e(h),e(B),e(U)),b(_,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,_,B,U,W,Z,C="與我們的模型相比，您的模型做得如何？如果您獲得類似的數字，那麼您的訓練就是成功的！",G;return _=new I({props:{code:"aW1wb3J0JTIwbnVtcHklMjBhcyUyMG5wJTBBJTBBYWxsX3ByZWRpY3Rpb25zJTIwJTNEJTIwJTVCJTVEJTBBYWxsX2xhYmVscyUyMCUzRCUyMCU1QiU1RCUwQWZvciUyMGJhdGNoJTIwaW4lMjB0Zl9ldmFsX2RhdGFzZXQlM0ElMEElMjAlMjAlMjAlMjBsb2dpdHMlMjAlM0QlMjBtb2RlbC5wcmVkaWN0KGJhdGNoKSU1QiUyMmxvZ2l0cyUyMiU1RCUwQSUyMCUyMCUyMCUyMGxhYmVscyUyMCUzRCUyMGJhdGNoJTVCJTIybGFiZWxzJTIyJTVEJTBBJTIwJTIwJTIwJTIwcHJlZGljdGlvbnMlMjAlM0QlMjBucC5hcmdtYXgobG9naXRzJTJDJTIwYXhpcyUzRC0xKSUwQSUyMCUyMCUyMCUyMGZvciUyMHByZWRpY3Rpb24lMkMlMjBsYWJlbCUyMGluJTIwemlwKHByZWRpY3Rpb25zJTJDJTIwbGFiZWxzKSUzQSUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMGZvciUyMHByZWRpY3RlZF9pZHglMkMlMjBsYWJlbF9pZHglMjBpbiUyMHppcChwcmVkaWN0aW9uJTJDJTIwbGFiZWwpJTNBJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwaWYlMjBsYWJlbF9pZHglMjAlM0QlM0QlMjAtMTAwJTNBJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwY29udGludWUlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBhbGxfcHJlZGljdGlvbnMuYXBwZW5kKGxhYmVsX25hbWVzJTVCcHJlZGljdGVkX2lkeCU1RCklMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBhbGxfbGFiZWxzLmFwcGVuZChsYWJlbF9uYW1lcyU1QmxhYmVsX2lkeCU1RCklMEFtZXRyaWMuY29tcHV0ZShwcmVkaWN0aW9ucyUzRCU1QmFsbF9wcmVkaWN0aW9ucyU1RCUyQyUyMHJlZmVyZW5jZXMlM0QlNUJhbGxfbGFiZWxzJTVEKQ==",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(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}}),U=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=m("p"),M.innerHTML=u,i=a(),f=m("p"),f.innerHTML=x,h=a(),T(_.$$.fragment),B=a(),T(U.$$.fragment),W=a(),Z=m("p"),Z.textContent=C},l(k){M=o(k,"P",{"data-svelte-h":!0}),d(M)!=="svelte-1ir5cl6"&&(M.innerHTML=u),i=p(k),f=o(k,"P",{"data-svelte-h":!0}),d(f)!=="svelte-840r4r"&&(f.innerHTML=x),h=p(k),w(_.$$.fragment,k),B=p(k),w(U.$$.fragment,k),W=p(k),Z=o(k,"P",{"data-svelte-h":!0}),d(Z)!=="svelte-pcd2bo"&&(Z.textContent=C)},m(k,V){t(k,M,V),t(k,i,V),t(k,f,V),t(k,h,V),j(_,k,V),t(k,B,V),j(U,k,V),t(k,W,V),t(k,Z,V),G=!0},i(k){G||(J(_.$$.fragment,k),J(U.$$.fragment,k),G=!0)},o(k){y(_.$$.fragment,k),y(U.$$.fragment,k),G=!1},d(k){k&&(e(M),e(i),e(f),e(h),e(B),e(W),e(Z)),b(_,k),b(U,k)}}}function oa(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,_,B,U,W="現在已經完成了，我們幾乎準備好定義我們的 <code>Trainer</code> .我們只需要一個 <code>model</code> 微調！",Z;return _=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=m("p"),M.innerHTML=u,i=a(),f=m("p"),f.innerHTML=x,h=a(),T(_.$$.fragment),B=a(),U=m("p"),U.innerHTML=W},l(C){M=o(C,"P",{"data-svelte-h":!0}),d(M)!=="svelte-1ir5cl6"&&(M.innerHTML=u),i=p(C),f=o(C,"P",{"data-svelte-h":!0}),d(f)!=="svelte-840r4r"&&(f.innerHTML=x),h=p(C),w(_.$$.fragment,C),B=p(C),U=o(C,"P",{"data-svelte-h":!0}),d(U)!=="svelte-b1rvpq"&&(U.innerHTML=W)},m(C,G){t(C,M,G),t(C,i,G),t(C,f,G),t(C,h,G),j(_,C,G),t(C,B,G),t(C,U,G),Z=!0},i(C){Z||(J(_.$$.fragment,C),Z=!0)},o(C){y(_.$$.fragment,C),Z=!1},d(C){C&&(e(M),e(i),e(f),e(h),e(B),e(U)),b(_,C)}}}function Qn(g){let M,u,i,f="由於我們正在研究Token分類問題，因此我們將使用 <code>AutoModelForTokenClassification</code> 類。定義這個模型時要記住的主要事情是傳遞一些關於我們的標籤數量的信息。執行此操作的最簡單方法是將該數字傳遞給 <code>num_labels</code> 參數，但是如果我們想要一個很好的推理小部件，就像我們在本節開頭看到的那樣，最好設置正確的標籤對應關係。",x,h,_="它們應該由兩個字典設置， <code>id2label</code> 和 <code>label2id</code> ，其中包含從 ID 到標籤的映射，反之亦然：",B,U,W,Z,C="現在我們可以將它們傳遞給 <code>AutoModelForTokenClassification.from_pretrained()</code> 方法，它們將在模型的配置中設置，然後保存並上傳到Hub：",G,k,V,X,El='就像我們在<a href="/course/chapter3">第三章</a>,定義我們的 <code>AutoModelForSequenceClassification</code> ，創建模型會發出警告，提示一些權重未被使用（來自預訓練頭的權重）和一些其他權重被隨機初始化（來自新Token分類頭的權重），我們將要訓練這個模型。我們將在一分鐘內完成，但首先讓我們仔細檢查我們的模型是否具有正確數量的標籤：',Hl,Y,nl,Q,al,P,Yl,A,Nl,E,S="我們現在準備好訓練我們的模型了！在定義我們的 <code>Trainer</code>之前，我們只需要做最後兩件事：登錄 Hugging Face 並定義我們的訓練參數。如果您在notebook上工作，有一個方便的功能可以幫助您：",Fl,H,L,K,$s="這將顯示一個小部件，您可以在其中輸入您的 Hugging Face 賬號和密碼。如果您不是在notebook上工作，只需在終端中輸入以下行：",pl,O,zl,N,Tl="Once this is done, we can define our <code>TrainingArguments</code>:",Ml,ll,Sl,R,wl='您之前已經看過其中的大部分內容：我們設置了一些超參數（例如學習率、要訓練的 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,F,jl,bl,dl="最後，我們只是將所有內容傳遞給 <code>Trainer</code> 並啟動訓練：",ul,rl,z,Ul,fl="請注意，當訓練發生時，每次保存模型時（這裡是每個epooch），它都會在後臺上傳到 Hub。這樣，如有必要，您將能夠在另一臺機器上繼續您的訓練。",hl,cl,sl="訓練完成後，我們使用 <code>push_to_hub()</code> 確保我們上傳模型的最新版本",Ql,v,ks,Jl,el="This command returns the URL of the commit it just did, if you want to inspect it:",_s,yl,r,$,gs="這 <code>Trainer</code> 還創建了一張包含所有評估結果的模型卡並上傳。在此階段，您可以使用模型中心上的推理小部件來測試您的模型並與您的朋友分享。您已成功在Token分類任務上微調模型 - 恭喜！",Hs,Il,Tt="如果您想更深入地瞭解訓練循環，我們現在將向您展示如何使用 🤗 Accelerate 做同樣的事情。",Ns,Cl,Fs,$l,ce='現在讓我們看一下完整的訓練循環，這樣您可以輕鬆定義所需的部分。它看起來很像我們在<a href="/course/chapter3/4">第三章</a>, 所做的，對評估進行了一些更改。',Ll,xs,zs,kl,Je="首先我們需要為我們的數據集構建 <code>DataLoader</code> 。我們將重用我們的 <code>data_collator</code> 作為一個 <code>collate_fn</code> 並打亂訓練集，但不打亂驗證集：",Dl,ql,Pl,Zs,ye="接下來，我們重新實例化我們的模型，以確保我們不會從之前的訓練繼續訓練，而是再次從 BERT 預訓練模型開始：",Kl,Ol,ls,ss,Bs="然後我們將需要一個優化器。我們將使用經典 <code>AdamW</code> ，這就像 <code>Adam</code> ，但在應用權重衰減的方式上進行了改進：",me,es,ts,Ws,oe="Once we have all those objects, we can send them to the <code>accelerator.prepare()</code> method:",ns,Gs,Ss,_l,Ls,gl,Te="現在我們已經發送了我們的 <code>train_dataloader</code> 到 <code>accelerator.prepare()</code> ，我們可以使用它的長度來計算訓練步驟的數量。請記住，我們應該始終在準備好dataloader後執行此操作，因為該方法會改變其長度。我們使用經典線性學習率調度：",as,As,Ds,xl,we="最後，要將我們的模型推送到 Hub，我們需要創建一個 <code>Repository</code> 工作文件夾中的對象。如果您尚未登錄，請先登錄 Hugging Face。我們將從我們想要為模型提供的模型 ID 中確定存儲庫名稱（您可以自由地用自己的選擇替換 <code>repo_name</code> ；它只需要包含您的用戶名，可以使用<code>get_full_repo_name()</code>函數的查看目前的repo_name）：",ps,vs,qs,ol,Ps,Zl,je="Then we can clone that repository in a local folder. If it already exists, this local folder should be an existing clone of the repository we are working with:",Ms,is,rs,Vs,be="We can now upload anything we save in <code>output_dir</code> by calling the <code>repo.push_to_hub()</code> method. This will help us upload the intermediate models at the end of each epoch.",cs,Rs,Ks,Bl,Os,Wl,wt="我們現在準備編寫完整的訓練循環。為了簡化它的評估部分，我們定義了這個 <code>postprocess()</code> 接受預測和標籤並將它們轉換為字符串列表的函數，也就是 <code>metric</code>對象需要的輸入格式：",le,Gl,se,Al,de="然後我們可以編寫訓練循環。在定義一個進度條來跟蹤訓練的進行後，循環分為三個部分：",Js,Xs,ue="<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>",ys,ms,Ys="這是訓練循環的完整代碼：",ee,vl,Ue,os,Qs="果這是您第一次看到用 🤗 Accelerate 保存的模型，讓我們花點時間檢查一下它附帶的三行代碼：",te,Vl,ne,Rl,jt=`第一行是不言自明的：它告訴所有進程等到都處於那個階段再繼續(阻塞)。這是為了確保在保存之前，我們在每個過程中都有相同的模型。然後獲取<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>。`,ae,Xl,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>中查看我們使用這個代碼訓練的模型。如果你想測試訓練循環的任何調整，你可以直接通過編輯上面顯示的代碼來實現它們!',Ts;return M=new ml({props:{title:"定義模型",local:"定義模型",headingTag:"h3"}}),U=new I({props:{code:"aWQybGFiZWwlMjAlM0QlMjAlN0JpJTNBJTIwbGFiZWwlMjBmb3IlMjBpJTJDJTIwbGFiZWwlMjBpbiUyMGVudW1lcmF0ZShsYWJlbF9uYW1lcyklN0QlMEFsYWJlbDJpZCUyMCUzRCUyMCU3QnYlM0ElMjBrJTIwZm9yJTIwayUyQyUyMHYlMjBpbiUyMGlkMmxhYmVsLml0ZW1zKCklN0Q=",highlighted:`id2label = {i: label <span class="hljs-keyword">for</span> i, label <span class="hljs-keyword">in</span> <span class="hljs-built_in">enumerate</span>(label_names)}
label2id = {v: k <span class="hljs-keyword">for</span> k, v <span class="hljs-keyword">in</span> id2label.items()}`,wrap:!1}}),k=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}}),Y=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}}),P=new re({props:{warning:!0,$$slots:{default:[Ta]},$$scope:{ctx:g}}}),A=new ml({props:{title:"微調模型",local:"微調模型",headingTag:"h3"}}),H=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}}),ll=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}}),F=new re({props:{$$slots:{default:[wa]},$$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}}),v=new I({props:{code:"dHJhaW5lci5wdXNoX3RvX2h1Yihjb21taXRfbWVzc2FnZSUzRCUyMlRyYWluaW5nJTIwY29tcGxldGUlMjIp",highlighted:'trainer.push_to_hub(commit_message=<span class="hljs-string">&quot;Training complete&quot;</span>)',wrap:!1}}),yl=new I({props:{code:"J2h0dHBzJTNBJTJGJTJGaHVnZ2luZ2ZhY2UuY28lMkZzZ3VnZ2VyJTJGYmVydC1maW5ldHVuZWQtbmVyJTJGY29tbWl0JTJGMjZhYjIxZTViMTU2OGY5YWZlY2NkYWVkMmQ4NzE1ZjU3MWQ3ODZlZCc=",highlighted:'<span class="hljs-string">&#x27;https://huggingface.co/sgugger/bert-finetuned-ner/commit/26ab21e5b1568f9afeccdaed2d8715f571d786ed&#x27;</span>',wrap:!1}}),Cl=new ml({props:{title:"自定義訓練循環",local:"自定義訓練循環",headingTag:"h2"}}),xs=new ml({props:{title:"做好訓練前的準備",local:"做好訓練前的準備",headingTag:"h3"}}),ql=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}}),Ol=new I({props:{code:"bW9kZWwlMjAlM0QlMjBBdXRvTW9kZWxGb3JUb2tlbkNsYXNzaWZpY2F0aW9uLmZyb21fcHJldHJhaW5lZCglMEElMjAlMjAlMjAlMjBtb2RlbF9jaGVja3BvaW50JTJDJTBBJTIwJTIwJTIwJTIwaWQybGFiZWwlM0RpZDJsYWJlbCUyQyUwQSUyMCUyMCUyMCUyMGxhYmVsMmlkJTNEbGFiZWwyaWQlMkMlMEEp",highlighted:`model = AutoModelForTokenClassification.from_pretrained(
    model_checkpoint,
    id2label=id2label,
    label2id=label2id,
)`,wrap:!1}}),es=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}}),Gs=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}}),_l=new re({props:{$$slots:{default:[ja]},$$scope:{ctx:g}}}),As=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}}),vs=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}}),ol=new I({props:{code:"J3NndWdnZXIlMkZiZXJ0LWZpbmV0dW5lZC1uZXItYWNjZWxlcmF0ZSc=",highlighted:'<span class="hljs-string">&#x27;sgugger/bert-finetuned-ner-accelerate&#x27;</span>',wrap:!1}}),is=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}}),Rs=new ml({props:{title:"Training loop",local:"training-loop",headingTag:"h3"}}),Bl=new ml({props:{title:"訓練循環",local:"訓練循環",headingTag:"h3"}}),Gl=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}}),vl=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}}),Vl=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(){T(M.$$.fragment),u=a(),i=m("p"),i.innerHTML=f,x=a(),h=m("p"),h.innerHTML=_,B=a(),T(U.$$.fragment),W=a(),Z=m("p"),Z.innerHTML=C,G=a(),T(k.$$.fragment),V=a(),X=m("p"),X.innerHTML=El,Hl=a(),T(Y.$$.fragment),nl=a(),T(Q.$$.fragment),al=a(),T(P.$$.fragment),Yl=a(),T(A.$$.fragment),Nl=a(),E=m("p"),E.innerHTML=S,Fl=a(),T(H.$$.fragment),L=a(),K=m("p"),K.textContent=$s,pl=a(),T(O.$$.fragment),zl=a(),N=m("p"),N.innerHTML=Tl,Ml=a(),T(ll.$$.fragment),Sl=a(),R=m("p"),R.innerHTML=wl,il=a(),T(F.$$.fragment),jl=a(),bl=m("p"),bl.innerHTML=dl,ul=a(),T(rl.$$.fragment),z=a(),Ul=m("p"),Ul.textContent=fl,hl=a(),cl=m("p"),cl.innerHTML=sl,Ql=a(),T(v.$$.fragment),ks=a(),Jl=m("p"),Jl.textContent=el,_s=a(),T(yl.$$.fragment),r=a(),$=m("p"),$.innerHTML=gs,Hs=a(),Il=m("p"),Il.textContent=Tt,Ns=a(),T(Cl.$$.fragment),Fs=a(),$l=m("p"),$l.innerHTML=ce,Ll=a(),T(xs.$$.fragment),zs=a(),kl=m("p"),kl.innerHTML=Je,Dl=a(),T(ql.$$.fragment),Pl=a(),Zs=m("p"),Zs.textContent=ye,Kl=a(),T(Ol.$$.fragment),ls=a(),ss=m("p"),ss.innerHTML=Bs,me=a(),T(es.$$.fragment),ts=a(),Ws=m("p"),Ws.innerHTML=oe,ns=a(),T(Gs.$$.fragment),Ss=a(),T(_l.$$.fragment),Ls=a(),gl=m("p"),gl.innerHTML=Te,as=a(),T(As.$$.fragment),Ds=a(),xl=m("p"),xl.innerHTML=we,ps=a(),T(vs.$$.fragment),qs=a(),T(ol.$$.fragment),Ps=a(),Zl=m("p"),Zl.textContent=je,Ms=a(),T(is.$$.fragment),rs=a(),Vs=m("p"),Vs.innerHTML=be,cs=a(),T(Rs.$$.fragment),Ks=a(),T(Bl.$$.fragment),Os=a(),Wl=m("p"),Wl.innerHTML=wt,le=a(),T(Gl.$$.fragment),se=a(),Al=m("p"),Al.textContent=de,Js=a(),Xs=m("ul"),Xs.innerHTML=ue,ys=a(),ms=m("p"),ms.textContent=Ys,ee=a(),T(vl.$$.fragment),Ue=a(),os=m("p"),os.textContent=Qs,te=a(),T(Vl.$$.fragment),ne=a(),Rl=m("p"),Rl.innerHTML=jt,ae=a(),Xl=m("p"),Xl.innerHTML=fe},l(s){w(M.$$.fragment,s),u=p(s),i=o(s,"P",{"data-svelte-h":!0}),d(i)!=="svelte-1min3sz"&&(i.innerHTML=f),x=p(s),h=o(s,"P",{"data-svelte-h":!0}),d(h)!=="svelte-6jnith"&&(h.innerHTML=_),B=p(s),w(U.$$.fragment,s),W=p(s),Z=o(s,"P",{"data-svelte-h":!0}),d(Z)!=="svelte-a1wka0"&&(Z.innerHTML=C),G=p(s),w(k.$$.fragment,s),V=p(s),X=o(s,"P",{"data-svelte-h":!0}),d(X)!=="svelte-1t3x82c"&&(X.innerHTML=El),Hl=p(s),w(Y.$$.fragment,s),nl=p(s),w(Q.$$.fragment,s),al=p(s),w(P.$$.fragment,s),Yl=p(s),w(A.$$.fragment,s),Nl=p(s),E=o(s,"P",{"data-svelte-h":!0}),d(E)!=="svelte-7s0gb6"&&(E.innerHTML=S),Fl=p(s),w(H.$$.fragment,s),L=p(s),K=o(s,"P",{"data-svelte-h":!0}),d(K)!=="svelte-162697j"&&(K.textContent=$s),pl=p(s),w(O.$$.fragment,s),zl=p(s),N=o(s,"P",{"data-svelte-h":!0}),d(N)!=="svelte-h1gi55"&&(N.innerHTML=Tl),Ml=p(s),w(ll.$$.fragment,s),Sl=p(s),R=o(s,"P",{"data-svelte-h":!0}),d(R)!=="svelte-8bm5dv"&&(R.innerHTML=wl),il=p(s),w(F.$$.fragment,s),jl=p(s),bl=o(s,"P",{"data-svelte-h":!0}),d(bl)!=="svelte-1wvlrrj"&&(bl.innerHTML=dl),ul=p(s),w(rl.$$.fragment,s),z=p(s),Ul=o(s,"P",{"data-svelte-h":!0}),d(Ul)!=="svelte-phco4r"&&(Ul.textContent=fl),hl=p(s),cl=o(s,"P",{"data-svelte-h":!0}),d(cl)!=="svelte-ka8crc"&&(cl.innerHTML=sl),Ql=p(s),w(v.$$.fragment,s),ks=p(s),Jl=o(s,"P",{"data-svelte-h":!0}),d(Jl)!=="svelte-mme7gz"&&(Jl.textContent=el),_s=p(s),w(yl.$$.fragment,s),r=p(s),$=o(s,"P",{"data-svelte-h":!0}),d($)!=="svelte-pzk96o"&&($.innerHTML=gs),Hs=p(s),Il=o(s,"P",{"data-svelte-h":!0}),d(Il)!=="svelte-1a0w12w"&&(Il.textContent=Tt),Ns=p(s),w(Cl.$$.fragment,s),Fs=p(s),$l=o(s,"P",{"data-svelte-h":!0}),d($l)!=="svelte-159ygmk"&&($l.innerHTML=ce),Ll=p(s),w(xs.$$.fragment,s),zs=p(s),kl=o(s,"P",{"data-svelte-h":!0}),d(kl)!=="svelte-3n70bh"&&(kl.innerHTML=Je),Dl=p(s),w(ql.$$.fragment,s),Pl=p(s),Zs=o(s,"P",{"data-svelte-h":!0}),d(Zs)!=="svelte-1ytjtup"&&(Zs.textContent=ye),Kl=p(s),w(Ol.$$.fragment,s),ls=p(s),ss=o(s,"P",{"data-svelte-h":!0}),d(ss)!=="svelte-ps3jgc"&&(ss.innerHTML=Bs),me=p(s),w(es.$$.fragment,s),ts=p(s),Ws=o(s,"P",{"data-svelte-h":!0}),d(Ws)!=="svelte-1oqv3so"&&(Ws.innerHTML=oe),ns=p(s),w(Gs.$$.fragment,s),Ss=p(s),w(_l.$$.fragment,s),Ls=p(s),gl=o(s,"P",{"data-svelte-h":!0}),d(gl)!=="svelte-87bmw4"&&(gl.innerHTML=Te),as=p(s),w(As.$$.fragment,s),Ds=p(s),xl=o(s,"P",{"data-svelte-h":!0}),d(xl)!=="svelte-1gs3lys"&&(xl.innerHTML=we),ps=p(s),w(vs.$$.fragment,s),qs=p(s),w(ol.$$.fragment,s),Ps=p(s),Zl=o(s,"P",{"data-svelte-h":!0}),d(Zl)!=="svelte-lt5x8r"&&(Zl.textContent=je),Ms=p(s),w(is.$$.fragment,s),rs=p(s),Vs=o(s,"P",{"data-svelte-h":!0}),d(Vs)!=="svelte-1mcbsiy"&&(Vs.innerHTML=be),cs=p(s),w(Rs.$$.fragment,s),Ks=p(s),w(Bl.$$.fragment,s),Os=p(s),Wl=o(s,"P",{"data-svelte-h":!0}),d(Wl)!=="svelte-1t2yu5i"&&(Wl.innerHTML=wt),le=p(s),w(Gl.$$.fragment,s),se=p(s),Al=o(s,"P",{"data-svelte-h":!0}),d(Al)!=="svelte-892gxr"&&(Al.textContent=de),Js=p(s),Xs=o(s,"UL",{"data-svelte-h":!0}),d(Xs)!=="svelte-16hmptw"&&(Xs.innerHTML=ue),ys=p(s),ms=o(s,"P",{"data-svelte-h":!0}),d(ms)!=="svelte-uj337y"&&(ms.textContent=Ys),ee=p(s),w(vl.$$.fragment,s),Ue=p(s),os=o(s,"P",{"data-svelte-h":!0}),d(os)!=="svelte-1qbz863"&&(os.textContent=Qs),te=p(s),w(Vl.$$.fragment,s),ne=p(s),Rl=o(s,"P",{"data-svelte-h":!0}),d(Rl)!=="svelte-1dlsben"&&(Rl.innerHTML=jt),ae=p(s),Xl=o(s,"P",{"data-svelte-h":!0}),d(Xl)!=="svelte-ircn2g"&&(Xl.innerHTML=fe)},m(s,c){j(M,s,c),t(s,u,c),t(s,i,c),t(s,x,c),t(s,h,c),t(s,B,c),j(U,s,c),t(s,W,c),t(s,Z,c),t(s,G,c),j(k,s,c),t(s,V,c),t(s,X,c),t(s,Hl,c),j(Y,s,c),t(s,nl,c),j(Q,s,c),t(s,al,c),j(P,s,c),t(s,Yl,c),j(A,s,c),t(s,Nl,c),t(s,E,c),t(s,Fl,c),j(H,s,c),t(s,L,c),t(s,K,c),t(s,pl,c),j(O,s,c),t(s,zl,c),t(s,N,c),t(s,Ml,c),j(ll,s,c),t(s,Sl,c),t(s,R,c),t(s,il,c),j(F,s,c),t(s,jl,c),t(s,bl,c),t(s,ul,c),j(rl,s,c),t(s,z,c),t(s,Ul,c),t(s,hl,c),t(s,cl,c),t(s,Ql,c),j(v,s,c),t(s,ks,c),t(s,Jl,c),t(s,_s,c),j(yl,s,c),t(s,r,c),t(s,$,c),t(s,Hs,c),t(s,Il,c),t(s,Ns,c),j(Cl,s,c),t(s,Fs,c),t(s,$l,c),t(s,Ll,c),j(xs,s,c),t(s,zs,c),t(s,kl,c),t(s,Dl,c),j(ql,s,c),t(s,Pl,c),t(s,Zs,c),t(s,Kl,c),j(Ol,s,c),t(s,ls,c),t(s,ss,c),t(s,me,c),j(es,s,c),t(s,ts,c),t(s,Ws,c),t(s,ns,c),j(Gs,s,c),t(s,Ss,c),j(_l,s,c),t(s,Ls,c),t(s,gl,c),t(s,as,c),j(As,s,c),t(s,Ds,c),t(s,xl,c),t(s,ps,c),j(vs,s,c),t(s,qs,c),j(ol,s,c),t(s,Ps,c),t(s,Zl,c),t(s,Ms,c),j(is,s,c),t(s,rs,c),t(s,Vs,c),t(s,cs,c),j(Rs,s,c),t(s,Ks,c),j(Bl,s,c),t(s,Os,c),t(s,Wl,c),t(s,le,c),j(Gl,s,c),t(s,se,c),t(s,Al,c),t(s,Js,c),t(s,Xs,c),t(s,ys,c),t(s,ms,c),t(s,ee,c),j(vl,s,c),t(s,Ue,c),t(s,os,c),t(s,te,c),j(Vl,s,c),t(s,ne,c),t(s,Rl,c),t(s,ae,c),t(s,Xl,c),Ts=!0},i(s){Ts||(J(M.$$.fragment,s),J(U.$$.fragment,s),J(k.$$.fragment,s),J(Y.$$.fragment,s),J(Q.$$.fragment,s),J(P.$$.fragment,s),J(A.$$.fragment,s),J(H.$$.fragment,s),J(O.$$.fragment,s),J(ll.$$.fragment,s),J(F.$$.fragment,s),J(rl.$$.fragment,s),J(v.$$.fragment,s),J(yl.$$.fragment,s),J(Cl.$$.fragment,s),J(xs.$$.fragment,s),J(ql.$$.fragment,s),J(Ol.$$.fragment,s),J(es.$$.fragment,s),J(Gs.$$.fragment,s),J(_l.$$.fragment,s),J(As.$$.fragment,s),J(vs.$$.fragment,s),J(ol.$$.fragment,s),J(is.$$.fragment,s),J(Rs.$$.fragment,s),J(Bl.$$.fragment,s),J(Gl.$$.fragment,s),J(vl.$$.fragment,s),J(Vl.$$.fragment,s),Ts=!0)},o(s){y(M.$$.fragment,s),y(U.$$.fragment,s),y(k.$$.fragment,s),y(Y.$$.fragment,s),y(Q.$$.fragment,s),y(P.$$.fragment,s),y(A.$$.fragment,s),y(H.$$.fragment,s),y(O.$$.fragment,s),y(ll.$$.fragment,s),y(F.$$.fragment,s),y(rl.$$.fragment,s),y(v.$$.fragment,s),y(yl.$$.fragment,s),y(Cl.$$.fragment,s),y(xs.$$.fragment,s),y(ql.$$.fragment,s),y(Ol.$$.fragment,s),y(es.$$.fragment,s),y(Gs.$$.fragment,s),y(_l.$$.fragment,s),y(As.$$.fragment,s),y(vs.$$.fragment,s),y(ol.$$.fragment,s),y(is.$$.fragment,s),y(Rs.$$.fragment,s),y(Bl.$$.fragment,s),y(Gl.$$.fragment,s),y(vl.$$.fragment,s),y(Vl.$$.fragment,s),Ts=!1},d(s){s&&(e(u),e(i),e(x),e(h),e(B),e(W),e(Z),e(G),e(V),e(X),e(Hl),e(nl),e(al),e(Yl),e(Nl),e(E),e(Fl),e(L),e(K),e(pl),e(zl),e(N),e(Ml),e(Sl),e(R),e(il),e(jl),e(bl),e(ul),e(z),e(Ul),e(hl),e(cl),e(Ql),e(ks),e(Jl),e(_s),e(r),e($),e(Hs),e(Il),e(Ns),e(Fs),e($l),e(Ll),e(zs),e(kl),e(Dl),e(Pl),e(Zs),e(Kl),e(ls),e(ss),e(me),e(ts),e(Ws),e(ns),e(Ss),e(Ls),e(gl),e(as),e(Ds),e(xl),e(ps),e(qs),e(Ps),e(Zl),e(Ms),e(rs),e(Vs),e(cs),e(Ks),e(Os),e(Wl),e(le),e(se),e(Al),e(Js),e(Xs),e(ys),e(ms),e(ee),e(Ue),e(os),e(te),e(ne),e(Rl),e(ae),e(Xl)),b(M,s),b(U,s),b(k,s),b(Y,s),b(Q,s),b(P,s),b(A,s),b(H,s),b(O,s),b(ll,s),b(F,s),b(rl,s),b(v,s),b(yl,s),b(Cl,s),b(xs,s),b(ql,s),b(Ol,s),b(es,s),b(Gs,s),b(_l,s),b(As,s),b(vs,s),b(ol,s),b(is,s),b(Rs,s),b(Bl,s),b(Gl,s),b(vl,s),b(Vl,s)}}}function Ta(g){let M,u="⚠️ 如果模型的標籤數量錯誤，稍後調用Trainer.train()方法時會出現一個模糊的錯誤（類似於“CUDA error: device-side assert triggered”）。這是用戶報告此類錯誤的第一個原因，因此請確保進行這樣的檢查以確認您擁有預期數量的標籤。";return{c(){M=m("p"),M.textContent=u},l(i){M=o(i,"P",{"data-svelte-h":!0}),d(M)!=="svelte-odtfri"&&(M.textContent=u)},m(i,f){t(i,M,f)},p:Es,d(i){i&&e(M)}}}function wa(g){let M,u="💡 如果您正在使用的輸出目錄已經存在，那麼輸出目錄必須是從同一個存儲庫clone下來的。如果不是，您將在聲明 <code>Trainer</code> 時遇到錯誤，並且需要設置一個新名稱。";return{c(){M=m("p"),M.innerHTML=u},l(i){M=o(i,"P",{"data-svelte-h":!0}),d(M)!=="svelte-vnmd58"&&(M.innerHTML=u)},m(i,f){t(i,M,f)},p:Es,d(i){i&&e(M)}}}function ja(g){let M,u='🚨 如果您在 TPU 上進行訓練，則需要將以上單元格中的所有代碼移動到專用的訓練函數中。有關詳細信息，請參閱 <a href="/course/chapter3">第3章</a>。';return{c(){M=m("p"),M.innerHTML=u},l(i){M=o(i,"P",{"data-svelte-h":!0}),d(M)!=="svelte-1ktdga8"&&(M.innerHTML=u)},m(i,f){t(i,M,f)},p:Es,d(i){i&&e(M)}}}function ba(g){let M,u,i,f,x,h,_,B,U,W,Z,C,G,k,V="我們將探索的第一個應用是Token分類。這個通用任務包括任何可以表述為“為句子中的詞或字分配標籤”的問題，例如：",X,El,Hl="<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>",Y,nl,Q,al,P="當然，還有很多其他類型的token分類問題；這些只是幾個有代表性的例子。在本節中，我們將在 NER 任務上微調模型 (BERT)，然後該模型將能夠計算如下預測：",Yl,A,Nl,E,S,Fl,H,L,K='<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,pl,O='您可以<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的模型，可以嘗試輸入一些句子看看模型的預測結果。',zl,N,Tl,Ml,ll='首先，我們需要一個適合標記分類的數據集。在本節中，我們將使用<a href="https://huggingface.co/datasets/conll2003" rel="nofollow">CoNLL-2003 數據集</a>, 其中包含來自路透社的新聞報道。',Sl,R,wl,il,F,jl,bl="要加載 CoNLL-2003 數據集，我們使用 來自 🤗 Datasets 庫的<strong>load_dataset()</strong> 方法：",dl,ul,rl,z,Ul='這將下載並緩存數據集，就像和我們在<a href="/course/chapter3">第三章</a> 加載GLUE MRPC 數據集一樣。檢查這個對象可以讓我們看到存在哪些列，以及訓練集、驗證集和測試集之間是如何分割的:',fl,hl,cl,sl,Ql,v,ks="特別是，我們可以看到數據集包含我們之前提到的三個任務的標籤：NER、POS 和chunking。與其他數據集的一個很大區別是輸入文本不是作為句子或文檔呈現的，而是單詞列表（最後一列稱為 <strong>tokens</strong> ，但它包含的是這些詞是預先標記化的輸入，仍然需要通過標記器進行子詞標記）。",Jl,el,_s="我們來看看訓練集的第一個元素：",yl,r,$,gs,Hs,Il,Tt="由於我們要執行命名實體識別，我們將查看 NER 標籤：",Ns,Cl,Fs,$l,ce,Ll,xs="這一列是類標籤的序列。元素的類型在ner_feature的feature屬性中，我們可以通過查看該特性的names屬性來訪問名稱列表:",zs,kl,Je,Dl,ql,Pl,Zs="因此，這一列包含的元素是ClassLabels的序列。序列元素的類型在<code>ner_feature</code>的<code>feature</code>中，我們可以通過查看該<code>feature</code>的<code>names</code>屬性來訪問名稱列表:",ye,Kl,Ol,ls,ss,Bs,me='我們在<a href="/course/chapter6/3">第六章</a>, 深入研究<strong>token-classification</strong> 管道時已經看到了這些標籤 ，但為了快速複習：',es,ts,Ws="<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>",oe,ns,Gs="現在解碼我們之前看到的標籤：",Ss,_l,Ls,gl,Te,as,As="例如混合 <strong>B-</strong> 和 <strong>I-</strong> 標籤，這是相同的代碼在索引 4 的訓練集元素上的預測結果：",Ds,xl,we,ps,vs="正如我們所看到的，跨越兩個單詞的實體，如“European Union”和“Werner Zwingmann”，模型為第一個單詞標註了一個B-標籤，為第二個單詞標註了一個I-標籤。",qs,ol,Ps,Zl,je,Ms,is,rs,Vs='像往常一樣，我們的文本需要轉換為Token ID，然後模型才能理解它們。正如我們在<a href="/course/chapter6/">第六章</a>所學的那樣。不過在標記任務中，一個很大的區別是我們有pre-tokenized的輸入。幸運的是，tokenizer API可以很容易地處理這個問題;我們只需要用一個特殊的tokenizer。',be,cs,Rs="首先，讓我們創建<code>tokenizer</code>對象。如前所述，我們將使用 BERT 預訓練模型，因此我們將從下載並緩存關聯的分詞器開始：",Ks,Bl,Os,Wl,wt='你可以更換把 <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 支持：',le,Gl,se,Al,de,Js,Xs="要對預先標記的輸入進行標記，我們可以像往常一樣使用我們的<code>tokenizer</code> 只需添加 <code>is_split_into_words=True</code>:",ue,ys,ms,Ys,ee,vl,Ue=`正如我們所見，分詞器添加了模型使用的特殊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>):`,os,Qs,te,Vl,ne,Rl,jt="通過一點點工作，我們可以擴展我們的標籤列表以匹配token 。我們將應用的第一條規則是，特殊token 的標籤為 <code>-100</code> 。這是因為默認情況下 <code>-100</code> 是一個在我們將使用的損失函數（交叉熵）中被忽略的索引。然後，每個token 都會獲得與其所在單詞的token 相同的標籤，因為它們是同一實體的一部分。對於單詞內部但不在開頭的Token，我們將<code>B-</code> 替換為 <code>I-</code> (因為token 不以實體開頭):",ae,Xl,fe,Ts,s="讓我們在我們的第一句話上試一試：",c,he,dt,Ie,ut,Ce,Mn="正如我們所看到的，我們的函數為開頭和結尾的兩個特殊標記添加了  <code>-100</code> ，併為分成兩個標記的單詞添加了一個新的<code>0</code> 。",Ut,pe,ft,$e,rn="為了預處理我們的整個數據集，我們需要標記所有輸入並在所有標籤上應用 <code>align_labels_with_tokens()</code> 。為了利用我們的快速分詞器的速度優勢，最好同時對大量文本進行分詞，因此我們將編寫一個處理示例列表的函數並使用帶 <code>batched=True</code> 有選項的 <code>Dataset.map()</code>方法 .與我們之前的示例唯一不同的是當分詞器的輸入是文本列表（或者像例子中的單詞列表）時  <code>word_ids()</code> 函數需要獲取我們想要單詞的索引的ID，所以我們也添加它：",ht,ke,It,_e,cn="請注意，我們還沒有填充我們的輸入；我們稍後會在使用數據整理器創建batch時這樣做。",Ct,ge,Jn="我們現在可以一次性將所有預處理應用於數據集的其他部分：",$t,xe,kt,Ze,yn='我們已經完成了最難的部分！現在數據已經被預處理了，實際的訓練看起來很像我們<a href="/course/chapter3">第三章</a>做的.',_t,ws,js,it,Be,gt,We,mn='我們不能像<a href="/course/chapter3">第三章</a>那樣只使用一個 <code>DataCollatorWithPadding </code>因為這隻會填充輸入（輸入 ID、注意掩碼和標記類型 ID）。在這裡我們的標籤應該以與輸入完全相同的方式填充，以便它們保持長度相同，使用  <code>-100</code> ，這樣在損失計算中就可以忽略相應的預測。',xt,Ge,on='這一切都是由一個 <a href="https://huggingface.co/transformers/main_classes/data_collator.html#datacollatorfortokenclassification" rel="nofollow"><code>DataCollatorForTokenClassification</code></a>完成.它是一個帶有填充的數據整理器它需要  <code>tokenizer</code> 用於預處理輸入：',Zt,bs,ds,rt,Ae,Tn="為了在幾個樣本上測試這一點，我們可以在訓練集中的示例列表上調用它：",Bt,ve,Wt,Ve,Gt,Re,wn="讓我們將其與數據集中第一個和第二個元素的標籤進行比較：",At,Xe,vt,Ye,Vt,us,Us,ct,Jt,Qe,Rt,fs,hs,yt,Ee,Xt,He,jn="這個評估方式與標準精度不同:它實際上將標籤列表作為字符串，而不是整數，因此在將預測和標籤傳遞給它之前，我們需要完全解碼它們。讓我們看看它是如何工作的。首先，我們將獲得第一個訓練示例的標籤:",Yt,Ne,Qt,Fe,Et,ze,bn="然後我們可以通過更改索引 2 處的值來為那些創建假的預測：",Ht,Se,Nt,Le,dn="請注意，該指標的輸入是預測列表（不僅僅是一個）和標籤列表。這是輸出：",Ft,De,zt,Is,Cs,mt,ot,qe,St,Pe,un="我們已經向您展示瞭如何使用我們在模型中心微調的模型和推理小部件。在本地使用它 <code>pipeline</code> ，您只需要指定正確的模型標識符：",Lt,Ke,Dt,Oe,qt,lt,Un="太棒了！我們的模型與此管道的默認模型一樣有效！",Pt,st,Kt,bt,Ot;x=new Pn({props:{fw:g[0]}}),_=new Dn({props:{containerStyle:"float: right; margin-left: 10px; display: inline-flex; position: relative; z-index: 10;"}}),U=new ml({props:{title:"Token 分類",local:"token-分類",headingTag:"h1"}});const fn=[On,Kn],et=[];function hn(l,n){return l[0]==="pt"?0:1}Z=hn(g),C=et[Z]=fn[Z](g),nl=new Xn({props:{id:"wVHdVlPScxA"}}),N=new ml({props:{title:"準備數據",local:"準備數據",headingTag:"h2"}}),R=new re({props:{$$slots:{default:[la]},$$scope:{ctx:g}}}),il=new ml({props:{title:"CoNLL-2003 數據集",local:"conll-2003-數據集",headingTag:"h3"}}),ul=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}}),hl=new I({props:{code:"cmF3X2RhdGFzZXRz",highlighted:"raw_datasets",wrap:!1}}),sl=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}}),r=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}}),gs=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}}),Cl=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}}),$l=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}}),kl=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}}),Dl=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}}),Kl=new I({props:{code:"bGFiZWxfbmFtZXMlMjAlM0QlMjBuZXJfZmVhdHVyZS5mZWF0dXJlLm5hbWVzJTBBbGFiZWxfbmFtZXM=",highlighted:`label_names = ner_feature.feature.names
label_names`,wrap:!1}}),ls=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}}),gl=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}}),xl=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}}),ol=new re({props:{$$slots:{default:[sa]},$$scope:{ctx:g}}}),Zl=new ml({props:{title:"處理數據",local:"處理數據",headingTag:"h3"}}),Ms=new Xn({props:{id:"iY2AZYdZAr0"}}),Bl=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}}),Al=new I({props:{code:"VHJ1ZQ==",highlighted:'<span class="hljs-literal">True</span>',wrap:!1}}),ys=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}}),Ys=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}}),Qs=new I({props:{code:"aW5wdXRzLndvcmRfaWRzKCk=",highlighted:"inputs.word_ids()",wrap:!1}}),Vl=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}}),Xl=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}}),he=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}}),Ie=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}}),pe=new re({props:{$$slots:{default:[ea]},$$scope:{ctx:g}}}),ke=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}}),xe=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 In=[na,ta],tt=[];function Cn(l,n){return l[0]==="pt"?0:1}ws=Cn(g),js=tt[ws]=In[ws](g),Be=new ml({props:{title:"數據排序",local:"數據排序",headingTag:"h3"}});const $n=[pa,aa],nt=[];function kn(l,n){return l[0]==="pt"?0:1}bs=kn(g),ds=nt[bs]=$n[bs](g),ve=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}}),Ve=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}}),Xe=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}}),Ye=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 _n=[ia,Ma],at=[];function gn(l,n){return l[0]==="pt"?0:1}us=gn(g),Us=at[us]=_n[us](g);let D=g[0]==="tf"&&Yn(g);Qe=new ml({props:{title:"評估指標",local:"評估指標",headingTag:"h3"}});const xn=[ya,Ja],pt=[];function Zn(l,n){return l[0]==="pt"?0:1}fs=Zn(g),hs=pt[fs]=xn[fs](g),Ee=new I({props:{code:"ZnJvbSUyMGRhdGFzZXRzJTIwaW1wb3J0JTIwbG9hZF9tZXRyaWMlMEElMEFtZXRyaWMlMjAlM0QlMjBsb2FkX21ldHJpYyglMjJzZXFldmFsJTIyKQ==",highlighted:`<span class="hljs-keyword">from</span> datasets <span class="hljs-keyword">import</span> load_metric

metric = load_metric(<span class="hljs-string">&quot;seqeval&quot;</span>)`,wrap:!1}}),Ne=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}}),Fe=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}}),Se=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}}),De=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 Bn=[oa,ma],Mt=[];function Wn(l,n){return l[0]==="pt"?0:1}Is=Wn(g),Cs=Mt[Is]=Bn[Is](g);let q=g[0]==="pt"&&Qn(g);return qe=new ml({props:{title:"使用微調模型",local:"使用微調模型",headingTag:"h2"}}),Ke=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}}),Oe=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}}),st=new qn({props:{source:"https://github.com/huggingface/course/blob/main/chapters/zh-TW/chapter7/2.mdx"}}),{c(){M=m("meta"),u=a(),i=m("p"),f=a(),T(x.$$.fragment),h=a(),T(_.$$.fragment),B=a(),T(U.$$.fragment),W=a(),C.c(),G=a(),k=m("p"),k.textContent=V,X=a(),El=m("ul"),El.innerHTML=Hl,Y=a(),T(nl.$$.fragment),Q=a(),al=m("p"),al.textContent=P,Yl=a(),A=m("iframe"),E=a(),S=m("iframe"),H=a(),L=m("a"),L.innerHTML=K,$s=a(),pl=m("p"),pl.innerHTML=O,zl=a(),T(N.$$.fragment),Tl=a(),Ml=m("p"),Ml.innerHTML=ll,Sl=a(),T(R.$$.fragment),wl=a(),T(il.$$.fragment),F=a(),jl=m("p"),jl.innerHTML=bl,dl=a(),T(ul.$$.fragment),rl=a(),z=m("p"),z.innerHTML=Ul,fl=a(),T(hl.$$.fragment),cl=a(),T(sl.$$.fragment),Ql=a(),v=m("p"),v.innerHTML=ks,Jl=a(),el=m("p"),el.textContent=_s,yl=a(),T(r.$$.fragment),$=a(),T(gs.$$.fragment),Hs=a(),Il=m("p"),Il.textContent=Tt,Ns=a(),T(Cl.$$.fragment),Fs=a(),T($l.$$.fragment),ce=a(),Ll=m("p"),Ll.textContent=xs,zs=a(),T(kl.$$.fragment),Je=a(),T(Dl.$$.fragment),ql=a(),Pl=m("p"),Pl.innerHTML=Zs,ye=a(),T(Kl.$$.fragment),Ol=a(),T(ls.$$.fragment),ss=a(),Bs=m("p"),Bs.innerHTML=me,es=a(),ts=m("ul"),ts.innerHTML=Ws,oe=a(),ns=m("p"),ns.textContent=Gs,Ss=a(),T(_l.$$.fragment),Ls=a(),T(gl.$$.fragment),Te=a(),as=m("p"),as.innerHTML=As,Ds=a(),T(xl.$$.fragment),we=a(),ps=m("p"),ps.textContent=vs,qs=a(),T(ol.$$.fragment),Ps=a(),T(Zl.$$.fragment),je=a(),T(Ms.$$.fragment),is=a(),rs=m("p"),rs.innerHTML=Vs,be=a(),cs=m("p"),cs.innerHTML=Rs,Ks=a(),T(Bl.$$.fragment),Os=a(),Wl=m("p"),Wl.innerHTML=wt,le=a(),T(Gl.$$.fragment),se=a(),T(Al.$$.fragment),de=a(),Js=m("p"),Js.innerHTML=Xs,ue=a(),T(ys.$$.fragment),ms=a(),T(Ys.$$.fragment),ee=a(),vl=m("p"),vl.innerHTML=Ue,os=a(),T(Qs.$$.fragment),te=a(),T(Vl.$$.fragment),ne=a(),Rl=m("p"),Rl.innerHTML=jt,ae=a(),T(Xl.$$.fragment),fe=a(),Ts=m("p"),Ts.textContent=s,c=a(),T(he.$$.fragment),dt=a(),T(Ie.$$.fragment),ut=a(),Ce=m("p"),Ce.innerHTML=Mn,Ut=a(),T(pe.$$.fragment),ft=a(),$e=m("p"),$e.innerHTML=rn,ht=a(),T(ke.$$.fragment),It=a(),_e=m("p"),_e.textContent=cn,Ct=a(),ge=m("p"),ge.textContent=Jn,$t=a(),T(xe.$$.fragment),kt=a(),Ze=m("p"),Ze.innerHTML=yn,_t=a(),js.c(),it=a(),T(Be.$$.fragment),gt=a(),We=m("p"),We.innerHTML=mn,xt=a(),Ge=m("p"),Ge.innerHTML=on,Zt=a(),ds.c(),rt=a(),Ae=m("p"),Ae.textContent=Tn,Bt=a(),T(ve.$$.fragment),Wt=a(),T(Ve.$$.fragment),Gt=a(),Re=m("p"),Re.textContent=wn,At=a(),T(Xe.$$.fragment),vt=a(),T(Ye.$$.fragment),Vt=a(),Us.c(),ct=a(),D&&D.c(),Jt=a(),T(Qe.$$.fragment),Rt=a(),hs.c(),yt=a(),T(Ee.$$.fragment),Xt=a(),He=m("p"),He.textContent=jn,Yt=a(),T(Ne.$$.fragment),Qt=a(),T(Fe.$$.fragment),Et=a(),ze=m("p"),ze.textContent=bn,Ht=a(),T(Se.$$.fragment),Nt=a(),Le=m("p"),Le.textContent=dn,Ft=a(),T(De.$$.fragment),zt=a(),Cs.c(),mt=a(),q&&q.c(),ot=a(),T(qe.$$.fragment),St=a(),Pe=m("p"),Pe.innerHTML=un,Lt=a(),T(Ke.$$.fragment),Dt=a(),T(Oe.$$.fragment),qt=a(),lt=m("p"),lt.textContent=Un,Pt=a(),T(st.$$.fragment),Kt=a(),bt=m("p"),this.h()},l(l){const n=Sn("svelte-u9bgzb",document.head);M=o(n,"META",{name:!0,content:!0}),n.forEach(e),u=p(l),i=o(l,"P",{}),ln(i).forEach(e),f=p(l),w(x.$$.fragment,l),h=p(l),w(_.$$.fragment,l),B=p(l),w(U.$$.fragment,l),W=p(l),C.l(l),G=p(l),k=o(l,"P",{"data-svelte-h":!0}),d(k)!=="svelte-fj4lzc"&&(k.textContent=V),X=p(l),El=o(l,"UL",{"data-svelte-h":!0}),d(El)!=="svelte-3dd52o"&&(El.innerHTML=Hl),Y=p(l),w(nl.$$.fragment,l),Q=p(l),al=o(l,"P",{"data-svelte-h":!0}),d(al)!=="svelte-bw2qoz"&&(al.textContent=P),Yl=p(l),A=o(l,"IFRAME",{src:!0,frameborder:!0,height:!0,title:!0,class:!0,allow:!0,sandbox:!0}),ln(A).forEach(e),E=p(l),S=o(l,"IFRAME",{src:!0,frameborder:!0,height:!0,title:!0,class:!0,allow:!0,sandbox:!0}),ln(S).forEach(e),H=p(l),L=o(l,"A",{class:!0,href:!0,"data-svelte-h":!0}),d(L)!=="svelte-1n7oe9l"&&(L.innerHTML=K),$s=p(l),pl=o(l,"P",{"data-svelte-h":!0}),d(pl)!=="svelte-1nhfol8"&&(pl.innerHTML=O),zl=p(l),w(N.$$.fragment,l),Tl=p(l),Ml=o(l,"P",{"data-svelte-h":!0}),d(Ml)!=="svelte-1wlxkvc"&&(Ml.innerHTML=ll),Sl=p(l),w(R.$$.fragment,l),wl=p(l),w(il.$$.fragment,l),F=p(l),jl=o(l,"P",{"data-svelte-h":!0}),d(jl)!=="svelte-1rs5g05"&&(jl.innerHTML=bl),dl=p(l),w(ul.$$.fragment,l),rl=p(l),z=o(l,"P",{"data-svelte-h":!0}),d(z)!=="svelte-bc5n37"&&(z.innerHTML=Ul),fl=p(l),w(hl.$$.fragment,l),cl=p(l),w(sl.$$.fragment,l),Ql=p(l),v=o(l,"P",{"data-svelte-h":!0}),d(v)!=="svelte-rfb2mc"&&(v.innerHTML=ks),Jl=p(l),el=o(l,"P",{"data-svelte-h":!0}),d(el)!=="svelte-1ppbae7"&&(el.textContent=_s),yl=p(l),w(r.$$.fragment,l),$=p(l),w(gs.$$.fragment,l),Hs=p(l),Il=o(l,"P",{"data-svelte-h":!0}),d(Il)!=="svelte-1oau2a1"&&(Il.textContent=Tt),Ns=p(l),w(Cl.$$.fragment,l),Fs=p(l),w($l.$$.fragment,l),ce=p(l),Ll=o(l,"P",{"data-svelte-h":!0}),d(Ll)!=="svelte-1d6x9nt"&&(Ll.textContent=xs),zs=p(l),w(kl.$$.fragment,l),Je=p(l),w(Dl.$$.fragment,l),ql=p(l),Pl=o(l,"P",{"data-svelte-h":!0}),d(Pl)!=="svelte-2d6jzb"&&(Pl.innerHTML=Zs),ye=p(l),w(Kl.$$.fragment,l),Ol=p(l),w(ls.$$.fragment,l),ss=p(l),Bs=o(l,"P",{"data-svelte-h":!0}),d(Bs)!=="svelte-otkzcd"&&(Bs.innerHTML=me),es=p(l),ts=o(l,"UL",{"data-svelte-h":!0}),d(ts)!=="svelte-f551vb"&&(ts.innerHTML=Ws),oe=p(l),ns=o(l,"P",{"data-svelte-h":!0}),d(ns)!=="svelte-v74fd7"&&(ns.textContent=Gs),Ss=p(l),w(_l.$$.fragment,l),Ls=p(l),w(gl.$$.fragment,l),Te=p(l),as=o(l,"P",{"data-svelte-h":!0}),d(as)!=="svelte-1d7eu4w"&&(as.innerHTML=As),Ds=p(l),w(xl.$$.fragment,l),we=p(l),ps=o(l,"P",{"data-svelte-h":!0}),d(ps)!=="svelte-1040q5t"&&(ps.textContent=vs),qs=p(l),w(ol.$$.fragment,l),Ps=p(l),w(Zl.$$.fragment,l),je=p(l),w(Ms.$$.fragment,l),is=p(l),rs=o(l,"P",{"data-svelte-h":!0}),d(rs)!=="svelte-dizw0r"&&(rs.innerHTML=Vs),be=p(l),cs=o(l,"P",{"data-svelte-h":!0}),d(cs)!=="svelte-ieeu5a"&&(cs.innerHTML=Rs),Ks=p(l),w(Bl.$$.fragment,l),Os=p(l),Wl=o(l,"P",{"data-svelte-h":!0}),d(Wl)!=="svelte-qhmbt6"&&(Wl.innerHTML=wt),le=p(l),w(Gl.$$.fragment,l),se=p(l),w(Al.$$.fragment,l),de=p(l),Js=o(l,"P",{"data-svelte-h":!0}),d(Js)!=="svelte-aswiqt"&&(Js.innerHTML=Xs),ue=p(l),w(ys.$$.fragment,l),ms=p(l),w(Ys.$$.fragment,l),ee=p(l),vl=o(l,"P",{"data-svelte-h":!0}),d(vl)!=="svelte-1ui81xt"&&(vl.innerHTML=Ue),os=p(l),w(Qs.$$.fragment,l),te=p(l),w(Vl.$$.fragment,l),ne=p(l),Rl=o(l,"P",{"data-svelte-h":!0}),d(Rl)!=="svelte-xyrlko"&&(Rl.innerHTML=jt),ae=p(l),w(Xl.$$.fragment,l),fe=p(l),Ts=o(l,"P",{"data-svelte-h":!0}),d(Ts)!=="svelte-1jpbfuf"&&(Ts.textContent=s),c=p(l),w(he.$$.fragment,l),dt=p(l),w(Ie.$$.fragment,l),ut=p(l),Ce=o(l,"P",{"data-svelte-h":!0}),d(Ce)!=="svelte-v66ec8"&&(Ce.innerHTML=Mn),Ut=p(l),w(pe.$$.fragment,l),ft=p(l),$e=o(l,"P",{"data-svelte-h":!0}),d($e)!=="svelte-sese4w"&&($e.innerHTML=rn),ht=p(l),w(ke.$$.fragment,l),It=p(l),_e=o(l,"P",{"data-svelte-h":!0}),d(_e)!=="svelte-1fdwu6p"&&(_e.textContent=cn),Ct=p(l),ge=o(l,"P",{"data-svelte-h":!0}),d(ge)!=="svelte-1n3be24"&&(ge.textContent=Jn),$t=p(l),w(xe.$$.fragment,l),kt=p(l),Ze=o(l,"P",{"data-svelte-h":!0}),d(Ze)!=="svelte-hmnzd6"&&(Ze.innerHTML=yn),_t=p(l),js.l(l),it=p(l),w(Be.$$.fragment,l),gt=p(l),We=o(l,"P",{"data-svelte-h":!0}),d(We)!=="svelte-8rm9gx"&&(We.innerHTML=mn),xt=p(l),Ge=o(l,"P",{"data-svelte-h":!0}),d(Ge)!=="svelte-1jnbgsb"&&(Ge.innerHTML=on),Zt=p(l),ds.l(l),rt=p(l),Ae=o(l,"P",{"data-svelte-h":!0}),d(Ae)!=="svelte-eihhyp"&&(Ae.textContent=Tn),Bt=p(l),w(ve.$$.fragment,l),Wt=p(l),w(Ve.$$.fragment,l),Gt=p(l),Re=o(l,"P",{"data-svelte-h":!0}),d(Re)!=="svelte-qeezpf"&&(Re.textContent=wn),At=p(l),w(Xe.$$.fragment,l),vt=p(l),w(Ye.$$.fragment,l),Vt=p(l),Us.l(l),ct=p(l),D&&D.l(l),Jt=p(l),w(Qe.$$.fragment,l),Rt=p(l),hs.l(l),yt=p(l),w(Ee.$$.fragment,l),Xt=p(l),He=o(l,"P",{"data-svelte-h":!0}),d(He)!=="svelte-uy7xi3"&&(He.textContent=jn),Yt=p(l),w(Ne.$$.fragment,l),Qt=p(l),w(Fe.$$.fragment,l),Et=p(l),ze=o(l,"P",{"data-svelte-h":!0}),d(ze)!=="svelte-6cg1dt"&&(ze.textContent=bn),Ht=p(l),w(Se.$$.fragment,l),Nt=p(l),Le=o(l,"P",{"data-svelte-h":!0}),d(Le)!=="svelte-1u36har"&&(Le.textContent=dn),Ft=p(l),w(De.$$.fragment,l),zt=p(l),Cs.l(l),mt=p(l),q&&q.l(l),ot=p(l),w(qe.$$.fragment,l),St=p(l),Pe=o(l,"P",{"data-svelte-h":!0}),d(Pe)!=="svelte-11d45sb"&&(Pe.innerHTML=un),Lt=p(l),w(Ke.$$.fragment,l),Dt=p(l),w(Oe.$$.fragment,l),qt=p(l),lt=o(l,"P",{"data-svelte-h":!0}),d(lt)!=="svelte-nm02mc"&&(lt.textContent=Un),Pt=p(l),w(st.$$.fragment,l),Kt=p(l),bt=o(l,"P",{}),ln(bt).forEach(e),this.h()},h(){tl(M,"name","hf:doc:metadata"),tl(M,"content",da),Rn(A.src,Nl="https://course-demos-bert-finetuned-ner.hf.space")||tl(A,"src",Nl),tl(A,"frameborder","0"),tl(A,"height","350"),tl(A,"title","Gradio app"),tl(A,"class","block dark:hidden container p-0 flex-grow space-iframe"),tl(A,"allow","accelerometer; ambient-light-sensor; autoplay; battery; camera; document-domain; encrypted-media; fullscreen; geolocation; gyroscope; layout-animations; legacy-image-formats; magnetometer; microphone; midi; oversized-images; payment; picture-in-picture; publickey-credentials-get; sync-xhr; usb; vr ; wake-lock; xr-spatial-tracking"),tl(A,"sandbox","allow-forms allow-modals allow-popups allow-popups-to-escape-sandbox allow-same-origin allow-scripts allow-downloads"),Rn(S.src,Fl="https://course-demos-bert-finetuned-ner-darkmode.hf.space")||tl(S,"src",Fl),tl(S,"frameborder","0"),tl(S,"height","350"),tl(S,"title","Gradio app"),tl(S,"class","hidden dark:block container p-0 flex-grow space-iframe"),tl(S,"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"),tl(S,"sandbox","allow-forms allow-modals allow-popups allow-popups-to-escape-sandbox allow-same-origin allow-scripts allow-downloads"),tl(L,"class","flex justify-center"),tl(L,"href","/huggingface-course/bert-finetuned-ner")},m(l,n){Ln(document.head,M),t(l,u,n),t(l,i,n),t(l,f,n),j(x,l,n),t(l,h,n),j(_,l,n),t(l,B,n),j(U,l,n),t(l,W,n),et[Z].m(l,n),t(l,G,n),t(l,k,n),t(l,X,n),t(l,El,n),t(l,Y,n),j(nl,l,n),t(l,Q,n),t(l,al,n),t(l,Yl,n),t(l,A,n),t(l,E,n),t(l,S,n),t(l,H,n),t(l,L,n),t(l,$s,n),t(l,pl,n),t(l,zl,n),j(N,l,n),t(l,Tl,n),t(l,Ml,n),t(l,Sl,n),j(R,l,n),t(l,wl,n),j(il,l,n),t(l,F,n),t(l,jl,n),t(l,dl,n),j(ul,l,n),t(l,rl,n),t(l,z,n),t(l,fl,n),j(hl,l,n),t(l,cl,n),j(sl,l,n),t(l,Ql,n),t(l,v,n),t(l,Jl,n),t(l,el,n),t(l,yl,n),j(r,l,n),t(l,$,n),j(gs,l,n),t(l,Hs,n),t(l,Il,n),t(l,Ns,n),j(Cl,l,n),t(l,Fs,n),j($l,l,n),t(l,ce,n),t(l,Ll,n),t(l,zs,n),j(kl,l,n),t(l,Je,n),j(Dl,l,n),t(l,ql,n),t(l,Pl,n),t(l,ye,n),j(Kl,l,n),t(l,Ol,n),j(ls,l,n),t(l,ss,n),t(l,Bs,n),t(l,es,n),t(l,ts,n),t(l,oe,n),t(l,ns,n),t(l,Ss,n),j(_l,l,n),t(l,Ls,n),j(gl,l,n),t(l,Te,n),t(l,as,n),t(l,Ds,n),j(xl,l,n),t(l,we,n),t(l,ps,n),t(l,qs,n),j(ol,l,n),t(l,Ps,n),j(Zl,l,n),t(l,je,n),j(Ms,l,n),t(l,is,n),t(l,rs,n),t(l,be,n),t(l,cs,n),t(l,Ks,n),j(Bl,l,n),t(l,Os,n),t(l,Wl,n),t(l,le,n),j(Gl,l,n),t(l,se,n),j(Al,l,n),t(l,de,n),t(l,Js,n),t(l,ue,n),j(ys,l,n),t(l,ms,n),j(Ys,l,n),t(l,ee,n),t(l,vl,n),t(l,os,n),j(Qs,l,n),t(l,te,n),j(Vl,l,n),t(l,ne,n),t(l,Rl,n),t(l,ae,n),j(Xl,l,n),t(l,fe,n),t(l,Ts,n),t(l,c,n),j(he,l,n),t(l,dt,n),j(Ie,l,n),t(l,ut,n),t(l,Ce,n),t(l,Ut,n),j(pe,l,n),t(l,ft,n),t(l,$e,n),t(l,ht,n),j(ke,l,n),t(l,It,n),t(l,_e,n),t(l,Ct,n),t(l,ge,n),t(l,$t,n),j(xe,l,n),t(l,kt,n),t(l,Ze,n),t(l,_t,n),tt[ws].m(l,n),t(l,it,n),j(Be,l,n),t(l,gt,n),t(l,We,n),t(l,xt,n),t(l,Ge,n),t(l,Zt,n),nt[bs].m(l,n),t(l,rt,n),t(l,Ae,n),t(l,Bt,n),j(ve,l,n),t(l,Wt,n),j(Ve,l,n),t(l,Gt,n),t(l,Re,n),t(l,At,n),j(Xe,l,n),t(l,vt,n),j(Ye,l,n),t(l,Vt,n),at[us].m(l,n),t(l,ct,n),D&&D.m(l,n),t(l,Jt,n),j(Qe,l,n),t(l,Rt,n),pt[fs].m(l,n),t(l,yt,n),j(Ee,l,n),t(l,Xt,n),t(l,He,n),t(l,Yt,n),j(Ne,l,n),t(l,Qt,n),j(Fe,l,n),t(l,Et,n),t(l,ze,n),t(l,Ht,n),j(Se,l,n),t(l,Nt,n),t(l,Le,n),t(l,Ft,n),j(De,l,n),t(l,zt,n),Mt[Is].m(l,n),t(l,mt,n),q&&q.m(l,n),t(l,ot,n),j(qe,l,n),t(l,St,n),t(l,Pe,n),t(l,Lt,n),j(Ke,l,n),t(l,Dt,n),j(Oe,l,n),t(l,qt,n),t(l,lt,n),t(l,Pt,n),j(st,l,n),t(l,Kt,n),t(l,bt,n),Ot=!0},p(l,[n]){const Gn={};n&1&&(Gn.fw=l[0]),x.$set(Gn);let sn=Z;Z=hn(l),Z!==sn&&(ie(),y(et[sn],1,1,()=>{et[sn]=null}),Me(),C=et[Z],C||(C=et[Z]=fn[Z](l),C.c()),J(C,1),C.m(G.parentNode,G));const An={};n&2&&(An.$$scope={dirty:n,ctx:l}),R.$set(An);const vn={};n&2&&(vn.$$scope={dirty:n,ctx:l}),ol.$set(vn);const Vn={};n&2&&(Vn.$$scope={dirty:n,ctx:l}),pe.$set(Vn);let en=ws;ws=Cn(l),ws!==en&&(ie(),y(tt[en],1,1,()=>{tt[en]=null}),Me(),js=tt[ws],js||(js=tt[ws]=In[ws](l),js.c()),J(js,1),js.m(it.parentNode,it));let tn=bs;bs=kn(l),bs!==tn&&(ie(),y(nt[tn],1,1,()=>{nt[tn]=null}),Me(),ds=nt[bs],ds||(ds=nt[bs]=$n[bs](l),ds.c()),J(ds,1),ds.m(rt.parentNode,rt));let nn=us;us=gn(l),us!==nn&&(ie(),y(at[nn],1,1,()=>{at[nn]=null}),Me(),Us=at[us],Us||(Us=at[us]=_n[us](l),Us.c()),J(Us,1),Us.m(ct.parentNode,ct)),l[0]==="tf"?D?n&1&&J(D,1):(D=Yn(l),D.c(),J(D,1),D.m(Jt.parentNode,Jt)):D&&(ie(),y(D,1,1,()=>{D=null}),Me());let an=fs;fs=Zn(l),fs!==an&&(ie(),y(pt[an],1,1,()=>{pt[an]=null}),Me(),hs=pt[fs],hs||(hs=pt[fs]=xn[fs](l),hs.c()),J(hs,1),hs.m(yt.parentNode,yt));let pn=Is;Is=Wn(l),Is!==pn&&(ie(),y(Mt[pn],1,1,()=>{Mt[pn]=null}),Me(),Cs=Mt[Is],Cs||(Cs=Mt[Is]=Bn[Is](l),Cs.c()),J(Cs,1),Cs.m(mt.parentNode,mt)),l[0]==="pt"?q?n&1&&J(q,1):(q=Qn(l),q.c(),J(q,1),q.m(ot.parentNode,ot)):q&&(ie(),y(q,1,1,()=>{q=null}),Me())},i(l){Ot||(J(x.$$.fragment,l),J(_.$$.fragment,l),J(U.$$.fragment,l),J(C),J(nl.$$.fragment,l),J(N.$$.fragment,l),J(R.$$.fragment,l),J(il.$$.fragment,l),J(ul.$$.fragment,l),J(hl.$$.fragment,l),J(sl.$$.fragment,l),J(r.$$.fragment,l),J(gs.$$.fragment,l),J(Cl.$$.fragment,l),J($l.$$.fragment,l),J(kl.$$.fragment,l),J(Dl.$$.fragment,l),J(Kl.$$.fragment,l),J(ls.$$.fragment,l),J(_l.$$.fragment,l),J(gl.$$.fragment,l),J(xl.$$.fragment,l),J(ol.$$.fragment,l),J(Zl.$$.fragment,l),J(Ms.$$.fragment,l),J(Bl.$$.fragment,l),J(Gl.$$.fragment,l),J(Al.$$.fragment,l),J(ys.$$.fragment,l),J(Ys.$$.fragment,l),J(Qs.$$.fragment,l),J(Vl.$$.fragment,l),J(Xl.$$.fragment,l),J(he.$$.fragment,l),J(Ie.$$.fragment,l),J(pe.$$.fragment,l),J(ke.$$.fragment,l),J(xe.$$.fragment,l),J(js),J(Be.$$.fragment,l),J(ds),J(ve.$$.fragment,l),J(Ve.$$.fragment,l),J(Xe.$$.fragment,l),J(Ye.$$.fragment,l),J(Us),J(D),J(Qe.$$.fragment,l),J(hs),J(Ee.$$.fragment,l),J(Ne.$$.fragment,l),J(Fe.$$.fragment,l),J(Se.$$.fragment,l),J(De.$$.fragment,l),J(Cs),J(q),J(qe.$$.fragment,l),J(Ke.$$.fragment,l),J(Oe.$$.fragment,l),J(st.$$.fragment,l),Ot=!0)},o(l){y(x.$$.fragment,l),y(_.$$.fragment,l),y(U.$$.fragment,l),y(C),y(nl.$$.fragment,l),y(N.$$.fragment,l),y(R.$$.fragment,l),y(il.$$.fragment,l),y(ul.$$.fragment,l),y(hl.$$.fragment,l),y(sl.$$.fragment,l),y(r.$$.fragment,l),y(gs.$$.fragment,l),y(Cl.$$.fragment,l),y($l.$$.fragment,l),y(kl.$$.fragment,l),y(Dl.$$.fragment,l),y(Kl.$$.fragment,l),y(ls.$$.fragment,l),y(_l.$$.fragment,l),y(gl.$$.fragment,l),y(xl.$$.fragment,l),y(ol.$$.fragment,l),y(Zl.$$.fragment,l),y(Ms.$$.fragment,l),y(Bl.$$.fragment,l),y(Gl.$$.fragment,l),y(Al.$$.fragment,l),y(ys.$$.fragment,l),y(Ys.$$.fragment,l),y(Qs.$$.fragment,l),y(Vl.$$.fragment,l),y(Xl.$$.fragment,l),y(he.$$.fragment,l),y(Ie.$$.fragment,l),y(pe.$$.fragment,l),y(ke.$$.fragment,l),y(xe.$$.fragment,l),y(js),y(Be.$$.fragment,l),y(ds),y(ve.$$.fragment,l),y(Ve.$$.fragment,l),y(Xe.$$.fragment,l),y(Ye.$$.fragment,l),y(Us),y(D),y(Qe.$$.fragment,l),y(hs),y(Ee.$$.fragment,l),y(Ne.$$.fragment,l),y(Fe.$$.fragment,l),y(Se.$$.fragment,l),y(De.$$.fragment,l),y(Cs),y(q),y(qe.$$.fragment,l),y(Ke.$$.fragment,l),y(Oe.$$.fragment,l),y(st.$$.fragment,l),Ot=!1},d(l){l&&(e(u),e(i),e(f),e(h),e(B),e(W),e(G),e(k),e(X),e(El),e(Y),e(Q),e(al),e(Yl),e(A),e(E),e(S),e(H),e(L),e($s),e(pl),e(zl),e(Tl),e(Ml),e(Sl),e(wl),e(F),e(jl),e(dl),e(rl),e(z),e(fl),e(cl),e(Ql),e(v),e(Jl),e(el),e(yl),e($),e(Hs),e(Il),e(Ns),e(Fs),e(ce),e(Ll),e(zs),e(Je),e(ql),e(Pl),e(ye),e(Ol),e(ss),e(Bs),e(es),e(ts),e(oe),e(ns),e(Ss),e(Ls),e(Te),e(as),e(Ds),e(we),e(ps),e(qs),e(Ps),e(je),e(is),e(rs),e(be),e(cs),e(Ks),e(Os),e(Wl),e(le),e(se),e(de),e(Js),e(ue),e(ms),e(ee),e(vl),e(os),e(te),e(ne),e(Rl),e(ae),e(fe),e(Ts),e(c),e(dt),e(ut),e(Ce),e(Ut),e(ft),e($e),e(ht),e(It),e(_e),e(Ct),e(ge),e($t),e(kt),e(Ze),e(_t),e(it),e(gt),e(We),e(xt),e(Ge),e(Zt),e(rt),e(Ae),e(Bt),e(Wt),e(Gt),e(Re),e(At),e(vt),e(Vt),e(ct),e(Jt),e(Rt),e(yt),e(Xt),e(He),e(Yt),e(Qt),e(Et),e(ze),e(Ht),e(Nt),e(Le),e(Ft),e(zt),e(mt),e(ot),e(St),e(Pe),e(Lt),e(Dt),e(qt),e(lt),e(Pt),e(Kt),e(bt)),e(M),b(x,l),b(_,l),b(U,l),et[Z].d(l),b(nl,l),b(N,l),b(R,l),b(il,l),b(ul,l),b(hl,l),b(sl,l),b(r,l),b(gs,l),b(Cl,l),b($l,l),b(kl,l),b(Dl,l),b(Kl,l),b(ls,l),b(_l,l),b(gl,l),b(xl,l),b(ol,l),b(Zl,l),b(Ms,l),b(Bl,l),b(Gl,l),b(Al,l),b(ys,l),b(Ys,l),b(Qs,l),b(Vl,l),b(Xl,l),b(he,l),b(Ie,l),b(pe,l),b(ke,l),b(xe,l),tt[ws].d(l),b(Be,l),nt[bs].d(l),b(ve,l),b(Ve,l),b(Xe,l),b(Ye,l),at[us].d(l),D&&D.d(l),b(Qe,l),pt[fs].d(l),b(Ee,l),b(Ne,l),b(Fe,l),b(Se,l),b(De,l),Mt[Is].d(l),q&&q.d(l),b(qe,l),b(Ke,l),b(Oe,l),b(st,l)}}}const da='{"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":"Training loop","local":"training-loop","sections":[],"depth":3},{"title":"訓練循環","local":"訓練循環","sections":[],"depth":3}],"depth":2},{"title":"使用微調模型","local":"使用微調模型","sections":[],"depth":2}],"depth":1}';function ua(g,M,u){let i="pt";return Nn(()=>{const f=new URLSearchParams(window.location.search);u(0,i=f.get("fw")||"pt")}),[i]}class ga extends Fn{constructor(M){super(),zn(this,M,ua,ba,Hn,{})}}export{ga as component};
