import{s as rM,f as TM,o as UM,n as ts}from"../chunks/scheduler.37c15a92.js";import{S as iM,i as mM,g as T,s as t,r as i,m as eM,H as aM,A as jM,h as U,f as s,c as n,j as na,u as m,x as o,n as tM,E as nM,k as Rl,y as qt,a as e,v as j,t as r,b as Pe,d as y,w,p as la}from"../chunks/index.2bf4358c.js";import{T as as}from"../chunks/Tip.363c041f.js";import{Y as Ot}from"../chunks/Youtube.1e50a667.js";import{C as d}from"../chunks/CodeBlock.4e987730.js";import{D as JM}from"../chunks/DocNotebookDropdown.efc1fb7c.js";import{F as wM}from"../chunks/FrameworkSwitchCourse.8d4d4ab6.js";import{H as Il,E as oM}from"../chunks/getInferenceSnippets.7bb25a7f.js";function dM(g){let J,u;return J=new JM({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(){i(J.$$.fragment)},l(c){m(J.$$.fragment,c)},m(c,I){j(J,c,I),u=!0},i(c){u||(y(J.$$.fragment,c),u=!0)},o(c){r(J.$$.fragment,c),u=!1},d(c){w(J,c)}}}function uM(g){let J,u;return J=new JM({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(){i(J.$$.fragment)},l(c){m(J.$$.fragment,c)},m(c,I){j(J,c,I),u=!0},i(c){u||(y(J.$$.fragment,c),u=!0)},o(c){r(J.$$.fragment,c),u=!1},d(c){w(J,c)}}}function bM(g){let J,u="✏️ <strong>试试看！</strong> 更改 <code>Dataset.shuffle()</code> 命令中的随机种子以探索语料库中的其他评论。如果你是说西班牙语的人，请查看 <code>spanish_dataset</code> 中的一些评论，看看标题是否像是合理的摘要。";return{c(){J=T("p"),J.innerHTML=u},l(c){J=U(c,"P",{"data-svelte-h":!0}),o(J)!=="svelte-tcmbtn"&&(J.innerHTML=u)},m(c,I){e(c,J,I)},p:ts,d(c){c&&s(J)}}}function hM(g){let J,u="✏️ <strong>试试看！</strong> 完成本节后，可以尝试比较一下 mT5 和用相同技术微调过的 mBART 的性能。附加的挑战：只在英文评论上微调 T5。因为 T5 有一个特殊的前缀提示，你需要在下面的预处理步骤中将 <code>summarize:</code> 添加到输入例子前。";return{c(){J=T("p"),J.innerHTML=u},l(c){J=U(c,"P",{"data-svelte-h":!0}),o(J)!=="svelte-1a7u20u"&&(J.innerHTML=u)},m(c,I){e(c,J,I)},p:ts,d(c){c&&s(J)}}}function IM(g){let J,u="💡在 NLP 项目的早期阶段，一个好的做法是在小样本数据上训练一类“小”模型。这使你可以更快地调试和迭代端到端工作流。当你对结果有信心之后，你只需要通过简单地更改模型 checkpoint 就可以在较大规模数据上训练模型！";return{c(){J=T("p"),J.textContent=u},l(c){J=U(c,"P",{"data-svelte-h":!0}),o(J)!=="svelte-1n3fajv"&&(J.textContent=u)},m(c,I){e(c,J,I)},p:ts,d(c){c&&s(J)}}}function CM(g){let J,u="💡 你可能已经注意到我们在上面的 <code>Dataset.map()</code> 函数中使用了 <code>batched=True</code> 。这将以 1000（默认值）的 batch size 对示例继续编码，并让你可以利用 🤗 Transformers 中快速 tokenizer 的多线程功能。在可能的情况下，尝试使用 <code>batched=True</code> 来加速你的预处理！";return{c(){J=T("p"),J.innerHTML=u},l(c){J=U(c,"P",{"data-svelte-h":!0}),o(J)!=="svelte-135nn0g"&&(J.innerHTML=u)},m(c,I){e(c,J,I)},p:ts,d(c){c&&s(J)}}}function fM(g){let J,u='🙋 如果这是你第一次听说精确度（Precision）和召回率（Recall），请不要担心——我们将一起通过一些清晰的示例来理解它们。这些指标通常在分类任务中遇到，所以如果你想了解在分类任务中精确度（Precision）和召回率（Recall）是如何定义的，我们建议你查看 <code>scikit-learn</code> 的 <a href="https://scikit-learn.org/stable/auto_examples/model_selection/plot_precision_recall.html" rel="nofollow">指南</a> 。';return{c(){J=T("p"),J.innerHTML=u},l(c){J=U(c,"P",{"data-svelte-h":!0}),o(J)!=="svelte-199nz8t"&&(J.innerHTML=u)},m(c,I){e(c,J,I)},p:ts,d(c){c&&s(J)}}}function kM(g){let J,u="✏️ <strong>试试看！</strong> 自己手动创建一个生成摘要和参考摘要，看看使用 evaluate 得出的 ROUGE 分数是否与基于精确度和召回率公式的手动计算一致。附加的挑战：将文本切分为长度为2的词组，并手动计算精度和召回率与 <code>rouge2</code> 指标的精确度和召回率进行对比。";return{c(){J=T("p"),J.innerHTML=u},l(c){J=U(c,"P",{"data-svelte-h":!0}),o(J)!=="svelte-8527q"&&(J.innerHTML=u)},m(c,I){e(c,J,I)},p:ts,d(c){c&&s(J)}}}function ZM(g){let J,u,c,I="微调模型来提取摘要与我们在本章中介绍的其他任务非常相似。我们需要做的第一件事是从 <code>mt5-small</code> checkpoint 中加载预训练模型。由于摘要提取是一个序列到序列的任务，我们可以使用 <code>TFAutoModelForSeq2SeqLM</code> 类加载模型，该类会自动下载并缓存模型权重：",G,k,$;return J=new Il({props:{title:"使用 Keras API 微调 mT5",local:"使用 Keras API 微调 mT5",headingTag:"h2"}}),k=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(){i(J.$$.fragment),u=t(),c=T("p"),c.innerHTML=I,G=t(),i(k.$$.fragment)},l(h){m(J.$$.fragment,h),u=n(h),c=U(h,"P",{"data-svelte-h":!0}),o(c)!=="svelte-14ymmqp"&&(c.innerHTML=I),G=n(h),m(k.$$.fragment,h)},m(h,Z){j(J,h,Z),e(h,u,Z),e(h,c,Z),e(h,G,Z),j(k,h,Z),$=!0},i(h){$||(y(J.$$.fragment,h),y(k.$$.fragment,h),$=!0)},o(h){r(J.$$.fragment,h),r(k.$$.fragment,h),$=!1},d(h){h&&(s(u),s(c),s(G)),w(J,h),w(k,h)}}}function gM(g){let J,u,c,I="微调模型来提取摘要与我们在本章中介绍的其他任务非常相似。我们需要做的第一件事是从 <code>mt5-small</code> checkpoint 中加载预训练模型。由于摘要提取是一个序列到序列的任务，我们可以使用 AutoModelForSeq2SeqLM 类加载模型，该类会自动下载并缓存模型权重：",G,k,$;return J=new Il({props:{title:"使用 Trainer API 微调 mT5",local:"使用 Trainer API 微调 mT5",headingTag:"h2"}}),k=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(){i(J.$$.fragment),u=t(),c=T("p"),c.innerHTML=I,G=t(),i(k.$$.fragment)},l(h){m(J.$$.fragment,h),u=n(h),c=U(h,"P",{"data-svelte-h":!0}),o(c)!=="svelte-10ncu66"&&(c.innerHTML=I),G=n(h),m(k.$$.fragment,h)},m(h,Z){j(J,h,Z),e(h,u,Z),e(h,c,Z),e(h,G,Z),j(k,h,Z),$=!0},i(h){$||(y(J.$$.fragment,h),y(k.$$.fragment,h),$=!0)},o(h){r(J.$$.fragment,h),r(k.$$.fragment,h),$=!1},d(h){h&&(s(u),s(c),s(G)),w(J,h),w(k,h)}}}function GM(g){let J,u='💡 如果你想知道为什么在实例化的过程中没有看到任何关于微调模型的警告，那是因为对于序列到序列的任务，我们保留了网络的所有权重。与此相比，在 <a href="https://chat.openai.com/course/chapter3" rel="nofollow">第三章</a> 中的文本分类模型中，我们用一个随机初始化的网络替换了预训练模型的头部。';return{c(){J=T("p"),J.innerHTML=u},l(c){J=U(c,"P",{"data-svelte-h":!0}),o(J)!=="svelte-1j1p0yv"&&(J.innerHTML=u)},m(c,I){e(c,J,I)},p:ts,d(c){c&&s(J)}}}function MM(g){let J,u="为了在训练期间计算 <code>ROUGE</code> 分数，我们需要在训练期间生成文本形式的摘要。幸运的是，🤗 Transformers 提供了专用的 <code>Seq2SeqTrainingArguments</code> 和 <code>Seq2SeqTrainer</code> 类，可以自动为我们完成这项工作！为了了解它是如何工作的，让我们首先为我们的实验定义超参数和其他参数,在后面的的训练过程会讲到如何实现的。",c,I,G,k,$='在上面的代码中，我们把 <code>predict_with_generate</code> 参数设置为 <code>True</code> ，这样可以在评估期间生成摘要来计算每个 <code>epoch</code> 的 ROUGE 分数。正如在 <a href="/course/chapter1">第一章</a> 中学到的，模型的 <code>generate()</code> 函数实现了使用解码器逐个预测单词来推理生成的文本。设置 <code>predict_with_generate=True</code> 后，<code>Seq2SeqTrainer</code> 会在评估时使用 <code>generate()</code> 函数。除此之外我们还调整默认的超参数，如学习率、<code>epochs</code> 数和权重衰减，并且设置 <code>save_total_limit</code> 选项， 使训练期间最多只能保存 3 个 <code>checkpoint</code> 的选项。——这是因为即使是 mT5 的“small”版本也使用大约 1 GB 的硬盘空间，我们可以通过限制保存的副本数量来节省一点空间。',h,Z,N='设置 <code>push_to_hub=True</code>  选项后 <code>Trainer</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>Seq2SeqTrainingArguments</code> 中添加了 <code>hub_model_id=&quot;huggingface-course/mt5-finetuned-amazon-en-es&quot;</code> 。',B,A,X="为了在训练期间评估模型，我们还需要为 <code>Trainer</code> 提供一个 <code>compute_metrics()</code> 函数。对于摘要模型来说，不能直接调用 <code>rouge_score.compute()</code> 进行评估，因为我们需要将输出和参考摘要解码为文本，然后才能计算 ROUGE 分数。下面的函数就完成了解码和计算分数，除此之外还使用了 <code>nltk</code> 中的 <code>sent_tokenize()</code> 函数将摘要句子用换行符分隔开：",x,Q,R;return I=new d({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMFNlcTJTZXFUcmFpbmluZ0FyZ3VtZW50cyUwQSUwQWJhdGNoX3NpemUlMjAlM0QlMjA4JTBBbnVtX3RyYWluX2Vwb2NocyUyMCUzRCUyMDglMEElMjMlMjAlRTYlQUYlOEYlRTQlQjglQUElRTglQUUlQUQlRTclQkIlODMlRTUlOTElQTglRTYlOUMlOUYlRTklODMlQkQlRTglQkUlOTMlRTUlODclQkElRTglQUUlQUQlRTclQkIlODMlRTYlOEQlOUYlRTUlQTQlQjElMEFsb2dnaW5nX3N0ZXBzJTIwJTNEJTIwbGVuKHRva2VuaXplZF9kYXRhc2V0cyU1QiUyMnRyYWluJTIyJTVEKSUyMCUyRiUyRiUyMGJhdGNoX3NpemUlMEFtb2RlbF9uYW1lJTIwJTNEJTIwbW9kZWxfY2hlY2twb2ludC5zcGxpdCglMjIlMkYlMjIpJTVCLTElNUQlMEElMEFhcmdzJTIwJTNEJTIwU2VxMlNlcVRyYWluaW5nQXJndW1lbnRzKCUwQSUyMCUyMCUyMCUyMG91dHB1dF9kaXIlM0RmJTIyJTdCbW9kZWxfbmFtZSU3RC1maW5ldHVuZWQtYW1hem9uLWVuLWVzJTIyJTJDJTBBJTIwJTIwJTIwJTIwZXZhbHVhdGlvbl9zdHJhdGVneSUzRCUyMmVwb2NoJTIyJTJDJTBBJTIwJTIwJTIwJTIwbGVhcm5pbmdfcmF0ZSUzRDUuNmUtNSUyQyUwQSUyMCUyMCUyMCUyMHBlcl9kZXZpY2VfdHJhaW5fYmF0Y2hfc2l6ZSUzRGJhdGNoX3NpemUlMkMlMEElMjAlMjAlMjAlMjBwZXJfZGV2aWNlX2V2YWxfYmF0Y2hfc2l6ZSUzRGJhdGNoX3NpemUlMkMlMEElMjAlMjAlMjAlMjB3ZWlnaHRfZGVjYXklM0QwLjAxJTJDJTBBJTIwJTIwJTIwJTIwc2F2ZV90b3RhbF9saW1pdCUzRDMlMkMlMEElMjAlMjAlMjAlMjBudW1fdHJhaW5fZXBvY2hzJTNEbnVtX3RyYWluX2Vwb2NocyUyQyUwQSUyMCUyMCUyMCUyMHByZWRpY3Rfd2l0aF9nZW5lcmF0ZSUzRFRydWUlMkMlMEElMjAlMjAlMjAlMjBsb2dnaW5nX3N0ZXBzJTNEbG9nZ2luZ19zdGVwcyUyQyUwQSUyMCUyMCUyMCUyMHB1c2hfdG9faHViJTNEVHJ1ZSUyQyUwQSk=",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"># 每个训练周期都输出训练损失</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=logging_steps,
    push_to_hub=<span class="hljs-literal">True</span>,
)`,wrap:!1}}),Q=new d({props:{code:"aW1wb3J0JTIwbnVtcHklMjBhcyUyMG5wJTBBJTBBJTBBZGVmJTIwY29tcHV0ZV9tZXRyaWNzKGV2YWxfcHJlZCklM0ElMEElMjAlMjAlMjAlMjBwcmVkaWN0aW9ucyUyQyUyMGxhYmVscyUyMCUzRCUyMGV2YWxfcHJlZCUwQSUyMCUyMCUyMCUyMCUyMyUyMCVFNSVCMCU4NiVFNyU5NCU5RiVFNiU4OCU5MCVFNyU5QSU4NCVFNiU5MSU5OCVFOCVBNiU4MSVFOCVBNyVBMyVFNyVBMCU4MSVFNCVCOCVCQSVFNiU5NiU4NyVFNiU5QyVBQyUwQSUyMCUyMCUyMCUyMGRlY29kZWRfcHJlZHMlMjAlM0QlMjB0b2tlbml6ZXIuYmF0Y2hfZGVjb2RlKHByZWRpY3Rpb25zJTJDJTIwc2tpcF9zcGVjaWFsX3Rva2VucyUzRFRydWUpJTBBJTIwJTIwJTIwJTIwJTIzJTIwJUU2JTlCJUJGJUU2JThEJUEyJUU2JUEwJTg3JUU3JUFEJUJFJUU0JUI4JUFEJUU3JTlBJTg0LTEwMCUyQyVFNSU5QiVBMCVFNCVCOCVCQSVFNiU4OCU5MSVFNCVCQiVBQyVFNiU5NyVBMCVFNiVCMyU5NSVFOCVBNyVBMyVFNyVBMCU4MSVFNSVBRSU4MyVFNCVCQiVBQyUwQSUyMCUyMCUyMCUyMGxhYmVscyUyMCUzRCUyMG5wLndoZXJlKGxhYmVscyUyMCElM0QlMjAtMTAwJTJDJTIwbGFiZWxzJTJDJTIwdG9rZW5pemVyLnBhZF90b2tlbl9pZCklMEElMjAlMjAlMjAlM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XIlM0RUcnVlJTBBJTIwJTIwJTIwJTIwKSUwQSUyMCUyMCUyMCUyMCUyMyUyMCVFOCVBRSVBMSVFNyVBRSU5N1JPVUdFJUU1JTg4JTg2JUU2JTk1JUIwJTBBJTIwJTIwJTIwJTIwcmVzdWx0JTIwJTNEJTIwJTdCa2V5JTNBJTIwdmFsdWUubWlkLmZtZWFzdXJlJTIwKiUyMDEwMCUyMGZvciUyMGtleSUyQyUyMHZhbHVlJTIwaW4lMjByZXN1bHQuaXRlbXMoKSU3RCUwQSUyMCUyMCUyMCUyMHJldHVybiUyMCU3QmslM0ElMjByb3VuZCh2JTJDJTIwNCklMjBmb3IlMjBrJTJDJTIwdiUyMGluJTIwcmVzdWx0Lml0ZW1zKCklN0Q=",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"># 将生成的摘要解码为文本</span>
    decoded_preds = tokenizer.batch_decode(predictions, skip_special_tokens=<span class="hljs-literal">True</span>)
    <span class="hljs-comment"># 替换标签中的-100,因为我们无法解码它们</span>
    labels = np.where(labels != -<span class="hljs-number">100</span>, labels, tokenizer.pad_token_id)
    <span class="hljs-comment"># 将参考摘要解码为文本</span>
    decoded_labels = tokenizer.batch_decode(labels, skip_special_tokens=<span class="hljs-literal">True</span>)
    <span class="hljs-comment"># ROUGE期望每个句子后都有一个换行符</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"># 计算ROUGE分数</span>
    result = rouge_score.compute(
        predictions=decoded_preds, references=decoded_labels, use_stemmer=<span class="hljs-literal">True</span>
    )
    <span class="hljs-comment"># 计算ROUGE分数</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(){J=T("p"),J.innerHTML=u,c=t(),i(I.$$.fragment),G=t(),k=T("p"),k.innerHTML=$,h=t(),Z=T("p"),Z.innerHTML=N,B=t(),A=T("p"),A.innerHTML=X,x=t(),i(Q.$$.fragment)},l(f){J=U(f,"P",{"data-svelte-h":!0}),o(J)!=="svelte-1pi4697"&&(J.innerHTML=u),c=n(f),m(I.$$.fragment,f),G=n(f),k=U(f,"P",{"data-svelte-h":!0}),o(k)!=="svelte-1ss8xg4"&&(k.innerHTML=$),h=n(f),Z=U(f,"P",{"data-svelte-h":!0}),o(Z)!=="svelte-1dfoxpk"&&(Z.innerHTML=N),B=n(f),A=U(f,"P",{"data-svelte-h":!0}),o(A)!=="svelte-v4vgeb"&&(A.innerHTML=X),x=n(f),m(Q.$$.fragment,f)},m(f,V){e(f,J,V),e(f,c,V),j(I,f,V),e(f,G,V),e(f,k,V),e(f,h,V),e(f,Z,V),e(f,B,V),e(f,A,V),e(f,x,V),j(Q,f,V),R=!0},i(f){R||(y(I.$$.fragment,f),y(Q.$$.fragment,f),R=!0)},o(f){r(I.$$.fragment,f),r(Q.$$.fragment,f),R=!1},d(f){f&&(s(J),s(c),s(G),s(k),s(h),s(Z),s(B),s(A),s(x)),w(I,f),w(Q,f)}}}function BM(g){let J,u;return J=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(){i(J.$$.fragment)},l(c){m(J.$$.fragment,c)},m(c,I){j(J,c,I),u=!0},i(c){u||(y(J.$$.fragment,c),u=!0)},o(c){r(J.$$.fragment,c),u=!1},d(c){w(J,c)}}}function VM(g){let J,u;return J=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(){i(J.$$.fragment)},l(c){m(J.$$.fragment,c)},m(c,I){j(J,c,I),u=!0},i(c){u||(y(J.$$.fragment,c),u=!0)},o(c){r(J.$$.fragment,c),u=!1},d(c){w(J,c)}}}function RM(g){let J,u="我们几乎准备好训练所需的所有东西了！我们只需要使用我们上面定义的数据整理器将我们的数据集转换为 <code>tf.data.Dataset</code> ，然后 <code>compile()</code> 和 <code>fit()</code> 模型。首先，转换数据集：",c,I,G,k,$="现在，我们定义训练超参数并编译：",h,Z,N,B,A="最后，训练模型。我们添加了 <code>PushToHubCallback</code> ，它会在每个 epoch 后将模型上传到 Hub，这样我们就可以在后面用上传好的模型来进行推理：",X,x,Q,R,f="我们在训练期间看到了一些损失值，但没有看到之前计算的 <code>ROUGE</code> 分数。要获得这些指标，需要先获取模型的输出结果并将其转换为字符串。然后构建参考摘要和预测的列表，接下来就可以计算 <code>ROUGE</code> 分数了（请注意，如果在这一部分遇到缺少 <code>tqdm</code> 库，则可能需要执行 <code>!pip install tqdm</code> ）。",V,q,v='我们还将使用一种可以显着提高性能的技巧 —— 使用 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 的倍数，并使用填充整理器创建一个新数据集，然后使用 <code>@tf.function(jit_compile=True)</code> 装饰器装饰我们的生成函数，这将把整个函数标记为用 XLA 编译。',Y,F,_,O,S="我们有了参考摘要和模型输出预测的字符串的列表之后，计算 ROUGE 分数就很容易了：",E,z,W,K,H;return I=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:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMGNyZWF0ZV9vcHRpbWl6ZXIlMEFpbXBvcnQlMjB0ZW5zb3JmbG93JTIwYXMlMjB0ZiUwQSUwQSUyMyUyMCVFOCVBRSVBRCVFNyVCQiU4MyVFNiVBRCVBNSVFNiU5NSVCMCVFNiU5OCVBRiVFNiU5NSVCMCVFNiU4RCVBRSVFOSU5QiU4NiVFNCVCOCVBRCVFNyU5QSU4NCVFNiVBMCVCNyVFNiU5QyVBQyVFNiU5NSVCMCVFOSU4NyU4RiUyQyVFOSU5OSVBNCVFNCVCQiVBNSUyMGJhdGNoJTIwJUU1JUE0JUE3JUU1JUIwJThGJTJDJUU3JTg0JUI2JUU1JTkwJThFJUU0JUI5JTk4JUU0JUJCJUE1JUU2JTgwJUJCJUU3JTlBJTg0JTIwZXBvY2glMjAlRTYlOTUlQjAlRTMlODAlODIlMEElMjMlMjAlRTYlQjMlQTglRTYlODQlOEYlRTglQkYlOTklRTklODclOEMlRTclOUElODQlMjB0Zl90cmFpbl9kYXRhc2V0JTIwJUU2JTk4JUFGJTIwYmF0Y2glMjAlRTUlQkQlQTIlRTUlQkMlOEYlRTclOUElODQlMjB0Zi5kYXRhLkRhdGFzZXQlMkMlMEElMjMlMjAlRTglODAlOEMlRTQlQjglOEQlRTYlOTglQUYlRTUlOEUlOUYlRTUl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24uc2V0X2dsb2JhbF9wb2xpY3koJTIybWl4ZWRfZmxvYXQxNiUyMik=",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"># 训练步数是数据集中的样本数量,除以 batch 大小,然后乘以总的 epoch 数。</span>
<span class="hljs-comment"># 注意这里的 tf_train_dataset 是 batch 形式的 tf.data.Dataset,</span>
<span class="hljs-comment"># 而不是原始的 Hugging Face Dataset ,所以使用 len() 计算它的长度已经是 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"># 使用 float16 混合精度进行训练</span>
tf.keras.mixed_precision.set_global_policy(<span class="hljs-string">&quot;mixed_float16&quot;</span>)`,wrap:!1}}),x=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}}),F=new d({props:{code:"ZnJvbSUyMHRxZG0lMjBpbXBvcnQlMjB0cWRtJTBBaW1wb3J0JTIwbnVtcHklMjBhcyUyMG5wJTBBJTBBZ2VuZXJhdGlvbl9kYXRhX2NvbGxhdG9yJTIwJTNEJTIwRGF0YUNvbGxhdG9yRm9yU2VxMlNlcSglMEElMjAlMjAlMjAlMjB0b2tlbml6ZXIlMkMlMjBtb2RlbCUzRG1vZGVsJTJDJTIwcmV0dXJuX3RlbnNvcnMlM0QlMjJ0ZiUyMiUyQyUyMHBhZF90b19tdWx0aXBsZV9vZiUzRDMyMCUwQSklMEElMEF0Zl9nZW5lcmF0ZV9kYXRhc2V0JTIwJTNEJTIwbW9kZWwucHJlcGFyZV90Zl9kYXRhc2V0KCUwQSUyMCUyMCUyMCUyMHRva2VuaXplZF9kYXRhc2V0cyU1QiUyMnZhbGlkYXRpb24lMjIlNUQlMkMlMEElMjAlMjAlMjAlMjBjb2xsYXRlX2ZuJTNEZ2VuZXJhdGlvbl9kYXRhX2NvbGxhdG9yJTJDJTBBJTIwJTIwJTIwJTIwc2h1ZmZsZSUzREZhbHNlJTJDJTBBJTIwJTIwJTIwJTIwYmF0Y2hfc2l6ZSUzRDglMkMlMEElMjAlMjAlMjAlMjBkcm9wX3JlbWFpbmRlciUzRFRydWUlMkMlMEEpJTBBJTBBJTBBJTQwdGYuZn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YmF0Y2hfZGVjb2RlKGxhYmVscyUyQyUyMHNraXBfc3BlY2lhbF90b2tlbnMlM0RUcnVlKSUwQSUyMCUyMCUyMCUyMGRlY29kZWRfcHJlZHMlMjAlM0QlMjAlNUIlMjIlNUNuJTIyLmpvaW4oc2VudF90b2tlbml6ZShwcmVkLnN0cmlwKCkpKSUyMGZvciUyMHByZWQlMjBpbiUyMGRlY29kZWRfcHJlZHMlNUQlMEElMjAlMjAlMjAlMjBkZWNvZGVkX2xhYmVscyUyMCUzRCUyMCU1QiUyMiU1Q24lMjIuam9pbihzZW50X3Rva2VuaXplKGxhYmVsLnN0cmlwKCkpKSUyMGZvciUyMGxhYmVsJTIwaW4lMjBkZWNvZGVkX2xhYmVscyU1RCUwQSUyMCUyMCUyMCUyMGFsbF9wcmVkcy5leHRlbmQoZGVjb2RlZF9wcmVkcyklMEElMjAlMjAlMjAlMjBhbGxfbGFiZWxzLmV4dGVuZChkZWNvZGVkX2xhYmVscyk=",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}}),z=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}}),K=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(){J=T("p"),J.innerHTML=u,c=t(),i(I.$$.fragment),G=t(),k=T("p"),k.textContent=$,h=t(),i(Z.$$.fragment),N=t(),B=T("p"),B.innerHTML=A,X=t(),i(x.$$.fragment),Q=t(),R=T("p"),R.innerHTML=f,V=t(),q=T("p"),q.innerHTML=v,Y=t(),i(F.$$.fragment),_=t(),O=T("p"),O.textContent=S,E=t(),i(z.$$.fragment),W=t(),i(K.$$.fragment)},l(p){J=U(p,"P",{"data-svelte-h":!0}),o(J)!=="svelte-1t3zavh"&&(J.innerHTML=u),c=n(p),m(I.$$.fragment,p),G=n(p),k=U(p,"P",{"data-svelte-h":!0}),o(k)!=="svelte-1mnx5ma"&&(k.textContent=$),h=n(p),m(Z.$$.fragment,p),N=n(p),B=U(p,"P",{"data-svelte-h":!0}),o(B)!=="svelte-z61zrb"&&(B.innerHTML=A),X=n(p),m(x.$$.fragment,p),Q=n(p),R=U(p,"P",{"data-svelte-h":!0}),o(R)!=="svelte-1uq9pzm"&&(R.innerHTML=f),V=n(p),q=U(p,"P",{"data-svelte-h":!0}),o(q)!=="svelte-f5c22u"&&(q.innerHTML=v),Y=n(p),m(F.$$.fragment,p),_=n(p),O=U(p,"P",{"data-svelte-h":!0}),o(O)!=="svelte-oeiqc2"&&(O.textContent=S),E=n(p),m(z.$$.fragment,p),W=n(p),m(K.$$.fragment,p)},m(p,C){e(p,J,C),e(p,c,C),j(I,p,C),e(p,G,C),e(p,k,C),e(p,h,C),j(Z,p,C),e(p,N,C),e(p,B,C),e(p,X,C),j(x,p,C),e(p,Q,C),e(p,R,C),e(p,V,C),e(p,q,C),e(p,Y,C),j(F,p,C),e(p,_,C),e(p,O,C),e(p,E,C),j(z,p,C),e(p,W,C),j(K,p,C),H=!0},i(p){H||(y(I.$$.fragment,p),y(Z.$$.fragment,p),y(x.$$.fragment,p),y(F.$$.fragment,p),y(z.$$.fragment,p),y(K.$$.fragment,p),H=!0)},o(p){r(I.$$.fragment,p),r(Z.$$.fragment,p),r(x.$$.fragment,p),r(F.$$.fragment,p),r(z.$$.fragment,p),r(K.$$.fragment,p),H=!1},d(p){p&&(s(J),s(c),s(G),s(k),s(h),s(N),s(B),s(X),s(Q),s(R),s(V),s(q),s(Y),s(_),s(O),s(E),s(W)),w(I,p),w(Z,p),w(x,p),w(F,p),w(z,p),w(K,p)}}}function $M(g){let J,u="我们终于拥有了训练所需的所有的前期准备！我们现在只需要使用标准参数实例化 Trainer",c,I,G,k,$="然后启动我们的训练：",h,Z,N,B,A="在训练期间，应该可以看到训练损失逐渐减小，并且 ROUGE 分数随着 epoch 的增加而增加。训练完成之后，你可以通过运行 <code>Trainer.evaluate()</code> 来查看最后的 ROUGE 分数：",X,x,Q,R,f,V,q="从分数中我们可以看到，我们的模型轻松超过了我们的 <code>lead-3</code> baseline——很好！最后要做的是将模型权重推送到 Hub，如下所示：",v,Y,F,_,O,S,E='上面的代码会把 checkpoint 和配置文件保存到 <code>output_dir</code> ，然后将所有文件上传到 Hub。我们还可以通过 <code>tags</code> 参数指定模型的类型，这样就可以确保在 Hub 上的小工具会是一个摘要生成的小工具，而不是与 mT5 架构的默认文本生成小工具（关于模型标签的更多信息，请参见 <a href="https://huggingface.co/docs/hub/main#how-is-a-models-type-of-inference-api-and-widget-determined" rel="nofollow">🤗Hub文档</a> ）。 <code>trainer.push_to_hub()</code> 的输出是带有 Git 提交哈希的 URL，所以你可以打开 URL 轻松查看模型库的修改记录！',z,W,K="在结束本节之前，让我们看一下如何使用 🤗 Accelerate 提供的底层 API 对 mT5 进行微调。",H;return I=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}}),x=new d({props:{code:"dHJhaW5lci5ldmFsdWF0ZSgp",highlighted:"trainer.evaluate()",wrap:!1}}),R=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}}),Y=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}}),_=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(){J=T("p"),J.textContent=u,c=t(),i(I.$$.fragment),G=t(),k=T("p"),k.textContent=$,h=t(),i(Z.$$.fragment),N=t(),B=T("p"),B.innerHTML=A,X=t(),i(x.$$.fragment),Q=t(),i(R.$$.fragment),f=t(),V=T("p"),V.innerHTML=q,v=t(),i(Y.$$.fragment),F=t(),i(_.$$.fragment),O=t(),S=T("p"),S.innerHTML=E,z=t(),W=T("p"),W.textContent=K},l(p){J=U(p,"P",{"data-svelte-h":!0}),o(J)!=="svelte-k1w48q"&&(J.textContent=u),c=n(p),m(I.$$.fragment,p),G=n(p),k=U(p,"P",{"data-svelte-h":!0}),o(k)!=="svelte-g0g928"&&(k.textContent=$),h=n(p),m(Z.$$.fragment,p),N=n(p),B=U(p,"P",{"data-svelte-h":!0}),o(B)!=="svelte-1mb4sxu"&&(B.innerHTML=A),X=n(p),m(x.$$.fragment,p),Q=n(p),m(R.$$.fragment,p),f=n(p),V=U(p,"P",{"data-svelte-h":!0}),o(V)!=="svelte-83u181"&&(V.innerHTML=q),v=n(p),m(Y.$$.fragment,p),F=n(p),m(_.$$.fragment,p),O=n(p),S=U(p,"P",{"data-svelte-h":!0}),o(S)!=="svelte-1fwiaqa"&&(S.innerHTML=E),z=n(p),W=U(p,"P",{"data-svelte-h":!0}),o(W)!=="svelte-5f3tcj"&&(W.textContent=K)},m(p,C){e(p,J,C),e(p,c,C),j(I,p,C),e(p,G,C),e(p,k,C),e(p,h,C),j(Z,p,C),e(p,N,C),e(p,B,C),e(p,X,C),j(x,p,C),e(p,Q,C),j(R,p,C),e(p,f,C),e(p,V,C),e(p,v,C),j(Y,p,C),e(p,F,C),j(_,p,C),e(p,O,C),e(p,S,C),e(p,z,C),e(p,W,C),H=!0},i(p){H||(y(I.$$.fragment,p),y(Z.$$.fragment,p),y(x.$$.fragment,p),y(R.$$.fragment,p),y(Y.$$.fragment,p),y(_.$$.fragment,p),H=!0)},o(p){r(I.$$.fragment,p),r(Z.$$.fragment,p),r(x.$$.fragment,p),r(R.$$.fragment,p),r(Y.$$.fragment,p),r(_.$$.fragment,p),H=!1},d(p){p&&(s(J),s(c),s(G),s(k),s(h),s(N),s(B),s(X),s(Q),s(f),s(V),s(v),s(F),s(O),s(S),s(z),s(W)),w(I,p),w(Z,p),w(x,p),w(R,p),w(Y,p),w(_,p)}}}function pM(g){let J,u,c,I='使用 🤗 Accelerate 微调我们的模型与我们在 <a href="/course/chapter3">第三章</a> 中遇到的文本分类示例非常相似。与文本分类的主要区别在于摘要模型需要在训练期间显式生成摘要并实现 ROUGE 分数的计算（请记住， <code>Seq2SeqTrainer</code> 已经为我们实现了生成摘要的部分）。让我们看看我们如何在 🤗 Accelerate 中实现这两个要求！',G,k,$,h,Z="首先，我们需要为每个数据分组创建一个 <code>DataLoader</code> 。由于 PyTorch 的 dataloaders 的输入是由张量组成的 batch，所以我们需要将数据集的格式设定为 <code>&quot;torch&quot;</code> ：",N,B,A,X,x="然后我们可以实例化数据整理器，并使用它来定义我们的 DataLoader：",Q,R,f,V,q="接下来，我们需要定义我们要使用的优化器。与我们的其他例子一样，我们将使用 <code>AdamW</code> ，这个优化器大多数场景下都很有效：",v,Y,F,_,O="为了重新开始微调，而不是从上面微调过的模型继续微调，我们需要重新实例化 model。",S,E,z,W,K="最后，我们将模型、优化器和 dataloaders 输入到 <code>accelerator.prepare()</code> 方法中：",H,p,C,P,Wl,ll,sa="现在我们已经准备好了我们的对象，还有三个事情需要做",Al,sl,ns="<li>定义学习率调度计划。</li> <li>实现一个功能来对模型输出的摘要进行后续处理以进行评估。</li> <li>在 Hub 上创建一个模型仓库，我们可以将模型推送到该仓库。</li>",Tl,Ul,Cl="对于学习率调度，我们将使用前几节中的标准线性衰减：",vl,el,Ms,il,$l="对于后续处理，我们需要一个函数，将生成的摘要拆分为由换行符分隔的句子。这是 ROUGE 指标需要的输入格式，我们可以使用以下代码片段来实现：",Xl,al,Yl,tl,ea="如果你还记得我们是如何定义 <code>Seq2SeqTrainer</code> 的 <code>compute_metrics()</code> 函数，那么你应该对上述的代码来感到很熟悉。",El,nl,ps="最后，我们需要在 Hugging Face Hub 上创建一个模型仓库。为此，我们可以使用名为🤗 Hub 的 python 库。我们只需要为我们的仓库取一个 ID，Hub 库中有一个实用的函数可以将仓库 ID 与用户 ID 组合起来：",ml,Ql,Fl,Ml,zl,pl,aa="现在我们可以将这个仓库克隆到模型保存的路径中，该目录将存储训练生成的文件：",Sl,Jl,Hl,cl,Js="这样，我们就可以在训练期间通过调用 <code>repo.push_to_hub()</code> 方法将模型推送到 Hub！现在让我们通过写出完整的训练循环来结束我们的分析。",jl,Nl,Dl,yl,cs="文本摘要的训练循环与我们遇到的其他 🤗 Accelerate 示例非常相似，大致分为四个主要步骤：",wl,ol,xl="<li>通过在每个 epoch 迭代 <code>train_dataloader</code> 中的所有示例来训练模型。</li> <li>在每个 epoch 结束时生成摘要，首先生成 tokens 然后将它们（和参考摘要）解码为文本。</li> <li>使用我们之前的方法计算 ROUGE 分数。</li> <li>保存 checkpoint 并将所有内容推送到 Hub。在这里，我们依赖 <code>Repository</code> 对象的巧妙的 <code>blocking=False</code> 参数，以便我们可以在每个 epoch 异步地上传 checkpoint，这使我们能够继续训练，而不必等待与 GB 大小的模型慢呼呼的上传！</li>",ys,dl,fl="这些步骤可以在以下代码块中看到：",rs,ul,bl,_l,Ll,rl,Ts="就是这样！运行此程序后，你将获得与我们使用“Trainer”获得的模型和结果非常相似的模型和结果。",hl;return J=new Il({props:{title:"使用 🤗 Accelerate 微调 mT5",local:"使用 🤗 Accelerate 微调 mT5",headingTag:"h2"}}),k=new Il({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}}),R=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}}),E=new d({props:{code:"bW9kZWwlMjAlM0QlMjBBdXRvTW9kZWxGb3JTZXEyU2VxTE0uZnJvbV9wcmV0cmFpbmVkKG1vZGVsX2NoZWNrcG9pbnQp",highlighted:"model = AutoModelForSeq2SeqLM.from_pretrained(model_checkpoint)",wrap:!1}}),p=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 as({props:{$$slots:{default:[QM]},$$scope:{ctx:g}}}),el=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}}),al=new d({props:{code:"ZGVmJTIwcG9zdHByb2Nlc3NfdGV4dChwcmVkcyUyQyUyMGxhYmVscyklM0ElMEElMjAlMjAlMjAlMjBwcmVkcyUyMCUzRCUyMCU1QnByZWQuc3RyaXAoKSUyMGZvciUyMHByZWQlMjBpbiUyMHByZWRzJTVEJTBBJTIwJTIwJTIwJTIwbGFiZWxzJTIwJTNEJTIwJTVCbGFiZWwuc3RyaXAoKSUyMGZvciUyMGxhYmVsJTIwaW4lMjBsYWJlbHMlNUQlMEElMEElMjAlMjAlMjAlMjAlMjMlMjBST1VHRSUyMCVFOSU5QyU4MCVFOCVBNiU4MSVFNiVBRiU4RiVFNCVCOCVBQSVFNSU4RiVBNSVFNSVBRCU5MCVFNSU5MCU4RSVFNiU5QyU4OSVFNCVCOCU4MCVFNCVCOCVBQSVFNiU4RCVBMiVFOCVBMSU4QyVFNyVBQyVBNiUwQSUyMCUyMCUyMCUyMHByZWRzJTIwJTNEJTIwJTVCJTIyJTVDbiUyMi5qb2luKG5sdGsuc2VudF90b2tlbml6ZShwcmVkKSklMjBmb3IlMjBwcmVkJTIwaW4lMjBwcmVkcyU1RCUwQSUyMCUyMCUyMCUyMGxhYmVscyUyMCUzRCUyMCU1QiUyMiU1Q24lMjIuam9pbihubHRrLnNlbnRfdG9rZW5pemUobGFiZWwpKSUyMGZvciUyMGxhYmVsJTIwaW4lMjBsYWJlbHMlNUQlMEElMEElMjAlMjAlMjAlMjByZXR1cm4lMjBwcmVkcyUyQyUyMGxhYmVscw==",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 需要每个句子后有一个换行符</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}}),Ql=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}}),Ml=new d({props:{code:"J2xld3R1biUyRm10NS1maW5ldHVuZWQtYW1hem9uLWVuLWVzLWFjY2VsZXJhdGUn",highlighted:'<span class="hljs-string">&#x27;lewtun/mt5-finetuned-amazon-en-es-accelerate&#x27;</span>',wrap:!1}}),Jl=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}}),Nl=new Il({props:{title:"训练循环",local:"训练循环",headingTag:"h3"}}),ul=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"># 训练</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"># 评估</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"># 如果我们没有填充到最大长度,我们需要填充标签</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"># 替换标签中的 -100,因为我们无法解码它们</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"># 计算评估的 loss</span>
    result = rouge_score.compute()
    <span class="hljs-comment"># 提取中位 ROUGE 分数</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"># 保存和上传</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}}),_l=new d({props:{code:"RXBvY2glMjAwJTNBJTIwJTdCJ3JvdWdlMSclM0ElMjA1LjYzNTElMkMlMjAncm91Z2UyJyUzQSUyMDEuMTYyNSUyQyUyMCdyb3VnZUwnJTNBJTIwNS40ODY2JTJDJTIwJ3JvdWdlTHN1bSclM0ElMjA1LjUwMDUlN0QlMEFFcG9jaCUyMDElM0ElMjAlN0Incm91Z2UxJyUzQSUyMDkuODY0NiUyQyUyMCdyb3VnZTInJTN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WdlTCclM0ElMjAxMy4xNTM2JTJDJTIwJ3JvdWdlTHN1bSclM0ElMjAxMy4xMTk0JTdEJTBBRXBvY2glMjA4JTNBJTIwJTdCJ3JvdWdlMSclM0ElMjAxMy45NiUyQyUyMCdyb3VnZTInJTNBJTIwNi41OTk4JTJDJTIwJ3JvdWdlTCclM0ElMjAxMy45MTIzJTJDJTIwJ3JvdWdlTHN1bSclM0ElMjAxMy43NzQ0JTdEJTBBRXBvY2glMjA5JTNBJTIwJTdCJ3JvdWdlMSclM0ElMjAxNC4xMTkyJTJDJTIwJ3JvdWdlMiclM0ElMjA3LjAwNTklMkMlMjAncm91Z2VMJyUzQSUyMDE0LjExNzIlMkMlMjAncm91Z2VMc3VtJyUzQSUyMDEzLjk1MDklN0Q=",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(){i(J.$$.fragment),u=t(),c=T("p"),c.innerHTML=I,G=t(),i(k.$$.fragment),$=t(),h=T("p"),h.innerHTML=Z,N=t(),i(B.$$.fragment),A=t(),X=T("p"),X.textContent=x,Q=t(),i(R.$$.fragment),f=t(),V=T("p"),V.innerHTML=q,v=t(),i(Y.$$.fragment),F=t(),_=T("p"),_.textContent=O,S=t(),i(E.$$.fragment),z=t(),W=T("p"),W.innerHTML=K,H=t(),i(p.$$.fragment),C=t(),i(P.$$.fragment),Wl=t(),ll=T("p"),ll.textContent=sa,Al=t(),sl=T("ul"),sl.innerHTML=ns,Tl=t(),Ul=T("p"),Ul.textContent=Cl,vl=t(),i(el.$$.fragment),Ms=t(),il=T("p"),il.textContent=$l,Xl=t(),i(al.$$.fragment),Yl=t(),tl=T("p"),tl.innerHTML=ea,El=t(),nl=T("p"),nl.textContent=ps,ml=t(),i(Ql.$$.fragment),Fl=t(),i(Ml.$$.fragment),zl=t(),pl=T("p"),pl.textContent=aa,Sl=t(),i(Jl.$$.fragment),Hl=t(),cl=T("p"),cl.innerHTML=Js,jl=t(),i(Nl.$$.fragment),Dl=t(),yl=T("p"),yl.textContent=cs,wl=t(),ol=T("ol"),ol.innerHTML=xl,ys=t(),dl=T("p"),dl.textContent=fl,rs=t(),i(ul.$$.fragment),bl=t(),i(_l.$$.fragment),Ll=t(),rl=T("p"),rl.textContent=Ts},l(M){m(J.$$.fragment,M),u=n(M),c=U(M,"P",{"data-svelte-h":!0}),o(c)!=="svelte-wu70u8"&&(c.innerHTML=I),G=n(M),m(k.$$.fragment,M),$=n(M),h=U(M,"P",{"data-svelte-h":!0}),o(h)!=="svelte-e8jrik"&&(h.innerHTML=Z),N=n(M),m(B.$$.fragment,M),A=n(M),X=U(M,"P",{"data-svelte-h":!0}),o(X)!=="svelte-kdk3mg"&&(X.textContent=x),Q=n(M),m(R.$$.fragment,M),f=n(M),V=U(M,"P",{"data-svelte-h":!0}),o(V)!=="svelte-jwwixh"&&(V.innerHTML=q),v=n(M),m(Y.$$.fragment,M),F=n(M),_=U(M,"P",{"data-svelte-h":!0}),o(_)!=="svelte-195z74x"&&(_.textContent=O),S=n(M),m(E.$$.fragment,M),z=n(M),W=U(M,"P",{"data-svelte-h":!0}),o(W)!=="svelte-17m50n9"&&(W.innerHTML=K),H=n(M),m(p.$$.fragment,M),C=n(M),m(P.$$.fragment,M),Wl=n(M),ll=U(M,"P",{"data-svelte-h":!0}),o(ll)!=="svelte-2jqjwc"&&(ll.textContent=sa),Al=n(M),sl=U(M,"UL",{"data-svelte-h":!0}),o(sl)!=="svelte-17xyoqw"&&(sl.innerHTML=ns),Tl=n(M),Ul=U(M,"P",{"data-svelte-h":!0}),o(Ul)!=="svelte-17aodqd"&&(Ul.textContent=Cl),vl=n(M),m(el.$$.fragment,M),Ms=n(M),il=U(M,"P",{"data-svelte-h":!0}),o(il)!=="svelte-19luloo"&&(il.textContent=$l),Xl=n(M),m(al.$$.fragment,M),Yl=n(M),tl=U(M,"P",{"data-svelte-h":!0}),o(tl)!=="svelte-15is6l4"&&(tl.innerHTML=ea),El=n(M),nl=U(M,"P",{"data-svelte-h":!0}),o(nl)!=="svelte-a86jqs"&&(nl.textContent=ps),ml=n(M),m(Ql.$$.fragment,M),Fl=n(M),m(Ml.$$.fragment,M),zl=n(M),pl=U(M,"P",{"data-svelte-h":!0}),o(pl)!=="svelte-1gimviy"&&(pl.textContent=aa),Sl=n(M),m(Jl.$$.fragment,M),Hl=n(M),cl=U(M,"P",{"data-svelte-h":!0}),o(cl)!=="svelte-1t4dtyt"&&(cl.innerHTML=Js),jl=n(M),m(Nl.$$.fragment,M),Dl=n(M),yl=U(M,"P",{"data-svelte-h":!0}),o(yl)!=="svelte-115iam9"&&(yl.textContent=cs),wl=n(M),ol=U(M,"OL",{"data-svelte-h":!0}),o(ol)!=="svelte-1ezyy1"&&(ol.innerHTML=xl),ys=n(M),dl=U(M,"P",{"data-svelte-h":!0}),o(dl)!=="svelte-l6b7ka"&&(dl.textContent=fl),rs=n(M),m(ul.$$.fragment,M),bl=n(M),m(_l.$$.fragment,M),Ll=n(M),rl=U(M,"P",{"data-svelte-h":!0}),o(rl)!=="svelte-f03snx"&&(rl.textContent=Ts)},m(M,b){j(J,M,b),e(M,u,b),e(M,c,b),e(M,G,b),j(k,M,b),e(M,$,b),e(M,h,b),e(M,N,b),j(B,M,b),e(M,A,b),e(M,X,b),e(M,Q,b),j(R,M,b),e(M,f,b),e(M,V,b),e(M,v,b),j(Y,M,b),e(M,F,b),e(M,_,b),e(M,S,b),j(E,M,b),e(M,z,b),e(M,W,b),e(M,H,b),j(p,M,b),e(M,C,b),j(P,M,b),e(M,Wl,b),e(M,ll,b),e(M,Al,b),e(M,sl,b),e(M,Tl,b),e(M,Ul,b),e(M,vl,b),j(el,M,b),e(M,Ms,b),e(M,il,b),e(M,Xl,b),j(al,M,b),e(M,Yl,b),e(M,tl,b),e(M,El,b),e(M,nl,b),e(M,ml,b),j(Ql,M,b),e(M,Fl,b),j(Ml,M,b),e(M,zl,b),e(M,pl,b),e(M,Sl,b),j(Jl,M,b),e(M,Hl,b),e(M,cl,b),e(M,jl,b),j(Nl,M,b),e(M,Dl,b),e(M,yl,b),e(M,wl,b),e(M,ol,b),e(M,ys,b),e(M,dl,b),e(M,rs,b),j(ul,M,b),e(M,bl,b),j(_l,M,b),e(M,Ll,b),e(M,rl,b),hl=!0},i(M){hl||(y(J.$$.fragment,M),y(k.$$.fragment,M),y(B.$$.fragment,M),y(R.$$.fragment,M),y(Y.$$.fragment,M),y(E.$$.fragment,M),y(p.$$.fragment,M),y(P.$$.fragment,M),y(el.$$.fragment,M),y(al.$$.fragment,M),y(Ql.$$.fragment,M),y(Ml.$$.fragment,M),y(Jl.$$.fragment,M),y(Nl.$$.fragment,M),y(ul.$$.fragment,M),y(_l.$$.fragment,M),hl=!0)},o(M){r(J.$$.fragment,M),r(k.$$.fragment,M),r(B.$$.fragment,M),r(R.$$.fragment,M),r(Y.$$.fragment,M),r(E.$$.fragment,M),r(p.$$.fragment,M),r(P.$$.fragment,M),r(el.$$.fragment,M),r(al.$$.fragment,M),r(Ql.$$.fragment,M),r(Ml.$$.fragment,M),r(Jl.$$.fragment,M),r(Nl.$$.fragment,M),r(ul.$$.fragment,M),r(_l.$$.fragment,M),hl=!1},d(M){M&&(s(u),s(c),s(G),s($),s(h),s(N),s(A),s(X),s(Q),s(f),s(V),s(v),s(F),s(_),s(S),s(z),s(W),s(H),s(C),s(Wl),s(ll),s(Al),s(sl),s(Tl),s(Ul),s(vl),s(Ms),s(il),s(Xl),s(Yl),s(tl),s(El),s(nl),s(ml),s(Fl),s(zl),s(pl),s(Sl),s(Hl),s(cl),s(jl),s(Dl),s(yl),s(wl),s(ol),s(ys),s(dl),s(rs),s(bl),s(Ll),s(rl)),w(J,M),w(k,M),w(B,M),w(R,M),w(Y,M),w(E,M),w(p,M),w(P,M),w(el,M),w(al,M),w(Ql,M),w(Ml,M),w(Jl,M),w(Nl,M),w(ul,M),w(_l,M)}}}function QM(g){let J,u='🚨如果你在 TPU 上进行训练，则需要将上述所有代码移动到专门的训练函数中。有关 TPU 的详细信息，请回顾 <a href="/course/chapter3">第三章</a> 。';return{c(){J=T("p"),J.innerHTML=u},l(c){J=U(c,"P",{"data-svelte-h":!0}),o(J)!=="svelte-141qx8b"&&(J.innerHTML=u)},m(c,I){e(c,J,I)},p:ts,d(c){c&&s(J)}}}function NM(g){let J,u,c,I,G,k,$,h,Z,N,B,A,X="在本节中，我们将看看如何使用 Transformer 模型将长篇文档压缩为摘要，这项任务称为文本摘要。这是最具挑战性的自然语言处理（NLP）任务之一，因为它需要一系列能力，例如理解长篇文章并且生成能够捕捉文档中主要主题的连贯文本。但是，如果做得好，文本摘要是一种强大的工具，可以减轻各个领域的人详细阅读长文档的负担，从而加快业务流程。",x,Q,R,f,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> 。',q,v,Y,F,_,O="如果你试一试的话，就发现模型能够生成非常简洁的摘要，因为它们是从客户在产品评论中提供的标题中学到的。让我们首先为这项任务准备一个合适的双语语料库。",S,E,z,W,K='我们将使用 <a href="https://huggingface.co/datasets/amazon_reviews_multi" rel="nofollow">多语言亚马逊评论语料库</a> 创建我们的双语摘要器。该语料库由六种语言的亚马逊产品评论组成，通常用于多语言分类器的基准测试。然而，由于每条评论都附有一个简短的标题，我们可以使用标题作为我们模型学习的参考摘要！首先，让我们从 Hugging Face Hub 下载英语和西班牙语子集：',H,p,C,P,Wl,ll,sa='如你所见，在英语数据集的 <code>train</code> 部分有 200,000 条评论， <code>validation</code> 和 <code>test</code> 部分有 5,000 条评论。我们感兴趣的评论正文和标题保存在 <code>review_body</code> 和 <code>review_title</code> 列中。让我们通过创建一个简单的函数来从训练集中随机抽取一些样本，该函数使用我们在 <a href="/course/chapter5">第五章</a> 学到过：',Al,sl,ns,Tl,Ul,Cl,vl,el,Ms="这个示例显示了人们通常在网上评论的多样性，从积极的到消极的（以及介于两者之间的评论！）。尽管带有“meh”标题的示例的信息量不大，但其他标题看起来像是对评论本身的不错的总结。在单个 GPU 上训练所有 400,000 条评论的摘要模型将花费太长时间，因此我们将专注于为单个产品领域生成摘要。为了了解我们可以选择哪些领域，让我们将 <code>english_dataset</code> 转换为 <code>pandas.DataFrame</code> ，并计算每个产品类别的评论数量：",il,$l,Xl,al,Yl,tl,ea='在英语数据集中，最受欢迎的产品是家居用品、服装和无线电子产品。不过，为了带有亚马逊的特色，让我们专注于总结书籍的评论——毕竟，这是亚马逊这家公司成立的基础！我们可以看到两个符合要求的产品类别（ <code>book</code> 和 <code>digital_ebook_purchase</code> ），所以让我们用这两个产品类别过滤两种语言的数据集。正如我们在 <a href="/course/chapter5">第五章</a> 学到的， <code>Dataset.filter()</code> 函数可以让我们非常有效地对数据集进行切片，所以我们可以定义一个简单的函数来进行此操作：',El,nl,ps,ml,Ql="当我们使用这个函数对 <code>english_dataset</code> 和 <code>spanish_dataset</code> 过滤后，结果将只包含涉及书籍类别的那些行。在使用过滤器之前，让我们将 <code>english_dataset</code> 的格式从 <code>&quot;pandas&quot;</code> 切换回 <code>&quot;arrow&quot;</code> ：",Fl,Ml,zl,pl,aa="然后我们可以使用过滤器功能，作为一个基本的检查，让我们检查一些评论的样本，看看它们是否确实与书籍有关：",Sl,Jl,Hl,cl,Js,jl,Nl="好吧，我们可以看到评论并不是严格意义上的书籍，也可能是指日历和 OneNote 等电子应用程序等内容。尽管如此，该领域似乎也适合训练摘要模型。在我们查筛选适合此任务的各种模型之前，我们还有最后一点数据准备要做：将英文和西班牙文评论作为单个 <code>DatasetDict</code> 对象组合起来。🤗 Datasets 提供了一个方便的 <code>concatenate_datasets()</code> 函数，它（名如其实）将把两个 <code>Dataset</code> 对象堆叠在一起。因此，为了创建我们的双语数据集，我们将遍历数据集的每个部分，并打乱结果以确保我们的模型不会过度拟合单一语言：",Dl,yl,cs,wl,ol,xl,ys="这的确看起来像是混合了英语和西班牙语的评论！现在我们有了一个训练语料库，最后要检查的一件事是评论及其标题中单词的分布。这对于摘要任务尤其重要，其中数据中如果出现大量参考摘要过于简短会使模型偏向于生成的摘要中仅有一两个单词。下面的图中显示了单词分布，我们可以看到有些标题严重偏向于 1-2 个单词：",dl,fl,rs='<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."/>',ul,bl,_l="为了解决这个问题，我们将过滤掉标题非常短的示例，以便我们的模型可以生成更有效的摘要。由于我们正在处理英文和西班牙文文本，因此我们可以使用粗略的启发式方法在空白处拆分标题的单词，然后用我们强大的 <code>Dataset.filter()</code> 方法如下：",Ll,rl,Ts,hl,M="现在我们已经准备好了我们的语料库，让我们来看看一些可以对其进行微调的可选的 Transformer 模型！",b,Us,Ma,is,Kt='如果你仔细想想，文本摘要是一种类似于机器翻译的任务：我们有一个像评论这样的文本正文，我们希望将其“翻译”成一个较短的版本，同时捕捉到输入文本的主要特征。因此，大多数用于文本摘要的 Transformer 模型采用了我们在 <a href="/course/chapter1">第一章</a> 遇到的编码器-解码器架构。尽管有一些例外，例如 GPT 系列模型，它们在 few-shot（少量微调）之后也可以提取摘要。下表列出了一些可以进行摘要微调的流行预训练模型。',pa,ms,Pt='<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>',Ja,js,ln="从此表中可以看出，大多数用于摘要的 Transformer 模型（以及大多数 NLP 任务）都是单一语言的。如果你的任务所使用的语言是“有大量语料库”（如英语或德语）的语言，这很好。但对于世界各地正在使用的数千种其他语言，则不然。幸运的是，有一类多语言 Transformer 模型，如 mT5 和 mBART，可以解决问题。这些模型也是使用因果语言建模进行预训练的，但有一点不同：它们不是在一种语言的语料库上训练，而是同时在 50 多种语言的文本上进行联合训练！",ca,ws,sn="我们将使用 mT5，这是一种基于 T5 的有趣架构，在文本到文本任务中进行了预训练。在 T5 中，每个 NLP 任务都是以任务前缀（如 <code>summarize:</code> ）的形式定义的，模型根据不同的任务生成不同的文本。如下图所示，这让 T5 变得非常通用，因为你可以用一个模型解决很多任务！",ya,ql,en='<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."/>',ra,os,an="mT5 不使用前缀，但具有 T5 的大部分功能，并且具有多语言的优势。现在我们已经选择了一个模型，接下来让我们来看看如何准备我们的训练数据。",Ta,Ol,Ua,ds,ia,us,ma,bs,tn="我们接下来的任务是对我们的评论及其标题进行 tokenize 和 encode 。通常，我们需要首先加载与预训练模型 checkpoint 相关的 tokenizer，这次我们将使用较小的 <code>mt5-small</code> 作为我们的 checkpoint 这样我们就可以在合理的时间消耗内对模型进行微调：",ja,hs,wa,Kl,oa,Is,nn="让我们在一个小样本上测试 mT5  tokenizer",da,Cs,ua,fs,ba,ks,Mn='在这里我们可以看到熟悉的 <code>input_ids</code> 和 <code>attention_mask</code> ，我们在 <a href="https://chat.openai.com/course/chapter3" rel="nofollow">第3章</a> 的第一次微调实验中遇到过。让我们使用 tokenizer 的 <code>convert_ids_to_tokens()</code> 函数解码这些输入 ID，看看我们正在处理的是什么类型的 tokenizer：',ha,Zs,Ia,gs,Ca,Gs,pn='从特殊的 Unicode 字符 <code>▁</code> 和表示序列结束 <code>&lt;/s&gt;</code> token 可以看出来，我们正在使用基于 <a href="https://chat.openai.com/course/chapter6" rel="nofollow">第6章</a> 中讨论的 Unigram 子词分词算法的 SentencePiece tokenizer 。 Unigram 对于多语言语料库特别有用，因为它让 SentencePiece 不必受口音、标点符号以及很多语言（如日语）没有空白字符的影响，只专注于找出最优的分词方式。',fa,Bs,Jn="为了对我们的语料库 tokenize ，我们需要处理与摘要任务会遇到的一个细微问题：因为我们的输出目标也是文本，所以输入和输出加起来可能超过模型的最大上下文大小。这意味着我们需要对评论及其标题进行截断，以确保我们不会将过长的输入传递给我们的模型。🤗 Transformers 中的 tokenizer 提供了一个绝妙的 <code>text_target</code> 参数，允许你将目标文本与输入并行 tokenize。以下是如何为 mT5 处理输入和目标文本的示例：",ka,Vs,Za,Rs,cn="让我们逐步解析这段代码，理解发生了什么。我们首先定义了 <code>max_input_length</code> 和 <code>max_target_length</code> 的值，这些值设定了我们的评论和标题的最大长度。由于评论主体通常比标题大得多，我们相应地调整了这些值。",ga,$s,yn="通过 <code>preprocess_function()</code> 函数，我们可以使用我们在这门课程中广泛使用的方便的 <code>Dataset.map()</code> 函数，轻松地对整个语料库 tokenize 。",Ga,Qs,Ba,Ns,rn="既然语料库已经预处理完毕，我们来看看一些常用的摘要指标。正如我们在下面即将看到的，在衡量机器生成的文本的质量方面没有灵丹妙药。",Va,Pl,Ra,xs,$a,_s,Qa,Ws,Tn="与我们在本课程中涵盖的大多数其他任务相比，衡量文本生成任务（如摘要或翻译）的好坏并不那么简单。例如，对于“我喜欢阅读饥饿游戏”这样的评论，可能有多个有效摘要，例如“我喜欢饥饿游戏”或“饥饿游戏是一本好书”。显然，在生成的摘要和标签之间进行某种精确匹配并不是一个好的解决方案——即使是人类在这样的评估指标下也会表现不佳，因为每个人都有自己的写作风格。",Na,As,Un='总而言之，最常用的指标之一是<a href="https://en.wikipedia.org/wiki/ROUGE_(metric)" rel="nofollow">ROUGE 分数</a>（Recall-Oriented Understudy for Gisting Evaluation 的缩写）。该指标背后的基本思想是将生成的摘要与一组通常由人类创建的参考摘要进行比较。更具体地说，假设我们要比较以下两个摘要：',xa,vs,_a,Xs,mn="比较它们的一种方法是计算重叠单词的数量，在这个例子中为 6。然而，这种方法有些粗糙，因此 ROUGE 是基于计算计算重叠部分的 <code>精确度(Precision)</code> 和 <code>召回率(Recall)</code> 分数来计算的。",Wa,ls,Aa,Ys,zt,va,cM='<span class="katex-display"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><mtext>召回率</mtext><mo>=</mo><mfrac><mtext>重叠词的数量</mtext><mtext>参考摘要中的总词数</mtext></mfrac></mrow><annotation encoding="application/x-tex"> \\mathrm{召回率} = \\frac{\\mathrm{重叠词的数量}}{\\mathrm{参考摘要中的总词数}} </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 cjk_fallback">召回率</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.0463em;vertical-align:-0.686em;"></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.3603em;"><span style="top:-2.314em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord"><span class="mord mathrm cjk_fallback">参考摘要中的总词数</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 cjk_fallback">重叠词的数量</span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.686em;"><span></span></span></span></span></span><span class="mclose nulldelimiter"></span></span></span></span></span></span>',Xa,Es,St,Ya,yM='<span class="katex-display"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><mtext>精确度</mtext><mo>=</mo><mfrac><mtext>重叠词的数量</mtext><mtext>生成摘要中的总词数</mtext></mfrac></mrow><annotation encoding="application/x-tex"> \\mathrm{精确度} = \\frac{\\mathrm{重叠词的数量}}{\\mathrm{生成摘要中的总词数}} </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 cjk_fallback">精确度</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.0463em;vertical-align:-0.686em;"></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.3603em;"><span style="top:-2.314em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord"><span class="mord mathrm cjk_fallback">生成摘要中的总词数</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 cjk_fallback">重叠词的数量</span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.686em;"><span></span></span></span></span></span><span class="mclose nulldelimiter"></span></span></span></span></span></span>',Ea,Fs,jn="详细摘要使用这种计算方法会得到 6/10 = 0.6 的精确度，这比较短的摘要获得的 6/7 = 0.86 的精确度要差得多。在实践中，通常会先计算计算精度和召回率，然后得到 F1 分数（精确度和召回率的调和平均数）。我们可以很容易地在🤗 Datasets 中通过安装 <code>rouge_score</code> 包来实现这些计算：",Fa,zs,za,Ss,wn="然后按如下方式加载 ROUGE 指标：",Sa,Hs,Ha,Ds,on="接着我们可以使用 <code>rouge_score.compute()</code> 函数来一次性计算所有的指标：",Da,Ls,La,qs,qa,Os,dn=`哇，这个输出中包含了很多信息——它们都代表什么意思呢？首先，🤗 Datasets 计算了精度、召回率和 F1 分数的置信区间；也些就是你在这里看到的 <code>low</code> 、 <code>mid</code> 和 <code>high</code> 属性。此外，🤗 Datasets 还计算了基于在比较生成摘要和参考摘要时的采用不同文本粒度的各种 ROUGE 得分。 <code>rouge1</code> 测量的是生成摘要和参考摘要中单个单词的重叠程度。
