import{s as oM,f as nM,o as UM,n as nl}from"../chunks/scheduler.37c15a92.js";import{S as wM,i as jM,g as y,s as n,r as c,m as MM,H as pM,A as hM,h as J,f as l,c as M,j as Oa,u as T,x as w,n as rM,E as mM,k as q,y as Pt,a,v as o,t as i,b as se,d as m,w as U,p as le}from"../chunks/index.2bf4358c.js";import{T as tl}from"../chunks/Tip.363c041f.js";import{Y as Ot}from"../chunks/Youtube.1e50a667.js";import{C as d}from"../chunks/CodeBlock.4e987730.js";import{D as JM}from"../chunks/DocNotebookDropdown.efc1fb7c.js";import{F as dM}from"../chunks/FrameworkSwitchCourse.8d4d4ab6.js";import{H as gs,E as uM}from"../chunks/getInferenceSnippets.8b9eb92a.js";function bM(k){let p,u;return p=new JM({props:{classNames:"absolute z-10 right-0 top-0",options:[{label:"Google Colab",value:"https://colab.research.google.com/github/huggingface/notebooks/blob/master/course/chapter7/section5_tf.ipynb"},{label:"Aws Studio",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/master/course/chapter7/section5_tf.ipynb"}]}}),{c(){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){U(p,r)}}}function IM(k){let p,u;return p=new JM({props:{classNames:"absolute z-10 right-0 top-0",options:[{label:"Google Colab",value:"https://colab.research.google.com/github/huggingface/notebooks/blob/master/course/chapter7/section5_pt.ipynb"},{label:"Aws Studio",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/master/course/chapter7/section5_pt.ipynb"}]}}),{c(){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){U(p,r)}}}function fM(k){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}),w(p)!=="svelte-dnykow"&&(p.innerHTML=u)},m(r,f){a(r,p,f)},p:nl,d(r){r&&l(p)}}}function CM(k){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}),w(p)!=="svelte-a0f3vx"&&(p.innerHTML=u)},m(r,f){a(r,p,f)},p:nl,d(r){r&&l(p)}}}function gM(k){let p,u="💡在 NLP 項目的早期階段，一個好的做法是在小樣本數據上訓練一類“小”模型。這使您可以更快地調試和迭代端到端工作流。一旦您對結果充滿信心，您始終可以通過簡單地更改模型檢查點來在大規模數據上訓練模型！";return{c(){p=y("p"),p.textContent=u},l(r){p=J(r,"P",{"data-svelte-h":!0}),w(p)!=="svelte-pcld25"&&(p.textContent=u)},m(r,f){a(r,p,f)},p:nl,d(r){r&&l(p)}}}function ZM(k){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}),w(p)!=="svelte-r2ca50"&&(p.innerHTML=u)},m(r,f){a(r,p,f)},p:nl,d(r){r&&l(p)}}}function kM(k){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}),w(p)!=="svelte-ia9gv8"&&(p.innerHTML=u)},m(r,f){a(r,p,f)},p:nl,d(r){r&&l(p)}}}function GM(k){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}),w(p)!=="svelte-1czorp1"&&(p.innerHTML=u)},m(r,f){a(r,p,f)},p:nl,d(r){r&&l(p)}}}function vM(k){let p,u,r,f="微調模型以進行提取摘要與我們在本章中介紹的其他任務非常相似。 我們需要做的第一件事是從<code>mt5-small</code>檢查點加載預訓練模型。 由於摘要提取是一個序列到序列的任務，我們可以使用 AutoModelForSeq2SeqLM 類加載模型，該類會自動下載並緩存權重：",G,g,_;return p=new gs({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=n(),r=y("p"),r.innerHTML=f,G=n(),c(g.$$.fragment)},l(I){T(p.$$.fragment,I),u=M(I),r=J(I,"P",{"data-svelte-h":!0}),w(r)!=="svelte-1vu03ta"&&(r.innerHTML=f),G=M(I),T(g.$$.fragment,I)},m(I,Z){o(p,I,Z),a(I,u,Z),a(I,r,Z),a(I,G,Z),o(g,I,Z),_=!0},i(I){_||(m(p.$$.fragment,I),m(g.$$.fragment,I),_=!0)},o(I){i(p.$$.fragment,I),i(g.$$.fragment,I),_=!1},d(I){I&&(l(u),l(r),l(G)),U(p,I),U(g,I)}}}function BM(k){let p,u,r,f="微調模型以進行提取摘要與我們在本章中介紹的其他任務非常相似。 我們需要做的第一件事是從<code>mt5-small</code>檢查點加載預訓練模型。 由於摘要提取是一個序列到序列的任務，我們可以使用 AutoModelForSeq2SeqLM 類加載模型，該類會自動下載並緩存權重：",G,g,_;return p=new gs({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=n(),r=y("p"),r.innerHTML=f,G=n(),c(g.$$.fragment)},l(I){T(p.$$.fragment,I),u=M(I),r=J(I,"P",{"data-svelte-h":!0}),w(r)!=="svelte-1vu03ta"&&(r.innerHTML=f),G=M(I),T(g.$$.fragment,I)},m(I,Z){o(p,I,Z),a(I,u,Z),a(I,r,Z),a(I,G,Z),o(g,I,Z),_=!0},i(I){_||(m(p.$$.fragment,I),m(g.$$.fragment,I),_=!0)},o(I){i(p.$$.fragment,I),i(g.$$.fragment,I),_=!1},d(I){I&&(l(u),l(r),l(G)),U(p,I),U(g,I)}}}function xM(k){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}),w(p)!=="svelte-gwvjmk"&&(p.innerHTML=u)},m(r,f){a(r,p,f)},p:nl,d(r){r&&l(p)}}}function iM(k){let p,u="我們需要生成摘要以便在訓練期間計算 ROUGE 分數。幸運的是，🤗 Transformers 提供了專用的 <code>Seq2SeqTrainingArguments</code> 和 <code>Seq2SeqTrainer</code> 類，可以自動為我們完成這項工作！ 為了瞭解它是如何工作的，讓我們首先為我們的實驗定義超參數和其他參數：",r,f,G,g,_='在這裡， <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,N='<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>。',v,z,S="我們需要做的下一件事是為訓練器提供一個“compute_metrics()”函數，以便我們可以在訓練期間評估我們的模型。 總結起來，這比簡單地在模型的預測上調用 <code>rouge_score.compute()</code> 更復雜一些，因為我們需要在計算 ROUGE 分數之前將輸出和標籤解碼為文本。 下面的函數正是這樣做的，並且還利用 <code>nltk</code> 中的 <code>sent_tokenize()</code> 函數來用換行符分隔摘要語句：",X,R,W;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,
    push_to_hub=<span class="hljs-literal">True</span>,
)`,wrap:!1}}),R=new d({props:{code:"aW1wb3J0JTIwbnVtcHklMjBhcyUyMG5wJTBBJTBBJTBBZGVmJTIwY29tcHV0ZV9tZXRyaWNzKGV2YWxfcHJlZCklM0ElMEElMjAlMjAlMjAlMjBwcmVkaWN0aW9ucyUyQyUyMGxhYmVscyUyMCUzRCUyMGV2YWxfcHJlZCUwQSUyMCUyMCUyMCUyMCUyMyUyMERlY29kZSUyMGdlbmVyYXRlZCUyMHN1bW1hcmllcyUyMGludG8lMjB0ZXh0JTBBJTIwJTIwJTIwJTIwZGVjb2RlZF9wcmVkcyUyMCUzRCUyMHRva2VuaXplci5iYXRjaF9kZWNvZGUocHJlZGljdGlvbnMlMkMlMjBza2lwX3NwZWNpYWxfdG9rZW5zJTNEVHJ1ZSklMEElMjAlMjAlMjAlMjAlMjMlMjBSZXBsYWNlJTIwLTEwMCUyMGluJTIwdGhlJTIwbGFiZWxzJTIwYXMlMjB3ZSUyMGNhbid0JTIwZGVjb2RlJTIwdGhlbSUwQSUyMCUyMCUyMCUyMGxhYmVscyUyMCUzRCUyMG5wLndoZXJlKGxhYmVscyUyMCElM0QlMjAtMTAwJTJDJTIwbGFiZWxzJTJDJTIwdG9rZW5pemVyLnBhZF90b2tlbl9pZCklMEElMjAlMjAlMjAlMjAlMjMlMjBEZWNvZGUlMjByZWZlcmVuY2UlMjBzdW1tYXJpZXMlMjBpbnRvJTIwdGV4dCUwQSUyMCUyMCUyMCUyMGRlY29kZWRfbGFiZWxzJTIwJTNEJTIwdG9rZW5pemVyLmJhdGNoX2RlY29kZShsYWJlbHMlMkMlMjBza2lwX3NwZWNpYWxfdG9rZW5zJTNEVHJ1ZSklMEElMjAlMjAlMjAlMjAlMjMlMjBST1VHRSUyMGV4cGVjdHMlMjBhJTIwbmV3bGluZSUyMGFmdGVyJTIwZWFjaCUyMHNlbnRlbmNlJTBBJTIwJTIwJTIwJTIwZGVjb2RlZF9wcmVkcyUyMCUzRCUyMCU1QiUyMiU1Q24lMjIuam9pbihzZW50X3Rva2VuaXplKHByZWQuc3RyaXAoKSkpJTIwZm9yJTIwcHJlZCUyMGluJTIwZGVjb2RlZF9wcmVkcyU1RCUwQSUyMCUyMCUyMCUyMGRlY29kZWRfbGFiZWxzJTIwJTNEJTIwJTVCJTIyJTVDbiUyMi5qb2luKHNlbnRfdG9rZW5pemUobGFiZWwuc3RyaXAoKSkpJTIwZm9yJTIwbGFiZWwlMjBpbiUyMGRlY29kZWRfbGFiZWxzJTVEJTBBJTIwJTIwJTIwJTIwJTIzJTIwQ29tcHV0ZSUyMFJPVUdFJTIwc2NvcmVzJTBBJTIwJTIwJTIwJTIwcmVzdWx0JTIwJTNEJTIwcm91Z2Vfc2NvcmUuY29tcHV0ZSglMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBwcmVkaWN0aW9ucyUzRGRlY29kZWRfcHJlZHMlMkMlMjByZWZlcmVuY2VzJTNEZGVjb2RlZF9sYWJlbHMlMkMlMjB1c2Vfc3RlbW1lciUzRFRydWUlMEElMjAlMjAlMjAlMjApJTBBJTIwJTIwJTIwJTIwJTIzJTIwRXh0cmFjdCUyMHRoZSUyMG1lZGlhbiUyMHNjb3JlcyUwQSUyMCUyMCUyMCUyMHJlc3VsdCUyMCUzRCUyMCU3QmtleSUzQSUyMHZhbHVlLm1pZC5mbWVhc3VyZSUyMColMjAxMDAlMjBmb3IlMjBrZXklMkMlMjB2YWx1ZSUyMGluJTIwcmVzdWx0Lml0ZW1zKCklN0QlMEElMjAlMjAlMjAlMjByZXR1cm4lMjAlN0JrJTNBJTIwcm91bmQodiUyQyUyMDQpJTIwZm9yJTIwayUyQyUyMHYlMjBpbiUyMHJlc3VsdC5pdGVtcygpJTdE",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=n(),c(f.$$.fragment),G=n(),g=y("p"),g.innerHTML=_,I=n(),Z=y("p"),Z.innerHTML=N,v=n(),z=y("p"),z.innerHTML=S,X=n(),c(R.$$.fragment)},l(C){p=J(C,"P",{"data-svelte-h":!0}),w(p)!=="svelte-di08mr"&&(p.innerHTML=u),r=M(C),T(f.$$.fragment,C),G=M(C),g=J(C,"P",{"data-svelte-h":!0}),w(g)!=="svelte-ajxonu"&&(g.innerHTML=_),I=M(C),Z=J(C,"P",{"data-svelte-h":!0}),w(Z)!=="svelte-1146555"&&(Z.innerHTML=N),v=M(C),z=J(C,"P",{"data-svelte-h":!0}),w(z)!=="svelte-4ndhx8"&&(z.innerHTML=S),X=M(C),T(R.$$.fragment,C)},m(C,B){a(C,p,B),a(C,r,B),o(f,C,B),a(C,G,B),a(C,g,B),a(C,I,B),a(C,Z,B),a(C,v,B),a(C,z,B),a(C,X,B),o(R,C,B),W=!0},i(C){W||(m(f.$$.fragment,C),m(R.$$.fragment,C),W=!0)},o(C){i(f.$$.fragment,C),i(R.$$.fragment,C),W=!1},d(C){C&&(l(p),l(r),l(G),l(g),l(I),l(Z),l(v),l(z),l(X)),U(f,C),U(R,C)}}}function $M(k){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){U(p,r)}}}function WM(k){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){U(p,r)}}}function _M(k){let p,u="我們幾乎準備好訓練了！ 我們只需要使用我們上面定義的數據整理器將我們的數據集轉換為 tf.data.Dataset ，然後 <code>compile()</code> 和 <code>fit()</code> 模型。 首先，轉換數據集：",r,f,G,g,_="現在，我們定義訓練超參數並編譯：",I,Z,N,v,z="最後，我們擬合模型。 我們在每個 epoch 之後使用<code>PushToHubCallback</code>將模型保存到 Hub，這將允許我們稍後使用它進行推理：",S,X,R,W,C="我們在訓練期間輸出了一些loss，但實際上我們希望看到我們之前計算的 ROUGE 指標。 要獲得這些指標，我們需要從模型生成輸出並將它們轉換為字符串。 讓我們為 ROUGE 指標構建一些標籤和預測列表以進行比較（請注意，如果您在本節中遇到import的錯誤，您可能需要<code>!pip install tqdm</code>）：",B,D,A,Y,K="一旦我們有了標籤和預測字符串列表，計算 ROUGE 分數就很容易了：",$,L,E,Q,P;return f=new d({props:{code:"dGZfdHJhaW5fZGF0YXNldCUyMCUzRCUyMHRva2VuaXplZF9kYXRhc2V0cyU1QiUyMnRyYWluJTIyJTVELnRvX3RmX2RhdGFzZXQoJTBBJTIwJTIwJTIwJTIwY29sdW1ucyUzRCU1QiUyMmlucHV0X2lkcyUyMiUyQyUyMCUyMmF0dGVudGlvbl9tYXNrJTIyJTJDJTIwJTIybGFiZWxzJTIyJTVEJTJDJTBBJTIwJTIwJTIwJTIwY29sbGF0ZV9mbiUzRGRhdGFfY29sbGF0b3IlMkMlMEElMjAlMjAlMjAlMjBzaHVmZmxlJTNEVHJ1ZSUyQyUwQSUyMCUyMCUyMCUyMGJhdGNoX3NpemUlM0Q4JTJDJTBBKSUwQXRmX2V2YWxfZGF0YXNldCUyMCUzRCUyMHRva2VuaXplZF9kYXRhc2V0cyU1QiUyMnZhbGlkYXRpb24lMjIlNUQudG9fdGZfZGF0YXNldCglMEElMjAlMjAlMjAlMjBjb2x1bW5zJTNEJTVCJTIyaW5wdXRfaWRzJTIyJTJDJTIwJTIyYXR0ZW50aW9uX21hc2slMjIlMkMlMjAlMjJsYWJlbHMlMjIlNUQlMkMlMEElMjAlMjAlMjAlMjBjb2xsYXRlX2ZuJTNEZGF0YV9jb2xsYXRvciUyQyUwQSUyMCUyMCUyMCUyMHNodWZmbGUlM0RGYWxzZSUyQyUwQSUyMCUyMCUyMCUyMGJhdGNoX3NpemUlM0Q4JTJDJTBBKQ==",highlighted:`tf_train_dataset = tokenized_datasets[<span class="hljs-string">&quot;train&quot;</span>].to_tf_dataset(
    columns=[<span class="hljs-string">&quot;input_ids&quot;</span>, <span class="hljs-string">&quot;attention_mask&quot;</span>, <span class="hljs-string">&quot;labels&quot;</span>],
    collate_fn=data_collator,
    shuffle=<span class="hljs-literal">True</span>,
    batch_size=<span class="hljs-number">8</span>,
)
tf_eval_dataset = tokenized_datasets[<span class="hljs-string">&quot;validation&quot;</span>].to_tf_dataset(
    columns=[<span class="hljs-string">&quot;input_ids&quot;</span>, <span class="hljs-string">&quot;attention_mask&quot;</span>, <span class="hljs-string">&quot;labels&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:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMGNyZWF0ZV9vcHRpbWl6ZXIlMEFpbXBvcnQlMjB0ZW5zb3JmbG93JTIwYXMlMjB0ZiUwQSUwQSUyMyUyMFRoZSUyMG51bWJlciUyMG9mJTIwdHJhaW5pbmclMjBzdGVwcyUyMGlzJTIwdGhlJTIwbnVtYmVyJTIwb2YlMjBzYW1wbGVzJTIwaW4lMjB0aGUlMjBkYXRhc2V0JTJDJTIwZGl2aWRlZCUyMGJ5JTIwdGhlJTIwYmF0Y2glMjBzaXplJTIwdGhlbiUyMG11bHRpcGxpZWQlMEElMjMlMjBieSUyMHRoZSUyMHRvdGFsJTIwbnVtYmVyJTIwb2YlMjBlcG9jaHMuJTIwTm90ZSUyMHRoYXQlMjB0aGUlMjB0Zl90cmFpbl9kYXRhc2V0JTIwaGVyZSUyMGlzJTIwYSUyMGJhdGNoZWQlMjB0Zi5kYXRhLkRhdGFzZXQlMkMlMEElMjMlMjBub3QlMjB0aGUlMjBvcmlnaW5hbCUyMEh1Z2dpbmclMjBGYWNlJTIwRGF0YXNldCUyQyUyMHNvJTIwaXRzJTIwbGVuKCklMjBpcyUyMGFscmVhZHklMjBudW1fc2FtcGxlcyUyMCUyRiUyRiUyMGJhdGNoX3NpemUuJTBBbnVtX3RyYWluX2Vwb2NocyUyMCUzRCUyMDglMEFudW1fdHJhaW5fc3RlcHMlMjAlM0QlMjBsZW4odGZfdHJhaW5fZGF0YXNldCklMjAqJTIwbnVtX3RyYWluX2Vwb2NocyUwQW1vZGVsX25hbWUlMjAlM0QlMjBtb2RlbF9jaGVja3BvaW50LnNwbGl0KCUyMiUyRiUyMiklNUItMSU1RCUwQSUwQW9wdGltaXplciUyQyUyMHNjaGVkdWxlJTIwJTNEJTIwY3JlYXRlX29wdGltaXplciglMEElMjAlMjAlMjAlMjBpbml0X2xyJTNENS42ZS01JTJDJTBBJTIwJTIwJTIwJTIwbnVtX3dhcm11cF9zdGVwcyUzRDAlMkMlMEElMjAlMjAlMjAlMjBudW1fdHJhaW5fc3RlcHMlM0RudW1fdHJhaW5fc3RlcHMlMkMlMEElMjAlMjAlMjAlMjB3ZWlnaHRfZGVjYXlfcmF0ZSUzRDAuMDElMkMlMEEpJTBBJTBBbW9kZWwuY29tcGlsZShvcHRpbWl6ZXIlM0RvcHRpbWl6ZXIpJTBBJTBBJTIzJTIwVHJhaW4lMjBpbiUyMG1peGVkLXByZWNpc2lvbiUyMGZsb2F0MTYlMEF0Zi5rZXJhcy5taXhlZF9wcmVjaXNpb24uc2V0X2dsb2JhbF9wb2xpY3koJTIybWl4ZWRfZmxvYXQxNiUyMik=",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}}),X=new d({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycy5rZXJhc19jYWxsYmFja3MlMjBpbXBvcnQlMjBQdXNoVG9IdWJDYWxsYmFjayUwQSUwQWNhbGxiYWNrJTIwJTNEJTIwUHVzaFRvSHViQ2FsbGJhY2soJTBBJTIwJTIwJTIwJTIwb3V0cHV0X2RpciUzRGYlMjIlN0Jtb2RlbF9uYW1lJTdELWZpbmV0dW5lZC1hbWF6b24tZW4tZXMlMjIlMkMlMjB0b2tlbml6ZXIlM0R0b2tlbml6ZXIlMEEpJTBBJTBBbW9kZWwuZml0KCUwQSUyMCUyMCUyMCUyMHRmX3RyYWluX2RhdGFzZXQlMkMlMjB2YWxpZGF0aW9uX2RhdGElM0R0Zl9ldmFsX2RhdGFzZXQlMkMlMjBjYWxsYmFja3MlM0QlNUJjYWxsYmFjayU1RCUyQyUyMGVwb2NocyUzRDglMEEp",highlighted:`<span class="hljs-keyword">from</span> transformers.keras_callbacks <span class="hljs-keyword">import</span> PushToHubCallback

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

model.fit(
    tf_train_dataset, validation_data=tf_eval_dataset, callbacks=[callback], epochs=<span class="hljs-number">8</span>
)`,wrap:!1}}),D=new d({props:{code:"ZnJvbSUyMHRxZG0lMjBpbXBvcnQlMjB0cWRtJTBBaW1wb3J0JTIwbnVtcHklMjBhcyUyMG5wJTBBJTBBYWxsX3ByZWRzJTIwJTNEJTIwJTVCJTVEJTBBYWxsX2xhYmVscyUyMCUzRCUyMCU1QiU1RCUwQWZvciUyMGJhdGNoJTIwaW4lMjB0cWRtKHRmX2V2YWxfZGF0YXNldCklM0ElMEElMjAlMjAlMjAlMjBwcmVkaWN0aW9ucyUyMCUzRCUyMG1vZGVsLmdlbmVyYXRlKCoqYmF0Y2gpJTBBJTIwJTIwJTIwJTIwZGVjb2RlZF9wcmVkcyUyMCUzRCUyMHRva2VuaXplci5iYXRjaF9kZWNvZGUocHJlZGljdGlvbnMlMkMlMjBza2lwX3NwZWNpYWxfdG9rZW5zJTNEVHJ1ZSklMEElMjAlMjAlMjAlMjBsYWJlbHMlMjAlM0QlMjBiYXRjaCU1QiUyMmxhYmVscyUyMiU1RC5udW1weSgpJTBBJTIwJTIwJTIwJTIwbGFiZWxzJTIwJTNEJTIwbnAud2hlcmUobGFiZWxzJTIwISUzRCUyMC0xMDAlMkMlMjBsYWJlbHMlMkMlMjB0b2tlbml6ZXIucGFkX3Rva2VuX2lkKSUwQSUyMCUyMCUyMCUyMGRlY29kZWRfbGFiZWxzJTIwJTNEJTIwdG9rZW5pemVyLmJhdGNoX2RlY29kZShsYWJlbHMlMkMlMjBza2lwX3NwZWNpYWxfdG9rZW5zJTNEVHJ1ZSklMEElMjAlMjAlMjAlMjBkZWNvZGVkX3ByZWRzJTIwJTNEJTIwJTVCJTIyJTVDbiUyMi5qb2luKHNlbnRfdG9rZW5pemUocHJlZC5zdHJpcCgpKSklMjBmb3IlMjBwcmVkJTIwaW4lMjBkZWNvZGVkX3ByZWRzJTVEJTBBJTIwJTIwJTIwJTIwZGVjb2RlZF9sYWJlbHMlMjAlM0QlMjAlNUIlMjIlNUNuJTIyLmpvaW4oc2VudF90b2tlbml6ZShsYWJlbC5zdHJpcCgpKSklMjBmb3IlMjBsYWJlbCUyMGluJTIwZGVjb2RlZF9sYWJlbHMlNUQlMEElMjAlMjAlMjAlMjBhbGxfcHJlZHMuZXh0ZW5kKGRlY29kZWRfcHJlZHMpJTBBJTIwJTIwJTIwJTIwYWxsX2xhYmVscy5leHRlbmQoZGVjb2RlZF9sYWJlbHMp",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

all_preds = []
all_labels = []
<span class="hljs-keyword">for</span> batch <span class="hljs-keyword">in</span> tqdm(tf_eval_dataset):
    predictions = model.generate(**batch)
    decoded_preds = tokenizer.batch_decode(predictions, skip_special_tokens=<span class="hljs-literal">True</span>)
    labels = batch[<span class="hljs-string">&quot;labels&quot;</span>].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}}),L=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}}),Q=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=n(),c(f.$$.fragment),G=n(),g=y("p"),g.textContent=_,I=n(),c(Z.$$.fragment),N=n(),v=y("p"),v.innerHTML=z,S=n(),c(X.$$.fragment),R=n(),W=y("p"),W.innerHTML=C,B=n(),c(D.$$.fragment),A=n(),Y=y("p"),Y.textContent=K,$=n(),c(L.$$.fragment),E=n(),c(Q.$$.fragment)},l(j){p=J(j,"P",{"data-svelte-h":!0}),w(p)!=="svelte-15odn3e"&&(p.innerHTML=u),r=M(j),T(f.$$.fragment,j),G=M(j),g=J(j,"P",{"data-svelte-h":!0}),w(g)!=="svelte-1hcze2v"&&(g.textContent=_),I=M(j),T(Z.$$.fragment,j),N=M(j),v=J(j,"P",{"data-svelte-h":!0}),w(v)!=="svelte-10opmwr"&&(v.innerHTML=z),S=M(j),T(X.$$.fragment,j),R=M(j),W=J(j,"P",{"data-svelte-h":!0}),w(W)!=="svelte-l2j3yw"&&(W.innerHTML=C),B=M(j),T(D.$$.fragment,j),A=M(j),Y=J(j,"P",{"data-svelte-h":!0}),w(Y)!=="svelte-1h3xls6"&&(Y.textContent=K),$=M(j),T(L.$$.fragment,j),E=M(j),T(Q.$$.fragment,j)},m(j,x){a(j,p,x),a(j,r,x),o(f,j,x),a(j,G,x),a(j,g,x),a(j,I,x),o(Z,j,x),a(j,N,x),a(j,v,x),a(j,S,x),o(X,j,x),a(j,R,x),a(j,W,x),a(j,B,x),o(D,j,x),a(j,A,x),a(j,Y,x),a(j,$,x),o(L,j,x),a(j,E,x),o(Q,j,x),P=!0},i(j){P||(m(f.$$.fragment,j),m(Z.$$.fragment,j),m(X.$$.fragment,j),m(D.$$.fragment,j),m(L.$$.fragment,j),m(Q.$$.fragment,j),P=!0)},o(j){i(f.$$.fragment,j),i(Z.$$.fragment,j),i(X.$$.fragment,j),i(D.$$.fragment,j),i(L.$$.fragment,j),i(Q.$$.fragment,j),P=!1},d(j){j&&(l(p),l(r),l(G),l(g),l(I),l(N),l(v),l(S),l(R),l(W),l(B),l(A),l(Y),l($),l(E)),U(f,j),U(Z,j),U(X,j),U(D,j),U(L,j),U(Q,j)}}}function VM(k){let p,u="我們終於擁有了訓練所需的所有的前期準備！我們現在只需要使用標準參數實例化訓練器：",r,f,G,g,_="並啟動我們的訓練：",I,Z,N,v,z="在訓練期間，您應該會看到訓練損失減少並且 ROUGE 分數隨著每個 epoch 增加。訓練完成後，您可以通過運行<strong>Trainer.evaluate()</strong> 查看最終的 ROUGE 分數 ：",S,X,R,W,C,B,D="從分數中我們可以看到，我們的模型輕鬆超過了我們的lead-3 baseline——很好！最後要做的是將模型權重推送到 Hub，如下所示：",A,Y,K,$,L,E,Q='這會將檢查點和配置文件保存到 <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，因此您可以輕鬆查看對模型存儲庫所做的更改！',P,j,x="在結束本節之前，讓我們看一下如何使用 🤗 Accelerate 提供的底層API對 mT5 進行微調。",ms;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}}),X=new d({props:{code:"dHJhaW5lci5ldmFsdWF0ZSgp",highlighted:"trainer.evaluate()",wrap:!1}}),W=new d({props:{code:"JTdCJ2V2YWxfbG9zcyclM0ElMjAzLjAyODUyNDM5ODgwMzcxMSUyQyUwQSUyMCdldmFsX3JvdWdlMSclM0ElMjAxNi45NzI4JTJDJTBBJTIwJ2V2YWxfcm91Z2UyJyUzQSUyMDguMjk2OSUyQyUwQSUyMCdldmFsX3JvdWdlTCclM0ElMjAxNi44MzY2JTJDJTBBJTIwJ2V2YWxfcm91Z2VMc3VtJyUzQSUyMDE2Ljg1MSUyQyUwQSUyMCdldmFsX2dlbl9sZW4nJTNBJTIwMTAuMTU5NyUyQyUwQSUyMCdldmFsX3J1bnRpbWUnJTNBJTIwNi4xMDU0JTJDJTBBJTIwJ2V2YWxfc2FtcGxlc19wZXJfc2Vjb25kJyUzQSUyMDM4Ljk4MiUyQyUwQSUyMCdldmFsX3N0ZXBzX3Blcl9zZWNvbmQnJTNBJTIwNC45MTQlN0Q=",highlighted:`{<span class="hljs-string">&#x27;eval_loss&#x27;</span>: <span class="hljs-number">3.028524398803711</span>,
 <span class="hljs-string">&#x27;eval_rouge1&#x27;</span>: <span class="hljs-number">16.9728</span>,
 <span class="hljs-string">&#x27;eval_rouge2&#x27;</span>: <span class="hljs-number">8.2969</span>,
 <span class="hljs-string">&#x27;eval_rougeL&#x27;</span>: <span class="hljs-number">16.8366</span>,
 <span class="hljs-string">&#x27;eval_rougeLsum&#x27;</span>: <span class="hljs-number">16.851</span>,
 <span class="hljs-string">&#x27;eval_gen_len&#x27;</span>: <span class="hljs-number">10.1597</span>,
 <span class="hljs-string">&#x27;eval_runtime&#x27;</span>: <span class="hljs-number">6.1054</span>,
 <span class="hljs-string">&#x27;eval_samples_per_second&#x27;</span>: <span class="hljs-number">38.982</span>,
 <span class="hljs-string">&#x27;eval_steps_per_second&#x27;</span>: <span class="hljs-number">4.914</span>}`,wrap:!1}}),Y=new d({props:{code:"dHJhaW5lci5wdXNoX3RvX2h1Yihjb21taXRfbWVzc2FnZSUzRCUyMlRyYWluaW5nJTIwY29tcGxldGUlMjIlMkMlMjB0YWdzJTNEJTIyc3VtbWFyaXphdGlvbiUyMik=",highlighted:'trainer.push_to_hub(<span class="hljs-attribute">commit_message</span>=<span class="hljs-string">&quot;Training complete&quot;</span>, <span class="hljs-attribute">tags</span>=<span class="hljs-string">&quot;summarization&quot;</span>)',wrap:!1}}),$=new d({props:{code:"J2h0dHBzJTNBJTJGJTJGaHVnZ2luZ2ZhY2UuY28lMkZodWdnaW5nZmFjZS1jb3Vyc2UlMkZtdDUtZmluZXR1bmVkLWFtYXpvbi1lbi1lcyUyRmNvbW1pdCUyRmFhMDUzNmI4MjliMjhlNzNlMWU0Yjk0YjhhNWFhY2VjNDIwZDQwZTAn",highlighted:'<span class="hljs-string">&#x27;https://huggingface.co/huggingface-course/mt5-finetuned-amazon-en-es/commit/aa0536b829b28e73e1e4b94b8a5aacec420d40e0&#x27;</span>',wrap:!1}}),{c(){p=y("p"),p.textContent=u,r=n(),c(f.$$.fragment),G=n(),g=y("p"),g.textContent=_,I=n(),c(Z.$$.fragment),N=n(),v=y("p"),v.innerHTML=z,S=n(),c(X.$$.fragment),R=n(),c(W.$$.fragment),C=n(),B=y("p"),B.textContent=D,A=n(),c(Y.$$.fragment),K=n(),c($.$$.fragment),L=n(),E=y("p"),E.innerHTML=Q,P=n(),j=y("p"),j.textContent=x},l(h){p=J(h,"P",{"data-svelte-h":!0}),w(p)!=="svelte-1evx2ii"&&(p.textContent=u),r=M(h),T(f.$$.fragment,h),G=M(h),g=J(h,"P",{"data-svelte-h":!0}),w(g)!=="svelte-1xae0e3"&&(g.textContent=_),I=M(h),T(Z.$$.fragment,h),N=M(h),v=J(h,"P",{"data-svelte-h":!0}),w(v)!=="svelte-19bot0z"&&(v.innerHTML=z),S=M(h),T(X.$$.fragment,h),R=M(h),T(W.$$.fragment,h),C=M(h),B=J(h,"P",{"data-svelte-h":!0}),w(B)!=="svelte-186a160"&&(B.textContent=D),A=M(h),T(Y.$$.fragment,h),K=M(h),T($.$$.fragment,h),L=M(h),E=J(h,"P",{"data-svelte-h":!0}),w(E)!=="svelte-v9ezef"&&(E.innerHTML=Q),P=M(h),j=J(h,"P",{"data-svelte-h":!0}),w(j)!=="svelte-1n5yakw"&&(j.textContent=x)},m(h,V){a(h,p,V),a(h,r,V),o(f,h,V),a(h,G,V),a(h,g,V),a(h,I,V),o(Z,h,V),a(h,N,V),a(h,v,V),a(h,S,V),o(X,h,V),a(h,R,V),o(W,h,V),a(h,C,V),a(h,B,V),a(h,A,V),o(Y,h,V),a(h,K,V),o($,h,V),a(h,L,V),a(h,E,V),a(h,P,V),a(h,j,V),ms=!0},i(h){ms||(m(f.$$.fragment,h),m(Z.$$.fragment,h),m(X.$$.fragment,h),m(W.$$.fragment,h),m(Y.$$.fragment,h),m($.$$.fragment,h),ms=!0)},o(h){i(f.$$.fragment,h),i(Z.$$.fragment,h),i(X.$$.fragment,h),i(W.$$.fragment,h),i(Y.$$.fragment,h),i($.$$.fragment,h),ms=!1},d(h){h&&(l(p),l(r),l(G),l(g),l(I),l(N),l(v),l(S),l(R),l(C),l(B),l(A),l(K),l(L),l(E),l(P),l(j)),U(f,h),U(Z,h),U(X,h),U(W,h),U(Y,h),U($,h)}}}function yM(k){let p,u,r,f='使用 🤗 Accelerate 微調我們的模型與我們在 <a href="/course/chapter3">Chapter 3</a> 中遇到的文本分類示例非常相似。 主要區別在於需要在訓練期間顯式生成摘要並定義我們如何計算 ROUGE 分數（回想一下，<code>Seq2SeqTrainer</code> 為我們生成了摘要）。 讓我們看看我們如何在 🤗 Accelerate 中實現這兩個要求！',G,g,_,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>：`,N,v,z,S,X="現在我們已經有了僅由張量組成的數據集，接下來要做的是再次實例化<code>DataCollatorForSeq2Seq</code>。 為此，我們需要提供模型微調前的版本，所以讓我們從緩存中再次加載它：",R,W,C,B,D="然後我們可以實例化數據整理器並使用它來定義我們的數據加載器：",A,Y,K,$,L="接下來要做的是定義我們想要使用的優化器。與我們的其他示例一樣，我們將使用 <strong>AdamW</strong> ，這適用於大多數問題：",E,Q,P,j,x="最後，我們將模型、優化器和數據加載器提供給 <strong>accelerator.prepare()</strong> 方法：",ms,h,V,Js,cs,Ts,$s="現在我們已經準備好了我們索要用的對象，還有三件事要做：",As,O,ae="<li>定義學習率調度計劃。</li> <li>實現一個功能來對摘要進行後續處理以進行評估。</li> <li>在 Hub 上創建一個存儲庫，我們可以將模型推送到該存儲庫。</li>",zs,ss,Ml="對於學習率調度，我們將使用前幾節中的標準線性衰減：",os,Us,is,ws,Ws="對於後續處理，我們需要一個函數，將生成的摘要拆分為由換行符分隔的句子。 這是 ROUGE 指標所期望的格式，我們可以使用以下代碼片段來實現：",pl,js,hs,ds,_s="如果你還記得我們是如何定義 <code>Seq2SeqTrainer</code> 的 <code>compute_metrics()</code> 函數的，這對你來說應該很熟悉。",Ys,ls,ee="最後，我們需要在 Hugging Face Hub 上創建一個模型存儲庫。 為此，我們可以使用🤗 Hub 庫的get_full_repo_name。 我們只需要為我們的存儲庫定義一個名稱，該庫有一個非常好用的函數可以將存儲庫 ID 與用戶配置文件結合起來：",Qs,as,Ss,es,rl,us,Vs="現在我們可以使用這個存儲庫名稱將本地版本克隆到我們的結果目錄中，該目錄將存儲訓練的模型：",Es,ts,ml,bs,Rs="這將允許我們在訓練期間通過調用 <code>repo.push_to_hub()</code> 方法將模型推送到 Hub！ 現在讓我們通過寫出完整的訓練循環來結束我們的分析。",Fs,ns,Hs,Ms,te="文本摘要的訓練循環與我們遇到的其他 🤗 Accelerate 示例非常相似，大致分為四個主要步驟：這",Ds,ps,il="<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>",Is,fs,Ns="這些步驟可以在以下代碼塊中看到：",yl,Cs,ys,Xs,Ls,rs,ne="就是這樣！ 運行此程序後，您將獲得與我們使用“Trainer”獲得的模型和結果非常相似的模型和結果。",qs;return p=new gs({props:{title:"使用 🤗 Accelerate 微調 mT5",local:"使用--accelerate-微調-mt5",headingTag:"h2"}}),g=new gs({props:{title:"為訓練做好一切準備",local:"為訓練做好一切準備",headingTag:"h3"}}),v=new d({props:{code:"dG9rZW5pemVkX2RhdGFzZXRzLnNldF9mb3JtYXQoJTIydG9yY2glMjIp",highlighted:'tokenized_datasets.set_format(<span class="hljs-string">&quot;torch&quot;</span>)',wrap:!1}}),W=new d({props:{code:"bW9kZWwlMjAlM0QlMjBBdXRvTW9kZWxGb3JTZXEyU2VxTE0uZnJvbV9wcmV0cmFpbmVkKG1vZGVsX2NoZWNrcG9pbnQp",highlighted:"model = AutoModelForSeq2SeqLM.from_pretrained(model_checkpoint)",wrap:!1}}),Y=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}}),Q=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}}),Js=new tl({props:{$$slots:{default:[RM]},$$scope:{ctx:k}}}),Us=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}}),js=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}}),as=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}}),es=new d({props:{code:"J2xld3R1biUyRm10NS1maW5ldHVuZWQtYW1hem9uLWVuLWVzLWFjY2VsZXJhdGUn",highlighted:'<span class="hljs-string">&#x27;lewtun/mt5-finetuned-amazon-en-es-accelerate&#x27;</span>',wrap:!1}}),ts=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}}),ns=new gs({props:{title:"訓練循環",local:"訓練循環",headingTag:"h3"}}),Cs=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}}),Xs=new d({props:{code:"RXBvY2glMjAwJTNBJTIwJTdCJ3JvdWdlMSclM0ElMjA1LjYzNTElMkMlMjAncm91Z2UyJyUzQSUyMDEuMTYyNSUyQyUyMCdyb3VnZUwnJTNBJTIwNS40ODY2JTJDJTIwJ3JvdWdlTHN1bSclM0ElMjA1LjUwMDUlN0QlMEFFcG9jaCUyMDElM0ElMjAlN0Incm91Z2UxJyUzQSUyMDkuODY0NiUyQyUyMCdyb3VnZTInJTNBJTIwMy40MTA2JTJDJTIwJ3JvdWdlTCclM0ElMjA5Ljk0MzklMkMlMjAncm91Z2VMc3VtJyUzQSUyMDkuOTMwNiU3RCUwQUVwb2NoJTIwMiUzQSUyMCU3Qidyb3VnZTEnJTNBJTIwMTEuMDg3MiUyQyUyMCdyb3VnZTInJTNBJTIwMy4zMjczJTJDJTIwJ3JvdWdlTCclM0ElMjAxMS4wNTA4JTJDJTIwJ3JvdWdlTHN1bSclM0ElMjAxMC45NDY4JTdEJTBBRXBvY2glMjAzJTNBJTIwJTdCJ3JvdWdlMSclM0ElMjAxMS44NTg3JTJDJTIwJ3JvdWdlMiclM0ElMjA0LjgxNjclMkMlMjAncm91Z2VMJyUzQSUyMDExLjc5ODYlMkMlMjAncm91Z2VMc3VtJyUzQSUyMDExLjc1MTglN0QlMEFFcG9jaCUyMDQlM0ElMjAlN0Incm91Z2UxJyUzQSUyMDEyLjk4NDIlMkMlMjAncm91Z2UyJyUzQSUyMDUuNTg4NyUyQyUyMCdyb3VnZUwnJTNBJTIwMTIuNzU0NiUyQyUyMCdyb3VnZUxzdW0nJTNBJTIwMTIuNzAyOSU3RCUwQUVwb2NoJTIwNSUzQSUyMCU3Qidyb3VnZTEnJTNBJTIwMTMuNDYyOCUyQyUyMCdyb3VnZTInJTNBJTIwNi40NTk4JTJDJTIwJ3JvdWdlTCclM0ElMjAxMy4zMTIlMkMlMjAncm91Z2VMc3VtJyUzQSUyMDEzLjI5MTMlN0QlMEFFcG9jaCUyMDYlM0ElMjAlN0Incm91Z2UxJyUzQSUyMDEyLjkxMzElMkMlMjAncm91Z2UyJyUzQSUyMDUuODkxNCUyQyUyMCdyb3VnZUwnJTNBJTIwMTIuNjg5NiUyQyUyMCdyb3VnZUxzdW0nJTNBJTIwMTIuNTcwMSU3RCUwQUVwb2NoJTIwNyUzQSUyMCU3Qidyb3VnZTEnJTNBJTIwMTMuMzA3OSUyQyUyMCdyb3VnZTInJTNBJTIwNi4yOTk0JTJDJTIwJ3JvdWdlTCclM0ElMjAxMy4xNTM2JTJDJTIwJ3JvdWdlTHN1bSclM0ElMjAxMy4xMTk0JTdEJTBBRXBvY2glMjA4JTNBJTIwJTdCJ3JvdWdlMSclM0ElMjAxMy45NiUyQyUyMCdyb3VnZTInJTNBJTIwNi41OTk4JTJDJTIwJ3JvdWdlTCclM0ElMjAxMy45MTIzJTJDJTIwJ3JvdWdlTHN1bSclM0ElMjAxMy43NzQ0JTdEJTBBRXBvY2glMjA5JTNBJTIwJTdCJ3JvdWdlMSclM0ElMjAxNC4xMTkyJTJDJTIwJ3JvdWdlMiclM0ElMjA3LjAwNTklMkMlMjAncm91Z2VMJyUzQSUyMDE0LjExNzIlMkMlMjAncm91Z2VMc3VtJyUzQSUyMDEzLjk1MDklN0Q=",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=n(),r=y("p"),r.innerHTML=f,G=n(),c(g.$$.fragment),_=n(),I=y("p"),I.innerHTML=Z,N=n(),c(v.$$.fragment),z=n(),S=y("p"),S.innerHTML=X,R=n(),c(W.$$.fragment),C=n(),B=y("p"),B.textContent=D,A=n(),c(Y.$$.fragment),K=n(),$=y("p"),$.innerHTML=L,E=n(),c(Q.$$.fragment),P=n(),j=y("p"),j.innerHTML=x,ms=n(),c(h.$$.fragment),V=n(),c(Js.$$.fragment),cs=n(),Ts=y("p"),Ts.textContent=$s,As=n(),O=y("ul"),O.innerHTML=ae,zs=n(),ss=y("p"),ss.textContent=Ml,os=n(),c(Us.$$.fragment),is=n(),ws=y("p"),ws.textContent=Ws,pl=n(),c(js.$$.fragment),hs=n(),ds=y("p"),ds.innerHTML=_s,Ys=n(),ls=y("p"),ls.textContent=ee,Qs=n(),c(as.$$.fragment),Ss=n(),c(es.$$.fragment),rl=n(),us=y("p"),us.textContent=Vs,Es=n(),c(ts.$$.fragment),ml=n(),bs=y("p"),bs.innerHTML=Rs,Fs=n(),c(ns.$$.fragment),Hs=n(),Ms=y("p"),Ms.textContent=te,Ds=n(),ps=y("ol"),ps.innerHTML=il,Is=n(),fs=y("p"),fs.textContent=Ns,yl=n(),c(Cs.$$.fragment),ys=n(),c(Xs.$$.fragment),Ls=n(),rs=y("p"),rs.textContent=ne},l(t){T(p.$$.fragment,t),u=M(t),r=J(t,"P",{"data-svelte-h":!0}),w(r)!=="svelte-34tute"&&(r.innerHTML=f),G=M(t),T(g.$$.fragment,t),_=M(t),I=J(t,"P",{"data-svelte-h":!0}),w(I)!=="svelte-vaymut"&&(I.innerHTML=Z),N=M(t),T(v.$$.fragment,t),z=M(t),S=J(t,"P",{"data-svelte-h":!0}),w(S)!=="svelte-j2upv7"&&(S.innerHTML=X),R=M(t),T(W.$$.fragment,t),C=M(t),B=J(t,"P",{"data-svelte-h":!0}),w(B)!=="svelte-13d4wbh"&&(B.textContent=D),A=M(t),T(Y.$$.fragment,t),K=M(t),$=J(t,"P",{"data-svelte-h":!0}),w($)!=="svelte-17ustuc"&&($.innerHTML=L),E=M(t),T(Q.$$.fragment,t),P=M(t),j=J(t,"P",{"data-svelte-h":!0}),w(j)!=="svelte-19isevy"&&(j.innerHTML=x),ms=M(t),T(h.$$.fragment,t),V=M(t),T(Js.$$.fragment,t),cs=M(t),Ts=J(t,"P",{"data-svelte-h":!0}),w(Ts)!=="svelte-vtsua8"&&(Ts.textContent=$s),As=M(t),O=J(t,"UL",{"data-svelte-h":!0}),w(O)!=="svelte-1emhrdw"&&(O.innerHTML=ae),zs=M(t),ss=J(t,"P",{"data-svelte-h":!0}),w(ss)!=="svelte-6h01mk"&&(ss.textContent=Ml),os=M(t),T(Us.$$.fragment,t),is=M(t),ws=J(t,"P",{"data-svelte-h":!0}),w(ws)!=="svelte-1ybzp24"&&(ws.textContent=Ws),pl=M(t),T(js.$$.fragment,t),hs=M(t),ds=J(t,"P",{"data-svelte-h":!0}),w(ds)!=="svelte-u939lb"&&(ds.innerHTML=_s),Ys=M(t),ls=J(t,"P",{"data-svelte-h":!0}),w(ls)!=="svelte-18hbt2a"&&(ls.textContent=ee),Qs=M(t),T(as.$$.fragment,t),Ss=M(t),T(es.$$.fragment,t),rl=M(t),us=J(t,"P",{"data-svelte-h":!0}),w(us)!=="svelte-97puqp"&&(us.textContent=Vs),Es=M(t),T(ts.$$.fragment,t),ml=M(t),bs=J(t,"P",{"data-svelte-h":!0}),w(bs)!=="svelte-4m9afo"&&(bs.innerHTML=Rs),Fs=M(t),T(ns.$$.fragment,t),Hs=M(t),Ms=J(t,"P",{"data-svelte-h":!0}),w(Ms)!=="svelte-1mstidq"&&(Ms.textContent=te),Ds=M(t),ps=J(t,"OL",{"data-svelte-h":!0}),w(ps)!=="svelte-bno592"&&(ps.innerHTML=il),Is=M(t),fs=J(t,"P",{"data-svelte-h":!0}),w(fs)!=="svelte-127wmdb"&&(fs.textContent=Ns),yl=M(t),T(Cs.$$.fragment,t),ys=M(t),T(Xs.$$.fragment,t),Ls=M(t),rs=J(t,"P",{"data-svelte-h":!0}),w(rs)!=="svelte-1okcb59"&&(rs.textContent=ne)},m(t,b){o(p,t,b),a(t,u,b),a(t,r,b),a(t,G,b),o(g,t,b),a(t,_,b),a(t,I,b),a(t,N,b),o(v,t,b),a(t,z,b),a(t,S,b),a(t,R,b),o(W,t,b),a(t,C,b),a(t,B,b),a(t,A,b),o(Y,t,b),a(t,K,b),a(t,$,b),a(t,E,b),o(Q,t,b),a(t,P,b),a(t,j,b),a(t,ms,b),o(h,t,b),a(t,V,b),o(Js,t,b),a(t,cs,b),a(t,Ts,b),a(t,As,b),a(t,O,b),a(t,zs,b),a(t,ss,b),a(t,os,b),o(Us,t,b),a(t,is,b),a(t,ws,b),a(t,pl,b),o(js,t,b),a(t,hs,b),a(t,ds,b),a(t,Ys,b),a(t,ls,b),a(t,Qs,b),o(as,t,b),a(t,Ss,b),o(es,t,b),a(t,rl,b),a(t,us,b),a(t,Es,b),o(ts,t,b),a(t,ml,b),a(t,bs,b),a(t,Fs,b),o(ns,t,b),a(t,Hs,b),a(t,Ms,b),a(t,Ds,b),a(t,ps,b),a(t,Is,b),a(t,fs,b),a(t,yl,b),o(Cs,t,b),a(t,ys,b),o(Xs,t,b),a(t,Ls,b),a(t,rs,b),qs=!0},i(t){qs||(m(p.$$.fragment,t),m(g.$$.fragment,t),m(v.$$.fragment,t),m(W.$$.fragment,t),m(Y.$$.fragment,t),m(Q.$$.fragment,t),m(h.$$.fragment,t),m(Js.$$.fragment,t),m(Us.$$.fragment,t),m(js.$$.fragment,t),m(as.$$.fragment,t),m(es.$$.fragment,t),m(ts.$$.fragment,t),m(ns.$$.fragment,t),m(Cs.$$.fragment,t),m(Xs.$$.fragment,t),qs=!0)},o(t){i(p.$$.fragment,t),i(g.$$.fragment,t),i(v.$$.fragment,t),i(W.$$.fragment,t),i(Y.$$.fragment,t),i(Q.$$.fragment,t),i(h.$$.fragment,t),i(Js.$$.fragment,t),i(Us.$$.fragment,t),i(js.$$.fragment,t),i(as.$$.fragment,t),i(es.$$.fragment,t),i(ts.$$.fragment,t),i(ns.$$.fragment,t),i(Cs.$$.fragment,t),i(Xs.$$.fragment,t),qs=!1},d(t){t&&(l(u),l(r),l(G),l(_),l(I),l(N),l(z),l(S),l(R),l(C),l(B),l(A),l(K),l($),l(E),l(P),l(j),l(ms),l(V),l(cs),l(Ts),l(As),l(O),l(zs),l(ss),l(os),l(is),l(ws),l(pl),l(hs),l(ds),l(Ys),l(ls),l(Qs),l(Ss),l(rl),l(us),l(Es),l(ml),l(bs),l(Fs),l(Hs),l(Ms),l(Ds),l(ps),l(Is),l(fs),l(yl),l(ys),l(Ls),l(rs)),U(p,t),U(g,t),U(v,t),U(W,t),U(Y,t),U(Q,t),U(h,t),U(Js,t),U(Us,t),U(js,t),U(as,t),U(es,t),U(ts,t),U(ns,t),U(Cs,t),U(Xs,t)}}}function RM(k){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}),w(p)!=="svelte-1ovzgdz"&&(p.innerHTML=u)},m(r,f){a(r,p,f)},p:nl,d(r){r&&l(p)}}}function NM(k){let p,u,r,f,G,g,_,I,Z,N,v,z,S="在本節中，我們將看看如何使用 Transformer 模型將長文檔壓縮為摘要，這項任務稱為文本摘要.這是最具挑戰性的 NLP 任務之一，因為它需要一系列能力，例如理解長篇文章和生成能夠捕捉文檔中主要主題的連貫文本。但是，如果做得好，文本摘要是一種強大的工具，可以減輕領域專家詳細閱讀長文檔的負擔，從而加快各種業務流程。",X,R,W,C,B='儘管在<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>。',D,A,Y,K,$,L,E,Q,P="如下所示：正如我們將看到的，這些摘要很簡潔，因為它們是從客戶在產品評論中提供的標題中學到的。讓我們首先為這項任務準備一個合適的雙語語料庫。",j,x,ms,h,V='我們將使用<a href="https://huggingface.co/datasets/amazon_reviews_multi" rel="nofollow">多語言亞馬遜評論語料庫</a>創建我們的雙語摘要器。該語料庫由六種語言的亞馬遜產品評論組成，通常用於對多語言分類器進行基準測試。然而，由於每條評論都附有一個簡短的標題，我們可以使用標題作為我們模型學習的目標摘要！首先，讓我們從 Hugging Face Hub 下載英語和西班牙語子集：',Js,cs,Ts,$s,As,O,ae='如您所見，對於每種語言，都有 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>學到過：',zs,ss,Ml,os,Us,is,ws,Ws,pl="此示例顯示了人們通常在網上找到的評論的多樣性，從正面到負面（以及介於兩者之間的所有內容！）。儘管標題為“meh”的示例信息量不大，但其他標題看起來像是對評論本身的體面總結。在單個 GPU 上訓練所有 400,000 條評論的摘要模型將花費太長時間，因此我們將專注於為單個產品領域生成摘要。為了瞭解我們可以選擇哪些域，讓我們將 <strong>english_dataset</strong> 轉換到 <strong>pandas.DataFrame</strong> 並計算每個產品類別的評論數量：",js,hs,ds,_s,Ys,ls,ee='英語數據集中最受歡迎的產品是家居用品、服裝和無線電子產品。不過，為了堅持亞馬遜的主題，讓我們專注於總結書籍的評論——畢竟，這是亞馬遜這家公司成立的基礎！我們可以看到兩個符合要求的產品類別（ <strong>book</strong> 和 <strong>digital_ebook_purchase</strong> )，所以讓我們為這些產品過濾兩種語言的數據集。正如我們在<a href="/course/chapter5">第五章</a>學到的， 這 <strong>Dataset.filter()</strong> 函數允許我們非常有效地對數據集進行切片，因此我們可以定義一個簡單的函數來執行此操作：',Qs,as,Ss,es,rl="現在，當我們將此函數應用於 <strong>english_dataset</strong> 和 <strong>spanish_dataset</strong> ，結果將只包含涉及書籍類別的那些行。在應用過濾器之前，讓我們將<strong>english_dataset</strong>的格式從 <strong>pandas</strong> 切換回到 <strong>arrow</strong> ：",us,Vs,Es,ts,ml="然後我們可以應用過濾器功能，作為健全性檢查，讓我們檢查評論樣本，看看它們是否確實與書籍有關：",bs,Rs,Fs,ns,Hs,Ms,te="好的，我們可以看到評論並不是嚴格意義上的書籍，可能是指日曆和 OneNote 等電子應用程序等內容。儘管如此，該領域似乎適合訓練摘要模型。在我們查看適合此任務的各種模型之前，我們還有最後一點數據準備要做：將英語和西班牙語評論合併為一個 <strong>DatasetDict</strong> 目的。 🤗 Datasets 提供了一個方便的 <strong>concatenate_datasets()</strong> 函數（顧名思義）合併 <strong>Dataset</strong> 對象。因此，為了創建我們的雙語數據集，我們將遍歷每個拆分，連接該拆分的數據集，並打亂結果以確保我們的模型不會過度擬合單一語言：",Ds,ps,il,Is,fs,Ns,yl="這當然看起來像是英語和西班牙語評論的混合！現在我們有了一個訓練語料庫，最後要檢查的一件事是評論中單詞的分佈及其標題。這對於摘要任務尤其重要，其中數據中的簡短參考摘要會使模型偏向於僅在生成的摘要中輸出一兩個單詞。下面的圖顯示了單詞分佈，我們可以看到有些標題嚴重偏向於 1-2 個單詞：",Cs,ys,Xs='<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."/>',Ls,rs,ne="為了解決這個問題，我們將過濾掉標題非常短的示例，以便我們的模型可以生成更有趣的摘要。由於我們正在處理英文和西班牙文文本，因此我們可以使用粗略的啟發式方法在空白處拆分標題，然後使用我們可信賴的 <strong>Dataset.filter()</strong> 方法如下：",qs,t,b,Jl,sn="現在我們已經準備好了我們的語料庫，讓我們來看看一些可以對其進行微調的可能的 Transformer 模型！",pe,cl,re,Tl,ln='如果你仔細想想，文本摘要是一種類似於機器翻譯的任務：我們有一個像評論這樣的文本正文，我們希望將其“翻譯”成一個較短的版本，以捕捉輸入的顯著特徵。因此，大多數用於文本摘要的 Transformer 模型採用了我們在<a href="/course/chapter1">第一章</a>遇到的編碼器-解碼器架構。儘管有一些例外，例如 GPT 系列模型，它們在few-shot（少量微調）之後也可以提取摘要。下表列出了一些流行的預訓練模型，可以對其進行微調以進行彙總。',me,ol,an='<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>',ie,Ul,en="從此表中可以看出，大多數用於摘要的 Transformer 模型（以及大多數 NLP 任務）都是單語的。如果您的任務是使用“有大量語料庫”的語言（如英語或德語），這很好，但對於世界各地正在使用的數千種其他語言，則不然。幸運的是，有一類多語言 Transformer 模型，如 mT5 和 mBART，可以解決問題。這些模型是使用語言建模進行預訓練的，但有一點不同：它們不是在一種語言的語料庫上訓練，而是同時在 50 多種語言的文本上進行聯合訓練！",ye,wl,tn="我們將使用 mT5，這是一種基於 T5 的有趣架構，在文本到文本框架中進行了預訓練。在 T5 中，每個 NLP 任務都是根據提示前綴來制定的，例如 <strong>summarize:</strong> 這使模型使生成的文本適應提示。如下圖所示，這讓 T5 變得非常通用，因為你可以用一個模型解決很多任務！",Je,Ks,nn='<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."/>',ce,jl,Mn="mT5 不使用前綴，但具有 T5 的大部分功能，並且具有多語言的優勢。現在我們已經選擇了一個模型，讓我們來看看準備我們的訓練數據。",Te,Ps,oe,hl,Ue,dl,we,ul,pn="我們的下一個任務是對我們的評論及其標題進行標記和編碼。像往常一樣，我們首先加載與預訓練模型檢查點相關的標記器。我們將使用 <strong>mt5-small</strong> 作為我們的檢查點，以便我們可以在合理的時間內微調模型：",je,bl,he,Os,de,Il,rn="讓我們在一個小例子上測試 mT5 標記器：",ue,fl,be,Cl,Ie,gl,mn='在這裡我們可以看到我們在<a href="/course/chapter3">第三章</a>第一次微調實驗中遇到的熟悉的 <strong>input_ids</strong> 和 <strong>attention_mask</strong> .讓我們用分詞器解碼這些輸入 ID ，可以<strong>convert_ids_to_tokens()</strong> 函數來查看我們正在處理什麼樣的標記器：',fe,Zl,Ce,kl,ge,Gl,yn='特殊的 Unicode 字符 <code>▁</code> 和序列結束標記 <code>&lt;/s&gt;</code> 表明我們正在處理 SentencePiece 分詞器，它基於在<a href="/course/chapter6">第六章</a>中討論的Unigram分詞算法. Unigram 對多語言語料庫特別有用，因為它允許 SentencePiece 不知道重音、標點符號以及許多語言（如日語）沒有空格字符。',Ze,vl,Jn="為了標記我們的語料庫，我們必須處理與摘要相關的細節：因為我們的標籤也是文本，它們可能會超過模型的最大上下文大小。這意味著我們需要對評論及其標題進行截斷，以確保我們不會將過長的輸入傳遞給我們的模型。 🤗 Transformers 中的分詞器提供了一個漂亮的 <strong>as_target_tokenizer()</strong> 函數，它允許您並行分詞並標記標籤的函數。這通常是使用預處理函數內的上下文管理器完成的，該函數首先對輸入進行編碼，然後將標籤編碼為單獨的列。以下是 mT5 的此函數的示例：",ke,Bl,Ge,xl,cn="讓我們通過這段代碼來了解發生了什麼。我們做的第一件事是定義值 <strong>max_input_length</strong> 和 <strong>max_target_length</strong> ，它為我們的評論和標題的長度設置了上限。由於評論正文通常比標題大得多，我們相應地調整了這些值。然後，在 <strong>preprocess_function()</strong> 我們可以看到評論首先被標記化，然後是標題在 <strong>as_target_tokenizer()</strong> 函數里也做了相同的處理.",ve,$l,Tn="有了 <code>preprocess_function()</code>，我們在整個課程中廣泛使用的方便的 <code>Dataset.map()</code> 函數來標記整個語料庫是一件簡單的事情：",Be,Wl,xe,_l,on="既然語料庫已經預處理完畢，我們來看看一些常用的摘要指標。正如我們將看到的，在衡量機器生成的文本的質量方面沒有靈丹妙藥。",$e,sl,We,Vl,_e,Rl,Ve,Nl,Un="與我們在本課程中涵蓋的大多數其他任務相比，衡量文本生成任務（如摘要或翻譯）的性能並不那麼簡單。例如，對於“我喜歡閱讀飢餓遊戲”這樣的評論，有多個有效摘要，例如“我喜歡飢餓遊戲”或“飢餓遊戲是一本好書”。顯然，在生成的摘要和標籤之間應用某種精確匹配並不是一個好的解決方案——即使是人類在這樣的指標下也會表現不佳，因為我們都有自己的寫作風格。",Re,Xl,wn='總而言之，最常用的指標之一是<a href="https://en.wikipedia.org/wiki/ROUGE_(metric)" rel="nofollow">ROUGE 分數</a>（Recall-Oriented Understudy for Gisting Evaluation 的縮寫）。該指標背後的基本思想是將生成的摘要與一組通常由人類創建的參考摘要進行比較。為了更精確，假設我們要比較以下兩個摘要：',Ne,Al,Xe,zl,jn="比較它們的一種方法是計算重疊單詞的數量，在這種情況下為 6。但是，這有點粗糙，因此 ROUGE 是基於計算計算重疊的 <em>precision</em> 和 <em>recall</em> 分數。。",Ae,ll,ze,Yl,Ht,Ye,cM='<span class="katex-display"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><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>',Qe,Ql,Dt,Se,TM='<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>',Ee,Sl,hn="將此應用到我們的詳細摘要中會得到 6/10 = 0.6 的精度，這比我們較短的摘要獲得的 6/7 = 0.86 的精度要差得多。在實踐中，通常計算精度和召回率，然後報告 F1-score（精度和召回率的調和平均值）。我們可以在 🤗 Datasets 中通過安裝 <strong>rouge_score</strong> 包來計算他們：",Fe,El,He,Fl,dn="然後按如下方式加載 ROUGE 指標：",De,Hl,Le,Dl,un="然後我們可以使用 <strong>rouge_score.compute()</strong> 一次性計算所有指標的函數：",qe,Ll,Ke,ql,Pe,Kl,bn="哇，那個輸出中有很多信息——這都是什麼意思？首先，🤗 Datasets實際上計算了精度、召回率和 F1 分數的置信區間；這些是你可以在這裡看到的 <strong>low</strong> , <strong>mid</strong> ， 和 <strong>high</strong> 屬性。此外，🤗 Datasets在比較生成摘要和參考摘要時，會根據不同類型的文本粒度計算各種 ROUGE 分數。這 <strong>rouge1</strong> 變體是一元組的重疊——這只是表達單詞重疊的一種奇特方式，這正是我們上面討論的度量標準。為了驗證這一點，讓我們輸出 <strong>mid</strong> 的數值：",Oe,Pl,st,Ol,lt,sa,In="太好了，準確率和召回率匹配了！那麼其他的 ROUGE 分數呢？ <strong>rouge2</strong> 測量二元組之間的重疊（想想單詞對的重疊），而 <strong>rougeL</strong> 和 <strong>rougeLsum</strong> 通過在生成的和參考摘要中查找最長的公共子串來測量最長的單詞匹配序列。中的“總和” <strong>rougeLsum</strong> 指的是這個指標是在整個摘要上計算的，而 <strong>rougeL</strong> 計算為單個句子的平均值。",at,al,et,la,fn="我們將使用這些 ROUGE 分數來跟蹤我們模型的性能，但在此之前，讓我們做每個優秀的 NLP 從業者都應該做的事情：創建一個強大而簡單的baseline！",tt,aa,nt,ea,Cn="文本摘要的一個常見基線是簡單地取一篇文章的前三個句子，通常稱為 <em>lead-3</em> 基線。 我們可以使用句號(英文使用.)來跟蹤句子邊界，但這在”U.S.” or “U.N.”之類的首字母縮略詞上會失敗。所以我們將使用 <code>nltk</code> 庫，它包含一個更好的算法來處理這些情況。 您可以使用 <code>pip</code> 安裝軟件包，如下所示：",Mt,ta,pt,na,gn="然後下載標點規則：",rt,Ma,mt,pa,Zn="接下來，我們從 <code>nltk</code> 導入句子標記器並創建一個簡單的函數來提取評論中的前三個句子。 文本摘要的約定是用換行符分隔每個摘要，因此我們也將其包含在內並在訓練示例上對其進行測試：",it,ra,yt,ma,Jt,ia,kn="這似乎有效，所以讓我們現在實現一個函數，從數據集中提取這些“摘要”並計算baseline的 ROUGE 分數：",ct,ya,Tt,Ja,Gn="然後我們可以使用這個函數來計算驗證集上的 ROUGE 分數，並使用 Pandas 對它們進行一些美化：",ot,ca,Ut,Ta,wt,oa,vn="我們可以看到<code>rouge2</code>的分數明顯低於其他； 這可能反映了這樣一個事實，即評論標題通常很簡潔，因此lead-3 baseline過於冗長。 現在我們有了一個很好的基準，讓我們將注意力轉向微調 mT5！",jt,Zs,ks,Ha,el,ht,Ua,Bn="我們需要做的下一件事是登錄 Hugging Face Hub。如果您在notebook中運行此代碼，則可以使用以下實用程序函數執行此操作：",dt,wa,ut,ja,xn="這將顯示一個小部件，您可以在其中輸入您的憑據。或者，您可以在終端中運行此命令並在那裡登錄：",bt,ha,It,Da,da,$n='接下來，我們需要為我們的序列到序列任務定義一個數據整理器。由於 mT5 是一個編碼器-解碼器 Transformer 模型，準備我們的批次的一個微妙之處是，在解碼過程中，我們需要將標籤向右移動一個。 這是為了確保解碼器只看到之前的真實的標籤，而不是當前或未來的標籤，這對於模型來說很容易記憶。 這類似於在 <a href="/course/chapter7/6">因果語言建模</a> 等任務中如何將掩蔽的自我注意應用於輸入。',ft,ua,Wn="幸運的是，🤗 Transformers 提供了一個 <code>DataCollatorForSeq2Seq</code> 整理器，它將為我們動態填充輸入和標籤。 要實例化這個收集器，我們只需要提供 <code>tokenizer</code> 和 <code>model</code>：",Ct,Gs,vs,La,ba,_n="讓我們看看這個整理器在輸入一小批示例時會產生什麼。 首先，我們需要刪除帶有字符串的列，因為整理器不知道如何填充這些元素：",gt,Ia,Zt,fa,Vn="由於 collator 需要一個 <code>dict</code> 的列表，其中每個 <code>dict</code> 代表數據集中的一個示例，我們還需要在將數據傳遞給 data collator 之前將數據整理成預期的格式：",kt,Ca,Gt,ga,vt,Za,Rn="這裡要注意的主要是第一個例子比第二個例子要長，所以第二個例子的 <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> 標記將標籤向右移動。",Bt,Bs,xs,qa,Ka,ka,xt,Ga,Nn="將模型推送到 Hub 後，您可以通過推理小部件或“管道”對象來使用它，如下所示：",$t,va,Wt,Ba,Xn="我們可以將測試集中的一些示例（模型還沒有看到）提供給我們的管道，以瞭解生成摘要的質量。 首先讓我們實現一個簡單的函數來一起顯示評論、標題和生成的摘要：",_t,xa,Vt,$a,An="讓我們看一下我們得到的一個英文例子：",Rt,Wa,Nt,_a,Xt,Va,zn="這還不錯！ 我們可以看到，我們的模型實際上已經能夠通過增加部分新詞來執行抽象摘要。 也許我們模型最酷的方面是它是雙語的，所以我們還可以生成西班牙語評論的摘要：",At,Ra,zt,Na,Yt,Xa,Yn="摘要翻譯成了英文的“非常容易閱讀”，在這種情況下，我們可以看到它是直接從評論中提取的。 這顯示了 mT5 模型的多功能性，並讓您體驗了處理多語言語料庫的感覺！",Qt,Aa,Qn="接下來，我們將把注意力轉向稍微複雜的任務：從頭開始訓練語言模型。",St,za,Et,Me,Ft;G=new dM({props:{fw:k[0]}}),_=new gs({props:{title:"提取文本摘要",local:"提取文本摘要",headingTag:"h1"}});const Sn=[IM,bM],Ya=[];function En(s,e){return s[0]==="pt"?0:1}Z=En(k),N=Ya[Z]=Sn[Z](k),R=new Ot({props:{id:"yHnr5Dk2zCI"}}),x=new gs({props:{title:"準備多語言語料庫",local:"準備多語言語料庫",headingTag:"h2"}}),cs=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}}),$s=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}}),os=new d({props:{code:"JyUzRSUzRSUyMFRpdGxlJTNBJTIwV29ya2VkJTIwaW4lMjBmcm9udCUyMHBvc2l0aW9uJTJDJTIwbm90JTIwcmVhciclMEEnJTNFJTNFJTIwUmV2aWV3JTNBJTIwMyUyMHN0YXJzJTIwYmVjYXVzZSUyMHRoZXNlJTIwYXJlJTIwbm90JTIwcmVhciUyMGJyYWtlcyUyMGFzJTIwc3RhdGVkJTIwaW4lMjB0aGUlMjBpdGVtJTIwZGVzY3JpcHRpb24uJTIwQXQlMjBsZWFzdCUyMHRoZSUyMG1vdW50JTIwYWRhcHRlciUyMG9ubHklMjB3b3JrZWQlMjBvbiUyMHRoZSUyMGZyb250JTIwZm9yayUyMG9mJTIwdGhlJTIwYmlrZSUyMHRoYXQlMjBJJTIwZ290JTIwaXQlMjBmb3IuJyUwQSUwQSclM0UlM0UlMjBUaXRsZSUzQSUyMG1laCclMEEnJTNFJTNFJTIwUmV2aWV3JTNBJTIwRG9lcyUyMGl0JUUyJTgwJTk5cyUyMGpvYiUyMGFuZCUyMGl0JUUyJTgwJTk5cyUyMGdvcmdlb3VzJTIwYnV0JTIwbWluZSUyMGlzJTIwZmFsbGluZyUyMGFwYXJ0JTJDJTIwSSUyMGhhZCUyMHRvJTIwYmFzaWNhbGx5JTIwcHV0JTIwaXQlMjB0b2dldGhlciUyMGFnYWluJTIwd2l0aCUyMGhvdCUyMGdsdWUnJTBBJTBBJyUzRSUzRSUyMFRpdGxlJTNBJTIwQ2FuJTVDJ3QlMjBiZWF0JTIwdGhlc2UlMjBmb3IlMjB0aGUlMjBtb25leSclMEEnJTNFJTNFJTIwUmV2aWV3JTNBJTIwQm91Z2h0JTIwdGhpcyUyMGZvciUyMGhhbmRsaW5nJTIwbWlzY2VsbGFuZW91cyUyMGFpcmNyYWZ0JTIwcGFydHMlMjBhbmQlMjBoYW5nZXIlMjAlMjJzdHVmZiUyMiUyMHRoYXQlMjBJJTIwbmVlZGVkJTIwdG8lMjBvcmdhbml6ZSUzQiUyMGl0JTIwcmVhbGx5JTIwZml0JTIwdGhlJTIwYmlsbC4lMjBUaGUlMjB1bml0JTIwYXJyaXZlZCUyMHF1aWNrbHklMkMlMjB3YXMlMjB3ZWxsJTIwcGFja2FnZWQlMjBhbmQlMjBhcnJpdmVkJTIwaW50YWN0JTIwKGFsd2F5cyUyMGElMjBnb29kJTIwc2lnbikuJTIwVGhlcmUlMjBhcmUlMjBmaXZlJTIwd2FsbCUyMG1vdW50cy0tJTIwdGhyZWUlMjBvbiUyMHRoZSUyMHRvcCUyMGFuZCUyMHR3byUyMG9uJTIwdGhlJTIwYm90dG9tLiUyMEklMjB3YW50ZWQlMjB0byUyMG1vdW50JTIwaXQlMjBvbiUyMHRoZSUyMHdhbGwlMkMlMjBzbyUyMGFsbCUyMEklMjBoYWQlMjB0byUyMGRvJTIwd2FzJTIwdG8lMjByZW1vdmUlMjB0aGUlMjB0b3AlMjB0d28lMjBsYXllcnMlMjBvZiUyMHBsYXN0aWMlMjBkcmF3ZXJzJTJDJTIwYXMlMjB3ZWxsJTIwYXMlMjB0aGUlMjBib3R0b20lMjBjb3JuZXIlMjBkcmF3ZXJzJTJDJTIwcGxhY2UlMjBpdCUyMHdoZW4lMjBJJTIwd2FudGVkJTIwYW5kJTIwbWFyayUyMGl0JTNCJTIwSSUyMHRoZW4lMjB1c2VkJTIwc29tZSUyMG9mJTIwdGhlJTIwbmV3JTIwcGxhc3RpYyUyMHNjcmV3JTIwaW4lMjB3YWxsJTIwYW5jaG9ycyUyMCh0aGUlMjA1MCUyMHBvdW5kJTIwdmFyaWV0eSklMjBhbmQlMjBpdCUyMGVhc2lseSUyMG1vdW50ZWQlMjB0byUyMHRoZSUyMHdhbGwuJTIwU29tZSUyMGhhdmUlMjByZW1hcmtlZCUyMHRoYXQlMjB0aGV5JTIwd2FudGVkJTIwZGl2aWRlcnMlMjBmb3IlMjB0aGUlMjBkcmF3ZXJzJTJDJTIwYW5kJTIwdGhhdCUyMHRoZXklMjBtYWRlJTIwdGhvc2UuJTIwR29vZCUyMGlkZWEuJTIwTXklMjBhcHBsaWNhdGlvbiUyMHdhcyUyMHRoYXQlMjBJJTIwbmVlZGVkJTIwc29tZXRoaW5nJTIwdGhhdCUyMEklMjBjYW4lMjBzZWUlMjB0aGUlMjBjb250ZW50cyUyMGF0JTIwYWJvdXQlMjBleWUlMjBsZXZlbCUyQyUyMHNvJTIwSSUyMHdhbnRlZCUyMHRoZSUyMGZ1bGxlci1zaXplZCUyMGRyYXdlcnMuJTIwSSUyMGFsc28lMjBsaWtlJTIwdGhhdCUyMHRoZXNlJTIwYXJlJTIwdGhlJTIwbmV3JTIwcGxhc3RpYyUyMHRoYXQlMjBkb2VzbiU1Qyd0JTIwZ2V0JTIwYnJpdHRsZSUyMGFuZCUyMHNwbGl0JTIwbGlrZSUyMG15JTIwb2xkZXIlMjBwbGFzdGljJTIwZHJhd2VycyUyMGRpZC4lMjBJJTIwbGlrZSUyMHRoZSUyMGFsbC1wbGFzdGljJTIwY29uc3RydWN0aW9uLiUyMEl0JTVDJ3MlMjBoZWF2eSUyMGR1dHklMjBlbm91Z2glMjB0byUyMGhvbGQlMjBtZXRhbCUyMHBhcnRzJTJDJTIwYnV0JTIwYmVpbmclMjBtYWRlJTIwb2YlMjBwbGFzdGljJTIwaXQlNUMncyUyMG5vdCUyMGFzJTIwaGVhdnklMjBhcyUyMGElMjBtZXRhbCUyMGZyYW1lJTJDJTIwc28lMjB5b3UlMjBjYW4lMjBlYXNpbHklMjBtb3VudCUyMGl0JTIwdG8lMjB0aGUlMjB3YWxsJTIwYW5kJTIwc3RpbGwlMjBsb2FkJTIwaXQlMjB1cCUyMHdpdGglMjBoZWF2eSUyMHN0dWZmJTJDJTIwb3IlMjBsaWdodCUyMHN0dWZmLiUyME5vJTIwcHJvYmxlbSUyMHRoZXJlLiUyMEZvciUyMHRoZSUyMG1vbmV5JTJDJTIweW91JTIwY2FuJTVDJ3QlMjBiZWF0JTIwaXQuJTIwQmVzdCUyMG9uZSUyMG9mJTIwdGhlc2UlMjBJJTVDJ3ZlJTIwYm91Z2h0JTIwdG8lMjBkYXRlLS0lMjBhbmQlMjBJJTVDJ3ZlJTIwYmVlbiUyMHVzaW5nJTIwc29tZSUyMHZlcnNpb24lMjBvZiUyMHRoZXNlJTIwZm9yJTIwb3ZlciUyMGZvcnR5JTIweWVhcnMuJw==",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}}),is=new tl({props:{$$slots:{default:[fM]},$$scope:{ctx:k}}}),hs=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}}),_s=new d({props:{code:"aG9tZSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMDE3Njc5JTBBYXBwYXJlbCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMDE1OTUxJTBBd2lyZWxlc3MlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAxNTcxNyUwQW90aGVyJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwMTM0MTglMEFiZWF1dHklMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAxMjA5MSUwQWRydWdzdG9yZSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMDExNzMwJTBBa2l0Y2hlbiUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMDEwMzgyJTBBdG95JTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwODc0NSUwQXNwb3J0cyUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMDgyNzclMEFhdXRvbW90aXZlJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwNzUwNiUwQWxhd25fYW5kX2dhcmRlbiUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMDczMjclMEFob21lX2ltcHJvdmVtZW50JTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwNzEzNiUwQXBldF9wcm9kdWN0cyUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMDcwODIlMEFkaWdpdGFsX2Vib29rX3B1cmNoYXNlJTIwJTIwJTIwJTIwJTIwNjc0OSUwQXBjJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwNjQwMSUwQWVsZWN0cm9uaWNzJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwNjE4NiUwQW9mZmljZV9wcm9kdWN0JTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwNTUyMSUwQXNob2VzJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwNTE5NyUwQWdyb2NlcnklMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjA0NzMwJTBBYm9vayUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMDM3NTYlMEFOYW1lJTNBJTIwcHJvZHVjdF9jYXRlZ29yeSUyQyUyMGR0eXBlJTNBJTIwaW50NjQ=",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}}),as=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}}),Vs=new d({props:{code:"ZW5nbGlzaF9kYXRhc2V0LnJlc2V0X2Zvcm1hdCgp",highlighted:"english_dataset.reset_format()",wrap:!1}}),Rs=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}}),ns=new d({props:{code:"JyUzRSUzRSUyMFRpdGxlJTNBJTIwSSU1QydtJTIwZGlzc2Fwb2ludGVkLiclMEEnJTNFJTNFJTIwUmV2aWV3JTNBJTIwSSUyMGd1ZXNzJTIwSSUyMGhhZCUyMGhpZ2hlciUyMGV4cGVjdGF0aW9ucyUyMGZvciUyMHRoaXMlMjBib29rJTIwZnJvbSUyMHRoZSUyMHJldmlld3MuJTIwSSUyMHJlYWxseSUyMHRob3VnaHQlMjBJJTVDJ2QlMjBhdCUyMGxlYXN0JTIwbGlrZSUyMGl0LiUyMFRoZSUyMHBsb3QlMjBpZGVhJTIwd2FzJTIwZ3JlYXQuJTIwSSUyMGxvdmVkJTIwQXNoJTIwYnV0JTJDJTIwaXQlMjBqdXN0JTIwZGlkbnQlMjBnbyUyMGFueXdoZXJlLiUyME1vc3QlMjBvZiUyMHRoZSUyMGJvb2slMjB3YXMlMjBhYm91dCUyMHRoZWlyJTIwcmFkaW8lMjBzaG93JTIwYW5kJTIwdGFsa2luZyUyMHRvJTIwY2FsbGVycy4lMjBJJTIwd2FudGVkJTIwdGhlJTIwYXV0aG9yJTIwdG8lMjBkaWclMjBkZWVwZXIlMjBzbyUyMHdlJTIwY291bGQlMjByZWFsbHklMjBnZXQlMjB0byUyMGtub3clMjB0aGUlMjBjaGFyYWN0ZXJzLiUyMEFsbCUyMHdlJTIwa25vdyUyMGFib3V0JTIwR3JhY2UlMjBpcyUyMHRoYXQlMjBzaGUlMjBpcyUyMGF0dHJhY3RpdmUlMjBsb29raW5nJTJDJTIwTGF0aW5vJTIwYW5kJTIwaXMlMjBraW5kJTIwb2YlMjBhJTIwYnJhdC4lMjBJJTVDJ20lMjBkaXNzYXBvaW50ZWQuJyUwQSUwQSclM0UlM0UlMjBUaXRsZSUzQSUyMEdvb2QlMjBhcnQlMkMlMjBnb29kJTIwcHJpY2UlMkMlMjBwb29yJTIwZGVzaWduJyUwQSclM0UlM0UlMjBSZXZpZXclM0ElMjBJJTIwaGFkJTIwZ290dGVuJTIwdGhlJTIwREMlMjBWaW50YWdlJTIwY2FsZW5kYXIlMjB0aGUlMjBwYXN0JTIwdHdvJTIweWVhcnMlMkMlMjBidXQlMjBpdCUyMHdhcyUyMG9uJTIwYmFja29yZGVyJTIwZm9yZXZlciUyMHRoaXMlMjB5ZWFyJTIwYW5kJTIwSSUyMHNhdyUyMHRoZXklMjBoYWQlMjBzaHJ1bmslMjB0aGUlMjBkaW1lbnNpb25zJTIwZm9yJTIwbm8lMjBnb29kJTIwcmVhc29uLiUyMFRoaXMlMjBvbmUlMjBoYXMlMjBnb29kJTIwYXJ0JTIwY2hvaWNlcyUyMGJ1dCUyMHRoZSUyMGRlc2lnbiUyMGhhcyUyMHRoZSUyMGZvbGQlMjBnb2luZyUyMHRocm91Z2glMjB0aGUlMjBwaWN0dXJlJTJDJTIwc28lMjBpdCU1QydzJTIwbGVzcyUyMGFlc3RoZXRpY2FsbHklMjBwbGVhc2luZyUyQyUyMGVzcGVjaWFsbHklMjBpZiUyMHlvdSUyMHdhbnQlMjB0byUyMGtlZXAlMjBhJTIwcGljdHVyZSUyMHRvJTIwaGFuZy4lMjBGb3IlMjB0aGUlMjBwcmljZSUyQyUyMGElMjBnb29kJTIwY2FsZW5kYXInJTBBJTBBJyUzRSUzRSUyMFRpdGxlJTNBJTIwSGVscGZ1bCclMEEnJTNFJTNFJTIwUmV2aWV3JTNBJTIwTmVhcmx5JTIwYWxsJTIwdGhlJTIwdGlwcyUyMHVzZWZ1bCUyMGFuZC4lMjBJJTIwY29uc2lkZXIlMjBteXNlbGYlMjBhbiUyMGludGVybWVkaWF0ZSUyMHRvJTIwYWR2YW5jZWQlMjB1c2VyJTIwb2YlMjBPbmVOb3RlLiUyMEklMjB3b3VsZCUyMGhpZ2hseSUyMHJlY29tbWVuZC4n",highlighted:`<span class="hljs-string">&#x27;&gt;&gt; Title: I\\&#x27;m dissapointed.&#x27;</span>
<span class="hljs-string">&#x27;&gt;&gt; Review: I guess I had higher expectations for this book from the reviews. I really thought I\\&#x27;d at least like it. The plot idea was great. I loved Ash but, it just didnt go anywhere. Most of the book was about their radio show and talking to callers. I wanted the author to dig deeper so we could really get to know the characters. All we know about Grace is that she is attractive looking, Latino and is kind of a brat. I\\&#x27;m dissapointed.&#x27;</span>

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

<span class="hljs-string">&#x27;&gt;&gt; Title: Helpful&#x27;</span>
<span class="hljs-string">&#x27;&gt;&gt; Review: Nearly all the tips useful and. I consider myself an intermediate to advanced user of OneNote. I would highly recommend.&#x27;</span>`,wrap:!1}}),ps=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}}),Is=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}}),t=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 gs({props:{title:"文本摘要模型",local:"文本摘要模型",headingTag:"h2"}}),Ps=new tl({props:{$$slots:{default:[CM]},$$scope:{ctx:k}}}),hl=new gs({props:{title:"預處理數據",local:"預處理數據",headingTag:"h2"}}),dl=new Ot({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}}),Os=new tl({props:{$$slots:{default:[gM]},$$scope:{ctx:k}}}),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}}),kl=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}}),Bl=new d({props:{code:"bWF4X2lucHV0X2xlbmd0aCUyMCUzRCUyMDUxMiUwQW1heF90YXJnZXRfbGVuZ3RoJTIwJTNEJTIwMzAlMEElMEElMEFkZWYlMjBwcmVwcm9jZXNzX2Z1bmN0aW9uKGV4YW1wbGVzKSUzQSUwQSUyMCUyMCUyMCUyMG1vZGVsX2lucHV0cyUyMCUzRCUyMHRva2VuaXplciglMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBleGFtcGxlcyU1QiUyMnJldmlld19ib2R5JTIyJTVEJTJDJTIwbWF4X2xlbmd0aCUzRG1heF9pbnB1dF9sZW5ndGglMkMlMjB0cnVuY2F0aW9uJTNEVHJ1ZSUwQSUyMCUyMCUyMCUyMCklMEElMjAlMjAlMjAlMjAlMjMlMjBTZXQlMjB1cCUyMHRoZSUyMHRva2VuaXplciUyMGZvciUyMHRhcmdldHMlMEElMjAlMjAlMjAlMjB3aXRoJTIwdG9rZW5pemVyLmFzX3RhcmdldF90b2tlbml6ZXIoKSUzQSUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMGxhYmVscyUyMCUzRCUyMHRva2VuaXplciglMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBleGFtcGxlcyU1QiUyMnJldmlld190aXRsZSUyMiU1RCUyQyUyMG1heF9sZW5ndGglM0RtYXhfdGFyZ2V0X2xlbmd0aCUyQyUyMHRydW5jYXRpb24lM0RUcnVlJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwKSUwQSUwQSUyMCUyMCUyMCUyMG1vZGVsX2lucHV0cyU1QiUyMmxhYmVscyUyMiU1RCUyMCUzRCUyMGxhYmVscyU1QiUyMmlucHV0X2lkcyUyMiU1RCUwQSUyMCUyMCUyMCUyMHJldHVybiUyMG1vZGVsX2lucHV0cw==",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>
    )
    <span class="hljs-comment"># Set up the tokenizer for targets</span>
    <span class="hljs-keyword">with</span> tokenizer.as_target_tokenizer():
        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}}),sl=new tl({props:{$$slots:{default:[ZM]},$$scope:{ctx:k}}}),Vl=new gs({props:{title:"文本摘要的指標",local:"文本摘要的指標",headingTag:"h2"}}),Rl=new Ot({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}}),ll=new tl({props:{$$slots:{default:[kM]},$$scope:{ctx:k}}}),El=new d({props:{code:"IXBpcCUyMGluc3RhbGwlMjByb3VnZV9zY29yZQ==",highlighted:"!pip install rouge_score",wrap:!1}}),Hl=new d({props:{code:"ZnJvbSUyMGRhdGFzZXRzJTIwaW1wb3J0JTIwbG9hZF9tZXRyaWMlMEElMEFyb3VnZV9zY29yZSUyMCUzRCUyMGxvYWRfbWV0cmljKCUyMnJvdWdlJTIyKQ==",highlighted:`<span class="hljs-keyword">from</span> datasets <span class="hljs-keyword">import</span> load_metric

rouge_score = load_metric(<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}}),al=new tl({props:{$$slots:{default:[GM]},$$scope:{ctx:k}}}),aa=new gs({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 Fn=[BM,vM],Qa=[];function Hn(s,e){return s[0]==="pt"?0:1}Zs=Hn(k),ks=Qa[Zs]=Fn[Zs](k),el=new tl({props:{$$slots:{default:[xM]},$$scope:{ctx:k}}}),wa=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 F=k[0]==="pt"&&iM();const Dn=[WM,$M],Sa=[];function Ln(s,e){return s[0]==="pt"?0:1}Gs=Ln(k),vs=Sa[Gs]=Dn[Gs](k),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:"JTdCJ2F0dGVudGlvbl9tYXNrJyUzQSUyMHRlbnNvciglNUIlNUIxJTJDJTIwMSUyQyUyMDElMkMlMjAxJTJDJTIwMSUyQyUyMDElMkMlMjAxJTJDJTIwMSUyQyUyMDElMkMlMjAxJTJDJTIwMSUyQyUyMDElMkMlMjAxJTJDJTIwMSUyQyUyMDElMkMlMjAxJTJDJTIwMSUyQyUyMDElMkMlMjAxJTJDJTIwMSUyQyUyMDElMkMlMjAxJTJDJTIwMSUyQyUyMDElMkMlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAxJTJDJTIwMSUyQyUyMDElMkMlMjAxJTJDJTIwMSUyQyUyMDAlMkMlMjAwJTJDJTIwMCUyQyUyMDAlMkMlMjAwJTJDJTIwMCU1RCUyQyUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCU1QjElMkMlMjAxJTJDJTIwMSUyQyUyMDElMkMlMjAxJTJDJTIwMSUyQyUyMDElMkMlMjAxJTJDJTIwMSUyQyUyMDElMkMlMjAxJTJDJTIwMSUyQyUyMDElMkMlMjAxJTJDJTIwMSUyQyUyMDElMkMlMjAxJTJDJTIwMSUyQyUyMDElMkMlMjAxJTJDJTIwMSUyQyUyMDElMkMlMjAxJTJDJTIwMSUyQyUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMDElMkMlMjAxJTJDJTIwMSUyQyUyMDElMkMlMjAxJTJDJTIwMSUyQyUyMDElMkMlMjAxJTJDJTIwMSUyQyUyMDElMkMlMjAxJTVEJTVEKSUyQyUyMCdpbnB1dF9pZHMnJTNBJTIwdGVuc29yKCU1QiU1QiUyMCUyMDE0OTQlMkMlMjAlMjAlMjAlMjAyNTklMkMlMjAlMjAlMjA4NjIyJTJDJTIwJTIwJTIwJTIwMzkwJTJDJTIwJTIwJTIwJTIwMjU5JTJDJTIwJTIwJTIwJTIwMjYyJTJDJTIwJTIwJTIwMjMxNiUyQyUyMCUyMCUyMDM0MzUlMkMlMjAlMjAlMjAlMjA5NTUlMkMlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjA3NzIlMkMlMjAlMjAlMjAlMjAyODElMkMlMjAlMjAlMjAlMjA3NzIlMkMlMjAlMjAlMjAxNjE3JTJDJTIwJTIwJTIwJTIwMjYzJTJDJTIwJTIwJTIwJTIwMzA1JTJDJTIwJTIwMTQ3MDElMkMlMjAlMjAlMjAlMjAyNjAlMkMlMjAlMjAlMjAxMzg1JTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwMzAzMSUyQyUyMCUyMCUyMCUyMDI1OSUyQyUyMCUyMDI0MTQ2JTJDJTIwJTIwJTIwJTIwMzMyJTJDJTIwJTIwJTIwMTAzNyUyQyUyMCUyMCUyMCUyMDI1OSUyQyUyMCUyMDQzOTA2JTJDJTIwJTIwJTIwJTIwMzA1JTJDJTIwJTIwJTIwJTIwMzM2JTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwMjYwJTJDJTIwJTIwJTIwJTIwJTIwJTIwMSUyQyUyMCUyMCUyMCUyMCUyMCUyMDAlMkMlMjAlMjAlMjAlMjAlMjAlMjAwJTJDJTIwJTIwJTIwJTIwJTIwJTIwMCUyQyUyMCUyMCUyMCUyMCUyMCUyMDAlMkMlMjAlMjAlMjAlMjAlMjAlMjAwJTJDJTIwJTIwJTIwJTIwJTIwJTIwMCU1RCUyQyUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCU1QiUyMCUyMCUyMDI1OSUyQyUyMCUyMDI3NTMxJTJDJTIwJTIwMTM0ODMlMkMlMjAlMjAlMjAlMjAyNTklMkMlMjAlMjAlMjA3NTA1JTJDJTIwJTIwJTIwJTIwMjYwJTJDJTIwMTEyMjQwJTJDJTIwJTIwMTUxOTIlMkMlMjAlMjAlMjAlMjAzMDUlMkMlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjA1MzE5OCUyQyUyMCUyMCUyMCUyMDI3NiUyQyUyMCUyMCUyMCUyMDI1OSUyQyUyMCUyMDc0MDYwJTJDJTIwJTIwJTIwJTIwMjYzJTJDJTIwJTIwJTIwJTIwMjYwJTJDJTIwJTIwJTIwJTIwNDU5JTJDJTIwJTIwMjU2NDAlMkMlMjAlMjAlMjAlMjA3NzYlMkMlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAyMTE5JTJDJTIwJTIwJTIwJTIwMzM2JTJDJTIwJTIwJTIwJTIwMjU5JTJDJTIwJTIwJTIwMjIyMCUyQyUyMCUyMCUyMCUyMDI1OSUyQyUyMCUyMDE4ODk2JTJDJTIwJTIwJTIwJTIwMjg4JTJDJTIwJTIwJTIwNDkwNiUyQyUyMCUyMCUyMCUyMDI4OCUyQyUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMDEwMzclMkMlMjAlMjAlMjAzOTMxJTJDJTIwJTIwJTIwJTIwMjYwJTJDJTIwJTIwJTIwNzA4MyUyQyUyMDEwMTQ3NiUyQyUyMCUyMCUyMDExNDMlMkMlMjAlMjAlMjAlMjAyNjAlMkMlMjAlMjAlMjAlMjAlMjAlMjAxJTVEJTVEKSUyQyUyMCdsYWJlbHMnJTNBJTIwdGVuc29yKCU1QiU1QiUyMDc0ODMlMkMlMjAlMjAlMjAyNTklMkMlMjAlMjAyMzY0JTJDJTIwMTU2OTUlMkMlMjAlMjAlMjAlMjAlMjAxJTJDJTIwJTIwLTEwMCU1RCUyQyUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCU1QiUyMCUyMDI1OSUyQyUyMDI3NTMxJTJDJTIwMTM0ODMlMkMlMjAlMjAlMjAyNTklMkMlMjAlMjA3NTA1JTJDJTIwJTIwJTIwJTIwJTIwMSU1RCU1RCklMkMlMjAnZGVjb2Rlcl9pbnB1dF9pZHMnJTNBJTIwdGVuc29yKCU1QiU1QiUyMCUyMCUyMCUyMDAlMkMlMjAlMjA3NDgzJTJDJTIwJTIwJTIwMjU5JTJDJTIwJTIwMjM2NCUyQyUyMDE1Njk1JTJDJTIwJTIwJTIwJTIwJTIwMSU1RCUyQyUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCU1QiUyMCUyMCUyMCUyMDAlMkMlMjAlMjAlMjAyNTklMkMlMjAyNzUzMSUyQyUyMDEzNDgzJTJDJTIwJTIwJTIwMjU5JTJDJTIwJTIwNzUwNSU1RCU1RCklN0Q=",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 qn=[VM,_M],Ea=[];function Kn(s,e){return s[0]==="pt"?0:1}Bs=Kn(k),xs=Ea[Bs]=qn[Bs](k);let H=k[0]==="pt"&&yM(k);return ka=new gs({props:{title:"使用您微調的模型",local:"使用您微調的模型",headingTag:"h2"}}),va=new d({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMHBpcGVsaW5lJTBBJTBBaHViX21vZGVsX2lkJTIwJTNEJTIwJTIyaHVnZ2luZ2ZhY2UtY291cnNlJTJGbXQ1LXNtYWxsLWZpbmV0dW5lZC1hbWF6b24tZW4tZXMlMjIlMEFzdW1tYXJpemVyJTIwJTNEJTIwcGlwZWxpbmUoJTIyc3VtbWFyaXphdGlvbiUyMiUyQyUyMG1vZGVsJTNEaHViX21vZGVsX2lkKQ==",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> pipeline

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

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

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

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

<span class="hljs-string">&#x27;&gt;&gt;&gt; Summary: Muy facil de leer&#x27;</span>`,wrap:!1}}),za=new uM({props:{source:"https://github.com/huggingface/course/blob/main/chapters/zh-TW/chapter7/5.mdx"}}),{c(){p=y("meta"),u=n(),r=y("p"),f=n(),c(G.$$.fragment),g=n(),c(_.$$.fragment),I=n(),N.c(),v=n(),z=y("p"),z.textContent=S,X=n(),c(R.$$.fragment),W=n(),C=y("p"),C.innerHTML=B,D=n(),A=y("iframe"),K=n(),$=y("iframe"),E=n(),Q=y("p"),Q.textContent=P,j=n(),c(x.$$.fragment),ms=n(),h=y("p"),h.innerHTML=V,Js=n(),c(cs.$$.fragment),Ts=n(),c($s.$$.fragment),As=n(),O=y("p"),O.innerHTML=ae,zs=n(),c(ss.$$.fragment),Ml=n(),c(os.$$.fragment),Us=n(),c(is.$$.fragment),ws=n(),Ws=y("p"),Ws.innerHTML=pl,js=n(),c(hs.$$.fragment),ds=n(),c(_s.$$.fragment),Ys=n(),ls=y("p"),ls.innerHTML=ee,Qs=n(),c(as.$$.fragment),Ss=n(),es=y("p"),es.innerHTML=rl,us=n(),c(Vs.$$.fragment),Es=n(),ts=y("p"),ts.textContent=ml,bs=n(),c(Rs.$$.fragment),Fs=n(),c(ns.$$.fragment),Hs=n(),Ms=y("p"),Ms.innerHTML=te,Ds=n(),c(ps.$$.fragment),il=n(),c(Is.$$.fragment),fs=n(),Ns=y("p"),Ns.textContent=yl,Cs=n(),ys=y("div"),ys.innerHTML=Xs,Ls=n(),rs=y("p"),rs.innerHTML=ne,qs=n(),c(t.$$.fragment),b=n(),Jl=y("p"),Jl.textContent=sn,pe=n(),c(cl.$$.fragment),re=n(),Tl=y("p"),Tl.innerHTML=ln,me=n(),ol=y("table"),ol.innerHTML=an,ie=n(),Ul=y("p"),Ul.textContent=en,ye=n(),wl=y("p"),wl.innerHTML=tn,Je=n(),Ks=y("div"),Ks.innerHTML=nn,ce=n(),jl=y("p"),jl.textContent=Mn,Te=n(),c(Ps.$$.fragment),oe=n(),c(hl.$$.fragment),Ue=n(),c(dl.$$.fragment),we=n(),ul=y("p"),ul.innerHTML=pn,je=n(),c(bl.$$.fragment),he=n(),c(Os.$$.fragment),de=n(),Il=y("p"),Il.textContent=rn,ue=n(),c(fl.$$.fragment),be=n(),c(Cl.$$.fragment),Ie=n(),gl=y("p"),gl.innerHTML=mn,fe=n(),c(Zl.$$.fragment),Ce=n(),c(kl.$$.fragment),ge=n(),Gl=y("p"),Gl.innerHTML=yn,Ze=n(),vl=y("p"),vl.innerHTML=Jn,ke=n(),c(Bl.$$.fragment),Ge=n(),xl=y("p"),xl.innerHTML=cn,ve=n(),$l=y("p"),$l.innerHTML=Tn,Be=n(),c(Wl.$$.fragment),xe=n(),_l=y("p"),_l.textContent=on,$e=n(),c(sl.$$.fragment),We=n(),c(Vl.$$.fragment),_e=n(),c(Rl.$$.fragment),Ve=n(),Nl=y("p"),Nl.textContent=Un,Re=n(),Xl=y("p"),Xl.innerHTML=wn,Ne=n(),c(Al.$$.fragment),Xe=n(),zl=y("p"),zl.innerHTML=jn,Ae=n(),c(ll.$$.fragment),ze=n(),Yl=y("p"),Ht=MM(`對於 ROUGE，recall 衡量生成的參考摘要包含了多少參考摘要。如果我們只是比較單詞，recall可以根據以下公式計算：
`),Ye=new pM(!1),Qe=n(),Ql=y("p"),Dt=MM(`對於我們上面的簡單例子，這個公式給出了 6/6 = 1 的完美召回率；即，參考摘要中的所有單詞都已由模型生成。這聽起來可能很棒，但想象一下，如果我們生成的摘要是“我真的很喜歡整晚閱讀飢餓遊戲”。這也將有完美的recall，但可以說是一個更糟糕的總結，因為它很冗長。為了處理這些場景，我們還計算了pecision，它在 ROUGE 上下文中衡量生成的摘要中有多少是相關的：
`),Se=new pM(!1),Ee=n(),Sl=y("p"),Sl.innerHTML=hn,Fe=n(),c(El.$$.fragment),He=n(),Fl=y("p"),Fl.textContent=dn,De=n(),c(Hl.$$.fragment),Le=n(),Dl=y("p"),Dl.innerHTML=un,qe=n(),c(Ll.$$.fragment),Ke=n(),c(ql.$$.fragment),Pe=n(),Kl=y("p"),Kl.innerHTML=bn,Oe=n(),c(Pl.$$.fragment),st=n(),c(Ol.$$.fragment),lt=n(),sa=y("p"),sa.innerHTML=In,at=n(),c(al.$$.fragment),et=n(),la=y("p"),la.textContent=fn,tt=n(),c(aa.$$.fragment),nt=n(),ea=y("p"),ea.innerHTML=Cn,Mt=n(),c(ta.$$.fragment),pt=n(),na=y("p"),na.textContent=gn,rt=n(),c(Ma.$$.fragment),mt=n(),pa=y("p"),pa.innerHTML=Zn,it=n(),c(ra.$$.fragment),yt=n(),c(ma.$$.fragment),Jt=n(),ia=y("p"),ia.textContent=kn,ct=n(),c(ya.$$.fragment),Tt=n(),Ja=y("p"),Ja.textContent=Gn,ot=n(),c(ca.$$.fragment),Ut=n(),c(Ta.$$.fragment),wt=n(),oa=y("p"),oa.innerHTML=vn,jt=n(),ks.c(),Ha=n(),c(el.$$.fragment),ht=n(),Ua=y("p"),Ua.textContent=Bn,dt=n(),c(wa.$$.fragment),ut=n(),ja=y("p"),ja.textContent=xn,bt=n(),c(ha.$$.fragment),It=n(),F&&F.c(),Da=n(),da=y("p"),da.innerHTML=$n,ft=n(),ua=y("p"),ua.innerHTML=Wn,Ct=n(),vs.c(),La=n(),ba=y("p"),ba.textContent=_n,gt=n(),c(Ia.$$.fragment),Zt=n(),fa=y("p"),fa.innerHTML=Vn,kt=n(),c(Ca.$$.fragment),Gt=n(),c(ga.$$.fragment),vt=n(),Za=y("p"),Za.innerHTML=Rn,Bt=n(),xs.c(),qa=n(),H&&H.c(),Ka=n(),c(ka.$$.fragment),xt=n(),Ga=y("p"),Ga.textContent=Nn,$t=n(),c(va.$$.fragment),Wt=n(),Ba=y("p"),Ba.textContent=Xn,_t=n(),c(xa.$$.fragment),Vt=n(),$a=y("p"),$a.textContent=An,Rt=n(),c(Wa.$$.fragment),Nt=n(),c(_a.$$.fragment),Xt=n(),Va=y("p"),Va.textContent=zn,At=n(),c(Ra.$$.fragment),zt=n(),c(Na.$$.fragment),Yt=n(),Xa=y("p"),Xa.textContent=Yn,Qt=n(),Aa=y("p"),Aa.textContent=Qn,St=n(),c(za.$$.fragment),Et=n(),Me=y("p"),this.h()},l(s){const e=hM("svelte-u9bgzb",document.head);p=J(e,"META",{name:!0,content:!0}),e.forEach(l),u=M(s),r=J(s,"P",{}),Oa(r).forEach(l),f=M(s),T(G.$$.fragment,s),g=M(s),T(_.$$.fragment,s),I=M(s),N.l(s),v=M(s),z=J(s,"P",{"data-svelte-h":!0}),w(z)!=="svelte-19rxt6u"&&(z.textContent=S),X=M(s),T(R.$$.fragment,s),W=M(s),C=J(s,"P",{"data-svelte-h":!0}),w(C)!=="svelte-1oslg25"&&(C.innerHTML=B),D=M(s),A=J(s,"IFRAME",{src:!0,frameborder:!0,height:!0,title:!0,class:!0,allow:!0,sandbox:!0}),Oa(A).forEach(l),K=M(s),$=J(s,"IFRAME",{src:!0,frameborder:!0,height:!0,title:!0,class:!0,allow:!0,sandbox:!0}),Oa($).forEach(l),E=M(s),Q=J(s,"P",{"data-svelte-h":!0}),w(Q)!=="svelte-1mp60xs"&&(Q.textContent=P),j=M(s),T(x.$$.fragment,s),ms=M(s),h=J(s,"P",{"data-svelte-h":!0}),w(h)!=="svelte-iqutbd"&&(h.innerHTML=V),Js=M(s),T(cs.$$.fragment,s),Ts=M(s),T($s.$$.fragment,s),As=M(s),O=J(s,"P",{"data-svelte-h":!0}),w(O)!=="svelte-1ad4cuj"&&(O.innerHTML=ae),zs=M(s),T(ss.$$.fragment,s),Ml=M(s),T(os.$$.fragment,s),Us=M(s),T(is.$$.fragment,s),ws=M(s),Ws=J(s,"P",{"data-svelte-h":!0}),w(Ws)!=="svelte-18zemtu"&&(Ws.innerHTML=pl),js=M(s),T(hs.$$.fragment,s),ds=M(s),T(_s.$$.fragment,s),Ys=M(s),ls=J(s,"P",{"data-svelte-h":!0}),w(ls)!=="svelte-pylu96"&&(ls.innerHTML=ee),Qs=M(s),T(as.$$.fragment,s),Ss=M(s),es=J(s,"P",{"data-svelte-h":!0}),w(es)!=="svelte-14rncl5"&&(es.innerHTML=rl),us=M(s),T(Vs.$$.fragment,s),Es=M(s),ts=J(s,"P",{"data-svelte-h":!0}),w(ts)!=="svelte-1sksjg"&&(ts.textContent=ml),bs=M(s),T(Rs.$$.fragment,s),Fs=M(s),T(ns.$$.fragment,s),Hs=M(s),Ms=J(s,"P",{"data-svelte-h":!0}),w(Ms)!=="svelte-9lfxiy"&&(Ms.innerHTML=te),Ds=M(s),T(ps.$$.fragment,s),il=M(s),T(Is.$$.fragment,s),fs=M(s),Ns=J(s,"P",{"data-svelte-h":!0}),w(Ns)!=="svelte-158xy6s"&&(Ns.textContent=yl),Cs=M(s),ys=J(s,"DIV",{class:!0,"data-svelte-h":!0}),w(ys)!=="svelte-1pwnbfd"&&(ys.innerHTML=Xs),Ls=M(s),rs=J(s,"P",{"data-svelte-h":!0}),w(rs)!=="svelte-w38ny3"&&(rs.innerHTML=ne),qs=M(s),T(t.$$.fragment,s),b=M(s),Jl=J(s,"P",{"data-svelte-h":!0}),w(Jl)!=="svelte-1qh2yc1"&&(Jl.textContent=sn),pe=M(s),T(cl.$$.fragment,s),re=M(s),Tl=J(s,"P",{"data-svelte-h":!0}),w(Tl)!=="svelte-1yg4ppq"&&(Tl.innerHTML=ln),me=M(s),ol=J(s,"TABLE",{"data-svelte-h":!0}),w(ol)!=="svelte-du121x"&&(ol.innerHTML=an),ie=M(s),Ul=J(s,"P",{"data-svelte-h":!0}),w(Ul)!=="svelte-1m6yd2o"&&(Ul.textContent=en),ye=M(s),wl=J(s,"P",{"data-svelte-h":!0}),w(wl)!=="svelte-9k2jla"&&(wl.innerHTML=tn),Je=M(s),Ks=J(s,"DIV",{class:!0,"data-svelte-h":!0}),w(Ks)!=="svelte-k7lnur"&&(Ks.innerHTML=nn),ce=M(s),jl=J(s,"P",{"data-svelte-h":!0}),w(jl)!=="svelte-d4pwwt"&&(jl.textContent=Mn),Te=M(s),T(Ps.$$.fragment,s),oe=M(s),T(hl.$$.fragment,s),Ue=M(s),T(dl.$$.fragment,s),we=M(s),ul=J(s,"P",{"data-svelte-h":!0}),w(ul)!=="svelte-15tecul"&&(ul.innerHTML=pn),je=M(s),T(bl.$$.fragment,s),he=M(s),T(Os.$$.fragment,s),de=M(s),Il=J(s,"P",{"data-svelte-h":!0}),w(Il)!=="svelte-13rekop"&&(Il.textContent=rn),ue=M(s),T(fl.$$.fragment,s),be=M(s),T(Cl.$$.fragment,s),Ie=M(s),gl=J(s,"P",{"data-svelte-h":!0}),w(gl)!=="svelte-15k723b"&&(gl.innerHTML=mn),fe=M(s),T(Zl.$$.fragment,s),Ce=M(s),T(kl.$$.fragment,s),ge=M(s),Gl=J(s,"P",{"data-svelte-h":!0}),w(Gl)!=="svelte-1dmk4g6"&&(Gl.innerHTML=yn),Ze=M(s),vl=J(s,"P",{"data-svelte-h":!0}),w(vl)!=="svelte-14xuy3i"&&(vl.innerHTML=Jn),ke=M(s),T(Bl.$$.fragment,s),Ge=M(s),xl=J(s,"P",{"data-svelte-h":!0}),w(xl)!=="svelte-1a5w1mm"&&(xl.innerHTML=cn),ve=M(s),$l=J(s,"P",{"data-svelte-h":!0}),w($l)!=="svelte-g594qb"&&($l.innerHTML=Tn),Be=M(s),T(Wl.$$.fragment,s),xe=M(s),_l=J(s,"P",{"data-svelte-h":!0}),w(_l)!=="svelte-1ya70qk"&&(_l.textContent=on),$e=M(s),T(sl.$$.fragment,s),We=M(s),T(Vl.$$.fragment,s),_e=M(s),T(Rl.$$.fragment,s),Ve=M(s),Nl=J(s,"P",{"data-svelte-h":!0}),w(Nl)!=="svelte-rmkt8r"&&(Nl.textContent=Un),Re=M(s),Xl=J(s,"P",{"data-svelte-h":!0}),w(Xl)!=="svelte-46mqaz"&&(Xl.innerHTML=wn),Ne=M(s),T(Al.$$.fragment,s),Xe=M(s),zl=J(s,"P",{"data-svelte-h":!0}),w(zl)!=="svelte-1j6b4e1"&&(zl.innerHTML=jn),Ae=M(s),T(ll.$$.fragment,s),ze=M(s),Yl=J(s,"P",{});var Pa=Oa(Yl);Ht=rM(Pa,`對於 ROUGE，recall 衡量生成的參考摘要包含了多少參考摘要。如果我們只是比較單詞，recall可以根據以下公式計算：
`),Ye=mM(Pa,!1),Pa.forEach(l),Qe=M(s),Ql=J(s,"P",{});var Fa=Oa(Ql);Dt=rM(Fa,`對於我們上面的簡單例子，這個公式給出了 6/6 = 1 的完美召回率；即，參考摘要中的所有單詞都已由模型生成。這聽起來可能很棒，但想象一下，如果我們生成的摘要是“我真的很喜歡整晚閱讀飢餓遊戲”。這也將有完美的recall，但可以說是一個更糟糕的總結，因為它很冗長。為了處理這些場景，我們還計算了pecision，它在 ROUGE 上下文中衡量生成的摘要中有多少是相關的：
`),Se=mM(Fa,!1),Fa.forEach(l),Ee=M(s),Sl=J(s,"P",{"data-svelte-h":!0}),w(Sl)!=="svelte-1y1wy0n"&&(Sl.innerHTML=hn),Fe=M(s),T(El.$$.fragment,s),He=M(s),Fl=J(s,"P",{"data-svelte-h":!0}),w(Fl)!=="svelte-1an8p6d"&&(Fl.textContent=dn),De=M(s),T(Hl.$$.fragment,s),Le=M(s),Dl=J(s,"P",{"data-svelte-h":!0}),w(Dl)!=="svelte-w10v88"&&(Dl.innerHTML=un),qe=M(s),T(Ll.$$.fragment,s),Ke=M(s),T(ql.$$.fragment,s),Pe=M(s),Kl=J(s,"P",{"data-svelte-h":!0}),w(Kl)!=="svelte-14liyx0"&&(Kl.innerHTML=bn),Oe=M(s),T(Pl.$$.fragment,s),st=M(s),T(Ol.$$.fragment,s),lt=M(s),sa=J(s,"P",{"data-svelte-h":!0}),w(sa)!=="svelte-ih9agl"&&(sa.innerHTML=In),at=M(s),T(al.$$.fragment,s),et=M(s),la=J(s,"P",{"data-svelte-h":!0}),w(la)!=="svelte-99pum5"&&(la.textContent=fn),tt=M(s),T(aa.$$.fragment,s),nt=M(s),ea=J(s,"P",{"data-svelte-h":!0}),w(ea)!=="svelte-151fi9y"&&(ea.innerHTML=Cn),Mt=M(s),T(ta.$$.fragment,s),pt=M(s),na=J(s,"P",{"data-svelte-h":!0}),w(na)!=="svelte-zy89wf"&&(na.textContent=gn),rt=M(s),T(Ma.$$.fragment,s),mt=M(s),pa=J(s,"P",{"data-svelte-h":!0}),w(pa)!=="svelte-3nsd4c"&&(pa.innerHTML=Zn),it=M(s),T(ra.$$.fragment,s),yt=M(s),T(ma.$$.fragment,s),Jt=M(s),ia=J(s,"P",{"data-svelte-h":!0}),w(ia)!=="svelte-1ot0nfj"&&(ia.textContent=kn),ct=M(s),T(ya.$$.fragment,s),Tt=M(s),Ja=J(s,"P",{"data-svelte-h":!0}),w(Ja)!=="svelte-f11201"&&(Ja.textContent=Gn),ot=M(s),T(ca.$$.fragment,s),Ut=M(s),T(Ta.$$.fragment,s),wt=M(s),oa=J(s,"P",{"data-svelte-h":!0}),w(oa)!=="svelte-1ur5vss"&&(oa.innerHTML=vn),jt=M(s),ks.l(s),Ha=M(s),T(el.$$.fragment,s),ht=M(s),Ua=J(s,"P",{"data-svelte-h":!0}),w(Ua)!=="svelte-vzo7vx"&&(Ua.textContent=Bn),dt=M(s),T(wa.$$.fragment,s),ut=M(s),ja=J(s,"P",{"data-svelte-h":!0}),w(ja)!=="svelte-1l0n5g4"&&(ja.textContent=xn),bt=M(s),T(ha.$$.fragment,s),It=M(s),F&&F.l(s),Da=M(s),da=J(s,"P",{"data-svelte-h":!0}),w(da)!=="svelte-hb45we"&&(da.innerHTML=$n),ft=M(s),ua=J(s,"P",{"data-svelte-h":!0}),w(ua)!=="svelte-1exrf4x"&&(ua.innerHTML=Wn),Ct=M(s),vs.l(s),La=M(s),ba=J(s,"P",{"data-svelte-h":!0}),w(ba)!=="svelte-1vpbjmc"&&(ba.textContent=_n),gt=M(s),T(Ia.$$.fragment,s),Zt=M(s),fa=J(s,"P",{"data-svelte-h":!0}),w(fa)!=="svelte-1cjqhvx"&&(fa.innerHTML=Vn),kt=M(s),T(Ca.$$.fragment,s),Gt=M(s),T(ga.$$.fragment,s),vt=M(s),Za=J(s,"P",{"data-svelte-h":!0}),w(Za)!=="svelte-p2m34e"&&(Za.innerHTML=Rn),Bt=M(s),xs.l(s),qa=M(s),H&&H.l(s),Ka=M(s),T(ka.$$.fragment,s),xt=M(s),Ga=J(s,"P",{"data-svelte-h":!0}),w(Ga)!=="svelte-1gond6a"&&(Ga.textContent=Nn),$t=M(s),T(va.$$.fragment,s),Wt=M(s),Ba=J(s,"P",{"data-svelte-h":!0}),w(Ba)!=="svelte-1po5f75"&&(Ba.textContent=Xn),_t=M(s),T(xa.$$.fragment,s),Vt=M(s),$a=J(s,"P",{"data-svelte-h":!0}),w($a)!=="svelte-1tt494o"&&($a.textContent=An),Rt=M(s),T(Wa.$$.fragment,s),Nt=M(s),T(_a.$$.fragment,s),Xt=M(s),Va=J(s,"P",{"data-svelte-h":!0}),w(Va)!=="svelte-h36ly9"&&(Va.textContent=zn),At=M(s),T(Ra.$$.fragment,s),zt=M(s),T(Na.$$.fragment,s),Yt=M(s),Xa=J(s,"P",{"data-svelte-h":!0}),w(Xa)!=="svelte-1axhtkv"&&(Xa.textContent=Yn),Qt=M(s),Aa=J(s,"P",{"data-svelte-h":!0}),w(Aa)!=="svelte-ybbmy9"&&(Aa.textContent=Qn),St=M(s),T(za.$$.fragment,s),Et=M(s),Me=J(s,"P",{}),Oa(Me).forEach(l),this.h()},h(){q(p,"name","hf:doc:metadata"),q(p,"content",XM),nM(A.src,Y="https://course-demos-mt5-small-finetuned-amazon-en-es.hf.space")||q(A,"src",Y),q(A,"frameborder","0"),q(A,"height","400"),q(A,"title","Gradio app"),q(A,"class","block dark:hidden container p-0 flex-grow space-iframe"),q(A,"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"),q(A,"sandbox","allow-forms allow-modals allow-popups allow-popups-to-escape-sandbox allow-same-origin allow-scripts allow-downloads"),nM($.src,L="https://course-demos-mt5-small-finetuned-amazon-en-es-darkmode.hf.space")||q($,"src",L),q($,"frameborder","0"),q($,"height","400"),q($,"title","Gradio app"),q($,"class","hidden dark:block container p-0 flex-grow space-iframe"),q($,"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"),q($,"sandbox","allow-forms allow-modals allow-popups allow-popups-to-escape-sandbox allow-same-origin allow-scripts allow-downloads"),q(ys,"class","flex justify-center"),q(Ks,"class","flex justify-center"),Ye.a=null,Se.a=null},m(s,e){Pt(document.head,p),a(s,u,e),a(s,r,e),a(s,f,e),o(G,s,e),a(s,g,e),o(_,s,e),a(s,I,e),Ya[Z].m(s,e),a(s,v,e),a(s,z,e),a(s,X,e),o(R,s,e),a(s,W,e),a(s,C,e),a(s,D,e),a(s,A,e),a(s,K,e),a(s,$,e),a(s,E,e),a(s,Q,e),a(s,j,e),o(x,s,e),a(s,ms,e),a(s,h,e),a(s,Js,e),o(cs,s,e),a(s,Ts,e),o($s,s,e),a(s,As,e),a(s,O,e),a(s,zs,e),o(ss,s,e),a(s,Ml,e),o(os,s,e),a(s,Us,e),o(is,s,e),a(s,ws,e),a(s,Ws,e),a(s,js,e),o(hs,s,e),a(s,ds,e),o(_s,s,e),a(s,Ys,e),a(s,ls,e),a(s,Qs,e),o(as,s,e),a(s,Ss,e),a(s,es,e),a(s,us,e),o(Vs,s,e),a(s,Es,e),a(s,ts,e),a(s,bs,e),o(Rs,s,e),a(s,Fs,e),o(ns,s,e),a(s,Hs,e),a(s,Ms,e),a(s,Ds,e),o(ps,s,e),a(s,il,e),o(Is,s,e),a(s,fs,e),a(s,Ns,e),a(s,Cs,e),a(s,ys,e),a(s,Ls,e),a(s,rs,e),a(s,qs,e),o(t,s,e),a(s,b,e),a(s,Jl,e),a(s,pe,e),o(cl,s,e),a(s,re,e),a(s,Tl,e),a(s,me,e),a(s,ol,e),a(s,ie,e),a(s,Ul,e),a(s,ye,e),a(s,wl,e),a(s,Je,e),a(s,Ks,e),a(s,ce,e),a(s,jl,e),a(s,Te,e),o(Ps,s,e),a(s,oe,e),o(hl,s,e),a(s,Ue,e),o(dl,s,e),a(s,we,e),a(s,ul,e),a(s,je,e),o(bl,s,e),a(s,he,e),o(Os,s,e),a(s,de,e),a(s,Il,e),a(s,ue,e),o(fl,s,e),a(s,be,e),o(Cl,s,e),a(s,Ie,e),a(s,gl,e),a(s,fe,e),o(Zl,s,e),a(s,Ce,e),o(kl,s,e),a(s,ge,e),a(s,Gl,e),a(s,Ze,e),a(s,vl,e),a(s,ke,e),o(Bl,s,e),a(s,Ge,e),a(s,xl,e),a(s,ve,e),a(s,$l,e),a(s,Be,e),o(Wl,s,e),a(s,xe,e),a(s,_l,e),a(s,$e,e),o(sl,s,e),a(s,We,e),o(Vl,s,e),a(s,_e,e),o(Rl,s,e),a(s,Ve,e),a(s,Nl,e),a(s,Re,e),a(s,Xl,e),a(s,Ne,e),o(Al,s,e),a(s,Xe,e),a(s,zl,e),a(s,Ae,e),o(ll,s,e),a(s,ze,e),a(s,Yl,e),Pt(Yl,Ht),Ye.m(cM,Yl),a(s,Qe,e),a(s,Ql,e),Pt(Ql,Dt),Se.m(TM,Ql),a(s,Ee,e),a(s,Sl,e),a(s,Fe,e),o(El,s,e),a(s,He,e),a(s,Fl,e),a(s,De,e),o(Hl,s,e),a(s,Le,e),a(s,Dl,e),a(s,qe,e),o(Ll,s,e),a(s,Ke,e),o(ql,s,e),a(s,Pe,e),a(s,Kl,e),a(s,Oe,e),o(Pl,s,e),a(s,st,e),o(Ol,s,e),a(s,lt,e),a(s,sa,e),a(s,at,e),o(al,s,e),a(s,et,e),a(s,la,e),a(s,tt,e),o(aa,s,e),a(s,nt,e),a(s,ea,e),a(s,Mt,e),o(ta,s,e),a(s,pt,e),a(s,na,e),a(s,rt,e),o(Ma,s,e),a(s,mt,e),a(s,pa,e),a(s,it,e),o(ra,s,e),a(s,yt,e),o(ma,s,e),a(s,Jt,e),a(s,ia,e),a(s,ct,e),o(ya,s,e),a(s,Tt,e),a(s,Ja,e),a(s,ot,e),o(ca,s,e),a(s,Ut,e),o(Ta,s,e),a(s,wt,e),a(s,oa,e),a(s,jt,e),Qa[Zs].m(s,e),a(s,Ha,e),o(el,s,e),a(s,ht,e),a(s,Ua,e),a(s,dt,e),o(wa,s,e),a(s,ut,e),a(s,ja,e),a(s,bt,e),o(ha,s,e),a(s,It,e),F&&F.m(s,e),a(s,Da,e),a(s,da,e),a(s,ft,e),a(s,ua,e),a(s,Ct,e),Sa[Gs].m(s,e),a(s,La,e),a(s,ba,e),a(s,gt,e),o(Ia,s,e),a(s,Zt,e),a(s,fa,e),a(s,kt,e),o(Ca,s,e),a(s,Gt,e),o(ga,s,e),a(s,vt,e),a(s,Za,e),a(s,Bt,e),Ea[Bs].m(s,e),a(s,qa,e),H&&H.m(s,e),a(s,Ka,e),o(ka,s,e),a(s,xt,e),a(s,Ga,e),a(s,$t,e),o(va,s,e),a(s,Wt,e),a(s,Ba,e),a(s,_t,e),o(xa,s,e),a(s,Vt,e),a(s,$a,e),a(s,Rt,e),o(Wa,s,e),a(s,Nt,e),o(_a,s,e),a(s,Xt,e),a(s,Va,e),a(s,At,e),o(Ra,s,e),a(s,zt,e),o(Na,s,e),a(s,Yt,e),a(s,Xa,e),a(s,Qt,e),a(s,Aa,e),a(s,St,e),o(za,s,e),a(s,Et,e),a(s,Me,e),Ft=!0},p(s,[e]){const Pa={};e&1&&(Pa.fw=s[0]),G.$set(Pa);let Fa=Z;Z=En(s),Z!==Fa&&(le(),i(Ya[Fa],1,1,()=>{Ya[Fa]=null}),se(),N=Ya[Z],N||(N=Ya[Z]=Sn[Z](s),N.c()),m(N,1),N.m(v.parentNode,v));const Pn={};e&2&&(Pn.$$scope={dirty:e,ctx:s}),is.$set(Pn);const On={};e&2&&(On.$$scope={dirty:e,ctx:s}),Ps.$set(On);const sM={};e&2&&(sM.$$scope={dirty:e,ctx:s}),Os.$set(sM);const lM={};e&2&&(lM.$$scope={dirty:e,ctx:s}),sl.$set(lM);const aM={};e&2&&(aM.$$scope={dirty:e,ctx:s}),ll.$set(aM);const eM={};e&2&&(eM.$$scope={dirty:e,ctx:s}),al.$set(eM);let Lt=Zs;Zs=Hn(s),Zs!==Lt&&(le(),i(Qa[Lt],1,1,()=>{Qa[Lt]=null}),se(),ks=Qa[Zs],ks||(ks=Qa[Zs]=Fn[Zs](s),ks.c()),m(ks,1),ks.m(Ha.parentNode,Ha));const tM={};e&2&&(tM.$$scope={dirty:e,ctx:s}),el.$set(tM),s[0]==="pt"?F?e&1&&m(F,1):(F=iM(),F.c(),m(F,1),F.m(Da.parentNode,Da)):F&&(le(),i(F,1,1,()=>{F=null}),se());let qt=Gs;Gs=Ln(s),Gs!==qt&&(le(),i(Sa[qt],1,1,()=>{Sa[qt]=null}),se(),vs=Sa[Gs],vs||(vs=Sa[Gs]=Dn[Gs](s),vs.c()),m(vs,1),vs.m(La.parentNode,La));let Kt=Bs;Bs=Kn(s),Bs!==Kt&&(le(),i(Ea[Kt],1,1,()=>{Ea[Kt]=null}),se(),xs=Ea[Bs],xs||(xs=Ea[Bs]=qn[Bs](s),xs.c()),m(xs,1),xs.m(qa.parentNode,qa)),s[0]==="pt"?H?e&1&&m(H,1):(H=yM(s),H.c(),m(H,1),H.m(Ka.parentNode,Ka)):H&&(le(),i(H,1,1,()=>{H=null}),se())},i(s){Ft||(m(G.$$.fragment,s),m(_.$$.fragment,s),m(N),m(R.$$.fragment,s),m(x.$$.fragment,s),m(cs.$$.fragment,s),m($s.$$.fragment,s),m(ss.$$.fragment,s),m(os.$$.fragment,s),m(is.$$.fragment,s),m(hs.$$.fragment,s),m(_s.$$.fragment,s),m(as.$$.fragment,s),m(Vs.$$.fragment,s),m(Rs.$$.fragment,s),m(ns.$$.fragment,s),m(ps.$$.fragment,s),m(Is.$$.fragment,s),m(t.$$.fragment,s),m(cl.$$.fragment,s),m(Ps.$$.fragment,s),m(hl.$$.fragment,s),m(dl.$$.fragment,s),m(bl.$$.fragment,s),m(Os.$$.fragment,s),m(fl.$$.fragment,s),m(Cl.$$.fragment,s),m(Zl.$$.fragment,s),m(kl.$$.fragment,s),m(Bl.$$.fragment,s),m(Wl.$$.fragment,s),m(sl.$$.fragment,s),m(Vl.$$.fragment,s),m(Rl.$$.fragment,s),m(Al.$$.fragment,s),m(ll.$$.fragment,s),m(El.$$.fragment,s),m(Hl.$$.fragment,s),m(Ll.$$.fragment,s),m(ql.$$.fragment,s),m(Pl.$$.fragment,s),m(Ol.$$.fragment,s),m(al.$$.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(ks),m(el.$$.fragment,s),m(wa.$$.fragment,s),m(ha.$$.fragment,s),m(F),m(vs),m(Ia.$$.fragment,s),m(Ca.$$.fragment,s),m(ga.$$.fragment,s),m(xs),m(H),m(ka.$$.fragment,s),m(va.$$.fragment,s),m(xa.$$.fragment,s),m(Wa.$$.fragment,s),m(_a.$$.fragment,s),m(Ra.$$.fragment,s),m(Na.$$.fragment,s),m(za.$$.fragment,s),Ft=!0)},o(s){i(G.$$.fragment,s),i(_.$$.fragment,s),i(N),i(R.$$.fragment,s),i(x.$$.fragment,s),i(cs.$$.fragment,s),i($s.$$.fragment,s),i(ss.$$.fragment,s),i(os.$$.fragment,s),i(is.$$.fragment,s),i(hs.$$.fragment,s),i(_s.$$.fragment,s),i(as.$$.fragment,s),i(Vs.$$.fragment,s),i(Rs.$$.fragment,s),i(ns.$$.fragment,s),i(ps.$$.fragment,s),i(Is.$$.fragment,s),i(t.$$.fragment,s),i(cl.$$.fragment,s),i(Ps.$$.fragment,s),i(hl.$$.fragment,s),i(dl.$$.fragment,s),i(bl.$$.fragment,s),i(Os.$$.fragment,s),i(fl.$$.fragment,s),i(Cl.$$.fragment,s),i(Zl.$$.fragment,s),i(kl.$$.fragment,s),i(Bl.$$.fragment,s),i(Wl.$$.fragment,s),i(sl.$$.fragment,s),i(Vl.$$.fragment,s),i(Rl.$$.fragment,s),i(Al.$$.fragment,s),i(ll.$$.fragment,s),i(El.$$.fragment,s),i(Hl.$$.fragment,s),i(Ll.$$.fragment,s),i(ql.$$.fragment,s),i(Pl.$$.fragment,s),i(Ol.$$.fragment,s),i(al.$$.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(ks),i(el.$$.fragment,s),i(wa.$$.fragment,s),i(ha.$$.fragment,s),i(F),i(vs),i(Ia.$$.fragment,s),i(Ca.$$.fragment,s),i(ga.$$.fragment,s),i(xs),i(H),i(ka.$$.fragment,s),i(va.$$.fragment,s),i(xa.$$.fragment,s),i(Wa.$$.fragment,s),i(_a.$$.fragment,s),i(Ra.$$.fragment,s),i(Na.$$.fragment,s),i(za.$$.fragment,s),Ft=!1},d(s){s&&(l(u),l(r),l(f),l(g),l(I),l(v),l(z),l(X),l(W),l(C),l(D),l(A),l(K),l($),l(E),l(Q),l(j),l(ms),l(h),l(Js),l(Ts),l(As),l(O),l(zs),l(Ml),l(Us),l(ws),l(Ws),l(js),l(ds),l(Ys),l(ls),l(Qs),l(Ss),l(es),l(us),l(Es),l(ts),l(bs),l(Fs),l(Hs),l(Ms),l(Ds),l(il),l(fs),l(Ns),l(Cs),l(ys),l(Ls),l(rs),l(qs),l(b),l(Jl),l(pe),l(re),l(Tl),l(me),l(ol),l(ie),l(Ul),l(ye),l(wl),l(Je),l(Ks),l(ce),l(jl),l(Te),l(oe),l(Ue),l(we),l(ul),l(je),l(he),l(de),l(Il),l(ue),l(be),l(Ie),l(gl),l(fe),l(Ce),l(ge),l(Gl),l(Ze),l(vl),l(ke),l(Ge),l(xl),l(ve),l($l),l(Be),l(xe),l(_l),l($e),l(We),l(_e),l(Ve),l(Nl),l(Re),l(Xl),l(Ne),l(Xe),l(zl),l(Ae),l(ze),l(Yl),l(Qe),l(Ql),l(Ee),l(Sl),l(Fe),l(He),l(Fl),l(De),l(Le),l(Dl),l(qe),l(Ke),l(Pe),l(Kl),l(Oe),l(st),l(lt),l(sa),l(at),l(et),l(la),l(tt),l(nt),l(ea),l(Mt),l(pt),l(na),l(rt),l(mt),l(pa),l(it),l(yt),l(Jt),l(ia),l(ct),l(Tt),l(Ja),l(ot),l(Ut),l(wt),l(oa),l(jt),l(Ha),l(ht),l(Ua),l(dt),l(ut),l(ja),l(bt),l(It),l(Da),l(da),l(ft),l(ua),l(Ct),l(La),l(ba),l(gt),l(Zt),l(fa),l(kt),l(Gt),l(vt),l(Za),l(Bt),l(qa),l(Ka),l(xt),l(Ga),l($t),l(Wt),l(Ba),l(_t),l(Vt),l($a),l(Rt),l(Nt),l(Xt),l(Va),l(At),l(zt),l(Yt),l(Xa),l(Qt),l(Aa),l(St),l(Et),l(Me)),l(p),U(G,s),U(_,s),Ya[Z].d(s),U(R,s),U(x,s),U(cs,s),U($s,s),U(ss,s),U(os,s),U(is,s),U(hs,s),U(_s,s),U(as,s),U(Vs,s),U(Rs,s),U(ns,s),U(ps,s),U(Is,s),U(t,s),U(cl,s),U(Ps,s),U(hl,s),U(dl,s),U(bl,s),U(Os,s),U(fl,s),U(Cl,s),U(Zl,s),U(kl,s),U(Bl,s),U(Wl,s),U(sl,s),U(Vl,s),U(Rl,s),U(Al,s),U(ll,s),U(El,s),U(Hl,s),U(Ll,s),U(ql,s),U(Pl,s),U(Ol,s),U(al,s),U(aa,s),U(ta,s),U(Ma,s),U(ra,s),U(ma,s),U(ya,s),U(ca,s),U(Ta,s),Qa[Zs].d(s),U(el,s),U(wa,s),U(ha,s),F&&F.d(s),Sa[Gs].d(s),U(Ia,s),U(Ca,s),U(ga,s),Ea[Bs].d(s),H&&H.d(s),U(ka,s),U(va,s),U(xa,s),U(Wa,s),U(_a,s),U(Ra,s),U(Na,s),U(za,s)}}}const XM='{"title":"提取文本摘要","local":"提取文本摘要","sections":[{"title":"準備多語言語料庫","local":"準備多語言語料庫","sections":[],"depth":2},{"title":"文本摘要模型","local":"文本摘要模型","sections":[],"depth":2},{"title":"預處理數據","local":"預處理數據","sections":[],"depth":2},{"title":"文本摘要的指標","local":"文本摘要的指標","sections":[{"title":"創建強大的baseline","local":"創建強大的baseline","sections":[],"depth":3}],"depth":2},{"title":"使用 Trainer API微調mT5","local":"使用-trainer-api微調mt5","sections":[],"depth":2},{"title":"使用 Keras API微調mT5","local":"使用-keras-api微調mt5","sections":[],"depth":2},{"title":"使用 🤗 Accelerate 微調 mT5","local":"使用--accelerate-微調-mt5","sections":[{"title":"為訓練做好一切準備","local":"為訓練做好一切準備","sections":[],"depth":3},{"title":"訓練循環","local":"訓練循環","sections":[],"depth":3}],"depth":2},{"title":"使用您微調的模型","local":"使用您微調的模型","sections":[],"depth":2}],"depth":1}';function AM(k,p,u){let r="pt";return UM(()=>{const f=new URLSearchParams(window.location.search);u(0,r=f.get("fw")||"pt")}),[r]}class LM extends wM{constructor(p){super(),jM(this,p,AM,NM,oM,{})}}export{LM as component};
