import{S as qm,i as Mm,s as Tm,e as i,t as a,c as p,a as _,h as l,d as t,g as n,G as s,k as f,w as j,m as d,x as y,y as E,q as g,o as b,B as x,b as q,M as zm,N as Fr,p as at,v as Am,n as lt}from"../../chunks/vendor-hf-doc-builder.js";import{T as St}from"../../chunks/Tip-hf-doc-builder.js";import{Y as Co}from"../../chunks/Youtube-hf-doc-builder.js";import{I as E_}from"../../chunks/IconCopyLink-hf-doc-builder.js";import{C as T}from"../../chunks/CodeBlock-hf-doc-builder.js";import{D as Dm}from"../../chunks/DocNotebookDropdown-hf-doc-builder.js";import{F as Cm}from"../../chunks/FrameworkSwitchCourse-hf-doc-builder.js";function Pm(O){let o,h;return o=new Dm({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(){j(o.$$.fragment)},l(c){y(o.$$.fragment,c)},m(c,w){E(o,c,w),h=!0},i(c){h||(g(o.$$.fragment,c),h=!0)},o(c){b(o.$$.fragment,c),h=!1},d(c){x(o,c)}}}function Sm(O){let o,h;return o=new Dm({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(){j(o.$$.fragment)},l(c){y(o.$$.fragment,c)},m(c,w){E(o,c,w),h=!0},i(c){h||(g(o.$$.fragment,c),h=!0)},o(c){b(o.$$.fragment,c),h=!1},d(c){x(o,c)}}}function Om(O){let o,h,c,w,D;return{c(){o=i("p"),h=a("\u{1F64B} \u5982\u679C\u60A8\u5BF9\u201C\u63A9\u7801\u8BED\u8A00\u5EFA\u6A21\u201D\u548C\u201C\u9884\u8BAD\u7EC3\u6A21\u578B\u201D\u8FD9\u4E24\u4E2A\u672F\u8BED\u611F\u5230\u964C\u751F, \u8BF7\u67E5\u770B"),c=i("a"),w=a("\u7B2C\u4E00\u7AE0"),D=a(", \u6211\u4EEC\u5728\u5176\u4E2D\u89E3\u91CA\u4E86\u6240\u6709\u8FD9\u4E9B\u6838\u5FC3\u6982\u5FF5, \u5E76\u9644\u6709\u89C6\u9891!"),this.h()},l($){o=p($,"P",{});var k=_(o);h=l(k,"\u{1F64B} \u5982\u679C\u60A8\u5BF9\u201C\u63A9\u7801\u8BED\u8A00\u5EFA\u6A21\u201D\u548C\u201C\u9884\u8BAD\u7EC3\u6A21\u578B\u201D\u8FD9\u4E24\u4E2A\u672F\u8BED\u611F\u5230\u964C\u751F, \u8BF7\u67E5\u770B"),c=p(k,"A",{href:!0});var M=_(c);w=l(M,"\u7B2C\u4E00\u7AE0"),M.forEach(t),D=l(k,", \u6211\u4EEC\u5728\u5176\u4E2D\u89E3\u91CA\u4E86\u6240\u6709\u8FD9\u4E9B\u6838\u5FC3\u6982\u5FF5, \u5E76\u9644\u6709\u89C6\u9891!"),k.forEach(t),this.h()},h(){q(c,"href","/course/chapter1")},m($,k){n($,o,k),s(o,h),s(o,c),s(c,w),s(o,D)},d($){$&&t(o)}}}function Km(O){let o,h,c,w,D,$,k,M,u,A,P,K,L,N,H,F,B,W;return k=new T({props:{code:`from transformers import TFAutoModelForMaskedLM

model_checkpoint = "distilbert-base-uncased"
model = TFAutoModelForMaskedLM.from_pretrained(model_checkpoint)`,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)`}}),H=new T({props:{code:`model(model.dummy_inputs)  # Build the model
model.summary()`,highlighted:`model(model.dummy_inputs)  <span class="hljs-comment"># Build the model</span>
model.summary()`}}),B=new T({props:{code:`Model: "tf_distil_bert_for_masked_lm"
_________________________________________________________________
Layer (type)                 Output Shape              Param #   
=================================================================
distilbert (TFDistilBertMain multiple                  66362880  
_________________________________________________________________
vocab_transform (Dense)      multiple                  590592    
_________________________________________________________________
vocab_layer_norm (LayerNorma multiple                  1536      
_________________________________________________________________
vocab_projector (TFDistilBer multiple                  23866170  
=================================================================
Total params: 66,985,530
Trainable params: 66,985,530
Non-trainable params: 0
_________________________________________________________________`,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>
_________________________________________________________________`}}),{c(){o=i("p"),h=a("\u8BA9\u6211\u4EEC\u7EE7\u7EED, \u4F7F\u7528 "),c=i("code"),w=a("AutoModelForMaskedLM"),D=a(" \u7C7B\u4E0B\u8F7D DistilBERT:"),$=f(),j(k.$$.fragment),M=f(),u=i("p"),A=a("\u6211\u4EEC\u53EF\u4EE5\u901A\u8FC7\u8C03\u7528  "),P=i("code"),K=a("summary()"),L=a(" \u65B9\u6CD5\u67E5\u770B\u6A21\u578B\u6709\u591A\u5C11\u53C2\u6570:"),N=f(),j(H.$$.fragment),F=f(),j(B.$$.fragment)},l(v){o=p(v,"P",{});var R=_(o);h=l(R,"\u8BA9\u6211\u4EEC\u7EE7\u7EED, \u4F7F\u7528 "),c=p(R,"CODE",{});var I=_(c);w=l(I,"AutoModelForMaskedLM"),I.forEach(t),D=l(R," \u7C7B\u4E0B\u8F7D DistilBERT:"),R.forEach(t),$=d(v),y(k.$$.fragment,v),M=d(v),u=p(v,"P",{});var V=_(u);A=l(V,"\u6211\u4EEC\u53EF\u4EE5\u901A\u8FC7\u8C03\u7528  "),P=p(V,"CODE",{});var se=_(P);K=l(se,"summary()"),se.forEach(t),L=l(V," \u65B9\u6CD5\u67E5\u770B\u6A21\u578B\u6709\u591A\u5C11\u53C2\u6570:"),V.forEach(t),N=d(v),y(H.$$.fragment,v),F=d(v),y(B.$$.fragment,v)},m(v,R){n(v,o,R),s(o,h),s(o,c),s(c,w),s(o,D),n(v,$,R),E(k,v,R),n(v,M,R),n(v,u,R),s(u,A),s(u,P),s(P,K),s(u,L),n(v,N,R),E(H,v,R),n(v,F,R),E(B,v,R),W=!0},i(v){W||(g(k.$$.fragment,v),g(H.$$.fragment,v),g(B.$$.fragment,v),W=!0)},o(v){b(k.$$.fragment,v),b(H.$$.fragment,v),b(B.$$.fragment,v),W=!1},d(v){v&&t(o),v&&t($),x(k,v),v&&t(M),v&&t(u),v&&t(N),x(H,v),v&&t(F),x(B,v)}}}function Rm(O){let o,h,c,w,D,$,k,M,u,A,P,K,L,N,H,F,B,W;return k=new T({props:{code:`from transformers import AutoModelForMaskedLM

model_checkpoint = "distilbert-base-uncased"
model = AutoModelForMaskedLM.from_pretrained(model_checkpoint)`,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)`}}),H=new T({props:{code:`distilbert_num_parameters = model.num_parameters() / 1_000_000
print(f"'>>> DistilBERT number of parameters: {round(distilbert_num_parameters)}M'")
print(f"'>>> BERT number of parameters: 110M'")`,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>)`}}),B=new T({props:{code:`'>>> DistilBERT number of parameters: 67M'
'>>> BERT number of parameters: 110M'`,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>`}}),{c(){o=i("p"),h=a("\u8BA9\u6211\u4EEC\u7EE7\u7EED, \u4F7F\u7528 "),c=i("code"),w=a("AutoModelForMaskedLM"),D=a(" \u7C7B\u4E0B\u8F7D DistilBERT:"),$=f(),j(k.$$.fragment),M=f(),u=i("p"),A=a("\u6211\u4EEC\u53EF\u4EE5\u901A\u8FC7\u8C03\u7528 "),P=i("code"),K=a("num_parameters()"),L=a(" \u65B9\u6CD5\u67E5\u770B\u6A21\u578B\u6709\u591A\u5C11\u53C2\u6570:"),N=f(),j(H.$$.fragment),F=f(),j(B.$$.fragment)},l(v){o=p(v,"P",{});var R=_(o);h=l(R,"\u8BA9\u6211\u4EEC\u7EE7\u7EED, \u4F7F\u7528 "),c=p(R,"CODE",{});var I=_(c);w=l(I,"AutoModelForMaskedLM"),I.forEach(t),D=l(R," \u7C7B\u4E0B\u8F7D DistilBERT:"),R.forEach(t),$=d(v),y(k.$$.fragment,v),M=d(v),u=p(v,"P",{});var V=_(u);A=l(V,"\u6211\u4EEC\u53EF\u4EE5\u901A\u8FC7\u8C03\u7528 "),P=p(V,"CODE",{});var se=_(P);K=l(se,"num_parameters()"),se.forEach(t),L=l(V," \u65B9\u6CD5\u67E5\u770B\u6A21\u578B\u6709\u591A\u5C11\u53C2\u6570:"),V.forEach(t),N=d(v),y(H.$$.fragment,v),F=d(v),y(B.$$.fragment,v)},m(v,R){n(v,o,R),s(o,h),s(o,c),s(c,w),s(o,D),n(v,$,R),E(k,v,R),n(v,M,R),n(v,u,R),s(u,A),s(u,P),s(P,K),s(u,L),n(v,N,R),E(H,v,R),n(v,F,R),E(B,v,R),W=!0},i(v){W||(g(k.$$.fragment,v),g(H.$$.fragment,v),g(B.$$.fragment,v),W=!0)},o(v){b(k.$$.fragment,v),b(H.$$.fragment,v),b(B.$$.fragment,v),W=!1},d(v){v&&t(o),v&&t($),x(k,v),v&&t(M),v&&t(u),v&&t(N),x(H,v),v&&t(F),x(B,v)}}}function Lm(O){let o,h;return o=new T({props:{code:`import numpy as np
import tensorflow as tf

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

for token in top_5_tokens:
    print(f">>> {text.replace(tokenizer.mask_token, tokenizer.decode([token]))}")`,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>)`}}),{c(){j(o.$$.fragment)},l(c){y(o.$$.fragment,c)},m(c,w){E(o,c,w),h=!0},i(c){h||(g(o.$$.fragment,c),h=!0)},o(c){b(o.$$.fragment,c),h=!1},d(c){x(o,c)}}}function Bm(O){let o,h;return o=new T({props:{code:`import torch

inputs = tokenizer(text, return_tensors="pt")
token_logits = model(**inputs).logits
# Find the location of [MASK] and extract its logits
mask_token_index = torch.where(inputs["input_ids"] == tokenizer.mask_token_id)[1]
mask_token_logits = token_logits[0, mask_token_index, :]
# Pick the [MASK] candidates with the highest logits
top_5_tokens = torch.topk(mask_token_logits, 5, dim=1).indices[0].tolist()

for token in top_5_tokens:
    print(f"'>>> {text.replace(tokenizer.mask_token, tokenizer.decode([token]))}'")`,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>)`}}),{c(){j(o.$$.fragment)},l(c){y(o.$$.fragment,c)},m(c,w){E(o,c,w),h=!0},i(c){h||(g(o.$$.fragment,c),h=!0)},o(c){b(o.$$.fragment,c),h=!1},d(c){x(o,c)}}}function Hm(O){let o,h,c,w,D,$,k,M,u,A,P,K,L,N,H,F,B,W,v,R,I,V,se,Y,ye,ee;return{c(){o=i("p"),h=a("\u270F\uFE0F "),c=i("strong"),w=a("\u8BD5\u8BD5\u770B!"),D=a(" \u521B\u5EFA "),$=i("code"),k=a("\u65E0\u76D1\u7763"),M=a(" \u62C6\u5206\u7684\u968F\u673A\u6837\u672C, \u5E76\u9A8C\u8BC1\u6807\u7B7E\u65E2\u4E0D\u662F "),u=i("code"),A=a("0"),P=a(" \u4E5F\u4E0D\u662F "),K=i("code"),L=a("1"),N=a("\u3002\u5728\u6B64\u8FC7\u7A0B\u4E2D, \u4F60\u8FD8\u53EF\u4EE5\u68C0\u67E5 "),H=i("code"),F=a("train"),B=a(" \u548C "),W=i("code"),v=a("test"),R=a(" \u62C6\u5206\u4E2D\u7684\u6807\u7B7E\u662F\u5426\u786E\u5B9E\u4E3A "),I=i("code"),V=a("0"),se=a(" \u6216 "),Y=i("code"),ye=a("1"),ee=a(" \u2014 \u8FD9\u662F\u6BCF\u4E2A NLP \u4ECE\u4E1A\u8005\u5728\u65B0\u9879\u76EE\u5F00\u59CB\u65F6\u90FD\u5E94\u8BE5\u6267\u884C\u7684\u6709\u7528\u7684\u5065\u5168\u6027\u68C0\u67E5!")},l(ie){o=p(ie,"P",{});var G=_(o);h=l(G,"\u270F\uFE0F "),c=p(G,"STRONG",{});var fe=_(c);w=l(fe,"\u8BD5\u8BD5\u770B!"),fe.forEach(t),D=l(G," \u521B\u5EFA "),$=p(G,"CODE",{});var U=_($);k=l(U,"\u65E0\u76D1\u7763"),U.forEach(t),M=l(G," \u62C6\u5206\u7684\u968F\u673A\u6837\u672C, \u5E76\u9A8C\u8BC1\u6807\u7B7E\u65E2\u4E0D\u662F "),u=p(G,"CODE",{});var Fe=_(u);A=l(Fe,"0"),Fe.forEach(t),P=l(G," \u4E5F\u4E0D\u662F "),K=p(G,"CODE",{});var le=_(K);L=l(le,"1"),le.forEach(t),N=l(G,"\u3002\u5728\u6B64\u8FC7\u7A0B\u4E2D, \u4F60\u8FD8\u53EF\u4EE5\u68C0\u67E5 "),H=p(G,"CODE",{});var te=_(H);F=l(te,"train"),te.forEach(t),B=l(G," \u548C "),W=p(G,"CODE",{});var Me=_(W);v=l(Me,"test"),Me.forEach(t),R=l(G," \u62C6\u5206\u4E2D\u7684\u6807\u7B7E\u662F\u5426\u786E\u5B9E\u4E3A "),I=p(G,"CODE",{});var Q=_(I);V=l(Q,"0"),Q.forEach(t),se=l(G," \u6216 "),Y=p(G,"CODE",{});var Ee=_(Y);ye=l(Ee,"1"),Ee.forEach(t),ee=l(G," \u2014 \u8FD9\u662F\u6BCF\u4E2A NLP \u4ECE\u4E1A\u8005\u5728\u65B0\u9879\u76EE\u5F00\u59CB\u65F6\u90FD\u5E94\u8BE5\u6267\u884C\u7684\u6709\u7528\u7684\u5065\u5168\u6027\u68C0\u67E5!"),G.forEach(t)},m(ie,G){n(ie,o,G),s(o,h),s(o,c),s(c,w),s(o,D),s(o,$),s($,k),s(o,M),s(o,u),s(u,A),s(o,P),s(o,K),s(K,L),s(o,N),s(o,H),s(H,F),s(o,B),s(o,W),s(W,v),s(o,R),s(o,I),s(I,V),s(o,se),s(o,Y),s(Y,ye),s(o,ee)},d(ie){ie&&t(o)}}}function Fm(O){let o,h,c,w,D,$,k,M,u,A,P,K,L,N;return{c(){o=i("p"),h=a("\u270F\uFE0F "),c=i("strong"),w=a("\u8BD5\u8BD5\u770B!"),D=a(" \u4E00\u4E9B Transformer \u6A21\u578B, \u4F8B\u5982 "),$=i("a"),k=a("BigBird"),M=a(" \u548C "),u=i("a"),A=a("Longformer"),P=a(", \u5B83\u4EEC\u5177\u6709\u6BD4BERT\u548C\u5176\u4ED6\u65E9\u671FTransformer\u6A21\u578B\u66F4\u957F\u7684\u4E0A\u4E0B\u6587\u957F\u5EA6\u3002\u4E3A\u8FD9\u4E9B\u68C0\u67E5\u70B9\u4E4B\u4E00\u5B9E\u4F8B\u5316\u6807\u8BB0\u5668, \u5E76\u9A8C\u8BC1 "),K=i("code"),L=a("model_max_length"),N=a(" \u662F\u5426\u4E0E\u6A21\u578B\u5361\u4E0A\u5F15\u7528\u7684\u5185\u5BB9\u4E00\u81F4\u3002"),this.h()},l(H){o=p(H,"P",{});var F=_(o);h=l(F,"\u270F\uFE0F "),c=p(F,"STRONG",{});var B=_(c);w=l(B,"\u8BD5\u8BD5\u770B!"),B.forEach(t),D=l(F," \u4E00\u4E9B Transformer \u6A21\u578B, \u4F8B\u5982 "),$=p(F,"A",{href:!0,rel:!0});var W=_($);k=l(W,"BigBird"),W.forEach(t),M=l(F," \u548C "),u=p(F,"A",{href:!0});var v=_(u);A=l(v,"Longformer"),v.forEach(t),P=l(F,", \u5B83\u4EEC\u5177\u6709\u6BD4BERT\u548C\u5176\u4ED6\u65E9\u671FTransformer\u6A21\u578B\u66F4\u957F\u7684\u4E0A\u4E0B\u6587\u957F\u5EA6\u3002\u4E3A\u8FD9\u4E9B\u68C0\u67E5\u70B9\u4E4B\u4E00\u5B9E\u4F8B\u5316\u6807\u8BB0\u5668, \u5E76\u9A8C\u8BC1 "),K=p(F,"CODE",{});var R=_(K);L=l(R,"model_max_length"),R.forEach(t),N=l(F," \u662F\u5426\u4E0E\u6A21\u578B\u5361\u4E0A\u5F15\u7528\u7684\u5185\u5BB9\u4E00\u81F4\u3002"),F.forEach(t),this.h()},h(){q($,"href","https://huggingface.co/google/bigbird-roberta-base"),q($,"rel","nofollow"),q(u,"href","hf.co/allenai/longformer-base-4096")},m(H,F){n(H,o,F),s(o,h),s(o,c),s(c,w),s(o,D),s(o,$),s($,k),s(o,M),s(o,u),s(u,A),s(o,P),s(o,K),s(K,L),s(o,N)},d(H){H&&t(o)}}}function Nm(O){let o,h;return{c(){o=i("p"),h=a("\u8BF7\u6CE8\u610F, \u5728\u5B9E\u9645\u573A\u666F\u4E2D\u4F7F\u7528\u8F83\u5C0F\u7684\u5757\u5927\u5C0F\u53EF\u80FD\u662F\u6709\u5BB3\u7684, \u56E0\u6B64\u4F60\u5E94\u8BE5\u4F7F\u7528\u4E0E\u5C06\u5E94\u7528\u6A21\u578B\u7684\u7528\u4F8B\u76F8\u5BF9\u5E94\u7684\u5927\u5C0F\u3002")},l(c){o=p(c,"P",{});var w=_(o);h=l(w,"\u8BF7\u6CE8\u610F, \u5728\u5B9E\u9645\u573A\u666F\u4E2D\u4F7F\u7528\u8F83\u5C0F\u7684\u5757\u5927\u5C0F\u53EF\u80FD\u662F\u6709\u5BB3\u7684, \u56E0\u6B64\u4F60\u5E94\u8BE5\u4F7F\u7528\u4E0E\u5C06\u5E94\u7528\u6A21\u578B\u7684\u7528\u4F8B\u76F8\u5BF9\u5E94\u7684\u5927\u5C0F\u3002"),w.forEach(t)},m(c,w){n(c,o,w),s(o,h)},d(c){c&&t(o)}}}function Im(O){let o,h,c,w,D,$,k,M,u,A,P;return{c(){o=i("p"),h=a("\u270F\uFE0F "),c=i("strong"),w=a("\u8BD5\u8BD5\u770B!"),D=a(" \u591A\u6B21\u8FD0\u884C\u4E0A\u9762\u7684\u4EE3\u7801\u7247\u6BB5, \u770B\u770B\u968F\u673A\u5C4F\u853D\u53D1\u751F\u5728\u4F60\u773C\u524D! \u8FD8\u8981\u5C06 "),$=i("code"),k=a("tokenizer.decode()"),M=a(" \u65B9\u6CD5\u66FF\u6362\u4E3A "),u=i("code"),A=a("tokenizer.convert_ids_to_tokens()"),P=a(" \u4EE5\u67E5\u770B\u6709\u65F6\u4F1A\u5C4F\u853D\u7ED9\u5B9A\u5355\u8BCD\u4E2D\u7684\u5355\u4E2A\u6807\u8BB0, \u800C\u4E0D\u662F\u5176\u4ED6\u6807\u8BB0\u3002")},l(K){o=p(K,"P",{});var L=_(o);h=l(L,"\u270F\uFE0F "),c=p(L,"STRONG",{});var N=_(c);w=l(N,"\u8BD5\u8BD5\u770B!"),N.forEach(t),D=l(L," \u591A\u6B21\u8FD0\u884C\u4E0A\u9762\u7684\u4EE3\u7801\u7247\u6BB5, \u770B\u770B\u968F\u673A\u5C4F\u853D\u53D1\u751F\u5728\u4F60\u773C\u524D! \u8FD8\u8981\u5C06 "),$=p(L,"CODE",{});var H=_($);k=l(H,"tokenizer.decode()"),H.forEach(t),M=l(L," \u65B9\u6CD5\u66FF\u6362\u4E3A "),u=p(L,"CODE",{});var F=_(u);A=l(F,"tokenizer.convert_ids_to_tokens()"),F.forEach(t),P=l(L," \u4EE5\u67E5\u770B\u6709\u65F6\u4F1A\u5C4F\u853D\u7ED9\u5B9A\u5355\u8BCD\u4E2D\u7684\u5355\u4E2A\u6807\u8BB0, \u800C\u4E0D\u662F\u5176\u4ED6\u6807\u8BB0\u3002"),L.forEach(t)},m(K,L){n(K,o,L),s(o,h),s(o,c),s(c,w),s(o,D),s(o,$),s($,k),s(o,M),s(o,u),s(u,A),s(o,P)},d(K){K&&t(o)}}}function ym(O){let o,h,c,w,D;return{c(){o=i("p"),h=a("\u968F\u673A\u63A9\u7801\u7684\u4E00\u4E2A\u526F\u4F5C\u7528\u662F, \u5F53\u4F7F\u7528 "),c=i("code"),w=a("Trainer"),D=a(" \u65F6, \u6211\u4EEC\u7684\u8BC4\u4F30\u6307\u6807\u5C06\u4E0D\u662F\u786E\u5B9A\u6027\u7684, \u56E0\u4E3A\u6211\u4EEC\u5BF9\u8BAD\u7EC3\u96C6\u548C\u6D4B\u8BD5\u96C6\u4F7F\u7528\u76F8\u540C\u7684\u6570\u636E\u6574\u7406\u5668\u3002\u7A0D\u540E\u6211\u4EEC\u4F1A\u770B\u5230, \u5F53\u6211\u4EEC\u4F7F\u7528 \u{1F917} Accelerate \u8FDB\u884C\u5FAE\u8C03\u65F6, \u6211\u4EEC\u5C06\u5982\u4F55\u5229\u7528\u81EA\u5B9A\u4E49\u8BC4\u4F30\u5FAA\u73AF\u7684\u7075\u6D3B\u6027\u6765\u51BB\u7ED3\u968F\u673A\u6027\u3002")},l($){o=p($,"P",{});var k=_(o);h=l(k,"\u968F\u673A\u63A9\u7801\u7684\u4E00\u4E2A\u526F\u4F5C\u7528\u662F, \u5F53\u4F7F\u7528 "),c=p(k,"CODE",{});var M=_(c);w=l(M,"Trainer"),M.forEach(t),D=l(k," \u65F6, \u6211\u4EEC\u7684\u8BC4\u4F30\u6307\u6807\u5C06\u4E0D\u662F\u786E\u5B9A\u6027\u7684, \u56E0\u4E3A\u6211\u4EEC\u5BF9\u8BAD\u7EC3\u96C6\u548C\u6D4B\u8BD5\u96C6\u4F7F\u7528\u76F8\u540C\u7684\u6570\u636E\u6574\u7406\u5668\u3002\u7A0D\u540E\u6211\u4EEC\u4F1A\u770B\u5230, \u5F53\u6211\u4EEC\u4F7F\u7528 \u{1F917} Accelerate \u8FDB\u884C\u5FAE\u8C03\u65F6, \u6211\u4EEC\u5C06\u5982\u4F55\u5229\u7528\u81EA\u5B9A\u4E49\u8BC4\u4F30\u5FAA\u73AF\u7684\u7075\u6D3B\u6027\u6765\u51BB\u7ED3\u968F\u673A\u6027\u3002"),k.forEach(t)},m($,k){n($,o,k),s(o,h),s(o,c),s(c,w),s(o,D)},d($){$&&t(o)}}}function Gm(O){let o,h;return o=new T({props:{code:`import collections
import numpy as np

from transformers.data import tf_default_data_collator

wwm_probability = 0.2


def whole_word_masking_data_collator(features):
    for feature in features:
        word_ids = feature.pop("word_ids")

        # Create a map between words and corresponding token indices
        mapping = collections.defaultdict(list)
        current_word_index = -1
        current_word = None
        for idx, word_id in enumerate(word_ids):
            if word_id is not None:
                if word_id != current_word:
                    current_word = word_id
                    current_word_index += 1
                mapping[current_word_index].append(idx)

        # Randomly mask words
        mask = np.random.binomial(1, wwm_probability, (len(mapping),))
        input_ids = feature["input_ids"]
        labels = feature["labels"]
        new_labels = [-100] * len(labels)
        for word_id in np.where(mask)[0]:
            word_id = word_id.item()
            for idx in mapping[word_id]:
                new_labels[idx] = labels[idx]
                input_ids[idx] = tokenizer.mask_token_id
        feature["labels"] = new_labels

    return tf_default_data_collator(features)`,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)`}}),{c(){j(o.$$.fragment)},l(c){y(o.$$.fragment,c)},m(c,w){E(o,c,w),h=!0},i(c){h||(g(o.$$.fragment,c),h=!0)},o(c){b(o.$$.fragment,c),h=!1},d(c){x(o,c)}}}function Um(O){let o,h;return o=new T({props:{code:`import collections
import numpy as np

from transformers import default_data_collator

wwm_probability = 0.2


def whole_word_masking_data_collator(features):
    for feature in features:
        word_ids = feature.pop("word_ids")

        # Create a map between words and corresponding token indices
        mapping = collections.defaultdict(list)
        current_word_index = -1
        current_word = None
        for idx, word_id in enumerate(word_ids):
            if word_id is not None:
                if word_id != current_word:
                    current_word = word_id
                    current_word_index += 1
                mapping[current_word_index].append(idx)

        # Randomly mask words
        mask = np.random.binomial(1, wwm_probability, (len(mapping),))
        input_ids = feature["input_ids"]
        labels = feature["labels"]
        new_labels = [-100] * len(labels)
        for word_id in np.where(mask)[0]:
            word_id = word_id.item()
            for idx in mapping[word_id]:
                new_labels[idx] = labels[idx]
                input_ids[idx] = tokenizer.mask_token_id
        feature["labels"] = new_labels

    return default_data_collator(features)`,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)`}}),{c(){j(o.$$.fragment)},l(c){y(o.$$.fragment,c)},m(c,w){E(o,c,w),h=!0},i(c){h||(g(o.$$.fragment,c),h=!0)},o(c){b(o.$$.fragment,c),h=!1},d(c){x(o,c)}}}function Wm(O){let o,h,c,w,D,$,k,M,u,A,P;return{c(){o=i("p"),h=a("\u270F\uFE0F "),c=i("strong"),w=a("\u8BD5\u8BD5\u770B!"),D=a(" \u591A\u6B21\u8FD0\u884C\u4E0A\u9762\u7684\u4EE3\u7801\u7247\u6BB5, \u770B\u770B\u968F\u673A\u5C4F\u853D\u53D1\u751F\u5728\u4F60\u773C\u524D! \u8FD8\u8981\u5C06 "),$=i("code"),k=a("tokenizer.decode()"),M=a(" \u65B9\u6CD5\u66FF\u6362\u4E3A "),u=i("code"),A=a("tokenizer.convert_ids_to_tokens()"),P=a(" \u4EE5\u67E5\u770B\u6765\u81EA\u7ED9\u5B9A\u5355\u8BCD\u7684\u6807\u8BB0\u59CB\u7EC8\u88AB\u5C4F\u853D\u5728\u4E00\u8D77\u3002")},l(K){o=p(K,"P",{});var L=_(o);h=l(L,"\u270F\uFE0F "),c=p(L,"STRONG",{});var N=_(c);w=l(N,"\u8BD5\u8BD5\u770B!"),N.forEach(t),D=l(L," \u591A\u6B21\u8FD0\u884C\u4E0A\u9762\u7684\u4EE3\u7801\u7247\u6BB5, \u770B\u770B\u968F\u673A\u5C4F\u853D\u53D1\u751F\u5728\u4F60\u773C\u524D! \u8FD8\u8981\u5C06 "),$=p(L,"CODE",{});var H=_($);k=l(H,"tokenizer.decode()"),H.forEach(t),M=l(L," \u65B9\u6CD5\u66FF\u6362\u4E3A "),u=p(L,"CODE",{});var F=_(u);A=l(F,"tokenizer.convert_ids_to_tokens()"),F.forEach(t),P=l(L," \u4EE5\u67E5\u770B\u6765\u81EA\u7ED9\u5B9A\u5355\u8BCD\u7684\u6807\u8BB0\u59CB\u7EC8\u88AB\u5C4F\u853D\u5728\u4E00\u8D77\u3002"),L.forEach(t)},m(K,L){n(K,o,L),s(o,h),s(o,c),s(c,w),s(o,D),s(o,$),s($,k),s(o,M),s(o,u),s(u,A),s(o,P)},d(K){K&&t(o)}}}function Ym(O){let o,h,c,w,D,$,k,M,u,A,P,K,L,N,H,F,B,W,v,R,I,V,se,Y,ye,ee,ie,G,fe,U,Fe,le,te,Me,Q,Ee,Te,Ie,pe,ze,xe,re,ue,De,ke,me,Ge,he,$e,ae,we,ve,Ue,je,C,J,Oe,_e,Ke,We,ne,ge,oe,qe,de,Ae,Re,ls,Ye;return k=new T({props:{code:`from transformers import TrainingArguments

batch_size = 64
# Show the training loss with every epoch
logging_steps = len(downsampled_dataset["train"]) // batch_size
model_name = model_checkpoint.split("/")[-1]

training_args = TrainingArguments(
    output_dir=f"{model_name}-finetuned-imdb",
    overwrite_output_dir=True,
    evaluation_strategy="epoch",
    learning_rate=2e-5,
    weight_decay=0.01,
    per_device_train_batch_size=batch_size,
    per_device_eval_batch_size=batch_size,
    push_to_hub=True,
    fp16=True,
    logging_steps=logging_steps,
)`,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,
)`}}),Ke=new T({props:{code:`from transformers import Trainer

trainer = Trainer(
    model=model,
    args=training_args,
    train_dataset=downsampled_dataset["train"],
    eval_dataset=downsampled_dataset["test"],
    data_collator=data_collator,
    tokenizer=tokenizer,
)`,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,
)`}}),{c(){o=i("p"),h=a("\u767B\u9646\u540E, \u6211\u4EEC\u53EF\u4EE5\u6307\u5B9A "),c=i("code"),w=a("Trainer"),D=a(" \u53C2\u6570:"),$=f(),j(k.$$.fragment),M=f(),u=i("p"),A=a("\u5728\u8FD9\u91CC, \u6211\u4EEC\u8C03\u6574\u4E86\u4E00\u4E9B\u9ED8\u8BA4\u9009\u9879, \u5305\u62EC "),P=i("code"),K=a("logging_steps"),L=a(" , \u4EE5\u786E\u4FDD\u6211\u4EEC\u8DDF\u8E2A\u6BCF\u4E2Aepoch\u7684\u8BAD\u7EC3\u635F\u5931\u3002\u6211\u4EEC\u8FD8\u4F7F\u7528\u4E86 "),N=i("code"),H=a("fp16=True"),F=a(" \u6765\u5B9E\u73B0\u6DF7\u5408\u7CBE\u5EA6\u8BAD\u7EC3, \u8FD9\u7ED9\u6211\u4EEC\u5E26\u6765\u4E86\u53E6\u4E00\u4E2A\u901F\u5EA6\u63D0\u5347\u3002\u9ED8\u8BA4\u60C5\u51B5\u4E0B, "),B=i("code"),W=a("Trainer"),v=a(" \u5C06\u5220\u9664\u4E0D\u5C5E\u4E8E\u6A21\u578B\u7684 "),R=i("code"),I=a("forward()"),V=a(" \u65B9\u6CD5\u7684\u5217\u3002\u8FD9\u610F\u5473\u7740, \u5982\u679C\u4F60\u4F7F\u7528\u6574\u4E2A\u5355\u8BCD\u5C4F\u853D\u6392\u5E8F\u5668, \u4F60\u8FD8\u9700\u8981\u8BBE\u7F6E "),se=i("code"),Y=a("remove_unused_columns=False"),ye=a(", \u4EE5\u786E\u4FDD\u6211\u4EEC\u4E0D\u4F1A\u5728\u8BAD\u7EC3\u671F\u95F4\u4E22\u5931 "),ee=i("code"),ie=a("word_ids"),G=a(" \u5217\u3002"),fe=f(),U=i("p"),Fe=a("\u8BF7\u6CE8\u610F, \u4F60\u53EF\u4EE5\u4F7F\u7528 "),le=i("code"),te=a("hub_model_id"),Me=a(" \u53C2\u6570\u6307\u5B9A\u8981\u63A8\u9001\u5230\u7684\u5B58\u50A8\u5E93\u7684\u540D\u79F0((\u7279\u522B\u662F\u4F60\u5C06\u5FC5\u987B\u4F7F\u7528\u8BE5\u53C2\u6570\u5411\u7EC4\u7EC7\u63A8\u9001)\u3002\u4F8B\u5982, \u5F53\u6211\u4EEC\u5C06\u6A21\u578B\u63A8\u9001\u5230 "),Q=i("a"),Ee=i("code"),Te=a("huggingface-course"),Ie=a(" organization"),pe=a(" \u65F6, \u6211\u4EEC\u6DFB\u52A0\u4E86 "),ze=i("code"),xe=a('hub_model_id="huggingface-course/distilbert-finetuned-imdb"'),re=a(" \u5230 "),ue=i("code"),De=a("TrainingArguments"),ke=a(" \u4E2D\u3002\u9ED8\u8BA4\u60C5\u51B5\u4E0B, \u4F7F\u7528\u7684\u5B58\u50A8\u5E93\u5C06\u5728\u4F60\u7684\u547D\u540D\u7A7A\u95F4\u4E2D\u5E76\u4EE5\u4F60\u8BBE\u7F6E\u7684\u8F93\u51FA\u76EE\u5F55\u547D\u540D, \u56E0\u6B64\u5728\u6211\u4EEC\u7684\u793A\u4F8B\u4E2D, \u5B83\u5C06\u662F "),me=i("code"),Ge=a('"lewtun/distilbert-finetuned-imdb"'),he=a("\u3002"),$e=f(),ae=i("p"),we=a("\u6211\u4EEC\u73B0\u5728\u62E5\u6709\u5B9E\u4F8B\u5316 "),ve=i("code"),Ue=a("Trainer"),je=a(" \u7684\u6240\u6709\u6210\u5206\u3002\u8FD9\u91CC\u6211\u4EEC\u53EA\u4F7F\u7528\u6807\u51C6\u7684 "),C=i("code"),J=a("data_collator"),Oe=a(", \u4F46\u4F60\u53EF\u4EE5\u5C1D\u8BD5\u4F7F\u7528\u6574\u4E2A\u5355\u8BCD\u63A9\u7801\u6574\u7406\u5668\u5E76\u6BD4\u8F83\u7ED3\u679C\u4F5C\u4E3A\u7EC3\u4E60:"),_e=f(),j(Ke.$$.fragment),We=f(),ne=i("p"),ge=a("\u6211\u4EEC\u73B0\u5728\u51C6\u5907\u8FD0\u884C "),oe=i("code"),qe=a("trainer.train()"),de=a(" \u2014 \u4F46\u5728\u6B64\u4E4B\u524D\u8BA9\u6211\u4EEC\u7B80\u8981\u5730\u770B\u4E00\u4E0B "),Ae=i("em"),Re=a("perplexity"),ls=a(", \u8FD9\u662F\u8BC4\u4F30\u8BED\u8A00\u6A21\u578B\u6027\u80FD\u7684\u5E38\u7528\u6307\u6807\u3002"),this.h()},l(z){o=p(z,"P",{});var X=_(o);h=l(X,"\u767B\u9646\u540E, \u6211\u4EEC\u53EF\u4EE5\u6307\u5B9A "),c=p(X,"CODE",{});var Ve=_(c);w=l(Ve,"Trainer"),Ve.forEach(t),D=l(X," \u53C2\u6570:"),X.forEach(t),$=d(z),y(k.$$.fragment,z),M=d(z),u=p(z,"P",{});var be=_(u);A=l(be,"\u5728\u8FD9\u91CC, \u6211\u4EEC\u8C03\u6574\u4E86\u4E00\u4E9B\u9ED8\u8BA4\u9009\u9879, \u5305\u62EC "),P=p(be,"CODE",{});var ss=_(P);K=l(ss,"logging_steps"),ss.forEach(t),L=l(be," , \u4EE5\u786E\u4FDD\u6211\u4EEC\u8DDF\u8E2A\u6BCF\u4E2Aepoch\u7684\u8BAD\u7EC3\u635F\u5931\u3002\u6211\u4EEC\u8FD8\u4F7F\u7528\u4E86 "),N=p(be,"CODE",{});var Je=_(N);H=l(Je,"fp16=True"),Je.forEach(t),F=l(be," \u6765\u5B9E\u73B0\u6DF7\u5408\u7CBE\u5EA6\u8BAD\u7EC3, \u8FD9\u7ED9\u6211\u4EEC\u5E26\u6765\u4E86\u53E6\u4E00\u4E2A\u901F\u5EA6\u63D0\u5347\u3002\u9ED8\u8BA4\u60C5\u51B5\u4E0B, "),B=p(be,"CODE",{});var ys=_(B);W=l(ys,"Trainer"),ys.forEach(t),v=l(be," \u5C06\u5220\u9664\u4E0D\u5C5E\u4E8E\u6A21\u578B\u7684 "),R=p(be,"CODE",{});var ps=_(R);I=l(ps,"forward()"),ps.forEach(t),V=l(be," \u65B9\u6CD5\u7684\u5217\u3002\u8FD9\u610F\u5473\u7740, \u5982\u679C\u4F60\u4F7F\u7528\u6574\u4E2A\u5355\u8BCD\u5C4F\u853D\u6392\u5E8F\u5668, \u4F60\u8FD8\u9700\u8981\u8BBE\u7F6E "),se=p(be,"CODE",{});var Es=_(se);Y=l(Es,"remove_unused_columns=False"),Es.forEach(t),ye=l(be,", \u4EE5\u786E\u4FDD\u6211\u4EEC\u4E0D\u4F1A\u5728\u8BAD\u7EC3\u671F\u95F4\u4E22\u5931 "),ee=p(be,"CODE",{});var Ce=_(ee);ie=l(Ce,"word_ids"),Ce.forEach(t),G=l(be," \u5217\u3002"),be.forEach(t),fe=d(z),U=p(z,"P",{});var Z=_(U);Fe=l(Z,"\u8BF7\u6CE8\u610F, \u4F60\u53EF\u4EE5\u4F7F\u7528 "),le=p(Z,"CODE",{});var rs=_(le);te=l(rs,"hub_model_id"),rs.forEach(t),Me=l(Z," \u53C2\u6570\u6307\u5B9A\u8981\u63A8\u9001\u5230\u7684\u5B58\u50A8\u5E93\u7684\u540D\u79F0((\u7279\u522B\u662F\u4F60\u5C06\u5FC5\u987B\u4F7F\u7528\u8BE5\u53C2\u6570\u5411\u7EC4\u7EC7\u63A8\u9001)\u3002\u4F8B\u5982, \u5F53\u6211\u4EEC\u5C06\u6A21\u578B\u63A8\u9001\u5230 "),Q=p(Z,"A",{href:!0,rel:!0});var Le=_(Q);Ee=p(Le,"CODE",{});var xs=_(Ee);Te=l(xs,"huggingface-course"),xs.forEach(t),Ie=l(Le," organization"),Le.forEach(t),pe=l(Z," \u65F6, \u6211\u4EEC\u6DFB\u52A0\u4E86 "),ze=p(Z,"CODE",{});var Qe=_(ze);xe=l(Qe,'hub_model_id="huggingface-course/distilbert-finetuned-imdb"'),Qe.forEach(t),re=l(Z," \u5230 "),ue=p(Z,"CODE",{});var ns=_(ue);De=l(ns,"TrainingArguments"),ns.forEach(t),ke=l(Z," \u4E2D\u3002\u9ED8\u8BA4\u60C5\u51B5\u4E0B, \u4F7F\u7528\u7684\u5B58\u50A8\u5E93\u5C06\u5728\u4F60\u7684\u547D\u540D\u7A7A\u95F4\u4E2D\u5E76\u4EE5\u4F60\u8BBE\u7F6E\u7684\u8F93\u51FA\u76EE\u5F55\u547D\u540D, \u56E0\u6B64\u5728\u6211\u4EEC\u7684\u793A\u4F8B\u4E2D, \u5B83\u5C06\u662F "),me=p(Z,"CODE",{});var _s=_(me);Ge=l(_s,'"lewtun/distilbert-finetuned-imdb"'),_s.forEach(t),he=l(Z,"\u3002"),Z.forEach(t),$e=d(z),ae=p(z,"P",{});var ce=_(ae);we=l(ce,"\u6211\u4EEC\u73B0\u5728\u62E5\u6709\u5B9E\u4F8B\u5316 "),ve=p(ce,"CODE",{});var Bs=_(ve);Ue=l(Bs,"Trainer"),Bs.forEach(t),je=l(ce," \u7684\u6240\u6709\u6210\u5206\u3002\u8FD9\u91CC\u6211\u4EEC\u53EA\u4F7F\u7528\u6807\u51C6\u7684 "),C=p(ce,"CODE",{});var cs=_(C);J=l(cs,"data_collator"),cs.forEach(t),Oe=l(ce,", \u4F46\u4F60\u53EF\u4EE5\u5C1D\u8BD5\u4F7F\u7528\u6574\u4E2A\u5355\u8BCD\u63A9\u7801\u6574\u7406\u5668\u5E76\u6BD4\u8F83\u7ED3\u679C\u4F5C\u4E3A\u7EC3\u4E60:"),ce.forEach(t),_e=d(z),y(Ke.$$.fragment,z),We=d(z),ne=p(z,"P",{});var Be=_(ne);ge=l(Be,"\u6211\u4EEC\u73B0\u5728\u51C6\u5907\u8FD0\u884C "),oe=p(Be,"CODE",{});var Ds=_(oe);qe=l(Ds,"trainer.train()"),Ds.forEach(t),de=l(Be," \u2014 \u4F46\u5728\u6B64\u4E4B\u524D\u8BA9\u6211\u4EEC\u7B80\u8981\u5730\u770B\u4E00\u4E0B "),Ae=p(Be,"EM",{});var Ne=_(Ae);Re=l(Ne,"perplexity"),Ne.forEach(t),ls=l(Be,", \u8FD9\u662F\u8BC4\u4F30\u8BED\u8A00\u6A21\u578B\u6027\u80FD\u7684\u5E38\u7528\u6307\u6807\u3002"),Be.forEach(t),this.h()},h(){q(Q,"href","https://huggingface.co/huggingface-course"),q(Q,"rel","nofollow")},m(z,X){n(z,o,X),s(o,h),s(o,c),s(c,w),s(o,D),n(z,$,X),E(k,z,X),n(z,M,X),n(z,u,X),s(u,A),s(u,P),s(P,K),s(u,L),s(u,N),s(N,H),s(u,F),s(u,B),s(B,W),s(u,v),s(u,R),s(R,I),s(u,V),s(u,se),s(se,Y),s(u,ye),s(u,ee),s(ee,ie),s(u,G),n(z,fe,X),n(z,U,X),s(U,Fe),s(U,le),s(le,te),s(U,Me),s(U,Q),s(Q,Ee),s(Ee,Te),s(Q,Ie),s(U,pe),s(U,ze),s(ze,xe),s(U,re),s(U,ue),s(ue,De),s(U,ke),s(U,me),s(me,Ge),s(U,he),n(z,$e,X),n(z,ae,X),s(ae,we),s(ae,ve),s(ve,Ue),s(ae,je),s(ae,C),s(C,J),s(ae,Oe),n(z,_e,X),E(Ke,z,X),n(z,We,X),n(z,ne,X),s(ne,ge),s(ne,oe),s(oe,qe),s(ne,de),s(ne,Ae),s(Ae,Re),s(ne,ls),Ye=!0},i(z){Ye||(g(k.$$.fragment,z),g(Ke.$$.fragment,z),Ye=!0)},o(z){b(k.$$.fragment,z),b(Ke.$$.fragment,z),Ye=!1},d(z){z&&t(o),z&&t($),x(k,z),z&&t(M),z&&t(u),z&&t(fe),z&&t(U),z&&t($e),z&&t(ae),z&&t(_e),x(Ke,z),z&&t(We),z&&t(ne)}}}function Vm(O){let o,h,c,w,D,$,k,M,u,A,P,K,L,N,H,F,B,W,v,R,I,V,se,Y,ye,ee,ie,G,fe,U,Fe,le,te,Me,Q,Ee,Te,Ie,pe,ze,xe,re,ue,De,ke,me,Ge,he,$e,ae,we,ve,Ue,je;return k=new T({props:{code:`tf_train_dataset = downsampled_dataset["train"].to_tf_dataset(
    columns=["input_ids", "attention_mask", "labels"],
    collate_fn=data_collator,
    shuffle=True,
    batch_size=32,
)

tf_eval_dataset = downsampled_dataset["test"].to_tf_dataset(
    columns=["input_ids", "attention_mask", "labels"],
    collate_fn=data_collator,
    shuffle=False,
    batch_size=32,
)`,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>,
)`}}),De=new T({props:{code:`from transformers import create_optimizer
from transformers.keras_callbacks import PushToHubCallback
import tensorflow as tf

num_train_steps = len(tf_train_dataset)
optimizer, schedule = create_optimizer(
    init_lr=2e-5,
    num_warmup_steps=1_000,
    num_train_steps=num_train_steps,
    weight_decay_rate=0.01,
)
model.compile(optimizer=optimizer)

# Train in mixed-precision float16
tf.keras.mixed_precision.set_global_policy("mixed_float16")

callback = PushToHubCallback(
    output_dir=f"{model_name}-finetuned-imdb", tokenizer=tokenizer
)`,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
)`}}),{c(){o=i("p"),h=a("\u767B\u9646\u540E, \u6211\u4EEC\u5C31\u53EF\u4EE5\u521B\u5EFA\u6211\u4EEC\u7684 "),c=i("code"),w=a("tf.data"),D=a(" \u6570\u636E\u96C6\u3002\u6211\u4EEC\u5C06\u5728\u8FD9\u91CC\u53EA\u4F7F\u7528\u6807\u51C6\u6570\u636E\u6574\u7406\u5668, \u4F46\u4F60\u4E5F\u53EF\u4EE5\u5C1D\u8BD5\u4F7F\u7528\u6574\u4E2A\u5355\u8BCD\u63A9\u7801\u6574\u7406\u5668\u5E76\u5C06\u7ED3\u679C\u4F5C\u4E3A\u7EC3\u4E60\u8FDB\u884C\u6BD4\u8F83:"),$=f(),j(k.$$.fragment),M=f(),u=i("p"),A=a("\u63A5\u4E0B\u6765, \u6211\u4EEC\u8BBE\u7F6E\u8BAD\u7EC3\u8D85\u53C2\u6570\u5E76\u7F16\u8BD1\u6A21\u578B\u3002\u6211\u4EEC\u4F7F\u7528 \u{1F917} Transformers \u5E93\u4E2D\u7684 "),P=i("code"),K=a("create_optimizer()"),L=a(" \u51FD\u6570, \u5B83\u63D0\u4F9B\u4E86\u4E00\u4E2A\u5177\u6709\u7EBF\u6027\u5B66\u4E60\u7387\u8870\u51CF\u7684 "),N=i("code"),H=a("AdamW"),F=a(" \u4F18\u5316\u5668\u3002\u6211\u4EEC\u8FD8\u4F7F\u7528\u4E86\u6A21\u578B\u5185\u7F6E\u7684\u635F\u5931, \u5F53\u6CA1\u6709\u635F\u5931\u88AB\u6307\u5B9A\u4E3A "),B=i("code"),W=a("compile()"),v=a(" \u53C2\u6570\u662F, \u8FD9\u662F\u9ED8\u8BA4\u503C, \u5E76\u4E14\u6211\u4EEC\u5C06\u8BAD\u7EC3\u7CBE\u5EA6\u8BBE\u7F6E\u4E3A "),R=i("code"),I=a('"mixed_float16"'),V=a("\u3002\u8BF7\u6CE8\u610F,\u5982\u679C\u4F60\u4F7F\u7528\u7684\u662FColab GPU\u6216\u5176\u4ED6\u4E0D\u652F\u6301float16\u52A0\u901F\u7684GPU, \u4F60\u53EF\u80FD\u5E94\u8BE5\u6CE8\u91CA\u6389\u8FD9\u4E00\u884C\u3002"),se=f(),Y=i("p"),ye=a("\u6B64\u5916, \u6211\u4EEC\u8FD8\u8BBE\u7F6E\u4E86\u4E00\u4E2A "),ee=i("code"),ie=a("PushToHubCallback"),G=a(", \u5B83\u5C06\u5728\u6BCF\u4E2Aepoch\u540E\u5C06\u6A21\u578B\u4FDD\u5B58\u5230Hub\u3002\u4F60\u53EF\u4EE5\u4F7F\u7528 "),fe=i("code"),U=a("hub_model_id"),Fe=a(" \u53C2\u6570\u6307\u5B9A\u4F60\u60F3\u8981\u63A8\u9001\u5230\u7684\u5B58\u50A8\u5E93\u7684\u540D\u79F0 (\u7279\u522B\u662F\u4F60\u5C06\u5FC5\u987B\u4F7F\u7528\u8BE5\u53C2\u6570\u6765\u63A8\u9001\u5230\u7EC4\u7EC7)\u3002\u4F8B\u5982, \u4E3A\u4E86\u5C06\u6A21\u578B\u63A8\u9001\u5230 "),le=i("a"),te=i("code"),Me=a("huggingface-course"),Q=a(" organization"),Ee=a(", \u6211\u4EEC\u6DFB\u52A0\u4E86 "),Te=i("code"),Ie=a('hub_model_id="huggingface-course/distilbert-finetuned-imdb"'),pe=a("\u3002\u9ED8\u8BA4\u60C5\u51B5\u4E0B, \u4F7F\u7528\u7684\u5B58\u50A8\u5E93\u5C06\u4F4D\u4E8E\u4F60\u7684\u547D\u540D\u7A7A\u95F4\u4E2D, \u5E76\u4EE5\u4F60\u8BBE\u7F6E\u7684\u8F93\u51FA\u76EE\u5F55\u547D\u540D, \u56E0\u6B64\u5728\u6211\u4EEC\u7684\u793A\u4F8B\u4E2D, \u5B83\u5C06\u662F "),ze=i("code"),xe=a('"lewtun/distilbert-finetuned-imdb"'),re=a("\u3002"),ue=f(),j(De.$$.fragment),ke=f(),me=i("p"),Ge=a("\u6211\u4EEC\u73B0\u5728\u5DF2\u7ECF\u51C6\u5907\u597D\u8FD0\u884C "),he=i("code"),$e=a("model.fit()"),ae=a(" \u4E86 \u2014 \u4F46\u5728\u6B64\u4E4B\u524D, \u8BA9\u6211\u4EEC\u5148\u7B80\u5355\u5730\u770B\u770B "),we=i("em"),ve=a("perplexity"),Ue=a(", \u5B83\u662F\u8BC4\u4F30\u8BED\u8A00\u6A21\u578B\u6027\u80FD\u7684\u5E38\u7528\u6307\u6807\u3002"),this.h()},l(C){o=p(C,"P",{});var J=_(o);h=l(J,"\u767B\u9646\u540E, \u6211\u4EEC\u5C31\u53EF\u4EE5\u521B\u5EFA\u6211\u4EEC\u7684 "),c=p(J,"CODE",{});var Oe=_(c);w=l(Oe,"tf.data"),Oe.forEach(t),D=l(J," \u6570\u636E\u96C6\u3002\u6211\u4EEC\u5C06\u5728\u8FD9\u91CC\u53EA\u4F7F\u7528\u6807\u51C6\u6570\u636E\u6574\u7406\u5668, \u4F46\u4F60\u4E5F\u53EF\u4EE5\u5C1D\u8BD5\u4F7F\u7528\u6574\u4E2A\u5355\u8BCD\u63A9\u7801\u6574\u7406\u5668\u5E76\u5C06\u7ED3\u679C\u4F5C\u4E3A\u7EC3\u4E60\u8FDB\u884C\u6BD4\u8F83:"),J.forEach(t),$=d(C),y(k.$$.fragment,C),M=d(C),u=p(C,"P",{});var _e=_(u);A=l(_e,"\u63A5\u4E0B\u6765, \u6211\u4EEC\u8BBE\u7F6E\u8BAD\u7EC3\u8D85\u53C2\u6570\u5E76\u7F16\u8BD1\u6A21\u578B\u3002\u6211\u4EEC\u4F7F\u7528 \u{1F917} Transformers \u5E93\u4E2D\u7684 "),P=p(_e,"CODE",{});var Ke=_(P);K=l(Ke,"create_optimizer()"),Ke.forEach(t),L=l(_e," \u51FD\u6570, \u5B83\u63D0\u4F9B\u4E86\u4E00\u4E2A\u5177\u6709\u7EBF\u6027\u5B66\u4E60\u7387\u8870\u51CF\u7684 "),N=p(_e,"CODE",{});var We=_(N);H=l(We,"AdamW"),We.forEach(t),F=l(_e," \u4F18\u5316\u5668\u3002\u6211\u4EEC\u8FD8\u4F7F\u7528\u4E86\u6A21\u578B\u5185\u7F6E\u7684\u635F\u5931, \u5F53\u6CA1\u6709\u635F\u5931\u88AB\u6307\u5B9A\u4E3A "),B=p(_e,"CODE",{});var ne=_(B);W=l(ne,"compile()"),ne.forEach(t),v=l(_e," \u53C2\u6570\u662F, \u8FD9\u662F\u9ED8\u8BA4\u503C, \u5E76\u4E14\u6211\u4EEC\u5C06\u8BAD\u7EC3\u7CBE\u5EA6\u8BBE\u7F6E\u4E3A "),R=p(_e,"CODE",{});var ge=_(R);I=l(ge,'"mixed_float16"'),ge.forEach(t),V=l(_e,"\u3002\u8BF7\u6CE8\u610F,\u5982\u679C\u4F60\u4F7F\u7528\u7684\u662FColab GPU\u6216\u5176\u4ED6\u4E0D\u652F\u6301float16\u52A0\u901F\u7684GPU, \u4F60\u53EF\u80FD\u5E94\u8BE5\u6CE8\u91CA\u6389\u8FD9\u4E00\u884C\u3002"),_e.forEach(t),se=d(C),Y=p(C,"P",{});var oe=_(Y);ye=l(oe,"\u6B64\u5916, \u6211\u4EEC\u8FD8\u8BBE\u7F6E\u4E86\u4E00\u4E2A "),ee=p(oe,"CODE",{});var qe=_(ee);ie=l(qe,"PushToHubCallback"),qe.forEach(t),G=l(oe,", \u5B83\u5C06\u5728\u6BCF\u4E2Aepoch\u540E\u5C06\u6A21\u578B\u4FDD\u5B58\u5230Hub\u3002\u4F60\u53EF\u4EE5\u4F7F\u7528 "),fe=p(oe,"CODE",{});var de=_(fe);U=l(de,"hub_model_id"),de.forEach(t),Fe=l(oe," \u53C2\u6570\u6307\u5B9A\u4F60\u60F3\u8981\u63A8\u9001\u5230\u7684\u5B58\u50A8\u5E93\u7684\u540D\u79F0 (\u7279\u522B\u662F\u4F60\u5C06\u5FC5\u987B\u4F7F\u7528\u8BE5\u53C2\u6570\u6765\u63A8\u9001\u5230\u7EC4\u7EC7)\u3002\u4F8B\u5982, \u4E3A\u4E86\u5C06\u6A21\u578B\u63A8\u9001\u5230 "),le=p(oe,"A",{href:!0,rel:!0});var Ae=_(le);te=p(Ae,"CODE",{});var Re=_(te);Me=l(Re,"huggingface-course"),Re.forEach(t),Q=l(Ae," organization"),Ae.forEach(t),Ee=l(oe,", \u6211\u4EEC\u6DFB\u52A0\u4E86 "),Te=p(oe,"CODE",{});var ls=_(Te);Ie=l(ls,'hub_model_id="huggingface-course/distilbert-finetuned-imdb"'),ls.forEach(t),pe=l(oe,"\u3002\u9ED8\u8BA4\u60C5\u51B5\u4E0B, \u4F7F\u7528\u7684\u5B58\u50A8\u5E93\u5C06\u4F4D\u4E8E\u4F60\u7684\u547D\u540D\u7A7A\u95F4\u4E2D, \u5E76\u4EE5\u4F60\u8BBE\u7F6E\u7684\u8F93\u51FA\u76EE\u5F55\u547D\u540D, \u56E0\u6B64\u5728\u6211\u4EEC\u7684\u793A\u4F8B\u4E2D, \u5B83\u5C06\u662F "),ze=p(oe,"CODE",{});var Ye=_(ze);xe=l(Ye,'"lewtun/distilbert-finetuned-imdb"'),Ye.forEach(t),re=l(oe,"\u3002"),oe.forEach(t),ue=d(C),y(De.$$.fragment,C),ke=d(C),me=p(C,"P",{});var z=_(me);Ge=l(z,"\u6211\u4EEC\u73B0\u5728\u5DF2\u7ECF\u51C6\u5907\u597D\u8FD0\u884C "),he=p(z,"CODE",{});var X=_(he);$e=l(X,"model.fit()"),X.forEach(t),ae=l(z," \u4E86 \u2014 \u4F46\u5728\u6B64\u4E4B\u524D, \u8BA9\u6211\u4EEC\u5148\u7B80\u5355\u5730\u770B\u770B "),we=p(z,"EM",{});var Ve=_(we);ve=l(Ve,"perplexity"),Ve.forEach(t),Ue=l(z,", \u5B83\u662F\u8BC4\u4F30\u8BED\u8A00\u6A21\u578B\u6027\u80FD\u7684\u5E38\u7528\u6307\u6807\u3002"),z.forEach(t),this.h()},h(){q(le,"href","https://huggingface.co/huggingface-course"),q(le,"rel","nofollow")},m(C,J){n(C,o,J),s(o,h),s(o,c),s(c,w),s(o,D),n(C,$,J),E(k,C,J),n(C,M,J),n(C,u,J),s(u,A),s(u,P),s(P,K),s(u,L),s(u,N),s(N,H),s(u,F),s(u,B),s(B,W),s(u,v),s(u,R),s(R,I),s(u,V),n(C,se,J),n(C,Y,J),s(Y,ye),s(Y,ee),s(ee,ie),s(Y,G),s(Y,fe),s(fe,U),s(Y,Fe),s(Y,le),s(le,te),s(te,Me),s(le,Q),s(Y,Ee),s(Y,Te),s(Te,Ie),s(Y,pe),s(Y,ze),s(ze,xe),s(Y,re),n(C,ue,J),E(De,C,J),n(C,ke,J),n(C,me,J),s(me,Ge),s(me,he),s(he,$e),s(me,ae),s(me,we),s(we,ve),s(me,Ue),je=!0},i(C){je||(g(k.$$.fragment,C),g(De.$$.fragment,C),je=!0)},o(C){b(k.$$.fragment,C),b(De.$$.fragment,C),je=!1},d(C){C&&t(o),C&&t($),x(k,C),C&&t(M),C&&t(u),C&&t(se),C&&t(Y),C&&t(ue),x(De,C),C&&t(ke),C&&t(me)}}}function Jm(O){let o,h,c,w,D,$,k,M;return k=new T({props:{code:`import math

eval_loss = model.evaluate(tf_eval_dataset)
print(f"Perplexity: {math.exp(eval_loss):.2f}")`,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>)`}}),{c(){o=i("p"),h=a("\u5047\u8BBE\u6211\u4EEC\u7684\u6D4B\u8BD5\u96C6\u4E3B\u8981\u7531\u8BED\u6CD5\u6B63\u786E\u7684\u53E5\u5B50\u7EC4\u6210, \u90A3\u4E48\u8861\u91CF\u6211\u4EEC\u7684\u8BED\u8A00\u6A21\u578B\u8D28\u91CF\u7684\u4E00\u79CD\u65B9\u6CD5\u662F\u8BA1\u7B97\u6D4B\u8BD5\u96C6\u6240\u6709\u53E5\u5B50\u4E2D\u5B83\u5206\u914D\u7ED9\u4E0B\u4E00\u4E2A\u5355\u8BCD\u7684\u6982\u7387\u3002\u9AD8\u6982\u7387\u8868\u660E, \u8BE5\u6A21\u578B\u8868\u660E\u8BE5\u6A21\u578B\u5BF9\u672A\u89C1\u8FC7\u7684\u793A\u4F8B\u4E0D\u611F\u5230 \u201C\u60CA\u8BB6\u201D \u6216 \u201C\u56F0\u60D1\u201D, \u5E76\u8868\u660E\u5B83\u5DF2\u7ECF\u5B66\u4F1A\u4E86\u8BE5\u8BED\u8A00\u7684\u57FA\u672C\u8BED\u6CD5\u6A21\u5F0F\u3002\u5173\u4E8Eperplexity\u5EA6\u6709\u5404\u79CD\u4E0D\u540C\u7684\u6570\u5B66\u5B9A\u4E49, \u4F46\u6211\u4EEC\u8981\u7528\u7684\u5B9A\u4E49\u662F\u4EA4\u53C9\u71B5\u635F\u5931\u7684\u6307\u6570\u3002\u56E0\u6B64, \u6211\u4EEC\u53EF\u4EE5\u901A\u8FC7 "),c=i("code"),w=a("model.evaluate()"),D=a(" \u65B9\u6CD5\u8BA1\u7B97\u6D4B\u8BD5\u96C6\u4E0A\u7684\u4EA4\u53C9\u71B5\u635F\u5931, \u7136\u540E\u53D6\u7ED3\u679C\u7684\u6307\u6570\u6765\u8BA1\u7B97\u6211\u4EEC\u9884\u8BAD\u7EC3\u6A21\u578B\u7684perplexity\u5EA6:"),$=f(),j(k.$$.fragment)},l(u){o=p(u,"P",{});var A=_(o);h=l(A,"\u5047\u8BBE\u6211\u4EEC\u7684\u6D4B\u8BD5\u96C6\u4E3B\u8981\u7531\u8BED\u6CD5\u6B63\u786E\u7684\u53E5\u5B50\u7EC4\u6210, \u90A3\u4E48\u8861\u91CF\u6211\u4EEC\u7684\u8BED\u8A00\u6A21\u578B\u8D28\u91CF\u7684\u4E00\u79CD\u65B9\u6CD5\u662F\u8BA1\u7B97\u6D4B\u8BD5\u96C6\u6240\u6709\u53E5\u5B50\u4E2D\u5B83\u5206\u914D\u7ED9\u4E0B\u4E00\u4E2A\u5355\u8BCD\u7684\u6982\u7387\u3002\u9AD8\u6982\u7387\u8868\u660E, \u8BE5\u6A21\u578B\u8868\u660E\u8BE5\u6A21\u578B\u5BF9\u672A\u89C1\u8FC7\u7684\u793A\u4F8B\u4E0D\u611F\u5230 \u201C\u60CA\u8BB6\u201D \u6216 \u201C\u56F0\u60D1\u201D, \u5E76\u8868\u660E\u5B83\u5DF2\u7ECF\u5B66\u4F1A\u4E86\u8BE5\u8BED\u8A00\u7684\u57FA\u672C\u8BED\u6CD5\u6A21\u5F0F\u3002\u5173\u4E8Eperplexity\u5EA6\u6709\u5404\u79CD\u4E0D\u540C\u7684\u6570\u5B66\u5B9A\u4E49, \u4F46\u6211\u4EEC\u8981\u7528\u7684\u5B9A\u4E49\u662F\u4EA4\u53C9\u71B5\u635F\u5931\u7684\u6307\u6570\u3002\u56E0\u6B64, \u6211\u4EEC\u53EF\u4EE5\u901A\u8FC7 "),c=p(A,"CODE",{});var P=_(c);w=l(P,"model.evaluate()"),P.forEach(t),D=l(A," \u65B9\u6CD5\u8BA1\u7B97\u6D4B\u8BD5\u96C6\u4E0A\u7684\u4EA4\u53C9\u71B5\u635F\u5931, \u7136\u540E\u53D6\u7ED3\u679C\u7684\u6307\u6570\u6765\u8BA1\u7B97\u6211\u4EEC\u9884\u8BAD\u7EC3\u6A21\u578B\u7684perplexity\u5EA6:"),A.forEach(t),$=d(u),y(k.$$.fragment,u)},m(u,A){n(u,o,A),s(o,h),s(o,c),s(c,w),s(o,D),n(u,$,A),E(k,u,A),M=!0},i(u){M||(g(k.$$.fragment,u),M=!0)},o(u){b(k.$$.fragment,u),M=!1},d(u){u&&t(o),u&&t($),x(k,u)}}}function Qm(O){let o,h,c,w,D,$,k,M;return k=new T({props:{code:`import math

eval_results = trainer.evaluate()
print(f">>> Perplexity: {math.exp(eval_results['eval_loss']):.2f}")`,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>)`}}),{c(){o=i("p"),h=a("\u5047\u8BBE\u6211\u4EEC\u7684\u6D4B\u8BD5\u96C6\u4E3B\u8981\u7531\u8BED\u6CD5\u6B63\u786E\u7684\u53E5\u5B50\u7EC4\u6210, \u90A3\u4E48\u8861\u91CF\u6211\u4EEC\u7684\u8BED\u8A00\u6A21\u578B\u8D28\u91CF\u7684\u4E00\u79CD\u65B9\u6CD5\u662F\u8BA1\u7B97\u5B83\u5206\u914D\u7ED9\u6D4B\u8BD5\u96C6\u4E2D\u6240\u6709\u53E5\u5B50\u4E2D\u7684\u4E0B\u4E00\u4E2A\u5355\u8BCD\u7684\u6982\u7387\u3002\u9AD8\u6982\u7387\u8868\u660E\u6A21\u578B\u5BF9\u770B\u4E0D\u89C1\u7684\u4F8B\u5B50\u5E76\u4E0D\u611F\u5230 \u201C\u60CA\u8BB6\u201D \u6216 \u201C\u7591\u60D1\u201D, \u5E76\u8868\u660E\u5B83\u5DF2\u7ECF\u5B66\u4E60\u4E86\u8BED\u8A00\u4E2D\u7684\u57FA\u672C\u8BED\u6CD5\u6A21\u5F0F\u3002 perplexity\u5EA6\u6709\u591A\u79CD\u6570\u5B66\u5B9A\u4E49, \u4F46\u6211\u4EEC\u5C06\u4F7F\u7528\u7684\u5B9A\u4E49\u662F\u4EA4\u53C9\u71B5\u635F\u5931\u7684\u6307\u6570\u3002\u56E0\u6B64, \u6211\u4EEC\u53EF\u4EE5\u901A\u8FC7 "),c=i("code"),w=a("Trainer.evaluate()"),D=a(" \u51FD\u6570\u8BA1\u7B97\u6D4B\u8BD5\u96C6\u4E0A\u7684\u4EA4\u53C9\u71B5\u635F\u5931, \u7136\u540E\u53D6\u7ED3\u679C\u7684\u6307\u6570\u6765\u8BA1\u7B97\u9884\u8BAD\u7EC3\u6A21\u578B\u7684perplexity\u5EA6:"),$=f(),j(k.$$.fragment)},l(u){o=p(u,"P",{});var A=_(o);h=l(A,"\u5047\u8BBE\u6211\u4EEC\u7684\u6D4B\u8BD5\u96C6\u4E3B\u8981\u7531\u8BED\u6CD5\u6B63\u786E\u7684\u53E5\u5B50\u7EC4\u6210, \u90A3\u4E48\u8861\u91CF\u6211\u4EEC\u7684\u8BED\u8A00\u6A21\u578B\u8D28\u91CF\u7684\u4E00\u79CD\u65B9\u6CD5\u662F\u8BA1\u7B97\u5B83\u5206\u914D\u7ED9\u6D4B\u8BD5\u96C6\u4E2D\u6240\u6709\u53E5\u5B50\u4E2D\u7684\u4E0B\u4E00\u4E2A\u5355\u8BCD\u7684\u6982\u7387\u3002\u9AD8\u6982\u7387\u8868\u660E\u6A21\u578B\u5BF9\u770B\u4E0D\u89C1\u7684\u4F8B\u5B50\u5E76\u4E0D\u611F\u5230 \u201C\u60CA\u8BB6\u201D \u6216 \u201C\u7591\u60D1\u201D, \u5E76\u8868\u660E\u5B83\u5DF2\u7ECF\u5B66\u4E60\u4E86\u8BED\u8A00\u4E2D\u7684\u57FA\u672C\u8BED\u6CD5\u6A21\u5F0F\u3002 perplexity\u5EA6\u6709\u591A\u79CD\u6570\u5B66\u5B9A\u4E49, \u4F46\u6211\u4EEC\u5C06\u4F7F\u7528\u7684\u5B9A\u4E49\u662F\u4EA4\u53C9\u71B5\u635F\u5931\u7684\u6307\u6570\u3002\u56E0\u6B64, \u6211\u4EEC\u53EF\u4EE5\u901A\u8FC7 "),c=p(A,"CODE",{});var P=_(c);w=l(P,"Trainer.evaluate()"),P.forEach(t),D=l(A," \u51FD\u6570\u8BA1\u7B97\u6D4B\u8BD5\u96C6\u4E0A\u7684\u4EA4\u53C9\u71B5\u635F\u5931, \u7136\u540E\u53D6\u7ED3\u679C\u7684\u6307\u6570\u6765\u8BA1\u7B97\u9884\u8BAD\u7EC3\u6A21\u578B\u7684perplexity\u5EA6:"),A.forEach(t),$=d(u),y(k.$$.fragment,u)},m(u,A){n(u,o,A),s(o,h),s(o,c),s(c,w),s(o,D),n(u,$,A),E(k,u,A),M=!0},i(u){M||(g(k.$$.fragment,u),M=!0)},o(u){b(k.$$.fragment,u),M=!1},d(u){u&&t(o),u&&t($),x(k,u)}}}function Xm(O){let o,h;return o=new T({props:{code:"model.fit(tf_train_dataset, validation_data=tf_eval_dataset, callbacks=[callback])",highlighted:"model.fit(tf_train_dataset, validation_data=tf_eval_dataset, callbacks=[callback])"}}),{c(){j(o.$$.fragment)},l(c){y(o.$$.fragment,c)},m(c,w){E(o,c,w),h=!0},i(c){h||(g(o.$$.fragment,c),h=!0)},o(c){b(o.$$.fragment,c),h=!1},d(c){x(o,c)}}}function Zm(O){let o,h;return o=new T({props:{code:"trainer.train()",highlighted:"trainer.train()"}}),{c(){j(o.$$.fragment)},l(c){y(o.$$.fragment,c)},m(c,w){E(o,c,w),h=!0},i(c){h||(g(o.$$.fragment,c),h=!0)},o(c){b(o.$$.fragment,c),h=!1},d(c){x(o,c)}}}function ef(O){let o,h;return o=new T({props:{code:`eval_loss = model.evaluate(tf_eval_dataset)
print(f"Perplexity: {math.exp(eval_loss):.2f}")`,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>)`}}),{c(){j(o.$$.fragment)},l(c){y(o.$$.fragment,c)},m(c,w){E(o,c,w),h=!0},i(c){h||(g(o.$$.fragment,c),h=!0)},o(c){b(o.$$.fragment,c),h=!1},d(c){x(o,c)}}}function sf(O){let o,h;return o=new T({props:{code:`eval_results = trainer.evaluate()
print(f">>> Perplexity: {math.exp(eval_results['eval_loss']):.2f}")`,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>)`}}),{c(){j(o.$$.fragment)},l(c){y(o.$$.fragment,c)},m(c,w){E(o,c,w),h=!0},i(c){h||(g(o.$$.fragment,c),h=!0)},o(c){b(o.$$.fragment,c),h=!1},d(c){x(o,c)}}}function Em(O){let o,h,c,w,D;return w=new T({props:{code:"trainer.push_to_hub()",highlighted:"trainer.push_to_hub()"}}),{c(){o=i("p"),h=a("\u8BAD\u7EC3\u5B8C\u6210\u540E, \u6211\u4EEC\u53EF\u4EE5\u5C06\u5E26\u6709\u8BAD\u7EC3\u4FE1\u606F\u7684\u6A21\u578B\u5361\u63A8\u9001\u5230 Hub (\u68C0\u67E5\u70B9\u5728\u8BAD\u7EC3\u8FC7\u7A0B\u4E2D\u81EA\u884C\u4FDD\u5B58):"),c=f(),j(w.$$.fragment)},l($){o=p($,"P",{});var k=_(o);h=l(k,"\u8BAD\u7EC3\u5B8C\u6210\u540E, \u6211\u4EEC\u53EF\u4EE5\u5C06\u5E26\u6709\u8BAD\u7EC3\u4FE1\u606F\u7684\u6A21\u578B\u5361\u63A8\u9001\u5230 Hub (\u68C0\u67E5\u70B9\u5728\u8BAD\u7EC3\u8FC7\u7A0B\u4E2D\u81EA\u884C\u4FDD\u5B58):"),k.forEach(t),c=d($),y(w.$$.fragment,$)},m($,k){n($,o,k),s(o,h),n($,c,k),E(w,$,k),D=!0},i($){D||(g(w.$$.fragment,$),D=!0)},o($){b(w.$$.fragment,$),D=!1},d($){$&&t(o),$&&t(c),x(w,$)}}}function tf(O){let o,h,c,w,D;return{c(){o=i("p"),h=a("\u270F\uFE0F "),c=i("strong"),w=a("\u8F6E\u5230\u4F60\u4E86!"),D=a(" \u5C06\u6570\u636E\u6574\u7406\u5668\u6539\u4E3A\u5168\u5B57\u5C4F\u853D\u6574\u7406\u5668\u540E\u8FD0\u884C\u4E0A\u9762\u7684\u8BAD\u7EC3\u3002\u4F60\u6709\u5F97\u5230\u66F4\u597D\u7684\u7ED3\u679C\u5417?")},l($){o=p($,"P",{});var k=_(o);h=l(k,"\u270F\uFE0F "),c=p(k,"STRONG",{});var M=_(c);w=l(M,"\u8F6E\u5230\u4F60\u4E86!"),M.forEach(t),D=l(k," \u5C06\u6570\u636E\u6574\u7406\u5668\u6539\u4E3A\u5168\u5B57\u5C4F\u853D\u6574\u7406\u5668\u540E\u8FD0\u884C\u4E0A\u9762\u7684\u8BAD\u7EC3\u3002\u4F60\u6709\u5F97\u5230\u66F4\u597D\u7684\u7ED3\u679C\u5417?"),k.forEach(t)},m($,k){n($,o,k),s(o,h),s(o,c),s(c,w),s(o,D)},d($){$&&t(o)}}}function xm(O){let o,h,c,w,D,$,k,M,u,A,P,K,L,N,H,F,B,W,v,R,I,V,se,Y,ye,ee,ie,G,fe,U,Fe,le,te,Me,Q,Ee,Te,Ie,pe,ze,xe,re,ue,De,ke,me,Ge,he,$e,ae,we,ve,Ue,je,C,J,Oe,_e,Ke,We,ne,ge,oe,qe,de,Ae,Re,ls,Ye,z,X,Ve,be,ss,Je,ys,ps,Es,Ce,Z,rs,Le,xs,Qe,ns,_s,ce,Bs,cs,Be,Ds,Ne,Ot,mt,ts,ft,qs,Hs,Fs,Kt,rt;return k=new E_({}),te=new T({props:{code:`def insert_random_mask(batch):
    features = [dict(zip(batch, t)) for t in zip(*batch.values())]
    masked_inputs = data_collator(features)
    # Create a new "masked" column for each column in the dataset
    return {"masked_" + k: v.numpy() for k, v in masked_inputs.items()}`,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()}`}}),xe=new T({props:{code:`downsampled_dataset = downsampled_dataset.remove_columns(["word_ids"])
eval_dataset = downsampled_dataset["test"].map(
    insert_random_mask,
    batched=True,
    remove_columns=downsampled_dataset["test"].column_names,
)
eval_dataset = eval_dataset.rename_columns(
    {
        "masked_input_ids": "input_ids",
        "masked_attention_mask": "attention_mask",
        "masked_labels": "labels",
    }
)`,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>,
    }
)`}}),$e=new T({props:{code:`from torch.utils.data import DataLoader
from transformers import default_data_collator

batch_size = 64
train_dataloader = DataLoader(
    downsampled_dataset["train"],
    shuffle=True,
    batch_size=batch_size,
    collate_fn=data_collator,
)
eval_dataloader = DataLoader(
    eval_dataset, batch_size=batch_size, collate_fn=default_data_collator
)`,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
)`}}),je=new T({props:{code:"model = AutoModelForMaskedLM.from_pretrained(model_checkpoint)",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>'}}),ge=new T({props:{code:`from torch.optim import AdamW

optimizer = AdamW(model.parameters(), lr=5e-5)`,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>)`}}),z=new T({props:{code:`from accelerate import Accelerator

accelerator = Accelerator()
model, optimizer, train_dataloader, eval_dataloader = accelerator.prepare(
    model, optimizer, train_dataloader, eval_dataloader
)`,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
)`}}),Je=new T({props:{code:`from transformers import get_scheduler

num_train_epochs = 3
num_update_steps_per_epoch = len(train_dataloader)
num_training_steps = num_train_epochs * num_update_steps_per_epoch

lr_scheduler = get_scheduler(
    "linear",
    optimizer=optimizer,
    num_warmup_steps=0,
    num_training_steps=num_training_steps,
)`,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,
)`}}),Z=new T({props:{code:`from huggingface_hub import get_full_repo_name

model_name = "distilbert-base-uncased-finetuned-imdb-accelerate"
repo_name = get_full_repo_name(model_name)
repo_name`,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`}}),Le=new T({props:{code:"'lewtun/distilbert-base-uncased-finetuned-imdb-accelerate'",highlighted:'<span class="hljs-string">&#x27;lewtun/distilbert-base-uncased-finetuned-imdb-accelerate&#x27;</span>'}}),Be=new T({props:{code:`from huggingface_hub import Repository

output_dir = model_name
repo = Repository(output_dir, clone_from=repo_name)`,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)`}}),ts=new T({props:{code:`from tqdm.auto import tqdm
import torch
import math

progress_bar = tqdm(range(num_training_steps))

for epoch in range(num_train_epochs):
    # Training
    model.train()
    for batch in train_dataloader:
        outputs = model(**batch)
        loss = outputs.loss
        accelerator.backward(loss)

        optimizer.step()
        lr_scheduler.step()
        optimizer.zero_grad()
        progress_bar.update(1)

    # Evaluation
    model.eval()
    losses = []
    for step, batch in enumerate(eval_dataloader):
        with torch.no_grad():
            outputs = model(**batch)

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

    losses = torch.cat(losses)
    losses = losses[: len(eval_dataset)]
    try:
        perplexity = math.exp(torch.mean(losses))
    except OverflowError:
        perplexity = float("inf")

    print(f">>> Epoch {epoch}: Perplexity: {perplexity}")

    # Save and upload
    accelerator.wait_for_everyone()
    unwrapped_model = accelerator.unwrap_model(model)
    unwrapped_model.save_pretrained(output_dir, save_function=accelerator.save)
    if accelerator.is_main_process:
        tokenizer.save_pretrained(output_dir)
        repo.push_to_hub(
            commit_message=f"Training in progress epoch {epoch}", blocking=False
        )`,highlighted:`<span class="hljs-keyword">from</span> tqdm.auto <span class="hljs-keyword">import</span> tqdm
<span class="hljs-keyword">import</span> torch
<span class="hljs-keyword">import</span> 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>
        )`}}),qs=new T({props:{code:`Epoch 0: Perplexity: 11.397545307900472
Epoch 1: Perplexity: 10.904909330983092
Epoch 2: Perplexity: 10.729503505340409`,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>`}}),{c(){o=i("p"),h=a("\u5728\u6211\u4EEC\u7684\u7528\u4F8B\u4E2D, \u6211\u4EEC\u4E0D\u9700\u8981\u5BF9\u8BAD\u7EC3\u5FAA\u73AF\u505A\u4EFB\u4F55\u7279\u522B\u7684\u4E8B\u60C5, \u4F46\u5728\u67D0\u4E9B\u60C5\u51B5\u4E0B, \u4F60\u53EF\u80FD\u9700\u8981\u5B9E\u73B0\u4E00\u4E9B\u81EA\u5B9A\u4E49\u903B\u8F91\u3002\u5BF9\u4E8E\u8FD9\u4E9B\u5E94\u7528, \u4F60\u53EF\u4EE5\u4F7F\u7528 \u{1F917} Accelerate \u2014 \u8BA9\u6211\u4EEC\u6765\u770B\u770B\u5427!"),c=f(),w=i("h2"),D=i("a"),$=i("span"),j(k.$$.fragment),M=f(),u=i("span"),A=a("\u4F7F\u7528 \u{1F917} Accelerate \u5FAE\u8C03 DistilBERT"),P=f(),K=i("p"),L=a("\u6B63\u5982\u6211\u4EEC\u5728 "),N=i("code"),H=a("Trainer"),F=a(" \u4E2D\u770B\u5230\u7684, \u5BF9\u63A9\u7801\u8BED\u8A00\u6A21\u578B\u7684\u5FAE\u8C03\u4E0E "),B=i("a"),W=a("\u7B2C\u4E09\u7AE0"),v=a(" \u4E2D\u7684\u6587\u672C\u5206\u7C7B\u793A\u4F8B\u975E\u5E38\u76F8\u4F3C\u3002\u4E8B\u5B9E\u4E0A, \u552F\u4E00\u7684\u5FAE\u5999\u4E4B\u5904\u662F\u4F7F\u7528\u7279\u6B8A\u7684\u6570\u636E\u6574\u7406\u5668, \u6211\u4EEC\u5DF2\u7ECF\u5728\u672C\u8282\u7684\u524D\u9762\u4ECB\u7ECD\u8FC7\u4E86!"),R=f(),I=i("p"),V=a("\u7136\u800C, \u6211\u4EEC\u770B\u5230 "),se=i("code"),Y=a("DataCollatorForLanguageModeling"),ye=a(" \u8FD8\u5BF9\u6BCF\u6B21\u8BC4\u4F30\u5E94\u7528\u968F\u673A\u63A9\u7801, \u56E0\u6B64\u6BCF\u6B21\u8BAD\u7EC3\u8FD0\u884C\u65F6, \u6211\u4EEC\u90FD\u4F1A\u770B\u5230perplexity\u5EA6\u5206\u6570\u7684\u4E00\u4E9B\u6CE2\u52A8\u3002\u6D88\u9664\u8FD9\u79CD\u968F\u673A\u6027\u6765\u6E90\u7684\u4E00\u79CD\u65B9\u6CD5\u662F\u5E94\u7528\u63A9\u7801 "),ee=i("em"),ie=a("\u4E00\u6B21"),G=a(" \u5728\u6574\u4E2A\u6D4B\u8BD5\u96C6\u4E0A, \u7136\u540E\u4F7F\u7528\u{1F917} Transformers \u4E2D\u7684\u9ED8\u8BA4\u6570\u636E\u6574\u7406\u5668\u5728\u8BC4\u4F30\u671F\u95F4\u6536\u96C6\u6279\u6B21\u3002\u4E3A\u4E86\u770B\u770B\u5B83\u662F\u5982\u4F55\u5DE5\u4F5C\u7684, \u8BA9\u6211\u4EEC\u5B9E\u73B0\u4E00\u4E2A\u7B80\u5355\u7684\u51FD\u6570, \u5C06\u63A9\u7801\u5E94\u7528\u4E8E\u6279\u5904\u7406, \u7C7B\u4F3C\u4E8E\u6211\u4EEC\u7B2C\u4E00\u6B21\u9047\u5230\u7684 "),fe=i("code"),U=a("DataCollatorForLanguageModeling"),Fe=a(":"),le=f(),j(te.$$.fragment),Me=f(),Q=i("p"),Ee=a("\u63A5\u4E0B\u6765, \u6211\u4EEC\u5C06\u6B64\u51FD\u6570\u5E94\u7528\u4E8E\u6211\u4EEC\u7684\u6D4B\u8BD5\u96C6\u5E76\u5220\u9664\u672A\u63A9\u7801\u7684\u5217, \u4EE5\u4FBF\u6211\u4EEC\u53EF\u4EE5\u7528\u63A9\u7801\u7684\u5217\u66FF\u6362\u5B83\u4EEC\u3002\u4F60\u53EF\u4EE5\u901A\u8FC7\u7528\u9002\u5F53\u7684\u66FF\u6362\u4E0A\u9762\u7684 "),Te=i("code"),Ie=a("data_collator"),pe=a(" \u6765\u4F7F\u6574\u4E2A\u5355\u8BCD\u63A9\u7801, \u5728\u8FD9\u79CD\u60C5\u51B5\u4E0B, \u4F60\u5E94\u8BE5\u5220\u9664\u6B64\u5904\u7684\u7B2C\u4E00\u884C:"),ze=f(),j(xe.$$.fragment),re=f(),ue=i("p"),De=a("\u7136\u540E\u6211\u4EEC\u53EF\u4EE5\u50CF\u5F80\u5E38\u4E00\u6837\u8BBE\u7F6E\u6570\u636E\u52A0\u8F7D\u5668, \u4F46\u6211\u4EEC\u5C06\u4F7F\u7528\u{1F917} Transformers \u4E2D\u7684 "),ke=i("code"),me=a("default_data_collator"),Ge=a(" \u4F5C\u4E3A\u8BC4\u4F30\u96C6:"),he=f(),j($e.$$.fragment),ae=f(),we=i("p"),ve=a("\u4ECE\u8FD9\u91CC\u5F00\u59CB, \u6211\u4EEC\u9075\u5FAA\u{1F917} Accelerate \u7684\u6807\u51C6\u6B65\u9AA4\u3002\u7B2C\u4E00\u4E2A\u4EFB\u52A1\u662F\u52A0\u8F7D\u9884\u8BAD\u7EC3\u6A21\u578B\u7684\u65B0\u7248\u672C:"),Ue=f(),j(je.$$.fragment),C=f(),J=i("p"),Oe=a("\u7136\u540E\u6211\u4EEC\u9700\u8981\u6307\u5B9A\u4F18\u5316\u5668; \u6211\u4EEC\u5C06\u4F7F\u7528\u6807\u51C6\u7684 "),_e=i("code"),Ke=a("AdamW"),We=a(":"),ne=f(),j(ge.$$.fragment),oe=f(),qe=i("p"),de=a("\u6709\u4E86\u8FD9\u4E9B\u5BF9\u8C61, \u6211\u4EEC\u73B0\u5728\u53EF\u4EE5\u51C6\u5907\u4F7F\u7528 "),Ae=i("code"),Re=a("Accelerator"),ls=a(" \u52A0\u901F\u5668\u8FDB\u884C\u8BAD\u7EC3\u7684\u4E00\u5207:"),Ye=f(),j(z.$$.fragment),X=f(),Ve=i("p"),be=a("\u73B0\u5728\u6211\u4EEC\u7684\u6A21\u578B\u3001\u4F18\u5316\u5668\u548C\u6570\u636E\u52A0\u8F7D\u5668\u90FD\u914D\u7F6E\u597D\u4E86, \u6211\u4EEC\u53EF\u4EE5\u6307\u5B9A\u5B66\u4E60\u7387\u8C03\u5EA6\u5668\u5982\u4E0B:"),ss=f(),j(Je.$$.fragment),ys=f(),ps=i("p"),Es=a("\u5728\u8BAD\u7EC3\u4E4B\u524D\u8981\u505A\u7684\u6700\u540E\u4E00\u4EF6\u4E8B\u662F: \u5728 Hugging Face Hub \u4E0A\u521B\u5EFA\u4E00\u4E2A\u6A21\u578B\u5E93! \u6211\u4EEC\u53EF\u4EE5\u4F7F\u7528 \u{1F917} Hub \u5E93\u6765\u9996\u5148\u751F\u6210\u6211\u4EEC\u7684 repo \u7684\u5168\u540D:"),Ce=f(),j(Z.$$.fragment),rs=f(),j(Le.$$.fragment),xs=f(),Qe=i("p"),ns=a("\u7136\u540E\u4F7F\u7528\u6765\u81EA\u{1F917} Hub \u7684 "),_s=i("code"),ce=a("Repository"),Bs=a(" \u7C7B:"),cs=f(),j(Be.$$.fragment),Ds=f(),Ne=i("p"),Ot=a("\u5B8C\u6210\u540E, \u53EA\u9700\u5199\u51FA\u5B8C\u6574\u7684\u8BAD\u7EC3\u548C\u8BC4\u4F30\u5FAA\u73AF\u5373\u53EF:"),mt=f(),j(ts.$$.fragment),ft=f(),j(qs.$$.fragment),Hs=f(),Fs=i("p"),Kt=a("\u5F88\u68D2, \u6211\u4EEC\u5DF2\u7ECF\u80FD\u591F\u8BC4\u4F30\u6BCF\u4E2A epoch \u7684perplexity\u5EA6, \u5E76\u786E\u4FDD\u591A\u6B21\u8BAD\u7EC3\u8FD0\u884C\u662F\u53EF\u91CD\u590D\u7684!"),this.h()},l(m){o=p(m,"P",{});var S=_(o);h=l(S,"\u5728\u6211\u4EEC\u7684\u7528\u4F8B\u4E2D, \u6211\u4EEC\u4E0D\u9700\u8981\u5BF9\u8BAD\u7EC3\u5FAA\u73AF\u505A\u4EFB\u4F55\u7279\u522B\u7684\u4E8B\u60C5, \u4F46\u5728\u67D0\u4E9B\u60C5\u51B5\u4E0B, \u4F60\u53EF\u80FD\u9700\u8981\u5B9E\u73B0\u4E00\u4E9B\u81EA\u5B9A\u4E49\u903B\u8F91\u3002\u5BF9\u4E8E\u8FD9\u4E9B\u5E94\u7528, \u4F60\u53EF\u4EE5\u4F7F\u7528 \u{1F917} Accelerate \u2014 \u8BA9\u6211\u4EEC\u6765\u770B\u770B\u5427!"),S.forEach(t),c=d(m),w=p(m,"H2",{class:!0});var Ms=_(w);D=p(Ms,"A",{id:!0,class:!0,href:!0});var Ha=_(D);$=p(Ha,"SPAN",{});var Rt=_($);y(k.$$.fragment,Rt),Rt.forEach(t),Ha.forEach(t),M=d(Ms),u=p(Ms,"SPAN",{});var os=_(u);A=l(os,"\u4F7F\u7528 \u{1F917} Accelerate \u5FAE\u8C03 DistilBERT"),os.forEach(t),Ms.forEach(t),P=d(m),K=p(m,"P",{});var He=_(K);L=l(He,"\u6B63\u5982\u6211\u4EEC\u5728 "),N=p(He,"CODE",{});var nt=_(N);H=l(nt,"Trainer"),nt.forEach(t),F=l(He," \u4E2D\u770B\u5230\u7684, \u5BF9\u63A9\u7801\u8BED\u8A00\u6A21\u578B\u7684\u5FAE\u8C03\u4E0E "),B=p(He,"A",{href:!0});var Ns=_(B);W=l(Ns,"\u7B2C\u4E09\u7AE0"),Ns.forEach(t),v=l(He," \u4E2D\u7684\u6587\u672C\u5206\u7C7B\u793A\u4F8B\u975E\u5E38\u76F8\u4F3C\u3002\u4E8B\u5B9E\u4E0A, \u552F\u4E00\u7684\u5FAE\u5999\u4E4B\u5904\u662F\u4F7F\u7528\u7279\u6B8A\u7684\u6570\u636E\u6574\u7406\u5668, \u6211\u4EEC\u5DF2\u7ECF\u5728\u672C\u8282\u7684\u524D\u9762\u4ECB\u7ECD\u8FC7\u4E86!"),He.forEach(t),R=d(m),I=p(m,"P",{});var ms=_(I);V=l(ms,"\u7136\u800C, \u6211\u4EEC\u770B\u5230 "),se=p(ms,"CODE",{});var ot=_(se);Y=l(ot,"DataCollatorForLanguageModeling"),ot.forEach(t),ye=l(ms," \u8FD8\u5BF9\u6BCF\u6B21\u8BC4\u4F30\u5E94\u7528\u968F\u673A\u63A9\u7801, \u56E0\u6B64\u6BCF\u6B21\u8BAD\u7EC3\u8FD0\u884C\u65F6, \u6211\u4EEC\u90FD\u4F1A\u770B\u5230perplexity\u5EA6\u5206\u6570\u7684\u4E00\u4E9B\u6CE2\u52A8\u3002\u6D88\u9664\u8FD9\u79CD\u968F\u673A\u6027\u6765\u6E90\u7684\u4E00\u79CD\u65B9\u6CD5\u662F\u5E94\u7528\u63A9\u7801 "),ee=p(ms,"EM",{});var Fa=_(ee);ie=l(Fa,"\u4E00\u6B21"),Fa.forEach(t),G=l(ms," \u5728\u6574\u4E2A\u6D4B\u8BD5\u96C6\u4E0A, \u7136\u540E\u4F7F\u7528\u{1F917} Transformers \u4E2D\u7684\u9ED8\u8BA4\u6570\u636E\u6574\u7406\u5668\u5728\u8BC4\u4F30\u671F\u95F4\u6536\u96C6\u6279\u6B21\u3002\u4E3A\u4E86\u770B\u770B\u5B83\u662F\u5982\u4F55\u5DE5\u4F5C\u7684, \u8BA9\u6211\u4EEC\u5B9E\u73B0\u4E00\u4E2A\u7B80\u5355\u7684\u51FD\u6570, \u5C06\u63A9\u7801\u5E94\u7528\u4E8E\u6279\u5904\u7406, \u7C7B\u4F3C\u4E8E\u6211\u4EEC\u7B2C\u4E00\u6B21\u9047\u5230\u7684 "),fe=p(ms,"CODE",{});var Lt=_(fe);U=l(Lt,"DataCollatorForLanguageModeling"),Lt.forEach(t),Fe=l(ms,":"),ms.forEach(t),le=d(m),y(te.$$.fragment,m),Me=d(m),Q=p(m,"P",{});var ds=_(Q);Ee=l(ds,"\u63A5\u4E0B\u6765, \u6211\u4EEC\u5C06\u6B64\u51FD\u6570\u5E94\u7528\u4E8E\u6211\u4EEC\u7684\u6D4B\u8BD5\u96C6\u5E76\u5220\u9664\u672A\u63A9\u7801\u7684\u5217, \u4EE5\u4FBF\u6211\u4EEC\u53EF\u4EE5\u7528\u63A9\u7801\u7684\u5217\u66FF\u6362\u5B83\u4EEC\u3002\u4F60\u53EF\u4EE5\u901A\u8FC7\u7528\u9002\u5F53\u7684\u66FF\u6362\u4E0A\u9762\u7684 "),Te=p(ds,"CODE",{});var Na=_(Te);Ie=l(Na,"data_collator"),Na.forEach(t),pe=l(ds," \u6765\u4F7F\u6574\u4E2A\u5355\u8BCD\u63A9\u7801, \u5728\u8FD9\u79CD\u60C5\u51B5\u4E0B, \u4F60\u5E94\u8BE5\u5220\u9664\u6B64\u5904\u7684\u7B2C\u4E00\u884C:"),ds.forEach(t),ze=d(m),y(xe.$$.fragment,m),re=d(m),ue=p(m,"P",{});var it=_(ue);De=l(it,"\u7136\u540E\u6211\u4EEC\u53EF\u4EE5\u50CF\u5F80\u5E38\u4E00\u6837\u8BBE\u7F6E\u6570\u636E\u52A0\u8F7D\u5668, \u4F46\u6211\u4EEC\u5C06\u4F7F\u7528\u{1F917} Transformers \u4E2D\u7684 "),ke=p(it,"CODE",{});var fs=_(ke);me=l(fs,"default_data_collator"),fs.forEach(t),Ge=l(it," \u4F5C\u4E3A\u8BC4\u4F30\u96C6:"),it.forEach(t),he=d(m),y($e.$$.fragment,m),ae=d(m),we=p(m,"P",{});var Ia=_(we);ve=l(Ia,"\u4ECE\u8FD9\u91CC\u5F00\u59CB, \u6211\u4EEC\u9075\u5FAA\u{1F917} Accelerate \u7684\u6807\u51C6\u6B65\u9AA4\u3002\u7B2C\u4E00\u4E2A\u4EFB\u52A1\u662F\u52A0\u8F7D\u9884\u8BAD\u7EC3\u6A21\u578B\u7684\u65B0\u7248\u672C:"),Ia.forEach(t),Ue=d(m),y(je.$$.fragment,m),C=d(m),J=p(m,"P",{});var us=_(J);Oe=l(us,"\u7136\u540E\u6211\u4EEC\u9700\u8981\u6307\u5B9A\u4F18\u5316\u5668; \u6211\u4EEC\u5C06\u4F7F\u7528\u6807\u51C6\u7684 "),_e=p(us,"CODE",{});var Ga=_(_e);Ke=l(Ga,"AdamW"),Ga.forEach(t),We=l(us,":"),us.forEach(t),ne=d(m),y(ge.$$.fragment,m),oe=d(m),qe=p(m,"P",{});var dt=_(qe);de=l(dt,"\u6709\u4E86\u8FD9\u4E9B\u5BF9\u8C61, \u6211\u4EEC\u73B0\u5728\u53EF\u4EE5\u51C6\u5907\u4F7F\u7528 "),Ae=p(dt,"CODE",{});var ut=_(Ae);Re=l(ut,"Accelerator"),ut.forEach(t),ls=l(dt," \u52A0\u901F\u5668\u8FDB\u884C\u8BAD\u7EC3\u7684\u4E00\u5207:"),dt.forEach(t),Ye=d(m),y(z.$$.fragment,m),X=d(m),Ve=p(m,"P",{});var Ua=_(Ve);be=l(Ua,"\u73B0\u5728\u6211\u4EEC\u7684\u6A21\u578B\u3001\u4F18\u5316\u5668\u548C\u6570\u636E\u52A0\u8F7D\u5668\u90FD\u914D\u7F6E\u597D\u4E86, \u6211\u4EEC\u53EF\u4EE5\u6307\u5B9A\u5B66\u4E60\u7387\u8C03\u5EA6\u5668\u5982\u4E0B:"),Ua.forEach(t),ss=d(m),y(Je.$$.fragment,m),ys=d(m),ps=p(m,"P",{});var Wa=_(ps);Es=l(Wa,"\u5728\u8BAD\u7EC3\u4E4B\u524D\u8981\u505A\u7684\u6700\u540E\u4E00\u4EF6\u4E8B\u662F: \u5728 Hugging Face Hub \u4E0A\u521B\u5EFA\u4E00\u4E2A\u6A21\u578B\u5E93! \u6211\u4EEC\u53EF\u4EE5\u4F7F\u7528 \u{1F917} Hub \u5E93\u6765\u9996\u5148\u751F\u6210\u6211\u4EEC\u7684 repo \u7684\u5168\u540D:"),Wa.forEach(t),Ce=d(m),y(Z.$$.fragment,m),rs=d(m),y(Le.$$.fragment,m),xs=d(m),Qe=p(m,"P",{});var pt=_(Qe);ns=l(pt,"\u7136\u540E\u4F7F\u7528\u6765\u81EA\u{1F917} Hub \u7684 "),_s=p(pt,"CODE",{});var Is=_(_s);ce=l(Is,"Repository"),Is.forEach(t),Bs=l(pt," \u7C7B:"),pt.forEach(t),cs=d(m),y(Be.$$.fragment,m),Ds=d(m),Ne=p(m,"P",{});var Bt=_(Ne);Ot=l(Bt,"\u5B8C\u6210\u540E, \u53EA\u9700\u5199\u51FA\u5B8C\u6574\u7684\u8BAD\u7EC3\u548C\u8BC4\u4F30\u5FAA\u73AF\u5373\u53EF:"),Bt.forEach(t),mt=d(m),y(ts.$$.fragment,m),ft=d(m),y(qs.$$.fragment,m),Hs=d(m),Fs=p(m,"P",{});var Gs=_(Fs);Kt=l(Gs,"\u5F88\u68D2, \u6211\u4EEC\u5DF2\u7ECF\u80FD\u591F\u8BC4\u4F30\u6BCF\u4E2A epoch \u7684perplexity\u5EA6, \u5E76\u786E\u4FDD\u591A\u6B21\u8BAD\u7EC3\u8FD0\u884C\u662F\u53EF\u91CD\u590D\u7684!"),Gs.forEach(t),this.h()},h(){q(D,"id","accelerate-distilbert"),q(D,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),q(D,"href","#accelerate-distilbert"),q(w,"class","relative group"),q(B,"href","/course/chapter3")},m(m,S){n(m,o,S),s(o,h),n(m,c,S),n(m,w,S),s(w,D),s(D,$),E(k,$,null),s(w,M),s(w,u),s(u,A),n(m,P,S),n(m,K,S),s(K,L),s(K,N),s(N,H),s(K,F),s(K,B),s(B,W),s(K,v),n(m,R,S),n(m,I,S),s(I,V),s(I,se),s(se,Y),s(I,ye),s(I,ee),s(ee,ie),s(I,G),s(I,fe),s(fe,U),s(I,Fe),n(m,le,S),E(te,m,S),n(m,Me,S),n(m,Q,S),s(Q,Ee),s(Q,Te),s(Te,Ie),s(Q,pe),n(m,ze,S),E(xe,m,S),n(m,re,S),n(m,ue,S),s(ue,De),s(ue,ke),s(ke,me),s(ue,Ge),n(m,he,S),E($e,m,S),n(m,ae,S),n(m,we,S),s(we,ve),n(m,Ue,S),E(je,m,S),n(m,C,S),n(m,J,S),s(J,Oe),s(J,_e),s(_e,Ke),s(J,We),n(m,ne,S),E(ge,m,S),n(m,oe,S),n(m,qe,S),s(qe,de),s(qe,Ae),s(Ae,Re),s(qe,ls),n(m,Ye,S),E(z,m,S),n(m,X,S),n(m,Ve,S),s(Ve,be),n(m,ss,S),E(Je,m,S),n(m,ys,S),n(m,ps,S),s(ps,Es),n(m,Ce,S),E(Z,m,S),n(m,rs,S),E(Le,m,S),n(m,xs,S),n(m,Qe,S),s(Qe,ns),s(Qe,_s),s(_s,ce),s(Qe,Bs),n(m,cs,S),E(Be,m,S),n(m,Ds,S),n(m,Ne,S),s(Ne,Ot),n(m,mt,S),E(ts,m,S),n(m,ft,S),E(qs,m,S),n(m,Hs,S),n(m,Fs,S),s(Fs,Kt),rt=!0},i(m){rt||(g(k.$$.fragment,m),g(te.$$.fragment,m),g(xe.$$.fragment,m),g($e.$$.fragment,m),g(je.$$.fragment,m),g(ge.$$.fragment,m),g(z.$$.fragment,m),g(Je.$$.fragment,m),g(Z.$$.fragment,m),g(Le.$$.fragment,m),g(Be.$$.fragment,m),g(ts.$$.fragment,m),g(qs.$$.fragment,m),rt=!0)},o(m){b(k.$$.fragment,m),b(te.$$.fragment,m),b(xe.$$.fragment,m),b($e.$$.fragment,m),b(je.$$.fragment,m),b(ge.$$.fragment,m),b(z.$$.fragment,m),b(Je.$$.fragment,m),b(Z.$$.fragment,m),b(Le.$$.fragment,m),b(Be.$$.fragment,m),b(ts.$$.fragment,m),b(qs.$$.fragment,m),rt=!1},d(m){m&&t(o),m&&t(c),m&&t(w),x(k),m&&t(P),m&&t(K),m&&t(R),m&&t(I),m&&t(le),x(te,m),m&&t(Me),m&&t(Q),m&&t(ze),x(xe,m),m&&t(re),m&&t(ue),m&&t(he),x($e,m),m&&t(ae),m&&t(we),m&&t(Ue),x(je,m),m&&t(C),m&&t(J),m&&t(ne),x(ge,m),m&&t(oe),m&&t(qe),m&&t(Ye),x(z,m),m&&t(X),m&&t(Ve),m&&t(ss),x(Je,m),m&&t(ys),m&&t(ps),m&&t(Ce),x(Z,m),m&&t(rs),x(Le,m),m&&t(xs),m&&t(Qe),m&&t(cs),x(Be,m),m&&t(Ds),m&&t(Ne),m&&t(mt),x(ts,m),m&&t(ft),x(qs,m),m&&t(Hs),m&&t(Fs)}}}function af(O){let o,h,c,w,D,$,k,M;return{c(){o=i("p"),h=a("\u270F\uFE0F "),c=i("strong"),w=a("\u8BD5\u8BD5\u770B!"),D=a(" \u4E3A\u4E86\u91CF\u5316\u57DF\u9002\u5E94\u7684\u597D\u5904, \u5FAE\u8C03 IMDb \u6807\u7B7E\u4E0A\u7684\u5206\u7C7B\u5668\u548C\u9884\u5148\u8BAD\u7EC3\u548C\u5FAE\u8C03\u7684Distil BERT\u68C0\u67E5\u70B9\u3002\u5982\u679C\u4F60\u9700\u8981\u590D\u4E60\u6587\u672C\u5206\u7C7B, \u8BF7\u67E5\u770B "),$=i("a"),k=a("\u7B2C\u4E09\u7AE0"),M=a("\u3002"),this.h()},l(u){o=p(u,"P",{});var A=_(o);h=l(A,"\u270F\uFE0F "),c=p(A,"STRONG",{});var P=_(c);w=l(P,"\u8BD5\u8BD5\u770B!"),P.forEach(t),D=l(A," \u4E3A\u4E86\u91CF\u5316\u57DF\u9002\u5E94\u7684\u597D\u5904, \u5FAE\u8C03 IMDb \u6807\u7B7E\u4E0A\u7684\u5206\u7C7B\u5668\u548C\u9884\u5148\u8BAD\u7EC3\u548C\u5FAE\u8C03\u7684Distil BERT\u68C0\u67E5\u70B9\u3002\u5982\u679C\u4F60\u9700\u8981\u590D\u4E60\u6587\u672C\u5206\u7C7B, \u8BF7\u67E5\u770B "),$=p(A,"A",{href:!0});var K=_($);k=l(K,"\u7B2C\u4E09\u7AE0"),K.forEach(t),M=l(A,"\u3002"),A.forEach(t),this.h()},h(){q($,"href","/course/chapter3")},m(u,A){n(u,o,A),s(o,h),s(o,c),s(c,w),s(o,D),s(o,$),s($,k),s(o,M)},d(u){u&&t(o)}}}function lf(O){let o,h,c,w,D,$,k,M,u,A,P,K,L,N,H,F,B,W,v,R,I,V,se,Y,ye,ee,ie,G,fe,U,Fe,le,te,Me,Q,Ee,Te,Ie,pe,ze,xe,re,ue,De,ke,me,Ge,he,$e,ae,we,ve,Ue,je,C,J,Oe,_e,Ke,We,ne,ge,oe,qe,de,Ae,Re,ls,Ye,z,X,Ve,be,ss,Je,ys,ps,Es,Ce,Z,rs,Le,xs,Qe,ns,_s,ce,Bs,cs,Be,Ds,Ne,Ot,mt,ts,ft,qs,Hs,Fs,Kt,rt,m,S,Ms,Ha,Rt,os,He,nt,Ns,ms,ot,Fa,Lt,ds,Na,it,fs,Ia,us,Ga,dt,ut,Ua,Wa,pt,Is,Bt,Gs,Nr,Xe,Po,Kl,So,Oo,Rl,Ko,Ro,Ll,Lo,Bo,Bl,Ho,Fo,Hl,No,Io,Ir,Ht,Gr,Ft,Ur,Us,Go,Fl,Uo,Wo,Nl,Yo,Vo,Wr,ht,Yr,gt,Jo,Ya,Qo,Xo,Vr,Nt,Zo,Jr,It,Qr,Va,ei,Xr,Ze,si,Il,ti,ai,Gl,li,ri,Ja,ni,oi,Ul,ii,pi,Wl,_i,ci,Zr,Gt,en,Ut,sn,hs,mi,Yl,fi,di,Vl,ui,hi,Jl,gi,bi,tn,bt,ki,Ql,$i,wi,an,Wt,ln,Yt,rn,kt,vi,Xl,ji,yi,nn,$t,on,Qa,Ei,pn,Vt,_n,wt,cn,Xa,xi,mn,Jt,fn,Qt,dn,Za,Di,un,Xt,hn,Zt,gn,Ws,qi,Zl,Mi,Ti,er,zi,Ai,bn,ea,kn,sa,$n,el,Ci,wn,vt,ta,Pi,sr,Si,Oi,Ki,aa,Ri,tr,Li,Bi,vn,sl,Hi,jn,la,yn,is,Fi,ar,Ni,Ii,lr,Gi,Ui,rr,Wi,Yi,nr,Vi,Ji,En,Ys,Qi,or,Xi,Zi,ir,ep,sp,xn,ra,Dn,na,qn,es,tp,pr,ap,lp,_r,rp,np,cr,op,ip,mr,pp,_p,fr,cp,mp,Mn,oa,Tn,ia,zn,tl,fp,An,pa,Cn,_a,Pn,gs,dp,dr,up,hp,ur,gp,bp,hr,kp,$p,Sn,_t,jt,gr,ca,wp,ma,vp,br,jp,yp,On,bs,Ep,al,xp,Dp,kr,qp,Mp,$r,Tp,zp,Kn,fa,Rn,ks,Ap,wr,Cp,Pp,vr,Sp,Op,jr,Kp,Rp,Ln,da,Bn,ua,Hn,Vs,Lp,yr,Bp,Hp,Er,Fp,Np,Fn,yt,Nn,ll,Js,Ip,xr,Gp,Up,Dr,Wp,Yp,In,Ts,zs,rl,nl,Vp,Gn,ha,Un,ga,Wn,Et,Yn,Qs,Jp,ol,Qp,Xp,qr,Zp,e_,Vn,ba,Jn,ka,Qn,Xs,s_,Mr,t_,a_,Tr,l_,r_,Xn,$a,Zn,il,n_,eo,wa,so,pl,o_,to,As,Cs,_l,ct,xt,zr,va,i_,Ar,p_,ao,ja,lo,cl,__,ro,Ps,Ss,ml,ya,no,fl,c_,oo,Os,Ks,dl,ul,m_,io,Rs,Ls,hl,Ea,po,gl,f_,_o,bl,Dt,co,kl,xa,d_,mo,Zs,u_,Cr,h_,g_,Pr,b_,k_,fo,Da,uo,$l,$_,ho,qa,go,Ma,bo,wl,w_,ko,Ta,$o,qt,v_,vl,j_,y_,wo,Mt,vo;c=new Cm({props:{fw:O[0]}});const x_=[Sm,Pm],za=[];function D_(e,r){return e[0]==="pt"?0:1}M=D_(O),u=za[M]=x_[M](O),he=new Co({props:{id:"mqElG5QJWUg"}}),ae=new St({props:{$$slots:{default:[Om]},$$scope:{ctx:O}}});const q_=[Rm,Km],Aa=[];function M_(e,r){return e[0]==="pt"?0:1}Ce=M_(O),Z=Aa[Ce]=q_[Ce](O),ns=new T({props:{code:'text = "This is a great [MASK]."',highlighted:'text = <span class="hljs-string">&quot;This is a great [MASK].&quot;</span>'}}),m=new T({props:{code:`from transformers import AutoTokenizer

tokenizer = AutoTokenizer.from_pretrained(model_checkpoint)`,highlighted:`<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoTokenizer

tokenizer = AutoTokenizer.from_pretrained(model_checkpoint)`}});const T_=[Bm,Lm],Ca=[];function z_(e,r){return e[0]==="pt"?0:1}os=z_(O),He=Ca[os]=T_[os](O),Ns=new T({props:{code:`'>>> This is a great deal.'
'>>> This is a great success.'
'>>> This is a great adventure.'
'>>> This is a great idea.'
'>>> This is a great feat.'`,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>`}}),Is=new T({props:{code:`from datasets import load_dataset

imdb_dataset = load_dataset("imdb")
imdb_dataset`,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`}}),Gs=new T({props:{code:`DatasetDict({
    train: Dataset({
        features: ['text', 'label'],
        num_rows: 25000
    })
    test: Dataset({
        features: ['text', 'label'],
        num_rows: 25000
    })
    unsupervised: Dataset({
        features: ['text', 'label'],
        num_rows: 50000
    })
})`,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>
    })
})`}}),Ht=new T({props:{code:`sample = imdb_dataset["train"].shuffle(seed=42).select(range(3))

for row in sample:
    print(f"\\n'>>> Review: {row['text']}'")
    print(f"'>>> Label: {row['label']}'")`,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>)`}}),Ft=new T({props:{code:`
'>>> 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, "kodokoo" in Phir Hera Pheri, etc., etc., the director is becoming ridiculously predictable. Don\\'t get me wrong; as clich\xE9d 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.<br /><br />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.'
'>>> Label: 0'

'>>> 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" 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.<br /><br />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.'
'>>> Label: 0'

'>>> 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. <br /><br />My 4 and 6 year old children love this movie and have been asking again and again to watch it. <br /><br />I have enjoyed watching it again too. Though I have to admit it is not as good on a little TV.<br /><br />I do not have older children so I do not know what they would think of it. <br /><br />The songs are very cute. My daughter keeps singing them over and over.<br /><br />Hope this helps.'
'>>> Label: 1'`,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\xE9d 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>`}}),ht=new St({props:{$$slots:{default:[Hm]},$$scope:{ctx:O}}}),It=new Co({props:{id:"8PmhEIXhBvI"}}),Gt=new T({props:{code:`def tokenize_function(examples):
    result = tokenizer(examples["text"])
    if tokenizer.is_fast:
        result["word_ids"] = [result.word_ids(i) for i in range(len(result["input_ids"]))]
    return result


# Use batched=True to activate fast multithreading!
tokenized_datasets = imdb_dataset.map(
    tokenize_function, batched=True, remove_columns=["text", "label"]
)
tokenized_datasets`,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`}}),Ut=new T({props:{code:`DatasetDict({
    train: Dataset({
        features: ['attention_mask', 'input_ids', 'word_ids'],
        num_rows: 25000
    })
    test: Dataset({
        features: ['attention_mask', 'input_ids', 'word_ids'],
        num_rows: 25000
    })
    unsupervised: Dataset({
        features: ['attention_mask', 'input_ids', 'word_ids'],
        num_rows: 50000
    })
})`,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>
    })
})`}}),Wt=new T({props:{code:"tokenizer.model_max_length",highlighted:"tokenizer.model_max_length"}}),Yt=new T({props:{code:"512",highlighted:'<span class="hljs-number">512</span>'}}),$t=new St({props:{$$slots:{default:[Fm]},$$scope:{ctx:O}}}),Vt=new T({props:{code:"chunk_size = 128",highlighted:'chunk_size = <span class="hljs-number">128</span>'}}),wt=new St({props:{warning:!0,$$slots:{default:[Nm]},$$scope:{ctx:O}}}),Jt=new T({props:{code:`# Slicing produces a list of lists for each feature
tokenized_samples = tokenized_datasets["train"][:3]

for idx, sample in enumerate(tokenized_samples["input_ids"]):
    print(f"'>>> Review {idx} length: {len(sample)}'")`,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>)`}}),Qt=new T({props:{code:`'>>> Review 0 length: 200'
'>>> Review 1 length: 559'
'>>> Review 2 length: 192'`,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>`}}),Xt=new T({props:{code:`concatenated_examples = {
    k: sum(tokenized_samples[k], []) for k in tokenized_samples.keys()
}
total_length = len(concatenated_examples["input_ids"])
print(f"'>>> Concatenated reviews length: {total_length}'")`,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>)`}}),Zt=new T({props:{code:"'>>> Concatenated reviews length: 951'",highlighted:'<span class="hljs-string">&#x27;&gt;&gt;&gt; Concatenated reviews length: 951&#x27;</span>'}}),ea=new T({props:{code:`chunks = {
    k: [t[i : i + chunk_size] for i in range(0, total_length, chunk_size)]
    for k, t in concatenated_examples.items()
}

for chunk in chunks["input_ids"]:
    print(f"'>>> Chunk length: {len(chunk)}'")`,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>)`}}),sa=new T({props:{code:`'>>> Chunk length: 128'
'>>> Chunk length: 128'
'>>> Chunk length: 128'
'>>> Chunk length: 128'
'>>> Chunk length: 128'
'>>> Chunk length: 128'
'>>> Chunk length: 128'
'>>> Chunk length: 55'`,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>`}}),la=new T({props:{code:`def group_texts(examples):
    # Concatenate all texts
    concatenated_examples = {k: sum(examples[k], []) for k in examples.keys()}
    # Compute length of concatenated texts
    total_length = len(concatenated_examples[list(examples.keys())[0]])
    # We drop the last chunk if it's smaller than chunk_size
    total_length = (total_length // chunk_size) * chunk_size
    # Split by chunks of max_len
    result = {
        k: [t[i : i + chunk_size] for i in range(0, total_length, chunk_size)]
        for k, t in concatenated_examples.items()
    }
    # Create a new labels column
    result["labels"] = result["input_ids"].copy()
    return result`,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`}}),ra=new T({props:{code:`lm_datasets = tokenized_datasets.map(group_texts, batched=True)
lm_datasets`,highlighted:`lm_datasets = tokenized_datasets.<span class="hljs-built_in">map</span>(group_texts, batched=<span class="hljs-literal">True</span>)
lm_datasets`}}),na=new T({props:{code:`DatasetDict({
    train: Dataset({
        features: ['attention_mask', 'input_ids', 'labels', 'word_ids'],
        num_rows: 61289
    })
    test: Dataset({
        features: ['attention_mask', 'input_ids', 'labels', 'word_ids'],
        num_rows: 59905
    })
    unsupervised: Dataset({
        features: ['attention_mask', 'input_ids', 'labels', 'word_ids'],
        num_rows: 122963
    })
})`,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>
    })
})`}}),oa=new T({props:{code:'tokenizer.decode(lm_datasets["train"][1]["input_ids"])',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>])'}}),ia=new T({props:{code:`".... at.......... high. a classic line : inspector : i'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'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"`,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>'}}),pa=new T({props:{code:'tokenizer.decode(lm_datasets["train"][1]["labels"])',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>])'}}),_a=new T({props:{code:`".... at.......... high. a classic line : inspector : i'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'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"`,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>'}}),ca=new E_({}),fa=new T({props:{code:`from transformers import DataCollatorForLanguageModeling

