import{s as Qn,f as vn,o as En,n as As}from"../chunks/scheduler.37c15a92.js";import{S as Hn,i as Nn,g as m,s as a,r as w,A as Fn,h as o,f as e,c as p,j as Kt,u as j,x as T,k as tl,y as zn,a as t,v as b,t as y,b as Me,d as J,w as d,p as ie}from"../chunks/index.2bf4358c.js";import{T as re}from"../chunks/Tip.363c041f.js";import{Y as Vn}from"../chunks/Youtube.1e50a667.js";import{C as I}from"../chunks/CodeBlock.4f5fc1ad.js";import{D as Yn}from"../chunks/DocNotebookDropdown.d9dfeb24.js";import{F as Sn}from"../chunks/FrameworkSwitchCourse.8d4d4ab6.js";import{H as cl,E as Ln}from"../chunks/EditOnGithub.8916dc7c.js";function Dn(g){let M,U;return M=new Yn({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(){w(M.$$.fragment)},l(i){j(M.$$.fragment,i)},m(i,f){b(M,i,f),U=!0},i(i){U||(J(M.$$.fragment,i),U=!0)},o(i){y(M.$$.fragment,i),U=!1},d(i){d(M,i)}}}function qn(g){let M,U;return M=new Yn({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(){w(M.$$.fragment)},l(i){j(M.$$.fragment,i)},m(i,f){b(M,i,f),U=!0},i(i){U||(J(M.$$.fragment,i),U=!0)},o(i){y(M.$$.fragment,i),U=!1},d(i){d(M,i)}}}function Pn(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}),T(M)!=="svelte-196ipzf"&&(M.innerHTML=U)},m(i,f){t(i,M,f)},p:As,d(i){i&&e(M)}}}function Kn(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}),T(M)!=="svelte-vqz3tk"&&(M.innerHTML=U)},m(i,f){t(i,M,f)},p:As,d(i){i&&e(M)}}}function On(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}),T(M)!=="svelte-q7rrku"&&(M.innerHTML=U)},m(i,f){t(i,M,f)},p:As,d(i){i&&e(M)}}}function la(g){let M,U,i,f="使用Keras的實際代碼將與之前非常相似;唯一的變化是將數據整理成批處理的方式和指標計算函數。",x;return M=new cl({props:{title:"使用 Keras 微調模型",local:"使用-keras-微調模型",headingTag:"h2"}}),{c(){w(M.$$.fragment),U=a(),i=m("p"),i.textContent=f},l(h){j(M.$$.fragment,h),U=p(h),i=o(h,"P",{"data-svelte-h":!0}),T(i)!=="svelte-1ay6z2d"&&(i.textContent=f)},m(h,k){b(M,h,k),t(h,U,k),t(h,i,k),x=!0},i(h){x||(J(M.$$.fragment,h),x=!0)},o(h){y(M.$$.fragment,h),x=!1},d(h){h&&(e(U),e(i)),d(M,h)}}}function sa(g){let M,U,i,f="使用 <code>Trainer</code> 的實際代碼會和以前一樣；唯一的變化是數據整理成時批處理的方式和度量計算函數。",x;return M=new cl({props:{title:"使用 Trainer API 微調模型",local:"使用-trainer-api-微調模型",headingTag:"h2"}}),{c(){w(M.$$.fragment),U=a(),i=m("p"),i.innerHTML=f},l(h){j(M.$$.fragment,h),U=p(h),i=o(h,"P",{"data-svelte-h":!0}),T(i)!=="svelte-1higdwj"&&(i.innerHTML=f)},m(h,k){b(M,h,k),t(h,U,k),t(h,i,k),x=!0},i(h){x||(J(M.$$.fragment,h),x=!0)},o(h){y(M.$$.fragment,h),x=!1},d(h){h&&(e(U),e(i)),d(M,h)}}}function ea(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(){w(M.$$.fragment)},l(i){j(M.$$.fragment,i)},m(i,f){b(M,i,f),U=!0},i(i){U||(J(M.$$.fragment,i),U=!0)},o(i){y(M.$$.fragment,i),U=!1},d(i){d(M,i)}}}function ta(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(){w(M.$$.fragment)},l(i){j(M.$$.fragment,i)},m(i,f){b(M,i,f),U=!0},i(i){U||(J(M.$$.fragment,i),U=!0)},o(i){y(M.$$.fragment,i),U=!1},d(i){d(M,i)}}}function na(g){let M,U="我們的數據整理器已準備就緒！現在，讓我們用它來製作一個帶有<code>to_tf_dataset()</code>方法的<code>tf.data.Dataset</code>。",i,f,x,h,k="Next stop: the model itself.",W;return f=new I({props:{code:"dGZfdHJhaW5fZGF0YXNldCUyMCUzRCUyMHRva2VuaXplZF9kYXRhc2V0cyU1QiUyMnRyYWluJTIyJTVELnRvX3RmX2RhdGFzZXQoJTBBJTIwJTIwJTIwJTIwY29sdW1ucyUzRCU1QiUyMmF0dGVudGlvbl9tYXNrJTIyJTJDJTIwJTIyaW5wdXRfaWRzJTIyJTJDJTIwJTIybGFiZWxzJTIyJTJDJTIwJTIydG9rZW5fdHlwZV9pZHMlMjIlNUQlMkMlMEElMjAlMjAlMjAlMjBjb2xsYXRlX2ZuJTNEZGF0YV9jb2xsYXRvciUyQyUwQSUyMCUyMCUyMCUyMHNodWZmbGUlM0RUcnVlJTJDJTBBJTIwJTIwJTIwJTIwYmF0Y2hfc2l6ZSUzRDE2JTJDJTBBKSUwQSUwQXRmX2V2YWxfZGF0YXNldCUyMCUzRCUyMHRva2VuaXplZF9kYXRhc2V0cyU1QiUyMnZhbGlkYXRpb24lMjIlNUQudG9fdGZfZGF0YXNldCglMEElMjAlMjAlMjAlMjBjb2x1bW5zJTNEJTVCJTIyYXR0ZW50aW9uX21hc2slMjIlMkMlMjAlMjJpbnB1dF9pZHMlMjIlMkMlMjAlMjJsYWJlbHMlMjIlMkMlMjAlMjJ0b2tlbl90eXBlX2lkcyUyMiU1RCUyQyUwQSUyMCUyMCUyMCUyMGNvbGxhdGVfZm4lM0RkYXRhX2NvbGxhdG9yJTJDJTBBJTIwJTIwJTIwJTIwc2h1ZmZsZSUzREZhbHNlJTJDJTBBJTIwJTIwJTIwJTIwYmF0Y2hfc2l6ZSUzRDE2JTJDJTBBKQ==",highlighted:`tf_train_dataset = tokenized_datasets[<span class="hljs-string">&quot;train&quot;</span>].to_tf_dataset(
    columns=[<span class="hljs-string">&quot;attention_mask&quot;</span>, <span class="hljs-string">&quot;input_ids&quot;</span>, <span class="hljs-string">&quot;labels&quot;</span>, <span class="hljs-string">&quot;token_type_ids&quot;</span>],
    collate_fn=data_collator,
    shuffle=<span class="hljs-literal">True</span>,
    batch_size=<span class="hljs-number">16</span>,
)

tf_eval_dataset = tokenized_datasets[<span class="hljs-string">&quot;validation&quot;</span>].to_tf_dataset(
    columns=[<span class="hljs-string">&quot;attention_mask&quot;</span>, <span class="hljs-string">&quot;input_ids&quot;</span>, <span class="hljs-string">&quot;labels&quot;</span>, <span class="hljs-string">&quot;token_type_ids&quot;</span>],
    collate_fn=data_collator,
    shuffle=<span class="hljs-literal">False</span>,
    batch_size=<span class="hljs-number">16</span>,
)`,wrap:!1}}),{c(){M=m("p"),M.innerHTML=U,i=a(),w(f.$$.fragment),x=a(),h=m("p"),h.textContent=k},l(u){M=o(u,"P",{"data-svelte-h":!0}),T(M)!=="svelte-1hvqwv4"&&(M.innerHTML=U),i=p(u),j(f.$$.fragment,u),x=p(u),h=o(u,"P",{"data-svelte-h":!0}),T(h)!=="svelte-68qel6"&&(h.textContent=k)},m(u,Z){t(u,M,Z),t(u,i,Z),b(f,u,Z),t(u,x,Z),t(u,h,Z),W=!0},i(u){W||(J(f.$$.fragment,u),W=!0)},o(u){y(f.$$.fragment,u),W=!1},d(u){u&&(e(M),e(i),e(x),e(h)),d(f,u)}}}function aa(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}),T(M)!=="svelte-1hygkvj"&&(M.innerHTML=U)},m(i,f){t(i,M,f)},i:As,o:As,d(i){i&&e(M)}}}function Rn(g){let M,U,i,f="由於我們正在研究Token分類問題，因此我們將使用 <code>AutoModelForTokenClassification</code> 類。定義這個模型時要記住的主要事情是傳遞一些關於我們的標籤數量的信息。執行此操作的最簡單方法是將該數字傳遞給 <code>num_labels</code> 參數，但是如果我們想要一個很好的推理小部件，就像我們在本節開頭看到的那樣，最好設置正確的標籤對應關係。",x,h,k="它們應該由兩個字典設置， <code>id2label</code> 和 <code>label2id</code> ，其中包含從 ID 到標籤的映射，反之亦然：",W,u,Z,B,C="現在我們可以將它們傳遞給 <code>AutoModelForTokenClassification.from_pretrained()</code> 方法，它們將在模型的配置中設置，然後保存並上傳到Hub：",G,_,v,P,hs='就像我們在<a href="/course/chapter3">第三章</a>,定義我們的 <code>AutoModelForSequenceClassification</code> ，創建模型會發出警告，提示一些權重未被使用（來自預訓練頭的權重）和一些其他權重被隨機初始化（來自新Token分類頭的權重），我們將要訓練這個模型。我們將在一分鐘內完成，但首先讓我們仔細檢查我們的模型是否具有正確數量的標籤：',nl,Q,al,K,Hl,A,Ll,E,R,O,Is="現在，我們已準備好訓練模型了！不過，我們首先要做兩件事：應該登錄到Hugging Face並定義我們的訓練超參數。如果你在notebook上工作，有一個便利功能可以幫助你做到這一點：",L,ll,Nl,X,ae="這將顯示一個小部件，您可以在其中輸入您的 Hugging Face 賬號和密碼。",Fl,Y,Dl="如果您不是在notebook上工作，只需在終端中輸入以下行：",H,Sl,zl,V,ql="登錄後，我們可以準備編譯模型所需的一切。🤗 Transformers提供了一個方便的<code>create_optimizer()</code> 函數，該函數將為您提供一個<code>AdamW</code>優化器，其中包含適當的權重衰減和學習速率衰減設置，與內置的<code>Adam</code>優化器相似，這兩者都將提高模型的性能：",N,yl,pl,sl,Pl="還要注意，我們不為<code>compile()</code>提供<code>loss</code>參數。這是因為模型實際上可以在內部計算損失 - 如果您編譯時沒有損失並在輸入字典中提供標籤（就像我們在數據集中所做的那樣），那麼模型將使用該內部損失進行訓練，這將適用於您選擇的任務和模型類型。",F,ml,ol="接下來，我們定義一個<code>PushToHubCallback</code>，以便在訓練期間將模型上傳到 Hub，並使用該回調來擬合模型：",Tl,Ml,z,wl,jl='您之前已經看過其中的大部分內容：我們設置了一些超參數（例如學習率、要訓練的 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,el,Kl,S,bl="請注意，當訓練發生時，每次保存模型時（這裡是每個epooch），它都會在後臺上傳到 Hub。這樣，如有必要，您將能夠在另一臺機器上繼續您的訓練。",dl,ul,Ul="在此階段，您可以使用模型中心上的推理小組件來測試模型並與朋友共享。您已經成功微調了令牌分類任務的模型 - 恭喜！但是，我們的模型到底有多好呢？我們應該評估一些指標來找出答案。",rl;return M=new cl({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}}),_=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}}),Q=new I({props:{code:"bW9kZWwuY29uZmlnLm51bV9sYWJlbHM=",highlighted:"model.config.num_labels",wrap:!1}}),K=new I({props:{code:"OQ==",highlighted:'<span class="hljs-number">9</span>',wrap:!1}}),A=new re({props:{warning:!0,$$slots:{default:[pa]},$$scope:{ctx:g}}}),E=new cl({props:{title:"微調模型",local:"微調模型",headingTag:"h3"}}),ll=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}}),Sl=new I({props:{code:"aHVnZ2luZ2ZhY2UtY2xpJTIwbG9naW4=",highlighted:"huggingface-cli login",wrap:!1}}),yl=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}}),Ml=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}}),el=new re({props:{$$slots:{default:[Ma]},$$scope:{ctx:g}}}),{c(){w(M.$$.fragment),U=a(),i=m("p"),i.innerHTML=f,x=a(),h=m("p"),h.innerHTML=k,W=a(),w(u.$$.fragment),Z=a(),B=m("p"),B.innerHTML=C,G=a(),w(_.$$.fragment),v=a(),P=m("p"),P.innerHTML=hs,nl=a(),w(Q.$$.fragment),al=a(),w(K.$$.fragment),Hl=a(),w(A.$$.fragment),Ll=a(),w(E.$$.fragment),R=a(),O=m("p"),O.textContent=Is,L=a(),w(ll.$$.fragment),Nl=a(),X=m("p"),X.textContent=ae,Fl=a(),Y=m("p"),Y.textContent=Dl,H=a(),w(Sl.$$.fragment),zl=a(),V=m("p"),V.innerHTML=ql,N=a(),w(yl.$$.fragment),pl=a(),sl=m("p"),sl.innerHTML=Pl,F=a(),ml=m("p"),ml.innerHTML=ol,Tl=a(),w(Ml.$$.fragment),z=a(),wl=m("p"),wl.innerHTML=jl,il=a(),w(el.$$.fragment),Kl=a(),S=m("p"),S.textContent=bl,dl=a(),ul=m("p"),ul.textContent=Ul},l(r){j(M.$$.fragment,r),U=p(r),i=o(r,"P",{"data-svelte-h":!0}),T(i)!=="svelte-1min3sz"&&(i.innerHTML=f),x=p(r),h=o(r,"P",{"data-svelte-h":!0}),T(h)!=="svelte-6jnith"&&(h.innerHTML=k),W=p(r),j(u.$$.fragment,r),Z=p(r),B=o(r,"P",{"data-svelte-h":!0}),T(B)!=="svelte-a1wka0"&&(B.innerHTML=C),G=p(r),j(_.$$.fragment,r),v=p(r),P=o(r,"P",{"data-svelte-h":!0}),T(P)!=="svelte-1t3x82c"&&(P.innerHTML=hs),nl=p(r),j(Q.$$.fragment,r),al=p(r),j(K.$$.fragment,r),Hl=p(r),j(A.$$.fragment,r),Ll=p(r),j(E.$$.fragment,r),R=p(r),O=o(r,"P",{"data-svelte-h":!0}),T(O)!=="svelte-lwyrol"&&(O.textContent=Is),L=p(r),j(ll.$$.fragment,r),Nl=p(r),X=o(r,"P",{"data-svelte-h":!0}),T(X)!=="svelte-zkdh66"&&(X.textContent=ae),Fl=p(r),Y=o(r,"P",{"data-svelte-h":!0}),T(Y)!=="svelte-pruo9h"&&(Y.textContent=Dl),H=p(r),j(Sl.$$.fragment,r),zl=p(r),V=o(r,"P",{"data-svelte-h":!0}),T(V)!=="svelte-kol9d8"&&(V.innerHTML=ql),N=p(r),j(yl.$$.fragment,r),pl=p(r),sl=o(r,"P",{"data-svelte-h":!0}),T(sl)!=="svelte-2u3hy3"&&(sl.innerHTML=Pl),F=p(r),ml=o(r,"P",{"data-svelte-h":!0}),T(ml)!=="svelte-jv6tr4"&&(ml.innerHTML=ol),Tl=p(r),j(Ml.$$.fragment,r),z=p(r),wl=o(r,"P",{"data-svelte-h":!0}),T(wl)!=="svelte-1hzakdn"&&(wl.innerHTML=jl),il=p(r),j(el.$$.fragment,r),Kl=p(r),S=o(r,"P",{"data-svelte-h":!0}),T(S)!=="svelte-phco4r"&&(S.textContent=bl),dl=p(r),ul=o(r,"P",{"data-svelte-h":!0}),T(ul)!=="svelte-1m3wx0m"&&(ul.textContent=Ul)},m(r,$){b(M,r,$),t(r,U,$),t(r,i,$),t(r,x,$),t(r,h,$),t(r,W,$),b(u,r,$),t(r,Z,$),t(r,B,$),t(r,G,$),b(_,r,$),t(r,v,$),t(r,P,$),t(r,nl,$),b(Q,r,$),t(r,al,$),b(K,r,$),t(r,Hl,$),b(A,r,$),t(r,Ll,$),b(E,r,$),t(r,R,$),t(r,O,$),t(r,L,$),b(ll,r,$),t(r,Nl,$),t(r,X,$),t(r,Fl,$),t(r,Y,$),t(r,H,$),b(Sl,r,$),t(r,zl,$),t(r,V,$),t(r,N,$),b(yl,r,$),t(r,pl,$),t(r,sl,$),t(r,F,$),t(r,ml,$),t(r,Tl,$),b(Ml,r,$),t(r,z,$),t(r,wl,$),t(r,il,$),b(el,r,$),t(r,Kl,$),t(r,S,$),t(r,dl,$),t(r,ul,$),rl=!0},i(r){rl||(J(M.$$.fragment,r),J(u.$$.fragment,r),J(_.$$.fragment,r),J(Q.$$.fragment,r),J(K.$$.fragment,r),J(A.$$.fragment,r),J(E.$$.fragment,r),J(ll.$$.fragment,r),J(Sl.$$.fragment,r),J(yl.$$.fragment,r),J(Ml.$$.fragment,r),J(el.$$.fragment,r),rl=!0)},o(r){y(M.$$.fragment,r),y(u.$$.fragment,r),y(_.$$.fragment,r),y(Q.$$.fragment,r),y(K.$$.fragment,r),y(A.$$.fragment,r),y(E.$$.fragment,r),y(ll.$$.fragment,r),y(Sl.$$.fragment,r),y(yl.$$.fragment,r),y(Ml.$$.fragment,r),y(el.$$.fragment,r),rl=!1},d(r){r&&(e(U),e(i),e(x),e(h),e(W),e(Z),e(B),e(G),e(v),e(P),e(nl),e(al),e(Hl),e(Ll),e(R),e(O),e(L),e(Nl),e(X),e(Fl),e(Y),e(H),e(zl),e(V),e(N),e(pl),e(sl),e(F),e(ml),e(Tl),e(z),e(wl),e(il),e(Kl),e(S),e(dl),e(ul)),d(M,r),d(u,r),d(_,r),d(Q,r),d(K,r),d(A,r),d(E,r),d(ll,r),d(Sl,r),d(yl,r),d(Ml,r),d(el,r)}}}function pa(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}),T(M)!=="svelte-yordje"&&(M.innerHTML=U)},m(i,f){t(i,M,f)},p:As,d(i){i&&e(M)}}}function Ma(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}),T(M)!=="svelte-kwyipi"&&(M.innerHTML=U)},m(i,f){t(i,M,f)},p:As,d(i){i&&e(M)}}}function ia(g){let M,U='用於評估Token分類預測的傳統框架是 <a href="https://github.com/chakki-works/seqeval" rel="nofollow"><em>seqeval</em></a>. 要使用此指標，我們首先需要安裝seqeval庫：',i,f,x,h,k='然後我們可以通過加載它 <code>load_metric()</code> 函數就像我們在<a href="/course/chapter3">第三章</a>做的那樣：',W;return f=new I({props:{code:"IXBpcCUyMGluc3RhbGwlMjBzZXFldmFs",highlighted:"!pip install seqeval",wrap:!1}}),{c(){M=m("p"),M.innerHTML=U,i=a(),w(f.$$.fragment),x=a(),h=m("p"),h.innerHTML=k},l(u){M=o(u,"P",{"data-svelte-h":!0}),T(M)!=="svelte-16kw28d"&&(M.innerHTML=U),i=p(u),j(f.$$.fragment,u),x=p(u),h=o(u,"P",{"data-svelte-h":!0}),T(h)!=="svelte-14sahcb"&&(h.innerHTML=k)},m(u,Z){t(u,M,Z),t(u,i,Z),b(f,u,Z),t(u,x,Z),t(u,h,Z),W=!0},i(u){W||(J(f.$$.fragment,u),W=!0)},o(u){y(f.$$.fragment,u),W=!1},d(u){u&&(e(M),e(i),e(x),e(h)),d(f,u)}}}function ra(g){let M,U="為了讓 <code>Trainer</code> 在每個epoch計算一個度量，我們需要定義一個 <code>compute_metrics()</code> 函數，該函數接受預測和標籤數組，並返回一個包含度量名稱和值的字典",i,f,x='用於評估Token分類預測的傳統框架是 <a href="https://github.com/chakki-works/seqeval" rel="nofollow"><em>seqeval</em></a>. 要使用此指標，我們首先需要安裝seqeval庫：',h,k,W,u,Z='然後我們可以通過加載它 <code>load_metric()</code> 函數就像我們在<a href="/course/chapter3">第三章</a>做的那樣：',B;return k=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(),w(k.$$.fragment),W=a(),u=m("p"),u.innerHTML=Z},l(C){M=o(C,"P",{"data-svelte-h":!0}),T(M)!=="svelte-zayi6n"&&(M.innerHTML=U),i=p(C),f=o(C,"P",{"data-svelte-h":!0}),T(f)!=="svelte-16kw28d"&&(f.innerHTML=x),h=p(C),j(k.$$.fragment,C),W=p(C),u=o(C,"P",{"data-svelte-h":!0}),T(u)!=="svelte-14sahcb"&&(u.innerHTML=Z)},m(C,G){t(C,M,G),t(C,i,G),t(C,f,G),t(C,h,G),b(k,C,G),t(C,W,G),t(C,u,G),B=!0},i(C){B||(J(k.$$.fragment,C),B=!0)},o(C){y(k.$$.fragment,C),B=!1},d(C){C&&(e(M),e(i),e(f),e(h),e(W),e(u)),d(k,C)}}}function ca(g){let M,U="它返回很多信息！我們獲得每個單獨實體以及整體的準確率、召回率和 F1 分數。對於我們的度量計算，我們將只保留總分，但可以隨意調整 <code>compute_metrics()</code> 函數返回您想要查看的所有指標。",i,f,x="這<code>compute_metrics()</code> 函數首先採用 logits 的 argmax 將它們轉換為預測（像往常一樣，logits 和概率的順序相同，因此我們不需要應用 softmax）。然後我們必須將標籤和預測從整數轉換為字符串。我們刪除標籤為 <code>-100</code> 所有值 ，然後將結果傳遞給 <code>metric.compute()</code> 方法：",h,k,W,u,Z,B,C="與我們的模型相比，您的模型做得如何？如果您獲得類似的數字，那麼您的訓練就是成功的！",G;return k=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(),w(k.$$.fragment),W=a(),w(u.$$.fragment),Z=a(),B=m("p"),B.textContent=C},l(_){M=o(_,"P",{"data-svelte-h":!0}),T(M)!=="svelte-1ir5cl6"&&(M.innerHTML=U),i=p(_),f=o(_,"P",{"data-svelte-h":!0}),T(f)!=="svelte-840r4r"&&(f.innerHTML=x),h=p(_),j(k.$$.fragment,_),W=p(_),j(u.$$.fragment,_),Z=p(_),B=o(_,"P",{"data-svelte-h":!0}),T(B)!=="svelte-pcd2bo"&&(B.textContent=C)},m(_,v){t(_,M,v),t(_,i,v),t(_,f,v),t(_,h,v),b(k,_,v),t(_,W,v),b(u,_,v),t(_,Z,v),t(_,B,v),G=!0},i(_){G||(J(k.$$.fragment,_),J(u.$$.fragment,_),G=!0)},o(_){y(k.$$.fragment,_),y(u.$$.fragment,_),G=!1},d(_){_&&(e(M),e(i),e(f),e(h),e(W),e(Z),e(B)),d(k,_),d(u,_)}}}function Ja(g){let M,U="它返回很多信息！我們獲得每個單獨實體以及整體的準確率、召回率和 F1 分數。對於我們的度量計算，我們將只保留總分，但可以隨意調整 <code>compute_metrics()</code> 函數返回您想要查看的所有指標。",i,f,x="這<code>compute_metrics()</code> 函數首先採用 logits 的 argmax 將它們轉換為預測（像往常一樣，logits 和概率的順序相同，因此我們不需要應用 softmax）。然後我們必須將標籤和預測從整數轉換為字符串。我們刪除標籤為 <code>-100</code> 所有值 ，然後將結果傳遞給 <code>metric.compute()</code> 方法：",h,k,W,u,Z="現在已經完成了，我們幾乎準備好定義我們的 <code>Trainer</code> .我們只需要一個 <code>model</code> 微調！",B;return k=new I({props:{code:"aW1wb3J0JTIwbnVtcHklMjBhcyUyMG5wJTBBJTBBJTBBZGVmJTIwY29tcHV0ZV9tZXRyaWNzKGV2YWxfcHJlZHMpJTNBJTBBJTIwJTIwJTIwJTIwbG9naXRzJTJDJTIwbGFiZWxzJTIwJTNEJTIwZXZhbF9wcmVkcyUwQSUyMCUyMCUyMCUyMHByZWRpY3Rpb25zJTIwJTNEJTIwbnAuYXJnbWF4KGxvZ2l0cyUyQyUyMGF4aXMlM0QtMSklMEElMEElMjAlMjAlMjAlMjAlMjMlMjBSZW1vdmUlMjBpZ25vcmVkJTIwaW5kZXglMjAoc3BlY2lhbCUyMHRva2VucyklMjBhbmQlMjBjb252ZXJ0JTIwdG8lMjBsYWJlbHMlMEElMjAlMjAlMjAlMjB0cnVlX2xhYmVscyUyMCUzRCUyMCU1QiU1QmxhYmVsX25hbWVzJTVCbCU1RCUyMGZvciUyMGwlMjBpbiUyMGxhYmVsJTIwaWYlMjBsJTIwISUzRCUyMC0xMDAlNUQlMjBmb3IlMjBsYWJlbCUyMGluJTIwbGFiZWxzJTVEJTBBJTIwJTIwJTIwJTIwdHJ1ZV9wcmVkaWN0aW9ucyUyMCUzRCUyMCU1QiUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCU1QmxhYmVsX25hbWVzJTVCcCU1RCUyMGZvciUyMChwJTJDJTIwbCklMjBpbiUyMHppcChwcmVkaWN0aW9uJTJDJTIwbGFiZWwpJTIwaWYlMjBsJTIwISUzRCUyMC0xMDAlNUQlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBmb3IlMjBwcmVkaWN0aW9uJTJDJTIwbGFiZWwlMjBpbiUyMHppcChwcmVkaWN0aW9ucyUyQyUyMGxhYmVscyklMEElMjAlMjAlMjAlMjAlNUQlMEElMjAlMjAlMjAlMjBhbGxfbWV0cmljcyUyMCUzRCUyMG1ldHJpYy5jb21wdXRlKHByZWRpY3Rpb25zJTNEdHJ1ZV9wcmVkaWN0aW9ucyUyQyUyMHJlZmVyZW5jZXMlM0R0cnVlX2xhYmVscyklMEElMjAlMjAlMjAlMjByZXR1cm4lMjAlN0IlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjJwcmVjaXNpb24lMjIlM0ElMjBhbGxfbWV0cmljcyU1QiUyMm92ZXJhbGxfcHJlY2lzaW9uJTIyJTVEJTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIycmVjYWxsJTIyJTNBJTIwYWxsX21ldHJpY3MlNUIlMjJvdmVyYWxsX3JlY2FsbCUyMiU1RCUyQyUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMmYxJTIyJTNBJTIwYWxsX21ldHJpY3MlNUIlMjJvdmVyYWxsX2YxJTIyJTVEJTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIyYWNjdXJhY3klMjIlM0ElMjBhbGxfbWV0cmljcyU1QiUyMm92ZXJhbGxfYWNjdXJhY3klMjIlNUQlMkMlMEElMjAlMjAlMjAlMjAlN0Q=",highlighted:`<span class="hljs-keyword">import</span> numpy <span class="hljs-keyword">as</span> np


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

    <span class="hljs-comment"># Remove ignored index (special tokens) and convert to labels</span>
    true_labels = [[label_names[l] <span class="hljs-keyword">for</span> l <span class="hljs-keyword">in</span> label <span class="hljs-keyword">if</span> l != -<span class="hljs-number">100</span>] <span class="hljs-keyword">for</span> label <span class="hljs-keyword">in</span> labels]
    true_predictions = [
        [label_names[p] <span class="hljs-keyword">for</span> (p, l) <span class="hljs-keyword">in</span> <span class="hljs-built_in">zip</span>(prediction, label) <span class="hljs-keyword">if</span> l != -<span class="hljs-number">100</span>]
        <span class="hljs-keyword">for</span> prediction, label <span class="hljs-keyword">in</span> <span class="hljs-built_in">zip</span>(predictions, labels)
    ]
    all_metrics = metric.compute(predictions=true_predictions, references=true_labels)
    <span class="hljs-keyword">return</span> {
        <span class="hljs-string">&quot;precision&quot;</span>: all_metrics[<span class="hljs-string">&quot;overall_precision&quot;</span>],
        <span class="hljs-string">&quot;recall&quot;</span>: all_metrics[<span class="hljs-string">&quot;overall_recall&quot;</span>],
        <span class="hljs-string">&quot;f1&quot;</span>: all_metrics[<span class="hljs-string">&quot;overall_f1&quot;</span>],
        <span class="hljs-string">&quot;accuracy&quot;</span>: all_metrics[<span class="hljs-string">&quot;overall_accuracy&quot;</span>],
    }`,wrap:!1}}),{c(){M=m("p"),M.innerHTML=U,i=a(),f=m("p"),f.innerHTML=x,h=a(),w(k.$$.fragment),W=a(),u=m("p"),u.innerHTML=Z},l(C){M=o(C,"P",{"data-svelte-h":!0}),T(M)!=="svelte-1ir5cl6"&&(M.innerHTML=U),i=p(C),f=o(C,"P",{"data-svelte-h":!0}),T(f)!=="svelte-840r4r"&&(f.innerHTML=x),h=p(C),j(k.$$.fragment,C),W=p(C),u=o(C,"P",{"data-svelte-h":!0}),T(u)!=="svelte-b1rvpq"&&(u.innerHTML=Z)},m(C,G){t(C,M,G),t(C,i,G),t(C,f,G),t(C,h,G),b(k,C,G),t(C,W,G),t(C,u,G),B=!0},i(C){B||(J(k.$$.fragment,C),B=!0)},o(C){y(k.$$.fragment,C),B=!1},d(C){C&&(e(M),e(i),e(f),e(h),e(W),e(u)),d(k,C)}}}function Xn(g){let M,U,i,f="由於我們正在研究Token分類問題，因此我們將使用 <code>AutoModelForTokenClassification</code> 類。定義這個模型時要記住的主要事情是傳遞一些關於我們的標籤數量的信息。執行此操作的最簡單方法是將該數字傳遞給 <code>num_labels</code> 參數，但是如果我們想要一個很好的推理小部件，就像我們在本節開頭看到的那樣，最好設置正確的標籤對應關係。",x,h,k="它們應該由兩個字典設置， <code>id2label</code> 和 <code>label2id</code> ，其中包含從 ID 到標籤的映射，反之亦然：",W,u,Z,B,C="現在我們可以將它們傳遞給 <code>AutoModelForTokenClassification.from_pretrained()</code> 方法，它們將在模型的配置中設置，然後保存並上傳到Hub：",G,_,v,P,hs='就像我們在<a href="/course/chapter3">第三章</a>,定義我們的 <code>AutoModelForSequenceClassification</code> ，創建模型會發出警告，提示一些權重未被使用（來自預訓練頭的權重）和一些其他權重被隨機初始化（來自新Token分類頭的權重），我們將要訓練這個模型。我們將在一分鐘內完成，但首先讓我們仔細檢查我們的模型是否具有正確數量的標籤：',nl,Q,al,K,Hl,A,Ll,E,R,O,Is="我們現在準備好訓練我們的模型了！在定義我們的 <code>Trainer</code>之前，我們只需要做最後兩件事：登錄 Hugging Face 並定義我們的訓練參數。如果您在notebook上工作，有一個方便的功能可以幫助您：",L,ll,Nl,X,ae="這將顯示一個小部件，您可以在其中輸入您的 Hugging Face 賬號和密碼。如果您不是在notebook上工作，只需在終端中輸入以下行：",Fl,Y,Dl,H,Sl="Once this is done, we can define our <code>TrainingArguments</code>:",zl,V,ql,N,yl='您之前已經看過其中的大部分內容：我們設置了一些超參數（例如學習率、要訓練的 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>。',pl,sl,Pl,F,ml="最後，我們只是將所有內容傳遞給 <code>Trainer</code> 並啟動訓練：",ol,Tl,Ml,z,wl="請注意，當訓練發生時，每次保存模型時（這裡是每個epooch），它都會在後臺上傳到 Hub。這樣，如有必要，您將能夠在另一臺機器上繼續您的訓練。",jl,il,el="訓練完成後，我們使用 <code>push_to_hub()</code> 確保我們上傳模型的最新版本",Kl,S,bl,dl,ul="This command returns the URL of the commit it just did, if you want to inspect it:",Ul,rl,r,$,Cs="這 <code>Trainer</code> 還創建了一張包含所有評估結果的模型卡並上傳。在此階段，您可以使用模型中心上的推理小部件來測試您的模型並與您的朋友分享。您已成功在Token分類任務上微調模型 - 恭喜！",ce,Ol,$s="如果您想更深入地瞭解訓練循環，我們現在將向您展示如何使用 🤗 Accelerate 做同樣的事情。",vs,fl,Vs,hl,ct='現在讓我們看一下完整的訓練循環，這樣您可以輕鬆定義所需的部分。它看起來很像我們在<a href="/course/chapter3/4">第三章</a>, 所做的，對評估進行了一些更改。',Rs,Il,Xs,Cl,Je="首先我們需要為我們的數據集構建 <code>DataLoader</code> 。我們將重用我們的 <code>data_collator</code> 作為一個 <code>collate_fn</code> 並打亂訓練集，但不打亂驗證集：",ls,ks,Ys,$l,ye="接下來，我們重新實例化我們的模型，以確保我們不會從之前的訓練繼續訓練，而是再次從 BERT 預訓練模型開始：",ss,es,ts,_s,me="然後我們將需要一個優化器。我們將使用經典 <code>AdamW</code> ，這就像 <code>Adam</code> ，但在應用權重衰減的方式上進行了改進：",ns,gs,Qs,kl,Jt="Once we have all those objects, we can send them to the <code>accelerator.prepare()</code> method:",Es,_l,Hs,gl,Ns,xl,yt="現在我們已經發送了我們的 <code>train_dataloader</code> 到 <code>accelerator.prepare()</code> ，我們可以使用它的長度來計算訓練步驟的數量。請記住，我們應該始終在準備好dataloader後執行此操作，因為該方法會改變其長度。我們使用經典線性學習率調度：",Fs,Zl,zs,Bl,mt="最後，要將我們的模型推送到 Hub，我們需要創建一個 <code>Repository</code> 工作文件夾中的對象。如果您尚未登錄，請先登錄 Hugging Face。我們將從我們想要為模型提供的模型 ID 中確定存儲庫名稱（您可以自由地用自己的選擇替換 <code>repo_name</code> ；它只需要包含您的用戶名，可以使用<code>get_full_repo_name()</code>函數的查看目前的repo_name）：",Ss,Jl,Ls,Wl,Ds,Gl,oe="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:",as,xs,qs,Al,ot="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.",Ps,vl,Ks,Vl,Te,ps,Zs="我們現在準備編寫完整的訓練循環。為了簡化它的評估部分，我們定義了這個 <code>postprocess()</code> 接受預測和標籤並將它們轉換為字符串列表的函數，也就是 <code>metric</code>對象需要的輸入格式：",Os,Rl,le,Xl,Tt="然後我們可以編寫訓練循環。在定義一個進度條來跟蹤訓練的進行後，循環分為三個部分：",se,Yl,we="<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>",Ms,is,Bs="這是訓練循環的完整代碼：",je,rs,cs,Js,Ws="果這是您第一次看到用 🤗 Accelerate 保存的模型，讓我們花點時間檢查一下它附帶的三行代碼：",ee,Ql,be,ys,Gs=`第一行是不言自明的：它告訴所有進程等到都處於那個階段再繼續(阻塞)。這是為了確保在保存之前，我們在每個過程中都有相同的模型。然後獲取<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>。`,te,El,wt='當完成之後，你應該有一個模型，它產生的結果與<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>中查看我們使用這個代碼訓練的模型。如果你想測試訓練循環的任何調整，你可以直接通過編輯上面顯示的代碼來實現它們!',ne;return M=new cl({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}}),_=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}}),Q=new I({props:{code:"bW9kZWwuY29uZmlnLm51bV9sYWJlbHM=",highlighted:"model.config.num_labels",wrap:!1}}),K=new I({props:{code:"OQ==",highlighted:'<span class="hljs-number">9</span>',wrap:!1}}),A=new re({props:{warning:!0,$$slots:{default:[ya]},$$scope:{ctx:g}}}),E=new cl({props:{title:"微調模型",local:"微調模型",headingTag:"h3"}}),ll=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}}),Y=new I({props:{code:"aHVnZ2luZ2ZhY2UtY2xpJTIwbG9naW4=",highlighted:"huggingface-cli login",wrap:!1}}),V=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}}),sl=new re({props:{$$slots:{default:[ma]},$$scope:{ctx:g}}}),Tl=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}}),S=new I({props:{code:"dHJhaW5lci5wdXNoX3RvX2h1Yihjb21taXRfbWVzc2FnZSUzRCUyMlRyYWluaW5nJTIwY29tcGxldGUlMjIp",highlighted:'trainer.push_to_hub(commit_message=<span class="hljs-string">&quot;Training complete&quot;</span>)',wrap:!1}}),rl=new I({props:{code:"J2h0dHBzJTNBJTJGJTJGaHVnZ2luZ2ZhY2UuY28lMkZzZ3VnZ2VyJTJGYmVydC1maW5ldHVuZWQtbmVyJTJGY29tbWl0JTJGMjZhYjIxZTViMTU2OGY5YWZlY2NkYWVkMmQ4NzE1ZjU3MWQ3ODZlZCc=",highlighted:'<span class="hljs-string">&#x27;https://huggingface.co/sgugger/bert-finetuned-ner/commit/26ab21e5b1568f9afeccdaed2d8715f571d786ed&#x27;</span>',wrap:!1}}),fl=new cl({props:{title:"自定義訓練循環",local:"自定義訓練循環",headingTag:"h2"}}),Il=new cl({props:{title:"做好訓練前的準備",local:"做好訓練前的準備",headingTag:"h3"}}),ks=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}}),es=new I({props:{code:"bW9kZWwlMjAlM0QlMjBBdXRvTW9kZWxGb3JUb2tlbkNsYXNzaWZpY2F0aW9uLmZyb21fcHJldHJhaW5lZCglMEElMjAlMjAlMjAlMjBtb2RlbF9jaGVja3BvaW50JTJDJTBBJTIwJTIwJTIwJTIwaWQybGFiZWwlM0RpZDJsYWJlbCUyQyUwQSUyMCUyMCUyMCUyMGxhYmVsMmlkJTNEbGFiZWwyaWQlMkMlMEEp",highlighted:`model = AutoModelForTokenClassification.from_pretrained(
    model_checkpoint,
    id2label=id2label,
    label2id=label2id,
)`,wrap:!1}}),gs=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}}),_l=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}}),gl=new re({props:{$$slots:{default:[oa]},$$scope:{ctx:g}}}),Zl=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}}),Jl=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}}),Wl=new I({props:{code:"J3NndWdnZXIlMkZiZXJ0LWZpbmV0dW5lZC1uZXItYWNjZWxlcmF0ZSc=",highlighted:'<span class="hljs-string">&#x27;sgugger/bert-finetuned-ner-accelerate&#x27;</span>',wrap:!1}}),xs=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}}),vl=new cl({props:{title:"Training loop",local:"training-loop",headingTag:"h3"}}),Vl=new cl({props:{title:"訓練循環",local:"訓練循環",headingTag:"h3"}}),Rl=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}}),rs=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}}),Ql=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(){w(M.$$.fragment),U=a(),i=m("p"),i.innerHTML=f,x=a(),h=m("p"),h.innerHTML=k,W=a(),w(u.$$.fragment),Z=a(),B=m("p"),B.innerHTML=C,G=a(),w(_.$$.fragment),v=a(),P=m("p"),P.innerHTML=hs,nl=a(),w(Q.$$.fragment),al=a(),w(K.$$.fragment),Hl=a(),w(A.$$.fragment),Ll=a(),w(E.$$.fragment),R=a(),O=m("p"),O.innerHTML=Is,L=a(),w(ll.$$.fragment),Nl=a(),X=m("p"),X.textContent=ae,Fl=a(),w(Y.$$.fragment),Dl=a(),H=m("p"),H.innerHTML=Sl,zl=a(),w(V.$$.fragment),ql=a(),N=m("p"),N.innerHTML=yl,pl=a(),w(sl.$$.fragment),Pl=a(),F=m("p"),F.innerHTML=ml,ol=a(),w(Tl.$$.fragment),Ml=a(),z=m("p"),z.textContent=wl,jl=a(),il=m("p"),il.innerHTML=el,Kl=a(),w(S.$$.fragment),bl=a(),dl=m("p"),dl.textContent=ul,Ul=a(),w(rl.$$.fragment),r=a(),$=m("p"),$.innerHTML=Cs,ce=a(),Ol=m("p"),Ol.textContent=$s,vs=a(),w(fl.$$.fragment),Vs=a(),hl=m("p"),hl.innerHTML=ct,Rs=a(),w(Il.$$.fragment),Xs=a(),Cl=m("p"),Cl.innerHTML=Je,ls=a(),w(ks.$$.fragment),Ys=a(),$l=m("p"),$l.textContent=ye,ss=a(),w(es.$$.fragment),ts=a(),_s=m("p"),_s.innerHTML=me,ns=a(),w(gs.$$.fragment),Qs=a(),kl=m("p"),kl.innerHTML=Jt,Es=a(),w(_l.$$.fragment),Hs=a(),w(gl.$$.fragment),Ns=a(),xl=m("p"),xl.innerHTML=yt,Fs=a(),w(Zl.$$.fragment),zs=a(),Bl=m("p"),Bl.innerHTML=mt,Ss=a(),w(Jl.$$.fragment),Ls=a(),w(Wl.$$.fragment),Ds=a(),Gl=m("p"),Gl.textContent=oe,as=a(),w(xs.$$.fragment),qs=a(),Al=m("p"),Al.innerHTML=ot,Ps=a(),w(vl.$$.fragment),Ks=a(),w(Vl.$$.fragment),Te=a(),ps=m("p"),ps.innerHTML=Zs,Os=a(),w(Rl.$$.fragment),le=a(),Xl=m("p"),Xl.textContent=Tt,se=a(),Yl=m("ul"),Yl.innerHTML=we,Ms=a(),is=m("p"),is.textContent=Bs,je=a(),w(rs.$$.fragment),cs=a(),Js=m("p"),Js.textContent=Ws,ee=a(),w(Ql.$$.fragment),be=a(),ys=m("p"),ys.innerHTML=Gs,te=a(),El=m("p"),El.innerHTML=wt},l(s){j(M.$$.fragment,s),U=p(s),i=o(s,"P",{"data-svelte-h":!0}),T(i)!=="svelte-1min3sz"&&(i.innerHTML=f),x=p(s),h=o(s,"P",{"data-svelte-h":!0}),T(h)!=="svelte-6jnith"&&(h.innerHTML=k),W=p(s),j(u.$$.fragment,s),Z=p(s),B=o(s,"P",{"data-svelte-h":!0}),T(B)!=="svelte-a1wka0"&&(B.innerHTML=C),G=p(s),j(_.$$.fragment,s),v=p(s),P=o(s,"P",{"data-svelte-h":!0}),T(P)!=="svelte-1t3x82c"&&(P.innerHTML=hs),nl=p(s),j(Q.$$.fragment,s),al=p(s),j(K.$$.fragment,s),Hl=p(s),j(A.$$.fragment,s),Ll=p(s),j(E.$$.fragment,s),R=p(s),O=o(s,"P",{"data-svelte-h":!0}),T(O)!=="svelte-7s0gb6"&&(O.innerHTML=Is),L=p(s),j(ll.$$.fragment,s),Nl=p(s),X=o(s,"P",{"data-svelte-h":!0}),T(X)!=="svelte-162697j"&&(X.textContent=ae),Fl=p(s),j(Y.$$.fragment,s),Dl=p(s),H=o(s,"P",{"data-svelte-h":!0}),T(H)!=="svelte-h1gi55"&&(H.innerHTML=Sl),zl=p(s),j(V.$$.fragment,s),ql=p(s),N=o(s,"P",{"data-svelte-h":!0}),T(N)!=="svelte-8bm5dv"&&(N.innerHTML=yl),pl=p(s),j(sl.$$.fragment,s),Pl=p(s),F=o(s,"P",{"data-svelte-h":!0}),T(F)!=="svelte-1wvlrrj"&&(F.innerHTML=ml),ol=p(s),j(Tl.$$.fragment,s),Ml=p(s),z=o(s,"P",{"data-svelte-h":!0}),T(z)!=="svelte-phco4r"&&(z.textContent=wl),jl=p(s),il=o(s,"P",{"data-svelte-h":!0}),T(il)!=="svelte-ka8crc"&&(il.innerHTML=el),Kl=p(s),j(S.$$.fragment,s),bl=p(s),dl=o(s,"P",{"data-svelte-h":!0}),T(dl)!=="svelte-mme7gz"&&(dl.textContent=ul),Ul=p(s),j(rl.$$.fragment,s),r=p(s),$=o(s,"P",{"data-svelte-h":!0}),T($)!=="svelte-pzk96o"&&($.innerHTML=Cs),ce=p(s),Ol=o(s,"P",{"data-svelte-h":!0}),T(Ol)!=="svelte-1a0w12w"&&(Ol.textContent=$s),vs=p(s),j(fl.$$.fragment,s),Vs=p(s),hl=o(s,"P",{"data-svelte-h":!0}),T(hl)!=="svelte-159ygmk"&&(hl.innerHTML=ct),Rs=p(s),j(Il.$$.fragment,s),Xs=p(s),Cl=o(s,"P",{"data-svelte-h":!0}),T(Cl)!=="svelte-3n70bh"&&(Cl.innerHTML=Je),ls=p(s),j(ks.$$.fragment,s),Ys=p(s),$l=o(s,"P",{"data-svelte-h":!0}),T($l)!=="svelte-1ytjtup"&&($l.textContent=ye),ss=p(s),j(es.$$.fragment,s),ts=p(s),_s=o(s,"P",{"data-svelte-h":!0}),T(_s)!=="svelte-ps3jgc"&&(_s.innerHTML=me),ns=p(s),j(gs.$$.fragment,s),Qs=p(s),kl=o(s,"P",{"data-svelte-h":!0}),T(kl)!=="svelte-1oqv3so"&&(kl.innerHTML=Jt),Es=p(s),j(_l.$$.fragment,s),Hs=p(s),j(gl.$$.fragment,s),Ns=p(s),xl=o(s,"P",{"data-svelte-h":!0}),T(xl)!=="svelte-87bmw4"&&(xl.innerHTML=yt),Fs=p(s),j(Zl.$$.fragment,s),zs=p(s),Bl=o(s,"P",{"data-svelte-h":!0}),T(Bl)!=="svelte-1gs3lys"&&(Bl.innerHTML=mt),Ss=p(s),j(Jl.$$.fragment,s),Ls=p(s),j(Wl.$$.fragment,s),Ds=p(s),Gl=o(s,"P",{"data-svelte-h":!0}),T(Gl)!=="svelte-lt5x8r"&&(Gl.textContent=oe),as=p(s),j(xs.$$.fragment,s),qs=p(s),Al=o(s,"P",{"data-svelte-h":!0}),T(Al)!=="svelte-1mcbsiy"&&(Al.innerHTML=ot),Ps=p(s),j(vl.$$.fragment,s),Ks=p(s),j(Vl.$$.fragment,s),Te=p(s),ps=o(s,"P",{"data-svelte-h":!0}),T(ps)!=="svelte-1t2yu5i"&&(ps.innerHTML=Zs),Os=p(s),j(Rl.$$.fragment,s),le=p(s),Xl=o(s,"P",{"data-svelte-h":!0}),T(Xl)!=="svelte-892gxr"&&(Xl.textContent=Tt),se=p(s),Yl=o(s,"UL",{"data-svelte-h":!0}),T(Yl)!=="svelte-16hmptw"&&(Yl.innerHTML=we),Ms=p(s),is=o(s,"P",{"data-svelte-h":!0}),T(is)!=="svelte-uj337y"&&(is.textContent=Bs),je=p(s),j(rs.$$.fragment,s),cs=p(s),Js=o(s,"P",{"data-svelte-h":!0}),T(Js)!=="svelte-1qbz863"&&(Js.textContent=Ws),ee=p(s),j(Ql.$$.fragment,s),be=p(s),ys=o(s,"P",{"data-svelte-h":!0}),T(ys)!=="svelte-1dlsben"&&(ys.innerHTML=Gs),te=p(s),El=o(s,"P",{"data-svelte-h":!0}),T(El)!=="svelte-ircn2g"&&(El.innerHTML=wt)},m(s,c){b(M,s,c),t(s,U,c),t(s,i,c),t(s,x,c),t(s,h,c),t(s,W,c),b(u,s,c),t(s,Z,c),t(s,B,c),t(s,G,c),b(_,s,c),t(s,v,c),t(s,P,c),t(s,nl,c),b(Q,s,c),t(s,al,c),b(K,s,c),t(s,Hl,c),b(A,s,c),t(s,Ll,c),b(E,s,c),t(s,R,c),t(s,O,c),t(s,L,c),b(ll,s,c),t(s,Nl,c),t(s,X,c),t(s,Fl,c),b(Y,s,c),t(s,Dl,c),t(s,H,c),t(s,zl,c),b(V,s,c),t(s,ql,c),t(s,N,c),t(s,pl,c),b(sl,s,c),t(s,Pl,c),t(s,F,c),t(s,ol,c),b(Tl,s,c),t(s,Ml,c),t(s,z,c),t(s,jl,c),t(s,il,c),t(s,Kl,c),b(S,s,c),t(s,bl,c),t(s,dl,c),t(s,Ul,c),b(rl,s,c),t(s,r,c),t(s,$,c),t(s,ce,c),t(s,Ol,c),t(s,vs,c),b(fl,s,c),t(s,Vs,c),t(s,hl,c),t(s,Rs,c),b(Il,s,c),t(s,Xs,c),t(s,Cl,c),t(s,ls,c),b(ks,s,c),t(s,Ys,c),t(s,$l,c),t(s,ss,c),b(es,s,c),t(s,ts,c),t(s,_s,c),t(s,ns,c),b(gs,s,c),t(s,Qs,c),t(s,kl,c),t(s,Es,c),b(_l,s,c),t(s,Hs,c),b(gl,s,c),t(s,Ns,c),t(s,xl,c),t(s,Fs,c),b(Zl,s,c),t(s,zs,c),t(s,Bl,c),t(s,Ss,c),b(Jl,s,c),t(s,Ls,c),b(Wl,s,c),t(s,Ds,c),t(s,Gl,c),t(s,as,c),b(xs,s,c),t(s,qs,c),t(s,Al,c),t(s,Ps,c),b(vl,s,c),t(s,Ks,c),b(Vl,s,c),t(s,Te,c),t(s,ps,c),t(s,Os,c),b(Rl,s,c),t(s,le,c),t(s,Xl,c),t(s,se,c),t(s,Yl,c),t(s,Ms,c),t(s,is,c),t(s,je,c),b(rs,s,c),t(s,cs,c),t(s,Js,c),t(s,ee,c),b(Ql,s,c),t(s,be,c),t(s,ys,c),t(s,te,c),t(s,El,c),ne=!0},i(s){ne||(J(M.$$.fragment,s),J(u.$$.fragment,s),J(_.$$.fragment,s),J(Q.$$.fragment,s),J(K.$$.fragment,s),J(A.$$.fragment,s),J(E.$$.fragment,s),J(ll.$$.fragment,s),J(Y.$$.fragment,s),J(V.$$.fragment,s),J(sl.$$.fragment,s),J(Tl.$$.fragment,s),J(S.$$.fragment,s),J(rl.$$.fragment,s),J(fl.$$.fragment,s),J(Il.$$.fragment,s),J(ks.$$.fragment,s),J(es.$$.fragment,s),J(gs.$$.fragment,s),J(_l.$$.fragment,s),J(gl.$$.fragment,s),J(Zl.$$.fragment,s),J(Jl.$$.fragment,s),J(Wl.$$.fragment,s),J(xs.$$.fragment,s),J(vl.$$.fragment,s),J(Vl.$$.fragment,s),J(Rl.$$.fragment,s),J(rs.$$.fragment,s),J(Ql.$$.fragment,s),ne=!0)},o(s){y(M.$$.fragment,s),y(u.$$.fragment,s),y(_.$$.fragment,s),y(Q.$$.fragment,s),y(K.$$.fragment,s),y(A.$$.fragment,s),y(E.$$.fragment,s),y(ll.$$.fragment,s),y(Y.$$.fragment,s),y(V.$$.fragment,s),y(sl.$$.fragment,s),y(Tl.$$.fragment,s),y(S.$$.fragment,s),y(rl.$$.fragment,s),y(fl.$$.fragment,s),y(Il.$$.fragment,s),y(ks.$$.fragment,s),y(es.$$.fragment,s),y(gs.$$.fragment,s),y(_l.$$.fragment,s),y(gl.$$.fragment,s),y(Zl.$$.fragment,s),y(Jl.$$.fragment,s),y(Wl.$$.fragment,s),y(xs.$$.fragment,s),y(vl.$$.fragment,s),y(Vl.$$.fragment,s),y(Rl.$$.fragment,s),y(rs.$$.fragment,s),y(Ql.$$.fragment,s),ne=!1},d(s){s&&(e(U),e(i),e(x),e(h),e(W),e(Z),e(B),e(G),e(v),e(P),e(nl),e(al),e(Hl),e(Ll),e(R),e(O),e(L),e(Nl),e(X),e(Fl),e(Dl),e(H),e(zl),e(ql),e(N),e(pl),e(Pl),e(F),e(ol),e(Ml),e(z),e(jl),e(il),e(Kl),e(bl),e(dl),e(Ul),e(r),e($),e(ce),e(Ol),e(vs),e(Vs),e(hl),e(Rs),e(Xs),e(Cl),e(ls),e(Ys),e($l),e(ss),e(ts),e(_s),e(ns),e(Qs),e(kl),e(Es),e(Hs),e(Ns),e(xl),e(Fs),e(zs),e(Bl),e(Ss),e(Ls),e(Ds),e(Gl),e(as),e(qs),e(Al),e(Ps),e(Ks),e(Te),e(ps),e(Os),e(le),e(Xl),e(se),e(Yl),e(Ms),e(is),e(je),e(cs),e(Js),e(ee),e(be),e(ys),e(te),e(El)),d(M,s),d(u,s),d(_,s),d(Q,s),d(K,s),d(A,s),d(E,s),d(ll,s),d(Y,s),d(V,s),d(sl,s),d(Tl,s),d(S,s),d(rl,s),d(fl,s),d(Il,s),d(ks,s),d(es,s),d(gs,s),d(_l,s),d(gl,s),d(Zl,s),d(Jl,s),d(Wl,s),d(xs,s),d(vl,s),d(Vl,s),d(Rl,s),d(rs,s),d(Ql,s)}}}function ya(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}),T(M)!=="svelte-odtfri"&&(M.textContent=U)},m(i,f){t(i,M,f)},p:As,d(i){i&&e(M)}}}function ma(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}),T(M)!=="svelte-vnmd58"&&(M.innerHTML=U)},m(i,f){t(i,M,f)},p:As,d(i){i&&e(M)}}}function oa(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}),T(M)!=="svelte-1ktdga8"&&(M.innerHTML=U)},m(i,f){t(i,M,f)},p:As,d(i){i&&e(M)}}}function Ta(g){let M,U,i,f,x,h,k,W,u,Z,B,C,G="我們將探索的第一個應用是Token分類。這個通用任務包括任何可以表述為“為句子中的詞或字分配標籤”的問題，例如：",_,v,P="<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>",hs,nl,Q,al,K="當然，還有很多其他類型的token分類問題；這些只是幾個有代表性的例子。在本節中，我們將在 NER 任務上微調模型 (BERT)，然後該模型將能夠計算如下預測：",Hl,A,Ll,E,R,O,Is,L,ll='<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."/>',Nl,X,ae='您可以<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的模型，可以嘗試輸入一些句子看看模型的預測結果。',Fl,Y,Dl,H,Sl='首先，我們需要一個適合標記分類的數據集。在本節中，我們將使用<a href="https://huggingface.co/datasets/conll2003" rel="nofollow">CoNLL-2003 數據集</a>, 其中包含來自路透社的新聞報道。',zl,V,ql,N,yl,pl,sl="要加載 CoNLL-2003 數據集，我們使用 來自 🤗 Datasets 庫的<strong>load_dataset()</strong> 方法：",Pl,F,ml,ol,Tl='這將下載並緩存數據集，就像和我們在<a href="/course/chapter3">第三章</a> 加載GLUE MRPC 數據集一樣。檢查這個對象可以讓我們看到存在哪些列，以及訓練集、驗證集和測試集之間是如何分割的:',Ml,z,wl,jl,il,el,Kl="特別是，我們可以看到數據集包含我們之前提到的三個任務的標籤：NER、POS 和chunking。與其他數據集的一個很大區別是輸入文本不是作為句子或文檔呈現的，而是單詞列表（最後一列稱為 <strong>tokens</strong> ，但它包含的是這些詞是預先標記化的輸入，仍然需要通過標記器進行子詞標記）。",S,bl,dl="我們來看看訓練集的第一個元素：",ul,Ul,rl,r,$,Cs,ce="由於我們要執行命名實體識別，我們將查看 NER 標籤：",Ol,$s,vs,fl,Vs,hl,ct="這一列是類標籤的序列。元素的類型在ner_feature的feature屬性中，我們可以通過查看該特性的names屬性來訪問名稱列表:",Rs,Il,Xs,Cl,Je,ls,ks="因此，這一列包含的元素是ClassLabels的序列。序列元素的類型在<code>ner_feature</code>的<code>feature</code>中，我們可以通過查看該<code>feature</code>的<code>names</code>屬性來訪問名稱列表:",Ys,$l,ye,ss,es,ts,_s='我們在<a href="/course/chapter6/3">第六章</a>, 深入研究<strong>token-classification</strong> 管道時已經看到了這些標籤 ，但為了快速複習：',me,ns,gs="<li><code>O</code> 表示這個詞不對應任何實體。</li> <li><code>B-PER</code>/<code>I-PER</code>意味著這個詞對應於人名實體的開頭/內部。</li> <li><code>B-ORG</code>/<code>I-ORG</code> 的意思是這個詞對應於組織名稱實體的開頭/內部。</li> <li><code>B-LOC</code>/<code>I-LOC</code> 指的是是這個詞對應於地名實體的開頭/內部。</li> <li><code>B-MISC</code>/<code>I-MISC</code> 表示該詞對應於一個雜項實體的開頭/內部。</li>",Qs,kl,Jt="現在解碼我們之前看到的標籤：",Es,_l,Hs,gl,Ns,xl,yt="例如混合 <strong>B-</strong> 和 <strong>I-</strong> 標籤，這是相同的代碼在索引 4 的訓練集元素上的預測結果：",Fs,Zl,zs,Bl,mt="正如我們所看到的，跨越兩個單詞的實體，如“European Union”和“Werner Zwingmann”，模型為第一個單詞標註了一個B-標籤，為第二個單詞標註了一個I-標籤。",Ss,Jl,Ls,Wl,Ds,Gl,oe,as,xs='像往常一樣，我們的文本需要轉換為Token ID，然後模型才能理解它們。正如我們在<a href="/course/chapter6/">第六章</a>所學的那樣。不過在標記任務中，一個很大的區別是我們有pre-tokenized的輸入。幸運的是，tokenizer API可以很容易地處理這個問題;我們只需要用一個特殊的tokenizer。',qs,Al,ot="首先，讓我們創建<code>tokenizer</code>對象。如前所述，我們將使用 BERT 預訓練模型，因此我們將從下載並緩存關聯的分詞器開始：",Ps,vl,Ks,Vl,Te='你可以更換把 <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 支持：',ps,Zs,Os,Rl,le,Xl,Tt="要對預先標記的輸入進行標記，我們可以像往常一樣使用我們的<code>tokenizer</code> 只需添加 <code>is_split_into_words=True</code>:",se,Yl,we,Ms,is,Bs,je=`正如我們所見，分詞器添加了模型使用的特殊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>):`,rs,cs,Js,Ws,ee,Ql,be="通過一點點工作，我們可以擴展我們的標籤列表以匹配token 。我們將應用的第一條規則是，特殊token 的標籤為 <code>-100</code> 。這是因為默認情況下 <code>-100</code> 是一個在我們將使用的損失函數（交叉熵）中被忽略的索引。然後，每個token 都會獲得與其所在單詞的token 相同的標籤，因為它們是同一實體的一部分。對於單詞內部但不在開頭的Token，我們將<code>B-</code> 替換為 <code>I-</code> (因為token 不以實體開頭):",ys,Gs,te,El,wt="讓我們在我們的第一句話上試一試：",ne,s,c,de,bt,ue,an="正如我們所看到的，我們的函數為開頭和結尾的兩個特殊標記添加了  <code>-100</code> ，併為分成兩個標記的單詞添加了一個新的<code>0</code> 。",dt,pe,ut,Ue,pn="為了預處理我們的整個數據集，我們需要標記所有輸入並在所有標籤上應用 <code>align_labels_with_tokens()</code> 。為了利用我們的快速分詞器的速度優勢，最好同時對大量文本進行分詞，因此我們將編寫一個處理示例列表的函數並使用帶 <code>batched=True</code> 有選項的 <code>Dataset.map()</code>方法 .與我們之前的示例唯一不同的是當分詞器的輸入是文本列表（或者像例子中的單詞列表）時  <code>word_ids()</code> 函數需要獲取我們想要單詞的索引的ID，所以我們也添加它：",Ut,fe,ft,he,Mn="請注意，我們還沒有填充我們的輸入；我們稍後會在使用數據整理器創建batch時這樣做。",ht,Ie,rn="我們現在可以一次性將所有預處理應用於數據集的其他部分：",It,Ce,Ct,$e,cn='我們已經完成了最難的部分！現在數據已經被預處理了，實際的訓練看起來很像我們<a href="/course/chapter3">第三章</a>做的.',$t,ms,os,tt,ke,kt,_e,Jn='我們不能像<a href="/course/chapter3">第三章</a>那樣只使用一個 <code>DataCollatorWithPadding </code>因為這隻會填充輸入（輸入 ID、注意掩碼和標記類型 ID）。在這裡我們的標籤應該以與輸入完全相同的方式填充，以便它們保持長度相同，使用  <code>-100</code> ，這樣在損失計算中就可以忽略相應的預測。',_t,ge,yn='這一切都是由一個 <a href="https://huggingface.co/transformers/main_classes/data_collator.html#datacollatorfortokenclassification" rel="nofollow"><code>DataCollatorForTokenClassification</code></a>完成.它是一個帶有填充的數據整理器它需要  <code>tokenizer</code> 用於預處理輸入：',gt,Ts,ws,nt,xe,mn="為了在幾個樣本上測試這一點，我們可以在訓練集中的示例列表上調用它：",xt,Ze,Zt,Be,Bt,We,on="讓我們將其與數據集中第一個和第二個元素的標籤進行比較：",Wt,Ge,Gt,Ae,At,js,bs,at,pt,ve,vt,ds,us,Mt,Ve,Vt,Re,Tn="這個評估方式與標準精度不同:它實際上將標籤列表作為字符串，而不是整數，因此在將預測和標籤傳遞給它之前，我們需要完全解碼它們。讓我們看看它是如何工作的。首先，我們將獲得第一個訓練示例的標籤:",Rt,Xe,Xt,Ye,Yt,Qe,wn="然後我們可以通過更改索引 2 處的值來為那些創建假的預測：",Qt,Ee,Et,He,jn="請注意，該指標的輸入是預測列表（不僅僅是一個）和標籤列表。這是輸出：",Ht,Ne,Nt,Us,fs,it,rt,Fe,Ft,ze,bn="我們已經向您展示瞭如何使用我們在模型中心微調的模型和推理小部件。在本地使用它 <code>pipeline</code> ，您只需要指定正確的模型標識符：",zt,Se,St,Le,Lt,De,dn="太棒了！我們的模型與此管道的默認模型一樣有效！",Dt,qe,qt,jt,Pt;x=new Sn({props:{fw:g[0]}}),k=new cl({props:{title:"Token 分類",local:"token-分類",headingTag:"h1"}});const un=[qn,Dn],Pe=[];function Un(l,n){return l[0]==="pt"?0:1}u=Un(g),Z=Pe[u]=un[u](g),nl=new Vn({props:{id:"wVHdVlPScxA"}}),Y=new cl({props:{title:"準備數據",local:"準備數據",headingTag:"h2"}}),V=new re({props:{$$slots:{default:[Pn]},$$scope:{ctx:g}}}),N=new cl({props:{title:"CoNLL-2003 數據集",local:"conll-2003-數據集",headingTag:"h3"}}),F=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}}),z=new I({props:{code:"cmF3X2RhdGFzZXRz",highlighted:"raw_datasets",wrap:!1}}),jl=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}}),Ul=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}}),r=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}}),$s=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}}),fl=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}}),Il=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}}),Cl=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}}),$l=new I({props:{code:"bGFiZWxfbmFtZXMlMjAlM0QlMjBuZXJfZmVhdHVyZS5mZWF0dXJlLm5hbWVzJTBBbGFiZWxfbmFtZXM=",highlighted:`label_names = ner_feature.feature.names
label_names`,wrap:!1}}),ss=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}}),Zl=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}}),Jl=new re({props:{$$slots:{default:[Kn]},$$scope:{ctx:g}}}),Wl=new cl({props:{title:"處理數據",local:"處理數據",headingTag:"h3"}}),Gl=new Vn({props:{id:"iY2AZYdZAr0"}}),vl=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}}),Zs=new I({props:{code:"dG9rZW5pemVyLmlzX2Zhc3Q=",highlighted:"tokenizer.is_fast",wrap:!1}}),Rl=new I({props:{code:"VHJ1ZQ==",highlighted:'<span class="hljs-literal">True</span>',wrap:!1}}),Yl=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}}),Ms=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}}),cs=new I({props:{code:"aW5wdXRzLndvcmRfaWRzKCk=",highlighted:"inputs.word_ids()",wrap:!1}}),Ws=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}}),Gs=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}}),s=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}}),de=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:[On]},$$scope:{ctx:g}}}),fe=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}}),Ce=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 fn=[sa,la],Ke=[];function hn(l,n){return l[0]==="pt"?0:1}ms=hn(g),os=Ke[ms]=fn[ms](g),ke=new cl({props:{title:"數據排序",local:"數據排序",headingTag:"h3"}});const In=[ta,ea],Oe=[];function Cn(l,n){return l[0]==="pt"?0:1}Ts=Cn(g),ws=Oe[Ts]=In[Ts](g),Ze=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}}),Be=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}}),Ge=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}}),Ae=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=[aa,na],lt=[];function kn(l,n){return l[0]==="pt"?0:1}js=kn(g),bs=lt[js]=$n[js](g);let D=g[0]==="tf"&&Rn(g);ve=new cl({props:{title:"評估指標",local:"評估指標",headingTag:"h3"}});const _n=[ra,ia],st=[];function gn(l,n){return l[0]==="pt"?0:1}ds=gn(g),us=st[ds]=_n[ds](g),Ve=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}}),Xe=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}}),Ye=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}}),Ee=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}}),Ne=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 xn=[Ja,ca],et=[];function Zn(l,n){return l[0]==="pt"?0:1}Us=Zn(g),fs=et[Us]=xn[Us](g);let q=g[0]==="pt"&&Xn(g);return Fe=new cl({props:{title:"使用微調模型",local:"使用微調模型",headingTag:"h2"}}),Se=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}}),Le=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}}),qe=new Ln({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(),w(x.$$.fragment),h=a(),w(k.$$.fragment),W=a(),Z.c(),B=a(),C=m("p"),C.textContent=G,_=a(),v=m("ul"),v.innerHTML=P,hs=a(),w(nl.$$.fragment),Q=a(),al=m("p"),al.textContent=K,Hl=a(),A=m("iframe"),E=a(),R=m("iframe"),Is=a(),L=m("a"),L.innerHTML=ll,Nl=a(),X=m("p"),X.innerHTML=ae,Fl=a(),w(Y.$$.fragment),Dl=a(),H=m("p"),H.innerHTML=Sl,zl=a(),w(V.$$.fragment),ql=a(),w(N.$$.fragment),yl=a(),pl=m("p"),pl.innerHTML=sl,Pl=a(),w(F.$$.fragment),ml=a(),ol=m("p"),ol.innerHTML=Tl,Ml=a(),w(z.$$.fragment),wl=a(),w(jl.$$.fragment),il=a(),el=m("p"),el.innerHTML=Kl,S=a(),bl=m("p"),bl.textContent=dl,ul=a(),w(Ul.$$.fragment),rl=a(),w(r.$$.fragment),$=a(),Cs=m("p"),Cs.textContent=ce,Ol=a(),w($s.$$.fragment),vs=a(),w(fl.$$.fragment),Vs=a(),hl=m("p"),hl.textContent=ct,Rs=a(),w(Il.$$.fragment),Xs=a(),w(Cl.$$.fragment),Je=a(),ls=m("p"),ls.innerHTML=ks,Ys=a(),w($l.$$.fragment),ye=a(),w(ss.$$.fragment),es=a(),ts=m("p"),ts.innerHTML=_s,me=a(),ns=m("ul"),ns.innerHTML=gs,Qs=a(),kl=m("p"),kl.textContent=Jt,Es=a(),w(_l.$$.fragment),Hs=a(),w(gl.$$.fragment),Ns=a(),xl=m("p"),xl.innerHTML=yt,Fs=a(),w(Zl.$$.fragment),zs=a(),Bl=m("p"),Bl.textContent=mt,Ss=a(),w(Jl.$$.fragment),Ls=a(),w(Wl.$$.fragment),Ds=a(),w(Gl.$$.fragment),oe=a(),as=m("p"),as.innerHTML=xs,qs=a(),Al=m("p"),Al.innerHTML=ot,Ps=a(),w(vl.$$.fragment),Ks=a(),Vl=m("p"),Vl.innerHTML=Te,ps=a(),w(Zs.$$.fragment),Os=a(),w(Rl.$$.fragment),le=a(),Xl=m("p"),Xl.innerHTML=Tt,se=a(),w(Yl.$$.fragment),we=a(),w(Ms.$$.fragment),is=a(),Bs=m("p"),Bs.innerHTML=je,rs=a(),w(cs.$$.fragment),Js=a(),w(Ws.$$.fragment),ee=a(),Ql=m("p"),Ql.innerHTML=be,ys=a(),w(Gs.$$.fragment),te=a(),El=m("p"),El.textContent=wt,ne=a(),w(s.$$.fragment),c=a(),w(de.$$.fragment),bt=a(),ue=m("p"),ue.innerHTML=an,dt=a(),w(pe.$$.fragment),ut=a(),Ue=m("p"),Ue.innerHTML=pn,Ut=a(),w(fe.$$.fragment),ft=a(),he=m("p"),he.textContent=Mn,ht=a(),Ie=m("p"),Ie.textContent=rn,It=a(),w(Ce.$$.fragment),Ct=a(),$e=m("p"),$e.innerHTML=cn,$t=a(),os.c(),tt=a(),w(ke.$$.fragment),kt=a(),_e=m("p"),_e.innerHTML=Jn,_t=a(),ge=m("p"),ge.innerHTML=yn,gt=a(),ws.c(),nt=a(),xe=m("p"),xe.textContent=mn,xt=a(),w(Ze.$$.fragment),Zt=a(),w(Be.$$.fragment),Bt=a(),We=m("p"),We.textContent=on,Wt=a(),w(Ge.$$.fragment),Gt=a(),w(Ae.$$.fragment),At=a(),bs.c(),at=a(),D&&D.c(),pt=a(),w(ve.$$.fragment),vt=a(),us.c(),Mt=a(),w(Ve.$$.fragment),Vt=a(),Re=m("p"),Re.textContent=Tn,Rt=a(),w(Xe.$$.fragment),Xt=a(),w(Ye.$$.fragment),Yt=a(),Qe=m("p"),Qe.textContent=wn,Qt=a(),w(Ee.$$.fragment),Et=a(),He=m("p"),He.textContent=jn,Ht=a(),w(Ne.$$.fragment),Nt=a(),fs.c(),it=a(),q&&q.c(),rt=a(),w(Fe.$$.fragment),Ft=a(),ze=m("p"),ze.innerHTML=bn,zt=a(),w(Se.$$.fragment),St=a(),w(Le.$$.fragment),Lt=a(),De=m("p"),De.textContent=dn,Dt=a(),w(qe.$$.fragment),qt=a(),jt=m("p"),this.h()},l(l){const n=Fn("svelte-u9bgzb",document.head);M=o(n,"META",{name:!0,content:!0}),n.forEach(e),U=p(l),i=o(l,"P",{}),Kt(i).forEach(e),f=p(l),j(x.$$.fragment,l),h=p(l),j(k.$$.fragment,l),W=p(l),Z.l(l),B=p(l),C=o(l,"P",{"data-svelte-h":!0}),T(C)!=="svelte-fj4lzc"&&(C.textContent=G),_=p(l),v=o(l,"UL",{"data-svelte-h":!0}),T(v)!=="svelte-3dd52o"&&(v.innerHTML=P),hs=p(l),j(nl.$$.fragment,l),Q=p(l),al=o(l,"P",{"data-svelte-h":!0}),T(al)!=="svelte-bw2qoz"&&(al.textContent=K),Hl=p(l),A=o(l,"IFRAME",{src:!0,frameborder:!0,height:!0,title:!0,class:!0,allow:!0,sandbox:!0}),Kt(A).forEach(e),E=p(l),R=o(l,"IFRAME",{src:!0,frameborder:!0,height:!0,title:!0,class:!0,allow:!0,sandbox:!0}),Kt(R).forEach(e),Is=p(l),L=o(l,"A",{class:!0,href:!0,"data-svelte-h":!0}),T(L)!=="svelte-1n7oe9l"&&(L.innerHTML=ll),Nl=p(l),X=o(l,"P",{"data-svelte-h":!0}),T(X)!=="svelte-1nhfol8"&&(X.innerHTML=ae),Fl=p(l),j(Y.$$.fragment,l),Dl=p(l),H=o(l,"P",{"data-svelte-h":!0}),T(H)!=="svelte-1wlxkvc"&&(H.innerHTML=Sl),zl=p(l),j(V.$$.fragment,l),ql=p(l),j(N.$$.fragment,l),yl=p(l),pl=o(l,"P",{"data-svelte-h":!0}),T(pl)!=="svelte-1rs5g05"&&(pl.innerHTML=sl),Pl=p(l),j(F.$$.fragment,l),ml=p(l),ol=o(l,"P",{"data-svelte-h":!0}),T(ol)!=="svelte-bc5n37"&&(ol.innerHTML=Tl),Ml=p(l),j(z.$$.fragment,l),wl=p(l),j(jl.$$.fragment,l),il=p(l),el=o(l,"P",{"data-svelte-h":!0}),T(el)!=="svelte-rfb2mc"&&(el.innerHTML=Kl),S=p(l),bl=o(l,"P",{"data-svelte-h":!0}),T(bl)!=="svelte-1ppbae7"&&(bl.textContent=dl),ul=p(l),j(Ul.$$.fragment,l),rl=p(l),j(r.$$.fragment,l),$=p(l),Cs=o(l,"P",{"data-svelte-h":!0}),T(Cs)!=="svelte-1oau2a1"&&(Cs.textContent=ce),Ol=p(l),j($s.$$.fragment,l),vs=p(l),j(fl.$$.fragment,l),Vs=p(l),hl=o(l,"P",{"data-svelte-h":!0}),T(hl)!=="svelte-1d6x9nt"&&(hl.textContent=ct),Rs=p(l),j(Il.$$.fragment,l),Xs=p(l),j(Cl.$$.fragment,l),Je=p(l),ls=o(l,"P",{"data-svelte-h":!0}),T(ls)!=="svelte-2d6jzb"&&(ls.innerHTML=ks),Ys=p(l),j($l.$$.fragment,l),ye=p(l),j(ss.$$.fragment,l),es=p(l),ts=o(l,"P",{"data-svelte-h":!0}),T(ts)!=="svelte-otkzcd"&&(ts.innerHTML=_s),me=p(l),ns=o(l,"UL",{"data-svelte-h":!0}),T(ns)!=="svelte-f551vb"&&(ns.innerHTML=gs),Qs=p(l),kl=o(l,"P",{"data-svelte-h":!0}),T(kl)!=="svelte-v74fd7"&&(kl.textContent=Jt),Es=p(l),j(_l.$$.fragment,l),Hs=p(l),j(gl.$$.fragment,l),Ns=p(l),xl=o(l,"P",{"data-svelte-h":!0}),T(xl)!=="svelte-1d7eu4w"&&(xl.innerHTML=yt),Fs=p(l),j(Zl.$$.fragment,l),zs=p(l),Bl=o(l,"P",{"data-svelte-h":!0}),T(Bl)!=="svelte-1040q5t"&&(Bl.textContent=mt),Ss=p(l),j(Jl.$$.fragment,l),Ls=p(l),j(Wl.$$.fragment,l),Ds=p(l),j(Gl.$$.fragment,l),oe=p(l),as=o(l,"P",{"data-svelte-h":!0}),T(as)!=="svelte-dizw0r"&&(as.innerHTML=xs),qs=p(l),Al=o(l,"P",{"data-svelte-h":!0}),T(Al)!=="svelte-ieeu5a"&&(Al.innerHTML=ot),Ps=p(l),j(vl.$$.fragment,l),Ks=p(l),Vl=o(l,"P",{"data-svelte-h":!0}),T(Vl)!=="svelte-qhmbt6"&&(Vl.innerHTML=Te),ps=p(l),j(Zs.$$.fragment,l),Os=p(l),j(Rl.$$.fragment,l),le=p(l),Xl=o(l,"P",{"data-svelte-h":!0}),T(Xl)!=="svelte-aswiqt"&&(Xl.innerHTML=Tt),se=p(l),j(Yl.$$.fragment,l),we=p(l),j(Ms.$$.fragment,l),is=p(l),Bs=o(l,"P",{"data-svelte-h":!0}),T(Bs)!=="svelte-1ui81xt"&&(Bs.innerHTML=je),rs=p(l),j(cs.$$.fragment,l),Js=p(l),j(Ws.$$.fragment,l),ee=p(l),Ql=o(l,"P",{"data-svelte-h":!0}),T(Ql)!=="svelte-xyrlko"&&(Ql.innerHTML=be),ys=p(l),j(Gs.$$.fragment,l),te=p(l),El=o(l,"P",{"data-svelte-h":!0}),T(El)!=="svelte-1jpbfuf"&&(El.textContent=wt),ne=p(l),j(s.$$.fragment,l),c=p(l),j(de.$$.fragment,l),bt=p(l),ue=o(l,"P",{"data-svelte-h":!0}),T(ue)!=="svelte-v66ec8"&&(ue.innerHTML=an),dt=p(l),j(pe.$$.fragment,l),ut=p(l),Ue=o(l,"P",{"data-svelte-h":!0}),T(Ue)!=="svelte-sese4w"&&(Ue.innerHTML=pn),Ut=p(l),j(fe.$$.fragment,l),ft=p(l),he=o(l,"P",{"data-svelte-h":!0}),T(he)!=="svelte-1fdwu6p"&&(he.textContent=Mn),ht=p(l),Ie=o(l,"P",{"data-svelte-h":!0}),T(Ie)!=="svelte-1n3be24"&&(Ie.textContent=rn),It=p(l),j(Ce.$$.fragment,l),Ct=p(l),$e=o(l,"P",{"data-svelte-h":!0}),T($e)!=="svelte-hmnzd6"&&($e.innerHTML=cn),$t=p(l),os.l(l),tt=p(l),j(ke.$$.fragment,l),kt=p(l),_e=o(l,"P",{"data-svelte-h":!0}),T(_e)!=="svelte-8rm9gx"&&(_e.innerHTML=Jn),_t=p(l),ge=o(l,"P",{"data-svelte-h":!0}),T(ge)!=="svelte-1jnbgsb"&&(ge.innerHTML=yn),gt=p(l),ws.l(l),nt=p(l),xe=o(l,"P",{"data-svelte-h":!0}),T(xe)!=="svelte-eihhyp"&&(xe.textContent=mn),xt=p(l),j(Ze.$$.fragment,l),Zt=p(l),j(Be.$$.fragment,l),Bt=p(l),We=o(l,"P",{"data-svelte-h":!0}),T(We)!=="svelte-qeezpf"&&(We.textContent=on),Wt=p(l),j(Ge.$$.fragment,l),Gt=p(l),j(Ae.$$.fragment,l),At=p(l),bs.l(l),at=p(l),D&&D.l(l),pt=p(l),j(ve.$$.fragment,l),vt=p(l),us.l(l),Mt=p(l),j(Ve.$$.fragment,l),Vt=p(l),Re=o(l,"P",{"data-svelte-h":!0}),T(Re)!=="svelte-uy7xi3"&&(Re.textContent=Tn),Rt=p(l),j(Xe.$$.fragment,l),Xt=p(l),j(Ye.$$.fragment,l),Yt=p(l),Qe=o(l,"P",{"data-svelte-h":!0}),T(Qe)!=="svelte-6cg1dt"&&(Qe.textContent=wn),Qt=p(l),j(Ee.$$.fragment,l),Et=p(l),He=o(l,"P",{"data-svelte-h":!0}),T(He)!=="svelte-1u36har"&&(He.textContent=jn),Ht=p(l),j(Ne.$$.fragment,l),Nt=p(l),fs.l(l),it=p(l),q&&q.l(l),rt=p(l),j(Fe.$$.fragment,l),Ft=p(l),ze=o(l,"P",{"data-svelte-h":!0}),T(ze)!=="svelte-11d45sb"&&(ze.innerHTML=bn),zt=p(l),j(Se.$$.fragment,l),St=p(l),j(Le.$$.fragment,l),Lt=p(l),De=o(l,"P",{"data-svelte-h":!0}),T(De)!=="svelte-nm02mc"&&(De.textContent=dn),Dt=p(l),j(qe.$$.fragment,l),qt=p(l),jt=o(l,"P",{}),Kt(jt).forEach(e),this.h()},h(){tl(M,"name","hf:doc:metadata"),tl(M,"content",wa),vn(A.src,Ll="https://course-demos-bert-finetuned-ner.hf.space")||tl(A,"src",Ll),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"),vn(R.src,O="https://course-demos-bert-finetuned-ner-darkmode.hf.space")||tl(R,"src",O),tl(R,"frameborder","0"),tl(R,"height","350"),tl(R,"title","Gradio app"),tl(R,"class","hidden dark:block container p-0 flex-grow space-iframe"),tl(R,"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(R,"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){zn(document.head,M),t(l,U,n),t(l,i,n),t(l,f,n),b(x,l,n),t(l,h,n),b(k,l,n),t(l,W,n),Pe[u].m(l,n),t(l,B,n),t(l,C,n),t(l,_,n),t(l,v,n),t(l,hs,n),b(nl,l,n),t(l,Q,n),t(l,al,n),t(l,Hl,n),t(l,A,n),t(l,E,n),t(l,R,n),t(l,Is,n),t(l,L,n),t(l,Nl,n),t(l,X,n),t(l,Fl,n),b(Y,l,n),t(l,Dl,n),t(l,H,n),t(l,zl,n),b(V,l,n),t(l,ql,n),b(N,l,n),t(l,yl,n),t(l,pl,n),t(l,Pl,n),b(F,l,n),t(l,ml,n),t(l,ol,n),t(l,Ml,n),b(z,l,n),t(l,wl,n),b(jl,l,n),t(l,il,n),t(l,el,n),t(l,S,n),t(l,bl,n),t(l,ul,n),b(Ul,l,n),t(l,rl,n),b(r,l,n),t(l,$,n),t(l,Cs,n),t(l,Ol,n),b($s,l,n),t(l,vs,n),b(fl,l,n),t(l,Vs,n),t(l,hl,n),t(l,Rs,n),b(Il,l,n),t(l,Xs,n),b(Cl,l,n),t(l,Je,n),t(l,ls,n),t(l,Ys,n),b($l,l,n),t(l,ye,n),b(ss,l,n),t(l,es,n),t(l,ts,n),t(l,me,n),t(l,ns,n),t(l,Qs,n),t(l,kl,n),t(l,Es,n),b(_l,l,n),t(l,Hs,n),b(gl,l,n),t(l,Ns,n),t(l,xl,n),t(l,Fs,n),b(Zl,l,n),t(l,zs,n),t(l,Bl,n),t(l,Ss,n),b(Jl,l,n),t(l,Ls,n),b(Wl,l,n),t(l,Ds,n),b(Gl,l,n),t(l,oe,n),t(l,as,n),t(l,qs,n),t(l,Al,n),t(l,Ps,n),b(vl,l,n),t(l,Ks,n),t(l,Vl,n),t(l,ps,n),b(Zs,l,n),t(l,Os,n),b(Rl,l,n),t(l,le,n),t(l,Xl,n),t(l,se,n),b(Yl,l,n),t(l,we,n),b(Ms,l,n),t(l,is,n),t(l,Bs,n),t(l,rs,n),b(cs,l,n),t(l,Js,n),b(Ws,l,n),t(l,ee,n),t(l,Ql,n),t(l,ys,n),b(Gs,l,n),t(l,te,n),t(l,El,n),t(l,ne,n),b(s,l,n),t(l,c,n),b(de,l,n),t(l,bt,n),t(l,ue,n),t(l,dt,n),b(pe,l,n),t(l,ut,n),t(l,Ue,n),t(l,Ut,n),b(fe,l,n),t(l,ft,n),t(l,he,n),t(l,ht,n),t(l,Ie,n),t(l,It,n),b(Ce,l,n),t(l,Ct,n),t(l,$e,n),t(l,$t,n),Ke[ms].m(l,n),t(l,tt,n),b(ke,l,n),t(l,kt,n),t(l,_e,n),t(l,_t,n),t(l,ge,n),t(l,gt,n),Oe[Ts].m(l,n),t(l,nt,n),t(l,xe,n),t(l,xt,n),b(Ze,l,n),t(l,Zt,n),b(Be,l,n),t(l,Bt,n),t(l,We,n),t(l,Wt,n),b(Ge,l,n),t(l,Gt,n),b(Ae,l,n),t(l,At,n),lt[js].m(l,n),t(l,at,n),D&&D.m(l,n),t(l,pt,n),b(ve,l,n),t(l,vt,n),st[ds].m(l,n),t(l,Mt,n),b(Ve,l,n),t(l,Vt,n),t(l,Re,n),t(l,Rt,n),b(Xe,l,n),t(l,Xt,n),b(Ye,l,n),t(l,Yt,n),t(l,Qe,n),t(l,Qt,n),b(Ee,l,n),t(l,Et,n),t(l,He,n),t(l,Ht,n),b(Ne,l,n),t(l,Nt,n),et[Us].m(l,n),t(l,it,n),q&&q.m(l,n),t(l,rt,n),b(Fe,l,n),t(l,Ft,n),t(l,ze,n),t(l,zt,n),b(Se,l,n),t(l,St,n),b(Le,l,n),t(l,Lt,n),t(l,De,n),t(l,Dt,n),b(qe,l,n),t(l,qt,n),t(l,jt,n),Pt=!0},p(l,[n]){const Bn={};n&1&&(Bn.fw=l[0]),x.$set(Bn);let Ot=u;u=Un(l),u!==Ot&&(ie(),y(Pe[Ot],1,1,()=>{Pe[Ot]=null}),Me(),Z=Pe[u],Z||(Z=Pe[u]=un[u](l),Z.c()),J(Z,1),Z.m(B.parentNode,B));const Wn={};n&2&&(Wn.$$scope={dirty:n,ctx:l}),V.$set(Wn);const Gn={};n&2&&(Gn.$$scope={dirty:n,ctx:l}),Jl.$set(Gn);const An={};n&2&&(An.$$scope={dirty:n,ctx:l}),pe.$set(An);let ln=ms;ms=hn(l),ms!==ln&&(ie(),y(Ke[ln],1,1,()=>{Ke[ln]=null}),Me(),os=Ke[ms],os||(os=Ke[ms]=fn[ms](l),os.c()),J(os,1),os.m(tt.parentNode,tt));let sn=Ts;Ts=Cn(l),Ts!==sn&&(ie(),y(Oe[sn],1,1,()=>{Oe[sn]=null}),Me(),ws=Oe[Ts],ws||(ws=Oe[Ts]=In[Ts](l),ws.c()),J(ws,1),ws.m(nt.parentNode,nt));let en=js;js=kn(l),js!==en&&(ie(),y(lt[en],1,1,()=>{lt[en]=null}),Me(),bs=lt[js],bs||(bs=lt[js]=$n[js](l),bs.c()),J(bs,1),bs.m(at.parentNode,at)),l[0]==="tf"?D?n&1&&J(D,1):(D=Rn(l),D.c(),J(D,1),D.m(pt.parentNode,pt)):D&&(ie(),y(D,1,1,()=>{D=null}),Me());let tn=ds;ds=gn(l),ds!==tn&&(ie(),y(st[tn],1,1,()=>{st[tn]=null}),Me(),us=st[ds],us||(us=st[ds]=_n[ds](l),us.c()),J(us,1),us.m(Mt.parentNode,Mt));let nn=Us;Us=Zn(l),Us!==nn&&(ie(),y(et[nn],1,1,()=>{et[nn]=null}),Me(),fs=et[Us],fs||(fs=et[Us]=xn[Us](l),fs.c()),J(fs,1),fs.m(it.parentNode,it)),l[0]==="pt"?q?n&1&&J(q,1):(q=Xn(l),q.c(),J(q,1),q.m(rt.parentNode,rt)):q&&(ie(),y(q,1,1,()=>{q=null}),Me())},i(l){Pt||(J(x.$$.fragment,l),J(k.$$.fragment,l),J(Z),J(nl.$$.fragment,l),J(Y.$$.fragment,l),J(V.$$.fragment,l),J(N.$$.fragment,l),J(F.$$.fragment,l),J(z.$$.fragment,l),J(jl.$$.fragment,l),J(Ul.$$.fragment,l),J(r.$$.fragment,l),J($s.$$.fragment,l),J(fl.$$.fragment,l),J(Il.$$.fragment,l),J(Cl.$$.fragment,l),J($l.$$.fragment,l),J(ss.$$.fragment,l),J(_l.$$.fragment,l),J(gl.$$.fragment,l),J(Zl.$$.fragment,l),J(Jl.$$.fragment,l),J(Wl.$$.fragment,l),J(Gl.$$.fragment,l),J(vl.$$.fragment,l),J(Zs.$$.fragment,l),J(Rl.$$.fragment,l),J(Yl.$$.fragment,l),J(Ms.$$.fragment,l),J(cs.$$.fragment,l),J(Ws.$$.fragment,l),J(Gs.$$.fragment,l),J(s.$$.fragment,l),J(de.$$.fragment,l),J(pe.$$.fragment,l),J(fe.$$.fragment,l),J(Ce.$$.fragment,l),J(os),J(ke.$$.fragment,l),J(ws),J(Ze.$$.fragment,l),J(Be.$$.fragment,l),J(Ge.$$.fragment,l),J(Ae.$$.fragment,l),J(bs),J(D),J(ve.$$.fragment,l),J(us),J(Ve.$$.fragment,l),J(Xe.$$.fragment,l),J(Ye.$$.fragment,l),J(Ee.$$.fragment,l),J(Ne.$$.fragment,l),J(fs),J(q),J(Fe.$$.fragment,l),J(Se.$$.fragment,l),J(Le.$$.fragment,l),J(qe.$$.fragment,l),Pt=!0)},o(l){y(x.$$.fragment,l),y(k.$$.fragment,l),y(Z),y(nl.$$.fragment,l),y(Y.$$.fragment,l),y(V.$$.fragment,l),y(N.$$.fragment,l),y(F.$$.fragment,l),y(z.$$.fragment,l),y(jl.$$.fragment,l),y(Ul.$$.fragment,l),y(r.$$.fragment,l),y($s.$$.fragment,l),y(fl.$$.fragment,l),y(Il.$$.fragment,l),y(Cl.$$.fragment,l),y($l.$$.fragment,l),y(ss.$$.fragment,l),y(_l.$$.fragment,l),y(gl.$$.fragment,l),y(Zl.$$.fragment,l),y(Jl.$$.fragment,l),y(Wl.$$.fragment,l),y(Gl.$$.fragment,l),y(vl.$$.fragment,l),y(Zs.$$.fragment,l),y(Rl.$$.fragment,l),y(Yl.$$.fragment,l),y(Ms.$$.fragment,l),y(cs.$$.fragment,l),y(Ws.$$.fragment,l),y(Gs.$$.fragment,l),y(s.$$.fragment,l),y(de.$$.fragment,l),y(pe.$$.fragment,l),y(fe.$$.fragment,l),y(Ce.$$.fragment,l),y(os),y(ke.$$.fragment,l),y(ws),y(Ze.$$.fragment,l),y(Be.$$.fragment,l),y(Ge.$$.fragment,l),y(Ae.$$.fragment,l),y(bs),y(D),y(ve.$$.fragment,l),y(us),y(Ve.$$.fragment,l),y(Xe.$$.fragment,l),y(Ye.$$.fragment,l),y(Ee.$$.fragment,l),y(Ne.$$.fragment,l),y(fs),y(q),y(Fe.$$.fragment,l),y(Se.$$.fragment,l),y(Le.$$.fragment,l),y(qe.$$.fragment,l),Pt=!1},d(l){l&&(e(U),e(i),e(f),e(h),e(W),e(B),e(C),e(_),e(v),e(hs),e(Q),e(al),e(Hl),e(A),e(E),e(R),e(Is),e(L),e(Nl),e(X),e(Fl),e(Dl),e(H),e(zl),e(ql),e(yl),e(pl),e(Pl),e(ml),e(ol),e(Ml),e(wl),e(il),e(el),e(S),e(bl),e(ul),e(rl),e($),e(Cs),e(Ol),e(vs),e(Vs),e(hl),e(Rs),e(Xs),e(Je),e(ls),e(Ys),e(ye),e(es),e(ts),e(me),e(ns),e(Qs),e(kl),e(Es),e(Hs),e(Ns),e(xl),e(Fs),e(zs),e(Bl),e(Ss),e(Ls),e(Ds),e(oe),e(as),e(qs),e(Al),e(Ps),e(Ks),e(Vl),e(ps),e(Os),e(le),e(Xl),e(se),e(we),e(is),e(Bs),e(rs),e(Js),e(ee),e(Ql),e(ys),e(te),e(El),e(ne),e(c),e(bt),e(ue),e(dt),e(ut),e(Ue),e(Ut),e(ft),e(he),e(ht),e(Ie),e(It),e(Ct),e($e),e($t),e(tt),e(kt),e(_e),e(_t),e(ge),e(gt),e(nt),e(xe),e(xt),e(Zt),e(Bt),e(We),e(Wt),e(Gt),e(At),e(at),e(pt),e(vt),e(Mt),e(Vt),e(Re),e(Rt),e(Xt),e(Yt),e(Qe),e(Qt),e(Et),e(He),e(Ht),e(Nt),e(it),e(rt),e(Ft),e(ze),e(zt),e(St),e(Lt),e(De),e(Dt),e(qt),e(jt)),e(M),d(x,l),d(k,l),Pe[u].d(l),d(nl,l),d(Y,l),d(V,l),d(N,l),d(F,l),d(z,l),d(jl,l),d(Ul,l),d(r,l),d($s,l),d(fl,l),d(Il,l),d(Cl,l),d($l,l),d(ss,l),d(_l,l),d(gl,l),d(Zl,l),d(Jl,l),d(Wl,l),d(Gl,l),d(vl,l),d(Zs,l),d(Rl,l),d(Yl,l),d(Ms,l),d(cs,l),d(Ws,l),d(Gs,l),d(s,l),d(de,l),d(pe,l),d(fe,l),d(Ce,l),Ke[ms].d(l),d(ke,l),Oe[Ts].d(l),d(Ze,l),d(Be,l),d(Ge,l),d(Ae,l),lt[js].d(l),D&&D.d(l),d(ve,l),st[ds].d(l),d(Ve,l),d(Xe,l),d(Ye,l),d(Ee,l),d(Ne,l),et[Us].d(l),q&&q.d(l),d(Fe,l),d(Se,l),d(Le,l),d(qe,l)}}}const wa='{"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 ja(g,M,U){let i="pt";return En(()=>{const f=new URLSearchParams(window.location.search);U(0,i=f.get("fw")||"pt")}),[i]}class $a extends Hn{constructor(M){super(),Nn(this,M,ja,Ta,Qn,{})}}export{$a as component};