为了验证这一点，让我们提取出我们得分的 <code>mid</code> 值：`,Oa,Ks,Ka,Ps,Pa,le,un="太好了，精确度和召回率的数字都对上了！那么其他的 ROUGE 得分表示什么含义呢？ <code>rouge2</code> 度量了二元词组（考虑单词对的重叠）之间的重叠，而 <code>rougeL</code> 和 <code>rougeLsum</code> 通过寻找生成的摘要和参考摘要中最长的公共子串来度量单词的最长匹配序列。 <code>rougeLsum</code> 中的“sum”指的是该指标是在整个摘要上计算的，而 <code>rougeL</code> 是指在各个句子上计算的平均值。",lt,ss,st,se,bn="我们将使用这些 ROUGE 分数来跟踪我们模型的性能，但在此之前，让我们做每个优秀的 NLP 从业者都应该做的事情：创建一个强大而简单的 baseline！",et,ee,at,ae,hn="对于文本摘要，一个常见的参考 baseline 是简单地取文章的前三句话作为摘要，通常称为 <code>lead-3</code> baseline。我们可以使用句号（英文使用．）来跟踪句子边界，但这在“U.S.” or “U.N.”之类的首字母缩略词上会计算错误。所以我们将使用 <code>nltk</code> 库，它包含一个更好的算法来处理这些情况。你可以使用以下方式安装该包：",tt,te,nt,ne,In="然后下载标点规则：",Mt,Me,pt,pe,Cn="接下来，我们从 <code>nltk</code> 导入句子的 tokenizer 并创建一个简单的函数用来提取评论中的前三个句子。文本摘要的默认情况下使用换行符分隔每个摘要，因此我们也按照这样的规则处理，并在训练集的示例上对其进行测试：",Jt,Je,ct,ce,yt,ye,fn="这似乎有效，接下来让我们现在实现一个函数，从数据集中提取这些“摘要”并计算 baseline 的 ROUGE 分数：",rt,re,Tt,Te,kn="然后我们可以使用这个函数来计算验证集上的 ROUGE 分数，并使用 Pandas 对输出的结果进行一些美化：",Ut,Ue,it,ie,mt,me,Zn="我们可以看到 <code>rouge2</code> 的分数明显低于其他的rouge；这可能反映了这样一个事实，即评论标题通常很简洁，因此 <code>lead-3</code> baseline 过于冗长导致得分不高。现在我们有了一个很好的参考基准，让我们将注意力转向微调 mT5！",jt,kl,Zl,He,es,wt,je,gn="我们需要做的下一件事是登录 Hugging Face Hub。如果你在 notebook 中运行此代码，则可以使用以下实用程序函数进行此操作：",ot,we,dt,oe,Gn="这将显示一个小工具，你可以在其中输入你的凭据。或者，你可以在你的终端运行这条命令来登陆：",ut,de,bt,De,ue,Bn='接下来，我们需要为我们的序列到序列任务定义一个数据整理器（data collator）。由于 mT5 是一个编码器-解码器的 Transformer 模型，因此在将数据整理成 batch 时有一点需要注意，那就是在解码期间，我们需要将标签向右移动一个单位。这是为了确保解码器只看到之前的参考序列，而不是当前要预测的 <code>token</code> 或之后的参考序列，这样模型就能避免容易记住标签。这类似与在 <a href="https://chat.openai.com/course/chapter7/6" rel="nofollow">因果语言模型</a> 这样的任务中使用掩码自注意力的机制类似。',ht,be,Vn="幸运的是，🤗 Transformers 提供了一个 <code>DataCollatorForSeq2Seq</code> 整理器，它会动态地填充我们的输入和标签。我们只需要提供 <code>tokenizer</code> 和 <code>model</code> 既可实例化这个整理器：",It,gl,Gl,Le,he,Rn="让我们看看当给这个整理器提供一个小批次的样本时，它的处理过程是怎么样的。首先，我们需要删除带有字符串的列，因为整理器不知道如何对这些元素进行填充（padding）：",Ct,Ie,ft,Ce,$n="由于 collator 需要一个 <code>dict</code> 的列表，其中每个 <code>dict</code> 代表数据集中的一个样本，所以我们也需要在将数据传给数据整理器之前，将数据整理成预期的格式：",kt,fe,Zt,ke,gt,Ze,Qn="首先要注意的是，第二个例子比第一个例子要长，所以第一个例子的 <code>input_ids</code> 和 <code>attention_mask</code> 在右边用 <code>[PAD]</code> token （ID 为 <code>0</code> ）进行了填充。同样，我们可以看到标签也使用 <code>-100</code> 进行了填充，以确保填充的 <code>tokens</code> 被损失函数忽略。最后，我们可以看到多了一个新的 <code>decoder_input_ids</code> 字段，它是通过在第一个条目中插入 <code>[PAD]</code> <code>tokens</code> 来将标签向右移动一个 token 形成的。",Gt,Bl,Vl,qe,Oe,ge,Bt,Ge,Nn="将模型推送到 Hub 后，你可以通过推理小部件或 <code>pipeline</code> 对象来使用它，如下所示：",Vt,Be,Rt,Ve,xn="我们可以将测试集（模型还没有见过的一些数据）中取一些样本提供给我们的管道，来感受一下生成的摘要的质量。首先让我们实现一个简单的函数，同时显示评论、标题和生成的摘要：",$t,Re,Qt,$e,_n="让我们看一下其中一个英文摘要的例子：",Nt,Qe,xt,Ne,_t,xe,Wn="这还不错！我们可以看到，我们的模型实际上已经能够通过增加部分新词来生成总结的摘要了。我们模型最酷的方面是它是双语的，所以我们还可以生成西班牙语评论的摘要：",Wt,_e,At,We,vt,Ae,An="在这个例子中生成的摘要翻译成中文的意思是“非常容易阅读”，我们可以看到它是直接从评论中提取的。同时，这个例子还展现了mT5 模型的多种功能特性，并支持处理多语言的语料库！",Xt,ve,vn="接下来，我们将尝试一个稍微复杂一点的任务：从头开始训练一个语言模型。",Yt,Xe,Et,ta,Ft;G=new wM({props:{fw:g[0]}}),$=new Il({props:{title:"提取文本摘要",local:"提取文本摘要",headingTag:"h1"}});const Xn=[uM,dM],Ye=[];function Yn(l,a){return l[0]==="pt"?0:1}Z=Yn(g),N=Ye[Z]=Xn[Z](g),Q=new Ot({props:{id:"yHnr5Dk2zCI"}}),E=new Il({props:{title:"准备多语言语料库",local:"准备多语言语料库",headingTag:"h2"}}),p=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:"RGF0YXNldERpY3QoJTdCJTBBJTIwJTIwJTIwJTIwdHJhaW4lM0ElMjBEYXRhc2V0KCU3QiUwQSUyMCUyMCU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lMjAlMjBudW1fcm93cyUzQSUyMDUwMDAlMEElMjAlMjAlMjAlMjAlN0QpJTBBJTdEKQ==",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}}),sl=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}}),Tl=new d({props:{code:"JyUzRSUzRSUyMFRpdGxlJTNBJTIwV29ya2VkJTIwaW4lMjBmcm9udCUyMHBvc2l0aW9uJTJDJTIwbm90JTIwcmVhciclMEEnJTNFJTNFJTIwUmV2aWV3JTNBJTIwMyUyMHN0YXJzJTIwYmVjYXVzZSU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wb3ZlciUyMGZvcnR5JTIweWVhcnMuJw==",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}}),Cl=new as({props:{$$slots:{default:[bM]},$$scope:{ctx:g}}}),$l=new d({props:{code:"ZW5nbGlzaF9kYXRhc2V0LnNldF9mb3JtYXQoJTIycGFuZGFzJTIyKSUwQWVuZ2xpc2hfZGYlMjAlM0QlMjBlbmdsaXNoX2RhdGFzZXQlNUIlMjJ0cmFpbiUyMiU1RCU1QiUzQSU1RCUwQSUyMyUyMCVFNiU5OCVCRSVFNyVBNCVCQSVFNSU4OSU4RCUyMDIwJTIwJUU0JUI4JUFBJUU0JUJBJUE3JUU1JTkzJTgxJUU3JTlBJTg0JUU2JTk1JUIwJUU5JTg3JThGJTBBZW5nbGlzaF9kZiU1QiUyMnByb2R1Y3RfY2F0ZWdvcnklMjIlNUQudmFsdWVfY291bnRzKCklNUIlM0EyMCU1RA==",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"># 显示前 20 个产品的数量</span>
english_df[<span class="hljs-string">&quot;product_category&quot;</span>].value_counts()[:<span class="hljs-number">20</span>]`,wrap:!1}}),al=new d({props:{code:"aG9tZSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMDE3Njc5JTBBYXBwYXJlbCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMDE1OTUxJTBBd2lyZWxlc3MlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAxNTcxNyUwQW90aGVyJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwMTM0MTglMEFiZWF1dHklMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAxMjA5MSUwQWRydWdzdG9yZSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMDExNzMwJTBBa2l0Y2hlbiUyMCUyMCUyMCUyMCUyMCUyMCUyMCUy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yb2NlcnklMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjA0NzMwJTBBYm9vayUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMDM3NTYlMEFOYW1lJTNBJTIwcHJvZHVjdF9jYXRlZ29yeSUyQyUyMGR0eXBlJTNBJTIwaW50NjQ=",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}}),nl=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}}),Ml=new d({props:{code:"ZW5nbGlzaF9kYXRhc2V0LnJlc2V0X2Zvcm1hdCgp",highlighted:"english_dataset.reset_format()",wrap:!1}}),Jl=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}}),cl=new d({props:{code:"JyUzRSUzRSUyMFRpdGxlJTNBJTIwSSU1QydtJTIwZGlzc2Fwb2ludGVkLiclMEEnJTNFJTNFJTIwUmV2aWV3JTNBJTIwSSUyMGd1ZXNzJTIwSSUyMGhhZCUyMGhpZ2hlciUyMGV4cGVjdGF0aW9ucyUyMGZvciUyMHRoaXMlMjBib29rJTIwZnJvbSUyMHRoZSUyMHJldmlld3MuJTIwSSUyMHJlYWxseSUyMHRob3VnaHQlMjBJJTVDJ2QlMjBhdCUyMGxlYXN0JTIwbGlrZSUyMGl0LiUyMFRoZSUyMHBsb3QlMjBpZGVhJTIwd2FzJTIwZ3JlYXQuJTIwSSUyMGxvdmVk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biUyMGhhcyUyMHRoZSUyMGZvbGQlMjBnb2luZyUyMHRocm91Z2glMjB0aGUlMjBwaWN0dXJlJTJDJTIwc28lMjBpdCU1QydzJTIwbGVzcyUyMGFlc3RoZXRpY2FsbHklMjBwbGVhc2luZyUyQyUyMGVzcGVjaWFsbHklMjBpZiUyMHlvdSUyMHdhbnQlMjB0byUyMGtlZXAlMjBhJTIwcGljdHVyZSUyMHRvJTIwaGFuZy4lMjBGb3IlMjB0aGUlMjBwcmljZSUyQyUyMGElMjBnb29kJTIwY2FsZW5kYXInJTBBJTBBJyUzRSUzRSUyMFRpdGxlJTNBJTIwSGVscGZ1bCclMEEnJTNFJTNFJTIwUmV2aWV3JTNBJTIwTmVhcmx5JTIwYWxsJTIwdGhlJTIwdGlwcyUyMHVzZWZ1bCUyMGFuZC4lMjBJJTIwY29uc2lkZXIlMjBteXNlbGYlMjBhbiUyMGludGVybWVkaWF0ZSUyMHRvJTIwYWR2YW5jZWQlMjB1c2VyJTIwb2YlMjBPbmVOb3RlLiUyMEklMjB3b3VsZCUyMGhpZ2hseSUyMHJlY29tbWVuZC4n",highlighted:`<span class="hljs-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}}),yl=new d({props:{code:"ZnJvbSUyMGRhdGFzZXRzJTIwaW1wb3J0JTIwY29uY2F0ZW5hdGVfZGF0YXNldHMlMkMlMjBEYXRhc2V0RGljdCUwQSUwQWJvb2tzX2RhdGFzZXQlMjAlM0QlMjBEYXRhc2V0RGljdCgpJTBBJTBBZm9yJTIwc3BsaXQlMjBpbiUyMGVuZ2xpc2hfYm9va3Mua2V5cygpJTNBJTBBJTIwJTIwJTIwJTIwYm9va3NfZGF0YXNldCU1QnNwbGl0JTVEJTIwJTNEJTIwY29uY2F0ZW5hdGVfZGF0YXNldHMoJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTVCZW5nbGlzaF9ib29rcyU1QnNwbGl0JTVEJTJDJTIwc3BhbmlzaF9ib29rcyU1QnNwbGl0JTVEJTVEJTBBJTIwJTIwJTIwJTIwKSUwQSUyMCUyMCUyMCUyMGJvb2tzX2RhdGFzZXQlNUJzcGxpdCU1RCUyMCUzRCUyMGJvb2tzX2RhdGFzZXQlNUJzcGxpdCU1RC5zaHVmZmxlKHNlZWQlM0Q0MiklMEElMEElMjMlMjAlRTYlOEMlOTElRTklODAlODklRTQlQjglODAlRTQlQkElOUIlRTYlQTAlQjclRTQlQkUlOEIlMEFzaG93X3NhbXBsZXMoYm9va3NfZGF0YXNldCk=",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"># 挑选一些样例</span>
show_samples(books_dataset)`,wrap:!1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ted:`<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}}),rl=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}}),Us=new Il({props:{title:"文本摘要模型",local:"文本摘要模型",headingTag:"h2"}}),Ol=new as({props:{$$slots:{default:[hM]},$$scope:{ctx:g}}}),ds=new Il({props:{title:"预处理数据",local:"预处理数据",headingTag:"h2"}}),us=new Ot({props:{id:"1m7BerpSq8A"}}),hs=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}}),Kl=new as({props:{$$slots:{default:[IM]},$$scope:{ctx:g}}}),Cs=new d({props:{code:"aW5wdXRzJTIwJTNEJTIwdG9rZW5pemVyKCUyMkklMjBsb3ZlZCUyMHJlYWRpbmclMjB0aGUlMjBIdW5nZXIlMjBHYW1lcyElMjIpJTBBaW5wdXRz",highlighted:`inputs = tokenizer(<span class="hljs-string">&quot;I loved reading the Hunger Games!&quot;</span>)
inputs`,wrap:!1}}),fs=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}}),Zs=new d({props:{code:"dG9rZW5pemVyLmNvbnZlcnRfaWRzX3RvX3Rva2VucyhpbnB1dHMuaW5wdXRfaWRzKQ==",highlighted:"tokenizer.convert_ids_to_tokens(inputs.input_ids)",wrap:!1}}),gs=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}}),Vs=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}}),Qs=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}}),Pl=new as({props:{$$slots:{default:[CM]},$$scope:{ctx:g}}}),xs=new Il({props:{title:"文本摘要的评估指标",local:"文本摘要的评估指标",headingTag:"h2"}}),_s=new Ot({props:{id:"TMshhnrEXlg"}}),vs=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}}),ls=new as({props:{$$slots:{default:[fM]},$$scope:{ctx:g}}}),zs=new d({props:{code:"IXBpcCUyMGluc3RhbGwlMjByb3VnZV9zY29yZQ==",highlighted:"!pip install rouge_score",wrap:!1}}),Hs=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}}),Ls=new d({props:{code:"c2NvcmVzJTIwJTNEJTIwcm91Z2Vfc2NvcmUuY29tcHV0ZSglMEElMjAlMjAlMjAlMjBwcmVkaWN0aW9ucyUzRCU1QmdlbmVyYXRlZF9zdW1tYXJ5JTVEJTJDJTIwcmVmZXJlbmNlcyUzRCU1QnJlZmVyZW5jZV9zdW1tYXJ5JTVEJTBBKSUwQXNjb3Jlcw==",highlighted:`scores = rouge_score.compute(
    predictions=[generated_summary], references=[reference_summary]
)
scores`,wrap:!1}}),qs=new d({props:{code:"JTdCJ3JvdWdlMSclM0ElMjBBZ2dyZWdhdGVTY29yZShsb3clM0RTY29yZShwcmVjaXNpb24lM0QwLjg2JTJDJTIwcm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QwLjkyKSUyQyUyMG1pZCUzRFNjb3JlKHByZWNpc2lvbiUzRDAuODYlMkMlMjByZWNhbGwlM0QxLjAlMkMlMjBmbWVhc3VyZSUzRDAuOTIpJTJDJTIwaGlnaCUzRFNjb3JlKHByZWNpc2lvbiUzRDAuODYlMkMlMjByZWNhbGwlM0QxLjAlMkMlMjBmbWVhc3VyZSUzRDAuOTIpKSU3RA==",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}}),Ks=new d({props:{code:"c2NvcmVzJTVCJTIycm91Z2UxJTIyJTVELm1pZA==",highlighted:'scores[<span class="hljs-string">&quot;rouge1&quot;</span>].mid',wrap:!1}}),Ps=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}}),ss=new as({props:{$$slots:{default:[kM]},$$scope:{ctx:g}}}),ee=new Il({props:{title:"创建强大的 baseline",local:"创建强大的 baseline",headingTag:"h3"}}),te=new d({props:{code:"IXBpcCUyMGluc3RhbGwlMjBubHRr",highlighted:"!pip install nltk",wrap:!1}}),Me=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}}),Je=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}}),ce=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}}),re=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}}),Ue=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}}),ie=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 En=[gM,ZM],Ee=[];function Fn(l,a){return l[0]==="pt"?0:1}kl=Fn(g),Zl=Ee[kl]=En[kl](g),es=new as({props:{$$slots:{default:[GM]},$$scope:{ctx:g}}}),we=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}}),de=new d({props:{code:"aHVnZ2luZ2ZhY2UtY2xpJTIwbG9naW4=",highlighted:'huggingface-<span class="hljs-keyword">cli</span> login',wrap:!1}});let D=g[0]==="pt"&&MM();const zn=[VM,BM],Fe=[];function Sn(l,a){return l[0]==="pt"?0:1}gl=Sn(g),Gl=Fe[gl]=zn[gl](g),Ie=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}}),fe=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}}),ke=new d({props:{code:"JTdCJ2F0dGVudGlvbl9tYXNrJyUzQSUyMHRlbnNvciglNUIlNUIxJTJDJTIwMSUyQyUyMDElMkMlMjAxJTJDJTIwMSUyQyUyMDElMkMlMjAxJTJDJTIwMSUyQyUyMDElMkMlMjAxJTJDJTIwMSUyQyUyMDElMkMlMjAxJTJDJTIwMSUyQyUyMDElMkMlMjAxJTJDJTIwMSUyQyUyMDElMkMlMjAxJTJDJTIwMSUyQyUyMDElMkMlMjAxJTJDJTIwMSUyQyUyMDElMkMlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAxJTJDJTIwMSUyQyUyMDElMkMlMjAxJTJDJTIwMSUyQyUyMDAlMkMlMjAwJTJDJTIwMCUyQyUyMDAlMkMlMjAwJTJDJTIwMCU1RCUyQyUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCU1QjElMkMlMjAxJTJDJTIwMSUyQyUy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UyMCUyMCUyMCUyMDEwMzclMkMlMjAlMjAlMjAzOTMxJTJDJTIwJTIwJTIwJTIwMjYwJTJDJTIwJTIwJTIwNzA4MyUyQyUyMDEwMTQ3NiUyQyUyMCUyMCUyMDExNDMlMkMlMjAlMjAlMjAlMjAyNjAlMkMlMjAlMjAlMjAlMjAlMjAlMjAxJTVEJTVEKSUyQyUyMCdsYWJlbHMnJTNBJTIwdGVuc29yKCU1QiU1QiUyMDc0ODMlMkMlMjAlMjAlMjAyNTklMkMlMjAlMjAyMzY0JTJDJTIwMTU2OTUlMkMlMjAlMjAlMjAlMjAlMjAxJTJDJTIwJTIwLTEwMCU1RCUyQyUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCU1QiUyMCUyMDI1OSUyQyUyMDI3NTMxJTJDJTIwMTM0ODMlMkMlMjAlMjAlMjAyNTklMkMlMjAlMjA3NTA1JTJDJTIwJTIwJTIwJTIwJTIwMSU1RCU1RCklMkMlMjAnZGVjb2Rlcl9pbnB1dF9pZHMnJTNBJTIwdGVuc29yKCU1QiU1QiUyMCUyMCUyMCUyMDAlMkMlMjAlMjA3NDgzJTJDJTIwJTIwJTIwMjU5JTJDJTIwJTIwMjM2NCUyQyUyMDE1Njk1JTJDJTIwJTIwJTIwJTIwJTIwMSU1RCUyQyUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCU1QiUyMCUyMCUyMCUyMDAlMkMlMjAlMjAlMjAyNTklMkMlMjAyNzUzMSUyQyUyMDEzNDgzJTJDJTIwJTIwJTIwMjU5JTJDJTIwJTIwNzUwNSU1RCU1RCklN0Q=",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,RM],ze=[];function Dn(l,a){return l[0]==="pt"?0:1}Bl=Dn(g),Vl=ze[Bl]=Hn[Bl](g);let L=g[0]==="pt"&&pM(g);return ge=new Il({props:{title:"使用你微调的模型",local:"使用你微调的模型",headingTag:"h2"}}),Be=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}}),Re=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}}),Qe=new d({props:{code:"cHJpbnRfc3VtbWFyeSgxMDAp",highlighted:'print_summary(<span class="hljs-number">100</span>)',wrap:!1}}),Ne=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}}),_e=new d({props:{code:"cHJpbnRfc3VtbWFyeSgwKQ==",highlighted:'print_summary(<span class="hljs-number">0</span>)',wrap:!1}}),We=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}}),Xe=new oM({props:{source:"https://github.com/huggingface/course/blob/main/chapters/zh-CN/chapter7/5.mdx"}}),{c(){J=T("meta"),u=t(),c=T("p"),I=t(),i(G.$$.fragment),k=t(),i($.$$.fragment),h=t(),N.c(),B=t(),A=T("p"),A.textContent=X,x=t(),i(Q.$$.fragment),R=t(),f=T("p"),f.innerHTML=V,q=t(),v=T("iframe"),F=t(),_=T("p"),_.textContent=O,S=t(),i(E.$$.fragment),z=t(),W=T("p"),W.innerHTML=K,H=t(),i(p.$$.fragment),C=t(),i(P.$$.fragment),Wl=t(),ll=T("p"),ll.innerHTML=sa,Al=t(),i(sl.$$.fragment),ns=t(),i(Tl.$$.fragment),Ul=t(),i(Cl.$$.fragment),vl=t(),el=T("p"),el.innerHTML=Ms,il=t(),i($l.$$.fragment),Xl=t(),i(al.$$.fragment),Yl=t(),tl=T("p"),tl.innerHTML=ea,El=t(),i(nl.$$.fragment),ps=t(),ml=T("p"),ml.innerHTML=Ql,Fl=t(),i(Ml.$$.fragment),zl=t(),pl=T("p"),pl.textContent=aa,Sl=t(),i(Jl.$$.fragment),Hl=t(),i(cl.$$.fragment),Js=t(),jl=T("p"),jl.innerHTML=Nl,Dl=t(),i(yl.$$.fragment),cs=t(),i(wl.$$.fragment),ol=t(),xl=T("p"),xl.textContent=ys,dl=t(),fl=T("div"),fl.innerHTML=rs,ul=t(),bl=T("p"),bl.innerHTML=_l,Ll=t(),i(rl.$$.fragment),Ts=t(),hl=T("p"),hl.textContent=M,b=t(),i(Us.$$.fragment),Ma=t(),is=T("p"),is.innerHTML=Kt,pa=t(),ms=T("table"),ms.innerHTML=Pt,Ja=t(),js=T("p"),js.textContent=ln,ca=t(),ws=T("p"),ws.innerHTML=sn,ya=t(),ql=T("div"),ql.innerHTML=en,ra=t(),os=T("p"),os.textContent=an,Ta=t(),i(Ol.$$.fragment),Ua=t(),i(ds.$$.fragment),ia=t(),i(us.$$.fragment),ma=t(),bs=T("p"),bs.innerHTML=tn,ja=t(),i(hs.$$.fragment),wa=t(),i(Kl.$$.fragment),oa=t(),Is=T("p"),Is.textContent=nn,da=t(),i(Cs.$$.fragment),ua=t(),i(fs.$$.fragment),ba=t(),ks=T("p"),ks.innerHTML=Mn,ha=t(),i(Zs.$$.fragment),Ia=t(),i(gs.$$.fragment),Ca=t(),Gs=T("p"),Gs.innerHTML=pn,fa=t(),Bs=T("p"),Bs.innerHTML=Jn,ka=t(),i(Vs.$$.fragment),Za=t(),Rs=T("p"),Rs.innerHTML=cn,ga=t(),$s=T("p"),$s.innerHTML=yn,Ga=t(),i(Qs.$$.fragment),Ba=t(),Ns=T("p"),Ns.textContent=rn,Va=t(),i(Pl.$$.fragment),Ra=t(),i(xs.$$.fragment),$a=t(),i(_s.$$.fragment),Qa=t(),Ws=T("p"),Ws.textContent=Tn,Na=t(),As=T("p"),As.innerHTML=Un,xa=t(),i(vs.$$.fragment),_a=t(),Xs=T("p"),Xs.innerHTML=mn,Wa=t(),i(ls.$$.fragment),Aa=t(),Ys=T("p"),zt=eM(`对于 ROUGE，召回率衡量的是参考摘要中被生成摘要捕获的内容量。如果我们只是比较单词，召回率可以按照以下公式计算：
`),va=new aM(!1),Xa=t(),Es=T("p"),St=eM(`对于上面的那个例子，这个公式给出了 6/6 = 1 的完美召回率；即，参考摘要中的所有单词模型都生成出来了。这听起来可能很棒，但想象一下，如果我们生成的摘要是“我真的很喜欢整晚阅读饥饿游戏”。这也会有完美的 recall，但可以说这是一个更糟糕的总结，因为它很冗长。为了适应于这些场景，我们还计算了精确度，它在 ROUGE 上下文中衡量了生成的摘要中有多少是相关的：
`),Ya=new aM(!1),Ea=t(),Fs=T("p"),Fs.innerHTML=jn,Fa=t(),i(zs.$$.fragment),za=t(),Ss=T("p"),Ss.textContent=wn,Sa=t(),i(Hs.$$.fragment),Ha=t(),Ds=T("p"),Ds.innerHTML=on,Da=t(),i(Ls.$$.fragment),La=t(),i(qs.$$.fragment),qa=t(),Os=T("p"),Os.innerHTML=dn,Oa=t(),i(Ks.$$.fragment),Ka=t(),i(Ps.$$.fragment),Pa=t(),le=T("p"),le.innerHTML=un,lt=t(),i(ss.$$.fragment),st=t(),se=T("p"),se.textContent=bn,et=t(),i(ee.$$.fragment),at=t(),ae=T("p"),ae.innerHTML=hn,tt=t(),i(te.$$.fragment),nt=t(),ne=T("p"),ne.textContent=In,Mt=t(),i(Me.$$.fragment),pt=t(),pe=T("p"),pe.innerHTML=Cn,Jt=t(),i(Je.$$.fragment),ct=t(),i(ce.$$.fragment),yt=t(),ye=T("p"),ye.textContent=fn,rt=t(),i(re.$$.fragment),Tt=t(),Te=T("p"),Te.textContent=kn,Ut=t(),i(Ue.$$.fragment),it=t(),i(ie.$$.fragment),mt=t(),me=T("p"),me.innerHTML=Zn,jt=t(),Zl.c(),He=t(),i(es.$$.fragment),wt=t(),je=T("p"),je.textContent=gn,ot=t(),i(we.$$.fragment),dt=t(),oe=T("p"),oe.textContent=Gn,ut=t(),i(de.$$.fragment),bt=t(),D&&D.c(),De=t(),ue=T("p"),ue.innerHTML=Bn,ht=t(),be=T("p"),be.innerHTML=Vn,It=t(),Gl.c(),Le=t(),he=T("p"),he.textContent=Rn,Ct=t(),i(Ie.$$.fragment),ft=t(),Ce=T("p"),Ce.innerHTML=$n,kt=t(),i(fe.$$.fragment),Zt=t(),i(ke.$$.fragment),gt=t(),Ze=T("p"),Ze.innerHTML=Qn,Gt=t(),Vl.c(),qe=t(),L&&L.c(),Oe=t(),i(ge.$$.fragment),Bt=t(),Ge=T("p"),Ge.innerHTML=Nn,Vt=t(),i(Be.$$.fragment),Rt=t(),Ve=T("p"),Ve.textContent=xn,$t=t(),i(Re.$$.fragment),Qt=t(),$e=T("p"),$e.textContent=_n,Nt=t(),i(Qe.$$.fragment),xt=t(),i(Ne.$$.fragment),_t=t(),xe=T("p"),xe.textContent=Wn,Wt=t(),i(_e.$$.fragment),At=t(),i(We.$$.fragment),vt=t(),Ae=T("p"),Ae.textContent=An,Xt=t(),ve=T("p"),ve.textContent=vn,Yt=t(),i(Xe.$$.fragment),Et=t(),ta=T("p"),this.h()},l(l){const a=jM("svelte-u9bgzb",document.head);J=U(a,"META",{name:!0,content:!0}),a.forEach(s),u=n(l),c=U(l,"P",{}),na(c).forEach(s),I=n(l),m(G.$$.fragment,l),k=n(l),m($.$$.fragment,l),h=n(l),N.l(l),B=n(l),A=U(l,"P",{"data-svelte-h":!0}),o(A)!=="svelte-t8t9xu"&&(A.textContent=X),x=n(l),m(Q.$$.fragment,l),R=n(l),f=U(l,"P",{"data-svelte-h":!0}),o(f)!=="svelte-omsdwm"&&(f.innerHTML=V),q=n(l),v=U(l,"IFRAME",{src:!0,frameborder:!0,height:!0,title:!0,class:!0,allow:!0,sandbox:!0}),na(v).forEach(s),F=n(l),_=U(l,"P",{"data-svelte-h":!0}),o(_)!=="svelte-1an75tu"&&(_.textContent=O),S=n(l),m(E.$$.fragment,l),z=n(l),W=U(l,"P",{"data-svelte-h":!0}),o(W)!=="svelte-v42lau"&&(W.innerHTML=K),H=n(l),m(p.$$.fragment,l),C=n(l),m(P.$$.fragment,l),Wl=n(l),ll=U(l,"P",{"data-svelte-h":!0}),o(ll)!=="svelte-18haute"&&(ll.innerHTML=sa),Al=n(l),m(sl.$$.fragment,l),ns=n(l),m(Tl.$$.fragment,l),Ul=n(l),m(Cl.$$.fragment,l),vl=n(l),el=U(l,"P",{"data-svelte-h":!0}),o(el)!=="svelte-1dybb2d"&&(el.innerHTML=Ms),il=n(l),m($l.$$.fragment,l),Xl=n(l),m(al.$$.fragment,l),Yl=n(l),tl=U(l,"P",{"data-svelte-h":!0}),o(tl)!=="svelte-rukx46"&&(tl.innerHTML=ea),El=n(l),m(nl.$$.fragment,l),ps=n(l),ml=U(l,"P",{"data-svelte-h":!0}),o(ml)!=="svelte-15x20dg"&&(ml.innerHTML=Ql),Fl=n(l),m(Ml.$$.fragment,l),zl=n(l),pl=U(l,"P",{"data-svelte-h":!0}),o(pl)!=="svelte-4j5rw6"&&(pl.textContent=aa),Sl=n(l),m(Jl.$$.fragment,l),Hl=n(l),m(cl.$$.fragment,l),Js=n(l),jl=U(l,"P",{"data-svelte-h":!0}),o(jl)!=="svelte-13d4564"&&(jl.innerHTML=Nl),Dl=n(l),m(yl.$$.fragment,l),cs=n(l),m(wl.$$.fragment,l),ol=n(l),xl=U(l,"P",{"data-svelte-h":!0}),o(xl)!=="svelte-13x36yp"&&(xl.textContent=ys),dl=n(l),fl=U(l,"DIV",{class:!0,"data-svelte-h":!0}),o(fl)!=="svelte-1pwnbfd"&&(fl.innerHTML=rs),ul=n(l),bl=U(l,"P",{"data-svelte-h":!0}),o(bl)!=="svelte-88flin"&&(bl.innerHTML=_l),Ll=n(l),m(rl.$$.fragment,l),Ts=n(l),hl=U(l,"P",{"data-svelte-h":!0}),o(hl)!=="svelte-10rsjo5"&&(hl.textContent=M),b=n(l),m(Us.$$.fragment,l),Ma=n(l),is=U(l,"P",{"data-svelte-h":!0}),o(is)!=="svelte-1pb3wvf"&&(is.innerHTML=Kt),pa=n(l),ms=U(l,"TABLE",{"data-svelte-h":!0}),o(ms)!=="svelte-zf82i5"&&(ms.innerHTML=Pt),Ja=n(l),js=U(l,"P",{"data-svelte-h":!0}),o(js)!=="svelte-rjq7dx"&&(js.textContent=ln),ca=n(l),ws=U(l,"P",{"data-svelte-h":!0}),o(ws)!=="svelte-1j5tvah"&&(ws.innerHTML=sn),ya=n(l),ql=U(l,"DIV",{class:!0,"data-svelte-h":!0}),o(ql)!=="svelte-k7lnur"&&(ql.innerHTML=en),ra=n(l),os=U(l,"P",{"data-svelte-h":!0}),o(os)!=="svelte-1ha2w"&&(os.textContent=an),Ta=n(l),m(Ol.$$.fragment,l),Ua=n(l),m(ds.$$.fragment,l),ia=n(l),m(us.$$.fragment,l),ma=n(l),bs=U(l,"P",{"data-svelte-h":!0}),o(bs)!=="svelte-19rjunc"&&(bs.innerHTML=tn),ja=n(l),m(hs.$$.fragment,l),wa=n(l),m(Kl.$$.fragment,l),oa=n(l),Is=U(l,"P",{"data-svelte-h":!0}),o(Is)!=="svelte-11y0b4p"&&(Is.textContent=nn),da=n(l),m(Cs.$$.fragment,l),ua=n(l),m(fs.$$.fragment,l),ba=n(l),ks=U(l,"P",{"data-svelte-h":!0}),o(ks)!=="svelte-9fcusl"&&(ks.innerHTML=Mn),ha=n(l),m(Zs.$$.fragment,l),Ia=n(l),m(gs.$$.fragment,l),Ca=n(l),Gs=U(l,"P",{"data-svelte-h":!0}),o(Gs)!=="svelte-j6j15c"&&(Gs.innerHTML=pn),fa=n(l),Bs=U(l,"P",{"data-svelte-h":!0}),o(Bs)!=="svelte-19zfc4v"&&(Bs.innerHTML=Jn),ka=n(l),m(Vs.$$.fragment,l),Za=n(l),Rs=U(l,"P",{"data-svelte-h":!0}),o(Rs)!=="svelte-1qticg4"&&(Rs.innerHTML=cn),ga=n(l),$s=U(l,"P",{"data-svelte-h":!0}),o($s)!=="svelte-zh5yvz"&&($s.innerHTML=yn),Ga=n(l),m(Qs.$$.fragment,l),Ba=n(l),Ns=U(l,"P",{"data-svelte-h":!0}),o(Ns)!=="svelte-1og3mrq"&&(Ns.textContent=rn),Va=n(l),m(Pl.$$.fragment,l),Ra=n(l),m(xs.$$.fragment,l),$a=n(l),m(_s.$$.fragment,l),Qa=n(l),Ws=U(l,"P",{"data-svelte-h":!0}),o(Ws)!=="svelte-x5422x"&&(Ws.textContent=Tn),Na=n(l),As=U(l,"P",{"data-svelte-h":!0}),o(As)!=="svelte-w2nm9w"&&(As.innerHTML=Un),xa=n(l),m(vs.$$.fragment,l),_a=n(l),Xs=U(l,"P",{"data-svelte-h":!0}),o(Xs)!=="svelte-1g09k10"&&(Xs.innerHTML=mn),Wa=n(l),m(ls.$$.fragment,l),Aa=n(l),Ys=U(l,"P",{});var Ke=na(Ys);zt=tM(Ke,`对于 ROUGE，召回率衡量的是参考摘要中被生成摘要捕获的内容量。如果我们只是比较单词，召回率可以按照以下公式计算：
`),va=nM(Ke,!1),Ke.forEach(s),Xa=n(l),Es=U(l,"P",{});var Se=na(Es);St=tM(Se,`对于上面的那个例子，这个公式给出了 6/6 = 1 的完美召回率；即，参考摘要中的所有单词模型都生成出来了。这听起来可能很棒，但想象一下，如果我们生成的摘要是“我真的很喜欢整晚阅读饥饿游戏”。这也会有完美的 recall，但可以说这是一个更糟糕的总结，因为它很冗长。为了适应于这些场景，我们还计算了精确度，它在 ROUGE 上下文中衡量了生成的摘要中有多少是相关的：
`),Ya=nM(Se,!1),Se.forEach(s),Ea=n(l),Fs=U(l,"P",{"data-svelte-h":!0}),o(Fs)!=="svelte-1rop0lg"&&(Fs.innerHTML=jn),Fa=n(l),m(zs.$$.fragment,l),za=n(l),Ss=U(l,"P",{"data-svelte-h":!0}),o(Ss)!=="svelte-qano4p"&&(Ss.textContent=wn),Sa=n(l),m(Hs.$$.fragment,l),Ha=n(l),Ds=U(l,"P",{"data-svelte-h":!0}),o(Ds)!=="svelte-vsb7v2"&&(Ds.innerHTML=on),Da=n(l),m(Ls.$$.fragment,l),La=n(l),m(qs.$$.fragment,l),qa=n(l),Os=U(l,"P",{"data-svelte-h":!0}),o(Os)!=="svelte-1flc8yx"&&(Os.innerHTML=dn),Oa=n(l),m(Ks.$$.fragment,l),Ka=n(l),m(Ps.$$.fragment,l),Pa=n(l),le=U(l,"P",{"data-svelte-h":!0}),o(le)!=="svelte-ah5tgr"&&(le.innerHTML=un),lt=n(l),m(ss.$$.fragment,l),st=n(l),se=U(l,"P",{"data-svelte-h":!0}),o(se)!=="svelte-rrs400"&&(se.textContent=bn),et=n(l),m(ee.$$.fragment,l),at=n(l),ae=U(l,"P",{"data-svelte-h":!0}),o(ae)!=="svelte-1kxgkww"&&(ae.innerHTML=hn),tt=n(l),m(te.$$.fragment,l),nt=n(l),ne=U(l,"P",{"data-svelte-h":!0}),o(ne)!=="svelte-lvcdc3"&&(ne.textContent=In),Mt=n(l),m(Me.$$.fragment,l),pt=n(l),pe=U(l,"P",{"data-svelte-h":!0}),o(pe)!=="svelte-14ylm0j"&&(pe.innerHTML=Cn),Jt=n(l),m(Je.$$.fragment,l),ct=n(l),m(ce.$$.fragment,l),yt=n(l),ye=U(l,"P",{"data-svelte-h":!0}),o(ye)!=="svelte-15ftpf8"&&(ye.textContent=fn),rt=n(l),m(re.$$.fragment,l),Tt=n(l),Te=U(l,"P",{"data-svelte-h":!0}),o(Te)!=="svelte-1j0zzcr"&&(Te.textContent=kn),Ut=n(l),m(Ue.$$.fragment,l),it=n(l),m(ie.$$.fragment,l),mt=n(l),me=U(l,"P",{"data-svelte-h":!0}),o(me)!=="svelte-rvqebq"&&(me.innerHTML=Zn),jt=n(l),Zl.l(l),He=n(l),m(es.$$.fragment,l),wt=n(l),je=U(l,"P",{"data-svelte-h":!0}),o(je)!=="svelte-1tyhl6x"&&(je.textContent=gn),ot=n(l),m(we.$$.fragment,l),dt=n(l),oe=U(l,"P",{"data-svelte-h":!0}),o(oe)!=="svelte-1e16czp"&&(oe.textContent=Gn),ut=n(l),m(de.$$.fragment,l),bt=n(l),D&&D.l(l),De=n(l),ue=U(l,"P",{"data-svelte-h":!0}),o(ue)!=="svelte-1712trz"&&(ue.innerHTML=Bn),ht=n(l),be=U(l,"P",{"data-svelte-h":!0}),o(be)!=="svelte-xjlg53"&&(be.innerHTML=Vn),It=n(l),Gl.l(l),Le=n(l),he=U(l,"P",{"data-svelte-h":!0}),o(he)!=="svelte-1timsrr"&&(he.textContent=Rn),Ct=n(l),m(Ie.$$.fragment,l),ft=n(l),Ce=U(l,"P",{"data-svelte-h":!0}),o(Ce)!=="svelte-11nqg2f"&&(Ce.innerHTML=$n),kt=n(l),m(fe.$$.fragment,l),Zt=n(l),m(ke.$$.fragment,l),gt=n(l),Ze=U(l,"P",{"data-svelte-h":!0}),o(Ze)!=="svelte-v37mlp"&&(Ze.innerHTML=Qn),Gt=n(l),Vl.l(l),qe=n(l),L&&L.l(l),Oe=n(l),m(ge.$$.fragment,l),Bt=n(l),Ge=U(l,"P",{"data-svelte-h":!0}),o(Ge)!=="svelte-kn30l3"&&(Ge.innerHTML=Nn),Vt=n(l),m(Be.$$.fragment,l),Rt=n(l),Ve=U(l,"P",{"data-svelte-h":!0}),o(Ve)!=="svelte-bxc39y"&&(Ve.textContent=xn),$t=n(l),m(Re.$$.fragment,l),Qt=n(l),$e=U(l,"P",{"data-svelte-h":!0}),o($e)!=="svelte-led41n"&&($e.textContent=_n),Nt=n(l),m(Qe.$$.fragment,l),xt=n(l),m(Ne.$$.fragment,l),_t=n(l),xe=U(l,"P",{"data-svelte-h":!0}),o(xe)!=="svelte-jnazqv"&&(xe.textContent=Wn),Wt=n(l),m(_e.$$.fragment,l),At=n(l),m(We.$$.fragment,l),vt=n(l),Ae=U(l,"P",{"data-svelte-h":!0}),o(Ae)!=="svelte-17mx8ys"&&(Ae.textContent=An),Xt=n(l),ve=U(l,"P",{"data-svelte-h":!0}),o(ve)!=="svelte-14hkeg5"&&(ve.textContent=vn),Yt=n(l),m(Xe.$$.fragment,l),Et=n(l),ta=U(l,"P",{}),na(ta).forEach(s),this.h()},h(){Rl(J,"name","hf:doc:metadata"),Rl(J,"content",xM),TM(v.src,Y="https://course-demos-mt5-small-finetuned-amazon-en-es.hf.space")||Rl(v,"src",Y),Rl(v,"frameborder","0"),Rl(v,"height","400"),Rl(v,"title","Gradio app"),Rl(v,"class","block dark:hidden container p-0 flex-grow space-iframe"),Rl(v,"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"),Rl(v,"sandbox","allow-forms allow-modals allow-popups allow-popups-to-escape-sandbox allow-same-origin allow-scripts allow-downloads"),Rl(fl,"class","flex justify-center"),Rl(ql,"class","flex justify-center"),va.a=null,Ya.a=null},m(l,a){qt(document.head,J),e(l,u,a),e(l,c,a),e(l,I,a),j(G,l,a),e(l,k,a),j($,l,a),e(l,h,a),Ye[Z].m(l,a),e(l,B,a),e(l,A,a),e(l,x,a),j(Q,l,a),e(l,R,a),e(l,f,a),e(l,q,a),e(l,v,a),e(l,F,a),e(l,_,a),e(l,S,a),j(E,l,a),e(l,z,a),e(l,W,a),e(l,H,a),j(p,l,a),e(l,C,a),j(P,l,a),e(l,Wl,a),e(l,ll,a),e(l,Al,a),j(sl,l,a),e(l,ns,a),j(Tl,l,a),e(l,Ul,a),j(Cl,l,a),e(l,vl,a),e(l,el,a),e(l,il,a),j($l,l,a),e(l,Xl,a),j(al,l,a),e(l,Yl,a),e(l,tl,a),e(l,El,a),j(nl,l,a),e(l,ps,a),e(l,ml,a),e(l,Fl,a),j(Ml,l,a),e(l,zl,a),e(l,pl,a),e(l,Sl,a),j(Jl,l,a),e(l,Hl,a),j(cl,l,a),e(l,Js,a),e(l,jl,a),e(l,Dl,a),j(yl,l,a),e(l,cs,a),j(wl,l,a),e(l,ol,a),e(l,xl,a),e(l,dl,a),e(l,fl,a),e(l,ul,a),e(l,bl,a),e(l,Ll,a),j(rl,l,a),e(l,Ts,a),e(l,hl,a),e(l,b,a),j(Us,l,a),e(l,Ma,a),e(l,is,a),e(l,pa,a),e(l,ms,a),e(l,Ja,a),e(l,js,a),e(l,ca,a),e(l,ws,a),e(l,ya,a),e(l,ql,a),e(l,ra,a),e(l,os,a),e(l,Ta,a),j(Ol,l,a),e(l,Ua,a),j(ds,l,a),e(l,ia,a),j(us,l,a),e(l,ma,a),e(l,bs,a),e(l,ja,a),j(hs,l,a),e(l,wa,a),j(Kl,l,a),e(l,oa,a),e(l,Is,a),e(l,da,a),j(Cs,l,a),e(l,ua,a),j(fs,l,a),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,bt,a),D&&D.m(l,a),e(l,De,a),e(l,ue,a),e(l,ht,a),e(l,be,a),e(l,It,a),Fe[gl].m(l,a),e(l,Le,a),e(l,he,a),e(l,Ct,a),j(Ie,l,a),e(l,ft,a),e(l,Ce,a),e(l,kt,a),j(fe,l,a),e(l,Zt,a),j(ke,l,a),e(l,gt,a),e(l,Ze,a),e(l,Gt,a),ze[Bl].m(l,a),e(l,qe,a),L&&L.m(l,a),e(l,Oe,a),j(ge,l,a),e(l,Bt,a),e(l,Ge,a),e(l,Vt,a),j(Be,l,a),e(l,Rt,a),e(l,Ve,a),e(l,$t,a),j(Re,l,a),e(l,Qt,a),e(l,$e,a),e(l,Nt,a),j(Qe,l,a),e(l,xt,a),j(Ne,l,a),e(l,_t,a),e(l,xe,a),e(l,Wt,a),j(_e,l,a),e(l,At,a),j(We,l,a),e(l,vt,a),e(l,Ae,a),e(l,Xt,a),e(l,ve,a),e(l,Yt,a),j(Xe,l,a),e(l,Et,a),e(l,ta,a),Ft=!0},p(l,[a]){const Ke={};a&1&&(Ke.fw=l[0]),G.$set(Ke);let Se=Z;Z=Yn(l),Z!==Se&&(la(),r(Ye[Se],1,1,()=>{Ye[Se]=null}),Pe(),N=Ye[Z],N||(N=Ye[Z]=Xn[Z](l),N.c()),y(N,1),N.m(B.parentNode,B));const Ln={};a&2&&(Ln.$$scope={dirty:a,ctx:l}),Cl.$set(Ln);const qn={};a&2&&(qn.$$scope={dirty:a,ctx:l}),Ol.$set(qn);const On={};a&2&&(On.$$scope={dirty:a,ctx:l}),Kl.$set(On);const Kn={};a&2&&(Kn.$$scope={dirty:a,ctx:l}),Pl.$set(Kn);const Pn={};a&2&&(Pn.$$scope={dirty:a,ctx:l}),ls.$set(Pn);const lM={};a&2&&(lM.$$scope={dirty:a,ctx:l}),ss.$set(lM);let Ht=kl;kl=Fn(l),kl!==Ht&&(la(),r(Ee[Ht],1,1,()=>{Ee[Ht]=null}),Pe(),Zl=Ee[kl],Zl||(Zl=Ee[kl]=En[kl](l),Zl.c()),y(Zl,1),Zl.m(He.parentNode,He));const sM={};a&2&&(sM.$$scope={dirty:a,ctx:l}),es.$set(sM),l[0]==="pt"?D?a&1&&y(D,1):(D=MM(),D.c(),y(D,1),D.m(De.parentNode,De)):D&&(la(),r(D,1,1,()=>{D=null}),Pe());let Dt=gl;gl=Sn(l),gl!==Dt&&(la(),r(Fe[Dt],1,1,()=>{Fe[Dt]=null}),Pe(),Gl=Fe[gl],Gl||(Gl=Fe[gl]=zn[gl](l),Gl.c()),y(Gl,1),Gl.m(Le.parentNode,Le));let Lt=Bl;Bl=Dn(l),Bl!==Lt&&(la(),r(ze[Lt],1,1,()=>{ze[Lt]=null}),Pe(),Vl=ze[Bl],Vl||(Vl=ze[Bl]=Hn[Bl](l),Vl.c()),y(Vl,1),Vl.m(qe.parentNode,qe)),l[0]==="pt"?L?a&1&&y(L,1):(L=pM(l),L.c(),y(L,1),L.m(Oe.parentNode,Oe)):L&&(la(),r(L,1,1,()=>{L=null}),Pe())},i(l){Ft||(y(G.$$.fragment,l),y($.$$.fragment,l),y(N),y(Q.$$.fragment,l),y(E.$$.fragment,l),y(p.$$.fragment,l),y(P.$$.fragment,l),y(sl.$$.fragment,l),y(Tl.$$.fragment,l),y(Cl.$$.fragment,l),y($l.$$.fragment,l),y(al.$$.fragment,l),y(nl.$$.fragment,l),y(Ml.$$.fragment,l),y(Jl.$$.fragment,l),y(cl.$$.fragment,l),y(yl.$$.fragment,l),y(wl.$$.fragment,l),y(rl.$$.fragment,l),y(Us.$$.fragment,l),y(Ol.$$.fragment,l),y(ds.$$.fragment,l),y(us.$$.fragment,l),y(hs.$$.fragment,l),y(Kl.$$.fragment,l),y(Cs.$$.fragment,l),y(fs.$$.fragment,l),y(Zs.$$.fragment,l),y(gs.$$.fragment,l),y(Vs.$$.fragment,l),y(Qs.$$.fragment,l),y(Pl.$$.fragment,l),y(xs.$$.fragment,l),y(_s.$$.fragment,l),y(vs.$$.fragment,l),y(ls.$$.fragment,l),y(zs.$$.fragment,l),y(Hs.$$.fragment,l),y(Ls.$$.fragment,l),y(qs.$$.fragment,l),y(Ks.$$.fragment,l),y(Ps.$$.fragment,l),y(ss.$$.fragment,l),y(ee.$$.fragment,l),y(te.$$.fragment,l),y(Me.$$.fragment,l),y(Je.$$.fragment,l),y(ce.$$.fragment,l),y(re.$$.fragment,l),y(Ue.$$.fragment,l),y(ie.$$.fragment,l),y(Zl),y(es.$$.fragment,l),y(we.$$.fragment,l),y(de.$$.fragment,l),y(D),y(Gl),y(Ie.$$.fragment,l),y(fe.$$.fragment,l),y(ke.$$.fragment,l),y(Vl),y(L),y(ge.$$.fragment,l),y(Be.$$.fragment,l),y(Re.$$.fragment,l),y(Qe.$$.fragment,l),y(Ne.$$.fragment,l),y(_e.$$.fragment,l),y(We.$$.fragment,l),y(Xe.$$.fragment,l),Ft=!0)},o(l){r(G.$$.fragment,l),r($.$$.fragment,l),r(N),r(Q.$$.fragment,l),r(E.$$.fragment,l),r(p.$$.fragment,l),r(P.$$.fragment,l),r(sl.$$.fragment,l),r(Tl.$$.fragment,l),r(Cl.$$.fragment,l),r($l.$$.fragment,l),r(al.$$.fragment,l),r(nl.$$.fragment,l),r(Ml.$$.fragment,l),r(Jl.$$.fragment,l),r(cl.$$.fragment,l),r(yl.$$.fragment,l),r(wl.$$.fragment,l),r(rl.$$.fragment,l),r(Us.$$.fragment,l),r(Ol.$$.fragment,l),r(ds.$$.fragment,l),r(us.$$.fragment,l),r(hs.$$.fragment,l),r(Kl.$$.fragment,l),r(Cs.$$.fragment,l),r(fs.$$.fragment,l),r(Zs.$$.fragment,l),r(gs.$$.fragment,l),r(Vs.$$.fragment,l),r(Qs.$$.fragment,l),r(Pl.$$.fragment,l),r(xs.$$.fragment,l),r(_s.$$.fragment,l),r(vs.$$.fragment,l),r(ls.$$.fragment,l),r(zs.$$.fragment,l),r(Hs.$$.fragment,l),r(Ls.$$.fragment,l),r(qs.$$.fragment,l),r(Ks.$$.fragment,l),r(Ps.$$.fragment,l),r(ss.$$.fragment,l),r(ee.$$.fragment,l),r(te.$$.fragment,l),r(Me.$$.fragment,l),r(Je.$$.fragment,l),r(ce.$$.fragment,l),r(re.$$.fragment,l),r(Ue.$$.fragment,l),r(ie.$$.fragment,l),r(Zl),r(es.$$.fragment,l),r(we.$$.fragment,l),r(de.$$.fragment,l),r(D),r(Gl),r(Ie.$$.fragment,l),r(fe.$$.fragment,l),r(ke.$$.fragment,l),r(Vl),r(L),r(ge.$$.fragment,l),r(Be.$$.fragment,l),r(Re.$$.fragment,l),r(Qe.$$.fragment,l),r(Ne.$$.fragment,l),r(_e.$$.fragment,l),r(We.$$.fragment,l),r(Xe.$$.fragment,l),Ft=!1},d(l){l&&(s(u),s(c),s(I),s(k),s(h),s(B),s(A),s(x),s(R),s(f),s(q),s(v),s(F),s(_),s(S),s(z),s(W),s(H),s(C),s(Wl),s(ll),s(Al),s(ns),s(Ul),s(vl),s(el),s(il),s(Xl),s(Yl),s(tl),s(El),s(ps),s(ml),s(Fl),s(zl),s(pl),s(Sl),s(Hl),s(Js),s(jl),s(Dl),s(cs),s(ol),s(xl),s(dl),s(fl),s(ul),s(bl),s(Ll),s(Ts),s(hl),s(b),s(Ma),s(is),s(pa),s(ms),s(Ja),s(js),s(ca),s(ws),s(ya),s(ql),s(ra),s(os),s(Ta),s(Ua),s(ia),s(ma),s(bs),s(ja),s(wa),s(oa),s(Is),s(da),s(ua),s(ba),s(ks),s(ha),s(Ia),s(Ca),s(Gs),s(fa),s(Bs),s(ka),s(Za),s(Rs),s(ga),s($s),s(Ga),s(Ba),s(Ns),s(Va),s(Ra),s($a),s(Qa),s(Ws),s(Na),s(As),s(xa),s(_a),s(Xs),s(Wa),s(Aa),s(Ys),s(Xa),s(Es),s(Ea),s(Fs),s(Fa),s(za),s(Ss),s(Sa),s(Ha),s(Ds),s(Da),s(La),s(qa),s(Os),s(Oa),s(Ka),s(Pa),s(le),s(lt),s(st),s(se),s(et),s(at),s(ae),s(tt),s(nt),s(ne),s(Mt),s(pt),s(pe),s(Jt),s(ct),s(yt),s(ye),s(rt),s(Tt),s(Te),s(Ut),s(it),s(mt),s(me),s(jt),s(He),s(wt),s(je),s(ot),s(dt),s(oe),s(ut),s(bt),s(De),s(ue),s(ht),s(be),s(It),s(Le),s(he),s(Ct),s(ft),s(Ce),s(kt),s(Zt),s(gt),s(Ze),s(Gt),s(qe),s(Oe),s(Bt),s(Ge),s(Vt),s(Rt),s(Ve),s($t),s(Qt),s($e),s(Nt),s(xt),s(_t),s(xe),s(Wt),s(At),s(vt),s(Ae),s(Xt),s(ve),s(Yt),s(Et),s(ta)),s(J),w(G,l),w($,l),Ye[Z].d(l),w(Q,l),w(E,l),w(p,l),w(P,l),w(sl,l),w(Tl,l),w(Cl,l),w($l,l),w(al,l),w(nl,l),w(Ml,l),w(Jl,l),w(cl,l),w(yl,l),w(wl,l),w(rl,l),w(Us,l),w(Ol,l),w(ds,l),w(us,l),w(hs,l),w(Kl,l),w(Cs,l),w(fs,l),w(Zs,l),w(gs,l),w(Vs,l),w(Qs,l),w(Pl,l),w(xs,l),w(_s,l),w(vs,l),w(ls,l),w(zs,l),w(Hs,l),w(Ls,l),w(qs,l),w(Ks,l),w(Ps,l),w(ss,l),w(ee,l),w(te,l),w(Me,l),w(Je,l),w(ce,l),w(re,l),w(Ue,l),w(ie,l),Ee[kl].d(l),w(es,l),w(we,l),w(de,l),D&&D.d(l),Fe[gl].d(l),w(Ie,l),w(fe,l),w(ke,l),ze[Bl].d(l),L&&L.d(l),w(ge,l),w(Be,l),w(Re,l),w(Qe,l),w(Ne,l),w(_e,l),w(We,l),w(Xe,l)}}}const xM='{"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 _M(g,J,u){let c="pt";return UM(()=>{const I=new URLSearchParams(window.location.search);u(0,c=I.get("fw")||"pt")}),[c]}class SM extends iM{constructor(J){super(),mM(this,J,_M,NM,rM,{})}}export{SM as component};