data_collator = DataCollatorForLanguageModeling(tokenizer=tokenizer, mlm_probability=0.15)`,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>)`}}),da=new T({props:{code:`samples = [lm_datasets["train"][i] for i in range(2)]
for sample in samples:
    _ = sample.pop("word_ids")

for chunk in data_collator(samples)["input_ids"]:
    print(f"\\n'>>> {tokenizer.decode(chunk)}'")`,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>)`}}),ua=new T({props:{code:`'>>> [CLS] bromwell [MASK] is a cartoon comedy. it ran at the same [MASK] as some other [MASK] about school life, [MASK] as " teachers ". [MASK] [MASK] [MASK] in the teaching [MASK] lead [MASK] to believe that bromwell high\\'[MASK] satire is much closer to reality than is " teachers ". the scramble [MASK] [MASK] financially, the [MASK]ful students whogn [MASK] right through [MASK] pathetic teachers\\'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]...'

'>>> .... at.. [MASK]... [MASK]... high. a classic line plucked inspector : i\\'[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\\'t! [SEP] [CLS] [MASK]ness ( or [MASK]lessness as george \u5B87in stated )\u516C 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'`,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 \u5B87in stated )\u516C 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>`}}),yt=new St({props:{$$slots:{default:[Im]},$$scope:{ctx:O}}});let as=O[0]==="pt"&&ym();const A_=[Um,Gm],Pa=[];function C_(e,r){return e[0]==="pt"?0:1}Ts=C_(O),zs=Pa[Ts]=A_[Ts](O),ha=new T({props:{code:`samples = [lm_datasets["train"][i] for i in range(2)]
batch = whole_word_masking_data_collator(samples)

for chunk in batch["input_ids"]:
    print(f"\\n'>>> {tokenizer.decode(chunk)}'")`,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>)`}}),ga=new T({props:{code:`'>>> [CLS] bromwell high is a cartoon comedy [MASK] it ran at the same time as some other programs about school life, such as " teachers ". my 35 years in the teaching profession lead me to believe that bromwell high\\'s satire is much closer to reality than is " teachers ". the scramble to survive financially, the insightful students who can see right through their pathetic teachers\\'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.....'

'>>> .... [MASK] [MASK] [MASK] [MASK]....... high. a classic line : inspector : i\\'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\\'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'`,highlighted:`<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>`}}),Et=new St({props:{$$slots:{default:[Wm]},$$scope:{ctx:O}}}),ba=new T({props:{code:`train_size = 10_000
test_size = int(0.1 * train_size)

downsampled_dataset = lm_datasets["train"].train_test_split(
    train_size=train_size, test_size=test_size, seed=42
)
downsampled_dataset`,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`}}),ka=new T({props:{code:`DatasetDict({
    train: Dataset({
        features: ['attention_mask', 'input_ids', 'labels', 'word_ids'],
        num_rows: 10000
    })
    test: Dataset({
        features: ['attention_mask', 'input_ids', 'labels', 'word_ids'],
        num_rows: 1000
    })
})`,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>
    })
})`}}),$a=new T({props:{code:`from huggingface_hub import notebook_login

