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

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

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

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

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


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

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

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

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

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

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

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

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

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

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

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


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


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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            decoded_preds, decoded_labels = postprocess_text(
                decoded_preds, decoded_labels
            )

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

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

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

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


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

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

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

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

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

books_dataset = DatasetDict()

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

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

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

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

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


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

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

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


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


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

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

notebook_login()`,wrap:!1}}),ha=new d({props:{code:"aHVnZ2luZ2ZhY2UtY2xpJTIwbG9naW4=",highlighted:'huggingface-<span class="hljs-keyword">cli</span> login',wrap:!1}});let H=G[0]==="pt"&&tM();const Yn=[GM,ZM],Ya=[];function En(s,e){return s[0]==="pt"?0:1}Gs=En(G),ks=Ya[Gs]=Yn[Gs](G),Ia=new d({props:{code:"dG9rZW5pemVkX2RhdGFzZXRzJTIwJTNEJTIwdG9rZW5pemVkX2RhdGFzZXRzLnJlbW92ZV9jb2x1bW5zKCUwQSUyMCUyMCUyMCUyMGJvb2tzX2RhdGFzZXQlNUIlMjJ0cmFpbiUyMiU1RC5jb2x1bW5fbmFtZXMlMEEp",highlighted:`tokenized_datasets = tokenized_datasets.remove_columns(
    books_dataset[<span class="hljs-string">&quot;train&quot;</span>].column_names
)`,wrap:!1}}),Ca=new d({props:{code:"ZmVhdHVyZXMlMjAlM0QlMjAlNUJ0b2tlbml6ZWRfZGF0YXNldHMlNUIlMjJ0cmFpbiUyMiU1RCU1QmklNUQlMjBmb3IlMjBpJTIwaW4lMjByYW5nZSgyKSU1RCUwQWRhdGFfY29sbGF0b3IoZmVhdHVyZXMp",highlighted:`features = [tokenized_datasets[<span class="hljs-string">&quot;train&quot;</span>][i] <span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> <span class="hljs-built_in">range</span>(<span class="hljs-number">2</span>)]
data_collator(features)`,wrap:!1}}),ga=new d({props:{code:"JTdCJ2F0dGVudGlvbl9tYXNrJyUzQSUyMHRlbnNvciglNUIlNUIxJTJDJTIwMSUyQyUyMDElMk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yMDE1Njk1JTJDJTIwJTIwJTIwJTIwJTIwMSU1RCUyQyUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCU1QiUyMCUyMCUyMCUyMDAlMkMlMjAlMjAlMjAyNTklMkMlMjAyNzUzMSUyQyUyMDEzNDgzJTJDJTIwJTIwJTIwMjU5JTJDJTIwJTIwNzUwNSU1RCU1RCklN0Q=",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 Sn=[BM,kM],Ea=[];function Fn(s,e){return s[0]==="pt"?0:1}Bs=Fn(G),vs=Ea[Bs]=Sn[Bs](G);let D=G[0]==="pt"&&nM(G);return Ga=new Is({props:{title:"使用您微调的模型",local:"使用您微调的模型",headingTag:"h2"}}),Ba=new d({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMHBpcGVsaW5lJTBBJTBBaHViX21vZGVsX2lkJTIwJTNEJTIwJTIyaHVnZ2luZ2ZhY2UtY291cnNlJTJGbXQ1LXNtYWxsLWZpbmV0dW5lZC1hbWF6b24tZW4tZXMlMjIlMEFzdW1tYXJpemVyJTIwJTNEJTIwcGlwZWxpbmUoJTIyc3VtbWFyaXphdGlvbiUyMiUyQyUyMG1vZGVsJTNEaHViX21vZGVsX2lkKQ==",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> pipeline

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

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

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

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

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