import{s as yM,f as JM,o as cM,n as tl}from"../chunks/scheduler.37c15a92.js";import{S as TM,i as oM,g as y,s as t,r as c,m as aM,H as eM,A as wM,h as J,f as l,c as n,j as ne,u as T,x as U,n as tM,E as nM,k as xs,y as qt,a,v as o,t as i,b as Oa,d as m,w,p as se}from"../chunks/index.2bf4358c.js";import{T as el}from"../chunks/Tip.363c041f.js";import{Y as Kt}from"../chunks/Youtube.1e50a667.js";import{C as d}from"../chunks/CodeBlock.4f5fc1ad.js";import{D as rM}from"../chunks/DocNotebookDropdown.d9dfeb24.js";import{F as UM}from"../chunks/FrameworkSwitchCourse.8d4d4ab6.js";import{H as Is,E as jM}from"../chunks/EditOnGithub.8916dc7c.js";function hM(G){let p,u;return p=new rM({props:{classNames:"absolute z-10 right-0 top-0",options:[{label:"Google Colab",value:"https://colab.research.google.com/github/huggingface/notebooks/blob/master/course/chapter7/section5_tf.ipynb"},{label:"Aws Studio",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/master/course/chapter7/section5_tf.ipynb"}]}}),{c(){c(p.$$.fragment)},l(r){T(p.$$.fragment,r)},m(r,f){o(p,r,f),u=!0},i(r){u||(m(p.$$.fragment,r),u=!0)},o(r){i(p.$$.fragment,r),u=!1},d(r){w(p,r)}}}function dM(G){let p,u;return p=new rM({props:{classNames:"absolute z-10 right-0 top-0",options:[{label:"Google Colab",value:"https://colab.research.google.com/github/huggingface/notebooks/blob/master/course/chapter7/section5_pt.ipynb"},{label:"Aws Studio",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/master/course/chapter7/section5_pt.ipynb"}]}}),{c(){c(p.$$.fragment)},l(r){T(p.$$.fragment,r)},m(r,f){o(p,r,f),u=!0},i(r){u||(m(p.$$.fragment,r),u=!0)},o(r){i(p.$$.fragment,r),u=!1},d(r){w(p,r)}}}function uM(G){let p,u="✏️ <strong>试试看！</strong> 更改 <code>Dataset.shuffle()</code> 命令中的随机种子以探索语料库中的其他评论。 如果您是说西班牙语的人，请查看 <code>spanish_dataset</code> 中的一些评论，看看标题是否也像合理的摘要。";return{c(){p=y("p"),p.innerHTML=u},l(r){p=J(r,"P",{"data-svelte-h":!0}),U(p)!=="svelte-fw7qp9"&&(p.innerHTML=u)},m(r,f){a(r,p,f)},p:tl,d(r){r&&l(p)}}}function bM(G){let p,u="✏️ <strong>试试看！</strong> 完成本节后，通过使用相同的技术对 mBART 进行微调，看看 mT5 与 mBART 相比有多好。 对于奖励积分，您还可以尝试仅在英文评论上微调 T5。 由于 T5 需要一个特殊的前缀提示，因此您需要在下面的预处理步骤中将“summarize:”添加到输入示例中。";return{c(){p=y("p"),p.innerHTML=u},l(r){p=J(r,"P",{"data-svelte-h":!0}),U(p)!=="svelte-7sstiz"&&(p.innerHTML=u)},m(r,f){a(r,p,f)},p:tl,d(r){r&&l(p)}}}function IM(G){let p,u="💡在 NLP 项目的早期阶段，一个好的做法是在小样本数据上训练一类“小”模型。这使您可以更快地调试和迭代端到端工作流。一旦您对结果充满信心，您始终可以通过简单地更改模型检查点来在大规模数据上训练模型！";return{c(){p=y("p"),p.textContent=u},l(r){p=J(r,"P",{"data-svelte-h":!0}),U(p)!=="svelte-rii2gd"&&(p.textContent=u)},m(r,f){a(r,p,f)},p:tl,d(r){r&&l(p)}}}function fM(G){let p,u="💡 你可能已经注意到我们在上面的 <code>Dataset.map()</code> 函数中使用了 <code>batched=True</code>。 这会以 1,000 个（默认）为单位对示例进行编码，并允许您利用 🤗 Transformers 中快速标记器的多线程功能。 在可能的情况下，尝试使用 <code>batched=True</code> 来加速您的预处理！";return{c(){p=y("p"),p.innerHTML=u},l(r){p=J(r,"P",{"data-svelte-h":!0}),U(p)!=="svelte-1caf8iy"&&(p.innerHTML=u)},m(r,f){a(r,p,f)},p:tl,d(r){r&&l(p)}}}function CM(G){let p,u='🙋 如果这是您第一次听说精确率和召回率，请不要担心——我们将一起通过一些明确的示例来说明一切。 这些指标通常在分类任务中遇到，因此如果您想了解在该上下文中如何定义精确度和召回率，我们建议查看 scikit-learn [指南](<a href="https://scikit-learn.org/stable" rel="nofollow">https://scikit-learn.org/stable</a> /auto_examples/model_selection/plot_precision_recall.html）。';return{c(){p=y("p"),p.innerHTML=u},l(r){p=J(r,"P",{"data-svelte-h":!0}),U(p)!=="svelte-fumf55"&&(p.innerHTML=u)},m(r,f){a(r,p,f)},p:tl,d(r){r&&l(p)}}}function gM(G){let p,u="✏️ <strong>试试看！</strong> 创建您自己的生成和参考摘要示例，并查看生成的 ROUGE 分数是否与基于精确度和召回率公式的手动计算一致。 对于附加分，将文本拆分为二元组并比较“rouge2”指标的精度和召回率。";return{c(){p=y("p"),p.innerHTML=u},l(r){p=J(r,"P",{"data-svelte-h":!0}),U(p)!=="svelte-u8s20w"&&(p.innerHTML=u)},m(r,f){a(r,p,f)},p:tl,d(r){r&&l(p)}}}function ZM(G){let p,u,r,f="微调模型以进行提取摘要与我们在本章中介绍的其他任务非常相似。 我们需要做的第一件事是从<code>mt5-small</code>检查点加载预训练模型。 由于摘要提取是一个序列到序列的任务，我们可以使用 <code>TFAutoModelForSeq2SeqLM</code> 类加载模型，该类会自动下载并缓存权重：",k,g,W;return p=new Is({props:{title:"使用 Keras API微调mT5",local:"使用 Keras API微调mT5",headingTag:"h2"}}),g=new d({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMFRGQXV0b01vZGVsRm9yU2VxMlNlcUxNJTBBJTBBbW9kZWwlMjAlM0QlMjBURkF1dG9Nb2RlbEZvclNlcTJTZXFMTS5mcm9tX3ByZXRyYWluZWQobW9kZWxfY2hlY2twb2ludCk=",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> TFAutoModelForSeq2SeqLM

model = TFAutoModelForSeq2SeqLM.from_pretrained(model_checkpoint)`,wrap:!1}}),{c(){c(p.$$.fragment),u=t(),r=y("p"),r.innerHTML=f,k=t(),c(g.$$.fragment)},l(I){T(p.$$.fragment,I),u=n(I),r=J(I,"P",{"data-svelte-h":!0}),U(r)!=="svelte-1aljj75"&&(r.innerHTML=f),k=n(I),T(g.$$.fragment,I)},m(I,Z){o(p,I,Z),a(I,u,Z),a(I,r,Z),a(I,k,Z),o(g,I,Z),W=!0},i(I){W||(m(p.$$.fragment,I),m(g.$$.fragment,I),W=!0)},o(I){i(p.$$.fragment,I),i(g.$$.fragment,I),W=!1},d(I){I&&(l(u),l(r),l(k)),w(p,I),w(g,I)}}}function GM(G){let p,u,r,f="微调模型以进行提取摘要与我们在本章中介绍的其他任务非常相似。 我们需要做的第一件事是从<code>mt5-small</code>检查点加载预训练模型。 由于摘要提取是一个序列到序列的任务，我们可以使用 AutoModelForSeq2SeqLM 类加载模型，该类会自动下载并缓存权重：",k,g,W;return p=new Is({props:{title:"使用 Trainer API微调mT5",local:"使用 Trainer API微调mT5",headingTag:"h2"}}),g=new d({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9Nb2RlbEZvclNlcTJTZXFMTSUwQSUwQW1vZGVsJTIwJTNEJTIwQXV0b01vZGVsRm9yU2VxMlNlcUxNLmZyb21fcHJldHJhaW5lZChtb2RlbF9jaGVja3BvaW50KQ==",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoModelForSeq2SeqLM

model = AutoModelForSeq2SeqLM.from_pretrained(model_checkpoint)`,wrap:!1}}),{c(){c(p.$$.fragment),u=t(),r=y("p"),r.innerHTML=f,k=t(),c(g.$$.fragment)},l(I){T(p.$$.fragment,I),u=n(I),r=J(I,"P",{"data-svelte-h":!0}),U(r)!=="svelte-g79k48"&&(r.innerHTML=f),k=n(I),T(g.$$.fragment,I)},m(I,Z){o(p,I,Z),a(I,u,Z),a(I,r,Z),a(I,k,Z),o(g,I,Z),W=!0},i(I){W||(m(p.$$.fragment,I),m(g.$$.fragment,I),W=!0)},o(I){i(p.$$.fragment,I),i(g.$$.fragment,I),W=!1},d(I){I&&(l(u),l(r),l(k)),w(p,I),w(g,I)}}}function kM(G){let p,u=`💡 If you’re wondering why you don’t see any warnings about fine-tuning the model on a downstream task, that’s because for sequence-to-sequence tasks we keep all the weights of the network. Compare this to our text classification model in <a href="/course/chapter3">Chapter 3</a>, where the head of the pretrained model was replaced with a randomly initialized network.
💡 如果您想知道为什么在下游任务中没有看到任何关于微调模型的警告，那是因为对于序列到序列的任务，我们保留了网络的所有权重。与我们在[第三章] (/course/chapter3)中的文本分类模型进行比较，文本分类模型预训练模型的头部被随机初始化的网络替换。`;return{c(){p=y("p"),p.innerHTML=u},l(r){p=J(r,"P",{"data-svelte-h":!0}),U(p)!=="svelte-18mpd72"&&(p.innerHTML=u)},m(r,f){a(r,p,f)},p:tl,d(r){r&&l(p)}}}function MM(G){let p,u="我们需要生成摘要以便在训练期间计算 ROUGE 分数。幸运的是，🤗 Transformers 提供了专用的 <code>Seq2SeqTrainingArguments</code> 和 <code>Seq2SeqTrainer</code> 类，可以自动为我们完成这项工作！ 为了了解它是如何工作的，让我们首先为我们的实验定义超参数和其他参数：",r,f,k,g,W='在这里， <strong>predict_with_generate</strong> 参数已设置为True表明我们应该在评估期间生成摘要，以便我们可以计算每个时期的 ROUGE 分数。正如在<a href="/course/chapter1">第一章</a>所讨论的，解码器通过逐个预测令牌来执行推理，这是由模型的 <strong>generate()</strong> 方法实现的。设置 <strong>predict_with_generate=True</strong> 告诉 <strong>Seq2SeqTrainer</strong> 使用该方法进行评估。我们还调整了一些默认的超参数，例如学习率、epoch数和权重衰减，并且我们设置了 <strong>save_total_limit</strong> 训练期间最多只保存 3 个检查点的选项——这是因为即使是 mT5 的“small”版本也使用大约 1 GB 的硬盘空间，我们可以通过限制我们保存的副本数量来节省一点空间。',I,Z,R='<code>push_to_hub=True</code> 参数将允许我们在训练后将模型推送到 Hub； 您将在<code>output_dir</code>定义的位置中的用户配置文件下找到存储库。 请注意，您可以使用 <code>hub_model_id</code> 参数指定要推送到的存储库的名称（特别是当您想要推送到组织时，您必须使用此参数）。 例如，当我们将模型推送到 <a href="https://huggingface.co/huggingface-course" rel="nofollow"><code>huggingface-course</code> 组织</a> 时，我们添加了<code>hub_model_id=&quot;huggingface-course/mt5-finetuned-amazon-en-es&quot;</code> 到 <code>Seq2SeqTrainingArguments</code>。',B,z,E="我们需要做的下一件事是为训练器提供一个“compute_metrics()”函数，以便我们可以在训练期间评估我们的模型。 总结起来，这比简单地在模型的预测上调用 <code>rouge_score.compute()</code> 更复杂一些，因为我们需要在计算 ROUGE 分数之前将输出和标签解码为文本。 下面的函数正是这样做的，并且还利用 <code>nltk</code> 中的 <code>sent_tokenize()</code> 函数来用换行符分隔摘要语句：",N,_,x;return f=new d({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMFNlcTJTZXFUcmFpbmluZ0FyZ3VtZW50cyUwQSUwQWJhdGNoX3NpemUlMjAlM0QlMjA4JTBBbnVtX3RyYWluX2Vwb2NocyUyMCUzRCUyMDglMEElMjMlMjBTaG93JTIwdGhlJTIwdHJhaW5pbmclMjBsb3NzJTIwd2l0aCUyMGV2ZXJ5JTIwZXBvY2glMEFsb2dnaW5nX3N0ZXBzJTIwJTNEJTIwbGVuKHRva2VuaXplZF9kYXRhc2V0cyU1QiUyMnRyYWluJTIyJTVEKSUyMCUyRiUyRiUyMGJhdGNoX3NpemUlMEFtb2RlbF9uYW1lJTIwJTNEJTIwbW9kZWxfY2hlY2twb2ludC5zcGxpdCglMjIlMkYlMjIpJTVCLTElNUQlMEElMEFhcmdzJTIwJTNEJTIwU2VxMlNlcVRyYWluaW5nQXJndW1lbnRzKCUwQSUyMCUyMCUyMCUyMG91dHB1dF9kaXIlM0RmJTIyJTdCbW9kZWxfbmFtZSU3RC1maW5ldHVuZWQtYW1hem9uLWVuLWVzJTIyJTJDJTBBJTIwJTIwJTIwJTIwZXZhbHVhdGlvbl9zdHJhdGVneSUzRCUyMmVwb2NoJTIyJTJDJTBBJTIwJTIwJTIwJTIwbGVhcm5pbmdfcmF0ZSUzRDUuNmUtNSUyQyUwQSUyMCUyMCUyMCUyMHBlcl9kZXZpY2VfdHJhaW5fYmF0Y2hfc2l6ZSUzRGJhdGNoX3NpemUlMkMlMEElMjAlMjAlMjAlMjBwZXJfZGV2aWNlX2V2YWxfYmF0Y2hfc2l6ZSUzRGJhdGNoX3NpemUlMkMlMEElMjAlMjAlMjAlMjB3ZWlnaHRfZGVjYXklM0QwLjAxJTJDJTBBJTIwJTIwJTIwJTIwc2F2ZV90b3RhbF9saW1pdCUzRDMlMkMlMEElMjAlMjAlMjAlMjBudW1fdHJhaW5fZXBvY2hzJTNEbnVtX3RyYWluX2Vwb2NocyUyQyUwQSUyMCUyMCUyMCUyMHByZWRpY3Rfd2l0aF9nZW5lcmF0ZSUzRFRydWUlMkMlMEElMjAlMjAlMjAlMjBsb2dnaW5nX3N0ZXBzJTNEbG9nZ2luZ19zdGVwcyUyQyUwQSUyMCUyMCUyMCUyMHB1c2hfdG9faHViJTNEVHJ1ZSUyQyUwQSk=",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> Seq2SeqTrainingArguments

batch_size = <span class="hljs-number">8</span>
num_train_epochs = <span class="hljs-number">8</span>
<span class="hljs-comment"># Show the training loss with every epoch</span>
logging_steps = <span class="hljs-built_in">len</span>(tokenized_datasets[<span class="hljs-string">&quot;train&quot;</span>]) // batch_size
model_name = model_checkpoint.split(<span class="hljs-string">&quot;/&quot;</span>)[-<span class="hljs-number">1</span>]

args = Seq2SeqTrainingArguments(
    output_dir=<span class="hljs-string">f&quot;<span class="hljs-subst">{model_name}</span>-finetuned-amazon-en-es&quot;</span>,
    evaluation_strategy=<span class="hljs-string">&quot;epoch&quot;</span>,
    learning_rate=<span class="hljs-number">5.6e-5</span>,
    per_device_train_batch_size=batch_size,
    per_device_eval_batch_size=batch_size,
    weight_decay=<span class="hljs-number">0.01</span>,
    save_total_limit=<span class="hljs-number">3</span>,
    num_train_epochs=num_train_epochs,
    predict_with_generate=<span class="hljs-literal">True</span>,
    logging_steps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kcyUyMCUzRCUyMCU1QiUyMiU1Q24lMjIuam9pbihzZW50X3Rva2VuaXplKHByZWQuc3RyaXAoKSkpJTIwZm9yJTIwcHJlZCUyMGluJTIwZGVjb2RlZF9wcmVkcyU1RCUwQSUyMCUyMCUyMCUyMGRlY29kZWRfbGFiZWxzJTIwJTNEJTIwJTVCJTIyJTVDbiUyMi5qb2luKHNlbnRfdG9rZW5pemUobGFiZWwuc3RyaXAoKSkpJTIwZm9yJTIwbGFiZWwlMjBpbiUyMGRlY29kZWRfbGFiZWxzJTVEJTBBJTIwJTIwJTIwJTIwJTIzJTIwQ29tcHV0ZSUyMFJPVUdFJTIwc2NvcmVzJTBBJTIwJTIwJTIwJTIwcmVzdWx0JTIwJTNEJTIwcm91Z2Vfc2NvcmUuY29tcHV0ZSglMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBwcmVkaWN0aW9ucyUzRGRlY29kZWRfcHJlZHMlMkMlMjByZWZlcmVuY2VzJTNEZGVjb2RlZF9sYWJlbHMlMkMlMjB1c2Vfc3RlbW1lciUzRFRydWUlMEElMjAlMjAlMjAlMjApJTBBJTIwJTIwJTIwJTIwJTIzJTIwRXh0cmFjdCUyMHRoZSUyMG1lZGlhbiUyMHNjb3JlcyUwQSUyMCUyMCUyMCUyMHJlc3VsdCUyMCUzRCUyMCU3QmtleSUzQSUyMHZhbHVlLm1pZC5mbWVhc3VyZSUyMColMjAxMDAlMjBmb3IlMjBrZXklMkMlMjB2YWx1ZSUyMGluJTIwcmVzdWx0Lml0ZW1zKCklN0QlMEElMjAlMjAlMjAlMjByZXR1cm4lMjAlN0JrJTNBJTIwcm91bmQodiUyQyUyMDQpJTIwZm9yJTIwayUyQyUyMHYlMjBpbiUyMHJlc3VsdC5pdGVtcygpJTdE",highlighted:`<span class="hljs-keyword">import</span> numpy <span class="hljs-keyword">as</span> np


<span class="hljs-keyword">def</span> <span class="hljs-title function_">compute_metrics</span>(<span class="hljs-params">eval_pred</span>):
    predictions, labels = eval_pred
    <span class="hljs-comment"># Decode generated summaries into text</span>
    decoded_preds = tokenizer.batch_decode(predictions, skip_special_tokens=<span class="hljs-literal">True</span>)
    <span class="hljs-comment"># Replace -100 in the labels as we can&#x27;t decode them</span>
    labels = np.where(labels != -<span class="hljs-number">100</span>, labels, tokenizer.pad_token_id)
    <span class="hljs-comment"># Decode reference summaries into text</span>
    decoded_labels = tokenizer.batch_decode(labels, skip_special_tokens=<span class="hljs-literal">True</span>)
    <span class="hljs-comment"># ROUGE expects a newline after each sentence</span>
    decoded_preds = [<span class="hljs-string">&quot;\\n&quot;</span>.join(sent_tokenize(pred.strip())) <span class="hljs-keyword">for</span> pred <span class="hljs-keyword">in</span> decoded_preds]
    decoded_labels = [<span class="hljs-string">&quot;\\n&quot;</span>.join(sent_tokenize(label.strip())) <span class="hljs-keyword">for</span> label <span class="hljs-keyword">in</span> decoded_labels]
    <span class="hljs-comment"># Compute ROUGE scores</span>
    result = rouge_score.compute(
        predictions=decoded_preds, references=decoded_labels, use_stemmer=<span class="hljs-literal">True</span>
    )
    <span class="hljs-comment"># Extract the median scores</span>
    result = {key: value.mid.fmeasure * <span class="hljs-number">100</span> <span class="hljs-keyword">for</span> key, value <span class="hljs-keyword">in</span> result.items()}
    <span class="hljs-keyword">return</span> {k: <span class="hljs-built_in">round</span>(v, <span class="hljs-number">4</span>) <span class="hljs-keyword">for</span> k, v <span class="hljs-keyword">in</span> result.items()}`,wrap:!1}}),{c(){p=y("p"),p.innerHTML=u,r=t(),c(f.$$.fragment),k=t(),g=y("p"),g.innerHTML=W,I=t(),Z=y("p"),Z.innerHTML=R,B=t(),z=y("p"),z.innerHTML=E,N=t(),c(_.$$.fragment)},l(C){p=J(C,"P",{"data-svelte-h":!0}),U(p)!=="svelte-9kgdsq"&&(p.innerHTML=u),r=n(C),T(f.$$.fragment,C),k=n(C),g=J(C,"P",{"data-svelte-h":!0}),U(g)!=="svelte-mz6sng"&&(g.innerHTML=W),I=n(C),Z=J(C,"P",{"data-svelte-h":!0}),U(Z)!=="svelte-1hd5i5i"&&(Z.innerHTML=R),B=n(C),z=J(C,"P",{"data-svelte-h":!0}),U(z)!=="svelte-18rqbg3"&&(z.innerHTML=E),N=n(C),T(_.$$.fragment,C)},m(C,v){a(C,p,v),a(C,r,v),o(f,C,v),a(C,k,v),a(C,g,v),a(C,I,v),a(C,Z,v),a(C,B,v),a(C,z,v),a(C,N,v),o(_,C,v),x=!0},i(C){x||(m(f.$$.fragment,C),m(_.$$.fragment,C),x=!0)},o(C){i(f.$$.fragment,C),i(_.$$.fragment,C),x=!1},d(C){C&&(l(p),l(r),l(k),l(g),l(I),l(Z),l(B),l(z),l(N)),w(f,C),w(_,C)}}}function BM(G){let p,u;return p=new d({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMERhdGFDb2xsYXRvckZvclNlcTJTZXElMEElMEFkYXRhX2NvbGxhdG9yJTIwJTNEJTIwRGF0YUNvbGxhdG9yRm9yU2VxMlNlcSh0b2tlbml6ZXIlMkMlMjBtb2RlbCUzRG1vZGVsJTJDJTIwcmV0dXJuX3RlbnNvcnMlM0QlMjJ0ZiUyMik=",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> DataCollatorForSeq2Seq

data_collator = DataCollatorForSeq2Seq(tokenizer, model=model, return_tensors=<span class="hljs-string">&quot;tf&quot;</span>)`,wrap:!1}}),{c(){c(p.$$.fragment)},l(r){T(p.$$.fragment,r)},m(r,f){o(p,r,f),u=!0},i(r){u||(m(p.$$.fragment,r),u=!0)},o(r){i(p.$$.fragment,r),u=!1},d(r){w(p,r)}}}function vM(G){let p,u;return p=new d({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMERhdGFDb2xsYXRvckZvclNlcTJTZXElMEElMEFkYXRhX2NvbGxhdG9yJTIwJTNEJTIwRGF0YUNvbGxhdG9yRm9yU2VxMlNlcSh0b2tlbml6ZXIlMkMlMjBtb2RlbCUzRG1vZGVsKQ==",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> DataCollatorForSeq2Seq

data_collator = DataCollatorForSeq2Seq(tokenizer, model=model)`,wrap:!1}}),{c(){c(p.$$.fragment)},l(r){T(p.$$.fragment,r)},m(r,f){o(p,r,f),u=!0},i(r){u||(m(p.$$.fragment,r),u=!0)},o(r){i(p.$$.fragment,r),u=!1},d(r){w(p,r)}}}function xM(G){let p,u="我们几乎准备好训练了！ 我们只需要使用我们上面定义的数据整理器将我们的数据集转换为 tf.data.Dataset ，然后 <code>compile()</code> 和 <code>fit()</code> 模型。 首先，转换数据集：",r,f,k,g,W="现在，我们定义训练超参数并编译：",I,Z,R,B,z="最后，我们拟合模型。 我们在每个 epoch 之后使用<code>PushToHubCallback</code>将模型保存到 Hub，这将允许我们稍后使用它进行推理：",E,N,_,x,C='我们在训练期间得到了一些loss，但实际上我们希望看到我们之前计算的 ROUGE 指标。 要获得这些指标，我们需要从模型生成输出并将它们转换为字符串。 让我们为 ROUGE 指标构建一些标签和预测列表以进行比较（请注意，如果您遇到此部分的导入错误，您可能需要<code>!pip install tqdm</code>）。 我们还将使用一个可以显着提高性能的技巧 - 使用 TensorFlow 的加速线性代数编译器 <a href="https://www.tensorflow.org/xla" rel="nofollow">XLA</a> 编译我们的生成代码。 XLA 对模型的计算图应用了各种优化，并显着提高了速度和内存使用率。 正如 Hugging Face <a href="https://huggingface.co/blog/tf-xla-generate" rel="nofollow">博客</a> 中所述，当我们的输入形状变化不大时，XLA 效果最佳。 为了处理这个问题，我们将输入填充为 128 的倍数，并使用填充整理器创建一个新数据集，然后我们将 @tf.function(jit_compile=True) 装饰器应用于我们的生成函数，它会将整个函数标记为使用 XLA 进行编译。',v,L,X,Q,K="一旦我们有了标签和预测字符串列表，计算 ROUGE 分数就很容易了：",A,q,S,Y,F;return f=new d({props:{code:"dGZfdHJhaW5fZGF0YXNldCUyMCUzRCUyMG1vZGVsLnByZXBhcmVfdGZfZGF0YXNldCglMEElMjAlMjAlMjAlMjB0b2tlbml6ZWRfZGF0YXNldHMlNUIlMjJ0cmFpbiUyMiU1RCUyQyUwQSUyMCUyMCUyMCUyMGNvbGxhdGVfZm4lM0RkYXRhX2NvbGxhdG9yJTJDJTBBJTIwJTIwJTIwJTIwc2h1ZmZsZSUzRFRydWUlMkMlMEElMjAlMjAlMjAlMjBiYXRjaF9zaXplJTNEOCUyQyUwQSklMEF0Zl9ldmFsX2RhdGFzZXQlMjAlM0QlMjBtb2RlbC5wcmVwYXJlX3RmX2RhdGFzZXQoJTBBJTIwJTIwJTIwJTIwdG9rZW5pemVkX2RhdGFzZXRzJTVCJTIydmFsaWRhdGlvbiUyMiU1RCUyQyUwQSUyMCUyMCUyMCUyMGNvbGxhdGVfZm4lM0RkYXRhX2NvbGxhdG9yJTJDJTBBJTIwJTIwJTIwJTIwc2h1ZmZsZSUzREZhbHNlJTJDJTBBJTIwJTIwJTIwJTIwYmF0Y2hfc2l6ZSUzRDglMkMlMEEp",highlighted:`tf_train_dataset = model.prepare_tf_dataset(
    tokenized_datasets[<span class="hljs-string">&quot;train&quot;</span>],
    collate_fn=data_collator,
    shuffle=<span class="hljs-literal">True</span>,
    batch_size=<span class="hljs-number">8</span>,
)
tf_eval_dataset = model.prepare_tf_dataset(
    tokenized_datasets[<span class="hljs-string">&quot;validation&quot;</span>],
    collate_fn=data_collator,
    shuffle=<span class="hljs-literal">False</span>,
    batch_size=<span class="hljs-number">8</span>,
)`,wrap:!1}}),Z=new d({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMGNyZWF0ZV9vcHRpbWl6ZXIlMEFpbXBvcnQlMjB0ZW5zb3JmbG93JTIwYXMlMjB0ZiUwQSUwQSUyMyUyMFRoZSUyMG51bWJlciUyMG9mJTIwdHJhaW5pbmclMjBzdGVwcyUyMGlzJTIwdGhlJTIwbnVtYmVyJTIwb2YlMjBzYW1wbGVzJTIwaW4lMjB0aGUlMjBkYXRhc2V0JTJD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MTYlMEF0Zi5rZXJhcy5taXhlZF9wcmVjaXNpb24uc2V0X2dsb2JhbF9wb2xpY3koJTIybWl4ZWRfZmxvYXQxNiUyMik=",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> create_optimizer
<span class="hljs-keyword">import</span> tensorflow <span class="hljs-keyword">as</span> tf

<span class="hljs-comment"># The number of training steps is the number of samples in the dataset, divided by the batch size then multiplied</span>
<span class="hljs-comment"># by the total number of epochs. Note that the tf_train_dataset here is a batched tf.data.Dataset,</span>
<span class="hljs-comment"># not the original Hugging Face Dataset, so its len() is already num_samples // batch_size.</span>
num_train_epochs = <span class="hljs-number">8</span>
num_train_steps = <span class="hljs-built_in">len</span>(tf_train_dataset) * num_train_epochs
model_name = model_checkpoint.split(<span class="hljs-string">&quot;/&quot;</span>)[-<span class="hljs-number">1</span>]

optimizer, schedule = create_optimizer(
    init_lr=<span class="hljs-number">5.6e-5</span>,
    num_warmup_steps=<span class="hljs-number">0</span>,
    num_train_steps=num_train_steps,
    weight_decay_rate=<span class="hljs-number">0.01</span>,
)

model.<span class="hljs-built_in">compile</span>(optimizer=optimizer)

<span class="hljs-comment"># Train in mixed-precision float16</span>
tf.keras.mixed_precision.set_global_policy(<span class="hljs-string">&quot;mixed_float16&quot;</span>)`,wrap:!1}}),N=new d({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycy5rZXJhc19jYWxsYmFja3MlMjBpbXBvcnQlMjBQdXNoVG9IdWJDYWxsYmFjayUwQSUwQWNhbGxiYWNrJTIwJTNEJTIwUHVzaFRvSHViQ2FsbGJhY2soJTBBJTIwJTIwJTIwJTIwb3V0cHV0X2RpciUzRGYlMjIlN0Jtb2RlbF9uYW1lJTdELWZpbmV0dW5lZC1hbWF6b24tZW4tZXMlMjIlMkMlMjB0b2tlbml6ZXIlM0R0b2tlbml6ZXIlMEEpJTBBJTBBbW9kZWwuZml0KCUwQSUyMCUyMCUyMCUyMHRmX3RyYWluX2RhdGFzZXQlMkMlMjB2YWxpZGF0aW9uX2RhdGElM0R0Zl9ldmFsX2RhdGFzZXQlMkMlMjBjYWxsYmFja3MlM0QlNUJjYWxsYmFjayU1RCUyQyUyMGVwb2NocyUzRDglMEEp",highlighted:`<span class="hljs-keyword">from</span> transformers.keras_callbacks <span class="hljs-keyword">import</span> PushToHubCallback

callback = PushToHubCallback(
    output_dir=<span class="hljs-string">f&quot;<span class="hljs-subst">{model_name}</span>-finetuned-amazon-en-es&quot;</span>, tokenizer=tokenizer
)

model.fit(
    tf_train_dataset, validation_data=tf_eval_dataset, callbacks=[callback], epochs=<span class="hljs-number">8</span>
)`,wrap:!1}}),L=new d({props:{code:"ZnJvbSUyMHRxZG0lMjBpbXBvcnQlMjB0cWRtJTBBaW1wb3J0JTIwbnVtcHklMjBhcyUyMG5wJTBBJTBBZ2VuZXJhdGlvbl9kYXRhX2NvbGxhdG9yJTIwJTNEJTIwRGF0YUNvbGxhdG9yRm9yU2VxMlNlcSglMEElMjAlMjAlMjAlMjB0b2tlbml6ZXIlMkMlMjBtb2RlbCUzRG1vZGVsJTJDJTIwcmV0dXJuX3RlbnNvcnMlM0QlMjJ0ZiUyMiUyQyUyMHBhZF90b19tdWx0aXBsZV9vZiUzRDMyMCUwQSklMEElMEF0Zl9nZW5lcmF0ZV9kYXRhc2V0JTIwJTNEJTIwbW9kZWwucHJlcGFyZV90Zl9kYXRhc2V0KCUwQSUyMCUyMCUyMCUyMHRva2VuaXplZF9kYXRhc2V0cyU1QiUyMnZhbGlkYXRpb24lMjIlNUQlMkMlMEElMjAlMjAlMjAlMjBjb2xsYXRlX2ZuJTNEZ2VuZXJhdGlvbl9kYXRhX2NvbGxhdG9yJTJDJTBBJTIwJTIwJTIwJTIwc2h1ZmZsZSUzREZhbHNlJTJDJTBBJTIwJTIwJTIwJTIwYmF0Y2hfc2l6ZSUzRDglMkMlMEElMjAlMjAlMjAlMjBkcm9wX3JlbWFpbmRlciUzRFRydWUlMkMlMEEpJTBBJTBBJTBBJTQ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ml6ZXIuYmF0Y2hfZGVjb2RlKGxhYmVscyUyQyUyMHNraXBfc3BlY2lhbF90b2tlbnMlM0RUcnVlKSUwQSUyMCUyMCUyMCUyMGRlY29kZWRfcHJlZHMlMjAlM0QlMjAlNUIlMjIlNUNuJTIyLmpvaW4oc2VudF90b2tlbml6ZShwcmVkLnN0cmlwKCkpKSUyMGZvciUyMHByZWQlMjBpbiUyMGRlY29kZWRfcHJlZHMlNUQlMEElMjAlMjAlMjAlMjBkZWNvZGVkX2xhYmVscyUyMCUzRCUyMCU1QiUyMiU1Q24lMjIuam9pbihzZW50X3Rva2VuaXplKGxhYmVsLnN0cmlwKCkpKSUyMGZvciUyMGxhYmVsJTIwaW4lMjBkZWNvZGVkX2xhYmVscyU1RCUwQSUyMCUyMCUyMCUyMGFsbF9wcmVkcy5leHRlbmQoZGVjb2RlZF9wcmVkcyklMEElMjAlMjAlMjAlMjBhbGxfbGFiZWxzLmV4dGVuZChkZWNvZGVkX2xhYmVscyk=",highlighted:`<span class="hljs-keyword">from</span> tqdm <span class="hljs-keyword">import</span> tqdm
<span class="hljs-keyword">import</span> numpy <span class="hljs-keyword">as</span> np

generation_data_collator = DataCollatorForSeq2Seq(
    tokenizer, model=model, return_tensors=<span class="hljs-string">&quot;tf&quot;</span>, pad_to_multiple_of=<span class="hljs-number">320</span>
)

tf_generate_dataset = model.prepare_tf_dataset(
    tokenized_datasets[<span class="hljs-string">&quot;validation&quot;</span>],
    collate_fn=generation_data_collator,
    shuffle=<span class="hljs-literal">False</span>,
    batch_size=<span class="hljs-number">8</span>,
    drop_remainder=<span class="hljs-literal">True</span>,
)


<span class="hljs-meta">@tf.function(<span class="hljs-params">jit_compile=<span class="hljs-literal">True</span></span>)</span>
<span class="hljs-keyword">def</span> <span class="hljs-title function_">generate_with_xla</span>(<span class="hljs-params">batch</span>):
    <span class="hljs-keyword">return</span> model.generate(
        input_ids=batch[<span class="hljs-string">&quot;input_ids&quot;</span>],
        attention_mask=batch[<span class="hljs-string">&quot;attention_mask&quot;</span>],
        max_new_tokens=<span class="hljs-number">32</span>,
    )


all_preds = []
all_labels = []
<span class="hljs-keyword">for</span> batch, labels <span class="hljs-keyword">in</span> tqdm(tf_generate_dataset):
    predictions = generate_with_xla(batch)
    decoded_preds = tokenizer.batch_decode(predictions, skip_special_tokens=<span class="hljs-literal">True</span>)
    labels = labels.numpy()
    labels = np.where(labels != -<span class="hljs-number">100</span>, labels, tokenizer.pad_token_id)
    decoded_labels = tokenizer.batch_decode(labels, skip_special_tokens=<span class="hljs-literal">True</span>)
    decoded_preds = [<span class="hljs-string">&quot;\\n&quot;</span>.join(sent_tokenize(pred.strip())) <span class="hljs-keyword">for</span> pred <span class="hljs-keyword">in</span> decoded_preds]
    decoded_labels = [<span class="hljs-string">&quot;\\n&quot;</span>.join(sent_tokenize(label.strip())) <span class="hljs-keyword">for</span> label <span class="hljs-keyword">in</span> decoded_labels]
    all_preds.extend(decoded_preds)
    all_labels.extend(decoded_labels)`,wrap:!1}}),q=new d({props:{code:"cmVzdWx0JTIwJTNEJTIwcm91Z2Vfc2NvcmUuY29tcHV0ZSglMEElMjAlMjAlMjAlMjBwcmVkaWN0aW9ucyUzRGRlY29kZWRfcHJlZHMlMkMlMjByZWZlcmVuY2VzJTNEZGVjb2RlZF9sYWJlbHMlMkMlMjB1c2Vfc3RlbW1lciUzRFRydWUlMEEpJTBBcmVzdWx0JTIwJTNEJTIwJTdCa2V5JTNBJTIwdmFsdWUubWlkLmZtZWFzdXJlJTIwKiUyMDEwMCUyMGZvciUyMGtleSUyQyUyMHZhbHVlJTIwaW4lMjByZXN1bHQuaXRlbXMoKSU3RCUwQSU3QmslM0ElMjByb3VuZCh2JTJDJTIwNCklMjBmb3IlMjBrJTJDJTIwdiUyMGluJTIwcmVzdWx0Lml0ZW1zKCklN0Q=",highlighted:`result = rouge_score.compute(
    predictions=decoded_preds, references=decoded_labels, use_stemmer=<span class="hljs-literal">True</span>
)
result = {key: value.mid.fmeasure * <span class="hljs-number">100</span> <span class="hljs-keyword">for</span> key, value <span class="hljs-keyword">in</span> result.items()}
{k: <span class="hljs-built_in">round</span>(v, <span class="hljs-number">4</span>) <span class="hljs-keyword">for</span> k, v <span class="hljs-keyword">in</span> result.items()}`,wrap:!1}}),Y=new d({props:{code:"JTdCJ3JvdWdlMSclM0ElMjAzMS40ODE1JTJDJTIwJ3JvdWdlMiclM0ElMjAyNS40Mzg2JTJDJTIwJ3JvdWdlTCclM0ElMjAzMS40ODE1JTJDJTIwJ3JvdWdlTHN1bSclM0ElMjAzMS40ODE1JTdE",highlighted:'{&#x27;rouge1&#x27;: <span class="hljs-number">31.4815</span>, &#x27;rouge2&#x27;: <span class="hljs-number">25.4386</span>, &#x27;rougeL&#x27;: <span class="hljs-number">31.4815</span>, &#x27;rougeLsum&#x27;: <span class="hljs-number">31.4815</span>}',wrap:!1}}),{c(){p=y("p"),p.innerHTML=u,r=t(),c(f.$$.fragment),k=t(),g=y("p"),g.textContent=W,I=t(),c(Z.$$.fragment),R=t(),B=y("p"),B.innerHTML=z,E=t(),c(N.$$.fragment),_=t(),x=y("p"),x.innerHTML=C,v=t(),c(L.$$.fragment),X=t(),Q=y("p"),Q.textContent=K,A=t(),c(q.$$.fragment),S=t(),c(Y.$$.fragment)},l(j){p=J(j,"P",{"data-svelte-h":!0}),U(p)!=="svelte-n2hza4"&&(p.innerHTML=u),r=n(j),T(f.$$.fragment,j),k=n(j),g=J(j,"P",{"data-svelte-h":!0}),U(g)!=="svelte-1mnx5ma"&&(g.textContent=W),I=n(j),T(Z.$$.fragment,j),R=n(j),B=J(j,"P",{"data-svelte-h":!0}),U(B)!=="svelte-1lyetsu"&&(B.innerHTML=z),E=n(j),T(N.$$.fragment,j),_=n(j),x=J(j,"P",{"data-svelte-h":!0}),U(x)!=="svelte-fe2ill"&&(x.innerHTML=C),v=n(j),T(L.$$.fragment,j),X=n(j),Q=J(j,"P",{"data-svelte-h":!0}),U(Q)!=="svelte-1ma219f"&&(Q.textContent=K),A=n(j),T(q.$$.fragment,j),S=n(j),T(Y.$$.fragment,j)},m(j,V){a(j,p,V),a(j,r,V),o(f,j,V),a(j,k,V),a(j,g,V),a(j,I,V),o(Z,j,V),a(j,R,V),a(j,B,V),a(j,E,V),o(N,j,V),a(j,_,V),a(j,x,V),a(j,v,V),o(L,j,V),a(j,X,V),a(j,Q,V),a(j,A,V),o(q,j,V),a(j,S,V),o(Y,j,V),F=!0},i(j){F||(m(f.$$.fragment,j),m(Z.$$.fragment,j),m(N.$$.fragment,j),m(L.$$.fragment,j),m(q.$$.fragment,j),m(Y.$$.fragment,j),F=!0)},o(j){i(f.$$.fragment,j),i(Z.$$.fragment,j),i(N.$$.fragment,j),i(L.$$.fragment,j),i(q.$$.fragment,j),i(Y.$$.fragment,j),F=!1},d(j){j&&(l(p),l(r),l(k),l(g),l(I),l(R),l(B),l(E),l(_),l(x),l(v),l(X),l(Q),l(A),l(S)),w(f,j),w(Z,j),w(N,j),w(L,j),w(q,j),w(Y,j)}}}function $M(G){let p,u="我们终于拥有了训练所需的所有的前期准备！我们现在只需要使用标准参数实例化训练器：",r,f,k,g,W="并启动我们的训练：",I,Z,R,B,z="在训练期间，您应该会看到训练损失减少并且 ROUGE 分数随着每个 epoch 增加。训练完成后，您可以通过运行<strong>Trainer.evaluate()</strong> 查看最终的 ROUGE 分数 ：",E,N,_,x,C,v,L="从分数中我们可以看到，我们的模型轻松超过了我们的lead-3 baseline——很好！最后要做的是将模型权重推送到 Hub，如下所示：",X,Q,K,A,q,S,Y='这会将检查点和配置文件保存到 <strong>output_dir</strong> , 在将所有文件上传到模型中心之前。通过指定 <strong>tags</strong> 参数，我们还确保模型中心上的小部件将是一个用于汇总管道的小部件，而不是与 mT5 架构关联的默认文本生成小部件（有关模型标签的更多信息，请参阅<a href="https://huggingface.co/docs/hub/main#how-is-a-models-type-of-inference-api-and-widget-determined" rel="nofollow">🤗 Hub 文档</a>）。输出来自 <strong>trainer.push_to_hub()</strong> 是 Git 提交哈希的 URL，因此您可以轻松查看对模型存储库所做的更改！',F,j,V="在结束本节之前，让我们看一下如何使用 🤗 Accelerate 提供的底层API对 mT5 进行微调。",ys;return f=new d({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMFNlcTJTZXFUcmFpbmVyJTBBJTBBdHJhaW5lciUyMCUzRCUyMFNlcTJTZXFUcmFpbmVyKCUwQSUyMCUyMCUyMCUyMG1vZGVsJTJDJTBBJTIwJTIwJTIwJTIwYXJncyUyQyUwQSUyMCUyMCUyMCUyMHRyYWluX2RhdGFzZXQlM0R0b2tlbml6ZWRfZGF0YXNldHMlNUIlMjJ0cmFpbiUyMiU1RCUyQyUwQSUyMCUyMCUyMCUyMGV2YWxfZGF0YXNldCUzRHRva2VuaXplZF9kYXRhc2V0cyU1QiUyMnZhbGlkYXRpb24lMjIlNUQlMkMlMEElMjAlMjAlMjAlMjBkYXRhX2NvbGxhdG9yJTNEZGF0YV9jb2xsYXRvciUyQyUwQSUyMCUyMCUyMCUyMHRva2VuaXplciUzRHRva2VuaXplciUyQyUwQSUyMCUyMCUyMCUyMGNvbXB1dGVfbWV0cmljcyUzRGNvbXB1dGVfbWV0cmljcyUyQyUwQSk=",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> Seq2SeqTrainer

trainer = Seq2SeqTrainer(
    model,
    args,
    train_dataset=tokenized_datasets[<span class="hljs-string">&quot;train&quot;</span>],
    eval_dataset=tokenized_datasets[<span class="hljs-string">&quot;validation&quot;</span>],
    data_collator=data_collator,
    tokenizer=tokenizer,
    compute_metrics=compute_metrics,
)`,wrap:!1}}),Z=new d({props:{code:"dHJhaW5lci50cmFpbigp",highlighted:"trainer.train()",wrap:!1}}),N=new d({props:{code:"dHJhaW5lci5ldmFsdWF0ZSgp",highlighted:"trainer.evaluate()",wrap:!1}}),x=new d({props:{code:"JTdCJ2V2YWxfbG9zcyclM0ElMjAzLjAyODUyNDM5ODgwMzcxMSUyQyUwQSUyMCdldmFsX3JvdWdlMSclM0ElMjAxNi45NzI4JTJDJTBBJTIwJ2V2YWxfcm91Z2UyJyUzQSUyMDguMjk2OSUyQyUwQSUyMCdldmFsX3JvdWdlTCclM0ElMjAxNi44MzY2JTJDJTBBJTIwJ2V2YWxfcm91Z2VMc3VtJyUzQSUyMDE2Ljg1MSUyQyUwQSUyMCdldmFsX2dlbl9sZW4nJTNBJTIwMTAuMTU5NyUyQyUwQSUyMCdldmFsX3J1bnRpbWUnJTNBJTIwNi4xMDU0JTJDJTBBJTIwJ2V2YWxfc2FtcGxlc19wZXJfc2Vjb25kJyUzQSUyMDM4Ljk4MiUyQyUwQSUyMCdldmFsX3N0ZXBzX3Blcl9zZWNvbmQnJTNBJTIwNC45MTQlN0Q=",highlighted:`{<span class="hljs-string">&#x27;eval_loss&#x27;</span>: <span class="hljs-number">3.028524398803711</span>,
 <span class="hljs-string">&#x27;eval_rouge1&#x27;</span>: <span class="hljs-number">16.9728</span>,
 <span class="hljs-string">&#x27;eval_rouge2&#x27;</span>: <span class="hljs-number">8.2969</span>,
 <span class="hljs-string">&#x27;eval_rougeL&#x27;</span>: <span class="hljs-number">16.8366</span>,
 <span class="hljs-string">&#x27;eval_rougeLsum&#x27;</span>: <span class="hljs-number">16.851</span>,
 <span class="hljs-string">&#x27;eval_gen_len&#x27;</span>: <span class="hljs-number">10.1597</span>,
 <span class="hljs-string">&#x27;eval_runtime&#x27;</span>: <span class="hljs-number">6.1054</span>,
 <span class="hljs-string">&#x27;eval_samples_per_second&#x27;</span>: <span class="hljs-number">38.982</span>,
 <span class="hljs-string">&#x27;eval_steps_per_second&#x27;</span>: <span class="hljs-number">4.914</span>}`,wrap:!1}}),Q=new d({props:{code:"dHJhaW5lci5wdXNoX3RvX2h1Yihjb21taXRfbWVzc2FnZSUzRCUyMlRyYWluaW5nJTIwY29tcGxldGUlMjIlMkMlMjB0YWdzJTNEJTIyc3VtbWFyaXphdGlvbiUyMik=",highlighted:'trainer.push_to_hub(<span class="hljs-attribute">commit_message</span>=<span class="hljs-string">&quot;Training complete&quot;</span>, <span class="hljs-attribute">tags</span>=<span class="hljs-string">&quot;summarization&quot;</span>)',wrap:!1}}),A=new d({props:{code:"J2h0dHBzJTNBJTJGJTJGaHVnZ2luZ2ZhY2UuY28lMkZodWdnaW5nZmFjZS1jb3Vyc2UlMkZtdDUtZmluZXR1bmVkLWFtYXpvbi1lbi1lcyUyRmNvbW1pdCUyRmFhMDUzNmI4MjliMjhlNzNlMWU0Yjk0YjhhNWFhY2VjNDIwZDQwZTAn",highlighted:'<span class="hljs-string">&#x27;https://huggingface.co/huggingface-course/mt5-finetuned-amazon-en-es/commit/aa0536b829b28e73e1e4b94b8a5aacec420d40e0&#x27;</span>',wrap:!1}}),{c(){p=y("p"),p.textContent=u,r=t(),c(f.$$.fragment),k=t(),g=y("p"),g.textContent=W,I=t(),c(Z.$$.fragment),R=t(),B=y("p"),B.innerHTML=z,E=t(),c(N.$$.fragment),_=t(),c(x.$$.fragment),C=t(),v=y("p"),v.textContent=L,X=t(),c(Q.$$.fragment),K=t(),c(A.$$.fragment),q=t(),S=y("p"),S.innerHTML=Y,F=t(),j=y("p"),j.textContent=V},l(h){p=J(h,"P",{"data-svelte-h":!0}),U(p)!=="svelte-1pgo9jn"&&(p.textContent=u),r=n(h),T(f.$$.fragment,h),k=n(h),g=J(h,"P",{"data-svelte-h":!0}),U(g)!=="svelte-1w9sfsy"&&(g.textContent=W),I=n(h),T(Z.$$.fragment,h),R=n(h),B=J(h,"P",{"data-svelte-h":!0}),U(B)!=="svelte-1nxn86t"&&(B.innerHTML=z),E=n(h),T(N.$$.fragment,h),_=n(h),T(x.$$.fragment,h),C=n(h),v=J(h,"P",{"data-svelte-h":!0}),U(v)!=="svelte-18bxe5e"&&(v.textContent=L),X=n(h),T(Q.$$.fragment,h),K=n(h),T(A.$$.fragment,h),q=n(h),S=J(h,"P",{"data-svelte-h":!0}),U(S)!=="svelte-1t9u7dl"&&(S.innerHTML=Y),F=n(h),j=J(h,"P",{"data-svelte-h":!0}),U(j)!=="svelte-ct1spf"&&(j.textContent=V)},m(h,$){a(h,p,$),a(h,r,$),o(f,h,$),a(h,k,$),a(h,g,$),a(h,I,$),o(Z,h,$),a(h,R,$),a(h,B,$),a(h,E,$),o(N,h,$),a(h,_,$),o(x,h,$),a(h,C,$),a(h,v,$),a(h,X,$),o(Q,h,$),a(h,K,$),o(A,h,$),a(h,q,$),a(h,S,$),a(h,F,$),a(h,j,$),ys=!0},i(h){ys||(m(f.$$.fragment,h),m(Z.$$.fragment,h),m(N.$$.fragment,h),m(x.$$.fragment,h),m(Q.$$.fragment,h),m(A.$$.fragment,h),ys=!0)},o(h){i(f.$$.fragment,h),i(Z.$$.fragment,h),i(N.$$.fragment,h),i(x.$$.fragment,h),i(Q.$$.fragment,h),i(A.$$.fragment,h),ys=!1},d(h){h&&(l(p),l(r),l(k),l(g),l(I),l(R),l(B),l(E),l(_),l(C),l(v),l(X),l(K),l(q),l(S),l(F),l(j)),w(f,h),w(Z,h),w(N,h),w(x,h),w(Q,h),w(A,h)}}}function pM(G){let p,u,r,f='使用 🤗 Accelerate 微调我们的模型与我们在 <a href="/course/chapter3">Chapter 3</a> 中遇到的文本分类示例非常相似。 主要区别在于需要在训练期间显式生成摘要并定义我们如何计算 ROUGE 分数（回想一下，<code>Seq2SeqTrainer</code> 为我们生成了摘要）。 让我们看看我们如何在 🤗 Accelerate 中实现这两个要求！',k,g,W,I,Z=`The first thing we need to do is create a <code>DataLoader</code> for each of our splits. Since the PyTorch dataloaders expect batches of tensors, we need to set the format to <code>&quot;torch&quot;</code> in our datasets:
我们需要做的第一件事是为每个数据集的每一个拆分创建一个<code>DataLoader</code>。 由于 PyTorch 数据加载器需要成批的张量，我们需要在数据集中将格式设置为<code>torch</code>：`,R,B,z,E,N="现在我们已经有了仅由张量组成的数据集，接下来要做的是再次实例化<code>DataCollatorForSeq2Seq</code>。 为此，我们需要提供模型微调前的版本，所以让我们从缓存中再次加载它：",_,x,C,v,L="然后我们可以实例化数据整理器并使用它来定义我们的数据加载器：",X,Q,K,A,q="接下来要做的是定义我们想要使用的优化器。与我们的其他示例一样，我们将使用 <strong>AdamW</strong> ，这适用于大多数问题：",S,Y,F,j,V="最后，我们将模型、优化器和数据加载器提供给 <strong>accelerator.prepare()</strong> 方法：",ys,h,$,P,Ns,O,le="现在我们已经准备好了我们索要用的对象，还有三件事要做：",Xs,ss,nl="<li>定义学习率调度计划。</li> <li>实现一个功能来对摘要进行后续处理以进行评估。</li> <li>在 Hub 上创建一个存储库，我们可以将模型推送到该存储库。</li>",Js,cs,fs="对于学习率调度，我们将使用前几节中的标准线性衰减：",As,ls,Ml,Ts,$s="对于后续处理，我们需要一个函数，将生成的摘要拆分为由换行符分隔的句子。 这是 ROUGE 指标所期望的格式，我们可以使用以下代码片段来实现：",zs,as,Qs,es,ae="如果你还记得我们是如何定义 <code>Seq2SeqTrainer</code> 的 <code>compute_metrics()</code> 函数的，这对你来说应该很熟悉。",Ys,ts,pl="最后，我们需要在 Hugging Face Hub 上创建一个模型存储库。 为此，我们可以使用🤗 Hub 库的get_full_repo_name。 我们只需要为我们的存储库定义一个名称，该库有一个非常好用的函数可以将存储库 ID 与用户配置文件结合起来：",os,Ws,Es,ns,Ss,Ms,ee="现在我们可以使用这个存储库名称将本地版本克隆到我们的结果目录中，该目录将存储训练的模型：",Fs,ps,Hs,rs,rl="这将允许我们在训练期间通过调用 <code>repo.push_to_hub()</code> 方法将模型推送到 Hub！ 现在让我们通过写出完整的训练循环来结束我们的分析。",ws,_s,Ds,ms,ml="文本摘要的训练循环与我们遇到的其他 🤗 Accelerate 示例非常相似，大致分为四个主要步骤：这",Us,js,Vs="<li>通过在每个epoch 迭代 <code>train_dataloader</code> 中的所有示例来训练模型。</li> <li>在每个 epoch 结束时生成模型摘要，首先生成标记，然后将它们（和参考摘要）解码为文本。</li> <li>使用我们之前看到的相同技术计算 ROUGE 分数。</li> <li>保存检查点并将所有内容推送到 Hub。 在这里，我们依赖 <code>Repository</code> 对象的巧妙的 <code>blocking=False</code> 参数，以便我们可以在每个 epoch 异步地上传检查点。 这使我们能够继续训练，而不必等待与 GB 大小的模型慢呼呼的上传！</li>",il,hs,Cs="这些步骤可以在以下代码块中看到：",yl,ds,us,Rs,Ls,is,Jl="就是这样！ 运行此程序后，您将获得与我们使用“Trainer”获得的模型和结果非常相似的模型和结果。",bs;return p=new Is({props:{title:"使用 🤗 Accelerate 微调 mT5",local:"使用 🤗 Accelerate 微调 mT5",headingTag:"h2"}}),g=new Is({props:{title:"为训练做好一切准备",local:"为训练做好一切准备",headingTag:"h3"}}),B=new d({props:{code:"dG9rZW5pemVkX2RhdGFzZXRzLnNldF9mb3JtYXQoJTIydG9yY2glMjIp",highlighted:'tokenized_datasets.set_format(<span class="hljs-string">&quot;torch&quot;</span>)',wrap:!1}}),x=new d({props:{code:"bW9kZWwlMjAlM0QlMjBBdXRvTW9kZWxGb3JTZXEyU2VxTE0uZnJvbV9wcmV0cmFpbmVkKG1vZGVsX2NoZWNrcG9pbnQp",highlighted:"model = AutoModelForSeq2SeqLM.from_pretrained(model_checkpoint)",wrap:!1}}),Q=new d({props:{code:"ZnJvbSUyMHRvcmNoLnV0aWxzLmRhdGElMjBpbXBvcnQlMjBEYXRhTG9hZGVyJTBBJTBBYmF0Y2hfc2l6ZSUyMCUzRCUyMDglMEF0cmFpbl9kYXRhbG9hZGVyJTIwJTNEJTIwRGF0YUxvYWRlciglMEElMjAlMjAlMjAlMjB0b2tlbml6ZWRfZGF0YXNldHMlNUIlMjJ0cmFpbiUyMiU1RCUyQyUwQSUyMCUyMCUyMCUyMHNodWZmbGUlM0RUcnVlJTJDJTBBJTIwJTIwJTIwJTIwY29sbGF0ZV9mbiUzRGRhdGFfY29sbGF0b3IlMkMlMEElMjAlMjAlMjAlMjBiYXRjaF9zaXplJTNEYmF0Y2hfc2l6ZSUyQyUwQSklMEFldmFsX2RhdGFsb2FkZXIlMjAlM0QlMjBEYXRhTG9hZGVyKCUwQSUyMCUyMCUyMCUyMHRva2VuaXplZF9kYXRhc2V0cyU1QiUyMnZhbGlkYXRpb24lMjIlNUQlMkMlMjBjb2xsYXRlX2ZuJTNEZGF0YV9jb2xsYXRvciUyQyUyMGJhdGNoX3NpemUlM0RiYXRjaF9zaXplJTBBKQ==",highlighted:`<span class="hljs-keyword">from</span> torch.utils.data <span class="hljs-keyword">import</span> DataLoader

batch_size = <span class="hljs-number">8</span>
train_dataloader = DataLoader(
    tokenized_datasets[<span class="hljs-string">&quot;train&quot;</span>],
    shuffle=<span class="hljs-literal">True</span>,
    collate_fn=data_collator,
    batch_size=batch_size,
)
eval_dataloader = DataLoader(
    tokenized_datasets[<span class="hljs-string">&quot;validation&quot;</span>], collate_fn=data_collator, batch_size=batch_size
)`,wrap:!1}}),Y=new d({props:{code:"ZnJvbSUyMHRvcmNoLm9wdGltJTIwaW1wb3J0JTIwQWRhbVclMEElMEFvcHRpbWl6ZXIlMjAlM0QlMjBBZGFtVyhtb2RlbC5wYXJhbWV0ZXJzKCklMkMlMjBsciUzRDJlLTUp",highlighted:`<span class="hljs-keyword">from</span> torch.optim <span class="hljs-keyword">import</span> AdamW

optimizer = AdamW(model.parameters(), lr=<span class="hljs-number">2e-5</span>)`,wrap:!1}}),h=new d({props:{code:"ZnJvbSUyMGFjY2VsZXJhdGUlMjBpbXBvcnQlMjBBY2NlbGVyYXRvciUwQSUwQWFjY2VsZXJhdG9yJTIwJTNEJTIwQWNjZWxlcmF0b3IoKSUwQW1vZGVsJTJDJTIwb3B0aW1pemVyJTJDJTIwdHJhaW5fZGF0YWxvYWRlciUyQyUyMGV2YWxfZGF0YWxvYWRlciUyMCUzRCUyMGFjY2VsZXJhdG9yLnByZXBhcmUoJTBBJTIwJTIwJTIwJTIwbW9kZWwlMkMlMjBvcHRpbWl6ZXIlMkMlMjB0cmFpbl9kYXRhbG9hZGVyJTJDJTIwZXZhbF9kYXRhbG9hZGVyJTBBKQ==",highlighted:`<span class="hljs-keyword">from</span> accelerate <span class="hljs-keyword">import</span> Accelerator

accelerator = Accelerator()
model, optimizer, train_dataloader, eval_dataloader = accelerator.prepare(
    model, optimizer, train_dataloader, eval_dataloader
)`,wrap:!1}}),P=new el({props:{$$slots:{default:[WM]},$$scope:{ctx:G}}}),ls=new d({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMGdldF9zY2hlZHVsZXIlMEElMEFudW1fdHJhaW5fZXBvY2hzJTIwJTNEJTIwMTAlMEFudW1fdXBkYXRlX3N0ZXBzX3Blcl9lcG9jaCUyMCUzRCUyMGxlbih0cmFpbl9kYXRhbG9hZGVyKSUwQW51bV90cmFpbmluZ19zdGVwcyUyMCUzRCUyMG51bV90cmFpbl9lcG9jaHMlMjAqJTIwbnVtX3VwZGF0ZV9zdGVwc19wZXJfZXBvY2glMEElMEFscl9zY2hlZHVsZXIlMjAlM0QlMjBnZXRfc2NoZWR1bGVyKCUwQSUyMCUyMCUyMCUyMCUyMmxpbmVhciUyMiUyQyUwQSUyMCUyMCUyMCUyMG9wdGltaXplciUzRG9wdGltaXplciUyQyUwQSUyMCUyMCUyMCUyMG51bV93YXJtdXBfc3RlcHMlM0QwJTJDJTBBJTIwJTIwJTIwJTIwbnVtX3RyYWluaW5nX3N0ZXBzJTNEbnVtX3RyYWluaW5nX3N0ZXBzJTJDJTBBKQ==",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> get_scheduler

num_train_epochs = <span class="hljs-number">10</span>
num_update_steps_per_epoch = <span class="hljs-built_in">len</span>(train_dataloader)
num_training_steps = num_train_epochs * num_update_steps_per_epoch

lr_scheduler = get_scheduler(
    <span class="hljs-string">&quot;linear&quot;</span>,
    optimizer=optimizer,
    num_warmup_steps=<span class="hljs-number">0</span>,
    num_training_steps=num_training_steps,
)`,wrap:!1}}),as=new d({props:{code:"ZGVmJTIwcG9zdHByb2Nlc3NfdGV4dChwcmVkcyUyQyUyMGxhYmVscyklM0ElMEElMjAlMjAlMjAlMjBwcmVkcyUyMCUzRCUyMCU1QnByZWQuc3RyaXAoKSUyMGZvciUyMHByZWQlMjBpbiUyMHByZWRzJTVEJTBBJTIwJTIwJTIwJTIwbGFiZWxzJTIwJTNEJTIwJTVCbGFiZWwuc3RyaXAoKSUyMGZvciUyMGxhYmVsJTIwaW4lMjBsYWJlbHMlNUQlMEElMEElMjAlMjAlMjAlMjAlMjMlMjBST1VHRSUyMGV4cGVjdHMlMjBhJTIwbmV3bGluZSUyMGFmdGVyJTIwZWFjaCUyMHNlbnRlbmNlJTBBJTIwJTIwJTIwJTIwcHJlZHMlMjAlM0QlMjAlNUIlMjIlNUNuJTIyLmpvaW4obmx0ay5zZW50X3Rva2VuaXplKHByZWQpKSUyMGZvciUyMHByZWQlMjBpbiUyMHByZWRzJTVEJTBBJTIwJTIwJTIwJTIwbGFiZWxzJTIwJTNEJTIwJTVCJTIyJTVDbiUyMi5qb2luKG5sdGsuc2VudF90b2tlbml6ZShsYWJlbCkpJTIwZm9yJTIwbGFiZWwlMjBpbiUyMGxhYmVscyU1RCUwQSUwQSUyMCUyMCUyMCUyMHJldHVybiUyMHByZWRzJTJDJTIwbGFiZWxz",highlighted:`<span class="hljs-keyword">def</span> <span class="hljs-title function_">postprocess_text</span>(<span class="hljs-params">preds, labels</span>):
    preds = [pred.strip() <span class="hljs-keyword">for</span> pred <span class="hljs-keyword">in</span> preds]
    labels = [label.strip() <span class="hljs-keyword">for</span> label <span class="hljs-keyword">in</span> labels]

    <span class="hljs-comment"># ROUGE expects a newline after each sentence</span>
    preds = [<span class="hljs-string">&quot;\\n&quot;</span>.join(nltk.sent_tokenize(pred)) <span class="hljs-keyword">for</span> pred <span class="hljs-keyword">in</span> preds]
    labels = [<span class="hljs-string">&quot;\\n&quot;</span>.join(nltk.sent_tokenize(label)) <span class="hljs-keyword">for</span> label <span class="hljs-keyword">in</span> labels]

    <span class="hljs-keyword">return</span> preds, labels`,wrap:!1}}),Ws=new d({props:{code:"ZnJvbSUyMGh1Z2dpbmdmYWNlX2h1YiUyMGltcG9ydCUyMGdldF9mdWxsX3JlcG9fbmFtZSUwQSUwQW1vZGVsX25hbWUlMjAlM0QlMjAlMjJ0ZXN0LWJlcnQtZmluZXR1bmVkLXNxdWFkLWFjY2VsZXJhdGUlMjIlMEFyZXBvX25hbWUlMjAlM0QlMjBnZXRfZnVsbF9yZXBvX25hbWUobW9kZWxfbmFtZSklMEFyZXBvX25hbWU=",highlighted:`<span class="hljs-keyword">from</span> huggingface_hub <span class="hljs-keyword">import</span> get_full_repo_name

model_name = <span class="hljs-string">&quot;test-bert-finetuned-squad-accelerate&quot;</span>
repo_name = get_full_repo_name(model_name)
repo_name`,wrap:!1}}),ns=new d({props:{code:"J2xld3R1biUyRm10NS1maW5ldHVuZWQtYW1hem9uLWVuLWVzLWFjY2VsZXJhdGUn",highlighted:'<span class="hljs-string">&#x27;lewtun/mt5-finetuned-amazon-en-es-accelerate&#x27;</span>',wrap:!1}}),ps=new d({props:{code:"ZnJvbSUyMGh1Z2dpbmdmYWNlX2h1YiUyMGltcG9ydCUyMFJlcG9zaXRvcnklMEElMEFvdXRwdXRfZGlyJTIwJTNEJTIwJTIycmVzdWx0cy1tdDUtZmluZXR1bmVkLXNxdWFkLWFjY2VsZXJhdGUlMjIlMEFyZXBvJTIwJTNEJTIwUmVwb3NpdG9yeShvdXRwdXRfZGlyJTJDJTIwY2xvbmVfZnJvbSUzRHJlcG9fbmFtZSk=",highlighted:`<span class="hljs-keyword">from</span> huggingface_hub <span class="hljs-keyword">import</span> Repository

output_dir = <span class="hljs-string">&quot;results-mt5-finetuned-squad-accelerate&quot;</span>
repo = Repository(output_dir, clone_from=repo_name)`,wrap:!1}}),_s=new Is({props:{title:"训练循环",local:"训练循环",headingTag:"h3"}}),ds=new d({props:{code:" ",highlighted:`<span class="hljs-keyword">from</span> tqdm.auto <span class="hljs-keyword">import</span> tqdm
<span class="hljs-keyword">import</span> torch
<span class="hljs-keyword">import</span> numpy <span class="hljs-keyword">as</span> np

progress_bar = tqdm(<span class="hljs-built_in">range</span>(num_training_steps))

<span class="hljs-keyword">for</span> epoch <span class="hljs-keyword">in</span> <span class="hljs-built_in">range</span>(num_train_epochs):
    <span class="hljs-comment"># Training</span>
    model.train()
    <span class="hljs-keyword">for</span> step, batch <span class="hljs-keyword">in</span> <span class="hljs-built_in">enumerate</span>(train_dataloader):
        outputs = model(**batch)
        loss = outputs.loss
        accelerator.backward(loss)

        optimizer.step()
        lr_scheduler.step()
        optimizer.zero_grad()
        progress_bar.update(<span class="hljs-number">1</span>)

    <span class="hljs-comment"># Evaluation</span>
    model.<span class="hljs-built_in">eval</span>()
    <span class="hljs-keyword">for</span> step, batch <span class="hljs-keyword">in</span> <span class="hljs-built_in">enumerate</span>(eval_dataloader):
        <span class="hljs-keyword">with</span> torch.no_grad():
            generated_tokens = accelerator.unwrap_model(model).generate(
                batch[<span class="hljs-string">&quot;input_ids&quot;</span>],
                attention_mask=batch[<span class="hljs-string">&quot;attention_mask&quot;</span>],
            )

            generated_tokens = accelerator.pad_across_processes(
                generated_tokens, dim=<span class="hljs-number">1</span>, pad_index=tokenizer.pad_token_id
            )
            labels = batch[<span class="hljs-string">&quot;labels&quot;</span>]

            <span class="hljs-comment"># If we did not pad to max length, we need to pad the labels too</span>
            labels = accelerator.pad_across_processes(
                batch[<span class="hljs-string">&quot;labels&quot;</span>], dim=<span class="hljs-number">1</span>, pad_index=tokenizer.pad_token_id
            )

            generated_tokens = accelerator.gather(generated_tokens).cpu().numpy()
            labels = accelerator.gather(labels).cpu().numpy()

            <span class="hljs-comment"># Replace -100 in the labels as we can&#x27;t decode them</span>
            labels = np.where(labels != -<span class="hljs-number">100</span>, labels, tokenizer.pad_token_id)
            <span class="hljs-keyword">if</span> <span class="hljs-built_in">isinstance</span>(generated_tokens, <span class="hljs-built_in">tuple</span>):
                generated_tokens = generated_tokens[<span class="hljs-number">0</span>]
            decoded_preds = tokenizer.batch_decode(
                generated_tokens, skip_special_tokens=<span class="hljs-literal">True</span>
            )
            decoded_labels = tokenizer.batch_decode(labels, skip_special_tokens=<span class="hljs-literal">True</span>)

            decoded_preds, decoded_labels = postprocess_text(
                decoded_preds, decoded_labels
            )

            rouge_score.add_batch(predictions=decoded_preds, references=decoded_labels)

    <span class="hljs-comment"># Compute metrics</span>
    result = rouge_score.compute()
    <span class="hljs-comment"># Extract the median ROUGE scores</span>
    result = {key: value.mid.fmeasure * <span class="hljs-number">100</span> <span class="hljs-keyword">for</span> key, value <span class="hljs-keyword">in</span> result.items()}
    result = {k: <span class="hljs-built_in">round</span>(v, <span class="hljs-number">4</span>) <span class="hljs-keyword">for</span> k, v <span class="hljs-keyword">in</span> result.items()}
    <span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;Epoch <span class="hljs-subst">{epoch}</span>:&quot;</span>, result)

    <span class="hljs-comment"># Save and upload</span>
    accelerator.wait_for_everyone()
    unwrapped_model = accelerator.unwrap_model(model)
    unwrapped_model.save_pretrained(output_dir, save_function=accelerator.save)
    <span class="hljs-keyword">if</span> accelerator.is_main_process:
        tokenizer.save_pretrained(output_dir)
        repo.push_to_hub(
            commit_message=<span class="hljs-string">f&quot;Training in progress epoch <span class="hljs-subst">{epoch}</span>&quot;</span>, blocking=<span class="hljs-literal">False</span>
        )`,wrap:!1}}),Rs=new d({props:{code:"RXBvY2glMjAwJTNBJTIwJTdCJ3JvdWdlMSclM0ElMjA1LjYzNTElMkMlMjAncm91Z2UyJyUzQSUyMDEuMTYyNSUyQyUyMCdyb3VnZUwnJTNBJTIwNS40ODY2JTJDJTIwJ3JvdWdlTHN1bSclM0ElMjA1LjUwMDUlN0QlMEFFcG9jaCUyMDElM0ElMjAlN0Incm91Z2UxJyUzQSUyMDkuODY0NiUyQyUyMCdyb3VnZTInJTNBJTIwMy40MTA2JTJDJTIwJ3JvdWdlTCclM0ElMjA5Ljk0MzklMkMlMjAncm91Z2VMc3VtJyUzQSUyMDkuOTMwNiU3RCUwQUVwb2NoJTIwMiUzQSUyMCU3Qidyb3V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UyMCdyb3VnZTInJTNBJTIwNi41OTk4JTJDJTIwJ3JvdWdlTCclM0ElMjAxMy45MTIzJTJDJTIwJ3JvdWdlTHN1bSclM0ElMjAxMy43NzQ0JTdEJTBBRXBvY2glMjA5JTNBJTIwJTdCJ3JvdWdlMSclM0ElMjAxNC4xMTkyJTJDJTIwJ3JvdWdlMiclM0ElMjA3LjAwNTklMkMlMjAncm91Z2VMJyUzQSUyMDE0LjExNzIlMkMlMjAncm91Z2VMc3VtJyUzQSUyMDEzLjk1MDklN0Q=",highlighted:`Epoch <span class="hljs-number">0</span>: {<span class="hljs-string">&#x27;rouge1&#x27;</span>: <span class="hljs-number">5.6351</span>, <span class="hljs-string">&#x27;rouge2&#x27;</span>: <span class="hljs-number">1.1625</span>, <span class="hljs-string">&#x27;rougeL&#x27;</span>: <span class="hljs-number">5.4866</span>, <span class="hljs-string">&#x27;rougeLsum&#x27;</span>: <span class="hljs-number">5.5005</span>}
Epoch <span class="hljs-number">1</span>: {<span class="hljs-string">&#x27;rouge1&#x27;</span>: <span class="hljs-number">9.8646</span>, <span class="hljs-string">&#x27;rouge2&#x27;</span>: <span class="hljs-number">3.4106</span>, <span class="hljs-string">&#x27;rougeL&#x27;</span>: <span class="hljs-number">9.9439</span>, <span class="hljs-string">&#x27;rougeLsum&#x27;</span>: <span class="hljs-number">9.9306</span>}
Epoch <span class="hljs-number">2</span>: {<span class="hljs-string">&#x27;rouge1&#x27;</span>: <span class="hljs-number">11.0872</span>, <span class="hljs-string">&#x27;rouge2&#x27;</span>: <span class="hljs-number">3.3273</span>, <span class="hljs-string">&#x27;rougeL&#x27;</span>: <span class="hljs-number">11.0508</span>, <span class="hljs-string">&#x27;rougeLsum&#x27;</span>: <span class="hljs-number">10.9468</span>}
Epoch <span class="hljs-number">3</span>: {<span class="hljs-string">&#x27;rouge1&#x27;</span>: <span class="hljs-number">11.8587</span>, <span class="hljs-string">&#x27;rouge2&#x27;</span>: <span class="hljs-number">4.8167</span>, <span class="hljs-string">&#x27;rougeL&#x27;</span>: <span class="hljs-number">11.7986</span>, <span class="hljs-string">&#x27;rougeLsum&#x27;</span>: <span class="hljs-number">11.7518</span>}
Epoch <span class="hljs-number">4</span>: {<span class="hljs-string">&#x27;rouge1&#x27;</span>: <span class="hljs-number">12.9842</span>, <span class="hljs-string">&#x27;rouge2&#x27;</span>: <span class="hljs-number">5.5887</span>, <span class="hljs-string">&#x27;rougeL&#x27;</span>: <span class="hljs-number">12.7546</span>, <span class="hljs-string">&#x27;rougeLsum&#x27;</span>: <span class="hljs-number">12.7029</span>}
Epoch <span class="hljs-number">5</span>: {<span class="hljs-string">&#x27;rouge1&#x27;</span>: <span class="hljs-number">13.4628</span>, <span class="hljs-string">&#x27;rouge2&#x27;</span>: <span class="hljs-number">6.4598</span>, <span class="hljs-string">&#x27;rougeL&#x27;</span>: <span class="hljs-number">13.312</span>, <span class="hljs-string">&#x27;rougeLsum&#x27;</span>: <span class="hljs-number">13.2913</span>}
Epoch <span class="hljs-number">6</span>: {<span class="hljs-string">&#x27;rouge1&#x27;</span>: <span class="hljs-number">12.9131</span>, <span class="hljs-string">&#x27;rouge2&#x27;</span>: <span class="hljs-number">5.8914</span>, <span class="hljs-string">&#x27;rougeL&#x27;</span>: <span class="hljs-number">12.6896</span>, <span class="hljs-string">&#x27;rougeLsum&#x27;</span>: <span class="hljs-number">12.5701</span>}
Epoch <span class="hljs-number">7</span>: {<span class="hljs-string">&#x27;rouge1&#x27;</span>: <span class="hljs-number">13.3079</span>, <span class="hljs-string">&#x27;rouge2&#x27;</span>: <span class="hljs-number">6.2994</span>, <span class="hljs-string">&#x27;rougeL&#x27;</span>: <span class="hljs-number">13.1536</span>, <span class="hljs-string">&#x27;rougeLsum&#x27;</span>: <span class="hljs-number">13.1194</span>}
Epoch <span class="hljs-number">8</span>: {<span class="hljs-string">&#x27;rouge1&#x27;</span>: <span class="hljs-number">13.96</span>, <span class="hljs-string">&#x27;rouge2&#x27;</span>: <span class="hljs-number">6.5998</span>, <span class="hljs-string">&#x27;rougeL&#x27;</span>: <span class="hljs-number">13.9123</span>, <span class="hljs-string">&#x27;rougeLsum&#x27;</span>: <span class="hljs-number">13.7744</span>}
Epoch <span class="hljs-number">9</span>: {<span class="hljs-string">&#x27;rouge1&#x27;</span>: <span class="hljs-number">14.1192</span>, <span class="hljs-string">&#x27;rouge2&#x27;</span>: <span class="hljs-number">7.0059</span>, <span class="hljs-string">&#x27;rougeL&#x27;</span>: <span class="hljs-number">14.1172</span>, <span class="hljs-string">&#x27;rougeLsum&#x27;</span>: <span class="hljs-number">13.9509</span>}`,wrap:!1}}),{c(){c(p.$$.fragment),u=t(),r=y("p"),r.innerHTML=f,k=t(),c(g.$$.fragment),W=t(),I=y("p"),I.innerHTML=Z,R=t(),c(B.$$.fragment),z=t(),E=y("p"),E.innerHTML=N,_=t(),c(x.$$.fragment),C=t(),v=y("p"),v.textContent=L,X=t(),c(Q.$$.fragment),K=t(),A=y("p"),A.innerHTML=q,S=t(),c(Y.$$.fragment),F=t(),j=y("p"),j.innerHTML=V,ys=t(),c(h.$$.fragment),$=t(),c(P.$$.fragment),Ns=t(),O=y("p"),O.textContent=le,Xs=t(),ss=y("ul"),ss.innerHTML=nl,Js=t(),cs=y("p"),cs.textContent=fs,As=t(),c(ls.$$.fragment),Ml=t(),Ts=y("p"),Ts.textContent=$s,zs=t(),c(as.$$.fragment),Qs=t(),es=y("p"),es.innerHTML=ae,Ys=t(),ts=y("p"),ts.textContent=pl,os=t(),c(Ws.$$.fragment),Es=t(),c(ns.$$.fragment),Ss=t(),Ms=y("p"),Ms.textContent=ee,Fs=t(),c(ps.$$.fragment),Hs=t(),rs=y("p"),rs.innerHTML=rl,ws=t(),c(_s.$$.fragment),Ds=t(),ms=y("p"),ms.textContent=ml,Us=t(),js=y("ol"),js.innerHTML=Vs,il=t(),hs=y("p"),hs.textContent=Cs,yl=t(),c(ds.$$.fragment),us=t(),c(Rs.$$.fragment),Ls=t(),is=y("p"),is.textContent=Jl},l(M){T(p.$$.fragment,M),u=n(M),r=J(M,"P",{"data-svelte-h":!0}),U(r)!=="svelte-16mmf8s"&&(r.innerHTML=f),k=n(M),T(g.$$.fragment,M),W=n(M),I=J(M,"P",{"data-svelte-h":!0}),U(I)!=="svelte-163azxt"&&(I.innerHTML=Z),R=n(M),T(B.$$.fragment,M),z=n(M),E=J(M,"P",{"data-svelte-h":!0}),U(E)!=="svelte-9sn7z8"&&(E.innerHTML=N),_=n(M),T(x.$$.fragment,M),C=n(M),v=J(M,"P",{"data-svelte-h":!0}),U(v)!=="svelte-7l0cyc"&&(v.textContent=L),X=n(M),T(Q.$$.fragment,M),K=n(M),A=J(M,"P",{"data-svelte-h":!0}),U(A)!=="svelte-1epxz76"&&(A.innerHTML=q),S=n(M),T(Y.$$.fragment,M),F=n(M),j=J(M,"P",{"data-svelte-h":!0}),U(j)!=="svelte-9onor1"&&(j.innerHTML=V),ys=n(M),T(h.$$.fragment,M),$=n(M),T(P.$$.fragment,M),Ns=n(M),O=J(M,"P",{"data-svelte-h":!0}),U(O)!=="svelte-138v5ic"&&(O.textContent=le),Xs=n(M),ss=J(M,"UL",{"data-svelte-h":!0}),U(ss)!=="svelte-1vwgy67"&&(ss.innerHTML=nl),Js=n(M),cs=J(M,"P",{"data-svelte-h":!0}),U(cs)!=="svelte-17aodqd"&&(cs.textContent=fs),As=n(M),T(ls.$$.fragment,M),Ml=n(M),Ts=J(M,"P",{"data-svelte-h":!0}),U(Ts)!=="svelte-1qviu3v"&&(Ts.textContent=$s),zs=n(M),T(as.$$.fragment,M),Qs=n(M),es=J(M,"P",{"data-svelte-h":!0}),U(es)!=="svelte-d938e1"&&(es.innerHTML=ae),Ys=n(M),ts=J(M,"P",{"data-svelte-h":!0}),U(ts)!=="svelte-5g21za"&&(ts.textContent=pl),os=n(M),T(Ws.$$.fragment,M),Es=n(M),T(ns.$$.fragment,M),Ss=n(M),Ms=J(M,"P",{"data-svelte-h":!0}),U(Ms)!=="svelte-ocoiuk"&&(Ms.textContent=ee),Fs=n(M),T(ps.$$.fragment,M),Hs=n(M),rs=J(M,"P",{"data-svelte-h":!0}),U(rs)!=="svelte-12t81fm"&&(rs.innerHTML=rl),ws=n(M),T(_s.$$.fragment,M),Ds=n(M),ms=J(M,"P",{"data-svelte-h":!0}),U(ms)!=="svelte-1951b9m"&&(ms.textContent=ml),Us=n(M),js=J(M,"OL",{"data-svelte-h":!0}),U(js)!=="svelte-1t28d2s"&&(js.innerHTML=Vs),il=n(M),hs=J(M,"P",{"data-svelte-h":!0}),U(hs)!=="svelte-l6b7ka"&&(hs.textContent=Cs),yl=n(M),T(ds.$$.fragment,M),us=n(M),T(Rs.$$.fragment,M),Ls=n(M),is=J(M,"P",{"data-svelte-h":!0}),U(is)!=="svelte-f0n4p1"&&(is.textContent=Jl)},m(M,b){o(p,M,b),a(M,u,b),a(M,r,b),a(M,k,b),o(g,M,b),a(M,W,b),a(M,I,b),a(M,R,b),o(B,M,b),a(M,z,b),a(M,E,b),a(M,_,b),o(x,M,b),a(M,C,b),a(M,v,b),a(M,X,b),o(Q,M,b),a(M,K,b),a(M,A,b),a(M,S,b),o(Y,M,b),a(M,F,b),a(M,j,b),a(M,ys,b),o(h,M,b),a(M,$,b),o(P,M,b),a(M,Ns,b),a(M,O,b),a(M,Xs,b),a(M,ss,b),a(M,Js,b),a(M,cs,b),a(M,As,b),o(ls,M,b),a(M,Ml,b),a(M,Ts,b),a(M,zs,b),o(as,M,b),a(M,Qs,b),a(M,es,b),a(M,Ys,b),a(M,ts,b),a(M,os,b),o(Ws,M,b),a(M,Es,b),o(ns,M,b),a(M,Ss,b),a(M,Ms,b),a(M,Fs,b),o(ps,M,b),a(M,Hs,b),a(M,rs,b),a(M,ws,b),o(_s,M,b),a(M,Ds,b),a(M,ms,b),a(M,Us,b),a(M,js,b),a(M,il,b),a(M,hs,b),a(M,yl,b),o(ds,M,b),a(M,us,b),o(Rs,M,b),a(M,Ls,b),a(M,is,b),bs=!0},i(M){bs||(m(p.$$.fragment,M),m(g.$$.fragment,M),m(B.$$.fragment,M),m(x.$$.fragment,M),m(Q.$$.fragment,M),m(Y.$$.fragment,M),m(h.$$.fragment,M),m(P.$$.fragment,M),m(ls.$$.fragment,M),m(as.$$.fragment,M),m(Ws.$$.fragment,M),m(ns.$$.fragment,M),m(ps.$$.fragment,M),m(_s.$$.fragment,M),m(ds.$$.fragment,M),m(Rs.$$.fragment,M),bs=!0)},o(M){i(p.$$.fragment,M),i(g.$$.fragment,M),i(B.$$.fragment,M),i(x.$$.fragment,M),i(Q.$$.fragment,M),i(Y.$$.fragment,M),i(h.$$.fragment,M),i(P.$$.fragment,M),i(ls.$$.fragment,M),i(as.$$.fragment,M),i(Ws.$$.fragment,M),i(ns.$$.fragment,M),i(ps.$$.fragment,M),i(_s.$$.fragment,M),i(ds.$$.fragment,M),i(Rs.$$.fragment,M),bs=!1},d(M){M&&(l(u),l(r),l(k),l(W),l(I),l(R),l(z),l(E),l(_),l(C),l(v),l(X),l(K),l(A),l(S),l(F),l(j),l(ys),l($),l(Ns),l(O),l(Xs),l(ss),l(Js),l(cs),l(As),l(Ml),l(Ts),l(zs),l(Qs),l(es),l(Ys),l(ts),l(os),l(Es),l(Ss),l(Ms),l(Fs),l(Hs),l(rs),l(ws),l(Ds),l(ms),l(Us),l(js),l(il),l(hs),l(yl),l(us),l(Ls),l(is)),w(p,M),w(g,M),w(B,M),w(x,M),w(Q,M),w(Y,M),w(h,M),w(P,M),w(ls,M),w(as,M),w(Ws,M),w(ns,M),w(ps,M),w(_s,M),w(ds,M),w(Rs,M)}}}function WM(G){let p,u='🚨如果您在 TPU 上进行训练，则需要将上述所有代码移动到专门的训练函数中。有关详细信息，请参阅<a href="/course/chapter3">第三章</a>。';return{c(){p=y("p"),p.innerHTML=u},l(r){p=J(r,"P",{"data-svelte-h":!0}),U(p)!=="svelte-oal0y5"&&(p.innerHTML=u)},m(r,f){a(r,p,f)},p:tl,d(r){r&&l(p)}}}function _M(G){let p,u,r,f,k,g,W,I,Z,R,B,z,E="在本节中，我们将看看如何使用 Transformer 模型将长文档压缩为摘要，这项任务称为文本摘要.这是最具挑战性的 NLP 任务之一，因为它需要一系列能力，例如理解长篇文章和生成能够捕捉文档中主要主题的连贯文本。但是，如果做得好，文本摘要是一种强大的工具，可以减轻领域专家详细阅读长文档的负担，从而加快各种业务流程。",N,_,x,C,v='尽管在<a href="https://huggingface.co/models?pipeline_tag=summarization=downloads" rel="nofollow">Hugging Face Hub</a>上已经存在各种微调模型用于文本摘要，几乎所有这些都只适用于英文文档。因此，为了在本节中添加一些变化，我们将为英语和西班牙语训练一个双语模型。在本节结束时，您将有一个可以总结客户评论的<a href="https://huggingface.co/huggingface-course/mt5-small-finetuned-amazon-en-es" rel="nofollow">模型</a>。',L,X,Q,K,A,q="如下所示：正如我们将看到的，这些摘要很简洁，因为它们是从客户在产品评论中提供的标题中学到的。让我们首先为这项任务准备一个合适的双语语料库。",S,Y,F,j,V='我们将使用<a href="https://huggingface.co/datasets/amazon_reviews_multi" rel="nofollow">多语言亚马逊评论语料库</a>创建我们的双语摘要器。该语料库由六种语言的亚马逊产品评论组成，通常用于对多语言分类器进行基准测试。然而，由于每条评论都附有一个简短的标题，我们可以使用标题作为我们模型学习的目标摘要！首先，让我们从 Hugging Face Hub 下载英语和西班牙语子集：',ys,h,$,P,Ns,O,le='如您所见，对于每种语言，都有 200,000 条评论 <strong>train</strong> 拆分，每个评论有 5,000 条评论 <strong>validation</strong> 和 <strong>test</strong> 分裂。我们感兴趣的评论信息包含在 <strong>review_body</strong> 和 <strong>review_title</strong> 列。让我们通过创建一个简单的函数来查看一些示例，该函数使用我们在<a href="/course/chapter5">第五章</a>学到过：',Xs,ss,nl,Js,cs,fs,As,ls,Ml="此示例显示了人们通常在网上找到的评论的多样性，从正面到负面（以及介于两者之间的所有内容！）。尽管标题为“meh”的示例信息量不大，但其他标题看起来像是对评论本身的体面总结。在单个 GPU 上训练所有 400,000 条评论的摘要模型将花费太长时间，因此我们将专注于为单个产品领域生成摘要。为了了解我们可以选择哪些域，让我们将 <strong>english_dataset</strong> 转换到 <strong>pandas.DataFrame</strong> 并计算每个产品类别的评论数量：",Ts,$s,zs,as,Qs,es,ae='英语数据集中最受欢迎的产品是家居用品、服装和无线电子产品。不过，为了坚持亚马逊的主题，让我们专注于总结书籍的评论——毕竟，这是亚马逊这家公司成立的基础！我们可以看到两个符合要求的产品类别（ <strong>book</strong> 和 <strong>digital_ebook_purchase</strong> )，所以让我们为这些产品过滤两种语言的数据集。正如我们在<a href="/course/chapter5">第五章</a>学到的， 这 <strong>Dataset.filter()</strong> 函数允许我们非常有效地对数据集进行切片，因此我们可以定义一个简单的函数来执行此操作：',Ys,ts,pl,os,Ws="现在，当我们将此函数应用于 <strong>english_dataset</strong> 和 <strong>spanish_dataset</strong> ，结果将只包含涉及书籍类别的那些行。在应用过滤器之前，让我们将<strong>english_dataset</strong>的格式从 <strong>pandas</strong> 切换回到 <strong>arrow</strong> ：",Es,ns,Ss,Ms,ee="然后我们可以应用过滤器功能，作为健全性检查，让我们检查评论样本，看看它们是否确实与书籍有关：",Fs,ps,Hs,rs,rl,ws,_s="好的，我们可以看到评论并不是严格意义上的书籍，可能是指日历和 OneNote 等电子应用程序等内容。尽管如此，该领域似乎适合训练摘要模型。在我们查看适合此任务的各种模型之前，我们还有最后一点数据准备要做：将英语和西班牙语评论合并为一个 <strong>DatasetDict</strong> 目的。 🤗 Datasets 提供了一个方便的 <strong>concatenate_datasets()</strong> 函数（顾名思义）合并 <strong>Dataset</strong> 对象。因此，为了创建我们的双语数据集，我们将遍历每个拆分，连接该拆分的数据集，并打乱结果以确保我们的模型不会过度拟合单一语言：",Ds,ms,ml,Us,js,Vs,il="这当然看起来像是英语和西班牙语评论的混合！现在我们有了一个训练语料库，最后要检查的一件事是评论中单词的分布及其标题。这对于摘要任务尤其重要，其中数据中的简短参考摘要会使模型偏向于仅在生成的摘要中输出一两个单词。下面的图显示了单词分布，我们可以看到有些标题严重偏向于 1-2 个单词：",hs,Cs,yl='<img class="block dark:hidden" src="https://huggingface.co/datasets/huggingface-course/documentation-images/resolve/main/en/chapter7/review-lengths.svg" alt="Word count distributions for the review titles and texts."/> <img class="hidden dark:block" src="https://huggingface.co/datasets/huggingface-course/documentation-images/resolve/main/en/chapter7/review-lengths-dark.svg" alt="Word count distributions for the review titles and texts."/>',ds,us,Rs="为了解决这个问题，我们将过滤掉标题非常短的示例，以便我们的模型可以生成更有趣的摘要。由于我们正在处理英文和西班牙文文本，因此我们可以使用粗略的启发式方法在空白处拆分标题，然后使用我们可信赖的 <strong>Dataset.filter()</strong> 方法如下：",Ls,is,Jl,bs,M="现在我们已经准备好了我们的语料库，让我们来看看一些可以对其进行微调的可能的 Transformer 模型！",b,cl,Me,Tl,Pt='如果你仔细想想，文本摘要是一种类似于机器翻译的任务：我们有一个像评论这样的文本正文，我们希望将其“翻译”成一个较短的版本，以捕捉输入的显着特征。因此，大多数用于文本摘要的 Transformer 模型采用了我们在<a href="/course/chapter1">第一章</a>遇到的编码器-解码器架构。尽管有一些例外，例如 GPT 系列模型，它们在few-shot（少量微调）之后也可以提取摘要。下表列出了一些流行的预训练模型，可以对其进行微调以进行汇总。',pe,ol,Ot='<thead><tr><th align="center">Transformer 模型</th> <th>描述</th> <th align="center">多种语言?</th></tr></thead> <tbody><tr><td align="center"><a href="https://huggingface.co/gpt2-xl" rel="nofollow">GPT-2</a></td> <td>虽然训练为自回归语言模型，但您可以通过在输入文本末尾附加“TL;DR”来使 GPT-2 生成摘要。</td> <td align="center">❌</td></tr> <tr><td align="center"><a href="https://huggingface.co/google/pegasus-large" rel="nofollow">PEGASUS</a></td> <td>在预训练是的目标是来预测多句子文本中的屏蔽句子。 这个预训练目标比普通语言建模更接近文本摘要，并且在流行的基准测试中得分很高。</td> <td align="center">❌</td></tr> <tr><td align="center"><a href="https://huggingface.co/t5-base" rel="nofollow">T5</a></td> <td>通用的 Transformer 架构，在文本到文本的框架中制定所有任务； 例如，模型文本摘要的输入格式是<code>summarize: ARTICLE</code>。</td> <td align="center">❌</td></tr> <tr><td align="center"><a href="https://huggingface.co/google/mt5-base" rel="nofollow">mT5</a></td> <td>T5 的多语言版本，在多语言 Common Crawl 语料库 (mC4) 上进行预训练，涵盖 101 种语言。</td> <td align="center">✅</td></tr> <tr><td align="center"><a href="https://huggingface.co/facebook/bart-base" rel="nofollow">BART</a></td> <td>一种新颖的 Transformer 架构，其中包含经过训练的编码器和解码器堆栈，以重建被破坏的输入，结合了 BERT 和 GPT-2 的预训练方案。</td> <td align="center">❌</td></tr> <tr><td align="center"><a href="https://huggingface.co/facebook/mbart-large-50" rel="nofollow">mBART-50</a></td> <td>BART 的多语言版本，预训练了 50 种语言。</td> <td align="center">✅</td></tr></tbody>',re,wl,sn="从此表中可以看出，大多数用于摘要的 Transformer 模型（以及大多数 NLP 任务）都是单语的。如果您的任务是使用“有大量语料库”的语言（如英语或德语），这很好，但对于世界各地正在使用的数千种其他语言，则不然。幸运的是，有一类多语言 Transformer 模型，如 mT5 和 mBART，可以解决问题。这些模型是使用语言建模进行预训练的，但有一点不同：它们不是在一种语言的语料库上训练，而是同时在 50 多种语言的文本上进行联合训练！",me,Ul,ln="我们将使用 mT5，这是一种基于 T5 的有趣架构，在文本到文本框架中进行了预训练。在 T5 中，每个 NLP 任务都是根据提示前缀来制定的，例如 <strong>summarize:</strong> 这使模型使生成的文本适应提示。如下图所示，这让 T5 变得非常通用，因为你可以用一个模型解决很多任务！",ie,qs,an='<img class="block dark:hidden" src="https://huggingface.co/datasets/huggingface-course/documentation-images/resolve/main/en/chapter7/t5.svg" alt="Different tasks performed by the T5 architecture."/> <img class="hidden dark:block" src="https://huggingface.co/datasets/huggingface-course/documentation-images/resolve/main/en/chapter7/t5-dark.svg" alt="Different tasks performed by the T5 architecture."/>',ye,jl,en="mT5 不使用前缀，但具有 T5 的大部分功能，并且具有多语言的优势。现在我们已经选择了一个模型，让我们来看看准备我们的训练数据。",Je,Ks,ce,hl,Te,dl,oe,ul,tn="我们的下一个任务是对我们的评论及其标题进行标记和编码。像往常一样，我们首先加载与预训练模型检查点相关的标记器。我们将使用 <strong>mt5-small</strong> 作为我们的检查点，以便我们可以在合理的时间内微调模型：",we,bl,Ue,Ps,je,Il,nn="让我们在一个小例子上测试 mT5 标记器：",he,fl,de,Cl,ue,gl,Mn='在这里我们可以看到我们在<a href="/course/chapter3">第三章</a>第一次微调实验中遇到的熟悉的 <strong>input_ids</strong> 和 <strong>attention_mask</strong> .让我们用分词器解码这些输入 ID ，可以<strong>convert_ids_to_tokens()</strong> 函数来查看我们正在处理什么样的标记器：',be,Zl,Ie,Gl,fe,kl,pn='特殊的 Unicode 字符 <code>▁</code> 和序列结束标记 <code>&lt;/s&gt;</code> 表明我们正在处理 SentencePiece 分词器，它基于在<a href="/course/chapter6">第六章</a>中讨论的Unigram分词算法. Unigram 对多语言语料库特别有用，因为它允许 SentencePiece 不知道重音、标点符号以及许多语言（如日语）没有空格字符。',Ce,Bl,rn="为了标记我们的语料库，我们必须处理与摘要相关的微妙之处：因为我们的标签也是文本，所以它们可能超过模型的最大上下文大小。 这意味着我们需要对评论及其标题进行截断，以确保我们不会将过长的输入传递给我们的模型。 🤗 Transformers 中的分词器提供了一个绝妙的 <code>text_target</code> 参数，允许您将标签与输入并行分词。 以下是如何为 mT5 处理输入和目标的示例：",ge,vl,Ze,xl,mn="让我们通过这段代码来了解发生了什么。我们做的第一件事是定义值 <strong>max_input_length</strong> 和 <strong>max_target_length</strong> ，它为我们的评论和标题的长度设置了上限。由于评论正文通常比标题大得多，我们相应地调整了这些值。",Ge,$l,yn="有了 <code>preprocess_function()</code>，我们在整个课程中广泛使用的方便的 <code>Dataset.map()</code> 函数来标记整个语料库是一件简单的事情：",ke,Wl,Be,_l,Jn="既然语料库已经预处理完毕，我们来看看一些常用的摘要指标。正如我们将看到的，在衡量机器生成的文本的质量方面没有灵丹妙药。",ve,Os,xe,Vl,$e,Rl,We,Nl,cn="与我们在本课程中涵盖的大多数其他任务相比，衡量文本生成任务（如摘要或翻译）的性能并不那么简单。例如，对于“我喜欢阅读饥饿游戏”这样的评论，有多个有效摘要，例如“我喜欢饥饿游戏”或“饥饿游戏是一本好书”。显然，在生成的摘要和标签之间应用某种精确匹配并不是一个好的解决方案——即使是人类在这样的指标下也会表现不佳，因为我们都有自己的写作风格。",_e,Xl,Tn='总而言之，最常用的指标之一是<a href="https://en.wikipedia.org/wiki/ROUGE_(metric)" rel="nofollow">ROUGE 分数</a>（Recall-Oriented Understudy for Gisting Evaluation 的缩写）。该指标背后的基本思想是将生成的摘要与一组通常由人类创建的参考摘要进行比较。为了更精确，假设我们要比较以下两个摘要：',Ve,Al,Re,zl,on="比较它们的一种方法是计算重叠单词的数量，在这种情况下为 6。但是，这有点粗糙，因此 ROUGE 是基于计算计算重叠的 <em>precision</em> 和 <em>recall</em> 分数。。",Ne,sl,Xe,Ql,St,Ae,mM='<span class="katex-display"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><mrow><mi mathvariant="normal">R</mi><mi mathvariant="normal">e</mi><mi mathvariant="normal">c</mi><mi mathvariant="normal">a</mi><mi mathvariant="normal">l</mi><mi mathvariant="normal">l</mi></mrow><mo>=</mo><mfrac><mrow><mi mathvariant="normal">N</mi><mi mathvariant="normal">u</mi><mi mathvariant="normal">m</mi><mi mathvariant="normal">b</mi><mi mathvariant="normal">e</mi><mi mathvariant="normal">r</mi><mtext> </mtext><mi mathvariant="normal">o</mi><mi mathvariant="normal">f</mi><mtext> </mtext><mi mathvariant="normal">o</mi><mi mathvariant="normal">v</mi><mi mathvariant="normal">e</mi><mi mathvariant="normal">r</mi><mi mathvariant="normal">l</mi><mi mathvariant="normal">a</mi><mi mathvariant="normal">p</mi><mi mathvariant="normal">p</mi><mi mathvariant="normal">i</mi><mi mathvariant="normal">n</mi><mi mathvariant="normal">g</mi><mtext> </mtext><mi mathvariant="normal">w</mi><mi mathvariant="normal">o</mi><mi mathvariant="normal">r</mi><mi mathvariant="normal">d</mi><mi mathvariant="normal">s</mi></mrow><mrow><mi mathvariant="normal">T</mi><mi mathvariant="normal">o</mi><mi mathvariant="normal">t</mi><mi mathvariant="normal">a</mi><mi mathvariant="normal">l</mi><mtext> </mtext><mi mathvariant="normal">n</mi><mi mathvariant="normal">u</mi><mi mathvariant="normal">m</mi><mi mathvariant="normal">b</mi><mi mathvariant="normal">e</mi><mi mathvariant="normal">r</mi><mtext> </mtext><mi mathvariant="normal">o</mi><mi mathvariant="normal">f</mi><mtext> </mtext><mi mathvariant="normal">w</mi><mi mathvariant="normal">o</mi><mi mathvariant="normal">r</mi><mi mathvariant="normal">d</mi><mi mathvariant="normal">s</mi><mtext> </mtext><mi mathvariant="normal">i</mi><mi mathvariant="normal">n</mi><mtext> </mtext><mi mathvariant="normal">r</mi><mi mathvariant="normal">e</mi><mi mathvariant="normal">f</mi><mi mathvariant="normal">e</mi><mi mathvariant="normal">r</mi><mi mathvariant="normal">e</mi><mi mathvariant="normal">n</mi><mi mathvariant="normal">c</mi><mi mathvariant="normal">e</mi><mtext> </mtext><mi mathvariant="normal">s</mi><mi mathvariant="normal">u</mi><mi mathvariant="normal">m</mi><mi mathvariant="normal">m</mi><mi mathvariant="normal">a</mi><mi mathvariant="normal">r</mi><mi mathvariant="normal">y</mi></mrow></mfrac></mrow><annotation encoding="application/x-tex"> \\mathrm{Recall} = \\frac{\\mathrm{Number\\,of\\,overlapping\\, words}}{\\mathrm{Total\\, number\\, of\\, words\\, in\\, reference\\, summary}} </annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.6944em;"></span><span class="mord"><span class="mord mathrm">Recall</span></span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2778em;"></span></span><span class="base"><span class="strut" style="height:2.2519em;vertical-align:-0.8804em;"></span><span class="mord"><span class="mopen nulldelimiter"></span><span class="mfrac"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:1.3714em;"><span style="top:-2.314em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord"><span class="mord mathrm">Total</span><span class="mspace" style="margin-right:0.1667em;"></span><span class="mord mathrm">number</span><span class="mspace" style="margin-right:0.1667em;"></span><span class="mord mathrm" style="margin-right:0.07778em;">of</span><span class="mspace" style="margin-right:0.1667em;"></span><span class="mord mathrm">words</span><span class="mspace" style="margin-right:0.1667em;"></span><span class="mord mathrm">in</span><span class="mspace" style="margin-right:0.1667em;"></span><span class="mord mathrm">reference</span><span class="mspace" style="margin-right:0.1667em;"></span><span class="mord mathrm" style="margin-right:0.01389em;">summary</span></span></span></span><span style="top:-3.23em;"><span class="pstrut" style="height:3em;"></span><span class="frac-line" style="border-bottom-width:0.04em;"></span></span><span style="top:-3.677em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord"><span class="mord mathrm">Number</span><span class="mspace" style="margin-right:0.1667em;"></span><span class="mord mathrm" style="margin-right:0.07778em;">of</span><span class="mspace" style="margin-right:0.1667em;"></span><span class="mord mathrm" style="margin-right:0.01389em;">overlapping</span><span class="mspace" style="margin-right:0.1667em;"></span><span class="mord mathrm">words</span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.8804em;"><span></span></span></span></span></span><span class="mclose nulldelimiter"></span></span></span></span></span></span>',ze,Yl,Ft,Qe,iM='<span class="katex-display"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><mrow><mi mathvariant="normal">P</mi><mi mathvariant="normal">r</mi><mi mathvariant="normal">e</mi><mi mathvariant="normal">c</mi><mi mathvariant="normal">i</mi><mi mathvariant="normal">s</mi><mi mathvariant="normal">i</mi><mi mathvariant="normal">o</mi><mi mathvariant="normal">n</mi></mrow><mo>=</mo><mfrac><mrow><mi mathvariant="normal">N</mi><mi mathvariant="normal">u</mi><mi mathvariant="normal">m</mi><mi mathvariant="normal">b</mi><mi mathvariant="normal">e</mi><mi mathvariant="normal">r</mi><mtext> </mtext><mi mathvariant="normal">o</mi><mi mathvariant="normal">f</mi><mtext> </mtext><mi mathvariant="normal">o</mi><mi mathvariant="normal">v</mi><mi mathvariant="normal">e</mi><mi mathvariant="normal">r</mi><mi mathvariant="normal">l</mi><mi mathvariant="normal">a</mi><mi mathvariant="normal">p</mi><mi mathvariant="normal">p</mi><mi mathvariant="normal">i</mi><mi mathvariant="normal">n</mi><mi mathvariant="normal">g</mi><mtext> </mtext><mi mathvariant="normal">w</mi><mi mathvariant="normal">o</mi><mi mathvariant="normal">r</mi><mi mathvariant="normal">d</mi><mi mathvariant="normal">s</mi></mrow><mrow><mi mathvariant="normal">T</mi><mi mathvariant="normal">o</mi><mi mathvariant="normal">t</mi><mi mathvariant="normal">a</mi><mi mathvariant="normal">l</mi><mtext> </mtext><mi mathvariant="normal">n</mi><mi mathvariant="normal">u</mi><mi mathvariant="normal">m</mi><mi mathvariant="normal">b</mi><mi mathvariant="normal">e</mi><mi mathvariant="normal">r</mi><mtext> </mtext><mi mathvariant="normal">o</mi><mi mathvariant="normal">f</mi><mtext> </mtext><mi mathvariant="normal">w</mi><mi mathvariant="normal">o</mi><mi mathvariant="normal">r</mi><mi mathvariant="normal">d</mi><mi mathvariant="normal">s</mi><mtext> </mtext><mi mathvariant="normal">i</mi><mi mathvariant="normal">n</mi><mtext> </mtext><mi mathvariant="normal">g</mi><mi mathvariant="normal">e</mi><mi mathvariant="normal">n</mi><mi mathvariant="normal">e</mi><mi mathvariant="normal">r</mi><mi mathvariant="normal">a</mi><mi mathvariant="normal">t</mi><mi mathvariant="normal">e</mi><mi mathvariant="normal">d</mi><mtext> </mtext><mi mathvariant="normal">s</mi><mi mathvariant="normal">u</mi><mi mathvariant="normal">m</mi><mi mathvariant="normal">m</mi><mi mathvariant="normal">a</mi><mi mathvariant="normal">r</mi><mi mathvariant="normal">y</mi></mrow></mfrac></mrow><annotation encoding="application/x-tex"> \\mathrm{Precision} = \\frac{\\mathrm{Number\\,of\\,overlapping\\, words}}{\\mathrm{Total\\, number\\, of\\, words\\, in\\, generated\\, summary}} </annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.6833em;"></span><span class="mord"><span class="mord mathrm">Precision</span></span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2778em;"></span></span><span class="base"><span class="strut" style="height:2.2519em;vertical-align:-0.8804em;"></span><span class="mord"><span class="mopen nulldelimiter"></span><span class="mfrac"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:1.3714em;"><span style="top:-2.314em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord"><span class="mord mathrm">Total</span><span class="mspace" style="margin-right:0.1667em;"></span><span class="mord mathrm">number</span><span class="mspace" style="margin-right:0.1667em;"></span><span class="mord mathrm" style="margin-right:0.07778em;">of</span><span class="mspace" style="margin-right:0.1667em;"></span><span class="mord mathrm">words</span><span class="mspace" style="margin-right:0.1667em;"></span><span class="mord mathrm">in</span><span class="mspace" style="margin-right:0.1667em;"></span><span class="mord mathrm">generated</span><span class="mspace" style="margin-right:0.1667em;"></span><span class="mord mathrm" style="margin-right:0.01389em;">summary</span></span></span></span><span style="top:-3.23em;"><span class="pstrut" style="height:3em;"></span><span class="frac-line" style="border-bottom-width:0.04em;"></span></span><span style="top:-3.677em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord"><span class="mord mathrm">Number</span><span class="mspace" style="margin-right:0.1667em;"></span><span class="mord mathrm" style="margin-right:0.07778em;">of</span><span class="mspace" style="margin-right:0.1667em;"></span><span class="mord mathrm" style="margin-right:0.01389em;">overlapping</span><span class="mspace" style="margin-right:0.1667em;"></span><span class="mord mathrm">words</span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.8804em;"><span></span></span></span></span></span><span class="mclose nulldelimiter"></span></span></span></span></span></span>',Ye,El,wn="将此应用到我们的详细摘要中会得到 6/10 = 0.6 的精度，这比我们较短的摘要获得的 6/7 = 0.86 的精度要差得多。在实践中，通常计算精度和召回率，然后报告 F1-score（精度和召回率的调和平均值）。我们可以在 🤗 Datasets 中通过安装 <strong>rouge_score</strong> 包来计算他们：",Ee,Sl,Se,Fl,Un="然后按如下方式加载 ROUGE 指标：",Fe,Hl,He,Dl,jn="然后我们可以使用 <strong>rouge_score.compute()</strong> 一次性计算所有指标的函数：",De,Ll,Le,ql,qe,Kl,hn="哇，那个输出中有很多信息——这都是什么意思？首先，🤗 Datasets实际上计算了精度、召回率和 F1 分数的置信区间；这些是你可以在这里看到的 <strong>low</strong> , <strong>mid</strong> ， 和 <strong>high</strong> 属性。此外，🤗 Datasets在比较生成摘要和参考摘要时，会根据不同类型的文本粒度计算各种 ROUGE 分数。这 <strong>rouge1</strong> 变体是一元组的重叠——这只是表达单词重叠的一种奇特方式，这正是我们上面讨论的度量标准。为了验证这一点，让我们输出 <strong>mid</strong> 的数值：",Ke,Pl,Pe,Ol,Oe,sa,dn="太好了，准确率和召回率匹配了！那么其他的 ROUGE 分数呢？ <strong>rouge2</strong> 测量二元组之间的重叠（想想单词对的重叠），而 <strong>rougeL</strong> 和 <strong>rougeLsum</strong> 通过在生成的和参考摘要中查找最长的公共子串来测量最长的单词匹配序列。中的“总和” <strong>rougeLsum</strong> 指的是这个指标是在整个摘要上计算的，而 <strong>rougeL</strong> 计算为单个句子的平均值。",st,ll,lt,la,un="我们将使用这些 ROUGE 分数来跟踪我们模型的性能，但在此之前，让我们做每个优秀的 NLP 从业者都应该做的事情：创建一个强大而简单的baseline！",at,aa,et,ea,bn="文本摘要的一个常见基线是简单地取一篇文章的前三个句子，通常称为 <em>lead-3</em> 基线。 我们可以使用句号(英文使用.)来跟踪句子边界，但这在”U.S.” or “U.N.”之类的首字母缩略词上会失败。所以我们将使用 <code>nltk</code> 库，它包含一个更好的算法来处理这些情况。 您可以使用 <code>pip</code> 安装软件包，如下所示：",tt,ta,nt,na,In="然后下载标点规则：",Mt,Ma,pt,pa,fn="接下来，我们从 <code>nltk</code> 导入句子标记器并创建一个简单的函数来提取评论中的前三个句子。 文本摘要的约定是用换行符分隔每个摘要，因此我们也将其包含在内并在训练示例上对其进行测试：",rt,ra,mt,ma,it,ia,Cn="这似乎有效，所以让我们现在实现一个函数，从数据集中提取这些“摘要”并计算baseline的 ROUGE 分数：",yt,ya,Jt,Ja,gn="然后我们可以使用这个函数来计算验证集上的 ROUGE 分数，并使用 Pandas 对它们进行一些美化：",ct,ca,Tt,Ta,ot,oa,Zn="我们可以看到<code>rouge2</code>的分数明显低于其他； 这可能反映了这样一个事实，即评论标题通常很简洁，因此lead-3 baseline过于冗长。 现在我们有了一个很好的基准，让我们将注意力转向微调 mT5！",wt,gs,Zs,Ha,al,Ut,wa,Gn="我们需要做的下一件事是登录 Hugging Face Hub。如果您在notebook中运行此代码，则可以使用以下实用程序函数执行此操作：",jt,Ua,ht,ja,kn="这将显示一个小部件，您可以在其中输入您的凭据。或者，您可以在终端中运行此命令并在那里登录：",dt,ha,ut,Da,da,Bn='接下来，我们需要为我们的序列到序列任务定义一个数据整理器。由于 mT5 是一个编码器-解码器 Transformer 模型，准备我们的批次的一个微妙之处是，在解码过程中，我们需要将标签向右移动一个。 这是为了确保解码器只看到之前的真实的标签，而不是当前或未来的标签，这对于模型来说很容易记忆。 这类似于在 <a href="/course/chapter7/6">因果语言建模</a> 等任务中如何将掩蔽的自我注意应用于输入。',bt,ua,vn="幸运的是，🤗 Transformers 提供了一个 <code>DataCollatorForSeq2Seq</code> 整理器，它将为我们动态填充输入和标签。 要实例化这个收集器，我们只需要提供 <code>tokenizer</code> 和 <code>model</code>：",It,Gs,ks,La,ba,xn="让我们看看这个整理器在输入一小批示例时会产生什么。 首先，我们需要删除带有字符串的列，因为整理器不知道如何填充这些元素：",ft,Ia,Ct,fa,$n="由于 collator 需要一个 <code>dict</code> 的列表，其中每个 <code>dict</code> 代表数据集中的一个示例，我们还需要在将数据传递给 data collator 之前将数据整理成预期的格式：",gt,Ca,Zt,ga,Gt,Za,Wn="这里要注意的主要是第一个例子比第二个例子要长，所以第二个例子的 <code>input_ids</code> 和 <code>attention_mask</code> 已经在右侧填充了一个 <code>[PAD]</code> 标记（其 ID 是 <code>0</code>）。 类似地，我们可以看到 <code>labels</code> 已用 <code>-100</code> 填充，以确保填充标记被损失函数忽略。 最后，我们可以看到一个新的 <code>decoder_input_ids</code>，它通过在第一个条目中插入 <code>[PAD]</code> 标记将标签向右移动。",kt,Bs,vs,qa,Ka,Ga,Bt,ka,_n="将模型推送到 Hub 后，您可以通过推理小部件或“管道”对象来使用它，如下所示：",vt,Ba,xt,va,Vn="我们可以将测试集中的一些示例（模型还没有看到）提供给我们的管道，以了解生成摘要的质量。 首先让我们实现一个简单的函数来一起显示评论、标题和生成的摘要：",$t,xa,Wt,$a,Rn="让我们看一下我们得到的一个英文例子：",_t,Wa,Vt,_a,Rt,Va,Nn="这还不错！ 我们可以看到，我们的模型实际上已经能够通过增加部分新词来执行抽象摘要。 也许我们模型最酷的方面是它是双语的，所以我们还可以生成西班牙语评论的摘要：",Nt,Ra,Xt,Na,At,Xa,Xn="摘要翻译成了英文的“非常容易阅读”，在这种情况下，我们可以看到它是直接从评论中提取的。 这显示了 mT5 模型的多功能性，并让您体验了处理多语言语料库的感觉！",zt,Aa,An="接下来，我们将把注意力转向稍微复杂的任务：从头开始训练语言模型。",Qt,za,Yt,te,Et;k=new UM({props:{fw:G[0]}}),W=new Is({props:{title:"提取文本摘要",local:"提取文本摘要",headingTag:"h1"}});const zn=[dM,hM],Qa=[];function Qn(s,e){return s[0]==="pt"?0:1}Z=Qn(G),R=Qa[Z]=zn[Z](G),_=new Kt({props:{id:"yHnr5Dk2zCI"}}),Y=new Is({props:{title:"准备多语言语料库",local:"准备多语言语料库",headingTag:"h2"}}),h=new d({props:{code:"ZnJvbSUyMGRhdGFzZXRzJTIwaW1wb3J0JTIwbG9hZF9kYXRhc2V0JTBBJTBBc3BhbmlzaF9kYXRhc2V0JTIwJTNEJTIwbG9hZF9kYXRhc2V0KCUyMmFtYXpvbl9yZXZpZXdzX211bHRpJTIyJTJDJTIwJTIyZXMlMjIpJTBBZW5nbGlzaF9kYXRhc2V0JTIwJTNEJTIwbG9hZF9kYXRhc2V0KCUyMmFtYXpvbl9yZXZpZXdzX211bHRpJTIyJTJDJTIwJTIyZW4lMjIpJTBBZW5nbGlzaF9kYXRhc2V0",highlighted:`<span class="hljs-keyword">from</span> datasets <span class="hljs-keyword">import</span> load_dataset

spanish_dataset = load_dataset(<span class="hljs-string">&quot;amazon_reviews_multi&quot;</span>, <span class="hljs-string">&quot;es&quot;</span>)
english_dataset = load_dataset(<span class="hljs-string">&quot;amazon_reviews_multi&quot;</span>, <span class="hljs-string">&quot;en&quot;</span>)
english_dataset`,wrap:!1}}),P=new d({props:{code:"RGF0YXNldERpY3QoJTdCJTBBJTIwJTIwJTIwJTIwdHJhaW4lM0ElMjBEYXRhc2V0KCU3QiUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMGZlYXR1cmVzJTNBJTIwJTVCJ3Jldmlld19pZCclMkMlMjAncHJvZHVjdF9pZCclMkMlMjAncmV2aWV3ZXJfaWQnJTJDJTIwJ3N0YXJzJyUyQyUyMCdyZXZpZXdfYm9keSclMkMlMjAncmV2aWV3X3RpdGxlJyUyQyUyMCdsYW5ndWFnZSclMkMlMjAncHJvZHVjdF9jYXRlZ29yeSclNUQlMkMlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBudW1fcm93cyUzQSUyMDIwMDAwMCUwQSUyMCUyMCUyMCUyMCU3RCklMEElMjAlMjAlMjAlMjB2YWxpZGF0aW9uJTNBJTIwRGF0YXNldCglN0IlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBmZWF0dXJlcyUzQSUyMCU1QidyZXZpZXdfaWQnJTJDJTIwJ3Byb2R1Y3RfaWQnJTJDJTIwJ3Jldmlld2VyX2lkJyUyQyUyMCdzdGFycyclMkMlMjAncmV2aWV3X2JvZHknJTJDJTIwJ3Jldmlld190aXRsZSclMkMlMjAnbGFuZ3VhZ2UnJTJDJTIwJ3Byb2R1Y3RfY2F0ZWdvcnknJTVEJTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwbnVtX3Jvd3MlM0ElMjA1MDAwJTBBJTIwJTIwJTIwJTIwJTdEKSUwQSUyMCUyMCUyMCUyMHRlc3QlM0ElMjBEYXRhc2V0KCU3QiUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMGZlYXR1cmVzJTNBJTIwJTVCJ3Jldmlld19pZCclMkMlMjAncHJvZHVjdF9pZCclMkMlMjAncmV2aWV3ZXJfaWQnJTJDJTIwJ3N0YXJzJyUyQyUyMCdyZXZpZXdfYm9keSclMkMlMjAncmV2aWV3X3RpdGxlJyUyQyUyMCdsYW5ndWFnZSclMkMlMjAncHJvZHVjdF9jYXRlZ29yeSclNUQlMkMlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBudW1fcm93cyUzQSUyMDUwMDAlMEElMjAlMjAlMjAlMjAlN0QpJTBBJTdEKQ==",highlighted:`DatasetDict({
    train: Dataset({
        features: [<span class="hljs-string">&#x27;review_id&#x27;</span>, <span class="hljs-string">&#x27;product_id&#x27;</span>, <span class="hljs-string">&#x27;reviewer_id&#x27;</span>, <span class="hljs-string">&#x27;stars&#x27;</span>, <span class="hljs-string">&#x27;review_body&#x27;</span>, <span class="hljs-string">&#x27;review_title&#x27;</span>, <span class="hljs-string">&#x27;language&#x27;</span>, <span class="hljs-string">&#x27;product_category&#x27;</span>],
        num_rows: <span class="hljs-number">200000</span>
    })
    validation: Dataset({
        features: [<span class="hljs-string">&#x27;review_id&#x27;</span>, <span class="hljs-string">&#x27;product_id&#x27;</span>, <span class="hljs-string">&#x27;reviewer_id&#x27;</span>, <span class="hljs-string">&#x27;stars&#x27;</span>, <span class="hljs-string">&#x27;review_body&#x27;</span>, <span class="hljs-string">&#x27;review_title&#x27;</span>, <span class="hljs-string">&#x27;language&#x27;</span>, <span class="hljs-string">&#x27;product_category&#x27;</span>],
        num_rows: <span class="hljs-number">5000</span>
    })
    test: Dataset({
        features: [<span class="hljs-string">&#x27;review_id&#x27;</span>, <span class="hljs-string">&#x27;product_id&#x27;</span>, <span class="hljs-string">&#x27;reviewer_id&#x27;</span>, <span class="hljs-string">&#x27;stars&#x27;</span>, <span class="hljs-string">&#x27;review_body&#x27;</span>, <span class="hljs-string">&#x27;review_title&#x27;</span>, <span class="hljs-string">&#x27;language&#x27;</span>, <span class="hljs-string">&#x27;product_category&#x27;</span>],
        num_rows: <span class="hljs-number">5000</span>
    })
})`,wrap:!1}}),ss=new d({props:{code:"ZGVmJTIwc2hvd19zYW1wbGVzKGRhdGFzZXQlMkMlMjBudW1fc2FtcGxlcyUzRDMlMkMlMjBzZWVkJTNENDIpJTNBJTBBJTIwJTIwJTIwJTIwc2FtcGxlJTIwJTNEJTIwZGF0YXNldCU1QiUyMnRyYWluJTIyJTVELnNodWZmbGUoc2VlZCUzRHNlZWQpLnNlbGVjdChyYW5nZShudW1fc2FtcGxlcykpJTBBJTIwJTIwJTIwJTIwZm9yJTIwZXhhbXBsZSUyMGluJTIwc2FtcGxlJTNBJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwcHJpbnQoZiUyMiU1Q24nJTNFJTNFJTIwVGl0bGUlM0ElMjAlN0JleGFtcGxlJTVCJ3Jldmlld190aXRsZSclNUQlN0QnJTIyKSUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMHByaW50KGYlMjInJTNFJTNFJTIwUmV2aWV3JTNBJTIwJTdCZXhhbXBsZSU1QidyZXZpZXdfYm9keSclNUQlN0QnJTIyKSUwQSUwQSUwQXNob3dfc2FtcGxlcyhlbmdsaXNoX2RhdGFzZXQp",highlighted:`<span class="hljs-keyword">def</span> <span class="hljs-title function_">show_samples</span>(<span class="hljs-params">dataset, num_samples=<span class="hljs-number">3</span>, seed=<span class="hljs-number">42</span></span>):
    sample = dataset[<span class="hljs-string">&quot;train&quot;</span>].shuffle(seed=seed).select(<span class="hljs-built_in">range</span>(num_samples))
    <span class="hljs-keyword">for</span> example <span class="hljs-keyword">in</span> sample:
        <span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;\\n&#x27;&gt;&gt; Title: <span class="hljs-subst">{example[<span class="hljs-string">&#x27;review_title&#x27;</span>]}</span>&#x27;&quot;</span>)
        <span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;&#x27;&gt;&gt; Review: <span class="hljs-subst">{example[<span class="hljs-string">&#x27;review_body&#x27;</span>]}</span>&#x27;&quot;</span>)


show_samples(english_dataset)`,wrap:!1}}),Js=new d({props:{code:"JyUzRSUzRSUyMFRpdGxlJTNBJTIwV29ya2VkJTIwaW4lMjBmcm9udCUyMHBvc2l0aW9uJTJDJTIwbm90JTIwcmVhciclMEEnJTNFJTNFJTIwUmV2aWV3JTNBJTIwMyUyMHN0YXJzJTIwYmVjYXVzZSUyMHRoZXNlJTIwYXJlJTIwbm90JTIwcmVhciUyMGJyYWtlcyUyMGFzJTIwc3RhdGVkJTIwaW4lMjB0aGUlMjBpdGVtJTIwZGVzY3JpcHRpb24uJTIwQXQlMjBsZWFzdCUyMHRoZSUyMG1vdW50JTIwYWRhcHRlciUyMG9ubHklMjB3b3JrZWQlMjBvbiUyMHRoZSUyMGZyb250JTIwZm9yayUyMG9mJTIwdGhlJTIwYmlrZSUyMHRoYXQlMjBJJTIwZ290JTIwaXQlMjBmb3IuJyUwQSUwQSclM0UlM0UlMjBUaXRsZSUzQSUyMG1laCclMEEnJTNFJTNFJTIwUmV2aWV3JTNBJTIwRG9lcyUyMGl0JUUyJTgwJTk5cyUyMGpvYiUyMGFuZCUyMGl0JUUyJTgwJTk5cyUyMGdvcmdlb3VzJTIwYnV0JTIwbWluZSUyMGlzJTIwZmFsbGluZyUyMGFwYXJ0JTJDJTIwSSUyMGhhZCUyMHRvJTIwYmFzaWNhbGx5JTIwcHV0JTI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yUyMG5vdCUyMGFzJTIwaGVhdnklMjBhcyUyMGElMjBtZXRhbCUyMGZyYW1lJTJDJTIwc28lMjB5b3UlMjBjYW4lMjBlYXNpbHklMjBtb3VudCUyMGl0JTIwdG8lMjB0aGUlMjB3YWxsJTIwYW5kJTIwc3RpbGwlMjBsb2FkJTIwaXQlMjB1cCUyMHdpdGglMjBoZWF2eSUyMHN0dWZmJTJDJTIwb3IlMjBsaWdodCUyMHN0dWZmLiUyME5vJTIwcHJvYmxlbSUyMHRoZXJlLiUyMEZvciUyMHRoZSUyMG1vbmV5JTJDJTIweW91JTIwY2FuJTVDJ3QlMjBiZWF0JTIwaXQuJTIwQmVzdCUyMG9uZSUyMG9mJTIwdGhlc2UlMjBJJTVDJ3ZlJTIwYm91Z2h0JTIwdG8lMjBkYXRlLS0lMjBhbmQlMjBJJTVDJ3ZlJTIwYmVlbiUyMHVzaW5nJTIwc29tZSUyMHZlcnNpb24lMjBvZiUyMHRoZXNlJTIwZm9yJTIwb3ZlciUyMGZvcnR5JTIweWVhcnMuJw==",highlighted:`<span class="hljs-string">&#x27;&gt;&gt; Title: Worked in front position, not rear&#x27;</span>
<span class="hljs-string">&#x27;&gt;&gt; Review: 3 stars because these are not rear brakes as stated in the item description. At least the mount adapter only worked on the front fork of the bike that I got it for.&#x27;</span>

<span class="hljs-string">&#x27;&gt;&gt; Title: meh&#x27;</span>
<span class="hljs-string">&#x27;&gt;&gt; Review: Does it’s job and it’s gorgeous but mine is falling apart, I had to basically put it together again with hot glue&#x27;</span>

<span class="hljs-string">&#x27;&gt;&gt; Title: Can\\&#x27;t beat these for the money&#x27;</span>
<span class="hljs-string">&#x27;&gt;&gt; Review: Bought this for handling miscellaneous aircraft parts and hanger &quot;stuff&quot; that I needed to organize; it really fit the bill. The unit arrived quickly, was well packaged and arrived intact (always a good sign). There are five wall mounts-- three on the top and two on the bottom. I wanted to mount it on the wall, so all I had to do was to remove the top two layers of plastic drawers, as well as the bottom corner drawers, place it when I wanted and mark it; I then used some of the new plastic screw in wall anchors (the 50 pound variety) and it easily mounted to the wall. Some have remarked that they wanted dividers for the drawers, and that they made those. Good idea. My application was that I needed something that I can see the contents at about eye level, so I wanted the fuller-sized drawers. I also like that these are the new plastic that doesn\\&#x27;t get brittle and split like my older plastic drawers did. I like the all-plastic construction. It\\&#x27;s heavy duty enough to hold metal parts, but being made of plastic it\\&#x27;s not as heavy as a metal frame, so you can easily mount it to the wall and still load it up with heavy stuff, or light stuff. No problem there. For the money, you can\\&#x27;t beat it. Best one of these I\\&#x27;ve bought to date-- and I\\&#x27;ve been using some version of these for over forty years.&#x27;</span>`,wrap:!1}}),fs=new el({props:{$$slots:{default:[uM]},$$scope:{ctx:G}}}),$s=new d({props:{code:"ZW5nbGlzaF9kYXRhc2V0LnNldF9mb3JtYXQoJTIycGFuZGFzJTIyKSUwQWVuZ2xpc2hfZGYlMjAlM0QlMjBlbmdsaXNoX2RhdGFzZXQlNUIlMjJ0cmFpbiUyMiU1RCU1QiUzQSU1RCUwQSUyMyUyMFNob3clMjBjb3VudHMlMjBmb3IlMjB0b3AlMjAyMCUyMHByb2R1Y3RzJTBBZW5nbGlzaF9kZiU1QiUyMnByb2R1Y3RfY2F0ZWdvcnklMjIlNUQudmFsdWVfY291bnRzKCklNUIlM0EyMCU1RA==",highlighted:`english_dataset.set_format(<span class="hljs-string">&quot;pandas&quot;</span>)
english_df = english_dataset[<span class="hljs-string">&quot;train&quot;</span>][:]
<span class="hljs-comment"># Show counts for top 20 products</span>
english_df[<span class="hljs-string">&quot;product_category&quot;</span>].value_counts()[:<span class="hljs-number">20</span>]`,wrap:!1}}),as=new d({props:{code:"aG9tZSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMDE3Njc5JTBBYXBwYXJlbCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUy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aWdpdGFsX2Vib29rX3B1cmNoYXNlJTIwJTIwJTIwJTIwJTIwNjc0OSUwQXBjJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwNjQwMSUwQWVsZWN0cm9uaWNzJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwNjE4NiUwQW9mZmljZV9wcm9kdWN0JTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwNTUyMSUwQXNob2VzJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwNTE5NyUwQWdyb2NlcnklMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjA0NzMwJTBBYm9vayUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMDM3NTYlMEFOYW1lJTNBJTIwcHJvZHVjdF9jYXRlZ29yeSUyQyUyMGR0eXBlJTNBJTIwaW50NjQ=",highlighted:`home                      <span class="hljs-number">17679</span>
apparel                   <span class="hljs-number">15951</span>
wireless                  <span class="hljs-number">15717</span>
other                     <span class="hljs-number">13418</span>
beauty                    <span class="hljs-number">12091</span>
drugstore                 <span class="hljs-number">11730</span>
kitchen                   <span class="hljs-number">10382</span>
toy                        <span class="hljs-number">8745</span>
sports                     <span class="hljs-number">8277</span>
automotive                 <span class="hljs-number">7506</span>
lawn_and_garden            <span class="hljs-number">7327</span>
home_improvement           <span class="hljs-number">7136</span>
pet_products               <span class="hljs-number">7082</span>
digital_ebook_purchase     <span class="hljs-number">6749</span>
pc                         <span class="hljs-number">6401</span>
electronics                <span class="hljs-number">6186</span>
office_product             <span class="hljs-number">5521</span>
shoes                      <span class="hljs-number">5197</span>
grocery                    <span class="hljs-number">4730</span>
book                       <span class="hljs-number">3756</span>
Name: product_category, dtype: int64`,wrap:!1}}),ts=new d({props:{code:"ZGVmJTIwZmlsdGVyX2Jvb2tzKGV4YW1wbGUpJTNBJTBBJTIwJTIwJTIwJTIwcmV0dXJuJTIwKCUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMGV4YW1wbGUlNUIlMjJwcm9kdWN0X2NhdGVnb3J5JTIyJTVEJTIwJTNEJTNEJTIwJTIyYm9vayUyMiUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMG9yJTIwZXhhbXBsZSU1QiUyMnByb2R1Y3RfY2F0ZWdvcnklMjIlNUQlMjAlM0QlM0QlMjAlMjJkaWdpdGFsX2Vib29rX3B1cmNoYXNlJTIyJTBBJTIwJTIwJTIwJTIwKQ==",highlighted:`<span class="hljs-keyword">def</span> <span class="hljs-title function_">filter_books</span>(<span class="hljs-params">example</span>):
    <span class="hljs-keyword">return</span> (
        example[<span class="hljs-string">&quot;product_category&quot;</span>] == <span class="hljs-string">&quot;book&quot;</span>
        <span class="hljs-keyword">or</span> example[<span class="hljs-string">&quot;product_category&quot;</span>] == <span class="hljs-string">&quot;digital_ebook_purchase&quot;</span>
    )`,wrap:!1}}),ns=new d({props:{code:"ZW5nbGlzaF9kYXRhc2V0LnJlc2V0X2Zvcm1hdCgp",highlighted:"english_dataset.reset_format()",wrap:!1}}),ps=new d({props:{code:"c3BhbmlzaF9ib29rcyUyMCUzRCUyMHNwYW5pc2hfZGF0YXNldC5maWx0ZXIoZmlsdGVyX2Jvb2tzKSUwQWVuZ2xpc2hfYm9va3MlMjAlM0QlMjBlbmdsaXNoX2RhdGFzZXQuZmlsdGVyKGZpbHRlcl9ib29rcyklMEFzaG93X3NhbXBsZXMoZW5nbGlzaF9ib29rcyk=",highlighted:`spanish_books = spanish_dataset.<span class="hljs-built_in">filter</span>(filter_books)
english_books = english_dataset.<span class="hljs-built_in">filter</span>(filter_books)
show_samples(english_books)`,wrap:!1}}),rs=new d({props:{code:"JyUzRSUzRSUyMFRpdGxlJTNBJTIwSSU1QydtJTIwZGlzc2Fwb2ludGVkLiclMEEnJTNFJTNFJTIwUmV2aWV3JTNBJTIwSSUyMGd1ZXNzJTIwSSUyMGhhZCUyMGhpZ2hlciUyMGV4cGVjdGF0aW9ucyUyMGZvciUyMHRoaXMlMjBib29rJTIwZnJvbSUyMHRoZSUyMHJldmlld3MuJTIwSSUyMHJlYWxseSUyMHRob3VnaHQlMjBJJTVDJ2QlMjBhdCUyMGxlYXN0JTIwbGlrZSUyMGl0LiUyMFRoZSUyMHBsb3QlMjBpZGVhJTIwd2FzJTIwZ3JlYXQuJTIwSSUyMGxvdmVkJTIwQXNoJTIwYnV0JTJDJTIwaXQlMjBqdXN0JTIwZGlkbnQlMjBnbyUyMGFueXdoZXJlLiUyME1vc3QlMjBvZiUyMHRoZSUyMGJvb2slMjB3YXMlMjBhYm91dCUyMHRoZWlyJTIwcmFkaW8lMjBzaG93JTIwYW5kJTIwdGFsa2luZyUyMHRvJTIwY2FsbGVycy4lMjBJJTIwd2FudGVkJTIwdGhlJTIwYXV0aG9yJTIwdG8lMjBkaWclMjBkZWVwZXIlMjBzbyUyMHdlJTIwY291bGQlMjByZWFsbHklMjBnZXQlMjB0byUyMGtub3clMjB0aGUlMjBjaGFyYWN0ZXJzLiUyMEFsbCUyMHdlJTIwa25vdyUyMGFib3V0JTIwR3JhY2UlMjBpcyUyMHRoYXQlMjBzaGUlMjBpcyUyMGF0dHJhY3RpdmUlMjBsb29raW5nJTJDJTIwTGF0aW5vJTIwYW5kJTIwaXMlMjBraW5kJTIwb2YlMjBhJTIwYnJhdC4lMjBJJTVDJ20lMjBkaXNzYXBvaW50ZWQuJyUwQSUwQSclM0UlM0UlMjBUaXRsZSUzQSUyMEdvb2QlMjBhcnQlMkMlMjB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-string">&#x27;&gt;&gt; Title: I\\&#x27;m dissapointed.&#x27;</span>
<span class="hljs-string">&#x27;&gt;&gt; Review: I guess I had higher expectations for this book from the reviews. I really thought I\\&#x27;d at least like it. The plot idea was great. I loved Ash but, it just didnt go anywhere. Most of the book was about their radio show and talking to callers. I wanted the author to dig deeper so we could really get to know the characters. All we know about Grace is that she is attractive looking, Latino and is kind of a brat. I\\&#x27;m dissapointed.&#x27;</span>

<span class="hljs-string">&#x27;&gt;&gt; Title: Good art, good price, poor design&#x27;</span>
<span class="hljs-string">&#x27;&gt;&gt; Review: I had gotten the DC Vintage calendar the past two years, but it was on backorder forever this year and I saw they had shrunk the dimensions for no good reason. This one has good art choices but the design has the fold going through the picture, so it\\&#x27;s less aesthetically pleasing, especially if you want to keep a picture to hang. For the price, a good calendar&#x27;</span>

<span class="hljs-string">&#x27;&gt;&gt; Title: Helpful&#x27;</span>
<span class="hljs-string">&#x27;&gt;&gt; Review: Nearly all the tips useful and. I consider myself an intermediate to advanced user of OneNote. I would highly recommend.&#x27;</span>`,wrap:!1}}),ms=new d({props:{code:"ZnJvbSUyMGRhdGFzZXRzJTIwaW1wb3J0JTIwY29uY2F0ZW5hdGVfZGF0YXNldHMlMkMlMjBEYXRhc2V0RGljdCUwQSUwQWJvb2tzX2RhdGFzZXQlMjAlM0QlMjBEYXRhc2V0RGljdCgpJTBBJTBBZm9yJTIwc3BsaXQlMjBpbiUyMGVuZ2xpc2hfYm9va3Mua2V5cygpJTNBJTBBJTIwJTIwJTIwJTIwYm9va3NfZGF0YXNldCU1QnNwbGl0JTVEJTIwJTNEJTIwY29uY2F0ZW5hdGVfZGF0YXNldHMoJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTVCZW5nbGlzaF9ib29rcyU1QnNwbGl0JTVEJTJDJTIwc3BhbmlzaF9ib29rcyU1QnNwbGl0JTVEJTVEJTBBJTIwJTIwJTIwJTIwKSUwQSUyMCUyMCUyMCUyMGJvb2tzX2RhdGFzZXQlNUJzcGxpdCU1RCUyMCUzRCUyMGJvb2tzX2RhdGFzZXQlNUJzcGxpdCU1RC5zaHVmZmxlKHNlZWQlM0Q0MiklMEElMEElMjMlMjBQZWVrJTIwYXQlMjBhJTIwZmV3JTIwZXhhbXBsZXMlMEFzaG93X3NhbXBsZXMoYm9va3NfZGF0YXNldCk=",highlighted:`<span class="hljs-keyword">from</span> datasets <span class="hljs-keyword">import</span> concatenate_datasets, DatasetDict

books_dataset = DatasetDict()

<span class="hljs-keyword">for</span> split <span class="hljs-keyword">in</span> english_books.keys():
    books_dataset[split] = concatenate_datasets(
        [english_books[split], spanish_books[split]]
    )
    books_dataset[split] = books_dataset[split].shuffle(seed=<span class="hljs-number">42</span>)

<span class="hljs-comment"># Peek at a few examples</span>
show_samples(books_dataset)`,wrap:!1}}),Us=new d({props:{code:"JyUzRSUzRSUyMFRpdGxlJTNBJTIwRWFzeSUyMHRvJTIwZm9sbG93ISEhISclMEEnJTNFJTNFJTIwUmV2aWV3JTNBJTIwSSUyMGxvdmVkJTIwVGhlJTIwZGFzaCUyMGRpZXQlMjB3ZWlnaHQlMjBsb3NzJTIwU29sdXRpb24uJTIwTmV2ZXIlMjBodW5ncnkuJTIwSSUyMHdvdWxkJTIwcmVjb21tZW5kJTIwdGhpcyUyMGRpZXQuJTIwQWxzbyUyMHRoZSUyMG1lbnVzJTIwYXJlJTIwd2VsbCUyMHJvdW5kZWQuJTIwVHJ5JTIwaXQuJTIwSGFzJTIwbG90cyUyMG9mJTIwdGhlJTIwaW5mb3JtYXRpb24lMjBuZWVkJTIwdGhhbmtzLiclMEElMEEnJTNFJTNFJTIwVGl0bGUlM0ElMjBQQVJDSUFMTUVOVEUlMjBEQSVDMyU5MUFETyclMEEnJTNFJTNFJTIwUmV2aWV3JTNBJTIwTWUlMjBsbGVnJUMzJUIzJTIwZWwlMjBkJUMzJUFEYSUyMHF1ZSUyMHRvY2FiYSUyQyUyMGp1bnRvJTIwYSUyMG90cm9zJTIwbGlicm9zJTIwcXVlJTIwcGVkJUMzJUFEJTJDJTIwcGVybyUyMGxhJTIwY2FqYSUyMGxsZWclQzMlQjMlMjBlbiUyMG1hbCUyMGVzdGFkbyUyMGxvJTIwY3VhbCUyMGRhJUMzJUIxJUMzJUIzJTIwbGFzJTIwZXNxdWluYXMlMjBkZSUyMGxvcyUyMGxpYnJvcyUyMHBvcnF1ZSUyMHZlbiVDMyVBRGFuJTIwc2luJTIwcHJvdGVjY2klQzMlQjNuJTIwKGZvcnJvKS4nJTBBJTBBJyUzRSUzRSUyMFRpdGxlJTNBJTIwbm8lMjBsbyUyMGhlJTIwcG9kaWRvJTIwZGVzY2FyZ2FyJyUwQSclM0UlM0UlMjBSZXZpZXclM0ElMjBpZ3VhbCUyMHF1ZSUyMGVsJTIwYW50ZXJpb3In",highlighted:`<span class="hljs-string">&#x27;&gt;&gt; Title: Easy to follow!!!!&#x27;</span>
<span class="hljs-string">&#x27;&gt;&gt; Review: I loved The dash diet weight loss Solution. Never hungry. I would recommend this diet. Also the menus are well rounded. Try it. Has lots of the information need thanks.&#x27;</span>

<span class="hljs-string">&#x27;&gt;&gt; Title: PARCIALMENTE DAÑADO&#x27;</span>
<span class="hljs-string">&#x27;&gt;&gt; Review: Me llegó el día que tocaba, junto a otros libros que pedí, pero la caja llegó en mal estado lo cual dañó las esquinas de los libros porque venían sin protección (forro).&#x27;</span>

<span class="hljs-string">&#x27;&gt;&gt; Title: no lo he podido descargar&#x27;</span>
<span class="hljs-string">&#x27;&gt;&gt; Review: igual que el anterior&#x27;</span>`,wrap:!1}}),is=new d({props:{code:"Ym9va3NfZGF0YXNldCUyMCUzRCUyMGJvb2tzX2RhdGFzZXQuZmlsdGVyKGxhbWJkYSUyMHglM0ElMjBsZW4oeCU1QiUyMnJldmlld190aXRsZSUyMiU1RC5zcGxpdCgpKSUyMCUzRSUyMDIp",highlighted:'books_dataset = books_dataset.<span class="hljs-built_in">filter</span>(<span class="hljs-keyword">lambda</span> x: <span class="hljs-built_in">len</span>(x[<span class="hljs-string">&quot;review_title&quot;</span>].split()) &gt; <span class="hljs-number">2</span>)',wrap:!1}}),cl=new Is({props:{title:"文本摘要模型",local:"文本摘要模型",headingTag:"h2"}}),Ks=new el({props:{$$slots:{default:[bM]},$$scope:{ctx:G}}}),hl=new Is({props:{title:"预处理数据",local:"预处理数据",headingTag:"h2"}}),dl=new Kt({props:{id:"1m7BerpSq8A"}}),bl=new d({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9Ub2tlbml6ZXIlMEElMEFtb2RlbF9jaGVja3BvaW50JTIwJTNEJTIwJTIyZ29vZ2xlJTJGbXQ1LXNtYWxsJTIyJTBBdG9rZW5pemVyJTIwJTNEJTIwQXV0b1Rva2VuaXplci5mcm9tX3ByZXRyYWluZWQobW9kZWxfY2hlY2twb2ludCk=",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoTokenizer

model_checkpoint = <span class="hljs-string">&quot;google/mt5-small&quot;</span>
tokenizer = AutoTokenizer.from_pretrained(model_checkpoint)`,wrap:!1}}),Ps=new el({props:{$$slots:{default:[IM]},$$scope:{ctx:G}}}),fl=new d({props:{code:"aW5wdXRzJTIwJTNEJTIwdG9rZW5pemVyKCUyMkklMjBsb3ZlZCUyMHJlYWRpbmclMjB0aGUlMjBIdW5nZXIlMjBHYW1lcyElMjIpJTBBaW5wdXRz",highlighted:`inputs = tokenizer(<span class="hljs-string">&quot;I loved reading the Hunger Games!&quot;</span>)
inputs`,wrap:!1}}),Cl=new d({props:{code:"JTdCJ2lucHV0X2lkcyclM0ElMjAlNUIzMzYlMkMlMjAyNTklMkMlMjAyODM4NyUyQyUyMDExODA3JTJDJTIwMjg3JTJDJTIwNjI4OTMlMkMlMjAyOTUlMkMlMjAxMjUwNyUyQyUyMDElNUQlMkMlMjAnYXR0ZW50aW9uX21hc2snJTNBJTIwJTVCMSUyQyUyMDElMkMlMjAxJTJDJTIwMSUyQyUyMDElMkMlMjAxJTJDJTIwMSUyQyUyMDElMkMlMjAxJTVEJTdE",highlighted:'{<span class="hljs-string">&#x27;input_ids&#x27;</span>: [<span class="hljs-number">336</span>, <span class="hljs-number">259</span>, <span class="hljs-number">28387</span>, <span class="hljs-number">11807</span>, <span class="hljs-number">287</span>, <span class="hljs-number">62893</span>, <span class="hljs-number">295</span>, <span class="hljs-number">12507</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>]}',wrap:!1}}),Zl=new d({props:{code:"dG9rZW5pemVyLmNvbnZlcnRfaWRzX3RvX3Rva2VucyhpbnB1dHMuaW5wdXRfaWRzKQ==",highlighted:"tokenizer.convert_ids_to_tokens(inputs.input_ids)",wrap:!1}}),Gl=new d({props:{code:"JTVCJyVFMiU5NiU4MUknJTJDJTIwJyVFMiU5NiU4MSclMkMlMjAnbG92ZWQnJTJDJTIwJyVFMiU5NiU4MXJlYWRpbmcnJTJDJTIwJyVFMiU5NiU4MXRoZSclMkMlMjAnJUUyJTk2JTgxSHVuZyclMkMlMjAnZXInJTJDJTIwJyVFMiU5NiU4MUdhbWVzJyUyQyUyMCclM0MlMkZzJTNFJyU1RA==",highlighted:'[<span class="hljs-string">&#x27;▁I&#x27;</span>, <span class="hljs-string">&#x27;▁&#x27;</span>, <span class="hljs-string">&#x27;loved&#x27;</span>, <span class="hljs-string">&#x27;▁reading&#x27;</span>, <span class="hljs-string">&#x27;▁the&#x27;</span>, <span class="hljs-string">&#x27;▁Hung&#x27;</span>, <span class="hljs-string">&#x27;er&#x27;</span>, <span class="hljs-string">&#x27;▁Games&#x27;</span>, <span class="hljs-string">&#x27;&lt;/s&gt;&#x27;</span>]',wrap:!1}}),vl=new d({props:{code:"bWF4X2lucHV0X2xlbmd0aCUyMCUzRCUyMDUxMiUwQW1heF90YXJnZXRfbGVuZ3RoJTIwJTNEJTIwMzAlMEElMEElMEFkZWYlMjBwcmVwcm9jZXNzX2Z1bmN0aW9uKGV4YW1wbGVzKSUzQSUwQSUyMCUyMCUyMCUyMG1vZGVsX2lucHV0cyUyMCUzRCUyMHRva2VuaXplciglMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBleGFtcGxlcyU1QiUyMnJldmlld19ib2R5JTIyJTVEJTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwbWF4X2xlbmd0aCUzRG1heF9pbnB1dF9sZW5ndGglMkMlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjB0cnVuY2F0aW9uJTNEVHJ1ZSUyQyUwQSUyMCUyMCUyMCUyMCklMEElMjAlMjAlMjAlMjBsYWJlbHMlMjAlM0QlMjB0b2tlbml6ZXIoJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwZXhhbXBsZXMlNUIlMjJyZXZpZXdfdGl0bGUlMjIlNUQlMkMlMjBtYXhfbGVuZ3RoJTNEbWF4X3RhcmdldF9sZW5ndGglMkMlMjB0cnVuY2F0aW9uJTNEVHJ1ZSUwQSUyMCUyMCUyMCUyMCklMEElMjAlMjAlMjAlMjBtb2RlbF9pbnB1dHMlNUIlMjJsYWJlbHMlMjIlNUQlMjAlM0QlMjBsYWJlbHMlNUIlMjJpbnB1dF9pZHMlMjIlNUQlMEElMjAlMjAlMjAlMjByZXR1cm4lMjBtb2RlbF9pbnB1dHM=",highlighted:`max_input_length = <span class="hljs-number">512</span>
max_target_length = <span class="hljs-number">30</span>


<span class="hljs-keyword">def</span> <span class="hljs-title function_">preprocess_function</span>(<span class="hljs-params">examples</span>):
    model_inputs = tokenizer(
        examples[<span class="hljs-string">&quot;review_body&quot;</span>],
        max_length=max_input_length,
        truncation=<span class="hljs-literal">True</span>,
    )
    labels = tokenizer(
        examples[<span class="hljs-string">&quot;review_title&quot;</span>], max_length=max_target_length, truncation=<span class="hljs-literal">True</span>
    )
    model_inputs[<span class="hljs-string">&quot;labels&quot;</span>] = labels[<span class="hljs-string">&quot;input_ids&quot;</span>]
    <span class="hljs-keyword">return</span> model_inputs`,wrap:!1}}),Wl=new d({props:{code:"dG9rZW5pemVkX2RhdGFzZXRzJTIwJTNEJTIwYm9va3NfZGF0YXNldC5tYXAocHJlcHJvY2Vzc19mdW5jdGlvbiUyQyUyMGJhdGNoZWQlM0RUcnVlKQ==",highlighted:'tokenized_datasets = books_dataset.<span class="hljs-built_in">map</span>(preprocess_function, batched=<span class="hljs-literal">True</span>)',wrap:!1}}),Os=new el({props:{$$slots:{default:[fM]},$$scope:{ctx:G}}}),Vl=new Is({props:{title:"文本摘要的指标",local:"文本摘要的指标",headingTag:"h2"}}),Rl=new Kt({props:{id:"TMshhnrEXlg"}}),Al=new d({props:{code:"Z2VuZXJhdGVkX3N1bW1hcnklMjAlM0QlMjAlMjJJJTIwYWJzb2x1dGVseSUyMGxvdmVkJTIwcmVhZGluZyUyMHRoZSUyMEh1bmdlciUyMEdhbWVzJTIyJTBBcmVmZXJlbmNlX3N1bW1hcnklMjAlM0QlMjAlMjJJJTIwbG92ZWQlMjByZWFkaW5nJTIwdGhlJTIwSHVuZ2VyJTIwR2FtZXMlMjI=",highlighted:`generated_summary = <span class="hljs-string">&quot;I absolutely loved reading the Hunger Games&quot;</span>
reference_summary = <span class="hljs-string">&quot;I loved reading the Hunger Games&quot;</span>`,wrap:!1}}),sl=new el({props:{$$slots:{default:[CM]},$$scope:{ctx:G}}}),Sl=new d({props:{code:"IXBpcCUyMGluc3RhbGwlMjByb3VnZV9zY29yZQ==",highlighted:"!pip install rouge_score",wrap:!1}}),Hl=new d({props:{code:"aW1wb3J0JTIwZXZhbHVhdGUlMEElMEFyb3VnZV9zY29yZSUyMCUzRCUyMGV2YWx1YXRlLmxvYWQoJTIycm91Z2UlMjIp",highlighted:`<span class="hljs-keyword">import</span> evaluate

rouge_score = evaluate.load(<span class="hljs-string">&quot;rouge&quot;</span>)`,wrap:!1}}),Ll=new d({props:{code:"c2NvcmVzJTIwJTNEJTIwcm91Z2Vfc2NvcmUuY29tcHV0ZSglMEElMjAlMjAlMjAlMjBwcmVkaWN0aW9ucyUzRCU1QmdlbmVyYXRlZF9zdW1tYXJ5JTVEJTJDJTIwcmVmZXJlbmNlcyUzRCU1QnJlZmVyZW5jZV9zdW1tYXJ5JTVEJTBBKSUwQXNjb3Jlcw==",highlighted:`scores = rouge_score.compute(
    predictions=[generated_summary], references=[reference_summary]
)
scores`,wrap:!1}}),ql=new d({props:{code:"JTdCJ3JvdWdlMSclM0ElMjBBZ2dyZWdhdGVTY29yZShsb3clM0RTY29yZShwcmVjaXNpb24lM0QwLjg2JTJDJTIwcmVjYWxsJTNEMS4wJTJDJTIwZm1lYXN1cmUlM0QwLjkyKSUyQyUyMG1pZCUzRFNjb3JlKHByZWNpc2lvbiUzRDAuODYlMkMlMjByZWNhbGwlM0QxLjAlMkMlMjBmbWVhc3VyZSUzRDAuOTIpJTJDJTIwaGlnaCUzRFNjb3JlKHByZWNpc2lvbiUzRDAuODYlMkMlMjByZWNhbGwlM0QxLjAlMkMlMjBmbWVhc3VyZSUzRDAuOTIpKSUyQyUwQSUyMCdyb3VnZTInJTNBJTIwQWdncmVnYXRlU2NvcmUobG93JTNEU2NvcmUocHJlY2lzaW9uJTNEMC42NyUyQyUyMHJlY2FsbCUzRDAuOCUyQyUyMGZtZWFzdXJlJTNEMC43MyklMkMlMjBtaWQlM0RTY29yZShwcmVjaXNpb24lM0QwLjY3JTJDJTIwcmVjYWxsJTNEMC44JTJDJTIwZm1lYXN1cmUlM0QwLjczKSUyQyUyMGhpZ2glM0RTY29yZShwcmVjaXNpb24lM0QwLjY3JTJDJTIwcmVjYWxsJTNEMC44JTJDJTIwZm1lYXN1cmUlM0QwLjczKSklMkMlMEElMjAncm91Z2VMJyUzQSUyMEFnZ3JlZ2F0ZVNjb3JlKGxvdyUzRFNjb3JlKHByZWNpc2lvbiUzRDAuODYlMkMlMjByZWNhbGwlM0QxLjAlMkMlMjBmbWVhc3VyZSUzRDAuOTIpJTJDJTIwbWlkJTNEU2NvcmUocHJlY2lzaW9uJTNEMC44NiUyQyUyMHJlY2FsbCUzRDEuMCUyQyUyMGZtZWFzdXJlJTNEMC45MiklMkMlMjBoaWdoJTNEU2NvcmUocHJlY2lzaW9uJTNEMC44NiUyQyUyMHJlY2FsbCUzRDEuMCUyQyUyMGZtZWFzdXJlJTNEMC45MikpJTJDJTBBJTIwJ3JvdWdlTHN1bSclM0ElMjBBZ2dyZWdhdGVTY29yZShsb3clM0RTY29yZShwcmVjaXNpb24lM0QwLjg2JTJDJTIwcmVjYWxsJTNEMS4wJTJDJTIwZm1lYXN1cmUlM0QwLjkyKSUyQyUyMG1pZCUzRFNjb3JlKHByZWNpc2lvbiUzRDAuODYlMkMlMjByZWNhbGwlM0QxLjAlMkMlMjBmbWVhc3VyZSUzRDAuOTIpJTJDJTIwaGlnaCUzRFNjb3JlKHByZWNpc2lvbiUzRDAuODYlMkMlMjByZWNhbGwlM0QxLjAlMkMlMjBmbWVhc3VyZSUzRDAuOTIpKSU3RA==",highlighted:`{<span class="hljs-string">&#x27;rouge1&#x27;</span>: AggregateScore(low=Score(precision=<span class="hljs-number">0.86</span>, recall=<span class="hljs-number">1.0</span>, fmeasure=<span class="hljs-number">0.92</span>), mid=Score(precision=<span class="hljs-number">0.86</span>, recall=<span class="hljs-number">1.0</span>, fmeasure=<span class="hljs-number">0.92</span>), high=Score(precision=<span class="hljs-number">0.86</span>, recall=<span class="hljs-number">1.0</span>, fmeasure=<span class="hljs-number">0.92</span>)),
 <span class="hljs-string">&#x27;rouge2&#x27;</span>: AggregateScore(low=Score(precision=<span class="hljs-number">0.67</span>, recall=<span class="hljs-number">0.8</span>, fmeasure=<span class="hljs-number">0.73</span>), mid=Score(precision=<span class="hljs-number">0.67</span>, recall=<span class="hljs-number">0.8</span>, fmeasure=<span class="hljs-number">0.73</span>), high=Score(precision=<span class="hljs-number">0.67</span>, recall=<span class="hljs-number">0.8</span>, fmeasure=<span class="hljs-number">0.73</span>)),
 <span class="hljs-string">&#x27;rougeL&#x27;</span>: AggregateScore(low=Score(precision=<span class="hljs-number">0.86</span>, recall=<span class="hljs-number">1.0</span>, fmeasure=<span class="hljs-number">0.92</span>), mid=Score(precision=<span class="hljs-number">0.86</span>, recall=<span class="hljs-number">1.0</span>, fmeasure=<span class="hljs-number">0.92</span>), high=Score(precision=<span class="hljs-number">0.86</span>, recall=<span class="hljs-number">1.0</span>, fmeasure=<span class="hljs-number">0.92</span>)),
 <span class="hljs-string">&#x27;rougeLsum&#x27;</span>: AggregateScore(low=Score(precision=<span class="hljs-number">0.86</span>, recall=<span class="hljs-number">1.0</span>, fmeasure=<span class="hljs-number">0.92</span>), mid=Score(precision=<span class="hljs-number">0.86</span>, recall=<span class="hljs-number">1.0</span>, fmeasure=<span class="hljs-number">0.92</span>), high=Score(precision=<span class="hljs-number">0.86</span>, recall=<span class="hljs-number">1.0</span>, fmeasure=<span class="hljs-number">0.92</span>))}`,wrap:!1}}),Pl=new d({props:{code:"c2NvcmVzJTVCJTIycm91Z2UxJTIyJTVELm1pZA==",highlighted:'scores[<span class="hljs-string">&quot;rouge1&quot;</span>].mid',wrap:!1}}),Ol=new d({props:{code:"U2NvcmUocHJlY2lzaW9uJTNEMC44NiUyQyUyMHJlY2FsbCUzRDEuMCUyQyUyMGZtZWFzdXJlJTNEMC45Mik=",highlighted:'Score(precision=<span class="hljs-number">0.86</span>, recall=<span class="hljs-number">1.0</span>, fmeasure=<span class="hljs-number">0.92</span>)',wrap:!1}}),ll=new el({props:{$$slots:{default:[gM]},$$scope:{ctx:G}}}),aa=new Is({props:{title:"创建强大的baseline",local:"创建强大的baseline",headingTag:"h3"}}),ta=new d({props:{code:"IXBpcCUyMGluc3RhbGwlMjBubHRr",highlighted:"!pip install nltk",wrap:!1}}),Ma=new d({props:{code:"aW1wb3J0JTIwbmx0ayUwQSUwQW5sdGsuZG93bmxvYWQoJTIycHVua3QlMjIp",highlighted:`<span class="hljs-keyword">import</span> nltk

nltk.download(<span class="hljs-string">&quot;punkt&quot;</span>)`,wrap:!1}}),ra=new d({props:{code:"ZnJvbSUyMG5sdGsudG9rZW5pemUlMjBpbXBvcnQlMjBzZW50X3Rva2VuaXplJTBBJTBBJTBBZGVmJTIwdGhyZWVfc2VudGVuY2Vfc3VtbWFyeSh0ZXh0KSUzQSUwQSUyMCUyMCUyMCUyMHJldHVybiUyMCUyMiU1Q24lMjIuam9pbihzZW50X3Rva2VuaXplKHRleHQpJTVCJTNBMyU1RCklMEElMEElMEFwcmludCh0aHJlZV9zZW50ZW5jZV9zdW1tYXJ5KGJvb2tzX2RhdGFzZXQlNUIlMjJ0cmFpbiUyMiU1RCU1QjElNUQlNUIlMjJyZXZpZXdfYm9keSUyMiU1RCkp",highlighted:`<span class="hljs-keyword">from</span> nltk.tokenize <span class="hljs-keyword">import</span> sent_tokenize


<span class="hljs-keyword">def</span> <span class="hljs-title function_">three_sentence_summary</span>(<span class="hljs-params">text</span>):
    <span class="hljs-keyword">return</span> <span class="hljs-string">&quot;\\n&quot;</span>.join(sent_tokenize(text)[:<span class="hljs-number">3</span>])


<span class="hljs-built_in">print</span>(three_sentence_summary(books_dataset[<span class="hljs-string">&quot;train&quot;</span>][<span class="hljs-number">1</span>][<span class="hljs-string">&quot;review_body&quot;</span>]))`,wrap:!1}}),ma=new d({props:{code:"J0klMjBncmV3JTIwdXAlMjByZWFkaW5nJTIwS29vbnR6JTJDJTIwYW5kJTIweWVhcnMlMjBhZ28lMkMlMjBJJTIwc3RvcHBlZCUyQ2NvbnZpbmNlZCUyMGklMjBoYWQlMjAlMjJvdXRncm93biUyMiUyMGhpbS4nJTBBJ1N0aWxsJTJDd2hlbiUyMGElMjBmcmllbmQlMjB3YXMlMjBsb29raW5nJTIwZm9yJTIwc29tZXRoaW5nJTIwc3VzcGVuc2VmdWwlMjB0b28lMjByZWFkJTJDJTIwSSUyMHN1Z2dlc3RlZCUyMEtvb250ei4nJTBBJ1NoZSUyMGZvdW5kJTIwU3RyYW5nZXJzLic=",highlighted:`<span class="hljs-string">&#x27;I grew up reading Koontz, and years ago, I stopped,convinced i had &quot;outgrown&quot; him.&#x27;</span>
<span class="hljs-string">&#x27;Still,when a friend was looking for something suspenseful too read, I suggested Koontz.&#x27;</span>
<span class="hljs-string">&#x27;She found Strangers.&#x27;</span>`,wrap:!1}}),ya=new d({props:{code:"ZGVmJTIwZXZhbHVhdGVfYmFzZWxpbmUoZGF0YXNldCUyQyUyMG1ldHJpYyklM0ElMEElMjAlMjAlMjAlMjBzdW1tYXJpZXMlMjAlM0QlMjAlNUJ0aHJlZV9zZW50ZW5jZV9zdW1tYXJ5KHRleHQpJTIwZm9yJTIwdGV4dCUyMGluJTIwZGF0YXNldCU1QiUyMnJldmlld19ib2R5JTIyJTVEJTVEJTBBJTIwJTIwJTIwJTIwcmV0dXJuJTIwbWV0cmljLmNvbXB1dGUocHJlZGljdGlvbnMlM0RzdW1tYXJpZXMlMkMlMjByZWZlcmVuY2VzJTNEZGF0YXNldCU1QiUyMnJldmlld190aXRsZSUyMiU1RCk=",highlighted:`<span class="hljs-keyword">def</span> <span class="hljs-title function_">evaluate_baseline</span>(<span class="hljs-params">dataset, metric</span>):
    summaries = [three_sentence_summary(text) <span class="hljs-keyword">for</span> text <span class="hljs-keyword">in</span> dataset[<span class="hljs-string">&quot;review_body&quot;</span>]]
    <span class="hljs-keyword">return</span> metric.compute(predictions=summaries, references=dataset[<span class="hljs-string">&quot;review_title&quot;</span>])`,wrap:!1}}),ca=new d({props:{code:"aW1wb3J0JTIwcGFuZGFzJTIwYXMlMjBwZCUwQSUwQXNjb3JlJTIwJTNEJTIwZXZhbHVhdGVfYmFzZWxpbmUoYm9va3NfZGF0YXNldCU1QiUyMnZhbGlkYXRpb24lMjIlNUQlMkMlMjByb3VnZV9zY29yZSklMEFyb3VnZV9uYW1lcyUyMCUzRCUyMCU1QiUyMnJvdWdlMSUyMiUyQyUyMCUyMnJvdWdlMiUyMiUyQyUyMCUyMnJvdWdlTCUyMiUyQyUyMCUyMnJvdWdlTHN1bSUyMiU1RCUwQXJvdWdlX2RpY3QlMjAlM0QlMjBkaWN0KChybiUyQyUyMHJvdW5kKHNjb3JlJTVCcm4lNUQubWlkLmZtZWFzdXJlJTIwKiUyMDEwMCUyQyUyMDIpKSUyMGZvciUyMHJuJTIwaW4lMjByb3VnZV9uYW1lcyklMEFyb3VnZV9kaWN0",highlighted:`<span class="hljs-keyword">import</span> pandas <span class="hljs-keyword">as</span> pd

score = evaluate_baseline(books_dataset[<span class="hljs-string">&quot;validation&quot;</span>], rouge_score)
rouge_names = [<span class="hljs-string">&quot;rouge1&quot;</span>, <span class="hljs-string">&quot;rouge2&quot;</span>, <span class="hljs-string">&quot;rougeL&quot;</span>, <span class="hljs-string">&quot;rougeLsum&quot;</span>]
rouge_dict = <span class="hljs-built_in">dict</span>((rn, <span class="hljs-built_in">round</span>(score[rn].mid.fmeasure * <span class="hljs-number">100</span>, <span class="hljs-number">2</span>)) <span class="hljs-keyword">for</span> rn <span class="hljs-keyword">in</span> rouge_names)
rouge_dict`,wrap:!1}}),Ta=new d({props:{code:"JTdCJ3JvdWdlMSclM0ElMjAxNi43NCUyQyUyMCdyb3VnZTInJTNBJTIwOC44MyUyQyUyMCdyb3VnZUwnJTNBJTIwMTUuNiUyQyUyMCdyb3VnZUxzdW0nJTNBJTIwMTUuOTYlN0Q=",highlighted:'{<span class="hljs-string">&#x27;rouge1&#x27;</span>: <span class="hljs-number">16.74</span>, <span class="hljs-string">&#x27;rouge2&#x27;</span>: <span class="hljs-number">8.83</span>, <span class="hljs-string">&#x27;rougeL&#x27;</span>: <span class="hljs-number">15.6</span>, <span class="hljs-string">&#x27;rougeLsum&#x27;</span>: <span class="hljs-number">15.96</span>}',wrap:!1}});const Yn=[GM,ZM],Ya=[];function En(s,e){return s[0]==="pt"?0:1}gs=En(G),Zs=Ya[gs]=Yn[gs](G),al=new el({props:{$$slots:{default:[kM]},$$scope:{ctx:G}}}),Ua=new d({props:{code:"ZnJvbSUyMGh1Z2dpbmdmYWNlX2h1YiUyMGltcG9ydCUyMG5vdGVib29rX2xvZ2luJTBBJTBBbm90ZWJvb2tfbG9naW4oKQ==",highlighted:`<span class="hljs-keyword">from</span> huggingface_hub <span class="hljs-keyword">import</span> notebook_login

notebook_login()`,wrap:!1}}),ha=new d({props:{code:"aHVnZ2luZ2ZhY2UtY2xpJTIwbG9naW4=",highlighted:'huggingface-<span class="hljs-keyword">cli</span> login',wrap:!1}});let H=G[0]==="pt"&&MM();const Sn=[vM,BM],Ea=[];function Fn(s,e){return s[0]==="pt"?0:1}Gs=Fn(G),ks=Ea[Gs]=Sn[Gs](G),Ia=new d({props:{code:"dG9rZW5pemVkX2RhdGFzZXRzJTIwJTNEJTIwdG9rZW5pemVkX2RhdGFzZXRzLnJlbW92ZV9jb2x1bW5zKCUwQSUyMCUyMCUyMCUyMGJvb2tzX2RhdGFzZXQlNUIlMjJ0cmFpbiUyMiU1RC5jb2x1bW5fbmFtZXMlMEEp",highlighted:`tokenized_datasets = tokenized_datasets.remove_columns(
    books_dataset[<span class="hljs-string">&quot;train&quot;</span>].column_names
)`,wrap:!1}}),Ca=new d({props:{code:"ZmVhdHVyZXMlMjAlM0QlMjAlNUJ0b2tlbml6ZWRfZGF0YXNldHMlNUIlMjJ0cmFpbiUyMiU1RCU1QmklNUQlMjBmb3IlMjBpJTIwaW4lMjByYW5nZSgyKSU1RCUwQWRhdGFfY29sbGF0b3IoZmVhdHVyZXMp",highlighted:`features = [tokenized_datasets[<span class="hljs-string">&quot;train&quot;</span>][i] <span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> <span class="hljs-built_in">range</span>(<span class="hljs-number">2</span>)]
data_collator(features)`,wrap:!1}}),ga=new d({props:{code:"JTdCJ2F0dGVudGlvbl9tYXNrJyUzQSUyMHRlbnNvciglNUI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jU5JTJDJTIwJTIwMjM2NCUyQyUyMDE1Njk1JTJDJTIwJTIwJTIwJTIwJTIwMSU1RCUyQyUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCU1QiUyMCUyMCUyMCUyMDAlMkMlMjAlMjAlMjAyNTklMkMlMjAyNzUzMSUyQyUyMDEzNDgzJTJDJTIwJTIwJTIwMjU5JTJDJTIwJTIwNzUwNSU1RCU1RCklN0Q=",highlighted:`{<span class="hljs-string">&#x27;attention_mask&#x27;</span>: tensor([[<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>, <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">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-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>, <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-string">&#x27;input_ids&#x27;</span>: tensor([[  <span class="hljs-number">1494</span>,    <span class="hljs-number">259</span>,   <span class="hljs-number">8622</span>,    <span class="hljs-number">390</span>,    <span class="hljs-number">259</span>,    <span class="hljs-number">262</span>,   <span class="hljs-number">2316</span>,   <span class="hljs-number">3435</span>,    <span class="hljs-number">955</span>,
            <span class="hljs-number">772</span>,    <span class="hljs-number">281</span>,    <span class="hljs-number">772</span>,   <span class="hljs-number">1617</span>,    <span class="hljs-number">263</span>,    <span class="hljs-number">305</span>,  <span class="hljs-number">14701</span>,    <span class="hljs-number">260</span>,   <span class="hljs-number">1385</span>,
           <span class="hljs-number">3031</span>,    <span class="hljs-number">259</span>,  <span class="hljs-number">24146</span>,    <span class="hljs-number">332</span>,   <span class="hljs-number">1037</span>,    <span class="hljs-number">259</span>,  <span class="hljs-number">43906</span>,    <span class="hljs-number">305</span>,    <span class="hljs-number">336</span>,
            <span class="hljs-number">260</span>,      <span class="hljs-number">1</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">259</span>,  <span class="hljs-number">27531</span>,  <span class="hljs-number">13483</span>,    <span class="hljs-number">259</span>,   <span class="hljs-number">7505</span>,    <span class="hljs-number">260</span>, <span class="hljs-number">112240</span>,  <span class="hljs-number">15192</span>,    <span class="hljs-number">305</span>,
          <span class="hljs-number">53198</span>,    <span class="hljs-number">276</span>,    <span class="hljs-number">259</span>,  <span class="hljs-number">74060</span>,    <span class="hljs-number">263</span>,    <span class="hljs-number">260</span>,    <span class="hljs-number">459</span>,  <span class="hljs-number">25640</span>,    <span class="hljs-number">776</span>,
           <span class="hljs-number">2119</span>,    <span class="hljs-number">336</span>,    <span class="hljs-number">259</span>,   <span class="hljs-number">2220</span>,    <span class="hljs-number">259</span>,  <span class="hljs-number">18896</span>,    <span class="hljs-number">288</span>,   <span class="hljs-number">4906</span>,    <span class="hljs-number">288</span>,
           <span class="hljs-number">1037</span>,   <span class="hljs-number">3931</span>,    <span class="hljs-number">260</span>,   <span class="hljs-number">7083</span>, <span class="hljs-number">101476</span>,   <span class="hljs-number">1143</span>,    <span class="hljs-number">260</span>,      <span class="hljs-number">1</span>]]), <span class="hljs-string">&#x27;labels&#x27;</span>: tensor([[ <span class="hljs-number">7483</span>,   <span class="hljs-number">259</span>,  <span class="hljs-number">2364</span>, <span class="hljs-number">15695</span>,     <span class="hljs-number">1</span>,  -<span class="hljs-number">100</span>],
        [  <span class="hljs-number">259</span>, <span class="hljs-number">27531</span>, <span class="hljs-number">13483</span>,   <span class="hljs-number">259</span>,  <span class="hljs-number">7505</span>,     <span class="hljs-number">1</span>]]), <span class="hljs-string">&#x27;decoder_input_ids&#x27;</span>: tensor([[    <span class="hljs-number">0</span>,  <span class="hljs-number">7483</span>,   <span class="hljs-number">259</span>,  <span class="hljs-number">2364</span>, <span class="hljs-number">15695</span>,     <span class="hljs-number">1</span>],
        [    <span class="hljs-number">0</span>,   <span class="hljs-number">259</span>, <span class="hljs-number">27531</span>, <span class="hljs-number">13483</span>,   <span class="hljs-number">259</span>,  <span class="hljs-number">7505</span>]])}`,wrap:!1}});const Hn=[$M,xM],Sa=[];function Dn(s,e){return s[0]==="pt"?0:1}Bs=Dn(G),vs=Sa[Bs]=Hn[Bs](G);let D=G[0]==="pt"&&pM(G);return Ga=new Is({props:{title:"使用您微调的模型",local:"使用您微调的模型",headingTag:"h2"}}),Ba=new d({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMHBpcGVsaW5lJTBBJTBBaHViX21vZGVsX2lkJTIwJTNEJTIwJTIyaHVnZ2luZ2ZhY2UtY291cnNlJTJGbXQ1LXNtYWxsLWZpbmV0dW5lZC1hbWF6b24tZW4tZXMlMjIlMEFzdW1tYXJpemVyJTIwJTNEJTIwcGlwZWxpbmUoJTIyc3VtbWFyaXphdGlvbiUyMiUyQyUyMG1vZGVsJTNEaHViX21vZGVsX2lkKQ==",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> pipeline

hub_model_id = <span class="hljs-string">&quot;huggingface-course/mt5-small-finetuned-amazon-en-es&quot;</span>
summarizer = pipeline(<span class="hljs-string">&quot;summarization&quot;</span>, model=hub_model_id)`,wrap:!1}}),xa=new d({props:{code:"ZGVmJTIwcHJpbnRfc3VtbWFyeShpZHgpJTNBJTBBJTIwJTIwJTIwJTIwcmV2aWV3JTIwJTNEJTIwYm9va3NfZGF0YXNldCU1QiUyMnRlc3QlMjIlNUQlNUJpZHglNUQlNUIlMjJyZXZpZXdfYm9keSUyMiU1RCUwQSUyMCUyMCUyMCUyMHRpdGxlJTIwJTNEJTIwYm9va3NfZGF0YXNldCU1QiUyMnRlc3QlMjIlNUQlNUJpZHglNUQlNUIlMjJyZXZpZXdfdGl0bGUlMjIlNUQlMEElMjAlMjAlMjAlMjBzdW1tYXJ5JTIwJTNEJTIwc3VtbWFyaXplcihib29rc19kYXRhc2V0JTVCJTIydGVzdCUyMiU1RCU1QmlkeCU1RCU1QiUyMnJldmlld19ib2R5JTIyJTVEKSU1QjAlNUQlNUIlMjJzdW1tYXJ5X3RleHQlMjIlNUQlMEElMjAlMjAlMjAlMjBwcmludChmJTIyJyUzRSUzRSUzRSUyMFJldmlldyUzQSUyMCU3QnJldmlldyU3RCclMjIpJTBBJTIwJTIwJTIwJTIwcHJpbnQoZiUyMiU1Q24nJTNFJTNFJTNFJTIwVGl0bGUlM0ElMjAlN0J0aXRsZSU3RCclMjIpJTBBJTIwJTIwJTIwJTIwcHJpbnQoZiUyMiU1Q24nJTNFJTNFJTNFJTIwU3VtbWFyeSUzQSUyMCU3QnN1bW1hcnklN0QnJTIyKQ==",highlighted:`<span class="hljs-keyword">def</span> <span class="hljs-title function_">print_summary</span>(<span class="hljs-params">idx</span>):
    review = books_dataset[<span class="hljs-string">&quot;test&quot;</span>][idx][<span class="hljs-string">&quot;review_body&quot;</span>]
    title = books_dataset[<span class="hljs-string">&quot;test&quot;</span>][idx][<span class="hljs-string">&quot;review_title&quot;</span>]
    summary = summarizer(books_dataset[<span class="hljs-string">&quot;test&quot;</span>][idx][<span class="hljs-string">&quot;review_body&quot;</span>])[<span class="hljs-number">0</span>][<span class="hljs-string">&quot;summary_text&quot;</span>]
    <span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;&#x27;&gt;&gt;&gt; Review: <span class="hljs-subst">{review}</span>&#x27;&quot;</span>)
    <span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;\\n&#x27;&gt;&gt;&gt; Title: <span class="hljs-subst">{title}</span>&#x27;&quot;</span>)
    <span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;\\n&#x27;&gt;&gt;&gt; Summary: <span class="hljs-subst">{summary}</span>&#x27;&quot;</span>)`,wrap:!1}}),Wa=new d({props:{code:"cHJpbnRfc3VtbWFyeSgxMDAp",highlighted:'print_summary(<span class="hljs-number">100</span>)',wrap:!1}}),_a=new d({props:{code:"JyUzRSUzRSUzRSUyMFJldmlldyUzQSUyME5vdGhpbmclMjBzcGVjaWFsJTIwYXQlMjBhbGwlMjBhYm91dCUyMHRoaXMlMjBwcm9kdWN0Li4uJTIwdGhlJTIwYm9vayUyMGlzJTIwdG9vJTIwc21hbGwlMjBhbmQlMjBzdGlmZiUyMGFuZCUyMGhhcmQlMjB0byUyMHdyaXRlJTIwaW4uJTIwVGhlJTIwaHVnZSUyMHN0aWNrZXIlMjBvbiUyMHRoZSUyMGJhY2slMjBkb2VzbiVFMiU4MCU5OXQlMjBjb21lJTIwb2ZmJTIwYW5kJTIwbG9va3MlMjBzdXBlciUyMHRhY2t5LiUyMEklMjB3b3VsZCUyMG5vdCUyMHB1cmNoYXNlJTIwdGhpcyUyMGFnYWluLiUyMEklMjBjb3VsZCUyMGhhdmUlMjBqdXN0JTIwYm91Z2h0JTIwYSUyMGpvdXJuYWwlMjBmcm9tJTIwdGhlJTIwZG9sbGFyJTIwc3RvcmUlMjBhbmQlMjBpdCUyMHdvdWxkJTIwYmUlMjBiYXNpY2FsbHklMjB0aGUlMjBzYW1lJTIwdGhpbmcuJTIwSXQlRTIlODAlOTlzJTIwYWxzbyUyMHJlYWxseSUyMGV4cGVuc2l2ZSUyMGZvciUyMHdoYXQlMjBpdCUyMGlzLiclMEElMEEnJTNFJTNFJTNFJTIwVGl0bGUlM0ElMjBOb3QlMjBpbXByZXNzZWQlMjBhdCUyMGFsbC4uLiUyMGJ1eSUyMHNvbWV0aGluZyUyMGVsc2UnJTBBJTBBJyUzRSUzRSUzRSUyMFN1bW1hcnklM0ElMjBOb3RoaW5nJTIwc3BlY2lhbCUyMGF0JTIwYWxsJTIwYWJvdXQlMjB0aGlzJTIwcHJvZHVjdCc=",highlighted:`<span class="hljs-string">&#x27;&gt;&gt;&gt; Review: Nothing special at all about this product... the book is too small and stiff and hard to write in. The huge sticker on the back doesn’t come off and looks super tacky. I would not purchase this again. I could have just bought a journal from the dollar store and it would be basically the same thing. It’s also really expensive for what it is.&#x27;</span>

<span class="hljs-string">&#x27;&gt;&gt;&gt; Title: Not impressed at all... buy something else&#x27;</span>

<span class="hljs-string">&#x27;&gt;&gt;&gt; Summary: Nothing special at all about this product&#x27;</span>`,wrap:!1}}),Ra=new d({props:{code:"cHJpbnRfc3VtbWFyeSgwKQ==",highlighted:'print_summary(<span class="hljs-number">0</span>)',wrap:!1}}),Na=new d({props:{code:"JyUzRSUzRSUzRSUyMFJldmlldyUzQSUyMEVzJTIwdW5hJTIwdHJpbG9naWElMjBxdWUlMjBzZSUyMGhhY2UlMjBtdXklMjBmYWNpbCUyMGRlJTIwbGVlci4lMjBNZSUyMGhhJTIwZ3VzdGFkbyUyQyUyMG5vJTIwbWUlMjBlc3BlcmFiYSUyMGVsJTIwZmluYWwlMjBwYXJhJTIwbmFkYSclMEElMEEnJTNFJTNFJTNFJTIwVGl0bGUlM0ElMjBCdWVuYSUyMGxpdGVyYXR1cmElMjBwYXJhJTIwYWRvbGVzY2VudGVzJyUwQSUwQSclM0UlM0UlM0UlMjBTdW1tYXJ5JTNBJTIwTXV5JTIwZmFjaWwlMjBkZSUyMGxlZXIn",highlighted:`<span class="hljs-string">&#x27;&gt;&gt;&gt; Review: Es una trilogia que se hace muy facil de leer. Me ha gustado, no me esperaba el final para nada&#x27;</span>

<span class="hljs-string">&#x27;&gt;&gt;&gt; Title: Buena literatura para adolescentes&#x27;</span>

<span class="hljs-string">&#x27;&gt;&gt;&gt; Summary: Muy facil de leer&#x27;</span>`,wrap:!1}}),za=new jM({props:{source:"https://github.com/huggingface/course/blob/main/chapters/zh-CN/chapter7/5.mdx"}}),{c(){p=y("meta"),u=t(),r=y("p"),f=t(),c(k.$$.fragment),g=t(),c(W.$$.fragment),I=t(),R.c(),B=t(),z=y("p"),z.textContent=E,N=t(),c(_.$$.fragment),x=t(),C=y("p"),C.innerHTML=v,L=t(),X=y("iframe"),K=t(),A=y("p"),A.textContent=q,S=t(),c(Y.$$.fragment),F=t(),j=y("p"),j.innerHTML=V,ys=t(),c(h.$$.fragment),$=t(),c(P.$$.fragment),Ns=t(),O=y("p"),O.innerHTML=le,Xs=t(),c(ss.$$.fragment),nl=t(),c(Js.$$.fragment),cs=t(),c(fs.$$.fragment),As=t(),ls=y("p"),ls.innerHTML=Ml,Ts=t(),c($s.$$.fragment),zs=t(),c(as.$$.fragment),Qs=t(),es=y("p"),es.innerHTML=ae,Ys=t(),c(ts.$$.fragment),pl=t(),os=y("p"),os.innerHTML=Ws,Es=t(),c(ns.$$.fragment),Ss=t(),Ms=y("p"),Ms.textContent=ee,Fs=t(),c(ps.$$.fragment),Hs=t(),c(rs.$$.fragment),rl=t(),ws=y("p"),ws.innerHTML=_s,Ds=t(),c(ms.$$.fragment),ml=t(),c(Us.$$.fragment),js=t(),Vs=y("p"),Vs.textContent=il,hs=t(),Cs=y("div"),Cs.innerHTML=yl,ds=t(),us=y("p"),us.innerHTML=Rs,Ls=t(),c(is.$$.fragment),Jl=t(),bs=y("p"),bs.textContent=M,b=t(),c(cl.$$.fragment),Me=t(),Tl=y("p"),Tl.innerHTML=Pt,pe=t(),ol=y("table"),ol.innerHTML=Ot,re=t(),wl=y("p"),wl.textContent=sn,me=t(),Ul=y("p"),Ul.innerHTML=ln,ie=t(),qs=y("div"),qs.innerHTML=an,ye=t(),jl=y("p"),jl.textContent=en,Je=t(),c(Ks.$$.fragment),ce=t(),c(hl.$$.fragment),Te=t(),c(dl.$$.fragment),oe=t(),ul=y("p"),ul.innerHTML=tn,we=t(),c(bl.$$.fragment),Ue=t(),c(Ps.$$.fragment),je=t(),Il=y("p"),Il.textContent=nn,he=t(),c(fl.$$.fragment),de=t(),c(Cl.$$.fragment),ue=t(),gl=y("p"),gl.innerHTML=Mn,be=t(),c(Zl.$$.fragment),Ie=t(),c(Gl.$$.fragment),fe=t(),kl=y("p"),kl.innerHTML=pn,Ce=t(),Bl=y("p"),Bl.innerHTML=rn,ge=t(),c(vl.$$.fragment),Ze=t(),xl=y("p"),xl.innerHTML=mn,Ge=t(),$l=y("p"),$l.innerHTML=yn,ke=t(),c(Wl.$$.fragment),Be=t(),_l=y("p"),_l.textContent=Jn,ve=t(),c(Os.$$.fragment),xe=t(),c(Vl.$$.fragment),$e=t(),c(Rl.$$.fragment),We=t(),Nl=y("p"),Nl.textContent=cn,_e=t(),Xl=y("p"),Xl.innerHTML=Tn,Ve=t(),c(Al.$$.fragment),Re=t(),zl=y("p"),zl.innerHTML=on,Ne=t(),c(sl.$$.fragment),Xe=t(),Ql=y("p"),St=aM(`对于 ROUGE，recall 衡量生成的参考摘要包含了多少参考摘要。如果我们只是比较单词，recall可以根据以下公式计算：
`),Ae=new eM(!1),ze=t(),Yl=y("p"),Ft=aM(`对于我们上面的简单例子，这个公式给出了 6/6 = 1 的完美召回率；即，参考摘要中的所有单词都已由模型生成。这听起来可能很棒，但想象一下，如果我们生成的摘要是“我真的很喜欢整晚阅读饥饿游戏”。这也将有完美的recall，但可以说是一个更糟糕的总结，因为它很冗长。为了处理这些场景，我们还计算了pecision，它在 ROUGE 上下文中衡量生成的摘要中有多少是相关的：
`),Qe=new eM(!1),Ye=t(),El=y("p"),El.innerHTML=wn,Ee=t(),c(Sl.$$.fragment),Se=t(),Fl=y("p"),Fl.textContent=Un,Fe=t(),c(Hl.$$.fragment),He=t(),Dl=y("p"),Dl.innerHTML=jn,De=t(),c(Ll.$$.fragment),Le=t(),c(ql.$$.fragment),qe=t(),Kl=y("p"),Kl.innerHTML=hn,Ke=t(),c(Pl.$$.fragment),Pe=t(),c(Ol.$$.fragment),Oe=t(),sa=y("p"),sa.innerHTML=dn,st=t(),c(ll.$$.fragment),lt=t(),la=y("p"),la.textContent=un,at=t(),c(aa.$$.fragment),et=t(),ea=y("p"),ea.innerHTML=bn,tt=t(),c(ta.$$.fragment),nt=t(),na=y("p"),na.textContent=In,Mt=t(),c(Ma.$$.fragment),pt=t(),pa=y("p"),pa.innerHTML=fn,rt=t(),c(ra.$$.fragment),mt=t(),c(ma.$$.fragment),it=t(),ia=y("p"),ia.textContent=Cn,yt=t(),c(ya.$$.fragment),Jt=t(),Ja=y("p"),Ja.textContent=gn,ct=t(),c(ca.$$.fragment),Tt=t(),c(Ta.$$.fragment),ot=t(),oa=y("p"),oa.innerHTML=Zn,wt=t(),Zs.c(),Ha=t(),c(al.$$.fragment),Ut=t(),wa=y("p"),wa.textContent=Gn,jt=t(),c(Ua.$$.fragment),ht=t(),ja=y("p"),ja.textContent=kn,dt=t(),c(ha.$$.fragment),ut=t(),H&&H.c(),Da=t(),da=y("p"),da.innerHTML=Bn,bt=t(),ua=y("p"),ua.innerHTML=vn,It=t(),ks.c(),La=t(),ba=y("p"),ba.textContent=xn,ft=t(),c(Ia.$$.fragment),Ct=t(),fa=y("p"),fa.innerHTML=$n,gt=t(),c(Ca.$$.fragment),Zt=t(),c(ga.$$.fragment),Gt=t(),Za=y("p"),Za.innerHTML=Wn,kt=t(),vs.c(),qa=t(),D&&D.c(),Ka=t(),c(Ga.$$.fragment),Bt=t(),ka=y("p"),ka.textContent=_n,vt=t(),c(Ba.$$.fragment),xt=t(),va=y("p"),va.textContent=Vn,$t=t(),c(xa.$$.fragment),Wt=t(),$a=y("p"),$a.textContent=Rn,_t=t(),c(Wa.$$.fragment),Vt=t(),c(_a.$$.fragment),Rt=t(),Va=y("p"),Va.textContent=Nn,Nt=t(),c(Ra.$$.fragment),Xt=t(),c(Na.$$.fragment),At=t(),Xa=y("p"),Xa.textContent=Xn,zt=t(),Aa=y("p"),Aa.textContent=An,Qt=t(),c(za.$$.fragment),Yt=t(),te=y("p"),this.h()},l(s){const e=wM("svelte-u9bgzb",document.head);p=J(e,"META",{name:!0,content:!0}),e.forEach(l),u=n(s),r=J(s,"P",{}),ne(r).forEach(l),f=n(s),T(k.$$.fragment,s),g=n(s),T(W.$$.fragment,s),I=n(s),R.l(s),B=n(s),z=J(s,"P",{"data-svelte-h":!0}),U(z)!=="svelte-1e84xu9"&&(z.textContent=E),N=n(s),T(_.$$.fragment,s),x=n(s),C=J(s,"P",{"data-svelte-h":!0}),U(C)!=="svelte-q51rv5"&&(C.innerHTML=v),L=n(s),X=J(s,"IFRAME",{src:!0,frameborder:!0,height:!0,title:!0,class:!0,allow:!0,sandbox:!0}),ne(X).forEach(l),K=n(s),A=J(s,"P",{"data-svelte-h":!0}),U(A)!=="svelte-1bdwguy"&&(A.textContent=q),S=n(s),T(Y.$$.fragment,s),F=n(s),j=J(s,"P",{"data-svelte-h":!0}),U(j)!=="svelte-4x411w"&&(j.innerHTML=V),ys=n(s),T(h.$$.fragment,s),$=n(s),T(P.$$.fragment,s),Ns=n(s),O=J(s,"P",{"data-svelte-h":!0}),U(O)!=="svelte-1ide2ue"&&(O.innerHTML=le),Xs=n(s),T(ss.$$.fragment,s),nl=n(s),T(Js.$$.fragment,s),cs=n(s),T(fs.$$.fragment,s),As=n(s),ls=J(s,"P",{"data-svelte-h":!0}),U(ls)!=="svelte-1cqnwz6"&&(ls.innerHTML=Ml),Ts=n(s),T($s.$$.fragment,s),zs=n(s),T(as.$$.fragment,s),Qs=n(s),es=J(s,"P",{"data-svelte-h":!0}),U(es)!=="svelte-1tibfoz"&&(es.innerHTML=ae),Ys=n(s),T(ts.$$.fragment,s),pl=n(s),os=J(s,"P",{"data-svelte-h":!0}),U(os)!=="svelte-18f0qc1"&&(os.innerHTML=Ws),Es=n(s),T(ns.$$.fragment,s),Ss=n(s),Ms=J(s,"P",{"data-svelte-h":!0}),U(Ms)!=="svelte-30v9g"&&(Ms.textContent=ee),Fs=n(s),T(ps.$$.fragment,s),Hs=n(s),T(rs.$$.fragment,s),rl=n(s),ws=J(s,"P",{"data-svelte-h":!0}),U(ws)!=="svelte-1dd9qv1"&&(ws.innerHTML=_s),Ds=n(s),T(ms.$$.fragment,s),ml=n(s),T(Us.$$.fragment,s),js=n(s),Vs=J(s,"P",{"data-svelte-h":!0}),U(Vs)!=="svelte-vb4562"&&(Vs.textContent=il),hs=n(s),Cs=J(s,"DIV",{class:!0,"data-svelte-h":!0}),U(Cs)!=="svelte-1pwnbfd"&&(Cs.innerHTML=yl),ds=n(s),us=J(s,"P",{"data-svelte-h":!0}),U(us)!=="svelte-1heux3u"&&(us.innerHTML=Rs),Ls=n(s),T(is.$$.fragment,s),Jl=n(s),bs=J(s,"P",{"data-svelte-h":!0}),U(bs)!=="svelte-acffvt"&&(bs.textContent=M),b=n(s),T(cl.$$.fragment,s),Me=n(s),Tl=J(s,"P",{"data-svelte-h":!0}),U(Tl)!=="svelte-6jj9c7"&&(Tl.innerHTML=Pt),pe=n(s),ol=J(s,"TABLE",{"data-svelte-h":!0}),U(ol)!=="svelte-1xtu7ek"&&(ol.innerHTML=Ot),re=n(s),wl=J(s,"P",{"data-svelte-h":!0}),U(wl)!=="svelte-1r0bln9"&&(wl.textContent=sn),me=n(s),Ul=J(s,"P",{"data-svelte-h":!0}),U(Ul)!=="svelte-se8fp8"&&(Ul.innerHTML=ln),ie=n(s),qs=J(s,"DIV",{class:!0,"data-svelte-h":!0}),U(qs)!=="svelte-k7lnur"&&(qs.innerHTML=an),ye=n(s),jl=J(s,"P",{"data-svelte-h":!0}),U(jl)!=="svelte-fvbmu4"&&(jl.textContent=en),Je=n(s),T(Ks.$$.fragment,s),ce=n(s),T(hl.$$.fragment,s),Te=n(s),T(dl.$$.fragment,s),oe=n(s),ul=J(s,"P",{"data-svelte-h":!0}),U(ul)!=="svelte-pv2d7w"&&(ul.innerHTML=tn),we=n(s),T(bl.$$.fragment,s),Ue=n(s),T(Ps.$$.fragment,s),je=n(s),Il=J(s,"P",{"data-svelte-h":!0}),U(Il)!=="svelte-ktwqil"&&(Il.textContent=nn),he=n(s),T(fl.$$.fragment,s),de=n(s),T(Cl.$$.fragment,s),ue=n(s),gl=J(s,"P",{"data-svelte-h":!0}),U(gl)!=="svelte-15k9hl2"&&(gl.innerHTML=Mn),be=n(s),T(Zl.$$.fragment,s),Ie=n(s),T(Gl.$$.fragment,s),fe=n(s),kl=J(s,"P",{"data-svelte-h":!0}),U(kl)!=="svelte-i2otyx"&&(kl.innerHTML=pn),Ce=n(s),Bl=J(s,"P",{"data-svelte-h":!0}),U(Bl)!=="svelte-7d0bqa"&&(Bl.innerHTML=rn),ge=n(s),T(vl.$$.fragment,s),Ze=n(s),xl=J(s,"P",{"data-svelte-h":!0}),U(xl)!=="svelte-d6j8u8"&&(xl.innerHTML=mn),Ge=n(s),$l=J(s,"P",{"data-svelte-h":!0}),U($l)!=="svelte-148zj7m"&&($l.innerHTML=yn),ke=n(s),T(Wl.$$.fragment,s),Be=n(s),_l=J(s,"P",{"data-svelte-h":!0}),U(_l)!=="svelte-6lz54o"&&(_l.textContent=Jn),ve=n(s),T(Os.$$.fragment,s),xe=n(s),T(Vl.$$.fragment,s),$e=n(s),T(Rl.$$.fragment,s),We=n(s),Nl=J(s,"P",{"data-svelte-h":!0}),U(Nl)!=="svelte-pytv7s"&&(Nl.textContent=cn),_e=n(s),Xl=J(s,"P",{"data-svelte-h":!0}),U(Xl)!=="svelte-1njbp4i"&&(Xl.innerHTML=Tn),Ve=n(s),T(Al.$$.fragment,s),Re=n(s),zl=J(s,"P",{"data-svelte-h":!0}),U(zl)!=="svelte-1kpggy4"&&(zl.innerHTML=on),Ne=n(s),T(sl.$$.fragment,s),Xe=n(s),Ql=J(s,"P",{});var Pa=ne(Ql);St=tM(Pa,`对于 ROUGE，recall 衡量生成的参考摘要包含了多少参考摘要。如果我们只是比较单词，recall可以根据以下公式计算：
`),Ae=nM(Pa,!1),Pa.forEach(l),ze=n(s),Yl=J(s,"P",{});var Fa=ne(Yl);Ft=tM(Fa,`对于我们上面的简单例子，这个公式给出了 6/6 = 1 的完美召回率；即，参考摘要中的所有单词都已由模型生成。这听起来可能很棒，但想象一下，如果我们生成的摘要是“我真的很喜欢整晚阅读饥饿游戏”。这也将有完美的recall，但可以说是一个更糟糕的总结，因为它很冗长。为了处理这些场景，我们还计算了pecision，它在 ROUGE 上下文中衡量生成的摘要中有多少是相关的：
`),Qe=nM(Fa,!1),Fa.forEach(l),Ye=n(s),El=J(s,"P",{"data-svelte-h":!0}),U(El)!=="svelte-1x62v85"&&(El.innerHTML=wn),Ee=n(s),T(Sl.$$.fragment,s),Se=n(s),Fl=J(s,"P",{"data-svelte-h":!0}),U(Fl)!=="svelte-qano4p"&&(Fl.textContent=Un),Fe=n(s),T(Hl.$$.fragment,s),He=n(s),Dl=J(s,"P",{"data-svelte-h":!0}),U(Dl)!=="svelte-1uchqn4"&&(Dl.innerHTML=jn),De=n(s),T(Ll.$$.fragment,s),Le=n(s),T(ql.$$.fragment,s),qe=n(s),Kl=J(s,"P",{"data-svelte-h":!0}),U(Kl)!=="svelte-i36j3h"&&(Kl.innerHTML=hn),Ke=n(s),T(Pl.$$.fragment,s),Pe=n(s),T(Ol.$$.fragment,s),Oe=n(s),sa=J(s,"P",{"data-svelte-h":!0}),U(sa)!=="svelte-tpmnxr"&&(sa.innerHTML=dn),st=n(s),T(ll.$$.fragment,s),lt=n(s),la=J(s,"P",{"data-svelte-h":!0}),U(la)!=="svelte-153ocmo"&&(la.textContent=un),at=n(s),T(aa.$$.fragment,s),et=n(s),ea=J(s,"P",{"data-svelte-h":!0}),U(ea)!=="svelte-o34uop"&&(ea.innerHTML=bn),tt=n(s),T(ta.$$.fragment,s),nt=n(s),na=J(s,"P",{"data-svelte-h":!0}),U(na)!=="svelte-lvcdc3"&&(na.textContent=In),Mt=n(s),T(Ma.$$.fragment,s),pt=n(s),pa=J(s,"P",{"data-svelte-h":!0}),U(pa)!=="svelte-1ldgi0e"&&(pa.innerHTML=fn),rt=n(s),T(ra.$$.fragment,s),mt=n(s),T(ma.$$.fragment,s),it=n(s),ia=J(s,"P",{"data-svelte-h":!0}),U(ia)!=="svelte-5bzapm"&&(ia.textContent=Cn),yt=n(s),T(ya.$$.fragment,s),Jt=n(s),Ja=J(s,"P",{"data-svelte-h":!0}),U(Ja)!=="svelte-8njgb6"&&(Ja.textContent=gn),ct=n(s),T(ca.$$.fragment,s),Tt=n(s),T(Ta.$$.fragment,s),ot=n(s),oa=J(s,"P",{"data-svelte-h":!0}),U(oa)!=="svelte-1xfv04i"&&(oa.innerHTML=Zn),wt=n(s),Zs.l(s),Ha=n(s),T(al.$$.fragment,s),Ut=n(s),wa=J(s,"P",{"data-svelte-h":!0}),U(wa)!=="svelte-1ml52v"&&(wa.textContent=Gn),jt=n(s),T(Ua.$$.fragment,s),ht=n(s),ja=J(s,"P",{"data-svelte-h":!0}),U(ja)!=="svelte-kpt7xr"&&(ja.textContent=kn),dt=n(s),T(ha.$$.fragment,s),ut=n(s),H&&H.l(s),Da=n(s),da=J(s,"P",{"data-svelte-h":!0}),U(da)!=="svelte-18zn3n7"&&(da.innerHTML=Bn),bt=n(s),ua=J(s,"P",{"data-svelte-h":!0}),U(ua)!=="svelte-1ht7i7p"&&(ua.innerHTML=vn),It=n(s),ks.l(s),La=n(s),ba=J(s,"P",{"data-svelte-h":!0}),U(ba)!=="svelte-dulsnu"&&(ba.textContent=xn),ft=n(s),T(Ia.$$.fragment,s),Ct=n(s),fa=J(s,"P",{"data-svelte-h":!0}),U(fa)!=="svelte-1f7cfkt"&&(fa.innerHTML=$n),gt=n(s),T(Ca.$$.fragment,s),Zt=n(s),T(ga.$$.fragment,s),Gt=n(s),Za=J(s,"P",{"data-svelte-h":!0}),U(Za)!=="svelte-bfe0my"&&(Za.innerHTML=Wn),kt=n(s),vs.l(s),qa=n(s),D&&D.l(s),Ka=n(s),T(Ga.$$.fragment,s),Bt=n(s),ka=J(s,"P",{"data-svelte-h":!0}),U(ka)!=="svelte-hqz62f"&&(ka.textContent=_n),vt=n(s),T(Ba.$$.fragment,s),xt=n(s),va=J(s,"P",{"data-svelte-h":!0}),U(va)!=="svelte-w2xpgs"&&(va.textContent=Vn),$t=n(s),T(xa.$$.fragment,s),Wt=n(s),$a=J(s,"P",{"data-svelte-h":!0}),U($a)!=="svelte-uj0kjf"&&($a.textContent=Rn),_t=n(s),T(Wa.$$.fragment,s),Vt=n(s),T(_a.$$.fragment,s),Rt=n(s),Va=J(s,"P",{"data-svelte-h":!0}),U(Va)!=="svelte-jiqz5i"&&(Va.textContent=Nn),Nt=n(s),T(Ra.$$.fragment,s),Xt=n(s),T(Na.$$.fragment,s),At=n(s),Xa=J(s,"P",{"data-svelte-h":!0}),U(Xa)!=="svelte-bm45cg"&&(Xa.textContent=Xn),zt=n(s),Aa=J(s,"P",{"data-svelte-h":!0}),U(Aa)!=="svelte-z154pj"&&(Aa.textContent=An),Qt=n(s),T(za.$$.fragment,s),Yt=n(s),te=J(s,"P",{}),ne(te).forEach(l),this.h()},h(){xs(p,"name","hf:doc:metadata"),xs(p,"content",VM),JM(X.src,Q="https://course-demos-mt5-small-finetuned-amazon-en-es.hf.space")||xs(X,"src",Q),xs(X,"frameborder","0"),xs(X,"height","400"),xs(X,"title","Gradio app"),xs(X,"class","block dark:hidden container p-0 flex-grow space-iframe"),xs(X,"allow","accelerometer; ambient-light-sensor; autoplay; battery; camera; document-domain; encrypted-media; fullscreen; geolocation; gyroscope; layout-animations; legacy-image-formats; magnetometer; microphone; midi; oversized-images; payment; picture-in-picture; publickey-credentials-get; sync-xhr; usb; vr ; wake-lock; xr-spatial-tracking"),xs(X,"sandbox","allow-forms allow-modals allow-popups allow-popups-to-escape-sandbox allow-same-origin allow-scripts allow-downloads"),xs(Cs,"class","flex justify-center"),xs(qs,"class","flex justify-center"),Ae.a=null,Qe.a=null},m(s,e){qt(document.head,p),a(s,u,e),a(s,r,e),a(s,f,e),o(k,s,e),a(s,g,e),o(W,s,e),a(s,I,e),Qa[Z].m(s,e),a(s,B,e),a(s,z,e),a(s,N,e),o(_,s,e),a(s,x,e),a(s,C,e),a(s,L,e),a(s,X,e),a(s,K,e),a(s,A,e),a(s,S,e),o(Y,s,e),a(s,F,e),a(s,j,e),a(s,ys,e),o(h,s,e),a(s,$,e),o(P,s,e),a(s,Ns,e),a(s,O,e),a(s,Xs,e),o(ss,s,e),a(s,nl,e),o(Js,s,e),a(s,cs,e),o(fs,s,e),a(s,As,e),a(s,ls,e),a(s,Ts,e),o($s,s,e),a(s,zs,e),o(as,s,e),a(s,Qs,e),a(s,es,e),a(s,Ys,e),o(ts,s,e),a(s,pl,e),a(s,os,e),a(s,Es,e),o(ns,s,e),a(s,Ss,e),a(s,Ms,e),a(s,Fs,e),o(ps,s,e),a(s,Hs,e),o(rs,s,e),a(s,rl,e),a(s,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Fa],1,1,()=>{Qa[Fa]=null}),Oa(),R=Qa[Z],R||(R=Qa[Z]=zn[Z](s),R.c()),m(R,1),R.m(B.parentNode,B));const Ln={};e&2&&(Ln.$$scope={dirty:e,ctx:s}),fs.$set(Ln);const qn={};e&2&&(qn.$$scope={dirty:e,ctx:s}),Ks.$set(qn);const Kn={};e&2&&(Kn.$$scope={dirty:e,ctx:s}),Ps.$set(Kn);const Pn={};e&2&&(Pn.$$scope={dirty:e,ctx:s}),Os.$set(Pn);const On={};e&2&&(On.$$scope={dirty:e,ctx:s}),sl.$set(On);const sM={};e&2&&(sM.$$scope={dirty:e,ctx:s}),ll.$set(sM);let Ht=gs;gs=En(s),gs!==Ht&&(se(),i(Ya[Ht],1,1,()=>{Ya[Ht]=null}),Oa(),Zs=Ya[gs],Zs||(Zs=Ya[gs]=Yn[gs](s),Zs.c()),m(Zs,1),Zs.m(Ha.parentNode,Ha));const lM={};e&2&&(lM.$$scope={dirty:e,ctx:s}),al.$set(lM),s[0]==="pt"?H?e&1&&m(H,1):(H=MM(),H.c(),m(H,1),H.m(Da.parentNode,Da)):H&&(se(),i(H,1,1,()=>{H=null}),Oa());let Dt=Gs;Gs=Fn(s),Gs!==Dt&&(se(),i(Ea[Dt],1,1,()=>{Ea[Dt]=null}),Oa(),ks=Ea[Gs],ks||(ks=Ea[Gs]=Sn[Gs](s),ks.c()),m(ks,1),ks.m(La.parentNode,La));let Lt=Bs;Bs=Dn(s),Bs!==Lt&&(se(),i(Sa[Lt],1,1,()=>{Sa[Lt]=null}),Oa(),vs=Sa[Bs],vs||(vs=Sa[Bs]=Hn[Bs](s),vs.c()),m(vs,1),vs.m(qa.parentNode,qa)),s[0]==="pt"?D?e&1&&m(D,1):(D=pM(s),D.c(),m(D,1),D.m(Ka.parentNode,Ka)):D&&(se(),i(D,1,1,()=>{D=null}),Oa())},i(s){Et||(m(k.$$.fragment,s),m(W.$$.fragment,s),m(R),m(_.$$.fragment,s),m(Y.$$.fragment,s),m(h.$$.fragment,s),m(P.$$.fragment,s),m(ss.$$.fragment,s),m(Js.$$.fragment,s),m(fs.$$.fragment,s),m($s.$$.fragment,s),m(as.$$.fragment,s),m(ts.$$.fragment,s),m(ns.$$.fragment,s),m(ps.$$.fragment,s),m(rs.$$.fragment,s),m(ms.$$.fragment,s),m(Us.$$.fragment,s),m(is.$$.fragment,s),m(cl.$$.fragment,s),m(Ks.$$.fragment,s),m(hl.$$.fragment,s),m(dl.$$.fragment,s),m(bl.$$.fragment,s),m(Ps.$$.fragment,s),m(fl.$$.fragment,s),m(Cl.$$.fragment,s),m(Zl.$$.fragment,s),m(Gl.$$.fragment,s),m(vl.$$.fragment,s),m(Wl.$$.fragment,s),m(Os.$$.fragment,s),m(Vl.$$.fragment,s),m(Rl.$$.fragment,s),m(Al.$$.fragment,s),m(sl.$$.fragment,s),m(Sl.$$.fragment,s),m(Hl.$$.fragment,s),m(Ll.$$.fragment,s),m(ql.$$.fragment,s),m(Pl.$$.fragment,s),m(Ol.$$.fragment,s),m(ll.$$.fragment,s),m(aa.$$.fragment,s),m(ta.$$.fragment,s),m(Ma.$$.fragment,s),m(ra.$$.fragment,s),m(ma.$$.fragment,s),m(ya.$$.fragment,s),m(ca.$$.fragment,s),m(Ta.$$.fragment,s),m(Zs),m(al.$$.fragment,s),m(Ua.$$.fragment,s),m(ha.$$.fragment,s),m(H),m(ks),m(Ia.$$.fragment,s),m(Ca.$$.fragment,s),m(ga.$$.fragment,s),m(vs),m(D),m(Ga.$$.fragment,s),m(Ba.$$.fragment,s),m(xa.$$.fragment,s),m(Wa.$$.fragment,s),m(_a.$$.fragment,s),m(Ra.$$.fragment,s),m(Na.$$.fragment,s),m(za.$$.fragment,s),Et=!0)},o(s){i(k.$$.fragment,s),i(W.$$.fragment,s),i(R),i(_.$$.fragment,s),i(Y.$$.fragment,s),i(h.$$.fragment,s),i(P.$$.fragment,s),i(ss.$$.fragment,s),i(Js.$$.fragment,s),i(fs.$$.fragment,s),i($s.$$.fragment,s),i(as.$$.fragment,s),i(ts.$$.fragment,s),i(ns.$$.fragment,s),i(ps.$$.fragment,s),i(rs.$$.fragment,s),i(ms.$$.fragment,s),i(Us.$$.fragment,s),i(is.$$.fragment,s),i(cl.$$.fragment,s),i(Ks.$$.fragment,s),i(hl.$$.fragment,s),i(dl.$$.fragment,s),i(bl.$$.fragment,s),i(Ps.$$.fragment,s),i(fl.$$.fragment,s),i(Cl.$$.fragment,s),i(Zl.$$.fragment,s),i(Gl.$$.fragment,s),i(vl.$$.fragment,s),i(Wl.$$.fragment,s),i(Os.$$.fragment,s),i(Vl.$$.fragment,s),i(Rl.$$.fragment,s),i(Al.$$.fragment,s),i(sl.$$.fragment,s),i(Sl.$$.fragment,s),i(Hl.$$.fragment,s),i(Ll.$$.fragment,s),i(ql.$$.fragment,s),i(Pl.$$.fragment,s),i(Ol.$$.fragment,s),i(ll.$$.fragment,s),i(aa.$$.fragment,s),i(ta.$$.fragment,s),i(Ma.$$.fragment,s),i(ra.$$.fragment,s),i(ma.$$.fragment,s),i(ya.$$.fragment,s),i(ca.$$.fragment,s),i(Ta.$$.fragment,s),i(Zs),i(al.$$.fragment,s),i(Ua.$$.fragment,s),i(ha.$$.fragment,s),i(H),i(ks),i(Ia.$$.fragment,s),i(Ca.$$.fragment,s),i(ga.$$.fragment,s),i(vs),i(D),i(Ga.$$.fragment,s),i(Ba.$$.fragment,s),i(xa.$$.fragment,s),i(Wa.$$.fragment,s),i(_a.$$.fragment,s),i(Ra.$$.fragment,s),i(Na.$$.fragment,s),i(za.$$.fragment,s),Et=!1},d(s){s&&(l(u),l(r),l(f),l(g),l(I),l(B),l(z),l(N),l(x),l(C),l(L),l(X),l(K),l(A),l(S),l(F),l(j),l(ys),l($),l(Ns),l(O),l(Xs),l(nl),l(cs),l(As),l(ls),l(Ts),l(zs),l(Qs),l(es),l(Ys),l(pl),l(os),l(Es),l(Ss),l(Ms),l(Fs),l(Hs),l(rl),l(ws),l(Ds),l(ml),l(js),l(Vs),l(hs),l(Cs),l(ds),l(us),l(Ls),l(Jl),l(bs),l(b),l(Me),l(Tl),l(pe),l(ol),l(re),l(wl),l(me),l(Ul),l(ie),l(qs),l(ye),l(jl),l(Je),l(ce),l(Te),l(oe),l(ul),l(we),l(Ue),l(je),l(Il),l(he),l(de),l(ue),l(gl),l(be),l(Ie),l(fe),l(kl),l(Ce),l(Bl),l(ge),l(Ze),l(xl),l(Ge),l($l),l(ke),l(Be),l(_l),l(ve),l(xe),l($e),l(We),l(Nl),l(_e),l(Xl),l(Ve),l(Re),l(zl),l(Ne),l(Xe),l(Ql),l(ze),l(Yl),l(Ye),l(El),l(Ee),l(Se),l(Fl),l(Fe),l(He),l(Dl),l(De),l(Le),l(qe),l(Kl),l(Ke),l(Pe),l(Oe),l(sa),l(st),l(lt),l(la),l(at),l(et),l(ea),l(tt),l(nt),l(na),l(Mt),l(pt),l(pa),l(rt),l(mt),l(it),l(ia),l(yt),l(Jt),l(Ja),l(ct),l(Tt),l(ot),l(oa),l(wt),l(Ha),l(Ut),l(wa),l(jt),l(ht),l(ja),l(dt),l(ut),l(Da),l(da),l(bt),l(ua),l(It),l(La),l(ba),l(ft),l(Ct),l(fa),l(gt),l(Zt),l(Gt),l(Za),l(kt),l(qa),l(Ka),l(Bt),l(ka),l(vt),l(xt),l(va),l($t),l(Wt),l($a),l(_t),l(Vt),l(Rt),l(Va),l(Nt),l(Xt),l(At),l(Xa),l(zt),l(Aa),l(Qt),l(Yt),l(te)),l(p),w(k,s),w(W,s),Qa[Z].d(s),w(_,s),w(Y,s),w(h,s),w(P,s),w(ss,s),w(Js,s),w(fs,s),w($s,s),w(as,s),w(ts,s),w(ns,s),w(ps,s),w(rs,s),w(ms,s),w(Us,s),w(is,s),w(cl,s),w(Ks,s),w(hl,s),w(dl,s),w(bl,s),w(Ps,s),w(fl,s),w(Cl,s),w(Zl,s),w(Gl,s),w(vl,s),w(Wl,s),w(Os,s),w(Vl,s),w(Rl,s),w(Al,s),w(sl,s),w(Sl,s),w(Hl,s),w(Ll,s),w(ql,s),w(Pl,s),w(Ol,s),w(ll,s),w(aa,s),w(ta,s),w(Ma,s),w(ra,s),w(ma,s),w(ya,s),w(ca,s),w(Ta,s),Ya[gs].d(s),w(al,s),w(Ua,s),w(ha,s),H&&H.d(s),Ea[Gs].d(s),w(Ia,s),w(Ca,s),w(ga,s),Sa[Bs].d(s),D&&D.d(s),w(Ga,s),w(Ba,s),w(xa,s),w(Wa,s),w(_a,s),w(Ra,s),w(Na,s),w(za,s)}}}const VM='{"title":"提取文本摘要","local":"提取文本摘要","sections":[{"title":"准备多语言语料库","local":"准备多语言语料库","sections":[],"depth":2},{"title":"文本摘要模型","local":"文本摘要模型","sections":[],"depth":2},{"title":"预处理数据","local":"预处理数据","sections":[],"depth":2},{"title":"文本摘要的指标","local":"文本摘要的指标","sections":[{"title":"创建强大的baseline","local":"创建强大的baseline","sections":[],"depth":3}],"depth":2},{"title":"使用 Trainer API微调mT5","local":"使用 Trainer API微调mT5","sections":[],"depth":2},{"title":"使用 Keras API微调mT5","local":"使用 Keras API微调mT5","sections":[],"depth":2},{"title":"使用 🤗 Accelerate 微调 mT5","local":"使用 🤗 Accelerate 微调 mT5","sections":[{"title":"为训练做好一切准备","local":"为训练做好一切准备","sections":[],"depth":3},{"title":"训练循环","local":"训练循环","sections":[],"depth":3}],"depth":2},{"title":"使用您微调的模型","local":"使用您微调的模型","sections":[],"depth":2}],"depth":1}';function RM(G,p,u){let r="pt";return cM(()=>{const f=new URLSearchParams(window.location.search);u(0,r=f.get("fw")||"pt")}),[r]}class FM extends TM{constructor(p){super(),oM(this,p,RM,_M,yM,{})}}export{FM as component};