notebook_login()`,highlighted:`<span class="hljs-keyword">from</span> huggingface_hub <span class="hljs-keyword">import</span> notebook_login

notebook_login()`}}),wa=new T({props:{code:"huggingface-cli login",highlighted:'huggingface-<span class="hljs-keyword">cli</span> login'}});const P_=[Vm,Ym],Sa=[];function S_(e,r){return e[0]==="tf"?0:1}As=S_(O),Cs=Sa[As]=P_[As](O),va=new E_({}),ja=new Co({props:{id:"NURcDHhYe98"}});const O_=[Qm,Jm],Oa=[];function K_(e,r){return e[0]==="pt"?0:1}Ps=K_(O),Ss=Oa[Ps]=O_[Ps](O),ya=new T({props:{code:"Perplexity: 21.75",highlighted:'<span class="hljs-meta">&gt;&gt;&gt; </span>Perplexity: <span class="hljs-number">21.75</span>'}});const R_=[Zm,Xm],Ka=[];function L_(e,r){return e[0]==="pt"?0:1}Os=L_(O),Ks=Ka[Os]=R_[Os](O);const B_=[sf,ef],Ra=[];function H_(e,r){return e[0]==="pt"?0:1}Rs=H_(O),Ls=Ra[Rs]=B_[Rs](O),Ea=new T({props:{code:"Perplexity: 11.32",highlighted:'<span class="hljs-meta">&gt;&gt;&gt; </span>Perplexity: <span class="hljs-number">11.32</span>'}});let Pe=O[0]==="pt"&&Em();Dt=new St({props:{$$slots:{default:[tf]},$$scope:{ctx:O}}});let Se=O[0]==="pt"&&xm();return Da=new T({props:{code:`from transformers import pipeline

