import{s as yM,f as aM,o as JM,n as Hl}from"../chunks/scheduler.37c15a92.js";import{S as rM,i as UM,g as d,s as M,r as o,A as oM,h as m,f as e,c as p,j as za,u as c,x as b,k as v,y as cM,a as t,v as T,t as J,b as kl,d as y,w,p as Rl}from"../chunks/index.2bf4358c.js";import{T as Fl}from"../chunks/Tip.363c041f.js";import{Y as Na}from"../chunks/Youtube.1e50a667.js";import{C as h}from"../chunks/CodeBlock.4e987730.js";import{D as iM}from"../chunks/DocNotebookDropdown.efc1fb7c.js";import{F as TM}from"../chunks/FrameworkSwitchCourse.8d4d4ab6.js";import{H as Sl,E as wM}from"../chunks/getInferenceSnippets.1837c472.js";function dM(I){let a,U;return a=new iM({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/section3_tf.ipynb"},{label:"Aws Studio",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/master/course/chapter7/section3_tf.ipynb"}]}}),{c(){o(a.$$.fragment)},l(n){c(a.$$.fragment,n)},m(n,r){T(a,n,r),U=!0},i(n){U||(y(a.$$.fragment,n),U=!0)},o(n){J(a.$$.fragment,n),U=!1},d(n){w(a,n)}}}function mM(I){let a,U;return a=new iM({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/section3_pt.ipynb"},{label:"Aws Studio",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/master/course/chapter7/section3_pt.ipynb"}]}}),{c(){o(a.$$.fragment)},l(n){c(a.$$.fragment,n)},m(n,r){T(a,n,r),U=!0},i(n){U||(y(a.$$.fragment,n),U=!0)},o(n){J(a.$$.fragment,n),U=!1},d(n){w(a,n)}}}function jM(I){let a,U='🙋 如果您對“掩碼語言建模”和“預訓練模型”這兩個術語感到陌生, 請查看<a href="/course/chapter1">第一章</a>, 我們在其中解釋了所有這些核心概念, 並附有視頻!';return{c(){a=d("p"),a.innerHTML=U},l(n){a=m(n,"P",{"data-svelte-h":!0}),b(a)!=="svelte-1cbbuaw"&&(a.innerHTML=U)},m(n,r){t(n,a,r)},p:Hl,d(n){n&&e(a)}}}function bM(I){let a,U="讓我們繼續, 使用 <code>AutoModelForMaskedLM</code> 類下載 DistilBERT:",n,r,G,j,R="我們可以通過調用  <code>summary()</code> 方法查看模型有多少參數:",W,_,X,k,g;return r=new h({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMFRGQXV0b01vZGVsRm9yTWFza2VkTE0lMEElMEFtb2RlbF9jaGVja3BvaW50JTIwJTNEJTIwJTIyZGlzdGlsYmVydC1iYXNlLXVuY2FzZWQlMjIlMEFtb2RlbCUyMCUzRCUyMFRGQXV0b01vZGVsRm9yTWFza2VkTE0uZnJvbV9wcmV0cmFpbmVkKG1vZGVsX2NoZWNrcG9pbnQp",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> TFAutoModelForMaskedLM

model_checkpoint = <span class="hljs-string">&quot;distilbert-base-uncased&quot;</span>
model = TFAutoModelForMaskedLM.from_pretrained(model_checkpoint)`,wrap:!1}}),_=new h({props:{code:"bW9kZWwobW9kZWwuZHVtbXlfaW5wdXRzKSUyMCUyMCUyMyUyMEJ1aWxkJTIwdGhlJTIwbW9kZWwlMEFtb2RlbC5zdW1tYXJ5KCk=",highlighted:`model(model.dummy_inputs)  <span class="hljs-comment"># Build the model</span>
model.summary()`,wrap:!1}}),k=new h({props:{code:"TW9kZWwlM0ElMjAlMjJ0Zl9kaXN0aWxfYmVydF9mb3JfbWFza2VkX2xtJTIyJTBBX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX18lMEFMYXllciUyMCh0eXBlKSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyME91dHB1dCUyMFNoY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X19fX19fJTBBdm9jYWJfcHJvamVjdG9yJTIwKFRGRGlzdGlsQmVyJTIwbXVsdGlwbGUlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAyMzg2NjE3MCUyMCUyMCUwQSUzRCUzRCUzRCUzRCUzRCUzRCUzRCUzRCUzRCUzRCUzRCUzRCUzRCUzRCUzRCUzRCUzRCUzRCUzRCUzRCUzRCUzRCUzRCUzRCUzRCUzRCUzRCUzRCUzRCUzRCUzRCUzRCUzRCUzRCUzRCUzRCUzRCUzRCUzRCUzRCUzRCUzRCUzRCUzRCUzRCUzRCUzRCUzRCUzRCUzRCUzRCUzRCUzRCUzRCUzRCUzRCUzRCUzRCUzRCUzRCUzRCUzRCUzRCUzRCUzRCUwQVRvdGFsJTIwcGFyYW1zJTNBJTIwNjYlMkM5ODUlMkM1MzAlMEFUcmFpbmFibGUlMjBwYXJhbXMlM0ElMjA2NiUyQzk4NSUyQzUzMCUwQU5vbi10cmFpbmFibGUlMjBwYXJhbXMlM0ElMjAwJTBBX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX18=",highlighted:`Model: <span class="hljs-string">&quot;tf_distil_bert_for_masked_lm&quot;</span>
_________________________________________________________________
Layer (<span class="hljs-built_in">type</span>)                 Output Shape              Param <span class="hljs-comment">#   </span>
=================================================================
distilbert (TFDistilBertMain multiple                  <span class="hljs-number">66362880</span>  
_________________________________________________________________
vocab_transform (Dense)      multiple                  <span class="hljs-number">590592</span>    
_________________________________________________________________
vocab_layer_norm (LayerNorma multiple                  <span class="hljs-number">1536</span>      
_________________________________________________________________
vocab_projector (TFDistilBer multiple                  <span class="hljs-number">23866170</span>  
=================================================================
Total params: <span class="hljs-number">66</span>,<span class="hljs-number">985</span>,<span class="hljs-number">530</span>
Trainable params: <span class="hljs-number">66</span>,<span class="hljs-number">985</span>,<span class="hljs-number">530</span>
Non-trainable params: <span class="hljs-number">0</span>
_________________________________________________________________`,wrap:!1}}),{c(){a=d("p"),a.innerHTML=U,n=M(),o(r.$$.fragment),G=M(),j=d("p"),j.innerHTML=R,W=M(),o(_.$$.fragment),X=M(),o(k.$$.fragment)},l(u){a=m(u,"P",{"data-svelte-h":!0}),b(a)!=="svelte-1xsyw0g"&&(a.innerHTML=U),n=p(u),c(r.$$.fragment,u),G=p(u),j=m(u,"P",{"data-svelte-h":!0}),b(j)!=="svelte-1budijy"&&(j.innerHTML=R),W=p(u),c(_.$$.fragment,u),X=p(u),c(k.$$.fragment,u)},m(u,Z){t(u,a,Z),t(u,n,Z),T(r,u,Z),t(u,G,Z),t(u,j,Z),t(u,W,Z),T(_,u,Z),t(u,X,Z),T(k,u,Z),g=!0},i(u){g||(y(r.$$.fragment,u),y(_.$$.fragment,u),y(k.$$.fragment,u),g=!0)},o(u){J(r.$$.fragment,u),J(_.$$.fragment,u),J(k.$$.fragment,u),g=!1},d(u){u&&(e(a),e(n),e(G),e(j),e(W),e(X)),w(r,u),w(_,u),w(k,u)}}}function uM(I){let a,U="讓我們繼續, 使用 <code>AutoModelForMaskedLM</code> 類下載 DistilBERT:",n,r,G,j,R="我們可以通過調用 <code>num_parameters()</code> 方法查看模型有多少參數:",W,_,X,k,g;return r=new h({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9Nb2RlbEZvck1hc2tlZExNJTBBJTBBbW9kZWxfY2hlY2twb2ludCUyMCUzRCUyMCUyMmRpc3RpbGJlcnQtYmFzZS11bmNhc2VkJTIyJTBBbW9kZWwlMjAlM0QlMjBBdXRvTW9kZWxGb3JNYXNrZWRMTS5mcm9tX3ByZXRyYWluZWQobW9kZWxfY2hlY2twb2ludCk=",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoModelForMaskedLM

model_checkpoint = <span class="hljs-string">&quot;distilbert-base-uncased&quot;</span>
model = AutoModelForMaskedLM.from_pretrained(model_checkpoint)`,wrap:!1}}),_=new h({props:{code:"ZGlzdGlsYmVydF9udW1fcGFyYW1ldGVycyUyMCUzRCUyMG1vZGVsLm51bV9wYXJhbWV0ZXJzKCklMjAlMkYlMjAxXzAwMF8wMDAlMEFwcmludChmJTIyJyUzRSUzRSUzRSUyMERpc3RpbEJFUlQlMjBudW1iZXIlMjBvZiUyMHBhcmFtZXRlcnMlM0ElMjAlN0Jyb3VuZChkaXN0aWxiZXJ0X251bV9wYXJhbWV0ZXJzKSU3RE0nJTIyKSUwQXByaW50KGYlMjInJTNFJTNFJTNFJTIwQkVSVCUyMG51bWJlciUyMG9mJTIwcGFyYW1ldGVycyUzQSUyMDExME0nJTIyKQ==",highlighted:`distilbert_num_parameters = model.num_parameters() / <span class="hljs-number">1_000_000</span>
<span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;&#x27;&gt;&gt;&gt; DistilBERT number of parameters: <span class="hljs-subst">{<span class="hljs-built_in">round</span>(distilbert_num_parameters)}</span>M&#x27;&quot;</span>)
<span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;&#x27;&gt;&gt;&gt; BERT number of parameters: 110M&#x27;&quot;</span>)`,wrap:!1}}),k=new h({props:{code:"JyUzRSUzRSUzRSUyMERpc3RpbEJFUlQlMjBudW1iZXIlMjBvZiUyMHBhcmFtZXRlcnMlM0ElMjA2N00nJTBBJyUzRSUzRSUzRSUyMEJFUlQlMjBudW1iZXIlMjBvZiUyMHBhcmFtZXRlcnMlM0ElMjAxMTBNJw==",highlighted:`<span class="hljs-string">&#x27;&gt;&gt;&gt; DistilBERT number of parameters: 67M&#x27;</span>
<span class="hljs-string">&#x27;&gt;&gt;&gt; BERT number of parameters: 110M&#x27;</span>`,wrap:!1}}),{c(){a=d("p"),a.innerHTML=U,n=M(),o(r.$$.fragment),G=M(),j=d("p"),j.innerHTML=R,W=M(),o(_.$$.fragment),X=M(),o(k.$$.fragment)},l(u){a=m(u,"P",{"data-svelte-h":!0}),b(a)!=="svelte-1xsyw0g"&&(a.innerHTML=U),n=p(u),c(r.$$.fragment,u),G=p(u),j=m(u,"P",{"data-svelte-h":!0}),b(j)!=="svelte-1r9u9pt"&&(j.innerHTML=R),W=p(u),c(_.$$.fragment,u),X=p(u),c(k.$$.fragment,u)},m(u,Z){t(u,a,Z),t(u,n,Z),T(r,u,Z),t(u,G,Z),t(u,j,Z),t(u,W,Z),T(_,u,Z),t(u,X,Z),T(k,u,Z),g=!0},i(u){g||(y(r.$$.fragment,u),y(_.$$.fragment,u),y(k.$$.fragment,u),g=!0)},o(u){J(r.$$.fragment,u),J(_.$$.fragment,u),J(k.$$.fragment,u),g=!1},d(u){u&&(e(a),e(n),e(G),e(j),e(W),e(X)),w(r,u),w(_,u),w(k,u)}}}function hM(I){let a,U;return a=new h({props:{code:"aW1wb3J0JTIwbnVtcHklMjBhcyUyMG5wJTBBaW1wb3J0JTIwdGVuc29yZmxvdyUyMGFzJTIwdGYlMEElMEFpbnB1dHMlMjAlM0QlMjB0b2tlbml6ZXIodGV4dCUyQyUyMHJldHVybl90ZW5zb3JzJTNEJTIybnAlMjIpJTBBdG9rZW5fbG9naXRzJTIwJTNEJTIwbW9kZWwoKippbnB1dHMpLmxvZ2l0cyUwQSUyMyUyMEZpbmQlMjB0aGUlMjBsb2NhdGlvbiUyMG9mJTIwJTVCTUFTSyU1RCUyMGFuZCUyMGV4dHJhY3QlMjBpdHMlMjBsb2dpdHMlMEFtYXNrX3Rva2VuX2luZGV4JTIwJTNEJTIwbnAuYXJnd2hlcmUoaW5wdXRzJTVCJTIyaW5wdXRfaWRzJTIyJTVEJTIwJTNEJTNEJTIwdG9rZW5pemVyLm1hc2tfdG9rZW5faWQpJTVCMCUyQyUyMDElNUQlMEFtYXNrX3Rva2VuX2xvZ2l0cyUyMCUzRCUyMHRva2VuX2xvZ2l0cyU1QjAlMkMlMjBtYXNrX3Rva2VuX2luZGV4JTJDJTIwJTNBJTVEJTBBJTIzJTIwUGljayUyMHRoZSUyMCU1Qk1BU0slNUQlMjBjYW5kaWRhdGVzJTIwd2l0aCUyMHRoZSUyMGhpZ2hlc3QlMjBsb2dpdHMlMEElMjMlMjBXZSUyMG5lZ2F0ZSUyMHRoZSUyMGFycmF5JTIwYmVmb3JlJTIwYXJnc29ydCUyMHRvJTIwZ2V0JTIwdGhlJTIwbGFyZ2VzdCUyQyUyMG5vdCUyMHRoZSUyMHNtYWxsZXN0JTJDJTIwbG9naXRzJTBBdG9wXzVfdG9rZW5zJTIwJTNEJTIwbnAuYXJnc29ydCgtbWFza190b2tlbl9sb2dpdHMpJTVCJTNBNSU1RC50b2xpc3QoKSUwQSUwQWZvciUyMHRva2VuJTIwaW4lMjB0b3BfNV90b2tlbnMlM0ElMEElMjAlMjAlMjAlMjBwcmludChmJTIyJTNFJTNFJTNFJTIwJTdCdGV4dC5yZXBsYWNlKHRva2VuaXplci5tYXNrX3Rva2VuJTJDJTIwdG9rZW5pemVyLmRlY29kZSglNUJ0b2tlbiU1RCkpJTdEJTIyKQ==",highlighted:`<span class="hljs-keyword">import</span> numpy <span class="hljs-keyword">as</span> np
<span class="hljs-keyword">import</span> tensorflow <span class="hljs-keyword">as</span> tf

inputs = tokenizer(text, return_tensors=<span class="hljs-string">&quot;np&quot;</span>)
token_logits = model(**inputs).logits
<span class="hljs-comment"># Find the location of [MASK] and extract its logits</span>
mask_token_index = np.argwhere(inputs[<span class="hljs-string">&quot;input_ids&quot;</span>] == tokenizer.mask_token_id)[<span class="hljs-number">0</span>, <span class="hljs-number">1</span>]
mask_token_logits = token_logits[<span class="hljs-number">0</span>, mask_token_index, :]
<span class="hljs-comment"># Pick the [MASK] candidates with the highest logits</span>
<span class="hljs-comment"># We negate the array before argsort to get the largest, not the smallest, logits</span>
top_5_tokens = np.argsort(-mask_token_logits)[:<span class="hljs-number">5</span>].tolist()

<span class="hljs-keyword">for</span> token <span class="hljs-keyword">in</span> top_5_tokens:
    <span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;&gt;&gt;&gt; <span class="hljs-subst">{text.replace(tokenizer.mask_token, tokenizer.decode([token]))}</span>&quot;</span>)`,wrap:!1}}),{c(){o(a.$$.fragment)},l(n){c(a.$$.fragment,n)},m(n,r){T(a,n,r),U=!0},i(n){U||(y(a.$$.fragment,n),U=!0)},o(n){J(a.$$.fragment,n),U=!1},d(n){w(a,n)}}}function fM(I){let a,U;return a=new h({props:{code:"aW1wb3J0JTIwdG9yY2glMEElMEFpbnB1dHMlMjAlM0QlMjB0b2tlbml6ZXIodGV4dCUyQyUyMHJldHVybl90ZW5zb3JzJTNEJTIycHQlMjIpJTBBdG9rZW5fbG9naXRzJTIwJTNEJTIwbW9kZWwoKippbnB1dHMpLmxvZ2l0cyUwQSUyMyUyMEZpbmQlMjB0aGUlMjBsb2NhdGlvbiUyMG9mJTIwJTVCTUFTSyU1RCUyMGFuZCUyMGV4dHJhY3QlMjBpdHMlMjBsb2dpdHMlMEFtYXNrX3Rva2VuX2luZGV4JTIwJTNEJTIwdG9yY2gud2hlcmUoaW5wdXRzJTVCJTIyaW5wdXRfaWRzJTIyJTVEJTIwJTNEJTNEJTIwdG9rZW5pemVyLm1hc2tfdG9rZW5faWQpJTVCMSU1RCUwQW1hc2tfdG9rZW5fbG9naXRzJTIwJTNEJTIwdG9rZW5fbG9naXRzJTVCMCUyQyUyMG1hc2tfdG9rZW5faW5kZXglMkMlMjAlM0ElNUQlMEElMjMlMjBQaWNrJTIwdGhlJTIwJTVCTUFTSyU1RCUyMGNhbmRpZGF0ZXMlMjB3aXRoJTIwdGhlJTIwaGlnaGVzdCUyMGxvZ2l0cyUwQXRvcF81X3Rva2VucyUyMCUzRCUyMHRvcmNoLnRvcGsobWFza190b2tlbl9sb2dpdHMlMkMlMjA1JTJDJTIwZGltJTNEMSkuaW5kaWNlcyU1QjAlNUQudG9saXN0KCklMEElMEFmb3IlMjB0b2tlbiUyMGluJTIwdG9wXzVfdG9rZW5zJTNBJTBBJTIwJTIwJTIwJTIwcHJpbnQoZiUyMiclM0UlM0UlM0UlMjAlN0J0ZXh0LnJlcGxhY2UodG9rZW5pemVyLm1hc2tfdG9rZW4lMkMlMjB0b2tlbml6ZXIuZGVjb2RlKCU1QnRva2VuJTVEKSklN0QnJTIyKQ==",highlighted:`<span class="hljs-keyword">import</span> torch

inputs = tokenizer(text, return_tensors=<span class="hljs-string">&quot;pt&quot;</span>)
token_logits = model(**inputs).logits
<span class="hljs-comment"># Find the location of [MASK] and extract its logits</span>
mask_token_index = torch.where(inputs[<span class="hljs-string">&quot;input_ids&quot;</span>] == tokenizer.mask_token_id)[<span class="hljs-number">1</span>]
mask_token_logits = token_logits[<span class="hljs-number">0</span>, mask_token_index, :]
<span class="hljs-comment"># Pick the [MASK] candidates with the highest logits</span>
top_5_tokens = torch.topk(mask_token_logits, <span class="hljs-number">5</span>, dim=<span class="hljs-number">1</span>).indices[<span class="hljs-number">0</span>].tolist()

<span class="hljs-keyword">for</span> token <span class="hljs-keyword">in</span> top_5_tokens:
    <span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;&#x27;&gt;&gt;&gt; <span class="hljs-subst">{text.replace(tokenizer.mask_token, tokenizer.decode([token]))}</span>&#x27;&quot;</span>)`,wrap:!1}}),{c(){o(a.$$.fragment)},l(n){c(a.$$.fragment,n)},m(n,r){T(a,n,r),U=!0},i(n){U||(y(a.$$.fragment,n),U=!0)},o(n){J(a.$$.fragment,n),U=!1},d(n){w(a,n)}}}function IM(I){let a,U="✏️ <strong>試試看!</strong> 創建 <code>無監督</code> 拆分的隨機樣本, 並驗證標籤既不是 <code>0</code> 也不是 <code>1</code>。在此過程中, 你還可以檢查 <code>train</code> 和 <code>test</code> 拆分中的標籤是否確實為 <code>0</code> 或 <code>1</code> — 這是每個 NLP 從業者在新項目開始時都應該執行的有用的健全性檢查!";return{c(){a=d("p"),a.innerHTML=U},l(n){a=m(n,"P",{"data-svelte-h":!0}),b(a)!=="svelte-eetmpl"&&(a.innerHTML=U)},m(n,r){t(n,a,r)},p:Hl,d(n){n&&e(a)}}}function CM(I){let a,U='✏️ <strong>試試看!</strong> 一些 Transformer 模型, 例如 <a href="https://huggingface.co/google/bigbird-roberta-base" rel="nofollow">BigBird</a> 和 <a href="hf.co/allenai/longformer-base-4096">Longformer</a>, 它們具有比BERT和其他早期Transformer模型更長的上下文長度。為這些檢查點之一實例化標記器, 並驗證 <code>model_max_length</code> 是否與模型卡上引用的內容一致。';return{c(){a=d("p"),a.innerHTML=U},l(n){a=m(n,"P",{"data-svelte-h":!0}),b(a)!=="svelte-1txp68m"&&(a.innerHTML=U)},m(n,r){t(n,a,r)},p:Hl,d(n){n&&e(a)}}}function _M(I){let a,U="請注意, 在實際場景中使用較小的塊大小可能是有害的, 因此你應該使用與將應用模型的用例相對應的大小。";return{c(){a=d("p"),a.textContent=U},l(n){a=m(n,"P",{"data-svelte-h":!0}),b(a)!=="svelte-1kos6h"&&(a.textContent=U)},m(n,r){t(n,a,r)},p:Hl,d(n){n&&e(a)}}}function GM(I){let a,U="✏️ <strong>試試看!</strong> 多次運行上面的代碼片段, 看看隨機屏蔽發生在你眼前! 還要將 <code>tokenizer.decode()</code> 方法替換為 <code>tokenizer.convert_ids_to_tokens()</code> 以查看有時會屏蔽給定單詞中的單個標記, 而不是其他標記。";return{c(){a=d("p"),a.innerHTML=U},l(n){a=m(n,"P",{"data-svelte-h":!0}),b(a)!=="svelte-1k5tuyy"&&(a.innerHTML=U)},m(n,r){t(n,a,r)},p:Hl,d(n){n&&e(a)}}}function nM(I){let a,U="隨機掩碼的一個副作用是, 當使用 <code>Trainer</code> 時, 我們的評估指標將不是確定性的, 因為我們對訓練集和測試集使用相同的數據整理器。稍後我們會看到, 當我們使用 🤗 Accelerate 進行微調時, 我們將如何利用自定義評估循環的靈活性來凍結隨機性。";return{c(){a=d("p"),a.innerHTML=U},l(n){a=m(n,"P",{"data-svelte-h":!0}),b(a)!=="svelte-1ph49zd"&&(a.innerHTML=U)},m(n,r){t(n,a,r)},d(n){n&&e(a)}}}function ZM(I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XJlKG1hc2spJTVCMCU1RCUzQSUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMHdvcmRfaWQlMjAlM0QlMjB3b3JkX2lkLml0ZW0oKSUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMGZvciUyMGlkeCUyMGluJTIwbWFwcGluZyU1QndvcmRfaWQlNUQlM0ElMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBuZXdfbGFiZWxzJTVCaWR4JTVEJTIwJTNEJTIwbGFiZWxzJTVCaWR4JTVEJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwaW5wdXRfaWRzJTVCaWR4JTVEJTIwJTNEJTIwdG9rZW5pemVyLm1hc2tfdG9rZW5faWQlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBmZWF0dXJlJTVCJTIybGFiZWxzJTIyJTVEJTIwJTNEJTIwbmV3X2xhYmVscyUwQSUwQSUyMCUyMCUyMCUyMHJldHVybiUyMHRmX2RlZmF1bHRfZGF0YV9jb2xsYXRvcihmZWF0dXJlcyk=",highlighted:`<span class="hljs-keyword">import</span> collections
<span class="hljs-keyword">import</span> numpy <span class="hljs-keyword">as</span> np

<span class="hljs-keyword">from</span> transformers.data <span class="hljs-keyword">import</span> tf_default_data_collator

wwm_probability = <span class="hljs-number">0.2</span>


<span class="hljs-keyword">def</span> <span class="hljs-title function_">whole_word_masking_data_collator</span>(<span class="hljs-params">features</span>):
    <span class="hljs-keyword">for</span> feature <span class="hljs-keyword">in</span> features:
        word_ids = feature.pop(<span class="hljs-string">&quot;word_ids&quot;</span>)

        <span class="hljs-comment"># Create a map between words and corresponding token indices</span>
        mapping = collections.defaultdict(<span class="hljs-built_in">list</span>)
        current_word_index = -<span class="hljs-number">1</span>
        current_word = <span class="hljs-literal">None</span>
        <span class="hljs-keyword">for</span> idx, word_id <span class="hljs-keyword">in</span> <span class="hljs-built_in">enumerate</span>(word_ids):
            <span class="hljs-keyword">if</span> word_id <span class="hljs-keyword">is</span> <span class="hljs-keyword">not</span> <span class="hljs-literal">None</span>:
                <span class="hljs-keyword">if</span> word_id != current_word:
                    current_word = word_id
                    current_word_index += <span class="hljs-number">1</span>
                mapping[current_word_index].append(idx)

        <span class="hljs-comment"># Randomly mask words</span>
        mask = np.random.binomial(<span class="hljs-number">1</span>, wwm_probability, (<span class="hljs-built_in">len</span>(mapping),))
        input_ids = feature[<span class="hljs-string">&quot;input_ids&quot;</span>]
        labels = feature[<span class="hljs-string">&quot;labels&quot;</span>]
        new_labels = [-<span class="hljs-number">100</span>] * <span class="hljs-built_in">len</span>(labels)
        <span class="hljs-keyword">for</span> word_id <span class="hljs-keyword">in</span> np.where(mask)[<span class="hljs-number">0</span>]:
            word_id = word_id.item()
            <span class="hljs-keyword">for</span> idx <span class="hljs-keyword">in</span> mapping[word_id]:
                new_labels[idx] = labels[idx]
                input_ids[idx] = tokenizer.mask_token_id
        feature[<span class="hljs-string">&quot;labels&quot;</span>] = new_labels

    <span class="hljs-keyword">return</span> tf_default_data_collator(features)`,wrap:!1}}),{c(){o(a.$$.fragment)},l(n){c(a.$$.fragment,n)},m(n,r){T(a,n,r),U=!0},i(n){U||(y(a.$$.fragment,n),U=!0)},o(n){J(a.$$.fragment,n),U=!1},d(n){w(a,n)}}}function BM(I){let a,U;return a=new h({props:{code:"aW1wb3J0JTIwY29sbGVjdGlvbnMlMEFpbXBvcnQlMjBudW1weSUyMGFzJTIwbnAlMEElMEFmcm9tJTIwdHJhbnNmb3JtZXJzJTIwaW1wb3J0JTIwZGVmYXVsdF9kYXRhX2NvbGxhdG9yJTBBJTBBd3dtX3Byb2JhYmlsaXR5JTIwJTNEJTIwMC4yJTBBJTBBJTBBZGVmJTIwd2hvbGVfd29yZF9tYXNraW5nX2RhdGFfY29sbGF0b3IoZmVhdHVyZX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3X2xhYmVscyU1QmlkeCU1RCUyMCUzRCUyMGxhYmVscyU1QmlkeCU1RCUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMGlucHV0X2lkcyU1QmlkeCU1RCUyMCUzRCUyMHRva2VuaXplci5tYXNrX3Rva2VuX2lkJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwZmVhdHVyZSU1QiUyMmxhYmVscyUyMiU1RCUyMCUzRCUyMG5ld19sYWJlbHMlMEElMEElMjAlMjAlMjAlMjByZXR1cm4lMjBkZWZhdWx0X2RhdGFfY29sbGF0b3IoZmVhdHVyZXMp",highlighted:`<span class="hljs-keyword">import</span> collections
<span class="hljs-keyword">import</span> numpy <span class="hljs-keyword">as</span> np

<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> default_data_collator

wwm_probability = <span class="hljs-number">0.2</span>


<span class="hljs-keyword">def</span> <span class="hljs-title function_">whole_word_masking_data_collator</span>(<span class="hljs-params">features</span>):
    <span class="hljs-keyword">for</span> feature <span class="hljs-keyword">in</span> features:
        word_ids = feature.pop(<span class="hljs-string">&quot;word_ids&quot;</span>)

        <span class="hljs-comment"># Create a map between words and corresponding token indices</span>
        mapping = collections.defaultdict(<span class="hljs-built_in">list</span>)
        current_word_index = -<span class="hljs-number">1</span>
        current_word = <span class="hljs-literal">None</span>
        <span class="hljs-keyword">for</span> idx, word_id <span class="hljs-keyword">in</span> <span class="hljs-built_in">enumerate</span>(word_ids):
            <span class="hljs-keyword">if</span> word_id <span class="hljs-keyword">is</span> <span class="hljs-keyword">not</span> <span class="hljs-literal">None</span>:
                <span class="hljs-keyword">if</span> word_id != current_word:
                    current_word = word_id
                    current_word_index += <span class="hljs-number">1</span>
                mapping[current_word_index].append(idx)

        <span class="hljs-comment"># Randomly mask words</span>
        mask = np.random.binomial(<span class="hljs-number">1</span>, wwm_probability, (<span class="hljs-built_in">len</span>(mapping),))
        input_ids = feature[<span class="hljs-string">&quot;input_ids&quot;</span>]
        labels = feature[<span class="hljs-string">&quot;labels&quot;</span>]
        new_labels = [-<span class="hljs-number">100</span>] * <span class="hljs-built_in">len</span>(labels)
        <span class="hljs-keyword">for</span> word_id <span class="hljs-keyword">in</span> np.where(mask)[<span class="hljs-number">0</span>]:
            word_id = word_id.item()
            <span class="hljs-keyword">for</span> idx <span class="hljs-keyword">in</span> mapping[word_id]:
                new_labels[idx] = labels[idx]
                input_ids[idx] = tokenizer.mask_token_id
        feature[<span class="hljs-string">&quot;labels&quot;</span>] = new_labels

    <span class="hljs-keyword">return</span> default_data_collator(features)`,wrap:!1}}),{c(){o(a.$$.fragment)},l(n){c(a.$$.fragment,n)},m(n,r){T(a,n,r),U=!0},i(n){U||(y(a.$$.fragment,n),U=!0)},o(n){J(a.$$.fragment,n),U=!1},d(n){w(a,n)}}}function gM(I){let a,U="✏️ <strong>試試看!</strong> 多次運行上面的代碼片段, 看看隨機屏蔽發生在你眼前! 還要將 <code>tokenizer.decode()</code> 方法替換為 <code>tokenizer.convert_ids_to_tokens()</code> 以查看來自給定單詞的標記始終被屏蔽在一起。";return{c(){a=d("p"),a.innerHTML=U},l(n){a=m(n,"P",{"data-svelte-h":!0}),b(a)!=="svelte-1xa89mc"&&(a.innerHTML=U)},m(n,r){t(n,a,r)},p:Hl,d(n){n&&e(a)}}}function kM(I){let a,U="登陸後, 我們可以指定 <code>Trainer</code> 參數:",n,r,G,j,R="在這裡, 我們調整了一些默認選項, 包括 <code>logging_steps</code> , 以確保我們跟蹤每個epoch的訓練損失。我們還使用了 <code>fp16=True</code> 來實現混合精度訓練, 這給我們帶來了另一個速度提升。默認情況下, <code>Trainer</code> 將刪除不屬於模型的 <code>forward()</code> 方法的列。這意味著, 如果你使用整個單詞屏蔽排序器, 你還需要設置 <code>remove_unused_columns=False</code>, 以確保我們不會在訓練期間丟失 <code>word_ids</code> 列。",W,_,X='請注意, 你可以使用 <code>hub_model_id</code> 參數指定要推送到的存儲庫的名稱((特別是你將必須使用該參數向組織推送)。例如, 當我們將模型推送到 <a href="https://huggingface.co/huggingface-course" rel="nofollow"><code>huggingface-course</code> organization</a> 時, 我們添加了 <code>hub_model_id=&quot;huggingface-course/distilbert-finetuned-imdb&quot;</code> 到 <code>TrainingArguments</code> 中。默認情況下, 使用的存儲庫將在你的命名空間中並以你設置的輸出目錄命名, 因此在我們的示例中, 它將是 <code>&quot;lewtun/distilbert-finetuned-imdb&quot;</code>。',k,g,u="我們現在擁有實例化 <code>Trainer</code> 的所有成分。這裡我們只使用標準的 <code>data_collator</code>, 但你可以嘗試使用整個單詞掩碼整理器並比較結果作為練習:",Z,z,Y,C,$="我們現在準備運行 <code>trainer.train()</code> — 但在此之前讓我們簡要地看一下 <em>perplexity</em>, 這是評估語言模型性能的常用指標。",F;return r=new h({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMFRyYWluaW5nQXJndW1lbnRzJTBBJTBBYmF0Y2hfc2l6ZSUyMCUzRCUyMDY0JTBBJTIzJTIwU2hvdyUyMHRoZSUyMHRyYWluaW5nJTIwbG9zcyUyMHdpdGglMjBldmVyeSUyMGVwb2NoJTBBbG9nZ2luZ19zdGVwcyUyMCUzRCUyMGxlbihkb3duc2FtcGxlZF9kYXRhc2V0JTVCJTIydHJhaW4lMjIlNUQpJTIwJTJGJTJGJTIwYmF0Y2hfc2l6ZSUwQW1vZGVsX25hbWUlMjAlM0QlMjBtb2RlbF9jaGVja3BvaW50LnNwbGl0KCUyMiUyRiUyMiklNUItMSU1RCUwQSUwQXRyYWluaW5nX2FyZ3MlMjAlM0QlMjBUcmFpbmluZ0FyZ3VtZW50cyglMEElMjAlMjAlMjAlMjBvdXRwdXRfZGlyJTNEZiUyMiU3Qm1vZGVsX25hbWUlN0QtZmluZXR1bmVkLWltZGIlMjIlMkMlMEElMjAlMjAlMjAlMjBvdmVyd3JpdGVfb3V0cHV0X2RpciUzRFRydWUlMkMlMEElMjAlMjAlMjAlMjBldmFsdWF0aW9uX3N0cmF0ZWd5JTNEJTIyZXBvY2glMjIlMkMlMEElMjAlMjAlMjAlMjBsZWFybmluZ19yYXRlJTNEMmUtNSUyQyUwQSUyMCUyMCUyMCUyMHdlaWdodF9kZWNheSUzRDAuMDElMkMlMEElMjAlMjAlMjAlMjBwZXJfZGV2aWNlX3RyYWluX2JhdGNoX3NpemUlM0RiYXRjaF9zaXplJTJDJTBBJTIwJTIwJTIwJTIwcGVyX2RldmljZV9ldmFsX2JhdGNoX3NpemUlM0RiYXRjaF9zaXplJTJDJTBBJTIwJTIwJTIwJTIwcHVzaF90b19odWIlM0RUcnVlJTJDJTBBJTIwJTIwJTIwJTIwZnAxNiUzRFRydWUlMkMlMEElMjAlMjAlMjAlMjBsb2dnaW5nX3N0ZXBzJTNEbG9nZ2luZ19zdGVwcyUyQyUwQSk=",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> TrainingArguments

batch_size = <span class="hljs-number">64</span>
<span class="hljs-comment"># Show the training loss with every epoch</span>
logging_steps = <span class="hljs-built_in">len</span>(downsampled_dataset[<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>]

training_args = TrainingArguments(
    output_dir=<span class="hljs-string">f&quot;<span class="hljs-subst">{model_name}</span>-finetuned-imdb&quot;</span>,
    overwrite_output_dir=<span class="hljs-literal">True</span>,
    evaluation_strategy=<span class="hljs-string">&quot;epoch&quot;</span>,
    learning_rate=<span class="hljs-number">2e-5</span>,
    weight_decay=<span class="hljs-number">0.01</span>,
    per_device_train_batch_size=batch_size,
    per_device_eval_batch_size=batch_size,
    push_to_hub=<span class="hljs-literal">True</span>,
    fp16=<span class="hljs-literal">True</span>,
    logging_steps=logging_steps,
)`,wrap:!1}}),z=new h({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMFRyYWluZXIlMEElMEF0cmFpbmVyJTIwJTNEJTIwVHJhaW5lciglMEElMjAlMjAlMjAlMjBtb2RlbCUzRG1vZGVsJTJDJTBBJTIwJTIwJTIwJTIwYXJncyUzRHRyYWluaW5nX2FyZ3MlMkMlMEElMjAlMjAlMjAlMjB0cmFpbl9kYXRhc2V0JTNEZG93bnNhbXBsZWRfZGF0YXNldCU1QiUyMnRyYWluJTIyJTVEJTJDJTBBJTIwJTIwJTIwJTIwZXZhbF9kYXRhc2V0JTNEZG93bnNhbXBsZWRfZGF0YXNldCU1QiUyMnRlc3QlMjIlNUQlMkMlMEElMjAlMjAlMjAlMjBkYXRhX2NvbGxhdG9yJTNEZGF0YV9jb2xsYXRvciUyQyUwQSUyMCUyMCUyMCUyMHRva2VuaXplciUzRHRva2VuaXplciUyQyUwQSk=",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> Trainer

trainer = Trainer(
    model=model,
    args=training_args,
    train_dataset=downsampled_dataset[<span class="hljs-string">&quot;train&quot;</span>],
    eval_dataset=downsampled_dataset[<span class="hljs-string">&quot;test&quot;</span>],
    data_collator=data_collator,
    tokenizer=tokenizer,
)`,wrap:!1}}),{c(){a=d("p"),a.innerHTML=U,n=M(),o(r.$$.fragment),G=M(),j=d("p"),j.innerHTML=R,W=M(),_=d("p"),_.innerHTML=X,k=M(),g=d("p"),g.innerHTML=u,Z=M(),o(z.$$.fragment),Y=M(),C=d("p"),C.innerHTML=$},l(B){a=m(B,"P",{"data-svelte-h":!0}),b(a)!=="svelte-16k3gzf"&&(a.innerHTML=U),n=p(B),c(r.$$.fragment,B),G=p(B),j=m(B,"P",{"data-svelte-h":!0}),b(j)!=="svelte-1qukwmr"&&(j.innerHTML=R),W=p(B),_=m(B,"P",{"data-svelte-h":!0}),b(_)!=="svelte-1u7mjys"&&(_.innerHTML=X),k=p(B),g=m(B,"P",{"data-svelte-h":!0}),b(g)!=="svelte-qgf3yh"&&(g.innerHTML=u),Z=p(B),c(z.$$.fragment,B),Y=p(B),C=m(B,"P",{"data-svelte-h":!0}),b(C)!=="svelte-1uxro8u"&&(C.innerHTML=$)},m(B,V){t(B,a,V),t(B,n,V),T(r,B,V),t(B,G,V),t(B,j,V),t(B,W,V),t(B,_,V),t(B,k,V),t(B,g,V),t(B,Z,V),T(z,B,V),t(B,Y,V),t(B,C,V),F=!0},i(B){F||(y(r.$$.fragment,B),y(z.$$.fragment,B),F=!0)},o(B){J(r.$$.fragment,B),J(z.$$.fragment,B),F=!1},d(B){B&&(e(a),e(n),e(G),e(j),e(W),e(_),e(k),e(g),e(Z),e(Y),e(C)),w(r,B),w(z,B)}}}function RM(I){let a,U="登陸後, 我們就可以創建我們的 <code>tf.data</code> 數據集。我們將在這裡只使用標準數據整理器, 但你也可以嘗試使用整個單詞掩碼整理器並將結果作為練習進行比較:",n,r,G,j,R="接下來, 我們設置訓練超參數並編譯模型。我們使用 🤗 Transformers 庫中的 <code>create_optimizer()</code> 函數, 它提供了一個具有線性學習率衰減的 <code>AdamW</code> 優化器。我們還使用了模型內置的損失, 當沒有損失被指定為 <code>compile()</code> 參數是, 這是默認值, 並且我們將訓練精度設置為 <code>&quot;mixed_float16&quot;</code>。請注意,如果你使用的是Colab GPU或其他不支持float16加速的GPU, 你可能應該註釋掉這一行。",W,_,X='此外, 我們還設置了一個 <code>PushToHubCallback</code>, 它將在每個epoch後將模型保存到Hub。你可以使用 <code>hub_model_id</code> 參數指定你想要推送到的存儲庫的名稱 (特別是你將必須使用該參數來推送到組織)。例如, 為了將模型推送到 <a href="https://huggingface.co/huggingface-course" rel="nofollow"><code>huggingface-course</code> organization</a>, 我們添加了 <code>hub_model_id=&quot;huggingface-course/distilbert-finetuned-imdb&quot;</code>。默認情況下, 使用的存儲庫將位於你的命名空間中, 並以你設置的輸出目錄命名, 因此在我們的示例中, 它將是 <code>&quot;lewtun/distilbert-finetuned-imdb&quot;</code>。',k,g,u,Z,z="我們現在已經準備好運行 <code>model.fit()</code> 了 — 但在此之前, 讓我們先簡單地看看 <em>perplexity</em>, 它是評估語言模型性能的常用指標。",Y;return r=new h({props:{code:"dGZfdHJhaW5fZGF0YXNldCUyMCUzRCUyMGRvd25zYW1wbGVkX2RhdGFzZXQlNUIlMjJ0cmFpbiUyMiU1RC50b190Zl9kYXRhc2V0KCUwQSUyMCUyMCUyMCUyMGNvbHVtbnMlM0QlNUIlMjJpbnB1dF9pZHMlMjIlMkMlMjAlMjJhdHRlbnRpb25fbWFzayUyMiUyQyUyMCUyMmxhYmVscyUyMiU1RCUyQyUwQSUyMCUyMCUyMCUyMGNvbGxhdGVfZm4lM0RkYXRhX2NvbGxhdG9yJTJDJTBBJTIwJTIwJTIwJTIwc2h1ZmZsZSUzRFRydWUlMkMlMEElMjAlMjAlMjAlMjBiYXRjaF9zaXplJTNEMzIlMkMlMEEpJTBBJTBBdGZfZXZhbF9kYXRhc2V0JTIwJTNEJTIwZG93bnNhbXBsZWRfZGF0YXNldCU1QiUyMnRlc3QlMjIlNUQudG9fdGZfZGF0YXNldCglMEElMjAlMjAlMjAlMjBjb2x1bW5zJTNEJTVCJTIyaW5wdXRfaWRzJTIyJTJDJTIwJTIyYXR0ZW50aW9uX21hc2slMjIlMkMlMjAlMjJsYWJlbHMlMjIlNUQlMkMlMEElMjAlMjAlMjAlMjBjb2xsYXRlX2ZuJTNEZGF0YV9jb2xsYXRvciUyQyUwQSUyMCUyMCUyMCUyMHNodWZmbGUlM0RGYWxzZSUyQyUwQSUyMCUyMCUyMCUyMGJhdGNoX3NpemUlM0QzMiUyQyUwQSk=",highlighted:`tf_train_dataset = downsampled_dataset[<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">32</span>,
)

tf_eval_dataset = downsampled_dataset[<span class="hljs-string">&quot;test&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">32</span>,
)`,wrap:!1}}),g=new h({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMGNyZWF0ZV9vcHRpbWl6ZXIlMEFmcm9tJTIwdHJhbnNmb3JtZXJzLmtlcmFzX2NhbGxiYWNrcyUyMGltcG9ydCUyMFB1c2hUb0h1YkNhbGxiYWNrJTBBaW1wb3J0JTIwdGVuc29yZmxvdyUyMGFzJTIwdGYlMEElMEFudW1fdHJhaW5fc3RlcHMlMjAlM0QlMjBsZW4odGZfdHJhaW5fZGF0YXNldCklMEFvcHRpbWl6ZXIlMkMlMjBzY2hlZHVsZSUyMCUzRCUyMGNyZWF0ZV9vcHRpbWl6ZXIoJTBBJTIwJTIwJTIwJTIwaW5pdF9sciUzRDJlLTUlMkMlMEElMjAlMjAlMjAlMjBudW1fd2FybXVwX3N0ZXBzJTNEMV8wMDAlMkMlMEElMjAlMjAlMjAlMjBudW1fdHJhaW5fc3RlcHMlM0RudW1fdHJhaW5fc3RlcHMlMkMlMEElMjAlMjAlMjAlMjB3ZWlnaHRfZGVjYXlfcmF0ZSUzRDAuMDElMkMlMEEpJTBBbW9kZWwuY29tcGlsZShvcHRpbWl6ZXIlM0RvcHRpbWl6ZXIpJTBBJTBBJTIzJTIwVHJhaW4lMjBpbiUyMG1peGVkLXByZWNpc2lvbiUyMGZsb2F0MTYlMEF0Zi5rZXJhcy5taXhlZF9wcmVjaXNpb24uc2V0X2dsb2JhbF9wb2xpY3koJTIybWl4ZWRfZmxvYXQxNiUyMiklMEElMEFjYWxsYmFjayUyMCUzRCUyMFB1c2hUb0h1YkNhbGxiYWNrKCUwQSUyMCUyMCUyMCUyMG91dHB1dF9kaXIlM0RmJTIyJTdCbW9kZWxfbmFtZSU3RC1maW5ldHVuZWQtaW1kYiUyMiUyQyUyMHRva2VuaXplciUzRHRva2VuaXplciUwQSk=",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> create_optimizer
<span class="hljs-keyword">from</span> transformers.keras_callbacks <span class="hljs-keyword">import</span> PushToHubCallback
<span class="hljs-keyword">import</span> tensorflow <span class="hljs-keyword">as</span> tf

num_train_steps = <span class="hljs-built_in">len</span>(tf_train_dataset)
optimizer, schedule = create_optimizer(
    init_lr=<span class="hljs-number">2e-5</span>,
    num_warmup_steps=<span class="hljs-number">1_000</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>)

callback = PushToHubCallback(
    output_dir=<span class="hljs-string">f&quot;<span class="hljs-subst">{model_name}</span>-finetuned-imdb&quot;</span>, tokenizer=tokenizer
)`,wrap:!1}}),{c(){a=d("p"),a.innerHTML=U,n=M(),o(r.$$.fragment),G=M(),j=d("p"),j.innerHTML=R,W=M(),_=d("p"),_.innerHTML=X,k=M(),o(g.$$.fragment),u=M(),Z=d("p"),Z.innerHTML=z},l(C){a=m(C,"P",{"data-svelte-h":!0}),b(a)!=="svelte-1arnuqw"&&(a.innerHTML=U),n=p(C),c(r.$$.fragment,C),G=p(C),j=m(C,"P",{"data-svelte-h":!0}),b(j)!=="svelte-vdjvpm"&&(j.innerHTML=R),W=p(C),_=m(C,"P",{"data-svelte-h":!0}),b(_)!=="svelte-129cw4f"&&(_.innerHTML=X),k=p(C),c(g.$$.fragment,C),u=p(C),Z=m(C,"P",{"data-svelte-h":!0}),b(Z)!=="svelte-1qarymm"&&(Z.innerHTML=z)},m(C,$){t(C,a,$),t(C,n,$),T(r,C,$),t(C,G,$),t(C,j,$),t(C,W,$),t(C,_,$),t(C,k,$),T(g,C,$),t(C,u,$),t(C,Z,$),Y=!0},i(C){Y||(y(r.$$.fragment,C),y(g.$$.fragment,C),Y=!0)},o(C){J(r.$$.fragment,C),J(g.$$.fragment,C),Y=!1},d(C){C&&(e(a),e(n),e(G),e(j),e(W),e(_),e(k),e(u),e(Z)),w(r,C),w(g,C)}}}function XM(I){let a,U="假設我們的測試集主要由語法正確的句子組成, 那麼衡量我們的語言模型質量的一種方法是計算測試集所有句子中它分配給下一個單詞的概率。高概率表明, 該模型表明該模型對未見過的示例不感到 “驚訝” 或 “困惑”, 並表明它已經學會了該語言的基本語法模式。關於perplexity度有各種不同的數學定義, 但我們要用的定義是交叉熵損失的指數。因此, 我們可以通過 <code>model.evaluate()</code> 方法計算測試集上的交叉熵損失, 然後取結果的指數來計算我們預訓練模型的perplexity度:",n,r,G;return r=new h({props:{code:"aW1wb3J0JTIwbWF0aCUwQSUwQWV2YWxfbG9zcyUyMCUzRCUyMG1vZGVsLmV2YWx1YXRlKHRmX2V2YWxfZGF0YXNldCklMEFwcmludChmJTIyUGVycGxleGl0eSUzQSUyMCU3Qm1hdGguZXhwKGV2YWxfbG9zcyklM0EuMmYlN0QlMjIp",highlighted:`<span class="hljs-keyword">import</span> math

eval_loss = model.evaluate(tf_eval_dataset)
<span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;Perplexity: <span class="hljs-subst">{math.exp(eval_loss):<span class="hljs-number">.2</span>f}</span>&quot;</span>)`,wrap:!1}}),{c(){a=d("p"),a.innerHTML=U,n=M(),o(r.$$.fragment)},l(j){a=m(j,"P",{"data-svelte-h":!0}),b(a)!=="svelte-zy8yqp"&&(a.innerHTML=U),n=p(j),c(r.$$.fragment,j)},m(j,R){t(j,a,R),t(j,n,R),T(r,j,R),G=!0},i(j){G||(y(r.$$.fragment,j),G=!0)},o(j){J(r.$$.fragment,j),G=!1},d(j){j&&(e(a),e(n)),w(r,j)}}}function WM(I){let a,U="假設我們的測試集主要由語法正確的句子組成, 那麼衡量我們的語言模型質量的一種方法是計算它分配給測試集中所有句子中的下一個單詞的概率。高概率表明模型對看不見的例子並不感到 “驚訝” 或 “疑惑”, 並表明它已經學習了語言中的基本語法模式。 perplexity度有多種數學定義, 但我們將使用的定義是交叉熵損失的指數。因此, 我們可以通過 <code>Trainer.evaluate()</code> 函數計算測試集上的交叉熵損失, 然後取結果的指數來計算預訓練模型的perplexity度:",n,r,G;return r=new h({props:{code:"aW1wb3J0JTIwbWF0aCUwQSUwQWV2YWxfcmVzdWx0cyUyMCUzRCUyMHRyYWluZXIuZXZhbHVhdGUoKSUwQXByaW50KGYlMjIlM0UlM0UlM0UlMjBQZXJwbGV4aXR5JTNBJTIwJTdCbWF0aC5leHAoZXZhbF9yZXN1bHRzJTVCJ2V2YWxfbG9zcyclNUQpJTNBLjJmJTdEJTIyKQ==",highlighted:`<span class="hljs-keyword">import</span> math

eval_results = trainer.evaluate()
<span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;&gt;&gt;&gt; Perplexity: <span class="hljs-subst">{math.exp(eval_results[<span class="hljs-string">&#x27;eval_loss&#x27;</span>]):<span class="hljs-number">.2</span>f}</span>&quot;</span>)`,wrap:!1}}),{c(){a=d("p"),a.innerHTML=U,n=M(),o(r.$$.fragment)},l(j){a=m(j,"P",{"data-svelte-h":!0}),b(a)!=="svelte-bs0opi"&&(a.innerHTML=U),n=p(j),c(r.$$.fragment,j)},m(j,R){t(j,a,R),t(j,n,R),T(r,j,R),G=!0},i(j){G||(y(r.$$.fragment,j),G=!0)},o(j){J(r.$$.fragment,j),G=!1},d(j){j&&(e(a),e(n)),w(r,j)}}}function $M(I){let a,U;return a=new h({props:{code:"bW9kZWwuZml0KHRmX3RyYWluX2RhdGFzZXQlMkMlMjB2YWxpZGF0aW9uX2RhdGElM0R0Zl9ldmFsX2RhdGFzZXQlMkMlMjBjYWxsYmFja3MlM0QlNUJjYWxsYmFjayU1RCk=",highlighted:"model.fit(tf_train_dataset, validation_data=tf_eval_dataset, callbacks=[callback])",wrap:!1}}),{c(){o(a.$$.fragment)},l(n){c(a.$$.fragment,n)},m(n,r){T(a,n,r),U=!0},i(n){U||(y(a.$$.fragment,n),U=!0)},o(n){J(a.$$.fragment,n),U=!1},d(n){w(a,n)}}}function VM(I){let a,U;return a=new h({props:{code:"dHJhaW5lci50cmFpbigp",highlighted:"trainer.train()",wrap:!1}}),{c(){o(a.$$.fragment)},l(n){c(a.$$.fragment,n)},m(n,r){T(a,n,r),U=!0},i(n){U||(y(a.$$.fragment,n),U=!0)},o(n){J(a.$$.fragment,n),U=!1},d(n){w(a,n)}}}function zM(I){let a,U;return a=new h({props:{code:"ZXZhbF9sb3NzJTIwJTNEJTIwbW9kZWwuZXZhbHVhdGUodGZfZXZhbF9kYXRhc2V0KSUwQXByaW50KGYlMjJQZXJwbGV4aXR5JTNBJTIwJTdCbWF0aC5leHAoZXZhbF9sb3NzKSUzQS4yZiU3RCUyMik=",highlighted:`eval_loss = model.evaluate(tf_eval_dataset)
<span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;Perplexity: <span class="hljs-subst">{math.exp(eval_loss):<span class="hljs-number">.2</span>f}</span>&quot;</span>)`,wrap:!1}}),{c(){o(a.$$.fragment)},l(n){c(a.$$.fragment,n)},m(n,r){T(a,n,r),U=!0},i(n){U||(y(a.$$.fragment,n),U=!0)},o(n){J(a.$$.fragment,n),U=!1},d(n){w(a,n)}}}function NM(I){let a,U;return a=new h({props:{code:"ZXZhbF9yZXN1bHRzJTIwJTNEJTIwdHJhaW5lci5ldmFsdWF0ZSgpJTBBcHJpbnQoZiUyMiUzRSUzRSUzRSUyMFBlcnBsZXhpdHklM0ElMjAlN0JtYXRoLmV4cChldmFsX3Jlc3VsdHMlNUInZXZhbF9sb3NzJyU1RCklM0EuMmYlN0QlMjIp",highlighted:`eval_results = trainer.evaluate()
<span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;&gt;&gt;&gt; Perplexity: <span class="hljs-subst">{math.exp(eval_results[<span class="hljs-string">&#x27;eval_loss&#x27;</span>]):<span class="hljs-number">.2</span>f}</span>&quot;</span>)`,wrap:!1}}),{c(){o(a.$$.fragment)},l(n){c(a.$$.fragment,n)},m(n,r){T(a,n,r),U=!0},i(n){U||(y(a.$$.fragment,n),U=!0)},o(n){J(a.$$.fragment,n),U=!1},d(n){w(a,n)}}}function MM(I){let a,U="訓練完成後, 我們可以將帶有訓練信息的模型卡推送到 Hub (檢查點在訓練過程中自行保存):",n,r,G;return r=new h({props:{code:"dHJhaW5lci5wdXNoX3RvX2h1Yigp",highlighted:"trainer.push_to_hub()",wrap:!1}}),{c(){a=d("p"),a.textContent=U,n=M(),o(r.$$.fragment)},l(j){a=m(j,"P",{"data-svelte-h":!0}),b(a)!=="svelte-572w17"&&(a.textContent=U),n=p(j),c(r.$$.fragment,j)},m(j,R){t(j,a,R),t(j,n,R),T(r,j,R),G=!0},i(j){G||(y(r.$$.fragment,j),G=!0)},o(j){J(r.$$.fragment,j),G=!1},d(j){j&&(e(a),e(n)),w(r,j)}}}function xM(I){let a,U="✏️ <strong>輪到你了!</strong> 將數據整理器改為全字屏蔽整理器後運行上面的訓練。你有得到更好的結果嗎?";return{c(){a=d("p"),a.innerHTML=U},l(n){a=m(n,"P",{"data-svelte-h":!0}),b(a)!=="svelte-h2fj7n"&&(a.innerHTML=U)},m(n,r){t(n,a,r)},p:Hl,d(n){n&&e(a)}}}function pM(I){let a,U="在我們的用例中, 我們不需要對訓練循環做任何特別的事情, 但在某些情況下, 你可能需要實現一些自定義邏輯。對於這些應用, 你可以使用 🤗 Accelerate — 讓我們來看看吧!",n,r,G,j,R='正如我們在 <code>Trainer</code> 中看到的, 對掩碼語言模型的微調與 <a href="/course/chapter3">第三章</a> 中的文本分類示例非常相似。事實上, 唯一的微妙之處是使用特殊的數據整理器, 我們已經在本節的前面介紹過了!',W,_,X="然而, 我們看到 <code>DataCollatorForLanguageModeling</code> 還對每次評估應用隨機掩碼, 因此每次訓練運行時, 我們都會看到perplexity度分數的一些波動。消除這種隨機性來源的一種方法是應用掩碼 <em>一次</em> 在整個測試集上, 然後使用🤗 Transformers 中的默認數據整理器在評估期間收集批次。為了看看它是如何工作的, 讓我們實現一個簡單的函數, 將掩碼應用於批處理, 類似於我們第一次遇到的 <code>DataCollatorForLanguageModeling</code>:",k,g,u,Z,z="接下來, 我們將此函數應用於我們的測試集並刪除未掩碼的列, 以便我們可以用掩碼的列替換它們。你可以通過用適當的替換上面的 <code>data_collator</code> 來使整個單詞掩碼, 在這種情況下, 你應該刪除此處的第一行:",Y,C,$,F,B="然後我們可以像往常一樣設置數據加載器, 但我們將使用🤗 Transformers 中的 <code>default_data_collator</code> 作為評估集:",V,Cl,Xl,S,De="從這裡開始, 我們遵循🤗 Accelerate 的標準步驟。第一個任務是加載預訓練模型的新版本:",Wl,N,Ll,O,E="然後我們需要指定優化器; 我們將使用標準的 <code>AdamW</code>:",ql,ll,sl,_l,Dl="有了這些對象, 我們現在可以準備使用 <code>Accelerator</code> 加速器進行訓練的一切:",el,tl,P,al,Gl="現在我們的模型、優化器和數據加載器都配置好了, 我們可以指定學習率調度器如下:",$l,H,Kl,nl,Ul="在訓練之前要做的最後一件事是: 在 Hugging Face Hub 上創建一個模型庫! 我們可以使用 🤗 Hub 庫來首先生成我們的 repo 的全名:",Pl,Ml,pl,Zl,Vl,x,K="然後使用來自🤗 Hub 的 <code>Repository</code> 類:",ol,L,Ol,il,Bl="完成後, 只需寫出完整的訓練和評估循環即可:",zl,q,ls,yl,Jl,rl,gl="很棒, 我們已經能夠評估每個 epoch 的perplexity度, 並確保多次訓練運行是可重複的!",ss;return r=new Sl({props:{title:"使用 🤗 Accelerate 微調 DistilBERT",local:"使用--accelerate-微調-distilbert",headingTag:"h2"}}),g=new h({props:{code:"ZGVmJTIwaW5zZXJ0X3JhbmRvbV9tYXNrKGJhdGNoKSUzQSUwQSUyMCUyMCUyMCUyMGZlYXR1cmVzJTIwJTNEJTIwJTVCZGljdCh6aXAoYmF0Y2glMkMlMjB0KSklMjBmb3IlMjB0JTIwaW4lMjB6aXAoKmJhdGNoLnZhbHVlcygpKSU1RCUwQSUyMCUyMCUyMCUyMG1hc2tlZF9pbnB1dHMlMjAlM0QlMjBkYXRhX2NvbGxhdG9yKGZlYXR1cmVzKSUwQSUyMCUyMCUyMCUyMCUyMyUyMENyZWF0ZSUyMGElMjBuZXclMjAlMjJtYXNrZWQlMjIlMjBjb2x1bW4lMjBmb3IlMjBlYWNoJTIwY29sdW1uJTIwaW4lMjB0aGUlMjBkYXRhc2V0JTBBJTIwJTIwJTIwJTIwcmV0dXJuJTIwJTdCJTIybWFza2VkXyUyMiUyMCUyQiUyMGslM0ElMjB2Lm51bXB5KCklMjBmb3IlMjBrJTJDJTIwdiUyMGluJTIwbWFza2VkX2lucHV0cy5pdGVtcygpJTdE",highlighted:`<span class="hljs-keyword">def</span> <span class="hljs-title function_">insert_random_mask</span>(<span class="hljs-params">batch</span>):
    features = [<span class="hljs-built_in">dict</span>(<span class="hljs-built_in">zip</span>(batch, t)) <span class="hljs-keyword">for</span> t <span class="hljs-keyword">in</span> <span class="hljs-built_in">zip</span>(*batch.values())]
    masked_inputs = data_collator(features)
    <span class="hljs-comment"># Create a new &quot;masked&quot; column for each column in the dataset</span>
    <span class="hljs-keyword">return</span> {<span class="hljs-string">&quot;masked_&quot;</span> + k: v.numpy() <span class="hljs-keyword">for</span> k, v <span class="hljs-keyword">in</span> masked_inputs.items()}`,wrap:!1}}),C=new h({props:{code:"ZG93bnNhbXBsZWRfZGF0YXNldCUyMCUzRCUyMGRvd25zYW1wbGVkX2RhdGFzZXQucmVtb3ZlX2NvbHVtbnMoJTVCJTIyd29yZF9pZHMlMjIlNUQpJTBBZXZhbF9kYXRhc2V0JTIwJTNEJTIwZG93bnNhbXBsZWRfZGF0YXNldCU1QiUyMnRlc3QlMjIlNUQubWFwKCUwQSUyMCUyMCUyMCUyMGluc2VydF9yYW5kb21fbWFzayUyQyUwQSUyMCUyMCUyMCUyMGJhdGNoZWQlM0RUcnVlJTJDJTBBJTIwJTIwJTIwJTIwcmVtb3ZlX2NvbHVtbnMlM0Rkb3duc2FtcGxlZF9kYXRhc2V0JTVCJTIydGVzdCUyMiU1RC5jb2x1bW5fbmFtZXMlMkMlMEEpJTBBZXZhbF9kYXRhc2V0JTIwJTNEJTIwZXZhbF9kYXRhc2V0LnJlbmFtZV9jb2x1bW5zKCUwQSUyMCUyMCUyMCUyMCU3QiUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMm1hc2tlZF9pbnB1dF9pZHMlMjIlM0ElMjAlMjJpbnB1dF9pZHMlMjIlMkMlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjJtYXNrZWRfYXR0ZW50aW9uX21hc2slMjIlM0ElMjAlMjJhdHRlbnRpb25fbWFzayUyMiUyQyUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMm1hc2tlZF9sYWJlbHMlMjIlM0ElMjAlMjJsYWJlbHMlMjIlMkMlMEElMjAlMjAlMjAlMjAlN0QlMEEp",highlighted:`downsampled_dataset = downsampled_dataset.remove_columns([<span class="hljs-string">&quot;word_ids&quot;</span>])
eval_dataset = downsampled_dataset[<span class="hljs-string">&quot;test&quot;</span>].<span class="hljs-built_in">map</span>(
    insert_random_mask,
    batched=<span class="hljs-literal">True</span>,
    remove_columns=downsampled_dataset[<span class="hljs-string">&quot;test&quot;</span>].column_names,
)
eval_dataset = eval_dataset.rename_columns(
    {
        <span class="hljs-string">&quot;masked_input_ids&quot;</span>: <span class="hljs-string">&quot;input_ids&quot;</span>,
        <span class="hljs-string">&quot;masked_attention_mask&quot;</span>: <span class="hljs-string">&quot;attention_mask&quot;</span>,
        <span class="hljs-string">&quot;masked_labels&quot;</span>: <span class="hljs-string">&quot;labels&quot;</span>,
    }
)`,wrap:!1}}),Cl=new h({props:{code:"ZnJvbSUyMHRvcmNoLnV0aWxzLmRhdGElMjBpbXBvcnQlMjBEYXRhTG9hZGVyJTBBZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMGRlZmF1bHRfZGF0YV9jb2xsYXRvciUwQSUwQWJhdGNoX3NpemUlMjAlM0QlMjA2NCUwQXRyYWluX2RhdGFsb2FkZXIlMjAlM0QlMjBEYXRhTG9hZGVyKCUwQSUyMCUyMCUyMCUyMGRvd25zYW1wbGVkX2RhdGFzZXQlNUIlMjJ0cmFpbiUyMiU1RCUyQyUwQSUyMCUyMCUyMCUyMHNodWZmbGUlM0RUcnVlJTJDJTBBJTIwJTIwJTIwJTIwYmF0Y2hfc2l6ZSUzRGJhdGNoX3NpemUlMkMlMEElMjAlMjAlMjAlMjBjb2xsYXRlX2ZuJTNEZGF0YV9jb2xsYXRvciUyQyUwQSklMEFldmFsX2RhdGFsb2FkZXIlMjAlM0QlMjBEYXRhTG9hZGVyKCUwQSUyMCUyMCUyMCUyMGV2YWxfZGF0YXNldCUyQyUyMGJhdGNoX3NpemUlM0RiYXRjaF9zaXplJTJDJTIwY29sbGF0ZV9mbiUzRGRlZmF1bHRfZGF0YV9jb2xsYXRvciUwQSk=",highlighted:`<span class="hljs-keyword">from</span> torch.utils.data <span class="hljs-keyword">import</span> DataLoader
<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> default_data_collator

batch_size = <span class="hljs-number">64</span>
train_dataloader = DataLoader(
    downsampled_dataset[<span class="hljs-string">&quot;train&quot;</span>],
    shuffle=<span class="hljs-literal">True</span>,
    batch_size=batch_size,
    collate_fn=data_collator,
)
eval_dataloader = DataLoader(
    eval_dataset, batch_size=batch_size, collate_fn=default_data_collator
)`,wrap:!1}}),N=new h({props:{code:"bW9kZWwlMjAlM0QlMjBBdXRvTW9kZWxGb3JNYXNrZWRMTS5mcm9tX3ByZXRyYWluZWQobW9kZWxfY2hlY2twb2ludCk=",highlighted:'model = <span class="hljs-module-access"><span class="hljs-module"><span class="hljs-identifier">AutoModelForMaskedLM</span>.</span></span>from<span class="hljs-constructor">_pretrained(<span class="hljs-params">model_checkpoint</span>)</span>',wrap:!1}}),ll=new h({props:{code:"ZnJvbSUyMHRvcmNoLm9wdGltJTIwaW1wb3J0JTIwQWRhbVclMEElMEFvcHRpbWl6ZXIlMjAlM0QlMjBBZGFtVyhtb2RlbC5wYXJhbWV0ZXJzKCklMkMlMjBsciUzRDVlLTUp",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">5e-5</span>)`,wrap:!1}}),tl=new h({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}}),H=new h({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMGdldF9zY2hlZHVsZXIlMEElMEFudW1fdHJhaW5fZXBvY2hzJTIwJTNEJTIwMyUwQW51bV91cGRhdGVfc3RlcHNfcGVyX2Vwb2NoJTIwJTNEJTIwbGVuKHRyYWluX2RhdGFsb2FkZXIpJTBBbnVtX3RyYWluaW5nX3N0ZXBzJTIwJTNEJTIwbnVtX3RyYWluX2Vwb2NocyUyMColMjBudW1fdXBkYXRlX3N0ZXBzX3Blcl9lcG9jaCUwQSUwQWxyX3NjaGVkdWxlciUyMCUzRCUyMGdldF9zY2hlZHVsZXIoJTBBJTIwJTIwJTIwJTIwJTIybGluZWFyJTIyJTJDJTBBJTIwJTIwJTIwJTIwb3B0aW1pemVyJTNEb3B0aW1pemVyJTJDJTBBJTIwJTIwJTIwJTIwbnVtX3dhcm11cF9zdGVwcyUzRDAlMkMlMEElMjAlMjAlMjAlMjBudW1fdHJhaW5pbmdfc3RlcHMlM0RudW1fdHJhaW5pbmdfc3RlcHMlMkMlMEEp",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> get_scheduler

num_train_epochs = <span class="hljs-number">3</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}}),Ml=new h({props:{code:"ZnJvbSUyMGh1Z2dpbmdmYWNlX2h1YiUyMGltcG9ydCUyMGdldF9mdWxsX3JlcG9fbmFtZSUwQSUwQW1vZGVsX25hbWUlMjAlM0QlMjAlMjJkaXN0aWxiZXJ0LWJhc2UtdW5jYXNlZC1maW5ldHVuZWQtaW1kYi1hY2NlbGVyYXRlJTIyJTBBcmVwb19uYW1lJTIwJTNEJTIwZ2V0X2Z1bGxfcmVwb19uYW1lKG1vZGVsX25hbWUpJTBBcmVwb19uYW1l",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;distilbert-base-uncased-finetuned-imdb-accelerate&quot;</span>
repo_name = get_full_repo_name(model_name)
repo_name`,wrap:!1}}),Zl=new h({props:{code:"J2xld3R1biUyRmRpc3RpbGJlcnQtYmFzZS11bmNhc2VkLWZpbmV0dW5lZC1pbWRiLWFjY2VsZXJhdGUn",highlighted:'<span class="hljs-string">&#x27;lewtun/distilbert-base-uncased-finetuned-imdb-accelerate&#x27;</span>',wrap:!1}}),L=new h({props:{code:"ZnJvbSUyMGh1Z2dpbmdmYWNlX2h1YiUyMGltcG9ydCUyMFJlcG9zaXRvcnklMEElMEFvdXRwdXRfZGlyJTIwJTNEJTIwbW9kZWxfbmFtZSUwQXJlcG8lMjAlM0QlMjBSZXBvc2l0b3J5KG91dHB1dF9kaXIlMkMlMjBjbG9uZV9mcm9tJTNEcmVwb19uYW1lKQ==",highlighted:`<span class="hljs-keyword">from</span> huggingface_hub <span class="hljs-keyword">import</span> Repository

output_dir = model_name
repo = Repository(output_dir, clone_from=repo_name)`,wrap:!1}}),q=new h({props:{code:"ZnJvbSUyMHRxZG0uYXV0byUyMGltcG9ydCUyMHRxZG0lMEFpbXBvcnQlMjB0b3JjaCUwQWltcG9ydCUyMG1hdGglMEElMEFwcm9ncmVzc19iYXIlMjAlM0QlMjB0cWRtKHJhbmdlKG51bV90cmFpbmluZ19zdGVwcykpJTBBJTBBZm9yJTIwZXBvY2glMjBpbiUyMHJhbmdlKG51bV90cmFpbl9lcG9jaHMpJTNBJTBBJTIwJTIwJTIwJTIwJTIzJTIwVHJhaW5pbmclMEElMjAlMjAlMjAlMjBtb2RlbC50cmFpbigpJTBBJTIwJTIwJTIwJTIwZm9yJTIwYmF0Y2glMjBpbiUyMHRyYWluX2RhdGFsb2FkZXIlM0ElMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBvdXRwdXRzJTIwJTNEJTIwbW9kZWwoKipiYXRjaCklMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBsb3NzJTIwJTNEJTIwb3V0cHV0cy5sb3NzJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwYWNjZWxlcmF0b3IuYmFja3dhcmQobG9zcyklMEElMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBvcHRpbWl6ZXIuc3RlcCgpJTBBJTIwJTIwJTIwJTIwJT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">import</span> tqdm
<span class="hljs-keyword">import</span> torch
<span class="hljs-keyword">import</span> math

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> batch <span class="hljs-keyword">in</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>()
    losses = []
    <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():
            outputs = model(**batch)

        loss = outputs.loss
        losses.append(accelerator.gather(loss.repeat(batch_size)))

    losses = torch.cat(losses)
    losses = losses[: <span class="hljs-built_in">len</span>(eval_dataset)]
    <span class="hljs-keyword">try</span>:
        perplexity = math.exp(torch.mean(losses))
    <span class="hljs-keyword">except</span> OverflowError:
        perplexity = <span class="hljs-built_in">float</span>(<span class="hljs-string">&quot;inf&quot;</span>)

    <span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;&gt;&gt;&gt; Epoch <span class="hljs-subst">{epoch}</span>: Perplexity: <span class="hljs-subst">{perplexity}</span>&quot;</span>)

    <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}}),yl=new h({props:{code:"RXBvY2glMjAwJTNBJTIwUGVycGxleGl0eSUzQSUyMDExLjM5NzU0NTMwNzkwMDQ3MiUwQUVwb2NoJTIwMSUzQSUyMFBlcnBsZXhpdHklM0ElMjAxMC45MDQ5MDkzMzA5ODMwOTIlMEFFcG9jaCUyMDIlM0ElMjBQZXJwbGV4aXR5JTNBJTIwMTAuNzI5NTAzNTA1MzQwNDA5",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span>Epoch <span class="hljs-number">0</span>: Perplexity: <span class="hljs-number">11.397545307900472</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>Epoch <span class="hljs-number">1</span>: Perplexity: <span class="hljs-number">10.904909330983092</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>Epoch <span class="hljs-number">2</span>: Perplexity: <span class="hljs-number">10.729503505340409</span>`,wrap:!1}}),{c(){a=d("p"),a.textContent=U,n=M(),o(r.$$.fragment),G=M(),j=d("p"),j.innerHTML=R,W=M(),_=d("p"),_.innerHTML=X,k=M(),o(g.$$.fragment),u=M(),Z=d("p"),Z.innerHTML=z,Y=M(),o(C.$$.fragment),$=M(),F=d("p"),F.innerHTML=B,V=M(),o(Cl.$$.fragment),Xl=M(),S=d("p"),S.textContent=De,Wl=M(),o(N.$$.fragment),Ll=M(),O=d("p"),O.innerHTML=E,ql=M(),o(ll.$$.fragment),sl=M(),_l=d("p"),_l.innerHTML=Dl,el=M(),o(tl.$$.fragment),P=M(),al=d("p"),al.textContent=Gl,$l=M(),o(H.$$.fragment),Kl=M(),nl=d("p"),nl.textContent=Ul,Pl=M(),o(Ml.$$.fragment),pl=M(),o(Zl.$$.fragment),Vl=M(),x=d("p"),x.innerHTML=K,ol=M(),o(L.$$.fragment),Ol=M(),il=d("p"),il.textContent=Bl,zl=M(),o(q.$$.fragment),ls=M(),o(yl.$$.fragment),Jl=M(),rl=d("p"),rl.textContent=gl},l(i){a=m(i,"P",{"data-svelte-h":!0}),b(a)!=="svelte-73lwtv"&&(a.textContent=U),n=p(i),c(r.$$.fragment,i),G=p(i),j=m(i,"P",{"data-svelte-h":!0}),b(j)!=="svelte-1eehin8"&&(j.innerHTML=R),W=p(i),_=m(i,"P",{"data-svelte-h":!0}),b(_)!=="svelte-1ryqag4"&&(_.innerHTML=X),k=p(i),c(g.$$.fragment,i),u=p(i),Z=m(i,"P",{"data-svelte-h":!0}),b(Z)!=="svelte-xn1luj"&&(Z.innerHTML=z),Y=p(i),c(C.$$.fragment,i),$=p(i),F=m(i,"P",{"data-svelte-h":!0}),b(F)!=="svelte-1bcvz87"&&(F.innerHTML=B),V=p(i),c(Cl.$$.fragment,i),Xl=p(i),S=m(i,"P",{"data-svelte-h":!0}),b(S)!=="svelte-c8botu"&&(S.textContent=De),Wl=p(i),c(N.$$.fragment,i),Ll=p(i),O=m(i,"P",{"data-svelte-h":!0}),b(O)!=="svelte-13chbev"&&(O.innerHTML=E),ql=p(i),c(ll.$$.fragment,i),sl=p(i),_l=m(i,"P",{"data-svelte-h":!0}),b(_l)!=="svelte-1gq59mc"&&(_l.innerHTML=Dl),el=p(i),c(tl.$$.fragment,i),P=p(i),al=m(i,"P",{"data-svelte-h":!0}),b(al)!=="svelte-zzmeh7"&&(al.textContent=Gl),$l=p(i),c(H.$$.fragment,i),Kl=p(i),nl=m(i,"P",{"data-svelte-h":!0}),b(nl)!=="svelte-bs3zy5"&&(nl.textContent=Ul),Pl=p(i),c(Ml.$$.fragment,i),pl=p(i),c(Zl.$$.fragment,i),Vl=p(i),x=m(i,"P",{"data-svelte-h":!0}),b(x)!=="svelte-1i7l5yg"&&(x.innerHTML=K),ol=p(i),c(L.$$.fragment,i),Ol=p(i),il=m(i,"P",{"data-svelte-h":!0}),b(il)!=="svelte-crn7bt"&&(il.textContent=Bl),zl=p(i),c(q.$$.fragment,i),ls=p(i),c(yl.$$.fragment,i),Jl=p(i),rl=m(i,"P",{"data-svelte-h":!0}),b(rl)!=="svelte-18hjved"&&(rl.textContent=gl)},m(i,f){t(i,a,f),t(i,n,f),T(r,i,f),t(i,G,f),t(i,j,f),t(i,W,f),t(i,_,f),t(i,k,f),T(g,i,f),t(i,u,f),t(i,Z,f),t(i,Y,f),T(C,i,f),t(i,$,f),t(i,F,f),t(i,V,f),T(Cl,i,f),t(i,Xl,f),t(i,S,f),t(i,Wl,f),T(N,i,f),t(i,Ll,f),t(i,O,f),t(i,ql,f),T(ll,i,f),t(i,sl,f),t(i,_l,f),t(i,el,f),T(tl,i,f),t(i,P,f),t(i,al,f),t(i,$l,f),T(H,i,f),t(i,Kl,f),t(i,nl,f),t(i,Pl,f),T(Ml,i,f),t(i,pl,f),T(Zl,i,f),t(i,Vl,f),t(i,x,f),t(i,ol,f),T(L,i,f),t(i,Ol,f),t(i,il,f),t(i,zl,f),T(q,i,f),t(i,ls,f),T(yl,i,f),t(i,Jl,f),t(i,rl,f),ss=!0},i(i){ss||(y(r.$$.fragment,i),y(g.$$.fragment,i),y(C.$$.fragment,i),y(Cl.$$.fragment,i),y(N.$$.fragment,i),y(ll.$$.fragment,i),y(tl.$$.fragment,i),y(H.$$.fragment,i),y(Ml.$$.fragment,i),y(Zl.$$.fragment,i),y(L.$$.fragment,i),y(q.$$.fragment,i),y(yl.$$.fragment,i),ss=!0)},o(i){J(r.$$.fragment,i),J(g.$$.fragment,i),J(C.$$.fragment,i),J(Cl.$$.fragment,i),J(N.$$.fragment,i),J(ll.$$.fragment,i),J(tl.$$.fragment,i),J(H.$$.fragment,i),J(Ml.$$.fragment,i),J(Zl.$$.fragment,i),J(L.$$.fragment,i),J(q.$$.fragment,i),J(yl.$$.fragment,i),ss=!1},d(i){i&&(e(a),e(n),e(G),e(j),e(W),e(_),e(k),e(u),e(Z),e(Y),e($),e(F),e(V),e(Xl),e(S),e(Wl),e(Ll),e(O),e(ql),e(sl),e(_l),e(el),e(P),e(al),e($l),e(Kl),e(nl),e(Pl),e(pl),e(Vl),e(x),e(ol),e(Ol),e(il),e(zl),e(ls),e(Jl),e(rl)),w(r,i),w(g,i),w(C,i),w(Cl,i),w(N,i),w(ll,i),w(tl,i),w(H,i),w(Ml,i),w(Zl,i),w(L,i),w(q,i),w(yl,i)}}}function AM(I){let a,U='✏️ <strong>試試看!</strong> 為了量化域適應的好處, 微調 IMDb 標籤上的分類器和預先訓練和微調的Distil BERT檢查點。如果你需要複習文本分類, 請查看 <a href="/course/chapter3">第三章</a>。';return{c(){a=d("p"),a.innerHTML=U},l(n){a=m(n,"P",{"data-svelte-h":!0}),b(a)!=="svelte-1m7fkud"&&(a.innerHTML=U)},m(n,r){t(n,a,r)},p:Hl,d(n){n&&e(a)}}}function QM(I){let a,U,n,r,G,j,R,W,_,X,k,g,u="對於許多涉及 Transformer 模型的 NLP 程序, 你可以簡單地從 Hugging Face Hub 中獲取一個預訓練的模型, 然後直接在你的數據上對其進行微調, 以完成手頭的任務。只要用於預訓練的語料庫與用於微調的語料庫沒有太大區別, 遷移學習通常會產生很好的結果。",Z,z,Y="但是, 在某些情況下, 你需要先微調數據上的語言模型, 然後再訓練特定於任務的head。例如, 如果您的數據集包含法律合同或科學文章, 像 BERT 這樣的普通 Transformer 模型通常會將您語料庫中的特定領域詞視為稀有標記, 結果性能可能不盡如人意。通過在域內數據上微調語言模型, 你可以提高許多下游任務的性能, 這意味著您通常只需執行一次此步驟!",C,$,F='這種在域內數據上微調預訓練語言模型的過程通常稱為 <em>領域適應</em>。 它於 2018 年由 <a href="https://arxiv.org/abs/1801.06146" rel="nofollow">ULMFiT</a>推廣, 這是使遷移學習真正適用於 NLP 的首批神經架構之一 (基於 LSTM)。 下圖顯示了使用 ULMFiT 進行域自適應的示例; 在本節中, 我們將做類似的事情, 但使用的是 Transformer 而不是 LSTM!',B,V,Cl='<img class="block dark:hidden" src="https://huggingface.co/datasets/huggingface-course/documentation-images/resolve/main/en/chapter7/ulmfit.svg" alt="ULMFiT."/> <img class="hidden dark:block" src="https://huggingface.co/datasets/huggingface-course/documentation-images/resolve/main/en/chapter7/ulmfit-dark.svg" alt="ULMFiT."/>',Xl,S,De='在本節結束時, 你將在Hub上擁有一個<a href="https://huggingface.co/huggingface-course/distilbert-base-uncased-finetuned-imdb?text=This+is+a+great+%5BMASK%5D." rel="nofollow">掩碼語言模型(masked language model)</a>, 該模型可以自動完成句子, 如下所示:',Wl,N,Ll,O,E,ql,ll,sl,_l="讓我們開始吧!",Dl,el,tl,P,al,Gl,$l,H,Kl='首先, 讓我們為掩碼語言建模選擇一個合適的預訓練模型。如以下屏幕截圖所示, 你可以通過在<a href="https://huggingface.co/models?pipeline_tag=fill-mask&amp;sort=downloads" rel="nofollow">Hugging Face Hub</a>上應用”Fill-Mask”過濾器找到:',nl,Ul,Pl='<img src="https://huggingface.co/datasets/huggingface-course/documentation-images/resolve/main/en/chapter7/mlm-models.png" alt="Hub models." width="80%"/>',Ml,pl,Zl=`儘管 BERT 和 RoBERTa 系列模型的下載量最大, 但我們將使用名為 <a href="https://huggingface.co/distilbert-base-uncased" rel="nofollow">DistilBERT</a>的模型。
可以更快地訓練, 而下游性能幾乎沒有損失。這個模型使用一種稱為<a href="https://en.wikipedia.org/wiki/Knowledge_distillation" rel="nofollow"><em>知識蒸餾</em></a>的特殊技術進行訓練, 其中使用像 BERT 這樣的大型“教師模型”來指導參數少得多的“學生模型”的訓練。在本節中對知識蒸餾細節的解釋會使我們離題太遠, 但如果你有興趣, 可以閱讀所有相關內容 <a href="https://www.oreilly.com/library/view/natural-language-processing/9781098136789/" rel="nofollow"><em>Natural Language Processing with Transformers</em></a> (俗稱Transformers教科書)。`,Vl,x,K,ol,L,Ol="DistilBERT 大約有 6700 萬個參數, 大約比 BERT 基本模型小兩倍, 這大致意味著訓練的速度提高了兩倍 — 非常棒! 現在讓我們看看這個模型預測什麼樣的標記最有可能完成一小部分文本:",il,Bl,zl,q,ls='作為人類, 我們可以想象 <code>[MASK]</code> 標記有很多可能性, 例如 “day”、 “ride” 或者 “painting”。對於預訓練模型, 預測取決於模型所訓練的語料庫, 因為它會學習獲取數據中存在的統計模式。與 BERT 一樣, DistilBERT 在<a href="https://huggingface.co/datasets/wikipedia" rel="nofollow">English Wikipedia</a> 和 <a href="https://huggingface.co/datasets/bookcorpus" rel="nofollow">BookCorpus</a> 數據集上進行預訓練, 所以我們期望對 <code>[MASK]</code> 的預測能夠反映這些領域。為了預測掩碼, 我們需要 DistilBERT 的標記器來生成模型的輸入, 所以讓我們也從 Hub 下載它:',yl,Jl,rl,gl,ss="使用標記器和模型, 我們現在可以將我們的文本示例傳遞給模型, 提取 logits, 並打印出前 5 個候選:",i,f,cl,Qe,es,Pe,ts,Ha="我們可以從輸出中看到模型的預測是指日常用語, 鑑於英語維基百科的基礎, 這也許並不奇怪。讓我們看看我們如何將這個領域改變為更小眾的東西 — 高度兩極分化的電影評論!",Oe,as,lt,ns,La='為了展示域適配, 我們將使用著名的<a href="https://huggingface.co/datasets/imdb" rel="nofollow">大型電影評論數據集(Large Movie Review Dataset)</a> (或者簡稱為IMDb), 這是一個電影評論語料庫, 通常用於對情感分析模型進行基準測試。通過在這個語料庫上對 DistilBERT 進行微調, 我們預計語言模型將根據維基百科的事實數據調整其詞彙表, 這些數據已經預先訓練到電影評論中更主觀的元素。我們可以使用🤗 Datasets中的<code>load_dataset()</code>函數從Hugging Face 中獲取數據:',st,Ms,et,ps,tt,is,qa="我們可以看到 <code>train</code> 和 <code>test</code> 每個拆分包含 25,000 條評論, 而有一個未標記的拆分稱為 <code>unsupervised</code> 包含 50,000 條評論。讓我們看一些示例, 以瞭解我們正在處理的文本類型。正如我們在本課程的前幾章中所做的那樣, 我們將鏈接 <code>Dataset.shuffle()</code> 和 <code>Dataset.select()</code> 函數創建隨機樣本:",at,ys,nt,Js,Mt,rs,Da="是的, 這些肯定是電影評論, 如果你年齡足夠,你甚至可能會理解上次評論中關於擁有 VHS 版本的評論😜! 雖然我們不需要語言建模的標籤, 但我們已經可以看到 <code>0</code> 表示負面評論, 而 <code>1</code> 對應正面。",pt,Nl,it,Us,Ka='現在我們已經快速瀏覽了數據, 讓我們深入研究為掩碼語言建模做準備。正如我們將看到的, 與我們在<a href="/course/chapter3">第三章</a>中看到的序列分類任務相比, 還需要採取一些額外的步驟。讓我們繼續!',yt,os,Jt,cs,rt,Ts,Pa="對於自迴歸和掩碼語言建模, 一個常見的預處理步驟是連接所有示例, 然後將整個語料庫拆分為相同大小的塊。 這與我們通常的方法完全不同, 我們只是簡單地標記單個示例。為什麼要將所有內容連接在一起? 原因是單個示例如果太長可能會被截斷, 這將導致丟失可能對語言建模任務有用的信息!",Ut,ws,Oa='因此, 我們將像往常一樣首先標記我們的語料庫, 但是 <em>沒有</em> 在我們的標記器中設置 <code>truncation=True</code> 選項。 我們還將獲取可用的單詞 ID ((如果我們使用快速標記器, 它們是可用的, 如 <a href="/course/chapter6/3">第六章</a>中所述), 因為我們稍後將需要它們來進行全字屏蔽。我們將把它包裝在一個簡單的函數中, 當我們在做的時候, 我們將刪除 <code>text</code> 和 <code>label</code> 列, 因為我們不再需要它們:',ot,ds,ct,ms,Tt,js,ln="由於 DistilBERT 是一個類似 BERT 的模型, 我們可以看到編碼文本由我們在其他章節中看到的 <code>input_ids</code> 和 <code>attention_mask</code> 組成, 以及我們添加的 <code>word_ids</code>。",wt,bs,sn="現在我們已經標記了我們的電影評論, 下一步是將它們組合在一起並將結果分成塊。 但是這些塊應該有多大? 這最終將取決於你可用的 GPU 內存量, 但一個好的起點是查看模型的最大上下文大小是多少。這可以通過檢查標記器的 <code>model_max_length</code> 屬性來判斷:",dt,us,mt,hs,jt,fs,en="該值來自於與檢查點相關聯的 <em>tokenizer_config.json</em> 文件; 在這種情況下, 我們可以看到上下文大小是 512 個標記, 就像 BERT 一樣。",bt,xl,ut,Is,tn="因此, 以便在像Google Colab 那樣的 GPU 上運行我們的實驗, 我們將選擇可以放入內存的更小一些的東西:",ht,Cs,ft,Al,It,_s,an="有趣的來了。為了展示串聯是如何工作的, 讓我們從我們的標記化訓練集中取一些評論並打印出每個評論的標記數量:",Ct,Gs,_t,Zs,Gt,Bs,nn="然後我們可以用一個簡單的字典理解來連接所有例子, 如下所示:",Zt,gs,Bt,ks,gt,Rs,Mn="很棒, 總長度檢查出來了 — 現在, 讓我們將連接的評論拆分為大小為 <code>block_size</code> 的塊。為此, 我們迭代了 <code>concatenated_examples</code> 中的特徵, 並使用列表理解來創建每個特徵的切片。結果是每個特徵的塊字典:",kt,Xs,Rt,Ws,Xt,$s,pn="正如你在這個例子中看到的, 最後一個塊通常會小於最大塊大小。有兩種主要的策略來處理這個問題:",Wt,Vs,yn="<li>如果最後一個塊小於 <code>chunk_size</code>, 請刪除它。</li> <li>填充最後一個塊, 直到其長度等於 <code>chunk_size</code>。</li>",$t,zs,Jn="我們將在這裡採用第一種方法, 因此讓我們將上述所有邏輯包裝在一個函數中, 我們可以將其應用於我們的標記化數據集:",Vt,Ns,zt,xs,rn="注意, 在 <code>group_texts()</code> 的最後一步中, 我們創建了一個新的 <code>labels</code> 列, 它是 <code>input_ids</code> 列的副本。我們很快就會看到, 這是因為在掩碼語言建模中, 目標是預測輸入批次中隨機掩碼的標記, 並通過創建一個 <code>labels</code> 列, 們為我們的語言模型提供了基礎事實以供學習。",Nt,As,Un="現在, 讓我們使用我們可信賴的 <code>Dataset.map()</code> 函數將 <code>group_texts()</code> 應用到我們的標記化數據集:",xt,Qs,At,vs,Qt,Ys,on="你可以看到, 對文本進行分組, 然後對文本進行分塊, 產生的示例比我們最初的 25,000 用於 <code>train</code>和 <code>test</code> 拆分的示例多得多。那是因為我們現在有了涉及 <em>連續標記</em> 的示例, 這些示例跨越了原始語料庫中的多個示例。你可以通過在其中一個塊中查找特殊的 <code>[SEP]</code> 和 <code>[CLS]</code> 標記來明確的看到這一點:",vt,Es,Yt,Fs,Et,Ss,cn="在此示例中, 你可以看到兩篇重疊的電影評論, 一篇關於高中電影, 另一篇關於無家可歸。 讓我們也看看掩碼語言建模的標籤是什麼樣的:",Ft,Hs,St,Ls,Ht,qs,Tn="正如前面的 <code>group_texts()</code> 函數所期望的那樣, 這看起來與解碼後的 <code>input_ids</code> 相同 — 但是我們的模型怎麼可能學到任何東西呢? 我們錯過了一個關鍵步驟: 在輸入中的隨機位置插入 <code>[MASK]</code> 標記! 讓我們看看如何使用特殊的數據整理器在微調期間即時執行此操作。",Lt,Ds,qt,Ks,wn='微調屏蔽語言模型幾乎與微調序列分類模型相同, 就像我們在 <a href="/course/chapter3">第三章</a>所作的那樣。 唯一的區別是我們需要一個特殊的數據整理器, 它可以隨機屏蔽每批文本中的一些標記。幸運的是, 🤗 Transformers 為這項任務準備了專用的 <code>DataCollatorForLanguageModeling</code> 。我們只需要將它轉遞給標記器和一個 <code>mlm_probability</code> 參數, 該參數指定要屏蔽的標記的分數。我們將選擇 15%, 這是 BERT 使用的數量也是文獻中的常見選擇:',Dt,Ps,Kt,Os,dn="要了解隨機掩碼的工作原理, 讓我們向數據整理器提供一些示例。由於它需要一個 <code>dict</code> 的列表, 其中每個 <code>dict</code> 表示單個連續文本塊, 我們首先迭代數據集, 然後再將批次提供給整理器。我們刪除了這個數據整理器的 <code>&quot;word_ids&quot;</code> 鍵, 因為它不需要它:",Pt,le,Ot,se,la,ee,mn="很棒, 成功了! 我們可以看到, <code>[MASK]</code> 標記已隨機插入我們文本中的不同位置。 這些將是我們的模型在訓練期間必須預測的標記 — 數據整理器的美妙之處在於, 它將隨機化每個批次的 <code>[MASK]</code> 插入!",sa,Ql,ea,ve,te,jn="在為掩碼語言建模訓練模型時, 可以使用的一種技術是將整個單詞一起屏蔽, 而不僅僅是單個標記。這種方法稱為 <em>全詞屏蔽</em>。 如果我們想使用全詞屏蔽, 我們需要自己構建一個數據整理器。數據整理器只是一個函數, 它接受一個樣本列表並將它們轉換為一個批次, 所以現在讓我們這樣做吧! 我們將使用之前計算的單詞 ID 在單詞索引和相應標記之間進行映射, 然後隨機決定要屏蔽哪些單詞並將該屏蔽應用於輸入。請注意, 除了與掩碼對應的標籤外, 所有的標籤均為 <code>-100</code>。",ta,Tl,wl,Ye,ae,bn="Next, we can try it on the same samples as before:",aa,ne,na,Me,Ma,vl,pa,pe,un='現在我們有兩個數據整理器, 其餘的微調步驟是標準的。如果您沒有足夠幸運地獲得神話般的 P100 GPU 😭, 在 Google Colab 上進行訓練可能需要一段時間, 因此我們將首先將訓練集的大小縮減為幾千個示例。別擔心, 我們仍然會得到一個相當不錯的語言模型! 在 🤗 Datasets 中快速下采樣數據集的方法是通過我們在 <a href="/course/chapter5">第五章</a> 中看到的 <code>Dataset.train_test_split()</code> 函數:',ia,ie,ya,ye,Ja,Je,hn="這會自動創建新的 <code>train</code> 和 <code>test</code> 拆分, 訓練集大小設置為 10,000 個示例, 驗證設置為其中的 10% — 如果你有一個強大的 GPU, 可以隨意增加它! 我們需要做的下一件事是登錄 Hugging Face Hub。如果你在筆記本中運行此代碼, 則可以使用以下實用程序函數執行此操作:",ra,re,Ua,Ue,fn="這將顯示一個小部件, 你可以在其中輸入你的憑據。或者, 你可以運行:",oa,oe,ca,ce,In="在你最喜歡的終端中登錄。",Ta,dl,ml,Ee,Te,wa,we,da,de,Cn="與文本分類或問答等其他任務不同, 在這些任務中, 我們會得到一個帶標籤的語料庫進行訓練, 而語言建模則沒有任何明確的標籤。那麼我們如何確定什麼是好的語言模型呢? 就像手機中的自動更正功能一樣, 一個好的語言模型是為語法正確的句子分配高概率, 為無意義的句子分配低概率。為了讓你更好地瞭解這是什麼樣子, 您可以在網上找到一整套 “autocorrect fails”, 其中一個人手機中的模型產生了一些相當有趣 (而且通常不合適) 的結果!",ma,jl,bl,Fe,me,ja,je,_n="較低的perplexity分數意味著更好的語言模型, 我們可以在這裡看到我們的起始模型有一個較大的值。看看我們能不能通過微調來降低它! 為此, 我們首先運行訓練循環:",ba,ul,hl,Se,be,Gn="然後像以前一樣計算測試集上的perplexity度:",ua,fl,Il,He,ue,ha,he,Zn="很好 — 這大大減少了困惑, 這告訴我們模型已經瞭解了一些關於電影評論領域的知識!",fa,Le,Yl,Ia,qe,fe,Ca,Ie,Bn="你可以通過在Hub上使用其他小部件或在本地使用🤗 Transformers 的<code>管道</code>於微調模型進行交互。讓我們使用後者來下載我們的模型, 使用 <code>fill-mask</code> 管道:",_a,Ce,Ga,_e,gn="然後, 我們可以向管道提供 “This is a great [MASK]” 示例文本, 並查看前 5 個預測是什麼:",Za,Ge,Ba,Ze,ga,Be,kn="好的 — 我們的模型顯然已經調整了它的權重來預測與電影更密切相關的詞!",ka,ge,Ra,ke,Rn='這結束了我們訓練語言模型的第一個實驗。在 <a href="/course/chapter7/section6">第六節</a>中你將學習如何從頭開始訓練像 GPT-2 這樣的自迴歸模型; 如果你想了解如何預訓練您自己的 Transformer 模型, 請前往那裡!',Xa,El,Wa,Re,$a,Ke,Va;G=new TM({props:{fw:I[0]}}),R=new Sl({props:{title:"微調掩碼語言模型",local:"微調掩碼語言模型",headingTag:"h1"}});const Xn=[mM,dM],Xe=[];function Wn(l,s){return l[0]==="pt"?0:1}_=Wn(I),X=Xe[_]=Xn[_](I),el=new Na({props:{id:"mqElG5QJWUg"}}),P=new Fl({props:{$$slots:{default:[jM]},$$scope:{ctx:I}}}),Gl=new Sl({props:{title:"選擇用於掩碼語言建模的預訓練模型",local:"選擇用於掩碼語言建模的預訓練模型",headingTag:"h2"}});const $n=[uM,bM],We=[];function Vn(l,s){return l[0]==="pt"?0:1}x=Vn(I),K=We[x]=$n[x](I),Bl=new h({props:{code:"dGV4dCUyMCUzRCUyMCUyMlRoaXMlMjBpcyUyMGElMjBncmVhdCUyMCU1Qk1BU0slNUQuJTIy",highlighted:'text = <span class="hljs-string">&quot;This is a great [MASK].&quot;</span>',wrap:!1}}),Jl=new h({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMEF1dG9Ub2tlbml6ZXIlMEElMEF0b2tlbml6ZXIlMjAlM0QlMjBBdXRvVG9rZW5pemVyLmZyb21fcHJldHJhaW5lZChtb2RlbF9jaGVja3BvaW50KQ==",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoTokenizer

tokenizer = AutoTokenizer.from_pretrained(model_checkpoint)`,wrap:!1}});const zn=[fM,hM],$e=[];function Nn(l,s){return l[0]==="pt"?0:1}f=Nn(I),cl=$e[f]=zn[f](I),es=new h({props:{code:"JyUzRSUzRSUzRSUyMFRoaXMlMjBpcyUyMGElMjBncmVhdCUyMGRlYWwuJyUwQSclM0UlM0UlM0UlMjBUaGlzJTIwaXMlMjBhJTIwZ3JlYXQlMjBzdWNjZXNzLiclMEEnJTNFJTNFJTNFJTIwVGhpcyUyMGlzJTIwYSUyMGdyZWF0JTIwYWR2ZW50dXJlLiclMEEnJTNFJTNFJTNFJTIwVGhpcyUyMGlzJTIwYSUyMGdyZWF0JTIwaWRlYS4nJTBBJyUzRSUzRSUzRSUyMFRoaXMlMjBpcyUyMGElMjBncmVhdCUyMGZlYXQuJw==",highlighted:`<span class="hljs-string">&#x27;&gt;&gt;&gt; This is a great deal.&#x27;</span>
<span class="hljs-string">&#x27;&gt;&gt;&gt; This is a great success.&#x27;</span>
<span class="hljs-string">&#x27;&gt;&gt;&gt; This is a great adventure.&#x27;</span>
<span class="hljs-string">&#x27;&gt;&gt;&gt; This is a great idea.&#x27;</span>
<span class="hljs-string">&#x27;&gt;&gt;&gt; This is a great feat.&#x27;</span>`,wrap:!1}}),as=new Sl({props:{title:"數據集",local:"數據集",headingTag:"h2"}}),Ms=new h({props:{code:"ZnJvbSUyMGRhdGFzZXRzJTIwaW1wb3J0JTIwbG9hZF9kYXRhc2V0JTBBJTBBaW1kYl9kYXRhc2V0JTIwJTNEJTIwbG9hZF9kYXRhc2V0KCUyMmltZGIlMjIpJTBBaW1kYl9kYXRhc2V0",highlighted:`<span class="hljs-keyword">from</span> datasets <span class="hljs-keyword">import</span> load_dataset

imdb_dataset = load_dataset(<span class="hljs-string">&quot;imdb&quot;</span>)
imdb_dataset`,wrap:!1}}),ps=new h({props:{code:"RGF0YXNldERpY3QoJTdCJTBBJTIwJTIwJTIwJTIwdHJhaW4lM0ElMjBEYXRhc2V0KCU3QiUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMGZlYXR1cmVzJTNBJTIwJTVCJ3RleHQnJTJDJTIwJ2xhYmVsJyU1RCUyQyUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMG51bV9yb3dzJTNBJTIwMjUwMDAlMEElMjAlMjAlMjAlMjAlN0QpJTBBJTIwJTIwJTIwJTIwdGVzdCUzQSUyMERhdGFzZXQoJTdCJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwZmVhdHVyZXMlM0ElMjAlNUIndGV4dCclMkMlMjAnbGFiZWwnJTVEJTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwbnVtX3Jvd3MlM0ElMjAyNTAwMCUwQSUyMCUyMCUyMCUyMCU3RCklMEElMjAlMjAlMjAlMjB1bnN1cGVydmlzZWQlM0ElMjBEYXRhc2V0KCU3QiUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMGZlYXR1cmVzJTNBJTIwJTVCJ3RleHQnJTJDJTIwJ2xhYmVsJyU1RCUyQyUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMG51bV9yb3dzJTNBJTIwNTAwMDAlMEElMjAlMjAlMjAlMjAlN0QpJTBBJTdEKQ==",highlighted:`DatasetDict({
    train: Dataset({
        features: [<span class="hljs-string">&#x27;text&#x27;</span>, <span class="hljs-string">&#x27;label&#x27;</span>],
        num_rows: <span class="hljs-number">25000</span>
    })
    test: Dataset({
        features: [<span class="hljs-string">&#x27;text&#x27;</span>, <span class="hljs-string">&#x27;label&#x27;</span>],
        num_rows: <span class="hljs-number">25000</span>
    })
    unsupervised: Dataset({
        features: [<span class="hljs-string">&#x27;text&#x27;</span>, <span class="hljs-string">&#x27;label&#x27;</span>],
        num_rows: <span class="hljs-number">50000</span>
    })
})`,wrap:!1}}),ys=new h({props:{code:"c2FtcGxlJTIwJTNEJTIwaW1kYl9kYXRhc2V0JTVCJTIydHJhaW4lMjIlNUQuc2h1ZmZsZShzZWVkJTNENDIpLnNlbGVjdChyYW5nZSgzKSklMEElMEFmb3IlMjByb3clMjBpbiUyMHNhbXBsZSUzQSUwQSUyMCUyMCUyMCUyMHByaW50KGYlMjIlNUNuJyUzRSUzRSUzRSUyMFJldmlldyUzQSUyMCU3QnJvdyU1Qid0ZXh0JyU1RCU3RCclMjIpJTBBJTIwJTIwJTIwJTIwcHJpbnQoZiUyMiclM0UlM0UlM0UlMjBMYWJlbCUzQSUyMCU3QnJvdyU1QidsYWJlbCclNUQlN0QnJTIyKQ==",highlighted:`sample = imdb_dataset[<span class="hljs-string">&quot;train&quot;</span>].shuffle(seed=<span class="hljs-number">42</span>).select(<span class="hljs-built_in">range</span>(<span class="hljs-number">3</span>))

<span class="hljs-keyword">for</span> row <span class="hljs-keyword">in</span> sample:
    <span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;\\n&#x27;&gt;&gt;&gt; Review: <span class="hljs-subst">{row[<span class="hljs-string">&#x27;text&#x27;</span>]}</span>&#x27;&quot;</span>)
    <span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;&#x27;&gt;&gt;&gt; Label: <span class="hljs-subst">{row[<span class="hljs-string">&#x27;label&#x27;</span>]}</span>&#x27;&quot;</span>)`,wrap:!1}}),Js=new h({props:{code:" ",highlighted:`
<span class="hljs-string">&#x27;&gt;&gt;&gt; Review: This is your typical Priyadarshan movie--a bunch of loony characters out on some silly mission. His signature climax has the entire cast of the film coming together and fighting each other in some crazy moshpit over hidden money. Whether it is a winning lottery ticket in Malamaal Weekly, black money in Hera Pheri, &quot;kodokoo&quot; in Phir Hera Pheri, etc., etc., the director is becoming ridiculously predictable. Don\\&#x27;t get me wrong; as clichéd and preposterous his movies may be, I usually end up enjoying the comedy. However, in most his previous movies there has actually been some good humor, (Hungama and Hera Pheri being noteworthy ones). Now, the hilarity of his films is fading as he is using the same formula over and over again.&lt;br /&gt;&lt;br /&gt;Songs are good. Tanushree Datta looks awesome. Rajpal Yadav is irritating, and Tusshar is not a whole lot better. Kunal Khemu is OK, and Sharman Joshi is the best.&#x27;</span>
<span class="hljs-string">&#x27;&gt;&gt;&gt; Label: 0&#x27;</span>

<span class="hljs-string">&#x27;&gt;&gt;&gt; Review: Okay, the story makes no sense, the characters lack any dimensionally, the best dialogue is ad-libs about the low quality of movie, the cinematography is dismal, and only editing saves a bit of the muddle, but Sam&quot; Peckinpah directed the film. Somehow, his direction is not enough. For those who appreciate Peckinpah and his great work, this movie is a disappointment. Even a great cast cannot redeem the time the viewer wastes with this minimal effort.&lt;br /&gt;&lt;br /&gt;The proper response to the movie is the contempt that the director San Peckinpah, James Caan, Robert Duvall, Burt Young, Bo Hopkins, Arthur Hill, and even Gig Young bring to their work. Watch the great Peckinpah films. Skip this mess.&#x27;</span>
<span class="hljs-string">&#x27;&gt;&gt;&gt; Label: 0&#x27;</span>

<span class="hljs-string">&#x27;&gt;&gt;&gt; Review: I saw this movie at the theaters when I was about 6 or 7 years old. I loved it then, and have recently come to own a VHS version. &lt;br /&gt;&lt;br /&gt;My 4 and 6 year old children love this movie and have been asking again and again to watch it. &lt;br /&gt;&lt;br /&gt;I have enjoyed watching it again too. Though I have to admit it is not as good on a little TV.&lt;br /&gt;&lt;br /&gt;I do not have older children so I do not know what they would think of it. &lt;br /&gt;&lt;br /&gt;The songs are very cute. My daughter keeps singing them over and over.&lt;br /&gt;&lt;br /&gt;Hope this helps.&#x27;</span>
<span class="hljs-string">&#x27;&gt;&gt;&gt; Label: 1&#x27;</span>`,wrap:!1}}),Nl=new Fl({props:{$$slots:{default:[IM]},$$scope:{ctx:I}}}),os=new Sl({props:{title:"預處理數據",local:"預處理數據",headingTag:"h2"}}),cs=new Na({props:{id:"8PmhEIXhBvI"}}),ds=new h({props:{code:"ZGVmJTIwdG9rZW5pemVfZnVuY3Rpb24oZXhhbXBsZXMpJTNBJTBBJTIwJTIwJTIwJTIwcmVzdWx0JTIwJTNEJTIwdG9rZW5pemVyKGV4YW1wbGVzJTVCJTIydGV4dCUyMiU1RCklMEElMjAlMjAlMjAlMjBpZiUyMHRva2VuaXplci5pc19mYXN0JTNBJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwcmVzdWx0JTVCJTIyd29yZF9pZHMlMjIlNUQlMjAlM0QlMjAlNUJyZXN1bHQud29yZF9pZHMoaSklMjBmb3IlMjBpJTIwaW4lMjByYW5nZShsZW4ocmVzdWx0JTVCJTIyaW5wdXRfaWRzJTIyJTVEKSklNUQlMEElMjAlMjAlMjAlMjByZXR1cm4lMjByZXN1bHQlMEElMEElMEElMjMlMjBVc2UlMjBiYXRjaGVkJTNEVHJ1ZSUyMHRvJTIwYWN0aXZhdGUlMjBmYXN0JTIwbXVsdGl0aHJlYWRpbmchJTBBdG9rZW5pemVkX2RhdGFzZXRzJTIwJTNEJTIwaW1kYl9kYXRhc2V0Lm1hcCglMEElMjAlMjAlMjAlMjB0b2tlbml6ZV9mdW5jdGlvbiUyQyUyMGJhdGNoZWQlM0RUcnVlJTJDJTIwcmVtb3ZlX2NvbHVtbnMlM0QlNUIlMjJ0ZXh0JTIyJTJDJTIwJTIybGFiZWwlMjIlNUQlMEEpJTBBdG9rZW5pemVkX2RhdGFzZXRz",highlighted:`<span class="hljs-keyword">def</span> <span class="hljs-title function_">tokenize_function</span>(<span class="hljs-params">examples</span>):
    result = tokenizer(examples[<span class="hljs-string">&quot;text&quot;</span>])
    <span class="hljs-keyword">if</span> tokenizer.is_fast:
        result[<span class="hljs-string">&quot;word_ids&quot;</span>] = [result.word_ids(i) <span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> <span class="hljs-built_in">range</span>(<span class="hljs-built_in">len</span>(result[<span class="hljs-string">&quot;input_ids&quot;</span>]))]
    <span class="hljs-keyword">return</span> result


<span class="hljs-comment"># Use batched=True to activate fast multithreading!</span>
tokenized_datasets = imdb_dataset.<span class="hljs-built_in">map</span>(
    tokenize_function, batched=<span class="hljs-literal">True</span>, remove_columns=[<span class="hljs-string">&quot;text&quot;</span>, <span class="hljs-string">&quot;label&quot;</span>]
)
tokenized_datasets`,wrap:!1}}),ms=new h({props:{code:"RGF0YXNldERpY3QoJTdCJTBBJTIwJTIwJTIwJTIwdHJhaW4lM0ElMjBEYXRhc2V0KCU3QiUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMGZlYXR1cmVzJTNBJTIwJTVCJ2F0dGVudGlvbl9tYXNrJyUyQyUyMCdpbnB1dF9pZHMnJTJDJTIwJ3dvcmRfaWRzJyU1RCUyQyUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMG51bV9yb3dzJTNBJTIwMjUwMDAlMEElMjAlMjAlMjAlMjAlN0QpJTBBJTIwJTIwJTIwJTIwdGVzdCUzQSUyMERhdGFzZXQoJTdCJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwZmVhdHVyZXMlM0ElMjAlNUInYXR0ZW50aW9uX21hc2snJTJDJTIwJ2lucHV0X2lkcyclMkMlMjAnd29yZF9pZHMnJTVEJTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwbnVtX3Jvd3MlM0ElMjAyNTAwMCUwQSUyMCUyMCUyMCUyMCU3RCklMEElMjAlMjAlMjAlMjB1bnN1cGVydmlzZWQlM0ElMjBEYXRhc2V0KCU3QiUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMGZlYXR1cmVzJTNBJTIwJTVCJ2F0dGVudGlvbl9tYXNrJyUyQyUyMCdpbnB1dF9pZHMnJTJDJTIwJ3dvcmRfaWRzJyU1RCUyQyUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMG51bV9yb3dzJTNBJTIwNTAwMDAlMEElMjAlMjAlMjAlMjAlN0QpJTBBJTdEKQ==",highlighted:`DatasetDict({
    train: Dataset({
        features: [<span class="hljs-string">&#x27;attention_mask&#x27;</span>, <span class="hljs-string">&#x27;input_ids&#x27;</span>, <span class="hljs-string">&#x27;word_ids&#x27;</span>],
        num_rows: <span class="hljs-number">25000</span>
    })
    test: Dataset({
        features: [<span class="hljs-string">&#x27;attention_mask&#x27;</span>, <span class="hljs-string">&#x27;input_ids&#x27;</span>, <span class="hljs-string">&#x27;word_ids&#x27;</span>],
        num_rows: <span class="hljs-number">25000</span>
    })
    unsupervised: Dataset({
        features: [<span class="hljs-string">&#x27;attention_mask&#x27;</span>, <span class="hljs-string">&#x27;input_ids&#x27;</span>, <span class="hljs-string">&#x27;word_ids&#x27;</span>],
        num_rows: <span class="hljs-number">50000</span>
    })
})`,wrap:!1}}),us=new h({props:{code:"dG9rZW5pemVyLm1vZGVsX21heF9sZW5ndGg=",highlighted:"tokenizer.model_max_length",wrap:!1}}),hs=new h({props:{code:"NTEy",highlighted:'<span class="hljs-number">512</span>',wrap:!1}}),xl=new Fl({props:{$$slots:{default:[CM]},$$scope:{ctx:I}}}),Cs=new h({props:{code:"Y2h1bmtfc2l6ZSUyMCUzRCUyMDEyOA==",highlighted:'chunk_size = <span class="hljs-number">128</span>',wrap:!1}}),Al=new Fl({props:{warning:!0,$$slots:{default:[_M]},$$scope:{ctx:I}}}),Gs=new h({props:{code:"JTIzJTIwU2xpY2luZyUyMHByb2R1Y2VzJTIwYSUyMGxpc3QlMjBvZiUyMGxpc3RzJTIwZm9yJTIwZWFjaCUyMGZlYXR1cmUlMEF0b2tlbml6ZWRfc2FtcGxlcyUyMCUzRCUyMHRva2VuaXplZF9kYXRhc2V0cyU1QiUyMnRyYWluJTIyJTVEJTVCJTNBMyU1RCUwQSUwQWZvciUyMGlkeCUyQyUyMHNhbXBsZSUyMGluJTIwZW51bWVyYXRlKHRva2VuaXplZF9zYW1wbGVzJTVCJTIyaW5wdXRfaWRzJTIyJTVEKSUzQSUwQSUyMCUyMCUyMCUyMHByaW50KGYlMjInJTNFJTNFJTNFJTIwUmV2aWV3JTIwJTdCaWR4JTdEJTIwbGVuZ3RoJTNBJTIwJTdCbGVuKHNhbXBsZSklN0QnJTIyKQ==",highlighted:`<span class="hljs-comment"># Slicing produces a list of lists for each feature</span>
tokenized_samples = tokenized_datasets[<span class="hljs-string">&quot;train&quot;</span>][:<span class="hljs-number">3</span>]

<span class="hljs-keyword">for</span> idx, sample <span class="hljs-keyword">in</span> <span class="hljs-built_in">enumerate</span>(tokenized_samples[<span class="hljs-string">&quot;input_ids&quot;</span>]):
    <span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;&#x27;&gt;&gt;&gt; Review <span class="hljs-subst">{idx}</span> length: <span class="hljs-subst">{<span class="hljs-built_in">len</span>(sample)}</span>&#x27;&quot;</span>)`,wrap:!1}}),Zs=new h({props:{code:"JyUzRSUzRSUzRSUyMFJldmlldyUyMDAlMjBsZW5ndGglM0ElMjAyMDAnJTBBJyUzRSUzRSUzRSUyMFJldmlldyUyMDElMjBsZW5ndGglM0ElMjA1NTknJTBBJyUzRSUzRSUzRSUyMFJldmlldyUyMDIlMjBsZW5ndGglM0ElMjAxOTIn",highlighted:`<span class="hljs-string">&#x27;&gt;&gt;&gt; Review 0 length: 200&#x27;</span>
<span class="hljs-string">&#x27;&gt;&gt;&gt; Review 1 length: 559&#x27;</span>
<span class="hljs-string">&#x27;&gt;&gt;&gt; Review 2 length: 192&#x27;</span>`,wrap:!1}}),gs=new h({props:{code:"Y29uY2F0ZW5hdGVkX2V4YW1wbGVzJTIwJTNEJTIwJTdCJTBBJTIwJTIwJTIwJTIwayUzQSUyMHN1bSh0b2tlbml6ZWRfc2FtcGxlcyU1QmslNUQlMkMlMjAlNUIlNUQpJTIwZm9yJTIwayUyMGluJTIwdG9rZW5pemVkX3NhbXBsZXMua2V5cygpJTBBJTdEJTBBdG90YWxfbGVuZ3RoJTIwJTNEJTIwbGVuKGNvbmNhdGVuYXRlZF9leGFtcGxlcyU1QiUyMmlucHV0X2lkcyUyMiU1RCklMEFwcmludChmJTIyJyUzRSUzRSUzRSUyMENvbmNhdGVuYXRlZCUyMHJldmlld3MlMjBsZW5ndGglM0ElMjAlN0J0b3RhbF9sZW5ndGglN0QnJTIyKQ==",highlighted:`concatenated_examples = {
    k: <span class="hljs-built_in">sum</span>(tokenized_samples[k], []) <span class="hljs-keyword">for</span> k <span class="hljs-keyword">in</span> tokenized_samples.keys()
}
total_length = <span class="hljs-built_in">len</span>(concatenated_examples[<span class="hljs-string">&quot;input_ids&quot;</span>])
<span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;&#x27;&gt;&gt;&gt; Concatenated reviews length: <span class="hljs-subst">{total_length}</span>&#x27;&quot;</span>)`,wrap:!1}}),ks=new h({props:{code:"JyUzRSUzRSUzRSUyMENvbmNhdGVuYXRlZCUyMHJldmlld3MlMjBsZW5ndGglM0ElMjA5NTEn",highlighted:'<span class="hljs-string">&#x27;&gt;&gt;&gt; Concatenated reviews length: 951&#x27;</span>',wrap:!1}}),Xs=new h({props:{code:"Y2h1bmtzJTIwJTNEJTIwJTdCJTBBJTIwJTIwJTIwJTIwayUzQSUyMCU1QnQlNUJpJTIwJTNBJTIwaSUyMCUyQiUyMGNodW5rX3NpemUlNUQlMjBmb3IlMjBpJTIwaW4lMjByYW5nZSgwJTJDJTIwdG90YWxfbGVuZ3RoJTJDJTIwY2h1bmtfc2l6ZSklNUQlMEElMjAlMjAlMjAlMjBmb3IlMjBrJTJDJTIwdCUyMGluJTIwY29uY2F0ZW5hdGVkX2V4YW1wbGVzLml0ZW1zKCklMEElN0QlMEElMEFmb3IlMjBjaHVuayUyMGluJTIwY2h1bmtzJTVCJTIyaW5wdXRfaWRzJTIyJTVEJTNBJTBBJTIwJTIwJTIwJTIwcHJpbnQoZiUyMiclM0UlM0UlM0UlMjBDaHVuayUyMGxlbmd0aCUzQSUyMCU3QmxlbihjaHVuayklN0QnJTIyKQ==",highlighted:`chunks = {
    k: [t[i : i + chunk_size] <span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> <span class="hljs-built_in">range</span>(<span class="hljs-number">0</span>, total_length, chunk_size)]
    <span class="hljs-keyword">for</span> k, t <span class="hljs-keyword">in</span> concatenated_examples.items()
}

<span class="hljs-keyword">for</span> chunk <span class="hljs-keyword">in</span> chunks[<span class="hljs-string">&quot;input_ids&quot;</span>]:
    <span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;&#x27;&gt;&gt;&gt; Chunk length: <span class="hljs-subst">{<span class="hljs-built_in">len</span>(chunk)}</span>&#x27;&quot;</span>)`,wrap:!1}}),Ws=new h({props:{code:"JyUzRSUzRSUzRSUyMENodW5rJTIwbGVuZ3RoJTNBJTIwMTI4JyUwQSclM0UlM0UlM0UlMjBDaHVuayUyMGxlbmd0aCUzQSUyMDEyOCclMEEnJTNFJTNFJTNFJTIwQ2h1bmslMjBsZW5ndGglM0ElMjAxMjgnJTBBJyUzRSUzRSUzRSUyMENodW5rJTIwbGVuZ3RoJTNBJTIwMTI4JyUwQSclM0UlM0UlM0UlMjBDaHVuayUyMGxlbmd0aCUzQSUyMDEyOCclMEEnJTNFJTNFJTNFJTIwQ2h1bmslMjBsZW5ndGglM0ElMjAxMjgnJTBBJyUzRSUzRSUzRSUyMENodW5rJTIwbGVuZ3RoJTNBJTIwMTI4JyUwQSclM0UlM0UlM0UlMjBDaHVuayUyMGxlbmd0aCUzQSUyMDU1Jw==",highlighted:`<span class="hljs-string">&#x27;&gt;&gt;&gt; Chunk length: 128&#x27;</span>
<span class="hljs-string">&#x27;&gt;&gt;&gt; Chunk length: 128&#x27;</span>
<span class="hljs-string">&#x27;&gt;&gt;&gt; Chunk length: 128&#x27;</span>
<span class="hljs-string">&#x27;&gt;&gt;&gt; Chunk length: 128&#x27;</span>
<span class="hljs-string">&#x27;&gt;&gt;&gt; Chunk length: 128&#x27;</span>
<span class="hljs-string">&#x27;&gt;&gt;&gt; Chunk length: 128&#x27;</span>
<span class="hljs-string">&#x27;&gt;&gt;&gt; Chunk length: 128&#x27;</span>
<span class="hljs-string">&#x27;&gt;&gt;&gt; Chunk length: 55&#x27;</span>`,wrap:!1}}),Ns=new h({props:{code:"ZGVmJTIwZ3JvdXBfdGV4dHMoZXhhbXBsZXMpJTNBJTBBJTIwJTIwJTIwJTIwJTI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wbGVzLml0ZW1zKCklMEElMjAlMjAlMjAlMjAlN0QlMEElMjAlMjAlMjAlMjAlMjMlMjBDcmVhdGUlMjBhJTIwbmV3JTIwbGFiZWxzJTIwY29sdW1uJTBBJTIwJTIwJTIwJTIwcmVzdWx0JTVCJTIybGFiZWxzJTIyJTVEJTIwJTNEJTIwcmVzdWx0JTVCJTIyaW5wdXRfaWRzJTIyJTVELmNvcHkoKSUwQSUyMCUyMCUyMCUyMHJldHVybiUyMHJlc3VsdA==",highlighted:`<span class="hljs-keyword">def</span> <span class="hljs-title function_">group_texts</span>(<span class="hljs-params">examples</span>):
    <span class="hljs-comment"># Concatenate all texts</span>
    concatenated_examples = {k: <span class="hljs-built_in">sum</span>(examples[k], []) <span class="hljs-keyword">for</span> k <span class="hljs-keyword">in</span> examples.keys()}
    <span class="hljs-comment"># Compute length of concatenated texts</span>
    total_length = <span class="hljs-built_in">len</span>(concatenated_examples[<span class="hljs-built_in">list</span>(examples.keys())[<span class="hljs-number">0</span>]])
    <span class="hljs-comment"># We drop the last chunk if it&#x27;s smaller than chunk_size</span>
    total_length = (total_length // chunk_size) * chunk_size
    <span class="hljs-comment"># Split by chunks of max_len</span>
    result = {
        k: [t[i : i + chunk_size] <span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> <span class="hljs-built_in">range</span>(<span class="hljs-number">0</span>, total_length, chunk_size)]
        <span class="hljs-keyword">for</span> k, t <span class="hljs-keyword">in</span> concatenated_examples.items()
    }
    <span class="hljs-comment"># Create a new labels column</span>
    result[<span class="hljs-string">&quot;labels&quot;</span>] = result[<span class="hljs-string">&quot;input_ids&quot;</span>].copy()
    <span class="hljs-keyword">return</span> result`,wrap:!1}}),Qs=new h({props:{code:"bG1fZGF0YXNldHMlMjAlM0QlMjB0b2tlbml6ZWRfZGF0YXNldHMubWFwKGdyb3VwX3RleHRzJTJDJTIwYmF0Y2hlZCUzRFRydWUpJTBBbG1fZGF0YXNldHM=",highlighted:`lm_datasets = tokenized_datasets.<span class="hljs-built_in">map</span>(group_texts, batched=<span class="hljs-literal">True</span>)
lm_datasets`,wrap:!1}}),vs=new h({props:{code:"RGF0YXNldERpY3QoJTdCJTBBJTIwJTIwJTIwJTIwdHJhaW4lM0ElMjBEYXRhc2V0KCU3QiUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMGZlYXR1cmVzJTNBJTIwJTVCJ2F0dGVudGlvbl9tYXNrJyUyQyUyMCdpbnB1dF9pZHMnJTJDJTIwJ2xhYmVscyclMkMlMjAnd29yZF9pZHMnJTVEJTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwbnVtX3Jvd3MlM0ElMjA2MTI4OSUwQSUyMCUyMCUyMCUyMCU3RCklMEElMjAlMjAlMjAlMjB0ZXN0JTNBJTIwRGF0YXNldCglN0IlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBmZWF0dXJlcyUzQSUyMCU1QidhdHRlbnRpb25fbWFzayclMkMlMjAnaW5wdXRfaWRzJyUyQyUyMCdsYWJlbHMnJTJDJTIwJ3dvcmRfaWRzJyU1RCUyQyUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMG51bV9yb3dzJTNBJTIwNTk5MDUlMEElMjAlMjAlMjAlMjAlN0QpJTBBJTIwJTIwJTIwJTIwdW5zdXBlcnZpc2VkJTNBJTIwRGF0YXNldCglN0IlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBmZWF0dXJlcyUzQSUyMCU1QidhdHRlbnRpb25fbWFzayclMkMlMjAnaW5wdXRfaWRzJyUyQyUyMCdsYWJlbHMnJTJDJTIwJ3dvcmRfaWRzJyU1RCUyQyUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMG51bV9yb3dzJTNBJTIwMTIyOTYzJTBBJTIwJTIwJTIwJTIwJTdEKSUwQSU3RCk=",highlighted:`DatasetDict({
    train: Dataset({
        features: [<span class="hljs-string">&#x27;attention_mask&#x27;</span>, <span class="hljs-string">&#x27;input_ids&#x27;</span>, <span class="hljs-string">&#x27;labels&#x27;</span>, <span class="hljs-string">&#x27;word_ids&#x27;</span>],
        num_rows: <span class="hljs-number">61289</span>
    })
    test: Dataset({
        features: [<span class="hljs-string">&#x27;attention_mask&#x27;</span>, <span class="hljs-string">&#x27;input_ids&#x27;</span>, <span class="hljs-string">&#x27;labels&#x27;</span>, <span class="hljs-string">&#x27;word_ids&#x27;</span>],
        num_rows: <span class="hljs-number">59905</span>
    })
    unsupervised: Dataset({
        features: [<span class="hljs-string">&#x27;attention_mask&#x27;</span>, <span class="hljs-string">&#x27;input_ids&#x27;</span>, <span class="hljs-string">&#x27;labels&#x27;</span>, <span class="hljs-string">&#x27;word_ids&#x27;</span>],
        num_rows: <span class="hljs-number">122963</span>
    })
})`,wrap:!1}}),Es=new h({props:{code:"dG9rZW5pemVyLmRlY29kZShsbV9kYXRhc2V0cyU1QiUyMnRyYWluJTIyJTVEJTVCMSU1RCU1QiUyMmlucHV0X2lkcyUyMiU1RCk=",highlighted:'tokenizer.decode(lm_datasets[<span class="hljs-string">&quot;train&quot;</span>][<span class="hljs-number">1</span>][<span class="hljs-string">&quot;input_ids&quot;</span>])',wrap:!1}}),Fs=new h({props:{code:"JTIyLi4uLiUyMGF0Li4uLi4uLi4uLiUyMGhpZ2guJTIwYSUyMGNsYXNzaWMlMjBsaW5lJTIwJTNBJTIwaW5zcGVjdG9yJTIwJTNBJTIwaSdtJTIwaGVyZSUyMHRvJTIwc2FjayUyMG9uZSUyMG9mJTIweW91ciUyMHRlYWNoZXJzLiUyMHN0dWRlbnQlMjAlM0ElMjB3ZWxjb21lJTIwdG8lMjBicm9td2VsbCUyMGhpZ2guJTIwaSUyMGV4cGVjdCUyMHRoYXQlMjBtYW55JTIwYWR1bHRzJTIwb2YlMjBteSUyMGFnZSUyMHRoaW5rJTIwdGhhdCUyMGJyb213ZWxsJTIwaGlnaCUyMGlzJTIwZmFyJTIwZmV0Y2hlZC4lMjB3aGF0JTIwYSUyMHBpdHklMjB0aGF0JTIwaXQlMjBpc24ndCElMjAlNUJTRVAlNUQlMjAlNUJDTFMlNUQlMjBob21lbGVzc25lc3MlMjAoJTIwb3IlMjBob3VzZWxlc3NuZXNzJTIwYXMlMjBnZW9yZ2UlMjBjYXJsaW4lMjBzdGF0ZWQlMjApJTIwaGFzJTIwYmVlbiUyMGFuJTIwaXNzdWUlMjBmb3IlMjB5ZWFycyUyMGJ1dCUyMG5ldmVyJTIwYSUyMHBsYW4lMjB0byUyMGhlbHAlMjB0aG9zZSUyMG9uJTIwdGhlJTIwc3RyZWV0JTIwdGhhdCUyMHdlcmUlMjBvbmNlJTIwY29uc2lkZXJlZCUyMGh1bWFuJTIwd2hvJTIwZGlkJTIwZXZlcnl0aGluZyUyMGZyb20lMjBnb2luZyUyMHRvJTIwc2Nob29sJTJDJTIwd29yayUyQyUyMG9yJTIwdm90ZSUyMGZvciUyMHRoZSUyMG1hdHRlci4lMjBtb3N0JTIwcGVvcGxlJTIwdGhpbmslMjBvZiUyMHRoZSUyMGhvbWVsZXNzJTIy",highlighted:'<span class="hljs-string">&quot;.... at.......... high. a classic line : inspector : i&#x27;m here to sack one of your teachers. student : welcome to bromwell high. i expect that many adults of my age think that bromwell high is far fetched. what a pity that it isn&#x27;t! [SEP] [CLS] homelessness ( or houselessness as george carlin stated ) has been an issue for years but never a plan to help those on the street that were once considered human who did everything from going to school, work, or vote for the matter. most people think of the homeless&quot;</span>',wrap:!1}}),Hs=new h({props:{code:"dG9rZW5pemVyLmRlY29kZShsbV9kYXRhc2V0cyU1QiUyMnRyYWluJTIyJTVEJTVCMSU1RCU1QiUyMmxhYmVscyUyMiU1RCk=",highlighted:'tokenizer.decode(lm_datasets[<span class="hljs-string">&quot;train&quot;</span>][<span class="hljs-number">1</span>][<span class="hljs-string">&quot;labels&quot;</span>])',wrap:!1}}),Ls=new h({props:{code:"JTIyLi4uLiUyMGF0Li4uLi4uLi4uLiUyMGhpZ2guJTIwYSUyMGNsYXNzaWMlMjBsaW5lJTIwJTNBJTIwaW5zcGVjdG9yJTIwJTNBJTIwaSdtJTIwaGVyZSUyMHRvJTIwc2FjayUyMG9uZSUyMG9mJTIweW91ciUyMHRlYWNoZXJzLiUyMHN0dWRlbnQlMjAlM0ElMjB3ZWxjb21lJTIwdG8lMjBicm9td2VsbCUyMGhpZ2guJTIwaSUyMGV4cGVjdCUyMHRoYXQlMjBtYW55JTIwYWR1bHRzJTIwb2YlMjBteSUyMGFnZSUyMHRoaW5rJTIwdGhhdCUyMGJyb213ZWxsJTIwaGlnaCUyMGlzJTIwZmFyJTIwZmV0Y2hlZC4lMjB3aGF0JTIwYSUyMHBpdHklMjB0aGF0JTIwaXQlMjBpc24ndCElMjAlNUJTRVAlNUQlMjAlNUJDTFMlNUQlMjBob21lbGVzc25lc3MlMjAoJTIwb3IlMjBob3VzZWxlc3NuZXNzJTIwYXMlMjBnZW9yZ2UlMjBjYXJsaW4lMjBzdGF0ZWQlMjApJTIwaGFzJTIwYmVlbiUyMGFuJTIwaXNzdWUlMjBmb3IlMjB5ZWFycyUyMGJ1dCUyMG5ldmVyJTIwYSUyMHBsYW4lMjB0byUyMGhlbHAlMjB0aG9zZSUyMG9uJTIwdGhlJTIwc3RyZWV0JTIwdGhhdCUyMHdlcmUlMjBvbmNlJTIwY29uc2lkZXJlZCUyMGh1bWFuJTIwd2hvJTIwZGlkJTIwZXZlcnl0aGluZyUyMGZyb20lMjBnb2luZyUyMHRvJTIwc2Nob29sJTJDJTIwd29yayUyQyUyMG9yJTIwdm90ZSUyMGZvciUyMHRoZSUyMG1hdHRlci4lMjBtb3N0JTIwcGVvcGxlJTIwdGhpbmslMjBvZiUyMHRoZSUyMGhvbWVsZXNzJTIy",highlighted:'<span class="hljs-string">&quot;.... at.......... high. a classic line : inspector : i&#x27;m here to sack one of your teachers. student : welcome to bromwell high. i expect that many adults of my age think that bromwell high is far fetched. what a pity that it isn&#x27;t! [SEP] [CLS] homelessness ( or houselessness as george carlin stated ) has been an issue for years but never a plan to help those on the street that were once considered human who did everything from going to school, work, or vote for the matter. most people think of the homeless&quot;</span>',wrap:!1}}),Ds=new Sl({props:{title:"使用 Trainer API 微調DistilBERT",local:"使用-trainer-api-微調distilbert",headingTag:"h2"}}),Ps=new h({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMERhdGFDb2xsYXRvckZvckxhbmd1YWdlTW9kZWxpbmclMEElMEFkYXRhX2NvbGxhdG9yJTIwJTNEJTIwRGF0YUNvbGxhdG9yRm9yTGFuZ3VhZ2VNb2RlbGluZyh0b2tlbml6ZXIlM0R0b2tlbml6ZXIlMkMlMjBtbG1fcHJvYmFiaWxpdHklM0QwLjE1KQ==",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> DataCollatorForLanguageModeling

data_collator = DataCollatorForLanguageModeling(tokenizer=tokenizer, mlm_probability=<span class="hljs-number">0.15</span>)`,wrap:!1}}),le=new h({props:{code:"c2FtcGxlcyUyMCUzRCUyMCU1QmxtX2RhdGFzZXRzJTVCJTIydHJhaW4lMjIlNUQlNUJpJTVEJTIwZm9yJTIwaSUyMGluJTIwcmFuZ2UoMiklNUQlMEFmb3IlMjBzYW1wbGUlMjBpbiUyMHNhbXBsZXMlM0ElMEElMjAlMjAlMjAlMjBfJTIwJTNEJTIwc2FtcGxlLnBvcCglMjJ3b3JkX2lkcyUyMiklMEElMEFmb3IlMjBjaHVuayUyMGluJTIwZGF0YV9jb2xsYXRvcihzYW1wbGVzKSU1QiUyMmlucHV0X2lkcyUyMiU1RCUzQSUwQSUyMCUyMCUyMCUyMHByaW50KGYlMjIlNUNuJyUzRSUzRSUzRSUyMCU3QnRva2VuaXplci5kZWNvZGUoY2h1bmspJTdEJyUyMik=",highlighted:`samples = [lm_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>)]
<span class="hljs-keyword">for</span> sample <span class="hljs-keyword">in</span> samples:
    _ = sample.pop(<span class="hljs-string">&quot;word_ids&quot;</span>)

<span class="hljs-keyword">for</span> chunk <span class="hljs-keyword">in</span> data_collator(samples)[<span class="hljs-string">&quot;input_ids&quot;</span>]:
    <span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;\\n&#x27;&gt;&gt;&gt; <span class="hljs-subst">{tokenizer.decode(chunk)}</span>&#x27;&quot;</span>)`,wrap:!1}}),se=new h({props:{code:"JyUzRSUzRSUzRSUyMCU1QkNMUyU1RCUyMGJyb213ZWxsJTIwJTVCTUFTSyU1RCUyMGlzJTIwYSUyMGNhcnRvb24lMjBjb21lZHkuJTIwaXQlMjByYW4lMjBhdCUyMHRoZSUyMHNhbWUlMjAlNUJNQVNLJTVEJTIwYXMlMjBzb21lJTIwb3RoZXIlMjAlNUJNQVNLJTVEJTIwYWJvdXQlMjBzY2hvb2wlMjBsaWZlJTJDJTIwJTVCTUFTSyU1RCUyMGFzJTIwJTIyJTIwdGVhY2hlcnMlMjAlMjIuJTIwJTVCTUFTSyU1RCUyMCU1Qk1BU0slNUQlMjAlNUJNQVNLJTVEJTIwaW4lMjB0aGUlMjB0ZWFjaGluZyUyMCU1Qk1BU0slNUQlMjBsZWFkJTIwJTVCTUFTSyU1RCUyMHRvJTIwYmVsaWV2ZSUyMHRoYXQlMjBicm9td2VsbCUyMGhpZ2glNUMnJTVCTUFTSyU1RCUyMHNhdGlyZSUyMGlzJTIwbXVjaCUyMGNsb3NlciUyMHRvJTIwcmVhbGl0eSUyMHRoYW4lMjBpcyUyMCUyMiUyMHRlYWNoZXJzJTIwJTIyLiUyMHRoZSUyMHNjcmFtYmxlJTIwJTVCTUFTSyU1RCUyMCU1Qk1BU0slNUQlMjBmaW5hbmNpYWxseSUyQyUyMHRoZSUyMCU1Qk1BU0slNURmdWwlMjBzdHVkZW50cyUyMHdob2duJTIwJTVCTUFTSyU1RCUyMHJpZ2h0JTIwdGhyb3VnaCUyMCU1Qk1BU0slN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lNFUCU1RCUyMCU1QkNMUyU1RCUyMCU1Qk1BU0slNURuZXNzJTIwKCUyMG9yJTIwJTVCTUFTSyU1RGxlc3NuZXNzJTIwYXMlMjBnZW9yZ2UlMjAlRTUlQUUlODdpbiUyMHN0YXRlZCUyMCklRTUlODUlQUMlMjBiZWVuJTIwYW4lMjBpc3N1ZSUyMGZvciUyMHllYXJzJTIwYnV0JTIwbmV2ZXIlMjAlNUJNQVNLJTVEJTIwcGxhbiUyMHRvJTIwaGVscCUyMHRob3NlJTIwb24lMjB0aGUlMjBzdHJlZXQlMjB0aGF0JTIwd2VyZSUyMG9uY2UlMjBjb25zaWRlcmVkJTIwaHVtYW4lMjAlNUJNQVNLJTVEJTIwZGlkJTIwZXZlcnl0aGluZyUyMGZyb20lMjBnb2luZyUyMHRvJTIwc2Nob29sJTJDJTIwJTVCTUFTSyU1RCUyQyUyMCU1Qk1BU0slNUQlMjB2b3RlJTIwZm9yJTIwdGhlJTIwbWF0dGVyLiUyMG1vc3QlMjBwZW9wbGUlMjB0aGluayUyMCU1Qk1BU0slNUQlMjB0aGUlMjBob21lbGVzcyc=",highlighted:`<span class="hljs-string">&#x27;&gt;&gt;&gt; [CLS] bromwell [MASK] is a cartoon comedy. it ran at the same [MASK] as some other [MASK] about school life, [MASK] as &quot; teachers &quot;. [MASK] [MASK] [MASK] in the teaching [MASK] lead [MASK] to believe that bromwell high\\&#x27;[MASK] satire is much closer to reality than is &quot; teachers &quot;. the scramble [MASK] [MASK] financially, the [MASK]ful students whogn [MASK] right through [MASK] pathetic teachers\\&#x27;pomp, the pettiness of the whole situation, distinction remind me of the schools i knew and their students. when i saw [MASK] episode in [MASK] a student repeatedly tried to burn down the school, [MASK] immediately recalled. [MASK]...&#x27;</span>

<span class="hljs-string">&#x27;&gt;&gt;&gt; .... at.. [MASK]... [MASK]... high. a classic line plucked inspector : i\\&#x27;[MASK] here to [MASK] one of your [MASK]. student : welcome to bromwell [MASK]. i expect that many adults of my age think that [MASK]mwell [MASK] is [MASK] fetched. what a pity that it isn\\&#x27;t! [SEP] [CLS] [MASK]ness ( or [MASK]lessness as george 宇in stated )公 been an issue for years but never [MASK] plan to help those on the street that were once considered human [MASK] did everything from going to school, [MASK], [MASK] vote for the matter. most people think [MASK] the homeless&#x27;</span>`,wrap:!1}}),Ql=new Fl({props:{$$slots:{default:[GM]},$$scope:{ctx:I}}});let D=I[0]==="pt"&&nM();const xn=[BM,ZM],Ve=[];function An(l,s){return l[0]==="pt"?0:1}Tl=An(I),wl=Ve[Tl]=xn[Tl](I),ne=new h({props:{code:"c2FtcGxlcyUyMCUzRCUyMCU1QmxtX2RhdGFzZXRzJTVCJTIydHJhaW4lMjIlNUQlNUJpJTVEJTIwZm9yJTIwaSUyMGluJTIwcmFuZ2UoMiklNUQlMEFiYXRjaCUyMCUzRCUyMHdob2xlX3dvcmRfbWFza2luZ19kYXRhX2NvbGxhdG9yKHNhbXBsZXMpJTBBJTBBZm9yJTIwY2h1bmslMjBpbiUyMGJhdGNoJTVCJTIyaW5wdXRfaWRzJTIyJTVEJTNBJTBBJTIwJTIwJTIwJTIwcHJpbnQoZiUyMiU1Q24nJTNFJTNFJTNFJTIwJTdCdG9rZW5pemVyLmRlY29kZShjaHVuayklN0QnJTIyKQ==",highlighted:`samples = [lm_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>)]
batch = whole_word_masking_data_collator(samples)

<span class="hljs-keyword">for</span> chunk <span class="hljs-keyword">in</span> batch[<span class="hljs-string">&quot;input_ids&quot;</span>]:
    <span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;\\n&#x27;&gt;&gt;&gt; <span class="hljs-subst">{tokenizer.decode(chunk)}</span>&#x27;&quot;</span>)`,wrap:!1}}),Me=new h({props:{code:"JyUzRSUzRSUzRSUyMCU1QkNMUyU1RCUyMGJyb213ZWxsJTIwaGlnaCUyMGlzJTIwY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ighted:`<span class="hljs-string">&#x27;&gt;&gt;&gt; [CLS] bromwell high is a cartoon comedy [MASK] it ran at the same time as some other programs about school life, such as &quot; teachers &quot;. my 35 years in the teaching profession lead me to believe that bromwell high\\&#x27;s satire is much closer to reality than is &quot; teachers &quot;. the scramble to survive financially, the insightful students who can see right through their pathetic teachers\\&#x27;pomp, the pettiness of the whole situation, all remind me of the schools i knew and their students. when i saw the episode in which a student repeatedly tried to burn down the school, i immediately recalled.....&#x27;</span>

<span class="hljs-string">&#x27;&gt;&gt;&gt; .... [MASK] [MASK] [MASK] [MASK]....... high. a classic line : inspector : i\\&#x27;m here to sack one of your teachers. student : welcome to bromwell high. i expect that many adults of my age think that bromwell high is far fetched. what a pity that it isn\\&#x27;t! [SEP] [CLS] homelessness ( or houselessness as george carlin stated ) has been an issue for years but never a plan to help those on the street that were once considered human who did everything from going to school, work, or vote for the matter. most people think of the homeless&#x27;</span>`,wrap:!1}}),vl=new Fl({props:{$$slots:{default:[gM]},$$scope:{ctx:I}}}),ie=new h({props:{code:"dHJhaW5fc2l6ZSUyMCUzRCUyMDEwXzAwMCUwQXRlc3Rfc2l6ZSUyMCUzRCUyMGludCgwLjElMjAqJTIwdHJhaW5fc2l6ZSklMEElMEFkb3duc2FtcGxlZF9kYXRhc2V0JTIwJTNEJTIwbG1fZGF0YXNldHMlNUIlMjJ0cmFpbiUyMiU1RC50cmFpbl90ZXN0X3NwbGl0KCUwQSUyMCUyMCUyMCUyMHRyYWluX3NpemUlM0R0cmFpbl9zaXplJTJDJTIwdGVzdF9zaXplJTNEdGVzdF9zaXplJTJDJTIwc2VlZCUzRDQyJTBBKSUwQWRvd25zYW1wbGVkX2RhdGFzZXQ=",highlighted:`train_size = <span class="hljs-number">10_000</span>
test_size = <span class="hljs-built_in">int</span>(<span class="hljs-number">0.1</span> * train_size)

downsampled_dataset = lm_datasets[<span class="hljs-string">&quot;train&quot;</span>].train_test_split(
    train_size=train_size, test_size=test_size, seed=<span class="hljs-number">42</span>
)
downsampled_dataset`,wrap:!1}}),ye=new h({props:{code:"RGF0YXNldERpY3QoJTdCJTBBJTIwJTIwJTIwJTIwdHJhaW4lM0ElMjBEYXRhc2V0KCU3QiUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMGZlYXR1cmVzJTNBJTIwJTVCJ2F0dGVudGlvbl9tYXNrJyUyQyUyMCdpbnB1dF9pZHMnJTJDJTIwJ2xhYmVscyclMkMlMjAnd29yZF9pZHMnJTVEJTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwbnVtX3Jvd3MlM0ElMjAxMDAwMCUwQSUyMCUyMCUyMCUyMCU3RCklMEElMjAlMjAlMjAlMjB0ZXN0JTNBJTIwRGF0YXNldCglN0IlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBmZWF0dXJlcyUzQSUyMCU1QidhdHRlbnRpb25fbWFzayclMkMlMjAnaW5wdXRfaWRzJyUyQyUyMCdsYWJlbHMnJTJDJTIwJ3dvcmRfaWRzJyU1RCUyQyUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMG51bV9yb3dzJTNBJTIwMTAwMCUwQSUyMCUyMCUyMCUyMCU3RCklMEElN0Qp",highlighted:`DatasetDict({
    train: Dataset({
        features: [<span class="hljs-string">&#x27;attention_mask&#x27;</span>, <span class="hljs-string">&#x27;input_ids&#x27;</span>, <span class="hljs-string">&#x27;labels&#x27;</span>, <span class="hljs-string">&#x27;word_ids&#x27;</span>],
        num_rows: <span class="hljs-number">10000</span>
    })
    test: Dataset({
        features: [<span class="hljs-string">&#x27;attention_mask&#x27;</span>, <span class="hljs-string">&#x27;input_ids&#x27;</span>, <span class="hljs-string">&#x27;labels&#x27;</span>, <span class="hljs-string">&#x27;word_ids&#x27;</span>],
        num_rows: <span class="hljs-number">1000</span>
    })
})`,wrap:!1}}),re=new h({props:{code:"ZnJvbSUyMGh1Z2dpbmdmYWNlX2h1YiUyMGltcG9ydCUyMG5vdGVib29rX2xvZ2luJTBBJTBBbm90ZWJvb2tfbG9naW4oKQ==",highlighted:`<span class="hljs-keyword">from</span> huggingface_hub <span class="hljs-keyword">import</span> notebook_login

notebook_login()`,wrap:!1}}),oe=new h({props:{code:"aHVnZ2luZ2ZhY2UtY2xpJTIwbG9naW4=",highlighted:'huggingface-<span class="hljs-keyword">cli</span> login',wrap:!1}});const Qn=[RM,kM],ze=[];function vn(l,s){return l[0]==="tf"?0:1}dl=vn(I),ml=ze[dl]=Qn[dl](I),Te=new Sl({props:{title:"語言模型的perplexity",local:"語言模型的perplexity",headingTag:"h3"}}),we=new Na({props:{id:"NURcDHhYe98"}});const Yn=[WM,XM],Ne=[];function En(l,s){return l[0]==="pt"?0:1}jl=En(I),bl=Ne[jl]=Yn[jl](I),me=new h({props:{code:"UGVycGxleGl0eSUzQSUyMDIxLjc1",highlighted:'<span class="hljs-meta">&gt;&gt;&gt; </span>Perplexity: <span class="hljs-number">21.75</span>',wrap:!1}});const Fn=[VM,$M],xe=[];function Sn(l,s){return l[0]==="pt"?0:1}ul=Sn(I),hl=xe[ul]=Fn[ul](I);const Hn=[NM,zM],Ae=[];function Ln(l,s){return l[0]==="pt"?0:1}fl=Ln(I),Il=Ae[fl]=Hn[fl](I),ue=new h({props:{code:"UGVycGxleGl0eSUzQSUyMDExLjMy",highlighted:'<span class="hljs-meta">&gt;&gt;&gt; </span>Perplexity: <span class="hljs-number">11.32</span>',wrap:!1}});let A=I[0]==="pt"&&MM();Yl=new Fl({props:{$$slots:{default:[xM]},$$scope:{ctx:I}}});let Q=I[0]==="pt"&&pM();return fe=new Sl({props:{title:"使用我們微調的模型",local:"使用我們微調的模型",headingTag:"h2"}}),Ce=new h({props:{code:"ZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMHBpcGVsaW5lJTBBJTBBbWFza19maWxsZXIlMjAlM0QlMjBwaXBlbGluZSglMEElMjAlMjAlMjAlMjAlMjJmaWxsLW1hc2slMjIlMkMlMjBtb2RlbCUzRCUyMmh1Z2dpbmdmYWNlLWNvdXJzZSUyRmRpc3RpbGJlcnQtYmFzZS11bmNhc2VkLWZpbmV0dW5lZC1pbWRiJTIyJTBBKQ==",highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> pipeline

mask_filler = pipeline(
    <span class="hljs-string">&quot;fill-mask&quot;</span>, model=<span class="hljs-string">&quot;huggingface-course/distilbert-base-uncased-finetuned-imdb&quot;</span>
)`,wrap:!1}}),Ge=new h({props:{code:"cHJlZHMlMjAlM0QlMjBtYXNrX2ZpbGxlcih0ZXh0KSUwQSUwQWZvciUyMHByZWQlMjBpbiUyMHByZWRzJTNBJTBBJTIwJTIwJTIwJTIwcHJpbnQoZiUyMiUzRSUzRSUzRSUyMCU3QnByZWQlNUInc2VxdWVuY2UnJTVEJTdEJTIyKQ==",highlighted:`preds = mask_filler(text)

<span class="hljs-keyword">for</span> pred <span class="hljs-keyword">in</span> preds:
    <span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;&gt;&gt;&gt; <span class="hljs-subst">{pred[<span class="hljs-string">&#x27;sequence&#x27;</span>]}</span>&quot;</span>)`,wrap:!1}}),Ze=new h({props:{code:"JyUzRSUzRSUzRSUyMHRoaXMlMjBpcyUyMGElMjBncmVhdCUyMG1vdmllLiclMEEnJTNFJTNFJTNFJTIwdGhpcyUyMGlzJTIwYSUyMGdyZWF0JTIwZmlsbS4nJTBBJyUzRSUzRSUzRSUyMHRoaXMlMjBpcyUyMGElMjBncmVhdCUyMHN0b3J5LiclMEEnJTNFJTNFJTNFJTIwdGhpcyUyMGlzJTIwYSUyMGdyZWF0JTIwbW92aWVzLiclMEEnJTNFJTNFJTNFJTIwdGhpcyUyMGlzJTIwYSUyMGdyZWF0JTIwY2hhcmFjdGVyLic=",highlighted:`<span class="hljs-string">&#x27;&gt;&gt;&gt; this is a great movie.&#x27;</span>
<span class="hljs-string">&#x27;&gt;&gt;&gt; this is a great film.&#x27;</span>
<span class="hljs-string">&#x27;&gt;&gt;&gt; this is a great story.&#x27;</span>
<span class="hljs-string">&#x27;&gt;&gt;&gt; this is a great movies.&#x27;</span>
<span class="hljs-string">&#x27;&gt;&gt;&gt; this is a great character.&#x27;</span>`,wrap:!1}}),ge=new Na({props:{id:"0Oxphw4Q9fo"}}),El=new Fl({props:{$$slots:{default:[AM]},$$scope:{ctx:I}}}),Re=new wM({props:{source:"https://github.com/huggingface/course/blob/main/chapters/zh-TW/chapter7/3.mdx"}}),{c(){a=d("meta"),U=M(),n=d("p"),r=M(),o(G.$$.fragment),j=M(),o(R.$$.fragment),W=M(),X.c(),k=M(),g=d("p"),g.textContent=u,Z=M(),z=d("p"),z.textContent=Y,C=M(),$=d("p"),$.innerHTML=F,B=M(),V=d("div"),V.innerHTML=Cl,Xl=M(),S=d("p"),S.innerHTML=De,Wl=M(),N=d("iframe"),O=M(),E=d("iframe"),ll=M(),sl=d("p"),sl.textContent=_l,Dl=M(),o(el.$$.fragment),tl=M(),o(P.$$.fragment),al=M(),o(Gl.$$.fragment),$l=M(),H=d("p"),H.innerHTML=Kl,nl=M(),Ul=d("div"),Ul.innerHTML=Pl,Ml=M(),pl=d("p"),pl.innerHTML=Zl,Vl=M(),K.c(),ol=M(),L=d("p"),L.textContent=Ol,il=M(),o(Bl.$$.fragment),zl=M(),q=d("p"),q.innerHTML=ls,yl=M(),o(Jl.$$.fragment),rl=M(),gl=d("p"),gl.textContent=ss,i=M(),cl.c(),Qe=M(),o(es.$$.fragment),Pe=M(),ts=d("p"),ts.textContent=Ha,Oe=M(),o(as.$$.fragment),lt=M(),ns=d("p"),ns.innerHTML=La,st=M(),o(Ms.$$.fragment),et=M(),o(ps.$$.fragment),tt=M(),is=d("p"),is.innerHTML=qa,at=M(),o(ys.$$.fragment),nt=M(),o(Js.$$.fragment),Mt=M(),rs=d("p"),rs.innerHTML=Da,pt=M(),o(Nl.$$.fragment),it=M(),Us=d("p"),Us.innerHTML=Ka,yt=M(),o(os.$$.fragment),Jt=M(),o(cs.$$.fragment),rt=M(),Ts=d("p"),Ts.textContent=Pa,Ut=M(),ws=d("p"),ws.innerHTML=Oa,ot=M(),o(ds.$$.fragment),ct=M(),o(ms.$$.fragment),Tt=M(),js=d("p"),js.innerHTML=ln,wt=M(),bs=d("p"),bs.innerHTML=sn,dt=M(),o(us.$$.fragment),mt=M(),o(hs.$$.fragment),jt=M(),fs=d("p"),fs.innerHTML=en,bt=M(),o(xl.$$.fragment),ut=M(),Is=d("p"),Is.textContent=tn,ht=M(),o(Cs.$$.fragment),ft=M(),o(Al.$$.fragment),It=M(),_s=d("p"),_s.textContent=an,Ct=M(),o(Gs.$$.fragment),_t=M(),o(Zs.$$.fragment),Gt=M(),Bs=d("p"),Bs.textContent=nn,Zt=M(),o(gs.$$.fragment),Bt=M(),o(ks.$$.fragment),gt=M(),Rs=d("p"),Rs.innerHTML=Mn,kt=M(),o(Xs.$$.fragment),Rt=M(),o(Ws.$$.fragment),Xt=M(),$s=d("p"),$s.textContent=pn,Wt=M(),Vs=d("ul"),Vs.innerHTML=yn,$t=M(),zs=d("p"),zs.textContent=Jn,Vt=M(),o(Ns.$$.fragment),zt=M(),xs=d("p"),xs.innerHTML=rn,Nt=M(),As=d("p"),As.innerHTML=Un,xt=M(),o(Qs.$$.fragment),At=M(),o(vs.$$.fragment),Qt=M(),Ys=d("p"),Ys.innerHTML=on,vt=M(),o(Es.$$.fragment),Yt=M(),o(Fs.$$.fragment),Et=M(),Ss=d("p"),Ss.textContent=cn,Ft=M(),o(Hs.$$.fragment),St=M(),o(Ls.$$.fragment),Ht=M(),qs=d("p"),qs.innerHTML=Tn,Lt=M(),o(Ds.$$.fragment),qt=M(),Ks=d("p"),Ks.innerHTML=wn,Dt=M(),o(Ps.$$.fragment),Kt=M(),Os=d("p"),Os.innerHTML=dn,Pt=M(),o(le.$$.fragment),Ot=M(),o(se.$$.fragment),la=M(),ee=d("p"),ee.innerHTML=mn,sa=M(),o(Ql.$$.fragment),ea=M(),D&&D.c(),ve=M(),te=d("p"),te.innerHTML=jn,ta=M(),wl.c(),Ye=M(),ae=d("p"),ae.textContent=bn,aa=M(),o(ne.$$.fragment),na=M(),o(Me.$$.fragment),Ma=M(),o(vl.$$.fragment),pa=M(),pe=d("p"),pe.innerHTML=un,ia=M(),o(ie.$$.fragment),ya=M(),o(ye.$$.fragment),Ja=M(),Je=d("p"),Je.innerHTML=hn,ra=M(),o(re.$$.fragment),Ua=M(),Ue=d("p"),Ue.textContent=fn,oa=M(),o(oe.$$.fragment),ca=M(),ce=d("p"),ce.textContent=In,Ta=M(),ml.c(),Ee=M(),o(Te.$$.fragment),wa=M(),o(we.$$.fragment),da=M(),de=d("p"),de.textContent=Cn,ma=M(),bl.c(),Fe=M(),o(me.$$.fragment),ja=M(),je=d("p"),je.textContent=_n,ba=M(),hl.c(),Se=M(),be=d("p"),be.textContent=Gn,ua=M(),Il.c(),He=M(),o(ue.$$.fragment),ha=M(),he=d("p"),he.textContent=Zn,fa=M(),A&&A.c(),Le=M(),o(Yl.$$.fragment),Ia=M(),Q&&Q.c(),qe=M(),o(fe.$$.fragment),Ca=M(),Ie=d("p"),Ie.innerHTML=Bn,_a=M(),o(Ce.$$.fragment),Ga=M(),_e=d("p"),_e.textContent=gn,Za=M(),o(Ge.$$.fragment),Ba=M(),o(Ze.$$.fragment),ga=M(),Be=d("p"),Be.textContent=kn,ka=M(),o(ge.$$.fragment),Ra=M(),ke=d("p"),ke.innerHTML=Rn,Xa=M(),o(El.$$.fragment),Wa=M(),o(Re.$$.fragment),$a=M(),Ke=d("p"),this.h()},l(l){const s=oM("svelte-u9bgzb",document.head);a=m(s,"META",{name:!0,content:!0}),s.forEach(e),U=p(l),n=m(l,"P",{}),za(n).forEach(e),r=p(l),c(G.$$.fragment,l),j=p(l),c(R.$$.fragment,l),W=p(l),X.l(l),k=p(l),g=m(l,"P",{"data-svelte-h":!0}),b(g)!=="svelte-okiss5"&&(g.textContent=u),Z=p(l),z=m(l,"P",{"data-svelte-h":!0}),b(z)!=="svelte-15popus"&&(z.textContent=Y),C=p(l),$=m(l,"P",{"data-svelte-h":!0}),b($)!=="svelte-1p0z671"&&($.innerHTML=F),B=p(l),V=m(l,"DIV",{class:!0,"data-svelte-h":!0}),b(V)!=="svelte-1lvgpuv"&&(V.innerHTML=Cl),Xl=p(l),S=m(l,"P",{"data-svelte-h":!0}),b(S)!=="svelte-17y0qt2"&&(S.innerHTML=De),Wl=p(l),N=m(l,"IFRAME",{src:!0,frameborder:!0,height:!0,title:!0,class:!0,allow:!0,sandbox:!0}),za(N).forEach(e),O=p(l),E=m(l,"IFRAME",{src:!0,frameborder:!0,height:!0,title:!0,class:!0,allow:!0,sandbox:!0}),za(E).forEach(e),ll=p(l),sl=m(l,"P",{"data-svelte-h":!0}),b(sl)!=="svelte-1sq740p"&&(sl.textContent=_l),Dl=p(l),c(el.$$.fragment,l),tl=p(l),c(P.$$.fragment,l),al=p(l),c(Gl.$$.fragment,l),$l=p(l),H=m(l,"P",{"data-svelte-h":!0}),b(H)!=="svelte-bg7l79"&&(H.innerHTML=Kl),nl=p(l),Ul=m(l,"DIV",{class:!0,"data-svelte-h":!0}),b(Ul)!=="svelte-zc90xi"&&(Ul.innerHTML=Pl),Ml=p(l),pl=m(l,"P",{"data-svelte-h":!0}),b(pl)!=="svelte-1o8fwt7"&&(pl.innerHTML=Zl),Vl=p(l),K.l(l),ol=p(l),L=m(l,"P",{"data-svelte-h":!0}),b(L)!=="svelte-1kt3w80"&&(L.textContent=Ol),il=p(l),c(Bl.$$.fragment,l),zl=p(l),q=m(l,"P",{"data-svelte-h":!0}),b(q)!=="svelte-11vuawp"&&(q.innerHTML=ls),yl=p(l),c(Jl.$$.fragment,l),rl=p(l),gl=m(l,"P",{"data-svelte-h":!0}),b(gl)!=="svelte-172kd7j"&&(gl.textContent=ss),i=p(l),cl.l(l),Qe=p(l),c(es.$$.fragment,l),Pe=p(l),ts=m(l,"P",{"data-svelte-h":!0}),b(ts)!=="svelte-1lbmqhm"&&(ts.textContent=Ha),Oe=p(l),c(as.$$.fragment,l),lt=p(l),ns=m(l,"P",{"data-svelte-h":!0}),b(ns)!=="svelte-syl2nx"&&(ns.innerHTML=La),st=p(l),c(Ms.$$.fragment,l),et=p(l),c(ps.$$.fragment,l),tt=p(l),is=m(l,"P",{"data-svelte-h":!0}),b(is)!=="svelte-9hzp4f"&&(is.innerHTML=qa),at=p(l),c(ys.$$.fragment,l),nt=p(l),c(Js.$$.fragment,l),Mt=p(l),rs=m(l,"P",{"data-svelte-h":!0}),b(rs)!=="svelte-gwemqp"&&(rs.innerHTML=Da),pt=p(l),c(Nl.$$.fragment,l),it=p(l),Us=m(l,"P",{"data-svelte-h":!0}),b(Us)!=="svelte-hs720y"&&(Us.innerHTML=Ka),yt=p(l),c(os.$$.fragment,l),Jt=p(l),c(cs.$$.fragment,l),rt=p(l),Ts=m(l,"P",{"data-svelte-h":!0}),b(Ts)!=="svelte-imzojq"&&(Ts.textContent=Pa),Ut=p(l),ws=m(l,"P",{"data-svelte-h":!0}),b(ws)!=="svelte-ytzsls"&&(ws.innerHTML=Oa),ot=p(l),c(ds.$$.fragment,l),ct=p(l),c(ms.$$.fragment,l),Tt=p(l),js=m(l,"P",{"data-svelte-h":!0}),b(js)!=="svelte-729mwf"&&(js.innerHTML=ln),wt=p(l),bs=m(l,"P",{"data-svelte-h":!0}),b(bs)!=="svelte-b6e4dt"&&(bs.innerHTML=sn),dt=p(l),c(us.$$.fragment,l),mt=p(l),c(hs.$$.fragment,l),jt=p(l),fs=m(l,"P",{"data-svelte-h":!0}),b(fs)!=="svelte-u046yy"&&(fs.innerHTML=en),bt=p(l),c(xl.$$.fragment,l),ut=p(l),Is=m(l,"P",{"data-svelte-h":!0}),b(Is)!=="svelte-1ent9vh"&&(Is.textContent=tn),ht=p(l),c(Cs.$$.fragment,l),ft=p(l),c(Al.$$.fragment,l),It=p(l),_s=m(l,"P",{"data-svelte-h":!0}),b(_s)!=="svelte-1k68kmr"&&(_s.textContent=an),Ct=p(l),c(Gs.$$.fragment,l),_t=p(l),c(Zs.$$.fragment,l),Gt=p(l),Bs=m(l,"P",{"data-svelte-h":!0}),b(Bs)!=="svelte-o1wjrj"&&(Bs.textContent=nn),Zt=p(l),c(gs.$$.fragment,l),Bt=p(l),c(ks.$$.fragment,l),gt=p(l),Rs=m(l,"P",{"data-svelte-h":!0}),b(Rs)!=="svelte-lvtpzl"&&(Rs.innerHTML=Mn),kt=p(l),c(Xs.$$.fragment,l),Rt=p(l),c(Ws.$$.fragment,l),Xt=p(l),$s=m(l,"P",{"data-svelte-h":!0}),b($s)!=="svelte-1w49gc9"&&($s.textContent=pn),Wt=p(l),Vs=m(l,"UL",{"data-svelte-h":!0}),b(Vs)!=="svelte-1gdvotx"&&(Vs.innerHTML=yn),$t=p(l),zs=m(l,"P",{"data-svelte-h":!0}),b(zs)!=="svelte-jlq4z1"&&(zs.textContent=Jn),Vt=p(l),c(Ns.$$.fragment,l),zt=p(l),xs=m(l,"P",{"data-svelte-h":!0}),b(xs)!=="svelte-1gkoikg"&&(xs.innerHTML=rn),Nt=p(l),As=m(l,"P",{"data-svelte-h":!0}),b(As)!=="svelte-c63gnk"&&(As.innerHTML=Un),xt=p(l),c(Qs.$$.fragment,l),At=p(l),c(vs.$$.fragment,l),Qt=p(l),Ys=m(l,"P",{"data-svelte-h":!0}),b(Ys)!=="svelte-119hjmn"&&(Ys.innerHTML=on),vt=p(l),c(Es.$$.fragment,l),Yt=p(l),c(Fs.$$.fragment,l),Et=p(l),Ss=m(l,"P",{"data-svelte-h":!0}),b(Ss)!=="svelte-ypc5kl"&&(Ss.textContent=cn),Ft=p(l),c(Hs.$$.fragment,l),St=p(l),c(Ls.$$.fragment,l),Ht=p(l),qs=m(l,"P",{"data-svelte-h":!0}),b(qs)!=="svelte-1ar0lyr"&&(qs.innerHTML=Tn),Lt=p(l),c(Ds.$$.fragment,l),qt=p(l),Ks=m(l,"P",{"data-svelte-h":!0}),b(Ks)!=="svelte-y7i7ac"&&(Ks.innerHTML=wn),Dt=p(l),c(Ps.$$.fragment,l),Kt=p(l),Os=m(l,"P",{"data-svelte-h":!0}),b(Os)!=="svelte-ot1mhk"&&(Os.innerHTML=dn),Pt=p(l),c(le.$$.fragment,l),Ot=p(l),c(se.$$.fragment,l),la=p(l),ee=m(l,"P",{"data-svelte-h":!0}),b(ee)!=="svelte-w9sbjh"&&(ee.innerHTML=mn),sa=p(l),c(Ql.$$.fragment,l),ea=p(l),D&&D.l(l),ve=p(l),te=m(l,"P",{"data-svelte-h":!0}),b(te)!=="svelte-xx6oyd"&&(te.innerHTML=jn),ta=p(l),wl.l(l),Ye=p(l),ae=m(l,"P",{"data-svelte-h":!0}),b(ae)!=="svelte-1xi9xjp"&&(ae.textContent=bn),aa=p(l),c(ne.$$.fragment,l),na=p(l),c(Me.$$.fragment,l),Ma=p(l),c(vl.$$.fragment,l),pa=p(l),pe=m(l,"P",{"data-svelte-h":!0}),b(pe)!=="svelte-1ob3td8"&&(pe.innerHTML=un),ia=p(l),c(ie.$$.fragment,l),ya=p(l),c(ye.$$.fragment,l),Ja=p(l),Je=m(l,"P",{"data-svelte-h":!0}),b(Je)!=="svelte-f7ffbw"&&(Je.innerHTML=hn),ra=p(l),c(re.$$.fragment,l),Ua=p(l),Ue=m(l,"P",{"data-svelte-h":!0}),b(Ue)!=="svelte-15pipue"&&(Ue.textContent=fn),oa=p(l),c(oe.$$.fragment,l),ca=p(l),ce=m(l,"P",{"data-svelte-h":!0}),b(ce)!=="svelte-t5e1t4"&&(ce.textContent=In),Ta=p(l),ml.l(l),Ee=p(l),c(Te.$$.fragment,l),wa=p(l),c(we.$$.fragment,l),da=p(l),de=m(l,"P",{"data-svelte-h":!0}),b(de)!=="svelte-4xeq20"&&(de.textContent=Cn),ma=p(l),bl.l(l),Fe=p(l),c(me.$$.fragment,l),ja=p(l),je=m(l,"P",{"data-svelte-h":!0}),b(je)!=="svelte-1se9kyj"&&(je.textContent=_n),ba=p(l),hl.l(l),Se=p(l),be=m(l,"P",{"data-svelte-h":!0}),b(be)!=="svelte-1fkokxt"&&(be.textContent=Gn),ua=p(l),Il.l(l),He=p(l),c(ue.$$.fragment,l),ha=p(l),he=m(l,"P",{"data-svelte-h":!0}),b(he)!=="svelte-1m7xyiu"&&(he.textContent=Zn),fa=p(l),A&&A.l(l),Le=p(l),c(Yl.$$.fragment,l),Ia=p(l),Q&&Q.l(l),qe=p(l),c(fe.$$.fragment,l),Ca=p(l),Ie=m(l,"P",{"data-svelte-h":!0}),b(Ie)!=="svelte-32ghl2"&&(Ie.innerHTML=Bn),_a=p(l),c(Ce.$$.fragment,l),Ga=p(l),_e=m(l,"P",{"data-svelte-h":!0}),b(_e)!=="svelte-1bghojn"&&(_e.textContent=gn),Za=p(l),c(Ge.$$.fragment,l),Ba=p(l),c(Ze.$$.fragment,l),ga=p(l),Be=m(l,"P",{"data-svelte-h":!0}),b(Be)!=="svelte-1rxgtel"&&(Be.textContent=kn),ka=p(l),c(ge.$$.fragment,l),Ra=p(l),ke=m(l,"P",{"data-svelte-h":!0}),b(ke)!=="svelte-gojed0"&&(ke.innerHTML=Rn),Xa=p(l),c(El.$$.fragment,l),Wa=p(l),c(Re.$$.fragment,l),$a=p(l),Ke=m(l,"P",{}),za(Ke).forEach(e),this.h()},h(){v(a,"name","hf:doc:metadata"),v(a,"content",vM),v(V,"class","flex justify-center"),aM(N.src,Ll="https://course-demos-distilbert-base-uncased-finetune-7400b54.hf.space")||v(N,"src",Ll),v(N,"frameborder","0"),v(N,"height","300"),v(N,"title","Gradio app"),v(N,"class","block dark:hidden container p-0 flex-grow space-iframe"),v(N,"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"),v(N,"sandbox","allow-forms allow-modals allow-popups allow-popups-to-escape-sandbox allow-same-origin allow-scripts allow-downloads"),aM(E.src,ql="https://course-demos-distilbert-base-uncased-finetuned-imdb-darkmode.hf.space")||v(E,"src",ql),v(E,"frameborder","0"),v(E,"height","300"),v(E,"title","Gradio app"),v(E,"class","hidden dark:block container p-0 flex-grow space-iframe"),v(E,"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"),v(E,"sandbox","allow-forms allow-modals allow-popups allow-popups-to-escape-sandbox allow-same-origin allow-scripts allow-downloads"),v(Ul,"class","flex justify-center")},m(l,s){cM(document.head,a),t(l,U,s),t(l,n,s),t(l,r,s),T(G,l,s),t(l,j,s),T(R,l,s),t(l,W,s),Xe[_].m(l,s),t(l,k,s),t(l,g,s),t(l,Z,s),t(l,z,s),t(l,C,s),t(l,$,s),t(l,B,s),t(l,V,s),t(l,Xl,s),t(l,S,s),t(l,Wl,s),t(l,N,s),t(l,O,s),t(l,E,s),t(l,ll,s),t(l,sl,s),t(l,Dl,s),T(el,l,s),t(l,tl,s),T(P,l,s),t(l,al,s),T(Gl,l,s),t(l,$l,s),t(l,H,s),t(l,nl,s),t(l,Ul,s),t(l,Ml,s),t(l,pl,s),t(l,Vl,s),We[x].m(l,s),t(l,ol,s),t(l,L,s),t(l,il,s),T(Bl,l,s),t(l,zl,s),t(l,q,s),t(l,yl,s),T(Jl,l,s),t(l,rl,s),t(l,gl,s),t(l,i,s),$e[f].m(l,s),t(l,Qe,s),T(es,l,s),t(l,Pe,s),t(l,ts,s),t(l,Oe,s),T(as,l,s),t(l,lt,s),t(l,ns,s),t(l,st,s),T(Ms,l,s),t(l,et,s),T(ps,l,s),t(l,tt,s),t(l,is,s),t(l,at,s),T(ys,l,s),t(l,nt,s),T(Js,l,s),t(l,Mt,s),t(l,rs,s),t(l,pt,s),T(Nl,l,s),t(l,it,s),t(l,Us,s),t(l,yt,s),T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,s),T(ie,l,s),t(l,ya,s),T(ye,l,s),t(l,Ja,s),t(l,Je,s),t(l,ra,s),T(re,l,s),t(l,Ua,s),t(l,Ue,s),t(l,oa,s),T(oe,l,s),t(l,ca,s),t(l,ce,s),t(l,Ta,s),ze[dl].m(l,s),t(l,Ee,s),T(Te,l,s),t(l,wa,s),T(we,l,s),t(l,da,s),t(l,de,s),t(l,ma,s),Ne[jl].m(l,s),t(l,Fe,s),T(me,l,s),t(l,ja,s),t(l,je,s),t(l,ba,s),xe[ul].m(l,s),t(l,Se,s),t(l,be,s),t(l,ua,s),Ae[fl].m(l,s),t(l,He,s),T(ue,l,s),t(l,ha,s),t(l,he,s),t(l,fa,s),A&&A.m(l,s),t(l,Le,s),T(Yl,l,s),t(l,Ia,s),Q&&Q.m(l,s),t(l,qe,s),T(fe,l,s),t(l,Ca,s),t(l,Ie,s),t(l,_a,s),T(Ce,l,s),t(l,Ga,s),t(l,_e,s),t(l,Za,s),T(Ge,l,s),t(l,Ba,s),T(Ze,l,s),t(l,ga,s),t(l,Be,s),t(l,ka,s),T(ge,l,s),t(l,Ra,s),t(l,ke,s),t(l,Xa,s),T(El,l,s),t(l,Wa,s),T(Re,l,s),t(l,$a,s),t(l,Ke,s),Va=!0},p(l,[s]){const qn={};s&1&&(qn.fw=l[0]),G.$set(qn);let xa=_;_=Wn(l),_!==xa&&(Rl(),J(Xe[xa],1,1,()=>{Xe[xa]=null}),kl(),X=Xe[_],X||(X=Xe[_]=Xn[_](l),X.c()),y(X,1),X.m(k.parentNode,k));const Dn={};s&2&&(Dn.$$scope={dirty:s,ctx:l}),P.$set(Dn);let Aa=x;x=Vn(l),x!==Aa&&(Rl(),J(We[Aa],1,1,()=>{We[Aa]=null}),kl(),K=We[x],K||(K=We[x]=$n[x](l),K.c()),y(K,1),K.m(ol.parentNode,ol));let Qa=f;f=Nn(l),f!==Qa&&(Rl(),J($e[Qa],1,1,()=>{$e[Qa]=null}),kl(),cl=$e[f],cl||(cl=$e[f]=zn[f](l),cl.c()),y(cl,1),cl.m(Qe.parentNode,Qe));const Kn={};s&2&&(Kn.$$scope={dirty:s,ctx:l}),Nl.$set(Kn);const Pn={};s&2&&(Pn.$$scope={dirty:s,ctx:l}),xl.$set(Pn);const On={};s&2&&(On.$$scope={dirty:s,ctx:l}),Al.$set(On);const lM={};s&2&&(lM.$$scope={dirty:s,ctx:l}),Ql.$set(lM),l[0]==="pt"?D||(D=nM(),D.c(),D.m(ve.parentNode,ve)):D&&(D.d(1),D=null);let va=Tl;Tl=An(l),Tl!==va&&(Rl(),J(Ve[va],1,1,()=>{Ve[va]=null}),kl(),wl=Ve[Tl],wl||(wl=Ve[Tl]=xn[Tl](l),wl.c()),y(wl,1),wl.m(Ye.parentNode,Ye));const sM={};s&2&&(sM.$$scope={dirty:s,ctx:l}),vl.$set(sM);let Ya=dl;dl=vn(l),dl!==Ya&&(Rl(),J(ze[Ya],1,1,()=>{ze[Ya]=null}),kl(),ml=ze[dl],ml||(ml=ze[dl]=Qn[dl](l),ml.c()),y(ml,1),ml.m(Ee.parentNode,Ee));let Ea=jl;jl=En(l),jl!==Ea&&(Rl(),J(Ne[Ea],1,1,()=>{Ne[Ea]=null}),kl(),bl=Ne[jl],bl||(bl=Ne[jl]=Yn[jl](l),bl.c()),y(bl,1),bl.m(Fe.parentNode,Fe));let Fa=ul;ul=Sn(l),ul!==Fa&&(Rl(),J(xe[Fa],1,1,()=>{xe[Fa]=null}),kl(),hl=xe[ul],hl||(hl=xe[ul]=Fn[ul](l),hl.c()),y(hl,1),hl.m(Se.parentNode,Se));let Sa=fl;fl=Ln(l),fl!==Sa&&(Rl(),J(Ae[Sa],1,1,()=>{Ae[Sa]=null}),kl(),Il=Ae[fl],Il||(Il=Ae[fl]=Hn[fl](l),Il.c()),y(Il,1),Il.m(He.parentNode,He)),l[0]==="pt"?A?s&1&&y(A,1):(A=MM(),A.c(),y(A,1),A.m(Le.parentNode,Le)):A&&(Rl(),J(A,1,1,()=>{A=null}),kl());const eM={};s&2&&(eM.$$scope={dirty:s,ctx:l}),Yl.$set(eM),l[0]==="pt"?Q?s&1&&y(Q,1):(Q=pM(),Q.c(),y(Q,1),Q.m(qe.parentNode,qe)):Q&&(Rl(),J(Q,1,1,()=>{Q=null}),kl());const tM={};s&2&&(tM.$$scope={dirty:s,ctx:l}),El.$set(tM)},i(l){Va||(y(G.$$.fragment,l),y(R.$$.fragment,l),y(X),y(el.$$.fragment,l),y(P.$$.fragment,l),y(Gl.$$.fragment,l),y(K),y(Bl.$$.fragment,l),y(Jl.$$.fragment,l),y(cl),y(es.$$.fragment,l),y(as.$$.fragment,l),y(Ms.$$.fragment,l),y(ps.$$.fragment,l),y(ys.$$.fragment,l),y(Js.$$.fragment,l),y(Nl.$$.fragment,l),y(os.$$.fragment,l),y(cs.$$.fragment,l),y(ds.$$.fragment,l),y(ms.$$.fragment,l),y(us.$$.fragment,l),y(hs.$$.fragment,l),y(xl.$$.fragment,l),y(Cs.$$.fragment,l),y(Al.$$.fragment,l),y(Gs.$$.fragment,l),y(Zs.$$.fragment,l),y(gs.$$.fragment,l),y(ks.$$.fragment,l),y(Xs.$$.fragment,l),y(Ws.$$.fragment,l),y(Ns.$$.fragment,l),y(Qs.$$.fragment,l),y(vs.$$.fragment,l),y(Es.$$.fragment,l),y(Fs.$$.fragment,l),y(Hs.$$.fragment,l),y(Ls.$$.fragment,l),y(Ds.$$.fragment,l),y(Ps.$$.fragment,l),y(le.$$.fragment,l),y(se.$$.fragment,l),y(Ql.$$.fragment,l),y(wl),y(ne.$$.fragment,l),y(Me.$$.fragment,l),y(vl.$$.fragment,l),y(ie.$$.fragment,l),y(ye.$$.fragment,l),y(re.$$.fragment,l),y(oe.$$.fragment,l),y(ml),y(Te.$$.fragment,l),y(we.$$.fragment,l),y(bl),y(me.$$.fragment,l),y(hl),y(Il),y(ue.$$.fragment,l),y(A),y(Yl.$$.fragment,l),y(Q),y(fe.$$.fragment,l),y(Ce.$$.fragment,l),y(Ge.$$.fragment,l),y(Ze.$$.fragment,l),y(ge.$$.fragment,l),y(El.$$.fragment,l),y(Re.$$.fragment,l),Va=!0)},o(l){J(G.$$.fragment,l),J(R.$$.fragment,l),J(X),J(el.$$.fragment,l),J(P.$$.fragment,l),J(Gl.$$.fragment,l),J(K),J(Bl.$$.fragment,l),J(Jl.$$.fragment,l),J(cl),J(es.$$.fragment,l),J(as.$$.fragment,l),J(Ms.$$.fragment,l),J(ps.$$.fragment,l),J(ys.$$.fragment,l),J(Js.$$.fragment,l),J(Nl.$$.fragment,l),J(os.$$.fragment,l),J(cs.$$.fragment,l),J(ds.$$.fragment,l),J(ms.$$.fragment,l),J(us.$$.fragment,l),J(hs.$$.fragment,l),J(xl.$$.fragment,l),J(Cs.$$.fragment,l),J(Al.$$.fragment,l),J(Gs.$$.fragment,l),J(Zs.$$.fragment,l),J(gs.$$.fragment,l),J(ks.$$.fragment,l),J(Xs.$$.fragment,l),J(Ws.$$.fragment,l),J(Ns.$$.fragment,l),J(Qs.$$.fragment,l),J(vs.$$.fragment,l),J(Es.$$.fragment,l),J(Fs.$$.fragment,l),J(Hs.$$.fragment,l),J(Ls.$$.fragment,l),J(Ds.$$.fragment,l),J(Ps.$$.fragment,l),J(le.$$.fragment,l),J(se.$$.fragment,l),J(Ql.$$.fragment,l),J(wl),J(ne.$$.fragment,l),J(Me.$$.fragment,l),J(vl.$$.fragment,l),J(ie.$$.fragment,l),J(ye.$$.fragment,l),J(re.$$.fragment,l),J(oe.$$.fragment,l),J(ml),J(Te.$$.fragment,l),J(we.$$.fragment,l),J(bl),J(me.$$.fragment,l),J(hl),J(Il),J(ue.$$.fragment,l),J(A),J(Yl.$$.fragment,l),J(Q),J(fe.$$.fragment,l),J(Ce.$$.fragment,l),J(Ge.$$.fragment,l),J(Ze.$$.fragment,l),J(ge.$$.fragment,l),J(El.$$.fragment,l),J(Re.$$.fragment,l),Va=!1},d(l){l&&(e(U),e(n),e(r),e(j),e(W),e(k),e(g),e(Z),e(z),e(C),e($),e(B),e(V),e(Xl),e(S),e(Wl),e(N),e(O),e(E),e(ll),e(sl),e(Dl),e(tl),e(al),e($l),e(H),e(nl),e(Ul),e(Ml),e(pl),e(Vl),e(ol),e(L),e(il),e(zl),e(q),e(yl),e(rl),e(gl),e(i),e(Qe),e(Pe),e(ts),e(Oe),e(lt),e(ns),e(st),e(et),e(tt),e(is),e(at),e(nt),e(Mt),e(rs),e(pt),e(it),e(Us),e(yt),e(Jt),e(rt),e(Ts),e(Ut),e(ws),e(ot),e(ct),e(Tt),e(js),e(wt),e(bs),e(dt),e(mt),e(jt),e(fs),e(bt),e(ut),e(Is),e(ht),e(ft),e(It),e(_s),e(Ct),e(_t),e(Gt),e(Bs),e(Zt),e(Bt),e(gt),e(Rs),e(kt),e(Rt),e(Xt),e($s),e(Wt),e(Vs),e($t),e(zs),e(Vt),e(zt),e(xs),e(Nt),e(As),e(xt),e(At),e(Qt),e(Ys),e(vt),e(Yt),e(Et),e(Ss),e(Ft),e(St),e(Ht),e(qs),e(Lt),e(qt),e(Ks),e(Dt),e(Kt),e(Os),e(Pt),e(Ot),e(la),e(ee),e(sa),e(ea),e(ve),e(te),e(ta),e(Ye),e(ae),e(aa),e(na),e(Ma),e(pa),e(pe),e(ia),e(ya),e(Ja),e(Je),e(ra),e(Ua),e(Ue),e(oa),e(ca),e(ce),e(Ta),e(Ee),e(wa),e(da),e(de),e(ma),e(Fe),e(ja),e(je),e(ba),e(Se),e(be),e(ua),e(He),e(ha),e(he),e(fa),e(Le),e(Ia),e(qe),e(Ca),e(Ie),e(_a),e(Ga),e(_e),e(Za),e(Ba),e(ga),e(Be),e(ka),e(Ra),e(ke),e(Xa),e(Wa),e($a),e(Ke)),e(a),w(G,l),w(R,l),Xe[_].d(l),w(el,l),w(P,l),w(Gl,l),We[x].d(l),w(Bl,l),w(Jl,l),$e[f].d(l),w(es,l),w(as,l),w(Ms,l),w(ps,l),w(ys,l),w(Js,l),w(Nl,l),w(os,l),w(cs,l),w(ds,l),w(ms,l),w(us,l),w(hs,l),w(xl,l),w(Cs,l),w(Al,l),w(Gs,l),w(Zs,l),w(gs,l),w(ks,l),w(Xs,l),w(Ws,l),w(Ns,l),w(Qs,l),w(vs,l),w(Es,l),w(Fs,l),w(Hs,l),w(Ls,l),w(Ds,l),w(Ps,l),w(le,l),w(se,l),w(Ql,l),D&&D.d(l),Ve[Tl].d(l),w(ne,l),w(Me,l),w(vl,l),w(ie,l),w(ye,l),w(re,l),w(oe,l),ze[dl].d(l),w(Te,l),w(we,l),Ne[jl].d(l),w(me,l),xe[ul].d(l),Ae[fl].d(l),w(ue,l),A&&A.d(l),w(Yl,l),Q&&Q.d(l),w(fe,l),w(Ce,l),w(Ge,l),w(Ze,l),w(ge,l),w(El,l),w(Re,l)}}}const vM='{"title":"微調掩碼語言模型","local":"微調掩碼語言模型","sections":[{"title":"選擇用於掩碼語言建模的預訓練模型","local":"選擇用於掩碼語言建模的預訓練模型","sections":[],"depth":2},{"title":"數據集","local":"數據集","sections":[],"depth":2},{"title":"預處理數據","local":"預處理數據","sections":[],"depth":2},{"title":"使用 Trainer API 微調DistilBERT","local":"使用-trainer-api-微調distilbert","sections":[{"title":"語言模型的perplexity","local":"語言模型的perplexity","sections":[],"depth":3}],"depth":2},{"title":"使用 🤗 Accelerate 微調 DistilBERT","local":"使用--accelerate-微調-distilbert","sections":[],"depth":2},{"title":"使用我們微調的模型","local":"使用我們微調的模型","sections":[],"depth":2}],"depth":1}';function YM(I,a,U){let n="pt";return JM(()=>{const r=new URLSearchParams(window.location.search);U(0,n=r.get("fw")||"pt")}),[n]}class PM extends rM{constructor(a){super(),UM(this,a,YM,QM,yM,{})}}export{PM as component};
