import{s as $e,o as ke,n as _t}from"../chunks/scheduler.37c15a92.js";import{S as Ce,i as xe,g as y,s as r,r as J,A as Ie,h as j,f as n,c as M,j as de,u as U,x as m,k as we,y as Re,a,v as b,t as u,b as Ps,d as o,w as h,p as Ks}from"../chunks/index.2bf4358c.js";import{T as gt}from"../chunks/Tip.363c041f.js";import{Y as Ml}from"../chunks/Youtube.1e50a667.js";import{C as w}from"../chunks/CodeBlock.4e987730.js";import{C as _e}from"../chunks/CourseFloatingBanner.9ff4c771.js";import{F as Ze}from"../chunks/FrameworkSwitchCourse.8d4d4ab6.js";import{H as Ut,E as Ne}from"../chunks/getInferenceSnippets.39afd8fb.js";function Ae(f){let t,p;return t=new _e({props:{chapter:3,classNames:"absolute z-10 right-0 top-0",notebooks:[{label:"Google Colab",value:"https://colab.research.google.com/github/huggingface/notebooks/blob/master/course/zh-CN/chapter3/section2_tf.ipynb"},{label:"Aws Studio",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/master/course/zh-CN/chapter3/section2_tf.ipynb"}]}}),{c(){J(t.$$.fragment)},l(e){U(t.$$.fragment,e)},m(e,i){b(t,e,i),p=!0},i(e){p||(o(t.$$.fragment,e),p=!0)},o(e){u(t.$$.fragment,e),p=!1},d(e){h(t,e)}}}function Ge(f){let t,p;return t=new _e({props:{chapter:3,classNames:"absolute z-10 right-0 top-0",notebooks:[{label:"Google Colab",value:"https://colab.research.google.com/github/huggingface/notebooks/blob/master/course/zh-CN/chapter3/section2_pt.ipynb"},{label:"Aws Studio",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/master/course/zh-CN/chapter3/section2_pt.ipynb"}]}}),{c(){J(t.$$.fragment)},l(e){U(t.$$.fragment,e)},m(e,i){b(t,e,i),p=!0},i(e){p||(o(t.$$.fragment,e),p=!0)},o(e){u(t.$$.fragment,e),p=!1},d(e){h(t,e)}}}function Qe(f){let t,p='這一小節學習<a href="/course/chapter2">第一小節</a>中提到的「如何使用模型中心（hub）大型數據集」，下面是我們用模型中心的數據在 TensorFlow 上訓練句子分類器的一個例子：',e,i,d;return i=new w({props:{code:"aW1wb3J0JTIwdGVuc29yZmxvdyUyMGFzJTIwdGYlMEFpbXBvcnQlMjBudW1weSUyMGFzJTIwbnAlMEFmcm9tJTIwdHJhbnNmb3JtZXJzJTIwaW1wb3J0JTIwQXV0b1Rva2VuaXplciUyQyUyMFRGQXV0b01vZGVsRm9yU2VxdWVuY2VDbGFzc2lmaWNhdGlvbiUwQSUwQSUyMyUyMFNhbWUlMjBhcyUyMGJlZm9yZSUwQWNoZWNrcG9pbnQlMjAlM0QlMjAlMjJiZXJ0LWJhc2UtdW5jYXNlZCUyMiUwQXRva2VuaXplciUyMCUzRCUyMEF1dG9Ub2tlbml6ZXIuZnJvbV9wcmV0cmFpbmVkKGNoZWNrcG9pbnQpJTBBbW9kZWwlMjAlM0QlMjBURkF1dG9Nb2RlbEZvclNlcXVlbmNlQ2xhc3NpZmljYXRpb24uZnJvbV9wcmV0cmFpbmVkKGNoZWNrcG9pbnQpJTBBc2VxdWVuY2VzJTIwJTNEJTIwJTVCJTBBJTIwJTIwJTIwJTIwJTIySSd2ZSUyMGJlZW4lMjB3YWl0aW5nJTIwZm9yJTIwYSUyMEh1Z2dpbmdGYWNlJTIwY291cnNlJTIwbXklMjB3aG9sZSUyMGxpZmUuJTIyJTJDJTBBJTIwJTIwJTIwJTIwJTIyVGhpcyUyMGNvdXJzZSUyMGlzJTIwYW1hemluZyElMjIlMkMlMEElNUQlMEFiYXRjaCUyMCUzRCUyMGRpY3QodG9rZW5pemVyKHNlcXVlbmNlcyUyQyUyMHBhZGRpbmclM0RUcnVlJTJDJTIwdHJ1bmNhdGlvbiUzRFRydWUlMkMlMjByZXR1cm5fdGVuc29ycyUzRCUyMnRmJTIyKSklMEElMEElMjMlMjBUaGlzJTIwaXMlMjBuZXclMEFtb2RlbC5jb21waWxlKG9wdGltaXplciUzRCUyMmFkYW0lMjIlMkMlMjBsb3NzJTNEJTIyc3BhcnNlX2NhdGVnb3JpY2FsX2Nyb3NzZW50cm9weSUyMiklMEFsYWJlbHMlMjAlM0QlMjB0Zi5jb252ZXJ0X3RvX3RlbnNvciglNUIxJTJDJTIwMSU1RCklMEFtb2RlbC50cmFpbl9vbl9iYXRjaChiYXRjaCUyQyUyMGxhYmVscyk=",highlighted:`<span class="hljs-keyword">import</span> tensorflow <span class="hljs-keyword">as</span> tf
<span class="hljs-keyword">import</span> numpy <span class="hljs-keyword">as</span> np
<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoTokenizer, TFAutoModelForSequenceClassification

<span class="hljs-comment"># Same as before</span>
checkpoint = <span class="hljs-string">&quot;bert-base-uncased&quot;</span>
tokenizer = AutoTokenizer.from_pretrained(checkpoint)
model = TFAutoModelForSequenceClassification.from_pretrained(checkpoint)
sequences = [
    <span class="hljs-string">&quot;I&#x27;ve been waiting for a HuggingFace course my whole life.&quot;</span>,
    <span class="hljs-string">&quot;This course is amazing!&quot;</span>,
]
batch = <span class="hljs-built_in">dict</span>(tokenizer(sequences, padding=<span class="hljs-literal">True</span>, truncation=<span class="hljs-literal">True</span>, return_tensors=<span class="hljs-string">&quot;tf&quot;</span>))

<span class="hljs-comment"># This is new</span>
model.<span class="hljs-built_in">compile</span>(optimizer=<span class="hljs-string">&quot;adam&quot;</span>, loss=<span class="hljs-string">&quot;sparse_categorical_crossentropy&quot;</span>)
labels = tf.convert_to_tensor([<span class="hljs-number">1</span>, <span class="hljs-number">1</span>])
model.train_on_batch(batch, labels)`,wrap:!1}}),{c(){t=y("p"),t.innerHTML=p,e=r(),J(i.$$.fragment)},l(c){t=j(c,"P",{"data-svelte-h":!0}),m(t)!=="svelte-juaxyd"&&(t.innerHTML=p),e=M(c),U(i.$$.fragment,c)},m(c,g){a(c,t,g),a(c,e,g),b(i,c,g),d=!0},i(c){d||(o(i.$$.fragment,c),d=!0)},o(c){u(i.$$.fragment,c),d=!1},d(c){c&&(n(t),n(e)),h(i,c)}}}function Be(f){let t,p='這一小節學習<a href="/course/chapter2">第一小節</a>中提到的「如何使用模型中心（hub）大型數據集」，下面是我們用模型中心的數據在 PyTorch 上訓練句子分類器的一個例子：',e,i,d;return i=new w({props:{code:"aW1wb3J0JTIwdG9yY2glMEFmcm9tJTIwdG9yY2gub3B0aW0lMjBpbXBvcnQlMjBBZGFtVyUwQWZyb20lMjB0cmFuc2Zvcm1lcnMlMjBpbXBvcnQlMjBBdXRvVG9rZW5pemVyJTJDJTIwQXV0b01vZGVsRm9yU2VxdWVuY2VDbGFzc2lmaWNhdGlvbiUwQSUwQSUyMyUyMFNhbWUlMjBhcyUyMGJlZm9yZSUwQWNoZWNrcG9pbnQlMjAlM0QlMjAlMjJiZXJ0LWJhc2UtdW5jYXNlZCUyMiUwQXRva2VuaXplciUyMCUzRCUyMEF1dG9Ub2tlbml6ZXIuZnJvbV9wcmV0cmFpbmVkKGNoZWNrcG9pbnQpJTBBbW9kZWwlMjAlM0QlMjBBdXRvTW9kZWxGb3JTZXF1ZW5jZUNsYXNzaWZpY2F0aW9uLmZyb21fcHJldHJhaW5lZChjaGVja3BvaW50KSUwQXNlcXVlbmNlcyUyMCUzRCUyMCU1QiUwQSUyMCUyMCUyMCUyMCUyMkkndmUlMjBiZWVuJTIwd2FpdGluZyUyMGZvciUyMGElMjBIdWdnaW5nRmFjZSUyMGNvdXJzZSUyMG15JTIwd2hvbGUlMjBsaWZlLiUyMiUyQyUwQSUyMCUyMCUyMCUyMCUyMlRoaXMlMjBjb3Vyc2UlMjBpcyUyMGFtYXppbmchJTIyJTJDJTBBJTVEJTBBYmF0Y2glMjAlM0QlMjB0b2tlbml6ZXIoc2VxdWVuY2VzJTJDJTIwcGFkZGluZyUzRFRydWUlMkMlMjB0cnVuY2F0aW9uJTNEVHJ1ZSUyQyUyMHJldHVybl90ZW5zb3JzJTNEJTIycHQlMjIpJTBBJTBBJTIzJTIwVGhpcyUyMGlzJTIwbmV3JTBBYmF0Y2glNUIlMjJsYWJlbHMlMjIlNUQlMjAlM0QlMjB0b3JjaC50ZW5zb3IoJTVCMSUyQyUyMDElNUQpJTBBJTBBb3B0aW1pemVyJTIwJTNEJTIwQWRhbVcobW9kZWwucGFyYW1ldGVycygpKSUwQWxvc3MlMjAlM0QlMjBtb2RlbCgqKmJhdGNoKS5sb3NzJTBBbG9zcy5iYWNrd2FyZCgpJTBBb3B0aW1pemVyLnN0ZXAoKQ==",highlighted:`<span class="hljs-keyword">import</span> torch
<span class="hljs-keyword">from</span> torch.optim <span class="hljs-keyword">import</span> AdamW
<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoTokenizer, AutoModelForSequenceClassification

<span class="hljs-comment"># Same as before</span>
checkpoint = <span class="hljs-string">&quot;bert-base-uncased&quot;</span>
tokenizer = AutoTokenizer.from_pretrained(checkpoint)
model = AutoModelForSequenceClassification.from_pretrained(checkpoint)
sequences = [
    <span class="hljs-string">&quot;I&#x27;ve been waiting for a HuggingFace course my whole life.&quot;</span>,
    <span class="hljs-string">&quot;This course is amazing!&quot;</span>,
]
batch = tokenizer(sequences, padding=<span class="hljs-literal">True</span>, truncation=<span class="hljs-literal">True</span>, return_tensors=<span class="hljs-string">&quot;pt&quot;</span>)

<span class="hljs-comment"># This is new</span>
batch[<span class="hljs-string">&quot;labels&quot;</span>] = torch.tensor([<span class="hljs-number">1</span>, <span class="hljs-number">1</span>])

optimizer = AdamW(model.parameters())
loss = model(**batch).loss
loss.backward()
optimizer.step()`,wrap:!1}}),{c(){t=y("p"),t.innerHTML=p,e=r(),J(i.$$.fragment)},l(c){t=j(c,"P",{"data-svelte-h":!0}),m(t)!=="svelte-x1nemh"&&(t.innerHTML=p),e=M(c),U(i.$$.fragment,c)},m(c,g){a(c,t,g),a(c,e,g),b(i,c,g),d=!0},i(c){d||(o(i.$$.fragment,c),d=!0)},o(c){u(i.$$.fragment,c),d=!1},d(c){c&&(n(t),n(e)),h(i,c)}}}function ve(f){let t,p;return t=new Ml({props:{id:"W_gMJF0xomE"}}),{c(){J(t.$$.fragment)},l(e){U(t.$$.fragment,e)},m(e,i){b(t,e,i),p=!0},i(e){p||(o(t.$$.fragment,e),p=!0)},o(e){u(t.$$.fragment,e),p=!1},d(e){h(t,e)}}}function Xe(f){let t,p;return t=new Ml({props:{id:"_BZearw7f0w"}}),{c(){J(t.$$.fragment)},l(e){U(t.$$.fragment,e)},m(e,i){b(t,e,i),p=!0},i(e){p||(o(t.$$.fragment,e),p=!0)},o(e){u(t.$$.fragment,e),p=!1},d(e){h(t,e)}}}function Ve(f){let t,p="✏️ <strong>試試看！</strong> 查看訓練集的第15行元素和驗證集的87行元素。他們的標籤是什麼？";return{c(){t=y("p"),t.innerHTML=p},l(e){t=j(e,"P",{"data-svelte-h":!0}),m(t)!=="svelte-c2aioh"&&(t.innerHTML=p)},m(e,i){a(e,t,i)},p:_t,d(e){e&&n(t)}}}function We(f){let t,p;return t=new Ml({props:{id:"P-rZWqcB6CE"}}),{c(){J(t.$$.fragment)},l(e){U(t.$$.fragment,e)},m(e,i){b(t,e,i),p=!0},i(e){p||(o(t.$$.fragment,e),p=!0)},o(e){u(t.$$.fragment,e),p=!1},d(e){h(t,e)}}}function Ee(f){let t,p;return t=new Ml({props:{id:"0u3ioSwev3s"}}),{c(){J(t.$$.fragment)},l(e){U(t.$$.fragment,e)},m(e,i){b(t,e,i),p=!0},i(e){p||(o(t.$$.fragment,e),p=!0)},o(e){u(t.$$.fragment,e),p=!1},d(e){h(t,e)}}}function ze(f){let t,p="✏️ <strong>試試看！</strong> 選取訓練集中的第15個元素，將兩句話分別標記為一對。結果和上方的例子有什麼不同？";return{c(){t=y("p"),t.innerHTML=p},l(e){t=j(e,"P",{"data-svelte-h":!0}),m(t)!=="svelte-mrtvfp"&&(t.innerHTML=p)},m(e,i){a(e,t,i)},p:_t,d(e){e&&n(t)}}}function He(f){let t,p="負責在批處理中將數據整理為一個batch的函數稱為<em>collate函數</em>。它只會將您的樣本轉換為 tf.Tensor並將它們拼接起來(如果你的元素是列表、元組或字典，則會使用遞歸)。這在我們的這個例子中下是不可行的，因為我們的輸入不是都是相同大小的。我們故意在之後每個batch上進行填充，避免有太多填充的過長的輸入。這將大大加快訓練速度，但請注意，如果你在TPU上訓練，這可能會導致問題——TPU喜歡固定的形狀，即使這需要額外的填充。";return{c(){t=y("p"),t.innerHTML=p},l(e){t=j(e,"P",{"data-svelte-h":!0}),m(t)!=="svelte-7eucyw"&&(t.innerHTML=p)},m(e,i){a(e,t,i)},d(e){e&&n(t)}}}function Se(f){let t,p="負責在批處理中將數據整理為一個batch的函數稱為<em>collate函數</em>。它是你可以在構建<strong>DataLoader</strong>時傳遞的一個參數，默認是一個函數，它將把你的數據集轉換為PyTorch張量，並將它們拼接起來(如果你的元素是列表、元組或字典，則會使用遞歸)。這在我們的這個例子中下是不可行的，因為我們的輸入不是都是相同大小的。我們故意在之後每個batch上進行填充，避免有太多填充的過長的輸入。這將大大加快訓練速度，但請注意，如果你在TPU上訓練，這可能會導致問題——TPU喜歡固定的形狀，即使這需要額外的填充。";return{c(){t=y("p"),t.innerHTML=p},l(e){t=j(e,"P",{"data-svelte-h":!0}),m(t)!=="svelte-1kinyi6"&&(t.innerHTML=p)},m(e,i){a(e,t,i)},d(e){e&&n(t)}}}function Ye(f){let t,p;return t=new w({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMERhdGFDb2xsYXRvcldpdGhQYWRkaW5nJTBBJTBBZGF0YV9jb2xsYXRvciUyMCUzRCUyMERhdGFDb2xsYXRvcldpdGhQYWRkaW5nKHRva2VuaXplciUzRHRva2VuaXplciUyQyUyMHJldHVybl90ZW5zb3JzJTNEJTIydGYlMjIp",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> DataCollatorWithPadding

data_collator = DataCollatorWithPadding(tokenizer=tokenizer, return_tensors=<span class="hljs-string">&quot;tf&quot;</span>)`,wrap:!1}}),{c(){J(t.$$.fragment)},l(e){U(t.$$.fragment,e)},m(e,i){b(t,e,i),p=!0},i(e){p||(o(t.$$.fragment,e),p=!0)},o(e){u(t.$$.fragment,e),p=!1},d(e){h(t,e)}}}function Fe(f){let t,p;return t=new w({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMERhdGFDb2xsYXRvcldpdGhQYWRkaW5nJTBBJTBBZGF0YV9jb2xsYXRvciUyMCUzRCUyMERhdGFDb2xsYXRvcldpdGhQYWRkaW5nKHRva2VuaXplciUzRHRva2VuaXplcik=",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> DataCollatorWithPadding

data_collator = DataCollatorWithPadding(tokenizer=tokenizer)`,wrap:!1}}),{c(){J(t.$$.fragment)},l(e){U(t.$$.fragment,e)},m(e,i){b(t,e,i),p=!0},i(e){p||(o(t.$$.fragment,e),p=!0)},o(e){u(t.$$.fragment,e),p=!1},d(e){h(t,e)}}}function De(f){let t,p,e,i="看起來不錯！現在，我們已經將原始文本轉化為了模型可以處理的數據，我們已準備好對其進行微調！",d;return t=new w({props:{code:"JTdCJ2F0dGVudGlvbl9tYXNrJyUzQSUyMHRvcmNoLlNpemUoJTVCOCUyQyUyMDY3JTVEKSUyQyUwQSUyMCdpbnB1dF9pZHMnJTNBJTIwdG9yY2guU2l6ZSglNUI4JTJDJTIwNjclNUQpJTJDJTBBJTIwJ3Rva2VuX3R5cGVfaWRzJyUzQSUyMHRvcmNoLlNpemUoJTVCOCUyQyUyMDY3JTVEKSUyQyUwQSUyMCdsYWJlbHMnJTNBJTIwdG9yY2guU2l6ZSglNUI4JTVEKSU3RA==",highlighted:`{<span class="hljs-string">&#x27;attention_mask&#x27;</span>: torch.Size([<span class="hljs-number">8</span>, <span class="hljs-number">67</span>]),
 <span class="hljs-string">&#x27;input_ids&#x27;</span>: torch.Size([<span class="hljs-number">8</span>, <span class="hljs-number">67</span>]),
 <span class="hljs-string">&#x27;token_type_ids&#x27;</span>: torch.Size([<span class="hljs-number">8</span>, <span class="hljs-number">67</span>]),
 <span class="hljs-string">&#x27;labels&#x27;</span>: torch.Size([<span class="hljs-number">8</span>])}`,wrap:!1}}),{c(){J(t.$$.fragment),p=r(),e=y("p"),e.textContent=i},l(c){U(t.$$.fragment,c),p=M(c),e=j(c,"P",{"data-svelte-h":!0}),m(e)!=="svelte-19tjzm9"&&(e.textContent=i)},m(c,g){b(t,c,g),a(c,p,g),a(c,e,g),d=!0},i(c){d||(o(t.$$.fragment,c),d=!0)},o(c){u(t.$$.fragment,c),d=!1},d(c){c&&(n(p),n(e)),h(t,c)}}}function qe(f){let t,p;return t=new w({props:{code:"JTdCJ2F0dGVudGlvbl9tYXNrJyUzQSUyMFRlbnNvclNoYXBlKCU1QjglMkMlMjA2NyU1RCklMkMlMEElMjAnaW5wdXRfaWRzJyUzQSUyMFRlbnNvclNoYXBlKCU1QjglMkMlMjA2NyU1RCklMkMlMEElMjAndG9rZW5fdHlwZV9pZHMnJTNBJTIwVGVuc29yU2hhcGUoJTVCOCUyQyUyMDY3JTVEKSUyQyUwQSUyMCdsYWJlbHMnJTNBJTIwVGVuc29yU2hhcGUoJTVCOCU1RCklN0Q=",highlighted:`{<span class="hljs-string">&#x27;attention_mask&#x27;</span>: TensorShape([<span class="hljs-number">8</span>, <span class="hljs-number">67</span>]),
 <span class="hljs-string">&#x27;input_ids&#x27;</span>: TensorShape([<span class="hljs-number">8</span>, <span class="hljs-number">67</span>]),
 <span class="hljs-string">&#x27;token_type_ids&#x27;</span>: TensorShape([<span class="hljs-number">8</span>, <span class="hljs-number">67</span>]),
 <span class="hljs-string">&#x27;labels&#x27;</span>: TensorShape([<span class="hljs-number">8</span>])}`,wrap:!1}}),{c(){J(t.$$.fragment)},l(e){U(t.$$.fragment,e)},m(e,i){b(t,e,i),p=!0},i(e){p||(o(t.$$.fragment,e),p=!0)},o(e){u(t.$$.fragment,e),p=!1},d(e){h(t,e)}}}function Le(f){let t,p="✏️ <strong>試試看！</strong> 在GLUE SST-2數據集上應用預處理。它有點不同，因為它是由單個句子而不是成對的句子組成的，但是我們所做的其他事情看起來應該是一樣的。另一個更難的挑戰，請嘗試編寫一個可用於任何GLUE任務的預處理函數。";return{c(){t=y("p"),t.innerHTML=p},l(e){t=j(e,"P",{"data-svelte-h":!0}),m(t)!=="svelte-15a5shq"&&(t.innerHTML=p)},m(e,i){a(e,t,i)},p:_t,d(e){e&&n(t)}}}function ge(f){let t,p="現在我們有了 dataset 和 data collator，我們需要將 dataset 批次地應用 data collator。 我們可以手動載入批次並整理它們，但這需要大量工作，性能可能也不是很好。 相反，有一個簡單的方法可以為這個問題提供高效的解決方案：<code>to_tf_dataset()</code>。 這將在您的數據集上調用一個 <code>tf.data.Dataset</code>的方法，這個方法帶有一個可選的 data collator 功能。 <code>tf.data.Dataset</code> 是 Keras 可用於 <code>model.fit()</code> 的原生 TensorFlow 格式，因此這種方法會立即將🤗 Dataset 轉換為可用於訓練的格式。 讓我們看看它在我們的數據集上是如何使用的！",e,i,d,c,g="就是這樣！ 我們可以將這些數據集帶入下一節，在經過所有艱苦的數據預處理工作之後，訓練將變得非常簡單。",B;return i=new w({props:{code:"dGZfdHJhaW5fZGF0YXNldCUyMCUzRCUyMHRva2VuaXplZF9kYXRhc2V0cyU1QiUyMnRyYWluJTIyJTVELnRvX3RmX2RhdGFzZXQoJTBBJTIwJTIwJTIwJTIwY29sdW1ucyUzRCU1QiUyMmF0dGVudGlvbl9tYXNrJTIyJTJDJTIwJTIyaW5wdXRfaWRzJTIyJTJDJTIwJTIydG9rZW5fdHlwZV9pZHMlMjIlNUQlMkMlMEElMjAlMjAlMjAlMjBsYWJlbF9jb2xzJTNEJTVCJTIybGFiZWxzJTIyJTVEJTJDJTBBJTIwJTIwJTIwJTIwc2h1ZmZsZSUzRFRydWUlMkMlMEElMjAlMjAlMjAlMjBjb2xsYXRlX2ZuJTNEZGF0YV9jb2xsYXRvciUyQyUwQSUyMCUyMCUyMCUyMGJhdGNoX3NpemUlM0Q4JTJDJTBBKSUwQSUwQXRmX3ZhbGlkYXRpb25fZGF0YXNldCUyMCUzRCUyMHRva2VuaXplZF9kYXRhc2V0cyU1QiUyMnZhbGlkYXRpb24lMjIlNUQudG9fdGZfZGF0YXNldCglMEElMjAlMjAlMjAlMjBjb2x1bW5zJTNEJTVCJTIyYXR0ZW50aW9uX21hc2slMjIlMkMlMjAlMjJpbnB1dF9pZHMlMjIlMkMlMjAlMjJ0b2tlbl90eXBlX2lkcyUyMiU1RCUyQyUwQSUyMCUyMCUyMCUyMGxhYmVsX2NvbHMlM0QlNUIlMjJsYWJlbHMlMjIlNUQlMkMlMEElMjAlMjAlMjAlMjBzaHVmZmxlJTNERmFsc2UlMkMlMEElMjAlMjAlMjAlMjBjb2xsYXRlX2ZuJTNEZGF0YV9jb2xsYXRvciUyQyUwQSUyMCUyMCUyMCUyMGJhdGNoX3NpemUlM0Q4JTJDJTBBKQ==",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;token_type_ids&quot;</span>],
    label_cols=[<span class="hljs-string">&quot;labels&quot;</span>],
    shuffle=<span class="hljs-literal">True</span>,
    collate_fn=data_collator,
    batch_size=<span class="hljs-number">8</span>,
)

tf_validation_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;token_type_ids&quot;</span>],
    label_cols=[<span class="hljs-string">&quot;labels&quot;</span>],
    shuffle=<span class="hljs-literal">False</span>,
    collate_fn=data_collator,
    batch_size=<span class="hljs-number">8</span>,
)`,wrap:!1}}),{c(){t=y("p"),t.innerHTML=p,e=r(),J(i.$$.fragment),d=r(),c=y("p"),c.textContent=g},l(T){t=j(T,"P",{"data-svelte-h":!0}),m(t)!=="svelte-1cwkjpk"&&(t.innerHTML=p),e=M(T),U(i.$$.fragment,T),d=M(T),c=j(T,"P",{"data-svelte-h":!0}),m(c)!=="svelte-1rk3qjw"&&(c.textContent=g)},m(T,$){a(T,t,$),a(T,e,$),b(i,T,$),a(T,d,$),a(T,c,$),B=!0},i(T){B||(o(i.$$.fragment,T),B=!0)},o(T){u(i.$$.fragment,T),B=!1},d(T){T&&(n(t),n(e),n(d),n(c)),h(i,T)}}}function Pe(f){let t,p,e,i,d,c,g,B,T,$,Os,k,C,sl,E,$t="當然，僅僅用兩句話訓練模型不會產生很好的效果。為了獲得更好的結果，您需要準備一個更大的數據集。",il,z,kt='在本節中，我們將使用MRPC（微軟研究釋義語料庫）數據集作為示例，該數據集由威廉·多蘭和克里斯·布羅克特在<a href="https://www.aclweb.org/anthology/I05-5002.pdf" rel="nofollow">這篇文章</a>發佈。該數據集由5801對句子組成，每個句子對帶有一個標籤，指示它們是否為同義（即，如果兩個句子的意思相同）。我們在本章中選擇了它，因為它是一個小數據集，所以很容易對它進行訓練。',cl,H,ol,x,I,ll,S,Ct='模型中心（hub）不只是包含模型；它也有許多不同語言的多個數據集。點擊<a href="https://huggingface.co/datasets" rel="nofollow">數據集</a>的鏈接即可進行瀏覽。我們建議您在閱讀本節後閱讀一下<a href="https://huggingface.co/docs/datasets/loading" rel="nofollow">加載和處理新的數據集</a>這篇文章，這會讓您對huggingface的darasets更加清晰。但現在，讓我們使用MRPC數據集中的<a href="https://gluebenchmark.com/" rel="nofollow">GLUE 基準測試數據集</a>，它是構成MRPC數據集的10個數據集之一，這是一個學術基準，用於衡量機器學習模型在10個不同文本分類任務中的性能。',ul,Y,xt="🤗 Datasets庫提供了一個非常便捷的命令，可以在模型中心（hub）上下載和緩存數據集。我們可以通過以下的代碼下載MRPC數據集：",yl,F,jl,D,ml,q,It="正如你所看到的，我們獲得了一個<strong>DatasetDict</strong>對象，其中包含訓練集、驗證集和測試集。每一個集合都包含幾個列(<strong>sentence1</strong>, <strong>sentence2</strong>, <strong>label</strong>, and <strong>idx</strong>)以及一個代表行數的變量，即每個集合中的行的個數（因此，訓練集中有3668對句子，驗證集中有408對，測試集中有1725對）。",Jl,L,Rt="默認情況下，此命令在下載數據集並緩存到 <strong>~/.cache/huggingface/dataset</strong>. 回想一下第2章，您可以通過設置<strong>HF_HOME</strong>環境變量來自定義緩存的文件夾。",Ul,P,Zt="我們可以訪問我們數據集中的每一個<strong>raw_train_dataset</strong>對象，如使用字典：",bl,K,hl,O,fl,ss,Nt="我們可以看到標籤已經是整數了，所以我們不需要對標籤做任何預處理。要知道哪個數字對應於哪個標籤，我們可以查看<strong>raw_train_dataset</strong>的<strong>features</strong>. 這將告訴我們每列的類型：",Tl,ls,dl,ts,wl,es,At="在上面的例子之中,<strong>Label（標籤）</strong> 是一種<strong>ClassLabel（分類標籤）</strong>，使用整數建立起到類別標籤的映射關係。<strong>0</strong>對應於<strong>not_equivalent</strong>，<strong>1</strong>對應於<strong>equivalent</strong>。",gl,X,_l,ns,$l,R,Z,tl,as,Gt='為了預處理數據集，我們需要將文本轉換為模型能夠理解的數字。正如你在<a href="/course/chapter2">第二章</a>上看到的那樣',kl,ps,Cl,rs,Qt="然而，在兩句話傳遞給模型，預測這兩句話是否是同義之前。我們需要這兩句話依次進行適當的預處理。幸運的是，標記器不僅僅可以輸入單個句子還可以輸入一組句子，並按照我們的BERT模型所期望的輸入進行處理：",xl,Ms,Il,is,Rl,cs,Bt='我們在<a href="/course/chapter2">第二章</a> 討論了<strong>輸入詞id(input_ids)</strong> 和 <strong>注意力遮罩(attention_mask)</strong> ，但我們在那個時候沒有討論<strong>類型標記ID(token_type_ids)</strong>。在這個例子中，<strong>類型標記ID(token_type_ids)</strong>的作用就是告訴模型輸入的哪一部分是第一句，哪一部分是第二句。',Zl,V,Nl,os,vt="如果我們將<strong>input_ids</strong>中的id轉換回文字:",Al,us,Gl,ys,Xt="我們將得到：",Ql,js,Bl,ms,Vt="所以我們看到模型需要輸入的形式是 <strong>[CLS] sentence1 [SEP] sentence2 [SEP]</strong>。因此，當有兩句話的時候。<strong>類型標記ID(token_type_ids)</strong> 的值是：",vl,Js,Xl,Us,Wt="如您所見，輸入中 <strong>[CLS] sentence1 [SEP]</strong> 它們的類型標記ID均為<strong>0</strong>，而其他部分，對應於<strong>sentence2 [SEP]</strong>，所有的類型標記ID均為<strong>1</strong>.",Vl,bs,Et="請注意，如果選擇其他的檢查點，則不一定具有<strong>類型標記ID(token_type_ids)</strong>（例如，如果使用DistilBERT模型，就不會返回它們）。只有當它在預訓練期間使用過這一層，模型在構建時依賴它們，才會返回它們。",Wl,hs,zt='用類型標記ID對BERT進行預訓練,並且使用<a href="/course/chapter1">第一章</a>的遮罩語言模型，還有一個額外的應用類型，叫做下一句預測. 這項任務的目標是建立成對句子之間關係的模型。',El,fs,Ht="在下一個句子預測任務中，會給模型輸入成對的句子（帶有隨機遮罩的標記），並被要求預測第二個句子是否緊跟第一個句子。為了提高模型的泛化能力，數據集中一半的兩個句子在原始文檔中挨在一起，另一半的兩個句子來自兩個不同的文檔。",zl,Ts,St="一般來說，你不需要擔心是否有<strong>類型標記ID(token_type_ids)</strong>。在您的標輸入中：只要您對標記器和模型使用相同的檢查點，一切都會很好，因為標記器知道向其模型提供什麼。",Hl,ds,Yt='現在我們已經瞭解了標記器如何處理一對句子，我們可以使用它對整個數據集進行處理：如<a href="/course/chapter2">之前的章節</a>，我們可以給標記器提供一組句子，第一個參數是它第一個句子的列表，第二個參數是第二個句子的列表。這也與我們在<a href="/course/chapter2">第二章</a>中看到的填充和截斷選項兼容. 因此，預處理訓練數據集的一種方法是：',Sl,ws,Yl,gs,Ft='這很有效，但它的缺點是返回字典（字典的鍵是<strong>輸入詞id(input_ids)</strong> ， <strong>注意力遮罩(attention_mask)</strong> 和 <strong>類型標記ID(token_type_ids)</strong>，字典的值是鍵所對應值的列表）。而且只有當您在轉換過程中有足夠的內存來存儲整個數據集時才不會出錯（而🤗數據集庫中的數據集是以<a href="https://arrow.apache.org/" rel="nofollow">Apache Arrow</a>文件存儲在磁盤上，因此您只需將接下來要用的數據加載在內存中，因此會對內存容量的需求要低一些）。',Fl,_s,Dt='為了將數據保存為數據集，我們將使用<a href="https://huggingface.co/docs/datasets/package_reference/main_classes#datasets.Dataset.map" rel="nofollow">Dataset.map()</a>方法，如果我們需要做更多的預處理而不僅僅是標記化，那麼這也給了我們一些額外的自定義的方法。這個方法的工作原理是在數據集的每個元素上應用一個函數，因此讓我們定義一個標記輸入的函數：',Dl,$s,ql,ks,qt='此函數的輸入是一個字典（與數據集的項類似），並返回一個包含<strong>輸入詞id(input_ids)</strong> ， <strong>注意力遮罩(attention_mask)</strong> 和 <strong>類型標記ID(token_type_ids)</strong> 鍵的新字典。請注意，如果像上面的<strong>示例</strong>一樣，如果鍵所對應的值包含多個句子（每個鍵作為一個句子列表），那麼它依然可以工作，就像前面的例子一樣標記器可以處理成對的句子列表。這樣的話我們可以在調用<strong>map()</strong>使用該選項 <strong>batched=True</strong> ，這將顯著加快標記與標記的速度。這個<strong>標記器</strong>來自<a href="https://github.com/huggingface/tokenizers" rel="nofollow">🤗 Tokenizers</a>庫由Rust編寫而成。當我們一次給它大量的輸入時，這個標記器可以非常快。',Ll,Cs,Lt="請注意，我們現在在標記函數中省略了<strong>padding</strong>參數。這是因為在標記的時候將所有樣本填充到最大長度的效率不高。一個更好的做法：在構建批處理時填充樣本更好，因為這樣我們只需要填充到該批處理中的最大長度，而不是整個數據集的最大長度。當輸入長度變化很大時，這可以節省大量時間和處理能力!",Pl,xs,Pt="下面是我們如何在所有數據集上同時應用標記函數。我們在調用<strong>map</strong>時使用了<strong>batch =True</strong>，這樣函數就可以同時應用到數據集的多個元素上，而不是分別應用到每個元素上。這將使我們的預處理快許多",Kl,Is,Ol,Rs,Kt="🤗Datasets 庫應用這種處理的方式是向數據集添加新的字段，每個字段對應預處理函數返回的字典中的每個鍵:",st,Zs,lt,Ns,Ot="在使用預處理函數<strong>map()</strong>時，甚至可以通過傳遞<strong>num_proc</strong>參數使用並行處理。我們在這裡沒有這樣做，因為🤗標記器庫已經使用多個線程來更快地標記我們的樣本，但是如果您沒有使用該庫支持的快速標記器，使用<strong>num_proc</strong>可能會加快預處理。",tt,As,se="我們的<strong>標記函數(tokenize_function)</strong>返回包含<strong>輸入詞id(input_ids)</strong> ， <strong>注意力遮罩(attention_mask)</strong> 和 <strong>類型標記ID(token_type_ids)</strong> 鍵的字典,所以這三個字段被添加到數據集的標記的結果中。注意，如果預處理函數<strong>map()</strong>為現有鍵返回一個新值，那將會修改原有鍵的值。",et,Gs,le="最後一件我們需要做的事情是，當我們一起批處理元素時，將所有示例填充到最長元素的長度——我們稱之為動態填充。",nt,Qs,at,Bs,pt,el,vs,te="為了解決句子長度統一的問題，我們必須定義一個collate函數，該函數會將每個batch句子填充到正確的長度。幸運的是，🤗transformer庫通過<strong>DataCollatorWithPadding</strong>為我們提供了這樣一個函數。當你實例化它時，需要一個標記器(用來知道使用哪個詞來填充，以及模型期望填充在左邊還是右邊)，並將做你需要的一切:",rt,N,A,nl,Xs,ee="為了測試這個新玩具，讓我們從我們的訓練集中抽取幾個樣本。這裡，我們刪除列<strong>idx</strong>, <strong>sentence1</strong>和<strong>sentence2</strong>，因為不需要它們，並查看一個batch中每個條目的長度:",Mt,Vs,it,Ws,ct,Es,ne="毫無疑問，我們得到了不同長度的樣本，從32到67。動態填充意味著該批中的所有樣本都應該填充到長度為67，這是該批中的最大長度。如果沒有動態填充，所有的樣本都必須填充到整個數據集中的最大長度，或者模型可以接受的最大長度。讓我們再次檢查<strong>data_collator</strong>是否正確地動態填充了這批樣本：",ot,zs,ut,G,Q,al,W,yt,pl,Hs,jt,rl,mt;d=new Ze({props:{fw:f[0]}}),g=new Ut({props:{title:"處理數據",local:"處理數據",headingTag:"h1"}});const ae=[Ge,Ae],Ss=[];function pe(s,l){return s[0]==="pt"?0:1}T=pe(f),$=Ss[T]=ae[T](f);const re=[Be,Qe],Ys=[];function Me(s,l){return s[0]==="pt"?0:1}k=Me(f),C=Ys[k]=re[k](f),H=new Ut({props:{title:"從模型中心（Hub）加載數據集",local:"從模型中心hub加載數據集",headingTag:"h3"}});const ie=[Xe,ve],Fs=[];function ce(s,l){return s[0]==="pt"?0:1}x=ce(f),I=Fs[x]=ie[x](f),F=new w({props:{code:"ZnJvbSUyMGRhdGFzZXRzJTIwaW1wb3J0JTIwbG9hZF9kYXRhc2V0JTBBJTBBcmF3X2RhdGFzZXRzJTIwJTNEJTIwbG9hZF9kYXRhc2V0KCUyMmdsdWUlMjIlMkMlMjAlMjJtcnBjJTIyKSUwQXJhd19kYXRhc2V0cw==",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;glue&quot;</span>, <span class="hljs-string">&quot;mrpc&quot;</span>)
raw_datasets`,wrap:!1}}),D=new w({props:{code:"RGF0YXNldERpY3QoJTdCJTBBJTIwJTIwJTIwJTIwdHJhaW4lM0ElMjBEYXRhc2V0KCU3QiUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMGZlYXR1cmVzJTNBJTIwJTVCJ3NlbnRlbmNlMSclMkMlMjAnc2VudGVuY2UyJyUyQyUyMCdsYWJlbCclMkMlMjAnaWR4JyU1RCUyQyUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMG51bV9yb3dzJTNBJTIwMzY2OCUwQSUyMCUyMCUyMCUyMCU3RCklMEElMjAlMjAlMjAlMjB2YWxpZGF0aW9uJTNBJTIwRGF0YXNldCglN0IlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBmZWF0dXJlcyUzQSUyMCU1QidzZW50ZW5jZTEnJTJDJTIwJ3NlbnRlbmNlMiclMkMlMjAnbGFiZWwnJTJDJTIwJ2lkeCclNUQlMkMlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBudW1fcm93cyUzQSUyMDQwOCUwQSUyMCUyMCUyMCUyMCU3RCklMEElMjAlMjAlMjAlMjB0ZXN0JTNBJTIwRGF0YXNldCglN0IlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBmZWF0dXJlcyUzQSUyMCU1QidzZW50ZW5jZTEnJTJDJTIwJ3NlbnRlbmNlMiclMkMlMjAnbGFiZWwnJTJDJTIwJ2lkeCclNUQlMkMlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBudW1fcm93cyUzQSUyMDE3MjUlMEElMjAlMjAlMjAlMjAlN0QpJTBBJTdEKQ==",highlighted:`DatasetDict({
    train: Dataset({
        features: [<span class="hljs-string">&#x27;sentence1&#x27;</span>, <span class="hljs-string">&#x27;sentence2&#x27;</span>, <span class="hljs-string">&#x27;label&#x27;</span>, <span class="hljs-string">&#x27;idx&#x27;</span>],
        num_rows: <span class="hljs-number">3668</span>
    })
    validation: Dataset({
        features: [<span class="hljs-string">&#x27;sentence1&#x27;</span>, <span class="hljs-string">&#x27;sentence2&#x27;</span>, <span class="hljs-string">&#x27;label&#x27;</span>, <span class="hljs-string">&#x27;idx&#x27;</span>],
        num_rows: <span class="hljs-number">408</span>
    })
    test: Dataset({
        features: [<span class="hljs-string">&#x27;sentence1&#x27;</span>, <span class="hljs-string">&#x27;sentence2&#x27;</span>, <span class="hljs-string">&#x27;label&#x27;</span>, <span class="hljs-string">&#x27;idx&#x27;</span>],
        num_rows: <span class="hljs-number">1725</span>
    })
})`,wrap:!1}}),K=new w({props:{code:"cmF3X3RyYWluX2RhdGFzZXQlMjAlM0QlMjByYXdfZGF0YXNldHMlNUIlMjJ0cmFpbiUyMiU1RCUwQXJhd190cmFpbl9kYXRhc2V0JTVCMCU1RA==",highlighted:`raw_train_dataset = raw_datasets[<span class="hljs-string">&quot;train&quot;</span>]
raw_train_dataset[<span class="hljs-number">0</span>]`,wrap:!1}}),O=new w({props:{code:"JTdCJ2lkeCclM0ElMjAwJTJDJTBBJTIwJ2xhYmVsJyUzQSUyMDElMkMlMEElMjAnc2VudGVuY2UxJyUzQSUyMCdBbXJvemklMjBhY2N1c2VkJTIwaGlzJTIwYnJvdGhlciUyMCUyQyUyMHdob20lMjBoZSUyMGNhbGxlZCUyMCUyMiUyMHRoZSUyMHdpdG5lc3MlMjAlMjIlMjAlMkMlMjBvZiUyMGRlbGliZXJhdGVseSUyMGRpc3RvcnRpbmclMjBoaXMlMjBldmlkZW5jZSUyMC4nJTJDJTBBJTIwJ3NlbnRlbmNlMiclM0ElMjAnUmVmZXJyaW5nJTIwdG8lMjBoaW0lMjBhcyUyMG9ubHklMjAlMjIlMjB0aGUlMjB3aXRuZXNzJTIwJTIyJTIwJTJDJTIwQW1yb3ppJTIwYWNjdXNlZCUyMGhpcyUyMGJyb3RoZXIlMjBvZiUyMGRlbGliZXJhdGVseSUyMGRpc3RvcnRpbmclMjBoaXMlMjBldmlkZW5jZSUyMC4nJTdE",highlighted:`{<span class="hljs-string">&#x27;idx&#x27;</span>: <span class="hljs-number">0</span>,
 <span class="hljs-string">&#x27;label&#x27;</span>: <span class="hljs-number">1</span>,
 <span class="hljs-string">&#x27;sentence1&#x27;</span>: <span class="hljs-string">&#x27;Amrozi accused his brother , whom he called &quot; the witness &quot; , of deliberately distorting his evidence .&#x27;</span>,
 <span class="hljs-string">&#x27;sentence2&#x27;</span>: <span class="hljs-string">&#x27;Referring to him as only &quot; the witness &quot; , Amrozi accused his brother of deliberately distorting his evidence .&#x27;</span>}`,wrap:!1}}),ls=new w({props:{code:"cmF3X3RyYWluX2RhdGFzZXQuZmVhdHVyZXM=",highlighted:"raw_train_dataset.features",wrap:!1}}),ts=new w({props:{code:"JTdCJ3NlbnRlbmNlMSclM0ElMjBWYWx1ZShkdHlwZSUzRCdzdHJpbmcnJTJDJTIwaWQlM0ROb25lKSUyQyUwQSUyMCdzZW50ZW5jZTInJTNBJTIwVmFsdWUoZHR5cGUlM0Qnc3RyaW5nJyUyQyUyMGlkJTNETm9uZSklMkMlMEElMjAnbGFiZWwnJTNBJTIwQ2xhc3NMYWJlbChudW1fY2xhc3NlcyUzRDIlMkMlMjBuYW1lcyUzRCU1Qidub3RfZXF1aXZhbGVudCclMkMlMjAnZXF1aXZhbGVudCclNUQlMkMlMjBuYW1lc19maWxlJTNETm9uZSUyQyUyMGlkJTNETm9uZSklMkMlMEElMjAnaWR4JyUzQSUyMFZhbHVlKGR0eXBlJTNEJ2ludDMyJyUyQyUyMGlkJTNETm9uZSklN0Q=",highlighted:`{<span class="hljs-string">&#x27;sentence1&#x27;</span>: Value(dtype=<span class="hljs-string">&#x27;string&#x27;</span>, <span class="hljs-built_in">id</span>=<span class="hljs-literal">None</span>),
 <span class="hljs-string">&#x27;sentence2&#x27;</span>: Value(dtype=<span class="hljs-string">&#x27;string&#x27;</span>, <span class="hljs-built_in">id</span>=<span class="hljs-literal">None</span>),
 <span class="hljs-string">&#x27;label&#x27;</span>: ClassLabel(num_classes=<span class="hljs-number">2</span>, names=[<span class="hljs-string">&#x27;not_equivalent&#x27;</span>, <span class="hljs-string">&#x27;equivalent&#x27;</span>], names_file=<span class="hljs-literal">None</span>, <span class="hljs-built_in">id</span>=<span class="hljs-literal">None</span>),
 <span class="hljs-string">&#x27;idx&#x27;</span>: Value(dtype=<span class="hljs-string">&#x27;int32&#x27;</span>, <span class="hljs-built_in">id</span>=<span class="hljs-literal">None</span>)}`,wrap:!1}}),X=new gt({props:{$$slots:{default:[Ve]},$$scope:{ctx:f}}}),ns=new Ut({props:{title:"預處理數據集",local:"預處理數據集",headingTag:"h3"}});const oe=[Ee,We],Ds=[];function ue(s,l){return s[0]==="pt"?0:1}R=ue(f),Z=Ds[R]=oe[R](f),ps=new w({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9Ub2tlbml6ZXIlMEElMEFjaGVja3BvaW50JTIwJTNEJTIwJTIyYmVydC1iYXNlLXVuY2FzZWQlMjIlMEF0b2tlbml6ZXIlMjAlM0QlMjBBdXRvVG9rZW5pemVyLmZyb21fcHJldHJhaW5lZChjaGVja3BvaW50KSUwQXRva2VuaXplZF9zZW50ZW5jZXNfMSUyMCUzRCUyMHRva2VuaXplcihyYXdfZGF0YXNldHMlNUIlMjJ0cmFpbiUyMiU1RCU1QiUyMnNlbnRlbmNlMSUyMiU1RCklMEF0b2tlbml6ZWRfc2VudGVuY2VzXzIlMjAlM0QlMjB0b2tlbml6ZXIocmF3X2RhdGFzZXRzJTVCJTIydHJhaW4lMjIlNUQlNUIlMjJzZW50ZW5jZTIlMjIlNUQp",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoTokenizer

checkpoint = <span class="hljs-string">&quot;bert-base-uncased&quot;</span>
tokenizer = AutoTokenizer.from_pretrained(checkpoint)
tokenized_sentences_1 = tokenizer(raw_datasets[<span class="hljs-string">&quot;train&quot;</span>][<span class="hljs-string">&quot;sentence1&quot;</span>])
tokenized_sentences_2 = tokenizer(raw_datasets[<span class="hljs-string">&quot;train&quot;</span>][<span class="hljs-string">&quot;sentence2&quot;</span>])`,wrap:!1}}),Ms=new w({props:{code:"aW5wdXRzJTIwJTNEJTIwdG9rZW5pemVyKCUyMlRoaXMlMjBpcyUyMHRoZSUyMGZpcnN0JTIwc2VudGVuY2UuJTIyJTJDJTIwJTIyVGhpcyUyMGlzJTIwdGhlJTIwc2Vjb25kJTIwb25lLiUyMiklMEFpbnB1dHM=",highlighted:`inputs = tokenizer(<span class="hljs-string">&quot;This is the first sentence.&quot;</span>, <span class="hljs-string">&quot;This is the second one.&quot;</span>)
inputs`,wrap:!1}}),is=new w({props:{code:"JTdCJTIwJTBBJTIwJTIwJ2lucHV0X2lkcyclM0ElMjAlNUIxMDElMkMlMjAyMDIzJTJDJTIwMjAwMyUyQyUyMDE5OTYlMkMlMjAyMDM0JTJDJTIwNjI1MSUyQyUyMDEwMTIlMkMlMjAxMDIlMkMlMjAyMDIzJTJDJTIwMjAwMyUyQyUyMDE5OTYlMkMlMjAyMTE3JTJDJTIwMjAyOCUyQyUyMDEwMTIlMkMlMjAxMDIlNUQlMkMlMEElMjAlMjAndG9rZW5fdHlwZV9pZHMnJTNBJTIwJTVCMCUyQyUyMDAlMkMlMjAwJTJDJTIwMCUyQyUyMDAlMkMlMjAwJTJDJTIwMCUyQyUyMDAlMkMlMjAxJTJDJTIwMSUyQyUyMDElMkMlMjAxJTJDJTIwMSUyQyUyMDElMkMlMjAxJTVEJTJDJTBBJTIwJTIwJ2F0dGVudGlvbl9tYXNrJyUzQSUyMCU1QjElMkMlMjAxJTJDJTIwMSUyQyUyMDElMkMlMjAxJTJDJTIwMSUyQyUyMDElMkMlMjAxJTJDJTIwMSUyQyUyMDElMkMlMjAxJTJDJTIwMSUyQyUyMDElMkMlMjAxJTJDJTIwMSU1RCUwQSU3RA==",highlighted:`{ 
  <span class="hljs-string">&#x27;input_ids&#x27;</span>: [<span class="hljs-number">101</span>, <span class="hljs-number">2023</span>, <span class="hljs-number">2003</span>, <span class="hljs-number">1996</span>, <span class="hljs-number">2034</span>, <span class="hljs-number">6251</span>, <span class="hljs-number">1012</span>, <span class="hljs-number">102</span>, <span class="hljs-number">2023</span>, <span class="hljs-number">2003</span>, <span class="hljs-number">1996</span>, <span class="hljs-number">2117</span>, <span class="hljs-number">2028</span>, <span class="hljs-number">1012</span>, <span class="hljs-number">102</span>],
  <span class="hljs-string">&#x27;token_type_ids&#x27;</span>: [<span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>],
  <span class="hljs-string">&#x27;attention_mask&#x27;</span>: [<span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>]
}`,wrap:!1}}),V=new gt({props:{$$slots:{default:[ze]},$$scope:{ctx:f}}}),us=new w({props:{code:"dG9rZW5pemVyLmNvbnZlcnRfaWRzX3RvX3Rva2VucyhpbnB1dHMlNUIlMjJpbnB1dF9pZHMlMjIlNUQp",highlighted:'tokenizer.convert_ids_to_tokens(inputs[<span class="hljs-string">&quot;input_ids&quot;</span>])',wrap:!1}}),js=new w({props:{code:"JTVCJyU1QkNMUyU1RCclMkMlMjAndGhpcyclMkMlMjAnaXMnJTJDJTIwJ3RoZSclMkMlMjAnZmlyc3QnJTJDJTIwJ3NlbnRlbmNlJyUyQyUyMCcuJyUyQyUyMCclNUJTRVAlNUQnJTJDJTIwJ3RoaXMnJTJDJTIwJ2lzJyUyQyUyMCd0aGUnJTJDJTIwJ3NlY29uZCclMkMlMjAnb25lJyUyQyUyMCcuJyUyQyUyMCclNUJTRVAlNUQnJTVE",highlighted:'[<span class="hljs-string">&#x27;[CLS]&#x27;</span>, <span class="hljs-string">&#x27;this&#x27;</span>, <span class="hljs-string">&#x27;is&#x27;</span>, <span class="hljs-string">&#x27;the&#x27;</span>, <span class="hljs-string">&#x27;first&#x27;</span>, <span class="hljs-string">&#x27;sentence&#x27;</span>, <span class="hljs-string">&#x27;.&#x27;</span>, <span class="hljs-string">&#x27;[SEP]&#x27;</span>, <span class="hljs-string">&#x27;this&#x27;</span>, <span class="hljs-string">&#x27;is&#x27;</span>, <span class="hljs-string">&#x27;the&#x27;</span>, <span class="hljs-string">&#x27;second&#x27;</span>, <span class="hljs-string">&#x27;one&#x27;</span>, <span class="hljs-string">&#x27;.&#x27;</span>, <span class="hljs-string">&#x27;[SEP]&#x27;</span>]',wrap:!1}}),Js=new w({props:{code:"JTVCJyU1QkNMUyU1RCclMkMlMjAndGhpcyclMkMlMjAnaXMnJTJDJTIwJ3RoZSclMkMlMjAnZmlyc3QnJTJDJTIwJ3NlbnRlbmNlJyUyQyUyMCcuJyUyQyUyMCclNUJTRVAlNUQnJTJDJTIwJ3RoaXMnJTJDJTIwJ2lzJyUyQyUyMCd0aGUnJTJDJTIwJ3NlY29uZCclMkMlMjAnb25lJyUyQyUyMCcuJyUyQyUyMCclNUJTRVAlNUQnJTVEJTBBJTVCJTIwJTIwJTIwJTIwJTIwJTIwMCUyQyUyMCUyMCUyMCUyMCUyMCUyMDAlMkMlMjAlMjAlMjAlMjAwJTJDJTIwJTIwJTIwJTIwJTIwMCUyQyUyMCUyMCUyMCUyMCUyMCUyMCUyMDAlMkMlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAwJTJDJTIwJTIwJTIwMCUyQyUyMCUyMCUyMCUyMCUyMCUyMCUyMDAlMkMlMjAlMjAlMjAlMjAlMjAlMjAxJTJDJTIwJTIwJTIwJTIwMSUyQyUyMCUyMCUyMCUyMCUyMDElMkMlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAxJTJDJTIwJTIwJTIwJTIwJTIwMSUyQyUyMCUyMCUyMDElMkMlMjAlMjAlMjAlMjAlMjAlMjAlMjAxJTVE",highlighted:`[<span class="hljs-string">&#x27;[CLS]&#x27;</span>, <span class="hljs-string">&#x27;this&#x27;</span>, <span class="hljs-string">&#x27;is&#x27;</span>, <span class="hljs-string">&#x27;the&#x27;</span>, <span class="hljs-string">&#x27;first&#x27;</span>, <span class="hljs-string">&#x27;sentence&#x27;</span>, <span class="hljs-string">&#x27;.&#x27;</span>, <span class="hljs-string">&#x27;[SEP]&#x27;</span>, <span class="hljs-string">&#x27;this&#x27;</span>, <span class="hljs-string">&#x27;is&#x27;</span>, <span class="hljs-string">&#x27;the&#x27;</span>, <span class="hljs-string">&#x27;second&#x27;</span>, <span class="hljs-string">&#x27;one&#x27;</span>, <span class="hljs-string">&#x27;.&#x27;</span>, <span class="hljs-string">&#x27;[SEP]&#x27;</span>]
[      <span class="hljs-number">0</span>,      <span class="hljs-number">0</span>,    <span class="hljs-number">0</span>,     <span class="hljs-number">0</span>,       <span class="hljs-number">0</span>,          <span class="hljs-number">0</span>,   <span class="hljs-number">0</span>,       <span class="hljs-number">0</span>,      <span class="hljs-number">1</span>,    <span class="hljs-number">1</span>,     <span class="hljs-number">1</span>,        <span class="hljs-number">1</span>,     <span class="hljs-number">1</span>,   <span class="hljs-number">1</span>,       <span class="hljs-number">1</span>]`,wrap:!1}}),ws=new w({props:{code:"dG9rZW5pemVkX2RhdGFzZXQlMjAlM0QlMjB0b2tlbml6ZXIoJTBBJTIwJTIwJTIwJTIwcmF3X2RhdGFzZXRzJTVCJTIydHJhaW4lMjIlNUQlNUIlMjJzZW50ZW5jZTElMjIlNUQlMkMlMEElMjAlMjAlMjAlMjByYXdfZGF0YXNldHMlNUIlMjJ0cmFpbiUyMiU1RCU1QiUyMnNlbnRlbmNlMiUyMiU1RCUyQyUwQSUyMCUyMCUyMCUyMHBhZGRpbmclM0RUcnVlJTJDJTBBJTIwJTIwJTIwJTIwdHJ1bmNhdGlvbiUzRFRydWUlMkMlMEEp",highlighted:`tokenized_dataset = tokenizer(
    raw_datasets[<span class="hljs-string">&quot;train&quot;</span>][<span class="hljs-string">&quot;sentence1&quot;</span>],
    raw_datasets[<span class="hljs-string">&quot;train&quot;</span>][<span class="hljs-string">&quot;sentence2&quot;</span>],
    padding=<span class="hljs-literal">True</span>,
    truncation=<span class="hljs-literal">True</span>,
)`,wrap:!1}}),$s=new w({props:{code:"ZGVmJTIwdG9rZW5pemVfZnVuY3Rpb24oZXhhbXBsZSklM0ElMEElMjAlMjAlMjAlMjByZXR1cm4lMjB0b2tlbml6ZXIoZXhhbXBsZSU1QiUyMnNlbnRlbmNlMSUyMiU1RCUyQyUyMGV4YW1wbGUlNUIlMjJzZW50ZW5jZTIlMjIlNUQlMkMlMjB0cnVuY2F0aW9uJTNEVHJ1ZSk=",highlighted:`<span class="hljs-keyword">def</span> <span class="hljs-title function_">tokenize_function</span>(<span class="hljs-params">example</span>):
    <span class="hljs-keyword">return</span> tokenizer(example[<span class="hljs-string">&quot;sentence1&quot;</span>], example[<span class="hljs-string">&quot;sentence2&quot;</span>], truncation=<span class="hljs-literal">True</span>)`,wrap:!1}}),Is=new w({props:{code:"dG9rZW5pemVkX2RhdGFzZXRzJTIwJTNEJTIwcmF3X2RhdGFzZXRzLm1hcCh0b2tlbml6ZV9mdW5jdGlvbiUyQyUyMGJhdGNoZWQlM0RUcnVlKSUwQXRva2VuaXplZF9kYXRhc2V0cw==",highlighted:`tokenized_datasets = raw_datasets.<span class="hljs-built_in">map</span>(tokenize_function, batched=<span class="hljs-literal">True</span>)
tokenized_datasets`,wrap:!1}}),Zs=new w({props:{code:"RGF0YXNldERpY3QoJTdCJTBBJTIwJTIwJTIwJTIwdHJhaW4lM0ElMjBEYXRhc2V0KCU3QiUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMGZlYXR1cmVzJTNBJTIwJTVCJ2F0dGVudGlvbl9tYXNrJyUyQyUyMCdpZHgnJTJDJTIwJ2lucHV0X2lkcyclMkMlMjAnbGFiZWwnJTJDJTIwJ3NlbnRlbmNlMSclMkMlMjAnc2VudGVuY2UyJyUyQyUyMCd0b2tlbl90eXBlX2lkcyclNUQlMkMlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBudW1fcm93cyUzQSUyMDM2NjglMEElMjAlMjAlMjAlMjAlN0QpJTBBJTIwJTIwJTIwJTIwdmFsaWRhdGlvbiUzQSUyMERhdGFzZXQoJTdCJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwZmVhdHVyZXMlM0ElMjAlNUInYXR0ZW50aW9uX21hc2snJTJDJTIwJ2lkeCclMkMlMjAnaW5wdXRfaWRzJyUyQyUyMCdsYWJlbCclMkMlMjAnc2VudGVuY2UxJyUyQyUyMCdzZW50ZW5jZTInJTJDJTIwJ3Rva2VuX3R5cGVfaWRzJyU1RCUyQyUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMG51bV9yb3dzJTNBJTIwNDA4JTBBJTIwJTIwJTIwJTIwJTdEKSUwQSUyMCUyMCUyMCUyMHRlc3QlM0ElMjBEYXRhc2V0KCU3QiUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMGZlYXR1cmVzJTNBJTIwJTVCJ2F0dGVudGlvbl9tYXNrJyUyQyUyMCdpZHgnJTJDJTIwJ2lucHV0X2lkcyclMkMlMjAnbGFiZWwnJTJDJTIwJ3NlbnRlbmNlMSclMkMlMjAnc2VudGVuY2UyJyUyQyUyMCd0b2tlbl90eXBlX2lkcyclNUQlMkMlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBudW1fcm93cyUzQSUyMDE3MjUlMEElMjAlMjAlMjAlMjAlN0QpJTBBJTdEKQ==",highlighted:`DatasetDict({
    train: Dataset({
        features: [<span class="hljs-string">&#x27;attention_mask&#x27;</span>, <span class="hljs-string">&#x27;idx&#x27;</span>, <span class="hljs-string">&#x27;input_ids&#x27;</span>, <span class="hljs-string">&#x27;label&#x27;</span>, <span class="hljs-string">&#x27;sentence1&#x27;</span>, <span class="hljs-string">&#x27;sentence2&#x27;</span>, <span class="hljs-string">&#x27;token_type_ids&#x27;</span>],
        num_rows: <span class="hljs-number">3668</span>
    })
    validation: Dataset({
        features: [<span class="hljs-string">&#x27;attention_mask&#x27;</span>, <span class="hljs-string">&#x27;idx&#x27;</span>, <span class="hljs-string">&#x27;input_ids&#x27;</span>, <span class="hljs-string">&#x27;label&#x27;</span>, <span class="hljs-string">&#x27;sentence1&#x27;</span>, <span class="hljs-string">&#x27;sentence2&#x27;</span>, <span class="hljs-string">&#x27;token_type_ids&#x27;</span>],
        num_rows: <span class="hljs-number">408</span>
    })
    test: Dataset({
        features: [<span class="hljs-string">&#x27;attention_mask&#x27;</span>, <span class="hljs-string">&#x27;idx&#x27;</span>, <span class="hljs-string">&#x27;input_ids&#x27;</span>, <span class="hljs-string">&#x27;label&#x27;</span>, <span class="hljs-string">&#x27;sentence1&#x27;</span>, <span class="hljs-string">&#x27;sentence2&#x27;</span>, <span class="hljs-string">&#x27;token_type_ids&#x27;</span>],
        num_rows: <span class="hljs-number">1725</span>
    })
})`,wrap:!1}}),Qs=new Ut({props:{title:"動態填充",local:"動態填充",headingTag:"h3"}}),Bs=new Ml({props:{id:"7q5NyFT8REg"}});function ye(s,l){return s[0]==="pt"?Se:He}let Jt=ye(f),v=Jt(f);const je=[Fe,Ye],qs=[];function me(s,l){return s[0]==="pt"?0:1}N=me(f),A=qs[N]=je[N](f),Vs=new w({props:{code:"c2FtcGxlcyUyMCUzRCUyMHRva2VuaXplZF9kYXRhc2V0cyU1QiUyMnRyYWluJTIyJTVEJTVCJTNBOCU1RCUwQXNhbXBsZXMlMjAlM0QlMjAlN0JrJTNBJTIwdiUyMGZvciUyMGslMkMlMjB2JTIwaW4lMjBzYW1wbGVzLml0ZW1zKCklMjBpZiUyMGslMjBub3QlMjBpbiUyMCU1QiUyMmlkeCUyMiUyQyUyMCUyMnNlbnRlbmNlMSUyMiUyQyUyMCUyMnNlbnRlbmNlMiUyMiU1RCU3RCUwQSU1Qmxlbih4KSUyMGZvciUyMHglMjBpbiUyMHNhbXBsZXMlNUIlMjJpbnB1dF9pZHMlMjIlNUQlNUQ=",highlighted:`samples = tokenized_datasets[<span class="hljs-string">&quot;train&quot;</span>][:<span class="hljs-number">8</span>]
samples = {k: v <span class="hljs-keyword">for</span> k, v <span class="hljs-keyword">in</span> samples.items() <span class="hljs-keyword">if</span> k <span class="hljs-keyword">not</span> <span class="hljs-keyword">in</span> [<span class="hljs-string">&quot;idx&quot;</span>, <span class="hljs-string">&quot;sentence1&quot;</span>, <span class="hljs-string">&quot;sentence2&quot;</span>]}
[<span class="hljs-built_in">len</span>(x) <span class="hljs-keyword">for</span> x <span class="hljs-keyword">in</span> samples[<span class="hljs-string">&quot;input_ids&quot;</span>]]`,wrap:!1}}),Ws=new w({props:{code:"JTVCNTAlMkMlMjA1OSUyQyUyMDQ3JTJDJTIwNjclMkMlMjA1OSUyQyUyMDUwJTJDJTIwNjIlMkMlMjAzMiU1RA==",highlighted:'[<span class="hljs-number">50</span>, <span class="hljs-number">59</span>, <span class="hljs-number">47</span>, <span class="hljs-number">67</span>, <span class="hljs-number">59</span>, <span class="hljs-number">50</span>, <span class="hljs-number">62</span>, <span class="hljs-number">32</span>]',wrap:!1}}),zs=new w({props:{code:"JTBBJTYwJTYwJTYwcHklMEFiYXRjaCUyMCUzRCUyMGRhdGFfY29sbGF0b3Ioc2FtcGxlcyklMEElN0JrJTNBJTIwdi5zaGFwZSUyMGZvciUyMGslMkMlMjB2JTIwaW4lMjBiYXRjaC5pdGVtcygpJTdE",highlighted:'\n```py\nbatch = dat<span class="hljs-built_in">a_collator</span>(samples)\n<span class="hljs-title">{k:</span> v.shape for k, v in batch.items()}',wrap:!1}});const Je=[qe,De],Ls=[];function Ue(s,l){return s[0]==="tf"?0:1}G=Ue(f),Q=Ls[G]=Je[G](f),W=new gt({props:{$$slots:{default:[Le]},$$scope:{ctx:f}}});let _=f[0]==="tf"&&ge();return Hs=new Ne({props:{source:"https://github.com/huggingface/course/blob/main/chapters/zh-TW/chapter3/2.mdx"}}),{c(){t=y("meta"),p=r(),e=y("p"),i=r(),J(d.$$.fragment),c=r(),J(g.$$.fragment),B=r(),$.c(),Os=r(),C.c(),sl=r(),E=y("p"),E.textContent=$t,il=r(),z=y("p"),z.innerHTML=kt,cl=r(),J(H.$$.fragment),ol=r(),I.c(),ll=r(),S=y("p"),S.innerHTML=Ct,ul=r(),Y=y("p"),Y.textContent=xt,yl=r(),J(F.$$.fragment),jl=r(),J(D.$$.fragment),ml=r(),q=y("p"),q.innerHTML=It,Jl=r(),L=y("p"),L.innerHTML=Rt,Ul=r(),P=y("p"),P.innerHTML=Zt,bl=r(),J(K.$$.fragment),hl=r(),J(O.$$.fragment),fl=r(),ss=y("p"),ss.innerHTML=Nt,Tl=r(),J(ls.$$.fragment),dl=r(),J(ts.$$.fragment),wl=r(),es=y("p"),es.innerHTML=At,gl=r(),J(X.$$.fragment),_l=r(),J(ns.$$.fragment),$l=r(),Z.c(),tl=r(),as=y("p"),as.innerHTML=Gt,kl=r(),J(ps.$$.fragment),Cl=r(),rs=y("p"),rs.textContent=Qt,xl=r(),J(Ms.$$.fragment),Il=r(),J(is.$$.fragment),Rl=r(),cs=y("p"),cs.innerHTML=Bt,Zl=r(),J(V.$$.fragment),Nl=r(),os=y("p"),os.innerHTML=vt,Al=r(),J(us.$$.fragment),Gl=r(),ys=y("p"),ys.textContent=Xt,Ql=r(),J(js.$$.fragment),Bl=r(),ms=y("p"),ms.innerHTML=Vt,vl=r(),J(Js.$$.fragment),Xl=r(),Us=y("p"),Us.innerHTML=Wt,Vl=r(),bs=y("p"),bs.innerHTML=Et,Wl=r(),hs=y("p"),hs.innerHTML=zt,El=r(),fs=y("p"),fs.textContent=Ht,zl=r(),Ts=y("p"),Ts.innerHTML=St,Hl=r(),ds=y("p"),ds.innerHTML=Yt,Sl=r(),J(ws.$$.fragment),Yl=r(),gs=y("p"),gs.innerHTML=Ft,Fl=r(),_s=y("p"),_s.innerHTML=Dt,Dl=r(),J($s.$$.fragment),ql=r(),ks=y("p"),ks.innerHTML=qt,Ll=r(),Cs=y("p"),Cs.innerHTML=Lt,Pl=r(),xs=y("p"),xs.innerHTML=Pt,Kl=r(),J(Is.$$.fragment),Ol=r(),Rs=y("p"),Rs.textContent=Kt,st=r(),J(Zs.$$.fragment),lt=r(),Ns=y("p"),Ns.innerHTML=Ot,tt=r(),As=y("p"),As.innerHTML=se,et=r(),Gs=y("p"),Gs.textContent=le,nt=r(),J(Qs.$$.fragment),at=r(),J(Bs.$$.fragment),pt=r(),v.c(),el=r(),vs=y("p"),vs.innerHTML=te,rt=r(),A.c(),nl=r(),Xs=y("p"),Xs.innerHTML=ee,Mt=r(),J(Vs.$$.fragment),it=r(),J(Ws.$$.fragment),ct=r(),Es=y("p"),Es.innerHTML=ne,ot=r(),J(zs.$$.fragment),ut=r(),Q.c(),al=r(),J(W.$$.fragment),yt=r(),_&&_.c(),pl=r(),J(Hs.$$.fragment),jt=r(),rl=y("p"),this.h()},l(s){const l=Ie("svelte-u9bgzb",document.head);t=j(l,"META",{name:!0,content:!0}),l.forEach(n),p=M(s),e=j(s,"P",{}),de(e).forEach(n),i=M(s),U(d.$$.fragment,s),c=M(s),U(g.$$.fragment,s),B=M(s),$.l(s),Os=M(s),C.l(s),sl=M(s),E=j(s,"P",{"data-svelte-h":!0}),m(E)!=="svelte-1tud19e"&&(E.textContent=$t),il=M(s),z=j(s,"P",{"data-svelte-h":!0}),m(z)!=="svelte-6au758"&&(z.innerHTML=kt),cl=M(s),U(H.$$.fragment,s),ol=M(s),I.l(s),ll=M(s),S=j(s,"P",{"data-svelte-h":!0}),m(S)!=="svelte-xth3rd"&&(S.innerHTML=Ct),ul=M(s),Y=j(s,"P",{"data-svelte-h":!0}),m(Y)!=="svelte-aik3xs"&&(Y.textContent=xt),yl=M(s),U(F.$$.fragment,s),jl=M(s),U(D.$$.fragment,s),ml=M(s),q=j(s,"P",{"data-svelte-h":!0}),m(q)!=="svelte-12hpwdm"&&(q.innerHTML=It),Jl=M(s),L=j(s,"P",{"data-svelte-h":!0}),m(L)!=="svelte-1r81a35"&&(L.innerHTML=Rt),Ul=M(s),P=j(s,"P",{"data-svelte-h":!0}),m(P)!=="svelte-1q65f7f"&&(P.innerHTML=Zt),bl=M(s),U(K.$$.fragment,s),hl=M(s),U(O.$$.fragment,s),fl=M(s),ss=j(s,"P",{"data-svelte-h":!0}),m(ss)!=="svelte-wcw8ol"&&(ss.innerHTML=Nt),Tl=M(s),U(ls.$$.fragment,s),dl=M(s),U(ts.$$.fragment,s),wl=M(s),es=j(s,"P",{"data-svelte-h":!0}),m(es)!=="svelte-1suwfc2"&&(es.innerHTML=At),gl=M(s),U(X.$$.fragment,s),_l=M(s),U(ns.$$.fragment,s),$l=M(s),Z.l(s),tl=M(s),as=j(s,"P",{"data-svelte-h":!0}),m(as)!=="svelte-5i35i2"&&(as.innerHTML=Gt),kl=M(s),U(ps.$$.fragment,s),Cl=M(s),rs=j(s,"P",{"data-svelte-h":!0}),m(rs)!=="svelte-b116bs"&&(rs.textContent=Qt),xl=M(s),U(Ms.$$.fragment,s),Il=M(s),U(is.$$.fragment,s),Rl=M(s),cs=j(s,"P",{"data-svelte-h":!0}),m(cs)!=="svelte-gwt5vd"&&(cs.innerHTML=Bt),Zl=M(s),U(V.$$.fragment,s),Nl=M(s),os=j(s,"P",{"data-svelte-h":!0}),m(os)!=="svelte-1tphukj"&&(os.innerHTML=vt),Al=M(s),U(us.$$.fragment,s),Gl=M(s),ys=j(s,"P",{"data-svelte-h":!0}),m(ys)!=="svelte-14b16nm"&&(ys.textContent=Xt),Ql=M(s),U(js.$$.fragment,s),Bl=M(s),ms=j(s,"P",{"data-svelte-h":!0}),m(ms)!=="svelte-1jxkp6a"&&(ms.innerHTML=Vt),vl=M(s),U(Js.$$.fragment,s),Xl=M(s),Us=j(s,"P",{"data-svelte-h":!0}),m(Us)!=="svelte-9qj7c0"&&(Us.innerHTML=Wt),Vl=M(s),bs=j(s,"P",{"data-svelte-h":!0}),m(bs)!=="svelte-nb1fp3"&&(bs.innerHTML=Et),Wl=M(s),hs=j(s,"P",{"data-svelte-h":!0}),m(hs)!=="svelte-pjywr3"&&(hs.innerHTML=zt),El=M(s),fs=j(s,"P",{"data-svelte-h":!0}),m(fs)!=="svelte-1l39tnu"&&(fs.textContent=Ht),zl=M(s),Ts=j(s,"P",{"data-svelte-h":!0}),m(Ts)!=="svelte-1n2vgk4"&&(Ts.innerHTML=St),Hl=M(s),ds=j(s,"P",{"data-svelte-h":!0}),m(ds)!=="svelte-52p7vs"&&(ds.innerHTML=Yt),Sl=M(s),U(ws.$$.fragment,s),Yl=M(s),gs=j(s,"P",{"data-svelte-h":!0}),m(gs)!=="svelte-rqzipa"&&(gs.innerHTML=Ft),Fl=M(s),_s=j(s,"P",{"data-svelte-h":!0}),m(_s)!=="svelte-yw4773"&&(_s.innerHTML=Dt),Dl=M(s),U($s.$$.fragment,s),ql=M(s),ks=j(s,"P",{"data-svelte-h":!0}),m(ks)!=="svelte-qsko2d"&&(ks.innerHTML=qt),Ll=M(s),Cs=j(s,"P",{"data-svelte-h":!0}),m(Cs)!=="svelte-1c49eey"&&(Cs.innerHTML=Lt),Pl=M(s),xs=j(s,"P",{"data-svelte-h":!0}),m(xs)!=="svelte-1bs0ns4"&&(xs.innerHTML=Pt),Kl=M(s),U(Is.$$.fragment,s),Ol=M(s),Rs=j(s,"P",{"data-svelte-h":!0}),m(Rs)!=="svelte-17ue2uw"&&(Rs.textContent=Kt),st=M(s),U(Zs.$$.fragment,s),lt=M(s),Ns=j(s,"P",{"data-svelte-h":!0}),m(Ns)!=="svelte-12ax04u"&&(Ns.innerHTML=Ot),tt=M(s),As=j(s,"P",{"data-svelte-h":!0}),m(As)!=="svelte-4711gw"&&(As.innerHTML=se),et=M(s),Gs=j(s,"P",{"data-svelte-h":!0}),m(Gs)!=="svelte-ab8kpw"&&(Gs.textContent=le),nt=M(s),U(Qs.$$.fragment,s),at=M(s),U(Bs.$$.fragment,s),pt=M(s),v.l(s),el=M(s),vs=j(s,"P",{"data-svelte-h":!0}),m(vs)!=="svelte-142xupr"&&(vs.innerHTML=te),rt=M(s),A.l(s),nl=M(s),Xs=j(s,"P",{"data-svelte-h":!0}),m(Xs)!=="svelte-e9fcqi"&&(Xs.innerHTML=ee),Mt=M(s),U(Vs.$$.fragment,s),it=M(s),U(Ws.$$.fragment,s),ct=M(s),Es=j(s,"P",{"data-svelte-h":!0}),m(Es)!=="svelte-ror00y"&&(Es.innerHTML=ne),ot=M(s),U(zs.$$.fragment,s),ut=M(s),Q.l(s),al=M(s),U(W.$$.fragment,s),yt=M(s),_&&_.l(s),pl=M(s),U(Hs.$$.fragment,s),jt=M(s),rl=j(s,"P",{}),de(rl).forEach(n),this.h()},h(){we(t,"name","hf:doc:metadata"),we(t,"content",Ke)},m(s,l){Re(document.head,t),a(s,p,l),a(s,e,l),a(s,i,l),b(d,s,l),a(s,c,l),b(g,s,l),a(s,B,l),Ss[T].m(s,l),a(s,Os,l),Ys[k].m(s,l),a(s,sl,l),a(s,E,l),a(s,il,l),a(s,z,l),a(s,cl,l),b(H,s,l),a(s,ol,l),Fs[x].m(s,l),a(s,ll,l),a(s,S,l),a(s,ul,l),a(s,Y,l),a(s,yl,l),b(F,s,l),a(s,jl,l),b(D,s,l),a(s,ml,l),a(s,q,l),a(s,Jl,l),a(s,L,l),a(s,Ul,l),a(s,P,l),a(s,bl,l),b(K,s,l),a(s,hl,l),b(O,s,l),a(s,fl,l),a(s,ss,l),a(s,Tl,l),b(ls,s,l),a(s,dl,l),b(ts,s,l),a(s,wl,l),a(s,es,l),a(s,gl,l),b(X,s,l),a(s,_l,l),b(ns,s,l),a(s,$l,l),Ds[R].m(s,l),a(s,tl,l),a(s,as,l),a(s,kl,l),b(ps,s,l),a(s,Cl,l),a(s,rs,l),a(s,xl,l),b(Ms,s,l),a(s,Il,l),b(is,s,l),a(s,Rl,l),a(s,cs,l),a(s,Zl,l),b(V,s,l),a(s,Nl,l),a(s,os,l),a(s,Al,l),b(us,s,l),a(s,Gl,l),a(s,ys,l),a(s,Ql,l),b(js,s,l),a(s,Bl,l),a(s,ms,l),a(s,vl,l),b(Js,s,l),a(s,Xl,l),a(s,Us,l),a(s,Vl,l),a(s,bs,l),a(s,Wl,l),a(s,hs,l),a(s,El,l),a(s,fs,l),a(s,zl,l),a(s,Ts,l),a(s,Hl,l),a(s,ds,l),a(s,Sl,l),b(ws,s,l),a(s,Yl,l),a(s,gs,l),a(s,Fl,l),a(s,_s,l),a(s,Dl,l),b($s,s,l),a(s,ql,l),a(s,ks,l),a(s,Ll,l),a(s,Cs,l),a(s,Pl,l),a(s,xs,l),a(s,Kl,l),b(Is,s,l),a(s,Ol,l),a(s,Rs,l),a(s,st,l),b(Zs,s,l),a(s,lt,l),a(s,Ns,l),a(s,tt,l),a(s,As,l),a(s,et,l),a(s,Gs,l),a(s,nt,l),b(Qs,s,l),a(s,at,l),b(Bs,s,l),a(s,pt,l),v.m(s,l),a(s,el,l),a(s,vs,l),a(s,rt,l),qs[N].m(s,l),a(s,nl,l),a(s,Xs,l),a(s,Mt,l),b(Vs,s,l),a(s,it,l),b(Ws,s,l),a(s,ct,l),a(s,Es,l),a(s,ot,l),b(zs,s,l),a(s,ut,l),Ls[G].m(s,l),a(s,al,l),b(W,s,l),a(s,yt,l),_&&_.m(s,l),a(s,pl,l),b(Hs,s,l),a(s,jt,l),a(s,rl,l),mt=!0},p(s,[l]){const be={};l&1&&(be.fw=s[0]),d.$set(be);let bt=T;T=pe(s),T!==bt&&(Ks(),u(Ss[bt],1,1,()=>{Ss[bt]=null}),Ps(),$=Ss[T],$||($=Ss[T]=ae[T](s),$.c()),o($,1),$.m(Os.parentNode,Os));let ht=k;k=Me(s),k!==ht&&(Ks(),u(Ys[ht],1,1,()=>{Ys[ht]=null}),Ps(),C=Ys[k],C||(C=Ys[k]=re[k](s),C.c()),o(C,1),C.m(sl.parentNode,sl));let ft=x;x=ce(s),x!==ft&&(Ks(),u(Fs[ft],1,1,()=>{Fs[ft]=null}),Ps(),I=Fs[x],I||(I=Fs[x]=ie[x](s),I.c()),o(I,1),I.m(ll.parentNode,ll));const he={};l&2&&(he.$$scope={dirty:l,ctx:s}),X.$set(he);let Tt=R;R=ue(s),R!==Tt&&(Ks(),u(Ds[Tt],1,1,()=>{Ds[Tt]=null}),Ps(),Z=Ds[R],Z||(Z=Ds[R]=oe[R](s),Z.c()),o(Z,1),Z.m(tl.parentNode,tl));const fe={};l&2&&(fe.$$scope={dirty:l,ctx:s}),V.$set(fe),Jt!==(Jt=ye(s))&&(v.d(1),v=Jt(s),v&&(v.c(),v.m(el.parentNode,el)));let dt=N;N=me(s),N!==dt&&(Ks(),u(qs[dt],1,1,()=>{qs[dt]=null}),Ps(),A=qs[N],A||(A=qs[N]=je[N](s),A.c()),o(A,1),A.m(nl.parentNode,nl));let wt=G;G=Ue(s),G!==wt&&(Ks(),u(Ls[wt],1,1,()=>{Ls[wt]=null}),Ps(),Q=Ls[G],Q||(Q=Ls[G]=Je[G](s),Q.c()),o(Q,1),Q.m(al.parentNode,al));const Te={};l&2&&(Te.$$scope={dirty:l,ctx:s}),W.$set(Te),s[0]==="tf"?_?l&1&&o(_,1):(_=ge(),_.c(),o(_,1),_.m(pl.parentNode,pl)):_&&(Ks(),u(_,1,1,()=>{_=null}),Ps())},i(s){mt||(o(d.$$.fragment,s),o(g.$$.fragment,s),o($),o(C),o(H.$$.fragment,s),o(I),o(F.$$.fragment,s),o(D.$$.fragment,s),o(K.$$.fragment,s),o(O.$$.fragment,s),o(ls.$$.fragment,s),o(ts.$$.fragment,s),o(X.$$.fragment,s),o(ns.$$.fragment,s),o(Z),o(ps.$$.fragment,s),o(Ms.$$.fragment,s),o(is.$$.fragment,s),o(V.$$.fragment,s),o(us.$$.fragment,s),o(js.$$.fragment,s),o(Js.$$.fragment,s),o(ws.$$.fragment,s),o($s.$$.fragment,s),o(Is.$$.fragment,s),o(Zs.$$.fragment,s),o(Qs.$$.fragment,s),o(Bs.$$.fragment,s),o(A),o(Vs.$$.fragment,s),o(Ws.$$.fragment,s),o(zs.$$.fragment,s),o(Q),o(W.$$.fragment,s),o(_),o(Hs.$$.fragment,s),mt=!0)},o(s){u(d.$$.fragment,s),u(g.$$.fragment,s),u($),u(C),u(H.$$.fragment,s),u(I),u(F.$$.fragment,s),u(D.$$.fragment,s),u(K.$$.fragment,s),u(O.$$.fragment,s),u(ls.$$.fragment,s),u(ts.$$.fragment,s),u(X.$$.fragment,s),u(ns.$$.fragment,s),u(Z),u(ps.$$.fragment,s),u(Ms.$$.fragment,s),u(is.$$.fragment,s),u(V.$$.fragment,s),u(us.$$.fragment,s),u(js.$$.fragment,s),u(Js.$$.fragment,s),u(ws.$$.fragment,s),u($s.$$.fragment,s),u(Is.$$.fragment,s),u(Zs.$$.fragment,s),u(Qs.$$.fragment,s),u(Bs.$$.fragment,s),u(A),u(Vs.$$.fragment,s),u(Ws.$$.fragment,s),u(zs.$$.fragment,s),u(Q),u(W.$$.fragment,s),u(_),u(Hs.$$.fragment,s),mt=!1},d(s){s&&(n(p),n(e),n(i),n(c),n(B),n(Os),n(sl),n(E),n(il),n(z),n(cl),n(ol),n(ll),n(S),n(ul),n(Y),n(yl),n(jl),n(ml),n(q),n(Jl),n(L),n(Ul),n(P),n(bl),n(hl),n(fl),n(ss),n(Tl),n(dl),n(wl),n(es),n(gl),n(_l),n($l),n(tl),n(as),n(kl),n(Cl),n(rs),n(xl),n(Il),n(Rl),n(cs),n(Zl),n(Nl),n(os),n(Al),n(Gl),n(ys),n(Ql),n(Bl),n(ms),n(vl),n(Xl),n(Us),n(Vl),n(bs),n(Wl),n(hs),n(El),n(fs),n(zl),n(Ts),n(Hl),n(ds),n(Sl),n(Yl),n(gs),n(Fl),n(_s),n(Dl),n(ql),n(ks),n(Ll),n(Cs),n(Pl),n(xs),n(Kl),n(Ol),n(Rs),n(st),n(lt),n(Ns),n(tt),n(As),n(et),n(Gs),n(nt),n(at),n(pt),n(el),n(vs),n(rt),n(nl),n(Xs),n(Mt),n(it),n(ct),n(Es),n(ot),n(ut),n(al),n(yt),n(pl),n(jt),n(rl)),n(t),h(d,s),h(g,s),Ss[T].d(s),Ys[k].d(s),h(H,s),Fs[x].d(s),h(F,s),h(D,s),h(K,s),h(O,s),h(ls,s),h(ts,s),h(X,s),h(ns,s),Ds[R].d(s),h(ps,s),h(Ms,s),h(is,s),h(V,s),h(us,s),h(js,s),h(Js,s),h(ws,s),h($s,s),h(Is,s),h(Zs,s),h(Qs,s),h(Bs,s),v.d(s),qs[N].d(s),h(Vs,s),h(Ws,s),h(zs,s),Ls[G].d(s),h(W,s),_&&_.d(s),h(Hs,s)}}}const Ke='{"title":"處理數據","local":"處理數據","sections":[{"title":"從模型中心（Hub）加載數據集","local":"從模型中心hub加載數據集","sections":[],"depth":3},{"title":"預處理數據集","local":"預處理數據集","sections":[],"depth":3},{"title":"動態填充","local":"動態填充","sections":[],"depth":3}],"depth":1}';function Oe(f,t,p){let e="pt";return ke(()=>{const i=new URLSearchParams(window.location.search);p(0,e=i.get("fw")||"pt")}),[e]}class Mn extends Ce{constructor(t){super(),xe(this,t,Oe,Pe,$e,{})}}export{Mn as component};