mask_filler = pipeline(
    "fill-mask", model="huggingface-course/distilbert-base-uncased-finetuned-imdb"
)`,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>
)`}}),qa=new T({props:{code:`preds = mask_filler(text)

for pred in preds:
    print(f">>> {pred['sequence']}")`,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>)`}}),Ma=new T({props:{code:`'>>> this is a great movie.'
'>>> this is a great film.'
'>>> this is a great story.'
'>>> this is a great movies.'
'>>> this is a great character.'`,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>`}}),Ta=new Co({props:{id:"0Oxphw4Q9fo"}}),Mt=new St({props:{$$slots:{default:[af]},$$scope:{ctx:O}}}),{c(){o=i("meta"),h=f(),j(c.$$.fragment),w=f(),D=i("h1"),$=a("\u5FAE\u8C03\u63A9\u7801\u8BED\u8A00\u6A21\u578B"),k=f(),u.c(),A=f(),P=i("p"),K=a("\u5BF9\u4E8E\u8BB8\u591A\u6D89\u53CA Transformer \u6A21\u578B\u7684 NLP \u7A0B\u5E8F, \u4F60\u53EF\u4EE5\u7B80\u5355\u5730\u4ECE Hugging Face Hub \u4E2D\u83B7\u53D6\u4E00\u4E2A\u9884\u8BAD\u7EC3\u7684\u6A21\u578B, \u7136\u540E\u76F4\u63A5\u5728\u4F60\u7684\u6570\u636E\u4E0A\u5BF9\u5176\u8FDB\u884C\u5FAE\u8C03, \u4EE5\u5B8C\u6210\u624B\u5934\u7684\u4EFB\u52A1\u3002\u53EA\u8981\u7528\u4E8E\u9884\u8BAD\u7EC3\u7684\u8BED\u6599\u5E93\u4E0E\u7528\u4E8E\u5FAE\u8C03\u7684\u8BED\u6599\u5E93\u6CA1\u6709\u592A\u5927\u533A\u522B, \u8FC1\u79FB\u5B66\u4E60\u901A\u5E38\u4F1A\u4EA7\u751F\u5F88\u597D\u7684\u7ED3\u679C\u3002"),L=f(),N=i("p"),H=a("\u4F46\u662F, \u5728\u67D0\u4E9B\u60C5\u51B5\u4E0B, \u4F60\u9700\u8981\u5148\u5FAE\u8C03\u6570\u636E\u4E0A\u7684\u8BED\u8A00\u6A21\u578B, \u7136\u540E\u518D\u8BAD\u7EC3\u7279\u5B9A\u4E8E\u4EFB\u52A1\u7684head\u3002\u4F8B\u5982, \u5982\u679C\u60A8\u7684\u6570\u636E\u96C6\u5305\u542B\u6CD5\u5F8B\u5408\u540C\u6216\u79D1\u5B66\u6587\u7AE0, \u50CF BERT \u8FD9\u6837\u7684\u666E\u901A Transformer \u6A21\u578B\u901A\u5E38\u4F1A\u5C06\u60A8\u8BED\u6599\u5E93\u4E2D\u7684\u7279\u5B9A\u9886\u57DF\u8BCD\u89C6\u4E3A\u7A00\u6709\u6807\u8BB0, \u7ED3\u679C\u6027\u80FD\u53EF\u80FD\u4E0D\u5C3D\u5982\u4EBA\u610F\u3002\u901A\u8FC7\u5728\u57DF\u5185\u6570\u636E\u4E0A\u5FAE\u8C03\u8BED\u8A00\u6A21\u578B, \u4F60\u53EF\u4EE5\u63D0\u9AD8\u8BB8\u591A\u4E0B\u6E38\u4EFB\u52A1\u7684\u6027\u80FD, \u8FD9\u610F\u5473\u7740\u60A8\u901A\u5E38\u53EA\u9700\u6267\u884C\u4E00\u6B21\u6B64\u6B65\u9AA4!"),F=f(),B=i("p"),W=a("\u8FD9\u79CD\u5728\u57DF\u5185\u6570\u636E\u4E0A\u5FAE\u8C03\u9884\u8BAD\u7EC3\u8BED\u8A00\u6A21\u578B\u7684\u8FC7\u7A0B\u901A\u5E38\u79F0\u4E3A "),v=i("em"),R=a("\u9886\u57DF\u9002\u5E94"),I=a("\u3002 \u5B83\u4E8E 2018 \u5E74\u7531 "),V=i("a"),se=a("ULMFiT"),Y=a("\u63A8\u5E7F, \u8FD9\u662F\u4F7F\u8FC1\u79FB\u5B66\u4E60\u771F\u6B63\u9002\u7528\u4E8E NLP \u7684\u9996\u6279\u795E\u7ECF\u67B6\u6784\u4E4B\u4E00 (\u57FA\u4E8E LSTM)\u3002 \u4E0B\u56FE\u663E\u793A\u4E86\u4F7F\u7528 ULMFiT \u8FDB\u884C\u57DF\u81EA\u9002\u5E94\u7684\u793A\u4F8B; \u5728\u672C\u8282\u4E2D, \u6211\u4EEC\u5C06\u505A\u7C7B\u4F3C\u7684\u4E8B\u60C5, \u4F46\u4F7F\u7528\u7684\u662F Transformer \u800C\u4E0D\u662F LSTM!"),ye=f(),ee=i("div"),ie=i("img"),fe=f(),U=i("img"),le=f(),te=i("p"),Me=a("\u5728\u672C\u8282\u7ED3\u675F\u65F6, \u4F60\u5C06\u5728Hub\u4E0A\u62E5\u6709\u4E00\u4E2A"),Q=i("a"),Ee=a("\u63A9\u7801\u8BED\u8A00\u6A21\u578B(masked language model)"),Te=a(", \u8BE5\u6A21\u578B\u53EF\u4EE5\u81EA\u52A8\u5B8C\u6210\u53E5\u5B50, \u5982\u4E0B\u6240\u793A:"),Ie=f(),pe=i("iframe"),xe=f(),re=i("iframe"),De=f(),ke=i("p"),me=a("\u8BA9\u6211\u4EEC\u5F00\u59CB\u5427!"),Ge=f(),j(he.$$.fragment),$e=f(),j(ae.$$.fragment),we=f(),ve=i("h2"),Ue=a("\u9009\u62E9\u7528\u4E8E\u63A9\u7801\u8BED\u8A00\u5EFA\u6A21\u7684\u9884\u8BAD\u7EC3\u6A21\u578B"),je=f(),C=i("p"),J=a("\u9996\u5148, \u8BA9\u6211\u4EEC\u4E3A\u63A9\u7801\u8BED\u8A00\u5EFA\u6A21\u9009\u62E9\u4E00\u4E2A\u5408\u9002\u7684\u9884\u8BAD\u7EC3\u6A21\u578B\u3002\u5982\u4EE5\u4E0B\u5C4F\u5E55\u622A\u56FE\u6240\u793A, \u4F60\u53EF\u4EE5\u901A\u8FC7\u5728"),Oe=i("a"),_e=a("Hugging Face Hub"),Ke=a("\u4E0A\u5E94\u7528\u201DFill-Mask\u201D\u8FC7\u6EE4\u5668\u627E\u5230:"),We=f(),ne=i("div"),ge=i("img"),qe=f(),de=i("p"),Ae=a("\u5C3D\u7BA1 BERT \u548C RoBERTa \u7CFB\u5217\u6A21\u578B\u7684\u4E0B\u8F7D\u91CF\u6700\u5927, \u4F46\u6211\u4EEC\u5C06\u4F7F\u7528\u540D\u4E3A "),Re=i("a"),ls=a("DistilBERT"),Ye=a(`\u7684\u6A21\u578B\u3002
\u53EF\u4EE5\u66F4\u5FEB\u5730\u8BAD\u7EC3, \u800C\u4E0B\u6E38\u6027\u80FD\u51E0\u4E4E\u6CA1\u6709\u635F\u5931\u3002\u8FD9\u4E2A\u6A21\u578B\u4F7F\u7528\u4E00\u79CD\u79F0\u4E3A`),z=i("a"),X=i("em"),Ve=a("\u77E5\u8BC6\u84B8\u998F"),be=a("\u7684\u7279\u6B8A\u6280\u672F\u8FDB\u884C\u8BAD\u7EC3, \u5176\u4E2D\u4F7F\u7528\u50CF BERT \u8FD9\u6837\u7684\u5927\u578B\u201C\u6559\u5E08\u6A21\u578B\u201D\u6765\u6307\u5BFC\u53C2\u6570\u5C11\u5F97\u591A\u7684\u201C\u5B66\u751F\u6A21\u578B\u201D\u7684\u8BAD\u7EC3\u3002\u5728\u672C\u8282\u4E2D\u5BF9\u77E5\u8BC6\u84B8\u998F\u7EC6\u8282\u7684\u89E3\u91CA\u4F1A\u4F7F\u6211\u4EEC\u79BB\u9898\u592A\u8FDC, \u4F46\u5982\u679C\u4F60\u6709\u5174\u8DA3, \u53EF\u4EE5\u9605\u8BFB\u6240\u6709\u76F8\u5173\u5185\u5BB9 "),ss=i("a"),Je=i("em"),ys=a("Natural Language Processing with Transformers"),ps=a(" (\u4FD7\u79F0Transformers\u6559\u79D1\u4E66)\u3002"),Es=f(),Z.c(),rs=f(),Le=i("p"),xs=a("DistilBERT \u5927\u7EA6\u6709 6700 \u4E07\u4E2A\u53C2\u6570, \u5927\u7EA6\u6BD4 BERT \u57FA\u672C\u6A21\u578B\u5C0F\u4E24\u500D, \u8FD9\u5927\u81F4\u610F\u5473\u7740\u8BAD\u7EC3\u7684\u901F\u5EA6\u63D0\u9AD8\u4E86\u4E24\u500D \u2014 \u975E\u5E38\u68D2! \u73B0\u5728\u8BA9\u6211\u4EEC\u770B\u770B\u8FD9\u4E2A\u6A21\u578B\u9884\u6D4B\u4EC0\u4E48\u6837\u7684\u6807\u8BB0\u6700\u6709\u53EF\u80FD\u5B8C\u6210\u4E00\u5C0F\u90E8\u5206\u6587\u672C:"),Qe=f(),j(ns.$$.fragment),_s=f(),ce=i("p"),Bs=a("\u4F5C\u4E3A\u4EBA\u7C7B, \u6211\u4EEC\u53EF\u4EE5\u60F3\u8C61 "),cs=i("code"),Be=a("[MASK]"),Ds=a(" \u6807\u8BB0\u6709\u5F88\u591A\u53EF\u80FD\u6027, \u4F8B\u5982 \u201Cday\u201D\u3001 \u201Cride\u201D \u6216\u8005 \u201Cpainting\u201D\u3002\u5BF9\u4E8E\u9884\u8BAD\u7EC3\u6A21\u578B, \u9884\u6D4B\u53D6\u51B3\u4E8E\u6A21\u578B\u6240\u8BAD\u7EC3\u7684\u8BED\u6599\u5E93, \u56E0\u4E3A\u5B83\u4F1A\u5B66\u4E60\u83B7\u53D6\u6570\u636E\u4E2D\u5B58\u5728\u7684\u7EDF\u8BA1\u6A21\u5F0F\u3002\u4E0E BERT \u4E00\u6837, DistilBERT \u5728"),Ne=i("a"),Ot=a("English Wikipedia"),mt=a(" \u548C "),ts=i("a"),ft=a("BookCorpus"),qs=a(" \u6570\u636E\u96C6\u4E0A\u8FDB\u884C\u9884\u8BAD\u7EC3, \u6240\u4EE5\u6211\u4EEC\u671F\u671B\u5BF9 "),Hs=i("code"),Fs=a("[MASK]"),Kt=a(" \u7684\u9884\u6D4B\u80FD\u591F\u53CD\u6620\u8FD9\u4E9B\u9886\u57DF\u3002\u4E3A\u4E86\u9884\u6D4B\u63A9\u7801, \u6211\u4EEC\u9700\u8981 DistilBERT \u7684\u6807\u8BB0\u5668\u6765\u751F\u6210\u6A21\u578B\u7684\u8F93\u5165, \u6240\u4EE5\u8BA9\u6211\u4EEC\u4E5F\u4ECE Hub \u4E0B\u8F7D\u5B83:"),rt=f(),j(m.$$.fragment),S=f(),Ms=i("p"),Ha=a("\u4F7F\u7528\u6807\u8BB0\u5668\u548C\u6A21\u578B, \u6211\u4EEC\u73B0\u5728\u53EF\u4EE5\u5C06\u6211\u4EEC\u7684\u6587\u672C\u793A\u4F8B\u4F20\u9012\u7ED9\u6A21\u578B, \u63D0\u53D6 logits, \u5E76\u6253\u5370\u51FA\u524D 5 \u4E2A\u5019\u9009:"),Rt=f(),He.c(),nt=f(),j(Ns.$$.fragment),ms=f(),ot=i("p"),Fa=a("\u6211\u4EEC\u53EF\u4EE5\u4ECE\u8F93\u51FA\u4E2D\u770B\u5230\u6A21\u578B\u7684\u9884\u6D4B\u662F\u6307\u65E5\u5E38\u7528\u8BED, \u9274\u4E8E\u82F1\u8BED\u7EF4\u57FA\u767E\u79D1\u7684\u57FA\u7840, \u8FD9\u4E5F\u8BB8\u5E76\u4E0D\u5947\u602A\u3002\u8BA9\u6211\u4EEC\u770B\u770B\u6211\u4EEC\u5982\u4F55\u5C06\u8FD9\u4E2A\u9886\u57DF\u6539\u53D8\u4E3A\u66F4\u5C0F\u4F17\u7684\u4E1C\u897F \u2014 \u9AD8\u5EA6\u4E24\u6781\u5206\u5316\u7684\u7535\u5F71\u8BC4\u8BBA!"),Lt=f(),ds=i("h2"),Na=a("\u6570\u636E\u96C6"),it=f(),fs=i("p"),Ia=a("\u4E3A\u4E86\u5C55\u793A\u57DF\u9002\u914D, \u6211\u4EEC\u5C06\u4F7F\u7528\u8457\u540D\u7684"),us=i("a"),Ga=a("\u5927\u578B\u7535\u5F71\u8BC4\u8BBA\u6570\u636E\u96C6(Large Movie Review Dataset)"),dt=a(" (\u6216\u8005\u7B80\u79F0\u4E3AIMDb), \u8FD9\u662F\u4E00\u4E2A\u7535\u5F71\u8BC4\u8BBA\u8BED\u6599\u5E93, \u901A\u5E38\u7528\u4E8E\u5BF9\u60C5\u611F\u5206\u6790\u6A21\u578B\u8FDB\u884C\u57FA\u51C6\u6D4B\u8BD5\u3002\u901A\u8FC7\u5728\u8FD9\u4E2A\u8BED\u6599\u5E93\u4E0A\u5BF9 DistilBERT \u8FDB\u884C\u5FAE\u8C03, \u6211\u4EEC\u9884\u8BA1\u8BED\u8A00\u6A21\u578B\u5C06\u6839\u636E\u7EF4\u57FA\u767E\u79D1\u7684\u4E8B\u5B9E\u6570\u636E\u8C03\u6574\u5176\u8BCD\u6C47\u8868, \u8FD9\u4E9B\u6570\u636E\u5DF2\u7ECF\u9884\u5148\u8BAD\u7EC3\u5230\u7535\u5F71\u8BC4\u8BBA\u4E2D\u66F4\u4E3B\u89C2\u7684\u5143\u7D20\u3002\u6211\u4EEC\u53EF\u4EE5\u4F7F\u7528\u{1F917} Datasets\u4E2D\u7684"),ut=i("code"),Ua=a("load_dataset()"),Wa=a("\u51FD\u6570\u4ECEHugging Face \u4E2D\u83B7\u53D6\u6570\u636E:"),pt=f(),j(Is.$$.fragment),Bt=f(),j(Gs.$$.fragment),Nr=f(),Xe=i("p"),Po=a("\u6211\u4EEC\u53EF\u4EE5\u770B\u5230 "),Kl=i("code"),So=a("train"),Oo=a(" \u548C "),Rl=i("code"),Ko=a("test"),Ro=a(" \u6BCF\u4E2A\u62C6\u5206\u5305\u542B 25,000 \u6761\u8BC4\u8BBA, \u800C\u6709\u4E00\u4E2A\u672A\u6807\u8BB0\u7684\u62C6\u5206\u79F0\u4E3A "),Ll=i("code"),Lo=a("unsupervised"),Bo=a(" \u5305\u542B 50,000 \u6761\u8BC4\u8BBA\u3002\u8BA9\u6211\u4EEC\u770B\u4E00\u4E9B\u793A\u4F8B, \u4EE5\u4E86\u89E3\u6211\u4EEC\u6B63\u5728\u5904\u7406\u7684\u6587\u672C\u7C7B\u578B\u3002\u6B63\u5982\u6211\u4EEC\u5728\u672C\u8BFE\u7A0B\u7684\u524D\u51E0\u7AE0\u4E2D\u6240\u505A\u7684\u90A3\u6837, \u6211\u4EEC\u5C06\u94FE\u63A5 "),Bl=i("code"),Ho=a("Dataset.shuffle()"),Fo=a(" \u548C "),Hl=i("code"),No=a("Dataset.select()"),Io=a(" \u51FD\u6570\u521B\u5EFA\u968F\u673A\u6837\u672C:"),Ir=f(),j(Ht.$$.fragment),Gr=f(),j(Ft.$$.fragment),Ur=f(),Us=i("p"),Go=a("\u662F\u7684, \u8FD9\u4E9B\u80AF\u5B9A\u662F\u7535\u5F71\u8BC4\u8BBA, \u5982\u679C\u4F60\u5E74\u9F84\u8DB3\u591F,\u4F60\u751A\u81F3\u53EF\u80FD\u4F1A\u7406\u89E3\u4E0A\u6B21\u8BC4\u8BBA\u4E2D\u5173\u4E8E\u62E5\u6709 VHS \u7248\u672C\u7684\u8BC4\u8BBA\u{1F61C}! \u867D\u7136\u6211\u4EEC\u4E0D\u9700\u8981\u8BED\u8A00\u5EFA\u6A21\u7684\u6807\u7B7E, \u4F46\u6211\u4EEC\u5DF2\u7ECF\u53EF\u4EE5\u770B\u5230 "),Fl=i("code"),Uo=a("0"),Wo=a(" \u8868\u793A\u8D1F\u9762\u8BC4\u8BBA, \u800C "),Nl=i("code"),Yo=a("1"),Vo=a(" \u5BF9\u5E94\u6B63\u9762\u3002"),Wr=f(),j(ht.$$.fragment),Yr=f(),gt=i("p"),Jo=a("\u73B0\u5728\u6211\u4EEC\u5DF2\u7ECF\u5FEB\u901F\u6D4F\u89C8\u4E86\u6570\u636E, \u8BA9\u6211\u4EEC\u6DF1\u5165\u7814\u7A76\u4E3A\u63A9\u7801\u8BED\u8A00\u5EFA\u6A21\u505A\u51C6\u5907\u3002\u6B63\u5982\u6211\u4EEC\u5C06\u770B\u5230\u7684, \u4E0E\u6211\u4EEC\u5728"),Ya=i("a"),Qo=a("\u7B2C\u4E09\u7AE0"),Xo=a("\u4E2D\u770B\u5230\u7684\u5E8F\u5217\u5206\u7C7B\u4EFB\u52A1\u76F8\u6BD4, \u8FD8\u9700\u8981\u91C7\u53D6\u4E00\u4E9B\u989D\u5916\u7684\u6B65\u9AA4\u3002\u8BA9\u6211\u4EEC\u7EE7\u7EED!"),Vr=f(),Nt=i("h2"),Zo=a("\u9884\u5904\u7406\u6570\u636E"),Jr=f(),j(It.$$.fragment),Qr=f(),Va=i("p"),ei=a("\u5BF9\u4E8E\u81EA\u56DE\u5F52\u548C\u63A9\u7801\u8BED\u8A00\u5EFA\u6A21, \u4E00\u4E2A\u5E38\u89C1\u7684\u9884\u5904\u7406\u6B65\u9AA4\u662F\u8FDE\u63A5\u6240\u6709\u793A\u4F8B, \u7136\u540E\u5C06\u6574\u4E2A\u8BED\u6599\u5E93\u62C6\u5206\u4E3A\u76F8\u540C\u5927\u5C0F\u7684\u5757\u3002 \u8FD9\u4E0E\u6211\u4EEC\u901A\u5E38\u7684\u65B9\u6CD5\u5B8C\u5168\u4E0D\u540C, \u6211\u4EEC\u53EA\u662F\u7B80\u5355\u5730\u6807\u8BB0\u5355\u4E2A\u793A\u4F8B\u3002\u4E3A\u4EC0\u4E48\u8981\u5C06\u6240\u6709\u5185\u5BB9\u8FDE\u63A5\u5728\u4E00\u8D77? \u539F\u56E0\u662F\u5355\u4E2A\u793A\u4F8B\u5982\u679C\u592A\u957F\u53EF\u80FD\u4F1A\u88AB\u622A\u65AD, \u8FD9\u5C06\u5BFC\u81F4\u4E22\u5931\u53EF\u80FD\u5BF9\u8BED\u8A00\u5EFA\u6A21\u4EFB\u52A1\u6709\u7528\u7684\u4FE1\u606F!"),Xr=f(),Ze=i("p"),si=a("\u56E0\u6B64, \u6211\u4EEC\u5C06\u50CF\u5F80\u5E38\u4E00\u6837\u9996\u5148\u6807\u8BB0\u6211\u4EEC\u7684\u8BED\u6599\u5E93, \u4F46\u662F "),Il=i("em"),ti=a("\u6CA1\u6709"),ai=a(" \u5728\u6211\u4EEC\u7684\u6807\u8BB0\u5668\u4E2D\u8BBE\u7F6E "),Gl=i("code"),li=a("truncation=True"),ri=a(" \u9009\u9879\u3002 \u6211\u4EEC\u8FD8\u5C06\u83B7\u53D6\u53EF\u7528\u7684\u5355\u8BCD ID ((\u5982\u679C\u6211\u4EEC\u4F7F\u7528\u5FEB\u901F\u6807\u8BB0\u5668, \u5B83\u4EEC\u662F\u53EF\u7528\u7684, \u5982 "),Ja=i("a"),ni=a("\u7B2C\u516D\u7AE0"),oi=a("\u4E2D\u6240\u8FF0), \u56E0\u4E3A\u6211\u4EEC\u7A0D\u540E\u5C06\u9700\u8981\u5B83\u4EEC\u6765\u8FDB\u884C\u5168\u5B57\u5C4F\u853D\u3002\u6211\u4EEC\u5C06\u628A\u5B83\u5305\u88C5\u5728\u4E00\u4E2A\u7B80\u5355\u7684\u51FD\u6570\u4E2D, \u5F53\u6211\u4EEC\u5728\u505A\u7684\u65F6\u5019, \u6211\u4EEC\u5C06\u5220\u9664 "),Ul=i("code"),ii=a("text"),pi=a(" \u548C "),Wl=i("code"),_i=a("label"),ci=a(" \u5217, \u56E0\u4E3A\u6211\u4EEC\u4E0D\u518D\u9700\u8981\u5B83\u4EEC:"),Zr=f(),j(Gt.$$.fragment),en=f(),j(Ut.$$.fragment),sn=f(),hs=i("p"),mi=a("\u7531\u4E8E DistilBERT \u662F\u4E00\u4E2A\u7C7B\u4F3C BERT \u7684\u6A21\u578B, \u6211\u4EEC\u53EF\u4EE5\u770B\u5230\u7F16\u7801\u6587\u672C\u7531\u6211\u4EEC\u5728\u5176\u4ED6\u7AE0\u8282\u4E2D\u770B\u5230\u7684 "),Yl=i("code"),fi=a("input_ids"),di=a(" \u548C "),Vl=i("code"),ui=a("attention_mask"),hi=a(" \u7EC4\u6210, \u4EE5\u53CA\u6211\u4EEC\u6DFB\u52A0\u7684 "),Jl=i("code"),gi=a("word_ids"),bi=a("\u3002"),tn=f(),bt=i("p"),ki=a("\u73B0\u5728\u6211\u4EEC\u5DF2\u7ECF\u6807\u8BB0\u4E86\u6211\u4EEC\u7684\u7535\u5F71\u8BC4\u8BBA, \u4E0B\u4E00\u6B65\u662F\u5C06\u5B83\u4EEC\u7EC4\u5408\u5728\u4E00\u8D77\u5E76\u5C06\u7ED3\u679C\u5206\u6210\u5757\u3002 \u4F46\u662F\u8FD9\u4E9B\u5757\u5E94\u8BE5\u6709\u591A\u5927? \u8FD9\u6700\u7EC8\u5C06\u53D6\u51B3\u4E8E\u4F60\u53EF\u7528\u7684 GPU \u5185\u5B58\u91CF, \u4F46\u4E00\u4E2A\u597D\u7684\u8D77\u70B9\u662F\u67E5\u770B\u6A21\u578B\u7684\u6700\u5927\u4E0A\u4E0B\u6587\u5927\u5C0F\u662F\u591A\u5C11\u3002\u8FD9\u53EF\u4EE5\u901A\u8FC7\u68C0\u67E5\u6807\u8BB0\u5668\u7684 "),Ql=i("code"),$i=a("model_max_length"),wi=a(" \u5C5E\u6027\u6765\u5224\u65AD:"),an=f(),j(Wt.$$.fragment),ln=f(),j(Yt.$$.fragment),rn=f(),kt=i("p"),vi=a("\u8BE5\u503C\u6765\u81EA\u4E8E\u4E0E\u68C0\u67E5\u70B9\u76F8\u5173\u8054\u7684 "),Xl=i("em"),ji=a("tokenizer_config.json"),yi=a(" \u6587\u4EF6; \u5728\u8FD9\u79CD\u60C5\u51B5\u4E0B, \u6211\u4EEC\u53EF\u4EE5\u770B\u5230\u4E0A\u4E0B\u6587\u5927\u5C0F\u662F 512 \u4E2A\u6807\u8BB0, \u5C31\u50CF BERT \u4E00\u6837\u3002"),nn=f(),j($t.$$.fragment),on=f(),Qa=i("p"),Ei=a("\u56E0\u6B64, \u4EE5\u4FBF\u5728\u50CFGoogle Colab \u90A3\u6837\u7684 GPU \u4E0A\u8FD0\u884C\u6211\u4EEC\u7684\u5B9E\u9A8C, \u6211\u4EEC\u5C06\u9009\u62E9\u53EF\u4EE5\u653E\u5165\u5185\u5B58\u7684\u66F4\u5C0F\u4E00\u4E9B\u7684\u4E1C\u897F:"),pn=f(),j(Vt.$$.fragment),_n=f(),j(wt.$$.fragment),cn=f(),Xa=i("p"),xi=a("\u6709\u8DA3\u7684\u6765\u4E86\u3002\u4E3A\u4E86\u5C55\u793A\u4E32\u8054\u662F\u5982\u4F55\u5DE5\u4F5C\u7684, \u8BA9\u6211\u4EEC\u4ECE\u6211\u4EEC\u7684\u6807\u8BB0\u5316\u8BAD\u7EC3\u96C6\u4E2D\u53D6\u4E00\u4E9B\u8BC4\u8BBA\u5E76\u6253\u5370\u51FA\u6BCF\u4E2A\u8BC4\u8BBA\u7684\u6807\u8BB0\u6570\u91CF:"),mn=f(),j(Jt.$$.fragment),fn=f(),j(Qt.$$.fragment),dn=f(),Za=i("p"),Di=a("\u7136\u540E\u6211\u4EEC\u53EF\u4EE5\u7528\u4E00\u4E2A\u7B80\u5355\u7684\u5B57\u5178\u7406\u89E3\u6765\u8FDE\u63A5\u6240\u6709\u4F8B\u5B50, \u5982\u4E0B\u6240\u793A:"),un=f(),j(Xt.$$.fragment),hn=f(),j(Zt.$$.fragment),gn=f(),Ws=i("p"),qi=a("\u5F88\u68D2, \u603B\u957F\u5EA6\u68C0\u67E5\u51FA\u6765\u4E86 \u2014 \u73B0\u5728, \u8BA9\u6211\u4EEC\u5C06\u8FDE\u63A5\u7684\u8BC4\u8BBA\u62C6\u5206\u4E3A\u5927\u5C0F\u4E3A "),Zl=i("code"),Mi=a("block_size"),Ti=a(" \u7684\u5757\u3002\u4E3A\u6B64, \u6211\u4EEC\u8FED\u4EE3\u4E86 "),er=i("code"),zi=a("concatenated_examples"),Ai=a(" \u4E2D\u7684\u7279\u5F81, \u5E76\u4F7F\u7528\u5217\u8868\u7406\u89E3\u6765\u521B\u5EFA\u6BCF\u4E2A\u7279\u5F81\u7684\u5207\u7247\u3002\u7ED3\u679C\u662F\u6BCF\u4E2A\u7279\u5F81\u7684\u5757\u5B57\u5178:"),bn=f(),j(ea.$$.fragment),kn=f(),j(sa.$$.fragment),$n=f(),el=i("p"),Ci=a("\u6B63\u5982\u4F60\u5728\u8FD9\u4E2A\u4F8B\u5B50\u4E2D\u770B\u5230\u7684, \u6700\u540E\u4E00\u4E2A\u5757\u901A\u5E38\u4F1A\u5C0F\u4E8E\u6700\u5927\u5757\u5927\u5C0F\u3002\u6709\u4E24\u79CD\u4E3B\u8981\u7684\u7B56\u7565\u6765\u5904\u7406\u8FD9\u4E2A\u95EE\u9898:"),wn=f(),vt=i("ul"),ta=i("li"),Pi=a("\u5982\u679C\u6700\u540E\u4E00\u4E2A\u5757\u5C0F\u4E8E "),sr=i("code"),Si=a("chunk_size"),Oi=a(", \u8BF7\u5220\u9664\u5B83\u3002"),Ki=f(),aa=i("li"),Ri=a("\u586B\u5145\u6700\u540E\u4E00\u4E2A\u5757, \u76F4\u5230\u5176\u957F\u5EA6\u7B49\u4E8E "),tr=i("code"),Li=a("chunk_size"),Bi=a("\u3002"),vn=f(),sl=i("p"),Hi=a("\u6211\u4EEC\u5C06\u5728\u8FD9\u91CC\u91C7\u7528\u7B2C\u4E00\u79CD\u65B9\u6CD5, \u56E0\u6B64\u8BA9\u6211\u4EEC\u5C06\u4E0A\u8FF0\u6240\u6709\u903B\u8F91\u5305\u88C5\u5728\u4E00\u4E2A\u51FD\u6570\u4E2D, \u6211\u4EEC\u53EF\u4EE5\u5C06\u5176\u5E94\u7528\u4E8E\u6211\u4EEC\u7684\u6807\u8BB0\u5316\u6570\u636E\u96C6:"),jn=f(),j(la.$$.fragment),yn=f(),is=i("p"),Fi=a("\u6CE8\u610F, \u5728 "),ar=i("code"),Ni=a("group_texts()"),Ii=a(" \u7684\u6700\u540E\u4E00\u6B65\u4E2D, \u6211\u4EEC\u521B\u5EFA\u4E86\u4E00\u4E2A\u65B0\u7684 "),lr=i("code"),Gi=a("labels"),Ui=a(" \u5217, \u5B83\u662F "),rr=i("code"),Wi=a("input_ids"),Yi=a(" \u5217\u7684\u526F\u672C\u3002\u6211\u4EEC\u5F88\u5FEB\u5C31\u4F1A\u770B\u5230, \u8FD9\u662F\u56E0\u4E3A\u5728\u63A9\u7801\u8BED\u8A00\u5EFA\u6A21\u4E2D, \u76EE\u6807\u662F\u9884\u6D4B\u8F93\u5165\u6279\u6B21\u4E2D\u968F\u673A\u63A9\u7801\u7684\u6807\u8BB0, \u5E76\u901A\u8FC7\u521B\u5EFA\u4E00\u4E2A "),nr=i("code"),Vi=a("labels"),Ji=a(" \u5217, \u4EEC\u4E3A\u6211\u4EEC\u7684\u8BED\u8A00\u6A21\u578B\u63D0\u4F9B\u4E86\u57FA\u7840\u4E8B\u5B9E\u4EE5\u4F9B\u5B66\u4E60\u3002"),En=f(),Ys=i("p"),Qi=a("\u73B0\u5728, \u8BA9\u6211\u4EEC\u4F7F\u7528\u6211\u4EEC\u53EF\u4FE1\u8D56\u7684 "),or=i("code"),Xi=a("Dataset.map()"),Zi=a(" \u51FD\u6570\u5C06 "),ir=i("code"),ep=a("group_texts()"),sp=a(" \u5E94\u7528\u5230\u6211\u4EEC\u7684\u6807\u8BB0\u5316\u6570\u636E\u96C6:"),xn=f(),j(ra.$$.fragment),Dn=f(),j(na.$$.fragment),qn=f(),es=i("p"),tp=a("\u4F60\u53EF\u4EE5\u770B\u5230, \u5BF9\u6587\u672C\u8FDB\u884C\u5206\u7EC4, \u7136\u540E\u5BF9\u6587\u672C\u8FDB\u884C\u5206\u5757, \u4EA7\u751F\u7684\u793A\u4F8B\u6BD4\u6211\u4EEC\u6700\u521D\u7684 25,000 \u7528\u4E8E "),pr=i("code"),ap=a("train"),lp=a("\u548C "),_r=i("code"),rp=a("test"),np=a(" \u62C6\u5206\u7684\u793A\u4F8B\u591A\u5F97\u591A\u3002\u90A3\u662F\u56E0\u4E3A\u6211\u4EEC\u73B0\u5728\u6709\u4E86\u6D89\u53CA "),cr=i("em"),op=a("\u8FDE\u7EED\u6807\u8BB0"),ip=a(" \u7684\u793A\u4F8B, \u8FD9\u4E9B\u793A\u4F8B\u8DE8\u8D8A\u4E86\u539F\u59CB\u8BED\u6599\u5E93\u4E2D\u7684\u591A\u4E2A\u793A\u4F8B\u3002\u4F60\u53EF\u4EE5\u901A\u8FC7\u5728\u5176\u4E2D\u4E00\u4E2A\u5757\u4E2D\u67E5\u627E\u7279\u6B8A\u7684 "),mr=i("code"),pp=a("[SEP]"),_p=a(" \u548C "),fr=i("code"),cp=a("[CLS]"),mp=a(" \u6807\u8BB0\u6765\u660E\u786E\u7684\u770B\u5230\u8FD9\u4E00\u70B9:"),Mn=f(),j(oa.$$.fragment),Tn=f(),j(ia.$$.fragment),zn=f(),tl=i("p"),fp=a("\u5728\u6B64\u793A\u4F8B\u4E2D, \u4F60\u53EF\u4EE5\u770B\u5230\u4E24\u7BC7\u91CD\u53E0\u7684\u7535\u5F71\u8BC4\u8BBA, \u4E00\u7BC7\u5173\u4E8E\u9AD8\u4E2D\u7535\u5F71, \u53E6\u4E00\u7BC7\u5173\u4E8E\u65E0\u5BB6\u53EF\u5F52\u3002 \u8BA9\u6211\u4EEC\u4E5F\u770B\u770B\u63A9\u7801\u8BED\u8A00\u5EFA\u6A21\u7684\u6807\u7B7E\u662F\u4EC0\u4E48\u6837\u7684:"),An=f(),j(pa.$$.fragment),Cn=f(),j(_a.$$.fragment),Pn=f(),gs=i("p"),dp=a("\u6B63\u5982\u524D\u9762\u7684 "),dr=i("code"),up=a("group_texts()"),hp=a(" \u51FD\u6570\u6240\u671F\u671B\u7684\u90A3\u6837, \u8FD9\u770B\u8D77\u6765\u4E0E\u89E3\u7801\u540E\u7684 "),ur=i("code"),gp=a("input_ids"),bp=a(" \u76F8\u540C \u2014 \u4F46\u662F\u6211\u4EEC\u7684\u6A21\u578B\u600E\u4E48\u53EF\u80FD\u5B66\u5230\u4EFB\u4F55\u4E1C\u897F\u5462? \u6211\u4EEC\u9519\u8FC7\u4E86\u4E00\u4E2A\u5173\u952E\u6B65\u9AA4: \u5728\u8F93\u5165\u4E2D\u7684\u968F\u673A\u4F4D\u7F6E\u63D2\u5165 "),hr=i("code"),kp=a("[MASK]"),$p=a(" \u6807\u8BB0! \u8BA9\u6211\u4EEC\u770B\u770B\u5982\u4F55\u4F7F\u7528\u7279\u6B8A\u7684\u6570\u636E\u6574\u7406\u5668\u5728\u5FAE\u8C03\u671F\u95F4\u5373\u65F6\u6267\u884C\u6B64\u64CD\u4F5C\u3002"),Sn=f(),_t=i("h2"),jt=i("a"),gr=i("span"),j(ca.$$.fragment),wp=f(),ma=i("span"),vp=a("\u4F7F\u7528 "),br=i("code"),jp=a("Trainer"),yp=a(" API \u5FAE\u8C03DistilBERT"),On=f(),bs=i("p"),Ep=a("\u5FAE\u8C03\u5C4F\u853D\u8BED\u8A00\u6A21\u578B\u51E0\u4E4E\u4E0E\u5FAE\u8C03\u5E8F\u5217\u5206\u7C7B\u6A21\u578B\u76F8\u540C, \u5C31\u50CF\u6211\u4EEC\u5728 "),al=i("a"),xp=a("\u7B2C\u4E09\u7AE0"),Dp=a("\u6240\u4F5C\u7684\u90A3\u6837\u3002 \u552F\u4E00\u7684\u533A\u522B\u662F\u6211\u4EEC\u9700\u8981\u4E00\u4E2A\u7279\u6B8A\u7684\u6570\u636E\u6574\u7406\u5668, \u5B83\u53EF\u4EE5\u968F\u673A\u5C4F\u853D\u6BCF\u6279\u6587\u672C\u4E2D\u7684\u4E00\u4E9B\u6807\u8BB0\u3002\u5E78\u8FD0\u7684\u662F, \u{1F917} Transformers \u4E3A\u8FD9\u9879\u4EFB\u52A1\u51C6\u5907\u4E86\u4E13\u7528\u7684 "),kr=i("code"),qp=a("DataCollatorForLanguageModeling"),Mp=a(" \u3002\u6211\u4EEC\u53EA\u9700\u8981\u5C06\u5B83\u8F6C\u9012\u7ED9\u6807\u8BB0\u5668\u548C\u4E00\u4E2A "),$r=i("code"),Tp=a("mlm_probability"),zp=a(" \u53C2\u6570, \u8BE5\u53C2\u6570\u6307\u5B9A\u8981\u5C4F\u853D\u7684\u6807\u8BB0\u7684\u5206\u6570\u3002\u6211\u4EEC\u5C06\u9009\u62E9 15%, \u8FD9\u662F BERT \u4F7F\u7528\u7684\u6570\u91CF\u4E5F\u662F\u6587\u732E\u4E2D\u7684\u5E38\u89C1\u9009\u62E9:"),Kn=f(),j(fa.$$.fragment),Rn=f(),ks=i("p"),Ap=a("\u8981\u4E86\u89E3\u968F\u673A\u63A9\u7801\u7684\u5DE5\u4F5C\u539F\u7406, \u8BA9\u6211\u4EEC\u5411\u6570\u636E\u6574\u7406\u5668\u63D0\u4F9B\u4E00\u4E9B\u793A\u4F8B\u3002\u7531\u4E8E\u5B83\u9700\u8981\u4E00\u4E2A "),wr=i("code"),Cp=a("dict"),Pp=a(" \u7684\u5217\u8868, \u5176\u4E2D\u6BCF\u4E2A "),vr=i("code"),Sp=a("dict"),Op=a(" \u8868\u793A\u5355\u4E2A\u8FDE\u7EED\u6587\u672C\u5757, \u6211\u4EEC\u9996\u5148\u8FED\u4EE3\u6570\u636E\u96C6, \u7136\u540E\u518D\u5C06\u6279\u6B21\u63D0\u4F9B\u7ED9\u6574\u7406\u5668\u3002\u6211\u4EEC\u5220\u9664\u4E86\u8FD9\u4E2A\u6570\u636E\u6574\u7406\u5668\u7684 "),jr=i("code"),Kp=a('"word_ids"'),Rp=a(" \u952E, \u56E0\u4E3A\u5B83\u4E0D\u9700\u8981\u5B83:"),Ln=f(),j(da.$$.fragment),Bn=f(),j(ua.$$.fragment),Hn=f(),Vs=i("p"),Lp=a("\u5F88\u68D2, \u6210\u529F\u4E86! \u6211\u4EEC\u53EF\u4EE5\u770B\u5230, "),yr=i("code"),Bp=a("[MASK]"),Hp=a(" \u6807\u8BB0\u5DF2\u968F\u673A\u63D2\u5165\u6211\u4EEC\u6587\u672C\u4E2D\u7684\u4E0D\u540C\u4F4D\u7F6E\u3002 \u8FD9\u4E9B\u5C06\u662F\u6211\u4EEC\u7684\u6A21\u578B\u5728\u8BAD\u7EC3\u671F\u95F4\u5FC5\u987B\u9884\u6D4B\u7684\u6807\u8BB0 \u2014 \u6570\u636E\u6574\u7406\u5668\u7684\u7F8E\u5999\u4E4B\u5904\u5728\u4E8E, \u5B83\u5C06\u968F\u673A\u5316\u6BCF\u4E2A\u6279\u6B21\u7684 "),Er=i("code"),Fp=a("[MASK]"),Np=a(" \u63D2\u5165!"),Fn=f(),j(yt.$$.fragment),Nn=f(),as&&as.c(),ll=f(),Js=i("p"),Ip=a("\u5728\u4E3A\u63A9\u7801\u8BED\u8A00\u5EFA\u6A21\u8BAD\u7EC3\u6A21\u578B\u65F6, \u53EF\u4EE5\u4F7F\u7528\u7684\u4E00\u79CD\u6280\u672F\u662F\u5C06\u6574\u4E2A\u5355\u8BCD\u4E00\u8D77\u5C4F\u853D, \u800C\u4E0D\u4EC5\u4EC5\u662F\u5355\u4E2A\u6807\u8BB0\u3002\u8FD9\u79CD\u65B9\u6CD5\u79F0\u4E3A "),xr=i("em"),Gp=a("\u5168\u8BCD\u5C4F\u853D"),Up=a("\u3002 \u5982\u679C\u6211\u4EEC\u60F3\u4F7F\u7528\u5168\u8BCD\u5C4F\u853D, \u6211\u4EEC\u9700\u8981\u81EA\u5DF1\u6784\u5EFA\u4E00\u4E2A\u6570\u636E\u6574\u7406\u5668\u3002\u6570\u636E\u6574\u7406\u5668\u53EA\u662F\u4E00\u4E2A\u51FD\u6570, \u5B83\u63A5\u53D7\u4E00\u4E2A\u6837\u672C\u5217\u8868\u5E76\u5C06\u5B83\u4EEC\u8F6C\u6362\u4E3A\u4E00\u4E2A\u6279\u6B21, \u6240\u4EE5\u73B0\u5728\u8BA9\u6211\u4EEC\u8FD9\u6837\u505A\u5427! \u6211\u4EEC\u5C06\u4F7F\u7528\u4E4B\u524D\u8BA1\u7B97\u7684\u5355\u8BCD ID \u5728\u5355\u8BCD\u7D22\u5F15\u548C\u76F8\u5E94\u6807\u8BB0\u4E4B\u95F4\u8FDB\u884C\u6620\u5C04, \u7136\u540E\u968F\u673A\u51B3\u5B9A\u8981\u5C4F\u853D\u54EA\u4E9B\u5355\u8BCD\u5E76\u5C06\u8BE5\u5C4F\u853D\u5E94\u7528\u4E8E\u8F93\u5165\u3002\u8BF7\u6CE8\u610F, \u9664\u4E86\u4E0E\u63A9\u7801\u5BF9\u5E94\u7684\u6807\u7B7E\u5916, \u6240\u6709\u7684\u6807\u7B7E\u5747\u4E3A "),Dr=i("code"),Wp=a("-100"),Yp=a("\u3002"),In=f(),zs.c(),rl=f(),nl=i("p"),Vp=a("Next, we can try it on the same samples as before:"),Gn=f(),j(ha.$$.fragment),Un=f(),j(ga.$$.fragment),Wn=f(),j(Et.$$.fragment),Yn=f(),Qs=i("p"),Jp=a("\u73B0\u5728\u6211\u4EEC\u6709\u4E24\u4E2A\u6570\u636E\u6574\u7406\u5668, \u5176\u4F59\u7684\u5FAE\u8C03\u6B65\u9AA4\u662F\u6807\u51C6\u7684\u3002\u5982\u679C\u60A8\u6CA1\u6709\u8DB3\u591F\u5E78\u8FD0\u5730\u83B7\u5F97\u795E\u8BDD\u822C\u7684 P100 GPU \u{1F62D}, \u5728 Google Colab \u4E0A\u8FDB\u884C\u8BAD\u7EC3\u53EF\u80FD\u9700\u8981\u4E00\u6BB5\u65F6\u95F4, \u56E0\u6B64\u6211\u4EEC\u5C06\u9996\u5148\u5C06\u8BAD\u7EC3\u96C6\u7684\u5927\u5C0F\u7F29\u51CF\u4E3A\u51E0\u5343\u4E2A\u793A\u4F8B\u3002\u522B\u62C5\u5FC3, \u6211\u4EEC\u4ECD\u7136\u4F1A\u5F97\u5230\u4E00\u4E2A\u76F8\u5F53\u4E0D\u9519\u7684\u8BED\u8A00\u6A21\u578B! \u5728 \u{1F917} Datasets \u4E2D\u5FEB\u901F\u4E0B\u91C7\u6837\u6570\u636E\u96C6\u7684\u65B9\u6CD5\u662F\u901A\u8FC7\u6211\u4EEC\u5728 "),ol=i("a"),Qp=a("\u7B2C\u4E94\u7AE0"),Xp=a(" \u4E2D\u770B\u5230\u7684 "),qr=i("code"),Zp=a("Dataset.train_test_split()"),e_=a(" \u51FD\u6570:"),Vn=f(),j(ba.$$.fragment),Jn=f(),j(ka.$$.fragment),Qn=f(),Xs=i("p"),s_=a("\u8FD9\u4F1A\u81EA\u52A8\u521B\u5EFA\u65B0\u7684 "),Mr=i("code"),t_=a("train"),a_=a(" \u548C "),Tr=i("code"),l_=a("test"),r_=a(" \u62C6\u5206, \u8BAD\u7EC3\u96C6\u5927\u5C0F\u8BBE\u7F6E\u4E3A 10,000 \u4E2A\u793A\u4F8B, \u9A8C\u8BC1\u8BBE\u7F6E\u4E3A\u5176\u4E2D\u7684 10% \u2014 \u5982\u679C\u4F60\u6709\u4E00\u4E2A\u5F3A\u5927\u7684 GPU, \u53EF\u4EE5\u968F\u610F\u589E\u52A0\u5B83! \u6211\u4EEC\u9700\u8981\u505A\u7684\u4E0B\u4E00\u4EF6\u4E8B\u662F\u767B\u5F55 Hugging Face Hub\u3002\u5982\u679C\u4F60\u5728\u7B14\u8BB0\u672C\u4E2D\u8FD0\u884C\u6B64\u4EE3\u7801, \u5219\u53EF\u4EE5\u4F7F\u7528\u4EE5\u4E0B\u5B9E\u7528\u7A0B\u5E8F\u51FD\u6570\u6267\u884C\u6B64\u64CD\u4F5C:"),Xn=f(),j($a.$$.fragment),Zn=f(),il=i("p"),n_=a("\u8FD9\u5C06\u663E\u793A\u4E00\u4E2A\u5C0F\u90E8\u4EF6, \u4F60\u53EF\u4EE5\u5728\u5176\u4E2D\u8F93\u5165\u4F60\u7684\u51ED\u636E\u3002\u6216\u8005, \u4F60\u53EF\u4EE5\u8FD0\u884C:"),eo=f(),j(wa.$$.fragment),so=f(),pl=i("p"),o_=a("\u5728\u4F60\u6700\u559C\u6B22\u7684\u7EC8\u7AEF\u4E2D\u767B\u5F55\u3002"),to=f(),Cs.c(),_l=f(),ct=i("h3"),xt=i("a"),zr=i("span"),j(va.$$.fragment),i_=f(),Ar=i("span"),p_=a("\u8BED\u8A00\u6A21\u578B\u7684perplexity"),ao=f(),j(ja.$$.fragment),lo=f(),cl=i("p"),__=a("\u4E0E\u6587\u672C\u5206\u7C7B\u6216\u95EE\u7B54\u7B49\u5176\u4ED6\u4EFB\u52A1\u4E0D\u540C, \u5728\u8FD9\u4E9B\u4EFB\u52A1\u4E2D, \u6211\u4EEC\u4F1A\u5F97\u5230\u4E00\u4E2A\u5E26\u6807\u7B7E\u7684\u8BED\u6599\u5E93\u8FDB\u884C\u8BAD\u7EC3, \u800C\u8BED\u8A00\u5EFA\u6A21\u5219\u6CA1\u6709\u4EFB\u4F55\u660E\u786E\u7684\u6807\u7B7E\u3002\u90A3\u4E48\u6211\u4EEC\u5982\u4F55\u786E\u5B9A\u4EC0\u4E48\u662F\u597D\u7684\u8BED\u8A00\u6A21\u578B\u5462? \u5C31\u50CF\u624B\u673A\u4E2D\u7684\u81EA\u52A8\u66F4\u6B63\u529F\u80FD\u4E00\u6837, \u4E00\u4E2A\u597D\u7684\u8BED\u8A00\u6A21\u578B\u662F\u4E3A\u8BED\u6CD5\u6B63\u786E\u7684\u53E5\u5B50\u5206\u914D\u9AD8\u6982\u7387, \u4E3A\u65E0\u610F\u4E49\u7684\u53E5\u5B50\u5206\u914D\u4F4E\u6982\u7387\u3002\u4E3A\u4E86\u8BA9\u4F60\u66F4\u597D\u5730\u4E86\u89E3\u8FD9\u662F\u4EC0\u4E48\u6837\u5B50, \u60A8\u53EF\u4EE5\u5728\u7F51\u4E0A\u627E\u5230\u4E00\u6574\u5957 \u201Cautocorrect fails\u201D, \u5176\u4E2D\u4E00\u4E2A\u4EBA\u624B\u673A\u4E2D\u7684\u6A21\u578B\u4EA7\u751F\u4E86\u4E00\u4E9B\u76F8\u5F53\u6709\u8DA3 (\u800C\u4E14\u901A\u5E38\u4E0D\u5408\u9002) \u7684\u7ED3\u679C!"),ro=f(),Ss.c(),ml=f(),j(ya.$$.fragment),no=f(),fl=i("p"),c_=a("\u8F83\u4F4E\u7684perplexity\u5206\u6570\u610F\u5473\u7740\u66F4\u597D\u7684\u8BED\u8A00\u6A21\u578B, \u6211\u4EEC\u53EF\u4EE5\u5728\u8FD9\u91CC\u770B\u5230\u6211\u4EEC\u7684\u8D77\u59CB\u6A21\u578B\u6709\u4E00\u4E2A\u8F83\u5927\u7684\u503C\u3002\u770B\u770B\u6211\u4EEC\u80FD\u4E0D\u80FD\u901A\u8FC7\u5FAE\u8C03\u6765\u964D\u4F4E\u5B83! \u4E3A\u6B64, \u6211\u4EEC\u9996\u5148\u8FD0\u884C\u8BAD\u7EC3\u5FAA\u73AF:"),oo=f(),Ks.c(),dl=f(),ul=i("p"),m_=a("\u7136\u540E\u50CF\u4EE5\u524D\u4E00\u6837\u8BA1\u7B97\u6D4B\u8BD5\u96C6\u4E0A\u7684perplexity\u5EA6:"),io=f(),Ls.c(),hl=f(),j(Ea.$$.fragment),po=f(),gl=i("p"),f_=a("\u5F88\u597D \u2014 \u8FD9\u5927\u5927\u51CF\u5C11\u4E86\u56F0\u60D1, \u8FD9\u544A\u8BC9\u6211\u4EEC\u6A21\u578B\u5DF2\u7ECF\u4E86\u89E3\u4E86\u4E00\u4E9B\u5173\u4E8E\u7535\u5F71\u8BC4\u8BBA\u9886\u57DF\u7684\u77E5\u8BC6!"),_o=f(),Pe&&Pe.c(),bl=f(),j(Dt.$$.fragment),co=f(),Se&&Se.c(),kl=f(),xa=i("h2"),d_=a("\u4F7F\u7528\u6211\u4EEC\u5FAE\u8C03\u7684\u6A21\u578B"),mo=f(),Zs=i("p"),u_=a("\u4F60\u53EF\u4EE5\u901A\u8FC7\u5728Hub\u4E0A\u4F7F\u7528\u5176\u4ED6\u5C0F\u90E8\u4EF6\u6216\u5728\u672C\u5730\u4F7F\u7528\u{1F917} Transformers \u7684"),Cr=i("code"),h_=a("\u7BA1\u9053"),g_=a("\u4E8E\u5FAE\u8C03\u6A21\u578B\u8FDB\u884C\u4EA4\u4E92\u3002\u8BA9\u6211\u4EEC\u4F7F\u7528\u540E\u8005\u6765\u4E0B\u8F7D\u6211\u4EEC\u7684\u6A21\u578B, \u4F7F\u7528 "),Pr=i("code"),b_=a("fill-mask"),k_=a(" \u7BA1\u9053:"),fo=f(),j(Da.$$.fragment),uo=f(),$l=i("p"),$_=a("\u7136\u540E, \u6211\u4EEC\u53EF\u4EE5\u5411\u7BA1\u9053\u63D0\u4F9B \u201CThis is a great [MASK]\u201D \u793A\u4F8B\u6587\u672C, \u5E76\u67E5\u770B\u524D 5 \u4E2A\u9884\u6D4B\u662F\u4EC0\u4E48:"),ho=f(),j(qa.$$.fragment),go=f(),j(Ma.$$.fragment),bo=f(),wl=i("p"),w_=a("\u597D\u7684 \u2014 \u6211\u4EEC\u7684\u6A21\u578B\u663E\u7136\u5DF2\u7ECF\u8C03\u6574\u4E86\u5B83\u7684\u6743\u91CD\u6765\u9884\u6D4B\u4E0E\u7535\u5F71\u66F4\u5BC6\u5207\u76F8\u5173\u7684\u8BCD!"),ko=f(),j(Ta.$$.fragment),$o=f(),qt=i("p"),v_=a("\u8FD9\u7ED3\u675F\u4E86\u6211\u4EEC\u8BAD\u7EC3\u8BED\u8A00\u6A21\u578B\u7684\u7B2C\u4E00\u4E2A\u5B9E\u9A8C\u3002\u5728 "),vl=i("a"),j_=a("\u7B2C\u516D\u8282"),y_=a("\u4E2D\u4F60\u5C06\u5B66\u4E60\u5982\u4F55\u4ECE\u5934\u5F00\u59CB\u8BAD\u7EC3\u50CF GPT-2 \u8FD9\u6837\u7684\u81EA\u56DE\u5F52\u6A21\u578B; \u5982\u679C\u4F60\u60F3\u4E86\u89E3\u5982\u4F55\u9884\u8BAD\u7EC3\u60A8\u81EA\u5DF1\u7684 Transformer \u6A21\u578B, \u8BF7\u524D\u5F80\u90A3\u91CC!"),wo=f(),j(Mt.$$.fragment),this.h()},l(e){const r=zm('[data-svelte="svelte-1phssyn"]',document.head);o=p(r,"META",{name:!0,content:!0}),r.forEach(t),h=d(e),y(c.$$.fragment,e),w=d(e),D=p(e,"H1",{id:!0});var Sr=_(D);$=l(Sr,"\u5FAE\u8C03\u63A9\u7801\u8BED\u8A00\u6A21\u578B"),Sr.forEach(t),k=d(e),u.l(e),A=d(e),P=p(e,"P",{});var jl=_(P);K=l(jl,"\u5BF9\u4E8E\u8BB8\u591A\u6D89\u53CA Transformer \u6A21\u578B\u7684 NLP \u7A0B\u5E8F, \u4F60\u53EF\u4EE5\u7B80\u5355\u5730\u4ECE Hugging Face Hub \u4E2D\u83B7\u53D6\u4E00\u4E2A\u9884\u8BAD\u7EC3\u7684\u6A21\u578B, \u7136\u540E\u76F4\u63A5\u5728\u4F60\u7684\u6570\u636E\u4E0A\u5BF9\u5176\u8FDB\u884C\u5FAE\u8C03, \u4EE5\u5B8C\u6210\u624B\u5934\u7684\u4EFB\u52A1\u3002\u53EA\u8981\u7528\u4E8E\u9884\u8BAD\u7EC3\u7684\u8BED\u6599\u5E93\u4E0E\u7528\u4E8E\u5FAE\u8C03\u7684\u8BED\u6599\u5E93\u6CA1\u6709\u592A\u5927\u533A\u522B, \u8FC1\u79FB\u5B66\u4E60\u901A\u5E38\u4F1A\u4EA7\u751F\u5F88\u597D\u7684\u7ED3\u679C\u3002"),jl.forEach(t),L=d(e),N=p(e,"P",{});var Or=_(N);H=l(Or,"\u4F46\u662F, \u5728\u67D0\u4E9B\u60C5\u51B5\u4E0B, \u4F60\u9700\u8981\u5148\u5FAE\u8C03\u6570\u636E\u4E0A\u7684\u8BED\u8A00\u6A21\u578B, \u7136\u540E\u518D\u8BAD\u7EC3\u7279\u5B9A\u4E8E\u4EFB\u52A1\u7684head\u3002\u4F8B\u5982, \u5982\u679C\u60A8\u7684\u6570\u636E\u96C6\u5305\u542B\u6CD5\u5F8B\u5408\u540C\u6216\u79D1\u5B66\u6587\u7AE0, \u50CF BERT \u8FD9\u6837\u7684\u666E\u901A Transformer \u6A21\u578B\u901A\u5E38\u4F1A\u5C06\u60A8\u8BED\u6599\u5E93\u4E2D\u7684\u7279\u5B9A\u9886\u57DF\u8BCD\u89C6\u4E3A\u7A00\u6709\u6807\u8BB0, \u7ED3\u679C\u6027\u80FD\u53EF\u80FD\u4E0D\u5C3D\u5982\u4EBA\u610F\u3002\u901A\u8FC7\u5728\u57DF\u5185\u6570\u636E\u4E0A\u5FAE\u8C03\u8BED\u8A00\u6A21\u578B, \u4F60\u53EF\u4EE5\u63D0\u9AD8\u8BB8\u591A\u4E0B\u6E38\u4EFB\u52A1\u7684\u6027\u80FD, \u8FD9\u610F\u5473\u7740\u60A8\u901A\u5E38\u53EA\u9700\u6267\u884C\u4E00\u6B21\u6B64\u6B65\u9AA4!"),Or.forEach(t),F=d(e),B=p(e,"P",{});var et=_(B);W=l(et,"\u8FD9\u79CD\u5728\u57DF\u5185\u6570\u636E\u4E0A\u5FAE\u8C03\u9884\u8BAD\u7EC3\u8BED\u8A00\u6A21\u578B\u7684\u8FC7\u7A0B\u901A\u5E38\u79F0\u4E3A "),v=p(et,"EM",{});var yl=_(v);R=l(yl,"\u9886\u57DF\u9002\u5E94"),yl.forEach(t),I=l(et,"\u3002 \u5B83\u4E8E 2018 \u5E74\u7531 "),V=p(et,"A",{href:!0,rel:!0});var Kr=_(V);se=l(Kr,"ULMFiT"),Kr.forEach(t),Y=l(et,"\u63A8\u5E7F, \u8FD9\u662F\u4F7F\u8FC1\u79FB\u5B66\u4E60\u771F\u6B63\u9002\u7528\u4E8E NLP \u7684\u9996\u6279\u795E\u7ECF\u67B6\u6784\u4E4B\u4E00 (\u57FA\u4E8E LSTM)\u3002 \u4E0B\u56FE\u663E\u793A\u4E86\u4F7F\u7528 ULMFiT \u8FDB\u884C\u57DF\u81EA\u9002\u5E94\u7684\u793A\u4F8B; \u5728\u672C\u8282\u4E2D, \u6211\u4EEC\u5C06\u505A\u7C7B\u4F3C\u7684\u4E8B\u60C5, \u4F46\u4F7F\u7528\u7684\u662F Transformer \u800C\u4E0D\u662F LSTM!"),et.forEach(t),ye=d(e),ee=p(e,"DIV",{class:!0});var La=_(ee);ie=p(La,"IMG",{class:!0,src:!0,alt:!0}),fe=d(La),U=p(La,"IMG",{class:!0,src:!0,alt:!0}),La.forEach(t),le=d(e),te=p(e,"P",{});var Ba=_(te);Me=l(Ba,"\u5728\u672C\u8282\u7ED3\u675F\u65F6, \u4F60\u5C06\u5728Hub\u4E0A\u62E5\u6709\u4E00\u4E2A"),Q=p(Ba,"A",{href:!0,rel:!0});var Rr=_(Q);Ee=l(Rr,"\u63A9\u7801\u8BED\u8A00\u6A21\u578B(masked language model)"),Rr.forEach(t),Te=l(Ba,", \u8BE5\u6A21\u578B\u53EF\u4EE5\u81EA\u52A8\u5B8C\u6210\u53E5\u5B50, \u5982\u4E0B\u6240\u793A:"),Ba.forEach(t),Ie=d(e),pe=p(e,"IFRAME",{src:!0,frameborder:!0,height:!0,title:!0,class:!0,allow:!0,sandbox:!0}),_(pe).forEach(t),xe=d(e),re=p(e,"IFRAME",{src:!0,frameborder:!0,height:!0,title:!0,class:!0,allow:!0,sandbox:!0}),_(re).forEach(t),De=d(e),ke=p(e,"P",{});var El=_(ke);me=l(El,"\u8BA9\u6211\u4EEC\u5F00\u59CB\u5427!"),El.forEach(t),Ge=d(e),y(he.$$.fragment,e),$e=d(e),y(ae.$$.fragment,e),we=d(e),ve=p(e,"H2",{id:!0});var Lr=_(ve);Ue=l(Lr,"\u9009\u62E9\u7528\u4E8E\u63A9\u7801\u8BED\u8A00\u5EFA\u6A21\u7684\u9884\u8BAD\u7EC3\u6A21\u578B"),Lr.forEach(t),je=d(e),C=p(e,"P",{});var Tt=_(C);J=l(Tt,"\u9996\u5148, \u8BA9\u6211\u4EEC\u4E3A\u63A9\u7801\u8BED\u8A00\u5EFA\u6A21\u9009\u62E9\u4E00\u4E2A\u5408\u9002\u7684\u9884\u8BAD\u7EC3\u6A21\u578B\u3002\u5982\u4EE5\u4E0B\u5C4F\u5E55\u622A\u56FE\u6240\u793A, \u4F60\u53EF\u4EE5\u901A\u8FC7\u5728"),Oe=p(Tt,"A",{href:!0,rel:!0});var xl=_(Oe);_e=l(xl,"Hugging Face Hub"),xl.forEach(t),Ke=l(Tt,"\u4E0A\u5E94\u7528\u201DFill-Mask\u201D\u8FC7\u6EE4\u5668\u627E\u5230:"),Tt.forEach(t),We=d(e),ne=p(e,"DIV",{class:!0});var Dl=_(ne);ge=p(Dl,"IMG",{src:!0,alt:!0,width:!0}),Dl.forEach(t),qe=d(e),de=p(e,"P",{});var $s=_(de);Ae=l($s,"\u5C3D\u7BA1 BERT \u548C RoBERTa \u7CFB\u5217\u6A21\u578B\u7684\u4E0B\u8F7D\u91CF\u6700\u5927, \u4F46\u6211\u4EEC\u5C06\u4F7F\u7528\u540D\u4E3A "),Re=p($s,"A",{href:!0,rel:!0});var Br=_(Re);ls=l(Br,"DistilBERT"),Br.forEach(t),Ye=l($s,`\u7684\u6A21\u578B\u3002
\u53EF\u4EE5\u66F4\u5FEB\u5730\u8BAD\u7EC3, \u800C\u4E0B\u6E38\u6027\u80FD\u51E0\u4E4E\u6CA1\u6709\u635F\u5931\u3002\u8FD9\u4E2A\u6A21\u578B\u4F7F\u7528\u4E00\u79CD\u79F0\u4E3A`),z=p($s,"A",{href:!0,rel:!0});var Hr=_(z);X=p(Hr,"EM",{});var F_=_(X);Ve=l(F_,"\u77E5\u8BC6\u84B8\u998F"),F_.forEach(t),Hr.forEach(t),be=l($s,"\u7684\u7279\u6B8A\u6280\u672F\u8FDB\u884C\u8BAD\u7EC3, \u5176\u4E2D\u4F7F\u7528\u50CF BERT \u8FD9\u6837\u7684\u5927\u578B\u201C\u6559\u5E08\u6A21\u578B\u201D\u6765\u6307\u5BFC\u53C2\u6570\u5C11\u5F97\u591A\u7684\u201C\u5B66\u751F\u6A21\u578B\u201D\u7684\u8BAD\u7EC3\u3002\u5728\u672C\u8282\u4E2D\u5BF9\u77E5\u8BC6\u84B8\u998F\u7EC6\u8282\u7684\u89E3\u91CA\u4F1A\u4F7F\u6211\u4EEC\u79BB\u9898\u592A\u8FDC, \u4F46\u5982\u679C\u4F60\u6709\u5174\u8DA3, \u53EF\u4EE5\u9605\u8BFB\u6240\u6709\u76F8\u5173\u5185\u5BB9 "),ss=p($s,"A",{href:!0,rel:!0});var N_=_(ss);Je=p(N_,"EM",{});var I_=_(Je);ys=l(I_,"Natural Language Processing with Transformers"),I_.forEach(t),N_.forEach(t),ps=l($s," (\u4FD7\u79F0Transformers\u6559\u79D1\u4E66)\u3002"),$s.forEach(t),Es=d(e),Z.l(e),rs=d(e),Le=p(e,"P",{});var G_=_(Le);xs=l(G_,"DistilBERT \u5927\u7EA6\u6709 6700 \u4E07\u4E2A\u53C2\u6570, \u5927\u7EA6\u6BD4 BERT \u57FA\u672C\u6A21\u578B\u5C0F\u4E24\u500D, \u8FD9\u5927\u81F4\u610F\u5473\u7740\u8BAD\u7EC3\u7684\u901F\u5EA6\u63D0\u9AD8\u4E86\u4E24\u500D \u2014 \u975E\u5E38\u68D2! \u73B0\u5728\u8BA9\u6211\u4EEC\u770B\u770B\u8FD9\u4E2A\u6A21\u578B\u9884\u6D4B\u4EC0\u4E48\u6837\u7684\u6807\u8BB0\u6700\u6709\u53EF\u80FD\u5B8C\u6210\u4E00\u5C0F\u90E8\u5206\u6587\u672C:"),G_.forEach(t),Qe=d(e),y(ns.$$.fragment,e),_s=d(e),ce=p(e,"P",{});var st=_(ce);Bs=l(st,"\u4F5C\u4E3A\u4EBA\u7C7B, \u6211\u4EEC\u53EF\u4EE5\u60F3\u8C61 "),cs=p(st,"CODE",{});var U_=_(cs);Be=l(U_,"[MASK]"),U_.forEach(t),Ds=l(st," \u6807\u8BB0\u6709\u5F88\u591A\u53EF\u80FD\u6027, \u4F8B\u5982 \u201Cday\u201D\u3001 \u201Cride\u201D \u6216\u8005 \u201Cpainting\u201D\u3002\u5BF9\u4E8E\u9884\u8BAD\u7EC3\u6A21\u578B, \u9884\u6D4B\u53D6\u51B3\u4E8E\u6A21\u578B\u6240\u8BAD\u7EC3\u7684\u8BED\u6599\u5E93, \u56E0\u4E3A\u5B83\u4F1A\u5B66\u4E60\u83B7\u53D6\u6570\u636E\u4E2D\u5B58\u5728\u7684\u7EDF\u8BA1\u6A21\u5F0F\u3002\u4E0E BERT \u4E00\u6837, DistilBERT \u5728"),Ne=p(st,"A",{href:!0,rel:!0});var W_=_(Ne);Ot=l(W_,"English Wikipedia"),W_.forEach(t),mt=l(st," \u548C "),ts=p(st,"A",{href:!0,rel:!0});var Y_=_(ts);ft=l(Y_,"BookCorpus"),Y_.forEach(t),qs=l(st," \u6570\u636E\u96C6\u4E0A\u8FDB\u884C\u9884\u8BAD\u7EC3, \u6240\u4EE5\u6211\u4EEC\u671F\u671B\u5BF9 "),Hs=p(st,"CODE",{});var V_=_(Hs);Fs=l(V_,"[MASK]"),V_.forEach(t),Kt=l(st," \u7684\u9884\u6D4B\u80FD\u591F\u53CD\u6620\u8FD9\u4E9B\u9886\u57DF\u3002\u4E3A\u4E86\u9884\u6D4B\u63A9\u7801, \u6211\u4EEC\u9700\u8981 DistilBERT \u7684\u6807\u8BB0\u5668\u6765\u751F\u6210\u6A21\u578B\u7684\u8F93\u5165, \u6240\u4EE5\u8BA9\u6211\u4EEC\u4E5F\u4ECE Hub \u4E0B\u8F7D\u5B83:"),st.forEach(t),rt=d(e),y(m.$$.fragment,e),S=d(e),Ms=p(e,"P",{});var J_=_(Ms);Ha=l(J_,"\u4F7F\u7528\u6807\u8BB0\u5668\u548C\u6A21\u578B, \u6211\u4EEC\u73B0\u5728\u53EF\u4EE5\u5C06\u6211\u4EEC\u7684\u6587\u672C\u793A\u4F8B\u4F20\u9012\u7ED9\u6A21\u578B, \u63D0\u53D6 logits, \u5E76\u6253\u5370\u51FA\u524D 5 \u4E2A\u5019\u9009:"),J_.forEach(t),Rt=d(e),He.l(e),nt=d(e),y(Ns.$$.fragment,e),ms=d(e),ot=p(e,"P",{});var Q_=_(ot);Fa=l(Q_,"\u6211\u4EEC\u53EF\u4EE5\u4ECE\u8F93\u51FA\u4E2D\u770B\u5230\u6A21\u578B\u7684\u9884\u6D4B\u662F\u6307\u65E5\u5E38\u7528\u8BED, \u9274\u4E8E\u82F1\u8BED\u7EF4\u57FA\u767E\u79D1\u7684\u57FA\u7840, \u8FD9\u4E5F\u8BB8\u5E76\u4E0D\u5947\u602A\u3002\u8BA9\u6211\u4EEC\u770B\u770B\u6211\u4EEC\u5982\u4F55\u5C06\u8FD9\u4E2A\u9886\u57DF\u6539\u53D8\u4E3A\u66F4\u5C0F\u4F17\u7684\u4E1C\u897F \u2014 \u9AD8\u5EA6\u4E24\u6781\u5206\u5316\u7684\u7535\u5F71\u8BC4\u8BBA!"),Q_.forEach(t),Lt=d(e),ds=p(e,"H2",{id:!0});var X_=_(ds);Na=l(X_,"\u6570\u636E\u96C6"),X_.forEach(t),it=d(e),fs=p(e,"P",{});var ql=_(fs);Ia=l(ql,"\u4E3A\u4E86\u5C55\u793A\u57DF\u9002\u914D, \u6211\u4EEC\u5C06\u4F7F\u7528\u8457\u540D\u7684"),us=p(ql,"A",{href:!0,rel:!0});var Z_=_(us);Ga=l(Z_,"\u5927\u578B\u7535\u5F71\u8BC4\u8BBA\u6570\u636E\u96C6(Large Movie Review Dataset)"),Z_.forEach(t),dt=l(ql," (\u6216\u8005\u7B80\u79F0\u4E3AIMDb), \u8FD9\u662F\u4E00\u4E2A\u7535\u5F71\u8BC4\u8BBA\u8BED\u6599\u5E93, \u901A\u5E38\u7528\u4E8E\u5BF9\u60C5\u611F\u5206\u6790\u6A21\u578B\u8FDB\u884C\u57FA\u51C6\u6D4B\u8BD5\u3002\u901A\u8FC7\u5728\u8FD9\u4E2A\u8BED\u6599\u5E93\u4E0A\u5BF9 DistilBERT \u8FDB\u884C\u5FAE\u8C03, \u6211\u4EEC\u9884\u8BA1\u8BED\u8A00\u6A21\u578B\u5C06\u6839\u636E\u7EF4\u57FA\u767E\u79D1\u7684\u4E8B\u5B9E\u6570\u636E\u8C03\u6574\u5176\u8BCD\u6C47\u8868, \u8FD9\u4E9B\u6570\u636E\u5DF2\u7ECF\u9884\u5148\u8BAD\u7EC3\u5230\u7535\u5F71\u8BC4\u8BBA\u4E2D\u66F4\u4E3B\u89C2\u7684\u5143\u7D20\u3002\u6211\u4EEC\u53EF\u4EE5\u4F7F\u7528\u{1F917} Datasets\u4E2D\u7684"),ut=p(ql,"CODE",{});var ec=_(ut);Ua=l(ec,"load_dataset()"),ec.forEach(t),Wa=l(ql,"\u51FD\u6570\u4ECEHugging Face \u4E2D\u83B7\u53D6\u6570\u636E:"),ql.forEach(t),pt=d(e),y(Is.$$.fragment,e),Bt=d(e),y(Gs.$$.fragment,e),Nr=d(e),Xe=p(e,"P",{});var ws=_(Xe);Po=l(ws,"\u6211\u4EEC\u53EF\u4EE5\u770B\u5230 "),Kl=p(ws,"CODE",{});var sc=_(Kl);So=l(sc,"train"),sc.forEach(t),Oo=l(ws," \u548C "),Rl=p(ws,"CODE",{});var tc=_(Rl);Ko=l(tc,"test"),tc.forEach(t),Ro=l(ws," \u6BCF\u4E2A\u62C6\u5206\u5305\u542B 25,000 \u6761\u8BC4\u8BBA, \u800C\u6709\u4E00\u4E2A\u672A\u6807\u8BB0\u7684\u62C6\u5206\u79F0\u4E3A "),Ll=p(ws,"CODE",{});var ac=_(Ll);Lo=l(ac,"unsupervised"),ac.forEach(t),Bo=l(ws," \u5305\u542B 50,000 \u6761\u8BC4\u8BBA\u3002\u8BA9\u6211\u4EEC\u770B\u4E00\u4E9B\u793A\u4F8B, \u4EE5\u4E86\u89E3\u6211\u4EEC\u6B63\u5728\u5904\u7406\u7684\u6587\u672C\u7C7B\u578B\u3002\u6B63\u5982\u6211\u4EEC\u5728\u672C\u8BFE\u7A0B\u7684\u524D\u51E0\u7AE0\u4E2D\u6240\u505A\u7684\u90A3\u6837, \u6211\u4EEC\u5C06\u94FE\u63A5 "),Bl=p(ws,"CODE",{});var lc=_(Bl);Ho=l(lc,"Dataset.shuffle()"),lc.forEach(t),Fo=l(ws," \u548C "),Hl=p(ws,"CODE",{});var rc=_(Hl);No=l(rc,"Dataset.select()"),rc.forEach(t),Io=l(ws," \u51FD\u6570\u521B\u5EFA\u968F\u673A\u6837\u672C:"),ws.forEach(t),Ir=d(e),y(Ht.$$.fragment,e),Gr=d(e),y(Ft.$$.fragment,e),Ur=d(e),Us=p(e,"P",{});var Ml=_(Us);Go=l(Ml,"\u662F\u7684, \u8FD9\u4E9B\u80AF\u5B9A\u662F\u7535\u5F71\u8BC4\u8BBA, \u5982\u679C\u4F60\u5E74\u9F84\u8DB3\u591F,\u4F60\u751A\u81F3\u53EF\u80FD\u4F1A\u7406\u89E3\u4E0A\u6B21\u8BC4\u8BBA\u4E2D\u5173\u4E8E\u62E5\u6709 VHS \u7248\u672C\u7684\u8BC4\u8BBA\u{1F61C}! \u867D\u7136\u6211\u4EEC\u4E0D\u9700\u8981\u8BED\u8A00\u5EFA\u6A21\u7684\u6807\u7B7E, \u4F46\u6211\u4EEC\u5DF2\u7ECF\u53EF\u4EE5\u770B\u5230 "),Fl=p(Ml,"CODE",{});var nc=_(Fl);Uo=l(nc,"0"),nc.forEach(t),Wo=l(Ml," \u8868\u793A\u8D1F\u9762\u8BC4\u8BBA, \u800C "),Nl=p(Ml,"CODE",{});var oc=_(Nl);Yo=l(oc,"1"),oc.forEach(t),Vo=l(Ml," \u5BF9\u5E94\u6B63\u9762\u3002"),Ml.forEach(t),Wr=d(e),y(ht.$$.fragment,e),Yr=d(e),gt=p(e,"P",{});var jo=_(gt);Jo=l(jo,"\u73B0\u5728\u6211\u4EEC\u5DF2\u7ECF\u5FEB\u901F\u6D4F\u89C8\u4E86\u6570\u636E, \u8BA9\u6211\u4EEC\u6DF1\u5165\u7814\u7A76\u4E3A\u63A9\u7801\u8BED\u8A00\u5EFA\u6A21\u505A\u51C6\u5907\u3002\u6B63\u5982\u6211\u4EEC\u5C06\u770B\u5230\u7684, \u4E0E\u6211\u4EEC\u5728"),Ya=p(jo,"A",{href:!0});var ic=_(Ya);Qo=l(ic,"\u7B2C\u4E09\u7AE0"),ic.forEach(t),Xo=l(jo,"\u4E2D\u770B\u5230\u7684\u5E8F\u5217\u5206\u7C7B\u4EFB\u52A1\u76F8\u6BD4, \u8FD8\u9700\u8981\u91C7\u53D6\u4E00\u4E9B\u989D\u5916\u7684\u6B65\u9AA4\u3002\u8BA9\u6211\u4EEC\u7EE7\u7EED!"),jo.forEach(t),Vr=d(e),Nt=p(e,"H2",{id:!0});var pc=_(Nt);Zo=l(pc,"\u9884\u5904\u7406\u6570\u636E"),pc.forEach(t),Jr=d(e),y(It.$$.fragment,e),Qr=d(e),Va=p(e,"P",{});var _c=_(Va);ei=l(_c,"\u5BF9\u4E8E\u81EA\u56DE\u5F52\u548C\u63A9\u7801\u8BED\u8A00\u5EFA\u6A21, \u4E00\u4E2A\u5E38\u89C1\u7684\u9884\u5904\u7406\u6B65\u9AA4\u662F\u8FDE\u63A5\u6240\u6709\u793A\u4F8B, \u7136\u540E\u5C06\u6574\u4E2A\u8BED\u6599\u5E93\u62C6\u5206\u4E3A\u76F8\u540C\u5927\u5C0F\u7684\u5757\u3002 \u8FD9\u4E0E\u6211\u4EEC\u901A\u5E38\u7684\u65B9\u6CD5\u5B8C\u5168\u4E0D\u540C, \u6211\u4EEC\u53EA\u662F\u7B80\u5355\u5730\u6807\u8BB0\u5355\u4E2A\u793A\u4F8B\u3002\u4E3A\u4EC0\u4E48\u8981\u5C06\u6240\u6709\u5185\u5BB9\u8FDE\u63A5\u5728\u4E00\u8D77? \u539F\u56E0\u662F\u5355\u4E2A\u793A\u4F8B\u5982\u679C\u592A\u957F\u53EF\u80FD\u4F1A\u88AB\u622A\u65AD, \u8FD9\u5C06\u5BFC\u81F4\u4E22\u5931\u53EF\u80FD\u5BF9\u8BED\u8A00\u5EFA\u6A21\u4EFB\u52A1\u6709\u7528\u7684\u4FE1\u606F!"),_c.forEach(t),Xr=d(e),Ze=p(e,"P",{});var vs=_(Ze);si=l(vs,"\u56E0\u6B64, \u6211\u4EEC\u5C06\u50CF\u5F80\u5E38\u4E00\u6837\u9996\u5148\u6807\u8BB0\u6211\u4EEC\u7684\u8BED\u6599\u5E93, \u4F46\u662F "),Il=p(vs,"EM",{});var cc=_(Il);ti=l(cc,"\u6CA1\u6709"),cc.forEach(t),ai=l(vs," \u5728\u6211\u4EEC\u7684\u6807\u8BB0\u5668\u4E2D\u8BBE\u7F6E "),Gl=p(vs,"CODE",{});var mc=_(Gl);li=l(mc,"truncation=True"),mc.forEach(t),ri=l(vs," \u9009\u9879\u3002 \u6211\u4EEC\u8FD8\u5C06\u83B7\u53D6\u53EF\u7528\u7684\u5355\u8BCD ID ((\u5982\u679C\u6211\u4EEC\u4F7F\u7528\u5FEB\u901F\u6807\u8BB0\u5668, \u5B83\u4EEC\u662F\u53EF\u7528\u7684, \u5982 "),Ja=p(vs,"A",{href:!0});var fc=_(Ja);ni=l(fc,"\u7B2C\u516D\u7AE0"),fc.forEach(t),oi=l(vs,"\u4E2D\u6240\u8FF0), \u56E0\u4E3A\u6211\u4EEC\u7A0D\u540E\u5C06\u9700\u8981\u5B83\u4EEC\u6765\u8FDB\u884C\u5168\u5B57\u5C4F\u853D\u3002\u6211\u4EEC\u5C06\u628A\u5B83\u5305\u88C5\u5728\u4E00\u4E2A\u7B80\u5355\u7684\u51FD\u6570\u4E2D, \u5F53\u6211\u4EEC\u5728\u505A\u7684\u65F6\u5019, \u6211\u4EEC\u5C06\u5220\u9664 "),Ul=p(vs,"CODE",{});var dc=_(Ul);ii=l(dc,"text"),dc.forEach(t),pi=l(vs," \u548C "),Wl=p(vs,"CODE",{});var uc=_(Wl);_i=l(uc,"label"),uc.forEach(t),ci=l(vs," \u5217, \u56E0\u4E3A\u6211\u4EEC\u4E0D\u518D\u9700\u8981\u5B83\u4EEC:"),vs.forEach(t),Zr=d(e),y(Gt.$$.fragment,e),en=d(e),y(Ut.$$.fragment,e),sn=d(e),hs=p(e,"P",{});var zt=_(hs);mi=l(zt,"\u7531\u4E8E DistilBERT \u662F\u4E00\u4E2A\u7C7B\u4F3C BERT \u7684\u6A21\u578B, \u6211\u4EEC\u53EF\u4EE5\u770B\u5230\u7F16\u7801\u6587\u672C\u7531\u6211\u4EEC\u5728\u5176\u4ED6\u7AE0\u8282\u4E2D\u770B\u5230\u7684 "),Yl=p(zt,"CODE",{});var hc=_(Yl);fi=l(hc,"input_ids"),hc.forEach(t),di=l(zt," \u548C "),Vl=p(zt,"CODE",{});var gc=_(Vl);ui=l(gc,"attention_mask"),gc.forEach(t),hi=l(zt," \u7EC4\u6210, \u4EE5\u53CA\u6211\u4EEC\u6DFB\u52A0\u7684 "),Jl=p(zt,"CODE",{});var bc=_(Jl);gi=l(bc,"word_ids"),bc.forEach(t),bi=l(zt,"\u3002"),zt.forEach(t),tn=d(e),bt=p(e,"P",{});var yo=_(bt);ki=l(yo,"\u73B0\u5728\u6211\u4EEC\u5DF2\u7ECF\u6807\u8BB0\u4E86\u6211\u4EEC\u7684\u7535\u5F71\u8BC4\u8BBA, \u4E0B\u4E00\u6B65\u662F\u5C06\u5B83\u4EEC\u7EC4\u5408\u5728\u4E00\u8D77\u5E76\u5C06\u7ED3\u679C\u5206\u6210\u5757\u3002 \u4F46\u662F\u8FD9\u4E9B\u5757\u5E94\u8BE5\u6709\u591A\u5927? \u8FD9\u6700\u7EC8\u5C06\u53D6\u51B3\u4E8E\u4F60\u53EF\u7528\u7684 GPU \u5185\u5B58\u91CF, \u4F46\u4E00\u4E2A\u597D\u7684\u8D77\u70B9\u662F\u67E5\u770B\u6A21\u578B\u7684\u6700\u5927\u4E0A\u4E0B\u6587\u5927\u5C0F\u662F\u591A\u5C11\u3002\u8FD9\u53EF\u4EE5\u901A\u8FC7\u68C0\u67E5\u6807\u8BB0\u5668\u7684 "),Ql=p(yo,"CODE",{});var kc=_(Ql);$i=l(kc,"model_max_length"),kc.forEach(t),wi=l(yo," \u5C5E\u6027\u6765\u5224\u65AD:"),yo.forEach(t),an=d(e),y(Wt.$$.fragment,e),ln=d(e),y(Yt.$$.fragment,e),rn=d(e),kt=p(e,"P",{});var Eo=_(kt);vi=l(Eo,"\u8BE5\u503C\u6765\u81EA\u4E8E\u4E0E\u68C0\u67E5\u70B9\u76F8\u5173\u8054\u7684 "),Xl=p(Eo,"EM",{});var $c=_(Xl);ji=l($c,"tokenizer_config.json"),$c.forEach(t),yi=l(Eo," \u6587\u4EF6; \u5728\u8FD9\u79CD\u60C5\u51B5\u4E0B, \u6211\u4EEC\u53EF\u4EE5\u770B\u5230\u4E0A\u4E0B\u6587\u5927\u5C0F\u662F 512 \u4E2A\u6807\u8BB0, \u5C31\u50CF BERT \u4E00\u6837\u3002"),Eo.forEach(t),nn=d(e),y($t.$$.fragment,e),on=d(e),Qa=p(e,"P",{});var wc=_(Qa);Ei=l(wc,"\u56E0\u6B64, \u4EE5\u4FBF\u5728\u50CFGoogle Colab \u90A3\u6837\u7684 GPU \u4E0A\u8FD0\u884C\u6211\u4EEC\u7684\u5B9E\u9A8C, \u6211\u4EEC\u5C06\u9009\u62E9\u53EF\u4EE5\u653E\u5165\u5185\u5B58\u7684\u66F4\u5C0F\u4E00\u4E9B\u7684\u4E1C\u897F:"),wc.forEach(t),pn=d(e),y(Vt.$$.fragment,e),_n=d(e),y(wt.$$.fragment,e),cn=d(e),Xa=p(e,"P",{});var vc=_(Xa);xi=l(vc,"\u6709\u8DA3\u7684\u6765\u4E86\u3002\u4E3A\u4E86\u5C55\u793A\u4E32\u8054\u662F\u5982\u4F55\u5DE5\u4F5C\u7684, \u8BA9\u6211\u4EEC\u4ECE\u6211\u4EEC\u7684\u6807\u8BB0\u5316\u8BAD\u7EC3\u96C6\u4E2D\u53D6\u4E00\u4E9B\u8BC4\u8BBA\u5E76\u6253\u5370\u51FA\u6BCF\u4E2A\u8BC4\u8BBA\u7684\u6807\u8BB0\u6570\u91CF:"),vc.forEach(t),mn=d(e),y(Jt.$$.fragment,e),fn=d(e),y(Qt.$$.fragment,e),dn=d(e),Za=p(e,"P",{});var jc=_(Za);Di=l(jc,"\u7136\u540E\u6211\u4EEC\u53EF\u4EE5\u7528\u4E00\u4E2A\u7B80\u5355\u7684\u5B57\u5178\u7406\u89E3\u6765\u8FDE\u63A5\u6240\u6709\u4F8B\u5B50, \u5982\u4E0B\u6240\u793A:"),jc.forEach(t),un=d(e),y(Xt.$$.fragment,e),hn=d(e),y(Zt.$$.fragment,e),gn=d(e),Ws=p(e,"P",{});var Tl=_(Ws);qi=l(Tl,"\u5F88\u68D2, \u603B\u957F\u5EA6\u68C0\u67E5\u51FA\u6765\u4E86 \u2014 \u73B0\u5728, \u8BA9\u6211\u4EEC\u5C06\u8FDE\u63A5\u7684\u8BC4\u8BBA\u62C6\u5206\u4E3A\u5927\u5C0F\u4E3A "),Zl=p(Tl,"CODE",{});var yc=_(Zl);Mi=l(yc,"block_size"),yc.forEach(t),Ti=l(Tl," \u7684\u5757\u3002\u4E3A\u6B64, \u6211\u4EEC\u8FED\u4EE3\u4E86 "),er=p(Tl,"CODE",{});var Ec=_(er);zi=l(Ec,"concatenated_examples"),Ec.forEach(t),Ai=l(Tl," \u4E2D\u7684\u7279\u5F81, \u5E76\u4F7F\u7528\u5217\u8868\u7406\u89E3\u6765\u521B\u5EFA\u6BCF\u4E2A\u7279\u5F81\u7684\u5207\u7247\u3002\u7ED3\u679C\u662F\u6BCF\u4E2A\u7279\u5F81\u7684\u5757\u5B57\u5178:"),Tl.forEach(t),bn=d(e),y(ea.$$.fragment,e),kn=d(e),y(sa.$$.fragment,e),$n=d(e),el=p(e,"P",{});var xc=_(el);Ci=l(xc,"\u6B63\u5982\u4F60\u5728\u8FD9\u4E2A\u4F8B\u5B50\u4E2D\u770B\u5230\u7684, \u6700\u540E\u4E00\u4E2A\u5757\u901A\u5E38\u4F1A\u5C0F\u4E8E\u6700\u5927\u5757\u5927\u5C0F\u3002\u6709\u4E24\u79CD\u4E3B\u8981\u7684\u7B56\u7565\u6765\u5904\u7406\u8FD9\u4E2A\u95EE\u9898:"),xc.forEach(t),wn=d(e),vt=p(e,"UL",{});var xo=_(vt);ta=p(xo,"LI",{});var Do=_(ta);Pi=l(Do,"\u5982\u679C\u6700\u540E\u4E00\u4E2A\u5757\u5C0F\u4E8E "),sr=p(Do,"CODE",{});var Dc=_(sr);Si=l(Dc,"chunk_size"),Dc.forEach(t),Oi=l(Do,", \u8BF7\u5220\u9664\u5B83\u3002"),Do.forEach(t),Ki=d(xo),aa=p(xo,"LI",{});var qo=_(aa);Ri=l(qo,"\u586B\u5145\u6700\u540E\u4E00\u4E2A\u5757, \u76F4\u5230\u5176\u957F\u5EA6\u7B49\u4E8E "),tr=p(qo,"CODE",{});var qc=_(tr);Li=l(qc,"chunk_size"),qc.forEach(t),Bi=l(qo,"\u3002"),qo.forEach(t),xo.forEach(t),vn=d(e),sl=p(e,"P",{});var Mc=_(sl);Hi=l(Mc,"\u6211\u4EEC\u5C06\u5728\u8FD9\u91CC\u91C7\u7528\u7B2C\u4E00\u79CD\u65B9\u6CD5, \u56E0\u6B64\u8BA9\u6211\u4EEC\u5C06\u4E0A\u8FF0\u6240\u6709\u903B\u8F91\u5305\u88C5\u5728\u4E00\u4E2A\u51FD\u6570\u4E2D, \u6211\u4EEC\u53EF\u4EE5\u5C06\u5176\u5E94\u7528\u4E8E\u6211\u4EEC\u7684\u6807\u8BB0\u5316\u6570\u636E\u96C6:"),Mc.forEach(t),jn=d(e),y(la.$$.fragment,e),yn=d(e),is=p(e,"P",{});var tt=_(is);Fi=l(tt,"\u6CE8\u610F, \u5728 "),ar=p(tt,"CODE",{});var Tc=_(ar);Ni=l(Tc,"group_texts()"),Tc.forEach(t),Ii=l(tt," \u7684\u6700\u540E\u4E00\u6B65\u4E2D, \u6211\u4EEC\u521B\u5EFA\u4E86\u4E00\u4E2A\u65B0\u7684 "),lr=p(tt,"CODE",{});var zc=_(lr);Gi=l(zc,"labels"),zc.forEach(t),Ui=l(tt," \u5217, \u5B83\u662F "),rr=p(tt,"CODE",{});var Ac=_(rr);Wi=l(Ac,"input_ids"),Ac.forEach(t),Yi=l(tt," \u5217\u7684\u526F\u672C\u3002\u6211\u4EEC\u5F88\u5FEB\u5C31\u4F1A\u770B\u5230, \u8FD9\u662F\u56E0\u4E3A\u5728\u63A9\u7801\u8BED\u8A00\u5EFA\u6A21\u4E2D, \u76EE\u6807\u662F\u9884\u6D4B\u8F93\u5165\u6279\u6B21\u4E2D\u968F\u673A\u63A9\u7801\u7684\u6807\u8BB0, \u5E76\u901A\u8FC7\u521B\u5EFA\u4E00\u4E2A "),nr=p(tt,"CODE",{});var Cc=_(nr);Vi=l(Cc,"labels"),Cc.forEach(t),Ji=l(tt," \u5217, \u4EEC\u4E3A\u6211\u4EEC\u7684\u8BED\u8A00\u6A21\u578B\u63D0\u4F9B\u4E86\u57FA\u7840\u4E8B\u5B9E\u4EE5\u4F9B\u5B66\u4E60\u3002"),tt.forEach(t),En=d(e),Ys=p(e,"P",{});var zl=_(Ys);Qi=l(zl,"\u73B0\u5728, \u8BA9\u6211\u4EEC\u4F7F\u7528\u6211\u4EEC\u53EF\u4FE1\u8D56\u7684 "),or=p(zl,"CODE",{});var Pc=_(or);Xi=l(Pc,"Dataset.map()"),Pc.forEach(t),Zi=l(zl," \u51FD\u6570\u5C06 "),ir=p(zl,"CODE",{});var Sc=_(ir);ep=l(Sc,"group_texts()"),Sc.forEach(t),sp=l(zl," \u5E94\u7528\u5230\u6211\u4EEC\u7684\u6807\u8BB0\u5316\u6570\u636E\u96C6:"),zl.forEach(t),xn=d(e),y(ra.$$.fragment,e),Dn=d(e),y(na.$$.fragment,e),qn=d(e),es=p(e,"P",{});var js=_(es);tp=l(js,"\u4F60\u53EF\u4EE5\u770B\u5230, \u5BF9\u6587\u672C\u8FDB\u884C\u5206\u7EC4, \u7136\u540E\u5BF9\u6587\u672C\u8FDB\u884C\u5206\u5757, \u4EA7\u751F\u7684\u793A\u4F8B\u6BD4\u6211\u4EEC\u6700\u521D\u7684 25,000 \u7528\u4E8E "),pr=p(js,"CODE",{});var Oc=_(pr);ap=l(Oc,"train"),Oc.forEach(t),lp=l(js,"\u548C "),_r=p(js,"CODE",{});var Kc=_(_r);rp=l(Kc,"test"),Kc.forEach(t),np=l(js," \u62C6\u5206\u7684\u793A\u4F8B\u591A\u5F97\u591A\u3002\u90A3\u662F\u56E0\u4E3A\u6211\u4EEC\u73B0\u5728\u6709\u4E86\u6D89\u53CA "),cr=p(js,"EM",{});var Rc=_(cr);op=l(Rc,"\u8FDE\u7EED\u6807\u8BB0"),Rc.forEach(t),ip=l(js," \u7684\u793A\u4F8B, \u8FD9\u4E9B\u793A\u4F8B\u8DE8\u8D8A\u4E86\u539F\u59CB\u8BED\u6599\u5E93\u4E2D\u7684\u591A\u4E2A\u793A\u4F8B\u3002\u4F60\u53EF\u4EE5\u901A\u8FC7\u5728\u5176\u4E2D\u4E00\u4E2A\u5757\u4E2D\u67E5\u627E\u7279\u6B8A\u7684 "),mr=p(js,"CODE",{});var Lc=_(mr);pp=l(Lc,"[SEP]"),Lc.forEach(t),_p=l(js," \u548C "),fr=p(js,"CODE",{});var Bc=_(fr);cp=l(Bc,"[CLS]"),Bc.forEach(t),mp=l(js," \u6807\u8BB0\u6765\u660E\u786E\u7684\u770B\u5230\u8FD9\u4E00\u70B9:"),js.forEach(t),Mn=d(e),y(oa.$$.fragment,e),Tn=d(e),y(ia.$$.fragment,e),zn=d(e),tl=p(e,"P",{});var Hc=_(tl);fp=l(Hc,"\u5728\u6B64\u793A\u4F8B\u4E2D, \u4F60\u53EF\u4EE5\u770B\u5230\u4E24\u7BC7\u91CD\u53E0\u7684\u7535\u5F71\u8BC4\u8BBA, \u4E00\u7BC7\u5173\u4E8E\u9AD8\u4E2D\u7535\u5F71, \u53E6\u4E00\u7BC7\u5173\u4E8E\u65E0\u5BB6\u53EF\u5F52\u3002 \u8BA9\u6211\u4EEC\u4E5F\u770B\u770B\u63A9\u7801\u8BED\u8A00\u5EFA\u6A21\u7684\u6807\u7B7E\u662F\u4EC0\u4E48\u6837\u7684:"),Hc.forEach(t),An=d(e),y(pa.$$.fragment,e),Cn=d(e),y(_a.$$.fragment,e),Pn=d(e),gs=p(e,"P",{});var At=_(gs);dp=l(At,"\u6B63\u5982\u524D\u9762\u7684 "),dr=p(At,"CODE",{});var Fc=_(dr);up=l(Fc,"group_texts()"),Fc.forEach(t),hp=l(At," \u51FD\u6570\u6240\u671F\u671B\u7684\u90A3\u6837, \u8FD9\u770B\u8D77\u6765\u4E0E\u89E3\u7801\u540E\u7684 "),ur=p(At,"CODE",{});var Nc=_(ur);gp=l(Nc,"input_ids"),Nc.forEach(t),bp=l(At," \u76F8\u540C \u2014 \u4F46\u662F\u6211\u4EEC\u7684\u6A21\u578B\u600E\u4E48\u53EF\u80FD\u5B66\u5230\u4EFB\u4F55\u4E1C\u897F\u5462? \u6211\u4EEC\u9519\u8FC7\u4E86\u4E00\u4E2A\u5173\u952E\u6B65\u9AA4: \u5728\u8F93\u5165\u4E2D\u7684\u968F\u673A\u4F4D\u7F6E\u63D2\u5165 "),hr=p(At,"CODE",{});var Ic=_(hr);kp=l(Ic,"[MASK]"),Ic.forEach(t),$p=l(At," \u6807\u8BB0! \u8BA9\u6211\u4EEC\u770B\u770B\u5982\u4F55\u4F7F\u7528\u7279\u6B8A\u7684\u6570\u636E\u6574\u7406\u5668\u5728\u5FAE\u8C03\u671F\u95F4\u5373\u65F6\u6267\u884C\u6B64\u64CD\u4F5C\u3002"),At.forEach(t),Sn=d(e),_t=p(e,"H2",{class:!0});var Mo=_(_t);jt=p(Mo,"A",{id:!0,class:!0,href:!0});var Gc=_(jt);gr=p(Gc,"SPAN",{});var Uc=_(gr);y(ca.$$.fragment,Uc),Uc.forEach(t),Gc.forEach(t),wp=d(Mo),ma=p(Mo,"SPAN",{});var To=_(ma);vp=l(To,"\u4F7F\u7528 "),br=p(To,"CODE",{});var Wc=_(br);jp=l(Wc,"Trainer"),Wc.forEach(t),yp=l(To," API \u5FAE\u8C03DistilBERT"),To.forEach(t),Mo.forEach(t),On=d(e),bs=p(e,"P",{});var Ct=_(bs);Ep=l(Ct,"\u5FAE\u8C03\u5C4F\u853D\u8BED\u8A00\u6A21\u578B\u51E0\u4E4E\u4E0E\u5FAE\u8C03\u5E8F\u5217\u5206\u7C7B\u6A21\u578B\u76F8\u540C, \u5C31\u50CF\u6211\u4EEC\u5728 "),al=p(Ct,"A",{href:!0});var Yc=_(al);xp=l(Yc,"\u7B2C\u4E09\u7AE0"),Yc.forEach(t),Dp=l(Ct,"\u6240\u4F5C\u7684\u90A3\u6837\u3002 \u552F\u4E00\u7684\u533A\u522B\u662F\u6211\u4EEC\u9700\u8981\u4E00\u4E2A\u7279\u6B8A\u7684\u6570\u636E\u6574\u7406\u5668, \u5B83\u53EF\u4EE5\u968F\u673A\u5C4F\u853D\u6BCF\u6279\u6587\u672C\u4E2D\u7684\u4E00\u4E9B\u6807\u8BB0\u3002\u5E78\u8FD0\u7684\u662F, \u{1F917} Transformers \u4E3A\u8FD9\u9879\u4EFB\u52A1\u51C6\u5907\u4E86\u4E13\u7528\u7684 "),kr=p(Ct,"CODE",{});var Vc=_(kr);qp=l(Vc,"DataCollatorForLanguageModeling"),Vc.forEach(t),Mp=l(Ct," \u3002\u6211\u4EEC\u53EA\u9700\u8981\u5C06\u5B83\u8F6C\u9012\u7ED9\u6807\u8BB0\u5668\u548C\u4E00\u4E2A "),$r=p(Ct,"CODE",{});var Jc=_($r);Tp=l(Jc,"mlm_probability"),Jc.forEach(t),zp=l(Ct," \u53C2\u6570, \u8BE5\u53C2\u6570\u6307\u5B9A\u8981\u5C4F\u853D\u7684\u6807\u8BB0\u7684\u5206\u6570\u3002\u6211\u4EEC\u5C06\u9009\u62E9 15%, \u8FD9\u662F BERT \u4F7F\u7528\u7684\u6570\u91CF\u4E5F\u662F\u6587\u732E\u4E2D\u7684\u5E38\u89C1\u9009\u62E9:"),Ct.forEach(t),Kn=d(e),y(fa.$$.fragment,e),Rn=d(e),ks=p(e,"P",{});var Pt=_(ks);Ap=l(Pt,"\u8981\u4E86\u89E3\u968F\u673A\u63A9\u7801\u7684\u5DE5\u4F5C\u539F\u7406, \u8BA9\u6211\u4EEC\u5411\u6570\u636E\u6574\u7406\u5668\u63D0\u4F9B\u4E00\u4E9B\u793A\u4F8B\u3002\u7531\u4E8E\u5B83\u9700\u8981\u4E00\u4E2A "),wr=p(Pt,"CODE",{});var Qc=_(wr);Cp=l(Qc,"dict"),Qc.forEach(t),Pp=l(Pt," \u7684\u5217\u8868, \u5176\u4E2D\u6BCF\u4E2A "),vr=p(Pt,"CODE",{});var Xc=_(vr);Sp=l(Xc,"dict"),Xc.forEach(t),Op=l(Pt," \u8868\u793A\u5355\u4E2A\u8FDE\u7EED\u6587\u672C\u5757, \u6211\u4EEC\u9996\u5148\u8FED\u4EE3\u6570\u636E\u96C6, \u7136\u540E\u518D\u5C06\u6279\u6B21\u63D0\u4F9B\u7ED9\u6574\u7406\u5668\u3002\u6211\u4EEC\u5220\u9664\u4E86\u8FD9\u4E2A\u6570\u636E\u6574\u7406\u5668\u7684 "),jr=p(Pt,"CODE",{});var Zc=_(jr);Kp=l(Zc,'"word_ids"'),Zc.forEach(t),Rp=l(Pt," \u952E, \u56E0\u4E3A\u5B83\u4E0D\u9700\u8981\u5B83:"),Pt.forEach(t),Ln=d(e),y(da.$$.fragment,e),Bn=d(e),y(ua.$$.fragment,e),Hn=d(e),Vs=p(e,"P",{});var Al=_(Vs);Lp=l(Al,"\u5F88\u68D2, \u6210\u529F\u4E86! \u6211\u4EEC\u53EF\u4EE5\u770B\u5230, "),yr=p(Al,"CODE",{});var em=_(yr);Bp=l(em,"[MASK]"),em.forEach(t),Hp=l(Al," \u6807\u8BB0\u5DF2\u968F\u673A\u63D2\u5165\u6211\u4EEC\u6587\u672C\u4E2D\u7684\u4E0D\u540C\u4F4D\u7F6E\u3002 \u8FD9\u4E9B\u5C06\u662F\u6211\u4EEC\u7684\u6A21\u578B\u5728\u8BAD\u7EC3\u671F\u95F4\u5FC5\u987B\u9884\u6D4B\u7684\u6807\u8BB0 \u2014 \u6570\u636E\u6574\u7406\u5668\u7684\u7F8E\u5999\u4E4B\u5904\u5728\u4E8E, \u5B83\u5C06\u968F\u673A\u5316\u6BCF\u4E2A\u6279\u6B21\u7684 "),Er=p(Al,"CODE",{});var sm=_(Er);Fp=l(sm,"[MASK]"),sm.forEach(t),Np=l(Al," \u63D2\u5165!"),Al.forEach(t),Fn=d(e),y(yt.$$.fragment,e),Nn=d(e),as&&as.l(e),ll=d(e),Js=p(e,"P",{});var Cl=_(Js);Ip=l(Cl,"\u5728\u4E3A\u63A9\u7801\u8BED\u8A00\u5EFA\u6A21\u8BAD\u7EC3\u6A21\u578B\u65F6, \u53EF\u4EE5\u4F7F\u7528\u7684\u4E00\u79CD\u6280\u672F\u662F\u5C06\u6574\u4E2A\u5355\u8BCD\u4E00\u8D77\u5C4F\u853D, \u800C\u4E0D\u4EC5\u4EC5\u662F\u5355\u4E2A\u6807\u8BB0\u3002\u8FD9\u79CD\u65B9\u6CD5\u79F0\u4E3A "),xr=p(Cl,"EM",{});var tm=_(xr);Gp=l(tm,"\u5168\u8BCD\u5C4F\u853D"),tm.forEach(t),Up=l(Cl,"\u3002 \u5982\u679C\u6211\u4EEC\u60F3\u4F7F\u7528\u5168\u8BCD\u5C4F\u853D, \u6211\u4EEC\u9700\u8981\u81EA\u5DF1\u6784\u5EFA\u4E00\u4E2A\u6570\u636E\u6574\u7406\u5668\u3002\u6570\u636E\u6574\u7406\u5668\u53EA\u662F\u4E00\u4E2A\u51FD\u6570, \u5B83\u63A5\u53D7\u4E00\u4E2A\u6837\u672C\u5217\u8868\u5E76\u5C06\u5B83\u4EEC\u8F6C\u6362\u4E3A\u4E00\u4E2A\u6279\u6B21, \u6240\u4EE5\u73B0\u5728\u8BA9\u6211\u4EEC\u8FD9\u6837\u505A\u5427! \u6211\u4EEC\u5C06\u4F7F\u7528\u4E4B\u524D\u8BA1\u7B97\u7684\u5355\u8BCD ID \u5728\u5355\u8BCD\u7D22\u5F15\u548C\u76F8\u5E94\u6807\u8BB0\u4E4B\u95F4\u8FDB\u884C\u6620\u5C04, \u7136\u540E\u968F\u673A\u51B3\u5B9A\u8981\u5C4F\u853D\u54EA\u4E9B\u5355\u8BCD\u5E76\u5C06\u8BE5\u5C4F\u853D\u5E94\u7528\u4E8E\u8F93\u5165\u3002\u8BF7\u6CE8\u610F, \u9664\u4E86\u4E0E\u63A9\u7801\u5BF9\u5E94\u7684\u6807\u7B7E\u5916, \u6240\u6709\u7684\u6807\u7B7E\u5747\u4E3A "),Dr=p(Cl,"CODE",{});var am=_(Dr);Wp=l(am,"-100"),am.forEach(t),Yp=l(Cl,"\u3002"),Cl.forEach(t),In=d(e),zs.l(e),rl=d(e),nl=p(e,"P",{});var lm=_(nl);Vp=l(lm,"Next, we can try it on the same samples as before:"),lm.forEach(t),Gn=d(e),y(ha.$$.fragment,e),Un=d(e),y(ga.$$.fragment,e),Wn=d(e),y(Et.$$.fragment,e),Yn=d(e),Qs=p(e,"P",{});var Pl=_(Qs);Jp=l(Pl,"\u73B0\u5728\u6211\u4EEC\u6709\u4E24\u4E2A\u6570\u636E\u6574\u7406\u5668, \u5176\u4F59\u7684\u5FAE\u8C03\u6B65\u9AA4\u662F\u6807\u51C6\u7684\u3002\u5982\u679C\u60A8\u6CA1\u6709\u8DB3\u591F\u5E78\u8FD0\u5730\u83B7\u5F97\u795E\u8BDD\u822C\u7684 P100 GPU \u{1F62D}, \u5728 Google Colab \u4E0A\u8FDB\u884C\u8BAD\u7EC3\u53EF\u80FD\u9700\u8981\u4E00\u6BB5\u65F6\u95F4, \u56E0\u6B64\u6211\u4EEC\u5C06\u9996\u5148\u5C06\u8BAD\u7EC3\u96C6\u7684\u5927\u5C0F\u7F29\u51CF\u4E3A\u51E0\u5343\u4E2A\u793A\u4F8B\u3002\u522B\u62C5\u5FC3, \u6211\u4EEC\u4ECD\u7136\u4F1A\u5F97\u5230\u4E00\u4E2A\u76F8\u5F53\u4E0D\u9519\u7684\u8BED\u8A00\u6A21\u578B! \u5728 \u{1F917} Datasets \u4E2D\u5FEB\u901F\u4E0B\u91C7\u6837\u6570\u636E\u96C6\u7684\u65B9\u6CD5\u662F\u901A\u8FC7\u6211\u4EEC\u5728 "),ol=p(Pl,"A",{href:!0});var rm=_(ol);Qp=l(rm,"\u7B2C\u4E94\u7AE0"),rm.forEach(t),Xp=l(Pl," \u4E2D\u770B\u5230\u7684 "),qr=p(Pl,"CODE",{});var nm=_(qr);Zp=l(nm,"Dataset.train_test_split()"),nm.forEach(t),e_=l(Pl," \u51FD\u6570:"),Pl.forEach(t),Vn=d(e),y(ba.$$.fragment,e),Jn=d(e),y(ka.$$.fragment,e),Qn=d(e),Xs=p(e,"P",{});var Sl=_(Xs);s_=l(Sl,"\u8FD9\u4F1A\u81EA\u52A8\u521B\u5EFA\u65B0\u7684 "),Mr=p(Sl,"CODE",{});var om=_(Mr);t_=l(om,"train"),om.forEach(t),a_=l(Sl," \u548C "),Tr=p(Sl,"CODE",{});var im=_(Tr);l_=l(im,"test"),im.forEach(t),r_=l(Sl," \u62C6\u5206, \u8BAD\u7EC3\u96C6\u5927\u5C0F\u8BBE\u7F6E\u4E3A 10,000 \u4E2A\u793A\u4F8B, \u9A8C\u8BC1\u8BBE\u7F6E\u4E3A\u5176\u4E2D\u7684 10% \u2014 \u5982\u679C\u4F60\u6709\u4E00\u4E2A\u5F3A\u5927\u7684 GPU, \u53EF\u4EE5\u968F\u610F\u589E\u52A0\u5B83! \u6211\u4EEC\u9700\u8981\u505A\u7684\u4E0B\u4E00\u4EF6\u4E8B\u662F\u767B\u5F55 Hugging Face Hub\u3002\u5982\u679C\u4F60\u5728\u7B14\u8BB0\u672C\u4E2D\u8FD0\u884C\u6B64\u4EE3\u7801, \u5219\u53EF\u4EE5\u4F7F\u7528\u4EE5\u4E0B\u5B9E\u7528\u7A0B\u5E8F\u51FD\u6570\u6267\u884C\u6B64\u64CD\u4F5C:"),Sl.forEach(t),Xn=d(e),y($a.$$.fragment,e),Zn=d(e),il=p(e,"P",{});var pm=_(il);n_=l(pm,"\u8FD9\u5C06\u663E\u793A\u4E00\u4E2A\u5C0F\u90E8\u4EF6, \u4F60\u53EF\u4EE5\u5728\u5176\u4E2D\u8F93\u5165\u4F60\u7684\u51ED\u636E\u3002\u6216\u8005, \u4F60\u53EF\u4EE5\u8FD0\u884C:"),pm.forEach(t),eo=d(e),y(wa.$$.fragment,e),so=d(e),pl=p(e,"P",{});var _m=_(pl);o_=l(_m,"\u5728\u4F60\u6700\u559C\u6B22\u7684\u7EC8\u7AEF\u4E2D\u767B\u5F55\u3002"),_m.forEach(t),to=d(e),Cs.l(e),_l=d(e),ct=p(e,"H3",{class:!0});var zo=_(ct);xt=p(zo,"A",{id:!0,class:!0,href:!0});var cm=_(xt);zr=p(cm,"SPAN",{});var mm=_(zr);y(va.$$.fragment,mm),mm.forEach(t),cm.forEach(t),i_=d(zo),Ar=p(zo,"SPAN",{});var fm=_(Ar);p_=l(fm,"\u8BED\u8A00\u6A21\u578B\u7684perplexity"),fm.forEach(t),zo.forEach(t),ao=d(e),y(ja.$$.fragment,e),lo=d(e),cl=p(e,"P",{});var dm=_(cl);__=l(dm,"\u4E0E\u6587\u672C\u5206\u7C7B\u6216\u95EE\u7B54\u7B49\u5176\u4ED6\u4EFB\u52A1\u4E0D\u540C, \u5728\u8FD9\u4E9B\u4EFB\u52A1\u4E2D, \u6211\u4EEC\u4F1A\u5F97\u5230\u4E00\u4E2A\u5E26\u6807\u7B7E\u7684\u8BED\u6599\u5E93\u8FDB\u884C\u8BAD\u7EC3, \u800C\u8BED\u8A00\u5EFA\u6A21\u5219\u6CA1\u6709\u4EFB\u4F55\u660E\u786E\u7684\u6807\u7B7E\u3002\u90A3\u4E48\u6211\u4EEC\u5982\u4F55\u786E\u5B9A\u4EC0\u4E48\u662F\u597D\u7684\u8BED\u8A00\u6A21\u578B\u5462? \u5C31\u50CF\u624B\u673A\u4E2D\u7684\u81EA\u52A8\u66F4\u6B63\u529F\u80FD\u4E00\u6837, \u4E00\u4E2A\u597D\u7684\u8BED\u8A00\u6A21\u578B\u662F\u4E3A\u8BED\u6CD5\u6B63\u786E\u7684\u53E5\u5B50\u5206\u914D\u9AD8\u6982\u7387, \u4E3A\u65E0\u610F\u4E49\u7684\u53E5\u5B50\u5206\u914D\u4F4E\u6982\u7387\u3002\u4E3A\u4E86\u8BA9\u4F60\u66F4\u597D\u5730\u4E86\u89E3\u8FD9\u662F\u4EC0\u4E48\u6837\u5B50, \u60A8\u53EF\u4EE5\u5728\u7F51\u4E0A\u627E\u5230\u4E00\u6574\u5957 \u201Cautocorrect fails\u201D, \u5176\u4E2D\u4E00\u4E2A\u4EBA\u624B\u673A\u4E2D\u7684\u6A21\u578B\u4EA7\u751F\u4E86\u4E00\u4E9B\u76F8\u5F53\u6709\u8DA3 (\u800C\u4E14\u901A\u5E38\u4E0D\u5408\u9002) \u7684\u7ED3\u679C!"),dm.forEach(t),ro=d(e),Ss.l(e),ml=d(e),y(ya.$$.fragment,e),no=d(e),fl=p(e,"P",{});var um=_(fl);c_=l(um,"\u8F83\u4F4E\u7684perplexity\u5206\u6570\u610F\u5473\u7740\u66F4\u597D\u7684\u8BED\u8A00\u6A21\u578B, \u6211\u4EEC\u53EF\u4EE5\u5728\u8FD9\u91CC\u770B\u5230\u6211\u4EEC\u7684\u8D77\u59CB\u6A21\u578B\u6709\u4E00\u4E2A\u8F83\u5927\u7684\u503C\u3002\u770B\u770B\u6211\u4EEC\u80FD\u4E0D\u80FD\u901A\u8FC7\u5FAE\u8C03\u6765\u964D\u4F4E\u5B83! \u4E3A\u6B64, \u6211\u4EEC\u9996\u5148\u8FD0\u884C\u8BAD\u7EC3\u5FAA\u73AF:"),um.forEach(t),oo=d(e),Ks.l(e),dl=d(e),ul=p(e,"P",{});var hm=_(ul);m_=l(hm,"\u7136\u540E\u50CF\u4EE5\u524D\u4E00\u6837\u8BA1\u7B97\u6D4B\u8BD5\u96C6\u4E0A\u7684perplexity\u5EA6:"),hm.forEach(t),io=d(e),Ls.l(e),hl=d(e),y(Ea.$$.fragment,e),po=d(e),gl=p(e,"P",{});var gm=_(gl);f_=l(gm,"\u5F88\u597D \u2014 \u8FD9\u5927\u5927\u51CF\u5C11\u4E86\u56F0\u60D1, \u8FD9\u544A\u8BC9\u6211\u4EEC\u6A21\u578B\u5DF2\u7ECF\u4E86\u89E3\u4E86\u4E00\u4E9B\u5173\u4E8E\u7535\u5F71\u8BC4\u8BBA\u9886\u57DF\u7684\u77E5\u8BC6!"),gm.forEach(t),_o=d(e),Pe&&Pe.l(e),bl=d(e),y(Dt.$$.fragment,e),co=d(e),Se&&Se.l(e),kl=d(e),xa=p(e,"H2",{id:!0});var bm=_(xa);d_=l(bm,"\u4F7F\u7528\u6211\u4EEC\u5FAE\u8C03\u7684\u6A21\u578B"),bm.forEach(t),mo=d(e),Zs=p(e,"P",{});var Ol=_(Zs);u_=l(Ol,"\u4F60\u53EF\u4EE5\u901A\u8FC7\u5728Hub\u4E0A\u4F7F\u7528\u5176\u4ED6\u5C0F\u90E8\u4EF6\u6216\u5728\u672C\u5730\u4F7F\u7528\u{1F917} Transformers \u7684"),Cr=p(Ol,"CODE",{});var km=_(Cr);h_=l(km,"\u7BA1\u9053"),km.forEach(t),g_=l(Ol,"\u4E8E\u5FAE\u8C03\u6A21\u578B\u8FDB\u884C\u4EA4\u4E92\u3002\u8BA9\u6211\u4EEC\u4F7F\u7528\u540E\u8005\u6765\u4E0B\u8F7D\u6211\u4EEC\u7684\u6A21\u578B, \u4F7F\u7528 "),Pr=p(Ol,"CODE",{});var $m=_(Pr);b_=l($m,"fill-mask"),$m.forEach(t),k_=l(Ol," \u7BA1\u9053:"),Ol.forEach(t),fo=d(e),y(Da.$$.fragment,e),uo=d(e),$l=p(e,"P",{});var wm=_($l);$_=l(wm,"\u7136\u540E, \u6211\u4EEC\u53EF\u4EE5\u5411\u7BA1\u9053\u63D0\u4F9B \u201CThis is a great [MASK]\u201D \u793A\u4F8B\u6587\u672C, \u5E76\u67E5\u770B\u524D 5 \u4E2A\u9884\u6D4B\u662F\u4EC0\u4E48:"),wm.forEach(t),ho=d(e),y(qa.$$.fragment,e),go=d(e),y(Ma.$$.fragment,e),bo=d(e),wl=p(e,"P",{});var vm=_(wl);w_=l(vm,"\u597D\u7684 \u2014 \u6211\u4EEC\u7684\u6A21\u578B\u663E\u7136\u5DF2\u7ECF\u8C03\u6574\u4E86\u5B83\u7684\u6743\u91CD\u6765\u9884\u6D4B\u4E0E\u7535\u5F71\u66F4\u5BC6\u5207\u76F8\u5173\u7684\u8BCD!"),vm.forEach(t),ko=d(e),y(Ta.$$.fragment,e),$o=d(e),qt=p(e,"P",{});var Ao=_(qt);v_=l(Ao,"\u8FD9\u7ED3\u675F\u4E86\u6211\u4EEC\u8BAD\u7EC3\u8BED\u8A00\u6A21\u578B\u7684\u7B2C\u4E00\u4E2A\u5B9E\u9A8C\u3002\u5728 "),vl=p(Ao,"A",{href:!0});var jm=_(vl);j_=l(jm,"\u7B2C\u516D\u8282"),jm.forEach(t),y_=l(Ao,"\u4E2D\u4F60\u5C06\u5B66\u4E60\u5982\u4F55\u4ECE\u5934\u5F00\u59CB\u8BAD\u7EC3\u50CF GPT-2 \u8FD9\u6837\u7684\u81EA\u56DE\u5F52\u6A21\u578B; \u5982\u679C\u4F60\u60F3\u4E86\u89E3\u5982\u4F55\u9884\u8BAD\u7EC3\u60A8\u81EA\u5DF1\u7684 Transformer \u6A21\u578B, \u8BF7\u524D\u5F80\u90A3\u91CC!"),Ao.forEach(t),wo=d(e),y(Mt.$$.fragment,e),this.h()},h(){q(o,"name","hf:doc:metadata"),q(o,"content",JSON.stringify(rf)),q(D,"id",""),q(V,"href","https://arxiv.org/abs/1801.06146"),q(V,"rel","nofollow"),q(ie,"class","block dark:hidden"),Fr(ie.src,G="https://huggingface.co/datasets/huggingface-course/documentation-images/resolve/main/en/chapter7/ulmfit.svg")||q(ie,"src",G),q(ie,"alt","ULMFiT."),q(U,"class","hidden dark:block"),Fr(U.src,Fe="https://huggingface.co/datasets/huggingface-course/documentation-images/resolve/main/en/chapter7/ulmfit-dark.svg")||q(U,"src",Fe),q(U,"alt","ULMFiT."),q(ee,"class","flex justify-center"),q(Q,"href","https://huggingface.co/huggingface-course/distilbert-base-uncased-finetuned-imdb?text=This+is+a+great+%5BMASK%5D."),q(Q,"rel","nofollow"),Fr(pe.src,ze="https://course-demos-distilbert-base-uncased-finetune-7400b54.hf.space")||q(pe,"src",ze),q(pe,"frameborder","0"),q(pe,"height","300"),q(pe,"title","Gradio app"),q(pe,"class","block dark:hidden container p-0 flex-grow space-iframe"),q(pe,"allow","accelerometer; ambient-light-sensor; autoplay; battery; camera; document-domain; encrypted-media; fullscreen; geolocation; gyroscope; layout-animations; legacy-image-formats; magnetometer; microphone; midi; oversized-images; payment; picture-in-picture; publickey-credentials-get; sync-xhr; usb; vr ; wake-lock; xr-spatial-tracking"),q(pe,"sandbox","allow-forms allow-modals allow-popups allow-popups-to-escape-sandbox allow-same-origin allow-scripts allow-downloads"),Fr(re.src,ue="https://course-demos-distilbert-base-uncased-finetuned-imdb-darkmode.hf.space")||q(re,"src",ue),q(re,"frameborder","0"),q(re,"height","300"),q(re,"title","Gradio app"),q(re,"class","hidden dark:block container p-0 flex-grow space-iframe"),q(re,"allow","accelerometer; ambient-light-sensor; autoplay; battery; camera; document-domain; encrypted-media; fullscreen; geolocation; gyroscope; layout-animations; legacy-image-formats; magnetometer; microphone; midi; oversized-images; payment; picture-in-picture; publickey-credentials-get; sync-xhr; usb; vr ; wake-lock; xr-spatial-tracking"),q(re,"sandbox","allow-forms allow-modals allow-popups allow-popups-to-escape-sandbox allow-same-origin allow-scripts allow-downloads"),q(ve,"id",""),q(Oe,"href","https://huggingface.co/models?pipeline_tag=fill-mask&sort=downloads"),q(Oe,"rel","nofollow"),Fr(ge.src,oe="https://huggingface.co/datasets/huggingface-course/documentation-images/resolve/main/en/chapter7/mlm-models.png")||q(ge,"src",oe),q(ge,"alt","Hub models."),q(ge,"width","80%"),q(ne,"class","flex justify-center"),q(Re,"href","https://huggingface.co/distilbert-base-uncased"),q(Re,"rel","nofollow"),q(z,"href","https://en.wikipedia.org/wiki/Knowledge_distillation"),q(z,"rel","nofollow"),q(ss,"href","https://www.oreilly.com/library/view/natural-language-processing/9781098136789/"),q(ss,"rel","nofollow"),q(Ne,"href","https://huggingface.co/datasets/wikipedia"),q(Ne,"rel","nofollow"),q(ts,"href","https://huggingface.co/datasets/bookcorpus"),q(ts,"rel","nofollow"),q(ds,"id",""),q(us,"href","https://huggingface.co/datasets/imdb"),q(us,"rel","nofollow"),q(Ya,"href","/course/chapter3"),q(Nt,"id",""),q(Ja,"href","/course/chapter6/3"),q(jt,"id","trainer-api-distilbert"),q(jt,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),q(jt,"href","#trainer-api-distilbert"),q(_t,"class","relative group"),q(al,"href","/course/chapter3"),q(ol,"href","/course/chapter5"),q(xt,"id","perplexity"),q(xt,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),q(xt,"href","#perplexity"),q(ct,"class","relative group"),q(xa,"id",""),q(vl,"href","/course/chapter7/section6")},m(e,r){s(document.head,o),n(e,h,r),E(c,e,r),n(e,w,r),n(e,D,r),s(D,$),n(e,k,r),za[M].m(e,r),n(e,A,r),n(e,P,r),s(P,K),n(e,L,r),n(e,N,r),s(N,H),n(e,F,r),n(e,B,r),s(B,W),s(B,v),s(v,R),s(B,I),s(B,V),s(V,se),s(B,Y),n(e,ye,r),n(e,ee,r),s(ee,ie),s(ee,fe),s(ee,U),n(e,le,r),n(e,te,r),s(te,Me),s(te,Q),s(Q,Ee),s(te,Te),n(e,Ie,r),n(e,pe,r),n(e,xe,r),n(e,re,r),n(e,De,r),n(e,ke,r),s(ke,me),n(e,Ge,r),E(he,e,r),n(e,$e,r),E(ae,e,r),n(e,we,r),n(e,ve,r),s(ve,Ue),n(e,je,r),n(e,C,r),s(C,J),s(C,Oe),s(Oe,_e),s(C,Ke),n(e,We,r),n(e,ne,r),s(ne,ge),n(e,qe,r),n(e,de,r),s(de,Ae),s(de,Re),s(Re,ls),s(de,Ye),s(de,z),s(z,X),s(X,Ve),s(de,be),s(de,ss),s(ss,Je),s(Je,ys),s(de,ps),n(e,Es,r),Aa[Ce].m(e,r),n(e,rs,r),n(e,Le,r),s(Le,xs),n(e,Qe,r),E(ns,e,r),n(e,_s,r),n(e,ce,r),s(ce,Bs),s(ce,cs),s(cs,Be),s(ce,Ds),s(ce,Ne),s(Ne,Ot),s(ce,mt),s(ce,ts),s(ts,ft),s(ce,qs),s(ce,Hs),s(Hs,Fs),s(ce,Kt),n(e,rt,r),E(m,e,r),n(e,S,r),n(e,Ms,r),s(Ms,Ha),n(e,Rt,r),Ca[os].m(e,r),n(e,nt,r),E(Ns,e,r),n(e,ms,r),n(e,ot,r),s(ot,Fa),n(e,Lt,r),n(e,ds,r),s(ds,Na),n(e,it,r),n(e,fs,r),s(fs,Ia),s(fs,us),s(us,Ga),s(fs,dt),s(fs,ut),s(ut,Ua),s(fs,Wa),n(e,pt,r),E(Is,e,r),n(e,Bt,r),E(Gs,e,r),n(e,Nr,r),n(e,Xe,r),s(Xe,Po),s(Xe,Kl),s(Kl,So),s(Xe,Oo),s(Xe,Rl),s(Rl,Ko),s(Xe,Ro),s(Xe,Ll),s(Ll,Lo),s(Xe,Bo),s(Xe,Bl),s(Bl,Ho),s(Xe,Fo),s(Xe,Hl),s(Hl,No),s(Xe,Io),n(e,Ir,r),E(Ht,e,r),n(e,Gr,r),E(Ft,e,r),n(e,Ur,r),n(e,Us,r),s(Us,Go),s(Us,Fl),s(Fl,Uo),s(Us,Wo),s(Us,Nl),s(Nl,Yo),s(Us,Vo),n(e,Wr,r),E(ht,e,r),n(e,Yr,r),n(e,gt,r),s(gt,Jo),s(gt,Ya),s(Ya,Qo),s(gt,Xo),n(e,Vr,r),n(e,Nt,r),s(Nt,Zo),n(e,Jr,r),E(It,e,r),n(e,Qr,r),n(e,Va,r),s(Va,ei),n(e,Xr,r),n(e,Ze,r),s(Ze,si),s(Ze,Il),s(Il,ti),s(Ze,ai),s(Ze,Gl),s(Gl,li),s(Ze,ri),s(Ze,Ja),s(Ja,ni),s(Ze,oi),s(Ze,Ul),s(Ul,ii),s(Ze,pi),s(Ze,Wl),s(Wl,_i),s(Ze,ci),n(e,Zr,r),E(Gt,e,r),n(e,en,r),E(Ut,e,r),n(e,sn,r),n(e,hs,r),s(hs,mi),s(hs,Yl),s(Yl,fi),s(hs,di),s(hs,Vl),s(Vl,ui),s(hs,hi),s(hs,Jl),s(Jl,gi),s(hs,bi),n(e,tn,r),n(e,bt,r),s(bt,ki),s(bt,Ql),s(Ql,$i),s(bt,wi),n(e,an,r),E(Wt,e,r),n(e,ln,r),E(Yt,e,r),n(e,rn,r),n(e,kt,r),s(kt,vi),s(kt,Xl),s(Xl,ji),s(kt,yi),n(e,nn,r),E($t,e,r),n(e,on,r),n(e,Qa,r),s(Qa,Ei),n(e,pn,r),E(Vt,e,r),n(e,_n,r),E(wt,e,r),n(e,cn,r),n(e,Xa,r),s(Xa,xi),n(e,mn,r),E(Jt,e,r),n(e,fn,r),E(Qt,e,r),n(e,dn,r),n(e,Za,r),s(Za,Di),n(e,un,r),E(Xt,e,r),n(e,hn,r),E(Zt,e,r),n(e,gn,r),n(e,Ws,r),s(Ws,qi),s(Ws,Zl),s(Zl,Mi),s(Ws,Ti),s(Ws,er),s(er,zi),s(Ws,Ai),n(e,bn,r),E(ea,e,r),n(e,kn,r),E(sa,e,r),n(e,$n,r),n(e,el,r),s(el,Ci),n(e,wn,r),n(e,vt,r),s(vt,ta),s(ta,Pi),s(ta,sr),s(sr,Si),s(ta,Oi),s(vt,Ki),s(vt,aa),s(aa,Ri),s(aa,tr),s(tr,Li),s(aa,Bi),n(e,vn,r),n(e,sl,r),s(sl,Hi),n(e,jn,r),E(la,e,r),n(e,yn,r),n(e,is,r),s(is,Fi),s(is,ar),s(ar,Ni),s(is,Ii),s(is,lr),s(lr,Gi),s(is,Ui),s(is,rr),s(rr,Wi),s(is,Yi),s(is,nr),s(nr,Vi),s(is,Ji),n(e,En,r),n(e,Ys,r),s(Ys,Qi),s(Ys,or),s(or,Xi),s(Ys,Zi),s(Ys,ir),s(ir,ep),s(Ys,sp),n(e,xn,r),E(ra,e,r),n(e,Dn,r),E(na,e,r),n(e,qn,r),n(e,es,r),s(es,tp),s(es,pr),s(pr,ap),s(es,lp),s(es,_r),s(_r,rp),s(es,np),s(es,cr),s(cr,op),s(es,ip),s(es,mr),s(mr,pp),s(es,_p),s(es,fr),s(fr,cp),s(es,mp),n(e,Mn,r),E(oa,e,r),n(e,Tn,r),E(ia,e,r),n(e,zn,r),n(e,tl,r),s(tl,fp),n(e,An,r),E(pa,e,r),n(e,Cn,r),E(_a,e,r),n(e,Pn,r),n(e,gs,r),s(gs,dp),s(gs,dr),s(dr,up),s(gs,hp),s(gs,ur),s(ur,gp),s(gs,bp),s(gs,hr),s(hr,kp),s(gs,$p),n(e,Sn,r),n(e,_t,r),s(_t,jt),s(jt,gr),E(ca,gr,null),s(_t,wp),s(_t,ma),s(ma,vp),s(ma,br),s(br,jp),s(ma,yp),n(e,On,r),n(e,bs,r),s(bs,Ep),s(bs,al),s(al,xp),s(bs,Dp),s(bs,kr),s(kr,qp),s(bs,Mp),s(bs,$r),s($r,Tp),s(bs,zp),n(e,Kn,r),E(fa,e,r),n(e,Rn,r),n(e,ks,r),s(ks,Ap),s(ks,wr),s(wr,Cp),s(ks,Pp),s(ks,vr),s(vr,Sp),s(ks,Op),s(ks,jr),s(jr,Kp),s(ks,Rp),n(e,Ln,r),E(da,e,r),n(e,Bn,r),E(ua,e,r),n(e,Hn,r),n(e,Vs,r),s(Vs,Lp),s(Vs,yr),s(yr,Bp),s(Vs,Hp),s(Vs,Er),s(Er,Fp),s(Vs,Np),n(e,Fn,r),E(yt,e,r),n(e,Nn,r),as&&as.m(e,r),n(e,ll,r),n(e,Js,r),s(Js,Ip),s(Js,xr),s(xr,Gp),s(Js,Up),s(Js,Dr),s(Dr,Wp),s(Js,Yp),n(e,In,r),Pa[Ts].m(e,r),n(e,rl,r),n(e,nl,r),s(nl,Vp),n(e,Gn,r),E(ha,e,r),n(e,Un,r),E(ga,e,r),n(e,Wn,r),E(Et,e,r),n(e,Yn,r),n(e,Qs,r),s(Qs,Jp),s(Qs,ol),s(ol,Qp),s(Qs,Xp),s(Qs,qr),s(qr,Zp),s(Qs,e_),n(e,Vn,r),E(ba,e,r),n(e,Jn,r),E(ka,e,r),n(e,Qn,r),n(e,Xs,r),s(Xs,s_),s(Xs,Mr),s(Mr,t_),s(Xs,a_),s(Xs,Tr),s(Tr,l_),s(Xs,r_),n(e,Xn,r),E($a,e,r),n(e,Zn,r),n(e,il,r),s(il,n_),n(e,eo,r),E(wa,e,r),n(e,so,r),n(e,pl,r),s(pl,o_),n(e,to,r),Sa[As].m(e,r),n(e,_l,r),n(e,ct,r),s(ct,xt),s(xt,zr),E(va,zr,null),s(ct,i_),s(ct,Ar),s(Ar,p_),n(e,ao,r),E(ja,e,r),n(e,lo,r),n(e,cl,r),s(cl,__),n(e,ro,r),Oa[Ps].m(e,r),n(e,ml,r),E(ya,e,r),n(e,no,r),n(e,fl,r),s(fl,c_),n(e,oo,r),Ka[Os].m(e,r),n(e,dl,r),n(e,ul,r),s(ul,m_),n(e,io,r),Ra[Rs].m(e,r),n(e,hl,r),E(Ea,e,r),n(e,po,r),n(e,gl,r),s(gl,f_),n(e,_o,r),Pe&&Pe.m(e,r),n(e,bl,r),E(Dt,e,r),n(e,co,r),Se&&Se.m(e,r),n(e,kl,r),n(e,xa,r),s(xa,d_),n(e,mo,r),n(e,Zs,r),s(Zs,u_),s(Zs,Cr),s(Cr,h_),s(Zs,g_),s(Zs,Pr),s(Pr,b_),s(Zs,k_),n(e,fo,r),E(Da,e,r),n(e,uo,r),n(e,$l,r),s($l,$_),n(e,ho,r),E(qa,e,r),n(e,go,r),E(Ma,e,r),n(e,bo,r),n(e,wl,r),s(wl,w_),n(e,ko,r),E(Ta,e,r),n(e,$o,r),n(e,qt,r),s(qt,v_),s(qt,vl),s(vl,j_),s(qt,y_),n(e,wo,r),E(Mt,e,r),vo=!0},p(e,[r]){const Sr={};r&1&&(Sr.fw=e[0]),c.$set(Sr);let jl=M;M=D_(e),M!==jl&&(lt(),b(za[jl],1,1,()=>{za[jl]=null}),at(),u=za[M],u||(u=za[M]=x_[M](e),u.c()),g(u,1),u.m(A.parentNode,A));const Or={};r&2&&(Or.$$scope={dirty:r,ctx:e}),ae.$set(Or);let et=Ce;Ce=M_(e),Ce!==et&&(lt(),b(Aa[et],1,1,()=>{Aa[et]=null}),at(),Z=Aa[Ce],Z||(Z=Aa[Ce]=q_[Ce](e),Z.c()),g(Z,1),Z.m(rs.parentNode,rs));let yl=os;os=z_(e),os!==yl&&(lt(),b(Ca[yl],1,1,()=>{Ca[yl]=null}),at(),He=Ca[os],He||(He=Ca[os]=T_[os](e),He.c()),g(He,1),He.m(nt.parentNode,nt));const Kr={};r&2&&(Kr.$$scope={dirty:r,ctx:e}),ht.$set(Kr);const La={};r&2&&(La.$$scope={dirty:r,ctx:e}),$t.$set(La);const Ba={};r&2&&(Ba.$$scope={dirty:r,ctx:e}),wt.$set(Ba);const Rr={};r&2&&(Rr.$$scope={dirty:r,ctx:e}),yt.$set(Rr),e[0]==="pt"?as||(as=ym(),as.c(),as.m(ll.parentNode,ll)):as&&(as.d(1),as=null);let El=Ts;Ts=C_(e),Ts!==El&&(lt(),b(Pa[El],1,1,()=>{Pa[El]=null}),at(),zs=Pa[Ts],zs||(zs=Pa[Ts]=A_[Ts](e),zs.c()),g(zs,1),zs.m(rl.parentNode,rl));const Lr={};r&2&&(Lr.$$scope={dirty:r,ctx:e}),Et.$set(Lr);let Tt=As;As=S_(e),As!==Tt&&(lt(),b(Sa[Tt],1,1,()=>{Sa[Tt]=null}),at(),Cs=Sa[As],Cs||(Cs=Sa[As]=P_[As](e),Cs.c()),g(Cs,1),Cs.m(_l.parentNode,_l));let xl=Ps;Ps=K_(e),Ps!==xl&&(lt(),b(Oa[xl],1,1,()=>{Oa[xl]=null}),at(),Ss=Oa[Ps],Ss||(Ss=Oa[Ps]=O_[Ps](e),Ss.c()),g(Ss,1),Ss.m(ml.parentNode,ml));let Dl=Os;Os=L_(e),Os!==Dl&&(lt(),b(Ka[Dl],1,1,()=>{Ka[Dl]=null}),at(),Ks=Ka[Os],Ks||(Ks=Ka[Os]=R_[Os](e),Ks.c()),g(Ks,1),Ks.m(dl.parentNode,dl));let $s=Rs;Rs=H_(e),Rs!==$s&&(lt(),b(Ra[$s],1,1,()=>{Ra[$s]=null}),at(),Ls=Ra[Rs],Ls||(Ls=Ra[Rs]=B_[Rs](e),Ls.c()),g(Ls,1),Ls.m(hl.parentNode,hl)),e[0]==="pt"?Pe?r&1&&g(Pe,1):(Pe=Em(),Pe.c(),g(Pe,1),Pe.m(bl.parentNode,bl)):Pe&&(lt(),b(Pe,1,1,()=>{Pe=null}),at());const Br={};r&2&&(Br.$$scope={dirty:r,ctx:e}),Dt.$set(Br),e[0]==="pt"?Se?r&1&&g(Se,1):(Se=xm(),Se.c(),g(Se,1),Se.m(kl.parentNode,kl)):Se&&(lt(),b(Se,1,1,()=>{Se=null}),at());const Hr={};r&2&&(Hr.$$scope={dirty:r,ctx:e}),Mt.$set(Hr)},i(e){vo||(g(c.$$.fragment,e),g(u),g(he.$$.fragment,e),g(ae.$$.fragment,e),g(Z),g(ns.$$.fragment,e),g(m.$$.fragment,e),g(He),g(Ns.$$.fragment,e),g(Is.$$.fragment,e),g(Gs.$$.fragment,e),g(Ht.$$.fragment,e),g(Ft.$$.fragment,e),g(ht.$$.fragment,e),g(It.$$.fragment,e),g(Gt.$$.fragment,e),g(Ut.$$.fragment,e),g(Wt.$$.fragment,e),g(Yt.$$.fragment,e),g($t.$$.fragment,e),g(Vt.$$.fragment,e),g(wt.$$.fragment,e),g(Jt.$$.fragment,e),g(Qt.$$.fragment,e),g(Xt.$$.fragment,e),g(Zt.$$.fragment,e),g(ea.$$.fragment,e),g(sa.$$.fragment,e),g(la.$$.fragment,e),g(ra.$$.fragment,e),g(na.$$.fragment,e),g(oa.$$.fragment,e),g(ia.$$.fragment,e),g(pa.$$.fragment,e),g(_a.$$.fragment,e),g(ca.$$.fragment,e),g(fa.$$.fragment,e),g(da.$$.fragment,e),g(ua.$$.fragment,e),g(yt.$$.fragment,e),g(zs),g(ha.$$.fragment,e),g(ga.$$.fragment,e),g(Et.$$.fragment,e),g(ba.$$.fragment,e),g(ka.$$.fragment,e),g($a.$$.fragment,e),g(wa.$$.fragment,e),g(Cs),g(va.$$.fragment,e),g(ja.$$.fragment,e),g(Ss),g(ya.$$.fragment,e),g(Ks),g(Ls),g(Ea.$$.fragment,e),g(Pe),g(Dt.$$.fragment,e),g(Se),g(Da.$$.fragment,e),g(qa.$$.fragment,e),g(Ma.$$.fragment,e),g(Ta.$$.fragment,e),g(Mt.$$.fragment,e),vo=!0)},o(e){b(c.$$.fragment,e),b(u),b(he.$$.fragment,e),b(ae.$$.fragment,e),b(Z),b(ns.$$.fragment,e),b(m.$$.fragment,e),b(He),b(Ns.$$.fragment,e),b(Is.$$.fragment,e),b(Gs.$$.fragment,e),b(Ht.$$.fragment,e),b(Ft.$$.fragment,e),b(ht.$$.fragment,e),b(It.$$.fragment,e),b(Gt.$$.fragment,e),b(Ut.$$.fragment,e),b(Wt.$$.fragment,e),b(Yt.$$.fragment,e),b($t.$$.fragment,e),b(Vt.$$.fragment,e),b(wt.$$.fragment,e),b(Jt.$$.fragment,e),b(Qt.$$.fragment,e),b(Xt.$$.fragment,e),b(Zt.$$.fragment,e),b(ea.$$.fragment,e),b(sa.$$.fragment,e),b(la.$$.fragment,e),b(ra.$$.fragment,e),b(na.$$.fragment,e),b(oa.$$.fragment,e),b(ia.$$.fragment,e),b(pa.$$.fragment,e),b(_a.$$.fragment,e),b(ca.$$.fragment,e),b(fa.$$.fragment,e),b(da.$$.fragment,e),b(ua.$$.fragment,e),b(yt.$$.fragment,e),b(zs),b(ha.$$.fragment,e),b(ga.$$.fragment,e),b(Et.$$.fragment,e),b(ba.$$.fragment,e),b(ka.$$.fragment,e),b($a.$$.fragment,e),b(wa.$$.fragment,e),b(Cs),b(va.$$.fragment,e),b(ja.$$.fragment,e),b(Ss),b(ya.$$.fragment,e),b(Ks),b(Ls),b(Ea.$$.fragment,e),b(Pe),b(Dt.$$.fragment,e),b(Se),b(Da.$$.fragment,e),b(qa.$$.fragment,e),b(Ma.$$.fragment,e),b(Ta.$$.fragment,e),b(Mt.$$.fragment,e),vo=!1},d(e){t(o),e&&t(h),x(c,e),e&&t(w),e&&t(D),e&&t(k),za[M].d(e),e&&t(A),e&&t(P),e&&t(L),e&&t(N),e&&t(F),e&&t(B),e&&t(ye),e&&t(ee),e&&t(le),e&&t(te),e&&t(Ie),e&&t(pe),e&&t(xe),e&&t(re),e&&t(De),e&&t(ke),e&&t(Ge),x(he,e),e&&t($e),x(ae,e),e&&t(we),e&&t(ve),e&&t(je),e&&t(C),e&&t(We),e&&t(ne),e&&t(qe),e&&t(de),e&&t(Es),Aa[Ce].d(e),e&&t(rs),e&&t(Le),e&&t(Qe),x(ns,e),e&&t(_s),e&&t(ce),e&&t(rt),x(m,e),e&&t(S),e&&t(Ms),e&&t(Rt),Ca[os].d(e),e&&t(nt),x(Ns,e),e&&t(ms),e&&t(ot),e&&t(Lt),e&&t(ds),e&&t(it),e&&t(fs),e&&t(pt),x(Is,e),e&&t(Bt),x(Gs,e),e&&t(Nr),e&&t(Xe),e&&t(Ir),x(Ht,e),e&&t(Gr),x(Ft,e),e&&t(Ur),e&&t(Us),e&&t(Wr),x(ht,e),e&&t(Yr),e&&t(gt),e&&t(Vr),e&&t(Nt),e&&t(Jr),x(It,e),e&&t(Qr),e&&t(Va),e&&t(Xr),e&&t(Ze),e&&t(Zr),x(Gt,e),e&&t(en),x(Ut,e),e&&t(sn),e&&t(hs),e&&t(tn),e&&t(bt),e&&t(an),x(Wt,e),e&&t(ln),x(Yt,e),e&&t(rn),e&&t(kt),e&&t(nn),x($t,e),e&&t(on),e&&t(Qa),e&&t(pn),x(Vt,e),e&&t(_n),x(wt,e),e&&t(cn),e&&t(Xa),e&&t(mn),x(Jt,e),e&&t(fn),x(Qt,e),e&&t(dn),e&&t(Za),e&&t(un),x(Xt,e),e&&t(hn),x(Zt,e),e&&t(gn),e&&t(Ws),e&&t(bn),x(ea,e),e&&t(kn),x(sa,e),e&&t($n),e&&t(el),e&&t(wn),e&&t(vt),e&&t(vn),e&&t(sl),e&&t(jn),x(la,e),e&&t(yn),e&&t(is),e&&t(En),e&&t(Ys),e&&t(xn),x(ra,e),e&&t(Dn),x(na,e),e&&t(qn),e&&t(es),e&&t(Mn),x(oa,e),e&&t(Tn),x(ia,e),e&&t(zn),e&&t(tl),e&&t(An),x(pa,e),e&&t(Cn),x(_a,e),e&&t(Pn),e&&t(gs),e&&t(Sn),e&&t(_t),x(ca),e&&t(On),e&&t(bs),e&&t(Kn),x(fa,e),e&&t(Rn),e&&t(ks),e&&t(Ln),x(da,e),e&&t(Bn),x(ua,e),e&&t(Hn),e&&t(Vs),e&&t(Fn),x(yt,e),e&&t(Nn),as&&as.d(e),e&&t(ll),e&&t(Js),e&&t(In),Pa[Ts].d(e),e&&t(rl),e&&t(nl),e&&t(Gn),x(ha,e),e&&t(Un),x(ga,e),e&&t(Wn),x(Et,e),e&&t(Yn),e&&t(Qs),e&&t(Vn),x(ba,e),e&&t(Jn),x(ka,e),e&&t(Qn),e&&t(Xs),e&&t(Xn),x($a,e),e&&t(Zn),e&&t(il),e&&t(eo),x(wa,e),e&&t(so),e&&t(pl),e&&t(to),Sa[As].d(e),e&&t(_l),e&&t(ct),x(va),e&&t(ao),x(ja,e),e&&t(lo),e&&t(cl),e&&t(ro),Oa[Ps].d(e),e&&t(ml),x(ya,e),e&&t(no),e&&t(fl),e&&t(oo),Ka[Os].d(e),e&&t(dl),e&&t(ul),e&&t(io),Ra[Rs].d(e),e&&t(hl),x(Ea,e),e&&t(po),e&&t(gl),e&&t(_o),Pe&&Pe.d(e),e&&t(bl),x(Dt,e),e&&t(co),Se&&Se.d(e),e&&t(kl),e&&t(xa),e&&t(mo),e&&t(Zs),e&&t(fo),x(Da,e),e&&t(uo),e&&t($l),e&&t(ho),x(qa,e),e&&t(go),x(Ma,e),e&&t(bo),e&&t(wl),e&&t(ko),x(Ta,e),e&&t($o),e&&t(qt),e&&t(wo),x(Mt,e)}}}const rf={local:"",sections:[{local:"",title:"\u9009\u62E9\u7528\u4E8E\u63A9\u7801\u8BED\u8A00\u5EFA\u6A21\u7684\u9884\u8BAD\u7EC3\u6A21\u578B"},{local:"",title:"\u6570\u636E\u96C6"},{local:"",title:"\u9884\u5904\u7406\u6570\u636E"},{local:"trainer-api-distilbert",sections:[{local:"perplexity",title:"\u8BED\u8A00\u6A21\u578B\u7684perplexity"}],title:"\u4F7F\u7528 `Trainer` API \u5FAE\u8C03DistilBERT"},{local:"accelerate-distilbert",title:"\u4F7F\u7528 \u{1F917} Accelerate \u5FAE\u8C03 DistilBERT"},{local:"",title:"\u4F7F\u7528\u6211\u4EEC\u5FAE\u8C03\u7684\u6A21\u578B"}],title:"\u5FAE\u8C03\u63A9\u7801\u8BED\u8A00\u6A21\u578B"};function nf(O,o,h){let c="pt";return Am(()=>{const w=new URLSearchParams(window.location.search);h(0,c=w.get("fw")||"pt")}),[c]}class uf extends qm{constructor(o){super();Mm(this,o,nf,lf,Tm,{})}}export{uf as default,rf as metadata};
