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.4f5fc1ad.js";import{C as _e}from"../chunks/CourseFloatingBanner.06521e8b.js";import{F as Ze}from"../chunks/FrameworkSwitchCourse.8d4d4ab6.js";import{H as Ut,E as Ne}from"../chunks/EditOnGithub.8916dc7c.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 Qe(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 Ge(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-kt80ar"&&(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 Xe(f){let t,p='这一小节学习<a href="/course/chapter2">第一小节</a>中提到的“如何使用模型中心（hub）大型数据集”，下面是我们用模型中心的数据在PyTorch上训练句子分类器的一个例子：',e,i,d;return i=new w({props:{code:"aW1wb3J0JTIwdG9yY2glMEFmcm9tJTIwdHJhbnNmb3JtZXJzJTIwaW1wb3J0JTIwQWRhbVclMkMlMjBBdXRvVG9rZW5pemVyJTJDJTIwQXV0b01vZGVsRm9yU2VxdWVuY2VDbGFzc2lmaWNhdGlvbiUwQSUwQSUyMyUyMFNhbWUlMjBhcyUyMGJlZm9yZSUwQWNoZWNrcG9pbnQlMjAlM0QlMjAlMjJiZXJ0LWJhc2UtdW5jYXNlZCUyMiUwQXRva2VuaXplciUyMCUzRCUyMEF1dG9Ub2tlbml6ZXIuZnJvbV9wcmV0cmFpbmVkKGNoZWNrcG9pbnQpJTBBbW9kZWwlMjAlM0QlMjBBdXRvTW9kZWxGb3JTZXF1ZW5jZUNsYXNzaWZpY2F0aW9uLmZyb21fcHJldHJhaW5lZChjaGVja3BvaW50KSUwQXNlcXVlbmNlcyUyMCUzRCUyMCU1QiUwQSUyMCUyMCUyMCUyMCUyMkkndmUlMjBiZWVuJTIwd2FpdGluZyUyMGZvciUyMGElMjBIdWdnaW5nRmFjZSUyMGNvdXJzZSUyMG15JTIwd2hvbGUlMjBsaWZlLiUyMiUyQyUwQSUyMCUyMCUyMCUyMCUyMlRoaXMlMjBjb3Vyc2UlMjBpcyUyMGFtYXppbmchJTIyJTJDJTBBJTVEJTBBYmF0Y2glMjAlM0QlMjB0b2tlbml6ZXIoc2VxdWVuY2VzJTJDJTIwcGFkZGluZyUzRFRydWUlMkMlMjB0cnVuY2F0aW9uJTNEVHJ1ZSUyQyUyMHJldHVybl90ZW5zb3JzJTNEJTIycHQlMjIpJTBBJTBBJTIzJTIwVGhpcyUyMGlzJTIwbmV3JTBBYmF0Y2glNUIlMjJsYWJlbHMlMjIlNUQlMjAlM0QlMjB0b3JjaC50ZW5zb3IoJTVCMSUyQyUyMDElNUQpJTBBJTBBb3B0aW1pemVyJTIwJTNEJTIwQWRhbVcobW9kZWwucGFyYW1ldGVycygpKSUwQWxvc3MlMjAlM0QlMjBtb2RlbCgqKmJhdGNoKS5sb3NzJTBBbG9zcy5iYWNrd2FyZCgpJTBBb3B0aW1pemVyLnN0ZXAoKQ==",highlighted:`<span class="hljs-keyword">import</span> torch
<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AdamW, 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-1xtlyjh"&&(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;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 ve(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-1usx5xw"&&(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 ze(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 Ee(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-1ttnljt"&&(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-1cdpvhz"&&(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-alm93x"&&(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 De(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 Fe(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-or9ziy"&&(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-1m5uq1u"&&(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="就是这样！ 我们可以将这些数据集带入下一节，在经过所有艰苦的数据预处理工作之后，训练将变得非常简单。",X;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-1d9ldyd"&&(t.innerHTML=p),e=M(T),U(i.$$.fragment,T),d=M(T),c=j(T,"P",{"data-svelte-h":!0}),m(c)!=="svelte-cg0kxh"&&(c.textContent=g)},m(T,$){a(T,t,$),a(T,e,$),b(i,T,$),a(T,d,$),a(T,c,$),X=!0},i(T){X||(o(i.$$.fragment,T),X=!0)},o(T){u(i.$$.fragment,T),X=!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,X,T,$,Os,k,C,sl,z,$t="当然，仅仅用两句话训练模型不会产生很好的效果。为了获得更好的结果，您需要准备一个更大的数据集。",il,E,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,D,jl,F,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/datasets</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,v,_l,ns,$l,R,Z,tl,as,Qt='为了预处理数据集，我们需要将文本转换为模型能够理解的数字。正如你在<a href="/course/chapter2">第二章</a>上看到的那样',kl,ps,Cl,rs,Gt="然而，在两句话传递给模型，预测这两句话是否是同义之前。我们需要这两句话依次进行适当的预处理。幸运的是，标记器不仅仅可以输入单个句子还可以输入一组句子，并按照我们的BERT模型所期望的输入进行处理：",xl,Ms,Il,is,Rl,cs,Xt='我们在<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,Bt="如果我们将<strong>input_ids</strong>中的id转换回文字:",Al,us,Ql,ys,vt="我们将得到：",Gl,js,Xl,ms,Vt="所以我们看到模型需要输入的形式是 <strong>[CLS] sentence1 [SEP] sentence2 [SEP]</strong>。因此，当有两句话的时候。<strong>类型标记ID(token_type_ids)</strong> 的值是：",Bl,Js,vl,Us,Wt="如您所见，输入中 <strong>[CLS] sentence1 [SEP]</strong> 它们的类型标记ID均为<strong>0</strong>，而其他部分，对应于<strong>sentence2 [SEP]</strong>，所有的类型标记ID均为<strong>1</strong>.",Vl,bs,zt="请注意，如果选择其他的检查点，则不一定具有<strong>类型标记ID(token_type_ids)</strong>（例如，如果使用DistilBERT模型，就不会返回它们）。只有当它在预训练期间使用过这一层，模型在构建时依赖它们，才会返回它们。",Wl,hs,Et='用类型标记ID对BERT进行预训练,并且使用<a href="/course/chapter1">第一章</a>的遮罩语言模型，还有一个额外的应用类型，叫做下一句预测. 这项任务的目标是建立成对句子之间关系的模型。',zl,fs,Ht="在下一个句子预测任务中，会给模型输入成对的句子（带有随机遮罩的标记），并被要求预测第二个句子是否紧跟第一个句子。为了提高模型的泛化能力，数据集中一半的两个句子在原始文档中挨在一起，另一半的两个句子来自两个不同的文档。",El,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,Dt='这很有效，但它的缺点是返回字典（字典的键是<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>文件存储在磁盘上，因此您只需将接下来要用的数据加载在内存中，因此会对内存容量的需求要低一些）。',Dl,_s,Ft='为了将数据保存为数据集，我们将使用<a href="https://huggingface.co/docs/datasets/package_reference/main_classes#datasets.Dataset.map" rel="nofollow">Dataset.map()</a>方法，如果我们需要做更多的预处理而不仅仅是标记化，那么这也给了我们一些额外的自定义的方法。这个方法的工作原理是在数据集的每个元素上应用一个函数，因此让我们定义一个标记输入的函数：',Fl,$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,Qs,le="最后一件我们需要做的事情是，当我们一起批处理元素时，将所有示例填充到最长元素的长度——我们称之为动态填充。",nt,Gs,at,Xs,pt,el,Bs,te="为了解决句子长度统一的问题，我们必须定义一个collate函数，该函数会将每个batch句子填充到正确的长度。幸运的是，🤗transformer库通过<strong>DataCollatorWithPadding</strong>为我们提供了这样一个函数。当你实例化它时，需要一个标记器(用来知道使用哪个词来填充，以及模型期望填充在左边还是右边)，并将做你需要的一切:",rt,N,A,nl,vs,ee="为了测试这个新玩具，让我们从我们的训练集中抽取几个样本。这里，我们删除列<strong>idx</strong>, <strong>sentence1</strong>和<strong>sentence2</strong>，因为不需要它们，并查看一个batch中每个条目的长度:",Mt,Vs,it,Ws,ct,zs,ne="毫无疑问，我们得到了不同长度的样本，从32到67。动态填充意味着该批中的所有样本都应该填充到长度为67，这是该批中的最大长度。如果没有动态填充，所有的样本都必须填充到整个数据集中的最大长度，或者模型可以接受的最大长度。让我们再次检查<strong>data_collator</strong>是否正确地动态填充了这批样本：",ot,Es,ut,Q,G,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=[Qe,Ae],Ss=[];function pe(s,l){return s[0]==="pt"?0:1}T=pe(f),$=Ss[T]=ae[T](f);const re=[Xe,Ge],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=[ve,Be],Ds=[];function ce(s,l){return s[0]==="pt"?0:1}x=ce(f),I=Ds[x]=ie[x](f),D=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}}),F=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}}),v=new gt({props:{$$slots:{default:[Ve]},$$scope:{ctx:f}}}),ns=new Ut({props:{title:"预处理数据集",local:"预处理数据集",headingTag:"h3"}});const oe=[ze,We],Fs=[];function ue(s,l){return s[0]==="pt"?0:1}R=ue(f),Z=Fs[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:[Ee]},$$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}}),Gs=new Ut({props:{title:"动态填充",local:"动态填充",headingTag:"h3"}}),Xs=new Ml({props:{id:"7q5NyFT8REg"}});function ye(s,l){return s[0]==="pt"?Se:He}let Jt=ye(f),B=Jt(f);const je=[De,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}}),Es=new w({props:{code:"YmF0Y2glMjAlM0QlMjBkYXRhX2NvbGxhdG9yKHNhbXBsZXMpJTBBJTdCayUzQSUyMHYuc2hhcGUlMjBmb3IlMjBrJTJDJTIwdiUyMGluJTIwYmF0Y2guaXRlbXMoKSU3RA==",highlighted:`batch = data_collator(samples)
{k: v.shape <span class="hljs-keyword">for</span> k, v <span class="hljs-keyword">in</span> batch.items()}`,wrap:!1}});const Je=[qe,Fe],Ls=[];function Ue(s,l){return s[0]==="tf"?0:1}Q=Ue(f),G=Ls[Q]=Je[Q](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-CN/chapter3/2.mdx"}}),{c(){t=y("meta"),p=r(),e=y("p"),i=r(),J(d.$$.fragment),c=r(),J(g.$$.fragment),X=r(),$.c(),Os=r(),C.c(),sl=r(),z=y("p"),z.textContent=$t,il=r(),E=y("p"),E.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(D.$$.fragment),jl=r(),J(F.$$.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(v.$$.fragment),_l=r(),J(ns.$$.fragment),$l=r(),Z.c(),tl=r(),as=y("p"),as.innerHTML=Qt,kl=r(),J(ps.$$.fragment),Cl=r(),rs=y("p"),rs.textContent=Gt,xl=r(),J(Ms.$$.fragment),Il=r(),J(is.$$.fragment),Rl=r(),cs=y("p"),cs.innerHTML=Xt,Zl=r(),J(V.$$.fragment),Nl=r(),os=y("p"),os.innerHTML=Bt,Al=r(),J(us.$$.fragment),Ql=r(),ys=y("p"),ys.textContent=vt,Gl=r(),J(js.$$.fragment),Xl=r(),ms=y("p"),ms.innerHTML=Vt,Bl=r(),J(Js.$$.fragment),vl=r(),Us=y("p"),Us.innerHTML=Wt,Vl=r(),bs=y("p"),bs.innerHTML=zt,Wl=r(),hs=y("p"),hs.innerHTML=Et,zl=r(),fs=y("p"),fs.textContent=Ht,El=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=Dt,Dl=r(),_s=y("p"),_s.innerHTML=Ft,Fl=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(),Qs=y("p"),Qs.textContent=le,nt=r(),J(Gs.$$.fragment),at=r(),J(Xs.$$.fragment),pt=r(),B.c(),el=r(),Bs=y("p"),Bs.innerHTML=te,rt=r(),A.c(),nl=r(),vs=y("p"),vs.innerHTML=ee,Mt=r(),J(Vs.$$.fragment),it=r(),J(Ws.$$.fragment),ct=r(),zs=y("p"),zs.innerHTML=ne,ot=r(),J(Es.$$.fragment),ut=r(),G.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),X=M(s),$.l(s),Os=M(s),C.l(s),sl=M(s),z=j(s,"P",{"data-svelte-h":!0}),m(z)!=="svelte-drmjm8"&&(z.textContent=$t),il=M(s),E=j(s,"P",{"data-svelte-h":!0}),m(E)!=="svelte-fe15wv"&&(E.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-ncgqns"&&(S.innerHTML=Ct),ul=M(s),Y=j(s,"P",{"data-svelte-h":!0}),m(Y)!=="svelte-r34sn4"&&(Y.textContent=xt),yl=M(s),U(D.$$.fragment,s),jl=M(s),U(F.$$.fragment,s),ml=M(s),q=j(s,"P",{"data-svelte-h":!0}),m(q)!=="svelte-1oj59g2"&&(q.innerHTML=It),Jl=M(s),L=j(s,"P",{"data-svelte-h":!0}),m(L)!=="svelte-pv8csc"&&(L.innerHTML=Rt),Ul=M(s),P=j(s,"P",{"data-svelte-h":!0}),m(P)!=="svelte-15kj1js"&&(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-19kpezu"&&(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-ocxmcv"&&(es.innerHTML=At),gl=M(s),U(v.$$.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-2tqoru"&&(as.innerHTML=Qt),kl=M(s),U(ps.$$.fragment,s),Cl=M(s),rs=j(s,"P",{"data-svelte-h":!0}),m(rs)!=="svelte-ofjmes"&&(rs.textContent=Gt),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-10bulny"&&(cs.innerHTML=Xt),Zl=M(s),U(V.$$.fragment,s),Nl=M(s),os=j(s,"P",{"data-svelte-h":!0}),m(os)!=="svelte-1quodij"&&(os.innerHTML=Bt),Al=M(s),U(us.$$.fragment,s),Ql=M(s),ys=j(s,"P",{"data-svelte-h":!0}),m(ys)!=="svelte-gglnbk"&&(ys.textContent=vt),Gl=M(s),U(js.$$.fragment,s),Xl=M(s),ms=j(s,"P",{"data-svelte-h":!0}),m(ms)!=="svelte-1s11yzb"&&(ms.innerHTML=Vt),Bl=M(s),U(Js.$$.fragment,s),vl=M(s),Us=j(s,"P",{"data-svelte-h":!0}),m(Us)!=="svelte-1y7jnff"&&(Us.innerHTML=Wt),Vl=M(s),bs=j(s,"P",{"data-svelte-h":!0}),m(bs)!=="svelte-1xi026e"&&(bs.innerHTML=zt),Wl=M(s),hs=j(s,"P",{"data-svelte-h":!0}),m(hs)!=="svelte-tbu9c"&&(hs.innerHTML=Et),zl=M(s),fs=j(s,"P",{"data-svelte-h":!0}),m(fs)!=="svelte-1d9jis2"&&(fs.textContent=Ht),El=M(s),Ts=j(s,"P",{"data-svelte-h":!0}),m(Ts)!=="svelte-1786w2"&&(Ts.innerHTML=St),Hl=M(s),ds=j(s,"P",{"data-svelte-h":!0}),m(ds)!=="svelte-1xli505"&&(ds.innerHTML=Yt),Sl=M(s),U(ws.$$.fragment,s),Yl=M(s),gs=j(s,"P",{"data-svelte-h":!0}),m(gs)!=="svelte-58c7jq"&&(gs.innerHTML=Dt),Dl=M(s),_s=j(s,"P",{"data-svelte-h":!0}),m(_s)!=="svelte-16yej49"&&(_s.innerHTML=Ft),Fl=M(s),U($s.$$.fragment,s),ql=M(s),ks=j(s,"P",{"data-svelte-h":!0}),m(ks)!=="svelte-1xl7vlo"&&(ks.innerHTML=qt),Ll=M(s),Cs=j(s,"P",{"data-svelte-h":!0}),m(Cs)!=="svelte-1yzpwga"&&(Cs.innerHTML=Lt),Pl=M(s),xs=j(s,"P",{"data-svelte-h":!0}),m(xs)!=="svelte-7yhdfb"&&(xs.innerHTML=Pt),Kl=M(s),U(Is.$$.fragment,s),Ol=M(s),Rs=j(s,"P",{"data-svelte-h":!0}),m(Rs)!=="svelte-hz2h68"&&(Rs.textContent=Kt),st=M(s),U(Zs.$$.fragment,s),lt=M(s),Ns=j(s,"P",{"data-svelte-h":!0}),m(Ns)!=="svelte-xoe8xo"&&(Ns.innerHTML=Ot),tt=M(s),As=j(s,"P",{"data-svelte-h":!0}),m(As)!=="svelte-sz4bn"&&(As.innerHTML=se),et=M(s),Qs=j(s,"P",{"data-svelte-h":!0}),m(Qs)!=="svelte-5ri5dk"&&(Qs.textContent=le),nt=M(s),U(Gs.$$.fragment,s),at=M(s),U(Xs.$$.fragment,s),pt=M(s),B.l(s),el=M(s),Bs=j(s,"P",{"data-svelte-h":!0}),m(Bs)!=="svelte-10043jj"&&(Bs.innerHTML=te),rt=M(s),A.l(s),nl=M(s),vs=j(s,"P",{"data-svelte-h":!0}),m(vs)!=="svelte-1f78lmo"&&(vs.innerHTML=ee),Mt=M(s),U(Vs.$$.fragment,s),it=M(s),U(Ws.$$.fragment,s),ct=M(s),zs=j(s,"P",{"data-svelte-h":!0}),m(zs)!=="svelte-6un5b7"&&(zs.innerHTML=ne),ot=M(s),U(Es.$$.fragment,s),ut=M(s),G.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,X,l),Ss[T].m(s,l),a(s,Os,l),Ys[k].m(s,l),a(s,sl,l),a(s,z,l),a(s,il,l),a(s,E,l),a(s,cl,l),b(H,s,l),a(s,ol,l),Ds[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(D,s,l),a(s,jl,l),b(F,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(v,s,l),a(s,_l,l),b(ns,s,l),a(s,$l,l),Fs[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,Ql,l),a(s,ys,l),a(s,Gl,l),b(js,s,l),a(s,Xl,l),a(s,ms,l),a(s,Bl,l),b(Js,s,l),a(s,vl,l),a(s,Us,l),a(s,Vl,l),a(s,bs,l),a(s,Wl,l),a(s,hs,l),a(s,zl,l),a(s,fs,l),a(s,El,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,Dl,l),a(s,_s,l),a(s,Fl,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,Qs,l),a(s,nt,l),b(Gs,s,l),a(s,at,l),b(Xs,s,l),a(s,pt,l),B.m(s,l),a(s,el,l),a(s,Bs,l),a(s,rt,l),qs[N].m(s,l),a(s,nl,l),a(s,vs,l),a(s,Mt,l),b(Vs,s,l),a(s,it,l),b(Ws,s,l),a(s,ct,l),a(s,zs,l),a(s,ot,l),b(Es,s,l),a(s,ut,l),Ls[Q].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(Ds[ft],1,1,()=>{Ds[ft]=null}),Ps(),I=Ds[x],I||(I=Ds[x]=ie[x](s),I.c()),o(I,1),I.m(ll.parentNode,ll));const he={};l&2&&(he.$$scope={dirty:l,ctx:s}),v.$set(he);let Tt=R;R=ue(s),R!==Tt&&(Ks(),u(Fs[Tt],1,1,()=>{Fs[Tt]=null}),Ps(),Z=Fs[R],Z||(Z=Fs[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))&&(B.d(1),B=Jt(s),B&&(B.c(),B.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=Q;Q=Ue(s),Q!==wt&&(Ks(),u(Ls[wt],1,1,()=>{Ls[wt]=null}),Ps(),G=Ls[Q],G||(G=Ls[Q]=Je[Q](s),G.c()),o(G,1),G.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(D.$$.fragment,s),o(F.$$.fragment,s),o(K.$$.fragment,s),o(O.$$.fragment,s),o(ls.$$.fragment,s),o(ts.$$.fragment,s),o(v.$$.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(Gs.$$.fragment,s),o(Xs.$$.fragment,s),o(A),o(Vs.$$.fragment,s),o(Ws.$$.fragment,s),o(Es.$$.fragment,s),o(G),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(D.$$.fragment,s),u(F.$$.fragment,s),u(K.$$.fragment,s),u(O.$$.fragment,s),u(ls.$$.fragment,s),u(ts.$$.fragment,s),u(v.$$.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(Gs.$$.fragment,s),u(Xs.$$.fragment,s),u(A),u(Vs.$$.fragment,s),u(Ws.$$.fragment,s),u(Es.$$.fragment,s),u(G),u(W.$$.fragment,s),u(_),u(Hs.$$.fragment,s),mt=!1},d(s){s&&(n(p),n(e),n(i),n(c),n(X),n(Os),n(sl),n(z),n(il),n(E),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(Ql),n(ys),n(Gl),n(Xl),n(ms),n(Bl),n(vl),n(Us),n(Vl),n(bs),n(Wl),n(hs),n(zl),n(fs),n(El),n(Ts),n(Hl),n(ds),n(Sl),n(Yl),n(gs),n(Dl),n(_s),n(Fl),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(Qs),n(nt),n(at),n(pt),n(el),n(Bs),n(rt),n(nl),n(vs),n(Mt),n(it),n(ct),n(zs),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),Ds[x].d(s),h(D,s),h(F,s),h(K,s),h(O,s),h(ls,s),h(ts,s),h(v,s),h(ns,s),Fs[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(Gs,s),h(Xs,s),B.d(s),qs[N].d(s),h(Vs,s),h(Ws,s),h(Es,s),Ls[Q].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};
